Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1067589rdg; Wed, 11 Oct 2023 13:27:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBOocpkt0/wCoFTW0hcp2RdsyuBGH0rgAcBV82FlT3oJINKlIpQfxUx/MDHQ8wPcuCws+5 X-Received: by 2002:a05:6358:a1a:b0:164:a5c0:46a5 with SMTP id 26-20020a0563580a1a00b00164a5c046a5mr6968325rwa.12.1697056037727; Wed, 11 Oct 2023 13:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697056037; cv=none; d=google.com; s=arc-20160816; b=hKfsWJzCTQBloBt9cu+GZ2p4av3eNTR1FDgSlj1nmdHeCEp2CL2j1CW1WHDO4pFS0f /ZNRI3yJclbzYn1bZpVKsrEu2kjiru9ahcXQx3nUqHsaxxHF8EXNNSjHS/4Jt/gt8Ro8 SLuwmNxZnxzjos2AmSKRJEAUSEb3mqjd/ojBtEE4X1vAc2guprRewoWNUYkkLRvmjX7l 3cbbh9AZLMqGILj8KB0/RuJaydz81xV2AMpks7oE/k8GGTdRYBW9JQDDoU7wCa1EBEL0 nd8o6b7QVRzbzAnyttNl91amNwG5u/LjECpNJlXts4vwKvY8wUEn+XN+wxwdf76ONTNC ZfKg== 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id n3-20020a6546c3000000b00563f72935e3si519166pgr.608.2023.10.11.13.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:27:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; 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:8 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 fry.vger.email (Postfix) with ESMTP id AF52380B81CA; Wed, 11 Oct 2023 13:27:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376409AbjJKU0z (ORCPT + 99 others); Wed, 11 Oct 2023 16:26:55 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 13:27:13 -0700 (PDT) X-Spam-Level: ** 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); -- 2.40.0.1.gaa8946217a0b