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#include "is42s16800a-7t.h"
43
44DECLARE_GLOBAL_DATA_PTR;
45
46extern int usb_cpu_init(void);
47
48#ifndef CONFIG_SYS_RAMBOOT
49static void sdram_start(int hi_addr)
50{
51 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
52 long control = SDRAM_CONTROL | hi_addr_bit;
53
54
55 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
56
57
58 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
59
60
61 out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
62
63
64 out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
65
66
67 out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
68}
69#endif
70
71
72
73
74
75
76
77phys_size_t initdram(int board_type)
78{
79 ulong dramsize = 0;
80 ulong dramsize2 = 0;
81 uint svr, pvr;
82#ifndef CONFIG_SYS_RAMBOOT
83 ulong test1, test2;
84
85
86 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C);
87 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);
88
89
90 out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
91 out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
92
93
94 sdram_start(0);
95 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
96 sdram_start(1);
97 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
98 if (test1 > test2) {
99 sdram_start(0);
100 dramsize = test1;
101 } else {
102 dramsize = test2;
103 }
104
105
106 if (dramsize < (1 << 20))
107 dramsize = 0;
108
109
110 if (dramsize > 0) {
111 out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
112 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
113 } else {
114 out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0);
115 }
116
117
118 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
119
120
121 test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
122 0x08000000);
123 dramsize2 = test1;
124
125
126 if (dramsize2 < (1 << 20))
127 dramsize2 = 0;
128
129
130 if (dramsize2 > 0) {
131 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
132 (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
133 } else {
134 out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize);
135 }
136
137#else
138
139
140 dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
141 if (dramsize >= 0x13)
142 dramsize = (1 << (dramsize - 0x13)) << 20;
143 else
144 dramsize = 0;
145
146
147 dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
148 if (dramsize2 >= 0x13)
149 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
150 else
151 dramsize2 = 0;
152
153#endif
154
155
156
157
158
159
160
161
162
163
164 svr = get_svr();
165 pvr = get_pvr();
166 if ((SVR_MJREV(svr) >= 2) &&
167 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
168 out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
169
170 return dramsize + dramsize2;
171}
172
173int checkboard(void)
174{
175 char *s = getenv("serial#");
176
177 puts ("Board: InterControl digsyMTC");
178 if (s != NULL) {
179 puts(", ");
180 puts(s);
181 }
182 putc('\n');
183
184 return 0;
185}
186
187int board_early_init_r(void)
188{
189#ifdef CONFIG_MPC52XX_SPI
190 struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
191#endif
192
193
194
195
196
197
198 clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
199
200 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
201
202 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
203
204#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
205
206 usb_cpu_init();
207#endif
208#ifdef CONFIG_MPC52XX_SPI
209
210 out_be32(&gpt[6].emsr, 0x00000034);
211
212 out_be32(&gpt[7].emsr, 0x00000034);
213#endif
214
215 return (0);
216}
217
218void board_get_enetaddr (uchar * enet)
219{
220 ushort read = 0;
221 ushort addr_of_eth_addr = 0;
222 ushort len_sys = 0;
223 ushort len_sys_cfg = 0;
224
225
226 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
227 if (read != EEPROM_IDENT)
228 return;
229
230
231 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
232 eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
233 (uchar *)&len_sys_cfg, 2);
234 addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
235 if (addr_of_eth_addr >= EEPROM_LEN)
236 return;
237
238 eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
239}
240
241int misc_init_r(void)
242{
243 uchar enetaddr[6];
244
245 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
246 board_get_enetaddr(enetaddr);
247 eth_setenv_enetaddr("ethaddr", enetaddr);
248 }
249
250 return 0;
251}
252
253#ifdef CONFIG_PCI
254static struct pci_controller hose;
255
256extern void pci_mpc5xxx_init(struct pci_controller *);
257
258void pci_init_board(void)
259{
260 pci_mpc5xxx_init(&hose);
261}
262#endif
263
264#ifdef CONFIG_CMD_IDE
265
266#ifdef CONFIG_IDE_RESET
267
268void init_ide_reset(void)
269{
270 debug ("init_ide_reset\n");
271
272
273 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
274
275 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
276
277 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
278
279 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
280
281}
282
283void ide_set_reset(int idereset)
284{
285 debug ("ide_reset(%d)\n", idereset);
286
287
288 clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
289
290 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
291
292 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
293
294 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
295
296 udelay(10000);
297
298
299 setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
300
301 setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
302
303 setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
304
305 setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
306}
307#endif
308
309#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
310void ft_board_setup(void *blob, bd_t *bd)
311{
312 ft_cpu_setup(blob, bd);
313}
314#endif
315
316#endif
317