xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc83xx/cpu_init.c (revision b7707b043ebbf88fe0fb49442db9316ded3a0740)
1a47a12beSStefan Roese /*
2a47a12beSStefan Roese  * Copyright (C) 2004-2009 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5a47a12beSStefan Roese  */
6a47a12beSStefan Roese 
7a47a12beSStefan Roese #include <common.h>
8a47a12beSStefan Roese #include <mpc83xx.h>
9a47a12beSStefan Roese #include <ioports.h>
10a47a12beSStefan Roese #include <asm/io.h>
11a47a12beSStefan Roese #ifdef CONFIG_USB_EHCI_FSL
12e162c6b1SMateusz Kulikowski #include <usb/ehci-ci.h>
13a47a12beSStefan Roese #endif
14a47a12beSStefan Roese 
15a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
16a47a12beSStefan Roese 
17a47a12beSStefan Roese #ifdef CONFIG_QE
18a47a12beSStefan Roese extern qe_iop_conf_t qe_iop_conf_tab[];
19a47a12beSStefan Roese extern void qe_config_iopin(u8 port, u8 pin, int dir,
20a47a12beSStefan Roese 			 int open_drain, int assign);
21a47a12beSStefan Roese extern void qe_init(uint qe_base);
22a47a12beSStefan Roese extern void qe_reset(void);
23a47a12beSStefan Roese 
24a47a12beSStefan Roese static void config_qe_ioports(void)
25a47a12beSStefan Roese {
26a47a12beSStefan Roese 	u8	port, pin;
27a47a12beSStefan Roese 	int	dir, open_drain, assign;
28a47a12beSStefan Roese 	int	i;
29a47a12beSStefan Roese 
30a47a12beSStefan Roese 	for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
31a47a12beSStefan Roese 		port		= qe_iop_conf_tab[i].port;
32a47a12beSStefan Roese 		pin		= qe_iop_conf_tab[i].pin;
33a47a12beSStefan Roese 		dir		= qe_iop_conf_tab[i].dir;
34a47a12beSStefan Roese 		open_drain	= qe_iop_conf_tab[i].open_drain;
35a47a12beSStefan Roese 		assign		= qe_iop_conf_tab[i].assign;
36a47a12beSStefan Roese 		qe_config_iopin(port, pin, dir, open_drain, assign);
37a47a12beSStefan Roese 	}
38a47a12beSStefan Roese }
39a47a12beSStefan Roese #endif
40a47a12beSStefan Roese 
41a47a12beSStefan Roese /*
42a47a12beSStefan Roese  * Breathe some life into the CPU...
43a47a12beSStefan Roese  *
44a47a12beSStefan Roese  * Set up the memory map,
45a47a12beSStefan Roese  * initialize a bunch of registers,
46a47a12beSStefan Roese  * initialize the UPM's
47a47a12beSStefan Roese  */
48a47a12beSStefan Roese void cpu_init_f (volatile immap_t * im)
49a47a12beSStefan Roese {
50a47a12beSStefan Roese 	__be32 acr_mask =
51a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_PIPE_DEP /* Arbiter pipeline depth */
5271bd860cSKim Phillips 		ACR_PIPE_DEP |
53a47a12beSStefan Roese #endif
54a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_RPTCNT /* Arbiter repeat count */
5571bd860cSKim Phillips 		ACR_RPTCNT |
56a47a12beSStefan Roese #endif
57a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_APARK	/* Arbiter address parking mode */
5871bd860cSKim Phillips 		ACR_APARK |
59a47a12beSStefan Roese #endif
60a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_PARKM	/* Arbiter parking master */
6171bd860cSKim Phillips 		ACR_PARKM |
62a47a12beSStefan Roese #endif
63a47a12beSStefan Roese 		0;
64a47a12beSStefan Roese 	__be32 acr_val =
65a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_PIPE_DEP /* Arbiter pipeline depth */
66a47a12beSStefan Roese 		(CONFIG_SYS_ACR_PIPE_DEP << ACR_PIPE_DEP_SHIFT) |
67a47a12beSStefan Roese #endif
68a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_RPTCNT /* Arbiter repeat count */
69a47a12beSStefan Roese 		(CONFIG_SYS_ACR_RPTCNT << ACR_RPTCNT_SHIFT) |
70a47a12beSStefan Roese #endif
71a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_APARK	/* Arbiter address parking mode */
72a47a12beSStefan Roese 		(CONFIG_SYS_ACR_APARK << ACR_APARK_SHIFT) |
73a47a12beSStefan Roese #endif
74a47a12beSStefan Roese #ifdef CONFIG_SYS_ACR_PARKM	/* Arbiter parking master */
75a47a12beSStefan Roese 		(CONFIG_SYS_ACR_PARKM << ACR_PARKM_SHIFT) |
76a47a12beSStefan Roese #endif
77a47a12beSStefan Roese 		0;
78a47a12beSStefan Roese 	__be32 spcr_mask =
79a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_OPT /* Optimize transactions between CSB and other dev */
8071bd860cSKim Phillips 		SPCR_OPT |
81a47a12beSStefan Roese #endif
82a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSECEP /* all eTSEC's Emergency priority */
8371bd860cSKim Phillips 		SPCR_TSECEP |
84a47a12beSStefan Roese #endif
85a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSEC1EP /* TSEC1 Emergency priority */
8671bd860cSKim Phillips 		SPCR_TSEC1EP |
87a47a12beSStefan Roese #endif
88a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSEC2EP /* TSEC2 Emergency priority */
8971bd860cSKim Phillips 		SPCR_TSEC2EP |
90a47a12beSStefan Roese #endif
91a47a12beSStefan Roese 		0;
92a47a12beSStefan Roese 	__be32 spcr_val =
93a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_OPT
94a47a12beSStefan Roese 		(CONFIG_SYS_SPCR_OPT << SPCR_OPT_SHIFT) |
95a47a12beSStefan Roese #endif
96a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSECEP /* all eTSEC's Emergency priority */
97a47a12beSStefan Roese 		(CONFIG_SYS_SPCR_TSECEP << SPCR_TSECEP_SHIFT) |
98a47a12beSStefan Roese #endif
99a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSEC1EP /* TSEC1 Emergency priority */
100a47a12beSStefan Roese 		(CONFIG_SYS_SPCR_TSEC1EP << SPCR_TSEC1EP_SHIFT) |
101a47a12beSStefan Roese #endif
102a47a12beSStefan Roese #ifdef CONFIG_SYS_SPCR_TSEC2EP /* TSEC2 Emergency priority */
103a47a12beSStefan Roese 		(CONFIG_SYS_SPCR_TSEC2EP << SPCR_TSEC2EP_SHIFT) |
104a47a12beSStefan Roese #endif
105a47a12beSStefan Roese 		0;
106a47a12beSStefan Roese 	__be32 sccr_mask =
107a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
10871bd860cSKim Phillips 		SCCR_ENCCM |
109a47a12beSStefan Roese #endif
110a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
11171bd860cSKim Phillips 		SCCR_PCICM |
112a47a12beSStefan Roese #endif
113f1371048SIlya Yanok #ifdef CONFIG_SYS_SCCR_PCIEXP1CM	/* PCIE1 clock mode */
114f1371048SIlya Yanok 		SCCR_PCIEXP1CM |
115f1371048SIlya Yanok #endif
116f1371048SIlya Yanok #ifdef CONFIG_SYS_SCCR_PCIEXP2CM	/* PCIE2 clock mode */
117f1371048SIlya Yanok 		SCCR_PCIEXP2CM |
118f1371048SIlya Yanok #endif
119a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
12071bd860cSKim Phillips 		SCCR_TSECCM |
121a47a12beSStefan Roese #endif
122a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
12371bd860cSKim Phillips 		SCCR_TSEC1CM |
124a47a12beSStefan Roese #endif
125a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
12671bd860cSKim Phillips 		SCCR_TSEC2CM |
127a47a12beSStefan Roese #endif
128a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
12971bd860cSKim Phillips 		SCCR_TSEC1ON |
130a47a12beSStefan Roese #endif
131a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
13271bd860cSKim Phillips 		SCCR_TSEC2ON |
133a47a12beSStefan Roese #endif
134a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
13571bd860cSKim Phillips 		SCCR_USBMPHCM |
136a47a12beSStefan Roese #endif
137a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_USBDRCM /* USB DR clock mode */
13871bd860cSKim Phillips 		SCCR_USBDRCM |
139a47a12beSStefan Roese #endif
140a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_SATACM /* SATA controller clock mode */
14171bd860cSKim Phillips 		SCCR_SATACM |
142a47a12beSStefan Roese #endif
143a47a12beSStefan Roese 		0;
144a47a12beSStefan Roese 	__be32 sccr_val =
145a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
146a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_ENCCM << SCCR_ENCCM_SHIFT) |
147a47a12beSStefan Roese #endif
148a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
149a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_PCICM << SCCR_PCICM_SHIFT) |
150a47a12beSStefan Roese #endif
151f1371048SIlya Yanok #ifdef CONFIG_SYS_SCCR_PCIEXP1CM	/* PCIE1 clock mode */
152f1371048SIlya Yanok 		(CONFIG_SYS_SCCR_PCIEXP1CM << SCCR_PCIEXP1CM_SHIFT) |
153f1371048SIlya Yanok #endif
154f1371048SIlya Yanok #ifdef CONFIG_SYS_SCCR_PCIEXP2CM	/* PCIE2 clock mode */
155f1371048SIlya Yanok 		(CONFIG_SYS_SCCR_PCIEXP2CM << SCCR_PCIEXP2CM_SHIFT) |
156f1371048SIlya Yanok #endif
157a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
158a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_TSECCM << SCCR_TSECCM_SHIFT) |
159a47a12beSStefan Roese #endif
160a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
161a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_TSEC1CM << SCCR_TSEC1CM_SHIFT) |
162a47a12beSStefan Roese #endif
163a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
164a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_TSEC2CM << SCCR_TSEC2CM_SHIFT) |
165a47a12beSStefan Roese #endif
166a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
167a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_TSEC1ON << SCCR_TSEC1ON_SHIFT) |
168a47a12beSStefan Roese #endif
169a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
170a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_TSEC2ON << SCCR_TSEC2ON_SHIFT) |
171a47a12beSStefan Roese #endif
172a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
173a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_USBMPHCM << SCCR_USBMPHCM_SHIFT) |
174a47a12beSStefan Roese #endif
175a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_USBDRCM /* USB DR clock mode */
176a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_USBDRCM << SCCR_USBDRCM_SHIFT) |
177a47a12beSStefan Roese #endif
178a47a12beSStefan Roese #ifdef CONFIG_SYS_SCCR_SATACM /* SATA controller clock mode */
179a47a12beSStefan Roese 		(CONFIG_SYS_SCCR_SATACM << SCCR_SATACM_SHIFT) |
180a47a12beSStefan Roese #endif
181a47a12beSStefan Roese 		0;
182a47a12beSStefan Roese 	__be32 lcrr_mask =
183a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_DBYP /* PLL bypass */
184a47a12beSStefan Roese 		LCRR_DBYP |
185a47a12beSStefan Roese #endif
186a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_EADC /* external address delay */
187a47a12beSStefan Roese 		LCRR_EADC |
188a47a12beSStefan Roese #endif
189a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_CLKDIV /* system clock divider */
190a47a12beSStefan Roese 		LCRR_CLKDIV |
191a47a12beSStefan Roese #endif
192a47a12beSStefan Roese 		0;
193a47a12beSStefan Roese 	__be32 lcrr_val =
194a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_DBYP /* PLL bypass */
195a47a12beSStefan Roese 		CONFIG_SYS_LCRR_DBYP |
196a47a12beSStefan Roese #endif
197a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_EADC
198a47a12beSStefan Roese 		CONFIG_SYS_LCRR_EADC |
199a47a12beSStefan Roese #endif
200a47a12beSStefan Roese #ifdef CONFIG_SYS_LCRR_CLKDIV /* system clock divider */
201a47a12beSStefan Roese 		CONFIG_SYS_LCRR_CLKDIV |
202a47a12beSStefan Roese #endif
203a47a12beSStefan Roese 		0;
204a47a12beSStefan Roese 
205a47a12beSStefan Roese 	/* Pointer is writable since we allocated a register for it */
206a47a12beSStefan Roese 	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
207a47a12beSStefan Roese 
208a47a12beSStefan Roese 	/* Clear initial global data */
209a47a12beSStefan Roese 	memset ((void *) gd, 0, sizeof (gd_t));
210a47a12beSStefan Roese 
211a47a12beSStefan Roese 	/* system performance tweaking */
212a47a12beSStefan Roese 	clrsetbits_be32(&im->arbiter.acr, acr_mask, acr_val);
213a47a12beSStefan Roese 
214a47a12beSStefan Roese 	clrsetbits_be32(&im->sysconf.spcr, spcr_mask, spcr_val);
215a47a12beSStefan Roese 
216a47a12beSStefan Roese 	clrsetbits_be32(&im->clk.sccr, sccr_mask, sccr_val);
217a47a12beSStefan Roese 
218a47a12beSStefan Roese 	/* RSR - Reset Status Register - clear all status (4.6.1.3) */
2193c4c308cSSimon Glass 	gd->arch.reset_status = __raw_readl(&im->reset.rsr);
220a47a12beSStefan Roese 	__raw_writel(~(RSR_RES), &im->reset.rsr);
221a47a12beSStefan Roese 
222a47a12beSStefan Roese 	/* AER - Arbiter Event Register - store status */
22343e60814SSimon Glass 	gd->arch.arbiter_event_attributes = __raw_readl(&im->arbiter.aeatr);
22443e60814SSimon Glass 	gd->arch.arbiter_event_address = __raw_readl(&im->arbiter.aeadr);
225a47a12beSStefan Roese 
226a47a12beSStefan Roese 	/*
227a47a12beSStefan Roese 	 * RMR - Reset Mode Register
228a47a12beSStefan Roese 	 * contains checkstop reset enable (4.6.1.4)
229a47a12beSStefan Roese 	 */
230a47a12beSStefan Roese 	__raw_writel(RMR_CSRE & (1<<RMR_CSRE_SHIFT), &im->reset.rmr);
231a47a12beSStefan Roese 
232a47a12beSStefan Roese 	/* LCRR - Clock Ratio Register (10.3.1.16)
233a47a12beSStefan Roese 	 * write, read, and isync per MPC8379ERM rev.1 CLKDEV field description
234a47a12beSStefan Roese 	 */
235f51cdaf1SBecky Bruce 	clrsetbits_be32(&im->im_lbc.lcrr, lcrr_mask, lcrr_val);
236f51cdaf1SBecky Bruce 	__raw_readl(&im->im_lbc.lcrr);
237a47a12beSStefan Roese 	isync();
238a47a12beSStefan Roese 
239a47a12beSStefan Roese 	/* Enable Time Base & Decrementer ( so we will have udelay() )*/
240a47a12beSStefan Roese 	setbits_be32(&im->sysconf.spcr, SPCR_TBEN);
241a47a12beSStefan Roese 
242a47a12beSStefan Roese 	/* System General Purpose Register */
243a47a12beSStefan Roese #ifdef CONFIG_SYS_SICRH
244a47a12beSStefan Roese #if defined(CONFIG_MPC834x) || defined(CONFIG_MPC8313)
245a47a12beSStefan Roese 	/* regarding to MPC34x manual rev.1 bits 28..29 must be preserved */
246a47a12beSStefan Roese 	__raw_writel((im->sysconf.sicrh & 0x0000000C) | CONFIG_SYS_SICRH,
247a47a12beSStefan Roese 		     &im->sysconf.sicrh);
248a47a12beSStefan Roese #else
249a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_SICRH, &im->sysconf.sicrh);
250a47a12beSStefan Roese #endif
251a47a12beSStefan Roese #endif
252a47a12beSStefan Roese #ifdef CONFIG_SYS_SICRL
253a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_SICRL, &im->sysconf.sicrl);
254a47a12beSStefan Roese #endif
255a88731a6SGerlando Falauto #ifdef CONFIG_SYS_GPR1
256a88731a6SGerlando Falauto 	__raw_writel(CONFIG_SYS_GPR1, &im->sysconf.gpr1);
257a88731a6SGerlando Falauto #endif
258a47a12beSStefan Roese #ifdef CONFIG_SYS_DDRCDR /* DDR control driver register */
259a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_DDRCDR, &im->sysconf.ddrcdr);
260a47a12beSStefan Roese #endif
261a47a12beSStefan Roese #ifdef CONFIG_SYS_OBIR /* Output buffer impedance register */
262a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_OBIR, &im->sysconf.obir);
263a47a12beSStefan Roese #endif
264a47a12beSStefan Roese 
265a47a12beSStefan Roese #ifdef CONFIG_QE
266a47a12beSStefan Roese 	/* Config QE ioports */
267a47a12beSStefan Roese 	config_qe_ioports();
268a47a12beSStefan Roese #endif
269f51cdaf1SBecky Bruce 	/* Set up preliminary BR/OR regs */
270f51cdaf1SBecky Bruce 	init_early_memctl_regs();
271a47a12beSStefan Roese 
272f51cdaf1SBecky Bruce 	/* Local Access window setup */
273f51cdaf1SBecky Bruce #if defined(CONFIG_SYS_LBLAWBAR0_PRELIM) && defined(CONFIG_SYS_LBLAWAR0_PRELIM)
274a47a12beSStefan Roese 	im->sysconf.lblaw[0].bar = CONFIG_SYS_LBLAWBAR0_PRELIM;
275a47a12beSStefan Roese 	im->sysconf.lblaw[0].ar = CONFIG_SYS_LBLAWAR0_PRELIM;
276a47a12beSStefan Roese #else
277f51cdaf1SBecky Bruce #error	CONFIG_SYS_LBLAWBAR0_PRELIM & CONFIG_SYS_LBLAWAR0_PRELIM must be defined
278a47a12beSStefan Roese #endif
279a47a12beSStefan Roese 
280a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR1_PRELIM) && defined(CONFIG_SYS_LBLAWAR1_PRELIM)
281a47a12beSStefan Roese 	im->sysconf.lblaw[1].bar = CONFIG_SYS_LBLAWBAR1_PRELIM;
282a47a12beSStefan Roese 	im->sysconf.lblaw[1].ar = CONFIG_SYS_LBLAWAR1_PRELIM;
283a47a12beSStefan Roese #endif
284a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR2_PRELIM) && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
285a47a12beSStefan Roese 	im->sysconf.lblaw[2].bar = CONFIG_SYS_LBLAWBAR2_PRELIM;
286a47a12beSStefan Roese 	im->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2_PRELIM;
287a47a12beSStefan Roese #endif
288a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR3_PRELIM) && defined(CONFIG_SYS_LBLAWAR3_PRELIM)
289a47a12beSStefan Roese 	im->sysconf.lblaw[3].bar = CONFIG_SYS_LBLAWBAR3_PRELIM;
290a47a12beSStefan Roese 	im->sysconf.lblaw[3].ar = CONFIG_SYS_LBLAWAR3_PRELIM;
291a47a12beSStefan Roese #endif
292a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR4_PRELIM) && defined(CONFIG_SYS_LBLAWAR4_PRELIM)
293a47a12beSStefan Roese 	im->sysconf.lblaw[4].bar = CONFIG_SYS_LBLAWBAR4_PRELIM;
294a47a12beSStefan Roese 	im->sysconf.lblaw[4].ar = CONFIG_SYS_LBLAWAR4_PRELIM;
295a47a12beSStefan Roese #endif
296a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR5_PRELIM) && defined(CONFIG_SYS_LBLAWAR5_PRELIM)
297a47a12beSStefan Roese 	im->sysconf.lblaw[5].bar = CONFIG_SYS_LBLAWBAR5_PRELIM;
298a47a12beSStefan Roese 	im->sysconf.lblaw[5].ar = CONFIG_SYS_LBLAWAR5_PRELIM;
299a47a12beSStefan Roese #endif
300a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR6_PRELIM) && defined(CONFIG_SYS_LBLAWAR6_PRELIM)
301a47a12beSStefan Roese 	im->sysconf.lblaw[6].bar = CONFIG_SYS_LBLAWBAR6_PRELIM;
302a47a12beSStefan Roese 	im->sysconf.lblaw[6].ar = CONFIG_SYS_LBLAWAR6_PRELIM;
303a47a12beSStefan Roese #endif
304a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR7_PRELIM) && defined(CONFIG_SYS_LBLAWAR7_PRELIM)
305a47a12beSStefan Roese 	im->sysconf.lblaw[7].bar = CONFIG_SYS_LBLAWBAR7_PRELIM;
306a47a12beSStefan Roese 	im->sysconf.lblaw[7].ar = CONFIG_SYS_LBLAWAR7_PRELIM;
307a47a12beSStefan Roese #endif
308a47a12beSStefan Roese #ifdef CONFIG_SYS_GPIO1_PRELIM
309a47a12beSStefan Roese 	im->gpio[0].dat = CONFIG_SYS_GPIO1_DAT;
310a47a12beSStefan Roese 	im->gpio[0].dir = CONFIG_SYS_GPIO1_DIR;
311a47a12beSStefan Roese #endif
312a47a12beSStefan Roese #ifdef CONFIG_SYS_GPIO2_PRELIM
313a47a12beSStefan Roese 	im->gpio[1].dat = CONFIG_SYS_GPIO2_DAT;
314a47a12beSStefan Roese 	im->gpio[1].dir = CONFIG_SYS_GPIO2_DIR;
315a47a12beSStefan Roese #endif
31684d2e03fSKim Phillips #if defined(CONFIG_USB_EHCI_FSL) && defined(CONFIG_MPC831x)
317a47a12beSStefan Roese 	uint32_t temp;
31877354e9dSramneek mehresh 	struct usb_ehci *ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB1_ADDR;
319a47a12beSStefan Roese 
320a47a12beSStefan Roese 	/* Configure interface. */
321a47a12beSStefan Roese 	setbits_be32(&ehci->control, REFSEL_16MHZ | UTMI_PHY_EN);
322a47a12beSStefan Roese 
323a47a12beSStefan Roese 	/* Wait for clock to stabilize */
324a47a12beSStefan Roese 	do {
325a47a12beSStefan Roese 		temp = __raw_readl(&ehci->control);
326a47a12beSStefan Roese 		udelay(1000);
327a47a12beSStefan Roese 	} while (!(temp & PHY_CLK_VALID));
328a47a12beSStefan Roese #endif
329a47a12beSStefan Roese }
330a47a12beSStefan Roese 
331a47a12beSStefan Roese int cpu_init_r (void)
332a47a12beSStefan Roese {
333a47a12beSStefan Roese #ifdef CONFIG_QE
334a47a12beSStefan Roese 	uint qe_base = CONFIG_SYS_IMMR + 0x00100000; /* QE immr base */
335a47a12beSStefan Roese 
336a47a12beSStefan Roese 	qe_init(qe_base);
337a47a12beSStefan Roese 	qe_reset();
338a47a12beSStefan Roese #endif
339a47a12beSStefan Roese 	return 0;
340a47a12beSStefan Roese }
341a47a12beSStefan Roese 
342a47a12beSStefan Roese /*
343a47a12beSStefan Roese  * Print out the bus arbiter event
344a47a12beSStefan Roese  */
345a47a12beSStefan Roese #if defined(CONFIG_DISPLAY_AER_FULL)
346a47a12beSStefan Roese static int print_83xx_arb_event(int force)
347a47a12beSStefan Roese {
348a47a12beSStefan Roese 	static char* event[] = {
349a47a12beSStefan Roese 		"Address Time Out",
350a47a12beSStefan Roese 		"Data Time Out",
351a47a12beSStefan Roese 		"Address Only Transfer Type",
352a47a12beSStefan Roese 		"External Control Word Transfer Type",
353a47a12beSStefan Roese 		"Reserved Transfer Type",
354a47a12beSStefan Roese 		"Transfer Error",
355a47a12beSStefan Roese 		"reserved",
356a47a12beSStefan Roese 		"reserved"
357a47a12beSStefan Roese 	};
358a47a12beSStefan Roese 	static char* master[] = {
359a47a12beSStefan Roese 		"e300 Core Data Transaction",
360a47a12beSStefan Roese 		"reserved",
361a47a12beSStefan Roese 		"e300 Core Instruction Fetch",
362a47a12beSStefan Roese 		"reserved",
363a47a12beSStefan Roese 		"TSEC1",
364a47a12beSStefan Roese 		"TSEC2",
365a47a12beSStefan Roese 		"USB MPH",
366a47a12beSStefan Roese 		"USB DR",
367a47a12beSStefan Roese 		"Encryption Core",
368a47a12beSStefan Roese 		"I2C Boot Sequencer",
369a47a12beSStefan Roese 		"JTAG",
370a47a12beSStefan Roese 		"reserved",
371a47a12beSStefan Roese 		"eSDHC",
372a47a12beSStefan Roese 		"PCI1",
373a47a12beSStefan Roese 		"PCI2",
374a47a12beSStefan Roese 		"DMA",
375a47a12beSStefan Roese 		"QUICC Engine 00",
376a47a12beSStefan Roese 		"QUICC Engine 01",
377a47a12beSStefan Roese 		"QUICC Engine 10",
378a47a12beSStefan Roese 		"QUICC Engine 11",
379a47a12beSStefan Roese 		"reserved",
380a47a12beSStefan Roese 		"reserved",
381a47a12beSStefan Roese 		"reserved",
382a47a12beSStefan Roese 		"reserved",
383a47a12beSStefan Roese 		"SATA1",
384a47a12beSStefan Roese 		"SATA2",
385a47a12beSStefan Roese 		"SATA3",
386a47a12beSStefan Roese 		"SATA4",
387a47a12beSStefan Roese 		"reserved",
388a47a12beSStefan Roese 		"PCI Express 1",
389a47a12beSStefan Roese 		"PCI Express 2",
390a47a12beSStefan Roese 		"TDM-DMAC"
391a47a12beSStefan Roese 	};
392a47a12beSStefan Roese 	static char *transfer[] = {
393a47a12beSStefan Roese 		"Address-only, Clean Block",
394a47a12beSStefan Roese 		"Address-only, lwarx reservation set",
395a47a12beSStefan Roese 		"Single-beat or Burst write",
396a47a12beSStefan Roese 		"reserved",
397a47a12beSStefan Roese 		"Address-only, Flush Block",
398a47a12beSStefan Roese 		"reserved",
399a47a12beSStefan Roese 		"Burst write",
400a47a12beSStefan Roese 		"reserved",
401a47a12beSStefan Roese 		"Address-only, sync",
402a47a12beSStefan Roese 		"Address-only, tlbsync",
403a47a12beSStefan Roese 		"Single-beat or Burst read",
404a47a12beSStefan Roese 		"Single-beat or Burst read",
405a47a12beSStefan Roese 		"Address-only, Kill Block",
406a47a12beSStefan Roese 		"Address-only, icbi",
407a47a12beSStefan Roese 		"Burst read",
408a47a12beSStefan Roese 		"reserved",
409a47a12beSStefan Roese 		"Address-only, eieio",
410a47a12beSStefan Roese 		"reserved",
411a47a12beSStefan Roese 		"Single-beat write",
412a47a12beSStefan Roese 		"reserved",
413a47a12beSStefan Roese 		"ecowx - Illegal single-beat write",
414a47a12beSStefan Roese 		"reserved",
415a47a12beSStefan Roese 		"reserved",
416a47a12beSStefan Roese 		"reserved",
417a47a12beSStefan Roese 		"Address-only, TLB Invalidate",
418a47a12beSStefan Roese 		"reserved",
419a47a12beSStefan Roese 		"Single-beat or Burst read",
420a47a12beSStefan Roese 		"reserved",
421a47a12beSStefan Roese 		"eciwx - Illegal single-beat read",
422a47a12beSStefan Roese 		"reserved",
423a47a12beSStefan Roese 		"Burst read",
424a47a12beSStefan Roese 		"reserved"
425a47a12beSStefan Roese 	};
426a47a12beSStefan Roese 
42743e60814SSimon Glass 	int etype = (gd->arch.arbiter_event_attributes & AEATR_EVENT)
428a47a12beSStefan Roese 		    >> AEATR_EVENT_SHIFT;
42943e60814SSimon Glass 	int mstr_id = (gd->arch.arbiter_event_attributes & AEATR_MSTR_ID)
430a47a12beSStefan Roese 		      >> AEATR_MSTR_ID_SHIFT;
43143e60814SSimon Glass 	int tbst = (gd->arch.arbiter_event_attributes & AEATR_TBST)
432a47a12beSStefan Roese 		   >> AEATR_TBST_SHIFT;
43343e60814SSimon Glass 	int tsize = (gd->arch.arbiter_event_attributes & AEATR_TSIZE)
434a47a12beSStefan Roese 		    >> AEATR_TSIZE_SHIFT;
43543e60814SSimon Glass 	int ttype = (gd->arch.arbiter_event_attributes & AEATR_TTYPE)
436a47a12beSStefan Roese 		    >> AEATR_TTYPE_SHIFT;
437a47a12beSStefan Roese 
43843e60814SSimon Glass 	if (!force && !gd->arch.arbiter_event_address)
439a47a12beSStefan Roese 		return 0;
440a47a12beSStefan Roese 
441a47a12beSStefan Roese 	puts("Arbiter Event Status:\n");
44243e60814SSimon Glass 	printf("       Event Address: 0x%08lX\n",
44343e60814SSimon Glass 	       gd->arch.arbiter_event_address);
444a47a12beSStefan Roese 	printf("       Event Type:    0x%1x  = %s\n", etype, event[etype]);
445a47a12beSStefan Roese 	printf("       Master ID:     0x%02x = %s\n", mstr_id, master[mstr_id]);
446a47a12beSStefan Roese 	printf("       Transfer Size: 0x%1x  = %d bytes\n", (tbst<<3) | tsize,
447a47a12beSStefan Roese 				tbst ? (tsize ? tsize : 8) : 16 + 8 * tsize);
448a47a12beSStefan Roese 	printf("       Transfer Type: 0x%02x = %s\n", ttype, transfer[ttype]);
449a47a12beSStefan Roese 
45043e60814SSimon Glass 	return gd->arch.arbiter_event_address;
451a47a12beSStefan Roese }
452a47a12beSStefan Roese 
453a47a12beSStefan Roese #elif defined(CONFIG_DISPLAY_AER_BRIEF)
454a47a12beSStefan Roese 
455a47a12beSStefan Roese static int print_83xx_arb_event(int force)
456a47a12beSStefan Roese {
45743e60814SSimon Glass 	if (!force && !gd->arch.arbiter_event_address)
458a47a12beSStefan Roese 		return 0;
459a47a12beSStefan Roese 
460a47a12beSStefan Roese 	printf("Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n",
46143e60814SSimon Glass 		gd->arch.arbiter_event_attributes,
46243e60814SSimon Glass 		gd->arch.arbiter_event_address);
463a47a12beSStefan Roese 
46443e60814SSimon Glass 	return gd->arch.arbiter_event_address;
465a47a12beSStefan Roese }
466a47a12beSStefan Roese #endif /* CONFIG_DISPLAY_AER_xxxx */
467a47a12beSStefan Roese 
468a47a12beSStefan Roese /*
469a47a12beSStefan Roese  * Figure out the cause of the reset
470a47a12beSStefan Roese  */
471a47a12beSStefan Roese int prt_83xx_rsr(void)
472a47a12beSStefan Roese {
473a47a12beSStefan Roese 	static struct {
474a47a12beSStefan Roese 		ulong mask;
475a47a12beSStefan Roese 		char *desc;
476a47a12beSStefan Roese 	} bits[] = {
477a47a12beSStefan Roese 		{
478a47a12beSStefan Roese 		RSR_SWSR, "Software Soft"}, {
479a47a12beSStefan Roese 		RSR_SWHR, "Software Hard"}, {
480a47a12beSStefan Roese 		RSR_JSRS, "JTAG Soft"}, {
481a47a12beSStefan Roese 		RSR_CSHR, "Check Stop"}, {
482a47a12beSStefan Roese 		RSR_SWRS, "Software Watchdog"}, {
483a47a12beSStefan Roese 		RSR_BMRS, "Bus Monitor"}, {
484a47a12beSStefan Roese 		RSR_SRS,  "External/Internal Soft"}, {
485a47a12beSStefan Roese 		RSR_HRS,  "External/Internal Hard"}
486a47a12beSStefan Roese 	};
487*b7707b04SRobert P. J. Day 	static int n = ARRAY_SIZE(bits);
4883c4c308cSSimon Glass 	ulong rsr = gd->arch.reset_status;
489a47a12beSStefan Roese 	int i;
490a47a12beSStefan Roese 	char *sep;
491a47a12beSStefan Roese 
492a47a12beSStefan Roese 	puts("Reset Status:");
493a47a12beSStefan Roese 
494a47a12beSStefan Roese 	sep = " ";
495a47a12beSStefan Roese 	for (i = 0; i < n; i++)
496a47a12beSStefan Roese 		if (rsr & bits[i].mask) {
497a47a12beSStefan Roese 			printf("%s%s", sep, bits[i].desc);
498a47a12beSStefan Roese 			sep = ", ";
499a47a12beSStefan Roese 		}
500a47a12beSStefan Roese 	puts("\n");
501a47a12beSStefan Roese 
502a47a12beSStefan Roese #if defined(CONFIG_DISPLAY_AER_FULL) || defined(CONFIG_DISPLAY_AER_BRIEF)
503a47a12beSStefan Roese 	print_83xx_arb_event(rsr & RSR_BMRS);
504a47a12beSStefan Roese #endif
505a47a12beSStefan Roese 	puts("\n");
506a47a12beSStefan Roese 
507a47a12beSStefan Roese 	return 0;
508a47a12beSStefan Roese }
509