diff options
-rw-r--r-- | drivers/of/gpio.c | 34 | ||||
-rw-r--r-- | include/linux/of_gpio.h | 6 |
2 files changed, 40 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: | |||
80 | EXPORT_SYMBOL(of_get_gpio_flags); | 80 | EXPORT_SYMBOL(of_get_gpio_flags); |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * of_gpio_count - Count GPIOs for a device | ||
84 | * @np: device node to count GPIOs for | ||
85 | * | ||
86 | * The function returns the count of GPIOs specified for a node. | ||
87 | * | ||
88 | * Note that the empty GPIO specifiers counts too. For example, | ||
89 | * | ||
90 | * gpios = <0 | ||
91 | * &pio1 1 2 | ||
92 | * 0 | ||
93 | * &pio2 3 4>; | ||
94 | * | ||
95 | * defines four GPIOs (so this function will return 4), two of which | ||
96 | * are not specified. | ||
97 | */ | ||
98 | unsigned int of_gpio_count(struct device_node *np) | ||
99 | { | ||
100 | unsigned int cnt = 0; | ||
101 | |||
102 | do { | ||
103 | int ret; | ||
104 | |||
105 | ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", | ||
106 | cnt, NULL, NULL); | ||
107 | /* A hole in the gpios = <> counts anyway. */ | ||
108 | if (ret < 0 && ret != -EEXIST) | ||
109 | break; | ||
110 | } while (++cnt); | ||
111 | |||
112 | return cnt; | ||
113 | } | ||
114 | EXPORT_SYMBOL(of_gpio_count); | ||
115 | |||
116 | /** | ||
83 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags | 117 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags |
84 | * @of_gc: pointer to the of_gpio_chip structure | 118 | * @of_gc: pointer to the of_gpio_chip structure |
85 | * @np: device node of the GPIO chip | 119 | * @np: device node of the GPIO chip |
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index e25abf610cb6..fc2472c3c254 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h | |||
@@ -65,6 +65,7 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) | |||
65 | 65 | ||
66 | extern int of_get_gpio_flags(struct device_node *np, int index, | 66 | extern int of_get_gpio_flags(struct device_node *np, int index, |
67 | enum of_gpio_flags *flags); | 67 | enum of_gpio_flags *flags); |
68 | extern unsigned int of_gpio_count(struct device_node *np); | ||
68 | 69 | ||
69 | extern int of_mm_gpiochip_add(struct device_node *np, | 70 | extern int of_mm_gpiochip_add(struct device_node *np, |
70 | struct of_mm_gpio_chip *mm_gc); | 71 | struct of_mm_gpio_chip *mm_gc); |
@@ -81,6 +82,11 @@ static inline int of_get_gpio_flags(struct device_node *np, int index, | |||
81 | return -ENOSYS; | 82 | return -ENOSYS; |
82 | } | 83 | } |
83 | 84 | ||
85 | static inline unsigned int of_gpio_count(struct device_node *np) | ||
86 | { | ||
87 | return 0; | ||
88 | } | ||
89 | |||
84 | #endif /* CONFIG_OF_GPIO */ | 90 | #endif /* CONFIG_OF_GPIO */ |
85 | 91 | ||
86 | /** | 92 | /** |