netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / drivers / spi / au1550_spi.c
index 87b73e0..cfd5ff9 100644 (file)
@@ -237,8 +237,14 @@ static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
        unsigned bpw, hz;
        u32 cfg, stat;
 
-       bpw = t ? t->bits_per_word : spi->bits_per_word;
-       hz = t ? t->speed_hz : spi->max_speed_hz;
+       bpw = spi->bits_per_word;
+       hz = spi->max_speed_hz;
+       if (t) {
+               if (t->bits_per_word)
+                       bpw = t->bits_per_word;
+               if (t->speed_hz)
+                       hz = t->speed_hz;
+       }
 
        if (bpw < 4 || bpw > 24) {
                dev_err(&spi->dev, "setupxfer: invalid bits_per_word=%d\n",
@@ -284,27 +290,16 @@ static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
        return 0;
 }
 
-/* the spi->mode bits understood by this driver: */
-#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST)
-
 static int au1550_spi_setup(struct spi_device *spi)
 {
        struct au1550_spi *hw = spi_master_get_devdata(spi->master);
 
-       if (spi->bits_per_word == 0)
-               spi->bits_per_word = 8;
        if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
                dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
                        spi->bits_per_word);
                return -EINVAL;
        }
 
-       if (spi->mode & ~MODEBITS) {
-               dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
-                       spi->mode & ~MODEBITS);
-               return -EINVAL;
-       }
-
        if (spi->max_speed_hz == 0)
                spi->max_speed_hz = hw->freq_max;
        if (spi->max_speed_hz > hw->freq_max
@@ -369,10 +364,23 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
        dma_rx_addr = t->rx_dma;
 
        /*
-        * check if buffers are already dma mapped, map them otherwise
+        * check if buffers are already dma mapped, map them otherwise:
+        * - first map the TX buffer, so cache data gets written to memory
+        * - then map the RX buffer, so that cache entries (with
+        *   soon-to-be-stale data) get removed
         * use rx buffer in place of tx if tx buffer was not provided
         * use temp rx buffer (preallocated or realloc to fit) for rx dma
         */
+       if (t->tx_buf) {
+               if (t->tx_dma == 0) {   /* if DMA_ADDR_INVALID, map it */
+                       dma_tx_addr = dma_map_single(hw->dev,
+                                       (void *)t->tx_buf,
+                                       t->len, DMA_TO_DEVICE);
+                       if (dma_mapping_error(hw->dev, dma_tx_addr))
+                               dev_err(hw->dev, "tx dma map error\n");
+               }
+       }
+
        if (t->rx_buf) {
                if (t->rx_dma == 0) {   /* if DMA_ADDR_INVALID, map it */
                        dma_rx_addr = dma_map_single(hw->dev,
@@ -396,15 +404,8 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
                dma_sync_single_for_device(hw->dev, dma_rx_addr,
                        t->len, DMA_FROM_DEVICE);
        }
-       if (t->tx_buf) {
-               if (t->tx_dma == 0) {   /* if DMA_ADDR_INVALID, map it */
-                       dma_tx_addr = dma_map_single(hw->dev,
-                                       (void *)t->tx_buf,
-                                       t->len, DMA_TO_DEVICE);
-                       if (dma_mapping_error(hw->dev, dma_tx_addr))
-                               dev_err(hw->dev, "tx dma map error\n");
-               }
-       } else {
+
+       if (!t->tx_buf) {
                dma_sync_single_for_device(hw->dev, dma_rx_addr,
                                t->len, DMA_BIDIRECTIONAL);
                hw->tx = hw->rx;
@@ -775,6 +776,9 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
                goto err_nomem;
        }
 
+       /* the spi->mode bits understood by this driver: */
+       master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
+
        hw = spi_master_get_devdata(master);
 
        hw->master = spi_master_get(master);