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