blob: 8baf5d09d1d235c184642012b8c7c6b18fe0f88d [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>
11#include <test/ut.h>
12
13/* This must match the specifier for power-domains in the DT node */
14#define TEST_POWER_DOMAIN 2
15
16static int dm_test_power_domain(struct unit_test_state *uts)
17{
18 struct udevice *dev_power_domain;
19 struct udevice *dev_test;
20
21 ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
22 "power-domain",
23 &dev_power_domain));
24 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
25 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
26 TEST_POWER_DOMAIN));
27
28 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "power-domain-test",
29 &dev_test));
Peng Fan7a2c2be2018-07-27 10:20:39 +080030 ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
31 TEST_POWER_DOMAIN));
Stephen Warren92c67fa2016-07-13 13:45:31 -060032 ut_assertok(sandbox_power_domain_test_get(dev_test));
33
34 ut_assertok(sandbox_power_domain_test_on(dev_test));
35 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
36 ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
37 TEST_POWER_DOMAIN));
38
39 ut_assertok(sandbox_power_domain_test_off(dev_test));
40 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
41 ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
42 TEST_POWER_DOMAIN));
43
44 ut_assertok(sandbox_power_domain_test_free(dev_test));
45
46 return 0;
47}
48DM_TEST(dm_test_power_domain, DM_TESTF_SCAN_FDT);