Lines Matching +full:pins +full:- +full:are +full:- +full:numbered
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2011-2012 ST-Ericsson SA
6 * Written on behalf of Linaro for ST-Ericsson
21 #include <linux/radix-tree.h>
34 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pinmux_check_ops()
40 !ops->get_functions_count || in pinmux_check_ops()
41 !ops->get_function_name || in pinmux_check_ops()
42 !ops->get_function_groups || in pinmux_check_ops()
43 !ops->set_mux) { in pinmux_check_ops()
44 dev_err(pctldev->dev, "pinmux ops lacks necessary functions\n"); in pinmux_check_ops()
45 return -EINVAL; in pinmux_check_ops()
48 nfuncs = ops->get_functions_count(pctldev); in pinmux_check_ops()
50 const char *fname = ops->get_function_name(pctldev, in pinmux_check_ops()
53 dev_err(pctldev->dev, "pinmux ops has no name for function%u\n", in pinmux_check_ops()
55 return -EINVAL; in pinmux_check_ops()
65 if (!map->data.mux.function) { in pinmux_validate_map()
67 map->name, i); in pinmux_validate_map()
68 return -EINVAL; in pinmux_validate_map()
75 * pinmux_can_be_used_for_gpio() - check if a specific pin
87 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pinmux_can_be_used_for_gpio()
93 if (ops->strict && desc->mux_usecount) in pinmux_can_be_used_for_gpio()
96 return !(ops->strict && !!desc->gpio_owner); in pinmux_can_be_used_for_gpio()
100 * pin_request() - request a single pin to be muxed in, typically for GPIO
113 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pin_request()
114 int status = -EINVAL; in pin_request()
118 dev_err(pctldev->dev, in pin_request()
124 dev_dbg(pctldev->dev, "request pin %d (%s) for %s\n", in pin_request()
125 pin, desc->name, owner); in pin_request()
127 if ((!gpio_range || ops->strict) && in pin_request()
128 desc->mux_usecount && strcmp(desc->mux_owner, owner)) { in pin_request()
129 dev_err(pctldev->dev, in pin_request()
131 desc->name, desc->mux_owner, owner); in pin_request()
135 if ((gpio_range || ops->strict) && desc->gpio_owner) { in pin_request()
136 dev_err(pctldev->dev, in pin_request()
138 desc->name, desc->gpio_owner, owner); in pin_request()
143 desc->gpio_owner = owner; in pin_request()
145 desc->mux_usecount++; in pin_request()
146 if (desc->mux_usecount > 1) in pin_request()
149 desc->mux_owner = owner; in pin_request()
153 if (!try_module_get(pctldev->owner)) { in pin_request()
154 dev_err(pctldev->dev, in pin_request()
157 status = -EINVAL; in pin_request()
165 if (gpio_range && ops->gpio_request_enable) in pin_request()
167 status = ops->gpio_request_enable(pctldev, gpio_range, pin); in pin_request()
168 else if (ops->request) in pin_request()
169 status = ops->request(pctldev, pin); in pin_request()
174 dev_err(pctldev->dev, "request() failed for pin %d\n", pin); in pin_request()
175 module_put(pctldev->owner); in pin_request()
181 desc->gpio_owner = NULL; in pin_request()
183 desc->mux_usecount--; in pin_request()
184 if (!desc->mux_usecount) in pin_request()
185 desc->mux_owner = NULL; in pin_request()
190 dev_err(pctldev->dev, "pin-%d (%s) status %d\n", in pin_request()
197 * pin_free() - release a single muxed in pin so something else can be muxed
210 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pin_free()
216 dev_err(pctldev->dev, in pin_free()
225 if (WARN_ON(!desc->mux_usecount)) in pin_free()
227 desc->mux_usecount--; in pin_free()
228 if (desc->mux_usecount) in pin_free()
236 if (gpio_range && ops->gpio_disable_free) in pin_free()
237 ops->gpio_disable_free(pctldev, gpio_range, pin); in pin_free()
238 else if (ops->free) in pin_free()
239 ops->free(pctldev, pin); in pin_free()
242 owner = desc->gpio_owner; in pin_free()
243 desc->gpio_owner = NULL; in pin_free()
245 owner = desc->mux_owner; in pin_free()
246 desc->mux_owner = NULL; in pin_free()
247 desc->mux_setting = NULL; in pin_free()
250 module_put(pctldev->owner); in pin_free()
256 * pinmux_request_gpio() - request pinmuxing for a GPIO pin
270 owner = kasprintf(GFP_KERNEL, "%s:%d", range->name, gpio); in pinmux_request_gpio()
272 return -ENOMEM; in pinmux_request_gpio()
282 * pinmux_free_gpio() - release a pin from GPIO muxing
284 * @pin: the affected currently GPIO-muxed in pin
297 * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin
310 ops = pctldev->desc->pmxops; in pinmux_gpio_direction()
312 if (ops->gpio_set_direction) in pinmux_gpio_direction()
313 ret = ops->gpio_set_direction(pctldev, range, pin, input); in pinmux_gpio_direction()
323 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pinmux_func_name_to_selector()
324 unsigned nfuncs = ops->get_functions_count(pctldev); in pinmux_func_name_to_selector()
329 const char *fname = ops->get_function_name(pctldev, selector); in pinmux_func_name_to_selector()
337 return -EINVAL; in pinmux_func_name_to_selector()
343 struct pinctrl_dev *pctldev = setting->pctldev; in pinmux_map_to_setting()
344 const struct pinmux_ops *pmxops = pctldev->desc->pmxops; in pinmux_map_to_setting()
351 dev_err(pctldev->dev, "does not support mux function\n"); in pinmux_map_to_setting()
352 return -EINVAL; in pinmux_map_to_setting()
355 ret = pinmux_func_name_to_selector(pctldev, map->data.mux.function); in pinmux_map_to_setting()
357 dev_err(pctldev->dev, "invalid function %s in map table\n", in pinmux_map_to_setting()
358 map->data.mux.function); in pinmux_map_to_setting()
361 setting->data.mux.func = ret; in pinmux_map_to_setting()
363 ret = pmxops->get_function_groups(pctldev, setting->data.mux.func, in pinmux_map_to_setting()
366 dev_err(pctldev->dev, "can't query groups for function %s\n", in pinmux_map_to_setting()
367 map->data.mux.function); in pinmux_map_to_setting()
371 dev_err(pctldev->dev, in pinmux_map_to_setting()
373 map->data.mux.function); in pinmux_map_to_setting()
374 return -EINVAL; in pinmux_map_to_setting()
376 if (map->data.mux.group) { in pinmux_map_to_setting()
377 group = map->data.mux.group; in pinmux_map_to_setting()
380 dev_err(pctldev->dev, in pinmux_map_to_setting()
382 group, map->data.mux.function); in pinmux_map_to_setting()
391 dev_err(pctldev->dev, "invalid group %s in map table\n", in pinmux_map_to_setting()
392 map->data.mux.group); in pinmux_map_to_setting()
395 setting->data.mux.group = ret; in pinmux_map_to_setting()
407 struct pinctrl_dev *pctldev = setting->pctldev; in pinmux_enable_setting()
408 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinmux_enable_setting()
409 const struct pinmux_ops *ops = pctldev->desc->pmxops; in pinmux_enable_setting()
411 const unsigned *pins = NULL; in pinmux_enable_setting() local
416 if (pctlops->get_group_pins) in pinmux_enable_setting()
417 ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, in pinmux_enable_setting()
418 &pins, &num_pins); in pinmux_enable_setting()
424 gname = pctlops->get_group_name(pctldev, in pinmux_enable_setting()
425 setting->data.mux.group); in pinmux_enable_setting()
426 dev_warn(pctldev->dev, in pinmux_enable_setting()
427 "could not get pins for group %s\n", in pinmux_enable_setting()
432 /* Try to allocate all pins in this group, one by one */ in pinmux_enable_setting()
434 ret = pin_request(pctldev, pins[i], setting->dev_name, NULL); in pinmux_enable_setting()
439 desc = pin_desc_get(pctldev, pins[i]); in pinmux_enable_setting()
440 pname = desc ? desc->name : "non-existing"; in pinmux_enable_setting()
441 gname = pctlops->get_group_name(pctldev, in pinmux_enable_setting()
442 setting->data.mux.group); in pinmux_enable_setting()
443 dev_err(pctldev->dev, in pinmux_enable_setting()
446 pins[i], pname, gname, in pinmux_enable_setting()
452 /* Now that we have acquired the pins, encode the mux setting */ in pinmux_enable_setting()
454 desc = pin_desc_get(pctldev, pins[i]); in pinmux_enable_setting()
456 dev_warn(pctldev->dev, in pinmux_enable_setting()
458 pins[i]); in pinmux_enable_setting()
461 desc->mux_setting = &(setting->data.mux); in pinmux_enable_setting()
464 ret = ops->set_mux(pctldev, setting->data.mux.func, in pinmux_enable_setting()
465 setting->data.mux.group); in pinmux_enable_setting()
474 desc = pin_desc_get(pctldev, pins[i]); in pinmux_enable_setting()
476 desc->mux_setting = NULL; in pinmux_enable_setting()
479 /* On error release all taken pins */ in pinmux_enable_setting()
480 while (--i >= 0) in pinmux_enable_setting()
481 pin_free(pctldev, pins[i], NULL); in pinmux_enable_setting()
488 struct pinctrl_dev *pctldev = setting->pctldev; in pinmux_disable_setting()
489 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinmux_disable_setting()
491 const unsigned *pins = NULL; in pinmux_disable_setting() local
496 if (pctlops->get_group_pins) in pinmux_disable_setting()
497 ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, in pinmux_disable_setting()
498 &pins, &num_pins); in pinmux_disable_setting()
503 gname = pctlops->get_group_name(pctldev, in pinmux_disable_setting()
504 setting->data.mux.group); in pinmux_disable_setting()
505 dev_warn(pctldev->dev, in pinmux_disable_setting()
506 "could not get pins for group %s\n", in pinmux_disable_setting()
513 desc = pin_desc_get(pctldev, pins[i]); in pinmux_disable_setting()
515 dev_warn(pctldev->dev, in pinmux_disable_setting()
517 pins[i]); in pinmux_disable_setting()
520 if (desc->mux_setting == &(setting->data.mux)) { in pinmux_disable_setting()
521 pin_free(pctldev, pins[i], NULL); in pinmux_disable_setting()
525 gname = pctlops->get_group_name(pctldev, in pinmux_disable_setting()
526 setting->data.mux.group); in pinmux_disable_setting()
527 dev_warn(pctldev->dev, in pinmux_disable_setting()
529 "deactivating group %s - it is already " in pinmux_disable_setting()
531 pins[i], desc->name, gname); in pinmux_disable_setting()
541 struct pinctrl_dev *pctldev = s->private; in pinmux_functions_show()
542 const struct pinmux_ops *pmxops = pctldev->desc->pmxops; in pinmux_functions_show()
549 mutex_lock(&pctldev->mutex); in pinmux_functions_show()
550 nfuncs = pmxops->get_functions_count(pctldev); in pinmux_functions_show()
552 const char *func = pmxops->get_function_name(pctldev, in pinmux_functions_show()
559 ret = pmxops->get_function_groups(pctldev, func_selector, in pinmux_functions_show()
576 mutex_unlock(&pctldev->mutex); in pinmux_functions_show()
583 struct pinctrl_dev *pctldev = s->private; in pinmux_pins_show()
584 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinmux_pins_show()
585 const struct pinmux_ops *pmxops = pctldev->desc->pmxops; in pinmux_pins_show()
592 if (pmxops->strict) in pinmux_pins_show()
599 mutex_lock(&pctldev->mutex); in pinmux_pins_show()
602 for (i = 0; i < pctldev->desc->npins; i++) { in pinmux_pins_show()
606 pin = pctldev->desc->pins[i].number; in pinmux_pins_show()
612 if (desc->mux_owner && in pinmux_pins_show()
613 !strcmp(desc->mux_owner, pinctrl_dev_get_name(pctldev))) in pinmux_pins_show()
616 if (pmxops->strict) { in pinmux_pins_show()
617 if (desc->mux_owner) in pinmux_pins_show()
619 pin, desc->name, desc->mux_owner, in pinmux_pins_show()
621 else if (desc->gpio_owner) in pinmux_pins_show()
623 pin, desc->name, desc->gpio_owner); in pinmux_pins_show()
626 pin, desc->name); in pinmux_pins_show()
628 /* For non-strict controllers */ in pinmux_pins_show()
629 seq_printf(s, "pin %d (%s): %s %s%s", pin, desc->name, in pinmux_pins_show()
630 desc->mux_owner ? desc->mux_owner in pinmux_pins_show()
632 desc->gpio_owner ? desc->gpio_owner in pinmux_pins_show()
638 if (desc->mux_setting) in pinmux_pins_show()
640 pmxops->get_function_name(pctldev, in pinmux_pins_show()
641 desc->mux_setting->func), in pinmux_pins_show()
642 pctlops->get_group_name(pctldev, in pinmux_pins_show()
643 desc->mux_setting->group)); in pinmux_pins_show()
648 mutex_unlock(&pctldev->mutex); in pinmux_pins_show()
656 map->data.mux.group ? map->data.mux.group : "(default)", in pinmux_show_map()
657 map->data.mux.function); in pinmux_show_map()
663 struct pinctrl_dev *pctldev = setting->pctldev; in pinmux_show_setting()
664 const struct pinmux_ops *pmxops = pctldev->desc->pmxops; in pinmux_show_setting()
665 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinmux_show_setting()
668 pctlops->get_group_name(pctldev, setting->data.mux.group), in pinmux_show_setting()
669 setting->data.mux.group, in pinmux_show_setting()
670 pmxops->get_function_name(pctldev, setting->data.mux.func), in pinmux_show_setting()
671 setting->data.mux.func); in pinmux_show_setting()
681 struct seq_file *sfile = file->private_data; in pinmux_select()
682 struct pinctrl_dev *pctldev = sfile->private; in pinmux_select()
683 const struct pinmux_ops *pmxops = pctldev->desc->pmxops; in pinmux_select()
690 return -ENOMEM; in pinmux_select()
694 return -ENOMEM; in pinmux_select()
699 buf[len-1] = '\0'; in pinmux_select()
704 ret = -EINVAL; in pinmux_select()
711 ret = -EINVAL; in pinmux_select()
720 ret = -EINVAL; in pinmux_select()
726 dev_err(pctldev->dev, "invalid function %s in map table\n", fname); in pinmux_select()
731 ret = pmxops->get_function_groups(pctldev, fsel, &groups, &num_groups); in pinmux_select()
733 dev_err(pctldev->dev, "no groups for function %d (%s)", fsel, fname); in pinmux_select()
739 dev_err(pctldev->dev, "invalid group %s", gname); in pinmux_select()
745 dev_err(pctldev->dev, "failed to get group selector for %s", gname); in pinmux_select()
750 ret = pmxops->set_mux(pctldev, fsel, gsel); in pinmux_select()
752 dev_err(pctldev->dev, "set_mux() failed: %d", ret); in pinmux_select()
765 return single_open(file, NULL, inode->i_private); in pinmux_select_open()
779 debugfs_create_file("pinmux-functions", 0444, in pinmux_init_device_debugfs()
781 debugfs_create_file("pinmux-pins", 0444, in pinmux_init_device_debugfs()
783 debugfs_create_file("pinmux-select", 0200, in pinmux_init_device_debugfs()
792 * pinmux_generic_get_function_count() - returns number of functions
797 return pctldev->num_functions; in pinmux_generic_get_function_count()
802 * pinmux_generic_get_function_name() - returns the function name
812 function = radix_tree_lookup(&pctldev->pin_function_tree, in pinmux_generic_get_function_name()
817 return function->name; in pinmux_generic_get_function_name()
822 * pinmux_generic_get_function_groups() - gets the function groups
835 function = radix_tree_lookup(&pctldev->pin_function_tree, in pinmux_generic_get_function_groups()
838 dev_err(pctldev->dev, "%s could not find function%i\n", in pinmux_generic_get_function_groups()
840 return -EINVAL; in pinmux_generic_get_function_groups()
842 *groups = function->group_names; in pinmux_generic_get_function_groups()
843 *num_groups = function->num_group_names; in pinmux_generic_get_function_groups()
850 * pinmux_generic_get_function() - returns a function based on the number
859 function = radix_tree_lookup(&pctldev->pin_function_tree, in pinmux_generic_get_function()
869 * pinmux_generic_add_function() - adds a function group
886 return -EINVAL; in pinmux_generic_add_function()
892 selector = pctldev->num_functions; in pinmux_generic_add_function()
894 function = devm_kzalloc(pctldev->dev, sizeof(*function), GFP_KERNEL); in pinmux_generic_add_function()
896 return -ENOMEM; in pinmux_generic_add_function()
898 function->name = name; in pinmux_generic_add_function()
899 function->group_names = groups; in pinmux_generic_add_function()
900 function->num_group_names = num_groups; in pinmux_generic_add_function()
901 function->data = data; in pinmux_generic_add_function()
903 radix_tree_insert(&pctldev->pin_function_tree, selector, function); in pinmux_generic_add_function()
905 pctldev->num_functions++; in pinmux_generic_add_function()
912 * pinmux_generic_remove_function() - removes a numbered function
923 function = radix_tree_lookup(&pctldev->pin_function_tree, in pinmux_generic_remove_function()
926 return -ENOENT; in pinmux_generic_remove_function()
928 radix_tree_delete(&pctldev->pin_function_tree, selector); in pinmux_generic_remove_function()
929 devm_kfree(pctldev->dev, function); in pinmux_generic_remove_function()
931 pctldev->num_functions--; in pinmux_generic_remove_function()
938 * pinmux_generic_free_functions() - removes all functions
942 * functions are allocated with devm_kzalloc() so no need to free
950 radix_tree_for_each_slot(slot, &pctldev->pin_function_tree, &iter, 0) in pinmux_generic_free_functions()
951 radix_tree_delete(&pctldev->pin_function_tree, iter.index); in pinmux_generic_free_functions()
953 pctldev->num_functions = 0; in pinmux_generic_free_functions()