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