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#include <common.h>
28#include <mpc5xxx.h>
29#include <pci.h>
30#include <asm/processor.h>
31#include <libfdt.h>
32
33#define SDRAM_DDR 0
34#if 1
35
36#define SDRAM_MODE 0x00CD0000
37#define SDRAM_CONTROL 0x504F0000
38#define SDRAM_CONFIG1 0xD2322800
39#define SDRAM_CONFIG2 0x8AD70000
40#else
41
42#define SDRAM_MODE 0x008D0000
43#define SDRAM_CONTROL 0xD04F0000
44#define SDRAM_CONFIG1 0xf7277f00
45#define SDRAM_CONFIG2 0x88b70004
46#endif
47
48#ifndef CONFIG_SYS_RAMBOOT
49static void sdram_start (int hi_addr)
50{
51 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
52
53
54 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
55 __asm__ volatile ("sync");
56
57
58 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
59 __asm__ volatile ("sync");
60
61#if SDRAM_DDR
62
63 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
64 __asm__ volatile ("sync");
65
66
67 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
68 __asm__ volatile ("sync");
69#endif
70
71
72 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
73 __asm__ volatile ("sync");
74
75
76 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
77 __asm__ volatile ("sync");
78
79
80 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
81 __asm__ volatile ("sync");
82
83
84 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
85 __asm__ volatile ("sync");
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
101#ifndef CONFIG_SYS_RAMBOOT
102 ulong test1, test2;
103
104
105 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;
106 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;
107 __asm__ volatile ("sync");
108
109
110 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
111 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
112 __asm__ volatile ("sync");
113
114#if SDRAM_DDR
115
116 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
117 __asm__ volatile ("sync");
118#endif
119
120
121 sdram_start(0);
122 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
123 sdram_start(1);
124 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
125 if (test1 > test2) {
126 sdram_start(0);
127 dramsize = test1;
128 } else {
129 dramsize = test2;
130 }
131
132
133 if (dramsize < (1 << 20)) {
134 dramsize = 0;
135 }
136
137
138 if (dramsize > 0) {
139 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
140 } else {
141 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0;
142 }
143
144
145 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;
146
147
148 if (!dramsize)
149 sdram_start(0);
150 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
151 if (!dramsize) {
152 sdram_start(1);
153 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
154 }
155 if (test1 > test2) {
156 sdram_start(0);
157 dramsize2 = test1;
158 } else {
159 dramsize2 = test2;
160 }
161
162
163 if (dramsize2 < (1 << 20)) {
164 dramsize2 = 0;
165 }
166
167
168 if (dramsize2 > 0) {
169 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
170 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
171 } else {
172 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize;
173 }
174
175#else
176
177
178 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
179 if (dramsize >= 0x13) {
180 dramsize = (1 << (dramsize - 0x13)) << 20;
181 } else {
182 dramsize = 0;
183 }
184
185
186 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
187 if (dramsize2 >= 0x13) {
188 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
189 } else {
190 dramsize2 = 0;
191 }
192
193#endif
194
195
196
197
198
199
200
201
202
203
204 svr = get_svr();
205 pvr = get_pvr();
206 if ((SVR_MJREV(svr) >= 2) &&
207 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
208
209 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
210 __asm__ volatile ("sync");
211 }
212
213 return dramsize + dramsize2;
214}
215
216int checkboard (void)
217{
218 puts ("Board: Sauter (Jupiter)\n");
219 return 0;
220}
221
222void flash_preinit(void)
223{
224
225
226
227
228
229
230 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1;
231}
232
233int board_early_init_r (void)
234{
235 flash_preinit ();
236 return 0;
237}
238
239void flash_afterinit(ulong size)
240{
241 if (size == 0x1000000) {
242 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
243 START_REG(CONFIG_SYS_BOOTCS_START | size);
244 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
245 STOP_REG(CONFIG_SYS_BOOTCS_START | size, size);
246 }
247 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25);
248 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16);
249}
250
251int update_flash_size (int flash_size)
252{
253 flash_afterinit (flash_size);
254 return 0;
255}
256
257int board_early_init_f (void)
258{
259 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1;
260 return 0;
261}
262
263#ifdef CONFIG_PCI
264static struct pci_controller hose;
265
266extern void pci_mpc5xxx_init(struct pci_controller *);
267
268void pci_init_board(void)
269{
270 pci_mpc5xxx_init(&hose);
271}
272#endif
273
274#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
275
276void init_ide_reset (void)
277{
278 debug ("init_ide_reset\n");
279
280
281 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
282 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
283
284 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
285}
286
287void ide_set_reset (int idereset)
288{
289 debug ("ide_reset(%d)\n", idereset);
290
291 if (idereset) {
292 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
293
294 udelay(500000);
295 } else {
296 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
297 }
298}
299#endif
300
301#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
302void
303ft_board_setup(void *blob, bd_t *bd)
304{
305 ft_cpu_setup(blob, bd);
306}
307#endif
308