Skip to content

Commit 07a635b

Browse files
committed
mtd: spi-nor: add Global Block Unlock support
We can't determine this purely by manufacturer type and it's not autodetectable by anything like SFDP, so make a new flag for it: UNLOCK_GLOBAL_BLOCK. Note that the Global Block Unlock command has different names depending on the manufacturer, but always the same command value: 0x98. Macronix's MX25U12835F names it Gang Block Unlock, Winbound's W25Q128FV names it Global Block Unlock and Microchip's SST26VF064B names it Global Block Protection Unlock. Based on initial work done by Anurag Kumar Vulisha: https://patchwork.kernel.org/patch/7611271/ Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent 1f70f3b commit 07a635b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct flash_info {
9090
#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
9191
#define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */
9292
#define USE_CLSR BIT(14) /* use CLSR command */
93+
#define UNLOCK_GLOBAL_BLOCK BIT(15) /* Unlock global block protection */
9394
};
9495

9596
#define JEDEC_MFR(info) ((info)->id[0])
@@ -3414,6 +3415,17 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,
34143415
return 0;
34153416
}
34163417

3418+
static int spi_nor_unlock_global_block_protection(struct spi_nor *nor)
3419+
{
3420+
int ret;
3421+
3422+
write_enable(nor);
3423+
ret = nor->write_reg(nor, SPINOR_OP_GBULK, NULL, 0);
3424+
if (ret < 0)
3425+
return ret;
3426+
return spi_nor_wait_till_ready(nor);
3427+
}
3428+
34173429
static int spi_nor_init(struct spi_nor *nor)
34183430
{
34193431
int err;
@@ -3431,6 +3443,15 @@ static int spi_nor_init(struct spi_nor *nor)
34313443
spi_nor_wait_till_ready(nor);
34323444
}
34333445

3446+
if (nor->info->flags & UNLOCK_GLOBAL_BLOCK) {
3447+
err = spi_nor_unlock_global_block_protection(nor);
3448+
if (err) {
3449+
dev_err(nor->dev,
3450+
"Cannot unlock the global block protection\n");
3451+
return err;
3452+
}
3453+
}
3454+
34343455
if (nor->quad_enable) {
34353456
err = nor->quad_enable(nor);
34363457
if (err) {

include/linux/mtd/spi-nor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define SPINOR_OP_RDSFDP 0x5a /* Read SFDP */
6262
#define SPINOR_OP_RDCR 0x35 /* Read configuration register */
6363
#define SPINOR_OP_RDFSR 0x70 /* Read flag status register */
64+
#define SPINOR_OP_GBULK 0x98 /* Global Block Unlock Protection */
6465

6566
/* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
6667
#define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */

0 commit comments

Comments
 (0)