Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
0a6d3158 LW |
2 | #ifndef __LINUX_GPIO_MACHINE_H |
3 | #define __LINUX_GPIO_MACHINE_H | |
4 | ||
b3ea074f | 5 | #include <linux/types.h> |
b3ea074f | 6 | |
0a6d3158 | 7 | enum gpio_lookup_flags { |
4050586b AS |
8 | GPIO_ACTIVE_HIGH = (0 << 0), |
9 | GPIO_ACTIVE_LOW = (1 << 0), | |
10 | GPIO_OPEN_DRAIN = (1 << 1), | |
11 | GPIO_OPEN_SOURCE = (1 << 2), | |
12 | GPIO_PERSISTENT = (0 << 3), | |
13 | GPIO_TRANSITORY = (1 << 3), | |
14 | GPIO_PULL_UP = (1 << 4), | |
15 | GPIO_PULL_DOWN = (1 << 5), | |
c269df8c | 16 | GPIO_PULL_DISABLE = (1 << 6), |
2d6c06f5 AS |
17 | |
18 | GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT, | |
0a6d3158 LW |
19 | }; |
20 | ||
21 | /** | |
22 | * struct gpiod_lookup - lookup table | |
4c033b54 GU |
23 | * @key: either the name of the chip the GPIO belongs to, or the GPIO line name |
24 | * Note that GPIO line names are not guaranteed to be globally unique, | |
25 | * so this will use the first match found! | |
26 | * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO, or | |
27 | * U16_MAX to indicate that @key is a GPIO line name | |
0a6d3158 LW |
28 | * @con_id: name of the GPIO from the device's point of view |
29 | * @idx: index of the GPIO in case several GPIOs share the same name | |
fed7026a | 30 | * @flags: bitmask of gpio_lookup_flags GPIO_* values |
0a6d3158 LW |
31 | * |
32 | * gpiod_lookup is a lookup table for associating GPIOs to specific devices and | |
33 | * functions using platform data. | |
34 | */ | |
35 | struct gpiod_lookup { | |
4c033b54 | 36 | const char *key; |
0a6d3158 LW |
37 | u16 chip_hwnum; |
38 | const char *con_id; | |
39 | unsigned int idx; | |
fed7026a | 40 | unsigned long flags; |
0a6d3158 LW |
41 | }; |
42 | ||
43 | struct gpiod_lookup_table { | |
44 | struct list_head list; | |
45 | const char *dev_id; | |
46 | struct gpiod_lookup table[]; | |
47 | }; | |
48 | ||
a411e81e BG |
49 | /** |
50 | * struct gpiod_hog - GPIO line hog table | |
51 | * @chip_label: name of the chip the GPIO belongs to | |
52 | * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO | |
53 | * @line_name: consumer name for the hogged line | |
fed7026a | 54 | * @lflags: bitmask of gpio_lookup_flags GPIO_* values |
a411e81e BG |
55 | * @dflags: GPIO flags used to specify the direction and value |
56 | */ | |
57 | struct gpiod_hog { | |
58 | struct list_head list; | |
59 | const char *chip_label; | |
60 | u16 chip_hwnum; | |
61 | const char *line_name; | |
fed7026a | 62 | unsigned long lflags; |
a411e81e BG |
63 | int dflags; |
64 | }; | |
65 | ||
813c2aee LW |
66 | /* |
67 | * Helper for lookup tables with just one single lookup for a device. | |
68 | */ | |
69 | #define GPIO_LOOKUP_SINGLE(_name, _dev_id, _key, _chip_hwnum, _con_id, _flags) \ | |
70 | static struct gpiod_lookup_table _name = { \ | |
71 | .dev_id = _dev_id, \ | |
72 | .table = { \ | |
73 | GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags), \ | |
74 | {}, \ | |
75 | }, \ | |
76 | } | |
77 | ||
0a6d3158 LW |
78 | /* |
79 | * Simple definition of a single GPIO under a con_id | |
80 | */ | |
4c033b54 GU |
81 | #define GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags) \ |
82 | GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, 0, _flags) | |
0a6d3158 LW |
83 | |
84 | /* | |
85 | * Use this macro if you need to have several GPIOs under the same con_id. | |
86 | * Each GPIO needs to use a different index and can be accessed using | |
87 | * gpiod_get_index() | |
88 | */ | |
4c033b54 | 89 | #define GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, _idx, _flags) \ |
b2498cb8 | 90 | (struct gpiod_lookup) { \ |
4c033b54 | 91 | .key = _key, \ |
0a6d3158 LW |
92 | .chip_hwnum = _chip_hwnum, \ |
93 | .con_id = _con_id, \ | |
94 | .idx = _idx, \ | |
95 | .flags = _flags, \ | |
96 | } | |
97 | ||
a411e81e BG |
98 | /* |
99 | * Simple definition of a single GPIO hog in an array. | |
100 | */ | |
101 | #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \ | |
b2498cb8 | 102 | (struct gpiod_hog) { \ |
a411e81e BG |
103 | .chip_label = _chip_label, \ |
104 | .chip_hwnum = _chip_hwnum, \ | |
105 | .line_name = _line_name, \ | |
106 | .lflags = _lflags, \ | |
107 | .dflags = _dflags, \ | |
108 | } | |
109 | ||
020e0b1c | 110 | #ifdef CONFIG_GPIOLIB |
0a6d3158 | 111 | void gpiod_add_lookup_table(struct gpiod_lookup_table *table); |
3946d187 | 112 | void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); |
be9015ab | 113 | void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); |
a411e81e | 114 | void gpiod_add_hogs(struct gpiod_hog *hogs); |
dd61b292 | 115 | void gpiod_remove_hogs(struct gpiod_hog *hogs); |
f310f2ef | 116 | #else /* ! CONFIG_GPIOLIB */ |
020e0b1c AG |
117 | static inline |
118 | void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} | |
119 | static inline | |
3946d187 DT |
120 | void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} |
121 | static inline | |
020e0b1c | 122 | void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} |
a411e81e | 123 | static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {} |
dd61b292 | 124 | static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {} |
f310f2ef | 125 | #endif /* CONFIG_GPIOLIB */ |
0a6d3158 LW |
126 | |
127 | #endif /* __LINUX_GPIO_MACHINE_H */ |