aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/Kconfig8
-rw-r--r--drivers/ata/Makefile1
-rw-r--r--drivers/ata/ahci_platform.c191
-rw-r--r--include/linux/ahci_platform.h29
4 files changed, 229 insertions, 0 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 01c52c415bdc..cbadb9fa1277 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -65,6 +65,14 @@ config SATA_AHCI
65 65
66 If unsure, say N. 66 If unsure, say N.
67 67
68config SATA_AHCI_PLATFORM
69 tristate "Platform AHCI SATA support"
70 help
71 This option enables support for Platform AHCI Serial ATA
72 controllers.
73
74 If unsure, say N.
75
68config SATA_SIL24 76config SATA_SIL24
69 tristate "Silicon Image 3124/3132 SATA support" 77 tristate "Silicon Image 3124/3132 SATA support"
70 depends on PCI 78 depends on PCI
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 20c5251e7e41..d0a93c4ad3ec 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -2,6 +2,7 @@
2obj-$(CONFIG_ATA) += libata.o 2obj-$(CONFIG_ATA) += libata.o
3 3
4obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o 4obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o
5obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o
5obj-$(CONFIG_SATA_SVW) += sata_svw.o 6obj-$(CONFIG_SATA_SVW) += sata_svw.o
6obj-$(CONFIG_ATA_PIIX) += ata_piix.o 7obj-$(CONFIG_ATA_PIIX) += ata_piix.o
7obj-$(CONFIG_SATA_PROMISE) += sata_promise.o 8obj-$(CONFIG_SATA_PROMISE) += sata_promise.o
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
new file mode 100644
index 000000000000..42cdd7363fad
--- /dev/null
+++ b/drivers/ata/ahci_platform.c
@@ -0,0 +1,191 @@
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/init.h>
18#include <linux/interrupt.h>
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/libata.h>
22#include <linux/ahci_platform.h>
23#include "ahci.h"
24
25static int __init ahci_probe(struct platform_device *pdev)
26{
27 struct device *dev = &pdev->dev;
28 struct ahci_platform_data *pdata = dev->platform_data;
29 struct ata_port_info pi = {
30 .flags = AHCI_FLAG_COMMON,
31 .pio_mask = ATA_PIO4,
32 .udma_mask = ATA_UDMA6,
33 .port_ops = &ahci_ops,
34 };
35 const struct ata_port_info *ppi[] = { &pi, NULL };
36 struct ahci_host_priv *hpriv;
37 struct ata_host *host;
38 struct resource *mem;
39 int irq;
40 int n_ports;
41 int i;
42 int rc;
43
44 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
45 if (!mem) {
46 dev_err(dev, "no mmio space\n");
47 return -EINVAL;
48 }
49
50 irq = platform_get_irq(pdev, 0);
51 if (irq <= 0) {
52 dev_err(dev, "no irq\n");
53 return -EINVAL;
54 }
55
56 if (pdata && pdata->init) {
57 rc = pdata->init(dev);
58 if (rc)
59 return rc;
60 }
61
62 if (pdata && pdata->ata_port_info)
63 pi = *pdata->ata_port_info;
64
65 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
66 if (!hpriv) {
67 rc = -ENOMEM;
68 goto err0;
69 }
70
71 hpriv->flags |= (unsigned long)pi.private_data;
72
73 hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
74 if (!hpriv->mmio) {
75 dev_err(dev, "can't map %pR\n", mem);
76 rc = -ENOMEM;
77 goto err0;
78 }
79
80 ahci_save_initial_config(dev, hpriv,
81 pdata ? pdata->force_port_map : 0,
82 pdata ? pdata->mask_port_map : 0);
83
84 /* prepare host */
85 if (hpriv->cap & HOST_CAP_NCQ)
86 pi.flags |= ATA_FLAG_NCQ;
87
88 if (hpriv->cap & HOST_CAP_PMP)
89 pi.flags |= ATA_FLAG_PMP;
90
91 ahci_set_em_messages(hpriv, &pi);
92
93 /* CAP.NP sometimes indicate the index of the last enabled
94 * port, at other times, that of the last possible port, so
95 * determining the maximum port number requires looking at
96 * both CAP.NP and port_map.
97 */
98 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
99
100 host = ata_host_alloc_pinfo(dev, ppi, n_ports);
101 if (!host) {
102 rc = -ENOMEM;
103 goto err0;
104 }
105
106 host->private_data = hpriv;
107
108 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
109 host->flags |= ATA_HOST_PARALLEL_SCAN;
110 else
111 printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n");
112
113 if (pi.flags & ATA_FLAG_EM)
114 ahci_reset_em(host);
115
116 for (i = 0; i < host->n_ports; i++) {
117 struct ata_port *ap = host->ports[i];
118
119 ata_port_desc(ap, "mmio %pR", mem);
120 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
121
122 /* set initial link pm policy */
123 ap->pm_policy = NOT_AVAILABLE;
124
125 /* set enclosure management message type */
126 if (ap->flags & ATA_FLAG_EM)
127 ap->em_message_type = ahci_em_messages;
128
129 /* disabled/not-implemented port */
130 if (!(hpriv->port_map & (1 << i)))
131 ap->ops = &ata_dummy_port_ops;
132 }
133
134 rc = ahci_reset_controller(host);
135 if (rc)
136 goto err0;
137
138 ahci_init_controller(host);
139 ahci_print_info(host, "platform");
140
141 rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
142 &ahci_sht);
143 if (rc)
144 goto err0;
145
146 return 0;
147err0:
148 if (pdata && pdata->exit)
149 pdata->exit(dev);
150 return rc;
151}
152
153static int __devexit ahci_remove(struct platform_device *pdev)
154{
155 struct device *dev = &pdev->dev;
156 struct ahci_platform_data *pdata = dev->platform_data;
157 struct ata_host *host = dev_get_drvdata(dev);
158
159 ata_host_detach(host);
160
161 if (pdata && pdata->exit)
162 pdata->exit(dev);
163
164 return 0;
165}
166
167static struct platform_driver ahci_driver = {
168 .probe = ahci_probe,
169 .remove = __devexit_p(ahci_remove),
170 .driver = {
171 .name = "ahci",
172 .owner = THIS_MODULE,
173 },
174};
175
176static int __init ahci_init(void)
177{
178 return platform_driver_probe(&ahci_driver, ahci_probe);
179}
180module_init(ahci_init);
181
182static void __exit ahci_exit(void)
183{
184 platform_driver_unregister(&ahci_driver);
185}
186module_exit(ahci_exit);
187
188MODULE_DESCRIPTION("AHCI SATA platform driver");
189MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
190MODULE_LICENSE("GPL");
191MODULE_ALIAS("platform:ahci");
diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h
new file mode 100644
index 000000000000..f7dd576dd5a4
--- /dev/null
+++ b/include/linux/ahci_platform.h
@@ -0,0 +1,29 @@
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#ifndef _AHCI_PLATFORM_H
16#define _AHCI_PLATFORM_H
17
18struct device;
19struct ata_port_info;
20
21struct ahci_platform_data {
22 int (*init)(struct device *dev);
23 void (*exit)(struct device *dev);
24 const struct ata_port_info *ata_port_info;
25 unsigned int force_port_map;
26 unsigned int mask_port_map;
27};
28
29#endif /* _AHCI_PLATFORM_H */