cpu.c 15 KB

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