diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2011-06-21 10:41:51 -0400 |
---|---|---|
committer | Shawn Guo <shawn.guo@linaro.org> | 2011-07-26 21:31:14 -0400 |
commit | 913413c307c919f8b21edccea23a9fd9d9d49a64 (patch) | |
tree | f36a4cf7e1f2111d4bdf14253476d115b5110f1f /drivers/mmc/host/sdhci-esdhc-imx.c | |
parent | ca2cc333920690db87a03c2ee3bd6f43adb3e7fb (diff) |
mmc: sdhci-esdhc-imx: extend card_detect and write_protect support for mx5
The patch extends card_detect and write_protect support to get mx5
family and more scenarios supported. The changes include:
* Turn platform_data from optional to mandatory
* Add cd_types and wp_types into platform_data to cover more use
cases
* Remove the use of flag ESDHC_FLAG_GPIO_FOR_CD
* Adjust some machine codes to adopt the platform_data changes
* Work around the issue that software reset will get card detection
circuit stop working
With this patch, card_detect and write_protect gets supported on
mx5 based platforms.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Chris Ball <cjb@laptop.org>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Tested-by: Arnaud Patard <arnaud.patard@rtp-net.org>
Acked-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/host/sdhci-esdhc-imx.c')
-rw-r--r-- | drivers/mmc/host/sdhci-esdhc-imx.c | 138 |
1 files changed, 87 insertions, 51 deletions
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 710b706f4fcf..4269bb498ff0 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #define SDHCI_VENDOR_SPEC 0xC0 | 29 | #define SDHCI_VENDOR_SPEC 0xC0 |
30 | #define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002 | 30 | #define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002 |
31 | 31 | ||
32 | #define ESDHC_FLAG_GPIO_FOR_CD (1 << 0) | ||
33 | /* | 32 | /* |
34 | * The CMDTYPE of the CMD register (offset 0xE) should be set to | 33 | * The CMDTYPE of the CMD register (offset 0xE) should be set to |
35 | * "11" when the STOP CMD12 is issued on imx53 to abort one | 34 | * "11" when the STOP CMD12 is issued on imx53 to abort one |
@@ -58,19 +57,15 @@ static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, i | |||
58 | 57 | ||
59 | static u32 esdhc_readl_le(struct sdhci_host *host, int reg) | 58 | static u32 esdhc_readl_le(struct sdhci_host *host, int reg) |
60 | { | 59 | { |
61 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | 60 | struct esdhc_platform_data *boarddata = |
62 | struct pltfm_imx_data *imx_data = pltfm_host->priv; | 61 | host->mmc->parent->platform_data; |
63 | 62 | ||
64 | /* fake CARD_PRESENT flag on mx25/35 */ | 63 | /* fake CARD_PRESENT flag */ |
65 | u32 val = readl(host->ioaddr + reg); | 64 | u32 val = readl(host->ioaddr + reg); |
66 | 65 | ||
67 | if (unlikely((reg == SDHCI_PRESENT_STATE) | 66 | if (unlikely((reg == SDHCI_PRESENT_STATE) |
68 | && (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD))) { | 67 | && gpio_is_valid(boarddata->cd_gpio))) { |
69 | struct esdhc_platform_data *boarddata = | 68 | if (gpio_get_value(boarddata->cd_gpio)) |
70 | host->mmc->parent->platform_data; | ||
71 | |||
72 | if (boarddata && gpio_is_valid(boarddata->cd_gpio) | ||
73 | && gpio_get_value(boarddata->cd_gpio)) | ||
74 | /* no card, if a valid gpio says so... */ | 69 | /* no card, if a valid gpio says so... */ |
75 | val &= ~SDHCI_CARD_PRESENT; | 70 | val &= ~SDHCI_CARD_PRESENT; |
76 | else | 71 | else |
@@ -85,12 +80,13 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg) | |||
85 | { | 80 | { |
86 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | 81 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
87 | struct pltfm_imx_data *imx_data = pltfm_host->priv; | 82 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
83 | struct esdhc_platform_data *boarddata = | ||
84 | host->mmc->parent->platform_data; | ||
88 | 85 | ||
89 | if (unlikely((reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE) | 86 | if (unlikely((reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE) |
90 | && (imx_data->flags & ESDHC_FLAG_GPIO_FOR_CD))) | 87 | && (boarddata->cd_type == ESDHC_CD_GPIO))) |
91 | /* | 88 | /* |
92 | * these interrupts won't work with a custom card_detect gpio | 89 | * these interrupts won't work with a custom card_detect gpio |
93 | * (only applied to mx25/35) | ||
94 | */ | 90 | */ |
95 | val &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); | 91 | val &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); |
96 | 92 | ||
@@ -173,6 +169,17 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) | |||
173 | return; | 169 | return; |
174 | } | 170 | } |
175 | esdhc_clrset_le(host, 0xff, val, reg); | 171 | esdhc_clrset_le(host, 0xff, val, reg); |
172 | |||
173 | /* | ||
174 | * The esdhc has a design violation to SDHC spec which tells | ||
175 | * that software reset should not affect card detection circuit. | ||
176 | * But esdhc clears its SYSCTL register bits [0..2] during the | ||
177 | * software reset. This will stop those clocks that card detection | ||
178 | * circuit relies on. To work around it, we turn the clocks on back | ||
179 | * to keep card detection circuit functional. | ||
180 | */ | ||
181 | if ((reg == SDHCI_SOFTWARE_RESET) && (val & 1)) | ||
182 | esdhc_clrset_le(host, 0x7, 0x7, ESDHC_SYSTEM_CONTROL); | ||
176 | } | 183 | } |
177 | 184 | ||
178 | static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host) | 185 | static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host) |
@@ -189,6 +196,25 @@ static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host) | |||
189 | return clk_get_rate(pltfm_host->clk) / 256 / 16; | 196 | return clk_get_rate(pltfm_host->clk) / 256 / 16; |
190 | } | 197 | } |
191 | 198 | ||
199 | static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host) | ||
200 | { | ||
201 | struct esdhc_platform_data *boarddata = | ||
202 | host->mmc->parent->platform_data; | ||
203 | |||
204 | switch (boarddata->wp_type) { | ||
205 | case ESDHC_WP_GPIO: | ||
206 | if (gpio_is_valid(boarddata->wp_gpio)) | ||
207 | return gpio_get_value(boarddata->wp_gpio); | ||
208 | case ESDHC_WP_CONTROLLER: | ||
209 | return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) & | ||
210 | SDHCI_WRITE_PROTECT); | ||
211 | case ESDHC_WP_NONE: | ||
212 | break; | ||
213 | } | ||
214 | |||
215 | return -ENOSYS; | ||
216 | } | ||
217 | |||
192 | static struct sdhci_ops sdhci_esdhc_ops = { | 218 | static struct sdhci_ops sdhci_esdhc_ops = { |
193 | .read_l = esdhc_readl_le, | 219 | .read_l = esdhc_readl_le, |
194 | .read_w = esdhc_readw_le, | 220 | .read_w = esdhc_readw_le, |
@@ -198,6 +224,7 @@ static struct sdhci_ops sdhci_esdhc_ops = { | |||
198 | .set_clock = esdhc_set_clock, | 224 | .set_clock = esdhc_set_clock, |
199 | .get_max_clock = esdhc_pltfm_get_max_clock, | 225 | .get_max_clock = esdhc_pltfm_get_max_clock, |
200 | .get_min_clock = esdhc_pltfm_get_min_clock, | 226 | .get_min_clock = esdhc_pltfm_get_min_clock, |
227 | .get_ro = esdhc_pltfm_get_ro, | ||
201 | }; | 228 | }; |
202 | 229 | ||
203 | static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { | 230 | static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { |
@@ -207,17 +234,6 @@ static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { | |||
207 | .ops = &sdhci_esdhc_ops, | 234 | .ops = &sdhci_esdhc_ops, |
208 | }; | 235 | }; |
209 | 236 | ||
210 | static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host) | ||
211 | { | ||
212 | struct esdhc_platform_data *boarddata = | ||
213 | host->mmc->parent->platform_data; | ||
214 | |||
215 | if (boarddata && gpio_is_valid(boarddata->wp_gpio)) | ||
216 | return gpio_get_value(boarddata->wp_gpio); | ||
217 | else | ||
218 | return -ENOSYS; | ||
219 | } | ||
220 | |||
221 | static irqreturn_t cd_irq(int irq, void *data) | 237 | static irqreturn_t cd_irq(int irq, void *data) |
222 | { | 238 | { |
223 | struct sdhci_host *sdhost = (struct sdhci_host *)data; | 239 | struct sdhci_host *sdhost = (struct sdhci_host *)data; |
@@ -258,47 +274,65 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev) | |||
258 | if (!cpu_is_mx25()) | 274 | if (!cpu_is_mx25()) |
259 | host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; | 275 | host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; |
260 | 276 | ||
261 | if (cpu_is_mx25() || cpu_is_mx35()) { | 277 | if (cpu_is_mx25() || cpu_is_mx35()) |
262 | /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ | 278 | /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ |
263 | host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK; | 279 | host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK; |
264 | /* write_protect can't be routed to controller, use gpio */ | ||
265 | sdhci_esdhc_ops.get_ro = esdhc_pltfm_get_ro; | ||
266 | } | ||
267 | 280 | ||
268 | if (!(cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51())) | 281 | if (!(cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51())) |
269 | imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; | 282 | imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; |
270 | 283 | ||
271 | boarddata = host->mmc->parent->platform_data; | 284 | boarddata = host->mmc->parent->platform_data; |
272 | if (boarddata) { | 285 | if (!boarddata) { |
286 | dev_err(mmc_dev(host->mmc), "no board data!\n"); | ||
287 | err = -EINVAL; | ||
288 | goto no_board_data; | ||
289 | } | ||
290 | |||
291 | /* write_protect */ | ||
292 | if (boarddata->wp_type == ESDHC_WP_GPIO) { | ||
273 | err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP"); | 293 | err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP"); |
274 | if (err) { | 294 | if (err) { |
275 | dev_warn(mmc_dev(host->mmc), | 295 | dev_warn(mmc_dev(host->mmc), |
276 | "no write-protect pin available!\n"); | 296 | "no write-protect pin available!\n"); |
277 | boarddata->wp_gpio = err; | 297 | boarddata->wp_gpio = -EINVAL; |
278 | } | 298 | } |
299 | } else { | ||
300 | boarddata->wp_gpio = -EINVAL; | ||
301 | } | ||
302 | |||
303 | /* card_detect */ | ||
304 | if (boarddata->cd_type != ESDHC_CD_GPIO) | ||
305 | boarddata->cd_gpio = -EINVAL; | ||
279 | 306 | ||
307 | switch (boarddata->cd_type) { | ||
308 | case ESDHC_CD_GPIO: | ||
280 | err = gpio_request_one(boarddata->cd_gpio, GPIOF_IN, "ESDHC_CD"); | 309 | err = gpio_request_one(boarddata->cd_gpio, GPIOF_IN, "ESDHC_CD"); |
281 | if (err) { | 310 | if (err) { |
282 | dev_warn(mmc_dev(host->mmc), | 311 | dev_err(mmc_dev(host->mmc), |
283 | "no card-detect pin available!\n"); | 312 | "no card-detect pin available!\n"); |
284 | goto no_card_detect_pin; | 313 | goto no_card_detect_pin; |
285 | } | 314 | } |
286 | 315 | ||
287 | /* i.MX5x has issues to be researched */ | ||
288 | if (!cpu_is_mx25() && !cpu_is_mx35()) | ||
289 | goto not_supported; | ||
290 | |||
291 | err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq, | 316 | err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq, |
292 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | 317 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, |
293 | mmc_hostname(host->mmc), host); | 318 | mmc_hostname(host->mmc), host); |
294 | if (err) { | 319 | if (err) { |
295 | dev_warn(mmc_dev(host->mmc), "request irq error\n"); | 320 | dev_err(mmc_dev(host->mmc), "request irq error\n"); |
296 | goto no_card_detect_irq; | 321 | goto no_card_detect_irq; |
297 | } | 322 | } |
323 | /* fall through */ | ||
298 | 324 | ||
299 | imx_data->flags |= ESDHC_FLAG_GPIO_FOR_CD; | 325 | case ESDHC_CD_CONTROLLER: |
300 | /* Now we have a working card_detect again */ | 326 | /* we have a working card_detect back */ |
301 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; | 327 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
328 | break; | ||
329 | |||
330 | case ESDHC_CD_PERMANENT: | ||
331 | host->mmc->caps = MMC_CAP_NONREMOVABLE; | ||
332 | break; | ||
333 | |||
334 | case ESDHC_CD_NONE: | ||
335 | break; | ||
302 | } | 336 | } |
303 | 337 | ||
304 | err = sdhci_add_host(host); | 338 | err = sdhci_add_host(host); |
@@ -307,16 +341,20 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev) | |||
307 | 341 | ||
308 | return 0; | 342 | return 0; |
309 | 343 | ||
310 | no_card_detect_irq: | 344 | err_add_host: |
311 | gpio_free(boarddata->cd_gpio); | 345 | if (gpio_is_valid(boarddata->cd_gpio)) |
312 | no_card_detect_pin: | 346 | free_irq(gpio_to_irq(boarddata->cd_gpio), host); |
313 | boarddata->cd_gpio = err; | 347 | no_card_detect_irq: |
314 | not_supported: | 348 | if (gpio_is_valid(boarddata->cd_gpio)) |
315 | kfree(imx_data); | 349 | gpio_free(boarddata->cd_gpio); |
316 | err_add_host: | 350 | if (gpio_is_valid(boarddata->wp_gpio)) |
351 | gpio_free(boarddata->wp_gpio); | ||
352 | no_card_detect_pin: | ||
353 | no_board_data: | ||
317 | clk_disable(pltfm_host->clk); | 354 | clk_disable(pltfm_host->clk); |
318 | clk_put(pltfm_host->clk); | 355 | clk_put(pltfm_host->clk); |
319 | err_clk_get: | 356 | err_clk_get: |
357 | kfree(imx_data); | ||
320 | sdhci_pltfm_free(pdev); | 358 | sdhci_pltfm_free(pdev); |
321 | return err; | 359 | return err; |
322 | } | 360 | } |
@@ -331,14 +369,12 @@ static int __devexit sdhci_esdhc_imx_remove(struct platform_device *pdev) | |||
331 | 369 | ||
332 | sdhci_remove_host(host, dead); | 370 | sdhci_remove_host(host, dead); |
333 | 371 | ||
334 | if (boarddata && gpio_is_valid(boarddata->wp_gpio)) | 372 | if (gpio_is_valid(boarddata->wp_gpio)) |
335 | gpio_free(boarddata->wp_gpio); | 373 | gpio_free(boarddata->wp_gpio); |
336 | 374 | ||
337 | if (boarddata && gpio_is_valid(boarddata->cd_gpio)) { | 375 | if (gpio_is_valid(boarddata->cd_gpio)) { |
376 | free_irq(gpio_to_irq(boarddata->cd_gpio), host); | ||
338 | gpio_free(boarddata->cd_gpio); | 377 | gpio_free(boarddata->cd_gpio); |
339 | |||
340 | if (!(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)) | ||
341 | free_irq(gpio_to_irq(boarddata->cd_gpio), host); | ||
342 | } | 378 | } |
343 | 379 | ||
344 | clk_disable(pltfm_host->clk); | 380 | clk_disable(pltfm_host->clk); |