From 61bb8bfc7cf12a32d547c0084a2999712bef6443 Mon Sep 17 00:00:00 2001 From: Sebastian Hesselbarth Date: Tue, 2 Jul 2013 20:14:34 +0200 Subject: [PATCH] OF: gpio: convert DT based gpio handling to new OF API This creates a Linux OF API compatible counterpart of of_get_named_gpio_flags. Existing of_get_named_gpio is converted to a static inline function, which is in the corresponding of_gpio.h include. While at it, drivers/of/gpio.c is also renamed to drivers/of/of_gpio.c to follow the of_ prefix naming scheme. The new include is also added to existing users of of_get_named_gpio. Signed-off-by: Sebastian Hesselbarth Signed-off-by: Sascha Hauer --- drivers/of/Makefile | 2 +- drivers/of/gpio.c | 26 ---------------------- drivers/of/of_gpio.c | 52 +++++++++++++++++++++++++++++++++++++++++++ drivers/spi/imx_spi.c | 1 + include/of.h | 3 --- include/of_gpio.h | 44 ++++++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 30 deletions(-) delete mode 100644 drivers/of/gpio.c create mode 100644 drivers/of/of_gpio.c create mode 100644 include/of_gpio.h diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 186074eae..e7d07334b 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,5 +1,5 @@ obj-y += address.o base.o fdt.o platform.o obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o -obj-$(CONFIG_GPIOLIB) += gpio.o +obj-$(CONFIG_GPIOLIB) += of_gpio.o obj-y += partition.o obj-y += of_net.o diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c deleted file mode 100644 index 41e91ec29..000000000 --- a/drivers/of/gpio.c +++ /dev/null @@ -1,26 +0,0 @@ -#define DEBUG - -#include -#include -#include -#include - -int of_get_named_gpio(struct device_node *np, - const char *propname, int index) -{ - int ret; - struct of_phandle_args out_args; - - ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", - index, &out_args); - if (ret) { - pr_debug("%s: can't parse gpios property: %d\n", __func__, ret); - return -EINVAL; - } - - ret = gpio_get_num(out_args.np->device, out_args.args[0]); - if (ret < 0) - return ret; - - return ret; -} diff --git a/drivers/of/of_gpio.c b/drivers/of/of_gpio.c new file mode 100644 index 000000000..3afdf0d09 --- /dev/null +++ b/drivers/of/of_gpio.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +/** + * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API + * @np: device node to get GPIO from + * @propname: property name containing gpio specifier(s) + * @index: index of the GPIO + * @flags: a flags pointer to fill in + * + * Returns GPIO number to use with GPIO API, or one of the errno value on the + * error condition. If @flags is not NULL the function also fills in flags for + * the GPIO. + */ +int of_get_named_gpio_flags(struct device_node *np, const char *propname, + int index, enum of_gpio_flags *flags) +{ + struct of_phandle_args out_args; + struct device_d *dev; + int ret; + + ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", + index, &out_args); + if (ret) { + pr_err("%s: cannot parse %s property: %d\n", + __func__, propname, ret); + return ret; + } + + dev = of_find_device_by_node(out_args.np); + if (!dev) { + pr_err("%s: unable to find device of node %s: %d\n", + __func__, out_args.np->full_name, ret); + return ret; + } + + ret = gpio_get_num(dev, out_args.args[0]); + if (ret < 0) { + pr_err("%s: unable to get gpio num of device %s: %d\n", + __func__, dev_name(dev), ret); + return ret; + } + + if (flags) + *flags = out_args.args[1]; + + return ret; +} +EXPORT_SYMBOL(of_get_named_gpio_flags); diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c index b749337da..6f942bf57 100644 --- a/drivers/spi/imx_spi.c +++ b/drivers/spi/imx_spi.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/include/of.h b/include/of.h index f1f555fcb..f33ed20bb 100644 --- a/include/of.h +++ b/include/of.h @@ -96,9 +96,6 @@ static inline void of_write_number(void *__cell, u64 val, int size) } } -int of_get_named_gpio(struct device_node *np, - const char *propname, int index); - void of_print_property(const void *data, int len); void of_print_cmdline(struct device_node *root); diff --git a/include/of_gpio.h b/include/of_gpio.h new file mode 100644 index 000000000..50536a8a3 --- /dev/null +++ b/include/of_gpio.h @@ -0,0 +1,44 @@ +/* + * OF helpers for the GPIO API + * + * based on Linux OF_GPIO API + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __OF_GPIO_H +#define __OF_GPIO_H + +/* + * This is Linux-specific flags. By default controllers' and Linux' mapping + * match, but GPIO controllers are free to translate their own flags to + * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended. + */ +enum of_gpio_flags { + OF_GPIO_ACTIVE_LOW = 0x1, +}; + +#ifdef CONFIG_OFTREE +extern int of_get_named_gpio_flags(struct device_node *np, + const char *list_name, int index, enum of_gpio_flags *flags); + +#else /* CONFIG_OFTREE */ + +static inline int of_get_named_gpio_flags(struct device_node *np, + const char *list_name, int index, enum of_gpio_flags *flags) +{ + return -ENOSYS; +} + +#endif /* CONFIG_OFTREE */ + +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); +} + +#endif