From patchwork Wed Oct 11 20:26:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 151544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp795099vqb; Wed, 11 Oct 2023 13:27:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdT6TQ+TgSWzaW1YFeZFzWvqTZyO6lFl8A10V2f1ipx/PoOmjnufrMssLsyGk2AAcUxp0Z X-Received: by 2002:a92:db4f:0:b0:350:f353:4017 with SMTP id w15-20020a92db4f000000b00350f3534017mr20624604ilq.0.1697056021209; Wed, 11 Oct 2023 13:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697056021; cv=none; d=google.com; s=arc-20160816; b=aiV6IcaFCUCtsP1eVTlMExWBradJnt+2lXHLebxt+dHiYAeklI6Ck+vBCbH0dZ498F Fucxpt3LGawn3BD0oWQXOVXdn12UD5BVxMn7OJtEzzHGRcGXcSjSfgibYzNZrztIjC1d 95m5/0AFo+0rshn5WY2GPlg0m1vzxiDE46I3ctMcTwoFuYh0mMDcqTyGf0q/wI1GHIEN N5PG0lcKMaNisdRG0236nmn7lF+6Ne6RNhCNPYul7U3TR2nTMvQdi6F3HpFHKM9t7s6p p8xqCmNQezc/bdC7W0N++2+FECyM8t+D43NcFe4ujp/Hql99coUkAWCY4wDsVKpXW18s 5pAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cvw4NaV3i3IRRXXk2LeoD0QbBDG/0Zxh7dNXZwTsBC8=; fh=RAF7KyPAfJnoj7VNMZqcV/N9L3IgTT6Eds+WXuPmNQA=; b=WHAGOXNYKP5APzcctOJGSyXdYIMbTgAhkqYLTWi/CgNRsnmxB1k4VDW3w08tW/7tDS 0rdlny+W8h1GBi6LsbYuRLKJI5N0smgAT1onxr5zjbIoz5NJJ+VkJLfEKRbat0mvgsyX YfcxrlViJJBUsm6avisMJMOvy+EsmC86LYw7CoOAZGELSC8PIImHDq9/poZiyQ2l8Ab3 F84SvDzJIwm1SMctk1fViw4ZFWMdkZ5/qCwhPeh8wB1bNBoXEGfNMsC95HcU6Q30zlY8 JBDfwvIsAHlzI7BmeESrxongdw9oeAKKx54CJZtd9kUIYSGOm1AUFfek0/ZXEyvzIOin LfxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe1ut4p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x32-20020a634a20000000b00578a26aee75si553026pga.295.2023.10.11.13.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:27:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe1ut4p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 940F08025B63; Wed, 11 Oct 2023 13:27:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376434AbjJKU04 (ORCPT + 18 others); Wed, 11 Oct 2023 16:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376386AbjJKU0u (ORCPT ); Wed, 11 Oct 2023 16:26:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F18293; Wed, 11 Oct 2023 13:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697056009; x=1728592009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bRyQlSHpeOLdYLvwN2SQBQmioztVBGvZYUmThNk322Y=; b=Qe1ut4p615zXxS5m9Y2RkWTU9HIeiLG6pQBt4cKi8/hAunDHyCr6XkF+ aWHlflxAOG48R4FhFVjPnRqIC+nxVvwfMudJm4BFo02wZXomg8btxNQxB vdKofhx1tK1pDkoabkA/XkuRi0x4tntCl6EvZacijLVGasnJvW/1T8pcp i4pW85tauzMHCvVyOaXAcl14ZfA3FzYJnGU8n/dBHNGoU6FjhEugcEf3H TMnZcPq5mV4fZvhr+WClvE2XaJx33aKcZZwbX0cowAbpOMGkMFsPCSsj4 +V4Z7kH/2TVpdlCCpa5YXBWNmtKVrqP4tjdtCVt97ykKluhTAhxLxWU24 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="471015140" X-IronPort-AV: E=Sophos;i="6.03,217,1694761200"; d="scan'208";a="471015140" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 13:26:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="783393504" X-IronPort-AV: E=Sophos;i="6.03,217,1694761200"; d="scan'208";a="783393504" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2023 13:26:43 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0BA25345; Wed, 11 Oct 2023 23:26:41 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , Andy Shevchenko , Linus Walleij , Dipen Patel , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org Cc: Bartosz Golaszewski , Andy Shevchenko , Thierry Reding , Jonathan Hunter Subject: [PATCH v2 1/4] gpiolib: provide gpio_device_find_by_fwnode() Date: Wed, 11 Oct 2023 23:26:35 +0300 Message-Id: <20231011202638.372382-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231011202638.372382-1-andriy.shevchenko@linux.intel.com> References: <20231011202638.372382-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 13:27:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779492214446488545 X-GMAIL-MSGID: 1779492214446488545 One of the ways of looking up GPIO devices is using their fwnode. Provide a helper for that to avoid every user implementing their own matching function. Reviewed-by: Dipen Patel Tested-by: Dipen Patel Reviewed-by: Linus Walleij Link: https://lore.kernel.org/r/20231010151709.4104747-2-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 20 ++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7b4d12b714a3..31c06a32cb8a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1142,6 +1142,26 @@ struct gpio_device *gpio_device_find_by_label(const char *label) } EXPORT_SYMBOL_GPL(gpio_device_find_by_label); +static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, void *fwnode) +{ + return device_match_fwnode(&gc->gpiodev->dev, fwnode); +} + +/** + * gpio_device_find_by_fwnode() - wrapper around gpio_device_find() finding + * the GPIO device by its fwnode + * @fwnode: Firmware node to lookup + * + * Returns: + * Reference to the GPIO device or NULL. Reference must be released with + * gpio_device_put(). + */ +struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode) +{ + return gpio_device_find((void *)fwnode, gpio_chip_match_by_fwnode); +} +EXPORT_SYMBOL_GPL(gpio_device_find_by_fwnode); + /** * gpio_device_get() - Increase the reference count of this GPIO device * @gdev: GPIO device to increase the refcount for diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index f8ad7f40100c..ae4162d3f1d3 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -611,6 +611,7 @@ struct gpio_chip *gpiochip_find(void *data, struct gpio_device *gpio_device_find(void *data, int (*match)(struct gpio_chip *gc, void *data)); struct gpio_device *gpio_device_find_by_label(const char *label); +struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode); struct gpio_device *gpio_device_get(struct gpio_device *gdev); void gpio_device_put(struct gpio_device *gdev);