diff options
| -rw-r--r-- | drivers/of/gpio.c | 9 | ||||
| -rw-r--r-- | include/linux/of_gpio.h | 27 |
2 files changed, 30 insertions, 6 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c index 7e62d15d60f6..e034b38590a8 100644 --- a/drivers/of/gpio.c +++ b/drivers/of/gpio.c | |||
| @@ -78,8 +78,9 @@ err0: | |||
| 78 | EXPORT_SYMBOL(of_get_named_gpio_flags); | 78 | EXPORT_SYMBOL(of_get_named_gpio_flags); |
| 79 | 79 | ||
| 80 | /** | 80 | /** |
| 81 | * of_gpio_count - Count GPIOs for a device | 81 | * of_gpio_named_count - Count GPIOs for a device |
| 82 | * @np: device node to count GPIOs for | 82 | * @np: device node to count GPIOs for |
| 83 | * @propname: property name containing gpio specifier(s) | ||
| 83 | * | 84 | * |
| 84 | * The function returns the count of GPIOs specified for a node. | 85 | * The function returns the count of GPIOs specified for a node. |
| 85 | * | 86 | * |
| @@ -93,14 +94,14 @@ EXPORT_SYMBOL(of_get_named_gpio_flags); | |||
| 93 | * defines four GPIOs (so this function will return 4), two of which | 94 | * defines four GPIOs (so this function will return 4), two of which |
| 94 | * are not specified. | 95 | * are not specified. |
| 95 | */ | 96 | */ |
| 96 | unsigned int of_gpio_count(struct device_node *np) | 97 | unsigned int of_gpio_named_count(struct device_node *np, const char* propname) |
| 97 | { | 98 | { |
| 98 | unsigned int cnt = 0; | 99 | unsigned int cnt = 0; |
| 99 | 100 | ||
| 100 | do { | 101 | do { |
| 101 | int ret; | 102 | int ret; |
| 102 | 103 | ||
| 103 | ret = of_parse_phandle_with_args(np, "gpios", "#gpio-cells", | 104 | ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", |
| 104 | cnt, NULL); | 105 | cnt, NULL); |
| 105 | /* A hole in the gpios = <> counts anyway. */ | 106 | /* A hole in the gpios = <> counts anyway. */ |
| 106 | if (ret < 0 && ret != -EEXIST) | 107 | if (ret < 0 && ret != -EEXIST) |
| @@ -109,7 +110,7 @@ unsigned int of_gpio_count(struct device_node *np) | |||
| 109 | 110 | ||
| 110 | return cnt; | 111 | return cnt; |
| 111 | } | 112 | } |
| 112 | EXPORT_SYMBOL(of_gpio_count); | 113 | EXPORT_SYMBOL(of_gpio_named_count); |
| 113 | 114 | ||
| 114 | /** | 115 | /** |
| 115 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags | 116 | * 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 b254052a49d7..81733d12cbea 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h | |||
| @@ -50,7 +50,8 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) | |||
| 50 | extern int of_get_named_gpio_flags(struct device_node *np, | 50 | extern int of_get_named_gpio_flags(struct device_node *np, |
| 51 | const char *list_name, int index, enum of_gpio_flags *flags); | 51 | const char *list_name, int index, enum of_gpio_flags *flags); |
| 52 | 52 | ||
| 53 | extern unsigned int of_gpio_count(struct device_node *np); | 53 | extern unsigned int of_gpio_named_count(struct device_node *np, |
| 54 | const char* propname); | ||
| 54 | 55 | ||
| 55 | extern int of_mm_gpiochip_add(struct device_node *np, | 56 | extern int of_mm_gpiochip_add(struct device_node *np, |
| 56 | struct of_mm_gpio_chip *mm_gc); | 57 | struct of_mm_gpio_chip *mm_gc); |
| @@ -71,7 +72,8 @@ static inline int of_get_named_gpio_flags(struct device_node *np, | |||
| 71 | return -ENOSYS; | 72 | return -ENOSYS; |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | static inline unsigned int of_gpio_count(struct device_node *np) | 75 | static inline unsigned int of_gpio_named_count(struct device_node *np, |
| 76 | const char* propname) | ||
| 75 | { | 77 | { |
| 76 | return 0; | 78 | return 0; |
| 77 | } | 79 | } |
| @@ -89,6 +91,27 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { } | |||
| 89 | #endif /* CONFIG_OF_GPIO */ | 91 | #endif /* CONFIG_OF_GPIO */ |
| 90 | 92 | ||
| 91 | /** | 93 | /** |
| 94 | * of_gpio_count - Count GPIOs for a device | ||
| 95 | * @np: device node to count GPIOs for | ||
| 96 | * | ||
| 97 | * The function returns the count of GPIOs specified for a node. | ||
| 98 | * | ||
| 99 | * Note that the empty GPIO specifiers counts too. For example, | ||
| 100 | * | ||
| 101 | * gpios = <0 | ||
| 102 | * &pio1 1 2 | ||
| 103 | * 0 | ||
| 104 | * &pio2 3 4>; | ||
| 105 | * | ||
| 106 | * defines four GPIOs (so this function will return 4), two of which | ||
| 107 | * are not specified. | ||
| 108 | */ | ||
| 109 | static inline unsigned int of_gpio_count(struct device_node *np) | ||
| 110 | { | ||
| 111 | return of_gpio_named_count(np, "gpios"); | ||
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 92 | * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API | 115 | * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API |
| 93 | * @np: device node to get GPIO from | 116 | * @np: device node to get GPIO from |
| 94 | * @index: index of the GPIO | 117 | * @index: index of the GPIO |
