2 * Synopsys DesignWare Multimedia Card Interface driver
3 * (Based on NXP driver for lpc 31xx)
5 * Copyright (C) 2009 NXP Semiconductors
6 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
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.
14 #include <linux/blkdev.h>
15 #include <linux/clk.h>
16 #include <linux/debugfs.h>
17 #include <linux/device.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/err.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/ioport.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/seq_file.h>
26 #include <linux/slab.h>
27 #include <linux/stat.h>
28 #include <linux/delay.h>
29 #include <linux/irq.h>
30 #include <linux/mmc/host.h>
31 #include <linux/mmc/mmc.h>
32 #include <linux/mmc/dw_mmc.h>
33 #include <linux/bitops.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/workqueue.h>
37 #include <linux/of_gpio.h>
41 /* Common flag combinations */
42 #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \
43 SDMMC_INT_HTO | SDMMC_INT_SBE | \
45 #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
47 #define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \
48 DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE)
49 #define DW_MCI_SEND_STATUS 1
50 #define DW_MCI_RECV_STATUS 2
51 #define DW_MCI_DMA_THRESHOLD 16
53 #ifdef CONFIG_MMC_DW_IDMAC
54 #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
55 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
56 SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
60 u32 des0; /* Control Descriptor */
61 #define IDMAC_DES0_DIC BIT(1)
62 #define IDMAC_DES0_LD BIT(2)
63 #define IDMAC_DES0_FD BIT(3)
64 #define IDMAC_DES0_CH BIT(4)
65 #define IDMAC_DES0_ER BIT(5)
66 #define IDMAC_DES0_CES BIT(30)
67 #define IDMAC_DES0_OWN BIT(31)
69 u32 des1; /* Buffer sizes */
70 #define IDMAC_SET_BUFFER1_SIZE(d, s) \
71 ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff))
73 u32 des2; /* buffer 1 physical address */
75 u32 des3; /* buffer 2 physical address */
77 #endif /* CONFIG_MMC_DW_IDMAC */
80 * struct dw_mci_slot - MMC slot state
81 * @mmc: The mmc_host representing this slot.
82 * @host: The MMC controller this slot is using.
83 * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
84 * @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
85 * @ctype: Card type for this slot.
86 * @mrq: mmc_request currently being processed or waiting to be
87 * processed, or NULL when the slot is idle.
88 * @queue_node: List node for placing this node in the @queue list of
90 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
91 * @__clk_old: The last updated clock with reflecting clock divider.
92 * Keeping track of this helps us to avoid spamming the console
93 * with CONFIG_MMC_CLKGATE.
94 * @flags: Random state bits associated with the slot.
95 * @id: Number of this slot.
96 * @last_detect_state: Most recently observed card detect state.
107 struct mmc_request *mrq;
108 struct list_head queue_node;
111 unsigned int __clk_old;
113 #define DW_MMC_CARD_PRESENT 0
114 #define DW_MMC_CARD_NEED_INIT 1
116 int last_detect_state;
119 #if defined(CONFIG_DEBUG_FS)
120 static int dw_mci_req_show(struct seq_file *s, void *v)
122 struct dw_mci_slot *slot = s->private;
123 struct mmc_request *mrq;
124 struct mmc_command *cmd;
125 struct mmc_command *stop;
126 struct mmc_data *data;
128 /* Make sure we get a consistent snapshot */
129 spin_lock_bh(&slot->host->lock);
139 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
140 cmd->opcode, cmd->arg, cmd->flags,
141 cmd->resp[0], cmd->resp[1], cmd->resp[2],
142 cmd->resp[2], cmd->error);
144 seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
145 data->bytes_xfered, data->blocks,
146 data->blksz, data->flags, data->error);
149 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
150 stop->opcode, stop->arg, stop->flags,
151 stop->resp[0], stop->resp[1], stop->resp[2],
152 stop->resp[2], stop->error);
155 spin_unlock_bh(&slot->host->lock);
160 static int dw_mci_req_open(struct inode *inode, struct file *file)
162 return single_open(file, dw_mci_req_show, inode->i_private);
165 static const struct file_operations dw_mci_req_fops = {
166 .owner = THIS_MODULE,
167 .open = dw_mci_req_open,
170 .release = single_release,
173 static int dw_mci_regs_show(struct seq_file *s, void *v)
175 seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS);
176 seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS);
177 seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD);
178 seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL);
179 seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK);
180 seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA);
185 static int dw_mci_regs_open(struct inode *inode, struct file *file)
187 return single_open(file, dw_mci_regs_show, inode->i_private);
190 static const struct file_operations dw_mci_regs_fops = {
191 .owner = THIS_MODULE,
192 .open = dw_mci_regs_open,
195 .release = single_release,
198 static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
200 struct mmc_host *mmc = slot->mmc;
201 struct dw_mci *host = slot->host;
205 root = mmc->debugfs_root;
209 node = debugfs_create_file("regs", S_IRUSR, root, host,
214 node = debugfs_create_file("req", S_IRUSR, root, slot,
219 node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
223 node = debugfs_create_x32("pending_events", S_IRUSR, root,
224 (u32 *)&host->pending_events);
228 node = debugfs_create_x32("completed_events", S_IRUSR, root,
229 (u32 *)&host->completed_events);
236 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
238 #endif /* defined(CONFIG_DEBUG_FS) */
240 static void dw_mci_set_timeout(struct dw_mci *host)
242 /* timeout (maximum) */
243 mci_writel(host, TMOUT, 0xffffffff);
246 static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
248 struct mmc_data *data;
249 struct dw_mci_slot *slot = mmc_priv(mmc);
250 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
252 cmd->error = -EINPROGRESS;
256 if (cmdr == MMC_STOP_TRANSMISSION)
257 cmdr |= SDMMC_CMD_STOP;
259 cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
261 if (cmd->flags & MMC_RSP_PRESENT) {
262 /* We expect a response, so set this bit */
263 cmdr |= SDMMC_CMD_RESP_EXP;
264 if (cmd->flags & MMC_RSP_136)
265 cmdr |= SDMMC_CMD_RESP_LONG;
268 if (cmd->flags & MMC_RSP_CRC)
269 cmdr |= SDMMC_CMD_RESP_CRC;
273 cmdr |= SDMMC_CMD_DAT_EXP;
274 if (data->flags & MMC_DATA_STREAM)
275 cmdr |= SDMMC_CMD_STRM_MODE;
276 if (data->flags & MMC_DATA_WRITE)
277 cmdr |= SDMMC_CMD_DAT_WR;
280 if (drv_data && drv_data->prepare_command)
281 drv_data->prepare_command(slot->host, &cmdr);
286 static void dw_mci_start_command(struct dw_mci *host,
287 struct mmc_command *cmd, u32 cmd_flags)
291 "start command: ARGR=0x%08x CMDR=0x%08x\n",
292 cmd->arg, cmd_flags);
294 mci_writel(host, CMDARG, cmd->arg);
297 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
300 static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
302 dw_mci_start_command(host, data->stop, host->stop_cmdr);
305 /* DMA interface functions */
306 static void dw_mci_stop_dma(struct dw_mci *host)
308 if (host->using_dma) {
309 host->dma_ops->stop(host);
310 host->dma_ops->cleanup(host);
312 /* Data transfer was stopped by the interrupt handler */
313 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
317 static int dw_mci_get_dma_dir(struct mmc_data *data)
319 if (data->flags & MMC_DATA_WRITE)
320 return DMA_TO_DEVICE;
322 return DMA_FROM_DEVICE;
325 #ifdef CONFIG_MMC_DW_IDMAC
326 static void dw_mci_dma_cleanup(struct dw_mci *host)
328 struct mmc_data *data = host->data;
331 if (!data->host_cookie)
332 dma_unmap_sg(host->dev,
335 dw_mci_get_dma_dir(data));
338 static void dw_mci_idmac_stop_dma(struct dw_mci *host)
342 /* Disable and reset the IDMAC interface */
343 temp = mci_readl(host, CTRL);
344 temp &= ~SDMMC_CTRL_USE_IDMAC;
345 temp |= SDMMC_CTRL_DMA_RESET;
346 mci_writel(host, CTRL, temp);
348 /* Stop the IDMAC running */
349 temp = mci_readl(host, BMOD);
350 temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
351 mci_writel(host, BMOD, temp);
354 static void dw_mci_idmac_complete_dma(struct dw_mci *host)
356 struct mmc_data *data = host->data;
358 dev_vdbg(host->dev, "DMA complete\n");
360 host->dma_ops->cleanup(host);
363 * If the card was removed, data will be NULL. No point in trying to
364 * send the stop command or waiting for NBUSY in this case.
367 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
368 tasklet_schedule(&host->tasklet);
372 static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
376 struct idmac_desc *desc = host->sg_cpu;
378 for (i = 0; i < sg_len; i++, desc++) {
379 unsigned int length = sg_dma_len(&data->sg[i]);
380 u32 mem_addr = sg_dma_address(&data->sg[i]);
382 /* Set the OWN bit and disable interrupts for this descriptor */
383 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH;
386 IDMAC_SET_BUFFER1_SIZE(desc, length);
388 /* Physical address to DMA to/from */
389 desc->des2 = mem_addr;
392 /* Set first descriptor */
394 desc->des0 |= IDMAC_DES0_FD;
396 /* Set last descriptor */
397 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
398 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
399 desc->des0 |= IDMAC_DES0_LD;
404 static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
408 dw_mci_translate_sglist(host, host->data, sg_len);
410 /* Select IDMAC interface */
411 temp = mci_readl(host, CTRL);
412 temp |= SDMMC_CTRL_USE_IDMAC;
413 mci_writel(host, CTRL, temp);
417 /* Enable the IDMAC */
418 temp = mci_readl(host, BMOD);
419 temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
420 mci_writel(host, BMOD, temp);
422 /* Start it running */
423 mci_writel(host, PLDMND, 1);
426 static int dw_mci_idmac_init(struct dw_mci *host)
428 struct idmac_desc *p;
431 /* Number of descriptors in the ring buffer */
432 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
434 /* Forward link the descriptor list */
435 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
436 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
438 /* Set the last descriptor as the end-of-ring descriptor */
439 p->des3 = host->sg_dma;
440 p->des0 = IDMAC_DES0_ER;
442 mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET);
444 /* Mask out interrupts - get Tx & Rx complete only */
445 mci_writel(host, IDSTS, IDMAC_INT_CLR);
446 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI |
449 /* Set the descriptor base address */
450 mci_writel(host, DBADDR, host->sg_dma);
454 static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
455 .init = dw_mci_idmac_init,
456 .start = dw_mci_idmac_start_dma,
457 .stop = dw_mci_idmac_stop_dma,
458 .complete = dw_mci_idmac_complete_dma,
459 .cleanup = dw_mci_dma_cleanup,
461 #endif /* CONFIG_MMC_DW_IDMAC */
463 static int dw_mci_pre_dma_transfer(struct dw_mci *host,
464 struct mmc_data *data,
467 struct scatterlist *sg;
468 unsigned int i, sg_len;
470 if (!next && data->host_cookie)
471 return data->host_cookie;
474 * We don't do DMA on "complex" transfers, i.e. with
475 * non-word-aligned buffers or lengths. Also, we don't bother
476 * with all the DMA setup overhead for short transfers.
478 if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
484 for_each_sg(data->sg, sg, data->sg_len, i) {
485 if (sg->offset & 3 || sg->length & 3)
489 sg_len = dma_map_sg(host->dev,
492 dw_mci_get_dma_dir(data));
497 data->host_cookie = sg_len;
502 static void dw_mci_pre_req(struct mmc_host *mmc,
503 struct mmc_request *mrq,
506 struct dw_mci_slot *slot = mmc_priv(mmc);
507 struct mmc_data *data = mrq->data;
509 if (!slot->host->use_dma || !data)
512 if (data->host_cookie) {
513 data->host_cookie = 0;
517 if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0)
518 data->host_cookie = 0;
521 static void dw_mci_post_req(struct mmc_host *mmc,
522 struct mmc_request *mrq,
525 struct dw_mci_slot *slot = mmc_priv(mmc);
526 struct mmc_data *data = mrq->data;
528 if (!slot->host->use_dma || !data)
531 if (data->host_cookie)
532 dma_unmap_sg(slot->host->dev,
535 dw_mci_get_dma_dir(data));
536 data->host_cookie = 0;
539 static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
546 /* If we don't have a channel, we can't do DMA */
550 sg_len = dw_mci_pre_dma_transfer(host, data, 0);
552 host->dma_ops->stop(host);
559 "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
560 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
563 /* Enable the DMA interface */
564 temp = mci_readl(host, CTRL);
565 temp |= SDMMC_CTRL_DMA_ENABLE;
566 mci_writel(host, CTRL, temp);
568 /* Disable RX/TX IRQs, let DMA handle it */
569 temp = mci_readl(host, INTMASK);
570 temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
571 mci_writel(host, INTMASK, temp);
573 host->dma_ops->start(host, sg_len);
578 static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
582 data->error = -EINPROGRESS;
588 if (data->flags & MMC_DATA_READ)
589 host->dir_status = DW_MCI_RECV_STATUS;
591 host->dir_status = DW_MCI_SEND_STATUS;
593 if (dw_mci_submit_data_dma(host, data)) {
594 int flags = SG_MITER_ATOMIC;
595 if (host->data->flags & MMC_DATA_READ)
596 flags |= SG_MITER_TO_SG;
598 flags |= SG_MITER_FROM_SG;
600 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
602 host->part_buf_start = 0;
603 host->part_buf_count = 0;
605 mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
606 temp = mci_readl(host, INTMASK);
607 temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
608 mci_writel(host, INTMASK, temp);
610 temp = mci_readl(host, CTRL);
611 temp &= ~SDMMC_CTRL_DMA_ENABLE;
612 mci_writel(host, CTRL, temp);
616 static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
618 struct dw_mci *host = slot->host;
619 unsigned long timeout = jiffies + msecs_to_jiffies(500);
620 unsigned int cmd_status = 0;
622 mci_writel(host, CMDARG, arg);
624 mci_writel(host, CMD, SDMMC_CMD_START | cmd);
626 while (time_before(jiffies, timeout)) {
627 cmd_status = mci_readl(host, CMD);
628 if (!(cmd_status & SDMMC_CMD_START))
631 dev_err(&slot->mmc->class_dev,
632 "Timeout sending command (cmd %#x arg %#x status %#x)\n",
633 cmd, arg, cmd_status);
636 static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
638 struct dw_mci *host = slot->host;
639 unsigned int clock = slot->clock;
644 mci_writel(host, CLKENA, 0);
646 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
647 } else if (clock != host->current_speed || force_clkinit) {
648 div = host->bus_hz / clock;
649 if (host->bus_hz % clock && host->bus_hz > clock)
651 * move the + 1 after the divide to prevent
652 * over-clocking the card.
656 div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
658 if ((clock << div) != slot->__clk_old || force_clkinit)
659 dev_info(&slot->mmc->class_dev,
660 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
661 slot->id, host->bus_hz, clock,
662 div ? ((host->bus_hz / div) >> 1) :
666 mci_writel(host, CLKENA, 0);
667 mci_writel(host, CLKSRC, 0);
671 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
673 /* set clock to desired speed */
674 mci_writel(host, CLKDIV, div);
678 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
680 /* enable clock; only low power if no SDIO */
681 clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
682 if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->id)))
683 clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
684 mci_writel(host, CLKENA, clk_en_a);
688 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
690 /* keep the clock with reflecting clock dividor */
691 slot->__clk_old = clock << div;
694 host->current_speed = clock;
696 /* Set the current slot bus width */
697 mci_writel(host, CTYPE, (slot->ctype << slot->id));
700 static void __dw_mci_start_request(struct dw_mci *host,
701 struct dw_mci_slot *slot,
702 struct mmc_command *cmd)
704 struct mmc_request *mrq;
705 struct mmc_data *data;
709 if (host->pdata->select_slot)
710 host->pdata->select_slot(slot->id);
712 host->cur_slot = slot;
715 host->pending_events = 0;
716 host->completed_events = 0;
717 host->data_status = 0;
721 dw_mci_set_timeout(host);
722 mci_writel(host, BYTCNT, data->blksz*data->blocks);
723 mci_writel(host, BLKSIZ, data->blksz);
726 cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
728 /* this is the first command, send the initialization clock */
729 if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
730 cmdflags |= SDMMC_CMD_INIT;
733 dw_mci_submit_data(host, data);
737 dw_mci_start_command(host, cmd, cmdflags);
740 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
743 static void dw_mci_start_request(struct dw_mci *host,
744 struct dw_mci_slot *slot)
746 struct mmc_request *mrq = slot->mrq;
747 struct mmc_command *cmd;
749 cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
750 __dw_mci_start_request(host, slot, cmd);
753 /* must be called with host->lock held */
754 static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
755 struct mmc_request *mrq)
757 dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
762 if (host->state == STATE_IDLE) {
763 host->state = STATE_SENDING_CMD;
764 dw_mci_start_request(host, slot);
766 list_add_tail(&slot->queue_node, &host->queue);
770 static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
772 struct dw_mci_slot *slot = mmc_priv(mmc);
773 struct dw_mci *host = slot->host;
778 * The check for card presence and queueing of the request must be
779 * atomic, otherwise the card could be removed in between and the
780 * request wouldn't fail until another card was inserted.
782 spin_lock_bh(&host->lock);
784 if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
785 spin_unlock_bh(&host->lock);
786 mrq->cmd->error = -ENOMEDIUM;
787 mmc_request_done(mmc, mrq);
791 dw_mci_queue_request(host, slot, mrq);
793 spin_unlock_bh(&host->lock);
796 static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
798 struct dw_mci_slot *slot = mmc_priv(mmc);
799 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
802 switch (ios->bus_width) {
803 case MMC_BUS_WIDTH_4:
804 slot->ctype = SDMMC_CTYPE_4BIT;
806 case MMC_BUS_WIDTH_8:
807 slot->ctype = SDMMC_CTYPE_8BIT;
810 /* set default 1 bit mode */
811 slot->ctype = SDMMC_CTYPE_1BIT;
814 regs = mci_readl(slot->host, UHS_REG);
817 if (ios->timing == MMC_TIMING_UHS_DDR50)
818 regs |= ((0x1 << slot->id) << 16);
820 regs &= ~((0x1 << slot->id) << 16);
822 mci_writel(slot->host, UHS_REG, regs);
825 * Use mirror of ios->clock to prevent race with mmc
826 * core ios update when finding the minimum.
828 slot->clock = ios->clock;
830 if (drv_data && drv_data->set_ios)
831 drv_data->set_ios(slot->host, ios);
833 /* Slot specific timing and width adjustment */
834 dw_mci_setup_bus(slot, false);
836 switch (ios->power_mode) {
838 set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
840 if (slot->host->pdata->setpower)
841 slot->host->pdata->setpower(slot->id, mmc->ocr_avail);
842 regs = mci_readl(slot->host, PWREN);
843 regs |= (1 << slot->id);
844 mci_writel(slot->host, PWREN, regs);
847 /* Power down slot */
848 if (slot->host->pdata->setpower)
849 slot->host->pdata->setpower(slot->id, 0);
850 regs = mci_readl(slot->host, PWREN);
851 regs &= ~(1 << slot->id);
852 mci_writel(slot->host, PWREN, regs);
859 static int dw_mci_get_ro(struct mmc_host *mmc)
862 struct dw_mci_slot *slot = mmc_priv(mmc);
863 struct dw_mci_board *brd = slot->host->pdata;
865 /* Use platform get_ro function, else try on board write protect */
866 if (slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT)
868 else if (brd->get_ro)
869 read_only = brd->get_ro(slot->id);
870 else if (gpio_is_valid(slot->wp_gpio))
871 read_only = gpio_get_value(slot->wp_gpio);
874 mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
876 dev_dbg(&mmc->class_dev, "card is %s\n",
877 read_only ? "read-only" : "read-write");
882 static int dw_mci_get_cd(struct mmc_host *mmc)
885 struct dw_mci_slot *slot = mmc_priv(mmc);
886 struct dw_mci_board *brd = slot->host->pdata;
888 /* Use platform get_cd function, else try onboard card detect */
889 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
891 else if (brd->get_cd)
892 present = !brd->get_cd(slot->id);
894 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
898 dev_dbg(&mmc->class_dev, "card is present\n");
900 dev_dbg(&mmc->class_dev, "card is not present\n");
906 * Disable lower power mode.
908 * Low power mode will stop the card clock when idle. According to the
909 * description of the CLKENA register we should disable low power mode
910 * for SDIO cards if we need SDIO interrupts to work.
912 * This function is fast if low power mode is already disabled.
914 static void dw_mci_disable_low_power(struct dw_mci_slot *slot)
916 struct dw_mci *host = slot->host;
918 const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
920 clk_en_a = mci_readl(host, CLKENA);
922 if (clk_en_a & clken_low_pwr) {
923 mci_writel(host, CLKENA, clk_en_a & ~clken_low_pwr);
924 mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
925 SDMMC_CMD_PRV_DAT_WAIT, 0);
929 static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
931 struct dw_mci_slot *slot = mmc_priv(mmc);
932 struct dw_mci *host = slot->host;
935 /* Enable/disable Slot Specific SDIO interrupt */
936 int_mask = mci_readl(host, INTMASK);
939 * Turn off low power mode if it was enabled. This is a bit of
940 * a heavy operation and we disable / enable IRQs a lot, so
941 * we'll leave low power mode disabled and it will get
942 * re-enabled again in dw_mci_setup_bus().
944 dw_mci_disable_low_power(slot);
946 mci_writel(host, INTMASK,
947 (int_mask | SDMMC_INT_SDIO(slot->id)));
949 mci_writel(host, INTMASK,
950 (int_mask & ~SDMMC_INT_SDIO(slot->id)));
954 static const struct mmc_host_ops dw_mci_ops = {
955 .request = dw_mci_request,
956 .pre_req = dw_mci_pre_req,
957 .post_req = dw_mci_post_req,
958 .set_ios = dw_mci_set_ios,
959 .get_ro = dw_mci_get_ro,
960 .get_cd = dw_mci_get_cd,
961 .enable_sdio_irq = dw_mci_enable_sdio_irq,
964 static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
965 __releases(&host->lock)
966 __acquires(&host->lock)
968 struct dw_mci_slot *slot;
969 struct mmc_host *prev_mmc = host->cur_slot->mmc;
971 WARN_ON(host->cmd || host->data);
973 host->cur_slot->mrq = NULL;
975 if (!list_empty(&host->queue)) {
976 slot = list_entry(host->queue.next,
977 struct dw_mci_slot, queue_node);
978 list_del(&slot->queue_node);
979 dev_vdbg(host->dev, "list not empty: %s is next\n",
980 mmc_hostname(slot->mmc));
981 host->state = STATE_SENDING_CMD;
982 dw_mci_start_request(host, slot);
984 dev_vdbg(host->dev, "list empty\n");
985 host->state = STATE_IDLE;
988 spin_unlock(&host->lock);
989 mmc_request_done(prev_mmc, mrq);
990 spin_lock(&host->lock);
993 static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
995 u32 status = host->cmd_status;
997 host->cmd_status = 0;
999 /* Read the response from the card (up to 16 bytes) */
1000 if (cmd->flags & MMC_RSP_PRESENT) {
1001 if (cmd->flags & MMC_RSP_136) {
1002 cmd->resp[3] = mci_readl(host, RESP0);
1003 cmd->resp[2] = mci_readl(host, RESP1);
1004 cmd->resp[1] = mci_readl(host, RESP2);
1005 cmd->resp[0] = mci_readl(host, RESP3);
1007 cmd->resp[0] = mci_readl(host, RESP0);
1014 if (status & SDMMC_INT_RTO)
1015 cmd->error = -ETIMEDOUT;
1016 else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
1017 cmd->error = -EILSEQ;
1018 else if (status & SDMMC_INT_RESP_ERR)
1024 /* newer ip versions need a delay between retries */
1025 if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
1029 dw_mci_stop_dma(host);
1035 static void dw_mci_tasklet_func(unsigned long priv)
1037 struct dw_mci *host = (struct dw_mci *)priv;
1038 struct mmc_data *data;
1039 struct mmc_command *cmd;
1040 enum dw_mci_state state;
1041 enum dw_mci_state prev_state;
1044 spin_lock(&host->lock);
1046 state = host->state;
1056 case STATE_SENDING_CMD:
1057 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1058 &host->pending_events))
1063 set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
1064 dw_mci_command_complete(host, cmd);
1065 if (cmd == host->mrq->sbc && !cmd->error) {
1066 prev_state = state = STATE_SENDING_CMD;
1067 __dw_mci_start_request(host, host->cur_slot,
1072 if (!host->mrq->data || cmd->error) {
1073 dw_mci_request_end(host, host->mrq);
1077 prev_state = state = STATE_SENDING_DATA;
1080 case STATE_SENDING_DATA:
1081 if (test_and_clear_bit(EVENT_DATA_ERROR,
1082 &host->pending_events)) {
1083 dw_mci_stop_dma(host);
1085 send_stop_cmd(host, data);
1086 state = STATE_DATA_ERROR;
1090 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1091 &host->pending_events))
1094 set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
1095 prev_state = state = STATE_DATA_BUSY;
1098 case STATE_DATA_BUSY:
1099 if (!test_and_clear_bit(EVENT_DATA_COMPLETE,
1100 &host->pending_events))
1104 set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
1105 status = host->data_status;
1107 if (status & DW_MCI_DATA_ERROR_FLAGS) {
1108 if (status & SDMMC_INT_DRTO) {
1109 data->error = -ETIMEDOUT;
1110 } else if (status & SDMMC_INT_DCRC) {
1111 data->error = -EILSEQ;
1112 } else if (status & SDMMC_INT_EBE &&
1114 DW_MCI_SEND_STATUS) {
1116 * No data CRC status was returned.
1117 * The number of bytes transferred will
1118 * be exaggerated in PIO mode.
1120 data->bytes_xfered = 0;
1121 data->error = -ETIMEDOUT;
1130 * After an error, there may be data lingering
1131 * in the FIFO, so reset it - doing so
1132 * generates a block interrupt, hence setting
1133 * the scatter-gather pointer to NULL.
1135 sg_miter_stop(&host->sg_miter);
1137 ctrl = mci_readl(host, CTRL);
1138 ctrl |= SDMMC_CTRL_FIFO_RESET;
1139 mci_writel(host, CTRL, ctrl);
1141 data->bytes_xfered = data->blocks * data->blksz;
1146 dw_mci_request_end(host, host->mrq);
1150 if (host->mrq->sbc && !data->error) {
1151 data->stop->error = 0;
1152 dw_mci_request_end(host, host->mrq);
1156 prev_state = state = STATE_SENDING_STOP;
1158 send_stop_cmd(host, data);
1161 case STATE_SENDING_STOP:
1162 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1163 &host->pending_events))
1167 dw_mci_command_complete(host, host->mrq->stop);
1168 dw_mci_request_end(host, host->mrq);
1171 case STATE_DATA_ERROR:
1172 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1173 &host->pending_events))
1176 state = STATE_DATA_BUSY;
1179 } while (state != prev_state);
1181 host->state = state;
1183 spin_unlock(&host->lock);
1187 /* push final bytes to part_buf, only use during push */
1188 static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
1190 memcpy((void *)&host->part_buf, buf, cnt);
1191 host->part_buf_count = cnt;
1194 /* append bytes to part_buf, only use during push */
1195 static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
1197 cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
1198 memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
1199 host->part_buf_count += cnt;
1203 /* pull first bytes from part_buf, only use during pull */
1204 static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
1206 cnt = min(cnt, (int)host->part_buf_count);
1208 memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
1210 host->part_buf_count -= cnt;
1211 host->part_buf_start += cnt;
1216 /* pull final bytes from the part_buf, assuming it's just been filled */
1217 static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
1219 memcpy(buf, &host->part_buf, cnt);
1220 host->part_buf_start = cnt;
1221 host->part_buf_count = (1 << host->data_shift) - cnt;
1224 static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1226 struct mmc_data *data = host->data;
1229 /* try and push anything in the part_buf */
1230 if (unlikely(host->part_buf_count)) {
1231 int len = dw_mci_push_part_bytes(host, buf, cnt);
1234 if (host->part_buf_count == 2) {
1235 mci_writew(host, DATA(host->data_offset),
1237 host->part_buf_count = 0;
1240 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1241 if (unlikely((unsigned long)buf & 0x1)) {
1243 u16 aligned_buf[64];
1244 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1245 int items = len >> 1;
1247 /* memcpy from input buffer into aligned buffer */
1248 memcpy(aligned_buf, buf, len);
1251 /* push data from aligned buffer into fifo */
1252 for (i = 0; i < items; ++i)
1253 mci_writew(host, DATA(host->data_offset),
1260 for (; cnt >= 2; cnt -= 2)
1261 mci_writew(host, DATA(host->data_offset), *pdata++);
1264 /* put anything remaining in the part_buf */
1266 dw_mci_set_part_bytes(host, buf, cnt);
1267 /* Push data if we have reached the expected data length */
1268 if ((data->bytes_xfered + init_cnt) ==
1269 (data->blksz * data->blocks))
1270 mci_writew(host, DATA(host->data_offset),
1275 static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1277 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1278 if (unlikely((unsigned long)buf & 0x1)) {
1280 /* pull data from fifo into aligned buffer */
1281 u16 aligned_buf[64];
1282 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1283 int items = len >> 1;
1285 for (i = 0; i < items; ++i)
1286 aligned_buf[i] = mci_readw(host,
1287 DATA(host->data_offset));
1288 /* memcpy from aligned buffer into output buffer */
1289 memcpy(buf, aligned_buf, len);
1297 for (; cnt >= 2; cnt -= 2)
1298 *pdata++ = mci_readw(host, DATA(host->data_offset));
1302 host->part_buf16 = mci_readw(host, DATA(host->data_offset));
1303 dw_mci_pull_final_bytes(host, buf, cnt);
1307 static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1309 struct mmc_data *data = host->data;
1312 /* try and push anything in the part_buf */
1313 if (unlikely(host->part_buf_count)) {
1314 int len = dw_mci_push_part_bytes(host, buf, cnt);
1317 if (host->part_buf_count == 4) {
1318 mci_writel(host, DATA(host->data_offset),
1320 host->part_buf_count = 0;
1323 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1324 if (unlikely((unsigned long)buf & 0x3)) {
1326 u32 aligned_buf[32];
1327 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1328 int items = len >> 2;
1330 /* memcpy from input buffer into aligned buffer */
1331 memcpy(aligned_buf, buf, len);
1334 /* push data from aligned buffer into fifo */
1335 for (i = 0; i < items; ++i)
1336 mci_writel(host, DATA(host->data_offset),
1343 for (; cnt >= 4; cnt -= 4)
1344 mci_writel(host, DATA(host->data_offset), *pdata++);
1347 /* put anything remaining in the part_buf */
1349 dw_mci_set_part_bytes(host, buf, cnt);
1350 /* Push data if we have reached the expected data length */
1351 if ((data->bytes_xfered + init_cnt) ==
1352 (data->blksz * data->blocks))
1353 mci_writel(host, DATA(host->data_offset),
1358 static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1360 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1361 if (unlikely((unsigned long)buf & 0x3)) {
1363 /* pull data from fifo into aligned buffer */
1364 u32 aligned_buf[32];
1365 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1366 int items = len >> 2;
1368 for (i = 0; i < items; ++i)
1369 aligned_buf[i] = mci_readl(host,
1370 DATA(host->data_offset));
1371 /* memcpy from aligned buffer into output buffer */
1372 memcpy(buf, aligned_buf, len);
1380 for (; cnt >= 4; cnt -= 4)
1381 *pdata++ = mci_readl(host, DATA(host->data_offset));
1385 host->part_buf32 = mci_readl(host, DATA(host->data_offset));
1386 dw_mci_pull_final_bytes(host, buf, cnt);
1390 static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1392 struct mmc_data *data = host->data;
1395 /* try and push anything in the part_buf */
1396 if (unlikely(host->part_buf_count)) {
1397 int len = dw_mci_push_part_bytes(host, buf, cnt);
1401 if (host->part_buf_count == 8) {
1402 mci_writeq(host, DATA(host->data_offset),
1404 host->part_buf_count = 0;
1407 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1408 if (unlikely((unsigned long)buf & 0x7)) {
1410 u64 aligned_buf[16];
1411 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1412 int items = len >> 3;
1414 /* memcpy from input buffer into aligned buffer */
1415 memcpy(aligned_buf, buf, len);
1418 /* push data from aligned buffer into fifo */
1419 for (i = 0; i < items; ++i)
1420 mci_writeq(host, DATA(host->data_offset),
1427 for (; cnt >= 8; cnt -= 8)
1428 mci_writeq(host, DATA(host->data_offset), *pdata++);
1431 /* put anything remaining in the part_buf */
1433 dw_mci_set_part_bytes(host, buf, cnt);
1434 /* Push data if we have reached the expected data length */
1435 if ((data->bytes_xfered + init_cnt) ==
1436 (data->blksz * data->blocks))
1437 mci_writeq(host, DATA(host->data_offset),
1442 static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1444 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1445 if (unlikely((unsigned long)buf & 0x7)) {
1447 /* pull data from fifo into aligned buffer */
1448 u64 aligned_buf[16];
1449 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1450 int items = len >> 3;
1452 for (i = 0; i < items; ++i)
1453 aligned_buf[i] = mci_readq(host,
1454 DATA(host->data_offset));
1455 /* memcpy from aligned buffer into output buffer */
1456 memcpy(buf, aligned_buf, len);
1464 for (; cnt >= 8; cnt -= 8)
1465 *pdata++ = mci_readq(host, DATA(host->data_offset));
1469 host->part_buf = mci_readq(host, DATA(host->data_offset));
1470 dw_mci_pull_final_bytes(host, buf, cnt);
1474 static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
1478 /* get remaining partial bytes */
1479 len = dw_mci_pull_part_bytes(host, buf, cnt);
1480 if (unlikely(len == cnt))
1485 /* get the rest of the data */
1486 host->pull_data(host, buf, cnt);
1489 static void dw_mci_read_data_pio(struct dw_mci *host, bool dto)
1491 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1493 unsigned int offset;
1494 struct mmc_data *data = host->data;
1495 int shift = host->data_shift;
1498 unsigned int remain, fcnt;
1501 if (!sg_miter_next(sg_miter))
1504 host->sg = sg_miter->piter.sg;
1505 buf = sg_miter->addr;
1506 remain = sg_miter->length;
1510 fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
1511 << shift) + host->part_buf_count;
1512 len = min(remain, fcnt);
1515 dw_mci_pull_data(host, (void *)(buf + offset), len);
1516 data->bytes_xfered += len;
1521 sg_miter->consumed = offset;
1522 status = mci_readl(host, MINTSTS);
1523 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
1524 /* if the RXDR is ready read again */
1525 } while ((status & SDMMC_INT_RXDR) ||
1526 (dto && SDMMC_GET_FCNT(mci_readl(host, STATUS))));
1529 if (!sg_miter_next(sg_miter))
1531 sg_miter->consumed = 0;
1533 sg_miter_stop(sg_miter);
1537 sg_miter_stop(sg_miter);
1540 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
1543 static void dw_mci_write_data_pio(struct dw_mci *host)
1545 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1547 unsigned int offset;
1548 struct mmc_data *data = host->data;
1549 int shift = host->data_shift;
1552 unsigned int fifo_depth = host->fifo_depth;
1553 unsigned int remain, fcnt;
1556 if (!sg_miter_next(sg_miter))
1559 host->sg = sg_miter->piter.sg;
1560 buf = sg_miter->addr;
1561 remain = sg_miter->length;
1565 fcnt = ((fifo_depth -
1566 SDMMC_GET_FCNT(mci_readl(host, STATUS)))
1567 << shift) - host->part_buf_count;
1568 len = min(remain, fcnt);
1571 host->push_data(host, (void *)(buf + offset), len);
1572 data->bytes_xfered += len;
1577 sg_miter->consumed = offset;
1578 status = mci_readl(host, MINTSTS);
1579 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
1580 } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
1583 if (!sg_miter_next(sg_miter))
1585 sg_miter->consumed = 0;
1587 sg_miter_stop(sg_miter);
1591 sg_miter_stop(sg_miter);
1594 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
1597 static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
1599 if (!host->cmd_status)
1600 host->cmd_status = status;
1604 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
1605 tasklet_schedule(&host->tasklet);
1608 static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1610 struct dw_mci *host = dev_id;
1614 pending = mci_readl(host, MINTSTS); /* read-only mask reg */
1617 * DTO fix - version 2.10a and below, and only if internal DMA
1620 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) {
1622 ((mci_readl(host, STATUS) >> 17) & 0x1fff))
1623 pending |= SDMMC_INT_DATA_OVER;
1627 if (pending & DW_MCI_CMD_ERROR_FLAGS) {
1628 mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
1629 host->cmd_status = pending;
1631 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
1634 if (pending & DW_MCI_DATA_ERROR_FLAGS) {
1635 /* if there is an error report DATA_ERROR */
1636 mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
1637 host->data_status = pending;
1639 set_bit(EVENT_DATA_ERROR, &host->pending_events);
1640 tasklet_schedule(&host->tasklet);
1643 if (pending & SDMMC_INT_DATA_OVER) {
1644 mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
1645 if (!host->data_status)
1646 host->data_status = pending;
1648 if (host->dir_status == DW_MCI_RECV_STATUS) {
1649 if (host->sg != NULL)
1650 dw_mci_read_data_pio(host, true);
1652 set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
1653 tasklet_schedule(&host->tasklet);
1656 if (pending & SDMMC_INT_RXDR) {
1657 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
1658 if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
1659 dw_mci_read_data_pio(host, false);
1662 if (pending & SDMMC_INT_TXDR) {
1663 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
1664 if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
1665 dw_mci_write_data_pio(host);
1668 if (pending & SDMMC_INT_CMD_DONE) {
1669 mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
1670 dw_mci_cmd_interrupt(host, pending);
1673 if (pending & SDMMC_INT_CD) {
1674 mci_writel(host, RINTSTS, SDMMC_INT_CD);
1675 queue_work(host->card_workqueue, &host->card_work);
1678 /* Handle SDIO Interrupts */
1679 for (i = 0; i < host->num_slots; i++) {
1680 struct dw_mci_slot *slot = host->slot[i];
1681 if (pending & SDMMC_INT_SDIO(i)) {
1682 mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i));
1683 mmc_signal_sdio_irq(slot->mmc);
1689 #ifdef CONFIG_MMC_DW_IDMAC
1690 /* Handle DMA interrupts */
1691 pending = mci_readl(host, IDSTS);
1692 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
1693 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI);
1694 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
1695 host->dma_ops->complete(host);
1702 static void dw_mci_work_routine_card(struct work_struct *work)
1704 struct dw_mci *host = container_of(work, struct dw_mci, card_work);
1707 for (i = 0; i < host->num_slots; i++) {
1708 struct dw_mci_slot *slot = host->slot[i];
1709 struct mmc_host *mmc = slot->mmc;
1710 struct mmc_request *mrq;
1714 present = dw_mci_get_cd(mmc);
1715 while (present != slot->last_detect_state) {
1716 dev_dbg(&slot->mmc->class_dev, "card %s\n",
1717 present ? "inserted" : "removed");
1719 spin_lock_bh(&host->lock);
1721 /* Card change detected */
1722 slot->last_detect_state = present;
1724 /* Mark card as present if applicable */
1726 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1728 /* Clean up queue if present */
1731 if (mrq == host->mrq) {
1735 switch (host->state) {
1738 case STATE_SENDING_CMD:
1739 mrq->cmd->error = -ENOMEDIUM;
1743 case STATE_SENDING_DATA:
1744 mrq->data->error = -ENOMEDIUM;
1745 dw_mci_stop_dma(host);
1747 case STATE_DATA_BUSY:
1748 case STATE_DATA_ERROR:
1749 if (mrq->data->error == -EINPROGRESS)
1750 mrq->data->error = -ENOMEDIUM;
1754 case STATE_SENDING_STOP:
1755 mrq->stop->error = -ENOMEDIUM;
1759 dw_mci_request_end(host, mrq);
1761 list_del(&slot->queue_node);
1762 mrq->cmd->error = -ENOMEDIUM;
1764 mrq->data->error = -ENOMEDIUM;
1766 mrq->stop->error = -ENOMEDIUM;
1768 spin_unlock(&host->lock);
1769 mmc_request_done(slot->mmc, mrq);
1770 spin_lock(&host->lock);
1774 /* Power down slot */
1776 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1779 * Clear down the FIFO - doing so generates a
1780 * block interrupt, hence setting the
1781 * scatter-gather pointer to NULL.
1783 sg_miter_stop(&host->sg_miter);
1786 ctrl = mci_readl(host, CTRL);
1787 ctrl |= SDMMC_CTRL_FIFO_RESET;
1788 mci_writel(host, CTRL, ctrl);
1790 #ifdef CONFIG_MMC_DW_IDMAC
1791 ctrl = mci_readl(host, BMOD);
1792 /* Software reset of DMA */
1793 ctrl |= SDMMC_IDMAC_SWRESET;
1794 mci_writel(host, BMOD, ctrl);
1799 spin_unlock_bh(&host->lock);
1801 present = dw_mci_get_cd(mmc);
1804 mmc_detect_change(slot->mmc,
1805 msecs_to_jiffies(host->pdata->detect_delay_ms));
1810 /* given a slot id, find out the device node representing that slot */
1811 static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
1813 struct device_node *np;
1817 if (!dev || !dev->of_node)
1820 for_each_child_of_node(dev->of_node, np) {
1821 addr = of_get_property(np, "reg", &len);
1822 if (!addr || (len < sizeof(int)))
1824 if (be32_to_cpup(addr) == slot)
1830 static struct dw_mci_of_slot_quirks {
1833 } of_slot_quirks[] = {
1835 .quirk = "disable-wp",
1836 .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT,
1840 static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1842 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1847 for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++)
1848 if (of_get_property(np, of_slot_quirks[idx].quirk, NULL))
1849 quirks |= of_slot_quirks[idx].id;
1854 /* find out bus-width for a given slot */
1855 static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
1857 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1863 if (of_property_read_u32(np, "bus-width", &bus_wd))
1864 dev_err(dev, "bus-width property not found, assuming width"
1869 /* find the write protect gpio for a given slot; or -1 if none specified */
1870 static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1872 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1878 gpio = of_get_named_gpio(np, "wp-gpios", 0);
1880 /* Having a missing entry is valid; return silently */
1881 if (!gpio_is_valid(gpio))
1884 if (devm_gpio_request(dev, gpio, "dw-mci-wp")) {
1885 dev_warn(dev, "gpio [%d] request failed\n", gpio);
1891 #else /* CONFIG_OF */
1892 static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1896 static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
1900 static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
1904 static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1908 #endif /* CONFIG_OF */
1910 static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1912 struct mmc_host *mmc;
1913 struct dw_mci_slot *slot;
1914 const struct dw_mci_drv_data *drv_data = host->drv_data;
1918 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
1922 slot = mmc_priv(mmc);
1926 host->slot[id] = slot;
1928 slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
1930 mmc->ops = &dw_mci_ops;
1931 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
1932 mmc->f_max = host->bus_hz;
1934 if (host->pdata->get_ocr)
1935 mmc->ocr_avail = host->pdata->get_ocr(id);
1937 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1940 * Start with slot power disabled, it will be enabled when a card
1943 if (host->pdata->setpower)
1944 host->pdata->setpower(id, 0);
1946 if (host->pdata->caps)
1947 mmc->caps = host->pdata->caps;
1949 if (host->pdata->pm_caps)
1950 mmc->pm_caps = host->pdata->pm_caps;
1952 if (host->dev->of_node) {
1953 ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
1957 ctrl_id = to_platform_device(host->dev)->id;
1959 if (drv_data && drv_data->caps)
1960 mmc->caps |= drv_data->caps[ctrl_id];
1962 if (host->pdata->caps2)
1963 mmc->caps2 = host->pdata->caps2;
1965 if (host->pdata->get_bus_wd)
1966 bus_width = host->pdata->get_bus_wd(slot->id);
1967 else if (host->dev->of_node)
1968 bus_width = dw_mci_of_get_bus_wd(host->dev, slot->id);
1972 switch (bus_width) {
1974 mmc->caps |= MMC_CAP_8_BIT_DATA;
1976 mmc->caps |= MMC_CAP_4_BIT_DATA;
1979 if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
1980 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
1982 if (host->pdata->blk_settings) {
1983 mmc->max_segs = host->pdata->blk_settings->max_segs;
1984 mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
1985 mmc->max_blk_count = host->pdata->blk_settings->max_blk_count;
1986 mmc->max_req_size = host->pdata->blk_settings->max_req_size;
1987 mmc->max_seg_size = host->pdata->blk_settings->max_seg_size;
1989 /* Useful defaults if platform data is unset. */
1990 #ifdef CONFIG_MMC_DW_IDMAC
1991 mmc->max_segs = host->ring_size;
1992 mmc->max_blk_size = 65536;
1993 mmc->max_blk_count = host->ring_size;
1994 mmc->max_seg_size = 0x1000;
1995 mmc->max_req_size = mmc->max_seg_size * mmc->max_blk_count;
1998 mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */
1999 mmc->max_blk_count = 512;
2000 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
2001 mmc->max_seg_size = mmc->max_req_size;
2002 #endif /* CONFIG_MMC_DW_IDMAC */
2005 if (dw_mci_get_cd(mmc))
2006 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
2008 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
2010 slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id);
2012 ret = mmc_add_host(mmc);
2016 #if defined(CONFIG_DEBUG_FS)
2017 dw_mci_init_debugfs(slot);
2020 /* Card initially undetected */
2021 slot->last_detect_state = 0;
2030 static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
2032 /* Shutdown detect IRQ */
2033 if (slot->host->pdata->exit)
2034 slot->host->pdata->exit(id);
2036 /* Debugfs stuff is cleaned up by mmc core */
2037 mmc_remove_host(slot->mmc);
2038 slot->host->slot[id] = NULL;
2039 mmc_free_host(slot->mmc);
2042 static void dw_mci_init_dma(struct dw_mci *host)
2044 /* Alloc memory for sg translation */
2045 host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE,
2046 &host->sg_dma, GFP_KERNEL);
2047 if (!host->sg_cpu) {
2048 dev_err(host->dev, "%s: could not alloc DMA memory\n",
2053 /* Determine which DMA interface to use */
2054 #ifdef CONFIG_MMC_DW_IDMAC
2055 host->dma_ops = &dw_mci_idmac_ops;
2056 dev_info(host->dev, "Using internal DMA controller.\n");
2062 if (host->dma_ops->init && host->dma_ops->start &&
2063 host->dma_ops->stop && host->dma_ops->cleanup) {
2064 if (host->dma_ops->init(host)) {
2065 dev_err(host->dev, "%s: Unable to initialize "
2066 "DMA Controller.\n", __func__);
2070 dev_err(host->dev, "DMA initialization not found.\n");
2078 dev_info(host->dev, "Using PIO mode.\n");
2083 static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
2085 unsigned long timeout = jiffies + msecs_to_jiffies(500);
2088 mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
2089 SDMMC_CTRL_DMA_RESET));
2091 /* wait till resets clear */
2093 ctrl = mci_readl(host, CTRL);
2094 if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
2095 SDMMC_CTRL_DMA_RESET)))
2097 } while (time_before(jiffies, timeout));
2099 dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
2105 static struct dw_mci_of_quirks {
2110 .quirk = "supports-highspeed",
2111 .id = DW_MCI_QUIRK_HIGHSPEED,
2113 .quirk = "broken-cd",
2114 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
2118 static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2120 struct dw_mci_board *pdata;
2121 struct device *dev = host->dev;
2122 struct device_node *np = dev->of_node;
2123 const struct dw_mci_drv_data *drv_data = host->drv_data;
2125 u32 clock_frequency;
2127 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2129 dev_err(dev, "could not allocate memory for pdata\n");
2130 return ERR_PTR(-ENOMEM);
2133 /* find out number of slots supported */
2134 if (of_property_read_u32(dev->of_node, "num-slots",
2135 &pdata->num_slots)) {
2136 dev_info(dev, "num-slots property not found, "
2137 "assuming 1 slot is available\n");
2138 pdata->num_slots = 1;
2142 for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++)
2143 if (of_get_property(np, of_quirks[idx].quirk, NULL))
2144 pdata->quirks |= of_quirks[idx].id;
2146 if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth))
2147 dev_info(dev, "fifo-depth property not found, using "
2148 "value of FIFOTH register as default\n");
2150 of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms);
2152 if (!of_property_read_u32(np, "clock-frequency", &clock_frequency))
2153 pdata->bus_hz = clock_frequency;
2155 if (drv_data && drv_data->parse_dt) {
2156 ret = drv_data->parse_dt(host);
2158 return ERR_PTR(ret);
2161 if (of_find_property(np, "keep-power-in-suspend", NULL))
2162 pdata->pm_caps |= MMC_PM_KEEP_POWER;
2164 if (of_find_property(np, "enable-sdio-wakeup", NULL))
2165 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
2170 #else /* CONFIG_OF */
2171 static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2173 return ERR_PTR(-EINVAL);
2175 #endif /* CONFIG_OF */
2177 int dw_mci_probe(struct dw_mci *host)
2179 const struct dw_mci_drv_data *drv_data = host->drv_data;
2180 int width, i, ret = 0;
2185 host->pdata = dw_mci_parse_dt(host);
2186 if (IS_ERR(host->pdata)) {
2187 dev_err(host->dev, "platform data not available\n");
2192 if (!host->pdata->select_slot && host->pdata->num_slots > 1) {
2194 "Platform data must supply select_slot function\n");
2198 host->biu_clk = devm_clk_get(host->dev, "biu");
2199 if (IS_ERR(host->biu_clk)) {
2200 dev_dbg(host->dev, "biu clock not available\n");
2202 ret = clk_prepare_enable(host->biu_clk);
2204 dev_err(host->dev, "failed to enable biu clock\n");
2209 host->ciu_clk = devm_clk_get(host->dev, "ciu");
2210 if (IS_ERR(host->ciu_clk)) {
2211 dev_dbg(host->dev, "ciu clock not available\n");
2212 host->bus_hz = host->pdata->bus_hz;
2214 ret = clk_prepare_enable(host->ciu_clk);
2216 dev_err(host->dev, "failed to enable ciu clock\n");
2220 if (host->pdata->bus_hz) {
2221 ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz);
2224 "Unable to set bus rate to %ul\n",
2225 host->pdata->bus_hz);
2227 host->bus_hz = clk_get_rate(host->ciu_clk);
2230 if (drv_data && drv_data->setup_clock) {
2231 ret = drv_data->setup_clock(host);
2234 "implementation specific clock setup failed\n");
2239 host->vmmc = devm_regulator_get_optional(host->dev, "vmmc");
2240 if (IS_ERR(host->vmmc)) {
2241 ret = PTR_ERR(host->vmmc);
2242 if (ret == -EPROBE_DEFER)
2245 dev_info(host->dev, "no vmmc regulator found: %d\n", ret);
2248 ret = regulator_enable(host->vmmc);
2250 if (ret != -EPROBE_DEFER)
2252 "regulator_enable fail: %d\n", ret);
2257 if (!host->bus_hz) {
2259 "Platform data must supply bus speed\n");
2264 host->quirks = host->pdata->quirks;
2266 spin_lock_init(&host->lock);
2267 INIT_LIST_HEAD(&host->queue);
2270 * Get the host data width - this assumes that HCON has been set with
2271 * the correct values.
2273 i = (mci_readl(host, HCON) >> 7) & 0x7;
2275 host->push_data = dw_mci_push_data16;
2276 host->pull_data = dw_mci_pull_data16;
2278 host->data_shift = 1;
2279 } else if (i == 2) {
2280 host->push_data = dw_mci_push_data64;
2281 host->pull_data = dw_mci_pull_data64;
2283 host->data_shift = 3;
2285 /* Check for a reserved value, and warn if it is */
2287 "HCON reports a reserved host data width!\n"
2288 "Defaulting to 32-bit access.\n");
2289 host->push_data = dw_mci_push_data32;
2290 host->pull_data = dw_mci_pull_data32;
2292 host->data_shift = 2;
2295 /* Reset all blocks */
2296 if (!mci_wait_reset(host->dev, host))
2299 host->dma_ops = host->pdata->dma_ops;
2300 dw_mci_init_dma(host);
2302 /* Clear the interrupts for the host controller */
2303 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2304 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2306 /* Put in max timeout */
2307 mci_writel(host, TMOUT, 0xFFFFFFFF);
2310 * FIFO threshold settings RxMark = fifo_size / 2 - 1,
2311 * Tx Mark = fifo_size / 2 DMA Size = 8
2313 if (!host->pdata->fifo_depth) {
2315 * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
2316 * have been overwritten by the bootloader, just like we're
2317 * about to do, so if you know the value for your hardware, you
2318 * should put it in the platform data.
2320 fifo_size = mci_readl(host, FIFOTH);
2321 fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
2323 fifo_size = host->pdata->fifo_depth;
2325 host->fifo_depth = fifo_size;
2326 host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
2327 ((fifo_size/2) << 0));
2328 mci_writel(host, FIFOTH, host->fifoth_val);
2330 /* disable clock to CIU */
2331 mci_writel(host, CLKENA, 0);
2332 mci_writel(host, CLKSRC, 0);
2335 * In 2.40a spec, Data offset is changed.
2336 * Need to check the version-id and set data-offset for DATA register.
2338 host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
2339 dev_info(host->dev, "Version ID is %04x\n", host->verid);
2341 if (host->verid < DW_MMC_240A)
2342 host->data_offset = DATA_OFFSET;
2344 host->data_offset = DATA_240A_OFFSET;
2346 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
2347 host->card_workqueue = alloc_workqueue("dw-mci-card",
2348 WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1);
2349 if (!host->card_workqueue) {
2353 INIT_WORK(&host->card_work, dw_mci_work_routine_card);
2354 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
2355 host->irq_flags, "dw-mci", host);
2359 if (host->pdata->num_slots)
2360 host->num_slots = host->pdata->num_slots;
2362 host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
2365 * Enable interrupts for command done, data over, data empty, card det,
2366 * receive ready and error such as transmit, receive timeout, crc error
2368 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2369 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2370 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2371 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2372 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
2374 dev_info(host->dev, "DW MMC controller at irq %d, "
2375 "%d bit host data width, "
2377 host->irq, width, fifo_size);
2379 /* We need at least one slot to succeed */
2380 for (i = 0; i < host->num_slots; i++) {
2381 ret = dw_mci_init_slot(host, i);
2383 dev_dbg(host->dev, "slot %d init failed\n", i);
2389 dev_info(host->dev, "%d slots initialized\n", init_slots);
2391 dev_dbg(host->dev, "attempted to initialize %d slots, "
2392 "but failed on all\n", host->num_slots);
2396 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
2397 dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n");
2402 destroy_workqueue(host->card_workqueue);
2405 if (host->use_dma && host->dma_ops->exit)
2406 host->dma_ops->exit(host);
2410 regulator_disable(host->vmmc);
2413 if (!IS_ERR(host->ciu_clk))
2414 clk_disable_unprepare(host->ciu_clk);
2417 if (!IS_ERR(host->biu_clk))
2418 clk_disable_unprepare(host->biu_clk);
2422 EXPORT_SYMBOL(dw_mci_probe);
2424 void dw_mci_remove(struct dw_mci *host)
2428 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2429 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2431 for (i = 0; i < host->num_slots; i++) {
2432 dev_dbg(host->dev, "remove slot %d\n", i);
2434 dw_mci_cleanup_slot(host->slot[i], i);
2437 /* disable clock to CIU */
2438 mci_writel(host, CLKENA, 0);
2439 mci_writel(host, CLKSRC, 0);
2441 destroy_workqueue(host->card_workqueue);
2443 if (host->use_dma && host->dma_ops->exit)
2444 host->dma_ops->exit(host);
2447 regulator_disable(host->vmmc);
2449 if (!IS_ERR(host->ciu_clk))
2450 clk_disable_unprepare(host->ciu_clk);
2452 if (!IS_ERR(host->biu_clk))
2453 clk_disable_unprepare(host->biu_clk);
2455 EXPORT_SYMBOL(dw_mci_remove);
2459 #ifdef CONFIG_PM_SLEEP
2461 * TODO: we should probably disable the clock to the card in the suspend path.
2463 int dw_mci_suspend(struct dw_mci *host)
2467 for (i = 0; i < host->num_slots; i++) {
2468 struct dw_mci_slot *slot = host->slot[i];
2471 ret = mmc_suspend_host(slot->mmc);
2474 slot = host->slot[i];
2476 mmc_resume_host(host->slot[i]->mmc);
2483 regulator_disable(host->vmmc);
2487 EXPORT_SYMBOL(dw_mci_suspend);
2489 int dw_mci_resume(struct dw_mci *host)
2494 ret = regulator_enable(host->vmmc);
2497 "failed to enable regulator: %d\n", ret);
2502 if (!mci_wait_reset(host->dev, host)) {
2507 if (host->use_dma && host->dma_ops->init)
2508 host->dma_ops->init(host);
2510 /* Restore the old value at FIFOTH register */
2511 mci_writel(host, FIFOTH, host->fifoth_val);
2513 /* Put in max timeout */
2514 mci_writel(host, TMOUT, 0xFFFFFFFF);
2516 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2517 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2518 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2519 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2520 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
2522 for (i = 0; i < host->num_slots; i++) {
2523 struct dw_mci_slot *slot = host->slot[i];
2526 if (slot->mmc->pm_flags & MMC_PM_KEEP_POWER) {
2527 dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
2528 dw_mci_setup_bus(slot, true);
2531 ret = mmc_resume_host(host->slot[i]->mmc);
2537 EXPORT_SYMBOL(dw_mci_resume);
2538 #endif /* CONFIG_PM_SLEEP */
2540 static int __init dw_mci_init(void)
2542 pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
2546 static void __exit dw_mci_exit(void)
2550 module_init(dw_mci_init);
2551 module_exit(dw_mci_exit);
2553 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
2554 MODULE_AUTHOR("NXP Semiconductor VietNam");
2555 MODULE_AUTHOR("Imagination Technologies Ltd");
2556 MODULE_LICENSE("GPL v2");