cpu.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright 2004,2007 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. #if defined(CONFIG_OF_FLAT_TREE)
  32. #include <ft_build.h>
  33. #endif
  34. int checkcpu (void)
  35. {
  36. sys_info_t sysinfo;
  37. uint lcrr; /* local bus clock ratio register */
  38. uint clkdiv; /* clock divider portion of lcrr */
  39. uint pvr, svr;
  40. uint fam;
  41. uint ver;
  42. uint major, minor;
  43. svr = get_svr();
  44. ver = SVR_VER(svr);
  45. major = SVR_MAJ(svr);
  46. minor = SVR_MIN(svr);
  47. puts("CPU: ");
  48. switch (ver) {
  49. case SVR_8540:
  50. puts("8540");
  51. break;
  52. case SVR_8541:
  53. puts("8541");
  54. break;
  55. case SVR_8555:
  56. puts("8555");
  57. break;
  58. case SVR_8560:
  59. puts("8560");
  60. break;
  61. case SVR_8548:
  62. puts("8548");
  63. break;
  64. case SVR_8548_E:
  65. puts("8548_E");
  66. break;
  67. case SVR_8544:
  68. puts("8544");
  69. break;
  70. case SVR_8544_E:
  71. puts("8544_E");
  72. break;
  73. case SVR_8568_E:
  74. puts("8568_E");
  75. break;
  76. default:
  77. puts("Unknown");
  78. break;
  79. }
  80. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  81. pvr = get_pvr();
  82. fam = PVR_FAM(pvr);
  83. ver = PVR_VER(pvr);
  84. major = PVR_MAJ(pvr);
  85. minor = PVR_MIN(pvr);
  86. printf("Core: ");
  87. switch (fam) {
  88. case PVR_FAM(PVR_85xx):
  89. puts("E500");
  90. break;
  91. default:
  92. puts("Unknown");
  93. break;
  94. }
  95. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  96. get_sys_info(&sysinfo);
  97. puts("Clock Configuration:\n");
  98. printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  99. printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
  100. printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  101. #if defined(CFG_LBC_LCRR)
  102. lcrr = CFG_LBC_LCRR;
  103. #else
  104. {
  105. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  106. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  107. lcrr = lbc->lcrr;
  108. }
  109. #endif
  110. clkdiv = lcrr & 0x0f;
  111. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  112. #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
  113. /*
  114. * Yes, the entire PQ38 family use the same
  115. * bit-representation for twice the clock divider values.
  116. */
  117. clkdiv *= 2;
  118. #endif
  119. printf("LBC:%4lu MHz\n",
  120. sysinfo.freqSystemBus / 1000000 / clkdiv);
  121. } else {
  122. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  123. }
  124. if (ver == SVR_8560) {
  125. printf("CPM: %lu Mhz\n",
  126. sysinfo.freqSystemBus / 1000000);
  127. }
  128. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  129. return 0;
  130. }
  131. /* ------------------------------------------------------------------------- */
  132. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  133. {
  134. uint pvr;
  135. uint ver;
  136. pvr = get_pvr();
  137. ver = PVR_VER(pvr);
  138. if (ver & 1){
  139. /* e500 v2 core has reset control register */
  140. volatile unsigned int * rstcr;
  141. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  142. *rstcr = 0x2; /* HRESET_REQ */
  143. }else{
  144. /*
  145. * Initiate hard reset in debug control register DBCR0
  146. * Make sure MSR[DE] = 1
  147. */
  148. unsigned long val;
  149. val = mfspr(DBCR0);
  150. val |= 0x70000000;
  151. mtspr(DBCR0,val);
  152. }
  153. return 1;
  154. }
  155. /*
  156. * Get timebase clock frequency
  157. */
  158. unsigned long get_tbclk (void)
  159. {
  160. sys_info_t sys_info;
  161. get_sys_info(&sys_info);
  162. return ((sys_info.freqSystemBus + 7L) / 8L);
  163. }
  164. #if defined(CONFIG_WATCHDOG)
  165. void
  166. watchdog_reset(void)
  167. {
  168. int re_enable = disable_interrupts();
  169. reset_85xx_watchdog();
  170. if (re_enable) enable_interrupts();
  171. }
  172. void
  173. reset_85xx_watchdog(void)
  174. {
  175. /*
  176. * Clear TSR(WIS) bit by writing 1
  177. */
  178. unsigned long val;
  179. val = mfspr(SPRN_TSR);
  180. val |= TSR_WIS;
  181. mtspr(SPRN_TSR, val);
  182. }
  183. #endif /* CONFIG_WATCHDOG */
  184. #if defined(CONFIG_DDR_ECC)
  185. void dma_init(void) {
  186. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  187. volatile ccsr_dma_t *dma = &immap->im_dma;
  188. dma->satr0 = 0x02c40000;
  189. dma->datr0 = 0x02c40000;
  190. dma->sr0 = 0xfffffff; /* clear any errors */
  191. asm("sync; isync; msync");
  192. return;
  193. }
  194. uint dma_check(void) {
  195. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  196. volatile ccsr_dma_t *dma = &immap->im_dma;
  197. volatile uint status = dma->sr0;
  198. /* While the channel is busy, spin */
  199. while((status & 4) == 4) {
  200. status = dma->sr0;
  201. }
  202. /* clear MR0[CS] channel start bit */
  203. dma->mr0 &= 0x00000001;
  204. asm("sync;isync;msync");
  205. if (status != 0) {
  206. printf ("DMA Error: status = %x\n", status);
  207. }
  208. return status;
  209. }
  210. int dma_xfer(void *dest, uint count, void *src) {
  211. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  212. volatile ccsr_dma_t *dma = &immap->im_dma;
  213. dma->dar0 = (uint) dest;
  214. dma->sar0 = (uint) src;
  215. dma->bcr0 = count;
  216. dma->mr0 = 0xf000004;
  217. asm("sync;isync;msync");
  218. dma->mr0 = 0xf000005;
  219. asm("sync;isync;msync");
  220. return dma_check();
  221. }
  222. #endif
  223. #ifdef CONFIG_OF_FLAT_TREE
  224. void
  225. ft_cpu_setup(void *blob, bd_t *bd)
  226. {
  227. u32 *p;
  228. ulong clock;
  229. int len;
  230. clock = bd->bi_busfreq;
  231. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  232. if (p != NULL)
  233. *p = cpu_to_be32(clock);
  234. p = ft_get_prop(blob, "/qe@e0080000/" OF_CPU "/bus-frequency", &len);
  235. if (p != NULL)
  236. *p = cpu_to_be32(clock);
  237. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  238. if (p != NULL)
  239. *p = cpu_to_be32(clock);
  240. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  241. if (p != NULL)
  242. *p = cpu_to_be32(clock);
  243. #if defined(CONFIG_MPC85XX_TSEC1)
  244. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  245. if (p)
  246. memcpy(p, bd->bi_enetaddr, 6);
  247. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  248. if (p)
  249. memcpy(p, bd->bi_enetaddr, 6);
  250. #endif
  251. #if defined(CONFIG_HAS_ETH1)
  252. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  253. if (p)
  254. memcpy(p, bd->bi_enet1addr, 6);
  255. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  256. if (p)
  257. memcpy(p, bd->bi_enet1addr, 6);
  258. #endif
  259. #if defined(CONFIG_HAS_ETH2)
  260. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  261. if (p)
  262. memcpy(p, bd->bi_enet2addr, 6);
  263. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
  264. if (p)
  265. memcpy(p, bd->bi_enet2addr, 6);
  266. #endif
  267. #if defined(CONFIG_HAS_ETH3)
  268. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  269. if (p)
  270. memcpy(p, bd->bi_enet3addr, 6);
  271. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
  272. if (p)
  273. memcpy(p, bd->bi_enet3addr, 6);
  274. #endif
  275. }
  276. #endif