iocost: Fix check condition of iocg abs_vdebt
[linux/fpc-iii.git] / drivers / pinctrl / pinmux.c
blob9503ddf2edc76a2dda40168b818c3f3e193e983b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Core driver for the pin muxing portions of the pin control subsystem
5 * Copyright (C) 2011-2012 ST-Ericsson SA
6 * Written on behalf of Linaro for ST-Ericsson
7 * Based on bits of regulator core, gpio core and clk core
9 * Author: Linus Walleij <linus.walleij@linaro.org>
11 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
13 #define pr_fmt(fmt) "pinmux core: " fmt
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/device.h>
19 #include <linux/slab.h>
20 #include <linux/radix-tree.h>
21 #include <linux/err.h>
22 #include <linux/list.h>
23 #include <linux/string.h>
24 #include <linux/debugfs.h>
25 #include <linux/seq_file.h>
26 #include <linux/pinctrl/machine.h>
27 #include <linux/pinctrl/pinmux.h>
28 #include "core.h"
29 #include "pinmux.h"
31 int pinmux_check_ops(struct pinctrl_dev *pctldev)
33 const struct pinmux_ops *ops = pctldev->desc->pmxops;
34 unsigned nfuncs;
35 unsigned selector = 0;
37 /* Check that we implement required operations */
38 if (!ops ||
39 !ops->get_functions_count ||
40 !ops->get_function_name ||
41 !ops->get_function_groups ||
42 !ops->set_mux) {
43 dev_err(pctldev->dev, "pinmux ops lacks necessary functions\n");
44 return -EINVAL;
46 /* Check that all functions registered have names */
47 nfuncs = ops->get_functions_count(pctldev);
48 while (selector < nfuncs) {
49 const char *fname = ops->get_function_name(pctldev,
50 selector);
51 if (!fname) {
52 dev_err(pctldev->dev, "pinmux ops has no name for function%u\n",
53 selector);
54 return -EINVAL;
56 selector++;
59 return 0;
62 int pinmux_validate_map(const struct pinctrl_map *map, int i)
64 if (!map->data.mux.function) {
65 pr_err("failed to register map %s (%d): no function given\n",
66 map->name, i);
67 return -EINVAL;
70 return 0;
73 /**
74 * pinmux_can_be_used_for_gpio() - check if a specific pin
75 * is either muxed to a different function or used as gpio.
77 * @pin: the pin number in the global pin space
79 * Controllers not defined as strict will always return true,
80 * menaning that the gpio can be used.
82 bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
84 struct pin_desc *desc = pin_desc_get(pctldev, pin);
85 const struct pinmux_ops *ops = pctldev->desc->pmxops;
87 /* Can't inspect pin, assume it can be used */
88 if (!desc || !ops)
89 return true;
91 if (ops->strict && desc->mux_usecount)
92 return false;
94 return !(ops->strict && !!desc->gpio_owner);
97 /**
98 * pin_request() - request a single pin to be muxed in, typically for GPIO
99 * @pin: the pin number in the global pin space
100 * @owner: a representation of the owner of this pin; typically the device
101 * name that controls its mux function, or the requested GPIO name
102 * @gpio_range: the range matching the GPIO pin if this is a request for a
103 * single GPIO pin
105 static int pin_request(struct pinctrl_dev *pctldev,
106 int pin, const char *owner,
107 struct pinctrl_gpio_range *gpio_range)
109 struct pin_desc *desc;
110 const struct pinmux_ops *ops = pctldev->desc->pmxops;
111 int status = -EINVAL;
113 desc = pin_desc_get(pctldev, pin);
114 if (desc == NULL) {
115 dev_err(pctldev->dev,
116 "pin %d is not registered so it cannot be requested\n",
117 pin);
118 goto out;
121 dev_dbg(pctldev->dev, "request pin %d (%s) for %s\n",
122 pin, desc->name, owner);
124 if ((!gpio_range || ops->strict) &&
125 desc->mux_usecount && strcmp(desc->mux_owner, owner)) {
126 dev_err(pctldev->dev,
127 "pin %s already requested by %s; cannot claim for %s\n",
128 desc->name, desc->mux_owner, owner);
129 goto out;
132 if ((gpio_range || ops->strict) && desc->gpio_owner) {
133 dev_err(pctldev->dev,
134 "pin %s already requested by %s; cannot claim for %s\n",
135 desc->name, desc->gpio_owner, owner);
136 goto out;
139 if (gpio_range) {
140 desc->gpio_owner = owner;
141 } else {
142 desc->mux_usecount++;
143 if (desc->mux_usecount > 1)
144 return 0;
146 desc->mux_owner = owner;
149 /* Let each pin increase references to this module */
150 if (!try_module_get(pctldev->owner)) {
151 dev_err(pctldev->dev,
152 "could not increase module refcount for pin %d\n",
153 pin);
154 status = -EINVAL;
155 goto out_free_pin;
159 * If there is no kind of request function for the pin we just assume
160 * we got it by default and proceed.
162 if (gpio_range && ops->gpio_request_enable)
163 /* This requests and enables a single GPIO pin */
164 status = ops->gpio_request_enable(pctldev, gpio_range, pin);
165 else if (ops->request)
166 status = ops->request(pctldev, pin);
167 else
168 status = 0;
170 if (status) {
171 dev_err(pctldev->dev, "request() failed for pin %d\n", pin);
172 module_put(pctldev->owner);
175 out_free_pin:
176 if (status) {
177 if (gpio_range) {
178 desc->gpio_owner = NULL;
179 } else {
180 desc->mux_usecount--;
181 if (!desc->mux_usecount)
182 desc->mux_owner = NULL;
185 out:
186 if (status)
187 dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
188 pin, owner, status);
190 return status;
194 * pin_free() - release a single muxed in pin so something else can be muxed
195 * @pctldev: pin controller device handling this pin
196 * @pin: the pin to free
197 * @gpio_range: the range matching the GPIO pin if this is a request for a
198 * single GPIO pin
200 * This function returns a pointer to the previous owner. This is used
201 * for callers that dynamically allocate an owner name so it can be freed
202 * once the pin is free. This is done for GPIO request functions.
204 static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
205 struct pinctrl_gpio_range *gpio_range)
207 const struct pinmux_ops *ops = pctldev->desc->pmxops;
208 struct pin_desc *desc;
209 const char *owner;
211 desc = pin_desc_get(pctldev, pin);
212 if (desc == NULL) {
213 dev_err(pctldev->dev,
214 "pin is not registered so it cannot be freed\n");
215 return NULL;
218 if (!gpio_range) {
220 * A pin should not be freed more times than allocated.
222 if (WARN_ON(!desc->mux_usecount))
223 return NULL;
224 desc->mux_usecount--;
225 if (desc->mux_usecount)
226 return NULL;
230 * If there is no kind of request function for the pin we just assume
231 * we got it by default and proceed.
233 if (gpio_range && ops->gpio_disable_free)
234 ops->gpio_disable_free(pctldev, gpio_range, pin);
235 else if (ops->free)
236 ops->free(pctldev, pin);
238 if (gpio_range) {
239 owner = desc->gpio_owner;
240 desc->gpio_owner = NULL;
241 } else {
242 owner = desc->mux_owner;
243 desc->mux_owner = NULL;
244 desc->mux_setting = NULL;
247 module_put(pctldev->owner);
249 return owner;
253 * pinmux_request_gpio() - request pinmuxing for a GPIO pin
254 * @pctldev: pin controller device affected
255 * @pin: the pin to mux in for GPIO
256 * @range: the applicable GPIO range
258 int pinmux_request_gpio(struct pinctrl_dev *pctldev,
259 struct pinctrl_gpio_range *range,
260 unsigned pin, unsigned gpio)
262 const char *owner;
263 int ret;
265 /* Conjure some name stating what chip and pin this is taken by */
266 owner = kasprintf(GFP_KERNEL, "%s:%d", range->name, gpio);
267 if (!owner)
268 return -ENOMEM;
270 ret = pin_request(pctldev, pin, owner, range);
271 if (ret < 0)
272 kfree(owner);
274 return ret;
278 * pinmux_free_gpio() - release a pin from GPIO muxing
279 * @pctldev: the pin controller device for the pin
280 * @pin: the affected currently GPIO-muxed in pin
281 * @range: applicable GPIO range
283 void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
284 struct pinctrl_gpio_range *range)
286 const char *owner;
288 owner = pin_free(pctldev, pin, range);
289 kfree(owner);
293 * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin
294 * @pctldev: the pin controller handling this pin
295 * @range: applicable GPIO range
296 * @pin: the affected GPIO pin in this controller
297 * @input: true if we set the pin as input, false for output
299 int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
300 struct pinctrl_gpio_range *range,
301 unsigned pin, bool input)
303 const struct pinmux_ops *ops;
304 int ret;
306 ops = pctldev->desc->pmxops;
308 if (ops->gpio_set_direction)
309 ret = ops->gpio_set_direction(pctldev, range, pin, input);
310 else
311 ret = 0;
313 return ret;
316 static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev,
317 const char *function)
319 const struct pinmux_ops *ops = pctldev->desc->pmxops;
320 unsigned nfuncs = ops->get_functions_count(pctldev);
321 unsigned selector = 0;
323 /* See if this pctldev has this function */
324 while (selector < nfuncs) {
325 const char *fname = ops->get_function_name(pctldev, selector);
327 if (!strcmp(function, fname))
328 return selector;
330 selector++;
333 return -EINVAL;
336 int pinmux_map_to_setting(const struct pinctrl_map *map,
337 struct pinctrl_setting *setting)
339 struct pinctrl_dev *pctldev = setting->pctldev;
340 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
341 char const * const *groups;
342 unsigned num_groups;
343 int ret;
344 const char *group;
346 if (!pmxops) {
347 dev_err(pctldev->dev, "does not support mux function\n");
348 return -EINVAL;
351 ret = pinmux_func_name_to_selector(pctldev, map->data.mux.function);
352 if (ret < 0) {
353 dev_err(pctldev->dev, "invalid function %s in map table\n",
354 map->data.mux.function);
355 return ret;
357 setting->data.mux.func = ret;
359 ret = pmxops->get_function_groups(pctldev, setting->data.mux.func,
360 &groups, &num_groups);
361 if (ret < 0) {
362 dev_err(pctldev->dev, "can't query groups for function %s\n",
363 map->data.mux.function);
364 return ret;
366 if (!num_groups) {
367 dev_err(pctldev->dev,
368 "function %s can't be selected on any group\n",
369 map->data.mux.function);
370 return -EINVAL;
372 if (map->data.mux.group) {
373 group = map->data.mux.group;
374 ret = match_string(groups, num_groups, group);
375 if (ret < 0) {
376 dev_err(pctldev->dev,
377 "invalid group \"%s\" for function \"%s\"\n",
378 group, map->data.mux.function);
379 return ret;
381 } else {
382 group = groups[0];
385 ret = pinctrl_get_group_selector(pctldev, group);
386 if (ret < 0) {
387 dev_err(pctldev->dev, "invalid group %s in map table\n",
388 map->data.mux.group);
389 return ret;
391 setting->data.mux.group = ret;
393 return 0;
396 void pinmux_free_setting(const struct pinctrl_setting *setting)
398 /* This function is currently unused */
401 int pinmux_enable_setting(const struct pinctrl_setting *setting)
403 struct pinctrl_dev *pctldev = setting->pctldev;
404 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
405 const struct pinmux_ops *ops = pctldev->desc->pmxops;
406 int ret = 0;
407 const unsigned *pins = NULL;
408 unsigned num_pins = 0;
409 int i;
410 struct pin_desc *desc;
412 if (pctlops->get_group_pins)
413 ret = pctlops->get_group_pins(pctldev, setting->data.mux.group,
414 &pins, &num_pins);
416 if (ret) {
417 const char *gname;
419 /* errors only affect debug data, so just warn */
420 gname = pctlops->get_group_name(pctldev,
421 setting->data.mux.group);
422 dev_warn(pctldev->dev,
423 "could not get pins for group %s\n",
424 gname);
425 num_pins = 0;
428 /* Try to allocate all pins in this group, one by one */
429 for (i = 0; i < num_pins; i++) {
430 ret = pin_request(pctldev, pins[i], setting->dev_name, NULL);
431 if (ret) {
432 const char *gname;
433 const char *pname;
435 desc = pin_desc_get(pctldev, pins[i]);
436 pname = desc ? desc->name : "non-existing";
437 gname = pctlops->get_group_name(pctldev,
438 setting->data.mux.group);
439 dev_err(pctldev->dev,
440 "could not request pin %d (%s) from group %s "
441 " on device %s\n",
442 pins[i], pname, gname,
443 pinctrl_dev_get_name(pctldev));
444 goto err_pin_request;
448 /* Now that we have acquired the pins, encode the mux setting */
449 for (i = 0; i < num_pins; i++) {
450 desc = pin_desc_get(pctldev, pins[i]);
451 if (desc == NULL) {
452 dev_warn(pctldev->dev,
453 "could not get pin desc for pin %d\n",
454 pins[i]);
455 continue;
457 desc->mux_setting = &(setting->data.mux);
460 ret = ops->set_mux(pctldev, setting->data.mux.func,
461 setting->data.mux.group);
463 if (ret)
464 goto err_set_mux;
466 return 0;
468 err_set_mux:
469 for (i = 0; i < num_pins; i++) {
470 desc = pin_desc_get(pctldev, pins[i]);
471 if (desc)
472 desc->mux_setting = NULL;
474 err_pin_request:
475 /* On error release all taken pins */
476 while (--i >= 0)
477 pin_free(pctldev, pins[i], NULL);
479 return ret;
482 void pinmux_disable_setting(const struct pinctrl_setting *setting)
484 struct pinctrl_dev *pctldev = setting->pctldev;
485 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
486 int ret = 0;
487 const unsigned *pins = NULL;
488 unsigned num_pins = 0;
489 int i;
490 struct pin_desc *desc;
492 if (pctlops->get_group_pins)
493 ret = pctlops->get_group_pins(pctldev, setting->data.mux.group,
494 &pins, &num_pins);
495 if (ret) {
496 const char *gname;
498 /* errors only affect debug data, so just warn */
499 gname = pctlops->get_group_name(pctldev,
500 setting->data.mux.group);
501 dev_warn(pctldev->dev,
502 "could not get pins for group %s\n",
503 gname);
504 num_pins = 0;
507 /* Flag the descs that no setting is active */
508 for (i = 0; i < num_pins; i++) {
509 desc = pin_desc_get(pctldev, pins[i]);
510 if (desc == NULL) {
511 dev_warn(pctldev->dev,
512 "could not get pin desc for pin %d\n",
513 pins[i]);
514 continue;
516 if (desc->mux_setting == &(setting->data.mux)) {
517 pin_free(pctldev, pins[i], NULL);
518 } else {
519 const char *gname;
521 gname = pctlops->get_group_name(pctldev,
522 setting->data.mux.group);
523 dev_warn(pctldev->dev,
524 "not freeing pin %d (%s) as part of "
525 "deactivating group %s - it is already "
526 "used for some other setting",
527 pins[i], desc->name, gname);
532 #ifdef CONFIG_DEBUG_FS
534 /* Called from pincontrol core */
535 static int pinmux_functions_show(struct seq_file *s, void *what)
537 struct pinctrl_dev *pctldev = s->private;
538 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
539 unsigned nfuncs;
540 unsigned func_selector = 0;
542 if (!pmxops)
543 return 0;
545 mutex_lock(&pctldev->mutex);
546 nfuncs = pmxops->get_functions_count(pctldev);
547 while (func_selector < nfuncs) {
548 const char *func = pmxops->get_function_name(pctldev,
549 func_selector);
550 const char * const *groups;
551 unsigned num_groups;
552 int ret;
553 int i;
555 ret = pmxops->get_function_groups(pctldev, func_selector,
556 &groups, &num_groups);
557 if (ret) {
558 seq_printf(s, "function %s: COULD NOT GET GROUPS\n",
559 func);
560 func_selector++;
561 continue;
564 seq_printf(s, "function: %s, groups = [ ", func);
565 for (i = 0; i < num_groups; i++)
566 seq_printf(s, "%s ", groups[i]);
567 seq_puts(s, "]\n");
569 func_selector++;
572 mutex_unlock(&pctldev->mutex);
574 return 0;
577 static int pinmux_pins_show(struct seq_file *s, void *what)
579 struct pinctrl_dev *pctldev = s->private;
580 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
581 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
582 unsigned i, pin;
584 if (!pmxops)
585 return 0;
587 seq_puts(s, "Pinmux settings per pin\n");
588 if (pmxops->strict)
589 seq_puts(s,
590 "Format: pin (name): mux_owner|gpio_owner (strict) hog?\n");
591 else
592 seq_puts(s,
593 "Format: pin (name): mux_owner gpio_owner hog?\n");
595 mutex_lock(&pctldev->mutex);
597 /* The pin number can be retrived from the pin controller descriptor */
598 for (i = 0; i < pctldev->desc->npins; i++) {
599 struct pin_desc *desc;
600 bool is_hog = false;
602 pin = pctldev->desc->pins[i].number;
603 desc = pin_desc_get(pctldev, pin);
604 /* Skip if we cannot search the pin */
605 if (desc == NULL)
606 continue;
608 if (desc->mux_owner &&
609 !strcmp(desc->mux_owner, pinctrl_dev_get_name(pctldev)))
610 is_hog = true;
612 if (pmxops->strict) {
613 if (desc->mux_owner)
614 seq_printf(s, "pin %d (%s): device %s%s",
615 pin, desc->name, desc->mux_owner,
616 is_hog ? " (HOG)" : "");
617 else if (desc->gpio_owner)
618 seq_printf(s, "pin %d (%s): GPIO %s",
619 pin, desc->name, desc->gpio_owner);
620 else
621 seq_printf(s, "pin %d (%s): UNCLAIMED",
622 pin, desc->name);
623 } else {
624 /* For non-strict controllers */
625 seq_printf(s, "pin %d (%s): %s %s%s", pin, desc->name,
626 desc->mux_owner ? desc->mux_owner
627 : "(MUX UNCLAIMED)",
628 desc->gpio_owner ? desc->gpio_owner
629 : "(GPIO UNCLAIMED)",
630 is_hog ? " (HOG)" : "");
633 /* If mux: print function+group claiming the pin */
634 if (desc->mux_setting)
635 seq_printf(s, " function %s group %s\n",
636 pmxops->get_function_name(pctldev,
637 desc->mux_setting->func),
638 pctlops->get_group_name(pctldev,
639 desc->mux_setting->group));
640 else
641 seq_putc(s, '\n');
644 mutex_unlock(&pctldev->mutex);
646 return 0;
649 void pinmux_show_map(struct seq_file *s, const struct pinctrl_map *map)
651 seq_printf(s, "group %s\nfunction %s\n",
652 map->data.mux.group ? map->data.mux.group : "(default)",
653 map->data.mux.function);
656 void pinmux_show_setting(struct seq_file *s,
657 const struct pinctrl_setting *setting)
659 struct pinctrl_dev *pctldev = setting->pctldev;
660 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
661 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
663 seq_printf(s, "group: %s (%u) function: %s (%u)\n",
664 pctlops->get_group_name(pctldev, setting->data.mux.group),
665 setting->data.mux.group,
666 pmxops->get_function_name(pctldev, setting->data.mux.func),
667 setting->data.mux.func);
670 DEFINE_SHOW_ATTRIBUTE(pinmux_functions);
671 DEFINE_SHOW_ATTRIBUTE(pinmux_pins);
673 void pinmux_init_device_debugfs(struct dentry *devroot,
674 struct pinctrl_dev *pctldev)
676 debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO,
677 devroot, pctldev, &pinmux_functions_fops);
678 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,
679 devroot, pctldev, &pinmux_pins_fops);
682 #endif /* CONFIG_DEBUG_FS */
684 #ifdef CONFIG_GENERIC_PINMUX_FUNCTIONS
687 * pinmux_generic_get_function_count() - returns number of functions
688 * @pctldev: pin controller device
690 int pinmux_generic_get_function_count(struct pinctrl_dev *pctldev)
692 return pctldev->num_functions;
694 EXPORT_SYMBOL_GPL(pinmux_generic_get_function_count);
697 * pinmux_generic_get_function_name() - returns the function name
698 * @pctldev: pin controller device
699 * @selector: function number
701 const char *
702 pinmux_generic_get_function_name(struct pinctrl_dev *pctldev,
703 unsigned int selector)
705 struct function_desc *function;
707 function = radix_tree_lookup(&pctldev->pin_function_tree,
708 selector);
709 if (!function)
710 return NULL;
712 return function->name;
714 EXPORT_SYMBOL_GPL(pinmux_generic_get_function_name);
717 * pinmux_generic_get_function_groups() - gets the function groups
718 * @pctldev: pin controller device
719 * @selector: function number
720 * @groups: array of pin groups
721 * @num_groups: number of pin groups
723 int pinmux_generic_get_function_groups(struct pinctrl_dev *pctldev,
724 unsigned int selector,
725 const char * const **groups,
726 unsigned * const num_groups)
728 struct function_desc *function;
730 function = radix_tree_lookup(&pctldev->pin_function_tree,
731 selector);
732 if (!function) {
733 dev_err(pctldev->dev, "%s could not find function%i\n",
734 __func__, selector);
735 return -EINVAL;
737 *groups = function->group_names;
738 *num_groups = function->num_group_names;
740 return 0;
742 EXPORT_SYMBOL_GPL(pinmux_generic_get_function_groups);
745 * pinmux_generic_get_function() - returns a function based on the number
746 * @pctldev: pin controller device
747 * @group_selector: function number
749 struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev,
750 unsigned int selector)
752 struct function_desc *function;
754 function = radix_tree_lookup(&pctldev->pin_function_tree,
755 selector);
756 if (!function)
757 return NULL;
759 return function;
761 EXPORT_SYMBOL_GPL(pinmux_generic_get_function);
764 * pinmux_generic_add_function() - adds a function group
765 * @pctldev: pin controller device
766 * @name: name of the function
767 * @groups: array of pin groups
768 * @num_groups: number of pin groups
769 * @data: pin controller driver specific data
771 int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
772 const char *name,
773 const char **groups,
774 const unsigned int num_groups,
775 void *data)
777 struct function_desc *function;
778 int selector;
780 if (!name)
781 return -EINVAL;
783 selector = pinmux_func_name_to_selector(pctldev, name);
784 if (selector >= 0)
785 return selector;
787 selector = pctldev->num_functions;
789 function = devm_kzalloc(pctldev->dev, sizeof(*function), GFP_KERNEL);
790 if (!function)
791 return -ENOMEM;
793 function->name = name;
794 function->group_names = groups;
795 function->num_group_names = num_groups;
796 function->data = data;
798 radix_tree_insert(&pctldev->pin_function_tree, selector, function);
800 pctldev->num_functions++;
802 return selector;
804 EXPORT_SYMBOL_GPL(pinmux_generic_add_function);
807 * pinmux_generic_remove_function() - removes a numbered function
808 * @pctldev: pin controller device
809 * @selector: function number
811 * Note that the caller must take care of locking.
813 int pinmux_generic_remove_function(struct pinctrl_dev *pctldev,
814 unsigned int selector)
816 struct function_desc *function;
818 function = radix_tree_lookup(&pctldev->pin_function_tree,
819 selector);
820 if (!function)
821 return -ENOENT;
823 radix_tree_delete(&pctldev->pin_function_tree, selector);
824 devm_kfree(pctldev->dev, function);
826 pctldev->num_functions--;
828 return 0;
830 EXPORT_SYMBOL_GPL(pinmux_generic_remove_function);
833 * pinmux_generic_free_functions() - removes all functions
834 * @pctldev: pin controller device
836 * Note that the caller must take care of locking. The pinctrl
837 * functions are allocated with devm_kzalloc() so no need to free
838 * them here.
840 void pinmux_generic_free_functions(struct pinctrl_dev *pctldev)
842 struct radix_tree_iter iter;
843 void __rcu **slot;
845 radix_tree_for_each_slot(slot, &pctldev->pin_function_tree, &iter, 0)
846 radix_tree_delete(&pctldev->pin_function_tree, iter.index);
848 pctldev->num_functions = 0;
851 #endif /* CONFIG_GENERIC_PINMUX_FUNCTIONS */