cpu.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. unsigned long val, msr;
  155. pvr = get_pvr();
  156. ver = PVR_VER(pvr);
  157. if (ver & 1){
  158. /* e500 v2 core has reset control register */
  159. volatile unsigned int * rstcr;
  160. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  161. *rstcr = 0x2; /* HRESET_REQ */
  162. udelay(100);
  163. }
  164. /*
  165. * Fallthrough if the code above failed
  166. * Initiate hard reset in debug control register DBCR0
  167. * Make sure MSR[DE] = 1
  168. */
  169. msr = mfmsr ();
  170. msr |= MSR_DE;
  171. mtmsr (msr);
  172. val = mfspr(DBCR0);
  173. val |= 0x70000000;
  174. mtspr(DBCR0,val);
  175. return 1;
  176. }
  177. /*
  178. * Get timebase clock frequency
  179. */
  180. unsigned long get_tbclk (void)
  181. {
  182. return (gd->bus_clk + 4UL)/8UL;
  183. }
  184. #if defined(CONFIG_WATCHDOG)
  185. void
  186. watchdog_reset(void)
  187. {
  188. int re_enable = disable_interrupts();
  189. reset_85xx_watchdog();
  190. if (re_enable) enable_interrupts();
  191. }
  192. void
  193. reset_85xx_watchdog(void)
  194. {
  195. /*
  196. * Clear TSR(WIS) bit by writing 1
  197. */
  198. unsigned long val;
  199. val = mfspr(SPRN_TSR);
  200. val |= TSR_WIS;
  201. mtspr(SPRN_TSR, val);
  202. }
  203. #endif /* CONFIG_WATCHDOG */
  204. #if defined(CONFIG_DDR_ECC)
  205. void dma_init(void) {
  206. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  207. dma->satr0 = 0x02c40000;
  208. dma->datr0 = 0x02c40000;
  209. dma->sr0 = 0xfffffff; /* clear any errors */
  210. asm("sync; isync; msync");
  211. return;
  212. }
  213. uint dma_check(void) {
  214. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  215. volatile uint status = dma->sr0;
  216. /* While the channel is busy, spin */
  217. while((status & 4) == 4) {
  218. status = dma->sr0;
  219. }
  220. /* clear MR0[CS] channel start bit */
  221. dma->mr0 &= 0x00000001;
  222. asm("sync;isync;msync");
  223. if (status != 0) {
  224. printf ("DMA Error: status = %x\n", status);
  225. }
  226. return status;
  227. }
  228. int dma_xfer(void *dest, uint count, void *src) {
  229. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  230. dma->dar0 = (uint) dest;
  231. dma->sar0 = (uint) src;
  232. dma->bcr0 = count;
  233. dma->mr0 = 0xf000004;
  234. asm("sync;isync;msync");
  235. dma->mr0 = 0xf000005;
  236. asm("sync;isync;msync");
  237. return dma_check();
  238. }
  239. #endif