1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020, Linaro Limited
4  */
5 
6 #ifndef __SANDBOX_SCMI_TEST_H
7 #define __SANDBOX_SCMI_TEST_H
8 
9 struct udevice;
10 struct sandbox_scmi_agent;
11 struct sandbox_scmi_service;
12 
13 /**
14  * struct sandbox_scmi_clk - Simulated clock exposed by SCMI
15  * @id:		Identifier of the clock used in the SCMI protocol
16  * @enabled:	Clock state: true if enabled, false if disabled
17  * @rate:	Clock rate in Hertz
18  */
19 struct sandbox_scmi_clk {
20 	uint id;
21 	bool enabled;
22 	ulong rate;
23 };
24 
25 /**
26  * struct sandbox_scmi_reset - Simulated reset controller exposed by SCMI
27  * @id:		Identifier of the reset controller used in the SCMI protocol
28  * @asserted:	Reset control state: true if asserted, false if desasserted
29  */
30 struct sandbox_scmi_reset {
31 	uint id;
32 	bool asserted;
33 };
34 
35 /**
36  * struct sandbox_scmi_voltd - Simulated voltage regulator exposed by SCMI
37  * @id:		Identifier of the voltage domain used in the SCMI protocol
38  * @enabled:	Regulator state: true if on, false if off
39  * @voltage_uv:	Regulator current voltage in microvoltd (uV)
40  */
41 struct sandbox_scmi_voltd {
42 	uint id;
43 	bool enabled;
44 	int voltage_uv;
45 };
46 
47 /**
48  * struct sandbox_scmi_agent - Simulated SCMI service seen by SCMI agent
49  * @idx:	Identifier for the SCMI agent, its index
50  * @clk:	Simulated clocks
51  * @clk_count:	Simulated clocks array size
52  * @reset:	Simulated reset domains
53  * @reset_count: Simulated reset domains array size
54  * @voltd:	 Simulated voltage domains (regulators)
55  * @voltd_count: Simulated voltage domains array size
56  */
57 struct sandbox_scmi_agent {
58 	uint idx;
59 	struct sandbox_scmi_clk *clk;
60 	size_t clk_count;
61 	struct sandbox_scmi_reset *reset;
62 	size_t reset_count;
63 	struct sandbox_scmi_voltd *voltd;
64 	size_t voltd_count;
65 };
66 
67 /**
68  * struct sandbox_scmi_service - Reference to simutaed SCMI agents/services
69  * @agent:		Pointer to SCMI sandbox agent pointers array
70  * @agent_count:	Number of emulated agents exposed in array @agent.
71  */
72 struct sandbox_scmi_service {
73 	struct sandbox_scmi_agent **agent;
74 	size_t agent_count;
75 };
76 
77 /**
78  * struct sandbox_scmi_devices - Reference to devices probed through SCMI
79  * @clk:		Array the clock devices
80  * @clk_count:		Number of clock devices probed
81  * @reset:		Array the reset controller devices
82  * @reset_count:	Number of reset controller devices probed
83  * @regul:		Array regulator devices
84  * @regul_count:	Number of regulator devices probed
85  */
86 struct sandbox_scmi_devices {
87 	struct clk *clk;
88 	size_t clk_count;
89 	struct reset_ctl *reset;
90 	size_t reset_count;
91 	struct udevice **regul;
92 	size_t regul_count;
93 };
94 
95 #ifdef CONFIG_SCMI_FIRMWARE
96 /**
97  * sandbox_scmi_service_context - Get the simulated SCMI services context
98  * @return:	Reference to backend simulated resources state
99  */
100 struct sandbox_scmi_service *sandbox_scmi_service_ctx(void);
101 
102 /**
103  * sandbox_scmi_devices_get_ref - Get references to devices accessed through SCMI
104  * @dev:	Reference to the test device used get test resources
105  * @return:	Reference to the devices probed by the SCMI test
106  */
107 struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev);
108 #else
sandbox_scmi_service_ctx(void)109 static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
110 {
111 	return NULL;
112 }
113 
114 static inline
sandbox_scmi_devices_ctx(struct udevice * dev)115 struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev)
116 {
117 	return NULL;
118 }
119 #endif /* CONFIG_SCMI_FIRMWARE */
120 #endif /* __SANDBOX_SCMI_TEST_H */
121