Lines Matching full:pwrseq

20 #include <linux/pwrseq/consumer.h>
21 #include <linux/pwrseq/provider.h>
45 * Descriptor - a handle passed by the pwrseq core to every consumer that
59 * Protects the device list on the pwrseq bus from concurrent modifications
249 static struct pwrseq_device *pwrseq_device_get(struct pwrseq_device *pwrseq) in pwrseq_device_get() argument
251 get_device(&pwrseq->dev); in pwrseq_device_get()
253 return pwrseq; in pwrseq_device_get()
256 static void pwrseq_device_put(struct pwrseq_device *pwrseq) in pwrseq_device_put() argument
258 put_device(&pwrseq->dev); in pwrseq_device_put()
264 * @pwrseq: Reference to the power sequencing device.
270 struct pwrseq_device *pwrseq; member
276 .name = "pwrseq",
281 struct pwrseq_device *pwrseq = to_pwrseq_device(dev); in pwrseq_release() local
284 list_for_each_entry_safe(target, pos, &pwrseq->targets, list) { in pwrseq_release()
289 mutex_destroy(&pwrseq->state_lock); in pwrseq_release()
290 ida_free(&pwrseq_ida, pwrseq->id); in pwrseq_release()
291 kfree(pwrseq); in pwrseq_release()
414 struct pwrseq_device *pwrseq, in pwrseq_do_setup_targets() argument
432 target->unit = pwrseq_unit_setup(pos->unit, &pwrseq->units, in pwrseq_do_setup_targets()
440 list_add_tail(&target->list, &pwrseq->targets); in pwrseq_do_setup_targets()
447 struct pwrseq_device *pwrseq) in pwrseq_setup_targets() argument
455 ret = pwrseq_do_setup_targets(targets, pwrseq, &processed_units); in pwrseq_setup_targets()
471 * Returns the address of the new pwrseq device or ERR_PTR() on failure.
476 struct pwrseq_device *pwrseq; in pwrseq_device_register() local
483 pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL); in pwrseq_device_register()
484 if (!pwrseq) in pwrseq_device_register()
487 pwrseq->dev.type = &pwrseq_device_type; in pwrseq_device_register()
488 pwrseq->dev.bus = &pwrseq_bus; in pwrseq_device_register()
489 pwrseq->dev.parent = config->parent; in pwrseq_device_register()
490 device_set_node(&pwrseq->dev, dev_fwnode(config->parent)); in pwrseq_device_register()
491 dev_set_drvdata(&pwrseq->dev, config->drvdata); in pwrseq_device_register()
495 kfree(pwrseq); in pwrseq_device_register()
499 pwrseq->id = id; in pwrseq_device_register()
505 device_initialize(&pwrseq->dev); in pwrseq_device_register()
507 ret = dev_set_name(&pwrseq->dev, "pwrseq.%d", pwrseq->id); in pwrseq_device_register()
511 pwrseq->owner = config->owner ?: THIS_MODULE; in pwrseq_device_register()
512 pwrseq->match = config->match; in pwrseq_device_register()
514 init_rwsem(&pwrseq->rw_lock); in pwrseq_device_register()
515 mutex_init(&pwrseq->state_lock); in pwrseq_device_register()
516 INIT_LIST_HEAD(&pwrseq->targets); in pwrseq_device_register()
517 INIT_LIST_HEAD(&pwrseq->units); in pwrseq_device_register()
519 ret = pwrseq_setup_targets(config->targets, pwrseq); in pwrseq_device_register()
524 ret = device_add(&pwrseq->dev); in pwrseq_device_register()
529 return pwrseq; in pwrseq_device_register()
532 pwrseq_device_put(pwrseq); in pwrseq_device_register()
539 * @pwrseq: Power sequencer to unregister.
541 void pwrseq_device_unregister(struct pwrseq_device *pwrseq) in pwrseq_device_unregister() argument
543 struct device *dev = &pwrseq->dev; in pwrseq_device_unregister()
546 scoped_guard(mutex, &pwrseq->state_lock) { in pwrseq_device_unregister()
547 guard(rwsem_write)(&pwrseq->rw_lock); in pwrseq_device_unregister()
549 list_for_each_entry(target, &pwrseq->targets, list) in pwrseq_device_unregister()
558 pwrseq_device_put(pwrseq); in pwrseq_device_unregister()
564 struct pwrseq_device *pwrseq = data; in devm_pwrseq_device_unregister() local
566 pwrseq_device_unregister(pwrseq); in devm_pwrseq_device_unregister()
575 * Returns the address of the new pwrseq device or ERR_PTR() on failure.
581 struct pwrseq_device *pwrseq; in devm_pwrseq_device_register() local
584 pwrseq = pwrseq_device_register(config); in devm_pwrseq_device_register()
585 if (IS_ERR(pwrseq)) in devm_pwrseq_device_register()
586 return pwrseq; in devm_pwrseq_device_register()
589 pwrseq); in devm_pwrseq_device_register()
593 return pwrseq; in devm_pwrseq_device_register()
600 * @pwrseq: Power sequencer object.
605 void *pwrseq_device_get_drvdata(struct pwrseq_device *pwrseq) in pwrseq_device_get_drvdata() argument
607 return dev_get_drvdata(&pwrseq->dev); in pwrseq_device_get_drvdata()
619 struct pwrseq_device *pwrseq = to_pwrseq_device(pwrseq_dev); in pwrseq_match_device() local
626 guard(rwsem_read)(&pwrseq->rw_lock); in pwrseq_match_device()
627 if (!device_is_registered(&pwrseq->dev)) in pwrseq_match_device()
630 ret = pwrseq->match(pwrseq, match_data->dev); in pwrseq_match_device()
635 list_for_each_entry(target, &pwrseq->targets, list) { in pwrseq_match_device()
649 if (!try_module_get(pwrseq->owner)) in pwrseq_match_device()
652 match_data->desc->pwrseq = pwrseq_device_get(pwrseq); in pwrseq_match_device()
701 struct pwrseq_device *pwrseq; in pwrseq_put() local
706 pwrseq = desc->pwrseq; in pwrseq_put()
712 module_put(pwrseq->owner); in pwrseq_put()
713 pwrseq_device_put(pwrseq); in pwrseq_put()
752 static int pwrseq_unit_enable(struct pwrseq_device *pwrseq,
754 static int pwrseq_unit_disable(struct pwrseq_device *pwrseq,
757 static int pwrseq_unit_enable_deps(struct pwrseq_device *pwrseq, in pwrseq_unit_enable_deps() argument
764 ret = pwrseq_unit_enable(pwrseq, pos->unit); in pwrseq_unit_enable_deps()
767 pwrseq_unit_disable(pwrseq, pos->unit); in pwrseq_unit_enable_deps()
775 static int pwrseq_unit_disable_deps(struct pwrseq_device *pwrseq, in pwrseq_unit_disable_deps() argument
782 ret = pwrseq_unit_disable(pwrseq, pos->unit); in pwrseq_unit_disable_deps()
785 pwrseq_unit_enable(pwrseq, pos->unit); in pwrseq_unit_disable_deps()
793 static int pwrseq_unit_enable(struct pwrseq_device *pwrseq, in pwrseq_unit_enable() argument
798 lockdep_assert_held_read(&pwrseq->rw_lock); in pwrseq_unit_enable()
799 lockdep_assert_held(&pwrseq->state_lock); in pwrseq_unit_enable()
806 ret = pwrseq_unit_enable_deps(pwrseq, &unit->deps); in pwrseq_unit_enable()
808 dev_err(&pwrseq->dev, in pwrseq_unit_enable()
815 ret = unit->enable(pwrseq); in pwrseq_unit_enable()
817 dev_err(&pwrseq->dev, in pwrseq_unit_enable()
820 pwrseq_unit_disable_deps(pwrseq, &unit->deps); in pwrseq_unit_enable()
830 static int pwrseq_unit_disable(struct pwrseq_device *pwrseq, in pwrseq_unit_disable() argument
835 lockdep_assert_held_read(&pwrseq->rw_lock); in pwrseq_unit_disable()
836 lockdep_assert_held(&pwrseq->state_lock); in pwrseq_unit_disable()
850 ret = unit->disable(pwrseq); in pwrseq_unit_disable()
852 dev_err(&pwrseq->dev, in pwrseq_unit_disable()
859 ret = pwrseq_unit_disable_deps(pwrseq, &unit->deps); in pwrseq_unit_disable()
861 dev_err(&pwrseq->dev, in pwrseq_unit_disable()
865 unit->enable(pwrseq); in pwrseq_unit_disable()
890 struct pwrseq_device *pwrseq; in pwrseq_power_on() local
900 pwrseq = desc->pwrseq; in pwrseq_power_on()
904 guard(rwsem_read)(&pwrseq->rw_lock); in pwrseq_power_on()
905 if (!device_is_registered(&pwrseq->dev)) in pwrseq_power_on()
908 scoped_guard(mutex, &pwrseq->state_lock) { in pwrseq_power_on()
909 ret = pwrseq_unit_enable(pwrseq, unit); in pwrseq_power_on()
915 ret = target->post_enable(pwrseq); in pwrseq_power_on()
917 pwrseq_unit_disable(pwrseq, unit); in pwrseq_power_on()
941 struct pwrseq_device *pwrseq; in pwrseq_power_off() local
950 pwrseq = desc->pwrseq; in pwrseq_power_off()
953 guard(rwsem_read)(&pwrseq->rw_lock); in pwrseq_power_off()
954 if (!device_is_registered(&pwrseq->dev)) in pwrseq_power_off()
957 guard(mutex)(&pwrseq->state_lock); in pwrseq_power_off()
959 ret = pwrseq_unit_disable(pwrseq, unit); in pwrseq_power_off()
1041 struct pwrseq_device *pwrseq = to_pwrseq_device(dev); in pwrseq_debugfs_seq_show() local
1048 list_for_each_entry(target, &pwrseq->targets, list) in pwrseq_debugfs_seq_show()
1052 list_for_each_entry(unit, &pwrseq->units, list) in pwrseq_debugfs_seq_show()
1086 pwrseq_debugfs_dentry = debugfs_create_file("pwrseq", 0444, NULL, NULL, in pwrseq_init()