cpu.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright 2004,2007,2008 Freescale Semiconductor, Inc.
  3. * (C) Copyright 2002, 2003 Motorola Inc.
  4. * Xianghua Xiao (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2000
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #include <asm/cache.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. struct cpu_type {
  33. char name[15];
  34. u32 soc_ver;
  35. };
  36. #define CPU_TYPE_ENTRY(x) {#x, SVR_##x}
  37. struct cpu_type cpu_type_list [] = {
  38. CPU_TYPE_ENTRY(8533),
  39. CPU_TYPE_ENTRY(8533_E),
  40. CPU_TYPE_ENTRY(8540),
  41. CPU_TYPE_ENTRY(8541),
  42. CPU_TYPE_ENTRY(8541_E),
  43. CPU_TYPE_ENTRY(8543),
  44. CPU_TYPE_ENTRY(8543_E),
  45. CPU_TYPE_ENTRY(8544),
  46. CPU_TYPE_ENTRY(8544_E),
  47. CPU_TYPE_ENTRY(8545),
  48. CPU_TYPE_ENTRY(8545_E),
  49. CPU_TYPE_ENTRY(8547_E),
  50. CPU_TYPE_ENTRY(8548),
  51. CPU_TYPE_ENTRY(8548_E),
  52. CPU_TYPE_ENTRY(8555),
  53. CPU_TYPE_ENTRY(8555_E),
  54. CPU_TYPE_ENTRY(8560),
  55. CPU_TYPE_ENTRY(8567),
  56. CPU_TYPE_ENTRY(8567_E),
  57. CPU_TYPE_ENTRY(8568),
  58. CPU_TYPE_ENTRY(8568_E),
  59. CPU_TYPE_ENTRY(8572),
  60. CPU_TYPE_ENTRY(8572_E),
  61. };
  62. int checkcpu (void)
  63. {
  64. sys_info_t sysinfo;
  65. uint lcrr; /* local bus clock ratio register */
  66. uint clkdiv; /* clock divider portion of lcrr */
  67. uint pvr, svr;
  68. uint fam;
  69. uint ver;
  70. uint major, minor;
  71. int i;
  72. u32 ddr_ratio;
  73. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  74. svr = get_svr();
  75. ver = SVR_SOC_VER(svr);
  76. major = SVR_MAJ(svr);
  77. minor = SVR_MIN(svr);
  78. puts("CPU: ");
  79. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  80. if (cpu_type_list[i].soc_ver == ver) {
  81. puts(cpu_type_list[i].name);
  82. break;
  83. }
  84. if (i == ARRAY_SIZE(cpu_type_list))
  85. puts("Unknown");
  86. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  87. pvr = get_pvr();
  88. fam = PVR_FAM(pvr);
  89. ver = PVR_VER(pvr);
  90. major = PVR_MAJ(pvr);
  91. minor = PVR_MIN(pvr);
  92. printf("Core: ");
  93. switch (fam) {
  94. case PVR_FAM(PVR_85xx):
  95. puts("E500");
  96. break;
  97. default:
  98. puts("Unknown");
  99. break;
  100. }
  101. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  102. get_sys_info(&sysinfo);
  103. puts("Clock Configuration:\n");
  104. printf(" CPU:%4lu MHz, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000));
  105. printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(sysinfo.freqSystemBus,1000000));
  106. ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
  107. switch (ddr_ratio) {
  108. case 0x0:
  109. printf(" DDR:%4lu MHz (%lu MT/s data rate), ",
  110. DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
  111. break;
  112. case 0x7:
  113. printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
  114. DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000));
  115. break;
  116. default:
  117. printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
  118. DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
  119. break;
  120. }
  121. #if defined(CFG_LBC_LCRR)
  122. lcrr = CFG_LBC_LCRR;
  123. #else
  124. {
  125. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  126. lcrr = lbc->lcrr;
  127. }
  128. #endif
  129. clkdiv = lcrr & 0x0f;
  130. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  131. #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
  132. /*
  133. * Yes, the entire PQ38 family use the same
  134. * bit-representation for twice the clock divider values.
  135. */
  136. clkdiv *= 2;
  137. #endif
  138. printf("LBC:%4lu MHz\n",
  139. DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv);
  140. } else {
  141. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  142. }
  143. #ifdef CONFIG_CPM2
  144. printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
  145. #endif
  146. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  147. return 0;
  148. }
  149. /* ------------------------------------------------------------------------- */
  150. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  151. {
  152. uint pvr;
  153. uint ver;
  154. pvr = get_pvr();
  155. ver = PVR_VER(pvr);
  156. if (ver & 1){
  157. /* e500 v2 core has reset control register */
  158. volatile unsigned int * rstcr;
  159. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  160. *rstcr = 0x2; /* HRESET_REQ */
  161. }else{
  162. /*
  163. * Initiate hard reset in debug control register DBCR0
  164. * Make sure MSR[DE] = 1
  165. */
  166. unsigned long val, msr;
  167. msr = mfmsr ();
  168. msr |= MSR_DE;
  169. mtmsr (msr);
  170. val = mfspr(DBCR0);
  171. val |= 0x70000000;
  172. mtspr(DBCR0,val);
  173. }
  174. return 1;
  175. }
  176. /*
  177. * Get timebase clock frequency
  178. */
  179. unsigned long get_tbclk (void)
  180. {
  181. return (gd->bus_clk + 4UL)/8UL;
  182. }
  183. #if defined(CONFIG_WATCHDOG)
  184. void
  185. watchdog_reset(void)
  186. {
  187. int re_enable = disable_interrupts();
  188. reset_85xx_watchdog();
  189. if (re_enable) enable_interrupts();
  190. }
  191. void
  192. reset_85xx_watchdog(void)
  193. {
  194. /*
  195. * Clear TSR(WIS) bit by writing 1
  196. */
  197. unsigned long val;
  198. val = mfspr(SPRN_TSR);
  199. val |= TSR_WIS;
  200. mtspr(SPRN_TSR, val);
  201. }
  202. #endif /* CONFIG_WATCHDOG */
  203. #if defined(CONFIG_DDR_ECC)
  204. void dma_init(void) {
  205. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  206. dma->satr0 = 0x02c40000;
  207. dma->datr0 = 0x02c40000;
  208. dma->sr0 = 0xfffffff; /* clear any errors */
  209. asm("sync; isync; msync");
  210. return;
  211. }
  212. uint dma_check(void) {
  213. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  214. volatile uint status = dma->sr0;
  215. /* While the channel is busy, spin */
  216. while((status & 4) == 4) {
  217. status = dma->sr0;
  218. }
  219. /* clear MR0[CS] channel start bit */
  220. dma->mr0 &= 0x00000001;
  221. asm("sync;isync;msync");
  222. if (status != 0) {
  223. printf ("DMA Error: status = %x\n", status);
  224. }
  225. return status;
  226. }
  227. int dma_xfer(void *dest, uint count, void *src) {
  228. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  229. dma->dar0 = (uint) dest;
  230. dma->sar0 = (uint) src;
  231. dma->bcr0 = count;
  232. dma->mr0 = 0xf000004;
  233. asm("sync;isync;msync");
  234. dma->mr0 = 0xf000005;
  235. asm("sync;isync;msync");
  236. return dma_check();
  237. }
  238. #endif