Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 10 | #include <reset.h> |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 11 | #include <dm/test.h> |
| 12 | #include <asm/reset.h> |
| 13 | #include <test/ut.h> |
| 14 | |
| 15 | /* This must match the specifier for mbox-names="test" in the DT node */ |
| 16 | #define TEST_RESET_ID 2 |
| 17 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 18 | /* This is the other reset phandle specifier handled by bulk */ |
| 19 | #define OTHER_RESET_ID 2 |
| 20 | |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 21 | /* Base test of the reset uclass */ |
| 22 | static int dm_test_reset_base(struct unit_test_state *uts) |
| 23 | { |
| 24 | struct udevice *dev; |
| 25 | struct reset_ctl reset_method1; |
| 26 | struct reset_ctl reset_method2; |
| 27 | |
| 28 | /* Get the device using the reset device */ |
| 29 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 30 | &dev)); |
| 31 | |
| 32 | /* Get the same reset port in 2 different ways and compare */ |
| 33 | ut_assertok(reset_get_by_index(dev, 1, &reset_method1)); |
| 34 | ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1, |
| 35 | &reset_method2)); |
| 36 | ut_asserteq(reset_method1.id, reset_method2.id); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_FDT); |
| 42 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 43 | static int dm_test_reset(struct unit_test_state *uts) |
| 44 | { |
| 45 | struct udevice *dev_reset; |
| 46 | struct udevice *dev_test; |
| 47 | |
| 48 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 49 | &dev_reset)); |
| 50 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 51 | |
| 52 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 53 | &dev_test)); |
| 54 | ut_assertok(sandbox_reset_test_get(dev_test)); |
| 55 | |
| 56 | ut_assertok(sandbox_reset_test_assert(dev_test)); |
| 57 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 58 | |
| 59 | ut_assertok(sandbox_reset_test_deassert(dev_test)); |
| 60 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 61 | |
| 62 | ut_assertok(sandbox_reset_test_free(dev_test)); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT); |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 67 | |
| 68 | static int dm_test_reset_bulk(struct unit_test_state *uts) |
| 69 | { |
| 70 | struct udevice *dev_reset; |
| 71 | struct udevice *dev_test; |
| 72 | |
| 73 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 74 | &dev_reset)); |
| 75 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 76 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 77 | |
| 78 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 79 | &dev_test)); |
| 80 | ut_assertok(sandbox_reset_test_get_bulk(dev_test)); |
| 81 | |
| 82 | ut_assertok(sandbox_reset_test_assert_bulk(dev_test)); |
| 83 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 84 | ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 85 | |
| 86 | ut_assertok(sandbox_reset_test_deassert_bulk(dev_test)); |
| 87 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 88 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 89 | |
| 90 | ut_assertok(sandbox_reset_test_release_bulk(dev_test)); |
| 91 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 92 | ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT); |