summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib-of.c
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-10-17 13:21:37 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-10-19 17:24:52 -0400
commitaf8b6375a8291fe2cf77707f3edec86b98a999cc (patch)
tree2e4970d4e726411586dbc2143f27ba49ff50142e /drivers/gpio/gpiolib-of.c
parent79a9becda8940deb2274b5aa4577c86d52ee7ecb (diff)
gpiolib: port of_ functions to use gpiod
Refactor the of_ functions of gpiolib to use the now public gpiod interface, and export of_get_named_gpiod_flags() and of_get_gpiod_flags() functions. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-of.c')
-rw-r--r--drivers/gpio/gpiolib-of.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 0dfaf20e4dad..32a396d891be 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -15,19 +15,21 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/gpio.h> 18#include <linux/gpio/consumer.h>
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/of_address.h> 20#include <linux/of_address.h>
21#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/pinctrl/pinctrl.h> 22#include <linux/pinctrl/pinctrl.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24 24
25struct gpio_desc;
26
25/* Private data structure for of_gpiochip_find_and_xlate */ 27/* Private data structure for of_gpiochip_find_and_xlate */
26struct gg_data { 28struct gg_data {
27 enum of_gpio_flags *flags; 29 enum of_gpio_flags *flags;
28 struct of_phandle_args gpiospec; 30 struct of_phandle_args gpiospec;
29 31
30 int out_gpio; 32 struct gpio_desc *out_gpio;
31}; 33};
32 34
33/* Private function for resolving node pointer to gpio_chip */ 35/* Private function for resolving node pointer to gpio_chip */
@@ -45,28 +47,31 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
45 if (ret < 0) 47 if (ret < 0)
46 return false; 48 return false;
47 49
48 gg_data->out_gpio = ret + gc->base; 50 gg_data->out_gpio = gpio_to_desc(ret + gc->base);
49 return true; 51 return true;
50} 52}
51 53
52/** 54/**
53 * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API 55 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
54 * @np: device node to get GPIO from 56 * @np: device node to get GPIO from
55 * @propname: property name containing gpio specifier(s) 57 * @propname: property name containing gpio specifier(s)
56 * @index: index of the GPIO 58 * @index: index of the GPIO
57 * @flags: a flags pointer to fill in 59 * @flags: a flags pointer to fill in
58 * 60 *
59 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 61 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
60 * value on the error condition. If @flags is not NULL the function also fills 62 * value on the error condition. If @flags is not NULL the function also fills
61 * in flags for the GPIO. 63 * in flags for the GPIO.
62 */ 64 */
63int of_get_named_gpio_flags(struct device_node *np, const char *propname, 65struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
64 int index, enum of_gpio_flags *flags) 66 const char *propname, int index, enum of_gpio_flags *flags)
65{ 67{
66 /* Return -EPROBE_DEFER to support probe() functions to be called 68 /* Return -EPROBE_DEFER to support probe() functions to be called
67 * later when the GPIO actually becomes available 69 * later when the GPIO actually becomes available
68 */ 70 */
69 struct gg_data gg_data = { .flags = flags, .out_gpio = -EPROBE_DEFER }; 71 struct gg_data gg_data = {
72 .flags = flags,
73 .out_gpio = ERR_PTR(-EPROBE_DEFER)
74 };
70 int ret; 75 int ret;
71 76
72 /* .of_xlate might decide to not fill in the flags, so clear it. */ 77 /* .of_xlate might decide to not fill in the flags, so clear it. */
@@ -78,16 +83,17 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
78 if (ret) { 83 if (ret) {
79 pr_debug("%s: can't parse gpios property of node '%s[%d]'\n", 84 pr_debug("%s: can't parse gpios property of node '%s[%d]'\n",
80 __func__, np->full_name, index); 85 __func__, np->full_name, index);
81 return ret; 86 return ERR_PTR(ret);
82 } 87 }
83 88
84 gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); 89 gpiochip_find(&gg_data, of_gpiochip_find_and_xlate);
85 90
86 of_node_put(gg_data.gpiospec.np); 91 of_node_put(gg_data.gpiospec.np);
87 pr_debug("%s exited with status %d\n", __func__, gg_data.out_gpio); 92 pr_debug("%s exited with status %d\n", __func__,
93 PTR_RET(gg_data.out_gpio));
88 return gg_data.out_gpio; 94 return gg_data.out_gpio;
89} 95}
90EXPORT_SYMBOL(of_get_named_gpio_flags); 96EXPORT_SYMBOL(of_get_named_gpiod_flags);
91 97
92/** 98/**
93 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 99 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags