ipq806x: set v4.9 as default
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.4 / 710-spi-qup-Make-sure-mode-is-only-determined-once.patch
index e5dafd76b4b38702f6f013158aa97d25b953a542..338c3a0c2b39d2d6818f50d625e1d8d2d95587cb 100644 (file)
@@ -14,22 +14,20 @@ Change-Id: If3cdd924355e037d77dc8201a72895fac0461aa5
  drivers/spi/spi-qup.c | 96 +++++++++++++++++++--------------------------------
  1 file changed, 36 insertions(+), 60 deletions(-)
 
-diff --git a/drivers/spi/spi-qup.c b/drivers/spi/spi-qup.c
-index eb2cb8c..714fd4e 100644
 --- a/drivers/spi/spi-qup.c
 +++ b/drivers/spi/spi-qup.c
 @@ -150,13 +150,20 @@ struct spi_qup {
        int                     rx_bytes;
        int                     qup_v1;
-
 -      int                     use_dma;
 +      int                     mode;
        struct dma_slave_config rx_conf;
        struct dma_slave_config tx_conf;
 -      int mode;
  };
-
-
 +static inline bool spi_qup_is_dma_xfer(int mode)
 +{
 +      if (mode == QUP_IO_M_MODE_DMOV || mode == QUP_IO_M_MODE_BAM)
@@ -41,19 +39,19 @@ index eb2cb8c..714fd4e 100644
  static inline bool spi_qup_is_valid_state(struct spi_qup *controller)
  {
        u32 opstate = readl_relaxed(controller->base + QUP_STATE);
-@@ -427,7 +434,7 @@ static irqreturn_t spi_qup_qup_irq(int irq, void *dev_id)
+@@ -427,7 +434,7 @@ static irqreturn_t spi_qup_qup_irq(int i
                error = -EIO;
        }
-
 -      if (!controller->use_dma) {
 +      if (!spi_qup_is_dma_xfer(controller->mode)) {
                if (opflags & QUP_OP_IN_SERVICE_FLAG)
                        spi_qup_fifo_read(controller, xfer);
-
-@@ -446,43 +453,11 @@ static irqreturn_t spi_qup_qup_irq(int irq, void *dev_id)
+@@ -446,43 +453,11 @@ static irqreturn_t spi_qup_qup_irq(int i
        return IRQ_HANDLED;
  }
-
 -static u32
 -spi_qup_get_mode(struct spi_master *master, struct spi_transfer *xfer)
 -{
@@ -93,17 +91,17 @@ index eb2cb8c..714fd4e 100644
 -      u32 config, iomode, mode, control;
 +      u32 config, iomode, control;
        int ret, n_words;
-
        if (spi->mode & SPI_LOOP && xfer->len > controller->in_fifo_sz) {
-@@ -503,24 +478,22 @@ static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
+@@ -503,24 +478,22 @@ static int spi_qup_io_config(struct spi_
                return -EIO;
        }
-
 -      controller->mode = mode = spi_qup_get_mode(spi->master, xfer);
 +      controller->w_size = DIV_ROUND_UP(xfer->bits_per_word, 8);
 +      controller->n_words = xfer->len / controller->w_size;
        n_words = controller->n_words;
-
 -      if (mode == QUP_IO_M_MODE_FIFO) {
 +      if (n_words <= (controller->in_fifo_sz / sizeof(u32))) {
 +              controller->mode = QUP_IO_M_MODE_FIFO;
@@ -127,9 +125,9 @@ index eb2cb8c..714fd4e 100644
 +              controller->mode = QUP_IO_M_MODE_BAM;
                writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
                writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
-
-@@ -541,19 +514,26 @@ static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
-
+@@ -541,19 +514,26 @@ static int spi_qup_io_config(struct spi_
                        writel_relaxed(0, controller->base + QUP_MX_OUTPUT_CNT);
                }
 +      } else {
@@ -140,46 +138,46 @@ index eb2cb8c..714fd4e 100644
 +              writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
 +              writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
        }
-
        iomode = readl_relaxed(controller->base + QUP_IO_M_MODES);
        /* Set input and output transfer mode */
        iomode &= ~(QUP_IO_M_INPUT_MODE_MASK | QUP_IO_M_OUTPUT_MODE_MASK);
-
 -      if (!controller->use_dma)
 +      if (!spi_qup_is_dma_xfer(controller->mode))
                iomode &= ~(QUP_IO_M_PACK_EN | QUP_IO_M_UNPACK_EN);
        else
                iomode |= QUP_IO_M_PACK_EN | QUP_IO_M_UNPACK_EN;
-
 -      iomode |= (mode << QUP_IO_M_OUTPUT_MODE_MASK_SHIFT);
 -      iomode |= (mode << QUP_IO_M_INPUT_MODE_MASK_SHIFT);
 +      iomode |= (controller->mode << QUP_IO_M_OUTPUT_MODE_MASK_SHIFT);
 +      iomode |= (controller->mode << QUP_IO_M_INPUT_MODE_MASK_SHIFT);
-
        writel_relaxed(iomode, controller->base + QUP_IO_M_MODES);
-
-@@ -594,7 +574,7 @@ static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
+@@ -594,7 +574,7 @@ static int spi_qup_io_config(struct spi_
        config |= xfer->bits_per_word - 1;
        config |= QUP_CONFIG_SPI_MODE;
-
 -      if (controller->use_dma) {
 +      if (spi_qup_is_dma_xfer(controller->mode)) {
                if (!xfer->tx_buf)
                        config |= QUP_CONFIG_NO_OUTPUT;
                if (!xfer->rx_buf)
-@@ -612,7 +592,7 @@ static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
+@@ -612,7 +592,7 @@ static int spi_qup_io_config(struct spi_
                 * status change in BAM mode
                 */
-
 -              if (mode == QUP_IO_M_MODE_BAM)
 +              if (spi_qup_is_dma_xfer(controller->mode))
                        mask = QUP_OP_IN_SERVICE_FLAG | QUP_OP_OUT_SERVICE_FLAG;
-
                writel_relaxed(mask, controller->base + QUP_OPERATIONAL_MASK);
-@@ -646,7 +626,7 @@ static int spi_qup_transfer_one(struct spi_master *master,
+@@ -646,7 +626,7 @@ static int spi_qup_transfer_one(struct s
        controller->tx_bytes = 0;
        spin_unlock_irqrestore(&controller->lock, flags);
-
 -      if (controller->use_dma)
 +      if (spi_qup_is_dma_xfer(controller->mode))
                ret = spi_qup_do_dma(master, xfer);
@@ -188,13 +186,13 @@ index eb2cb8c..714fd4e 100644
 @@ -670,7 +650,7 @@ exit:
                ret = controller->error;
        spin_unlock_irqrestore(&controller->lock, flags);
-
 -      if (ret && controller->use_dma)
 +      if (ret && spi_qup_is_dma_xfer(controller->mode))
                spi_qup_dma_terminate(master, xfer);
-
        return ret;
-@@ -681,9 +661,7 @@ static bool spi_qup_can_dma(struct spi_master *master, struct spi_device *spi,
+@@ -681,9 +661,7 @@ static bool spi_qup_can_dma(struct spi_m
  {
        struct spi_qup *qup = spi_master_get_devdata(master);
        size_t dma_align = dma_get_cache_alignment();
@@ -202,24 +200,21 @@ index eb2cb8c..714fd4e 100644
 -
 -      qup->use_dma = 0;
 +      int n_words;
-
        if (xfer->rx_buf && (xfer->len % qup->in_blk_sz ||
            IS_ERR_OR_NULL(master->dma_rx) ||
-@@ -695,12 +673,10 @@ static bool spi_qup_can_dma(struct spi_master *master, struct spi_device *spi,
+@@ -695,12 +673,10 @@ static bool spi_qup_can_dma(struct spi_m
            !IS_ALIGNED((size_t)xfer->tx_buf, dma_align)))
                return false;
-
 -      mode = spi_qup_get_mode(master, xfer);
 -      if (mode == QUP_IO_M_MODE_FIFO)
 +      n_words = xfer->len / DIV_ROUND_UP(xfer->bits_per_word, 8);
 +      if (n_words <= (qup->in_fifo_sz / sizeof(u32)))
                return false;
-
 -      qup->use_dma = 1;
 -
        return true;
  }
-
---
-2.7.2
-