Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
From: Furquan Shaikh <furquan@chromium.org>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Tony Lindgren <tony@atomide.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Len Brown <lenb@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Hanjun Guo <hanjun.guo@linaro.org>,
	Will Deacon <will.deacon@arm.com>, Rob Herring <robh@kernel.org>,
	Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Adam Thomson <Adam.Thomson.Opensource@diasemi.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	Furquan Shaikh <furquan@chromium.org>, Dmitry Torokhov <dtor@>
Subject: [PATCH 6/7] drivers/gpio: Add and export gpiod_lookup[_index]
Date: Tue, 24 Jan 2017 16:06:40 -0800	[thread overview]
Message-ID: <20170125000641.25520-7-furquan@chromium.org> (raw)
In-Reply-To: <20170125000641.25520-1-furquan@chromium.org>

Sometimes (as the case with fixed regulator) we only want to look up,
but not necessarily reserve right away, GPIO. gpiod_lookup() and
gpiod_lookup_by_index() allow us doing just that.

Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
---
 drivers/gpio/gpiolib.c        | 75 ++++++++++++++++++++++++++++++++++---------
 include/linux/gpio/consumer.h | 21 ++++++++++++
 2 files changed, 80 insertions(+), 16 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a07ae9e37930..7f8ac6c229e8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3165,6 +3165,22 @@ int gpiod_count(struct device *dev, const char *con_id)
 EXPORT_SYMBOL_GPL(gpiod_count);
 
 /**
+ * gpiod_lookup - look up a GPIO for a given GPIO function
+ * @dev:	GPIO consumer, can be NULL for system-global GPIOs
+ * @con_id:	function within the GPIO consumer
+ *
+ * Return the GPIO descriptor corresponding to the function con_id of device
+ * dev, -ENOENT if no GPIO has been assigned to the requested function, or
+ * another IS_ERR() code.
+ */
+struct gpio_desc *__must_check gpiod_lookup(struct device *dev,
+					    const char *con_id)
+{
+	return gpiod_lookup_index(dev, con_id, 0);
+}
+EXPORT_SYMBOL_GPL(gpiod_lookup);
+
+/**
  * gpiod_get - obtain a GPIO for a given GPIO function
  * @dev:	GPIO consumer, can be NULL for system-global GPIOs
  * @con_id:	function within the GPIO consumer
@@ -3241,26 +3257,19 @@ static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
 }
 
 /**
- * gpiod_get_index - obtain a GPIO from a multi-index GPIO function
+ * gpiod_lookup_index - look up a GPIO from a multi-index GPIO function
  * @dev:	GPIO consumer, can be NULL for system-global GPIOs
  * @con_id:	function within the GPIO consumer
  * @idx:	index of the GPIO to obtain in the consumer
- * @flags:	optional GPIO initialization flags
- *
- * This variant of gpiod_get() allows to access GPIOs other than the first
- * defined one for functions that define several GPIOs.
  *
- * Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the
- * requested function and/or index, or another IS_ERR() code if an error
- * occurred while trying to acquire the GPIO.
+ * Return a valid GPIO descriptor, or -ENOENT if no GPIO has been assigned to
+ * the requested function and/or index, or another IS_ERR() code.
  */
-struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
-					       const char *con_id,
-					       unsigned int idx,
-					       enum gpiod_flags flags)
+struct gpio_desc *__must_check gpiod_lookup_index(struct device *dev,
+						  const char *con_id,
+						  unsigned int idx)
 {
 	struct gpio_desc *desc = NULL;
-	int status;
 	enum gpio_lookup_flags lookupflags = 0;
 
 	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
@@ -3285,16 +3294,50 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 		desc = gpiod_find(dev, con_id, idx, &lookupflags);
 	}
 
-	if (IS_ERR(desc)) {
+	if (IS_ERR(desc))
 		dev_dbg(dev, "lookup for GPIO %s failed\n", con_id);
+
+	/*
+	 * Configure static flags based on lookup data (such as
+	 * "active low", "open drain", etc.)
+	 */
+	gpiod_configure_flags(desc, con_id, lookupflags, 0);
+
+	return desc;
+}
+EXPORT_SYMBOL_GPL(gpiod_lookup_index);
+
+/**
+ * gpiod_get_index - obtain a GPIO from a multi-index GPIO function
+ * @dev:	GPIO consumer, can be NULL for system-global GPIOs
+ * @con_id:	function within the GPIO consumer
+ * @idx:	index of the GPIO to obtain in the consumer
+ * @flags:	optional GPIO initialization flags
+ *
+ * This variant of gpiod_get() allows to access GPIOs other than the first
+ * defined one for functions that define several GPIOs.
+ *
+ * Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the
+ * requested function and/or index, or another IS_ERR() code if an error
+ * occurred while trying to acquire the GPIO.
+ */
+struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
+					       const char *con_id,
+					       unsigned int idx,
+					       enum gpiod_flags flags)
+{
+	struct gpio_desc *desc;
+	int status;
+
+	desc = gpiod_lookup_index(dev, con_id, idx);
+	if (IS_ERR(desc))
 		return desc;
-	}
 
 	status = gpiod_request(desc, con_id);
 	if (status < 0)
 		return ERR_PTR(status);
 
-	status = gpiod_configure_flags(desc, con_id, lookupflags, flags);
+	status = gpiod_configure_flags(desc, con_id, 0, flags);
 	if (status < 0) {
 		dev_dbg(dev, "setup of GPIO %s failed\n", con_id);
 		gpiod_put(desc);
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index fb0fde686cb1..8fcb638f5568 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -46,6 +46,13 @@ enum gpiod_flags {
 /* Return the number of GPIOs associated with a device / function */
 int gpiod_count(struct device *dev, const char *con_id);
 
+/* Look up GPIOs */
+struct gpio_desc *__must_check gpiod_lookup(struct device *dev,
+					    const char *con_id);
+struct gpio_desc *__must_check gpiod_lookup_index(struct device *dev,
+						  const char *con_id,
+						  unsigned int idx);
+
 /* Acquire and dispose GPIOs */
 struct gpio_desc *__must_check gpiod_get(struct device *dev,
 					 const char *con_id,
@@ -146,6 +153,20 @@ static inline int gpiod_count(struct device *dev, const char *con_id)
 	return 0;
 }
 
+static inline struct gpio_desc *__must_check gpiod_lookup(struct device *dev,
+							  const char *con_id)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+static inline struct gpio_desc *__must_check
+gpiod_lookup_index(struct device *dev,
+		   const char *con_id,
+		   unsigned int idx)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
 						       const char *con_id,
 						       enum gpiod_flags flags)
-- 
2.11.0.483.g087da7b7c-goog


  parent reply	other threads:[~2017-01-25  0:06 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25  0:06 [PATCH 0/7] Implement generic regulator constraints parsing for ACPI and OF Furquan Shaikh
2017-01-25  0:06 ` [PATCH 1/7] drivers/regulator: Rename of_map_mode to map_mode in regulator desc Furquan Shaikh
2017-01-25  0:06 ` [PATCH 2/7] ACPI / property: have acpi_get_next_subnode take fwnode_handle Furquan Shaikh
2017-01-25 11:00   ` kbuild test robot
2017-01-25  0:06 ` [PATCH 3/7] device property: introduce fwnode_for_each_child() Furquan Shaikh
2017-01-25  0:06 ` [PATCH 4/7] device property: introduce fwnode_get_named_child_node() Furquan Shaikh
2017-01-25  0:06 ` [PATCH 5/7] device property: Export dev_fwnode Furquan Shaikh
2017-01-25  0:06 ` Furquan Shaikh [this message]
2017-01-25 11:18   ` [PATCH 6/7] drivers/gpio: Add and export gpiod_lookup[_index] kbuild test robot
2017-01-26 15:24   ` Linus Walleij
2017-01-25  0:06 ` [PATCH 7/7] drivers/regulator: Initialize regulator init data for ACPI regulators Furquan Shaikh
2017-01-25 12:29 ` [PATCH 0/7] Implement generic regulator constraints parsing for ACPI and OF Lorenzo Pieralisi
2017-01-25 12:49 ` Mark Brown
2017-01-25 12:55   ` Rafael J. Wysocki
2017-01-25 16:56     ` Furquan Shaikh
2017-01-25 18:23       ` Mark Rutland
2017-01-25 18:29         ` Mark Brown
2017-01-25 18:34           ` Mark Rutland
2017-01-25 18:49             ` Mark Brown
2017-01-25 19:39               ` Mark Rutland
2017-01-25 18:44           ` Dmitry Torokhov
2017-01-25 19:27             ` Dmitry Torokhov
2017-01-25 20:39               ` Mark Brown
2017-01-25 21:17                 ` Dmitry Torokhov
2017-01-25 21:30                   ` Mark Brown
2017-01-25 22:05                     ` Dmitry Torokhov
2017-01-25 22:25                       ` Mark Brown
2017-01-25 21:44               ` Al Stone
2017-01-25 23:27                 ` Dmitry Torokhov
2017-01-26  0:15                   ` Al Stone
2017-01-26  0:33                     ` Dmitry Torokhov
2017-01-26 10:35                       ` Rafael J. Wysocki
2017-02-04 16:08                         ` Mark Brown
2017-01-25 19:21           ` Lorenzo Pieralisi
2017-01-25 20:40             ` Mark Brown
2017-01-25 18:25       ` Mark Brown

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=20170125000641.25520-7-furquan@chromium.org \
    --to=furquan@chromium.org \
    --cc=Adam.Thomson.Opensource@diasemi.com \
    --cc=broonie@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gnurou@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hanjun.guo@linaro.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh@kernel.org \
    --cc=sathyanarayana.nujella@intel.com \
    --cc=tony@atomide.com \
    --cc=will.deacon@arm.com \
    /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