cpu.c 6.5 KB

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