2008-03-05 01:28:27 +03:00
|
|
|
#ifndef __LINUX_GPIO_H
|
|
|
|
#define __LINUX_GPIO_H
|
|
|
|
|
2012-04-15 13:52:54 +04:00
|
|
|
#include <linux/errno.h>
|
|
|
|
|
2008-03-05 01:28:27 +03:00
|
|
|
/* see Documentation/gpio.txt */
|
|
|
|
|
2011-06-15 04:05:11 +04: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)
|
|
|
|
|
2012-02-17 18:56:21 +04:00
|
|
|
/* Gpio pin is open drain */
|
|
|
|
#define GPIOF_OPEN_DRAIN (1 << 2)
|
|
|
|
|
2012-02-17 18:56:22 +04:00
|
|
|
/* Gpio pin is open source */
|
|
|
|
#define GPIOF_OPEN_SOURCE (1 << 3)
|
|
|
|
|
2012-06-20 12:44:05 +04:00
|
|
|
#define GPIOF_EXPORT (1 << 4)
|
|
|
|
#define GPIOF_EXPORT_CHANGEABLE (1 << 5)
|
2011-12-13 21:34:01 +04:00
|
|
|
#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
|
|
|
|
#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
|
|
|
|
|
2011-10-24 17:24:10 +04: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;
|
|
|
|
};
|
|
|
|
|
2008-03-05 01:28:27 +03:00
|
|
|
#ifdef CONFIG_GENERIC_GPIO
|
2012-04-15 13:52:54 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
|
2008-03-05 01:28:27 +03:00
|
|
|
#include <asm/gpio.h>
|
2012-04-15 13:52:54 +04: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 17:49:39 +04:00
|
|
|
#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
|
2008-03-05 01:28:27 +03:00
|
|
|
|
2012-11-06 17:49:39 +04:00
|
|
|
#else /* ! CONFIG_GENERIC_GPIO */
|
2008-03-05 01:28:27 +03:00
|
|
|
|
2008-10-16 09:03:12 +04:00
|
|
|
#include <linux/kernel.h>
|
2008-05-24 00:04:58 +04:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
2011-11-24 05:12:59 +04:00
|
|
|
#include <linux/bug.h>
|
2008-05-24 00:04:58 +04:00
|
|
|
|
2009-09-23 03:46:33 +04:00
|
|
|
struct device;
|
2010-09-01 18:55:24 +04:00
|
|
|
struct gpio_chip;
|
2009-09-23 03:46:33 +04:00
|
|
|
|
2011-05-11 03:23:07 +04:00
|
|
|
static inline bool gpio_is_valid(int number)
|
2008-03-05 01:28:27 +03:00
|
|
|
{
|
2011-05-11 03:23:07 +04:00
|
|
|
return false;
|
2008-03-05 01:28:27 +03:00
|
|
|
}
|
|
|
|
|
2011-01-14 04:26:46 +03:00
|
|
|
static inline int gpio_request(unsigned gpio, const char *label)
|
2008-03-05 01:28:27 +03:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2012-04-04 19:14:48 +04:00
|
|
|
static inline int devm_gpio_request(struct device *dev, unsigned gpio,
|
|
|
|
const char *label)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-01-14 11:34:29 +03:00
|
|
|
static inline int gpio_request_one(unsigned gpio,
|
2011-01-13 04:00:24 +03:00
|
|
|
unsigned long flags, const char *label)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2012-05-02 15:46:46 +04:00
|
|
|
static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
|
|
|
|
unsigned long flags, const char *label)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-05-26 03:20:31 +04:00
|
|
|
static inline int gpio_request_array(const struct gpio *array, size_t num)
|
2011-01-13 04:00:24 +03:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2008-03-05 01:28:27 +03:00
|
|
|
static inline void gpio_free(unsigned gpio)
|
|
|
|
{
|
2008-10-16 09:03:12 +04:00
|
|
|
might_sleep();
|
|
|
|
|
2008-03-05 01:28:27 +03:00
|
|
|
/* GPIO can never have been requested */
|
2012-04-04 19:14:48 +04:00
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_gpio_free(struct device *dev, unsigned gpio)
|
|
|
|
{
|
|
|
|
might_sleep();
|
|
|
|
|
|
|
|
/* GPIO can never have been requested */
|
2008-03-05 01:28:27 +03:00
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2011-05-26 03:20:31 +04:00
|
|
|
static inline void gpio_free_array(const struct gpio *array, size_t num)
|
2011-01-13 04:00:24 +03:00
|
|
|
{
|
|
|
|
might_sleep();
|
|
|
|
|
|
|
|
/* GPIO can never have been requested */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2011-01-14 04:26:46 +03:00
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
2008-03-05 01:28:27 +03:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-01-14 04:26:46 +03:00
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
2008-03-05 01:28:27 +03:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2010-05-27 01:42:23 +04:00
|
|
|
static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2008-03-05 01:28:27 +03: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 12:46:07 +04: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-23 03:46:33 +04: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 03:46:20 +03: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-23 03:46:33 +04: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 12:46:07 +04:00
|
|
|
static inline void gpio_unexport(unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been exported */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
2008-03-05 01:28:27 +03:00
|
|
|
static inline int gpio_to_irq(unsigned gpio)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested or set as input */
|
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 19:03:35 +04:00
|
|
|
static inline int
|
2012-11-06 17:49:39 +04:00
|
|
|
gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
|
2012-11-21 11:48:09 +04:00
|
|
|
unsigned int gpio_offset, unsigned int pin_offset,
|
2012-11-20 15:40:15 +04:00
|
|
|
unsigned int npins)
|
2012-11-06 17:49:39 +04:00
|
|
|
{
|
2012-11-06 20:16:39 +04:00
|
|
|
WARN_ON(1);
|
|
|
|
return -EINVAL;
|
2012-11-06 17:49:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gpiochip_remove_pin_ranges(struct gpio_chip *chip)
|
|
|
|
{
|
2012-11-06 20:16:39 +04:00
|
|
|
WARN_ON(1);
|
2012-11-06 17:49:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! CONFIG_GENERIC_GPIO */
|
2008-03-05 01:28:27 +03:00
|
|
|
|
|
|
|
#endif /* __LINUX_GPIO_H */
|