Skip to content

Commit

Permalink
of/gpio: Implement of_gpio_count()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Anton Vorontsov authored and Paul Mackerras committed Dec 21, 2008
1 parent 7736a3d commit 7498209
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions drivers/of/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ int of_get_gpio_flags(struct device_node *np, int index,
}
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
Expand Down
6 changes: 6 additions & 0 deletions include/linux/of_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)

extern int of_get_gpio_flags(struct device_node *np, int index,
enum of_gpio_flags *flags);
extern unsigned int of_gpio_count(struct device_node *np);

extern int of_mm_gpiochip_add(struct device_node *np,
struct of_mm_gpio_chip *mm_gc);
Expand All @@ -81,6 +82,11 @@ static inline int of_get_gpio_flags(struct device_node *np, int index,
return -ENOSYS;
}

static inline unsigned int of_gpio_count(struct device_node *np)
{
return 0;
}

#endif /* CONFIG_OF_GPIO */

/**
Expand Down

0 comments on commit 7498209

Please sign in to comment.