LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Bartosz Golaszewski <brgl@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Paul Menzel <pmenzel@molgen.mpg.de>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev@lists.ozlabs.org, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] misc: eeprom: at24: Make VCC supply description requirement optional
Date: Sun, 24 May 2026 10:05:33 +0200	[thread overview]
Message-ID: <20260524080533.8749-2-pmenzel@molgen.mpg.de> (raw)

Some platforms (e.g. IBM Power System S822LC (8335-GCA POWER8)) do not
describe the EEPROM’s VCC supply in firmware-provided device trees.
Using `devm_regulator_get()` on such systems falls back to a dummy
regulator with a kernel warning:

    at24 0-0051: supply vcc not found, using dummy regulator
    at24 0-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
    at24 0-0052: supply vcc not found, using dummy regulator
    at24 0-0052: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    at24 0-0053: supply vcc not found, using dummy regulator
    at24 0-0053: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    at24 0-0054: supply vcc not found, using dummy regulator
    at24 0-0054: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    […]
    at24 12-0050: supply vcc not found, using dummy regulator
    at24 12-0050: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
    at24 12-0051: supply vcc not found, using dummy regulator
    at24 12-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write

Switch to `devm_regulator_get_optional()` and treat -ENODEV as “no
supply described”. When `vcc_reg` is NULL, skip all
regulator_enable/disable calls; the hardware is assumed to be always
powered. Linux now logs:

    at24 0-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
    at24 0-0052: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    at24 0-0053: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    at24 0-0054: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    at24 0-0055: 256 byte 24c02 EEPROM, writable, 1 bytes/write
    […]
    at24 12-0050: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
    at24 12-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write

Assisted-by: Claude Sonnet 4.6
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
 drivers/misc/eeprom/at24.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 0200288d3a7a..7e1050f8759a 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -699,9 +699,12 @@ static int at24_probe(struct i2c_client *client)
 	at24->offset_adj = at24_get_offset_adj(flags, byte_len);
 	at24->client_regmaps[0] = regmap;
 
-	at24->vcc_reg = devm_regulator_get(dev, "vcc");
-	if (IS_ERR(at24->vcc_reg))
-		return PTR_ERR(at24->vcc_reg);
+	at24->vcc_reg = devm_regulator_get_optional(dev, "vcc");
+	if (IS_ERR(at24->vcc_reg)) {
+		if (PTR_ERR(at24->vcc_reg) != -ENODEV)
+			return PTR_ERR(at24->vcc_reg);
+		at24->vcc_reg = NULL;
+	}
 
 	writable = !(flags & AT24_FLAG_READONLY);
 	if (writable) {
@@ -754,9 +757,12 @@ static int at24_probe(struct i2c_client *client)
 
 	full_power = acpi_dev_state_d0(&client->dev);
 	if (full_power) {
-		err = regulator_enable(at24->vcc_reg);
-		if (err)
-			return dev_err_probe(dev, err, "Failed to enable vcc regulator\n");
+		if (at24->vcc_reg) {
+			err = regulator_enable(at24->vcc_reg);
+			if (err) {
+				return dev_err_probe(dev, err, "Failed to enable vcc regulator\n");
+			}
+		}
 
 		pm_runtime_set_active(dev);
 	}
@@ -771,7 +777,7 @@ static int at24_probe(struct i2c_client *client)
 		err = at24_read(at24, 0, &test_byte, 1);
 		if (err) {
 			pm_runtime_disable(dev);
-			if (!pm_runtime_status_suspended(dev))
+			if (!pm_runtime_status_suspended(dev) && at24->vcc_reg)
 				regulator_disable(at24->vcc_reg);
 			return -ENODEV;
 		}
@@ -808,7 +814,7 @@ static void at24_remove(struct i2c_client *client)
 
 	pm_runtime_disable(&client->dev);
 	if (acpi_dev_state_d0(&client->dev)) {
-		if (!pm_runtime_status_suspended(&client->dev))
+		if (!pm_runtime_status_suspended(&client->dev) && at24->vcc_reg)
 			regulator_disable(at24->vcc_reg);
 		pm_runtime_set_suspended(&client->dev);
 	}
@@ -819,6 +825,8 @@ static int __maybe_unused at24_suspend(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct at24_data *at24 = i2c_get_clientdata(client);
 
+	if (!at24->vcc_reg)
+		return 0;
 	return regulator_disable(at24->vcc_reg);
 }
 
@@ -827,6 +835,8 @@ static int __maybe_unused at24_resume(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct at24_data *at24 = i2c_get_clientdata(client);
 
+	if (!at24->vcc_reg)
+		return 0;
 	return regulator_enable(at24->vcc_reg);
 }
 
-- 
2.53.0



             reply	other threads:[~2026-05-24  8:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24  8:05 Paul Menzel [this message]
2026-05-24 22:07 ` [PATCH] misc: eeprom: at24: Make VCC supply description requirement optional Mark Brown
2026-05-25  7:07   ` Paul Menzel
2026-05-25 10:32     ` Mark Brown

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=20260524080533.8749-2-pmenzel@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=arnd@arndb.de \
    --cc=brgl@kernel.org \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    /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