Commit ef7de262 authored by Axel Lin's avatar Axel Lin Committed by Linus Walleij

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.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent e45d1c80
...@@ -81,9 +81,15 @@ static inline void zevio_gpio_port_set(struct zevio_gpio *c, unsigned pin, ...@@ -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) static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin)
{ {
struct zevio_gpio *controller = to_zevio_gpio(chip); struct zevio_gpio *controller = to_zevio_gpio(chip);
u32 val, dir;
/* Only reading allowed, so no spinlock needed */ spin_lock(&controller->lock);
u32 val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT); 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; return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment