1
2
3
4
5
6
7
8
9
10
11
12#include <linux/kref.h>
13#include <linux/mutex.h>
14#include <linux/radix-tree.h>
15#include <linux/pinctrl/pinconf.h>
16#include <linux/pinctrl/machine.h>
17
18struct pinctrl_gpio_range;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43struct pinctrl_dev {
44 struct list_head node;
45 struct pinctrl_desc *desc;
46 struct radix_tree_root pin_desc_tree;
47#ifdef CONFIG_GENERIC_PINCTRL_GROUPS
48 struct radix_tree_root pin_group_tree;
49 unsigned int num_groups;
50#endif
51#ifdef CONFIG_GENERIC_PINMUX_FUNCTIONS
52 struct radix_tree_root pin_function_tree;
53 unsigned int num_functions;
54#endif
55 struct list_head gpio_ranges;
56 struct device *dev;
57 struct module *owner;
58 void *driver_data;
59 struct pinctrl *p;
60 struct pinctrl_state *hog_default;
61 struct pinctrl_state *hog_sleep;
62 struct mutex mutex;
63#ifdef CONFIG_DEBUG_FS
64 struct dentry *device_root;
65#endif
66};
67
68
69
70
71
72
73
74
75
76
77
78struct pinctrl {
79 struct list_head node;
80 struct device *dev;
81 struct list_head states;
82 struct pinctrl_state *state;
83 struct list_head dt_maps;
84 struct kref users;
85};
86
87
88
89
90
91
92
93struct pinctrl_state {
94 struct list_head node;
95 const char *name;
96 struct list_head settings;
97};
98
99
100
101
102
103
104struct pinctrl_setting_mux {
105 unsigned group;
106 unsigned func;
107};
108
109
110
111
112
113
114
115
116
117struct pinctrl_setting_configs {
118 unsigned group_or_pin;
119 unsigned long *configs;
120 unsigned num_configs;
121};
122
123
124
125
126
127
128
129
130
131
132struct pinctrl_setting {
133 struct list_head node;
134 enum pinctrl_map_type type;
135 struct pinctrl_dev *pctldev;
136 const char *dev_name;
137 union {
138 struct pinctrl_setting_mux mux;
139 struct pinctrl_setting_configs configs;
140 } data;
141};
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160struct pin_desc {
161 struct pinctrl_dev *pctldev;
162 const char *name;
163 bool dynamic_name;
164 void *drv_data;
165
166#ifdef CONFIG_PINMUX
167 unsigned mux_usecount;
168 const char *mux_owner;
169 const struct pinctrl_setting_mux *mux_setting;
170 const char *gpio_owner;
171#endif
172};
173
174
175
176
177
178
179
180struct pinctrl_maps {
181 struct list_head node;
182 const struct pinctrl_map *maps;
183 unsigned num_maps;
184};
185
186#ifdef CONFIG_GENERIC_PINCTRL_GROUPS
187
188
189
190
191
192
193
194
195struct group_desc {
196 const char *name;
197 int *pins;
198 int num_pins;
199 void *data;
200};
201
202int pinctrl_generic_get_group_count(struct pinctrl_dev *pctldev);
203
204const char *pinctrl_generic_get_group_name(struct pinctrl_dev *pctldev,
205 unsigned int group_selector);
206
207int pinctrl_generic_get_group_pins(struct pinctrl_dev *pctldev,
208 unsigned int group_selector,
209 const unsigned int **pins,
210 unsigned int *npins);
211
212struct group_desc *pinctrl_generic_get_group(struct pinctrl_dev *pctldev,
213 unsigned int group_selector);
214
215int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name,
216 int *gpins, int ngpins, void *data);
217
218int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev,
219 unsigned int group_selector);
220
221static inline int
222pinctrl_generic_remove_last_group(struct pinctrl_dev *pctldev)
223{
224 return pinctrl_generic_remove_group(pctldev, pctldev->num_groups - 1);
225}
226
227#endif
228
229struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
230struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np);
231int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
232const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
233int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
234 const char *pin_group);
235
236static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
237 unsigned int pin)
238{
239 return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
240}
241
242extern struct pinctrl_gpio_range *
243pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev,
244 unsigned int pin);
245
246int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps,
247 bool dup);
248void pinctrl_unregister_map(const struct pinctrl_map *map);
249
250extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
251extern int pinctrl_force_default(struct pinctrl_dev *pctldev);
252
253extern struct mutex pinctrl_maps_mutex;
254extern struct list_head pinctrl_maps;
255
256#define for_each_maps(_maps_node_, _i_, _map_) \
257 list_for_each_entry(_maps_node_, &pinctrl_maps, node) \
258 for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \
259 _i_ < _maps_node_->num_maps; \
260 _i_++, _map_ = &_maps_node_->maps[_i_])
261