| 1 | From 39e3d37b1f7194277b8a3ea3536a67ec2d24491e Mon Sep 17 00:00:00 2001 |
| 2 | From: San Mehat <san@android.com> |
| 3 | Date: Thu, 4 Dec 2008 11:18:00 -0800 |
| 4 | Subject: [PATCH 100/134] mmc: sd: Add retries in re-detection |
| 5 | |
| 6 | Signed-off-by: San Mehat <san@android.com> |
| 7 | --- |
| 8 | drivers/mmc/core/sd.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- |
| 9 | 1 files changed, 43 insertions(+), 3 deletions(-) |
| 10 | |
| 11 | --- a/drivers/mmc/core/sd.c |
| 12 | +++ b/drivers/mmc/core/sd.c |
| 13 | @@ -558,18 +558,37 @@ static void mmc_sd_remove(struct mmc_hos |
| 14 | */ |
| 15 | static void mmc_sd_detect(struct mmc_host *host) |
| 16 | { |
| 17 | - int err; |
| 18 | + int err = 0; |
| 19 | +#ifdef CONFIG_MMC_PARANOID_SD_INIT |
| 20 | + int retries = 5; |
| 21 | +#endif |
| 22 | |
| 23 | BUG_ON(!host); |
| 24 | BUG_ON(!host->card); |
| 25 | - |
| 26 | + |
| 27 | mmc_claim_host(host); |
| 28 | |
| 29 | /* |
| 30 | * Just check if our card has been removed. |
| 31 | */ |
| 32 | +#ifdef CONFIG_MMC_PARANOID_SD_INIT |
| 33 | + while(retries) { |
| 34 | + err = mmc_send_status(host->card, NULL); |
| 35 | + printk("%s(%s): err = %d\n", __func__, mmc_hostname(host), err); |
| 36 | + if (err) { |
| 37 | + retries--; |
| 38 | + udelay(5); |
| 39 | + continue; |
| 40 | + } |
| 41 | + break; |
| 42 | + } |
| 43 | + if (!retries) { |
| 44 | + printk(KERN_ERR "%s(%s): Unable to re-detect card (%d)\n", |
| 45 | + __func__, mmc_hostname(host), err); |
| 46 | + } |
| 47 | +#else |
| 48 | err = mmc_send_status(host->card, NULL); |
| 49 | - |
| 50 | +#endif |
| 51 | mmc_release_host(host); |
| 52 | |
| 53 | if (err) { |
| 54 | @@ -664,6 +683,9 @@ static const struct mmc_bus_ops mmc_sd_o |
| 55 | int mmc_attach_sd(struct mmc_host *host, u32 ocr) |
| 56 | { |
| 57 | int err; |
| 58 | +#ifdef CONFIG_MMC_PARANOID_SD_INIT |
| 59 | + int retries; |
| 60 | +#endif |
| 61 | |
| 62 | BUG_ON(!host); |
| 63 | WARN_ON(!host->claimed); |
| 64 | @@ -712,9 +734,27 @@ int mmc_attach_sd(struct mmc_host *host, |
| 65 | /* |
| 66 | * Detect and init the card. |
| 67 | */ |
| 68 | +#ifdef CONFIG_MMC_PARANOID_SD_INIT |
| 69 | + retries = 5; |
| 70 | + while (retries) { |
| 71 | + err = mmc_sd_init_card(host, host->ocr, NULL); |
| 72 | + if (err) { |
| 73 | + retries--; |
| 74 | + continue; |
| 75 | + } |
| 76 | + break; |
| 77 | + } |
| 78 | + |
| 79 | + if (!retries) { |
| 80 | + printk(KERN_ERR "%s: mmc_sd_init_card() failure (err = %d)\n", |
| 81 | + mmc_hostname(host), err); |
| 82 | + goto err; |
| 83 | + } |
| 84 | +#else |
| 85 | err = mmc_sd_init_card(host, host->ocr, NULL); |
| 86 | if (err) |
| 87 | goto err; |
| 88 | +#endif |
| 89 | |
| 90 | mmc_release_host(host); |
| 91 | |
| 92 | |