2 * Copyright (c) 2013 Google, Inc
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0+
18 int dm_testdrv_op_count[DM_TEST_OP_COUNT];
19 static struct unit_test_state *uts = &global_dm_test_state;
21 static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
23 const struct dm_test_pdata *pdata = dev_get_platdata(dev);
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 = {
36 static int test_bind(struct udevice *dev)
38 /* Private data should not be allocated */
39 ut_assert(!dev_get_priv(dev));
41 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
45 static int test_probe(struct udevice *dev)
47 struct dm_test_priv *priv = dev_get_priv(dev);
49 /* Private data should be allocated */
52 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
53 priv->ping_total += DM_TEST_START_TOTAL;
57 static int test_remove(struct udevice *dev)
59 /* Private data should still be allocated */
60 ut_assert(dev_get_priv(dev));
62 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
66 static int test_unbind(struct udevice *dev)
68 /* Private data should not be allocated */
69 ut_assert(!dev->priv);
71 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
75 U_BOOT_DRIVER(test_drv) = {
81 .remove = test_remove,
82 .unbind = test_unbind,
83 .priv_auto_alloc_size = sizeof(struct dm_test_priv),
86 U_BOOT_DRIVER(test2_drv) = {
92 .remove = test_remove,
93 .unbind = test_unbind,
94 .priv_auto_alloc_size = sizeof(struct dm_test_priv),
97 static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
99 *pingret = pingval + 2;
104 static const struct test_ops test_manual_ops = {
105 .ping = test_manual_drv_ping,
108 static int test_manual_bind(struct udevice *dev)
110 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
115 static int test_manual_probe(struct udevice *dev)
117 struct dm_test_state *dms = uts->priv;
119 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
120 if (!dms->force_fail_alloc)
121 dev->priv = calloc(1, sizeof(struct dm_test_priv));
128 static int test_manual_remove(struct udevice *dev)
130 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
134 static int test_manual_unbind(struct udevice *dev)
136 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
140 U_BOOT_DRIVER(test_manual_drv) = {
141 .name = "test_manual_drv",
143 .ops = &test_manual_ops,
144 .bind = test_manual_bind,
145 .probe = test_manual_probe,
146 .remove = test_manual_remove,
147 .unbind = test_manual_unbind,
150 U_BOOT_DRIVER(test_pre_reloc_drv) = {
151 .name = "test_pre_reloc_drv",
153 .ops = &test_manual_ops,
154 .bind = test_manual_bind,
155 .probe = test_manual_probe,
156 .remove = test_manual_remove,
157 .unbind = test_manual_unbind,
158 .flags = DM_FLAG_PRE_RELOC,