diff mbox

[U-Boot] gpio: rcar_gen3: Fix GPIO read support

Message ID 20170513134804.8078-1-marek.vasut+renesas@gmail.com
State Accepted
Commit 1815c297387babb250ca2b845b5647b332b232c2
Headers show

Commit Message

Marek Vasut May 13, 2017, 1:48 p.m. UTC
From: Kouei Abe <kouei.abe.cp@renesas.com>

This patch fixes to read the GPIO status after confirming the
INOUT setting.

Signed-off-by: Kouei Abe <kouei.abe.cp@renesas.com>
Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
Cc: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Cc: Tom Rini <trini@konsulko.com>
---
 drivers/gpio/sh_pfc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Nobuhiro Iwamatsu May 13, 2017, 9:35 p.m. UTC | #1
Applied to rmobile branch, thanks!

2017-05-13 22:48 GMT+09:00 Marek Vasut <marek.vasut@gmail.com>:
> From: Kouei Abe <kouei.abe.cp@renesas.com>
>
> This patch fixes to read the GPIO status after confirming the
> INOUT setting.
>
> Signed-off-by: Kouei Abe <kouei.abe.cp@renesas.com>
> Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
> Cc: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
> Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  drivers/gpio/sh_pfc.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/sh_pfc.c b/drivers/gpio/sh_pfc.c
> index a0eac137c2..ad8da9ef28 100644
> --- a/drivers/gpio/sh_pfc.c
> +++ b/drivers/gpio/sh_pfc.c
> @@ -66,17 +66,18 @@ static void gpio_write_raw_reg(void *mapped_reg,
>  }
>
>  static int gpio_read_bit(struct pinmux_data_reg *dr,
> +                        unsigned long offset,
>                          unsigned long in_pos)
>  {
>         unsigned long pos;
>
>         pos = dr->reg_width - (in_pos + 1);
>
> -       debug("read_bit: addr = %lx, pos = %ld, "
> -                "r_width = %ld\n", dr->reg, pos, dr->reg_width);
> +       debug("read_bit: addr = %lx, pos = %ld, r_width = %ld\n",
> +             dr->reg + offset, pos, dr->reg_width);
>
> -       return
> -           (gpio_read_raw_reg(dr->mapped_reg + 0x4, dr->reg_width) >> pos) & 1;
> +       return (gpio_read_raw_reg(dr->mapped_reg + offset,
> +                                 dr->reg_width) >> pos) & 1;
>  }
>
>  static void gpio_write_bit(struct pinmux_data_reg *dr,
> @@ -559,12 +560,16 @@ static int sh_gpio_direction_output(unsigned offset, int value)
>  static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio)
>  {
>         struct pinmux_data_reg *dr = NULL;
> -       int bit = 0;
> +       int bit = 0, offset = 0;
>
>         if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
>                 return -1;
> +#if defined(CONFIG_RCAR_GEN3)
> +       if ((gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_INPUT)
> +               offset += 4;
> +#endif
>
> -       return gpio_read_bit(dr, bit);
> +       return gpio_read_bit(dr, offset, bit);
>  }
>
>  static int sh_gpio_get(unsigned offset)
> --
> 2.11.0
>
diff mbox

Patch

diff --git a/drivers/gpio/sh_pfc.c b/drivers/gpio/sh_pfc.c
index a0eac137c2..ad8da9ef28 100644
--- a/drivers/gpio/sh_pfc.c
+++ b/drivers/gpio/sh_pfc.c
@@ -66,17 +66,18 @@  static void gpio_write_raw_reg(void *mapped_reg,
 }
 
 static int gpio_read_bit(struct pinmux_data_reg *dr,
+			 unsigned long offset,
 			 unsigned long in_pos)
 {
 	unsigned long pos;
 
 	pos = dr->reg_width - (in_pos + 1);
 
-	debug("read_bit: addr = %lx, pos = %ld, "
-		 "r_width = %ld\n", dr->reg, pos, dr->reg_width);
+	debug("read_bit: addr = %lx, pos = %ld, r_width = %ld\n",
+	      dr->reg + offset, pos, dr->reg_width);
 
-	return
-	    (gpio_read_raw_reg(dr->mapped_reg + 0x4, dr->reg_width) >> pos) & 1;
+	return (gpio_read_raw_reg(dr->mapped_reg + offset,
+				  dr->reg_width) >> pos) & 1;
 }
 
 static void gpio_write_bit(struct pinmux_data_reg *dr,
@@ -559,12 +560,16 @@  static int sh_gpio_direction_output(unsigned offset, int value)
 static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio)
 {
 	struct pinmux_data_reg *dr = NULL;
-	int bit = 0;
+	int bit = 0, offset = 0;
 
 	if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
 		return -1;
+#if defined(CONFIG_RCAR_GEN3)
+	if ((gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_INPUT)
+		offset += 4;
+#endif
 
-	return gpio_read_bit(dr, bit);
+	return gpio_read_bit(dr, offset, bit);
 }
 
 static int sh_gpio_get(unsigned offset)