spi/pl022: remove function cannot exit
[linux-2.6.git] / drivers / spi / spi-pl022.c
index 2541705..730b4a3 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/scatterlist.h>
+#include <linux/pm_runtime.h>
 
 /*
  * This macro is used to define some register default values.
@@ -381,6 +382,8 @@ struct pl022 {
        enum ssp_reading                read;
        enum ssp_writing                write;
        u32                             exp_fifo_level;
+       enum ssp_rx_level_trig          rx_lev_trig;
+       enum ssp_tx_level_trig          tx_lev_trig;
        /* DMA settings */
 #ifdef CONFIG_DMA_ENGINE
        struct dma_chan                 *dma_rx_channel;
@@ -515,6 +518,7 @@ static void giveback(struct pl022 *pl022)
        clk_disable(pl022->clk);
        amba_pclk_disable(pl022->adev);
        amba_vcore_disable(pl022->adev);
+       pm_runtime_put(&pl022->adev->dev);
 }
 
 /**
@@ -907,12 +911,10 @@ static int configure_dma(struct pl022 *pl022)
        struct dma_slave_config rx_conf = {
                .src_addr = SSP_DR(pl022->phybase),
                .direction = DMA_FROM_DEVICE,
-               .src_maxburst = pl022->vendor->fifodepth >> 1,
        };
        struct dma_slave_config tx_conf = {
                .dst_addr = SSP_DR(pl022->phybase),
                .direction = DMA_TO_DEVICE,
-               .dst_maxburst = pl022->vendor->fifodepth >> 1,
        };
        unsigned int pages;
        int ret;
@@ -926,6 +928,54 @@ static int configure_dma(struct pl022 *pl022)
        if (!rxchan || !txchan)
                return -ENODEV;
 
+       /*
+        * If supplied, the DMA burstsize should equal the FIFO trigger level.
+        * Notice that the DMA engine uses one-to-one mapping. Since we can
+        * not trigger on 2 elements this needs explicit mapping rather than
+        * calculation.
+        */
+       switch (pl022->rx_lev_trig) {
+       case SSP_RX_1_OR_MORE_ELEM:
+               rx_conf.src_maxburst = 1;
+               break;
+       case SSP_RX_4_OR_MORE_ELEM:
+               rx_conf.src_maxburst = 4;
+               break;
+       case SSP_RX_8_OR_MORE_ELEM:
+               rx_conf.src_maxburst = 8;
+               break;
+       case SSP_RX_16_OR_MORE_ELEM:
+               rx_conf.src_maxburst = 16;
+               break;
+       case SSP_RX_32_OR_MORE_ELEM:
+               rx_conf.src_maxburst = 32;
+               break;
+       default:
+               rx_conf.src_maxburst = pl022->vendor->fifodepth >> 1;
+               break;
+       }
+
+       switch (pl022->tx_lev_trig) {
+       case SSP_TX_1_OR_MORE_EMPTY_LOC:
+               tx_conf.dst_maxburst = 1;
+               break;
+       case SSP_TX_4_OR_MORE_EMPTY_LOC:
+               tx_conf.dst_maxburst = 4;
+               break;
+       case SSP_TX_8_OR_MORE_EMPTY_LOC:
+               tx_conf.dst_maxburst = 8;
+               break;
+       case SSP_TX_16_OR_MORE_EMPTY_LOC:
+               tx_conf.dst_maxburst = 16;
+               break;
+       case SSP_TX_32_OR_MORE_EMPTY_LOC:
+               tx_conf.dst_maxburst = 32;
+               break;
+       default:
+               tx_conf.dst_maxburst = pl022->vendor->fifodepth >> 1;
+               break;
+       }
+
        switch (pl022->read) {
        case READING_NULL:
                /* Use the same as for writing */
@@ -1494,6 +1544,7 @@ static void pump_messages(struct work_struct *work)
         * and core will be disabled when giveback() is called in each method
         * (poll/interrupt/DMA)
         */
+       pm_runtime_get_sync(&pl022->adev->dev);
        amba_vcore_enable(pl022->adev);
        amba_pclk_enable(pl022->adev);
        clk_enable(pl022->clk);
@@ -1627,17 +1678,57 @@ static int verify_controller_parameters(struct pl022 *pl022,
                        "Communication mode is configured incorrectly\n");
                return -EINVAL;
        }
-       if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM)
-           || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) {
+       switch (chip_info->rx_lev_trig) {
+       case SSP_RX_1_OR_MORE_ELEM:
+       case SSP_RX_4_OR_MORE_ELEM:
+       case SSP_RX_8_OR_MORE_ELEM:
+               /* These are always OK, all variants can handle this */
+               break;
+       case SSP_RX_16_OR_MORE_ELEM:
+               if (pl022->vendor->fifodepth < 16) {
+                       dev_err(&pl022->adev->dev,
+                       "RX FIFO Trigger Level is configured incorrectly\n");
+                       return -EINVAL;
+               }
+               break;
+       case SSP_RX_32_OR_MORE_ELEM:
+               if (pl022->vendor->fifodepth < 32) {
+                       dev_err(&pl022->adev->dev,
+                       "RX FIFO Trigger Level is configured incorrectly\n");
+                       return -EINVAL;
+               }
+               break;
+       default:
                dev_err(&pl022->adev->dev,
                        "RX FIFO Trigger Level is configured incorrectly\n");
                return -EINVAL;
+               break;
        }
-       if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC)
-           || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) {
+       switch (chip_info->tx_lev_trig) {
+       case SSP_TX_1_OR_MORE_EMPTY_LOC:
+       case SSP_TX_4_OR_MORE_EMPTY_LOC:
+       case SSP_TX_8_OR_MORE_EMPTY_LOC:
+               /* These are always OK, all variants can handle this */
+               break;
+       case SSP_TX_16_OR_MORE_EMPTY_LOC:
+               if (pl022->vendor->fifodepth < 16) {
+                       dev_err(&pl022->adev->dev,
+                       "TX FIFO Trigger Level is configured incorrectly\n");
+                       return -EINVAL;
+               }
+               break;
+       case SSP_TX_32_OR_MORE_EMPTY_LOC:
+               if (pl022->vendor->fifodepth < 32) {
+                       dev_err(&pl022->adev->dev,
+                       "TX FIFO Trigger Level is configured incorrectly\n");
+                       return -EINVAL;
+               }
+               break;
+       default:
                dev_err(&pl022->adev->dev,
                        "TX FIFO Trigger Level is configured incorrectly\n");
                return -EINVAL;
+               break;
        }
        if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) {
                if ((chip_info->ctrl_len < SSP_BITS_4)
@@ -1859,6 +1950,7 @@ static int pl022_setup(struct spi_device *spi)
        }
        if ((clk_freq.cpsdvsr < CPSDVR_MIN)
            || (clk_freq.cpsdvsr > CPSDVR_MAX)) {
+               status = -EINVAL;
                dev_err(&spi->dev,
                        "cpsdvsr is configured incorrectly\n");
                goto err_config_params;
@@ -1871,6 +1963,9 @@ static int pl022_setup(struct spi_device *spi)
                goto err_config_params;
        }
 
+       pl022->rx_lev_trig = chip_info->rx_lev_trig;
+       pl022->tx_lev_trig = chip_info->tx_lev_trig;
+
        /* Now set controller state based on controller data */
        chip->xfer_type = chip_info->com_mode;
        if (!chip_info->cs_control) {
@@ -2091,6 +2186,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
        }
        printk(KERN_INFO "pl022: mapped registers from 0x%08x to %p\n",
               adev->res.start, pl022->virtbase);
+       pm_runtime_enable(dev);
+       pm_runtime_resume(dev);
 
        pl022->clk = clk_get(&adev->dev, NULL);
        if (IS_ERR(pl022->clk)) {
@@ -2152,6 +2249,7 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
        destroy_queue(pl022);
        pl022_dma_remove(pl022);
        free_irq(adev->irq[0], pl022);
+       pm_runtime_disable(&adev->dev);
  err_no_irq:
        clk_put(pl022->clk);
  err_no_clk:
@@ -2169,17 +2267,13 @@ static int __devexit
 pl022_remove(struct amba_device *adev)
 {
        struct pl022 *pl022 = amba_get_drvdata(adev);
-       int status = 0;
+
        if (!pl022)
                return 0;
 
        /* Remove the queue */
-       status = destroy_queue(pl022);
-       if (status != 0) {
-               dev_err(&adev->dev,
-                       "queue remove failed (%d)\n", status);
-               return status;
-       }
+       if (destroy_queue(pl022) != 0)
+               dev_err(&adev->dev, "queue remove failed\n");
        load_ssp_default_config(pl022);
        pl022_dma_remove(pl022);
        free_irq(adev->irq[0], pl022);
@@ -2191,7 +2285,6 @@ pl022_remove(struct amba_device *adev)
        spi_unregister_master(pl022->master);
        spi_master_put(pl022->master);
        amba_set_drvdata(adev, NULL);
-       dev_dbg(&adev->dev, "remove succeeded\n");
        return 0;
 }