mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Chris Healy <cphealy@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] mtd: devices: m25p80: Share code between m25p80_read() and m25p80_write()
Date: Sun, 31 Mar 2019 21:49:38 -0700	[thread overview]
Message-ID: <20190401044938.31237-3-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190401044938.31237-1-andrew.smirnov@gmail.com>

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


  parent reply	other threads:[~2019-04-01  4:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-04-02  6:36 ` [PATCH 1/3] mtd: devices: m25p80: Simplify m25p80_read() Vignesh Raghavendra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401044938.31237-3-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=cphealy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®