cmd_yucca.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * (C) Copyright 2001
  3. * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * hacked for evb440spe
  8. */
  9. #include <common.h>
  10. #include <cli.h>
  11. #include <command.h>
  12. #include <console.h>
  13. #include "yucca.h"
  14. #include <i2c.h>
  15. #include <asm/byteorder.h>
  16. extern void print_evb440spe_info(void);
  17. static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
  18. int flag, int argc, char * const argv[]);
  19. /* ------------------------------------------------------------------------- */
  20. int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  21. {
  22. return setBootStrapClock (cmdtp, 1, flag, argc, argv);
  23. }
  24. /* ------------------------------------------------------------------------- */
  25. /* Modify memory.
  26. *
  27. * Syntax:
  28. * evb440spe wrclk prom0,prom1
  29. */
  30. static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
  31. int argc, char * const argv[])
  32. {
  33. uchar chip;
  34. ulong data;
  35. int nbytes;
  36. char sysClock[4];
  37. char cpuClock[4];
  38. char plbClock[4];
  39. char pcixClock[4];
  40. if (argc < 3)
  41. return cmd_usage(cmdtp);
  42. if (strcmp(argv[2], "prom0") == 0)
  43. chip = IIC0_BOOTPROM_ADDR;
  44. else
  45. chip = IIC0_ALT_BOOTPROM_ADDR;
  46. do {
  47. printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
  48. nbytes = cli_readline(" ? ");
  49. if (strcmp(console_buffer, "quit") == 0)
  50. return 0;
  51. if ((strcmp(console_buffer, "33") != 0) &
  52. (strcmp(console_buffer, "66") != 0))
  53. nbytes=0;
  54. strcpy(sysClock, console_buffer);
  55. } while (nbytes == 0);
  56. do {
  57. if (strcmp(sysClock, "66") == 0) {
  58. printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
  59. } else {
  60. #ifdef CONFIG_STRESS
  61. printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
  62. #else
  63. printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
  64. #endif
  65. }
  66. nbytes = cli_readline(" ? ");
  67. if (strcmp(console_buffer, "quit") == 0)
  68. return 0;
  69. if (strcmp(sysClock, "66") == 0) {
  70. if ((strcmp(console_buffer, "400") != 0) &
  71. (strcmp(console_buffer, "533") != 0)
  72. #ifdef CONFIG_STRESS
  73. & (strcmp(console_buffer, "667") != 0)
  74. #endif
  75. ) {
  76. nbytes = 0;
  77. }
  78. } else {
  79. if ((strcmp(console_buffer, "400") != 0) &
  80. (strcmp(console_buffer, "500") != 0) &
  81. (strcmp(console_buffer, "533") != 0)
  82. #ifdef CONFIG_STRESS
  83. & (strcmp(console_buffer, "667") != 0)
  84. #endif
  85. ) {
  86. nbytes = 0;
  87. }
  88. }
  89. strcpy(cpuClock, console_buffer);
  90. } while (nbytes == 0);
  91. if (strcmp(cpuClock, "500") == 0){
  92. strcpy(plbClock, "166");
  93. } else if (strcmp(cpuClock, "533") == 0){
  94. strcpy(plbClock, "133");
  95. } else {
  96. do {
  97. if (strcmp(cpuClock, "400") == 0)
  98. printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
  99. #ifdef CONFIG_STRESS
  100. if (strcmp(cpuClock, "667") == 0)
  101. printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
  102. #endif
  103. nbytes = cli_readline(" ? ");
  104. if (strcmp(console_buffer, "quit") == 0)
  105. return 0;
  106. if (strcmp(cpuClock, "400") == 0) {
  107. if ((strcmp(console_buffer, "100") != 0) &
  108. (strcmp(console_buffer, "133") != 0))
  109. nbytes = 0;
  110. }
  111. #ifdef CONFIG_STRESS
  112. if (strcmp(cpuClock, "667") == 0) {
  113. if ((strcmp(console_buffer, "133") != 0) &
  114. (strcmp(console_buffer, "166") != 0))
  115. nbytes = 0;
  116. }
  117. #endif
  118. strcpy(plbClock, console_buffer);
  119. } while (nbytes == 0);
  120. }
  121. do {
  122. printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
  123. nbytes = cli_readline(" ? ");
  124. if (strcmp(console_buffer, "quit") == 0)
  125. return 0;
  126. if ((strcmp(console_buffer, "33") != 0) &
  127. (strcmp(console_buffer, "66") != 0) &
  128. (strcmp(console_buffer, "100") != 0) &
  129. (strcmp(console_buffer, "133") != 0)) {
  130. nbytes = 0;
  131. }
  132. strcpy(pcixClock, console_buffer);
  133. } while (nbytes == 0);
  134. printf("\nsys clk = %s MHz\n", sysClock);
  135. printf("cpu clk = %s MHz\n", cpuClock);
  136. printf("plb clk = %s MHz\n", plbClock);
  137. printf("Pci-X clk = %s MHz\n", pcixClock);
  138. do {
  139. printf("\npress [y] to write I2C bootstrap\n");
  140. printf("or [n] to abort.\n");
  141. printf("Don't forget to set board switches\n");
  142. printf("according to your choice before re-starting\n");
  143. printf("(refer to 440spe_uboot_kit_um_1_01.pdf)\n");
  144. nbytes = cli_readline(" ? ");
  145. if (strcmp(console_buffer, "n") == 0)
  146. return 0;
  147. } while (nbytes == 0);
  148. if (strcmp(sysClock, "33") == 0) {
  149. if ((strcmp(cpuClock, "400") == 0) &
  150. (strcmp(plbClock, "100") == 0))
  151. data = 0x8678c206;
  152. if ((strcmp(cpuClock, "400") == 0) &
  153. (strcmp(plbClock, "133") == 0))
  154. data = 0x8678c2c6;
  155. if ((strcmp(cpuClock, "500") == 0))
  156. data = 0x8778f2c6;
  157. if ((strcmp(cpuClock, "533") == 0))
  158. data = 0x87790252;
  159. #ifdef CONFIG_STRESS
  160. if ((strcmp(cpuClock, "667") == 0) &
  161. (strcmp(plbClock, "133") == 0))
  162. data = 0x87794256;
  163. if ((strcmp(cpuClock, "667") == 0) &
  164. (strcmp(plbClock, "166") == 0))
  165. data = 0x87794206;
  166. #endif
  167. }
  168. if (strcmp(sysClock, "66") == 0) {
  169. if ((strcmp(cpuClock, "400") == 0) &
  170. (strcmp(plbClock, "100") == 0))
  171. data = 0x84706206;
  172. if ((strcmp(cpuClock, "400") == 0) &
  173. (strcmp(plbClock, "133") == 0))
  174. data = 0x847062c6;
  175. if ((strcmp(cpuClock, "533") == 0))
  176. data = 0x85708206;
  177. #ifdef CONFIG_STRESS
  178. if ((strcmp(cpuClock, "667") == 0) &
  179. (strcmp(plbClock, "133") == 0))
  180. data = 0x8570a256;
  181. if ((strcmp(cpuClock, "667") == 0) &
  182. (strcmp(plbClock, "166") == 0))
  183. data = 0x8570a206;
  184. #endif
  185. }
  186. #ifdef DEBUG
  187. printf(" pin strap0 to write in i2c = %x\n", data);
  188. #endif /* DEBUG */
  189. if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
  190. printf("Error writing strap0 in %s\n", argv[2]);
  191. if (strcmp(pcixClock, "33") == 0)
  192. data = 0x00000701;
  193. if (strcmp(pcixClock, "66") == 0)
  194. data = 0x00000601;
  195. if (strcmp(pcixClock, "100") == 0)
  196. data = 0x00000501;
  197. if (strcmp(pcixClock, "133") == 0)
  198. data = 0x00000401;
  199. if (strcmp(plbClock, "166") == 0)
  200. data = data | 0x05950000;
  201. else
  202. data = data | 0x05A50000;
  203. #ifdef DEBUG
  204. printf(" pin strap1 to write in i2c = %x\n", data);
  205. #endif /* DEBUG */
  206. udelay(1000);
  207. if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
  208. printf("Error writing strap1 in %s\n", argv[2]);
  209. return 0;
  210. }
  211. U_BOOT_CMD(
  212. evb440spe, 3, 1, do_evb440spe,
  213. "program the serial device strap",
  214. "wrclk [prom0|prom1] - program the serial device strap"
  215. );