blob: db24d2a080512b5ec96ce85b7f6de30b1ecbad10 [file] [log] [blame]
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +03001/*
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 Kumarf1e70c22012-08-27 10:37:19 +053015#include <linux/clk.h>
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +030016#include <linux/kernel.h>
Tejun Heofbaf6662010-03-30 02:52:43 +090017#include <linux/gfp.h>
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +030018#include <linux/module.h>
Shiraz Hashim18c25ff2012-03-16 15:49:55 +053019#include <linux/pm.h>
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +030020#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>
Roger Quadros21b5fae2014-02-22 16:53:40 +010025#include <linux/phy/phy.h>
Roger Quadrose708e462014-02-22 16:53:41 +010026#include <linux/pm_runtime.h>
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +030027#include "ahci.h"
28
Brian Norris1896b152012-11-02 00:46:17 -070029static void ahci_host_stop(struct ata_host *host);
30
Richard Zhu8b789d82013-10-15 10:44:54 +080031struct ata_port_operations ahci_platform_ops = {
Brian Norris1896b152012-11-02 00:46:17 -070032 .inherits = &ahci_ops,
33 .host_stop = ahci_host_stop,
34};
Richard Zhu8b789d82013-10-15 10:44:54 +080035EXPORT_SYMBOL_GPL(ahci_platform_ops);
Brian Norris1896b152012-11-02 00:46:17 -070036
Hans de Goedec093e1d2014-02-22 17:22:54 +010037static const struct ata_port_info ahci_port_info = {
38 .flags = AHCI_FLAG_COMMON,
39 .pio_mask = ATA_PIO4,
40 .udma_mask = ATA_UDMA6,
41 .port_ops = &ahci_platform_ops,
Richard Zhu904c04f2011-09-28 15:41:54 +080042};
43
Tejun Heofad16e72010-09-21 09:25:48 +020044static struct scsi_host_template ahci_platform_sht = {
45 AHCI_SHT("ahci_platform"),
46};
47
Hans de Goede156c5882014-02-22 16:53:31 +010048/**
49 * ahci_platform_enable_clks - Enable platform clocks
50 * @hpriv: host private area to store config values
51 *
52 * This function enables all the clks found in hpriv->clks, starting at
53 * index 0. If any clk fails to enable it disables all the clks already
54 * enabled in reverse order, and then returns an error.
55 *
56 * RETURNS:
57 * 0 on success otherwise a negative error code
58 */
59int ahci_platform_enable_clks(struct ahci_host_priv *hpriv)
60{
61 int c, rc;
62
63 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) {
64 rc = clk_prepare_enable(hpriv->clks[c]);
65 if (rc)
66 goto disable_unprepare_clk;
67 }
68 return 0;
69
70disable_unprepare_clk:
71 while (--c >= 0)
72 clk_disable_unprepare(hpriv->clks[c]);
73 return rc;
74}
75EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);
76
77/**
78 * ahci_platform_disable_clks - Disable platform clocks
79 * @hpriv: host private area to store config values
80 *
81 * This function disables all the clks found in hpriv->clks, in reverse
82 * order of ahci_platform_enable_clks (starting at the end of the array).
83 */
84void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
85{
86 int c;
87
88 for (c = AHCI_MAX_CLKS - 1; c >= 0; c--)
89 if (hpriv->clks[c])
90 clk_disable_unprepare(hpriv->clks[c]);
91}
92EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
93
Hans de Goede96a01ba2014-02-22 16:53:33 +010094/**
95 * ahci_platform_enable_resources - Enable platform resources
96 * @hpriv: host private area to store config values
97 *
98 * This function enables all ahci_platform managed resources in the
99 * following order:
100 * 1) Regulator
101 * 2) Clocks (through ahci_platform_enable_clks)
Roger Quadros21b5fae2014-02-22 16:53:40 +0100102 * 3) Phy
Hans de Goede96a01ba2014-02-22 16:53:33 +0100103 *
104 * If resource enabling fails at any point the previous enabled resources
105 * are disabled in reverse order.
106 *
107 * RETURNS:
108 * 0 on success otherwise a negative error code
109 */
110int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
111{
112 int rc;
113
114 if (hpriv->target_pwr) {
115 rc = regulator_enable(hpriv->target_pwr);
116 if (rc)
117 return rc;
118 }
119
120 rc = ahci_platform_enable_clks(hpriv);
121 if (rc)
122 goto disable_regulator;
123
Roger Quadros21b5fae2014-02-22 16:53:40 +0100124 if (hpriv->phy) {
125 rc = phy_init(hpriv->phy);
126 if (rc)
127 goto disable_clks;
128
129 rc = phy_power_on(hpriv->phy);
130 if (rc) {
131 phy_exit(hpriv->phy);
132 goto disable_clks;
133 }
134 }
135
Hans de Goede96a01ba2014-02-22 16:53:33 +0100136 return 0;
137
Roger Quadros21b5fae2014-02-22 16:53:40 +0100138disable_clks:
139 ahci_platform_disable_clks(hpriv);
140
Hans de Goede96a01ba2014-02-22 16:53:33 +0100141disable_regulator:
142 if (hpriv->target_pwr)
143 regulator_disable(hpriv->target_pwr);
144 return rc;
145}
146EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
147
148/**
149 * ahci_platform_disable_resources - Disable platform resources
150 * @hpriv: host private area to store config values
151 *
152 * This function disables all ahci_platform managed resources in the
153 * following order:
Roger Quadros21b5fae2014-02-22 16:53:40 +0100154 * 1) Phy
155 * 2) Clocks (through ahci_platform_disable_clks)
156 * 3) Regulator
Hans de Goede96a01ba2014-02-22 16:53:33 +0100157 */
158void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
159{
Roger Quadros21b5fae2014-02-22 16:53:40 +0100160 if (hpriv->phy) {
161 phy_power_off(hpriv->phy);
162 phy_exit(hpriv->phy);
163 }
164
Hans de Goede96a01ba2014-02-22 16:53:33 +0100165 ahci_platform_disable_clks(hpriv);
166
167 if (hpriv->target_pwr)
168 regulator_disable(hpriv->target_pwr);
169}
170EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
171
Hans de Goede23b07d42014-02-22 16:53:34 +0100172static void ahci_platform_put_resources(struct device *dev, void *res)
Hans de Goede156c5882014-02-22 16:53:31 +0100173{
Hans de Goede23b07d42014-02-22 16:53:34 +0100174 struct ahci_host_priv *hpriv = res;
Hans de Goede156c5882014-02-22 16:53:31 +0100175 int c;
176
Roger Quadrose708e462014-02-22 16:53:41 +0100177 if (hpriv->got_runtime_pm) {
178 pm_runtime_put_sync(dev);
179 pm_runtime_disable(dev);
180 }
181
Hans de Goede156c5882014-02-22 16:53:31 +0100182 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
183 clk_put(hpriv->clks[c]);
184}
185
Hans de Goede23b07d42014-02-22 16:53:34 +0100186/**
187 * ahci_platform_get_resources - Get platform resources
188 * @pdev: platform device to get resources for
189 *
190 * This function allocates an ahci_host_priv struct, and gets the following
191 * resources, storing a reference to them inside the returned struct:
192 *
193 * 1) mmio registers (IORESOURCE_MEM 0, mandatory)
194 * 2) regulator for controlling the targets power (optional)
195 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
196 * or for non devicetree enabled platforms a single clock
Roger Quadros21b5fae2014-02-22 16:53:40 +0100197 * 4) phy (optional)
Hans de Goede23b07d42014-02-22 16:53:34 +0100198 *
199 * RETURNS:
200 * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
201 */
202struct ahci_host_priv *ahci_platform_get_resources(
203 struct platform_device *pdev)
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300204{
205 struct device *dev = &pdev->dev;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300206 struct ahci_host_priv *hpriv;
Hans de Goede156c5882014-02-22 16:53:31 +0100207 struct clk *clk;
Hans de Goede23b07d42014-02-22 16:53:34 +0100208 int i, rc = -ENOMEM;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300209
Hans de Goede23b07d42014-02-22 16:53:34 +0100210 if (!devres_open_group(dev, NULL, GFP_KERNEL))
211 return ERR_PTR(-ENOMEM);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300212
Hans de Goede23b07d42014-02-22 16:53:34 +0100213 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv),
214 GFP_KERNEL);
215 if (!hpriv)
216 goto err_out;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300217
Hans de Goede23b07d42014-02-22 16:53:34 +0100218 devres_add(dev, hpriv);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300219
Hans de Goede23b07d42014-02-22 16:53:34 +0100220 hpriv->mmio = devm_ioremap_resource(dev,
221 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300222 if (!hpriv->mmio) {
Hans de Goede23b07d42014-02-22 16:53:34 +0100223 dev_err(dev, "no mmio space\n");
224 goto err_out;
Jassi Brar08354802010-06-25 18:21:19 +0900225 }
226
Hans de Goede4b3e6032014-02-22 16:53:32 +0100227 hpriv->target_pwr = devm_regulator_get_optional(dev, "target");
228 if (IS_ERR(hpriv->target_pwr)) {
229 rc = PTR_ERR(hpriv->target_pwr);
230 if (rc == -EPROBE_DEFER)
Hans de Goede23b07d42014-02-22 16:53:34 +0100231 goto err_out;
Hans de Goede4b3e6032014-02-22 16:53:32 +0100232 hpriv->target_pwr = NULL;
233 }
234
Hans de Goede156c5882014-02-22 16:53:31 +0100235 for (i = 0; i < AHCI_MAX_CLKS; i++) {
236 /*
237 * For now we must use clk_get(dev, NULL) for the first clock,
238 * because some platforms (da850, spear13xx) are not yet
239 * converted to use devicetree for clocks. For new platforms
240 * this is equivalent to of_clk_get(dev->of_node, 0).
241 */
242 if (i == 0)
243 clk = clk_get(dev, NULL);
244 else
245 clk = of_clk_get(dev->of_node, i);
246
247 if (IS_ERR(clk)) {
248 rc = PTR_ERR(clk);
249 if (rc == -EPROBE_DEFER)
Hans de Goede23b07d42014-02-22 16:53:34 +0100250 goto err_out;
Hans de Goede156c5882014-02-22 16:53:31 +0100251 break;
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530252 }
Hans de Goede156c5882014-02-22 16:53:31 +0100253 hpriv->clks[i] = clk;
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530254 }
255
Roger Quadros21b5fae2014-02-22 16:53:40 +0100256 hpriv->phy = devm_phy_get(dev, "sata-phy");
257 if (IS_ERR(hpriv->phy)) {
258 rc = PTR_ERR(hpriv->phy);
259 switch (rc) {
260 case -ENODEV:
261 case -ENOSYS:
262 /* continue normally */
263 hpriv->phy = NULL;
264 break;
265
266 case -EPROBE_DEFER:
267 goto err_out;
268
269 default:
270 dev_err(dev, "couldn't get sata-phy\n");
271 goto err_out;
272 }
273 }
274
Roger Quadrose708e462014-02-22 16:53:41 +0100275 pm_runtime_enable(dev);
276 pm_runtime_get_sync(dev);
277 hpriv->got_runtime_pm = true;
278
Hans de Goede23b07d42014-02-22 16:53:34 +0100279 devres_remove_group(dev, NULL);
280 return hpriv;
Hans de Goede156c5882014-02-22 16:53:31 +0100281
Hans de Goede23b07d42014-02-22 16:53:34 +0100282err_out:
283 devres_release_group(dev, NULL);
284 return ERR_PTR(rc);
285}
286EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
287
288/**
289 * ahci_platform_init_host - Bring up an ahci-platform host
290 * @pdev: platform device pointer for the host
291 * @hpriv: ahci-host private data for the host
292 * @pi_template: template for the ata_port_info to use
293 * @force_port_map: param passed to ahci_save_initial_config
294 * @mask_port_map: param passed to ahci_save_initial_config
295 *
296 * This function does all the usual steps needed to bring up an
297 * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
298 * must be initialized / enabled before calling this.
299 *
300 * RETURNS:
301 * 0 on success otherwise a negative error code
302 */
303int ahci_platform_init_host(struct platform_device *pdev,
304 struct ahci_host_priv *hpriv,
305 const struct ata_port_info *pi_template,
306 unsigned int force_port_map,
307 unsigned int mask_port_map)
308{
309 struct device *dev = &pdev->dev;
310 struct ata_port_info pi = *pi_template;
311 const struct ata_port_info *ppi[] = { &pi, NULL };
312 struct ata_host *host;
313 int i, irq, n_ports, rc;
314
315 irq = platform_get_irq(pdev, 0);
316 if (irq <= 0) {
317 dev_err(dev, "no irq\n");
318 return -EINVAL;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300319 }
320
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300321 /* prepare host */
Hans de Goede23b07d42014-02-22 16:53:34 +0100322 hpriv->flags |= (unsigned long)pi.private_data;
323
324 ahci_save_initial_config(dev, hpriv, force_port_map, mask_port_map);
325
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300326 if (hpriv->cap & HOST_CAP_NCQ)
327 pi.flags |= ATA_FLAG_NCQ;
328
329 if (hpriv->cap & HOST_CAP_PMP)
330 pi.flags |= ATA_FLAG_PMP;
331
332 ahci_set_em_messages(hpriv, &pi);
333
334 /* CAP.NP sometimes indicate the index of the last enabled
335 * port, at other times, that of the last possible port, so
336 * determining the maximum port number requires looking at
337 * both CAP.NP and port_map.
338 */
339 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
340
341 host = ata_host_alloc_pinfo(dev, ppi, n_ports);
Hans de Goede23b07d42014-02-22 16:53:34 +0100342 if (!host)
343 return -ENOMEM;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300344
345 host->private_data = hpriv;
346
347 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
348 host->flags |= ATA_HOST_PARALLEL_SCAN;
349 else
Jingoo Han0fed4c02013-10-05 09:15:59 +0900350 dev_info(dev, "SSS flag set, parallel bus scan disabled\n");
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300351
352 if (pi.flags & ATA_FLAG_EM)
353 ahci_reset_em(host);
354
355 for (i = 0; i < host->n_ports; i++) {
356 struct ata_port *ap = host->ports[i];
357
Hans de Goede23b07d42014-02-22 16:53:34 +0100358 ata_port_desc(ap, "mmio %pR",
359 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300360 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
361
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300362 /* set enclosure management message type */
363 if (ap->flags & ATA_FLAG_EM)
Jeff Garzik55787182010-05-14 17:23:37 -0400364 ap->em_message_type = hpriv->em_msg_type;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300365
366 /* disabled/not-implemented port */
367 if (!(hpriv->port_map & (1 << i)))
368 ap->ops = &ata_dummy_port_ops;
369 }
370
371 rc = ahci_reset_controller(host);
372 if (rc)
Hans de Goede23b07d42014-02-22 16:53:34 +0100373 return rc;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300374
375 ahci_init_controller(host);
376 ahci_print_info(host, "platform");
377
Hans de Goede23b07d42014-02-22 16:53:34 +0100378 return ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
379 &ahci_platform_sht);
380}
381EXPORT_SYMBOL_GPL(ahci_platform_init_host);
382
383static int ahci_probe(struct platform_device *pdev)
384{
385 struct device *dev = &pdev->dev;
386 struct ahci_platform_data *pdata = dev_get_platdata(dev);
Hans de Goede23b07d42014-02-22 16:53:34 +0100387 struct ahci_host_priv *hpriv;
388 int rc;
389
390 hpriv = ahci_platform_get_resources(pdev);
391 if (IS_ERR(hpriv))
392 return PTR_ERR(hpriv);
393
394 rc = ahci_platform_enable_resources(hpriv);
395 if (rc)
396 return rc;
397
398 /*
399 * Some platforms might need to prepare for mmio region access,
400 * which could be done in the following init call. So, the mmio
401 * region shouldn't be accessed before init (if provided) has
402 * returned successfully.
403 */
404 if (pdata && pdata->init) {
405 rc = pdata->init(dev, hpriv->mmio);
406 if (rc)
407 goto disable_resources;
408 }
409
Hans de Goede6ef95e82014-02-22 17:22:55 +0100410 rc = ahci_platform_init_host(pdev, hpriv, &ahci_port_info, 0, 0);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300411 if (rc)
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530412 goto pdata_exit;
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300413
414 return 0;
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530415pdata_exit:
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300416 if (pdata && pdata->exit)
417 pdata->exit(dev);
Hans de Goede96a01ba2014-02-22 16:53:33 +0100418disable_resources:
419 ahci_platform_disable_resources(hpriv);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300420 return rc;
421}
422
Brian Norris1896b152012-11-02 00:46:17 -0700423static void ahci_host_stop(struct ata_host *host)
424{
425 struct device *dev = host->dev;
426 struct ahci_platform_data *pdata = dev_get_platdata(dev);
427 struct ahci_host_priv *hpriv = host->private_data;
428
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300429 if (pdata && pdata->exit)
430 pdata->exit(dev);
431
Hans de Goede96a01ba2014-02-22 16:53:33 +0100432 ahci_platform_disable_resources(hpriv);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300433}
434
Yuanhan Liu29448ec2012-10-16 22:59:01 +0800435#ifdef CONFIG_PM_SLEEP
Hans de Goede648cb6f2014-02-22 16:53:35 +0100436/**
437 * ahci_platform_suspend_host - Suspend an ahci-platform host
438 * @dev: device pointer for the host
439 *
440 * This function does all the usual steps needed to suspend an
441 * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
442 * must be disabled after calling this.
443 *
444 * RETURNS:
445 * 0 on success otherwise a negative error code
446 */
447int ahci_platform_suspend_host(struct device *dev)
Brian Norris17ab5942011-11-18 11:10:10 -0800448{
Brian Norris17ab5942011-11-18 11:10:10 -0800449 struct ata_host *host = dev_get_drvdata(dev);
450 struct ahci_host_priv *hpriv = host->private_data;
451 void __iomem *mmio = hpriv->mmio;
452 u32 ctl;
Brian Norris17ab5942011-11-18 11:10:10 -0800453
454 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
455 dev_err(dev, "firmware update required for suspend/resume\n");
456 return -EIO;
457 }
458
459 /*
460 * AHCI spec rev1.1 section 8.3.3:
461 * Software must disable interrupts prior to requesting a
462 * transition of the HBA to D3 state.
463 */
464 ctl = readl(mmio + HOST_CTL);
465 ctl &= ~HOST_IRQ_EN;
466 writel(ctl, mmio + HOST_CTL);
467 readl(mmio + HOST_CTL); /* flush */
468
Hans de Goede648cb6f2014-02-22 16:53:35 +0100469 return ata_host_suspend(host, PMSG_SUSPEND);
470}
471EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
472
473/**
474 * ahci_platform_resume_host - Resume an ahci-platform host
475 * @dev: device pointer for the host
476 *
477 * This function does all the usual steps needed to resume an ahci-platform
478 * host, note any necessary resources (ie clks, phy, etc.) must be
479 * initialized / enabled before calling this.
480 *
481 * RETURNS:
482 * 0 on success otherwise a negative error code
483 */
484int ahci_platform_resume_host(struct device *dev)
485{
486 struct ata_host *host = dev_get_drvdata(dev);
487 int rc;
488
489 if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
490 rc = ahci_reset_controller(host);
491 if (rc)
492 return rc;
493
494 ahci_init_controller(host);
495 }
496
497 ata_host_resume(host);
498
499 return 0;
500}
501EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
502
503/**
504 * ahci_platform_suspend - Suspend an ahci-platform device
505 * @dev: the platform device to suspend
506 *
507 * This function suspends the host associated with the device, followed by
508 * disabling all the resources of the device.
509 *
510 * RETURNS:
511 * 0 on success otherwise a negative error code
512 */
513int ahci_platform_suspend(struct device *dev)
514{
515 struct ahci_platform_data *pdata = dev_get_platdata(dev);
516 struct ata_host *host = dev_get_drvdata(dev);
517 struct ahci_host_priv *hpriv = host->private_data;
518 int rc;
519
520 rc = ahci_platform_suspend_host(dev);
Brian Norris17ab5942011-11-18 11:10:10 -0800521 if (rc)
522 return rc;
523
524 if (pdata && pdata->suspend)
525 return pdata->suspend(dev);
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530526
Hans de Goede96a01ba2014-02-22 16:53:33 +0100527 ahci_platform_disable_resources(hpriv);
Hans de Goede4b3e6032014-02-22 16:53:32 +0100528
Brian Norris17ab5942011-11-18 11:10:10 -0800529 return 0;
530}
Hans de Goede648cb6f2014-02-22 16:53:35 +0100531EXPORT_SYMBOL_GPL(ahci_platform_suspend);
Brian Norris17ab5942011-11-18 11:10:10 -0800532
Hans de Goede648cb6f2014-02-22 16:53:35 +0100533/**
534 * ahci_platform_resume - Resume an ahci-platform device
535 * @dev: the platform device to resume
536 *
537 * This function enables all the resources of the device followed by
538 * resuming the host associated with the device.
539 *
540 * RETURNS:
541 * 0 on success otherwise a negative error code
542 */
543int ahci_platform_resume(struct device *dev)
Brian Norris17ab5942011-11-18 11:10:10 -0800544{
545 struct ahci_platform_data *pdata = dev_get_platdata(dev);
546 struct ata_host *host = dev_get_drvdata(dev);
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530547 struct ahci_host_priv *hpriv = host->private_data;
Brian Norris17ab5942011-11-18 11:10:10 -0800548 int rc;
549
Hans de Goede96a01ba2014-02-22 16:53:33 +0100550 rc = ahci_platform_enable_resources(hpriv);
Hans de Goede156c5882014-02-22 16:53:31 +0100551 if (rc)
Hans de Goede96a01ba2014-02-22 16:53:33 +0100552 return rc;
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530553
Brian Norris17ab5942011-11-18 11:10:10 -0800554 if (pdata && pdata->resume) {
555 rc = pdata->resume(dev);
556 if (rc)
Hans de Goede96a01ba2014-02-22 16:53:33 +0100557 goto disable_resources;
Brian Norris17ab5942011-11-18 11:10:10 -0800558 }
559
Hans de Goede648cb6f2014-02-22 16:53:35 +0100560 rc = ahci_platform_resume_host(dev);
561 if (rc)
562 goto disable_resources;
Brian Norris17ab5942011-11-18 11:10:10 -0800563
Roger Quadrose708e462014-02-22 16:53:41 +0100564 /* We resumed so update PM runtime state */
565 pm_runtime_disable(dev);
566 pm_runtime_set_active(dev);
567 pm_runtime_enable(dev);
568
Brian Norris17ab5942011-11-18 11:10:10 -0800569 return 0;
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530570
Hans de Goede96a01ba2014-02-22 16:53:33 +0100571disable_resources:
572 ahci_platform_disable_resources(hpriv);
Viresh Kumarf1e70c22012-08-27 10:37:19 +0530573
574 return rc;
Brian Norris17ab5942011-11-18 11:10:10 -0800575}
Hans de Goede648cb6f2014-02-22 16:53:35 +0100576EXPORT_SYMBOL_GPL(ahci_platform_resume);
Brian Norris17ab5942011-11-18 11:10:10 -0800577#endif
578
Hans de Goede648cb6f2014-02-22 16:53:35 +0100579static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
580 ahci_platform_resume);
Shiraz Hashim18c25ff2012-03-16 15:49:55 +0530581
Rob Herring02aac312010-11-03 21:04:59 -0500582static const struct of_device_id ahci_of_match[] = {
Viresh Kumar5f098a32012-04-21 17:40:12 +0530583 { .compatible = "snps,spear-ahci", },
Girish K S1e8f5f72013-04-16 14:58:02 +0530584 { .compatible = "snps,exynos5440-ahci", },
Alistair Popple2435dcb2013-11-22 13:08:29 +1100585 { .compatible = "ibm,476gtr-ahci", },
Roger Quadrosc4311472014-02-22 16:53:38 +0100586 { .compatible = "snps,dwc-ahci", },
Rob Herring02aac312010-11-03 21:04:59 -0500587 {},
588};
589MODULE_DEVICE_TABLE(of, ahci_of_match);
590
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300591static struct platform_driver ahci_driver = {
Brian Norris941c77f2012-11-02 00:46:15 -0700592 .probe = ahci_probe,
Brian Norris83291d62012-11-02 00:46:19 -0700593 .remove = ata_platform_remove_one,
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300594 .driver = {
595 .name = "ahci",
596 .owner = THIS_MODULE,
Rob Herring02aac312010-11-03 21:04:59 -0500597 .of_match_table = ahci_of_match,
Brian Norris17ab5942011-11-18 11:10:10 -0800598 .pm = &ahci_pm_ops,
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300599 },
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300600};
Brian Norris9a99e472012-11-02 00:46:16 -0700601module_platform_driver(ahci_driver);
Anton Vorontsov1c2a49f2010-03-04 20:06:06 +0300602
603MODULE_DESCRIPTION("AHCI SATA platform driver");
604MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
605MODULE_LICENSE("GPL");
606MODULE_ALIAS("platform:ahci");