From patchwork Tue Sep 5 18:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13374928 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79023CA0FFA for ; Tue, 5 Sep 2023 18:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fxQVuVUjOqpiDaiXoOmr5dffCjTqEh3LADHA+K/oQ/8=; b=xgaVfWOTMkgKbY 8OGmL2xLx/IW9MsOFIOb+9rpLNKPuC3GwS1EM+drXjHJCIhVH0PFbqUZGNdN97lOaaPZ0qywclDXX IOtm6Kn2yNs3ms5+fHoV5AdneuZGWhHwdR8fMMec+JYBwtK44+Q+irWjOcI6RIthexJ3Y8eWEpJS0 qqQ35MwKmYhR96JF9eiXd3rPKR8tGzA7tTYJJ5GoW3rqsMG6uB8GcmeMAhxl4GChAoCH4OOhmf1WD qGwvV+SeEbqjP4zQXfN05X6WrK+U18v25sYcjJoCbr6Q9/o+jks328bwKCYvfj4CoJBsErezwKGaw 3iAR3JQn0oicR9KYPA0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qdbBD-006YSR-1l; Tue, 05 Sep 2023 18:53:39 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qdbB9-006YOh-07 for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2023 18:53:37 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401b0d97850so30051635e9.2 for ; Tue, 05 Sep 2023 11:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1693940010; x=1694544810; darn=lists.infradead.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=vqkLr0JyIMxB5faQNNXnf+zRj68nvo49fQs7ZKVuUBo=; b=thM2Xs+9mSJCjXxwzL8+ehUqoIDRPxpP061l8IIfoJ1043D6TakQjyjs4r1DlWEIgB WWSI3X+yMdpdT7aguvkJvsFSi7AvfNJEcWEfZbJslAGJAmIGv2x/2QhfLFw6MyRZuXXW ETsWXqcPyK5kiz9cB1jxXGB/luy8M5Aow/mOu15Indtzx8UQZXgGDehsssd8vK3CPfl9 W1V9Ou0C489TwdAE26lz/L6m56TFVOoxSXdXbyoBoTeR43wNAM8IXzRIuAcYLg6ev3xv S/FYMyVjwwz4WlSmf4A3SKeAaN3yTwo8DNbfv4cf3meYGRyMpzDFZDu+WqSEwlVRb/xT rsSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693940010; x=1694544810; 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=vqkLr0JyIMxB5faQNNXnf+zRj68nvo49fQs7ZKVuUBo=; b=bpLP0CSgU6yqbYefE5eiWN6tL9NGnEl4sESZmjsPi9YizhJ7TC1Os0aETHJfn5RH9K tRB8MzizO5s1EBO9oCpTbW/sA5URR+WcgXnPM+PcreAEt6Gs7ln5o4yIAxp9J8n177i+ TYoL57aYaNTWVnUvIdFgCJjm0uWlBNLHslwI7O4LNe2KE9Azack74ZSy6QW0cowE59zv wXv73sSSBK43ayYgvzTW6CGIqoFHx7Ur/AxVM13XQbSVxluXA8uibUKZeDMsOotwIs9A OZhob55OtsLrI8xa/vIU92WVzBKFvL0DWznisnmKy54bUkx+NO7vYV1PVRTfd2G4SQot DPug== X-Gm-Message-State: AOJu0YxsS2QzB9r+Qsl1HIcuD6g0CU7IeQW9krVI5cp8vj/WL8iF8sWv nou5Ub/5Dx5loPowFJAklwozOQ== X-Google-Smtp-Source: AGHT+IG3KG15PaiG7DgNG5yZVi1RIG05HTUsTSLH76kG9iwAZEGSHThfSg45jv+oBWQBQS0UnnvYaw== X-Received: by 2002:a05:600c:2256:b0:3fe:1af6:6542 with SMTP id a22-20020a05600c225600b003fe1af66542mr449099wmm.33.1693940009775; Tue, 05 Sep 2023 11:53:29 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7a54:5dbc:6d09:48b7]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c249100b003fbc30825fbsm17550010wms.39.2023.09.05.11.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 11:53:29 -0700 (PDT) From: Bartosz Golaszewski To: Aaro Koskinen , Janusz Krzysztofik , Tony Lindgren , Russell King , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Dipen Patel , Thierry Reding , Jonathan Hunter , Hans de Goede , Mark Gross Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org, platform-driver-x86@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 03/21] gpiolib: provide gpio_device_find_by_label() Date: Tue, 5 Sep 2023 20:52:51 +0200 Message-Id: <20230905185309.131295-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230905185309.131295-1-brgl@bgdev.pl> References: <20230905185309.131295-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230905_115335_073808_B9B9E265 X-CRM114-Status: GOOD ( 12.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 9e083ecb8df0..74b837671d30 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1074,6 +1075,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 5c5029cec226..92f7143bad3e 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -609,6 +609,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);