2024-05-29 09:50:25

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v2] regulator: gpio: Correct default GPIO state to LOW

According to the GPIO regulator DT bindings[1], the default GPIO state
is LOW. However, the driver defaults to HIGH.

Before the conversion to descriptors in commit d6cd33ad71029a3f
("regulator: gpio: Convert to use descriptors"), the default state used
by the driver was rather ill-defined, too:
- If the "gpio-states" property was missing or empty, the default was
low, matching the bindings.
- If the "gpio-states" property was present, the default for missing
entries was the value of the last present entry.

Fix this by making the driver adhere to the DT bindings, i.e. default to
LOW.

[1] Documentation/devicetree/bindings/regulator/gpio-regulator.yaml

Signed-off-by: Geert Uytterhoeven <[email protected]>
Acked-by: Linus Walleij <[email protected]>
---
I have no idea if this has any impact.
I guess most/all DTS files have proper gpios-states properties?

v2:
- Add Acked-by.
---
drivers/regulator/gpio-regulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 65927fa2ef161cda..5dfed8bae0c4cfdc 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -176,9 +176,9 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
ret = of_property_read_u32_index(np, "gpios-states", i,
&val);

- /* Default to high per specification */
+ /* Default to low per specification */
if (ret)
- config->gflags[i] = GPIOD_OUT_HIGH;
+ config->gflags[i] = GPIOD_OUT_LOW;
else
config->gflags[i] =
val ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
--
2.34.1



2024-05-29 13:19:30

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v2] regulator: gpio: Correct default GPIO state to LOW

Hi Mark,

On Wed, May 29, 2024 at 3:15 PM Mark Brown <[email protected]> wrote:
> On Wed, May 29, 2024 at 11:49:51AM +0200, Geert Uytterhoeven wrote:
> > According to the GPIO regulator DT bindings[1], the default GPIO state
> > is LOW. However, the driver defaults to HIGH.
>
> > Before the conversion to descriptors in commit d6cd33ad71029a3f
> > ("regulator: gpio: Convert to use descriptors"), the default state used
> > by the driver was rather ill-defined, too:
>
> That was 4 years ago...
>
> > I have no idea if this has any impact.
> > I guess most/all DTS files have proper gpios-states properties?
>
> That seems optimistic, and a grep in mainline shows some users but not
> really as many as I'd intuitively expect.
>
> > - /* Default to high per specification */
> > + /* Default to low per specification */
> > if (ret)
> > - config->gflags[i] = GPIOD_OUT_HIGH;
> > + config->gflags[i] = GPIOD_OUT_LOW;
> > else
>
> The risk here is that we start glitching the power where previously we
> didn't. This does make me nervous.

/me too

The alternative is to change the GPIO regulator DT bindings document
to match the code...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68korg

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2024-05-29 13:19:46

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v2] regulator: gpio: Correct default GPIO state to LOW

On Wed, May 29, 2024 at 11:49:51AM +0200, Geert Uytterhoeven wrote:
> According to the GPIO regulator DT bindings[1], the default GPIO state
> is LOW. However, the driver defaults to HIGH.

> Before the conversion to descriptors in commit d6cd33ad71029a3f
> ("regulator: gpio: Convert to use descriptors"), the default state used
> by the driver was rather ill-defined, too:

That was 4 years ago...

> I have no idea if this has any impact.
> I guess most/all DTS files have proper gpios-states properties?

That seems optimistic, and a grep in mainline shows some users but not
really as many as I'd intuitively expect.

> - /* Default to high per specification */
> + /* Default to low per specification */
> if (ret)
> - config->gflags[i] = GPIOD_OUT_HIGH;
> + config->gflags[i] = GPIOD_OUT_LOW;
> else

The risk here is that we start glitching the power where previously we
didn't. This does make me nervous.


Attachments:
(No filename) (959.00 B)
signature.asc (499.00 B)
Download all attachments

2024-05-29 13:37:39

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v2] regulator: gpio: Correct default GPIO state to LOW

On Wed, May 29, 2024 at 03:19:04PM +0200, Geert Uytterhoeven wrote:
> On Wed, May 29, 2024 at 3:15 PM Mark Brown <[email protected]> wrote:

> > The risk here is that we start glitching the power where previously we
> > didn't. This does make me nervous.

> /me too

> The alternative is to change the GPIO regulator DT bindings document
> to match the code...

Yup, that makes me feel a lot safer than changing the code.


Attachments:
(No filename) (438.00 B)
signature.asc (499.00 B)
Download all attachments