pixis.c 10 KB

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