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#include <common.h>
36#include <mpc5xxx.h>
37#include <net.h>
38#include <pci.h>
39#include <asm/processor.h>
40#include <asm/io.h>
41#include "eeprom.h"
42#if defined(CONFIG_DIGSY_REV5)
43#include "is45s16800a2.h"
44#include <mtd/cfi_flash.h>
45#else
46#include "is42s16800a-7t.h"
47#endif
48#include <libfdt.h>
49#include <fdt_support.h>
50
51DECLARE_GLOBAL_DATA_PTR;
52
53extern int usb_cpu_init(void);
54
55#if defined(CONFIG_DIGSY_REV5)
56
57
58
59
60void flash_cmd_reset(flash_info_t *info)
61{
62 flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
63}
64#endif
65
66#ifndef CONFIG_SYS_RAMBOOT
67static void sdram_start(int hi_addr)
68{
69 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
70 long control = SDRAM_CONTROL | hi_addr_bit;
71
72
73 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
74
75
76 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
77
78
79 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
80
81
82 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
83
84
85 out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
86}
87#endif
88
89
90
91
92
93
94
95phys_size_t initdram(int board_type)
96{
97 ulong dramsize = 0;
98 ulong dramsize2 = 0;
99 uint svr, pvr;
100#ifndef CONFIG_SYS_RAMBOOT
101 ulong test1, test2;
102
103
104 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C);
105 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);
106
107
108 out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
109 out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
110
111
112 sdram_start(0);
113 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
114 sdram_start(1);
115 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
116 if (test1 > test2) {
117 sdram_start(0);
118 dramsize = test1;
119 } else {
120 dramsize = test2;
121 }
122
123
124 if (dramsize < (1 << 20))
125 dramsize = 0;
126
127
128 if (dramsize > 0) {
129 out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
130 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
131 } else {
132 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0);
133 }
134
135
136 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
137
138
139 test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
140 0x08000000);
141 dramsize2 = test1;
142
143
144 if (dramsize2 < (1 << 20))
145 dramsize2 = 0;
146
147
148 if (dramsize2 > 0) {
149 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
150 (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
151 } else {
152 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize);
153 }
154
155#else
156
157
158 dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
159 if (dramsize >= 0x13)
160 dramsize = (1 << (dramsize - 0x13)) << 20;
161 else
162 dramsize = 0;
163
164
165 dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
166 if (dramsize2 >= 0x13)
167 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
168 else
169 dramsize2 = 0;
170
171#endif
172
173
174
175
176
177
178
179
180
181
182 svr = get_svr();
183 pvr = get_pvr();
184 if ((SVR_MJREV(svr) >= 2) &&
185 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
186 out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
187
188 return dramsize + dramsize2;
189}
190
191int checkboard(void)
192{
193 char *s = getenv("serial#");
194
195 puts ("Board: InterControl digsyMTC");
196#if defined(CONFIG_DIGSY_REV5)
197 puts (" rev5");
198#endif
199 if (s != NULL) {
200 puts(", ");
201 puts(s);
202 }
203 putc('\n');
204
205 return 0;
206}
207
208int board_early_init_r(void)
209{
210#ifdef CONFIG_MPC52XX_SPI
211 struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
212#endif
213
214
215
216
217
218
219 clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
220
221 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
222
223 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
224
225#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
226
227 usb_cpu_init();
228#endif
229#ifdef CONFIG_MPC52XX_SPI
230
231 out_be32(&gpt[6].emsr, 0x00000034);
232
233 out_be32(&gpt[7].emsr, 0x00000034);
234#endif
235
236 return (0);
237}
238
239void board_get_enetaddr (uchar * enet)
240{
241 ushort read = 0;
242 ushort addr_of_eth_addr = 0;
243 ushort len_sys = 0;
244 ushort len_sys_cfg = 0;
245
246
247 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
248 if (read != EEPROM_IDENT)
249 return;
250
251
252 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
253 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
254 (uchar *)&len_sys_cfg, 2);
255 addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
256 if (addr_of_eth_addr >= EEPROM_LEN)
257 return;
258
259 eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
260}
261
262int misc_init_r(void)
263{
264 uchar enetaddr[6];
265
266 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
267 board_get_enetaddr(enetaddr);
268 eth_setenv_enetaddr("ethaddr", enetaddr);
269 }
270
271 return 0;
272}
273
274#ifdef CONFIG_PCI
275static struct pci_controller hose;
276
277extern void pci_mpc5xxx_init(struct pci_controller *);
278
279void pci_init_board(void)
280{
281 pci_mpc5xxx_init(&hose);
282}
283#endif
284
285#ifdef CONFIG_CMD_IDE
286
287#ifdef CONFIG_IDE_RESET
288
289void init_ide_reset(void)
290{
291 debug ("init_ide_reset\n");
292
293
294 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
295
296 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
297
298 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
299
300 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
301
302}
303
304void ide_set_reset(int idereset)
305{
306 debug ("ide_reset(%d)\n", idereset);
307
308
309 clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
310
311 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
312
313 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
314
315 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
316
317 udelay(10000);
318
319
320 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
321
322 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
323
324 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
325
326 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
327}
328#endif
329#endif
330
331#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
332static void ft_delete_node(void *fdt, const char *compat)
333{
334 int off = -1;
335 int ret;
336
337 off = fdt_node_offset_by_compatible(fdt, -1, compat);
338 if (off < 0) {
339 printf("Could not find %s node.\n", compat);
340 return;
341 }
342
343 ret = fdt_del_node(fdt, off);
344 if (ret < 0)
345 printf("Could not delete %s node.\n", compat);
346}
347#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
348static void ft_adapt_flash_base(void *blob)
349{
350 flash_info_t *dev = &flash_info[0];
351 int off;
352 struct fdt_property *prop;
353 int len;
354 u32 *reg, *reg2;
355
356 off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
357 if (off < 0) {
358 printf("Could not find fsl,mpc5200b-lpb node.\n");
359 return;
360 }
361
362
363 prop = fdt_get_property_w(blob, off, "ranges", &len);
364 if (prop) {
365 reg = reg2 = (u32 *)&prop->data[0];
366
367 reg[2] = dev->start[0];
368 reg[3] = dev->size;
369 fdt_setprop(blob, off, "ranges", reg2, len);
370 } else
371 printf("Could not find ranges\n");
372}
373
374extern ulong flash_get_size (phys_addr_t base, int banknum);
375
376
377int update_flash_size (int flash_size)
378{
379 volatile struct mpc5xxx_mmap_ctl *mm =
380 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
381 flash_info_t *dev;
382 int i;
383 int size = 0;
384 unsigned long base = 0x0;
385 u32 *cs_reg = (u32 *)&mm->cs0_start;
386
387 for (i = 0; i < 2; i++) {
388 dev = &flash_info[i];
389
390 if (dev->size) {
391
392 base -= dev->size;
393 out_be32(cs_reg, START_REG(base));
394 cs_reg++;
395 out_be32(cs_reg, STOP_REG(base, dev->size));
396 cs_reg++;
397
398 size += flash_get_size(base, i);
399 }
400 }
401 gd->bd->bi_flashstart = base;
402 return 0;
403}
404#endif
405
406void ft_board_setup(void *blob, bd_t *bd)
407{
408 ft_cpu_setup(blob, bd);
409
410
411
412
413#if defined(CONFIG_DIGSY_REV5)
414 ft_delete_node(blob, "dallas,ds1339");
415#else
416 ft_delete_node(blob, "mc,rv3029c2");
417#endif
418#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
419#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
420
421 fdt_fixup_nor_flash_size(blob);
422#endif
423 ft_adapt_flash_base(blob);
424#endif
425}
426#endif
427