1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
17 int dm_testdrv_op_count[DM_TEST_OP_COUNT];
18 static struct unit_test_state *uts = &global_dm_test_state;
20 static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
22 const struct dm_test_pdata *pdata = dev_get_platdata(dev);
23 struct dm_test_priv *priv = dev_get_priv(dev);
25 *pingret = pingval + pdata->ping_add;
26 priv->ping_total += *pingret;
31 static const struct test_ops test_ops = {
35 static int test_bind(struct udevice *dev)
37 /* Private data should not be allocated */
38 ut_assert(!dev_get_priv(dev));
40 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
44 static int test_probe(struct udevice *dev)
46 struct dm_test_priv *priv = dev_get_priv(dev);
48 /* Private data should be allocated */
51 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
52 priv->ping_total += DM_TEST_START_TOTAL;
56 static int test_remove(struct udevice *dev)
58 /* Private data should still be allocated */
59 ut_assert(dev_get_priv(dev));
61 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
65 static int test_unbind(struct udevice *dev)
67 /* Private data should not be allocated */
68 ut_assert(!dev->priv);
70 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
74 U_BOOT_DRIVER(test_drv) = {
80 .remove = test_remove,
81 .unbind = test_unbind,
82 .priv_auto_alloc_size = sizeof(struct dm_test_priv),
85 U_BOOT_DRIVER(test2_drv) = {
91 .remove = test_remove,
92 .unbind = test_unbind,
93 .priv_auto_alloc_size = sizeof(struct dm_test_priv),
96 static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
98 *pingret = pingval + 2;
103 static const struct test_ops test_manual_ops = {
104 .ping = test_manual_drv_ping,
107 static int test_manual_bind(struct udevice *dev)
109 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
114 static int test_manual_probe(struct udevice *dev)
116 struct dm_test_state *dms = uts->priv;
118 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
119 if (!dms->force_fail_alloc)
120 dev->priv = calloc(1, sizeof(struct dm_test_priv));
127 static int test_manual_remove(struct udevice *dev)
129 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
133 static int test_manual_unbind(struct udevice *dev)
135 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
139 U_BOOT_DRIVER(test_manual_drv) = {
140 .name = "test_manual_drv",
142 .ops = &test_manual_ops,
143 .bind = test_manual_bind,
144 .probe = test_manual_probe,
145 .remove = test_manual_remove,
146 .unbind = test_manual_unbind,
149 U_BOOT_DRIVER(test_pre_reloc_drv) = {
150 .name = "test_pre_reloc_drv",
152 .ops = &test_manual_ops,
153 .bind = test_manual_bind,
154 .probe = test_manual_probe,
155 .remove = test_manual_remove,
156 .unbind = test_manual_unbind,
157 .flags = DM_FLAG_PRE_RELOC,
160 U_BOOT_DRIVER(test_act_dma_drv) = {
161 .name = "test_act_dma_drv",
163 .ops = &test_manual_ops,
164 .bind = test_manual_bind,
165 .probe = test_manual_probe,
166 .remove = test_manual_remove,
167 .unbind = test_manual_unbind,
168 .flags = DM_FLAG_ACTIVE_DMA,