xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc83xx/cpu_init.c (revision 1db3fca7192dc3ce7196c628db308ee6ac1ac87a)
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) */
235a47a12beSStefan Roese 	gd->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 */
239a47a12beSStefan Roese 	gd->arbiter_event_attributes = __raw_readl(&im->arbiter.aeatr);
240a47a12beSStefan Roese 	gd->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
271a47a12beSStefan Roese #ifdef CONFIG_SYS_DDRCDR /* DDR control driver register */
272a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_DDRCDR, &im->sysconf.ddrcdr);
273a47a12beSStefan Roese #endif
274a47a12beSStefan Roese #ifdef CONFIG_SYS_OBIR /* Output buffer impedance register */
275a47a12beSStefan Roese 	__raw_writel(CONFIG_SYS_OBIR, &im->sysconf.obir);
276a47a12beSStefan Roese #endif
277a47a12beSStefan Roese 
278a47a12beSStefan Roese #ifdef CONFIG_QE
279a47a12beSStefan Roese 	/* Config QE ioports */
280a47a12beSStefan Roese 	config_qe_ioports();
281a47a12beSStefan Roese #endif
282f51cdaf1SBecky Bruce 	/* Set up preliminary BR/OR regs */
283f51cdaf1SBecky Bruce 	init_early_memctl_regs();
284a47a12beSStefan Roese 
285f51cdaf1SBecky Bruce 	/* Local Access window setup */
286f51cdaf1SBecky Bruce #if defined(CONFIG_SYS_LBLAWBAR0_PRELIM) && defined(CONFIG_SYS_LBLAWAR0_PRELIM)
287a47a12beSStefan Roese 	im->sysconf.lblaw[0].bar = CONFIG_SYS_LBLAWBAR0_PRELIM;
288a47a12beSStefan Roese 	im->sysconf.lblaw[0].ar = CONFIG_SYS_LBLAWAR0_PRELIM;
289a47a12beSStefan Roese #else
290f51cdaf1SBecky Bruce #error	CONFIG_SYS_LBLAWBAR0_PRELIM & CONFIG_SYS_LBLAWAR0_PRELIM must be defined
291a47a12beSStefan Roese #endif
292a47a12beSStefan Roese 
293a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR1_PRELIM) && defined(CONFIG_SYS_LBLAWAR1_PRELIM)
294a47a12beSStefan Roese 	im->sysconf.lblaw[1].bar = CONFIG_SYS_LBLAWBAR1_PRELIM;
295a47a12beSStefan Roese 	im->sysconf.lblaw[1].ar = CONFIG_SYS_LBLAWAR1_PRELIM;
296a47a12beSStefan Roese #endif
297a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR2_PRELIM) && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
298a47a12beSStefan Roese 	im->sysconf.lblaw[2].bar = CONFIG_SYS_LBLAWBAR2_PRELIM;
299a47a12beSStefan Roese 	im->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2_PRELIM;
300a47a12beSStefan Roese #endif
301a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR3_PRELIM) && defined(CONFIG_SYS_LBLAWAR3_PRELIM)
302a47a12beSStefan Roese 	im->sysconf.lblaw[3].bar = CONFIG_SYS_LBLAWBAR3_PRELIM;
303a47a12beSStefan Roese 	im->sysconf.lblaw[3].ar = CONFIG_SYS_LBLAWAR3_PRELIM;
304a47a12beSStefan Roese #endif
305a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR4_PRELIM) && defined(CONFIG_SYS_LBLAWAR4_PRELIM)
306a47a12beSStefan Roese 	im->sysconf.lblaw[4].bar = CONFIG_SYS_LBLAWBAR4_PRELIM;
307a47a12beSStefan Roese 	im->sysconf.lblaw[4].ar = CONFIG_SYS_LBLAWAR4_PRELIM;
308a47a12beSStefan Roese #endif
309a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR5_PRELIM) && defined(CONFIG_SYS_LBLAWAR5_PRELIM)
310a47a12beSStefan Roese 	im->sysconf.lblaw[5].bar = CONFIG_SYS_LBLAWBAR5_PRELIM;
311a47a12beSStefan Roese 	im->sysconf.lblaw[5].ar = CONFIG_SYS_LBLAWAR5_PRELIM;
312a47a12beSStefan Roese #endif
313a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR6_PRELIM) && defined(CONFIG_SYS_LBLAWAR6_PRELIM)
314a47a12beSStefan Roese 	im->sysconf.lblaw[6].bar = CONFIG_SYS_LBLAWBAR6_PRELIM;
315a47a12beSStefan Roese 	im->sysconf.lblaw[6].ar = CONFIG_SYS_LBLAWAR6_PRELIM;
316a47a12beSStefan Roese #endif
317a47a12beSStefan Roese #if defined(CONFIG_SYS_LBLAWBAR7_PRELIM) && defined(CONFIG_SYS_LBLAWAR7_PRELIM)
318a47a12beSStefan Roese 	im->sysconf.lblaw[7].bar = CONFIG_SYS_LBLAWBAR7_PRELIM;
319a47a12beSStefan Roese 	im->sysconf.lblaw[7].ar = CONFIG_SYS_LBLAWAR7_PRELIM;
320a47a12beSStefan Roese #endif
321a47a12beSStefan Roese #ifdef CONFIG_SYS_GPIO1_PRELIM
322a47a12beSStefan Roese 	im->gpio[0].dat = CONFIG_SYS_GPIO1_DAT;
323a47a12beSStefan Roese 	im->gpio[0].dir = CONFIG_SYS_GPIO1_DIR;
324a47a12beSStefan Roese #endif
325a47a12beSStefan Roese #ifdef CONFIG_SYS_GPIO2_PRELIM
326a47a12beSStefan Roese 	im->gpio[1].dat = CONFIG_SYS_GPIO2_DAT;
327a47a12beSStefan Roese 	im->gpio[1].dir = CONFIG_SYS_GPIO2_DIR;
328a47a12beSStefan Roese #endif
329a47a12beSStefan Roese #ifdef CONFIG_USB_EHCI_FSL
330a47a12beSStefan Roese #ifndef CONFIG_MPC834x
331a47a12beSStefan Roese 	uint32_t temp;
332*1db3fca7SWolfgang Denk 	struct usb_ehci *ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
333a47a12beSStefan Roese 
334a47a12beSStefan Roese 	/* Configure interface. */
335a47a12beSStefan Roese 	setbits_be32(&ehci->control, REFSEL_16MHZ | UTMI_PHY_EN);
336a47a12beSStefan Roese 
337a47a12beSStefan Roese 	/* Wait for clock to stabilize */
338a47a12beSStefan Roese 	do {
339a47a12beSStefan Roese 		temp = __raw_readl(&ehci->control);
340a47a12beSStefan Roese 		udelay(1000);
341a47a12beSStefan Roese 	} while (!(temp & PHY_CLK_VALID));
342a47a12beSStefan Roese #endif
343a47a12beSStefan Roese #endif
344a47a12beSStefan Roese }
345a47a12beSStefan Roese 
346a47a12beSStefan Roese int cpu_init_r (void)
347a47a12beSStefan Roese {
348a47a12beSStefan Roese #ifdef CONFIG_QE
349a47a12beSStefan Roese 	uint qe_base = CONFIG_SYS_IMMR + 0x00100000; /* QE immr base */
350a47a12beSStefan Roese 
351a47a12beSStefan Roese 	qe_init(qe_base);
352a47a12beSStefan Roese 	qe_reset();
353a47a12beSStefan Roese #endif
354a47a12beSStefan Roese 	return 0;
355a47a12beSStefan Roese }
356a47a12beSStefan Roese 
357a47a12beSStefan Roese /*
358a47a12beSStefan Roese  * Print out the bus arbiter event
359a47a12beSStefan Roese  */
360a47a12beSStefan Roese #if defined(CONFIG_DISPLAY_AER_FULL)
361a47a12beSStefan Roese static int print_83xx_arb_event(int force)
362a47a12beSStefan Roese {
363a47a12beSStefan Roese 	static char* event[] = {
364a47a12beSStefan Roese 		"Address Time Out",
365a47a12beSStefan Roese 		"Data Time Out",
366a47a12beSStefan Roese 		"Address Only Transfer Type",
367a47a12beSStefan Roese 		"External Control Word Transfer Type",
368a47a12beSStefan Roese 		"Reserved Transfer Type",
369a47a12beSStefan Roese 		"Transfer Error",
370a47a12beSStefan Roese 		"reserved",
371a47a12beSStefan Roese 		"reserved"
372a47a12beSStefan Roese 	};
373a47a12beSStefan Roese 	static char* master[] = {
374a47a12beSStefan Roese 		"e300 Core Data Transaction",
375a47a12beSStefan Roese 		"reserved",
376a47a12beSStefan Roese 		"e300 Core Instruction Fetch",
377a47a12beSStefan Roese 		"reserved",
378a47a12beSStefan Roese 		"TSEC1",
379a47a12beSStefan Roese 		"TSEC2",
380a47a12beSStefan Roese 		"USB MPH",
381a47a12beSStefan Roese 		"USB DR",
382a47a12beSStefan Roese 		"Encryption Core",
383a47a12beSStefan Roese 		"I2C Boot Sequencer",
384a47a12beSStefan Roese 		"JTAG",
385a47a12beSStefan Roese 		"reserved",
386a47a12beSStefan Roese 		"eSDHC",
387a47a12beSStefan Roese 		"PCI1",
388a47a12beSStefan Roese 		"PCI2",
389a47a12beSStefan Roese 		"DMA",
390a47a12beSStefan Roese 		"QUICC Engine 00",
391a47a12beSStefan Roese 		"QUICC Engine 01",
392a47a12beSStefan Roese 		"QUICC Engine 10",
393a47a12beSStefan Roese 		"QUICC Engine 11",
394a47a12beSStefan Roese 		"reserved",
395a47a12beSStefan Roese 		"reserved",
396a47a12beSStefan Roese 		"reserved",
397a47a12beSStefan Roese 		"reserved",
398a47a12beSStefan Roese 		"SATA1",
399a47a12beSStefan Roese 		"SATA2",
400a47a12beSStefan Roese 		"SATA3",
401a47a12beSStefan Roese 		"SATA4",
402a47a12beSStefan Roese 		"reserved",
403a47a12beSStefan Roese 		"PCI Express 1",
404a47a12beSStefan Roese 		"PCI Express 2",
405a47a12beSStefan Roese 		"TDM-DMAC"
406a47a12beSStefan Roese 	};
407a47a12beSStefan Roese 	static char *transfer[] = {
408a47a12beSStefan Roese 		"Address-only, Clean Block",
409a47a12beSStefan Roese 		"Address-only, lwarx reservation set",
410a47a12beSStefan Roese 		"Single-beat or Burst write",
411a47a12beSStefan Roese 		"reserved",
412a47a12beSStefan Roese 		"Address-only, Flush Block",
413a47a12beSStefan Roese 		"reserved",
414a47a12beSStefan Roese 		"Burst write",
415a47a12beSStefan Roese 		"reserved",
416a47a12beSStefan Roese 		"Address-only, sync",
417a47a12beSStefan Roese 		"Address-only, tlbsync",
418a47a12beSStefan Roese 		"Single-beat or Burst read",
419a47a12beSStefan Roese 		"Single-beat or Burst read",
420a47a12beSStefan Roese 		"Address-only, Kill Block",
421a47a12beSStefan Roese 		"Address-only, icbi",
422a47a12beSStefan Roese 		"Burst read",
423a47a12beSStefan Roese 		"reserved",
424a47a12beSStefan Roese 		"Address-only, eieio",
425a47a12beSStefan Roese 		"reserved",
426a47a12beSStefan Roese 		"Single-beat write",
427a47a12beSStefan Roese 		"reserved",
428a47a12beSStefan Roese 		"ecowx - Illegal single-beat write",
429a47a12beSStefan Roese 		"reserved",
430a47a12beSStefan Roese 		"reserved",
431a47a12beSStefan Roese 		"reserved",
432a47a12beSStefan Roese 		"Address-only, TLB Invalidate",
433a47a12beSStefan Roese 		"reserved",
434a47a12beSStefan Roese 		"Single-beat or Burst read",
435a47a12beSStefan Roese 		"reserved",
436a47a12beSStefan Roese 		"eciwx - Illegal single-beat read",
437a47a12beSStefan Roese 		"reserved",
438a47a12beSStefan Roese 		"Burst read",
439a47a12beSStefan Roese 		"reserved"
440a47a12beSStefan Roese 	};
441a47a12beSStefan Roese 
442a47a12beSStefan Roese 	int etype = (gd->arbiter_event_attributes & AEATR_EVENT)
443a47a12beSStefan Roese 	            >> AEATR_EVENT_SHIFT;
444a47a12beSStefan Roese 	int mstr_id = (gd->arbiter_event_attributes & AEATR_MSTR_ID)
445a47a12beSStefan Roese 	              >> AEATR_MSTR_ID_SHIFT;
446a47a12beSStefan Roese 	int tbst = (gd->arbiter_event_attributes & AEATR_TBST)
447a47a12beSStefan Roese 	           >> AEATR_TBST_SHIFT;
448a47a12beSStefan Roese 	int tsize = (gd->arbiter_event_attributes & AEATR_TSIZE)
449a47a12beSStefan Roese 	            >> AEATR_TSIZE_SHIFT;
450a47a12beSStefan Roese 	int ttype = (gd->arbiter_event_attributes & AEATR_TTYPE)
451a47a12beSStefan Roese 	            >> AEATR_TTYPE_SHIFT;
452a47a12beSStefan Roese 
453a47a12beSStefan Roese 	if (!force && !gd->arbiter_event_address)
454a47a12beSStefan Roese 		return 0;
455a47a12beSStefan Roese 
456a47a12beSStefan Roese 	puts("Arbiter Event Status:\n");
457a47a12beSStefan Roese 	printf("       Event Address: 0x%08lX\n", gd->arbiter_event_address);
458a47a12beSStefan Roese 	printf("       Event Type:    0x%1x  = %s\n", etype, event[etype]);
459a47a12beSStefan Roese 	printf("       Master ID:     0x%02x = %s\n", mstr_id, master[mstr_id]);
460a47a12beSStefan Roese 	printf("       Transfer Size: 0x%1x  = %d bytes\n", (tbst<<3) | tsize,
461a47a12beSStefan Roese 				tbst ? (tsize ? tsize : 8) : 16 + 8 * tsize);
462a47a12beSStefan Roese 	printf("       Transfer Type: 0x%02x = %s\n", ttype, transfer[ttype]);
463a47a12beSStefan Roese 
464a47a12beSStefan Roese 	return gd->arbiter_event_address;
465a47a12beSStefan Roese }
466a47a12beSStefan Roese 
467a47a12beSStefan Roese #elif defined(CONFIG_DISPLAY_AER_BRIEF)
468a47a12beSStefan Roese 
469a47a12beSStefan Roese static int print_83xx_arb_event(int force)
470a47a12beSStefan Roese {
471a47a12beSStefan Roese 	if (!force && !gd->arbiter_event_address)
472a47a12beSStefan Roese 		return 0;
473a47a12beSStefan Roese 
474a47a12beSStefan Roese 	printf("Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n",
475a47a12beSStefan Roese 		gd->arbiter_event_attributes, gd->arbiter_event_address);
476a47a12beSStefan Roese 
477a47a12beSStefan Roese 	return gd->arbiter_event_address;
478a47a12beSStefan Roese }
479a47a12beSStefan Roese #endif /* CONFIG_DISPLAY_AER_xxxx */
480a47a12beSStefan Roese 
481a47a12beSStefan Roese /*
482a47a12beSStefan Roese  * Figure out the cause of the reset
483a47a12beSStefan Roese  */
484a47a12beSStefan Roese int prt_83xx_rsr(void)
485a47a12beSStefan Roese {
486a47a12beSStefan Roese 	static struct {
487a47a12beSStefan Roese 		ulong mask;
488a47a12beSStefan Roese 		char *desc;
489a47a12beSStefan Roese 	} bits[] = {
490a47a12beSStefan Roese 		{
491a47a12beSStefan Roese 		RSR_SWSR, "Software Soft"}, {
492a47a12beSStefan Roese 		RSR_SWHR, "Software Hard"}, {
493a47a12beSStefan Roese 		RSR_JSRS, "JTAG Soft"}, {
494a47a12beSStefan Roese 		RSR_CSHR, "Check Stop"}, {
495a47a12beSStefan Roese 		RSR_SWRS, "Software Watchdog"}, {
496a47a12beSStefan Roese 		RSR_BMRS, "Bus Monitor"}, {
497a47a12beSStefan Roese 		RSR_SRS,  "External/Internal Soft"}, {
498a47a12beSStefan Roese 		RSR_HRS,  "External/Internal Hard"}
499a47a12beSStefan Roese 	};
500a47a12beSStefan Roese 	static int n = sizeof bits / sizeof bits[0];
501a47a12beSStefan Roese 	ulong rsr = gd->reset_status;
502a47a12beSStefan Roese 	int i;
503a47a12beSStefan Roese 	char *sep;
504a47a12beSStefan Roese 
505a47a12beSStefan Roese 	puts("Reset Status:");
506a47a12beSStefan Roese 
507a47a12beSStefan Roese 	sep = " ";
508a47a12beSStefan Roese 	for (i = 0; i < n; i++)
509a47a12beSStefan Roese 		if (rsr & bits[i].mask) {
510a47a12beSStefan Roese 			printf("%s%s", sep, bits[i].desc);
511a47a12beSStefan Roese 			sep = ", ";
512a47a12beSStefan Roese 		}
513a47a12beSStefan Roese 	puts("\n");
514a47a12beSStefan Roese 
515a47a12beSStefan Roese #if defined(CONFIG_DISPLAY_AER_FULL) || defined(CONFIG_DISPLAY_AER_BRIEF)
516a47a12beSStefan Roese 	print_83xx_arb_event(rsr & RSR_BMRS);
517a47a12beSStefan Roese #endif
518a47a12beSStefan Roese 	puts("\n");
519a47a12beSStefan Roese 
520a47a12beSStefan Roese 	return 0;
521a47a12beSStefan Roese }
522