Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 1 | // 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 Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 8 | * Note in test.dts the protocol@10 node in scmi node. Protocol 0x10 is not |
Yuepeng Xing | 7943ae2 | 2022-12-02 14:23:07 +0800 | [diff] [blame] | 9 | * implemented in U-Boot SCMI components but the implementation is expected |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 10 | * 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 Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 15 | #include <clk.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 16 | #include <dm.h> |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 17 | #include <reset.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 18 | #include <scmi_agent.h> |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 19 | #include <scmi_agent-uclass.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 20 | #include <scmi_protocols.h> |
Raymond Mao | cb73fe9 | 2024-05-16 14:11:52 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 22 | #include <asm/scmi_test.h> |
| 23 | #include <dm/device-internal.h> |
| 24 | #include <dm/test.h> |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 25 | #include <power/regulator.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 26 | #include <test/ut.h> |
| 27 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 28 | static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 29 | struct sandbox_scmi_agent *agent, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 30 | struct udevice *dev) |
| 31 | { |
| 32 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 33 | |
| 34 | /* Device references to check context against test sequence */ |
| 35 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 36 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 37 | ut_asserteq(2, scmi_devices->clk_count); |
Etienne Carriere | c3bba70 | 2021-03-08 22:38:08 +0100 | [diff] [blame] | 38 | ut_asserteq(1, scmi_devices->reset_count); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 39 | ut_asserteq(2, scmi_devices->regul_count); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 40 | |
| 41 | /* State of the simulated SCMI server exposed */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 42 | ut_asserteq(3, agent->clk_count); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 43 | 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 Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int load_sandbox_scmi_test_devices(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 53 | struct sandbox_scmi_agent **ctx, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 54 | struct udevice **dev) |
| 55 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 56 | struct udevice *agent_dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 57 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 58 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 59 | &agent_dev)); |
| 60 | ut_assertnonnull(agent_dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 61 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 62 | *ctx = sandbox_scmi_agent_ctx(agent_dev); |
| 63 | ut_assertnonnull(*ctx); |
| 64 | |
| 65 | /* probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 66 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi", |
| 67 | dev)); |
| 68 | ut_assertnonnull(*dev); |
| 69 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 70 | return ut_assert_scmi_state_postprobe(uts, *ctx, *dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, |
| 74 | struct udevice *dev) |
| 75 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 76 | /* un-probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 77 | ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); |
| 78 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 82 | /* |
| 83 | * Test SCMI states when loading and releasing resources |
| 84 | * related to SCMI drivers. |
| 85 | */ |
| 86 | static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) |
| 87 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 88 | struct sandbox_scmi_agent *ctx; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 89 | struct udevice *dev = NULL; |
| 90 | int ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 91 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 92 | ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 93 | if (!ret) |
| 94 | ret = release_sandbox_scmi_test_devices(uts, dev); |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 95 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 96 | return ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 97 | } |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 98 | DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 99 | |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 100 | static 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 | |
| 206 | DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT); |
| 207 | |
AKASHI Takahiro | 3d6fe58 | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 208 | static 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 | |
| 286 | DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT); |
| 287 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 288 | static 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 Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 299 | if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 300 | return -EAGAIN; |
| 301 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 302 | /* 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 | |
| 392 | DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT); |
| 393 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 394 | static int dm_test_scmi_clocks(struct unit_test_state *uts) |
| 395 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 396 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 397 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 398 | struct udevice *agent_dev, *clock_dev, *dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 399 | int ret_dev; |
| 400 | int ret; |
| 401 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 402 | if (!CONFIG_IS_ENABLED(CLK_SCMI)) |
| 403 | return -EAGAIN; |
| 404 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 405 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 406 | if (ret) |
| 407 | return ret; |
| 408 | |
| 409 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 410 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 411 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 412 | /* 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 Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 420 | /* Test SCMI clocks rate manipulation */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 421 | 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 Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 425 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 426 | ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 427 | |
| 428 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); |
| 429 | ut_assert(!ret_dev || ret_dev == 1088); |
| 430 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 431 | ut_asserteq(1088, agent->clk[0].rate); |
| 432 | ut_asserteq(200, agent->clk[1].rate); |
| 433 | ut_asserteq(1000, agent->clk[2].rate); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 434 | |
| 435 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 436 | ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 437 | |
| 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 Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 443 | ut_assert(!agent->clk[0].enabled); |
| 444 | ut_assert(!agent->clk[1].enabled); |
| 445 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 446 | |
| 447 | ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 448 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 449 | ut_assert(agent->clk[0].enabled); |
| 450 | ut_assert(!agent->clk[1].enabled); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 451 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 452 | |
| 453 | ut_assertok(clk_disable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 454 | |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 455 | ut_assert(!agent->clk[0].enabled); |
| 456 | ut_assert(!agent->clk[1].enabled); |
| 457 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 458 | |
| 459 | return release_sandbox_scmi_test_devices(uts, dev); |
| 460 | } |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 461 | DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 462 | |
| 463 | static int dm_test_scmi_resets(struct unit_test_state *uts) |
| 464 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 465 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 466 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 467 | struct udevice *agent_dev, *reset_dev, *dev = NULL; |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 468 | int ret; |
| 469 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 470 | if (!CONFIG_IS_ENABLED(RESET_SCMI)) |
| 471 | return -EAGAIN; |
| 472 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 473 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 474 | if (ret) |
| 475 | return ret; |
| 476 | |
| 477 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 478 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 479 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 480 | /* 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 Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 488 | /* Test SCMI resect controller manipulation */ |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 489 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 490 | |
| 491 | ut_assertok(reset_assert(&scmi_devices->reset[0])); |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 492 | ut_assert(agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 493 | |
| 494 | ut_assertok(reset_deassert(&scmi_devices->reset[0])); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 495 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 496 | |
| 497 | return release_sandbox_scmi_test_devices(uts, dev); |
| 498 | } |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 499 | DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 500 | |
| 501 | static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) |
| 502 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 503 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 504 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 505 | struct dm_regulator_uclass_plat *uc_pdata; |
| 506 | struct udevice *dev; |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 507 | struct udevice *regul0_dev; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 508 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 509 | if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 510 | return -EAGAIN; |
| 511 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 512 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 513 | |
| 514 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 515 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 516 | |
| 517 | /* Set/Get an SCMI voltage domain level */ |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 518 | regul0_dev = scmi_devices->regul[0]; |
| 519 | ut_assert(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 520 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 521 | uc_pdata = dev_get_uclass_plat(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 522 | ut_assert(uc_pdata); |
| 523 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 524 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 525 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 526 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 527 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 528 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 529 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 530 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 531 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 532 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 533 | |
| 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 Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 537 | ut_assert(!agent->voltd[0].enabled); |
| 538 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 539 | |
| 540 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 541 | ut_assert(agent->voltd[0].enabled); |
| 542 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 543 | |
| 544 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 545 | ut_assert(agent->voltd[0].enabled); |
| 546 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 547 | |
| 548 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 549 | ut_assert(!agent->voltd[0].enabled); |
| 550 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 551 | |
| 552 | return release_sandbox_scmi_test_devices(uts, dev); |
| 553 | } |
| 554 | DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT); |