gpio-rcar: Use OUTDT when reading GPIOs configured as output
Subsystems (3)
Magnus Damm
maintainerPATCH 1/1 gpio-rcar: Use OUTDT when reading GPIOs configured as output
From: Magnus Damm <[email protected]>
Testing on r8a7790 shows that INDT does not indicate the correct pin state when reading a GPIO configured as output, so update the gpio_rcar_get() function to handle this case.
---
drivers/gpio/gpio-rcar.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpio/gpio-rcar.c +8 -1
@@ -230,7 +230,14 @@ static int gpio_rcar_direction_input(strstatic int gpio_rcar_get (struct gpio_chip *chip,unsigned offset) { -return (int )(gpio_rcar_read (gpio_to_priv (chip),INDT ) &BIT (offset)); +u32 bit =BIT (offset); + +/* testing on r8a7790 shows that INDT does not show correct pin state +* when configured as output, so use OUTDT in case of output pins */ +if (gpio_rcar_read (gpio_to_priv (chip),INOUTSEL ) & bit) +return (int )(gpio_rcar_read (gpio_to_priv (chip),OUTDT ) & bit); +else +return (int )(gpio_rcar_read (gpio_to_priv (chip),INDT ) & bit); }static void gpio_rcar_set (struct gpio_chip *chip,unsigned offset,int value)
Quoted 7 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Testing on r8a7790 shows that INDT does not indicate the correct pin state when reading a GPIO configured as output, so update the
gpio_rcar_get()function to handle this case.Signed-off-by Magnus Damm <[email protected]>
Patch applied. Unless you need this to go through some SH tree, I'm carrying it in the GPIO tree.
Yours,
Linus Walleij
Magnus Damm
maintainerHi Linus,
Quoted 4 lines · Linus Walleij
Quoted 2 lines · Magnus Damm
From: Magnus Damm <[email protected]>
Quoted 8 lines
Quoted 5 lines
Testing on r8a7790 shows that INDT does not indicate the correct pin state when reading a GPIO configured as output, so update the
gpio_rcar_get()function to handle this case.Signed-off-by Magnus Damm <[email protected]>Patch applied. Unless you need this to go through some SH tree, I'm carrying it in the GPIO tree.
Thanks a lot! You carrying it in the GPIO tree sounds perfect to me.
Cheers,
/ magnus
Hi Magnus,
Quoted 5 lines · On Monday 17 June 2013 08:41:52 Magnus Damm wrote:
From: Magnus Damm <[email protected]>
Testing on r8a7790 shows that INDT does not indicate the correct pin state when reading a GPIO configured as output, so update the
gpio_rcar_get()function to handle this case.
Have you checked whether this is true on the other SoCs as well ? Reading back the output register instead of the input register will not allow detection of conflicts. If the hardware can't provide that, fine, but otherwise it would be a nice feature to keep (although it might not get used in practice).
Quoted 1 line
Signed-off-by Magnus Damm <[email protected]>
Quoted 24 lines
---
drivers/gpio/gpio-rcar.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/gpio/gpio-rcar.c +8
-1@@ -230,7 +230,14 @@ static int gpio_rcar_direction_input(strstatic int gpio_rcar_get (struct gpio_chip *chip,unsigned offset) { -return (int )(gpio_rcar_read (gpio_to_priv (chip),INDT ) &BIT (offset)); +u32 bit =BIT (offset); + +/* testing on r8a7790 shows that INDT does not show correct pin state +* when configured as output, so use OUTDT in case of output pins */ +if (gpio_rcar_read (gpio_to_priv (chip),INOUTSEL ) & bit) +return (int )(gpio_rcar_read (gpio_to_priv (chip),OUTDT ) & bit); +else +return (int )(gpio_rcar_read (gpio_to_priv (chip),INDT ) & bit); } static void gpio_rcar_set(struct gpio_chip *chip, unsigned offset, intvalue)
Signature · 3 lines
Regards, Laurent Pinchart
Magnus Damm
maintainerHi Laurent,
Quoted 5 lines · Laurent Pinchart
Hi Magnus,
Quoted 2 lines · On Monday 17 June 2013 08:41:52 Magnus Damm wrote:
From: Magnus Damm <[email protected]>
Quoted 8 lines
Quoted 3 lines
Testing on r8a7790 shows that INDT does not indicate the correct pin state when reading a GPIO configured as output, so update the
gpio_rcar_get()function to handle this case.Have you checked whether this is true on the other SoCs as well ? Reading back the output register instead of the input register will not allow detection of conflicts. If the hardware can't provide that, fine, but otherwise it would be a nice feature to keep (although it might not get used in practice).
I have not tested this patch myself, but I've received feedback from an internal team at Renesas. Regarding other SoCs, I'm quite confident in this change, the data sheet for both R-Car H2 and R-Car H1 have the following sentence in them:
"INDT is valid only for the ports for which general input/output mode is selected by the general IO/interrupt switching
register and then general input mode is selected by the general input/output switching register"
I agree it would be nice with hardware that allowed reading the pin state regardless independently of any mode setting. =)
Quoted 3 lines
Quoted 1 line
Signed-off-by Magnus Damm <[email protected]>Acked-by Laurent Pinchart <[email protected]>
Thanks!
/ magnus