Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 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 | |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 15 | #include <linux/clk.h> |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Tejun Heo | fbaf666 | 2010-03-30 02:52:43 +0900 | [diff] [blame] | 17 | #include <linux/gfp.h> |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 18 | #include <linux/module.h> |
Shiraz Hashim | 18c25ff | 2012-03-16 15:49:55 +0530 | [diff] [blame] | 19 | #include <linux/pm.h> |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/libata.h> |
| 24 | #include <linux/ahci_platform.h> |
| 25 | #include "ahci.h" |
| 26 | |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 27 | static void ahci_host_stop(struct ata_host *host); |
| 28 | |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 29 | enum ahci_type { |
| 30 | AHCI, /* standard platform ahci */ |
| 31 | IMX53_AHCI, /* ahci on i.mx53 */ |
Brian Norris | d408e2b | 2012-02-21 10:38:44 -0800 | [diff] [blame] | 32 | STRICT_AHCI, /* delayed DMA engine start */ |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | static struct platform_device_id ahci_devtype[] = { |
| 36 | { |
| 37 | .name = "ahci", |
| 38 | .driver_data = AHCI, |
| 39 | }, { |
| 40 | .name = "imx53-ahci", |
| 41 | .driver_data = IMX53_AHCI, |
| 42 | }, { |
Brian Norris | d408e2b | 2012-02-21 10:38:44 -0800 | [diff] [blame] | 43 | .name = "strict-ahci", |
| 44 | .driver_data = STRICT_AHCI, |
| 45 | }, { |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 46 | /* sentinel */ |
| 47 | } |
| 48 | }; |
| 49 | MODULE_DEVICE_TABLE(platform, ahci_devtype); |
| 50 | |
Richard Zhu | 8b789d8 | 2013-10-15 10:44:54 +0800 | [diff] [blame] | 51 | struct ata_port_operations ahci_platform_ops = { |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 52 | .inherits = &ahci_ops, |
| 53 | .host_stop = ahci_host_stop, |
| 54 | }; |
Richard Zhu | 8b789d8 | 2013-10-15 10:44:54 +0800 | [diff] [blame] | 55 | EXPORT_SYMBOL_GPL(ahci_platform_ops); |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 56 | |
Brian Norris | 071d3ad | 2012-12-05 23:44:20 -0800 | [diff] [blame] | 57 | static struct ata_port_operations ahci_platform_retry_srst_ops = { |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 58 | .inherits = &ahci_pmp_retry_srst_ops, |
| 59 | .host_stop = ahci_host_stop, |
| 60 | }; |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 61 | |
| 62 | static const struct ata_port_info ahci_port_info[] = { |
| 63 | /* by features */ |
| 64 | [AHCI] = { |
| 65 | .flags = AHCI_FLAG_COMMON, |
| 66 | .pio_mask = ATA_PIO4, |
| 67 | .udma_mask = ATA_UDMA6, |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 68 | .port_ops = &ahci_platform_ops, |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 69 | }, |
| 70 | [IMX53_AHCI] = { |
| 71 | .flags = AHCI_FLAG_COMMON, |
| 72 | .pio_mask = ATA_PIO4, |
| 73 | .udma_mask = ATA_UDMA6, |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 74 | .port_ops = &ahci_platform_retry_srst_ops, |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 75 | }, |
Brian Norris | d408e2b | 2012-02-21 10:38:44 -0800 | [diff] [blame] | 76 | [STRICT_AHCI] = { |
| 77 | AHCI_HFLAGS (AHCI_HFLAG_DELAY_ENGINE), |
| 78 | .flags = AHCI_FLAG_COMMON, |
| 79 | .pio_mask = ATA_PIO4, |
| 80 | .udma_mask = ATA_UDMA6, |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 81 | .port_ops = &ahci_platform_ops, |
Brian Norris | d408e2b | 2012-02-21 10:38:44 -0800 | [diff] [blame] | 82 | }, |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 83 | }; |
| 84 | |
Tejun Heo | fad16e7 | 2010-09-21 09:25:48 +0200 | [diff] [blame] | 85 | static struct scsi_host_template ahci_platform_sht = { |
| 86 | AHCI_SHT("ahci_platform"), |
| 87 | }; |
| 88 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 89 | /** |
| 90 | * ahci_platform_enable_clks - Enable platform clocks |
| 91 | * @hpriv: host private area to store config values |
| 92 | * |
| 93 | * This function enables all the clks found in hpriv->clks, starting at |
| 94 | * index 0. If any clk fails to enable it disables all the clks already |
| 95 | * enabled in reverse order, and then returns an error. |
| 96 | * |
| 97 | * RETURNS: |
| 98 | * 0 on success otherwise a negative error code |
| 99 | */ |
| 100 | int ahci_platform_enable_clks(struct ahci_host_priv *hpriv) |
| 101 | { |
| 102 | int c, rc; |
| 103 | |
| 104 | for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) { |
| 105 | rc = clk_prepare_enable(hpriv->clks[c]); |
| 106 | if (rc) |
| 107 | goto disable_unprepare_clk; |
| 108 | } |
| 109 | return 0; |
| 110 | |
| 111 | disable_unprepare_clk: |
| 112 | while (--c >= 0) |
| 113 | clk_disable_unprepare(hpriv->clks[c]); |
| 114 | return rc; |
| 115 | } |
| 116 | EXPORT_SYMBOL_GPL(ahci_platform_enable_clks); |
| 117 | |
| 118 | /** |
| 119 | * ahci_platform_disable_clks - Disable platform clocks |
| 120 | * @hpriv: host private area to store config values |
| 121 | * |
| 122 | * This function disables all the clks found in hpriv->clks, in reverse |
| 123 | * order of ahci_platform_enable_clks (starting at the end of the array). |
| 124 | */ |
| 125 | void ahci_platform_disable_clks(struct ahci_host_priv *hpriv) |
| 126 | { |
| 127 | int c; |
| 128 | |
| 129 | for (c = AHCI_MAX_CLKS - 1; c >= 0; c--) |
| 130 | if (hpriv->clks[c]) |
| 131 | clk_disable_unprepare(hpriv->clks[c]); |
| 132 | } |
| 133 | EXPORT_SYMBOL_GPL(ahci_platform_disable_clks); |
| 134 | |
| 135 | static void ahci_put_clks(struct ahci_host_priv *hpriv) |
| 136 | { |
| 137 | int c; |
| 138 | |
| 139 | for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) |
| 140 | clk_put(hpriv->clks[c]); |
| 141 | } |
| 142 | |
Greg Kroah-Hartman | 0ec2491 | 2012-12-21 13:19:58 -0800 | [diff] [blame] | 143 | static int ahci_probe(struct platform_device *pdev) |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 144 | { |
| 145 | struct device *dev = &pdev->dev; |
JiSheng Zhang | 0034561 | 2011-10-31 21:20:10 +0800 | [diff] [blame] | 146 | struct ahci_platform_data *pdata = dev_get_platdata(dev); |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 147 | const struct platform_device_id *id = platform_get_device_id(pdev); |
Rob Herring | ff95613 | 2011-11-15 21:00:56 -0600 | [diff] [blame] | 148 | struct ata_port_info pi = ahci_port_info[id ? id->driver_data : 0]; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 149 | const struct ata_port_info *ppi[] = { &pi, NULL }; |
| 150 | struct ahci_host_priv *hpriv; |
| 151 | struct ata_host *host; |
| 152 | struct resource *mem; |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 153 | struct clk *clk; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 154 | int irq; |
| 155 | int n_ports; |
| 156 | int i; |
| 157 | int rc; |
| 158 | |
| 159 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 160 | if (!mem) { |
| 161 | dev_err(dev, "no mmio space\n"); |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
| 165 | irq = platform_get_irq(pdev, 0); |
| 166 | if (irq <= 0) { |
| 167 | dev_err(dev, "no irq\n"); |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 171 | if (pdata && pdata->ata_port_info) |
| 172 | pi = *pdata->ata_port_info; |
| 173 | |
| 174 | hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); |
| 175 | if (!hpriv) { |
Jassi Brar | 0835480 | 2010-06-25 18:21:19 +0900 | [diff] [blame] | 176 | dev_err(dev, "can't alloc ahci_host_priv\n"); |
| 177 | return -ENOMEM; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | hpriv->flags |= (unsigned long)pi.private_data; |
| 181 | |
| 182 | hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem)); |
| 183 | if (!hpriv->mmio) { |
| 184 | dev_err(dev, "can't map %pR\n", mem); |
Jassi Brar | 0835480 | 2010-06-25 18:21:19 +0900 | [diff] [blame] | 185 | return -ENOMEM; |
| 186 | } |
| 187 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 188 | for (i = 0; i < AHCI_MAX_CLKS; i++) { |
| 189 | /* |
| 190 | * For now we must use clk_get(dev, NULL) for the first clock, |
| 191 | * because some platforms (da850, spear13xx) are not yet |
| 192 | * converted to use devicetree for clocks. For new platforms |
| 193 | * this is equivalent to of_clk_get(dev->of_node, 0). |
| 194 | */ |
| 195 | if (i == 0) |
| 196 | clk = clk_get(dev, NULL); |
| 197 | else |
| 198 | clk = of_clk_get(dev->of_node, i); |
| 199 | |
| 200 | if (IS_ERR(clk)) { |
| 201 | rc = PTR_ERR(clk); |
| 202 | if (rc == -EPROBE_DEFER) |
| 203 | goto free_clk; |
| 204 | break; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 205 | } |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 206 | hpriv->clks[i] = clk; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 207 | } |
| 208 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 209 | rc = ahci_enable_clks(dev, hpriv); |
| 210 | if (rc) |
| 211 | goto free_clk; |
| 212 | |
Jassi Brar | 0835480 | 2010-06-25 18:21:19 +0900 | [diff] [blame] | 213 | /* |
| 214 | * Some platforms might need to prepare for mmio region access, |
| 215 | * which could be done in the following init call. So, the mmio |
| 216 | * region shouldn't be accessed before init (if provided) has |
| 217 | * returned successfully. |
| 218 | */ |
| 219 | if (pdata && pdata->init) { |
| 220 | rc = pdata->init(dev, hpriv->mmio); |
| 221 | if (rc) |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 222 | goto disable_unprepare_clk; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | ahci_save_initial_config(dev, hpriv, |
| 226 | pdata ? pdata->force_port_map : 0, |
| 227 | pdata ? pdata->mask_port_map : 0); |
| 228 | |
| 229 | /* prepare host */ |
| 230 | if (hpriv->cap & HOST_CAP_NCQ) |
| 231 | pi.flags |= ATA_FLAG_NCQ; |
| 232 | |
| 233 | if (hpriv->cap & HOST_CAP_PMP) |
| 234 | pi.flags |= ATA_FLAG_PMP; |
| 235 | |
| 236 | ahci_set_em_messages(hpriv, &pi); |
| 237 | |
| 238 | /* CAP.NP sometimes indicate the index of the last enabled |
| 239 | * port, at other times, that of the last possible port, so |
| 240 | * determining the maximum port number requires looking at |
| 241 | * both CAP.NP and port_map. |
| 242 | */ |
| 243 | n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); |
| 244 | |
| 245 | host = ata_host_alloc_pinfo(dev, ppi, n_ports); |
| 246 | if (!host) { |
| 247 | rc = -ENOMEM; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 248 | goto pdata_exit; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | host->private_data = hpriv; |
| 252 | |
| 253 | if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) |
| 254 | host->flags |= ATA_HOST_PARALLEL_SCAN; |
| 255 | else |
Jingoo Han | 0fed4c0 | 2013-10-05 09:15:59 +0900 | [diff] [blame] | 256 | dev_info(dev, "SSS flag set, parallel bus scan disabled\n"); |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 257 | |
| 258 | if (pi.flags & ATA_FLAG_EM) |
| 259 | ahci_reset_em(host); |
| 260 | |
| 261 | for (i = 0; i < host->n_ports; i++) { |
| 262 | struct ata_port *ap = host->ports[i]; |
| 263 | |
| 264 | ata_port_desc(ap, "mmio %pR", mem); |
| 265 | ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); |
| 266 | |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 267 | /* set enclosure management message type */ |
| 268 | if (ap->flags & ATA_FLAG_EM) |
Jeff Garzik | 5578718 | 2010-05-14 17:23:37 -0400 | [diff] [blame] | 269 | ap->em_message_type = hpriv->em_msg_type; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 270 | |
| 271 | /* disabled/not-implemented port */ |
| 272 | if (!(hpriv->port_map & (1 << i))) |
| 273 | ap->ops = &ata_dummy_port_ops; |
| 274 | } |
| 275 | |
| 276 | rc = ahci_reset_controller(host); |
| 277 | if (rc) |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 278 | goto pdata_exit; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 279 | |
| 280 | ahci_init_controller(host); |
| 281 | ahci_print_info(host, "platform"); |
| 282 | |
| 283 | rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED, |
Tejun Heo | fad16e7 | 2010-09-21 09:25:48 +0200 | [diff] [blame] | 284 | &ahci_platform_sht); |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 285 | if (rc) |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 286 | goto pdata_exit; |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 287 | |
| 288 | return 0; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 289 | pdata_exit: |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 290 | if (pdata && pdata->exit) |
| 291 | pdata->exit(dev); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 292 | disable_unprepare_clk: |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 293 | ahci_disable_clks(hpriv); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 294 | free_clk: |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 295 | ahci_put_clks(hpriv); |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 296 | return rc; |
| 297 | } |
| 298 | |
Brian Norris | 1896b15 | 2012-11-02 00:46:17 -0700 | [diff] [blame] | 299 | static void ahci_host_stop(struct ata_host *host) |
| 300 | { |
| 301 | struct device *dev = host->dev; |
| 302 | struct ahci_platform_data *pdata = dev_get_platdata(dev); |
| 303 | struct ahci_host_priv *hpriv = host->private_data; |
| 304 | |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 305 | if (pdata && pdata->exit) |
| 306 | pdata->exit(dev); |
| 307 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 308 | ahci_disable_clks(hpriv); |
| 309 | ahci_put_clks(hpriv); |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 310 | } |
| 311 | |
Yuanhan Liu | 29448ec | 2012-10-16 22:59:01 +0800 | [diff] [blame] | 312 | #ifdef CONFIG_PM_SLEEP |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 313 | static int ahci_suspend(struct device *dev) |
| 314 | { |
| 315 | struct ahci_platform_data *pdata = dev_get_platdata(dev); |
| 316 | struct ata_host *host = dev_get_drvdata(dev); |
| 317 | struct ahci_host_priv *hpriv = host->private_data; |
| 318 | void __iomem *mmio = hpriv->mmio; |
| 319 | u32 ctl; |
| 320 | int rc; |
| 321 | |
| 322 | if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { |
| 323 | dev_err(dev, "firmware update required for suspend/resume\n"); |
| 324 | return -EIO; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * AHCI spec rev1.1 section 8.3.3: |
| 329 | * Software must disable interrupts prior to requesting a |
| 330 | * transition of the HBA to D3 state. |
| 331 | */ |
| 332 | ctl = readl(mmio + HOST_CTL); |
| 333 | ctl &= ~HOST_IRQ_EN; |
| 334 | writel(ctl, mmio + HOST_CTL); |
| 335 | readl(mmio + HOST_CTL); /* flush */ |
| 336 | |
| 337 | rc = ata_host_suspend(host, PMSG_SUSPEND); |
| 338 | if (rc) |
| 339 | return rc; |
| 340 | |
| 341 | if (pdata && pdata->suspend) |
| 342 | return pdata->suspend(dev); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 343 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 344 | ahci_disable_clks(hpriv); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 345 | |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static int ahci_resume(struct device *dev) |
| 350 | { |
| 351 | struct ahci_platform_data *pdata = dev_get_platdata(dev); |
| 352 | struct ata_host *host = dev_get_drvdata(dev); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 353 | struct ahci_host_priv *hpriv = host->private_data; |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 354 | int rc; |
| 355 | |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 356 | rc = ahci_enable_clks(dev, hpriv); |
| 357 | if (rc) |
| 358 | return rc; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 359 | |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 360 | if (pdata && pdata->resume) { |
| 361 | rc = pdata->resume(dev); |
| 362 | if (rc) |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 363 | goto disable_unprepare_clk; |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | if (dev->power.power_state.event == PM_EVENT_SUSPEND) { |
| 367 | rc = ahci_reset_controller(host); |
| 368 | if (rc) |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 369 | goto disable_unprepare_clk; |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 370 | |
| 371 | ahci_init_controller(host); |
| 372 | } |
| 373 | |
| 374 | ata_host_resume(host); |
| 375 | |
| 376 | return 0; |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 377 | |
| 378 | disable_unprepare_clk: |
Hans de Goede | 156c588 | 2014-02-22 16:53:31 +0100 | [diff] [blame^] | 379 | ahci_disable_clks(hpriv); |
Viresh Kumar | f1e70c2 | 2012-08-27 10:37:19 +0530 | [diff] [blame] | 380 | |
| 381 | return rc; |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 382 | } |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 383 | #endif |
| 384 | |
Brian Norris | 071d3ad | 2012-12-05 23:44:20 -0800 | [diff] [blame] | 385 | static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume); |
Shiraz Hashim | 18c25ff | 2012-03-16 15:49:55 +0530 | [diff] [blame] | 386 | |
Rob Herring | 02aac31 | 2010-11-03 21:04:59 -0500 | [diff] [blame] | 387 | static const struct of_device_id ahci_of_match[] = { |
Viresh Kumar | 5f098a3 | 2012-04-21 17:40:12 +0530 | [diff] [blame] | 388 | { .compatible = "snps,spear-ahci", }, |
Girish K S | 1e8f5f7 | 2013-04-16 14:58:02 +0530 | [diff] [blame] | 389 | { .compatible = "snps,exynos5440-ahci", }, |
Alistair Popple | 2435dcb | 2013-11-22 13:08:29 +1100 | [diff] [blame] | 390 | { .compatible = "ibm,476gtr-ahci", }, |
Rob Herring | 02aac31 | 2010-11-03 21:04:59 -0500 | [diff] [blame] | 391 | {}, |
| 392 | }; |
| 393 | MODULE_DEVICE_TABLE(of, ahci_of_match); |
| 394 | |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 395 | static struct platform_driver ahci_driver = { |
Brian Norris | 941c77f | 2012-11-02 00:46:15 -0700 | [diff] [blame] | 396 | .probe = ahci_probe, |
Brian Norris | 83291d6 | 2012-11-02 00:46:19 -0700 | [diff] [blame] | 397 | .remove = ata_platform_remove_one, |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 398 | .driver = { |
| 399 | .name = "ahci", |
| 400 | .owner = THIS_MODULE, |
Rob Herring | 02aac31 | 2010-11-03 21:04:59 -0500 | [diff] [blame] | 401 | .of_match_table = ahci_of_match, |
Brian Norris | 17ab594 | 2011-11-18 11:10:10 -0800 | [diff] [blame] | 402 | .pm = &ahci_pm_ops, |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 403 | }, |
Richard Zhu | 904c04f | 2011-09-28 15:41:54 +0800 | [diff] [blame] | 404 | .id_table = ahci_devtype, |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 405 | }; |
Brian Norris | 9a99e47 | 2012-11-02 00:46:16 -0700 | [diff] [blame] | 406 | module_platform_driver(ahci_driver); |
Anton Vorontsov | 1c2a49f | 2010-03-04 20:06:06 +0300 | [diff] [blame] | 407 | |
| 408 | MODULE_DESCRIPTION("AHCI SATA platform driver"); |
| 409 | MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>"); |
| 410 | MODULE_LICENSE("GPL"); |
| 411 | MODULE_ALIAS("platform:ahci"); |