From: Andrew Chew <achew@nvidia.com>
To: <linus.walleij@linaro.org>, <ldewangan@nvidia.com>,
<sameo@linux.intel.com>
Cc: <achew@nvidia.com>, <rklein@nvidia.com>,
<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH V2] gpio: palmas: Fix misreported GPIO out value
Date: Fri, 26 Jul 2013 13:39:53 -0700 [thread overview]
Message-ID: <1374871193-403-1-git-send-email-achew@nvidia.com> (raw)
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@nvidia.com>
---
V2: Fixed a warning from using test_bit with an int instead of long. Keeping
the int and just masking that bit in the raw now.
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..723825d 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 (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));
--
1.8.1.5
next reply other threads:[~2013-07-26 20:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 20:39 Andrew Chew [this message]
2013-07-29 6:00 ` [PATCH V2] gpio: palmas: Fix misreported GPIO out value Laxman Dewangan
2013-08-16 13:06 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374871193-403-1-git-send-email-achew@nvidia.com \
--to=achew@nvidia.com \
--cc=ldewangan@nvidia.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rklein@nvidia.com \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.