1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2004-2009 Freescale Semiconductor, Inc.
7 #include <asm-offsets.h>
9 #include <system-constants.h>
11 #include <asm/global_data.h>
13 #include <asm/processor.h>
15 #ifdef CONFIG_USB_EHCI_FSL
16 #include <usb/ehci-ci.h>
18 #include <linux/delay.h>
23 #include "lblaw/lblaw.h"
24 #include "elbc/elbc.h"
25 #include "sysio/sysio.h"
26 #include "arbiter/arbiter.h"
27 #include "initreg/initreg.h"
29 DECLARE_GLOBAL_DATA_PTR;
32 extern qe_iop_conf_t qe_iop_conf_tab[];
33 extern void qe_config_iopin(u8 port, u8 pin, int dir,
34 int open_drain, int assign);
36 #if !defined(CONFIG_PINCTRL)
37 static void config_qe_ioports(void)
40 int dir, open_drain, assign;
43 for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
44 port = qe_iop_conf_tab[i].port;
45 pin = qe_iop_conf_tab[i].pin;
46 dir = qe_iop_conf_tab[i].dir;
47 open_drain = qe_iop_conf_tab[i].open_drain;
48 assign = qe_iop_conf_tab[i].assign;
49 qe_config_iopin(port, pin, dir, open_drain, assign);
56 * Breathe some life into the CPU...
58 * Set up the memory map,
59 * initialize a bunch of registers,
60 * initialize the UPM's
62 void cpu_init_f (volatile immap_t * im)
65 #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
68 #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
71 #ifdef CONFIG_SYS_SCCR_PCIEXP1CM /* PCIE1 clock mode */
74 #ifdef CONFIG_SYS_SCCR_PCIEXP2CM /* PCIE2 clock mode */
77 #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
80 #ifdef CFG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
83 #ifdef CFG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
86 #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
89 #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
92 #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
95 #ifdef CFG_SYS_SCCR_USBDRCM /* USB DR clock mode */
98 #ifdef CFG_SYS_SCCR_SATACM /* SATA controller clock mode */
103 #ifdef CONFIG_SYS_SCCR_ENCCM /* Encryption clock mode */
104 (CONFIG_SYS_SCCR_ENCCM << SCCR_ENCCM_SHIFT) |
106 #ifdef CONFIG_SYS_SCCR_PCICM /* PCI & DMA clock mode */
107 (CONFIG_SYS_SCCR_PCICM << SCCR_PCICM_SHIFT) |
109 #ifdef CONFIG_SYS_SCCR_PCIEXP1CM /* PCIE1 clock mode */
110 (CONFIG_SYS_SCCR_PCIEXP1CM << SCCR_PCIEXP1CM_SHIFT) |
112 #ifdef CONFIG_SYS_SCCR_PCIEXP2CM /* PCIE2 clock mode */
113 (CONFIG_SYS_SCCR_PCIEXP2CM << SCCR_PCIEXP2CM_SHIFT) |
115 #ifdef CONFIG_SYS_SCCR_TSECCM /* all TSEC's clock mode */
116 (CONFIG_SYS_SCCR_TSECCM << SCCR_TSECCM_SHIFT) |
118 #ifdef CFG_SYS_SCCR_TSEC1CM /* TSEC1 clock mode */
119 (CFG_SYS_SCCR_TSEC1CM << SCCR_TSEC1CM_SHIFT) |
121 #ifdef CFG_SYS_SCCR_TSEC2CM /* TSEC2 clock mode */
122 (CFG_SYS_SCCR_TSEC2CM << SCCR_TSEC2CM_SHIFT) |
124 #ifdef CONFIG_SYS_SCCR_TSEC1ON /* TSEC1 clock switch */
125 (CONFIG_SYS_SCCR_TSEC1ON << SCCR_TSEC1ON_SHIFT) |
127 #ifdef CONFIG_SYS_SCCR_TSEC2ON /* TSEC2 clock switch */
128 (CONFIG_SYS_SCCR_TSEC2ON << SCCR_TSEC2ON_SHIFT) |
130 #ifdef CONFIG_SYS_SCCR_USBMPHCM /* USB MPH clock mode */
131 (CONFIG_SYS_SCCR_USBMPHCM << SCCR_USBMPHCM_SHIFT) |
133 #ifdef CFG_SYS_SCCR_USBDRCM /* USB DR clock mode */
134 (CFG_SYS_SCCR_USBDRCM << SCCR_USBDRCM_SHIFT) |
136 #ifdef CFG_SYS_SCCR_SATACM /* SATA controller clock mode */
137 (CFG_SYS_SCCR_SATACM << SCCR_SATACM_SHIFT) |
141 /* Pointer is writable since we allocated a register for it */
142 gd = (gd_t *)SYS_INIT_SP_ADDR;
144 /* global data region was cleared in start.S */
146 /* system performance tweaking */
147 clrsetbits_be32(&im->arbiter.acr, acr_mask, acr_val);
149 clrsetbits_be32(&im->sysconf.spcr, spcr_mask, spcr_val);
151 clrsetbits_be32(&im->clk.sccr, sccr_mask, sccr_val);
153 /* RSR - Reset Status Register - clear all status (4.6.1.3) */
154 gd->arch.reset_status = __raw_readl(&im->reset.rsr);
155 __raw_writel(~(RSR_RES), &im->reset.rsr);
157 /* AER - Arbiter Event Register - store status */
158 gd->arch.arbiter_event_attributes = __raw_readl(&im->arbiter.aeatr);
159 gd->arch.arbiter_event_address = __raw_readl(&im->arbiter.aeadr);
162 * RMR - Reset Mode Register
163 * contains checkstop reset enable (4.6.1.4)
165 __raw_writel(RMR_CSRE & (1<<RMR_CSRE_SHIFT), &im->reset.rmr);
167 /* LCRR - Clock Ratio Register (10.3.1.16)
168 * write, read, and isync per MPC8379ERM rev.1 CLKDEV field description
170 clrsetbits_be32(&im->im_lbc.lcrr, lcrr_mask, lcrr_val);
171 __raw_readl(&im->im_lbc.lcrr);
174 /* Enable Time Base & Decrementer ( so we will have udelay() )*/
175 setbits_be32(&im->sysconf.spcr, SPCR_TBEN);
177 /* System General Purpose Register */
179 #if defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC8313)
180 /* regarding to MPC34x manual rev.1 bits 28..29 must be preserved */
181 __raw_writel((im->sysconf.sicrh & 0x0000000C) | CFG_SYS_SICRH,
184 __raw_writel(CFG_SYS_SICRH, &im->sysconf.sicrh);
188 __raw_writel(CFG_SYS_SICRL, &im->sysconf.sicrl);
191 __raw_writel(CFG_SYS_GPR1, &im->sysconf.gpr1);
193 #ifdef CFG_SYS_DDRCDR /* DDR control driver register */
194 __raw_writel(CFG_SYS_DDRCDR, &im->sysconf.ddrcdr);
196 #ifdef CFG_SYS_OBIR /* Output buffer impedance register */
197 __raw_writel(CFG_SYS_OBIR, &im->sysconf.obir);
200 #if !defined(CONFIG_PINCTRL)
202 /* Config QE ioports */
207 /* Set up preliminary BR/OR regs */
208 init_early_memctl_regs();
210 /* Local Access window setup */
211 #if defined(CFG_SYS_LBLAWBAR0_PRELIM) && defined(CFG_SYS_LBLAWAR0_PRELIM)
212 im->sysconf.lblaw[0].bar = CFG_SYS_LBLAWBAR0_PRELIM;
213 im->sysconf.lblaw[0].ar = CFG_SYS_LBLAWAR0_PRELIM;
215 #error CFG_SYS_LBLAWBAR0_PRELIM & CFG_SYS_LBLAWAR0_PRELIM must be defined
218 #if defined(CFG_SYS_LBLAWBAR1_PRELIM) && defined(CFG_SYS_LBLAWAR1_PRELIM)
219 im->sysconf.lblaw[1].bar = CFG_SYS_LBLAWBAR1_PRELIM;
220 im->sysconf.lblaw[1].ar = CFG_SYS_LBLAWAR1_PRELIM;
222 #if defined(CFG_SYS_LBLAWBAR2_PRELIM) && defined(CFG_SYS_LBLAWAR2_PRELIM)
223 im->sysconf.lblaw[2].bar = CFG_SYS_LBLAWBAR2_PRELIM;
224 im->sysconf.lblaw[2].ar = CFG_SYS_LBLAWAR2_PRELIM;
226 #if defined(CFG_SYS_LBLAWBAR3_PRELIM) && defined(CFG_SYS_LBLAWAR3_PRELIM)
227 im->sysconf.lblaw[3].bar = CFG_SYS_LBLAWBAR3_PRELIM;
228 im->sysconf.lblaw[3].ar = CFG_SYS_LBLAWAR3_PRELIM;
232 int cpu_init_r (void)
235 uint qe_base = CONFIG_SYS_IMMR + 0x00100000; /* QE immr base */
244 * Print out the bus arbiter event
246 #if defined(CONFIG_DISPLAY_AER_FULL)
247 static int print_83xx_arb_event(int force)
249 static char* event[] = {
252 "Address Only Transfer Type",
253 "External Control Word Transfer Type",
254 "Reserved Transfer Type",
259 static char* master[] = {
260 "e300 Core Data Transaction",
262 "e300 Core Instruction Fetch",
269 "I2C Boot Sequencer",
293 static char *transfer[] = {
294 "Address-only, Clean Block",
295 "Address-only, lwarx reservation set",
296 "Single-beat or Burst write",
298 "Address-only, Flush Block",
302 "Address-only, sync",
303 "Address-only, tlbsync",
304 "Single-beat or Burst read",
305 "Single-beat or Burst read",
306 "Address-only, Kill Block",
307 "Address-only, icbi",
310 "Address-only, eieio",
314 "ecowx - Illegal single-beat write",
318 "Address-only, TLB Invalidate",
320 "Single-beat or Burst read",
322 "eciwx - Illegal single-beat read",
328 int etype = (gd->arch.arbiter_event_attributes & AEATR_EVENT)
329 >> AEATR_EVENT_SHIFT;
330 int mstr_id = (gd->arch.arbiter_event_attributes & AEATR_MSTR_ID)
331 >> AEATR_MSTR_ID_SHIFT;
332 int tbst = (gd->arch.arbiter_event_attributes & AEATR_TBST)
334 int tsize = (gd->arch.arbiter_event_attributes & AEATR_TSIZE)
335 >> AEATR_TSIZE_SHIFT;
336 int ttype = (gd->arch.arbiter_event_attributes & AEATR_TTYPE)
337 >> AEATR_TTYPE_SHIFT;
339 if (!force && !gd->arch.arbiter_event_address)
342 puts("Arbiter Event Status:\n");
343 printf(" Event Address: 0x%08lX\n",
344 gd->arch.arbiter_event_address);
345 printf(" Event Type: 0x%1x = %s\n", etype, event[etype]);
346 printf(" Master ID: 0x%02x = %s\n", mstr_id, master[mstr_id]);
347 printf(" Transfer Size: 0x%1x = %d bytes\n", (tbst<<3) | tsize,
348 tbst ? (tsize ? tsize : 8) : 16 + 8 * tsize);
349 printf(" Transfer Type: 0x%02x = %s\n", ttype, transfer[ttype]);
351 return gd->arch.arbiter_event_address;
354 #elif defined(CONFIG_DISPLAY_AER_BRIEF)
356 static int print_83xx_arb_event(int force)
358 if (!force && !gd->arch.arbiter_event_address)
361 printf("Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n",
362 gd->arch.arbiter_event_attributes,
363 gd->arch.arbiter_event_address);
365 return gd->arch.arbiter_event_address;
367 #endif /* CONFIG_DISPLAY_AER_xxxx */
369 #ifndef CONFIG_CPU_MPC83XX
371 * Figure out the cause of the reset
373 int prt_83xx_rsr(void)
380 RSR_SWSR, "Software Soft"}, {
381 RSR_SWHR, "Software Hard"}, {
382 RSR_JSRS, "JTAG Soft"}, {
383 RSR_CSHR, "Check Stop"}, {
384 RSR_SWRS, "Software Watchdog"}, {
385 RSR_BMRS, "Bus Monitor"}, {
386 RSR_SRS, "External/Internal Soft"}, {
387 RSR_HRS, "External/Internal Hard"}
389 static int n = ARRAY_SIZE(bits);
390 ulong rsr = gd->arch.reset_status;
394 puts("Reset Status:");
397 for (i = 0; i < n; i++)
398 if (rsr & bits[i].mask) {
399 printf("%s%s", sep, bits[i].desc);
404 #if defined(CONFIG_DISPLAY_AER_FULL) || defined(CONFIG_DISPLAY_AER_BRIEF)
405 print_83xx_arb_event(rsr & RSR_BMRS);