test-fdt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <fdtdec.h>
  9. #include <malloc.h>
  10. #include <asm/io.h>
  11. #include <dm/test.h>
  12. #include <dm/root.h>
  13. #include <dm/device-internal.h>
  14. #include <dm/uclass-internal.h>
  15. #include <dm/util.h>
  16. #include <dm/lists.h>
  17. #include <dm/of_access.h>
  18. #include <test/ut.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
  21. {
  22. const struct dm_test_pdata *pdata = dev->platdata;
  23. struct dm_test_priv *priv = dev_get_priv(dev);
  24. *pingret = pingval + pdata->ping_add;
  25. priv->ping_total += *pingret;
  26. return 0;
  27. }
  28. static const struct test_ops test_ops = {
  29. .ping = testfdt_drv_ping,
  30. };
  31. static int testfdt_ofdata_to_platdata(struct udevice *dev)
  32. {
  33. struct dm_test_pdata *pdata = dev_get_platdata(dev);
  34. pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  35. "ping-add", -1);
  36. pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
  37. "ping-expect");
  38. return 0;
  39. }
  40. static int testfdt_drv_probe(struct udevice *dev)
  41. {
  42. struct dm_test_priv *priv = dev_get_priv(dev);
  43. priv->ping_total += DM_TEST_START_TOTAL;
  44. /*
  45. * If this device is on a bus, the uclass_flag will be set before
  46. * calling this function. In the meantime the uclass_postp is
  47. * initlized to a value -1. These are used respectively by
  48. * dm_test_bus_child_pre_probe_uclass() and
  49. * dm_test_bus_child_post_probe_uclass().
  50. */
  51. priv->uclass_total += priv->uclass_flag;
  52. priv->uclass_postp = -1;
  53. return 0;
  54. }
  55. static const struct udevice_id testfdt_ids[] = {
  56. {
  57. .compatible = "denx,u-boot-fdt-test",
  58. .data = DM_TEST_TYPE_FIRST },
  59. {
  60. .compatible = "google,another-fdt-test",
  61. .data = DM_TEST_TYPE_SECOND },
  62. { }
  63. };
  64. U_BOOT_DRIVER(testfdt_drv) = {
  65. .name = "testfdt_drv",
  66. .of_match = testfdt_ids,
  67. .id = UCLASS_TEST_FDT,
  68. .ofdata_to_platdata = testfdt_ofdata_to_platdata,
  69. .probe = testfdt_drv_probe,
  70. .ops = &test_ops,
  71. .priv_auto_alloc_size = sizeof(struct dm_test_priv),
  72. .platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
  73. };
  74. static const struct udevice_id testfdt1_ids[] = {
  75. {
  76. .compatible = "denx,u-boot-fdt-test1",
  77. .data = DM_TEST_TYPE_FIRST },
  78. { }
  79. };
  80. U_BOOT_DRIVER(testfdt1_drv) = {
  81. .name = "testfdt1_drv",
  82. .of_match = testfdt1_ids,
  83. .id = UCLASS_TEST_FDT,
  84. .ofdata_to_platdata = testfdt_ofdata_to_platdata,
  85. .probe = testfdt_drv_probe,
  86. .ops = &test_ops,
  87. .priv_auto_alloc_size = sizeof(struct dm_test_priv),
  88. .platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
  89. .flags = DM_FLAG_PRE_RELOC,
  90. };
  91. /* From here is the testfdt uclass code */
  92. int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
  93. {
  94. const struct test_ops *ops = device_get_ops(dev);
  95. if (!ops->ping)
  96. return -ENOSYS;
  97. return ops->ping(dev, pingval, pingret);
  98. }
  99. UCLASS_DRIVER(testfdt) = {
  100. .name = "testfdt",
  101. .id = UCLASS_TEST_FDT,
  102. .flags = DM_UC_FLAG_SEQ_ALIAS,
  103. };
  104. struct dm_testprobe_pdata {
  105. int probe_err;
  106. };
  107. static int testprobe_drv_probe(struct udevice *dev)
  108. {
  109. struct dm_testprobe_pdata *pdata = dev_get_platdata(dev);
  110. return pdata->probe_err;
  111. }
  112. static const struct udevice_id testprobe_ids[] = {
  113. { .compatible = "denx,u-boot-probe-test" },
  114. { }
  115. };
  116. U_BOOT_DRIVER(testprobe_drv) = {
  117. .name = "testprobe_drv",
  118. .of_match = testprobe_ids,
  119. .id = UCLASS_TEST_PROBE,
  120. .probe = testprobe_drv_probe,
  121. .platdata_auto_alloc_size = sizeof(struct dm_testprobe_pdata),
  122. };
  123. UCLASS_DRIVER(testprobe) = {
  124. .name = "testprobe",
  125. .id = UCLASS_TEST_PROBE,
  126. .flags = DM_UC_FLAG_SEQ_ALIAS,
  127. };
  128. int dm_check_devices(struct unit_test_state *uts, int num_devices)
  129. {
  130. struct udevice *dev;
  131. int ret;
  132. int i;
  133. /*
  134. * Now check that the ping adds are what we expect. This is using the
  135. * ping-add property in each node.
  136. */
  137. for (i = 0; i < num_devices; i++) {
  138. uint32_t base;
  139. ret = uclass_get_device(UCLASS_TEST_FDT, i, &dev);
  140. ut_assert(!ret);
  141. /*
  142. * Get the 'ping-expect' property, which tells us what the
  143. * ping add should be. We don't use the platdata because we
  144. * want to test the code that sets that up
  145. * (testfdt_drv_probe()).
  146. */
  147. base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
  148. "ping-expect");
  149. debug("dev=%d, base=%d: %s\n", i, base,
  150. fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL));
  151. ut_assert(!dm_check_operations(uts, dev, base,
  152. dev_get_priv(dev)));
  153. }
  154. return 0;
  155. }
  156. /* Test that FDT-based binding works correctly */
  157. static int dm_test_fdt(struct unit_test_state *uts)
  158. {
  159. const int num_devices = 8;
  160. struct udevice *dev;
  161. struct uclass *uc;
  162. int ret;
  163. int i;
  164. ret = dm_scan_fdt(gd->fdt_blob, false);
  165. ut_assert(!ret);
  166. ret = uclass_get(UCLASS_TEST_FDT, &uc);
  167. ut_assert(!ret);
  168. /* These are num_devices compatible root-level device tree nodes */
  169. ut_asserteq(num_devices, list_count_items(&uc->dev_head));
  170. /* Each should have platform data but no private data */
  171. for (i = 0; i < num_devices; i++) {
  172. ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev);
  173. ut_assert(!ret);
  174. ut_assert(!dev_get_priv(dev));
  175. ut_assert(dev->platdata);
  176. }
  177. ut_assertok(dm_check_devices(uts, num_devices));
  178. return 0;
  179. }
  180. DM_TEST(dm_test_fdt, 0);
  181. static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
  182. {
  183. struct uclass *uc;
  184. int ret;
  185. ret = dm_scan_fdt(gd->fdt_blob, true);
  186. ut_assert(!ret);
  187. ret = uclass_get(UCLASS_TEST_FDT, &uc);
  188. ut_assert(!ret);
  189. /*
  190. * These are 2 pre-reloc devices:
  191. * one with "u-boot,dm-pre-reloc" property (a-test node), and the other
  192. * one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node).
  193. */
  194. ut_asserteq(2, list_count_items(&uc->dev_head));
  195. return 0;
  196. }
  197. DM_TEST(dm_test_fdt_pre_reloc, 0);
  198. /* Test that sequence numbers are allocated properly */
  199. static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
  200. {
  201. struct udevice *dev;
  202. /* A few basic santiy tests */
  203. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev));
  204. ut_asserteq_str("b-test", dev->name);
  205. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev));
  206. ut_asserteq_str("a-test", dev->name);
  207. ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5,
  208. true, &dev));
  209. ut_asserteq_ptr(NULL, dev);
  210. /* Test aliases */
  211. ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev));
  212. ut_asserteq_str("e-test", dev->name);
  213. ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
  214. true, &dev));
  215. /*
  216. * Note that c-test nodes are not probed since it is not a top-level
  217. * node
  218. */
  219. ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
  220. ut_asserteq_str("b-test", dev->name);
  221. /*
  222. * d-test wants sequence number 3 also, but it can't have it because
  223. * b-test gets it first.
  224. */
  225. ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev));
  226. ut_asserteq_str("d-test", dev->name);
  227. /* d-test actually gets 0 */
  228. ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 0, &dev));
  229. ut_asserteq_str("d-test", dev->name);
  230. /* initially no one wants seq 1 */
  231. ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 1,
  232. &dev));
  233. ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
  234. ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 4, &dev));
  235. /* But now that it is probed, we can find it */
  236. ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 1, &dev));
  237. ut_asserteq_str("f-test", dev->name);
  238. return 0;
  239. }
  240. DM_TEST(dm_test_fdt_uclass_seq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  241. /* Test that we can find a device by device tree offset */
  242. static int dm_test_fdt_offset(struct unit_test_state *uts)
  243. {
  244. const void *blob = gd->fdt_blob;
  245. struct udevice *dev;
  246. int node;
  247. node = fdt_path_offset(blob, "/e-test");
  248. ut_assert(node > 0);
  249. ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node,
  250. &dev));
  251. ut_asserteq_str("e-test", dev->name);
  252. /* This node should not be bound */
  253. node = fdt_path_offset(blob, "/junk");
  254. ut_assert(node > 0);
  255. ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
  256. node, &dev));
  257. /* This is not a top level node so should not be probed */
  258. node = fdt_path_offset(blob, "/some-bus/c-test@5");
  259. ut_assert(node > 0);
  260. ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
  261. node, &dev));
  262. return 0;
  263. }
  264. DM_TEST(dm_test_fdt_offset,
  265. DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
  266. /**
  267. * Test various error conditions with uclass_first_device() and
  268. * uclass_next_device()
  269. */
  270. static int dm_test_first_next_device(struct unit_test_state *uts)
  271. {
  272. struct dm_testprobe_pdata *pdata;
  273. struct udevice *dev, *parent = NULL;
  274. int count;
  275. int ret;
  276. /* There should be 4 devices */
  277. for (ret = uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0;
  278. dev;
  279. ret = uclass_next_device(&dev)) {
  280. count++;
  281. parent = dev_get_parent(dev);
  282. }
  283. ut_assertok(ret);
  284. ut_asserteq(4, count);
  285. /* Remove them and try again, with an error on the second one */
  286. ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 1, &dev));
  287. pdata = dev_get_platdata(dev);
  288. pdata->probe_err = -ENOMEM;
  289. device_remove(parent, DM_REMOVE_NORMAL);
  290. ut_assertok(uclass_first_device(UCLASS_TEST_PROBE, &dev));
  291. ut_asserteq(-ENOMEM, uclass_next_device(&dev));
  292. ut_asserteq_ptr(dev, NULL);
  293. /* Now an error on the first one */
  294. ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev));
  295. pdata = dev_get_platdata(dev);
  296. pdata->probe_err = -ENOENT;
  297. device_remove(parent, DM_REMOVE_NORMAL);
  298. ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev));
  299. return 0;
  300. }
  301. DM_TEST(dm_test_first_next_device, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  302. /**
  303. * check_devices() - Check return values and pointers
  304. *
  305. * This runs through a full sequence of uclass_first_device_check()...
  306. * uclass_next_device_check() checking that the return values and devices
  307. * are correct.
  308. *
  309. * @uts: Test state
  310. * @devlist: List of expected devices
  311. * @mask: Indicates which devices should return an error. Device n should
  312. * return error (-NOENT - n) if bit n is set, or no error (i.e. 0) if
  313. * bit n is clear.
  314. */
  315. static int check_devices(struct unit_test_state *uts,
  316. struct udevice *devlist[], int mask)
  317. {
  318. int expected_ret;
  319. struct udevice *dev;
  320. int i;
  321. expected_ret = (mask & 1) ? -ENOENT : 0;
  322. mask >>= 1;
  323. ut_asserteq(expected_ret,
  324. uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
  325. for (i = 0; i < 4; i++) {
  326. ut_asserteq_ptr(devlist[i], dev);
  327. expected_ret = (mask & 1) ? -ENOENT - (i + 1) : 0;
  328. mask >>= 1;
  329. ut_asserteq(expected_ret, uclass_next_device_check(&dev));
  330. }
  331. ut_asserteq_ptr(NULL, dev);
  332. return 0;
  333. }
  334. /* Test uclass_first_device_check() and uclass_next_device_check() */
  335. static int dm_test_first_next_ok_device(struct unit_test_state *uts)
  336. {
  337. struct dm_testprobe_pdata *pdata;
  338. struct udevice *dev, *parent = NULL, *devlist[4];
  339. int count;
  340. int ret;
  341. /* There should be 4 devices */
  342. count = 0;
  343. for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev);
  344. dev;
  345. ret = uclass_next_device_check(&dev)) {
  346. ut_assertok(ret);
  347. devlist[count++] = dev;
  348. parent = dev_get_parent(dev);
  349. }
  350. ut_asserteq(4, count);
  351. ut_assertok(uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
  352. ut_assertok(check_devices(uts, devlist, 0));
  353. /* Remove them and try again, with an error on the second one */
  354. pdata = dev_get_platdata(devlist[1]);
  355. pdata->probe_err = -ENOENT - 1;
  356. device_remove(parent, DM_REMOVE_NORMAL);
  357. ut_assertok(check_devices(uts, devlist, 1 << 1));
  358. /* Now an error on the first one */
  359. pdata = dev_get_platdata(devlist[0]);
  360. pdata->probe_err = -ENOENT - 0;
  361. device_remove(parent, DM_REMOVE_NORMAL);
  362. ut_assertok(check_devices(uts, devlist, 3 << 0));
  363. /* Now errors on all */
  364. pdata = dev_get_platdata(devlist[2]);
  365. pdata->probe_err = -ENOENT - 2;
  366. pdata = dev_get_platdata(devlist[3]);
  367. pdata->probe_err = -ENOENT - 3;
  368. device_remove(parent, DM_REMOVE_NORMAL);
  369. ut_assertok(check_devices(uts, devlist, 0xf << 0));
  370. return 0;
  371. }
  372. DM_TEST(dm_test_first_next_ok_device, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  373. static const struct udevice_id fdt_dummy_ids[] = {
  374. { .compatible = "denx,u-boot-fdt-dummy", },
  375. { }
  376. };
  377. UCLASS_DRIVER(fdt_dummy) = {
  378. .name = "fdt-dummy",
  379. .id = UCLASS_TEST_DUMMY,
  380. .flags = DM_UC_FLAG_SEQ_ALIAS,
  381. };
  382. U_BOOT_DRIVER(fdt_dummy_drv) = {
  383. .name = "fdt_dummy_drv",
  384. .of_match = fdt_dummy_ids,
  385. .id = UCLASS_TEST_DUMMY,
  386. };
  387. static int dm_test_fdt_translation(struct unit_test_state *uts)
  388. {
  389. struct udevice *dev;
  390. /* Some simple translations */
  391. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  392. ut_asserteq_str("dev@0,0", dev->name);
  393. ut_asserteq(0x8000, dev_read_addr(dev));
  394. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
  395. ut_asserteq_str("dev@1,100", dev->name);
  396. ut_asserteq(0x9000, dev_read_addr(dev));
  397. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, true, &dev));
  398. ut_asserteq_str("dev@2,200", dev->name);
  399. ut_asserteq(0xA000, dev_read_addr(dev));
  400. /* No translation for busses with #size-cells == 0 */
  401. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev));
  402. ut_asserteq_str("dev@42", dev->name);
  403. ut_asserteq(0x42, dev_read_addr(dev));
  404. return 0;
  405. }
  406. DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  407. /* Test devfdt_remap_addr_index() */
  408. static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
  409. {
  410. struct udevice *dev;
  411. fdt_addr_t addr;
  412. void *paddr;
  413. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  414. addr = devfdt_get_addr(dev);
  415. ut_asserteq(0x8000, addr);
  416. paddr = map_physmem(addr, 0, MAP_NOCACHE);
  417. ut_assertnonnull(paddr);
  418. ut_asserteq_ptr(paddr, devfdt_remap_addr(dev));
  419. return 0;
  420. }
  421. DM_TEST(dm_test_fdt_remap_addr_flat,
  422. DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
  423. /* Test dev_remap_addr_index() */
  424. static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
  425. {
  426. struct udevice *dev;
  427. fdt_addr_t addr;
  428. void *paddr;
  429. ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  430. addr = dev_read_addr(dev);
  431. ut_asserteq(0x8000, addr);
  432. paddr = map_physmem(addr, 0, MAP_NOCACHE);
  433. ut_assertnonnull(paddr);
  434. ut_asserteq_ptr(paddr, dev_remap_addr(dev));
  435. return 0;
  436. }
  437. DM_TEST(dm_test_fdt_remap_addr_live,
  438. DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  439. static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
  440. {
  441. struct udevice *dev;
  442. ofnode node;
  443. if (!of_live_active()) {
  444. printf("Live tree not active; ignore test\n");
  445. return 0;
  446. }
  447. /* Test enabling devices */
  448. node = ofnode_path("/usb@2");
  449. ut_assert(!of_device_is_available(ofnode_to_np(node)));
  450. ofnode_set_enabled(node, true);
  451. ut_assert(of_device_is_available(ofnode_to_np(node)));
  452. device_bind_driver_to_node(dm_root(), "usb_sandbox", "usb@2", node,
  453. &dev);
  454. ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, true, &dev));
  455. /* Test string property setting */
  456. ut_assert(device_is_compatible(dev, "sandbox,usb"));
  457. ofnode_write_string(node, "compatible", "gdsys,super-usb");
  458. ut_assert(device_is_compatible(dev, "gdsys,super-usb"));
  459. ofnode_write_string(node, "compatible", "sandbox,usb");
  460. ut_assert(device_is_compatible(dev, "sandbox,usb"));
  461. /* Test setting generic properties */
  462. /* Non-existent in DTB */
  463. ut_asserteq(FDT_ADDR_T_NONE, dev_read_addr(dev));
  464. /* reg = 0x42, size = 0x100 */
  465. ut_assertok(ofnode_write_prop(node, "reg", 8,
  466. "\x00\x00\x00\x42\x00\x00\x01\x00"));
  467. ut_asserteq(0x42, dev_read_addr(dev));
  468. /* Test disabling devices */
  469. device_remove(dev, DM_REMOVE_NORMAL);
  470. device_unbind(dev);
  471. ut_assert(of_device_is_available(ofnode_to_np(node)));
  472. ofnode_set_enabled(node, false);
  473. ut_assert(!of_device_is_available(ofnode_to_np(node)));
  474. return 0;
  475. }
  476. DM_TEST(dm_test_fdt_livetree_writing, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  477. static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
  478. {
  479. ofnode node;
  480. if (!of_live_active()) {
  481. printf("Live tree not active; ignore test\n");
  482. return 0;
  483. }
  484. node = ofnode_path("/usb@2");
  485. /* Test enabling devices */
  486. ut_assert(!of_device_is_available(ofnode_to_np(node)));
  487. dev_enable_by_path("/usb@2");
  488. ut_assert(of_device_is_available(ofnode_to_np(node)));
  489. /* Test disabling devices */
  490. ut_assert(of_device_is_available(ofnode_to_np(node)));
  491. dev_disable_by_path("/usb@2");
  492. ut_assert(!of_device_is_available(ofnode_to_np(node)));
  493. return 0;
  494. }
  495. DM_TEST(dm_test_fdt_disable_enable_by_path, DM_TESTF_SCAN_PDATA |
  496. DM_TESTF_SCAN_FDT);