Merge with git://www.denx.de/git/u-boot.git
[platform/kernel/u-boot.git] / cpu / mpc83xx / cpu_init.c
1 /*
2  * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <mpc83xx.h>
25 #include <ioports.h>
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 #ifdef CONFIG_QE
30 extern qe_iop_conf_t qe_iop_conf_tab[];
31 extern void qe_config_iopin(u8 port, u8 pin, int dir,
32                          int open_drain, int assign);
33 extern void qe_init(uint qe_base);
34 extern void qe_reset(void);
35
36 static void config_qe_ioports(void)
37 {
38         u8      port, pin;
39         int     dir, open_drain, assign;
40         int     i;
41
42         for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
43                 port            = qe_iop_conf_tab[i].port;
44                 pin             = qe_iop_conf_tab[i].pin;
45                 dir             = qe_iop_conf_tab[i].dir;
46                 open_drain      = qe_iop_conf_tab[i].open_drain;
47                 assign          = qe_iop_conf_tab[i].assign;
48                 qe_config_iopin(port, pin, dir, open_drain, assign);
49         }
50 }
51 #endif
52
53 /*
54  * Breathe some life into the CPU...
55  *
56  * Set up the memory map,
57  * initialize a bunch of registers,
58  * initialize the UPM's
59  */
60 void cpu_init_f (volatile immap_t * im)
61 {
62         /* Pointer is writable since we allocated a register for it */
63         gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
64
65         /* Clear initial global data */
66         memset ((void *) gd, 0, sizeof (gd_t));
67
68         /* system performance tweaking */
69
70 #ifdef CFG_ACR_PIPE_DEP
71         /* Arbiter pipeline depth */
72         im->arbiter.acr = (im->arbiter.acr & ~ACR_PIPE_DEP) |
73                           (CFG_ACR_PIPE_DEP << ACR_PIPE_DEP_SHIFT);
74 #endif
75
76 #ifdef CFG_SPCR_TSEC1EP
77         /* TSEC1 Emergency priority */
78         im->sysconf.spcr = (im->sysconf.spcr & ~SPCR_TSEC1EP) | (CFG_SPCR_TSEC1EP << SPCR_TSEC1EP_SHIFT);
79 #endif
80
81 #ifdef CFG_SPCR_TSEC2EP
82         /* TSEC2 Emergency priority */
83         im->sysconf.spcr = (im->sysconf.spcr & ~SPCR_TSEC2EP) | (CFG_SPCR_TSEC2EP << SPCR_TSEC2EP_SHIFT);
84 #endif
85
86 #ifdef CFG_SCCR_TSEC1CM
87         /* TSEC1 clock mode */
88         im->clk.sccr = (im->clk.sccr & ~SCCR_TSEC1CM) | (CFG_SCCR_TSEC1CM << SCCR_TSEC1CM_SHIFT);
89 #endif
90
91 #ifdef CFG_SCCR_TSEC2CM
92         /* TSEC2 & I2C1 clock mode */
93         im->clk.sccr = (im->clk.sccr & ~SCCR_TSEC2CM) | (CFG_SCCR_TSEC2CM << SCCR_TSEC2CM_SHIFT);
94 #endif
95
96 #ifdef CFG_SCCR_TSEC1ON
97         /* TSEC1 clock switch */
98         im->clk.sccr = (im->clk.sccr & ~SCCR_TSEC1ON) | (CFG_SCCR_TSEC1ON << SCCR_TSEC1ON_SHIFT);
99 #endif
100
101 #ifdef CFG_SCCR_TSEC2ON
102         /* TSEC2 clock switch */
103         im->clk.sccr = (im->clk.sccr & ~SCCR_TSEC2ON) | (CFG_SCCR_TSEC2ON << SCCR_TSEC2ON_SHIFT);
104 #endif
105
106 #ifdef CFG_SCCR_USBMPHCM
107         /* USB MPH clock mode */
108         im->clk.sccr = (im->clk.sccr & ~SCCR_USBMPHCM) | (CFG_SCCR_USBMPHCM << SCCR_USBMPHCM_SHIFT);
109 #endif
110
111 #ifdef CFG_SCCR_PCICM
112         /* PCI & DMA clock mode */
113         im->clk.sccr = (im->clk.sccr & ~SCCR_PCICM) | (CFG_SCCR_PCICM << SCCR_PCICM_SHIFT);
114 #endif
115
116 #ifdef CFG_SCCR_USBDRCM
117         /* USB DR clock mode */
118         im->clk.sccr = (im->clk.sccr & ~SCCR_USBDRCM) | (CFG_SCCR_USBDRCM << SCCR_USBDRCM_SHIFT);
119 #endif
120
121 #ifdef CFG_SCCR_ENCCM
122         /* Encryption clock mode */
123         im->clk.sccr = (im->clk.sccr & ~SCCR_ENCCM) | (CFG_SCCR_ENCCM << SCCR_PCICM_SHIFT);
124 #endif
125
126 #ifdef CFG_ACR_RPTCNT
127         /* Arbiter repeat count */
128         im->arbiter.acr = ((im->arbiter.acr & ~(ACR_RPTCNT)) | (CFG_ACR_RPTCNT << ACR_RPTCNT_SHIFT));
129 #endif
130
131         /* RSR - Reset Status Register - clear all status (4.6.1.3) */
132         gd->reset_status = im->reset.rsr;
133         im->reset.rsr = ~(RSR_RES);
134
135         /*
136          * RMR - Reset Mode Register
137          * contains checkstop reset enable (4.6.1.4)
138          */
139         im->reset.rmr = (RMR_CSRE & (1<<RMR_CSRE_SHIFT));
140
141         /* LCRR - Clock Ratio Register (10.3.1.16) */
142         im->lbus.lcrr = CFG_LCRR;
143
144         /* Enable Time Base & Decrimenter ( so we will have udelay() )*/
145         im->sysconf.spcr |= SPCR_TBEN;
146
147         /* System General Purpose Register */
148 #ifdef CFG_SICRH
149         im->sysconf.sicrh = CFG_SICRH;
150 #endif
151 #ifdef CFG_SICRL
152         im->sysconf.sicrl = CFG_SICRL;
153 #endif
154         /* DDR control driver register */
155 #ifdef CFG_DDRCDR
156         im->sysconf.ddrcdr = CFG_DDRCDR;
157 #endif
158
159 #ifdef CONFIG_QE
160         /* Config QE ioports */
161         config_qe_ioports();
162 #endif
163
164         /*
165          * Memory Controller:
166          */
167
168         /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
169          * addresses - these have to be modified later when FLASH size
170          * has been determined
171          */
172
173 #if defined(CFG_BR0_PRELIM)  \
174         && defined(CFG_OR0_PRELIM) \
175         && defined(CFG_LBLAWBAR0_PRELIM) \
176         && defined(CFG_LBLAWAR0_PRELIM)
177         im->lbus.bank[0].br = CFG_BR0_PRELIM;
178         im->lbus.bank[0].or = CFG_OR0_PRELIM;
179         im->sysconf.lblaw[0].bar = CFG_LBLAWBAR0_PRELIM;
180         im->sysconf.lblaw[0].ar = CFG_LBLAWAR0_PRELIM;
181 #else
182 #error  CFG_BR0_PRELIM, CFG_OR0_PRELIM, CFG_LBLAWBAR0_PRELIM & CFG_LBLAWAR0_PRELIM must be defined
183 #endif
184
185 #if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
186         im->lbus.bank[1].br = CFG_BR1_PRELIM;
187         im->lbus.bank[1].or = CFG_OR1_PRELIM;
188 #endif
189 #if defined(CFG_LBLAWBAR1_PRELIM) && defined(CFG_LBLAWAR1_PRELIM)
190         im->sysconf.lblaw[1].bar = CFG_LBLAWBAR1_PRELIM;
191         im->sysconf.lblaw[1].ar = CFG_LBLAWAR1_PRELIM;
192 #endif
193 #if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
194         im->lbus.bank[2].br = CFG_BR2_PRELIM;
195         im->lbus.bank[2].or = CFG_OR2_PRELIM;
196 #endif
197 #if defined(CFG_LBLAWBAR2_PRELIM) && defined(CFG_LBLAWAR2_PRELIM)
198         im->sysconf.lblaw[2].bar = CFG_LBLAWBAR2_PRELIM;
199         im->sysconf.lblaw[2].ar = CFG_LBLAWAR2_PRELIM;
200 #endif
201 #if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
202         im->lbus.bank[3].br = CFG_BR3_PRELIM;
203         im->lbus.bank[3].or = CFG_OR3_PRELIM;
204 #endif
205 #if defined(CFG_LBLAWBAR3_PRELIM) && defined(CFG_LBLAWAR3_PRELIM)
206         im->sysconf.lblaw[3].bar = CFG_LBLAWBAR3_PRELIM;
207         im->sysconf.lblaw[3].ar = CFG_LBLAWAR3_PRELIM;
208 #endif
209 #if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
210         im->lbus.bank[4].br = CFG_BR4_PRELIM;
211         im->lbus.bank[4].or = CFG_OR4_PRELIM;
212 #endif
213 #if defined(CFG_LBLAWBAR4_PRELIM) && defined(CFG_LBLAWAR4_PRELIM)
214         im->sysconf.lblaw[4].bar = CFG_LBLAWBAR4_PRELIM;
215         im->sysconf.lblaw[4].ar = CFG_LBLAWAR4_PRELIM;
216 #endif
217 #if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
218         im->lbus.bank[5].br = CFG_BR5_PRELIM;
219         im->lbus.bank[5].or = CFG_OR5_PRELIM;
220 #endif
221 #if defined(CFG_LBLAWBAR5_PRELIM) && defined(CFG_LBLAWAR5_PRELIM)
222         im->sysconf.lblaw[5].bar = CFG_LBLAWBAR5_PRELIM;
223         im->sysconf.lblaw[5].ar = CFG_LBLAWAR5_PRELIM;
224 #endif
225 #if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
226         im->lbus.bank[6].br = CFG_BR6_PRELIM;
227         im->lbus.bank[6].or = CFG_OR6_PRELIM;
228 #endif
229 #if defined(CFG_LBLAWBAR6_PRELIM) && defined(CFG_LBLAWAR6_PRELIM)
230         im->sysconf.lblaw[6].bar = CFG_LBLAWBAR6_PRELIM;
231         im->sysconf.lblaw[6].ar = CFG_LBLAWAR6_PRELIM;
232 #endif
233 #if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
234         im->lbus.bank[7].br = CFG_BR7_PRELIM;
235         im->lbus.bank[7].or = CFG_OR7_PRELIM;
236 #endif
237 #if defined(CFG_LBLAWBAR7_PRELIM) && defined(CFG_LBLAWAR7_PRELIM)
238         im->sysconf.lblaw[7].bar = CFG_LBLAWBAR7_PRELIM;
239         im->sysconf.lblaw[7].ar = CFG_LBLAWAR7_PRELIM;
240 #endif
241 #ifdef CFG_GPIO1_PRELIM
242         im->gpio[0].dir = CFG_GPIO1_DIR;
243         im->gpio[0].dat = CFG_GPIO1_DAT;
244 #endif
245 #ifdef CFG_GPIO2_PRELIM
246         im->gpio[1].dir = CFG_GPIO2_DIR;
247         im->gpio[1].dat = CFG_GPIO2_DAT;
248 #endif
249 }
250
251 int cpu_init_r (void)
252 {
253 #ifdef CONFIG_QE
254         uint qe_base = CFG_IMMR + 0x00100000; /* QE immr base */
255         qe_init(qe_base);
256         qe_reset();
257 #endif
258         return 0;
259 }
260
261 /*
262  * Figure out the cause of the reset
263  */
264 int prt_83xx_rsr(void)
265 {
266         static struct {
267                 ulong mask;
268                 char *desc;
269         } bits[] = {
270                 {
271                 RSR_SWSR, "Software Soft"}, {
272                 RSR_SWHR, "Software Hard"}, {
273                 RSR_JSRS, "JTAG Soft"}, {
274                 RSR_CSHR, "Check Stop"}, {
275                 RSR_SWRS, "Software Watchdog"}, {
276                 RSR_BMRS, "Bus Monitor"}, {
277                 RSR_SRS,  "External/Internal Soft"}, {
278                 RSR_HRS,  "External/Internal Hard"}
279         };
280         static int n = sizeof bits / sizeof bits[0];
281         ulong rsr = gd->reset_status;
282         int i;
283         char *sep;
284
285         puts("Reset Status:");
286
287         sep = " ";
288         for (i = 0; i < n; i++)
289                 if (rsr & bits[i].mask) {
290                         printf("%s%s", sep, bits[i].desc);
291                         sep = ", ";
292                 }
293         puts("\n\n");
294         return 0;
295 }