From patchwork Tue Jun 14 10:07:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 69984 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1963419qgf; Tue, 14 Jun 2016 03:07:45 -0700 (PDT) X-Received: by 10.98.36.130 with SMTP id k2mr2917282pfk.118.1465898864846; Tue, 14 Jun 2016 03:07:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cq10si23525719pac.11.2016.06.14.03.07.44; Tue, 14 Jun 2016 03:07:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752277AbcFNKHB (ORCPT + 30 others); Tue, 14 Jun 2016 06:07:01 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:55828 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751618AbcFNKGg (ORCPT ); Tue, 14 Jun 2016 06:06:36 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id u5EA5ngF003372; Tue, 14 Jun 2016 19:05:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u5EA5ngF003372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1465898751; bh=y8HyEJr6Z++62A97wlh0wnvhPQ3lKHQmpsC7ueshtJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x5PJ0SKpCf284hnZH688MuTRAgx9B3/KRLgvPXdXFV0LjtdNftLRoqyyMSXpPpog2 GPlXLQIIzOfbt9zbOa/kF7Bco4oa7nYIr0RKlp+QfYkY0GYUXBqDVLfqdb+38aGOw2 zdnjTeP/WL9MSX5ynvkLOXyxXLkCwhVQGBdfgobE8ahjqqS/lfjj2LYOSo9CmUAL+Y hhBsVzDAmqUWfumG1JOKifBuEq00W6cgutV44/nqVzDHdPXihshd2CHW8h3QmPxIEW KtD/ehcjSi8KG7E870hOxyxlCCrvVgQxTkyugb4cbAz6PgIOb1SYGjRZxG/0I2g4j4 ubJZSldP8Us9g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-gpio@vger.kernel.org Cc: Masahiro Yamada , Linus Walleij , Alexandre Courbot , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] gpio: of: drop needless gpio_chip look-up in of_parse_own_gpio() Date: Tue, 14 Jun 2016 19:07:04 +0900 Message-Id: <1465898827-2229-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465898827-2229-1-git-send-email-yamada.masahiro@socionext.com> References: <1465898827-2229-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function is doing more complicated than needed. The caller of this function, of_gpiochip_scan_gpios() already knows the pointer to the gpio_chip. It can pass it to of_parse_own_gpio() instead of looking up the gpio_chip by gpiochip_find(). Signed-off-by: Masahiro Yamada --- drivers/gpio/gpiolib-of.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) -- 1.9.1 diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 99fc40e..27b1729 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -122,6 +122,7 @@ EXPORT_SYMBOL(of_get_named_gpio_flags); /** * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API * @np: device node to get GPIO from + * @chip: GPIO chip whose hog is parsed * @name: GPIO line name * @lflags: gpio_lookup_flags - returned from of_find_gpio() or * of_parse_own_gpio() @@ -131,19 +132,19 @@ EXPORT_SYMBOL(of_get_named_gpio_flags); * value on the error condition. */ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, + struct gpio_chip *chip, const char **name, enum gpio_lookup_flags *lflags, enum gpiod_flags *dflags) { struct device_node *chip_np; enum of_gpio_flags xlate_flags; - struct gg_data gg_data = { - .flags = &xlate_flags, - }; + struct of_phandle_args gpiospec; + struct gpio_desc *desc; u32 tmp; int ret; - chip_np = np->parent; + chip_np = chip->of_node; if (!chip_np) return ERR_PTR(-EINVAL); @@ -155,23 +156,23 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, if (ret) return ERR_PTR(ret); - if (tmp > MAX_PHANDLE_ARGS) + if (tmp > MAX_PHANDLE_ARGS || tmp != chip->of_gpio_n_cells) return ERR_PTR(-EINVAL); - gg_data.gpiospec.args_count = tmp; - gg_data.gpiospec.np = chip_np; - ret = of_property_read_u32_array(np, "gpios", gg_data.gpiospec.args, - tmp); + gpiospec.np = chip_np; + gpiospec.args_count = tmp; + + ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp); if (ret) return ERR_PTR(ret); - gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); - if (!gg_data.out_gpio) { - if (np->parent == np) - return ERR_PTR(-ENXIO); - else - return ERR_PTR(-EINVAL); - } + ret = chip->of_xlate(chip, &gpiospec, &xlate_flags); + if (ret < 0) + return ERR_PTR(ret); + + desc = gpiochip_get_desc(chip, ret); + if (IS_ERR(desc)) + return desc; if (xlate_flags & OF_GPIO_ACTIVE_LOW) *lflags |= GPIO_ACTIVE_LOW; @@ -184,14 +185,14 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, *dflags |= GPIOD_OUT_HIGH; else { pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n", - desc_to_gpio(gg_data.out_gpio), np->name); + desc_to_gpio(desc), np->name); return ERR_PTR(-EINVAL); } if (name && of_property_read_string(np, "line-name", name)) *name = np->name; - return gg_data.out_gpio; + return desc; } /** @@ -260,7 +261,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) if (!of_property_read_bool(np, "gpio-hog")) continue; - desc = of_parse_own_gpio(np, &name, &lflags, &dflags); + desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags); if (IS_ERR(desc)) continue;