diff options
author | Antony Pavlov <antonynpavlov@gmail.com> | 2014-06-24 01:21:11 +0400 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-06-25 08:34:48 +0200 |
commit | 3ad9434f2faed97331670de1f5a6317df8c493b5 (patch) | |
tree | b2a9c6686b01d1a756389f53610534e6b57463bf /include/of_gpio.h | |
parent | f21744fba3eebb3eb90954c7397226047ecd0d98 (diff) | |
download | barebox-3ad9434f2faed97331670de1f5a6317df8c493b5.tar.gz barebox-3ad9434f2faed97331670de1f5a6317df8c493b5.tar.xz |
i2c: i2c_gpio: add devicetree support
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/of_gpio.h')
-rw-r--r-- | include/of_gpio.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/of_gpio.h b/include/of_gpio.h index d42b18e63f..95a454c683 100644 --- a/include/of_gpio.h +++ b/include/of_gpio.h @@ -35,10 +35,65 @@ static inline int of_get_named_gpio_flags(struct device_node *np, #endif /* CONFIG_OF_GPIO */ +/** + * 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 + * + * Example: + * gpios = <0 + * &gpio1 1 2 + * 0 + * &gpio2 3 4>; + * + * The above example defines four GPIOs, two of which are not specified. + * This function will return '4' + */ +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"); +} + +static inline int of_get_gpio_flags(struct device_node *np, int index, + enum of_gpio_flags *flags) +{ + return of_get_named_gpio_flags(np, "gpios", index, flags); +} + static inline int of_get_named_gpio(struct device_node *np, const char *list_name, int index) { return of_get_named_gpio_flags(np, list_name, index, NULL); } +/** + * of_get_gpio() - Get a GPIO number to use with GPIO API + * @np: device node to get GPIO from + * @index: index of the GPIO + * + * Returns GPIO number to use with Linux generic GPIO API, or one of the errno + * value on the error condition. + */ +static inline int of_get_gpio(struct device_node *np, int index) +{ + return of_get_gpio_flags(np, index, NULL); +} + #endif |