Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <errno.h> |
| 8 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <dm/test.h> |
Nikhil M Jain | bb9d131 | 2023-01-31 15:35:15 +0530 | [diff] [blame] | 14 | #include <dm/read.h> |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 15 | #include <dm/root.h> |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 16 | #include <dm/device-internal.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 17 | #include <dm/devres.h> |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 18 | #include <dm/uclass-internal.h> |
| 19 | #include <dm/util.h> |
Mario Six | 058ef5b | 2018-06-26 08:46:49 +0200 | [diff] [blame] | 20 | #include <dm/of_access.h> |
Patrick Delaunay | da37ed3 | 2021-05-21 12:25:00 +0200 | [diff] [blame] | 21 | #include <linux/ioport.h> |
Sughosh Ganu | 6012c1e | 2024-07-30 16:41:32 +0530 | [diff] [blame] | 22 | #include <linux/list.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 23 | #include <test/test.h> |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 24 | #include <test/ut.h> |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 28 | struct dm_testprobe_pdata { |
| 29 | int probe_err; |
| 30 | }; |
| 31 | |
| 32 | static int testprobe_drv_probe(struct udevice *dev) |
| 33 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 34 | struct dm_testprobe_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 35 | |
| 36 | return pdata->probe_err; |
| 37 | } |
| 38 | |
| 39 | static const struct udevice_id testprobe_ids[] = { |
| 40 | { .compatible = "denx,u-boot-probe-test" }, |
| 41 | { } |
| 42 | }; |
| 43 | |
| 44 | U_BOOT_DRIVER(testprobe_drv) = { |
| 45 | .name = "testprobe_drv", |
| 46 | .of_match = testprobe_ids, |
| 47 | .id = UCLASS_TEST_PROBE, |
| 48 | .probe = testprobe_drv_probe, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 49 | .plat_auto = sizeof(struct dm_testprobe_pdata), |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | UCLASS_DRIVER(testprobe) = { |
| 53 | .name = "testprobe", |
| 54 | .id = UCLASS_TEST_PROBE, |
| 55 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 56 | }; |
| 57 | |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 58 | struct dm_testdevres_pdata { |
| 59 | void *ptr; |
| 60 | }; |
| 61 | |
| 62 | struct dm_testdevres_priv { |
| 63 | void *ptr; |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 64 | void *ptr_ofdata; |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static int testdevres_drv_bind(struct udevice *dev) |
| 68 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 69 | struct dm_testdevres_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 70 | |
| 71 | pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 76 | static int testdevres_drv_of_to_plat(struct udevice *dev) |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 77 | { |
| 78 | struct dm_testdevres_priv *priv = dev_get_priv(dev); |
| 79 | |
| 80 | priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 85 | static int testdevres_drv_probe(struct udevice *dev) |
| 86 | { |
| 87 | struct dm_testdevres_priv *priv = dev_get_priv(dev); |
| 88 | |
| 89 | priv->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE2, 0); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static const struct udevice_id testdevres_ids[] = { |
| 95 | { .compatible = "denx,u-boot-devres-test" }, |
| 96 | { } |
| 97 | }; |
| 98 | |
| 99 | U_BOOT_DRIVER(testdevres_drv) = { |
| 100 | .name = "testdevres_drv", |
| 101 | .of_match = testdevres_ids, |
| 102 | .id = UCLASS_TEST_DEVRES, |
| 103 | .bind = testdevres_drv_bind, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 104 | .of_to_plat = testdevres_drv_of_to_plat, |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 105 | .probe = testdevres_drv_probe, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 106 | .plat_auto = sizeof(struct dm_testdevres_pdata), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 107 | .priv_auto = sizeof(struct dm_testdevres_priv), |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | UCLASS_DRIVER(testdevres) = { |
| 111 | .name = "testdevres", |
| 112 | .id = UCLASS_TEST_DEVRES, |
| 113 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 114 | }; |
| 115 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 116 | int dm_check_devices(struct unit_test_state *uts, int num_devices) |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 117 | { |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 118 | struct udevice *dev; |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 119 | int ret; |
| 120 | int i; |
| 121 | |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 122 | /* |
| 123 | * Now check that the ping adds are what we expect. This is using the |
| 124 | * ping-add property in each node. |
| 125 | */ |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 126 | for (i = 0; i < num_devices; i++) { |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 127 | uint32_t base; |
| 128 | |
| 129 | ret = uclass_get_device(UCLASS_TEST_FDT, i, &dev); |
| 130 | ut_assert(!ret); |
| 131 | |
| 132 | /* |
Simon Glass | a7bb08a | 2014-07-23 06:54:57 -0600 | [diff] [blame] | 133 | * Get the 'ping-expect' property, which tells us what the |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 134 | * ping add should be. We don't use the plat because we |
Simon Glass | a7bb08a | 2014-07-23 06:54:57 -0600 | [diff] [blame] | 135 | * want to test the code that sets that up |
| 136 | * (testfdt_drv_probe()). |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 137 | */ |
Marek Vasut | dd7af67 | 2023-08-23 21:37:44 +0200 | [diff] [blame] | 138 | base = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
| 139 | "ping-expect", -1); |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 140 | debug("dev=%d, base=%d: %s\n", i, base, |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 141 | fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL)); |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 142 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 143 | ut_assert(!dm_check_operations(uts, dev, base, |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 144 | dev_get_priv(dev))); |
| 145 | } |
| 146 | |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* Test that FDT-based binding works correctly */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 151 | static int dm_test_fdt(struct unit_test_state *uts) |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 152 | { |
Jean-Jacques Hiblot | 7387340 | 2020-09-11 13:43:35 +0530 | [diff] [blame] | 153 | const int num_devices = 9; |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 154 | struct udevice *dev; |
| 155 | struct uclass *uc; |
| 156 | int ret; |
| 157 | int i; |
| 158 | |
Simon Glass | 4d71d60 | 2020-11-28 17:50:10 -0700 | [diff] [blame] | 159 | ret = dm_extended_scan(false); |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 160 | ut_assert(!ret); |
| 161 | |
| 162 | ret = uclass_get(UCLASS_TEST_FDT, &uc); |
| 163 | ut_assert(!ret); |
| 164 | |
| 165 | /* These are num_devices compatible root-level device tree nodes */ |
Sughosh Ganu | 6012c1e | 2024-07-30 16:41:32 +0530 | [diff] [blame] | 166 | ut_asserteq(num_devices, list_count_nodes(&uc->dev_head)); |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 167 | |
Simon Glass | ba75049 | 2015-01-25 08:27:00 -0700 | [diff] [blame] | 168 | /* Each should have platform data but no private data */ |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 169 | for (i = 0; i < num_devices; i++) { |
| 170 | ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev); |
| 171 | ut_assert(!ret); |
| 172 | ut_assert(!dev_get_priv(dev)); |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 173 | ut_assert(dev_get_plat(dev)); |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 174 | } |
| 175 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 176 | ut_assertok(dm_check_devices(uts, num_devices)); |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 177 | |
Simon Glass | b2c1cac | 2014-02-26 15:59:21 -0700 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | DM_TEST(dm_test_fdt, 0); |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 181 | |
Michal Simek | 4247cf4 | 2019-01-31 16:31:00 +0100 | [diff] [blame] | 182 | static int dm_test_alias_highest_id(struct unit_test_state *uts) |
| 183 | { |
| 184 | int ret; |
| 185 | |
Michael Walle | 7efcdfd | 2021-02-25 16:51:11 +0100 | [diff] [blame] | 186 | ret = dev_read_alias_highest_id("ethernet"); |
Sean Anderson | 67d93a4 | 2022-05-05 13:11:30 -0400 | [diff] [blame] | 187 | ut_asserteq(8, ret); |
Michal Simek | 4247cf4 | 2019-01-31 16:31:00 +0100 | [diff] [blame] | 188 | |
| 189 | ret = dev_read_alias_highest_id("gpio"); |
Patrick Delaunay | 28bdaa5 | 2020-01-13 11:35:14 +0100 | [diff] [blame] | 190 | ut_asserteq(3, ret); |
Michal Simek | 4247cf4 | 2019-01-31 16:31:00 +0100 | [diff] [blame] | 191 | |
| 192 | ret = dev_read_alias_highest_id("pci"); |
| 193 | ut_asserteq(2, ret); |
| 194 | |
| 195 | ret = dev_read_alias_highest_id("i2c"); |
| 196 | ut_asserteq(0, ret); |
| 197 | |
| 198 | ret = dev_read_alias_highest_id("deadbeef"); |
| 199 | ut_asserteq(-1, ret); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | DM_TEST(dm_test_alias_highest_id, 0); |
| 204 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 205 | static int dm_test_fdt_pre_reloc(struct unit_test_state *uts) |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 206 | { |
| 207 | struct uclass *uc; |
| 208 | int ret; |
| 209 | |
Simon Glass | 5039cab | 2020-11-28 17:50:09 -0700 | [diff] [blame] | 210 | ret = dm_scan_fdt(true); |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 211 | ut_assert(!ret); |
| 212 | |
| 213 | ret = uclass_get(UCLASS_TEST_FDT, &uc); |
| 214 | ut_assert(!ret); |
| 215 | |
Bin Meng | d9d2478 | 2018-10-10 22:07:01 -0700 | [diff] [blame] | 216 | /* |
| 217 | * These are 2 pre-reloc devices: |
Simon Glass | fc1aa35 | 2023-02-13 08:56:34 -0700 | [diff] [blame] | 218 | * one with "bootph-all" property (a-test node), and the other |
Bin Meng | d9d2478 | 2018-10-10 22:07:01 -0700 | [diff] [blame] | 219 | * one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node). |
| 220 | */ |
Sughosh Ganu | 6012c1e | 2024-07-30 16:41:32 +0530 | [diff] [blame] | 221 | ut_asserteq(2, list_count_nodes(&uc->dev_head)); |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | DM_TEST(dm_test_fdt_pre_reloc, 0); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 226 | |
| 227 | /* Test that sequence numbers are allocated properly */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 228 | static int dm_test_fdt_uclass_seq(struct unit_test_state *uts) |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 229 | { |
| 230 | struct udevice *dev; |
| 231 | |
| 232 | /* A few basic santiy tests */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 233 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, &dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 234 | ut_asserteq_str("b-test", dev->name); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 235 | ut_asserteq(3, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 236 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 237 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, &dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 238 | ut_asserteq_str("a-test", dev->name); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 239 | ut_asserteq(8, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 240 | |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 241 | /* |
| 242 | * This device has no alias so gets the next value after all available |
| 243 | * aliases. The last alias is testfdt12 |
| 244 | */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 245 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 13, &dev)); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 246 | ut_asserteq_str("d-test", dev->name); |
| 247 | ut_asserteq(13, dev_seq(dev)); |
| 248 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 249 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 250 | &dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 251 | ut_asserteq_ptr(NULL, dev); |
| 252 | |
| 253 | /* Test aliases */ |
| 254 | ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev)); |
| 255 | ut_asserteq_str("e-test", dev->name); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 256 | ut_asserteq(6, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 257 | |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 258 | /* |
| 259 | * Note that c-test nodes are not probed since it is not a top-level |
| 260 | * node |
| 261 | */ |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 262 | ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev)); |
| 263 | ut_asserteq_str("b-test", dev->name); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 264 | ut_asserteq(3, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * d-test wants sequence number 3 also, but it can't have it because |
| 268 | * b-test gets it first. |
| 269 | */ |
| 270 | ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev)); |
| 271 | ut_asserteq_str("d-test", dev->name); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 272 | ut_asserteq(13, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 273 | |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 274 | /* g-test gets the next value after f-test */ |
| 275 | ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 15, &dev)); |
| 276 | ut_asserteq_str("g-test", dev->name); |
| 277 | ut_asserteq(15, dev_seq(dev)); |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 278 | |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 279 | /* And we should still have holes in our sequence numbers */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 280 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 0, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 281 | &dev)); |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 282 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 1, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 283 | &dev)); |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 284 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 2, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 285 | &dev)); |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 286 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 4, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 287 | &dev)); |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 288 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 289 | &dev)); |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 290 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9, |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 291 | &dev)); |
| 292 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 10, |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 293 | &dev)); |
Simon Glass | 7d5e411 | 2020-12-16 21:20:26 -0700 | [diff] [blame] | 294 | ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 11, |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 295 | &dev)); |
Michael Walle | 7c41a22 | 2020-06-02 01:47:09 +0200 | [diff] [blame] | 296 | |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 297 | return 0; |
| 298 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 299 | DM_TEST(dm_test_fdt_uclass_seq, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | c1464ab | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 300 | |
Simon Glass | 791a17f | 2020-12-16 21:20:27 -0700 | [diff] [blame] | 301 | /* More tests for sequence numbers */ |
| 302 | static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts) |
| 303 | { |
| 304 | struct udevice *dev; |
| 305 | |
| 306 | /* |
| 307 | * Since DM_UC_FLAG_NO_AUTO_SEQ is set for this uclass, only testfdtm1 |
| 308 | * should get a sequence number assigned |
| 309 | */ |
| 310 | ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 0, &dev)); |
| 311 | ut_asserteq_str("testfdtm0", dev->name); |
| 312 | ut_asserteq(-1, dev_seq(dev)); |
| 313 | |
| 314 | ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT_MANUAL, 1, &dev)); |
| 315 | ut_asserteq_str("testfdtm1", dev->name); |
| 316 | ut_asserteq(1, dev_seq(dev)); |
| 317 | |
| 318 | ut_assertok(uclass_get_device(UCLASS_TEST_FDT_MANUAL, 2, &dev)); |
| 319 | ut_asserteq_str("testfdtm2", dev->name); |
| 320 | ut_asserteq(-1, dev_seq(dev)); |
| 321 | |
| 322 | return 0; |
| 323 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 324 | DM_TEST(dm_test_fdt_uclass_seq_manual, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 791a17f | 2020-12-16 21:20:27 -0700 | [diff] [blame] | 325 | |
Simon Glass | 38040a9 | 2020-12-16 21:20:32 -0700 | [diff] [blame] | 326 | static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts) |
| 327 | { |
| 328 | struct udevice *dev; |
| 329 | ofnode node; |
| 330 | |
| 331 | /* Check creating a device with an alias */ |
| 332 | node = ofnode_path("/some-bus/c-test@1"); |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 333 | ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test), |
Simon Glass | 38040a9 | 2020-12-16 21:20:32 -0700 | [diff] [blame] | 334 | "c-test@1", NULL, node, &dev)); |
| 335 | ut_asserteq(12, dev_seq(dev)); |
| 336 | ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev)); |
| 337 | ut_asserteq_str("c-test@1", dev->name); |
| 338 | |
| 339 | /* |
| 340 | * Now bind a device without an alias. It should not get the next |
| 341 | * sequence number after all aliases, and existing bound devices. The |
| 342 | * last alias is 12, so we have: |
| 343 | * |
| 344 | * 13 d-test |
| 345 | * 14 f-test |
| 346 | * 15 g-test |
| 347 | * 16 h-test |
| 348 | * 17 another-test |
| 349 | * 18 chosen-test |
| 350 | * |
| 351 | * So next available is 19 |
| 352 | */ |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 353 | ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test), |
Simon Glass | 38040a9 | 2020-12-16 21:20:32 -0700 | [diff] [blame] | 354 | "fred", NULL, ofnode_null(), &dev)); |
| 355 | ut_asserteq(19, dev_seq(dev)); |
| 356 | |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 357 | ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test), |
Simon Glass | 38040a9 | 2020-12-16 21:20:32 -0700 | [diff] [blame] | 358 | "fred2", NULL, ofnode_null(), &dev)); |
| 359 | ut_asserteq(20, dev_seq(dev)); |
| 360 | |
| 361 | return 0; |
| 362 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 363 | DM_TEST(dm_test_fdt_uclass_seq_more, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 38040a9 | 2020-12-16 21:20:32 -0700 | [diff] [blame] | 364 | |
Simon Glass | c1464ab | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 365 | /* Test that we can find a device by device tree offset */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 366 | static int dm_test_fdt_offset(struct unit_test_state *uts) |
Simon Glass | c1464ab | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 367 | { |
| 368 | const void *blob = gd->fdt_blob; |
| 369 | struct udevice *dev; |
| 370 | int node; |
| 371 | |
| 372 | node = fdt_path_offset(blob, "/e-test"); |
| 373 | ut_assert(node > 0); |
| 374 | ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node, |
| 375 | &dev)); |
| 376 | ut_asserteq_str("e-test", dev->name); |
| 377 | |
| 378 | /* This node should not be bound */ |
| 379 | node = fdt_path_offset(blob, "/junk"); |
| 380 | ut_assert(node > 0); |
| 381 | ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, |
| 382 | node, &dev)); |
| 383 | |
| 384 | /* This is not a top level node so should not be probed */ |
Simon Glass | 4071742 | 2014-07-23 06:55:18 -0600 | [diff] [blame] | 385 | node = fdt_path_offset(blob, "/some-bus/c-test@5"); |
Simon Glass | c1464ab | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 386 | ut_assert(node > 0); |
| 387 | ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, |
| 388 | node, &dev)); |
| 389 | |
| 390 | return 0; |
| 391 | } |
Simon Glass | 70b66e7 | 2017-05-18 20:09:44 -0600 | [diff] [blame] | 392 | DM_TEST(dm_test_fdt_offset, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 393 | UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 394 | |
| 395 | /** |
Michal Suchanek | f5a5902 | 2022-10-12 21:57:50 +0200 | [diff] [blame] | 396 | * Test various error conditions with uclass_first_device(), |
| 397 | * uclass_next_device(), and uclass_probe_all() |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 398 | */ |
Michal Suchanek | f5a5902 | 2022-10-12 21:57:50 +0200 | [diff] [blame] | 399 | static int dm_test_first_next_device_probeall(struct unit_test_state *uts) |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 400 | { |
| 401 | struct dm_testprobe_pdata *pdata; |
| 402 | struct udevice *dev, *parent = NULL; |
| 403 | int count; |
| 404 | int ret; |
| 405 | |
| 406 | /* There should be 4 devices */ |
Michal Suchanek | 98e1ada | 2022-10-12 21:58:09 +0200 | [diff] [blame] | 407 | for (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 408 | dev; |
Michal Suchanek | 98e1ada | 2022-10-12 21:58:09 +0200 | [diff] [blame] | 409 | uclass_next_device(&dev)) { |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 410 | count++; |
| 411 | parent = dev_get_parent(dev); |
| 412 | } |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 413 | ut_asserteq(4, count); |
| 414 | |
| 415 | /* Remove them and try again, with an error on the second one */ |
| 416 | ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 1, &dev)); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 417 | pdata = dev_get_plat(dev); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 418 | pdata->probe_err = -ENOMEM; |
| 419 | device_remove(parent, DM_REMOVE_NORMAL); |
Michal Suchanek | 98e1ada | 2022-10-12 21:58:09 +0200 | [diff] [blame] | 420 | for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev), |
| 421 | count = 0; |
| 422 | dev; |
| 423 | ret = uclass_next_device_check(&dev)) { |
| 424 | if (!ret) |
| 425 | count++; |
| 426 | else |
| 427 | ut_asserteq(-ENOMEM, ret); |
| 428 | parent = dev_get_parent(dev); |
| 429 | } |
| 430 | ut_asserteq(3, count); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 431 | |
| 432 | /* Now an error on the first one */ |
| 433 | ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev)); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 434 | pdata = dev_get_plat(dev); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 435 | pdata->probe_err = -ENOENT; |
| 436 | device_remove(parent, DM_REMOVE_NORMAL); |
Michal Suchanek | 98e1ada | 2022-10-12 21:58:09 +0200 | [diff] [blame] | 437 | for (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; |
| 438 | dev; |
| 439 | uclass_next_device(&dev)) { |
| 440 | count++; |
| 441 | parent = dev_get_parent(dev); |
| 442 | } |
| 443 | ut_asserteq(2, count); |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 444 | |
Michal Suchanek | f5a5902 | 2022-10-12 21:57:50 +0200 | [diff] [blame] | 445 | /* Now that broken devices are set up test probe_all */ |
| 446 | device_remove(parent, DM_REMOVE_NORMAL); |
| 447 | /* There are broken devices so an error should be returned */ |
| 448 | ut_assert(uclass_probe_all(UCLASS_TEST_PROBE) < 0); |
| 449 | /* but non-error device should be probed nonetheless */ |
| 450 | ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 2, &dev)); |
| 451 | ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); |
| 452 | ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 3, &dev)); |
| 453 | ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); |
| 454 | |
Simon Glass | 9c433fe | 2017-04-23 20:10:44 -0600 | [diff] [blame] | 455 | return 0; |
| 456 | } |
Michal Suchanek | f5a5902 | 2022-10-12 21:57:50 +0200 | [diff] [blame] | 457 | DM_TEST(dm_test_first_next_device_probeall, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 458 | UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 459 | |
Simon Glass | 27c0e17 | 2020-02-06 09:54:49 -0700 | [diff] [blame] | 460 | /* Test iteration through devices in a uclass */ |
| 461 | static int dm_test_uclass_foreach(struct unit_test_state *uts) |
| 462 | { |
| 463 | struct udevice *dev; |
| 464 | struct uclass *uc; |
| 465 | int count; |
| 466 | |
| 467 | count = 0; |
| 468 | uclass_id_foreach_dev(UCLASS_TEST_FDT, dev, uc) |
| 469 | count++; |
Jean-Jacques Hiblot | 7387340 | 2020-09-11 13:43:35 +0530 | [diff] [blame] | 470 | ut_asserteq(9, count); |
Simon Glass | 27c0e17 | 2020-02-06 09:54:49 -0700 | [diff] [blame] | 471 | |
| 472 | count = 0; |
| 473 | uclass_foreach_dev(dev, uc) |
| 474 | count++; |
Jean-Jacques Hiblot | 7387340 | 2020-09-11 13:43:35 +0530 | [diff] [blame] | 475 | ut_asserteq(9, count); |
Simon Glass | 27c0e17 | 2020-02-06 09:54:49 -0700 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 479 | DM_TEST(dm_test_uclass_foreach, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 27c0e17 | 2020-02-06 09:54:49 -0700 | [diff] [blame] | 480 | |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 481 | /** |
| 482 | * check_devices() - Check return values and pointers |
| 483 | * |
| 484 | * This runs through a full sequence of uclass_first_device_check()... |
| 485 | * uclass_next_device_check() checking that the return values and devices |
| 486 | * are correct. |
| 487 | * |
| 488 | * @uts: Test state |
| 489 | * @devlist: List of expected devices |
| 490 | * @mask: Indicates which devices should return an error. Device n should |
| 491 | * return error (-NOENT - n) if bit n is set, or no error (i.e. 0) if |
| 492 | * bit n is clear. |
| 493 | */ |
| 494 | static int check_devices(struct unit_test_state *uts, |
| 495 | struct udevice *devlist[], int mask) |
| 496 | { |
| 497 | int expected_ret; |
| 498 | struct udevice *dev; |
| 499 | int i; |
| 500 | |
| 501 | expected_ret = (mask & 1) ? -ENOENT : 0; |
| 502 | mask >>= 1; |
| 503 | ut_asserteq(expected_ret, |
| 504 | uclass_first_device_check(UCLASS_TEST_PROBE, &dev)); |
| 505 | for (i = 0; i < 4; i++) { |
| 506 | ut_asserteq_ptr(devlist[i], dev); |
| 507 | expected_ret = (mask & 1) ? -ENOENT - (i + 1) : 0; |
| 508 | mask >>= 1; |
| 509 | ut_asserteq(expected_ret, uclass_next_device_check(&dev)); |
| 510 | } |
| 511 | ut_asserteq_ptr(NULL, dev); |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* Test uclass_first_device_check() and uclass_next_device_check() */ |
| 517 | static int dm_test_first_next_ok_device(struct unit_test_state *uts) |
| 518 | { |
| 519 | struct dm_testprobe_pdata *pdata; |
| 520 | struct udevice *dev, *parent = NULL, *devlist[4]; |
| 521 | int count; |
| 522 | int ret; |
| 523 | |
| 524 | /* There should be 4 devices */ |
| 525 | count = 0; |
| 526 | for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev); |
| 527 | dev; |
| 528 | ret = uclass_next_device_check(&dev)) { |
| 529 | ut_assertok(ret); |
| 530 | devlist[count++] = dev; |
| 531 | parent = dev_get_parent(dev); |
| 532 | } |
| 533 | ut_asserteq(4, count); |
| 534 | ut_assertok(uclass_first_device_check(UCLASS_TEST_PROBE, &dev)); |
| 535 | ut_assertok(check_devices(uts, devlist, 0)); |
| 536 | |
| 537 | /* Remove them and try again, with an error on the second one */ |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 538 | pdata = dev_get_plat(devlist[1]); |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 539 | pdata->probe_err = -ENOENT - 1; |
| 540 | device_remove(parent, DM_REMOVE_NORMAL); |
| 541 | ut_assertok(check_devices(uts, devlist, 1 << 1)); |
| 542 | |
| 543 | /* Now an error on the first one */ |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 544 | pdata = dev_get_plat(devlist[0]); |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 545 | pdata->probe_err = -ENOENT - 0; |
| 546 | device_remove(parent, DM_REMOVE_NORMAL); |
| 547 | ut_assertok(check_devices(uts, devlist, 3 << 0)); |
| 548 | |
| 549 | /* Now errors on all */ |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 550 | pdata = dev_get_plat(devlist[2]); |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 551 | pdata->probe_err = -ENOENT - 2; |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 552 | pdata = dev_get_plat(devlist[3]); |
Simon Glass | 3ff83bc | 2017-04-23 20:10:45 -0600 | [diff] [blame] | 553 | pdata->probe_err = -ENOENT - 3; |
| 554 | device_remove(parent, DM_REMOVE_NORMAL); |
| 555 | ut_assertok(check_devices(uts, devlist, 0xf << 0)); |
| 556 | |
| 557 | return 0; |
| 558 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 559 | DM_TEST(dm_test_first_next_ok_device, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 560 | |
| 561 | static const struct udevice_id fdt_dummy_ids[] = { |
| 562 | { .compatible = "denx,u-boot-fdt-dummy", }, |
| 563 | { } |
| 564 | }; |
| 565 | |
| 566 | UCLASS_DRIVER(fdt_dummy) = { |
Eugeniu Rosca | 5ba71e5 | 2018-05-19 14:13:55 +0200 | [diff] [blame] | 567 | .name = "fdt-dummy", |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 568 | .id = UCLASS_TEST_DUMMY, |
| 569 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 570 | }; |
| 571 | |
| 572 | U_BOOT_DRIVER(fdt_dummy_drv) = { |
| 573 | .name = "fdt_dummy_drv", |
| 574 | .of_match = fdt_dummy_ids, |
| 575 | .id = UCLASS_TEST_DUMMY, |
| 576 | }; |
| 577 | |
| 578 | static int dm_test_fdt_translation(struct unit_test_state *uts) |
| 579 | { |
| 580 | struct udevice *dev; |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 581 | fdt32_t dma_addr[2]; |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 582 | |
| 583 | /* Some simple translations */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 584 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 585 | ut_asserteq_str("dev@0,0", dev->name); |
| 586 | ut_asserteq(0x8000, dev_read_addr(dev)); |
| 587 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 588 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev)); |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 589 | ut_asserteq_str("dev@1,100", dev->name); |
| 590 | ut_asserteq(0x9000, dev_read_addr(dev)); |
| 591 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 592 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, &dev)); |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 593 | ut_asserteq_str("dev@2,200", dev->name); |
| 594 | ut_asserteq(0xA000, dev_read_addr(dev)); |
| 595 | |
Yuepeng Xing | 71cc021 | 2022-12-02 14:23:07 +0800 | [diff] [blame] | 596 | /* No translation for buses with #size-cells == 0 */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 597 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, &dev)); |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 598 | ut_asserteq_str("dev@42", dev->name); |
| 599 | ut_asserteq(0x42, dev_read_addr(dev)); |
| 600 | |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 601 | /* dma address translation */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 602 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 603 | dma_addr[0] = cpu_to_be32(0); |
| 604 | dma_addr[1] = cpu_to_be32(0); |
| 605 | ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr)); |
| 606 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 607 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, &dev)); |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 608 | dma_addr[0] = cpu_to_be32(1); |
| 609 | dma_addr[1] = cpu_to_be32(0x100); |
| 610 | ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr)); |
| 611 | |
Mario Six | 35616ef | 2018-03-12 14:53:33 +0100 | [diff] [blame] | 612 | return 0; |
| 613 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 614 | DM_TEST(dm_test_fdt_translation, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 615 | |
Ovidiu Panait | 1b6773c | 2020-08-03 22:17:36 +0300 | [diff] [blame] | 616 | static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts) |
| 617 | { |
| 618 | struct udevice *gpio, *dev; |
| 619 | void *ptr; |
Johan Jonker | 8664860 | 2023-04-23 11:19:41 +0200 | [diff] [blame] | 620 | void *paddr; |
Ovidiu Panait | 1b6773c | 2020-08-03 22:17:36 +0300 | [diff] [blame] | 621 | |
| 622 | /* Test for missing reg property */ |
| 623 | ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio)); |
| 624 | ut_assertnull(devfdt_get_addr_ptr(gpio)); |
| 625 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 626 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Ovidiu Panait | 1b6773c | 2020-08-03 22:17:36 +0300 | [diff] [blame] | 627 | ptr = devfdt_get_addr_ptr(dev); |
Johan Jonker | 8664860 | 2023-04-23 11:19:41 +0200 | [diff] [blame] | 628 | |
| 629 | paddr = map_sysmem(0x8000, 0); |
| 630 | ut_asserteq_ptr(paddr, ptr); |
Ovidiu Panait | 1b6773c | 2020-08-03 22:17:36 +0300 | [diff] [blame] | 631 | |
| 632 | return 0; |
| 633 | } |
| 634 | DM_TEST(dm_test_fdt_get_addr_ptr_flat, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 635 | UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE); |
Ovidiu Panait | 1b6773c | 2020-08-03 22:17:36 +0300 | [diff] [blame] | 636 | |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 637 | static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) |
| 638 | { |
| 639 | struct udevice *dev; |
| 640 | fdt_addr_t addr; |
| 641 | void *paddr; |
| 642 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 643 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 644 | |
| 645 | addr = devfdt_get_addr(dev); |
| 646 | ut_asserteq(0x8000, addr); |
| 647 | |
| 648 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 649 | ut_assertnonnull(paddr); |
| 650 | ut_asserteq_ptr(paddr, devfdt_remap_addr(dev)); |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | DM_TEST(dm_test_fdt_remap_addr_flat, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 655 | UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE); |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 656 | |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 657 | static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts) |
| 658 | { |
| 659 | struct udevice *dev; |
| 660 | fdt_addr_t addr; |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 661 | fdt_size_t size; |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 662 | void *paddr; |
| 663 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 664 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 665 | |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 666 | addr = devfdt_get_addr_size_index(dev, 0, &size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 667 | ut_asserteq(0x8000, addr); |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 668 | ut_asserteq(0x1000, size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 669 | |
| 670 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 671 | ut_assertnonnull(paddr); |
| 672 | ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0)); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | DM_TEST(dm_test_fdt_remap_addr_index_flat, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 677 | UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 678 | |
| 679 | static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts) |
| 680 | { |
| 681 | struct udevice *dev; |
| 682 | fdt_addr_t addr; |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 683 | fdt_size_t size; |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 684 | void *paddr; |
| 685 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 686 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 687 | |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 688 | addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 689 | ut_asserteq(0x8000, addr); |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 690 | ut_asserteq(0x1000, size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 691 | |
| 692 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 693 | ut_assertnonnull(paddr); |
| 694 | ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0")); |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | DM_TEST(dm_test_fdt_remap_addr_name_flat, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 699 | UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 700 | |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 701 | static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) |
| 702 | { |
| 703 | struct udevice *dev; |
| 704 | fdt_addr_t addr; |
| 705 | void *paddr; |
| 706 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 707 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 708 | |
| 709 | addr = dev_read_addr(dev); |
| 710 | ut_asserteq(0x8000, addr); |
| 711 | |
| 712 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 713 | ut_assertnonnull(paddr); |
| 714 | ut_asserteq_ptr(paddr, dev_remap_addr(dev)); |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | DM_TEST(dm_test_fdt_remap_addr_live, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 719 | UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Mario Six | 058ef5b | 2018-06-26 08:46:49 +0200 | [diff] [blame] | 720 | |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 721 | static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts) |
| 722 | { |
| 723 | struct udevice *dev; |
| 724 | fdt_addr_t addr; |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 725 | fdt_size_t size; |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 726 | void *paddr; |
| 727 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 728 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 729 | |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 730 | addr = dev_read_addr_size_index(dev, 0, &size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 731 | ut_asserteq(0x8000, addr); |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 732 | ut_asserteq(0x1000, size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 733 | |
| 734 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 735 | ut_assertnonnull(paddr); |
| 736 | ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0)); |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | DM_TEST(dm_test_fdt_remap_addr_index_live, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 741 | UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 742 | |
| 743 | static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts) |
| 744 | { |
| 745 | struct udevice *dev; |
| 746 | fdt_addr_t addr; |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 747 | fdt_size_t size; |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 748 | void *paddr; |
| 749 | |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 750 | ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 751 | |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 752 | addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 753 | ut_asserteq(0x8000, addr); |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 754 | ut_asserteq(0x1000, size); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 755 | |
| 756 | paddr = map_physmem(addr, 0, MAP_NOCACHE); |
| 757 | ut_assertnonnull(paddr); |
| 758 | ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0")); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | DM_TEST(dm_test_fdt_remap_addr_name_live, |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 763 | UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 764 | |
Mario Six | d6f6dc3 | 2018-06-26 08:46:51 +0200 | [diff] [blame] | 765 | static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts) |
| 766 | { |
| 767 | ofnode node; |
| 768 | |
| 769 | if (!of_live_active()) { |
| 770 | printf("Live tree not active; ignore test\n"); |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | node = ofnode_path("/usb@2"); |
| 775 | |
| 776 | /* Test enabling devices */ |
| 777 | |
| 778 | ut_assert(!of_device_is_available(ofnode_to_np(node))); |
| 779 | dev_enable_by_path("/usb@2"); |
| 780 | ut_assert(of_device_is_available(ofnode_to_np(node))); |
| 781 | |
| 782 | /* Test disabling devices */ |
| 783 | |
| 784 | ut_assert(of_device_is_available(ofnode_to_np(node))); |
| 785 | dev_disable_by_path("/usb@2"); |
| 786 | ut_assert(!of_device_is_available(ofnode_to_np(node))); |
| 787 | |
| 788 | return 0; |
| 789 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 790 | DM_TEST(dm_test_fdt_disable_enable_by_path, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | dc3efdc | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 791 | |
| 792 | /* Test a few uclass phandle functions */ |
| 793 | static int dm_test_fdt_phandle(struct unit_test_state *uts) |
| 794 | { |
| 795 | struct udevice *back, *dev, *dev2; |
| 796 | |
| 797 | ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &back)); |
Heinrich Schuchardt | 6c2a871 | 2020-07-17 00:20:14 +0200 | [diff] [blame] | 798 | ut_assertnonnull(back); |
Simon Glass | dc3efdc | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 799 | ut_asserteq(-ENOENT, uclass_find_device_by_phandle(UCLASS_REGULATOR, |
| 800 | back, "missing", &dev)); |
| 801 | ut_assertok(uclass_find_device_by_phandle(UCLASS_REGULATOR, back, |
| 802 | "power-supply", &dev)); |
Heinrich Schuchardt | 6c2a871 | 2020-07-17 00:20:14 +0200 | [diff] [blame] | 803 | ut_assertnonnull(dev); |
Simon Glass | dc3efdc | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 804 | ut_asserteq(0, device_active(dev)); |
| 805 | ut_asserteq_str("ldo1", dev->name); |
| 806 | ut_assertok(uclass_get_device_by_phandle(UCLASS_REGULATOR, back, |
| 807 | "power-supply", &dev2)); |
| 808 | ut_asserteq_ptr(dev, dev2); |
| 809 | |
| 810 | return 0; |
| 811 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 812 | DM_TEST(dm_test_fdt_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | a11341a | 2018-11-18 08:14:31 -0700 | [diff] [blame] | 813 | |
| 814 | /* Test device_find_first_child_by_uclass() */ |
| 815 | static int dm_test_first_child(struct unit_test_state *uts) |
| 816 | { |
| 817 | struct udevice *i2c, *dev, *dev2; |
| 818 | |
| 819 | ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c)); |
| 820 | ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_RTC, &dev)); |
| 821 | ut_asserteq_str("rtc@43", dev->name); |
| 822 | ut_assertok(device_find_child_by_name(i2c, "rtc@43", &dev2)); |
| 823 | ut_asserteq_ptr(dev, dev2); |
| 824 | ut_assertok(device_find_child_by_name(i2c, "rtc@61", &dev2)); |
| 825 | ut_asserteq_str("rtc@61", dev2->name); |
| 826 | |
| 827 | ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_I2C_EEPROM, |
| 828 | &dev)); |
| 829 | ut_asserteq_str("eeprom@2c", dev->name); |
| 830 | ut_assertok(device_find_child_by_name(i2c, "eeprom@2c", &dev2)); |
| 831 | ut_asserteq_ptr(dev, dev2); |
| 832 | |
| 833 | ut_asserteq(-ENODEV, device_find_first_child_by_uclass(i2c, |
| 834 | UCLASS_VIDEO, &dev)); |
| 835 | ut_asserteq(-ENODEV, device_find_child_by_name(i2c, "missing", &dev)); |
| 836 | |
| 837 | return 0; |
| 838 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 839 | DM_TEST(dm_test_first_child, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 840 | |
| 841 | /* Test integer functions in dm_read_...() */ |
| 842 | static int dm_test_read_int(struct unit_test_state *uts) |
| 843 | { |
| 844 | struct udevice *dev; |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 845 | u8 val8; |
| 846 | u16 val16; |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 847 | u32 val32; |
| 848 | s32 sval; |
| 849 | uint val; |
Dario Binacchi | 421e81e | 2020-03-29 18:04:40 +0200 | [diff] [blame] | 850 | u64 val64; |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 851 | |
| 852 | ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); |
| 853 | ut_asserteq_str("a-test", dev->name); |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 854 | |
| 855 | ut_assertok(dev_read_u8(dev, "int8-value", &val8)); |
| 856 | ut_asserteq(0x12, val8); |
| 857 | |
| 858 | ut_asserteq(-EINVAL, dev_read_u8(dev, "missing", &val8)); |
| 859 | ut_asserteq(6, dev_read_u8_default(dev, "missing", 6)); |
| 860 | |
| 861 | ut_asserteq(0x12, dev_read_u8_default(dev, "int8-value", 6)); |
| 862 | |
| 863 | ut_assertok(dev_read_u16(dev, "int16-value", &val16)); |
| 864 | ut_asserteq(0x1234, val16); |
| 865 | |
| 866 | ut_asserteq(-EINVAL, dev_read_u16(dev, "missing", &val16)); |
| 867 | ut_asserteq(6, dev_read_u16_default(dev, "missing", 6)); |
| 868 | |
| 869 | ut_asserteq(0x1234, dev_read_u16_default(dev, "int16-value", 6)); |
| 870 | |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 871 | ut_assertok(dev_read_u32(dev, "int-value", &val32)); |
| 872 | ut_asserteq(1234, val32); |
| 873 | |
| 874 | ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32)); |
| 875 | ut_asserteq(6, dev_read_u32_default(dev, "missing", 6)); |
| 876 | |
| 877 | ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6)); |
| 878 | ut_asserteq(1234, val32); |
| 879 | |
| 880 | ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval)); |
| 881 | ut_asserteq(6, dev_read_s32_default(dev, "missing", 6)); |
| 882 | |
| 883 | ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6)); |
| 884 | ut_assertok(dev_read_s32(dev, "uint-value", &sval)); |
| 885 | ut_asserteq(-1234, sval); |
| 886 | |
| 887 | val = 0; |
| 888 | ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val)); |
| 889 | ut_assertok(dev_read_u32u(dev, "uint-value", &val)); |
| 890 | ut_asserteq(-1234, val); |
| 891 | |
Dario Binacchi | 421e81e | 2020-03-29 18:04:40 +0200 | [diff] [blame] | 892 | ut_assertok(dev_read_u64(dev, "int64-value", &val64)); |
| 893 | ut_asserteq_64(0x1111222233334444, val64); |
| 894 | |
| 895 | ut_asserteq_64(-EINVAL, dev_read_u64(dev, "missing", &val64)); |
| 896 | ut_asserteq_64(6, dev_read_u64_default(dev, "missing", 6)); |
| 897 | |
| 898 | ut_asserteq_64(0x1111222233334444, |
| 899 | dev_read_u64_default(dev, "int64-value", 6)); |
| 900 | |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 901 | return 0; |
| 902 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 903 | DM_TEST(dm_test_read_int, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 35cb2a4 | 2020-02-06 09:54:50 -0700 | [diff] [blame] | 904 | |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 905 | static int dm_test_read_int_index(struct unit_test_state *uts) |
| 906 | { |
| 907 | struct udevice *dev; |
| 908 | u32 val32; |
| 909 | |
| 910 | ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); |
| 911 | ut_asserteq_str("a-test", dev->name); |
| 912 | |
| 913 | ut_asserteq(-EINVAL, dev_read_u32_index(dev, "missing", 0, &val32)); |
| 914 | ut_asserteq(19, dev_read_u32_index_default(dev, "missing", 0, 19)); |
| 915 | |
| 916 | ut_assertok(dev_read_u32_index(dev, "int-array", 0, &val32)); |
| 917 | ut_asserteq(5678, val32); |
| 918 | ut_assertok(dev_read_u32_index(dev, "int-array", 1, &val32)); |
| 919 | ut_asserteq(9123, val32); |
| 920 | ut_assertok(dev_read_u32_index(dev, "int-array", 2, &val32)); |
| 921 | ut_asserteq(4567, val32); |
| 922 | ut_asserteq(-EOVERFLOW, dev_read_u32_index(dev, "int-array", 3, |
| 923 | &val32)); |
| 924 | |
| 925 | ut_asserteq(5678, dev_read_u32_index_default(dev, "int-array", 0, 2)); |
| 926 | ut_asserteq(9123, dev_read_u32_index_default(dev, "int-array", 1, 2)); |
| 927 | ut_asserteq(4567, dev_read_u32_index_default(dev, "int-array", 2, 2)); |
| 928 | ut_asserteq(2, dev_read_u32_index_default(dev, "int-array", 3, 2)); |
| 929 | |
| 930 | return 0; |
| 931 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 932 | DM_TEST(dm_test_read_int_index, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 933 | |
Patrick Delaunay | 8cd2801 | 2020-09-25 09:41:16 +0200 | [diff] [blame] | 934 | static int dm_test_read_phandle(struct unit_test_state *uts) |
| 935 | { |
| 936 | struct udevice *dev; |
| 937 | struct ofnode_phandle_args args; |
| 938 | int ret; |
| 939 | const char prop[] = "test-gpios"; |
| 940 | const char cell[] = "#gpio-cells"; |
| 941 | const char prop2[] = "phandle-value"; |
| 942 | |
| 943 | ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); |
| 944 | ut_asserteq_str("a-test", dev->name); |
| 945 | |
| 946 | /* Test dev_count_phandle_with_args with cell name */ |
| 947 | ret = dev_count_phandle_with_args(dev, "missing", cell, 0); |
| 948 | ut_asserteq(-ENOENT, ret); |
| 949 | ret = dev_count_phandle_with_args(dev, prop, "#invalid", 0); |
| 950 | ut_asserteq(-EINVAL, ret); |
| 951 | ut_asserteq(5, dev_count_phandle_with_args(dev, prop, cell, 0)); |
| 952 | |
| 953 | /* Test dev_read_phandle_with_args with cell name */ |
| 954 | ret = dev_read_phandle_with_args(dev, "missing", cell, 0, 0, &args); |
| 955 | ut_asserteq(-ENOENT, ret); |
| 956 | ret = dev_read_phandle_with_args(dev, prop, "#invalid", 0, 0, &args); |
| 957 | ut_asserteq(-EINVAL, ret); |
| 958 | ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 0, &args)); |
| 959 | ut_asserteq(1, args.args_count); |
| 960 | ut_asserteq(1, args.args[0]); |
| 961 | ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 1, &args)); |
| 962 | ut_asserteq(1, args.args_count); |
| 963 | ut_asserteq(4, args.args[0]); |
| 964 | ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 2, &args)); |
| 965 | ut_asserteq(5, args.args_count); |
| 966 | ut_asserteq(5, args.args[0]); |
| 967 | ut_asserteq(1, args.args[4]); |
| 968 | ret = dev_read_phandle_with_args(dev, prop, cell, 0, 3, &args); |
| 969 | ut_asserteq(-ENOENT, ret); |
| 970 | ut_assertok(dev_read_phandle_with_args(dev, prop, cell, 0, 4, &args)); |
| 971 | ut_asserteq(1, args.args_count); |
| 972 | ut_asserteq(12, args.args[0]); |
| 973 | ret = dev_read_phandle_with_args(dev, prop, cell, 0, 5, &args); |
| 974 | ut_asserteq(-ENOENT, ret); |
| 975 | |
| 976 | /* Test dev_count_phandle_with_args with cell count */ |
| 977 | ret = dev_count_phandle_with_args(dev, "missing", NULL, 2); |
| 978 | ut_asserteq(-ENOENT, ret); |
| 979 | ut_asserteq(3, dev_count_phandle_with_args(dev, prop2, NULL, 1)); |
| 980 | |
| 981 | /* Test dev_read_phandle_with_args with cell count */ |
| 982 | ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 0, &args)); |
| 983 | ut_asserteq(1, ofnode_valid(args.node)); |
| 984 | ut_asserteq(1, args.args_count); |
| 985 | ut_asserteq(10, args.args[0]); |
| 986 | ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 1, &args); |
| 987 | ut_asserteq(-EINVAL, ret); |
| 988 | ut_assertok(dev_read_phandle_with_args(dev, prop2, NULL, 1, 2, &args)); |
| 989 | ut_asserteq(1, ofnode_valid(args.node)); |
| 990 | ut_asserteq(1, args.args_count); |
| 991 | ut_asserteq(30, args.args[0]); |
| 992 | ret = dev_read_phandle_with_args(dev, prop2, NULL, 1, 3, &args); |
| 993 | ut_asserteq(-ENOENT, ret); |
| 994 | |
| 995 | return 0; |
| 996 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 997 | DM_TEST(dm_test_read_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Patrick Delaunay | 8cd2801 | 2020-09-25 09:41:16 +0200 | [diff] [blame] | 998 | |
Simon Glass | 35cb2a4 | 2020-02-06 09:54:50 -0700 | [diff] [blame] | 999 | /* Test iteration through devices by drvdata */ |
| 1000 | static int dm_test_uclass_drvdata(struct unit_test_state *uts) |
| 1001 | { |
| 1002 | struct udevice *dev; |
| 1003 | |
| 1004 | ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT, |
| 1005 | DM_TEST_TYPE_FIRST, &dev)); |
| 1006 | ut_asserteq_str("a-test", dev->name); |
| 1007 | |
| 1008 | ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT, |
| 1009 | DM_TEST_TYPE_SECOND, &dev)); |
| 1010 | ut_asserteq_str("d-test", dev->name); |
| 1011 | |
| 1012 | ut_asserteq(-ENODEV, uclass_first_device_drvdata(UCLASS_TEST_FDT, |
| 1013 | DM_TEST_TYPE_COUNT, |
| 1014 | &dev)); |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1018 | DM_TEST(dm_test_uclass_drvdata, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Tom Rini | b7b1838 | 2020-02-11 10:58:41 -0500 | [diff] [blame] | 1019 | |
Simon Glass | 000676b | 2020-01-27 08:49:47 -0700 | [diff] [blame] | 1020 | /* Test device_first_child_ofdata_err(), etc. */ |
| 1021 | static int dm_test_child_ofdata(struct unit_test_state *uts) |
| 1022 | { |
| 1023 | struct udevice *bus, *dev; |
| 1024 | int count; |
| 1025 | |
| 1026 | ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); |
| 1027 | count = 0; |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1028 | device_foreach_child_of_to_plat(dev, bus) { |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1029 | ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); |
| 1030 | ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); |
Simon Glass | 000676b | 2020-01-27 08:49:47 -0700 | [diff] [blame] | 1031 | count++; |
| 1032 | } |
| 1033 | ut_asserteq(3, count); |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1037 | DM_TEST(dm_test_child_ofdata, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 76db9b7 | 2020-01-27 08:49:48 -0700 | [diff] [blame] | 1038 | |
| 1039 | /* Test device_first_child_err(), etc. */ |
| 1040 | static int dm_test_first_child_probe(struct unit_test_state *uts) |
| 1041 | { |
| 1042 | struct udevice *bus, *dev; |
| 1043 | int count; |
| 1044 | |
| 1045 | ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); |
| 1046 | count = 0; |
| 1047 | device_foreach_child_probe(dev, bus) { |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1048 | ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); |
| 1049 | ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); |
Simon Glass | 76db9b7 | 2020-01-27 08:49:48 -0700 | [diff] [blame] | 1050 | count++; |
| 1051 | } |
| 1052 | ut_asserteq(3, count); |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1056 | DM_TEST(dm_test_first_child_probe, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 44c4789 | 2020-04-05 15:38:19 -0600 | [diff] [blame] | 1057 | |
| 1058 | /* Test that ofdata is read for parents before children */ |
| 1059 | static int dm_test_ofdata_order(struct unit_test_state *uts) |
| 1060 | { |
| 1061 | struct udevice *bus, *dev; |
| 1062 | |
| 1063 | ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus)); |
| 1064 | ut_assertnonnull(bus); |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1065 | ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID)); |
Simon Glass | 44c4789 | 2020-04-05 15:38:19 -0600 | [diff] [blame] | 1066 | |
| 1067 | ut_assertok(device_find_first_child(bus, &dev)); |
| 1068 | ut_assertnonnull(dev); |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1069 | ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)); |
Simon Glass | 44c4789 | 2020-04-05 15:38:19 -0600 | [diff] [blame] | 1070 | |
| 1071 | /* read the child's ofdata which should cause the parent's to be read */ |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1072 | ut_assertok(device_of_to_plat(dev)); |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1073 | ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); |
| 1074 | ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID); |
Simon Glass | 44c4789 | 2020-04-05 15:38:19 -0600 | [diff] [blame] | 1075 | |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 1076 | ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); |
| 1077 | ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED)); |
Simon Glass | 44c4789 | 2020-04-05 15:38:19 -0600 | [diff] [blame] | 1078 | |
| 1079 | return 0; |
| 1080 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1081 | DM_TEST(dm_test_ofdata_order, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Dario Binacchi | 836cc9d | 2020-12-30 00:16:26 +0100 | [diff] [blame] | 1082 | |
| 1083 | /* Test dev_decode_display_timing() */ |
| 1084 | static int dm_test_decode_display_timing(struct unit_test_state *uts) |
| 1085 | { |
| 1086 | struct udevice *dev; |
| 1087 | struct display_timing timing; |
| 1088 | |
| 1089 | ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); |
| 1090 | ut_asserteq_str("a-test", dev->name); |
| 1091 | |
| 1092 | ut_assertok(dev_decode_display_timing(dev, 0, &timing)); |
| 1093 | ut_assert(timing.hactive.typ == 240); |
| 1094 | ut_assert(timing.hback_porch.typ == 7); |
| 1095 | ut_assert(timing.hfront_porch.typ == 6); |
| 1096 | ut_assert(timing.hsync_len.typ == 1); |
| 1097 | ut_assert(timing.vactive.typ == 320); |
| 1098 | ut_assert(timing.vback_porch.typ == 5); |
| 1099 | ut_assert(timing.vfront_porch.typ == 8); |
| 1100 | ut_assert(timing.vsync_len.typ == 2); |
| 1101 | ut_assert(timing.pixelclock.typ == 6500000); |
| 1102 | ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH); |
| 1103 | ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW)); |
| 1104 | ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH)); |
| 1105 | ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_LOW); |
| 1106 | ut_assert(timing.flags & DISPLAY_FLAGS_DE_HIGH); |
| 1107 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW)); |
| 1108 | ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE); |
| 1109 | ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)); |
| 1110 | ut_assert(timing.flags & DISPLAY_FLAGS_INTERLACED); |
| 1111 | ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLESCAN); |
| 1112 | ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLECLK); |
| 1113 | |
| 1114 | ut_assertok(dev_decode_display_timing(dev, 1, &timing)); |
| 1115 | ut_assert(timing.hactive.typ == 480); |
| 1116 | ut_assert(timing.hback_porch.typ == 59); |
| 1117 | ut_assert(timing.hfront_porch.typ == 10); |
| 1118 | ut_assert(timing.hsync_len.typ == 12); |
| 1119 | ut_assert(timing.vactive.typ == 800); |
| 1120 | ut_assert(timing.vback_porch.typ == 15); |
| 1121 | ut_assert(timing.vfront_porch.typ == 17); |
| 1122 | ut_assert(timing.vsync_len.typ == 16); |
| 1123 | ut_assert(timing.pixelclock.typ == 9000000); |
| 1124 | ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH)); |
| 1125 | ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_LOW); |
| 1126 | ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH); |
| 1127 | ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_LOW)); |
| 1128 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_HIGH)); |
| 1129 | ut_assert(timing.flags & DISPLAY_FLAGS_DE_LOW); |
| 1130 | ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)); |
| 1131 | ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE); |
| 1132 | ut_assert(!(timing.flags & DISPLAY_FLAGS_INTERLACED)); |
| 1133 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLESCAN)); |
| 1134 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLECLK)); |
| 1135 | |
| 1136 | ut_assertok(dev_decode_display_timing(dev, 2, &timing)); |
| 1137 | ut_assert(timing.hactive.typ == 800); |
| 1138 | ut_assert(timing.hback_porch.typ == 89); |
| 1139 | ut_assert(timing.hfront_porch.typ == 164); |
| 1140 | ut_assert(timing.hsync_len.typ == 11); |
| 1141 | ut_assert(timing.vactive.typ == 480); |
| 1142 | ut_assert(timing.vback_porch.typ == 23); |
| 1143 | ut_assert(timing.vfront_porch.typ == 10); |
| 1144 | ut_assert(timing.vsync_len.typ == 13); |
| 1145 | ut_assert(timing.pixelclock.typ == 33500000); |
| 1146 | ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH)); |
| 1147 | ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW)); |
| 1148 | ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH)); |
| 1149 | ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_LOW)); |
| 1150 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_HIGH)); |
| 1151 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW)); |
| 1152 | ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)); |
| 1153 | ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)); |
| 1154 | ut_assert(!(timing.flags & DISPLAY_FLAGS_INTERLACED)); |
| 1155 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLESCAN)); |
| 1156 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DOUBLECLK)); |
| 1157 | |
| 1158 | ut_assert(dev_decode_display_timing(dev, 3, &timing)); |
| 1159 | return 0; |
| 1160 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1161 | DM_TEST(dm_test_decode_display_timing, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Patrick Delaunay | da37ed3 | 2021-05-21 12:25:00 +0200 | [diff] [blame] | 1162 | |
Nikhil M Jain | bb9d131 | 2023-01-31 15:35:15 +0530 | [diff] [blame] | 1163 | /* Test dev_decode_panel_timing() */ |
| 1164 | static int dm_test_decode_panel_timing(struct unit_test_state *uts) |
| 1165 | { |
| 1166 | struct udevice *dev; |
| 1167 | struct display_timing timing; |
| 1168 | |
| 1169 | ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); |
| 1170 | ut_asserteq_str("a-test", dev->name); |
| 1171 | |
| 1172 | ut_assertok(dev_decode_panel_timing(dev, &timing)); |
| 1173 | ut_assert(timing.hactive.typ == 240); |
| 1174 | ut_assert(timing.hback_porch.typ == 7); |
| 1175 | ut_assert(timing.hfront_porch.typ == 6); |
| 1176 | ut_assert(timing.hsync_len.typ == 1); |
| 1177 | ut_assert(timing.vactive.typ == 320); |
| 1178 | ut_assert(timing.vback_porch.typ == 5); |
| 1179 | ut_assert(timing.vfront_porch.typ == 8); |
| 1180 | ut_assert(timing.vsync_len.typ == 2); |
| 1181 | ut_assert(timing.pixelclock.typ == 6500000); |
| 1182 | ut_assert(timing.flags & DISPLAY_FLAGS_HSYNC_HIGH); |
| 1183 | ut_assert(!(timing.flags & DISPLAY_FLAGS_HSYNC_LOW)); |
| 1184 | ut_assert(!(timing.flags & DISPLAY_FLAGS_VSYNC_HIGH)); |
| 1185 | ut_assert(timing.flags & DISPLAY_FLAGS_VSYNC_LOW); |
| 1186 | ut_assert(timing.flags & DISPLAY_FLAGS_DE_HIGH); |
| 1187 | ut_assert(!(timing.flags & DISPLAY_FLAGS_DE_LOW)); |
| 1188 | ut_assert(timing.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE); |
| 1189 | ut_assert(!(timing.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)); |
| 1190 | ut_assert(timing.flags & DISPLAY_FLAGS_INTERLACED); |
| 1191 | ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLESCAN); |
| 1192 | ut_assert(timing.flags & DISPLAY_FLAGS_DOUBLECLK); |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1196 | DM_TEST(dm_test_decode_panel_timing, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Nikhil M Jain | bb9d131 | 2023-01-31 15:35:15 +0530 | [diff] [blame] | 1197 | |
Patrick Delaunay | da37ed3 | 2021-05-21 12:25:00 +0200 | [diff] [blame] | 1198 | /* Test read_resourcee() */ |
| 1199 | static int dm_test_read_resource(struct unit_test_state *uts) |
| 1200 | { |
| 1201 | struct udevice *dev; |
| 1202 | struct resource res; |
| 1203 | |
| 1204 | /* test resource without translation */ |
| 1205 | ut_assertok(uclass_find_device_by_name(UCLASS_SIMPLE_BUS, "syscon@2", &dev)); |
| 1206 | ut_assertok(dev_read_resource(dev, 0, &res)); |
| 1207 | ut_asserteq(0x40, res.start); |
| 1208 | ut_asserteq(0x44, res.end); |
| 1209 | ut_assertok(dev_read_resource(dev, 1, &res)); |
| 1210 | ut_asserteq(0x48, res.start); |
| 1211 | ut_asserteq(0x4d, res.end); |
| 1212 | |
| 1213 | /* test resource with translation */ |
| 1214 | ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@1,100", &dev)); |
| 1215 | ut_assertok(dev_read_resource(dev, 0, &res)); |
| 1216 | ut_asserteq(0x9000, res.start); |
| 1217 | ut_asserteq(0x9fff, res.end); |
| 1218 | |
| 1219 | /* test named resource */ |
| 1220 | ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@0,0", &dev)); |
| 1221 | ut_assertok(dev_read_resource_byname(dev, "sandbox-dummy-0", &res)); |
| 1222 | ut_asserteq(0x8000, res.start); |
| 1223 | ut_asserteq(0x8fff, res.end); |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 1227 | DM_TEST(dm_test_read_resource, UTF_SCAN_PDATA | UTF_SCAN_FDT); |