1 From 3b5db9d024f173c30ef4060c31bb8e9fbd194cc1 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Mon, 2 Dec 2013 16:13:32 +0100
4 Subject: [PATCH] libahci: Allow drivers to override start_engine
6 Allwinner A10 and A20 ARM SoCs have an AHCI sata controller which needs a
7 special register to be poked before starting the DMA engine.
9 This register gets reset on an ahci_stop_engine call, so there is no other
10 place then ahci_start_engine where this poking can be done.
12 This commit allows drivers to override ahci_start_engine behavior for use by
13 the Allwinner AHCI driver (and potentially other drivers in the future).
15 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
17 drivers/ata/ahci.c | 6 ++++--
18 drivers/ata/ahci.h | 6 ++++++
19 drivers/ata/libahci.c | 26 +++++++++++++++++++-------
20 drivers/ata/sata_highbank.c | 3 ++-
21 4 files changed, 31 insertions(+), 10 deletions(-)
23 --- a/drivers/ata/ahci.c
24 +++ b/drivers/ata/ahci.c
25 @@ -583,6 +583,7 @@ static int ahci_vt8251_hardreset(struct
26 unsigned long deadline)
28 struct ata_port *ap = link->ap;
29 + struct ahci_host_priv *hpriv = ap->host->private_data;
33 @@ -593,7 +594,7 @@ static int ahci_vt8251_hardreset(struct
34 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
35 deadline, &online, NULL);
37 - ahci_start_engine(ap);
38 + hpriv->start_engine(ap);
40 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
42 @@ -608,6 +609,7 @@ static int ahci_p5wdh_hardreset(struct a
44 struct ata_port *ap = link->ap;
45 struct ahci_port_priv *pp = ap->private_data;
46 + struct ahci_host_priv *hpriv = ap->host->private_data;
47 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
48 struct ata_taskfile tf;
50 @@ -623,7 +625,7 @@ static int ahci_p5wdh_hardreset(struct a
51 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
52 deadline, &online, NULL);
54 - ahci_start_engine(ap);
55 + hpriv->start_engine(ap);
57 /* The pseudo configuration device on SIMG4726 attached to
58 * ASUS P5W-DH Deluxe doesn't send signature FIS after
59 --- a/drivers/ata/ahci.h
60 +++ b/drivers/ata/ahci.h
63 #include <linux/clk.h>
64 #include <linux/libata.h>
65 +#include <linux/regulator/consumer.h>
67 /* Enclosure Management Control */
68 #define EM_CTRL_MSG_TYPE 0x000f0000
74 AHCI_MAX_SG = 168, /* hardware max is 64K */
75 AHCI_DMA_BOUNDARY = 0xffffffff,
77 @@ -322,8 +324,15 @@ struct ahci_host_priv {
78 u32 em_loc; /* enclosure management location */
79 u32 em_buf_sz; /* EM buffer size in byte */
80 u32 em_msg_type; /* EM message type */
81 - struct clk *clk; /* Only for platforms supporting clk */
82 + struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
83 + struct regulator *target_pwr; /* Optional */
84 void *plat_data; /* Other platform data */
86 + * Optional ahci_start_engine override, if not set this gets set to the
87 + * default ahci_start_engine during ahci_save_initial_config, this can
88 + * be overridden anytime before the host is activated.
90 + void (*start_engine)(struct ata_port *ap);
93 extern int ahci_ignore_sss;
94 --- a/drivers/ata/libahci.c
95 +++ b/drivers/ata/libahci.c
96 @@ -394,6 +394,9 @@ static ssize_t ahci_show_em_supported(st
98 * If inconsistent, config values are fixed up by this function.
100 + * If it is not set already this function sets hpriv->start_engine to
101 + * ahci_start_engine.
106 @@ -500,6 +503,9 @@ void ahci_save_initial_config(struct dev
109 hpriv->port_map = port_map;
111 + if (!hpriv->start_engine)
112 + hpriv->start_engine = ahci_start_engine;
114 EXPORT_SYMBOL_GPL(ahci_save_initial_config);
116 @@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_p
119 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
120 - ahci_start_engine(ap);
121 + hpriv->start_engine(ap);
124 if (ap->flags & ATA_FLAG_EM) {
125 @@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap
129 - ahci_start_engine(ap);
130 + hpriv->start_engine(ap);
133 EXPORT_SYMBOL_GPL(ahci_kick_engine);
134 @@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_lin
135 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
136 struct ata_port *ap = link->ap;
137 struct ahci_port_priv *pp = ap->private_data;
138 + struct ahci_host_priv *hpriv = ap->host->private_data;
139 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
140 struct ata_taskfile tf;
142 @@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_lin
143 rc = sata_link_hardreset(link, timing, deadline, &online,
146 - ahci_start_engine(ap);
147 + hpriv->start_engine(ap);
150 *class = ahci_dev_classify(ap);
151 @@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *a
153 void ahci_error_handler(struct ata_port *ap)
155 + struct ahci_host_priv *hpriv = ap->host->private_data;
157 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
159 ahci_stop_engine(ap);
160 - ahci_start_engine(ap);
161 + hpriv->start_engine(ap);
164 sata_pmp_error_handler(ap);
165 @@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struc
167 static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
169 + struct ahci_host_priv *hpriv = ap->host->private_data;
170 void __iomem *port_mmio = ahci_port_base(ap);
171 struct ata_device *dev = ap->link.device;
172 u32 devslp, dm, dito, mdat, deto;
173 @@ -2094,7 +2104,7 @@ static void ahci_set_aggressive_devslp(s
175 writel(devslp, port_mmio + PORT_DEVSLP);
177 - ahci_start_engine(ap);
178 + hpriv->start_engine(ap);
180 /* enable device sleep feature for the drive */
181 err_mask = ata_dev_set_feature(dev,
182 @@ -2106,6 +2116,7 @@ static void ahci_set_aggressive_devslp(s
184 static void ahci_enable_fbs(struct ata_port *ap)
186 + struct ahci_host_priv *hpriv = ap->host->private_data;
187 struct ahci_port_priv *pp = ap->private_data;
188 void __iomem *port_mmio = ahci_port_base(ap);
190 @@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_p
192 dev_err(ap->host->dev, "Failed to enable FBS\n");
194 - ahci_start_engine(ap);
195 + hpriv->start_engine(ap);
198 static void ahci_disable_fbs(struct ata_port *ap)
200 + struct ahci_host_priv *hpriv = ap->host->private_data;
201 struct ahci_port_priv *pp = ap->private_data;
202 void __iomem *port_mmio = ahci_port_base(ap);
204 @@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_
205 pp->fbs_enabled = false;
208 - ahci_start_engine(ap);
209 + hpriv->start_engine(ap);
212 static void ahci_pmp_attach(struct ata_port *ap)
213 --- a/drivers/ata/sata_highbank.c
214 +++ b/drivers/ata/sata_highbank.c
215 @@ -403,6 +403,7 @@ static int ahci_highbank_hardreset(struc
216 static const unsigned long timing[] = { 5, 100, 500};
217 struct ata_port *ap = link->ap;
218 struct ahci_port_priv *pp = ap->private_data;
219 + struct ahci_host_priv *hpriv = ap->host->private_data;
220 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
221 struct ata_taskfile tf;
223 @@ -431,7 +432,7 @@ static int ahci_highbank_hardreset(struc
225 } while (!online && retry--);
227 - ahci_start_engine(ap);
228 + hpriv->start_engine(ap);
231 *class = ahci_dev_classify(ap);
232 --- a/Documentation/devicetree/bindings/ata/ahci-platform.txt
233 +++ b/Documentation/devicetree/bindings/ata/ahci-platform.txt
234 @@ -10,6 +10,8 @@ Required properties:
237 - dma-coherent : Present if dma operations are coherent
238 +- clocks : a list of phandle + clock specifier pairs
239 +- target-supply : regulator for SATA target power
243 --- a/drivers/ata/ahci_platform.c
244 +++ b/drivers/ata/ahci_platform.c
245 @@ -87,78 +87,252 @@ static struct scsi_host_template ahci_pl
246 AHCI_SHT("ahci_platform"),
249 -static int ahci_probe(struct platform_device *pdev)
251 + * ahci_platform_enable_clks - Enable platform clocks
252 + * @hpriv: host private area to store config values
254 + * This function enables all the clks found in hpriv->clks, starting
255 + * at index 0. If any clk fails to enable it disables all the clks
256 + * already enabled in reverse order, and then returns an error.
262 + * 0 on success otherwise a negative error code
264 +int ahci_platform_enable_clks(struct ahci_host_priv *hpriv)
266 - struct device *dev = &pdev->dev;
267 - struct ahci_platform_data *pdata = dev_get_platdata(dev);
268 - const struct platform_device_id *id = platform_get_device_id(pdev);
269 - struct ata_port_info pi = ahci_port_info[id ? id->driver_data : 0];
270 - const struct ata_port_info *ppi[] = { &pi, NULL };
271 - struct ahci_host_priv *hpriv;
272 - struct ata_host *host;
273 - struct resource *mem;
280 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
282 - dev_err(dev, "no mmio space\n");
284 + for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) {
285 + rc = clk_prepare_enable(hpriv->clks[c]);
287 + goto disable_unprepare_clk;
291 - irq = platform_get_irq(pdev, 0);
293 - dev_err(dev, "no irq\n");
296 +disable_unprepare_clk:
298 + clk_disable_unprepare(hpriv->clks[c]);
301 +EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);
303 - if (pdata && pdata->ata_port_info)
304 - pi = *pdata->ata_port_info;
306 + * ahci_platform_disable_clks - Disable platform clocks
307 + * @hpriv: host private area to store config values
309 + * This function disables all the clks found in hpriv->clks, in reverse
310 + * order of ahci_platform_enable_clks (starting at the end of the array).
315 +void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
319 - hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
321 - dev_err(dev, "can't alloc ahci_host_priv\n");
323 + for (c = AHCI_MAX_CLKS - 1; c >= 0; c--)
324 + if (hpriv->clks[c])
325 + clk_disable_unprepare(hpriv->clks[c]);
327 +EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
330 + * ahci_platform_enable_resources - Enable platform resources
331 + * @hpriv: host private area to store config values
333 + * This function enables all ahci_platform managed resources in
334 + * the following order:
336 + * 2) Clocks (through ahci_platform_enable_clks)
338 + * If resource enabling fails at any point the previous enabled
339 + * resources are disabled in reverse order.
345 + * 0 on success otherwise a negative error code
347 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
351 + if (hpriv->target_pwr) {
352 + rc = regulator_enable(hpriv->target_pwr);
357 - hpriv->flags |= (unsigned long)pi.private_data;
358 + rc = ahci_platform_enable_clks(hpriv);
360 + goto disable_regulator;
365 + if (hpriv->target_pwr)
366 + regulator_disable(hpriv->target_pwr);
369 +EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
372 + * ahci_platform_disable_resources - Disable platform resources
373 + * @hpriv: host private area to store config values
375 + * This function disables all ahci_platform managed resources in
376 + * the following order:
377 + * 1) Clocks (through ahci_platform_disable_clks)
383 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
385 + ahci_platform_disable_clks(hpriv);
387 - hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
388 + if (hpriv->target_pwr)
389 + regulator_disable(hpriv->target_pwr);
391 +EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
393 +static void ahci_platform_put_resources(struct device *dev, void *res)
395 + struct ahci_host_priv *hpriv = res;
398 + for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
399 + clk_put(hpriv->clks[c]);
403 + * ahci_platform_get_resources - Get platform resources
404 + * @pdev: platform device to get resources for
406 + * This function allocates an ahci_host_priv struct, and gets the
407 + * following resources, storing a reference to them inside the returned
410 + * 1) mmio registers (IORESOURCE_MEM 0, mandatory)
411 + * 2) regulator for controlling the targets power (optional)
412 + * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
413 + * or for non devicetree enabled platforms a single clock
419 + * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
421 +struct ahci_host_priv *ahci_platform_get_resources(
422 + struct platform_device *pdev)
424 + struct device *dev = &pdev->dev;
425 + struct ahci_host_priv *hpriv;
427 + int i, rc = -ENOMEM;
429 + if (!devres_open_group(dev, NULL, GFP_KERNEL))
430 + return ERR_PTR(-ENOMEM);
432 + hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv),
437 + devres_add(dev, hpriv);
439 + hpriv->mmio = devm_ioremap_resource(dev,
440 + platform_get_resource(pdev, IORESOURCE_MEM, 0));
442 - dev_err(dev, "can't map %pR\n", mem);
444 + dev_err(dev, "no mmio space\n");
448 - hpriv->clk = clk_get(dev, NULL);
449 - if (IS_ERR(hpriv->clk)) {
450 - dev_err(dev, "can't get clock\n");
452 - rc = clk_prepare_enable(hpriv->clk);
454 - dev_err(dev, "clock prepare enable failed");
456 + hpriv->target_pwr = devm_regulator_get_optional(dev, "target");
457 + if (IS_ERR(hpriv->target_pwr)) {
458 + rc = PTR_ERR(hpriv->target_pwr);
459 + if (rc == -EPROBE_DEFER)
461 + hpriv->target_pwr = NULL;
464 + for (i = 0; i < AHCI_MAX_CLKS; i++) {
466 + * For now we must use clk_get(dev, NULL) for the first clock,
467 + * because some platforms (da850, spear13xx) are not yet
468 + * converted to use devicetree for clocks. For new platforms
469 + * this is equivalent to of_clk_get(dev->of_node, 0).
472 + clk = clk_get(dev, NULL);
474 + clk = of_clk_get(dev->of_node, i);
478 + if (rc == -EPROBE_DEFER)
482 + hpriv->clks[i] = clk;
486 - * Some platforms might need to prepare for mmio region access,
487 - * which could be done in the following init call. So, the mmio
488 - * region shouldn't be accessed before init (if provided) has
489 - * returned successfully.
491 - if (pdata && pdata->init) {
492 - rc = pdata->init(dev, hpriv->mmio);
494 - goto disable_unprepare_clk;
496 + devres_remove_group(dev, NULL);
500 + devres_release_group(dev, NULL);
501 + return ERR_PTR(rc);
503 +EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
506 + * ahci_platform_init_host - Bring up an ahci-platform host
507 + * @pdev: platform device pointer for the host
508 + * @hpriv: ahci-host private data for the host
509 + * @pi_template: template for the ata_port_info to use
510 + * @force_port_map: param passed to ahci_save_initial_config
511 + * @mask_port_map: param passed to ahci_save_initial_config
513 + * This function does all the usual steps needed to bring up an
514 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
515 + * must be initialized / enabled before calling this.
521 + * 0 on success otherwise a negative error code
523 +int ahci_platform_init_host(struct platform_device *pdev,
524 + struct ahci_host_priv *hpriv,
525 + const struct ata_port_info *pi_template,
526 + unsigned int force_port_map,
527 + unsigned int mask_port_map)
529 + struct device *dev = &pdev->dev;
530 + struct ata_port_info pi = *pi_template;
531 + const struct ata_port_info *ppi[] = { &pi, NULL };
532 + struct ata_host *host;
533 + int i, irq, n_ports, rc;
535 - ahci_save_initial_config(dev, hpriv,
536 - pdata ? pdata->force_port_map : 0,
537 - pdata ? pdata->mask_port_map : 0);
538 + irq = platform_get_irq(pdev, 0);
540 + dev_err(dev, "no irq\n");
545 + hpriv->flags |= (unsigned long)pi.private_data;
547 + ahci_save_initial_config(dev, hpriv, force_port_map, mask_port_map);
549 if (hpriv->cap & HOST_CAP_NCQ)
550 pi.flags |= ATA_FLAG_NCQ;
552 @@ -175,10 +349,8 @@ static int ahci_probe(struct platform_de
553 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
555 host = ata_host_alloc_pinfo(dev, ppi, n_ports);
563 host->private_data = hpriv;
565 @@ -193,7 +365,8 @@ static int ahci_probe(struct platform_de
566 for (i = 0; i < host->n_ports; i++) {
567 struct ata_port *ap = host->ports[i];
569 - ata_port_desc(ap, "mmio %pR", mem);
570 + ata_port_desc(ap, "mmio %pR",
571 + platform_get_resource(pdev, IORESOURCE_MEM, 0));
572 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
574 /* set enclosure management message type */
575 @@ -207,13 +380,53 @@ static int ahci_probe(struct platform_de
577 rc = ahci_reset_controller(host);
582 ahci_init_controller(host);
583 ahci_print_info(host, "platform");
585 - rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
586 - &ahci_platform_sht);
587 + return ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
588 + &ahci_platform_sht);
590 +EXPORT_SYMBOL_GPL(ahci_platform_init_host);
592 +static int ahci_probe(struct platform_device *pdev)
594 + struct device *dev = &pdev->dev;
595 + struct ahci_platform_data *pdata = dev_get_platdata(dev);
596 + const struct platform_device_id *id = platform_get_device_id(pdev);
597 + const struct ata_port_info *pi_template;
598 + struct ahci_host_priv *hpriv;
601 + hpriv = ahci_platform_get_resources(pdev);
603 + return PTR_ERR(hpriv);
605 + rc = ahci_platform_enable_resources(hpriv);
610 + * Some platforms might need to prepare for mmio region access,
611 + * which could be done in the following init call. So, the mmio
612 + * region shouldn't be accessed before init (if provided) has
613 + * returned successfully.
615 + if (pdata && pdata->init) {
616 + rc = pdata->init(dev, hpriv->mmio);
618 + goto disable_resources;
621 + if (pdata && pdata->ata_port_info)
622 + pi_template = pdata->ata_port_info;
624 + pi_template = &ahci_port_info[id ? id->driver_data : 0];
626 + rc = ahci_platform_init_host(pdev, hpriv, pi_template,
627 + pdata ? pdata->force_port_map : 0,
628 + pdata ? pdata->mask_port_map : 0);
632 @@ -221,12 +434,8 @@ static int ahci_probe(struct platform_de
634 if (pdata && pdata->exit)
636 -disable_unprepare_clk:
637 - if (!IS_ERR(hpriv->clk))
638 - clk_disable_unprepare(hpriv->clk);
640 - if (!IS_ERR(hpriv->clk))
641 - clk_put(hpriv->clk);
643 + ahci_platform_disable_resources(hpriv);
647 @@ -239,21 +448,30 @@ static void ahci_host_stop(struct ata_ho
648 if (pdata && pdata->exit)
651 - if (!IS_ERR(hpriv->clk)) {
652 - clk_disable_unprepare(hpriv->clk);
653 - clk_put(hpriv->clk);
655 + ahci_platform_disable_resources(hpriv);
658 #ifdef CONFIG_PM_SLEEP
659 -static int ahci_suspend(struct device *dev)
661 + * ahci_platform_suspend_host - Suspend an ahci-platform host
662 + * @dev: device pointer for the host
664 + * This function does all the usual steps needed to suspend an
665 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
666 + * must be disabled after calling this.
672 + * 0 on success otherwise a negative error code
674 +int ahci_platform_suspend_host(struct device *dev)
676 - struct ahci_platform_data *pdata = dev_get_platdata(dev);
677 struct ata_host *host = dev_get_drvdata(dev);
678 struct ahci_host_priv *hpriv = host->private_data;
679 void __iomem *mmio = hpriv->mmio;
683 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
684 dev_err(dev, "firmware update required for suspend/resume\n");
685 @@ -270,61 +488,122 @@ static int ahci_suspend(struct device *d
686 writel(ctl, mmio + HOST_CTL);
687 readl(mmio + HOST_CTL); /* flush */
689 - rc = ata_host_suspend(host, PMSG_SUSPEND);
690 + return ata_host_suspend(host, PMSG_SUSPEND);
692 +EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
695 + * ahci_platform_resume_host - Resume an ahci-platform host
696 + * @dev: device pointer for the host
698 + * This function does all the usual steps needed to resume an
699 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
700 + * must be initialized / enabled before calling this.
706 + * 0 on success otherwise a negative error code
708 +int ahci_platform_resume_host(struct device *dev)
710 + struct ata_host *host = dev_get_drvdata(dev);
713 + if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
714 + rc = ahci_reset_controller(host);
718 + ahci_init_controller(host);
721 + ata_host_resume(host);
725 +EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
728 + * ahci_platform_suspend - Suspend an ahci-platform device
729 + * @dev: the platform device to suspend
731 + * This function suspends the host associated with the device, followed
732 + * by disabling all the resources of the device.
738 + * 0 on success otherwise a negative error code
740 +int ahci_platform_suspend(struct device *dev)
742 + struct ahci_platform_data *pdata = dev_get_platdata(dev);
743 + struct ata_host *host = dev_get_drvdata(dev);
744 + struct ahci_host_priv *hpriv = host->private_data;
747 + rc = ahci_platform_suspend_host(dev);
751 if (pdata && pdata->suspend)
752 return pdata->suspend(dev);
754 - if (!IS_ERR(hpriv->clk))
755 - clk_disable_unprepare(hpriv->clk);
756 + ahci_platform_disable_resources(hpriv);
760 +EXPORT_SYMBOL_GPL(ahci_platform_suspend);
762 -static int ahci_resume(struct device *dev)
764 + * ahci_platform_resume - Resume an ahci-platform device
765 + * @dev: the platform device to resume
767 + * This function enables all the resources of the device followed by
768 + * resuming the host associated with the device.
774 + * 0 on success otherwise a negative error code
776 +int ahci_platform_resume(struct device *dev)
778 struct ahci_platform_data *pdata = dev_get_platdata(dev);
779 struct ata_host *host = dev_get_drvdata(dev);
780 struct ahci_host_priv *hpriv = host->private_data;
783 - if (!IS_ERR(hpriv->clk)) {
784 - rc = clk_prepare_enable(hpriv->clk);
786 - dev_err(dev, "clock prepare enable failed");
790 + rc = ahci_platform_enable_resources(hpriv);
794 if (pdata && pdata->resume) {
795 rc = pdata->resume(dev);
797 - goto disable_unprepare_clk;
800 - if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
801 - rc = ahci_reset_controller(host);
803 - goto disable_unprepare_clk;
805 - ahci_init_controller(host);
806 + goto disable_resources;
809 - ata_host_resume(host);
810 + rc = ahci_platform_resume_host(dev);
812 + goto disable_resources;
816 -disable_unprepare_clk:
817 - if (!IS_ERR(hpriv->clk))
818 - clk_disable_unprepare(hpriv->clk);
820 + ahci_platform_disable_resources(hpriv);
824 +EXPORT_SYMBOL_GPL(ahci_platform_resume);
827 -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
828 +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
829 + ahci_platform_resume);
831 static const struct of_device_id ahci_of_match[] = {
832 { .compatible = "snps,spear-ahci", },
833 --- a/include/linux/ahci_platform.h
834 +++ b/include/linux/ahci_platform.h
838 struct ata_port_info;
839 +struct ahci_host_priv;
840 +struct platform_device;
843 + * Note ahci_platform_data is deprecated, it is only kept around for use
844 + * by the old da850 and spear13xx ahci code.
845 + * New drivers should instead declare their own platform_driver struct, and
846 + * use ahci_platform* functions in their own probe, suspend and resume methods.
848 struct ahci_platform_data {
849 int (*init)(struct device *dev, void __iomem *addr);
850 void (*exit)(struct device *dev);
851 @@ -30,4 +38,21 @@ struct ahci_platform_data {
852 unsigned int mask_port_map;
855 +int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);
856 +void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);
857 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
858 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
859 +struct ahci_host_priv *ahci_platform_get_resources(
860 + struct platform_device *pdev);
861 +int ahci_platform_init_host(struct platform_device *pdev,
862 + struct ahci_host_priv *hpriv,
863 + const struct ata_port_info *pi_template,
864 + unsigned int force_port_map,
865 + unsigned int mask_port_map);
867 +int ahci_platform_suspend_host(struct device *dev);
868 +int ahci_platform_resume_host(struct device *dev);
869 +int ahci_platform_suspend(struct device *dev);
870 +int ahci_platform_resume(struct device *dev);
872 #endif /* _AHCI_PLATFORM_H */