1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <common.h>
34#include <fdt_support.h>
35#include <mpc5xxx.h>
36#include <pci.h>
37#include <malloc.h>
38#include <asm/processor.h>
39#include <asm/io.h>
40
41#ifndef CONFIG_SYS_RAMBOOT
42static void sdram_start (int hi_addr)
43{
44 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
45
46
47 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
48 (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
49 __asm__ volatile ("sync");
50
51
52 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
53 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
54 __asm__ volatile ("sync");
55
56#if SDRAM_DDR
57
58 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_EMODE));
59 __asm__ volatile ("sync");
60
61
62 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE,
63 (SDRAM_MODE | 0x04000000));
64 __asm__ volatile ("sync");
65#endif
66
67
68 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
69 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
70 __asm__ volatile ("sync");
71
72
73 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
74 (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
75 __asm__ volatile ("sync");
76
77
78 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_MODE));
79 __asm__ volatile ("sync");
80
81
82 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
83 (SDRAM_CONTROL | hi_addr_bit));
84 __asm__ volatile ("sync");
85}
86#endif
87
88
89
90
91
92
93
94phys_size_t initdram (int board_type)
95{
96 ulong dramsize = 0;
97 ulong dramsize2 = 0;
98 uint svr, pvr;
99
100#ifndef CONFIG_SYS_RAMBOOT
101 ulong test1, test2;
102
103
104 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0x0000001c);
105 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);
106 __asm__ volatile ("sync");
107
108
109 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
110 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
111 __asm__ volatile ("sync");
112
113#if SDRAM_DDR
114
115 out_be32 ((unsigned __iomem *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
116 __asm__ volatile ("sync");
117#endif
118
119
120 sdram_start (0);
121 test1 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
122 sdram_start(1);
123 test2 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
124 if (test1 > test2) {
125 sdram_start (0);
126 dramsize = test1;
127 } else {
128 dramsize = test2;
129 }
130
131
132 if (dramsize < (1 << 20)) {
133 dramsize = 0;
134 }
135
136
137 if (dramsize > 0) {
138 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG,
139 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
140 } else {
141 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0);
142 }
143
144
145 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, (dramsize + 0x0000001c));
146
147
148 if (!dramsize)
149 sdram_start (0);
150 test2 = test1 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
151 if (!dramsize) {
152 sdram_start (1);
153 test2 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
154 }
155 if (test1 > test2) {
156 sdram_start (0);
157 dramsize2 = test1;
158 } else {
159 dramsize2 = test2;
160 }
161
162
163 if (dramsize2 < (1 << 20)) {
164 dramsize2 = 0;
165 }
166
167
168 if (dramsize2 > 0) {
169 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG,
170 (dramsize | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
171 } else {
172 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, dramsize);
173 }
174
175#else
176
177
178 dramsize = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
179 if (dramsize >= 0x13) {
180 dramsize = (1 << (dramsize - 0x13)) << 20;
181 } else {
182 dramsize = 0;
183 }
184
185
186 dramsize2 = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
187 if (dramsize2 >= 0x13) {
188 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
189 } else {
190 dramsize2 = 0;
191 }
192
193#endif
194
195
196
197
198
199
200
201
202
203
204 svr = get_svr();
205 pvr = get_pvr();
206 if ((SVR_MJREV(svr) >= 2) &&
207 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
208
209 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_SDELAY, 0x04);
210 __asm__ volatile ("sync");
211 }
212
213 return dramsize + dramsize2;
214}
215
216int checkboard (void)
217{
218 puts ("Board: MUC.MC-52 HW WDT ");
219#if defined(CONFIG_HW_WATCHDOG)
220 puts ("enabled\n");
221#else
222 puts ("disabled\n");
223#endif
224 return 0;
225}
226
227#ifdef CONFIG_PREBOOT
228
229static uchar kbd_magic_prefix[] = "key_magic";
230static uchar kbd_command_prefix[] = "key_cmd";
231
232#define S1_ROT 0xf0
233#define S2_Q 0x40
234#define S2_M 0x20
235
236struct kbd_data_t {
237 char s1;
238 char s2;
239};
240
241struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
242{
243 kbd_data->s1 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS1_BASE);
244 kbd_data->s2 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS2_BASE);
245
246 return kbd_data;
247}
248
249static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
250{
251 char s1 = str[0];
252 char s2;
253
254 if (s1 >= '0' && s1 <= '9')
255 s1 -= '0';
256 else if (s1 >= 'a' && s1 <= 'f')
257 s1 = s1 - 'a' + 10;
258 else if (s1 >= 'A' && s1 <= 'F')
259 s1 = s1 - 'A' + 10;
260 else
261 return -1;
262
263 if (((S1_ROT & kbd_data->s1) >> 4) != s1)
264 return -1;
265
266 s2 = (S2_Q | S2_M) & kbd_data->s2;
267
268 switch (str[1]) {
269 case 'q':
270 case 'Q':
271 if (s2 == S2_Q)
272 return -1;
273 break;
274 case 'm':
275 case 'M':
276 if (s2 == S2_M)
277 return -1;
278 break;
279 case '\0':
280 if (s2 == (S2_Q | S2_M))
281 return 0;
282 default:
283 return -1;
284 }
285
286 if (str[2])
287 return -1;
288
289 return 0;
290}
291
292static char *key_match (const struct kbd_data_t *kbd_data)
293{
294 char magic[sizeof (kbd_magic_prefix) + 1];
295 char *suffix;
296 char *kbd_magic_keys;
297
298
299
300
301
302
303
304
305
306 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
307 kbd_magic_keys = "";
308
309
310
311
312 for (suffix = kbd_magic_keys; *suffix ||
313 suffix == kbd_magic_keys; ++suffix) {
314 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
315
316 if (compare_magic(kbd_data, getenv(magic)) == 0) {
317 char cmd_name[sizeof (kbd_command_prefix) + 1];
318 char *cmd;
319
320 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
321 cmd = getenv (cmd_name);
322
323 return (cmd);
324 }
325 }
326
327 return (NULL);
328}
329
330#endif
331
332int misc_init_r (void)
333{
334#ifdef CONFIG_PREBOOT
335 struct kbd_data_t kbd_data;
336
337 char *str = strdup (key_match (get_keys (&kbd_data)));
338
339 setenv ("preboot", str);
340 free (str);
341#endif
342
343 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), ' ');
344 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), ' ');
345 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), ' ');
346 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), ' ');
347 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), ' ');
348 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), ' ');
349 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), ' ');
350 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), ' ');
351
352 return 0;
353}
354
355int board_early_init_r (void)
356{
357 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG, in_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG) & ~0x1);
358 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_FLASH_BASE));
359 out_be32 ((unsigned __iomem *)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_FLASH_BASE));
360 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_STOP,
361 STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
362 out_be32 ((unsigned __iomem *)MPC5XXX_CS0_STOP,
363 STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
364 return 0;
365}
366
367int last_stage_init (void)
368{
369 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), 'M');
370 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), 'U');
371 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), 'C');
372 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), '.');
373 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), 'M');
374 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), 'C');
375 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), '5');
376 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), '2');
377
378 return 0;
379}
380
381#if defined(CONFIG_HW_WATCHDOG)
382#define GPT_OUT_0 0x00000027
383#define GPT_OUT_1 0x00000037
384void hw_watchdog_reset (void)
385{
386
387 out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_1);
388 out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_0);
389}
390#endif
391
392#ifdef CONFIG_PCI
393static struct pci_controller hose;
394
395extern void pci_mpc5xxx_init (struct pci_controller *);
396
397void pci_init_board (void)
398{
399 pci_mpc5xxx_init (&hose);
400}
401#endif
402
403#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
404void ft_board_setup(void *blob, bd_t *bd)
405{
406 ft_cpu_setup(blob, bd);
407}
408#endif
409