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