Skip to contentSkip to conversation

gpio: zevio: Get correct gpio output value

PATCH In review Axel Lin 2 participants 4 messages Apr 7, 2014 – Apr 22, 2014 GPIO

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v2 1/1 gpio: zevio: Get correct gpio output value

Read gpio output value from ZEVIO_GPIO_OUTPUT.
The spin_lock is required to ensure the direction is not changed before reading input/ouput value.

---
 drivers/gpio/gpio-zevio.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpio/gpio-zevio.c +8 -2
index 9bf5034..29b0150 100644
@@ -81,9 +81,15 @@ static inline void zevio_gpio_port_set(struct zevio_gpio *c, unsigned pin,
 static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin)
 {
 	struct zevio_gpio *controller = to_zevio_gpio(chip);
+	u32 val, dir;
 
-	/* Only reading allowed, so no spinlock needed */
-	u32 val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT);
+	spin_lock(&controller->lock);
+	dir = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_DIRECTION);
+	if (dir & BIT(ZEVIO_GPIO_BIT(pin)))
+		val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT);
+	else
+		val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_OUTPUT);
+	spin_unlock(&controller->lock);
 
 	return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1;
 }
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 5 lines · Axel Lin

Read gpio output value from ZEVIO_GPIO_OUTPUT.
The spin_lock is required to ensure the direction is not changed before reading input/ouput value.

Waiting for an ACK in this v2 version.

Should it be tagged for stable even?

Yours,
Linus Walleij

author
#2 lore raw

2014-04-11 1:56 GMT+08:00 Linus Walleij <[email protected]>:

Quoted 11 lines · Axel Lin
Quoted 6 lines

Read gpio output value from ZEVIO_GPIO_OUTPUT.
The spin_lock is required to ensure the direction is not changed before reading input/ouput value.

Waiting for an ACK in this v2 version.

Should it be tagged for stable even?

This is a new driver, so no need for stable.

Regards,
Axel

#3 lore raw
In reply to Axel Lin
Quoted 5 lines · Axel Lin

Read gpio output value from ZEVIO_GPIO_OUTPUT.
The spin_lock is required to ensure the direction is not changed before reading input/ouput value.

OK out of patience waiting for ACKs, v2 patch applied.

Yours,
Linus Walleij