From 72986913fc4ba3e0c1c276aa63e2040ff8290201 Mon Sep 17 00:00:00 2001 From: Jon Lin Date: Mon, 14 Aug 2023 14:52:36 +0800 Subject: [PATCH] mtd: spinand: Enable HWP_EN for skyhigh devices HWP_EN must be enabled first before block unlock region is set. Change-Id: I6b107d97de48bb2644da865f353d2adace95224e Signed-off-by: Jon Lin --- drivers/mtd/nand/spi/core.c | 7 +++++++ include/linux/mtd/spinand.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 24cdc9356daa..f783f2c9c42f 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1118,6 +1118,13 @@ static int spinand_reinit(struct mtd_info *mtd) if (ret) return ret; + /* HWP_EN must be enabled first before block unlock region is set */ + if (spinand->id.data[0] == 0x01) { + ret = spinand_lock_block(spinand, HWP_EN); + if (ret) + return ret; + } + ret = spinand_lock_block(spinand, BL_ALL_UNLOCKED); if (ret) return ret; diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 60800872e286..04dabc460897 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -149,6 +149,7 @@ /* feature register */ #define REG_BLOCK_LOCK 0xa0 #define BL_ALL_UNLOCKED 0x00 +#define HWP_EN 0x02 /* Skyhigh feature, Hardware write protection */ /* configuration register */ #define REG_CFG 0xb0