devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>,
	devicetree@vger.kernel.org, linux-gpio@vger.kernel.org,
	kernel@pengutronix.de, Markus Pargmann <mpa@pengutronix.de>
Subject: [PATCH v3 2/2] gpiolib: Add GPIO initialization
Date: Tue, 17 Nov 2015 11:07:58 +0100	[thread overview]
Message-ID: <1447754878-21099-3-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1447754878-21099-1-git-send-email-mpa@pengutronix.de>

This functions adds a way to initialize a GPIO without hogging it.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/gpio/gpiolib-of.c | 13 ++++++++-----
 drivers/gpio/gpiolib.c    | 24 ++++++++++++++++++++++++
 drivers/gpio/gpiolib.h    |  2 ++
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 5fe34a9df3e6..48cdc22eabf2 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -211,15 +211,18 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip)
 	enum gpiod_flags dflags;
 
 	for_each_child_of_node(chip->of_node, np) {
-		if (!of_property_read_bool(np, "gpio-hog"))
-			continue;
 
 		desc = of_parse_own_gpio(np, &name, &lflags, &dflags);
-		if (IS_ERR(desc))
+		if (IS_ERR(desc) || !dflags)
 			continue;
 
-		if (gpiod_hog(desc, name, lflags, dflags))
-			continue;
+		if (of_property_read_bool(np, "gpio-hog"))
+			gpiod_hog(desc, name, lflags, dflags);
+		else if (of_property_read_bool(np, "gpio-initval"))
+			gpiod_initialize(desc, lflags, dflags);
+		else
+			dev_dbg(chip->dev, "GPIO line %d (%s): neither gpio-hog nor gpio-initval found.\n",
+				desc_to_gpio(desc), np->name);
 	}
 }
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a18f00fc1bb8..3b35f2fafeb2 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2329,6 +2329,30 @@ static void gpiochip_free_hogs(struct gpio_chip *chip)
 }
 
 /**
+ * gpiod_initialize - Initialize a GPIO with a given value
+ * @desc:	gpio whose value will be assigned
+ * @lflags:	gpio_lookup_flags - returned from of_find_gpio() or
+ *		of_get_gpio_hog()
+ * @dflags:	gpiod_flags - optional GPIO initialization flags
+ *
+ * This is used to initialize GPIOs that were defined in DT
+ */
+int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags,
+		     enum gpiod_flags dflags)
+{
+	int status;
+
+	status = gpiod_configure_flags(desc, NULL, dflags);
+	if (status < 0) {
+		pr_err("initial setup of GPIO (chip %s, offset %d) failed\n",
+		       gpiod_to_chip(desc)->label, gpio_chip_hwgpio(desc));
+		return status;
+	}
+
+	return 0;
+}
+
+/**
  * gpiod_get_array - obtain multiple GPIOs from a multi-index GPIO function
  * @dev:	GPIO consumer, can be NULL for system-global GPIOs
  * @con_id:	function within the GPIO consumer
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 98ab08c0aa2d..4abf53a5e651 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -107,6 +107,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label);
 void gpiod_free(struct gpio_desc *desc);
 int gpiod_hog(struct gpio_desc *desc, const char *name,
 		unsigned long lflags, enum gpiod_flags dflags);
+int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags,
+		     enum gpiod_flags dflags);
 
 /*
  * Return the GPIO number of the passed descriptor relative to its chip
-- 
2.6.2


  parent reply	other threads:[~2015-11-17 10:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17 10:07 [PATCH v3 0/2] gpiolib: Initializing GPIOs using DT property gpio-initval Markus Pargmann
     [not found] ` <1447754878-21099-1-git-send-email-mpa-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-11-17 10:07   ` [PATCH v3 1/2] dt-bindings: GPIO: Add gpio-initval Markus Pargmann
2015-11-17 20:35     ` Rob Herring
2015-11-18 10:20       ` Linus Walleij
2015-11-17 10:07 ` Markus Pargmann [this message]
2015-11-17 10:21   ` [PATCH v3 2/2] gpiolib: Add GPIO initialization Markus Pargmann
2015-11-29 21:32     ` Linus Walleij

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=1447754878-21099-3-git-send-email-mpa@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=gnurou@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.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).