aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Bonesio <bones@secretlab.ca>2011-06-27 19:49:57 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-06-28 17:39:50 -0400
commita6b0919140b49e0871584362ae0cf1d18c476058 (patch)
tree9e9052104053a155ab8ca69ccadd581e9f8eede6
parentbf859f84a19f8e562af4a990a287b5e3edabc572 (diff)
of/gpio: Add new method for getting gpios under different property names
This patch adds a new routine, of_get_named_gpio_flags(), which takes the property name as a parameter rather than assuming "gpios". of_get_gpio_flags() is modified to call of_get_named_gpio_flags() with "gpios" as the property parameter. Signed-off-by: John Bonesio <bones@secretlab.ca> [grant.likely: Tidied up whitespace and tweaked kerneldoc comments.] Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
-rw-r--r--drivers/of/gpio.c11
-rw-r--r--include/linux/of_gpio.h42
2 files changed, 43 insertions, 10 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 905960338fb2..3007662ac614 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -21,8 +21,9 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22 22
23/** 23/**
24 * of_get_gpio_flags - Get a GPIO number and flags to use with GPIO API 24 * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API
25 * @np: device node to get GPIO from 25 * @np: device node to get GPIO from
26 * @propname: property name containing gpio specifier(s)
26 * @index: index of the GPIO 27 * @index: index of the GPIO
27 * @flags: a flags pointer to fill in 28 * @flags: a flags pointer to fill in
28 * 29 *
@@ -30,8 +31,8 @@
30 * value on the error condition. If @flags is not NULL the function also fills 31 * value on the error condition. If @flags is not NULL the function also fills
31 * in flags for the GPIO. 32 * in flags for the GPIO.
32 */ 33 */
33int of_get_gpio_flags(struct device_node *np, int index, 34int of_get_named_gpio_flags(struct device_node *np, const char *propname,
34 enum of_gpio_flags *flags) 35 int index, enum of_gpio_flags *flags)
35{ 36{
36 int ret; 37 int ret;
37 struct device_node *gpio_np; 38 struct device_node *gpio_np;
@@ -40,7 +41,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
40 const void *gpio_spec; 41 const void *gpio_spec;
41 const __be32 *gpio_cells; 42 const __be32 *gpio_cells;
42 43
43 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, 44 ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
44 &gpio_np, &gpio_spec); 45 &gpio_np, &gpio_spec);
45 if (ret) { 46 if (ret) {
46 pr_debug("%s: can't parse gpios property\n", __func__); 47 pr_debug("%s: can't parse gpios property\n", __func__);
@@ -79,7 +80,7 @@ err0:
79 pr_debug("%s exited with status %d\n", __func__, ret); 80 pr_debug("%s exited with status %d\n", __func__, ret);
80 return ret; 81 return ret;
81} 82}
82EXPORT_SYMBOL(of_get_gpio_flags); 83EXPORT_SYMBOL(of_get_named_gpio_flags);
83 84
84/** 85/**
85 * of_gpio_count - Count GPIOs for a device 86 * of_gpio_count - Count GPIOs for a device
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 6598c04dab01..aec8025c786a 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -46,8 +46,9 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
46 return container_of(gc, struct of_mm_gpio_chip, gc); 46 return container_of(gc, struct of_mm_gpio_chip, gc);
47} 47}
48 48
49extern int of_get_gpio_flags(struct device_node *np, int index, 49extern int of_get_named_gpio_flags(struct device_node *np,
50 enum of_gpio_flags *flags); 50 const char *list_name, int index, enum of_gpio_flags *flags);
51
51extern unsigned int of_gpio_count(struct device_node *np); 52extern unsigned int of_gpio_count(struct device_node *np);
52 53
53extern int of_mm_gpiochip_add(struct device_node *np, 54extern int of_mm_gpiochip_add(struct device_node *np,
@@ -60,8 +61,8 @@ extern struct gpio_chip *of_node_to_gpiochip(struct device_node *np);
60#else /* CONFIG_OF_GPIO */ 61#else /* CONFIG_OF_GPIO */
61 62
62/* Drivers may not strictly depend on the GPIO support, so let them link. */ 63/* Drivers may not strictly depend on the GPIO support, so let them link. */
63static inline int of_get_gpio_flags(struct device_node *np, int index, 64static inline int of_get_named_gpio_flags(struct device_node *np,
64 enum of_gpio_flags *flags) 65 const char *list_name, int index, enum of_gpio_flags *flags)
65{ 66{
66 return -ENOSYS; 67 return -ENOSYS;
67} 68}
@@ -77,7 +78,38 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
77#endif /* CONFIG_OF_GPIO */ 78#endif /* CONFIG_OF_GPIO */
78 79
79/** 80/**
80 * of_get_gpio - Get a GPIO number to use with GPIO API 81 * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API
82 * @np: device node to get GPIO from
83 * @index: index of the GPIO
84 * @flags: a flags pointer to fill in
85 *
86 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
87 * value on the error condition. If @flags is not NULL the function also fills
88 * in flags for the GPIO.
89 */
90static inline int of_get_gpio_flags(struct device_node *np, int index,
91 enum of_gpio_flags *flags)
92{
93 return of_get_named_gpio_flags(np, "gpios", index, flags);
94}
95
96/**
97 * of_get_named_gpio() - Get a GPIO number to use with GPIO API
98 * @np: device node to get GPIO from
99 * @propname: Name of property containing gpio specifier(s)
100 * @index: index of the GPIO
101 *
102 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
103 * value on the error condition.
104 */
105static inline int of_get_named_gpio(struct device_node *np,
106 const char *propname, int index)
107{
108 return of_get_named_gpio_flags(np, propname, index, NULL);
109}
110
111/**
112 * of_get_gpio() - Get a GPIO number to use with GPIO API
81 * @np: device node to get GPIO from 113 * @np: device node to get GPIO from
82 * @index: index of the GPIO 114 * @index: index of the GPIO
83 * 115 *