1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
12 * written or collected and sometimes rewritten by
15 * minor modifications by
27 #include <asm/cache.h>
28 #include <asm/cpm_8xx.h>
29 #include <linux/compiler.h>
32 #if defined(CONFIG_OF_LIBFDT)
33 #include <linux/libfdt.h>
34 #include <fdt_support.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 /* ------------------------------------------------------------------------- */
44 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
45 memctl8xx_t __iomem *memctl = &immap->im_memctl;
46 u32 cacheon = rd_ic_cst() & IDC_ENABLED;
47 /* probe in flash memoryarea */
48 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
53 wr_ic_cst(IDC_INVALL);
54 wr_ic_cst(IDC_DISABLE);
55 __asm__ volatile ("isync");
57 while (!((m = rd_ic_cst()) & IDC_CERR2)) {
60 __asm__ volatile ("isync");
63 k += 0x10; /* the number of bytes in a cacheline */
67 wr_ic_cst(IDC_INVALL);
70 wr_ic_cst(IDC_ENABLE);
72 wr_ic_cst(IDC_DISABLE);
74 __asm__ volatile ("isync");
79 /* ------------------------------------------------------------------------- */
81 /* call with cache disabled */
83 static int checkdcache(void)
85 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
86 memctl8xx_t __iomem *memctl = &immap->im_memctl;
87 u32 cacheon = rd_dc_cst() & IDC_ENABLED;
88 /* probe in flash memoryarea */
89 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
94 wr_dc_cst(IDC_INVALL);
95 wr_dc_cst(IDC_DISABLE);
97 while (!((m = rd_dc_cst()) & IDC_CERR2)) {
101 k += 0x10; /* the number of bytes in a cacheline */
104 wr_dc_cst(IDC_UNALL);
105 wr_dc_cst(IDC_INVALL);
108 wr_dc_cst(IDC_ENABLE);
110 wr_dc_cst(IDC_DISABLE);
115 static int check_CPU(long clock, uint pvr, uint immr)
117 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
121 /* the highest 16 bits should be 0x0050 for a 860 */
123 if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
127 in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
130 * Some boards use sockets so different CPUs can be used.
131 * We have to check chip version in run time.
134 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
135 case 0x08010004: /* Rev. A.0 */
136 printf("MPC866xxxZPnnA");
138 case 0x08000003: /* Rev. 0.3 */
139 printf("MPC866xxxZPnn");
141 case 0x09000000: /* 870/875/880/885 */
146 printf("unknown MPC86x (0x%08x)", k);
150 printf(" at %s MHz: ", strmhz(buf, clock));
152 print_size(checkicache(), " I-Cache ");
153 print_size(checkdcache(), " D-Cache");
155 /* do we have a FEC (860T/P or 852/859/866/885)? */
157 out_be32(&immap->im_cpm.cp_fec.fec_addr_low, 0x12345678);
158 if (in_be32(&immap->im_cpm.cp_fec.fec_addr_low) == 0x12345678)
159 printf(" FEC present");
166 /* ------------------------------------------------------------------------- */
170 ulong clock = gd->cpu_clk;
171 uint immr = get_immr(); /* Return full IMMR contents */
172 uint pvr = get_pvr();
176 return check_CPU(clock, pvr, immr);
179 /* ------------------------------------------------------------------------- */
181 void upmconfig(uint upm, uint *table, uint size)
185 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
186 memctl8xx_t __iomem *memctl = &immap->im_memctl;
188 for (i = 0; i < size; i++) {
189 out_be32(&memctl->memc_mdr, table[i]); /* (16-15) */
190 out_be32(&memctl->memc_mcr, addr | upm); /* (16-16) */
195 /* ------------------------------------------------------------------------- */
197 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
201 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
203 /* Checkstop Reset enable */
204 setbits_be32(&immap->im_clkrst.car_plprcr, PLPRCR_CSR);
206 /* Interrupts and MMU off */
207 __asm__ volatile ("mtspr 81, 0");
208 __asm__ volatile ("mfmsr %0" : "=r" (msr));
211 __asm__ volatile ("mtmsr %0" : : "r" (msr));
214 * Trying to execute the next instruction at a non-existing address
215 * should cause a machine check, resulting in reset
217 #ifdef CONFIG_SYS_RESET_ADDRESS
218 addr = CONFIG_SYS_RESET_ADDRESS;
221 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
222 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid address.
223 * Better pick an address known to be invalid on your system and assign
224 * it to CONFIG_SYS_RESET_ADDRESS.
225 * "(ulong)-1" used to be a good choice for many systems...
227 addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
229 ((void (*)(void)) addr)();
233 /* ------------------------------------------------------------------------- */
236 * Get timebase clock frequency (like cpu_clk in Hz)
238 * See sections 14.2 and 14.6 of the User's Manual
240 unsigned long get_tbclk(void)
242 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
243 ulong oscclk, factor, pll;
245 if (in_be32(&immap->im_clkrst.car_sccr) & SCCR_TBS)
246 return gd->cpu_clk / 16;
248 pll = in_be32(&immap->im_clkrst.car_plprcr);
250 #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
253 * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication
254 * factor is calculated as follows:
259 * factor = -----------------
263 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD) + 1)) /
264 (PLPRCR_val(PDF) + 1) / (1 << PLPRCR_val(S));
266 oscclk = gd->cpu_clk / factor;
268 if ((in_be32(&immap->im_clkrst.car_sccr) & SCCR_RTSEL) == 0 ||
276 * Initializes on-chip ethernet controllers.
277 * to override, implement board_eth_init()
279 int cpu_eth_init(bd_t *bis)
281 #if defined(CONFIG_MPC8XX_FEC)