1/*
2 * AHCI SATA platform driver
3 *
4 * Copyright 2004-2005 Red Hat, Inc.
5 * Jeff Garzik <jgarzik@pobox.com>
6 * Copyright 2010 MontaVista Software, LLC.
7 * Anton Vorontsov <avorontsov@ru.mvista.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/pm.h>
18#include <linux/device.h>
19#include <linux/of_device.h>
20#include <linux/platform_device.h>
21#include <linux/libata.h>
22#include <linux/ahci_platform.h>
23#include <linux/acpi.h>
24#include <linux/pci_ids.h>
25#include "ahci.h"
26
27#define DRV_NAME "ahci"
28
29static const struct ata_port_info ahci_port_info = {
30 .flags = AHCI_FLAG_COMMON,
31 .pio_mask = ATA_PIO4,
32 .udma_mask = ATA_UDMA6,
33 .port_ops = &ahci_platform_ops,
34};
35
36static const struct ata_port_info ahci_port_info_nolpm = {
37 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_LPM,
38 .pio_mask = ATA_PIO4,
39 .udma_mask = ATA_UDMA6,
40 .port_ops = &ahci_platform_ops,
41};
42
43static struct scsi_host_template ahci_platform_sht = {
44 AHCI_SHT(DRV_NAME),
45};
46
47static int ahci_probe(struct platform_device *pdev)
48{
49 struct device *dev = &pdev->dev;
50 struct ahci_host_priv *hpriv;
51 const struct ata_port_info *port;
52 int rc;
53
54 hpriv = ahci_platform_get_resources(pdev,
55 AHCI_PLATFORM_GET_RESETS);
56 if (IS_ERR(hpriv))
57 return PTR_ERR(hpriv);
58
59 rc = ahci_platform_enable_resources(hpriv);
60 if (rc)
61 return rc;
62
63 of_property_read_u32(dev->of_node,
64 "ports-implemented", &hpriv->force_port_map);
65
66 if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci"))
67 hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
68
69 port = acpi_device_get_match_data(dev);
70 if (!port)
71 port = &ahci_port_info;
72
73 rc = ahci_platform_init_host(pdev, hpriv, port,
74 &ahci_platform_sht);
75 if (rc)
76 goto disable_resources;
77
78 return 0;
79disable_resources:
80 ahci_platform_disable_resources(hpriv);
81 return rc;
82}
83
84static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
85 ahci_platform_resume);
86
87static const struct of_device_id ahci_of_match[] = {
88 { .compatible = "generic-ahci", },
89 /* Keep the following compatibles for device tree compatibility */
90 { .compatible = "snps,spear-ahci", },
91 { .compatible = "ibm,476gtr-ahci", },
92 { .compatible = "snps,dwc-ahci", },
93 { .compatible = "hisilicon,hisi-ahci", },
94 { .compatible = "cavium,octeon-7130-ahci", },
95 {},
96};
97MODULE_DEVICE_TABLE(of, ahci_of_match);
98
99static const struct acpi_device_id ahci_acpi_match[] = {
100 { "APMC0D33", (unsigned long)&ahci_port_info_nolpm },
101 { ACPI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff) },
102 {},
103};
104MODULE_DEVICE_TABLE(acpi, ahci_acpi_match);
105
106static struct platform_driver ahci_driver = {
107 .probe = ahci_probe,
108 .remove = ata_platform_remove_one,
109 .shutdown = ahci_platform_shutdown,
110 .driver = {
111 .name = DRV_NAME,
112 .of_match_table = ahci_of_match,
113 .acpi_match_table = ahci_acpi_match,
114 .pm = &ahci_pm_ops,
115 },
116};
117module_platform_driver(ahci_driver);
118
119MODULE_DESCRIPTION("AHCI SATA platform driver");
120MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
121MODULE_LICENSE("GPL");
122MODULE_ALIAS("platform:ahci");
123