cpu.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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, msr;
  149. msr = mfmsr ();
  150. msr |= MSR_DE;
  151. mtmsr (msr);
  152. val = mfspr(DBCR0);
  153. val |= 0x70000000;
  154. mtspr(DBCR0,val);
  155. }
  156. return 1;
  157. }
  158. /*
  159. * Get timebase clock frequency
  160. */
  161. unsigned long get_tbclk (void)
  162. {
  163. sys_info_t sys_info;
  164. get_sys_info(&sys_info);
  165. return ((sys_info.freqSystemBus + 7L) / 8L);
  166. }
  167. #if defined(CONFIG_WATCHDOG)
  168. void
  169. watchdog_reset(void)
  170. {
  171. int re_enable = disable_interrupts();
  172. reset_85xx_watchdog();
  173. if (re_enable) enable_interrupts();
  174. }
  175. void
  176. reset_85xx_watchdog(void)
  177. {
  178. /*
  179. * Clear TSR(WIS) bit by writing 1
  180. */
  181. unsigned long val;
  182. val = mfspr(SPRN_TSR);
  183. val |= TSR_WIS;
  184. mtspr(SPRN_TSR, val);
  185. }
  186. #endif /* CONFIG_WATCHDOG */
  187. #if defined(CONFIG_DDR_ECC)
  188. void dma_init(void) {
  189. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  190. volatile ccsr_dma_t *dma = &immap->im_dma;
  191. dma->satr0 = 0x02c40000;
  192. dma->datr0 = 0x02c40000;
  193. dma->sr0 = 0xfffffff; /* clear any errors */
  194. asm("sync; isync; msync");
  195. return;
  196. }
  197. uint dma_check(void) {
  198. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  199. volatile ccsr_dma_t *dma = &immap->im_dma;
  200. volatile uint status = dma->sr0;
  201. /* While the channel is busy, spin */
  202. while((status & 4) == 4) {
  203. status = dma->sr0;
  204. }
  205. /* clear MR0[CS] channel start bit */
  206. dma->mr0 &= 0x00000001;
  207. asm("sync;isync;msync");
  208. if (status != 0) {
  209. printf ("DMA Error: status = %x\n", status);
  210. }
  211. return status;
  212. }
  213. int dma_xfer(void *dest, uint count, void *src) {
  214. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  215. volatile ccsr_dma_t *dma = &immap->im_dma;
  216. dma->dar0 = (uint) dest;
  217. dma->sar0 = (uint) src;
  218. dma->bcr0 = count;
  219. dma->mr0 = 0xf000004;
  220. asm("sync;isync;msync");
  221. dma->mr0 = 0xf000005;
  222. asm("sync;isync;msync");
  223. return dma_check();
  224. }
  225. #endif
  226. #ifdef CONFIG_OF_FLAT_TREE
  227. void
  228. ft_cpu_setup(void *blob, bd_t *bd)
  229. {
  230. u32 *p;
  231. ulong clock;
  232. int len;
  233. clock = bd->bi_busfreq;
  234. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  235. if (p != NULL)
  236. *p = cpu_to_be32(clock);
  237. p = ft_get_prop(blob, "/qe@e0080000/" OF_CPU "/bus-frequency", &len);
  238. if (p != NULL)
  239. *p = cpu_to_be32(clock);
  240. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  241. if (p != NULL)
  242. *p = cpu_to_be32(clock);
  243. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  244. if (p != NULL)
  245. *p = cpu_to_be32(clock);
  246. #if defined(CONFIG_HAS_ETH0)
  247. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  248. if (p)
  249. memcpy(p, bd->bi_enetaddr, 6);
  250. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  251. if (p)
  252. memcpy(p, bd->bi_enetaddr, 6);
  253. #endif
  254. #if defined(CONFIG_HAS_ETH1)
  255. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  256. if (p)
  257. memcpy(p, bd->bi_enet1addr, 6);
  258. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  259. if (p)
  260. memcpy(p, bd->bi_enet1addr, 6);
  261. #endif
  262. #if defined(CONFIG_HAS_ETH2)
  263. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  264. if (p)
  265. memcpy(p, bd->bi_enet2addr, 6);
  266. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
  267. if (p)
  268. memcpy(p, bd->bi_enet2addr, 6);
  269. #ifdef CONFIG_UEC_ETH
  270. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
  271. if (p)
  272. memcpy(p, bd->bi_enet2addr, 6);
  273. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
  274. if (p)
  275. memcpy(p, bd->bi_enet2addr, 6);
  276. #endif
  277. #endif
  278. #if defined(CONFIG_HAS_ETH3)
  279. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  280. if (p)
  281. memcpy(p, bd->bi_enet3addr, 6);
  282. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
  283. if (p)
  284. memcpy(p, bd->bi_enet3addr, 6);
  285. #ifdef CONFIG_UEC_ETH
  286. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
  287. if (p)
  288. memcpy(p, bd->bi_enet3addr, 6);
  289. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
  290. if (p)
  291. memcpy(p, bd->bi_enet3addr, 6);
  292. #endif
  293. #endif
  294. }
  295. #endif