Commit e4b580bc authored by Vignesh R's avatar Vignesh R Committed by Cyrille Pitchen

mtd: spi-nor: cadence-quadspi: Refactor indirect read/write sequence.

Move configuring of indirect read/write start address to
cqspi_indirect_*_execute() function and rename cqspi_indirect_*_setup()
function. This will help to reuse cqspi_indirect_*_setup() function for
supporting direct access mode.
Signed-off-by: default avatarVignesh R <vigneshr@ti.com>
Signed-off-by: default avatarCyrille Pitchen <cyrille.pitchen@wedev4u.fr>
parent 17407ec3
...@@ -450,8 +450,7 @@ static int cqspi_command_write_addr(struct spi_nor *nor, ...@@ -450,8 +450,7 @@ static int cqspi_command_write_addr(struct spi_nor *nor,
return cqspi_exec_flash_cmd(cqspi, reg); return cqspi_exec_flash_cmd(cqspi, reg);
} }
static int cqspi_indirect_read_setup(struct spi_nor *nor, static int cqspi_read_setup(struct spi_nor *nor)
const unsigned int from_addr)
{ {
struct cqspi_flash_pdata *f_pdata = nor->priv; struct cqspi_flash_pdata *f_pdata = nor->priv;
struct cqspi_st *cqspi = f_pdata->cqspi; struct cqspi_st *cqspi = f_pdata->cqspi;
...@@ -459,8 +458,6 @@ static int cqspi_indirect_read_setup(struct spi_nor *nor, ...@@ -459,8 +458,6 @@ static int cqspi_indirect_read_setup(struct spi_nor *nor,
unsigned int dummy_clk = 0; unsigned int dummy_clk = 0;
unsigned int reg; unsigned int reg;
writel(from_addr, reg_base + CQSPI_REG_INDIRECTRDSTARTADDR);
reg = nor->read_opcode << CQSPI_REG_RD_INSTR_OPCODE_LSB; reg = nor->read_opcode << CQSPI_REG_RD_INSTR_OPCODE_LSB;
reg |= cqspi_calc_rdreg(nor, nor->read_opcode); reg |= cqspi_calc_rdreg(nor, nor->read_opcode);
...@@ -493,8 +490,8 @@ static int cqspi_indirect_read_setup(struct spi_nor *nor, ...@@ -493,8 +490,8 @@ static int cqspi_indirect_read_setup(struct spi_nor *nor,
return 0; return 0;
} }
static int cqspi_indirect_read_execute(struct spi_nor *nor, static int cqspi_indirect_read_execute(struct spi_nor *nor, u8 *rxbuf,
u8 *rxbuf, const unsigned n_rx) loff_t from_addr, const size_t n_rx)
{ {
struct cqspi_flash_pdata *f_pdata = nor->priv; struct cqspi_flash_pdata *f_pdata = nor->priv;
struct cqspi_st *cqspi = f_pdata->cqspi; struct cqspi_st *cqspi = f_pdata->cqspi;
...@@ -504,6 +501,7 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor, ...@@ -504,6 +501,7 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor,
unsigned int bytes_to_read = 0; unsigned int bytes_to_read = 0;
int ret = 0; int ret = 0;
writel(from_addr, reg_base + CQSPI_REG_INDIRECTRDSTARTADDR);
writel(remaining, reg_base + CQSPI_REG_INDIRECTRDBYTES); writel(remaining, reg_base + CQSPI_REG_INDIRECTRDBYTES);
/* Clear all interrupts. */ /* Clear all interrupts. */
...@@ -570,8 +568,7 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor, ...@@ -570,8 +568,7 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor,
return ret; return ret;
} }
static int cqspi_indirect_write_setup(struct spi_nor *nor, static int cqspi_write_setup(struct spi_nor *nor)
const unsigned int to_addr)
{ {
unsigned int reg; unsigned int reg;
struct cqspi_flash_pdata *f_pdata = nor->priv; struct cqspi_flash_pdata *f_pdata = nor->priv;
...@@ -584,8 +581,6 @@ static int cqspi_indirect_write_setup(struct spi_nor *nor, ...@@ -584,8 +581,6 @@ static int cqspi_indirect_write_setup(struct spi_nor *nor,
reg = cqspi_calc_rdreg(nor, nor->program_opcode); reg = cqspi_calc_rdreg(nor, nor->program_opcode);
writel(reg, reg_base + CQSPI_REG_RD_INSTR); writel(reg, reg_base + CQSPI_REG_RD_INSTR);
writel(to_addr, reg_base + CQSPI_REG_INDIRECTWRSTARTADDR);
reg = readl(reg_base + CQSPI_REG_SIZE); reg = readl(reg_base + CQSPI_REG_SIZE);
reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK; reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
reg |= (nor->addr_width - 1); reg |= (nor->addr_width - 1);
...@@ -593,8 +588,8 @@ static int cqspi_indirect_write_setup(struct spi_nor *nor, ...@@ -593,8 +588,8 @@ static int cqspi_indirect_write_setup(struct spi_nor *nor,
return 0; return 0;
} }
static int cqspi_indirect_write_execute(struct spi_nor *nor, static int cqspi_indirect_write_execute(struct spi_nor *nor, loff_t to_addr,
const u8 *txbuf, const unsigned n_tx) const u8 *txbuf, const size_t n_tx)
{ {
const unsigned int page_size = nor->page_size; const unsigned int page_size = nor->page_size;
struct cqspi_flash_pdata *f_pdata = nor->priv; struct cqspi_flash_pdata *f_pdata = nor->priv;
...@@ -604,6 +599,7 @@ static int cqspi_indirect_write_execute(struct spi_nor *nor, ...@@ -604,6 +599,7 @@ static int cqspi_indirect_write_execute(struct spi_nor *nor,
unsigned int write_bytes; unsigned int write_bytes;
int ret; int ret;
writel(to_addr, reg_base + CQSPI_REG_INDIRECTWRSTARTADDR);
writel(remaining, reg_base + CQSPI_REG_INDIRECTWRBYTES); writel(remaining, reg_base + CQSPI_REG_INDIRECTWRBYTES);
/* Clear all interrupts. */ /* Clear all interrupts. */
...@@ -900,11 +896,11 @@ static ssize_t cqspi_write(struct spi_nor *nor, loff_t to, ...@@ -900,11 +896,11 @@ static ssize_t cqspi_write(struct spi_nor *nor, loff_t to,
if (ret) if (ret)
return ret; return ret;
ret = cqspi_indirect_write_setup(nor, to); ret = cqspi_write_setup(nor);
if (ret) if (ret)
return ret; return ret;
ret = cqspi_indirect_write_execute(nor, buf, len); ret = cqspi_indirect_write_execute(nor, to, buf, len);
if (ret) if (ret)
return ret; return ret;
...@@ -920,11 +916,11 @@ static ssize_t cqspi_read(struct spi_nor *nor, loff_t from, ...@@ -920,11 +916,11 @@ static ssize_t cqspi_read(struct spi_nor *nor, loff_t from,
if (ret) if (ret)
return ret; return ret;
ret = cqspi_indirect_read_setup(nor, from); ret = cqspi_read_setup(nor);
if (ret) if (ret)
return ret; return ret;
ret = cqspi_indirect_read_execute(nor, buf, len); ret = cqspi_indirect_read_execute(nor, buf, from, len);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment