Lines Matching +full:their +full:- +full:claim +full:- +full:gpios

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
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()
192 pindesc = radix_tree_lookup(&pctldev->pin_desc_tree, in pinctrl_free_pindescs()
195 radix_tree_delete(&pctldev->pin_desc_tree, in pinctrl_free_pindescs()
197 if (pindesc->dynamic_name) in pinctrl_free_pindescs()
198 kfree(pindesc->name); in pinctrl_free_pindescs()
210 pindesc = pin_desc_get(pctldev, pin->number); in pinctrl_register_one_pin()
212 dev_err(pctldev->dev, "pin %d already registered\n", in pinctrl_register_one_pin()
213 pin->number); in pinctrl_register_one_pin()
214 return -EINVAL; in pinctrl_register_one_pin()
219 return -ENOMEM; in pinctrl_register_one_pin()
222 pindesc->pctldev = pctldev; in pinctrl_register_one_pin()
225 if (pin->name) { in pinctrl_register_one_pin()
226 pindesc->name = pin->name; in pinctrl_register_one_pin()
228 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", pin->number); in pinctrl_register_one_pin()
229 if (!pindesc->name) { in pinctrl_register_one_pin()
230 error = -ENOMEM; in pinctrl_register_one_pin()
233 pindesc->dynamic_name = true; in pinctrl_register_one_pin()
236 pindesc->drv_data = pin->drv_data; in pinctrl_register_one_pin()
238 error = radix_tree_insert(&pctldev->pin_desc_tree, pin->number, pindesc); in pinctrl_register_one_pin()
243 pin->number, pindesc->name, pctldev->desc->name); in pinctrl_register_one_pin()
268 * gpio_to_pin() - GPIO range GPIO number to pin number translation
284 unsigned int pin = gc->base + offset - range->base; in gpio_to_pin()
285 if (range->pins) in gpio_to_pin()
286 return range->pins[pin]; in gpio_to_pin()
288 return range->pin_base + pin; in gpio_to_pin()
292 * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
306 mutex_lock(&pctldev->mutex); in pinctrl_match_gpio_range()
308 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_match_gpio_range()
310 if ((gc->base + offset) >= range->base && in pinctrl_match_gpio_range()
311 (gc->base + offset) < range->base + range->npins) { in pinctrl_match_gpio_range()
312 mutex_unlock(&pctldev->mutex); in pinctrl_match_gpio_range()
316 mutex_unlock(&pctldev->mutex); in pinctrl_match_gpio_range()
321 * pinctrl_ready_for_gpio_range() - check if other GPIO pins of
329 * of the same GPIO chip don't have back-end pinctrl interface.
331 * certain GPIO pin doesn't have back-end pinctrl device. If the return value
346 mutex_lock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
347 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_ready_for_gpio_range()
349 if (range->base + range->npins - 1 < gc->base || in pinctrl_ready_for_gpio_range()
350 range->base > gc->base + gc->ngpio - 1) in pinctrl_ready_for_gpio_range()
352 mutex_unlock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
356 mutex_unlock(&pctldev->mutex); in pinctrl_ready_for_gpio_range()
372 * pinctrl_get_device_gpio_range() - find device for GPIO range
380 * -EPROBE_DEFER if the GPIO range could not be found in any device since it
407 return -EPROBE_DEFER; in pinctrl_get_device_gpio_range()
411 * pinctrl_add_gpio_range() - register a GPIO range for a controller
419 * This adds a range of GPIOs to be handled by a certain pin controller. Call
425 mutex_lock(&pctldev->mutex); in pinctrl_add_gpio_range()
426 list_add_tail(&range->node, &pctldev->gpio_ranges); in pinctrl_add_gpio_range()
427 mutex_unlock(&pctldev->mutex); in pinctrl_add_gpio_range()
455 return ERR_PTR(-EPROBE_DEFER); in pinctrl_find_and_add_gpio_range()
466 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinctrl_get_group_pins()
469 if (!pctlops->get_group_pins) in pinctrl_get_group_pins()
470 return -EINVAL; in pinctrl_get_group_pins()
476 return pctlops->get_group_pins(pctldev, gs, pins, num_pins); in pinctrl_get_group_pins()
487 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_find_gpio_range_from_pin_nolock()
489 if (range->pins) { in pinctrl_find_gpio_range_from_pin_nolock()
491 for (a = 0; a < range->npins; a++) { in pinctrl_find_gpio_range_from_pin_nolock()
492 if (range->pins[a] == pin) in pinctrl_find_gpio_range_from_pin_nolock()
495 } else if (pin >= range->pin_base && in pinctrl_find_gpio_range_from_pin_nolock()
496 pin < range->pin_base + range->npins) in pinctrl_find_gpio_range_from_pin_nolock()
505 * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin
507 * @pin: a controller-local number to find the range for
515 mutex_lock(&pctldev->mutex); in pinctrl_find_gpio_range_from_pin()
517 mutex_unlock(&pctldev->mutex); in pinctrl_find_gpio_range_from_pin()
524 * pinctrl_remove_gpio_range() - remove a range of GPIOs from a pin controller
531 mutex_lock(&pctldev->mutex); in pinctrl_remove_gpio_range()
532 list_del(&range->node); in pinctrl_remove_gpio_range()
533 mutex_unlock(&pctldev->mutex); in pinctrl_remove_gpio_range()
540 * pinctrl_generic_get_group_count() - returns the number of pin groups
545 return pctldev->num_groups; in pinctrl_generic_get_group_count()
550 * pinctrl_generic_get_group_name() - returns the name of a pin group
559 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group_name()
564 return group->grp.name; in pinctrl_generic_get_group_name()
569 * pinctrl_generic_get_group_pins() - gets the pin group pins
582 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group_pins()
585 dev_err(pctldev->dev, "%s could not find pingroup%i\n", in pinctrl_generic_get_group_pins()
587 return -EINVAL; in pinctrl_generic_get_group_pins()
590 *pins = group->grp.pins; in pinctrl_generic_get_group_pins()
591 *num_pins = group->grp.npins; in pinctrl_generic_get_group_pins()
598 * pinctrl_generic_get_group() - returns a pin group based on the number
607 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_get_group()
619 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_generic_group_name_to_selector()
620 int ngroups = ops->get_groups_count(pctldev); in pinctrl_generic_group_name_to_selector()
625 const char *gname = ops->get_group_name(pctldev, selector); in pinctrl_generic_group_name_to_selector()
633 return -EINVAL; in pinctrl_generic_group_name_to_selector()
637 * pinctrl_generic_add_group() - adds a new pin group
653 return -EINVAL; in pinctrl_generic_add_group()
659 selector = pctldev->num_groups; in pinctrl_generic_add_group()
661 group = devm_kzalloc(pctldev->dev, sizeof(*group), GFP_KERNEL); in pinctrl_generic_add_group()
663 return -ENOMEM; in pinctrl_generic_add_group()
667 error = radix_tree_insert(&pctldev->pin_group_tree, selector, group); in pinctrl_generic_add_group()
671 pctldev->num_groups++; in pinctrl_generic_add_group()
678 * pinctrl_generic_remove_group() - removes a numbered pin group
689 group = radix_tree_lookup(&pctldev->pin_group_tree, in pinctrl_generic_remove_group()
692 return -ENOENT; in pinctrl_generic_remove_group()
694 radix_tree_delete(&pctldev->pin_group_tree, selector); in pinctrl_generic_remove_group()
695 devm_kfree(pctldev->dev, group); in pinctrl_generic_remove_group()
697 pctldev->num_groups--; in pinctrl_generic_remove_group()
704 * pinctrl_generic_free_groups() - removes all pin groups
715 radix_tree_for_each_slot(slot, &pctldev->pin_group_tree, &iter, 0) in pinctrl_generic_free_groups()
716 radix_tree_delete(&pctldev->pin_group_tree, iter.index); in pinctrl_generic_free_groups()
718 pctldev->num_groups = 0; in pinctrl_generic_free_groups()
728 * pinctrl_get_group_selector() - returns the group selector for a group
735 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; in pinctrl_get_group_selector()
736 unsigned int ngroups = pctlops->get_groups_count(pctldev); in pinctrl_get_group_selector()
740 const char *gname = pctlops->get_group_name(pctldev, in pinctrl_get_group_selector()
743 dev_dbg(pctldev->dev, in pinctrl_get_group_selector()
753 dev_err(pctldev->dev, "does not have pin group %s\n", in pinctrl_get_group_selector()
756 return -EINVAL; in pinctrl_get_group_selector()
769 * without a backing pin controller - bail out. in pinctrl_gpio_can_use_line()
774 mutex_lock(&pctldev->mutex); in pinctrl_gpio_can_use_line()
781 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_can_use_line()
788 * pinctrl_gpio_request() - request a single pin to be used as GPIO
792 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
793 * as part of their gpio_request() semantics, platforms and individual drivers
809 mutex_lock(&pctldev->mutex); in pinctrl_gpio_request()
814 ret = pinmux_request_gpio(pctldev, range, pin, gc->base + offset); in pinctrl_gpio_request()
816 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_request()
823 * pinctrl_gpio_free() - free control on a single pin, currently used as GPIO
827 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
828 * as part of their gpio_request() semantics, platforms and individual drivers
841 mutex_lock(&pctldev->mutex); in pinctrl_gpio_free()
848 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_free()
865 mutex_lock(&pctldev->mutex); in pinctrl_gpio_direction()
871 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_direction()
877 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
881 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
882 * as part of their gpio_direction_input() semantics, platforms and individual
892 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
896 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
897 * as part of their gpio_direction_output() semantics, platforms and individual
907 * pinctrl_gpio_set_config() - Apply config to given GPIO pin
912 * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
928 mutex_lock(&pctldev->mutex); in pinctrl_gpio_set_config()
931 mutex_unlock(&pctldev->mutex); in pinctrl_gpio_set_config()
942 list_for_each_entry(state, &p->states, node) in find_state()
943 if (!strcmp(state->name, name)) in find_state()
956 return ERR_PTR(-ENOMEM); in create_state()
958 state->name = name; in create_state()
959 INIT_LIST_HEAD(&state->settings); in create_state()
961 list_add_tail(&state->node, &p->states); in create_state()
973 state = find_state(p, map->name); in add_setting()
975 state = create_state(p, map->name); in add_setting()
979 if (map->type == PIN_MAP_TYPE_DUMMY_STATE) in add_setting()
984 return -ENOMEM; in add_setting()
986 setting->type = map->type; in add_setting()
989 setting->pctldev = pctldev; in add_setting()
991 setting->pctldev = in add_setting()
992 get_pinctrl_dev_from_devname(map->ctrl_dev_name); in add_setting()
993 if (!setting->pctldev) { in add_setting()
996 if (!strcmp(map->ctrl_dev_name, map->dev_name)) in add_setting()
997 return -ENODEV; in add_setting()
1002 dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe", in add_setting()
1003 map->ctrl_dev_name); in add_setting()
1004 return -EPROBE_DEFER; in add_setting()
1007 setting->dev_name = map->dev_name; in add_setting()
1009 switch (map->type) { in add_setting()
1018 ret = -EINVAL; in add_setting()
1026 list_add_tail(&setting->node, &state->settings); in add_setting()
1037 if (p->dev == dev) { in find_pinctrl()
1064 return ERR_PTR(-ENOMEM); in create_pinctrl()
1065 p->dev = dev; in create_pinctrl()
1066 INIT_LIST_HEAD(&p->states); in create_pinctrl()
1067 INIT_LIST_HEAD(&p->dt_maps); in create_pinctrl()
1081 if (strcmp(map->dev_name, devname)) in create_pinctrl()
1091 strcmp(dev_name(pctldev->dev), map->ctrl_dev_name)) in create_pinctrl()
1098 * - Defer, if the pinctrl device is not yet available in create_pinctrl()
1099 * - Fail, if the pinctrl device is not yet available, in create_pinctrl()
1104 * If the error returned was not -EPROBE_DEFER then we in create_pinctrl()
1106 * an -EPROBE_DEFER later, as that is the worst case. in create_pinctrl()
1108 if (ret == -EPROBE_DEFER) { in create_pinctrl()
1122 kref_init(&p->users); in create_pinctrl()
1126 list_add_tail(&p->node, &pinctrl_list); in create_pinctrl()
1133 * pinctrl_get() - retrieves the pinctrl handle for a device
1141 return ERR_PTR(-EINVAL); in pinctrl_get()
1151 kref_get(&p->users); in pinctrl_get()
1162 switch (setting->type) { in pinctrl_free_setting()
1183 list_for_each_entry_safe(state, n1, &p->states, node) { in pinctrl_free()
1184 list_for_each_entry_safe(setting, n2, &state->settings, node) { in pinctrl_free()
1185 pinctrl_free_setting(state == p->state, setting); in pinctrl_free()
1186 list_del(&setting->node); in pinctrl_free()
1189 list_del(&state->node); in pinctrl_free()
1196 list_del(&p->node); in pinctrl_free()
1202 * pinctrl_release() - release the pinctrl handle
1213 * pinctrl_put() - decrease use count on a previously claimed pinctrl handle
1218 kref_put(&p->users, pinctrl_release); in pinctrl_put()
1223 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
1236 dev_dbg(p->dev, "using pinctrl dummy state (%s)\n", in pinctrl_lookup_state()
1240 state = ERR_PTR(-ENODEV); in pinctrl_lookup_state()
1250 if (pctldev->desc->link_consumers) in pinctrl_link_add()
1251 device_link_add(consumer, pctldev->dev, in pinctrl_link_add()
1257 * pinctrl_commit_state() - select/activate/program a pinctrl state to HW
1264 struct pinctrl_state *old_state = READ_ONCE(p->state); in pinctrl_commit_state()
1271 * still owned by the new state will be re-acquired by the call in pinctrl_commit_state()
1274 list_for_each_entry(setting, &old_state->settings, node) { in pinctrl_commit_state()
1275 if (setting->type != PIN_MAP_TYPE_MUX_GROUP) in pinctrl_commit_state()
1281 p->state = NULL; in pinctrl_commit_state()
1283 /* Apply all the settings for the new state - pinmux first */ in pinctrl_commit_state()
1284 list_for_each_entry(setting, &state->settings, node) { in pinctrl_commit_state()
1285 switch (setting->type) { in pinctrl_commit_state()
1294 ret = -EINVAL; in pinctrl_commit_state()
1302 if (p != setting->pctldev->p) in pinctrl_commit_state()
1303 pinctrl_link_add(setting->pctldev, p->dev); in pinctrl_commit_state()
1306 /* Apply all the settings for the new state - pinconf after */ in pinctrl_commit_state()
1307 list_for_each_entry(setting, &state->settings, node) { in pinctrl_commit_state()
1308 switch (setting->type) { in pinctrl_commit_state()
1317 ret = -EINVAL; in pinctrl_commit_state()
1326 if (p != setting->pctldev->p) in pinctrl_commit_state()
1327 pinctrl_link_add(setting->pctldev, p->dev); in pinctrl_commit_state()
1330 p->state = state; in pinctrl_commit_state()
1335 dev_err(p->dev, "Error applying setting, reverse things back\n"); in pinctrl_commit_state()
1337 list_for_each_entry(setting2, &state->settings, node) { in pinctrl_commit_state()
1338 if (&setting2->node == &setting->node) in pinctrl_commit_state()
1347 if (setting2->type == PIN_MAP_TYPE_MUX_GROUP) in pinctrl_commit_state()
1351 /* There's no infinite recursive loop here because p->state is NULL */ in pinctrl_commit_state()
1359 * pinctrl_select_state() - select/activate/program a pinctrl state to HW
1365 if (p->state == state) in pinctrl_select_state()
1378 * devm_pinctrl_get() - Resource managed pinctrl_get()
1390 return ERR_PTR(-ENOMEM); in devm_pinctrl_get()
1412 * devm_pinctrl_put() - Resource managed pinctrl_put()
1421 WARN_ON(devres_release(p->dev, devm_pinctrl_release, in devm_pinctrl_put()
1427 * pinctrl_register_mappings() - register a set of pin controller mappings
1428 * @maps: the pincontrol mappings table to register. Note the pinctrl-core
1446 return -EINVAL; in pinctrl_register_mappings()
1452 return -EINVAL; in pinctrl_register_mappings()
1459 return -EINVAL; in pinctrl_register_mappings()
1479 return -EINVAL; in pinctrl_register_mappings()
1485 return -ENOMEM; in pinctrl_register_mappings()
1487 maps_node->maps = maps; in pinctrl_register_mappings()
1488 maps_node->num_maps = num_maps; in pinctrl_register_mappings()
1491 list_add_tail(&maps_node->node, &pinctrl_maps); in pinctrl_register_mappings()
1499 * pinctrl_unregister_mappings() - unregister a set of pin controller mappings
1509 if (maps_node->maps == map) { in pinctrl_unregister_mappings()
1510 list_del(&maps_node->node); in pinctrl_unregister_mappings()
1521 * pinctrl_force_sleep() - turn a given controller device into sleep state
1526 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep)) in pinctrl_force_sleep()
1527 return pinctrl_commit_state(pctldev->p, pctldev->hog_sleep); in pinctrl_force_sleep()
1533 * pinctrl_force_default() - turn a given controller device into default state
1538 if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default)) in pinctrl_force_default()
1539 return pinctrl_commit_state(pctldev->p, pctldev->hog_default); in pinctrl_force_default()
1545 * pinctrl_init_done() - tell pinctrl probe is done
1554 struct dev_pin_info *pins = dev->pins; in pinctrl_init_done()
1560 if (IS_ERR(pins->init_state)) in pinctrl_init_done()
1563 if (pins->p->state != pins->init_state) in pinctrl_init_done()
1566 if (IS_ERR(pins->default_state)) in pinctrl_init_done()
1569 ret = pinctrl_select_state(pins->p, pins->default_state); in pinctrl_init_done()
1579 struct dev_pin_info *pins = dev->pins; in pinctrl_select_bound_state()
1584 ret = pinctrl_select_state(pins->p, state); in pinctrl_select_bound_state()
1587 state->name); in pinctrl_select_bound_state()
1592 * pinctrl_select_default_state() - select default pinctrl state
1597 if (!dev->pins) in pinctrl_select_default_state()
1600 return pinctrl_select_bound_state(dev, dev->pins->default_state); in pinctrl_select_default_state()
1607 * pinctrl_pm_select_default_state() - select default pinctrl state for PM
1617 * pinctrl_pm_select_sleep_state() - select sleep pinctrl state for PM
1622 if (!dev->pins) in pinctrl_pm_select_sleep_state()
1625 return pinctrl_select_bound_state(dev, dev->pins->sleep_state); in pinctrl_pm_select_sleep_state()
1630 * pinctrl_pm_select_idle_state() - select idle pinctrl state for PM
1635 if (!dev->pins) in pinctrl_pm_select_idle_state()
1638 return pinctrl_select_bound_state(dev, dev->pins->idle_state); in pinctrl_pm_select_idle_state()
1647 struct pinctrl_dev *pctldev = s->private; in pinctrl_pins_show()
1648 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_pins_show()
1656 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); in pinctrl_pins_show()
1658 mutex_lock(&pctldev->mutex); in pinctrl_pins_show()
1661 for (i = 0; i < pctldev->desc->npins; i++) { in pinctrl_pins_show()
1664 pin = pctldev->desc->pins[i].number; in pinctrl_pins_show()
1670 seq_printf(s, "pin %d (%s) ", pin, desc->name); in pinctrl_pins_show()
1674 gpio_num = -1; in pinctrl_pins_show()
1675 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_pins_show()
1676 if (range->pins != NULL) { in pinctrl_pins_show()
1677 for (int i = 0; i < range->npins; ++i) { in pinctrl_pins_show()
1678 if (range->pins[i] == pin) { in pinctrl_pins_show()
1679 gpio_num = range->base + i; in pinctrl_pins_show()
1683 } else if ((pin >= range->pin_base) && in pinctrl_pins_show()
1684 (pin < (range->pin_base + range->npins))) { in pinctrl_pins_show()
1686 range->base + (pin - range->pin_base); in pinctrl_pins_show()
1688 if (gpio_num != -1) in pinctrl_pins_show()
1694 * we need to get rid of the range->base eventually and in pinctrl_pins_show()
1700 gpio_num - gpio_device_get_base(gdev), in pinctrl_pins_show()
1706 /* Driver-specific info per pin */ in pinctrl_pins_show()
1707 if (ops->pin_dbg_show) in pinctrl_pins_show()
1708 ops->pin_dbg_show(pctldev, s, pin); in pinctrl_pins_show()
1713 mutex_unlock(&pctldev->mutex); in pinctrl_pins_show()
1721 struct pinctrl_dev *pctldev = s->private; in pinctrl_groups_show()
1722 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_groups_show()
1725 mutex_lock(&pctldev->mutex); in pinctrl_groups_show()
1727 ngroups = ops->get_groups_count(pctldev); in pinctrl_groups_show()
1733 const char *gname = ops->get_group_name(pctldev, selector); in pinctrl_groups_show()
1738 if (ops->get_group_pins) in pinctrl_groups_show()
1739 ret = ops->get_group_pins(pctldev, selector, in pinctrl_groups_show()
1749 mutex_unlock(&pctldev->mutex); in pinctrl_groups_show()
1750 return -EINVAL; in pinctrl_groups_show()
1759 mutex_unlock(&pctldev->mutex); in pinctrl_groups_show()
1767 struct pinctrl_dev *pctldev = s->private; in pinctrl_gpioranges_show()
1772 mutex_lock(&pctldev->mutex); in pinctrl_gpioranges_show()
1775 list_for_each_entry(range, &pctldev->gpio_ranges, node) { in pinctrl_gpioranges_show()
1776 if (range->pins) { in pinctrl_gpioranges_show()
1778 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS {", in pinctrl_gpioranges_show()
1779 range->id, range->name, in pinctrl_gpioranges_show()
1780 range->base, (range->base + range->npins - 1)); in pinctrl_gpioranges_show()
1781 for (a = 0; a < range->npins - 1; a++) in pinctrl_gpioranges_show()
1782 seq_printf(s, "%u, ", range->pins[a]); in pinctrl_gpioranges_show()
1783 seq_printf(s, "%u}\n", range->pins[a]); in pinctrl_gpioranges_show()
1786 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n", in pinctrl_gpioranges_show()
1787 range->id, range->name, in pinctrl_gpioranges_show()
1788 range->base, (range->base + range->npins - 1), in pinctrl_gpioranges_show()
1789 range->pin_base, in pinctrl_gpioranges_show()
1790 (range->pin_base + range->npins - 1)); in pinctrl_gpioranges_show()
1793 mutex_unlock(&pctldev->mutex); in pinctrl_gpioranges_show()
1808 seq_printf(s, "%s ", pctldev->desc->name); in pinctrl_devices_show()
1809 if (pctldev->desc->pmxops) in pinctrl_devices_show()
1813 if (pctldev->desc->confops) in pinctrl_devices_show()
1852 map->dev_name, map->name, map_type(map->type), in pinctrl_maps_show()
1853 map->type); in pinctrl_maps_show()
1855 if (map->type != PIN_MAP_TYPE_DUMMY_STATE) in pinctrl_maps_show()
1857 map->ctrl_dev_name); in pinctrl_maps_show()
1859 switch (map->type) { in pinctrl_maps_show()
1885 seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); in pinctrl_show()
1891 dev_name(p->dev), in pinctrl_show()
1892 p->state ? p->state->name : "none"); in pinctrl_show()
1894 list_for_each_entry(state, &p->states, node) { in pinctrl_show()
1895 seq_printf(s, " state: %s\n", state->name); in pinctrl_show()
1897 list_for_each_entry(setting, &state->settings, node) { in pinctrl_show()
1898 struct pinctrl_dev *pctldev = setting->pctldev; in pinctrl_show()
1901 map_type(setting->type), in pinctrl_show()
1904 switch (setting->type) { in pinctrl_show()
1932 if (pctldev->desc->name && in pinctrl_init_device_debugfs()
1933 strcmp(dev_name(pctldev->dev), pctldev->desc->name)) { in pinctrl_init_device_debugfs()
1934 debugfs_name = devm_kasprintf(pctldev->dev, GFP_KERNEL, in pinctrl_init_device_debugfs()
1935 "%s-%s", dev_name(pctldev->dev), in pinctrl_init_device_debugfs()
1936 pctldev->desc->name); in pinctrl_init_device_debugfs()
1939 dev_name(pctldev->dev)); in pinctrl_init_device_debugfs()
1943 debugfs_name = dev_name(pctldev->dev); in pinctrl_init_device_debugfs()
1947 pctldev->device_root = device_root; in pinctrl_init_device_debugfs()
1951 dev_name(pctldev->dev)); in pinctrl_init_device_debugfs()
1958 debugfs_create_file("gpio-ranges", 0444, in pinctrl_init_device_debugfs()
1960 if (pctldev->desc->pmxops) in pinctrl_init_device_debugfs()
1962 if (pctldev->desc->confops) in pinctrl_init_device_debugfs()
1968 debugfs_remove_recursive(pctldev->device_root); in pinctrl_remove_device_debugfs()
1980 debugfs_create_file("pinctrl-devices", 0444, in pinctrl_init_debugfs()
1982 debugfs_create_file("pinctrl-maps", 0444, in pinctrl_init_debugfs()
1984 debugfs_create_file("pinctrl-handles", 0444, in pinctrl_init_debugfs()
2006 const struct pinctrl_ops *ops = pctldev->desc->pctlops; in pinctrl_check_ops()
2009 !ops->get_groups_count || in pinctrl_check_ops()
2010 !ops->get_group_name) in pinctrl_check_ops()
2011 return -EINVAL; in pinctrl_check_ops()
2017 * pinctrl_init_controller() - init a pin controller device
2030 return ERR_PTR(-EINVAL); in pinctrl_init_controller()
2031 if (!pctldesc->name) in pinctrl_init_controller()
2032 return ERR_PTR(-EINVAL); in pinctrl_init_controller()
2036 return ERR_PTR(-ENOMEM); in pinctrl_init_controller()
2039 pctldev->owner = pctldesc->owner; in pinctrl_init_controller()
2040 pctldev->desc = pctldesc; in pinctrl_init_controller()
2041 pctldev->driver_data = driver_data; in pinctrl_init_controller()
2042 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); in pinctrl_init_controller()
2044 INIT_RADIX_TREE(&pctldev->pin_group_tree, GFP_KERNEL); in pinctrl_init_controller()
2047 INIT_RADIX_TREE(&pctldev->pin_function_tree, GFP_KERNEL); in pinctrl_init_controller()
2049 INIT_LIST_HEAD(&pctldev->gpio_ranges); in pinctrl_init_controller()
2050 INIT_LIST_HEAD(&pctldev->node); in pinctrl_init_controller()
2051 pctldev->dev = dev; in pinctrl_init_controller()
2052 mutex_init(&pctldev->mutex); in pinctrl_init_controller()
2062 if (pctldesc->pmxops) { in pinctrl_init_controller()
2069 if (pctldesc->confops) { in pinctrl_init_controller()
2076 dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins); in pinctrl_init_controller()
2077 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins); in pinctrl_init_controller()
2080 pinctrl_free_pindescs(pctldev, pctldesc->pins, in pinctrl_init_controller()
2081 pctldesc->npins); in pinctrl_init_controller()
2088 mutex_destroy(&pctldev->mutex); in pinctrl_init_controller()
2095 pinctrl_free_pindescs(pctldev, pctldesc->pins, in pinctrl_uninit_controller()
2096 pctldesc->npins); in pinctrl_uninit_controller()
2097 mutex_destroy(&pctldev->mutex); in pinctrl_uninit_controller()
2103 pctldev->p = create_pinctrl(pctldev->dev, pctldev); in pinctrl_claim_hogs()
2104 if (PTR_ERR(pctldev->p) == -ENODEV) { in pinctrl_claim_hogs()
2105 dev_dbg(pctldev->dev, "no hogs found\n"); in pinctrl_claim_hogs()
2110 if (IS_ERR(pctldev->p)) { in pinctrl_claim_hogs()
2111 dev_err(pctldev->dev, "error claiming hogs: %li\n", in pinctrl_claim_hogs()
2112 PTR_ERR(pctldev->p)); in pinctrl_claim_hogs()
2114 return PTR_ERR(pctldev->p); in pinctrl_claim_hogs()
2117 pctldev->hog_default = in pinctrl_claim_hogs()
2118 pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT); in pinctrl_claim_hogs()
2119 if (IS_ERR(pctldev->hog_default)) { in pinctrl_claim_hogs()
2120 dev_dbg(pctldev->dev, in pinctrl_claim_hogs()
2123 if (pinctrl_select_state(pctldev->p, in pinctrl_claim_hogs()
2124 pctldev->hog_default)) in pinctrl_claim_hogs()
2125 dev_err(pctldev->dev, in pinctrl_claim_hogs()
2129 pctldev->hog_sleep = in pinctrl_claim_hogs()
2130 pinctrl_lookup_state(pctldev->p, in pinctrl_claim_hogs()
2132 if (IS_ERR(pctldev->hog_sleep)) in pinctrl_claim_hogs()
2133 dev_dbg(pctldev->dev, in pinctrl_claim_hogs()
2145 dev_err(pctldev->dev, "could not claim hogs: %i\n", error); in pinctrl_enable()
2150 list_add_tail(&pctldev->node, &pinctrldev_list); in pinctrl_enable()
2160 * pinctrl_register() - register a pin controller device
2191 * pinctrl_register_and_init() - register and init pin controller device
2223 * pinctrl_unregister() - unregister pinmux
2235 mutex_lock(&pctldev->mutex); in pinctrl_unregister()
2237 mutex_unlock(&pctldev->mutex); in pinctrl_unregister()
2239 if (!IS_ERR_OR_NULL(pctldev->p)) in pinctrl_unregister()
2240 pinctrl_put(pctldev->p); in pinctrl_unregister()
2243 mutex_lock(&pctldev->mutex); in pinctrl_unregister()
2245 list_del(&pctldev->node); in pinctrl_unregister()
2249 pinctrl_free_pindescs(pctldev, pctldev->desc->pins, in pinctrl_unregister()
2250 pctldev->desc->npins); in pinctrl_unregister()
2252 list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) in pinctrl_unregister()
2253 list_del(&range->node); in pinctrl_unregister()
2255 mutex_unlock(&pctldev->mutex); in pinctrl_unregister()
2256 mutex_destroy(&pctldev->mutex); in pinctrl_unregister()
2280 * devm_pinctrl_register() - Resource managed version of pinctrl_register().
2298 return ERR_PTR(-ENOMEM); in devm_pinctrl_register()
2314 * devm_pinctrl_register_and_init() - Resource managed pinctrl register and init
2334 return -ENOMEM; in devm_pinctrl_register_and_init()
2350 * devm_pinctrl_unregister() - Resource managed version of pinctrl_unregister().