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: 12775538 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5176C433F5 for ; Wed, 9 Mar 2022 19:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jiYPJBgqysSpzOLWKoxZxe2QnR2BOZucAJgTHeM5dfM=; b=yFC0R/5N6KDA+5 7rp6viOeh+KuAt3yy8xfWgGQYY4/qPNRcST/fwlgK0s7+rfiXAQxR/18pX5mHEd+GVASoKKEr7VSO fvOM5eOy82zP6teOKbaibEPt+cTz83TWPY/bbtjyBFGdDmiAHY7LHRBiqPNkhwb9wJivqHhWiI+fp DdFvxUI/tZxZEriW/PQR3iHBraSNuiFvjD2K2DkVHwlWHU9cBYbBvEDMAkRvsvgQZj9IKzxAfG1Vz Fzyq/vckjLEe/I00n117T7RHMy6klh23PeR69C42LP1M2ROzydSR9ILtBEB/9XHbpno4yc/UlXCYC y+ntbAlC7/DCOK4u8lQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2Ex-00AJrI-Cz; Wed, 09 Mar 2022 19:44:55 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2Et-00AJqP-Rd for linux-arm-kernel@lists.infradead.org; Wed, 09 Mar 2022 19:44:53 +0000 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:dLFpT1KDbXc=:11apCdB77n98Meem6SSNFG RtbUoMfsI7xhd4X6MSgWv0yIbeneS7a47Q+cA3rDL9DwptVyoRSdQqDeIwmFTnTzNC/gL2JXt p0IT4G8HyOzvZ0kcjozOLlFb1TFupCmRuSeUdu40A3x8wr3ohs+J1zorF4T0H7LDVUhE7LCpl pEkdQbUfLDmj6QzjDnWyRoS9mGJ3y+MD/XblqS1C5Mo3JyPC+l6CDtbeqS1yJ4wLSW0GWXfBI xRDd0mxsqMwkVuGVMCJ11UPfY2sjlf/+3FXdctlUttsPz13dRGiGUsOmXWQRvgP5ulpHEINCr AIK0oWQYR+1BhL98ph/2GmdyX05PO9QhzA/ob4jdWWQYiiWENL28OUfwH7t8BDBy+XmR4nP+K cw5qqKJ9vb9/ZVYm6iDT0Fb2Vqi7RhPMH7tRLoZfdyHPaqN9ei3t3+le0TyDybDW4rEtBjNxc ITiPWtcl8JSLScGfDbGV3Ka0KIR1dd3ho+gOWhXLSVy/amXGZQqQUh6WhVtDZnfNTNGVs7+gC ktY7jsCXlOLd8nPN7WFzdJ/iePGbsJI/plLDi9JiaPXNAh1pUapiAI3P9ZuCIfW/LauIWYQWh InejZNgSvv4a89fh+QIua1lADq+1MRsBwnoEoS7b6lNb1zNx9PxzIuee7GUKImmJxetQDjnn7 /C1cZrGf+9VnBYl0gFIn/HXNqB8eOZ/1DeMAiHL29ls+pvo+gmmT3SuRTC62EpwojNRs0r+9M x1L3qex0kMP2ZVs8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220309_114452_230459_E0242424 X-CRM114-Status: GOOD ( 15.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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: 12775539 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A785C433F5 for ; Wed, 9 Mar 2022 19:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xObeWwxHd1/6UGbohz5KCLnayZE+xa8qa9K9ksyz3Ao=; b=0ojcc/n+BPQr9t HLY8cJ3bl8MVQiuNxRClw+UYXhfQG837TKNSHOy9cptfaFuHo5Vju1CrCig7zgZMYThj5BtZyScr7 AQ4Fw50sNSz2TSSICh15FfQcJlB9XmN9+eCMUCxM9o+U04s9VtQMlN0OZf6AU5lNLdBgKALocE9hM 0dJPuwVZ4W9UD2p4yqkK+DAOgfWDYFAU+DCABKV2EAVQhvykvlLoCpf3swePhThWyLT1xux/4Refd 1fxl5h/bQ2+TA8YNWLhCkoDt4vz+Tp4ffEAVi9CN2tpvmJC4t/10ugR1V0H0ekIeGF5RnhQhTjY/M T3kBLhGz0158T1KPnCiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2F6-00AJsF-B7; Wed, 09 Mar 2022 19:45:04 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nS2Et-00AJqR-SL for linux-arm-kernel@lists.infradead.org; Wed, 09 Mar 2022 19:44:54 +0000 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:NNlrxlue2gA=:2weFW0A8nKGHda7lRP6V4R hY62kNe7KWK1c5WDPTNhpSAA2gEN4iLaI5op+GhLFmLyeSssaZpwkduQpBd74Z45aNIQPED63 8C8rZFz2Vr2i/FOajAmk4cikBeK3G1SJ/TLPDTbFUCUJxPZlH5zq0+MqChsUAKLQnNJjmEkFv CGZtWdOB9QBsWWBy5EAN0QNvW8cVB1o09j60bhq+2GltCffD+AOFGuYflP9FfKzY8FPSewFfg mhBNop6YxUH1wIL0rmeU59yofofq+hfvK61cf8eHNCL50AndgV6hB94evWN43b1DOuWLi4NW+ aCfQpyeDT7UwhXYYRE3zph7CUMyLiYTGzEmUpTfobyToViBn0I+N2ciLYyRs8pC/FxT9YUtQo SaJ9x+vPhnmJnc2W2Plr6iIItrG94wD9xkpAb7XiQAP7nNE/fIUPHyBms4wyruXX05dJacOjh CvUv/jcxd3/RpVMjzKpjhN7pZi7Ah8LblZfi9o6Q5o7zEHfqnpy5Vf/tbusjOUMTwNp0FfDnK msGDQQTUdFHqwoZ5XllZATHxSq7FFTyjh6FkRmBAacyyAhVcKjAOguD6/pT3r9dJ5UJ+G0C4R 3nFB1D66ShBFjs2mgJKCRGKf/G0q5A5QJD59WBiV1oWuavKw3UgBDA85ChDnD9m91mQOMu5C8 gIaH00Q3jUuitxqJ+Ggcfg9Ga8NRt4anQD/fAeX9sNLlMTobvR/yTj+vMdsuB0yWOVgBkIGWH tvyfPzl25ugGUCB6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220309_114452_230475_FB9FF0AB X-CRM114-Status: GOOD ( 14.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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,