1
2
3
4
5
6#include <common.h>
7#include <pci.h>
8#include <asm/processor.h>
9#include <asm/mmu.h>
10#include <asm/immap_85xx.h>
11#include <fsl_ddr_sdram.h>
12#include <ioports.h>
13#include <spd_sdram.h>
14#include <linux/libfdt.h>
15#include <fdt_support.h>
16
17#include "../common/cadmus.h"
18#include "../common/eeprom.h"
19#include "../common/via.h"
20
21#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
22extern void ddr_enable_ecc(unsigned int dram_size);
23#endif
24
25void local_bus_init(void);
26
27
28
29
30
31
32
33
34const iop_conf_t iop_conf_tab[4][32] = {
35
36
37 {
38 { 0, 1, 0, 1, 0, 0 },
39 { 0, 1, 0, 0, 0, 0 },
40 { 0, 1, 0, 1, 0, 0 },
41 { 0, 1, 0, 1, 0, 0 },
42 { 0, 1, 0, 0, 0, 0 },
43 { 0, 1, 0, 0, 0, 0 },
44 { 0, 1, 0, 1, 0, 0 },
45 { 0, 1, 0, 1, 0, 0 },
46 { 0, 1, 0, 1, 0, 0 },
47 { 0, 1, 0, 1, 0, 0 },
48 { 0, 1, 0, 1, 0, 0 },
49 { 0, 1, 0, 1, 0, 0 },
50 { 0, 1, 0, 1, 0, 0 },
51 { 0, 1, 0, 1, 0, 0 },
52 { 0, 1, 0, 0, 0, 0 },
53 { 0, 1, 0, 0, 0, 0 },
54 { 0, 1, 0, 0, 0, 0 },
55 { 0, 1, 0, 0, 0, 0 },
56 { 0, 1, 0, 0, 0, 0 },
57 { 0, 1, 0, 0, 0, 0 },
58 { 0, 1, 0, 0, 0, 0 },
59 { 0, 1, 0, 0, 0, 0 },
60 { 0, 1, 1, 1, 0, 0 },
61 { 0, 1, 1, 0, 0, 0 },
62 { 0, 0, 0, 1, 0, 0 },
63 { 0, 1, 1, 1, 0, 0 },
64 { 0, 0, 0, 1, 0, 0 },
65 { 0, 0, 0, 1, 0, 0 },
66 { 0, 0, 0, 1, 0, 0 },
67 { 0, 0, 0, 1, 0, 0 },
68 { 1, 0, 0, 0, 0, 0 },
69 { 0, 0, 0, 1, 0, 0 }
70 },
71
72
73 {
74 { 1, 1, 0, 1, 0, 0 },
75 { 1, 1, 0, 0, 0, 0 },
76 { 1, 1, 1, 1, 0, 0 },
77 { 1, 1, 0, 0, 0, 0 },
78 { 1, 1, 0, 0, 0, 0 },
79 { 1, 1, 0, 0, 0, 0 },
80 { 1, 1, 0, 1, 0, 0 },
81 { 1, 1, 0, 1, 0, 0 },
82 { 1, 1, 0, 1, 0, 0 },
83 { 1, 1, 0, 1, 0, 0 },
84 { 1, 1, 0, 0, 0, 0 },
85 { 1, 1, 0, 0, 0, 0 },
86 { 1, 1, 0, 0, 0, 0 },
87 { 1, 1, 0, 0, 0, 0 },
88 { 0, 1, 0, 0, 0, 0 },
89 { 0, 1, 0, 0, 0, 0 },
90 { 0, 1, 0, 1, 0, 0 },
91 { 0, 1, 0, 1, 0, 0 },
92 { 0, 1, 0, 0, 0, 0 },
93 { 0, 1, 0, 0, 0, 0 },
94 { 0, 1, 0, 0, 0, 0 },
95 { 0, 1, 0, 0, 0, 0 },
96 { 0, 1, 0, 0, 0, 0 },
97 { 0, 1, 0, 0, 0, 0 },
98 { 0, 1, 0, 1, 0, 0 },
99 { 0, 1, 0, 1, 0, 0 },
100 { 0, 1, 0, 1, 0, 0 },
101 { 0, 1, 0, 1, 0, 0 },
102 { 0, 0, 0, 0, 0, 0 },
103 { 0, 0, 0, 0, 0, 0 },
104 { 0, 0, 0, 0, 0, 0 },
105 { 0, 0, 0, 0, 0, 0 }
106 },
107
108
109 {
110 { 0, 0, 0, 1, 0, 0 },
111 { 0, 0, 0, 1, 0, 0 },
112 { 0, 1, 1, 0, 0, 0 },
113 { 0, 0, 0, 1, 0, 0 },
114 { 0, 0, 0, 1, 0, 0 },
115 { 0, 0, 0, 1, 0, 0 },
116 { 0, 0, 0, 1, 0, 0 },
117 { 0, 0, 0, 1, 0, 0 },
118 { 0, 1, 0, 1, 0, 0 },
119 { 0, 1, 0, 0, 0, 0 },
120 { 0, 1, 0, 0, 0, 0 },
121 { 0, 1, 0, 0, 0, 0 },
122 { 1, 1, 0, 0, 0, 0 },
123 { 1, 1, 0, 0, 0, 0 },
124 { 0, 0, 0, 1, 0, 0 },
125 { 0, 1, 0, 0, 0, 0 },
126 { 1, 1, 0, 0, 0, 0 },
127 { 0, 1, 0, 0, 0, 0 },
128 { 0, 0, 0, 1, 0, 0 },
129 { 0, 1, 0, 1, 0, 0 },
130 { 0, 0, 0, 1, 0, 0 },
131 { 1, 0, 0, 1, 0, 0 },
132 { 1, 0, 0, 0, 0, 0 },
133 { 0, 0, 0, 1, 0, 0 },
134 { 0, 0, 0, 1, 0, 0 },
135 { 0, 0, 0, 1, 0, 0 },
136 { 0, 0, 0, 1, 0, 0 },
137 { 0, 0, 0, 1, 0, 0 },
138 { 0, 0, 0, 1, 0, 0 },
139 { 0, 0, 0, 1, 0, 1 },
140 { 0, 0, 0, 1, 0, 0 },
141 { 0, 0, 0, 1, 0, 0 },
142 },
143
144
145 {
146 { 1, 1, 0, 0, 0, 0 },
147 { 1, 1, 1, 1, 0, 0 },
148 { 1, 1, 0, 1, 0, 0 },
149 { 0, 1, 0, 0, 0, 0 },
150 { 0, 1, 1, 1, 0, 0 },
151 { 0, 0, 0, 1, 0, 0 },
152 { 0, 0, 0, 1, 0, 0 },
153 { 0, 0, 0, 1, 0, 0 },
154 { 0, 0, 0, 1, 0, 0 },
155 { 0, 0, 0, 1, 0, 0 },
156 { 0, 0, 0, 1, 0, 0 },
157 { 0, 0, 0, 1, 0, 0 },
158 { 0, 0, 0, 1, 0, 0 },
159 { 0, 0, 0, 1, 0, 0 },
160 { 0, 1, 0, 0, 0, 0 },
161 { 0, 1, 0, 1, 0, 0 },
162 { 0, 1, 1, 0, 1, 0 },
163 { 0, 0, 0, 1, 0, 0 },
164 { 0, 0, 0, 0, 0, 0 },
165 { 0, 0, 0, 0, 0, 0 },
166 { 0, 0, 0, 0, 0, 0 },
167 { 0, 0, 0, 0, 0, 0 },
168 { 0, 1, 0, 1, 0, 0 },
169 { 0, 1, 0, 0, 0, 0 },
170 { 0, 0, 0, 1, 0, 1 },
171 { 0, 0, 0, 1, 0, 1 },
172 { 0, 0, 0, 1, 0, 1 },
173 { 0, 0, 0, 1, 0, 1 },
174 { 0, 0, 0, 0, 0, 0 },
175 { 0, 0, 0, 0, 0, 0 },
176 { 0, 0, 0, 0, 0, 0 },
177 { 0, 0, 0, 0, 0, 0 }
178 }
179};
180
181int checkboard (void)
182{
183 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
184 char buf[32];
185
186
187 uint pci_slot = get_pci_slot ();
188
189 uint pci_dual = get_pci_dual ();
190 uint pci1_32 = gur->pordevsr & 0x10000;
191 uint pci1_clk_sel = gur->porpllsr & 0x8000;
192 uint pci2_clk_sel = gur->porpllsr & 0x4000;
193
194 uint pci1_speed = get_clock_freq ();
195
196 uint cpu_board_rev = get_cpu_board_revision ();
197
198 printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
199 get_board_version (), pci_slot);
200
201 printf ("CPU Board Revision %d.%d (0x%04x)\n",
202 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
203 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
204
205 printf("PCI1: %d bit, %s MHz, %s\n",
206 (pci1_32) ? 32 : 64,
207 strmhz(buf, pci1_speed),
208 pci1_clk_sel ? "sync" : "async");
209
210 if (pci_dual) {
211 printf("PCI2: 32 bit, 66 MHz, %s\n",
212 pci2_clk_sel ? "sync" : "async");
213 } else {
214 printf("PCI2: disabled\n");
215 }
216
217
218
219
220 local_bus_init ();
221
222 return 0;
223}
224
225
226
227
228void
229local_bus_init(void)
230{
231 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
232 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
233
234 uint clkdiv;
235 uint lbc_hz;
236 sys_info_t sysinfo;
237 uint temp_lbcdll;
238
239
240
241
242
243
244
245
246
247
248 get_sys_info(&sysinfo);
249 clkdiv = lbc->lcrr & LCRR_CLKDIV;
250 lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv;
251
252 if (lbc_hz < 66) {
253 lbc->lcrr |= LCRR_DBYP;
254
255 } else if (lbc_hz >= 133) {
256 lbc->lcrr &= (~LCRR_DBYP);
257
258 } else {
259 lbc->lcrr &= (~LCRR_DBYP);
260 udelay(200);
261
262
263
264
265
266 temp_lbcdll = gur->lbcdllcr;
267 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
268 asm("sync;isync;msync");
269 }
270}
271
272
273
274
275void lbc_sdram_init(void)
276{
277#if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
278
279 uint idx;
280 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
281 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
282 uint cpu_board_rev;
283 uint lsdmr_common;
284
285 puts("LBC SDRAM: ");
286 print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
287 "\n ");
288
289
290
291
292 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
293 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
294 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
295 asm("msync");
296
297 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
298 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
299 asm("msync");
300
301
302
303
304 cpu_board_rev = get_cpu_board_revision();
305 lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
306 if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) {
307 lsdmr_common |= LSDMR_BSMA1617;
308 } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) {
309 lsdmr_common |= LSDMR_BSMA1516;
310 } else {
311
312
313
314
315 lsdmr_common |= LSDMR_BSMA1617;
316 }
317
318
319
320
321 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
322 asm("sync;msync");
323 *sdram_addr = 0xff;
324 ppcDcbf((unsigned long) sdram_addr);
325 udelay(100);
326
327
328
329
330 for (idx = 0; idx < 8; idx++) {
331 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
332 asm("sync;msync");
333 *sdram_addr = 0xff;
334 ppcDcbf((unsigned long) sdram_addr);
335 udelay(100);
336 }
337
338
339
340
341 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
342 asm("sync;msync");
343 *sdram_addr = 0xff;
344 ppcDcbf((unsigned long) sdram_addr);
345 udelay(100);
346
347
348
349
350 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
351 asm("sync;msync");
352 *sdram_addr = 0xff;
353 ppcDcbf((unsigned long) sdram_addr);
354 udelay(200);
355
356#endif
357}
358
359#ifdef CONFIG_PCI
360
361
362
363void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
364
365static struct pci_config_table pci_mpc85xxcds_config_table[] = {
366 {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
367 {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
368 {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
369 mpc85xx_config_via_usbide, {0,0,0}},
370 {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
371 mpc85xx_config_via_usb, {0,0,0}},
372 {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
373 mpc85xx_config_via_usb2, {0,0,0}},
374 {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
375 mpc85xx_config_via_power, {0,0,0}},
376 {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
377 mpc85xx_config_via_ac97, {0,0,0}},
378 {},
379};
380
381
382static struct pci_controller hose[] = {
383 {
384 config_table: pci_mpc85xxcds_config_table,
385 },
386#ifdef CONFIG_MPC85XX_PCI2
387 {},
388#endif
389};
390
391#endif
392
393void
394pci_init_board(void)
395{
396#ifdef CONFIG_PCI
397 pci_mpc85xx_init(hose);
398#endif
399}
400
401#if defined(CONFIG_OF_BOARD_SETUP)
402void
403ft_pci_setup(void *blob, bd_t *bd)
404{
405 int node, tmp[2];
406 const char *path;
407
408 node = fdt_path_offset(blob, "/aliases");
409 tmp[0] = 0;
410 if (node >= 0) {
411#ifdef CONFIG_PCI1
412 path = fdt_getprop(blob, node, "pci0", NULL);
413 if (path) {
414 tmp[1] = hose[0].last_busno - hose[0].first_busno;
415 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
416 }
417#endif
418#ifdef CONFIG_MPC85XX_PCI2
419 path = fdt_getprop(blob, node, "pci1", NULL);
420 if (path) {
421 tmp[1] = hose[1].last_busno - hose[1].first_busno;
422 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
423 }
424#endif
425 }
426}
427#endif
428