projects/linux·blob master · refs

112 lines · 2.8 KiB

1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * AHCI SATA platform driver
4 *
5 * Copyright 2004-2005 Red Hat, Inc.
6 * Jeff Garzik <[email protected]>
7 * Copyright 2010 MontaVista Software, LLC.
8 * Anton Vorontsov <[email protected]>
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/pm.h>
14#include <linux/device.h>
15#include <linux/platform_device.h>
16#include <linux/property.h>
17#include <linux/libata.h>
18#include <linux/ahci_platform.h>
19#include <linux/pci_ids.h>
20#include "ahci.h"
21
22#define DRV_NAME "ahci"
23
24static const struct ata_port_info ahci_port_info = {
25 .flags = AHCI_FLAG_COMMON,
26 .pio_mask = ATA_PIO4,
27 .udma_mask = ATA_UDMA6,
28 .port_ops = &ahci_platform_ops,
29};
30
31static const struct ata_port_info ahci_port_info_nolpm = {
32 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_LPM,
33 .pio_mask = ATA_PIO4,
34 .udma_mask = ATA_UDMA6,
35 .port_ops = &ahci_platform_ops,
36};
37
38static const struct scsi_host_template ahci_platform_sht = {
39 AHCI_SHT(DRV_NAME),
40};
41
42static int ahci_probe(struct platform_device *pdev)
43{
44 struct device *dev = &pdev->dev;
45 struct ahci_host_priv *hpriv;
46 const struct ata_port_info *port;
47 int rc;
48
49 hpriv = ahci_platform_get_resources(pdev,
50 AHCI_PLATFORM_GET_RESETS);
51 if (IS_ERR(hpriv))
52 return PTR_ERR(hpriv);
53
54 rc = ahci_platform_enable_resources(hpriv);
55 if (rc)
56 return rc;
57
58 if (device_is_compatible(dev, "hisilicon,hisi-ahci"))
59 hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
60
61 port = device_get_match_data(dev);
62 if (!port)
63 port = &ahci_port_info;
64
65 rc = ahci_platform_init_host(pdev, hpriv, port,
66 &ahci_platform_sht);
67 if (rc)
68 goto disable_resources;
69
70 return 0;
71disable_resources:
72 ahci_platform_disable_resources(hpriv);
73 return rc;
74}
75
76static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
77 ahci_platform_resume);
78
79static const struct of_device_id ahci_of_match[] = {
80 { .compatible = "generic-ahci", },
81 /* Keep the following compatibles for device tree compatibility */
82 { .compatible = "ibm,476gtr-ahci", },
83 { .compatible = "hisilicon,hisi-ahci", },
84 { .compatible = "cavium,octeon-7130-ahci", },
85 { /* sentinel */ }
86};
87MODULE_DEVICE_TABLE(of, ahci_of_match);
88
89static const struct acpi_device_id ahci_acpi_match[] = {
90 { .id = "APMC0D33", .driver_data = (unsigned long)&ahci_port_info_nolpm },
91 { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
92 { }
93};
94MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
95
96static struct platform_driver ahci_driver = {
97 .probe = ahci_probe,
98 .remove = ata_platform_remove_one,
99 .shutdown = ahci_platform_shutdown,
100 .driver = {
101 .name = DRV_NAME,
102 .of_match_table = ahci_of_match,
103 .acpi_match_table = ahci_acpi_match,
104 .pm = &ahci_pm_ops,
105 },
106};
107module_platform_driver(ahci_driver);
108
109MODULE_DESCRIPTION("AHCI SATA platform driver");
110MODULE_AUTHOR("Anton Vorontsov <[email protected]>");
111MODULE_LICENSE("GPL");
112MODULE_ALIAS("platform:ahci");