2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-11-30 11:03:05 +01:00
|
|
|
/*
|
2024-05-08 13:17:01 +03:00
|
|
|
* NOTE: This header *must not* be included.
|
2017-11-30 11:03:05 +01:00
|
|
|
*
|
|
|
|
|
* This is the LEGACY GPIO bulk include file, including legacy APIs. It is
|
|
|
|
|
* used for GPIO drivers still referencing the global GPIO numberspace,
|
|
|
|
|
* and should not be included in new code.
|
|
|
|
|
*
|
|
|
|
|
* If you're implementing a GPIO driver, only include <linux/gpio/driver.h>
|
|
|
|
|
* If you're implementing a GPIO consumer, only include <linux/gpio/consumer.h>
|
|
|
|
|
*/
|
2008-03-04 14:28:27 -08:00
|
|
|
#ifndef __LINUX_GPIO_H
|
|
|
|
|
#define __LINUX_GPIO_H
|
|
|
|
|
|
2023-02-08 17:37:22 +02:00
|
|
|
#include <linux/types.h>
|
2025-07-22 17:35:43 +02:00
|
|
|
#ifdef CONFIG_GPIOLIB
|
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIOLIB_LEGACY
|
2012-04-15 10:52:54 +01:00
|
|
|
|
2023-02-08 19:07:28 +02:00
|
|
|
struct device;
|
|
|
|
|
|
2011-06-14 17:05:11 -07:00
|
|
|
/* make these flag values available regardless of GPIO kconfig options */
|
2024-08-28 17:23:58 +03:00
|
|
|
#define GPIOF_IN ((1 << 0))
|
|
|
|
|
#define GPIOF_OUT_INIT_LOW ((0 << 0) | (0 << 1))
|
|
|
|
|
#define GPIOF_OUT_INIT_HIGH ((0 << 0) | (1 << 1))
|
2011-06-14 17:05:11 -07:00
|
|
|
|
2013-03-28 04:34:56 -07:00
|
|
|
#ifdef CONFIG_GPIOLIB
|
2023-02-08 17:37:22 +02:00
|
|
|
/*
|
|
|
|
|
* "valid" GPIO numbers are nonnegative and may be passed to
|
|
|
|
|
* setup routines like gpio_request(). Only some valid numbers
|
|
|
|
|
* can successfully be requested and used.
|
|
|
|
|
*
|
|
|
|
|
* Invalid GPIO numbers are useful for indicating no-such-GPIO in
|
|
|
|
|
* platform data and other tables.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool gpio_is_valid(int number)
|
2012-04-15 10:52:54 +01:00
|
|
|
{
|
2023-02-08 17:37:22 +02:00
|
|
|
/* only non-negative numbers are valid */
|
|
|
|
|
return number >= 0;
|
2012-04-15 10:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 17:37:22 +02:00
|
|
|
/*
|
|
|
|
|
* Platforms may implement their GPIO interface with library code,
|
|
|
|
|
* at a small performance cost for non-inlined operations and some
|
|
|
|
|
* extra memory (for code and for per-GPIO table entries).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Always use the library code for GPIO management calls,
|
|
|
|
|
* or when sleeping may be involved.
|
|
|
|
|
*/
|
|
|
|
|
int gpio_request(unsigned gpio, const char *label);
|
|
|
|
|
void gpio_free(unsigned gpio);
|
|
|
|
|
|
|
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
2012-04-15 10:52:54 +01:00
|
|
|
{
|
2023-02-08 17:37:22 +02:00
|
|
|
return gpiod_direction_input(gpio_to_desc(gpio));
|
|
|
|
|
}
|
|
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
|
|
|
|
{
|
|
|
|
|
return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
|
2012-04-15 10:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-08 17:37:22 +02:00
|
|
|
static inline int gpio_get_value_cansleep(unsigned gpio)
|
2012-04-15 10:52:54 +01:00
|
|
|
{
|
2023-02-08 17:37:22 +02:00
|
|
|
return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
|
|
|
|
|
}
|
|
|
|
|
static inline void gpio_set_value_cansleep(unsigned gpio, int value)
|
|
|
|
|
{
|
2025-02-20 10:56:59 +01:00
|
|
|
gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
|
2023-02-08 17:37:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int gpio_get_value(unsigned gpio)
|
|
|
|
|
{
|
|
|
|
|
return gpiod_get_raw_value(gpio_to_desc(gpio));
|
|
|
|
|
}
|
|
|
|
|
static inline void gpio_set_value(unsigned gpio, int value)
|
|
|
|
|
{
|
2025-02-20 10:56:59 +01:00
|
|
|
gpiod_set_raw_value(gpio_to_desc(gpio), value);
|
2023-02-08 17:37:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int gpio_to_irq(unsigned gpio)
|
|
|
|
|
{
|
|
|
|
|
return gpiod_to_irq(gpio_to_desc(gpio));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
|
|
|
|
|
|
2013-10-25 12:59:05 +02:00
|
|
|
int devm_gpio_request_one(struct device *dev, unsigned gpio,
|
|
|
|
|
unsigned long flags, const char *label);
|
|
|
|
|
|
2013-03-28 04:34:56 -07:00
|
|
|
#else /* ! CONFIG_GPIOLIB */
|
2008-03-04 14:28:27 -08:00
|
|
|
|
2008-10-15 22:03:12 -07:00
|
|
|
#include <linux/kernel.h>
|
2008-05-23 13:04:58 -07:00
|
|
|
|
2023-02-08 19:07:28 +02:00
|
|
|
#include <asm/bug.h>
|
|
|
|
|
#include <asm/errno.h>
|
2009-09-22 16:46:33 -07:00
|
|
|
|
2011-05-10 16:23:07 -07:00
|
|
|
static inline bool gpio_is_valid(int number)
|
2008-03-04 14:28:27 -08:00
|
|
|
{
|
2011-05-10 16:23:07 -07:00
|
|
|
return false;
|
2008-03-04 14:28:27 -08:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 17:26:46 -08:00
|
|
|
static inline int gpio_request(unsigned gpio, const char *label)
|
2008-03-04 14:28:27 -08:00
|
|
|
{
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 09:34:29 +01:00
|
|
|
static inline int gpio_request_one(unsigned gpio,
|
2011-01-12 17:00:24 -08:00
|
|
|
unsigned long flags, const char *label)
|
|
|
|
|
{
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-04 14:28:27 -08:00
|
|
|
static inline void gpio_free(unsigned gpio)
|
|
|
|
|
{
|
2008-10-15 22:03:12 -07:00
|
|
|
might_sleep();
|
|
|
|
|
|
2008-03-04 14:28:27 -08:00
|
|
|
/* GPIO can never have been requested */
|
2012-04-04 16:14:48 +01:00
|
|
|
WARN_ON(1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 17:26:46 -08:00
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
2008-03-04 14:28:27 -08:00
|
|
|
{
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 17:26:46 -08:00
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
2008-03-04 14:28:27 -08:00
|
|
|
{
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int gpio_get_value(unsigned gpio)
|
|
|
|
|
{
|
|
|
|
|
/* GPIO can never have been requested or set as {in,out}put */
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void gpio_set_value(unsigned gpio, int value)
|
|
|
|
|
{
|
|
|
|
|
/* GPIO can never have been requested or set as output */
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int gpio_get_value_cansleep(unsigned gpio)
|
|
|
|
|
{
|
|
|
|
|
/* GPIO can never have been requested or set as {in,out}put */
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void gpio_set_value_cansleep(unsigned gpio, int value)
|
|
|
|
|
{
|
|
|
|
|
/* GPIO can never have been requested or set as output */
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int gpio_to_irq(unsigned gpio)
|
|
|
|
|
{
|
|
|
|
|
/* GPIO can never have been requested or set as input */
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 12:59:05 +02:00
|
|
|
static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
|
|
|
|
|
unsigned long flags, const char *label)
|
|
|
|
|
{
|
|
|
|
|
WARN_ON(1);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 04:34:56 -07:00
|
|
|
#endif /* ! CONFIG_GPIOLIB */
|
2025-07-22 17:35:43 +02:00
|
|
|
#endif /* CONFIG_GPIOLIB_LEGACY */
|
2008-03-04 14:28:27 -08:00
|
|
|
#endif /* __LINUX_GPIO_H */
|