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 inline char* sdhci_sg_to_buffer(struct sdhci_host* host)
178 return sg_virt(host->cur_sg);
181 static inline int sdhci_next_sg(struct sdhci_host* host)
184 * Skip to next SG entry.
192 if (host->num_sg > 0) {
194 host->remain = host->cur_sg->length;
200 static void sdhci_read_block_pio(struct sdhci_host *host)
202 int blksize, chunk_remain;
207 DBG("PIO reading\n");
209 blksize = host->data->blksz;
213 buffer = sdhci_sg_to_buffer(host) + host->offset;
216 if (chunk_remain == 0) {
217 data = readl(host->ioaddr + SDHCI_BUFFER);
218 chunk_remain = min(blksize, 4);
221 size = min(host->remain, chunk_remain);
223 chunk_remain -= size;
225 host->offset += size;
226 host->remain -= size;
229 *buffer = data & 0xFF;
235 if (host->remain == 0) {
236 if (sdhci_next_sg(host) == 0) {
237 BUG_ON(blksize != 0);
240 buffer = sdhci_sg_to_buffer(host);
245 static void sdhci_write_block_pio(struct sdhci_host *host)
247 int blksize, chunk_remain;
252 DBG("PIO writing\n");
254 blksize = host->data->blksz;
259 buffer = sdhci_sg_to_buffer(host) + host->offset;
262 size = min(host->remain, chunk_remain);
264 chunk_remain -= size;
266 host->offset += size;
267 host->remain -= size;
271 data |= (u32)*buffer << 24;
276 if (chunk_remain == 0) {
277 writel(data, host->ioaddr + SDHCI_BUFFER);
278 chunk_remain = min(blksize, 4);
281 if (host->remain == 0) {
282 if (sdhci_next_sg(host) == 0) {
283 BUG_ON(blksize != 0);
286 buffer = sdhci_sg_to_buffer(host);
291 static void sdhci_transfer_pio(struct sdhci_host *host)
297 if (host->num_sg == 0)
300 if (host->data->flags & MMC_DATA_READ)
301 mask = SDHCI_DATA_AVAILABLE;
303 mask = SDHCI_SPACE_AVAILABLE;
305 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
306 if (host->data->flags & MMC_DATA_READ)
307 sdhci_read_block_pio(host);
309 sdhci_write_block_pio(host);
311 if (host->num_sg == 0)
315 DBG("PIO transfer complete.\n");
318 static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
320 local_irq_save(*flags);
321 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
324 static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
326 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
327 local_irq_restore(*flags);
330 static int sdhci_adma_table_pre(struct sdhci_host *host,
331 struct mmc_data *data)
338 dma_addr_t align_addr;
341 struct scatterlist *sg;
347 * The spec does not specify endianness of descriptor table.
348 * We currently guess that it is LE.
351 if (data->flags & MMC_DATA_READ)
352 direction = DMA_FROM_DEVICE;
354 direction = DMA_TO_DEVICE;
357 * The ADMA descriptor table is mapped further down as we
358 * need to fill it with data first.
361 host->align_addr = dma_map_single(mmc_dev(host->mmc),
362 host->align_buffer, 128 * 4, direction);
363 if (dma_mapping_error(host->align_addr))
365 BUG_ON(host->align_addr & 0x3);
367 host->sg_count = dma_map_sg(mmc_dev(host->mmc),
368 data->sg, data->sg_len, direction);
369 if (host->sg_count == 0)
372 desc = host->adma_desc;
373 align = host->align_buffer;
375 align_addr = host->align_addr;
377 for_each_sg(data->sg, sg, host->sg_count, i) {
378 addr = sg_dma_address(sg);
379 len = sg_dma_len(sg);
382 * The SDHCI specification states that ADMA
383 * addresses must be 32-bit aligned. If they
384 * aren't, then we use a bounce buffer for
385 * the (up to three) bytes that screw up the
388 offset = (4 - (addr & 0x3)) & 0x3;
390 if (data->flags & MMC_DATA_WRITE) {
391 buffer = sdhci_kmap_atomic(sg, &flags);
392 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
393 memcpy(align, buffer, offset);
394 sdhci_kunmap_atomic(buffer, &flags);
397 desc[7] = (align_addr >> 24) & 0xff;
398 desc[6] = (align_addr >> 16) & 0xff;
399 desc[5] = (align_addr >> 8) & 0xff;
400 desc[4] = (align_addr >> 0) & 0xff;
402 BUG_ON(offset > 65536);
404 desc[3] = (offset >> 8) & 0xff;
405 desc[2] = (offset >> 0) & 0xff;
408 desc[0] = 0x21; /* tran, valid */
419 desc[7] = (addr >> 24) & 0xff;
420 desc[6] = (addr >> 16) & 0xff;
421 desc[5] = (addr >> 8) & 0xff;
422 desc[4] = (addr >> 0) & 0xff;
426 desc[3] = (len >> 8) & 0xff;
427 desc[2] = (len >> 0) & 0xff;
430 desc[0] = 0x21; /* tran, valid */
435 * If this triggers then we have a calculation bug
438 WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4);
442 * Add a terminating entry.
453 desc[0] = 0x03; /* nop, end, valid */
456 * Resync align buffer as we might have changed it.
458 if (data->flags & MMC_DATA_WRITE) {
459 dma_sync_single_for_device(mmc_dev(host->mmc),
460 host->align_addr, 128 * 4, direction);
463 host->adma_addr = dma_map_single(mmc_dev(host->mmc),
464 host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE);
465 if (dma_mapping_error(host->align_addr))
467 BUG_ON(host->adma_addr & 0x3);
472 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
473 data->sg_len, direction);
475 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
481 static void sdhci_adma_table_post(struct sdhci_host *host,
482 struct mmc_data *data)
486 struct scatterlist *sg;
492 if (data->flags & MMC_DATA_READ)
493 direction = DMA_FROM_DEVICE;
495 direction = DMA_TO_DEVICE;
497 dma_unmap_single(mmc_dev(host->mmc), host->adma_addr,
498 (128 * 2 + 1) * 4, DMA_TO_DEVICE);
500 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
503 if (data->flags & MMC_DATA_READ) {
504 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg,
505 data->sg_len, direction);
507 align = host->align_buffer;
509 for_each_sg(data->sg, sg, host->sg_count, i) {
510 if (sg_dma_address(sg) & 0x3) {
511 size = 4 - (sg_dma_address(sg) & 0x3);
513 buffer = sdhci_kmap_atomic(sg, &flags);
514 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
515 memcpy(buffer, align, size);
516 sdhci_kunmap_atomic(buffer, &flags);
523 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
524 data->sg_len, direction);
527 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
530 unsigned target_timeout, current_timeout;
533 * If the host controller provides us with an incorrect timeout
534 * value, just skip the check and use 0xE. The hardware may take
535 * longer to time out, but that's much better than having a too-short
538 if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL))
542 target_timeout = data->timeout_ns / 1000 +
543 data->timeout_clks / host->clock;
546 * Figure out needed cycles.
547 * We do this in steps in order to fit inside a 32 bit int.
548 * The first step is the minimum timeout, which will have a
549 * minimum resolution of 6 bits:
550 * (1) 2^13*1000 > 2^22,
551 * (2) host->timeout_clk < 2^16
556 current_timeout = (1 << 13) * 1000 / host->timeout_clk;
557 while (current_timeout < target_timeout) {
559 current_timeout <<= 1;
565 printk(KERN_WARNING "%s: Too large timeout requested!\n",
566 mmc_hostname(host->mmc));
573 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
585 BUG_ON(data->blksz * data->blocks > 524288);
586 BUG_ON(data->blksz > host->mmc->max_blk_size);
587 BUG_ON(data->blocks > 65535);
590 host->data_early = 0;
592 count = sdhci_calc_timeout(host, data);
593 writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL);
595 if (host->flags & SDHCI_USE_DMA)
596 host->flags |= SDHCI_REQ_USE_DMA;
599 * FIXME: This doesn't account for merging when mapping the
602 if (host->flags & SDHCI_REQ_USE_DMA) {
604 struct scatterlist *sg;
607 if (host->flags & SDHCI_USE_ADMA) {
608 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
611 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
615 if (unlikely(broken)) {
616 for_each_sg(data->sg, sg, data->sg_len, i) {
617 if (sg->length & 0x3) {
618 DBG("Reverting to PIO because of "
619 "transfer size (%d)\n",
621 host->flags &= ~SDHCI_REQ_USE_DMA;
629 * The assumption here being that alignment is the same after
630 * translation to device address space.
632 if (host->flags & SDHCI_REQ_USE_DMA) {
634 struct scatterlist *sg;
637 if (host->flags & SDHCI_USE_ADMA) {
639 * As we use 3 byte chunks to work around
640 * alignment problems, we need to check this
643 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
646 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR)
650 if (unlikely(broken)) {
651 for_each_sg(data->sg, sg, data->sg_len, i) {
652 if (sg->offset & 0x3) {
653 DBG("Reverting to PIO because of "
655 host->flags &= ~SDHCI_REQ_USE_DMA;
662 if (host->flags & SDHCI_REQ_USE_DMA) {
663 if (host->flags & SDHCI_USE_ADMA) {
664 ret = sdhci_adma_table_pre(host, data);
667 * This only happens when someone fed
668 * us an invalid request.
671 host->flags &= ~SDHCI_USE_DMA;
673 writel(host->adma_addr,
674 host->ioaddr + SDHCI_ADMA_ADDRESS);
679 sg_cnt = dma_map_sg(mmc_dev(host->mmc),
680 data->sg, data->sg_len,
681 (data->flags & MMC_DATA_READ) ?
686 * This only happens when someone fed
687 * us an invalid request.
690 host->flags &= ~SDHCI_USE_DMA;
693 writel(sg_dma_address(data->sg),
694 host->ioaddr + SDHCI_DMA_ADDRESS);
700 * Always adjust the DMA selection as some controllers
701 * (e.g. JMicron) can't do PIO properly when the selection
704 if (host->version >= SDHCI_SPEC_200) {
705 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
706 ctrl &= ~SDHCI_CTRL_DMA_MASK;
707 if ((host->flags & SDHCI_REQ_USE_DMA) &&
708 (host->flags & SDHCI_USE_ADMA))
709 ctrl |= SDHCI_CTRL_ADMA32;
711 ctrl |= SDHCI_CTRL_SDMA;
712 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
715 if (!(host->flags & SDHCI_REQ_USE_DMA)) {
716 host->cur_sg = data->sg;
717 host->num_sg = data->sg_len;
720 host->remain = host->cur_sg->length;
723 /* We do not handle DMA boundaries, so set it to max (512 KiB) */
724 writew(SDHCI_MAKE_BLKSZ(7, data->blksz),
725 host->ioaddr + SDHCI_BLOCK_SIZE);
726 writew(data->blocks, host->ioaddr + SDHCI_BLOCK_COUNT);
729 static void sdhci_set_transfer_mode(struct sdhci_host *host,
730 struct mmc_data *data)
737 WARN_ON(!host->data);
739 mode = SDHCI_TRNS_BLK_CNT_EN;
740 if (data->blocks > 1)
741 mode |= SDHCI_TRNS_MULTI;
742 if (data->flags & MMC_DATA_READ)
743 mode |= SDHCI_TRNS_READ;
744 if (host->flags & SDHCI_REQ_USE_DMA)
745 mode |= SDHCI_TRNS_DMA;
747 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE);
750 static void sdhci_finish_data(struct sdhci_host *host)
752 struct mmc_data *data;
759 if (host->flags & SDHCI_REQ_USE_DMA) {
760 if (host->flags & SDHCI_USE_ADMA)
761 sdhci_adma_table_post(host, data);
763 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
764 data->sg_len, (data->flags & MMC_DATA_READ) ?
765 DMA_FROM_DEVICE : DMA_TO_DEVICE);
770 * The specification states that the block count register must
771 * be updated, but it does not specify at what point in the
772 * data flow. That makes the register entirely useless to read
773 * back so we have to assume that nothing made it to the card
774 * in the event of an error.
777 data->bytes_xfered = 0;
779 data->bytes_xfered = data->blksz * data->blocks;
783 * The controller needs a reset of internal state machines
784 * upon error conditions.
787 sdhci_reset(host, SDHCI_RESET_CMD);
788 sdhci_reset(host, SDHCI_RESET_DATA);
791 sdhci_send_command(host, data->stop);
793 tasklet_schedule(&host->finish_tasklet);
796 static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
800 unsigned long timeout;
807 mask = SDHCI_CMD_INHIBIT;
808 if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
809 mask |= SDHCI_DATA_INHIBIT;
811 /* We shouldn't wait for data inihibit for stop commands, even
812 though they might use busy signaling */
813 if (host->mrq->data && (cmd == host->mrq->data->stop))
814 mask &= ~SDHCI_DATA_INHIBIT;
816 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
818 printk(KERN_ERR "%s: Controller never released "
819 "inhibit bit(s).\n", mmc_hostname(host->mmc));
820 sdhci_dumpregs(host);
822 tasklet_schedule(&host->finish_tasklet);
829 mod_timer(&host->timer, jiffies + 10 * HZ);
833 sdhci_prepare_data(host, cmd->data);
835 writel(cmd->arg, host->ioaddr + SDHCI_ARGUMENT);
837 sdhci_set_transfer_mode(host, cmd->data);
839 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
840 printk(KERN_ERR "%s: Unsupported response type!\n",
841 mmc_hostname(host->mmc));
842 cmd->error = -EINVAL;
843 tasklet_schedule(&host->finish_tasklet);
847 if (!(cmd->flags & MMC_RSP_PRESENT))
848 flags = SDHCI_CMD_RESP_NONE;
849 else if (cmd->flags & MMC_RSP_136)
850 flags = SDHCI_CMD_RESP_LONG;
851 else if (cmd->flags & MMC_RSP_BUSY)
852 flags = SDHCI_CMD_RESP_SHORT_BUSY;
854 flags = SDHCI_CMD_RESP_SHORT;
856 if (cmd->flags & MMC_RSP_CRC)
857 flags |= SDHCI_CMD_CRC;
858 if (cmd->flags & MMC_RSP_OPCODE)
859 flags |= SDHCI_CMD_INDEX;
861 flags |= SDHCI_CMD_DATA;
863 writew(SDHCI_MAKE_CMD(cmd->opcode, flags),
864 host->ioaddr + SDHCI_COMMAND);
867 static void sdhci_finish_command(struct sdhci_host *host)
871 BUG_ON(host->cmd == NULL);
873 if (host->cmd->flags & MMC_RSP_PRESENT) {
874 if (host->cmd->flags & MMC_RSP_136) {
875 /* CRC is stripped so we need to do some shifting. */
876 for (i = 0;i < 4;i++) {
877 host->cmd->resp[i] = readl(host->ioaddr +
878 SDHCI_RESPONSE + (3-i)*4) << 8;
880 host->cmd->resp[i] |=
882 SDHCI_RESPONSE + (3-i)*4-1);
885 host->cmd->resp[0] = readl(host->ioaddr + SDHCI_RESPONSE);
889 host->cmd->error = 0;
891 if (host->data && host->data_early)
892 sdhci_finish_data(host);
894 if (!host->cmd->data)
895 tasklet_schedule(&host->finish_tasklet);
900 static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
904 unsigned long timeout;
906 if (clock == host->clock)
909 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
914 for (div = 1;div < 256;div *= 2) {
915 if ((host->max_clk / div) <= clock)
920 clk = div << SDHCI_DIVIDER_SHIFT;
921 clk |= SDHCI_CLOCK_INT_EN;
922 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
926 while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL))
927 & SDHCI_CLOCK_INT_STABLE)) {
929 printk(KERN_ERR "%s: Internal clock never "
930 "stabilised.\n", mmc_hostname(host->mmc));
931 sdhci_dumpregs(host);
938 clk |= SDHCI_CLOCK_CARD_EN;
939 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
945 static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
949 if (host->power == power)
952 if (power == (unsigned short)-1) {
953 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
958 * Spec says that we should clear the power reg before setting
959 * a new value. Some controllers don't seem to like this though.
961 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE))
962 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
964 pwr = SDHCI_POWER_ON;
966 switch (1 << power) {
967 case MMC_VDD_165_195:
968 pwr |= SDHCI_POWER_180;
972 pwr |= SDHCI_POWER_300;
976 pwr |= SDHCI_POWER_330;
983 * At least the Marvell CaFe chip gets confused if we set the voltage
984 * and set turn on power at the same time, so set the voltage first.
986 if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
987 writeb(pwr & ~SDHCI_POWER_ON,
988 host->ioaddr + SDHCI_POWER_CONTROL);
990 writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL);
996 /*****************************************************************************\
1000 \*****************************************************************************/
1002 static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1004 struct sdhci_host *host;
1005 unsigned long flags;
1007 host = mmc_priv(mmc);
1009 spin_lock_irqsave(&host->lock, flags);
1011 WARN_ON(host->mrq != NULL);
1013 #ifndef CONFIG_LEDS_CLASS
1014 sdhci_activate_led(host);
1019 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)
1020 || (host->flags & SDHCI_DEVICE_DEAD)) {
1021 host->mrq->cmd->error = -ENOMEDIUM;
1022 tasklet_schedule(&host->finish_tasklet);
1024 sdhci_send_command(host, mrq->cmd);
1027 spin_unlock_irqrestore(&host->lock, flags);
1030 static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1032 struct sdhci_host *host;
1033 unsigned long flags;
1036 host = mmc_priv(mmc);
1038 spin_lock_irqsave(&host->lock, flags);
1040 if (host->flags & SDHCI_DEVICE_DEAD)
1044 * Reset the chip on each power off.
1045 * Should clear out any weird states.
1047 if (ios->power_mode == MMC_POWER_OFF) {
1048 writel(0, host->ioaddr + SDHCI_SIGNAL_ENABLE);
1052 sdhci_set_clock(host, ios->clock);
1054 if (ios->power_mode == MMC_POWER_OFF)
1055 sdhci_set_power(host, -1);
1057 sdhci_set_power(host, ios->vdd);
1059 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
1061 if (ios->bus_width == MMC_BUS_WIDTH_4)
1062 ctrl |= SDHCI_CTRL_4BITBUS;
1064 ctrl &= ~SDHCI_CTRL_4BITBUS;
1066 if (ios->timing == MMC_TIMING_SD_HS)
1067 ctrl |= SDHCI_CTRL_HISPD;
1069 ctrl &= ~SDHCI_CTRL_HISPD;
1071 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
1074 * Some (ENE) controllers go apeshit on some ios operation,
1075 * signalling timeout and CRC errors even on CMD0. Resetting
1076 * it on each ios seems to solve the problem.
1078 if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
1079 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
1083 spin_unlock_irqrestore(&host->lock, flags);
1086 static int sdhci_get_ro(struct mmc_host *mmc)
1088 struct sdhci_host *host;
1089 unsigned long flags;
1092 host = mmc_priv(mmc);
1094 spin_lock_irqsave(&host->lock, flags);
1096 if (host->flags & SDHCI_DEVICE_DEAD)
1099 present = readl(host->ioaddr + SDHCI_PRESENT_STATE);
1101 spin_unlock_irqrestore(&host->lock, flags);
1103 return !(present & SDHCI_WRITE_PROTECT);
1106 static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1108 struct sdhci_host *host;
1109 unsigned long flags;
1112 host = mmc_priv(mmc);
1114 spin_lock_irqsave(&host->lock, flags);
1116 if (host->flags & SDHCI_DEVICE_DEAD)
1119 ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
1121 ier &= ~SDHCI_INT_CARD_INT;
1123 ier |= SDHCI_INT_CARD_INT;
1125 writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
1126 writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
1131 spin_unlock_irqrestore(&host->lock, flags);
1134 static const struct mmc_host_ops sdhci_ops = {
1135 .request = sdhci_request,
1136 .set_ios = sdhci_set_ios,
1137 .get_ro = sdhci_get_ro,
1138 .enable_sdio_irq = sdhci_enable_sdio_irq,
1141 /*****************************************************************************\
1145 \*****************************************************************************/
1147 static void sdhci_tasklet_card(unsigned long param)
1149 struct sdhci_host *host;
1150 unsigned long flags;
1152 host = (struct sdhci_host*)param;
1154 spin_lock_irqsave(&host->lock, flags);
1156 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
1158 printk(KERN_ERR "%s: Card removed during transfer!\n",
1159 mmc_hostname(host->mmc));
1160 printk(KERN_ERR "%s: Resetting controller.\n",
1161 mmc_hostname(host->mmc));
1163 sdhci_reset(host, SDHCI_RESET_CMD);
1164 sdhci_reset(host, SDHCI_RESET_DATA);
1166 host->mrq->cmd->error = -ENOMEDIUM;
1167 tasklet_schedule(&host->finish_tasklet);
1171 spin_unlock_irqrestore(&host->lock, flags);
1173 mmc_detect_change(host->mmc, msecs_to_jiffies(500));
1176 static void sdhci_tasklet_finish(unsigned long param)
1178 struct sdhci_host *host;
1179 unsigned long flags;
1180 struct mmc_request *mrq;
1182 host = (struct sdhci_host*)param;
1184 spin_lock_irqsave(&host->lock, flags);
1186 del_timer(&host->timer);
1191 * The controller needs a reset of internal state machines
1192 * upon error conditions.
1194 if (!(host->flags & SDHCI_DEVICE_DEAD) &&
1196 (mrq->data && (mrq->data->error ||
1197 (mrq->data->stop && mrq->data->stop->error))) ||
1198 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) {
1200 /* Some controllers need this kick or reset won't work here */
1201 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
1204 /* This is to force an update */
1205 clock = host->clock;
1207 sdhci_set_clock(host, clock);
1210 /* Spec says we should do both at the same time, but Ricoh
1211 controllers do not like that. */
1212 sdhci_reset(host, SDHCI_RESET_CMD);
1213 sdhci_reset(host, SDHCI_RESET_DATA);
1220 #ifndef CONFIG_LEDS_CLASS
1221 sdhci_deactivate_led(host);
1225 spin_unlock_irqrestore(&host->lock, flags);
1227 mmc_request_done(host->mmc, mrq);
1230 static void sdhci_timeout_timer(unsigned long data)
1232 struct sdhci_host *host;
1233 unsigned long flags;
1235 host = (struct sdhci_host*)data;
1237 spin_lock_irqsave(&host->lock, flags);
1240 printk(KERN_ERR "%s: Timeout waiting for hardware "
1241 "interrupt.\n", mmc_hostname(host->mmc));
1242 sdhci_dumpregs(host);
1245 host->data->error = -ETIMEDOUT;
1246 sdhci_finish_data(host);
1249 host->cmd->error = -ETIMEDOUT;
1251 host->mrq->cmd->error = -ETIMEDOUT;
1253 tasklet_schedule(&host->finish_tasklet);
1258 spin_unlock_irqrestore(&host->lock, flags);
1261 /*****************************************************************************\
1263 * Interrupt handling *
1265 \*****************************************************************************/
1267 static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
1269 BUG_ON(intmask == 0);
1272 printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
1273 "though no command operation was in progress.\n",
1274 mmc_hostname(host->mmc), (unsigned)intmask);
1275 sdhci_dumpregs(host);
1279 if (intmask & SDHCI_INT_TIMEOUT)
1280 host->cmd->error = -ETIMEDOUT;
1281 else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
1283 host->cmd->error = -EILSEQ;
1285 if (host->cmd->error)
1286 tasklet_schedule(&host->finish_tasklet);
1287 else if (intmask & SDHCI_INT_RESPONSE)
1288 sdhci_finish_command(host);
1291 static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
1293 BUG_ON(intmask == 0);
1297 * A data end interrupt is sent together with the response
1298 * for the stop command.
1300 if (intmask & SDHCI_INT_DATA_END)
1303 printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
1304 "though no data operation was in progress.\n",
1305 mmc_hostname(host->mmc), (unsigned)intmask);
1306 sdhci_dumpregs(host);
1311 if (intmask & SDHCI_INT_DATA_TIMEOUT)
1312 host->data->error = -ETIMEDOUT;
1313 else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
1314 host->data->error = -EILSEQ;
1315 else if (intmask & SDHCI_INT_ADMA_ERROR)
1316 host->data->error = -EIO;
1318 if (host->data->error)
1319 sdhci_finish_data(host);
1321 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
1322 sdhci_transfer_pio(host);
1325 * We currently don't do anything fancy with DMA
1326 * boundaries, but as we can't disable the feature
1327 * we need to at least restart the transfer.
1329 if (intmask & SDHCI_INT_DMA_END)
1330 writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS),
1331 host->ioaddr + SDHCI_DMA_ADDRESS);
1333 if (intmask & SDHCI_INT_DATA_END) {
1336 * Data managed to finish before the
1337 * command completed. Make sure we do
1338 * things in the proper order.
1340 host->data_early = 1;
1342 sdhci_finish_data(host);
1348 static irqreturn_t sdhci_irq(int irq, void *dev_id)
1351 struct sdhci_host* host = dev_id;
1355 spin_lock(&host->lock);
1357 intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
1359 if (!intmask || intmask == 0xffffffff) {
1364 DBG("*** %s got interrupt: 0x%08x\n",
1365 mmc_hostname(host->mmc), intmask);
1367 if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
1368 writel(intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE),
1369 host->ioaddr + SDHCI_INT_STATUS);
1370 tasklet_schedule(&host->card_tasklet);
1373 intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
1375 if (intmask & SDHCI_INT_CMD_MASK) {
1376 writel(intmask & SDHCI_INT_CMD_MASK,
1377 host->ioaddr + SDHCI_INT_STATUS);
1378 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
1381 if (intmask & SDHCI_INT_DATA_MASK) {
1382 writel(intmask & SDHCI_INT_DATA_MASK,
1383 host->ioaddr + SDHCI_INT_STATUS);
1384 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
1387 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
1389 intmask &= ~SDHCI_INT_ERROR;
1391 if (intmask & SDHCI_INT_BUS_POWER) {
1392 printk(KERN_ERR "%s: Card is consuming too much power!\n",
1393 mmc_hostname(host->mmc));
1394 writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS);
1397 intmask &= ~SDHCI_INT_BUS_POWER;
1399 if (intmask & SDHCI_INT_CARD_INT)
1402 intmask &= ~SDHCI_INT_CARD_INT;
1405 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
1406 mmc_hostname(host->mmc), intmask);
1407 sdhci_dumpregs(host);
1409 writel(intmask, host->ioaddr + SDHCI_INT_STATUS);
1412 result = IRQ_HANDLED;
1416 spin_unlock(&host->lock);
1419 * We have to delay this as it calls back into the driver.
1422 mmc_signal_sdio_irq(host->mmc);
1427 /*****************************************************************************\
1431 \*****************************************************************************/
1435 int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
1439 ret = mmc_suspend_host(host->mmc, state);
1443 free_irq(host->irq, host);
1448 EXPORT_SYMBOL_GPL(sdhci_suspend_host);
1450 int sdhci_resume_host(struct sdhci_host *host)
1454 if (host->flags & SDHCI_USE_DMA) {
1455 if (host->ops->enable_dma)
1456 host->ops->enable_dma(host);
1459 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
1460 mmc_hostname(host->mmc), host);
1467 ret = mmc_resume_host(host->mmc);
1474 EXPORT_SYMBOL_GPL(sdhci_resume_host);
1476 #endif /* CONFIG_PM */
1478 /*****************************************************************************\
1480 * Device allocation/registration *
1482 \*****************************************************************************/
1484 struct sdhci_host *sdhci_alloc_host(struct device *dev,
1487 struct mmc_host *mmc;
1488 struct sdhci_host *host;
1490 WARN_ON(dev == NULL);
1492 mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev);
1494 return ERR_PTR(-ENOMEM);
1496 host = mmc_priv(mmc);
1502 EXPORT_SYMBOL_GPL(sdhci_alloc_host);
1504 int sdhci_add_host(struct sdhci_host *host)
1506 struct mmc_host *mmc;
1510 WARN_ON(host == NULL);
1517 host->quirks = debug_quirks;
1519 sdhci_reset(host, SDHCI_RESET_ALL);
1521 host->version = readw(host->ioaddr + SDHCI_HOST_VERSION);
1522 host->version = (host->version & SDHCI_SPEC_VER_MASK)
1523 >> SDHCI_SPEC_VER_SHIFT;
1524 if (host->version > SDHCI_SPEC_200) {
1525 printk(KERN_ERR "%s: Unknown controller version (%d). "
1526 "You may experience problems.\n", mmc_hostname(mmc),
1530 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
1532 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
1533 host->flags |= SDHCI_USE_DMA;
1534 else if (!(caps & SDHCI_CAN_DO_DMA))
1535 DBG("Controller doesn't have DMA capability\n");
1537 host->flags |= SDHCI_USE_DMA;
1539 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
1540 (host->flags & SDHCI_USE_DMA)) {
1541 DBG("Disabling DMA as it is marked broken\n");
1542 host->flags &= ~SDHCI_USE_DMA;
1545 if (host->flags & SDHCI_USE_DMA) {
1546 if ((host->version >= SDHCI_SPEC_200) &&
1547 (caps & SDHCI_CAN_DO_ADMA2))
1548 host->flags |= SDHCI_USE_ADMA;
1551 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
1552 (host->flags & SDHCI_USE_ADMA)) {
1553 DBG("Disabling ADMA as it is marked broken\n");
1554 host->flags &= ~SDHCI_USE_ADMA;
1557 if (host->flags & SDHCI_USE_DMA) {
1558 if (host->ops->enable_dma) {
1559 if (host->ops->enable_dma(host)) {
1560 printk(KERN_WARNING "%s: No suitable DMA "
1561 "available. Falling back to PIO.\n",
1563 host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA);
1568 if (host->flags & SDHCI_USE_ADMA) {
1570 * We need to allocate descriptors for all sg entries
1571 * (128) and potentially one alignment transfer for
1572 * each of those entries.
1574 host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL);
1575 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL);
1576 if (!host->adma_desc || !host->align_buffer) {
1577 kfree(host->adma_desc);
1578 kfree(host->align_buffer);
1579 printk(KERN_WARNING "%s: Unable to allocate ADMA "
1580 "buffers. Falling back to standard DMA.\n",
1582 host->flags &= ~SDHCI_USE_ADMA;
1586 /* XXX: Hack to get MMC layer to avoid highmem */
1587 if (!(host->flags & SDHCI_USE_DMA))
1588 mmc_dev(host->mmc)->dma_mask = NULL;
1591 (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
1592 if (host->max_clk == 0) {
1593 printk(KERN_ERR "%s: Hardware doesn't specify base clock "
1594 "frequency.\n", mmc_hostname(mmc));
1597 host->max_clk *= 1000000;
1600 (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
1601 if (host->timeout_clk == 0) {
1602 printk(KERN_ERR "%s: Hardware doesn't specify timeout clock "
1603 "frequency.\n", mmc_hostname(mmc));
1606 if (caps & SDHCI_TIMEOUT_CLK_UNIT)
1607 host->timeout_clk *= 1000;
1610 * Set host parameters.
1612 mmc->ops = &sdhci_ops;
1613 mmc->f_min = host->max_clk / 256;
1614 mmc->f_max = host->max_clk;
1615 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
1617 if (caps & SDHCI_CAN_DO_HISPD)
1618 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1621 if (caps & SDHCI_CAN_VDD_330)
1622 mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34;
1623 if (caps & SDHCI_CAN_VDD_300)
1624 mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31;
1625 if (caps & SDHCI_CAN_VDD_180)
1626 mmc->ocr_avail |= MMC_VDD_165_195;
1628 if (mmc->ocr_avail == 0) {
1629 printk(KERN_ERR "%s: Hardware doesn't report any "
1630 "support voltages.\n", mmc_hostname(mmc));
1634 spin_lock_init(&host->lock);
1637 * Maximum number of segments. Depends on if the hardware
1638 * can do scatter/gather or not.
1640 if (host->flags & SDHCI_USE_ADMA)
1641 mmc->max_hw_segs = 128;
1642 else if (host->flags & SDHCI_USE_DMA)
1643 mmc->max_hw_segs = 1;
1645 mmc->max_hw_segs = 128;
1646 mmc->max_phys_segs = 128;
1649 * Maximum number of sectors in one transfer. Limited by DMA boundary
1652 mmc->max_req_size = 524288;
1655 * Maximum segment size. Could be one segment with the maximum number
1656 * of bytes. When doing hardware scatter/gather, each entry cannot
1657 * be larger than 64 KiB though.
1659 if (host->flags & SDHCI_USE_ADMA)
1660 mmc->max_seg_size = 65536;
1662 mmc->max_seg_size = mmc->max_req_size;
1665 * Maximum block size. This varies from controller to controller and
1666 * is specified in the capabilities register.
1668 mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> SDHCI_MAX_BLOCK_SHIFT;
1669 if (mmc->max_blk_size >= 3) {
1670 printk(KERN_WARNING "%s: Invalid maximum block size, "
1671 "assuming 512 bytes\n", mmc_hostname(mmc));
1672 mmc->max_blk_size = 512;
1674 mmc->max_blk_size = 512 << mmc->max_blk_size;
1677 * Maximum block count.
1679 mmc->max_blk_count = 65535;
1684 tasklet_init(&host->card_tasklet,
1685 sdhci_tasklet_card, (unsigned long)host);
1686 tasklet_init(&host->finish_tasklet,
1687 sdhci_tasklet_finish, (unsigned long)host);
1689 setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
1691 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
1692 mmc_hostname(mmc), host);
1698 #ifdef CONFIG_MMC_DEBUG
1699 sdhci_dumpregs(host);
1702 #ifdef CONFIG_LEDS_CLASS
1703 host->led.name = mmc_hostname(mmc);
1704 host->led.brightness = LED_OFF;
1705 host->led.default_trigger = mmc_hostname(mmc);
1706 host->led.brightness_set = sdhci_led_control;
1708 ret = led_classdev_register(mmc_dev(mmc), &host->led);
1717 printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n",
1718 mmc_hostname(mmc), host->hw_name, mmc_dev(mmc)->bus_id,
1719 (host->flags & SDHCI_USE_ADMA)?"A":"",
1720 (host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
1724 #ifdef CONFIG_LEDS_CLASS
1726 sdhci_reset(host, SDHCI_RESET_ALL);
1727 free_irq(host->irq, host);
1730 tasklet_kill(&host->card_tasklet);
1731 tasklet_kill(&host->finish_tasklet);
1736 EXPORT_SYMBOL_GPL(sdhci_add_host);
1738 void sdhci_remove_host(struct sdhci_host *host, int dead)
1740 unsigned long flags;
1743 spin_lock_irqsave(&host->lock, flags);
1745 host->flags |= SDHCI_DEVICE_DEAD;
1748 printk(KERN_ERR "%s: Controller removed during "
1749 " transfer!\n", mmc_hostname(host->mmc));
1751 host->mrq->cmd->error = -ENOMEDIUM;
1752 tasklet_schedule(&host->finish_tasklet);
1755 spin_unlock_irqrestore(&host->lock, flags);
1758 mmc_remove_host(host->mmc);
1760 #ifdef CONFIG_LEDS_CLASS
1761 led_classdev_unregister(&host->led);
1765 sdhci_reset(host, SDHCI_RESET_ALL);
1767 free_irq(host->irq, host);
1769 del_timer_sync(&host->timer);
1771 tasklet_kill(&host->card_tasklet);
1772 tasklet_kill(&host->finish_tasklet);
1774 kfree(host->adma_desc);
1775 kfree(host->align_buffer);
1777 host->adma_desc = NULL;
1778 host->align_buffer = NULL;
1781 EXPORT_SYMBOL_GPL(sdhci_remove_host);
1783 void sdhci_free_host(struct sdhci_host *host)
1785 mmc_free_host(host->mmc);
1788 EXPORT_SYMBOL_GPL(sdhci_free_host);
1790 /*****************************************************************************\
1792 * Driver init/exit *
1794 \*****************************************************************************/
1796 static int __init sdhci_drv_init(void)
1798 printk(KERN_INFO DRIVER_NAME
1799 ": Secure Digital Host Controller Interface driver\n");
1800 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1805 static void __exit sdhci_drv_exit(void)
1809 module_init(sdhci_drv_init);
1810 module_exit(sdhci_drv_exit);
1812 module_param(debug_quirks, uint, 0444);
1814 MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
1815 MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
1816 MODULE_LICENSE("GPL");
1818 MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");