From patchwork Fri Mar 25 20:03:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12792040 X-Patchwork-Delegate: geert@linux-m68k.org 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 8B154C433F5 for ; Fri, 25 Mar 2022 20:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbiCYUIc (ORCPT ); Fri, 25 Mar 2022 16:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbiCYUH5 (ORCPT ); Fri, 25 Mar 2022 16:07:57 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 770F62BB28; Fri, 25 Mar 2022 13:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648238655; x=1679774655; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=I9qL3XzxipS1lgo6CpdL7eX6zDMQG8eU8y3dPwQxX+Y=; b=O+/skQHCsifZ14BSN7Uy15tbo5g4s/Jyvg4DN2Z3oEBfFPA63/Sa0G6e 5j7oEQHcpr+3/1+Et3CTNe9E/QrIPTmutCaTZJwJ+acrzc6RNZcceZ9Fa v304SzwzTIc+T/bzw5HpqgGpSOsbteO8Ou0zcN6n4dAuX7b419nPH54GX jgWNC7pfPca6++ufBqCBz9co6nlLE/ysluceDU2w6vriXUlBxlTJCmpgp G0ttNksdCJ3Gdt5ei/lGehDJ9+czS2qRTXqfmoM7v/XmBEGAcd5ZCfuWR WjndAspSjBYZRaKm2Beucg6It3nEAza4BTFQBQ5Bj29aGiHYS285GB+fJ A==; X-IronPort-AV: E=McAfee;i="6200,9189,10297"; a="258900034" X-IronPort-AV: E=Sophos;i="5.90,211,1643702400"; d="scan'208";a="258900034" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2022 13:04:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,211,1643702400"; d="scan'208";a="501886245" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 25 Mar 2022 13:04:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 75E9F11E; Fri, 25 Mar 2022 22:04:30 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Gregory CLEMENT , Geert Uytterhoeven , Fabien Dessenne , Linus Walleij , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Cc: Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Andrew Lunn , Sebastian Hesselbarth , Maxime Coquelin , Alexandre Torgue , Bartosz Golaszewski Subject: [PATCH v1 1/5] gpiolib: Introduce gpiochip_count() helper Date: Fri, 25 Mar 2022 22:03:34 +0200 Message-Id: <20220325200338.54270-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The gpiochip_count() helper iterates over the device child nodes that have the "gpio-controller" property set. It returns the number of such nodes under given device. Signed-off-by: Andy Shevchenko --- include/linux/gpio/driver.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 894eab753fdf..52918ef5d288 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -9,6 +9,7 @@ #include #include #include +#include #include struct gpio_desc; @@ -750,4 +751,17 @@ static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc, } #endif /* CONFIG_GPIOLIB */ +static inline unsigned int gpiochip_count(struct device *dev) +{ + struct fwnode_handle *child; + unsigned int count = 0; + + device_for_each_child_node(dev, child) { + if (device_property_read_bool(child, "gpio-controller")) + count++; + } + + return count; +} + #endif /* __LINUX_GPIO_DRIVER_H */