]>
Commit | Line | Data |
---|---|---|
2744e8af LW |
1 | /* |
2 | * Core driver for the pin muxing portions of the pin control subsystem | |
3 | * | |
e93bcee0 | 4 | * Copyright (C) 2011-2012 ST-Ericsson SA |
2744e8af LW |
5 | * Written on behalf of Linaro for ST-Ericsson |
6 | * Based on bits of regulator core, gpio core and clk core | |
7 | * | |
8 | * Author: Linus Walleij <linus.walleij@linaro.org> | |
9 | * | |
10 | * License terms: GNU General Public License (GPL) version 2 | |
11 | */ | |
12 | #define pr_fmt(fmt) "pinmux core: " fmt | |
13 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/module.h> | |
16 | #include <linux/init.h> | |
17 | #include <linux/device.h> | |
18 | #include <linux/slab.h> | |
19 | #include <linux/radix-tree.h> | |
20 | #include <linux/err.h> | |
21 | #include <linux/list.h> | |
22 | #include <linux/mutex.h> | |
23 | #include <linux/spinlock.h> | |
97607d15 | 24 | #include <linux/string.h> |
2744e8af LW |
25 | #include <linux/sysfs.h> |
26 | #include <linux/debugfs.h> | |
27 | #include <linux/seq_file.h> | |
28 | #include <linux/pinctrl/machine.h> | |
29 | #include <linux/pinctrl/pinmux.h> | |
30 | #include "core.h" | |
befe5bdf | 31 | #include "pinmux.h" |
2744e8af LW |
32 | |
33 | /** | |
34 | * struct pinmux_group - group list item for pinmux groups | |
35 | * @node: pinmux group list node | |
d4e31987 SW |
36 | * @func_selector: the function selector for the pinmux device handling |
37 | * this pinmux | |
2744e8af LW |
38 | * @group_selector: the group selector for this group |
39 | */ | |
40 | struct pinmux_group { | |
41 | struct list_head node; | |
d4e31987 | 42 | unsigned func_selector; |
2744e8af LW |
43 | unsigned group_selector; |
44 | }; | |
45 | ||
03665e0f SW |
46 | int pinmux_check_ops(struct pinctrl_dev *pctldev) |
47 | { | |
48 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
49 | unsigned selector = 0; | |
50 | ||
51 | /* Check that we implement required operations */ | |
52 | if (!ops->list_functions || | |
53 | !ops->get_function_name || | |
54 | !ops->get_function_groups || | |
55 | !ops->enable || | |
56 | !ops->disable) | |
57 | return -EINVAL; | |
58 | ||
59 | /* Check that all functions registered have names */ | |
60 | while (ops->list_functions(pctldev, selector) >= 0) { | |
61 | const char *fname = ops->get_function_name(pctldev, | |
62 | selector); | |
63 | if (!fname) { | |
64 | pr_err("pinmux ops has no name for function%u\n", | |
65 | selector); | |
66 | return -EINVAL; | |
67 | } | |
68 | selector++; | |
69 | } | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
2744e8af LW |
74 | /** |
75 | * pin_request() - request a single pin to be muxed in, typically for GPIO | |
76 | * @pin: the pin number in the global pin space | |
3cc70ed3 SW |
77 | * @owner: a representation of the owner of this pin; typically the device |
78 | * name that controls its mux function, or the requested GPIO name | |
2744e8af LW |
79 | * @gpio_range: the range matching the GPIO pin if this is a request for a |
80 | * single GPIO pin | |
81 | */ | |
82 | static int pin_request(struct pinctrl_dev *pctldev, | |
3cc70ed3 | 83 | int pin, const char *owner, |
2744e8af LW |
84 | struct pinctrl_gpio_range *gpio_range) |
85 | { | |
86 | struct pin_desc *desc; | |
87 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
88 | int status = -EINVAL; | |
89 | ||
3cc70ed3 | 90 | dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, owner); |
2744e8af | 91 | |
2744e8af LW |
92 | desc = pin_desc_get(pctldev, pin); |
93 | if (desc == NULL) { | |
51cd24ee | 94 | dev_err(pctldev->dev, |
2744e8af LW |
95 | "pin is not registered so it cannot be requested\n"); |
96 | goto out; | |
97 | } | |
98 | ||
99 | spin_lock(&desc->lock); | |
3cc70ed3 | 100 | if (desc->owner && strcmp(desc->owner, owner)) { |
2744e8af | 101 | spin_unlock(&desc->lock); |
51cd24ee | 102 | dev_err(pctldev->dev, |
2744e8af LW |
103 | "pin already requested\n"); |
104 | goto out; | |
105 | } | |
3cc70ed3 | 106 | desc->owner = owner; |
2744e8af LW |
107 | spin_unlock(&desc->lock); |
108 | ||
109 | /* Let each pin increase references to this module */ | |
110 | if (!try_module_get(pctldev->owner)) { | |
51cd24ee | 111 | dev_err(pctldev->dev, |
2744e8af LW |
112 | "could not increase module refcount for pin %d\n", |
113 | pin); | |
114 | status = -EINVAL; | |
115 | goto out_free_pin; | |
116 | } | |
117 | ||
118 | /* | |
119 | * If there is no kind of request function for the pin we just assume | |
120 | * we got it by default and proceed. | |
121 | */ | |
3712a3c4 | 122 | if (gpio_range && ops->gpio_request_enable) |
2744e8af LW |
123 | /* This requests and enables a single GPIO pin */ |
124 | status = ops->gpio_request_enable(pctldev, gpio_range, pin); | |
125 | else if (ops->request) | |
126 | status = ops->request(pctldev, pin); | |
127 | else | |
128 | status = 0; | |
129 | ||
130 | if (status) | |
f9d41d7c | 131 | dev_err(pctldev->dev, "->request on device %s failed for pin %d\n", |
2744e8af LW |
132 | pctldev->desc->name, pin); |
133 | out_free_pin: | |
134 | if (status) { | |
135 | spin_lock(&desc->lock); | |
3cc70ed3 | 136 | desc->owner = NULL; |
2744e8af LW |
137 | spin_unlock(&desc->lock); |
138 | } | |
139 | out: | |
140 | if (status) | |
51cd24ee | 141 | dev_err(pctldev->dev, "pin-%d (%s) status %d\n", |
3cc70ed3 | 142 | pin, owner, status); |
2744e8af LW |
143 | |
144 | return status; | |
145 | } | |
146 | ||
147 | /** | |
148 | * pin_free() - release a single muxed in pin so something else can be muxed | |
149 | * @pctldev: pin controller device handling this pin | |
150 | * @pin: the pin to free | |
3712a3c4 SW |
151 | * @gpio_range: the range matching the GPIO pin if this is a request for a |
152 | * single GPIO pin | |
336cdba0 | 153 | * |
3cc70ed3 SW |
154 | * This function returns a pointer to the previous owner. This is used |
155 | * for callers that dynamically allocate an owner name so it can be freed | |
336cdba0 | 156 | * once the pin is free. This is done for GPIO request functions. |
2744e8af | 157 | */ |
3712a3c4 SW |
158 | static const char *pin_free(struct pinctrl_dev *pctldev, int pin, |
159 | struct pinctrl_gpio_range *gpio_range) | |
2744e8af LW |
160 | { |
161 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
162 | struct pin_desc *desc; | |
3cc70ed3 | 163 | const char *owner; |
2744e8af LW |
164 | |
165 | desc = pin_desc_get(pctldev, pin); | |
166 | if (desc == NULL) { | |
51cd24ee | 167 | dev_err(pctldev->dev, |
2744e8af | 168 | "pin is not registered so it cannot be freed\n"); |
3712a3c4 | 169 | return NULL; |
2744e8af LW |
170 | } |
171 | ||
3712a3c4 SW |
172 | /* |
173 | * If there is no kind of request function for the pin we just assume | |
174 | * we got it by default and proceed. | |
175 | */ | |
176 | if (gpio_range && ops->gpio_disable_free) | |
177 | ops->gpio_disable_free(pctldev, gpio_range, pin); | |
178 | else if (ops->free) | |
2744e8af LW |
179 | ops->free(pctldev, pin); |
180 | ||
181 | spin_lock(&desc->lock); | |
3cc70ed3 SW |
182 | owner = desc->owner; |
183 | desc->owner = NULL; | |
2744e8af LW |
184 | spin_unlock(&desc->lock); |
185 | module_put(pctldev->owner); | |
3712a3c4 | 186 | |
3cc70ed3 | 187 | return owner; |
2744e8af LW |
188 | } |
189 | ||
190 | /** | |
befe5bdf LW |
191 | * pinmux_request_gpio() - request pinmuxing for a GPIO pin |
192 | * @pctldev: pin controller device affected | |
193 | * @pin: the pin to mux in for GPIO | |
194 | * @range: the applicable GPIO range | |
2744e8af | 195 | */ |
befe5bdf LW |
196 | int pinmux_request_gpio(struct pinctrl_dev *pctldev, |
197 | struct pinctrl_gpio_range *range, | |
198 | unsigned pin, unsigned gpio) | |
2744e8af LW |
199 | { |
200 | char gpiostr[16]; | |
3cc70ed3 | 201 | const char *owner; |
2744e8af | 202 | int ret; |
2744e8af LW |
203 | |
204 | /* Conjure some name stating what chip and pin this is taken by */ | |
205 | snprintf(gpiostr, 15, "%s:%d", range->name, gpio); | |
206 | ||
3cc70ed3 SW |
207 | owner = kstrdup(gpiostr, GFP_KERNEL); |
208 | if (!owner) | |
5d2eaf80 SW |
209 | return -EINVAL; |
210 | ||
3cc70ed3 | 211 | ret = pin_request(pctldev, pin, owner, range); |
5d2eaf80 | 212 | if (ret < 0) |
3cc70ed3 | 213 | kfree(owner); |
5d2eaf80 SW |
214 | |
215 | return ret; | |
2744e8af | 216 | } |
2744e8af LW |
217 | |
218 | /** | |
befe5bdf LW |
219 | * pinmux_free_gpio() - release a pin from GPIO muxing |
220 | * @pctldev: the pin controller device for the pin | |
221 | * @pin: the affected currently GPIO-muxed in pin | |
222 | * @range: applicable GPIO range | |
2744e8af | 223 | */ |
befe5bdf LW |
224 | void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin, |
225 | struct pinctrl_gpio_range *range) | |
2744e8af | 226 | { |
3cc70ed3 | 227 | const char *owner; |
2744e8af | 228 | |
3cc70ed3 SW |
229 | owner = pin_free(pctldev, pin, range); |
230 | kfree(owner); | |
2744e8af | 231 | } |
2744e8af | 232 | |
befe5bdf LW |
233 | /** |
234 | * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin | |
235 | * @pctldev: the pin controller handling this pin | |
236 | * @range: applicable GPIO range | |
237 | * @pin: the affected GPIO pin in this controller | |
238 | * @input: true if we set the pin as input, false for output | |
239 | */ | |
240 | int pinmux_gpio_direction(struct pinctrl_dev *pctldev, | |
241 | struct pinctrl_gpio_range *range, | |
242 | unsigned pin, bool input) | |
542e704f | 243 | { |
542e704f LW |
244 | const struct pinmux_ops *ops; |
245 | int ret; | |
542e704f LW |
246 | |
247 | ops = pctldev->desc->pmxops; | |
248 | ||
542e704f LW |
249 | if (ops->gpio_set_direction) |
250 | ret = ops->gpio_set_direction(pctldev, range, pin, input); | |
251 | else | |
252 | ret = 0; | |
253 | ||
254 | return ret; | |
255 | } | |
256 | ||
2744e8af | 257 | /** |
de849eec | 258 | * acquire_pins() - acquire all the pins for a certain function on a pinmux |
2744e8af | 259 | * @pctldev: the device to take the pins on |
3cc70ed3 SW |
260 | * @owner: a representation of the owner of this pin; typically the device |
261 | * name that controls its mux function | |
2744e8af LW |
262 | * @group_selector: the group selector containing the pins to acquire |
263 | */ | |
264 | static int acquire_pins(struct pinctrl_dev *pctldev, | |
3cc70ed3 | 265 | const char *owner, |
2744e8af LW |
266 | unsigned group_selector) |
267 | { | |
268 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | |
a5818a8b | 269 | const unsigned *pins; |
2744e8af LW |
270 | unsigned num_pins; |
271 | int ret; | |
272 | int i; | |
273 | ||
274 | ret = pctlops->get_group_pins(pctldev, group_selector, | |
275 | &pins, &num_pins); | |
276 | if (ret) | |
277 | return ret; | |
278 | ||
51cd24ee | 279 | dev_dbg(pctldev->dev, "requesting the %u pins from group %u\n", |
2744e8af LW |
280 | num_pins, group_selector); |
281 | ||
282 | /* Try to allocate all pins in this group, one by one */ | |
283 | for (i = 0; i < num_pins; i++) { | |
3cc70ed3 | 284 | ret = pin_request(pctldev, pins[i], owner, NULL); |
2744e8af | 285 | if (ret) { |
51cd24ee | 286 | dev_err(pctldev->dev, |
3cc70ed3 SW |
287 | "could not get request pin %d on device %s - conflicting mux mappings?\n", |
288 | pins[i], | |
2744e8af LW |
289 | pinctrl_dev_get_name(pctldev)); |
290 | /* On error release all taken pins */ | |
291 | i--; /* this pin just failed */ | |
292 | for (; i >= 0; i--) | |
3712a3c4 | 293 | pin_free(pctldev, pins[i], NULL); |
2744e8af LW |
294 | return -ENODEV; |
295 | } | |
296 | } | |
297 | return 0; | |
298 | } | |
299 | ||
300 | /** | |
301 | * release_pins() - release pins taken by earlier acquirement | |
de849eec | 302 | * @pctldev: the device to free the pins on |
2744e8af LW |
303 | * @group_selector: the group selector containing the pins to free |
304 | */ | |
305 | static void release_pins(struct pinctrl_dev *pctldev, | |
306 | unsigned group_selector) | |
307 | { | |
308 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | |
a5818a8b | 309 | const unsigned *pins; |
2744e8af LW |
310 | unsigned num_pins; |
311 | int ret; | |
312 | int i; | |
313 | ||
314 | ret = pctlops->get_group_pins(pctldev, group_selector, | |
315 | &pins, &num_pins); | |
316 | if (ret) { | |
f9d41d7c | 317 | dev_err(pctldev->dev, "could not get pins to release for group selector %d\n", |
2744e8af LW |
318 | group_selector); |
319 | return; | |
320 | } | |
321 | for (i = 0; i < num_pins; i++) | |
3712a3c4 | 322 | pin_free(pctldev, pins[i], NULL); |
2744e8af LW |
323 | } |
324 | ||
2744e8af LW |
325 | /** |
326 | * pinmux_check_pin_group() - check function and pin group combo | |
327 | * @pctldev: device to check the pin group vs function for | |
328 | * @func_selector: the function selector to check the pin group for, we have | |
329 | * already looked this up in the calling function | |
330 | * @pin_group: the pin group to match to the function | |
331 | * | |
332 | * This function will check that the pinmux driver can supply the | |
333 | * selected pin group for a certain function, returns the group selector if | |
334 | * the group and function selector will work fine together, else returns | |
335 | * negative | |
336 | */ | |
337 | static int pinmux_check_pin_group(struct pinctrl_dev *pctldev, | |
338 | unsigned func_selector, | |
339 | const char *pin_group) | |
340 | { | |
341 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | |
342 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | |
343 | int ret; | |
344 | ||
345 | /* | |
346 | * If the driver does not support different pin groups for the | |
347 | * functions, we only support group 0, and assume this exists. | |
348 | */ | |
349 | if (!pctlops || !pctlops->list_groups) | |
350 | return 0; | |
351 | ||
352 | /* | |
353 | * Passing NULL (no specific group) will select the first and | |
354 | * hopefully only group of pins available for this function. | |
355 | */ | |
356 | if (!pin_group) { | |
357 | char const * const *groups; | |
358 | unsigned num_groups; | |
359 | ||
360 | ret = pmxops->get_function_groups(pctldev, func_selector, | |
361 | &groups, &num_groups); | |
362 | if (ret) | |
363 | return ret; | |
364 | if (num_groups < 1) | |
365 | return -EINVAL; | |
7afde8ba | 366 | ret = pinctrl_get_group_selector(pctldev, groups[0]); |
2744e8af | 367 | if (ret < 0) { |
51cd24ee | 368 | dev_err(pctldev->dev, |
f9d41d7c | 369 | "function %s wants group %s but the pin controller does not seem to have that group\n", |
2744e8af LW |
370 | pmxops->get_function_name(pctldev, func_selector), |
371 | groups[0]); | |
372 | return ret; | |
373 | } | |
374 | ||
375 | if (num_groups > 1) | |
51cd24ee | 376 | dev_dbg(pctldev->dev, |
f9d41d7c | 377 | "function %s support more than one group, default-selecting first group %s (%d)\n", |
2744e8af LW |
378 | pmxops->get_function_name(pctldev, func_selector), |
379 | groups[0], | |
380 | ret); | |
381 | ||
382 | return ret; | |
383 | } | |
384 | ||
51cd24ee | 385 | dev_dbg(pctldev->dev, |
2744e8af LW |
386 | "check if we have pin group %s on controller %s\n", |
387 | pin_group, pinctrl_dev_get_name(pctldev)); | |
388 | ||
7afde8ba | 389 | ret = pinctrl_get_group_selector(pctldev, pin_group); |
2744e8af | 390 | if (ret < 0) { |
51cd24ee | 391 | dev_dbg(pctldev->dev, |
2744e8af LW |
392 | "%s does not support pin group %s with function %s\n", |
393 | pinctrl_dev_get_name(pctldev), | |
394 | pin_group, | |
395 | pmxops->get_function_name(pctldev, func_selector)); | |
396 | } | |
397 | return ret; | |
398 | } | |
399 | ||
400 | /** | |
401 | * pinmux_search_function() - check pin control driver for a certain function | |
402 | * @pctldev: device to check for function and position | |
403 | * @map: function map containing the function and position to look for | |
404 | * @func_selector: returns the applicable function selector if found | |
405 | * @group_selector: returns the applicable group selector if found | |
406 | * | |
407 | * This will search the pinmux driver for an applicable | |
408 | * function with a specific pin group, returns 0 if these can be mapped | |
409 | * negative otherwise | |
410 | */ | |
411 | static int pinmux_search_function(struct pinctrl_dev *pctldev, | |
e93bcee0 | 412 | struct pinctrl_map const *map, |
2744e8af LW |
413 | unsigned *func_selector, |
414 | unsigned *group_selector) | |
415 | { | |
416 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
417 | unsigned selector = 0; | |
418 | ||
419 | /* See if this pctldev has this function */ | |
420 | while (ops->list_functions(pctldev, selector) >= 0) { | |
421 | const char *fname = ops->get_function_name(pctldev, | |
422 | selector); | |
423 | int ret; | |
424 | ||
425 | if (!strcmp(map->function, fname)) { | |
426 | /* Found the function, check pin group */ | |
427 | ret = pinmux_check_pin_group(pctldev, selector, | |
428 | map->group); | |
429 | if (ret < 0) | |
430 | return ret; | |
431 | ||
432 | /* This function and group selector can be used */ | |
433 | *func_selector = selector; | |
434 | *group_selector = ret; | |
435 | return 0; | |
436 | ||
437 | } | |
438 | selector++; | |
439 | } | |
440 | ||
441 | pr_err("%s does not support function %s\n", | |
442 | pinctrl_dev_get_name(pctldev), map->function); | |
443 | return -EINVAL; | |
444 | } | |
445 | ||
446 | /** | |
447 | * pinmux_enable_muxmap() - enable a map entry for a certain pinmux | |
448 | */ | |
449 | static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, | |
e93bcee0 | 450 | struct pinctrl *p, |
2744e8af LW |
451 | struct device *dev, |
452 | const char *devname, | |
e93bcee0 | 453 | struct pinctrl_map const *map) |
2744e8af LW |
454 | { |
455 | unsigned func_selector; | |
456 | unsigned group_selector; | |
457 | struct pinmux_group *grp; | |
458 | int ret; | |
459 | ||
460 | /* | |
461 | * Note that we're not locking the pinmux mutex here, because | |
462 | * this is only called at pinmux initialization time when it | |
463 | * has not been added to any list and thus is not reachable | |
464 | * by anyone else. | |
465 | */ | |
466 | ||
e93bcee0 | 467 | if (p->pctldev && p->pctldev != pctldev) { |
51cd24ee | 468 | dev_err(pctldev->dev, |
f9d41d7c UKK |
469 | "different pin control devices given for device %s, function %s\n", |
470 | devname, map->function); | |
2744e8af LW |
471 | return -EINVAL; |
472 | } | |
e93bcee0 LW |
473 | p->dev = dev; |
474 | p->pctldev = pctldev; | |
2744e8af LW |
475 | |
476 | /* Now go into the driver and try to match a function and group */ | |
477 | ret = pinmux_search_function(pctldev, map, &func_selector, | |
478 | &group_selector); | |
479 | if (ret < 0) | |
480 | return ret; | |
481 | ||
2744e8af | 482 | /* Now add this group selector, we may have many of them */ |
02f5b989 | 483 | grp = kmalloc(sizeof(*grp), GFP_KERNEL); |
2744e8af LW |
484 | if (!grp) |
485 | return -ENOMEM; | |
d4e31987 | 486 | grp->func_selector = func_selector; |
2744e8af | 487 | grp->group_selector = group_selector; |
3cc70ed3 | 488 | ret = acquire_pins(pctldev, devname, group_selector); |
2744e8af LW |
489 | if (ret) { |
490 | kfree(grp); | |
491 | return ret; | |
492 | } | |
8b9c139f | 493 | list_add_tail(&grp->node, &p->groups); |
2744e8af LW |
494 | |
495 | return 0; | |
496 | } | |
497 | ||
2744e8af | 498 | /** |
befe5bdf | 499 | * pinmux_apply_muxmap() - apply a certain mux mapping entry |
2744e8af | 500 | */ |
befe5bdf LW |
501 | int pinmux_apply_muxmap(struct pinctrl_dev *pctldev, |
502 | struct pinctrl *p, | |
503 | struct device *dev, | |
504 | const char *devname, | |
505 | struct pinctrl_map const *map) | |
2744e8af | 506 | { |
befe5bdf | 507 | int ret; |
2744e8af | 508 | |
befe5bdf LW |
509 | ret = pinmux_enable_muxmap(pctldev, p, dev, |
510 | devname, map); | |
511 | if (ret) { | |
512 | pinmux_put(p); | |
513 | return ret; | |
2744e8af LW |
514 | } |
515 | ||
befe5bdf | 516 | return 0; |
2744e8af | 517 | } |
2744e8af LW |
518 | |
519 | /** | |
befe5bdf | 520 | * pinmux_put() - free up the pinmux portions of a pin controller handle |
2744e8af | 521 | */ |
befe5bdf | 522 | void pinmux_put(struct pinctrl *p) |
2744e8af | 523 | { |
befe5bdf | 524 | struct list_head *node, *tmp; |
2744e8af | 525 | |
befe5bdf LW |
526 | list_for_each_safe(node, tmp, &p->groups) { |
527 | struct pinmux_group *grp = | |
528 | list_entry(node, struct pinmux_group, node); | |
529 | /* Release all pins taken by this group */ | |
530 | release_pins(p->pctldev, grp->group_selector); | |
531 | list_del(node); | |
532 | kfree(grp); | |
533 | } | |
2744e8af | 534 | } |
2744e8af LW |
535 | |
536 | /** | |
befe5bdf | 537 | * pinmux_enable() - enable the pinmux portion of a pin control handle |
2744e8af | 538 | */ |
befe5bdf | 539 | int pinmux_enable(struct pinctrl *p) |
2744e8af | 540 | { |
befe5bdf LW |
541 | struct pinctrl_dev *pctldev = p->pctldev; |
542 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
543 | struct pinmux_group *grp; | |
544 | int ret; | |
2744e8af | 545 | |
befe5bdf | 546 | list_for_each_entry(grp, &p->groups, node) { |
d4e31987 | 547 | ret = ops->enable(pctldev, grp->func_selector, |
befe5bdf LW |
548 | grp->group_selector); |
549 | if (ret) | |
550 | /* | |
551 | * TODO: call disable() on all groups we called | |
552 | * enable() on to this point? | |
553 | */ | |
554 | return ret; | |
2744e8af | 555 | } |
befe5bdf | 556 | return 0; |
2744e8af | 557 | } |
2744e8af LW |
558 | |
559 | /** | |
befe5bdf | 560 | * pinmux_disable() - disable the pinmux portions of a pin control handle |
2744e8af | 561 | */ |
befe5bdf | 562 | void pinmux_disable(struct pinctrl *p) |
2744e8af | 563 | { |
befe5bdf LW |
564 | struct pinctrl_dev *pctldev = p->pctldev; |
565 | const struct pinmux_ops *ops = pctldev->desc->pmxops; | |
566 | struct pinmux_group *grp; | |
2744e8af | 567 | |
befe5bdf | 568 | list_for_each_entry(grp, &p->groups, node) { |
d4e31987 | 569 | ops->disable(pctldev, grp->func_selector, |
befe5bdf | 570 | grp->group_selector); |
2744e8af | 571 | } |
2744e8af | 572 | } |
2744e8af | 573 | |
2744e8af LW |
574 | #ifdef CONFIG_DEBUG_FS |
575 | ||
576 | /* Called from pincontrol core */ | |
577 | static int pinmux_functions_show(struct seq_file *s, void *what) | |
578 | { | |
579 | struct pinctrl_dev *pctldev = s->private; | |
580 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | |
581 | unsigned func_selector = 0; | |
582 | ||
583 | while (pmxops->list_functions(pctldev, func_selector) >= 0) { | |
584 | const char *func = pmxops->get_function_name(pctldev, | |
585 | func_selector); | |
586 | const char * const *groups; | |
587 | unsigned num_groups; | |
588 | int ret; | |
589 | int i; | |
590 | ||
591 | ret = pmxops->get_function_groups(pctldev, func_selector, | |
592 | &groups, &num_groups); | |
593 | if (ret) | |
594 | seq_printf(s, "function %s: COULD NOT GET GROUPS\n", | |
595 | func); | |
596 | ||
597 | seq_printf(s, "function: %s, groups = [ ", func); | |
598 | for (i = 0; i < num_groups; i++) | |
599 | seq_printf(s, "%s ", groups[i]); | |
600 | seq_puts(s, "]\n"); | |
601 | ||
602 | func_selector++; | |
603 | ||
604 | } | |
605 | ||
606 | return 0; | |
607 | } | |
608 | ||
609 | static int pinmux_pins_show(struct seq_file *s, void *what) | |
610 | { | |
611 | struct pinctrl_dev *pctldev = s->private; | |
706e8520 | 612 | unsigned i, pin; |
2744e8af LW |
613 | |
614 | seq_puts(s, "Pinmux settings per pin\n"); | |
3cc70ed3 | 615 | seq_puts(s, "Format: pin (name): owner\n"); |
2744e8af | 616 | |
706e8520 CP |
617 | /* The pin number can be retrived from the pin controller descriptor */ |
618 | for (i = 0; i < pctldev->desc->npins; i++) { | |
2744e8af | 619 | struct pin_desc *desc; |
1cf94c45 | 620 | bool is_hog = false; |
2744e8af | 621 | |
706e8520 | 622 | pin = pctldev->desc->pins[i].number; |
2744e8af | 623 | desc = pin_desc_get(pctldev, pin); |
706e8520 | 624 | /* Skip if we cannot search the pin */ |
2744e8af LW |
625 | if (desc == NULL) |
626 | continue; | |
627 | ||
1cf94c45 LW |
628 | if (desc->owner && |
629 | !strcmp(desc->owner, pinctrl_dev_get_name(pctldev))) | |
630 | is_hog = true; | |
631 | ||
632 | seq_printf(s, "pin %d (%s): %s%s\n", pin, | |
2744e8af | 633 | desc->name ? desc->name : "unnamed", |
1cf94c45 LW |
634 | desc->owner ? desc->owner : "UNCLAIMED", |
635 | is_hog ? " (HOG)" : ""); | |
2744e8af LW |
636 | } |
637 | ||
638 | return 0; | |
639 | } | |
640 | ||
befe5bdf | 641 | void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p) |
2744e8af | 642 | { |
befe5bdf LW |
643 | struct pinctrl_dev *pctldev = p->pctldev; |
644 | const struct pinmux_ops *pmxops; | |
645 | const struct pinctrl_ops *pctlops; | |
646 | struct pinmux_group *grp; | |
d4e31987 | 647 | const char *sep = ""; |
2744e8af | 648 | |
befe5bdf LW |
649 | pmxops = pctldev->desc->pmxops; |
650 | pctlops = pctldev->desc->pctlops; | |
2744e8af | 651 | |
befe5bdf LW |
652 | seq_printf(s, " groups: ["); |
653 | list_for_each_entry(grp, &p->groups, node) { | |
d4e31987 SW |
654 | seq_printf(s, "%s%s (%u)=%s (%u)", |
655 | sep, | |
befe5bdf LW |
656 | pctlops->get_group_name(pctldev, |
657 | grp->group_selector), | |
d4e31987 SW |
658 | grp->group_selector, |
659 | pmxops->get_function_name(pctldev, | |
660 | grp->func_selector), | |
661 | grp->func_selector); | |
662 | sep = ", "; | |
2744e8af | 663 | } |
befe5bdf | 664 | seq_printf(s, " ]"); |
2744e8af LW |
665 | } |
666 | ||
667 | static int pinmux_functions_open(struct inode *inode, struct file *file) | |
668 | { | |
669 | return single_open(file, pinmux_functions_show, inode->i_private); | |
670 | } | |
671 | ||
672 | static int pinmux_pins_open(struct inode *inode, struct file *file) | |
673 | { | |
674 | return single_open(file, pinmux_pins_show, inode->i_private); | |
675 | } | |
676 | ||
2744e8af LW |
677 | static const struct file_operations pinmux_functions_ops = { |
678 | .open = pinmux_functions_open, | |
679 | .read = seq_read, | |
680 | .llseek = seq_lseek, | |
681 | .release = single_release, | |
682 | }; | |
683 | ||
684 | static const struct file_operations pinmux_pins_ops = { | |
685 | .open = pinmux_pins_open, | |
686 | .read = seq_read, | |
687 | .llseek = seq_lseek, | |
688 | .release = single_release, | |
689 | }; | |
690 | ||
2744e8af LW |
691 | void pinmux_init_device_debugfs(struct dentry *devroot, |
692 | struct pinctrl_dev *pctldev) | |
693 | { | |
694 | debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO, | |
695 | devroot, pctldev, &pinmux_functions_ops); | |
696 | debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO, | |
697 | devroot, pctldev, &pinmux_pins_ops); | |
2744e8af LW |
698 | } |
699 | ||
700 | #endif /* CONFIG_DEBUG_FS */ |