1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2004-2009 Freescale Semiconductor, Inc.
10 #include <asm/processor.h>
11 #ifdef CONFIG_USB_EHCI_FSL
12 #include <usb/ehci-ci.h>
15 #include "lblaw/lblaw.h"
16 #include "elbc/elbc.h"
17 #include "sysio/sysio.h"
18 #include "arbiter/arbiter.h"
20 DECLARE_GLOBAL_DATA_PTR;
23 extern qe_iop_conf_t qe_iop_conf_tab[];
24 extern void qe_config_iopin(u8 port, u8 pin, int dir,
25 int open_drain, int assign);
26 extern void qe_init(uint qe_base);
27 extern void qe_reset(void);
29 static void config_qe_ioports(void)
32 int dir, open_drain, assign;
35 for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
36 port = qe_iop_conf_tab[i].port;
37 pin = qe_iop_conf_tab[i].pin;
38 dir = qe_iop_conf_tab[i].dir;
39 open_drain = qe_iop_conf_tab[i].open_drain;
40 assign = qe_iop_conf_tab[i].assign;
41 qe_config_iopin(port, pin, dir, open_drain, assign);
47 * Breathe some life into the CPU...
49 * Set up the memory map,
50 * initialize a bunch of registers,
51 * initialize the UPM's
53 void cpu_init_f (volatile immap_t * im)
56 #ifdef CONFIG_SYS_SPCR_OPT /* Optimize transactions between CSB and other dev */
59 #ifdef CONFIG_SYS_SPCR_TSECEP /* all eTSEC's Emergency priority */
62 #ifdef CONFIG_SYS_SPCR_TSEC1EP /* TSEC1 Emergency priority */
65 #ifdef CONFIG_SYS_SPCR_TSEC2EP /* TSEC2 Emergency priority */
70 #ifdef CONFIG_SYS_SPCR_OPT
71 (CONFIG_SYS_SPCR_OPT << SPCR_OPT_SHIFT) |
73 #ifdef CONFIG_SYS_SPCR_TSECEP /* all eTSEC's Emergency priority */
74 (CONFIG_SYS_SPCR_TSECEP << SPCR_TSECEP_SHIFT) |
76 #ifdef CONFIG_SYS_SPCR_TSEC1EP /* TSEC1 Emergency priority */
77 (CONFIG_SYS_SPCR_TSEC1EP << SPCR_TSEC1EP_SHIFT) |
79 #ifdef CONFIG_SYS_SPCR_TSEC2EP /* TSEC2 Emergency priority */
80 (CONFIG_SYS_SPCR_TSEC2EP << SPCR_TSEC2EP_SHIFT) |
84 #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
87 #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
90 #ifdef CONFIG_SYS_SCCR_PCIEXP1CM /* PCIE1 clock mode */
93 #ifdef CONFIG_SYS_SCCR_PCIEXP2CM /* PCIE2 clock mode */
96 #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
99 #ifdef CONFIG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
102 #ifdef CONFIG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
105 #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
108 #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
111 #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
114 #ifdef CONFIG_SYS_SCCR_USBDRCM /* USB DR clock mode */
117 #ifdef CONFIG_SYS_SCCR_SATACM /* SATA controller clock mode */
122 #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
123 (CONFIG_SYS_SCCR_ENCCM << SCCR_ENCCM_SHIFT) |
125 #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
126 (CONFIG_SYS_SCCR_PCICM << SCCR_PCICM_SHIFT) |
128 #ifdef CONFIG_SYS_SCCR_PCIEXP1CM /* PCIE1 clock mode */
129 (CONFIG_SYS_SCCR_PCIEXP1CM << SCCR_PCIEXP1CM_SHIFT) |
131 #ifdef CONFIG_SYS_SCCR_PCIEXP2CM /* PCIE2 clock mode */
132 (CONFIG_SYS_SCCR_PCIEXP2CM << SCCR_PCIEXP2CM_SHIFT) |
134 #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
135 (CONFIG_SYS_SCCR_TSECCM << SCCR_TSECCM_SHIFT) |
137 #ifdef CONFIG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
138 (CONFIG_SYS_SCCR_TSEC1CM << SCCR_TSEC1CM_SHIFT) |
140 #ifdef CONFIG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
141 (CONFIG_SYS_SCCR_TSEC2CM << SCCR_TSEC2CM_SHIFT) |
143 #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
144 (CONFIG_SYS_SCCR_TSEC1ON << SCCR_TSEC1ON_SHIFT) |
146 #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
147 (CONFIG_SYS_SCCR_TSEC2ON << SCCR_TSEC2ON_SHIFT) |
149 #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
150 (CONFIG_SYS_SCCR_USBMPHCM << SCCR_USBMPHCM_SHIFT) |
152 #ifdef CONFIG_SYS_SCCR_USBDRCM /* USB DR clock mode */
153 (CONFIG_SYS_SCCR_USBDRCM << SCCR_USBDRCM_SHIFT) |
155 #ifdef CONFIG_SYS_SCCR_SATACM /* SATA controller clock mode */
156 (CONFIG_SYS_SCCR_SATACM << SCCR_SATACM_SHIFT) |
160 #ifdef CONFIG_SYS_LCRR_DBYP /* PLL bypass */
163 #ifdef CONFIG_SYS_LCRR_EADC /* external address delay */
166 #ifdef CONFIG_SYS_LCRR_CLKDIV /* system clock divider */
171 #ifdef CONFIG_SYS_LCRR_DBYP /* PLL bypass */
172 CONFIG_SYS_LCRR_DBYP |
174 #ifdef CONFIG_SYS_LCRR_EADC
175 CONFIG_SYS_LCRR_EADC |
177 #ifdef CONFIG_SYS_LCRR_CLKDIV /* system clock divider */
178 CONFIG_SYS_LCRR_CLKDIV |
182 /* Pointer is writable since we allocated a register for it */
183 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
185 /* global data region was cleared in start.S */
187 /* system performance tweaking */
188 clrsetbits_be32(&im->arbiter.acr, acr_mask, acr_val);
190 clrsetbits_be32(&im->sysconf.spcr, spcr_mask, spcr_val);
192 clrsetbits_be32(&im->clk.sccr, sccr_mask, sccr_val);
194 /* RSR - Reset Status Register - clear all status (4.6.1.3) */
195 gd->arch.reset_status = __raw_readl(&im->reset.rsr);
196 __raw_writel(~(RSR_RES), &im->reset.rsr);
198 /* AER - Arbiter Event Register - store status */
199 gd->arch.arbiter_event_attributes = __raw_readl(&im->arbiter.aeatr);
200 gd->arch.arbiter_event_address = __raw_readl(&im->arbiter.aeadr);
203 * RMR - Reset Mode Register
204 * contains checkstop reset enable (4.6.1.4)
206 __raw_writel(RMR_CSRE & (1<<RMR_CSRE_SHIFT), &im->reset.rmr);
208 /* LCRR - Clock Ratio Register (10.3.1.16)
209 * write, read, and isync per MPC8379ERM rev.1 CLKDEV field description
211 clrsetbits_be32(&im->im_lbc.lcrr, lcrr_mask, lcrr_val);
212 __raw_readl(&im->im_lbc.lcrr);
215 /* Enable Time Base & Decrementer ( so we will have udelay() )*/
216 setbits_be32(&im->sysconf.spcr, SPCR_TBEN);
218 /* System General Purpose Register */
219 #ifdef CONFIG_SYS_SICRH
220 #if defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC8313)
221 /* regarding to MPC34x manual rev.1 bits 28..29 must be preserved */
222 __raw_writel((im->sysconf.sicrh & 0x0000000C) | CONFIG_SYS_SICRH,
225 __raw_writel(CONFIG_SYS_SICRH, &im->sysconf.sicrh);
228 #ifdef CONFIG_SYS_SICRL
229 __raw_writel(CONFIG_SYS_SICRL, &im->sysconf.sicrl);
231 #ifdef CONFIG_SYS_GPR1
232 __raw_writel(CONFIG_SYS_GPR1, &im->sysconf.gpr1);
234 #ifdef CONFIG_SYS_DDRCDR /* DDR control driver register */
235 __raw_writel(CONFIG_SYS_DDRCDR, &im->sysconf.ddrcdr);
237 #ifdef CONFIG_SYS_OBIR /* Output buffer impedance register */
238 __raw_writel(CONFIG_SYS_OBIR, &im->sysconf.obir);
242 /* Config QE ioports */
245 /* Set up preliminary BR/OR regs */
246 init_early_memctl_regs();
248 /* Local Access window setup */
249 #if defined(CONFIG_SYS_LBLAWBAR0_PRELIM) && defined(CONFIG_SYS_LBLAWAR0_PRELIM)
250 im->sysconf.lblaw[0].bar = CONFIG_SYS_LBLAWBAR0_PRELIM;
251 im->sysconf.lblaw[0].ar = CONFIG_SYS_LBLAWAR0_PRELIM;
253 #error CONFIG_SYS_LBLAWBAR0_PRELIM & CONFIG_SYS_LBLAWAR0_PRELIM must be defined
256 #if defined(CONFIG_SYS_LBLAWBAR1_PRELIM) && defined(CONFIG_SYS_LBLAWAR1_PRELIM)
257 im->sysconf.lblaw[1].bar = CONFIG_SYS_LBLAWBAR1_PRELIM;
258 im->sysconf.lblaw[1].ar = CONFIG_SYS_LBLAWAR1_PRELIM;
260 #if defined(CONFIG_SYS_LBLAWBAR2_PRELIM) && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
261 im->sysconf.lblaw[2].bar = CONFIG_SYS_LBLAWBAR2_PRELIM;
262 im->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2_PRELIM;
264 #if defined(CONFIG_SYS_LBLAWBAR3_PRELIM) && defined(CONFIG_SYS_LBLAWAR3_PRELIM)
265 im->sysconf.lblaw[3].bar = CONFIG_SYS_LBLAWBAR3_PRELIM;
266 im->sysconf.lblaw[3].ar = CONFIG_SYS_LBLAWAR3_PRELIM;
268 #if defined(CONFIG_SYS_LBLAWBAR4_PRELIM) && defined(CONFIG_SYS_LBLAWAR4_PRELIM)
269 im->sysconf.lblaw[4].bar = CONFIG_SYS_LBLAWBAR4_PRELIM;
270 im->sysconf.lblaw[4].ar = CONFIG_SYS_LBLAWAR4_PRELIM;
272 #if defined(CONFIG_SYS_LBLAWBAR5_PRELIM) && defined(CONFIG_SYS_LBLAWAR5_PRELIM)
273 im->sysconf.lblaw[5].bar = CONFIG_SYS_LBLAWBAR5_PRELIM;
274 im->sysconf.lblaw[5].ar = CONFIG_SYS_LBLAWAR5_PRELIM;
276 #if defined(CONFIG_SYS_LBLAWBAR6_PRELIM) && defined(CONFIG_SYS_LBLAWAR6_PRELIM)
277 im->sysconf.lblaw[6].bar = CONFIG_SYS_LBLAWBAR6_PRELIM;
278 im->sysconf.lblaw[6].ar = CONFIG_SYS_LBLAWAR6_PRELIM;
280 #if defined(CONFIG_SYS_LBLAWBAR7_PRELIM) && defined(CONFIG_SYS_LBLAWAR7_PRELIM)
281 im->sysconf.lblaw[7].bar = CONFIG_SYS_LBLAWBAR7_PRELIM;
282 im->sysconf.lblaw[7].ar = CONFIG_SYS_LBLAWAR7_PRELIM;
284 #ifdef CONFIG_SYS_GPIO1_PRELIM
285 im->gpio[0].dat = CONFIG_SYS_GPIO1_DAT;
286 im->gpio[0].dir = CONFIG_SYS_GPIO1_DIR;
288 #ifdef CONFIG_SYS_GPIO2_PRELIM
289 im->gpio[1].dat = CONFIG_SYS_GPIO2_DAT;
290 im->gpio[1].dir = CONFIG_SYS_GPIO2_DIR;
292 #if defined(CONFIG_USB_EHCI_FSL) && defined(CONFIG_ARCH_MPC831X)
294 struct usb_ehci *ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB1_ADDR;
296 /* Configure interface. */
297 setbits_be32(&ehci->control, REFSEL_16MHZ | UTMI_PHY_EN);
299 /* Wait for clock to stabilize */
301 temp = __raw_readl(&ehci->control);
303 } while (!(temp & PHY_CLK_VALID));
307 int cpu_init_r (void)
310 uint qe_base = CONFIG_SYS_IMMR + 0x00100000; /* QE immr base */
319 * Print out the bus arbiter event
321 #if defined(CONFIG_DISPLAY_AER_FULL)
322 static int print_83xx_arb_event(int force)
324 static char* event[] = {
327 "Address Only Transfer Type",
328 "External Control Word Transfer Type",
329 "Reserved Transfer Type",
334 static char* master[] = {
335 "e300 Core Data Transaction",
337 "e300 Core Instruction Fetch",
344 "I2C Boot Sequencer",
368 static char *transfer[] = {
369 "Address-only, Clean Block",
370 "Address-only, lwarx reservation set",
371 "Single-beat or Burst write",
373 "Address-only, Flush Block",
377 "Address-only, sync",
378 "Address-only, tlbsync",
379 "Single-beat or Burst read",
380 "Single-beat or Burst read",
381 "Address-only, Kill Block",
382 "Address-only, icbi",
385 "Address-only, eieio",
389 "ecowx - Illegal single-beat write",
393 "Address-only, TLB Invalidate",
395 "Single-beat or Burst read",
397 "eciwx - Illegal single-beat read",
403 int etype = (gd->arch.arbiter_event_attributes & AEATR_EVENT)
404 >> AEATR_EVENT_SHIFT;
405 int mstr_id = (gd->arch.arbiter_event_attributes & AEATR_MSTR_ID)
406 >> AEATR_MSTR_ID_SHIFT;
407 int tbst = (gd->arch.arbiter_event_attributes & AEATR_TBST)
409 int tsize = (gd->arch.arbiter_event_attributes & AEATR_TSIZE)
410 >> AEATR_TSIZE_SHIFT;
411 int ttype = (gd->arch.arbiter_event_attributes & AEATR_TTYPE)
412 >> AEATR_TTYPE_SHIFT;
414 if (!force && !gd->arch.arbiter_event_address)
417 puts("Arbiter Event Status:\n");
418 printf(" Event Address: 0x%08lX\n",
419 gd->arch.arbiter_event_address);
420 printf(" Event Type: 0x%1x = %s\n", etype, event[etype]);
421 printf(" Master ID: 0x%02x = %s\n", mstr_id, master[mstr_id]);
422 printf(" Transfer Size: 0x%1x = %d bytes\n", (tbst<<3) | tsize,
423 tbst ? (tsize ? tsize : 8) : 16 + 8 * tsize);
424 printf(" Transfer Type: 0x%02x = %s\n", ttype, transfer[ttype]);
426 return gd->arch.arbiter_event_address;
429 #elif defined(CONFIG_DISPLAY_AER_BRIEF)
431 static int print_83xx_arb_event(int force)
433 if (!force && !gd->arch.arbiter_event_address)
436 printf("Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n",
437 gd->arch.arbiter_event_attributes,
438 gd->arch.arbiter_event_address);
440 return gd->arch.arbiter_event_address;
442 #endif /* CONFIG_DISPLAY_AER_xxxx */
444 #ifndef CONFIG_CPU_MPC83XX
446 * Figure out the cause of the reset
448 int prt_83xx_rsr(void)
455 RSR_SWSR, "Software Soft"}, {
456 RSR_SWHR, "Software Hard"}, {
457 RSR_JSRS, "JTAG Soft"}, {
458 RSR_CSHR, "Check Stop"}, {
459 RSR_SWRS, "Software Watchdog"}, {
460 RSR_BMRS, "Bus Monitor"}, {
461 RSR_SRS, "External/Internal Soft"}, {
462 RSR_HRS, "External/Internal Hard"}
464 static int n = ARRAY_SIZE(bits);
465 ulong rsr = gd->arch.reset_status;
469 puts("Reset Status:");
472 for (i = 0; i < n; i++)
473 if (rsr & bits[i].mask) {
474 printf("%s%s", sep, bits[i].desc);
479 #if defined(CONFIG_DISPLAY_AER_FULL) || defined(CONFIG_DISPLAY_AER_BRIEF)
480 print_83xx_arb_event(rsr & RSR_BMRS);