Merge branch 'hwmon-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[pandora-kernel.git] / drivers / mmc / at91_mci.c
index d500b6b..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>
@@ -72,9 +73,9 @@
 #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"
 
@@ -147,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];
@@ -155,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);
 
@@ -206,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;
                        }
@@ -229,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);
                }
        }
 
@@ -265,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;
 
@@ -284,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);
        }
@@ -298,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");
@@ -315,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);
@@ -339,7 +344,9 @@ static void at91_mci_enable(struct at91mci_host *host)
        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, AT91_MCI_PDCMODE | 0x34a);
-       at91_mci_write(host, AT91_MCI_SDCR, 0);
+
+       /* use Slot A or B (only one at same time) */
+       at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
 }
 
 /*
@@ -424,15 +431,15 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
                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);
@@ -445,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;
@@ -474,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;
                }
        }
@@ -490,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;
 }
@@ -637,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;
                }
        }
@@ -754,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);
@@ -787,7 +794,7 @@ 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;
@@ -816,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;
@@ -903,7 +913,7 @@ 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;
@@ -965,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         = {
@@ -977,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)