From patchwork Sat Apr 9 09:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12807816 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 A7B00C433F5 for ; Sat, 9 Apr 2022 09:53:36 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=P/14EE1lNiktKzQLalXW5M7fsEgAsw9yXODmnICU7Jk=; b=Mw9A/wx2lnNrYw vKgfXKerdEaXwBy/rbCld0RvzISlpgjhTIof/WFzNTMPDdYatmNAtHeQHZMtSuudgTmlbVx+WLzKz C5ZxbymQiI5XBnutMlffuT83i4kK1RecqxflNvBMXh8KvRi2KCR95/yZyyUuRjrdfFbRIhlm98XML umOTCRC/YEpVzKtQfGPk2wv/QvIJbzjTKuacYHe/YjzvtmGDjaXzIL17LLAiUGLDrbSUFoobnH3tR 9VI5JSeRIC/aPrWJ42IAq4QKb2U94P8aiI2CR0tuj9r8WFZ6TxwxpyMOWXKZaMPYQRpASULi4KXK7 NQBMCISKehn9kCDgXOWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nd7lk-002jon-Bt; Sat, 09 Apr 2022 09:52:36 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nd7lS-002jln-4u; Sat, 09 Apr 2022 09:52:19 +0000 Received: from localhost.localdomain ([37.4.249.94]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MmCyE-1oLIHi1dGi-00iBEv; Sat, 09 Apr 2022 11:52:10 +0200 From: Stefan Wahren To: Linus Walleij , Bartosz Golaszewski , Florian Fainelli , Ray Jui , Scott Branden Cc: bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne , Phil Elwell , Krzysztof Kozlowski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Stefan Wahren Subject: [PATCH 1/2] gpiolib: of: Introduce hook for missing gpio-ranges Date: Sat, 9 Apr 2022 11:51:28 +0200 Message-Id: <20220409095129.45786-2-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220409095129.45786-1-stefan.wahren@i2se.com> References: <20220409095129.45786-1-stefan.wahren@i2se.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:CB02EKvvYydZC5du8AH3IAtLs1fKTmze7x6PqWzMFj9x2Xcd7BX DR+H15vbZSkfGzXjc8/tPJndsZk+GZlKFGP+LiQnHoQYy8Er0bANYgFfsUb7NYDU6kHSkcF HYR4Gv7TpReJCf2bH2UtDaWIpVcdhoLVsci82KxBAvMgBpCy/ZGjx/11Xzom4PcPS+ttYXc hObbjupwVjHxXTfxZjDJQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:1wUrPbMJhgY=:qii99htR46ZMXophlALDu0 2FIx4j10br7+X4bpuAeH1ggCmPk6s93xNaqPiUHKisP/bwR6g/yoUN4Rc5MGLvbIAHGhAaIpi HzeWdlYZVkc4Wwd93ImTmRp4QSYj2MFhlD9mBNe/1uzEotfpdrYufNDp8cqzNaHhAEUCgr/jI YLA6HoSCpIBuzcy3AjoR54TGpFmdioBlvheXXiVsIsDhpj2YpPRlu1hjfTXy3uuphJYnhm9bw RYXGCY+kbn7RdPOuQ7Ht0OgS4uQ1nFVh/BhJnCmtZRzel4oZGyUUeAQyD0HqE83pSV3q9xNDZ lc7Rkm+pL5awl7EYi6LJqoH4TRPYRrUcRUEBqVHKxcq95grJubj33UNN9uyQD20Uq+66HsI8w qEfWCFbwQ0yg9z4D75rbovFHh97VOuX+9aPYtMs3tFGT0/I8bI7UpKgM51g1huzgS2+4WqDF7 SaGv9ucDwj+Vjm1f4HJbdkjlo0bIbegP8BRnXSv1s9H+mx6smnyVoTHO8Y+iDBTLFc5Rdy3xx T4pihvDAkGil44Y9xokUbaV+aflxu9VTzaoML8U0l1lNKQ7R9xqgZQOAE7cxd5reX/wVk+8Go ERER8s6wNGETt3CSgf2XuAb4j39jLvVuq0APzskfGPF0UC8Ao6mCR+E9UhoZBHoCIdwiQMC1t yACjBXZsju4eBRGWtDAaGEySnfe2mX7pd8wMawNfvC5D+cW/3fkvX20AqjtLbQxL/oq7XN5QR 5Iw4auJINtaJRNXL X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220409_025218_522048_F81324D7 X-CRM114-Status: GOOD ( 14.78 ) 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: , 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. Fixes: 2ab73c6d8323 ("gpio: Support GPIO controllers without pin-ranges") Signed-off-by: Stefan Wahren Reviewed-by: Florian Fainelli Tested-by: Florian Fainelli 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 ae1ce319cd78..d9b235c88b54 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -931,6 +931,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 98c93510640e..b5d53decea5a 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -492,6 +492,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 Sat Apr 9 09:51:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 12807814 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 77905C433F5 for ; Sat, 9 Apr 2022 09:53:30 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=mXOfn+wp7zjND8P7ax3+8JLrtMUXRILAQI3G0zrBmoA=; b=oSEP5YELOBsjr+ vG06i64fW8uwtpa353UW0heyPrO4boTX8lDnF9oA1XSxyYHI09IwnbXuA9tNgJvuv6PjDhYuVuPEX FDdr8O2eh0Sfw5Dsjh9Gkd8BdwQ7M+2YCJL0u+SNh9s1Hv6Pgb+T5FVLQ8o+Nkq7HrzvEhGbV+1/n LKaRzVrzVfjTdzMPo2ctWbvyaEK1LiCxBGXJMsnvTWHYpel+DesXEE7n7zw7w16bOUv+jzg5LUZyp FqxHv8ycpQ1MNKaVNac1vrTkhEGiKzJvCWr/AS5EDXQT4F93PomIAQiJoqoaqv7robpqm4Gg+akZb NhhvhejsMWqdYNjj6hPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nd7lc-002jnl-1C; Sat, 09 Apr 2022 09:52:28 +0000 Received: from mout.kundenserver.de ([217.72.192.74]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nd7lQ-002jlj-CX; Sat, 09 Apr 2022 09:52:17 +0000 Received: from localhost.localdomain ([37.4.249.94]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MBV6n-1npXAT3Sr1-00Cxks; Sat, 09 Apr 2022 11:52:10 +0200 From: Stefan Wahren To: Linus Walleij , Bartosz Golaszewski , Florian Fainelli , Ray Jui , Scott Branden Cc: bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne , Phil Elwell , Krzysztof Kozlowski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Stefan Wahren Subject: [PATCH 2/2] pinctrl: bcm2835: implement hook for missing gpio-ranges Date: Sat, 9 Apr 2022 11:51:29 +0200 Message-Id: <20220409095129.45786-3-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220409095129.45786-1-stefan.wahren@i2se.com> References: <20220409095129.45786-1-stefan.wahren@i2se.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:cH2GKa+Sesy4auWa0VxnAWA+V7gGDs0vWaXC0MA5wpS30ZmOxNy 72XkB2bF7mkrbuvbdVznQ2DjMkkDbtkd5KoUAyfITurWA5IOVgYc01mzxVwM79/AsToEgch FJjFy8NZrEgxf7wgwdqjQfPBtAZYk59Gremkt00fncwW0AxEygWkhZOas7PfxUnqK0NQNAN LYvpzILW+iywikCkVLFPg== X-UI-Out-Filterresults: notjunk:1;V03:K0:JqHmuGSbNs8=:FzsvNdzM/oO96oe/XgwyYm 9JfYEADvpCauvjeo+NvCGThP3aeMYK/nagZMAQTUdjMooygGYCZXZgFCdm8oQRMSdfPAiLYCb c0AfFQGgy1af6o4a3AfVzmMEdqdrGeOBp7EKu+zaIGSRPr+VJz8Z/i4H2OCG2FWbVq3EmQwig noSiKcLLq797cEgKn1MoC2tM+Jd/rEK1UwRsHuGwn42+zYznyA0bbEKWDgsmEgsddyhHHKwWL tEmrJmPyQFeAtiDgbCppliWG2oLcukTCvpsMSXVu37hq0uvpnkosgFP4kEy8X6m/Ksc5o/W7F ieOY3PfX2ZxhsyzG7E3IrioIfxMJYIbOF+pSo8EKTUox9FgsZX3m0gthTsq668J0/brX9AOiF RhCHg1eQIJCDmaKmy7PleeUIAMQqXgRZRfYfBzcT43vKhxwoOft5BoPh+b2YFZAE/di7QEpIs RQDntgYg+5CAqiFmIQqVXdkFznb9lVeYG3nWy3hcqClik1k5XxOzZIUJgD0wLcdqqeimulnVZ 0j7NTXtfis2UcO79GVps/NvIubauDO/5iR29JEgaYPKVPE2RcVQlP28sIMX+cFDGNp2x6IDLx iz2j9Pyr3kHFV+Lv7eP01ElyZGvBMSL2lpd31IflM0IHUIvwBXrfRanYHF77aj6zgoEI/QML/ i1nt5ZH1gijrPqRvS5avAq2MN2LzCYIj5P12bIZfqtzjvHt2BWGojBdW2kJpY1RtR8L0Y2S/6 3/cEK/JaoLpQTdLa X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220409_025216_753850_7D9734FF X-CRM114-Status: GOOD ( 12.87 ) 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: , 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 kernel DTS files. Unfortunately it isn't guaranteed that these files are shipped to all users. So implement the necessary backward compatibility for BCM2835 and BCM2711 platform. Fixes: 266423e60ea1 ("pinctrl: bcm2835: Change init order for gpio hogs") Signed-off-by: Stefan Wahren Reviewed-by: Florian Fainelli Tested-by: Florian Fainelli --- 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 47e433e09c5c..dad453054776 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,