cpu.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  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. default:
  68. puts("Unknown");
  69. break;
  70. }
  71. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  72. pvr = get_pvr();
  73. fam = PVR_FAM(pvr);
  74. ver = PVR_VER(pvr);
  75. major = PVR_MAJ(pvr);
  76. minor = PVR_MIN(pvr);
  77. printf("Core: ");
  78. switch (fam) {
  79. case PVR_FAM(PVR_85xx):
  80. puts("E500");
  81. break;
  82. default:
  83. puts("Unknown");
  84. break;
  85. }
  86. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  87. get_sys_info(&sysinfo);
  88. puts("Clock Configuration:\n");
  89. printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  90. printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
  91. printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  92. #if defined(CFG_LBC_LCRR)
  93. lcrr = CFG_LBC_LCRR;
  94. #else
  95. {
  96. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  97. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  98. lcrr = lbc->lcrr;
  99. }
  100. #endif
  101. clkdiv = lcrr & 0x0f;
  102. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  103. #ifdef CONFIG_MPC8548
  104. /*
  105. * Yes, the entire PQ38 family use the same
  106. * bit-representation for twice the clock divider values.
  107. */
  108. clkdiv *= 2;
  109. #endif
  110. printf("LBC:%4lu MHz\n",
  111. sysinfo.freqSystemBus / 1000000 / clkdiv);
  112. } else {
  113. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  114. }
  115. if (ver == SVR_8560) {
  116. printf("CPM: %lu Mhz\n",
  117. sysinfo.freqSystemBus / 1000000);
  118. }
  119. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  120. return 0;
  121. }
  122. /* ------------------------------------------------------------------------- */
  123. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  124. {
  125. /*
  126. * Initiate hard reset in debug control register DBCR0
  127. * Make sure MSR[DE] = 1
  128. */
  129. unsigned long val;
  130. val = mfspr(DBCR0);
  131. val |= 0x70000000;
  132. mtspr(DBCR0,val);
  133. return 1;
  134. }
  135. /*
  136. * Get timebase clock frequency
  137. */
  138. unsigned long get_tbclk (void)
  139. {
  140. sys_info_t sys_info;
  141. get_sys_info(&sys_info);
  142. return ((sys_info.freqSystemBus + 7L) / 8L);
  143. }
  144. #if defined(CONFIG_WATCHDOG)
  145. void
  146. watchdog_reset(void)
  147. {
  148. int re_enable = disable_interrupts();
  149. reset_85xx_watchdog();
  150. if (re_enable) enable_interrupts();
  151. }
  152. void
  153. reset_85xx_watchdog(void)
  154. {
  155. /*
  156. * Clear TSR(WIS) bit by writing 1
  157. */
  158. unsigned long val;
  159. val = mfspr(tsr);
  160. val |= 0x40000000;
  161. mtspr(tsr, val);
  162. }
  163. #endif /* CONFIG_WATCHDOG */
  164. #if defined(CONFIG_DDR_ECC)
  165. void dma_init(void) {
  166. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  167. volatile ccsr_dma_t *dma = &immap->im_dma;
  168. dma->satr0 = 0x02c40000;
  169. dma->datr0 = 0x02c40000;
  170. asm("sync; isync; msync");
  171. return;
  172. }
  173. uint dma_check(void) {
  174. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  175. volatile ccsr_dma_t *dma = &immap->im_dma;
  176. volatile uint status = dma->sr0;
  177. /* While the channel is busy, spin */
  178. while((status & 4) == 4) {
  179. status = dma->sr0;
  180. }
  181. if (status != 0) {
  182. printf ("DMA Error: status = %x\n", status);
  183. }
  184. return status;
  185. }
  186. int dma_xfer(void *dest, uint count, void *src) {
  187. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  188. volatile ccsr_dma_t *dma = &immap->im_dma;
  189. dma->dar0 = (uint) dest;
  190. dma->sar0 = (uint) src;
  191. dma->bcr0 = count;
  192. dma->mr0 = 0xf000004;
  193. asm("sync;isync;msync");
  194. dma->mr0 = 0xf000005;
  195. asm("sync;isync;msync");
  196. return dma_check();
  197. }
  198. #endif
  199. #ifdef CONFIG_OF_FLAT_TREE
  200. void
  201. ft_cpu_setup(void *blob, bd_t *bd)
  202. {
  203. u32 *p;
  204. ulong clock;
  205. int len;
  206. clock = bd->bi_busfreq;
  207. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  208. if (p != NULL)
  209. *p = cpu_to_be32(clock);
  210. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  211. if (p != NULL)
  212. *p = cpu_to_be32(clock);
  213. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  214. if (p != NULL)
  215. *p = cpu_to_be32(clock);
  216. #if defined(CONFIG_MPC85XX_TSEC1)
  217. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  218. memcpy(p, bd->bi_enetaddr, 6);
  219. #endif
  220. #if defined(CONFIG_HAS_ETH1)
  221. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  222. memcpy(p, bd->bi_enet1addr, 6);
  223. #endif
  224. #if defined(CONFIG_HAS_ETH2)
  225. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  226. memcpy(p, bd->bi_enet2addr, 6);
  227. #endif
  228. #if defined(CONFIG_HAS_ETH3)
  229. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  230. memcpy(p, bd->bi_enet3addr, 6);
  231. #endif
  232. }
  233. #endif