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 | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 30 | #include <miiphy.h> |
| 31 | |
| 32 | #if (CONFIG_COMMANDS & CFG_CMD_MII) |
| 33 | |
| 34 | /* |
| 35 | * Display values from last command. |
| 36 | */ |
| 37 | uint last_op; |
| 38 | uint last_addr; |
| 39 | uint last_data; |
| 40 | uint last_reg; |
| 41 | |
| 42 | /* |
| 43 | * MII read/write |
| 44 | * |
| 45 | * Syntax: |
| 46 | * mii read {addr} {reg} |
| 47 | * mii write {addr} {reg} {data} |
| 48 | */ |
| 49 | |
| 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; |
| 56 | |
wdenk | d126bfb | 2003-04-10 11:18:18 +0000 | [diff] [blame] | 57 | #ifdef CONFIG_8xx |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 58 | 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 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | /***************************************************/ |
| 131 | |
| 132 | cmd_tbl_t U_BOOT_CMD(MII) = MK_CMD_ENTRY( |
| 133 | "mii", 5, 1, do_mii, |
| 134 | "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 | |
wdenk | dd7d41f | 2002-09-18 20:04:01 +0000 | [diff] [blame] | 141 | #endif /* CFG_CMD_MII */ |