aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@st.com>2012-03-26 23:10:35 -0400
committerChris Ball <cjb@laptop.org>2012-05-01 10:30:44 -0400
commit6ebaf8f2b0f9e67ac2e00ba7af04a58b39312b3c (patch)
treedb399b2036495852b498ff6e4151b945d1d7e34f /drivers/mmc
parent3524b5d1edbcaf0aae9196ac942d8307624ff3f0 (diff)
mmc: sdhci-spear: Use devm_* derivatives
This patch replaces normal calls to resource allocation routines with devm_*() derivative of those routines. This removes the need to free those resources inside the driver. Signed-off-by: Viresh Kumar <viresh.kumar@st.com> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/sdhci-spear.c80
1 files changed, 27 insertions, 53 deletions
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 15191c1d999a..1fe32dfa7cd4 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -82,18 +82,18 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
82 goto err; 82 goto err;
83 } 83 }
84 84
85 if (!request_mem_region(iomem->start, resource_size(iomem), 85 if (!devm_request_mem_region(&pdev->dev, iomem->start,
86 "spear-sdhci")) { 86 resource_size(iomem), "spear-sdhci")) {
87 ret = -EBUSY; 87 ret = -EBUSY;
88 dev_dbg(&pdev->dev, "cannot request region\n"); 88 dev_dbg(&pdev->dev, "cannot request region\n");
89 goto err; 89 goto err;
90 } 90 }
91 91
92 sdhci = kzalloc(sizeof(*sdhci), GFP_KERNEL); 92 sdhci = devm_kzalloc(&pdev->dev, sizeof(*sdhci), GFP_KERNEL);
93 if (!sdhci) { 93 if (!sdhci) {
94 ret = -ENOMEM; 94 ret = -ENOMEM;
95 dev_dbg(&pdev->dev, "cannot allocate memory for sdhci\n"); 95 dev_dbg(&pdev->dev, "cannot allocate memory for sdhci\n");
96 goto err_kzalloc; 96 goto err;
97 } 97 }
98 98
99 /* clk enable */ 99 /* clk enable */
@@ -101,13 +101,13 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
101 if (IS_ERR(sdhci->clk)) { 101 if (IS_ERR(sdhci->clk)) {
102 ret = PTR_ERR(sdhci->clk); 102 ret = PTR_ERR(sdhci->clk);
103 dev_dbg(&pdev->dev, "Error getting clock\n"); 103 dev_dbg(&pdev->dev, "Error getting clock\n");
104 goto err_clk_get; 104 goto err;
105 } 105 }
106 106
107 ret = clk_enable(sdhci->clk); 107 ret = clk_enable(sdhci->clk);
108 if (ret) { 108 if (ret) {
109 dev_dbg(&pdev->dev, "Error enabling clock\n"); 109 dev_dbg(&pdev->dev, "Error enabling clock\n");
110 goto err_clk_enb; 110 goto put_clk;
111 } 111 }
112 112
113 /* overwrite platform_data */ 113 /* overwrite platform_data */
@@ -122,7 +122,7 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
122 if (IS_ERR(host)) { 122 if (IS_ERR(host)) {
123 ret = PTR_ERR(host); 123 ret = PTR_ERR(host);
124 dev_dbg(&pdev->dev, "error allocating host\n"); 124 dev_dbg(&pdev->dev, "error allocating host\n");
125 goto err_alloc_host; 125 goto disable_clk;
126 } 126 }
127 127
128 host->hw_name = "sdhci"; 128 host->hw_name = "sdhci";
@@ -130,17 +130,18 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
130 host->irq = platform_get_irq(pdev, 0); 130 host->irq = platform_get_irq(pdev, 0);
131 host->quirks = SDHCI_QUIRK_BROKEN_ADMA; 131 host->quirks = SDHCI_QUIRK_BROKEN_ADMA;
132 132
133 host->ioaddr = ioremap(iomem->start, resource_size(iomem)); 133 host->ioaddr = devm_ioremap(&pdev->dev, iomem->start,
134 resource_size(iomem));
134 if (!host->ioaddr) { 135 if (!host->ioaddr) {
135 ret = -ENOMEM; 136 ret = -ENOMEM;
136 dev_dbg(&pdev->dev, "failed to remap registers\n"); 137 dev_dbg(&pdev->dev, "failed to remap registers\n");
137 goto err_ioremap; 138 goto free_host;
138 } 139 }
139 140
140 ret = sdhci_add_host(host); 141 ret = sdhci_add_host(host);
141 if (ret) { 142 if (ret) {
142 dev_dbg(&pdev->dev, "error adding host\n"); 143 dev_dbg(&pdev->dev, "error adding host\n");
143 goto err_add_host; 144 goto free_host;
144 } 145 }
145 146
146 platform_set_drvdata(pdev, host); 147 platform_set_drvdata(pdev, host);
@@ -159,11 +160,12 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
159 if (sdhci->data->card_power_gpio >= 0) { 160 if (sdhci->data->card_power_gpio >= 0) {
160 int val = 0; 161 int val = 0;
161 162
162 ret = gpio_request(sdhci->data->card_power_gpio, "sdhci"); 163 ret = devm_gpio_request(&pdev->dev,
164 sdhci->data->card_power_gpio, "sdhci");
163 if (ret < 0) { 165 if (ret < 0) {
164 dev_dbg(&pdev->dev, "gpio request fail: %d\n", 166 dev_dbg(&pdev->dev, "gpio request fail: %d\n",
165 sdhci->data->card_power_gpio); 167 sdhci->data->card_power_gpio);
166 goto err_pgpio_request; 168 goto set_drvdata;
167 } 169 }
168 170
169 if (sdhci->data->power_always_enb) 171 if (sdhci->data->power_always_enb)
@@ -175,60 +177,48 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
175 if (ret) { 177 if (ret) {
176 dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", 178 dev_dbg(&pdev->dev, "gpio set direction fail: %d\n",
177 sdhci->data->card_power_gpio); 179 sdhci->data->card_power_gpio);
178 goto err_pgpio_direction; 180 goto set_drvdata;
179 } 181 }
180 } 182 }
181 183
182 if (sdhci->data->card_int_gpio >= 0) { 184 if (sdhci->data->card_int_gpio >= 0) {
183 ret = gpio_request(sdhci->data->card_int_gpio, "sdhci"); 185 ret = devm_gpio_request(&pdev->dev, sdhci->data->card_int_gpio,
186 "sdhci");
184 if (ret < 0) { 187 if (ret < 0) {
185 dev_dbg(&pdev->dev, "gpio request fail: %d\n", 188 dev_dbg(&pdev->dev, "gpio request fail: %d\n",
186 sdhci->data->card_int_gpio); 189 sdhci->data->card_int_gpio);
187 goto err_igpio_request; 190 goto set_drvdata;
188 } 191 }
189 192
190 ret = gpio_direction_input(sdhci->data->card_int_gpio); 193 ret = gpio_direction_input(sdhci->data->card_int_gpio);
191 if (ret) { 194 if (ret) {
192 dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", 195 dev_dbg(&pdev->dev, "gpio set direction fail: %d\n",
193 sdhci->data->card_int_gpio); 196 sdhci->data->card_int_gpio);
194 goto err_igpio_direction; 197 goto set_drvdata;
195 } 198 }
196 ret = request_irq(gpio_to_irq(sdhci->data->card_int_gpio), 199 ret = devm_request_irq(&pdev->dev,
200 gpio_to_irq(sdhci->data->card_int_gpio),
197 sdhci_gpio_irq, IRQF_TRIGGER_LOW, 201 sdhci_gpio_irq, IRQF_TRIGGER_LOW,
198 mmc_hostname(host->mmc), pdev); 202 mmc_hostname(host->mmc), pdev);
199 if (ret) { 203 if (ret) {
200 dev_dbg(&pdev->dev, "gpio request irq fail: %d\n", 204 dev_dbg(&pdev->dev, "gpio request irq fail: %d\n",
201 sdhci->data->card_int_gpio); 205 sdhci->data->card_int_gpio);
202 goto err_igpio_request_irq; 206 goto set_drvdata;
203 } 207 }
204 208
205 } 209 }
206 210
207 return 0; 211 return 0;
208 212
209err_igpio_request_irq: 213set_drvdata:
210err_igpio_direction:
211 if (sdhci->data->card_int_gpio >= 0)
212 gpio_free(sdhci->data->card_int_gpio);
213err_igpio_request:
214err_pgpio_direction:
215 if (sdhci->data->card_power_gpio >= 0)
216 gpio_free(sdhci->data->card_power_gpio);
217err_pgpio_request:
218 platform_set_drvdata(pdev, NULL); 214 platform_set_drvdata(pdev, NULL);
219 sdhci_remove_host(host, 1); 215 sdhci_remove_host(host, 1);
220err_add_host: 216free_host:
221 iounmap(host->ioaddr);
222err_ioremap:
223 sdhci_free_host(host); 217 sdhci_free_host(host);
224err_alloc_host: 218disable_clk:
225 clk_disable(sdhci->clk); 219 clk_disable(sdhci->clk);
226err_clk_enb: 220put_clk:
227 clk_put(sdhci->clk); 221 clk_put(sdhci->clk);
228err_clk_get:
229 kfree(sdhci);
230err_kzalloc:
231 release_mem_region(iomem->start, resource_size(iomem));
232err: 222err:
233 dev_err(&pdev->dev, "spear-sdhci probe failed: %d\n", ret); 223 dev_err(&pdev->dev, "spear-sdhci probe failed: %d\n", ret);
234 return ret; 224 return ret;
@@ -237,35 +227,19 @@ err:
237static int __devexit sdhci_remove(struct platform_device *pdev) 227static int __devexit sdhci_remove(struct platform_device *pdev)
238{ 228{
239 struct sdhci_host *host = platform_get_drvdata(pdev); 229 struct sdhci_host *host = platform_get_drvdata(pdev);
240 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
241 struct spear_sdhci *sdhci = dev_get_platdata(&pdev->dev); 230 struct spear_sdhci *sdhci = dev_get_platdata(&pdev->dev);
242 int dead; 231 int dead = 0;
243 u32 scratch; 232 u32 scratch;
244 233
245 if (sdhci->data) {
246 if (sdhci->data->card_int_gpio >= 0) {
247 free_irq(gpio_to_irq(sdhci->data->card_int_gpio), pdev);
248 gpio_free(sdhci->data->card_int_gpio);
249 }
250
251 if (sdhci->data->card_power_gpio >= 0)
252 gpio_free(sdhci->data->card_power_gpio);
253 }
254
255 platform_set_drvdata(pdev, NULL); 234 platform_set_drvdata(pdev, NULL);
256 dead = 0;
257 scratch = readl(host->ioaddr + SDHCI_INT_STATUS); 235 scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
258 if (scratch == (u32)-1) 236 if (scratch == (u32)-1)
259 dead = 1; 237 dead = 1;
260 238
261 sdhci_remove_host(host, dead); 239 sdhci_remove_host(host, dead);
262 iounmap(host->ioaddr);
263 sdhci_free_host(host); 240 sdhci_free_host(host);
264 clk_disable(sdhci->clk); 241 clk_disable(sdhci->clk);
265 clk_put(sdhci->clk); 242 clk_put(sdhci->clk);
266 kfree(sdhci);
267 if (iomem)
268 release_mem_region(iomem->start, resource_size(iomem));
269 243
270 return 0; 244 return 0;
271} 245}