From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
Frank Rowand <frowand.list@gmail.com>,
Rob Herring <robh+dt@kernel.org>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>,
Chris Brandt <chris.brandt@renesas.com>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH/RFC 1/2] gpio: of: Extract of_gpiochip_add_hog()
Date: Mon, 30 Dec 2019 14:38:51 +0100 [thread overview]
Message-ID: <20191230133852.5890-2-geert+renesas@glider.be> (raw)
In-Reply-To: <20191230133852.5890-1-geert+renesas@glider.be>
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 <geert+renesas@glider.be>
---
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
next prev parent reply other threads:[~2019-12-30 13:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-30 13:38 [PATCH/RFC 0/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
2019-12-30 13:38 ` Geert Uytterhoeven [this message]
2019-12-30 13:38 ` [PATCH/RFC 2/2] " Geert Uytterhoeven
2020-01-06 23:34 ` Frank Rowand
2020-01-07 7:10 ` Frank Rowand
2020-01-07 7:25 ` Frank Rowand
2020-01-07 8:02 ` Geert Uytterhoeven
2020-01-07 8:11 ` Geert Uytterhoeven
2020-01-24 21:57 ` Frank Rowand
2020-01-24 22:02 ` Frank Rowand
2020-01-07 7:59 ` Geert Uytterhoeven
2020-01-03 9:51 ` [PATCH/RFC 0/2] " Bartosz Golaszewski
2020-01-07 7:46 ` Geert Uytterhoeven
2020-01-07 9:03 ` Bartosz Golaszewski
2020-01-07 9:49 ` Geert Uytterhoeven
2020-01-06 23:34 ` Frank Rowand
2020-01-07 7:51 ` Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191230133852.5890-2-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=bgolaszewski@baylibre.com \
--cc=chris.brandt@renesas.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=pantelis.antoniou@konsulko.com \
--cc=peter.ujfalusi@ti.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).