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#include <common.h>
31#include <mpc5xxx.h>
32#include <pci.h>
33#include <asm/processor.h>
34#include <malloc.h>
35
36#ifndef CONFIG_SYS_RAMBOOT
37static void sdram_start (int hi_addr)
38{
39 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
40
41
42 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
43 __asm__ volatile ("sync");
44
45
46 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
47 __asm__ volatile ("sync");
48
49#if SDRAM_DDR
50
51 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
52 __asm__ volatile ("sync");
53
54
55 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
56 __asm__ volatile ("sync");
57#endif
58
59
60 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
61 __asm__ volatile ("sync");
62
63
64 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
65 __asm__ volatile ("sync");
66
67
68 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
69 __asm__ volatile ("sync");
70
71
72 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
73 __asm__ volatile ("sync");
74}
75#endif
76
77
78
79
80
81
82
83phys_size_t initdram (int board_type)
84{
85 ulong dramsize = 0;
86#ifndef CONFIG_SYS_RAMBOOT
87 ulong test1, test2;
88 uint svr, pvr;
89
90
91 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c;
92 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000;
93 __asm__ volatile ("sync");
94
95
96 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
97 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
98 __asm__ volatile ("sync");
99
100#if SDRAM_DDR
101
102 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
103 __asm__ volatile ("sync");
104#endif
105
106
107 sdram_start(0);
108 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
109 sdram_start(1);
110 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
111 if (test1 > test2) {
112 sdram_start(0);
113 dramsize = test1;
114 } else {
115 dramsize = test2;
116 }
117
118
119 if (dramsize < (1 << 20)) {
120 dramsize = 0;
121 }
122
123
124 if (dramsize > 0) {
125 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
126 __builtin_ffs(dramsize >> 20) - 1;
127 } else {
128 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0;
129 }
130
131 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize;
132#else
133
134
135 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
136 if (dramsize >= 0x13) {
137 dramsize = (1 << (dramsize - 0x13)) << 20;
138 } else {
139 dramsize = 0;
140 }
141
142
143 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
144 if (dramsize2 >= 0x13) {
145 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
146 } else {
147 dramsize2 = 0;
148 }
149
150#endif
151
152
153
154
155
156
157
158
159
160
161 svr = get_svr();
162 pvr = get_pvr();
163 if ((SVR_MJREV(svr) >= 2) &&
164 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
165
166 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
167 __asm__ volatile ("sync");
168 }
169
170
171 return dramsize;
172}
173
174int checkboard (void)
175{
176 puts ("Board: HMI1001\n");
177 return 0;
178}
179
180#ifdef CONFIG_PREBOOT
181
182static uchar kbd_magic_prefix[] = "key_magic";
183static uchar kbd_command_prefix[] = "key_cmd";
184
185#define S1_ROT 0xf0
186#define S2_Q 0x40
187#define S2_M 0x20
188
189struct kbd_data_t {
190 char s1;
191 char s2;
192};
193
194struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
195{
196 kbd_data->s1 = *((volatile uchar*)(CONFIG_SYS_STATUS1_BASE));
197 kbd_data->s2 = *((volatile uchar*)(CONFIG_SYS_STATUS2_BASE));
198
199 return kbd_data;
200}
201
202static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
203{
204 char s1 = str[0];
205 char s2;
206
207 if (s1 >= '0' && s1 <= '9')
208 s1 -= '0';
209 else if (s1 >= 'a' && s1 <= 'f')
210 s1 = s1 - 'a' + 10;
211 else if (s1 >= 'A' && s1 <= 'F')
212 s1 = s1 - 'A' + 10;
213 else
214 return -1;
215
216 if (((S1_ROT & kbd_data->s1) >> 4) != s1)
217 return -1;
218
219 s2 = (S2_Q | S2_M) & kbd_data->s2;
220
221 switch (str[1]) {
222 case 'q':
223 case 'Q':
224 if (s2 == S2_Q)
225 return -1;
226 break;
227 case 'm':
228 case 'M':
229 if (s2 == S2_M)
230 return -1;
231 break;
232 case '\0':
233 if (s2 == (S2_Q | S2_M))
234 return 0;
235 default:
236 return -1;
237 }
238
239 if (str[2])
240 return -1;
241
242 return 0;
243}
244
245static char *key_match (const struct kbd_data_t *kbd_data)
246{
247 char magic[sizeof (kbd_magic_prefix) + 1];
248 char *suffix;
249 char *kbd_magic_keys;
250
251
252
253
254
255
256
257
258
259 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
260 kbd_magic_keys = "";
261
262
263
264
265 for (suffix = kbd_magic_keys; *suffix ||
266 suffix == kbd_magic_keys; ++suffix) {
267 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
268
269 if (compare_magic(kbd_data, getenv(magic)) == 0) {
270 char cmd_name[sizeof (kbd_command_prefix) + 1];
271 char *cmd;
272
273 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
274 cmd = getenv (cmd_name);
275
276 return (cmd);
277 }
278 }
279
280 return (NULL);
281}
282
283#endif
284
285int misc_init_r (void)
286{
287#ifdef CONFIG_PREBOOT
288 struct kbd_data_t kbd_data;
289
290 char *str = strdup (key_match (get_keys (&kbd_data)));
291
292 setenv ("preboot", str);
293 free (str);
294#endif
295
296 return 0;
297}
298
299int board_early_init_r (void)
300{
301 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1;
302 *(vu_long *)MPC5XXX_BOOTCS_START =
303 *(vu_long *)MPC5XXX_CS0_START = START_REG(CONFIG_SYS_FLASH_BASE);
304 *(vu_long *)MPC5XXX_BOOTCS_STOP =
305 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE);
306 return 0;
307}
308#ifdef CONFIG_PCI
309static struct pci_controller hose;
310
311extern void pci_mpc5xxx_init(struct pci_controller *);
312
313void pci_init_board(void)
314{
315 pci_mpc5xxx_init(&hose);
316}
317#endif
318