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>
28 #include <asm/cache.h>
29 #include <asm/cpm_8xx.h>
30 #include <asm/global_data.h>
31 #include <linux/compiler.h>
34 #if defined(CONFIG_OF_LIBFDT)
35 #include <linux/libfdt.h>
36 #include <fdt_support.h>
39 DECLARE_GLOBAL_DATA_PTR;
41 /* ------------------------------------------------------------------------- */
46 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
47 memctl8xx_t __iomem *memctl = &immap->im_memctl;
48 u32 cacheon = rd_ic_cst() & IDC_ENABLED;
49 /* probe in flash memoryarea */
50 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
55 wr_ic_cst(IDC_INVALL);
56 wr_ic_cst(IDC_DISABLE);
57 __asm__ volatile ("isync");
59 while (!((m = rd_ic_cst()) & IDC_CERR2)) {
62 __asm__ volatile ("isync");
65 k += 0x10; /* the number of bytes in a cacheline */
69 wr_ic_cst(IDC_INVALL);
72 wr_ic_cst(IDC_ENABLE);
74 wr_ic_cst(IDC_DISABLE);
76 __asm__ volatile ("isync");
81 /* ------------------------------------------------------------------------- */
83 /* call with cache disabled */
85 static int checkdcache(void)
87 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
88 memctl8xx_t __iomem *memctl = &immap->im_memctl;
89 u32 cacheon = rd_dc_cst() & IDC_ENABLED;
90 /* probe in flash memoryarea */
91 u32 k = in_be32(&memctl->memc_br0) & ~0x00007fff;
96 wr_dc_cst(IDC_INVALL);
97 wr_dc_cst(IDC_DISABLE);
99 while (!((m = rd_dc_cst()) & IDC_CERR2)) {
101 wr_dc_cst(IDC_LDLCK);
103 k += 0x10; /* the number of bytes in a cacheline */
106 wr_dc_cst(IDC_UNALL);
107 wr_dc_cst(IDC_INVALL);
110 wr_dc_cst(IDC_ENABLE);
112 wr_dc_cst(IDC_DISABLE);
117 static int check_CPU(long clock, uint pvr, uint immr)
119 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
123 /* the highest 16 bits should be 0x0050 for a 860 */
125 if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
129 in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
132 * Some boards use sockets so different CPUs can be used.
133 * We have to check chip version in run time.
136 /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
137 case 0x08010004: /* Rev. A.0 */
138 printf("MPC866xxxZPnnA");
140 case 0x08000003: /* Rev. 0.3 */
141 printf("MPC866xxxZPnn");
143 case 0x09000000: /* 870/875/880/885 */
148 printf("unknown MPC86x (0x%08x)", k);
152 printf(" at %s MHz: ", strmhz(buf, clock));
154 print_size(checkicache(), " I-Cache ");
155 print_size(checkdcache(), " D-Cache");
157 /* do we have a FEC (860T/P or 852/859/866/885)? */
159 out_be32(&immap->im_cpm.cp_fec.fec_addr_low, 0x12345678);
160 if (in_be32(&immap->im_cpm.cp_fec.fec_addr_low) == 0x12345678)
161 printf(" FEC present");
168 /* ------------------------------------------------------------------------- */
172 ulong clock = gd->cpu_clk;
173 uint immr = get_immr(); /* Return full IMMR contents */
174 uint pvr = get_pvr();
178 return check_CPU(clock, pvr, immr);
181 /* ------------------------------------------------------------------------- */
183 void upmconfig(uint upm, uint *table, uint size)
187 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
188 memctl8xx_t __iomem *memctl = &immap->im_memctl;
190 for (i = 0; i < size; i++) {
191 out_be32(&memctl->memc_mdr, table[i]); /* (16-15) */
192 out_be32(&memctl->memc_mcr, addr | upm); /* (16-16) */
197 /* ------------------------------------------------------------------------- */
199 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
203 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
205 /* Checkstop Reset enable */
206 setbits_be32(&immap->im_clkrst.car_plprcr, PLPRCR_CSR);
208 /* Interrupts and MMU off */
209 __asm__ volatile ("mtspr 81, 0");
210 __asm__ volatile ("mfmsr %0" : "=r" (msr));
213 __asm__ volatile ("mtmsr %0" : : "r" (msr));
216 * Trying to execute the next instruction at a non-existing address
217 * should cause a machine check, resulting in reset
219 #ifdef CONFIG_SYS_RESET_ADDRESS
220 addr = CONFIG_SYS_RESET_ADDRESS;
223 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
224 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid address.
225 * Better pick an address known to be invalid on your system and assign
226 * it to CONFIG_SYS_RESET_ADDRESS.
227 * "(ulong)-1" used to be a good choice for many systems...
229 addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
231 ((void (*)(void)) addr)();
235 /* ------------------------------------------------------------------------- */
238 * Get timebase clock frequency (like cpu_clk in Hz)
240 * See sections 14.2 and 14.6 of the User's Manual
242 unsigned long get_tbclk(void)
244 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
245 ulong oscclk, factor, pll;
247 if (in_be32(&immap->im_clkrst.car_sccr) & SCCR_TBS)
248 return gd->cpu_clk / 16;
250 pll = in_be32(&immap->im_clkrst.car_plprcr);
252 #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT)
255 * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication
256 * factor is calculated as follows:
261 * factor = -----------------
265 factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD) + 1)) /
266 (PLPRCR_val(PDF) + 1) / (1 << PLPRCR_val(S));
268 oscclk = gd->cpu_clk / factor;
270 if ((in_be32(&immap->im_clkrst.car_sccr) & SCCR_RTSEL) == 0 ||
278 * Initializes on-chip ethernet controllers.
279 * to override, implement board_eth_init()
281 int cpu_eth_init(struct bd_info *bis)
283 #if defined(CONFIG_MPC8XX_FEC)