1 #include <linux/gpio/consumer.h>
2 #include <linux/gpio/driver.h>
4 #include <linux/gpio.h>
8 void gpio_free(unsigned gpio)
10 gpiod_free(gpio_to_desc(gpio));
12 EXPORT_SYMBOL_GPL(gpio_free);
15 * gpio_request_one - request a single GPIO with initial configuration
16 * @gpio: the GPIO number
17 * @flags: GPIO configuration as specified by GPIOF_*
18 * @label: a literal description string of this GPIO
20 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
22 struct gpio_desc *desc;
25 desc = gpio_to_desc(gpio);
27 err = gpiod_request(desc, label);
31 if (flags & GPIOF_OPEN_DRAIN)
32 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
34 if (flags & GPIOF_OPEN_SOURCE)
35 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
37 if (flags & GPIOF_DIR_IN)
38 err = gpiod_direction_input(desc);
40 err = gpiod_direction_output_raw(desc,
41 (flags & GPIOF_INIT_HIGH) ? 1 : 0);
46 if (flags & GPIOF_EXPORT) {
47 err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE);
58 EXPORT_SYMBOL_GPL(gpio_request_one);
60 int gpio_request(unsigned gpio, const char *label)
62 return gpiod_request(gpio_to_desc(gpio), label);
64 EXPORT_SYMBOL_GPL(gpio_request);
67 * gpio_request_array - request multiple GPIOs in a single call
68 * @array: array of the 'struct gpio'
69 * @num: how many GPIOs in the array
71 int gpio_request_array(const struct gpio *array, size_t num)
75 for (i = 0; i < num; i++, array++) {
76 err = gpio_request_one(array->gpio, array->flags, array->label);
84 gpio_free((--array)->gpio);
87 EXPORT_SYMBOL_GPL(gpio_request_array);
90 * gpio_free_array - release multiple GPIOs in a single call
91 * @array: array of the 'struct gpio'
92 * @num: how many GPIOs in the array
94 void gpio_free_array(const struct gpio *array, size_t num)
97 gpio_free((array++)->gpio);
99 EXPORT_SYMBOL_GPL(gpio_free_array);
101 int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
103 return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset));
105 EXPORT_SYMBOL_GPL(gpio_lock_as_irq);
107 void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset)
109 return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset));
111 EXPORT_SYMBOL_GPL(gpio_unlock_as_irq);