blob: 16e7bf5fd546ebf68046b9117c13ee21f81136bc [file] [log] [blame]
Christophe Leroy069fa832017-07-06 10:23:22 +02001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <watchdog.h>
10
11#include <mpc8xx.h>
12#include <commproc.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020013#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020014
15/*
16 * Breath some life into the CPU...
17 *
18 * Set up the memory map,
19 * initialize a bunch of registers,
20 * initialize the UPM's
21 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020022void cpu_init_f(immap_t __iomem *immr)
Christophe Leroy069fa832017-07-06 10:23:22 +020023{
Christophe Leroy394f9b32017-07-06 10:33:13 +020024 memctl8xx_t __iomem *memctl = &immr->im_memctl;
Christophe Leroy069fa832017-07-06 10:23:22 +020025 ulong reg;
26
27 /* SYPCR - contains watchdog control (11-9) */
28
Christophe Leroy394f9b32017-07-06 10:33:13 +020029 out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020030
31#if defined(CONFIG_WATCHDOG)
Christophe Leroy48f896d2017-07-06 10:33:17 +020032 reset_8xx_watchdog(immr);
Christophe Leroy069fa832017-07-06 10:23:22 +020033#endif /* CONFIG_WATCHDOG */
34
35 /* SIUMCR - contains debug pin configuration (11-6) */
Christophe Leroy394f9b32017-07-06 10:33:13 +020036 setbits_be32(&immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020037 /* initialize timebase status and control register (11-26) */
38 /* unlock TBSCRK */
39
Christophe Leroy394f9b32017-07-06 10:33:13 +020040 out_be32(&immr->im_sitk.sitk_tbscrk, KAPWR_KEY);
41 out_be16(&immr->im_sit.sit_tbscr, CONFIG_SYS_TBSCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020042
43 /* initialize the PIT (11-31) */
44
Christophe Leroy394f9b32017-07-06 10:33:13 +020045 out_be32(&immr->im_sitk.sitk_piscrk, KAPWR_KEY);
46 out_be16(&immr->im_sit.sit_piscr, CONFIG_SYS_PISCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020047
48 /* System integration timers. Don't change EBDF! (15-27) */
49
Christophe Leroy394f9b32017-07-06 10:33:13 +020050 out_be32(&immr->im_clkrstk.cark_sccrk, KAPWR_KEY);
Christophe Leroy23da3732017-07-06 10:33:21 +020051 clrsetbits_be32(&immr->im_clkrst.car_sccr, ~CONFIG_SYS_SCCR_MASK,
Christophe Leroy394f9b32017-07-06 10:33:13 +020052 CONFIG_SYS_SCCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020053
Christophe Leroy16ad0a42017-07-06 16:49:56 +020054 /*
55 * MPC866/885 ERRATA GLL2
56 * Description:
57 * In 1:2:1 mode, when HRESET is detected at the positive edge of
58 * EXTCLK, then there will be a loss of phase between
59 * EXTCLK and CLKOUT.
60 *
61 * Workaround:
62 * Reprogram the SCCR:
63 * 1. Write 1'b00 to SCCR[EBDF].
64 * 2. Write 1'b01 to SCCR[EBDF].
65 * 3. Rewrite the desired value to the PLPRCR register.
66 */
67 reg = in_be32(&immr->im_clkrst.car_sccr);
68 /* Are we in mode 1:2:1 ? */
69 if ((reg & SCCR_EBDF11) == SCCR_EBDF01) {
70 clrbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF11);
71 setbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF01);
72 }
73
Christophe Leroy069fa832017-07-06 10:23:22 +020074 /* PLL (CPU clock) settings (15-30) */
75
Christophe Leroy394f9b32017-07-06 10:33:13 +020076 out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
Christophe Leroy069fa832017-07-06 10:23:22 +020077
78 /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
79 * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
80 * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
81 * field value.
82 *
83 * For newer (starting MPC866) chips PLPRCR layout is different.
84 */
85#ifdef CONFIG_SYS_PLPRCR
Christophe Leroy394f9b32017-07-06 10:33:13 +020086 if ((CONFIG_SYS_PLPRCR & PLPRCR_MFACT_MSK) != 0) /* reset control bits*/
87 out_be32(&immr->im_clkrst.car_plprcr, CONFIG_SYS_PLPRCR);
88 else /* isolate MF-related fields and reset control bits */
89 clrsetbits_be32(&immr->im_clkrst.car_plprcr, ~PLPRCR_MFACT_MSK,
90 CONFIG_SYS_PLPRCR);
Christophe Leroy069fa832017-07-06 10:23:22 +020091#endif
92
93 /*
94 * Memory Controller:
95 */
96
Christophe Leroy394f9b32017-07-06 10:33:13 +020097 /* Clear everything except Port Size bits & add the "Bank Valid" bit */
98 clrsetbits_be32(&memctl->memc_br0, ~BR_PS_MSK, BR_V);
Christophe Leroy069fa832017-07-06 10:23:22 +020099
100 /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
101 * preliminary addresses - these have to be modified later
102 * when FLASH size has been determined
103 *
104 * Depending on the size of the memory region defined by
105 * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
106 * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
107 * map CONFIG_SYS_MONITOR_BASE.
108 *
109 * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
110 * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
111 *
112 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
113 * base address remains as 0x00000000. However, the address mask
114 * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
115 * into the Bank0.
116 *
117 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
118 * CONFIG_SYS_BR0_PRELIM in advance.
119 *
120 * [Thanks to Michael Liao for this explanation.
121 * I owe him a free beer. - wd]
122 */
123
124#if defined(CONFIG_SYS_OR0_REMAP)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200125 out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_REMAP);
Christophe Leroy069fa832017-07-06 10:23:22 +0200126#endif
127#if defined(CONFIG_SYS_OR1_REMAP)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200128 out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_REMAP);
Christophe Leroy069fa832017-07-06 10:23:22 +0200129#endif
130#if defined(CONFIG_SYS_OR5_REMAP)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200131 out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_REMAP);
Christophe Leroy069fa832017-07-06 10:23:22 +0200132#endif
133
134 /* now restrict to preliminary range */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200135 out_be32(&memctl->memc_br0, CONFIG_SYS_BR0_PRELIM);
136 out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200137
138#if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
Christophe Leroy394f9b32017-07-06 10:33:13 +0200139 out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
140 out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200141#endif
142
143#if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200144 out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_PRELIM);
145 out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200146#endif
147
148#if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200149 out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_PRELIM);
150 out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200151#endif
152
153#if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200154 out_be32(&memctl->memc_or4, CONFIG_SYS_OR4_PRELIM);
155 out_be32(&memctl->memc_br4, CONFIG_SYS_BR4_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200156#endif
157
158#if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200159 out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_PRELIM);
160 out_be32(&memctl->memc_br5, CONFIG_SYS_BR5_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200161#endif
162
163#if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200164 out_be32(&memctl->memc_or6, CONFIG_SYS_OR6_PRELIM);
165 out_be32(&memctl->memc_br6, CONFIG_SYS_BR6_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200166#endif
167
168#if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200169 out_be32(&memctl->memc_or7, CONFIG_SYS_OR7_PRELIM);
170 out_be32(&memctl->memc_br7, CONFIG_SYS_BR7_PRELIM);
Christophe Leroy069fa832017-07-06 10:23:22 +0200171#endif
172
173 /*
174 * Reset CPM
175 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200176 out_be16(&immr->im_cpm.cp_cpcr, CPM_CR_RST | CPM_CR_FLG);
177 /* Spin until command processed */
178 while (in_be16(&immr->im_cpm.cp_cpcr) & CPM_CR_FLG)
179 ;
Christophe Leroy069fa832017-07-06 10:23:22 +0200180}
181
182/*
183 * initialize higher level parts of CPU like timers
184 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200185int cpu_init_r(void)
Christophe Leroy069fa832017-07-06 10:23:22 +0200186{
Christophe Leroy48f896d2017-07-06 10:33:17 +0200187 return 0;
Christophe Leroy069fa832017-07-06 10:23:22 +0200188}