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 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 6 | #include <dm.h> |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 7 | #include <dm/device-internal.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> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 13 | #include <test/test.h> |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 14 | #include <test/ut.h> |
| 15 | |
| 16 | /* This must match the specifier for mbox-names="test" in the DT node */ |
| 17 | #define TEST_RESET_ID 2 |
| 18 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 19 | /* This is the other reset phandle specifier handled by bulk */ |
| 20 | #define OTHER_RESET_ID 2 |
| 21 | |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 22 | /* Base test of the reset uclass */ |
| 23 | static int dm_test_reset_base(struct unit_test_state *uts) |
| 24 | { |
| 25 | struct udevice *dev; |
Neil Armstrong | 9b4cdef | 2021-04-20 10:42:25 +0200 | [diff] [blame] | 26 | struct reset_ctl reset_method1, reset_method1_1; |
| 27 | struct reset_ctl reset_method2, reset_method2_1; |
| 28 | struct reset_ctl reset_method3, reset_method3_1; |
| 29 | struct reset_ctl reset_method4, reset_method4_1; |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 30 | |
| 31 | /* Get the device using the reset device */ |
| 32 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 33 | &dev)); |
| 34 | |
| 35 | /* Get the same reset port in 2 different ways and compare */ |
Neil Armstrong | 9b4cdef | 2021-04-20 10:42:25 +0200 | [diff] [blame] | 36 | ut_assertok(reset_get_by_index(dev, 0, &reset_method1)); |
Samuel Holland | 6078bff | 2023-01-21 18:02:52 -0600 | [diff] [blame] | 37 | ut_assertok(reset_get_by_name(dev, NULL, &reset_method1_1)); |
Neil Armstrong | 9b4cdef | 2021-04-20 10:42:25 +0200 | [diff] [blame] | 38 | ut_assertok(reset_get_by_index(dev, 1, &reset_method2)); |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 39 | ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1, |
Neil Armstrong | 9b4cdef | 2021-04-20 10:42:25 +0200 | [diff] [blame] | 40 | &reset_method2_1)); |
| 41 | ut_assertok(reset_get_by_index(dev, 2, &reset_method3)); |
| 42 | ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 2, |
| 43 | &reset_method3_1)); |
| 44 | ut_assertok(reset_get_by_index(dev, 3, &reset_method4)); |
| 45 | ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 3, |
| 46 | &reset_method4_1)); |
| 47 | |
| 48 | ut_asserteq(reset_method1.id, reset_method1_1.id); |
| 49 | ut_asserteq(reset_method2.id, reset_method2_1.id); |
| 50 | ut_asserteq(reset_method3.id, reset_method3_1.id); |
| 51 | ut_asserteq(reset_method4.id, reset_method4_1.id); |
| 52 | |
| 53 | ut_asserteq(true, reset_method1.id != reset_method2.id); |
| 54 | ut_asserteq(true, reset_method1.id != reset_method3.id); |
| 55 | ut_asserteq(true, reset_method1.id != reset_method4.id); |
| 56 | ut_asserteq(true, reset_method2.id != reset_method3.id); |
| 57 | ut_asserteq(true, reset_method2.id != reset_method4.id); |
| 58 | ut_asserteq(true, reset_method3.id != reset_method4.id); |
| 59 | |
| 60 | ut_asserteq(true, reset_method1_1.id != reset_method2_1.id); |
| 61 | ut_asserteq(true, reset_method1_1.id != reset_method3_1.id); |
| 62 | ut_asserteq(true, reset_method1_1.id != reset_method4_1.id); |
| 63 | ut_asserteq(true, reset_method2_1.id != reset_method3_1.id); |
| 64 | ut_asserteq(true, reset_method2_1.id != reset_method4_1.id); |
| 65 | ut_asserteq(true, reset_method3_1.id != reset_method4_1.id); |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 70 | DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT); |
Jagan Teki | dcd48c3 | 2019-02-28 00:26:56 +0530 | [diff] [blame] | 71 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 72 | static int dm_test_reset(struct unit_test_state *uts) |
| 73 | { |
| 74 | struct udevice *dev_reset; |
| 75 | struct udevice *dev_test; |
| 76 | |
| 77 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 78 | &dev_reset)); |
| 79 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 80 | |
| 81 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 82 | &dev_test)); |
| 83 | ut_assertok(sandbox_reset_test_get(dev_test)); |
| 84 | |
| 85 | ut_assertok(sandbox_reset_test_assert(dev_test)); |
| 86 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 87 | |
| 88 | ut_assertok(sandbox_reset_test_deassert(dev_test)); |
| 89 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 90 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 91 | ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 92 | ut_assertok(sandbox_reset_test_free(dev_test)); |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 93 | ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 94 | |
| 95 | return 0; |
| 96 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 97 | DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT); |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 98 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 99 | static int dm_test_reset_devm(struct unit_test_state *uts) |
| 100 | { |
| 101 | struct udevice *dev_reset; |
| 102 | struct udevice *dev_test; |
| 103 | |
| 104 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 105 | &dev_reset)); |
| 106 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 107 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 108 | &dev_test)); |
| 109 | ut_assertok(sandbox_reset_test_get_devm(dev_test)); |
| 110 | |
| 111 | ut_assertok(sandbox_reset_test_assert(dev_test)); |
| 112 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 113 | ut_assertok(sandbox_reset_test_deassert(dev_test)); |
| 114 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 115 | |
| 116 | ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
| 117 | ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL)); |
| 118 | ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT); |
| 123 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 124 | static int dm_test_reset_bulk(struct unit_test_state *uts) |
| 125 | { |
| 126 | struct udevice *dev_reset; |
| 127 | struct udevice *dev_test; |
| 128 | |
| 129 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 130 | &dev_reset)); |
| 131 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 132 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 133 | |
| 134 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 135 | &dev_test)); |
| 136 | ut_assertok(sandbox_reset_test_get_bulk(dev_test)); |
| 137 | |
| 138 | ut_assertok(sandbox_reset_test_assert_bulk(dev_test)); |
| 139 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 140 | ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 141 | |
| 142 | ut_assertok(sandbox_reset_test_deassert_bulk(dev_test)); |
| 143 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 144 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 145 | |
| 146 | ut_assertok(sandbox_reset_test_release_bulk(dev_test)); |
| 147 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 148 | ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 149 | |
| 150 | return 0; |
| 151 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 152 | DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT); |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 153 | |
| 154 | static int dm_test_reset_bulk_devm(struct unit_test_state *uts) |
| 155 | { |
| 156 | struct udevice *dev_reset; |
| 157 | struct udevice *dev_test; |
| 158 | |
| 159 | ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl", |
| 160 | &dev_reset)); |
| 161 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 162 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 163 | |
| 164 | ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test", |
| 165 | &dev_test)); |
| 166 | ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test)); |
| 167 | |
| 168 | ut_assertok(sandbox_reset_test_assert_bulk(dev_test)); |
| 169 | ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 170 | ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 171 | |
| 172 | ut_assertok(sandbox_reset_test_deassert_bulk(dev_test)); |
| 173 | ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID)); |
| 174 | ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID)); |
| 175 | |
| 176 | ut_asserteq(1, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID)); |
| 177 | ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
| 178 | ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL)); |
| 179 | ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID)); |
| 180 | ut_asserteq(0, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID)); |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT); |