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 | |
| 15 | #include <common.h> |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 16 | #include <clk.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 18 | #include <reset.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 19 | #include <scmi_agent.h> |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 20 | #include <scmi_agent-uclass.h> |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 21 | #include <scmi_protocols.h> |
AKASHI Takahiro | 3d6fe58 | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 22 | #include <vsprintf.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 23 | #include <asm/scmi_test.h> |
| 24 | #include <dm/device-internal.h> |
| 25 | #include <dm/test.h> |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 26 | #include <power/regulator.h> |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 27 | #include <test/ut.h> |
| 28 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 29 | static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 30 | struct sandbox_scmi_agent *agent, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 31 | struct udevice *dev) |
| 32 | { |
| 33 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 34 | |
| 35 | /* Device references to check context against test sequence */ |
| 36 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 37 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 38 | ut_asserteq(2, scmi_devices->clk_count); |
Etienne Carriere | c3bba70 | 2021-03-08 22:38:08 +0100 | [diff] [blame] | 39 | ut_asserteq(1, scmi_devices->reset_count); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 40 | ut_asserteq(2, scmi_devices->regul_count); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 41 | |
| 42 | /* State of the simulated SCMI server exposed */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 43 | ut_asserteq(3, agent->clk_count); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 44 | 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 Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int load_sandbox_scmi_test_devices(struct unit_test_state *uts, |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 54 | struct sandbox_scmi_agent **ctx, |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 55 | struct udevice **dev) |
| 56 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 57 | struct udevice *agent_dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 58 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 59 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 60 | &agent_dev)); |
| 61 | ut_assertnonnull(agent_dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 62 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 63 | *ctx = sandbox_scmi_agent_ctx(agent_dev); |
| 64 | ut_assertnonnull(*ctx); |
| 65 | |
| 66 | /* probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 67 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi", |
| 68 | dev)); |
| 69 | ut_assertnonnull(*dev); |
| 70 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 71 | return ut_assert_scmi_state_postprobe(uts, *ctx, *dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, |
| 75 | struct udevice *dev) |
| 76 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 77 | /* un-probe */ |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 78 | ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); |
| 79 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 83 | /* |
| 84 | * Test SCMI states when loading and releasing resources |
| 85 | * related to SCMI drivers. |
| 86 | */ |
| 87 | static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) |
| 88 | { |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 89 | struct sandbox_scmi_agent *ctx; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 90 | struct udevice *dev = NULL; |
| 91 | int ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 92 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 93 | ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 94 | if (!ret) |
| 95 | ret = release_sandbox_scmi_test_devices(uts, dev); |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 96 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 97 | return ret; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 98 | } |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 99 | DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 100 | |
AKASHI Takahiro | 93ecae9 | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 101 | static 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 | |
| 207 | DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT); |
| 208 | |
AKASHI Takahiro | 3d6fe58 | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 209 | static int dm_test_scmi_cmd(struct unit_test_state *uts) |
| 210 | { |
| 211 | struct udevice *agent_dev; |
| 212 | int num_proto = 0; |
| 213 | char cmd_out[30]; |
| 214 | |
| 215 | if (!CONFIG_IS_ENABLED(CMD_SCMI)) |
| 216 | return -EAGAIN; |
| 217 | |
| 218 | /* preparation */ |
| 219 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 220 | &agent_dev)); |
| 221 | ut_assertnonnull(agent_dev); |
| 222 | |
| 223 | /* |
| 224 | * Estimate the number of provided protocols. |
| 225 | * This estimation is correct as far as a corresponding |
| 226 | * protocol support is added to sandbox fake serer. |
| 227 | */ |
| 228 | if (CONFIG_IS_ENABLED(POWER_DOMAIN)) |
| 229 | num_proto++; |
| 230 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 231 | num_proto++; |
| 232 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 233 | num_proto++; |
| 234 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 235 | num_proto++; |
| 236 | |
| 237 | /* scmi info */ |
| 238 | ut_assertok(run_command("scmi info", 0)); |
| 239 | |
| 240 | ut_assert_nextline("SCMI device: scmi"); |
| 241 | snprintf(cmd_out, 30, " protocol version: 0x%x", |
| 242 | SCMI_BASE_PROTOCOL_VERSION); |
| 243 | ut_assert_nextline(cmd_out); |
| 244 | ut_assert_nextline(" # of agents: 2"); |
| 245 | ut_assert_nextline(" 0: platform"); |
| 246 | ut_assert_nextline(" > 1: OSPM"); |
| 247 | snprintf(cmd_out, 30, " # of protocols: %d", num_proto); |
| 248 | ut_assert_nextline(cmd_out); |
| 249 | if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 250 | ut_assert_nextline(" Power domain management"); |
| 251 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 252 | ut_assert_nextline(" Clock management"); |
| 253 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 254 | ut_assert_nextline(" Reset domain management"); |
| 255 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 256 | ut_assert_nextline(" Voltage domain management"); |
| 257 | ut_assert_nextline(" vendor: U-Boot"); |
| 258 | ut_assert_nextline(" sub vendor: Sandbox"); |
| 259 | ut_assert_nextline(" impl version: 0x1"); |
| 260 | |
| 261 | ut_assert_console_end(); |
| 262 | |
| 263 | /* scmi perm_dev */ |
| 264 | ut_assertok(run_command("scmi perm_dev 1 0 1", 0)); |
| 265 | ut_assert_console_end(); |
| 266 | |
| 267 | ut_assert(run_command("scmi perm_dev 1 0 0", 0)); |
| 268 | ut_assert_nextline("Denying access to device:0 failed (-13)"); |
| 269 | ut_assert_console_end(); |
| 270 | |
| 271 | /* scmi perm_proto */ |
| 272 | ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0)); |
| 273 | ut_assert_console_end(); |
| 274 | |
| 275 | ut_assert(run_command("scmi perm_proto 1 0 14 0", 0)); |
| 276 | ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed (-13)"); |
| 277 | ut_assert_console_end(); |
| 278 | |
| 279 | /* scmi reset */ |
| 280 | ut_assert(run_command("scmi reset 1 1", 0)); |
| 281 | ut_assert_nextline("Reset failed (-13)"); |
| 282 | ut_assert_console_end(); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT); |
| 288 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 289 | static int dm_test_scmi_power_domains(struct unit_test_state *uts) |
| 290 | { |
| 291 | struct sandbox_scmi_agent *agent; |
| 292 | struct sandbox_scmi_devices *scmi_devices; |
| 293 | struct udevice *agent_dev, *pwd, *dev; |
| 294 | u32 version, count, attributes, pstate; |
| 295 | u64 stats_addr; |
| 296 | size_t stats_len; |
| 297 | u8 *name; |
| 298 | int ret; |
| 299 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 300 | if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 301 | return -EAGAIN; |
| 302 | |
AKASHI Takahiro | 2ba0f82 | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 303 | /* preparation */ |
| 304 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
| 305 | ut_assertnonnull(agent); |
| 306 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
| 307 | ut_assertnonnull(scmi_devices); |
| 308 | ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */ |
| 309 | |
| 310 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 311 | &agent_dev)); |
| 312 | ut_assertnonnull(agent_dev); |
| 313 | pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN); |
| 314 | ut_assertnonnull(pwd); |
| 315 | |
| 316 | /* |
| 317 | * SCMI Power domain management protocol interfaces |
| 318 | */ |
| 319 | /* version */ |
| 320 | ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN, |
| 321 | &version); |
| 322 | ut_assertok(ret); |
| 323 | ut_asserteq(agent->pwdom_version, version); |
| 324 | |
| 325 | /* protocol attributes */ |
| 326 | ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len); |
| 327 | ut_assertok(ret); |
| 328 | ut_asserteq(agent->pwdom_count, count); |
| 329 | ut_asserteq(0, stats_len); |
| 330 | |
| 331 | /* protocol message attributes */ |
| 332 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET, |
| 333 | &attributes); |
| 334 | ut_assertok(ret); |
| 335 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY, |
| 336 | &attributes); |
| 337 | ut_asserteq(-ENOENT, ret); /* the protocol not supported */ |
| 338 | |
| 339 | /* power domain attributes */ |
| 340 | ret = scmi_pwd_attrs(pwd, 0, &attributes, &name); |
| 341 | ut_assertok(ret); |
| 342 | ut_asserteq_str("power-domain--0", name); |
| 343 | free(name); |
| 344 | |
| 345 | ret = scmi_pwd_attrs(pwd, 10, &attributes, &name); |
| 346 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 347 | |
| 348 | /* power domain state set/get */ |
| 349 | ret = scmi_pwd_state_set(pwd, 0, 0, 0); |
| 350 | ut_assertok(ret); |
| 351 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 352 | ut_assertok(ret); |
| 353 | ut_asserteq(0, pstate); /* ON */ |
| 354 | |
| 355 | ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST); |
| 356 | ut_assertok(ret); |
| 357 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 358 | ut_assertok(ret); |
| 359 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 360 | |
| 361 | ret = scmi_pwd_state_set(pwd, 0, 10, 0); |
| 362 | ut_asserteq(-ENOENT, ret); |
| 363 | |
| 364 | /* power domain name get */ |
| 365 | ret = scmi_pwd_name_get(pwd, 0, &name); |
| 366 | ut_assertok(ret); |
| 367 | ut_asserteq_str("power-domain--0-extended", name); |
| 368 | free(name); |
| 369 | |
| 370 | ret = scmi_pwd_name_get(pwd, 10, &name); |
| 371 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 372 | |
| 373 | /* |
| 374 | * U-Boot driver model interfaces |
| 375 | */ |
| 376 | /* power_domain_on */ |
| 377 | ret = power_domain_on(scmi_devices->pwdom); |
| 378 | ut_assertok(ret); |
| 379 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 380 | ut_assertok(ret); |
| 381 | ut_asserteq(0, pstate); /* ON */ |
| 382 | |
| 383 | /* power_domain_off */ |
| 384 | ret = power_domain_off(scmi_devices->pwdom); |
| 385 | ut_assertok(ret); |
| 386 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 387 | ut_assertok(ret); |
| 388 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 389 | |
| 390 | return release_sandbox_scmi_test_devices(uts, dev); |
| 391 | } |
| 392 | |
| 393 | DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT); |
| 394 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 395 | static int dm_test_scmi_clocks(struct unit_test_state *uts) |
| 396 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 397 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 398 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 399 | struct udevice *agent_dev, *clock_dev, *dev; |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 400 | int ret_dev; |
| 401 | int ret; |
| 402 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 403 | if (!CONFIG_IS_ENABLED(CLK_SCMI)) |
| 404 | return -EAGAIN; |
| 405 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 406 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 407 | if (ret) |
| 408 | return ret; |
| 409 | |
| 410 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 411 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 412 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 413 | /* Sandbox SCMI clock protocol has its own channel */ |
| 414 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 415 | &agent_dev)); |
| 416 | ut_assertnonnull(agent_dev); |
| 417 | clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK); |
| 418 | ut_assertnonnull(clock_dev); |
| 419 | ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev)); |
| 420 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 421 | /* Test SCMI clocks rate manipulation */ |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 422 | ut_asserteq(333, agent->clk[0].rate); |
| 423 | ut_asserteq(200, agent->clk[1].rate); |
| 424 | ut_asserteq(1000, agent->clk[2].rate); |
| 425 | |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 426 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 427 | ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 428 | |
| 429 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); |
| 430 | ut_assert(!ret_dev || ret_dev == 1088); |
| 431 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 432 | ut_asserteq(1088, agent->clk[0].rate); |
| 433 | ut_asserteq(200, agent->clk[1].rate); |
| 434 | ut_asserteq(1000, agent->clk[2].rate); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 435 | |
| 436 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 437 | ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 438 | |
| 439 | /* restore original rate for further tests */ |
| 440 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 333); |
| 441 | ut_assert(!ret_dev || ret_dev == 333); |
| 442 | |
| 443 | /* Test SCMI clocks gating manipulation */ |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 444 | ut_assert(!agent->clk[0].enabled); |
| 445 | ut_assert(!agent->clk[1].enabled); |
| 446 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 447 | |
| 448 | ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 449 | |
Etienne Carriere | 10d3e5d | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 450 | ut_assert(agent->clk[0].enabled); |
| 451 | ut_assert(!agent->clk[1].enabled); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 452 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 453 | |
| 454 | ut_assertok(clk_disable(&scmi_devices->clk[1])); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 455 | |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 456 | ut_assert(!agent->clk[0].enabled); |
| 457 | ut_assert(!agent->clk[1].enabled); |
| 458 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 459 | |
| 460 | return release_sandbox_scmi_test_devices(uts, dev); |
| 461 | } |
Etienne Carriere | 87d4f27 | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 462 | DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 463 | |
| 464 | static int dm_test_scmi_resets(struct unit_test_state *uts) |
| 465 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 466 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 467 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 468 | struct udevice *agent_dev, *reset_dev, *dev = NULL; |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 469 | int ret; |
| 470 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 471 | if (!CONFIG_IS_ENABLED(RESET_SCMI)) |
| 472 | return -EAGAIN; |
| 473 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 474 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 475 | if (ret) |
| 476 | return ret; |
| 477 | |
| 478 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 479 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 480 | |
AKASHI Takahiro | a89d9f4 | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 481 | /* Sandbox SCMI reset protocol doesn't have its own channel */ |
| 482 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 483 | &agent_dev)); |
| 484 | ut_assertnonnull(agent_dev); |
| 485 | reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN); |
| 486 | ut_assertnonnull(reset_dev); |
| 487 | ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev)); |
| 488 | |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 489 | /* Test SCMI resect controller manipulation */ |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 490 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 491 | |
| 492 | ut_assertok(reset_assert(&scmi_devices->reset[0])); |
Marek Vasut | fa847bb | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 493 | ut_assert(agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 494 | |
| 495 | ut_assertok(reset_deassert(&scmi_devices->reset[0])); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 496 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 497 | |
| 498 | return release_sandbox_scmi_test_devices(uts, dev); |
| 499 | } |
Etienne Carriere | c0dd177 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 500 | DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 501 | |
| 502 | static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) |
| 503 | { |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 504 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 505 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 506 | struct dm_regulator_uclass_plat *uc_pdata; |
| 507 | struct udevice *dev; |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 508 | struct udevice *regul0_dev; |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 509 | |
AKASHI Takahiro | 63cd0dc | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 510 | if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 511 | return -EAGAIN; |
| 512 | |
AKASHI Takahiro | bddcd3a | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 513 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 514 | |
| 515 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 516 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 517 | |
| 518 | /* Set/Get an SCMI voltage domain level */ |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 519 | regul0_dev = scmi_devices->regul[0]; |
| 520 | ut_assert(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 521 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 522 | uc_pdata = dev_get_uclass_plat(regul0_dev); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 523 | ut_assert(uc_pdata); |
| 524 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 525 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 526 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 527 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 528 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 529 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 530 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 531 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 532 | |
Etienne Carriere | 3dfd739 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 533 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 534 | |
| 535 | /* Enable/disable SCMI voltage domains */ |
| 536 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
| 537 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], false)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 538 | ut_assert(!agent->voltd[0].enabled); |
| 539 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 540 | |
| 541 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 542 | ut_assert(agent->voltd[0].enabled); |
| 543 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 544 | |
| 545 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], true)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 546 | ut_assert(agent->voltd[0].enabled); |
| 547 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 548 | |
| 549 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
Etienne Carriere | 41d62e2 | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 550 | ut_assert(!agent->voltd[0].enabled); |
| 551 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | 0124218 | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 552 | |
| 553 | return release_sandbox_scmi_test_devices(uts, dev); |
| 554 | } |
| 555 | DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT); |