Skip to contentSkip to conversation

gpio: tegra: read output value when gpio is set in direction_out

PATCH Superseded Laxman Dewangan 2 participants 3 messages Nov 8, 2012 – Nov 9, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: tegra: read output value when gpio is set in direction_out

Read the output value when gpio is set for the output mode for gpio_get_value(). Reading input value in direction out does not give correct value.

---
 drivers/gpio/gpio-tegra.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/gpio/gpio-tegra.c +6 -0
index c7c175a..0fb2ce7 100644
@@ -135,6 +135,12 @@ static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 
 static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
+	int bit_val = BIT(GPIO_BIT(offset));
+
+	/* If gpio is in output mode then read from the out value */
+	if (tegra_gpio_readl(GPIO_OE(offset)) & bit_val)
+		return !!(tegra_gpio_readl(GPIO_OUT(offset)) & bit_val);
+
 	return (tegra_gpio_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1;
 }
 
Signature · 1 line
1.7.1.1
#1 lore raw
Quoted 3 lines · Laxman Dewangan

Read the output value when gpio is set for the output mode for gpio_get_value(). Reading input value in direction out does not give correct value.

That's an unfortunate HW design, but oh well. Do you have any idea why reading the input register doesn't work? If you look at the Tegra20 TRM, page 666 figure 32 "SFIO/GPIO Pin Multiplexing Architecture", there's not indication that the input path wouldn't work if the output path is active. Perhaps the issue is in the GPIO module not the pinmux module?

drivers/gpio/gpio-tegra.c static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 145

Quoted 12 lines
drivers/gpio/gpio-tegra.c +6 -0
 
 static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
+	int bit_val = BIT(GPIO_BIT(offset));
+
+	/* If gpio is in output mode then read from the out value */
+	if (tegra_gpio_readl(GPIO_OE(offset)) & bit_val)
+		return !!(tegra_gpio_readl(GPIO_OUT(offset)) & bit_val);
+
 	return (tegra_gpio_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1;
 }

Any chance of using the same kind of logic to isolate the bit value? One branch above does !!(val & mask) and the other (val >> shift) & 1.

#2 lore raw
Quoted 10 lines · Stephen Warren
Quoted 3 lines · Laxman Dewangan

Read the output value when gpio is set for the output mode for gpio_get_value(). Reading input value in direction out does not give correct value.

That's an unfortunate HW design, but oh well. Do you have any idea why reading the input register doesn't work? If you look at the Tegra20 TRM, page 666 figure 32 "SFIO/GPIO Pin Multiplexing Architecture", there's not indication that the input path wouldn't work if the output path is active. Perhaps the issue is in the GPIO module not the pinmux module?

I think this is in the gpio controller design. I again check this in cardhu wih dumping gpio registers Bank:Port CNF OE OUT IN INT_STA INT_ENB INT_LVL
2:2 1c 18 08 04 00 00 000000

GPIO pin2,pin3 and pin4 are in gpio mode.
GPIO pin 3 and pin4 are in output mode and pin2 is in input mode.
Set the output to 1 for pin3 and reading back through gpio_in register for this pin, it is showing as 0, not 1.

Quoted 5 lines
Quoted 5 lines
drivers/gpio/gpio-tegra.c +2 -0
  static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
  {
+	int bit_val = BIT(GPIO_BIT(offset));
+
Quoted 8 lines

drivers/gpio/gpio-tegra.c static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 145

Quoted 6 lines
drivers/gpio/gpio-tegra.c +4 -0
+	/* If gpio is in output mode then read from the out value */
+	if (tegra_gpio_readl(GPIO_OE(offset))&  bit_val)
+		return !!(tegra_gpio_readl(GPIO_OUT(offset))&  bit_val);
+
  	return (tegra_gpio_readl(GPIO_IN(offset))>>  GPIO_BIT(offset))&  0x1;
  }

Any chance of using the same kind of logic to isolate the bit value? One branch above does !!(val& mask) and the other (val>> shift)& 1.

It was going to more than 80 column and hence I did like this. Let me respin this patch to have same kind of.