From a60d88e5cc96261909dc3d54495ce0b1e63fdc69 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Tue, 18 Mar 2025 09:26:35 +0800 Subject: [PATCH] drivers: bbram: npcx: bypass npcx49nf errata rev1.5 No.2.30 This commit workarounds the BBRAM status register write issue in npcx4: A write operation to the BKUP_STS register might disable write to all the Battery-Backed RAM (BBRM). The workaround is to perform a fake read from the BKUP_STS register after every write to this register. Signed-off-by: Jun Lin --- drivers/bbram/Kconfig.npcx | 9 +++++++++ drivers/bbram/bbram_npcx.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/bbram/Kconfig.npcx b/drivers/bbram/Kconfig.npcx index e529022213e..d5190d7d805 100644 --- a/drivers/bbram/Kconfig.npcx +++ b/drivers/bbram/Kconfig.npcx @@ -15,3 +15,12 @@ config BBRAM_NPCX_EMUL depends on EMUL help Enable the emulator for the NPCX BBRAM. + +config BBRAM_NPCX_STATUS_REG_WRITE_WORKAROUND + bool + default y if SOC_SERIES_NPCX4 + help + Workaround the issue documented in NPCX49nF errata rev1_5, No.2.30. + A write operation to the BKUP_STS register might disable write to all + the Battery-Backed RAM. The workaround is to read the BKUP_STS + register after every write to this register. diff --git a/drivers/bbram/bbram_npcx.c b/drivers/bbram/bbram_npcx.c index c40a577fabf..d085633fe83 100644 --- a/drivers/bbram/bbram_npcx.c +++ b/drivers/bbram/bbram_npcx.c @@ -35,6 +35,12 @@ static int get_bit_and_reset(const struct device *dev, int mask) DRV_STATUS(dev) &= ~mask; #else DRV_STATUS(dev) = mask; + + if (IS_ENABLED(CONFIG_BBRAM_NPCX_STATUS_REG_WRITE_WORKAROUND)) { + uint8_t __unused read_unused; + + read_unused = DRV_STATUS(dev); + } #endif return result; @@ -72,7 +78,6 @@ static int bbram_npcx_read(const struct device *dev, size_t offset, size_t size, return -EINVAL; } - bytecpy(data, ((uint8_t *)config->base_addr + offset), size); return 0; }