From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>
Cc: "David Woodhouse" <dwmw2@infradead.org>,
"Brian Norris" <computersforpeace@gmail.com>,
"Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Marek Vasut" <marek.vasut@gmail.com>,
"Richard Weinberger" <richard@nod.at>,
"Cyrille Pitchen" <cyrille.pitchen@wedev4u.fr>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
"Mark Brown" <broonie@kernel.org>,
"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
"Vignesh R" <vigneshr@ti.com>,
"Kamal Dasu" <kdasu.kdev@gmail.com>,
"Peter Pan" <peterpansjtu@gmail.com>,
"Frieder Schrempf" <frieder.schrempf@exceet.de>,
"Rafał Miłecki" <rafal@milecki.pl>,
"Sourav Poddar" <sourav.poddar@ti.com>
Subject: Re: [RFC PATCH 5/6] mtd: spi-nor: Use the spi_mem_xx() API
Date: Mon, 11 Jun 2018 09:35:55 +0200 [thread overview]
Message-ID: <20180611093555.50f8682d@bbrezillon> (raw)
In-Reply-To: <DB6PR0402MB28380B10F866F08E0CDC6B6999780@DB6PR0402MB2838.eurprd04.prod.outlook.com>
Hi Yogesh,
On Mon, 11 Jun 2018 06:25:02 +0000
Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com> wrote:
> static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
> const u_char *buf)
> {
> struct m25p *flash = nor->priv;
> - struct spi_device *spi = flash->spi;
> - unsigned int inst_nbits, addr_nbits, data_nbits, data_idx;
> - struct spi_transfer t[3] = {};
> - struct spi_message m;
> - int cmd_sz = m25p_cmdsz(nor);
> - ssize_t ret;
> + u8 addrs[4];
> + struct spi_mem_op op =
> + SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
> + SPI_MEM_OP_ADDRS(nor->addr_width, addrs, 1),
> + SPI_MEM_OP_DUMMY(0, 1),
> + SPI_MEM_OP_DATA_OUT(len, buf, 1));
> + size_t remaining = len;
> + int ret;
>
> /* get transfer protocols. */
> - inst_nbits = spi_nor_get_protocol_inst_nbits(nor->write_proto);
> - addr_nbits = spi_nor_get_protocol_addr_nbits(nor->write_proto);
> - data_nbits = spi_nor_get_protocol_data_nbits(nor->write_proto);
> -
> - spi_message_init(&m);
> + 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.dummy.buswidth = op.addr.buswidth;
> + op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto);
>
> if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
> - cmd_sz = 1;
> -
> - flash->command[0] = nor->program_opcode;
> - m25p_addr2cmd(nor, to, flash->command);
> + op.addr.nbytes = 0;
>
> - t[0].tx_buf = flash->command;
> - t[0].tx_nbits = inst_nbits;
> - t[0].len = cmd_sz;
> - spi_message_add_tail(&t[0], &m);
> + while (remaining) {
> + if (op.addr.nbytes)
> + m25p_offs2addr(nor, to, addrs);
>
> - /* split the op code and address bytes into two transfers if needed. */
> - data_idx = 1;
> - if (addr_nbits != inst_nbits) {
> - t[0].len = 1;
> + op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> + ret = spi_mem_adjust_op_size(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - t[1].tx_buf = &flash->command[1];
> - t[1].tx_nbits = addr_nbits;
> - t[1].len = cmd_sz - 1;
> - spi_message_add_tail(&t[1], &m);
> + ret = spi_mem_exec_op(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - data_idx = 2;
> + to += op.data.nbytes;
> + remaining -= op.data.nbytes;
> + op.data.buf.out += op.data.nbytes;
>
> For NOR flashes, WRITE command is being send in order as below
> Write Enable command
> Flash Write command
> Status Register command
>
> But for case when Write data size is more than op.data.nbytes then for
> remaining data size chunk, we are just sending the FLASH WRITE Command
> and this is the reason I am seeing failure after 64 byte data size.
>
Hm, I guess we'll have to revive this patch [1] (see below for a
modified version based on the spi-mem changes).
Regards,
Boris
[1]https://patchwork.ozlabs.org/patch/905507/
--->8---
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index e84563d2067f..f2403b36649c 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -84,22 +84,16 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
op.addr.nbytes = 0;
- 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;
+ op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
+ 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.out += op.data.nbytes;
- }
+ ret = spi_mem_exec_op(flash->spimem, &op);
+ if (ret)
+ return ret;
- return len;
+ return op.data.nbytes;
}
/*
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 5bfa36e95f35..3e635430bfde 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1431,13 +1431,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
goto write_err;
*retlen += written;
i += written;
- if (written != page_remain) {
- dev_err(nor->dev,
- "While writing %zu bytes written %zd bytes\n",
- page_remain, written);
- ret = -EIO;
- goto write_err;
- }
}
write_err:
WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>
Cc: "Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Vignesh R" <vigneshr@ti.com>,
"Kamal Dasu" <kdasu.kdev@gmail.com>,
"Richard Weinberger" <richard@nod.at>,
"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
"Peter Pan" <peterpansjtu@gmail.com>,
"Marek Vasut" <marek.vasut@gmail.com>,
"Frieder Schrempf" <frieder.schrempf@exceet.de>,
"Mark Brown" <broonie@kernel.org>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
"Cyrille Pitchen" <cyrille.pitchen@wedev4u.fr>,
"Rafał Miłecki" <rafal@milecki.pl>,
"Sourav Poddar" <sourav.poddar@ti.com>,
"Brian Norris" <computersforpeace@gmail.com>,
"David Woodhouse" <dwmw2@infradead.org>
Subject: Re: [RFC PATCH 5/6] mtd: spi-nor: Use the spi_mem_xx() API
Date: Mon, 11 Jun 2018 09:35:55 +0200 [thread overview]
Message-ID: <20180611093555.50f8682d@bbrezillon> (raw)
In-Reply-To: <DB6PR0402MB28380B10F866F08E0CDC6B6999780@DB6PR0402MB2838.eurprd04.prod.outlook.com>
Hi Yogesh,
On Mon, 11 Jun 2018 06:25:02 +0000
Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com> wrote:
> static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
> const u_char *buf)
> {
> struct m25p *flash = nor->priv;
> - struct spi_device *spi = flash->spi;
> - unsigned int inst_nbits, addr_nbits, data_nbits, data_idx;
> - struct spi_transfer t[3] = {};
> - struct spi_message m;
> - int cmd_sz = m25p_cmdsz(nor);
> - ssize_t ret;
> + u8 addrs[4];
> + struct spi_mem_op op =
> + SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
> + SPI_MEM_OP_ADDRS(nor->addr_width, addrs, 1),
> + SPI_MEM_OP_DUMMY(0, 1),
> + SPI_MEM_OP_DATA_OUT(len, buf, 1));
> + size_t remaining = len;
> + int ret;
>
> /* get transfer protocols. */
> - inst_nbits = spi_nor_get_protocol_inst_nbits(nor->write_proto);
> - addr_nbits = spi_nor_get_protocol_addr_nbits(nor->write_proto);
> - data_nbits = spi_nor_get_protocol_data_nbits(nor->write_proto);
> -
> - spi_message_init(&m);
> + 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.dummy.buswidth = op.addr.buswidth;
> + op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto);
>
> if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
> - cmd_sz = 1;
> -
> - flash->command[0] = nor->program_opcode;
> - m25p_addr2cmd(nor, to, flash->command);
> + op.addr.nbytes = 0;
>
> - t[0].tx_buf = flash->command;
> - t[0].tx_nbits = inst_nbits;
> - t[0].len = cmd_sz;
> - spi_message_add_tail(&t[0], &m);
> + while (remaining) {
> + if (op.addr.nbytes)
> + m25p_offs2addr(nor, to, addrs);
>
> - /* split the op code and address bytes into two transfers if needed. */
> - data_idx = 1;
> - if (addr_nbits != inst_nbits) {
> - t[0].len = 1;
> + op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
> + ret = spi_mem_adjust_op_size(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - t[1].tx_buf = &flash->command[1];
> - t[1].tx_nbits = addr_nbits;
> - t[1].len = cmd_sz - 1;
> - spi_message_add_tail(&t[1], &m);
> + ret = spi_mem_exec_op(flash->spimem, &op);
> + if (ret)
> + return ret;
>
> - data_idx = 2;
> + to += op.data.nbytes;
> + remaining -= op.data.nbytes;
> + op.data.buf.out += op.data.nbytes;
>
> For NOR flashes, WRITE command is being send in order as below
> Write Enable command
> Flash Write command
> Status Register command
>
> But for case when Write data size is more than op.data.nbytes then for
> remaining data size chunk, we are just sending the FLASH WRITE Command
> and this is the reason I am seeing failure after 64 byte data size.
>
Hm, I guess we'll have to revive this patch [1] (see below for a
modified version based on the spi-mem changes).
Regards,
Boris
[1]https://patchwork.ozlabs.org/patch/905507/
--->8---
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index e84563d2067f..f2403b36649c 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -84,22 +84,16 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
op.addr.nbytes = 0;
- 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;
+ op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
+ 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.out += op.data.nbytes;
- }
+ ret = spi_mem_exec_op(flash->spimem, &op);
+ if (ret)
+ return ret;
- return len;
+ return op.data.nbytes;
}
/*
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 5bfa36e95f35..3e635430bfde 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1431,13 +1431,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
goto write_err;
*retlen += written;
i += written;
- if (written != page_remain) {
- dev_err(nor->dev,
- "While writing %zu bytes written %zd bytes\n",
- page_remain, written);
- ret = -EIO;
- goto write_err;
- }
}
write_err:
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2018-06-11 7:36 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 23:21 [RFC PATCH 0/6] spi: Extend the framework to generically support memory devices Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 1/6] spi: Extend the core to ease integration of SPI memory controllers Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-06 9:43 ` Maxime Chevallier
2018-02-06 9:43 ` Maxime Chevallier
2018-02-06 10:25 ` Boris Brezillon
2018-02-06 10:25 ` Boris Brezillon
2018-02-06 12:06 ` Mark Brown
2018-02-06 12:06 ` Mark Brown
2018-02-09 12:52 ` Miquel Raynal
2018-02-09 12:52 ` Miquel Raynal
2018-02-11 16:00 ` Boris Brezillon
2018-02-11 16:00 ` Boris Brezillon
2018-02-12 11:50 ` Vignesh R
2018-02-12 11:50 ` Vignesh R
2018-02-12 12:28 ` Boris Brezillon
2018-02-12 12:28 ` Boris Brezillon
2018-02-19 13:53 ` Mark Brown
2018-02-19 14:20 ` Boris Brezillon
2018-02-19 14:00 ` Mark Brown
2018-02-19 14:32 ` Boris Brezillon
2018-02-28 7:51 ` Peter Pan
2018-02-28 7:51 ` Peter Pan
2018-02-28 12:25 ` Boris Brezillon
2018-02-28 12:25 ` Boris Brezillon
2018-03-04 21:15 ` Cyrille Pitchen
2018-03-04 21:15 ` Cyrille Pitchen
2018-03-05 9:00 ` Boris Brezillon
2018-03-05 9:00 ` Boris Brezillon
2018-03-05 13:01 ` Cyrille Pitchen
2018-03-05 13:01 ` Cyrille Pitchen
2018-03-05 13:47 ` Boris Brezillon
2018-03-05 13:47 ` Boris Brezillon
2018-03-08 14:07 ` Boris Brezillon
2018-03-08 14:07 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 2/6] spi: bcm-qspi: Implement the spi_mem interface Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 3/6] spi: bcm53xx: " Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 4/6] spi: ti-qspi: " Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-11 15:17 ` Miquel Raynal
2018-02-11 15:17 ` Miquel Raynal
2018-02-11 17:18 ` Boris Brezillon
2018-02-11 17:18 ` Boris Brezillon
2018-02-12 7:54 ` Miquel Raynal
2018-02-12 7:54 ` Miquel Raynal
2018-02-12 11:43 ` Vignesh R
2018-02-12 11:43 ` Vignesh R
2018-02-12 12:31 ` Boris Brezillon
2018-02-12 12:31 ` Boris Brezillon
2018-02-12 16:00 ` Vignesh R
2018-02-12 16:00 ` Vignesh R
2018-02-12 16:08 ` Boris Brezillon
2018-02-12 16:08 ` Boris Brezillon
2018-02-14 16:25 ` Vignesh R
2018-02-14 16:25 ` Vignesh R
2018-02-14 19:09 ` Boris Brezillon
2018-02-14 19:09 ` Boris Brezillon
2018-02-14 20:44 ` Schrempf Frieder
2018-02-14 20:44 ` Schrempf Frieder
2018-02-14 21:00 ` Boris Brezillon
2018-02-14 21:00 ` Boris Brezillon
2018-02-15 16:38 ` Schrempf Frieder
2018-02-15 16:38 ` Schrempf Frieder
2018-02-17 11:01 ` Vignesh R
2018-02-17 11:01 ` Vignesh R
2018-02-17 21:52 ` Boris Brezillon
2018-02-17 21:52 ` Boris Brezillon
2018-02-16 10:25 ` Boris Brezillon
2018-02-16 10:25 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 5/6] mtd: spi-nor: Use the spi_mem_xx() API Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-12 11:44 ` Vignesh R
2018-02-12 11:44 ` Vignesh R
2018-02-12 12:32 ` Boris Brezillon
2018-02-12 12:32 ` Boris Brezillon
2018-06-11 6:25 ` Yogesh Narayan Gaur
2018-06-11 6:25 ` Yogesh Narayan Gaur
2018-06-11 7:35 ` Boris Brezillon [this message]
2018-06-11 7:35 ` Boris Brezillon
2018-02-05 23:21 ` [RFC PATCH 6/6] spi: Get rid of the spi_flash_read() API Boris Brezillon
2018-02-05 23:21 ` Boris Brezillon
2018-02-16 10:21 ` Vignesh R
2018-02-16 10:21 ` Vignesh R
2018-02-16 10:24 ` Boris Brezillon
2018-02-16 10:24 ` Boris Brezillon
2018-02-19 16:25 ` [RFC PATCH 0/6] spi: Extend the framework to generically support memory devices Mark Brown
2018-02-19 16:51 ` Boris Brezillon
2018-03-04 21:40 ` Cyrille Pitchen
2018-03-04 21:40 ` Cyrille Pitchen
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=20180611093555.50f8682d@bbrezillon \
--to=boris.brezillon@bootlin.com \
--cc=boris.brezillon@free-electrons.com \
--cc=broonie@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=frieder.schrempf@exceet.de \
--cc=kdasu.kdev@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=marek.vasut@gmail.com \
--cc=peterpansjtu@gmail.com \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
--cc=sourav.poddar@ti.com \
--cc=vigneshr@ti.com \
--cc=yogeshnarayan.gaur@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.