xref: /linux/include/linux/pwrseq/provider.h (revision ffec878fa5fba8c527cbbb006b0522ae0d6599ce)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2024 Linaro Ltd.
4  */
5 
6 #ifndef __POWER_SEQUENCING_PROVIDER_H__
7 #define __POWER_SEQUENCING_PROVIDER_H__
8 
9 struct device;
10 struct module;
11 struct pwrseq_device;
12 
13 typedef int (*pwrseq_power_state_func)(struct pwrseq_device *);
14 typedef int (*pwrseq_match_func)(struct pwrseq_device *, struct device *);
15 
16 #define PWRSEQ_NO_MATCH 0
17 #define PWRSEQ_MATCH_OK 1
18 
19 /**
20  * struct pwrseq_unit_data - Configuration of a single power sequencing
21  *                           unit.
22  * @name: Name of the unit.
23  * @deps: Units that must be enabled before this one and disabled after it
24  *        in the order they come in this array. Must be NULL-terminated.
25  * @enable: Callback running the part of the power-on sequence provided by
26  *          this unit.
27  * @disable: Callback running the part of the power-off sequence provided
28  *           by this unit.
29  */
30 struct pwrseq_unit_data {
31 	const char *name;
32 	const struct pwrseq_unit_data **deps;
33 	pwrseq_power_state_func enable;
34 	pwrseq_power_state_func disable;
35 };
36 
37 /**
38  * struct pwrseq_target_data - Configuration of a power sequencing target.
39  * @name: Name of the target.
40  * @unit: Final unit that this target must reach in order to be considered
41  *        enabled.
42  * @post_enable: Callback run after the target unit has been enabled, *after*
43  *               the state lock has been released. It's useful for implementing
44  *               boot-up delays without blocking other users from powering up
45  *               using the same power sequencer.
46  */
47 struct pwrseq_target_data {
48 	const char *name;
49 	const struct pwrseq_unit_data *unit;
50 	pwrseq_power_state_func post_enable;
51 };
52 
53 /**
54  * struct pwrseq_config - Configuration used for registering a new provider.
55  * @parent: Parent device for the sequencer. Must be set.
56  * @owner: Module providing this device.
57  * @drvdata: Private driver data.
58  * @match: Provider callback used to match the consumer device to the sequencer.
59  * @targets: Array of targets for this power sequencer. Must be NULL-terminated.
60  */
61 struct pwrseq_config {
62 	struct device *parent;
63 	struct module *owner;
64 	void *drvdata;
65 	pwrseq_match_func match;
66 	const struct pwrseq_target_data **targets;
67 };
68 
69 struct pwrseq_device *
70 pwrseq_device_register(const struct pwrseq_config *config);
71 void pwrseq_device_unregister(struct pwrseq_device *pwrseq);
72 struct pwrseq_device *
73 devm_pwrseq_device_register(struct device *dev,
74 			    const struct pwrseq_config *config);
75 
76 void *pwrseq_device_get_drvdata(struct pwrseq_device *pwrseq);
77 
78 #endif /* __POWER_SEQUENCING_PROVIDER_H__ */
79