diff mbox series

[1/6] gpio: Set proper argument value to set_config

Message ID b9ed544722175ea00b1f6ecb29ca5c3e1322239f.1552591798.git-series.maxime.ripard@bootlin.com (mailing list archive)
State New, archived
Headers show
Series pinctrl: sunxi: Allow to configure pull-up / pull-down from GPIO flags | expand

Commit Message

Maxime Ripard March 14, 2019, 7:32 p.m. UTC
The gpio_set_config function creates a pinconf configuration for a given
pinc_config_param.

However, it always uses an arg of 0, which might not be a valid argument
for a given param. A good example of that would be the bias parameters,
where 0 means that the pull up or down resistor is null, and the pin is
directly connected to VCC/GND.

The framework uses in some other places the value 1 as a default argument
to enable the pull resistor, so let's use the same one here.

Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
---
 drivers/gpio/gpiolib.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Linus Walleij April 3, 2019, 4:41 p.m. UTC | #1
On Fri, Mar 15, 2019 at 2:33 AM Maxime Ripard <maxime.ripard@bootlin.com> wrote:

> The gpio_set_config function creates a pinconf configuration for a given
> pinc_config_param.
>
> However, it always uses an arg of 0, which might not be a valid argument
> for a given param. A good example of that would be the bias parameters,
> where 0 means that the pull up or down resistor is null, and the pin is
> directly connected to VCC/GND.
>
> The framework uses in some other places the value 1 as a default argument
> to enable the pull resistor, so let's use the same one here.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>

Patch applied to the GPIO tree, I suppose I can merge it there
orthogonally to the other patches (the result will be fine).

Yours,
Linus Walleij
Maxime Ripard April 3, 2019, 6:36 p.m. UTC | #2
Hi Linus,

On Wed, Apr 03, 2019 at 11:41:02PM +0700, Linus Walleij wrote:
> On Fri, Mar 15, 2019 at 2:33 AM Maxime Ripard <maxime.ripard@bootlin.com> wrote:
>
> > The gpio_set_config function creates a pinconf configuration for a given
> > pinc_config_param.
> >
> > However, it always uses an arg of 0, which might not be a valid argument
> > for a given param. A good example of that would be the bias parameters,
> > where 0 means that the pull up or down resistor is null, and the pin is
> > directly connected to VCC/GND.
> >
> > The framework uses in some other places the value 1 as a default argument
> > to enable the pull resistor, so let's use the same one here.
> >
> > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
>
> Patch applied to the GPIO tree, I suppose I can merge it there
> orthogonally to the other patches (the result will be fine).

Yeah, the only drawback I can see is that the configuration will be
rejected, but since it's going to be merged in fixes, the case where
we have the driver patches but not that one seems pretty unlikely.

We have a lot going through our tree for the next release though, so
ideally we should merge the DT patches through arm-soc.

Maxime

--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Linus Walleij April 4, 2019, 4:56 a.m. UTC | #3
On Thu, Apr 4, 2019 at 1:36 AM Maxime Ripard <maxime.ripard@bootlin.com> wrote:

> > Patch applied to the GPIO tree, I suppose I can merge it there
> > orthogonally to the other patches (the result will be fine).
>
> Yeah, the only drawback I can see is that the configuration will be
> rejected, but since it's going to be merged in fixes, the case where
> we have the driver patches but not that one seems pretty unlikely.

Hm I merged it for devel (next, v5.2) as I don't think there are regressions.
But if Thomas agrees we can put this into fixes instead.

> We have a lot going through our tree for the next release though, so
> ideally we should merge the DT patches through arm-soc.

That should always be fine to do in parallel.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 144af0733581..27cb5783ef52 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2565,8 +2565,20 @@  EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
 static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
 			   enum pin_config_param mode)
 {
-	unsigned long config = { PIN_CONF_PACKED(mode, 0) };
+	unsigned long config;
+	unsigned arg;
 
+	switch (mode) {
+	case PIN_CONFIG_BIAS_PULL_DOWN:
+	case PIN_CONFIG_BIAS_PULL_UP:
+		arg = 1;
+		break;
+
+	default:
+		arg = 0;
+	}
+
+	config = PIN_CONF_PACKED(mode, arg);
 	return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
 }