]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_mii.c
b5963f12e690c6fe36d0084cd3aa4cd80ce57e8f
[karo-tx-uboot.git] / common / cmd_mii.c
1 /*
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>
30 #include <cmd_mii.h>
31 #include <miiphy.h>
32
33 #if (CONFIG_COMMANDS & CFG_CMD_MII)
34
35 /*
36  * Display values from last command.
37  */
38 uint last_op;
39 uint last_addr;
40 uint last_data;
41 uint last_reg;
42
43 /*
44  * MII read/write
45  *
46  * Syntax:
47  *  mii read {addr} {reg}
48  *  mii write {addr} {reg} {data}
49  */
50
51 int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
52 {
53         char            op;
54         unsigned char   addr, reg;
55         unsigned short  data;
56         int             rcode = 0;
57
58 #ifdef CONFIG_MPC860
59         mii_init ();
60 #endif
61
62         /*
63          * We use the last specified parameters, unless new ones are
64          * entered.
65          */
66         op   = last_op;
67         addr = last_addr;
68         data = last_data;
69         reg  = last_reg;
70
71         if ((flag & CMD_FLAG_REPEAT) == 0) {
72                 op = argv[1][0];
73                 if (argc >= 3)
74                         addr = simple_strtoul (argv[2], NULL, 16);
75                 if (argc >= 4)
76                         reg  = simple_strtoul (argv[3], NULL, 16);
77                 if (argc >= 5)
78                         data = simple_strtoul (argv[4], NULL, 16);
79         }
80
81         /*
82          * check info/read/write.
83          */
84         if (op == 'i') {
85                 int j;
86                 unsigned int oui;
87                 unsigned char model;
88                 unsigned char rev;
89
90                 /*
91                  * Look for any and all PHYs.  Valid addresses are 0..31.
92                  */
93                 for (j = 0; j < 32; j++) {
94                         if (miiphy_info (j, &oui, &model, &rev) == 0) {
95                                 printf ("PHY 0x%02X: "
96                                         "OUI = 0x%04X, "
97                                         "Model = 0x%02X, "
98                                         "Rev = 0x%02X, "
99                                         "%3dbaseT, %s\n",
100                                         j, oui, model, rev,
101                                         miiphy_speed (j) == _100BASET ? 100 : 10,
102                                         miiphy_duplex (j) == FULL ? "FDX" : "HDX");
103                         }
104                 }
105         } else if (op == 'r') {
106                 if (miiphy_read (addr, reg, &data) != 0) {
107                         printf ("Error reading from the PHY\n");
108                         rcode = 1;
109                 }
110                 printf ("%04X\n", data & 0x0000FFFF);
111         } else if (op == 'w') {
112                 if (miiphy_write (addr, reg, data) != 0) {
113                         printf ("Error writing to the PHY\n");
114                         rcode = 1;
115                 }
116         } else {
117                 printf ("Usage:\n%s\n", cmdtp->usage);
118                 return 1;
119         }
120
121         /*
122          * Save the parameters for repeats.
123          */
124         last_op = op;
125         last_addr = addr;
126         last_data = data;
127
128         return rcode;
129 }
130
131 #endif /* CFG_CMD_MII */