xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/cpu.c (revision 2a3a96ca5e7e407140e3c3ef77ece72d5db30bc4)
1a47a12beSStefan Roese /*
2ab48ca1aSSrikanth Srinivasan  * Copyright 2004,2007-2010 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  * (C) Copyright 2002, 2003 Motorola Inc.
4a47a12beSStefan Roese  * Xianghua Xiao (X.Xiao@motorola.com)
5a47a12beSStefan Roese  *
6a47a12beSStefan Roese  * (C) Copyright 2000
7a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8a47a12beSStefan Roese  *
9a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
10a47a12beSStefan Roese  * project.
11a47a12beSStefan Roese  *
12a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
13a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
14a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
15a47a12beSStefan Roese  * the License, or (at your option) any later version.
16a47a12beSStefan Roese  *
17a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
18a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20a47a12beSStefan Roese  * GNU General Public License for more details.
21a47a12beSStefan Roese  *
22a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
23a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
24a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25a47a12beSStefan Roese  * MA 02111-1307 USA
26a47a12beSStefan Roese  */
27a47a12beSStefan Roese 
28a47a12beSStefan Roese #include <config.h>
29a47a12beSStefan Roese #include <common.h>
30a47a12beSStefan Roese #include <watchdog.h>
31a47a12beSStefan Roese #include <command.h>
32a47a12beSStefan Roese #include <fsl_esdhc.h>
33a47a12beSStefan Roese #include <asm/cache.h>
34a47a12beSStefan Roese #include <asm/io.h>
35199e262eSBecky Bruce #include <asm/mmu.h>
36199e262eSBecky Bruce #include <asm/fsl_law.h>
37a47a12beSStefan Roese 
38a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
39a47a12beSStefan Roese 
40a47a12beSStefan Roese int checkcpu (void)
41a47a12beSStefan Roese {
42a47a12beSStefan Roese 	sys_info_t sysinfo;
43a47a12beSStefan Roese 	uint pvr, svr;
44a47a12beSStefan Roese 	uint fam;
45a47a12beSStefan Roese 	uint ver;
46a47a12beSStefan Roese 	uint major, minor;
47a47a12beSStefan Roese 	struct cpu_type *cpu;
48a47a12beSStefan Roese 	char buf1[32], buf2[32];
499ce3c228SKumar Gala #if defined(CONFIG_DDR_CLK_FREQ) || defined(CONFIG_FSL_CORENET)
50a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
519ce3c228SKumar Gala #endif /* CONFIG_FSL_CORENET */
52ab48ca1aSSrikanth Srinivasan #ifdef CONFIG_DDR_CLK_FREQ
53ab48ca1aSSrikanth Srinivasan 	u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
54ab48ca1aSSrikanth Srinivasan 		>> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
55ab48ca1aSSrikanth Srinivasan #else
56a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
57a47a12beSStefan Roese 	u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
58a47a12beSStefan Roese 		>> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
59a47a12beSStefan Roese #else
60a47a12beSStefan Roese 	u32 ddr_ratio = 0;
61ab48ca1aSSrikanth Srinivasan #endif /* CONFIG_FSL_CORENET */
62a47a12beSStefan Roese #endif /* CONFIG_DDR_CLK_FREQ */
63a47a12beSStefan Roese 	int i;
64a47a12beSStefan Roese 
65a47a12beSStefan Roese 	svr = get_svr();
66a47a12beSStefan Roese 	major = SVR_MAJ(svr);
67a47a12beSStefan Roese #ifdef CONFIG_MPC8536
68a47a12beSStefan Roese 	major &= 0x7; /* the msb of this nibble is a mfg code */
69a47a12beSStefan Roese #endif
70a47a12beSStefan Roese 	minor = SVR_MIN(svr);
71a47a12beSStefan Roese 
72a47a12beSStefan Roese 	if (cpu_numcores() > 1) {
73a47a12beSStefan Roese #ifndef CONFIG_MP
74a47a12beSStefan Roese 		puts("Unicore software on multiprocessor system!!\n"
75a47a12beSStefan Roese 		     "To enable mutlticore build define CONFIG_MP\n");
76a47a12beSStefan Roese #endif
77a47a12beSStefan Roese 		volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
78a47a12beSStefan Roese 		printf("CPU%d:  ", pic->whoami);
79a47a12beSStefan Roese 	} else {
80a47a12beSStefan Roese 		puts("CPU:   ");
81a47a12beSStefan Roese 	}
82a47a12beSStefan Roese 
83a47a12beSStefan Roese 	cpu = gd->cpu;
84a47a12beSStefan Roese 
85a47a12beSStefan Roese 	puts(cpu->name);
86a47a12beSStefan Roese 	if (IS_E_PROCESSOR(svr))
87a47a12beSStefan Roese 		puts("E");
88a47a12beSStefan Roese 
89a47a12beSStefan Roese 	printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
90a47a12beSStefan Roese 
91a47a12beSStefan Roese 	pvr = get_pvr();
92a47a12beSStefan Roese 	fam = PVR_FAM(pvr);
93a47a12beSStefan Roese 	ver = PVR_VER(pvr);
94a47a12beSStefan Roese 	major = PVR_MAJ(pvr);
95a47a12beSStefan Roese 	minor = PVR_MIN(pvr);
96a47a12beSStefan Roese 
97a47a12beSStefan Roese 	printf("Core:  ");
98*2a3a96caSKumar Gala 	if (PVR_FAM(PVR_85xx)) {
99*2a3a96caSKumar Gala 		switch(PVR_MEM(pvr)) {
100*2a3a96caSKumar Gala 		case 0x1:
101*2a3a96caSKumar Gala 		case 0x2:
102a47a12beSStefan Roese 			puts("E500");
103a47a12beSStefan Roese 			break;
104*2a3a96caSKumar Gala 		case 0x3:
105*2a3a96caSKumar Gala 			puts("E500MC");
106*2a3a96caSKumar Gala 			break;
107*2a3a96caSKumar Gala 		case 0x4:
108*2a3a96caSKumar Gala 			puts("E5500");
109*2a3a96caSKumar Gala 			break;
110a47a12beSStefan Roese 		default:
111a47a12beSStefan Roese 			puts("Unknown");
112a47a12beSStefan Roese 			break;
113a47a12beSStefan Roese 		}
114*2a3a96caSKumar Gala 	} else {
115*2a3a96caSKumar Gala 		puts("Unknown");
116*2a3a96caSKumar Gala 	}
117a47a12beSStefan Roese 
118a47a12beSStefan Roese 	printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
119a47a12beSStefan Roese 
120a47a12beSStefan Roese 	get_sys_info(&sysinfo);
121a47a12beSStefan Roese 
122a47a12beSStefan Roese 	puts("Clock Configuration:");
123a47a12beSStefan Roese 	for (i = 0; i < cpu_numcores(); i++) {
124a47a12beSStefan Roese 		if (!(i & 3))
125a47a12beSStefan Roese 			printf ("\n       ");
126a47a12beSStefan Roese 		printf("CPU%d:%-4s MHz, ",
127a47a12beSStefan Roese 				i,strmhz(buf1, sysinfo.freqProcessor[i]));
128a47a12beSStefan Roese 	}
129a47a12beSStefan Roese 	printf("\n       CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
130a47a12beSStefan Roese 
131a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
132a47a12beSStefan Roese 	if (ddr_sync == 1) {
133a47a12beSStefan Roese 		printf("       DDR:%-4s MHz (%s MT/s data rate) "
134a47a12beSStefan Roese 			"(Synchronous), ",
135a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqDDRBus/2),
136a47a12beSStefan Roese 			strmhz(buf2, sysinfo.freqDDRBus));
137a47a12beSStefan Roese 	} else {
138a47a12beSStefan Roese 		printf("       DDR:%-4s MHz (%s MT/s data rate) "
139a47a12beSStefan Roese 			"(Asynchronous), ",
140a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqDDRBus/2),
141a47a12beSStefan Roese 			strmhz(buf2, sysinfo.freqDDRBus));
142a47a12beSStefan Roese 	}
143a47a12beSStefan Roese #else
144a47a12beSStefan Roese 	switch (ddr_ratio) {
145a47a12beSStefan Roese 	case 0x0:
146a47a12beSStefan Roese 		printf("       DDR:%-4s MHz (%s MT/s data rate), ",
147a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqDDRBus/2),
148a47a12beSStefan Roese 			strmhz(buf2, sysinfo.freqDDRBus));
149a47a12beSStefan Roese 		break;
150a47a12beSStefan Roese 	case 0x7:
151a47a12beSStefan Roese 		printf("       DDR:%-4s MHz (%s MT/s data rate) "
152a47a12beSStefan Roese 			"(Synchronous), ",
153a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqDDRBus/2),
154a47a12beSStefan Roese 			strmhz(buf2, sysinfo.freqDDRBus));
155a47a12beSStefan Roese 		break;
156a47a12beSStefan Roese 	default:
157a47a12beSStefan Roese 		printf("       DDR:%-4s MHz (%s MT/s data rate) "
158a47a12beSStefan Roese 			"(Asynchronous), ",
159a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqDDRBus/2),
160a47a12beSStefan Roese 			strmhz(buf2, sysinfo.freqDDRBus));
161a47a12beSStefan Roese 		break;
162a47a12beSStefan Roese 	}
163a47a12beSStefan Roese #endif
164a47a12beSStefan Roese 
165a47a12beSStefan Roese 	if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
166a47a12beSStefan Roese 		printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
167a47a12beSStefan Roese 	} else {
168a47a12beSStefan Roese 		printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
169a47a12beSStefan Roese 		       sysinfo.freqLocalBus);
170a47a12beSStefan Roese 	}
171a47a12beSStefan Roese 
172a47a12beSStefan Roese #ifdef CONFIG_CPM2
173a47a12beSStefan Roese 	printf("CPM:   %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
174a47a12beSStefan Roese #endif
175a47a12beSStefan Roese 
176a47a12beSStefan Roese #ifdef CONFIG_QE
177a47a12beSStefan Roese 	printf("       QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
178a47a12beSStefan Roese #endif
179a47a12beSStefan Roese 
180a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_FMAN
181a47a12beSStefan Roese 	for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
182a47a12beSStefan Roese 		printf("       FMAN%d: %s MHz\n", i,
183a47a12beSStefan Roese 			strmhz(buf1, sysinfo.freqFMan[i]));
184a47a12beSStefan Roese 	}
185a47a12beSStefan Roese #endif
186a47a12beSStefan Roese 
187a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME
188a47a12beSStefan Roese 	printf("       PME:   %s MHz\n", strmhz(buf1, sysinfo.freqPME));
189a47a12beSStefan Roese #endif
190a47a12beSStefan Roese 
191a47a12beSStefan Roese 	puts("L1:    D-cache 32 kB enabled\n       I-cache 32 kB enabled\n");
192a47a12beSStefan Roese 
193a47a12beSStefan Roese 	return 0;
194a47a12beSStefan Roese }
195a47a12beSStefan Roese 
196a47a12beSStefan Roese 
197a47a12beSStefan Roese /* ------------------------------------------------------------------------- */
198a47a12beSStefan Roese 
19954841ab5SWolfgang Denk int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char * const argv[])
200a47a12beSStefan Roese {
201a47a12beSStefan Roese /* Everything after the first generation of PQ3 parts has RSTCR */
202a47a12beSStefan Roese #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
203a47a12beSStefan Roese     defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
204a47a12beSStefan Roese 	unsigned long val, msr;
205a47a12beSStefan Roese 
206a47a12beSStefan Roese 	/*
207a47a12beSStefan Roese 	 * Initiate hard reset in debug control register DBCR0
208a47a12beSStefan Roese 	 * Make sure MSR[DE] = 1.  This only resets the core.
209a47a12beSStefan Roese 	 */
210a47a12beSStefan Roese 	msr = mfmsr ();
211a47a12beSStefan Roese 	msr |= MSR_DE;
212a47a12beSStefan Roese 	mtmsr (msr);
213a47a12beSStefan Roese 
214a47a12beSStefan Roese 	val = mfspr(DBCR0);
215a47a12beSStefan Roese 	val |= 0x70000000;
216a47a12beSStefan Roese 	mtspr(DBCR0,val);
217a47a12beSStefan Roese #else
218a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
219a47a12beSStefan Roese 	out_be32(&gur->rstcr, 0x2);	/* HRESET_REQ */
220a47a12beSStefan Roese 	udelay(100);
221a47a12beSStefan Roese #endif
222a47a12beSStefan Roese 
223a47a12beSStefan Roese 	return 1;
224a47a12beSStefan Roese }
225a47a12beSStefan Roese 
226a47a12beSStefan Roese 
227a47a12beSStefan Roese /*
228a47a12beSStefan Roese  * Get timebase clock frequency
229a47a12beSStefan Roese  */
230a47a12beSStefan Roese unsigned long get_tbclk (void)
231a47a12beSStefan Roese {
232a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
233a47a12beSStefan Roese 	return (gd->bus_clk + 8) / 16;
234a47a12beSStefan Roese #else
235a47a12beSStefan Roese 	return (gd->bus_clk + 4UL)/8UL;
236a47a12beSStefan Roese #endif
237a47a12beSStefan Roese }
238a47a12beSStefan Roese 
239a47a12beSStefan Roese 
240a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG)
241a47a12beSStefan Roese void
242a47a12beSStefan Roese watchdog_reset(void)
243a47a12beSStefan Roese {
244a47a12beSStefan Roese 	int re_enable = disable_interrupts();
245a47a12beSStefan Roese 	reset_85xx_watchdog();
246a47a12beSStefan Roese 	if (re_enable) enable_interrupts();
247a47a12beSStefan Roese }
248a47a12beSStefan Roese 
249a47a12beSStefan Roese void
250a47a12beSStefan Roese reset_85xx_watchdog(void)
251a47a12beSStefan Roese {
252a47a12beSStefan Roese 	/*
253a47a12beSStefan Roese 	 * Clear TSR(WIS) bit by writing 1
254a47a12beSStefan Roese 	 */
255a47a12beSStefan Roese 	unsigned long val;
256a47a12beSStefan Roese 	val = mfspr(SPRN_TSR);
257a47a12beSStefan Roese 	val |= TSR_WIS;
258a47a12beSStefan Roese 	mtspr(SPRN_TSR, val);
259a47a12beSStefan Roese }
260a47a12beSStefan Roese #endif	/* CONFIG_WATCHDOG */
261a47a12beSStefan Roese 
262a47a12beSStefan Roese /*
263a47a12beSStefan Roese  * Initializes on-chip MMC controllers.
264a47a12beSStefan Roese  * to override, implement board_mmc_init()
265a47a12beSStefan Roese  */
266a47a12beSStefan Roese int cpu_mmc_init(bd_t *bis)
267a47a12beSStefan Roese {
268a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC
269a47a12beSStefan Roese 	return fsl_esdhc_mmc_init(bis);
270a47a12beSStefan Roese #else
271a47a12beSStefan Roese 	return 0;
272a47a12beSStefan Roese #endif
273a47a12beSStefan Roese }
274199e262eSBecky Bruce 
275199e262eSBecky Bruce /*
276199e262eSBecky Bruce  * Print out the state of various machine registers.
277199e262eSBecky Bruce  * Currently prints out LAWs, BR0/OR0, and TLBs
278199e262eSBecky Bruce  */
279199e262eSBecky Bruce void mpc85xx_reginfo(void)
280199e262eSBecky Bruce {
281199e262eSBecky Bruce 	print_tlbcam();
282199e262eSBecky Bruce 	print_laws();
283199e262eSBecky Bruce 	print_lbc_regs();
284199e262eSBecky Bruce }
285