mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/3] gpiolib: introduce gpio initializer
Date: Tue, 26 Sep 2017 23:26:46 +0200	[thread overview]
Message-ID: <20170926212646.2968-4-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20170926212646.2968-1-u.kleine-koenig@pengutronix.de>

To define the initial state of a given gpio you can add a gpio-init node
to a gpio controller. This doesn't prevent a later consumer to request
that pin and only defines a save initial state.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/gpio/gpiolib.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index de543fbb1321..4aeba5193726 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -260,13 +260,12 @@ int gpio_direction_input(unsigned gpio)
 }
 EXPORT_SYMBOL(gpio_direction_input);
 
-static int gpioinfo_request_one(struct gpio_info *gi, unsigned long flags,
-				const char *label)
+static int gpioinfo_configure(struct gpio_info *gi, unsigned long flags)
 {
 	int err;
 
 	/*
-	 * Not all of the flags below are mulit-bit, but, for the sake
+	 * Not all of the flags below are multi-bit, but, for the sake
 	 * of consistency, the code is written as if all of them were.
 	 */
 	const bool active_low  = (flags & GPIOF_ACTIVE_LOW) == GPIOF_ACTIVE_LOW;
@@ -275,10 +274,6 @@ static int gpioinfo_request_one(struct gpio_info *gi, unsigned long flags,
 	const bool init_active = (flags & GPIOF_INIT_ACTIVE) == GPIOF_INIT_ACTIVE;
 	const bool init_high   = (flags & GPIOF_INIT_HIGH) == GPIOF_INIT_HIGH;
 
-	err = gpioinfo_request(gi, label);
-	if (err)
-		return err;
-
 	gi->active_low = active_low;
 
 	if (dir_in)
@@ -288,6 +283,19 @@ static int gpioinfo_request_one(struct gpio_info *gi, unsigned long flags,
 	else
 		err = gpioinfo_direction_output(gi, init_high);
 
+	return err;
+}
+
+static int gpioinfo_request_one(struct gpio_info *gi, unsigned long flags,
+				const char *label)
+{
+	int err;
+
+	err = gpioinfo_request(gi, label);
+	if (err)
+		return err;
+
+	err = gpioinfo_configure(gi, flags);
 	if (err)
 		gpioinfo_free(gi);
 
@@ -375,14 +383,15 @@ static int gpiochip_find_base(int start, int ngpio)
 	return base;
 }
 
-static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
-		       unsigned int idx)
+static int of_hogninit_gpio(struct device_node *np, struct gpio_chip *chip,
+			    unsigned int idx, bool request)
 {
 	struct device_node *chip_np = chip->dev->device_node;
 	unsigned long flags = 0;
 	u32 gpio_cells, gpio_num, gpio_flags;
 	int ret, gpio;
 	const char *name = NULL;
+	struct gpio_info *gi;
 
 	ret = of_property_read_u32(chip_np, "#gpio-cells", &gpio_cells);
 	if (ret)
@@ -417,6 +426,7 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
 		return ret;
 	}
 
+	gi = gpio_to_desc(gpio);
 
 	/*
 	 * Note that, in order to be compatible with Linux, the code
@@ -439,9 +449,13 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
 	else
 		return -EINVAL;
 
-	of_property_read_string(np, "line-name", &name);
+	if (request) {
+		of_property_read_string(np, "line-name", &name);
 
-	return gpio_request_one(gpio, flags, name);
+		return gpioinfo_request_one(gi, flags, name);
+	} else {
+		return gpioinfo_configure(gi, flags);
+	}
 }
 
 static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
@@ -453,12 +467,15 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
 		return 0;
 
 	for_each_available_child_of_node(chip->dev->device_node, np) {
-		if (!of_property_read_bool(np, "gpio-hog"))
+		bool hog = of_property_read_bool(np, "gpio-hog");
+		bool init = of_property_read_bool(np, "gpio-init");
+
+		if (!hog && !init)
 			continue;
 
 		for (ret = 0, i = 0;
 		     !ret;
-		     ret = of_hog_gpio(np, chip, i), i++)
+		     ret = of_hogninit_gpio(np, chip, i, hog), i++)
 			;
 		/*
 		 * We ignore -EOVERFLOW because it serves us as an
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-09-26 21:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-26 21:26 [PATCH 0/3] " Uwe Kleine-König
2017-09-26 21:26 ` [PATCH 1/3] gpiolib: reorder functions Uwe Kleine-König
2017-09-26 21:26 ` [PATCH 2/3] gpiolib: introduce helper functions working on gpio_info structs Uwe Kleine-König
2017-09-26 21:26 ` Uwe Kleine-König [this message]
2017-10-06  4:29 ` [PATCH 0/3] gpiolib: introduce gpio initializer Sascha Hauer
2017-10-09 19:27   ` Uwe Kleine-König

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=20170926212646.2968-4-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.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