cmd_pll.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@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. /*
  25. * ehnus: change pll frequency.
  26. * Wed Sep 5 11:45:17 CST 2007
  27. * hsun@udtech.com.cn
  28. */
  29. #include <common.h>
  30. #include <config.h>
  31. #include <command.h>
  32. #include <i2c.h>
  33. #ifdef CONFIG_CMD_EEPROM
  34. #define EEPROM_CONF_OFFSET 0
  35. #define EEPROM_TEST_OFFSET 16
  36. #define EEPROM_SDSTP_PARAM 16
  37. #define PLL_NAME_MAX 12
  38. #define BUF_STEP 8
  39. /* eeprom_wirtes 8Byte per op. */
  40. #define EEPROM_ALTER_FREQ(freq) \
  41. do { \
  42. int __i; \
  43. for (__i = 0; __i < 2; __i++) \
  44. eeprom_write (CONFIG_SYS_I2C_EEPROM_ADDR, \
  45. EEPROM_CONF_OFFSET + __i*BUF_STEP, \
  46. pll_select[freq], \
  47. BUF_STEP + __i*BUF_STEP); \
  48. } while (0)
  49. #define PDEBUG
  50. #ifdef PDEBUG
  51. #define PLL_DEBUG pll_debug(EEPROM_CONF_OFFSET)
  52. #else
  53. #define PLL_DEBUG
  54. #endif
  55. typedef enum {
  56. PLL_ebc20,
  57. PLL_333,
  58. PLL_4001,
  59. PLL_4002,
  60. PLL_533,
  61. PLL_600,
  62. PLL_666, /* For now, kilauea can't support */
  63. RCONF,
  64. WTEST,
  65. PLL_TOTAL
  66. } pll_freq_t;
  67. static const char
  68. pll_name[][PLL_NAME_MAX] = {
  69. "PLL_ebc20",
  70. "PLL_333",
  71. "PLL_400@1",
  72. "PLL_400@2",
  73. "PLL_533",
  74. "PLL_600",
  75. "PLL_666",
  76. "RCONF",
  77. "WTEST",
  78. ""
  79. };
  80. /*
  81. * ehnus:
  82. */
  83. static uchar
  84. pll_select[][EEPROM_SDSTP_PARAM] = {
  85. /* 0: CPU 333MHz EBC 20MHz, for test only */
  86. {
  87. 0x8c, 0x12, 0xec, 0x12, 0x88, 0x00, 0x0a, 0x00,
  88. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  89. },
  90. /* 0: 333 */
  91. {
  92. 0x8c, 0x12, 0xec, 0x12, 0x98, 0x00, 0x0a, 0x00,
  93. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  94. },
  95. /* 1: 400_266 */
  96. {
  97. 0x8e, 0x0e, 0xe8, 0x13, 0x98, 0x00, 0x0a, 0x00,
  98. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  99. },
  100. /* 2: 400 */
  101. {
  102. 0x8e, 0x0e, 0xe8, 0x12, 0x98, 0x00, 0x0a, 0x00,
  103. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  104. },
  105. /* 3: 533 */
  106. {
  107. 0x8e, 0x43, 0x60, 0x13, 0x98, 0x00, 0x0a, 0x00,
  108. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  109. },
  110. /* 4: 600 */
  111. {
  112. 0x8d, 0x02, 0x34, 0x13, 0x98, 0x00, 0x0a, 0x00,
  113. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  114. },
  115. /* 5: 666 */
  116. {
  117. 0x8d, 0x03, 0x78, 0x13, 0x98, 0x00, 0x0a, 0x00,
  118. 0x40, 0x08, 0x23, 0x50, 0x00, 0x05, 0x00, 0x00
  119. },
  120. {}
  121. };
  122. static uchar
  123. testbuf[EEPROM_SDSTP_PARAM] = {
  124. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  125. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  126. };
  127. static void
  128. pll_debug(int off)
  129. {
  130. int i;
  131. uchar buffer[EEPROM_SDSTP_PARAM];
  132. memset(buffer, 0, sizeof(buffer));
  133. eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, off,
  134. buffer, EEPROM_SDSTP_PARAM);
  135. printf("Debug: SDSTP[0-3] at offset \"0x%02x\" lists as follows: \n", off);
  136. for (i = 0; i < EEPROM_SDSTP_PARAM; i++)
  137. printf("%02x ", buffer[i]);
  138. printf("\n");
  139. }
  140. static void
  141. test_write(void)
  142. {
  143. printf("Debug: test eeprom_write ... ");
  144. /*
  145. * Write twice, 8 bytes per write
  146. */
  147. eeprom_write (CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_TEST_OFFSET,
  148. testbuf, 8);
  149. eeprom_write (CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_TEST_OFFSET+8,
  150. testbuf, 16);
  151. printf("done\n");
  152. pll_debug(EEPROM_TEST_OFFSET);
  153. }
  154. int
  155. do_pll_alter (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  156. {
  157. char c = '\0';
  158. pll_freq_t pll_freq;
  159. if (argc < 2) {
  160. cmd_usage(cmdtp);
  161. goto ret;
  162. }
  163. for (pll_freq = PLL_ebc20; pll_freq < PLL_TOTAL; pll_freq++)
  164. if (!strcmp(pll_name[pll_freq], argv[1]))
  165. break;
  166. switch (pll_freq) {
  167. case PLL_ebc20:
  168. case PLL_333:
  169. case PLL_4001:
  170. case PLL_4002:
  171. case PLL_533:
  172. case PLL_600:
  173. EEPROM_ALTER_FREQ(pll_freq);
  174. break;
  175. case PLL_666: /* not support */
  176. printf("Choose this option will result in a boot failure."
  177. "\nContinue? (Y/N): ");
  178. c = getc(); putc('\n');
  179. if ((c == 'y') || (c == 'Y')) {
  180. EEPROM_ALTER_FREQ(pll_freq);
  181. break;
  182. }
  183. goto ret;
  184. case RCONF:
  185. pll_debug(EEPROM_CONF_OFFSET);
  186. goto ret;
  187. case WTEST:
  188. printf("DEBUG: write test\n");
  189. test_write();
  190. goto ret;
  191. default:
  192. printf("Invalid options\n\n");
  193. cmd_usage(cmdtp);
  194. goto ret;
  195. }
  196. printf("PLL set to %s, "
  197. "reset the board to take effect\n", pll_name[pll_freq]);
  198. PLL_DEBUG;
  199. ret:
  200. return 0;
  201. }
  202. U_BOOT_CMD(
  203. pllalter, CONFIG_SYS_MAXARGS, 1, do_pll_alter,
  204. "pllalter- change pll frequence \n",
  205. "pllalter <selection> - change pll frequence \n\n\
  206. ** New freq take effect after reset. ** \n\
  207. ----------------------------------------------\n\
  208. PLL_ebc20: Board: AMCC 405EX(r) Evaluation Board\n\
  209. \t Same as PLL_333 \n\
  210. \t except \n\
  211. \t EBC: 20 MHz \n\
  212. ----------------------------------------------\n\
  213. PLL_333: Board: AMCC 405EX(r) Evaluation Board\n\
  214. \t VCO: 666 MHz \n\
  215. \t CPU: 333 MHz \n\
  216. \t PLB: 166 MHz \n\
  217. \t OPB: 83 MHz \n\
  218. \t DDR: 83 MHz \n\
  219. ------------------------------------------------\n\
  220. PLL_400@1: Board: AMCC 405EX(r) Evaluation Board\n\
  221. \t VCO: 800 MHz \n\
  222. \t CPU: 400 MHz \n\
  223. \t PLB: 133 MHz \n\
  224. \t OPB: 66 MHz \n\
  225. \t DDR: 133 MHz \n\
  226. ------------------------------------------------\n\
  227. PLL_400@2: Board: AMCC 405EX(r) Evaluation Board\n\
  228. \t VCO: 800 MHz \n\
  229. \t CPU: 400 MHz \n\
  230. \t PLB: 200 MHz \n\
  231. \t OPB: 100 MHz \n\
  232. \t DDR: 200 MHz \n\
  233. ----------------------------------------------\n\
  234. PLL_533: Board: AMCC 405EX(r) Evaluation Board\n\
  235. \t VCO: 1066 MHz \n\
  236. \t CPU: 533 MHz \n\
  237. \t PLB: 177 MHz \n\
  238. \t OPB: 88 MHz \n\
  239. \t DDR: 177 MHz \n\
  240. ----------------------------------------------\n\
  241. PLL_600: Board: AMCC 405EX(r) Evaluation Board\n\
  242. \t VCO: 1200 MHz \n\
  243. \t CPU: 600 MHz \n\
  244. \t PLB: 200 MHz \n\
  245. \t OPB: 100 MHz \n\
  246. \t DDR: 200 MHz \n\
  247. ----------------------------------------------\n\
  248. PLL_666: Board: AMCC 405EX(r) Evaluation Board\n\
  249. \t VCO: 1333 MHz \n\
  250. \t CPU: 666 MHz \n\
  251. \t PLB: 166 MHz \n\
  252. \t OPB: 83 MHz \n\
  253. \t DDR: 166 MHz \n\
  254. -----------------------------------------------\n\
  255. RCONF: Read current eeprom configuration. \n\
  256. -----------------------------------------------\n\
  257. WTEST: Test EEPROM write with predefined values\n\
  258. -----------------------------------------------\n"
  259. );
  260. #endif /* CONFIG_CMD_EEPROM */