23 #include <linux/kernel.h>
43 #include <linux/module.h>
49 #define DRIVER_NAME "mxs-mmc"
51 #define MXS_MMC_IRQ_BITS (BM_SSP_CTRL1_SDIO_IRQ | \
52 BM_SSP_CTRL1_RESP_ERR_IRQ | \
53 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ | \
54 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ | \
55 BM_SSP_CTRL1_DATA_CRC_IRQ | \
56 BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ | \
57 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ | \
58 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ)
61 #define MXS_MMC_DETECT_TIMEOUT (HZ/2)
78 static int mxs_mmc_get_ro(
struct mmc_host *mmc)
83 if (!gpio_is_valid(host->
wp_gpio))
111 ctrl1 =
BF_SSP(0x3, CTRL1_SSP_MODE) |
112 BF_SSP(0x7, CTRL1_WORD_LENGTH) |
122 BF_SSP(2, TIMING_CLOCK_DIVIDE) |
123 BF_SSP(0, TIMING_CLOCK_RATE),
135 static void mxs_mmc_start_cmd(
struct mxs_mmc_host *host,
138 static void mxs_mmc_request_done(
struct mxs_mmc_host *host)
170 mxs_mmc_start_cmd(host, mrq->
stop);
179 static void mxs_mmc_dma_irq_callback(
void *
param)
183 mxs_mmc_request_done(host);
194 spin_lock(&host->
lock);
200 spin_unlock(&host->
lock);
203 mmc_signal_sdio_irq(host->
mmc);
245 desc = dmaengine_prep_slave_sg(ssp->
dmach,
248 desc->
callback = mxs_mmc_dma_irq_callback;
264 u32 ctrl0, cmd0, cmd1;
284 dmaengine_submit(desc);
285 dma_async_issue_pending(ssp->
dmach);
290 "%s: failed to prep dma\n", __func__);
298 u32 ignore_crc, get_resp, long_resp;
299 u32 ctrl0, cmd0, cmd1;
326 dmaengine_submit(desc);
327 dma_async_issue_pending(ssp->
dmach);
332 "%s: failed to prep dma\n", __func__);
335 static unsigned short mxs_ns_to_ssp_ticks(
unsigned clock_rate,
unsigned ns)
337 const unsigned int ssp_timeout_mul = 4096;
342 const unsigned int clock_per_ms = clock_rate / 1000;
343 const unsigned int ms = ns / 1000;
344 const unsigned int ticks = ms * clock_per_ms;
345 const unsigned int ssp_ticks = ticks / ssp_timeout_mul;
357 unsigned int sg_len = data->
sg_len;
360 unsigned short dma_data_dir,
timeout;
363 unsigned int blocks = data->
blocks;
367 u32 ignore_crc, get_resp, long_resp,
read;
368 u32 ctrl0, cmd0, cmd1,
val;
388 ignore_crc | get_resp | long_resp |
405 if (data_size != data->blocks * data->
blksz)
410 ctrl0 |=
BF_SSP(data_size, CTRL0_XFER_COUNT);
411 cmd0 |=
BF_SSP(log2_blksz, CMD0_BLOCK_SIZE) |
412 BF_SSP(blocks - 1, CMD0_BLOCK_COUNT);
416 BF_SSP(blocks - 1, BLOCK_SIZE_BLOCK_COUNT),
435 val |=
BF_SSP(timeout, TIMING_TIMEOUT);
444 desc = mxs_mmc_prep_dma(host, 0);
457 dmaengine_submit(desc);
458 dma_async_issue_pending(ssp->
dmach);
462 "%s: failed to prep dma\n", __func__);
465 static void mxs_mmc_start_cmd(
struct mxs_mmc_host *host,
485 "%s: unknown MMC command\n", __func__);
496 mxs_mmc_start_cmd(host, mrq->
cmd);
514 static void mxs_mmc_enable_sdio_irq(
struct mmc_host *mmc,
int enable)
527 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
532 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
536 spin_unlock_irqrestore(&host->
lock, flags);
540 mmc_signal_sdio_irq(host->
mmc);
545 .request = mxs_mmc_request,
546 .get_ro = mxs_mmc_get_ro,
547 .get_cd = mxs_mmc_get_cd,
548 .set_ios = mxs_mmc_set_ios,
549 .enable_sdio_irq = mxs_mmc_enable_sdio_irq,
582 { .compatible =
"fsl,imx23-mmc", .data = (
void *)
IMX23_SSP, },
583 { .compatible =
"fsl,imx28-mmc", .data = (
void *)
IMX28_SSP, },
598 int ret = 0, irq_err, irq_dma;
608 if (!iores || irq_err < 0 || irq_dma < 0)
615 host = mmc_priv(mmc);
630 ret = of_property_read_u32(np,
"fsl,ssp-dma-channel",
634 "failed to get dma channel\n");
646 if (!IS_ERR(reg_vmmc)) {
650 "Failed to enable vmmc regulator: %d\n", ret);
655 pinctrl = devm_pinctrl_get_select_default(&pdev->
dev);
656 if (IS_ERR(pinctrl)) {
657 ret = PTR_ERR(pinctrl);
662 if (IS_ERR(ssp->
clk)) {
663 ret = PTR_ERR(ssp->
clk);
666 clk_prepare_enable(ssp->
clk);
676 "%s: failed to request dma\n", __func__);
681 mmc->
ops = &mxs_mmc_ops;
688 of_property_read_u32(np,
"bus-width", &bus_width);
691 else if (bus_width == 8)
706 mmc->
f_max = 288000000;
715 platform_set_drvdata(pdev, mmc);
717 ret = devm_request_irq(&pdev->
dev, irq_err, mxs_mmc_irq_handler, 0,
736 clk_disable_unprepare(ssp->
clk);
745 struct mmc_host *mmc = platform_get_drvdata(pdev);
751 platform_set_drvdata(pdev,
NULL);
756 clk_disable_unprepare(ssp->
clk);
765 static int mxs_mmc_suspend(
struct device *
dev)
774 clk_disable_unprepare(ssp->
clk);
779 static int mxs_mmc_resume(
struct device *
dev)
786 clk_prepare_enable(ssp->
clk);
793 static const struct dev_pm_ops mxs_mmc_pm_ops = {
795 .resume = mxs_mmc_resume,
800 .probe = mxs_mmc_probe,
801 .remove = mxs_mmc_remove,
802 .id_table = mxs_ssp_ids,
807 .pm = &mxs_mmc_pm_ops,
809 .of_match_table = mxs_mmc_dt_ids,