From patchwork Tue Apr 15 06:41:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 3989351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B1949F336 for ; Tue, 15 Apr 2014 06:45:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7461201FB for ; Tue, 15 Apr 2014 06:45:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B99A5201FA for ; Tue, 15 Apr 2014 06:45:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WZx5O-00048L-QK; Tue, 15 Apr 2014 06:43:14 +0000 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WZx4q-0003rP-Gy for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2014 06:42:41 +0000 Received: from wens by mirror2.csie.ntu.edu.tw with local (Exim 4.82) (envelope-from ) id 1WZx3u-0004jG-1J; Tue, 15 Apr 2014 14:41:42 +0800 From: Chen-Yu Tsai To: Linus Walleij , Johannes Berg , "John W. Linville" , Maxime Ripard Subject: [PATCH 1/7] gpiolib: gpiolib-of: Implement device tree gpio-names based lookup Date: Tue, 15 Apr 2014 14:41:35 +0800 Message-Id: <1397544101-18135-2-git-send-email-wens@csie.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1397544101-18135-1-git-send-email-wens@csie.org> References: <1397544101-18135-1-git-send-email-wens@csie.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140414_234240_742999_991A8C5F X-CRM114-Status: GOOD ( 13.12 ) X-Spam-Score: -1.0 (-) Cc: Alexandre Courbot , Heikki Krogerus , Arnd Bergmann , Stephen Warren , devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-sunxi@googlegroups.com, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Chen-Yu Tsai , Mika Westerberg , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch provides of_get_gpiod_flags_by_name(), which looks up GPIO phandles by name only, through gpios/gpio-names, and not by index. Signed-off-by: Chen-Yu Tsai --- drivers/gpio/gpiolib-of.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_gpio.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 2024d45..5c586fa 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -97,6 +97,54 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, EXPORT_SYMBOL(of_get_named_gpiod_flags); /** + * of_get_gpiod_flags_by_name() - Get a GPIO descriptor and flags by name + * @np: device node to get GPIO from + * @name: matching name of gpio phandle + * @flags: a flags pointer to fill in + * + * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno + * value on the error condition. If @flags is not NULL the function also fills + * in flags for the GPIO. + */ +struct gpio_desc *of_get_gpiod_flags_by_name(struct device_node *np, + const char *name, enum of_gpio_flags *flags) +{ + /* Return -EPROBE_DEFER to support probe() functions to be called + * later when the GPIO actually becomes available + */ + struct gg_data gg_data = { + .flags = flags, + .out_gpio = ERR_PTR(-EPROBE_DEFER) + }; + int index = 0; + int ret; + + /* exit if no name given */ + if (!name) + return ERR_PTR(-EINVAL); + + /* .of_xlate might decide to not fill in the flags, so clear it. */ + if (flags) + *flags = 0; + + if (name) + index = of_property_match_string(np, "gpio-names", name); + + ret = of_parse_phandle_with_args(np, "gpios", "#gpio-cells", index, + &gg_data.gpiospec); + + if (ret) + return ERR_PTR(ret); + + gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); + + of_node_put(gg_data.gpiospec.np); + + return gg_data.out_gpio; +} +EXPORT_SYMBOL(of_get_gpiod_flags_by_names); + +/** * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags * @gc: pointer to the gpio_chip structure * @np: device node of the GPIO chip diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index f14123a..134331f 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h @@ -51,6 +51,9 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, const char *list_name, int index, enum of_gpio_flags *flags); +extern struct gpio_desc *of_get_gpiod_flags_by_name(struct device_node *np, + const char *name, enum of_gpio_flags *flags); + extern int of_mm_gpiochip_add(struct device_node *np, struct of_mm_gpio_chip *mm_gc);