aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2008-12-01 01:30:04 -0500
committerPaul Mackerras <paulus@samba.org>2008-12-03 05:04:05 -0500
commitb908b53d580c3e9aba81ebe3339c5b7b4fa8031d (patch)
treec2a07833cd919f185e750391d2a8c5bd3bec827a /drivers/of
parent2fd091f3eebc5accefa5f77ff04436982765d15c (diff)
of/gpio: Implement of_get_gpio_flags()
This adds a new function, of_get_gpio_flags, which is like of_get_gpio(), but accepts a new "flags" argument. This new function will be used by the drivers that need to retrieve additional GPIO information, such as active-low flag. Also, this changes the default ("simple") .xlate routine to warn about bogus (< 2) #gpio-cells usage: the second cell should always be present for GPIO flags. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/gpio.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 7cd7301b5839..a4ba217116eb 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -19,14 +19,17 @@
19#include <asm/prom.h> 19#include <asm/prom.h>
20 20
21/** 21/**
22 * of_get_gpio - Get a GPIO number from the device tree to use with GPIO API 22 * of_get_gpio_flags - Get a GPIO number and flags to use with GPIO API
23 * @np: device node to get GPIO from 23 * @np: device node to get GPIO from
24 * @index: index of the GPIO 24 * @index: index of the GPIO
25 * @flags: a flags pointer to fill in
25 * 26 *
26 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 27 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
27 * value on the error condition. 28 * value on the error condition. If @flags is not NULL the function also fills
29 * in flags for the GPIO.
28 */ 30 */
29int of_get_gpio(struct device_node *np, int index) 31int of_get_gpio_flags(struct device_node *np, int index,
32 enum of_gpio_flags *flags)
30{ 33{
31 int ret; 34 int ret;
32 struct device_node *gc; 35 struct device_node *gc;
@@ -59,7 +62,11 @@ int of_get_gpio(struct device_node *np, int index)
59 goto err1; 62 goto err1;
60 } 63 }
61 64
62 ret = of_gc->xlate(of_gc, np, gpio_spec); 65 /* .xlate might decide to not fill in the flags, so clear it. */
66 if (flags)
67 *flags = 0;
68
69 ret = of_gc->xlate(of_gc, np, gpio_spec, flags);
63 if (ret < 0) 70 if (ret < 0)
64 goto err1; 71 goto err1;
65 72
@@ -70,26 +77,41 @@ err0:
70 pr_debug("%s exited with status %d\n", __func__, ret); 77 pr_debug("%s exited with status %d\n", __func__, ret);
71 return ret; 78 return ret;
72} 79}
73EXPORT_SYMBOL(of_get_gpio); 80EXPORT_SYMBOL(of_get_gpio_flags);
74 81
75/** 82/**
76 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number 83 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
77 * @of_gc: pointer to the of_gpio_chip structure 84 * @of_gc: pointer to the of_gpio_chip structure
78 * @np: device node of the GPIO chip 85 * @np: device node of the GPIO chip
79 * @gpio_spec: gpio specifier as found in the device tree 86 * @gpio_spec: gpio specifier as found in the device tree
87 * @flags: a flags pointer to fill in
80 * 88 *
81 * This is simple translation function, suitable for the most 1:1 mapped 89 * This is simple translation function, suitable for the most 1:1 mapped
82 * gpio chips. This function performs only one sanity check: whether gpio 90 * gpio chips. This function performs only one sanity check: whether gpio
83 * is less than ngpios (that is specified in the gpio_chip). 91 * is less than ngpios (that is specified in the gpio_chip).
84 */ 92 */
85int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, 93int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
86 const void *gpio_spec) 94 const void *gpio_spec, enum of_gpio_flags *flags)
87{ 95{
88 const u32 *gpio = gpio_spec; 96 const u32 *gpio = gpio_spec;
89 97
98 /*
99 * We're discouraging gpio_cells < 2, since that way you'll have to
100 * write your own xlate function (that will have to retrive the GPIO
101 * number and the flags from a single gpio cell -- this is possible,
102 * but not recommended).
103 */
104 if (of_gc->gpio_cells < 2) {
105 WARN_ON(1);
106 return -EINVAL;
107 }
108
90 if (*gpio > of_gc->gc.ngpio) 109 if (*gpio > of_gc->gc.ngpio)
91 return -EINVAL; 110 return -EINVAL;
92 111
112 if (flags)
113 *flags = gpio[1];
114
93 return *gpio; 115 return *gpio;
94} 116}
95EXPORT_SYMBOL(of_gpio_simple_xlate); 117EXPORT_SYMBOL(of_gpio_simple_xlate);