aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/of/gpio.c36
-rw-r--r--include/linux/of_gpio.h38
2 files changed, 63 insertions, 11 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);
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 67db101d0eb8..e25abf610cb6 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -14,9 +14,22 @@
14#ifndef __LINUX_OF_GPIO_H 14#ifndef __LINUX_OF_GPIO_H
15#define __LINUX_OF_GPIO_H 15#define __LINUX_OF_GPIO_H
16 16
17#include <linux/compiler.h>
18#include <linux/kernel.h>
17#include <linux/errno.h> 19#include <linux/errno.h>
18#include <linux/gpio.h> 20#include <linux/gpio.h>
19 21
22struct device_node;
23
24/*
25 * This is Linux-specific flags. By default controllers' and Linux' mapping
26 * match, but GPIO controllers are free to translate their own flags to
27 * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
28 */
29enum of_gpio_flags {
30 OF_GPIO_ACTIVE_LOW = 0x1,
31};
32
20#ifdef CONFIG_OF_GPIO 33#ifdef CONFIG_OF_GPIO
21 34
22/* 35/*
@@ -26,7 +39,7 @@ struct of_gpio_chip {
26 struct gpio_chip gc; 39 struct gpio_chip gc;
27 int gpio_cells; 40 int gpio_cells;
28 int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np, 41 int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
29 const void *gpio_spec); 42 const void *gpio_spec, enum of_gpio_flags *flags);
30}; 43};
31 44
32static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc) 45static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc)
@@ -50,20 +63,37 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
50 return container_of(of_gc, struct of_mm_gpio_chip, of_gc); 63 return container_of(of_gc, struct of_mm_gpio_chip, of_gc);
51} 64}
52 65
53extern int of_get_gpio(struct device_node *np, int index); 66extern int of_get_gpio_flags(struct device_node *np, int index,
67 enum of_gpio_flags *flags);
68
54extern int of_mm_gpiochip_add(struct device_node *np, 69extern int of_mm_gpiochip_add(struct device_node *np,
55 struct of_mm_gpio_chip *mm_gc); 70 struct of_mm_gpio_chip *mm_gc);
56extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, 71extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc,
57 struct device_node *np, 72 struct device_node *np,
58 const void *gpio_spec); 73 const void *gpio_spec,
74 enum of_gpio_flags *flags);
59#else 75#else
60 76
61/* Drivers may not strictly depend on the GPIO support, so let them link. */ 77/* Drivers may not strictly depend on the GPIO support, so let them link. */
62static inline int of_get_gpio(struct device_node *np, int index) 78static inline int of_get_gpio_flags(struct device_node *np, int index,
79 enum of_gpio_flags *flags)
63{ 80{
64 return -ENOSYS; 81 return -ENOSYS;
65} 82}
66 83
67#endif /* CONFIG_OF_GPIO */ 84#endif /* CONFIG_OF_GPIO */
68 85
86/**
87 * of_get_gpio - Get a GPIO number to use with GPIO API
88 * @np: device node to get GPIO from
89 * @index: index of the GPIO
90 *
91 * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
92 * value on the error condition.
93 */
94static inline int of_get_gpio(struct device_node *np, int index)
95{
96 return of_get_gpio_flags(np, index, NULL);
97}
98
69#endif /* __LINUX_OF_GPIO_H */ 99#endif /* __LINUX_OF_GPIO_H */