1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
9 #include <asm/global_data.h>
11 /* Records the last testbus device that was removed */
12 static struct udevice *testbus_removed;
14 struct udevice *testbus_get_clear_removed(void)
16 struct udevice *removed = testbus_removed;
18 testbus_removed = NULL;
23 static int testbus_drv_probe(struct udevice *dev)
25 if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
28 ret = dm_scan_fdt_dev(dev);
36 static int testbus_child_post_bind(struct udevice *dev)
38 struct dm_test_parent_plat *plat;
40 plat = dev_get_parent_plat(dev);
42 plat->uclass_bind_flag = 2;
47 static int testbus_child_pre_probe(struct udevice *dev)
49 struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
51 parent_data->flag += TEST_FLAG_CHILD_PROBED;
56 static int testbus_child_pre_probe_uclass(struct udevice *dev)
58 struct dm_test_priv *priv = dev_get_priv(dev);
65 static int testbus_child_post_probe_uclass(struct udevice *dev)
67 struct dm_test_priv *priv = dev_get_priv(dev);
74 static int testbus_child_post_remove(struct udevice *dev)
76 struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
78 parent_data->flag += TEST_FLAG_CHILD_REMOVED;
79 testbus_removed = dev;
84 static const struct udevice_id testbus_ids[] = {
85 { .compatible = "denx,u-boot-test-bus", .data = DM_TEST_TYPE_FIRST },
89 U_BOOT_DRIVER(testbus_drv) = {
90 .name = "testbus_drv",
91 .of_match = testbus_ids,
92 .id = UCLASS_TEST_BUS,
93 .probe = testbus_drv_probe,
94 .child_post_bind = testbus_child_post_bind,
95 .priv_auto = sizeof(struct dm_test_priv),
96 .plat_auto = sizeof(struct dm_test_pdata),
97 .per_child_auto = sizeof(struct dm_test_parent_data),
98 .per_child_plat_auto = sizeof(struct dm_test_parent_plat),
99 .child_pre_probe = testbus_child_pre_probe,
100 .child_post_remove = testbus_child_post_remove,
103 UCLASS_DRIVER(testbus) = {
105 .id = UCLASS_TEST_BUS,
106 .flags = DM_UC_FLAG_SEQ_ALIAS,
107 .child_pre_probe = testbus_child_pre_probe_uclass,
108 .child_post_probe = testbus_child_post_probe_uclass,
111 static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
113 const struct dm_test_pdata *pdata = dev_get_plat(dev);
114 struct dm_test_priv *priv = dev_get_priv(dev);
116 *pingret = pingval + pdata->ping_add;
117 priv->ping_total += *pingret;
122 static const struct test_ops test_ops = {
123 .ping = testfdt_drv_ping,
126 static int testfdt_of_to_plat(struct udevice *dev)
128 struct dm_test_pdata *pdata = dev_get_plat(dev);
130 pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
132 pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
138 static int testfdt_drv_probe(struct udevice *dev)
140 struct dm_test_priv *priv = dev_get_priv(dev);
142 priv->ping_total += DM_TEST_START_TOTAL;
145 * If this device is on a bus, the uclass_flag will be set before
146 * calling this function. In the meantime the uclass_postp is
147 * initlized to a value -1. These are used respectively by
148 * dm_test_bus_child_pre_probe_uclass() and
149 * dm_test_bus_child_post_probe_uclass().
151 priv->uclass_total += priv->uclass_flag;
152 priv->uclass_postp = -1;
157 static const struct udevice_id testfdt_ids[] = {
158 { .compatible = "denx,u-boot-fdt-test", .data = DM_TEST_TYPE_FIRST },
159 { .compatible = "google,another-fdt-test", .data = DM_TEST_TYPE_SECOND },
163 U_BOOT_DRIVER(testfdt_drv) = {
164 .name = "testfdt_drv",
165 .of_match = testfdt_ids,
166 .id = UCLASS_TEST_FDT,
167 .of_to_plat = testfdt_of_to_plat,
168 .probe = testfdt_drv_probe,
170 .priv_auto = sizeof(struct dm_test_priv),
171 .plat_auto = sizeof(struct dm_test_pdata),
174 static const struct udevice_id testfdt1_ids[] = {
175 { .compatible = "denx,u-boot-fdt-test1", .data = DM_TEST_TYPE_FIRST },
179 U_BOOT_DRIVER(testfdt1_drv) = {
180 .name = "testfdt1_drv",
181 .of_match = testfdt1_ids,
182 .id = UCLASS_TEST_FDT,
183 .of_to_plat = testfdt_of_to_plat,
184 .probe = testfdt_drv_probe,
186 .priv_auto = sizeof(struct dm_test_priv),
187 .plat_auto = sizeof(struct dm_test_pdata),
188 .flags = DM_FLAG_PRE_RELOC,
191 /* From here is the testfdt uclass code */
192 int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
194 const struct test_ops *ops = device_get_ops(dev);
199 return ops->ping(dev, pingval, pingret);
202 UCLASS_DRIVER(testfdt) = {
204 .id = UCLASS_TEST_FDT,
205 .flags = DM_UC_FLAG_SEQ_ALIAS,
208 static const struct udevice_id testfdtm_ids[] = {
209 { .compatible = "denx,u-boot-fdtm-test" },
213 U_BOOT_DRIVER(testfdtm_drv) = {
214 .name = "testfdtm_drv",
215 .of_match = testfdtm_ids,
216 .id = UCLASS_TEST_FDT_MANUAL,
219 UCLASS_DRIVER(testfdtm) = {
221 .id = UCLASS_TEST_FDT_MANUAL,
222 .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ,