xref: /openbmc/u-boot/test/dm/power-domain.c (revision dd1033e4)
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 
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_asserteq(1, sandbox_power_domain_query(dev_power_domain,
30 						  TEST_POWER_DOMAIN));
31 	ut_assertok(sandbox_power_domain_test_get(dev_test));
32 
33 	ut_assertok(sandbox_power_domain_test_on(dev_test));
34 	ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
35 	ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
36 						  TEST_POWER_DOMAIN));
37 
38 	ut_assertok(sandbox_power_domain_test_off(dev_test));
39 	ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
40 	ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
41 						  TEST_POWER_DOMAIN));
42 
43 	ut_assertok(sandbox_power_domain_test_free(dev_test));
44 
45 	return 0;
46 }
47 DM_TEST(dm_test_power_domain, DM_TESTF_SCAN_FDT);
48