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
34
35
36
37
38#include <common.h>
39#include <mpc5xxx.h>
40#include <pci.h>
41#include <asm/processor.h>
42#include <i2c.h>
43#include <linux/ctype.h>
44
45#ifdef CONFIG_OF_LIBFDT
46#include <libfdt.h>
47#include <libfdt_env.h>
48#include <fdt_support.h>
49#endif
50
51
52#include "cm5200.h"
53#include "fwupdate.h"
54
55DECLARE_GLOBAL_DATA_PTR;
56
57static hw_id_t hw_id;
58
59
60#ifndef CONFIG_SYS_RAMBOOT
61
62
63
64static void sdram_start(int hi_addr, mem_conf_t *mem_conf)
65{
66 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
67
68
69 *(vu_long *)MPC5XXX_SDRAM_CTRL = mem_conf->control | 0x80000000 |
70 hi_addr_bit;
71
72
73 *(vu_long *)MPC5XXX_SDRAM_CTRL = mem_conf->control | 0x80000002 |
74 hi_addr_bit;
75
76
77 *(vu_long *)MPC5XXX_SDRAM_CTRL = mem_conf->control | 0x80000004 |
78 hi_addr_bit;
79
80
81 *(vu_long *)MPC5XXX_SDRAM_CTRL = mem_conf->control | 0x80000004 |
82 hi_addr_bit;
83
84
85 *(vu_long *)MPC5XXX_SDRAM_MODE = mem_conf->mode;
86
87
88 *(vu_long *)MPC5XXX_SDRAM_CTRL = mem_conf->control | hi_addr_bit;
89}
90#endif
91
92
93
94
95
96
97
98static mem_conf_t* get_mem_config(int board_type)
99{
100 switch(board_type){
101 case CM1_QA:
102 return memory_config[0];
103 case CM11_QA:
104 case CMU1_QA:
105 return memory_config[1];
106 default:
107 printf("ERROR: Unknown module, using a default SDRAM "
108 "configuration - things may not work!!!.\n");
109 return memory_config[0];
110 }
111}
112
113
114
115
116
117phys_size_t initdram(int board_type)
118{
119 ulong dramsize = 0;
120#ifndef CONFIG_SYS_RAMBOOT
121 ulong test1, test2;
122 mem_conf_t *mem_conf;
123
124 mem_conf = get_mem_config(board_type);
125
126
127 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;
128
129
130 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = mem_conf->config1;
131 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = mem_conf->config2;
132
133 sdram_start(0, mem_conf);
134 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
135 sdram_start(1, mem_conf);
136 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
137 if (test1 > test2) {
138 sdram_start(0, mem_conf);
139 dramsize = test1;
140 } else
141 dramsize = test2;
142
143
144 if (dramsize < (1 << 20))
145 dramsize = 0;
146
147
148 if (dramsize > 0) {
149 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
150 __builtin_ffs(dramsize >> 20) - 1;
151 } else
152 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0;
153#else
154
155 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
156 if (dramsize >= 0x13)
157 dramsize = (1 << (dramsize - 0x13)) << 20;
158 else
159 dramsize = 0;
160#endif
161
162
163
164
165
166
167 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
168 __asm__ volatile ("sync");
169
170 return dramsize;
171}
172
173
174
175
176
177static void read_hw_id(hw_id_t hw_id)
178{
179 int i;
180 for (i = 0; i < HW_ID_ELEM_COUNT; ++i)
181 if (i2c_read(CONFIG_SYS_I2C_EEPROM,
182 hw_id_format[i].offset,
183 2,
184 (uchar *)&hw_id[i][0],
185 hw_id_format[i].length) != 0)
186 printf("ERROR: can't read HW ID from EEPROM\n");
187}
188
189
190
191
192
193
194
195static void identify_module(hw_id_t hw_id)
196{
197 int i, j, element;
198 char match;
199 gd->board_type = CM5200_UNKNOWN_MODULE;
200 for (i = 0; i < sizeof (hw_id_list) / sizeof (char **); ++i) {
201 match = 1;
202 for (j = 0; j < sizeof (hw_id_identify) / sizeof (int); ++j) {
203 element = hw_id_identify[j];
204 if (strncmp(hw_id_list[i][element],
205 &hw_id[element][0],
206 hw_id_format[element].length) != 0) {
207 match = 0;
208 break;
209 }
210 }
211 if (match) {
212 gd->board_type = i;
213 break;
214 }
215 }
216}
217
218
219
220
221
222
223static void compose_module_name(hw_id_t hw_id, char *buf)
224{
225 char tmp[MODULE_NAME_MAXLEN];
226 strncat(buf, &hw_id[PCB_NAME][0], hw_id_format[PCB_NAME].length);
227 strncat(buf, ".", 1);
228 strncat(buf, &hw_id[FORM][0], hw_id_format[FORM].length);
229 strncat(buf, &hw_id[VERSION][0], hw_id_format[VERSION].length);
230 strncat(buf, " (", 2);
231 strncat(buf, &hw_id[IDENTIFICATION_NUMBER][0],
232 hw_id_format[IDENTIFICATION_NUMBER].length);
233 sprintf(tmp, " / %u.%u)",
234 hw_id[MAJOR_SW_VERSION][0],
235 hw_id[MINOR_SW_VERSION][0]);
236 strcat(buf, tmp);
237}
238
239
240
241
242
243
244static void compose_hostname(hw_id_t hw_id, char *buf)
245{
246 char *p;
247 strncat(buf, &hw_id[PCB_NAME][0], hw_id_format[PCB_NAME].length);
248 strncat(buf, "_", 1);
249 strncat(buf, &hw_id[FORM][0], hw_id_format[FORM].length);
250 strncat(buf, &hw_id[VERSION][0], hw_id_format[VERSION].length);
251 for (p = buf; *p; ++p)
252 *p = tolower(*p);
253
254}
255
256
257#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
258
259
260
261
262static void ft_blob_update(void *blob, bd_t *bd)
263{
264 int len, ret, nodeoffset = 0;
265 char module_name[MODULE_NAME_MAXLEN] = {0};
266
267 compose_module_name(hw_id, module_name);
268 len = strlen(module_name) + 1;
269
270 ret = fdt_setprop(blob, nodeoffset, "model", module_name, len);
271 if (ret < 0)
272 printf("ft_blob_update(): cannot set /model property err:%s\n",
273 fdt_strerror(ret));
274
275 ret = fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
276
277 if (ret < 0) {
278 printf("ft_blob_update(): cannot set /memory/reg "
279 "property err:%s\n", fdt_strerror(ret));
280 }
281}
282#endif
283
284
285
286
287
288
289
290int checkboard(void)
291{
292 hw_id_t hw_id_tmp;
293 char module_name_tmp[MODULE_NAME_MAXLEN] = "";
294
295
296
297
298
299
300 gd->flags |= GD_FLG_SILENT;
301 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
302 gd->flags &= ~GD_FLG_SILENT;
303
304 read_hw_id(hw_id_tmp);
305 identify_module(hw_id_tmp);
306 compose_module_name(hw_id_tmp, module_name_tmp);
307
308 if (gd->board_type != CM5200_UNKNOWN_MODULE)
309 printf("Board: %s\n", module_name_tmp);
310 else
311 printf("Board: unrecognized cm5200 module (%s)\n",
312 module_name_tmp);
313
314 return 0;
315}
316
317
318int board_early_init_r(void)
319{
320
321
322
323
324
325 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1;
326
327
328 read_hw_id(hw_id);
329 return 0;
330}
331
332
333#ifdef CONFIG_POST
334int post_hotkeys_pressed(void)
335{
336 return 0;
337}
338#endif
339
340
341#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
342void post_word_store(ulong a)
343{
344 vu_long *save_addr = (vu_long *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
345 *save_addr = a;
346}
347
348
349ulong post_word_load(void)
350{
351 vu_long *save_addr = (vu_long *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
352 return *save_addr;
353}
354#endif
355
356
357#ifdef CONFIG_MISC_INIT_R
358int misc_init_r(void)
359{
360#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
361 uchar buf[6];
362 char str[18];
363 char hostname[MODULE_NAME_MAXLEN];
364
365
366 if (i2c_read(CONFIG_SYS_I2C_EEPROM, CONFIG_MAC_OFFSET, 2, buf, 6) == 0) {
367 sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X",
368 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
369
370 if (strstr(str, "00:06:C3") != str)
371 printf(LOG_PREFIX "Warning - Illegal MAC address (%s)"
372 " in EEPROM.\n", str);
373 else {
374 printf(LOG_PREFIX "Using MAC (%s) from I2C EEPROM\n",
375 str);
376 setenv("ethaddr", str);
377 }
378 } else {
379 printf(LOG_PREFIX "Warning - Unable to read MAC from I2C"
380 " device at address %02X:%04X\n", CONFIG_SYS_I2C_EEPROM,
381 CONFIG_MAC_OFFSET);
382 }
383#endif
384 if (!getenv("ethaddr"))
385 printf(LOG_PREFIX "MAC address not set, networking is not "
386 "operational\n");
387
388
389 hostname[0] = 0x00;
390 compose_hostname(hw_id, hostname);
391 setenv("hostname", hostname);
392
393 return 0;
394}
395#endif
396
397
398#ifdef CONFIG_LAST_STAGE_INIT
399int last_stage_init(void)
400{
401#ifdef CONFIG_USB_STORAGE
402 cm5200_fwupdate();
403#endif
404 return 0;
405}
406#endif
407
408
409#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
410void ft_board_setup(void *blob, bd_t *bd)
411{
412 ft_cpu_setup(blob, bd);
413 ft_blob_update(blob, bd);
414}
415#endif
416