pixis.c 11 KB

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