cmd_katmai.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  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. #include <common.h>
  25. #include <command.h>
  26. #include <i2c.h>
  27. #include <asm/byteorder.h>
  28. static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  29. {
  30. uchar chip;
  31. ulong data;
  32. int nbytes;
  33. extern char console_buffer[];
  34. char sysClock[4];
  35. char cpuClock[4];
  36. char plbClock[4];
  37. char pcixClock[4];
  38. if (argc < 3) {
  39. printf ("Usage:\n%s\n", cmdtp->usage);
  40. return 1;
  41. }
  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 = 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 = 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 = 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 = 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 = %sMhz\n", sysClock);
  135. printf("cpu clk = %sMhz\n", cpuClock);
  136. printf("plb clk = %sMhz\n", plbClock);
  137. printf("Pci-X clk = %sMhz\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 = 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 |= 0x05950000;
  201. else
  202. 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. bootstrap, 3, 1, do_bootstrap,
  213. "bootstrap - program the serial device strap\n",
  214. "wrclk [prom0|prom1] - program the serial device strap\n"
  215. );