From patchwork Tue Jun 14 10:07:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 69980 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1962958qgf; Tue, 14 Jun 2016 03:06:38 -0700 (PDT) X-Received: by 10.107.55.132 with SMTP id e126mr30144611ioa.35.1465898798293; Tue, 14 Jun 2016 03:06:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9si23517429pax.66.2016.06.14.03.06.38; Tue, 14 Jun 2016 03:06:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751785AbcFNKGh (ORCPT + 4 others); Tue, 14 Jun 2016 06:06:37 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:55837 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751326AbcFNKGg (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 u5EA5ngI003372; Tue, 14 Jun 2016 19:05:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u5EA5ngI003372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1465898754; bh=mpx3lvQkafbtihVa5sBgAaNyfHBzoDlFfeyfYRd0KV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VtUX0gE0vAKm8gZczWVOAtZ7HEcCaNMnhGUUEmKhyJF87hGPp1R8VKhoP+eQlHwRd EzqmUxV6v07SYnAQvB2Ka7hz866Sag34WxPi/IzNib5TsOaBgdPthsmJ7D9RXW5y42 XZOV021YPr2YjZblqLiaeo2h92sKrA5ln40d1FYBdJzN5YGkz66ZMq+dPqXofckdgI 1ZFTu0DxAcjZQ1Y1bosMIBvrKDodmiaSH3Y48JX979TQxCaoCOwDn+5Fa3RS4pl4vf ly/+I9BEEOWSNJWoWnE/1du5rxdpLpRMd0GUBL+peHFyEhVUdEt1gvizP4f8zOyAYn 1o1egDIFfmsqQ== 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 5/5] gpio: of: factor out common code to a new helper function Date: Tue, 14 Jun 2016 19:07:07 +0900 Message-Id: <1465898827-2229-6-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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The conversion from a DT spec to struct gpio_desc is common between of_get_named_gpiod_flags() and of_parse_own_gpio(). Factor out the common code to a new helper, of_xlate_and_get_gpiod_flags(). Signed-off-by: Masahiro Yamada --- drivers/gpio/gpiolib-of.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index d5e19f6..75e7b39 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -37,6 +37,22 @@ static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) return gpiochip_find(np, of_gpiochip_match_node); } +static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, + struct of_phandle_args *gpiospec, + enum of_gpio_flags *flags) +{ + int ret; + + if (chip->of_gpio_n_cells != gpiospec->args_count) + return ERR_PTR(-EINVAL); + + ret = chip->of_xlate(chip, gpiospec, flags); + if (ret < 0) + return ERR_PTR(ret); + + return gpiochip_get_desc(chip, ret); +} + /** * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API * @np: device node to get GPIO from @@ -69,18 +85,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, desc = ERR_PTR(-EPROBE_DEFER); goto out; } - if (chip->of_gpio_n_cells != gpiospec.args_count) { - desc = ERR_PTR(-EINVAL); - goto out; - } - - ret = chip->of_xlate(chip, &gpiospec, flags); - if (ret < 0) { - desc = ERR_PTR(ret); - goto out; - } - desc = gpiochip_get_desc(chip, ret); + desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags); if (IS_ERR(desc)) goto out; @@ -145,9 +151,6 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, if (ret) return ERR_PTR(ret); - if (tmp != chip->of_gpio_n_cells) - return ERR_PTR(-EINVAL); - gpiospec.np = chip_np; gpiospec.args_count = tmp; @@ -155,11 +158,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, if (ret) return ERR_PTR(ret); - ret = chip->of_xlate(chip, &gpiospec, &xlate_flags); - if (ret < 0) - return ERR_PTR(ret); - - desc = gpiochip_get_desc(chip, ret); + desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); if (IS_ERR(desc)) return desc;