Commit 8b628c65 authored by Andrew Chew's avatar Andrew Chew Committed by Linus Walleij

gpio: palmas: Fix misreported GPIO out value

It seems that the value read back from the PALMAS_GPIO_DATA_IN register
isn't valid if the GPIO direction is out.  When that's the case, we can
read back the PALMAS_GPIO_DATA_OUT register to get the proper output value.
Signed-off-by: default avatarAndrew Chew <achew@nvidia.com>
Acked-by: default avatarLaxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 5763318f
......@@ -43,9 +43,22 @@ static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset)
unsigned int val;
int ret;
ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_IN, &val);
ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_DIR, &val);
if (ret < 0) {
dev_err(gc->dev, "GPIO_DATA_IN read failed, err = %d\n", ret);
dev_err(gc->dev, "GPIO_DATA_DIR read failed, err = %d\n", ret);
return ret;
}
if (val & (1 << offset)) {
ret = palmas_read(palmas, PALMAS_GPIO_BASE,
PALMAS_GPIO_DATA_OUT, &val);
} else {
ret = palmas_read(palmas, PALMAS_GPIO_BASE,
PALMAS_GPIO_DATA_IN, &val);
}
if (ret < 0) {
dev_err(gc->dev, "GPIO_DATA_IN/OUT read failed, err = %d\n",
ret);
return ret;
}
return !!(val & BIT(offset));
......
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