xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc8xx/cpu_init.c (revision 5bda114b503ca66ef5bbc85a2dec06523bab34ba)
1907208c4SChristophe Leroy /*
2907208c4SChristophe Leroy  * (C) Copyright 2000-2002
3907208c4SChristophe Leroy  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4907208c4SChristophe Leroy  *
5907208c4SChristophe Leroy  * SPDX-License-Identifier:	GPL-2.0+
6907208c4SChristophe Leroy  */
7907208c4SChristophe Leroy 
8907208c4SChristophe Leroy #include <common.h>
9907208c4SChristophe Leroy #include <watchdog.h>
10907208c4SChristophe Leroy 
11907208c4SChristophe Leroy #include <mpc8xx.h>
12*5bda114bSChristophe Leroy #include <asm/cpm_8xx.h>
13ba3da734SChristophe Leroy #include <asm/io.h>
14907208c4SChristophe Leroy 
15907208c4SChristophe Leroy /*
16907208c4SChristophe Leroy  * Breath some life into the CPU...
17907208c4SChristophe Leroy  *
18907208c4SChristophe Leroy  * Set up the memory map,
19907208c4SChristophe Leroy  * initialize a bunch of registers,
20907208c4SChristophe Leroy  * initialize the UPM's
21907208c4SChristophe Leroy  */
cpu_init_f(immap_t __iomem * immr)22ba3da734SChristophe Leroy void cpu_init_f(immap_t __iomem *immr)
23907208c4SChristophe Leroy {
24ba3da734SChristophe Leroy 	memctl8xx_t __iomem *memctl = &immr->im_memctl;
25907208c4SChristophe Leroy 	ulong reg;
26907208c4SChristophe Leroy 
27907208c4SChristophe Leroy 	/* SYPCR - contains watchdog control (11-9) */
28907208c4SChristophe Leroy 
29ba3da734SChristophe Leroy 	out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR);
30907208c4SChristophe Leroy 
31907208c4SChristophe Leroy #if defined(CONFIG_WATCHDOG)
32907208c4SChristophe Leroy 	reset_8xx_watchdog(immr);
33907208c4SChristophe Leroy #endif /* CONFIG_WATCHDOG */
34907208c4SChristophe Leroy 
35907208c4SChristophe Leroy 	/* SIUMCR - contains debug pin configuration (11-6) */
36ba3da734SChristophe Leroy 	setbits_be32(&immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR);
37907208c4SChristophe Leroy 	/* initialize timebase status and control register (11-26) */
38907208c4SChristophe Leroy 	/* unlock TBSCRK */
39907208c4SChristophe Leroy 
40ba3da734SChristophe Leroy 	out_be32(&immr->im_sitk.sitk_tbscrk, KAPWR_KEY);
4193e85d02SChristophe Leroy 	out_be16(&immr->im_sit.sit_tbscr, CONFIG_SYS_TBSCR | TBSCR_TBE);
4293e85d02SChristophe Leroy 
4393e85d02SChristophe Leroy 	/* Unlock timebase register */
4493e85d02SChristophe Leroy 	out_be32(&immr->im_sitk.sitk_tbk, KAPWR_KEY);
45907208c4SChristophe Leroy 
46907208c4SChristophe Leroy 	/* initialize the PIT (11-31) */
47907208c4SChristophe Leroy 
48ba3da734SChristophe Leroy 	out_be32(&immr->im_sitk.sitk_piscrk, KAPWR_KEY);
49ba3da734SChristophe Leroy 	out_be16(&immr->im_sit.sit_piscr, CONFIG_SYS_PISCR);
50907208c4SChristophe Leroy 
51907208c4SChristophe Leroy 	/* System integration timers. Don't change EBDF! (15-27) */
52907208c4SChristophe Leroy 
53ba3da734SChristophe Leroy 	out_be32(&immr->im_clkrstk.cark_sccrk, KAPWR_KEY);
54b1e41d1cSChristophe Leroy 	clrsetbits_be32(&immr->im_clkrst.car_sccr, ~CONFIG_SYS_SCCR_MASK,
55ba3da734SChristophe Leroy 			CONFIG_SYS_SCCR);
56907208c4SChristophe Leroy 
5773bc94c6SChristophe Leroy 	/*
5873bc94c6SChristophe Leroy 	 * MPC866/885 ERRATA GLL2
5973bc94c6SChristophe Leroy 	 * Description:
6073bc94c6SChristophe Leroy 	 *   In 1:2:1 mode, when HRESET is detected at the positive edge of
6173bc94c6SChristophe Leroy 	 *   EXTCLK, then there will be a loss of phase between
6273bc94c6SChristophe Leroy 	 *   EXTCLK and CLKOUT.
6373bc94c6SChristophe Leroy 	 *
6473bc94c6SChristophe Leroy 	 * Workaround:
6573bc94c6SChristophe Leroy 	 *   Reprogram the SCCR:
6673bc94c6SChristophe Leroy 	 *   1.   Write 1'b00 to SCCR[EBDF].
6773bc94c6SChristophe Leroy 	 *   2.   Write 1'b01 to SCCR[EBDF].
6873bc94c6SChristophe Leroy 	 *   3.   Rewrite the desired value to the PLPRCR register.
6973bc94c6SChristophe Leroy 	 */
7073bc94c6SChristophe Leroy 	reg = in_be32(&immr->im_clkrst.car_sccr);
7173bc94c6SChristophe Leroy 	/* Are we in mode 1:2:1 ? */
7273bc94c6SChristophe Leroy 	if ((reg & SCCR_EBDF11) == SCCR_EBDF01) {
7373bc94c6SChristophe Leroy 		clrbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF11);
7473bc94c6SChristophe Leroy 		setbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF01);
7573bc94c6SChristophe Leroy 	}
7673bc94c6SChristophe Leroy 
77907208c4SChristophe Leroy 	/* PLL (CPU clock) settings (15-30) */
78907208c4SChristophe Leroy 
79ba3da734SChristophe Leroy 	out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
80907208c4SChristophe Leroy 
81907208c4SChristophe Leroy 	/* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
82907208c4SChristophe Leroy 	 * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
83907208c4SChristophe Leroy 	 * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
84907208c4SChristophe Leroy 	 * field value.
85907208c4SChristophe Leroy 	 *
86907208c4SChristophe Leroy 	 * For newer (starting MPC866) chips PLPRCR layout is different.
87907208c4SChristophe Leroy 	 */
88907208c4SChristophe Leroy #ifdef CONFIG_SYS_PLPRCR
89ba3da734SChristophe Leroy 	if ((CONFIG_SYS_PLPRCR & PLPRCR_MFACT_MSK) != 0) /* reset control bits*/
90ba3da734SChristophe Leroy 		out_be32(&immr->im_clkrst.car_plprcr, CONFIG_SYS_PLPRCR);
91ba3da734SChristophe Leroy 	else /* isolate MF-related fields and reset control bits */
92ba3da734SChristophe Leroy 		clrsetbits_be32(&immr->im_clkrst.car_plprcr, ~PLPRCR_MFACT_MSK,
93ba3da734SChristophe Leroy 				CONFIG_SYS_PLPRCR);
94907208c4SChristophe Leroy #endif
95907208c4SChristophe Leroy 
96907208c4SChristophe Leroy 	/*
97907208c4SChristophe Leroy 	 * Memory Controller:
98907208c4SChristophe Leroy 	 */
99907208c4SChristophe Leroy 
100ba3da734SChristophe Leroy 	/* Clear everything except Port Size bits & add the "Bank Valid" bit */
101ba3da734SChristophe Leroy 	clrsetbits_be32(&memctl->memc_br0, ~BR_PS_MSK, BR_V);
102907208c4SChristophe Leroy 
103907208c4SChristophe Leroy 	/* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
104907208c4SChristophe Leroy 	 * preliminary addresses - these have to be modified later
105907208c4SChristophe Leroy 	 * when FLASH size has been determined
106907208c4SChristophe Leroy 	 *
107907208c4SChristophe Leroy 	 * Depending on the size of the memory region defined by
108907208c4SChristophe Leroy 	 * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
109907208c4SChristophe Leroy 	 * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
110907208c4SChristophe Leroy 	 * map CONFIG_SYS_MONITOR_BASE.
111907208c4SChristophe Leroy 	 *
112907208c4SChristophe Leroy 	 * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
113907208c4SChristophe Leroy 	 * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
114907208c4SChristophe Leroy 	 *
115907208c4SChristophe Leroy 	 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
116907208c4SChristophe Leroy 	 * base address remains as 0x00000000. However, the address mask
117907208c4SChristophe Leroy 	 * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
118907208c4SChristophe Leroy 	 * into the Bank0.
119907208c4SChristophe Leroy 	 *
120907208c4SChristophe Leroy 	 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
121907208c4SChristophe Leroy 	 * CONFIG_SYS_BR0_PRELIM in advance.
122907208c4SChristophe Leroy 	 *
123907208c4SChristophe Leroy 	 * [Thanks to Michael Liao for this explanation.
124907208c4SChristophe Leroy 	 *  I owe him a free beer. - wd]
125907208c4SChristophe Leroy 	 */
126907208c4SChristophe Leroy 
127907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR0_REMAP)
128ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_REMAP);
129907208c4SChristophe Leroy #endif
130907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR1_REMAP)
131ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_REMAP);
132907208c4SChristophe Leroy #endif
133907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_REMAP)
134ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_REMAP);
135907208c4SChristophe Leroy #endif
136907208c4SChristophe Leroy 
137907208c4SChristophe Leroy 	/* now restrict to preliminary range */
138ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br0, CONFIG_SYS_BR0_PRELIM);
139ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_PRELIM);
140907208c4SChristophe Leroy 
141907208c4SChristophe Leroy #if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
142ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
143ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
144907208c4SChristophe Leroy #endif
145907208c4SChristophe Leroy 
146907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
147ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_PRELIM);
148ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_PRELIM);
149907208c4SChristophe Leroy #endif
150907208c4SChristophe Leroy 
151907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
152ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_PRELIM);
153ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_PRELIM);
154907208c4SChristophe Leroy #endif
155907208c4SChristophe Leroy 
156907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
157ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or4, CONFIG_SYS_OR4_PRELIM);
158ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br4, CONFIG_SYS_BR4_PRELIM);
159907208c4SChristophe Leroy #endif
160907208c4SChristophe Leroy 
161907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
162ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_PRELIM);
163ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br5, CONFIG_SYS_BR5_PRELIM);
164907208c4SChristophe Leroy #endif
165907208c4SChristophe Leroy 
166907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
167ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or6, CONFIG_SYS_OR6_PRELIM);
168ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br6, CONFIG_SYS_BR6_PRELIM);
169907208c4SChristophe Leroy #endif
170907208c4SChristophe Leroy 
171907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
172ba3da734SChristophe Leroy 	out_be32(&memctl->memc_or7, CONFIG_SYS_OR7_PRELIM);
173ba3da734SChristophe Leroy 	out_be32(&memctl->memc_br7, CONFIG_SYS_BR7_PRELIM);
174907208c4SChristophe Leroy #endif
175907208c4SChristophe Leroy 
176907208c4SChristophe Leroy 	/*
177907208c4SChristophe Leroy 	 * Reset CPM
178907208c4SChristophe Leroy 	 */
179ba3da734SChristophe Leroy 	out_be16(&immr->im_cpm.cp_cpcr, CPM_CR_RST | CPM_CR_FLG);
180ba3da734SChristophe Leroy 	/* Spin until command processed */
181ba3da734SChristophe Leroy 	while (in_be16(&immr->im_cpm.cp_cpcr) & CPM_CR_FLG)
182ba3da734SChristophe Leroy 		;
183907208c4SChristophe Leroy }
184907208c4SChristophe Leroy 
185907208c4SChristophe Leroy /*
186907208c4SChristophe Leroy  * initialize higher level parts of CPU like timers
187907208c4SChristophe Leroy  */
cpu_init_r(void)188907208c4SChristophe Leroy int cpu_init_r(void)
189907208c4SChristophe Leroy {
19070fd0710SChristophe Leroy 	return 0;
191907208c4SChristophe Leroy }
192