memstick: automatically retrieve "INT" value from command response
[sfrench/cifs-2.6.git] / drivers / memstick / host / jmb38x_ms.c
index 03fe8783b1ee0f41dace3f7f4a37a2c597a51050..f91037d50422e0ba9fa02f18b22704632c301999 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <linux/delay.h>
 #include <linux/highmem.h>
 #include <linux/memstick.h>
@@ -56,8 +57,6 @@ struct jmb38x_ms_host {
        unsigned long           timeout_jiffies;
        struct timer_list       timer;
        struct memstick_request *req;
-       unsigned char           eject:1,
-                               use_dma:1;
        unsigned char           cmd_flags;
        unsigned char           io_pos;
        unsigned int            io_word[2];
@@ -94,9 +93,22 @@ struct jmb38x_ms {
 #define HOST_CONTROL_IF_PAR4   0x1
 #define HOST_CONTROL_IF_PAR8   0x3
 
+#define STATUS_BUSY             0x00080000
+#define STATUS_MS_DAT7          0x00040000
+#define STATUS_MS_DAT6          0x00020000
+#define STATUS_MS_DAT5          0x00010000
+#define STATUS_MS_DAT4          0x00008000
+#define STATUS_MS_DAT3          0x00004000
+#define STATUS_MS_DAT2          0x00002000
+#define STATUS_MS_DAT1          0x00001000
+#define STATUS_MS_DAT0          0x00000800
 #define STATUS_HAS_MEDIA        0x00000400
 #define STATUS_FIFO_EMPTY       0x00000200
 #define STATUS_FIFO_FULL        0x00000100
+#define STATUS_MS_CED           0x00000080
+#define STATUS_MS_ERR           0x00000040
+#define STATUS_MS_BRQ           0x00000020
+#define STATUS_MS_CNK           0x00000001
 
 #define INT_STATUS_TPC_ERR      0x00080000
 #define INT_STATUS_CRC_ERR      0x00040000
@@ -123,7 +135,7 @@ enum {
        CMD_READY    = 0x01,
        FIFO_READY   = 0x02,
        REG_DATA     = 0x04,
-       AUTO_GET_INT = 0x08
+       DMA_DATA     = 0x08
 };
 
 static unsigned int jmb38x_ms_read_data(struct jmb38x_ms_host *host,
@@ -273,7 +285,7 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host)
 {
        unsigned int length;
        unsigned int off;
-       unsigned int t_size, p_off, p_cnt;
+       unsigned int t_size, p_cnt;
        unsigned char *buf;
        struct page *pg;
        unsigned long flags = 0;
@@ -287,6 +299,8 @@ static int jmb38x_ms_transfer_data(struct jmb38x_ms_host *host)
        }
 
        while (length) {
+               unsigned int uninitialized_var(p_off);
+
                if (host->req->long_data) {
                        pg = nth_page(sg_page(&host->req->sg),
                                      off >> PAGE_SHIFT);
@@ -364,28 +378,27 @@ static int jmb38x_ms_issue_cmd(struct memstick_host *msh)
                cmd |= TPC_DIR;
        if (host->req->need_card_int)
                cmd |= TPC_WAIT_INT;
-       if (host->req->get_int_reg)
-               cmd |= TPC_GET_INT;
 
        data = host->req->data;
 
-       host->use_dma = !no_dma;
+       if (!no_dma)
+               host->cmd_flags |= DMA_DATA;
 
        if (host->req->long_data) {
                data_len = host->req->sg.length;
        } else {
                data_len = host->req->data_len;
-               host->use_dma = 0;
+               host->cmd_flags &= ~DMA_DATA;
        }
 
        if (data_len <= 8) {
                cmd &= ~(TPC_DATA_SEL | 0xf);
                host->cmd_flags |= REG_DATA;
                cmd |= data_len & 0xf;
-               host->use_dma = 0;
+               host->cmd_flags &= ~DMA_DATA;
        }
 
-       if (host->use_dma) {
+       if (host->cmd_flags & DMA_DATA) {
                if (1 != pci_map_sg(host->chip->pdev, &host->req->sg, 1,
                                    host->req->data_dir == READ
                                    ? PCI_DMA_FROMDEVICE
@@ -448,13 +461,12 @@ static void jmb38x_ms_complete_cmd(struct memstick_host *msh, int last)
                readl(host->addr + INT_STATUS));
        dev_dbg(msh->cdev.dev, "c hstatus %08x\n", readl(host->addr + STATUS));
 
-       if (host->req->get_int_reg) {
-               t_val = readl(host->addr + TPC_P0);
-               host->req->int_reg = (t_val & 0xff);
-       }
+       host->req->int_reg = readl(host->addr + STATUS) & 0xff;
 
-       if (host->use_dma) {
-               writel(0, host->addr + DMA_CONTROL);
+       writel(0, host->addr + BLOCK);
+       writel(0, host->addr + DMA_CONTROL);
+
+       if (host->cmd_flags & DMA_DATA) {
                pci_unmap_sg(host->chip->pdev, &host->req->sg, 1,
                             host->req->data_dir == READ
                             ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
@@ -506,7 +518,7 @@ static irqreturn_t jmb38x_ms_isr(int irq, void *dev_id)
                        else
                                host->req->error = -ETIME;
                } else {
-                       if (host->use_dma) {
+                       if (host->cmd_flags & DMA_DATA) {
                                if (irq_status & INT_STATUS_EOTRAN)
                                        host->cmd_flags |= FIFO_READY;
                        } else {
@@ -772,13 +784,10 @@ static struct memstick_host *jmb38x_ms_alloc_host(struct jmb38x_ms *jm, int cnt)
        snprintf(host->host_id, DEVICE_ID_SIZE, DRIVER_NAME ":slot%d",
                 host->id);
        host->irq = jm->pdev->irq;
-       host->timeout_jiffies = msecs_to_jiffies(4000);
+       host->timeout_jiffies = msecs_to_jiffies(1000);
        msh->request = jmb38x_ms_request;
        msh->set_param = jmb38x_ms_set_param;
-       /*
-       msh->caps = MEMSTICK_CAP_AUTO_GET_INT | MEMSTICK_CAP_PAR4
-                   | MEMSTICK_CAP_PAR8;
-       */
+
        msh->caps = MEMSTICK_CAP_PAR4 | MEMSTICK_CAP_PAR8;
 
        setup_timer(&host->timer, jmb38x_ms_abort, (unsigned long)msh);