wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 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> |
wdenk | e44b911 | 2004-04-18 23:32:11 +0000 | [diff] [blame] | 30 | #include <miiphy.h> |
| 31 | |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_TERSE_MII |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 33 | /* |
| 34 | * Display values from last command. |
| 35 | */ |
| 36 | uint last_op; |
| 37 | uint last_addr; |
| 38 | uint last_data; |
| 39 | uint last_reg; |
| 40 | |
| 41 | /* |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 42 | * MII device/info/read/write |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 43 | * |
| 44 | * Syntax: |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 45 | * mii device {devname} |
| 46 | * mii info {addr} |
| 47 | * mii read {addr} {reg} |
| 48 | * mii write {addr} {reg} {data} |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 49 | */ |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 50 | int 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; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 56 | char *devname; |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 57 | |
Wolfgang Denk | a66dce5 | 2006-07-21 11:20:46 +0200 | [diff] [blame] | 58 | if (argc < 2) { |
| 59 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 60 | return 1; |
| 61 | } |
| 62 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 63 | #if defined(CONFIG_8xx) || defined(CONFIG_MCF52x2) |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 64 | mii_init (); |
| 65 | #endif |
| 66 | |
| 67 | /* |
| 68 | * We use the last specified parameters, unless new ones are |
| 69 | * entered. |
| 70 | */ |
| 71 | op = last_op; |
| 72 | addr = last_addr; |
| 73 | data = last_data; |
| 74 | reg = last_reg; |
| 75 | |
| 76 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 77 | op = argv[1][0]; |
| 78 | if (argc >= 3) |
| 79 | addr = simple_strtoul (argv[2], NULL, 16); |
| 80 | if (argc >= 4) |
| 81 | reg = simple_strtoul (argv[3], NULL, 16); |
| 82 | if (argc >= 5) |
| 83 | data = simple_strtoul (argv[4], NULL, 16); |
| 84 | } |
| 85 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 86 | /* use current device */ |
| 87 | devname = miiphy_get_current_dev(); |
| 88 | |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 89 | /* |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 90 | * check device/read/write/list. |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 91 | */ |
| 92 | if (op == 'i') { |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 93 | unsigned char j, start, end; |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 94 | unsigned int oui; |
| 95 | unsigned char model; |
| 96 | unsigned char rev; |
| 97 | |
| 98 | /* |
| 99 | * Look for any and all PHYs. Valid addresses are 0..31. |
| 100 | */ |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 101 | if (argc >= 3) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 102 | start = addr; end = addr + 1; |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 103 | } else { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 104 | start = 0; end = 31; |
wdenk | f4cec3f | 2003-12-06 23:20:41 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | for (j = start; j < end; j++) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 108 | if (miiphy_info (devname, j, &oui, &model, &rev) == 0) { |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 109 | printf ("PHY 0x%02X: " |
| 110 | "OUI = 0x%04X, " |
| 111 | "Model = 0x%02X, " |
| 112 | "Rev = 0x%02X, " |
Larry Johnson | 966a80b | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 113 | "%3dbase%s, %s\n", |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 114 | j, oui, model, rev, |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 115 | miiphy_speed (devname, j), |
Larry Johnson | 966a80b | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 116 | miiphy_is_1000base_x (devname, j) |
| 117 | ? "X" : "T", |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 118 | (miiphy_duplex (devname, j) == FULL) |
| 119 | ? "FDX" : "HDX"); |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | } else if (op == 'r') { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 123 | if (miiphy_read (devname, addr, reg, &data) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 124 | puts ("Error reading from the PHY\n"); |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 125 | rcode = 1; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 126 | } else { |
| 127 | printf ("%04X\n", data & 0x0000FFFF); |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 128 | } |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 129 | } else if (op == 'w') { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 130 | if (miiphy_write (devname, addr, reg, data) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 131 | puts ("Error writing to the PHY\n"); |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 132 | rcode = 1; |
| 133 | } |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 134 | } else if (op == 'd') { |
| 135 | if (argc == 2) |
| 136 | miiphy_listdev (); |
| 137 | else |
| 138 | miiphy_set_current_dev (argv[2]); |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 139 | } else { |
| 140 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Save the parameters for repeats. |
| 146 | */ |
| 147 | last_op = op; |
| 148 | last_addr = addr; |
| 149 | last_data = data; |
wdenk | 5f49575 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 150 | last_reg = reg; |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 151 | |
| 152 | return rcode; |
| 153 | } |
| 154 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 155 | /***************************************************/ |
| 156 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 157 | U_BOOT_CMD( |
| 158 | mii, 5, 1, do_mii, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 159 | "mii - MII utility commands\n", |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 160 | "device - list available devices\n" |
| 161 | "mii device <devname> - set current device\n" |
| 162 | "mii info <addr> - display MII PHY info\n" |
| 163 | "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n" |
| 164 | "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 165 | ); |
wdenk | e44b911 | 2004-04-18 23:32:11 +0000 | [diff] [blame] | 166 | |
| 167 | #else /* ! CONFIG_TERSE_MII ================================================= */ |
| 168 | |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 169 | typedef struct _MII_reg_desc_t { |
| 170 | ushort regno; |
| 171 | char * name; |
| 172 | } MII_reg_desc_t; |
| 173 | |
| 174 | MII_reg_desc_t reg_0_5_desc_tbl[] = { |
| 175 | { 0, "PHY control register" }, |
| 176 | { 1, "PHY status register" }, |
| 177 | { 2, "PHY ID 1 register" }, |
| 178 | { 3, "PHY ID 2 register" }, |
| 179 | { 4, "Autonegotiation advertisement register" }, |
| 180 | { 5, "Autonegotiation partner abilities register" }, |
| 181 | }; |
| 182 | |
| 183 | typedef struct _MII_field_desc_t { |
| 184 | ushort hi; |
| 185 | ushort lo; |
| 186 | ushort mask; |
| 187 | char * name; |
| 188 | } MII_field_desc_t; |
| 189 | |
| 190 | MII_field_desc_t reg_0_desc_tbl[] = { |
| 191 | { 15, 15, 0x01, "reset" }, |
| 192 | { 14, 14, 0x01, "loopback" }, |
| 193 | { 13, 6, 0x81, "speed selection" }, /* special */ |
| 194 | { 12, 12, 0x01, "A/N enable" }, |
| 195 | { 11, 11, 0x01, "power-down" }, |
| 196 | { 10, 10, 0x01, "isolate" }, |
| 197 | { 9, 9, 0x01, "restart A/N" }, |
| 198 | { 8, 8, 0x01, "duplex" }, /* special */ |
| 199 | { 7, 7, 0x01, "collision test enable" }, |
| 200 | { 5, 0, 0x3f, "(reserved)" } |
| 201 | }; |
| 202 | |
| 203 | MII_field_desc_t reg_1_desc_tbl[] = { |
| 204 | { 15, 15, 0x01, "100BASE-T4 able" }, |
| 205 | { 14, 14, 0x01, "100BASE-X full duplex able" }, |
| 206 | { 13, 13, 0x01, "100BASE-X half duplex able" }, |
| 207 | { 12, 12, 0x01, "10 Mbps full duplex able" }, |
| 208 | { 11, 11, 0x01, "10 Mbps half duplex able" }, |
| 209 | { 10, 10, 0x01, "100BASE-T2 full duplex able" }, |
| 210 | { 9, 9, 0x01, "100BASE-T2 half duplex able" }, |
| 211 | { 8, 8, 0x01, "extended status" }, |
| 212 | { 7, 7, 0x01, "(reserved)" }, |
| 213 | { 6, 6, 0x01, "MF preamble suppression" }, |
| 214 | { 5, 5, 0x01, "A/N complete" }, |
| 215 | { 4, 4, 0x01, "remote fault" }, |
| 216 | { 3, 3, 0x01, "A/N able" }, |
| 217 | { 2, 2, 0x01, "link status" }, |
| 218 | { 1, 1, 0x01, "jabber detect" }, |
| 219 | { 0, 0, 0x01, "extended capabilities" }, |
| 220 | }; |
| 221 | |
| 222 | MII_field_desc_t reg_2_desc_tbl[] = { |
| 223 | { 15, 0, 0xffff, "OUI portion" }, |
| 224 | }; |
| 225 | |
| 226 | MII_field_desc_t reg_3_desc_tbl[] = { |
| 227 | { 15, 10, 0x3f, "OUI portion" }, |
| 228 | { 9, 4, 0x3f, "manufacturer part number" }, |
| 229 | { 3, 0, 0x0f, "manufacturer rev. number" }, |
| 230 | }; |
| 231 | |
| 232 | MII_field_desc_t reg_4_desc_tbl[] = { |
| 233 | { 15, 15, 0x01, "next page able" }, |
| 234 | { 14, 14, 0x01, "reserved" }, |
| 235 | { 13, 13, 0x01, "remote fault" }, |
| 236 | { 12, 12, 0x01, "reserved" }, |
| 237 | { 11, 11, 0x01, "asymmetric pause" }, |
| 238 | { 10, 10, 0x01, "pause enable" }, |
| 239 | { 9, 9, 0x01, "100BASE-T4 able" }, |
| 240 | { 8, 8, 0x01, "100BASE-TX full duplex able" }, |
| 241 | { 7, 7, 0x01, "100BASE-TX able" }, |
| 242 | { 6, 6, 0x01, "10BASE-T full duplex able" }, |
| 243 | { 5, 5, 0x01, "10BASE-T able" }, |
| 244 | { 4, 0, 0x1f, "xxx to do" }, |
| 245 | }; |
| 246 | |
| 247 | MII_field_desc_t reg_5_desc_tbl[] = { |
| 248 | { 15, 15, 0x01, "next page able" }, |
| 249 | { 14, 14, 0x01, "acknowledge" }, |
| 250 | { 13, 13, 0x01, "remote fault" }, |
| 251 | { 12, 12, 0x01, "(reserved)" }, |
| 252 | { 11, 11, 0x01, "asymmetric pause able" }, |
| 253 | { 10, 10, 0x01, "pause able" }, |
| 254 | { 9, 9, 0x01, "100BASE-T4 able" }, |
| 255 | { 8, 8, 0x01, "100BASE-X full duplex able" }, |
| 256 | { 7, 7, 0x01, "100BASE-TX able" }, |
| 257 | { 6, 6, 0x01, "10BASE-T full duplex able" }, |
| 258 | { 5, 5, 0x01, "10BASE-T able" }, |
| 259 | { 4, 0, 0x1f, "xxx to do" }, |
| 260 | }; |
| 261 | |
| 262 | #define DESC0LEN (sizeof(reg_0_desc_tbl)/sizeof(reg_0_desc_tbl[0])) |
| 263 | #define DESC1LEN (sizeof(reg_1_desc_tbl)/sizeof(reg_1_desc_tbl[0])) |
| 264 | #define DESC2LEN (sizeof(reg_2_desc_tbl)/sizeof(reg_2_desc_tbl[0])) |
| 265 | #define DESC3LEN (sizeof(reg_3_desc_tbl)/sizeof(reg_3_desc_tbl[0])) |
| 266 | #define DESC4LEN (sizeof(reg_4_desc_tbl)/sizeof(reg_4_desc_tbl[0])) |
| 267 | #define DESC5LEN (sizeof(reg_5_desc_tbl)/sizeof(reg_5_desc_tbl[0])) |
| 268 | |
| 269 | typedef struct _MII_field_desc_and_len_t { |
| 270 | MII_field_desc_t * pdesc; |
| 271 | ushort len; |
| 272 | } MII_field_desc_and_len_t; |
| 273 | |
| 274 | MII_field_desc_and_len_t desc_and_len_tbl[] = { |
| 275 | { reg_0_desc_tbl, DESC0LEN }, |
| 276 | { reg_1_desc_tbl, DESC1LEN }, |
| 277 | { reg_2_desc_tbl, DESC2LEN }, |
| 278 | { reg_3_desc_tbl, DESC3LEN }, |
| 279 | { reg_4_desc_tbl, DESC4LEN }, |
| 280 | { reg_5_desc_tbl, DESC5LEN }, |
| 281 | }; |
| 282 | |
| 283 | static void dump_reg( |
| 284 | ushort regval, |
| 285 | MII_reg_desc_t * prd, |
| 286 | MII_field_desc_and_len_t * pdl); |
| 287 | |
| 288 | static int special_field( |
| 289 | ushort regno, |
| 290 | MII_field_desc_t * pdesc, |
| 291 | ushort regval); |
| 292 | |
| 293 | void MII_dump_0_to_5( |
| 294 | ushort regvals[6], |
| 295 | uchar reglo, |
| 296 | uchar reghi) |
| 297 | { |
| 298 | ulong i; |
| 299 | |
| 300 | for (i = 0; i < 6; i++) { |
| 301 | if ((reglo <= i) && (i <= reghi)) |
| 302 | dump_reg(regvals[i], ®_0_5_desc_tbl[i], |
| 303 | &desc_and_len_tbl[i]); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | static void dump_reg( |
| 308 | ushort regval, |
| 309 | MII_reg_desc_t * prd, |
| 310 | MII_field_desc_and_len_t * pdl) |
| 311 | { |
| 312 | ulong i; |
| 313 | ushort mask_in_place; |
| 314 | MII_field_desc_t * pdesc; |
| 315 | |
| 316 | printf("%u. (%04hx) -- %s --\n", |
| 317 | prd->regno, regval, prd->name); |
| 318 | |
| 319 | for (i = 0; i < pdl->len; i++) { |
| 320 | pdesc = &pdl->pdesc[i]; |
| 321 | |
| 322 | mask_in_place = pdesc->mask << pdesc->lo; |
| 323 | |
| 324 | printf(" (%04hx:%04hx) %u.", |
| 325 | mask_in_place, |
| 326 | regval & mask_in_place, |
| 327 | prd->regno); |
| 328 | |
| 329 | if (special_field(prd->regno, pdesc, regval)) { |
| 330 | } |
| 331 | else { |
| 332 | if (pdesc->hi == pdesc->lo) |
| 333 | printf("%2u ", pdesc->lo); |
| 334 | else |
| 335 | printf("%2u-%2u", pdesc->hi, pdesc->lo); |
| 336 | printf(" = %5u %s", |
| 337 | (regval & mask_in_place) >> pdesc->lo, |
| 338 | pdesc->name); |
| 339 | } |
| 340 | printf("\n"); |
| 341 | |
| 342 | } |
| 343 | printf("\n"); |
| 344 | } |
| 345 | |
| 346 | /* Special fields: |
| 347 | ** 0.6,13 |
| 348 | ** 0.8 |
| 349 | ** 2.15-0 |
| 350 | ** 3.15-0 |
| 351 | ** 4.4-0 |
| 352 | ** 5.4-0 |
| 353 | */ |
| 354 | |
| 355 | static int special_field( |
| 356 | ushort regno, |
| 357 | MII_field_desc_t * pdesc, |
| 358 | ushort regval) |
| 359 | { |
| 360 | if ((regno == 0) && (pdesc->lo == 6)) { |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 361 | ushort speed_bits = regval & PHY_BMCR_SPEED_MASK; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 362 | printf("%2u,%2u = b%u%u speed selection = %s Mbps", |
| 363 | 6, 13, |
| 364 | (regval >> 6) & 1, |
| 365 | (regval >> 13) & 1, |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 366 | speed_bits == PHY_BMCR_1000_MBPS ? "1000" : |
| 367 | speed_bits == PHY_BMCR_100_MBPS ? "100" : |
| 368 | speed_bits == PHY_BMCR_10_MBPS ? "10" : |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 369 | "???"); |
| 370 | return 1; |
| 371 | } |
| 372 | |
| 373 | else if ((regno == 0) && (pdesc->lo == 8)) { |
| 374 | printf("%2u = %5u duplex = %s", |
| 375 | pdesc->lo, |
| 376 | (regval >> pdesc->lo) & 1, |
| 377 | ((regval >> pdesc->lo) & 1) ? "full" : "half"); |
| 378 | return 1; |
| 379 | } |
| 380 | |
| 381 | else if ((regno == 4) && (pdesc->lo == 0)) { |
| 382 | ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask; |
| 383 | printf("%2u-%2u = %5u selector = %s", |
| 384 | pdesc->hi, pdesc->lo, sel_bits, |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 385 | sel_bits == PHY_ANLPAR_PSB_802_3 ? |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 386 | "IEEE 802.3" : |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 387 | sel_bits == PHY_ANLPAR_PSB_802_9 ? |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 388 | "IEEE 802.9 ISLAN-16T" : |
| 389 | "???"); |
| 390 | return 1; |
| 391 | } |
| 392 | |
| 393 | else if ((regno == 5) && (pdesc->lo == 0)) { |
| 394 | ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask; |
| 395 | printf("%2u-%2u = %u selector = %s", |
| 396 | pdesc->hi, pdesc->lo, sel_bits, |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 397 | sel_bits == PHY_ANLPAR_PSB_802_3 ? |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 398 | "IEEE 802.3" : |
wdenk | 656140b | 2004-04-25 13:18:40 +0000 | [diff] [blame] | 399 | sel_bits == PHY_ANLPAR_PSB_802_9 ? |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 400 | "IEEE 802.9 ISLAN-16T" : |
| 401 | "???"); |
| 402 | return 1; |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 408 | char last_op[2]; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 409 | uint last_data; |
| 410 | uint last_addr_lo; |
| 411 | uint last_addr_hi; |
| 412 | uint last_reg_lo; |
| 413 | uint last_reg_hi; |
| 414 | |
| 415 | static void extract_range( |
| 416 | char * input, |
| 417 | unsigned char * plo, |
| 418 | unsigned char * phi) |
| 419 | { |
| 420 | char * end; |
| 421 | *plo = simple_strtoul(input, &end, 16); |
| 422 | if (*end == '-') { |
| 423 | end++; |
| 424 | *phi = simple_strtoul(end, NULL, 16); |
| 425 | } |
| 426 | else { |
| 427 | *phi = *plo; |
| 428 | } |
| 429 | } |
| 430 | |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 431 | /* ---------------------------------------------------------------- */ |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 432 | int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 433 | { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 434 | char op[2]; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 435 | unsigned char addrlo, addrhi, reglo, reghi; |
Wolfgang Denk | edb6548 | 2005-09-24 21:54:50 +0200 | [diff] [blame] | 436 | unsigned char addr, reg; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 437 | unsigned short data; |
| 438 | int rcode = 0; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 439 | char *devname; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 440 | |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 441 | #if defined(CONFIG_8xx) || defined(CONFIG_MCF532x) |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 442 | mii_init (); |
| 443 | #endif |
| 444 | |
| 445 | /* |
| 446 | * We use the last specified parameters, unless new ones are |
| 447 | * entered. |
| 448 | */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 449 | op[0] = last_op[0]; |
| 450 | op[1] = last_op[1]; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 451 | addrlo = last_addr_lo; |
| 452 | addrhi = last_addr_hi; |
| 453 | reglo = last_reg_lo; |
| 454 | reghi = last_reg_hi; |
| 455 | data = last_data; |
| 456 | |
| 457 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 458 | op[0] = argv[1][0]; |
| 459 | if (strlen(argv[1]) > 1) |
| 460 | op[1] = argv[1][1]; |
| 461 | else |
| 462 | op[1] = '\0'; |
| 463 | |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 464 | if (argc >= 3) |
| 465 | extract_range(argv[2], &addrlo, &addrhi); |
| 466 | if (argc >= 4) |
| 467 | extract_range(argv[3], ®lo, ®hi); |
| 468 | if (argc >= 5) |
| 469 | data = simple_strtoul (argv[4], NULL, 16); |
| 470 | } |
| 471 | |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 472 | /* use current device */ |
| 473 | devname = miiphy_get_current_dev(); |
| 474 | |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 475 | /* |
| 476 | * check info/read/write. |
| 477 | */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 478 | if (op[0] == 'i') { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 479 | unsigned char j, start, end; |
| 480 | unsigned int oui; |
| 481 | unsigned char model; |
| 482 | unsigned char rev; |
| 483 | |
| 484 | /* |
| 485 | * Look for any and all PHYs. Valid addresses are 0..31. |
| 486 | */ |
| 487 | if (argc >= 3) { |
Wolfgang Denk | edb6548 | 2005-09-24 21:54:50 +0200 | [diff] [blame] | 488 | start = addrlo; end = addrhi; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 489 | } else { |
Wolfgang Denk | edb6548 | 2005-09-24 21:54:50 +0200 | [diff] [blame] | 490 | start = 0; end = 31; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Wolfgang Denk | edb6548 | 2005-09-24 21:54:50 +0200 | [diff] [blame] | 493 | for (j = start; j <= end; j++) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 494 | if (miiphy_info (devname, j, &oui, &model, &rev) == 0) { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 495 | printf("PHY 0x%02X: " |
| 496 | "OUI = 0x%04X, " |
| 497 | "Model = 0x%02X, " |
| 498 | "Rev = 0x%02X, " |
Larry Johnson | 966a80b | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 499 | "%3dbase%s, %s\n", |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 500 | j, oui, model, rev, |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 501 | miiphy_speed (devname, j), |
Larry Johnson | 966a80b | 2007-11-01 08:46:50 -0500 | [diff] [blame] | 502 | miiphy_is_1000base_x (devname, j) |
| 503 | ? "X" : "T", |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 504 | (miiphy_duplex (devname, j) == FULL) |
| 505 | ? "FDX" : "HDX"); |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 508 | } else if (op[0] == 'r') { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 509 | for (addr = addrlo; addr <= addrhi; addr++) { |
| 510 | for (reg = reglo; reg <= reghi; reg++) { |
| 511 | data = 0xffff; |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 512 | if (miiphy_read (devname, addr, reg, &data) != 0) { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 513 | printf( |
| 514 | "Error reading from the PHY addr=%02x reg=%02x\n", |
| 515 | addr, reg); |
| 516 | rcode = 1; |
Wolfgang Denk | edb6548 | 2005-09-24 21:54:50 +0200 | [diff] [blame] | 517 | } else { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 518 | if ((addrlo != addrhi) || (reglo != reghi)) |
| 519 | printf("addr=%02x reg=%02x data=", |
| 520 | (uint)addr, (uint)reg); |
| 521 | printf("%04X\n", data & 0x0000FFFF); |
| 522 | } |
| 523 | } |
| 524 | if ((addrlo != addrhi) && (reglo != reghi)) |
| 525 | printf("\n"); |
| 526 | } |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 527 | } else if (op[0] == 'w') { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 528 | for (addr = addrlo; addr <= addrhi; addr++) { |
| 529 | for (reg = reglo; reg <= reghi; reg++) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 530 | if (miiphy_write (devname, addr, reg, data) != 0) { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 531 | printf("Error writing to the PHY addr=%02x reg=%02x\n", |
| 532 | addr, reg); |
| 533 | rcode = 1; |
| 534 | } |
| 535 | } |
| 536 | } |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 537 | } else if (strncmp(op, "du", 2) == 0) { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 538 | ushort regs[6]; |
| 539 | int ok = 1; |
| 540 | if ((reglo > 5) || (reghi > 5)) { |
| 541 | printf( |
| 542 | "The MII dump command only formats the " |
| 543 | "standard MII registers, 0-5.\n"); |
| 544 | return 1; |
| 545 | } |
| 546 | for (addr = addrlo; addr <= addrhi; addr++) { |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 547 | for (reg = reglo; reg < reghi + 1; reg++) { |
| 548 | if (miiphy_read(devname, addr, reg, ®s[reg]) != 0) { |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 549 | ok = 0; |
| 550 | printf( |
| 551 | "Error reading from the PHY addr=%02x reg=%02x\n", |
| 552 | addr, reg); |
| 553 | rcode = 1; |
| 554 | } |
| 555 | } |
| 556 | if (ok) |
| 557 | MII_dump_0_to_5(regs, reglo, reghi); |
| 558 | printf("\n"); |
| 559 | } |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 560 | } else if (strncmp(op, "de", 2) == 0) { |
| 561 | if (argc == 2) |
| 562 | miiphy_listdev (); |
| 563 | else |
| 564 | miiphy_set_current_dev (argv[2]); |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 565 | } else { |
| 566 | printf("Usage:\n%s\n", cmdtp->usage); |
| 567 | return 1; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Save the parameters for repeats. |
| 572 | */ |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 573 | last_op[0] = op[0]; |
| 574 | last_op[1] = op[1]; |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 575 | last_addr_lo = addrlo; |
| 576 | last_addr_hi = addrhi; |
| 577 | last_reg_lo = reglo; |
| 578 | last_reg_hi = reghi; |
| 579 | last_data = data; |
| 580 | |
| 581 | return rcode; |
| 582 | } |
| 583 | |
| 584 | /***************************************************/ |
| 585 | |
| 586 | U_BOOT_CMD( |
| 587 | mii, 5, 1, do_mii, |
| 588 | "mii - MII utility commands\n", |
Marian Balakowicz | aab8c49 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 589 | "device - list available devices\n" |
| 590 | "mii device <devname> - set current device\n" |
| 591 | "mii info <addr> - display MII PHY info\n" |
| 592 | "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n" |
| 593 | "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n" |
| 594 | "mii dump <addr> <reg> - pretty-print <addr> <reg> (0-5 only)\n" |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 595 | "Addr and/or reg may be ranges, e.g. 2-7.\n" |
| 596 | ); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 597 | |
wdenk | 61066ec | 2004-04-18 22:57:51 +0000 | [diff] [blame] | 598 | #endif /* CONFIG_TERSE_MII */ |