printf: Remove unused 'bprintf'
[drm/drm-misc.git] / drivers / gpio / gpiolib-legacy.c
blobaeae6df8bec993314157a494cc068c5f6a090217
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bitops.h>
3 #include <linux/device.h>
4 #include <linux/errno.h>
5 #include <linux/export.h>
6 #include <linux/gfp.h>
8 #include <linux/gpio/consumer.h>
9 #include <linux/gpio/driver.h>
11 #include <linux/gpio.h>
13 #include "gpiolib.h"
16 * **DEPRECATED** This function is deprecated and must not be used in new code.
18 void gpio_free(unsigned gpio)
20 gpiod_free(gpio_to_desc(gpio));
22 EXPORT_SYMBOL_GPL(gpio_free);
24 /**
25 * gpio_request_one - request a single GPIO with initial configuration
26 * @gpio: the GPIO number
27 * @flags: GPIO configuration as specified by GPIOF_*
28 * @label: a literal description string of this GPIO
30 * **DEPRECATED** This function is deprecated and must not be used in new code.
32 * Returns:
33 * 0 on success, or negative errno on failure.
35 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
37 struct gpio_desc *desc;
38 int err;
40 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
41 desc = gpio_to_desc(gpio);
42 if (!desc)
43 return -EPROBE_DEFER;
45 err = gpiod_request(desc, label);
46 if (err)
47 return err;
49 if (flags & GPIOF_IN)
50 err = gpiod_direction_input(desc);
51 else
52 err = gpiod_direction_output_raw(desc, !!(flags & GPIOF_OUT_INIT_HIGH));
54 if (err)
55 goto free_gpio;
57 return 0;
59 free_gpio:
60 gpiod_free(desc);
61 return err;
63 EXPORT_SYMBOL_GPL(gpio_request_one);
66 * **DEPRECATED** This function is deprecated and must not be used in new code.
68 int gpio_request(unsigned gpio, const char *label)
70 struct gpio_desc *desc;
72 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
73 desc = gpio_to_desc(gpio);
74 if (!desc)
75 return -EPROBE_DEFER;
77 return gpiod_request(desc, label);
79 EXPORT_SYMBOL_GPL(gpio_request);
81 static void devm_gpio_release(struct device *dev, void *res)
83 unsigned *gpio = res;
85 gpio_free(*gpio);
88 /**
89 * devm_gpio_request - request a GPIO for a managed device
90 * @dev: device to request the GPIO for
91 * @gpio: GPIO to allocate
92 * @label: the name of the requested GPIO
94 * Except for the extra @dev argument, this function takes the
95 * same arguments and performs the same function as gpio_request().
96 * GPIOs requested with this function will be automatically freed
97 * on driver detach.
99 * **DEPRECATED** This function is deprecated and must not be used in new code.
101 * Returns:
102 * 0 on success, or negative errno on failure.
104 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
106 unsigned *dr;
107 int rc;
109 dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
110 if (!dr)
111 return -ENOMEM;
113 rc = gpio_request(gpio, label);
114 if (rc) {
115 devres_free(dr);
116 return rc;
119 *dr = gpio;
120 devres_add(dev, dr);
122 return 0;
124 EXPORT_SYMBOL_GPL(devm_gpio_request);
127 * devm_gpio_request_one - request a single GPIO with initial setup
128 * @dev: device to request for
129 * @gpio: the GPIO number
130 * @flags: GPIO configuration as specified by GPIOF_*
131 * @label: a literal description string of this GPIO
133 * **DEPRECATED** This function is deprecated and must not be used in new code.
135 * Returns:
136 * 0 on success, or negative errno on failure.
138 int devm_gpio_request_one(struct device *dev, unsigned gpio,
139 unsigned long flags, const char *label)
141 unsigned *dr;
142 int rc;
144 dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
145 if (!dr)
146 return -ENOMEM;
148 rc = gpio_request_one(gpio, flags, label);
149 if (rc) {
150 devres_free(dr);
151 return rc;
154 *dr = gpio;
155 devres_add(dev, dr);
157 return 0;
159 EXPORT_SYMBOL_GPL(devm_gpio_request_one);