spi: cadence-quadspi: Set dummy cycles from STIG commands
authorPratyush Yadav <p.yadav@ti.com>
Tue, 22 Dec 2020 18:44:21 +0000 (00:14 +0530)
committerMark Brown <broonie@kernel.org>
Wed, 6 Jan 2021 13:08:43 +0000 (13:08 +0000)
If a command does not have an address phase it goes via the STIG path.
The dummy cycles are not initialized for the STIG commands. As a result,
STIG commands with dummy cycles will not work.

Initialize the dummy cycle field before issuing the STIG command to make
sure it is sent correctly. Move the code to calculate dummy cycle value
to a separate function so it is not repeated twice. DTR support will add
some more logic here to it is worth it to extract it out in a function.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/20201222184425.7028-4-p.yadav@ti.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-cadence-quadspi.c

index 5efb1f929be0618d1999bb353f9381e408792604..6a778014ff606e2b4c11c4a7f9ae500dc12affa2 100644 (file)
@@ -188,6 +188,7 @@ struct cqspi_driver_platdata {
 #define CQSPI_REG_CMDCTRL                      0x90
 #define CQSPI_REG_CMDCTRL_EXECUTE_MASK         BIT(0)
 #define CQSPI_REG_CMDCTRL_INPROGRESS_MASK      BIT(1)
+#define CQSPI_REG_CMDCTRL_DUMMY_LSB            7
 #define CQSPI_REG_CMDCTRL_WR_BYTES_LSB         12
 #define CQSPI_REG_CMDCTRL_WR_EN_LSB            15
 #define CQSPI_REG_CMDCTRL_ADD_BYTES_LSB                16
@@ -198,6 +199,7 @@ struct cqspi_driver_platdata {
 #define CQSPI_REG_CMDCTRL_WR_BYTES_MASK                0x7
 #define CQSPI_REG_CMDCTRL_ADD_BYTES_MASK       0x3
 #define CQSPI_REG_CMDCTRL_RD_BYTES_MASK                0x7
+#define CQSPI_REG_CMDCTRL_DUMMY_MASK           0x1F
 
 #define CQSPI_REG_INDIRECTWR                   0x70
 #define CQSPI_REG_INDIRECTWR_START_MASK                BIT(0)
@@ -288,6 +290,15 @@ static unsigned int cqspi_calc_rdreg(struct cqspi_flash_pdata *f_pdata)
        return rdreg;
 }
 
+static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op)
+{
+       unsigned int dummy_clk;
+
+       dummy_clk = op->dummy.nbytes * 8;
+
+       return dummy_clk;
+}
+
 static int cqspi_wait_idle(struct cqspi_st *cqspi)
 {
        const unsigned int poll_idle_retry = 3;
@@ -355,6 +366,7 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
        size_t n_rx = op->data.nbytes;
        unsigned int rdreg;
        unsigned int reg;
+       unsigned int dummy_clk;
        size_t read_len;
        int status;
 
@@ -370,6 +382,14 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
        rdreg = cqspi_calc_rdreg(f_pdata);
        writel(rdreg, reg_base + CQSPI_REG_RD_INSTR);
 
+       dummy_clk = cqspi_calc_dummy(op);
+       if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
+               return -EOPNOTSUPP;
+
+       if (dummy_clk)
+               reg |= (dummy_clk & CQSPI_REG_CMDCTRL_DUMMY_MASK)
+                    << CQSPI_REG_CMDCTRL_DUMMY_LSB;
+
        reg |= (0x1 << CQSPI_REG_CMDCTRL_RD_EN_LSB);
 
        /* 0 means 1 byte. */
@@ -459,7 +479,8 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
        reg |= cqspi_calc_rdreg(f_pdata);
 
        /* Setup dummy clock cycles */
-       dummy_clk = op->dummy.nbytes * 8;
+       dummy_clk = cqspi_calc_dummy(op);
+
        if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
                return -EOPNOTSUPP;