Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp649220ybv; Thu, 20 Feb 2020 05:02:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxNqTk+wjRGE4ZFQaA783Qjfqejt06EKXc68E5idi+4NDxjlJHvhy9MnF6ikN/B62mnidzy X-Received: by 2002:a05:6830:1e2b:: with SMTP id t11mr23632054otr.81.1582203741456; Thu, 20 Feb 2020 05:02:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582203741; cv=none; d=google.com; s=arc-20160816; b=Eq7fHacZniCtnBSHtBY3ns8GseULFAeUF0w8h+w8AXs2vwpuSrcuaETxZBGdJEjDT7 aHHMguT66fgZTthWgHXhv8iDpF2dEvrCbVp1rZ0w6tsjm1cRtdKaq+xnpk3IsujUXDbD We9nPQXhVog+Ue8tFcDLkmjrw/BSMObeYGr4hVAdJm7FI+bOGSNaq7Re9uhW7zxdqnpw zVz+46aX0HdYA1ZRo70Z860G7WP3ChIQw7pr+/7ZYVzP+Dtte80E5/mNIkB4HJzYBeBm Cp3vHOyj/U7BY6SDpIrKddo+tCFvw5mV1M5OFx0qz1sSkMR4wXJ03lRhPWRi62yVnHJ9 XHLw== 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=Wj8EnTHJRHMvCu0g5UPEOmdzzHN+jYQWloSb3atcgVw=; b=PfyuX4iUAHkyPZMNwgIGA1bkG5SJ2Bdkj9sbkEdud9leThgVFWbt6JFoA3rTXNx9/I sh0VHu50yHcr1r+yfrVS2bkpJmgXzYIcBhOTPKx0NXTScmhSrJiOL1RXNzNAR6trvP51 e2Xr4fXf/UnesV70O9U+ORRf9h2z86VZyS5jUvi0XB5PpbllTi/4a+5pSn2l9nUbrXC9 i6ktBQcL/VrFxWsuA/cOm9ysPbwuWd7xHj+kn6+7bbRHS2D0V19LQzoN2zxPWpK1sBTW 534jfil4W9vGedzUEwWcaS01GF5fxycP/oHJsJ1PcKbdk4yJ3UQGt8e8Ep7p0Tb19Q5i GY+w== 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 h125si10423183oia.253.2020.02.20.05.02.07; Thu, 20 Feb 2020 05:02:21 -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 S1728114AbgBTNCB (ORCPT + 99 others); Thu, 20 Feb 2020 08:02:01 -0500 Received: from laurent.telenet-ops.be ([195.130.137.89]:53472 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727967AbgBTNCA (ORCPT ); Thu, 20 Feb 2020 08:02:00 -0500 Received: from ramsan ([84.195.182.253]) by laurent.telenet-ops.be with bizsmtp id 511u220065USYZQ0111uY3; Thu, 20 Feb 2020 14:01:58 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1j4lSj-000564-VF; Thu, 20 Feb 2020 14:01:53 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1j4lSj-0007Lh-To; Thu, 20 Feb 2020 14:01:53 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Pantelis Antoniou , Frank Rowand , Rob Herring , Mark Rutland 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 v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Date: Thu, 20 Feb 2020 14:01:48 +0100 Message-Id: <20200220130149.26283-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200220130149.26283-1-geert+renesas@glider.be> References: <20200220130149.26283-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 --- v2: - No changes. --- 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 c6d30f73df078e0b..2b47f93886075294 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -604,6 +604,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 @@ -614,29 +643,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