From patchwork Tue Feb 18 15:18:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 1240131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=glider.be Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48MPdh0tm9z9sNg for ; Wed, 19 Feb 2020 02:19:02 +1100 (AEDT) Received: from localhost ([::1]:36932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j44eJ-0005bi-Be for incoming@patchwork.ozlabs.org; Tue, 18 Feb 2020 10:18:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35863) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j44ds-0005aP-KW for qemu-devel@nongnu.org; Tue, 18 Feb 2020 10:18:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j44dq-0006Yt-Gz for qemu-devel@nongnu.org; Tue, 18 Feb 2020 10:18:31 -0500 Received: from laurent.telenet-ops.be ([2a02:1800:110:4::f00:19]:59228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j44dq-0006W5-5j for qemu-devel@nongnu.org; Tue, 18 Feb 2020 10:18:30 -0500 Received: from ramsan ([84.195.182.253]) by laurent.telenet-ops.be with bizsmtp id 4FJD2200x5USYZQ01FJDuz; Tue, 18 Feb 2020 16:18:25 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1j44dZ-0006yB-Pw; Tue, 18 Feb 2020 16:18:13 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1j44dZ-00022w-O1; Tue, 18 Feb 2020 16:18:13 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Jonathan Corbet , Harish Jenny K N , Eugeniu Rosca Subject: [PATCH v5 1/5] gpiolib: Add support for gpiochipN-based table lookup Date: Tue, 18 Feb 2020 16:18:08 +0100 Message-Id: <20200218151812.7816-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200218151812.7816-1-geert+renesas@glider.be> References: <20200218151812.7816-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:110:4::f00:19 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , linux-doc@vger.kernel.org, Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Rob Herring , Alexander Graf , Paolo Bonzini , Phil Reid Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently GPIO controllers can only be referred to by label in GPIO lookup tables. Add support for looking them up by "gpiochipN" name, with "N" the corresponding GPIO device's ID number. Signed-off-by: Geert Uytterhoeven Reviewed-by: Ulrich Hecht Reviewed-by: Eugeniu Rosca Tested-by: Eugeniu Rosca --- v5: - Add Reviewed-by, Tested-by, v4: - Add Reviewed-by, - Drop support for legacy sysfs interface based name matching, - Replace complex custom matching by a simple additional check in the existing gpiochip_match_name() function, - Add kerneldoc() for find_chip_by_name(), documenting matching order. v3: - New. --- drivers/gpio/gpiolib.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4d0106ceeba7bb24..200c2d2be4b78043 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1738,9 +1738,18 @@ static int gpiochip_match_name(struct gpio_chip *chip, void *data) { const char *name = data; - return !strcmp(chip->label, name); + return !strcmp(chip->label, name) || + !strcmp(dev_name(&chip->gpiodev->dev), name); } +/** + * find_chip_by_name() - Find a specific gpio_chip by name + * @name: Name to match + * + * Return a reference to a gpio_chip that matches the passed name. + * This function first tries matching on the gpio_chip's label, followed by + * matching on dev_name() of the corresponding gpio_device. + */ static struct gpio_chip *find_chip_by_name(const char *name) { return gpiochip_find((void *)name, gpiochip_match_name);