blob: 18fad1e34ffc8cad67496e7086750042f76b083a [file] [log] [blame]
wdenkdd7d41f2002-09-18 20:04:01 +00001/*
2 * (C) Copyright 2001
3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * MII Utilities
26 */
27
28#include <common.h>
29#include <command.h>
wdenkdd7d41f2002-09-18 20:04:01 +000030#include <miiphy.h>
31
32#if (CONFIG_COMMANDS & CFG_CMD_MII)
33
34/*
35 * Display values from last command.
36 */
37uint last_op;
38uint last_addr;
39uint last_data;
40uint last_reg;
41
42/*
43 * MII read/write
44 *
45 * Syntax:
46 * mii read {addr} {reg}
47 * mii write {addr} {reg} {data}
48 */
49
50int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
51{
52 char op;
53 unsigned char addr, reg;
54 unsigned short data;
55 int rcode = 0;
56
wdenk6bd14892003-04-10 11:18:18 +000057#ifdef CONFIG_8xx
wdenkdd7d41f2002-09-18 20:04:01 +000058 mii_init ();
59#endif
60
61 /*
62 * We use the last specified parameters, unless new ones are
63 * entered.
64 */
65 op = last_op;
66 addr = last_addr;
67 data = last_data;
68 reg = last_reg;
69
70 if ((flag & CMD_FLAG_REPEAT) == 0) {
71 op = argv[1][0];
72 if (argc >= 3)
73 addr = simple_strtoul (argv[2], NULL, 16);
74 if (argc >= 4)
75 reg = simple_strtoul (argv[3], NULL, 16);
76 if (argc >= 5)
77 data = simple_strtoul (argv[4], NULL, 16);
78 }
79
80 /*
81 * check info/read/write.
82 */
83 if (op == 'i') {
84 int j;
85 unsigned int oui;
86 unsigned char model;
87 unsigned char rev;
88
89 /*
90 * Look for any and all PHYs. Valid addresses are 0..31.
91 */
92 for (j = 0; j < 32; j++) {
93 if (miiphy_info (j, &oui, &model, &rev) == 0) {
94 printf ("PHY 0x%02X: "
95 "OUI = 0x%04X, "
96 "Model = 0x%02X, "
97 "Rev = 0x%02X, "
98 "%3dbaseT, %s\n",
99 j, oui, model, rev,
100 miiphy_speed (j) == _100BASET ? 100 : 10,
101 miiphy_duplex (j) == FULL ? "FDX" : "HDX");
102 }
103 }
104 } else if (op == 'r') {
105 if (miiphy_read (addr, reg, &data) != 0) {
106 printf ("Error reading from the PHY\n");
107 rcode = 1;
108 }
109 printf ("%04X\n", data & 0x0000FFFF);
110 } else if (op == 'w') {
111 if (miiphy_write (addr, reg, data) != 0) {
112 printf ("Error writing to the PHY\n");
113 rcode = 1;
114 }
115 } else {
116 printf ("Usage:\n%s\n", cmdtp->usage);
117 return 1;
118 }
119
120 /*
121 * Save the parameters for repeats.
122 */
123 last_op = op;
124 last_addr = addr;
125 last_data = data;
126
127 return rcode;
128}
129
wdenk57b2d802003-06-27 21:31:46 +0000130/***************************************************/
131
wdenkf287a242003-07-01 21:06:45 +0000132U_BOOT_CMD(
133 mii, 5, 1, do_mii,
wdenk57b2d802003-06-27 21:31:46 +0000134 "mii - MII utility commands\n",
135 "info <addr> - display MII PHY info\n"
136 "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n"
137 "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n"
138);
139
140
wdenkdd7d41f2002-09-18 20:04:01 +0000141#endif /* CFG_CMD_MII */