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