linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n
@ 2025-05-07 13:07 Ahmad Fatoum
  2025-05-13 13:04 ` Linus Walleij
  2025-05-15 15:01 ` Bartosz Golaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-05-07 13:07 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam
  Cc: linux-gpio, Dario Binacchi, Haibo Chen, Catalin Popescu, imx,
	linux-arm-kernel, linux-kernel, Ahmad Fatoum

i.MX GPIO numbering has been deterministic since commit 7e6086d9e54a
("gpio/mxc: specify gpio base for device tree probe"), a year after
device tree support was first added back in 2011.

Reverting to dynamically allocated GPIO base now would break most
systems making use of the sysfs API. These systems will be eventually
broken by the removal of the sysfs API, but that would result in GPIO
scripts not working instead of essentially toggling at random according
to probe order, which would happen if we unconditionally set base to -1.

Yet, the warning is annoying and has resulted in many rejected attempts
to remove it over the years[1][2][3].

As the i.MX GPIO driver is device tree only, GPIO_SYSFS is the only
consumer of the deterministic GPIO numbering. Let's therefore restrict the
static base and the warning that comes with it to configurations
with CONFIG_GPIO_SYSFS enabled.

[1]: https://lore.kernel.org/all/20230226205319.1013332-1-dario.binacchi@amarulasolutions.com/
[2]: https://lore.kernel.org/all/20230506085928.933737-2-haibo.chen@nxp.com/
[3]: https://lore.kernel.org/all/20241121145515.3087855-1-catalin.popescu@leica-geosystems.com/

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
This was one result of the discussion with Bartosz at FOSDEM 2025.
---
Changes in v2:
- drop warning opt-out flag
- set a dynamic base only if sysfs support is disabled.
- drop unrelated driver cleanup separately picked by Bartosz
- Link to v1: https://lore.kernel.org/r/20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de
---
 drivers/gpio/gpio-mxc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 619b6fb9d833a4bb94a93b4209f01b49ad1cbdb0..38504c9486b05802a792367111c9d71dc08bdd16 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -490,7 +490,14 @@ static int mxc_gpio_probe(struct platform_device *pdev)
 	port->gc.request = mxc_gpio_request;
 	port->gc.free = mxc_gpio_free;
 	port->gc.to_irq = mxc_gpio_to_irq;
-	port->gc.base = of_alias_get_id(np, "gpio") * 32;
+	/*
+	 * Driver is DT-only, so a fixed base needs only be maintained for legacy
+	 * userspace with sysfs interface.
+	 */
+	if (IS_ENABLED(CONFIG_GPIO_SYSFS))
+		port->gc.base = of_alias_get_id(np, "gpio") * 32;
+	else /* silence boot time warning */
+		port->gc.base = -1;
 
 	err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port);
 	if (err)

---
base-commit: 92a09c47464d040866cf2b4cd052bc60555185fb
change-id: 20250113-b4-imx-gpio-base-warning-4f9ae89887d0

Best regards,
-- 
Ahmad Fatoum <a.fatoum@pengutronix.de>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n
  2025-05-07 13:07 [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n Ahmad Fatoum
@ 2025-05-13 13:04 ` Linus Walleij
  2025-05-15 15:01 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2025-05-13 13:04 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Bartosz Golaszewski, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, linux-gpio,
	Dario Binacchi, Haibo Chen, Catalin Popescu, imx,
	linux-arm-kernel, linux-kernel

On Wed, May 7, 2025 at 3:07 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:

> i.MX GPIO numbering has been deterministic since commit 7e6086d9e54a
> ("gpio/mxc: specify gpio base for device tree probe"), a year after
> device tree support was first added back in 2011.
>
> Reverting to dynamically allocated GPIO base now would break most
> systems making use of the sysfs API. These systems will be eventually
> broken by the removal of the sysfs API, but that would result in GPIO
> scripts not working instead of essentially toggling at random according
> to probe order, which would happen if we unconditionally set base to -1.
>
> Yet, the warning is annoying and has resulted in many rejected attempts
> to remove it over the years[1][2][3].
>
> As the i.MX GPIO driver is device tree only, GPIO_SYSFS is the only
> consumer of the deterministic GPIO numbering. Let's therefore restrict the
> static base and the warning that comes with it to configurations
> with CONFIG_GPIO_SYSFS enabled.
>
> [1]: https://lore.kernel.org/all/20230226205319.1013332-1-dario.binacchi@amarulasolutions.com/
> [2]: https://lore.kernel.org/all/20230506085928.933737-2-haibo.chen@nxp.com/
> [3]: https://lore.kernel.org/all/20241121145515.3087855-1-catalin.popescu@leica-geosystems.com/
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Well that is an interesting way to do it. OK I guess!

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n
  2025-05-07 13:07 [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n Ahmad Fatoum
  2025-05-13 13:04 ` Linus Walleij
@ 2025-05-15 15:01 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2025-05-15 15:01 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Ahmad Fatoum
  Cc: Bartosz Golaszewski, linux-gpio, Dario Binacchi, Haibo Chen,
	Catalin Popescu, imx, linux-arm-kernel, linux-kernel

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Wed, 07 May 2025 15:07:25 +0200, Ahmad Fatoum wrote:
> i.MX GPIO numbering has been deterministic since commit 7e6086d9e54a
> ("gpio/mxc: specify gpio base for device tree probe"), a year after
> device tree support was first added back in 2011.
> 
> Reverting to dynamically allocated GPIO base now would break most
> systems making use of the sysfs API. These systems will be eventually
> broken by the removal of the sysfs API, but that would result in GPIO
> scripts not working instead of essentially toggling at random according
> to probe order, which would happen if we unconditionally set base to -1.
> 
> [...]

Applied, thanks!

[1/1] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n
      https://git.kernel.org/brgl/linux/c/0a45c1a002705c8622738fbd2a2913acf886ea27

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-15 15:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07 13:07 [PATCH v2] gpio: mxc: configure dynamic GPIO base for CONFIG_GPIO_SYSFS=n Ahmad Fatoum
2025-05-13 13:04 ` Linus Walleij
2025-05-15 15:01 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).