1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NOTE: This header *must not* be included.
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.
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>
12 #ifndef __LINUX_GPIO_H
13 #define __LINUX_GPIO_H
15 #include <linux/types.h>
19 /* make these flag values available regardless of GPIO kconfig options */
20 #define GPIOF_IN ((1 << 0))
21 #define GPIOF_OUT_INIT_LOW ((0 << 0) | (0 << 1))
22 #define GPIOF_OUT_INIT_HIGH ((0 << 0) | (1 << 1))
25 * struct gpio - a structure describing a GPIO with configuration
26 * @gpio: the GPIO number
27 * @flags: GPIO configuration as specified by GPIOF_*
28 * @label: a literal description string of this GPIO
38 #include <linux/gpio/consumer.h>
41 * "valid" GPIO numbers are nonnegative and may be passed to
42 * setup routines like gpio_request(). Only some valid numbers
43 * can successfully be requested and used.
45 * Invalid GPIO numbers are useful for indicating no-such-GPIO in
46 * platform data and other tables.
48 static inline bool gpio_is_valid(int number
)
50 /* only non-negative numbers are valid */
55 * Platforms may implement their GPIO interface with library code,
56 * at a small performance cost for non-inlined operations and some
57 * extra memory (for code and for per-GPIO table entries).
61 * At the end we want all GPIOs to be dynamically allocated from 0.
62 * However, some legacy drivers still perform fixed allocation.
63 * Until they are all fixed, leave 0-512 space for them.
65 #define GPIO_DYNAMIC_BASE 512
67 * Define the maximum of the possible GPIO in the global numberspace.
68 * While the GPIO base and numbers are positive, we limit it with signed
69 * maximum as a lot of code is using negative values for special cases.
71 #define GPIO_DYNAMIC_MAX INT_MAX
73 /* Always use the library code for GPIO management calls,
74 * or when sleeping may be involved.
76 int gpio_request(unsigned gpio
, const char *label
);
77 void gpio_free(unsigned gpio
);
79 static inline int gpio_direction_input(unsigned gpio
)
81 return gpiod_direction_input(gpio_to_desc(gpio
));
83 static inline int gpio_direction_output(unsigned gpio
, int value
)
85 return gpiod_direction_output_raw(gpio_to_desc(gpio
), value
);
88 static inline int gpio_get_value_cansleep(unsigned gpio
)
90 return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio
));
92 static inline void gpio_set_value_cansleep(unsigned gpio
, int value
)
94 return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio
), value
);
97 static inline int gpio_get_value(unsigned gpio
)
99 return gpiod_get_raw_value(gpio_to_desc(gpio
));
101 static inline void gpio_set_value(unsigned gpio
, int value
)
103 return gpiod_set_raw_value(gpio_to_desc(gpio
), value
);
106 static inline int gpio_to_irq(unsigned gpio
)
108 return gpiod_to_irq(gpio_to_desc(gpio
));
111 int gpio_request_one(unsigned gpio
, unsigned long flags
, const char *label
);
113 int devm_gpio_request(struct device
*dev
, unsigned gpio
, const char *label
);
114 int devm_gpio_request_one(struct device
*dev
, unsigned gpio
,
115 unsigned long flags
, const char *label
);
117 #else /* ! CONFIG_GPIOLIB */
119 #include <linux/kernel.h>
122 #include <asm/errno.h>
124 static inline bool gpio_is_valid(int number
)
129 static inline int gpio_request(unsigned gpio
, const char *label
)
134 static inline int gpio_request_one(unsigned gpio
,
135 unsigned long flags
, const char *label
)
140 static inline void gpio_free(unsigned gpio
)
144 /* GPIO can never have been requested */
148 static inline int gpio_direction_input(unsigned gpio
)
153 static inline int gpio_direction_output(unsigned gpio
, int value
)
158 static inline int gpio_get_value(unsigned gpio
)
160 /* GPIO can never have been requested or set as {in,out}put */
165 static inline void gpio_set_value(unsigned gpio
, int value
)
167 /* GPIO can never have been requested or set as output */
171 static inline int gpio_get_value_cansleep(unsigned gpio
)
173 /* GPIO can never have been requested or set as {in,out}put */
178 static inline void gpio_set_value_cansleep(unsigned gpio
, int value
)
180 /* GPIO can never have been requested or set as output */
184 static inline int gpio_to_irq(unsigned gpio
)
186 /* GPIO can never have been requested or set as input */
191 static inline int devm_gpio_request(struct device
*dev
, unsigned gpio
,
198 static inline int devm_gpio_request_one(struct device
*dev
, unsigned gpio
,
199 unsigned long flags
, const char *label
)
205 #endif /* ! CONFIG_GPIOLIB */
207 #endif /* __LINUX_GPIO_H */