summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2008-12-05 08:15:54 +0000
committerPaul Mackerras <paulus@samba.org>2008-12-21 14:21:14 +1100
commit749820928a2fd47ff536773d869d2c3f8038b7d1 (patch)
tree69f7f37a63f9c194f33fb7a16d12f62b583da6c8 /drivers/of
parent7736a3db98bed028d0e5235f8958a730acfd822e (diff)
of/gpio: Implement of_gpio_count()
This function is used to count how many GPIOs are specified for a device node. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/gpio.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index a4ba217116eb..6eea601a9204 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -80,6 +80,40 @@ err0:
EXPORT_SYMBOL(of_get_gpio_flags);
/**
+ * 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.
+ */
+unsigned int of_gpio_count(struct device_node *np)
+{
+ unsigned int cnt = 0;
+
+ do {
+ int ret;
+
+ ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells",
+ cnt, NULL, NULL);
+ /* A hole in the gpios = <> counts anyway. */
+ if (ret < 0 && ret != -EEXIST)
+ break;
+ } while (++cnt);
+
+ return cnt;
+}
+EXPORT_SYMBOL(of_gpio_count);
+
+/**
* of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
* @of_gc: pointer to the of_gpio_chip structure
* @np: device node of the GPIO chip