1 From 8121ed9c7ea2d56f5e0a98c2db396214f85d7485 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sat, 22 Feb 2014 16:53:35 +0100
4 Subject: [PATCH 115/182] ahci-platform: "Library-ise" suspend / resume
7 Split suspend / resume code into host suspend / resume functionality and
8 resource enable / disabling phases, and export the new suspend_ / resume_host
11 tj: Minor comment formatting updates.
13 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
14 Signed-off-by: Tejun Heo <tj@kernel.org>
16 drivers/ata/ahci_platform.c | 97 ++++++++++++++++++++++++++++++++++-------
17 include/linux/ahci_platform.h | 5 +++
18 2 files changed, 87 insertions(+), 15 deletions(-)
20 --- a/drivers/ata/ahci_platform.c
21 +++ b/drivers/ata/ahci_platform.c
22 @@ -432,14 +432,23 @@ static void ahci_host_stop(struct ata_ho
25 #ifdef CONFIG_PM_SLEEP
26 -static int ahci_suspend(struct device *dev)
28 + * ahci_platform_suspend_host - Suspend an ahci-platform host
29 + * @dev: device pointer for the host
31 + * This function does all the usual steps needed to suspend an
32 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
33 + * must be disabled after calling this.
36 + * 0 on success otherwise a negative error code
38 +int ahci_platform_suspend_host(struct device *dev)
40 - struct ahci_platform_data *pdata = dev_get_platdata(dev);
41 struct ata_host *host = dev_get_drvdata(dev);
42 struct ahci_host_priv *hpriv = host->private_data;
43 void __iomem *mmio = hpriv->mmio;
47 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
48 dev_err(dev, "firmware update required for suspend/resume\n");
49 @@ -456,7 +465,58 @@ static int ahci_suspend(struct device *d
50 writel(ctl, mmio + HOST_CTL);
51 readl(mmio + HOST_CTL); /* flush */
53 - rc = ata_host_suspend(host, PMSG_SUSPEND);
54 + return ata_host_suspend(host, PMSG_SUSPEND);
56 +EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
59 + * ahci_platform_resume_host - Resume an ahci-platform host
60 + * @dev: device pointer for the host
62 + * This function does all the usual steps needed to resume an ahci-platform
63 + * host, note any necessary resources (ie clks, phy, etc.) must be
64 + * initialized / enabled before calling this.
67 + * 0 on success otherwise a negative error code
69 +int ahci_platform_resume_host(struct device *dev)
71 + struct ata_host *host = dev_get_drvdata(dev);
74 + if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
75 + rc = ahci_reset_controller(host);
79 + ahci_init_controller(host);
82 + ata_host_resume(host);
86 +EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
89 + * ahci_platform_suspend - Suspend an ahci-platform device
90 + * @dev: the platform device to suspend
92 + * This function suspends the host associated with the device, followed by
93 + * disabling all the resources of the device.
96 + * 0 on success otherwise a negative error code
98 +int ahci_platform_suspend(struct device *dev)
100 + struct ahci_platform_data *pdata = dev_get_platdata(dev);
101 + struct ata_host *host = dev_get_drvdata(dev);
102 + struct ahci_host_priv *hpriv = host->private_data;
105 + rc = ahci_platform_suspend_host(dev);
109 @@ -467,8 +527,19 @@ static int ahci_suspend(struct device *d
113 +EXPORT_SYMBOL_GPL(ahci_platform_suspend);
115 -static int ahci_resume(struct device *dev)
117 + * ahci_platform_resume - Resume an ahci-platform device
118 + * @dev: the platform device to resume
120 + * This function enables all the resources of the device followed by
121 + * resuming the host associated with the device.
124 + * 0 on success otherwise a negative error code
126 +int ahci_platform_resume(struct device *dev)
128 struct ahci_platform_data *pdata = dev_get_platdata(dev);
129 struct ata_host *host = dev_get_drvdata(dev);
130 @@ -485,15 +556,9 @@ static int ahci_resume(struct device *de
131 goto disable_resources;
134 - if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
135 - rc = ahci_reset_controller(host);
137 - goto disable_resources;
139 - ahci_init_controller(host);
142 - ata_host_resume(host);
143 + rc = ahci_platform_resume_host(dev);
145 + goto disable_resources;
149 @@ -502,9 +567,11 @@ disable_resources:
153 +EXPORT_SYMBOL_GPL(ahci_platform_resume);
156 -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
157 +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
158 + ahci_platform_resume);
160 static const struct of_device_id ahci_of_match[] = {
161 { .compatible = "snps,spear-ahci", },
162 --- a/include/linux/ahci_platform.h
163 +++ b/include/linux/ahci_platform.h
164 @@ -50,4 +50,9 @@ int ahci_platform_init_host(struct platf
165 unsigned int force_port_map,
166 unsigned int mask_port_map);
168 +int ahci_platform_suspend_host(struct device *dev);
169 +int ahci_platform_resume_host(struct device *dev);
170 +int ahci_platform_suspend(struct device *dev);
171 +int ahci_platform_resume(struct device *dev);
173 #endif /* _AHCI_PLATFORM_H */