blob: 9f4d36c1ab45d744b6a224c6e0a6e6af419a8fa7 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
2 * (C) Copyright 2003 Motorola Inc.
3 * Modified by Xianghua Xiao, X.Xiao@motorola.com
4 *
5 * (C) Copyright 2000
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <watchdog.h>
29#include <asm/processor.h>
30#include <ioports.h>
31#include <asm/io.h>
32
Wolfgang Denkd87080b2006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
Matthew McClintock40d5fa32006-06-28 10:43:36 -050035
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -050036#ifdef CONFIG_CPM2
wdenk42d1f032003-10-15 23:53:47 +000037static void config_8560_ioports (volatile immap_t * immr)
38{
39 int portnum;
40
41 for (portnum = 0; portnum < 4; portnum++) {
42 uint pmsk = 0,
43 ppar = 0,
44 psor = 0,
45 pdir = 0,
46 podr = 0,
47 pdat = 0;
48 iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
49 iop_conf_t *eiopc = iopc + 32;
50 uint msk = 1;
51
52 /*
53 * NOTE:
54 * index 0 refers to pin 31,
55 * index 31 refers to pin 0
56 */
57 while (iopc < eiopc) {
58 if (iopc->conf) {
59 pmsk |= msk;
60 if (iopc->ppar)
61 ppar |= msk;
62 if (iopc->psor)
63 psor |= msk;
64 if (iopc->pdir)
65 pdir |= msk;
66 if (iopc->podr)
67 podr |= msk;
68 if (iopc->pdat)
69 pdat |= msk;
70 }
71
72 msk <<= 1;
73 iopc++;
74 }
75
76 if (pmsk != 0) {
77 volatile ioport_t *iop = ioport_addr (immr, portnum);
78 uint tpmsk = ~pmsk;
79
80 /*
81 * the (somewhat confused) paragraph at the
82 * bottom of page 35-5 warns that there might
83 * be "unknown behaviour" when programming
84 * PSORx and PDIRx, if PPARx = 1, so I
85 * decided this meant I had to disable the
86 * dedicated function first, and enable it
87 * last.
88 */
89 iop->ppar &= tpmsk;
90 iop->psor = (iop->psor & tpmsk) | psor;
91 iop->podr = (iop->podr & tpmsk) | podr;
92 iop->pdat = (iop->pdat & tpmsk) | pdat;
93 iop->pdir = (iop->pdir & tpmsk) | pdir;
94 iop->ppar |= ppar;
95 }
96 }
97}
98#endif
99
100/*
101 * Breathe some life into the CPU...
102 *
103 * Set up the memory map
104 * initialize a bunch of registers
105 */
106
107void cpu_init_f (void)
108{
wdenk42d1f032003-10-15 23:53:47 +0000109 volatile immap_t *immap = (immap_t *)CFG_IMMR;
110 volatile ccsr_lbc_t *memctl = &immap->im_lbc;
111 extern void m8560_cpm_reset (void);
112
113 /* Pointer is writable since we allocated a register for it */
114 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
115
116 /* Clear initial global data */
117 memset ((void *) gd, 0, sizeof (gd_t));
118
119
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500120#ifdef CONFIG_CPM2
wdenk42d1f032003-10-15 23:53:47 +0000121 config_8560_ioports(immap);
122#endif
123
124 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
125 * addresses - these have to be modified later when FLASH size
126 * has been determined
127 */
128#if defined(CFG_OR0_REMAP)
129 memctl->or0 = CFG_OR0_REMAP;
130#endif
131#if defined(CFG_OR1_REMAP)
132 memctl->or1 = CFG_OR1_REMAP;
133#endif
134
135 /* now restrict to preliminary range */
136#if defined(CFG_BR0_PRELIM) && defined(CFG_OR0_PRELIM)
137 memctl->br0 = CFG_BR0_PRELIM;
138 memctl->or0 = CFG_OR0_PRELIM;
139#endif
140
141#if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
142 memctl->or1 = CFG_OR1_PRELIM;
143 memctl->br1 = CFG_BR1_PRELIM;
144#endif
145
146#if !defined(CONFIG_MPC85xx)
147#if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
148 memctl->or2 = CFG_OR2_PRELIM;
149 memctl->br2 = CFG_BR2_PRELIM;
150#endif
151#endif
152
153#if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
154 memctl->or3 = CFG_OR3_PRELIM;
155 memctl->br3 = CFG_BR3_PRELIM;
156#endif
157
158#if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
159 memctl->or4 = CFG_OR4_PRELIM;
160 memctl->br4 = CFG_BR4_PRELIM;
161#endif
162
163#if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
164 memctl->or5 = CFG_OR5_PRELIM;
165 memctl->br5 = CFG_BR5_PRELIM;
166#endif
167
168#if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
169 memctl->or6 = CFG_OR6_PRELIM;
170 memctl->br6 = CFG_BR6_PRELIM;
171#endif
172
173#if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
174 memctl->or7 = CFG_OR7_PRELIM;
175 memctl->br7 = CFG_BR7_PRELIM;
176#endif
177
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500178#if defined(CONFIG_CPM2)
wdenk42d1f032003-10-15 23:53:47 +0000179 m8560_cpm_reset();
180#endif
181}
182
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500183
wdenk42d1f032003-10-15 23:53:47 +0000184/*
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500185 * Initialize L2 as cache.
186 *
187 * The newer 8548, etc, parts have twice as much cache, but
188 * use the same bit-encoding as the older 8555, etc, parts.
189 *
190 * FIXME: Use PVR_VER(pvr) == 1 test here instead of SVR_VER()?
wdenk42d1f032003-10-15 23:53:47 +0000191 */
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500192
193int cpu_init_r(void)
wdenk42d1f032003-10-15 23:53:47 +0000194{
195#if defined(CONFIG_L2_CACHE)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500196 volatile immap_t *immap = (immap_t *)CFG_IMMR;
wdenk42d1f032003-10-15 23:53:47 +0000197 volatile ccsr_l2cache_t *l2cache = &immap->im_l2cache;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500198 volatile uint cache_ctl;
199 uint svr, ver;
200
201 svr = get_svr();
202 ver = SVR_VER(svr);
wdenk42d1f032003-10-15 23:53:47 +0000203
204 asm("msync;isync");
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500205 cache_ctl = l2cache->l2ctl;
206
207 switch (cache_ctl & 0x30000000) {
Jon Loeligerd65cfe82005-07-25 10:58:39 -0500208 case 0x20000000:
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500209 if (ver == SVR_8548 || ver == SVR_8548_E) {
210 printf ("L2 cache 512KB:");
211 } else {
212 printf ("L2 cache 256KB:");
213 }
Jon Loeligerd65cfe82005-07-25 10:58:39 -0500214 break;
215 case 0x00000000:
216 case 0x10000000:
217 case 0x30000000:
218 default:
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500219 printf ("L2 cache unknown size (0x%08x)\n", cache_ctl);
Jon Loeligerd65cfe82005-07-25 10:58:39 -0500220 return -1;
221 }
222
223 asm("msync;isync");
wdenk42d1f032003-10-15 23:53:47 +0000224 l2cache->l2ctl = 0x68000000; /* invalidate */
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500225 cache_ctl = l2cache->l2ctl;
wdenk42d1f032003-10-15 23:53:47 +0000226 asm("msync;isync");
227
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500228 l2cache->l2ctl = 0xa8000000; /* enable 256KB L2 cache */
229 cache_ctl = l2cache->l2ctl;
230 asm("msync;isync");
231
232 printf(" enabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000233#else
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500234 printf("L2 cache: disabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000235#endif
236
237 return 0;
238}