gpio: Make of_count_named_gpios() use new of_count_phandle_with_args()

This patch replaces the horribly coded of_count_named_gpios() with a
call to of_count_phandle_with_args() which is far more efficient. This
also changes the return value of of_gpio_count() & of_gpio_named_count()
from 'unsigned int' to 'int' so that it can return an error code. All
the users of that function are fixed up to correctly handle a negative
return value.

v2: Split GPIO portion into a separate patch

Tested-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
This commit is contained in:
Grant Likely 2013-02-12 17:48:37 +00:00
parent bd69f73f2c
commit e80beb27d2
9 changed files with 41 additions and 71 deletions

View file

@ -50,9 +50,6 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
extern int of_get_named_gpio_flags(struct device_node *np,
const char *list_name, int index, enum of_gpio_flags *flags);
extern unsigned int of_gpio_named_count(struct device_node *np,
const char* propname);
extern int of_mm_gpiochip_add(struct device_node *np,
struct of_mm_gpio_chip *mm_gc);
@ -71,12 +68,6 @@ static inline int of_get_named_gpio_flags(struct device_node *np,
return -ENOSYS;
}
static inline unsigned int of_gpio_named_count(struct device_node *np,
const char* propname)
{
return 0;
}
static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec,
u32 *flags)
@ -90,22 +81,37 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
#endif /* CONFIG_OF_GPIO */
/**
* of_gpio_count - Count GPIOs for a device
* of_gpio_named_count() - Count GPIOs for a device
* @np: device node to count GPIOs for
* @propname: property name containing gpio specifier(s)
*
* The function returns the count of GPIOs specified for a node.
* Note that the empty GPIO specifiers count too. Returns either
* Number of gpios defined in property,
* -EINVAL for an incorrectly formed gpios property, or
* -ENOENT for a missing gpios property
*
* Note that the empty GPIO specifiers counts too. For example,
*
* Example:
* gpios = <0
* &pio1 1 2
* &gpio1 1 2
* 0
* &pio2 3 4>;
* &gpio2 3 4>;
*
* defines four GPIOs (so this function will return 4), two of which
* are not specified.
* The above example defines four GPIOs, two of which are not specified.
* This function will return '4'
*/
static inline unsigned int of_gpio_count(struct device_node *np)
static inline int of_gpio_named_count(struct device_node *np, const char* propname)
{
return of_count_phandle_with_args(np, propname, "#gpio-cells");
}
/**
* of_gpio_count() - Count GPIOs for a device
* @np: device node to count GPIOs for
*
* Same as of_gpio_named_count, but hard coded to use the 'gpios' property
*/
static inline int of_gpio_count(struct device_node *np)
{
return of_gpio_named_count(np, "gpios");
}