1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
4 */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <dm/test.h>
9 #include <asm/power-domain.h>
10 #include <test/ut.h>
11
12 /* This must match the specifier for power-domains in the DT node */
13 #define TEST_POWER_DOMAIN 2
14
dm_test_power_domain(struct unit_test_state * uts)15 static int dm_test_power_domain(struct unit_test_state *uts)
16 {
17 struct udevice *dev_power_domain;
18 struct udevice *dev_test;
19
20 ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
21 "power-domain",
22 &dev_power_domain));
23 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
24 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
25 TEST_POWER_DOMAIN));
26
27 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "power-domain-test",
28 &dev_test));
29 ut_assertok(sandbox_power_domain_test_get(dev_test));
30
31 ut_assertok(sandbox_power_domain_test_on(dev_test));
32 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
33 ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
34 TEST_POWER_DOMAIN));
35
36 ut_assertok(sandbox_power_domain_test_off(dev_test));
37 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
38 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
39 TEST_POWER_DOMAIN));
40
41 ut_assertok(sandbox_power_domain_test_free(dev_test));
42
43 return 0;
44 }
45 DM_TEST(dm_test_power_domain, DM_TESTF_SCAN_FDT);
46