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 /* Global pinmux maps, we allow one set only */
36 static struct pinmux_map
const *pinmux_maps
;
37 static unsigned pinmux_maps_num
;
40 * struct pinmux_group - group list item for pinmux groups
41 * @node: pinmux group list node
42 * @group_selector: the group selector for this group
45 struct list_head node
;
46 unsigned group_selector
;
50 * struct pinmux - per-device pinmux state holder
51 * @node: global list node
52 * @dev: the device using this pinmux
53 * @usecount: the number of active users of this mux setting, used to keep
54 * track of nested use cases
55 * @pins: an array of discrete physical pins used in this mapping, taken
56 * from the global pin enumeration space (copied from pinmux map)
57 * @num_pins: the number of pins in this mapping array, i.e. the number of
58 * elements in .pins so we can iterate over that array (copied from
60 * @pctldev: pin control device handling this pinmux
61 * @func_selector: the function selector for the pinmux device handling
63 * @groups: the group selectors for the pinmux device and
64 * selector combination handling this pinmux, this is a list that
65 * will be traversed on all pinmux operations such as
66 * get/put/enable/disable
67 * @mutex: a lock for the pinmux state holder
70 struct list_head node
;
73 struct pinctrl_dev
*pctldev
;
74 unsigned func_selector
;
75 struct list_head groups
;
80 * struct pinmux_hog - a list item to stash mux hogs
81 * @node: pinmux hog list node
82 * @map: map entry responsible for this hogging
83 * @pmx: the pinmux hogged by this item
86 struct list_head node
;
87 struct pinmux_map
const *map
;
92 * pin_request() - request a single pin to be muxed in, typically for GPIO
93 * @pin: the pin number in the global pin space
94 * @function: a functional name to give to this pin, passed to the driver
95 * so it knows what function to mux in, e.g. the string "gpioNN"
96 * means that you want to mux in the pin for use as GPIO number NN
97 * @gpio_range: the range matching the GPIO pin if this is a request for a
100 static int pin_request(struct pinctrl_dev
*pctldev
,
101 int pin
, const char *function
,
102 struct pinctrl_gpio_range
*gpio_range
)
104 struct pin_desc
*desc
;
105 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
106 int status
= -EINVAL
;
108 dev_dbg(&pctldev
->dev
, "request pin %d for %s\n", pin
, function
);
110 desc
= pin_desc_get(pctldev
, pin
);
112 dev_err(&pctldev
->dev
,
113 "pin is not registered so it cannot be requested\n");
118 dev_err(&pctldev
->dev
, "no function name given\n");
122 spin_lock(&desc
->lock
);
123 if (desc
->mux_function
) {
124 spin_unlock(&desc
->lock
);
125 dev_err(&pctldev
->dev
,
126 "pin already requested\n");
129 desc
->mux_function
= function
;
130 spin_unlock(&desc
->lock
);
132 /* Let each pin increase references to this module */
133 if (!try_module_get(pctldev
->owner
)) {
134 dev_err(&pctldev
->dev
,
135 "could not increase module refcount for pin %d\n",
142 * If there is no kind of request function for the pin we just assume
143 * we got it by default and proceed.
145 if (gpio_range
&& ops
->gpio_request_enable
)
146 /* This requests and enables a single GPIO pin */
147 status
= ops
->gpio_request_enable(pctldev
, gpio_range
, pin
);
148 else if (ops
->request
)
149 status
= ops
->request(pctldev
, pin
);
154 dev_err(&pctldev
->dev
, "->request on device %s failed "
156 pctldev
->desc
->name
, pin
);
159 spin_lock(&desc
->lock
);
160 desc
->mux_function
= NULL
;
161 spin_unlock(&desc
->lock
);
165 dev_err(&pctldev
->dev
, "pin-%d (%s) status %d\n",
166 pin
, function
? : "?", status
);
172 * pin_free() - release a single muxed in pin so something else can be muxed
173 * @pctldev: pin controller device handling this pin
174 * @pin: the pin to free
175 * @gpio_range: the range matching the GPIO pin if this is a request for a
178 * This function returns a pointer to the function name in use. This is used
179 * for callers that dynamically allocate a function name so it can be freed
180 * once the pin is free. This is done for GPIO request functions.
182 static const char *pin_free(struct pinctrl_dev
*pctldev
, int pin
,
183 struct pinctrl_gpio_range
*gpio_range
)
185 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
186 struct pin_desc
*desc
;
189 desc
= pin_desc_get(pctldev
, pin
);
191 dev_err(&pctldev
->dev
,
192 "pin is not registered so it cannot be freed\n");
197 * If there is no kind of request function for the pin we just assume
198 * we got it by default and proceed.
200 if (gpio_range
&& ops
->gpio_disable_free
)
201 ops
->gpio_disable_free(pctldev
, gpio_range
, pin
);
203 ops
->free(pctldev
, pin
);
205 spin_lock(&desc
->lock
);
206 func
= desc
->mux_function
;
207 desc
->mux_function
= NULL
;
208 spin_unlock(&desc
->lock
);
209 module_put(pctldev
->owner
);
215 * pinmux_request_gpio() - request a single pin to be muxed in as GPIO
216 * @gpio: the GPIO pin number from the GPIO subsystem number space
218 int pinmux_request_gpio(unsigned gpio
)
221 const char *function
;
222 struct pinctrl_dev
*pctldev
;
223 struct pinctrl_gpio_range
*range
;
227 ret
= pinctrl_get_device_gpio_range(gpio
, &pctldev
, &range
);
231 /* Convert to the pin controllers number space */
232 pin
= gpio
- range
->base
+ range
->pin_base
;
234 /* Conjure some name stating what chip and pin this is taken by */
235 snprintf(gpiostr
, 15, "%s:%d", range
->name
, gpio
);
237 function
= kstrdup(gpiostr
, GFP_KERNEL
);
241 ret
= pin_request(pctldev
, pin
, function
, range
);
247 EXPORT_SYMBOL_GPL(pinmux_request_gpio
);
250 * pinmux_free_gpio() - free a single pin, currently used as GPIO
251 * @gpio: the GPIO pin number from the GPIO subsystem number space
253 void pinmux_free_gpio(unsigned gpio
)
255 struct pinctrl_dev
*pctldev
;
256 struct pinctrl_gpio_range
*range
;
261 ret
= pinctrl_get_device_gpio_range(gpio
, &pctldev
, &range
);
265 /* Convert to the pin controllers number space */
266 pin
= gpio
- range
->base
+ range
->pin_base
;
268 func
= pin_free(pctldev
, pin
, range
);
271 EXPORT_SYMBOL_GPL(pinmux_free_gpio
);
274 * pinmux_register_mappings() - register a set of pinmux mappings
275 * @maps: the pinmux mappings table to register
276 * @num_maps: the number of maps in the mapping table
278 * Only call this once during initialization of your machine, the function is
279 * tagged as __init and won't be callable after init has completed. The map
280 * passed into this function will be owned by the pinmux core and cannot be
283 int __init
pinmux_register_mappings(struct pinmux_map
const *maps
,
288 if (pinmux_maps
!= NULL
) {
289 pr_err("pinmux mappings already registered, you can only "
290 "register one set of maps\n");
294 pr_debug("add %d pinmux maps\n", num_maps
);
295 for (i
= 0; i
< num_maps
; i
++) {
296 /* Sanity check the mapping */
298 pr_err("failed to register map %d: "
299 "no map name given\n", i
);
302 if (!maps
[i
].ctrl_dev
&& !maps
[i
].ctrl_dev_name
) {
303 pr_err("failed to register map %s (%d): "
304 "no pin control device given\n",
308 if (!maps
[i
].function
) {
309 pr_err("failed to register map %s (%d): "
310 "no function ID given\n", maps
[i
].name
, i
);
314 if (!maps
[i
].dev
&& !maps
[i
].dev_name
)
315 pr_debug("add system map %s function %s with no device\n",
319 pr_debug("register map %s, function %s\n",
325 pinmux_maps_num
= num_maps
;
331 * acquire_pins() - acquire all the pins for a certain funcion on a pinmux
332 * @pctldev: the device to take the pins on
333 * @func_selector: the function selector to acquire the pins for
334 * @group_selector: the group selector containing the pins to acquire
336 static int acquire_pins(struct pinctrl_dev
*pctldev
,
337 unsigned func_selector
,
338 unsigned group_selector
)
340 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
341 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
342 const char *func
= pmxops
->get_function_name(pctldev
,
344 const unsigned *pins
;
349 ret
= pctlops
->get_group_pins(pctldev
, group_selector
,
354 dev_dbg(&pctldev
->dev
, "requesting the %u pins from group %u\n",
355 num_pins
, group_selector
);
357 /* Try to allocate all pins in this group, one by one */
358 for (i
= 0; i
< num_pins
; i
++) {
359 ret
= pin_request(pctldev
, pins
[i
], func
, NULL
);
361 dev_err(&pctldev
->dev
,
362 "could not get pin %d for function %s "
363 "on device %s - conflicting mux mappings?\n",
364 pins
[i
], func
? : "(undefined)",
365 pinctrl_dev_get_name(pctldev
));
366 /* On error release all taken pins */
367 i
--; /* this pin just failed */
369 pin_free(pctldev
, pins
[i
], NULL
);
377 * release_pins() - release pins taken by earlier acquirement
378 * @pctldev: the device to free the pinx on
379 * @group_selector: the group selector containing the pins to free
381 static void release_pins(struct pinctrl_dev
*pctldev
,
382 unsigned group_selector
)
384 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
385 const unsigned *pins
;
390 ret
= pctlops
->get_group_pins(pctldev
, group_selector
,
393 dev_err(&pctldev
->dev
, "could not get pins to release for "
394 "group selector %d\n",
398 for (i
= 0; i
< num_pins
; i
++)
399 pin_free(pctldev
, pins
[i
], NULL
);
403 * pinmux_check_pin_group() - check function and pin group combo
404 * @pctldev: device to check the pin group vs function for
405 * @func_selector: the function selector to check the pin group for, we have
406 * already looked this up in the calling function
407 * @pin_group: the pin group to match to the function
409 * This function will check that the pinmux driver can supply the
410 * selected pin group for a certain function, returns the group selector if
411 * the group and function selector will work fine together, else returns
414 static int pinmux_check_pin_group(struct pinctrl_dev
*pctldev
,
415 unsigned func_selector
,
416 const char *pin_group
)
418 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
419 const struct pinctrl_ops
*pctlops
= pctldev
->desc
->pctlops
;
423 * If the driver does not support different pin groups for the
424 * functions, we only support group 0, and assume this exists.
426 if (!pctlops
|| !pctlops
->list_groups
)
430 * Passing NULL (no specific group) will select the first and
431 * hopefully only group of pins available for this function.
434 char const * const *groups
;
437 ret
= pmxops
->get_function_groups(pctldev
, func_selector
,
438 &groups
, &num_groups
);
443 ret
= pinctrl_get_group_selector(pctldev
, groups
[0]);
445 dev_err(&pctldev
->dev
,
446 "function %s wants group %s but the pin "
447 "controller does not seem to have that group\n",
448 pmxops
->get_function_name(pctldev
, func_selector
),
454 dev_dbg(&pctldev
->dev
,
455 "function %s support more than one group, "
456 "default-selecting first group %s (%d)\n",
457 pmxops
->get_function_name(pctldev
, func_selector
),
464 dev_dbg(&pctldev
->dev
,
465 "check if we have pin group %s on controller %s\n",
466 pin_group
, pinctrl_dev_get_name(pctldev
));
468 ret
= pinctrl_get_group_selector(pctldev
, pin_group
);
470 dev_dbg(&pctldev
->dev
,
471 "%s does not support pin group %s with function %s\n",
472 pinctrl_dev_get_name(pctldev
),
474 pmxops
->get_function_name(pctldev
, func_selector
));
480 * pinmux_search_function() - check pin control driver for a certain function
481 * @pctldev: device to check for function and position
482 * @map: function map containing the function and position to look for
483 * @func_selector: returns the applicable function selector if found
484 * @group_selector: returns the applicable group selector if found
486 * This will search the pinmux driver for an applicable
487 * function with a specific pin group, returns 0 if these can be mapped
490 static int pinmux_search_function(struct pinctrl_dev
*pctldev
,
491 struct pinmux_map
const *map
,
492 unsigned *func_selector
,
493 unsigned *group_selector
)
495 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
496 unsigned selector
= 0;
498 /* See if this pctldev has this function */
499 while (ops
->list_functions(pctldev
, selector
) >= 0) {
500 const char *fname
= ops
->get_function_name(pctldev
,
504 if (!strcmp(map
->function
, fname
)) {
505 /* Found the function, check pin group */
506 ret
= pinmux_check_pin_group(pctldev
, selector
,
511 /* This function and group selector can be used */
512 *func_selector
= selector
;
513 *group_selector
= ret
;
520 pr_err("%s does not support function %s\n",
521 pinctrl_dev_get_name(pctldev
), map
->function
);
526 * pinmux_enable_muxmap() - enable a map entry for a certain pinmux
528 static int pinmux_enable_muxmap(struct pinctrl_dev
*pctldev
,
532 struct pinmux_map
const *map
)
534 unsigned func_selector
;
535 unsigned group_selector
;
536 struct pinmux_group
*grp
;
540 * Note that we're not locking the pinmux mutex here, because
541 * this is only called at pinmux initialization time when it
542 * has not been added to any list and thus is not reachable
546 if (pmx
->pctldev
&& pmx
->pctldev
!= pctldev
) {
547 dev_err(&pctldev
->dev
,
548 "different pin control devices given for device %s, "
555 pmx
->pctldev
= pctldev
;
557 /* Now go into the driver and try to match a function and group */
558 ret
= pinmux_search_function(pctldev
, map
, &func_selector
,
564 * If the function selector is already set, it needs to be identical,
565 * we support several groups with one function but not several
566 * functions with one or several groups in the same pinmux.
568 if (pmx
->func_selector
!= UINT_MAX
&&
569 pmx
->func_selector
!= func_selector
) {
570 dev_err(&pctldev
->dev
,
571 "dual function defines in the map for device %s\n",
575 pmx
->func_selector
= func_selector
;
577 /* Now add this group selector, we may have many of them */
578 grp
= kmalloc(sizeof(struct pinmux_group
), GFP_KERNEL
);
581 grp
->group_selector
= group_selector
;
582 ret
= acquire_pins(pctldev
, func_selector
, group_selector
);
587 list_add(&grp
->node
, &pmx
->groups
);
592 static void pinmux_free_groups(struct pinmux
*pmx
)
594 struct list_head
*node
, *tmp
;
596 list_for_each_safe(node
, tmp
, &pmx
->groups
) {
597 struct pinmux_group
*grp
=
598 list_entry(node
, struct pinmux_group
, node
);
599 /* Release all pins taken by this group */
600 release_pins(pmx
->pctldev
, grp
->group_selector
);
607 * pinmux_get() - retrieves the pinmux for a certain device
608 * @dev: the device to get the pinmux for
609 * @name: an optional specific mux mapping name or NULL, the name is only
610 * needed if you want to have more than one mapping per device, or if you
611 * need an anonymous pinmux (not tied to any specific device)
613 struct pinmux
*pinmux_get(struct device
*dev
, const char *name
)
616 struct pinmux_map
const *map
= NULL
;
617 struct pinctrl_dev
*pctldev
= NULL
;
618 const char *devname
= NULL
;
621 unsigned num_maps
= 0;
625 /* We must have dev or ID or both */
627 return ERR_PTR(-EINVAL
);
630 devname
= dev_name(dev
);
632 pr_debug("get mux %s for device %s\n", name
,
633 devname
? devname
: "(none)");
636 * create the state cookie holder struct pinmux for each
637 * mapping, this is what consumers will get when requesting
638 * a pinmux handle with pinmux_get()
640 pmx
= kzalloc(sizeof(struct pinmux
), GFP_KERNEL
);
642 return ERR_PTR(-ENOMEM
);
643 mutex_init(&pmx
->mutex
);
644 pmx
->func_selector
= UINT_MAX
;
645 INIT_LIST_HEAD(&pmx
->groups
);
647 /* Iterate over the pinmux maps to locate the right ones */
648 for (i
= 0; i
< pinmux_maps_num
; i
++) {
649 map
= &pinmux_maps
[i
];
653 * First, try to find the pctldev given in the map
655 pctldev
= get_pinctrl_dev_from_dev(map
->ctrl_dev
,
658 const char *devname
= NULL
;
661 devname
= dev_name(map
->ctrl_dev
);
662 else if (map
->ctrl_dev_name
)
663 devname
= map
->ctrl_dev_name
;
665 pr_warning("could not find a pinctrl device for pinmux "
666 "function %s, fishy, they shall all have one\n",
668 pr_warning("given pinctrl device name: %s",
669 devname
? devname
: "UNDEFINED");
671 /* Continue to check the other mappings anyway... */
675 pr_debug("in map, found pctldev %s to handle function %s",
676 dev_name(&pctldev
->dev
), map
->function
);
680 * If we're looking for a specific named map, this must match,
681 * else we loop and look for the next.
684 if (map
->name
== NULL
)
686 if (strcmp(map
->name
, name
))
691 * This is for the case where no device name is given, we
692 * already know that the function name matches from above
695 if (!map
->dev_name
&& (name
!= NULL
))
698 /* If the mapping has a device set up it must match */
700 (!devname
|| !strcmp(map
->dev_name
, devname
)))
704 /* If this map is applicable, then apply it */
706 ret
= pinmux_enable_muxmap(pctldev
, pmx
, dev
,
709 pinmux_free_groups(pmx
);
718 /* We should have atleast one map, right */
720 pr_err("could not find any mux maps for device %s, ID %s\n",
721 devname
? devname
: "(anonymous)",
722 name
? name
: "(undefined)");
724 return ERR_PTR(-EINVAL
);
727 pr_debug("found %u mux maps for device %s, UD %s\n",
729 devname
? devname
: "(anonymous)",
730 name
? name
: "(undefined)");
732 /* Add the pinmux to the global list */
733 mutex_lock(&pinmux_list_mutex
);
734 list_add(&pmx
->node
, &pinmux_list
);
735 mutex_unlock(&pinmux_list_mutex
);
739 EXPORT_SYMBOL_GPL(pinmux_get
);
742 * pinmux_put() - release a previously claimed pinmux
743 * @pmx: a pinmux previously claimed by pinmux_get()
745 void pinmux_put(struct pinmux
*pmx
)
750 mutex_lock(&pmx
->mutex
);
752 pr_warn("releasing pinmux with active users!\n");
753 /* Free the groups and all acquired pins */
754 pinmux_free_groups(pmx
);
755 mutex_unlock(&pmx
->mutex
);
757 /* Remove from list */
758 mutex_lock(&pinmux_list_mutex
);
759 list_del(&pmx
->node
);
760 mutex_unlock(&pinmux_list_mutex
);
764 EXPORT_SYMBOL_GPL(pinmux_put
);
767 * pinmux_enable() - enable a certain pinmux setting
768 * @pmx: the pinmux to enable, previously claimed by pinmux_get()
770 int pinmux_enable(struct pinmux
*pmx
)
776 mutex_lock(&pmx
->mutex
);
777 if (pmx
->usecount
++ == 0) {
778 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
779 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
780 struct pinmux_group
*grp
;
782 list_for_each_entry(grp
, &pmx
->groups
, node
) {
783 ret
= ops
->enable(pctldev
, pmx
->func_selector
,
784 grp
->group_selector
);
787 * TODO: call disable() on all groups we called
788 * enable() on to this point?
795 mutex_unlock(&pmx
->mutex
);
798 EXPORT_SYMBOL_GPL(pinmux_enable
);
801 * pinmux_disable() - disable a certain pinmux setting
802 * @pmx: the pinmux to disable, previously claimed by pinmux_get()
804 void pinmux_disable(struct pinmux
*pmx
)
809 mutex_lock(&pmx
->mutex
);
810 if (--pmx
->usecount
== 0) {
811 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
812 const struct pinmux_ops
*ops
= pctldev
->desc
->pmxops
;
813 struct pinmux_group
*grp
;
815 list_for_each_entry(grp
, &pmx
->groups
, node
) {
816 ops
->disable(pctldev
, pmx
->func_selector
,
817 grp
->group_selector
);
820 mutex_unlock(&pmx
->mutex
);
822 EXPORT_SYMBOL_GPL(pinmux_disable
);
824 int pinmux_check_ops(const struct pinmux_ops
*ops
)
826 /* Check that we implement required operations */
827 if (!ops
->list_functions
||
828 !ops
->get_function_name
||
829 !ops
->get_function_groups
||
837 /* Hog a single map entry and add to the hoglist */
838 static int pinmux_hog_map(struct pinctrl_dev
*pctldev
,
839 struct pinmux_map
const *map
)
841 struct pinmux_hog
*hog
;
845 if (map
->dev
|| map
->dev_name
) {
847 * TODO: the day we have device tree support, we can
848 * traverse the device tree and hog to specific device nodes
849 * without any problems, so then we can hog pinmuxes for
850 * all devices that just want a static pin mux at this point.
852 dev_err(&pctldev
->dev
, "map %s wants to hog a non-system "
853 "pinmux, this is not going to work\n", map
->name
);
857 hog
= kzalloc(sizeof(struct pinmux_hog
), GFP_KERNEL
);
861 pmx
= pinmux_get(NULL
, map
->name
);
864 dev_err(&pctldev
->dev
,
865 "could not get the %s pinmux mapping for hogging\n",
870 ret
= pinmux_enable(pmx
);
874 dev_err(&pctldev
->dev
,
875 "could not enable the %s pinmux mapping for hogging\n",
883 dev_info(&pctldev
->dev
, "hogged map %s, function %s\n", map
->name
,
885 mutex_lock(&pctldev
->pinmux_hogs_lock
);
886 list_add(&hog
->node
, &pctldev
->pinmux_hogs
);
887 mutex_unlock(&pctldev
->pinmux_hogs_lock
);
893 * pinmux_hog_maps() - hog specific map entries on controller device
894 * @pctldev: the pin control device to hog entries on
896 * When the pin controllers are registered, there may be some specific pinmux
897 * map entries that need to be hogged, i.e. get+enabled until the system shuts
900 int pinmux_hog_maps(struct pinctrl_dev
*pctldev
)
902 struct device
*dev
= &pctldev
->dev
;
903 const char *devname
= dev_name(dev
);
907 INIT_LIST_HEAD(&pctldev
->pinmux_hogs
);
908 mutex_init(&pctldev
->pinmux_hogs_lock
);
910 for (i
= 0; i
< pinmux_maps_num
; i
++) {
911 struct pinmux_map
const *map
= &pinmux_maps
[i
];
913 if (((map
->ctrl_dev
== dev
) ||
914 !strcmp(map
->ctrl_dev_name
, devname
)) &&
916 /* OK time to hog! */
917 ret
= pinmux_hog_map(pctldev
, map
);
926 * pinmux_unhog_maps() - unhog specific map entries on controller device
927 * @pctldev: the pin control device to unhog entries on
929 void pinmux_unhog_maps(struct pinctrl_dev
*pctldev
)
931 struct list_head
*node
, *tmp
;
933 mutex_lock(&pctldev
->pinmux_hogs_lock
);
934 list_for_each_safe(node
, tmp
, &pctldev
->pinmux_hogs
) {
935 struct pinmux_hog
*hog
=
936 list_entry(node
, struct pinmux_hog
, node
);
937 pinmux_disable(hog
->pmx
);
938 pinmux_put(hog
->pmx
);
942 mutex_unlock(&pctldev
->pinmux_hogs_lock
);
945 #ifdef CONFIG_DEBUG_FS
947 /* Called from pincontrol core */
948 static int pinmux_functions_show(struct seq_file
*s
, void *what
)
950 struct pinctrl_dev
*pctldev
= s
->private;
951 const struct pinmux_ops
*pmxops
= pctldev
->desc
->pmxops
;
952 unsigned func_selector
= 0;
954 while (pmxops
->list_functions(pctldev
, func_selector
) >= 0) {
955 const char *func
= pmxops
->get_function_name(pctldev
,
957 const char * const *groups
;
962 ret
= pmxops
->get_function_groups(pctldev
, func_selector
,
963 &groups
, &num_groups
);
965 seq_printf(s
, "function %s: COULD NOT GET GROUPS\n",
968 seq_printf(s
, "function: %s, groups = [ ", func
);
969 for (i
= 0; i
< num_groups
; i
++)
970 seq_printf(s
, "%s ", groups
[i
]);
980 static int pinmux_pins_show(struct seq_file
*s
, void *what
)
982 struct pinctrl_dev
*pctldev
= s
->private;
985 seq_puts(s
, "Pinmux settings per pin\n");
986 seq_puts(s
, "Format: pin (name): pinmuxfunction\n");
988 /* The highest pin number need to be included in the loop, thus <= */
989 for (pin
= 0; pin
<= pctldev
->desc
->maxpin
; pin
++) {
991 struct pin_desc
*desc
;
993 desc
= pin_desc_get(pctldev
, pin
);
994 /* Pin space may be sparse */
998 seq_printf(s
, "pin %d (%s): %s\n", pin
,
999 desc
->name
? desc
->name
: "unnamed",
1000 desc
->mux_function
? desc
->mux_function
1007 static int pinmux_hogs_show(struct seq_file
*s
, void *what
)
1009 struct pinctrl_dev
*pctldev
= s
->private;
1010 struct pinmux_hog
*hog
;
1012 seq_puts(s
, "Pinmux map hogs held by device\n");
1014 list_for_each_entry(hog
, &pctldev
->pinmux_hogs
, node
)
1015 seq_printf(s
, "%s\n", hog
->map
->name
);
1020 static int pinmux_show(struct seq_file
*s
, void *what
)
1024 seq_puts(s
, "Requested pinmuxes and their maps:\n");
1025 list_for_each_entry(pmx
, &pinmux_list
, node
) {
1026 struct pinctrl_dev
*pctldev
= pmx
->pctldev
;
1027 const struct pinmux_ops
*pmxops
;
1028 const struct pinctrl_ops
*pctlops
;
1029 struct pinmux_group
*grp
;
1032 seq_puts(s
, "NO PIN CONTROLLER DEVICE\n");
1036 pmxops
= pctldev
->desc
->pmxops
;
1037 pctlops
= pctldev
->desc
->pctlops
;
1039 seq_printf(s
, "device: %s function: %s (%u),",
1040 pinctrl_dev_get_name(pmx
->pctldev
),
1041 pmxops
->get_function_name(pctldev
, pmx
->func_selector
),
1042 pmx
->func_selector
);
1044 seq_printf(s
, " groups: [");
1045 list_for_each_entry(grp
, &pmx
->groups
, node
) {
1046 seq_printf(s
, " %s (%u)",
1047 pctlops
->get_group_name(pctldev
, grp
->group_selector
),
1048 grp
->group_selector
);
1050 seq_printf(s
, " ]");
1052 seq_printf(s
, " users: %u map-> %s\n",
1054 pmx
->dev
? dev_name(pmx
->dev
) : "(system)");
1060 static int pinmux_maps_show(struct seq_file
*s
, void *what
)
1064 seq_puts(s
, "Pinmux maps:\n");
1066 for (i
= 0; i
< pinmux_maps_num
; i
++) {
1067 struct pinmux_map
const *map
= &pinmux_maps
[i
];
1069 seq_printf(s
, "%s:\n", map
->name
);
1070 if (map
->dev
|| map
->dev_name
)
1071 seq_printf(s
, " device: %s\n",
1072 map
->dev
? dev_name(map
->dev
) :
1075 seq_printf(s
, " SYSTEM MUX\n");
1076 seq_printf(s
, " controlling device %s\n",
1077 map
->ctrl_dev
? dev_name(map
->ctrl_dev
) :
1078 map
->ctrl_dev_name
);
1079 seq_printf(s
, " function: %s\n", map
->function
);
1080 seq_printf(s
, " group: %s\n", map
->group
? map
->group
:
1086 static int pinmux_functions_open(struct inode
*inode
, struct file
*file
)
1088 return single_open(file
, pinmux_functions_show
, inode
->i_private
);
1091 static int pinmux_pins_open(struct inode
*inode
, struct file
*file
)
1093 return single_open(file
, pinmux_pins_show
, inode
->i_private
);
1096 static int pinmux_hogs_open(struct inode
*inode
, struct file
*file
)
1098 return single_open(file
, pinmux_hogs_show
, inode
->i_private
);
1101 static int pinmux_open(struct inode
*inode
, struct file
*file
)
1103 return single_open(file
, pinmux_show
, NULL
);
1106 static int pinmux_maps_open(struct inode
*inode
, struct file
*file
)
1108 return single_open(file
, pinmux_maps_show
, NULL
);
1111 static const struct file_operations pinmux_functions_ops
= {
1112 .open
= pinmux_functions_open
,
1114 .llseek
= seq_lseek
,
1115 .release
= single_release
,
1118 static const struct file_operations pinmux_pins_ops
= {
1119 .open
= pinmux_pins_open
,
1121 .llseek
= seq_lseek
,
1122 .release
= single_release
,
1125 static const struct file_operations pinmux_hogs_ops
= {
1126 .open
= pinmux_hogs_open
,
1128 .llseek
= seq_lseek
,
1129 .release
= single_release
,
1132 static const struct file_operations pinmux_ops
= {
1133 .open
= pinmux_open
,
1135 .llseek
= seq_lseek
,
1136 .release
= single_release
,
1139 static const struct file_operations pinmux_maps_ops
= {
1140 .open
= pinmux_maps_open
,
1142 .llseek
= seq_lseek
,
1143 .release
= single_release
,
1146 void pinmux_init_device_debugfs(struct dentry
*devroot
,
1147 struct pinctrl_dev
*pctldev
)
1149 debugfs_create_file("pinmux-functions", S_IFREG
| S_IRUGO
,
1150 devroot
, pctldev
, &pinmux_functions_ops
);
1151 debugfs_create_file("pinmux-pins", S_IFREG
| S_IRUGO
,
1152 devroot
, pctldev
, &pinmux_pins_ops
);
1153 debugfs_create_file("pinmux-hogs", S_IFREG
| S_IRUGO
,
1154 devroot
, pctldev
, &pinmux_hogs_ops
);
1157 void pinmux_init_debugfs(struct dentry
*subsys_root
)
1159 debugfs_create_file("pinmuxes", S_IFREG
| S_IRUGO
,
1160 subsys_root
, NULL
, &pinmux_ops
);
1161 debugfs_create_file("pinmux-maps", S_IFREG
| S_IRUGO
,
1162 subsys_root
, NULL
, &pinmux_maps_ops
);
1165 #endif /* CONFIG_DEBUG_FS */