linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Linus Walleij <linus.walleij@linaro.org>,
	 Bartosz Golaszewski <brgl@bgdev.pl>,
	Andy Whitcroft <apw@canonical.com>,
	 Joe Perches <joe@perches.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	 Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Fabio Estevam <festevam@gmail.com>,
	 Andy Shevchenko <andy.shevchenko@gmail.com>,
	 Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	 Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	 Haibo Chen <haibo.chen@nxp.com>,
	 Catalin Popescu <catalin.popescu@leica-geosystems.com>,
	 linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	 Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] gpio: mxc: silence warning about GPIO base being statically allocated
Date: Mon, 13 Jan 2025 23:19:12 +0100	[thread overview]
Message-ID: <20250113-b4-imx-gpio-base-warning-v1-4-0a28731a5cf6@pengutronix.de> (raw)
In-Reply-To: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de>

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 change the base to -1.

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

Fix this by silencing the warning via the gpio_base_static_alloc
opt-out instead.

[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 triggers the newly added checkpatch.pl warning, but this is
intended.
---
 drivers/gpio/gpio-mxc.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 619b6fb9d833a4bb94a93b4209f01b49ad1cbdb0..c25a50abb02389e75b5ca2924828f4a7fb32fe6c 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -45,6 +45,11 @@ struct mxc_gpio_hwdata {
 	unsigned high_level;
 	unsigned rise_edge;
 	unsigned fall_edge;
+	/*
+	 * Static allocation of GPIO base is deprecated.
+	 * Set this to false for future SoCs.
+	 */
+	bool gpio_base_static_alloc;
 };
 
 struct mxc_gpio_reg_saved {
@@ -88,6 +93,7 @@ static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = {
 	.high_level	= 0x02,
 	.rise_edge	= 0x00,
 	.fall_edge	= 0x01,
+	.gpio_base_static_alloc = true,
 };
 
 static struct mxc_gpio_hwdata imx31_gpio_hwdata = {
@@ -103,6 +109,7 @@ static struct mxc_gpio_hwdata imx31_gpio_hwdata = {
 	.high_level	= 0x01,
 	.rise_edge	= 0x02,
 	.fall_edge	= 0x03,
+	.gpio_base_static_alloc = true,
 };
 
 static struct mxc_gpio_hwdata imx35_gpio_hwdata = {
@@ -118,6 +125,7 @@ static struct mxc_gpio_hwdata imx35_gpio_hwdata = {
 	.high_level	= 0x01,
 	.rise_edge	= 0x02,
 	.fall_edge	= 0x03,
+	.gpio_base_static_alloc = true,
 };
 
 #define GPIO_DR			(port->hwdata->dr_reg)
@@ -490,7 +498,19 @@ 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;
+	port->gc.base = -1;
+
+	if (port->hwdata->gpio_base_static_alloc) {
+		/*
+		 * GPIO indices have been fixed for the i.MX GPIO controllers
+		 * for many years and changing that now will induce a lot of
+		 * breakage at runtime. Setting this member buys users some time
+		 * until they are forced to migrate when sysfs GPIO support is
+		 * removed completely.
+		 */
+		port->gc.legacy_static_base = true;
+		port->gc.base = of_alias_get_id(np, "gpio") * 32;
+	}
 
 	err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port);
 	if (err)

-- 
2.39.5


  parent reply	other threads:[~2025-01-13 22:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 22:19 [PATCH 0/4] gpio: mxc: silence warning about GPIO base being statically allocated Ahmad Fatoum
2025-01-13 22:19 ` [PATCH 1/4] gpiolib: add opt-out for existing drivers with static GPIO base Ahmad Fatoum
2025-01-14  9:49   ` Andy Shevchenko
2025-01-14 10:06     ` Ahmad Fatoum
2025-01-14 19:38       ` Andy Shevchenko
2025-01-15  7:07         ` Ahmad Fatoum
2025-01-15 13:04           ` Kent Gibson
2025-01-21 10:26             ` Ahmad Fatoum
2025-01-15 12:00   ` Linus Walleij
2025-01-21 11:34     ` Ahmad Fatoum
2025-01-13 22:19 ` [PATCH 2/4] checkpatch: warn about use of legacy_static_base Ahmad Fatoum
2025-01-14 14:37   ` Linus Walleij
2025-01-13 22:19 ` [PATCH 3/4] gpio: mxc: remove dead code after switch to DT-only Ahmad Fatoum
2025-01-14  9:51   ` Andy Shevchenko
2025-01-15 16:55   ` Bartosz Golaszewski
2025-01-21 10:16     ` Ahmad Fatoum
2025-01-13 22:19 ` Ahmad Fatoum [this message]
2025-01-14  9:46 ` [PATCH 0/4] gpio: mxc: silence warning about GPIO base being statically allocated Andy Shevchenko
2025-01-14  9:55   ` Ahmad Fatoum
2025-01-14 19:43     ` Andy Shevchenko
2025-01-15  7:03       ` Ahmad Fatoum
2025-01-15 15:16         ` Andy Shevchenko
2025-01-21 11:16           ` Ahmad Fatoum
2025-01-15 16:52     ` Bartosz Golaszewski
2025-01-21 10:37       ` Ahmad Fatoum
2025-01-23  9:19         ` Bartosz Golaszewski
2025-01-23  8:06 ` (subset) " Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113-b4-imx-gpio-base-warning-v1-4-0a28731a5cf6@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=andy.shevchenko@gmail.com \
    --cc=apw@canonical.com \
    --cc=brgl@bgdev.pl \
    --cc=catalin.popescu@leica-geosystems.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=festevam@gmail.com \
    --cc=haibo.chen@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=joe@perches.com \
    --cc=kernel@pengutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).