pixis.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. NULL);
  234. #ifdef CONFIG_PIXIS_SGMII_CMD
  235. int pixis_set_sgmii(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  236. {
  237. int which_tsec = -1;
  238. uchar mask;
  239. uchar switch_mask;
  240. if (argc > 2)
  241. if (strcmp(argv[1], "all") != 0)
  242. which_tsec = simple_strtoul(argv[1], NULL, 0);
  243. switch (which_tsec) {
  244. #ifdef CONFIG_TSEC1
  245. case 1:
  246. mask = PIXIS_VSPEED2_TSEC1SER;
  247. switch_mask = PIXIS_VCFGEN1_TSEC1SER;
  248. break;
  249. #endif
  250. #ifdef CONFIG_TSEC2
  251. case 2:
  252. mask = PIXIS_VSPEED2_TSEC2SER;
  253. switch_mask = PIXIS_VCFGEN1_TSEC2SER;
  254. break;
  255. #endif
  256. #ifdef CONFIG_TSEC3
  257. case 3:
  258. mask = PIXIS_VSPEED2_TSEC3SER;
  259. switch_mask = PIXIS_VCFGEN1_TSEC3SER;
  260. break;
  261. #endif
  262. #ifdef CONFIG_TSEC4
  263. case 4:
  264. mask = PIXIS_VSPEED2_TSEC4SER;
  265. switch_mask = PIXIS_VCFGEN1_TSEC4SER;
  266. break;
  267. #endif
  268. default:
  269. mask = PIXIS_VSPEED2_MASK;
  270. switch_mask = PIXIS_VCFGEN1_MASK;
  271. break;
  272. }
  273. /* Toggle whether the switches or FPGA control the settings */
  274. if (!strcmp(argv[argc - 1], "switch"))
  275. clrbits_8((unsigned char *)PIXIS_BASE + PIXIS_VCFGEN1,
  276. switch_mask);
  277. else
  278. setbits_8((unsigned char *)PIXIS_BASE + PIXIS_VCFGEN1,
  279. switch_mask);
  280. /* If it's not the switches, enable or disable SGMII, as specified */
  281. if (!strcmp(argv[argc - 1], "on"))
  282. clrbits_8((unsigned char *)PIXIS_BASE + PIXIS_VSPEED2, mask);
  283. else if (!strcmp(argv[argc - 1], "off"))
  284. setbits_8((unsigned char *)PIXIS_BASE + PIXIS_VSPEED2, mask);
  285. return 0;
  286. }
  287. U_BOOT_CMD(
  288. pixis_set_sgmii, CONFIG_SYS_MAXARGS, 1, pixis_set_sgmii,
  289. "pixis_set_sgmii"
  290. " - Enable or disable SGMII mode for a given TSEC \n",
  291. "\npixis_set_sgmii [TSEC num] <on|off|switch>\n"
  292. " TSEC num: 1,2,3,4 or 'all'. 'all' is default.\n"
  293. " on - enables SGMII\n"
  294. " off - disables SGMII\n"
  295. " switch - use switch settings\n");
  296. #endif
  297. /*
  298. * This function takes the non-integral cpu:mpx pll ratio
  299. * and converts it to an integer that can be used to assign
  300. * FPGA register values.
  301. * input: strptr i.e. argv[2]
  302. */
  303. static ulong strfractoint(uchar *strptr)
  304. {
  305. int i, j, retval;
  306. int mulconst;
  307. int intarr_len = 0, decarr_len = 0, no_dec = 0;
  308. ulong intval = 0, decval = 0;
  309. uchar intarr[3], decarr[3];
  310. /* Assign the integer part to intarr[]
  311. * If there is no decimal point i.e.
  312. * if the ratio is an integral value
  313. * simply create the intarr.
  314. */
  315. i = 0;
  316. while (strptr[i] != '.') {
  317. if (strptr[i] == 0) {
  318. no_dec = 1;
  319. break;
  320. }
  321. intarr[i] = strptr[i];
  322. i++;
  323. }
  324. /* Assign length of integer part to intarr_len. */
  325. intarr_len = i;
  326. intarr[i] = '\0';
  327. if (no_dec) {
  328. /* Currently needed only for single digit corepll ratios */
  329. mulconst = 10;
  330. decval = 0;
  331. } else {
  332. j = 0;
  333. i++; /* Skipping the decimal point */
  334. while ((strptr[i] >= '0') && (strptr[i] <= '9')) {
  335. decarr[j] = strptr[i];
  336. i++;
  337. j++;
  338. }
  339. decarr_len = j;
  340. decarr[j] = '\0';
  341. mulconst = 1;
  342. for (i = 0; i < decarr_len; i++)
  343. mulconst *= 10;
  344. decval = simple_strtoul((char *)decarr, NULL, 10);
  345. }
  346. intval = simple_strtoul((char *)intarr, NULL, 10);
  347. intval = intval * mulconst;
  348. retval = intval + decval;
  349. return retval;
  350. }
  351. int
  352. pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  353. {
  354. unsigned int i;
  355. char *p_cf = NULL;
  356. char *p_cf_sysclk = NULL;
  357. char *p_cf_corepll = NULL;
  358. char *p_cf_mpxpll = NULL;
  359. char *p_altbank = NULL;
  360. char *p_wd = NULL;
  361. unsigned int unknown_param = 0;
  362. /*
  363. * No args is a simple reset request.
  364. */
  365. if (argc <= 1) {
  366. pixis_reset();
  367. /* not reached */
  368. }
  369. for (i = 1; i < argc; i++) {
  370. if (strcmp(argv[i], "cf") == 0) {
  371. p_cf = argv[i];
  372. if (i + 3 >= argc) {
  373. break;
  374. }
  375. p_cf_sysclk = argv[i+1];
  376. p_cf_corepll = argv[i+2];
  377. p_cf_mpxpll = argv[i+3];
  378. i += 3;
  379. continue;
  380. }
  381. if (strcmp(argv[i], "altbank") == 0) {
  382. p_altbank = argv[i];
  383. continue;
  384. }
  385. if (strcmp(argv[i], "wd") == 0) {
  386. p_wd = argv[i];
  387. continue;
  388. }
  389. unknown_param = 1;
  390. }
  391. /*
  392. * Check that cf has all required parms
  393. */
  394. if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll))
  395. || unknown_param) {
  396. #ifdef CONFIG_SYS_LONGHELP
  397. puts(cmdtp->help);
  398. #endif
  399. return 1;
  400. }
  401. /*
  402. * PIXIS seems to be sensitive to the ordering of
  403. * the registers that are touched.
  404. */
  405. read_from_px_regs(0);
  406. if (p_altbank) {
  407. read_from_px_regs_altbank(0);
  408. }
  409. clear_altbank();
  410. /*
  411. * Clock configuration specified.
  412. */
  413. if (p_cf) {
  414. unsigned long sysclk;
  415. unsigned long corepll;
  416. unsigned long mpxpll;
  417. sysclk = simple_strtoul(p_cf_sysclk, NULL, 10);
  418. corepll = strfractoint((uchar *) p_cf_corepll);
  419. mpxpll = simple_strtoul(p_cf_mpxpll, NULL, 10);
  420. if (!(set_px_sysclk(sysclk)
  421. && set_px_corepll(corepll)
  422. && set_px_mpxpll(mpxpll))) {
  423. #ifdef CONFIG_SYS_LONGHELP
  424. puts(cmdtp->help);
  425. #endif
  426. return 1;
  427. }
  428. read_from_px_regs(1);
  429. }
  430. /*
  431. * Altbank specified
  432. *
  433. * NOTE CHANGE IN BEHAVIOR: previous code would default
  434. * to enabling watchdog if altbank is specified.
  435. * Now the watchdog must be enabled explicitly using 'wd'.
  436. */
  437. if (p_altbank) {
  438. set_altbank();
  439. read_from_px_regs_altbank(1);
  440. }
  441. /*
  442. * Reset with watchdog specified.
  443. */
  444. if (p_wd) {
  445. set_px_go_with_watchdog();
  446. } else {
  447. set_px_go();
  448. }
  449. /*
  450. * Shouldn't be reached.
  451. */
  452. return 0;
  453. }
  454. U_BOOT_CMD(
  455. pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd,
  456. "Reset the board using the FPGA sequencer",
  457. " pixis_reset\n"
  458. " pixis_reset [altbank]\n"
  459. " pixis_reset altbank wd\n"
  460. " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
  461. " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n"
  462. );