Merge tag 'x86_cpu_for_v6.11_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / drivers / gpio / gpiolib-legacy.c
CommitLineData
dae5f0af 1// SPDX-License-Identifier: GPL-2.0
122c94de
AC
2#include <linux/gpio/consumer.h>
3#include <linux/gpio/driver.h>
4
5#include <linux/gpio.h>
6
7#include "gpiolib.h"
8
f4028860
BG
9/*
10 * **DEPRECATED** This function is deprecated and must not be used in new code.
11 */
122c94de
AC
12void gpio_free(unsigned gpio)
13{
14 gpiod_free(gpio_to_desc(gpio));
15}
16EXPORT_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
f4028860
BG
23 *
24 * **DEPRECATED** This function is deprecated and must not be used in new code.
122c94de
AC
25 */
26int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
27{
28 struct gpio_desc *desc;
29 int err;
30
0e9a5edf 31 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
8a7a6103
AS
32 desc = gpio_to_desc(gpio);
33 if (!desc)
0e9a5edf
AC
34 return -EPROBE_DEFER;
35
85b03b30
JH
36 err = gpiod_request(desc, label);
37 if (err)
38 return err;
39
2be00173
GR
40 if (flags & GPIOF_ACTIVE_LOW)
41 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
42
122c94de
AC
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
122c94de
AC
52 return 0;
53
54 free_gpio:
55 gpiod_free(desc);
56 return err;
57}
58EXPORT_SYMBOL_GPL(gpio_request_one);
59
f4028860
BG
60/*
61 * **DEPRECATED** This function is deprecated and must not be used in new code.
62 */
122c94de
AC
63int gpio_request(unsigned gpio, const char *label)
64{
8a7a6103 65 struct gpio_desc *desc;
0e9a5edf
AC
66
67 /* Compatibility: assume unavailable "valid" GPIOs will appear later */
8a7a6103
AS
68 desc = gpio_to_desc(gpio);
69 if (!desc)
0e9a5edf
AC
70 return -EPROBE_DEFER;
71
72 return gpiod_request(desc, label);
122c94de
AC
73}
74EXPORT_SYMBOL_GPL(gpio_request);