Skip to contentSkip to conversation

gpio: palmas: Fix misreported GPIO out value

PATCH In review Andrew Chew 3 participants 3 messages Jul 26, 2013 – Aug 16, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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

---
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(-)
drivers/gpio/gpio-palmas.c +15 -2
index e3a4e56..723825d 100644
@@ -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));
Signature · 1 line
1.8.1.5
Acked-by on v2 1/1
#1 lore raw
Quoted 3 lines · Andrew Chew

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.

#2 lore raw
In reply to Andrew Chew
Quoted 5 lines · Andrew Chew

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.

Quoted 4 lines

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