blob: 640026be5ac5d3c7aeec413de63f2a6ca87c4f9c [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +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 <mpc8260.h>
26#include <asm/cpm_8260.h>
27#include <ioports.h>
28
Wolfgang Denkd87080b2006-03-31 18:32:53 +020029DECLARE_GLOBAL_DATA_PTR;
30
wdenkc6097192002-11-03 00:24:07 +000031static void config_8260_ioports (volatile immap_t * immr)
32{
33 int portnum;
34
35 for (portnum = 0; portnum < 4; portnum++) {
36 uint pmsk = 0,
37 ppar = 0,
38 psor = 0,
39 pdir = 0,
40 podr = 0,
41 pdat = 0;
42 iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
43 iop_conf_t *eiopc = iopc + 32;
44 uint msk = 1;
45
46 /*
47 * NOTE:
48 * index 0 refers to pin 31,
49 * index 31 refers to pin 0
50 */
51 while (iopc < eiopc) {
52 if (iopc->conf) {
53 pmsk |= msk;
54 if (iopc->ppar)
55 ppar |= msk;
56 if (iopc->psor)
57 psor |= msk;
58 if (iopc->pdir)
59 pdir |= msk;
60 if (iopc->podr)
61 podr |= msk;
62 if (iopc->pdat)
63 pdat |= msk;
64 }
65
66 msk <<= 1;
67 iopc++;
68 }
69
70 if (pmsk != 0) {
71 volatile ioport_t *iop = ioport_addr (immr, portnum);
72 uint tpmsk = ~pmsk;
73
74 /*
wdenk8bde7f72003-06-27 21:31:46 +000075 * the (somewhat confused) paragraph at the
76 * bottom of page 35-5 warns that there might
77 * be "unknown behaviour" when programming
78 * PSORx and PDIRx, if PPARx = 1, so I
79 * decided this meant I had to disable the
80 * dedicated function first, and enable it
81 * last.
wdenkc6097192002-11-03 00:24:07 +000082 */
83 iop->ppar &= tpmsk;
84 iop->psor = (iop->psor & tpmsk) | psor;
wdenk6dd652f2003-06-19 23:40:20 +000085 iop->podr = (iop->podr & tpmsk) | podr;
wdenkc6097192002-11-03 00:24:07 +000086 iop->pdat = (iop->pdat & tpmsk) | pdat;
87 iop->pdir = (iop->pdir & tpmsk) | pdir;
wdenkc6097192002-11-03 00:24:07 +000088 iop->ppar |= ppar;
89 }
90 }
91}
92
93/*
94 * Breath some life into the CPU...
95 *
96 * Set up the memory map,
97 * initialize a bunch of registers,
98 * initialize the UPM's
99 */
100void cpu_init_f (volatile immap_t * immr)
101{
wdenk4b248f32004-03-14 16:51:43 +0000102#if !defined(CONFIG_COGENT) /* done in start.S for the cogent */
103 uint sccr;
104#endif
wdenkc6097192002-11-03 00:24:07 +0000105 volatile memctl8260_t *memctl = &immr->im_memctl;
106 extern void m8260_cpm_reset (void);
107
108 /* Pointer is writable since we allocated a register for it */
109 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
110
111 /* Clear initial global data */
112 memset ((void *) gd, 0, sizeof (gd_t));
113
114 /* RSR - Reset Status Register - clear all status (5-4) */
115 gd->reset_status = immr->im_clkrst.car_rsr;
116 immr->im_clkrst.car_rsr = RSR_ALLBITS;
117
118 /* RMR - Reset Mode Register - contains checkstop reset enable (5-5) */
119 immr->im_clkrst.car_rmr = CFG_RMR;
120
121 /* BCR - Bus Configuration Register (4-25) */
122 immr->im_siu_conf.sc_bcr = CFG_BCR;
123
124 /* SIUMCR - contains debug pin configuration (4-31) */
125 immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
126
127 config_8260_ioports (immr);
128
129 /* initialize time counter status and control register (4-40) */
130 immr->im_sit.sit_tmcntsc = CFG_TMCNTSC;
131
132 /* initialize the PIT (4-42) */
133 immr->im_sit.sit_piscr = CFG_PISCR;
134
135#if !defined(CONFIG_COGENT) /* done in start.S for the cogent */
136 /* System clock control register (9-8) */
wdenk4b248f32004-03-14 16:51:43 +0000137 sccr = immr->im_clkrst.car_sccr &
138 (SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK);
139 immr->im_clkrst.car_sccr = sccr |
140 (CFG_SCCR & ~(SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK) );
wdenkc6097192002-11-03 00:24:07 +0000141#endif /* !CONFIG_COGENT */
142
143 /*
144 * Memory Controller:
145 */
146
147 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
148 * addresses - these have to be modified later when FLASH size
149 * has been determined
150 */
151
152#if defined(CFG_OR0_REMAP)
153 memctl->memc_or0 = CFG_OR0_REMAP;
154#endif
155#if defined(CFG_OR1_REMAP)
156 memctl->memc_or1 = CFG_OR1_REMAP;
157#endif
158
159 /* now restrict to preliminary range */
160 memctl->memc_br0 = CFG_BR0_PRELIM;
161 memctl->memc_or0 = CFG_OR0_PRELIM;
162
163#if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
164 memctl->memc_or1 = CFG_OR1_PRELIM;
165 memctl->memc_br1 = CFG_BR1_PRELIM;
166#endif
167
168#if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
169 memctl->memc_or2 = CFG_OR2_PRELIM;
170 memctl->memc_br2 = CFG_BR2_PRELIM;
171#endif
172
173#if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
174 memctl->memc_or3 = CFG_OR3_PRELIM;
175 memctl->memc_br3 = CFG_BR3_PRELIM;
176#endif
177
178#if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
179 memctl->memc_or4 = CFG_OR4_PRELIM;
180 memctl->memc_br4 = CFG_BR4_PRELIM;
181#endif
182
183#if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
184 memctl->memc_or5 = CFG_OR5_PRELIM;
185 memctl->memc_br5 = CFG_BR5_PRELIM;
186#endif
187
188#if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
189 memctl->memc_or6 = CFG_OR6_PRELIM;
190 memctl->memc_br6 = CFG_BR6_PRELIM;
191#endif
192
193#if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
194 memctl->memc_or7 = CFG_OR7_PRELIM;
195 memctl->memc_br7 = CFG_BR7_PRELIM;
196#endif
197
198#if defined(CFG_BR8_PRELIM) && defined(CFG_OR8_PRELIM)
199 memctl->memc_or8 = CFG_OR8_PRELIM;
200 memctl->memc_br8 = CFG_BR8_PRELIM;
201#endif
202
203#if defined(CFG_BR9_PRELIM) && defined(CFG_OR9_PRELIM)
204 memctl->memc_or9 = CFG_OR9_PRELIM;
205 memctl->memc_br9 = CFG_BR9_PRELIM;
206#endif
207
208#if defined(CFG_BR10_PRELIM) && defined(CFG_OR10_PRELIM)
209 memctl->memc_or10 = CFG_OR10_PRELIM;
210 memctl->memc_br10 = CFG_BR10_PRELIM;
211#endif
212
213#if defined(CFG_BR11_PRELIM) && defined(CFG_OR11_PRELIM)
214 memctl->memc_or11 = CFG_OR11_PRELIM;
215 memctl->memc_br11 = CFG_BR11_PRELIM;
216#endif
217
218 m8260_cpm_reset ();
219}
220
221/*
222 * initialize higher level parts of CPU like time base and timers
223 */
224int cpu_init_r (void)
225{
wdenkc6097192002-11-03 00:24:07 +0000226 volatile immap_t *immr = (immap_t *) gd->bd->bi_immr_base;
227
228 immr->im_cpm.cp_rccr = CFG_RCCR;
229
230 return (0);
231}
232
233/*
234 * print out the reason for the reset
235 */
236int prt_8260_rsr (void)
237{
wdenkc6097192002-11-03 00:24:07 +0000238 static struct {
239 ulong mask;
240 char *desc;
241 } bits[] = {
242 {
243 RSR_JTRS, "JTAG"}, {
244 RSR_CSRS, "Check Stop"}, {
245 RSR_SWRS, "Software Watchdog"}, {
246 RSR_BMRS, "Bus Monitor"}, {
247 RSR_ESRS, "External Soft"}, {
248 RSR_EHRS, "External Hard"}
249 };
250 static int n = sizeof bits / sizeof bits[0];
251 ulong rsr = gd->reset_status;
252 int i;
253 char *sep;
254
wdenk4532cb62003-04-27 22:52:51 +0000255 puts (CPU_ID_STR " Reset Status:");
wdenkc6097192002-11-03 00:24:07 +0000256
257 sep = " ";
258 for (i = 0; i < n; i++)
259 if (rsr & bits[i].mask) {
260 printf ("%s%s", sep, bits[i].desc);
261 sep = ", ";
262 }
263
264 puts ("\n\n");
265 return (0);
266}