diff options
author | Alexandre Courbot <acourbot@nvidia.com> | 2013-10-17 13:21:37 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-10-19 17:24:52 -0400 |
commit | af8b6375a8291fe2cf77707f3edec86b98a999cc (patch) | |
tree | 2e4970d4e726411586dbc2143f27ba49ff50142e | |
parent | 79a9becda8940deb2274b5aa4577c86d52ee7ecb (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>
-rw-r--r-- | drivers/gpio/gpiolib-of.c | 28 | ||||
-rw-r--r-- | include/linux/of_gpio.h | 29 |
2 files changed, 41 insertions, 16 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 | ||
25 | struct gpio_desc; | ||
26 | |||
25 | /* Private data structure for of_gpiochip_find_and_xlate */ | 27 | /* Private data structure for of_gpiochip_find_and_xlate */ |
26 | struct gg_data { | 28 | struct 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 | */ |
63 | int of_get_named_gpio_flags(struct device_node *np, const char *propname, | 65 | struct 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 | } |
90 | EXPORT_SYMBOL(of_get_named_gpio_flags); | 96 | EXPORT_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 |
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index a83dc6f5008e..d71f2cc141ae 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/of.h> | 21 | #include <linux/of.h> |
22 | 22 | ||
23 | struct device_node; | 23 | struct device_node; |
24 | struct gpio_desc; | ||
24 | 25 | ||
25 | /* | 26 | /* |
26 | * This is Linux-specific flags. By default controllers' and Linux' mapping | 27 | * This is Linux-specific flags. By default controllers' and Linux' mapping |
@@ -47,7 +48,7 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) | |||
47 | return container_of(gc, struct of_mm_gpio_chip, gc); | 48 | return container_of(gc, struct of_mm_gpio_chip, gc); |
48 | } | 49 | } |
49 | 50 | ||
50 | extern int of_get_named_gpio_flags(struct device_node *np, | 51 | extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
51 | const char *list_name, int index, enum of_gpio_flags *flags); | 52 | const char *list_name, int index, enum of_gpio_flags *flags); |
52 | 53 | ||
53 | extern int of_mm_gpiochip_add(struct device_node *np, | 54 | extern int of_mm_gpiochip_add(struct device_node *np, |
@@ -62,10 +63,10 @@ extern int of_gpio_simple_xlate(struct gpio_chip *gc, | |||
62 | #else /* CONFIG_OF_GPIO */ | 63 | #else /* CONFIG_OF_GPIO */ |
63 | 64 | ||
64 | /* Drivers may not strictly depend on the GPIO support, so let them link. */ | 65 | /* Drivers may not strictly depend on the GPIO support, so let them link. */ |
65 | static inline int of_get_named_gpio_flags(struct device_node *np, | 66 | static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
66 | const char *list_name, int index, enum of_gpio_flags *flags) | 67 | const char *list_name, int index, enum of_gpio_flags *flags) |
67 | { | 68 | { |
68 | return -ENOSYS; | 69 | return ERR_PTR(-ENOSYS); |
69 | } | 70 | } |
70 | 71 | ||
71 | static inline int of_gpio_simple_xlate(struct gpio_chip *gc, | 72 | static inline int of_gpio_simple_xlate(struct gpio_chip *gc, |
@@ -80,6 +81,18 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { } | |||
80 | 81 | ||
81 | #endif /* CONFIG_OF_GPIO */ | 82 | #endif /* CONFIG_OF_GPIO */ |
82 | 83 | ||
84 | static inline int of_get_named_gpio_flags(struct device_node *np, | ||
85 | const char *list_name, int index, enum of_gpio_flags *flags) | ||
86 | { | ||
87 | struct gpio_desc *desc; | ||
88 | desc = of_get_named_gpiod_flags(np, list_name, index, flags); | ||
89 | |||
90 | if (IS_ERR(desc)) | ||
91 | return PTR_ERR(desc); | ||
92 | else | ||
93 | return desc_to_gpio(desc); | ||
94 | } | ||
95 | |||
83 | /** | 96 | /** |
84 | * of_gpio_named_count() - Count GPIOs for a device | 97 | * of_gpio_named_count() - Count GPIOs for a device |
85 | * @np: device node to count GPIOs for | 98 | * @np: device node to count GPIOs for |
@@ -117,15 +130,21 @@ static inline int of_gpio_count(struct device_node *np) | |||
117 | } | 130 | } |
118 | 131 | ||
119 | /** | 132 | /** |
120 | * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API | 133 | * of_get_gpiod_flags() - Get a GPIO descriptor and flags to use with GPIO API |
121 | * @np: device node to get GPIO from | 134 | * @np: device node to get GPIO from |
122 | * @index: index of the GPIO | 135 | * @index: index of the GPIO |
123 | * @flags: a flags pointer to fill in | 136 | * @flags: a flags pointer to fill in |
124 | * | 137 | * |
125 | * Returns GPIO number to use with Linux generic GPIO API, or one of the errno | 138 | * Returns GPIO descriptor to use with Linux generic GPIO API, or a errno |
126 | * value on the error condition. If @flags is not NULL the function also fills | 139 | * value on the error condition. If @flags is not NULL the function also fills |
127 | * in flags for the GPIO. | 140 | * in flags for the GPIO. |
128 | */ | 141 | */ |
142 | static inline struct gpio_desc *of_get_gpiod_flags(struct device_node *np, | ||
143 | int index, enum of_gpio_flags *flags) | ||
144 | { | ||
145 | return of_get_named_gpiod_flags(np, "gpios", index, flags); | ||
146 | } | ||
147 | |||
129 | static inline int of_get_gpio_flags(struct device_node *np, int index, | 148 | static inline int of_get_gpio_flags(struct device_node *np, int index, |
130 | enum of_gpio_flags *flags) | 149 | enum of_gpio_flags *flags) |
131 | { | 150 | { |