blob: 17b5a0d80e4239cc10fceb670be29dbf4e49a0f0 [file] [log] [blame]
David Brownell7560fa62008-03-04 14:28:27 -08001#ifndef __LINUX_GPIO_H
2#define __LINUX_GPIO_H
3
4/* see Documentation/gpio.txt */
5
Randy Dunlapc001fb72011-06-14 17:05:11 -07006/* make these flag values available regardless of GPIO kconfig options */
7#define GPIOF_DIR_OUT (0 << 0)
8#define GPIOF_DIR_IN (1 << 0)
9
10#define GPIOF_INIT_LOW (0 << 1)
11#define GPIOF_INIT_HIGH (1 << 1)
12
13#define GPIOF_IN (GPIOF_DIR_IN)
14#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
15#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
16
David Brownell7560fa62008-03-04 14:28:27 -080017#ifdef CONFIG_GENERIC_GPIO
18#include <asm/gpio.h>
19
20#else
21
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070022#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070023#include <linux/types.h>
24#include <linux/errno.h>
25
Jani Nikulaa4177ee2009-09-22 16:46:33 -070026struct device;
Wolfram Sang5f829e42011-01-12 17:00:24 -080027struct gpio;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060028struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070029
David Brownell7560fa62008-03-04 14:28:27 -080030/*
31 * Some platforms don't support the GPIO programming interface.
32 *
33 * In case some driver uses it anyway (it should normally have
34 * depended on GENERIC_GPIO), these routines help the compiler
35 * optimize out much GPIO-related code ... or trigger a runtime
36 * warning when something is wrongly called.
37 */
38
Joe Perches3474cb32011-05-10 16:23:07 -070039static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080040{
Joe Perches3474cb32011-05-10 16:23:07 -070041 return false;
David Brownell7560fa62008-03-04 14:28:27 -080042}
43
Linus Torvaldsd8a35152011-01-13 17:26:46 -080044static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -080045{
46 return -ENOSYS;
47}
48
Wolfram Sang323b7fe2011-01-14 09:34:29 +010049static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -080050 unsigned long flags, const char *label)
51{
52 return -ENOSYS;
53}
54
Lars-Peter Clausen7c295972011-05-25 16:20:31 -070055static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -080056{
57 return -ENOSYS;
58}
59
David Brownell7560fa62008-03-04 14:28:27 -080060static inline void gpio_free(unsigned gpio)
61{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070062 might_sleep();
63
David Brownell7560fa62008-03-04 14:28:27 -080064 /* GPIO can never have been requested */
65 WARN_ON(1);
66}
67
Lars-Peter Clausen7c295972011-05-25 16:20:31 -070068static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -080069{
70 might_sleep();
71
72 /* GPIO can never have been requested */
73 WARN_ON(1);
74}
75
Linus Torvaldsd8a35152011-01-13 17:26:46 -080076static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -080077{
78 return -ENOSYS;
79}
80
Linus Torvaldsd8a35152011-01-13 17:26:46 -080081static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -080082{
83 return -ENOSYS;
84}
85
Felipe Balbic4b5be92010-05-26 14:42:23 -070086static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
87{
88 return -ENOSYS;
89}
90
David Brownell7560fa62008-03-04 14:28:27 -080091static inline int gpio_get_value(unsigned gpio)
92{
93 /* GPIO can never have been requested or set as {in,out}put */
94 WARN_ON(1);
95 return 0;
96}
97
98static inline void gpio_set_value(unsigned gpio, int value)
99{
100 /* GPIO can never have been requested or set as output */
101 WARN_ON(1);
102}
103
104static inline int gpio_cansleep(unsigned gpio)
105{
106 /* GPIO can never have been requested or set as {in,out}put */
107 WARN_ON(1);
108 return 0;
109}
110
111static inline int gpio_get_value_cansleep(unsigned gpio)
112{
113 /* GPIO can never have been requested or set as {in,out}put */
114 WARN_ON(1);
115 return 0;
116}
117
118static inline void gpio_set_value_cansleep(unsigned gpio, int value)
119{
120 /* GPIO can never have been requested or set as output */
121 WARN_ON(1);
122}
123
David Brownelld8f388d2008-07-25 01:46:07 -0700124static inline int gpio_export(unsigned gpio, bool direction_may_change)
125{
126 /* GPIO can never have been requested or set as {in,out}put */
127 WARN_ON(1);
128 return -EINVAL;
129}
130
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700131static inline int gpio_export_link(struct device *dev, const char *name,
132 unsigned gpio)
133{
134 /* GPIO can never have been exported */
135 WARN_ON(1);
136 return -EINVAL;
137}
138
Jani Nikula07697462009-12-15 16:46:20 -0800139static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
140{
141 /* GPIO can never have been requested */
142 WARN_ON(1);
143 return -EINVAL;
144}
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700145
David Brownelld8f388d2008-07-25 01:46:07 -0700146static inline void gpio_unexport(unsigned gpio)
147{
148 /* GPIO can never have been exported */
149 WARN_ON(1);
150}
151
David Brownell7560fa62008-03-04 14:28:27 -0800152static inline int gpio_to_irq(unsigned gpio)
153{
154 /* GPIO can never have been requested or set as input */
155 WARN_ON(1);
156 return -EINVAL;
157}
158
159static inline int irq_to_gpio(unsigned irq)
160{
161 /* irq can never have been returned from gpio_to_irq() */
162 WARN_ON(1);
163 return -EINVAL;
164}
165
166#endif
167
168#endif /* __LINUX_GPIO_H */