2 * Atmel MultiMedia Card Interface driver
4 * Copyright (C) 2004-2008 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/blkdev.h>
11 #include <linux/clk.h>
12 #include <linux/device.h>
13 #include <linux/err.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ioport.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/scatterlist.h>
21 #include <linux/mmc/host.h>
23 #include <asm/atmel-mci.h>
25 #include <asm/unaligned.h>
27 #include <asm/arch/board.h>
28 #include <asm/arch/gpio.h>
30 #include "atmel-mci-regs.h"
32 #define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE)
35 EVENT_CMD_COMPLETE = 0,
47 struct scatterlist *sg;
48 unsigned int pio_offset;
50 struct mmc_request *mrq;
51 struct mmc_command *cmd;
52 struct mmc_data *data;
62 struct tasklet_struct tasklet;
63 unsigned long pending_events;
64 unsigned long completed_events;
70 /* For detect pin debouncing */
71 struct timer_list detect_timer;
74 unsigned long mapbase;
76 struct platform_device *pdev;
79 #define atmci_is_completed(host, event) \
80 test_bit(event, &host->completed_events)
81 #define atmci_test_and_clear_pending(host, event) \
82 test_and_clear_bit(event, &host->pending_events)
83 #define atmci_test_and_set_completed(host, event) \
84 test_and_set_bit(event, &host->completed_events)
85 #define atmci_set_completed(host, event) \
86 set_bit(event, &host->completed_events)
87 #define atmci_set_pending(host, event) \
88 set_bit(event, &host->pending_events)
89 #define atmci_clear_pending(host, event) \
90 clear_bit(event, &host->pending_events)
93 static void atmci_enable(struct atmel_mci *host)
95 clk_enable(host->mck);
96 mci_writel(host, CR, MCI_CR_MCIEN);
97 mci_writel(host, MR, host->mode_reg);
98 mci_writel(host, SDCR, host->sdc_reg);
101 static void atmci_disable(struct atmel_mci *host)
103 mci_writel(host, CR, MCI_CR_SWRST);
105 /* Stall until write is complete, then disable the bus clock */
107 clk_disable(host->mck);
110 static inline unsigned int ns_to_clocks(struct atmel_mci *host,
113 return (ns * (host->bus_hz / 1000000) + 999) / 1000;
116 static void atmci_set_timeout(struct atmel_mci *host,
117 struct mmc_data *data)
119 static unsigned dtomul_to_shift[] = {
120 0, 4, 7, 8, 10, 12, 16, 20
126 timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
128 for (dtomul = 0; dtomul < 8; dtomul++) {
129 unsigned shift = dtomul_to_shift[dtomul];
130 dtocyc = (timeout + (1 << shift) - 1) >> shift;
140 dev_vdbg(&host->mmc->class_dev, "setting timeout to %u cycles\n",
141 dtocyc << dtomul_to_shift[dtomul]);
142 mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc)));
146 * Return mask with command flags to be enabled for this command.
148 static u32 atmci_prepare_command(struct mmc_host *mmc,
149 struct mmc_command *cmd)
151 struct mmc_data *data;
154 cmd->error = -EINPROGRESS;
156 cmdr = MCI_CMDR_CMDNB(cmd->opcode);
158 if (cmd->flags & MMC_RSP_PRESENT) {
159 if (cmd->flags & MMC_RSP_136)
160 cmdr |= MCI_CMDR_RSPTYP_136BIT;
162 cmdr |= MCI_CMDR_RSPTYP_48BIT;
166 * This should really be MAXLAT_5 for CMD2 and ACMD41, but
167 * it's too difficult to determine whether this is an ACMD or
168 * not. Better make it 64.
170 cmdr |= MCI_CMDR_MAXLAT_64CYC;
172 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
173 cmdr |= MCI_CMDR_OPDCMD;
177 cmdr |= MCI_CMDR_START_XFER;
178 if (data->flags & MMC_DATA_STREAM)
179 cmdr |= MCI_CMDR_STREAM;
180 else if (data->blocks > 1)
181 cmdr |= MCI_CMDR_MULTI_BLOCK;
183 cmdr |= MCI_CMDR_BLOCK;
185 if (data->flags & MMC_DATA_READ)
186 cmdr |= MCI_CMDR_TRDIR_READ;
192 static void atmci_start_command(struct atmel_mci *host,
193 struct mmc_command *cmd,
196 /* Must read host->cmd after testing event flags */
201 dev_vdbg(&host->mmc->class_dev,
202 "start command: ARGR=0x%08x CMDR=0x%08x\n",
203 cmd->arg, cmd_flags);
205 mci_writel(host, ARGR, cmd->arg);
206 mci_writel(host, CMDR, cmd_flags);
209 static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data)
211 struct atmel_mci *host = mmc_priv(mmc);
213 atmci_start_command(host, data->stop, host->stop_cmdr);
214 mci_writel(host, IER, MCI_CMDRDY);
217 static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
219 struct atmel_mci *host = mmc_priv(mmc);
221 WARN_ON(host->cmd || host->data);
226 mmc_request_done(mmc, mrq);
230 * Returns a mask of interrupt flags to be enabled after the whole
231 * request has been prepared.
233 static u32 atmci_submit_data(struct mmc_host *mmc, struct mmc_data *data)
235 struct atmel_mci *host = mmc_priv(mmc);
238 data->error = -EINPROGRESS;
244 mci_writel(host, BLKR, MCI_BCNT(data->blocks)
245 | MCI_BLKLEN(data->blksz));
246 dev_vdbg(&mmc->class_dev, "BLKR=0x%08x\n",
247 MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz));
249 iflags = ATMCI_DATA_ERROR_FLAGS;
251 host->pio_offset = 0;
252 if (data->flags & MMC_DATA_READ)
260 static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
262 struct atmel_mci *host = mmc_priv(mmc);
263 struct mmc_data *data;
264 struct mmc_command *cmd;
268 iflags = mci_readl(host, IMR);
270 dev_warn(&mmc->class_dev, "WARNING: IMR=0x%08x\n",
271 mci_readl(host, IMR));
273 WARN_ON(host->mrq != NULL);
276 * We may "know" the card is gone even though there's still an
277 * electrical connection. If so, we really need to communicate
278 * this to the MMC core since there won't be any more
279 * interrupts as the card is completely removed. Otherwise,
280 * the MMC core might believe the card is still there even
281 * though the card was just removed very slowly.
283 if (!host->present) {
284 mrq->cmd->error = -ENOMEDIUM;
285 mmc_request_done(mmc, mrq);
290 host->pending_events = 0;
291 host->completed_events = 0;
295 /* We don't support multiple blocks of weird lengths. */
298 if (data->blocks > 1 && data->blksz & 3)
300 atmci_set_timeout(host, data);
305 cmdflags = atmci_prepare_command(mmc, cmd);
306 atmci_start_command(host, cmd, cmdflags);
309 iflags |= atmci_submit_data(mmc, data);
312 host->stop_cmdr = atmci_prepare_command(mmc, mrq->stop);
313 host->stop_cmdr |= MCI_CMDR_STOP_XFER;
314 if (!(data->flags & MMC_DATA_WRITE))
315 host->stop_cmdr |= MCI_CMDR_TRDIR_READ;
316 if (data->flags & MMC_DATA_STREAM)
317 host->stop_cmdr |= MCI_CMDR_STREAM;
319 host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK;
323 * We could have enabled interrupts earlier, but I suspect
324 * that would open up a nice can of interesting race
325 * conditions (e.g. command and data complete, but stop not
328 mci_writel(host, IER, iflags);
335 mrq->cmd->error = -EINVAL;
336 mmc_request_done(mmc, mrq);
339 static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
341 struct atmel_mci *host = mmc_priv(mmc);
347 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * ios->clock) - 1;
349 dev_warn(&mmc->class_dev,
350 "clock %u too slow; using %lu\n",
351 ios->clock, host->bus_hz / (2 * 256));
355 host->mode_reg = MCI_MR_CLKDIV(clkdiv) | MCI_MR_WRPROOF
359 switch (ios->bus_width) {
360 case MMC_BUS_WIDTH_1:
363 case MMC_BUS_WIDTH_4:
364 host->sdc_reg = MCI_SDCBUS_4BIT;
368 switch (ios->power_mode) {
370 /* Send init sequence (74 clock cycles) */
372 mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT);
373 while (!(mci_readl(host, SR) & MCI_CMDRDY))
379 * TODO: None of the currently available AVR32-based
380 * boards allow MMC power to be turned off. Implement
381 * power control when this can be tested properly.
387 static int atmci_get_ro(struct mmc_host *mmc)
390 struct atmel_mci *host = mmc_priv(mmc);
392 if (host->wp_pin >= 0) {
393 read_only = gpio_get_value(host->wp_pin);
394 dev_dbg(&mmc->class_dev, "card is %s\n",
395 read_only ? "read-only" : "read-write");
397 dev_dbg(&mmc->class_dev,
398 "no pin for checking read-only switch."
399 " Assuming write-enable.\n");
405 static struct mmc_host_ops atmci_ops = {
406 .request = atmci_request,
407 .set_ios = atmci_set_ios,
408 .get_ro = atmci_get_ro,
411 static void atmci_command_complete(struct atmel_mci *host,
412 struct mmc_command *cmd, u32 status)
414 /* Read the response from the card (up to 16 bytes) */
415 cmd->resp[0] = mci_readl(host, RSPR);
416 cmd->resp[1] = mci_readl(host, RSPR);
417 cmd->resp[2] = mci_readl(host, RSPR);
418 cmd->resp[3] = mci_readl(host, RSPR);
420 if (status & MCI_RTOE)
421 cmd->error = -ETIMEDOUT;
422 else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE))
423 cmd->error = -EILSEQ;
424 else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE))
430 dev_dbg(&host->mmc->class_dev,
431 "command error: status=0x%08x\n", status);
435 mci_writel(host, IDR, MCI_NOTBUSY
436 | MCI_TXRDY | MCI_RXRDY
437 | ATMCI_DATA_ERROR_FLAGS);
442 static void atmci_detect_change(unsigned long data)
444 struct atmel_mci *host = (struct atmel_mci *)data;
445 struct mmc_request *mrq = host->mrq;
449 * atmci_remove() sets detect_pin to -1 before freeing the
450 * interrupt. We must not re-enable the interrupt if it has
454 if (host->detect_pin < 0)
457 enable_irq(gpio_to_irq(host->detect_pin));
458 present = !gpio_get_value(host->detect_pin);
460 dev_vdbg(&host->pdev->dev, "detect change: %d (was %d)\n",
461 present, host->present);
463 if (present != host->present) {
464 dev_dbg(&host->mmc->class_dev, "card %s\n",
465 present ? "inserted" : "removed");
466 host->present = present;
468 /* Reset controller if card is gone */
470 mci_writel(host, CR, MCI_CR_SWRST);
471 mci_writel(host, IDR, ~0UL);
472 mci_writel(host, CR, MCI_CR_MCIEN);
475 /* Clean up queue if present */
478 * Reset controller to terminate any ongoing
479 * commands or data transfers.
481 mci_writel(host, CR, MCI_CR_SWRST);
483 if (!atmci_is_completed(host, EVENT_CMD_COMPLETE))
484 mrq->cmd->error = -ENOMEDIUM;
486 if (mrq->data && !atmci_is_completed(host,
487 EVENT_DATA_COMPLETE)) {
489 mrq->data->error = -ENOMEDIUM;
491 if (mrq->stop && !atmci_is_completed(host,
492 EVENT_STOP_COMPLETE))
493 mrq->stop->error = -ENOMEDIUM;
496 atmci_request_end(host->mmc, mrq);
499 mmc_detect_change(host->mmc, 0);
503 static void atmci_tasklet_func(unsigned long priv)
505 struct mmc_host *mmc = (struct mmc_host *)priv;
506 struct atmel_mci *host = mmc_priv(mmc);
507 struct mmc_request *mrq = host->mrq;
508 struct mmc_data *data = host->data;
510 dev_vdbg(&mmc->class_dev,
511 "tasklet: pending/completed/mask %lx/%lx/%x\n",
512 host->pending_events, host->completed_events,
513 mci_readl(host, IMR));
515 if (atmci_test_and_clear_pending(host, EVENT_CMD_COMPLETE)) {
517 * host->cmd must be set to NULL before the interrupt
518 * handler sees EVENT_CMD_COMPLETE
522 atmci_set_completed(host, EVENT_CMD_COMPLETE);
523 atmci_command_complete(host, mrq->cmd, host->cmd_status);
525 if (!mrq->cmd->error && mrq->stop
526 && atmci_is_completed(host, EVENT_XFER_COMPLETE)
527 && !atmci_test_and_set_completed(host,
529 send_stop_cmd(host->mmc, mrq->data);
531 if (atmci_test_and_clear_pending(host, EVENT_STOP_COMPLETE)) {
533 * host->cmd must be set to NULL before the interrupt
534 * handler sees EVENT_STOP_COMPLETE
538 atmci_set_completed(host, EVENT_STOP_COMPLETE);
539 atmci_command_complete(host, mrq->stop, host->stop_status);
541 if (atmci_test_and_clear_pending(host, EVENT_DATA_ERROR)) {
542 u32 status = host->data_status;
544 dev_vdbg(&mmc->class_dev, "data error: status=%08x\n", status);
546 atmci_set_completed(host, EVENT_DATA_ERROR);
547 atmci_set_completed(host, EVENT_DATA_COMPLETE);
549 if (status & MCI_DTOE) {
550 dev_dbg(&mmc->class_dev,
551 "data timeout error\n");
552 data->error = -ETIMEDOUT;
553 } else if (status & MCI_DCRCE) {
554 dev_dbg(&mmc->class_dev, "data CRC error\n");
555 data->error = -EILSEQ;
557 dev_dbg(&mmc->class_dev,
558 "data FIFO error (status=%08x)\n",
563 if (host->present && data->stop
564 && atmci_is_completed(host, EVENT_CMD_COMPLETE)
565 && !atmci_test_and_set_completed(
566 host, EVENT_STOP_SENT))
567 send_stop_cmd(host->mmc, data);
571 if (atmci_test_and_clear_pending(host, EVENT_DATA_COMPLETE)) {
572 atmci_set_completed(host, EVENT_DATA_COMPLETE);
574 if (!atmci_is_completed(host, EVENT_DATA_ERROR)) {
575 data->bytes_xfered = data->blocks * data->blksz;
582 if (host->mrq && !host->cmd && !host->data)
583 atmci_request_end(mmc, host->mrq);
586 static void atmci_read_data_pio(struct atmel_mci *host)
588 struct scatterlist *sg = host->sg;
589 void *buf = sg_virt(sg);
590 unsigned int offset = host->pio_offset;
591 struct mmc_data *data = host->data;
594 unsigned int nbytes = 0;
597 value = mci_readl(host, RDR);
598 if (likely(offset + 4 <= sg->length)) {
599 put_unaligned(value, (u32 *)(buf + offset));
604 if (offset == sg->length) {
605 host->sg = sg = sg_next(sg);
613 unsigned int remaining = sg->length - offset;
614 memcpy(buf + offset, &value, remaining);
617 flush_dcache_page(sg_page(sg));
618 host->sg = sg = sg_next(sg);
622 offset = 4 - remaining;
624 memcpy(buf, (u8 *)&value + remaining, offset);
628 status = mci_readl(host, SR);
629 if (status & ATMCI_DATA_ERROR_FLAGS) {
630 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY
631 | ATMCI_DATA_ERROR_FLAGS));
632 host->data_status = status;
633 atmci_set_pending(host, EVENT_DATA_ERROR);
634 tasklet_schedule(&host->tasklet);
637 } while (status & MCI_RXRDY);
639 host->pio_offset = offset;
640 data->bytes_xfered += nbytes;
645 mci_writel(host, IDR, MCI_RXRDY);
646 mci_writel(host, IER, MCI_NOTBUSY);
647 data->bytes_xfered += nbytes;
648 atmci_set_completed(host, EVENT_XFER_COMPLETE);
649 if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE)
650 && !atmci_test_and_set_completed(host, EVENT_STOP_SENT))
651 send_stop_cmd(host->mmc, data);
654 static void atmci_write_data_pio(struct atmel_mci *host)
656 struct scatterlist *sg = host->sg;
657 void *buf = sg_virt(sg);
658 unsigned int offset = host->pio_offset;
659 struct mmc_data *data = host->data;
662 unsigned int nbytes = 0;
665 if (likely(offset + 4 <= sg->length)) {
666 value = get_unaligned((u32 *)(buf + offset));
667 mci_writel(host, TDR, value);
671 if (offset == sg->length) {
672 host->sg = sg = sg_next(sg);
680 unsigned int remaining = sg->length - offset;
683 memcpy(&value, buf + offset, remaining);
686 host->sg = sg = sg_next(sg);
688 mci_writel(host, TDR, value);
692 offset = 4 - remaining;
694 memcpy((u8 *)&value + remaining, buf, offset);
695 mci_writel(host, TDR, value);
699 status = mci_readl(host, SR);
700 if (status & ATMCI_DATA_ERROR_FLAGS) {
701 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY
702 | ATMCI_DATA_ERROR_FLAGS));
703 host->data_status = status;
704 atmci_set_pending(host, EVENT_DATA_ERROR);
705 tasklet_schedule(&host->tasklet);
708 } while (status & MCI_TXRDY);
710 host->pio_offset = offset;
711 data->bytes_xfered += nbytes;
716 mci_writel(host, IDR, MCI_TXRDY);
717 mci_writel(host, IER, MCI_NOTBUSY);
718 data->bytes_xfered += nbytes;
719 atmci_set_completed(host, EVENT_XFER_COMPLETE);
720 if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE)
721 && !atmci_test_and_set_completed(host, EVENT_STOP_SENT))
722 send_stop_cmd(host->mmc, data);
725 static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
727 struct atmel_mci *host = mmc_priv(mmc);
729 mci_writel(host, IDR, MCI_CMDRDY);
731 if (atmci_is_completed(host, EVENT_STOP_SENT)) {
732 host->stop_status = status;
733 atmci_set_pending(host, EVENT_STOP_COMPLETE);
735 host->cmd_status = status;
736 atmci_set_pending(host, EVENT_CMD_COMPLETE);
739 tasklet_schedule(&host->tasklet);
742 static irqreturn_t atmci_interrupt(int irq, void *dev_id)
744 struct mmc_host *mmc = dev_id;
745 struct atmel_mci *host = mmc_priv(mmc);
746 u32 status, mask, pending;
747 unsigned int pass_count = 0;
749 spin_lock(&mmc->lock);
752 status = mci_readl(host, SR);
753 mask = mci_readl(host, IMR);
754 pending = status & mask;
758 if (pending & ATMCI_DATA_ERROR_FLAGS) {
759 mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS
760 | MCI_RXRDY | MCI_TXRDY);
761 pending &= mci_readl(host, IMR);
762 host->data_status = status;
763 atmci_set_pending(host, EVENT_DATA_ERROR);
764 tasklet_schedule(&host->tasklet);
766 if (pending & MCI_NOTBUSY) {
767 mci_writel(host, IDR, (MCI_NOTBUSY
768 | ATMCI_DATA_ERROR_FLAGS));
769 atmci_set_pending(host, EVENT_DATA_COMPLETE);
770 tasklet_schedule(&host->tasklet);
772 if (pending & MCI_RXRDY)
773 atmci_read_data_pio(host);
774 if (pending & MCI_TXRDY)
775 atmci_write_data_pio(host);
777 if (pending & MCI_CMDRDY)
778 atmci_cmd_interrupt(mmc, status);
779 } while (pass_count++ < 5);
781 spin_unlock(&mmc->lock);
783 return pass_count ? IRQ_HANDLED : IRQ_NONE;
786 static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id)
788 struct mmc_host *mmc = dev_id;
789 struct atmel_mci *host = mmc_priv(mmc);
792 * Disable interrupts until the pin has stabilized and check
793 * the state then. Use mod_timer() since we may be in the
794 * middle of the timer routine when this interrupt triggers.
796 disable_irq_nosync(irq);
797 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(20));
802 static int __init atmci_probe(struct platform_device *pdev)
804 struct mci_platform_data *pdata;
805 struct atmel_mci *host;
806 struct mmc_host *mmc;
807 struct resource *regs;
811 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
814 pdata = pdev->dev.platform_data;
817 irq = platform_get_irq(pdev, 0);
821 mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
825 host = mmc_priv(mmc);
828 host->detect_pin = pdata->detect_pin;
829 host->wp_pin = pdata->wp_pin;
831 host->mck = clk_get(&pdev->dev, "mci_clk");
832 if (IS_ERR(host->mck)) {
833 ret = PTR_ERR(host->mck);
838 host->regs = ioremap(regs->start, regs->end - regs->start + 1);
842 clk_enable(host->mck);
843 mci_writel(host, CR, MCI_CR_SWRST);
844 host->bus_hz = clk_get_rate(host->mck);
845 clk_disable(host->mck);
847 host->mapbase = regs->start;
849 mmc->ops = &atmci_ops;
850 mmc->f_min = (host->bus_hz + 511) / 512;
851 mmc->f_max = host->bus_hz / 2;
852 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
853 mmc->caps |= MMC_CAP_4_BIT_DATA;
855 mmc->max_hw_segs = 64;
856 mmc->max_phys_segs = 64;
857 mmc->max_req_size = 32768 * 512;
858 mmc->max_blk_size = 32768;
859 mmc->max_blk_count = 512;
861 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
863 ret = request_irq(irq, atmci_interrupt, 0, pdev->dev.bus_id, mmc);
865 goto err_request_irq;
867 /* Assume card is present if we don't have a detect pin */
869 if (host->detect_pin >= 0) {
870 if (gpio_request(host->detect_pin, "mmc_detect")) {
871 dev_dbg(&mmc->class_dev, "no detect pin available\n");
872 host->detect_pin = -1;
874 host->present = !gpio_get_value(host->detect_pin);
877 if (host->wp_pin >= 0) {
878 if (gpio_request(host->wp_pin, "mmc_wp")) {
879 dev_dbg(&mmc->class_dev, "no WP pin available\n");
884 platform_set_drvdata(pdev, host);
888 if (host->detect_pin >= 0) {
889 setup_timer(&host->detect_timer, atmci_detect_change,
890 (unsigned long)host);
892 ret = request_irq(gpio_to_irq(host->detect_pin),
893 atmci_detect_interrupt,
894 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
897 dev_dbg(&mmc->class_dev,
898 "could not request IRQ %d for detect pin\n",
899 gpio_to_irq(host->detect_pin));
900 gpio_free(host->detect_pin);
901 host->detect_pin = -1;
905 dev_info(&mmc->class_dev,
906 "Atmel MCI controller at 0x%08lx irq %d\n",
920 static int __exit atmci_remove(struct platform_device *pdev)
922 struct atmel_mci *host = platform_get_drvdata(pdev);
924 platform_set_drvdata(pdev, NULL);
927 if (host->detect_pin >= 0) {
928 int pin = host->detect_pin;
930 /* Make sure the timer doesn't enable the interrupt */
931 host->detect_pin = -1;
934 free_irq(gpio_to_irq(pin), host->mmc);
935 del_timer_sync(&host->detect_timer);
939 mmc_remove_host(host->mmc);
941 clk_enable(host->mck);
942 mci_writel(host, IDR, ~0UL);
943 mci_writel(host, CR, MCI_CR_MCIDIS);
945 clk_disable(host->mck);
947 if (host->wp_pin >= 0)
948 gpio_free(host->wp_pin);
950 free_irq(platform_get_irq(pdev, 0), host->mmc);
955 mmc_free_host(host->mmc);
960 static struct platform_driver atmci_driver = {
961 .remove = __exit_p(atmci_remove),
967 static int __init atmci_init(void)
969 return platform_driver_probe(&atmci_driver, atmci_probe);
972 static void __exit atmci_exit(void)
974 platform_driver_unregister(&atmci_driver);
977 module_init(atmci_init);
978 module_exit(atmci_exit);
980 MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
981 MODULE_AUTHOR("Haavard Skinnemoen <haavard.skinnemoen@atmel.com>");
982 MODULE_LICENSE("GPL v2");