From: Axel Lin Date: Mon, 7 Apr 2014 23:59:39 +0000 (+0800) Subject: gpio: zevio: Get correct gpio output value X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=ef7de2625fdd40c2d26a10bf87cc1626017adc18;p=openwrt%2Fstaging%2Fblogic.git 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 Signed-off-by: Linus Walleij --- diff --git a/drivers/gpio/gpio-zevio.c b/drivers/gpio/gpio-zevio.c index 7184f4577848..6270f755d0ed 100644 --- a/drivers/gpio/gpio-zevio.c +++ b/drivers/gpio/gpio-zevio.c @@ -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; }