diff options
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/acpi_gpio.h | 31 | ||||
-rw-r--r-- | include/linux/gpio.h | 57 | ||||
-rw-r--r-- | include/linux/gpio/consumer.h | 253 | ||||
-rw-r--r-- | include/linux/gpio/driver.h | 184 | ||||
-rw-r--r-- | include/linux/of_gpio.h | 29 |
5 files changed, 527 insertions, 27 deletions
diff --git a/include/linux/acpi_gpio.h b/include/linux/acpi_gpio.h index 4c120a1e0ca3..d875bc3dba3c 100644 --- a/include/linux/acpi_gpio.h +++ b/include/linux/acpi_gpio.h | |||
@@ -2,36 +2,35 @@ | |||
2 | #define _LINUX_ACPI_GPIO_H_ | 2 | #define _LINUX_ACPI_GPIO_H_ |
3 | 3 | ||
4 | #include <linux/device.h> | 4 | #include <linux/device.h> |
5 | #include <linux/err.h> | ||
5 | #include <linux/errno.h> | 6 | #include <linux/errno.h> |
6 | #include <linux/gpio.h> | 7 | #include <linux/gpio.h> |
8 | #include <linux/gpio/consumer.h> | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * struct acpi_gpio_info - ACPI GPIO specific information | 11 | * struct acpi_gpio_info - ACPI GPIO specific information |
10 | * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo | 12 | * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo |
13 | * @active_low: in case of @gpioint, the pin is active low | ||
11 | */ | 14 | */ |
12 | struct acpi_gpio_info { | 15 | struct acpi_gpio_info { |
13 | bool gpioint; | 16 | bool gpioint; |
17 | bool active_low; | ||
14 | }; | 18 | }; |
15 | 19 | ||
16 | #ifdef CONFIG_GPIO_ACPI | 20 | #ifdef CONFIG_GPIO_ACPI |
17 | 21 | ||
18 | int acpi_get_gpio(char *path, int pin); | 22 | struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, |
19 | int acpi_get_gpio_by_index(struct device *dev, int index, | 23 | struct acpi_gpio_info *info); |
20 | struct acpi_gpio_info *info); | ||
21 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); | 24 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); |
22 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); | 25 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); |
23 | 26 | ||
24 | #else /* CONFIG_GPIO_ACPI */ | 27 | #else /* CONFIG_GPIO_ACPI */ |
25 | 28 | ||
26 | static inline int acpi_get_gpio(char *path, int pin) | 29 | static inline struct gpio_desc * |
30 | acpi_get_gpiod_by_index(struct device *dev, int index, | ||
31 | struct acpi_gpio_info *info) | ||
27 | { | 32 | { |
28 | return -ENODEV; | 33 | return ERR_PTR(-ENOSYS); |
29 | } | ||
30 | |||
31 | static inline int acpi_get_gpio_by_index(struct device *dev, int index, | ||
32 | struct acpi_gpio_info *info) | ||
33 | { | ||
34 | return -ENODEV; | ||
35 | } | 34 | } |
36 | 35 | ||
37 | static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } | 36 | static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } |
@@ -39,4 +38,14 @@ static inline void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } | |||
39 | 38 | ||
40 | #endif /* CONFIG_GPIO_ACPI */ | 39 | #endif /* CONFIG_GPIO_ACPI */ |
41 | 40 | ||
41 | static inline int acpi_get_gpio_by_index(struct device *dev, int index, | ||
42 | struct acpi_gpio_info *info) | ||
43 | { | ||
44 | struct gpio_desc *desc = acpi_get_gpiod_by_index(dev, index, info); | ||
45 | |||
46 | if (IS_ERR(desc)) | ||
47 | return PTR_ERR(desc); | ||
48 | return desc_to_gpio(desc); | ||
49 | } | ||
50 | |||
42 | #endif /* _LINUX_ACPI_GPIO_H_ */ | 51 | #endif /* _LINUX_ACPI_GPIO_H_ */ |
diff --git a/include/linux/gpio.h b/include/linux/gpio.h index b8d0e53a802f..13dfd24d01ab 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h | |||
@@ -16,14 +16,17 @@ | |||
16 | #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) | 16 | #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) |
17 | #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) | 17 | #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) |
18 | 18 | ||
19 | /* Gpio pin is active-low */ | ||
20 | #define GPIOF_ACTIVE_LOW (1 << 2) | ||
21 | |||
19 | /* Gpio pin is open drain */ | 22 | /* Gpio pin is open drain */ |
20 | #define GPIOF_OPEN_DRAIN (1 << 2) | 23 | #define GPIOF_OPEN_DRAIN (1 << 3) |
21 | 24 | ||
22 | /* Gpio pin is open source */ | 25 | /* Gpio pin is open source */ |
23 | #define GPIOF_OPEN_SOURCE (1 << 3) | 26 | #define GPIOF_OPEN_SOURCE (1 << 4) |
24 | 27 | ||
25 | #define GPIOF_EXPORT (1 << 4) | 28 | #define GPIOF_EXPORT (1 << 5) |
26 | #define GPIOF_EXPORT_CHANGEABLE (1 << 5) | 29 | #define GPIOF_EXPORT_CHANGEABLE (1 << 6) |
27 | #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) | 30 | #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) |
28 | #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) | 31 | #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) |
29 | 32 | ||
@@ -74,6 +77,15 @@ static inline int irq_to_gpio(unsigned int irq) | |||
74 | 77 | ||
75 | #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ | 78 | #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ |
76 | 79 | ||
80 | /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */ | ||
81 | |||
82 | struct device; | ||
83 | |||
84 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); | ||
85 | int devm_gpio_request_one(struct device *dev, unsigned gpio, | ||
86 | unsigned long flags, const char *label); | ||
87 | void devm_gpio_free(struct device *dev, unsigned int gpio); | ||
88 | |||
77 | #else /* ! CONFIG_GPIOLIB */ | 89 | #else /* ! CONFIG_GPIOLIB */ |
78 | 90 | ||
79 | #include <linux/kernel.h> | 91 | #include <linux/kernel.h> |
@@ -205,6 +217,18 @@ static inline int gpio_to_irq(unsigned gpio) | |||
205 | return -EINVAL; | 217 | return -EINVAL; |
206 | } | 218 | } |
207 | 219 | ||
220 | static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) | ||
221 | { | ||
222 | WARN_ON(1); | ||
223 | return -EINVAL; | ||
224 | } | ||
225 | |||
226 | static inline void gpio_unlock_as_irq(struct gpio_chip *chip, | ||
227 | unsigned int offset) | ||
228 | { | ||
229 | WARN_ON(1); | ||
230 | } | ||
231 | |||
208 | static inline int irq_to_gpio(unsigned irq) | 232 | static inline int irq_to_gpio(unsigned irq) |
209 | { | 233 | { |
210 | /* irq can never have been returned from gpio_to_irq() */ | 234 | /* irq can never have been returned from gpio_to_irq() */ |
@@ -236,14 +260,25 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) | |||
236 | WARN_ON(1); | 260 | WARN_ON(1); |
237 | } | 261 | } |
238 | 262 | ||
239 | #endif /* ! CONFIG_GPIOLIB */ | 263 | static inline int devm_gpio_request(struct device *dev, unsigned gpio, |
264 | const char *label) | ||
265 | { | ||
266 | WARN_ON(1); | ||
267 | return -EINVAL; | ||
268 | } | ||
240 | 269 | ||
241 | struct device; | 270 | static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, |
271 | unsigned long flags, const char *label) | ||
272 | { | ||
273 | WARN_ON(1); | ||
274 | return -EINVAL; | ||
275 | } | ||
242 | 276 | ||
243 | /* bindings for managed devices that want to request gpios */ | 277 | static inline void devm_gpio_free(struct device *dev, unsigned int gpio) |
244 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); | 278 | { |
245 | int devm_gpio_request_one(struct device *dev, unsigned gpio, | 279 | WARN_ON(1); |
246 | unsigned long flags, const char *label); | 280 | } |
247 | void devm_gpio_free(struct device *dev, unsigned int gpio); | 281 | |
282 | #endif /* ! CONFIG_GPIOLIB */ | ||
248 | 283 | ||
249 | #endif /* __LINUX_GPIO_H */ | 284 | #endif /* __LINUX_GPIO_H */ |
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h new file mode 100644 index 000000000000..4d34dbbbad4d --- /dev/null +++ b/include/linux/gpio/consumer.h | |||
@@ -0,0 +1,253 @@ | |||
1 | #ifndef __LINUX_GPIO_CONSUMER_H | ||
2 | #define __LINUX_GPIO_CONSUMER_H | ||
3 | |||
4 | #include <linux/err.h> | ||
5 | #include <linux/kernel.h> | ||
6 | |||
7 | #ifdef CONFIG_GPIOLIB | ||
8 | |||
9 | struct device; | ||
10 | struct gpio_chip; | ||
11 | |||
12 | /** | ||
13 | * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are | ||
14 | * preferable to the old integer-based handles. | ||
15 | * | ||
16 | * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid | ||
17 | * until the GPIO is released. | ||
18 | */ | ||
19 | struct gpio_desc; | ||
20 | |||
21 | /* Acquire and dispose GPIOs */ | ||
22 | struct gpio_desc *__must_check gpiod_get(struct device *dev, | ||
23 | const char *con_id); | ||
24 | struct gpio_desc *__must_check gpiod_get_index(struct device *dev, | ||
25 | const char *con_id, | ||
26 | unsigned int idx); | ||
27 | void gpiod_put(struct gpio_desc *desc); | ||
28 | |||
29 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, | ||
30 | const char *con_id); | ||
31 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, | ||
32 | const char *con_id, | ||
33 | unsigned int idx); | ||
34 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); | ||
35 | |||
36 | int gpiod_get_direction(const struct gpio_desc *desc); | ||
37 | int gpiod_direction_input(struct gpio_desc *desc); | ||
38 | int gpiod_direction_output(struct gpio_desc *desc, int value); | ||
39 | |||
40 | /* Value get/set from non-sleeping context */ | ||
41 | int gpiod_get_value(const struct gpio_desc *desc); | ||
42 | void gpiod_set_value(struct gpio_desc *desc, int value); | ||
43 | int gpiod_get_raw_value(const struct gpio_desc *desc); | ||
44 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); | ||
45 | |||
46 | /* Value get/set from sleeping context */ | ||
47 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); | ||
48 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); | ||
49 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); | ||
50 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); | ||
51 | |||
52 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); | ||
53 | |||
54 | int gpiod_is_active_low(const struct gpio_desc *desc); | ||
55 | int gpiod_cansleep(const struct gpio_desc *desc); | ||
56 | |||
57 | int gpiod_to_irq(const struct gpio_desc *desc); | ||
58 | |||
59 | /* Convert between the old gpio_ and new gpiod_ interfaces */ | ||
60 | struct gpio_desc *gpio_to_desc(unsigned gpio); | ||
61 | int desc_to_gpio(const struct gpio_desc *desc); | ||
62 | struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); | ||
63 | |||
64 | #else /* CONFIG_GPIOLIB */ | ||
65 | |||
66 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, | ||
67 | const char *con_id) | ||
68 | { | ||
69 | return ERR_PTR(-ENOSYS); | ||
70 | } | ||
71 | static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev, | ||
72 | const char *con_id, | ||
73 | unsigned int idx) | ||
74 | { | ||
75 | return ERR_PTR(-ENOSYS); | ||
76 | } | ||
77 | static inline void gpiod_put(struct gpio_desc *desc) | ||
78 | { | ||
79 | might_sleep(); | ||
80 | |||
81 | /* GPIO can never have been requested */ | ||
82 | WARN_ON(1); | ||
83 | } | ||
84 | |||
85 | static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, | ||
86 | const char *con_id) | ||
87 | { | ||
88 | return ERR_PTR(-ENOSYS); | ||
89 | } | ||
90 | static inline | ||
91 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, | ||
92 | const char *con_id, | ||
93 | unsigned int idx) | ||
94 | { | ||
95 | return ERR_PTR(-ENOSYS); | ||
96 | } | ||
97 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) | ||
98 | { | ||
99 | might_sleep(); | ||
100 | |||
101 | /* GPIO can never have been requested */ | ||
102 | WARN_ON(1); | ||
103 | } | ||
104 | |||
105 | |||
106 | static inline int gpiod_get_direction(const struct gpio_desc *desc) | ||
107 | { | ||
108 | /* GPIO can never have been requested */ | ||
109 | WARN_ON(1); | ||
110 | return -ENOSYS; | ||
111 | } | ||
112 | static inline int gpiod_direction_input(struct gpio_desc *desc) | ||
113 | { | ||
114 | /* GPIO can never have been requested */ | ||
115 | WARN_ON(1); | ||
116 | return -ENOSYS; | ||
117 | } | ||
118 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) | ||
119 | { | ||
120 | /* GPIO can never have been requested */ | ||
121 | WARN_ON(1); | ||
122 | return -ENOSYS; | ||
123 | } | ||
124 | |||
125 | |||
126 | static inline int gpiod_get_value(const struct gpio_desc *desc) | ||
127 | { | ||
128 | /* GPIO can never have been requested */ | ||
129 | WARN_ON(1); | ||
130 | return 0; | ||
131 | } | ||
132 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) | ||
133 | { | ||
134 | /* GPIO can never have been requested */ | ||
135 | WARN_ON(1); | ||
136 | } | ||
137 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) | ||
138 | { | ||
139 | /* GPIO can never have been requested */ | ||
140 | WARN_ON(1); | ||
141 | return 0; | ||
142 | } | ||
143 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) | ||
144 | { | ||
145 | /* GPIO can never have been requested */ | ||
146 | WARN_ON(1); | ||
147 | } | ||
148 | |||
149 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) | ||
150 | { | ||
151 | /* GPIO can never have been requested */ | ||
152 | WARN_ON(1); | ||
153 | return 0; | ||
154 | } | ||
155 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) | ||
156 | { | ||
157 | /* GPIO can never have been requested */ | ||
158 | WARN_ON(1); | ||
159 | } | ||
160 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) | ||
161 | { | ||
162 | /* GPIO can never have been requested */ | ||
163 | WARN_ON(1); | ||
164 | return 0; | ||
165 | } | ||
166 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, | ||
167 | int value) | ||
168 | { | ||
169 | /* GPIO can never have been requested */ | ||
170 | WARN_ON(1); | ||
171 | } | ||
172 | |||
173 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) | ||
174 | { | ||
175 | /* GPIO can never have been requested */ | ||
176 | WARN_ON(1); | ||
177 | return -ENOSYS; | ||
178 | } | ||
179 | |||
180 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) | ||
181 | { | ||
182 | /* GPIO can never have been requested */ | ||
183 | WARN_ON(1); | ||
184 | return 0; | ||
185 | } | ||
186 | static inline int gpiod_cansleep(const struct gpio_desc *desc) | ||
187 | { | ||
188 | /* GPIO can never have been requested */ | ||
189 | WARN_ON(1); | ||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static inline int gpiod_to_irq(const struct gpio_desc *desc) | ||
194 | { | ||
195 | /* GPIO can never have been requested */ | ||
196 | WARN_ON(1); | ||
197 | return -EINVAL; | ||
198 | } | ||
199 | |||
200 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) | ||
201 | { | ||
202 | return ERR_PTR(-EINVAL); | ||
203 | } | ||
204 | static inline int desc_to_gpio(const struct gpio_desc *desc) | ||
205 | { | ||
206 | /* GPIO can never have been requested */ | ||
207 | WARN_ON(1); | ||
208 | return -EINVAL; | ||
209 | } | ||
210 | static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) | ||
211 | { | ||
212 | /* GPIO can never have been requested */ | ||
213 | WARN_ON(1); | ||
214 | return ERR_PTR(-ENODEV); | ||
215 | } | ||
216 | |||
217 | |||
218 | #endif /* CONFIG_GPIOLIB */ | ||
219 | |||
220 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) | ||
221 | |||
222 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); | ||
223 | int gpiod_export_link(struct device *dev, const char *name, | ||
224 | struct gpio_desc *desc); | ||
225 | int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value); | ||
226 | void gpiod_unexport(struct gpio_desc *desc); | ||
227 | |||
228 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ | ||
229 | |||
230 | static inline int gpiod_export(struct gpio_desc *desc, | ||
231 | bool direction_may_change) | ||
232 | { | ||
233 | return -ENOSYS; | ||
234 | } | ||
235 | |||
236 | static inline int gpiod_export_link(struct device *dev, const char *name, | ||
237 | struct gpio_desc *desc) | ||
238 | { | ||
239 | return -ENOSYS; | ||
240 | } | ||
241 | |||
242 | static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) | ||
243 | { | ||
244 | return -ENOSYS; | ||
245 | } | ||
246 | |||
247 | static inline void gpiod_unexport(struct gpio_desc *desc) | ||
248 | { | ||
249 | } | ||
250 | |||
251 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ | ||
252 | |||
253 | #endif | ||
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h new file mode 100644 index 000000000000..656a27efb2c8 --- /dev/null +++ b/include/linux/gpio/driver.h | |||
@@ -0,0 +1,184 @@ | |||
1 | #ifndef __LINUX_GPIO_DRIVER_H | ||
2 | #define __LINUX_GPIO_DRIVER_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | |||
6 | struct device; | ||
7 | struct gpio_desc; | ||
8 | struct seq_file; | ||
9 | |||
10 | /** | ||
11 | * struct gpio_chip - abstract a GPIO controller | ||
12 | * @label: for diagnostics | ||
13 | * @dev: optional device providing the GPIOs | ||
14 | * @owner: helps prevent removal of modules exporting active GPIOs | ||
15 | * @list: links gpio_chips together for traversal | ||
16 | * @request: optional hook for chip-specific activation, such as | ||
17 | * enabling module power and clock; may sleep | ||
18 | * @free: optional hook for chip-specific deactivation, such as | ||
19 | * disabling module power and clock; may sleep | ||
20 | * @get_direction: returns direction for signal "offset", 0=out, 1=in, | ||
21 | * (same as GPIOF_DIR_XXX), or negative error | ||
22 | * @direction_input: configures signal "offset" as input, or returns error | ||
23 | * @direction_output: configures signal "offset" as output, or returns error | ||
24 | * @get: returns value for signal "offset"; for output signals this | ||
25 | * returns either the value actually sensed, or zero | ||
26 | * @set: assigns output value for signal "offset" | ||
27 | * @set_debounce: optional hook for setting debounce time for specified gpio in | ||
28 | * interrupt triggered gpio chips | ||
29 | * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; | ||
30 | * implementation may not sleep | ||
31 | * @dbg_show: optional routine to show contents in debugfs; default code | ||
32 | * will be used when this is omitted, but custom code can show extra | ||
33 | * state (such as pullup/pulldown configuration). | ||
34 | * @base: identifies the first GPIO number handled by this chip; or, if | ||
35 | * negative during registration, requests dynamic ID allocation. | ||
36 | * @ngpio: the number of GPIOs handled by this controller; the last GPIO | ||
37 | * handled is (base + ngpio - 1). | ||
38 | * @desc: array of ngpio descriptors. Private. | ||
39 | * @can_sleep: flag must be set iff get()/set() methods sleep, as they | ||
40 | * must while accessing GPIO expander chips over I2C or SPI | ||
41 | * @names: if set, must be an array of strings to use as alternative | ||
42 | * names for the GPIOs in this chip. Any entry in the array | ||
43 | * may be NULL if there is no alias for the GPIO, however the | ||
44 | * array must be @ngpio entries long. A name can include a single printk | ||
45 | * format specifier for an unsigned int. It is substituted by the actual | ||
46 | * number of the gpio. | ||
47 | * | ||
48 | * A gpio_chip can help platforms abstract various sources of GPIOs so | ||
49 | * they can all be accessed through a common programing interface. | ||
50 | * Example sources would be SOC controllers, FPGAs, multifunction | ||
51 | * chips, dedicated GPIO expanders, and so on. | ||
52 | * | ||
53 | * Each chip controls a number of signals, identified in method calls | ||
54 | * by "offset" values in the range 0..(@ngpio - 1). When those signals | ||
55 | * are referenced through calls like gpio_get_value(gpio), the offset | ||
56 | * is calculated by subtracting @base from the gpio number. | ||
57 | */ | ||
58 | struct gpio_chip { | ||
59 | const char *label; | ||
60 | struct device *dev; | ||
61 | struct module *owner; | ||
62 | struct list_head list; | ||
63 | |||
64 | int (*request)(struct gpio_chip *chip, | ||
65 | unsigned offset); | ||
66 | void (*free)(struct gpio_chip *chip, | ||
67 | unsigned offset); | ||
68 | int (*get_direction)(struct gpio_chip *chip, | ||
69 | unsigned offset); | ||
70 | int (*direction_input)(struct gpio_chip *chip, | ||
71 | unsigned offset); | ||
72 | int (*direction_output)(struct gpio_chip *chip, | ||
73 | unsigned offset, int value); | ||
74 | int (*get)(struct gpio_chip *chip, | ||
75 | unsigned offset); | ||
76 | void (*set)(struct gpio_chip *chip, | ||
77 | unsigned offset, int value); | ||
78 | int (*set_debounce)(struct gpio_chip *chip, | ||
79 | unsigned offset, | ||
80 | unsigned debounce); | ||
81 | |||
82 | int (*to_irq)(struct gpio_chip *chip, | ||
83 | unsigned offset); | ||
84 | |||
85 | void (*dbg_show)(struct seq_file *s, | ||
86 | struct gpio_chip *chip); | ||
87 | int base; | ||
88 | u16 ngpio; | ||
89 | struct gpio_desc *desc; | ||
90 | const char *const *names; | ||
91 | unsigned can_sleep:1; | ||
92 | unsigned exported:1; | ||
93 | |||
94 | #if defined(CONFIG_OF_GPIO) | ||
95 | /* | ||
96 | * If CONFIG_OF is enabled, then all GPIO controllers described in the | ||
97 | * device tree automatically may have an OF translation | ||
98 | */ | ||
99 | struct device_node *of_node; | ||
100 | int of_gpio_n_cells; | ||
101 | int (*of_xlate)(struct gpio_chip *gc, | ||
102 | const struct of_phandle_args *gpiospec, u32 *flags); | ||
103 | #endif | ||
104 | #ifdef CONFIG_PINCTRL | ||
105 | /* | ||
106 | * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally | ||
107 | * describe the actual pin range which they serve in an SoC. This | ||
108 | * information would be used by pinctrl subsystem to configure | ||
109 | * corresponding pins for gpio usage. | ||
110 | */ | ||
111 | struct list_head pin_ranges; | ||
112 | #endif | ||
113 | }; | ||
114 | |||
115 | extern const char *gpiochip_is_requested(struct gpio_chip *chip, | ||
116 | unsigned offset); | ||
117 | |||
118 | /* add/remove chips */ | ||
119 | extern int gpiochip_add(struct gpio_chip *chip); | ||
120 | extern int __must_check gpiochip_remove(struct gpio_chip *chip); | ||
121 | extern struct gpio_chip *gpiochip_find(void *data, | ||
122 | int (*match)(struct gpio_chip *chip, void *data)); | ||
123 | |||
124 | /* lock/unlock as IRQ */ | ||
125 | int gpiod_lock_as_irq(struct gpio_desc *desc); | ||
126 | void gpiod_unlock_as_irq(struct gpio_desc *desc); | ||
127 | |||
128 | /** | ||
129 | * Lookup table for associating GPIOs to specific devices and functions using | ||
130 | * platform data. | ||
131 | */ | ||
132 | struct gpiod_lookup { | ||
133 | struct list_head list; | ||
134 | /* | ||
135 | * name of the chip the GPIO belongs to | ||
136 | */ | ||
137 | const char *chip_label; | ||
138 | /* | ||
139 | * hardware number (i.e. relative to the chip) of the GPIO | ||
140 | */ | ||
141 | u16 chip_hwnum; | ||
142 | /* | ||
143 | * name of device that can claim this GPIO | ||
144 | */ | ||
145 | const char *dev_id; | ||
146 | /* | ||
147 | * name of the GPIO from the device's point of view | ||
148 | */ | ||
149 | const char *con_id; | ||
150 | /* | ||
151 | * index of the GPIO in case several GPIOs share the same name | ||
152 | */ | ||
153 | unsigned int idx; | ||
154 | /* | ||
155 | * mask of GPIOF_* values | ||
156 | */ | ||
157 | unsigned long flags; | ||
158 | }; | ||
159 | |||
160 | /* | ||
161 | * Simple definition of a single GPIO under a con_id | ||
162 | */ | ||
163 | #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _dev_id, _con_id, _flags) \ | ||
164 | GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, 0, _flags) | ||
165 | |||
166 | /* | ||
167 | * Use this macro if you need to have several GPIOs under the same con_id. | ||
168 | * Each GPIO needs to use a different index and can be accessed using | ||
169 | * gpiod_get_index() | ||
170 | */ | ||
171 | #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, _idx, \ | ||
172 | _flags) \ | ||
173 | { \ | ||
174 | .chip_label = _chip_label, \ | ||
175 | .chip_hwnum = _chip_hwnum, \ | ||
176 | .dev_id = _dev_id, \ | ||
177 | .con_id = _con_id, \ | ||
178 | .idx = _idx, \ | ||
179 | .flags = _flags, \ | ||
180 | } | ||
181 | |||
182 | void gpiod_add_table(struct gpiod_lookup *table, size_t size); | ||
183 | |||
184 | #endif | ||
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index a83dc6f5008e..f14123a5a9df 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
21 | #include <linux/of.h> | 21 | #include <linux/of.h> |
22 | #include <linux/gpio/consumer.h> | ||
22 | 23 | ||
23 | struct device_node; | 24 | struct device_node; |
24 | 25 | ||
@@ -47,7 +48,7 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) | |||
47 | return container_of(gc, struct of_mm_gpio_chip, gc); | 48 | return container_of(gc, struct of_mm_gpio_chip, gc); |
48 | } | 49 | } |
49 | 50 | ||
50 | extern int of_get_named_gpio_flags(struct device_node *np, | 51 | extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
51 | const char *list_name, int index, enum of_gpio_flags *flags); | 52 | const char *list_name, int index, enum of_gpio_flags *flags); |
52 | 53 | ||
53 | extern int of_mm_gpiochip_add(struct device_node *np, | 54 | extern int of_mm_gpiochip_add(struct device_node *np, |
@@ -62,10 +63,10 @@ extern int of_gpio_simple_xlate(struct gpio_chip *gc, | |||
62 | #else /* CONFIG_OF_GPIO */ | 63 | #else /* CONFIG_OF_GPIO */ |
63 | 64 | ||
64 | /* Drivers may not strictly depend on the GPIO support, so let them link. */ | 65 | /* Drivers may not strictly depend on the GPIO support, so let them link. */ |
65 | static inline int of_get_named_gpio_flags(struct device_node *np, | 66 | static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
66 | const char *list_name, int index, enum of_gpio_flags *flags) | 67 | const char *list_name, int index, enum of_gpio_flags *flags) |
67 | { | 68 | { |
68 | return -ENOSYS; | 69 | return ERR_PTR(-ENOSYS); |
69 | } | 70 | } |
70 | 71 | ||
71 | static inline int of_gpio_simple_xlate(struct gpio_chip *gc, | 72 | static inline int of_gpio_simple_xlate(struct gpio_chip *gc, |
@@ -80,6 +81,18 @@ static inline void of_gpiochip_remove(struct gpio_chip *gc) { } | |||
80 | 81 | ||
81 | #endif /* CONFIG_OF_GPIO */ | 82 | #endif /* CONFIG_OF_GPIO */ |
82 | 83 | ||
84 | static inline int of_get_named_gpio_flags(struct device_node *np, | ||
85 | const char *list_name, int index, enum of_gpio_flags *flags) | ||
86 | { | ||
87 | struct gpio_desc *desc; | ||
88 | desc = of_get_named_gpiod_flags(np, list_name, index, flags); | ||
89 | |||
90 | if (IS_ERR(desc)) | ||
91 | return PTR_ERR(desc); | ||
92 | else | ||
93 | return desc_to_gpio(desc); | ||
94 | } | ||
95 | |||
83 | /** | 96 | /** |
84 | * of_gpio_named_count() - Count GPIOs for a device | 97 | * of_gpio_named_count() - Count GPIOs for a device |
85 | * @np: device node to count GPIOs for | 98 | * @np: device node to count GPIOs for |
@@ -117,15 +130,21 @@ static inline int of_gpio_count(struct device_node *np) | |||
117 | } | 130 | } |
118 | 131 | ||
119 | /** | 132 | /** |
120 | * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API | 133 | * of_get_gpiod_flags() - Get a GPIO descriptor and flags to use with GPIO API |
121 | * @np: device node to get GPIO from | 134 | * @np: device node to get GPIO from |
122 | * @index: index of the GPIO | 135 | * @index: index of the GPIO |
123 | * @flags: a flags pointer to fill in | 136 | * @flags: a flags pointer to fill in |
124 | * | 137 | * |
125 | * Returns GPIO number to use with Linux generic GPIO API, or one of the errno | 138 | * Returns GPIO descriptor to use with Linux generic GPIO API, or a errno |
126 | * value on the error condition. If @flags is not NULL the function also fills | 139 | * value on the error condition. If @flags is not NULL the function also fills |
127 | * in flags for the GPIO. | 140 | * in flags for the GPIO. |
128 | */ | 141 | */ |
142 | static inline struct gpio_desc *of_get_gpiod_flags(struct device_node *np, | ||
143 | int index, enum of_gpio_flags *flags) | ||
144 | { | ||
145 | return of_get_named_gpiod_flags(np, "gpios", index, flags); | ||
146 | } | ||
147 | |||
129 | static inline int of_get_gpio_flags(struct device_node *np, int index, | 148 | static inline int of_get_gpio_flags(struct device_node *np, int index, |
130 | enum of_gpio_flags *flags) | 149 | enum of_gpio_flags *flags) |
131 | { | 150 | { |