]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc8xx/cpu_init.c
* Fix problems caused by Robert Schwebel's cramfs patch
[karo-tx-uboot.git] / cpu / mpc8xx / cpu_init.c
1 /*
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)
31 void 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  */
41 void cpu_init_f (volatile immap_t * immr)
42 {
43 #ifndef CONFIG_MBX
44         volatile memctl8xx_t *memctl = &immr->im_memctl;
45         ulong mfmask;
46 #endif
47         ulong reg;
48
49         /* SYPCR - contains watchdog control (11-9) */
50
51         immr->im_siu_conf.sc_sypcr = CFG_SYPCR;
52
53 #if defined(CONFIG_WATCHDOG)
54         reset_8xx_watchdog (immr);
55 #endif /* CONFIG_WATCHDOG */
56
57         /* SIUMCR - contains debug pin configuration (11-6) */
58 #ifndef CONFIG_SVM_SC8xx
59         immr->im_siu_conf.sc_siumcr |= CFG_SIUMCR;
60 #else
61         immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
62 #endif
63         /* initialize timebase status and control register (11-26) */
64         /* unlock TBSCRK */
65
66         immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
67         immr->im_sit.sit_tbscr = CFG_TBSCR;
68
69         /* initialize the PIT (11-31) */
70
71         immr->im_sitk.sitk_piscrk = KAPWR_KEY;
72         immr->im_sit.sit_piscr = CFG_PISCR;
73
74         /* System integration timers. Don't change EBDF! (15-27) */
75
76         immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
77         reg = immr->im_clkrst.car_sccr;
78         reg &= SCCR_MASK;
79         reg |= CFG_SCCR;
80         immr->im_clkrst.car_sccr = reg;
81
82         /* PLL (CPU clock) settings (15-30) */
83
84         immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
85
86 #ifndef CONFIG_MBX              /* MBX board does things different */
87
88         /* If CFG_PLPRCR (set in the various *_config.h files) tries to
89          * set the MF field, then just copy CFG_PLPRCR over car_plprcr,
90          * otherwise OR in CFG_PLPRCR so we do not change the current MF
91          * field value.
92          *
93          * For newer (starting MPC866) chips PLPRCR layout is different.
94          */
95         if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
96            mfmask = PLPRCR_MFACT_MSK;
97         else
98            mfmask = PLPRCR_MF_MSK;
99
100         if ((CFG_PLPRCR & mfmask) != 0)
101            reg = CFG_PLPRCR;                    /* reset control bits   */
102         else {
103            reg = immr->im_clkrst.car_plprcr;
104            reg &= mfmask;                       /* isolate MF-related fields */
105            reg |= CFG_PLPRCR;                   /* reset control bits   */
106         }
107         immr->im_clkrst.car_plprcr = reg;
108
109         /*
110          * Memory Controller:
111          */
112
113         /* perform BR0 reset that MPC850 Rev. A can't guarantee */
114         reg = memctl->memc_br0;
115         reg &= BR_PS_MSK;       /* Clear everything except Port Size bits */
116         reg |= BR_V;            /* then add just the "Bank Valid" bit     */
117         memctl->memc_br0 = reg;
118
119         /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
120          * preliminary addresses - these have to be modified later
121          * when FLASH size has been determined
122          *
123          * Depending on the size of the memory region defined by
124          * CFG_OR0_REMAP some boards (wide address mask) allow to map the
125          * CFG_MONITOR_BASE, while others (narrower address mask) can't
126          * map CFG_MONITOR_BASE.
127          *
128          * For example, for CONFIG_IVMS8, the CFG_MONITOR_BASE is
129          * 0xff000000, but CFG_OR0_REMAP's address mask is 0xfff80000.
130          *
131          * If BR0 wasn't loaded with address base 0xff000000, then BR0's
132          * base address remains as 0x00000000. However, the address mask
133          * have been narrowed to 512Kb, so CFG_MONITOR_BASE wasn't mapped
134          * into the Bank0.
135          *
136          * This is why CONFIG_IVMS8 and similar boards must load BR0 with
137          * CFG_BR0_PRELIM in advance.
138          *
139          * [Thanks to Michael Liao for this explanation.
140          *  I owe him a free beer. - wd]
141          */
142
143 #if defined(CONFIG_ADDERII)     || \
144     defined(CONFIG_GTH)         || \
145     defined(CONFIG_HERMES)      || \
146     defined(CONFIG_ICU862)      || \
147     defined(CONFIG_IP860)       || \
148     defined(CONFIG_IVML24)      || \
149     defined(CONFIG_IVMS8)       || \
150     defined(CONFIG_LWMON)       || \
151     defined(CONFIG_MHPC)        || \
152     defined(CONFIG_PCU_E)       || \
153     defined(CONFIG_R360MPI)     || \
154     defined(CONFIG_RPXCLASSIC)  || \
155     defined(CONFIG_RPXLITE)     || \
156     defined(CONFIG_SPD823TS)
157
158         memctl->memc_br0 = CFG_BR0_PRELIM;
159 #endif
160
161 #if defined(CFG_OR0_REMAP)
162         memctl->memc_or0 = CFG_OR0_REMAP;
163 #endif
164 #if defined(CFG_OR1_REMAP)
165         memctl->memc_or1 = CFG_OR1_REMAP;
166 #endif
167 #if defined(CFG_OR5_REMAP)
168         memctl->memc_or5 = CFG_OR5_REMAP;
169 #endif
170
171         /* now restrict to preliminary range */
172         memctl->memc_br0 = CFG_BR0_PRELIM;
173         memctl->memc_or0 = CFG_OR0_PRELIM;
174
175 #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
176         memctl->memc_or1 = CFG_OR1_PRELIM;
177         memctl->memc_br1 = CFG_BR1_PRELIM;
178 #endif
179
180 #if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
181         memctl->memc_br0 = 0;
182 #endif
183
184 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
185         memctl->memc_or2 = CFG_OR2_PRELIM;
186         memctl->memc_br2 = CFG_BR2_PRELIM;
187 #endif
188
189 #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
190         memctl->memc_or3 = CFG_OR3_PRELIM;
191         memctl->memc_br3 = CFG_BR3_PRELIM;
192 #endif
193
194 #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
195         memctl->memc_or4 = CFG_OR4_PRELIM;
196         memctl->memc_br4 = CFG_BR4_PRELIM;
197 #endif
198
199 #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
200         memctl->memc_or5 = CFG_OR5_PRELIM;
201         memctl->memc_br5 = CFG_BR5_PRELIM;
202 #endif
203
204 #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
205         memctl->memc_or6 = CFG_OR6_PRELIM;
206         memctl->memc_br6 = CFG_BR6_PRELIM;
207 #endif
208
209 #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
210         memctl->memc_or7 = CFG_OR7_PRELIM;
211         memctl->memc_br7 = CFG_BR7_PRELIM;
212 #endif
213
214 #endif /* ! CONFIG_MBX */
215
216         /*
217          * Reset CPM
218          */
219         immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
220         do {                    /* Spin until command processed     */
221                 __asm__ ("eieio");
222         } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
223
224 #ifdef CONFIG_MBX
225         /*
226          * on the MBX, things are a little bit different:
227          * - we need to read the VPD to get board information
228          * - the plprcr is set up dynamically
229          * - the memory controller is set up dynamically
230          */
231         mbx_init ();
232 #endif /* CONFIG_MBX */
233
234 #ifdef CONFIG_RPXCLASSIC
235         rpxclassic_init ();
236 #endif
237
238 #ifdef CFG_RCCR                 /* must be done before cpm_load_patch() */
239         /* write config value */
240         immr->im_cpm.cp_rccr = CFG_RCCR;
241 #endif
242
243 #if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
244         cpm_load_patch (immr);  /* load mpc8xx  microcode patch */
245 #endif
246 }
247
248 /*
249  * initialize higher level parts of CPU like timers
250  */
251 int cpu_init_r (void)
252 {
253 #if defined(CFG_RTCSC) || defined(CFG_RMDS)
254         DECLARE_GLOBAL_DATA_PTR;
255
256         bd_t *bd = gd->bd;
257         volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
258 #endif
259
260 #ifdef CFG_RTCSC
261         /* Unlock RTSC register */
262         immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
263         /* write config value */
264         immr->im_sit.sit_rtcsc = CFG_RTCSC;
265 #endif
266
267 #ifdef CFG_RMDS
268         /* write config value */
269         immr->im_cpm.cp_rmds = CFG_RMDS;
270 #endif
271         return (0);
272 }