xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc86xx/cpu.c (revision 1425a87b1478bdb2620a46f2a23af7ca2e4b6073)
1a47a12beSStefan Roese /*
2a47a12beSStefan Roese  * Copyright 2006,2009-2010 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  * Jeff Brown
4a47a12beSStefan Roese  * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
5a47a12beSStefan Roese  *
61a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
7a47a12beSStefan Roese  */
8a47a12beSStefan Roese 
9a47a12beSStefan Roese #include <common.h>
10a47a12beSStefan Roese #include <watchdog.h>
11a47a12beSStefan Roese #include <command.h>
12a47a12beSStefan Roese #include <asm/cache.h>
13a47a12beSStefan Roese #include <asm/mmu.h>
14a47a12beSStefan Roese #include <mpc86xx.h>
15a47a12beSStefan Roese #include <asm/fsl_law.h>
16a47a12beSStefan Roese 
17a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
18a47a12beSStefan Roese 
19a47a12beSStefan Roese /*
20a47a12beSStefan Roese  * Default board reset function
21a47a12beSStefan Roese  */
22a47a12beSStefan Roese static void
23a47a12beSStefan Roese __board_reset(void)
24a47a12beSStefan Roese {
25a47a12beSStefan Roese 	/* Do nothing */
26a47a12beSStefan Roese }
27a47a12beSStefan Roese void board_reset(void) __attribute__((weak, alias("__board_reset")));
28a47a12beSStefan Roese 
29a47a12beSStefan Roese 
30a47a12beSStefan Roese int
31a47a12beSStefan Roese checkcpu(void)
32a47a12beSStefan Roese {
33a47a12beSStefan Roese 	sys_info_t sysinfo;
34a47a12beSStefan Roese 	uint pvr, svr;
35a47a12beSStefan Roese 	uint major, minor;
36a47a12beSStefan Roese 	char buf1[32], buf2[32];
37a47a12beSStefan Roese 	volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
38a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = &immap->im_gur;
39a47a12beSStefan Roese 	struct cpu_type *cpu;
40a47a12beSStefan Roese 	uint msscr0 = mfspr(MSSCR0);
41a47a12beSStefan Roese 
42a47a12beSStefan Roese 	svr = get_svr();
43a47a12beSStefan Roese 	major = SVR_MAJ(svr);
44a47a12beSStefan Roese 	minor = SVR_MIN(svr);
45a47a12beSStefan Roese 
46a47a12beSStefan Roese 	if (cpu_numcores() > 1) {
47a47a12beSStefan Roese #ifndef CONFIG_MP
48a47a12beSStefan Roese 		puts("Unicore software on multiprocessor system!!\n"
49a47a12beSStefan Roese 		     "To enable mutlticore build define CONFIG_MP\n");
50a47a12beSStefan Roese #endif
51a47a12beSStefan Roese 	}
52a47a12beSStefan Roese 	puts("CPU:   ");
53a47a12beSStefan Roese 
5467ac13b1SSimon Glass 	cpu = gd->arch.cpu;
55a47a12beSStefan Roese 
56a47a12beSStefan Roese 	puts(cpu->name);
57a47a12beSStefan Roese 
58a47a12beSStefan Roese 	printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
59a47a12beSStefan Roese 	puts("Core:  ");
60a47a12beSStefan Roese 
61a47a12beSStefan Roese 	pvr = get_pvr();
62a47a12beSStefan Roese 	major = PVR_E600_MAJ(pvr);
63a47a12beSStefan Roese 	minor = PVR_E600_MIN(pvr);
64a47a12beSStefan Roese 
656770c5e2SFabio Estevam 	printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0);
66a47a12beSStefan Roese 	if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
67a47a12beSStefan Roese 		puts("\n    Core1Translation Enabled");
68a47a12beSStefan Roese 	debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
69a47a12beSStefan Roese 
70a47a12beSStefan Roese 	printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
71a47a12beSStefan Roese 
72a47a12beSStefan Roese 	get_sys_info(&sysinfo);
73a47a12beSStefan Roese 
74a47a12beSStefan Roese 	puts("Clock Configuration:\n");
75997399faSPrabhakar Kushwaha 	printf("       CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freq_processor));
76997399faSPrabhakar Kushwaha 	printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freq_systembus));
77a47a12beSStefan Roese 	printf("       DDR:%-4s MHz (%s MT/s data rate), ",
78997399faSPrabhakar Kushwaha 		strmhz(buf1, sysinfo.freq_systembus / 2),
79997399faSPrabhakar Kushwaha 		strmhz(buf2, sysinfo.freq_systembus));
80a47a12beSStefan Roese 
81997399faSPrabhakar Kushwaha 	if (sysinfo.freq_localbus > LCRR_CLKDIV) {
82997399faSPrabhakar Kushwaha 		printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
83a47a12beSStefan Roese 	} else {
84a47a12beSStefan Roese 		printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
85997399faSPrabhakar Kushwaha 		       sysinfo.freq_localbus);
86a47a12beSStefan Roese 	}
87a47a12beSStefan Roese 
886b44d9e5SShruti Kanetkar 	puts("L1:    D-cache 32 KiB enabled\n");
896b44d9e5SShruti Kanetkar 	puts("       I-cache 32 KiB enabled\n");
90a47a12beSStefan Roese 
91a47a12beSStefan Roese 	puts("L2:    ");
92a47a12beSStefan Roese 	if (get_l2cr() & 0x80000000) {
93*1425a87bSYork Sun #if defined(CONFIG_ARCH_MPC8610)
94a47a12beSStefan Roese 		puts("256");
95a47a12beSStefan Roese #elif defined(CONFIG_MPC8641)
96a47a12beSStefan Roese 		puts("512");
97a47a12beSStefan Roese #endif
986b44d9e5SShruti Kanetkar 		puts(" KiB enabled\n");
99a47a12beSStefan Roese 	} else {
100a47a12beSStefan Roese 		puts("Disabled\n");
101a47a12beSStefan Roese 	}
102a47a12beSStefan Roese 
103a47a12beSStefan Roese 	return 0;
104a47a12beSStefan Roese }
105a47a12beSStefan Roese 
106a47a12beSStefan Roese 
107c22a711dSPeter Tyser int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
108a47a12beSStefan Roese {
109a47a12beSStefan Roese 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
110a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = &immap->im_gur;
111a47a12beSStefan Roese 
112a47a12beSStefan Roese 	/* Attempt board-specific reset */
113a47a12beSStefan Roese 	board_reset();
114a47a12beSStefan Roese 
115a47a12beSStefan Roese 	/* Next try asserting HRESET_REQ */
116a47a12beSStefan Roese 	out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);
117a47a12beSStefan Roese 
118a47a12beSStefan Roese 	while (1)
119a47a12beSStefan Roese 		;
120c22a711dSPeter Tyser 
121c22a711dSPeter Tyser 	return 1;
122a47a12beSStefan Roese }
123a47a12beSStefan Roese 
124a47a12beSStefan Roese 
125a47a12beSStefan Roese /*
126a47a12beSStefan Roese  * Get timebase clock frequency
127a47a12beSStefan Roese  */
128a47a12beSStefan Roese unsigned long
129a47a12beSStefan Roese get_tbclk(void)
130a47a12beSStefan Roese {
131a47a12beSStefan Roese 	sys_info_t sys_info;
132a47a12beSStefan Roese 
133a47a12beSStefan Roese 	get_sys_info(&sys_info);
134997399faSPrabhakar Kushwaha 	return (sys_info.freq_systembus + 3L) / 4L;
135a47a12beSStefan Roese }
136a47a12beSStefan Roese 
137a47a12beSStefan Roese 
138a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG)
139a47a12beSStefan Roese void
140a47a12beSStefan Roese watchdog_reset(void)
141a47a12beSStefan Roese {
142*1425a87bSYork Sun #if defined(CONFIG_ARCH_MPC8610)
143a47a12beSStefan Roese 	/*
144a47a12beSStefan Roese 	 * This actually feed the hard enabled watchdog.
145a47a12beSStefan Roese 	 */
146a47a12beSStefan Roese 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
147a47a12beSStefan Roese 	volatile ccsr_wdt_t *wdt = &immap->im_wdt;
148a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = &immap->im_gur;
149a47a12beSStefan Roese 	u32 tmp = gur->pordevsr;
150a47a12beSStefan Roese 
151a47a12beSStefan Roese 	if (tmp & 0x4000) {
152a47a12beSStefan Roese 		wdt->swsrr = 0x556c;
153a47a12beSStefan Roese 		wdt->swsrr = 0xaa39;
154a47a12beSStefan Roese 	}
155a47a12beSStefan Roese #endif
156a47a12beSStefan Roese }
157a47a12beSStefan Roese #endif	/* CONFIG_WATCHDOG */
158a47a12beSStefan Roese 
159a47a12beSStefan Roese /*
160a47a12beSStefan Roese  * Print out the state of various machine registers.
161a47a12beSStefan Roese  * Currently prints out LAWs, BR0/OR0, and BATs
162a47a12beSStefan Roese  */
163a47a12beSStefan Roese void mpc86xx_reginfo(void)
164a47a12beSStefan Roese {
165a47a12beSStefan Roese 	print_bats();
166a47a12beSStefan Roese 	print_laws();
167f51cdaf1SBecky Bruce 	print_lbc_regs();
168a47a12beSStefan Roese }
169a47a12beSStefan Roese 
170a47a12beSStefan Roese /*
171a47a12beSStefan Roese  * Set the DDR BATs to reflect the actual size of DDR.
172a47a12beSStefan Roese  *
173a47a12beSStefan Roese  * dram_size is the actual size of DDR, in bytes
174a47a12beSStefan Roese  *
175a47a12beSStefan Roese  * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only
176a47a12beSStefan Roese  * are using a single BAT to cover DDR.
177a47a12beSStefan Roese  *
178a47a12beSStefan Roese  * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN
179a47a12beSStefan Roese  * is not defined) then we might have a situation where U-Boot will attempt
180a47a12beSStefan Roese  * to relocated itself outside of the region mapped by DBAT0.
181a47a12beSStefan Roese  * This will cause a machine check.
182a47a12beSStefan Roese  *
183a47a12beSStefan Roese  * Currently we are limited to power of two sized DDR since we only use a
184a47a12beSStefan Roese  * single bat.  If a non-power of two size is used that is less than
185a47a12beSStefan Roese  * CONFIG_MAX_MEM_MAPPED u-boot will crash.
186a47a12beSStefan Roese  *
187a47a12beSStefan Roese  */
188a47a12beSStefan Roese void setup_ddr_bat(phys_addr_t dram_size)
189a47a12beSStefan Roese {
190a47a12beSStefan Roese 	unsigned long batu, bl;
191a47a12beSStefan Roese 
192a47a12beSStefan Roese 	bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED));
193a47a12beSStefan Roese 
194a47a12beSStefan Roese 	if (BATU_SIZE(bl) != dram_size) {
195a47a12beSStefan Roese 		u64 sz = (u64)dram_size - BATU_SIZE(bl);
196a47a12beSStefan Roese 		print_size(sz, " left unmapped\n");
197a47a12beSStefan Roese 	}
198a47a12beSStefan Roese 
199a47a12beSStefan Roese 	batu = bl | BATU_VS | BATU_VP;
200a47a12beSStefan Roese 	write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L);
201a47a12beSStefan Roese 	write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L);
202a47a12beSStefan Roese }
203