2 * Core driver for the pin muxing portions of the pin control subsystem
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core
8 * Author: Linus Walleij <linus.walleij@linaro.org>
10 * License terms: GNU General Public License (GPL) version 2
12 #define pr_fmt(fmt) "pinmux core: " fmt
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>
24 #include <linux/sysfs.h>
25 #include <linux/debugfs.h>
26 #include <linux/seq_file.h>
27 #include <linux/pinctrl/machine.h>
28 #include <linux/pinctrl/pinmux.h>
31 /* List of pinmuxes */
32 static DEFINE_MUTEX(pinmux_list_mutex
);
33 static LIST_HEAD(pinmux_list
);
35 /* List of pinmux hogs */
36 static DEFINE_MUTEX(pinmux_hoglist_mutex
);
37 static LIST_HEAD(pinmux_hoglist
);
39 /* Global pinmux maps, we allow one set only */
40 static struct pinmux_map
const *pinmux_maps
;
41 static unsigned pinmux_maps_num
;
44 * struct pinmux_group - group list item for pinmux groups
45 * @node: pinmux group list node
46 * @group_selector: the group selector for this group
49 struct list_head node
;
50 unsigned group_selector
;
54 * struct pinmux - per-device pinmux state holder
55 * @node: global list node
56 * @dev: the device using this pinmux
57 * @usecount: the number of active users of this mux setting, used to keep
58 * track of nested use cases
59 * @pins: an array of discrete physical pins used in this mapping, taken
60 * from the global pin enumeration space (copied from pinmux map)
61 * @num_pins: the number of pins in this mapping array, i.e. the number of
62 * elements in .pins so we can iterate over that array (copied from
64 * @pctldev: pin control device handling this pinmux
65 * @func_selector: the function selector for the pinmux device handling
67 * @groups: the group selectors for the pinmux device and
68 * selector combination handling this pinmux, this is a list that
69 * will be traversed on all pinmux operations such as
70 * get/put/enable/disable
71 * @mutex: a lock for the pinmux state holder
74 struct list_head node
;
77 struct pinctrl_dev
*pctldev
;
78 unsigned func_selector
;
79 struct list_head groups
;
84 * struct pinmux_hog - a list item to stash mux hogs
85 * @node: pinmux hog list node
86 * @map: map entry responsible for this hogging
87 * @pmx: the pinmux hogged by this item
90 struct list_head node
;
91 struct pinmux_map
const *map
;
96 * pin_request() - request a single pin to be muxed in, typically for GPIO
97 * @pin: the pin number in the global pin space
98 * @function: a functional name to give to this pin, passed to the driver
99 * so it knows what function to mux in, e.g. the string "gpioNN"
100 * means that you want to mux in the pin for use as GPIO number NN
101 * @gpio: if this request concerns a single GPIO pin
102 * @gpio_range: the range matching the GPIO pin if this is a request for a
105 static int pin_request(struct pinctrl_dev
*pctldev
,
106 int pin
, const char *function
, bool gpio
,
107 struct pinctrl_gpio_range
*gpio_range
)
109 struct pin_desc
*desc
;
110 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
111 int status
= -EINVAL
;
113 dev_dbg(&pctldev
->dev
, "request pin %d for %s\n", pin
, function
);
115 if (!pin_is_valid(pctldev
, pin
)) {
116 dev_err(&pctldev
->dev
, "pin is invalid\n");
121 dev_err(&pctldev
->dev
, "no function name given\n");
125 desc
= pin_desc_get(pctldev
, pin
);
127 dev_err(&pctldev
->dev
,
128 "pin is not registered so it cannot be requested\n");
132 spin_lock(&desc
->lock
);
133 if (desc
->mux_requested
) {
134 spin_unlock(&desc
->lock
);
135 dev_err(&pctldev
->dev
,
136 "pin already requested\n");
139 desc
->mux_requested
= true;
140 strncpy(desc
->mux_function
, function
, sizeof(desc
->mux_function
));
141 spin_unlock(&desc
->lock
);
143 /* Let each pin increase references to this module */
144 if (!try_module_get(pctldev
->owner
)) {
145 dev_err(&pctldev
->dev
,
146 "could not increase module refcount for pin %d\n",
153 * If there is no kind of request function for the pin we just assume
154 * we got it by default and proceed.
156 if (gpio
&& ops
->gpio_request_enable
)
157 /* This requests and enables a single GPIO pin */
158 status
= ops
->gpio_request_enable(pctldev
, gpio_range
, pin
);
159 else if (ops
->request
)
160 status
= ops
->request(pctldev
, pin
);
165 dev_err(&pctldev
->dev
, "->request on device %s failed "
167 pctldev
->desc
->name
, pin
);
170 spin_lock(&desc
->lock
);
171 desc
->mux_requested
= false;
172 desc
->mux_function
[0] = '\0';
173 spin_unlock(&desc
->lock
);
177 dev_err(&pctldev
->dev
, "pin-%d (%s) status %d\n",
178 pin
, function
? : "?", status
);
184 * pin_free() - release a single muxed in pin so something else can be muxed
185 * @pctldev: pin controller device handling this pin
186 * @pin: the pin to free
188 static void pin_free(struct pinctrl_dev
*pctldev
, int pin
)
190 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
191 struct pin_desc
*desc
;
193 desc
= pin_desc_get(pctldev
, pin
);
195 dev_err(&pctldev
->dev
,
196 "pin is not registered so it cannot be freed\n");
201 ops
->free(pctldev
, pin
);
203 spin_lock(&desc
->lock
);
204 desc
->mux_requested
= false;
205 desc
->mux_function
[0] = '\0';
206 spin_unlock(&desc
->lock
);
207 module_put(pctldev
->owner
);
211 * pinmux_request_gpio() - request a single pin to be muxed in as GPIO
212 * @gpio: the GPIO pin number from the GPIO subsystem number space
214 int pinmux_request_gpio(unsigned gpio
)
217 struct pinctrl_dev
*pctldev
;
218 struct pinctrl_gpio_range
*range
;
222 ret
= pinctrl_get_device_gpio_range(gpio
, &pctldev
, &range
);
226 /* Convert to the pin controllers number space */
227 pin
= gpio
- range
->base
;
229 /* Conjure some name stating what chip and pin this is taken by */
230 snprintf(gpiostr
, 15, "%s:%d", range
->name
, gpio
);
232 return pin_request(pctldev
, pin
, gpiostr
, true, range
);
234 EXPORT_SYMBOL_GPL(pinmux_request_gpio
);
237 * pinmux_free_gpio() - free a single pin, currently used as GPIO
238 * @gpio: the GPIO pin number from the GPIO subsystem number space
240 void pinmux_free_gpio(unsigned gpio
)
242 struct pinctrl_dev
*pctldev
;
243 struct pinctrl_gpio_range
*range
;
247 ret
= pinctrl_get_device_gpio_range(gpio
, &pctldev
, &range
);
251 /* Convert to the pin controllers number space */
252 pin
= gpio
- range
->base
;
254 pin_free(pctldev
, pin
);
256 EXPORT_SYMBOL_GPL(pinmux_free_gpio
);
259 * pinmux_register_mappings() - register a set of pinmux mappings
260 * @maps: the pinmux mappings table to register
261 * @num_maps: the number of maps in the mapping table
263 * Only call this once during initialization of your machine, the function is
264 * tagged as __init and won't be callable after init has completed. The map
265 * passed into this function will be owned by the pinmux core and cannot be
268 int __init
pinmux_register_mappings(struct pinmux_map
const *maps
,
273 if (pinmux_maps
!= NULL
) {
274 pr_err("pinmux mappings already registered, you can only "
275 "register one set of maps\n");
279 pr_debug("add %d pinmux maps\n", num_maps
);
280 for (i
= 0; i
< num_maps
; i
++) {
281 /* Sanity check the mapping */
283 pr_err("failed to register map %d: "
284 "no map name given\n", i
);
287 if (!maps
[i
].ctrl_dev
&& !maps
[i
].ctrl_dev_name
) {
288 pr_err("failed to register map %s (%d): "
289 "no pin control device given\n",
293 if (!maps
[i
].function
) {
294 pr_err("failed to register map %s (%d): "
295 "no function ID given\n", maps
[i
].name
, i
);
299 if (!maps
[i
].dev
&& !maps
[i
].dev_name
)
300 pr_debug("add system map %s function %s with no device\n",
304 pr_debug("register map %s, function %s\n",
310 pinmux_maps_num
= num_maps
;
316 * acquire_pins() - acquire all the pins for a certain funcion on a pinmux
317 * @pctldev: the device to take the pins on
318 * @func_selector: the function selector to acquire the pins for
319 * @group_selector: the group selector containing the pins to acquire
321 static int acquire_pins(struct pinctrl_dev
*pctldev
,
322 unsigned func_selector
,
323 unsigned group_selector
)
325 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
326 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
327 const char *func
= pmxops
->get_function_name(pctldev
,
334 ret
= pctlops
->get_group_pins(pctldev
, group_selector
,
339 dev_dbg(&pctldev
->dev
, "requesting the %u pins from group %u\n",
340 num_pins
, group_selector
);
342 /* Try to allocate all pins in this group, one by one */
343 for (i
= 0; i
< num_pins
; i
++) {
344 ret
= pin_request(pctldev
, pins
[i
], func
, false, NULL
);
346 dev_err(&pctldev
->dev
,
347 "could not get pin %d for function %s "
348 "on device %s - conflicting mux mappings?\n",
349 pins
[i
], func
? : "(undefined)",
350 pinctrl_dev_get_name(pctldev
));
351 /* On error release all taken pins */
352 i
--; /* this pin just failed */
354 pin_free(pctldev
, pins
[i
]);
362 * release_pins() - release pins taken by earlier acquirement
363 * @pctldev: the device to free the pinx on
364 * @group_selector: the group selector containing the pins to free
366 static void release_pins(struct pinctrl_dev
*pctldev
,
367 unsigned group_selector
)
369 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
375 ret
= pctlops
->get_group_pins(pctldev
, group_selector
,
378 dev_err(&pctldev
->dev
, "could not get pins to release for "
379 "group selector %d\n",
383 for (i
= 0; i
< num_pins
; i
++)
384 pin_free(pctldev
, pins
[i
]);
388 * pinmux_get_group_selector() - returns the group selector for a group
389 * @pctldev: the pin controller handling the group
390 * @pin_group: the pin group to look up
392 static int pinmux_get_group_selector(struct pinctrl_dev
*pctldev
,
393 const char *pin_group
)
395 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
396 unsigned group_selector
= 0;
398 while (pctlops
->list_groups(pctldev
, group_selector
) >= 0) {
399 const char *gname
= pctlops
->get_group_name(pctldev
,
401 if (!strcmp(gname
, pin_group
)) {
402 dev_dbg(&pctldev
->dev
,
403 "found group selector %u for %s\n",
406 return group_selector
;
412 dev_err(&pctldev
->dev
, "does not have pin group %s\n",
419 * pinmux_check_pin_group() - check function and pin group combo
420 * @pctldev: device to check the pin group vs function for
421 * @func_selector: the function selector to check the pin group for, we have
422 * already looked this up in the calling function
423 * @pin_group: the pin group to match to the function
425 * This function will check that the pinmux driver can supply the
426 * selected pin group for a certain function, returns the group selector if
427 * the group and function selector will work fine together, else returns
430 static int pinmux_check_pin_group(struct pinctrl_dev
*pctldev
,
431 unsigned func_selector
,
432 const char *pin_group
)
434 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
435 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
439 * If the driver does not support different pin groups for the
440 * functions, we only support group 0, and assume this exists.
442 if (!pctlops
|| !pctlops
->list_groups
)
446 * Passing NULL (no specific group) will select the first and
447 * hopefully only group of pins available for this function.
450 char const * const *groups
;
453 ret
= pmxops
->get_function_groups(pctldev
, func_selector
,
454 &groups
, &num_groups
);
459 ret
= pinmux_get_group_selector(pctldev
, groups
[0]);
461 dev_err(&pctldev
->dev
,
462 "function %s wants group %s but the pin "
463 "controller does not seem to have that group\n",
464 pmxops
->get_function_name(pctldev
, func_selector
),
470 dev_dbg(&pctldev
->dev
,
471 "function %s support more than one group, "
472 "default-selecting first group %s (%d)\n",
473 pmxops
->get_function_name(pctldev
, func_selector
),
480 dev_dbg(&pctldev
->dev
,
481 "check if we have pin group %s on controller %s\n",
482 pin_group
, pinctrl_dev_get_name(pctldev
));
484 ret
= pinmux_get_group_selector(pctldev
, pin_group
);
486 dev_dbg(&pctldev
->dev
,
487 "%s does not support pin group %s with function %s\n",
488 pinctrl_dev_get_name(pctldev
),
490 pmxops
->get_function_name(pctldev
, func_selector
));
496 * pinmux_search_function() - check pin control driver for a certain function
497 * @pctldev: device to check for function and position
498 * @map: function map containing the function and position to look for
499 * @func_selector: returns the applicable function selector if found
500 * @group_selector: returns the applicable group selector if found
502 * This will search the pinmux driver for an applicable
503 * function with a specific pin group, returns 0 if these can be mapped
506 static int pinmux_search_function(struct pinctrl_dev
*pctldev
,
507 struct pinmux_map
const *map
,
508 unsigned *func_selector
,
509 unsigned *group_selector
)
511 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
512 unsigned selector
= 0;
514 /* See if this pctldev has this function */
515 while (ops
->list_functions(pctldev
, selector
) >= 0) {
516 const char *fname
= ops
->get_function_name(pctldev
,
520 if (!strcmp(map
->function
, fname
)) {
521 /* Found the function, check pin group */
522 ret
= pinmux_check_pin_group(pctldev
, selector
,
527 /* This function and group selector can be used */
528 *func_selector
= selector
;
529 *group_selector
= ret
;
536 pr_err("%s does not support function %s\n",
537 pinctrl_dev_get_name(pctldev
), map
->function
);
542 * pinmux_enable_muxmap() - enable a map entry for a certain pinmux
544 static int pinmux_enable_muxmap(struct pinctrl_dev
*pctldev
,
548 struct pinmux_map
const *map
)
550 unsigned func_selector
;
551 unsigned group_selector
;
552 struct pinmux_group
*grp
;
556 * Note that we're not locking the pinmux mutex here, because
557 * this is only called at pinmux initialization time when it
558 * has not been added to any list and thus is not reachable
562 if (pmx
->pctldev
&& pmx
->pctldev
!= pctldev
) {
563 dev_err(&pctldev
->dev
,
564 "different pin control devices given for device %s, "
571 pmx
->pctldev
= pctldev
;
573 /* Now go into the driver and try to match a function and group */
574 ret
= pinmux_search_function(pctldev
, map
, &func_selector
,
580 * If the function selector is already set, it needs to be identical,
581 * we support several groups with one function but not several
582 * functions with one or several groups in the same pinmux.
584 if (pmx
->func_selector
!= UINT_MAX
&&
585 pmx
->func_selector
!= func_selector
) {
586 dev_err(&pctldev
->dev
,
587 "dual function defines in the map for device %s\n",
591 pmx
->func_selector
= func_selector
;
593 /* Now add this group selector, we may have many of them */
594 grp
= kmalloc(sizeof(struct pinmux_group
), GFP_KERNEL
);
597 grp
->group_selector
= group_selector
;
598 ret
= acquire_pins(pctldev
, func_selector
, group_selector
);
603 list_add(&grp
->node
, &pmx
->groups
);
608 static void pinmux_free_groups(struct pinmux
*pmx
)
610 struct list_head
*node
, *tmp
;
612 list_for_each_safe(node
, tmp
, &pmx
->groups
) {
613 struct pinmux_group
*grp
=
614 list_entry(node
, struct pinmux_group
, node
);
615 /* Release all pins taken by this group */
616 release_pins(pmx
->pctldev
, grp
->group_selector
);
623 * pinmux_get() - retrieves the pinmux for a certain device
624 * @dev: the device to get the pinmux for
625 * @name: an optional specific mux mapping name or NULL, the name is only
626 * needed if you want to have more than one mapping per device, or if you
627 * need an anonymous pinmux (not tied to any specific device)
629 struct pinmux
*pinmux_get(struct device
*dev
, const char *name
)
632 struct pinmux_map
const *map
= NULL
;
633 struct pinctrl_dev
*pctldev
= NULL
;
634 const char *devname
= NULL
;
637 unsigned num_maps
= 0;
641 /* We must have dev or ID or both */
643 return ERR_PTR(-EINVAL
);
646 devname
= dev_name(dev
);
648 pr_debug("get mux %s for device %s\n", name
,
649 devname
? devname
: "(none)");
652 * create the state cookie holder struct pinmux for each
653 * mapping, this is what consumers will get when requesting
654 * a pinmux handle with pinmux_get()
656 pmx
= kzalloc(sizeof(struct pinmux
), GFP_KERNEL
);
658 return ERR_PTR(-ENOMEM
);
659 mutex_init(&pmx
->mutex
);
660 pmx
->func_selector
= UINT_MAX
;
661 INIT_LIST_HEAD(&pmx
->groups
);
663 /* Iterate over the pinmux maps to locate the right ones */
664 for (i
= 0; i
< pinmux_maps_num
; i
++) {
665 map
= &pinmux_maps
[i
];
669 * First, try to find the pctldev given in the map
671 pctldev
= get_pinctrl_dev_from_dev(map
->ctrl_dev
,
674 const char *devname
= NULL
;
677 devname
= dev_name(map
->ctrl_dev
);
678 else if (map
->ctrl_dev_name
)
679 devname
= map
->ctrl_dev_name
;
681 pr_warning("could not find a pinctrl device for pinmux "
682 "function %s, fishy, they shall all have one\n",
684 pr_warning("given pinctrl device name: %s",
685 devname
? devname
: "UNDEFINED");
687 /* Continue to check the other mappings anyway... */
691 pr_debug("in map, found pctldev %s to handle function %s",
692 dev_name(&pctldev
->dev
), map
->function
);
696 * If we're looking for a specific named map, this must match,
697 * else we loop and look for the next.
700 if (map
->name
== NULL
)
702 if (strcmp(map
->name
, name
))
707 * This is for the case where no device name is given, we
708 * already know that the function name matches from above
711 if (!map
->dev_name
&& (name
!= NULL
))
714 /* If the mapping has a device set up it must match */
716 (!devname
|| !strcmp(map
->dev_name
, devname
)))
720 /* If this map is applicable, then apply it */
722 ret
= pinmux_enable_muxmap(pctldev
, pmx
, dev
,
725 pinmux_free_groups(pmx
);
734 /* We should have atleast one map, right */
736 pr_err("could not find any mux maps for device %s, ID %s\n",
737 devname
? devname
: "(anonymous)",
738 name
? name
: "(undefined)");
740 return ERR_PTR(-EINVAL
);
743 pr_debug("found %u mux maps for device %s, UD %s\n",
745 devname
? devname
: "(anonymous)",
746 name
? name
: "(undefined)");
748 /* Add the pinmux to the global list */
749 mutex_lock(&pinmux_list_mutex
);
750 list_add(&pmx
->node
, &pinmux_list
);
751 mutex_unlock(&pinmux_list_mutex
);
755 EXPORT_SYMBOL_GPL(pinmux_get
);
758 * pinmux_put() - release a previously claimed pinmux
759 * @pmx: a pinmux previously claimed by pinmux_get()
761 void pinmux_put(struct pinmux
*pmx
)
766 mutex_lock(&pmx
->mutex
);
768 pr_warn("releasing pinmux with active users!\n");
769 /* Free the groups and all acquired pins */
770 pinmux_free_groups(pmx
);
771 mutex_unlock(&pmx
->mutex
);
773 /* Remove from list */
774 mutex_lock(&pinmux_list_mutex
);
775 list_del(&pmx
->node
);
776 mutex_unlock(&pinmux_list_mutex
);
780 EXPORT_SYMBOL_GPL(pinmux_put
);
783 * pinmux_enable() - enable a certain pinmux setting
784 * @pmx: the pinmux to enable, previously claimed by pinmux_get()
786 int pinmux_enable(struct pinmux
*pmx
)
792 mutex_lock(&pmx
->mutex
);
793 if (pmx
->usecount
++ == 0) {
794 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
795 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
796 struct pinmux_group
*grp
;
798 list_for_each_entry(grp
, &pmx
->groups
, node
) {
799 ret
= ops
->enable(pctldev
, pmx
->func_selector
,
800 grp
->group_selector
);
803 * TODO: call disable() on all groups we called
804 * enable() on to this point?
811 mutex_unlock(&pmx
->mutex
);
814 EXPORT_SYMBOL_GPL(pinmux_enable
);
817 * pinmux_disable() - disable a certain pinmux setting
818 * @pmx: the pinmux to disable, previously claimed by pinmux_get()
820 void pinmux_disable(struct pinmux
*pmx
)
825 mutex_lock(&pmx
->mutex
);
826 if (--pmx
->usecount
== 0) {
827 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
828 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
829 struct pinmux_group
*grp
;
831 list_for_each_entry(grp
, &pmx
->groups
, node
) {
832 ops
->disable(pctldev
, pmx
->func_selector
,
833 grp
->group_selector
);
836 mutex_unlock(&pmx
->mutex
);
838 EXPORT_SYMBOL_GPL(pinmux_disable
);
840 int pinmux_check_ops(const struct pinmux_ops
*ops
)
842 /* Check that we implement required operations */
843 if (!ops
->list_functions
||
844 !ops
->get_function_name
||
845 !ops
->get_function_groups
||
853 /* Hog a single map entry and add to the hoglist */
854 static int pinmux_hog_map(struct pinctrl_dev
*pctldev
,
855 struct pinmux_map
const *map
)
857 struct pinmux_hog
*hog
;
861 if (map
->dev
|| map
->dev_name
) {
863 * TODO: the day we have device tree support, we can
864 * traverse the device tree and hog to specific device nodes
865 * without any problems, so then we can hog pinmuxes for
866 * all devices that just want a static pin mux at this point.
868 dev_err(&pctldev
->dev
, "map %s wants to hog a non-system "
869 "pinmux, this is not going to work\n", map
->name
);
873 hog
= kzalloc(sizeof(struct pinmux_hog
), GFP_KERNEL
);
877 pmx
= pinmux_get(NULL
, map
->name
);
880 dev_err(&pctldev
->dev
,
881 "could not get the %s pinmux mapping for hogging\n",
886 ret
= pinmux_enable(pmx
);
890 dev_err(&pctldev
->dev
,
891 "could not enable the %s pinmux mapping for hogging\n",
899 dev_info(&pctldev
->dev
, "hogged map %s, function %s\n", map
->name
,
901 mutex_lock(&pctldev
->pinmux_hogs_lock
);
902 list_add(&hog
->node
, &pctldev
->pinmux_hogs
);
903 mutex_unlock(&pctldev
->pinmux_hogs_lock
);
909 * pinmux_hog_maps() - hog specific map entries on controller device
910 * @pctldev: the pin control device to hog entries on
912 * When the pin controllers are registered, there may be some specific pinmux
913 * map entries that need to be hogged, i.e. get+enabled until the system shuts
916 int pinmux_hog_maps(struct pinctrl_dev
*pctldev
)
918 struct device
*dev
= &pctldev
->dev
;
919 const char *devname
= dev_name(dev
);
923 INIT_LIST_HEAD(&pctldev
->pinmux_hogs
);
924 mutex_init(&pctldev
->pinmux_hogs_lock
);
926 for (i
= 0; i
< pinmux_maps_num
; i
++) {
927 struct pinmux_map
const *map
= &pinmux_maps
[i
];
929 if (((map
->ctrl_dev
== dev
) ||
930 !strcmp(map
->ctrl_dev_name
, devname
)) &&
932 /* OK time to hog! */
933 ret
= pinmux_hog_map(pctldev
, map
);
942 * pinmux_hog_maps() - unhog specific map entries on controller device
943 * @pctldev: the pin control device to unhog entries on
945 void pinmux_unhog_maps(struct pinctrl_dev
*pctldev
)
947 struct list_head
*node
, *tmp
;
949 mutex_lock(&pctldev
->pinmux_hogs_lock
);
950 list_for_each_safe(node
, tmp
, &pctldev
->pinmux_hogs
) {
951 struct pinmux_hog
*hog
=
952 list_entry(node
, struct pinmux_hog
, node
);
953 pinmux_disable(hog
->pmx
);
954 pinmux_put(hog
->pmx
);
958 mutex_unlock(&pctldev
->pinmux_hogs_lock
);
961 #ifdef CONFIG_DEBUG_FS
963 /* Called from pincontrol core */
964 static int pinmux_functions_show(struct seq_file
*s
, void *what
)
966 struct pinctrl_dev
*pctldev
= s
->private;
967 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
968 unsigned func_selector
= 0;
970 while (pmxops
->list_functions(pctldev
, func_selector
) >= 0) {
971 const char *func
= pmxops
->get_function_name(pctldev
,
973 const char * const *groups
;
978 ret
= pmxops
->get_function_groups(pctldev
, func_selector
,
979 &groups
, &num_groups
);
981 seq_printf(s
, "function %s: COULD NOT GET GROUPS\n",
984 seq_printf(s
, "function: %s, groups = [ ", func
);
985 for (i
= 0; i
< num_groups
; i
++)
986 seq_printf(s
, "%s ", groups
[i
]);
996 static int pinmux_pins_show(struct seq_file
*s
, void *what
)
998 struct pinctrl_dev
*pctldev
= s
->private;
1001 seq_puts(s
, "Pinmux settings per pin\n");
1002 seq_puts(s
, "Format: pin (name): pinmuxfunction\n");
1004 /* The highest pin number need to be included in the loop, thus <= */
1005 for (pin
= 0; pin
<= pctldev
->desc
->maxpin
; pin
++) {
1007 struct pin_desc
*desc
;
1009 desc
= pin_desc_get(pctldev
, pin
);
1010 /* Pin space may be sparse */
1014 seq_printf(s
, "pin %d (%s): %s\n", pin
,
1015 desc
->name
? desc
->name
: "unnamed",
1016 desc
->mux_requested
? desc
->mux_function
: "UNCLAIMED");
1022 static int pinmux_hogs_show(struct seq_file
*s
, void *what
)
1024 struct pinctrl_dev
*pctldev
= s
->private;
1025 struct pinmux_hog
*hog
;
1027 seq_puts(s
, "Pinmux map hogs held by device\n");
1029 list_for_each_entry(hog
, &pctldev
->pinmux_hogs
, node
)
1030 seq_printf(s
, "%s\n", hog
->map
->name
);
1035 static int pinmux_show(struct seq_file
*s
, void *what
)
1039 seq_puts(s
, "Requested pinmuxes and their maps:\n");
1040 list_for_each_entry(pmx
, &pinmux_list
, node
) {
1041 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
1042 const struct pinmux_ops
*pmxops
;
1043 const struct pinctrl_ops
*pctlops
;
1044 struct pinmux_group
*grp
;
1047 seq_puts(s
, "NO PIN CONTROLLER DEVICE\n");
1051 pmxops
= pctldev
->desc
->pmxops
;
1052 pctlops
= pctldev
->desc
->pctlops
;
1054 seq_printf(s
, "device: %s function: %s (%u),",
1055 pinctrl_dev_get_name(pmx
->pctldev
),
1056 pmxops
->get_function_name(pctldev
, pmx
->func_selector
),
1057 pmx
->func_selector
);
1059 seq_printf(s
, " groups: [");
1060 list_for_each_entry(grp
, &pmx
->groups
, node
) {
1061 seq_printf(s
, " %s (%u)",
1062 pctlops
->get_group_name(pctldev
, grp
->group_selector
),
1063 grp
->group_selector
);
1065 seq_printf(s
, " ]");
1067 seq_printf(s
, " users: %u map-> %s\n",
1069 pmx
->dev
? dev_name(pmx
->dev
) : "(system)");
1075 static int pinmux_maps_show(struct seq_file
*s
, void *what
)
1079 seq_puts(s
, "Pinmux maps:\n");
1081 for (i
= 0; i
< pinmux_maps_num
; i
++) {
1082 struct pinmux_map
const *map
= &pinmux_maps
[i
];
1084 seq_printf(s
, "%s:\n", map
->name
);
1085 if (map
->dev
|| map
->dev_name
)
1086 seq_printf(s
, " device: %s\n",
1087 map
->dev
? dev_name(map
->dev
) :
1090 seq_printf(s
, " SYSTEM MUX\n");
1091 seq_printf(s
, " controlling device %s\n",
1092 map
->ctrl_dev
? dev_name(map
->ctrl_dev
) :
1093 map
->ctrl_dev_name
);
1094 seq_printf(s
, " function: %s\n", map
->function
);
1095 seq_printf(s
, " group: %s\n", map
->group
? map
->group
:
1101 static int pinmux_functions_open(struct inode
*inode
, struct file
*file
)
1103 return single_open(file
, pinmux_functions_show
, inode
->i_private
);
1106 static int pinmux_pins_open(struct inode
*inode
, struct file
*file
)
1108 return single_open(file
, pinmux_pins_show
, inode
->i_private
);
1111 static int pinmux_hogs_open(struct inode
*inode
, struct file
*file
)
1113 return single_open(file
, pinmux_hogs_show
, inode
->i_private
);
1116 static int pinmux_open(struct inode
*inode
, struct file
*file
)
1118 return single_open(file
, pinmux_show
, NULL
);
1121 static int pinmux_maps_open(struct inode
*inode
, struct file
*file
)
1123 return single_open(file
, pinmux_maps_show
, NULL
);
1126 static const struct file_operations pinmux_functions_ops
= {
1127 .open
= pinmux_functions_open
,
1129 .llseek
= seq_lseek
,
1130 .release
= single_release
,
1133 static const struct file_operations pinmux_pins_ops
= {
1134 .open
= pinmux_pins_open
,
1136 .llseek
= seq_lseek
,
1137 .release
= single_release
,
1140 static const struct file_operations pinmux_hogs_ops
= {
1141 .open
= pinmux_hogs_open
,
1143 .llseek
= seq_lseek
,
1144 .release
= single_release
,
1147 static const struct file_operations pinmux_ops
= {
1148 .open
= pinmux_open
,
1150 .llseek
= seq_lseek
,
1151 .release
= single_release
,
1154 static const struct file_operations pinmux_maps_ops
= {
1155 .open
= pinmux_maps_open
,
1157 .llseek
= seq_lseek
,
1158 .release
= single_release
,
1161 void pinmux_init_device_debugfs(struct dentry
*devroot
,
1162 struct pinctrl_dev
*pctldev
)
1164 debugfs_create_file("pinmux-functions", S_IFREG
| S_IRUGO
,
1165 devroot
, pctldev
, &pinmux_functions_ops
);
1166 debugfs_create_file("pinmux-pins", S_IFREG
| S_IRUGO
,
1167 devroot
, pctldev
, &pinmux_pins_ops
);
1168 debugfs_create_file("pinmux-hogs", S_IFREG
| S_IRUGO
,
1169 devroot
, pctldev
, &pinmux_hogs_ops
);
1172 void pinmux_init_debugfs(struct dentry
*subsys_root
)
1174 debugfs_create_file("pinmuxes", S_IFREG
| S_IRUGO
,
1175 subsys_root
, NULL
, &pinmux_ops
);
1176 debugfs_create_file("pinmux-maps", S_IFREG
| S_IRUGO
,
1177 subsys_root
, NULL
, &pinmux_maps_ops
);
1180 #endif /* CONFIG_DEBUG_FS */