diff options
Diffstat (limited to 'drivers/mmc/host/sdhci-spear.c')
-rw-r--r-- | drivers/mmc/host/sdhci-spear.c | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c index 6dfa82e03c7e..1fe32dfa7cd4 100644 --- a/drivers/mmc/host/sdhci-spear.c +++ b/drivers/mmc/host/sdhci-spear.c | |||
@@ -75,8 +75,6 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
75 | struct spear_sdhci *sdhci; | 75 | struct spear_sdhci *sdhci; |
76 | int ret; | 76 | int ret; |
77 | 77 | ||
78 | BUG_ON(pdev == NULL); | ||
79 | |||
80 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 78 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
81 | if (!iomem) { | 79 | if (!iomem) { |
82 | ret = -ENOMEM; | 80 | ret = -ENOMEM; |
@@ -84,18 +82,18 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
84 | goto err; | 82 | goto err; |
85 | } | 83 | } |
86 | 84 | ||
87 | if (!request_mem_region(iomem->start, resource_size(iomem), | 85 | if (!devm_request_mem_region(&pdev->dev, iomem->start, |
88 | "spear-sdhci")) { | 86 | resource_size(iomem), "spear-sdhci")) { |
89 | ret = -EBUSY; | 87 | ret = -EBUSY; |
90 | dev_dbg(&pdev->dev, "cannot request region\n"); | 88 | dev_dbg(&pdev->dev, "cannot request region\n"); |
91 | goto err; | 89 | goto err; |
92 | } | 90 | } |
93 | 91 | ||
94 | sdhci = kzalloc(sizeof(*sdhci), GFP_KERNEL); | 92 | sdhci = devm_kzalloc(&pdev->dev, sizeof(*sdhci), GFP_KERNEL); |
95 | if (!sdhci) { | 93 | if (!sdhci) { |
96 | ret = -ENOMEM; | 94 | ret = -ENOMEM; |
97 | dev_dbg(&pdev->dev, "cannot allocate memory for sdhci\n"); | 95 | dev_dbg(&pdev->dev, "cannot allocate memory for sdhci\n"); |
98 | goto err_kzalloc; | 96 | goto err; |
99 | } | 97 | } |
100 | 98 | ||
101 | /* clk enable */ | 99 | /* clk enable */ |
@@ -103,13 +101,13 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
103 | if (IS_ERR(sdhci->clk)) { | 101 | if (IS_ERR(sdhci->clk)) { |
104 | ret = PTR_ERR(sdhci->clk); | 102 | ret = PTR_ERR(sdhci->clk); |
105 | dev_dbg(&pdev->dev, "Error getting clock\n"); | 103 | dev_dbg(&pdev->dev, "Error getting clock\n"); |
106 | goto err_clk_get; | 104 | goto err; |
107 | } | 105 | } |
108 | 106 | ||
109 | ret = clk_enable(sdhci->clk); | 107 | ret = clk_enable(sdhci->clk); |
110 | if (ret) { | 108 | if (ret) { |
111 | dev_dbg(&pdev->dev, "Error enabling clock\n"); | 109 | dev_dbg(&pdev->dev, "Error enabling clock\n"); |
112 | goto err_clk_enb; | 110 | goto put_clk; |
113 | } | 111 | } |
114 | 112 | ||
115 | /* overwrite platform_data */ | 113 | /* overwrite platform_data */ |
@@ -124,7 +122,7 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
124 | if (IS_ERR(host)) { | 122 | if (IS_ERR(host)) { |
125 | ret = PTR_ERR(host); | 123 | ret = PTR_ERR(host); |
126 | dev_dbg(&pdev->dev, "error allocating host\n"); | 124 | dev_dbg(&pdev->dev, "error allocating host\n"); |
127 | goto err_alloc_host; | 125 | goto disable_clk; |
128 | } | 126 | } |
129 | 127 | ||
130 | host->hw_name = "sdhci"; | 128 | host->hw_name = "sdhci"; |
@@ -132,17 +130,18 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
132 | host->irq = platform_get_irq(pdev, 0); | 130 | host->irq = platform_get_irq(pdev, 0); |
133 | host->quirks = SDHCI_QUIRK_BROKEN_ADMA; | 131 | host->quirks = SDHCI_QUIRK_BROKEN_ADMA; |
134 | 132 | ||
135 | host->ioaddr = ioremap(iomem->start, resource_size(iomem)); | 133 | host->ioaddr = devm_ioremap(&pdev->dev, iomem->start, |
134 | resource_size(iomem)); | ||
136 | if (!host->ioaddr) { | 135 | if (!host->ioaddr) { |
137 | ret = -ENOMEM; | 136 | ret = -ENOMEM; |
138 | dev_dbg(&pdev->dev, "failed to remap registers\n"); | 137 | dev_dbg(&pdev->dev, "failed to remap registers\n"); |
139 | goto err_ioremap; | 138 | goto free_host; |
140 | } | 139 | } |
141 | 140 | ||
142 | ret = sdhci_add_host(host); | 141 | ret = sdhci_add_host(host); |
143 | if (ret) { | 142 | if (ret) { |
144 | dev_dbg(&pdev->dev, "error adding host\n"); | 143 | dev_dbg(&pdev->dev, "error adding host\n"); |
145 | goto err_add_host; | 144 | goto free_host; |
146 | } | 145 | } |
147 | 146 | ||
148 | platform_set_drvdata(pdev, host); | 147 | platform_set_drvdata(pdev, host); |
@@ -161,11 +160,12 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
161 | if (sdhci->data->card_power_gpio >= 0) { | 160 | if (sdhci->data->card_power_gpio >= 0) { |
162 | int val = 0; | 161 | int val = 0; |
163 | 162 | ||
164 | ret = gpio_request(sdhci->data->card_power_gpio, "sdhci"); | 163 | ret = devm_gpio_request(&pdev->dev, |
164 | sdhci->data->card_power_gpio, "sdhci"); | ||
165 | if (ret < 0) { | 165 | if (ret < 0) { |
166 | dev_dbg(&pdev->dev, "gpio request fail: %d\n", | 166 | dev_dbg(&pdev->dev, "gpio request fail: %d\n", |
167 | sdhci->data->card_power_gpio); | 167 | sdhci->data->card_power_gpio); |
168 | goto err_pgpio_request; | 168 | goto set_drvdata; |
169 | } | 169 | } |
170 | 170 | ||
171 | if (sdhci->data->power_always_enb) | 171 | if (sdhci->data->power_always_enb) |
@@ -177,60 +177,48 @@ static int __devinit sdhci_probe(struct platform_device *pdev) | |||
177 | if (ret) { | 177 | if (ret) { |
178 | dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", | 178 | dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", |
179 | sdhci->data->card_power_gpio); | 179 | sdhci->data->card_power_gpio); |
180 | goto err_pgpio_direction; | 180 | goto set_drvdata; |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | if (sdhci->data->card_int_gpio >= 0) { | 184 | if (sdhci->data->card_int_gpio >= 0) { |
185 | ret = gpio_request(sdhci->data->card_int_gpio, "sdhci"); | 185 | ret = devm_gpio_request(&pdev->dev, sdhci->data->card_int_gpio, |
186 | "sdhci"); | ||
186 | if (ret < 0) { | 187 | if (ret < 0) { |
187 | dev_dbg(&pdev->dev, "gpio request fail: %d\n", | 188 | dev_dbg(&pdev->dev, "gpio request fail: %d\n", |
188 | sdhci->data->card_int_gpio); | 189 | sdhci->data->card_int_gpio); |
189 | goto err_igpio_request; | 190 | goto set_drvdata; |
190 | } | 191 | } |
191 | 192 | ||
192 | ret = gpio_direction_input(sdhci->data->card_int_gpio); | 193 | ret = gpio_direction_input(sdhci->data->card_int_gpio); |
193 | if (ret) { | 194 | if (ret) { |
194 | dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", | 195 | dev_dbg(&pdev->dev, "gpio set direction fail: %d\n", |
195 | sdhci->data->card_int_gpio); | 196 | sdhci->data->card_int_gpio); |
196 | goto err_igpio_direction; | 197 | goto set_drvdata; |
197 | } | 198 | } |
198 | 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), | ||
199 | sdhci_gpio_irq, IRQF_TRIGGER_LOW, | 201 | sdhci_gpio_irq, IRQF_TRIGGER_LOW, |
200 | mmc_hostname(host->mmc), pdev); | 202 | mmc_hostname(host->mmc), pdev); |
201 | if (ret) { | 203 | if (ret) { |
202 | dev_dbg(&pdev->dev, "gpio request irq fail: %d\n", | 204 | dev_dbg(&pdev->dev, "gpio request irq fail: %d\n", |
203 | sdhci->data->card_int_gpio); | 205 | sdhci->data->card_int_gpio); |
204 | goto err_igpio_request_irq; | 206 | goto set_drvdata; |
205 | } | 207 | } |
206 | 208 | ||
207 | } | 209 | } |
208 | 210 | ||
209 | return 0; | 211 | return 0; |
210 | 212 | ||
211 | err_igpio_request_irq: | 213 | set_drvdata: |
212 | err_igpio_direction: | ||
213 | if (sdhci->data->card_int_gpio >= 0) | ||
214 | gpio_free(sdhci->data->card_int_gpio); | ||
215 | err_igpio_request: | ||
216 | err_pgpio_direction: | ||
217 | if (sdhci->data->card_power_gpio >= 0) | ||
218 | gpio_free(sdhci->data->card_power_gpio); | ||
219 | err_pgpio_request: | ||
220 | platform_set_drvdata(pdev, NULL); | 214 | platform_set_drvdata(pdev, NULL); |
221 | sdhci_remove_host(host, 1); | 215 | sdhci_remove_host(host, 1); |
222 | err_add_host: | 216 | free_host: |
223 | iounmap(host->ioaddr); | ||
224 | err_ioremap: | ||
225 | sdhci_free_host(host); | 217 | sdhci_free_host(host); |
226 | err_alloc_host: | 218 | disable_clk: |
227 | clk_disable(sdhci->clk); | 219 | clk_disable(sdhci->clk); |
228 | err_clk_enb: | 220 | put_clk: |
229 | clk_put(sdhci->clk); | 221 | clk_put(sdhci->clk); |
230 | err_clk_get: | ||
231 | kfree(sdhci); | ||
232 | err_kzalloc: | ||
233 | release_mem_region(iomem->start, resource_size(iomem)); | ||
234 | err: | 222 | err: |
235 | dev_err(&pdev->dev, "spear-sdhci probe failed: %d\n", ret); | 223 | dev_err(&pdev->dev, "spear-sdhci probe failed: %d\n", ret); |
236 | return ret; | 224 | return ret; |
@@ -239,35 +227,19 @@ err: | |||
239 | static int __devexit sdhci_remove(struct platform_device *pdev) | 227 | static int __devexit sdhci_remove(struct platform_device *pdev) |
240 | { | 228 | { |
241 | struct sdhci_host *host = platform_get_drvdata(pdev); | 229 | struct sdhci_host *host = platform_get_drvdata(pdev); |
242 | struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
243 | struct spear_sdhci *sdhci = dev_get_platdata(&pdev->dev); | 230 | struct spear_sdhci *sdhci = dev_get_platdata(&pdev->dev); |
244 | int dead; | 231 | int dead = 0; |
245 | u32 scratch; | 232 | u32 scratch; |
246 | 233 | ||
247 | if (sdhci->data) { | ||
248 | if (sdhci->data->card_int_gpio >= 0) { | ||
249 | free_irq(gpio_to_irq(sdhci->data->card_int_gpio), pdev); | ||
250 | gpio_free(sdhci->data->card_int_gpio); | ||
251 | } | ||
252 | |||
253 | if (sdhci->data->card_power_gpio >= 0) | ||
254 | gpio_free(sdhci->data->card_power_gpio); | ||
255 | } | ||
256 | |||
257 | platform_set_drvdata(pdev, NULL); | 234 | platform_set_drvdata(pdev, NULL); |
258 | dead = 0; | ||
259 | scratch = readl(host->ioaddr + SDHCI_INT_STATUS); | 235 | scratch = readl(host->ioaddr + SDHCI_INT_STATUS); |
260 | if (scratch == (u32)-1) | 236 | if (scratch == (u32)-1) |
261 | dead = 1; | 237 | dead = 1; |
262 | 238 | ||
263 | sdhci_remove_host(host, dead); | 239 | sdhci_remove_host(host, dead); |
264 | iounmap(host->ioaddr); | ||
265 | sdhci_free_host(host); | 240 | sdhci_free_host(host); |
266 | clk_disable(sdhci->clk); | 241 | clk_disable(sdhci->clk); |
267 | clk_put(sdhci->clk); | 242 | clk_put(sdhci->clk); |
268 | kfree(sdhci); | ||
269 | if (iomem) | ||
270 | release_mem_region(iomem->start, resource_size(iomem)); | ||
271 | 243 | ||
272 | return 0; | 244 | return 0; |
273 | } | 245 | } |