diff mbox

gpio-rcar: Use OUTDT when reading GPIOs configured as output

Message ID 20130616234152.23721.85467.sendpatchset@w520 (mailing list archive)
State Accepted
Headers show

Commit Message

Magnus Damm June 16, 2013, 11:41 p.m. UTC
From: Magnus Damm <damm@opensource.se>

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 <damm@opensource.se>
---

 drivers/gpio/gpio-rcar.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Linus Walleij June 17, 2013, 8:35 a.m. UTC | #1
On Mon, Jun 17, 2013 at 1:41 AM, Magnus Damm <magnus.damm@gmail.com> wrote:

> From: Magnus Damm <damm@opensource.se>
>
> 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 <damm@opensource.se>

Patch applied. Unless you need this to go through some SH
tree, I'm carrying it in the GPIO tree.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Magnus Damm June 17, 2013, 9:22 a.m. UTC | #2
Hi Linus,

On Mon, Jun 17, 2013 at 5:35 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, Jun 17, 2013 at 1:41 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
>
>> From: Magnus Damm <damm@opensource.se>
>>
>> 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 <damm@opensource.se>
>
> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart June 17, 2013, 10:58 a.m. UTC | #3
Hi Magnus,

On Monday 17 June 2013 08:41:52 Magnus Damm wrote:
> From: Magnus Damm <damm@opensource.se>
> 
> 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).

> Signed-off-by: Magnus Damm <damm@opensource.se>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> 
>  drivers/gpio/gpio-rcar.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> --- 0001/drivers/gpio/gpio-rcar.c
> +++ work/drivers/gpio/gpio-rcar.c	2013-06-12 09:23:53.000000000 +0900
> @@ -230,7 +230,14 @@ static int gpio_rcar_direction_input(str
> 
>  static 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)
Magnus Damm June 17, 2013, 11:45 a.m. UTC | #4
Hi Laurent,

On Mon, Jun 17, 2013 at 7:58 PM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
> Hi Magnus,
>
> On Monday 17 June 2013 08:41:52 Magnus Damm wrote:
>> From: Magnus Damm <damm@opensource.se>
>>
>> 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. =)

>> Signed-off-by: Magnus Damm <damm@opensource.se>
>
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks!

/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- 0001/drivers/gpio/gpio-rcar.c
+++ work/drivers/gpio/gpio-rcar.c	2013-06-12 09:23:53.000000000 +0900
@@ -230,7 +230,14 @@  static int gpio_rcar_direction_input(str
 
 static 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)