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: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Axel Lin 2014-04-08 07:59:39 +08:00 committed by Linus Walleij
parent e45d1c80c0
commit ef7de2625f
1 changed files with 8 additions and 2 deletions

View File

@ -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;
} }