1 /* 2 * Copyright (c) 2014 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <dm.h> 9 #include <dm/root.h> 10 #include <dm/test.h> 11 #include <dm/ut.h> 12 #include <dm/util.h> 13 14 DECLARE_GLOBAL_DATA_PTR; 15 16 static int testbus_drv_probe(struct udevice *dev) 17 { 18 return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false); 19 } 20 21 static const struct udevice_id testbus_ids[] = { 22 { 23 .compatible = "denx,u-boot-test-bus", 24 .data = DM_TEST_TYPE_FIRST }, 25 { } 26 }; 27 28 U_BOOT_DRIVER(testbus_drv) = { 29 .name = "testbus_drv", 30 .of_match = testbus_ids, 31 .id = UCLASS_TEST_BUS, 32 .probe = testbus_drv_probe, 33 .priv_auto_alloc_size = sizeof(struct dm_test_priv), 34 .platdata_auto_alloc_size = sizeof(struct dm_test_pdata), 35 }; 36 37 UCLASS_DRIVER(testbus) = { 38 .name = "testbus", 39 .id = UCLASS_TEST_BUS, 40 }; 41 42 /* Test that we can probe for children */ 43 static int dm_test_bus_children(struct dm_test_state *dms) 44 { 45 int num_devices = 4; 46 struct udevice *bus; 47 struct uclass *uc; 48 49 ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); 50 ut_asserteq(num_devices, list_count_items(&uc->dev_head)); 51 52 /* Probe the bus, which should yield 3 more devices */ 53 ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); 54 num_devices += 3; 55 56 ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); 57 ut_asserteq(num_devices, list_count_items(&uc->dev_head)); 58 59 ut_assert(!dm_check_devices(dms, num_devices)); 60 61 return 0; 62 } 63 DM_TEST(dm_test_bus_children, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); 64