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
31 #include <asm-generic/gpio.h>
62 * pinctrl_provide_dummies() - indicate if pinctrl provides dummy state support
77 return pctldev->desc->name; in pinctrl_dev_get_name()
83 return dev_name(pctldev->dev); in pinctrl_dev_get_devname()
89 return pctldev->driver_data; in pinctrl_dev_get_drvdata()
94 * get_pinctrl_dev_from_devname() - look up pin controller device
110 if (!strcmp(dev_name(pctldev->dev), devname)) { in get_pinctrl_dev_from_devname()
129 if (device_match_of_node(pctldev->dev, np)) { in get_pinctrl_dev_from_of_node()
140 * pin_get_from_name() - look up a pin number from a name
149 for (i = 0; i < pctldev->desc->npins; i++) { in pin_get_from_name()
152 pin = pctldev->desc->pins[i].number; in pin_get_from_name()
155 if (desc && !strcmp(name, desc->name)) in pin_get_from_name()
159 return -EINVAL; in pin_get_from_name()
163 * pin_get_name() - look up a pin name from a pin id
173 dev_err(pctldev->dev, "failed to get pin(%d) name\n", in pin_get_name()
178 return desc->name; in pin_get_name()
184 const struct pinctrl_pin_desc *pins, in pinctrl_free_pindescs() argument
192 pindesc = radix_tree_lookup(&pctldev->pin_desc_tree, in pinctrl_free_pindescs()
193 pins[i].number); in pinctrl_free_pindescs()
195 radix_tree_delete(&pctldev->pin_desc_tree, in pinctrl_free_pindescs()
196 pins[i].number); in pinctrl_free_pindescs()
197 if (pindesc->dynamic_name) in pinctrl_free_pindescs()
198 kfree(pindesc->name); in pinctrl_free_pindescs()
209 pindesc = pin_desc_get(pctldev, pin->number); in pinctrl_register_one_pin()
211 dev_err(pctldev->dev, "pin %d already registered\n", in pinctrl_register_one_pin()
212 pin->number); in pinctrl_register_one_pin()
213 return -EINVAL; in pinctrl_register_one_pin()
218 return -ENOMEM; in pinctrl_register_one_pin()
221 pindesc->pctldev = pctldev; in pinctrl_register_one_pin()
224 if (pin->name) { in pinctrl_register_one_pin()
225 pindesc->name = pin->name; in pinctrl_register_one_pin()
227 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", pin->number); in pinctrl_register_one_pin()
228 if (!pindesc->name) { in pinctrl_register_one_pin()
230 return -ENOMEM; in pinctrl_register_one_pin()
232 pindesc->dynamic_name = true; in pinctrl_register_one_pin()
235 pindesc->drv_data = pin->drv_data; in pinctrl_register_one_pin()
237 radix_tree_insert(&pctldev->pin_desc_tree, pin->number, pindesc); in pinctrl_register_one_pin()
239 pin->number, pindesc->name, pctldev->desc->name); in pinctrl_register_one_pin()
244 const struct pinctrl_pin_desc *pins, in pinctrl_register_pins() argument
251 ret = pinctrl_register_one_pin(pctldev, &pins[i]); in pinctrl_register_pins()
260 * gpio_to_pin() - GPIO range GPIO number to pin number translation
275 unsigned int offset = gpio - range->base; in gpio_to_pin()
276 if (range->pins) in gpio_to_pin()
277 return range->pins[offset]; in gpio_to_pin()
279 return range->pin_base + offset; in gpio_to_pin()
283 * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
295 mutex_lock(&pctldev->mutex); in pinctrl_match_gpio_range()
297 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_match_gpio_range()
299 if (gpio >= range->base && in pinctrl_match_gpio_range()
300 gpio < range->base + range->npins) { in pinctrl_match_gpio_range()
301 mutex_unlock(&pctldev->mutex); in pinctrl_match_gpio_range()
305 mutex_unlock(&pctldev->mutex); in pinctrl_match_gpio_range()
310 * pinctrl_ready_for_gpio_range() - check if other GPIO pins of
311 * the same GPIO chip are in range
316 * to check whether pinctrl device is ready or not. Maybe some GPIO pins
317 * of the same GPIO chip don't have back-end pinctrl interface.
319 * certain GPIO pin doesn't have back-end pinctrl device. If the return value
337 mutex_lock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
338 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_ready_for_gpio_range()
340 if (range->base + range->npins - 1 < chip->base || in pinctrl_ready_for_gpio_range()
341 range->base > chip->base + chip->ngpio - 1) in pinctrl_ready_for_gpio_range()
343 mutex_unlock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
347 mutex_unlock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
359 * pinctrl_get_device_gpio_range() - find device for GPIO range
366 * -EPROBE_DEFER if the GPIO range could not be found in any device since it
392 return -EPROBE_DEFER; in pinctrl_get_device_gpio_range()
396 * pinctrl_add_gpio_range() - register a GPIO range for a controller
406 mutex_lock(&pctldev->mutex); in pinctrl_add_gpio_range()
407 list_add_tail(&range->node, &pctldev->gpio_ranges); in pinctrl_add_gpio_range()
408 mutex_unlock(&pctldev->mutex); in pinctrl_add_gpio_range()
436 return ERR_PTR(-EPROBE_DEFER); in pinctrl_find_and_add_gpio_range()
445 const unsigned **pins, unsigned *num_pins) in pinctrl_get_group_pins() argument
447 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinctrl_get_group_pins()
450 if (!pctlops->get_group_pins) in pinctrl_get_group_pins()
451 return -EINVAL; in pinctrl_get_group_pins()
457 return pctlops->get_group_pins(pctldev, gs, pins, num_pins); in pinctrl_get_group_pins()
468 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_find_gpio_range_from_pin_nolock()
470 if (range->pins) { in pinctrl_find_gpio_range_from_pin_nolock()
472 for (a = 0; a < range->npins; a++) { in pinctrl_find_gpio_range_from_pin_nolock()
473 if (range->pins[a] == pin) in pinctrl_find_gpio_range_from_pin_nolock()
476 } else if (pin >= range->pin_base && in pinctrl_find_gpio_range_from_pin_nolock()
477 pin < range->pin_base + range->npins) in pinctrl_find_gpio_range_from_pin_nolock()
486 * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin
488 * @pin: a controller-local number to find the range for
496 mutex_lock(&pctldev->mutex); in pinctrl_find_gpio_range_from_pin()
498 mutex_unlock(&pctldev->mutex); in pinctrl_find_gpio_range_from_pin()
505 * pinctrl_remove_gpio_range() - remove a range of GPIOs from a pin controller
512 mutex_lock(&pctldev->mutex); in pinctrl_remove_gpio_range()
513 list_del(&range->node); in pinctrl_remove_gpio_range()
514 mutex_unlock(&pctldev->mutex); in pinctrl_remove_gpio_range()
521 * pinctrl_generic_get_group_count() - returns the number of pin groups
526 return pctldev->num_groups; in pinctrl_generic_get_group_count()
531 * pinctrl_generic_get_group_name() - returns the name of a pin group
540 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group_name()
545 return group->name; in pinctrl_generic_get_group_name()
550 * pinctrl_generic_get_group_pins() - gets the pin group pins
553 * @pins: pins in the group
554 * @num_pins: number of pins in the group
558 const unsigned int **pins, in pinctrl_generic_get_group_pins() argument
563 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group_pins()
566 dev_err(pctldev->dev, "%s could not find pingroup%i\n", in pinctrl_generic_get_group_pins()
568 return -EINVAL; in pinctrl_generic_get_group_pins()
571 *pins = group->pins; in pinctrl_generic_get_group_pins()
572 *num_pins = group->num_pins; in pinctrl_generic_get_group_pins()
579 * pinctrl_generic_get_group() - returns a pin group based on the number
588 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group()
600 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_generic_group_name_to_selector()
601 int ngroups = ops->get_groups_count(pctldev); in pinctrl_generic_group_name_to_selector()
606 const char *gname = ops->get_group_name(pctldev, selector); in pinctrl_generic_group_name_to_selector()
614 return -EINVAL; in pinctrl_generic_group_name_to_selector()
618 * pinctrl_generic_add_group() - adds a new pin group
621 * @pins: pins in the pin group
622 * @num_pins: number of pins in the pin group
628 int *pins, int num_pins, void *data) in pinctrl_generic_add_group() argument
634 return -EINVAL; in pinctrl_generic_add_group()
640 selector = pctldev->num_groups; in pinctrl_generic_add_group()
642 group = devm_kzalloc(pctldev->dev, sizeof(*group), GFP_KERNEL); in pinctrl_generic_add_group()
644 return -ENOMEM; in pinctrl_generic_add_group()
646 group->name = name; in pinctrl_generic_add_group()
647 group->pins = pins; in pinctrl_generic_add_group()
648 group->num_pins = num_pins; in pinctrl_generic_add_group()
649 group->data = data; in pinctrl_generic_add_group()
651 radix_tree_insert(&pctldev->pin_group_tree, selector, group); in pinctrl_generic_add_group()
653 pctldev->num_groups++; in pinctrl_generic_add_group()
660 * pinctrl_generic_remove_group() - removes a numbered pin group
671 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_remove_group()
674 return -ENOENT; in pinctrl_generic_remove_group()
676 radix_tree_delete(&pctldev->pin_group_tree, selector); in pinctrl_generic_remove_group()
677 devm_kfree(pctldev->dev, group); in pinctrl_generic_remove_group()
679 pctldev->num_groups--; in pinctrl_generic_remove_group()
686 * pinctrl_generic_free_groups() - removes all pin groups
690 * are allocated with devm_kzalloc() so no need to free them here.
697 radix_tree_for_each_slot(slot, &pctldev->pin_group_tree, &iter, 0) in pinctrl_generic_free_groups()
698 radix_tree_delete(&pctldev->pin_group_tree, iter.index); in pinctrl_generic_free_groups()
700 pctldev->num_groups = 0; in pinctrl_generic_free_groups()
710 * pinctrl_get_group_selector() - returns the group selector for a group
717 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinctrl_get_group_selector()
718 unsigned ngroups = pctlops->get_groups_count(pctldev); in pinctrl_get_group_selector()
722 const char *gname = pctlops->get_group_name(pctldev, in pinctrl_get_group_selector()
725 dev_dbg(pctldev->dev, in pinctrl_get_group_selector()
735 dev_err(pctldev->dev, "does not have pin group %s\n", in pinctrl_get_group_selector()
738 return -EINVAL; in pinctrl_get_group_selector()
751 * without a backing pin controller - bail out. in pinctrl_gpio_can_use_line()
756 mutex_lock(&pctldev->mutex); in pinctrl_gpio_can_use_line()
763 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_can_use_line()
770 * pinctrl_gpio_request() - request a single pin to be used as GPIO
773 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
775 * shall *NOT* request GPIO pins to be muxed in.
791 mutex_lock(&pctldev->mutex); in pinctrl_gpio_request()
798 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_request()
805 * pinctrl_gpio_free() - free control on a single pin, currently used as GPIO
808 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
810 * shall *NOT* request GPIO pins to be muxed out.
823 mutex_lock(&pctldev->mutex); in pinctrl_gpio_free()
830 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_free()
846 mutex_lock(&pctldev->mutex); in pinctrl_gpio_direction()
852 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_direction()
858 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
861 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
872 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
875 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
886 * pinctrl_gpio_set_config() - Apply config to given GPIO pin
890 * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
905 mutex_lock(&pctldev->mutex); in pinctrl_gpio_set_config()
908 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_set_config()
919 list_for_each_entry(state, &p->states, node) in find_state()
920 if (!strcmp(state->name, name)) in find_state()
933 return ERR_PTR(-ENOMEM); in create_state()
935 state->name = name; in create_state()
936 INIT_LIST_HEAD(&state->settings); in create_state()
938 list_add_tail(&state->node, &p->states); in create_state()
950 state = find_state(p, map->name); in add_setting()
952 state = create_state(p, map->name); in add_setting()
956 if (map->type == PIN_MAP_TYPE_DUMMY_STATE) in add_setting()
961 return -ENOMEM; in add_setting()
963 setting->type = map->type; in add_setting()
966 setting->pctldev = pctldev; in add_setting()
968 setting->pctldev = in add_setting()
969 get_pinctrl_dev_from_devname(map->ctrl_dev_name); in add_setting()
970 if (!setting->pctldev) { in add_setting()
973 if (!strcmp(map->ctrl_dev_name, map->dev_name)) in add_setting()
974 return -ENODEV; in add_setting()
979 dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe", in add_setting()
980 map->ctrl_dev_name); in add_setting()
981 return -EPROBE_DEFER; in add_setting()
984 setting->dev_name = map->dev_name; in add_setting()
986 switch (map->type) { in add_setting()
995 ret = -EINVAL; in add_setting()
1003 list_add_tail(&setting->node, &state->settings); in add_setting()
1014 if (p->dev == dev) { in find_pinctrl()
1042 return ERR_PTR(-ENOMEM); in create_pinctrl()
1043 p->dev = dev; in create_pinctrl()
1044 INIT_LIST_HEAD(&p->states); in create_pinctrl()
1045 INIT_LIST_HEAD(&p->dt_maps); in create_pinctrl()
1059 if (strcmp(map->dev_name, devname)) in create_pinctrl()
1062 * If pctldev is not null, we are claiming hog for it, in create_pinctrl()
1069 strcmp(dev_name(pctldev->dev), map->ctrl_dev_name)) in create_pinctrl()
1076 * - Defer, if the pinctrl device is not yet available in create_pinctrl()
1077 * - Fail, if the pinctrl device is not yet available, in create_pinctrl()
1082 * If the error returned was not -EPROBE_DEFER then we in create_pinctrl()
1084 * an -EPROBE_DEFER later, as that is the worst case. in create_pinctrl()
1086 if (ret == -EPROBE_DEFER) { in create_pinctrl()
1100 kref_init(&p->users); in create_pinctrl()
1104 list_add_tail(&p->node, &pinctrl_list); in create_pinctrl()
1111 * pinctrl_get() - retrieves the pinctrl handle for a device
1119 return ERR_PTR(-EINVAL); in pinctrl_get()
1129 kref_get(&p->users); in pinctrl_get()
1140 switch (setting->type) { in pinctrl_free_setting()
1161 list_for_each_entry_safe(state, n1, &p->states, node) { in pinctrl_free()
1162 list_for_each_entry_safe(setting, n2, &state->settings, node) { in pinctrl_free()
1163 pinctrl_free_setting(state == p->state, setting); in pinctrl_free()
1164 list_del(&setting->node); in pinctrl_free()
1167 list_del(&state->node); in pinctrl_free()
1174 list_del(&p->node); in pinctrl_free()
1180 * pinctrl_release() - release the pinctrl handle
1191 * pinctrl_put() - decrease use count on a previously claimed pinctrl handle
1196 kref_put(&p->users, pinctrl_release); in pinctrl_put()
1201 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
1214 dev_dbg(p->dev, "using pinctrl dummy state (%s)\n", in pinctrl_lookup_state()
1218 state = ERR_PTR(-ENODEV); in pinctrl_lookup_state()
1228 if (pctldev->desc->link_consumers) in pinctrl_link_add()
1229 device_link_add(consumer, pctldev->dev, in pinctrl_link_add()
1235 * pinctrl_commit_state() - select/activate/program a pinctrl state to HW
1242 struct pinctrl_state *old_state = p->state; in pinctrl_commit_state()
1245 if (p->state) { in pinctrl_commit_state()
1248 * of mux owner for that pingroup. Any pingroups which are in pinctrl_commit_state()
1249 * still owned by the new state will be re-acquired by the call in pinctrl_commit_state()
1252 list_for_each_entry(setting, &p->state->settings, node) { in pinctrl_commit_state()
1253 if (setting->type != PIN_MAP_TYPE_MUX_GROUP) in pinctrl_commit_state()
1259 p->state = NULL; in pinctrl_commit_state()
1261 /* Apply all the settings for the new state - pinmux first */ in pinctrl_commit_state()
1262 list_for_each_entry(setting, &state->settings, node) { in pinctrl_commit_state()
1263 switch (setting->type) { in pinctrl_commit_state()
1272 ret = -EINVAL; in pinctrl_commit_state()
1280 if (p != setting->pctldev->p) in pinctrl_commit_state()
1281 pinctrl_link_add(setting->pctldev, p->dev); in pinctrl_commit_state()
1284 /* Apply all the settings for the new state - pinconf after */ in pinctrl_commit_state()
1285 list_for_each_entry(setting, &state->settings, node) { in pinctrl_commit_state()
1286 switch (setting->type) { in pinctrl_commit_state()
1295 ret = -EINVAL; in pinctrl_commit_state()
1304 if (p != setting->pctldev->p) in pinctrl_commit_state()
1305 pinctrl_link_add(setting->pctldev, p->dev); in pinctrl_commit_state()
1308 p->state = state; in pinctrl_commit_state()
1313 dev_err(p->dev, "Error applying setting, reverse things back\n"); in pinctrl_commit_state()
1315 list_for_each_entry(setting2, &state->settings, node) { in pinctrl_commit_state()
1316 if (&setting2->node == &setting->node) in pinctrl_commit_state()
1320 * That means that some pins are muxed differently now in pinctrl_commit_state()
1322 * "unmux a pin"!), but it's not a big deal since the pins in pinctrl_commit_state()
1323 * are free to be muxed by another apply_setting. in pinctrl_commit_state()
1325 if (setting2->type == PIN_MAP_TYPE_MUX_GROUP) in pinctrl_commit_state()
1329 /* There's no infinite recursive loop here because p->state is NULL */ in pinctrl_commit_state()
1337 * pinctrl_select_state() - select/activate/program a pinctrl state to HW
1343 if (p->state == state) in pinctrl_select_state()
1356 * devm_pinctrl_get() - Resource managed pinctrl_get()
1368 return ERR_PTR(-ENOMEM); in devm_pinctrl_get()
1390 * devm_pinctrl_put() - Resource managed pinctrl_put()
1399 WARN_ON(devres_release(p->dev, devm_pinctrl_release, in devm_pinctrl_put()
1405 * pinctrl_register_mappings() - register a set of pin controller mappings
1406 * @maps: the pincontrol mappings table to register. Note the pinctrl-core
1424 return -EINVAL; in pinctrl_register_mappings()
1430 return -EINVAL; in pinctrl_register_mappings()
1437 return -EINVAL; in pinctrl_register_mappings()
1457 return -EINVAL; in pinctrl_register_mappings()
1463 return -ENOMEM; in pinctrl_register_mappings()
1465 maps_node->maps = maps; in pinctrl_register_mappings()
1466 maps_node->num_maps = num_maps; in pinctrl_register_mappings()
1469 list_add_tail(&maps_node->node, &pinctrl_maps); in pinctrl_register_mappings()
1477 * pinctrl_unregister_mappings() - unregister a set of pin controller mappings
1487 if (maps_node->maps == map) { in pinctrl_unregister_mappings()
1488 list_del(&maps_node->node); in pinctrl_unregister_mappings()
1499 * pinctrl_force_sleep() - turn a given controller device into sleep state
1504 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep)) in pinctrl_force_sleep()
1505 return pinctrl_commit_state(pctldev->p, pctldev->hog_sleep); in pinctrl_force_sleep()
1511 * pinctrl_force_default() - turn a given controller device into default state
1516 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default)) in pinctrl_force_default()
1517 return pinctrl_commit_state(pctldev->p, pctldev->hog_default); in pinctrl_force_default()
1523 * pinctrl_init_done() - tell pinctrl probe is done
1525 * We'll use this time to switch the pins from "init" to "default" unless the
1532 struct dev_pin_info *pins = dev->pins; in pinctrl_init_done() local
1535 if (!pins) in pinctrl_init_done()
1538 if (IS_ERR(pins->init_state)) in pinctrl_init_done()
1541 if (pins->p->state != pins->init_state) in pinctrl_init_done()
1544 if (IS_ERR(pins->default_state)) in pinctrl_init_done()
1547 ret = pinctrl_select_state(pins->p, pins->default_state); in pinctrl_init_done()
1557 struct dev_pin_info *pins = dev->pins; in pinctrl_select_bound_state() local
1562 ret = pinctrl_select_state(pins->p, state); in pinctrl_select_bound_state()
1565 state->name); in pinctrl_select_bound_state()
1570 * pinctrl_select_default_state() - select default pinctrl state
1575 if (!dev->pins) in pinctrl_select_default_state()
1578 return pinctrl_select_bound_state(dev, dev->pins->default_state); in pinctrl_select_default_state()
1585 * pinctrl_pm_select_default_state() - select default pinctrl state for PM
1595 * pinctrl_pm_select_sleep_state() - select sleep pinctrl state for PM
1600 if (!dev->pins) in pinctrl_pm_select_sleep_state()
1603 return pinctrl_select_bound_state(dev, dev->pins->sleep_state); in pinctrl_pm_select_sleep_state()
1608 * pinctrl_pm_select_idle_state() - select idle pinctrl state for PM
1613 if (!dev->pins) in pinctrl_pm_select_idle_state()
1616 return pinctrl_select_bound_state(dev, dev->pins->idle_state); in pinctrl_pm_select_idle_state()
1625 struct pinctrl_dev *pctldev = s->private; in pinctrl_pins_show()
1626 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_pins_show()
1634 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); in pinctrl_pins_show()
1636 mutex_lock(&pctldev->mutex); in pinctrl_pins_show()
1639 for (i = 0; i < pctldev->desc->npins; i++) { in pinctrl_pins_show()
1642 pin = pctldev->desc->pins[i].number; in pinctrl_pins_show()
1648 seq_printf(s, "pin %d (%s) ", pin, desc->name); in pinctrl_pins_show()
1651 gpio_num = -1; in pinctrl_pins_show()
1652 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_pins_show()
1653 if ((pin >= range->pin_base) && in pinctrl_pins_show()
1654 (pin < (range->pin_base + range->npins))) { in pinctrl_pins_show()
1655 gpio_num = range->base + (pin - range->pin_base); in pinctrl_pins_show()
1664 seq_printf(s, "%u:%s ", gpio_num - chip->gpiodev->base, chip->label); in pinctrl_pins_show()
1669 /* Driver-specific info per pin */ in pinctrl_pins_show()
1670 if (ops->pin_dbg_show) in pinctrl_pins_show()
1671 ops->pin_dbg_show(pctldev, s, pin); in pinctrl_pins_show()
1676 mutex_unlock(&pctldev->mutex); in pinctrl_pins_show()
1684 struct pinctrl_dev *pctldev = s->private; in pinctrl_groups_show()
1685 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_groups_show()
1688 mutex_lock(&pctldev->mutex); in pinctrl_groups_show()
1690 ngroups = ops->get_groups_count(pctldev); in pinctrl_groups_show()
1694 const unsigned *pins = NULL; in pinctrl_groups_show() local
1696 const char *gname = ops->get_group_name(pctldev, selector); in pinctrl_groups_show()
1701 if (ops->get_group_pins) in pinctrl_groups_show()
1702 ret = ops->get_group_pins(pctldev, selector, in pinctrl_groups_show()
1703 &pins, &num_pins); in pinctrl_groups_show()
1705 seq_printf(s, "%s [ERROR GETTING PINS]\n", in pinctrl_groups_show()
1710 pname = pin_get_name(pctldev, pins[i]); in pinctrl_groups_show()
1712 mutex_unlock(&pctldev->mutex); in pinctrl_groups_show()
1713 return -EINVAL; in pinctrl_groups_show()
1715 seq_printf(s, "pin %d (%s)\n", pins[i], pname); in pinctrl_groups_show()
1722 mutex_unlock(&pctldev->mutex); in pinctrl_groups_show()
1730 struct pinctrl_dev *pctldev = s->private; in pinctrl_gpioranges_show()
1735 mutex_lock(&pctldev->mutex); in pinctrl_gpioranges_show()
1738 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_gpioranges_show()
1739 if (range->pins) { in pinctrl_gpioranges_show()
1741 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS {", in pinctrl_gpioranges_show()
1742 range->id, range->name, in pinctrl_gpioranges_show()
1743 range->base, (range->base + range->npins - 1)); in pinctrl_gpioranges_show()
1744 for (a = 0; a < range->npins - 1; a++) in pinctrl_gpioranges_show()
1745 seq_printf(s, "%u, ", range->pins[a]); in pinctrl_gpioranges_show()
1746 seq_printf(s, "%u}\n", range->pins[a]); in pinctrl_gpioranges_show()
1749 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n", in pinctrl_gpioranges_show()
1750 range->id, range->name, in pinctrl_gpioranges_show()
1751 range->base, (range->base + range->npins - 1), in pinctrl_gpioranges_show()
1752 range->pin_base, in pinctrl_gpioranges_show()
1753 (range->pin_base + range->npins - 1)); in pinctrl_gpioranges_show()
1756 mutex_unlock(&pctldev->mutex); in pinctrl_gpioranges_show()
1771 seq_printf(s, "%s ", pctldev->desc->name); in pinctrl_devices_show()
1772 if (pctldev->desc->pmxops) in pinctrl_devices_show()
1776 if (pctldev->desc->confops) in pinctrl_devices_show()
1816 map->dev_name, map->name, map_type(map->type), in pinctrl_maps_show()
1817 map->type); in pinctrl_maps_show()
1819 if (map->type != PIN_MAP_TYPE_DUMMY_STATE) in pinctrl_maps_show()
1821 map->ctrl_dev_name); in pinctrl_maps_show()
1823 switch (map->type) { in pinctrl_maps_show()
1855 dev_name(p->dev), in pinctrl_show()
1856 p->state ? p->state->name : "none"); in pinctrl_show()
1858 list_for_each_entry(state, &p->states, node) { in pinctrl_show()
1859 seq_printf(s, " state: %s\n", state->name); in pinctrl_show()
1861 list_for_each_entry(setting, &state->settings, node) { in pinctrl_show()
1862 struct pinctrl_dev *pctldev = setting->pctldev; in pinctrl_show()
1865 map_type(setting->type), in pinctrl_show()
1868 switch (setting->type) { in pinctrl_show()
1896 if (pctldev->desc->name && in pinctrl_init_device_debugfs()
1897 strcmp(dev_name(pctldev->dev), pctldev->desc->name)) { in pinctrl_init_device_debugfs()
1898 debugfs_name = devm_kasprintf(pctldev->dev, GFP_KERNEL, in pinctrl_init_device_debugfs()
1899 "%s-%s", dev_name(pctldev->dev), in pinctrl_init_device_debugfs()
1900 pctldev->desc->name); in pinctrl_init_device_debugfs()
1903 dev_name(pctldev->dev)); in pinctrl_init_device_debugfs()
1907 debugfs_name = dev_name(pctldev->dev); in pinctrl_init_device_debugfs()
1911 pctldev->device_root = device_root; in pinctrl_init_device_debugfs()
1915 dev_name(pctldev->dev)); in pinctrl_init_device_debugfs()
1918 debugfs_create_file("pins", 0444, in pinctrl_init_device_debugfs()
1922 debugfs_create_file("gpio-ranges", 0444, in pinctrl_init_device_debugfs()
1924 if (pctldev->desc->pmxops) in pinctrl_init_device_debugfs()
1926 if (pctldev->desc->confops) in pinctrl_init_device_debugfs()
1932 debugfs_remove_recursive(pctldev->device_root); in pinctrl_remove_device_debugfs()
1944 debugfs_create_file("pinctrl-devices", 0444, in pinctrl_init_debugfs()
1946 debugfs_create_file("pinctrl-maps", 0444, in pinctrl_init_debugfs()
1948 debugfs_create_file("pinctrl-handles", 0444, in pinctrl_init_debugfs()
1970 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_check_ops()
1973 !ops->get_groups_count || in pinctrl_check_ops()
1974 !ops->get_group_name) in pinctrl_check_ops()
1975 return -EINVAL; in pinctrl_check_ops()
1981 * pinctrl_init_controller() - init a pin controller device
1994 return ERR_PTR(-EINVAL); in pinctrl_init_controller()
1995 if (!pctldesc->name) in pinctrl_init_controller()
1996 return ERR_PTR(-EINVAL); in pinctrl_init_controller()
2000 return ERR_PTR(-ENOMEM); in pinctrl_init_controller()
2003 pctldev->owner = pctldesc->owner; in pinctrl_init_controller()
2004 pctldev->desc = pctldesc; in pinctrl_init_controller()
2005 pctldev->driver_data = driver_data; in pinctrl_init_controller()
2006 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); in pinctrl_init_controller()
2008 INIT_RADIX_TREE(&pctldev->pin_group_tree, GFP_KERNEL); in pinctrl_init_controller()
2011 INIT_RADIX_TREE(&pctldev->pin_function_tree, GFP_KERNEL); in pinctrl_init_controller()
2013 INIT_LIST_HEAD(&pctldev->gpio_ranges); in pinctrl_init_controller()
2014 INIT_LIST_HEAD(&pctldev->node); in pinctrl_init_controller()
2015 pctldev->dev = dev; in pinctrl_init_controller()
2016 mutex_init(&pctldev->mutex); in pinctrl_init_controller()
2026 if (pctldesc->pmxops) { in pinctrl_init_controller()
2033 if (pctldesc->confops) { in pinctrl_init_controller()
2039 /* Register all the pins */ in pinctrl_init_controller()
2040 dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins); in pinctrl_init_controller()
2041 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins); in pinctrl_init_controller()
2044 pinctrl_free_pindescs(pctldev, pctldesc->pins, in pinctrl_init_controller()
2045 pctldesc->npins); in pinctrl_init_controller()
2052 mutex_destroy(&pctldev->mutex); in pinctrl_init_controller()
2059 pctldev->p = create_pinctrl(pctldev->dev, pctldev); in pinctrl_claim_hogs()
2060 if (PTR_ERR(pctldev->p) == -ENODEV) { in pinctrl_claim_hogs()
2061 dev_dbg(pctldev->dev, "no hogs found\n"); in pinctrl_claim_hogs()
2066 if (IS_ERR(pctldev->p)) { in pinctrl_claim_hogs()
2067 dev_err(pctldev->dev, "error claiming hogs: %li\n", in pinctrl_claim_hogs()
2068 PTR_ERR(pctldev->p)); in pinctrl_claim_hogs()
2070 return PTR_ERR(pctldev->p); in pinctrl_claim_hogs()
2073 pctldev->hog_default = in pinctrl_claim_hogs()
2074 pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT); in pinctrl_claim_hogs()
2075 if (IS_ERR(pctldev->hog_default)) { in pinctrl_claim_hogs()
2076 dev_dbg(pctldev->dev, in pinctrl_claim_hogs()
2079 if (pinctrl_select_state(pctldev->p, in pinctrl_claim_hogs()
2080 pctldev->hog_default)) in pinctrl_claim_hogs()
2081 dev_err(pctldev->dev, in pinctrl_claim_hogs()
2085 pctldev->hog_sleep = in pinctrl_claim_hogs()
2086 pinctrl_lookup_state(pctldev->p, in pinctrl_claim_hogs()
2088 if (IS_ERR(pctldev->hog_sleep)) in pinctrl_claim_hogs()
2089 dev_dbg(pctldev->dev, in pinctrl_claim_hogs()
2101 dev_err(pctldev->dev, "could not claim hogs: %i\n", in pinctrl_enable()
2103 pinctrl_free_pindescs(pctldev, pctldev->desc->pins, in pinctrl_enable()
2104 pctldev->desc->npins); in pinctrl_enable()
2105 mutex_destroy(&pctldev->mutex); in pinctrl_enable()
2112 list_add_tail(&pctldev->node, &pinctrldev_list); in pinctrl_enable()
2122 * pinctrl_register() - register a pin controller device
2128 * controller driver functions are called before the driver has a
2151 * pinctrl_register_and_init() - register and init pin controller device
2183 * pinctrl_unregister() - unregister pinmux
2195 mutex_lock(&pctldev->mutex); in pinctrl_unregister()
2197 mutex_unlock(&pctldev->mutex); in pinctrl_unregister()
2199 if (!IS_ERR_OR_NULL(pctldev->p)) in pinctrl_unregister()
2200 pinctrl_put(pctldev->p); in pinctrl_unregister()
2203 mutex_lock(&pctldev->mutex); in pinctrl_unregister()
2204 /* TODO: check that no pinmuxes are still active? */ in pinctrl_unregister()
2205 list_del(&pctldev->node); in pinctrl_unregister()
2209 pinctrl_free_pindescs(pctldev, pctldev->desc->pins, in pinctrl_unregister()
2210 pctldev->desc->npins); in pinctrl_unregister()
2212 list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) in pinctrl_unregister()
2213 list_del(&range->node); in pinctrl_unregister()
2215 mutex_unlock(&pctldev->mutex); in pinctrl_unregister()
2216 mutex_destroy(&pctldev->mutex); in pinctrl_unregister()
2240 * devm_pinctrl_register() - Resource managed version of pinctrl_register().
2258 return ERR_PTR(-ENOMEM); in devm_pinctrl_register()
2274 * devm_pinctrl_register_and_init() - Resource managed pinctrl register and init
2294 return -ENOMEM; in devm_pinctrl_register_and_init()
2310 * devm_pinctrl_unregister() - Resource managed version of pinctrl_unregister().