cmd_katmai.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. #define CONFIG_STRESS /* enable 667 MHz CPU freq selection */
  29. #define DEBUG
  30. static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  31. {
  32. uchar chip;
  33. ulong data;
  34. int nbytes;
  35. extern char console_buffer[];
  36. char sysClock[4];
  37. char cpuClock[4];
  38. char plbClock[4];
  39. char pcixClock[4];
  40. if (argc < 3) {
  41. cmd_usage(cmdtp);
  42. return 1;
  43. }
  44. if (strcmp(argv[2], "prom0") == 0)
  45. chip = IIC0_BOOTPROM_ADDR;
  46. else
  47. chip = IIC0_ALT_BOOTPROM_ADDR;
  48. /* on Katmai SysClk is always 33MHz */
  49. strcpy(sysClock, "33");
  50. do {
  51. #ifdef CONFIG_STRESS
  52. printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
  53. #else
  54. printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
  55. #endif
  56. nbytes = readline (" ? ");
  57. if (strcmp(console_buffer, "quit") == 0)
  58. return 0;
  59. if ((strcmp(console_buffer, "400") != 0) &&
  60. (strcmp(console_buffer, "500") != 0) &&
  61. (strcmp(console_buffer, "533") != 0)
  62. #ifdef CONFIG_STRESS
  63. && (strcmp(console_buffer, "667") != 0)
  64. #endif
  65. ) {
  66. nbytes = 0;
  67. }
  68. strcpy(cpuClock, console_buffer);
  69. } while (nbytes == 0);
  70. if (strcmp(cpuClock, "500") == 0)
  71. strcpy(plbClock, "166");
  72. else if (strcmp(cpuClock, "533") == 0)
  73. strcpy(plbClock, "133");
  74. else {
  75. do {
  76. if (strcmp(cpuClock, "400") == 0)
  77. printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
  78. #ifdef CONFIG_STRESS
  79. if (strcmp(cpuClock, "667") == 0)
  80. printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
  81. #endif
  82. nbytes = readline (" ? ");
  83. if (strcmp(console_buffer, "quit") == 0)
  84. return 0;
  85. if (strcmp(cpuClock, "400") == 0) {
  86. if ((strcmp(console_buffer, "100") != 0) &&
  87. (strcmp(console_buffer, "133") != 0))
  88. nbytes = 0;
  89. }
  90. #ifdef CONFIG_STRESS
  91. if (strcmp(cpuClock, "667") == 0) {
  92. if ((strcmp(console_buffer, "133") != 0) &&
  93. (strcmp(console_buffer, "166") != 0))
  94. nbytes = 0;
  95. }
  96. #endif
  97. strcpy(plbClock, console_buffer);
  98. } while (nbytes == 0);
  99. }
  100. do {
  101. printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
  102. nbytes = readline (" ? ");
  103. if (strcmp(console_buffer, "quit") == 0)
  104. return 0;
  105. if ((strcmp(console_buffer, "33") != 0) &&
  106. (strcmp(console_buffer, "66") != 0) &&
  107. (strcmp(console_buffer, "100") != 0) &&
  108. (strcmp(console_buffer, "133") != 0)) {
  109. nbytes = 0;
  110. }
  111. strcpy(pcixClock, console_buffer);
  112. } while (nbytes == 0);
  113. printf("\nsys clk = %s MHz\n", sysClock);
  114. printf("cpu clk = %s MHz\n", cpuClock);
  115. printf("plb clk = %s MHz\n", plbClock);
  116. printf("Pci-X clk = %s MHz\n", pcixClock);
  117. do {
  118. printf("\npress [y] to write I2C bootstrap \n");
  119. printf("or [n] to abort. \n");
  120. printf("Don't forget to set board switches \n");
  121. printf("according to your choice before re-starting \n");
  122. printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
  123. nbytes = readline (" ? ");
  124. if (strcmp(console_buffer, "n") == 0)
  125. return 0;
  126. } while (nbytes == 0);
  127. if (strcmp(sysClock, "33") == 0) {
  128. if ((strcmp(cpuClock, "400") == 0) &&
  129. (strcmp(plbClock, "100") == 0))
  130. data = 0x8678c206;
  131. if ((strcmp(cpuClock, "400") == 0) &&
  132. (strcmp(plbClock, "133") == 0))
  133. data = 0x8678c2c6;
  134. if ((strcmp(cpuClock, "500") == 0))
  135. data = 0x8778f2c6;
  136. if ((strcmp(cpuClock, "533") == 0))
  137. data = 0x87790252;
  138. #ifdef CONFIG_STRESS
  139. if ((strcmp(cpuClock, "667") == 0) &&
  140. (strcmp(plbClock, "133") == 0))
  141. data = 0x87794256;
  142. if ((strcmp(cpuClock, "667") == 0) &&
  143. (strcmp(plbClock, "166") == 0))
  144. data = 0x87794206;
  145. #endif
  146. }
  147. #ifdef DEBUG
  148. printf(" pin strap0 to write in i2c = %lx\n", data);
  149. #endif /* DEBUG */
  150. if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
  151. printf("Error writing strap0 in %s\n", argv[2]);
  152. if (strcmp(pcixClock, "33") == 0)
  153. data = 0x000007E1;
  154. if (strcmp(pcixClock, "66") == 0)
  155. data = 0x000006E1;
  156. if (strcmp(pcixClock, "100") == 0)
  157. data = 0x000005E1;
  158. if (strcmp(pcixClock, "133") == 0)
  159. data = 0x000004E1;
  160. if (strcmp(plbClock, "166") == 0)
  161. /* data |= 0x05950000; */ /* this set's DDR2 clock == PLB clock */
  162. data |= 0x05A50000; /* this set's DDR2 clock == 2 * PLB clock */
  163. else
  164. data |= 0x05A50000;
  165. #ifdef DEBUG
  166. printf(" pin strap1 to write in i2c = %lx\n", data);
  167. #endif /* DEBUG */
  168. udelay(1000);
  169. if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
  170. printf("Error writing strap1 in %s\n", argv[2]);
  171. return 0;
  172. }
  173. U_BOOT_CMD(
  174. bootstrap, 3, 1, do_bootstrap,
  175. "program the serial device strap",
  176. "wrclk [prom0|prom1] - program the serial device strap\n"
  177. );