1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * written or collected and sometimes rewritten by
13 * Magnus Damm <damm@bitsmart.com>
15 * minor modifications by
16 * Wolfgang Denk <wd@denx.de>
26 #include <asm/cache.h>
27 #include <asm/cpm_8xx.h>
28 #include <linux/compiler.h>
31 #if defined(CONFIG_OF_LIBFDT)
32 #include <linux/libfdt.h>
33 #include <fdt_support.h>
36 DECLARE_GLOBAL_DATA_PTR;
38 static int check_CPU(long clock, uint pvr, uint immr)
40 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
44 /* the highest 16 bits should be 0x0050 for a 860 */
46 if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
50 in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
53 * Some boards use sockets so different CPUs can be used.
54 * We have to check chip version in run time.
57 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
58 case 0x08010004: /* Rev. A.0 */
59 printf("MPC866xxxZPnnA");
61 case 0x08000003: /* Rev. 0.3 */
62 printf("MPC866xxxZPnn");
64 case 0x09000000: /* 870/875/880/885 */
69 printf("unknown MPC86x (0x%08x)", k);
73 printf(" at %s MHz: ", strmhz(buf, clock));
75 print_size(checkicache(), " I-Cache ");
76 print_size(checkdcache(), " D-Cache");
78 /* do we have a FEC (860T/P or 852/859/866/885)? */
80 out_be32(&immap->im_cpm.cp_fec.fec_addr_low, 0x12345678);
81 if (in_be32(&immap->im_cpm.cp_fec.fec_addr_low) == 0x12345678)
82 printf(" FEC present");
89 /* ------------------------------------------------------------------------- */
93 ulong clock = gd->cpu_clk;
94 uint immr = get_immr(); /* Return full IMMR contents */
99 return check_CPU(clock, pvr, immr);
102 /* ------------------------------------------------------------------------- */
105 int checkicache(void)
107 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
108 memctl8xx_t __iomem *memctl = &immap->im_memctl;
109 u32 cacheon = rd_ic_cst() & IDC_ENABLED;
110 /* probe in flash memoryarea */
111 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
115 wr_ic_cst(IDC_UNALL);
116 wr_ic_cst(IDC_INVALL);
117 wr_ic_cst(IDC_DISABLE);
118 __asm__ volatile ("isync");
120 while (!((m = rd_ic_cst()) & IDC_CERR2)) {
122 wr_ic_cst(IDC_LDLCK);
123 __asm__ volatile ("isync");
126 k += 0x10; /* the number of bytes in a cacheline */
129 wr_ic_cst(IDC_UNALL);
130 wr_ic_cst(IDC_INVALL);
133 wr_ic_cst(IDC_ENABLE);
135 wr_ic_cst(IDC_DISABLE);
137 __asm__ volatile ("isync");
142 /* ------------------------------------------------------------------------- */
144 /* call with cache disabled */
146 int checkdcache(void)
148 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
149 memctl8xx_t __iomem *memctl = &immap->im_memctl;
150 u32 cacheon = rd_dc_cst() & IDC_ENABLED;
151 /* probe in flash memoryarea */
152 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
156 wr_dc_cst(IDC_UNALL);
157 wr_dc_cst(IDC_INVALL);
158 wr_dc_cst(IDC_DISABLE);
160 while (!((m = rd_dc_cst()) & IDC_CERR2)) {
162 wr_dc_cst(IDC_LDLCK);
164 k += 0x10; /* the number of bytes in a cacheline */
167 wr_dc_cst(IDC_UNALL);
168 wr_dc_cst(IDC_INVALL);
171 wr_dc_cst(IDC_ENABLE);
173 wr_dc_cst(IDC_DISABLE);
178 /* ------------------------------------------------------------------------- */
180 void upmconfig(uint upm, uint *table, uint size)
184 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
185 memctl8xx_t __iomem *memctl = &immap->im_memctl;
187 for (i = 0; i < size; i++) {
188 out_be32(&memctl->memc_mdr, table[i]); /* (16-15) */
189 out_be32(&memctl->memc_mcr, addr | upm); /* (16-16) */
194 /* ------------------------------------------------------------------------- */
196 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
200 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
202 /* Checkstop Reset enable */
203 setbits_be32(&immap->im_clkrst.car_plprcr, PLPRCR_CSR);
205 /* Interrupts and MMU off */
206 __asm__ volatile ("mtspr 81, 0");
207 __asm__ volatile ("mfmsr %0" : "=r" (msr));
210 __asm__ volatile ("mtmsr %0" : : "r" (msr));
213 * Trying to execute the next instruction at a non-existing address
214 * should cause a machine check, resulting in reset
216 #ifdef CONFIG_SYS_RESET_ADDRESS
217 addr = CONFIG_SYS_RESET_ADDRESS;
220 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
221 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid address.
222 * Better pick an address known to be invalid on your system and assign
223 * it to CONFIG_SYS_RESET_ADDRESS.
224 * "(ulong)-1" used to be a good choice for many systems...
226 addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
228 ((void (*)(void)) addr)();
232 /* ------------------------------------------------------------------------- */
235 * Get timebase clock frequency (like cpu_clk in Hz)
237 * See sections 14.2 and 14.6 of the User's Manual
239 unsigned long get_tbclk(void)
241 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
242 ulong oscclk, factor, pll;
244 if (in_be32(&immap->im_clkrst.car_sccr) & SCCR_TBS)
245 return gd->cpu_clk / 16;
247 pll = in_be32(&immap->im_clkrst.car_plprcr);
249 #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
252 * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication
253 * factor is calculated as follows:
258 * factor = -----------------
262 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD) + 1)) /
263 (PLPRCR_val(PDF) + 1) / (1 << PLPRCR_val(S));
265 oscclk = gd->cpu_clk / factor;
267 if ((in_be32(&immap->im_clkrst.car_sccr) & SCCR_RTSEL) == 0 ||
275 * Initializes on-chip ethernet controllers.
276 * to override, implement board_eth_init()
278 int cpu_eth_init(bd_t *bis)
280 #if defined(CONFIG_MPC8XX_FEC)