2 * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
4 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * Thanks to the following companies for their support:
13 * - JMicron (hardware and technical support)
16 #include <linux/delay.h>
17 #include <linux/highmem.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/scatterlist.h>
22 #include <linux/leds.h>
24 #include <linux/mmc/host.h>
28 #define DRIVER_NAME "sdhci"
30 #define DBG(f, x...) \
31 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
33 static unsigned int debug_quirks = 0;
35 static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
36 static void sdhci_finish_data(struct sdhci_host *);
38 static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
39 static void sdhci_finish_command(struct sdhci_host *);
41 static void sdhci_dumpregs(struct sdhci_host *host)
43 printk(KERN_DEBUG DRIVER_NAME ": ============== REGISTER DUMP ==============\n");
45 printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
46 readl(host->ioaddr + SDHCI_DMA_ADDRESS),
47 readw(host->ioaddr + SDHCI_HOST_VERSION));
48 printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
49 readw(host->ioaddr + SDHCI_BLOCK_SIZE),
50 readw(host->ioaddr + SDHCI_BLOCK_COUNT));
51 printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
52 readl(host->ioaddr + SDHCI_ARGUMENT),
53 readw(host->ioaddr + SDHCI_TRANSFER_MODE));
54 printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
55 readl(host->ioaddr + SDHCI_PRESENT_STATE),
56 readb(host->ioaddr + SDHCI_HOST_CONTROL));
57 printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
58 readb(host->ioaddr + SDHCI_POWER_CONTROL),
59 readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL));
60 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
61 readb(host->ioaddr + SDHCI_WAKE_UP_CONTROL),
62 readw(host->ioaddr + SDHCI_CLOCK_CONTROL));
63 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
64 readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL),
65 readl(host->ioaddr + SDHCI_INT_STATUS));
66 printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
67 readl(host->ioaddr + SDHCI_INT_ENABLE),
68 readl(host->ioaddr + SDHCI_SIGNAL_ENABLE));
69 printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
70 readw(host->ioaddr + SDHCI_ACMD12_ERR),
71 readw(host->ioaddr + SDHCI_SLOT_INT_STATUS));
72 printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Max curr: 0x%08x\n",
73 readl(host->ioaddr + SDHCI_CAPABILITIES),
74 readl(host->ioaddr + SDHCI_MAX_CURRENT));
76 printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n");
79 /*****************************************************************************\
81 * Low level functions *
83 \*****************************************************************************/
85 static void sdhci_reset(struct sdhci_host *host, u8 mask)
87 unsigned long timeout;
89 if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
90 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) &
95 writeb(mask, host->ioaddr + SDHCI_SOFTWARE_RESET);
97 if (mask & SDHCI_RESET_ALL)
100 /* Wait max 100 ms */
103 /* hw clears the bit when it's done */
104 while (readb(host->ioaddr + SDHCI_SOFTWARE_RESET) & mask) {
106 printk(KERN_ERR "%s: Reset 0x%x never completed.\n",
107 mmc_hostname(host->mmc), (int)mask);
108 sdhci_dumpregs(host);
116 static void sdhci_init(struct sdhci_host *host)
120 sdhci_reset(host, SDHCI_RESET_ALL);
122 intmask = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
123 SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX |
124 SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
125 SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT |
126 SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL |
127 SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE |
128 SDHCI_INT_ADMA_ERROR;
130 writel(intmask, host->ioaddr + SDHCI_INT_ENABLE);
131 writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE);
134 static void sdhci_activate_led(struct sdhci_host *host)
138 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
139 ctrl |= SDHCI_CTRL_LED;
140 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
143 static void sdhci_deactivate_led(struct sdhci_host *host)
147 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
148 ctrl &= ~SDHCI_CTRL_LED;
149 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
152 #ifdef CONFIG_LEDS_CLASS
153 static void sdhci_led_control(struct led_classdev *led,
154 enum led_brightness brightness)
156 struct sdhci_host *host = container_of(led, struct sdhci_host, led);
159 spin_lock_irqsave(&host->lock, flags);
161 if (brightness == LED_OFF)
162 sdhci_deactivate_led(host);
164 sdhci_activate_led(host);
166 spin_unlock_irqrestore(&host->lock, flags);
170 /*****************************************************************************\
174 \*****************************************************************************/
176 static void sdhci_read_block_pio(struct sdhci_host *host)
179 size_t blksize, len, chunk;
180 u32 uninitialized_var(scratch);
183 DBG("PIO reading\n");
185 blksize = host->data->blksz;
188 local_irq_save(flags);
191 if (!sg_miter_next(&host->sg_miter))
194 len = min(host->sg_miter.length, blksize);
197 host->sg_miter.consumed = len;
199 buf = host->sg_miter.addr;
203 scratch = readl(host->ioaddr + SDHCI_BUFFER);
207 *buf = scratch & 0xFF;
216 sg_miter_stop(&host->sg_miter);
218 local_irq_restore(flags);
221 static void sdhci_write_block_pio(struct sdhci_host *host)
224 size_t blksize, len, chunk;
228 DBG("PIO writing\n");
230 blksize = host->data->blksz;
234 local_irq_save(flags);
237 if (!sg_miter_next(&host->sg_miter))
240 len = min(host->sg_miter.length, blksize);
243 host->sg_miter.consumed = len;
245 buf = host->sg_miter.addr;
248 scratch |= (u32)*buf << (chunk * 8);
254 if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
255 writel(scratch, host->ioaddr + SDHCI_BUFFER);
262 sg_miter_stop(&host->sg_miter);
264 local_irq_restore(flags);
267 static void sdhci_transfer_pio(struct sdhci_host *host)
273 if (host->blocks == 0)
276 if (host->data->flags & MMC_DATA_READ)
277 mask = SDHCI_DATA_AVAILABLE;
279 mask = SDHCI_SPACE_AVAILABLE;
282 * Some controllers (JMicron JMB38x) mess up the buffer bits
283 * for transfers < 4 bytes. As long as it is just one block,
284 * we can ignore the bits.
286 if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) &&
287 (host->data->blocks == 1))
290 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
291 if (host->data->flags & MMC_DATA_READ)
292 sdhci_read_block_pio(host);
294 sdhci_write_block_pio(host);
297 if (host->blocks == 0)
301 DBG("PIO transfer complete.\n");
304 static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
306 local_irq_save(*flags);
307 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
310 static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
312 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
313 local_irq_restore(*flags);
316 static int sdhci_adma_table_pre(struct sdhci_host *host,
317 struct mmc_data *data)
324 dma_addr_t align_addr;
327 struct scatterlist *sg;
333 * The spec does not specify endianness of descriptor table.
334 * We currently guess that it is LE.
337 if (data->flags & MMC_DATA_READ)
338 direction = DMA_FROM_DEVICE;
340 direction = DMA_TO_DEVICE;
343 * The ADMA descriptor table is mapped further down as we
344 * need to fill it with data first.
347 host->align_addr = dma_map_single(mmc_dev(host->mmc),
348 host->align_buffer, 128 * 4, direction);
349 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
351 BUG_ON(host->align_addr & 0x3);
353 host->sg_count = dma_map_sg(mmc_dev(host->mmc),
354 data->sg, data->sg_len, direction);
355 if (host->sg_count == 0)
358 desc = host->adma_desc;
359 align = host->align_buffer;
361 align_addr = host->align_addr;
363 for_each_sg(data->sg, sg, host->sg_count, i) {
364 addr = sg_dma_address(sg);
365 len = sg_dma_len(sg);
368 * The SDHCI specification states that ADMA
369 * addresses must be 32-bit aligned. If they
370 * aren't, then we use a bounce buffer for
371 * the (up to three) bytes that screw up the
374 offset = (4 - (addr & 0x3)) & 0x3;
376 if (data->flags & MMC_DATA_WRITE) {
377 buffer = sdhci_kmap_atomic(sg, &flags);
378 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
379 memcpy(align, buffer, offset);
380 sdhci_kunmap_atomic(buffer, &flags);
383 desc[7] = (align_addr >> 24) & 0xff;
384 desc[6] = (align_addr >> 16) & 0xff;
385 desc[5] = (align_addr >> 8) & 0xff;
386 desc[4] = (align_addr >> 0) & 0xff;
388 BUG_ON(offset > 65536);
390 desc[3] = (offset >> 8) & 0xff;
391 desc[2] = (offset >> 0) & 0xff;
394 desc[0] = 0x21; /* tran, valid */
405 desc[7] = (addr >> 24) & 0xff;
406 desc[6] = (addr >> 16) & 0xff;
407 desc[5] = (addr >> 8) & 0xff;
408 desc[4] = (addr >> 0) & 0xff;
412 desc[3] = (len >> 8) & 0xff;
413 desc[2] = (len >> 0) & 0xff;
416 desc[0] = 0x21; /* tran, valid */
421 * If this triggers then we have a calculation bug
424 WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4);
428 * Add a terminating entry.
439 desc[0] = 0x03; /* nop, end, valid */
442 * Resync align buffer as we might have changed it.
444 if (data->flags & MMC_DATA_WRITE) {
445 dma_sync_single_for_device(mmc_dev(host->mmc),
446 host->align_addr, 128 * 4, direction);
449 host->adma_addr = dma_map_single(mmc_dev(host->mmc),
450 host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE);
451 if (dma_mapping_error(mmc_dev(host->mmc), host->adma_addr))
453 BUG_ON(host->adma_addr & 0x3);
458 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
459 data->sg_len, direction);
461 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
467 static void sdhci_adma_table_post(struct sdhci_host *host,
468 struct mmc_data *data)
472 struct scatterlist *sg;
478 if (data->flags & MMC_DATA_READ)
479 direction = DMA_FROM_DEVICE;
481 direction = DMA_TO_DEVICE;
483 dma_unmap_single(mmc_dev(host->mmc), host->adma_addr,
484 (128 * 2 + 1) * 4, DMA_TO_DEVICE);
486 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
489 if (data->flags & MMC_DATA_READ) {
490 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg,
491 data->sg_len, direction);
493 align = host->align_buffer;
495 for_each_sg(data->sg, sg, host->sg_count, i) {
496 if (sg_dma_address(sg) & 0x3) {
497 size = 4 - (sg_dma_address(sg) & 0x3);
499 buffer = sdhci_kmap_atomic(sg, &flags);
500 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
501 memcpy(buffer, align, size);
502 sdhci_kunmap_atomic(buffer, &flags);
509 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
510 data->sg_len, direction);
513 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
516 unsigned target_timeout, current_timeout;
519 * If the host controller provides us with an incorrect timeout
520 * value, just skip the check and use 0xE. The hardware may take
521 * longer to time out, but that's much better than having a too-short
524 if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL))
528 target_timeout = data->timeout_ns / 1000 +
529 data->timeout_clks / host->clock;
532 * Figure out needed cycles.
533 * We do this in steps in order to fit inside a 32 bit int.
534 * The first step is the minimum timeout, which will have a
535 * minimum resolution of 6 bits:
536 * (1) 2^13*1000 > 2^22,
537 * (2) host->timeout_clk < 2^16
542 current_timeout = (1 << 13) * 1000 / host->timeout_clk;
543 while (current_timeout < target_timeout) {
545 current_timeout <<= 1;
551 printk(KERN_WARNING "%s: Too large timeout requested!\n",
552 mmc_hostname(host->mmc));
559 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
571 BUG_ON(data->blksz * data->blocks > 524288);
572 BUG_ON(data->blksz > host->mmc->max_blk_size);
573 BUG_ON(data->blocks > 65535);
576 host->data_early = 0;
578 count = sdhci_calc_timeout(host, data);
579 writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL);
581 if (host->flags & SDHCI_USE_DMA)
582 host->flags |= SDHCI_REQ_USE_DMA;
585 * FIXME: This doesn't account for merging when mapping the
588 if (host->flags & SDHCI_REQ_USE_DMA) {
590 struct scatterlist *sg;
593 if (host->flags & SDHCI_USE_ADMA) {
594 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
597 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
601 if (unlikely(broken)) {
602 for_each_sg(data->sg, sg, data->sg_len, i) {
603 if (sg->length & 0x3) {
604 DBG("Reverting to PIO because of "
605 "transfer size (%d)\n",
607 host->flags &= ~SDHCI_REQ_USE_DMA;
615 * The assumption here being that alignment is the same after
616 * translation to device address space.
618 if (host->flags & SDHCI_REQ_USE_DMA) {
620 struct scatterlist *sg;
623 if (host->flags & SDHCI_USE_ADMA) {
625 * As we use 3 byte chunks to work around
626 * alignment problems, we need to check this
629 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
632 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR)
636 if (unlikely(broken)) {
637 for_each_sg(data->sg, sg, data->sg_len, i) {
638 if (sg->offset & 0x3) {
639 DBG("Reverting to PIO because of "
641 host->flags &= ~SDHCI_REQ_USE_DMA;
648 if (host->flags & SDHCI_REQ_USE_DMA) {
649 if (host->flags & SDHCI_USE_ADMA) {
650 ret = sdhci_adma_table_pre(host, data);
653 * This only happens when someone fed
654 * us an invalid request.
657 host->flags &= ~SDHCI_REQ_USE_DMA;
659 writel(host->adma_addr,
660 host->ioaddr + SDHCI_ADMA_ADDRESS);
665 sg_cnt = dma_map_sg(mmc_dev(host->mmc),
666 data->sg, data->sg_len,
667 (data->flags & MMC_DATA_READ) ?
672 * This only happens when someone fed
673 * us an invalid request.
676 host->flags &= ~SDHCI_REQ_USE_DMA;
678 WARN_ON(sg_cnt != 1);
679 writel(sg_dma_address(data->sg),
680 host->ioaddr + SDHCI_DMA_ADDRESS);
686 * Always adjust the DMA selection as some controllers
687 * (e.g. JMicron) can't do PIO properly when the selection
690 if (host->version >= SDHCI_SPEC_200) {
691 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
692 ctrl &= ~SDHCI_CTRL_DMA_MASK;
693 if ((host->flags & SDHCI_REQ_USE_DMA) &&
694 (host->flags & SDHCI_USE_ADMA))
695 ctrl |= SDHCI_CTRL_ADMA32;
697 ctrl |= SDHCI_CTRL_SDMA;
698 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
701 if (!(host->flags & SDHCI_REQ_USE_DMA)) {
702 sg_miter_start(&host->sg_miter,
703 data->sg, data->sg_len, SG_MITER_ATOMIC);
704 host->blocks = data->blocks;
707 /* We do not handle DMA boundaries, so set it to max (512 KiB) */
708 writew(SDHCI_MAKE_BLKSZ(7, data->blksz),
709 host->ioaddr + SDHCI_BLOCK_SIZE);
710 writew(data->blocks, host->ioaddr + SDHCI_BLOCK_COUNT);
713 static void sdhci_set_transfer_mode(struct sdhci_host *host,
714 struct mmc_data *data)
721 WARN_ON(!host->data);
723 mode = SDHCI_TRNS_BLK_CNT_EN;
724 if (data->blocks > 1)
725 mode |= SDHCI_TRNS_MULTI;
726 if (data->flags & MMC_DATA_READ)
727 mode |= SDHCI_TRNS_READ;
728 if (host->flags & SDHCI_REQ_USE_DMA)
729 mode |= SDHCI_TRNS_DMA;
731 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE);
734 static void sdhci_finish_data(struct sdhci_host *host)
736 struct mmc_data *data;
743 if (host->flags & SDHCI_REQ_USE_DMA) {
744 if (host->flags & SDHCI_USE_ADMA)
745 sdhci_adma_table_post(host, data);
747 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
748 data->sg_len, (data->flags & MMC_DATA_READ) ?
749 DMA_FROM_DEVICE : DMA_TO_DEVICE);
754 * The specification states that the block count register must
755 * be updated, but it does not specify at what point in the
756 * data flow. That makes the register entirely useless to read
757 * back so we have to assume that nothing made it to the card
758 * in the event of an error.
761 data->bytes_xfered = 0;
763 data->bytes_xfered = data->blksz * data->blocks;
767 * The controller needs a reset of internal state machines
768 * upon error conditions.
771 sdhci_reset(host, SDHCI_RESET_CMD);
772 sdhci_reset(host, SDHCI_RESET_DATA);
775 sdhci_send_command(host, data->stop);
777 tasklet_schedule(&host->finish_tasklet);
780 static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
784 unsigned long timeout;
791 mask = SDHCI_CMD_INHIBIT;
792 if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
793 mask |= SDHCI_DATA_INHIBIT;
795 /* We shouldn't wait for data inihibit for stop commands, even
796 though they might use busy signaling */
797 if (host->mrq->data && (cmd == host->mrq->data->stop))
798 mask &= ~SDHCI_DATA_INHIBIT;
800 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
802 printk(KERN_ERR "%s: Controller never released "
803 "inhibit bit(s).\n", mmc_hostname(host->mmc));
804 sdhci_dumpregs(host);
806 tasklet_schedule(&host->finish_tasklet);
813 mod_timer(&host->timer, jiffies + 10 * HZ);
817 sdhci_prepare_data(host, cmd->data);
819 writel(cmd->arg, host->ioaddr + SDHCI_ARGUMENT);
821 sdhci_set_transfer_mode(host, cmd->data);
823 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
824 printk(KERN_ERR "%s: Unsupported response type!\n",
825 mmc_hostname(host->mmc));
826 cmd->error = -EINVAL;
827 tasklet_schedule(&host->finish_tasklet);
831 if (!(cmd->flags & MMC_RSP_PRESENT))
832 flags = SDHCI_CMD_RESP_NONE;
833 else if (cmd->flags & MMC_RSP_136)
834 flags = SDHCI_CMD_RESP_LONG;
835 else if (cmd->flags & MMC_RSP_BUSY)
836 flags = SDHCI_CMD_RESP_SHORT_BUSY;
838 flags = SDHCI_CMD_RESP_SHORT;
840 if (cmd->flags & MMC_RSP_CRC)
841 flags |= SDHCI_CMD_CRC;
842 if (cmd->flags & MMC_RSP_OPCODE)
843 flags |= SDHCI_CMD_INDEX;
845 flags |= SDHCI_CMD_DATA;
847 writew(SDHCI_MAKE_CMD(cmd->opcode, flags),
848 host->ioaddr + SDHCI_COMMAND);
851 static void sdhci_finish_command(struct sdhci_host *host)
855 BUG_ON(host->cmd == NULL);
857 if (host->cmd->flags & MMC_RSP_PRESENT) {
858 if (host->cmd->flags & MMC_RSP_136) {
859 /* CRC is stripped so we need to do some shifting. */
860 for (i = 0;i < 4;i++) {
861 host->cmd->resp[i] = readl(host->ioaddr +
862 SDHCI_RESPONSE + (3-i)*4) << 8;
864 host->cmd->resp[i] |=
866 SDHCI_RESPONSE + (3-i)*4-1);
869 host->cmd->resp[0] = readl(host->ioaddr + SDHCI_RESPONSE);
873 host->cmd->error = 0;
875 if (host->data && host->data_early)
876 sdhci_finish_data(host);
878 if (!host->cmd->data)
879 tasklet_schedule(&host->finish_tasklet);
884 static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
888 unsigned long timeout;
890 if (clock == host->clock)
893 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
898 for (div = 1;div < 256;div *= 2) {
899 if ((host->max_clk / div) <= clock)
904 clk = div << SDHCI_DIVIDER_SHIFT;
905 clk |= SDHCI_CLOCK_INT_EN;
906 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
910 while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL))
911 & SDHCI_CLOCK_INT_STABLE)) {
913 printk(KERN_ERR "%s: Internal clock never "
914 "stabilised.\n", mmc_hostname(host->mmc));
915 sdhci_dumpregs(host);
922 clk |= SDHCI_CLOCK_CARD_EN;
923 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
929 static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
933 if (host->power == power)
936 if (power == (unsigned short)-1) {
937 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
942 * Spec says that we should clear the power reg before setting
943 * a new value. Some controllers don't seem to like this though.
945 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE))
946 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
948 pwr = SDHCI_POWER_ON;
950 switch (1 << power) {
951 case MMC_VDD_165_195:
952 pwr |= SDHCI_POWER_180;
956 pwr |= SDHCI_POWER_300;
960 pwr |= SDHCI_POWER_330;
967 * At least the Marvell CaFe chip gets confused if we set the voltage
968 * and set turn on power at the same time, so set the voltage first.
970 if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
971 writeb(pwr & ~SDHCI_POWER_ON,
972 host->ioaddr + SDHCI_POWER_CONTROL);
974 writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL);
980 /*****************************************************************************\
984 \*****************************************************************************/
986 static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
988 struct sdhci_host *host;
991 host = mmc_priv(mmc);
993 spin_lock_irqsave(&host->lock, flags);
995 WARN_ON(host->mrq != NULL);
997 #ifndef CONFIG_LEDS_CLASS
998 sdhci_activate_led(host);
1003 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)
1004 || (host->flags & SDHCI_DEVICE_DEAD)) {
1005 host->mrq->cmd->error = -ENOMEDIUM;
1006 tasklet_schedule(&host->finish_tasklet);
1008 sdhci_send_command(host, mrq->cmd);
1011 spin_unlock_irqrestore(&host->lock, flags);
1014 static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1016 struct sdhci_host *host;
1017 unsigned long flags;
1020 host = mmc_priv(mmc);
1022 spin_lock_irqsave(&host->lock, flags);
1024 if (host->flags & SDHCI_DEVICE_DEAD)
1028 * Reset the chip on each power off.
1029 * Should clear out any weird states.
1031 if (ios->power_mode == MMC_POWER_OFF) {
1032 writel(0, host->ioaddr + SDHCI_SIGNAL_ENABLE);
1036 sdhci_set_clock(host, ios->clock);
1038 if (ios->power_mode == MMC_POWER_OFF)
1039 sdhci_set_power(host, -1);
1041 sdhci_set_power(host, ios->vdd);
1043 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
1045 if (ios->bus_width == MMC_BUS_WIDTH_4)
1046 ctrl |= SDHCI_CTRL_4BITBUS;
1048 ctrl &= ~SDHCI_CTRL_4BITBUS;
1050 if (ios->timing == MMC_TIMING_SD_HS)
1051 ctrl |= SDHCI_CTRL_HISPD;
1053 ctrl &= ~SDHCI_CTRL_HISPD;
1055 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
1058 * Some (ENE) controllers go apeshit on some ios operation,
1059 * signalling timeout and CRC errors even on CMD0. Resetting
1060 * it on each ios seems to solve the problem.
1062 if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
1063 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
1067 spin_unlock_irqrestore(&host->lock, flags);
1070 static int sdhci_get_ro(struct mmc_host *mmc)
1072 struct sdhci_host *host;
1073 unsigned long flags;
1076 host = mmc_priv(mmc);
1078 spin_lock_irqsave(&host->lock, flags);
1080 if (host->flags & SDHCI_DEVICE_DEAD)
1083 present = readl(host->ioaddr + SDHCI_PRESENT_STATE);
1085 spin_unlock_irqrestore(&host->lock, flags);
1087 return !(present & SDHCI_WRITE_PROTECT);
1090 static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1092 struct sdhci_host *host;
1093 unsigned long flags;
1096 host = mmc_priv(mmc);
1098 spin_lock_irqsave(&host->lock, flags);
1100 if (host->flags & SDHCI_DEVICE_DEAD)
1103 ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
1105 ier &= ~SDHCI_INT_CARD_INT;
1107 ier |= SDHCI_INT_CARD_INT;
1109 writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
1110 writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
1115 spin_unlock_irqrestore(&host->lock, flags);
1118 static const struct mmc_host_ops sdhci_ops = {
1119 .request = sdhci_request,
1120 .set_ios = sdhci_set_ios,
1121 .get_ro = sdhci_get_ro,
1122 .enable_sdio_irq = sdhci_enable_sdio_irq,
1125 /*****************************************************************************\
1129 \*****************************************************************************/
1131 static void sdhci_tasklet_card(unsigned long param)
1133 struct sdhci_host *host;
1134 unsigned long flags;
1136 host = (struct sdhci_host*)param;
1138 spin_lock_irqsave(&host->lock, flags);
1140 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
1142 printk(KERN_ERR "%s: Card removed during transfer!\n",
1143 mmc_hostname(host->mmc));
1144 printk(KERN_ERR "%s: Resetting controller.\n",
1145 mmc_hostname(host->mmc));
1147 sdhci_reset(host, SDHCI_RESET_CMD);
1148 sdhci_reset(host, SDHCI_RESET_DATA);
1150 host->mrq->cmd->error = -ENOMEDIUM;
1151 tasklet_schedule(&host->finish_tasklet);
1155 spin_unlock_irqrestore(&host->lock, flags);
1157 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
1160 static void sdhci_tasklet_finish(unsigned long param)
1162 struct sdhci_host *host;
1163 unsigned long flags;
1164 struct mmc_request *mrq;
1166 host = (struct sdhci_host*)param;
1168 spin_lock_irqsave(&host->lock, flags);
1170 del_timer(&host->timer);
1175 * The controller needs a reset of internal state machines
1176 * upon error conditions.
1178 if (!(host->flags & SDHCI_DEVICE_DEAD) &&
1180 (mrq->data && (mrq->data->error ||
1181 (mrq->data->stop && mrq->data->stop->error))) ||
1182 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) {
1184 /* Some controllers need this kick or reset won't work here */
1185 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
1188 /* This is to force an update */
1189 clock = host->clock;
1191 sdhci_set_clock(host, clock);
1194 /* Spec says we should do both at the same time, but Ricoh
1195 controllers do not like that. */
1196 sdhci_reset(host, SDHCI_RESET_CMD);
1197 sdhci_reset(host, SDHCI_RESET_DATA);
1204 #ifndef CONFIG_LEDS_CLASS
1205 sdhci_deactivate_led(host);
1209 spin_unlock_irqrestore(&host->lock, flags);
1211 mmc_request_done(host->mmc, mrq);
1214 static void sdhci_timeout_timer(unsigned long data)
1216 struct sdhci_host *host;
1217 unsigned long flags;
1219 host = (struct sdhci_host*)data;
1221 spin_lock_irqsave(&host->lock, flags);
1224 printk(KERN_ERR "%s: Timeout waiting for hardware "
1225 "interrupt.\n", mmc_hostname(host->mmc));
1226 sdhci_dumpregs(host);
1229 host->data->error = -ETIMEDOUT;
1230 sdhci_finish_data(host);
1233 host->cmd->error = -ETIMEDOUT;
1235 host->mrq->cmd->error = -ETIMEDOUT;
1237 tasklet_schedule(&host->finish_tasklet);
1242 spin_unlock_irqrestore(&host->lock, flags);
1245 /*****************************************************************************\
1247 * Interrupt handling *
1249 \*****************************************************************************/
1251 static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
1253 BUG_ON(intmask == 0);
1256 printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
1257 "though no command operation was in progress.\n",
1258 mmc_hostname(host->mmc), (unsigned)intmask);
1259 sdhci_dumpregs(host);
1263 if (intmask & SDHCI_INT_TIMEOUT)
1264 host->cmd->error = -ETIMEDOUT;
1265 else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
1267 host->cmd->error = -EILSEQ;
1269 if (host->cmd->error) {
1270 tasklet_schedule(&host->finish_tasklet);
1275 * The host can send and interrupt when the busy state has
1276 * ended, allowing us to wait without wasting CPU cycles.
1277 * Unfortunately this is overloaded on the "data complete"
1278 * interrupt, so we need to take some care when handling
1281 * Note: The 1.0 specification is a bit ambiguous about this
1282 * feature so there might be some problems with older
1285 if (host->cmd->flags & MMC_RSP_BUSY) {
1286 if (host->cmd->data)
1287 DBG("Cannot wait for busy signal when also "
1288 "doing a data transfer");
1293 if (intmask & SDHCI_INT_RESPONSE)
1294 sdhci_finish_command(host);
1297 static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
1299 BUG_ON(intmask == 0);
1303 * The "data complete" interrupt is also used to
1304 * indicate that a busy state has ended. See comment
1305 * above in sdhci_cmd_irq().
1307 if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
1308 if (intmask & SDHCI_INT_DATA_END) {
1309 sdhci_finish_command(host);
1314 printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
1315 "though no data operation was in progress.\n",
1316 mmc_hostname(host->mmc), (unsigned)intmask);
1317 sdhci_dumpregs(host);
1322 if (intmask & SDHCI_INT_DATA_TIMEOUT)
1323 host->data->error = -ETIMEDOUT;
1324 else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
1325 host->data->error = -EILSEQ;
1326 else if (intmask & SDHCI_INT_ADMA_ERROR)
1327 host->data->error = -EIO;
1329 if (host->data->error)
1330 sdhci_finish_data(host);
1332 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
1333 sdhci_transfer_pio(host);
1336 * We currently don't do anything fancy with DMA
1337 * boundaries, but as we can't disable the feature
1338 * we need to at least restart the transfer.
1340 if (intmask & SDHCI_INT_DMA_END)
1341 writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS),
1342 host->ioaddr + SDHCI_DMA_ADDRESS);
1344 if (intmask & SDHCI_INT_DATA_END) {
1347 * Data managed to finish before the
1348 * command completed. Make sure we do
1349 * things in the proper order.
1351 host->data_early = 1;
1353 sdhci_finish_data(host);
1359 static irqreturn_t sdhci_irq(int irq, void *dev_id)
1362 struct sdhci_host* host = dev_id;
1366 spin_lock(&host->lock);
1368 intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
1370 if (!intmask || intmask == 0xffffffff) {
1375 DBG("*** %s got interrupt: 0x%08x\n",
1376 mmc_hostname(host->mmc), intmask);
1378 if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
1379 writel(intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE),
1380 host->ioaddr + SDHCI_INT_STATUS);
1381 tasklet_schedule(&host->card_tasklet);
1384 intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
1386 if (intmask & SDHCI_INT_CMD_MASK) {
1387 writel(intmask & SDHCI_INT_CMD_MASK,
1388 host->ioaddr + SDHCI_INT_STATUS);
1389 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
1392 if (intmask & SDHCI_INT_DATA_MASK) {
1393 writel(intmask & SDHCI_INT_DATA_MASK,
1394 host->ioaddr + SDHCI_INT_STATUS);
1395 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
1398 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
1400 intmask &= ~SDHCI_INT_ERROR;
1402 if (intmask & SDHCI_INT_BUS_POWER) {
1403 printk(KERN_ERR "%s: Card is consuming too much power!\n",
1404 mmc_hostname(host->mmc));
1405 writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS);
1408 intmask &= ~SDHCI_INT_BUS_POWER;
1410 if (intmask & SDHCI_INT_CARD_INT)
1413 intmask &= ~SDHCI_INT_CARD_INT;
1416 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
1417 mmc_hostname(host->mmc), intmask);
1418 sdhci_dumpregs(host);
1420 writel(intmask, host->ioaddr + SDHCI_INT_STATUS);
1423 result = IRQ_HANDLED;
1427 spin_unlock(&host->lock);
1430 * We have to delay this as it calls back into the driver.
1433 mmc_signal_sdio_irq(host->mmc);
1438 /*****************************************************************************\
1442 \*****************************************************************************/
1446 int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
1450 ret = mmc_suspend_host(host->mmc, state);
1454 free_irq(host->irq, host);
1459 EXPORT_SYMBOL_GPL(sdhci_suspend_host);
1461 int sdhci_resume_host(struct sdhci_host *host)
1465 if (host->flags & SDHCI_USE_DMA) {
1466 if (host->ops->enable_dma)
1467 host->ops->enable_dma(host);
1470 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
1471 mmc_hostname(host->mmc), host);
1478 ret = mmc_resume_host(host->mmc);
1485 EXPORT_SYMBOL_GPL(sdhci_resume_host);
1487 #endif /* CONFIG_PM */
1489 /*****************************************************************************\
1491 * Device allocation/registration *
1493 \*****************************************************************************/
1495 struct sdhci_host *sdhci_alloc_host(struct device *dev,
1498 struct mmc_host *mmc;
1499 struct sdhci_host *host;
1501 WARN_ON(dev == NULL);
1503 mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev);
1505 return ERR_PTR(-ENOMEM);
1507 host = mmc_priv(mmc);
1513 EXPORT_SYMBOL_GPL(sdhci_alloc_host);
1515 int sdhci_add_host(struct sdhci_host *host)
1517 struct mmc_host *mmc;
1521 WARN_ON(host == NULL);
1528 host->quirks = debug_quirks;
1530 sdhci_reset(host, SDHCI_RESET_ALL);
1532 host->version = readw(host->ioaddr + SDHCI_HOST_VERSION);
1533 host->version = (host->version & SDHCI_SPEC_VER_MASK)
1534 >> SDHCI_SPEC_VER_SHIFT;
1535 if (host->version > SDHCI_SPEC_200) {
1536 printk(KERN_ERR "%s: Unknown controller version (%d). "
1537 "You may experience problems.\n", mmc_hostname(mmc),
1541 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
1543 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
1544 host->flags |= SDHCI_USE_DMA;
1545 else if (!(caps & SDHCI_CAN_DO_DMA))
1546 DBG("Controller doesn't have DMA capability\n");
1548 host->flags |= SDHCI_USE_DMA;
1550 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
1551 (host->flags & SDHCI_USE_DMA)) {
1552 DBG("Disabling DMA as it is marked broken\n");
1553 host->flags &= ~SDHCI_USE_DMA;
1556 if (host->flags & SDHCI_USE_DMA) {
1557 if ((host->version >= SDHCI_SPEC_200) &&
1558 (caps & SDHCI_CAN_DO_ADMA2))
1559 host->flags |= SDHCI_USE_ADMA;
1562 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
1563 (host->flags & SDHCI_USE_ADMA)) {
1564 DBG("Disabling ADMA as it is marked broken\n");
1565 host->flags &= ~SDHCI_USE_ADMA;
1568 if (host->flags & SDHCI_USE_DMA) {
1569 if (host->ops->enable_dma) {
1570 if (host->ops->enable_dma(host)) {
1571 printk(KERN_WARNING "%s: No suitable DMA "
1572 "available. Falling back to PIO.\n",
1574 host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA);
1579 if (host->flags & SDHCI_USE_ADMA) {
1581 * We need to allocate descriptors for all sg entries
1582 * (128) and potentially one alignment transfer for
1583 * each of those entries.
1585 host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL);
1586 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL);
1587 if (!host->adma_desc || !host->align_buffer) {
1588 kfree(host->adma_desc);
1589 kfree(host->align_buffer);
1590 printk(KERN_WARNING "%s: Unable to allocate ADMA "
1591 "buffers. Falling back to standard DMA.\n",
1593 host->flags &= ~SDHCI_USE_ADMA;
1598 * If we use DMA, then it's up to the caller to set the DMA
1599 * mask, but PIO does not need the hw shim so we set a new
1600 * mask here in that case.
1602 if (!(host->flags & SDHCI_USE_DMA)) {
1603 host->dma_mask = DMA_BIT_MASK(64);
1604 mmc_dev(host->mmc)->dma_mask = &host->dma_mask;
1608 (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
1609 if (host->max_clk == 0) {
1610 printk(KERN_ERR "%s: Hardware doesn't specify base clock "
1611 "frequency.\n", mmc_hostname(mmc));
1614 host->max_clk *= 1000000;
1617 (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
1618 if (host->timeout_clk == 0) {
1619 printk(KERN_ERR "%s: Hardware doesn't specify timeout clock "
1620 "frequency.\n", mmc_hostname(mmc));
1623 if (caps & SDHCI_TIMEOUT_CLK_UNIT)
1624 host->timeout_clk *= 1000;
1627 * Set host parameters.
1629 mmc->ops = &sdhci_ops;
1630 mmc->f_min = host->max_clk / 256;
1631 mmc->f_max = host->max_clk;
1632 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
1634 if ((caps & SDHCI_CAN_DO_HISPD) ||
1635 (host->quirks & SDHCI_QUIRK_FORCE_HIGHSPEED))
1636 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1639 if (caps & SDHCI_CAN_VDD_330)
1640 mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34;
1641 if (caps & SDHCI_CAN_VDD_300)
1642 mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31;
1643 if (caps & SDHCI_CAN_VDD_180)
1644 mmc->ocr_avail |= MMC_VDD_165_195;
1646 if (mmc->ocr_avail == 0) {
1647 printk(KERN_ERR "%s: Hardware doesn't report any "
1648 "support voltages.\n", mmc_hostname(mmc));
1652 spin_lock_init(&host->lock);
1655 * Maximum number of segments. Depends on if the hardware
1656 * can do scatter/gather or not.
1658 if (host->flags & SDHCI_USE_ADMA)
1659 mmc->max_hw_segs = 128;
1660 else if (host->flags & SDHCI_USE_DMA)
1661 mmc->max_hw_segs = 1;
1663 mmc->max_hw_segs = 128;
1664 mmc->max_phys_segs = 128;
1667 * Maximum number of sectors in one transfer. Limited by DMA boundary
1670 mmc->max_req_size = 524288;
1673 * Maximum segment size. Could be one segment with the maximum number
1674 * of bytes. When doing hardware scatter/gather, each entry cannot
1675 * be larger than 64 KiB though.
1677 if (host->flags & SDHCI_USE_ADMA)
1678 mmc->max_seg_size = 65536;
1680 mmc->max_seg_size = mmc->max_req_size;
1683 * Maximum block size. This varies from controller to controller and
1684 * is specified in the capabilities register.
1686 mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> SDHCI_MAX_BLOCK_SHIFT;
1687 if (mmc->max_blk_size >= 3) {
1688 printk(KERN_WARNING "%s: Invalid maximum block size, "
1689 "assuming 512 bytes\n", mmc_hostname(mmc));
1690 mmc->max_blk_size = 512;
1692 mmc->max_blk_size = 512 << mmc->max_blk_size;
1695 * Maximum block count.
1697 mmc->max_blk_count = 65535;
1702 tasklet_init(&host->card_tasklet,
1703 sdhci_tasklet_card, (unsigned long)host);
1704 tasklet_init(&host->finish_tasklet,
1705 sdhci_tasklet_finish, (unsigned long)host);
1707 setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
1709 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
1710 mmc_hostname(mmc), host);
1716 #ifdef CONFIG_MMC_DEBUG
1717 sdhci_dumpregs(host);
1720 #ifdef CONFIG_LEDS_CLASS
1721 host->led.name = mmc_hostname(mmc);
1722 host->led.brightness = LED_OFF;
1723 host->led.default_trigger = mmc_hostname(mmc);
1724 host->led.brightness_set = sdhci_led_control;
1726 ret = led_classdev_register(mmc_dev(mmc), &host->led);
1735 printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n",
1736 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
1737 (host->flags & SDHCI_USE_ADMA)?"A":"",
1738 (host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
1742 #ifdef CONFIG_LEDS_CLASS
1744 sdhci_reset(host, SDHCI_RESET_ALL);
1745 free_irq(host->irq, host);
1748 tasklet_kill(&host->card_tasklet);
1749 tasklet_kill(&host->finish_tasklet);
1754 EXPORT_SYMBOL_GPL(sdhci_add_host);
1756 void sdhci_remove_host(struct sdhci_host *host, int dead)
1758 unsigned long flags;
1761 spin_lock_irqsave(&host->lock, flags);
1763 host->flags |= SDHCI_DEVICE_DEAD;
1766 printk(KERN_ERR "%s: Controller removed during "
1767 " transfer!\n", mmc_hostname(host->mmc));
1769 host->mrq->cmd->error = -ENOMEDIUM;
1770 tasklet_schedule(&host->finish_tasklet);
1773 spin_unlock_irqrestore(&host->lock, flags);
1776 mmc_remove_host(host->mmc);
1778 #ifdef CONFIG_LEDS_CLASS
1779 led_classdev_unregister(&host->led);
1783 sdhci_reset(host, SDHCI_RESET_ALL);
1785 free_irq(host->irq, host);
1787 del_timer_sync(&host->timer);
1789 tasklet_kill(&host->card_tasklet);
1790 tasklet_kill(&host->finish_tasklet);
1792 kfree(host->adma_desc);
1793 kfree(host->align_buffer);
1795 host->adma_desc = NULL;
1796 host->align_buffer = NULL;
1799 EXPORT_SYMBOL_GPL(sdhci_remove_host);
1801 void sdhci_free_host(struct sdhci_host *host)
1803 mmc_free_host(host->mmc);
1806 EXPORT_SYMBOL_GPL(sdhci_free_host);
1808 /*****************************************************************************\
1810 * Driver init/exit *
1812 \*****************************************************************************/
1814 static int __init sdhci_drv_init(void)
1816 printk(KERN_INFO DRIVER_NAME
1817 ": Secure Digital Host Controller Interface driver\n");
1818 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1823 static void __exit sdhci_drv_exit(void)
1827 module_init(sdhci_drv_init);
1828 module_exit(sdhci_drv_exit);
1830 module_param(debug_quirks, uint, 0444);
1832 MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
1833 MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
1834 MODULE_LICENSE("GPL");
1836 MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");