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