blob: 39745b8bdd65d7893d184bbfa7bae221cd0cc0f0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Walleij56a46b62017-11-30 11:03:05 +01002/*
3 * <linux/gpio.h>
4 *
5 * This is the LEGACY GPIO bulk include file, including legacy APIs. It is
6 * used for GPIO drivers still referencing the global GPIO numberspace,
7 * and should not be included in new code.
8 *
9 * If you're implementing a GPIO driver, only include <linux/gpio/driver.h>
10 * If you're implementing a GPIO consumer, only include <linux/gpio/consumer.h>
11 */
David Brownell7560fa62008-03-04 14:28:27 -080012#ifndef __LINUX_GPIO_H
13#define __LINUX_GPIO_H
14
Mark Brown7563bbf2012-04-15 10:52:54 +010015#include <linux/errno.h>
16
Mauro Carvalho Chehab60a86662018-06-26 06:49:08 -030017/* see Documentation/driver-api/gpio/legacy.rst */
David Brownell7560fa62008-03-04 14:28:27 -080018
Randy Dunlapc001fb72011-06-14 17:05:11 -070019/* make these flag values available regardless of GPIO kconfig options */
20#define GPIOF_DIR_OUT (0 << 0)
21#define GPIOF_DIR_IN (1 << 0)
22
23#define GPIOF_INIT_LOW (0 << 1)
24#define GPIOF_INIT_HIGH (1 << 1)
25
26#define GPIOF_IN (GPIOF_DIR_IN)
27#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
28#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
29
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070030/* Gpio pin is active-low */
31#define GPIOF_ACTIVE_LOW (1 << 2)
32
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053033/* Gpio pin is open drain */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070034#define GPIOF_OPEN_DRAIN (1 << 3)
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053035
Laxman Dewangan25553ff2012-02-17 20:26:22 +053036/* Gpio pin is open source */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070037#define GPIOF_OPEN_SOURCE (1 << 4)
Laxman Dewangan25553ff2012-02-17 20:26:22 +053038
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070039#define GPIOF_EXPORT (1 << 5)
40#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010041#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
42#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
43
Mark Brownfeb83692011-10-24 15:24:10 +020044/**
45 * struct gpio - a structure describing a GPIO with configuration
46 * @gpio: the GPIO number
47 * @flags: GPIO configuration as specified by GPIOF_*
48 * @label: a literal description string of this GPIO
49 */
50struct gpio {
51 unsigned gpio;
52 unsigned long flags;
53 const char *label;
54};
55
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070056#ifdef CONFIG_GPIOLIB
Mark Brown7563bbf2012-04-15 10:52:54 +010057
58#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
David Brownell7560fa62008-03-04 14:28:27 -080059#include <asm/gpio.h>
Mark Brown7563bbf2012-04-15 10:52:54 +010060#else
61
62#include <asm-generic/gpio.h>
63
64static inline int gpio_get_value(unsigned int gpio)
65{
66 return __gpio_get_value(gpio);
67}
68
69static inline void gpio_set_value(unsigned int gpio, int value)
70{
71 __gpio_set_value(gpio, value);
72}
73
74static inline int gpio_cansleep(unsigned int gpio)
75{
76 return __gpio_cansleep(gpio);
77}
78
79static inline int gpio_to_irq(unsigned int gpio)
80{
81 return __gpio_to_irq(gpio);
82}
83
84static inline int irq_to_gpio(unsigned int irq)
85{
86 return -EINVAL;
87}
88
Linus Walleij165adc92012-11-06 14:49:39 +010089#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
David Brownell7560fa62008-03-04 14:28:27 -080090
Linus Walleij403c1d02013-10-25 12:59:05 +020091/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
92
93struct device;
94
95int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
96int devm_gpio_request_one(struct device *dev, unsigned gpio,
97 unsigned long flags, const char *label);
98void devm_gpio_free(struct device *dev, unsigned int gpio);
99
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700100#else /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800101
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700102#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -0700103#include <linux/types.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -0500104#include <linux/bug.h>
Christian Ruppert586a87e2013-10-15 15:37:54 +0200105#include <linux/pinctrl/pinctrl.h>
David Brownell6ea02052008-05-23 13:04:58 -0700106
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700107struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -0600108struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700109
Joe Perches3474cb32011-05-10 16:23:07 -0700110static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -0800111{
Joe Perches3474cb32011-05-10 16:23:07 -0700112 return false;
David Brownell7560fa62008-03-04 14:28:27 -0800113}
114
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800115static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -0800116{
117 return -ENOSYS;
118}
119
Wolfram Sang323b7fe2011-01-14 09:34:29 +0100120static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -0800121 unsigned long flags, const char *label)
122{
123 return -ENOSYS;
124}
125
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700126static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800127{
128 return -ENOSYS;
129}
130
David Brownell7560fa62008-03-04 14:28:27 -0800131static inline void gpio_free(unsigned gpio)
132{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700133 might_sleep();
134
David Brownell7560fa62008-03-04 14:28:27 -0800135 /* GPIO can never have been requested */
136 WARN_ON(1);
137}
138
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700139static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800140{
141 might_sleep();
142
143 /* GPIO can never have been requested */
144 WARN_ON(1);
145}
146
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800147static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800148{
149 return -ENOSYS;
150}
151
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800152static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800153{
154 return -ENOSYS;
155}
156
Felipe Balbic4b5be92010-05-26 14:42:23 -0700157static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
158{
159 return -ENOSYS;
160}
161
David Brownell7560fa62008-03-04 14:28:27 -0800162static inline int gpio_get_value(unsigned gpio)
163{
164 /* GPIO can never have been requested or set as {in,out}put */
165 WARN_ON(1);
166 return 0;
167}
168
169static inline void gpio_set_value(unsigned gpio, int value)
170{
171 /* GPIO can never have been requested or set as output */
172 WARN_ON(1);
173}
174
175static inline int gpio_cansleep(unsigned gpio)
176{
177 /* GPIO can never have been requested or set as {in,out}put */
178 WARN_ON(1);
179 return 0;
180}
181
182static inline int gpio_get_value_cansleep(unsigned gpio)
183{
184 /* GPIO can never have been requested or set as {in,out}put */
185 WARN_ON(1);
186 return 0;
187}
188
189static inline void gpio_set_value_cansleep(unsigned gpio, int value)
190{
191 /* GPIO can never have been requested or set as output */
192 WARN_ON(1);
193}
194
David Brownelld8f388d82008-07-25 01:46:07 -0700195static inline int gpio_export(unsigned gpio, bool direction_may_change)
196{
197 /* GPIO can never have been requested or set as {in,out}put */
198 WARN_ON(1);
199 return -EINVAL;
200}
201
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700202static inline int gpio_export_link(struct device *dev, const char *name,
203 unsigned gpio)
204{
205 /* GPIO can never have been exported */
206 WARN_ON(1);
207 return -EINVAL;
208}
209
David Brownelld8f388d82008-07-25 01:46:07 -0700210static inline void gpio_unexport(unsigned gpio)
211{
212 /* GPIO can never have been exported */
213 WARN_ON(1);
214}
215
David Brownell7560fa62008-03-04 14:28:27 -0800216static inline int gpio_to_irq(unsigned gpio)
217{
218 /* GPIO can never have been requested or set as input */
219 WARN_ON(1);
220 return -EINVAL;
221}
222
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900223static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
224 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200225{
226 WARN_ON(1);
227 return -EINVAL;
228}
229
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900230static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
231 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200232{
233 WARN_ON(1);
234}
235
David Brownell7560fa62008-03-04 14:28:27 -0800236static inline int irq_to_gpio(unsigned irq)
237{
238 /* irq can never have been returned from gpio_to_irq() */
239 WARN_ON(1);
240 return -EINVAL;
241}
242
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100243static inline int
Linus Walleij165adc92012-11-06 14:49:39 +0100244gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
Linus Walleij316511c2012-11-21 08:48:09 +0100245 unsigned int gpio_offset, unsigned int pin_offset,
Linus Walleij3f0f8672012-11-20 12:40:15 +0100246 unsigned int npins)
Linus Walleij165adc92012-11-06 14:49:39 +0100247{
Linus Walleij50309a92012-11-06 17:16:39 +0100248 WARN_ON(1);
249 return -EINVAL;
Linus Walleij165adc92012-11-06 14:49:39 +0100250}
251
Christian Ruppert586a87e2013-10-15 15:37:54 +0200252static inline int
253gpiochip_add_pingroup_range(struct gpio_chip *chip,
254 struct pinctrl_dev *pctldev,
255 unsigned int gpio_offset, const char *pin_group)
256{
257 WARN_ON(1);
258 return -EINVAL;
259}
260
Linus Walleij165adc92012-11-06 14:49:39 +0100261static inline void
262gpiochip_remove_pin_ranges(struct gpio_chip *chip)
263{
Linus Walleij50309a92012-11-06 17:16:39 +0100264 WARN_ON(1);
Linus Walleij165adc92012-11-06 14:49:39 +0100265}
266
Linus Walleij403c1d02013-10-25 12:59:05 +0200267static inline int devm_gpio_request(struct device *dev, unsigned gpio,
268 const char *label)
269{
270 WARN_ON(1);
271 return -EINVAL;
272}
273
274static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
275 unsigned long flags, const char *label)
276{
277 WARN_ON(1);
278 return -EINVAL;
279}
280
281static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
282{
283 WARN_ON(1);
284}
285
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700286#endif /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800287
David Brownell7560fa62008-03-04 14:28:27 -0800288#endif /* __LINUX_GPIO_H */