xref: /openbmc/u-boot/arch/powerpc/cpu/mpc83xx/cpu.c (revision 4e710ebb4463c8e031eb269c012fbadb2479608b)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a47a12beSStefan Roese  * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
4a47a12beSStefan Roese  */
5a47a12beSStefan Roese 
6a47a12beSStefan Roese /*
7a47a12beSStefan Roese  * CPU specific code for the MPC83xx family.
8a47a12beSStefan Roese  *
9a47a12beSStefan Roese  * Derived from the MPC8260 and MPC85xx.
10a47a12beSStefan Roese  */
11a47a12beSStefan Roese 
12a47a12beSStefan Roese #include <common.h>
13a47a12beSStefan Roese #include <watchdog.h>
14a47a12beSStefan Roese #include <command.h>
15a47a12beSStefan Roese #include <mpc83xx.h>
16a47a12beSStefan Roese #include <asm/processor.h>
17b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
18a47a12beSStefan Roese #include <tsec.h>
19a47a12beSStefan Roese #include <netdev.h>
20a47a12beSStefan Roese #include <fsl_esdhc.h>
2199509695SHeiko Schocher #if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_MPC831x)
2238d67a4eSZhao Qiang #include <linux/immap_qe.h>
23a47a12beSStefan Roese #include <asm/io.h>
24a47a12beSStefan Roese #endif
25a47a12beSStefan Roese 
26a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
27a47a12beSStefan Roese 
28*19fbdca4SMario Six #ifndef CONFIG_CPU_MPC83XX
checkcpu(void)29a47a12beSStefan Roese int checkcpu(void)
30a47a12beSStefan Roese {
31a47a12beSStefan Roese 	volatile immap_t *immr;
32a47a12beSStefan Roese 	ulong clock = gd->cpu_clk;
33a47a12beSStefan Roese 	u32 pvr = get_pvr();
34a47a12beSStefan Roese 	u32 spridr;
35a47a12beSStefan Roese 	char buf[32];
36d891ab95SSimon Glass 	int ret;
37a47a12beSStefan Roese 	int i;
38a47a12beSStefan Roese 
39a47a12beSStefan Roese 	const struct cpu_type {
40a47a12beSStefan Roese 		char name[15];
41a47a12beSStefan Roese 		u32 partid;
42a47a12beSStefan Roese 	} cpu_type_list [] = {
437c619ddcSIlya Yanok 		CPU_TYPE_ENTRY(8308),
44a88731a6SGerlando Falauto 		CPU_TYPE_ENTRY(8309),
45a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8311),
46a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8313),
47a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8314),
48a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8315),
49a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8321),
50a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8323),
51a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8343),
52a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8347_TBGA_),
53a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8347_PBGA_),
54a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8349),
55a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8358_TBGA_),
56a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8358_PBGA_),
57a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8360),
58a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8377),
59a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8378),
60a47a12beSStefan Roese 		CPU_TYPE_ENTRY(8379),
61a47a12beSStefan Roese 	};
62a47a12beSStefan Roese 
63a47a12beSStefan Roese 	immr = (immap_t *)CONFIG_SYS_IMMR;
64a47a12beSStefan Roese 
65d891ab95SSimon Glass 	ret = prt_83xx_rsr();
66d891ab95SSimon Glass 	if (ret)
67d891ab95SSimon Glass 		return ret;
68d891ab95SSimon Glass 
69a47a12beSStefan Roese 	puts("CPU:   ");
70a47a12beSStefan Roese 
71a47a12beSStefan Roese 	switch (pvr & 0xffff0000) {
72a47a12beSStefan Roese 		case PVR_E300C1:
73a47a12beSStefan Roese 			printf("e300c1, ");
74a47a12beSStefan Roese 			break;
75a47a12beSStefan Roese 
76a47a12beSStefan Roese 		case PVR_E300C2:
77a47a12beSStefan Roese 			printf("e300c2, ");
78a47a12beSStefan Roese 			break;
79a47a12beSStefan Roese 
80a47a12beSStefan Roese 		case PVR_E300C3:
81a47a12beSStefan Roese 			printf("e300c3, ");
82a47a12beSStefan Roese 			break;
83a47a12beSStefan Roese 
84a47a12beSStefan Roese 		case PVR_E300C4:
85a47a12beSStefan Roese 			printf("e300c4, ");
86a47a12beSStefan Roese 			break;
87a47a12beSStefan Roese 
88a47a12beSStefan Roese 		default:
89a47a12beSStefan Roese 			printf("Unknown core, ");
90a47a12beSStefan Roese 	}
91a47a12beSStefan Roese 
92a47a12beSStefan Roese 	spridr = immr->sysconf.spridr;
93a47a12beSStefan Roese 
94a47a12beSStefan Roese 	for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
95a47a12beSStefan Roese 		if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
96a47a12beSStefan Roese 			puts("MPC");
97a47a12beSStefan Roese 			puts(cpu_type_list[i].name);
98a47a12beSStefan Roese 			if (IS_E_PROCESSOR(spridr))
99a47a12beSStefan Roese 				puts("E");
100dfe812c7SKim Phillips 			if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
101dfe812c7SKim Phillips 			     SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
102dfe812c7SKim Phillips 			    REVID_MAJOR(spridr) >= 2)
103a47a12beSStefan Roese 				puts("A");
104a47a12beSStefan Roese 			printf(", Rev: %d.%d", REVID_MAJOR(spridr),
105a47a12beSStefan Roese 			       REVID_MINOR(spridr));
106a47a12beSStefan Roese 			break;
107a47a12beSStefan Roese 		}
108a47a12beSStefan Roese 
109a47a12beSStefan Roese 	if (i == ARRAY_SIZE(cpu_type_list))
110a47a12beSStefan Roese 		printf("(SPRIDR %08x unknown), ", spridr);
111a47a12beSStefan Roese 
112a47a12beSStefan Roese 	printf(" at %s MHz, ", strmhz(buf, clock));
113a47a12beSStefan Roese 
114c6731fe2SSimon Glass 	printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
115a47a12beSStefan Roese 
116a47a12beSStefan Roese 	return 0;
117a47a12beSStefan Roese }
118*19fbdca4SMario Six #endif
119a47a12beSStefan Roese 
12076fdad1fSMario Six #ifndef CONFIG_SYSRESET
121a47a12beSStefan Roese int
do_reset(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])12254841ab5SWolfgang Denk do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
123a47a12beSStefan Roese {
124a47a12beSStefan Roese 	ulong msr;
125a47a12beSStefan Roese #ifndef MPC83xx_RESET
126a47a12beSStefan Roese 	ulong addr;
127a47a12beSStefan Roese #endif
128a47a12beSStefan Roese 
129a47a12beSStefan Roese 	volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
130a47a12beSStefan Roese 
131a47a12beSStefan Roese 	puts("Resetting the board.\n");
132a47a12beSStefan Roese 
133a47a12beSStefan Roese #ifdef MPC83xx_RESET
134a47a12beSStefan Roese 
135a47a12beSStefan Roese 	/* Interrupts and MMU off */
136a47a12beSStefan Roese 	__asm__ __volatile__ ("mfmsr    %0":"=r" (msr):);
137a47a12beSStefan Roese 
138a47a12beSStefan Roese 	msr &= ~( MSR_EE | MSR_IR | MSR_DR);
139a47a12beSStefan Roese 	__asm__ __volatile__ ("mtmsr    %0"::"r" (msr));
140a47a12beSStefan Roese 
141a47a12beSStefan Roese 	/* enable Reset Control Reg */
142a47a12beSStefan Roese 	immap->reset.rpr = 0x52535445;
143a47a12beSStefan Roese 	__asm__ __volatile__ ("sync");
144a47a12beSStefan Roese 	__asm__ __volatile__ ("isync");
145a47a12beSStefan Roese 
146a47a12beSStefan Roese 	/* confirm Reset Control Reg is enabled */
147a47a12beSStefan Roese 	while(!((immap->reset.rcer) & RCER_CRE));
148a47a12beSStefan Roese 
149a47a12beSStefan Roese 	udelay(200);
150a47a12beSStefan Roese 
151a47a12beSStefan Roese 	/* perform reset, only one bit */
152a47a12beSStefan Roese 	immap->reset.rcr = RCR_SWHR;
153a47a12beSStefan Roese 
154a47a12beSStefan Roese #else	/* ! MPC83xx_RESET */
155a47a12beSStefan Roese 
156a47a12beSStefan Roese 	immap->reset.rmr = RMR_CSRE;    /* Checkstop Reset enable */
157a47a12beSStefan Roese 
158a47a12beSStefan Roese 	/* Interrupts and MMU off */
159a47a12beSStefan Roese 	__asm__ __volatile__ ("mfmsr    %0":"=r" (msr):);
160a47a12beSStefan Roese 
161a47a12beSStefan Roese 	msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
162a47a12beSStefan Roese 	__asm__ __volatile__ ("mtmsr    %0"::"r" (msr));
163a47a12beSStefan Roese 
164a47a12beSStefan Roese 	/*
165a47a12beSStefan Roese 	 * Trying to execute the next instruction at a non-existing address
166a47a12beSStefan Roese 	 * should cause a machine check, resulting in reset
167a47a12beSStefan Roese 	 */
168a47a12beSStefan Roese 	addr = CONFIG_SYS_RESET_ADDRESS;
169a47a12beSStefan Roese 
170a47a12beSStefan Roese 	((void (*)(void)) addr) ();
171a47a12beSStefan Roese #endif	/* MPC83xx_RESET */
172a47a12beSStefan Roese 
173a47a12beSStefan Roese 	return 1;
174a47a12beSStefan Roese }
17576fdad1fSMario Six #endif
176a47a12beSStefan Roese 
177a47a12beSStefan Roese /*
178a47a12beSStefan Roese  * Get timebase clock frequency (like cpu_clk in Hz)
179a47a12beSStefan Roese  */
1802c21749dSMario Six #ifndef CONFIG_TIMER
get_tbclk(void)181a47a12beSStefan Roese unsigned long get_tbclk(void)
182a47a12beSStefan Roese {
18363a7578eSMasahiro Yamada 	return (gd->bus_clk + 3L) / 4L;
184a47a12beSStefan Roese }
1852c21749dSMario Six #endif
186a47a12beSStefan Roese 
187a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG)
watchdog_reset(void)188a47a12beSStefan Roese void watchdog_reset (void)
189a47a12beSStefan Roese {
190a47a12beSStefan Roese 	int re_enable = disable_interrupts();
191a47a12beSStefan Roese 
192a47a12beSStefan Roese 	/* Reset the 83xx watchdog */
193a47a12beSStefan Roese 	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
194a47a12beSStefan Roese 	immr->wdt.swsrr = 0x556c;
195a47a12beSStefan Roese 	immr->wdt.swsrr = 0xaa39;
196a47a12beSStefan Roese 
197a47a12beSStefan Roese 	if (re_enable)
198a47a12beSStefan Roese 		enable_interrupts ();
199a47a12beSStefan Roese }
200a47a12beSStefan Roese #endif
201a47a12beSStefan Roese 
202a47a12beSStefan Roese /*
203a47a12beSStefan Roese  * Initializes on-chip ethernet controllers.
204a47a12beSStefan Roese  * to override, implement board_eth_init()
205a47a12beSStefan Roese  */
cpu_eth_init(bd_t * bis)206a47a12beSStefan Roese int cpu_eth_init(bd_t *bis)
207a47a12beSStefan Roese {
208a47a12beSStefan Roese #if defined(CONFIG_UEC_ETH)
209a47a12beSStefan Roese 	uec_standard_init(bis);
210a47a12beSStefan Roese #endif
211a47a12beSStefan Roese 
212a47a12beSStefan Roese #if defined(CONFIG_TSEC_ENET)
213a47a12beSStefan Roese 	tsec_standard_init(bis);
214a47a12beSStefan Roese #endif
215a47a12beSStefan Roese 	return 0;
216a47a12beSStefan Roese }
217a47a12beSStefan Roese 
218a47a12beSStefan Roese /*
219a47a12beSStefan Roese  * Initializes on-chip MMC controllers.
220a47a12beSStefan Roese  * to override, implement board_mmc_init()
221a47a12beSStefan Roese  */
cpu_mmc_init(bd_t * bis)222a47a12beSStefan Roese int cpu_mmc_init(bd_t *bis)
223a47a12beSStefan Roese {
224a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC
225a47a12beSStefan Roese 	return fsl_esdhc_mmc_init(bis);
226a47a12beSStefan Roese #else
227a47a12beSStefan Roese 	return 0;
228a47a12beSStefan Roese #endif
229a47a12beSStefan Roese }
230