From: Chen Minqiang <ptpt52@gmail.com>
To: Pratyush Yadav <pratyush@kernel.org>,
Michael Walle <mwalle@kernel.org>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>
Cc: Takahiro Kuwano <takahiro.kuwano@infineon.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Chen Minqiang <ptpt52@gmail.com>
Subject: [PATCH v2] mtd: spi-nor: allow force unlocking via DT property
Date: Thu, 6 Aug 2026 19:37:33 +0800 [thread overview]
Message-ID: <20260806113733.31042-1-ptpt52@gmail.com> (raw)
In-Reply-To: <2026-08-05171214.2934-1-ptpt52@gmail.com>
Some SPI NOR flash chips (such as generic or unlisted chips used in vendor
devices like Tenda AX12L Pro) have Block Protection (BP) bits set in the
Status Register by bootloaders or factory settings, locking flash blocks.
Because vendors frequently switch between various generic SPI NOR flash
chips ("Flash Lottery"), it is impractical to upstream explicit chip ID
flags (SNOR_F_HAS_LOCK) for every possible generic chip variant.
This patch introduces support for the "linux,force-sr-unlock" Device Tree
property:
1. In spi_nor_init_flags(), set the SNOR_F_HAS_LOCK flag on the flash
instance if "linux,force-sr-unlock" is present in the flash DT node. This
allows spi_nor_late_init_params() to automatically populate default
locking_ops without altering swp.c.
2. In spi_nor_init(), trigger spi_nor_try_unlock_all() if "linux,force-sr-unlock"
is set, invoking Linux kernel's native spi_nor_unlock() mechanism.
Signed-off-by: Chen Minqiang <ptpt52@gmail.com>
---
v1 -> v2:
- Set SNOR_F_HAS_LOCK in spi_nor_init_flags() when "linux,force-sr-unlock"
is present in DT, allowing spi_nor_late_init_params() to set default
locking_ops automatically without modifying swp.c.
---
drivers/mtd/spi-nor/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ccf4396cdcd0..9aa2aaa10c38 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2956,6 +2956,9 @@ static void spi_nor_init_flags(struct spi_nor *nor)
if (of_property_read_bool(np, "no-wp"))
nor->flags |= SNOR_F_NO_WP;
+ if (of_property_read_bool(np, "linux,force-sr-unlock"))
+ nor->flags |= SNOR_F_HAS_LOCK;
+
if (flags & SPI_NOR_SWP_IS_VOLATILE)
nor->flags |= SNOR_F_SWP_IS_VOLATILE;
@@ -3332,7 +3335,8 @@ static int spi_nor_init(struct spi_nor *nor)
spi_nor_cache_sr_lock_bits(nor, NULL);
if (IS_ENABLED(CONFIG_MTD_SPI_NOR_SWP_DISABLE) ||
(IS_ENABLED(CONFIG_MTD_SPI_NOR_SWP_DISABLE_ON_VOLATILE) &&
- nor->flags & SNOR_F_SWP_IS_VOLATILE)) {
+ nor->flags & SNOR_F_SWP_IS_VOLATILE) ||
+ of_property_read_bool(spi_nor_get_flash_node(nor), "linux,force-sr-unlock")) {
spi_nor_try_unlock_all(nor);
}
--
2.17.1
prev parent reply other threads:[~2026-08-06 11:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2026-08-05171214.2934-1-ptpt52@gmail.com>
2026-08-06 11:24 ` [PATCH] mtd: spi-nor: allow force unlocking via DT property Chen Minqiang
2026-08-06 11:37 ` Chen Minqiang [this message]
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=20260806113733.31042-1-ptpt52@gmail.com \
--to=ptpt52@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=takahiro.kuwano@infineon.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