2 * Copyright (c) 2013 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
16 #include <dm/uclass-internal.h>
19 DECLARE_GLOBAL_DATA_PTR
;
21 static int testfdt_drv_ping(struct udevice
*dev
, int pingval
, int *pingret
)
23 const struct dm_test_pdata
*pdata
= dev
->platdata
;
24 struct dm_test_priv
*priv
= dev_get_priv(dev
);
26 *pingret
= pingval
+ pdata
->ping_add
;
27 priv
->ping_total
+= *pingret
;
32 static const struct test_ops test_ops
= {
33 .ping
= testfdt_drv_ping
,
36 static int testfdt_ofdata_to_platdata(struct udevice
*dev
)
38 struct dm_test_pdata
*pdata
= dev_get_platdata(dev
);
40 pdata
->ping_add
= fdtdec_get_int(gd
->fdt_blob
, dev
->of_offset
,
42 pdata
->base
= fdtdec_get_addr(gd
->fdt_blob
, dev
->of_offset
, "reg");
47 static int testfdt_drv_probe(struct udevice
*dev
)
49 struct dm_test_priv
*priv
= dev_get_priv(dev
);
51 priv
->ping_total
+= DM_TEST_START_TOTAL
;
56 static const struct device_id testfdt_ids
[] = {
58 .compatible
= "denx,u-boot-fdt-test",
59 .data
= DM_TEST_TYPE_FIRST
},
61 .compatible
= "google,another-fdt-test",
62 .data
= DM_TEST_TYPE_SECOND
},
66 U_BOOT_DRIVER(testfdt_drv
) = {
67 .name
= "testfdt_drv",
68 .of_match
= testfdt_ids
,
69 .id
= UCLASS_TEST_FDT
,
70 .ofdata_to_platdata
= testfdt_ofdata_to_platdata
,
71 .probe
= testfdt_drv_probe
,
73 .priv_auto_alloc_size
= sizeof(struct dm_test_priv
),
74 .platdata_auto_alloc_size
= sizeof(struct dm_test_pdata
),
77 /* From here is the testfdt uclass code */
78 int testfdt_ping(struct udevice
*dev
, int pingval
, int *pingret
)
80 const struct test_ops
*ops
= device_get_ops(dev
);
85 return ops
->ping(dev
, pingval
, pingret
);
88 UCLASS_DRIVER(testfdt
) = {
90 .id
= UCLASS_TEST_FDT
,
93 /* Test that FDT-based binding works correctly */
94 static int dm_test_fdt(struct dm_test_state
*dms
)
96 const int num_drivers
= 3;
102 ret
= dm_scan_fdt(gd
->fdt_blob
);
105 ret
= uclass_get(UCLASS_TEST_FDT
, &uc
);
108 /* These are num_drivers compatible root-level device tree nodes */
109 ut_asserteq(num_drivers
, list_count_items(&uc
->dev_head
));
111 /* Each should have no platdata / priv */
112 for (i
= 0; i
< num_drivers
; i
++) {
113 ret
= uclass_find_device(UCLASS_TEST_FDT
, i
, &dev
);
115 ut_assert(!dev_get_priv(dev
));
116 ut_assert(!dev
->platdata
);
120 * Now check that the ping adds are what we expect. This is using the
121 * ping-add property in each node.
123 for (i
= 0; i
< num_drivers
; i
++) {
126 ret
= uclass_get_device(UCLASS_TEST_FDT
, i
, &dev
);
130 * Get the 'reg' property, which tells us what the ping add
131 * should be. We don't use the platdata because we want
132 * to test the code that sets that up (testfdt_drv_probe()).
134 base
= fdtdec_get_addr(gd
->fdt_blob
, dev
->of_offset
, "reg");
135 debug("dev=%d, base=%d: %s\n", i
, base
,
136 fdt_get_name(gd
->fdt_blob
, dev
->of_offset
, NULL
));
138 ut_assert(!dm_check_operations(dms
, dev
, base
,
144 DM_TEST(dm_test_fdt
, 0);