gpio/pinctrl: make gpio_chip members typed boolean
[deliverable/linux.git] / include / linux / gpio / driver.h
1 #ifndef __LINUX_GPIO_DRIVER_H
2 #define __LINUX_GPIO_DRIVER_H
3
4 #include <linux/types.h>
5
6 struct device;
7 struct gpio_desc;
8 struct seq_file;
9
10 /**
11 * struct gpio_chip - abstract a GPIO controller
12 * @label: for diagnostics
13 * @dev: optional device providing the GPIOs
14 * @owner: helps prevent removal of modules exporting active GPIOs
15 * @list: links gpio_chips together for traversal
16 * @request: optional hook for chip-specific activation, such as
17 * enabling module power and clock; may sleep
18 * @free: optional hook for chip-specific deactivation, such as
19 * disabling module power and clock; may sleep
20 * @get_direction: returns direction for signal "offset", 0=out, 1=in,
21 * (same as GPIOF_DIR_XXX), or negative error
22 * @direction_input: configures signal "offset" as input, or returns error
23 * @direction_output: configures signal "offset" as output, or returns error
24 * @get: returns value for signal "offset"; for output signals this
25 * returns either the value actually sensed, or zero
26 * @set: assigns output value for signal "offset"
27 * @set_debounce: optional hook for setting debounce time for specified gpio in
28 * interrupt triggered gpio chips
29 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings;
30 * implementation may not sleep
31 * @dbg_show: optional routine to show contents in debugfs; default code
32 * will be used when this is omitted, but custom code can show extra
33 * state (such as pullup/pulldown configuration).
34 * @base: identifies the first GPIO number handled by this chip; or, if
35 * negative during registration, requests dynamic ID allocation.
36 * @ngpio: the number of GPIOs handled by this controller; the last GPIO
37 * handled is (base + ngpio - 1).
38 * @desc: array of ngpio descriptors. Private.
39 * @names: if set, must be an array of strings to use as alternative
40 * names for the GPIOs in this chip. Any entry in the array
41 * may be NULL if there is no alias for the GPIO, however the
42 * array must be @ngpio entries long. A name can include a single printk
43 * format specifier for an unsigned int. It is substituted by the actual
44 * number of the gpio.
45 * @can_sleep: flag must be set iff get()/set() methods sleep, as they
46 * must while accessing GPIO expander chips over I2C or SPI
47 * @exported: flags if the gpiochip is exported for use from sysfs. Private.
48 *
49 * A gpio_chip can help platforms abstract various sources of GPIOs so
50 * they can all be accessed through a common programing interface.
51 * Example sources would be SOC controllers, FPGAs, multifunction
52 * chips, dedicated GPIO expanders, and so on.
53 *
54 * Each chip controls a number of signals, identified in method calls
55 * by "offset" values in the range 0..(@ngpio - 1). When those signals
56 * are referenced through calls like gpio_get_value(gpio), the offset
57 * is calculated by subtracting @base from the gpio number.
58 */
59 struct gpio_chip {
60 const char *label;
61 struct device *dev;
62 struct module *owner;
63 struct list_head list;
64
65 int (*request)(struct gpio_chip *chip,
66 unsigned offset);
67 void (*free)(struct gpio_chip *chip,
68 unsigned offset);
69 int (*get_direction)(struct gpio_chip *chip,
70 unsigned offset);
71 int (*direction_input)(struct gpio_chip *chip,
72 unsigned offset);
73 int (*direction_output)(struct gpio_chip *chip,
74 unsigned offset, int value);
75 int (*get)(struct gpio_chip *chip,
76 unsigned offset);
77 void (*set)(struct gpio_chip *chip,
78 unsigned offset, int value);
79 int (*set_debounce)(struct gpio_chip *chip,
80 unsigned offset,
81 unsigned debounce);
82
83 int (*to_irq)(struct gpio_chip *chip,
84 unsigned offset);
85
86 void (*dbg_show)(struct seq_file *s,
87 struct gpio_chip *chip);
88 int base;
89 u16 ngpio;
90 struct gpio_desc *desc;
91 const char *const *names;
92 bool can_sleep;
93 bool exported;
94
95 #if defined(CONFIG_OF_GPIO)
96 /*
97 * If CONFIG_OF is enabled, then all GPIO controllers described in the
98 * device tree automatically may have an OF translation
99 */
100 struct device_node *of_node;
101 int of_gpio_n_cells;
102 int (*of_xlate)(struct gpio_chip *gc,
103 const struct of_phandle_args *gpiospec, u32 *flags);
104 #endif
105 #ifdef CONFIG_PINCTRL
106 /*
107 * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
108 * describe the actual pin range which they serve in an SoC. This
109 * information would be used by pinctrl subsystem to configure
110 * corresponding pins for gpio usage.
111 */
112 struct list_head pin_ranges;
113 #endif
114 };
115
116 extern const char *gpiochip_is_requested(struct gpio_chip *chip,
117 unsigned offset);
118
119 /* add/remove chips */
120 extern int gpiochip_add(struct gpio_chip *chip);
121 extern int __must_check gpiochip_remove(struct gpio_chip *chip);
122 extern struct gpio_chip *gpiochip_find(void *data,
123 int (*match)(struct gpio_chip *chip, void *data));
124
125 /* lock/unlock as IRQ */
126 int gpiod_lock_as_irq(struct gpio_desc *desc);
127 void gpiod_unlock_as_irq(struct gpio_desc *desc);
128
129 /**
130 * Lookup table for associating GPIOs to specific devices and functions using
131 * platform data.
132 */
133 struct gpiod_lookup {
134 struct list_head list;
135 /*
136 * name of the chip the GPIO belongs to
137 */
138 const char *chip_label;
139 /*
140 * hardware number (i.e. relative to the chip) of the GPIO
141 */
142 u16 chip_hwnum;
143 /*
144 * name of device that can claim this GPIO
145 */
146 const char *dev_id;
147 /*
148 * name of the GPIO from the device's point of view
149 */
150 const char *con_id;
151 /*
152 * index of the GPIO in case several GPIOs share the same name
153 */
154 unsigned int idx;
155 /*
156 * mask of GPIOF_* values
157 */
158 unsigned long flags;
159 };
160
161 /*
162 * Simple definition of a single GPIO under a con_id
163 */
164 #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _dev_id, _con_id, _flags) \
165 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, 0, _flags)
166
167 /*
168 * Use this macro if you need to have several GPIOs under the same con_id.
169 * Each GPIO needs to use a different index and can be accessed using
170 * gpiod_get_index()
171 */
172 #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _dev_id, _con_id, _idx, \
173 _flags) \
174 { \
175 .chip_label = _chip_label, \
176 .chip_hwnum = _chip_hwnum, \
177 .dev_id = _dev_id, \
178 .con_id = _con_id, \
179 .idx = _idx, \
180 .flags = _flags, \
181 }
182
183 void gpiod_add_table(struct gpiod_lookup *table, size_t size);
184
185 #endif
This page took 0.045812 seconds and 5 git commands to generate.