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 */ };