1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* U-Boot sandbox DM tests for PHY common props
*
* Ported from Linux KUnit test:
* linux/drivers/phy/phy-common-props-test.c
*
* Copyright 2025-2026 NXP
*/
#include <dm.h>
#include <dm/ofnode.h>
#include <dm/test.h>
#include <linux/bitops.h>
#include <linux/phy/phy-common-props.h>
#include <dt-bindings/phy/phy.h>
#include <test/test.h>
#include <test/ut.h>
/* --- RX polarity tests -------------------------------------------------- */
/* Test: rx-polarity property is missing => default PHY_POL_NORMAL */
static int dm_test_phy_common_props_rx_missing(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-missing");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_NORMAL, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_missing, UTF_SCAN_FDT);
/* Test: rx-polarity has more values than rx-polarity-names => -EINVAL */
static int dm_test_phy_common_props_rx_more_values(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-more-values");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_more_values, UTF_SCAN_FDT);
/* Test: rx-polarity has 1 value and rx-polarity-names does not exist */
static int dm_test_phy_common_props_rx_single_value(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-single");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_single_value, UTF_SCAN_FDT);
/* Test: rx-polarity-names has more values than rx-polarity => -EINVAL */
static int dm_test_phy_common_props_rx_more_names(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-more-names");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_more_names, UTF_SCAN_FDT);
/* Test: valid arrays, find polarity by mode name */
static int dm_test_phy_common_props_rx_find_by_name(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-find-by-name");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_NORMAL, val);
ret = phy_get_manual_rx_polarity(node, "2500base-x", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
/* "usb-ss" has PHY_POL_AUTO; auto is supported here */
ret = phy_get_rx_polarity(node, "usb-ss", BIT(PHY_POL_AUTO),
PHY_POL_AUTO, &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_AUTO, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_find_by_name, UTF_SCAN_FDT);
/* Test: name not found, no "default" entry => -EINVAL */
static int dm_test_phy_common_props_rx_no_default(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-no-default");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_no_default, UTF_SCAN_FDT);
/* Test: name not found, "default" entry exists => use default polarity */
static int dm_test_phy_common_props_rx_with_default(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-with-default");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_with_default, UTF_SCAN_FDT);
/* Test: polarity value found but not in supported set => -EOPNOTSUPP */
static int dm_test_phy_common_props_rx_unsupported(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-unsupported");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
ut_asserteq(-EOPNOTSUPP, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_rx_unsupported, UTF_SCAN_FDT);
/* --- TX polarity tests -------------------------------------------------- */
/* Test: tx-polarity property is missing => default PHY_POL_NORMAL */
static int dm_test_phy_common_props_tx_missing(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-missing");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_NORMAL, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_missing, UTF_SCAN_FDT);
/* Test: tx-polarity has more values than tx-polarity-names => -EINVAL */
static int dm_test_phy_common_props_tx_more_values(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-more-values");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_more_values, UTF_SCAN_FDT);
/* Test: tx-polarity has 1 value and tx-polarity-names does not exist */
static int dm_test_phy_common_props_tx_single_value(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-single");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_single_value, UTF_SCAN_FDT);
/* Test: tx-polarity-names has more values than tx-polarity => -EINVAL */
static int dm_test_phy_common_props_tx_more_names(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-more-names");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_more_names, UTF_SCAN_FDT);
/* Test: valid arrays, find polarity by mode name */
static int dm_test_phy_common_props_tx_find_by_name(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-find-by-name");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_NORMAL, val);
ret = phy_get_manual_tx_polarity(node, "2500base-x", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
ret = phy_get_manual_tx_polarity(node, "1000base-x", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_NORMAL, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_find_by_name, UTF_SCAN_FDT);
/* Test: name not found, no "default" entry => -EINVAL */
static int dm_test_phy_common_props_tx_no_default(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-no-default");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(-EINVAL, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_no_default, UTF_SCAN_FDT);
/* Test: name not found, "default" entry exists => use default polarity */
static int dm_test_phy_common_props_tx_with_default(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-with-default");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(0, ret);
ut_asserteq(PHY_POL_INVERT, val);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_with_default, UTF_SCAN_FDT);
/* Test: polarity value found but not in supported set => -EOPNOTSUPP */
static int dm_test_phy_common_props_tx_unsupported(struct unit_test_state *uts)
{
ofnode node = ofnode_path("/phy-common-props-unsupported");
unsigned int val;
int ret;
ut_assert(ofnode_valid(node));
ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
ut_asserteq(-EOPNOTSUPP, ret);
return 0;
}
DM_TEST(dm_test_phy_common_props_tx_unsupported, UTF_SCAN_FDT);
|