cmd_mii.c 3.1 KB

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