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
36
37
38
39#include <common.h>
40#include <ioports.h>
41#include <mpc8260.h>
42#include <asm/m8260_pci.h>
43#include <i2c.h>
44#include <spd.h>
45#include <miiphy.h>
46#ifdef CONFIG_PCI
47#include <pci.h>
48#endif
49#ifdef CONFIG_OF_LIBFDT
50#include <libfdt.h>
51#include <fdt_support.h>
52#endif
53
54
55
56
57
58
59
60
61#define CONFIG_SYS_FCC1 (CONFIG_ETHER_INDEX == 1)
62#define CONFIG_SYS_FCC2 (CONFIG_ETHER_INDEX == 2)
63#define CONFIG_SYS_FCC3 (CONFIG_ETHER_INDEX == 3)
64
65const iop_conf_t iop_conf_tab[4][32] = {
66
67
68 {
69 { CONFIG_SYS_FCC1, 1, 1, 0, 0, 0 },
70 { CONFIG_SYS_FCC1, 1, 1, 0, 0, 0 },
71 { CONFIG_SYS_FCC1, 1, 1, 1, 0, 0 },
72 { CONFIG_SYS_FCC1, 1, 1, 1, 0, 0 },
73 { CONFIG_SYS_FCC1, 1, 1, 0, 0, 0 },
74 { CONFIG_SYS_FCC1, 1, 1, 0, 0, 0 },
75 { 0, 0, 0, 0, 0, 0 },
76 { 0, 0, 0, 0, 0, 0 },
77 { 0, 0, 0, 0, 0, 0 },
78 { 0, 0, 0, 0, 0, 0 },
79 { CONFIG_SYS_FCC1, 1, 0, 1, 0, 0 },
80 { CONFIG_SYS_FCC1, 1, 0, 1, 0, 0 },
81 { CONFIG_SYS_FCC1, 1, 0, 1, 0, 0 },
82 { CONFIG_SYS_FCC1, 1, 0, 1, 0, 0 },
83 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
84 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
85 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
86 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
87 { 0, 0, 0, 0, 0, 0 },
88 { 0, 0, 0, 0, 0, 0 },
89 { 0, 0, 0, 0, 0, 0 },
90 { 0, 0, 0, 0, 0, 0 },
91 { 0, 0, 0, 0, 0, 0 },
92 { 0, 0, 0, 0, 0, 0 },
93 { 0, 0, 0, 1, 0, 0 },
94 { 0, 0, 0, 0, 0, 0 },
95 { 0, 0, 0, 1, 0, 0 },
96 { 0, 0, 0, 1, 0, 0 },
97 { 0, 0, 0, 1, 0, 0 },
98 { 0, 0, 0, 1, 0, 0 },
99 { 0, 0, 0, 0, 0, 0 },
100 { 0, 0, 0, 1, 0, 0 }
101 },
102
103
104 {
105 { CONFIG_SYS_FCC2, 1, 0, 1, 0, 0 },
106 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
107 { CONFIG_SYS_FCC2, 1, 1, 1, 0, 0 },
108 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
109 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
110 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
111 { CONFIG_SYS_FCC2, 1, 0, 1, 0, 0 },
112 { CONFIG_SYS_FCC2, 1, 0, 1, 0, 0 },
113 { CONFIG_SYS_FCC2, 1, 0, 1, 0, 0 },
114 { CONFIG_SYS_FCC2, 1, 0, 1, 0, 0 },
115 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
116 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
117 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
118 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
119 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
120 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
121 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
122 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
123 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
124 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
125 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
126 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
127 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
128 { CONFIG_SYS_FCC3, 1, 0, 0, 0, 0 },
129 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
130 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
131 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
132 { CONFIG_SYS_FCC3, 1, 0, 1, 0, 0 },
133 { 0, 0, 0, 0, 0, 0 },
134 { 0, 0, 0, 0, 0, 0 },
135 { 0, 0, 0, 0, 0, 0 },
136 { 0, 0, 0, 0, 0, 0 }
137 },
138
139
140 {
141 { 0, 0, 0, 0, 0, 0 },
142 { 0, 0, 0, 0, 0, 0 },
143 { 0, 0, 0, 0, 0, 0 },
144 { 0, 0, 0, 0, 0, 0 },
145 { 0, 0, 0, 0, 0, 0 },
146 { 0, 0, 0, 0, 0, 0 },
147 { 0, 0, 0, 0, 0, 0 },
148 { 0, 0, 0, 0, 0, 0 },
149 { 0, 0, 0, 0, 0, 0 },
150 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
151 { CONFIG_SYS_FCC1, 1, 0, 0, 0, 0 },
152 { 0, 0, 0, 0, 0, 0 },
153#if CONFIG_ADSTYPE == CONFIG_SYS_8272ADS
154 { 1, 0, 0, 1, 0, 0 },
155 { 1, 0, 0, 0, 0, 0 },
156 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
157 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
158#else
159 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
160 { CONFIG_SYS_FCC2, 1, 0, 0, 0, 0 },
161 { 0, 0, 0, 0, 0, 0 },
162 { 0, 0, 0, 0, 0, 0 },
163#endif
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, 0, 0, 0, 0, 0 },
169#if CONFIG_ADSTYPE == CONFIG_SYS_8272ADS
170 { 0, 0, 0, 0, 0, 0 },
171 { 0, 0, 0, 0, 0, 0 },
172#else
173 { 1, 0, 0, 1, 0, 0 },
174 { 1, 0, 0, 0, 0, 0 },
175#endif
176 { 0, 0, 0, 0, 0, 0 },
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 { 0, 0, 0, 0, 0, 0 },
182 { 0, 0, 0, 0, 0, 0 },
183 { 0, 0, 0, 0, 0, 0 },
184 { 0, 0, 0, 0, 0, 0 },
185 },
186
187
188 {
189 { 1, 1, 0, 0, 0, 0 },
190 { 1, 1, 1, 1, 0, 0 },
191 { 0, 0, 0, 0, 0, 0 },
192 { 0, 1, 0, 0, 0, 0 },
193 { 0, 1, 1, 1, 0, 0 },
194 { 0, 0, 0, 1, 0, 0 },
195 { 0, 0, 0, 1, 0, 0 },
196 { 0, 0, 0, 1, 0, 0 },
197 { 0, 0, 0, 1, 0, 0 },
198 { 0, 0, 0, 1, 0, 0 },
199 { 0, 0, 0, 1, 0, 0 },
200 { 0, 0, 0, 1, 0, 0 },
201 { 0, 0, 0, 1, 0, 0 },
202 { 0, 0, 0, 1, 0, 0 },
203 { 0, 1, 0, 0, 0, 0 },
204 { 0, 1, 0, 1, 0, 0 },
205 { 1, 1, 1, 0, 1, 0 },
206 { 1, 1, 1, 0, 1, 0 },
207 { 0, 0, 0, 0, 0, 0 },
208 { 0, 0, 0, 0, 0, 0 },
209 { 0, 0, 0, 0, 0, 0 },
210 { 0, 0, 0, 0, 0, 0 },
211 { 0, 1, 0, 1, 0, 0 },
212 { 0, 1, 0, 0, 0, 0 },
213 { 0, 0, 0, 1, 0, 1 },
214 { 0, 0, 0, 1, 0, 1 },
215 { 0, 0, 0, 1, 0, 1 },
216 { 0, 0, 0, 1, 0, 1 },
217 { 0, 0, 0, 0, 0, 0 },
218 { 0, 0, 0, 0, 0, 0 },
219 { 0, 0, 0, 0, 0, 0 },
220 { 0, 0, 0, 0, 0, 0 }
221 }
222};
223
224void reset_phy (void)
225{
226 vu_long *bcsr = (vu_long *)CONFIG_SYS_BCSR;
227
228
229#if CONFIG_SYS_PHY_ADDR == 0
230 bcsr[1] &= ~(FETHIEN1 | FETH1_RST);
231 udelay(2);
232 bcsr[1] |= FETH1_RST;
233#else
234 bcsr[3] &= ~(FETHIEN2 | FETH2_RST);
235 udelay(2);
236 bcsr[3] |= FETH2_RST;
237#endif
238 udelay(1000);
239#ifdef CONFIG_MII
240#if CONFIG_ADSTYPE >= CONFIG_SYS_PQ2FADS
241
242
243
244
245 bb_miiphy_write(NULL, CONFIG_SYS_PHY_ADDR, 16, 0x610);
246 bb_miiphy_write(NULL, CONFIG_SYS_PHY_ADDR, MII_BMCR,
247 BMCR_ANENABLE | BMCR_ANRESTART);
248#else
249
250
251
252
253
254
255
256
257 bb_miiphy_write(NULL, CONFIG_SYS_PHY_ADDR, MII_ADVERTISE, 0x01E1);
258
259
260 bb_miiphy_write(NULL, CONFIG_SYS_PHY_ADDR, MII_FCSCOUNTER, 0x0000);
261
262 bb_miiphy_write(NULL, CONFIG_SYS_PHY_ADDR, MII_BMCR,
263 BMCR_ANENABLE | BMCR_ANRESTART);
264#endif
265#endif
266}
267
268#ifdef CONFIG_PCI
269typedef struct pci_ic_s {
270 unsigned long pci_int_stat;
271 unsigned long pci_int_mask;
272}pci_ic_t;
273#endif
274
275int board_early_init_f (void)
276{
277 vu_long *bcsr = (vu_long *)CONFIG_SYS_BCSR;
278
279#ifdef CONFIG_PCI
280 volatile pci_ic_t* pci_ic = (pci_ic_t *) CONFIG_SYS_PCI_INT;
281
282
283 pci_ic->pci_int_mask |= 0xfff00000;
284#endif
285#if (CONFIG_CONS_INDEX == 1) || (CONFIG_KGDB_INDEX == 1)
286 bcsr[1] &= ~RS232EN_1;
287#endif
288#if (CONFIG_CONS_INDEX > 1) || (CONFIG_KGDB_INDEX > 1)
289 bcsr[1] &= ~RS232EN_2;
290#endif
291
292#if CONFIG_ADSTYPE != CONFIG_SYS_8260ADS
293#if CONFIG_ADSTYPE == CONFIG_SYS_PQ2FADS
294 if ((bcsr[3] & BCSR_PCI_MODE) == 0)
295#endif
296 {
297 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
298
299 immap->im_clkrst.car_sccr |= M826X_SCCR_PCI_MODE_EN;
300 immap->im_siu_conf.sc_siumcr =
301 (immap->im_siu_conf.sc_siumcr & ~SIUMCR_LBPC11)
302 | SIUMCR_LBPC01;
303 }
304#endif
305
306 return 0;
307}
308
309#define ns2clk(ns) (ns / (1000000000 / CONFIG_8260_CLKIN) + 1)
310
311phys_size_t initdram (int board_type)
312{
313#if CONFIG_ADSTYPE == CONFIG_SYS_PQ2FADS
314 long int msize = 32;
315#elif CONFIG_ADSTYPE == CONFIG_SYS_8272ADS
316 long int msize = 64;
317#else
318 long int msize = 16;
319#endif
320
321#ifndef CONFIG_SYS_RAMBOOT
322 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
323 volatile memctl8260_t *memctl = &immap->im_memctl;
324 volatile uchar *ramaddr, c = 0xff;
325 uint or;
326 uint psdmr;
327 uint psrt;
328
329 int i;
330
331 immap->im_siu_conf.sc_ppc_acr = 0x00000002;
332 immap->im_siu_conf.sc_ppc_alrh = 0x01267893;
333 immap->im_siu_conf.sc_tescr1 = 0x00004000;
334
335 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
336#ifdef CONFIG_SYS_LSDRAM_BASE
337
338
339
340
341
342 if ((immap->im_siu_conf.sc_siumcr & SIUMCR_LBPC11) == SIUMCR_LBPC00) {
343 memctl->memc_lsrt = CONFIG_SYS_LSRT;
344#if CONFIG_ADSTYPE == CONFIG_SYS_PQ2FADS
345 memctl->memc_or3 = 0xFF803280;
346 memctl->memc_br3 = CONFIG_SYS_LSDRAM_BASE | 0x00001861;
347#else
348 memctl->memc_or4 = 0xFFC01480;
349 memctl->memc_br4 = CONFIG_SYS_LSDRAM_BASE | 0x00001861;
350#endif
351 memctl->memc_lsdmr = CONFIG_SYS_LSDMR | 0x28000000;
352 ramaddr = (uchar *) CONFIG_SYS_LSDRAM_BASE;
353 *ramaddr = c;
354 memctl->memc_lsdmr = CONFIG_SYS_LSDMR | 0x08000000;
355 for (i = 0; i < 8; i++)
356 *ramaddr = c;
357 memctl->memc_lsdmr = CONFIG_SYS_LSDMR | 0x18000000;
358 *ramaddr = c;
359 memctl->memc_lsdmr = CONFIG_SYS_LSDMR | 0x40000000;
360 }
361#endif
362
363
364#ifdef CONFIG_SPD_EEPROM
365 {
366 spd_eeprom_t spd;
367 uint pbi, bsel, rowst, lsb, tmp;
368
369 i2c_read (CONFIG_SPD_ADDR, 0, 1, (uchar *) & spd, sizeof (spd));
370
371
372
373
374 pbi = (spd.row_dens > 32) ? 1 : CONFIG_SDRAM_PBI;
375 msize = spd.nrows * (4 * spd.row_dens);
376 or = ~(msize - 1) << 20;
377 switch (spd.nbanks) {
378 case 2:
379 bsel = 1;
380 break;
381 case 4:
382 bsel = 2;
383 or |= 0x00002000;
384 break;
385 case 8:
386 bsel = 3;
387 or |= 0x00004000;
388 break;
389 }
390 lsb = 3;
391
392 if (pbi) {
393 rowst = 32 - (spd.nrow_addr + spd.ncol_addr + bsel + lsb);
394 or |= (rowst << 9);
395 } else {
396 rowst = 32 - (spd.nrow_addr + spd.ncol_addr + lsb);
397 or |= ((rowst * 2 - 12) << 9);
398 }
399 or |= ((spd.nrow_addr - 9) << 6);
400
401 psdmr = (pbi << 31);
402
403 tmp = 32 - (lsb + spd.nrow_addr);
404 psdmr |= ((tmp - (rowst - 5) - 13) << 24);
405 psdmr |= ((tmp - 3 - 12) << 21);
406
407 tmp = (31 - lsb - 10) - tmp;
408
409
410
411
412 if (pbi)
413 psdmr |= ((10 - (rowst + tmp)) << 18);
414 else
415 psdmr |= ((12 - (rowst + tmp)) << 18);
416
417
418 tmp = ns2clk (70);
419 switch (tmp) {
420 case 1:
421 case 2:
422 psdmr |= (1 << 15);
423 break;
424 case 3:
425 case 4:
426 case 5:
427 case 6:
428 case 7:
429 case 8:
430 psdmr |= ((tmp - 2) << 15);
431 break;
432 default:
433 psdmr |= (7 << 15);
434 }
435 psdmr |= (ns2clk (spd.trp) % 8 << 12);
436 psdmr |= (ns2clk (spd.trcd) % 8 << 9);
437
438
439 for (i = 0, tmp = spd.write_lat; (i < 4) && ((tmp & 1) == 0); i++)
440 tmp >>= 1;
441 switch (i) {
442 case 0:
443 case 1:
444 psdmr |= (1 << 4);
445 break;
446 case 2:
447 case 3:
448 psdmr |= (i << 4);
449 break;
450 }
451
452
453 for (i = 1, tmp = spd.cas_lat; (i < 3) && ((tmp & 1) == 0); i++)
454 tmp >>= 1;
455 psdmr |= i;
456
457 switch (spd.refresh & 0x7F) {
458 case 1:
459 tmp = 3900;
460 break;
461 case 2:
462 tmp = 7800;
463 break;
464 case 3:
465 tmp = 31300;
466 break;
467 case 4:
468 tmp = 62500;
469 break;
470 case 5:
471 tmp = 125000;
472 break;
473 default:
474 tmp = 15625;
475 }
476 psrt = tmp / (1000000000 / CONFIG_8260_CLKIN *
477 ((memctl->memc_mptpr >> 8) + 1)) - 1;
478#ifdef SPD_DEBUG
479 printf ("\nDIMM type: %-18.18s\n", spd.mpart);
480 printf ("SPD size: %d\n", spd.info_size);
481 printf ("EEPROM size: %d\n", 1 << spd.chip_size);
482 printf ("Memory type: %d\n", spd.mem_type);
483 printf ("Row addr: %d\n", spd.nrow_addr);
484 printf ("Column addr: %d\n", spd.ncol_addr);
485 printf ("# of rows: %d\n", spd.nrows);
486 printf ("Row density: %d\n", spd.row_dens);
487 printf ("# of banks: %d\n", spd.nbanks);
488 printf ("Data width: %d\n",
489 256 * spd.dataw_msb + spd.dataw_lsb);
490 printf ("Chip width: %d\n", spd.primw);
491 printf ("Refresh rate: %02X\n", spd.refresh);
492 printf ("CAS latencies: %02X\n", spd.cas_lat);
493 printf ("Write latencies: %02X\n", spd.write_lat);
494 printf ("tRP: %d\n", spd.trp);
495 printf ("tRCD: %d\n", spd.trcd);
496
497 printf ("OR=%X, PSDMR=%08X, PSRT=%0X\n", or, psdmr, psrt);
498#endif
499 }
500#else
501 or = CONFIG_SYS_OR2;
502 psdmr = CONFIG_SYS_PSDMR;
503 psrt = CONFIG_SYS_PSRT;
504#endif
505 memctl->memc_psrt = psrt;
506 memctl->memc_or2 = or;
507 memctl->memc_br2 = CONFIG_SYS_SDRAM_BASE | 0x00000041;
508 ramaddr = (uchar *) CONFIG_SYS_SDRAM_BASE;
509 memctl->memc_psdmr = psdmr | 0x28000000;
510 *ramaddr = c;
511 memctl->memc_psdmr = psdmr | 0x08000000;
512 for (i = 0; i < 8; i++)
513 *ramaddr = c;
514
515 memctl->memc_psdmr = psdmr | 0x18000000;
516 *ramaddr = c;
517 memctl->memc_psdmr = psdmr | 0x40000000;
518 *ramaddr = c;
519#endif
520
521
522 return (msize * 1024 * 1024);
523}
524
525int checkboard (void)
526{
527#if CONFIG_ADSTYPE == CONFIG_SYS_8260ADS
528 puts ("Board: Motorola MPC8260ADS\n");
529#elif CONFIG_ADSTYPE == CONFIG_SYS_8266ADS
530 puts ("Board: Motorola MPC8266ADS\n");
531#elif CONFIG_ADSTYPE == CONFIG_SYS_PQ2FADS
532 puts ("Board: Motorola PQ2FADS-ZU\n");
533#elif CONFIG_ADSTYPE == CONFIG_SYS_8272ADS
534 puts ("Board: Motorola MPC8272ADS\n");
535#else
536 puts ("Board: unknown\n");
537#endif
538 return 0;
539}
540
541#ifdef CONFIG_PCI
542struct pci_controller hose;
543
544extern void pci_mpc8250_init(struct pci_controller *);
545
546void pci_init_board(void)
547{
548 pci_mpc8250_init(&hose);
549}
550#endif
551
552#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
553void ft_board_setup(void *blob, bd_t *bd)
554{
555 ft_cpu_setup(blob, bd);
556#ifdef CONFIG_PCI
557 ft_pci_setup(blob, bd);
558#endif
559}
560#endif
561