]> Git Repo - linux.git/commitdiff
Merge remote-tracking branch 'spi/fix/imx' into spi-imx
authorMark Brown <[email protected]>
Fri, 19 Feb 2016 15:49:12 +0000 (00:49 +0900)
committerMark Brown <[email protected]>
Fri, 19 Feb 2016 15:49:12 +0000 (00:49 +0900)
1  2 
drivers/spi/spi-imx.c

diff --combined drivers/spi/spi-imx.c
index 0313293323ccbfa97f59cf5c36a94e60bc706f68,08492d6faa0d1f1fb6c182c8500b89c03e63f9bd..c5eeb846d9fdb2bc8df16cd72e54995690a4d3f7
@@@ -86,7 -86,6 +86,7 @@@ struct spi_imx_devtype_data 
  
  struct spi_imx_data {
        struct spi_bitbang bitbang;
 +      struct device *dev;
  
        struct completion xfer_done;
        void __iomem *base;
@@@ -205,8 -204,8 +205,8 @@@ static bool spi_imx_can_dma(struct spi_
  {
        struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
  
-       if (spi_imx->dma_is_inited &&
-           transfer->len > spi_imx->wml * sizeof(u32))
+       if (spi_imx->dma_is_inited && transfer->len >= spi_imx->wml &&
+           (transfer->len % spi_imx->wml) == 0)
                return true;
        return false;
  }
  #define MX51_ECSPI_TESTREG_LBC        BIT(31)
  
  /* MX51 eCSPI */
 -static unsigned int mx51_ecspi_clkdiv(unsigned int fin, unsigned int fspi,
 -                                    unsigned int *fres)
 +static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx,
 +                                    unsigned int fspi, unsigned int *fres)
  {
        /*
         * there are two 4-bit dividers, the pre-divider divides by
         * $pre, the post-divider by 2^$post
         */
        unsigned int pre, post;
 +      unsigned int fin = spi_imx->spi_clk;
  
        if (unlikely(fspi > fin))
                return 0;
  
        post = max(4U, post) - 4;
        if (unlikely(post > 0xf)) {
 -              pr_err("%s: cannot set clock freq: %u (base freq: %u)\n",
 -                              __func__, fspi, fin);
 +              dev_err(spi_imx->dev, "cannot set clock freq: %u (base freq: %u)\n",
 +                              fspi, fin);
                return 0xff;
        }
  
        pre = DIV_ROUND_UP(fin, fspi << post) - 1;
  
 -      pr_debug("%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
 +      dev_dbg(spi_imx->dev, "%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
                        __func__, fin, fspi, post, pre);
  
        /* Resulting frequency for the SCLK line. */
@@@ -332,7 -330,7 +332,7 @@@ static int __maybe_unused mx51_ecspi_co
        ctrl |= MX51_ECSPI_CTRL_MODE_MASK;
  
        /* set clock speed */
 -      ctrl |= mx51_ecspi_clkdiv(spi_imx->spi_clk, config->speed_hz, &clk);
 +      ctrl |= mx51_ecspi_clkdiv(spi_imx, config->speed_hz, &clk);
  
        /* set chip select to use */
        ctrl |= MX51_ECSPI_CTRL_CS(config->cs);
@@@ -921,8 -919,6 +921,6 @@@ static int spi_imx_dma_transfer(struct 
        struct dma_async_tx_descriptor *desc_tx = NULL, *desc_rx = NULL;
        int ret;
        unsigned long timeout;
-       u32 dma;
-       int left;
        struct spi_master *master = spi_imx->bitbang.master;
        struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
  
                                        tx->sgl, tx->nents, DMA_MEM_TO_DEV,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
                if (!desc_tx)
 -                      goto no_dma;
 +                      goto tx_nodma;
  
                desc_tx->callback = spi_imx_dma_tx_callback;
                desc_tx->callback_param = (void *)spi_imx;
                                        rx->sgl, rx->nents, DMA_DEV_TO_MEM,
                                        DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
                if (!desc_rx)
 -                      goto no_dma;
 +                      goto rx_nodma;
  
                desc_rx->callback = spi_imx_dma_rx_callback;
                desc_rx->callback_param = (void *)spi_imx;
        /* Trigger the cspi module. */
        spi_imx->dma_finished = 0;
  
-       dma = readl(spi_imx->base + MX51_ECSPI_DMA);
-       dma = dma & (~MX51_ECSPI_DMA_RXT_WML_MASK);
-       /* Change RX_DMA_LENGTH trigger dma fetch tail data */
-       left = transfer->len % spi_imx->wml;
-       if (left)
-               writel(dma | (left << MX51_ECSPI_DMA_RXT_WML_OFFSET),
-                               spi_imx->base + MX51_ECSPI_DMA);
        /*
         * Set these order to avoid potential RX overflow. The overflow may
         * happen if we enable SPI HW before starting RX DMA due to rescheduling
        timeout = wait_for_completion_timeout(&spi_imx->dma_tx_completion,
                                                IMX_DMA_TIMEOUT);
        if (!timeout) {
 -              pr_warn("%s %s: I/O Error in DMA TX\n",
 -                      dev_driver_string(&master->dev),
 -                      dev_name(&master->dev));
 +              dev_err(spi_imx->dev, "I/O Error in DMA TX\n");
                dmaengine_terminate_all(master->dma_tx);
                dmaengine_terminate_all(master->dma_rx);
        } else {
                timeout = wait_for_completion_timeout(
                                &spi_imx->dma_rx_completion, IMX_DMA_TIMEOUT);
                if (!timeout) {
 -                      pr_warn("%s %s: I/O Error in DMA RX\n",
 -                              dev_driver_string(&master->dev),
 -                              dev_name(&master->dev));
 +                      dev_err(spi_imx->dev, "I/O Error in DMA RX\n");
                        spi_imx->devtype_data->reset(spi_imx);
                        dmaengine_terminate_all(master->dma_rx);
                }
-               dma &= ~MX51_ECSPI_DMA_RXT_WML_MASK;
-               writel(dma |
-                      spi_imx->wml << MX51_ECSPI_DMA_RXT_WML_OFFSET,
-                      spi_imx->base + MX51_ECSPI_DMA);
        }
  
        spi_imx->dma_finished = 1;
  
        return ret;
  
 -no_dma:
 -      pr_warn_once("%s %s: DMA not available, falling back to PIO\n",
 -                   dev_driver_string(&master->dev),
 -                   dev_name(&master->dev));
 +rx_nodma:
 +      dmaengine_terminate_all(master->dma_tx);
 +tx_nodma:
 +      dev_warn_once(spi_imx->dev, "DMA not available, falling back to PIO\n");
        return -EAGAIN;
  }
  
@@@ -1139,7 -1128,6 +1126,7 @@@ static int spi_imx_probe(struct platfor
  
        spi_imx = spi_master_get_devdata(master);
        spi_imx->bitbang.master = master;
 +      spi_imx->dev = &pdev->dev;
  
        spi_imx->devtype_data = of_id ? of_id->data :
                (struct spi_imx_devtype_data *)pdev->id_entry->driver_data;
This page took 0.070274 seconds and 4 git commands to generate.