2008-03-04 22:28:27 +00:00
|
|
|
#ifndef __LINUX_GPIO_H
|
|
|
|
#define __LINUX_GPIO_H
|
|
|
|
|
2012-04-15 09:52:54 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
/* see Documentation/gpio.txt */
|
|
|
|
|
2011-06-15 00:05:11 +00:00
|
|
|
/* make these flag values available regardless of GPIO kconfig options */
|
|
|
|
#define GPIOF_DIR_OUT (0 << 0)
|
|
|
|
#define GPIOF_DIR_IN (1 << 0)
|
|
|
|
|
|
|
|
#define GPIOF_INIT_LOW (0 << 1)
|
|
|
|
#define GPIOF_INIT_HIGH (1 << 1)
|
|
|
|
|
|
|
|
#define GPIOF_IN (GPIOF_DIR_IN)
|
|
|
|
#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
|
|
|
|
#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
|
|
|
|
|
2013-10-17 17:21:36 +00:00
|
|
|
/* Gpio pin is active-low */
|
|
|
|
#define GPIOF_ACTIVE_LOW (1 << 2)
|
|
|
|
|
2012-02-17 14:56:21 +00:00
|
|
|
/* Gpio pin is open drain */
|
2013-10-17 17:21:36 +00:00
|
|
|
#define GPIOF_OPEN_DRAIN (1 << 3)
|
2012-02-17 14:56:21 +00:00
|
|
|
|
2012-02-17 14:56:22 +00:00
|
|
|
/* Gpio pin is open source */
|
2013-10-17 17:21:36 +00:00
|
|
|
#define GPIOF_OPEN_SOURCE (1 << 4)
|
2012-02-17 14:56:22 +00:00
|
|
|
|
2013-10-17 17:21:36 +00:00
|
|
|
#define GPIOF_EXPORT (1 << 5)
|
|
|
|
#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
|
2011-12-13 17:34:01 +00:00
|
|
|
#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
|
|
|
|
#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
|
|
|
|
|
2011-10-24 13:24:10 +00:00
|
|
|
/**
|
|
|
|
* struct gpio - a structure describing a GPIO with configuration
|
|
|
|
* @gpio: the GPIO number
|
|
|
|
* @flags: GPIO configuration as specified by GPIOF_*
|
|
|
|
* @label: a literal description string of this GPIO
|
|
|
|
*/
|
|
|
|
struct gpio {
|
|
|
|
unsigned gpio;
|
|
|
|
unsigned long flags;
|
|
|
|
const char *label;
|
|
|
|
};
|
|
|
|
|
2013-03-28 11:34:56 +00:00
|
|
|
#ifdef CONFIG_GPIOLIB
|
2012-04-15 09:52:54 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
|
2008-03-04 22:28:27 +00:00
|
|
|
#include <asm/gpio.h>
|
2012-04-15 09:52:54 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include <asm-generic/gpio.h>
|
|
|
|
|
|
|
|
static inline int gpio_get_value(unsigned int gpio)
|
|
|
|
{
|
|
|
|
return __gpio_get_value(gpio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gpio_set_value(unsigned int gpio, int value)
|
|
|
|
{
|
|
|
|
__gpio_set_value(gpio, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_cansleep(unsigned int gpio)
|
|
|
|
{
|
|
|
|
return __gpio_cansleep(gpio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_to_irq(unsigned int gpio)
|
|
|
|
{
|
|
|
|
return __gpio_to_irq(gpio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int irq_to_gpio(unsigned int irq)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:49:39 +00:00
|
|
|
#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
|
2008-03-04 22:28:27 +00:00
|
|
|
|
2013-10-25 10:59:05 +00:00
|
|
|
/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
|
|
|
|
|
|
|
|
struct device;
|
|
|
|
|
|
|
|
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
|
|
|
|
int devm_gpio_request_one(struct device *dev, unsigned gpio,
|
|
|
|
unsigned long flags, const char *label);
|
|
|
|
void devm_gpio_free(struct device *dev, unsigned int gpio);
|
|
|
|
|
2013-03-28 11:34:56 +00:00
|
|
|
#else /* ! CONFIG_GPIOLIB */
|
2008-03-04 22:28:27 +00:00
|
|
|
|
2008-10-16 05:03:12 +00:00
|
|
|
#include <linux/kernel.h>
|
2008-05-23 20:04:58 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
2011-11-24 01:12:59 +00:00
|
|
|
#include <linux/bug.h>
|
2013-10-15 13:37:54 +00:00
|
|
|
#include <linux/pinctrl/pinctrl.h>
|
2008-05-23 20:04:58 +00:00
|
|
|
|
2009-09-22 23:46:33 +00:00
|
|
|
struct device;
|
2010-09-01 14:55:24 +00:00
|
|
|
struct gpio_chip;
|
2009-09-22 23:46:33 +00:00
|
|
|
|
2011-05-10 23:23:07 +00:00
|
|
|
static inline bool gpio_is_valid(int number)
|
2008-03-04 22:28:27 +00:00
|
|
|
{
|
2011-05-10 23:23:07 +00:00
|
|
|
return false;
|
2008-03-04 22:28:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 01:26:46 +00:00
|
|
|
static inline int gpio_request(unsigned gpio, const char *label)
|
2008-03-04 22:28:27 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-01-14 08:34:29 +00:00
|
|
|
static inline int gpio_request_one(unsigned gpio,
|
2011-01-13 01:00:24 +00:00
|
|
|
unsigned long flags, const char *label)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-05-25 23:20:31 +00:00
|
|
|
static inline int gpio_request_array(const struct gpio *array, size_t num)
|
2011-01-13 01:00:24 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
static inline void gpio_free(unsigned gpio)
|
|
|
|
{
|
2008-10-16 05:03:12 +00:00
|
|
|
might_sleep();
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
/* GPIO can never have been requested */
|
2012-04-04 15:14:48 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2011-05-25 23:20:31 +00:00
|
|
|
static inline void gpio_free_array(const struct gpio *array, size_t num)
|
2011-01-13 01:00:24 +00:00
|
|
|
{
|
|
|
|
might_sleep();
|
|
|
|
|
|
|
|
/* GPIO can never have been requested */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2011-01-14 01:26:46 +00:00
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
2008-03-04 22:28:27 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-01-14 01:26:46 +00:00
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
2008-03-04 22:28:27 +00:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:42:23 +00:00
|
|
|
static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
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_cansleep(unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested or set as {in,out}put */
|
|
|
|
WARN_ON(1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
gpio: sysfs interface
This adds a simple sysfs interface for GPIOs.
/sys/class/gpio
/export ... asks the kernel to export a GPIO to userspace
/unexport ... to return a GPIO to the kernel
/gpioN ... for each exported GPIO #N
/value ... always readable, writes fail for input GPIOs
/direction ... r/w as: in, out (default low); write high, low
/gpiochipN ... for each gpiochip; #N is its first GPIO
/base ... (r/o) same as N
/label ... (r/o) descriptive, not necessarily unique
/ngpio ... (r/o) number of GPIOs; numbered N .. N+(ngpio - 1)
GPIOs claimed by kernel code may be exported by its owner using a new
gpio_export() call, which should be most useful for driver debugging.
Such exports may optionally be done without a "direction" attribute.
Userspace may ask to take over a GPIO by writing to a sysfs control file,
helping to cope with incomplete board support or other "one-off"
requirements that don't merit full kernel support:
echo 23 > /sys/class/gpio/export
... will gpio_request(23, "sysfs") and gpio_export(23);
use /sys/class/gpio/gpio-23/direction to (re)configure it,
when that GPIO can be used as both input and output.
echo 23 > /sys/class/gpio/unexport
... will gpio_free(23), when it was exported as above
The extra D-space footprint is a few hundred bytes, except for the sysfs
resources associated with each exported GPIO. The additional I-space
footprint is about two thirds of the current size of gpiolib (!). Since
no /dev node creation is involved, no "udev" support is needed.
Related changes:
* This adds a device pointer to "struct gpio_chip". When GPIO
providers initialize that, sysfs gpio class devices become children of
that device instead of being "virtual" devices.
* The (few) gpio_chip providers which have such a device node have
been updated.
* Some gpio_chip drivers also needed to update their module "owner"
field ... for which missing kerneldoc was added.
* Some gpio_chips don't support input GPIOs. Those GPIOs are now
flagged appropriately when the chip is registered.
Based on previous patches, and discussion both on and off LKML.
A Documentation/ABI/testing/sysfs-gpio update is ready to submit once this
merges to mainline.
[akpm@linux-foundation.org: a few maintenance build fixes]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Cc: Greg KH <greg@kroah.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-25 08:46:07 +00:00
|
|
|
static inline int gpio_export(unsigned gpio, bool direction_may_change)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested or set as {in,out}put */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-09-22 23:46:33 +00:00
|
|
|
static inline int gpio_export_link(struct device *dev, const char *name,
|
|
|
|
unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been exported */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-16 00:46:20 +00:00
|
|
|
static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2009-09-22 23:46:33 +00:00
|
|
|
|
gpio: sysfs interface
This adds a simple sysfs interface for GPIOs.
/sys/class/gpio
/export ... asks the kernel to export a GPIO to userspace
/unexport ... to return a GPIO to the kernel
/gpioN ... for each exported GPIO #N
/value ... always readable, writes fail for input GPIOs
/direction ... r/w as: in, out (default low); write high, low
/gpiochipN ... for each gpiochip; #N is its first GPIO
/base ... (r/o) same as N
/label ... (r/o) descriptive, not necessarily unique
/ngpio ... (r/o) number of GPIOs; numbered N .. N+(ngpio - 1)
GPIOs claimed by kernel code may be exported by its owner using a new
gpio_export() call, which should be most useful for driver debugging.
Such exports may optionally be done without a "direction" attribute.
Userspace may ask to take over a GPIO by writing to a sysfs control file,
helping to cope with incomplete board support or other "one-off"
requirements that don't merit full kernel support:
echo 23 > /sys/class/gpio/export
... will gpio_request(23, "sysfs") and gpio_export(23);
use /sys/class/gpio/gpio-23/direction to (re)configure it,
when that GPIO can be used as both input and output.
echo 23 > /sys/class/gpio/unexport
... will gpio_free(23), when it was exported as above
The extra D-space footprint is a few hundred bytes, except for the sysfs
resources associated with each exported GPIO. The additional I-space
footprint is about two thirds of the current size of gpiolib (!). Since
no /dev node creation is involved, no "udev" support is needed.
Related changes:
* This adds a device pointer to "struct gpio_chip". When GPIO
providers initialize that, sysfs gpio class devices become children of
that device instead of being "virtual" devices.
* The (few) gpio_chip providers which have such a device node have
been updated.
* Some gpio_chip drivers also needed to update their module "owner"
field ... for which missing kerneldoc was added.
* Some gpio_chips don't support input GPIOs. Those GPIOs are now
flagged appropriately when the chip is registered.
Based on previous patches, and discussion both on and off LKML.
A Documentation/ABI/testing/sysfs-gpio update is ready to submit once this
merges to mainline.
[akpm@linux-foundation.org: a few maintenance build fixes]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Cc: Greg KH <greg@kroah.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-25 08:46:07 +00:00
|
|
|
static inline void gpio_unexport(unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been exported */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
static inline int gpio_to_irq(unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested or set as input */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-09-24 09:54:38 +00:00
|
|
|
static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
|
|
|
|
{
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gpio_unlock_as_irq(struct gpio_chip *chip,
|
|
|
|
unsigned int offset)
|
|
|
|
{
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
static inline int irq_to_gpio(unsigned irq)
|
|
|
|
{
|
|
|
|
/* irq can never have been returned from gpio_to_irq() */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-06 15:03:35 +00:00
|
|
|
static inline int
|
2012-11-06 13:49:39 +00:00
|
|
|
gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
|
2012-11-21 07:48:09 +00:00
|
|
|
unsigned int gpio_offset, unsigned int pin_offset,
|
2012-11-20 11:40:15 +00:00
|
|
|
unsigned int npins)
|
2012-11-06 13:49:39 +00:00
|
|
|
{
|
2012-11-06 16:16:39 +00:00
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
2012-11-06 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 13:37:54 +00:00
|
|
|
static inline int
|
|
|
|
gpiochip_add_pingroup_range(struct gpio_chip *chip,
|
|
|
|
struct pinctrl_dev *pctldev,
|
|
|
|
unsigned int gpio_offset, const char *pin_group)
|
|
|
|
{
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:49:39 +00:00
|
|
|
static inline void
|
|
|
|
gpiochip_remove_pin_ranges(struct gpio_chip *chip)
|
|
|
|
{
|
2012-11-06 16:16:39 +00:00
|
|
|
WARN_ON(1);
|
2012-11-06 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2013-10-25 10:59:05 +00:00
|
|
|
static inline int devm_gpio_request(struct device *dev, unsigned gpio,
|
|
|
|
const char *label)
|
|
|
|
{
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-03-04 22:28:27 +00:00
|
|
|
|
2013-10-25 10:59:05 +00: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-01-18 07:57:46 +00:00
|
|
|
|
2013-10-25 10:59:05 +00:00
|
|
|
static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
|
|
|
|
{
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! CONFIG_GPIOLIB */
|
2013-01-18 07:57:46 +00:00
|
|
|
|
2008-03-04 22:28:27 +00:00
|
|
|
#endif /* __LINUX_GPIO_H */
|