cpu.c 6.0 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. struct cpu_type {
  32. char name[15];
  33. u32 soc_ver;
  34. };
  35. #define CPU_TYPE_ENTRY(x) {#x, SVR_##x}
  36. struct cpu_type cpu_type_list [] = {
  37. CPU_TYPE_ENTRY(8533),
  38. CPU_TYPE_ENTRY(8533_E),
  39. CPU_TYPE_ENTRY(8540),
  40. CPU_TYPE_ENTRY(8541),
  41. CPU_TYPE_ENTRY(8541_E),
  42. CPU_TYPE_ENTRY(8543),
  43. CPU_TYPE_ENTRY(8543_E),
  44. CPU_TYPE_ENTRY(8544),
  45. CPU_TYPE_ENTRY(8544_E),
  46. CPU_TYPE_ENTRY(8545),
  47. CPU_TYPE_ENTRY(8545_E),
  48. CPU_TYPE_ENTRY(8547_E),
  49. CPU_TYPE_ENTRY(8548),
  50. CPU_TYPE_ENTRY(8548_E),
  51. CPU_TYPE_ENTRY(8555),
  52. CPU_TYPE_ENTRY(8555_E),
  53. CPU_TYPE_ENTRY(8560),
  54. CPU_TYPE_ENTRY(8567),
  55. CPU_TYPE_ENTRY(8567_E),
  56. CPU_TYPE_ENTRY(8568),
  57. CPU_TYPE_ENTRY(8568_E),
  58. CPU_TYPE_ENTRY(8572),
  59. CPU_TYPE_ENTRY(8572_E),
  60. };
  61. int checkcpu (void)
  62. {
  63. sys_info_t sysinfo;
  64. uint lcrr; /* local bus clock ratio register */
  65. uint clkdiv; /* clock divider portion of lcrr */
  66. uint pvr, svr;
  67. uint fam;
  68. uint ver;
  69. uint major, minor;
  70. int i;
  71. u32 ddr_ratio;
  72. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  73. svr = get_svr();
  74. ver = SVR_SOC_VER(svr);
  75. major = SVR_MAJ(svr);
  76. minor = SVR_MIN(svr);
  77. puts("CPU: ");
  78. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  79. if (cpu_type_list[i].soc_ver == ver) {
  80. puts(cpu_type_list[i].name);
  81. break;
  82. }
  83. if (i == ARRAY_SIZE(cpu_type_list))
  84. puts("Unknown");
  85. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  86. pvr = get_pvr();
  87. fam = PVR_FAM(pvr);
  88. ver = PVR_VER(pvr);
  89. major = PVR_MAJ(pvr);
  90. minor = PVR_MIN(pvr);
  91. printf("Core: ");
  92. switch (fam) {
  93. case PVR_FAM(PVR_85xx):
  94. puts("E500");
  95. break;
  96. default:
  97. puts("Unknown");
  98. break;
  99. }
  100. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  101. get_sys_info(&sysinfo);
  102. puts("Clock Configuration:\n");
  103. printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  104. printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
  105. ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
  106. switch (ddr_ratio) {
  107. case 0x0:
  108. printf(" DDR:%4lu MHz, ", sysinfo.freqDDRBus / 2000000);
  109. break;
  110. case 0x7:
  111. printf(" DDR:%4lu MHz (Synchronous), ", sysinfo.freqDDRBus / 2000000);
  112. break;
  113. default:
  114. printf(" DDR:%4lu MHz (Asynchronous), ", sysinfo.freqDDRBus / 2000000);
  115. break;
  116. }
  117. #if defined(CFG_LBC_LCRR)
  118. lcrr = CFG_LBC_LCRR;
  119. #else
  120. {
  121. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  122. lcrr = lbc->lcrr;
  123. }
  124. #endif
  125. clkdiv = lcrr & 0x0f;
  126. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  127. #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
  128. /*
  129. * Yes, the entire PQ38 family use the same
  130. * bit-representation for twice the clock divider values.
  131. */
  132. clkdiv *= 2;
  133. #endif
  134. printf("LBC:%4lu MHz\n",
  135. sysinfo.freqSystemBus / 1000000 / clkdiv);
  136. } else {
  137. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  138. }
  139. #ifdef CONFIG_CPM2
  140. printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
  141. #endif
  142. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  143. return 0;
  144. }
  145. /* ------------------------------------------------------------------------- */
  146. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  147. {
  148. uint pvr;
  149. uint ver;
  150. pvr = get_pvr();
  151. ver = PVR_VER(pvr);
  152. if (ver & 1){
  153. /* e500 v2 core has reset control register */
  154. volatile unsigned int * rstcr;
  155. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  156. *rstcr = 0x2; /* HRESET_REQ */
  157. }else{
  158. /*
  159. * Initiate hard reset in debug control register DBCR0
  160. * Make sure MSR[DE] = 1
  161. */
  162. unsigned long val, msr;
  163. msr = mfmsr ();
  164. msr |= MSR_DE;
  165. mtmsr (msr);
  166. val = mfspr(DBCR0);
  167. val |= 0x70000000;
  168. mtspr(DBCR0,val);
  169. }
  170. return 1;
  171. }
  172. /*
  173. * Get timebase clock frequency
  174. */
  175. unsigned long get_tbclk (void)
  176. {
  177. sys_info_t sys_info;
  178. get_sys_info(&sys_info);
  179. return ((sys_info.freqSystemBus + 7L) / 8L);
  180. }
  181. #if defined(CONFIG_WATCHDOG)
  182. void
  183. watchdog_reset(void)
  184. {
  185. int re_enable = disable_interrupts();
  186. reset_85xx_watchdog();
  187. if (re_enable) enable_interrupts();
  188. }
  189. void
  190. reset_85xx_watchdog(void)
  191. {
  192. /*
  193. * Clear TSR(WIS) bit by writing 1
  194. */
  195. unsigned long val;
  196. val = mfspr(SPRN_TSR);
  197. val |= TSR_WIS;
  198. mtspr(SPRN_TSR, val);
  199. }
  200. #endif /* CONFIG_WATCHDOG */
  201. #if defined(CONFIG_DDR_ECC)
  202. void dma_init(void) {
  203. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  204. dma->satr0 = 0x02c40000;
  205. dma->datr0 = 0x02c40000;
  206. dma->sr0 = 0xfffffff; /* clear any errors */
  207. asm("sync; isync; msync");
  208. return;
  209. }
  210. uint dma_check(void) {
  211. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  212. volatile uint status = dma->sr0;
  213. /* While the channel is busy, spin */
  214. while((status & 4) == 4) {
  215. status = dma->sr0;
  216. }
  217. /* clear MR0[CS] channel start bit */
  218. dma->mr0 &= 0x00000001;
  219. asm("sync;isync;msync");
  220. if (status != 0) {
  221. printf ("DMA Error: status = %x\n", status);
  222. }
  223. return status;
  224. }
  225. int dma_xfer(void *dest, uint count, void *src) {
  226. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  227. dma->dar0 = (uint) dest;
  228. dma->sar0 = (uint) src;
  229. dma->bcr0 = count;
  230. dma->mr0 = 0xf000004;
  231. asm("sync;isync;msync");
  232. dma->mr0 = 0xf000005;
  233. asm("sync;isync;msync");
  234. return dma_check();
  235. }
  236. #endif