blob: da45314f2e4cf9d21981d0ce017b77162ae21157 [file] [log] [blame]
Etienne Carriere358599e2020-09-09 18:44:00 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020, Linaro Limited
4 *
5 * Tests scmi_agent uclass and the SCMI drivers implemented in other
6 * uclass devices probe when a SCMI server exposes resources.
7 *
Etienne Carriere41d62e22022-02-21 09:22:39 +01008 * Note in test.dts the protocol@10 node in scmi node. Protocol 0x10 is not
Yuepeng Xing7943ae22022-12-02 14:23:07 +08009 * implemented in U-Boot SCMI components but the implementation is expected
Etienne Carriere358599e2020-09-09 18:44:00 +020010 * to not complain on unknown protocol IDs, as long as it is not used. Note
11 * in test.dts tests that SCMI drivers probing does not fail for such an
12 * unknown SCMI protocol ID.
13 */
14
15#include <common.h>
Etienne Carriere87d4f272020-09-09 18:44:05 +020016#include <clk.h>
Etienne Carriere358599e2020-09-09 18:44:00 +020017#include <dm.h>
Etienne Carrierec0dd1772020-09-09 18:44:07 +020018#include <reset.h>
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +090019#include <scmi_agent.h>
AKASHI Takahiro93ecae92023-10-11 19:07:06 +090020#include <scmi_agent-uclass.h>
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +090021#include <scmi_protocols.h>
Etienne Carriere358599e2020-09-09 18:44:00 +020022#include <asm/scmi_test.h>
23#include <dm/device-internal.h>
24#include <dm/test.h>
Etienne Carriere87d4f272020-09-09 18:44:05 +020025#include <linux/kconfig.h>
Etienne Carriere01242182021-03-08 22:38:07 +010026#include <power/regulator.h>
Etienne Carriere358599e2020-09-09 18:44:00 +020027#include <test/ut.h>
28
Etienne Carriere87d4f272020-09-09 18:44:05 +020029static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090030 struct sandbox_scmi_agent *agent,
Etienne Carriere87d4f272020-09-09 18:44:05 +020031 struct udevice *dev)
32{
33 struct sandbox_scmi_devices *scmi_devices;
Etienne Carriere87d4f272020-09-09 18:44:05 +020034
35 /* Device references to check context against test sequence */
36 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020037 ut_assertnonnull(scmi_devices);
Etienne Carriere41d62e22022-02-21 09:22:39 +010038 ut_asserteq(2, scmi_devices->clk_count);
Etienne Carrierec3bba702021-03-08 22:38:08 +010039 ut_asserteq(1, scmi_devices->reset_count);
Etienne Carriere01242182021-03-08 22:38:07 +010040 ut_asserteq(2, scmi_devices->regul_count);
Etienne Carriere87d4f272020-09-09 18:44:05 +020041
42 /* State of the simulated SCMI server exposed */
Etienne Carriere10d3e5d2022-02-21 09:22:41 +010043 ut_asserteq(3, agent->clk_count);
Etienne Carriere41d62e22022-02-21 09:22:39 +010044 ut_assertnonnull(agent->clk);
45 ut_asserteq(1, agent->reset_count);
46 ut_assertnonnull(agent->reset);
47 ut_asserteq(2, agent->voltd_count);
48 ut_assertnonnull(agent->voltd);
Etienne Carriere87d4f272020-09-09 18:44:05 +020049
50 return 0;
51}
52
53static int load_sandbox_scmi_test_devices(struct unit_test_state *uts,
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090054 struct sandbox_scmi_agent **ctx,
Etienne Carriere87d4f272020-09-09 18:44:05 +020055 struct udevice **dev)
56{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090057 struct udevice *agent_dev;
Etienne Carriere87d4f272020-09-09 18:44:05 +020058
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090059 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
60 &agent_dev));
61 ut_assertnonnull(agent_dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020062
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090063 *ctx = sandbox_scmi_agent_ctx(agent_dev);
64 ut_assertnonnull(*ctx);
65
66 /* probe */
Etienne Carriere87d4f272020-09-09 18:44:05 +020067 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi",
68 dev));
69 ut_assertnonnull(*dev);
70
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090071 return ut_assert_scmi_state_postprobe(uts, *ctx, *dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020072}
73
74static int release_sandbox_scmi_test_devices(struct unit_test_state *uts,
75 struct udevice *dev)
76{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090077 /* un-probe */
Etienne Carriere87d4f272020-09-09 18:44:05 +020078 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
79
Etienne Carriere87d4f272020-09-09 18:44:05 +020080 return 0;
81}
82
Etienne Carriere358599e2020-09-09 18:44:00 +020083/*
84 * Test SCMI states when loading and releasing resources
85 * related to SCMI drivers.
86 */
87static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
88{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090089 struct sandbox_scmi_agent *ctx;
Etienne Carriere87d4f272020-09-09 18:44:05 +020090 struct udevice *dev = NULL;
91 int ret;
Etienne Carriere358599e2020-09-09 18:44:00 +020092
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090093 ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020094 if (!ret)
95 ret = release_sandbox_scmi_test_devices(uts, dev);
Etienne Carriere358599e2020-09-09 18:44:00 +020096
Etienne Carriere87d4f272020-09-09 18:44:05 +020097 return ret;
Etienne Carriere358599e2020-09-09 18:44:00 +020098}
Etienne Carriere358599e2020-09-09 18:44:00 +020099DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200100
AKASHI Takahiro93ecae92023-10-11 19:07:06 +0900101static int dm_test_scmi_base(struct unit_test_state *uts)
102{
103 struct udevice *agent_dev, *base;
104 struct scmi_agent_priv *priv;
105 u32 version, num_agents, num_protocols, impl_version;
106 u32 attributes, agent_id;
107 u8 *vendor, *agent_name, *protocols;
108 int ret;
109
110 /* preparation */
111 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
112 &agent_dev));
113 ut_assertnonnull(agent_dev);
114 ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
115 ut_assertnonnull(base = scmi_get_protocol(agent_dev,
116 SCMI_PROTOCOL_ID_BASE));
117
118 /* version */
119 ret = scmi_base_protocol_version(base, &version);
120 ut_assertok(ret);
121 ut_asserteq(priv->version, version);
122
123 /* protocol attributes */
124 ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols);
125 ut_assertok(ret);
126 ut_asserteq(priv->num_agents, num_agents);
127 ut_asserteq(priv->num_protocols, num_protocols);
128
129 /* discover vendor */
130 ret = scmi_base_discover_vendor(base, &vendor);
131 ut_assertok(ret);
132 ut_asserteq_str(priv->vendor, vendor);
133 free(vendor);
134
135 /* message attributes */
136 ret = scmi_base_protocol_message_attrs(base,
137 SCMI_BASE_DISCOVER_SUB_VENDOR,
138 &attributes);
139 ut_assertok(ret);
140 ut_assertok(attributes);
141
142 /* discover sub vendor */
143 ret = scmi_base_discover_sub_vendor(base, &vendor);
144 ut_assertok(ret);
145 ut_asserteq_str(priv->sub_vendor, vendor);
146 free(vendor);
147
148 /* impl version */
149 ret = scmi_base_discover_impl_version(base, &impl_version);
150 ut_assertok(ret);
151 ut_asserteq(priv->impl_version, impl_version);
152
153 /* discover agent (my self) */
154 ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id,
155 &agent_name);
156 ut_assertok(ret);
157 ut_asserteq(priv->agent_id, agent_id);
158 ut_asserteq_str(priv->agent_name, agent_name);
159 free(agent_name);
160
161 /* discover protocols */
162 ret = scmi_base_discover_list_protocols(base, &protocols);
163 ut_asserteq(num_protocols, ret);
164 ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
165 free(protocols);
166
167 /*
168 * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
169 * access and protocol permissions, but doesn't allow unsetting them nor
170 * resetting the configurations.
171 */
172 /* set device permissions */
173 ret = scmi_base_set_device_permissions(base, agent_id, 0,
174 SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
175 ut_assertok(ret); /* SCMI_SUCCESS */
176 ret = scmi_base_set_device_permissions(base, agent_id, 1,
177 SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
178 ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
179 ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
180 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
181
182 /* set protocol permissions */
183 ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
184 SCMI_PROTOCOL_ID_CLOCK,
185 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
186 ut_assertok(ret); /* SCMI_SUCCESS */
187 ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
188 SCMI_PROTOCOL_ID_CLOCK,
189 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
190 ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
191 ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
192 SCMI_PROTOCOL_ID_CLOCK, 0);
193 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
194
195 /* reset agent configuration */
196 ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
197 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
198 ret = scmi_base_reset_agent_configuration(base, agent_id,
199 SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS);
200 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
201 ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
202 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
203
204 return 0;
205}
206
207DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
208
AKASHI Takahiro2ba0f822023-10-16 14:39:46 +0900209static int dm_test_scmi_power_domains(struct unit_test_state *uts)
210{
211 struct sandbox_scmi_agent *agent;
212 struct sandbox_scmi_devices *scmi_devices;
213 struct udevice *agent_dev, *pwd, *dev;
214 u32 version, count, attributes, pstate;
215 u64 stats_addr;
216 size_t stats_len;
217 u8 *name;
218 int ret;
219
220 /* preparation */
221 ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
222 ut_assertnonnull(agent);
223 scmi_devices = sandbox_scmi_devices_ctx(dev);
224 ut_assertnonnull(scmi_devices);
225 ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */
226
227 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
228 &agent_dev));
229 ut_assertnonnull(agent_dev);
230 pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN);
231 ut_assertnonnull(pwd);
232
233 /*
234 * SCMI Power domain management protocol interfaces
235 */
236 /* version */
237 ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN,
238 &version);
239 ut_assertok(ret);
240 ut_asserteq(agent->pwdom_version, version);
241
242 /* protocol attributes */
243 ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len);
244 ut_assertok(ret);
245 ut_asserteq(agent->pwdom_count, count);
246 ut_asserteq(0, stats_len);
247
248 /* protocol message attributes */
249 ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET,
250 &attributes);
251 ut_assertok(ret);
252 ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY,
253 &attributes);
254 ut_asserteq(-ENOENT, ret); /* the protocol not supported */
255
256 /* power domain attributes */
257 ret = scmi_pwd_attrs(pwd, 0, &attributes, &name);
258 ut_assertok(ret);
259 ut_asserteq_str("power-domain--0", name);
260 free(name);
261
262 ret = scmi_pwd_attrs(pwd, 10, &attributes, &name);
263 ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
264
265 /* power domain state set/get */
266 ret = scmi_pwd_state_set(pwd, 0, 0, 0);
267 ut_assertok(ret);
268 ret = scmi_pwd_state_get(pwd, 0, &pstate);
269 ut_assertok(ret);
270 ut_asserteq(0, pstate); /* ON */
271
272 ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST);
273 ut_assertok(ret);
274 ret = scmi_pwd_state_get(pwd, 0, &pstate);
275 ut_assertok(ret);
276 ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
277
278 ret = scmi_pwd_state_set(pwd, 0, 10, 0);
279 ut_asserteq(-ENOENT, ret);
280
281 /* power domain name get */
282 ret = scmi_pwd_name_get(pwd, 0, &name);
283 ut_assertok(ret);
284 ut_asserteq_str("power-domain--0-extended", name);
285 free(name);
286
287 ret = scmi_pwd_name_get(pwd, 10, &name);
288 ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
289
290 /*
291 * U-Boot driver model interfaces
292 */
293 /* power_domain_on */
294 ret = power_domain_on(scmi_devices->pwdom);
295 ut_assertok(ret);
296 ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
297 ut_assertok(ret);
298 ut_asserteq(0, pstate); /* ON */
299
300 /* power_domain_off */
301 ret = power_domain_off(scmi_devices->pwdom);
302 ut_assertok(ret);
303 ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
304 ut_assertok(ret);
305 ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
306
307 return release_sandbox_scmi_test_devices(uts, dev);
308}
309
310DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT);
311
Etienne Carriere87d4f272020-09-09 18:44:05 +0200312static int dm_test_scmi_clocks(struct unit_test_state *uts)
313{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100314 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900315 struct sandbox_scmi_devices *scmi_devices;
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900316 struct udevice *agent_dev, *clock_dev, *dev;
Etienne Carriere87d4f272020-09-09 18:44:05 +0200317 int ret_dev;
318 int ret;
319
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900320 ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200321 if (ret)
322 return ret;
323
324 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100325 ut_assertnonnull(scmi_devices);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200326
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900327 /* Sandbox SCMI clock protocol has its own channel */
328 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
329 &agent_dev));
330 ut_assertnonnull(agent_dev);
331 clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
332 ut_assertnonnull(clock_dev);
333 ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev));
334
Etienne Carriere87d4f272020-09-09 18:44:05 +0200335 /* Test SCMI clocks rate manipulation */
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100336 ut_asserteq(333, agent->clk[0].rate);
337 ut_asserteq(200, agent->clk[1].rate);
338 ut_asserteq(1000, agent->clk[2].rate);
339
Etienne Carriere87d4f272020-09-09 18:44:05 +0200340 ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
341 ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200342
343 ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088);
344 ut_assert(!ret_dev || ret_dev == 1088);
345
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100346 ut_asserteq(1088, agent->clk[0].rate);
347 ut_asserteq(200, agent->clk[1].rate);
348 ut_asserteq(1000, agent->clk[2].rate);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200349
350 ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
351 ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200352
353 /* restore original rate for further tests */
354 ret_dev = clk_set_rate(&scmi_devices->clk[1], 333);
355 ut_assert(!ret_dev || ret_dev == 333);
356
357 /* Test SCMI clocks gating manipulation */
Etienne Carriere41d62e22022-02-21 09:22:39 +0100358 ut_assert(!agent->clk[0].enabled);
359 ut_assert(!agent->clk[1].enabled);
360 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200361
362 ut_asserteq(0, clk_enable(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200363
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100364 ut_assert(agent->clk[0].enabled);
365 ut_assert(!agent->clk[1].enabled);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100366 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200367
368 ut_assertok(clk_disable(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200369
Etienne Carriere41d62e22022-02-21 09:22:39 +0100370 ut_assert(!agent->clk[0].enabled);
371 ut_assert(!agent->clk[1].enabled);
372 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200373
374 return release_sandbox_scmi_test_devices(uts, dev);
375}
Etienne Carriere87d4f272020-09-09 18:44:05 +0200376DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200377
378static int dm_test_scmi_resets(struct unit_test_state *uts)
379{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100380 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900381 struct sandbox_scmi_devices *scmi_devices;
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900382 struct udevice *agent_dev, *reset_dev, *dev = NULL;
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200383 int ret;
384
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900385 ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200386 if (ret)
387 return ret;
388
389 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100390 ut_assertnonnull(scmi_devices);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200391
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900392 /* Sandbox SCMI reset protocol doesn't have its own channel */
393 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
394 &agent_dev));
395 ut_assertnonnull(agent_dev);
396 reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN);
397 ut_assertnonnull(reset_dev);
398 ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev));
399
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200400 /* Test SCMI resect controller manipulation */
Marek Vasutfa847bb2023-03-10 04:33:13 +0100401 ut_assert(!agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200402
403 ut_assertok(reset_assert(&scmi_devices->reset[0]));
Marek Vasutfa847bb2023-03-10 04:33:13 +0100404 ut_assert(agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200405
406 ut_assertok(reset_deassert(&scmi_devices->reset[0]));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100407 ut_assert(!agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200408
409 return release_sandbox_scmi_test_devices(uts, dev);
410}
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200411DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT);
Etienne Carriere01242182021-03-08 22:38:07 +0100412
413static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
414{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100415 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900416 struct sandbox_scmi_devices *scmi_devices;
Etienne Carriere01242182021-03-08 22:38:07 +0100417 struct dm_regulator_uclass_plat *uc_pdata;
418 struct udevice *dev;
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100419 struct udevice *regul0_dev;
Etienne Carriere01242182021-03-08 22:38:07 +0100420
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900421 ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
Etienne Carriere01242182021-03-08 22:38:07 +0100422
423 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100424 ut_assertnonnull(scmi_devices);
Etienne Carriere01242182021-03-08 22:38:07 +0100425
426 /* Set/Get an SCMI voltage domain level */
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100427 regul0_dev = scmi_devices->regul[0];
428 ut_assert(regul0_dev);
Etienne Carriere01242182021-03-08 22:38:07 +0100429
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100430 uc_pdata = dev_get_uclass_plat(regul0_dev);
Etienne Carriere01242182021-03-08 22:38:07 +0100431 ut_assert(uc_pdata);
432
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100433 ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100434 ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100435
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100436 ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100437
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100438 ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100439 ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100440
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100441 ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100442
443 /* Enable/disable SCMI voltage domains */
444 ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
445 ut_assertok(regulator_set_enable(scmi_devices->regul[1], false));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100446 ut_assert(!agent->voltd[0].enabled);
447 ut_assert(!agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100448
449 ut_assertok(regulator_set_enable(scmi_devices->regul[0], true));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100450 ut_assert(agent->voltd[0].enabled);
451 ut_assert(!agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100452
453 ut_assertok(regulator_set_enable(scmi_devices->regul[1], true));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100454 ut_assert(agent->voltd[0].enabled);
455 ut_assert(agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100456
457 ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100458 ut_assert(!agent->voltd[0].enabled);
459 ut_assert(agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100460
461 return release_sandbox_scmi_test_devices(uts, dev);
462}
463DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT);