From patchwork Mon Jan 13 22:19:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmad Fatoum X-Patchwork-Id: 857050 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A6541F9F40 for ; Mon, 13 Jan 2025 22:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806799; cv=none; b=sGqEaW4VJwOVv69YVIN8je5JNqGdYfLBRN3CNXRQlmJ6paRNMIl4jCz464tRwe9jWXyubqBS3FFiBpXmQ4ObVln04MTi9NNtOEZx09SDUD760xUL8LoYq0NTgr8y8DvMZqVQrlaGCuNOYWTJvVel87rPBU5RVOZnPiHC5cmygZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806799; c=relaxed/simple; bh=3tZhAPCNYwnEOO3+MI7+F0UKPfOLrwl6htzbycYw4qc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XYAG15Nehc2NJrPs2y2hZlu0EZpWaTfu7kOgIHWg1+P4P1cHLihOL0LBLsOdAcjHOJGFYZYuuATny/JEvHxDSxiWFfkGav+P0y4qq25hs9dnLYf7MVm17Fj3NLLV96UA/KwynOuFriSLqxzhZuzU5WVeqJvR0Au6jdv7xpYcnoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tXSmF-0005yj-7t; Mon, 13 Jan 2025 23:19:19 +0100 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXSmD-000KYf-29; Mon, 13 Jan 2025 23:19:18 +0100 Received: from localhost ([::1] helo=dude05.red.stw.pengutronix.de) by dude05.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tXSmE-008p8i-2c; Mon, 13 Jan 2025 23:19:18 +0100 From: Ahmad Fatoum Date: Mon, 13 Jan 2025 23:19:09 +0100 Subject: [PATCH 1/4] gpiolib: add opt-out for existing drivers with static GPIO base Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250113-b4-imx-gpio-base-warning-v1-1-0a28731a5cf6@pengutronix.de> References: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> In-Reply-To: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> To: Linus Walleij , Bartosz Golaszewski , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Fabio Estevam , Andy Shevchenko , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team Cc: Dario Binacchi , Haibo Chen , Catalin Popescu , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Ahmad Fatoum X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Some drivers have had deterministic GPIO numbering for most of their existence, e.g. the i.MX GPIO since commit 7e6086d9e54a ("gpio/mxc: specify gpio base for device tree probe"), more than 12 years ago. Reverting this to dynamically numbered will break existing setups in the worst manner possible: The build will succeed, the kernel will not print warnings, but users will find their devices essentially toggling GPIOs at random with the potential of permanent damage. As these concerns won't go away until the sysfs interface is removed, let's add a new struct gpio_chip::legacy_static_base member that can be used by existing drivers that have been grandfathered in to suppress the warning currently being printed: gpio gpiochip0: Static allocation of GPIO base is deprecated, use dynamic allocation. Signed-off-by: Ahmad Fatoum --- drivers/gpio/gpiolib.c | 2 +- include/linux/gpio/driver.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 679ed764cb143c4b3357106de1570e8d38441372..bedeb8f28badfb7287c4929f9ad0825e050a79c9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1011,7 +1011,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, * drop this and assign a poison instead. */ gc->base = base; - } else { + } else if (!gc->legacy_static_base) { dev_warn(&gdev->dev, "Static allocation of GPIO base is deprecated, use dynamic allocation.\n"); } diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 2dd7cb9cc270a68ddedbcdd5d44e0d0f88dfa785..6e820d79d03e61123f89aaf884d35d4a1a5918a7 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -382,6 +382,10 @@ struct gpio_irq_chip { * implies that if the chip supports IRQs, these IRQs need to be threaded * as the chip access may sleep when e.g. reading out the IRQ status * registers. + * @legacy_static_base: set for some existing drivers, where @base is non-negative + * and changing that would induce so much breakage that they were + * grandfathered in until GPIO sysfs support is removed altogether. + * Do not set this for any new drivers. * @read_reg: reader function for generic GPIO * @write_reg: writer function for generic GPIO * @be_bits: if the generic GPIO has big endian bit order (bit 31 is representing @@ -467,6 +471,7 @@ struct gpio_chip { u16 offset; const char *const *names; bool can_sleep; + bool legacy_static_base; #if IS_ENABLED(CONFIG_GPIO_GENERIC) unsigned long (*read_reg)(void __iomem *reg); From patchwork Mon Jan 13 22:19:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmad Fatoum X-Patchwork-Id: 857052 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBD6E1E9B13 for ; Mon, 13 Jan 2025 22:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806768; cv=none; b=LKURBvJ95mjDEPYP2P3+s4gwluqvqNOI2vJr9ntCRhW/ca6IYiFnBWyFw4//RXCXuX9SOTipwN+GktmbhlhY94pN1L9RLwqormTTEDJB8f60ivWiZ1lGpGbpMfKoVHmy0F17WtSoLD75oJiTj+w1LSASWgpdiTsn3M9rcEw96Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806768; c=relaxed/simple; bh=UEfyMNkflJZ2fhNc05ylC23IiSAozSl7+gLNlTjVK4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jOIKzw6lBrBzrsJH1cZGSpVyfYlL0gmGPC2Ct4U8kVKGLl7ArjhwFGgz/TwMFeNFB7nWrCuOsJ2BITHRUMw7wzygX9EIb1bOYTvcREXvl4/Dulhdg/IXO0NR9uRtgVCPNFsRbnb5Wo2bDkz95/Cd6D/cVN0949pb9xptWo7Lbss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tXSmF-0005yk-7t; Mon, 13 Jan 2025 23:19:19 +0100 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXSmD-000KYg-2A; Mon, 13 Jan 2025 23:19:18 +0100 Received: from localhost ([::1] helo=dude05.red.stw.pengutronix.de) by dude05.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tXSmE-008p8i-2d; Mon, 13 Jan 2025 23:19:18 +0100 From: Ahmad Fatoum Date: Mon, 13 Jan 2025 23:19:10 +0100 Subject: [PATCH 2/4] checkpatch: warn about use of legacy_static_base Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250113-b4-imx-gpio-base-warning-v1-2-0a28731a5cf6@pengutronix.de> References: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> In-Reply-To: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> To: Linus Walleij , Bartosz Golaszewski , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Fabio Estevam , Andy Shevchenko , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team Cc: Dario Binacchi , Haibo Chen , Catalin Popescu , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Ahmad Fatoum X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org gpio_chip::legacy_state_base was recently added as opt-out for existing drivers and shouldn't be used for new drivers. It's thus sensible to add a deprecation warning whenever it's used. This doesn't fit with the existing deprecated API check, because it requires a `(' to follow the symbol name, so a new member specific pattern is introduced instead. Signed-off-by: Ahmad Fatoum --- scripts/checkpatch.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7b28ad3317427a6bf9e27b77065aa3915cb13053..6c57a08833a4298573c7967b2a178fd7f46aa7ce 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -848,6 +848,13 @@ foreach my $entry (keys %deprecated_apis) { } $deprecated_apis_search = "(?:${deprecated_apis_search})"; +our %deprecated_members = ( + "legacy_static_base" => "setting .base to -1", +); + +our $deprecated_memb_search = "(?:" . join("|", keys %deprecated_members) . ")"; +%deprecated_apis = (%deprecated_apis, %deprecated_members); + our $mode_perms_world_writable = qr{ S_IWUGO | S_IWOTH | @@ -7407,8 +7414,8 @@ sub process { } # check for deprecated apis - if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) { - my $deprecated_api = $1; + if ($line =~ /\b(?$deprecated_apis_search)\b\s*\(|(?:->|\.)(?$deprecated_memb_search)\b/) { + my $deprecated_api = ${^CAPTURE}{old}; my $new_api = $deprecated_apis{$deprecated_api}; WARN("DEPRECATED_API", "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr); From patchwork Mon Jan 13 22:19:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmad Fatoum X-Patchwork-Id: 857051 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6181F9A91 for ; Mon, 13 Jan 2025 22:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806782; cv=none; b=loTPI5gbudLKzred+UMzd4s6b7RMY9S6PwmLK6A+vX5HtN1RU4SgWpPVX+XII7HXThK8qcx/dD4SsozDYvxRUJnFAghzJPM9nKWLr8TlAbCDfNEW/VjyIiXrm9uvmhiTPF43J0TEk9zqBOzAlFYeUq1u3fDWTrfsURRX1SMIwZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736806782; c=relaxed/simple; bh=LZUqTKQG/VudoIdjL3NreEIvE2/yKrFha28dh32t4+g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tf7dXeNZTHu3QF/zHbQb3eLhO6X3CBSHrtS4NtkRc6Ax4Atqt66x1R/gn0rqHkNBllPVn4agkmccpho2WDwNsy0Kq6WOLzukj8HTLrOJBHz0EknmpIdTgSZxwbOVUfuXBQbOLIPCgzvLYT6AhYm0i1y/zZybD6qR3zD7Mvq/Bz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tXSmF-0005ym-7s; Mon, 13 Jan 2025 23:19:19 +0100 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXSmD-000KYi-2G; Mon, 13 Jan 2025 23:19:18 +0100 Received: from localhost ([::1] helo=dude05.red.stw.pengutronix.de) by dude05.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tXSmE-008p8i-2f; Mon, 13 Jan 2025 23:19:18 +0100 From: Ahmad Fatoum Date: Mon, 13 Jan 2025 23:19:12 +0100 Subject: [PATCH 4/4] gpio: mxc: silence warning about GPIO base being statically allocated Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250113-b4-imx-gpio-base-warning-v1-4-0a28731a5cf6@pengutronix.de> References: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> In-Reply-To: <20250113-b4-imx-gpio-base-warning-v1-0-0a28731a5cf6@pengutronix.de> To: Linus Walleij , Bartosz Golaszewski , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Fabio Estevam , Andy Shevchenko , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team Cc: Dario Binacchi , Haibo Chen , Catalin Popescu , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Ahmad Fatoum X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org 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 --- 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)