2 * Core driver for the pin control subsystem
4 * Copyright (C) 2011-2012 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 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
12 * License terms: GNU General Public License (GPL) version 2
14 #define pr_fmt(fmt) "pinctrl core: " fmt
16 #include <linux/kernel.h>
17 #include <linux/kref.h>
18 #include <linux/export.h>
19 #include <linux/init.h>
20 #include <linux/device.h>
21 #include <linux/slab.h>
22 #include <linux/err.h>
23 #include <linux/list.h>
24 #include <linux/sysfs.h>
25 #include <linux/debugfs.h>
26 #include <linux/seq_file.h>
27 #include <linux/pinctrl/consumer.h>
28 #include <linux/pinctrl/pinctrl.h>
29 #include <linux/pinctrl/machine.h>
32 #include <asm-generic/gpio.h>
36 #include "devicetree.h"
41 static bool pinctrl_dummy_state;
43 /* Mutex taken to protect pinctrl_list */
44 static DEFINE_MUTEX(pinctrl_list_mutex);
46 /* Mutex taken to protect pinctrl_maps */
47 DEFINE_MUTEX(pinctrl_maps_mutex);
49 /* Mutex taken to protect pinctrldev_list */
50 static DEFINE_MUTEX(pinctrldev_list_mutex);
52 /* Global list of pin control devices (struct pinctrl_dev) */
53 static LIST_HEAD(pinctrldev_list);
55 /* List of pin controller handles (struct pinctrl) */
56 static LIST_HEAD(pinctrl_list);
58 /* List of pinctrl maps (struct pinctrl_maps) */
59 LIST_HEAD(pinctrl_maps);
63 * pinctrl_provide_dummies() - indicate if pinctrl provides dummy state support
65 * Usually this function is called by platforms without pinctrl driver support
66 * but run with some shared drivers using pinctrl APIs.
67 * After calling this function, the pinctrl core will return successfully
68 * with creating a dummy state for the driver to keep going smoothly.
70 void pinctrl_provide_dummies(void)
72 pinctrl_dummy_state = true;
75 const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
77 /* We're not allowed to register devices without name */
78 return pctldev->desc->name;
80 EXPORT_SYMBOL_GPL(pinctrl_dev_get_name);
82 const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev)
84 return dev_name(pctldev->dev);
86 EXPORT_SYMBOL_GPL(pinctrl_dev_get_devname);
88 void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev)
90 return pctldev->driver_data;
92 EXPORT_SYMBOL_GPL(pinctrl_dev_get_drvdata);
95 * get_pinctrl_dev_from_devname() - look up pin controller device
96 * @devname: the name of a device instance, as returned by dev_name()
98 * Looks up a pin control device matching a certain device name or pure device
99 * pointer, the pure device pointer will take precedence.
101 struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
103 struct pinctrl_dev *pctldev = NULL;
108 mutex_lock(&pinctrldev_list_mutex);
110 list_for_each_entry(pctldev, &pinctrldev_list, node) {
111 if (!strcmp(dev_name(pctldev->dev), devname)) {
112 /* Matched on device name */
113 mutex_unlock(&pinctrldev_list_mutex);
118 mutex_unlock(&pinctrldev_list_mutex);
123 struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np)
125 struct pinctrl_dev *pctldev;
127 mutex_lock(&pinctrldev_list_mutex);
129 list_for_each_entry(pctldev, &pinctrldev_list, node)
130 if (pctldev->dev->of_node == np) {
131 mutex_unlock(&pinctrldev_list_mutex);
135 mutex_unlock(&pinctrldev_list_mutex);
141 * pin_get_from_name() - look up a pin number from a name
142 * @pctldev: the pin control device to lookup the pin on
143 * @name: the name of the pin to look up
145 int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name)
149 /* The pin number can be retrived from the pin controller descriptor */
150 for (i = 0; i < pctldev->desc->npins; i++) {
151 struct pin_desc *desc;
153 pin = pctldev->desc->pins[i].number;
154 desc = pin_desc_get(pctldev, pin);
155 /* Pin space may be sparse */
158 if (desc->name && !strcmp(name, desc->name))
166 * pin_get_name_from_id() - look up a pin name from a pin id
167 * @pctldev: the pin control device to lookup the pin on
168 * @name: the name of the pin to look up
170 const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin)
172 const struct pin_desc *desc;
174 desc = pin_desc_get(pctldev, pin);
176 dev_err(pctldev->dev, "failed to get pin(%d) name\n",
185 * pin_is_valid() - check if pin exists on controller
186 * @pctldev: the pin control device to check the pin on
187 * @pin: pin to check, use the local pin controller index number
189 * This tells us whether a certain pin exist on a certain pin controller or
190 * not. Pin lists may be sparse, so some pins may not exist.
192 bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
194 struct pin_desc *pindesc;
199 mutex_lock(&pctldev->mutex);
200 pindesc = pin_desc_get(pctldev, pin);
201 mutex_unlock(&pctldev->mutex);
203 return pindesc != NULL;
205 EXPORT_SYMBOL_GPL(pin_is_valid);
207 /* Deletes a range of pin descriptors */
208 static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev,
209 const struct pinctrl_pin_desc *pins,
214 for (i = 0; i < num_pins; i++) {
215 struct pin_desc *pindesc;
217 pindesc = radix_tree_lookup(&pctldev->pin_desc_tree,
219 if (pindesc != NULL) {
220 radix_tree_delete(&pctldev->pin_desc_tree,
222 if (pindesc->dynamic_name)
223 kfree(pindesc->name);
229 static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
230 unsigned number, const char *name)
232 struct pin_desc *pindesc;
234 pindesc = pin_desc_get(pctldev, number);
235 if (pindesc != NULL) {
236 pr_err("pin %d already registered on %s\n", number,
237 pctldev->desc->name);
241 pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL);
242 if (pindesc == NULL) {
243 dev_err(pctldev->dev, "failed to alloc struct pin_desc\n");
248 pindesc->pctldev = pctldev;
250 /* Copy basic pin info */
252 pindesc->name = name;
254 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", number);
255 if (pindesc->name == NULL) {
259 pindesc->dynamic_name = true;
262 radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc);
263 pr_debug("registered pin %d (%s) on %s\n",
264 number, pindesc->name, pctldev->desc->name);
268 static int pinctrl_register_pins(struct pinctrl_dev *pctldev,
269 struct pinctrl_pin_desc const *pins,
275 for (i = 0; i < num_descs; i++) {
276 ret = pinctrl_register_one_pin(pctldev,
277 pins[i].number, pins[i].name);
286 * gpio_to_pin() - GPIO range GPIO number to pin number translation
287 * @range: GPIO range used for the translation
288 * @gpio: gpio pin to translate to a pin number
290 * Finds the pin number for a given GPIO using the specified GPIO range
291 * as a base for translation. The distinction between linear GPIO ranges
292 * and pin list based GPIO ranges is managed correctly by this function.
294 * This function assumes the gpio is part of the specified GPIO range, use
295 * only after making sure this is the case (e.g. by calling it on the
296 * result of successful pinctrl_get_device_gpio_range calls)!
298 static inline int gpio_to_pin(struct pinctrl_gpio_range *range,
301 unsigned int offset = gpio - range->base;
303 return range->pins[offset];
305 return range->pin_base + offset;
309 * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
310 * @pctldev: pin controller device to check
311 * @gpio: gpio pin to check taken from the global GPIO pin space
313 * Tries to match a GPIO pin number to the ranges handled by a certain pin
314 * controller, return the range or NULL
316 static struct pinctrl_gpio_range *
317 pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
319 struct pinctrl_gpio_range *range = NULL;
321 mutex_lock(&pctldev->mutex);
322 /* Loop over the ranges */
323 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
324 /* Check if we're in the valid range */
325 if (gpio >= range->base &&
326 gpio < range->base + range->npins) {
327 mutex_unlock(&pctldev->mutex);
331 mutex_unlock(&pctldev->mutex);
336 * pinctrl_ready_for_gpio_range() - check if other GPIO pins of
337 * the same GPIO chip are in range
338 * @gpio: gpio pin to check taken from the global GPIO pin space
340 * This function is complement of pinctrl_match_gpio_range(). If the return
341 * value of pinctrl_match_gpio_range() is NULL, this function could be used
342 * to check whether pinctrl device is ready or not. Maybe some GPIO pins
343 * of the same GPIO chip don't have back-end pinctrl interface.
344 * If the return value is true, it means that pinctrl device is ready & the
345 * certain GPIO pin doesn't have back-end pinctrl device. If the return value
346 * is false, it means that pinctrl device may not be ready.
348 #ifdef CONFIG_GPIOLIB
349 static bool pinctrl_ready_for_gpio_range(unsigned gpio)
351 struct pinctrl_dev *pctldev;
352 struct pinctrl_gpio_range *range = NULL;
353 struct gpio_chip *chip = gpio_to_chip(gpio);
355 mutex_lock(&pinctrldev_list_mutex);
357 /* Loop over the pin controllers */
358 list_for_each_entry(pctldev, &pinctrldev_list, node) {
359 /* Loop over the ranges */
360 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
361 /* Check if any gpio range overlapped with gpio chip */
362 if (range->base + range->npins - 1 < chip->base ||
363 range->base > chip->base + chip->ngpio - 1)
365 mutex_unlock(&pinctrldev_list_mutex);
370 mutex_unlock(&pinctrldev_list_mutex);
375 static bool pinctrl_ready_for_gpio_range(unsigned gpio) { return true; }
379 * pinctrl_get_device_gpio_range() - find device for GPIO range
380 * @gpio: the pin to locate the pin controller for
381 * @outdev: the pin control device if found
382 * @outrange: the GPIO range if found
384 * Find the pin controller handling a certain GPIO pin from the pinspace of
385 * the GPIO subsystem, return the device and the matching GPIO range. Returns
386 * -EPROBE_DEFER if the GPIO range could not be found in any device since it
387 * may still have not been registered.
389 static int pinctrl_get_device_gpio_range(unsigned gpio,
390 struct pinctrl_dev **outdev,
391 struct pinctrl_gpio_range **outrange)
393 struct pinctrl_dev *pctldev = NULL;
395 /* Loop over the pin controllers */
396 list_for_each_entry(pctldev, &pinctrldev_list, node) {
397 struct pinctrl_gpio_range *range;
399 range = pinctrl_match_gpio_range(pctldev, gpio);
407 return -EPROBE_DEFER;
411 * pinctrl_add_gpio_range() - register a GPIO range for a controller
412 * @pctldev: pin controller device to add the range to
413 * @range: the GPIO range to add
415 * This adds a range of GPIOs to be handled by a certain pin controller. Call
416 * this to register handled ranges after registering your pin controller.
418 void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
419 struct pinctrl_gpio_range *range)
421 mutex_lock(&pctldev->mutex);
422 list_add_tail(&range->node, &pctldev->gpio_ranges);
423 mutex_unlock(&pctldev->mutex);
425 EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
427 void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
428 struct pinctrl_gpio_range *ranges,
433 for (i = 0; i < nranges; i++)
434 pinctrl_add_gpio_range(pctldev, &ranges[i]);
436 EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges);
438 struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
439 struct pinctrl_gpio_range *range)
441 struct pinctrl_dev *pctldev;
443 pctldev = get_pinctrl_dev_from_devname(devname);
446 * If we can't find this device, let's assume that is because
447 * it has not probed yet, so the driver trying to register this
448 * range need to defer probing.
451 return ERR_PTR(-EPROBE_DEFER);
453 pinctrl_add_gpio_range(pctldev, range);
457 EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range);
460 * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin
461 * @pctldev: the pin controller device to look in
462 * @pin: a controller-local number to find the range for
464 struct pinctrl_gpio_range *
465 pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
468 struct pinctrl_gpio_range *range;
470 mutex_lock(&pctldev->mutex);
471 /* Loop over the ranges */
472 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
473 /* Check if we're in the valid range */
476 for (a = 0; a < range->npins; a++) {
477 if (range->pins[a] == pin)
480 } else if (pin >= range->pin_base &&
481 pin < range->pin_base + range->npins)
486 mutex_unlock(&pctldev->mutex);
489 EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin);
492 * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
493 * @pctldev: pin controller device to remove the range from
494 * @range: the GPIO range to remove
496 void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
497 struct pinctrl_gpio_range *range)
499 mutex_lock(&pctldev->mutex);
500 list_del(&range->node);
501 mutex_unlock(&pctldev->mutex);
503 EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
506 * pinctrl_get_group_selector() - returns the group selector for a group
507 * @pctldev: the pin controller handling the group
508 * @pin_group: the pin group to look up
510 int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
511 const char *pin_group)
513 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
514 unsigned ngroups = pctlops->get_groups_count(pctldev);
515 unsigned group_selector = 0;
517 while (group_selector < ngroups) {
518 const char *gname = pctlops->get_group_name(pctldev,
520 if (!strcmp(gname, pin_group)) {
521 dev_dbg(pctldev->dev,
522 "found group selector %u for %s\n",
525 return group_selector;
531 dev_err(pctldev->dev, "does not have pin group %s\n",
538 * pinctrl_request_gpio() - request a single pin to be used in as GPIO
539 * @gpio: the GPIO pin number from the GPIO subsystem number space
541 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
542 * as part of their gpio_request() semantics, platforms and individual drivers
543 * shall *NOT* request GPIO pins to be muxed in.
545 int pinctrl_request_gpio(unsigned gpio)
547 struct pinctrl_dev *pctldev;
548 struct pinctrl_gpio_range *range;
552 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
554 if (pinctrl_ready_for_gpio_range(gpio))
559 /* Convert to the pin controllers number space */
560 pin = gpio_to_pin(range, gpio);
562 ret = pinmux_request_gpio(pctldev, range, pin, gpio);
566 EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
569 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
570 * @gpio: the GPIO pin number from the GPIO subsystem number space
572 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
573 * as part of their gpio_free() semantics, platforms and individual drivers
574 * shall *NOT* request GPIO pins to be muxed out.
576 void pinctrl_free_gpio(unsigned gpio)
578 struct pinctrl_dev *pctldev;
579 struct pinctrl_gpio_range *range;
583 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
587 mutex_lock(&pctldev->mutex);
589 /* Convert to the pin controllers number space */
590 pin = gpio_to_pin(range, gpio);
592 pinmux_free_gpio(pctldev, pin, range);
594 mutex_unlock(&pctldev->mutex);
596 EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
598 static int pinctrl_gpio_direction(unsigned gpio, bool input)
600 struct pinctrl_dev *pctldev;
601 struct pinctrl_gpio_range *range;
605 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
610 mutex_lock(&pctldev->mutex);
612 /* Convert to the pin controllers number space */
613 pin = gpio_to_pin(range, gpio);
614 ret = pinmux_gpio_direction(pctldev, range, pin, input);
616 mutex_unlock(&pctldev->mutex);
622 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
623 * @gpio: the GPIO pin number from the GPIO subsystem number space
625 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
626 * as part of their gpio_direction_input() semantics, platforms and individual
627 * drivers shall *NOT* touch pin control GPIO calls.
629 int pinctrl_gpio_direction_input(unsigned gpio)
631 return pinctrl_gpio_direction(gpio, true);
633 EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
636 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
637 * @gpio: the GPIO pin number from the GPIO subsystem number space
639 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
640 * as part of their gpio_direction_output() semantics, platforms and individual
641 * drivers shall *NOT* touch pin control GPIO calls.
643 int pinctrl_gpio_direction_output(unsigned gpio)
645 return pinctrl_gpio_direction(gpio, false);
647 EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
649 static struct pinctrl_state *find_state(struct pinctrl *p,
652 struct pinctrl_state *state;
654 list_for_each_entry(state, &p->states, node)
655 if (!strcmp(state->name, name))
661 static struct pinctrl_state *create_state(struct pinctrl *p,
664 struct pinctrl_state *state;
666 state = kzalloc(sizeof(*state), GFP_KERNEL);
669 "failed to alloc struct pinctrl_state\n");
670 return ERR_PTR(-ENOMEM);
674 INIT_LIST_HEAD(&state->settings);
676 list_add_tail(&state->node, &p->states);
681 static int add_setting(struct pinctrl *p, struct pinctrl_map const *map)
683 struct pinctrl_state *state;
684 struct pinctrl_setting *setting;
687 state = find_state(p, map->name);
689 state = create_state(p, map->name);
691 return PTR_ERR(state);
693 if (map->type == PIN_MAP_TYPE_DUMMY_STATE)
696 setting = kzalloc(sizeof(*setting), GFP_KERNEL);
697 if (setting == NULL) {
699 "failed to alloc struct pinctrl_setting\n");
703 setting->type = map->type;
705 setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
706 if (setting->pctldev == NULL) {
708 /* Do not defer probing of hogs (circular loop) */
709 if (!strcmp(map->ctrl_dev_name, map->dev_name))
712 * OK let us guess that the driver is not there yet, and
713 * let's defer obtaining this pinctrl handle to later...
715 dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe",
717 return -EPROBE_DEFER;
720 setting->dev_name = map->dev_name;
723 case PIN_MAP_TYPE_MUX_GROUP:
724 ret = pinmux_map_to_setting(map, setting);
726 case PIN_MAP_TYPE_CONFIGS_PIN:
727 case PIN_MAP_TYPE_CONFIGS_GROUP:
728 ret = pinconf_map_to_setting(map, setting);
739 list_add_tail(&setting->node, &state->settings);
744 static struct pinctrl *find_pinctrl(struct device *dev)
748 mutex_lock(&pinctrl_list_mutex);
749 list_for_each_entry(p, &pinctrl_list, node)
751 mutex_unlock(&pinctrl_list_mutex);
755 mutex_unlock(&pinctrl_list_mutex);
759 static void pinctrl_free(struct pinctrl *p, bool inlist);
761 static struct pinctrl *create_pinctrl(struct device *dev)
765 struct pinctrl_maps *maps_node;
767 struct pinctrl_map const *map;
771 * create the state cookie holder struct pinctrl for each
772 * mapping, this is what consumers will get when requesting
773 * a pin control handle with pinctrl_get()
775 p = kzalloc(sizeof(*p), GFP_KERNEL);
777 dev_err(dev, "failed to alloc struct pinctrl\n");
778 return ERR_PTR(-ENOMEM);
781 INIT_LIST_HEAD(&p->states);
782 INIT_LIST_HEAD(&p->dt_maps);
784 ret = pinctrl_dt_to_map(p);
790 devname = dev_name(dev);
792 mutex_lock(&pinctrl_maps_mutex);
793 /* Iterate over the pin control maps to locate the right ones */
794 for_each_maps(maps_node, i, map) {
795 /* Map must be for this device */
796 if (strcmp(map->dev_name, devname))
799 ret = add_setting(p, map);
801 * At this point the adding of a setting may:
803 * - Defer, if the pinctrl device is not yet available
804 * - Fail, if the pinctrl device is not yet available,
805 * AND the setting is a hog. We cannot defer that, since
806 * the hog will kick in immediately after the device
809 * If the error returned was not -EPROBE_DEFER then we
810 * accumulate the errors to see if we end up with
811 * an -EPROBE_DEFER later, as that is the worst case.
813 if (ret == -EPROBE_DEFER) {
814 pinctrl_free(p, false);
815 mutex_unlock(&pinctrl_maps_mutex);
819 mutex_unlock(&pinctrl_maps_mutex);
822 /* If some other error than deferral occured, return here */
823 pinctrl_free(p, false);
827 kref_init(&p->users);
829 /* Add the pinctrl handle to the global list */
830 list_add_tail(&p->node, &pinctrl_list);
836 * pinctrl_get() - retrieves the pinctrl handle for a device
837 * @dev: the device to obtain the handle for
839 struct pinctrl *pinctrl_get(struct device *dev)
844 return ERR_PTR(-EINVAL);
847 * See if somebody else (such as the device core) has already
848 * obtained a handle to the pinctrl for this device. In that case,
849 * return another pointer to it.
851 p = find_pinctrl(dev);
853 dev_dbg(dev, "obtain a copy of previously claimed pinctrl\n");
858 return create_pinctrl(dev);
860 EXPORT_SYMBOL_GPL(pinctrl_get);
862 static void pinctrl_free_setting(bool disable_setting,
863 struct pinctrl_setting *setting)
865 switch (setting->type) {
866 case PIN_MAP_TYPE_MUX_GROUP:
868 pinmux_disable_setting(setting);
869 pinmux_free_setting(setting);
871 case PIN_MAP_TYPE_CONFIGS_PIN:
872 case PIN_MAP_TYPE_CONFIGS_GROUP:
873 pinconf_free_setting(setting);
880 static void pinctrl_free(struct pinctrl *p, bool inlist)
882 struct pinctrl_state *state, *n1;
883 struct pinctrl_setting *setting, *n2;
885 mutex_lock(&pinctrl_list_mutex);
886 list_for_each_entry_safe(state, n1, &p->states, node) {
887 list_for_each_entry_safe(setting, n2, &state->settings, node) {
888 pinctrl_free_setting(state == p->state, setting);
889 list_del(&setting->node);
892 list_del(&state->node);
896 pinctrl_dt_free_maps(p);
901 mutex_unlock(&pinctrl_list_mutex);
905 * pinctrl_release() - release the pinctrl handle
906 * @kref: the kref in the pinctrl being released
908 static void pinctrl_release(struct kref *kref)
910 struct pinctrl *p = container_of(kref, struct pinctrl, users);
912 pinctrl_free(p, true);
916 * pinctrl_put() - decrease use count on a previously claimed pinctrl handle
917 * @p: the pinctrl handle to release
919 void pinctrl_put(struct pinctrl *p)
921 kref_put(&p->users, pinctrl_release);
923 EXPORT_SYMBOL_GPL(pinctrl_put);
926 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
927 * @p: the pinctrl handle to retrieve the state from
928 * @name: the state name to retrieve
930 struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,
933 struct pinctrl_state *state;
935 state = find_state(p, name);
937 if (pinctrl_dummy_state) {
938 /* create dummy state */
939 dev_dbg(p->dev, "using pinctrl dummy state (%s)\n",
941 state = create_state(p, name);
943 state = ERR_PTR(-ENODEV);
948 EXPORT_SYMBOL_GPL(pinctrl_lookup_state);
951 * pinctrl_select_state() - select/activate/program a pinctrl state to HW
952 * @p: the pinctrl handle for the device that requests configuration
953 * @state: the state handle to select/activate/program
955 int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
957 struct pinctrl_setting *setting, *setting2;
958 struct pinctrl_state *old_state = p->state;
961 if (p->state == state)
966 * The set of groups with a mux configuration in the old state
967 * may not be identical to the set of groups with a mux setting
968 * in the new state. While this might be unusual, it's entirely
969 * possible for the "user"-supplied mapping table to be written
970 * that way. For each group that was configured in the old state
971 * but not in the new state, this code puts that group into a
972 * safe/disabled state.
974 list_for_each_entry(setting, &p->state->settings, node) {
976 if (setting->type != PIN_MAP_TYPE_MUX_GROUP)
978 list_for_each_entry(setting2, &state->settings, node) {
979 if (setting2->type != PIN_MAP_TYPE_MUX_GROUP)
981 if (setting2->data.mux.group ==
982 setting->data.mux.group) {
988 pinmux_disable_setting(setting);
994 /* Apply all the settings for the new state */
995 list_for_each_entry(setting, &state->settings, node) {
996 switch (setting->type) {
997 case PIN_MAP_TYPE_MUX_GROUP:
998 ret = pinmux_enable_setting(setting);
1000 case PIN_MAP_TYPE_CONFIGS_PIN:
1001 case PIN_MAP_TYPE_CONFIGS_GROUP:
1002 ret = pinconf_apply_setting(setting);
1010 goto unapply_new_state;
1019 dev_err(p->dev, "Error applying setting, reverse things back\n");
1021 list_for_each_entry(setting2, &state->settings, node) {
1022 if (&setting2->node == &setting->node)
1025 * All we can do here is pinmux_disable_setting.
1026 * That means that some pins are muxed differently now
1027 * than they were before applying the setting (We can't
1028 * "unmux a pin"!), but it's not a big deal since the pins
1029 * are free to be muxed by another apply_setting.
1031 if (setting2->type == PIN_MAP_TYPE_MUX_GROUP)
1032 pinmux_disable_setting(setting2);
1035 /* There's no infinite recursive loop here because p->state is NULL */
1037 pinctrl_select_state(p, old_state);
1041 EXPORT_SYMBOL_GPL(pinctrl_select_state);
1043 static void devm_pinctrl_release(struct device *dev, void *res)
1045 pinctrl_put(*(struct pinctrl **)res);
1049 * struct devm_pinctrl_get() - Resource managed pinctrl_get()
1050 * @dev: the device to obtain the handle for
1052 * If there is a need to explicitly destroy the returned struct pinctrl,
1053 * devm_pinctrl_put() should be used, rather than plain pinctrl_put().
1055 struct pinctrl *devm_pinctrl_get(struct device *dev)
1057 struct pinctrl **ptr, *p;
1059 ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL);
1061 return ERR_PTR(-ENOMEM);
1063 p = pinctrl_get(dev);
1066 devres_add(dev, ptr);
1073 EXPORT_SYMBOL_GPL(devm_pinctrl_get);
1075 static int devm_pinctrl_match(struct device *dev, void *res, void *data)
1077 struct pinctrl **p = res;
1083 * devm_pinctrl_put() - Resource managed pinctrl_put()
1084 * @p: the pinctrl handle to release
1086 * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally
1087 * this function will not need to be called and the resource management
1088 * code will ensure that the resource is freed.
1090 void devm_pinctrl_put(struct pinctrl *p)
1092 WARN_ON(devres_release(p->dev, devm_pinctrl_release,
1093 devm_pinctrl_match, p));
1095 EXPORT_SYMBOL_GPL(devm_pinctrl_put);
1097 int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
1098 bool dup, bool locked)
1101 struct pinctrl_maps *maps_node;
1103 pr_debug("add %d pinmux maps\n", num_maps);
1105 /* First sanity check the new mapping */
1106 for (i = 0; i < num_maps; i++) {
1107 if (!maps[i].dev_name) {
1108 pr_err("failed to register map %s (%d): no device given\n",
1113 if (!maps[i].name) {
1114 pr_err("failed to register map %d: no map name given\n",
1119 if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE &&
1120 !maps[i].ctrl_dev_name) {
1121 pr_err("failed to register map %s (%d): no pin control device given\n",
1126 switch (maps[i].type) {
1127 case PIN_MAP_TYPE_DUMMY_STATE:
1129 case PIN_MAP_TYPE_MUX_GROUP:
1130 ret = pinmux_validate_map(&maps[i], i);
1134 case PIN_MAP_TYPE_CONFIGS_PIN:
1135 case PIN_MAP_TYPE_CONFIGS_GROUP:
1136 ret = pinconf_validate_map(&maps[i], i);
1141 pr_err("failed to register map %s (%d): invalid type given\n",
1147 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
1149 pr_err("failed to alloc struct pinctrl_maps\n");
1153 maps_node->num_maps = num_maps;
1155 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,
1157 if (!maps_node->maps) {
1158 pr_err("failed to duplicate mapping table\n");
1163 maps_node->maps = maps;
1167 mutex_lock(&pinctrl_maps_mutex);
1168 list_add_tail(&maps_node->node, &pinctrl_maps);
1170 mutex_unlock(&pinctrl_maps_mutex);
1176 * pinctrl_register_mappings() - register a set of pin controller mappings
1177 * @maps: the pincontrol mappings table to register. This should probably be
1178 * marked with __initdata so it can be discarded after boot. This
1179 * function will perform a shallow copy for the mapping entries.
1180 * @num_maps: the number of maps in the mapping table
1182 int pinctrl_register_mappings(struct pinctrl_map const *maps,
1185 return pinctrl_register_map(maps, num_maps, true, false);
1188 void pinctrl_unregister_map(struct pinctrl_map const *map)
1190 struct pinctrl_maps *maps_node;
1192 mutex_lock(&pinctrl_maps_mutex);
1193 list_for_each_entry(maps_node, &pinctrl_maps, node) {
1194 if (maps_node->maps == map) {
1195 list_del(&maps_node->node);
1196 mutex_unlock(&pinctrl_maps_mutex);
1200 mutex_unlock(&pinctrl_maps_mutex);
1204 * pinctrl_force_sleep() - turn a given controller device into sleep state
1205 * @pctldev: pin controller device
1207 int pinctrl_force_sleep(struct pinctrl_dev *pctldev)
1209 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep))
1210 return pinctrl_select_state(pctldev->p, pctldev->hog_sleep);
1213 EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
1216 * pinctrl_force_default() - turn a given controller device into default state
1217 * @pctldev: pin controller device
1219 int pinctrl_force_default(struct pinctrl_dev *pctldev)
1221 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default))
1222 return pinctrl_select_state(pctldev->p, pctldev->hog_default);
1225 EXPORT_SYMBOL_GPL(pinctrl_force_default);
1230 * pinctrl_pm_select_state() - select pinctrl state for PM
1231 * @dev: device to select default state for
1232 * @state: state to set
1234 static int pinctrl_pm_select_state(struct device *dev,
1235 struct pinctrl_state *state)
1237 struct dev_pin_info *pins = dev->pins;
1241 return 0; /* No such state */
1242 ret = pinctrl_select_state(pins->p, state);
1244 dev_err(dev, "failed to activate pinctrl state %s\n",
1250 * pinctrl_pm_select_default_state() - select default pinctrl state for PM
1251 * @dev: device to select default state for
1253 int pinctrl_pm_select_default_state(struct device *dev)
1258 return pinctrl_pm_select_state(dev, dev->pins->default_state);
1260 EXPORT_SYMBOL_GPL(pinctrl_pm_select_default_state);
1263 * pinctrl_pm_select_sleep_state() - select sleep pinctrl state for PM
1264 * @dev: device to select sleep state for
1266 int pinctrl_pm_select_sleep_state(struct device *dev)
1271 return pinctrl_pm_select_state(dev, dev->pins->sleep_state);
1273 EXPORT_SYMBOL_GPL(pinctrl_pm_select_sleep_state);
1276 * pinctrl_pm_select_idle_state() - select idle pinctrl state for PM
1277 * @dev: device to select idle state for
1279 int pinctrl_pm_select_idle_state(struct device *dev)
1284 return pinctrl_pm_select_state(dev, dev->pins->idle_state);
1286 EXPORT_SYMBOL_GPL(pinctrl_pm_select_idle_state);
1289 #ifdef CONFIG_DEBUG_FS
1291 static int pinctrl_pins_show(struct seq_file *s, void *what)
1293 struct pinctrl_dev *pctldev = s->private;
1294 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1297 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
1299 mutex_lock(&pctldev->mutex);
1301 /* The pin number can be retrived from the pin controller descriptor */
1302 for (i = 0; i < pctldev->desc->npins; i++) {
1303 struct pin_desc *desc;
1305 pin = pctldev->desc->pins[i].number;
1306 desc = pin_desc_get(pctldev, pin);
1307 /* Pin space may be sparse */
1311 seq_printf(s, "pin %d (%s) ", pin,
1312 desc->name ? desc->name : "unnamed");
1314 /* Driver-specific info per pin */
1315 if (ops->pin_dbg_show)
1316 ops->pin_dbg_show(pctldev, s, pin);
1321 mutex_unlock(&pctldev->mutex);
1326 static int pinctrl_groups_show(struct seq_file *s, void *what)
1328 struct pinctrl_dev *pctldev = s->private;
1329 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1330 unsigned ngroups, selector = 0;
1332 mutex_lock(&pctldev->mutex);
1334 ngroups = ops->get_groups_count(pctldev);
1336 seq_puts(s, "registered pin groups:\n");
1337 while (selector < ngroups) {
1338 const unsigned *pins;
1340 const char *gname = ops->get_group_name(pctldev, selector);
1345 ret = ops->get_group_pins(pctldev, selector,
1348 seq_printf(s, "%s [ERROR GETTING PINS]\n",
1351 seq_printf(s, "group: %s\n", gname);
1352 for (i = 0; i < num_pins; i++) {
1353 pname = pin_get_name(pctldev, pins[i]);
1354 if (WARN_ON(!pname)) {
1355 mutex_unlock(&pctldev->mutex);
1358 seq_printf(s, "pin %d (%s)\n", pins[i], pname);
1365 mutex_unlock(&pctldev->mutex);
1370 static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
1372 struct pinctrl_dev *pctldev = s->private;
1373 struct pinctrl_gpio_range *range = NULL;
1375 seq_puts(s, "GPIO ranges handled:\n");
1377 mutex_lock(&pctldev->mutex);
1379 /* Loop over the ranges */
1380 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
1383 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS {",
1384 range->id, range->name,
1385 range->base, (range->base + range->npins - 1));
1386 for (a = 0; a < range->npins - 1; a++)
1387 seq_printf(s, "%u, ", range->pins[a]);
1388 seq_printf(s, "%u}\n", range->pins[a]);
1391 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
1392 range->id, range->name,
1393 range->base, (range->base + range->npins - 1),
1395 (range->pin_base + range->npins - 1));
1398 mutex_unlock(&pctldev->mutex);
1403 static int pinctrl_devices_show(struct seq_file *s, void *what)
1405 struct pinctrl_dev *pctldev;
1407 seq_puts(s, "name [pinmux] [pinconf]\n");
1409 mutex_lock(&pinctrldev_list_mutex);
1411 list_for_each_entry(pctldev, &pinctrldev_list, node) {
1412 seq_printf(s, "%s ", pctldev->desc->name);
1413 if (pctldev->desc->pmxops)
1414 seq_puts(s, "yes ");
1417 if (pctldev->desc->confops)
1424 mutex_unlock(&pinctrldev_list_mutex);
1429 static inline const char *map_type(enum pinctrl_map_type type)
1431 static const char * const names[] = {
1439 if (type >= ARRAY_SIZE(names))
1445 static int pinctrl_maps_show(struct seq_file *s, void *what)
1447 struct pinctrl_maps *maps_node;
1449 struct pinctrl_map const *map;
1451 seq_puts(s, "Pinctrl maps:\n");
1453 mutex_lock(&pinctrl_maps_mutex);
1454 for_each_maps(maps_node, i, map) {
1455 seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n",
1456 map->dev_name, map->name, map_type(map->type),
1459 if (map->type != PIN_MAP_TYPE_DUMMY_STATE)
1460 seq_printf(s, "controlling device %s\n",
1461 map->ctrl_dev_name);
1463 switch (map->type) {
1464 case PIN_MAP_TYPE_MUX_GROUP:
1465 pinmux_show_map(s, map);
1467 case PIN_MAP_TYPE_CONFIGS_PIN:
1468 case PIN_MAP_TYPE_CONFIGS_GROUP:
1469 pinconf_show_map(s, map);
1475 seq_printf(s, "\n");
1477 mutex_unlock(&pinctrl_maps_mutex);
1482 static int pinctrl_show(struct seq_file *s, void *what)
1485 struct pinctrl_state *state;
1486 struct pinctrl_setting *setting;
1488 seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
1490 mutex_lock(&pinctrl_list_mutex);
1492 list_for_each_entry(p, &pinctrl_list, node) {
1493 seq_printf(s, "device: %s current state: %s\n",
1495 p->state ? p->state->name : "none");
1497 list_for_each_entry(state, &p->states, node) {
1498 seq_printf(s, " state: %s\n", state->name);
1500 list_for_each_entry(setting, &state->settings, node) {
1501 struct pinctrl_dev *pctldev = setting->pctldev;
1503 seq_printf(s, " type: %s controller %s ",
1504 map_type(setting->type),
1505 pinctrl_dev_get_name(pctldev));
1507 switch (setting->type) {
1508 case PIN_MAP_TYPE_MUX_GROUP:
1509 pinmux_show_setting(s, setting);
1511 case PIN_MAP_TYPE_CONFIGS_PIN:
1512 case PIN_MAP_TYPE_CONFIGS_GROUP:
1513 pinconf_show_setting(s, setting);
1522 mutex_unlock(&pinctrl_list_mutex);
1527 static int pinctrl_pins_open(struct inode *inode, struct file *file)
1529 return single_open(file, pinctrl_pins_show, inode->i_private);
1532 static int pinctrl_groups_open(struct inode *inode, struct file *file)
1534 return single_open(file, pinctrl_groups_show, inode->i_private);
1537 static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
1539 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
1542 static int pinctrl_devices_open(struct inode *inode, struct file *file)
1544 return single_open(file, pinctrl_devices_show, NULL);
1547 static int pinctrl_maps_open(struct inode *inode, struct file *file)
1549 return single_open(file, pinctrl_maps_show, NULL);
1552 static int pinctrl_open(struct inode *inode, struct file *file)
1554 return single_open(file, pinctrl_show, NULL);
1557 static const struct file_operations pinctrl_pins_ops = {
1558 .open = pinctrl_pins_open,
1560 .llseek = seq_lseek,
1561 .release = single_release,
1564 static const struct file_operations pinctrl_groups_ops = {
1565 .open = pinctrl_groups_open,
1567 .llseek = seq_lseek,
1568 .release = single_release,
1571 static const struct file_operations pinctrl_gpioranges_ops = {
1572 .open = pinctrl_gpioranges_open,
1574 .llseek = seq_lseek,
1575 .release = single_release,
1578 static const struct file_operations pinctrl_devices_ops = {
1579 .open = pinctrl_devices_open,
1581 .llseek = seq_lseek,
1582 .release = single_release,
1585 static const struct file_operations pinctrl_maps_ops = {
1586 .open = pinctrl_maps_open,
1588 .llseek = seq_lseek,
1589 .release = single_release,
1592 static const struct file_operations pinctrl_ops = {
1593 .open = pinctrl_open,
1595 .llseek = seq_lseek,
1596 .release = single_release,
1599 static struct dentry *debugfs_root;
1601 static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1603 struct dentry *device_root;
1605 device_root = debugfs_create_dir(dev_name(pctldev->dev),
1607 pctldev->device_root = device_root;
1609 if (IS_ERR(device_root) || !device_root) {
1610 pr_warn("failed to create debugfs directory for %s\n",
1611 dev_name(pctldev->dev));
1614 debugfs_create_file("pins", S_IFREG | S_IRUGO,
1615 device_root, pctldev, &pinctrl_pins_ops);
1616 debugfs_create_file("pingroups", S_IFREG | S_IRUGO,
1617 device_root, pctldev, &pinctrl_groups_ops);
1618 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
1619 device_root, pctldev, &pinctrl_gpioranges_ops);
1620 pinmux_init_device_debugfs(device_root, pctldev);
1621 pinconf_init_device_debugfs(device_root, pctldev);
1624 static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1626 debugfs_remove_recursive(pctldev->device_root);
1629 static void pinctrl_init_debugfs(void)
1631 debugfs_root = debugfs_create_dir("pinctrl", NULL);
1632 if (IS_ERR(debugfs_root) || !debugfs_root) {
1633 pr_warn("failed to create debugfs directory\n");
1634 debugfs_root = NULL;
1638 debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
1639 debugfs_root, NULL, &pinctrl_devices_ops);
1640 debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
1641 debugfs_root, NULL, &pinctrl_maps_ops);
1642 debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
1643 debugfs_root, NULL, &pinctrl_ops);
1646 #else /* CONFIG_DEBUG_FS */
1648 static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1652 static void pinctrl_init_debugfs(void)
1656 static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1662 static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1664 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1667 !ops->get_groups_count ||
1668 !ops->get_group_name ||
1669 !ops->get_group_pins)
1672 if (ops->dt_node_to_map && !ops->dt_free_map)
1679 * pinctrl_register() - register a pin controller device
1680 * @pctldesc: descriptor for this pin controller
1681 * @dev: parent device for this pin controller
1682 * @driver_data: private pin controller data for this pin controller
1684 struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1685 struct device *dev, void *driver_data)
1687 struct pinctrl_dev *pctldev;
1692 if (!pctldesc->name)
1695 pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
1696 if (pctldev == NULL) {
1697 dev_err(dev, "failed to alloc struct pinctrl_dev\n");
1701 /* Initialize pin control device struct */
1702 pctldev->owner = pctldesc->owner;
1703 pctldev->desc = pctldesc;
1704 pctldev->driver_data = driver_data;
1705 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
1706 INIT_LIST_HEAD(&pctldev->gpio_ranges);
1708 mutex_init(&pctldev->mutex);
1710 /* check core ops for sanity */
1711 if (pinctrl_check_ops(pctldev)) {
1712 dev_err(dev, "pinctrl ops lacks necessary functions\n");
1716 /* If we're implementing pinmuxing, check the ops for sanity */
1717 if (pctldesc->pmxops) {
1718 if (pinmux_check_ops(pctldev))
1722 /* If we're implementing pinconfig, check the ops for sanity */
1723 if (pctldesc->confops) {
1724 if (pinconf_check_ops(pctldev))
1728 /* Register all the pins */
1729 dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);
1730 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
1732 dev_err(dev, "error during pin registration\n");
1733 pinctrl_free_pindescs(pctldev, pctldesc->pins,
1738 mutex_lock(&pinctrldev_list_mutex);
1739 list_add_tail(&pctldev->node, &pinctrldev_list);
1740 mutex_unlock(&pinctrldev_list_mutex);
1742 pctldev->p = pinctrl_get(pctldev->dev);
1744 if (!IS_ERR(pctldev->p)) {
1745 pctldev->hog_default =
1746 pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT);
1747 if (IS_ERR(pctldev->hog_default)) {
1748 dev_dbg(dev, "failed to lookup the default state\n");
1750 if (pinctrl_select_state(pctldev->p,
1751 pctldev->hog_default))
1753 "failed to select default state\n");
1756 pctldev->hog_sleep =
1757 pinctrl_lookup_state(pctldev->p,
1758 PINCTRL_STATE_SLEEP);
1759 if (IS_ERR(pctldev->hog_sleep))
1760 dev_dbg(dev, "failed to lookup the sleep state\n");
1763 pinctrl_init_device_debugfs(pctldev);
1768 mutex_destroy(&pctldev->mutex);
1772 EXPORT_SYMBOL_GPL(pinctrl_register);
1775 * pinctrl_unregister() - unregister pinmux
1776 * @pctldev: pin controller to unregister
1778 * Called by pinmux drivers to unregister a pinmux.
1780 void pinctrl_unregister(struct pinctrl_dev *pctldev)
1782 struct pinctrl_gpio_range *range, *n;
1783 if (pctldev == NULL)
1786 mutex_lock(&pinctrldev_list_mutex);
1787 mutex_lock(&pctldev->mutex);
1789 pinctrl_remove_device_debugfs(pctldev);
1791 if (!IS_ERR(pctldev->p))
1792 pinctrl_put(pctldev->p);
1794 /* TODO: check that no pinmuxes are still active? */
1795 list_del(&pctldev->node);
1796 /* Destroy descriptor tree */
1797 pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
1798 pctldev->desc->npins);
1799 /* remove gpio ranges map */
1800 list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node)
1801 list_del(&range->node);
1803 mutex_unlock(&pctldev->mutex);
1804 mutex_destroy(&pctldev->mutex);
1806 mutex_unlock(&pinctrldev_list_mutex);
1808 EXPORT_SYMBOL_GPL(pinctrl_unregister);
1810 static int __init pinctrl_init(void)
1812 pr_info("initialized pinctrl subsystem\n");
1813 pinctrl_init_debugfs();
1817 /* init early since many drivers really need to initialized pinmux early */
1818 core_initcall(pinctrl_init);