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 mutex_lock(&pinctrldev_list_mutex);
397 /* Loop over the pin controllers */
398 list_for_each_entry(pctldev, &pinctrldev_list, node) {
399 struct pinctrl_gpio_range *range;
401 range = pinctrl_match_gpio_range(pctldev, gpio);
405 mutex_unlock(&pinctrldev_list_mutex);
410 mutex_unlock(&pinctrldev_list_mutex);
412 return -EPROBE_DEFER;
416 * pinctrl_add_gpio_range() - register a GPIO range for a controller
417 * @pctldev: pin controller device to add the range to
418 * @range: the GPIO range to add
420 * This adds a range of GPIOs to be handled by a certain pin controller. Call
421 * this to register handled ranges after registering your pin controller.
423 void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
424 struct pinctrl_gpio_range *range)
426 mutex_lock(&pctldev->mutex);
427 list_add_tail(&range->node, &pctldev->gpio_ranges);
428 mutex_unlock(&pctldev->mutex);
430 EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
432 void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
433 struct pinctrl_gpio_range *ranges,
438 for (i = 0; i < nranges; i++)
439 pinctrl_add_gpio_range(pctldev, &ranges[i]);
441 EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges);
443 struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
444 struct pinctrl_gpio_range *range)
446 struct pinctrl_dev *pctldev;
448 pctldev = get_pinctrl_dev_from_devname(devname);
451 * If we can't find this device, let's assume that is because
452 * it has not probed yet, so the driver trying to register this
453 * range need to defer probing.
456 return ERR_PTR(-EPROBE_DEFER);
458 pinctrl_add_gpio_range(pctldev, range);
462 EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range);
465 * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin
466 * @pctldev: the pin controller device to look in
467 * @pin: a controller-local number to find the range for
469 struct pinctrl_gpio_range *
470 pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
473 struct pinctrl_gpio_range *range;
475 mutex_lock(&pctldev->mutex);
476 /* Loop over the ranges */
477 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
478 /* Check if we're in the valid range */
481 for (a = 0; a < range->npins; a++) {
482 if (range->pins[a] == pin)
485 } else if (pin >= range->pin_base &&
486 pin < range->pin_base + range->npins)
491 mutex_unlock(&pctldev->mutex);
494 EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin);
497 * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
498 * @pctldev: pin controller device to remove the range from
499 * @range: the GPIO range to remove
501 void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
502 struct pinctrl_gpio_range *range)
504 mutex_lock(&pctldev->mutex);
505 list_del(&range->node);
506 mutex_unlock(&pctldev->mutex);
508 EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
511 * pinctrl_get_group_selector() - returns the group selector for a group
512 * @pctldev: the pin controller handling the group
513 * @pin_group: the pin group to look up
515 int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
516 const char *pin_group)
518 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
519 unsigned ngroups = pctlops->get_groups_count(pctldev);
520 unsigned group_selector = 0;
522 while (group_selector < ngroups) {
523 const char *gname = pctlops->get_group_name(pctldev,
525 if (!strcmp(gname, pin_group)) {
526 dev_dbg(pctldev->dev,
527 "found group selector %u for %s\n",
530 return group_selector;
536 dev_err(pctldev->dev, "does not have pin group %s\n",
543 * pinctrl_request_gpio() - request a single pin to be used in as GPIO
544 * @gpio: the GPIO pin number from the GPIO subsystem number space
546 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
547 * as part of their gpio_request() semantics, platforms and individual drivers
548 * shall *NOT* request GPIO pins to be muxed in.
550 int pinctrl_request_gpio(unsigned gpio)
552 struct pinctrl_dev *pctldev;
553 struct pinctrl_gpio_range *range;
557 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
559 if (pinctrl_ready_for_gpio_range(gpio))
564 /* Convert to the pin controllers number space */
565 pin = gpio_to_pin(range, gpio);
567 ret = pinmux_request_gpio(pctldev, range, pin, gpio);
571 EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
574 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
575 * @gpio: the GPIO pin number from the GPIO subsystem number space
577 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
578 * as part of their gpio_free() semantics, platforms and individual drivers
579 * shall *NOT* request GPIO pins to be muxed out.
581 void pinctrl_free_gpio(unsigned gpio)
583 struct pinctrl_dev *pctldev;
584 struct pinctrl_gpio_range *range;
588 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
592 mutex_lock(&pctldev->mutex);
594 /* Convert to the pin controllers number space */
595 pin = gpio_to_pin(range, gpio);
597 pinmux_free_gpio(pctldev, pin, range);
599 mutex_unlock(&pctldev->mutex);
601 EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
603 static int pinctrl_gpio_direction(unsigned gpio, bool input)
605 struct pinctrl_dev *pctldev;
606 struct pinctrl_gpio_range *range;
610 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
615 mutex_lock(&pctldev->mutex);
617 /* Convert to the pin controllers number space */
618 pin = gpio_to_pin(range, gpio);
619 ret = pinmux_gpio_direction(pctldev, range, pin, input);
621 mutex_unlock(&pctldev->mutex);
627 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
628 * @gpio: the GPIO pin number from the GPIO subsystem number space
630 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
631 * as part of their gpio_direction_input() semantics, platforms and individual
632 * drivers shall *NOT* touch pin control GPIO calls.
634 int pinctrl_gpio_direction_input(unsigned gpio)
636 return pinctrl_gpio_direction(gpio, true);
638 EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
641 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
642 * @gpio: the GPIO pin number from the GPIO subsystem number space
644 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
645 * as part of their gpio_direction_output() semantics, platforms and individual
646 * drivers shall *NOT* touch pin control GPIO calls.
648 int pinctrl_gpio_direction_output(unsigned gpio)
650 return pinctrl_gpio_direction(gpio, false);
652 EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
654 static struct pinctrl_state *find_state(struct pinctrl *p,
657 struct pinctrl_state *state;
659 list_for_each_entry(state, &p->states, node)
660 if (!strcmp(state->name, name))
666 static struct pinctrl_state *create_state(struct pinctrl *p,
669 struct pinctrl_state *state;
671 state = kzalloc(sizeof(*state), GFP_KERNEL);
674 "failed to alloc struct pinctrl_state\n");
675 return ERR_PTR(-ENOMEM);
679 INIT_LIST_HEAD(&state->settings);
681 list_add_tail(&state->node, &p->states);
686 static int add_setting(struct pinctrl *p, struct pinctrl_map const *map)
688 struct pinctrl_state *state;
689 struct pinctrl_setting *setting;
692 state = find_state(p, map->name);
694 state = create_state(p, map->name);
696 return PTR_ERR(state);
698 if (map->type == PIN_MAP_TYPE_DUMMY_STATE)
701 setting = kzalloc(sizeof(*setting), GFP_KERNEL);
702 if (setting == NULL) {
704 "failed to alloc struct pinctrl_setting\n");
708 setting->type = map->type;
710 setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
711 if (setting->pctldev == NULL) {
713 /* Do not defer probing of hogs (circular loop) */
714 if (!strcmp(map->ctrl_dev_name, map->dev_name))
717 * OK let us guess that the driver is not there yet, and
718 * let's defer obtaining this pinctrl handle to later...
720 dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe",
722 return -EPROBE_DEFER;
725 setting->dev_name = map->dev_name;
728 case PIN_MAP_TYPE_MUX_GROUP:
729 ret = pinmux_map_to_setting(map, setting);
731 case PIN_MAP_TYPE_CONFIGS_PIN:
732 case PIN_MAP_TYPE_CONFIGS_GROUP:
733 ret = pinconf_map_to_setting(map, setting);
744 list_add_tail(&setting->node, &state->settings);
749 static struct pinctrl *find_pinctrl(struct device *dev)
753 mutex_lock(&pinctrl_list_mutex);
754 list_for_each_entry(p, &pinctrl_list, node)
756 mutex_unlock(&pinctrl_list_mutex);
760 mutex_unlock(&pinctrl_list_mutex);
764 static void pinctrl_free(struct pinctrl *p, bool inlist);
766 static struct pinctrl *create_pinctrl(struct device *dev)
770 struct pinctrl_maps *maps_node;
772 struct pinctrl_map const *map;
776 * create the state cookie holder struct pinctrl for each
777 * mapping, this is what consumers will get when requesting
778 * a pin control handle with pinctrl_get()
780 p = kzalloc(sizeof(*p), GFP_KERNEL);
782 dev_err(dev, "failed to alloc struct pinctrl\n");
783 return ERR_PTR(-ENOMEM);
786 INIT_LIST_HEAD(&p->states);
787 INIT_LIST_HEAD(&p->dt_maps);
789 ret = pinctrl_dt_to_map(p);
795 devname = dev_name(dev);
797 mutex_lock(&pinctrl_maps_mutex);
798 /* Iterate over the pin control maps to locate the right ones */
799 for_each_maps(maps_node, i, map) {
800 /* Map must be for this device */
801 if (strcmp(map->dev_name, devname))
804 ret = add_setting(p, map);
806 * At this point the adding of a setting may:
808 * - Defer, if the pinctrl device is not yet available
809 * - Fail, if the pinctrl device is not yet available,
810 * AND the setting is a hog. We cannot defer that, since
811 * the hog will kick in immediately after the device
814 * If the error returned was not -EPROBE_DEFER then we
815 * accumulate the errors to see if we end up with
816 * an -EPROBE_DEFER later, as that is the worst case.
818 if (ret == -EPROBE_DEFER) {
819 pinctrl_free(p, false);
820 mutex_unlock(&pinctrl_maps_mutex);
824 mutex_unlock(&pinctrl_maps_mutex);
827 /* If some other error than deferral occured, return here */
828 pinctrl_free(p, false);
832 kref_init(&p->users);
834 /* Add the pinctrl handle to the global list */
835 list_add_tail(&p->node, &pinctrl_list);
841 * pinctrl_get() - retrieves the pinctrl handle for a device
842 * @dev: the device to obtain the handle for
844 struct pinctrl *pinctrl_get(struct device *dev)
849 return ERR_PTR(-EINVAL);
852 * See if somebody else (such as the device core) has already
853 * obtained a handle to the pinctrl for this device. In that case,
854 * return another pointer to it.
856 p = find_pinctrl(dev);
858 dev_dbg(dev, "obtain a copy of previously claimed pinctrl\n");
863 return create_pinctrl(dev);
865 EXPORT_SYMBOL_GPL(pinctrl_get);
867 static void pinctrl_free_setting(bool disable_setting,
868 struct pinctrl_setting *setting)
870 switch (setting->type) {
871 case PIN_MAP_TYPE_MUX_GROUP:
873 pinmux_disable_setting(setting);
874 pinmux_free_setting(setting);
876 case PIN_MAP_TYPE_CONFIGS_PIN:
877 case PIN_MAP_TYPE_CONFIGS_GROUP:
878 pinconf_free_setting(setting);
885 static void pinctrl_free(struct pinctrl *p, bool inlist)
887 struct pinctrl_state *state, *n1;
888 struct pinctrl_setting *setting, *n2;
890 mutex_lock(&pinctrl_list_mutex);
891 list_for_each_entry_safe(state, n1, &p->states, node) {
892 list_for_each_entry_safe(setting, n2, &state->settings, node) {
893 pinctrl_free_setting(state == p->state, setting);
894 list_del(&setting->node);
897 list_del(&state->node);
901 pinctrl_dt_free_maps(p);
906 mutex_unlock(&pinctrl_list_mutex);
910 * pinctrl_release() - release the pinctrl handle
911 * @kref: the kref in the pinctrl being released
913 static void pinctrl_release(struct kref *kref)
915 struct pinctrl *p = container_of(kref, struct pinctrl, users);
917 pinctrl_free(p, true);
921 * pinctrl_put() - decrease use count on a previously claimed pinctrl handle
922 * @p: the pinctrl handle to release
924 void pinctrl_put(struct pinctrl *p)
926 kref_put(&p->users, pinctrl_release);
928 EXPORT_SYMBOL_GPL(pinctrl_put);
931 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
932 * @p: the pinctrl handle to retrieve the state from
933 * @name: the state name to retrieve
935 struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,
938 struct pinctrl_state *state;
940 state = find_state(p, name);
942 if (pinctrl_dummy_state) {
943 /* create dummy state */
944 dev_dbg(p->dev, "using pinctrl dummy state (%s)\n",
946 state = create_state(p, name);
948 state = ERR_PTR(-ENODEV);
953 EXPORT_SYMBOL_GPL(pinctrl_lookup_state);
956 * pinctrl_select_state() - select/activate/program a pinctrl state to HW
957 * @p: the pinctrl handle for the device that requests configuration
958 * @state: the state handle to select/activate/program
960 int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
962 struct pinctrl_setting *setting, *setting2;
963 struct pinctrl_state *old_state = p->state;
966 if (p->state == state)
971 * The set of groups with a mux configuration in the old state
972 * may not be identical to the set of groups with a mux setting
973 * in the new state. While this might be unusual, it's entirely
974 * possible for the "user"-supplied mapping table to be written
975 * that way. For each group that was configured in the old state
976 * but not in the new state, this code puts that group into a
977 * safe/disabled state.
979 list_for_each_entry(setting, &p->state->settings, node) {
981 if (setting->type != PIN_MAP_TYPE_MUX_GROUP)
983 list_for_each_entry(setting2, &state->settings, node) {
984 if (setting2->type != PIN_MAP_TYPE_MUX_GROUP)
986 if (setting2->data.mux.group ==
987 setting->data.mux.group) {
993 pinmux_disable_setting(setting);
999 /* Apply all the settings for the new state */
1000 list_for_each_entry(setting, &state->settings, node) {
1001 switch (setting->type) {
1002 case PIN_MAP_TYPE_MUX_GROUP:
1003 ret = pinmux_enable_setting(setting);
1005 case PIN_MAP_TYPE_CONFIGS_PIN:
1006 case PIN_MAP_TYPE_CONFIGS_GROUP:
1007 ret = pinconf_apply_setting(setting);
1015 goto unapply_new_state;
1024 dev_err(p->dev, "Error applying setting, reverse things back\n");
1026 list_for_each_entry(setting2, &state->settings, node) {
1027 if (&setting2->node == &setting->node)
1030 * All we can do here is pinmux_disable_setting.
1031 * That means that some pins are muxed differently now
1032 * than they were before applying the setting (We can't
1033 * "unmux a pin"!), but it's not a big deal since the pins
1034 * are free to be muxed by another apply_setting.
1036 if (setting2->type == PIN_MAP_TYPE_MUX_GROUP)
1037 pinmux_disable_setting(setting2);
1040 /* There's no infinite recursive loop here because p->state is NULL */
1042 pinctrl_select_state(p, old_state);
1046 EXPORT_SYMBOL_GPL(pinctrl_select_state);
1048 static void devm_pinctrl_release(struct device *dev, void *res)
1050 pinctrl_put(*(struct pinctrl **)res);
1054 * struct devm_pinctrl_get() - Resource managed pinctrl_get()
1055 * @dev: the device to obtain the handle for
1057 * If there is a need to explicitly destroy the returned struct pinctrl,
1058 * devm_pinctrl_put() should be used, rather than plain pinctrl_put().
1060 struct pinctrl *devm_pinctrl_get(struct device *dev)
1062 struct pinctrl **ptr, *p;
1064 ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL);
1066 return ERR_PTR(-ENOMEM);
1068 p = pinctrl_get(dev);
1071 devres_add(dev, ptr);
1078 EXPORT_SYMBOL_GPL(devm_pinctrl_get);
1080 static int devm_pinctrl_match(struct device *dev, void *res, void *data)
1082 struct pinctrl **p = res;
1088 * devm_pinctrl_put() - Resource managed pinctrl_put()
1089 * @p: the pinctrl handle to release
1091 * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally
1092 * this function will not need to be called and the resource management
1093 * code will ensure that the resource is freed.
1095 void devm_pinctrl_put(struct pinctrl *p)
1097 WARN_ON(devres_release(p->dev, devm_pinctrl_release,
1098 devm_pinctrl_match, p));
1100 EXPORT_SYMBOL_GPL(devm_pinctrl_put);
1102 int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
1103 bool dup, bool locked)
1106 struct pinctrl_maps *maps_node;
1108 pr_debug("add %d pinmux maps\n", num_maps);
1110 /* First sanity check the new mapping */
1111 for (i = 0; i < num_maps; i++) {
1112 if (!maps[i].dev_name) {
1113 pr_err("failed to register map %s (%d): no device given\n",
1118 if (!maps[i].name) {
1119 pr_err("failed to register map %d: no map name given\n",
1124 if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE &&
1125 !maps[i].ctrl_dev_name) {
1126 pr_err("failed to register map %s (%d): no pin control device given\n",
1131 switch (maps[i].type) {
1132 case PIN_MAP_TYPE_DUMMY_STATE:
1134 case PIN_MAP_TYPE_MUX_GROUP:
1135 ret = pinmux_validate_map(&maps[i], i);
1139 case PIN_MAP_TYPE_CONFIGS_PIN:
1140 case PIN_MAP_TYPE_CONFIGS_GROUP:
1141 ret = pinconf_validate_map(&maps[i], i);
1146 pr_err("failed to register map %s (%d): invalid type given\n",
1152 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
1154 pr_err("failed to alloc struct pinctrl_maps\n");
1158 maps_node->num_maps = num_maps;
1160 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,
1162 if (!maps_node->maps) {
1163 pr_err("failed to duplicate mapping table\n");
1168 maps_node->maps = maps;
1172 mutex_lock(&pinctrl_maps_mutex);
1173 list_add_tail(&maps_node->node, &pinctrl_maps);
1175 mutex_unlock(&pinctrl_maps_mutex);
1181 * pinctrl_register_mappings() - register a set of pin controller mappings
1182 * @maps: the pincontrol mappings table to register. This should probably be
1183 * marked with __initdata so it can be discarded after boot. This
1184 * function will perform a shallow copy for the mapping entries.
1185 * @num_maps: the number of maps in the mapping table
1187 int pinctrl_register_mappings(struct pinctrl_map const *maps,
1190 return pinctrl_register_map(maps, num_maps, true, false);
1193 void pinctrl_unregister_map(struct pinctrl_map const *map)
1195 struct pinctrl_maps *maps_node;
1197 mutex_lock(&pinctrl_maps_mutex);
1198 list_for_each_entry(maps_node, &pinctrl_maps, node) {
1199 if (maps_node->maps == map) {
1200 list_del(&maps_node->node);
1201 mutex_unlock(&pinctrl_maps_mutex);
1205 mutex_unlock(&pinctrl_maps_mutex);
1209 * pinctrl_force_sleep() - turn a given controller device into sleep state
1210 * @pctldev: pin controller device
1212 int pinctrl_force_sleep(struct pinctrl_dev *pctldev)
1214 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep))
1215 return pinctrl_select_state(pctldev->p, pctldev->hog_sleep);
1218 EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
1221 * pinctrl_force_default() - turn a given controller device into default state
1222 * @pctldev: pin controller device
1224 int pinctrl_force_default(struct pinctrl_dev *pctldev)
1226 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default))
1227 return pinctrl_select_state(pctldev->p, pctldev->hog_default);
1230 EXPORT_SYMBOL_GPL(pinctrl_force_default);
1235 * pinctrl_pm_select_state() - select pinctrl state for PM
1236 * @dev: device to select default state for
1237 * @state: state to set
1239 static int pinctrl_pm_select_state(struct device *dev,
1240 struct pinctrl_state *state)
1242 struct dev_pin_info *pins = dev->pins;
1246 return 0; /* No such state */
1247 ret = pinctrl_select_state(pins->p, state);
1249 dev_err(dev, "failed to activate pinctrl state %s\n",
1255 * pinctrl_pm_select_default_state() - select default pinctrl state for PM
1256 * @dev: device to select default state for
1258 int pinctrl_pm_select_default_state(struct device *dev)
1263 return pinctrl_pm_select_state(dev, dev->pins->default_state);
1265 EXPORT_SYMBOL_GPL(pinctrl_pm_select_default_state);
1268 * pinctrl_pm_select_sleep_state() - select sleep pinctrl state for PM
1269 * @dev: device to select sleep state for
1271 int pinctrl_pm_select_sleep_state(struct device *dev)
1276 return pinctrl_pm_select_state(dev, dev->pins->sleep_state);
1278 EXPORT_SYMBOL_GPL(pinctrl_pm_select_sleep_state);
1281 * pinctrl_pm_select_idle_state() - select idle pinctrl state for PM
1282 * @dev: device to select idle state for
1284 int pinctrl_pm_select_idle_state(struct device *dev)
1289 return pinctrl_pm_select_state(dev, dev->pins->idle_state);
1291 EXPORT_SYMBOL_GPL(pinctrl_pm_select_idle_state);
1294 #ifdef CONFIG_DEBUG_FS
1296 static int pinctrl_pins_show(struct seq_file *s, void *what)
1298 struct pinctrl_dev *pctldev = s->private;
1299 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1302 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
1304 mutex_lock(&pctldev->mutex);
1306 /* The pin number can be retrived from the pin controller descriptor */
1307 for (i = 0; i < pctldev->desc->npins; i++) {
1308 struct pin_desc *desc;
1310 pin = pctldev->desc->pins[i].number;
1311 desc = pin_desc_get(pctldev, pin);
1312 /* Pin space may be sparse */
1316 seq_printf(s, "pin %d (%s) ", pin,
1317 desc->name ? desc->name : "unnamed");
1319 /* Driver-specific info per pin */
1320 if (ops->pin_dbg_show)
1321 ops->pin_dbg_show(pctldev, s, pin);
1326 mutex_unlock(&pctldev->mutex);
1331 static int pinctrl_groups_show(struct seq_file *s, void *what)
1333 struct pinctrl_dev *pctldev = s->private;
1334 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1335 unsigned ngroups, selector = 0;
1337 mutex_lock(&pctldev->mutex);
1339 ngroups = ops->get_groups_count(pctldev);
1341 seq_puts(s, "registered pin groups:\n");
1342 while (selector < ngroups) {
1343 const unsigned *pins;
1345 const char *gname = ops->get_group_name(pctldev, selector);
1350 ret = ops->get_group_pins(pctldev, selector,
1353 seq_printf(s, "%s [ERROR GETTING PINS]\n",
1356 seq_printf(s, "group: %s\n", gname);
1357 for (i = 0; i < num_pins; i++) {
1358 pname = pin_get_name(pctldev, pins[i]);
1359 if (WARN_ON(!pname)) {
1360 mutex_unlock(&pctldev->mutex);
1363 seq_printf(s, "pin %d (%s)\n", pins[i], pname);
1370 mutex_unlock(&pctldev->mutex);
1375 static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
1377 struct pinctrl_dev *pctldev = s->private;
1378 struct pinctrl_gpio_range *range = NULL;
1380 seq_puts(s, "GPIO ranges handled:\n");
1382 mutex_lock(&pctldev->mutex);
1384 /* Loop over the ranges */
1385 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
1388 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS {",
1389 range->id, range->name,
1390 range->base, (range->base + range->npins - 1));
1391 for (a = 0; a < range->npins - 1; a++)
1392 seq_printf(s, "%u, ", range->pins[a]);
1393 seq_printf(s, "%u}\n", range->pins[a]);
1396 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
1397 range->id, range->name,
1398 range->base, (range->base + range->npins - 1),
1400 (range->pin_base + range->npins - 1));
1403 mutex_unlock(&pctldev->mutex);
1408 static int pinctrl_devices_show(struct seq_file *s, void *what)
1410 struct pinctrl_dev *pctldev;
1412 seq_puts(s, "name [pinmux] [pinconf]\n");
1414 mutex_lock(&pinctrldev_list_mutex);
1416 list_for_each_entry(pctldev, &pinctrldev_list, node) {
1417 seq_printf(s, "%s ", pctldev->desc->name);
1418 if (pctldev->desc->pmxops)
1419 seq_puts(s, "yes ");
1422 if (pctldev->desc->confops)
1429 mutex_unlock(&pinctrldev_list_mutex);
1434 static inline const char *map_type(enum pinctrl_map_type type)
1436 static const char * const names[] = {
1444 if (type >= ARRAY_SIZE(names))
1450 static int pinctrl_maps_show(struct seq_file *s, void *what)
1452 struct pinctrl_maps *maps_node;
1454 struct pinctrl_map const *map;
1456 seq_puts(s, "Pinctrl maps:\n");
1458 mutex_lock(&pinctrl_maps_mutex);
1459 for_each_maps(maps_node, i, map) {
1460 seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n",
1461 map->dev_name, map->name, map_type(map->type),
1464 if (map->type != PIN_MAP_TYPE_DUMMY_STATE)
1465 seq_printf(s, "controlling device %s\n",
1466 map->ctrl_dev_name);
1468 switch (map->type) {
1469 case PIN_MAP_TYPE_MUX_GROUP:
1470 pinmux_show_map(s, map);
1472 case PIN_MAP_TYPE_CONFIGS_PIN:
1473 case PIN_MAP_TYPE_CONFIGS_GROUP:
1474 pinconf_show_map(s, map);
1480 seq_printf(s, "\n");
1482 mutex_unlock(&pinctrl_maps_mutex);
1487 static int pinctrl_show(struct seq_file *s, void *what)
1490 struct pinctrl_state *state;
1491 struct pinctrl_setting *setting;
1493 seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
1495 mutex_lock(&pinctrl_list_mutex);
1497 list_for_each_entry(p, &pinctrl_list, node) {
1498 seq_printf(s, "device: %s current state: %s\n",
1500 p->state ? p->state->name : "none");
1502 list_for_each_entry(state, &p->states, node) {
1503 seq_printf(s, " state: %s\n", state->name);
1505 list_for_each_entry(setting, &state->settings, node) {
1506 struct pinctrl_dev *pctldev = setting->pctldev;
1508 seq_printf(s, " type: %s controller %s ",
1509 map_type(setting->type),
1510 pinctrl_dev_get_name(pctldev));
1512 switch (setting->type) {
1513 case PIN_MAP_TYPE_MUX_GROUP:
1514 pinmux_show_setting(s, setting);
1516 case PIN_MAP_TYPE_CONFIGS_PIN:
1517 case PIN_MAP_TYPE_CONFIGS_GROUP:
1518 pinconf_show_setting(s, setting);
1527 mutex_unlock(&pinctrl_list_mutex);
1532 static int pinctrl_pins_open(struct inode *inode, struct file *file)
1534 return single_open(file, pinctrl_pins_show, inode->i_private);
1537 static int pinctrl_groups_open(struct inode *inode, struct file *file)
1539 return single_open(file, pinctrl_groups_show, inode->i_private);
1542 static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
1544 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
1547 static int pinctrl_devices_open(struct inode *inode, struct file *file)
1549 return single_open(file, pinctrl_devices_show, NULL);
1552 static int pinctrl_maps_open(struct inode *inode, struct file *file)
1554 return single_open(file, pinctrl_maps_show, NULL);
1557 static int pinctrl_open(struct inode *inode, struct file *file)
1559 return single_open(file, pinctrl_show, NULL);
1562 static const struct file_operations pinctrl_pins_ops = {
1563 .open = pinctrl_pins_open,
1565 .llseek = seq_lseek,
1566 .release = single_release,
1569 static const struct file_operations pinctrl_groups_ops = {
1570 .open = pinctrl_groups_open,
1572 .llseek = seq_lseek,
1573 .release = single_release,
1576 static const struct file_operations pinctrl_gpioranges_ops = {
1577 .open = pinctrl_gpioranges_open,
1579 .llseek = seq_lseek,
1580 .release = single_release,
1583 static const struct file_operations pinctrl_devices_ops = {
1584 .open = pinctrl_devices_open,
1586 .llseek = seq_lseek,
1587 .release = single_release,
1590 static const struct file_operations pinctrl_maps_ops = {
1591 .open = pinctrl_maps_open,
1593 .llseek = seq_lseek,
1594 .release = single_release,
1597 static const struct file_operations pinctrl_ops = {
1598 .open = pinctrl_open,
1600 .llseek = seq_lseek,
1601 .release = single_release,
1604 static struct dentry *debugfs_root;
1606 static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1608 struct dentry *device_root;
1610 device_root = debugfs_create_dir(dev_name(pctldev->dev),
1612 pctldev->device_root = device_root;
1614 if (IS_ERR(device_root) || !device_root) {
1615 pr_warn("failed to create debugfs directory for %s\n",
1616 dev_name(pctldev->dev));
1619 debugfs_create_file("pins", S_IFREG | S_IRUGO,
1620 device_root, pctldev, &pinctrl_pins_ops);
1621 debugfs_create_file("pingroups", S_IFREG | S_IRUGO,
1622 device_root, pctldev, &pinctrl_groups_ops);
1623 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
1624 device_root, pctldev, &pinctrl_gpioranges_ops);
1625 pinmux_init_device_debugfs(device_root, pctldev);
1626 pinconf_init_device_debugfs(device_root, pctldev);
1629 static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1631 debugfs_remove_recursive(pctldev->device_root);
1634 static void pinctrl_init_debugfs(void)
1636 debugfs_root = debugfs_create_dir("pinctrl", NULL);
1637 if (IS_ERR(debugfs_root) || !debugfs_root) {
1638 pr_warn("failed to create debugfs directory\n");
1639 debugfs_root = NULL;
1643 debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
1644 debugfs_root, NULL, &pinctrl_devices_ops);
1645 debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
1646 debugfs_root, NULL, &pinctrl_maps_ops);
1647 debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
1648 debugfs_root, NULL, &pinctrl_ops);
1651 #else /* CONFIG_DEBUG_FS */
1653 static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1657 static void pinctrl_init_debugfs(void)
1661 static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1667 static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1669 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1672 !ops->get_groups_count ||
1673 !ops->get_group_name ||
1674 !ops->get_group_pins)
1677 if (ops->dt_node_to_map && !ops->dt_free_map)
1684 * pinctrl_register() - register a pin controller device
1685 * @pctldesc: descriptor for this pin controller
1686 * @dev: parent device for this pin controller
1687 * @driver_data: private pin controller data for this pin controller
1689 struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1690 struct device *dev, void *driver_data)
1692 struct pinctrl_dev *pctldev;
1697 if (!pctldesc->name)
1700 pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
1701 if (pctldev == NULL) {
1702 dev_err(dev, "failed to alloc struct pinctrl_dev\n");
1706 /* Initialize pin control device struct */
1707 pctldev->owner = pctldesc->owner;
1708 pctldev->desc = pctldesc;
1709 pctldev->driver_data = driver_data;
1710 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
1711 INIT_LIST_HEAD(&pctldev->gpio_ranges);
1713 mutex_init(&pctldev->mutex);
1715 /* check core ops for sanity */
1716 if (pinctrl_check_ops(pctldev)) {
1717 dev_err(dev, "pinctrl ops lacks necessary functions\n");
1721 /* If we're implementing pinmuxing, check the ops for sanity */
1722 if (pctldesc->pmxops) {
1723 if (pinmux_check_ops(pctldev))
1727 /* If we're implementing pinconfig, check the ops for sanity */
1728 if (pctldesc->confops) {
1729 if (pinconf_check_ops(pctldev))
1733 /* Register all the pins */
1734 dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);
1735 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
1737 dev_err(dev, "error during pin registration\n");
1738 pinctrl_free_pindescs(pctldev, pctldesc->pins,
1743 mutex_lock(&pinctrldev_list_mutex);
1744 list_add_tail(&pctldev->node, &pinctrldev_list);
1745 mutex_unlock(&pinctrldev_list_mutex);
1747 pctldev->p = pinctrl_get(pctldev->dev);
1749 if (!IS_ERR(pctldev->p)) {
1750 pctldev->hog_default =
1751 pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT);
1752 if (IS_ERR(pctldev->hog_default)) {
1753 dev_dbg(dev, "failed to lookup the default state\n");
1755 if (pinctrl_select_state(pctldev->p,
1756 pctldev->hog_default))
1758 "failed to select default state\n");
1761 pctldev->hog_sleep =
1762 pinctrl_lookup_state(pctldev->p,
1763 PINCTRL_STATE_SLEEP);
1764 if (IS_ERR(pctldev->hog_sleep))
1765 dev_dbg(dev, "failed to lookup the sleep state\n");
1768 pinctrl_init_device_debugfs(pctldev);
1773 mutex_destroy(&pctldev->mutex);
1777 EXPORT_SYMBOL_GPL(pinctrl_register);
1780 * pinctrl_unregister() - unregister pinmux
1781 * @pctldev: pin controller to unregister
1783 * Called by pinmux drivers to unregister a pinmux.
1785 void pinctrl_unregister(struct pinctrl_dev *pctldev)
1787 struct pinctrl_gpio_range *range, *n;
1788 if (pctldev == NULL)
1791 mutex_lock(&pinctrldev_list_mutex);
1792 mutex_lock(&pctldev->mutex);
1794 pinctrl_remove_device_debugfs(pctldev);
1796 if (!IS_ERR(pctldev->p))
1797 pinctrl_put(pctldev->p);
1799 /* TODO: check that no pinmuxes are still active? */
1800 list_del(&pctldev->node);
1801 /* Destroy descriptor tree */
1802 pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
1803 pctldev->desc->npins);
1804 /* remove gpio ranges map */
1805 list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node)
1806 list_del(&range->node);
1808 mutex_unlock(&pctldev->mutex);
1809 mutex_destroy(&pctldev->mutex);
1811 mutex_unlock(&pinctrldev_list_mutex);
1813 EXPORT_SYMBOL_GPL(pinctrl_unregister);
1815 static int __init pinctrl_init(void)
1817 pr_info("initialized pinctrl subsystem\n");
1818 pinctrl_init_debugfs();
1822 /* init early since many drivers really need to initialized pinmux early */
1823 core_initcall(pinctrl_init);