From: Daniel Svendsen via B4 Relay <devnull+das.emlogic.no@kernel.org>
To: Bartosz Golaszewski <brgl@kernel.org>,
Srinivas Kandagatla <srini@kernel.org>
Cc: Bibby Hsieh <bibby.hsieh@mediatek.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Daniel Svendsen <das@emlogic.no>
Subject: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
Date: Thu, 26 Nov 2026 01:15:35 +0100 [thread overview]
Message-ID: <20261126-at24-write-cycle-v1-1-ec9c38617130@emlogic.no> (raw)
From: Daniel Svendsen <das@emlogic.no>
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@vger.kernel.org
Signed-off-by: Daniel Svendsen <das@emlogic.no>
---
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@emlogic.no>
next reply other threads:[~2026-11-26 0:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:15 Daniel Svendsen via B4 Relay [this message]
2026-11-26 14:58 ` Bartosz Golaszewski
2026-11-27 14:21 Kristian Otnes (kotnes)
2026-11-27 20:33 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126-at24-write-cycle-v1-1-ec9c38617130@emlogic.no \
--to=devnull+das.emlogic.no@kernel.org \
--cc=bibby.hsieh@mediatek.com \
--cc=brgl@kernel.org \
--cc=das@emlogic.no \
--cc=linux-kernel@vger.kernel.org \
--cc=srini@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®