blob: 86b749dac9ae0533497cb91a80d9e5c69231e9ce [file] [log] [blame]
wdenk65faef92004-03-25 19:29:38 +00001/*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * Klaus Heydeck, Kieback & Peter GmbH & Co KG, heydeck@kieback-peter.de
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <mpc8xx.h>
27#include "../common/kup.h"
28#ifdef CONFIG_KUP4K_LOGO
29/* #include "s1d13706.h" */
30#endif
31
32#define KUP4X_USB
33
34
35typedef struct {
36 volatile unsigned char *VmemAddr;
37 volatile unsigned char *RegAddr;
38} FB_INFO_S1D13xxx;
39
40/* ------------------------------------------------------------------------- */
41
42int usb_init_kup4x (void);
43
44
45#ifdef CONFIG_KUP4K_LOGO
46void lcd_logo (bd_t * bd);
47#endif
48
49/* ------------------------------------------------------------------------- */
50
51#define _NOT_USED_ 0xFFFFFFFF
52
53const uint sdram_table[] = {
54 /*
55 * Single Read. (Offset 0 in UPMA RAM)
56 */
57 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
58 0x1FF77C47, /* last */
59
60 /*
61 * SDRAM Initialization (offset 5 in UPMA RAM)
62 *
63 * This is no UPM entry point. The following definition uses
64 * the remaining space to establish an initialization
65 * sequence, which is executed by a RUN command.
66 *
67 */
68 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
69
70 /*
71 * Burst Read. (Offset 8 in UPMA RAM)
72 */
73 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
74 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
75 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
76 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
77
78 /*
79 * Single Write. (Offset 18 in UPMA RAM)
80 */
81 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
82 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
83
84 /*
85 * Burst Write. (Offset 20 in UPMA RAM)
86 */
87 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
88 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
89 _NOT_USED_,
90 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
91 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
92
93 /*
94 * Refresh (Offset 30 in UPMA RAM)
95 */
96 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
97 0xFFFFFC84, 0xFFFFFC07, /* last */
98 _NOT_USED_, _NOT_USED_,
99 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
100
101 /*
102 * Exception. (Offset 3c in UPMA RAM)
103 */
104 0x7FFFFC07, /* last */
105 _NOT_USED_, _NOT_USED_, _NOT_USED_,
106};
107
108/* ------------------------------------------------------------------------- */
109
110/*
111 * Check Board Identity:
112 */
113
114int checkboard (void)
115{
116 volatile immap_t *immap = (immap_t *) CFG_IMMR;
117 volatile memctl8xx_t *memctl = &immap->im_memctl;
118 uchar *latch, rev, mod;
119
120 /*
121 * Init ChipSelect #4 (CAN + HW-Latch)
122 */
123 memctl->memc_or4 = 0xFFFF8926;
124 memctl->memc_br4 = 0x90000401;
125
126 latch = (uchar *) 0x90000200;
127 rev = (*latch & 0xF8) >> 3;
128 mod = (*latch & 0x03);
129 printf ("Board: KUP4X Rev %d.%d SN: %s\n", rev, mod,
130 getenv ("ethaddr"));
131 return (0);
132}
133
134/* ------------------------------------------------------------------------- */
135
136long int initdram (int board_type)
137{
138 volatile immap_t *immap = (immap_t *) CFG_IMMR;
139 volatile memctl8xx_t *memctl = &immap->im_memctl;
140 long int size_b0 = 0;
141 long int size_b1 = 0;
142 long int size_b2 = 0;
143 long int size_b3 = 0;
144
145 upmconfig (UPMA, (uint *) sdram_table,
146 sizeof (sdram_table) / sizeof (uint));
147 /*
148 * Preliminary prescaler for refresh (depends on number of
149 * banks): This value is selected for four cycles every 62.4 us
150 * with two SDRAM banks or four cycles every 31.2 us with one
151 * bank. It will be adjusted after memory sizing.
152 */
153 memctl->memc_mptpr = CFG_MPTPR;
154
155 memctl->memc_mar = 0x00000088;
156
157 /*
158 * Map controller banks 1 and 2 to the SDRAM banks 2 and 3 at
159 * preliminary addresses - these have to be modified after the
160 * SDRAM size has been determined.
161 */
162/* memctl->memc_or1 = CFG_OR1_PRELIM; */
163/* memctl->memc_br1 = CFG_BR1_PRELIM; */
164
165/* memctl->memc_or2 = CFG_OR2_PRELIM; */
166/* memctl->memc_br2 = CFG_BR2_PRELIM; */
167
168 memctl->memc_mamr = CFG_MAMR & (~(MAMR_PTAE)); /* no refresh yet */
169
170 udelay (200);
171
172 /* perform SDRAM initializsation sequence */
173
174 memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
175 udelay (1);
176 memctl->memc_mcr = 0x80002830; /* SDRAM bank 0 - execute twice */
177 udelay (1);
178 memctl->memc_mcr = 0x80002106; /* SDRAM bank 0 - RUN MRS Pattern from loc 6 */
179 udelay (1);
180
181 memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
182 udelay (1);
183 memctl->memc_mcr = 0x80004830; /* SDRAM bank 1 - execute twice */
184 udelay (1);
185 memctl->memc_mcr = 0x80004106; /* SDRAM bank 1 - RUN MRS Pattern from loc 6 */
186 udelay (1);
187
188 memctl->memc_mcr = 0x80006105; /* SDRAM bank 2 */
189 udelay (1);
190 memctl->memc_mcr = 0x80006830; /* SDRAM bank 2 - execute twice */
191 udelay (1);
192 memctl->memc_mcr = 0x80006106; /* SDRAM bank 2 - RUN MRS Pattern from loc 6 */
193 udelay (1);
194
195 memctl->memc_mcr = 0x8000C105; /* SDRAM bank 2 */
196 udelay (1);
197 memctl->memc_mcr = 0x8000C830; /* SDRAM bank 2 - execute twice */
198 udelay (1);
199 memctl->memc_mcr = 0x8000C106; /* SDRAM bank 2 - RUN MRS Pattern from loc 6 */
200 udelay (1);
201
202 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
203 udelay (1000);
204#if 0 /* 4 x 8MB */
205 size_b0 = 0x00800000;
206 size_b1 = 0x00800000;
207 size_b2 = 0x00800000;
208 size_b3 = 0x00800000;
209 memctl->memc_mptpr = CFG_MPTPR;
210 udelay (1000);
211 memctl->memc_or1 = 0xFF800A00;
212 memctl->memc_br1 = 0x00000081;
213 memctl->memc_or2 = 0xFF000A00;
214 memctl->memc_br2 = 0x00800081;
215 memctl->memc_or3 = 0xFE000A00;
216 memctl->memc_br3 = 0x01000081;
217 memctl->memc_or6 = 0xFE000A00;
218 memctl->memc_br6 = 0x01800081;
219#else /* 4 x 16 MB */
220 size_b0 = 0x01000000;
221 size_b1 = 0x01000000;
222 size_b2 = 0x01000000;
223 size_b3 = 0x01000000;
224 memctl->memc_mptpr = CFG_MPTPR;
225 udelay (1000);
226 memctl->memc_or1 = 0xFF000A00;
227 memctl->memc_br1 = 0x00000081;
228 memctl->memc_or2 = 0xFE000A00;
229 memctl->memc_br2 = 0x01000081;
230 memctl->memc_or3 = 0xFD000A00;
231 memctl->memc_br3 = 0x02000081;
232 memctl->memc_or6 = 0xFC000A00;
233 memctl->memc_br6 = 0x03000081;
234#endif
235 udelay (10000);
236
237 return (size_b0 + size_b1 + size_b2 + size_b3);
238}
239
240/* ------------------------------------------------------------------------- */
241
242/*
243 * Check memory range for valid RAM. A simple memory test determines
244 * the actually available RAM size between addresses `base' and
245 * `base + maxsize'. Some (not all) hardware errors are detected:
246 * - short between address lines
247 * - short between data lines
248 */
249#if 0
250static long int dram_size (long int mamr_value, long int *base,
251 long int maxsize)
252{
253 volatile immap_t *immap = (immap_t *) CFG_IMMR;
254 volatile memctl8xx_t *memctl = &immap->im_memctl;
255 volatile long int *addr;
256 ulong cnt, val;
257 ulong save[32]; /* to make test non-destructive */
258 unsigned char i = 0;
259
260 memctl->memc_mamr = mamr_value;
261
262 for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
263 addr = base + cnt; /* pointer arith! */
264
265 save[i++] = *addr;
266 *addr = ~cnt;
267 }
268
269 /* write 0 to base address */
270 addr = base;
271 save[i] = *addr;
272 *addr = 0;
273
274 /* check at base address */
275 if ((val = *addr) != 0) {
276 *addr = save[i];
277 return (0);
278 }
279
280 for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
281 addr = base + cnt; /* pointer arith! */
282
283 val = *addr;
284 *addr = save[--i];
285
286 if (val != (~cnt)) {
287 return (cnt * sizeof (long));
288 }
289 }
290 return (maxsize);
291}
292#endif
293
294int misc_init_r (void)
295{
296 volatile immap_t *immap = (immap_t *) CFG_IMMR;
297
298#ifdef CONFIG_IDE_LED
299 /* Configure PA8 as output port */
300 immap->im_ioport.iop_padir |= 0x80;
301 immap->im_ioport.iop_paodr |= 0x80;
302 immap->im_ioport.iop_papar &= ~0x80;
303 immap->im_ioport.iop_padat |= 0x80; /* turn it off */
304#endif
305#ifdef KUP4X_USB
306 usb_init_kup4x ();
307#endif
308 setenv ("hw", "4x");
309 poweron_key ();
310 return (0);
311}