linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] add power-supply control to enable eeprom usage
@ 2022-08-22 10:58 Eliav Farber
  2022-08-22 10:58 ` [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
  2022-08-22 10:58 ` [PATCH v2 2/2] eeprom: at24: add support for power-supply control Eliav Farber
  0 siblings, 2 replies; 8+ messages in thread
From: Eliav Farber @ 2022-08-22 10:58 UTC (permalink / raw)
  To: brgl, robh+dt, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel
  Cc: farbere, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw

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(+)

-- 
2.37.1


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

* [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-22 10:58 [PATCH v2 0/2] add power-supply control to enable eeprom usage Eliav Farber
@ 2022-08-22 10:58 ` Eliav Farber
  2022-08-22 21:46   ` Rob Herring
  2022-08-22 10:58 ` [PATCH v2 2/2] eeprom: at24: add support for power-supply control Eliav Farber
  1 sibling, 1 reply; 8+ messages in thread
From: Eliav Farber @ 2022-08-22 10:58 UTC (permalink / raw)
  To: brgl, robh+dt, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel
  Cc: farbere, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw

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.

Signed-off-by: Eliav Farber <farbere@amazon.com>
---
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(+)

diff --git a/Documentation/devicetree/bindings/eeprom/at24.txt b/Documentation/devicetree/bindings/eeprom/at24.txt
index f9a7c984274c..6d23ceac5fdc 100644
--- a/Documentation/devicetree/bindings/eeprom/at24.txt
+++ b/Documentation/devicetree/bindings/eeprom/at24.txt
@@ -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:
-- 
2.37.1


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

* [PATCH v2 2/2] eeprom: at24: add support for power-supply control
  2022-08-22 10:58 [PATCH v2 0/2] add power-supply control to enable eeprom usage Eliav Farber
  2022-08-22 10:58 ` [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
@ 2022-08-22 10:58 ` Eliav Farber
  2022-08-28 14:28   ` Bartosz Golaszewski
  1 sibling, 1 reply; 8+ messages in thread
From: Eliav Farber @ 2022-08-22 10:58 UTC (permalink / raw)
  To: brgl, robh+dt, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel
  Cc: farbere, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw

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.

Signed-off-by: Eliav Farber <farbere@amazon.com>
---
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(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index dc3537651b80..a5e3fe1403d9 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -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;
-- 
2.37.1


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

* Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-22 10:58 ` [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
@ 2022-08-22 21:46   ` Rob Herring
  2022-08-28 15:45     ` Farber, Eliav
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2022-08-22 21:46 UTC (permalink / raw)
  To: Eliav Farber
  Cc: brgl, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw

On Mon, Aug 22, 2022 at 10:58:29AM +0000, Eliav Farber wrote:
> 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.
> 
> Signed-off-by: Eliav Farber <farbere@amazon.com>
> ---
> 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

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

* Re: [PATCH v2 2/2] eeprom: at24: add support for power-supply control
  2022-08-22 10:58 ` [PATCH v2 2/2] eeprom: at24: add support for power-supply control Eliav Farber
@ 2022-08-28 14:28   ` Bartosz Golaszewski
  2022-08-28 15:47     ` Farber, Eliav
  0 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2022-08-28 14:28 UTC (permalink / raw)
  To: Eliav Farber
  Cc: Rob Herring, Mark Rutland, Arnd Bergmann, Greg Kroah-Hartman,
	linux-i2c, devicetree, Linux Kernel Mailing List, talel, hhhawa,
	jonnyc, hanochu, ronenk, itamark, shellykz, shorer, amitlavi,
	almogbs, dkl, dwmw

On Mon, Aug 22, 2022 at 12:58 PM Eliav Farber <farbere@amazon.com> wrote:
>
> 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.
>
> Signed-off-by: Eliav Farber <farbere@amazon.com>

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

Bart

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

* Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-22 21:46   ` Rob Herring
@ 2022-08-28 15:45     ` Farber, Eliav
  2022-08-30 17:05       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 8+ messages in thread
From: Farber, Eliav @ 2022-08-28 15:45 UTC (permalink / raw)
  To: Rob Herring
  Cc: brgl, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw, Farber, Eliav

On 8/23/2022 12:46 AM, Rob Herring wrote:
>>  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

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

* Re: [PATCH v2 2/2] eeprom: at24: add support for power-supply control
  2022-08-28 14:28   ` Bartosz Golaszewski
@ 2022-08-28 15:47     ` Farber, Eliav
  0 siblings, 0 replies; 8+ messages in thread
From: Farber, Eliav @ 2022-08-28 15:47 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Rob Herring, Mark Rutland, Arnd Bergmann, Greg Kroah-Hartman,
	linux-i2c, devicetree, Linux Kernel Mailing List, talel, hhhawa,
	jonnyc, hanochu, ronenk, itamark, shellykz, shorer, amitlavi,
	almogbs, dkl, dwmw, Farber, Eliav

On 8/28/2022 5:28 PM, Bartosz Golaszewski wrote:
> On Mon, Aug 22, 2022 at 12:58 PM Eliav Farber <farbere@amazon.com> wrote:
>>
>> 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.
>>
>> Signed-off-by: Eliav Farber <farbere@amazon.com>
>
> 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

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

* Re: [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-28 15:45     ` Farber, Eliav
@ 2022-08-30 17:05       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-30 17:05 UTC (permalink / raw)
  To: Farber, Eliav, Rob Herring
  Cc: brgl, mark.rutland, arnd, gregkh, linux-i2c, devicetree,
	linux-kernel, talel, hhhawa, jonnyc, hanochu, ronenk, itamark,
	shellykz, shorer, amitlavi, almogbs, dkl, dwmw

On 28/08/2022 18:45, Farber, Eliav wrote:
> On 8/23/2022 12:46 AM, Rob Herring wrote:
>>>  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

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

end of thread, other threads:[~2022-08-30 17:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 10:58 [PATCH v2 0/2] add power-supply control to enable eeprom usage Eliav Farber
2022-08-22 10:58 ` [PATCH v2 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
2022-08-22 21:46   ` Rob Herring
2022-08-28 15:45     ` Farber, Eliav
2022-08-30 17:05       ` Krzysztof Kozlowski
2022-08-22 10:58 ` [PATCH v2 2/2] eeprom: at24: add support for power-supply control Eliav Farber
2022-08-28 14:28   ` Bartosz Golaszewski
2022-08-28 15:47     ` Farber, Eliav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).