nl80211: Fix comment merge error
[deliverable/linux.git] / include / asm-generic / gpio.h
CommitLineData
4c20386c
DB
1#ifndef _ASM_GENERIC_GPIO_H
2#define _ASM_GENERIC_GPIO_H
3
6ea0205b
DB
4#include <linux/types.h>
5
d2876d08
DB
6#ifdef CONFIG_HAVE_GPIO_LIB
7
6ea0205b
DB
8#include <linux/compiler.h>
9
d2876d08
DB
10/* Platforms may implement their GPIO interface with library code,
11 * at a small performance cost for non-inlined operations and some
12 * extra memory (for code and for per-GPIO table entries).
13 *
14 * While the GPIO programming interface defines valid GPIO numbers
15 * to be in the range 0..MAX_INT, this library restricts them to the
16 * smaller range 0..ARCH_NR_GPIOS.
17 */
18
19#ifndef ARCH_NR_GPIOS
20#define ARCH_NR_GPIOS 256
21#endif
22
e6de1808
GL
23static inline int gpio_is_valid(int number)
24{
25 /* only some non-negative numbers are valid */
26 return ((unsigned)number) < ARCH_NR_GPIOS;
27}
28
d2876d08 29struct seq_file;
438d8908 30struct module;
d2876d08
DB
31
32/**
33 * struct gpio_chip - abstract a GPIO controller
34 * @label: for diagnostics
35 * @direction_input: configures signal "offset" as input, or returns error
36 * @get: returns value for signal "offset"; for output signals this
37 * returns either the value actually sensed, or zero
38 * @direction_output: configures signal "offset" as output, or returns error
39 * @set: assigns output value for signal "offset"
40 * @dbg_show: optional routine to show contents in debugfs; default code
41 * will be used when this is omitted, but custom code can show extra
42 * state (such as pullup/pulldown configuration).
43 * @base: identifies the first GPIO number handled by this chip; or, if
44 * negative during registration, requests dynamic ID allocation.
45 * @ngpio: the number of GPIOs handled by this controller; the last GPIO
46 * handled is (base + ngpio - 1).
47 * @can_sleep: flag must be set iff get()/set() methods sleep, as they
48 * must while accessing GPIO expander chips over I2C or SPI
49 *
50 * A gpio_chip can help platforms abstract various sources of GPIOs so
51 * they can all be accessed through a common programing interface.
52 * Example sources would be SOC controllers, FPGAs, multifunction
53 * chips, dedicated GPIO expanders, and so on.
54 *
55 * Each chip controls a number of signals, identified in method calls
56 * by "offset" values in the range 0..(@ngpio - 1). When those signals
57 * are referenced through calls like gpio_get_value(gpio), the offset
58 * is calculated by subtracting @base from the gpio number.
59 */
60struct gpio_chip {
61 char *label;
438d8908 62 struct module *owner;
d2876d08
DB
63
64 int (*direction_input)(struct gpio_chip *chip,
65 unsigned offset);
66 int (*get)(struct gpio_chip *chip,
67 unsigned offset);
68 int (*direction_output)(struct gpio_chip *chip,
69 unsigned offset, int value);
70 void (*set)(struct gpio_chip *chip,
71 unsigned offset, int value);
72 void (*dbg_show)(struct seq_file *s,
73 struct gpio_chip *chip);
74 int base;
75 u16 ngpio;
76 unsigned can_sleep:1;
77};
78
79extern const char *gpiochip_is_requested(struct gpio_chip *chip,
80 unsigned offset);
6ea0205b 81extern int __must_check gpiochip_reserve(int start, int ngpio);
d2876d08
DB
82
83/* add/remove chips */
84extern int gpiochip_add(struct gpio_chip *chip);
85extern int __must_check gpiochip_remove(struct gpio_chip *chip);
86
87
88/* Always use the library code for GPIO management calls,
89 * or when sleeping may be involved.
90 */
91extern int gpio_request(unsigned gpio, const char *label);
92extern void gpio_free(unsigned gpio);
93
94extern int gpio_direction_input(unsigned gpio);
95extern int gpio_direction_output(unsigned gpio, int value);
96
97extern int gpio_get_value_cansleep(unsigned gpio);
98extern void gpio_set_value_cansleep(unsigned gpio, int value);
99
100
101/* A platform's <asm/gpio.h> code may want to inline the I/O calls when
102 * the GPIO is constant and refers to some always-present controller,
103 * giving direct access to chip registers and tight bitbanging loops.
104 */
105extern int __gpio_get_value(unsigned gpio);
106extern void __gpio_set_value(unsigned gpio, int value);
107
108extern int __gpio_cansleep(unsigned gpio);
109
110
111#else
112
e6de1808
GL
113static inline int gpio_is_valid(int number)
114{
115 /* only non-negative numbers are valid */
116 return number >= 0;
117}
118
4c20386c
DB
119/* platforms that don't directly support access to GPIOs through I2C, SPI,
120 * or other blocking infrastructure can use these wrappers.
121 */
122
123static inline int gpio_cansleep(unsigned gpio)
124{
125 return 0;
126}
127
128static inline int gpio_get_value_cansleep(unsigned gpio)
129{
130 might_sleep();
131 return gpio_get_value(gpio);
132}
133
134static inline void gpio_set_value_cansleep(unsigned gpio, int value)
135{
136 might_sleep();
137 gpio_set_value(gpio, value);
138}
139
d2876d08
DB
140#endif
141
4c20386c 142#endif /* _ASM_GENERIC_GPIO_H */
This page took 0.164162 seconds and 5 git commands to generate.