diff options
| -rw-r--r-- | drivers/mmc/host/msm_sdcc.c | 99 | ||||
| -rw-r--r-- | drivers/mmc/host/msm_sdcc.h | 1 |
2 files changed, 52 insertions, 48 deletions
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c index 524858597901..591ef3c4e9a7 100644 --- a/drivers/mmc/host/msm_sdcc.c +++ b/drivers/mmc/host/msm_sdcc.c | |||
| @@ -48,7 +48,7 @@ | |||
| 48 | 48 | ||
| 49 | #define DRIVER_NAME "msm-sdcc" | 49 | #define DRIVER_NAME "msm-sdcc" |
| 50 | 50 | ||
| 51 | #define BUSCLK_TIMEOUT (HZ * 5) | 51 | #define BUSCLK_TIMEOUT (HZ) |
| 52 | static unsigned int msmsdcc_fmin = 144000; | 52 | static unsigned int msmsdcc_fmin = 144000; |
| 53 | static unsigned int msmsdcc_fmax = 50000000; | 53 | static unsigned int msmsdcc_fmax = 50000000; |
| 54 | static unsigned int msmsdcc_4bit = 1; | 54 | static unsigned int msmsdcc_4bit = 1; |
| @@ -60,29 +60,42 @@ static unsigned int msmsdcc_sdioirq; | |||
| 60 | #define CMD_SPINMAX 20 | 60 | #define CMD_SPINMAX 20 |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | static inline int | 63 | static inline void |
| 64 | msmsdcc_enable_clocks(struct msmsdcc_host *host, int enable) | 64 | msmsdcc_disable_clocks(struct msmsdcc_host *host, int deferr) |
| 65 | { | 65 | { |
| 66 | int rc; | 66 | WARN_ON(!host->clks_on); |
| 67 | 67 | ||
| 68 | WARN_ON(enable == host->clks_on); | 68 | if (deferr) { |
| 69 | if (enable) { | 69 | mod_timer(&host->busclk_timer, jiffies + BUSCLK_TIMEOUT); |
| 70 | rc = clk_enable(host->pclk); | ||
| 71 | if (rc) | ||
| 72 | return rc; | ||
| 73 | rc = clk_enable(host->clk); | ||
| 74 | if (rc) { | ||
| 75 | clk_disable(host->pclk); | ||
| 76 | return rc; | ||
| 77 | } | ||
| 78 | udelay(1 + ((3 * USEC_PER_SEC) / | ||
| 79 | (host->clk_rate ? host->clk_rate : msmsdcc_fmin))); | ||
| 80 | host->clks_on = 1; | ||
| 81 | } else { | 70 | } else { |
| 71 | del_timer_sync(&host->busclk_timer); | ||
| 72 | // dev_info(mmc_dev(host->mmc), "Immediate clock shutdown\n"); | ||
| 82 | clk_disable(host->clk); | 73 | clk_disable(host->clk); |
| 83 | clk_disable(host->pclk); | 74 | clk_disable(host->pclk); |
| 84 | host->clks_on = 0; | 75 | host->clks_on = 0; |
| 85 | } | 76 | } |
| 77 | } | ||
| 78 | |||
| 79 | static inline int | ||
| 80 | msmsdcc_enable_clocks(struct msmsdcc_host *host) | ||
| 81 | { | ||
| 82 | int rc; | ||
| 83 | |||
| 84 | WARN_ON(host->clks_on); | ||
| 85 | |||
| 86 | del_timer_sync(&host->busclk_timer); | ||
| 87 | |||
| 88 | rc = clk_enable(host->pclk); | ||
| 89 | if (rc) | ||
| 90 | return rc; | ||
| 91 | rc = clk_enable(host->clk); | ||
| 92 | if (rc) { | ||
| 93 | clk_disable(host->pclk); | ||
| 94 | return rc; | ||
| 95 | } | ||
| 96 | udelay(1 + ((3 * USEC_PER_SEC) / | ||
| 97 | (host->clk_rate ? host->clk_rate : msmsdcc_fmin))); | ||
| 98 | host->clks_on = 1; | ||
| 86 | return 0; | 99 | return 0; |
| 87 | } | 100 | } |
| 88 | 101 | ||
| @@ -118,8 +131,7 @@ msmsdcc_request_end(struct msmsdcc_host *host, struct mmc_request *mrq) | |||
| 118 | if (mrq->cmd->error == -ETIMEDOUT) | 131 | if (mrq->cmd->error == -ETIMEDOUT) |
| 119 | mdelay(5); | 132 | mdelay(5); |
| 120 | 133 | ||
| 121 | if (host->use_bustimer) | 134 | msmsdcc_disable_clocks(host, 1); |
| 122 | mod_timer(&host->busclk_timer, jiffies + BUSCLK_TIMEOUT); | ||
| 123 | /* | 135 | /* |
| 124 | * Need to drop the host lock here; mmc_request_done may call | 136 | * Need to drop the host lock here; mmc_request_done may call |
| 125 | * back into the driver... | 137 | * back into the driver... |
| @@ -240,12 +252,12 @@ msmsdcc_dma_complete_func(struct msm_dmov_cmd *cmd, | |||
| 240 | if (!mrq->data->error) | 252 | if (!mrq->data->error) |
| 241 | host->curr.data_xfered = host->curr.xfer_size; | 253 | host->curr.data_xfered = host->curr.xfer_size; |
| 242 | if (!mrq->data->stop || mrq->cmd->error) { | 254 | if (!mrq->data->stop || mrq->cmd->error) { |
| 243 | msmsdcc_writel(host, 0, MMCICOMMAND); | ||
| 244 | host->curr.mrq = NULL; | 255 | host->curr.mrq = NULL; |
| 245 | host->curr.cmd = NULL; | 256 | host->curr.cmd = NULL; |
| 246 | mrq->data->bytes_xfered = host->curr.data_xfered; | 257 | mrq->data->bytes_xfered = host->curr.data_xfered; |
| 247 | 258 | ||
| 248 | spin_unlock_irqrestore(&host->lock, flags); | 259 | spin_unlock_irqrestore(&host->lock, flags); |
| 260 | msmsdcc_disable_clocks(host, 1); | ||
| 249 | mmc_request_done(host->mmc, mrq); | 261 | mmc_request_done(host->mmc, mrq); |
| 250 | return; | 262 | return; |
| 251 | } else | 263 | } else |
| @@ -835,8 +847,14 @@ msmsdcc_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
| 835 | } | 847 | } |
| 836 | 848 | ||
| 837 | host->curr.mrq = mrq; | 849 | host->curr.mrq = mrq; |
| 850 | |||
| 851 | /* Need to drop the host lock here in case | ||
| 852 | * the busclk wd fires | ||
| 853 | */ | ||
| 854 | spin_unlock_irqrestore(&host->lock, flags); | ||
| 838 | if (!host->clks_on) | 855 | if (!host->clks_on) |
| 839 | msmsdcc_enable_clocks(host, 1); | 856 | msmsdcc_enable_clocks(host); |
| 857 | spin_lock_irqsave(&host->lock, flags); | ||
| 840 | 858 | ||
| 841 | if (mrq->data && mrq->data->flags & MMC_DATA_READ) | 859 | if (mrq->data && mrq->data->flags & MMC_DATA_READ) |
| 842 | /* Queue/read data, daisy-chain command when data starts */ | 860 | /* Queue/read data, daisy-chain command when data starts */ |
| @@ -867,9 +885,10 @@ msmsdcc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 867 | int rc; | 885 | int rc; |
| 868 | unsigned long flags; | 886 | unsigned long flags; |
| 869 | 887 | ||
| 870 | spin_lock_irqsave(&host->lock, flags); | ||
| 871 | if (!host->clks_on) | 888 | if (!host->clks_on) |
| 872 | msmsdcc_enable_clocks(host, 1); | 889 | msmsdcc_enable_clocks(host); |
| 890 | |||
| 891 | spin_lock_irqsave(&host->lock, flags); | ||
| 873 | 892 | ||
| 874 | if (ios->clock) { | 893 | if (ios->clock) { |
| 875 | if (ios->clock != host->clk_rate) { | 894 | if (ios->clock != host->clk_rate) { |
| @@ -915,8 +934,7 @@ msmsdcc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 915 | host->pwr = pwr; | 934 | host->pwr = pwr; |
| 916 | msmsdcc_writel(host, pwr, MMCIPOWER); | 935 | msmsdcc_writel(host, pwr, MMCIPOWER); |
| 917 | } | 936 | } |
| 918 | if (host->clks_on) | 937 | msmsdcc_disable_clocks(host, 1); |
| 919 | msmsdcc_enable_clocks(host, 0); | ||
| 920 | spin_unlock_irqrestore(&host->lock, flags); | 938 | spin_unlock_irqrestore(&host->lock, flags); |
| 921 | } | 939 | } |
| 922 | 940 | ||
| @@ -1001,9 +1019,9 @@ msmsdcc_busclk_expired(unsigned long _data) | |||
| 1001 | unsigned long flags; | 1019 | unsigned long flags; |
| 1002 | 1020 | ||
| 1003 | spin_lock_irqsave(&host->lock, flags); | 1021 | spin_lock_irqsave(&host->lock, flags); |
| 1022 | dev_info(mmc_dev(host->mmc), "Bus clock timer expired\n"); | ||
| 1004 | if (host->clks_on) | 1023 | if (host->clks_on) |
| 1005 | msmsdcc_enable_clocks(host, 0); | 1024 | msmsdcc_disable_clocks(host, 0); |
| 1006 | |||
| 1007 | spin_unlock_irqrestore(&host->lock, flags); | 1025 | spin_unlock_irqrestore(&host->lock, flags); |
| 1008 | } | 1026 | } |
| 1009 | 1027 | ||
| @@ -1110,8 +1128,6 @@ msmsdcc_probe(struct platform_device *pdev) | |||
| 1110 | 1128 | ||
| 1111 | host->cmdpoll = 1; | 1129 | host->cmdpoll = 1; |
| 1112 | 1130 | ||
| 1113 | host->use_bustimer = 1; | ||
| 1114 | |||
| 1115 | host->base = ioremap(memres->start, PAGE_SIZE); | 1131 | host->base = ioremap(memres->start, PAGE_SIZE); |
| 1116 | if (!host->base) { | 1132 | if (!host->base) { |
| 1117 | ret = -ENOMEM; | 1133 | ret = -ENOMEM; |
| @@ -1143,7 +1159,7 @@ msmsdcc_probe(struct platform_device *pdev) | |||
| 1143 | } | 1159 | } |
| 1144 | 1160 | ||
| 1145 | /* Enable clocks */ | 1161 | /* Enable clocks */ |
| 1146 | ret = msmsdcc_enable_clocks(host, 1); | 1162 | ret = msmsdcc_enable_clocks(host); |
| 1147 | if (ret) | 1163 | if (ret) |
| 1148 | goto clk_put; | 1164 | goto clk_put; |
| 1149 | 1165 | ||
| @@ -1263,8 +1279,7 @@ msmsdcc_probe(struct platform_device *pdev) | |||
| 1263 | if (host->timer.function) | 1279 | if (host->timer.function) |
| 1264 | pr_info("%s: Polling status mode enabled\n", mmc_hostname(mmc)); | 1280 | pr_info("%s: Polling status mode enabled\n", mmc_hostname(mmc)); |
| 1265 | 1281 | ||
| 1266 | if (host->use_bustimer) | 1282 | msmsdcc_disable_clocks(host, 1); |
| 1267 | mod_timer(&host->busclk_timer, jiffies + BUSCLK_TIMEOUT); | ||
| 1268 | return 0; | 1283 | return 0; |
| 1269 | cmd_irq_free: | 1284 | cmd_irq_free: |
| 1270 | free_irq(cmd_irqres->start, host); | 1285 | free_irq(cmd_irqres->start, host); |
| @@ -1272,7 +1287,7 @@ msmsdcc_probe(struct platform_device *pdev) | |||
| 1272 | if (host->stat_irq) | 1287 | if (host->stat_irq) |
| 1273 | free_irq(host->stat_irq, host); | 1288 | free_irq(host->stat_irq, host); |
| 1274 | clk_disable: | 1289 | clk_disable: |
| 1275 | msmsdcc_enable_clocks(host, 0); | 1290 | msmsdcc_disable_clocks(host, 0); |
| 1276 | clk_put: | 1291 | clk_put: |
| 1277 | clk_put(host->clk); | 1292 | clk_put(host->clk); |
| 1278 | pclk_put: | 1293 | pclk_put: |
| @@ -1293,8 +1308,6 @@ msmsdcc_suspend(struct platform_device *dev, pm_message_t state) | |||
| 1293 | if (mmc) { | 1308 | if (mmc) { |
| 1294 | struct msmsdcc_host *host = mmc_priv(mmc); | 1309 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 1295 | 1310 | ||
| 1296 | if (host->use_bustimer) | ||
| 1297 | del_timer_sync(&host->busclk_timer); | ||
| 1298 | spin_lock_irqsave(&host->lock, flags); | 1311 | spin_lock_irqsave(&host->lock, flags); |
| 1299 | if (host->stat_irq) | 1312 | if (host->stat_irq) |
| 1300 | disable_irq(host->stat_irq); | 1313 | disable_irq(host->stat_irq); |
| @@ -1304,10 +1317,10 @@ msmsdcc_suspend(struct platform_device *dev, pm_message_t state) | |||
| 1304 | if (!rc) { | 1317 | if (!rc) { |
| 1305 | msmsdcc_writel(host, 0, MMCIMASK0); | 1318 | msmsdcc_writel(host, 0, MMCIMASK0); |
| 1306 | 1319 | ||
| 1307 | if (host->clks_on) | ||
| 1308 | msmsdcc_enable_clocks(host, 0); | ||
| 1309 | } | 1320 | } |
| 1310 | spin_unlock_irqrestore(&host->lock, flags); | 1321 | spin_unlock_irqrestore(&host->lock, flags); |
| 1322 | if (host->clks_on) | ||
| 1323 | msmsdcc_disable_clocks(host, 0); | ||
| 1311 | } | 1324 | } |
| 1312 | return rc; | 1325 | return rc; |
| 1313 | } | 1326 | } |
| @@ -1316,27 +1329,19 @@ static int | |||
| 1316 | msmsdcc_resume(struct platform_device *dev) | 1329 | msmsdcc_resume(struct platform_device *dev) |
| 1317 | { | 1330 | { |
| 1318 | struct mmc_host *mmc = mmc_get_drvdata(dev); | 1331 | struct mmc_host *mmc = mmc_get_drvdata(dev); |
| 1319 | unsigned long flags; | ||
| 1320 | 1332 | ||
| 1321 | if (mmc) { | 1333 | if (mmc) { |
| 1322 | struct msmsdcc_host *host = mmc_priv(mmc); | 1334 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 1323 | 1335 | ||
| 1324 | spin_lock_irqsave(&host->lock, flags); | 1336 | msmsdcc_enable_clocks(host); |
| 1325 | |||
| 1326 | if (!host->clks_on) | ||
| 1327 | msmsdcc_enable_clocks(host, 1); | ||
| 1328 | |||
| 1329 | if (host->use_bustimer) | ||
| 1330 | mod_timer(&host->busclk_timer, jiffies + BUSCLK_TIMEOUT); | ||
| 1331 | 1337 | ||
| 1332 | msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0); | 1338 | msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0); |
| 1333 | 1339 | ||
| 1334 | spin_unlock_irqrestore(&host->lock, flags); | ||
| 1335 | |||
| 1336 | if (mmc->card && mmc->card->type != MMC_TYPE_SDIO) | 1340 | if (mmc->card && mmc->card->type != MMC_TYPE_SDIO) |
| 1337 | mmc_resume_host(mmc); | 1341 | mmc_resume_host(mmc); |
| 1338 | if (host->stat_irq) | 1342 | if (host->stat_irq) |
| 1339 | enable_irq(host->stat_irq); | 1343 | enable_irq(host->stat_irq); |
| 1344 | msmsdcc_disable_clocks(host, 1); | ||
| 1340 | } | 1345 | } |
| 1341 | return 0; | 1346 | return 0; |
| 1342 | } | 1347 | } |
diff --git a/drivers/mmc/host/msm_sdcc.h b/drivers/mmc/host/msm_sdcc.h index 361cb6efd248..da0039c9285e 100644 --- a/drivers/mmc/host/msm_sdcc.h +++ b/drivers/mmc/host/msm_sdcc.h | |||
| @@ -215,7 +215,6 @@ struct msmsdcc_host { | |||
| 215 | struct clk *pclk; /* SDCC peripheral bus clock */ | 215 | struct clk *pclk; /* SDCC peripheral bus clock */ |
| 216 | unsigned int clks_on; /* set if clocks are enabled */ | 216 | unsigned int clks_on; /* set if clocks are enabled */ |
| 217 | struct timer_list busclk_timer; | 217 | struct timer_list busclk_timer; |
| 218 | int use_bustimer; | ||
| 219 | 218 | ||
| 220 | unsigned int eject; /* eject state */ | 219 | unsigned int eject; /* eject state */ |
| 221 | 220 | ||
