Skip to contentSkip to conversation

pinctrl: cherryview: Configure HiZ pins to be input when requested as GPIOs

PATCH In review Mika Westerberg 2 participants 3 messages Jan 29, 2015 – Feb 4, 2015

Subsystems (3)
lore
Share & tools
lore

Mika Westerberg

author maintainer
#0 lore raw

PATCH 1/1 pinctrl: cherryview: Configure HiZ pins to be input when requested as GPIOs

If the pin is in HiZ mode when it is requested as GPIO its value cannot be read (it always returns 0). In order to cope with the Linux GPIO subsystem where we do not have such state at all, turn the pin to be input instead.

---
 drivers/pinctrl/intel/pinctrl-cherryview.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/pinctrl/intel/pinctrl-cherryview.c +15 -2
index dde67d425e9c..abe18960933d 100644
@@ -880,9 +880,22 @@ static int chv_gpio_request_enable(struct pinctrl_dev *pctldev,
 		value &= ~CHV_PADCTRL1_INVRXTX_MASK;
 		chv_writel(value, reg);
 
-		/* Switch to a GPIO mode */
 		reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
-		value = readl(reg) | CHV_PADCTRL0_GPIOEN;
+		value = readl(reg);
+
+		/*
+		 * If the pin is in HiZ mode (both TX and RX buffers are
+		 * disabled) we turn it to be input now.
+		 */
+		if ((value & CHV_PADCTRL0_GPIOCFG_MASK) ==
+		     (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) {
+			value &= ~CHV_PADCTRL0_GPIOCFG_MASK;
+			value |= CHV_PADCTRL0_GPIOCFG_GPI <<
+				CHV_PADCTRL0_GPIOCFG_SHIFT;
+		}
+
+		/* Switch to a GPIO mode */
+		value |= CHV_PADCTRL0_GPIOEN;
 		chv_writel(value, reg);
 	}
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 6 lines · Mika Westerberg

If the pin is in HiZ mode when it is requested as GPIO its value cannot be read (it always returns 0). In order to cope with the Linux GPIO subsystem where we do not have such state at all, turn the pin to be input instead.

Patch applied.

Since putting a pin into GPIO mode start poking around in essentially pin control registers, we may need to revisit the issue of the pin control subsystem not denying simultaneous use of a pin for a device muxing and GPIO. Maybe the "strict" setting forcing a pin to be either one or the other on a per-driver basis would enforce a better policy on this driver (and some others).

Yours,
Linus Walleij

author maintainer
#2 lore raw
Quoted 11 lines · Linus Walleij
Quoted 6 lines · Mika Westerberg

If the pin is in HiZ mode when it is requested as GPIO its value cannot be read (it always returns 0). In order to cope with the Linux GPIO subsystem where we do not have such state at all, turn the pin to be input instead.

Patch applied.

Thanks.

Quoted 6 lines

Since putting a pin into GPIO mode start poking around in essentially pin control registers, we may need to revisit the issue of the pin control subsystem not denying simultaneous use of a pin for a device muxing and GPIO. Maybe the "strict" setting forcing a pin to be either one or the other on a per-driver basis would enforce a better policy on this driver (and some others).

Yes, something like that sounds reasonable.