From patchwork Wed Mar 9 19:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 550864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F937C433FE for ; Wed, 9 Mar 2022 19:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237316AbiCITvL (ORCPT ); Wed, 9 Mar 2022 14:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbiCITvK (ORCPT ); Wed, 9 Mar 2022 14:51:10 -0500 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E7DAC for ; Wed, 9 Mar 2022 11:50:09 -0800 (PST) Received: from localhost.localdomain ([37.4.249.169]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MOzKk-1nn26C0XaW-00POnC; Wed, 09 Mar 2022 20:44:44 +0100 From: Stefan Wahren To: Linus Walleij , Bartosz Golaszewski , Florian Fainelli , Nicolas Saenz Julienne Cc: Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Arnd Bergmann , Phil Elwell , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Stefan Wahren Subject: [PATCH RFC 1/2] gpiolib: of: Introduce hook for missing gpio-ranges Date: Wed, 9 Mar 2022 20:43:45 +0100 Message-Id: <1646855026-9132-2-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646855026-9132-1-git-send-email-stefan.wahren@i2se.com> References: <1646855026-9132-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:IaICHcL/ihEZJrbQlwQnRUvARq7G5Mehnj7902lReucO64HiH0M vVzSUZlMLJUe0Ty3gDeaUiY0LfysrNlYFsJJJs3Rge4qfqHsi0zW7YUSf3Jm3qxlyW9zVo9 HHUn+gMkQZrRqZVrKVgrWdgOdGV5AvgGkDA6HejFQr/zP6v26skZMXQubk+BGLLcqSlCUix esJCPwQ3RdfqGLFP3IyCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:vTdakuSLCUI=:7GisNQDFNFEX5/Bsyfs8jk /etR+ZpbRmsdkulThWrOCaou8yv0VplmPJloFkT3ZL/EKWQya8GAWt1+tjdHHCpl/fcR9s8CM uyLY4JJpD0Z4rVlfzR3hUl/yDUZFQsiicEdFnUUnepns+jTpjBmmHOOiytqGpR8Y/rfTH5LHd Bh5yxS5sXwEpr/MV1Seizir1BWD7bwK3BTlRw7Ill0kzbqFGPHk3tCp6IVlKQ69s+Q+OskUdm ZJLpshQdj8vEs59ZzGawfEEGczUftAG7KXymviz6mo4pWzKiOBDn0HOgAd443jWL8leF+taUl O8HAnD/XvbfxXfpmAJbs7oQFASLaOnhUiWEkqvcJSV/AVoEaXPOTiL2bYex+m2QUYLTreAk1v vUrX2CylANX09JuvFWOcDXqQj64LIhvn7FqXc/J2GgAvagtSEdo0xMEnH5TtwNQMI8fH5tsPI cTeRGKHrFiKzx5LIRFm8PuhNdTeNDncmY8KEdHqUArPfB5AK5xf0NQEVjMPaTyDa9IszAg2XB +ogyQoyJluit2v2tu+yhLZpW0IzGhkRr0ZTbROfr/8kgF4tuOKpehvDRjOhgGtu0r8K2nVM6G uZVimyJE1QsujuoxOO0CRxw+AollYRA1ApzStBv5m946M4IdgtzxKKM7kQyuQzT9SxOj9eQLa 86fGV/j5AWPaAi9AcnM8tCTwO3GCMnh3sjyMnQU1cf4RK1OItuZmxT0UIU2kpeDrWTaxa1y4V c5IMt6MEd45b4Idu Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Since commit 2ab73c6d8323 ("gpio: Support GPIO controllers without pin-ranges") the device tree nodes of GPIO controller need the gpio-ranges property to handle gpio-hogs. Unfortunately it's impossible to guarantee that every new kernel is shipped with an updated device tree binary. In order to provide backward compatibility with those older DTB, we need a callback within of_gpiochip_add_pin_range() so the relevant platform driver can handle this case. Signed-off-by: Stefan Wahren Acked-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-of.c | 5 +++++ include/linux/gpio/driver.h | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 91dcf2c..45b6edb 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -933,6 +933,11 @@ static int of_gpiochip_add_pin_range(struct gpio_chip *chip) if (!np) return 0; + if (!of_property_read_bool(np, "gpio-ranges") && + chip->of_gpio_ranges_fallback) { + return chip->of_gpio_ranges_fallback(chip, np); + } + group_names = of_find_property(np, group_names_propname, NULL); for (;; index++) { diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b0728c8..47a5ea0 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -489,6 +489,18 @@ struct gpio_chip { */ int (*of_xlate)(struct gpio_chip *gc, const struct of_phandle_args *gpiospec, u32 *flags); + + /** + * @of_gpio_ranges_fallback + * + * Optional hook for the case that no gpio-ranges property is defined + * within the device tree node "np" (usually DT before introduction + * of gpio-ranges). So this callback is helpful to provide the + * necessary backward compatibility for the pin ranges. + */ + int (*of_gpio_ranges_fallback)(struct gpio_chip *gc, + struct device_node *np); + #endif /* CONFIG_OF_GPIO */ }; From patchwork Wed Mar 9 19:43:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 549877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9EC1C433F5 for ; Wed, 9 Mar 2022 19:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236219AbiCITvL (ORCPT ); Wed, 9 Mar 2022 14:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234660AbiCITvK (ORCPT ); Wed, 9 Mar 2022 14:51:10 -0500 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C59B55BF for ; Wed, 9 Mar 2022 11:50:10 -0800 (PST) Received: from localhost.localdomain ([37.4.249.169]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MuDPf-1oHfsn2FEz-00uaod; Wed, 09 Mar 2022 20:44:44 +0100 From: Stefan Wahren To: Linus Walleij , Bartosz Golaszewski , Florian Fainelli , Nicolas Saenz Julienne Cc: Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Arnd Bergmann , Phil Elwell , linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Stefan Wahren Subject: [PATCH RFC 2/2] pinctrl: bcm2835: implement hook for missing gpio-ranges Date: Wed, 9 Mar 2022 20:43:46 +0100 Message-Id: <1646855026-9132-3-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1646855026-9132-1-git-send-email-stefan.wahren@i2se.com> References: <1646855026-9132-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:gD25VDJriO0WlPO9G1KIEXwcB2q62js2g/T5+gpDWM+vpuAtgJX 8gc4fsnQow22MKJ411B8VqfZ8qfx/epjNPdU2EhjeNnKoBL04UFvhM1+XEVN1qTkXrHHIlX SXGxqfKTny0zh4vETTwQJEYJwKsJ2bQne4Rkc8yZyXFPIHSDIW5hO7/Lpkzk0DGMyYdp/Dx gc+LdAHL0qBbFqJqoolKQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:VnTOY1DYj4E=:7hOSv9L7KCyduhHbDjKQXD p//UKeWlplBXepTZLFggFEKZJPA/srfZa7MYcRG5BxGyiC3mm4CCCrgff4kYIhFDVmUw3vN8/ uqcGHnxdfVhLHqoQ5IldwGIQDvxl1ty9A+B13nesoRofyJRm/l4yy1ADizUGNTyE5VfQ7tVpY 46qFxs+dStrFZ52Mzm1mcyvKU1p6jyQ+fmlhLkEREiCPSA/3mT42pJAs3LWGCukfsdhNE2SVJ DdtTQ/LhNdLyenSQIumpv/1xvNbjL1+tBv2mkAm6wl6OruWmD0mKaQPiEWw4y5OBjxLREMxhA QLSfrGow7qBqdz+zcpy7N2NvZmzYlYjTIsYZaT+8PBLQUrvwvEYSUuR9yCh8wmdf/ayj3JcZa RY8VSToOqwfJumuKCgMxfGCVudp9/BNNah9smgJee9lU9STiHbwKpxLsDr0b6MuALDt7Otj1c CCqbdwv4NsCq4fqs8OIghsnBmlVHISmtvyaIY5G7z179124JSfYUDkOHbDx5h4v2VSEiCdJA1 7QEbbk7KRQgototq9ueqGEu5EIhOtif0mvbhUzGfZgBmTPEe9iFkck6x0JBtkUHrbowS4pMj1 J0SOK1QEULfvnsS67i06NS7WCzQ0KBQUYi3Pz4R/qBNeEx47gSrNlCsyyVNAAPPxjYz9RabxR lG0HukaZ7Sdlese4kctKbiCPNfWG02Z217VDF+6Rxvg3xkC64b4GAu9PoiD6/JYmeLmtxV/kk 0j9Ne4oLO68KNXWG Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The commit c8013355ead6 ("ARM: dts: gpio-ranges property is now required") fixed the GPIO probing issues caused by "pinctrl: bcm2835: Change init order for gpio hogs". This changed only the DTS files provided by the kernel tree. Unfortunately it isn't guaranteed that these files are shipped to all users. So implement the necessary backward compatibility for BCM2835 and BCM2711 platform. Signed-off-by: Stefan Wahren --- drivers/pinctrl/bcm/pinctrl-bcm2835.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c index 47e433e..dad4530 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c @@ -358,6 +358,22 @@ static int bcm2835_gpio_direction_output(struct gpio_chip *chip, return 0; } +static int bcm2835_of_gpio_ranges_fallback(struct gpio_chip *gc, + struct device_node *np) +{ + struct pinctrl_dev *pctldev = of_pinctrl_get(np); + + of_node_put(np); + + if (!pctldev) + return 0; + + gpiochip_add_pin_range(gc, pinctrl_dev_get_devname(pctldev), 0, 0, + gc->ngpio); + + return 0; +} + static const struct gpio_chip bcm2835_gpio_chip = { .label = MODULE_NAME, .owner = THIS_MODULE, @@ -372,6 +388,7 @@ static const struct gpio_chip bcm2835_gpio_chip = { .base = -1, .ngpio = BCM2835_NUM_GPIOS, .can_sleep = false, + .of_gpio_ranges_fallback = bcm2835_of_gpio_ranges_fallback, }; static const struct gpio_chip bcm2711_gpio_chip = { @@ -388,6 +405,7 @@ static const struct gpio_chip bcm2711_gpio_chip = { .base = -1, .ngpio = BCM2711_NUM_GPIOS, .can_sleep = false, + .of_gpio_ranges_fallback = bcm2835_of_gpio_ranges_fallback, }; static void bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc,