Lines Matching +full:de +full:- +full:asserted
1 // SPDX-License-Identifier: GPL-2.0-or-later
16 #include <linux/reset-controller.h>
26 * struct reset_control - a reset control
54 * struct reset_control_array - an array of reset controls
67 if (rcdev->dev) in rcdev_name()
68 return dev_name(rcdev->dev); in rcdev_name()
70 if (rcdev->of_node) in rcdev_name()
71 return rcdev->of_node->full_name; in rcdev_name()
77 * of_reset_simple_xlate - translate reset_spec to the reset line number
89 if (reset_spec->args[0] >= rcdev->nr_resets) in of_reset_simple_xlate()
90 return -EINVAL; in of_reset_simple_xlate()
92 return reset_spec->args[0]; in of_reset_simple_xlate()
96 * reset_controller_register - register a reset controller device
101 if (!rcdev->of_xlate) { in reset_controller_register()
102 rcdev->of_reset_n_cells = 1; in reset_controller_register()
103 rcdev->of_xlate = of_reset_simple_xlate; in reset_controller_register()
106 INIT_LIST_HEAD(&rcdev->reset_control_head); in reset_controller_register()
109 list_add(&rcdev->list, &reset_controller_list); in reset_controller_register()
117 * reset_controller_unregister - unregister a reset controller device
123 list_del(&rcdev->list); in reset_controller_unregister()
134 * devm_reset_controller_register - resource managed reset_controller_register()
151 return -ENOMEM; in devm_reset_controller_register()
167 * reset_controller_add_lookup - register a set of lookup entries
181 if (!entry->dev_id || !entry->provider) { in reset_controller_add_lookup()
187 list_add_tail(&entry->list, &reset_lookup_list); in reset_controller_add_lookup()
202 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_reset()
203 ret = reset_control_reset(resets->rstc[i]); in reset_control_array_reset()
216 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_rearm()
217 rstc = resets->rstc[i]; in reset_control_array_rearm()
223 return -EINVAL; in reset_control_array_rearm()
225 if (rstc->shared) { in reset_control_array_rearm()
226 if (WARN_ON(atomic_read(&rstc->deassert_count) != 0)) in reset_control_array_rearm()
227 return -EINVAL; in reset_control_array_rearm()
229 if (!rstc->acquired) in reset_control_array_rearm()
230 return -EPERM; in reset_control_array_rearm()
234 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_rearm()
235 rstc = resets->rstc[i]; in reset_control_array_rearm()
237 if (rstc && rstc->shared) in reset_control_array_rearm()
238 WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0); in reset_control_array_rearm()
248 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_assert()
249 ret = reset_control_assert(resets->rstc[i]); in reset_control_array_assert()
257 while (i--) in reset_control_array_assert()
258 reset_control_deassert(resets->rstc[i]); in reset_control_array_assert()
266 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_deassert()
267 ret = reset_control_deassert(resets->rstc[i]); in reset_control_array_deassert()
275 while (i--) in reset_control_array_deassert()
276 reset_control_assert(resets->rstc[i]); in reset_control_array_deassert()
285 for (i = 0; i < resets->num_rstcs; i++) { in reset_control_array_acquire()
286 err = reset_control_acquire(resets->rstc[i]); in reset_control_array_acquire()
294 while (i--) in reset_control_array_acquire()
295 reset_control_release(resets->rstc[i]); in reset_control_array_acquire()
304 for (i = 0; i < resets->num_rstcs; i++) in reset_control_array_release()
305 reset_control_release(resets->rstc[i]); in reset_control_array_release()
310 return rstc->array; in reset_control_is_array()
314 * reset_control_reset - reset the controlled device
319 * a no-op.
320 * Consumers must not use reset_control_(de)assert on shared reset lines when
334 return -EINVAL; in reset_control_reset()
339 if (!rstc->rcdev->ops->reset) in reset_control_reset()
340 return -ENOTSUPP; in reset_control_reset()
342 if (rstc->shared) { in reset_control_reset()
343 if (WARN_ON(atomic_read(&rstc->deassert_count) != 0)) in reset_control_reset()
344 return -EINVAL; in reset_control_reset()
346 if (atomic_inc_return(&rstc->triggered_count) != 1) in reset_control_reset()
349 if (!rstc->acquired) in reset_control_reset()
350 return -EPERM; in reset_control_reset()
353 ret = rstc->rcdev->ops->reset(rstc->rcdev, rstc->id); in reset_control_reset()
354 if (rstc->shared && ret) in reset_control_reset()
355 atomic_dec(&rstc->triggered_count); in reset_control_reset()
362 * reset_control_bulk_reset - reset the controlled devices in order
386 * reset_control_rearm - allow shared reset line to be re-triggered"
395 * Consumers must not use reset_control_(de)assert on shared reset lines when
406 return -EINVAL; in reset_control_rearm()
411 if (rstc->shared) { in reset_control_rearm()
412 if (WARN_ON(atomic_read(&rstc->deassert_count) != 0)) in reset_control_rearm()
413 return -EINVAL; in reset_control_rearm()
415 WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0); in reset_control_rearm()
417 if (!rstc->acquired) in reset_control_rearm()
418 return -EPERM; in reset_control_rearm()
426 * reset_control_assert - asserts the reset line
430 * will be asserted. When called on a shared reset controller the line may
436 * reset_control_(de)assert has been used.
447 return -EINVAL; in reset_control_assert()
452 if (rstc->shared) { in reset_control_assert()
453 if (WARN_ON(atomic_read(&rstc->triggered_count) != 0)) in reset_control_assert()
454 return -EINVAL; in reset_control_assert()
456 if (WARN_ON(atomic_read(&rstc->deassert_count) == 0)) in reset_control_assert()
457 return -EINVAL; in reset_control_assert()
459 if (atomic_dec_return(&rstc->deassert_count) != 0) in reset_control_assert()
466 if (!rstc->rcdev->ops->assert) in reset_control_assert()
471 * is no way to guarantee that the reset line is asserted after in reset_control_assert()
474 if (!rstc->rcdev->ops->assert) in reset_control_assert()
475 return -ENOTSUPP; in reset_control_assert()
477 if (!rstc->acquired) { in reset_control_assert()
479 rcdev_name(rstc->rcdev), rstc->id); in reset_control_assert()
480 return -EPERM; in reset_control_assert()
484 return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id); in reset_control_assert()
489 * reset_control_bulk_assert - asserts the reset lines in order
494 * If an assertion fails, already asserted resets are deasserted again.
512 while (i--) in reset_control_bulk_assert()
519 * reset_control_deassert - deasserts the reset line
524 * reset_control_(de)assert has been used.
535 return -EINVAL; in reset_control_deassert()
540 if (rstc->shared) { in reset_control_deassert()
541 if (WARN_ON(atomic_read(&rstc->triggered_count) != 0)) in reset_control_deassert()
542 return -EINVAL; in reset_control_deassert()
544 if (atomic_inc_return(&rstc->deassert_count) != 1) in reset_control_deassert()
547 if (!rstc->acquired) { in reset_control_deassert()
549 rcdev_name(rstc->rcdev), rstc->id); in reset_control_deassert()
550 return -EPERM; in reset_control_deassert()
556 * that it handles self-deasserting reset lines via .reset(). In that in reset_control_deassert()
559 * return -ENOTSUPP. in reset_control_deassert()
561 if (!rstc->rcdev->ops->deassert) in reset_control_deassert()
564 return rstc->rcdev->ops->deassert(rstc->rcdev, rstc->id); in reset_control_deassert()
569 * reset_control_bulk_deassert - deasserts the reset lines in reverse order
574 * If a deassertion fails, already deasserted resets are asserted again.
583 for (i = num_rstcs - 1; i >= 0; i--) { in reset_control_bulk_deassert()
599 * reset_control_status - returns a negative errno if not supported, a
600 * positive value if the reset line is asserted, or zero if the reset
601 * line is not asserted or if the desc is NULL (optional reset).
610 return -EINVAL; in reset_control_status()
612 if (rstc->rcdev->ops->status) in reset_control_status()
613 return rstc->rcdev->ops->status(rstc->rcdev, rstc->id); in reset_control_status()
615 return -ENOTSUPP; in reset_control_status()
620 * reset_control_acquire() - acquires a reset control for exclusive use
647 return -EINVAL; in reset_control_acquire()
654 if (rstc->acquired) { in reset_control_acquire()
659 list_for_each_entry(rc, &rstc->rcdev->reset_control_head, list) { in reset_control_acquire()
660 if (rstc != rc && rstc->id == rc->id) { in reset_control_acquire()
661 if (rc->acquired) { in reset_control_acquire()
663 return -EBUSY; in reset_control_acquire()
668 rstc->acquired = true; in reset_control_acquire()
676 * reset_control_bulk_acquire - acquires reset controls for exclusive use
699 while (i--) in reset_control_bulk_acquire()
706 * reset_control_release() - releases exclusive access to a reset control
723 rstc->acquired = false; in reset_control_release()
728 * reset_control_bulk_release() - releases exclusive access to reset controls
755 list_for_each_entry(rstc, &rcdev->reset_control_head, list) { in __reset_control_get_internal()
756 if (rstc->id == index) { in __reset_control_get_internal()
762 if (!rstc->shared && !shared && !acquired) in __reset_control_get_internal()
765 if (WARN_ON(!rstc->shared || !shared)) in __reset_control_get_internal()
766 return ERR_PTR(-EBUSY); in __reset_control_get_internal()
768 kref_get(&rstc->refcnt); in __reset_control_get_internal()
775 return ERR_PTR(-ENOMEM); in __reset_control_get_internal()
777 if (!try_module_get(rcdev->owner)) { in __reset_control_get_internal()
779 return ERR_PTR(-ENODEV); in __reset_control_get_internal()
782 rstc->rcdev = rcdev; in __reset_control_get_internal()
783 list_add(&rstc->list, &rcdev->reset_control_head); in __reset_control_get_internal()
784 rstc->id = index; in __reset_control_get_internal()
785 kref_init(&rstc->refcnt); in __reset_control_get_internal()
786 rstc->acquired = acquired; in __reset_control_get_internal()
787 rstc->shared = shared; in __reset_control_get_internal()
799 module_put(rstc->rcdev->owner); in __reset_control_release()
801 list_del(&rstc->list); in __reset_control_release()
809 kref_put(&rstc->refcnt, __reset_control_release); in __reset_control_put_internal()
823 return ERR_PTR(-EINVAL); in __of_reset_control_get()
827 "reset-names", id); in __of_reset_control_get()
828 if (index == -EILSEQ) in __of_reset_control_get()
831 return optional ? NULL : ERR_PTR(-ENOENT); in __of_reset_control_get()
834 ret = of_parse_phandle_with_args(node, "resets", "#reset-cells", in __of_reset_control_get()
836 if (ret == -EINVAL) in __of_reset_control_get()
844 if (args.np == r->of_node) { in __of_reset_control_get()
851 rstc = ERR_PTR(-EPROBE_DEFER); in __of_reset_control_get()
855 if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { in __of_reset_control_get()
856 rstc = ERR_PTR(-EINVAL); in __of_reset_control_get()
860 rstc_id = rcdev->of_xlate(rcdev, &args); in __of_reset_control_get()
885 if (!rcdev->dev) in __reset_controller_by_name()
888 if (!strcmp(name, dev_name(rcdev->dev))) in __reset_controller_by_name()
907 if (strcmp(lookup->dev_id, dev_id)) in __reset_control_get_from_lookup()
910 if ((!con_id && !lookup->con_id) || in __reset_control_get_from_lookup()
911 ((con_id && lookup->con_id) && in __reset_control_get_from_lookup()
912 !strcmp(con_id, lookup->con_id))) { in __reset_control_get_from_lookup()
914 rcdev = __reset_controller_by_name(lookup->provider); in __reset_control_get_from_lookup()
919 return ERR_PTR(-EPROBE_DEFER); in __reset_control_get_from_lookup()
923 lookup->index, in __reset_control_get_from_lookup()
933 return optional ? NULL : ERR_PTR(-ENOENT); in __reset_control_get_from_lookup()
943 return ERR_PTR(-EINVAL); in __reset_control_get()
945 if (dev->of_node) in __reset_control_get()
946 return __of_reset_control_get(dev->of_node, id, index, shared, in __reset_control_get()
973 while (i--) in __reset_control_bulk_get()
985 for (i = 0; i < resets->num_rstcs; i++) in reset_control_array_put()
986 __reset_control_put_internal(resets->rstc[i]); in reset_control_array_put()
992 * reset_control_put - free the reset controller
1012 * reset_control_bulk_put - free the reset controllers
1019 while (num_rstcs--) { in reset_control_bulk_put()
1042 return ERR_PTR(-ENOMEM); in __devm_reset_control_get()
1066 reset_control_bulk_put(devres->num_rstcs, devres->rstcs); in devm_reset_control_bulk_release()
1079 return -ENOMEM; in __devm_reset_control_bulk_get()
1087 ptr->num_rstcs = num_rstcs; in __devm_reset_control_bulk_get()
1088 ptr->rstcs = rstcs; in __devm_reset_control_bulk_get()
1096 * __device_reset - find reset controller associated with the device
1127 * of_reset_control_get_count - Count number of resets available with a device
1139 return -EINVAL; in of_reset_control_get_count()
1141 count = of_count_phandle_with_args(node, "resets", "#reset-cells"); in of_reset_control_get_count()
1143 count = -ENOENT; in of_reset_control_get_count()
1149 * of_reset_control_array_get - Get a list of reset controls using
1174 return ERR_PTR(-ENOMEM); in of_reset_control_array_get()
1181 resets->rstc[i] = rstc; in of_reset_control_array_get()
1183 resets->num_rstcs = num; in of_reset_control_array_get()
1184 resets->base.array = true; in of_reset_control_array_get()
1186 return &resets->base; in of_reset_control_array_get()
1190 while (--i >= 0) in of_reset_control_array_get()
1191 __reset_control_put_internal(resets->rstc[i]); in of_reset_control_array_get()
1201 * devm_reset_control_array_get - Resource managed reset control array get
1208 * that just have to be asserted or deasserted, without any
1221 return ERR_PTR(-ENOMEM); in devm_reset_control_array_get()
1223 rstc = of_reset_control_array_get(dev->of_node, shared, optional, true); in devm_reset_control_array_get()
1243 return -EINVAL; in reset_control_get_count_from_lookup()
1249 if (!strcmp(lookup->dev_id, dev_id)) in reset_control_get_count_from_lookup()
1256 count = -ENOENT; in reset_control_get_count_from_lookup()
1262 * reset_control_get_count - Count number of resets available with a device
1271 if (dev->of_node) in reset_control_get_count()
1272 return of_reset_control_get_count(dev->of_node); in reset_control_get_count()