xref: /linux/drivers/gpio/gpiolib-legacy.c (revision 2697b79a469b68e3ad3640f55284359c1396278d)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/gpio/consumer.h>
3 #include <linux/gpio/driver.h>
4 
5 #include <linux/gpio.h>
6 
7 #include "gpiolib.h"
8 
9 /*
10  * **DEPRECATED** This function is deprecated and must not be used in new code.
11  */
12 void gpio_free(unsigned gpio)
13 {
14 	gpiod_free(gpio_to_desc(gpio));
15 }
16 EXPORT_SYMBOL_GPL(gpio_free);
17 
18 /**
19  * gpio_request_one - request a single GPIO with initial configuration
20  * @gpio:	the GPIO number
21  * @flags:	GPIO configuration as specified by GPIOF_*
22  * @label:	a literal description string of this GPIO
23  *
24  * **DEPRECATED** This function is deprecated and must not be used in new code.
25  */
26 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
27 {
28 	struct gpio_desc *desc;
29 	int err;
30 
31 	/* Compatibility: assume unavailable "valid" GPIOs will appear later */
32 	desc = gpio_to_desc(gpio);
33 	if (!desc)
34 		return -EPROBE_DEFER;
35 
36 	err = gpiod_request(desc, label);
37 	if (err)
38 		return err;
39 
40 	if (flags & GPIOF_ACTIVE_LOW)
41 		set_bit(FLAG_ACTIVE_LOW, &desc->flags);
42 
43 	if (flags & GPIOF_DIR_IN)
44 		err = gpiod_direction_input(desc);
45 	else
46 		err = gpiod_direction_output_raw(desc,
47 				(flags & GPIOF_INIT_HIGH) ? 1 : 0);
48 
49 	if (err)
50 		goto free_gpio;
51 
52 	return 0;
53 
54  free_gpio:
55 	gpiod_free(desc);
56 	return err;
57 }
58 EXPORT_SYMBOL_GPL(gpio_request_one);
59 
60 /*
61  * **DEPRECATED** This function is deprecated and must not be used in new code.
62  */
63 int gpio_request(unsigned gpio, const char *label)
64 {
65 	struct gpio_desc *desc;
66 
67 	/* Compatibility: assume unavailable "valid" GPIOs will appear later */
68 	desc = gpio_to_desc(gpio);
69 	if (!desc)
70 		return -EPROBE_DEFER;
71 
72 	return gpiod_request(desc, label);
73 }
74 EXPORT_SYMBOL_GPL(gpio_request);
75