cpu.c 6.5 KB

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