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