cpu.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * m8xx.c
  9. *
  10. * CPU specific code
  11. *
  12. * written or collected and sometimes rewritten by
  13. * Magnus Damm <damm@bitsmart.com>
  14. *
  15. * minor modifications by
  16. * Wolfgang Denk <wd@denx.de>
  17. */
  18. #include <common.h>
  19. #include <watchdog.h>
  20. #include <command.h>
  21. #include <mpc8xx.h>
  22. #include <netdev.h>
  23. #include <asm/cache.h>
  24. #include <asm/cpm_8xx.h>
  25. #include <linux/compiler.h>
  26. #include <asm/io.h>
  27. #if defined(CONFIG_OF_LIBFDT)
  28. #include <linux/libfdt.h>
  29. #include <fdt_support.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. static int check_CPU(long clock, uint pvr, uint immr)
  33. {
  34. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  35. uint k;
  36. char buf[32];
  37. /* the highest 16 bits should be 0x0050 for a 860 */
  38. if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
  39. return -1;
  40. k = (immr << 16) |
  41. in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
  42. /*
  43. * Some boards use sockets so different CPUs can be used.
  44. * We have to check chip version in run time.
  45. */
  46. switch (k) {
  47. /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
  48. case 0x08010004: /* Rev. A.0 */
  49. printf("MPC866xxxZPnnA");
  50. break;
  51. case 0x08000003: /* Rev. 0.3 */
  52. printf("MPC866xxxZPnn");
  53. break;
  54. case 0x09000000: /* 870/875/880/885 */
  55. puts("MPC885ZPnn");
  56. break;
  57. default:
  58. printf("unknown MPC86x (0x%08x)", k);
  59. break;
  60. }
  61. printf(" at %s MHz: ", strmhz(buf, clock));
  62. print_size(checkicache(), " I-Cache ");
  63. print_size(checkdcache(), " D-Cache");
  64. /* do we have a FEC (860T/P or 852/859/866/885)? */
  65. out_be32(&immap->im_cpm.cp_fec.fec_addr_low, 0x12345678);
  66. if (in_be32(&immap->im_cpm.cp_fec.fec_addr_low) == 0x12345678)
  67. printf(" FEC present");
  68. putc('\n');
  69. return 0;
  70. }
  71. /* ------------------------------------------------------------------------- */
  72. int checkcpu(void)
  73. {
  74. ulong clock = gd->cpu_clk;
  75. uint immr = get_immr(); /* Return full IMMR contents */
  76. uint pvr = get_pvr();
  77. puts("CPU: ");
  78. return check_CPU(clock, pvr, immr);
  79. }
  80. /* ------------------------------------------------------------------------- */
  81. /* L1 i-cache */
  82. int checkicache(void)
  83. {
  84. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  85. memctl8xx_t __iomem *memctl = &immap->im_memctl;
  86. u32 cacheon = rd_ic_cst() & IDC_ENABLED;
  87. /* probe in flash memoryarea */
  88. u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
  89. u32 m;
  90. u32 lines = -1;
  91. wr_ic_cst(IDC_UNALL);
  92. wr_ic_cst(IDC_INVALL);
  93. wr_ic_cst(IDC_DISABLE);
  94. __asm__ volatile ("isync");
  95. while (!((m = rd_ic_cst()) & IDC_CERR2)) {
  96. wr_ic_adr(k);
  97. wr_ic_cst(IDC_LDLCK);
  98. __asm__ volatile ("isync");
  99. lines++;
  100. k += 0x10; /* the number of bytes in a cacheline */
  101. }
  102. wr_ic_cst(IDC_UNALL);
  103. wr_ic_cst(IDC_INVALL);
  104. if (cacheon)
  105. wr_ic_cst(IDC_ENABLE);
  106. else
  107. wr_ic_cst(IDC_DISABLE);
  108. __asm__ volatile ("isync");
  109. return lines << 4;
  110. };
  111. /* ------------------------------------------------------------------------- */
  112. /* L1 d-cache */
  113. /* call with cache disabled */
  114. int checkdcache(void)
  115. {
  116. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  117. memctl8xx_t __iomem *memctl = &immap->im_memctl;
  118. u32 cacheon = rd_dc_cst() & IDC_ENABLED;
  119. /* probe in flash memoryarea */
  120. u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
  121. u32 m;
  122. u32 lines = -1;
  123. wr_dc_cst(IDC_UNALL);
  124. wr_dc_cst(IDC_INVALL);
  125. wr_dc_cst(IDC_DISABLE);
  126. while (!((m = rd_dc_cst()) & IDC_CERR2)) {
  127. wr_dc_adr(k);
  128. wr_dc_cst(IDC_LDLCK);
  129. lines++;
  130. k += 0x10; /* the number of bytes in a cacheline */
  131. }
  132. wr_dc_cst(IDC_UNALL);
  133. wr_dc_cst(IDC_INVALL);
  134. if (cacheon)
  135. wr_dc_cst(IDC_ENABLE);
  136. else
  137. wr_dc_cst(IDC_DISABLE);
  138. return lines << 4;
  139. };
  140. /* ------------------------------------------------------------------------- */
  141. void upmconfig(uint upm, uint *table, uint size)
  142. {
  143. uint i;
  144. uint addr = 0;
  145. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  146. memctl8xx_t __iomem *memctl = &immap->im_memctl;
  147. for (i = 0; i < size; i++) {
  148. out_be32(&memctl->memc_mdr, table[i]); /* (16-15) */
  149. out_be32(&memctl->memc_mcr, addr | upm); /* (16-16) */
  150. addr++;
  151. }
  152. }
  153. /* ------------------------------------------------------------------------- */
  154. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  155. {
  156. ulong msr, addr;
  157. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  158. /* Checkstop Reset enable */
  159. setbits_be32(&immap->im_clkrst.car_plprcr, PLPRCR_CSR);
  160. /* Interrupts and MMU off */
  161. __asm__ volatile ("mtspr 81, 0");
  162. __asm__ volatile ("mfmsr %0" : "=r" (msr));
  163. msr &= ~0x1030;
  164. __asm__ volatile ("mtmsr %0" : : "r" (msr));
  165. /*
  166. * Trying to execute the next instruction at a non-existing address
  167. * should cause a machine check, resulting in reset
  168. */
  169. #ifdef CONFIG_SYS_RESET_ADDRESS
  170. addr = CONFIG_SYS_RESET_ADDRESS;
  171. #else
  172. /*
  173. * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
  174. * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid address.
  175. * Better pick an address known to be invalid on your system and assign
  176. * it to CONFIG_SYS_RESET_ADDRESS.
  177. * "(ulong)-1" used to be a good choice for many systems...
  178. */
  179. addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
  180. #endif
  181. ((void (*)(void)) addr)();
  182. return 1;
  183. }
  184. /* ------------------------------------------------------------------------- */
  185. /*
  186. * Get timebase clock frequency (like cpu_clk in Hz)
  187. *
  188. * See sections 14.2 and 14.6 of the User's Manual
  189. */
  190. unsigned long get_tbclk(void)
  191. {
  192. immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
  193. ulong oscclk, factor, pll;
  194. if (in_be32(&immap->im_clkrst.car_sccr) & SCCR_TBS)
  195. return gd->cpu_clk / 16;
  196. pll = in_be32(&immap->im_clkrst.car_plprcr);
  197. #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
  198. /*
  199. * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication
  200. * factor is calculated as follows:
  201. *
  202. * MFN
  203. * MFI + -------
  204. * MFD + 1
  205. * factor = -----------------
  206. * (PDF + 1) * 2^S
  207. *
  208. */
  209. factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD) + 1)) /
  210. (PLPRCR_val(PDF) + 1) / (1 << PLPRCR_val(S));
  211. oscclk = gd->cpu_clk / factor;
  212. if ((in_be32(&immap->im_clkrst.car_sccr) & SCCR_RTSEL) == 0 ||
  213. factor > 2)
  214. return oscclk / 4;
  215. return oscclk / 16;
  216. }
  217. /*
  218. * Initializes on-chip ethernet controllers.
  219. * to override, implement board_eth_init()
  220. */
  221. int cpu_eth_init(bd_t *bis)
  222. {
  223. #if defined(CONFIG_MPC8XX_FEC)
  224. fec_initialize(bis);
  225. #endif
  226. return 0;
  227. }