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/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/ioport.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/scatterlist.h>
20 #include <linux/mmc/host.h>
22 #include <asm/atmel-mci.h>
24 #include <asm/unaligned.h>
26 #include <asm/arch/board.h>
27 #include <asm/arch/gpio.h>
29 #include "atmel-mci-regs.h"
31 #define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE)
34 EVENT_CMD_COMPLETE = 0,
46 struct scatterlist *sg;
47 unsigned int pio_offset;
49 struct mmc_request *mrq;
50 struct mmc_command *cmd;
51 struct mmc_data *data;
61 struct tasklet_struct tasklet;
62 unsigned long pending_events;
63 unsigned long completed_events;
69 /* For detect pin debouncing */
70 struct timer_list detect_timer;
73 unsigned long mapbase;
75 struct platform_device *pdev;
78 #define atmci_is_completed(host, event) \
79 test_bit(event, &host->completed_events)
80 #define atmci_test_and_clear_pending(host, event) \
81 test_and_clear_bit(event, &host->pending_events)
82 #define atmci_test_and_set_completed(host, event) \
83 test_and_set_bit(event, &host->completed_events)
84 #define atmci_set_completed(host, event) \
85 set_bit(event, &host->completed_events)
86 #define atmci_set_pending(host, event) \
87 set_bit(event, &host->pending_events)
88 #define atmci_clear_pending(host, event) \
89 clear_bit(event, &host->pending_events)
92 static void atmci_enable(struct atmel_mci *host)
94 clk_enable(host->mck);
95 mci_writel(host, CR, MCI_CR_MCIEN);
96 mci_writel(host, MR, host->mode_reg);
97 mci_writel(host, SDCR, host->sdc_reg);
100 static void atmci_disable(struct atmel_mci *host)
102 mci_writel(host, CR, MCI_CR_SWRST);
104 /* Stall until write is complete, then disable the bus clock */
106 clk_disable(host->mck);
109 static inline unsigned int ns_to_clocks(struct atmel_mci *host,
112 return (ns * (host->bus_hz / 1000000) + 999) / 1000;
115 static void atmci_set_timeout(struct atmel_mci *host,
116 struct mmc_data *data)
118 static unsigned dtomul_to_shift[] = {
119 0, 4, 7, 8, 10, 12, 16, 20
125 timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
127 for (dtomul = 0; dtomul < 8; dtomul++) {
128 unsigned shift = dtomul_to_shift[dtomul];
129 dtocyc = (timeout + (1 << shift) - 1) >> shift;
139 dev_vdbg(&host->mmc->class_dev, "setting timeout to %u cycles\n",
140 dtocyc << dtomul_to_shift[dtomul]);
141 mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc)));
145 * Return mask with command flags to be enabled for this command.
147 static u32 atmci_prepare_command(struct mmc_host *mmc,
148 struct mmc_command *cmd)
150 struct mmc_data *data;
153 cmd->error = -EINPROGRESS;
155 cmdr = MCI_CMDR_CMDNB(cmd->opcode);
157 if (cmd->flags & MMC_RSP_PRESENT) {
158 if (cmd->flags & MMC_RSP_136)
159 cmdr |= MCI_CMDR_RSPTYP_136BIT;
161 cmdr |= MCI_CMDR_RSPTYP_48BIT;
165 * This should really be MAXLAT_5 for CMD2 and ACMD41, but
166 * it's too difficult to determine whether this is an ACMD or
167 * not. Better make it 64.
169 cmdr |= MCI_CMDR_MAXLAT_64CYC;
171 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
172 cmdr |= MCI_CMDR_OPDCMD;
176 cmdr |= MCI_CMDR_START_XFER;
177 if (data->flags & MMC_DATA_STREAM)
178 cmdr |= MCI_CMDR_STREAM;
179 else if (data->blocks > 1)
180 cmdr |= MCI_CMDR_MULTI_BLOCK;
182 cmdr |= MCI_CMDR_BLOCK;
184 if (data->flags & MMC_DATA_READ)
185 cmdr |= MCI_CMDR_TRDIR_READ;
191 static void atmci_start_command(struct atmel_mci *host,
192 struct mmc_command *cmd,
195 /* Must read host->cmd after testing event flags */
200 dev_vdbg(&host->mmc->class_dev,
201 "start command: ARGR=0x%08x CMDR=0x%08x\n",
202 cmd->arg, cmd_flags);
204 mci_writel(host, ARGR, cmd->arg);
205 mci_writel(host, CMDR, cmd_flags);
208 static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data)
210 struct atmel_mci *host = mmc_priv(mmc);
212 atmci_start_command(host, data->stop, host->stop_cmdr);
213 mci_writel(host, IER, MCI_CMDRDY);
216 static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
218 struct atmel_mci *host = mmc_priv(mmc);
220 WARN_ON(host->cmd || host->data);
225 mmc_request_done(mmc, mrq);
229 * Returns a mask of interrupt flags to be enabled after the whole
230 * request has been prepared.
232 static u32 atmci_submit_data(struct mmc_host *mmc, struct mmc_data *data)
234 struct atmel_mci *host = mmc_priv(mmc);
237 data->error = -EINPROGRESS;
243 mci_writel(host, BLKR, MCI_BCNT(data->blocks)
244 | MCI_BLKLEN(data->blksz));
245 dev_vdbg(&mmc->class_dev, "BLKR=0x%08x\n",
246 MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz));
248 iflags = ATMCI_DATA_ERROR_FLAGS;
250 host->pio_offset = 0;
251 if (data->flags & MMC_DATA_READ)
259 static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
261 struct atmel_mci *host = mmc_priv(mmc);
262 struct mmc_data *data;
263 struct mmc_command *cmd;
267 iflags = mci_readl(host, IMR);
269 dev_warn(&mmc->class_dev, "WARNING: IMR=0x%08x\n",
270 mci_readl(host, IMR));
272 WARN_ON(host->mrq != NULL);
275 * We may "know" the card is gone even though there's still an
276 * electrical connection. If so, we really need to communicate
277 * this to the MMC core since there won't be any more
278 * interrupts as the card is completely removed. Otherwise,
279 * the MMC core might believe the card is still there even
280 * though the card was just removed very slowly.
282 if (!host->present) {
283 mrq->cmd->error = -ENOMEDIUM;
284 mmc_request_done(mmc, mrq);
289 host->pending_events = 0;
290 host->completed_events = 0;
294 /* We don't support multiple blocks of weird lengths. */
297 if (data->blocks > 1 && data->blksz & 3)
299 atmci_set_timeout(host, data);
304 cmdflags = atmci_prepare_command(mmc, cmd);
305 atmci_start_command(host, cmd, cmdflags);
308 iflags |= atmci_submit_data(mmc, data);
311 host->stop_cmdr = atmci_prepare_command(mmc, mrq->stop);
312 host->stop_cmdr |= MCI_CMDR_STOP_XFER;
313 if (!(data->flags & MMC_DATA_WRITE))
314 host->stop_cmdr |= MCI_CMDR_TRDIR_READ;
315 if (data->flags & MMC_DATA_STREAM)
316 host->stop_cmdr |= MCI_CMDR_STREAM;
318 host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK;
322 * We could have enabled interrupts earlier, but I suspect
323 * that would open up a nice can of interesting race
324 * conditions (e.g. command and data complete, but stop not
327 mci_writel(host, IER, iflags);
334 mrq->cmd->error = -EINVAL;
335 mmc_request_done(mmc, mrq);
338 static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
340 struct atmel_mci *host = mmc_priv(mmc);
346 clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * ios->clock) - 1;
348 dev_warn(&mmc->class_dev,
349 "clock %u too slow; using %lu\n",
350 ios->clock, host->bus_hz / (2 * 256));
354 host->mode_reg = MCI_MR_CLKDIV(clkdiv) | MCI_MR_WRPROOF
358 switch (ios->bus_width) {
359 case MMC_BUS_WIDTH_1:
362 case MMC_BUS_WIDTH_4:
363 host->sdc_reg = MCI_SDCBUS_4BIT;
367 switch (ios->power_mode) {
369 /* Send init sequence (74 clock cycles) */
371 mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT);
372 while (!(mci_readl(host, SR) & MCI_CMDRDY))
378 * TODO: None of the currently available AVR32-based
379 * boards allow MMC power to be turned off. Implement
380 * power control when this can be tested properly.
386 static int atmci_get_ro(struct mmc_host *mmc)
389 struct atmel_mci *host = mmc_priv(mmc);
391 if (host->wp_pin >= 0) {
392 read_only = gpio_get_value(host->wp_pin);
393 dev_dbg(&mmc->class_dev, "card is %s\n",
394 read_only ? "read-only" : "read-write");
396 dev_dbg(&mmc->class_dev,
397 "no pin for checking read-only switch."
398 " Assuming write-enable.\n");
404 static struct mmc_host_ops atmci_ops = {
405 .request = atmci_request,
406 .set_ios = atmci_set_ios,
407 .get_ro = atmci_get_ro,
410 static void atmci_command_complete(struct atmel_mci *host,
411 struct mmc_command *cmd, u32 status)
413 /* Read the response from the card (up to 16 bytes) */
414 cmd->resp[0] = mci_readl(host, RSPR);
415 cmd->resp[1] = mci_readl(host, RSPR);
416 cmd->resp[2] = mci_readl(host, RSPR);
417 cmd->resp[3] = mci_readl(host, RSPR);
419 if (status & MCI_RTOE)
420 cmd->error = -ETIMEDOUT;
421 else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE))
422 cmd->error = -EILSEQ;
423 else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE))
429 dev_dbg(&host->mmc->class_dev,
430 "command error: status=0x%08x\n", status);
434 mci_writel(host, IDR, MCI_NOTBUSY
435 | MCI_TXRDY | MCI_RXRDY
436 | ATMCI_DATA_ERROR_FLAGS);
441 static void atmci_detect_change(unsigned long data)
443 struct atmel_mci *host = (struct atmel_mci *)data;
444 struct mmc_request *mrq = host->mrq;
448 * atmci_remove() sets detect_pin to -1 before freeing the
449 * interrupt. We must not re-enable the interrupt if it has
453 if (host->detect_pin < 0)
456 enable_irq(gpio_to_irq(host->detect_pin));
457 present = !gpio_get_value(host->detect_pin);
459 dev_vdbg(&host->pdev->dev, "detect change: %d (was %d)\n",
460 present, host->present);
462 if (present != host->present) {
463 dev_dbg(&host->mmc->class_dev, "card %s\n",
464 present ? "inserted" : "removed");
465 host->present = present;
467 /* Reset controller if card is gone */
469 mci_writel(host, CR, MCI_CR_SWRST);
470 mci_writel(host, IDR, ~0UL);
471 mci_writel(host, CR, MCI_CR_MCIEN);
474 /* Clean up queue if present */
477 * Reset controller to terminate any ongoing
478 * commands or data transfers.
480 mci_writel(host, CR, MCI_CR_SWRST);
482 if (!atmci_is_completed(host, EVENT_CMD_COMPLETE))
483 mrq->cmd->error = -ENOMEDIUM;
485 if (mrq->data && !atmci_is_completed(host,
486 EVENT_DATA_COMPLETE)) {
488 mrq->data->error = -ENOMEDIUM;
490 if (mrq->stop && !atmci_is_completed(host,
491 EVENT_STOP_COMPLETE))
492 mrq->stop->error = -ENOMEDIUM;
495 atmci_request_end(host->mmc, mrq);
498 mmc_detect_change(host->mmc, 0);
502 static void atmci_tasklet_func(unsigned long priv)
504 struct mmc_host *mmc = (struct mmc_host *)priv;
505 struct atmel_mci *host = mmc_priv(mmc);
506 struct mmc_request *mrq = host->mrq;
507 struct mmc_data *data = host->data;
509 dev_vdbg(&mmc->class_dev,
510 "tasklet: pending/completed/mask %lx/%lx/%x\n",
511 host->pending_events, host->completed_events,
512 mci_readl(host, IMR));
514 if (atmci_test_and_clear_pending(host, EVENT_CMD_COMPLETE)) {
516 * host->cmd must be set to NULL before the interrupt
517 * handler sees EVENT_CMD_COMPLETE
521 atmci_set_completed(host, EVENT_CMD_COMPLETE);
522 atmci_command_complete(host, mrq->cmd, host->cmd_status);
524 if (!mrq->cmd->error && mrq->stop
525 && atmci_is_completed(host, EVENT_XFER_COMPLETE)
526 && !atmci_test_and_set_completed(host,
528 send_stop_cmd(host->mmc, mrq->data);
530 if (atmci_test_and_clear_pending(host, EVENT_STOP_COMPLETE)) {
532 * host->cmd must be set to NULL before the interrupt
533 * handler sees EVENT_STOP_COMPLETE
537 atmci_set_completed(host, EVENT_STOP_COMPLETE);
538 atmci_command_complete(host, mrq->stop, host->stop_status);
540 if (atmci_test_and_clear_pending(host, EVENT_DATA_ERROR)) {
541 u32 status = host->data_status;
543 dev_vdbg(&mmc->class_dev, "data error: status=%08x\n", status);
545 atmci_set_completed(host, EVENT_DATA_ERROR);
546 atmci_set_completed(host, EVENT_DATA_COMPLETE);
548 if (status & MCI_DTOE) {
549 dev_dbg(&mmc->class_dev,
550 "data timeout error\n");
551 data->error = -ETIMEDOUT;
552 } else if (status & MCI_DCRCE) {
553 dev_dbg(&mmc->class_dev, "data CRC error\n");
554 data->error = -EILSEQ;
556 dev_dbg(&mmc->class_dev,
557 "data FIFO error (status=%08x)\n",
562 if (host->present && data->stop
563 && atmci_is_completed(host, EVENT_CMD_COMPLETE)
564 && !atmci_test_and_set_completed(
565 host, EVENT_STOP_SENT))
566 send_stop_cmd(host->mmc, data);
570 if (atmci_test_and_clear_pending(host, EVENT_DATA_COMPLETE)) {
571 atmci_set_completed(host, EVENT_DATA_COMPLETE);
573 if (!atmci_is_completed(host, EVENT_DATA_ERROR)) {
574 data->bytes_xfered = data->blocks * data->blksz;
581 if (host->mrq && !host->cmd && !host->data)
582 atmci_request_end(mmc, host->mrq);
585 static void atmci_read_data_pio(struct atmel_mci *host)
587 struct scatterlist *sg = host->sg;
588 void *buf = sg_virt(sg);
589 unsigned int offset = host->pio_offset;
590 struct mmc_data *data = host->data;
593 unsigned int nbytes = 0;
596 value = mci_readl(host, RDR);
597 if (likely(offset + 4 <= sg->length)) {
598 put_unaligned(value, (u32 *)(buf + offset));
603 if (offset == sg->length) {
604 host->sg = sg = sg_next(sg);
612 unsigned int remaining = sg->length - offset;
613 memcpy(buf + offset, &value, remaining);
616 flush_dcache_page(sg_page(sg));
617 host->sg = sg = sg_next(sg);
621 offset = 4 - remaining;
623 memcpy(buf, (u8 *)&value + remaining, offset);
627 status = mci_readl(host, SR);
628 if (status & ATMCI_DATA_ERROR_FLAGS) {
629 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY
630 | ATMCI_DATA_ERROR_FLAGS));
631 host->data_status = status;
632 atmci_set_pending(host, EVENT_DATA_ERROR);
633 tasklet_schedule(&host->tasklet);
636 } while (status & MCI_RXRDY);
638 host->pio_offset = offset;
639 data->bytes_xfered += nbytes;
644 mci_writel(host, IDR, MCI_RXRDY);
645 mci_writel(host, IER, MCI_NOTBUSY);
646 data->bytes_xfered += nbytes;
647 atmci_set_completed(host, EVENT_XFER_COMPLETE);
648 if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE)
649 && !atmci_test_and_set_completed(host, EVENT_STOP_SENT))
650 send_stop_cmd(host->mmc, data);
653 static void atmci_write_data_pio(struct atmel_mci *host)
655 struct scatterlist *sg = host->sg;
656 void *buf = sg_virt(sg);
657 unsigned int offset = host->pio_offset;
658 struct mmc_data *data = host->data;
661 unsigned int nbytes = 0;
664 if (likely(offset + 4 <= sg->length)) {
665 value = get_unaligned((u32 *)(buf + offset));
666 mci_writel(host, TDR, value);
670 if (offset == sg->length) {
671 host->sg = sg = sg_next(sg);
679 unsigned int remaining = sg->length - offset;
682 memcpy(&value, buf + offset, remaining);
685 host->sg = sg = sg_next(sg);
687 mci_writel(host, TDR, value);
691 offset = 4 - remaining;
693 memcpy((u8 *)&value + remaining, buf, offset);
694 mci_writel(host, TDR, value);
698 status = mci_readl(host, SR);
699 if (status & ATMCI_DATA_ERROR_FLAGS) {
700 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY
701 | ATMCI_DATA_ERROR_FLAGS));
702 host->data_status = status;
703 atmci_set_pending(host, EVENT_DATA_ERROR);
704 tasklet_schedule(&host->tasklet);
707 } while (status & MCI_TXRDY);
709 host->pio_offset = offset;
710 data->bytes_xfered += nbytes;
715 mci_writel(host, IDR, MCI_TXRDY);
716 mci_writel(host, IER, MCI_NOTBUSY);
717 data->bytes_xfered += nbytes;
718 atmci_set_completed(host, EVENT_XFER_COMPLETE);
719 if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE)
720 && !atmci_test_and_set_completed(host, EVENT_STOP_SENT))
721 send_stop_cmd(host->mmc, data);
724 static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
726 struct atmel_mci *host = mmc_priv(mmc);
728 mci_writel(host, IDR, MCI_CMDRDY);
730 if (atmci_is_completed(host, EVENT_STOP_SENT)) {
731 host->stop_status = status;
732 atmci_set_pending(host, EVENT_STOP_COMPLETE);
734 host->cmd_status = status;
735 atmci_set_pending(host, EVENT_CMD_COMPLETE);
738 tasklet_schedule(&host->tasklet);
741 static irqreturn_t atmci_interrupt(int irq, void *dev_id)
743 struct mmc_host *mmc = dev_id;
744 struct atmel_mci *host = mmc_priv(mmc);
745 u32 status, mask, pending;
746 unsigned int pass_count = 0;
748 spin_lock(&mmc->lock);
751 status = mci_readl(host, SR);
752 mask = mci_readl(host, IMR);
753 pending = status & mask;
757 if (pending & ATMCI_DATA_ERROR_FLAGS) {
758 mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS
759 | MCI_RXRDY | MCI_TXRDY);
760 pending &= mci_readl(host, IMR);
761 host->data_status = status;
762 atmci_set_pending(host, EVENT_DATA_ERROR);
763 tasklet_schedule(&host->tasklet);
765 if (pending & MCI_NOTBUSY) {
766 mci_writel(host, IDR, (MCI_NOTBUSY
767 | ATMCI_DATA_ERROR_FLAGS));
768 atmci_set_pending(host, EVENT_DATA_COMPLETE);
769 tasklet_schedule(&host->tasklet);
771 if (pending & MCI_RXRDY)
772 atmci_read_data_pio(host);
773 if (pending & MCI_TXRDY)
774 atmci_write_data_pio(host);
776 if (pending & MCI_CMDRDY)
777 atmci_cmd_interrupt(mmc, status);
778 } while (pass_count++ < 5);
780 spin_unlock(&mmc->lock);
782 return pass_count ? IRQ_HANDLED : IRQ_NONE;
785 static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id)
787 struct mmc_host *mmc = dev_id;
788 struct atmel_mci *host = mmc_priv(mmc);
791 * Disable interrupts until the pin has stabilized and check
792 * the state then. Use mod_timer() since we may be in the
793 * middle of the timer routine when this interrupt triggers.
795 disable_irq_nosync(irq);
796 mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(20));
801 static int __init atmci_probe(struct platform_device *pdev)
803 struct mci_platform_data *pdata;
804 struct atmel_mci *host;
805 struct mmc_host *mmc;
806 struct resource *regs;
810 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
813 pdata = pdev->dev.platform_data;
816 irq = platform_get_irq(pdev, 0);
820 mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
824 host = mmc_priv(mmc);
827 host->detect_pin = pdata->detect_pin;
828 host->wp_pin = pdata->wp_pin;
830 host->mck = clk_get(&pdev->dev, "mci_clk");
831 if (IS_ERR(host->mck)) {
832 ret = PTR_ERR(host->mck);
837 host->regs = ioremap(regs->start, regs->end - regs->start + 1);
841 clk_enable(host->mck);
842 mci_writel(host, CR, MCI_CR_SWRST);
843 host->bus_hz = clk_get_rate(host->mck);
844 clk_disable(host->mck);
846 host->mapbase = regs->start;
848 mmc->ops = &atmci_ops;
849 mmc->f_min = (host->bus_hz + 511) / 512;
850 mmc->f_max = host->bus_hz / 2;
851 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
852 mmc->caps |= MMC_CAP_4_BIT_DATA;
854 mmc->max_hw_segs = 64;
855 mmc->max_phys_segs = 64;
856 mmc->max_req_size = 32768 * 512;
857 mmc->max_blk_size = 32768;
858 mmc->max_blk_count = 512;
860 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
862 ret = request_irq(irq, atmci_interrupt, 0, pdev->dev.bus_id, mmc);
864 goto err_request_irq;
866 /* Assume card is present if we don't have a detect pin */
868 if (host->detect_pin >= 0) {
869 if (gpio_request(host->detect_pin, "mmc_detect")) {
870 dev_dbg(&mmc->class_dev, "no detect pin available\n");
871 host->detect_pin = -1;
873 host->present = !gpio_get_value(host->detect_pin);
876 if (host->wp_pin >= 0) {
877 if (gpio_request(host->wp_pin, "mmc_wp")) {
878 dev_dbg(&mmc->class_dev, "no WP pin available\n");
883 platform_set_drvdata(pdev, host);
887 if (host->detect_pin >= 0) {
888 setup_timer(&host->detect_timer, atmci_detect_change,
889 (unsigned long)host);
891 ret = request_irq(gpio_to_irq(host->detect_pin),
892 atmci_detect_interrupt,
893 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
896 dev_dbg(&mmc->class_dev,
897 "could not request IRQ %d for detect pin\n",
898 gpio_to_irq(host->detect_pin));
899 gpio_free(host->detect_pin);
900 host->detect_pin = -1;
904 dev_info(&mmc->class_dev,
905 "Atmel MCI controller at 0x%08lx irq %d\n",
919 static int __exit atmci_remove(struct platform_device *pdev)
921 struct atmel_mci *host = platform_get_drvdata(pdev);
923 platform_set_drvdata(pdev, NULL);
926 if (host->detect_pin >= 0) {
927 int pin = host->detect_pin;
929 /* Make sure the timer doesn't enable the interrupt */
930 host->detect_pin = -1;
933 free_irq(gpio_to_irq(pin), host->mmc);
934 del_timer_sync(&host->detect_timer);
938 mmc_remove_host(host->mmc);
940 clk_enable(host->mck);
941 mci_writel(host, IDR, ~0UL);
942 mci_writel(host, CR, MCI_CR_MCIDIS);
944 clk_disable(host->mck);
946 if (host->wp_pin >= 0)
947 gpio_free(host->wp_pin);
949 free_irq(platform_get_irq(pdev, 0), host->mmc);
954 mmc_free_host(host->mmc);
959 static struct platform_driver atmci_driver = {
960 .remove = __exit_p(atmci_remove),
966 static int __init atmci_init(void)
968 return platform_driver_probe(&atmci_driver, atmci_probe);
971 static void __exit atmci_exit(void)
973 platform_driver_unregister(&atmci_driver);
976 module_init(atmci_init);
977 module_exit(atmci_exit);
979 MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
980 MODULE_AUTHOR("Haavard Skinnemoen <haavard.skinnemoen@atmel.com>");
981 MODULE_LICENSE("GPL v2");