[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1374868766-8646-1-git-send-email-achew@nvidia.com>
Date: Fri, 26 Jul 2013 12:59:26 -0700
From: Andrew Chew <achew@...dia.com>
To: <linus.walleij@...aro.org>, <ldewangan@...dia.com>,
<sameo@...ux.intel.com>
CC: <achew@...dia.com>, <rklein@...dia.com>,
<linux-gpio@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] 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.
Change-Id: Iaf877e538cfdb37a6759c45ec3c6e4ee31078709
Signed-off-by: Andrew Chew <achew@...dia.com>
---
drivers/gpio/gpio-palmas.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c
index e3a4e56..7606a85 100644
--- a/drivers/gpio/gpio-palmas.c
+++ b/drivers/gpio/gpio-palmas.c
@@ -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 (test_bit(offset, &val)) {
+ 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));
--
1.8.1.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists