cmd_sequoia.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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/io.h>
  28. /*
  29. * There are 2 versions of production Sequoia & Rainier platforms.
  30. * The primary difference is the reference clock. Those with
  31. * 33333333 reference clocks will also have 667MHz rated
  32. * processors. Not enough differences to have unique clock
  33. * settings.
  34. *
  35. * NOR and NAND boot options change bytes 6, 7, 8, 9, 11. The
  36. * values are independent of the rest of the clock settings.
  37. *
  38. * All Sequoias & Rainiers select from two possible EEPROMs in Boot
  39. * Config F. One for 33MHz PCI, one for 66MHz PCI. The following
  40. * values are for the 33MHz PCI configuration. Byte 5 (0 base) is
  41. * the only value affected for a 33MHz PCI and simply needs a | 0x08.
  42. */
  43. #define NAND_COMPATIBLE 0x01
  44. #define NOR_COMPATIBLE 0x02
  45. /* check with Stefan on CONFIG_SYS_I2C_EEPROM_ADDR */
  46. #define I2C_EEPROM_ADDR 0x52
  47. static char *config_labels[] = {
  48. "CPU: 333 PLB: 133 OPB: 66 EBC: 66",
  49. "CPU: 333 PLB: 166 OPB: 83 EBC: 55",
  50. "CPU: 400 PLB: 133 OPB: 66 EBC: 66",
  51. "CPU: 400 PLB: 160 OPB: 80 EBC: 53",
  52. "CPU: 416 PLB: 166 OPB: 83 EBC: 55",
  53. "CPU: 500 PLB: 166 OPB: 83 EBC: 55",
  54. "CPU: 533 PLB: 133 OPB: 66 EBC: 66",
  55. "CPU: 667 PLB: 133 OPB: 66 EBC: 66",
  56. "CPU: 667 PLB: 166 OPB: 83 EBC: 55",
  57. NULL
  58. };
  59. static u8 boot_configs[][17] = {
  60. {
  61. (NOR_COMPATIBLE),
  62. 0x84, 0x70, 0xa2, 0xa6, 0x05, 0x57, 0xa0, 0x10, 0x40,
  63. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  64. },
  65. {
  66. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  67. 0xc7, 0x78, 0xf3, 0x4e, 0x05, 0xd7, 0xa0, 0x30, 0x40,
  68. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  69. },
  70. {
  71. (NOR_COMPATIBLE),
  72. 0x86, 0x78, 0xc2, 0xc6, 0x05, 0x57, 0xa0, 0x30, 0x40,
  73. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  74. },
  75. {
  76. (NOR_COMPATIBLE),
  77. 0x86, 0x78, 0xc2, 0xa6, 0x05, 0xd7, 0xa0, 0x10, 0x40,
  78. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  79. },
  80. {
  81. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  82. 0xc6, 0x78, 0x52, 0xa6, 0x05, 0xd7, 0xa0, 0x10, 0x40,
  83. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  84. },
  85. {
  86. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  87. 0xc7, 0x78, 0x52, 0xc6, 0x05, 0xd7, 0xa0, 0x30, 0x40,
  88. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  89. },
  90. {
  91. (NOR_COMPATIBLE),
  92. 0x87, 0x78, 0x82, 0x52, 0x09, 0x57, 0xa0, 0x30, 0x40,
  93. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  94. },
  95. {
  96. (NOR_COMPATIBLE),
  97. 0x87, 0x78, 0xa2, 0x56, 0x09, 0x57, 0xa0, 0x30, 0x40,
  98. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  99. },
  100. {
  101. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  102. 0x87, 0x78, 0xa2, 0x52, 0x09, 0xd7, 0xa0, 0x30, 0x40,
  103. 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  104. },
  105. {
  106. 0,
  107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  108. }
  109. };
  110. /*
  111. * Bytes 6,8,9,11 change for NAND boot
  112. */
  113. static u8 nand_boot[] = {
  114. 0xd0, 0xa0, 0x68, 0x58
  115. };
  116. static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  117. {
  118. u8 *buf, bNAND;
  119. int x, y, nbytes, selcfg;
  120. extern char console_buffer[];
  121. if (argc < 2) {
  122. cmd_usage(cmdtp);
  123. return 1;
  124. }
  125. if ((strcmp(argv[1], "nor") != 0) &&
  126. (strcmp(argv[1], "nand") != 0)) {
  127. printf("Unsupported boot-device - only nor|nand support\n");
  128. return 1;
  129. }
  130. /* set the nand flag based on provided input */
  131. if ((strcmp(argv[1], "nand") == 0))
  132. bNAND = 1;
  133. else
  134. bNAND = 0;
  135. printf("Available configurations: \n\n");
  136. if (bNAND) {
  137. for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
  138. /* filter on nand compatible */
  139. if (boot_configs[x][0] & NAND_COMPATIBLE) {
  140. printf(" %d - %s\n", (y+1), config_labels[x]);
  141. y++;
  142. }
  143. }
  144. } else {
  145. for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
  146. /* filter on nor compatible */
  147. if (boot_configs[x][0] & NOR_COMPATIBLE) {
  148. printf(" %d - %s\n", (y+1), config_labels[x]);
  149. y++;
  150. }
  151. }
  152. }
  153. do {
  154. nbytes = readline(" Selection [1-x / quit]: ");
  155. if (nbytes) {
  156. if (strcmp(console_buffer, "quit") == 0)
  157. return 0;
  158. selcfg = simple_strtol(console_buffer, NULL, 10);
  159. if ((selcfg < 1) || (selcfg > y))
  160. nbytes = 0;
  161. }
  162. } while (nbytes == 0);
  163. y = (selcfg - 1);
  164. for (x = 0; boot_configs[x][0] != 0; x++) {
  165. if (bNAND) {
  166. if (boot_configs[x][0] & NAND_COMPATIBLE) {
  167. if (y > 0)
  168. y--;
  169. else if (y < 1)
  170. break;
  171. }
  172. } else {
  173. if (boot_configs[x][0] & NOR_COMPATIBLE) {
  174. if (y > 0)
  175. y--;
  176. else if (y < 1)
  177. break;
  178. }
  179. }
  180. }
  181. buf = &boot_configs[x][1];
  182. if (bNAND) {
  183. buf[6] = nand_boot[0];
  184. buf[8] = nand_boot[1];
  185. buf[9] = nand_boot[2];
  186. buf[11] = nand_boot[3];
  187. }
  188. /* check CPLD register +5 for PCI 66MHz flag */
  189. if ((in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) & CONFIG_SYS_BCSR5_PCI66EN) == 0)
  190. /*
  191. * PLB-to-PCI divisor = 3 for 33MHz sync PCI
  192. * instead of 2 for 66MHz systems
  193. */
  194. buf[5] |= 0x08;
  195. if (i2c_write(I2C_EEPROM_ADDR, 0, 1, buf, 16) != 0)
  196. printf("Error writing to EEPROM at address 0x%x\n", I2C_EEPROM_ADDR);
  197. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  198. printf("Done\n");
  199. printf("Please power-cycle the board for the changes to take effect\n");
  200. return 0;
  201. }
  202. U_BOOT_CMD(
  203. bootstrap, 2, 0, do_bootstrap,
  204. "program the I2C bootstrap EEPROM",
  205. "<nand|nor> - strap to boot from NAND or NOR flash"
  206. );