blob: 49b354d1abeb0dde19043027023587cfe322ba27 [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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020030#if defined(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_RMDS)
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32#endif
33
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034#if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
35 defined(CONFIG_SYS_SMC_UCODE_PATCH)
wdenk4a9cbbe2002-08-27 09:48:53 +000036void cpm_load_patch (volatile immap_t * immr);
37#endif
38
39/*
40 * Breath some life into the CPU...
41 *
42 * Set up the memory map,
43 * initialize a bunch of registers,
44 * initialize the UPM's
45 */
46void cpu_init_f (volatile immap_t * immr)
47{
48#ifndef CONFIG_MBX
49 volatile memctl8xx_t *memctl = &immr->im_memctl;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050# ifdef CONFIG_SYS_PLPRCR
wdenk180d3f72004-01-04 16:28:35 +000051 ulong mfmask;
wdenkc178d3d2004-01-24 20:25:54 +000052# endif
wdenk4a9cbbe2002-08-27 09:48:53 +000053#endif
wdenk3bac3512003-03-12 10:41:04 +000054 ulong reg;
wdenk4a9cbbe2002-08-27 09:48:53 +000055
56 /* SYPCR - contains watchdog control (11-9) */
57
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020058 immr->im_siu_conf.sc_sypcr = CONFIG_SYS_SYPCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000059
60#if defined(CONFIG_WATCHDOG)
61 reset_8xx_watchdog (immr);
62#endif /* CONFIG_WATCHDOG */
63
64 /* SIUMCR - contains debug pin configuration (11-6) */
wdenkdc7c9a12003-03-26 06:55:25 +000065#ifndef CONFIG_SVM_SC8xx
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020066 immr->im_siu_conf.sc_siumcr |= CONFIG_SYS_SIUMCR;
wdenkdc7c9a12003-03-26 06:55:25 +000067#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020068 immr->im_siu_conf.sc_siumcr = CONFIG_SYS_SIUMCR;
wdenkdc7c9a12003-03-26 06:55:25 +000069#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000070 /* initialize timebase status and control register (11-26) */
71 /* unlock TBSCRK */
72
73 immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020074 immr->im_sit.sit_tbscr = CONFIG_SYS_TBSCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000075
76 /* initialize the PIT (11-31) */
77
78 immr->im_sitk.sitk_piscrk = KAPWR_KEY;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079 immr->im_sit.sit_piscr = CONFIG_SYS_PISCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000080
wdenk1cb8e982003-03-06 21:55:29 +000081 /* System integration timers. Don't change EBDF! (15-27) */
82
83 immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
84 reg = immr->im_clkrst.car_sccr;
85 reg &= SCCR_MASK;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020086 reg |= CONFIG_SYS_SCCR;
wdenk1cb8e982003-03-06 21:55:29 +000087 immr->im_clkrst.car_sccr = reg;
88
wdenk4a9cbbe2002-08-27 09:48:53 +000089 /* PLL (CPU clock) settings (15-30) */
90
91 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
92
93#ifndef CONFIG_MBX /* MBX board does things different */
94
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
96 * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
97 * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
wdenk4a9cbbe2002-08-27 09:48:53 +000098 * field value.
wdenk180d3f72004-01-04 16:28:35 +000099 *
100 * For newer (starting MPC866) chips PLPRCR layout is different.
wdenk4a9cbbe2002-08-27 09:48:53 +0000101 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102#ifdef CONFIG_SYS_PLPRCR
wdenk180d3f72004-01-04 16:28:35 +0000103 if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
104 mfmask = PLPRCR_MFACT_MSK;
105 else
106 mfmask = PLPRCR_MF_MSK;
107
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200108 if ((CONFIG_SYS_PLPRCR & mfmask) != 0)
109 reg = CONFIG_SYS_PLPRCR; /* reset control bits */
wdenk180d3f72004-01-04 16:28:35 +0000110 else {
111 reg = immr->im_clkrst.car_plprcr;
112 reg &= mfmask; /* isolate MF-related fields */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113 reg |= CONFIG_SYS_PLPRCR; /* reset control bits */
wdenk180d3f72004-01-04 16:28:35 +0000114 }
wdenk4a9cbbe2002-08-27 09:48:53 +0000115 immr->im_clkrst.car_plprcr = reg;
wdenkc178d3d2004-01-24 20:25:54 +0000116#endif
wdenk4a9cbbe2002-08-27 09:48:53 +0000117
wdenk4a9cbbe2002-08-27 09:48:53 +0000118 /*
119 * Memory Controller:
120 */
121
122 /* perform BR0 reset that MPC850 Rev. A can't guarantee */
123 reg = memctl->memc_br0;
124 reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
125 reg |= BR_V; /* then add just the "Bank Valid" bit */
126 memctl->memc_br0 = reg;
127
128 /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
129 * preliminary addresses - these have to be modified later
130 * when FLASH size has been determined
131 *
132 * Depending on the size of the memory region defined by
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133 * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
134 * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
135 * map CONFIG_SYS_MONITOR_BASE.
wdenk4a9cbbe2002-08-27 09:48:53 +0000136 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200137 * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
138 * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
wdenk4a9cbbe2002-08-27 09:48:53 +0000139 *
140 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
141 * base address remains as 0x00000000. However, the address mask
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200142 * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
wdenk4a9cbbe2002-08-27 09:48:53 +0000143 * into the Bank0.
144 *
145 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200146 * CONFIG_SYS_BR0_PRELIM in advance.
wdenk4a9cbbe2002-08-27 09:48:53 +0000147 *
148 * [Thanks to Michael Liao for this explanation.
149 * I owe him a free beer. - wd]
150 */
151
Wolfgang Denk0fe247b2010-07-05 22:46:33 +0200152#if defined(CONFIG_HERMES) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000153 defined(CONFIG_ICU862) || \
154 defined(CONFIG_IP860) || \
155 defined(CONFIG_IVML24) || \
156 defined(CONFIG_IVMS8) || \
157 defined(CONFIG_LWMON) || \
158 defined(CONFIG_MHPC) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000159 defined(CONFIG_R360MPI) || \
wdenk7e780362004-04-08 22:31:29 +0000160 defined(CONFIG_RMU) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000161 defined(CONFIG_RPXCLASSIC) || \
162 defined(CONFIG_RPXLITE) || \
Markus Klotzbuecherb02d0172006-07-12 08:48:24 +0200163 defined(CONFIG_SPC1920) || \
wdenkb028f712003-12-07 21:39:28 +0000164 defined(CONFIG_SPD823TS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000165
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200166 memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000167#endif
168
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200169#if defined(CONFIG_SYS_OR0_REMAP)
170 memctl->memc_or0 = CONFIG_SYS_OR0_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000171#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200172#if defined(CONFIG_SYS_OR1_REMAP)
173 memctl->memc_or1 = CONFIG_SYS_OR1_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000174#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200175#if defined(CONFIG_SYS_OR5_REMAP)
176 memctl->memc_or5 = CONFIG_SYS_OR5_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000177#endif
178
179 /* now restrict to preliminary range */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200180 memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
181 memctl->memc_or0 = CONFIG_SYS_OR0_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000182
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200183#if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
184 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
185 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000186#endif
187
188#if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
189 memctl->memc_br0 = 0;
190#endif
191
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192#if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
193 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
194 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000195#endif
196
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197#if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
198 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
199 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000200#endif
201
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202#if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
203 memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM;
204 memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000205#endif
206
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200207#if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
208 memctl->memc_or5 = CONFIG_SYS_OR5_PRELIM;
209 memctl->memc_br5 = CONFIG_SYS_BR5_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000210#endif
211
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200212#if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
213 memctl->memc_or6 = CONFIG_SYS_OR6_PRELIM;
214 memctl->memc_br6 = CONFIG_SYS_BR6_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000215#endif
216
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200217#if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
218 memctl->memc_or7 = CONFIG_SYS_OR7_PRELIM;
219 memctl->memc_br7 = CONFIG_SYS_BR7_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000220#endif
221
222#endif /* ! CONFIG_MBX */
223
224 /*
225 * Reset CPM
226 */
227 immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
228 do { /* Spin until command processed */
229 __asm__ ("eieio");
230 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
231
232#ifdef CONFIG_MBX
233 /*
234 * on the MBX, things are a little bit different:
235 * - we need to read the VPD to get board information
236 * - the plprcr is set up dynamically
237 * - the memory controller is set up dynamically
238 */
239 mbx_init ();
240#endif /* CONFIG_MBX */
241
242#ifdef CONFIG_RPXCLASSIC
243 rpxclassic_init ();
244#endif
245
Jean-Christophe PLAGNIOL-VILLARD9314cee2008-09-10 22:47:59 +0200246#if defined(CONFIG_RPXLITE) && defined(CONFIG_ENV_IS_IN_NVRAM)
wdenke63c8ee2004-06-09 21:04:48 +0000247 rpxlite_init ();
248#endif
249
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200250#ifdef CONFIG_SYS_RCCR /* must be done before cpm_load_patch() */
wdenk4a9cbbe2002-08-27 09:48:53 +0000251 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200252 immr->im_cpm.cp_rccr = CONFIG_SYS_RCCR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000253#endif
254
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200255#if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
256 defined(CONFIG_SYS_SMC_UCODE_PATCH)
wdenk4a9cbbe2002-08-27 09:48:53 +0000257 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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200266#if defined(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200271#ifdef CONFIG_SYS_RTCSC
wdenk4a9cbbe2002-08-27 09:48:53 +0000272 /* Unlock RTSC register */
273 immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
274 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200275 immr->im_sit.sit_rtcsc = CONFIG_SYS_RTCSC;
wdenk4a9cbbe2002-08-27 09:48:53 +0000276#endif
277
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200278#ifdef CONFIG_SYS_RMDS
wdenk4a9cbbe2002-08-27 09:48:53 +0000279 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200280 immr->im_cpm.cp_rmds = CONFIG_SYS_RMDS;
wdenk4a9cbbe2002-08-27 09:48:53 +0000281#endif
282 return (0);
283}