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 dm_test_state *dms = &global_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 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
118 if (!dms->force_fail_alloc)
119 dev->priv = calloc(1, sizeof(struct dm_test_priv));
126 static int test_manual_remove(struct udevice *dev)
128 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
132 static int test_manual_unbind(struct udevice *dev)
134 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
138 U_BOOT_DRIVER(test_manual_drv) = {
139 .name = "test_manual_drv",
141 .ops = &test_manual_ops,
142 .bind = test_manual_bind,
143 .probe = test_manual_probe,
144 .remove = test_manual_remove,
145 .unbind = test_manual_unbind,
148 U_BOOT_DRIVER(test_pre_reloc_drv) = {
149 .name = "test_pre_reloc_drv",
151 .ops = &test_manual_ops,
152 .bind = test_manual_bind,
153 .probe = test_manual_probe,
154 .remove = test_manual_remove,
155 .unbind = test_manual_unbind,
156 .flags = DM_FLAG_PRE_RELOC,