linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] add power-supply control to enable eeprom usage
@ 2022-08-28 15:49 Eliav Farber
  2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eliav Farber @ 2022-08-28 15:49 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 v3 and v2:
- Apply on top of v6.0-rc1.

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.yaml      |  4 ++
 drivers/misc/eeprom/at24.c                    | 40 +++++++++++++++++++
 2 files changed, 44 insertions(+)

-- 
2.37.1


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

* [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-28 15:49 [PATCH v3 0/2] add power-supply control to enable eeprom usage Eliav Farber
@ 2022-08-28 15:49 ` Eliav Farber
  2022-08-29 18:55   ` Rob Herring
  2022-08-28 15:49 ` [PATCH v3 2/2] eeprom: at24: add support for power-supply control Eliav Farber
  2022-08-31 13:00 ` [PATCH v3 0/2] add power-supply control to enable eeprom usage Bartosz Golaszewski
  2 siblings, 1 reply; 5+ messages in thread
From: Eliav Farber @ 2022-08-28 15:49 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>
---
V2 -> V3:
Apply on top of v6.0-rc1

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

diff --git a/Documentation/devicetree/bindings/eeprom/at24.yaml b/Documentation/devicetree/bindings/eeprom/at24.yaml
index d14e0accbda8..82f0046f67a9 100644
--- a/Documentation/devicetree/bindings/eeprom/at24.yaml
+++ b/Documentation/devicetree/bindings/eeprom/at24.yaml
@@ -179,6 +179,10 @@ properties:
     description:
       phandle of the regulator that provides the supply voltage.
 
+  power-supply:
+    description:
+      phandle of the gpio regulator that provides the supply voltage.
+
 required:
   - compatible
   - reg
-- 
2.37.1


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

* [PATCH v3 2/2] eeprom: at24: add support for power-supply control
  2022-08-28 15:49 [PATCH v3 0/2] add power-supply control to enable eeprom usage Eliav Farber
  2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
@ 2022-08-28 15:49 ` Eliav Farber
  2022-08-31 13:00 ` [PATCH v3 0/2] add power-supply control to enable eeprom usage Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Eliav Farber @ 2022-08-28 15:49 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>
---
V2 -> V3:
Apply on top of v6.0-rc1

 drivers/misc/eeprom/at24.c | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 633e1cf08d6e..97f16c361474 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -87,6 +87,8 @@ struct at24_data {
 	struct regulator *vcc_reg;
 	void (*read_post)(unsigned int off, char *buf, size_t count);
 
+	struct regulator *supply;
+
 	/*
 	 * Some chips tie up multiple I2C addresses; dummy devices reserve
 	 * them for us.
@@ -581,6 +583,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 = { };
@@ -681,6 +690,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 add action to disable power-supply regulator: %d\n",
+				err);
+			return err;
+		}
+
+		usleep_range(2000, 3000);
+	}
+
 	mutex_init(&at24->lock);
 	at24->byte_len = byte_len;
 	at24->page_size = page_size;
-- 
2.37.1


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

* Re: [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property
  2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
@ 2022-08-29 18:55   ` Rob Herring
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2022-08-29 18:55 UTC (permalink / raw)
  To: Eliav Farber
  Cc: Bartosz Golaszewski, Mark Rutland, Arnd Bergmann,
	Greg Kroah-Hartman, Linux I2C, devicetree, linux-kernel,
	Talel Shenhar, Hawa, Hanna, Jonathan Chocron, Hanoch, Uri,
	Krupnik, Ronen, itamark, shellykz, shorer, amitlavi, almogbs,
	dkl, Woodhouse, David

On Sun, Aug 28, 2022 at 10:49 AM Eliav Farber <farbere@amazon.com> 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>
> ---
> V2 -> V3:
> Apply on top of v6.0-rc1
>
>  Documentation/devicetree/bindings/eeprom/at24.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/eeprom/at24.yaml b/Documentation/devicetree/bindings/eeprom/at24.yaml
> index d14e0accbda8..82f0046f67a9 100644
> --- a/Documentation/devicetree/bindings/eeprom/at24.yaml
> +++ b/Documentation/devicetree/bindings/eeprom/at24.yaml
> @@ -179,6 +179,10 @@ properties:
>      description:
>        phandle of the regulator that provides the supply voltage.
>
> +  power-supply:

The datasheets I looked at say the supply name is 'VCC', so vcc-supply.

> +    description:
> +      phandle of the gpio regulator that provides the supply voltage.

What the connection is is outside the scope of the binding. IOW, it
might not be a GPIO controlled regulator. So drop the description.

> +
>  required:
>    - compatible
>    - reg
> --
> 2.37.1
>

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

* Re: [PATCH v3 0/2] add power-supply control to enable eeprom usage
  2022-08-28 15:49 [PATCH v3 0/2] add power-supply control to enable eeprom usage Eliav Farber
  2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
  2022-08-28 15:49 ` [PATCH v3 2/2] eeprom: at24: add support for power-supply control Eliav Farber
@ 2022-08-31 13:00 ` Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2022-08-31 13:00 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 Sun, Aug 28, 2022 at 5:49 PM Eliav Farber <farbere@amazon.com> wrote:
>
> First patch describes the new binding property.
> Second patch adds the functionality to the driver.
>
> Change between v3 and v2:
> - Apply on top of v6.0-rc1.
>
> 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.yaml      |  4 ++
>  drivers/misc/eeprom/at24.c                    | 40 +++++++++++++++++++
>  2 files changed, 44 insertions(+)
>
> --
> 2.37.1
>

What is the difference between this and the existing "vcc" regulator?
Why are you going through all the hoops in probe if a regular
regulator_get() will return a dummy regulator if the supply is not
found?

Bart

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

end of thread, other threads:[~2022-08-31 13:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-28 15:49 [PATCH v3 0/2] add power-supply control to enable eeprom usage Eliav Farber
2022-08-28 15:49 ` [PATCH v3 1/2] dt-bindings: at24: add new optional power-supply property Eliav Farber
2022-08-29 18:55   ` Rob Herring
2022-08-28 15:49 ` [PATCH v3 2/2] eeprom: at24: add support for power-supply control Eliav Farber
2022-08-31 13:00 ` [PATCH v3 0/2] add power-supply control to enable eeprom usage Bartosz Golaszewski

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).