linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Thibaut VARÈNE" <hacks+kernel@slashdirt.org>
To: linux-mtd@lists.infradead.org
Cc: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
	tudor.ambarus@microchip.com, p.yadav@ti.com, michael@walle.cc,
	git@johnthomson.fastmail.com.au,
	"Thibaut VARÈNE" <hacks+kernel@slashdirt.org>
Subject: [PATCH v3 2/3] mtd: spi-nor: set erasesize_minor for non-uniform erase
Date: Fri, 29 Jul 2022 11:16:35 +0200	[thread overview]
Message-ID: <20220729091636.59287-3-hacks+kernel@slashdirt.org> (raw)
In-Reply-To: <20220729091636.59287-1-hacks+kernel@slashdirt.org>

This patch sets erasesize_minor on SPI-NOR devices supporting
non-uniform erase, allowing write access to partitions that sit on
"minor" boundary. It preserves backward compatibility with existing
uniform behavior.

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
Signed-off-by: Thibaut VARÈNE <hacks+kernel@slashdirt.org>
---
 drivers/mtd/spi-nor/core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 502967c76..bafd3396e 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2144,6 +2144,7 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 {
 	struct spi_nor_erase_map *map = &nor->params->erase_map;
 	const struct spi_nor_erase_type *erase = NULL;
+	const struct spi_nor_erase_type *erase_minor = NULL;
 	struct mtd_info *mtd = &nor->mtd;
 	u32 wanted_size = nor->info->sector_size;
 	int i;
@@ -2172,12 +2173,14 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 
 	/*
 	 * For non-uniform SPI flash memory, set mtd->erasesize to the
-	 * maximum erase sector size. No need to set nor->erase_opcode.
+	 * maximum erase sector size and mtd->erasesize_minor to the minimum.
+	 * No need to set nor->erase_opcode.
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
 		if (map->erase_type[i].size) {
-			erase = &map->erase_type[i];
-			break;
+			if (!erase)
+				erase = &map->erase_type[i];
+			erase_minor = &map->erase_type[i];
 		}
 	}
 
@@ -2185,6 +2188,8 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 		return -EINVAL;
 
 	mtd->erasesize = erase->size;
+	if (erase_minor->size < erase->size)
+		mtd->erasesize_minor = erase_minor->size;
 	return 0;
 }
 
-- 
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2022-07-29  9:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29  9:16 [PATCH v3 0/3] mtd: write support for minor-aligned partitions Thibaut VARÈNE
2022-07-29  9:16 ` [PATCH v3 1/3] mtd: mtdpart: " Thibaut VARÈNE
2022-07-29  9:16 ` Thibaut VARÈNE [this message]
2022-07-29  9:16 ` [PATCH v3 3/3] mtd: spi-nor: allow overriding uniform erase Thibaut VARÈNE
2022-08-09  9:23 ` [PATCH v3 0/3] mtd: write support for minor-aligned partitions Thibaut VARÈNE
2022-08-09 15:45   ` 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=20220729091636.59287-3-hacks+kernel@slashdirt.org \
    --to=hacks+kernel@slashdirt.org \
    --cc=git@johnthomson.fastmail.com.au \
    --cc=linux-mtd@lists.infradead.org \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=p.yadav@ti.com \
    --cc=richard@nod.at \
    --cc=tudor.ambarus@microchip.com \
    --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).