blob: 9c3102dc69f2e93286ce102ff0108adbcb01f205 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk4a9cbbe2002-08-27 09:48:53 +00006 */
7
8#include <common.h>
9#include <watchdog.h>
10
11#include <mpc8xx.h>
12#include <commproc.h>
13
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020014#if defined(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_RMDS)
Wolfgang Denk6405a152006-03-31 18:32:53 +020015DECLARE_GLOBAL_DATA_PTR;
16#endif
17
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020018#if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
19 defined(CONFIG_SYS_SMC_UCODE_PATCH)
wdenk4a9cbbe2002-08-27 09:48:53 +000020void cpm_load_patch (volatile immap_t * immr);
21#endif
22
23/*
24 * Breath some life into the CPU...
25 *
26 * Set up the memory map,
27 * initialize a bunch of registers,
28 * initialize the UPM's
29 */
30void cpu_init_f (volatile immap_t * immr)
31{
wdenk4a9cbbe2002-08-27 09:48:53 +000032 volatile memctl8xx_t *memctl = &immr->im_memctl;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033# ifdef CONFIG_SYS_PLPRCR
wdenkad276f22004-01-04 16:28:35 +000034 ulong mfmask;
wdenkb50cde52004-01-24 20:25:54 +000035# endif
wdenkef5fe752003-03-12 10:41:04 +000036 ulong reg;
wdenk4a9cbbe2002-08-27 09:48:53 +000037
38 /* SYPCR - contains watchdog control (11-9) */
39
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 immr->im_siu_conf.sc_sypcr = CONFIG_SYS_SYPCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000041
42#if defined(CONFIG_WATCHDOG)
43 reset_8xx_watchdog (immr);
44#endif /* CONFIG_WATCHDOG */
45
46 /* SIUMCR - contains debug pin configuration (11-6) */
wdenkc8434db2003-03-26 06:55:25 +000047#ifndef CONFIG_SVM_SC8xx
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048 immr->im_siu_conf.sc_siumcr |= CONFIG_SYS_SIUMCR;
wdenkc8434db2003-03-26 06:55:25 +000049#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050 immr->im_siu_conf.sc_siumcr = CONFIG_SYS_SIUMCR;
wdenkc8434db2003-03-26 06:55:25 +000051#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000052 /* initialize timebase status and control register (11-26) */
53 /* unlock TBSCRK */
54
55 immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020056 immr->im_sit.sit_tbscr = CONFIG_SYS_TBSCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000057
58 /* initialize the PIT (11-31) */
59
60 immr->im_sitk.sitk_piscrk = KAPWR_KEY;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061 immr->im_sit.sit_piscr = CONFIG_SYS_PISCR;
wdenk4a9cbbe2002-08-27 09:48:53 +000062
wdenk1fe2c702003-03-06 21:55:29 +000063 /* System integration timers. Don't change EBDF! (15-27) */
64
65 immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
66 reg = immr->im_clkrst.car_sccr;
67 reg &= SCCR_MASK;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068 reg |= CONFIG_SYS_SCCR;
wdenk1fe2c702003-03-06 21:55:29 +000069 immr->im_clkrst.car_sccr = reg;
70
wdenk4a9cbbe2002-08-27 09:48:53 +000071 /* PLL (CPU clock) settings (15-30) */
72
73 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
74
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075 /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
76 * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
77 * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
wdenk4a9cbbe2002-08-27 09:48:53 +000078 * field value.
wdenkad276f22004-01-04 16:28:35 +000079 *
80 * For newer (starting MPC866) chips PLPRCR layout is different.
wdenk4a9cbbe2002-08-27 09:48:53 +000081 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082#ifdef CONFIG_SYS_PLPRCR
wdenkad276f22004-01-04 16:28:35 +000083 if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
84 mfmask = PLPRCR_MFACT_MSK;
85 else
86 mfmask = PLPRCR_MF_MSK;
87
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088 if ((CONFIG_SYS_PLPRCR & mfmask) != 0)
89 reg = CONFIG_SYS_PLPRCR; /* reset control bits */
wdenkad276f22004-01-04 16:28:35 +000090 else {
91 reg = immr->im_clkrst.car_plprcr;
92 reg &= mfmask; /* isolate MF-related fields */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 reg |= CONFIG_SYS_PLPRCR; /* reset control bits */
wdenkad276f22004-01-04 16:28:35 +000094 }
wdenk4a9cbbe2002-08-27 09:48:53 +000095 immr->im_clkrst.car_plprcr = reg;
wdenkb50cde52004-01-24 20:25:54 +000096#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000097
wdenk4a9cbbe2002-08-27 09:48:53 +000098 /*
99 * Memory Controller:
100 */
101
102 /* perform BR0 reset that MPC850 Rev. A can't guarantee */
103 reg = memctl->memc_br0;
104 reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
105 reg |= BR_V; /* then add just the "Bank Valid" bit */
106 memctl->memc_br0 = reg;
107
108 /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
109 * preliminary addresses - these have to be modified later
110 * when FLASH size has been determined
111 *
112 * Depending on the size of the memory region defined by
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200113 * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
114 * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
115 * map CONFIG_SYS_MONITOR_BASE.
wdenk4a9cbbe2002-08-27 09:48:53 +0000116 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117 * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
118 * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
wdenk4a9cbbe2002-08-27 09:48:53 +0000119 *
120 * If BR0 wasn't loaded with address base 0xff000000, then BR0's
121 * base address remains as 0x00000000. However, the address mask
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200122 * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
wdenk4a9cbbe2002-08-27 09:48:53 +0000123 * into the Bank0.
124 *
125 * This is why CONFIG_IVMS8 and similar boards must load BR0 with
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 * CONFIG_SYS_BR0_PRELIM in advance.
wdenk4a9cbbe2002-08-27 09:48:53 +0000127 *
128 * [Thanks to Michael Liao for this explanation.
129 * I owe him a free beer. - wd]
130 */
131
Wolfgang Denk30c3add2010-07-05 22:46:33 +0200132#if defined(CONFIG_HERMES) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000133 defined(CONFIG_ICU862) || \
134 defined(CONFIG_IP860) || \
135 defined(CONFIG_IVML24) || \
136 defined(CONFIG_IVMS8) || \
137 defined(CONFIG_LWMON) || \
138 defined(CONFIG_MHPC) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000139 defined(CONFIG_R360MPI) || \
wdenka09491a2004-04-08 22:31:29 +0000140 defined(CONFIG_RMU) || \
wdenk4a9cbbe2002-08-27 09:48:53 +0000141 defined(CONFIG_RPXLITE) || \
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200142 defined(CONFIG_SPC1920) || \
wdenk444f22b2003-12-07 21:39:28 +0000143 defined(CONFIG_SPD823TS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000144
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200145 memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000146#endif
147
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148#if defined(CONFIG_SYS_OR0_REMAP)
149 memctl->memc_or0 = CONFIG_SYS_OR0_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000150#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151#if defined(CONFIG_SYS_OR1_REMAP)
152 memctl->memc_or1 = CONFIG_SYS_OR1_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000153#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154#if defined(CONFIG_SYS_OR5_REMAP)
155 memctl->memc_or5 = CONFIG_SYS_OR5_REMAP;
wdenk4a9cbbe2002-08-27 09:48:53 +0000156#endif
157
158 /* now restrict to preliminary range */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200159 memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
160 memctl->memc_or0 = CONFIG_SYS_OR0_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000161
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162#if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
163 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
164 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000165#endif
166
167#if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
168 memctl->memc_br0 = 0;
169#endif
170
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200171#if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
172 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
173 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000174#endif
175
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176#if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
177 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
178 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000179#endif
180
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181#if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
182 memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM;
183 memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000184#endif
185
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200186#if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
187 memctl->memc_or5 = CONFIG_SYS_OR5_PRELIM;
188 memctl->memc_br5 = CONFIG_SYS_BR5_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000189#endif
190
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200191#if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
192 memctl->memc_or6 = CONFIG_SYS_OR6_PRELIM;
193 memctl->memc_br6 = CONFIG_SYS_BR6_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000194#endif
195
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196#if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
197 memctl->memc_or7 = CONFIG_SYS_OR7_PRELIM;
198 memctl->memc_br7 = CONFIG_SYS_BR7_PRELIM;
wdenk4a9cbbe2002-08-27 09:48:53 +0000199#endif
200
wdenk4a9cbbe2002-08-27 09:48:53 +0000201 /*
202 * Reset CPM
203 */
204 immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
205 do { /* Spin until command processed */
206 __asm__ ("eieio");
207 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
208
Jean-Christophe PLAGNIOL-VILLARDfdb79c32008-09-10 22:47:59 +0200209#if defined(CONFIG_RPXLITE) && defined(CONFIG_ENV_IS_IN_NVRAM)
wdenkec432742004-06-09 21:04:48 +0000210 rpxlite_init ();
211#endif
212
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213#ifdef CONFIG_SYS_RCCR /* must be done before cpm_load_patch() */
wdenk4a9cbbe2002-08-27 09:48:53 +0000214 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200215 immr->im_cpm.cp_rccr = CONFIG_SYS_RCCR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000216#endif
217
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200218#if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
219 defined(CONFIG_SYS_SMC_UCODE_PATCH)
wdenk4a9cbbe2002-08-27 09:48:53 +0000220 cpm_load_patch (immr); /* load mpc8xx microcode patch */
221#endif
222}
223
224/*
225 * initialize higher level parts of CPU like timers
226 */
227int cpu_init_r (void)
228{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200229#if defined(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_RMDS)
wdenk4a9cbbe2002-08-27 09:48:53 +0000230 bd_t *bd = gd->bd;
231 volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
232#endif
233
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200234#ifdef CONFIG_SYS_RTCSC
wdenk4a9cbbe2002-08-27 09:48:53 +0000235 /* Unlock RTSC register */
236 immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
237 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200238 immr->im_sit.sit_rtcsc = CONFIG_SYS_RTCSC;
wdenk4a9cbbe2002-08-27 09:48:53 +0000239#endif
240
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200241#ifdef CONFIG_SYS_RMDS
wdenk4a9cbbe2002-08-27 09:48:53 +0000242 /* write config value */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200243 immr->im_cpm.cp_rmds = CONFIG_SYS_RMDS;
wdenk4a9cbbe2002-08-27 09:48:53 +0000244#endif
245 return (0);
246}