Skip to contentSkip to conversation

add power-supply control to enable eeprom usage

PATCH Superseded Eliav Farber 4 participants 8 messages Aug 22, 2022 – Aug 30, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover add power-supply control to enable eeprom usage

First patch describes the new binding property. Second patch adds the functionality to the driver.

Change between v2 and v1:
- Use a gpio regulator for power-supply control.

Eliav Farber (2):
dt-bindings: at24: add new optional power-supply property
eeprom: at24: add support for power-supply control

 .../devicetree/bindings/eeprom/at24.txt       |  3 ++
 drivers/misc/eeprom/at24.c                    | 41 +++++++++++++++++++
 2 files changed, 44 insertions(+)
Signature · 1 line
2.37.1
#1 lore raw

PATCH v2 1/2 dt-bindings: at24: add new optional power-supply property

Boards using the AT24 EEPROMs might have a GPIO that controls the power supply of the chip, and it must be set to enable the usage of it.

Add a new optional property to the device tree binding document, which allows to specify a GPIO regulator for the pin that controls the power.

On Linux this means that we need to enable the GPIO at the beginning of probe function, before trying to access the chip.

---
V1 -> V2:
Change pointed out by Rob Herring:
- Use a gpio regulator for power-supply control.

 Documentation/devicetree/bindings/eeprom/at24.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/eeprom/at24.txt +3 -0
index f9a7c984274c..6d23ceac5fdc 100644
@@ -73,6 +73,9 @@ Optional properties:
 
   - wp-gpios: GPIO to which the write-protect pin of the chip is connected.
 
+  - power-supply: phandle of the gpio regulator that provides the supply
+                  voltage.
+
   - address-width: number of address bits (one of 8, 16).
 
 Example:
Signature · 1 line
2.37.1
maintainer
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property

Quoted 9 lines · Eliav Farber

Boards using the AT24 EEPROMs might have a GPIO that controls the power supply of the chip, and it must be set to enable the usage of it.

Add a new optional property to the device tree binding document, which allows to specify a GPIO regulator for the pin that controls the power.

On Linux this means that we need to enable the GPIO at the beginning of probe function, before trying to access the chip.

Quoted 8 lines

---
V1 -> V2:
Change pointed out by Rob Herring:
- Use a gpio regulator for power-supply control.

 Documentation/devicetree/bindings/eeprom/at24.txt | 3 +++
 1 file changed, 3 insertions(+)

This file doesn't exist any more. Use the latest -rc1 kernel unless there is a reason you need a different (even later) base.

Rob

#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property

Quoted 5 lines · Rob Herring
Quoted 2 lines

 Documentation/devicetree/bindings/eeprom/at24.txt | 3 +++

 1 file changed, 3 insertions(+)

This file doesn't exist any more. Use the latest -rc1 kernel unless there is a reason you need a different (even later) base.

I applied the change on top of v6.0-rc1

--
Thanks, Eliav

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property

Quoted 7 lines · Eliav
Quoted 5 lines · Rob Herring
Quoted 2 lines

 Documentation/devicetree/bindings/eeprom/at24.txt | 3 +++

 1 file changed, 3 insertions(+)

This file doesn't exist any more. Use the latest -rc1 kernel unless there is a reason you need a different (even later) base.

I applied the change on top of v6.0-rc1

Not really. The file is gone since v5.5-rc1 as you can easily see in the sources.

Since you did not Cc-me, it's another proof you based your work on some old kernel.

Best regards,
Krzysztof

#5 lore raw

PATCH v2 2/2 eeprom: at24: add support for power-supply control

In reply to Eliav Farber

Add an optional gpio regulator to support a power-supply control. If a gpio power-supply regulator is supplied in the device tree, the gpio is enabled during probe, and disabled on remove.

---
V1 -> V2:
Change pointed out by Rob Herring:
- Use a gpio regulator for power-supply control.

 drivers/misc/eeprom/at24.c | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
drivers/misc/eeprom/at24.c +41 -0
index dc3537651b80..a5e3fe1403d9 100644
@@ -25,6 +25,7 @@
 #include <linux/platform_data/at24.h>
 #include <linux/pm_runtime.h>
 #include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
 
 /*
  * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -78,6 +79,8 @@ struct at24_data {
 
 	struct gpio_desc *wp_gpio;
 
+	struct regulator *supply;
+
 	/*
 	 * Some chips tie up multiple I2C addresses; dummy devices reserve
 	 * them for us, and we'll use them with SMBus calls.
@@ -615,6 +618,13 @@ static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
 	}
 }
 
+static void devm_at24_regulator_disable(void *data)
+{
+	struct at24_data *at24 = data;
+
+	regulator_disable(at24->supply);
+}
+
 static int at24_probe(struct i2c_client *client)
 {
 	struct regmap_config regmap_config = { };
@@ -674,6 +684,37 @@ static int at24_probe(struct i2c_client *client)
 	if (!at24)
 		return -ENOMEM;
 
+	at24->supply = devm_regulator_get_optional(dev, "power");
+	if (IS_ERR(at24->supply)) {
+		err = PTR_ERR(at24->supply);
+		if (err == -ENODEV)
+			at24->supply = NULL;
+		else
+			return dev_err_probe(dev, err,
+					     "failed to get power-supply regulator\n");
+	}
+
+	if (at24->supply) {
+		err = regulator_enable(at24->supply);
+		if (err < 0) {
+			dev_err(dev,
+				"failed to enable power-supply regulator: %d\n",
+				err);
+			return err;
+		}
+
+		err = devm_add_action_or_reset(dev, devm_at24_regulator_disable,
+					       at24);
+		if (err < 0) {
+			dev_err(dev,
+				"failed to adction to disable power-supply regulator: %d\n",
+				err);
+			return err;
+		}
+
+		usleep_range(2000, 3000);
+	}
+
 	mutex_init(&at24->lock);
 	at24->byte_len = pdata.byte_len;
 	at24->page_size = pdata.page_size;
Signature · 1 line
2.37.1
#6 lore raw

Re: [PATCH v2 2/2] eeprom: at24: add support for power-supply control

Quoted 6 lines · Eliav Farber

Add an optional gpio regulator to support a power-supply control. If a gpio power-supply regulator is supplied in the device tree, the gpio is enabled during probe, and disabled on remove.

This doesn't apply on top of v6.0-rc1.

Bart

#7 lore raw

Re: [PATCH v2 2/2] eeprom: at24: add support for power-supply control

Quoted 9 lines · Bartosz Golaszewski
Quoted 6 lines · Eliav Farber

Add an optional gpio regulator to support a power-supply control. If a gpio power-supply regulator is supplied in the device tree, the gpio is enabled during probe, and disabled on remove.

This doesn't apply on top of v6.0-rc1.

I applied the change on top of v6.0-rc1.
Will be part of v3 I will send soon.

--
Thanks, Eliav