spi: add slave supprot
authorhhb <hhb@rock-chips.com>
Tue, 12 Mar 2013 02:37:26 +0000 (10:37 +0800)
committerhhb <hhb@rock-chips.com>
Tue, 12 Mar 2013 02:37:26 +0000 (10:37 +0800)
drivers/spi/rk29_spim.c
drivers/spi/rk29_spim.h

index a314787e71cb53a9ac115e48c98ea4e2aafa469d..e8a02cbe28a79574fe702ce736ecdddc9698e790 100755 (executable)
@@ -73,7 +73,7 @@ struct chip_data {
        u8 type;                /* SPI/SSP/MicroWire */\r
 \r
        u8 poll_mode;           /* 1 means use poll mode */\r
-\r
+       u8 slave_enable;\r
        u32 dma_width;\r
        u32 rx_threshold;\r
        u32 tx_threshold;\r
@@ -270,7 +270,12 @@ static void transfer_complete(struct rk29xx_spi *dws);
 static void wait_till_not_busy(struct rk29xx_spi *dws)\r
 {\r
        unsigned long end = jiffies + 1 + usecs_to_jiffies(1000);\r
-\r
+       //if spi was slave, it is SR_BUSY always.  \r
+       if(dws->cur_chip) {\r
+               if(dws->cur_chip->slave_enable == 1)\r
+                       return;\r
+       }\r
+       \r
        while (time_before(jiffies, end)) {\r
                if (!(rk29xx_readw(dws, SPIM_SR) & SR_BUSY))\r
                        return;\r
@@ -613,6 +618,7 @@ static void giveback(struct rk29xx_spi *dws)
        dws->prev_chip = dws->cur_chip;\r
        dws->cur_chip = NULL;\r
        dws->dma_mapped = 0;\r
+\r
        \r
        /*it is important to close intterrupt*/\r
        spi_mask_intr(dws, 0xff);\r
@@ -901,9 +907,11 @@ static void pump_transfers(unsigned long data)
                        chip->tmode = SPI_TMOD_TO;\r
 \r
                cr0 &= ~(0x3 << SPI_MODE_OFFSET);               \r
-               cr0 &= ~(0x3 << SPI_TMOD_OFFSET);       \r
+               cr0 &= ~(0x3 << SPI_TMOD_OFFSET);\r
+               cr0 &= ~(0x1 << SPI_OPMOD_OFFSET);      \r
                cr0 |= (spi->mode << SPI_MODE_OFFSET);\r
                cr0 |= (chip->tmode << SPI_TMOD_OFFSET);\r
+               cr0 |= ((chip->slave_enable & 1) << SPI_OPMOD_OFFSET);\r
        } \r
 \r
        /*\r
@@ -943,10 +951,11 @@ static void pump_transfers(unsigned long data)
                spi_chip_sel(dws, spi->chip_select);\r
 \r
         rk29xx_writew(dws, SPIM_CTRLR1, dws->len-1);\r
-               spi_enable_chip(dws, 1);\r
-\r
+               \r
                if (txint_level)\r
                        rk29xx_writew(dws, SPIM_TXFTLR, txint_level);\r
+               spi_enable_chip(dws, 1);        \r
+                       \r
                if (rxint_level)\r
                        rk29xx_writew(dws, SPIM_RXFTLR, rxint_level);\r
                /* Set the interrupt mask, for poll mode just diable all int */\r
@@ -1111,9 +1120,11 @@ static void dma_transfer(struct rk29xx_spi *dws)
                        chip->tmode = SPI_TMOD_TO;\r
 \r
                cr0 &= ~(0x3 << SPI_MODE_OFFSET);\r
-               cr0 &= ~(0x3 << SPI_TMOD_OFFSET);               \r
-               cr0 |= (chip->mode << SPI_MODE_OFFSET);\r
+               cr0 &= ~(0x3 << SPI_TMOD_OFFSET);\r
+               cr0 &= ~(0x1 << SPI_OPMOD_OFFSET);              \r
+               cr0 |= (spi->mode << SPI_MODE_OFFSET);\r
                cr0 |= (chip->tmode << SPI_TMOD_OFFSET);\r
+               cr0 |= ((chip->slave_enable & 1) << SPI_OPMOD_OFFSET);\r
        }\r
 \r
        /*\r
@@ -1730,7 +1741,7 @@ static int rk29xx_spi_setup(struct spi_device *spi)
 \r
                chip->poll_mode = chip_info->poll_mode;\r
                chip->type = chip_info->type;\r
-\r
+               chip->slave_enable = chip_info->slave_enable;\r
                chip->rx_threshold = 0;\r
                chip->tx_threshold = 0;\r
 \r
index d417bc8ce94644cf5e8394dc89c193c69378beae..073c434a7929063290d70b0f588266f44cb1d726 100755 (executable)
 \r
 #define SPI_SCOL_OFFSET                        7                  /* Serial Clock Polarity */\r
 \r
+#define SPI_OPMOD_OFFSET           20\r
+#define SPI_OPMOD_MASTER        0\r
+#define SPI_OPMOD_SLAVE         1\r
+\r
 #define SPI_TMOD_OFFSET                        18                 /* Transfer Mode */\r
 #define        SPI_TMOD_TR                         0x00                       /* xmit & recv */\r
 #define SPI_TMOD_TO                        0x01                       /* xmit only */\r
@@ -254,6 +258,7 @@ struct rk29xx_spi_chip {
        u8 poll_mode;   /* 0 for contoller polling mode */\r
        u8 type;        /* SPI/SSP/Micrwire */\r
        u8 enable_dma;\r
+       u8 slave_enable;\r
        void (*cs_control)(struct rk29xx_spi *dws, u32 cs, u8 flag);\r
 };\r
 \r