diff options
author | Pratyush Yadav <p.yadav@ti.com> | 2023-04-28 16:50:11 +0530 |
---|---|---|
committer | Udit Kumar <u-kumar1@ti.com> | 2023-05-22 22:07:17 +0530 |
commit | a13fec31bdd22dc0e6beab686a2ae79333f15298 (patch) | |
tree | 996a60a6795a864e05c717932297fd4795a5b215 /drivers/mtd/spi/spi-nor-core.c | |
parent | 4282a8e6f1457843e180be16cd0b327de2ac97e8 (diff) |
mtd: spi-nor-core: refactor read op creation to make a template op
A template of the read op will be needed in a upcoming commit. So,
refactor the code to create a read op in spi_nor_read_data() to a
separate function that returns the template of the op. The caller can
then fill in the details like address, data length, and the data buffer.
Update spi_nor_read_data() to use this template.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Signed-off-by: Apurva Nandan <a-nandan@ti.com>
Diffstat (limited to 'drivers/mtd/spi/spi-nor-core.c')
-rw-r--r-- | drivers/mtd/spi/spi-nor-core.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 2c3116ee53..24a3d18e7e 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -350,17 +350,18 @@ static int spansion_write_any_reg(struct spi_nor *nor, u32 addr, u8 val) } #endif -static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, - u_char *buf) +/* + * Return a template of the spi-mem op for performing a read operation. + * The caller is expected to fill in the address, the data length, and + * the data buffer. + */ +static struct spi_mem_op spi_nor_read_op(struct spi_nor *nor) { struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), - SPI_MEM_OP_ADDR(nor->addr_width, from, 0), + SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), SPI_MEM_OP_DUMMY(nor->read_dummy, 0), - SPI_MEM_OP_DATA_IN(len, buf, 0)); - size_t remaining = len; - int ret; - + SPI_MEM_OP_DATA_IN(1, NULL, 0)); spi_nor_setup_op(nor, &op, nor->read_proto); /* convert the dummy cycles to the number of bytes */ @@ -368,6 +369,20 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, if (spi_nor_protocol_is_dtr(nor->read_proto)) op.dummy.nbytes *= 2; + return op; +} + +static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, + u_char *buf) +{ + struct spi_mem_op op = spi_nor_read_op(nor); + size_t remaining = len; + int ret; + + op.addr.val = from; + op.data.nbytes = len; + op.data.buf.in = buf; + while (remaining) { op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; |