From patchwork Tue Oct 10 15:17:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 150843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp279695vqb; Tue, 10 Oct 2023 08:19:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOuHApsmdiyl/ulKbt+5JegDV4vPfLpUo5K3t2WxA+Ta2G7r4NdAcbU9EXhEVouUtlOUcW X-Received: by 2002:a05:6a21:998a:b0:13f:13cb:bc50 with SMTP id ve10-20020a056a21998a00b0013f13cbbc50mr23409722pzb.25.1696951161900; Tue, 10 Oct 2023 08:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696951161; cv=none; d=google.com; s=arc-20160816; b=V/bQwD7GDDqEYCvFGRNJvpNdvM0SP5G6RJKPWyuLwZ6xsJq2wm1syNQhW+VpkgAWFy xx9SDwyeju9HPWES8P17Fbp4WcKZ1gqEvy2TamIVitYlSlht2O2A0b/2sZ/nJcuvOqes GtgaDc37HfJLkp0PEWLXWUqPRWQ98jfrU/giGvZPsjArRDxtJCdi+R6/abnZA7maVMt9 ei2LnfRPP4oizSl9mExs85opsfVx6w/6X911J14NaFRmo1w16Rh+a35kMTNQUw7kHfrB 9K8vhKH56oq6G3Pivv/LHusYDIhm/8lPFYnbXYMESPkr6zbldQTunmw+OCkCb7SfHKKq cTBw== 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=i5ROKeu3fVCUIXJvWrp6VWiiote6ItG1Ru09SxSpXkk=; fh=Pmv/3wCd/vMMkz6ztZZNrSYr82TrxG1l8ka93ZTHWP8=; b=qWnFDzgx9Ywpafku/foDz+YEoGVByxOBJVy6uc1y2sLXvNqIbaWtOETx8/WtaARgg+ pfInUZv2Ar6qMeDhYr62qt74TAhB5nUwlmqeM4skXdjfbRgCl+f9ODXCIbHkvozXUsN/ tBjIhROXzaCMCKhIedkPnt2Up7EWFqOC0kNUb1y7rZoe0whGz87LAz0+l/jayF5yf0Id Y7KEy0Z5TRv13AZBuKy4wAoAeWdkjHEm8r9m4aMYwIT8CDwjElF5d1CjwKLyVFuYAW7D HrOLj6I+m0RnyKTDO3H7BaILZyPcLBYIhBV/paHKqw9IaDDR8DwDNbTbSm2drqp6EhDR sqJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k6YKOrzT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l63-20020a639142000000b00584aa817597si11776584pge.101.2023.10.10.08.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 08:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k6YKOrzT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id AF8E38167DB5; Tue, 10 Oct 2023 08:19:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbjJJPSv (ORCPT + 20 others); Tue, 10 Oct 2023 11:18:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232771AbjJJPSu (ORCPT ); Tue, 10 Oct 2023 11:18:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3226AA7; Tue, 10 Oct 2023 08:18: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=1696951129; x=1728487129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w1u+oz+TxHGbO6VqcwI4Fu7bojupIN05OR98eU3NVvk=; b=k6YKOrzTcWraLLYtcZGaCknOPXiLRdTgnEN3Q+PiVGgJnLSnl4ra4Keu k2aU3hWbjAsQl8xvd2lAkuiOJXm2xycJwwn+ScK76Gh61g1j9rqONSoyD 8m42ZYcErBooFAora60pJE6C+/Gac134ueCZYCw++Uw9xnYp8wHwlTCtX rvTcOmEOcYU+4L7l0lR35aNpgDQ7h2zWnr623cawIlAGJs1CUz5MEfPjS Q4KunvwkPsqdYBG51ta0c/kErq/UC5JQiGjH9GH9yEL4+S5lE2x/M4EbK zUSMb0v4OwtFRlY6fM1gO8htLNsztS20wQP4K41lR9TPpzZ6HmciRsQ4G Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="415439396" X-IronPort-AV: E=Sophos;i="6.03,213,1694761200"; d="scan'208";a="415439396" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 08:17:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="1084830070" X-IronPort-AV: E=Sophos;i="6.03,213,1694761200"; d="scan'208";a="1084830070" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 10 Oct 2023 08:17:10 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 33E8D93; Tue, 10 Oct 2023 18:17:10 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , Andy Shevchenko , Dipen Patel , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , Thierry Reding , Jonathan Hunter Subject: [PATCH v1 1/4] gpiolib: provide gpio_device_find_by_fwnode() Date: Tue, 10 Oct 2023 18:17:06 +0300 Message-Id: <20231010151709.4104747-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20231010151709.4104747-1-andriy.shevchenko@linux.intel.com> References: <20231010151709.4104747-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 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 autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 10 Oct 2023 08:19:19 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779382261561030284 X-GMAIL-MSGID: 1779382261561030284 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. Signed-off-by: Andy Shevchenko Acked-by: Linus Walleij --- 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);