blob: 120a9059c8e6d7424afc13749e723829b4da3424 [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
Stephen Warren92c67fa2016-07-13 13:45:31 -06006#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07007#include <malloc.h>
Stephen Warren92c67fa2016-07-13 13:45:31 -06008#include <dm/test.h>
9#include <asm/power-domain.h>
Simon Glass75c4d412020-07-19 10:15:37 -060010#include <test/test.h>
Stephen Warren92c67fa2016-07-13 13:45:31 -060011#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}
Simon Glass974dccd2020-07-28 19:41:12 -060048DM_TEST(dm_test_power_domain, UT_TESTF_SCAN_FDT);