blob: 83ff66a48a395ef53357500d0967fd1884d855d0 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <watchdog.h>
26
27#include <mpc8xx.h>
28#include <commproc.h>
29
30#if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
31void cpm_load_patch (volatile immap_t * immr);
32#endif
33
34/*
35 * Breath some life into the CPU...
36 *
37 * Set up the memory map,
38 * initialize a bunch of registers,
39 * initialize the UPM's
40 */
41void cpu_init_f (volatile immap_t * immr)
42{
43#ifndef CONFIG_MBX
44 volatile memctl8xx_t *memctl = &immr->im_memctl;
wdenk4a9cbbe2002-08-27 09:48:53 +000045#endif
wdenk3bac3512003-03-12 10:41:04 +000046 ulong reg;
wdenk4a9cbbe2002-08-27 09:48:53 +000047
48 /* SYPCR - contains watchdog control (11-9) */
49
50 immr->im_siu_conf.sc_sypcr = CFG_SYPCR;
51
52#if defined(CONFIG_WATCHDOG)
53 reset_8xx_watchdog (immr);
54#endif /* CONFIG_WATCHDOG */
55
56 /* SIUMCR - contains debug pin configuration (11-6) */
wdenkdc7c9a12003-03-26 06:55:25 +000057#ifndef CONFIG_SVM_SC8xx
wdenk4a9cbbe2002-08-27 09:48:53 +000058 immr->im_siu_conf.sc_siumcr |= CFG_SIUMCR;
wdenkdc7c9a12003-03-26 06:55:25 +000059#else
60 immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
61#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000062 /* initialize timebase status and control register (11-26) */
63 /* unlock TBSCRK */
64
65 immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
66 immr->im_sit.sit_tbscr = CFG_TBSCR;
67
68 /* initialize the PIT (11-31) */
69
70 immr->im_sitk.sitk_piscrk = KAPWR_KEY;
71 immr->im_sit.sit_piscr = CFG_PISCR;
72
wdenk1cb8e982003-03-06 21:55:29 +000073 /* System integration timers. Don't change EBDF! (15-27) */
74
75 immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
76 reg = immr->im_clkrst.car_sccr;
77 reg &= SCCR_MASK;
78 reg |= CFG_SCCR;
79 immr->im_clkrst.car_sccr = reg;
80
wdenk4a9cbbe2002-08-27 09:48:53 +000081 /* PLL (CPU clock) settings (15-30) */
82
83 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
84
85#ifndef CONFIG_MBX /* MBX board does things different */
86
87 /* If CFG_PLPRCR (set in the various *_config.h files) tries to
88 * set the MF field, then just copy CFG_PLPRCR over car_plprcr,
89 * otherwise OR in CFG_PLPRCR so we do not change the currentMF
90 * field value.
91 */
92#if ((CFG_PLPRCR & PLPRCR_MF_MSK) != 0)
93 reg = CFG_PLPRCR; /* reset control bits */
94#else
95 reg = immr->im_clkrst.car_plprcr;
96 reg &= PLPRCR_MF_MSK; /* isolate MF field */
97 reg |= CFG_PLPRCR; /* reset control bits */
98#endif
99 immr->im_clkrst.car_plprcr = reg;
100
wdenk4a9cbbe2002-08-27 09:48:53 +0000101 /*
102 * Memory Controller:
103 */
104
105 /* perform BR0 reset that MPC850 Rev. A can't guarantee */
106 reg = memctl->memc_br0;
107 reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
108 reg |= BR_V; /* then add just the "Bank Valid" bit */
109 memctl->memc_br0 = reg;
110
111 /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
112 * preliminary addresses - these have to be modified later
113 * when FLASH size has been determined
114 *
115 * Depending on the size of the memory region defined by
116 * CFG_OR0_REMAP some boards (wide address mask) allow to map the
117 * CFG_MONITOR_BASE, while others (narrower address mask) can't
118 * map CFG_MONITOR_BASE.
119 *
120 * For example, for CONFIG_IVMS8, the CFG_MONITOR_BASE is
121 * 0xff000000, but CFG_OR0_REMAP's address mask is 0xfff80000.
122 *
123 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
124 * base address remains as 0x00000000. However, the address mask
125 * have been narrowed to 512Kb, so CFG_MONITOR_BASE wasn't mapped
126 * into the Bank0.
127 *
128 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
129 * CFG_BR0_PRELIM in advance.
130 *
131 * [Thanks to Michael Liao for this explanation.
132 * I owe him a free beer. - wd]
133 */
134
135#if defined(CONFIG_GTH) || \
136 defined(CONFIG_HERMES) || \
137 defined(CONFIG_ICU862) || \
138 defined(CONFIG_IP860) || \
139 defined(CONFIG_IVML24) || \
140 defined(CONFIG_IVMS8) || \
141 defined(CONFIG_LWMON) || \
142 defined(CONFIG_MHPC) || \
143 defined(CONFIG_PCU_E) || \
144 defined(CONFIG_R360MPI) || \
145 defined(CONFIG_RPXCLASSIC) || \
146 defined(CONFIG_RPXLITE) || \
147 defined(CONFIG_SPD823TS) || \
148 (defined(CONFIG_MPC860T) && defined(CONFIG_FADS))
149
150 memctl->memc_br0 = CFG_BR0_PRELIM;
151#endif
152
153#if defined(CFG_OR0_REMAP)
154 memctl->memc_or0 = CFG_OR0_REMAP;
155#endif
156#if defined(CFG_OR1_REMAP)
157 memctl->memc_or1 = CFG_OR1_REMAP;
158#endif
159#if defined(CFG_OR5_REMAP)
160 memctl->memc_or5 = CFG_OR5_REMAP;
161#endif
162
163 /* now restrict to preliminary range */
164 memctl->memc_br0 = CFG_BR0_PRELIM;
165 memctl->memc_or0 = CFG_OR0_PRELIM;
166
167#if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
168 memctl->memc_or1 = CFG_OR1_PRELIM;
169 memctl->memc_br1 = CFG_BR1_PRELIM;
170#endif
171
172#if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
173 memctl->memc_br0 = 0;
174#endif
175
176#if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
177 memctl->memc_or2 = CFG_OR2_PRELIM;
178 memctl->memc_br2 = CFG_BR2_PRELIM;
179#endif
180
181#if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
182 memctl->memc_or3 = CFG_OR3_PRELIM;
183 memctl->memc_br3 = CFG_BR3_PRELIM;
184#endif
185
186#if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
187 memctl->memc_or4 = CFG_OR4_PRELIM;
188 memctl->memc_br4 = CFG_BR4_PRELIM;
189#endif
190
191#if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
192 memctl->memc_or5 = CFG_OR5_PRELIM;
193 memctl->memc_br5 = CFG_BR5_PRELIM;
194#endif
195
196#if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
197 memctl->memc_or6 = CFG_OR6_PRELIM;
198 memctl->memc_br6 = CFG_BR6_PRELIM;
199#endif
200
201#if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
202 memctl->memc_or7 = CFG_OR7_PRELIM;
203 memctl->memc_br7 = CFG_BR7_PRELIM;
204#endif
205
206#endif /* ! CONFIG_MBX */
207
208 /*
209 * Reset CPM
210 */
211 immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
212 do { /* Spin until command processed */
213 __asm__ ("eieio");
214 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
215
216#ifdef CONFIG_MBX
217 /*
218 * on the MBX, things are a little bit different:
219 * - we need to read the VPD to get board information
220 * - the plprcr is set up dynamically
221 * - the memory controller is set up dynamically
222 */
223 mbx_init ();
224#endif /* CONFIG_MBX */
225
226#ifdef CONFIG_RPXCLASSIC
227 rpxclassic_init ();
228#endif
229
230#ifdef CFG_RCCR /* must be done before cpm_load_patch() */
231 /* write config value */
232 immr->im_cpm.cp_rccr = CFG_RCCR;
233#endif
234
235#if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
236 cpm_load_patch (immr); /* load mpc8xx microcode patch */
237#endif
238}
239
240/*
241 * initialize higher level parts of CPU like timers
242 */
243int cpu_init_r (void)
244{
245#if defined(CFG_RTCSC) || defined(CFG_RMDS)
246 DECLARE_GLOBAL_DATA_PTR;
247
248 bd_t *bd = gd->bd;
249 volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
250#endif
251
252#ifdef CFG_RTCSC
253 /* Unlock RTSC register */
254 immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
255 /* write config value */
256 immr->im_sit.sit_rtcsc = CFG_RTCSC;
257#endif
258
259#ifdef CFG_RMDS
260 /* write config value */
261 immr->im_cpm.cp_rmds = CFG_RMDS;
262#endif
263 return (0);
264}