blob: fe8602eb7c87148d5bfeb6479c2f90d38a5f63aa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkdd7d41f2002-09-18 20:04:01 +00002/*
3 * (C) Copyright 2001
4 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
wdenkdd7d41f2002-09-18 20:04:01 +00005 */
6
7/*
8 * MII Utilities
9 */
10
11#include <common.h>
12#include <command.h>
Simon Glass992b6032020-07-19 10:15:39 -060013#include <dm.h>
wdenke44b9112004-04-18 23:32:11 +000014#include <miiphy.h>
15
wdenk61066ec2004-04-18 22:57:51 +000016typedef struct _MII_field_desc_t {
17 ushort hi;
18 ushort lo;
19 ushort mask;
Trent Piepho19345822019-05-09 19:23:39 +000020 const char *name;
wdenk61066ec2004-04-18 22:57:51 +000021} MII_field_desc_t;
22
Mike Frysinger4b497472010-10-20 01:06:48 -040023static const MII_field_desc_t reg_0_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000024 { 15, 15, 0x01, "reset" },
25 { 14, 14, 0x01, "loopback" },
26 { 13, 6, 0x81, "speed selection" }, /* special */
27 { 12, 12, 0x01, "A/N enable" },
28 { 11, 11, 0x01, "power-down" },
29 { 10, 10, 0x01, "isolate" },
30 { 9, 9, 0x01, "restart A/N" },
31 { 8, 8, 0x01, "duplex" }, /* special */
32 { 7, 7, 0x01, "collision test enable" },
33 { 5, 0, 0x3f, "(reserved)" }
34};
35
Mike Frysinger4b497472010-10-20 01:06:48 -040036static const MII_field_desc_t reg_1_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000037 { 15, 15, 0x01, "100BASE-T4 able" },
38 { 14, 14, 0x01, "100BASE-X full duplex able" },
39 { 13, 13, 0x01, "100BASE-X half duplex able" },
40 { 12, 12, 0x01, "10 Mbps full duplex able" },
41 { 11, 11, 0x01, "10 Mbps half duplex able" },
42 { 10, 10, 0x01, "100BASE-T2 full duplex able" },
43 { 9, 9, 0x01, "100BASE-T2 half duplex able" },
44 { 8, 8, 0x01, "extended status" },
45 { 7, 7, 0x01, "(reserved)" },
46 { 6, 6, 0x01, "MF preamble suppression" },
47 { 5, 5, 0x01, "A/N complete" },
48 { 4, 4, 0x01, "remote fault" },
49 { 3, 3, 0x01, "A/N able" },
50 { 2, 2, 0x01, "link status" },
51 { 1, 1, 0x01, "jabber detect" },
52 { 0, 0, 0x01, "extended capabilities" },
53};
54
Mike Frysinger4b497472010-10-20 01:06:48 -040055static const MII_field_desc_t reg_2_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000056 { 15, 0, 0xffff, "OUI portion" },
57};
58
Mike Frysinger4b497472010-10-20 01:06:48 -040059static const MII_field_desc_t reg_3_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000060 { 15, 10, 0x3f, "OUI portion" },
61 { 9, 4, 0x3f, "manufacturer part number" },
62 { 3, 0, 0x0f, "manufacturer rev. number" },
63};
64
Mike Frysinger4b497472010-10-20 01:06:48 -040065static const MII_field_desc_t reg_4_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000066 { 15, 15, 0x01, "next page able" },
Stephan Baurothcf617af2013-08-08 13:44:41 +020067 { 14, 14, 0x01, "(reserved)" },
wdenk61066ec2004-04-18 22:57:51 +000068 { 13, 13, 0x01, "remote fault" },
Stephan Baurothcf617af2013-08-08 13:44:41 +020069 { 12, 12, 0x01, "(reserved)" },
wdenk61066ec2004-04-18 22:57:51 +000070 { 11, 11, 0x01, "asymmetric pause" },
71 { 10, 10, 0x01, "pause enable" },
72 { 9, 9, 0x01, "100BASE-T4 able" },
73 { 8, 8, 0x01, "100BASE-TX full duplex able" },
74 { 7, 7, 0x01, "100BASE-TX able" },
75 { 6, 6, 0x01, "10BASE-T full duplex able" },
76 { 5, 5, 0x01, "10BASE-T able" },
Trent Piepho19345822019-05-09 19:23:39 +000077 { 4, 0, 0x1f, "selector" },
wdenk61066ec2004-04-18 22:57:51 +000078};
79
Mike Frysinger4b497472010-10-20 01:06:48 -040080static const MII_field_desc_t reg_5_desc_tbl[] = {
wdenk61066ec2004-04-18 22:57:51 +000081 { 15, 15, 0x01, "next page able" },
82 { 14, 14, 0x01, "acknowledge" },
83 { 13, 13, 0x01, "remote fault" },
84 { 12, 12, 0x01, "(reserved)" },
85 { 11, 11, 0x01, "asymmetric pause able" },
86 { 10, 10, 0x01, "pause able" },
87 { 9, 9, 0x01, "100BASE-T4 able" },
88 { 8, 8, 0x01, "100BASE-X full duplex able" },
89 { 7, 7, 0x01, "100BASE-TX able" },
90 { 6, 6, 0x01, "10BASE-T full duplex able" },
91 { 5, 5, 0x01, "10BASE-T able" },
Trent Piepho19345822019-05-09 19:23:39 +000092 { 4, 0, 0x1f, "partner selector" },
wdenk61066ec2004-04-18 22:57:51 +000093};
Trent Piepho19345822019-05-09 19:23:39 +000094
Trent Piepho1661ee02019-05-09 19:23:47 +000095static const MII_field_desc_t reg_9_desc_tbl[] = {
96 { 15, 13, 0x07, "test mode" },
97 { 12, 12, 0x01, "manual master/slave enable" },
98 { 11, 11, 0x01, "manual master/slave value" },
99 { 10, 10, 0x01, "multi/single port" },
100 { 9, 9, 0x01, "1000BASE-T full duplex able" },
101 { 8, 8, 0x01, "1000BASE-T half duplex able" },
102 { 7, 7, 0x01, "automatic TDR on link down" },
103 { 6, 6, 0x7f, "(reserved)" },
104};
105
106static const MII_field_desc_t reg_10_desc_tbl[] = {
107 { 15, 15, 0x01, "master/slave config fault" },
108 { 14, 14, 0x01, "master/slave config result" },
109 { 13, 13, 0x01, "local receiver status OK" },
110 { 12, 12, 0x01, "remote receiver status OK" },
111 { 11, 11, 0x01, "1000BASE-T full duplex able" },
112 { 10, 10, 0x01, "1000BASE-T half duplex able" },
113 { 9, 8, 0x03, "(reserved)" },
114 { 7, 0, 0xff, "1000BASE-T idle error counter"},
115};
116
Trent Piepho19345822019-05-09 19:23:39 +0000117typedef struct _MII_reg_desc_t {
118 ushort regno;
Mike Frysinger4b497472010-10-20 01:06:48 -0400119 const MII_field_desc_t *pdesc;
wdenk61066ec2004-04-18 22:57:51 +0000120 ushort len;
Trent Piepho19345822019-05-09 19:23:39 +0000121 const char *name;
122} MII_reg_desc_t;
wdenk61066ec2004-04-18 22:57:51 +0000123
Trent Piepho19345822019-05-09 19:23:39 +0000124static const MII_reg_desc_t mii_reg_desc_tbl[] = {
125 { MII_BMCR, reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl),
126 "PHY control register" },
127 { MII_BMSR, reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl),
128 "PHY status register" },
129 { MII_PHYSID1, reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl),
130 "PHY ID 1 register" },
131 { MII_PHYSID2, reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl),
132 "PHY ID 2 register" },
133 { MII_ADVERTISE, reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl),
134 "Autonegotiation advertisement register" },
135 { MII_LPA, reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl),
136 "Autonegotiation partner abilities register" },
Trent Piepho1661ee02019-05-09 19:23:47 +0000137 { MII_CTRL1000, reg_9_desc_tbl, ARRAY_SIZE(reg_9_desc_tbl),
138 "1000BASE-T control register" },
139 { MII_STAT1000, reg_10_desc_tbl, ARRAY_SIZE(reg_10_desc_tbl),
140 "1000BASE-T status register" },
wdenk61066ec2004-04-18 22:57:51 +0000141};
142
143static void dump_reg(
144 ushort regval,
Trent Piepho19345822019-05-09 19:23:39 +0000145 const MII_reg_desc_t *prd);
wdenk61066ec2004-04-18 22:57:51 +0000146
Trent Piepho19345822019-05-09 19:23:39 +0000147static bool special_field(ushort regno, const MII_field_desc_t *pdesc,
148 ushort regval);
wdenk61066ec2004-04-18 22:57:51 +0000149
Trent Piepho19345822019-05-09 19:23:39 +0000150static void MII_dump(const ushort *regvals, uchar reglo, uchar reghi)
wdenk61066ec2004-04-18 22:57:51 +0000151{
152 ulong i;
153
Trent Piepho19345822019-05-09 19:23:39 +0000154 for (i = 0; i < ARRAY_SIZE(mii_reg_desc_tbl); i++) {
155 const uchar reg = mii_reg_desc_tbl[i].regno;
156
157 if (reg >= reglo && reg <= reghi)
158 dump_reg(regvals[reg - reglo], &mii_reg_desc_tbl[i]);
wdenk61066ec2004-04-18 22:57:51 +0000159 }
160}
161
Trent Piepho19345822019-05-09 19:23:39 +0000162/* Print out field position, value, name */
163static void dump_field(const MII_field_desc_t *pdesc, ushort regval)
164{
165 if (pdesc->hi == pdesc->lo)
166 printf("%2u ", pdesc->lo);
167 else
168 printf("%2u-%2u", pdesc->hi, pdesc->lo);
169
170 printf(" = %5u %s", (regval >> pdesc->lo) & pdesc->mask,
171 pdesc->name);
172}
173
wdenk61066ec2004-04-18 22:57:51 +0000174static void dump_reg(
175 ushort regval,
Trent Piepho19345822019-05-09 19:23:39 +0000176 const MII_reg_desc_t *prd)
wdenk61066ec2004-04-18 22:57:51 +0000177{
178 ulong i;
179 ushort mask_in_place;
Mike Frysinger4b497472010-10-20 01:06:48 -0400180 const MII_field_desc_t *pdesc;
wdenk61066ec2004-04-18 22:57:51 +0000181
182 printf("%u. (%04hx) -- %s --\n",
183 prd->regno, regval, prd->name);
184
Trent Piepho19345822019-05-09 19:23:39 +0000185 for (i = 0; i < prd->len; i++) {
186 pdesc = &prd->pdesc[i];
wdenk61066ec2004-04-18 22:57:51 +0000187
188 mask_in_place = pdesc->mask << pdesc->lo;
189
Jeroen Hofsteea3e58912014-07-13 23:44:21 +0200190 printf(" (%04hx:%04x) %u.",
191 mask_in_place,
192 regval & mask_in_place,
193 prd->regno);
wdenk61066ec2004-04-18 22:57:51 +0000194
Trent Piepho19345822019-05-09 19:23:39 +0000195 if (!special_field(prd->regno, pdesc, regval))
196 dump_field(pdesc, regval);
wdenk61066ec2004-04-18 22:57:51 +0000197 printf("\n");
198
199 }
200 printf("\n");
201}
202
203/* Special fields:
204** 0.6,13
205** 0.8
206** 2.15-0
207** 3.15-0
208** 4.4-0
209** 5.4-0
210*/
211
Trent Piepho19345822019-05-09 19:23:39 +0000212static bool special_field(ushort regno, const MII_field_desc_t *pdesc,
213 ushort regval)
wdenk61066ec2004-04-18 22:57:51 +0000214{
Trent Piepho19345822019-05-09 19:23:39 +0000215 const ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
216
Mike Frysingerd63ee712010-12-23 15:40:12 -0500217 if ((regno == MII_BMCR) && (pdesc->lo == 6)) {
218 ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100);
wdenk61066ec2004-04-18 22:57:51 +0000219 printf("%2u,%2u = b%u%u speed selection = %s Mbps",
220 6, 13,
221 (regval >> 6) & 1,
222 (regval >> 13) & 1,
Mike Frysingerd63ee712010-12-23 15:40:12 -0500223 speed_bits == BMCR_SPEED1000 ? "1000" :
224 speed_bits == BMCR_SPEED100 ? "100" :
225 "10");
wdenk61066ec2004-04-18 22:57:51 +0000226 return 1;
227 }
228
Mike Frysingerd63ee712010-12-23 15:40:12 -0500229 else if ((regno == MII_BMCR) && (pdesc->lo == 8)) {
Trent Piepho19345822019-05-09 19:23:39 +0000230 dump_field(pdesc, regval);
231 printf(" = %s", ((regval >> pdesc->lo) & 1) ? "full" : "half");
wdenk61066ec2004-04-18 22:57:51 +0000232 return 1;
233 }
234
Mike Frysingerd63ee712010-12-23 15:40:12 -0500235 else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) {
Trent Piepho19345822019-05-09 19:23:39 +0000236 dump_field(pdesc, regval);
237 printf(" = %s",
238 sel_bits == PHY_ANLPAR_PSB_802_3 ? "IEEE 802.3 CSMA/CD" :
239 sel_bits == PHY_ANLPAR_PSB_802_9 ?
240 "IEEE 802.9 ISLAN-16T" : "???");
wdenk61066ec2004-04-18 22:57:51 +0000241 return 1;
242 }
243
Mike Frysingerd63ee712010-12-23 15:40:12 -0500244 else if ((regno == MII_LPA) && (pdesc->lo == 0)) {
Trent Piepho19345822019-05-09 19:23:39 +0000245 dump_field(pdesc, regval);
246 printf(" = %s",
247 sel_bits == PHY_ANLPAR_PSB_802_3 ? "IEEE 802.3 CSMA/CD" :
248 sel_bits == PHY_ANLPAR_PSB_802_9 ?
249 "IEEE 802.9 ISLAN-16T" : "???");
wdenk61066ec2004-04-18 22:57:51 +0000250 return 1;
251 }
252
253 return 0;
254}
255
Mike Frysinger4b497472010-10-20 01:06:48 -0400256static char last_op[2];
257static uint last_data;
258static uint last_addr_lo;
259static uint last_addr_hi;
260static uint last_reg_lo;
261static uint last_reg_hi;
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000262static uint last_mask;
wdenk61066ec2004-04-18 22:57:51 +0000263
264static void extract_range(
265 char * input,
266 unsigned char * plo,
267 unsigned char * phi)
268{
269 char * end;
270 *plo = simple_strtoul(input, &end, 16);
271 if (*end == '-') {
272 end++;
273 *phi = simple_strtoul(end, NULL, 16);
274 }
275 else {
276 *phi = *plo;
277 }
278}
279
wdenk20c98a62004-04-23 20:32:05 +0000280/* ---------------------------------------------------------------- */
Simon Glassed38aef2020-05-10 11:40:03 -0600281static int do_mii(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
wdenk61066ec2004-04-18 22:57:51 +0000282{
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200283 char op[2];
wdenk61066ec2004-04-18 22:57:51 +0000284 unsigned char addrlo, addrhi, reglo, reghi;
Wolfgang Denkedb65482005-09-24 21:54:50 +0200285 unsigned char addr, reg;
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000286 unsigned short data, mask;
wdenk61066ec2004-04-18 22:57:51 +0000287 int rcode = 0;
Mike Frysinger5ff5fdb2010-07-27 18:35:08 -0400288 const char *devname;
wdenk61066ec2004-04-18 22:57:51 +0000289
Wolfgang Denk3b683112010-07-17 01:06:04 +0200290 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +0000291 return CMD_RET_USAGE;
Shinya Kuribayashi9a631042007-12-27 15:39:54 +0900292
TsiChung Liewb3162452008-03-30 01:22:13 -0500293#if defined(CONFIG_MII_INIT)
wdenk61066ec2004-04-18 22:57:51 +0000294 mii_init ();
295#endif
296
297 /*
298 * We use the last specified parameters, unless new ones are
299 * entered.
300 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200301 op[0] = last_op[0];
302 op[1] = last_op[1];
wdenk61066ec2004-04-18 22:57:51 +0000303 addrlo = last_addr_lo;
304 addrhi = last_addr_hi;
305 reglo = last_reg_lo;
306 reghi = last_reg_hi;
307 data = last_data;
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000308 mask = last_mask;
wdenk61066ec2004-04-18 22:57:51 +0000309
310 if ((flag & CMD_FLAG_REPEAT) == 0) {
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200311 op[0] = argv[1][0];
312 if (strlen(argv[1]) > 1)
313 op[1] = argv[1][1];
314 else
315 op[1] = '\0';
316
wdenk61066ec2004-04-18 22:57:51 +0000317 if (argc >= 3)
318 extract_range(argv[2], &addrlo, &addrhi);
319 if (argc >= 4)
320 extract_range(argv[3], &reglo, &reghi);
321 if (argc >= 5)
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000322 data = simple_strtoul(argv[4], NULL, 16);
323 if (argc >= 6)
324 mask = simple_strtoul(argv[5], NULL, 16);
wdenk61066ec2004-04-18 22:57:51 +0000325 }
326
Hector Palacios4c2c4642018-08-17 13:06:40 +0200327 if (addrhi > 31 && strncmp(op, "de", 2)) {
Michal Simekf3aabf12015-10-19 15:13:34 +0200328 printf("Incorrect PHY address. Range should be 0-31\n");
329 return CMD_RET_USAGE;
330 }
331
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200332 /* use current device */
333 devname = miiphy_get_current_dev();
334
wdenk61066ec2004-04-18 22:57:51 +0000335 /*
336 * check info/read/write.
337 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200338 if (op[0] == 'i') {
wdenk61066ec2004-04-18 22:57:51 +0000339 unsigned char j, start, end;
340 unsigned int oui;
341 unsigned char model;
342 unsigned char rev;
343
344 /*
345 * Look for any and all PHYs. Valid addresses are 0..31.
346 */
347 if (argc >= 3) {
Wolfgang Denkedb65482005-09-24 21:54:50 +0200348 start = addrlo; end = addrhi;
wdenk61066ec2004-04-18 22:57:51 +0000349 } else {
Wolfgang Denkedb65482005-09-24 21:54:50 +0200350 start = 0; end = 31;
wdenk61066ec2004-04-18 22:57:51 +0000351 }
352
Wolfgang Denkedb65482005-09-24 21:54:50 +0200353 for (j = start; j <= end; j++) {
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200354 if (miiphy_info (devname, j, &oui, &model, &rev) == 0) {
wdenk61066ec2004-04-18 22:57:51 +0000355 printf("PHY 0x%02X: "
356 "OUI = 0x%04X, "
357 "Model = 0x%02X, "
358 "Rev = 0x%02X, "
Larry Johnson966a80b2007-11-01 08:46:50 -0500359 "%3dbase%s, %s\n",
wdenk61066ec2004-04-18 22:57:51 +0000360 j, oui, model, rev,
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200361 miiphy_speed (devname, j),
Larry Johnson966a80b2007-11-01 08:46:50 -0500362 miiphy_is_1000base_x (devname, j)
363 ? "X" : "T",
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200364 (miiphy_duplex (devname, j) == FULL)
365 ? "FDX" : "HDX");
wdenk61066ec2004-04-18 22:57:51 +0000366 }
367 }
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200368 } else if (op[0] == 'r') {
wdenk61066ec2004-04-18 22:57:51 +0000369 for (addr = addrlo; addr <= addrhi; addr++) {
370 for (reg = reglo; reg <= reghi; reg++) {
371 data = 0xffff;
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200372 if (miiphy_read (devname, addr, reg, &data) != 0) {
wdenk61066ec2004-04-18 22:57:51 +0000373 printf(
374 "Error reading from the PHY addr=%02x reg=%02x\n",
375 addr, reg);
376 rcode = 1;
Wolfgang Denkedb65482005-09-24 21:54:50 +0200377 } else {
wdenk61066ec2004-04-18 22:57:51 +0000378 if ((addrlo != addrhi) || (reglo != reghi))
379 printf("addr=%02x reg=%02x data=",
380 (uint)addr, (uint)reg);
381 printf("%04X\n", data & 0x0000FFFF);
382 }
383 }
384 if ((addrlo != addrhi) && (reglo != reghi))
385 printf("\n");
386 }
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200387 } else if (op[0] == 'w') {
wdenk61066ec2004-04-18 22:57:51 +0000388 for (addr = addrlo; addr <= addrhi; addr++) {
389 for (reg = reglo; reg <= reghi; reg++) {
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200390 if (miiphy_write (devname, addr, reg, data) != 0) {
wdenk61066ec2004-04-18 22:57:51 +0000391 printf("Error writing to the PHY addr=%02x reg=%02x\n",
392 addr, reg);
393 rcode = 1;
394 }
395 }
396 }
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000397 } else if (op[0] == 'm') {
398 for (addr = addrlo; addr <= addrhi; addr++) {
399 for (reg = reglo; reg <= reghi; reg++) {
400 unsigned short val = 0;
401 if (miiphy_read(devname, addr,
402 reg, &val)) {
403 printf("Error reading from the PHY");
404 printf(" addr=%02x", addr);
405 printf(" reg=%02x\n", reg);
406 rcode = 1;
407 } else {
408 val = (val & ~mask) | (data & mask);
409 if (miiphy_write(devname, addr,
410 reg, val)) {
411 printf("Error writing to the PHY");
412 printf(" addr=%02x", addr);
413 printf(" reg=%02x\n", reg);
414 rcode = 1;
415 }
416 }
417 }
418 }
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200419 } else if (strncmp(op, "du", 2) == 0) {
Trent Piepho1661ee02019-05-09 19:23:47 +0000420 ushort regs[MII_STAT1000 + 1]; /* Last reg is 0x0a */
wdenk61066ec2004-04-18 22:57:51 +0000421 int ok = 1;
Trent Piepho1661ee02019-05-09 19:23:47 +0000422 if (reglo > MII_STAT1000 || reghi > MII_STAT1000) {
423 printf("The MII dump command only formats the standard MII registers, 0-5, 9-a.\n");
wdenk61066ec2004-04-18 22:57:51 +0000424 return 1;
425 }
426 for (addr = addrlo; addr <= addrhi; addr++) {
Trent Piepho19345822019-05-09 19:23:39 +0000427 for (reg = reglo; reg <= reghi; reg++) {
428 if (miiphy_read(devname, addr, reg,
429 &regs[reg - reglo]) != 0) {
wdenk61066ec2004-04-18 22:57:51 +0000430 ok = 0;
431 printf(
432 "Error reading from the PHY addr=%02x reg=%02x\n",
433 addr, reg);
434 rcode = 1;
435 }
436 }
437 if (ok)
Trent Piepho19345822019-05-09 19:23:39 +0000438 MII_dump(regs, reglo, reghi);
wdenk61066ec2004-04-18 22:57:51 +0000439 printf("\n");
440 }
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200441 } else if (strncmp(op, "de", 2) == 0) {
442 if (argc == 2)
443 miiphy_listdev ();
444 else
445 miiphy_set_current_dev (argv[2]);
wdenk61066ec2004-04-18 22:57:51 +0000446 } else {
Simon Glassa06dfc72011-12-10 08:44:01 +0000447 return CMD_RET_USAGE;
wdenk61066ec2004-04-18 22:57:51 +0000448 }
449
450 /*
451 * Save the parameters for repeats.
452 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200453 last_op[0] = op[0];
454 last_op[1] = op[1];
wdenk61066ec2004-04-18 22:57:51 +0000455 last_addr_lo = addrlo;
456 last_addr_hi = addrhi;
457 last_reg_lo = reglo;
458 last_reg_hi = reghi;
459 last_data = data;
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000460 last_mask = mask;
wdenk61066ec2004-04-18 22:57:51 +0000461
462 return rcode;
463}
464
465/***************************************************/
466
467U_BOOT_CMD(
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000468 mii, 6, 1, do_mii,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600469 "MII utility commands",
Tim Jamesd9ba8a62015-03-25 11:55:15 +0000470 "device - list available devices\n"
471 "mii device <devname> - set current device\n"
472 "mii info <addr> - display MII PHY info\n"
473 "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n"
474 "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n"
475 "mii modify <addr> <reg> <data> <mask> - modify MII PHY <addr> register <reg>\n"
476 " updating bits identified in <mask>\n"
477 "mii dump <addr> <reg> - pretty-print <addr> <reg> (0-5 only)\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200478 "Addr and/or reg may be ranges, e.g. 2-7."
wdenk61066ec2004-04-18 22:57:51 +0000479);