From e555f20462b6c633e92649fab36d0b29e1c2e38b Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Thu, 13 Jun 2024 17:42:56 +0800 Subject: [PATCH] driver: bbram: npcx: fix the way to clear bbram status Bits in the BBRAM status register (BKUP_STS) are write-1-to-clear bits. The current driver writes 0 to clear those bits, which is incorrect. Fix it in this commit. Signed-off-by: Jun Lin --- drivers/bbram/bbram_npcx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/bbram/bbram_npcx.c b/drivers/bbram/bbram_npcx.c index ba9500ae6f1..ceca04b1d80 100644 --- a/drivers/bbram/bbram_npcx.c +++ b/drivers/bbram/bbram_npcx.c @@ -26,8 +26,16 @@ static int get_bit_and_reset(const struct device *dev, int mask) { int result = DRV_STATUS(dev) & mask; - /* Clear the bit(s) */ + /* + * Clear the bit(s): + * For emulator, write 0 to clear status bit(s). + * For real chip, write 1 to clear status bit(s). + */ +#ifdef CONFIG_BBRAM_NPCX_EMUL DRV_STATUS(dev) &= ~mask; +#else + DRV_STATUS(dev) = mask; +#endif return result; }