mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
@ 2026-11-27 14:21 Kristian Otnes (kotnes)
  2026-11-27 20:33 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Kristian Otnes (kotnes) @ 2026-11-27 14:21 UTC (permalink / raw)
  To: brgl; +Cc: bibby.hsieh, das, linux-kernel, srini, stable, das

This is ONLY a check for a detail on this patch, in case it has not been considered. It is not intended as a vote against the patch:

The at24 driver is presumably very old and was designed in a way with checking if eeprom is accessible BEFORE reading or writing. That takes care of the delayed internal write process. One can speculate why this approach was used, but it does avoid delays on occasional writes, since no wait added after final byte/page write, and potentially completed on next later access. The question is, should that concept be changed by now always adding a wait after a write?

The subtle problem documented for causing this patch was caused by the PM support added much later. If one wants to keep the original at24 design behavior, maybe one should look into how PM support to driver is handled. Either look into if PM autosuspend can be used or possibly only add a delay/polling if the device is under PM management (ie consumer registered or something).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-27 14:21 [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM Kristian Otnes (kotnes)
@ 2026-11-27 20:33 ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-11-27 20:33 UTC (permalink / raw)
  To: Kristian Otnes (kotnes)
  Cc: brgl, bibby.hsieh, das, linux-kernel, srini, stable

On Fri, Nov 27, 2026 at 02:21:26PM +0000, Kristian Otnes (kotnes) wrote:
> This is ONLY a check for a detail on this patch, in case it has not been considered. It is not intended as a vote against the patcha

There is no context here :(

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
  2026-11-26  0:15 Daniel Svendsen via B4 Relay
@ 2026-11-26 14:58 ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-11-26 14:58 UTC (permalink / raw)
  To: Daniel Svendsen; +Cc: Srinivas Kandagatla, Bibby Hsieh, linux-kernel, stable

On Thu, Nov 26, 2026 at 01:15:35AM +0100, Daniel Svendsen wrote:
> 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>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM
@ 2026-11-26  0:15 Daniel Svendsen via B4 Relay
  2026-11-26 14:58 ` Bartosz Golaszewski
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Svendsen via B4 Relay @ 2026-11-26  0:15 UTC (permalink / raw)
  To: Bartosz Golaszewski, Srinivas Kandagatla
  Cc: Bibby Hsieh, linux-kernel, stable, Daniel Svendsen

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>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27 20:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 14:21 [PATCH] eeprom: at24: wait for write cycle before releasing runtime PM Kristian Otnes (kotnes)
2026-11-27 20:33 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2026-11-26  0:15 Daniel Svendsen via B4 Relay
2026-11-26 14:58 ` Bartosz Golaszewski

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®