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 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
21 index 19e9eaa..01f7bbe 100644
22 --- a/drivers/ata/ahci_platform.c
23 +++ b/drivers/ata/ahci_platform.c
24 @@ -432,14 +432,23 @@ static void ahci_host_stop(struct ata_host *host)
27 #ifdef CONFIG_PM_SLEEP
28 -static int ahci_suspend(struct device *dev)
30 + * ahci_platform_suspend_host - Suspend an ahci-platform host
31 + * @dev: device pointer for the host
33 + * This function does all the usual steps needed to suspend an
34 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
35 + * must be disabled after calling this.
38 + * 0 on success otherwise a negative error code
40 +int ahci_platform_suspend_host(struct device *dev)
42 - struct ahci_platform_data *pdata = dev_get_platdata(dev);
43 struct ata_host *host = dev_get_drvdata(dev);
44 struct ahci_host_priv *hpriv = host->private_data;
45 void __iomem *mmio = hpriv->mmio;
49 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
50 dev_err(dev, "firmware update required for suspend/resume\n");
51 @@ -456,7 +465,58 @@ static int ahci_suspend(struct device *dev)
52 writel(ctl, mmio + HOST_CTL);
53 readl(mmio + HOST_CTL); /* flush */
55 - rc = ata_host_suspend(host, PMSG_SUSPEND);
56 + return ata_host_suspend(host, PMSG_SUSPEND);
58 +EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
61 + * ahci_platform_resume_host - Resume an ahci-platform host
62 + * @dev: device pointer for the host
64 + * This function does all the usual steps needed to resume an ahci-platform
65 + * host, note any necessary resources (ie clks, phy, etc.) must be
66 + * initialized / enabled before calling this.
69 + * 0 on success otherwise a negative error code
71 +int ahci_platform_resume_host(struct device *dev)
73 + struct ata_host *host = dev_get_drvdata(dev);
76 + if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
77 + rc = ahci_reset_controller(host);
81 + ahci_init_controller(host);
84 + ata_host_resume(host);
88 +EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
91 + * ahci_platform_suspend - Suspend an ahci-platform device
92 + * @dev: the platform device to suspend
94 + * This function suspends the host associated with the device, followed by
95 + * disabling all the resources of the device.
98 + * 0 on success otherwise a negative error code
100 +int ahci_platform_suspend(struct device *dev)
102 + struct ahci_platform_data *pdata = dev_get_platdata(dev);
103 + struct ata_host *host = dev_get_drvdata(dev);
104 + struct ahci_host_priv *hpriv = host->private_data;
107 + rc = ahci_platform_suspend_host(dev);
111 @@ -467,8 +527,19 @@ static int ahci_suspend(struct device *dev)
115 +EXPORT_SYMBOL_GPL(ahci_platform_suspend);
117 -static int ahci_resume(struct device *dev)
119 + * ahci_platform_resume - Resume an ahci-platform device
120 + * @dev: the platform device to resume
122 + * This function enables all the resources of the device followed by
123 + * resuming the host associated with the device.
126 + * 0 on success otherwise a negative error code
128 +int ahci_platform_resume(struct device *dev)
130 struct ahci_platform_data *pdata = dev_get_platdata(dev);
131 struct ata_host *host = dev_get_drvdata(dev);
132 @@ -485,15 +556,9 @@ static int ahci_resume(struct device *dev)
133 goto disable_resources;
136 - if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
137 - rc = ahci_reset_controller(host);
139 - goto disable_resources;
141 - ahci_init_controller(host);
144 - ata_host_resume(host);
145 + rc = ahci_platform_resume_host(dev);
147 + goto disable_resources;
151 @@ -502,9 +567,11 @@ disable_resources:
155 +EXPORT_SYMBOL_GPL(ahci_platform_resume);
158 -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
159 +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
160 + ahci_platform_resume);
162 static const struct of_device_id ahci_of_match[] = {
163 { .compatible = "snps,spear-ahci", },
164 diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h
165 index b80c51c..542f268 100644
166 --- a/include/linux/ahci_platform.h
167 +++ b/include/linux/ahci_platform.h
168 @@ -50,4 +50,9 @@ int ahci_platform_init_host(struct platform_device *pdev,
169 unsigned int force_port_map,
170 unsigned int mask_port_map);
172 +int ahci_platform_suspend_host(struct device *dev);
173 +int ahci_platform_resume_host(struct device *dev);
174 +int ahci_platform_suspend(struct device *dev);
175 +int ahci_platform_resume(struct device *dev);
177 #endif /* _AHCI_PLATFORM_H */