]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/spi/omap2_mcspi.c
V4L/DVB (12534): soc-camera: V4L2 API compliant scaling (S_FMT) and cropping (S_CROP)
[mv-sheeva.git] / drivers / spi / omap2_mcspi.c
index b4f3b753d0f453116f7efb2c355cfdd9ef314a0c..9b80ad36dbbad224c28d89475d0f91e8794d826b 100644 (file)
@@ -59,6 +59,8 @@
 
 /* per-register bitmasks: */
 
+#define OMAP2_MCSPI_SYSCONFIG_SMARTIDLE        (2 << 3)
+#define OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP        (1 << 2)
 #define OMAP2_MCSPI_SYSCONFIG_AUTOIDLE (1 << 0)
 #define OMAP2_MCSPI_SYSCONFIG_SOFTRESET        (1 << 1)
 
@@ -90,6 +92,7 @@
 
 #define OMAP2_MCSPI_CHCTRL_EN          (1 << 0)
 
+#define OMAP2_MCSPI_WAKEUPENABLE_WKEN  (1 << 0)
 
 /* We have 2 DMA channels per CS, one for RX and one for TX */
 struct omap2_mcspi_dma {
@@ -269,7 +272,7 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
 
        if (rx != NULL) {
                omap_set_dma_transfer_params(mcspi_dma->dma_rx_channel,
-                               data_type, element_count, 1,
+                               data_type, element_count - 1, 1,
                                OMAP_DMA_SYNC_ELEMENT,
                                mcspi_dma->dma_rx_sync_dev, 1);
 
@@ -300,6 +303,25 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
        if (rx != NULL) {
                wait_for_completion(&mcspi_dma->dma_rx_completion);
                dma_unmap_single(NULL, xfer->rx_dma, count, DMA_FROM_DEVICE);
+               omap2_mcspi_set_enable(spi, 0);
+               if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0)
+                               & OMAP2_MCSPI_CHSTAT_RXS)) {
+                       u32 w;
+
+                       w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
+                       if (word_len <= 8)
+                               ((u8 *)xfer->rx_buf)[element_count - 1] = w;
+                       else if (word_len <= 16)
+                               ((u16 *)xfer->rx_buf)[element_count - 1] = w;
+                       else /* word_len <= 32 */
+                               ((u32 *)xfer->rx_buf)[element_count - 1] = w;
+               } else {
+                       dev_err(&spi->dev, "DMA RX last word empty");
+                       count -= (word_len <= 8)  ? 1 :
+                                (word_len <= 16) ? 2 :
+                              /* word_len <= 32 */ 4;
+               }
+               omap2_mcspi_set_enable(spi, 1);
        }
        return count;
 }
@@ -603,9 +625,6 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
        return 0;
 }
 
-/* the spi->mode bits understood by this driver: */
-#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
-
 static int omap2_mcspi_setup(struct spi_device *spi)
 {
        int                     ret;
@@ -613,12 +632,6 @@ static int omap2_mcspi_setup(struct spi_device *spi)
        struct omap2_mcspi_dma  *mcspi_dma;
        struct omap2_mcspi_cs   *cs = spi->controller_state;
 
-       if (spi->mode & ~MODEBITS) {
-               dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
-                       spi->mode & ~MODEBITS);
-               return -EINVAL;
-       }
-
        if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
                dev_dbg(&spi->dev, "setup: unsupported %d bit words\n",
                        spi->bits_per_word);
@@ -882,8 +895,12 @@ static int __init omap2_mcspi_reset(struct omap2_mcspi *mcspi)
        } while (!(tmp & OMAP2_MCSPI_SYSSTATUS_RESETDONE));
 
        mcspi_write_reg(master, OMAP2_MCSPI_SYSCONFIG,
-                       /* (3 << 8) | (2 << 3) | */
-                       OMAP2_MCSPI_SYSCONFIG_AUTOIDLE);
+                       OMAP2_MCSPI_SYSCONFIG_AUTOIDLE |
+                       OMAP2_MCSPI_SYSCONFIG_ENAWAKEUP |
+                       OMAP2_MCSPI_SYSCONFIG_SMARTIDLE);
+
+       mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE,
+                       OMAP2_MCSPI_WAKEUPENABLE_WKEN);
 
        omap2_mcspi_set_master_mode(master);
 
@@ -982,6 +999,9 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
+       /* the spi->mode bits understood by this driver: */
+       master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+
        if (pdev->id != -1)
                master->bus_num = pdev->id;