Merge remote-tracking branches 'spi/topic/rockchip', 'spi/topic/rspi', 'spi/topic...
[sfrench/cifs-2.6.git] / drivers / spi / spi-s3c64xx.c
index 186342b74141432558bb405e865398a370b2fda4..b392cca8fa4f5ba3c1c499ea8b1bc228fcabdbee 100644 (file)
@@ -341,50 +341,16 @@ static void s3c64xx_spi_set_cs(struct spi_device *spi, bool enable)
 static int s3c64xx_spi_prepare_transfer(struct spi_master *spi)
 {
        struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
-       dma_filter_fn filter = sdd->cntrlr_info->filter;
-       struct device *dev = &sdd->pdev->dev;
-       dma_cap_mask_t mask;
 
        if (is_polling(sdd))
                return 0;
 
-       dma_cap_zero(mask);
-       dma_cap_set(DMA_SLAVE, mask);
-
-       /* Acquire DMA channels */
-       sdd->rx_dma.ch = dma_request_slave_channel_compat(mask, filter,
-                          sdd->cntrlr_info->dma_rx, dev, "rx");
-       if (!sdd->rx_dma.ch) {
-               dev_err(dev, "Failed to get RX DMA channel\n");
-               return -EBUSY;
-       }
        spi->dma_rx = sdd->rx_dma.ch;
-
-       sdd->tx_dma.ch = dma_request_slave_channel_compat(mask, filter,
-                          sdd->cntrlr_info->dma_tx, dev, "tx");
-       if (!sdd->tx_dma.ch) {
-               dev_err(dev, "Failed to get TX DMA channel\n");
-               dma_release_channel(sdd->rx_dma.ch);
-               return -EBUSY;
-       }
        spi->dma_tx = sdd->tx_dma.ch;
 
        return 0;
 }
 
-static int s3c64xx_spi_unprepare_transfer(struct spi_master *spi)
-{
-       struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi);
-
-       /* Free DMA channels */
-       if (!is_polling(sdd)) {
-               dma_release_channel(sdd->rx_dma.ch);
-               dma_release_channel(sdd->tx_dma.ch);
-       }
-
-       return 0;
-}
-
 static bool s3c64xx_spi_can_dma(struct spi_master *master,
                                struct spi_device *spi,
                                struct spi_transfer *xfer)
@@ -1091,11 +1057,6 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
 
        sdd->cur_bpw = 8;
 
-       if (!sdd->pdev->dev.of_node && (!sci->dma_tx || !sci->dma_rx)) {
-               dev_warn(&pdev->dev, "Unable to get SPI tx/rx DMA data. Switching to poll mode\n");
-               sdd->port_conf->quirks = S3C64XX_SPI_QUIRK_POLL;
-       }
-
        sdd->tx_dma.direction = DMA_MEM_TO_DEV;
        sdd->rx_dma.direction = DMA_DEV_TO_MEM;
 
@@ -1106,7 +1067,6 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
        master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer;
        master->prepare_message = s3c64xx_spi_prepare_message;
        master->transfer_one = s3c64xx_spi_transfer_one;
-       master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer;
        master->num_chipselect = sci->num_cs;
        master->dma_alignment = 8;
        master->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) |
@@ -1173,6 +1133,24 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
                }
        }
 
+       if (!is_polling(sdd)) {
+               /* Acquire DMA channels */
+               sdd->rx_dma.ch = dma_request_slave_channel_reason(&pdev->dev,
+                                                                 "rx");
+               if (IS_ERR(sdd->rx_dma.ch)) {
+                       dev_err(&pdev->dev, "Failed to get RX DMA channel\n");
+                       ret = PTR_ERR(sdd->rx_dma.ch);
+                       goto err_disable_io_clk;
+               }
+               sdd->tx_dma.ch = dma_request_slave_channel_reason(&pdev->dev,
+                                                                 "tx");
+               if (IS_ERR(sdd->tx_dma.ch)) {
+                       dev_err(&pdev->dev, "Failed to get TX DMA channel\n");
+                       ret = PTR_ERR(sdd->tx_dma.ch);
+                       goto err_release_rx_dma;
+               }
+       }
+
        pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
        pm_runtime_use_autosuspend(&pdev->dev);
        pm_runtime_set_active(&pdev->dev);
@@ -1205,9 +1183,8 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
 
        dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d with %d Slaves attached\n",
                                        sdd->port_id, master->num_chipselect);
-       dev_dbg(&pdev->dev, "\tIOmem=[%pR]\tFIFO %dbytes\tDMA=[Rx-%p, Tx-%p]\n",
-                                       mem_res, (FIFO_LVL_MASK(sdd) >> 1) + 1,
-                                       sci->dma_rx, sci->dma_tx);
+       dev_dbg(&pdev->dev, "\tIOmem=[%pR]\tFIFO %dbytes\n",
+                                       mem_res, (FIFO_LVL_MASK(sdd) >> 1) + 1);
 
        pm_runtime_mark_last_busy(&pdev->dev);
        pm_runtime_put_autosuspend(&pdev->dev);
@@ -1219,6 +1196,12 @@ err_pm_put:
        pm_runtime_disable(&pdev->dev);
        pm_runtime_set_suspended(&pdev->dev);
 
+       if (!is_polling(sdd))
+               dma_release_channel(sdd->tx_dma.ch);
+err_release_rx_dma:
+       if (!is_polling(sdd))
+               dma_release_channel(sdd->rx_dma.ch);
+err_disable_io_clk:
        clk_disable_unprepare(sdd->ioclk);
 err_disable_src_clk:
        clk_disable_unprepare(sdd->src_clk);
@@ -1239,6 +1222,11 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
 
        writel(0, sdd->regs + S3C64XX_SPI_INT_EN);
 
+       if (!is_polling(sdd)) {
+               dma_release_channel(sdd->rx_dma.ch);
+               dma_release_channel(sdd->tx_dma.ch);
+       }
+
        clk_disable_unprepare(sdd->ioclk);
 
        clk_disable_unprepare(sdd->src_clk);