1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <config.h>
26#include <mpc8xx.h>
27#include <i2c.h>
28
29#include <commproc.h>
30#include <command.h>
31#include <malloc.h>
32
33#include <linux/types.h>
34#include <linux/string.h>
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#define _not_used_ 0xffffffff
53
54const uint sdram_table[]=
55{
56
57 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
58 0x1ff77c47,
59
60
61
62 0x1ff77c34, 0xefeabc34, 0x1fb57c35,
63
64
65 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
66 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47,
67 _not_used_, _not_used_, _not_used_, _not_used_,
68 _not_used_, _not_used_, _not_used_, _not_used_,
69
70
71 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47,
72 _not_used_, _not_used_, _not_used_, _not_used_,
73
74
75 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
76 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _not_used_,
77 _not_used_, _not_used_, _not_used_, _not_used_,
78 _not_used_, _not_used_, _not_used_, _not_used_,
79
80
81 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
82 0xfffffc84, 0xfffffc07, _not_used_, _not_used_,
83 _not_used_, _not_used_, _not_used_, _not_used_,
84
85
86 0x7ffffc07, _not_used_, _not_used_, _not_used_ };
87
88
89
90
91
92
93
94int checkboard (void)
95{
96 puts ("Board: R360 MPI Board\n");
97 return 0;
98}
99
100
101
102static long int dram_size (long int, long int *, long int);
103
104
105
106phys_size_t initdram (int board_type)
107{
108 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
109 volatile memctl8xx_t *memctl = &immap->im_memctl;
110 long int size8, size9;
111 long int size_b0 = 0;
112 unsigned long reg;
113
114 upmconfig (UPMA, (uint *) sdram_table,
115 sizeof (sdram_table) / sizeof (uint));
116
117
118
119
120
121
122
123 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
124
125 memctl->memc_mar = 0x00000088;
126
127
128
129
130
131
132 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
133 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
134
135 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE));
136
137 udelay (200);
138
139
140
141 memctl->memc_mcr = 0x80004105;
142 udelay (200);
143 memctl->memc_mcr = 0x80004230;
144 udelay (200);
145
146 memctl->memc_mamr |= MAMR_PTAE;
147
148 udelay (1000);
149
150
151
152
153
154
155 size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE2_PRELIM,
156 SDRAM_MAX_SIZE);
157
158 udelay (1000);
159
160
161
162
163 size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE2_PRELIM,
164 SDRAM_MAX_SIZE);
165
166 if (size8 < size9) {
167 size_b0 = size9;
168
169 } else {
170 size_b0 = size8;
171 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
172 udelay (500);
173
174 }
175
176 udelay (1000);
177
178
179
180
181
182 if ((size_b0 < 0x02000000)) {
183
184 memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
185 udelay (1000);
186 }
187
188
189
190
191
192 memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
193 memctl->memc_br1 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
194
195
196 reg = memctl->memc_mptpr;
197 reg >>= 1;
198 memctl->memc_mptpr = reg;
199
200 udelay (10000);
201
202#ifdef CONFIG_CAN_DRIVER
203
204 memctl->memc_or3 = CONFIG_SYS_OR3_CAN;
205 memctl->memc_br3 = CONFIG_SYS_BR3_CAN;
206
207
208 memctl->memc_mbmr = MBMR_GPL_B4DIS;
209
210
211 memctl->memc_mdr = 0xFFFFC004;
212 memctl->memc_mcr = 0x0100 | UPMB;
213
214 memctl->memc_mdr = 0x0FFFD004;
215 memctl->memc_mcr = 0x0101 | UPMB;
216
217 memctl->memc_mdr = 0x0FFFC000;
218 memctl->memc_mcr = 0x0102 | UPMB;
219
220 memctl->memc_mdr = 0x3FFFC004;
221 memctl->memc_mcr = 0x0103 | UPMB;
222
223 memctl->memc_mdr = 0xFFFFDC05;
224 memctl->memc_mcr = 0x0104 | UPMB;
225
226
227 memctl->memc_mdr = 0xFFFCC004;
228 memctl->memc_mcr = 0x0118 | UPMB;
229
230 memctl->memc_mdr = 0xCFFCD004;
231 memctl->memc_mcr = 0x0119 | UPMB;
232
233 memctl->memc_mdr = 0x0FFCC000;
234 memctl->memc_mcr = 0x011A | UPMB;
235
236 memctl->memc_mdr = 0x7FFCC004;
237 memctl->memc_mcr = 0x011B | UPMB;
238
239 memctl->memc_mdr = 0xFFFDCC05;
240 memctl->memc_mcr = 0x011C | UPMB;
241#endif
242
243 return (size_b0);
244}
245
246
247
248
249
250
251
252
253
254
255
256static long int dram_size (long int mamr_value,
257 long int *base, long int maxsize)
258{
259 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
260 volatile memctl8xx_t *memctl = &immap->im_memctl;
261
262 memctl->memc_mamr = mamr_value;
263
264 return (get_ram_size(base, maxsize));
265}
266
267
268
269void r360_i2c_lcd_write (uchar data0, uchar data1)
270{
271 if (i2c_write (CONFIG_SYS_I2C_LCD_ADDR, data0, 1, &data1, 1)) {
272 printf("Can't write lcd data 0x%02X 0x%02X.\n", data0, data1);
273 }
274}
275
276
277
278
279
280
281
282
283#define KEYBD_KEY_MAX 16
284#define KEYBD_DATALEN ((KEYBD_KEY_MAX + 7) / 8)
285
286static uchar *key_match (uchar *);
287
288int misc_init_r (void)
289{
290 char kbd_data[KEYBD_DATALEN];
291 char keybd_env[2 * KEYBD_DATALEN + 1];
292 char *str;
293 int i;
294
295 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
296
297 i2c_read (CONFIG_SYS_I2C_KEY_ADDR, 0, 0, (uchar *)kbd_data, KEYBD_DATALEN);
298
299 for (i = 0; i < KEYBD_DATALEN; ++i) {
300 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
301 }
302 setenv ("keybd", keybd_env);
303
304 str = strdup ((char *)key_match ((uchar *)keybd_env));
305
306#ifdef CONFIG_PREBOOT
307 setenv ("preboot", str);
308#endif
309 if (str != NULL) {
310 free (str);
311 }
312
313 return (0);
314}
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329#ifdef CONFIG_PREBOOT
330
331static uchar kbd_magic_prefix[] = "key_magic";
332static uchar kbd_command_prefix[] = "key_cmd";
333
334static uchar *key_match (uchar * kbd_str)
335{
336 uchar magic[sizeof (kbd_magic_prefix) + 1];
337 uchar cmd_name[sizeof (kbd_command_prefix) + 1];
338 uchar *str, *suffix;
339 uchar *kbd_magic_keys;
340 char *cmd;
341
342
343
344
345
346
347
348
349
350 if ((kbd_magic_keys = (uchar *)getenv ("magic_keys")) != NULL) {
351
352
353
354 for (suffix = kbd_magic_keys;
355 *suffix || suffix == kbd_magic_keys;
356 ++suffix) {
357 sprintf ((char *)magic, "%s%c", kbd_magic_prefix, *suffix);
358
359#if 0
360 printf ("### Check magic \"%s\"\n", magic);
361#endif
362
363 if ((str = (uchar *)getenv ((char *)magic)) != 0) {
364
365#if 0
366 printf ("### Compare \"%s\" \"%s\"\n",
367 kbd_str, str);
368#endif
369 if (strcmp ((char *)kbd_str, (char *)str) == 0) {
370 sprintf ((char *)cmd_name, "%s%c",
371 kbd_command_prefix,
372 *suffix);
373
374 if ((cmd = getenv ((char *)cmd_name)) != 0) {
375#if 0
376 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
377 cmd_name, cmd);
378#endif
379 return ((uchar *)cmd);
380 }
381 }
382 }
383 }
384 }
385#if 0
386 printf ("### Delete PREBOOT\n");
387#endif
388 *kbd_str = '\0';
389 return (NULL);
390}
391#endif
392
393
394int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
395{
396 uchar kbd_data[KEYBD_DATALEN];
397 uchar keybd_env[2 * KEYBD_DATALEN + 1];
398 int i;
399
400 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
401
402
403 i2c_read (CONFIG_SYS_I2C_KEY_ADDR, 0, 0, kbd_data, KEYBD_DATALEN);
404
405 puts ("Keys:");
406 for (i = 0; i < KEYBD_DATALEN; ++i) {
407 sprintf ((char *)(keybd_env + i + i), "%02X", kbd_data[i]);
408 printf (" %02x", kbd_data[i]);
409 }
410 putc ('\n');
411 setenv ("keybd", (char *)keybd_env);
412 return 0;
413}
414
415U_BOOT_CMD(
416 kbd, 1, 1, do_kbd,
417 "read keyboard status",
418 ""
419);
420