[PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
From: Daniel Svendsen via B4 Relay
Date: Wed Nov 25 2026 - 19:16:34 EST
From: Daniel Svendsen <das@xxxxxxxxxx>
at24_regmap_write() returns as soon as the chip has ACKed the
transfer, but the EEPROM only programs the data afterwards, during its
internal write cycle (typically up to 5 ms). For all but the last
chunk, the following write is NACKed and retried until that cycle has
finished. After the last chunk nothing waits, and at24_write() drops
its runtime PM reference right away. When vcc is controlled through
runtime PM and has no other users, at24_suspend() disables the
regulator in the middle of the write cycle and the last chunk is lost,
while the write is reported as successful.
This was seen on a board where the EEPROM supply is a switchable
regulator used only by at24: 32-byte writes with a 16-byte page size
programmed just the first 16 bytes.
Wait for the write cycle to finish before releasing runtime PM by
doing a one-byte read of the last written address. at24_regmap_read()
retries while the chip NACKs, up to write_timeout.
Fixes: cd5676db0574 ("misc: eeprom: at24: support pm_runtime control")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Daniel Svendsen <das@xxxxxxxxxx>
---
drivers/nvmem/at24.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/at24.c b/drivers/nvmem/at24.c
index b9db13cc3e33..03cd83e5caff 100644
--- a/drivers/nvmem/at24.c
+++ b/drivers/nvmem/at24.c
@@ -482,6 +482,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
struct at24_data *at24;
struct device *dev;
char *buf = val;
+ char dummy;
int ret;
at24 = priv;
@@ -514,11 +515,17 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
count -= ret;
}
+ /*
+ * Wait for the last chunk's internal write cycle to finish before
+ * dropping the runtime PM reference, which may switch off vcc.
+ */
+ ret = at24_regmap_read(at24, &dummy, off - 1, 1);
+
mutex_unlock(&at24->lock);
pm_runtime_put(dev);
- return 0;
+ return ret < 0 ? ret : 0;
}
static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
---
base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838
change-id: 20261126-at24-write-cycle-7cedfd00f9f2
Best regards,
--
Daniel Svendsen <das@xxxxxxxxxx>