* [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read()
@ 2019-04-01 4:49 Andrey Smirnov
2019-04-01 4:49 ` [PATCH 2/3] mtd: devices: m25p80: Drop extra length clamping in m25p80_write() Andrey Smirnov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Andrey Smirnov @ 2019-04-01 4:49 UTC (permalink / raw)
To: linux-mtd
Cc: Andrey Smirnov, Brian Norris, Boris Brezillon, Marek Vasut,
Chris Healy, linux-kernel
Spi_nor_read() already has an appropriate loop around .read() callback
to handle the case when not all of the data requested was written in a
signle ->read() call. Drop extra code doing the same thing in
m25p80_read().
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
drivers/mtd/devices/m25p80.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 651bab6d4e31..114f8ccea85b 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -125,7 +125,6 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
SPI_MEM_OP_DATA_IN(len, buf, 1));
- size_t remaining = len;
int ret;
/* get transfer protocols. */
@@ -137,22 +136,15 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
/* convert the dummy cycles to the number of bytes */
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
- while (remaining) {
- op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
- ret = spi_mem_adjust_op_size(flash->spimem, &op);
- if (ret)
- return ret;
-
- ret = spi_mem_exec_op(flash->spimem, &op);
- if (ret)
- return ret;
+ ret = spi_mem_adjust_op_size(flash->spimem, &op);
+ if (ret)
+ return ret;
- op.addr.val += op.data.nbytes;
- remaining -= op.data.nbytes;
- op.data.buf.in += op.data.nbytes;
- }
+ ret = spi_mem_exec_op(flash->spimem, &op);
+ if (ret)
+ return ret;
- return len;
+ return op.data.nbytes;
}
/*
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] mtd: devices: m25p80: Drop extra length clamping in m25p80_write()
2019-04-01 4:49 [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Andrey Smirnov
@ 2019-04-01 4:49 ` Andrey Smirnov
2019-04-01 4:49 ` [PATCH 3/3] mtd: devices: m25p80: Share code between m25p80_read() and m25p80_write() Andrey Smirnov
2019-04-02 6:36 ` [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Vignesh Raghavendra
2 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2019-04-01 4:49 UTC (permalink / raw)
To: linux-mtd
Cc: Andrey Smirnov, Brian Norris, Boris Brezillon, Marek Vasut,
Chris Healy, linux-kernel
All of the needed length clamping should already be taken care of by
spi_mem_adjust_op_size(). No check like this is done in read path, so
this extra check in write doesn't appear to be necessary. Drop it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
drivers/mtd/devices/m25p80.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 114f8ccea85b..a54cad9bb6e3 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -103,7 +103,6 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
ret = spi_mem_adjust_op_size(flash->spimem, &op);
if (ret)
return ret;
- op.data.nbytes = len < op.data.nbytes ? len : op.data.nbytes;
ret = spi_mem_exec_op(flash->spimem, &op);
if (ret)
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] mtd: devices: m25p80: Share code between m25p80_read() and m25p80_write()
2019-04-01 4:49 [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Andrey Smirnov
2019-04-01 4:49 ` [PATCH 2/3] mtd: devices: m25p80: Drop extra length clamping in m25p80_write() Andrey Smirnov
@ 2019-04-01 4:49 ` Andrey Smirnov
2019-04-02 6:36 ` [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Vignesh Raghavendra
2 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2019-04-01 4:49 UTC (permalink / raw)
To: linux-mtd
Cc: Andrey Smirnov, Brian Norris, Boris Brezillon, Marek Vasut,
Chris Healy, linux-kernel
Move shared parts of m25p80_read() and m25p80_write() into a separate
subroutine and convert the rest of the code to use it. No functional
change intended.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
drivers/mtd/devices/m25p80.c | 58 ++++++++++++++++--------------------
1 file changed, 25 insertions(+), 33 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index a54cad9bb6e3..199f7c210799 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -81,34 +81,41 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
return ret;
}
-static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
- const u_char *buf)
+static ssize_t m25p80_read_write(struct spi_nor *nor, struct spi_mem_op *op,
+ enum spi_nor_protocol proto)
{
struct m25p *flash = nor->priv;
- struct spi_mem_op op =
- SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
- SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
- SPI_MEM_OP_NO_DUMMY,
- SPI_MEM_OP_DATA_OUT(len, buf, 1));
int ret;
/* get transfer protocols. */
- op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto);
- op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto);
- op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto);
-
- if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
- op.addr.nbytes = 0;
+ op->cmd.buswidth = spi_nor_get_protocol_inst_nbits(proto);
+ op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
+ op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
- ret = spi_mem_adjust_op_size(flash->spimem, &op);
+ ret = spi_mem_adjust_op_size(flash->spimem, op);
if (ret)
return ret;
- ret = spi_mem_exec_op(flash->spimem, &op);
+ ret = spi_mem_exec_op(flash->spimem, op);
if (ret)
return ret;
- return op.data.nbytes;
+ return op->data.nbytes;
+}
+
+static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
+ const u_char *buf)
+{
+ struct spi_mem_op op =
+ SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
+ SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(len, buf, 1));
+
+ if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
+ op.addr.nbytes = 0;
+
+ return m25p80_read_write(nor, &op, nor->write_proto);
}
/*
@@ -118,32 +125,17 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
u_char *buf)
{
- struct m25p *flash = nor->priv;
struct spi_mem_op op =
SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),
SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
SPI_MEM_OP_DATA_IN(len, buf, 1));
- int ret;
-
- /* get transfer protocols. */
- op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto);
- op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
- op.dummy.buswidth = op.addr.buswidth;
- op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto);
+ op.dummy.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
/* convert the dummy cycles to the number of bytes */
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
- ret = spi_mem_adjust_op_size(flash->spimem, &op);
- if (ret)
- return ret;
-
- ret = spi_mem_exec_op(flash->spimem, &op);
- if (ret)
- return ret;
-
- return op.data.nbytes;
+ return m25p80_read_write(nor, &op, nor->read_proto);
}
/*
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read()
2019-04-01 4:49 [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Andrey Smirnov
2019-04-01 4:49 ` [PATCH 2/3] mtd: devices: m25p80: Drop extra length clamping in m25p80_write() Andrey Smirnov
2019-04-01 4:49 ` [PATCH 3/3] mtd: devices: m25p80: Share code between m25p80_read() and m25p80_write() Andrey Smirnov
@ 2019-04-02 6:36 ` Vignesh Raghavendra
2 siblings, 0 replies; 4+ messages in thread
From: Vignesh Raghavendra @ 2019-04-02 6:36 UTC (permalink / raw)
To: Andrey Smirnov, linux-mtd
Cc: Marek Vasut, linux-kernel, Boris Brezillon, Brian Norris, Chris Healy
Hi,
On 01/04/19 10:19 AM, Andrey Smirnov wrote:
> Spi_nor_read() already has an appropriate loop around .read() callback
> to handle the case when not all of the data requested was written in a
> signle ->read() call. Drop extra code doing the same thing in
> m25p80_read().
>
Thanks for the patch series! But we are in the process of completely
moving m25p80.c into spi-nor.c which should take care of this series.
See[1][2], I plan to post the next version shortly. Let me know if
something is missing.
[1] https://patchwork.ozlabs.org/patch/982925/
[2] https://patchwork.ozlabs.org/patch/982922/
Regards
Vignesh
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Brian Norris <computersforpeace@gmail.com>
> Cc: Boris Brezillon <boris.brezillon@bootlin.com>
> Cc: Marek Vasut <marek.vasut@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: linux-mtd@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/mtd/devices/m25p80.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 651bab6d4e31..114f8ccea85b 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -125,7 +125,6 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
> SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
> SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
> SPI_MEM_OP_DATA_IN(len, buf, 1));
> - size_t remaining = len;
> int ret;
>
> /* get transfer protocols. */
> @@ -137,22 +136,15 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
> /* convert the dummy cycles to the number of bytes */
> op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
>
> - while (remaining) {
> - op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> - ret = spi_mem_adjust_op_size(flash->spimem, &op);
> - if (ret)
> - return ret;
> -
> - ret = spi_mem_exec_op(flash->spimem, &op);
> - if (ret)
> - return ret;
> + ret = spi_mem_adjust_op_size(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - op.addr.val += op.data.nbytes;
> - remaining -= op.data.nbytes;
> - op.data.buf.in += op.data.nbytes;
> - }
> + ret = spi_mem_exec_op(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - return len;
> + return op.data.nbytes;
> }
>
> /*
>
--
Regards
Vignesh
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-02 6:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 4:49 [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Andrey Smirnov
2019-04-01 4:49 ` [PATCH 2/3] mtd: devices: m25p80: Drop extra length clamping in m25p80_write() Andrey Smirnov
2019-04-01 4:49 ` [PATCH 3/3] mtd: devices: m25p80: Share code between m25p80_read() and m25p80_write() Andrey Smirnov
2019-04-02 6:36 ` [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Vignesh Raghavendra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).