printf: Remove unused 'bprintf'
[drm/drm-misc.git] / include / linux / gpio.h
blob6270150f4e297ab286c28f7a5c7c3017bd39dd58
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
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>
17 struct device;
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))
24 /**
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
30 struct gpio {
31 unsigned gpio;
32 unsigned long flags;
33 const char *label;
36 #ifdef CONFIG_GPIOLIB
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 */
51 return number >= 0;
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>
121 #include <asm/bug.h>
122 #include <asm/errno.h>
124 static inline bool gpio_is_valid(int number)
126 return false;
129 static inline int gpio_request(unsigned gpio, const char *label)
131 return -ENOSYS;
134 static inline int gpio_request_one(unsigned gpio,
135 unsigned long flags, const char *label)
137 return -ENOSYS;
140 static inline void gpio_free(unsigned gpio)
142 might_sleep();
144 /* GPIO can never have been requested */
145 WARN_ON(1);
148 static inline int gpio_direction_input(unsigned gpio)
150 return -ENOSYS;
153 static inline int gpio_direction_output(unsigned gpio, int value)
155 return -ENOSYS;
158 static inline int gpio_get_value(unsigned gpio)
160 /* GPIO can never have been requested or set as {in,out}put */
161 WARN_ON(1);
162 return 0;
165 static inline void gpio_set_value(unsigned gpio, int value)
167 /* GPIO can never have been requested or set as output */
168 WARN_ON(1);
171 static inline int gpio_get_value_cansleep(unsigned gpio)
173 /* GPIO can never have been requested or set as {in,out}put */
174 WARN_ON(1);
175 return 0;
178 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
180 /* GPIO can never have been requested or set as output */
181 WARN_ON(1);
184 static inline int gpio_to_irq(unsigned gpio)
186 /* GPIO can never have been requested or set as input */
187 WARN_ON(1);
188 return -EINVAL;
191 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
192 const char *label)
194 WARN_ON(1);
195 return -EINVAL;
198 static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
199 unsigned long flags, const char *label)
201 WARN_ON(1);
202 return -EINVAL;
205 #endif /* ! CONFIG_GPIOLIB */
207 #endif /* __LINUX_GPIO_H */