diff options
author | David Brownell <dbrownell@users.sourceforge.net> | 2008-02-05 01:28:20 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:12 -0500 |
commit | d2876d08d86f22ce1f276fc29f6baec8b53e32c6 (patch) | |
tree | d9d059fad208001edb58d9dff3ed6ad64c8e7407 /include | |
parent | a9c5fff542544c8595bb12efeb278a96d99386fc (diff) |
gpiolib: add gpio provider infrastructure
Provide new implementation infrastructure that platforms may choose to use
when implementing the GPIO programming interface. Platforms can update their
GPIO support to use this. In many cases the incremental cost to access a
non-inlined GPIO should be less than a dozen instructions, with the memory
cost being about a page (total) of extra data and code. The upside is:
* Providing two features which were "want to have (but OK to defer)" when
GPIO interfaces were first discussed in November 2006:
- A "struct gpio_chip" to plug in GPIOs that aren't directly supported
by SOC platforms, but come from FPGAs or other multifunction devices
using conventional device registers (like UCB-1x00 or SM501 GPIOs,
and southbridges in PCs with more open specs than usual).
- Full support for message-based GPIO expanders, where registers are
accessed through sleeping I/O calls. Previous support for these
"cansleep" calls was just stubs. (One example: the widely used
pcf8574 I2C chips, with 8 GPIOs each.)
* Including a non-stub implementation of the gpio_{request,free}() calls,
making those calls much more useful. The diagnostic labels are also
recorded given DEBUG_FS, so /sys/kernel/debug/gpio can show a snapshot
of all GPIOs known to this infrastructure.
The driver programming interfaces introduced in 2.6.21 do not change at all;
this infrastructure is entirely below those covers.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Eric Miao <eric.miao@marvell.com>
Cc: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: Philipp Zabel <philipp.zabel@gmail.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Ben Gardner <bgardner@wabtec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-generic/gpio.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 2d0aab1d8611..f29a502f4a6c 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h | |||
@@ -1,6 +1,102 @@ | |||
1 | #ifndef _ASM_GENERIC_GPIO_H | 1 | #ifndef _ASM_GENERIC_GPIO_H |
2 | #define _ASM_GENERIC_GPIO_H | 2 | #define _ASM_GENERIC_GPIO_H |
3 | 3 | ||
4 | #ifdef CONFIG_HAVE_GPIO_LIB | ||
5 | |||
6 | /* Platforms may implement their GPIO interface with library code, | ||
7 | * at a small performance cost for non-inlined operations and some | ||
8 | * extra memory (for code and for per-GPIO table entries). | ||
9 | * | ||
10 | * While the GPIO programming interface defines valid GPIO numbers | ||
11 | * to be in the range 0..MAX_INT, this library restricts them to the | ||
12 | * smaller range 0..ARCH_NR_GPIOS. | ||
13 | */ | ||
14 | |||
15 | #ifndef ARCH_NR_GPIOS | ||
16 | #define ARCH_NR_GPIOS 256 | ||
17 | #endif | ||
18 | |||
19 | struct seq_file; | ||
20 | |||
21 | /** | ||
22 | * struct gpio_chip - abstract a GPIO controller | ||
23 | * @label: for diagnostics | ||
24 | * @direction_input: configures signal "offset" as input, or returns error | ||
25 | * @get: returns value for signal "offset"; for output signals this | ||
26 | * returns either the value actually sensed, or zero | ||
27 | * @direction_output: configures signal "offset" as output, or returns error | ||
28 | * @set: assigns output value for signal "offset" | ||
29 | * @dbg_show: optional routine to show contents in debugfs; default code | ||
30 | * will be used when this is omitted, but custom code can show extra | ||
31 | * state (such as pullup/pulldown configuration). | ||
32 | * @base: identifies the first GPIO number handled by this chip; or, if | ||
33 | * negative during registration, requests dynamic ID allocation. | ||
34 | * @ngpio: the number of GPIOs handled by this controller; the last GPIO | ||
35 | * handled is (base + ngpio - 1). | ||
36 | * @can_sleep: flag must be set iff get()/set() methods sleep, as they | ||
37 | * must while accessing GPIO expander chips over I2C or SPI | ||
38 | * | ||
39 | * A gpio_chip can help platforms abstract various sources of GPIOs so | ||
40 | * they can all be accessed through a common programing interface. | ||
41 | * Example sources would be SOC controllers, FPGAs, multifunction | ||
42 | * chips, dedicated GPIO expanders, and so on. | ||
43 | * | ||
44 | * Each chip controls a number of signals, identified in method calls | ||
45 | * by "offset" values in the range 0..(@ngpio - 1). When those signals | ||
46 | * are referenced through calls like gpio_get_value(gpio), the offset | ||
47 | * is calculated by subtracting @base from the gpio number. | ||
48 | */ | ||
49 | struct gpio_chip { | ||
50 | char *label; | ||
51 | |||
52 | int (*direction_input)(struct gpio_chip *chip, | ||
53 | unsigned offset); | ||
54 | int (*get)(struct gpio_chip *chip, | ||
55 | unsigned offset); | ||
56 | int (*direction_output)(struct gpio_chip *chip, | ||
57 | unsigned offset, int value); | ||
58 | void (*set)(struct gpio_chip *chip, | ||
59 | unsigned offset, int value); | ||
60 | void (*dbg_show)(struct seq_file *s, | ||
61 | struct gpio_chip *chip); | ||
62 | int base; | ||
63 | u16 ngpio; | ||
64 | unsigned can_sleep:1; | ||
65 | }; | ||
66 | |||
67 | extern const char *gpiochip_is_requested(struct gpio_chip *chip, | ||
68 | unsigned offset); | ||
69 | |||
70 | /* add/remove chips */ | ||
71 | extern int gpiochip_add(struct gpio_chip *chip); | ||
72 | extern int __must_check gpiochip_remove(struct gpio_chip *chip); | ||
73 | |||
74 | |||
75 | /* Always use the library code for GPIO management calls, | ||
76 | * or when sleeping may be involved. | ||
77 | */ | ||
78 | extern int gpio_request(unsigned gpio, const char *label); | ||
79 | extern void gpio_free(unsigned gpio); | ||
80 | |||
81 | extern int gpio_direction_input(unsigned gpio); | ||
82 | extern int gpio_direction_output(unsigned gpio, int value); | ||
83 | |||
84 | extern int gpio_get_value_cansleep(unsigned gpio); | ||
85 | extern void gpio_set_value_cansleep(unsigned gpio, int value); | ||
86 | |||
87 | |||
88 | /* A platform's <asm/gpio.h> code may want to inline the I/O calls when | ||
89 | * the GPIO is constant and refers to some always-present controller, | ||
90 | * giving direct access to chip registers and tight bitbanging loops. | ||
91 | */ | ||
92 | extern int __gpio_get_value(unsigned gpio); | ||
93 | extern void __gpio_set_value(unsigned gpio, int value); | ||
94 | |||
95 | extern int __gpio_cansleep(unsigned gpio); | ||
96 | |||
97 | |||
98 | #else | ||
99 | |||
4 | /* platforms that don't directly support access to GPIOs through I2C, SPI, | 100 | /* platforms that don't directly support access to GPIOs through I2C, SPI, |
5 | * or other blocking infrastructure can use these wrappers. | 101 | * or other blocking infrastructure can use these wrappers. |
6 | */ | 102 | */ |
@@ -22,4 +118,6 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value) | |||
22 | gpio_set_value(gpio, value); | 118 | gpio_set_value(gpio, value); |
23 | } | 119 | } |
24 | 120 | ||
121 | #endif | ||
122 | |||
25 | #endif /* _ASM_GENERIC_GPIO_H */ | 123 | #endif /* _ASM_GENERIC_GPIO_H */ |