1 /* 2 * This program is distributed in the hope that it will be useful, 3 * but WITHOUT ANY WARRANTY; without even the implied warranty of 4 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5 * GNU General Public License for more details. 6 * 7 * You should have received a copy of the GNU General Public License 8 * along with this program; if not, write to the Free Software 9 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 10 */ 11 12 13 #include <common.h> 14 #include <command.h> 15 16 #include "swfunc.h" 17 #include "comminf.h" 18 #include "mem_io.h" 19 #include "mac_api.h" 20 21 extern int mac_test(int argc, char * const argv[], uint32_t mode); 22 23 int do_mactest (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 24 { 25 display_lantest_log_msg = 0; 26 return mac_test(argc, argv, MODE_DEDICATED); 27 } 28 29 int do_ncsitest (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 30 { 31 display_lantest_log_msg = 0; 32 return mac_test(argc, argv, MODE_NCSI); 33 } 34 35 U_BOOT_CMD(mactest, NETESTCMD_MAX_ARGS, 0, do_mactest, 36 "Dedicated LAN test program", NULL); 37 U_BOOT_CMD(ncsitest, NETESTCMD_MAX_ARGS, 0, do_ncsitest, 38 "Share LAN (NC-SI) test program", NULL); 39 40 // ------------------------------------------------------------------------------ 41 int do_mactestd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 42 { 43 display_lantest_log_msg = 1; 44 return mac_test(argc, argv, MODE_DEDICATED); 45 } 46 47 int do_ncsitestd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 48 { 49 display_lantest_log_msg = 1; 50 return mac_test(argc, argv, MODE_NCSI); 51 } 52 53 U_BOOT_CMD(mactestd, NETESTCMD_MAX_ARGS, 0, do_mactestd, 54 "Dedicated LAN test program and display more information", NULL); 55 U_BOOT_CMD(ncsitestd, NETESTCMD_MAX_ARGS, 0, do_ncsitestd, 56 "Share LAN (NC-SI) test program and display more information", NULL); 57 58 // ------------------------------------------------------------------------------ 59 #if 0 60 void multi_pin_2_mdcmdio_init( MAC_ENGINE *eng ) 61 { 62 #if defined(CONFIG_ASPEED_AST2500) 63 switch (eng->run.mdio_idx) { 64 case 0: 65 SCU_WR((SCU_RD(0x088) | 0xC0000000), 0x88); 66 break; 67 case 1: 68 SCU_WR((SCU_RD(0x090) | 0x00000004), 0x90); 69 break; 70 default: 71 break; 72 } 73 #endif 74 } 75 76 int do_phyread (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 77 { 78 MAC_ENGINE MACENG; 79 MAC_ENGINE *eng; 80 int MACnum; 81 int PHYreg; 82 uint32_t result_data; 83 int ret = 0; 84 int PHYaddr; 85 int timeout = 0; 86 uint32_t MAC_040; 87 88 eng = &MACENG; 89 do { 90 if (argc != 4) { 91 printf(" Wrong parameter number.\n"); 92 printf(" phyr mac addr reg\n"); 93 printf(" mac : 0 or 1. [hex]\n"); 94 printf(" PHY addr: 0 to 0x1F.[hex]\n"); 95 printf(" register: 0 to 0xFF.[hex]\n"); 96 printf(" example: phyr 0 0 1\n"); 97 ret = -1; 98 break; 99 } 100 101 MACnum = simple_strtoul(argv[1], NULL, 16); 102 PHYaddr = simple_strtoul(argv[2], NULL, 16); 103 PHYreg = simple_strtoul(argv[3], NULL, 16); 104 105 if (MACnum == 0) { 106 // Set MAC 0 107 eng->run.mac_base = MAC1_BASE; 108 eng->run.mdio_idx = 0; 109 } else if (MACnum == 1) { 110 // Set MAC 1 111 eng->run.mac_base = MAC2_BASE; 112 eng->run.mdio_idx = 1; 113 } else { 114 printf("wrong parameter (mac number)\n"); 115 ret = -1; 116 break; 117 } 118 119 if ((PHYaddr < 0) || (PHYaddr > 31)) { 120 printf("wrong parameter (PHY address)\n"); 121 ret = -1; 122 break; 123 } 124 125 multi_pin_2_mdcmdio_init(eng); 126 MAC_040 = mac_reg_read(eng, 0x40); 127 #ifdef CONFIG_ASPEED_AST2600 128 eng->env.is_new_mdio_reg[MACnum] = 1; 129 #else 130 eng->env.is_new_mdio_reg[MACnum] = (MAC_040 & 0x80000000) ? 1 : 0; 131 #endif 132 133 if (eng->env.is_new_mdio_reg[MACnum]) { 134 #ifdef CONFIG_ASPEED_AST2600 135 mac_reg_write(eng, 0x60, 136 MAC_PHYRd_New | (PHYaddr << 21) | 137 ((PHYreg & 0x1f) << 16)); 138 while (mac_reg_read(eng, 0x60) & 139 MAC_PHYBusy_New) { 140 #else 141 mac_reg_write(eng, 0x60, 142 MAC_PHYRd_New | (PHYaddr << 5) | 143 (PHYreg & 0x1f)); 144 while (mac_reg_read(eng, 0x60) & MAC_PHYBusy_New) { 145 #endif 146 if (++timeout > TIME_OUT_PHY_RW) { 147 ret = -1; 148 break; 149 } 150 } 151 #ifdef Delay_PHYRd 152 DELAY(Delay_PHYRd); 153 #endif 154 result_data = mac_reg_read(eng, 0x64) & 0xffff; 155 } else { 156 mac_reg_write(eng, 0x60, 157 MDC_Thres | MAC_PHYRd | 158 (PHYaddr << 16) | 159 ((PHYreg & 0x1f) << 21)); 160 while (mac_reg_read(eng, 0x60) & MAC_PHYRd) { 161 if (++timeout > TIME_OUT_PHY_RW) { 162 ret = -1; 163 break; 164 } 165 } 166 #ifdef Delay_PHYRd 167 DELAY(Delay_PHYRd); 168 #endif 169 result_data = mac_reg_read(eng, 0x64) >> 16; 170 } 171 printf(" PHY[%d] reg[0x%02X] = %04x\n", PHYaddr, PHYreg, 172 result_data); 173 } while (0); 174 175 return ret; 176 } 177 178 int do_phywrite (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 179 { 180 MAC_ENGINE MACENG; 181 MAC_ENGINE *eng; 182 uint32_t MACnum; 183 int PHYreg; 184 int PHYaddr; 185 uint32_t reg_data; 186 int ret = 0; 187 int timeout = 0; 188 uint32_t MAC_040; 189 190 eng = &MACENG; 191 192 do { 193 if ( argc != 5 ) 194 { 195 printf(" Wrong parameter number.\n"); 196 printf(" phyw mac addr reg data\n"); 197 printf(" mac : 0 or 1. [hex]\n"); 198 printf(" PHY addr: 0 to 0x1F. [hex]\n"); 199 printf(" register: 0 to 0xFF. [hex]\n"); 200 printf(" data : 0 to 0xFFFF.[hex]\n"); 201 printf(" example: phyw 0 0 0 610\n"); 202 ret = -1; 203 break; 204 } 205 206 MACnum = strtoul(argv[1], NULL, 16); 207 PHYaddr = strtoul(argv[2], NULL, 16); 208 PHYreg = strtoul(argv[3], NULL, 16); 209 reg_data = strtoul(argv[4], NULL, 16); 210 211 if ( MACnum == 0 ) { 212 // Set MAC 0 213 eng->run.mac_base = MAC1_BASE; 214 eng->run.mdio_idx = 0; 215 } 216 else if ( MACnum == 1 ) { 217 // Set MAC 1 218 eng->run.mac_base = MAC2_BASE; 219 eng->run.mdio_idx = 1; 220 } 221 else { 222 printf("wrong parameter (mac number)\n"); 223 ret = -1; 224 break; 225 } 226 227 if ( ( PHYaddr < 0 ) || ( PHYaddr > 31 ) ) { 228 printf("wrong parameter (PHY address)\n"); 229 ret = -1; 230 break; 231 } 232 233 multi_pin_2_mdcmdio_init( eng ); 234 MAC_040 = mac_reg_read( eng, 0x40 ); 235 #ifdef CONFIG_ASPEED_AST2600 236 eng->env.is_new_mdio_reg[MACnum] = 1; 237 #else 238 eng->env.is_new_mdio_reg[MACnum] = (MAC_040 & 0x80000000) ? 1 : 0; 239 #endif 240 241 if (eng->env.is_new_mdio_reg[MACnum]) { 242 #ifdef CONFIG_ASPEED_AST2600 243 mac_reg_write( eng, 0x60, reg_data | MAC_PHYWr_New | (PHYaddr<<21) | ((PHYreg & 0x1f)<<16) ); 244 245 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYBusy_New ) { 246 #else 247 mac_reg_write( eng, 0x60, ( reg_data << 16 ) | MAC_PHYWr_New | (PHYaddr<<5) | (PHYreg & 0x1f) ); 248 249 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYBusy_New ) { 250 #endif 251 if ( ++timeout > TIME_OUT_PHY_RW ) { 252 ret = -1; 253 break; 254 } 255 } 256 } 257 else { 258 mac_reg_write( eng, 0x64, reg_data ); 259 mac_reg_write( eng, 0x60, MDC_Thres | MAC_PHYWr | (PHYaddr<<16) | ((PHYreg & 0x1f) << 21) ); 260 261 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYWr ) { 262 if ( ++timeout > TIME_OUT_PHY_RW ) { 263 ret = -1; 264 break; 265 } 266 } 267 } // End if (eng->env.new_mdio_reg) 268 269 printf("Write: PHY[%d] reg[0x%02X] = %04x\n", PHYaddr, PHYreg, reg_data ); 270 } while ( 0 ); 271 272 return ret; 273 } 274 275 int do_phydump (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) 276 { 277 MAC_ENGINE MACENG; 278 MAC_ENGINE *eng; 279 int MACnum; 280 int PHYreg; 281 uint32_t result_data; 282 int ret = 0; 283 int PHYaddr; 284 int timeout = 0; 285 uint32_t MAC_040; 286 287 eng = &MACENG; 288 do { 289 if ( argc != 3 ) { 290 printf(" Wrong parameter number.\n"); 291 printf(" phyd mac addr\n"); 292 printf(" mac : 0 or 1. [hex]\n"); 293 printf(" PHY addr: 0 to 0x1F.[hex]\n"); 294 printf(" example: phyd 0 0\n"); 295 ret = -1; 296 break; 297 } 298 299 MACnum = strtoul(argv[1], NULL, 16); 300 PHYaddr = strtoul(argv[2], NULL, 16); 301 302 if ( MACnum == 0 ) { 303 // Set MAC 0 304 eng->run.mac_base = MAC1_BASE; 305 eng->run.mdio_idx = 0; 306 } 307 else if ( MACnum == 1 ) { 308 // Set MAC 1 309 eng->run.mac_base = MAC2_BASE; 310 eng->run.mdio_idx = 1; 311 } 312 else { 313 printf("wrong parameter (mac number)\n"); 314 ret = -1; 315 break; 316 } 317 318 if ( ( PHYaddr < 0 ) || ( PHYaddr > 31 ) ) { 319 printf("wrong parameter (PHY address)\n"); 320 ret = -1; 321 break; 322 } 323 324 multi_pin_2_mdcmdio_init( eng ); 325 MAC_040 = mac_reg_read( eng, 0x40 ); 326 #ifdef CONFIG_ASPEED_AST2600 327 eng->env.is_new_mdio_reg[MACnum] = 1; 328 #else 329 eng->env.is_new_mdio_reg[MACnum] = (MAC_040 & 0x80000000) ? 1 : 0; 330 #endif 331 332 if (eng->env.is_new_mdio_reg[MACnum]) { 333 for ( PHYreg = 0; PHYreg < 32; PHYreg++ ) { 334 #ifdef CONFIG_ASPEED_AST2600 335 mac_reg_write( eng, 0x60, MAC_PHYRd_New | (PHYaddr << 21) | (( PHYreg & 0x1f ) << 16) ); 336 337 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYBusy_New ) { 338 #else 339 mac_reg_write( eng, 0x60, MAC_PHYRd_New | (PHYaddr << 5) | ( PHYreg & 0x1f ) ); 340 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYBusy_New ) { 341 #endif 342 if ( ++timeout > TIME_OUT_PHY_RW ) { 343 ret = -1; 344 break; 345 } 346 } 347 #ifdef Delay_PHYRd 348 DELAY( Delay_PHYRd ); 349 #endif 350 result_data = mac_reg_read( eng, 0x64 ) & 0xffff; 351 switch ( PHYreg % 4 ) { 352 case 0 : printf("%02d| %04x ", PHYreg, result_data ); break; 353 case 3 : printf("%04x\n", result_data ); break; 354 default : printf("%04x ", result_data ); break; 355 } 356 } 357 } 358 else { 359 for ( PHYreg = 0; PHYreg < 32; PHYreg++ ) { 360 mac_reg_write( eng, 0x60, MDC_Thres | MAC_PHYRd | (PHYaddr << 16) | ((PHYreg & 0x1f) << 21) ); 361 while ( mac_reg_read( eng, 0x60 ) & MAC_PHYRd ) { 362 if ( ++timeout > TIME_OUT_PHY_RW ) { 363 ret = -1; 364 break; 365 } 366 } 367 #ifdef Delay_PHYRd 368 DELAY( Delay_PHYRd ); 369 #endif 370 result_data = mac_reg_read( eng, 0x64 ) >> 16; 371 switch ( PHYreg % 4 ) { 372 case 0 : printf("%02d| %04x ", PHYreg, result_data ); break; 373 case 3 : printf("%04x\n", result_data ); break; 374 default : printf("%04x ", result_data ); break; 375 } 376 } 377 } 378 } while ( 0 ); 379 380 return ret; 381 } 382 383 U_BOOT_CMD( 384 phyr, NETESTCMD_MAX_ARGS, 0, do_phyread, 385 "Read PHY register. (phyr mac addr reg)", 386 NULL 387 ); 388 389 U_BOOT_CMD( 390 phyw, NETESTCMD_MAX_ARGS, 0, do_phywrite, 391 "Write PHY register. (phyw mac addr reg data)", 392 NULL 393 ); 394 395 U_BOOT_CMD( 396 phyd, NETESTCMD_MAX_ARGS, 0, do_phydump, 397 "Dump PHY register. (phyd mac addr)", 398 NULL 399 ); 400 401 // ------------------------------------------------------------------------------ 402 int do_macgpio (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) 403 { 404 GPIO_WR(GPIO_RD( 0x78 ) & 0xf7bfffff, 0x78); 405 GPIO_WR(GPIO_RD( 0x7c ) | 0x08400000, 0x7c); 406 DELAY( 100 ); 407 GPIO_WR(GPIO_RD( 0x78 ) | 0x08400000, 0x78); 408 409 return 0; 410 } 411 412 U_BOOT_CMD( 413 macgpio, NETESTCMD_MAX_ARGS, 0, do_macgpio, 414 "Setting GPIO to trun on the system for the MACTEST/NCSITEST (OEM)", 415 NULL 416 ); 417 #endif 418 /* 419 int do_clkduty (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) 420 { 421 int temp; 422 int i; 423 char *re[10]; 424 425 temp = strtoul(argv[1], NULL, 16); 426 for ( i = 1; i < argc; i++ ) 427 { 428 re[i] = argv[i + 1]; 429 printf("arg[%d]= %s\n", i , re[i]); 430 } 431 argc--; 432 433 SCU_WR(0, 0x1DC); 434 mac_test( argc, re, MODE_DEDICATED ); 435 printf("SCU1DC= %x\n", SCU_RD(0x1DC) ); 436 437 for ( i = 0; i < 64; i += temp ) 438 { 439 SCU_WR((((uint32_t)(i + 0x40) << 16) | ((uint32_t)(i + 0x40) << 440 8) ), 0x1DC); 441 442 printf("SCU1DC= %x [%x]\n", SCU_RD(0x1DC) , (uint32_t)temp ); 443 mac_test( argc, re, MODE_DEDICATED ); 444 } 445 446 return 0; 447 } 448 449 U_BOOT_CMD( 450 clkduty, NETESTCMD_MAX_ARGS, 0, do_clkduty, 451 "clkduty", 452 NULL 453 ); 454 */ 455