Merge branch 'hwmon-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[pandora-kernel.git] / drivers / mmc / at91_mci.c
index cc05469..459f4b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  linux/drivers/mmc/at91_mci.c - ATMEL AT91RM9200 MCI Driver
+ *  linux/drivers/mmc/at91_mci.c - ATMEL AT91 MCI Driver
  *
  *  Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
  *
@@ -11,7 +11,7 @@
  */
 
 /*
-   This is the AT91RM9200 MCI driver that has been tested with both MMC cards
+   This is the AT91 MCI driver that has been tested with both MMC cards
    and SD-cards.  Boards that support write protect are now supported.
    The CCAT91SBC001 board does not support SD cards.
 
@@ -38,8 +38,8 @@
      controller to manage the transfers.
 
      A read is done from the controller directly to the scatterlist passed in from the request.
-     Due to a bug in the controller, when a read is completed, all the words are byte
-     swapped in the scatterlist buffers.
+     Due to a bug in the AT91RM9200 controller, when a read is completed, all the words are byte
+     swapped in the scatterlist buffers.  AT91SAM926x are not affected by this bug.
 
      The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY
 
@@ -64,6 +64,7 @@
 #include <linux/err.h>
 #include <linux/dma-mapping.h>
 #include <linux/clk.h>
+#include <linux/atmel_pdc.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/protocol.h>
 #include <asm/irq.h>
 #include <asm/mach/mmc.h>
 #include <asm/arch/board.h>
+#include <asm/arch/cpu.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/at91_mci.h>
-#include <asm/arch/at91_pdc.h>
 
 #define DRIVER_NAME "at91_mci"
 
 #undef SUPPORT_4WIRE
 
-static struct clk *mci_clk;
-
-#define FL_SENT_COMMAND (1 << 0)
-#define FL_SENT_STOP (1 << 1)
-
+#define FL_SENT_COMMAND        (1 << 0)
+#define FL_SENT_STOP   (1 << 1)
 
+#define AT91_MCI_ERRORS        (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE       \
+               | AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE               \
+               | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)                        
 
 #define at91_mci_read(host, reg)       __raw_readl((host)->baseaddr + (reg))
 #define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg))
@@ -101,10 +102,13 @@ struct at91mci_host
        struct mmc_request *request;
 
        void __iomem *baseaddr;
+       int irq;
 
        struct at91_mmc_data *board;
        int present;
 
+       struct clk *mci_clk;
+
        /*
         * Flag indicating when the command has been sent. This is used to
         * work out whether or not to send the stop
@@ -144,7 +148,6 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
        for (i = 0; i < len; i++) {
                struct scatterlist *sg;
                int amount;
-               int index;
                unsigned int *sgbuffer;
 
                sg = &data->sg[i];
@@ -152,10 +155,15 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
                sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
                amount = min(size, sg->length);
                size -= amount;
-               amount /= 4;
 
-               for (index = 0; index < amount; index++)
-                       *dmabuf++ = swab32(sgbuffer[index]);
+               if (cpu_is_at91rm9200()) {      /* AT91RM9200 errata */
+                       int index;
+
+                       for (index = 0; index < (amount / 4); index++)
+                               *dmabuf++ = swab32(sgbuffer[index]);
+               }
+               else
+                       memcpy(dmabuf, sgbuffer, amount);
 
                kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
 
@@ -203,13 +211,13 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
 
                /* Check to see if this needs filling */
                if (i == 0) {
-                       if (at91_mci_read(host, AT91_PDC_RCR) != 0) {
+                       if (at91_mci_read(host, ATMEL_PDC_RCR) != 0) {
                                pr_debug("Transfer active in current\n");
                                continue;
                        }
                }
                else {
-                       if (at91_mci_read(host, AT91_PDC_RNCR) != 0) {
+                       if (at91_mci_read(host, ATMEL_PDC_RNCR) != 0) {
                                pr_debug("Transfer active in next\n");
                                continue;
                        }
@@ -226,12 +234,12 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
                pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
 
                if (i == 0) {
-                       at91_mci_write(host, AT91_PDC_RPR, sg->dma_address);
-                       at91_mci_write(host, AT91_PDC_RCR, sg->length / 4);
+                       at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address);
+                       at91_mci_write(host, ATMEL_PDC_RCR, sg->length / 4);
                }
                else {
-                       at91_mci_write(host, AT91_PDC_RNPR, sg->dma_address);
-                       at91_mci_write(host, AT91_PDC_RNCR, sg->length / 4);
+                       at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address);
+                       at91_mci_write(host, ATMEL_PDC_RNCR, sg->length / 4);
                }
        }
 
@@ -262,8 +270,6 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
 
        while (host->in_use_index < host->transfer_index) {
                unsigned int *buffer;
-               int index;
-               int len;
 
                struct scatterlist *sg;
 
@@ -281,11 +287,13 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
 
                data->bytes_xfered += sg->length;
 
-               len = sg->length / 4;
+               if (cpu_is_at91rm9200()) {      /* AT91RM9200 errata */
+                       int index;
 
-               for (index = 0; index < len; index++) {
-                       buffer[index] = swab32(buffer[index]);
+                       for (index = 0; index < (sg->length / 4); index++)
+                               buffer[index] = swab32(buffer[index]);
                }
+
                kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
                flush_dcache_page(sg->page);
        }
@@ -295,7 +303,7 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
                at91mci_pre_dma_read(host);
        else {
                at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
-               at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
+               at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
        }
 
        pr_debug("post dma read done\n");
@@ -312,7 +320,7 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
        pr_debug("Handling the transmit\n");
 
        /* Disable the transfer */
-       at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
+       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
 
        /* Now wait for cmd ready */
        at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
@@ -333,10 +341,12 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
 static void at91_mci_enable(struct at91mci_host *host)
 {
        at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
-       at91_mci_write(host, AT91_MCI_IDR, 0xFFFFFFFF);
+       at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
        at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
-       at91_mci_write(host, AT91_MCI_MR, 0x834A);
-       at91_mci_write(host, AT91_MCI_SDCR, 0x0);
+       at91_mci_write(host, AT91_MCI_MR, AT91_MCI_PDCMODE | 0x34a);
+
+       /* use Slot A or B (only one at same time) */
+       at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
 }
 
 /*
@@ -417,19 +427,19 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
        /*
         * Set the arguments and send the command
         */
-       pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08lX)\n",
+       pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08X)\n",
                cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR));
 
        if (!data) {
-               at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS);
-               at91_mci_write(host, AT91_PDC_RPR, 0);
-               at91_mci_write(host, AT91_PDC_RCR, 0);
-               at91_mci_write(host, AT91_PDC_RNPR, 0);
-               at91_mci_write(host, AT91_PDC_RNCR, 0);
-               at91_mci_write(host, AT91_PDC_TPR, 0);
-               at91_mci_write(host, AT91_PDC_TCR, 0);
-               at91_mci_write(host, AT91_PDC_TNPR, 0);
-               at91_mci_write(host, AT91_PDC_TNCR, 0);
+               at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS | ATMEL_PDC_RXTDIS);
+               at91_mci_write(host, ATMEL_PDC_RPR, 0);
+               at91_mci_write(host, ATMEL_PDC_RCR, 0);
+               at91_mci_write(host, ATMEL_PDC_RNPR, 0);
+               at91_mci_write(host, ATMEL_PDC_RNCR, 0);
+               at91_mci_write(host, ATMEL_PDC_TPR, 0);
+               at91_mci_write(host, ATMEL_PDC_TCR, 0);
+               at91_mci_write(host, ATMEL_PDC_TNPR, 0);
+               at91_mci_write(host, ATMEL_PDC_TNCR, 0);
 
                at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
                at91_mci_write(host, AT91_MCI_CMDR, cmdr);
@@ -442,7 +452,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
        /*
         * Disable the PDC controller
         */
-       at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
+       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
 
        if (cmdr & AT91_MCI_TRCMD_START) {
                data->bytes_xfered = 0;
@@ -471,8 +481,8 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
 
                        pr_debug("Transmitting %d bytes\n", host->total_length);
 
-                       at91_mci_write(host, AT91_PDC_TPR, host->physical_address);
-                       at91_mci_write(host, AT91_PDC_TCR, host->total_length / 4);
+                       at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
+                       at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
                        ier = AT91_MCI_TXBUFE;
                }
        }
@@ -487,9 +497,9 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
 
        if (cmdr & AT91_MCI_TRCMD_START) {
                if (cmdr & AT91_MCI_TRDIR)
-                       at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTEN);
+                       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
                else
-                       at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTEN);
+                       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
        }
        return ier;
 }
@@ -506,7 +516,7 @@ static void at91mci_process_command(struct at91mci_host *host, struct mmc_comman
        pr_debug("setting ier to %08X\n", ier);
 
        /* Stop on errors or the required value */
-       at91_mci_write(host, AT91_MCI_IER, 0xffff0000 | ier);
+       at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
 }
 
 /*
@@ -597,7 +607,7 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 {
        int clkdiv;
        struct at91mci_host *host = mmc_priv(mmc);
-       unsigned long at91_master_clock = clk_get_rate(mci_clk);
+       unsigned long at91_master_clock = clk_get_rate(host->mci_clk);
 
        host->bus_mode = ios->bus_mode;
 
@@ -634,11 +644,11 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
        if (host->board->vcc_pin) {
                switch (ios->power_mode) {
                        case MMC_POWER_OFF:
-                               at91_set_gpio_output(host->board->vcc_pin, 0);
+                               at91_set_gpio_value(host->board->vcc_pin, 0);
                                break;
                        case MMC_POWER_UP:
                        case MMC_POWER_ON:
-                               at91_set_gpio_output(host->board->vcc_pin, 1);
+                               at91_set_gpio_value(host->board->vcc_pin, 1);
                                break;
                }
        }
@@ -651,39 +661,40 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
 {
        struct at91mci_host *host = devid;
        int completed = 0;
-
-       unsigned int int_status;
+       unsigned int int_status, int_mask;
 
        int_status = at91_mci_read(host, AT91_MCI_SR);
-       pr_debug("MCI irq: status = %08X, %08lX, %08lX\n", int_status, at91_mci_read(host, AT91_MCI_IMR),
-               int_status & at91_mci_read(host, AT91_MCI_IMR));
-
-       if ((int_status & at91_mci_read(host, AT91_MCI_IMR)) & 0xffff0000)
+       int_mask = at91_mci_read(host, AT91_MCI_IMR);
+       
+       pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask,
+               int_status & int_mask);
+       
+       int_status = int_status & int_mask;
+
+       if (int_status & AT91_MCI_ERRORS) {
                completed = 1;
+               
+               if (int_status & AT91_MCI_UNRE)
+                       pr_debug("MMC: Underrun error\n");
+               if (int_status & AT91_MCI_OVRE)
+                       pr_debug("MMC: Overrun error\n");
+               if (int_status & AT91_MCI_DTOE)
+                       pr_debug("MMC: Data timeout\n");
+               if (int_status & AT91_MCI_DCRCE)
+                       pr_debug("MMC: CRC error in data\n");
+               if (int_status & AT91_MCI_RTOE)
+                       pr_debug("MMC: Response timeout\n");
+               if (int_status & AT91_MCI_RENDE)
+                       pr_debug("MMC: Response end bit error\n");
+               if (int_status & AT91_MCI_RCRCE)
+                       pr_debug("MMC: Response CRC error\n");
+               if (int_status & AT91_MCI_RDIRE)
+                       pr_debug("MMC: Response direction error\n");
+               if (int_status & AT91_MCI_RINDE)
+                       pr_debug("MMC: Response index error\n");
+       } else {
+               /* Only continue processing if no errors */
 
-       int_status &= at91_mci_read(host, AT91_MCI_IMR);
-
-       if (int_status & AT91_MCI_UNRE)
-               pr_debug("MMC: Underrun error\n");
-       if (int_status & AT91_MCI_OVRE)
-               pr_debug("MMC: Overrun error\n");
-       if (int_status & AT91_MCI_DTOE)
-               pr_debug("MMC: Data timeout\n");
-       if (int_status & AT91_MCI_DCRCE)
-               pr_debug("MMC: CRC error in data\n");
-       if (int_status & AT91_MCI_RTOE)
-               pr_debug("MMC: Response timeout\n");
-       if (int_status & AT91_MCI_RENDE)
-               pr_debug("MMC: Response end bit error\n");
-       if (int_status & AT91_MCI_RCRCE)
-               pr_debug("MMC: Response CRC error\n");
-       if (int_status & AT91_MCI_RDIRE)
-               pr_debug("MMC: Response direction error\n");
-       if (int_status & AT91_MCI_RINDE)
-               pr_debug("MMC: Response index error\n");
-
-       /* Only continue processing if no errors */
-       if (!completed) {
                if (int_status & AT91_MCI_TXBUFE) {
                        pr_debug("TX buffer empty\n");
                        at91_mci_handle_transmitted(host);
@@ -694,9 +705,8 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
                        at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
                }
 
-               if (int_status & AT91_MCI_ENDTX) {
+               if (int_status & AT91_MCI_ENDTX)
                        pr_debug("Transmit has ended\n");
-               }
 
                if (int_status & AT91_MCI_ENDRX) {
                        pr_debug("Receive has ended\n");
@@ -708,34 +718,30 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
                        at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
                }
 
-               if (int_status & AT91_MCI_DTIP) {
+               if (int_status & AT91_MCI_DTIP)
                        pr_debug("Data transfer in progress\n");
-               }
 
-               if (int_status & AT91_MCI_BLKE) {
+               if (int_status & AT91_MCI_BLKE)
                        pr_debug("Block transfer has ended\n");
-               }
 
-               if (int_status & AT91_MCI_TXRDY) {
+               if (int_status & AT91_MCI_TXRDY)
                        pr_debug("Ready to transmit\n");
-               }
 
-               if (int_status & AT91_MCI_RXRDY) {
+               if (int_status & AT91_MCI_RXRDY)
                        pr_debug("Ready to receive\n");
-               }
 
                if (int_status & AT91_MCI_CMDRDY) {
                        pr_debug("Command ready\n");
                        completed = 1;
                }
        }
-       at91_mci_write(host, AT91_MCI_IDR, int_status);
 
        if (completed) {
                pr_debug("Completed command\n");
                at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
                at91mci_completed_command(host);
-       }
+       } else
+               at91_mci_write(host, AT91_MCI_IDR, int_status);
 
        return IRQ_HANDLED;
 }
@@ -755,14 +761,14 @@ static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
                        present ? "insert" : "remove");
                if (!present) {
                        pr_debug("****** Resetting SD-card bus width ******\n");
-                       at91_mci_write(host, AT91_MCI_SDCR, 0);
+                       at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
                }
                mmc_detect_change(host->mmc, msecs_to_jiffies(100));
        }
        return IRQ_HANDLED;
 }
 
-int at91_mci_get_ro(struct mmc_host *mmc)
+static int at91_mci_get_ro(struct mmc_host *mmc)
 {
        int read_only = 0;
        struct at91mci_host *host = mmc_priv(mmc);
@@ -788,17 +794,26 @@ static const struct mmc_host_ops at91_mci_ops = {
 /*
  * Probe for the device
  */
-static int at91_mci_probe(struct platform_device *pdev)
+static int __init at91_mci_probe(struct platform_device *pdev)
 {
        struct mmc_host *mmc;
        struct at91mci_host *host;
+       struct resource *res;
        int ret;
 
        pr_debug("Probe MCI devices\n");
 
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -ENXIO;
+
+       if (!request_mem_region(res->start, res->end - res->start + 1, DRIVER_NAME))
+               return -EBUSY;
+
        mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev);
        if (!mmc) {
                pr_debug("Failed to allocate mmc host\n");
+               release_mem_region(res->start, res->end - res->start + 1);
                return -ENOMEM;
        }
 
@@ -808,6 +823,9 @@ static int at91_mci_probe(struct platform_device *pdev)
        mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
        mmc->caps = MMC_CAP_BYTEBLOCK;
 
+       mmc->max_blk_size = 4095;
+       mmc->max_blk_count = mmc->max_req_size;
+
        host = mmc_priv(mmc);
        host->mmc = mmc;
        host->buffer = NULL;
@@ -817,38 +835,51 @@ static int at91_mci_probe(struct platform_device *pdev)
 #ifdef SUPPORT_4WIRE
                mmc->caps |= MMC_CAP_4_BIT_DATA;
 #else
-               printk("MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
+               printk("AT91 MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
 #endif
        }
 
        /*
         * Get Clock
         */
-       mci_clk = clk_get(&pdev->dev, "mci_clk");
-       if (IS_ERR(mci_clk)) {
+       host->mci_clk = clk_get(&pdev->dev, "mci_clk");
+       if (IS_ERR(host->mci_clk)) {
                printk(KERN_ERR "AT91 MMC: no clock defined.\n");
                mmc_free_host(mmc);
+               release_mem_region(res->start, res->end - res->start + 1);
                return -ENODEV;
        }
-       clk_enable(mci_clk);                    /* Enable the peripheral clock */
 
-       host->baseaddr = (void __iomem *)AT91_VA_BASE_MCI;
+       /*
+        * Map I/O region
+        */
+       host->baseaddr = ioremap(res->start, res->end - res->start + 1);
+       if (!host->baseaddr) {
+               clk_put(host->mci_clk);
+               mmc_free_host(mmc);
+               release_mem_region(res->start, res->end - res->start + 1);
+               return -ENOMEM;
+       }
 
        /*
         * Reset hardware
         */
+       clk_enable(host->mci_clk);              /* Enable the peripheral clock */
        at91_mci_disable(host);
        at91_mci_enable(host);
 
        /*
         * Allocate the MCI interrupt
         */
-       ret = request_irq(AT91RM9200_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host);
+       host->irq = platform_get_irq(pdev, 0);
+       ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host);
        if (ret) {
-               printk(KERN_ERR "Failed to request MCI interrupt\n");
-               clk_disable(mci_clk);
-               clk_put(mci_clk);
+               printk(KERN_ERR "AT91 MMC: Failed to request MCI interrupt\n");
+               clk_disable(host->mci_clk);
+               clk_put(host->mci_clk);
                mmc_free_host(mmc);
+               iounmap(host->baseaddr);
+               release_mem_region(res->start, res->end - res->start + 1);
                return ret;
        }
 
@@ -871,10 +902,10 @@ static int at91_mci_probe(struct platform_device *pdev)
                ret = request_irq(host->board->det_pin, at91_mmc_det_irq,
                                0, DRIVER_NAME, host);
                if (ret)
-                       printk(KERN_ERR "couldn't allocate MMC detect irq\n");
+                       printk(KERN_ERR "AT91 MMC: Couldn't allocate MMC detect irq\n");
        }
 
-       pr_debug(KERN_INFO "Added MCI driver\n");
+       pr_debug("Added MCI driver\n");
 
        return 0;
 }
@@ -882,10 +913,11 @@ static int at91_mci_probe(struct platform_device *pdev)
 /*
  * Remove a device
  */
-static int at91_mci_remove(struct platform_device *pdev)
+static int __exit at91_mci_remove(struct platform_device *pdev)
 {
        struct mmc_host *mmc = platform_get_drvdata(pdev);
        struct at91mci_host *host;
+       struct resource *res;
 
        if (!mmc)
                return -1;
@@ -897,16 +929,19 @@ static int at91_mci_remove(struct platform_device *pdev)
                cancel_delayed_work(&host->mmc->detect);
        }
 
-       mmc_remove_host(mmc);
        at91_mci_disable(host);
-       free_irq(AT91RM9200_ID_MCI, host);
-       mmc_free_host(mmc);
+       mmc_remove_host(mmc);
+       free_irq(host->irq, host);
 
-       clk_disable(mci_clk);                           /* Disable the peripheral clock */
-       clk_put(mci_clk);
+       clk_disable(host->mci_clk);                     /* Disable the peripheral clock */
+       clk_put(host->mci_clk);
 
-       platform_set_drvdata(pdev, NULL);
+       iounmap(host->baseaddr);
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       release_mem_region(res->start, res->end - res->start + 1);
 
+       mmc_free_host(mmc);
+       platform_set_drvdata(pdev, NULL);
        pr_debug("MCI Removed\n");
 
        return 0;
@@ -940,8 +975,7 @@ static int at91_mci_resume(struct platform_device *pdev)
 #endif
 
 static struct platform_driver at91_mci_driver = {
-       .probe          = at91_mci_probe,
-       .remove         = at91_mci_remove,
+       .remove         = __exit_p(at91_mci_remove),
        .suspend        = at91_mci_suspend,
        .resume         = at91_mci_resume,
        .driver         = {
@@ -952,7 +986,7 @@ static struct platform_driver at91_mci_driver = {
 
 static int __init at91_mci_init(void)
 {
-       return platform_driver_register(&at91_mci_driver);
+       return platform_driver_probe(&at91_mci_driver, at91_mci_probe);
 }
 
 static void __exit at91_mci_exit(void)