Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14185473ybl; Mon, 30 Dec 2019 05:39:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwMaTFdRcCDgHvXiM4DjdafcDwUeGJqgwuqQtTpa4fM2po/xqiWjaVchQEDe8xWk7U7WzVk X-Received: by 2002:a05:6830:138b:: with SMTP id d11mr61649867otq.38.1577713197161; Mon, 30 Dec 2019 05:39:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577713197; cv=none; d=google.com; s=arc-20160816; b=tXmU+xzfnecqUFX2fL+2Bh9Qdc+gxoQm8NSl7e9hYZyIiUakEXXeQQupJ1pQmOPKFl M7zVp5vSP7CZqw7VzeBjusKUus9hYPyp3DnHtpVPO4zW+G0gVBKJ2TYj50B7eh55ewTi YXEPlVjkigT1QSFAEx+XnMwBXnjNoa0OHa4GM+p0N1RmsnLJakwZ3ndOuvACS4J+lQ6F btEftd4Eg0gyr26K7c7Zmrl+HJWQxECSqOnc+rWLiNr4eW6J6chDfNEnwQgSH1t8m8VT ZALFLz7X+RcNj1iy2V4sZU2uTfoPKdhKQlZlszk2OBRVdoQL9vkOrX3L31ZgIf+4Ia90 Hftg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BQrTQ2DVQydp/btCJY7+gqoM6/FuWWTffL9DGhTffq0=; b=SFbNnpGEsTwCDZSQVJRQ9baT4Qsr5kChBrFn4ylgep2jAFTD64FSaOkkNzp9jyrSI6 jFHHCxjaYz83zOKMkXk+KtZeaNXjU46c06eixN4n9L/xs89JxPWK7mjEWOVZDpfRgBR8 n69nsmziGRR1OvkluCdPpf5yz8lfRv8hxuzW3mtmAN1VZdJcItp52cT5OUicBmJ/aEsa /avWU83VM0kN7XUcrzMKxbyD5ptVGeg9g9EAhY4MN+8CoUGYAnkSuhFYUxSKYBxqHRHw wE4pCB0S4DBpmpkQGs7I/VDBcvcqaHrrSLvJvatt1z5YaKYAxpnQdRM2qgYow9HsQZjE hSPw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si16559263otr.37.2019.12.30.05.39.42; Mon, 30 Dec 2019 05:39:57 -0800 (PST) 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; 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 S1727505AbfL3NjB (ORCPT + 99 others); Mon, 30 Dec 2019 08:39:01 -0500 Received: from laurent.telenet-ops.be ([195.130.137.89]:38002 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbfL3Ni7 (ORCPT ); Mon, 30 Dec 2019 08:38:59 -0500 Received: from ramsan ([84.195.182.253]) by laurent.telenet-ops.be with bizsmtp id kDeu2100J5USYZQ01Deu5A; Mon, 30 Dec 2019 14:38:57 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1ilvG2-0001h3-Ik; Mon, 30 Dec 2019 14:38:54 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1ilvG2-0001Xq-Gl; Mon, 30 Dec 2019 14:38:54 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Pantelis Antoniou , Frank Rowand , Rob Herring Cc: Peter Ujfalusi , Chris Brandt , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 1/2] gpio: of: Extract of_gpiochip_add_hog() Date: Mon, 30 Dec 2019 14:38:51 +0100 Message-Id: <20191230133852.5890-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230133852.5890-1-geert+renesas@glider.be> References: <20191230133852.5890-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extract the code to add all GPIO hogs of a gpio-hog node into its own function, so it can be reused. Signed-off-by: Geert Uytterhoeven --- drivers/gpio/gpiolib-of.c | 49 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index b696e4598a240ea4..dfae797846bb746b 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -625,6 +625,35 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, return desc; } +/** + * of_gpiochip_add_hog - Add all hogs in a hog device node + * @chip: gpio chip to act on + * @hog: device node describing the hogs + * + * Returns error if it fails otherwise 0 on success. + */ +static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) +{ + enum gpiod_flags dflags; + struct gpio_desc *desc; + unsigned long lflags; + const char *name; + unsigned int i; + int ret; + + for (i = 0;; i++) { + desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags); + if (IS_ERR(desc)) + break; + + ret = gpiod_hog(desc, name, lflags, dflags); + if (ret < 0) + return ret; + } + + return 0; +} + /** * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions * @chip: gpio chip to act on @@ -635,29 +664,17 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, */ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) { - struct gpio_desc *desc = NULL; struct device_node *np; - const char *name; - unsigned long lflags; - enum gpiod_flags dflags; - unsigned int i; int ret; for_each_available_child_of_node(chip->of_node, np) { if (!of_property_read_bool(np, "gpio-hog")) continue; - for (i = 0;; i++) { - desc = of_parse_own_gpio(np, chip, i, &name, &lflags, - &dflags); - if (IS_ERR(desc)) - break; - - ret = gpiod_hog(desc, name, lflags, dflags); - if (ret < 0) { - of_node_put(np); - return ret; - } + ret = of_gpiochip_add_hog(chip, np); + if (ret < 0) { + of_node_put(np); + return ret; } } -- 2.17.1