1 From 3b2df84624b38362cb84c2d4c6d1d3540c5069d3 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sat, 22 Feb 2014 16:53:33 +0100
4 Subject: [PATCH 112/182] ahci-platform: Add enable_ / disable_resources
7 tj: Minor comment formatting updates.
9 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 Signed-off-by: Tejun Heo <tj@kernel.org>
12 drivers/ata/ahci_platform.c | 106 +++++++++++++++++++++++++++--------------
13 include/linux/ahci_platform.h | 2 +
14 2 files changed, 71 insertions(+), 37 deletions(-)
16 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
17 index 8f18ebe..656d285 100644
18 --- a/drivers/ata/ahci_platform.c
19 +++ b/drivers/ata/ahci_platform.c
20 @@ -133,6 +133,62 @@ void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
22 EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
25 + * ahci_platform_enable_resources - Enable platform resources
26 + * @hpriv: host private area to store config values
28 + * This function enables all ahci_platform managed resources in the
31 + * 2) Clocks (through ahci_platform_enable_clks)
33 + * If resource enabling fails at any point the previous enabled resources
34 + * are disabled in reverse order.
37 + * 0 on success otherwise a negative error code
39 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
43 + if (hpriv->target_pwr) {
44 + rc = regulator_enable(hpriv->target_pwr);
49 + rc = ahci_platform_enable_clks(hpriv);
51 + goto disable_regulator;
56 + if (hpriv->target_pwr)
57 + regulator_disable(hpriv->target_pwr);
60 +EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
63 + * ahci_platform_disable_resources - Disable platform resources
64 + * @hpriv: host private area to store config values
66 + * This function disables all ahci_platform managed resources in the
68 + * 1) Clocks (through ahci_platform_disable_clks)
71 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
73 + ahci_platform_disable_clks(hpriv);
75 + if (hpriv->target_pwr)
76 + regulator_disable(hpriv->target_pwr);
78 +EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
80 static void ahci_put_clks(struct ahci_host_priv *hpriv)
83 @@ -215,15 +271,9 @@ static int ahci_probe(struct platform_device *pdev)
87 - if (hpriv->target_pwr) {
88 - rc = regulator_enable(hpriv->target_pwr);
93 - rc = ahci_enable_clks(dev, hpriv);
94 + rc = ahci_platform_enable_resources(hpriv);
96 - goto disable_regulator;
100 * Some platforms might need to prepare for mmio region access,
101 @@ -234,7 +284,7 @@ static int ahci_probe(struct platform_device *pdev)
102 if (pdata && pdata->init) {
103 rc = pdata->init(dev, hpriv->mmio);
105 - goto disable_unprepare_clk;
106 + goto disable_resources;
109 ahci_save_initial_config(dev, hpriv,
110 @@ -304,11 +354,8 @@ static int ahci_probe(struct platform_device *pdev)
112 if (pdata && pdata->exit)
114 -disable_unprepare_clk:
115 - ahci_disable_clks(hpriv);
117 - if (hpriv->target_pwr)
118 - regulator_disable(hpriv->target_pwr);
120 + ahci_platform_disable_resources(hpriv);
122 ahci_put_clks(hpriv);
124 @@ -323,11 +370,8 @@ static void ahci_host_stop(struct ata_host *host)
125 if (pdata && pdata->exit)
128 - ahci_disable_clks(hpriv);
129 + ahci_platform_disable_resources(hpriv);
130 ahci_put_clks(hpriv);
132 - if (hpriv->target_pwr)
133 - regulator_disable(hpriv->target_pwr);
136 #ifdef CONFIG_PM_SLEEP
137 @@ -362,10 +406,7 @@ static int ahci_suspend(struct device *dev)
138 if (pdata && pdata->suspend)
139 return pdata->suspend(dev);
141 - ahci_disable_clks(hpriv);
143 - if (hpriv->target_pwr)
144 - regulator_disable(hpriv->target_pwr);
145 + ahci_platform_disable_resources(hpriv);
149 @@ -377,26 +418,20 @@ static int ahci_resume(struct device *dev)
150 struct ahci_host_priv *hpriv = host->private_data;
153 - if (hpriv->target_pwr) {
154 - rc = regulator_enable(hpriv->target_pwr);
159 - rc = ahci_enable_clks(dev, hpriv);
160 + rc = ahci_platform_enable_resources(hpriv);
162 - goto disable_regulator;
165 if (pdata && pdata->resume) {
166 rc = pdata->resume(dev);
168 - goto disable_unprepare_clk;
169 + goto disable_resources;
172 if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
173 rc = ahci_reset_controller(host);
175 - goto disable_unprepare_clk;
176 + goto disable_resources;
178 ahci_init_controller(host);
180 @@ -405,11 +440,8 @@ static int ahci_resume(struct device *dev)
184 -disable_unprepare_clk:
185 - ahci_disable_clks(hpriv);
187 - if (hpriv->target_pwr)
188 - regulator_disable(hpriv->target_pwr);
190 + ahci_platform_disable_resources(hpriv);
194 diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h
195 index 769d065..b674b01 100644
196 --- a/include/linux/ahci_platform.h
197 +++ b/include/linux/ahci_platform.h
198 @@ -33,5 +33,7 @@ struct ahci_platform_data {
200 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);
201 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);
202 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
203 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
205 #endif /* _AHCI_PLATFORM_H */