2018-09-25 07:08:48 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-07-01 05:45:16 +00:00
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/gpio/driver.h>
|
|
|
|
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
|
|
|
|
#include "gpiolib.h"
|
|
|
|
|
2024-01-04 18:20:34 +00:00
|
|
|
/*
|
|
|
|
* **DEPRECATED** This function is deprecated and must not be used in new code.
|
|
|
|
*/
|
2014-07-01 05:45:16 +00:00
|
|
|
void gpio_free(unsigned gpio)
|
|
|
|
{
|
|
|
|
gpiod_free(gpio_to_desc(gpio));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(gpio_free);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gpio_request_one - request a single GPIO with initial configuration
|
|
|
|
* @gpio: the GPIO number
|
|
|
|
* @flags: GPIO configuration as specified by GPIOF_*
|
|
|
|
* @label: a literal description string of this GPIO
|
2024-01-04 18:20:34 +00:00
|
|
|
*
|
|
|
|
* **DEPRECATED** This function is deprecated and must not be used in new code.
|
2014-07-01 05:45:16 +00:00
|
|
|
*/
|
|
|
|
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
|
|
|
|
{
|
|
|
|
struct gpio_desc *desc;
|
|
|
|
int err;
|
|
|
|
|
2014-12-02 14:15:05 +00:00
|
|
|
/* Compatibility: assume unavailable "valid" GPIOs will appear later */
|
2024-02-21 21:31:56 +00:00
|
|
|
desc = gpio_to_desc(gpio);
|
|
|
|
if (!desc)
|
2014-12-02 14:15:05 +00:00
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
2016-07-03 16:32:05 +00:00
|
|
|
err = gpiod_request(desc, label);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2014-07-21 18:12:16 +00:00
|
|
|
if (flags & GPIOF_ACTIVE_LOW)
|
|
|
|
set_bit(FLAG_ACTIVE_LOW, &desc->flags);
|
|
|
|
|
2014-07-01 05:45:16 +00:00
|
|
|
if (flags & GPIOF_DIR_IN)
|
|
|
|
err = gpiod_direction_input(desc);
|
|
|
|
else
|
|
|
|
err = gpiod_direction_output_raw(desc,
|
|
|
|
(flags & GPIOF_INIT_HIGH) ? 1 : 0);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto free_gpio;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_gpio:
|
|
|
|
gpiod_free(desc);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(gpio_request_one);
|
|
|
|
|
2024-01-04 18:20:34 +00:00
|
|
|
/*
|
|
|
|
* **DEPRECATED** This function is deprecated and must not be used in new code.
|
|
|
|
*/
|
2014-07-01 05:45:16 +00:00
|
|
|
int gpio_request(unsigned gpio, const char *label)
|
|
|
|
{
|
2024-02-21 21:31:56 +00:00
|
|
|
struct gpio_desc *desc;
|
2014-12-02 14:15:05 +00:00
|
|
|
|
|
|
|
/* Compatibility: assume unavailable "valid" GPIOs will appear later */
|
2024-02-21 21:31:56 +00:00
|
|
|
desc = gpio_to_desc(gpio);
|
|
|
|
if (!desc)
|
2014-12-02 14:15:05 +00:00
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
return gpiod_request(desc, label);
|
2014-07-01 05:45:16 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(gpio_request);
|