1 /* Board specific functions for those embedded 8xx boards that do
2 * not have boot monitor support for board information.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 */
9
10 #include <linux/types.h>
11 #include <linux/config.h>
12 #ifdef CONFIG_8xx
13 #include <asm/mpc8xx.h>
14 #endif
15 #ifdef CONFIG_8260
16 #include <asm/mpc8260.h>
17 #include <asm/immap_cpm2.h>
18 #endif
19 #ifdef CONFIG_4xx
20 #include <asm/io.h>
21 #endif
22 #if defined(CONFIG_405GP) || defined(CONFIG_NP405H) || defined(CONFIG_NP405L)
23 #include <linux/netdevice.h>
24 #endif
25 extern unsigned long timebase_period_ns;
26
27 /* For those boards that don't provide one.
28 */
29 #if !defined(CONFIG_MBX)
30 static bd_t bdinfo;
31 #endif
32
33 /* IIC functions.
34 * These are just the basic master read/write operations so we can
35 * examine serial EEPROM.
36 */
37 extern void iic_read(uint devaddr, u_char *buf, uint offset, uint count);
38
39 /* Supply a default Ethernet address for those eval boards that don't
40 * ship with one. This is an address from the MBX board I have, so
41 * it is unlikely you will find it on your network.
42 */
43 static ushort def_enet_addr[] = { 0x0800, 0x3e26, 0x1559 };
44
45 #if defined(CONFIG_MBX)
46
47 /* The MBX hands us a pretty much ready to go board descriptor. This
48 * is where the idea started in the first place.
49 */
50 void
embed_config(bd_t ** bdp)51 embed_config(bd_t **bdp)
52 {
53 u_char *mp;
54 u_char eebuf[128];
55 int i = 8;
56 bd_t *bd;
57
58 bd = *bdp;
59
60 /* Read the first 128 bytes of the EEPROM. There is more,
61 * but this is all we need.
62 */
63 iic_read(0xa4, eebuf, 0, 128);
64
65 /* All we are looking for is the Ethernet MAC address. The
66 * first 8 bytes are 'MOTOROLA', so check for part of that.
67 * Next, the VPD describes a MAC 'packet' as being of type 08
68 * and size 06. So we look for that and the MAC must follow.
69 * If there are more than one, we still only care about the first.
70 * If it's there, assume we have a valid MAC address. If not,
71 * grab our default one.
72 */
73 if ((*(uint *)eebuf) == 0x4d4f544f) {
74 while (i < 127 && !(eebuf[i] == 0x08 && eebuf[i + 1] == 0x06))
75 i += eebuf[i + 1] + 2; /* skip this packet */
76
77 if (i == 127) /* Couldn't find. */
78 mp = (u_char *)def_enet_addr;
79 else
80 mp = &eebuf[i + 2];
81 }
82 else
83 mp = (u_char *)def_enet_addr;
84
85 for (i=0; i<6; i++)
86 bd->bi_enetaddr[i] = *mp++;
87
88 /* The boot rom passes these to us in MHz. Linux now expects
89 * them to be in Hz.
90 */
91 bd->bi_intfreq *= 1000000;
92 bd->bi_busfreq *= 1000000;
93
94 /* Stuff a baud rate here as well.
95 */
96 bd->bi_baudrate = 9600;
97 }
98 #endif /* CONFIG_MBX */
99
100 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || \
101 defined(CONFIG_RPX6) || defined(CONFIG_EP405)
102 /* Helper functions for Embedded Planet boards.
103 */
104 /* Because I didn't find anything that would do this.......
105 */
106 u_char
aschex_to_byte(u_char * cp)107 aschex_to_byte(u_char *cp)
108 {
109 u_char byte, c;
110
111 c = *cp++;
112
113 if ((c >= 'A') && (c <= 'F')) {
114 c -= 'A';
115 c += 10;
116 } else if ((c >= 'a') && (c <= 'f')) {
117 c -= 'a';
118 c += 10;
119 } else
120 c -= '0';
121
122 byte = c * 16;
123
124 c = *cp;
125
126 if ((c >= 'A') && (c <= 'F')) {
127 c -= 'A';
128 c += 10;
129 } else if ((c >= 'a') && (c <= 'f')) {
130 c -= 'a';
131 c += 10;
132 } else
133 c -= '0';
134
135 byte += c;
136
137 return(byte);
138 }
139
140 static void
rpx_eth(bd_t * bd,u_char * cp)141 rpx_eth(bd_t *bd, u_char *cp)
142 {
143 int i;
144
145 for (i=0; i<6; i++) {
146 bd->bi_enetaddr[i] = aschex_to_byte(cp);
147 cp += 2;
148 }
149 }
150
151 #ifdef CONFIG_RPX6
152 static uint
rpx_baseten(u_char * cp)153 rpx_baseten(u_char *cp)
154 {
155 uint retval;
156
157 retval = 0;
158
159 while (*cp != '\n') {
160 retval *= 10;
161 retval += (*cp) - '0';
162 cp++;
163 }
164 return(retval);
165 }
166 #endif
167
168 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
169 static void
rpx_brate(bd_t * bd,u_char * cp)170 rpx_brate(bd_t *bd, u_char *cp)
171 {
172 uint rate;
173
174 rate = 0;
175
176 while (*cp != '\n') {
177 rate *= 10;
178 rate += (*cp) - '0';
179 cp++;
180 }
181
182 bd->bi_baudrate = rate * 100;
183 }
184
185 static void
rpx_cpuspeed(bd_t * bd,u_char * cp)186 rpx_cpuspeed(bd_t *bd, u_char *cp)
187 {
188 uint num, den;
189
190 num = den = 0;
191
192 while (*cp != '\n') {
193 num *= 10;
194 num += (*cp) - '0';
195 cp++;
196 if (*cp == '/') {
197 cp++;
198 den = (*cp) - '0';
199 break;
200 }
201 }
202
203 /* I don't know why the RPX just can't state the actual
204 * CPU speed.....
205 */
206 if (den) {
207 num /= den;
208 num *= den;
209 }
210 bd->bi_intfreq = bd->bi_busfreq = num * 1000000;
211
212 /* The 8xx can only run a maximum 50 MHz bus speed (until
213 * Motorola changes this :-). Greater than 50 MHz parts
214 * run internal/2 for bus speed.
215 */
216 if (num > 50)
217 bd->bi_busfreq /= 2;
218 }
219 #endif
220
221 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_EP405)
222 static void
rpx_memsize(bd_t * bd,u_char * cp)223 rpx_memsize(bd_t *bd, u_char *cp)
224 {
225 uint size;
226
227 size = 0;
228
229 while (*cp != '\n') {
230 size *= 10;
231 size += (*cp) - '0';
232 cp++;
233 }
234
235 bd->bi_memsize = size * 1024 * 1024;
236 }
237 #endif /* LITE || CLASSIC || EP405 */
238
239 #endif /* Embedded Planet boards */
240
241 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
242
243 /* Read the EEPROM on the RPX-Lite board.
244 */
245 void
embed_config(bd_t ** bdp)246 embed_config(bd_t **bdp)
247 {
248 u_char eebuf[256], *cp;
249 bd_t *bd;
250
251 /* Read the first 256 bytes of the EEPROM. I think this
252 * is really all there is, and I hope if it gets bigger the
253 * info we want is still up front.
254 */
255 bd = &bdinfo;
256 *bdp = bd;
257
258 #if 1
259 iic_read(0xa8, eebuf, 0, 128);
260 iic_read(0xa8, &eebuf[128], 128, 128);
261
262 /* We look for two things, the Ethernet address and the
263 * serial baud rate. The records are separated by
264 * newlines.
265 */
266 cp = eebuf;
267 for (;;) {
268 if (*cp == 'E') {
269 cp++;
270 if (*cp == 'A') {
271 cp += 2;
272 rpx_eth(bd, cp);
273 }
274 }
275 if (*cp == 'S') {
276 cp++;
277 if (*cp == 'B') {
278 cp += 2;
279 rpx_brate(bd, cp);
280 }
281 }
282 if (*cp == 'D') {
283 cp++;
284 if (*cp == '1') {
285 cp += 2;
286 rpx_memsize(bd, cp);
287 }
288 }
289 if (*cp == 'H') {
290 cp++;
291 if (*cp == 'Z') {
292 cp += 2;
293 rpx_cpuspeed(bd, cp);
294 }
295 }
296
297 /* Scan to the end of the record.
298 */
299 while ((*cp != '\n') && (*cp != 0xff))
300 cp++;
301
302 /* If the next character is a 0 or ff, we are done.
303 */
304 cp++;
305 if ((*cp == 0) || (*cp == 0xff))
306 break;
307 }
308 bd->bi_memstart = 0;
309 #else
310 /* For boards without initialized EEPROM.
311 */
312 bd->bi_memstart = 0;
313 bd->bi_memsize = (8 * 1024 * 1024);
314 bd->bi_intfreq = 48000000;
315 bd->bi_busfreq = 48000000;
316 bd->bi_baudrate = 9600;
317 #endif
318 }
319 #endif /* RPXLITE || RPXCLASSIC */
320
321 #ifdef CONFIG_BSEIP
322 /* Build a board information structure for the BSE ip-Engine.
323 * There is more to come since we will add some environment
324 * variables and a function to read them.
325 */
326 void
embed_config(bd_t ** bdp)327 embed_config(bd_t **bdp)
328 {
329 u_char *cp;
330 int i;
331 bd_t *bd;
332
333 bd = &bdinfo;
334 *bdp = bd;
335
336 /* Baud rate and processor speed will eventually come
337 * from the environment variables.
338 */
339 bd->bi_baudrate = 9600;
340
341 /* Get the Ethernet station address from the Flash ROM.
342 */
343 cp = (u_char *)0xfe003ffa;
344 for (i=0; i<6; i++) {
345 bd->bi_enetaddr[i] = *cp++;
346 }
347
348 /* The rest of this should come from the environment as well.
349 */
350 bd->bi_memstart = 0;
351 bd->bi_memsize = (16 * 1024 * 1024);
352 bd->bi_intfreq = 48000000;
353 bd->bi_busfreq = 48000000;
354 }
355 #endif /* BSEIP */
356
357 #ifdef CONFIG_FADS
358 /* Build a board information structure for the FADS.
359 */
360 void
embed_config(bd_t ** bdp)361 embed_config(bd_t **bdp)
362 {
363 u_char *cp;
364 int i;
365 bd_t *bd;
366
367 bd = &bdinfo;
368 *bdp = bd;
369
370 /* Just fill in some known values.
371 */
372 bd->bi_baudrate = 9600;
373
374 /* Use default enet.
375 */
376 cp = (u_char *)def_enet_addr;
377 for (i=0; i<6; i++) {
378 bd->bi_enetaddr[i] = *cp++;
379 }
380
381 bd->bi_memstart = 0;
382 bd->bi_memsize = (8 * 1024 * 1024);
383 bd->bi_intfreq = 48000000;
384 bd->bi_busfreq = 48000000;
385 }
386 #endif /* FADS */
387
388 #ifdef CONFIG_8260
389 /* Compute 8260 clock values if the rom doesn't provide them.
390 * We can't compute the internal core frequency (I don't know how to
391 * do that).
392 */
393 static void
clk_8260(bd_t * bd)394 clk_8260(bd_t *bd)
395 {
396 uint scmr, vco_out, clkin;
397 uint plldf, pllmf, busdf, cpmdf;
398 volatile cpm2_map_t *ip;
399
400 ip = (cpm2_map_t *)CPM_MAP_ADDR;
401 scmr = ip->im_clkrst.car_scmr;
402
403 /* The clkin is always bus frequency.
404 */
405 clkin = bd->bi_busfreq;
406
407 /* Collect the bits from the scmr.
408 */
409 plldf = (scmr >> 12) & 1;
410 pllmf = scmr & 0xfff;
411 cpmdf = (scmr >> 16) & 0x0f;
412 busdf = (scmr >> 20) & 0x0f;
413
414 /* This is arithmetic from the 8260 manual.
415 */
416 vco_out = clkin / (plldf + 1);
417 vco_out *= 2 * (pllmf + 1);
418 bd->bi_vco = vco_out; /* Save for later */
419
420 bd->bi_cpmfreq = vco_out / 2; /* CPM Freq, in MHz */
421
422 /* Set Baud rate divisor. The power up default is divide by 16,
423 * but we set it again here in case it was changed.
424 */
425 ip->im_clkrst.car_sccr = 1; /* DIV 16 BRG */
426 bd->bi_brgfreq = vco_out / 16;
427 }
428 #endif
429
430 #ifdef CONFIG_EST8260
431 void
embed_config(bd_t ** bdp)432 embed_config(bd_t **bdp)
433 {
434 u_char *cp;
435 int i;
436 bd_t *bd;
437
438 bd = *bdp;
439 #if 0
440 /* This is actually provided by my boot rom. I have it
441 * here for those people that may load the kernel with
442 * a JTAG/COP tool and not the rom monitor.
443 */
444 bd->bi_baudrate = 115200;
445 bd->bi_intfreq = 200000000;
446 bd->bi_busfreq = 66666666;
447 bd->bi_cpmfreq = 66666666;
448 bd->bi_brgfreq = 33333333;
449 bd->bi_memsize = 16 * 1024 * 1024;
450 #else
451 /* The boot rom passes these to us in MHz. Linux now expects
452 * them to be in Hz.
453 */
454 bd->bi_intfreq *= 1000000;
455 bd->bi_busfreq *= 1000000;
456 bd->bi_cpmfreq *= 1000000;
457 bd->bi_brgfreq *= 1000000;
458 #endif
459
460 cp = (u_char *)def_enet_addr;
461 for (i=0; i<6; i++) {
462 bd->bi_enetaddr[i] = *cp++;
463 }
464 }
465 #endif /* EST8260 */
466
467 #ifdef CONFIG_SBS8260
468 void
embed_config(bd_t ** bdp)469 embed_config(bd_t **bdp)
470 {
471 u_char *cp;
472 int i;
473 bd_t *bd;
474
475 /* This should provided by the boot rom.
476 */
477 bd = &bdinfo;
478 *bdp = bd;
479 bd->bi_baudrate = 9600;
480 bd->bi_memsize = 64 * 1024 * 1024;
481
482 /* Set all of the clocks. We have to know the speed of the
483 * external clock. The development board had 66 MHz.
484 */
485 bd->bi_busfreq = 66666666;
486 clk_8260(bd);
487
488 /* I don't know how to compute this yet.
489 */
490 bd->bi_intfreq = 133000000;
491
492
493 cp = (u_char *)def_enet_addr;
494 for (i=0; i<6; i++) {
495 bd->bi_enetaddr[i] = *cp++;
496 }
497 }
498 #endif /* SBS8260 */
499
500 #ifdef CONFIG_RPX6
501 void
embed_config(bd_t ** bdp)502 embed_config(bd_t **bdp)
503 {
504 u_char *cp, *keyvals;
505 bd_t *bd;
506
507 keyvals = (u_char *)*bdp;
508
509 bd = &bdinfo;
510 *bdp = bd;
511
512 /* This is almost identical to the RPX-Lite/Classic functions
513 * on the 8xx boards. It would be nice to have a key lookup
514 * function in a string, but the format of all of the fields
515 * is slightly different.
516 */
517 cp = keyvals;
518 for (;;) {
519 if (*cp == 'E') {
520 cp++;
521 if (*cp == 'A') {
522 cp += 2;
523 rpx_eth(bd, cp);
524 }
525 }
526 if (*cp == 'S') {
527 cp++;
528 if (*cp == 'B') {
529 cp += 2;
530 bd->bi_baudrate = rpx_baseten(cp);
531 }
532 }
533 if (*cp == 'D') {
534 cp++;
535 if (*cp == '1') {
536 cp += 2;
537 bd->bi_memsize = rpx_baseten(cp) * 1024 * 1024;
538 }
539 }
540 if (*cp == 'X') {
541 cp++;
542 if (*cp == 'T') {
543 cp += 2;
544 bd->bi_busfreq = rpx_baseten(cp);
545 }
546 }
547 if (*cp == 'N') {
548 cp++;
549 if (*cp == 'V') {
550 cp += 2;
551 bd->bi_nvsize = rpx_baseten(cp) * 1024 * 1024;
552 }
553 }
554
555 /* Scan to the end of the record.
556 */
557 while ((*cp != '\n') && (*cp != 0xff))
558 cp++;
559
560 /* If the next character is a 0 or ff, we are done.
561 */
562 cp++;
563 if ((*cp == 0) || (*cp == 0xff))
564 break;
565 }
566 bd->bi_memstart = 0;
567
568 /* The memory size includes both the 60x and local bus DRAM.
569 * I don't want to use the local bus DRAM for real memory,
570 * so subtract it out. It would be nice if they were separate
571 * keys.
572 */
573 bd->bi_memsize -= 32 * 1024 * 1024;
574
575 /* Set all of the clocks. We have to know the speed of the
576 * external clock.
577 */
578 clk_8260(bd);
579
580 /* I don't know how to compute this yet.
581 */
582 bd->bi_intfreq = 200000000;
583 }
584 #endif /* RPX6 */
585
586 #ifdef CONFIG_ADS8260
587 void
embed_config(bd_t ** bdp)588 embed_config(bd_t **bdp)
589 {
590 u_char *cp;
591 int i;
592 bd_t *bd;
593
594 /* This should provided by the boot rom.
595 */
596 bd = &bdinfo;
597 *bdp = bd;
598 bd->bi_baudrate = 9600;
599 bd->bi_memsize = 16 * 1024 * 1024;
600
601 /* Set all of the clocks. We have to know the speed of the
602 * external clock. The development board had 66 MHz.
603 */
604 bd->bi_busfreq = 66666666;
605 clk_8260(bd);
606
607 /* I don't know how to compute this yet.
608 */
609 bd->bi_intfreq = 200000000;
610
611
612 cp = (u_char *)def_enet_addr;
613 for (i=0; i<6; i++) {
614 bd->bi_enetaddr[i] = *cp++;
615 }
616 }
617 #endif /* ADS8260 */
618
619 #ifdef CONFIG_WILLOW
620 void
embed_config(bd_t ** bdp)621 embed_config(bd_t **bdp)
622 {
623 u_char *cp;
624 int i;
625 bd_t *bd;
626
627 /* Willow has Open Firmware....I should learn how to get this
628 * information from it.
629 */
630 bd = &bdinfo;
631 *bdp = bd;
632 bd->bi_baudrate = 9600;
633 bd->bi_memsize = 32 * 1024 * 1024;
634
635 /* Set all of the clocks. We have to know the speed of the
636 * external clock. The development board had 66 MHz.
637 */
638 bd->bi_busfreq = 66666666;
639 clk_8260(bd);
640
641 /* I don't know how to compute this yet.
642 */
643 bd->bi_intfreq = 200000000;
644
645
646 cp = (u_char *)def_enet_addr;
647 for (i=0; i<6; i++) {
648 bd->bi_enetaddr[i] = *cp++;
649 }
650 }
651 #endif /* WILLOW */
652
653 #ifdef CONFIG_IBM_OPENBIOS
654 /* This could possibly work for all treeboot roms.
655 */
656 #define BOARD_INFO_VECTOR 0xFFFE0B50
657
658 void
embed_config(bd_t ** bdp)659 embed_config(bd_t **bdp)
660 {
661 u_char *cp;
662 int i;
663 bd_t *bd, *treeboot_bd;
664 bd_t *(*get_board_info)(void) =
665 (bd_t *(*)(void))(*(unsigned long *)BOARD_INFO_VECTOR);
666 #if !defined(CONFIG_STB03xxx)
667 /* shut down the Ethernet controller that the boot rom
668 * sometimes leaves running.
669 */
670 mtdcr(DCRN_MALCR(DCRN_MAL_BASE), MALCR_MMSR); /* 1st reset MAL */
671 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE)) & MALCR_MMSR) {}; /* wait for the reset */
672 out_be32((u32 *)EMAC0_BASE, 0x20000000); /* then reset EMAC */
673 eieio();
674 #endif
675
676 bd = &bdinfo;
677 *bdp = bd;
678 if ((treeboot_bd = get_board_info()) != NULL) {
679 memcpy(bd, treeboot_bd, sizeof(bd_t));
680 }
681 else {
682 /* Hmmm...better try to stuff some defaults.
683 */
684 bd->bi_memsize = 16 * 1024 * 1024;
685 cp = (u_char *)def_enet_addr;
686 for (i=0; i<6; i++) {
687 /* I should probably put different ones here,
688 * hopefully only one is used.
689 */
690 bd->BD_EMAC_ADDR(0,i) = *cp;
691
692 #ifdef CONFIG_PCI
693 bd->bi_pci_enetaddr[i] = *cp++;
694 #endif
695 }
696 bd->bi_intfreq = 200000000;
697 bd->bi_busfreq = 100000000;
698 #ifdef CONFIG_PCI
699 bd->bi_pci_busfreq = 66666666;
700 #endif
701 /* Yeah, this look weird, but on Redwood 4 they are
702 * different object in the structure. When RW5 uses
703 * OpenBIOS, it requires a special value.
704 */
705 #ifdef CONFIG_REDWOOD_5
706 bd->bi_intfreq = 200 * 1000 * 1000;
707 bd->bi_busfreq = 0;
708
709 bd->bi_tbfreq = 27 * 1000 * 1000;
710 #elif CONFIG_REDWOOD_4
711 bd->bi_tbfreq = bd->bi_intfreq;
712 #endif
713 }
714 }
715 #endif
716
717 #ifdef CONFIG_EP405
718 void
embed_config(bd_t ** bdp)719 embed_config(bd_t **bdp)
720 {
721 u_char *cp;
722 bd_t *bd;
723
724 bd = &bdinfo;
725 *bdp = bd;
726 #if 1
727 cp = (u_char *)0xF0000EE0;
728 for (;;) {
729 if (*cp == 'E') {
730 cp++;
731 if (*cp == 'A') {
732 cp += 2;
733 rpx_eth(bd, cp);
734 }
735 }
736
737 if (*cp == 'D') {
738 cp++;
739 if (*cp == '1') {
740 cp += 2;
741 rpx_memsize(bd, cp);
742 }
743 }
744
745 while ((*cp != '\n') && (*cp != 0xff))
746 cp++;
747
748 cp++;
749 if ((*cp == 0) || (*cp == 0xff))
750 break;
751 }
752 bd->bi_intfreq = 200000000;
753 bd->bi_busfreq = 100000000;
754 bd->bi_pci_busfreq= 33000000 ;
755 #else
756
757 bd->bi_memsize = 64000000;
758 bd->bi_intfreq = 200000000;
759 bd->bi_busfreq = 100000000;
760 bd->bi_pci_busfreq= 33000000 ;
761 #endif
762 timebase_period_ns = 1000000000 / bd->bi_tbfreq;
763 }
764 #endif
765