cpu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * Copyright 2004 Freescale Semiconductor
  3. * Jeff Brown (jeffrey@freescale.com)
  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 <watchdog.h>
  26. #include <command.h>
  27. #include <asm/cache.h>
  28. #include <mpc86xx.h>
  29. #if defined(CONFIG_OF_FLAT_TREE)
  30. #include <ft_build.h>
  31. #endif
  32. // SS: For debug only, remove after use
  33. static __inline__ unsigned long get_dbat3u (void)
  34. {
  35. unsigned long dbat3u;
  36. asm volatile("mfspr %0, 542" : "=r" (dbat3u) :);
  37. return dbat3u;
  38. }
  39. static __inline__ unsigned long get_dbat3l (void)
  40. {
  41. unsigned long dbat3l;
  42. asm volatile("mfspr %0, 543" : "=r" (dbat3l) :);
  43. return dbat3l;
  44. }
  45. static __inline__ unsigned long get_msr (void)
  46. {
  47. unsigned long msr;
  48. asm volatile("mfmsr %0" : "=r" (msr) :);
  49. return msr;
  50. }
  51. extern unsigned long get_board_sys_clk(ulong dummy);
  52. int checkcpu (void)
  53. {
  54. sys_info_t sysinfo;
  55. uint pvr, svr;
  56. uint ver;
  57. uint major, minor;
  58. uint lcrr; /* local bus clock ratio register */
  59. uint clkdiv; /* clock divider portion of lcrr */
  60. puts("Freescale PowerPC\n");
  61. pvr = get_pvr();
  62. ver = PVR_VER(pvr);
  63. major = PVR_MAJ(pvr);
  64. minor = PVR_MIN(pvr);
  65. puts ("CPU:\n");
  66. printf(" Core: ");
  67. switch (ver) {
  68. case PVR_VER(PVR_86xx):
  69. puts("E600");
  70. break;
  71. default:
  72. puts("Unknown");
  73. break;
  74. }
  75. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  76. svr = get_svr();
  77. ver = SVR_VER(svr);
  78. major = SVR_MAJ(svr);
  79. minor = SVR_MIN(svr);
  80. puts(" System: ");
  81. switch (ver) {
  82. case SVR_8641:
  83. puts("8641");
  84. break;
  85. case SVR_8641D:
  86. puts("8641D");
  87. break;
  88. default:
  89. puts("Unknown");
  90. break;
  91. }
  92. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  93. get_sys_info(&sysinfo);
  94. puts(" Clocks: ");
  95. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  96. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  97. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  98. #if defined(CFG_LBC_LCRR)
  99. lcrr = CFG_LBC_LCRR;
  100. #else
  101. {
  102. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  103. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  104. lcrr = lbc->lcrr;
  105. }
  106. #endif
  107. clkdiv = lcrr & 0x0f;
  108. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  109. printf("LBC:%4lu MHz\n",
  110. sysinfo.freqSystemBus / 1000000 / clkdiv);
  111. } else {
  112. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  113. }
  114. printf(" L2: ");
  115. if (get_l2cr() & 0x80000000)
  116. printf("Enabled\n");
  117. else
  118. printf("Disabled\n");
  119. return (0);
  120. }
  121. /* -------------------------------------------------------------------- */
  122. static inline void
  123. soft_restart(unsigned long addr)
  124. {
  125. #ifndef CONFIG_MPC8641HPCN
  126. /* SRR0 has system reset vector, SRR1 has default MSR value */
  127. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  128. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  129. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  130. __asm__ __volatile__ ("mtspr 27, 4");
  131. __asm__ __volatile__ ("rfi");
  132. #else /* CONFIG_MPC8641HPCN */
  133. out8(PIXIS_BASE+PIXIS_RST,0);
  134. #endif /* !CONFIG_MPC8641HPCN */
  135. while(1); /* not reached */
  136. }
  137. #ifdef CONFIG_MPC8641HPCN
  138. int set_px_sysclk(ulong sysclk)
  139. {
  140. u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux,tmp;
  141. /* Per table 27, page 58 of MPC8641HPCN spec*/
  142. switch(sysclk)
  143. {
  144. case 33:
  145. sysclk_s = 0x04;
  146. sysclk_r = 0x04;
  147. sysclk_v = 0x07;
  148. sysclk_aux = 0x00;
  149. break;
  150. case 40:
  151. sysclk_s = 0x01;
  152. sysclk_r = 0x1F;
  153. sysclk_v = 0x20;
  154. sysclk_aux = 0x01;
  155. break;
  156. case 50:
  157. sysclk_s = 0x01;
  158. sysclk_r = 0x1F;
  159. sysclk_v = 0x2A;
  160. sysclk_aux = 0x02;
  161. break;
  162. case 66:
  163. sysclk_s = 0x01;
  164. sysclk_r = 0x04;
  165. sysclk_v = 0x04;
  166. sysclk_aux = 0x03;
  167. break;
  168. case 83:
  169. sysclk_s = 0x01;
  170. sysclk_r = 0x1F;
  171. sysclk_v = 0x4B;
  172. sysclk_aux = 0x04;
  173. break;
  174. case 100:
  175. sysclk_s = 0x01;
  176. sysclk_r = 0x1F;
  177. sysclk_v = 0x5C;
  178. sysclk_aux = 0x05;
  179. break;
  180. case 134:
  181. sysclk_s = 0x06;
  182. sysclk_r = 0x1F;
  183. sysclk_v = 0x3B;
  184. sysclk_aux = 0x06;
  185. break;
  186. case 166:
  187. sysclk_s = 0x06;
  188. sysclk_r = 0x1F;
  189. sysclk_v = 0x4B;
  190. sysclk_aux = 0x07;
  191. break;
  192. default:
  193. printf("Unsupported SYSCLK frequency.\n");
  194. return 0;
  195. }
  196. vclkh = (sysclk_s << 5) | sysclk_r ;
  197. vclkl = sysclk_v;
  198. out8(PIXIS_BASE+PIXIS_VCLKH,vclkh);
  199. out8(PIXIS_BASE+PIXIS_VCLKL,vclkl);
  200. out8(PIXIS_BASE+PIXIS_AUX,sysclk_aux);
  201. return 1;
  202. }
  203. int set_px_mpxpll(ulong mpxpll)
  204. {
  205. u8 tmp;
  206. u8 val;
  207. switch(mpxpll)
  208. {
  209. case 2:
  210. case 4:
  211. case 6:
  212. case 8:
  213. case 10:
  214. case 12:
  215. case 14:
  216. case 16:
  217. val = (u8)mpxpll;
  218. break;
  219. default:
  220. printf("Unsupported MPXPLL ratio.\n");
  221. return 0;
  222. }
  223. tmp = in8(PIXIS_BASE+PIXIS_VSPEED1);
  224. tmp = (tmp & 0xF0) | (val & 0x0F);
  225. out8(PIXIS_BASE+PIXIS_VSPEED1,tmp);
  226. return 1;
  227. }
  228. int set_px_corepll(ulong corepll)
  229. {
  230. u8 tmp;
  231. u8 val;
  232. switch((int)corepll)
  233. {
  234. case 20:
  235. val = 0x08;
  236. break;
  237. case 25:
  238. val = 0x0C;
  239. break;
  240. case 30:
  241. val = 0x10;
  242. break;
  243. case 35:
  244. val = 0x1C;
  245. break;
  246. case 40:
  247. val = 0x14;
  248. break;
  249. case 45:
  250. val = 0x0E;
  251. break;
  252. default:
  253. printf("Unsupported COREPLL ratio.\n");
  254. return 0;
  255. }
  256. tmp = in8(PIXIS_BASE+PIXIS_VSPEED0);
  257. tmp = (tmp & 0xE0) | (val & 0x1F);
  258. out8(PIXIS_BASE+PIXIS_VSPEED0,tmp);
  259. return 1;
  260. }
  261. void read_from_px_regs(int set)
  262. {
  263. u8 tmp, mask = 0x1C;
  264. tmp = in8(PIXIS_BASE+PIXIS_VCFGEN0);
  265. if (set)
  266. tmp = tmp | mask;
  267. else
  268. tmp = tmp & ~mask;
  269. out8(PIXIS_BASE+PIXIS_VCFGEN0,tmp);
  270. }
  271. void read_from_px_regs_altbank(int set)
  272. {
  273. u8 tmp, mask = 0x04;
  274. tmp = in8(PIXIS_BASE+PIXIS_VCFGEN1);
  275. if (set)
  276. tmp = tmp | mask;
  277. else
  278. tmp = tmp & ~mask;
  279. out8(PIXIS_BASE+PIXIS_VCFGEN1,tmp);
  280. }
  281. void set_altbank(void)
  282. {
  283. u8 tmp;
  284. tmp = in8(PIXIS_BASE+PIXIS_VBOOT);
  285. tmp ^= 0x40;
  286. out8(PIXIS_BASE+PIXIS_VBOOT,tmp);
  287. }
  288. void set_px_go(void)
  289. {
  290. u8 tmp;
  291. tmp = in8(PIXIS_BASE+PIXIS_VCTL);
  292. tmp = tmp & 0x1E;
  293. out8(PIXIS_BASE+PIXIS_VCTL,tmp);
  294. tmp = in8(PIXIS_BASE+PIXIS_VCTL);
  295. tmp = tmp | 0x01;
  296. out8(PIXIS_BASE+PIXIS_VCTL,tmp);
  297. }
  298. void set_px_go_with_watchdog(void)
  299. {
  300. u8 tmp;
  301. tmp = in8(PIXIS_BASE+PIXIS_VCTL);
  302. tmp = tmp & 0x1E;
  303. out8(PIXIS_BASE+PIXIS_VCTL,tmp);
  304. tmp = in8(PIXIS_BASE+PIXIS_VCTL);
  305. tmp = tmp | 0x09;
  306. out8(PIXIS_BASE+PIXIS_VCTL,tmp);
  307. }
  308. /* This function takes the non-integral cpu:mpx pll ratio
  309. * and converts it to an integer that can be used to assign
  310. * FPGA register values.
  311. * input: strptr i.e. argv[2]
  312. */
  313. ulong strfractoint(uchar *strptr)
  314. {
  315. int i,j,retval,intarr_len=0, decarr_len=0, mulconst, no_dec=0;
  316. ulong intval =0, decval=0;
  317. uchar intarr[3], decarr[3];
  318. /* Assign the integer part to intarr[]
  319. * If there is no decimal point i.e.
  320. * if the ratio is an integral value
  321. * simply create the intarr.
  322. */
  323. i=0;
  324. while(strptr[i] != 46)
  325. {
  326. if(strptr[i] == 0)
  327. {
  328. no_dec = 1;
  329. break; /* Break from loop once the end of string is reached */
  330. }
  331. intarr[i] = strptr[i];
  332. i++;
  333. }
  334. intarr_len = i; /* Assign length of integer part to intarr_len*/
  335. intarr[i] = '\0'; /* */
  336. if(no_dec)
  337. {
  338. mulconst=10; /* Currently needed only for single digit corepll ratios */
  339. decval = 0;
  340. }
  341. else
  342. {
  343. j=0;
  344. i++; /* Skipping the decimal point */
  345. while ((strptr[i] > 47) && (strptr[i] < 58))
  346. {
  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 = mulconst*10;
  356. decval = simple_strtoul(decarr,NULL,10);
  357. }
  358. intval = simple_strtoul(intarr,NULL,10);
  359. intval = intval*mulconst;
  360. retval = intval+decval;
  361. return retval;
  362. }
  363. #endif //CONFIG_MPC8641HPCN
  364. /* no generic way to do board reset. simply call soft_reset. */
  365. void
  366. do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  367. {
  368. char cmd;
  369. ulong addr, val;
  370. ulong corepll;
  371. #ifdef CFG_RESET_ADDRESS
  372. addr = CFG_RESET_ADDRESS;
  373. #else
  374. /*
  375. * note: when CFG_MONITOR_BASE points to a RAM address,
  376. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  377. * address. Better pick an address known to be invalid on your
  378. * system and assign it to CFG_RESET_ADDRESS.
  379. */
  380. addr = CFG_MONITOR_BASE - sizeof (ulong);
  381. #endif
  382. #ifndef CONFIG_MPC8641HPCN
  383. /* flush and disable I/D cache */
  384. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  385. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  386. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  387. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  388. __asm__ __volatile__ ("sync");
  389. __asm__ __volatile__ ("mtspr 1008, 4");
  390. __asm__ __volatile__ ("isync");
  391. __asm__ __volatile__ ("sync");
  392. __asm__ __volatile__ ("mtspr 1008, 5");
  393. __asm__ __volatile__ ("isync");
  394. __asm__ __volatile__ ("sync");
  395. soft_restart(addr);
  396. #else /* CONFIG_MPC8641HPCN */
  397. if(argc > 1)
  398. {
  399. cmd = argv[1][1];
  400. switch(cmd)
  401. {
  402. case 'f': /* reset with frequency changed */
  403. if (argc < 5)
  404. goto my_usage;
  405. read_from_px_regs(0);
  406. val = set_px_sysclk(simple_strtoul(argv[2],NULL,10));
  407. corepll = strfractoint(argv[3]);
  408. val = val + set_px_corepll(corepll);
  409. val = val + set_px_mpxpll(simple_strtoul(argv[4],NULL,10));
  410. if(val == 3)
  411. {
  412. printf("Setting registers VCFGEN0 and VCTL\n");
  413. read_from_px_regs(1);
  414. printf("Resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL ....\n");
  415. set_px_go();
  416. }
  417. else
  418. goto my_usage;
  419. while(1); /* Not reached */
  420. case 'l':
  421. if(argv[2][1] == 'f')
  422. {
  423. read_from_px_regs(0);
  424. read_from_px_regs_altbank(0);
  425. /* reset with frequency changed */
  426. val = set_px_sysclk(simple_strtoul(argv[3],NULL,10));
  427. corepll = strfractoint(argv[4]);
  428. val = val + set_px_corepll(corepll);
  429. val = val + set_px_mpxpll(simple_strtoul(argv[5],NULL,10));
  430. if(val == 3)
  431. {
  432. printf("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
  433. set_altbank();
  434. read_from_px_regs(1);
  435. read_from_px_regs_altbank(1);
  436. printf("Enabling watchdog timer on the FPGA and resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL to boot from the other bank ....\n");
  437. set_px_go_with_watchdog();
  438. }
  439. else
  440. goto my_usage;
  441. while(1); /* Not reached */
  442. }
  443. else /* Reset from next bank without changing frequencies */
  444. {
  445. read_from_px_regs(0);
  446. read_from_px_regs_altbank(0);
  447. if(argc > 2)
  448. goto my_usage;
  449. printf("Setting registers VCFGEN1, VBOOT, and VCTL\n");
  450. set_altbank();
  451. read_from_px_regs_altbank(1);
  452. printf("Enabling watchdog timer on the FPGA and resetting board to boot from the other bank....\n");
  453. set_px_go_with_watchdog();
  454. while(1); /* Not reached */
  455. }
  456. default:
  457. goto my_usage;
  458. }
  459. my_usage:
  460. printf("\nUsage: reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n");
  461. printf(" reset altbank [cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>]\n");
  462. printf("For example: reset cf 40 2.5 10\n");
  463. printf("See MPC8641HPCN Design Workbook for valid values of command line parameters.\n");
  464. return;
  465. }
  466. else
  467. out8(PIXIS_BASE+PIXIS_RST,0);
  468. #endif /* !CONFIG_MPC8641HPCN */
  469. while(1); /* not reached */
  470. }
  471. /* ------------------------------------------------------------------------- */
  472. /*
  473. * Get timebase clock frequency
  474. */
  475. unsigned long get_tbclk(void)
  476. {
  477. sys_info_t sys_info;
  478. get_sys_info(&sys_info);
  479. return ((sys_info.freqSystemBus + 3L) / 4L);
  480. }
  481. /* ------------------------------------------------------------------------- */
  482. #if defined(CONFIG_WATCHDOG)
  483. void
  484. watchdog_reset(void)
  485. {
  486. }
  487. #endif /* CONFIG_WATCHDOG */
  488. /* ------------------------------------------------------------------------- */
  489. #if defined(CONFIG_DDR_ECC)
  490. void dma_init(void) {
  491. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  492. volatile ccsr_dma_t *dma = &immap->im_dma;
  493. dma->satr0 = 0x00040000;
  494. dma->datr0 = 0x00040000;
  495. asm("sync; isync");
  496. return;
  497. }
  498. uint dma_check(void) {
  499. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  500. volatile ccsr_dma_t *dma = &immap->im_dma;
  501. volatile uint status = dma->sr0;
  502. /* While the channel is busy, spin */
  503. while((status & 4) == 4) {
  504. status = dma->sr0;
  505. }
  506. if (status != 0) {
  507. printf ("DMA Error: status = %x\n", status);
  508. }
  509. return status;
  510. }
  511. int dma_xfer(void *dest, uint count, void *src) {
  512. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  513. volatile ccsr_dma_t *dma = &immap->im_dma;
  514. dma->dar0 = (uint) dest;
  515. dma->sar0 = (uint) src;
  516. dma->bcr0 = count;
  517. dma->mr0 = 0xf000004;
  518. asm("sync;isync");
  519. dma->mr0 = 0xf000005;
  520. asm("sync;isync");
  521. return dma_check();
  522. }
  523. #endif /* CONFIG_DDR_ECC */
  524. #ifdef CONFIG_OF_FLAT_TREE
  525. void ft_cpu_setup(void *blob, bd_t *bd)
  526. {
  527. u32 *p;
  528. ulong clock;
  529. int len;
  530. clock = bd->bi_busfreq;
  531. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  532. if (p != NULL)
  533. *p = cpu_to_be32(clock);
  534. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  535. if (p != NULL)
  536. *p = cpu_to_be32(clock);
  537. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  538. if (p != NULL)
  539. *p = cpu_to_be32(clock);
  540. #if defined(CONFIG_MPC86XX_TSEC1)
  541. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len);
  542. memcpy(p, bd->bi_enetaddr, 6);
  543. #endif
  544. #if defined(CONFIG_MPC86XX_TSEC2)
  545. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len);
  546. memcpy(p, bd->bi_enet1addr, 6);
  547. #endif
  548. #if defined(CONFIG_MPC86XX_TSEC3)
  549. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/address", &len);
  550. memcpy(p, bd->bi_enet2addr, 6);
  551. #endif
  552. #if defined(CONFIG_MPC86XX_TSEC4)
  553. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/address", &len);
  554. memcpy(p, bd->bi_enet3addr, 6);
  555. #endif
  556. }
  557. #endif