blob: 52f88c5a3606766162be33816f1053cd48ac9ece [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren92c67fa2016-07-13 13:45:31 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren92c67fa2016-07-13 13:45:31 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Stephen Warren92c67fa2016-07-13 13:45:31 -06009#include <dm/test.h>
10#include <asm/power-domain.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <test/test.h>
Stephen Warren92c67fa2016-07-13 13:45:31 -060012#include <test/ut.h>
13
14/* This must match the specifier for power-domains in the DT node */
15#define TEST_POWER_DOMAIN 2
16
17static int dm_test_power_domain(struct unit_test_state *uts)
18{
19 struct udevice *dev_power_domain;
20 struct udevice *dev_test;
21
22 ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
23 "power-domain",
24 &dev_power_domain));
25 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
26 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
27 TEST_POWER_DOMAIN));
28
29 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "power-domain-test",
30 &dev_test));
Peng Fan7a2c2be2018-07-27 10:20:39 +080031 ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
32 TEST_POWER_DOMAIN));
Stephen Warren92c67fa2016-07-13 13:45:31 -060033 ut_assertok(sandbox_power_domain_test_get(dev_test));
34
35 ut_assertok(sandbox_power_domain_test_on(dev_test));
36 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
37 ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
38 TEST_POWER_DOMAIN));
39
40 ut_assertok(sandbox_power_domain_test_off(dev_test));
41 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
42 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
43 TEST_POWER_DOMAIN));
44
45 ut_assertok(sandbox_power_domain_test_free(dev_test));
46
47 return 0;
48}
49DM_TEST(dm_test_power_domain, DM_TESTF_SCAN_FDT);