From mboxrd@z Thu Jan 1 00:00:00 1970 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 C20ADC54EBD for ; Fri, 13 Jan 2023 17:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbjAMRNy (ORCPT ); Fri, 13 Jan 2023 12:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbjAMRNe (ORCPT ); Fri, 13 Jan 2023 12:13:34 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 501048B51C; Fri, 13 Jan 2023 09:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673629923; x=1705165923; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4czDnVSkFSUSOJn9OForI+BzEj1U5wZMtWZ0AIG6g9Q=; b=HYVoq4AqX0YHOGHgr5y+jAi7BMgkNFiGwLzJxGY2r312mBVyUH6qAXDR LgGW8zo3kl3tnUQEIEbQ92tJ66AbAZM6N/UO8nIcKPe/VAUD8URZGAMUI vDqifRE5m/yXNPeGGJfR8lPMxxa63Ds5hzE/Pb4SPYp2uVel4hUCEhVE2 DldV3YA0Wx3yel9OE4obfzMoFd+u8X3W4O3T4YvEunZSZ22hsYxC1dxeJ X65GQFz11Vfk1nxIIMBjEBMKg/BJq49TYRp3fanHz/YbK+p9r94E6mRQX QUVKWvkpKN8dJEJEDbV4sYpBoz3AwOrdZOszxTOxe32ow+ywzD5bPCSTB g==; X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="322742816" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="322742816" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2023 09:10:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="608221583" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="608221583" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 13 Jan 2023 09:10:18 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7C93AE1; Fri, 13 Jan 2023 19:10:52 +0200 (EET) From: Andy Shevchenko To: Bartosz Golaszewski , Dmitry Torokhov , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Bartosz Golaszewski , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden , Stefan Wahren , Andy Shevchenko Subject: [PATCH v2 1/2] pinctrl: bcm: bcm2835: Switch to use ->add_pin_ranges() Date: Fri, 13 Jan 2023 19:10:50 +0200 Message-Id: <20230113171051.19309-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Yeah, while the ->add_pin_ranges() shouldn't be used by DT drivers, this one requires it to support quite old firmware descriptions that do not have gpio-ranges property. The change allows to clean up GPIO library from OF specifics. There is no functional change intended. Signed-off-by: Andy Shevchenko --- v2: fixed compilation issues (LKP), Cc'ed to the author of original code Btw, the commit d2b67744fd99 ("pinctrl: bcm2835: implement hook for missing gpio-ranges") seems problematic in the fist place due to odd of_node_put() call. I dunno how that part had been tested, or how it's supposed to work, i.e. where is the counterpart of_node_get(). Anyway this change drops it for good. Perhaps we can check gpio-ranges property presence inside the GPIO library, so this ->add_pin_ranges() won't be called at all. Also I would like to understand the dance around checking for pin control device. The original commit lacks of comments in the non-trivial code. drivers/pinctrl/bcm/pinctrl-bcm2835.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c index 7857e612a100..29f278c49103 100644 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c @@ -358,16 +358,17 @@ 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) +static int bcm2835_add_pin_ranges_fallback(struct gpio_chip *gc) { + struct device_node *np = dev_of_node(gc->parent); struct pinctrl_dev *pctldev = of_pinctrl_get(np); - of_node_put(np); - if (!pctldev) return 0; + if (of_property_read_bool(np, "gpio-ranges")) + return 0; + gpiochip_add_pin_range(gc, pinctrl_dev_get_devname(pctldev), 0, 0, gc->ngpio); @@ -388,7 +389,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, + .add_pin_ranges = bcm2835_add_pin_ranges_fallback, }; static const struct gpio_chip bcm2711_gpio_chip = { @@ -405,7 +406,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, + .add_pin_ranges = bcm2835_add_pin_ranges_fallback, }; static void bcm2835_gpio_irq_handle_bank(struct bcm2835_pinctrl *pc, -- 2.39.0