diff options
Diffstat (limited to 'drivers/mmc/host/mxcmmc.c')
-rw-r--r-- | drivers/mmc/host/mxcmmc.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c index b4a615c55f28..f4cbe473670e 100644 --- a/drivers/mmc/host/mxcmmc.c +++ b/drivers/mmc/host/mxcmmc.c | |||
@@ -140,6 +140,8 @@ struct mxcmci_host { | |||
140 | struct work_struct datawork; | 140 | struct work_struct datawork; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios); | ||
144 | |||
143 | static inline int mxcmci_use_dma(struct mxcmci_host *host) | 145 | static inline int mxcmci_use_dma(struct mxcmci_host *host) |
144 | { | 146 | { |
145 | return host->do_dma; | 147 | return host->do_dma; |
@@ -160,7 +162,7 @@ static void mxcmci_softreset(struct mxcmci_host *host) | |||
160 | writew(0xff, host->base + MMC_REG_RES_TO); | 162 | writew(0xff, host->base + MMC_REG_RES_TO); |
161 | } | 163 | } |
162 | 164 | ||
163 | static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | 165 | static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) |
164 | { | 166 | { |
165 | unsigned int nob = data->blocks; | 167 | unsigned int nob = data->blocks; |
166 | unsigned int blksz = data->blksz; | 168 | unsigned int blksz = data->blksz; |
@@ -168,6 +170,7 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
168 | #ifdef HAS_DMA | 170 | #ifdef HAS_DMA |
169 | struct scatterlist *sg; | 171 | struct scatterlist *sg; |
170 | int i; | 172 | int i; |
173 | int ret; | ||
171 | #endif | 174 | #endif |
172 | if (data->flags & MMC_DATA_STREAM) | 175 | if (data->flags & MMC_DATA_STREAM) |
173 | nob = 0xffff; | 176 | nob = 0xffff; |
@@ -183,7 +186,7 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
183 | for_each_sg(data->sg, sg, data->sg_len, i) { | 186 | for_each_sg(data->sg, sg, data->sg_len, i) { |
184 | if (sg->offset & 3 || sg->length & 3) { | 187 | if (sg->offset & 3 || sg->length & 3) { |
185 | host->do_dma = 0; | 188 | host->do_dma = 0; |
186 | return; | 189 | return 0; |
187 | } | 190 | } |
188 | } | 191 | } |
189 | 192 | ||
@@ -192,23 +195,30 @@ static void mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) | |||
192 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | 195 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, |
193 | data->sg_len, host->dma_dir); | 196 | data->sg_len, host->dma_dir); |
194 | 197 | ||
195 | imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, datasize, | 198 | ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, |
196 | host->res->start + MMC_REG_BUFFER_ACCESS, | 199 | datasize, |
197 | DMA_MODE_READ); | 200 | host->res->start + MMC_REG_BUFFER_ACCESS, |
201 | DMA_MODE_READ); | ||
198 | } else { | 202 | } else { |
199 | host->dma_dir = DMA_TO_DEVICE; | 203 | host->dma_dir = DMA_TO_DEVICE; |
200 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, | 204 | host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg, |
201 | data->sg_len, host->dma_dir); | 205 | data->sg_len, host->dma_dir); |
202 | 206 | ||
203 | imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, datasize, | 207 | ret = imx_dma_setup_sg(host->dma, data->sg, host->dma_nents, |
204 | host->res->start + MMC_REG_BUFFER_ACCESS, | 208 | datasize, |
205 | DMA_MODE_WRITE); | 209 | host->res->start + MMC_REG_BUFFER_ACCESS, |
210 | DMA_MODE_WRITE); | ||
206 | } | 211 | } |
207 | 212 | ||
213 | if (ret) { | ||
214 | dev_err(mmc_dev(host->mmc), "failed to setup DMA : %d\n", ret); | ||
215 | return ret; | ||
216 | } | ||
208 | wmb(); | 217 | wmb(); |
209 | 218 | ||
210 | imx_dma_enable(host->dma); | 219 | imx_dma_enable(host->dma); |
211 | #endif /* HAS_DMA */ | 220 | #endif /* HAS_DMA */ |
221 | return 0; | ||
212 | } | 222 | } |
213 | 223 | ||
214 | static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd, | 224 | static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd, |
@@ -345,8 +355,11 @@ static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask) | |||
345 | stat = readl(host->base + MMC_REG_STATUS); | 355 | stat = readl(host->base + MMC_REG_STATUS); |
346 | if (stat & STATUS_ERR_MASK) | 356 | if (stat & STATUS_ERR_MASK) |
347 | return stat; | 357 | return stat; |
348 | if (time_after(jiffies, timeout)) | 358 | if (time_after(jiffies, timeout)) { |
359 | mxcmci_softreset(host); | ||
360 | mxcmci_set_clk_rate(host, host->clock); | ||
349 | return STATUS_TIME_OUT_READ; | 361 | return STATUS_TIME_OUT_READ; |
362 | } | ||
350 | if (stat & mask) | 363 | if (stat & mask) |
351 | return 0; | 364 | return 0; |
352 | cpu_relax(); | 365 | cpu_relax(); |
@@ -531,6 +544,7 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
531 | { | 544 | { |
532 | struct mxcmci_host *host = mmc_priv(mmc); | 545 | struct mxcmci_host *host = mmc_priv(mmc); |
533 | unsigned int cmdat = host->cmdat; | 546 | unsigned int cmdat = host->cmdat; |
547 | int error; | ||
534 | 548 | ||
535 | WARN_ON(host->req != NULL); | 549 | WARN_ON(host->req != NULL); |
536 | 550 | ||
@@ -540,7 +554,12 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
540 | host->do_dma = 1; | 554 | host->do_dma = 1; |
541 | #endif | 555 | #endif |
542 | if (req->data) { | 556 | if (req->data) { |
543 | mxcmci_setup_data(host, req->data); | 557 | error = mxcmci_setup_data(host, req->data); |
558 | if (error) { | ||
559 | req->cmd->error = error; | ||
560 | goto out; | ||
561 | } | ||
562 | |||
544 | 563 | ||
545 | cmdat |= CMD_DAT_CONT_DATA_ENABLE; | 564 | cmdat |= CMD_DAT_CONT_DATA_ENABLE; |
546 | 565 | ||
@@ -548,7 +567,9 @@ static void mxcmci_request(struct mmc_host *mmc, struct mmc_request *req) | |||
548 | cmdat |= CMD_DAT_CONT_WRITE; | 567 | cmdat |= CMD_DAT_CONT_WRITE; |
549 | } | 568 | } |
550 | 569 | ||
551 | if (mxcmci_start_cmd(host, req->cmd, cmdat)) | 570 | error = mxcmci_start_cmd(host, req->cmd, cmdat); |
571 | out: | ||
572 | if (error) | ||
552 | mxcmci_finish_request(host, req); | 573 | mxcmci_finish_request(host, req); |
553 | } | 574 | } |
554 | 575 | ||
@@ -724,7 +745,9 @@ static int mxcmci_probe(struct platform_device *pdev) | |||
724 | goto out_clk_put; | 745 | goto out_clk_put; |
725 | } | 746 | } |
726 | 747 | ||
727 | mmc->f_min = clk_get_rate(host->clk) >> 7; | 748 | mmc->f_min = clk_get_rate(host->clk) >> 16; |
749 | if (mmc->f_min < 400000) | ||
750 | mmc->f_min = 400000; | ||
728 | mmc->f_max = clk_get_rate(host->clk) >> 1; | 751 | mmc->f_max = clk_get_rate(host->clk) >> 1; |
729 | 752 | ||
730 | /* recommended in data sheet */ | 753 | /* recommended in data sheet */ |