From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Marek Vasut <marek.vasut@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Richard Weinberger <richard@nod.at>,
linux-mtd@lists.infradead.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Subject: [PATCH v4] mtd: devices: m25p80: Use the spi-mem dirmap API
Date: Fri, 31 May 2019 21:31:46 +0300 [thread overview]
Message-ID: <c405efc0-58ef-c67a-d519-95e0eb843229@cogentembedded.com> (raw)
In-Reply-To: <610761cf-5a19-c182-07d8-8d118ca20035@cogentembedded.com>
From: Boris Brezillon <boris.brezillon@bootlin.com>
Make use of the spi-mem direct mapping API to let advanced controllers
optimize read/write operations when they support direct mapping.
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>
---
This is a leftover unmerged patch of the "spi: spi-mem: Add a direct mapping
API" series, atop of the 'mtd/next' branch of the MTD 'linux.git' repo.
Changes in v4:
- Add Yogesh's T-b and my S-o-b
Changes in v3:
- Make nor->read/write() functional before the direct mappings have been
created
- Add Miquel's R-b
Changes in v2:
- Rename the dirmap fields
- Return directly after calling dirmap_read/write() and let the spi-nor
framework call us again if those functions returned less than the
requested length
drivers/mtd/devices/m25p80.c | 102 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 99 insertions(+), 3 deletions(-)
Index: linux/drivers/mtd/devices/m25p80.c
===================================================================
--- linux.orig/drivers/mtd/devices/m25p80.c
+++ linux/drivers/mtd/devices/m25p80.c
@@ -31,8 +31,70 @@
struct m25p {
struct spi_mem *spimem;
struct spi_nor spi_nor;
+ struct {
+ struct spi_mem_dirmap_desc *rdesc;
+ struct spi_mem_dirmap_desc *wdesc;
+ } dirmap;
};
+static int m25p_create_write_dirmap(struct m25p *flash)
+{
+ struct spi_nor *nor = &flash->spi_nor;
+ struct spi_mem_dirmap_info info = {
+ .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
+ SPI_MEM_OP_ADDR(nor->addr_width, 0, 1),
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(0, NULL, 1)),
+ .offset = 0,
+ .length = flash->spi_nor.mtd.size,
+ };
+ struct spi_mem_op *op = &info.op_tmpl;
+
+ /* 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->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)
+ op->addr.nbytes = 0;
+
+ flash->dirmap.wdesc = spi_mem_dirmap_create(flash->spimem, &info);
+ if (IS_ERR(flash->dirmap.wdesc))
+ return PTR_ERR(flash->dirmap.wdesc);
+
+ return 0;
+}
+
+static int m25p_create_read_dirmap(struct m25p *flash)
+{
+ struct spi_nor *nor = &flash->spi_nor;
+ struct spi_mem_dirmap_info info = {
+ .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),
+ SPI_MEM_OP_ADDR(nor->addr_width, 0, 1),
+ SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
+ SPI_MEM_OP_DATA_IN(0, NULL, 1)),
+ .offset = 0,
+ .length = flash->spi_nor.mtd.size,
+ };
+ struct spi_mem_op *op = &info.op_tmpl;
+
+ /* 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);
+
+ /* convert the dummy cycles to the number of bytes */
+ op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8;
+
+ flash->dirmap.rdesc = spi_mem_dirmap_create(flash->spimem, &info);
+ if (IS_ERR(flash->dirmap.rdesc))
+ return PTR_ERR(flash->dirmap.rdesc);
+
+ return 0;
+}
+
static int m25p80_read_reg(struct spi_nor *nor, u8 code, u8 *val, int len)
{
struct m25p *flash = nor->priv;
@@ -92,6 +154,9 @@ static ssize_t m25p80_write(struct spi_n
SPI_MEM_OP_DATA_OUT(len, buf, 1));
int ret;
+ if (flash->dirmap.wdesc)
+ return spi_mem_dirmap_write(flash->dirmap.wdesc, to, len, buf);
+
/* 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);
@@ -128,6 +193,9 @@ static ssize_t m25p80_read(struct spi_no
size_t remaining = len;
int ret;
+ if (flash->dirmap.rdesc)
+ return spi_mem_dirmap_read(flash->dirmap.rdesc, from, len, buf);
+
/* 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);
@@ -238,19 +306,47 @@ static int m25p_probe(struct spi_mem *sp
if (ret)
return ret;
- return mtd_device_register(&nor->mtd, data ? data->parts : NULL,
- data ? data->nr_parts : 0);
+ ret = m25p_create_write_dirmap(flash);
+ if (ret)
+ return ret;
+
+ ret = m25p_create_read_dirmap(flash);
+ if (ret)
+ goto err_destroy_write_dirmap;
+
+ ret = mtd_device_register(&nor->mtd, data ? data->parts : NULL,
+ data ? data->nr_parts : 0);
+ if (ret)
+ goto err_destroy_read_dirmap;
+
+ return 0;
+
+err_destroy_read_dirmap:
+ spi_mem_dirmap_destroy(flash->dirmap.rdesc);
+
+err_destroy_write_dirmap:
+ spi_mem_dirmap_destroy(flash->dirmap.wdesc);
+
+ return ret;
}
static int m25p_remove(struct spi_mem *spimem)
{
struct m25p *flash = spi_mem_get_drvdata(spimem);
+ int ret;
spi_nor_restore(&flash->spi_nor);
/* Clean up MTD stuff. */
- return mtd_device_unregister(&flash->spi_nor.mtd);
+ ret = mtd_device_unregister(&flash->spi_nor.mtd);
+ if (ret)
+ return ret;
+
+ spi_mem_dirmap_destroy(flash->dirmap.rdesc);
+ spi_mem_dirmap_destroy(flash->dirmap.wdesc);
+
+ return 0;
}
static void m25p_shutdown(struct spi_mem *spimem)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2019-05-31 18:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-16 17:49 [PATCH 0/2] Untangle Spansion S25F{L|S}512S chip IDs Sergei Shtylyov
2019-01-16 17:51 ` [PATCH 1/2] mtd: spi-nor: add Spansion S25FS512S ID Sergei Shtylyov
2019-01-22 10:18 ` Tudor.Ambarus
2019-01-24 11:55 ` [1/2] " Boris Brezillon
2019-01-16 17:53 ` [PATCH 2/2] mtd: spi-nor: refine Spansion S25FL512S ID Sergei Shtylyov
2019-01-22 10:18 ` Tudor.Ambarus
2019-01-24 11:55 ` [2/2] " Boris Brezillon
2019-03-05 14:05 ` [PATCH 2/2] " Geert Uytterhoeven
2019-03-06 10:59 ` Tudor.Ambarus
2019-03-06 11:28 ` Tudor.Ambarus
2019-03-12 11:02 ` Geert Uytterhoeven
2019-01-21 8:28 ` [PATCH 0/2] Untangle Spansion S25F{L|S}512S chip IDs Tudor.Ambarus
2019-01-21 17:40 ` Sergei Shtylyov
2019-05-31 18:31 ` Sergei Shtylyov [this message]
2019-06-18 4:30 ` [PATCH v4] mtd: devices: m25p80: Use the spi-mem dirmap API Vignesh Raghavendra
2019-07-03 20:26 ` [PATCH] mtd: chips: gen_probe: kill useless initializer in mtd_do_chip_probe() Sergei Shtylyov
2019-09-17 4:24 ` Vignesh Raghavendra
2019-09-17 19:28 ` [PATCH] mtd: cfi_util: use DIV_ROUND_UP() in cfi_udelay() Sergei Shtylyov
2019-09-17 19:43 ` Geert Uytterhoeven
2019-09-17 19:53 ` Sergei Shtylyov
2019-09-17 21:23 ` Geert Uytterhoeven
2019-09-18 5:45 ` Vignesh Raghavendra
2019-09-27 20:15 ` Sergei Shtylyov
2019-10-25 20:26 ` [PATCH] mtd: spi-nor: use spi-mem dirmap API Sergei Shtylyov
2019-10-26 7:36 ` Boris Brezillon
2019-11-07 18:51 ` Sergei Shtylyov
2019-11-07 20:49 ` [PATCH v2] " Sergei Shtylyov
2019-11-07 20:56 ` Sergei Shtylyov
2019-11-07 20:56 ` Sergei Shtylyov
2019-11-09 19:35 ` Boris Brezillon
2019-11-10 19:49 ` Sergei Shtylyov
2020-02-01 20:55 ` [PATCH] mtd: spi-nor: use le32_to_cpu_array() Sergei Shtylyov
2020-02-17 0:03 ` Tudor.Ambarus
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=c405efc0-58ef-c67a-d519-95e0eb843229@cogentembedded.com \
--to=sergei.shtylyov@cogentembedded.com \
--cc=bbrezillon@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.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;
as well as URLs for NNTP newsgroup(s).