Skip to contentSkip to conversation

altera_pio: fix get_value

PATCH Superseded Julien Béraud 3 participants 5 messages Jan 4, 2019 – Jan 5, 2019 GPIO

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 altera_pio: fix get_value

gpio_get_value should return 0 or 1, not 1 << pin

---
 drivers/gpio/altera_pio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/altera_pio.c +1 -1
index 59e30979f0..997c32e56d 100644
@@ -56,7 +56,7 @@ static int altera_pio_get_value(struct udevice *dev, unsigned pin)
 	struct altera_pio_platdata *plat = dev_get_platdata(dev);
 	struct altera_pio_regs *const regs = plat->regs;
 
-	return readl(&regs->data) & (1 << pin);
+	return (readl(&regs->data) >> pin) & 1;
 }
 
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 altera_pio: fix get_value

Quoted 1 line · Julien Béraud

gpio_get_value should return 0 or 1, not 1 << pin

Is this documented somewhere ?

Quoted 10 lines
---
 drivers/gpio/altera_pio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/altera_pio.c +0 -0
index 59e30979f0..997c32e56d 100644

drivers/gpio/altera_pio.c static int altera_pio_get_value(struct udevice *dev, unsigned pin) · line 59

Quoted 5 lines
drivers/gpio/altera_pio.c +1 -1
@@ -56,7 +56,7 @@ static int altera_pio_get_value(struct udevice *dev, unsigned pin)
 	struct altera_pio_platdata *plat = dev_get_platdata(dev);
 	struct altera_pio_regs *const regs = plat->regs;
 
-	return readl(&regs->data) & (1 << pin);
+	return (readl(&regs->data) >> pin) & 1;

return !!(..condition..);

Quoted 4 lines
drivers/gpio/altera_pio.c +0 -0
 }
 
 
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 altera_pio: fix get_value

Am 04.01.2019 um 19:53 schrieb Marek Vasut:

Quoted 4 lines · Julien Béraud
Quoted 1 line

gpio_get_value should return 0 or 1, not 1 << pin

Is this documented somewhere ?

I saw it's kind of documented on 'dm_gpio_get_value', but not on struct dm_gpio_ops:

"@return GPIO value (0 for inactive, 1 for active) or -ve on error"

Regards,
Simon

Quoted 25 lines
Quoted 11 lines
---
  drivers/gpio/altera_pio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/altera_pio.c +0 -0
index 59e30979f0..997c32e56d 100644

drivers/gpio/altera_pio.c static int altera_pio_get_value(struct udevice *dev, unsigned pin) · line 59

Quoted 5 lines
drivers/gpio/altera_pio.c +1 -1
@@ -56,7 +56,7 @@ static int altera_pio_get_value(struct udevice *dev, unsigned pin)
  	struct altera_pio_platdata *plat = dev_get_platdata(dev);
  	struct altera_pio_regs *const regs = plat->regs;
 
-	return readl(&regs->data) & (1 << pin);
+	return (readl(&regs->data) >> pin) & 1;

return !!(..condition..);

Quoted 4 lines
drivers/gpio/altera_pio.c +0 -0
  }
 
 
#3 lore raw

PATCH 1/1 altera_pio: fix get_value

Quoted 10 lines · Simon Goldschmidt

Am 04.01.2019 um 19:53 schrieb Marek Vasut:

Quoted 4 lines · Julien Béraud
Quoted 1 line

gpio_get_value should return 0 or 1, not 1 << pin

Is this documented somewhere ?

I saw it's kind of documented on 'dm_gpio_get_value', but not on struct dm_gpio_ops:

"@return GPIO value (0 for inactive, 1 for active) or -ve on error"

Ah, and now that I think about it, it does make sense, since GPIO 31 would trigger an error on 32bit systems.

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH 1/1 altera_pio: fix get_value

In reply to Marek Vasut
Quoted 4 lines · Julien Béraud
Quoted 1 line

gpio_get_value should return 0 or 1, not 1 << pin

Is this documented somewhere ?

I should have mentioned that the following code in cmd/gpio.c expects it and displays a warning else.
...

		gpio_direction_output(gpio, value);
	}
	printf("gpio: pin %s (gpio %i) value is ", str_gpio, gpio);

	int nval = gpio_get_value(gpio);

	if (IS_ERR_VALUE(nval))
		printf("   Warning: no access to GPIO output value\n");
	else if (nval != value)
		printf("   Warning: value of pin is still %d\n", nval);

...

So with the current altera pio code, calling "gpio set N" with N != 0 prints a warning "value of pin is still 1 << N"

Quoted 4 lines

drivers/gpio/altera_pio.c static int altera_pio_get_value(struct udevice *dev, unsigned pin) · line 59

Quoted 2 lines
drivers/gpio/altera_pio.c +1 -1
-     return readl(&regs->data) & (1 << pin);
+     return (readl(&regs->data) >> pin) & 1;

return !!(..condition..);

Sure. I'll resend.

Julien