pixis.c 10 KB

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