2 * Portions copyright (C) 2003 Russell King, PXA MMCI Driver
3 * Portions copyright (C) 2004-2005 Pierre Ossman, W83L51xD SD/MMC driver
5 * Copyright 2008 Embedded Alley Solutions, Inc.
6 * Copyright 2009-2011 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/ioport.h>
27 #include <linux/of_device.h>
28 #include <linux/of_gpio.h>
29 #include <linux/platform_device.h>
30 #include <linux/delay.h>
31 #include <linux/interrupt.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/dmaengine.h>
34 #include <linux/highmem.h>
35 #include <linux/clk.h>
36 #include <linux/err.h>
37 #include <linux/completion.h>
38 #include <linux/mmc/host.h>
39 #include <linux/mmc/mmc.h>
40 #include <linux/mmc/sdio.h>
41 #include <linux/gpio.h>
42 #include <linux/regulator/consumer.h>
43 #include <linux/module.h>
44 #include <linux/pinctrl/consumer.h>
45 #include <linux/stmp_device.h>
46 #include <linux/spi/mxs-spi.h>
48 #define DRIVER_NAME "mxs-mmc"
50 #define MXS_MMC_IRQ_BITS (BM_SSP_CTRL1_SDIO_IRQ | \
51 BM_SSP_CTRL1_RESP_ERR_IRQ | \
52 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ | \
53 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ | \
54 BM_SSP_CTRL1_DATA_CRC_IRQ | \
55 BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ | \
56 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ | \
57 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ)
59 /* card detect polling timeout */
60 #define MXS_MMC_DETECT_TIMEOUT (HZ/2)
66 struct mmc_request *mrq;
67 struct mmc_command *cmd;
68 struct mmc_data *data;
70 unsigned char bus_width;
80 static int mxs_mmc_get_ro(struct mmc_host *mmc)
82 struct mxs_mmc_host *host = mmc_priv(mmc);
85 if (!gpio_is_valid(host->wp_gpio))
88 ret = gpio_get_value(host->wp_gpio);
90 if (host->wp_inverted)
96 static int mxs_mmc_get_cd(struct mmc_host *mmc)
98 struct mxs_mmc_host *host = mmc_priv(mmc);
99 struct mxs_ssp *ssp = &host->ssp;
101 return host->non_removable || host->broken_cd ||
102 !(readl(ssp->base + HW_SSP_STATUS(ssp)) &
103 BM_SSP_STATUS_CARD_DETECT) ^ host->cd_inverted;
106 static void mxs_mmc_reset(struct mxs_mmc_host *host)
108 struct mxs_ssp *ssp = &host->ssp;
111 stmp_reset_block(ssp->base);
113 ctrl0 = BM_SSP_CTRL0_IGNORE_CRC;
114 ctrl1 = BF_SSP(0x3, CTRL1_SSP_MODE) |
115 BF_SSP(0x7, CTRL1_WORD_LENGTH) |
116 BM_SSP_CTRL1_DMA_ENABLE |
117 BM_SSP_CTRL1_POLARITY |
118 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ_EN |
119 BM_SSP_CTRL1_DATA_CRC_IRQ_EN |
120 BM_SSP_CTRL1_DATA_TIMEOUT_IRQ_EN |
121 BM_SSP_CTRL1_RESP_TIMEOUT_IRQ_EN |
122 BM_SSP_CTRL1_RESP_ERR_IRQ_EN;
124 writel(BF_SSP(0xffff, TIMING_TIMEOUT) |
125 BF_SSP(2, TIMING_CLOCK_DIVIDE) |
126 BF_SSP(0, TIMING_CLOCK_RATE),
127 ssp->base + HW_SSP_TIMING(ssp));
129 if (host->sdio_irq_en) {
130 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
131 ctrl1 |= BM_SSP_CTRL1_SDIO_IRQ_EN;
134 writel(ctrl0, ssp->base + HW_SSP_CTRL0);
135 writel(ctrl1, ssp->base + HW_SSP_CTRL1(ssp));
138 static void mxs_mmc_start_cmd(struct mxs_mmc_host *host,
139 struct mmc_command *cmd);
141 static void mxs_mmc_request_done(struct mxs_mmc_host *host)
143 struct mmc_command *cmd = host->cmd;
144 struct mmc_data *data = host->data;
145 struct mmc_request *mrq = host->mrq;
146 struct mxs_ssp *ssp = &host->ssp;
148 if (mmc_resp_type(cmd) & MMC_RSP_PRESENT) {
149 if (mmc_resp_type(cmd) & MMC_RSP_136) {
150 cmd->resp[3] = readl(ssp->base + HW_SSP_SDRESP0(ssp));
151 cmd->resp[2] = readl(ssp->base + HW_SSP_SDRESP1(ssp));
152 cmd->resp[1] = readl(ssp->base + HW_SSP_SDRESP2(ssp));
153 cmd->resp[0] = readl(ssp->base + HW_SSP_SDRESP3(ssp));
155 cmd->resp[0] = readl(ssp->base + HW_SSP_SDRESP0(ssp));
160 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
161 data->sg_len, ssp->dma_dir);
163 * If there was an error on any block, we mark all
164 * data blocks as being in error.
167 data->bytes_xfered = data->blocks * data->blksz;
169 data->bytes_xfered = 0;
173 mxs_mmc_start_cmd(host, mrq->stop);
179 mmc_request_done(host->mmc, mrq);
182 static void mxs_mmc_dma_irq_callback(void *param)
184 struct mxs_mmc_host *host = param;
186 mxs_mmc_request_done(host);
189 static irqreturn_t mxs_mmc_irq_handler(int irq, void *dev_id)
191 struct mxs_mmc_host *host = dev_id;
192 struct mmc_command *cmd = host->cmd;
193 struct mmc_data *data = host->data;
194 struct mxs_ssp *ssp = &host->ssp;
197 spin_lock(&host->lock);
199 stat = readl(ssp->base + HW_SSP_CTRL1(ssp));
200 writel(stat & MXS_MMC_IRQ_BITS,
201 ssp->base + HW_SSP_CTRL1(ssp) + STMP_OFFSET_REG_CLR);
203 spin_unlock(&host->lock);
205 if ((stat & BM_SSP_CTRL1_SDIO_IRQ) && (stat & BM_SSP_CTRL1_SDIO_IRQ_EN))
206 mmc_signal_sdio_irq(host->mmc);
208 if (stat & BM_SSP_CTRL1_RESP_TIMEOUT_IRQ)
209 cmd->error = -ETIMEDOUT;
210 else if (stat & BM_SSP_CTRL1_RESP_ERR_IRQ)
214 if (stat & (BM_SSP_CTRL1_DATA_TIMEOUT_IRQ |
215 BM_SSP_CTRL1_RECV_TIMEOUT_IRQ))
216 data->error = -ETIMEDOUT;
217 else if (stat & BM_SSP_CTRL1_DATA_CRC_IRQ)
218 data->error = -EILSEQ;
219 else if (stat & (BM_SSP_CTRL1_FIFO_UNDERRUN_IRQ |
220 BM_SSP_CTRL1_FIFO_OVERRUN_IRQ))
227 static struct dma_async_tx_descriptor *mxs_mmc_prep_dma(
228 struct mxs_mmc_host *host, unsigned long flags)
230 struct mxs_ssp *ssp = &host->ssp;
231 struct dma_async_tx_descriptor *desc;
232 struct mmc_data *data = host->data;
233 struct scatterlist * sgl;
238 dma_map_sg(mmc_dev(host->mmc), data->sg,
239 data->sg_len, ssp->dma_dir);
241 sg_len = data->sg_len;
244 sgl = (struct scatterlist *) ssp->ssp_pio_words;
245 sg_len = SSP_PIO_NUM;
248 desc = dmaengine_prep_slave_sg(ssp->dmach,
249 sgl, sg_len, ssp->slave_dirn, flags);
251 desc->callback = mxs_mmc_dma_irq_callback;
252 desc->callback_param = host;
255 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
256 data->sg_len, ssp->dma_dir);
262 static void mxs_mmc_bc(struct mxs_mmc_host *host)
264 struct mxs_ssp *ssp = &host->ssp;
265 struct mmc_command *cmd = host->cmd;
266 struct dma_async_tx_descriptor *desc;
267 u32 ctrl0, cmd0, cmd1;
269 ctrl0 = BM_SSP_CTRL0_ENABLE | BM_SSP_CTRL0_IGNORE_CRC;
270 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD) | BM_SSP_CMD0_APPEND_8CYC;
273 if (host->sdio_irq_en) {
274 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
275 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
278 ssp->ssp_pio_words[0] = ctrl0;
279 ssp->ssp_pio_words[1] = cmd0;
280 ssp->ssp_pio_words[2] = cmd1;
281 ssp->dma_dir = DMA_NONE;
282 ssp->slave_dirn = DMA_TRANS_NONE;
283 desc = mxs_mmc_prep_dma(host, DMA_CTRL_ACK);
287 dmaengine_submit(desc);
288 dma_async_issue_pending(ssp->dmach);
292 dev_warn(mmc_dev(host->mmc),
293 "%s: failed to prep dma\n", __func__);
296 static void mxs_mmc_ac(struct mxs_mmc_host *host)
298 struct mxs_ssp *ssp = &host->ssp;
299 struct mmc_command *cmd = host->cmd;
300 struct dma_async_tx_descriptor *desc;
301 u32 ignore_crc, get_resp, long_resp;
302 u32 ctrl0, cmd0, cmd1;
304 ignore_crc = (mmc_resp_type(cmd) & MMC_RSP_CRC) ?
305 0 : BM_SSP_CTRL0_IGNORE_CRC;
306 get_resp = (mmc_resp_type(cmd) & MMC_RSP_PRESENT) ?
307 BM_SSP_CTRL0_GET_RESP : 0;
308 long_resp = (mmc_resp_type(cmd) & MMC_RSP_136) ?
309 BM_SSP_CTRL0_LONG_RESP : 0;
311 ctrl0 = BM_SSP_CTRL0_ENABLE | ignore_crc | get_resp | long_resp;
312 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD);
315 if (host->sdio_irq_en) {
316 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
317 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
320 ssp->ssp_pio_words[0] = ctrl0;
321 ssp->ssp_pio_words[1] = cmd0;
322 ssp->ssp_pio_words[2] = cmd1;
323 ssp->dma_dir = DMA_NONE;
324 ssp->slave_dirn = DMA_TRANS_NONE;
325 desc = mxs_mmc_prep_dma(host, DMA_CTRL_ACK);
329 dmaengine_submit(desc);
330 dma_async_issue_pending(ssp->dmach);
334 dev_warn(mmc_dev(host->mmc),
335 "%s: failed to prep dma\n", __func__);
338 static unsigned short mxs_ns_to_ssp_ticks(unsigned clock_rate, unsigned ns)
340 const unsigned int ssp_timeout_mul = 4096;
342 * Calculate ticks in ms since ns are large numbers
345 const unsigned int clock_per_ms = clock_rate / 1000;
346 const unsigned int ms = ns / 1000;
347 const unsigned int ticks = ms * clock_per_ms;
348 const unsigned int ssp_ticks = ticks / ssp_timeout_mul;
350 WARN_ON(ssp_ticks == 0);
354 static void mxs_mmc_adtc(struct mxs_mmc_host *host)
356 struct mmc_command *cmd = host->cmd;
357 struct mmc_data *data = cmd->data;
358 struct dma_async_tx_descriptor *desc;
359 struct scatterlist *sgl = data->sg, *sg;
360 unsigned int sg_len = data->sg_len;
363 unsigned short dma_data_dir, timeout;
364 enum dma_transfer_direction slave_dirn;
365 unsigned int data_size = 0, log2_blksz;
366 unsigned int blocks = data->blocks;
368 struct mxs_ssp *ssp = &host->ssp;
370 u32 ignore_crc, get_resp, long_resp, read;
371 u32 ctrl0, cmd0, cmd1, val;
373 ignore_crc = (mmc_resp_type(cmd) & MMC_RSP_CRC) ?
374 0 : BM_SSP_CTRL0_IGNORE_CRC;
375 get_resp = (mmc_resp_type(cmd) & MMC_RSP_PRESENT) ?
376 BM_SSP_CTRL0_GET_RESP : 0;
377 long_resp = (mmc_resp_type(cmd) & MMC_RSP_136) ?
378 BM_SSP_CTRL0_LONG_RESP : 0;
380 if (data->flags & MMC_DATA_WRITE) {
381 dma_data_dir = DMA_TO_DEVICE;
382 slave_dirn = DMA_MEM_TO_DEV;
385 dma_data_dir = DMA_FROM_DEVICE;
386 slave_dirn = DMA_DEV_TO_MEM;
387 read = BM_SSP_CTRL0_READ;
390 ctrl0 = BF_SSP(host->bus_width, CTRL0_BUS_WIDTH) |
391 ignore_crc | get_resp | long_resp |
392 BM_SSP_CTRL0_DATA_XFER | read |
393 BM_SSP_CTRL0_WAIT_FOR_IRQ |
396 cmd0 = BF_SSP(cmd->opcode, CMD0_CMD);
398 /* get logarithm to base 2 of block size for setting register */
399 log2_blksz = ilog2(data->blksz);
402 * take special care of the case that data size from data->sg
403 * is not equal to blocks x blksz
405 for_each_sg(sgl, sg, sg_len, i)
406 data_size += sg->length;
408 if (data_size != data->blocks * data->blksz)
411 /* xfer count, block size and count need to be set differently */
412 if (ssp_is_old(ssp)) {
413 ctrl0 |= BF_SSP(data_size, CTRL0_XFER_COUNT);
414 cmd0 |= BF_SSP(log2_blksz, CMD0_BLOCK_SIZE) |
415 BF_SSP(blocks - 1, CMD0_BLOCK_COUNT);
417 writel(data_size, ssp->base + HW_SSP_XFER_SIZE);
418 writel(BF_SSP(log2_blksz, BLOCK_SIZE_BLOCK_SIZE) |
419 BF_SSP(blocks - 1, BLOCK_SIZE_BLOCK_COUNT),
420 ssp->base + HW_SSP_BLOCK_SIZE);
423 if ((cmd->opcode == MMC_STOP_TRANSMISSION) ||
424 (cmd->opcode == SD_IO_RW_EXTENDED))
425 cmd0 |= BM_SSP_CMD0_APPEND_8CYC;
429 if (host->sdio_irq_en) {
430 ctrl0 |= BM_SSP_CTRL0_SDIO_IRQ_CHECK;
431 cmd0 |= BM_SSP_CMD0_CONT_CLKING_EN | BM_SSP_CMD0_SLOW_CLKING_EN;
434 /* set the timeout count */
435 timeout = mxs_ns_to_ssp_ticks(ssp->clk_rate, data->timeout_ns);
436 val = readl(ssp->base + HW_SSP_TIMING(ssp));
437 val &= ~(BM_SSP_TIMING_TIMEOUT);
438 val |= BF_SSP(timeout, TIMING_TIMEOUT);
439 writel(val, ssp->base + HW_SSP_TIMING(ssp));
442 ssp->ssp_pio_words[0] = ctrl0;
443 ssp->ssp_pio_words[1] = cmd0;
444 ssp->ssp_pio_words[2] = cmd1;
445 ssp->dma_dir = DMA_NONE;
446 ssp->slave_dirn = DMA_TRANS_NONE;
447 desc = mxs_mmc_prep_dma(host, 0);
452 WARN_ON(host->data != NULL);
454 ssp->dma_dir = dma_data_dir;
455 ssp->slave_dirn = slave_dirn;
456 desc = mxs_mmc_prep_dma(host, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
460 dmaengine_submit(desc);
461 dma_async_issue_pending(ssp->dmach);
464 dev_warn(mmc_dev(host->mmc),
465 "%s: failed to prep dma\n", __func__);
468 static void mxs_mmc_start_cmd(struct mxs_mmc_host *host,
469 struct mmc_command *cmd)
473 switch (mmc_cmd_type(cmd)) {
487 dev_warn(mmc_dev(host->mmc),
488 "%s: unknown MMC command\n", __func__);
493 static void mxs_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
495 struct mxs_mmc_host *host = mmc_priv(mmc);
497 WARN_ON(host->mrq != NULL);
499 mxs_mmc_start_cmd(host, mrq->cmd);
502 static void mxs_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
504 struct mxs_mmc_host *host = mmc_priv(mmc);
506 if (ios->bus_width == MMC_BUS_WIDTH_8)
508 else if (ios->bus_width == MMC_BUS_WIDTH_4)
514 mxs_ssp_set_clk_rate(&host->ssp, ios->clock);
517 static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
519 struct mxs_mmc_host *host = mmc_priv(mmc);
520 struct mxs_ssp *ssp = &host->ssp;
523 spin_lock_irqsave(&host->lock, flags);
525 host->sdio_irq_en = enable;
528 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK,
529 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
530 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
531 ssp->base + HW_SSP_CTRL1(ssp) + STMP_OFFSET_REG_SET);
533 writel(BM_SSP_CTRL0_SDIO_IRQ_CHECK,
534 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
535 writel(BM_SSP_CTRL1_SDIO_IRQ_EN,
536 ssp->base + HW_SSP_CTRL1(ssp) + STMP_OFFSET_REG_CLR);
539 spin_unlock_irqrestore(&host->lock, flags);
541 if (enable && readl(ssp->base + HW_SSP_STATUS(ssp)) &
542 BM_SSP_STATUS_SDIO_IRQ)
543 mmc_signal_sdio_irq(host->mmc);
547 static const struct mmc_host_ops mxs_mmc_ops = {
548 .request = mxs_mmc_request,
549 .get_ro = mxs_mmc_get_ro,
550 .get_cd = mxs_mmc_get_cd,
551 .set_ios = mxs_mmc_set_ios,
552 .enable_sdio_irq = mxs_mmc_enable_sdio_irq,
555 static bool mxs_mmc_dma_filter(struct dma_chan *chan, void *param)
557 struct mxs_mmc_host *host = param;
558 struct mxs_ssp *ssp = &host->ssp;
560 if (!mxs_dma_is_apbh(chan))
563 if (chan->chan_id != ssp->dma_channel)
566 chan->private = &ssp->dma_data;
571 static struct platform_device_id mxs_ssp_ids[] = {
574 .driver_data = IMX23_SSP,
577 .driver_data = IMX28_SSP,
582 MODULE_DEVICE_TABLE(platform, mxs_ssp_ids);
584 static const struct of_device_id mxs_mmc_dt_ids[] = {
585 { .compatible = "fsl,imx23-mmc", .data = (void *) IMX23_SSP, },
586 { .compatible = "fsl,imx28-mmc", .data = (void *) IMX28_SSP, },
589 MODULE_DEVICE_TABLE(of, mxs_mmc_dt_ids);
591 static int mxs_mmc_probe(struct platform_device *pdev)
593 const struct of_device_id *of_id =
594 of_match_device(mxs_mmc_dt_ids, &pdev->dev);
595 struct device_node *np = pdev->dev.of_node;
596 struct mxs_mmc_host *host;
597 struct mmc_host *mmc;
598 struct resource *iores, *dmares;
599 struct pinctrl *pinctrl;
600 int ret = 0, irq_err, irq_dma;
602 struct regulator *reg_vmmc;
603 enum of_gpio_flags flags;
607 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
608 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
609 irq_err = platform_get_irq(pdev, 0);
610 irq_dma = platform_get_irq(pdev, 1);
611 if (!iores || irq_err < 0 || irq_dma < 0)
614 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev);
618 host = mmc_priv(mmc);
620 ssp->dev = &pdev->dev;
621 ssp->base = devm_ioremap_resource(&pdev->dev, iores);
622 if (IS_ERR(ssp->base)) {
623 ret = PTR_ERR(ssp->base);
628 ssp->devid = (enum mxs_ssp_id) of_id->data;
630 * TODO: This is a temporary solution and should be changed
631 * to use generic DMA binding later when the helpers get in.
633 ret = of_property_read_u32(np, "fsl,ssp-dma-channel",
636 dev_err(mmc_dev(host->mmc),
637 "failed to get dma channel\n");
641 ssp->devid = pdev->id_entry->driver_data;
642 ssp->dma_channel = dmares->start;
646 host->sdio_irq_en = 0;
648 reg_vmmc = devm_regulator_get(&pdev->dev, "vmmc");
649 if (!IS_ERR(reg_vmmc)) {
650 ret = regulator_enable(reg_vmmc);
653 "Failed to enable vmmc regulator: %d\n", ret);
658 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
659 if (IS_ERR(pinctrl)) {
660 ret = PTR_ERR(pinctrl);
664 ssp->clk = clk_get(&pdev->dev, NULL);
665 if (IS_ERR(ssp->clk)) {
666 ret = PTR_ERR(ssp->clk);
669 clk_prepare_enable(ssp->clk);
674 dma_cap_set(DMA_SLAVE, mask);
675 ssp->dma_data.chan_irq = irq_dma;
676 ssp->dmach = dma_request_channel(mask, mxs_mmc_dma_filter, host);
678 dev_err(mmc_dev(host->mmc),
679 "%s: failed to request dma\n", __func__);
683 /* set mmc core parameters */
684 mmc->ops = &mxs_mmc_ops;
685 mmc->caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED |
686 MMC_CAP_SDIO_IRQ | MMC_CAP_NEEDS_POLL;
688 of_property_read_u32(np, "bus-width", &bus_width);
690 mmc->caps |= MMC_CAP_4_BIT_DATA;
691 else if (bus_width == 8)
692 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
693 host->broken_cd = of_property_read_bool(np, "broken-cd");
694 host->non_removable = of_property_read_bool(np, "non-removable");
695 if (host->non_removable)
696 mmc->caps |= MMC_CAP_NONREMOVABLE;
697 host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags);
698 if (flags & OF_GPIO_ACTIVE_LOW)
699 host->wp_inverted = 1;
701 host->cd_inverted = of_property_read_bool(np, "cd-inverted");
704 mmc->f_max = 288000000;
705 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
708 mmc->max_blk_size = 1 << 0xf;
709 mmc->max_blk_count = (ssp_is_old(ssp)) ? 0xff : 0xffffff;
710 mmc->max_req_size = (ssp_is_old(ssp)) ? 0xffff : 0xffffffff;
711 mmc->max_seg_size = dma_get_max_seg_size(ssp->dmach->device->dev);
713 platform_set_drvdata(pdev, mmc);
715 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0,
720 spin_lock_init(&host->lock);
722 ret = mmc_add_host(mmc);
726 dev_info(mmc_dev(host->mmc), "initialized\n");
732 dma_release_channel(ssp->dmach);
734 clk_disable_unprepare(ssp->clk);
741 static int mxs_mmc_remove(struct platform_device *pdev)
743 struct mmc_host *mmc = platform_get_drvdata(pdev);
744 struct mxs_mmc_host *host = mmc_priv(mmc);
745 struct mxs_ssp *ssp = &host->ssp;
747 mmc_remove_host(mmc);
749 platform_set_drvdata(pdev, NULL);
752 dma_release_channel(ssp->dmach);
754 clk_disable_unprepare(ssp->clk);
763 static int mxs_mmc_suspend(struct device *dev)
765 struct mmc_host *mmc = dev_get_drvdata(dev);
766 struct mxs_mmc_host *host = mmc_priv(mmc);
767 struct mxs_ssp *ssp = &host->ssp;
770 ret = mmc_suspend_host(mmc);
772 clk_disable_unprepare(ssp->clk);
777 static int mxs_mmc_resume(struct device *dev)
779 struct mmc_host *mmc = dev_get_drvdata(dev);
780 struct mxs_mmc_host *host = mmc_priv(mmc);
781 struct mxs_ssp *ssp = &host->ssp;
784 clk_prepare_enable(ssp->clk);
786 ret = mmc_resume_host(mmc);
791 static const struct dev_pm_ops mxs_mmc_pm_ops = {
792 .suspend = mxs_mmc_suspend,
793 .resume = mxs_mmc_resume,
797 static struct platform_driver mxs_mmc_driver = {
798 .probe = mxs_mmc_probe,
799 .remove = mxs_mmc_remove,
800 .id_table = mxs_ssp_ids,
803 .owner = THIS_MODULE,
805 .pm = &mxs_mmc_pm_ops,
807 .of_match_table = mxs_mmc_dt_ids,
811 module_platform_driver(mxs_mmc_driver);
813 MODULE_DESCRIPTION("FREESCALE MXS MMC peripheral");
814 MODULE_AUTHOR("Freescale Semiconductor");
815 MODULE_LICENSE("GPL");
816 MODULE_ALIAS("platform:" DRIVER_NAME);