]> git.ipfire.org Git - thirdparty/u-boot.git/blame - test/dm/test-driver.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / test / dm / test-driver.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
2e7d35d2
SG
2/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
2e7d35d2
SG
7 */
8
d678a59d 9#include <common.h>
2e7d35d2
SG
10#include <dm.h>
11#include <errno.h>
f7ae49fc 12#include <log.h>
2e7d35d2 13#include <malloc.h>
0e1fad43 14#include <asm/io.h>
0fd3d911 15#include <dm/device-internal.h>
2e7d35d2 16#include <dm/test.h>
0e1fad43 17#include <test/test.h>
e721b882 18#include <test/ut.h>
2e7d35d2
SG
19
20int dm_testdrv_op_count[DM_TEST_OP_COUNT];
2e7d35d2 21
54c5d08a 22static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
2e7d35d2 23{
c69cda25 24 const struct dm_test_pdata *pdata = dev_get_plat(dev);
2e7d35d2
SG
25 struct dm_test_priv *priv = dev_get_priv(dev);
26
27 *pingret = pingval + pdata->ping_add;
28 priv->ping_total += *pingret;
29
30 return 0;
31}
32
33static const struct test_ops test_ops = {
34 .ping = testdrv_ping,
35};
36
54c5d08a 37static int test_bind(struct udevice *dev)
2e7d35d2 38{
fe806861
SG
39 struct unit_test_state *uts = test_get_state();
40
2e7d35d2
SG
41 /* Private data should not be allocated */
42 ut_assert(!dev_get_priv(dev));
43
44 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
45 return 0;
46}
47
54c5d08a 48static int test_probe(struct udevice *dev)
2e7d35d2 49{
fe806861 50 struct unit_test_state *uts = test_get_state();
2e7d35d2
SG
51 struct dm_test_priv *priv = dev_get_priv(dev);
52
53 /* Private data should be allocated */
54 ut_assert(priv);
55
56 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
57 priv->ping_total += DM_TEST_START_TOTAL;
58 return 0;
59}
60
54c5d08a 61static int test_remove(struct udevice *dev)
2e7d35d2 62{
fe806861
SG
63 struct unit_test_state *uts = test_get_state();
64
2e7d35d2
SG
65 /* Private data should still be allocated */
66 ut_assert(dev_get_priv(dev));
67
68 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
69 return 0;
70}
71
54c5d08a 72static int test_unbind(struct udevice *dev)
2e7d35d2 73{
fe806861
SG
74 struct unit_test_state *uts = test_get_state();
75
2e7d35d2 76 /* Private data should not be allocated */
0fd3d911 77 ut_assert(!dev_get_priv(dev));
2e7d35d2
SG
78
79 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
80 return 0;
81}
82
83U_BOOT_DRIVER(test_drv) = {
84 .name = "test_drv",
85 .id = UCLASS_TEST,
86 .ops = &test_ops,
87 .bind = test_bind,
88 .probe = test_probe,
89 .remove = test_remove,
90 .unbind = test_unbind,
41575d8e 91 .priv_auto = sizeof(struct dm_test_priv),
2e7d35d2
SG
92};
93
94U_BOOT_DRIVER(test2_drv) = {
95 .name = "test2_drv",
96 .id = UCLASS_TEST,
97 .ops = &test_ops,
98 .bind = test_bind,
99 .probe = test_probe,
100 .remove = test_remove,
101 .unbind = test_unbind,
41575d8e 102 .priv_auto = sizeof(struct dm_test_priv),
2e7d35d2
SG
103};
104
54c5d08a 105static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
2e7d35d2
SG
106{
107 *pingret = pingval + 2;
108
109 return 0;
110}
111
112static const struct test_ops test_manual_ops = {
113 .ping = test_manual_drv_ping,
114};
115
54c5d08a 116static int test_manual_bind(struct udevice *dev)
2e7d35d2
SG
117{
118 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
119
120 return 0;
121}
122
54c5d08a 123static int test_manual_probe(struct udevice *dev)
2e7d35d2 124{
fe806861
SG
125 struct unit_test_state *uts = test_get_state();
126
2e7d35d2 127 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
4a467c6d 128 if (!uts->force_fail_alloc)
0fd3d911
SG
129 dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv)));
130 if (!dev_get_priv(dev))
2e7d35d2
SG
131 return -ENOMEM;
132
133 return 0;
134}
135
54c5d08a 136static int test_manual_remove(struct udevice *dev)
2e7d35d2
SG
137{
138 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
139 return 0;
140}
141
54c5d08a 142static int test_manual_unbind(struct udevice *dev)
2e7d35d2
SG
143{
144 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
145 return 0;
146}
147
148U_BOOT_DRIVER(test_manual_drv) = {
149 .name = "test_manual_drv",
150 .id = UCLASS_TEST,
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};
00606d7e
SG
157
158U_BOOT_DRIVER(test_pre_reloc_drv) = {
159 .name = "test_pre_reloc_drv",
160 .id = UCLASS_TEST,
161 .ops = &test_manual_ops,
162 .bind = test_manual_bind,
163 .probe = test_manual_probe,
164 .remove = test_manual_remove,
165 .unbind = test_manual_unbind,
166 .flags = DM_FLAG_PRE_RELOC,
167};
24f927c5
SR
168
169U_BOOT_DRIVER(test_act_dma_drv) = {
170 .name = "test_act_dma_drv",
171 .id = UCLASS_TEST,
172 .ops = &test_manual_ops,
173 .bind = test_manual_bind,
174 .probe = test_manual_probe,
175 .remove = test_manual_remove,
176 .unbind = test_manual_unbind,
177 .flags = DM_FLAG_ACTIVE_DMA,
178};
cc6f4c8f
MV
179
180U_BOOT_DRIVER(test_vital_clk_drv) = {
181 .name = "test_vital_clk_drv",
182 .id = UCLASS_TEST,
183 .ops = &test_manual_ops,
184 .bind = test_manual_bind,
185 .probe = test_manual_probe,
186 .remove = test_manual_remove,
187 .unbind = test_manual_unbind,
188 .flags = DM_FLAG_VITAL,
189};
190
191U_BOOT_DRIVER(test_act_dma_vital_clk_drv) = {
192 .name = "test_act_dma_vital_clk_drv",
193 .id = UCLASS_TEST,
194 .ops = &test_manual_ops,
195 .bind = test_manual_bind,
196 .probe = test_manual_probe,
197 .remove = test_manual_remove,
198 .unbind = test_manual_unbind,
199 .flags = DM_FLAG_VITAL | DM_FLAG_ACTIVE_DMA,
200};