Etienne Carriere | 02fd126 | 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 | 09665cb | 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 | 71cc021 | 2022-12-02 14:23:07 +0800 | [diff] [blame] | 9 | * implemented in U-Boot SCMI components but the implementation is expected |
Etienne Carriere | 02fd126 | 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 | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 16 | #include <clk.h> |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 18 | #include <reset.h> |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 19 | #include <scmi_agent.h> |
AKASHI Takahiro | 49f366b | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 20 | #include <scmi_agent-uclass.h> |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 21 | #include <scmi_protocols.h> |
AKASHI Takahiro | d40686d | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 22 | #include <vsprintf.h> |
Etienne Carriere | 02fd126 | 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 | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 26 | #include <linux/kconfig.h> |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 27 | #include <power/regulator.h> |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 28 | #include <test/ut.h> |
| 29 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 30 | static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts, |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 31 | struct sandbox_scmi_agent *agent, |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 32 | struct udevice *dev) |
| 33 | { |
| 34 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 35 | |
| 36 | /* Device references to check context against test sequence */ |
| 37 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 38 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 39 | ut_asserteq(2, scmi_devices->clk_count); |
Etienne Carriere | c83a843 | 2021-03-08 22:38:08 +0100 | [diff] [blame] | 40 | ut_asserteq(1, scmi_devices->reset_count); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 41 | ut_asserteq(2, scmi_devices->regul_count); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 42 | |
| 43 | /* State of the simulated SCMI server exposed */ |
Etienne Carriere | bf1f132 | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 44 | ut_asserteq(3, agent->clk_count); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 45 | ut_assertnonnull(agent->clk); |
| 46 | ut_asserteq(1, agent->reset_count); |
| 47 | ut_assertnonnull(agent->reset); |
| 48 | ut_asserteq(2, agent->voltd_count); |
| 49 | ut_assertnonnull(agent->voltd); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int load_sandbox_scmi_test_devices(struct unit_test_state *uts, |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 55 | struct sandbox_scmi_agent **ctx, |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 56 | struct udevice **dev) |
| 57 | { |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 58 | struct udevice *agent_dev; |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 59 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 60 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 61 | &agent_dev)); |
| 62 | ut_assertnonnull(agent_dev); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 63 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 64 | *ctx = sandbox_scmi_agent_ctx(agent_dev); |
| 65 | ut_assertnonnull(*ctx); |
| 66 | |
| 67 | /* probe */ |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 68 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi", |
| 69 | dev)); |
| 70 | ut_assertnonnull(*dev); |
| 71 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 72 | return ut_assert_scmi_state_postprobe(uts, *ctx, *dev); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static int release_sandbox_scmi_test_devices(struct unit_test_state *uts, |
| 76 | struct udevice *dev) |
| 77 | { |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 78 | /* un-probe */ |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 79 | ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); |
| 80 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 84 | /* |
| 85 | * Test SCMI states when loading and releasing resources |
| 86 | * related to SCMI drivers. |
| 87 | */ |
| 88 | static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts) |
| 89 | { |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 90 | struct sandbox_scmi_agent *ctx; |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 91 | struct udevice *dev = NULL; |
| 92 | int ret; |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 93 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 94 | ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 95 | if (!ret) |
| 96 | ret = release_sandbox_scmi_test_devices(uts, dev); |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 97 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 98 | return ret; |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 99 | } |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 100 | DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 101 | |
AKASHI Takahiro | 49f366b | 2023-10-11 19:07:06 +0900 | [diff] [blame] | 102 | static int dm_test_scmi_base(struct unit_test_state *uts) |
| 103 | { |
| 104 | struct udevice *agent_dev, *base; |
| 105 | struct scmi_agent_priv *priv; |
| 106 | u32 version, num_agents, num_protocols, impl_version; |
| 107 | u32 attributes, agent_id; |
| 108 | u8 *vendor, *agent_name, *protocols; |
| 109 | int ret; |
| 110 | |
| 111 | /* preparation */ |
| 112 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 113 | &agent_dev)); |
| 114 | ut_assertnonnull(agent_dev); |
| 115 | ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev)); |
| 116 | ut_assertnonnull(base = scmi_get_protocol(agent_dev, |
| 117 | SCMI_PROTOCOL_ID_BASE)); |
| 118 | |
| 119 | /* version */ |
| 120 | ret = scmi_base_protocol_version(base, &version); |
| 121 | ut_assertok(ret); |
| 122 | ut_asserteq(priv->version, version); |
| 123 | |
| 124 | /* protocol attributes */ |
| 125 | ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols); |
| 126 | ut_assertok(ret); |
| 127 | ut_asserteq(priv->num_agents, num_agents); |
| 128 | ut_asserteq(priv->num_protocols, num_protocols); |
| 129 | |
| 130 | /* discover vendor */ |
| 131 | ret = scmi_base_discover_vendor(base, &vendor); |
| 132 | ut_assertok(ret); |
| 133 | ut_asserteq_str(priv->vendor, vendor); |
| 134 | free(vendor); |
| 135 | |
| 136 | /* message attributes */ |
| 137 | ret = scmi_base_protocol_message_attrs(base, |
| 138 | SCMI_BASE_DISCOVER_SUB_VENDOR, |
| 139 | &attributes); |
| 140 | ut_assertok(ret); |
| 141 | ut_assertok(attributes); |
| 142 | |
| 143 | /* discover sub vendor */ |
| 144 | ret = scmi_base_discover_sub_vendor(base, &vendor); |
| 145 | ut_assertok(ret); |
| 146 | ut_asserteq_str(priv->sub_vendor, vendor); |
| 147 | free(vendor); |
| 148 | |
| 149 | /* impl version */ |
| 150 | ret = scmi_base_discover_impl_version(base, &impl_version); |
| 151 | ut_assertok(ret); |
| 152 | ut_asserteq(priv->impl_version, impl_version); |
| 153 | |
| 154 | /* discover agent (my self) */ |
| 155 | ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id, |
| 156 | &agent_name); |
| 157 | ut_assertok(ret); |
| 158 | ut_asserteq(priv->agent_id, agent_id); |
| 159 | ut_asserteq_str(priv->agent_name, agent_name); |
| 160 | free(agent_name); |
| 161 | |
| 162 | /* discover protocols */ |
| 163 | ret = scmi_base_discover_list_protocols(base, &protocols); |
| 164 | ut_asserteq(num_protocols, ret); |
| 165 | ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols); |
| 166 | free(protocols); |
| 167 | |
| 168 | /* |
| 169 | * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting |
| 170 | * access and protocol permissions, but doesn't allow unsetting them nor |
| 171 | * resetting the configurations. |
| 172 | */ |
| 173 | /* set device permissions */ |
| 174 | ret = scmi_base_set_device_permissions(base, agent_id, 0, |
| 175 | SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); |
| 176 | ut_assertok(ret); /* SCMI_SUCCESS */ |
| 177 | ret = scmi_base_set_device_permissions(base, agent_id, 1, |
| 178 | SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS); |
| 179 | ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ |
| 180 | ret = scmi_base_set_device_permissions(base, agent_id, 0, 0); |
| 181 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 182 | |
| 183 | /* set protocol permissions */ |
| 184 | ret = scmi_base_set_protocol_permissions(base, agent_id, 0, |
| 185 | SCMI_PROTOCOL_ID_CLOCK, |
| 186 | SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); |
| 187 | ut_assertok(ret); /* SCMI_SUCCESS */ |
| 188 | ret = scmi_base_set_protocol_permissions(base, agent_id, 1, |
| 189 | SCMI_PROTOCOL_ID_CLOCK, |
| 190 | SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS); |
| 191 | ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */ |
| 192 | ret = scmi_base_set_protocol_permissions(base, agent_id, 0, |
| 193 | SCMI_PROTOCOL_ID_CLOCK, 0); |
| 194 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 195 | |
| 196 | /* reset agent configuration */ |
| 197 | ret = scmi_base_reset_agent_configuration(base, agent_id, 0); |
| 198 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 199 | ret = scmi_base_reset_agent_configuration(base, agent_id, |
| 200 | SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS); |
| 201 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 202 | ret = scmi_base_reset_agent_configuration(base, agent_id, 0); |
| 203 | ut_asserteq(-EACCES, ret); /* SCMI_DENIED */ |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT); |
| 209 | |
AKASHI Takahiro | d40686d | 2023-11-14 11:14:28 +0900 | [diff] [blame] | 210 | static int dm_test_scmi_cmd(struct unit_test_state *uts) |
| 211 | { |
| 212 | struct udevice *agent_dev; |
| 213 | int num_proto = 0; |
| 214 | char cmd_out[30]; |
| 215 | |
| 216 | if (!CONFIG_IS_ENABLED(CMD_SCMI)) |
| 217 | return -EAGAIN; |
| 218 | |
| 219 | /* preparation */ |
| 220 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 221 | &agent_dev)); |
| 222 | ut_assertnonnull(agent_dev); |
| 223 | |
| 224 | /* |
| 225 | * Estimate the number of provided protocols. |
| 226 | * This estimation is correct as far as a corresponding |
| 227 | * protocol support is added to sandbox fake serer. |
| 228 | */ |
| 229 | if (CONFIG_IS_ENABLED(POWER_DOMAIN)) |
| 230 | num_proto++; |
| 231 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 232 | num_proto++; |
| 233 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 234 | num_proto++; |
| 235 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 236 | num_proto++; |
| 237 | |
| 238 | /* scmi info */ |
| 239 | ut_assertok(run_command("scmi info", 0)); |
| 240 | |
| 241 | ut_assert_nextline("SCMI device: scmi"); |
| 242 | snprintf(cmd_out, 30, " protocol version: 0x%x", |
| 243 | SCMI_BASE_PROTOCOL_VERSION); |
| 244 | ut_assert_nextline(cmd_out); |
| 245 | ut_assert_nextline(" # of agents: 2"); |
| 246 | ut_assert_nextline(" 0: platform"); |
| 247 | ut_assert_nextline(" > 1: OSPM"); |
| 248 | snprintf(cmd_out, 30, " # of protocols: %d", num_proto); |
| 249 | ut_assert_nextline(cmd_out); |
| 250 | if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 251 | ut_assert_nextline(" Power domain management"); |
| 252 | if (CONFIG_IS_ENABLED(CLK_SCMI)) |
| 253 | ut_assert_nextline(" Clock management"); |
| 254 | if (CONFIG_IS_ENABLED(RESET_SCMI)) |
| 255 | ut_assert_nextline(" Reset domain management"); |
| 256 | if (CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 257 | ut_assert_nextline(" Voltage domain management"); |
| 258 | ut_assert_nextline(" vendor: U-Boot"); |
| 259 | ut_assert_nextline(" sub vendor: Sandbox"); |
| 260 | ut_assert_nextline(" impl version: 0x1"); |
| 261 | |
| 262 | ut_assert_console_end(); |
| 263 | |
| 264 | /* scmi perm_dev */ |
| 265 | ut_assertok(run_command("scmi perm_dev 1 0 1", 0)); |
| 266 | ut_assert_console_end(); |
| 267 | |
| 268 | ut_assert(run_command("scmi perm_dev 1 0 0", 0)); |
| 269 | ut_assert_nextline("Denying access to device:0 failed (-13)"); |
| 270 | ut_assert_console_end(); |
| 271 | |
| 272 | /* scmi perm_proto */ |
| 273 | ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0)); |
| 274 | ut_assert_console_end(); |
| 275 | |
| 276 | ut_assert(run_command("scmi perm_proto 1 0 14 0", 0)); |
| 277 | ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed (-13)"); |
| 278 | ut_assert_console_end(); |
| 279 | |
| 280 | /* scmi reset */ |
| 281 | ut_assert(run_command("scmi reset 1 1", 0)); |
| 282 | ut_assert_nextline("Reset failed (-13)"); |
| 283 | ut_assert_console_end(); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT); |
| 289 | |
AKASHI Takahiro | 9e3474d | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 290 | static int dm_test_scmi_power_domains(struct unit_test_state *uts) |
| 291 | { |
| 292 | struct sandbox_scmi_agent *agent; |
| 293 | struct sandbox_scmi_devices *scmi_devices; |
| 294 | struct udevice *agent_dev, *pwd, *dev; |
| 295 | u32 version, count, attributes, pstate; |
| 296 | u64 stats_addr; |
| 297 | size_t stats_len; |
| 298 | u8 *name; |
| 299 | int ret; |
| 300 | |
AKASHI Takahiro | 08372eb | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 301 | if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN)) |
| 302 | return -EAGAIN; |
| 303 | |
AKASHI Takahiro | 9e3474d | 2023-10-16 14:39:46 +0900 | [diff] [blame] | 304 | /* preparation */ |
| 305 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
| 306 | ut_assertnonnull(agent); |
| 307 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
| 308 | ut_assertnonnull(scmi_devices); |
| 309 | ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */ |
| 310 | |
| 311 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 312 | &agent_dev)); |
| 313 | ut_assertnonnull(agent_dev); |
| 314 | pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN); |
| 315 | ut_assertnonnull(pwd); |
| 316 | |
| 317 | /* |
| 318 | * SCMI Power domain management protocol interfaces |
| 319 | */ |
| 320 | /* version */ |
| 321 | ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN, |
| 322 | &version); |
| 323 | ut_assertok(ret); |
| 324 | ut_asserteq(agent->pwdom_version, version); |
| 325 | |
| 326 | /* protocol attributes */ |
| 327 | ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len); |
| 328 | ut_assertok(ret); |
| 329 | ut_asserteq(agent->pwdom_count, count); |
| 330 | ut_asserteq(0, stats_len); |
| 331 | |
| 332 | /* protocol message attributes */ |
| 333 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET, |
| 334 | &attributes); |
| 335 | ut_assertok(ret); |
| 336 | ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY, |
| 337 | &attributes); |
| 338 | ut_asserteq(-ENOENT, ret); /* the protocol not supported */ |
| 339 | |
| 340 | /* power domain attributes */ |
| 341 | ret = scmi_pwd_attrs(pwd, 0, &attributes, &name); |
| 342 | ut_assertok(ret); |
| 343 | ut_asserteq_str("power-domain--0", name); |
| 344 | free(name); |
| 345 | |
| 346 | ret = scmi_pwd_attrs(pwd, 10, &attributes, &name); |
| 347 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 348 | |
| 349 | /* power domain state set/get */ |
| 350 | ret = scmi_pwd_state_set(pwd, 0, 0, 0); |
| 351 | ut_assertok(ret); |
| 352 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 353 | ut_assertok(ret); |
| 354 | ut_asserteq(0, pstate); /* ON */ |
| 355 | |
| 356 | ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST); |
| 357 | ut_assertok(ret); |
| 358 | ret = scmi_pwd_state_get(pwd, 0, &pstate); |
| 359 | ut_assertok(ret); |
| 360 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 361 | |
| 362 | ret = scmi_pwd_state_set(pwd, 0, 10, 0); |
| 363 | ut_asserteq(-ENOENT, ret); |
| 364 | |
| 365 | /* power domain name get */ |
| 366 | ret = scmi_pwd_name_get(pwd, 0, &name); |
| 367 | ut_assertok(ret); |
| 368 | ut_asserteq_str("power-domain--0-extended", name); |
| 369 | free(name); |
| 370 | |
| 371 | ret = scmi_pwd_name_get(pwd, 10, &name); |
| 372 | ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */ |
| 373 | |
| 374 | /* |
| 375 | * U-Boot driver model interfaces |
| 376 | */ |
| 377 | /* power_domain_on */ |
| 378 | ret = power_domain_on(scmi_devices->pwdom); |
| 379 | ut_assertok(ret); |
| 380 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 381 | ut_assertok(ret); |
| 382 | ut_asserteq(0, pstate); /* ON */ |
| 383 | |
| 384 | /* power_domain_off */ |
| 385 | ret = power_domain_off(scmi_devices->pwdom); |
| 386 | ut_assertok(ret); |
| 387 | ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate); |
| 388 | ut_assertok(ret); |
| 389 | ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */ |
| 390 | |
| 391 | return release_sandbox_scmi_test_devices(uts, dev); |
| 392 | } |
| 393 | |
| 394 | DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT); |
| 395 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 396 | static int dm_test_scmi_clocks(struct unit_test_state *uts) |
| 397 | { |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 398 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 399 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 400 | struct udevice *agent_dev, *clock_dev, *dev; |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 401 | int ret_dev; |
| 402 | int ret; |
| 403 | |
AKASHI Takahiro | 08372eb | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 404 | if (!CONFIG_IS_ENABLED(CLK_SCMI)) |
| 405 | return -EAGAIN; |
| 406 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 407 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 408 | if (ret) |
| 409 | return ret; |
| 410 | |
| 411 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 412 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 413 | |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 414 | /* Sandbox SCMI clock protocol has its own channel */ |
| 415 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 416 | &agent_dev)); |
| 417 | ut_assertnonnull(agent_dev); |
| 418 | clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK); |
| 419 | ut_assertnonnull(clock_dev); |
| 420 | ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev)); |
| 421 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 422 | /* Test SCMI clocks rate manipulation */ |
Etienne Carriere | bf1f132 | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 423 | ut_asserteq(333, agent->clk[0].rate); |
| 424 | ut_asserteq(200, agent->clk[1].rate); |
| 425 | ut_asserteq(1000, agent->clk[2].rate); |
| 426 | |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 427 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 428 | ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 429 | |
| 430 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088); |
| 431 | ut_assert(!ret_dev || ret_dev == 1088); |
| 432 | |
Etienne Carriere | bf1f132 | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 433 | ut_asserteq(1088, agent->clk[0].rate); |
| 434 | ut_asserteq(200, agent->clk[1].rate); |
| 435 | ut_asserteq(1000, agent->clk[2].rate); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 436 | |
| 437 | ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0])); |
| 438 | ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1])); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 439 | |
| 440 | /* restore original rate for further tests */ |
| 441 | ret_dev = clk_set_rate(&scmi_devices->clk[1], 333); |
| 442 | ut_assert(!ret_dev || ret_dev == 333); |
| 443 | |
| 444 | /* Test SCMI clocks gating manipulation */ |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 445 | ut_assert(!agent->clk[0].enabled); |
| 446 | ut_assert(!agent->clk[1].enabled); |
| 447 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 448 | |
| 449 | ut_asserteq(0, clk_enable(&scmi_devices->clk[1])); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 450 | |
Etienne Carriere | bf1f132 | 2022-02-21 09:22:41 +0100 | [diff] [blame] | 451 | ut_assert(agent->clk[0].enabled); |
| 452 | ut_assert(!agent->clk[1].enabled); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 453 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 454 | |
| 455 | ut_assertok(clk_disable(&scmi_devices->clk[1])); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 456 | |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 457 | ut_assert(!agent->clk[0].enabled); |
| 458 | ut_assert(!agent->clk[1].enabled); |
| 459 | ut_assert(!agent->clk[2].enabled); |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 460 | |
| 461 | return release_sandbox_scmi_test_devices(uts, dev); |
| 462 | } |
Etienne Carriere | 2d94c08fa | 2020-09-09 18:44:05 +0200 | [diff] [blame] | 463 | DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 464 | |
| 465 | static int dm_test_scmi_resets(struct unit_test_state *uts) |
| 466 | { |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 467 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 468 | struct sandbox_scmi_devices *scmi_devices; |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 469 | struct udevice *agent_dev, *reset_dev, *dev = NULL; |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 470 | int ret; |
| 471 | |
AKASHI Takahiro | 08372eb | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 472 | if (!CONFIG_IS_ENABLED(RESET_SCMI)) |
| 473 | return -EAGAIN; |
| 474 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 475 | ret = load_sandbox_scmi_test_devices(uts, &agent, &dev); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 476 | if (ret) |
| 477 | return ret; |
| 478 | |
| 479 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 480 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 481 | |
AKASHI Takahiro | cc4ecda | 2023-10-11 19:06:59 +0900 | [diff] [blame] | 482 | /* Sandbox SCMI reset protocol doesn't have its own channel */ |
| 483 | ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi", |
| 484 | &agent_dev)); |
| 485 | ut_assertnonnull(agent_dev); |
| 486 | reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN); |
| 487 | ut_assertnonnull(reset_dev); |
| 488 | ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev)); |
| 489 | |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 490 | /* Test SCMI resect controller manipulation */ |
Marek Vasut | 1531c4e | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 491 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 492 | |
| 493 | ut_assertok(reset_assert(&scmi_devices->reset[0])); |
Marek Vasut | 1531c4e | 2023-03-10 04:33:13 +0100 | [diff] [blame] | 494 | ut_assert(agent->reset[0].asserted); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 495 | |
| 496 | ut_assertok(reset_deassert(&scmi_devices->reset[0])); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 497 | ut_assert(!agent->reset[0].asserted); |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 498 | |
| 499 | return release_sandbox_scmi_test_devices(uts, dev); |
| 500 | } |
Etienne Carriere | 8b9b689 | 2020-09-09 18:44:07 +0200 | [diff] [blame] | 501 | DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 502 | |
| 503 | static int dm_test_scmi_voltage_domains(struct unit_test_state *uts) |
| 504 | { |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 505 | struct sandbox_scmi_agent *agent; |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 506 | struct sandbox_scmi_devices *scmi_devices; |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 507 | struct dm_regulator_uclass_plat *uc_pdata; |
| 508 | struct udevice *dev; |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 509 | struct udevice *regul0_dev; |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 510 | |
AKASHI Takahiro | 08372eb | 2023-11-14 11:14:24 +0900 | [diff] [blame] | 511 | if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI)) |
| 512 | return -EAGAIN; |
| 513 | |
AKASHI Takahiro | dae0046 | 2023-10-11 19:07:03 +0900 | [diff] [blame] | 514 | ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev)); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 515 | |
| 516 | scmi_devices = sandbox_scmi_devices_ctx(dev); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 517 | ut_assertnonnull(scmi_devices); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 518 | |
| 519 | /* Set/Get an SCMI voltage domain level */ |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 520 | regul0_dev = scmi_devices->regul[0]; |
| 521 | ut_assert(regul0_dev); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 522 | |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 523 | uc_pdata = dev_get_uclass_plat(regul0_dev); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 524 | ut_assert(uc_pdata); |
| 525 | |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 526 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 527 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 528 | |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 529 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 530 | |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 531 | ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 532 | ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 533 | |
Etienne Carriere | eeaf282 | 2021-03-08 22:38:09 +0100 | [diff] [blame] | 534 | ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 535 | |
| 536 | /* Enable/disable SCMI voltage domains */ |
| 537 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
| 538 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], false)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 539 | ut_assert(!agent->voltd[0].enabled); |
| 540 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 541 | |
| 542 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], true)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 543 | ut_assert(agent->voltd[0].enabled); |
| 544 | ut_assert(!agent->voltd[1].enabled); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 545 | |
| 546 | ut_assertok(regulator_set_enable(scmi_devices->regul[1], true)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 547 | ut_assert(agent->voltd[0].enabled); |
| 548 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 549 | |
| 550 | ut_assertok(regulator_set_enable(scmi_devices->regul[0], false)); |
Etienne Carriere | 09665cb | 2022-02-21 09:22:39 +0100 | [diff] [blame] | 551 | ut_assert(!agent->voltd[0].enabled); |
| 552 | ut_assert(agent->voltd[1].enabled); |
Etienne Carriere | b8f15cd | 2021-03-08 22:38:07 +0100 | [diff] [blame] | 553 | |
| 554 | return release_sandbox_scmi_test_devices(uts, dev); |
| 555 | } |
| 556 | DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT); |