linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] gpio: palmas: Fix misreported GPIO out value
@ 2013-07-26 20:39 Andrew Chew
  2013-07-29  6:00 ` Laxman Dewangan
  2013-08-16 13:06 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Chew @ 2013-07-26 20:39 UTC (permalink / raw)
  To: linus.walleij, ldewangan, sameo; +Cc: achew, rklein, linux-gpio, linux-kernel

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] gpio: palmas: Fix misreported GPIO out value
  2013-07-26 20:39 [PATCH V2] gpio: palmas: Fix misreported GPIO out value Andrew Chew
@ 2013-07-29  6:00 ` Laxman Dewangan
  2013-08-16 13:06 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Laxman Dewangan @ 2013-07-29  6:00 UTC (permalink / raw)
  To: Andrew Chew
  Cc: linus.walleij@linaro.org, sameo@linux.intel.com, Rhyland Klein,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org

On Saturday 27 July 2013 02:09 AM, Andrew Chew wrote:
> 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.

Looks good to me.
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] gpio: palmas: Fix misreported GPIO out value
  2013-07-26 20:39 [PATCH V2] gpio: palmas: Fix misreported GPIO out value Andrew Chew
  2013-07-29  6:00 ` Laxman Dewangan
@ 2013-08-16 13:06 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2013-08-16 13:06 UTC (permalink / raw)
  To: Andrew Chew
  Cc: Laxman Dewangan, Samuel Ortiz, Rhyland Klein,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org

On Fri, Jul 26, 2013 at 10:39 PM, Andrew Chew <achew@nvidia.com> wrote:

> 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

Very interesting that you use gerrit, but the kernel community does not
want this.

> 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.

Applied with change-id stripped and Laxman's ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-16 13:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-26 20:39 [PATCH V2] gpio: palmas: Fix misreported GPIO out value Andrew Chew
2013-07-29  6:00 ` Laxman Dewangan
2013-08-16 13:06 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).