Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 9 | #include <dm/test.h> |
| 10 | #include <asm/power-domain.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 12 | #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 | |
| 17 | static 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 Fan | 7a2c2be | 2018-07-27 10:20:39 +0800 | [diff] [blame] | 31 | ut_asserteq(1, sandbox_power_domain_query(dev_power_domain, |
| 32 | TEST_POWER_DOMAIN)); |
Stephen Warren | 92c67fa | 2016-07-13 13:45:31 -0600 | [diff] [blame] | 33 | 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 | } |
| 49 | DM_TEST(dm_test_power_domain, DM_TESTF_SCAN_FDT); |