aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/gpio.h
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-07-25 04:46:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:30 -0400
commitd8f388d8dc8d4f36539dd37c1fff62cc404ea0fc (patch)
treedf8603775c889f29f8a03c77b9f7913bfd90d296 /include/asm-generic/gpio.h
parent8b6dd986823a8d92ed9f54baa5cef8604d9d9d44 (diff)
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>
Diffstat (limited to 'include/asm-generic/gpio.h')
-rw-r--r--include/asm-generic/gpio.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 6be061d09da9..1beff5166e53 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -32,6 +32,8 @@ struct module;
32/** 32/**
33 * struct gpio_chip - abstract a GPIO controller 33 * struct gpio_chip - abstract a GPIO controller
34 * @label: for diagnostics 34 * @label: for diagnostics
35 * @dev: optional device providing the GPIOs
36 * @owner: helps prevent removal of modules exporting active GPIOs
35 * @direction_input: configures signal "offset" as input, or returns error 37 * @direction_input: configures signal "offset" as input, or returns error
36 * @get: returns value for signal "offset"; for output signals this 38 * @get: returns value for signal "offset"; for output signals this
37 * returns either the value actually sensed, or zero 39 * returns either the value actually sensed, or zero
@@ -59,6 +61,7 @@ struct module;
59 */ 61 */
60struct gpio_chip { 62struct gpio_chip {
61 char *label; 63 char *label;
64 struct device *dev;
62 struct module *owner; 65 struct module *owner;
63 66
64 int (*direction_input)(struct gpio_chip *chip, 67 int (*direction_input)(struct gpio_chip *chip,
@@ -74,6 +77,7 @@ struct gpio_chip {
74 int base; 77 int base;
75 u16 ngpio; 78 u16 ngpio;
76 unsigned can_sleep:1; 79 unsigned can_sleep:1;
80 unsigned exported:1;
77}; 81};
78 82
79extern const char *gpiochip_is_requested(struct gpio_chip *chip, 83extern const char *gpiochip_is_requested(struct gpio_chip *chip,
@@ -108,7 +112,18 @@ extern void __gpio_set_value(unsigned gpio, int value);
108extern int __gpio_cansleep(unsigned gpio); 112extern int __gpio_cansleep(unsigned gpio);
109 113
110 114
111#else 115#ifdef CONFIG_GPIO_SYSFS
116
117/*
118 * A sysfs interface can be exported by individual drivers if they want,
119 * but more typically is configured entirely from userspace.
120 */
121extern int gpio_export(unsigned gpio, bool direction_may_change);
122extern void gpio_unexport(unsigned gpio);
123
124#endif /* CONFIG_GPIO_SYSFS */
125
126#else /* !CONFIG_HAVE_GPIO_LIB */
112 127
113static inline int gpio_is_valid(int number) 128static inline int gpio_is_valid(int number)
114{ 129{
@@ -137,6 +152,20 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
137 gpio_set_value(gpio, value); 152 gpio_set_value(gpio, value);
138} 153}
139 154
140#endif 155#endif /* !CONFIG_HAVE_GPIO_LIB */
156
157#ifndef CONFIG_GPIO_SYSFS
158
159/* sysfs support is only available with gpiolib, where it's optional */
160
161static inline int gpio_export(unsigned gpio, bool direction_may_change)
162{
163 return -ENOSYS;
164}
165
166static inline void gpio_unexport(unsigned gpio)
167{
168}
169#endif /* CONFIG_GPIO_SYSFS */
141 170
142#endif /* _ASM_GENERIC_GPIO_H */ 171#endif /* _ASM_GENERIC_GPIO_H */