Skip to content

Commit 18d7d01

Browse files
Amit Kumar Mahapatraambarus
authored andcommitted
mtd: spi-nor: Avoid setting SRWD bit in SR if WP# signal not connected
Setting the status register write disable (SRWD) bit in the status register (SR) with WP# signal of the flash left floating or wrongly tied to GND (that includes internal pull-downs), will configure the SR permanently as read-only. If WP# signal is left floating or wrongly tied to GND, avoid setting SRWD bit while writing the SR during flash protection. Signed-off-by: Amit Kumar Mahapatra <[email protected]> Reviewed-by: Michael Walle <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tudor Ambarus <[email protected]>
1 parent cfc2928 commit 18d7d01

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,6 +2844,9 @@ static void spi_nor_init_flags(struct spi_nor *nor)
28442844
if (of_property_read_bool(np, "broken-flash-reset"))
28452845
nor->flags |= SNOR_F_BROKEN_RESET;
28462846

2847+
if (of_property_read_bool(np, "no-wp"))
2848+
nor->flags |= SNOR_F_NO_WP;
2849+
28472850
if (flags & SPI_NOR_SWP_IS_VOLATILE)
28482851
nor->flags |= SNOR_F_SWP_IS_VOLATILE;
28492852

drivers/mtd/spi-nor/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ enum spi_nor_option_flags {
132132
SNOR_F_SWP_IS_VOLATILE = BIT(13),
133133
SNOR_F_RWW = BIT(14),
134134
SNOR_F_ECC = BIT(15),
135+
SNOR_F_NO_WP = BIT(16),
135136
};
136137

137138
struct spi_nor_read_command {

drivers/mtd/spi-nor/debugfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const char *const snor_f_names[] = {
2727
SNOR_F_NAME(SWP_IS_VOLATILE),
2828
SNOR_F_NAME(RWW),
2929
SNOR_F_NAME(ECC),
30+
SNOR_F_NAME(NO_WP),
3031
};
3132
#undef SNOR_F_NAME
3233

drivers/mtd/spi-nor/swp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,13 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
214214

215215
status_new = (status_old & ~mask & ~tb_mask) | val;
216216

217-
/* Disallow further writes if WP pin is asserted */
218-
status_new |= SR_SRWD;
217+
/*
218+
* Disallow further writes if WP# pin is neither left floating nor
219+
* wrongly tied to GND (that includes internal pull-downs).
220+
* WP# pin hard strapped to GND can be a valid use case.
221+
*/
222+
if (!(nor->flags & SNOR_F_NO_WP))
223+
status_new |= SR_SRWD;
219224

220225
if (!use_top)
221226
status_new |= tb_mask;

0 commit comments

Comments
 (0)