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