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 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
28 if (!desc
&& gpio_is_valid(gpio
))
31 err
= gpiod_request(desc
, label
);
35 if (flags
& GPIOF_OPEN_DRAIN
)
36 set_bit(FLAG_OPEN_DRAIN
, &desc
->flags
);
38 if (flags
& GPIOF_OPEN_SOURCE
)
39 set_bit(FLAG_OPEN_SOURCE
, &desc
->flags
);
41 if (flags
& GPIOF_ACTIVE_LOW
)
42 set_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
44 if (flags
& GPIOF_DIR_IN
)
45 err
= gpiod_direction_input(desc
);
47 err
= gpiod_direction_output_raw(desc
,
48 (flags
& GPIOF_INIT_HIGH
) ? 1 : 0);
53 if (flags
& GPIOF_EXPORT
) {
54 err
= gpiod_export(desc
, flags
& GPIOF_EXPORT_CHANGEABLE
);
65 EXPORT_SYMBOL_GPL(gpio_request_one
);
67 int gpio_request(unsigned gpio
, const char *label
)
69 struct gpio_desc
*desc
= gpio_to_desc(gpio
);
71 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
72 if (!desc
&& gpio_is_valid(gpio
))
75 return gpiod_request(desc
, label
);
77 EXPORT_SYMBOL_GPL(gpio_request
);
80 * gpio_request_array - request multiple GPIOs in a single call
81 * @array: array of the 'struct gpio'
82 * @num: how many GPIOs in the array
84 int gpio_request_array(const struct gpio
*array
, size_t num
)
88 for (i
= 0; i
< num
; i
++, array
++) {
89 err
= gpio_request_one(array
->gpio
, array
->flags
, array
->label
);
97 gpio_free((--array
)->gpio
);
100 EXPORT_SYMBOL_GPL(gpio_request_array
);
103 * gpio_free_array - release multiple GPIOs in a single call
104 * @array: array of the 'struct gpio'
105 * @num: how many GPIOs in the array
107 void gpio_free_array(const struct gpio
*array
, size_t num
)
110 gpio_free((array
++)->gpio
);
112 EXPORT_SYMBOL_GPL(gpio_free_array
);