cmd_mii.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #if defined(CONFIG_8xx) || defined(CONFIG_MCF52x2)
  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. unsigned char j, start, end;
  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. if (argc >= 3) {
  82. start = addr; end = addr + 1;
  83. } else {
  84. start = 0; end = 32;
  85. }
  86. for (j = start; j < end; j++) {
  87. if (miiphy_info (j, &oui, &model, &rev) == 0) {
  88. printf ("PHY 0x%02X: "
  89. "OUI = 0x%04X, "
  90. "Model = 0x%02X, "
  91. "Rev = 0x%02X, "
  92. "%3dbaseT, %s\n",
  93. j, oui, model, rev,
  94. miiphy_speed (j) == _100BASET ? 100 : 10,
  95. miiphy_duplex (j) == FULL ? "FDX" : "HDX");
  96. }
  97. }
  98. } else if (op == 'r') {
  99. if (miiphy_read (addr, reg, &data) != 0) {
  100. printf ("Error reading from the PHY\n");
  101. rcode = 1;
  102. }
  103. printf ("%04X\n", data & 0x0000FFFF);
  104. } else if (op == 'w') {
  105. if (miiphy_write (addr, reg, data) != 0) {
  106. printf ("Error writing to the PHY\n");
  107. rcode = 1;
  108. }
  109. } else {
  110. printf ("Usage:\n%s\n", cmdtp->usage);
  111. return 1;
  112. }
  113. /*
  114. * Save the parameters for repeats.
  115. */
  116. last_op = op;
  117. last_addr = addr;
  118. last_data = data;
  119. return rcode;
  120. }
  121. /***************************************************/
  122. U_BOOT_CMD(
  123. mii, 5, 1, do_mii,
  124. "mii - MII utility commands\n",
  125. "info <addr> - display MII PHY info\n"
  126. "mii read <addr> <reg> - read MII PHY <addr> register <reg>\n"
  127. "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg>\n"
  128. );
  129. #endif /* CFG_CMD_MII */