blob: c9a03523184e1d6bdf01bf11b11cfd4264b2f2ce [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
Etienne Carriere87d4f272020-09-09 18:44:05 +020015#include <clk.h>
Etienne Carriere358599e2020-09-09 18:44:00 +020016#include <dm.h>
Etienne Carrierec0dd1772020-09-09 18:44:07 +020017#include <reset.h>
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +090018#include <scmi_agent.h>
AKASHI Takahiro93ecae92023-10-11 19:07:06 +090019#include <scmi_agent-uclass.h>
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +090020#include <scmi_protocols.h>
Raymond Maocb73fe92024-05-16 14:11:52 -070021#include <stdio.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 Carriere01242182021-03-08 22:38:07 +010025#include <power/regulator.h>
Etienne Carriere358599e2020-09-09 18:44:00 +020026#include <test/ut.h>
27
Etienne Carriere87d4f272020-09-09 18:44:05 +020028static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090029 struct sandbox_scmi_agent *agent,
Etienne Carriere87d4f272020-09-09 18:44:05 +020030 struct udevice *dev)
31{
32 struct sandbox_scmi_devices *scmi_devices;
Etienne Carriere87d4f272020-09-09 18:44:05 +020033
34 /* Device references to check context against test sequence */
35 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020036 ut_assertnonnull(scmi_devices);
Etienne Carriere41d62e22022-02-21 09:22:39 +010037 ut_asserteq(2, scmi_devices->clk_count);
Etienne Carrierec3bba702021-03-08 22:38:08 +010038 ut_asserteq(1, scmi_devices->reset_count);
Etienne Carriere01242182021-03-08 22:38:07 +010039 ut_asserteq(2, scmi_devices->regul_count);
Etienne Carriere87d4f272020-09-09 18:44:05 +020040
41 /* State of the simulated SCMI server exposed */
Etienne Carriere10d3e5d2022-02-21 09:22:41 +010042 ut_asserteq(3, agent->clk_count);
Etienne Carriere41d62e22022-02-21 09:22:39 +010043 ut_assertnonnull(agent->clk);
44 ut_asserteq(1, agent->reset_count);
45 ut_assertnonnull(agent->reset);
46 ut_asserteq(2, agent->voltd_count);
47 ut_assertnonnull(agent->voltd);
Etienne Carriere87d4f272020-09-09 18:44:05 +020048
49 return 0;
50}
51
52static int load_sandbox_scmi_test_devices(struct unit_test_state *uts,
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090053 struct sandbox_scmi_agent **ctx,
Etienne Carriere87d4f272020-09-09 18:44:05 +020054 struct udevice **dev)
55{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090056 struct udevice *agent_dev;
Etienne Carriere87d4f272020-09-09 18:44:05 +020057
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090058 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
59 &agent_dev));
60 ut_assertnonnull(agent_dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020061
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090062 *ctx = sandbox_scmi_agent_ctx(agent_dev);
63 ut_assertnonnull(*ctx);
64
65 /* probe */
Etienne Carriere87d4f272020-09-09 18:44:05 +020066 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi",
67 dev));
68 ut_assertnonnull(*dev);
69
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090070 return ut_assert_scmi_state_postprobe(uts, *ctx, *dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020071}
72
73static int release_sandbox_scmi_test_devices(struct unit_test_state *uts,
74 struct udevice *dev)
75{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090076 /* un-probe */
Etienne Carriere87d4f272020-09-09 18:44:05 +020077 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
78
Etienne Carriere87d4f272020-09-09 18:44:05 +020079 return 0;
80}
81
Etienne Carriere358599e2020-09-09 18:44:00 +020082/*
83 * Test SCMI states when loading and releasing resources
84 * related to SCMI drivers.
85 */
86static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
87{
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090088 struct sandbox_scmi_agent *ctx;
Etienne Carriere87d4f272020-09-09 18:44:05 +020089 struct udevice *dev = NULL;
90 int ret;
Etienne Carriere358599e2020-09-09 18:44:00 +020091
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +090092 ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +020093 if (!ret)
94 ret = release_sandbox_scmi_test_devices(uts, dev);
Etienne Carriere358599e2020-09-09 18:44:00 +020095
Etienne Carriere87d4f272020-09-09 18:44:05 +020096 return ret;
Etienne Carriere358599e2020-09-09 18:44:00 +020097}
Etienne Carriere358599e2020-09-09 18:44:00 +020098DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
Etienne Carriere87d4f272020-09-09 18:44:05 +020099
AKASHI Takahiro93ecae92023-10-11 19:07:06 +0900100static int dm_test_scmi_base(struct unit_test_state *uts)
101{
102 struct udevice *agent_dev, *base;
103 struct scmi_agent_priv *priv;
104 u32 version, num_agents, num_protocols, impl_version;
105 u32 attributes, agent_id;
106 u8 *vendor, *agent_name, *protocols;
107 int ret;
108
109 /* preparation */
110 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
111 &agent_dev));
112 ut_assertnonnull(agent_dev);
113 ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
114 ut_assertnonnull(base = scmi_get_protocol(agent_dev,
115 SCMI_PROTOCOL_ID_BASE));
116
117 /* version */
118 ret = scmi_base_protocol_version(base, &version);
119 ut_assertok(ret);
120 ut_asserteq(priv->version, version);
121
122 /* protocol attributes */
123 ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols);
124 ut_assertok(ret);
125 ut_asserteq(priv->num_agents, num_agents);
126 ut_asserteq(priv->num_protocols, num_protocols);
127
128 /* discover vendor */
129 ret = scmi_base_discover_vendor(base, &vendor);
130 ut_assertok(ret);
131 ut_asserteq_str(priv->vendor, vendor);
132 free(vendor);
133
134 /* message attributes */
135 ret = scmi_base_protocol_message_attrs(base,
136 SCMI_BASE_DISCOVER_SUB_VENDOR,
137 &attributes);
138 ut_assertok(ret);
139 ut_assertok(attributes);
140
141 /* discover sub vendor */
142 ret = scmi_base_discover_sub_vendor(base, &vendor);
143 ut_assertok(ret);
144 ut_asserteq_str(priv->sub_vendor, vendor);
145 free(vendor);
146
147 /* impl version */
148 ret = scmi_base_discover_impl_version(base, &impl_version);
149 ut_assertok(ret);
150 ut_asserteq(priv->impl_version, impl_version);
151
152 /* discover agent (my self) */
153 ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id,
154 &agent_name);
155 ut_assertok(ret);
156 ut_asserteq(priv->agent_id, agent_id);
157 ut_asserteq_str(priv->agent_name, agent_name);
158 free(agent_name);
159
160 /* discover protocols */
161 ret = scmi_base_discover_list_protocols(base, &protocols);
162 ut_asserteq(num_protocols, ret);
163 ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
164 free(protocols);
165
166 /*
167 * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
168 * access and protocol permissions, but doesn't allow unsetting them nor
169 * resetting the configurations.
170 */
171 /* set device permissions */
172 ret = scmi_base_set_device_permissions(base, agent_id, 0,
173 SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
174 ut_assertok(ret); /* SCMI_SUCCESS */
175 ret = scmi_base_set_device_permissions(base, agent_id, 1,
176 SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
177 ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
178 ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
179 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
180
181 /* set protocol permissions */
182 ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
183 SCMI_PROTOCOL_ID_CLOCK,
184 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
185 ut_assertok(ret); /* SCMI_SUCCESS */
186 ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
187 SCMI_PROTOCOL_ID_CLOCK,
188 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
189 ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
190 ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
191 SCMI_PROTOCOL_ID_CLOCK, 0);
192 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
193
194 /* reset agent configuration */
195 ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
196 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
197 ret = scmi_base_reset_agent_configuration(base, agent_id,
198 SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS);
199 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
200 ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
201 ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
202
203 return 0;
204}
205
206DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
207
AKASHI Takahiro3d6fe582023-11-14 11:14:28 +0900208static int dm_test_scmi_cmd(struct unit_test_state *uts)
209{
210 struct udevice *agent_dev;
211 int num_proto = 0;
212 char cmd_out[30];
213
214 if (!CONFIG_IS_ENABLED(CMD_SCMI))
215 return -EAGAIN;
216
217 /* preparation */
218 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
219 &agent_dev));
220 ut_assertnonnull(agent_dev);
221
222 /*
223 * Estimate the number of provided protocols.
224 * This estimation is correct as far as a corresponding
225 * protocol support is added to sandbox fake serer.
226 */
227 if (CONFIG_IS_ENABLED(POWER_DOMAIN))
228 num_proto++;
229 if (CONFIG_IS_ENABLED(CLK_SCMI))
230 num_proto++;
231 if (CONFIG_IS_ENABLED(RESET_SCMI))
232 num_proto++;
233 if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
234 num_proto++;
235
236 /* scmi info */
237 ut_assertok(run_command("scmi info", 0));
238
239 ut_assert_nextline("SCMI device: scmi");
240 snprintf(cmd_out, 30, " protocol version: 0x%x",
241 SCMI_BASE_PROTOCOL_VERSION);
242 ut_assert_nextline(cmd_out);
243 ut_assert_nextline(" # of agents: 2");
244 ut_assert_nextline(" 0: platform");
245 ut_assert_nextline(" > 1: OSPM");
246 snprintf(cmd_out, 30, " # of protocols: %d", num_proto);
247 ut_assert_nextline(cmd_out);
248 if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN))
249 ut_assert_nextline(" Power domain management");
250 if (CONFIG_IS_ENABLED(CLK_SCMI))
251 ut_assert_nextline(" Clock management");
252 if (CONFIG_IS_ENABLED(RESET_SCMI))
253 ut_assert_nextline(" Reset domain management");
254 if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
255 ut_assert_nextline(" Voltage domain management");
256 ut_assert_nextline(" vendor: U-Boot");
257 ut_assert_nextline(" sub vendor: Sandbox");
258 ut_assert_nextline(" impl version: 0x1");
259
260 ut_assert_console_end();
261
262 /* scmi perm_dev */
263 ut_assertok(run_command("scmi perm_dev 1 0 1", 0));
264 ut_assert_console_end();
265
266 ut_assert(run_command("scmi perm_dev 1 0 0", 0));
267 ut_assert_nextline("Denying access to device:0 failed (-13)");
268 ut_assert_console_end();
269
270 /* scmi perm_proto */
271 ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0));
272 ut_assert_console_end();
273
274 ut_assert(run_command("scmi perm_proto 1 0 14 0", 0));
275 ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed (-13)");
276 ut_assert_console_end();
277
278 /* scmi reset */
279 ut_assert(run_command("scmi reset 1 1", 0));
280 ut_assert_nextline("Reset failed (-13)");
281 ut_assert_console_end();
282
283 return 0;
284}
285
286DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT);
287
AKASHI Takahiro2ba0f822023-10-16 14:39:46 +0900288static int dm_test_scmi_power_domains(struct unit_test_state *uts)
289{
290 struct sandbox_scmi_agent *agent;
291 struct sandbox_scmi_devices *scmi_devices;
292 struct udevice *agent_dev, *pwd, *dev;
293 u32 version, count, attributes, pstate;
294 u64 stats_addr;
295 size_t stats_len;
296 u8 *name;
297 int ret;
298
AKASHI Takahiro63cd0dc2023-11-14 11:14:24 +0900299 if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN))
300 return -EAGAIN;
301
AKASHI Takahiro2ba0f822023-10-16 14:39:46 +0900302 /* preparation */
303 ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
304 ut_assertnonnull(agent);
305 scmi_devices = sandbox_scmi_devices_ctx(dev);
306 ut_assertnonnull(scmi_devices);
307 ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */
308
309 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
310 &agent_dev));
311 ut_assertnonnull(agent_dev);
312 pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN);
313 ut_assertnonnull(pwd);
314
315 /*
316 * SCMI Power domain management protocol interfaces
317 */
318 /* version */
319 ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN,
320 &version);
321 ut_assertok(ret);
322 ut_asserteq(agent->pwdom_version, version);
323
324 /* protocol attributes */
325 ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len);
326 ut_assertok(ret);
327 ut_asserteq(agent->pwdom_count, count);
328 ut_asserteq(0, stats_len);
329
330 /* protocol message attributes */
331 ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET,
332 &attributes);
333 ut_assertok(ret);
334 ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY,
335 &attributes);
336 ut_asserteq(-ENOENT, ret); /* the protocol not supported */
337
338 /* power domain attributes */
339 ret = scmi_pwd_attrs(pwd, 0, &attributes, &name);
340 ut_assertok(ret);
341 ut_asserteq_str("power-domain--0", name);
342 free(name);
343
344 ret = scmi_pwd_attrs(pwd, 10, &attributes, &name);
345 ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
346
347 /* power domain state set/get */
348 ret = scmi_pwd_state_set(pwd, 0, 0, 0);
349 ut_assertok(ret);
350 ret = scmi_pwd_state_get(pwd, 0, &pstate);
351 ut_assertok(ret);
352 ut_asserteq(0, pstate); /* ON */
353
354 ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST);
355 ut_assertok(ret);
356 ret = scmi_pwd_state_get(pwd, 0, &pstate);
357 ut_assertok(ret);
358 ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
359
360 ret = scmi_pwd_state_set(pwd, 0, 10, 0);
361 ut_asserteq(-ENOENT, ret);
362
363 /* power domain name get */
364 ret = scmi_pwd_name_get(pwd, 0, &name);
365 ut_assertok(ret);
366 ut_asserteq_str("power-domain--0-extended", name);
367 free(name);
368
369 ret = scmi_pwd_name_get(pwd, 10, &name);
370 ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
371
372 /*
373 * U-Boot driver model interfaces
374 */
375 /* power_domain_on */
376 ret = power_domain_on(scmi_devices->pwdom);
377 ut_assertok(ret);
378 ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
379 ut_assertok(ret);
380 ut_asserteq(0, pstate); /* ON */
381
382 /* power_domain_off */
383 ret = power_domain_off(scmi_devices->pwdom);
384 ut_assertok(ret);
385 ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
386 ut_assertok(ret);
387 ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
388
389 return release_sandbox_scmi_test_devices(uts, dev);
390}
391
392DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT);
393
Etienne Carriere87d4f272020-09-09 18:44:05 +0200394static int dm_test_scmi_clocks(struct unit_test_state *uts)
395{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100396 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900397 struct sandbox_scmi_devices *scmi_devices;
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900398 struct udevice *agent_dev, *clock_dev, *dev;
Etienne Carriere87d4f272020-09-09 18:44:05 +0200399 int ret_dev;
400 int ret;
401
AKASHI Takahiro63cd0dc2023-11-14 11:14:24 +0900402 if (!CONFIG_IS_ENABLED(CLK_SCMI))
403 return -EAGAIN;
404
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900405 ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200406 if (ret)
407 return ret;
408
409 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100410 ut_assertnonnull(scmi_devices);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200411
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900412 /* Sandbox SCMI clock protocol has its own channel */
413 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
414 &agent_dev));
415 ut_assertnonnull(agent_dev);
416 clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
417 ut_assertnonnull(clock_dev);
418 ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev));
419
Etienne Carriere87d4f272020-09-09 18:44:05 +0200420 /* Test SCMI clocks rate manipulation */
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100421 ut_asserteq(333, agent->clk[0].rate);
422 ut_asserteq(200, agent->clk[1].rate);
423 ut_asserteq(1000, agent->clk[2].rate);
424
Etienne Carriere87d4f272020-09-09 18:44:05 +0200425 ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
426 ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200427
428 ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088);
429 ut_assert(!ret_dev || ret_dev == 1088);
430
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100431 ut_asserteq(1088, agent->clk[0].rate);
432 ut_asserteq(200, agent->clk[1].rate);
433 ut_asserteq(1000, agent->clk[2].rate);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200434
435 ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
436 ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200437
438 /* restore original rate for further tests */
439 ret_dev = clk_set_rate(&scmi_devices->clk[1], 333);
440 ut_assert(!ret_dev || ret_dev == 333);
441
442 /* Test SCMI clocks gating manipulation */
Etienne Carriere41d62e22022-02-21 09:22:39 +0100443 ut_assert(!agent->clk[0].enabled);
444 ut_assert(!agent->clk[1].enabled);
445 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200446
447 ut_asserteq(0, clk_enable(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200448
Etienne Carriere10d3e5d2022-02-21 09:22:41 +0100449 ut_assert(agent->clk[0].enabled);
450 ut_assert(!agent->clk[1].enabled);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100451 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200452
453 ut_assertok(clk_disable(&scmi_devices->clk[1]));
Etienne Carriere87d4f272020-09-09 18:44:05 +0200454
Etienne Carriere41d62e22022-02-21 09:22:39 +0100455 ut_assert(!agent->clk[0].enabled);
456 ut_assert(!agent->clk[1].enabled);
457 ut_assert(!agent->clk[2].enabled);
Etienne Carriere87d4f272020-09-09 18:44:05 +0200458
459 return release_sandbox_scmi_test_devices(uts, dev);
460}
Etienne Carriere87d4f272020-09-09 18:44:05 +0200461DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200462
463static int dm_test_scmi_resets(struct unit_test_state *uts)
464{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100465 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900466 struct sandbox_scmi_devices *scmi_devices;
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900467 struct udevice *agent_dev, *reset_dev, *dev = NULL;
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200468 int ret;
469
AKASHI Takahiro63cd0dc2023-11-14 11:14:24 +0900470 if (!CONFIG_IS_ENABLED(RESET_SCMI))
471 return -EAGAIN;
472
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900473 ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200474 if (ret)
475 return ret;
476
477 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100478 ut_assertnonnull(scmi_devices);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200479
AKASHI Takahiroa89d9f42023-10-11 19:06:59 +0900480 /* Sandbox SCMI reset protocol doesn't have its own channel */
481 ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
482 &agent_dev));
483 ut_assertnonnull(agent_dev);
484 reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN);
485 ut_assertnonnull(reset_dev);
486 ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev));
487
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200488 /* Test SCMI resect controller manipulation */
Marek Vasutfa847bb2023-03-10 04:33:13 +0100489 ut_assert(!agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200490
491 ut_assertok(reset_assert(&scmi_devices->reset[0]));
Marek Vasutfa847bb2023-03-10 04:33:13 +0100492 ut_assert(agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200493
494 ut_assertok(reset_deassert(&scmi_devices->reset[0]));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100495 ut_assert(!agent->reset[0].asserted);
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200496
497 return release_sandbox_scmi_test_devices(uts, dev);
498}
Etienne Carrierec0dd1772020-09-09 18:44:07 +0200499DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT);
Etienne Carriere01242182021-03-08 22:38:07 +0100500
501static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
502{
Etienne Carriere41d62e22022-02-21 09:22:39 +0100503 struct sandbox_scmi_agent *agent;
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900504 struct sandbox_scmi_devices *scmi_devices;
Etienne Carriere01242182021-03-08 22:38:07 +0100505 struct dm_regulator_uclass_plat *uc_pdata;
506 struct udevice *dev;
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100507 struct udevice *regul0_dev;
Etienne Carriere01242182021-03-08 22:38:07 +0100508
AKASHI Takahiro63cd0dc2023-11-14 11:14:24 +0900509 if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
510 return -EAGAIN;
511
AKASHI Takahirobddcd3a2023-10-11 19:07:03 +0900512 ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
Etienne Carriere01242182021-03-08 22:38:07 +0100513
514 scmi_devices = sandbox_scmi_devices_ctx(dev);
Etienne Carriere41d62e22022-02-21 09:22:39 +0100515 ut_assertnonnull(scmi_devices);
Etienne Carriere01242182021-03-08 22:38:07 +0100516
517 /* Set/Get an SCMI voltage domain level */
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100518 regul0_dev = scmi_devices->regul[0];
519 ut_assert(regul0_dev);
Etienne Carriere01242182021-03-08 22:38:07 +0100520
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100521 uc_pdata = dev_get_uclass_plat(regul0_dev);
Etienne Carriere01242182021-03-08 22:38:07 +0100522 ut_assert(uc_pdata);
523
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100524 ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100525 ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100526
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100527 ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100528
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100529 ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100530 ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100531
Etienne Carriere3dfd7392021-03-08 22:38:09 +0100532 ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV);
Etienne Carriere01242182021-03-08 22:38:07 +0100533
534 /* Enable/disable SCMI voltage domains */
535 ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
536 ut_assertok(regulator_set_enable(scmi_devices->regul[1], false));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100537 ut_assert(!agent->voltd[0].enabled);
538 ut_assert(!agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100539
540 ut_assertok(regulator_set_enable(scmi_devices->regul[0], true));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100541 ut_assert(agent->voltd[0].enabled);
542 ut_assert(!agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100543
544 ut_assertok(regulator_set_enable(scmi_devices->regul[1], true));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100545 ut_assert(agent->voltd[0].enabled);
546 ut_assert(agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100547
548 ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
Etienne Carriere41d62e22022-02-21 09:22:39 +0100549 ut_assert(!agent->voltd[0].enabled);
550 ut_assert(agent->voltd[1].enabled);
Etienne Carriere01242182021-03-08 22:38:07 +0100551
552 return release_sandbox_scmi_test_devices(uts, dev);
553}
554DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT);