blob: 8ef7fc0ce0f0cb408bf04a9a01cea0eb2309815b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Brownell7560fa62008-03-04 14:28:27 -08002#ifndef __LINUX_GPIO_H
3#define __LINUX_GPIO_H
4
Mark Brown7563bbf2012-04-15 10:52:54 +01005#include <linux/errno.h>
6
Richard Genoudf7b370a2014-02-11 17:25:35 +01007/* see Documentation/gpio/gpio-legacy.txt */
David Brownell7560fa62008-03-04 14:28:27 -08008
Randy Dunlapc001fb72011-06-14 17:05:11 -07009/* make these flag values available regardless of GPIO kconfig options */
10#define GPIOF_DIR_OUT (0 << 0)
11#define GPIOF_DIR_IN (1 << 0)
12
13#define GPIOF_INIT_LOW (0 << 1)
14#define GPIOF_INIT_HIGH (1 << 1)
15
16#define GPIOF_IN (GPIOF_DIR_IN)
17#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
18#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
19
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070020/* Gpio pin is active-low */
21#define GPIOF_ACTIVE_LOW (1 << 2)
22
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053023/* Gpio pin is open drain */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070024#define GPIOF_OPEN_DRAIN (1 << 3)
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053025
Laxman Dewangan25553ff2012-02-17 20:26:22 +053026/* Gpio pin is open source */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070027#define GPIOF_OPEN_SOURCE (1 << 4)
Laxman Dewangan25553ff2012-02-17 20:26:22 +053028
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070029#define GPIOF_EXPORT (1 << 5)
30#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010031#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
32#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
33
Mark Brownfeb83692011-10-24 15:24:10 +020034/**
35 * struct gpio - a structure describing a GPIO with configuration
36 * @gpio: the GPIO number
37 * @flags: GPIO configuration as specified by GPIOF_*
38 * @label: a literal description string of this GPIO
39 */
40struct gpio {
41 unsigned gpio;
42 unsigned long flags;
43 const char *label;
44};
45
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070046#ifdef CONFIG_GPIOLIB
Mark Brown7563bbf2012-04-15 10:52:54 +010047
48#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
David Brownell7560fa62008-03-04 14:28:27 -080049#include <asm/gpio.h>
Mark Brown7563bbf2012-04-15 10:52:54 +010050#else
51
52#include <asm-generic/gpio.h>
53
54static inline int gpio_get_value(unsigned int gpio)
55{
56 return __gpio_get_value(gpio);
57}
58
59static inline void gpio_set_value(unsigned int gpio, int value)
60{
61 __gpio_set_value(gpio, value);
62}
63
64static inline int gpio_cansleep(unsigned int gpio)
65{
66 return __gpio_cansleep(gpio);
67}
68
69static inline int gpio_to_irq(unsigned int gpio)
70{
71 return __gpio_to_irq(gpio);
72}
73
74static inline int irq_to_gpio(unsigned int irq)
75{
76 return -EINVAL;
77}
78
Linus Walleij165adc92012-11-06 14:49:39 +010079#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
David Brownell7560fa62008-03-04 14:28:27 -080080
Linus Walleij403c1d02013-10-25 12:59:05 +020081/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
82
83struct device;
84
85int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
86int devm_gpio_request_one(struct device *dev, unsigned gpio,
87 unsigned long flags, const char *label);
88void devm_gpio_free(struct device *dev, unsigned int gpio);
89
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070090#else /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -080091
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070092#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070093#include <linux/types.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050094#include <linux/bug.h>
Christian Ruppert586a87e2013-10-15 15:37:54 +020095#include <linux/pinctrl/pinctrl.h>
David Brownell6ea02052008-05-23 13:04:58 -070096
Jani Nikulaa4177ee2009-09-22 16:46:33 -070097struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060098struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070099
Joe Perches3474cb32011-05-10 16:23:07 -0700100static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -0800101{
Joe Perches3474cb32011-05-10 16:23:07 -0700102 return false;
David Brownell7560fa62008-03-04 14:28:27 -0800103}
104
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800105static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -0800106{
107 return -ENOSYS;
108}
109
Wolfram Sang323b7fe2011-01-14 09:34:29 +0100110static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -0800111 unsigned long flags, const char *label)
112{
113 return -ENOSYS;
114}
115
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700116static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800117{
118 return -ENOSYS;
119}
120
David Brownell7560fa62008-03-04 14:28:27 -0800121static inline void gpio_free(unsigned gpio)
122{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700123 might_sleep();
124
David Brownell7560fa62008-03-04 14:28:27 -0800125 /* GPIO can never have been requested */
126 WARN_ON(1);
127}
128
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700129static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800130{
131 might_sleep();
132
133 /* GPIO can never have been requested */
134 WARN_ON(1);
135}
136
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800137static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800138{
139 return -ENOSYS;
140}
141
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800142static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800143{
144 return -ENOSYS;
145}
146
Felipe Balbic4b5be92010-05-26 14:42:23 -0700147static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
148{
149 return -ENOSYS;
150}
151
David Brownell7560fa62008-03-04 14:28:27 -0800152static inline int gpio_get_value(unsigned gpio)
153{
154 /* GPIO can never have been requested or set as {in,out}put */
155 WARN_ON(1);
156 return 0;
157}
158
159static inline void gpio_set_value(unsigned gpio, int value)
160{
161 /* GPIO can never have been requested or set as output */
162 WARN_ON(1);
163}
164
165static inline int gpio_cansleep(unsigned gpio)
166{
167 /* GPIO can never have been requested or set as {in,out}put */
168 WARN_ON(1);
169 return 0;
170}
171
172static inline int gpio_get_value_cansleep(unsigned gpio)
173{
174 /* GPIO can never have been requested or set as {in,out}put */
175 WARN_ON(1);
176 return 0;
177}
178
179static inline void gpio_set_value_cansleep(unsigned gpio, int value)
180{
181 /* GPIO can never have been requested or set as output */
182 WARN_ON(1);
183}
184
David Brownelld8f388d82008-07-25 01:46:07 -0700185static inline int gpio_export(unsigned gpio, bool direction_may_change)
186{
187 /* GPIO can never have been requested or set as {in,out}put */
188 WARN_ON(1);
189 return -EINVAL;
190}
191
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700192static inline int gpio_export_link(struct device *dev, const char *name,
193 unsigned gpio)
194{
195 /* GPIO can never have been exported */
196 WARN_ON(1);
197 return -EINVAL;
198}
199
David Brownelld8f388d82008-07-25 01:46:07 -0700200static inline void gpio_unexport(unsigned gpio)
201{
202 /* GPIO can never have been exported */
203 WARN_ON(1);
204}
205
David Brownell7560fa62008-03-04 14:28:27 -0800206static inline int gpio_to_irq(unsigned gpio)
207{
208 /* GPIO can never have been requested or set as input */
209 WARN_ON(1);
210 return -EINVAL;
211}
212
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900213static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
214 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200215{
216 WARN_ON(1);
217 return -EINVAL;
218}
219
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900220static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
221 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200222{
223 WARN_ON(1);
224}
225
David Brownell7560fa62008-03-04 14:28:27 -0800226static inline int irq_to_gpio(unsigned irq)
227{
228 /* irq can never have been returned from gpio_to_irq() */
229 WARN_ON(1);
230 return -EINVAL;
231}
232
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100233static inline int
Linus Walleij165adc92012-11-06 14:49:39 +0100234gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
Linus Walleij316511c2012-11-21 08:48:09 +0100235 unsigned int gpio_offset, unsigned int pin_offset,
Linus Walleij3f0f8672012-11-20 12:40:15 +0100236 unsigned int npins)
Linus Walleij165adc92012-11-06 14:49:39 +0100237{
Linus Walleij50309a92012-11-06 17:16:39 +0100238 WARN_ON(1);
239 return -EINVAL;
Linus Walleij165adc92012-11-06 14:49:39 +0100240}
241
Christian Ruppert586a87e2013-10-15 15:37:54 +0200242static inline int
243gpiochip_add_pingroup_range(struct gpio_chip *chip,
244 struct pinctrl_dev *pctldev,
245 unsigned int gpio_offset, const char *pin_group)
246{
247 WARN_ON(1);
248 return -EINVAL;
249}
250
Linus Walleij165adc92012-11-06 14:49:39 +0100251static inline void
252gpiochip_remove_pin_ranges(struct gpio_chip *chip)
253{
Linus Walleij50309a92012-11-06 17:16:39 +0100254 WARN_ON(1);
Linus Walleij165adc92012-11-06 14:49:39 +0100255}
256
Linus Walleij403c1d02013-10-25 12:59:05 +0200257static inline int devm_gpio_request(struct device *dev, unsigned gpio,
258 const char *label)
259{
260 WARN_ON(1);
261 return -EINVAL;
262}
263
264static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
265 unsigned long flags, const char *label)
266{
267 WARN_ON(1);
268 return -EINVAL;
269}
270
271static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
272{
273 WARN_ON(1);
274}
275
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700276#endif /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800277
David Brownell7560fa62008-03-04 14:28:27 -0800278#endif /* __LINUX_GPIO_H */