diff mbox series

pinctrl: renesas: gpio: Use dynamic GPIO base if no function GPIOs

Message ID df2cf30ac4c3cbee726799f32b727c1ebe62819c.1668000684.git.geert+renesas@glider.be
State New
Headers show
Series pinctrl: renesas: gpio: Use dynamic GPIO base if no function GPIOs | expand

Commit Message

Geert Uytterhoeven Nov. 9, 2022, 1:33 p.m. UTC
Since commit 502df79b860563d7 ("gpiolib: Warn on drivers still using
static gpiobase allocation") in gpio/for-next, one or more warnings are
printed during boot on systems where the pin controller also provides
GPIO functionality:

    gpio gpiochip0: Static allocation of GPIO base is deprecated, use dynamic allocation.

Fix this for ARM-based SH/R-Mobile SoCs by:
  1. Taking into account a non-zero GPIO base in the various GPIO chip
     callbacks,
  2. Switching to dynamic allocation of the GPIO base when support for
     legacy function GPIOs is not enabled.

On SuperH SoCs using legacy function GPIOs, the GPIO bases of the GPIO
controller and the GPIO function controller must not be changed, as all
board files rely on the fixed GPIO_* and GPIO_FN_* definitions provided
by the various <cpu/sh*.h> header files.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Tested on all affected ARM SH/R-Mobile SoCs.

Obviously SuperH should be converted from function GPIOs to pin control.
Is it actually possible to use pin control without DT?
Unfortunately I do not have access to any of the affected systems
(SH7203, SH726[49], SH772[0234], SH7734, SH7757, SH778[56] and SHX3).
---
 drivers/pinctrl/renesas/gpio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Geert Uytterhoeven Nov. 17, 2022, 7:49 p.m. UTC | #1
On Wed, Nov 9, 2022 at 2:38 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> Since commit 502df79b860563d7 ("gpiolib: Warn on drivers still using
> static gpiobase allocation") in gpio/for-next, one or more warnings are
> printed during boot on systems where the pin controller also provides
> GPIO functionality:
>
>     gpio gpiochip0: Static allocation of GPIO base is deprecated, use dynamic allocation.
>
> Fix this for ARM-based SH/R-Mobile SoCs by:
>   1. Taking into account a non-zero GPIO base in the various GPIO chip
>      callbacks,
>   2. Switching to dynamic allocation of the GPIO base when support for
>      legacy function GPIOs is not enabled.
>
> On SuperH SoCs using legacy function GPIOs, the GPIO bases of the GPIO
> controller and the GPIO function controller must not be changed, as all
> board files rely on the fixed GPIO_* and GPIO_FN_* definitions provided
> by the various <cpu/sh*.h> header files.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thanks, queued in renesas-pinctrl-for-v6.2.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox series

Patch

diff --git a/drivers/pinctrl/renesas/gpio.c b/drivers/pinctrl/renesas/gpio.c
index ea3d38b4af8da4e1..5758daf94fe2e867 100644
--- a/drivers/pinctrl/renesas/gpio.c
+++ b/drivers/pinctrl/renesas/gpio.c
@@ -135,12 +135,12 @@  static int gpio_pin_request(struct gpio_chip *gc, unsigned offset)
 	if (idx < 0 || pfc->info->pins[idx].enum_id == 0)
 		return -EINVAL;
 
-	return pinctrl_gpio_request(offset);
+	return pinctrl_gpio_request(gc->base + offset);
 }
 
 static void gpio_pin_free(struct gpio_chip *gc, unsigned offset)
 {
-	return pinctrl_gpio_free(offset);
+	return pinctrl_gpio_free(gc->base + offset);
 }
 
 static void gpio_pin_set_value(struct sh_pfc_chip *chip, unsigned offset,
@@ -164,7 +164,7 @@  static void gpio_pin_set_value(struct sh_pfc_chip *chip, unsigned offset,
 
 static int gpio_pin_direction_input(struct gpio_chip *gc, unsigned offset)
 {
-	return pinctrl_gpio_direction_input(offset);
+	return pinctrl_gpio_direction_input(gc->base + offset);
 }
 
 static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset,
@@ -172,7 +172,7 @@  static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset,
 {
 	gpio_pin_set_value(gpiochip_get_data(gc), offset, value);
 
-	return pinctrl_gpio_direction_output(offset);
+	return pinctrl_gpio_direction_output(gc->base + offset);
 }
 
 static int gpio_pin_get(struct gpio_chip *gc, unsigned offset)
@@ -238,7 +238,7 @@  static int gpio_pin_setup(struct sh_pfc_chip *chip)
 	gc->label = pfc->info->name;
 	gc->parent = pfc->dev;
 	gc->owner = THIS_MODULE;
-	gc->base = 0;
+	gc->base = IS_ENABLED(CONFIG_PINCTRL_SH_FUNC_GPIO) ? 0 : -1;
 	gc->ngpio = pfc->nr_gpio_pins;
 
 	return 0;