spi: tegra: correct directions when syncing buffer for device/dma.
Laxman Dewangan [Thu, 17 May 2012 11:19:57 +0000 (16:19 +0530)]
The Tx buffer to be synced with the direction of DMA_TO_DEVICE and
Rx buffer should be synced with direction of DMA_FROM_DEVICE.

bug 959947

Change-Id: I490a93e05723e3114c8ae3c640bb7eff23bcc75d
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/103095
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/spi/spi-tegra.c

index cfc6101..4901114 100644 (file)
@@ -441,7 +441,8 @@ static void spi_tegra_copy_client_txbuf_to_spi_txbuf(
 
        /* Make the dma buffer to read by cpu */
        dma_sync_single_for_cpu(&tspi->pdev->dev, tspi->tx_buf_phys,
-                               tspi->dma_buf_size, DMA_FROM_DEVICE);
+                               tspi->dma_buf_size, DMA_TO_DEVICE);
+
        if (tspi->is_packed) {
                len = tspi->curr_dma_words * tspi->bytes_per_word;
                memcpy(tspi->tx_buf, t->tx_buf + tspi->cur_pos, len);
@@ -461,6 +462,7 @@ static void spi_tegra_copy_client_txbuf_to_spi_txbuf(
                }
        }
        tspi->cur_tx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
+
        /* Make the dma buffer to read by dma */
        dma_sync_single_for_device(&tspi->pdev->dev, tspi->tx_buf_phys,
                                tspi->dma_buf_size, DMA_TO_DEVICE);
@@ -499,7 +501,7 @@ static void spi_tegra_copy_spi_rxbuf_to_client_rxbuf(
 
        /* Make the dma buffer to read by dma */
        dma_sync_single_for_device(&tspi->pdev->dev, tspi->rx_buf_phys,
-               tspi->dma_buf_size, DMA_TO_DEVICE);
+               tspi->dma_buf_size, DMA_FROM_DEVICE);
 }
 
 static int spi_tegra_start_dma_based_transfer(
@@ -547,9 +549,6 @@ static int spi_tegra_start_dma_based_transfer(
        if (tspi->cur_direction & DATA_DIR_TX) {
                spi_tegra_copy_client_txbuf_to_spi_txbuf(tspi, t);
                wmb();
-               /* Make the dma buffer to read by dma */
-               dma_sync_single_for_device(&tspi->pdev->dev, tspi->tx_buf_phys,
-                               tspi->dma_buf_size, DMA_TO_DEVICE);
                tspi->tx_dma_req.size = len;
                ret = tegra_dma_enqueue_req(tspi->tx_dma, &tspi->tx_dma_req);
                if (ret < 0) {
@@ -567,7 +566,8 @@ static int spi_tegra_start_dma_based_transfer(
        if (tspi->cur_direction & DATA_DIR_RX) {
                /* Make the dma buffer to read by dma */
                dma_sync_single_for_device(&tspi->pdev->dev, tspi->rx_buf_phys,
-                               tspi->dma_buf_size, DMA_TO_DEVICE);
+                               tspi->dma_buf_size, DMA_FROM_DEVICE);
+
                tspi->rx_dma_req.size = len;
                ret = tegra_dma_enqueue_req(tspi->rx_dma, &tspi->rx_dma_req);
                if (ret < 0) {
@@ -1344,10 +1344,6 @@ static int __init spi_tegra_probe(struct platform_device *pdev)
                goto fail_rx_buf_alloc;
        }
 
-       /* Make the dma buffer to read by dma */
-       dma_sync_single_for_device(&tspi->pdev->dev, tspi->rx_buf_phys,
-                               tspi->dma_buf_size, DMA_TO_DEVICE);
-
        memset(&tspi->rx_dma_req, 0, sizeof(struct tegra_dma_req));
        tspi->rx_dma_req.complete = tegra_spi_rx_dma_complete;
        tspi->rx_dma_req.to_memory = 1;
@@ -1377,10 +1373,6 @@ static int __init spi_tegra_probe(struct platform_device *pdev)
                goto fail_tx_buf_alloc;
        }
 
-       /* Make the dma buffer to read by dma */
-       dma_sync_single_for_device(&tspi->pdev->dev, tspi->tx_buf_phys,
-                               tspi->dma_buf_size, DMA_TO_DEVICE);
-
        memset(&tspi->tx_dma_req, 0, sizeof(struct tegra_dma_req));
        tspi->tx_dma_req.complete = tegra_spi_tx_dma_complete;
        tspi->tx_dma_req.to_memory = 0;