2020-09-09 16:44:00 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, Linaro Limited
|
|
|
|
*
|
|
|
|
* Tests scmi_agent uclass and the SCMI drivers implemented in other
|
|
|
|
* uclass devices probe when a SCMI server exposes resources.
|
|
|
|
*
|
2022-02-21 08:22:39 +00:00
|
|
|
* Note in test.dts the protocol@10 node in scmi node. Protocol 0x10 is not
|
2022-12-02 06:23:07 +00:00
|
|
|
* implemented in U-Boot SCMI components but the implementation is expected
|
2020-09-09 16:44:00 +00:00
|
|
|
* to not complain on unknown protocol IDs, as long as it is not used. Note
|
|
|
|
* in test.dts tests that SCMI drivers probing does not fail for such an
|
|
|
|
* unknown SCMI protocol ID.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-09-09 16:44:05 +00:00
|
|
|
#include <clk.h>
|
2020-09-09 16:44:00 +00:00
|
|
|
#include <dm.h>
|
2020-09-09 16:44:07 +00:00
|
|
|
#include <reset.h>
|
2023-10-11 10:06:59 +00:00
|
|
|
#include <scmi_agent.h>
|
2023-10-11 10:07:06 +00:00
|
|
|
#include <scmi_agent-uclass.h>
|
2023-10-11 10:06:59 +00:00
|
|
|
#include <scmi_protocols.h>
|
2020-09-09 16:44:00 +00:00
|
|
|
#include <asm/scmi_test.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/test.h>
|
2020-09-09 16:44:05 +00:00
|
|
|
#include <linux/kconfig.h>
|
2021-03-08 21:38:07 +00:00
|
|
|
#include <power/regulator.h>
|
2020-09-09 16:44:00 +00:00
|
|
|
#include <test/ut.h>
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_agent *agent,
|
2020-09-09 16:44:05 +00:00
|
|
|
struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_scmi_devices *scmi_devices;
|
|
|
|
|
|
|
|
/* Device references to check context against test sequence */
|
|
|
|
scmi_devices = sandbox_scmi_devices_ctx(dev);
|
|
|
|
ut_assertnonnull(scmi_devices);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_asserteq(2, scmi_devices->clk_count);
|
2021-03-08 21:38:08 +00:00
|
|
|
ut_asserteq(1, scmi_devices->reset_count);
|
2021-03-08 21:38:07 +00:00
|
|
|
ut_asserteq(2, scmi_devices->regul_count);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
/* State of the simulated SCMI server exposed */
|
2022-02-21 08:22:41 +00:00
|
|
|
ut_asserteq(3, agent->clk_count);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assertnonnull(agent->clk);
|
|
|
|
ut_asserteq(1, agent->reset_count);
|
|
|
|
ut_assertnonnull(agent->reset);
|
|
|
|
ut_asserteq(2, agent->voltd_count);
|
|
|
|
ut_assertnonnull(agent->voltd);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_sandbox_scmi_test_devices(struct unit_test_state *uts,
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_agent **ctx,
|
2020-09-09 16:44:05 +00:00
|
|
|
struct udevice **dev)
|
|
|
|
{
|
2023-10-11 10:07:03 +00:00
|
|
|
struct udevice *agent_dev;
|
2020-09-09 16:44:05 +00:00
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
|
|
|
|
&agent_dev));
|
|
|
|
ut_assertnonnull(agent_dev);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
*ctx = sandbox_scmi_agent_ctx(agent_dev);
|
|
|
|
ut_assertnonnull(*ctx);
|
|
|
|
|
|
|
|
/* probe */
|
2020-09-09 16:44:05 +00:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi",
|
|
|
|
dev));
|
|
|
|
ut_assertnonnull(*dev);
|
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
return ut_assert_scmi_state_postprobe(uts, *ctx, *dev);
|
2020-09-09 16:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int release_sandbox_scmi_test_devices(struct unit_test_state *uts,
|
|
|
|
struct udevice *dev)
|
|
|
|
{
|
2023-10-11 10:07:03 +00:00
|
|
|
/* un-probe */
|
2020-09-09 16:44:05 +00:00
|
|
|
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:44:00 +00:00
|
|
|
/*
|
|
|
|
* Test SCMI states when loading and releasing resources
|
|
|
|
* related to SCMI drivers.
|
|
|
|
*/
|
|
|
|
static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
|
|
|
|
{
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_agent *ctx;
|
2020-09-09 16:44:05 +00:00
|
|
|
struct udevice *dev = NULL;
|
|
|
|
int ret;
|
2020-09-09 16:44:00 +00:00
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev);
|
2020-09-09 16:44:05 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = release_sandbox_scmi_test_devices(uts, dev);
|
2020-09-09 16:44:00 +00:00
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
return ret;
|
2020-09-09 16:44:00 +00:00
|
|
|
}
|
|
|
|
DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
2023-10-11 10:07:06 +00:00
|
|
|
static int dm_test_scmi_base(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *agent_dev, *base;
|
|
|
|
struct scmi_agent_priv *priv;
|
|
|
|
u32 version, num_agents, num_protocols, impl_version;
|
|
|
|
u32 attributes, agent_id;
|
|
|
|
u8 *vendor, *agent_name, *protocols;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* preparation */
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
|
|
|
|
&agent_dev));
|
|
|
|
ut_assertnonnull(agent_dev);
|
|
|
|
ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
|
|
|
|
ut_assertnonnull(base = scmi_get_protocol(agent_dev,
|
|
|
|
SCMI_PROTOCOL_ID_BASE));
|
|
|
|
|
|
|
|
/* version */
|
|
|
|
ret = scmi_base_protocol_version(base, &version);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(priv->version, version);
|
|
|
|
|
|
|
|
/* protocol attributes */
|
|
|
|
ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(priv->num_agents, num_agents);
|
|
|
|
ut_asserteq(priv->num_protocols, num_protocols);
|
|
|
|
|
|
|
|
/* discover vendor */
|
|
|
|
ret = scmi_base_discover_vendor(base, &vendor);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str(priv->vendor, vendor);
|
|
|
|
free(vendor);
|
|
|
|
|
|
|
|
/* message attributes */
|
|
|
|
ret = scmi_base_protocol_message_attrs(base,
|
|
|
|
SCMI_BASE_DISCOVER_SUB_VENDOR,
|
|
|
|
&attributes);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_assertok(attributes);
|
|
|
|
|
|
|
|
/* discover sub vendor */
|
|
|
|
ret = scmi_base_discover_sub_vendor(base, &vendor);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str(priv->sub_vendor, vendor);
|
|
|
|
free(vendor);
|
|
|
|
|
|
|
|
/* impl version */
|
|
|
|
ret = scmi_base_discover_impl_version(base, &impl_version);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(priv->impl_version, impl_version);
|
|
|
|
|
|
|
|
/* discover agent (my self) */
|
|
|
|
ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id,
|
|
|
|
&agent_name);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(priv->agent_id, agent_id);
|
|
|
|
ut_asserteq_str(priv->agent_name, agent_name);
|
|
|
|
free(agent_name);
|
|
|
|
|
|
|
|
/* discover protocols */
|
|
|
|
ret = scmi_base_discover_list_protocols(base, &protocols);
|
|
|
|
ut_asserteq(num_protocols, ret);
|
|
|
|
ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
|
|
|
|
free(protocols);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
|
|
|
|
* access and protocol permissions, but doesn't allow unsetting them nor
|
|
|
|
* resetting the configurations.
|
|
|
|
*/
|
|
|
|
/* set device permissions */
|
|
|
|
ret = scmi_base_set_device_permissions(base, agent_id, 0,
|
|
|
|
SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
|
|
|
|
ut_assertok(ret); /* SCMI_SUCCESS */
|
|
|
|
ret = scmi_base_set_device_permissions(base, agent_id, 1,
|
|
|
|
SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
|
|
|
|
ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
|
|
|
|
ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
|
|
|
|
ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
|
|
|
|
|
|
|
|
/* set protocol permissions */
|
|
|
|
ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
|
|
|
|
SCMI_PROTOCOL_ID_CLOCK,
|
|
|
|
SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
|
|
|
|
ut_assertok(ret); /* SCMI_SUCCESS */
|
|
|
|
ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
|
|
|
|
SCMI_PROTOCOL_ID_CLOCK,
|
|
|
|
SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
|
|
|
|
ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
|
|
|
|
ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
|
|
|
|
SCMI_PROTOCOL_ID_CLOCK, 0);
|
|
|
|
ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
|
|
|
|
|
|
|
|
/* reset agent configuration */
|
|
|
|
ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
|
|
|
|
ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
|
|
|
|
ret = scmi_base_reset_agent_configuration(base, agent_id,
|
|
|
|
SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS);
|
|
|
|
ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
|
|
|
|
ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
|
|
|
|
ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
|
|
|
|
|
2023-10-16 05:39:46 +00:00
|
|
|
static int dm_test_scmi_power_domains(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct sandbox_scmi_agent *agent;
|
|
|
|
struct sandbox_scmi_devices *scmi_devices;
|
|
|
|
struct udevice *agent_dev, *pwd, *dev;
|
|
|
|
u32 version, count, attributes, pstate;
|
|
|
|
u64 stats_addr;
|
|
|
|
size_t stats_len;
|
|
|
|
u8 *name;
|
|
|
|
int ret;
|
|
|
|
|
2023-11-14 02:14:24 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2023-10-16 05:39:46 +00:00
|
|
|
/* preparation */
|
|
|
|
ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
|
|
|
|
ut_assertnonnull(agent);
|
|
|
|
scmi_devices = sandbox_scmi_devices_ctx(dev);
|
|
|
|
ut_assertnonnull(scmi_devices);
|
|
|
|
ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
|
|
|
|
&agent_dev));
|
|
|
|
ut_assertnonnull(agent_dev);
|
|
|
|
pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN);
|
|
|
|
ut_assertnonnull(pwd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SCMI Power domain management protocol interfaces
|
|
|
|
*/
|
|
|
|
/* version */
|
|
|
|
ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN,
|
|
|
|
&version);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(agent->pwdom_version, version);
|
|
|
|
|
|
|
|
/* protocol attributes */
|
|
|
|
ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(agent->pwdom_count, count);
|
|
|
|
ut_asserteq(0, stats_len);
|
|
|
|
|
|
|
|
/* protocol message attributes */
|
|
|
|
ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET,
|
|
|
|
&attributes);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY,
|
|
|
|
&attributes);
|
|
|
|
ut_asserteq(-ENOENT, ret); /* the protocol not supported */
|
|
|
|
|
|
|
|
/* power domain attributes */
|
|
|
|
ret = scmi_pwd_attrs(pwd, 0, &attributes, &name);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("power-domain--0", name);
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
ret = scmi_pwd_attrs(pwd, 10, &attributes, &name);
|
|
|
|
ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
|
|
|
|
|
|
|
|
/* power domain state set/get */
|
|
|
|
ret = scmi_pwd_state_set(pwd, 0, 0, 0);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ret = scmi_pwd_state_get(pwd, 0, &pstate);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(0, pstate); /* ON */
|
|
|
|
|
|
|
|
ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ret = scmi_pwd_state_get(pwd, 0, &pstate);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
|
|
|
|
|
|
|
|
ret = scmi_pwd_state_set(pwd, 0, 10, 0);
|
|
|
|
ut_asserteq(-ENOENT, ret);
|
|
|
|
|
|
|
|
/* power domain name get */
|
|
|
|
ret = scmi_pwd_name_get(pwd, 0, &name);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq_str("power-domain--0-extended", name);
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
ret = scmi_pwd_name_get(pwd, 10, &name);
|
|
|
|
ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* U-Boot driver model interfaces
|
|
|
|
*/
|
|
|
|
/* power_domain_on */
|
|
|
|
ret = power_domain_on(scmi_devices->pwdom);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(0, pstate); /* ON */
|
|
|
|
|
|
|
|
/* power_domain_off */
|
|
|
|
ret = power_domain_off(scmi_devices->pwdom);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
|
|
|
|
ut_assertok(ret);
|
|
|
|
ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
|
|
|
|
|
|
|
|
return release_sandbox_scmi_test_devices(uts, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT);
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
static int dm_test_scmi_clocks(struct unit_test_state *uts)
|
|
|
|
{
|
2022-02-21 08:22:39 +00:00
|
|
|
struct sandbox_scmi_agent *agent;
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_devices *scmi_devices;
|
2023-10-11 10:06:59 +00:00
|
|
|
struct udevice *agent_dev, *clock_dev, *dev;
|
2020-09-09 16:44:05 +00:00
|
|
|
int ret_dev;
|
|
|
|
int ret;
|
|
|
|
|
2023-11-14 02:14:24 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(CLK_SCMI))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
|
2020-09-09 16:44:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
scmi_devices = sandbox_scmi_devices_ctx(dev);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assertnonnull(scmi_devices);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
2023-10-11 10:06:59 +00:00
|
|
|
/* Sandbox SCMI clock protocol has its own channel */
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
|
|
|
|
&agent_dev));
|
|
|
|
ut_assertnonnull(agent_dev);
|
|
|
|
clock_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_CLOCK);
|
|
|
|
ut_assertnonnull(clock_dev);
|
|
|
|
ut_asserteq(0x14, sandbox_scmi_channel_id(clock_dev));
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
/* Test SCMI clocks rate manipulation */
|
2022-02-21 08:22:41 +00:00
|
|
|
ut_asserteq(333, agent->clk[0].rate);
|
|
|
|
ut_asserteq(200, agent->clk[1].rate);
|
|
|
|
ut_asserteq(1000, agent->clk[2].rate);
|
|
|
|
|
2020-09-09 16:44:05 +00:00
|
|
|
ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
|
|
|
|
ut_asserteq(333, clk_get_rate(&scmi_devices->clk[1]));
|
|
|
|
|
|
|
|
ret_dev = clk_set_rate(&scmi_devices->clk[1], 1088);
|
|
|
|
ut_assert(!ret_dev || ret_dev == 1088);
|
|
|
|
|
2022-02-21 08:22:41 +00:00
|
|
|
ut_asserteq(1088, agent->clk[0].rate);
|
|
|
|
ut_asserteq(200, agent->clk[1].rate);
|
|
|
|
ut_asserteq(1000, agent->clk[2].rate);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
ut_asserteq(1000, clk_get_rate(&scmi_devices->clk[0]));
|
|
|
|
ut_asserteq(1088, clk_get_rate(&scmi_devices->clk[1]));
|
|
|
|
|
|
|
|
/* restore original rate for further tests */
|
|
|
|
ret_dev = clk_set_rate(&scmi_devices->clk[1], 333);
|
|
|
|
ut_assert(!ret_dev || ret_dev == 333);
|
|
|
|
|
|
|
|
/* Test SCMI clocks gating manipulation */
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->clk[0].enabled);
|
|
|
|
ut_assert(!agent->clk[1].enabled);
|
|
|
|
ut_assert(!agent->clk[2].enabled);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
ut_asserteq(0, clk_enable(&scmi_devices->clk[1]));
|
|
|
|
|
2022-02-21 08:22:41 +00:00
|
|
|
ut_assert(agent->clk[0].enabled);
|
|
|
|
ut_assert(!agent->clk[1].enabled);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->clk[2].enabled);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
ut_assertok(clk_disable(&scmi_devices->clk[1]));
|
|
|
|
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->clk[0].enabled);
|
|
|
|
ut_assert(!agent->clk[1].enabled);
|
|
|
|
ut_assert(!agent->clk[2].enabled);
|
2020-09-09 16:44:05 +00:00
|
|
|
|
|
|
|
return release_sandbox_scmi_test_devices(uts, dev);
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT);
|
2020-09-09 16:44:07 +00:00
|
|
|
|
|
|
|
static int dm_test_scmi_resets(struct unit_test_state *uts)
|
|
|
|
{
|
2022-02-21 08:22:39 +00:00
|
|
|
struct sandbox_scmi_agent *agent;
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_devices *scmi_devices;
|
2023-10-11 10:06:59 +00:00
|
|
|
struct udevice *agent_dev, *reset_dev, *dev = NULL;
|
2020-09-09 16:44:07 +00:00
|
|
|
int ret;
|
|
|
|
|
2023-11-14 02:14:24 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(RESET_SCMI))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
|
2020-09-09 16:44:07 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
scmi_devices = sandbox_scmi_devices_ctx(dev);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assertnonnull(scmi_devices);
|
2020-09-09 16:44:07 +00:00
|
|
|
|
2023-10-11 10:06:59 +00:00
|
|
|
/* Sandbox SCMI reset protocol doesn't have its own channel */
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
|
|
|
|
&agent_dev));
|
|
|
|
ut_assertnonnull(agent_dev);
|
|
|
|
reset_dev = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_RESET_DOMAIN);
|
|
|
|
ut_assertnonnull(reset_dev);
|
|
|
|
ut_asserteq(0x0, sandbox_scmi_channel_id(reset_dev));
|
|
|
|
|
2020-09-09 16:44:07 +00:00
|
|
|
/* Test SCMI resect controller manipulation */
|
2023-03-10 03:33:13 +00:00
|
|
|
ut_assert(!agent->reset[0].asserted);
|
2020-09-09 16:44:07 +00:00
|
|
|
|
|
|
|
ut_assertok(reset_assert(&scmi_devices->reset[0]));
|
2023-03-10 03:33:13 +00:00
|
|
|
ut_assert(agent->reset[0].asserted);
|
2020-09-09 16:44:07 +00:00
|
|
|
|
|
|
|
ut_assertok(reset_deassert(&scmi_devices->reset[0]));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->reset[0].asserted);
|
2020-09-09 16:44:07 +00:00
|
|
|
|
|
|
|
return release_sandbox_scmi_test_devices(uts, dev);
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
|
|
|
|
{
|
2022-02-21 08:22:39 +00:00
|
|
|
struct sandbox_scmi_agent *agent;
|
2023-10-11 10:07:03 +00:00
|
|
|
struct sandbox_scmi_devices *scmi_devices;
|
2021-03-08 21:38:07 +00:00
|
|
|
struct dm_regulator_uclass_plat *uc_pdata;
|
|
|
|
struct udevice *dev;
|
2021-03-08 21:38:09 +00:00
|
|
|
struct udevice *regul0_dev;
|
2021-03-08 21:38:07 +00:00
|
|
|
|
2023-11-14 02:14:24 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(DM_REGULATOR_SCMI))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2023-10-11 10:07:03 +00:00
|
|
|
ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
scmi_devices = sandbox_scmi_devices_ctx(dev);
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assertnonnull(scmi_devices);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
/* Set/Get an SCMI voltage domain level */
|
2021-03-08 21:38:09 +00:00
|
|
|
regul0_dev = scmi_devices->regul[0];
|
|
|
|
ut_assert(regul0_dev);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
2021-03-08 21:38:09 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(regul0_dev);
|
2021-03-08 21:38:07 +00:00
|
|
|
ut_assert(uc_pdata);
|
|
|
|
|
2021-03-08 21:38:09 +00:00
|
|
|
ut_assertok(regulator_set_value(regul0_dev, uc_pdata->min_uV));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->min_uV);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
2021-03-08 21:38:09 +00:00
|
|
|
ut_assert(regulator_get_value(regul0_dev) == uc_pdata->min_uV);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
2021-03-08 21:38:09 +00:00
|
|
|
ut_assertok(regulator_set_value(regul0_dev, uc_pdata->max_uV));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_asserteq(agent->voltd[0].voltage_uv, uc_pdata->max_uV);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
2021-03-08 21:38:09 +00:00
|
|
|
ut_assert(regulator_get_value(regul0_dev) == uc_pdata->max_uV);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
/* Enable/disable SCMI voltage domains */
|
|
|
|
ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
|
|
|
|
ut_assertok(regulator_set_enable(scmi_devices->regul[1], false));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->voltd[0].enabled);
|
|
|
|
ut_assert(!agent->voltd[1].enabled);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
ut_assertok(regulator_set_enable(scmi_devices->regul[0], true));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(agent->voltd[0].enabled);
|
|
|
|
ut_assert(!agent->voltd[1].enabled);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
ut_assertok(regulator_set_enable(scmi_devices->regul[1], true));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(agent->voltd[0].enabled);
|
|
|
|
ut_assert(agent->voltd[1].enabled);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
ut_assertok(regulator_set_enable(scmi_devices->regul[0], false));
|
2022-02-21 08:22:39 +00:00
|
|
|
ut_assert(!agent->voltd[0].enabled);
|
|
|
|
ut_assert(agent->voltd[1].enabled);
|
2021-03-08 21:38:07 +00:00
|
|
|
|
|
|
|
return release_sandbox_scmi_test_devices(uts, dev);
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT);
|