1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/gpio/consumer.h>
3 #include <linux/gpio/driver.h>
5 #include <linux/gpio.h>
9 void gpio_free(unsigned gpio)
11 gpiod_free(gpio_to_desc(gpio));
13 EXPORT_SYMBOL_GPL(gpio_free);
16 * gpio_request_one - request a single GPIO with initial configuration
17 * @gpio: the GPIO number
18 * @flags: GPIO configuration as specified by GPIOF_*
19 * @label: a literal description string of this GPIO
21 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
23 struct gpio_desc *desc;
26 desc = gpio_to_desc(gpio);
28 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
29 if (!desc && gpio_is_valid(gpio))
32 err = gpiod_request(desc, label);
36 if (flags & GPIOF_ACTIVE_LOW)
37 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
39 if (flags & GPIOF_DIR_IN)
40 err = gpiod_direction_input(desc);
42 err = gpiod_direction_output_raw(desc,
43 (flags & GPIOF_INIT_HIGH) ? 1 : 0);
54 EXPORT_SYMBOL_GPL(gpio_request_one);
56 int gpio_request(unsigned gpio, const char *label)
58 struct gpio_desc *desc = gpio_to_desc(gpio);
60 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
61 if (!desc && gpio_is_valid(gpio))
64 return gpiod_request(desc, label);
66 EXPORT_SYMBOL_GPL(gpio_request);
69 * gpio_request_array - request multiple GPIOs in a single call
70 * @array: array of the 'struct gpio'
71 * @num: how many GPIOs in the array
73 int gpio_request_array(const struct gpio *array, size_t num)
77 for (i = 0; i < num; i++, array++) {
78 err = gpio_request_one(array->gpio, array->flags, array->label);
86 gpio_free((--array)->gpio);
89 EXPORT_SYMBOL_GPL(gpio_request_array);
92 * gpio_free_array - release multiple GPIOs in a single call
93 * @array: array of the 'struct gpio'
94 * @num: how many GPIOs in the array
96 void gpio_free_array(const struct gpio *array, size_t num)
99 gpio_free((array++)->gpio);
101 EXPORT_SYMBOL_GPL(gpio_free_array);