gpio: dw: Return output value when direction is out
authorSean Anderson <seanga2@gmail.com>
Mon, 14 Sep 2020 15:02:01 +0000 (11:02 -0400)
committerTom Rini <trini@konsulko.com>
Thu, 8 Oct 2020 15:42:36 +0000 (11:42 -0400)
dm_gpio_ops.get_value can be called when the gpio is either input or
output. The current dw code always returns the input value, which is
invalid if the direction is set to out.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Ley Foon Tan <ley.foon.tan@intel.com>
drivers/gpio/dwapb_gpio.c

index a52c9e1..37916e7 100644 (file)
@@ -66,13 +66,6 @@ static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,
        return 0;
 }
 
-static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
-{
-       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
-       return !!(readl(plat->base + GPIO_EXT_PORT(plat->bank)) & (1 << pin));
-}
-
-
 static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 {
        struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
@@ -98,6 +91,18 @@ static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)
                return GPIOF_INPUT;
 }
 
+static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+       u32 value;
+
+       if (dwapb_gpio_get_function(dev, pin) == GPIOF_OUTPUT)
+               value = readl(plat->base + GPIO_SWPORT_DR(plat->bank));
+       else
+               value = readl(plat->base + GPIO_EXT_PORT(plat->bank));
+       return !!(value & BIT(pin));
+}
+
 static const struct dm_gpio_ops gpio_dwapb_ops = {
        .direction_input        = dwapb_gpio_direction_input,
        .direction_output       = dwapb_gpio_direction_output,