mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Moffett <Kyle.D.Moffett@boeing.com>
To: linux-kernel@vger.kernel.org
Cc: Grant Likely <grant.likely@secretlab.ca>,
	Linus Walleij <linus.walleij@linaro.org>,
	devicetree-discuss@lists.ozlabs.org,
	Kyle Moffett <Kyle.D.Moffett@boeing.com>,
	Rob Herring <rob.herring@calxeda.com>
Subject: [REPOST RFC PATCH 1/3] of_gpio: Extend of_gpio_count() to support other property names
Date: Tue, 13 Dec 2011 13:23:32 -0500	[thread overview]
Message-ID: <1323800614-12642-2-git-send-email-Kyle.D.Moffett@boeing.com> (raw)
In-Reply-To: <1323800614-12642-1-git-send-email-Kyle.D.Moffett@boeing.com>

The of_get_named_gpio_flags() function allows the caller to specify the
property name which should be read for a list of GPIOs.

Unfortunately there is no easy way to *count* the number of GPIOs listed
in an arbitrary property.

To resolve this, rename of_gpio_count() to of_gpio_count_named() and add
a new "propname" parameter.

Also add a static inline replacement for of_gpio_count() which calls
of_gpio_count_named() with "gpios" to avoid breaking existing users.

Signed-off-by: Kyle Moffett <Kyle.D.Moffett@boeing.com>
---
 drivers/of/gpio.c       |   13 ++++++-------
 include/linux/of_gpio.h |   27 +++++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index ef0105f..f349aaf 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -83,8 +83,9 @@ err0:
 EXPORT_SYMBOL(of_get_named_gpio_flags);
 
 /**
- * of_gpio_count - Count GPIOs for a device
+ * of_gpio_count_named - Count GPIOs for a device
  * @np:		device node to count GPIOs for
+ * @propname:	property name containing gpio specifier(s)
  *
  * The function returns the count of GPIOs specified for a node.
  *
@@ -98,15 +99,13 @@ EXPORT_SYMBOL(of_get_named_gpio_flags);
  * defines four GPIOs (so this function will return 4), two of which
  * are not specified.
  */
-unsigned int of_gpio_count(struct device_node *np)
+unsigned int of_gpio_count_named(struct device_node *np, const char *propname)
 {
 	unsigned int cnt = 0;
 
 	do {
-		int ret;
-
-		ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells",
-						  cnt, NULL, NULL);
+		int ret = of_parse_phandles_with_args(np, propname,
+				"#gpio-cells", cnt, NULL, NULL);
 		/* A hole in the gpios = <> counts anyway. */
 		if (ret < 0 && ret != -EEXIST)
 			break;
@@ -114,7 +113,7 @@ unsigned int of_gpio_count(struct device_node *np)
 
 	return cnt;
 }
-EXPORT_SYMBOL(of_gpio_count);
+EXPORT_SYMBOL(of_gpio_count_named);
 
 /**
  * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 52280a2..1411a06 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -49,7 +49,8 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
 extern int of_get_named_gpio_flags(struct device_node *np,
 		const char *list_name, int index, enum of_gpio_flags *flags);
 
-extern unsigned int of_gpio_count(struct device_node *np);
+extern unsigned int of_gpio_count_named(struct device_node *np,
+		const char *propname);
 
 extern int of_mm_gpiochip_add(struct device_node *np,
 			      struct of_mm_gpio_chip *mm_gc);
@@ -69,7 +70,8 @@ static inline int of_get_named_gpio_flags(struct device_node *np,
 	return -ENOSYS;
 }
 
-static inline unsigned int of_gpio_count(struct device_node *np)
+static inline unsigned int of_gpio_count_named(struct device_node *np,
+		const char *propname)
 {
 	return 0;
 }
@@ -87,6 +89,27 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
 #endif /* CONFIG_OF_GPIO */
 
 /**
+ * of_gpio_count - Count GPIOs for a device
+ * @np:		device node to count GPIOs for
+ *
+ * The function returns the count of GPIOs specified for a node.
+ *
+ * Note that the empty GPIO specifiers counts too. For example,
+ *
+ * gpios = <0
+ *          &pio1 1 2
+ *          0
+ *          &pio2 3 4>;
+ *
+ * defines four GPIOs (so this function will return 4), two of which
+ * are not specified.
+ */
+static inline unsigned int of_gpio_count(struct device_node *np)
+{
+	return of_gpio_count_named(np, "gpios");
+}
+
+/**
  * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API
  * @np:		device node to get GPIO from
  * @index:	index of the GPIO
-- 
1.7.7.3


  reply	other threads:[~2011-12-13 18:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13 18:23 [REPOST RFC PATCH 0/3] New "gpio-poweroff" driver to turn off platform devices with GPIOs Kyle Moffett
2011-12-13 18:23 ` Kyle Moffett [this message]
2011-12-13 18:23 ` [REPOST RFC PATCH 2/3] of_gpio: Add new helpers for easily requesting lots of GPIOs Kyle Moffett
2012-01-04 18:49   ` Grant Likely
2011-12-13 18:23 ` [REPOST RFC PATCH 3/3] New "gpio-poweroff" driver to turn off platform devices with GPIOs Kyle Moffett
2011-12-13 19:10 ` [REPOST RFC PATCH 0/3] " Rob Herring
2011-12-13 20:44   ` Moffett, Kyle D
2011-12-14 12:02     ` Mark Brown
2011-12-14 20:34       ` Moffett, Kyle D
2011-12-17  9:20         ` Mark Brown
2011-12-19 16:56           ` Moffett, Kyle D
2011-12-20  1:38             ` Mark Brown
2011-12-20  1:53               ` Moffett, Kyle D
2011-12-20 14:38                 ` Mark Brown
2011-12-14 11:59 ` 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=1323800614-12642-2-git-send-email-Kyle.D.Moffett@boeing.com \
    --to=kyle.d.moffett@boeing.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.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

all inboxes | Powered by JetHome®