cpu.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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, ", sysinfo.freqProcessor / 1000000);
  105. printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
  106. ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
  107. switch (ddr_ratio) {
  108. case 0x0:
  109. printf(" DDR:%4lu MHz, ", sysinfo.freqDDRBus / 2000000);
  110. break;
  111. case 0x7:
  112. printf(" DDR:%4lu MHz (Synchronous), ", sysinfo.freqDDRBus / 2000000);
  113. break;
  114. default:
  115. printf(" DDR:%4lu MHz (Asynchronous), ", sysinfo.freqDDRBus / 2000000);
  116. break;
  117. }
  118. #if defined(CFG_LBC_LCRR)
  119. lcrr = CFG_LBC_LCRR;
  120. #else
  121. {
  122. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  123. lcrr = lbc->lcrr;
  124. }
  125. #endif
  126. clkdiv = lcrr & 0x0f;
  127. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  128. #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
  129. /*
  130. * Yes, the entire PQ38 family use the same
  131. * bit-representation for twice the clock divider values.
  132. */
  133. clkdiv *= 2;
  134. #endif
  135. printf("LBC:%4lu MHz\n",
  136. sysinfo.freqSystemBus / 1000000 / clkdiv);
  137. } else {
  138. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  139. }
  140. #ifdef CONFIG_CPM2
  141. printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
  142. #endif
  143. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  144. return 0;
  145. }
  146. /* ------------------------------------------------------------------------- */
  147. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  148. {
  149. uint pvr;
  150. uint ver;
  151. pvr = get_pvr();
  152. ver = PVR_VER(pvr);
  153. if (ver & 1){
  154. /* e500 v2 core has reset control register */
  155. volatile unsigned int * rstcr;
  156. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  157. *rstcr = 0x2; /* HRESET_REQ */
  158. }else{
  159. /*
  160. * Initiate hard reset in debug control register DBCR0
  161. * Make sure MSR[DE] = 1
  162. */
  163. unsigned long val, msr;
  164. msr = mfmsr ();
  165. msr |= MSR_DE;
  166. mtmsr (msr);
  167. val = mfspr(DBCR0);
  168. val |= 0x70000000;
  169. mtspr(DBCR0,val);
  170. }
  171. return 1;
  172. }
  173. /*
  174. * Get timebase clock frequency
  175. */
  176. unsigned long get_tbclk (void)
  177. {
  178. return (gd->bus_clk + 4UL)/8UL;
  179. }
  180. #if defined(CONFIG_WATCHDOG)
  181. void
  182. watchdog_reset(void)
  183. {
  184. int re_enable = disable_interrupts();
  185. reset_85xx_watchdog();
  186. if (re_enable) enable_interrupts();
  187. }
  188. void
  189. reset_85xx_watchdog(void)
  190. {
  191. /*
  192. * Clear TSR(WIS) bit by writing 1
  193. */
  194. unsigned long val;
  195. val = mfspr(SPRN_TSR);
  196. val |= TSR_WIS;
  197. mtspr(SPRN_TSR, val);
  198. }
  199. #endif /* CONFIG_WATCHDOG */
  200. #if defined(CONFIG_DDR_ECC)
  201. void dma_init(void) {
  202. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  203. dma->satr0 = 0x02c40000;
  204. dma->datr0 = 0x02c40000;
  205. dma->sr0 = 0xfffffff; /* clear any errors */
  206. asm("sync; isync; msync");
  207. return;
  208. }
  209. uint dma_check(void) {
  210. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  211. volatile uint status = dma->sr0;
  212. /* While the channel is busy, spin */
  213. while((status & 4) == 4) {
  214. status = dma->sr0;
  215. }
  216. /* clear MR0[CS] channel start bit */
  217. dma->mr0 &= 0x00000001;
  218. asm("sync;isync;msync");
  219. if (status != 0) {
  220. printf ("DMA Error: status = %x\n", status);
  221. }
  222. return status;
  223. }
  224. int dma_xfer(void *dest, uint count, void *src) {
  225. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  226. dma->dar0 = (uint) dest;
  227. dma->sar0 = (uint) src;
  228. dma->bcr0 = count;
  229. dma->mr0 = 0xf000004;
  230. asm("sync;isync;msync");
  231. dma->mr0 = 0xf000005;
  232. asm("sync;isync;msync");
  233. return dma_check();
  234. }
  235. #endif