Merge branches 'misc', 'eeepc-laptop' and 'bugzilla-14445' into release
[safe/jmp/linux-2.6] / drivers / mmc / host / at91_mci.c
index e4d018b..63924e0 100644 (file)
 #include <asm/irq.h>
 #include <asm/gpio.h>
 
-#include <asm/mach/mmc.h>
-#include <asm/arch/board.h>
-#include <asm/arch/cpu.h>
-#include <asm/arch/at91_mci.h>
+#include <mach/board.h>
+#include <mach/cpu.h>
+#include <mach/at91_mci.h>
 
 #define DRIVER_NAME "at91_mci"
 
@@ -198,9 +197,14 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
        unsigned int len, i, size;
        unsigned *dmabuf = host->buffer;
 
-       size = host->total_length;
+       size = data->blksz * data->blocks;
        len = data->sg_len;
 
+       /* AT91SAM926[0/3] Data Write Operation and number of bytes erratum */
+       if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
+               if (host->total_length == 12)
+                       memset(dmabuf, 0, 12);
+
        /*
         * Just loop through all entries. Size might not
         * be the entire list though so make sure that
@@ -222,9 +226,10 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
 
                        for (index = 0; index < (amount / 4); index++)
                                *dmabuf++ = swab32(sgbuffer[index]);
-               }
-               else
+               } else {
                        memcpy(dmabuf, sgbuffer, amount);
+                       dmabuf += amount;
+               }
 
                kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
 
@@ -417,7 +422,7 @@ static void at91_mci_update_bytes_xfered(struct at91mci_host *host)
                        /* card is in IDLE mode now */
                        pr_debug("-> bytes_xfered %d, total_length = %d\n",
                                data->bytes_xfered, host->total_length);
-                       data->bytes_xfered = host->total_length;
+                       data->bytes_xfered = data->blksz * data->blocks;
                }
        }
 }
@@ -514,11 +519,19 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
 
        if (data) {
 
-               if ( cpu_is_at91rm9200() && (data->blksz & 0x3) ) {
-                       pr_debug("Unsupported block size\n");
-                       cmd->error = -EINVAL;
-                       mmc_request_done(host->mmc, host->request);
-                       return;
+               if (cpu_is_at91rm9200() || cpu_is_at91sam9261()) {
+                       if (data->blksz & 0x3) {
+                               pr_debug("Unsupported block size\n");
+                               cmd->error = -EINVAL;
+                               mmc_request_done(host->mmc, host->request);
+                               return;
+                       }
+                       if (data->flags & MMC_DATA_STREAM) {
+                               pr_debug("Stream commands not supported\n");
+                               cmd->error = -EINVAL;
+                               mmc_request_done(host->mmc, host->request);
+                               return;
+                       }
                }
 
                block_length = data->blksz;
@@ -565,13 +578,13 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
                ier = AT91_MCI_CMDRDY;
        } else {
                /* zero block length and PDC mode */
-               mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
+               mr = at91_mci_read(host, AT91_MCI_MR) & 0x5fff;
                mr |= (data->blksz & 0x3) ? AT91_MCI_PDCFBYTE : 0;
                mr |= (block_length << 16);
                mr |= AT91_MCI_PDCMODE;
                at91_mci_write(host, AT91_MCI_MR, mr);
 
-               if (!cpu_is_at91rm9200())
+               if (!(cpu_is_at91rm9200() || cpu_is_at91sam9261()))
                        at91_mci_write(host, AT91_MCI_BLKR,
                                AT91_MCI_BLKR_BCNT(blocks) |
                                AT91_MCI_BLKR_BLKLEN(block_length));
@@ -600,12 +613,28 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
                                 * Handle a write
                                 */
                                host->total_length = block_length * blocks;
-                               host->buffer = dma_alloc_coherent(NULL,
-                                               host->total_length,
-                                               &host->physical_address, GFP_KERNEL);
+                               /*
+                                * AT91SAM926[0/3] Data Write Operation and
+                                * number of bytes erratum
+                                */
+                               if (cpu_is_at91sam9260 () || cpu_is_at91sam9263())
+                                       if (host->total_length < 12)
+                                               host->total_length = 12;
+
+                               host->buffer = kmalloc(host->total_length, GFP_KERNEL);
+                               if (!host->buffer) {
+                                       pr_debug("Can't alloc tx buffer\n");
+                                       cmd->error = -ENOMEM;
+                                       mmc_request_done(host->mmc, host->request);
+                                       return;
+                               }
 
                                at91_mci_sg_to_dma(host, data);
 
+                               host->physical_address = dma_map_single(NULL,
+                                               host->buffer, host->total_length,
+                                               DMA_TO_DEVICE);
+
                                pr_debug("Transmitting %d bytes\n", host->total_length);
 
                                at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
@@ -673,7 +702,10 @@ static void at91_mci_completed_command(struct at91mci_host *host, unsigned int s
        cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3));
 
        if (host->buffer) {
-               dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address);
+               dma_unmap_single(NULL,
+                               host->physical_address, host->total_length,
+                               DMA_TO_DEVICE);
+               kfree(host->buffer);
                host->buffer = NULL;
        }
 
@@ -974,7 +1006,7 @@ static int __init at91_mci_probe(struct platform_device *pdev)
        mmc->f_min = 375000;
        mmc->f_max = 25000000;
        mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
-       mmc->caps = MMC_CAP_MULTIWRITE | MMC_CAP_SDIO_IRQ;
+       mmc->caps = MMC_CAP_SDIO_IRQ;
 
        mmc->max_blk_size = 4095;
        mmc->max_blk_count = mmc->max_req_size;
@@ -1055,6 +1087,8 @@ static int __init at91_mci_probe(struct platform_device *pdev)
                goto fail0;
        }
 
+       setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host);
+
        platform_set_drvdata(pdev, mmc);
 
        /*
@@ -1068,8 +1102,6 @@ static int __init at91_mci_probe(struct platform_device *pdev)
 
        mmc_add_host(mmc);
 
-       setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host);
-
        /*
         * monitor card insertion/removal if we can
         */