blob: c79e5780ad3d74d7adc3397837383ffa2298d9e2 [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
Wolfgang Denkd87080b2006-03-31 18:32:53 +020030#if defined(CFG_RTCSC) || defined(CFG_RMDS)
31DECLARE_GLOBAL_DATA_PTR;
32#endif
33
wdenk4a9cbbe2002-08-27 09:48:53 +000034#if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
35void cpm_load_patch (volatile immap_t * immr);
36#endif
37
38/*
39 * Breath some life into the CPU...
40 *
41 * Set up the memory map,
42 * initialize a bunch of registers,
43 * initialize the UPM's
44 */
45void cpu_init_f (volatile immap_t * immr)
46{
47#ifndef CONFIG_MBX
48 volatile memctl8xx_t *memctl = &immr->im_memctl;
wdenkc178d3d2004-01-24 20:25:54 +000049# ifdef CFG_PLPRCR
wdenk180d3f72004-01-04 16:28:35 +000050 ulong mfmask;
wdenkc178d3d2004-01-24 20:25:54 +000051# endif
wdenk4a9cbbe2002-08-27 09:48:53 +000052#endif
wdenk3bac3512003-03-12 10:41:04 +000053 ulong reg;
wdenk4a9cbbe2002-08-27 09:48:53 +000054
55 /* SYPCR - contains watchdog control (11-9) */
56
57 immr->im_siu_conf.sc_sypcr = CFG_SYPCR;
58
59#if defined(CONFIG_WATCHDOG)
60 reset_8xx_watchdog (immr);
61#endif /* CONFIG_WATCHDOG */
62
63 /* SIUMCR - contains debug pin configuration (11-6) */
wdenkdc7c9a12003-03-26 06:55:25 +000064#ifndef CONFIG_SVM_SC8xx
wdenk4a9cbbe2002-08-27 09:48:53 +000065 immr->im_siu_conf.sc_siumcr |= CFG_SIUMCR;
wdenkdc7c9a12003-03-26 06:55:25 +000066#else
67 immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
68#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000069 /* initialize timebase status and control register (11-26) */
70 /* unlock TBSCRK */
71
72 immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
73 immr->im_sit.sit_tbscr = CFG_TBSCR;
74
75 /* initialize the PIT (11-31) */
76
77 immr->im_sitk.sitk_piscrk = KAPWR_KEY;
78 immr->im_sit.sit_piscr = CFG_PISCR;
79
wdenk1cb8e982003-03-06 21:55:29 +000080 /* System integration timers. Don't change EBDF! (15-27) */
81
82 immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
83 reg = immr->im_clkrst.car_sccr;
84 reg &= SCCR_MASK;
85 reg |= CFG_SCCR;
86 immr->im_clkrst.car_sccr = reg;
87
wdenk4a9cbbe2002-08-27 09:48:53 +000088 /* PLL (CPU clock) settings (15-30) */
89
90 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
91
92#ifndef CONFIG_MBX /* MBX board does things different */
93
94 /* If CFG_PLPRCR (set in the various *_config.h files) tries to
95 * set the MF field, then just copy CFG_PLPRCR over car_plprcr,
wdenk180d3f72004-01-04 16:28:35 +000096 * otherwise OR in CFG_PLPRCR so we do not change the current MF
wdenk4a9cbbe2002-08-27 09:48:53 +000097 * field value.
wdenk180d3f72004-01-04 16:28:35 +000098 *
99 * For newer (starting MPC866) chips PLPRCR layout is different.
wdenk4a9cbbe2002-08-27 09:48:53 +0000100 */
wdenkc178d3d2004-01-24 20:25:54 +0000101#ifdef CFG_PLPRCR
wdenk180d3f72004-01-04 16:28:35 +0000102 if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
103 mfmask = PLPRCR_MFACT_MSK;
104 else
105 mfmask = PLPRCR_MF_MSK;
106
107 if ((CFG_PLPRCR & mfmask) != 0)
108 reg = CFG_PLPRCR; /* reset control bits */
109 else {
110 reg = immr->im_clkrst.car_plprcr;
111 reg &= mfmask; /* isolate MF-related fields */
112 reg |= CFG_PLPRCR; /* reset control bits */
113 }
wdenk4a9cbbe2002-08-27 09:48:53 +0000114 immr->im_clkrst.car_plprcr = reg;
wdenkc178d3d2004-01-24 20:25:54 +0000115#endif
wdenk4a9cbbe2002-08-27 09:48:53 +0000116
wdenk4a9cbbe2002-08-27 09:48:53 +0000117 /*
118 * Memory Controller:
119 */
120
121 /* perform BR0 reset that MPC850 Rev. A can't guarantee */
122 reg = memctl->memc_br0;
123 reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
124 reg |= BR_V; /* then add just the "Bank Valid" bit */
125 memctl->memc_br0 = reg;
126
127 /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
128 * preliminary addresses - these have to be modified later
129 * when FLASH size has been determined
130 *
131 * Depending on the size of the memory region defined by
132 * CFG_OR0_REMAP some boards (wide address mask) allow to map the
133 * CFG_MONITOR_BASE, while others (narrower address mask) can't
134 * map CFG_MONITOR_BASE.
135 *
136 * For example, for CONFIG_IVMS8, the CFG_MONITOR_BASE is
137 * 0xff000000, but CFG_OR0_REMAP's address mask is 0xfff80000.
138 *
139 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
140 * base address remains as 0x00000000. However, the address mask
141 * have been narrowed to 512Kb, so CFG_MONITOR_BASE wasn't mapped
142 * into the Bank0.
143 *
144 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
145 * CFG_BR0_PRELIM in advance.
146 *
147 * [Thanks to Michael Liao for this explanation.
148 * I owe him a free beer. - wd]
149 */
150
wdenk26238132004-07-09 22:51:01 +0000151#if defined(CONFIG_GTH) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000152 defined(CONFIG_HERMES) || \
153 defined(CONFIG_ICU862) || \
154 defined(CONFIG_IP860) || \
155 defined(CONFIG_IVML24) || \
156 defined(CONFIG_IVMS8) || \
157 defined(CONFIG_LWMON) || \
158 defined(CONFIG_MHPC) || \
159 defined(CONFIG_PCU_E) || \
160 defined(CONFIG_R360MPI) || \
wdenk7e780362004-04-08 22:31:29 +0000161 defined(CONFIG_RMU) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000162 defined(CONFIG_RPXCLASSIC) || \
163 defined(CONFIG_RPXLITE) || \
Markus Klotzbuecherb02d0172006-07-12 08:48:24 +0200164 defined(CONFIG_SPC1920) || \
wdenkb028f712003-12-07 21:39:28 +0000165 defined(CONFIG_SPD823TS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000166
167 memctl->memc_br0 = CFG_BR0_PRELIM;
168#endif
169
170#if defined(CFG_OR0_REMAP)
171 memctl->memc_or0 = CFG_OR0_REMAP;
172#endif
173#if defined(CFG_OR1_REMAP)
174 memctl->memc_or1 = CFG_OR1_REMAP;
175#endif
176#if defined(CFG_OR5_REMAP)
177 memctl->memc_or5 = CFG_OR5_REMAP;
178#endif
179
180 /* now restrict to preliminary range */
181 memctl->memc_br0 = CFG_BR0_PRELIM;
182 memctl->memc_or0 = CFG_OR0_PRELIM;
183
184#if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
185 memctl->memc_or1 = CFG_OR1_PRELIM;
186 memctl->memc_br1 = CFG_BR1_PRELIM;
187#endif
188
189#if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
190 memctl->memc_br0 = 0;
191#endif
192
193#if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
194 memctl->memc_or2 = CFG_OR2_PRELIM;
195 memctl->memc_br2 = CFG_BR2_PRELIM;
196#endif
197
198#if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
199 memctl->memc_or3 = CFG_OR3_PRELIM;
200 memctl->memc_br3 = CFG_BR3_PRELIM;
201#endif
202
203#if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
204 memctl->memc_or4 = CFG_OR4_PRELIM;
205 memctl->memc_br4 = CFG_BR4_PRELIM;
206#endif
207
208#if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
209 memctl->memc_or5 = CFG_OR5_PRELIM;
210 memctl->memc_br5 = CFG_BR5_PRELIM;
211#endif
212
213#if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
214 memctl->memc_or6 = CFG_OR6_PRELIM;
215 memctl->memc_br6 = CFG_BR6_PRELIM;
216#endif
217
218#if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
219 memctl->memc_or7 = CFG_OR7_PRELIM;
220 memctl->memc_br7 = CFG_BR7_PRELIM;
221#endif
222
223#endif /* ! CONFIG_MBX */
224
225 /*
226 * Reset CPM
227 */
228 immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
229 do { /* Spin until command processed */
230 __asm__ ("eieio");
231 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
232
233#ifdef CONFIG_MBX
234 /*
235 * on the MBX, things are a little bit different:
236 * - we need to read the VPD to get board information
237 * - the plprcr is set up dynamically
238 * - the memory controller is set up dynamically
239 */
240 mbx_init ();
241#endif /* CONFIG_MBX */
242
243#ifdef CONFIG_RPXCLASSIC
244 rpxclassic_init ();
245#endif
246
wdenke63c8ee2004-06-09 21:04:48 +0000247#if defined(CONFIG_RPXLITE) && defined(CFG_ENV_IS_IN_NVRAM)
248 rpxlite_init ();
249#endif
250
wdenk4a9cbbe2002-08-27 09:48:53 +0000251#ifdef CFG_RCCR /* must be done before cpm_load_patch() */
252 /* write config value */
253 immr->im_cpm.cp_rccr = CFG_RCCR;
254#endif
255
256#if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
257 cpm_load_patch (immr); /* load mpc8xx microcode patch */
258#endif
259}
260
261/*
262 * initialize higher level parts of CPU like timers
263 */
264int cpu_init_r (void)
265{
266#if defined(CFG_RTCSC) || defined(CFG_RMDS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000267 bd_t *bd = gd->bd;
268 volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
269#endif
270
271#ifdef CFG_RTCSC
272 /* Unlock RTSC register */
273 immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
274 /* write config value */
275 immr->im_sit.sit_rtcsc = CFG_RTCSC;
276#endif
277
278#ifdef CFG_RMDS
279 /* write config value */
280 immr->im_cpm.cp_rmds = CFG_RMDS;
281#endif
282 return (0);
283}