Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
9struct device;
10struct module;
11struct pwrseq_device;
12
13typedef int (*pwrseq_power_state_func)(struct pwrseq_device *);
14typedef 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 */
30struct 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 */
47struct 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 */
61struct 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
69struct pwrseq_device *
70pwrseq_device_register(const struct pwrseq_config *config);
71void pwrseq_device_unregister(struct pwrseq_device *pwrseq);
72struct pwrseq_device *
73devm_pwrseq_device_register(struct device *dev,
74 const struct pwrseq_config *config);
75
76void *pwrseq_device_get_drvdata(struct pwrseq_device *pwrseq);
77
78#endif /* __POWER_SEQUENCING_PROVIDER_H__ */