blob: fab420ee29e20c539fc04d00bb102d384fc7bf55 [file] [log] [blame]
Tom Rini83d290c2018-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 Glass2a64ada2020-07-19 10:15:39 -060013#include <dm.h>
wdenke35745b2004-04-18 23:32:11 +000014#include <miiphy.h>
15
wdenk24711112004-04-18 22:57:51 +000016typedef struct _MII_field_desc_t {
17 ushort hi;
18 ushort lo;
19 ushort mask;
Trent Piepho4ef32312019-05-09 19:23:39 +000020 const char *name;
wdenk24711112004-04-18 22:57:51 +000021} MII_field_desc_t;
22
Mike Frysinger3a5ee0b2010-10-20 01:06:48 -040023static const MII_field_desc_t reg_0_desc_tbl[] = {
wdenk24711112004-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 Frysinger3a5ee0b2010-10-20 01:06:48 -040036static const MII_field_desc_t reg_1_desc_tbl[] = {
wdenk24711112004-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 Frysinger3a5ee0b2010-10-20 01:06:48 -040055static const MII_field_desc_t reg_2_desc_tbl[] = {
wdenk24711112004-04-18 22:57:51 +000056 { 15, 0, 0xffff, "OUI portion" },
57};
58
Mike Frysinger3a5ee0b2010-10-20 01:06:48 -040059static const MII_field_desc_t reg_3_desc_tbl[] = {
wdenk24711112004-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 Frysinger3a5ee0b2010-10-20 01:06:48 -040065static const MII_field_desc_t reg_4_desc_tbl[] = {
wdenk24711112004-04-18 22:57:51 +000066 { 15, 15, 0x01, "next page able" },
Stephan Bauroth57d33d42013-08-08 13:44:41 +020067 { 14, 14, 0x01, "(reserved)" },
wdenk24711112004-04-18 22:57:51 +000068 { 13, 13, 0x01, "remote fault" },
Stephan Bauroth57d33d42013-08-08 13:44:41 +020069 { 12, 12, 0x01, "(reserved)" },
wdenk24711112004-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 Piepho4ef32312019-05-09 19:23:39 +000077 { 4, 0, 0x1f, "selector" },
wdenk24711112004-04-18 22:57:51 +000078};
79
Mike Frysinger3a5ee0b2010-10-20 01:06:48 -040080static const MII_field_desc_t reg_5_desc_tbl[] = {
wdenk24711112004-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 Piepho4ef32312019-05-09 19:23:39 +000092 { 4, 0, 0x1f, "partner selector" },
wdenk24711112004-04-18 22:57:51 +000093};
Trent Piepho4ef32312019-05-09 19:23:39 +000094
Trent Piepho95637862019-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 Piepho4ef32312019-05-09 19:23:39 +0000117typedef struct _MII_reg_desc_t {
118 ushort regno;
Mike Frysinger3a5ee0b2010-10-20 01:06:48 -0400119 const MII_field_desc_t *pdesc;
wdenk24711112004-04-18 22:57:51 +0000120 ushort len;
Trent Piepho4ef32312019-05-09 19:23:39 +0000121 const char *name;
122} MII_reg_desc_t;
wdenk24711112004-04-18 22:57:51 +0000123
Trent Piepho4ef32312019-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 Piepho95637862019-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" },
wdenk24711112004-04-18 22:57:51 +0000141};
142
143static void dump_reg(
144 ushort regval,
Trent Piepho4ef32312019-05-09 19:23:39 +0000145 const MII_reg_desc_t *prd);
wdenk24711112004-04-18 22:57:51 +0000146
Trent Piepho4ef32312019-05-09 19:23:39 +0000147static bool special_field(ushort regno, const MII_field_desc_t *pdesc,
148 ushort regval);
wdenk24711112004-04-18 22:57:51 +0000149
Trent Piepho4ef32312019-05-09 19:23:39 +0000150static void MII_dump(const ushort *regvals, uchar reglo, uchar reghi)
wdenk24711112004-04-18 22:57:51 +0000151{
152 ulong i;
153
Trent Piepho4ef32312019-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]);
wdenk24711112004-04-18 22:57:51 +0000159 }
160}
161
Trent Piepho4ef32312019-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
wdenk24711112004-04-18 22:57:51 +0000174static void dump_reg(
175 ushort regval,
Trent Piepho4ef32312019-05-09 19:23:39 +0000176 const MII_reg_desc_t *prd)
wdenk24711112004-04-18 22:57:51 +0000177{
178 ulong i;
179 ushort mask_in_place;
Mike Frysinger3a5ee0b2010-10-20 01:06:48 -0400180 const MII_field_desc_t *pdesc;
wdenk24711112004-04-18 22:57:51 +0000181
182 printf("%u. (%04hx) -- %s --\n",
183 prd->regno, regval, prd->name);
184
Trent Piepho4ef32312019-05-09 19:23:39 +0000185 for (i = 0; i < prd->len; i++) {
186 pdesc = &prd->pdesc[i];
wdenk24711112004-04-18 22:57:51 +0000187
188 mask_in_place = pdesc->mask << pdesc->lo;
189
Jeroen Hofsteec68112f2014-07-13 23:44:21 +0200190 printf(" (%04hx:%04x) %u.",
191 mask_in_place,
192 regval & mask_in_place,
193 prd->regno);
wdenk24711112004-04-18 22:57:51 +0000194
Trent Piepho4ef32312019-05-09 19:23:39 +0000195 if (!special_field(prd->regno, pdesc, regval))
196 dump_field(pdesc, regval);
wdenk24711112004-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 Piepho4ef32312019-05-09 19:23:39 +0000212static bool special_field(ushort regno, const MII_field_desc_t *pdesc,
213 ushort regval)
wdenk24711112004-04-18 22:57:51 +0000214{
Trent Piepho4ef32312019-05-09 19:23:39 +0000215 const ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask;
216
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500217 if ((regno == MII_BMCR) && (pdesc->lo == 6)) {
218 ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100);
wdenk24711112004-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 Frysinger8ef583a2010-12-23 15:40:12 -0500223 speed_bits == BMCR_SPEED1000 ? "1000" :
224 speed_bits == BMCR_SPEED100 ? "100" :
225 "10");
wdenk24711112004-04-18 22:57:51 +0000226 return 1;
227 }
228
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500229 else if ((regno == MII_BMCR) && (pdesc->lo == 8)) {
Trent Piepho4ef32312019-05-09 19:23:39 +0000230 dump_field(pdesc, regval);
231 printf(" = %s", ((regval >> pdesc->lo) & 1) ? "full" : "half");
wdenk24711112004-04-18 22:57:51 +0000232 return 1;
233 }
234
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500235 else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) {
Trent Piepho4ef32312019-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" : "???");
wdenk24711112004-04-18 22:57:51 +0000241 return 1;
242 }
243
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500244 else if ((regno == MII_LPA) && (pdesc->lo == 0)) {
Trent Piepho4ef32312019-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" : "???");
wdenk24711112004-04-18 22:57:51 +0000250 return 1;
251 }
252
253 return 0;
254}
255
Mike Frysinger3a5ee0b2010-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 Jamesa095f042015-03-25 11:55:15 +0000262static uint last_mask;
wdenk24711112004-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;
Simon Glass7e5f4602021-07-24 09:03:29 -0600270 *plo = hextoul(input, &end);
wdenk24711112004-04-18 22:57:51 +0000271 if (*end == '-') {
272 end++;
Simon Glass7e5f4602021-07-24 09:03:29 -0600273 *phi = hextoul(end, NULL);
wdenk24711112004-04-18 22:57:51 +0000274 }
275 else {
276 *phi = *plo;
277 }
278}
279
wdenk5cf91d62004-04-23 20:32:05 +0000280/* ---------------------------------------------------------------- */
Simon Glass09140112020-05-10 11:40:03 -0600281static int do_mii(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
wdenk24711112004-04-18 22:57:51 +0000282{
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200283 char op[2];
wdenk24711112004-04-18 22:57:51 +0000284 unsigned char addrlo, addrhi, reglo, reghi;
Wolfgang Denk2b792af2005-09-24 21:54:50 +0200285 unsigned char addr, reg;
Tim Jamesa095f042015-03-25 11:55:15 +0000286 unsigned short data, mask;
wdenk24711112004-04-18 22:57:51 +0000287 int rcode = 0;
Mike Frysinger5700bb62010-07-27 18:35:08 -0400288 const char *devname;
wdenk24711112004-04-18 22:57:51 +0000289
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200290 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000291 return CMD_RET_USAGE;
Shinya Kuribayashib9173af2007-12-27 15:39:54 +0900292
TsiChung Liew0f3ba7e2008-03-30 01:22:13 -0500293#if defined(CONFIG_MII_INIT)
wdenk24711112004-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 Balakowicz63ff0042005-10-28 22:30:33 +0200301 op[0] = last_op[0];
302 op[1] = last_op[1];
wdenk24711112004-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 Jamesa095f042015-03-25 11:55:15 +0000308 mask = last_mask;
wdenk24711112004-04-18 22:57:51 +0000309
310 if ((flag & CMD_FLAG_REPEAT) == 0) {
Marian Balakowicz63ff0042005-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
wdenk24711112004-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)
Simon Glass7e5f4602021-07-24 09:03:29 -0600322 data = hextoul(argv[4], NULL);
Tim Jamesa095f042015-03-25 11:55:15 +0000323 if (argc >= 6)
Simon Glass7e5f4602021-07-24 09:03:29 -0600324 mask = hextoul(argv[5], NULL);
wdenk24711112004-04-18 22:57:51 +0000325 }
326
Hector Palaciosfb265a72018-08-17 13:06:40 +0200327 if (addrhi > 31 && strncmp(op, "de", 2)) {
Michal Simekbdaeb8f2015-10-19 15:13:34 +0200328 printf("Incorrect PHY address. Range should be 0-31\n");
329 return CMD_RET_USAGE;
330 }
331
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200332 /* use current device */
333 devname = miiphy_get_current_dev();
334
wdenk24711112004-04-18 22:57:51 +0000335 /*
336 * check info/read/write.
337 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200338 if (op[0] == 'i') {
wdenk24711112004-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 Denk2b792af2005-09-24 21:54:50 +0200348 start = addrlo; end = addrhi;
wdenk24711112004-04-18 22:57:51 +0000349 } else {
Wolfgang Denk2b792af2005-09-24 21:54:50 +0200350 start = 0; end = 31;
wdenk24711112004-04-18 22:57:51 +0000351 }
352
Wolfgang Denk2b792af2005-09-24 21:54:50 +0200353 for (j = start; j <= end; j++) {
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200354 if (miiphy_info (devname, j, &oui, &model, &rev) == 0) {
wdenk24711112004-04-18 22:57:51 +0000355 printf("PHY 0x%02X: "
356 "OUI = 0x%04X, "
357 "Model = 0x%02X, "
358 "Rev = 0x%02X, "
Larry Johnson71bc6e62007-11-01 08:46:50 -0500359 "%3dbase%s, %s\n",
wdenk24711112004-04-18 22:57:51 +0000360 j, oui, model, rev,
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200361 miiphy_speed (devname, j),
Larry Johnson71bc6e62007-11-01 08:46:50 -0500362 miiphy_is_1000base_x (devname, j)
363 ? "X" : "T",
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200364 (miiphy_duplex (devname, j) == FULL)
365 ? "FDX" : "HDX");
wdenk24711112004-04-18 22:57:51 +0000366 }
367 }
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200368 } else if (op[0] == 'r') {
wdenk24711112004-04-18 22:57:51 +0000369 for (addr = addrlo; addr <= addrhi; addr++) {
370 for (reg = reglo; reg <= reghi; reg++) {
371 data = 0xffff;
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200372 if (miiphy_read (devname, addr, reg, &data) != 0) {
wdenk24711112004-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 Denk2b792af2005-09-24 21:54:50 +0200377 } else {
wdenk24711112004-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 Balakowicz63ff0042005-10-28 22:30:33 +0200387 } else if (op[0] == 'w') {
wdenk24711112004-04-18 22:57:51 +0000388 for (addr = addrlo; addr <= addrhi; addr++) {
389 for (reg = reglo; reg <= reghi; reg++) {
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200390 if (miiphy_write (devname, addr, reg, data) != 0) {
wdenk24711112004-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 Jamesa095f042015-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 Balakowicz63ff0042005-10-28 22:30:33 +0200419 } else if (strncmp(op, "du", 2) == 0) {
Trent Piepho95637862019-05-09 19:23:47 +0000420 ushort regs[MII_STAT1000 + 1]; /* Last reg is 0x0a */
wdenk24711112004-04-18 22:57:51 +0000421 int ok = 1;
Trent Piepho95637862019-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");
wdenk24711112004-04-18 22:57:51 +0000424 return 1;
425 }
426 for (addr = addrlo; addr <= addrhi; addr++) {
Trent Piepho4ef32312019-05-09 19:23:39 +0000427 for (reg = reglo; reg <= reghi; reg++) {
428 if (miiphy_read(devname, addr, reg,
429 &regs[reg - reglo]) != 0) {
wdenk24711112004-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 Piepho4ef32312019-05-09 19:23:39 +0000438 MII_dump(regs, reglo, reghi);
wdenk24711112004-04-18 22:57:51 +0000439 printf("\n");
440 }
Marian Balakowicz63ff0042005-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]);
wdenk24711112004-04-18 22:57:51 +0000446 } else {
Simon Glass4c12eeb2011-12-10 08:44:01 +0000447 return CMD_RET_USAGE;
wdenk24711112004-04-18 22:57:51 +0000448 }
449
450 /*
451 * Save the parameters for repeats.
452 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200453 last_op[0] = op[0];
454 last_op[1] = op[1];
wdenk24711112004-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 Jamesa095f042015-03-25 11:55:15 +0000460 last_mask = mask;
wdenk24711112004-04-18 22:57:51 +0000461
462 return rcode;
463}
464
465/***************************************************/
466
467U_BOOT_CMD(
Tim Jamesa095f042015-03-25 11:55:15 +0000468 mii, 6, 1, do_mii,
Peter Tyser2fb26042009-01-27 18:03:12 -0600469 "MII utility commands",
Tim Jamesa095f042015-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 Denka89c33d2009-05-24 17:06:54 +0200478 "Addr and/or reg may be ranges, e.g. 2-7."
wdenk24711112004-04-18 22:57:51 +0000479);