pixis.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. * Copyright 2006,2010 Freescale Semiconductor
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <command.h>
  26. #include <asm/io.h>
  27. #define pixis_base (u8 *)PIXIS_BASE
  28. /*
  29. * Simple board reset.
  30. */
  31. void pixis_reset(void)
  32. {
  33. out_8(pixis_base + PIXIS_RST, 0);
  34. while (1);
  35. }
  36. /*
  37. * Per table 27, page 58 of MPC8641HPCN spec.
  38. */
  39. static int set_px_sysclk(unsigned long sysclk)
  40. {
  41. u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
  42. switch (sysclk) {
  43. case 33:
  44. sysclk_s = 0x04;
  45. sysclk_r = 0x04;
  46. sysclk_v = 0x07;
  47. sysclk_aux = 0x00;
  48. break;
  49. case 40:
  50. sysclk_s = 0x01;
  51. sysclk_r = 0x1F;
  52. sysclk_v = 0x20;
  53. sysclk_aux = 0x01;
  54. break;
  55. case 50:
  56. sysclk_s = 0x01;
  57. sysclk_r = 0x1F;
  58. sysclk_v = 0x2A;
  59. sysclk_aux = 0x02;
  60. break;
  61. case 66:
  62. sysclk_s = 0x01;
  63. sysclk_r = 0x04;
  64. sysclk_v = 0x04;
  65. sysclk_aux = 0x03;
  66. break;
  67. case 83:
  68. sysclk_s = 0x01;
  69. sysclk_r = 0x1F;
  70. sysclk_v = 0x4B;
  71. sysclk_aux = 0x04;
  72. break;
  73. case 100:
  74. sysclk_s = 0x01;
  75. sysclk_r = 0x1F;
  76. sysclk_v = 0x5C;
  77. sysclk_aux = 0x05;
  78. break;
  79. case 134:
  80. sysclk_s = 0x06;
  81. sysclk_r = 0x1F;
  82. sysclk_v = 0x3B;
  83. sysclk_aux = 0x06;
  84. break;
  85. case 166:
  86. sysclk_s = 0x06;
  87. sysclk_r = 0x1F;
  88. sysclk_v = 0x4B;
  89. sysclk_aux = 0x07;
  90. break;
  91. default:
  92. printf("Unsupported SYSCLK frequency.\n");
  93. return 0;
  94. }
  95. vclkh = (sysclk_s << 5) | sysclk_r;
  96. vclkl = sysclk_v;
  97. out_8(pixis_base + PIXIS_VCLKH, vclkh);
  98. out_8(pixis_base + PIXIS_VCLKL, vclkl);
  99. out_8(pixis_base + PIXIS_AUX, sysclk_aux);
  100. return 1;
  101. }
  102. /* Set the CFG_SYSPLL bits
  103. *
  104. * This only has effect if PX_VCFGEN0[SYSPLL]=1, which is true if
  105. * read_from_px_regs() is called.
  106. */
  107. static int set_px_mpxpll(unsigned long mpxpll)
  108. {
  109. switch (mpxpll) {
  110. case 2:
  111. case 4:
  112. case 6:
  113. case 8:
  114. case 10:
  115. case 12:
  116. case 14:
  117. case 16:
  118. clrsetbits_8(pixis_base + PIXIS_VSPEED1, 0x1F, mpxpll);
  119. return 1;
  120. }
  121. printf("Unsupported MPXPLL ratio.\n");
  122. return 0;
  123. }
  124. static int set_px_corepll(unsigned long corepll)
  125. {
  126. u8 val;
  127. switch (corepll) {
  128. case 20:
  129. val = 0x08;
  130. break;
  131. case 25:
  132. val = 0x0C;
  133. break;
  134. case 30:
  135. val = 0x10;
  136. break;
  137. case 35:
  138. val = 0x1C;
  139. break;
  140. case 40:
  141. val = 0x14;
  142. break;
  143. case 45:
  144. val = 0x0E;
  145. break;
  146. default:
  147. printf("Unsupported COREPLL ratio.\n");
  148. return 0;
  149. }
  150. clrsetbits_8(pixis_base + PIXIS_VSPEED0, 0x1F, val);
  151. return 1;
  152. }
  153. #ifndef CONFIG_SYS_PIXIS_VCFGEN0_ENABLE
  154. #define CONFIG_SYS_PIXIS_VCFGEN0_ENABLE 0x1C
  155. #endif
  156. /* Tell the PIXIS where to find the COREPLL, MPXPLL, SYSCLK values
  157. *
  158. * The PIXIS can be programmed to look at either the on-board dip switches
  159. * or various other PIXIS registers to determine the values for COREPLL,
  160. * MPXPLL, and SYSCLK.
  161. *
  162. * CONFIG_SYS_PIXIS_VCFGEN0_ENABLE is the value to write to the PIXIS_VCFGEN0
  163. * register that tells the pixis to use the various PIXIS register.
  164. */
  165. static void read_from_px_regs(int set)
  166. {
  167. u8 tmp = in_8(pixis_base + PIXIS_VCFGEN0);
  168. if (set)
  169. tmp = tmp | CONFIG_SYS_PIXIS_VCFGEN0_ENABLE;
  170. else
  171. tmp = tmp & ~CONFIG_SYS_PIXIS_VCFGEN0_ENABLE;
  172. out_8(pixis_base + PIXIS_VCFGEN0, tmp);
  173. }
  174. /* CONFIG_SYS_PIXIS_VBOOT_ENABLE is the value to write to the PX_VCFGEN1
  175. * register that tells the pixis to use the PX_VBOOT[LBMAP] register.
  176. */
  177. #ifndef CONFIG_SYS_PIXIS_VBOOT_ENABLE
  178. #define CONFIG_SYS_PIXIS_VBOOT_ENABLE 0x04
  179. #endif
  180. /* Configure the source of the boot location
  181. *
  182. * The PIXIS can be programmed to look at either the on-board dip switches
  183. * or the PX_VBOOT[LBMAP] register to determine where we should boot.
  184. *
  185. * If we want to boot from the alternate boot bank, we need to tell the PIXIS
  186. * to ignore the on-board dip switches and use the PX_VBOOT[LBMAP] instead.
  187. */
  188. static void read_from_px_regs_altbank(int set)
  189. {
  190. u8 tmp = in_8(pixis_base + PIXIS_VCFGEN1);
  191. if (set)
  192. tmp = tmp | CONFIG_SYS_PIXIS_VBOOT_ENABLE;
  193. else
  194. tmp = tmp & ~CONFIG_SYS_PIXIS_VBOOT_ENABLE;
  195. out_8(pixis_base + PIXIS_VCFGEN1, tmp);
  196. }
  197. /* CONFIG_SYS_PIXIS_VBOOT_MASK contains the bits to set in VBOOT register that
  198. * tells the PIXIS what the alternate flash bank is.
  199. *
  200. * Note that it's not really a mask. It contains the actual LBMAP bits that
  201. * must be set to select the alternate bank. This code assumes that the
  202. * primary bank has these bits set to 0, and the alternate bank has these
  203. * bits set to 1.
  204. */
  205. #ifndef CONFIG_SYS_PIXIS_VBOOT_MASK
  206. #define CONFIG_SYS_PIXIS_VBOOT_MASK (0x40)
  207. #endif
  208. /* Tell the PIXIS to boot from the default flash bank
  209. *
  210. * Program the default flash bank into the VBOOT register. This register is
  211. * used only if PX_VCFGEN1[FLASH]=1.
  212. */
  213. static void clear_altbank(void)
  214. {
  215. clrbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK);
  216. }
  217. /* Tell the PIXIS to boot from the alternate flash bank
  218. *
  219. * Program the alternate flash bank into the VBOOT register. This register is
  220. * used only if PX_VCFGEN1[FLASH]=1.
  221. */
  222. static void set_altbank(void)
  223. {
  224. setbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK);
  225. }
  226. /* Reset the board with watchdog disabled.
  227. *
  228. * This respects the altbank setting.
  229. */
  230. static void set_px_go(void)
  231. {
  232. /* Disable the VELA sequencer and watchdog */
  233. clrbits_8(pixis_base + PIXIS_VCTL, 9);
  234. /* Reboot by starting the VELA sequencer */
  235. setbits_8(pixis_base + PIXIS_VCTL, 0x1);
  236. while (1);
  237. }
  238. /* Reset the board with watchdog enabled.
  239. *
  240. * This respects the altbank setting.
  241. */
  242. static void set_px_go_with_watchdog(void)
  243. {
  244. /* Disable the VELA sequencer */
  245. clrbits_8(pixis_base + PIXIS_VCTL, 1);
  246. /* Enable the watchdog and reboot by starting the VELA sequencer */
  247. setbits_8(pixis_base + PIXIS_VCTL, 0x9);
  248. while (1);
  249. }
  250. /* Disable the watchdog
  251. *
  252. */
  253. static int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
  254. char * const argv[])
  255. {
  256. /* Disable the VELA sequencer and the watchdog */
  257. clrbits_8(pixis_base + PIXIS_VCTL, 9);
  258. return 0;
  259. }
  260. U_BOOT_CMD(
  261. diswd, 1, 0, pixis_disable_watchdog_cmd,
  262. "Disable watchdog timer",
  263. ""
  264. );
  265. #ifdef CONFIG_PIXIS_SGMII_CMD
  266. /* Enable or disable SGMII mode for a TSEC
  267. */
  268. static int pixis_set_sgmii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  269. {
  270. int which_tsec = -1;
  271. unsigned char mask;
  272. unsigned char switch_mask;
  273. if ((argc > 2) && (strcmp(argv[1], "all") != 0))
  274. which_tsec = simple_strtoul(argv[1], NULL, 0);
  275. switch (which_tsec) {
  276. #ifdef CONFIG_TSEC1
  277. case 1:
  278. mask = PIXIS_VSPEED2_TSEC1SER;
  279. switch_mask = PIXIS_VCFGEN1_TSEC1SER;
  280. break;
  281. #endif
  282. #ifdef CONFIG_TSEC2
  283. case 2:
  284. mask = PIXIS_VSPEED2_TSEC2SER;
  285. switch_mask = PIXIS_VCFGEN1_TSEC2SER;
  286. break;
  287. #endif
  288. #ifdef CONFIG_TSEC3
  289. case 3:
  290. mask = PIXIS_VSPEED2_TSEC3SER;
  291. switch_mask = PIXIS_VCFGEN1_TSEC3SER;
  292. break;
  293. #endif
  294. #ifdef CONFIG_TSEC4
  295. case 4:
  296. mask = PIXIS_VSPEED2_TSEC4SER;
  297. switch_mask = PIXIS_VCFGEN1_TSEC4SER;
  298. break;
  299. #endif
  300. default:
  301. mask = PIXIS_VSPEED2_MASK;
  302. switch_mask = PIXIS_VCFGEN1_MASK;
  303. break;
  304. }
  305. /* Toggle whether the switches or FPGA control the settings */
  306. if (!strcmp(argv[argc - 1], "switch"))
  307. clrbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask);
  308. else
  309. setbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask);
  310. /* If it's not the switches, enable or disable SGMII, as specified */
  311. if (!strcmp(argv[argc - 1], "on"))
  312. clrbits_8(pixis_base + PIXIS_VSPEED2, mask);
  313. else if (!strcmp(argv[argc - 1], "off"))
  314. setbits_8(pixis_base + PIXIS_VSPEED2, mask);
  315. return 0;
  316. }
  317. U_BOOT_CMD(
  318. pixis_set_sgmii, CONFIG_SYS_MAXARGS, 1, pixis_set_sgmii,
  319. "pixis_set_sgmii"
  320. " - Enable or disable SGMII mode for a given TSEC \n",
  321. "\npixis_set_sgmii [TSEC num] <on|off|switch>\n"
  322. " TSEC num: 1,2,3,4 or 'all'. 'all' is default.\n"
  323. " on - enables SGMII\n"
  324. " off - disables SGMII\n"
  325. " switch - use switch settings"
  326. );
  327. #endif
  328. /*
  329. * This function takes the non-integral cpu:mpx pll ratio
  330. * and converts it to an integer that can be used to assign
  331. * FPGA register values.
  332. * input: strptr i.e. argv[2]
  333. */
  334. static unsigned long strfractoint(char *strptr)
  335. {
  336. int i, j;
  337. int mulconst;
  338. int intarr_len, no_dec = 0;
  339. unsigned long intval = 0, decval = 0;
  340. char intarr[3], decarr[3];
  341. /* Assign the integer part to intarr[]
  342. * If there is no decimal point i.e.
  343. * if the ratio is an integral value
  344. * simply create the intarr.
  345. */
  346. i = 0;
  347. while (strptr[i] != '.') {
  348. if (strptr[i] == 0) {
  349. no_dec = 1;
  350. break;
  351. }
  352. intarr[i] = strptr[i];
  353. i++;
  354. }
  355. /* Assign length of integer part to intarr_len. */
  356. intarr_len = i;
  357. intarr[i] = '\0';
  358. if (no_dec) {
  359. /* Currently needed only for single digit corepll ratios */
  360. mulconst = 10;
  361. decval = 0;
  362. } else {
  363. j = 0;
  364. i++; /* Skipping the decimal point */
  365. while ((strptr[i] >= '0') && (strptr[i] <= '9')) {
  366. decarr[j] = strptr[i];
  367. i++;
  368. j++;
  369. }
  370. decarr[j] = '\0';
  371. mulconst = 1;
  372. for (i = 0; i < j; i++)
  373. mulconst *= 10;
  374. decval = simple_strtoul(decarr, NULL, 10);
  375. }
  376. intval = simple_strtoul(intarr, NULL, 10);
  377. intval = intval * mulconst;
  378. return intval + decval;
  379. }
  380. static int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  381. {
  382. unsigned int i;
  383. char *p_cf = NULL;
  384. char *p_cf_sysclk = NULL;
  385. char *p_cf_corepll = NULL;
  386. char *p_cf_mpxpll = NULL;
  387. char *p_altbank = NULL;
  388. char *p_wd = NULL;
  389. int unknown_param = 0;
  390. /*
  391. * No args is a simple reset request.
  392. */
  393. if (argc <= 1) {
  394. pixis_reset();
  395. /* not reached */
  396. }
  397. for (i = 1; i < argc; i++) {
  398. if (strcmp(argv[i], "cf") == 0) {
  399. p_cf = argv[i];
  400. if (i + 3 >= argc) {
  401. break;
  402. }
  403. p_cf_sysclk = argv[i+1];
  404. p_cf_corepll = argv[i+2];
  405. p_cf_mpxpll = argv[i+3];
  406. i += 3;
  407. continue;
  408. }
  409. if (strcmp(argv[i], "altbank") == 0) {
  410. p_altbank = argv[i];
  411. continue;
  412. }
  413. if (strcmp(argv[i], "wd") == 0) {
  414. p_wd = argv[i];
  415. continue;
  416. }
  417. unknown_param = 1;
  418. }
  419. /*
  420. * Check that cf has all required parms
  421. */
  422. if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll))
  423. || unknown_param) {
  424. #ifdef CONFIG_SYS_LONGHELP
  425. puts(cmdtp->help);
  426. #endif
  427. return 1;
  428. }
  429. /*
  430. * PIXIS seems to be sensitive to the ordering of
  431. * the registers that are touched.
  432. */
  433. read_from_px_regs(0);
  434. if (p_altbank)
  435. read_from_px_regs_altbank(0);
  436. clear_altbank();
  437. /*
  438. * Clock configuration specified.
  439. */
  440. if (p_cf) {
  441. unsigned long sysclk;
  442. unsigned long corepll;
  443. unsigned long mpxpll;
  444. sysclk = simple_strtoul(p_cf_sysclk, NULL, 10);
  445. corepll = strfractoint(p_cf_corepll);
  446. mpxpll = simple_strtoul(p_cf_mpxpll, NULL, 10);
  447. if (!(set_px_sysclk(sysclk)
  448. && set_px_corepll(corepll)
  449. && set_px_mpxpll(mpxpll))) {
  450. #ifdef CONFIG_SYS_LONGHELP
  451. puts(cmdtp->help);
  452. #endif
  453. return 1;
  454. }
  455. read_from_px_regs(1);
  456. }
  457. /*
  458. * Altbank specified
  459. *
  460. * NOTE CHANGE IN BEHAVIOR: previous code would default
  461. * to enabling watchdog if altbank is specified.
  462. * Now the watchdog must be enabled explicitly using 'wd'.
  463. */
  464. if (p_altbank) {
  465. set_altbank();
  466. read_from_px_regs_altbank(1);
  467. }
  468. /*
  469. * Reset with watchdog specified.
  470. */
  471. if (p_wd)
  472. set_px_go_with_watchdog();
  473. else
  474. set_px_go();
  475. /*
  476. * Shouldn't be reached.
  477. */
  478. return 0;
  479. }
  480. U_BOOT_CMD(
  481. pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
  482. "Reset the board using the FPGA sequencer",
  483. " pixis_reset\n"
  484. " pixis_reset [altbank]\n"
  485. " pixis_reset altbank wd\n"
  486. " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
  487. " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>"
  488. );