From patchwork Wed Sep 27 14:29:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 145670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3009872vqu; Wed, 27 Sep 2023 18:35:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUbKLFN0GENk+vHFTJV7SZseRGmGDR0xzZQMiNO4s2x1vPZwuGY4jIZnlRDnxK4vYs+4+9 X-Received: by 2002:a25:dd2:0:b0:d81:4107:7a3 with SMTP id 201-20020a250dd2000000b00d81410707a3mr3517903ybn.23.1695864910327; Wed, 27 Sep 2023 18:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695864910; cv=none; d=google.com; s=arc-20160816; b=tz9gglUFtaXkIHc4vTZ9ZHWPH7aOAx1xjrZYPqHCAvYcjeuBBz7nI8lg03BT3d3Eia BPRucjftTMPfT0Wfxglpn6ntXVwYIpatssRkvMs07amR4f3FZ/yxggC/3NzzAjscGY9Q fqGP8VhWcGmjhbBdKHVNXHR7Nu8Xiw6eT3a7EWgY2RH060ISgIp7o5rd0+ILD5kSUd1n r80EhUwvGhFRxcH5Cnr6DmyWCidcRXb6A+rqNTuPiNCkPHO1SsJMWZp8fRkhbQ56jOrH tvm8xOLFy2FioslPty27mw7teU6y+3IoEo1wZysYRP6DsJRICk9moTBzKUBAlh9ktt+H A2ug== 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=fTcEgfPoq9MntpjrBDVs2nRvtCmOFJGrOAf8mTlZ6ic=; fh=sKfwLbYyGsqFA9J5964tfV31zxizqPhzkdLiyF/udjc=; b=j7R49EHrBQ8kIqZQKnHHGNbXg0sHoIroWFQUt7Ig3qOwez29FYE1uf/aHwXg1whcdC Q140Da+gxs3FPNQ3IEK+ByMk/m8xfTMW/yYPsbnMOmNhptqvr9lrTnTRARhCeU0SnllZ +KNBiBBmcXVkrncmeP1J4si58u34IGGwSJL5JMZqDYW682lq/tSN+QZCPDBUxQHA4VL8 ftqefgcanO+KxT9sMyR6T5d5gma/4UdFn2cMNbmspFlrwRomQmNFEtZnE1w50x9wNHee lEzIqS14sMUuRmhDpvJkhgz5w33ZgjpwMt9K53eJb6r15kOtjhvDGD2VfZNzAE7fpaC/ pTww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=yMGNr1kd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bs6-20020a632806000000b0057458518e20si2792932pgb.164.2023.09.27.18.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 18:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=yMGNr1kd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 30698809B9CB; Wed, 27 Sep 2023 07:30:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232123AbjI0O3u (ORCPT + 21 others); Wed, 27 Sep 2023 10:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjI0O3m (ORCPT ); Wed, 27 Sep 2023 10:29:42 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EE22180 for ; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-307d58b3efbso9564626f8f.0 for ; Wed, 27 Sep 2023 07:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695824979; x=1696429779; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fTcEgfPoq9MntpjrBDVs2nRvtCmOFJGrOAf8mTlZ6ic=; b=yMGNr1kd3hLtrwjjnHhdG5D7rrhYIkgDkk4BxMJ6QcP26LpenmcAAuDPnHf2x5ArVt EgoK3A847GtHVbvzEw6m7lGUfHRpOEIlkETZaMT+0uBkyCCc4cyRTx91CSDrdjS6dx7b VlMWCtmFop9dmPdfsGynvahT/rsGD39zjTGZG7j1M8Fvb/t7eVpGu2Ni5rRpS5ixnY+X WhqaNKJgs/c145/0CyW2xlyasxa8FgO3ISVEs8QG8/OwNGCUU4xeLtMiM4Pzo2mG5FKp TXYoUbHI/YlQ9AGP8ed46DMSFpQzaXCONn4HUeRWYpoMXkQJ9LXrJNn97R0Q0r+K3i++ tpjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695824979; x=1696429779; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fTcEgfPoq9MntpjrBDVs2nRvtCmOFJGrOAf8mTlZ6ic=; b=QD8g5xtOM4kqcWSKfo44WQ4W/mhWFG4juOEydK21eHBLW+i7wOdPcTY7jgTrQEh298 WejTTaxiQDO/3NpnjfIwphC1BEAqdhN3f8TR+SecsG6mPQJERp3JY4QoBzIhEISlwg0A dsCdo5aW84urrnFZJZPcGMIV7xMh/R5Feqnp2yECFg1ImdOE6p/zBX5aDKJJEidT8uE+ paoaTr0PccrGHhwQJLwAjgM4ZXg4OV2sNEKxvhG9zpQdt3ZFpqHZ7ceZNZwVAwAiBWfM JDGjCje1AiohU36O6pwl1dq6M2QOm5lAalDiT4sZHlX0rGWj3CmqER0SSGnJI3xVK34T SVTw== X-Gm-Message-State: AOJu0YyCbtXeicnocwfDTpidCr5ERMxOg/ThFlwFYEaPYjSAWsI5En3u 55+nDCgeru1vKRKPkLJ6zm3ivw== X-Received: by 2002:a5d:5582:0:b0:31a:ddf0:93b with SMTP id i2-20020a5d5582000000b0031addf0093bmr1944891wrv.33.1695824978901; Wed, 27 Sep 2023 07:29:38 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4bb6:1525:9e22:4a15]) by smtp.gmail.com with ESMTPSA id v2-20020a1cf702000000b003feae747ff2sm20448303wmh.35.2023.09.27.07.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:29:38 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Mika Westerberg Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 04/11] gpiolib: provide gpio_device_find_by_label() Date: Wed, 27 Sep 2023 16:29:24 +0200 Message-Id: <20230927142931.19798-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230927142931.19798-1-brgl@bgdev.pl> References: <20230927142931.19798-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 07:30:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778243244065702220 X-GMAIL-MSGID: 1778243244065702220 From: Bartosz Golaszewski By far the most common way of looking up GPIO devices is using their label. Provide a helpers for that to avoid every user implementing their own matching function. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0371d23f0a46..9f20311e4c1a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1081,6 +1082,26 @@ struct gpio_device *gpio_device_find(void *data, } EXPORT_SYMBOL_GPL(gpio_device_find); +static int gpio_chip_match_by_label(struct gpio_chip *gc, void *label) +{ + return gc->label && !strcmp(gc->label, label); +} + +/** + * gpio_device_find_by_label() - wrapper around gpio_device_find() finding the + * GPIO device by its backing chip's label + * @label: Label 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_label(const char *label) +{ + return gpio_device_find((void *)label, gpio_chip_match_by_label); +} +EXPORT_SYMBOL_GPL(gpio_device_find_by_label); + static int gpiochip_match_name(struct gpio_chip *gc, void *data) { const char *name = data; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 6ad1f1a8ef2e..24996cba6465 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -610,6 +610,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_get(struct gpio_device *gdev); void gpio_device_put(struct gpio_device *gdev);