2 * AHCI SATA platform driver
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>
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)
15 #include <linux/kernel.h>
16 #include <linux/gfp.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
22 #include <linux/libata.h>
23 #include <linux/ahci_platform.h>
27 AHCI
, /* standard platform ahci */
28 IMX53_AHCI
, /* ahci on i.mx53 */
31 static struct platform_device_id ahci_devtype
[] = {
37 .driver_data
= IMX53_AHCI
,
42 MODULE_DEVICE_TABLE(platform
, ahci_devtype
);
45 static const struct ata_port_info ahci_port_info
[] = {
48 .flags
= AHCI_FLAG_COMMON
,
50 .udma_mask
= ATA_UDMA6
,
51 .port_ops
= &ahci_ops
,
54 .flags
= AHCI_FLAG_COMMON
,
56 .udma_mask
= ATA_UDMA6
,
57 .port_ops
= &ahci_pmp_retry_srst_ops
,
61 static struct scsi_host_template ahci_platform_sht
= {
62 AHCI_SHT("ahci_platform"),
65 static int __init
ahci_probe(struct platform_device
*pdev
)
67 struct device
*dev
= &pdev
->dev
;
68 struct ahci_platform_data
*pdata
= dev_get_platdata(dev
);
69 const struct platform_device_id
*id
= platform_get_device_id(pdev
);
70 struct ata_port_info pi
= ahci_port_info
[id
? id
->driver_data
: 0];
71 const struct ata_port_info
*ppi
[] = { &pi
, NULL
};
72 struct ahci_host_priv
*hpriv
;
73 struct ata_host
*host
;
80 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
82 dev_err(dev
, "no mmio space\n");
86 irq
= platform_get_irq(pdev
, 0);
88 dev_err(dev
, "no irq\n");
92 if (pdata
&& pdata
->ata_port_info
)
93 pi
= *pdata
->ata_port_info
;
95 hpriv
= devm_kzalloc(dev
, sizeof(*hpriv
), GFP_KERNEL
);
97 dev_err(dev
, "can't alloc ahci_host_priv\n");
101 hpriv
->flags
|= (unsigned long)pi
.private_data
;
103 hpriv
->mmio
= devm_ioremap(dev
, mem
->start
, resource_size(mem
));
105 dev_err(dev
, "can't map %pR\n", mem
);
110 * Some platforms might need to prepare for mmio region access,
111 * which could be done in the following init call. So, the mmio
112 * region shouldn't be accessed before init (if provided) has
113 * returned successfully.
115 if (pdata
&& pdata
->init
) {
116 rc
= pdata
->init(dev
, hpriv
->mmio
);
121 ahci_save_initial_config(dev
, hpriv
,
122 pdata
? pdata
->force_port_map
: 0,
123 pdata
? pdata
->mask_port_map
: 0);
126 if (hpriv
->cap
& HOST_CAP_NCQ
)
127 pi
.flags
|= ATA_FLAG_NCQ
;
129 if (hpriv
->cap
& HOST_CAP_PMP
)
130 pi
.flags
|= ATA_FLAG_PMP
;
132 ahci_set_em_messages(hpriv
, &pi
);
134 /* CAP.NP sometimes indicate the index of the last enabled
135 * port, at other times, that of the last possible port, so
136 * determining the maximum port number requires looking at
137 * both CAP.NP and port_map.
139 n_ports
= max(ahci_nr_ports(hpriv
->cap
), fls(hpriv
->port_map
));
141 host
= ata_host_alloc_pinfo(dev
, ppi
, n_ports
);
147 host
->private_data
= hpriv
;
149 if (!(hpriv
->cap
& HOST_CAP_SSS
) || ahci_ignore_sss
)
150 host
->flags
|= ATA_HOST_PARALLEL_SCAN
;
152 printk(KERN_INFO
"ahci: SSS flag set, parallel bus scan disabled\n");
154 if (pi
.flags
& ATA_FLAG_EM
)
157 for (i
= 0; i
< host
->n_ports
; i
++) {
158 struct ata_port
*ap
= host
->ports
[i
];
160 ata_port_desc(ap
, "mmio %pR", mem
);
161 ata_port_desc(ap
, "port 0x%x", 0x100 + ap
->port_no
* 0x80);
163 /* set enclosure management message type */
164 if (ap
->flags
& ATA_FLAG_EM
)
165 ap
->em_message_type
= hpriv
->em_msg_type
;
167 /* disabled/not-implemented port */
168 if (!(hpriv
->port_map
& (1 << i
)))
169 ap
->ops
= &ata_dummy_port_ops
;
172 rc
= ahci_reset_controller(host
);
176 ahci_init_controller(host
);
177 ahci_print_info(host
, "platform");
179 rc
= ata_host_activate(host
, irq
, ahci_interrupt
, IRQF_SHARED
,
186 if (pdata
&& pdata
->exit
)
191 static int __devexit
ahci_remove(struct platform_device
*pdev
)
193 struct device
*dev
= &pdev
->dev
;
194 struct ahci_platform_data
*pdata
= dev_get_platdata(dev
);
195 struct ata_host
*host
= dev_get_drvdata(dev
);
197 ata_host_detach(host
);
199 if (pdata
&& pdata
->exit
)
205 static const struct of_device_id ahci_of_match
[] = {
206 { .compatible
= "calxeda,hb-ahci", },
209 MODULE_DEVICE_TABLE(of
, ahci_of_match
);
211 static struct platform_driver ahci_driver
= {
212 .remove
= __devexit_p(ahci_remove
),
215 .owner
= THIS_MODULE
,
216 .of_match_table
= ahci_of_match
,
218 .id_table
= ahci_devtype
,
221 static int __init
ahci_init(void)
223 return platform_driver_probe(&ahci_driver
, ahci_probe
);
225 module_init(ahci_init
);
227 static void __exit
ahci_exit(void)
229 platform_driver_unregister(&ahci_driver
);
231 module_exit(ahci_exit
);
233 MODULE_DESCRIPTION("AHCI SATA platform driver");
234 MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
235 MODULE_LICENSE("GPL");
236 MODULE_ALIAS("platform:ahci");