Line data Source code
1 0 : /*
2 : * Copyright (c) 2025 Analog Devices, Inc.
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_SUBSYS_CPU_FREQ_PSTATE_H_
8 : #define ZEPHYR_SUBSYS_CPU_FREQ_PSTATE_H_
9 :
10 : #ifdef __cplusplus
11 : extern "C" {
12 : #endif
13 :
14 : #include <zephyr/types.h>
15 : #include <zephyr/devicetree.h>
16 : #include <zephyr/cpu_freq/pstate.h>
17 :
18 : /**
19 : * @brief CPU Frequency Scaling Performance State (pstate)
20 : * @defgroup subsys_cpu_freq_pstate CPU Frequency pstate
21 : * @since 4.3
22 : * @version 0.1.0
23 : * @ingroup subsys_cpu_freq
24 : * @{
25 : */
26 :
27 : /** Synthesize symbol of pstate from devicetree dependency ordinal */
28 1 : #define PSTATE_DT_SYM(_node) _CONCAT(__pstate_, DT_DEP_ORD(_node))
29 :
30 : /**
31 : * @brief Define all pstate information for the given node identifier.
32 : *
33 : * @param _node Node identifier.
34 : * @param _config Pointer to the SoC specific configuration for the pstate.
35 : */
36 1 : #define PSTATE_DT_DEFINE(_node, _config) \
37 : const struct pstate PSTATE_DT_SYM(_node) = { \
38 : .load_threshold = DT_PROP(_node, load_threshold), \
39 : .config = _config, \
40 : };
41 :
42 : /**
43 : * @brief Get a pstate reference from a devicetree node identifier.
44 : *
45 : * To be used in DT_FOREACH_CHILD() or similar macros
46 : *
47 : * @param _node Node identifier.
48 : */
49 1 : #define PSTATE_DT_GET(_node) &PSTATE_DT_SYM(_node)
50 :
51 :
52 : /**
53 : * @brief CPU performance state (pstate) struct.
54 : *
55 : * This struct holds information about a CPU pstate as well as a reference to vendor-specific
56 : * devicetree properties.
57 : */
58 1 : struct pstate {
59 1 : uint8_t load_threshold; /**< CPU load threshold at which P-state should be triggered */
60 1 : const void *config; /**< Vendor specific devicetree properties */
61 : };
62 :
63 : /* Define performance-states as extern to be picked up by CPU Freq policy */
64 : #define Z_DECLARE_PSTATE_EXTERN(_node) \
65 : extern const struct pstate PSTATE_DT_SYM(_node);
66 :
67 : DT_FOREACH_CHILD_STATUS_OKAY(DT_PATH(performance_states), Z_DECLARE_PSTATE_EXTERN)
68 :
69 : /**
70 : * @}
71 : */
72 :
73 : #ifdef __cplusplus
74 : }
75 : #endif
76 :
77 : #endif /* ZEPHYR_SUBSYS_CPU_FREQ_PSTATE_H_ */
|