]>
Commit | Line | Data |
---|---|---|
2e7d35d2 SG |
1 | /* |
2 | * Copyright (c) 2013 Google, Inc | |
3 | * | |
4 | * (C) Copyright 2012 | |
5 | * Pavel Herrmann <morpheus.ibis@gmail.com> | |
6 | * | |
7 | * SPDX-License-Identifier: GPL-2.0+ | |
8 | */ | |
9 | ||
10 | #include <common.h> | |
11 | #include <dm.h> | |
12 | #include <errno.h> | |
13 | #include <malloc.h> | |
14 | #include <dm/test.h> | |
15 | #include <dm/ut.h> | |
16 | #include <asm/io.h> | |
17 | ||
18 | int dm_testdrv_op_count[DM_TEST_OP_COUNT]; | |
19 | static struct dm_test_state *dms = &global_test_state; | |
20 | ||
54c5d08a | 21 | static int testdrv_ping(struct udevice *dev, int pingval, int *pingret) |
2e7d35d2 SG |
22 | { |
23 | const struct dm_test_pdata *pdata = dev_get_platdata(dev); | |
24 | struct dm_test_priv *priv = dev_get_priv(dev); | |
25 | ||
26 | *pingret = pingval + pdata->ping_add; | |
27 | priv->ping_total += *pingret; | |
28 | ||
29 | return 0; | |
30 | } | |
31 | ||
32 | static const struct test_ops test_ops = { | |
33 | .ping = testdrv_ping, | |
34 | }; | |
35 | ||
54c5d08a | 36 | static int test_bind(struct udevice *dev) |
2e7d35d2 SG |
37 | { |
38 | /* Private data should not be allocated */ | |
39 | ut_assert(!dev_get_priv(dev)); | |
40 | ||
41 | dm_testdrv_op_count[DM_TEST_OP_BIND]++; | |
42 | return 0; | |
43 | } | |
44 | ||
54c5d08a | 45 | static int test_probe(struct udevice *dev) |
2e7d35d2 SG |
46 | { |
47 | struct dm_test_priv *priv = dev_get_priv(dev); | |
48 | ||
49 | /* Private data should be allocated */ | |
50 | ut_assert(priv); | |
51 | ||
52 | dm_testdrv_op_count[DM_TEST_OP_PROBE]++; | |
53 | priv->ping_total += DM_TEST_START_TOTAL; | |
54 | return 0; | |
55 | } | |
56 | ||
54c5d08a | 57 | static int test_remove(struct udevice *dev) |
2e7d35d2 SG |
58 | { |
59 | /* Private data should still be allocated */ | |
60 | ut_assert(dev_get_priv(dev)); | |
61 | ||
62 | dm_testdrv_op_count[DM_TEST_OP_REMOVE]++; | |
63 | return 0; | |
64 | } | |
65 | ||
54c5d08a | 66 | static int test_unbind(struct udevice *dev) |
2e7d35d2 SG |
67 | { |
68 | /* Private data should not be allocated */ | |
69 | ut_assert(!dev->priv); | |
70 | ||
71 | dm_testdrv_op_count[DM_TEST_OP_UNBIND]++; | |
72 | return 0; | |
73 | } | |
74 | ||
75 | U_BOOT_DRIVER(test_drv) = { | |
76 | .name = "test_drv", | |
77 | .id = UCLASS_TEST, | |
78 | .ops = &test_ops, | |
79 | .bind = test_bind, | |
80 | .probe = test_probe, | |
81 | .remove = test_remove, | |
82 | .unbind = test_unbind, | |
83 | .priv_auto_alloc_size = sizeof(struct dm_test_priv), | |
84 | }; | |
85 | ||
86 | U_BOOT_DRIVER(test2_drv) = { | |
87 | .name = "test2_drv", | |
88 | .id = UCLASS_TEST, | |
89 | .ops = &test_ops, | |
90 | .bind = test_bind, | |
91 | .probe = test_probe, | |
92 | .remove = test_remove, | |
93 | .unbind = test_unbind, | |
94 | .priv_auto_alloc_size = sizeof(struct dm_test_priv), | |
95 | }; | |
96 | ||
54c5d08a | 97 | static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret) |
2e7d35d2 SG |
98 | { |
99 | *pingret = pingval + 2; | |
100 | ||
101 | return 0; | |
102 | } | |
103 | ||
104 | static const struct test_ops test_manual_ops = { | |
105 | .ping = test_manual_drv_ping, | |
106 | }; | |
107 | ||
54c5d08a | 108 | static int test_manual_bind(struct udevice *dev) |
2e7d35d2 SG |
109 | { |
110 | dm_testdrv_op_count[DM_TEST_OP_BIND]++; | |
111 | ||
112 | return 0; | |
113 | } | |
114 | ||
54c5d08a | 115 | static int test_manual_probe(struct udevice *dev) |
2e7d35d2 SG |
116 | { |
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)); | |
120 | if (!dev->priv) | |
121 | return -ENOMEM; | |
122 | ||
123 | return 0; | |
124 | } | |
125 | ||
54c5d08a | 126 | static int test_manual_remove(struct udevice *dev) |
2e7d35d2 SG |
127 | { |
128 | dm_testdrv_op_count[DM_TEST_OP_REMOVE]++; | |
129 | return 0; | |
130 | } | |
131 | ||
54c5d08a | 132 | static int test_manual_unbind(struct udevice *dev) |
2e7d35d2 SG |
133 | { |
134 | dm_testdrv_op_count[DM_TEST_OP_UNBIND]++; | |
135 | return 0; | |
136 | } | |
137 | ||
138 | U_BOOT_DRIVER(test_manual_drv) = { | |
139 | .name = "test_manual_drv", | |
140 | .id = UCLASS_TEST, | |
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, | |
146 | }; | |
00606d7e SG |
147 | |
148 | U_BOOT_DRIVER(test_pre_reloc_drv) = { | |
149 | .name = "test_pre_reloc_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 | .flags = DM_FLAG_PRE_RELOC, | |
157 | }; |