[U-Boot] [PATCH v7 79/87] mtd: spi-nor: Add m25p_cmdsz

Jagan Teki jteki at openedev.com
Tue Mar 22 08:38:31 CET 2016


Added m25p_cmdsz for finding command size based on
the addr_width.

Cc: Simon Glass <sjg at chromium.org>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Mugunthan V N <mugunthanvnm at ti.com>
Cc: Michal Simek <michal.simek at xilinx.com>
Cc: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
Signed-off-by: Jagan Teki <jteki at openedev.com>
---
 drivers/mtd/spi-nor/m25p80.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c
index 266407f..42c5a96 100644
--- a/drivers/mtd/spi-nor/m25p80.c
+++ b/drivers/mtd/spi-nor/m25p80.c
@@ -36,6 +36,11 @@ static void m25p_addr2cmd(struct spi_nor *nor, unsigned int addr, u8 *cmd)
 	cmd[4] = addr >> (nor->addr_width * 8 - 32);
 }
 
+static int m25p_cmdsz(struct spi_nor *nor)
+{
+	return 1 + nor->addr_width;
+}
+
 static int m25p80_read_reg(struct spi_nor *nor, u8 cmd, u8 *val, int len)
 {
 	struct m25p *flash = nor->priv;
@@ -142,8 +147,9 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 	if (nor->flags & SNOR_F_U_PAGE)
 		spi->flags |= SPI_XFER_U_PAGE;
 
-	ret = spi_write_then_read(spi, flash->command, 4 + nor->read_dummy,
-				  NULL, buf, len);
+	ret = spi_write_then_read(spi, flash->command,
+				  m25p_cmdsz(nor) + nor->read_dummy, NULL,
+				  buf, len);
 	if (ret < 0) {
 		debug("m25p80: error %d reading %x\n", ret, flash->command[0]);
 		return ret;
@@ -159,7 +165,7 @@ static int m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
 {
 	struct m25p *flash = nor->priv;
 	struct spi_slave *spi = flash->spi;
-	int cmd_sz = 4;
+	int cmd_sz = m25p_cmdsz(nor);
 	int ret;
 
 	ret = spi_claim_bus(spi);
@@ -213,7 +219,8 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)
 	debug("m25p80: erase %2x %2x %2x %2x (%llx)\n", flash->command[0],
 	       flash->command[1], flash->command[2], flash->command[3], offset);
 
-	ret = spi_write_then_read(spi, flash->command, 4, NULL, NULL, 0);
+	ret = spi_write_then_read(spi, flash->command, m25p_cmdsz(nor),
+				  NULL, NULL, 0);
 	if (ret < 0) {
 		debug("m25p80: error %d writing %x\n", ret, flash->command[0]);
 		return ret;
-- 
1.9.1



More information about the U-Boot mailing list