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 --- a/drivers/ata/ahci_platform.c
17 +++ b/drivers/ata/ahci_platform.c
18 @@ -133,6 +133,62 @@ void ahci_platform_disable_clks(struct a
20 EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
23 + * ahci_platform_enable_resources - Enable platform resources
24 + * @hpriv: host private area to store config values
26 + * This function enables all ahci_platform managed resources in the
29 + * 2) Clocks (through ahci_platform_enable_clks)
31 + * If resource enabling fails at any point the previous enabled resources
32 + * are disabled in reverse order.
35 + * 0 on success otherwise a negative error code
37 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
41 + if (hpriv->target_pwr) {
42 + rc = regulator_enable(hpriv->target_pwr);
47 + rc = ahci_platform_enable_clks(hpriv);
49 + goto disable_regulator;
54 + if (hpriv->target_pwr)
55 + regulator_disable(hpriv->target_pwr);
58 +EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
61 + * ahci_platform_disable_resources - Disable platform resources
62 + * @hpriv: host private area to store config values
64 + * This function disables all ahci_platform managed resources in the
66 + * 1) Clocks (through ahci_platform_disable_clks)
69 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
71 + ahci_platform_disable_clks(hpriv);
73 + if (hpriv->target_pwr)
74 + regulator_disable(hpriv->target_pwr);
76 +EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
78 static void ahci_put_clks(struct ahci_host_priv *hpriv)
81 @@ -215,15 +271,9 @@ static int ahci_probe(struct platform_de
85 - if (hpriv->target_pwr) {
86 - rc = regulator_enable(hpriv->target_pwr);
91 - rc = ahci_enable_clks(dev, hpriv);
92 + rc = ahci_platform_enable_resources(hpriv);
94 - goto disable_regulator;
98 * Some platforms might need to prepare for mmio region access,
99 @@ -234,7 +284,7 @@ static int ahci_probe(struct platform_de
100 if (pdata && pdata->init) {
101 rc = pdata->init(dev, hpriv->mmio);
103 - goto disable_unprepare_clk;
104 + goto disable_resources;
107 ahci_save_initial_config(dev, hpriv,
108 @@ -304,11 +354,8 @@ static int ahci_probe(struct platform_de
110 if (pdata && pdata->exit)
112 -disable_unprepare_clk:
113 - ahci_disable_clks(hpriv);
115 - if (hpriv->target_pwr)
116 - regulator_disable(hpriv->target_pwr);
118 + ahci_platform_disable_resources(hpriv);
120 ahci_put_clks(hpriv);
122 @@ -323,11 +370,8 @@ static void ahci_host_stop(struct ata_ho
123 if (pdata && pdata->exit)
126 - ahci_disable_clks(hpriv);
127 + ahci_platform_disable_resources(hpriv);
128 ahci_put_clks(hpriv);
130 - if (hpriv->target_pwr)
131 - regulator_disable(hpriv->target_pwr);
134 #ifdef CONFIG_PM_SLEEP
135 @@ -362,10 +406,7 @@ static int ahci_suspend(struct device *d
136 if (pdata && pdata->suspend)
137 return pdata->suspend(dev);
139 - ahci_disable_clks(hpriv);
141 - if (hpriv->target_pwr)
142 - regulator_disable(hpriv->target_pwr);
143 + ahci_platform_disable_resources(hpriv);
147 @@ -377,26 +418,20 @@ static int ahci_resume(struct device *de
148 struct ahci_host_priv *hpriv = host->private_data;
151 - if (hpriv->target_pwr) {
152 - rc = regulator_enable(hpriv->target_pwr);
157 - rc = ahci_enable_clks(dev, hpriv);
158 + rc = ahci_platform_enable_resources(hpriv);
160 - goto disable_regulator;
163 if (pdata && pdata->resume) {
164 rc = pdata->resume(dev);
166 - goto disable_unprepare_clk;
167 + goto disable_resources;
170 if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
171 rc = ahci_reset_controller(host);
173 - goto disable_unprepare_clk;
174 + goto disable_resources;
176 ahci_init_controller(host);
178 @@ -405,11 +440,8 @@ static int ahci_resume(struct device *de
182 -disable_unprepare_clk:
183 - ahci_disable_clks(hpriv);
185 - if (hpriv->target_pwr)
186 - regulator_disable(hpriv->target_pwr);
188 + ahci_platform_disable_resources(hpriv);
192 --- a/include/linux/ahci_platform.h
193 +++ b/include/linux/ahci_platform.h
194 @@ -33,5 +33,7 @@ struct ahci_platform_data {
196 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);
197 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);
198 +int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
199 +void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
201 #endif /* _AHCI_PLATFORM_H */