From patchwork Wed Nov 27 08:42:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 11263625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59CD913A4 for ; Wed, 27 Nov 2019 08:47:16 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 38909204FD for ; Wed, 27 Nov 2019 08:47:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38909204FD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=glider.be Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZsyg-0007k1-2b for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Nov 2019 03:47:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41832) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZsx4-0005gl-54 for qemu-devel@nongnu.org; Wed, 27 Nov 2019 03:45:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZsum-0002nm-IK for qemu-devel@nongnu.org; Wed, 27 Nov 2019 03:43:13 -0500 Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]:36338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZsum-0002lD-AQ for qemu-devel@nongnu.org; Wed, 27 Nov 2019 03:43:12 -0500 Received: from ramsan ([84.195.182.253]) by xavier.telenet-ops.be with bizsmtp id Wwiu2100T5USYZQ01wiuc1; Wed, 27 Nov 2019 09:43:07 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1iZsuU-0000xh-LV; Wed, 27 Nov 2019 09:42:54 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1iZsuU-0004OX-JP; Wed, 27 Nov 2019 09:42:54 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Jonathan Corbet , Rob Herring , Mark Rutland , Harish Jenny K N , Eugeniu Rosca Subject: [PATCH v3 2/7] gpiolib: Add support for gpiochipN-based table lookup Date: Wed, 27 Nov 2019 09:42:48 +0100 Message-Id: <20191127084253.16356-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191127084253.16356-1-geert+renesas@glider.be> References: <20191127084253.16356-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:120:4::f00:14 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: 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, devicetree@vger.kernel.org, Alexander Graf , Paolo Bonzini , Phil Reid Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.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" either the corresponding GPIO device's ID number, or the GPIO controller's first GPIO number. Signed-off-by: Geert Uytterhoeven Reviewed-by: Ulrich Hecht --- If this is rejected, the GPIO Aggregator documentation must be updated. The second variant is currently used by the legacy sysfs interface only, so perhaps the chip->base check should be dropped? v3: - New. --- drivers/gpio/gpiolib.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c9e47620d2434983..d24a3d79dcfe69ad 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1746,9 +1746,29 @@ static int gpiochip_match_name(struct gpio_chip *chip, void *data) return !strcmp(chip->label, name); } +static int gpiochip_match_id(struct gpio_chip *chip, void *data) +{ + int id = (uintptr_t)data; + + return id == chip->base || id == chip->gpiodev->id; +} + static struct gpio_chip *find_chip_by_name(const char *name) { - return gpiochip_find((void *)name, gpiochip_match_name); + struct gpio_chip *chip; + int id; + + chip = gpiochip_find((void *)name, gpiochip_match_name); + if (chip) + return chip; + + if (!str_has_prefix(name, GPIOCHIP_NAME)) + return NULL; + + if (kstrtoint(name + strlen(GPIOCHIP_NAME), 10, &id)) + return NULL; + + return gpiochip_find((void *)(uintptr_t)id, gpiochip_match_id); } #ifdef CONFIG_GPIOLIB_IRQCHIP