cmd_vcma9.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * (C) Copyright 2002
  3. * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
  4. *
  5. * adapted for VCMA9
  6. * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. *
  26. */
  27. #include <common.h>
  28. #include <command.h>
  29. #include "vcma9.h"
  30. #include "../common/common_util.h"
  31. #if defined(CONFIG_DRIVER_CS8900)
  32. #include <../drivers/cs8900.h>
  33. static uchar cs8900_chksum(ushort data)
  34. {
  35. return((data >> 8) & 0x00FF) + (data & 0x00FF);
  36. }
  37. #endif
  38. extern void print_vcma9_info(void);
  39. extern int vcma9_cantest(void);
  40. extern int vcma9_nandtest(void);
  41. extern int vcma9_dactest(void);
  42. extern int do_mplcommon(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  43. /* ------------------------------------------------------------------------- */
  44. int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  45. {
  46. DECLARE_GLOBAL_DATA_PTR;
  47. if (strcmp(argv[1], "info") == 0)
  48. {
  49. print_vcma9_info();
  50. return 0;
  51. }
  52. #if defined(CONFIG_DRIVER_CS8900)
  53. if (strcmp(argv[1], "cs8900_eeprom") == 0) {
  54. if (strcmp(argv[2], "read") == 0) {
  55. uchar addr; ushort data;
  56. addr = simple_strtoul(argv[3], NULL, 16);
  57. cs8900_e2prom_read(addr, &data);
  58. printf("0x%2.2X: 0x%4.4X\n", addr, data);
  59. } else if (strcmp(argv[2], "write") == 0) {
  60. uchar addr; ushort data;
  61. addr = simple_strtoul(argv[3], NULL, 16);
  62. data = simple_strtoul(argv[4], NULL, 16);
  63. cs8900_e2prom_write(addr, data);
  64. } else if (strcmp(argv[2], "setaddr") == 0) {
  65. uchar addr, i, csum; ushort data;
  66. /* check for valid ethaddr */
  67. for (i = 0; i < 6; i++)
  68. if (gd->bd->bi_enetaddr[i] != 0)
  69. break;
  70. if (i < 6) {
  71. addr = 1;
  72. data = 0x2158;
  73. cs8900_e2prom_write(addr, data);
  74. csum = cs8900_chksum(data);
  75. addr++;
  76. for (i = 0; i < 6; i+=2) {
  77. data = gd->bd->bi_enetaddr[i+1] << 8 |
  78. gd->bd->bi_enetaddr[i];
  79. cs8900_e2prom_write(addr, data);
  80. csum += cs8900_chksum(data);
  81. addr++;
  82. }
  83. /* calculate header link byte */
  84. data = 0xA100 | (addr * 2);
  85. cs8900_e2prom_write(0, data);
  86. csum += cs8900_chksum(data);
  87. /* write checksum word */
  88. cs8900_e2prom_write(addr, (0 - csum) << 8);
  89. } else {
  90. printf("\nplease defined 'ethaddr'\n");
  91. }
  92. } else if (strcmp(argv[2], "dump") == 0) {
  93. uchar addr, endaddr, csum; ushort data;
  94. printf("Dump of CS8900 config device: ");
  95. cs8900_e2prom_read(addr, &data);
  96. if ((data & 0xE000) == 0xA000) {
  97. endaddr = (data & 0x00FF) / 2;
  98. csum = cs8900_chksum(data);
  99. for (addr = 1; addr <= endaddr; addr++) {
  100. cs8900_e2prom_read(addr, &data);
  101. printf("\n0x%2.2X: 0x%4.4X", addr, data);
  102. csum += cs8900_chksum(data);
  103. }
  104. printf("\nChecksum: %s", (csum == 0) ? "ok" : "wrong");
  105. } else {
  106. printf("no valid config found");
  107. }
  108. printf("\n");
  109. }
  110. return 0;
  111. }
  112. #endif
  113. #if 0
  114. if (strcmp(argv[1], "cantest") == 0) {
  115. vcma9_cantest();
  116. return 0;
  117. }
  118. if (strcmp(argv[1], "nandtest") == 0) {
  119. vcma9_nandtest();
  120. return 0;
  121. }
  122. if (strcmp(argv[1], "dactest") == 0) {
  123. vcma9_dactest();
  124. return 0;
  125. }
  126. #endif
  127. return (do_mplcommon(cmdtp, flag, argc, argv));
  128. }