pixis.c 11 KB

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