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:
@@ -88,41 +88,6 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
|
||||
}
|
||||
EXPORT_SYMBOL(of_get_named_gpio_flags);
|
||||
|
||||
/**
|
||||
* 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 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_named_count(struct device_node *np, const char* propname)
|
||||
{
|
||||
unsigned int cnt = 0;
|
||||
|
||||
do {
|
||||
int ret;
|
||||
|
||||
ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
|
||||
cnt, NULL);
|
||||
/* A hole in the gpios = <> counts anyway. */
|
||||
if (ret < 0 && ret != -EEXIST)
|
||||
break;
|
||||
} while (++cnt);
|
||||
|
||||
return cnt;
|
||||
}
|
||||
EXPORT_SYMBOL(of_gpio_named_count);
|
||||
|
||||
/**
|
||||
* of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
|
||||
* @gc: pointer to the gpio_chip structure
|
||||
|
Reference in New Issue
Block a user