1 /* Board specific functions for those embedded 8xx boards that do
2 * not have boot monitor support for board information.
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.
10 #include <linux/types.h>
11 #include <linux/string.h>
14 #include <asm/mpc8xx.h>
17 #include <asm/mpc8260.h>
18 #include <asm/immap_cpm2.h>
23 #ifdef CONFIG_XILINX_VIRTEX
24 #include <platforms/4xx/xparameters/xparameters.h>
26 extern unsigned long timebase_period_ns
;
28 /* For those boards that don't provide one.
30 #if !defined(CONFIG_MBX)
35 * These are just the basic master read/write operations so we can
36 * examine serial EEPROM.
38 extern void iic_read(uint devaddr
, u_char
*buf
, uint offset
, uint count
);
40 /* Supply a default Ethernet address for those eval boards that don't
41 * ship with one. This is an address from the MBX board I have, so
42 * it is unlikely you will find it on your network.
44 static ushort def_enet_addr
[] = { 0x0800, 0x3e26, 0x1559 };
46 #if defined(CONFIG_MBX)
48 /* The MBX hands us a pretty much ready to go board descriptor. This
49 * is where the idea started in the first place.
52 embed_config(bd_t
**bdp
)
61 /* Read the first 128 bytes of the EEPROM. There is more,
62 * but this is all we need.
64 iic_read(0xa4, eebuf
, 0, 128);
66 /* All we are looking for is the Ethernet MAC address. The
67 * first 8 bytes are 'MOTOROLA', so check for part of that.
68 * Next, the VPD describes a MAC 'packet' as being of type 08
69 * and size 06. So we look for that and the MAC must follow.
70 * If there are more than one, we still only care about the first.
71 * If it's there, assume we have a valid MAC address. If not,
72 * grab our default one.
74 if ((*(uint
*)eebuf
) == 0x4d4f544f) {
75 while (i
< 127 && !(eebuf
[i
] == 0x08 && eebuf
[i
+ 1] == 0x06))
76 i
+= eebuf
[i
+ 1] + 2; /* skip this packet */
78 if (i
== 127) /* Couldn't find. */
79 mp
= (u_char
*)def_enet_addr
;
84 mp
= (u_char
*)def_enet_addr
;
87 bd
->bi_enetaddr
[i
] = *mp
++;
89 /* The boot rom passes these to us in MHz. Linux now expects
92 bd
->bi_intfreq
*= 1000000;
93 bd
->bi_busfreq
*= 1000000;
95 /* Stuff a baud rate here as well.
97 bd
->bi_baudrate
= 9600;
99 #endif /* CONFIG_MBX */
101 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || \
102 defined(CONFIG_RPX8260) || defined(CONFIG_EP405)
103 /* Helper functions for Embedded Planet boards.
105 /* Because I didn't find anything that would do this.......
108 aschex_to_byte(u_char
*cp
)
114 if ((c
>= 'A') && (c
<= 'F')) {
117 } else if ((c
>= 'a') && (c
<= 'f')) {
127 if ((c
>= 'A') && (c
<= 'F')) {
130 } else if ((c
>= 'a') && (c
<= 'f')) {
142 rpx_eth(bd_t
*bd
, u_char
*cp
)
146 for (i
=0; i
<6; i
++) {
147 bd
->bi_enetaddr
[i
] = aschex_to_byte(cp
);
152 #ifdef CONFIG_RPX8260
154 rpx_baseten(u_char
*cp
)
160 while (*cp
!= '\n') {
162 retval
+= (*cp
) - '0';
169 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
171 rpx_brate(bd_t
*bd
, u_char
*cp
)
177 while (*cp
!= '\n') {
183 bd
->bi_baudrate
= rate
* 100;
187 rpx_cpuspeed(bd_t
*bd
, u_char
*cp
)
193 while (*cp
!= '\n') {
204 /* I don't know why the RPX just can't state the actual
211 bd
->bi_intfreq
= bd
->bi_busfreq
= num
* 1000000;
213 /* The 8xx can only run a maximum 50 MHz bus speed (until
214 * Motorola changes this :-). Greater than 50 MHz parts
215 * run internal/2 for bus speed.
222 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_EP405)
224 rpx_memsize(bd_t
*bd
, u_char
*cp
)
230 while (*cp
!= '\n') {
236 bd
->bi_memsize
= size
* 1024 * 1024;
238 #endif /* LITE || CLASSIC || EP405 */
239 #if defined(CONFIG_EP405)
241 rpx_nvramsize(bd_t
*bd
, u_char
*cp
)
247 while (*cp
!= '\n') {
253 bd
->bi_nvramsize
= size
* 1024;
255 #endif /* CONFIG_EP405 */
257 #endif /* Embedded Planet boards */
259 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
261 /* Read the EEPROM on the RPX-Lite board.
264 embed_config(bd_t
**bdp
)
266 u_char eebuf
[256], *cp
;
269 /* Read the first 256 bytes of the EEPROM. I think this
270 * is really all there is, and I hope if it gets bigger the
271 * info we want is still up front.
277 iic_read(0xa8, eebuf
, 0, 128);
278 iic_read(0xa8, &eebuf
[128], 128, 128);
280 /* We look for two things, the Ethernet address and the
281 * serial baud rate. The records are separated by
311 rpx_cpuspeed(bd
, cp
);
315 /* Scan to the end of the record.
317 while ((*cp
!= '\n') && (*cp
!= 0xff))
320 /* If the next character is a 0 or ff, we are done.
323 if ((*cp
== 0) || (*cp
== 0xff))
328 /* For boards without initialized EEPROM.
331 bd
->bi_memsize
= (8 * 1024 * 1024);
332 bd
->bi_intfreq
= 48000000;
333 bd
->bi_busfreq
= 48000000;
334 bd
->bi_baudrate
= 9600;
337 #endif /* RPXLITE || RPXCLASSIC */
340 /* Build a board information structure for the BSE ip-Engine.
341 * There is more to come since we will add some environment
342 * variables and a function to read them.
345 embed_config(bd_t
**bdp
)
354 /* Baud rate and processor speed will eventually come
355 * from the environment variables.
357 bd
->bi_baudrate
= 9600;
359 /* Get the Ethernet station address from the Flash ROM.
361 cp
= (u_char
*)0xfe003ffa;
362 for (i
=0; i
<6; i
++) {
363 bd
->bi_enetaddr
[i
] = *cp
++;
366 /* The rest of this should come from the environment as well.
369 bd
->bi_memsize
= (16 * 1024 * 1024);
370 bd
->bi_intfreq
= 48000000;
371 bd
->bi_busfreq
= 48000000;
376 /* Build a board information structure for the FADS.
379 embed_config(bd_t
**bdp
)
388 /* Just fill in some known values.
390 bd
->bi_baudrate
= 9600;
394 cp
= (u_char
*)def_enet_addr
;
395 for (i
=0; i
<6; i
++) {
396 bd
->bi_enetaddr
[i
] = *cp
++;
400 bd
->bi_memsize
= (8 * 1024 * 1024);
401 bd
->bi_intfreq
= 40000000;
402 bd
->bi_busfreq
= 40000000;
407 /* Compute 8260 clock values if the rom doesn't provide them.
409 static unsigned char bus2core_8260
[] = {
410 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
411 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, 2,
412 6, 5, 13, 2, 14, 4, 15, 2, 3, 11, 8, 10, 16, 12, 7, 2,
418 uint scmr
, vco_out
, clkin
;
419 uint plldf
, pllmf
, corecnf
;
420 volatile cpm2_map_t
*ip
;
422 ip
= (cpm2_map_t
*)CPM_MAP_ADDR
;
423 scmr
= ip
->im_clkrst
.car_scmr
;
425 /* The clkin is always bus frequency.
427 clkin
= bd
->bi_busfreq
;
429 /* Collect the bits from the scmr.
431 plldf
= (scmr
>> 12) & 1;
432 pllmf
= scmr
& 0xfff;
433 corecnf
= (scmr
>> 24) &0x1f;
435 /* This is arithmetic from the 8260 manual.
437 vco_out
= clkin
/ (plldf
+ 1);
438 vco_out
*= 2 * (pllmf
+ 1);
439 bd
->bi_vco
= vco_out
; /* Save for later */
441 bd
->bi_cpmfreq
= vco_out
/ 2; /* CPM Freq, in MHz */
442 bd
->bi_intfreq
= bd
->bi_busfreq
* bus2core_8260
[corecnf
] / 2;
444 /* Set Baud rate divisor. The power up default is divide by 16,
445 * but we set it again here in case it was changed.
447 ip
->im_clkrst
.car_sccr
= 1; /* DIV 16 BRG */
448 bd
->bi_brgfreq
= vco_out
/ 16;
451 static unsigned char bus2core_8280
[] = {
452 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
453 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, 2,
454 6, 5, 13, 2, 14, 2, 15, 2, 3, 2, 2, 2, 16, 2, 2, 2,
460 uint scmr
, main_clk
, clkin
;
462 volatile cpm2_map_t
*ip
;
464 ip
= (cpm2_map_t
*)CPM_MAP_ADDR
;
465 scmr
= ip
->im_clkrst
.car_scmr
;
467 /* The clkin is always bus frequency.
469 clkin
= bd
->bi_busfreq
;
471 /* Collect the bits from the scmr.
474 corecnf
= (scmr
>> 24) & 0x1f;
476 /* This is arithmetic from the 8280 manual.
478 main_clk
= clkin
* (pllmf
+ 1);
480 bd
->bi_cpmfreq
= main_clk
/ 2; /* CPM Freq, in MHz */
481 bd
->bi_intfreq
= bd
->bi_busfreq
* bus2core_8280
[corecnf
] / 2;
483 /* Set Baud rate divisor. The power up default is divide by 16,
484 * but we set it again here in case it was changed.
486 ip
->im_clkrst
.car_sccr
= (ip
->im_clkrst
.car_sccr
& 0x3) | 0x1;
487 bd
->bi_brgfreq
= main_clk
/ 16;
491 #ifdef CONFIG_SBC82xx
493 embed_config(bd_t
**bdp
)
504 bd
->bi_baudrate
= 9600;
505 bd
->bi_memsize
= 256 * 1024 * 1024; /* just a guess */
507 cp
= (void*)SBC82xx_MACADDR_NVRAM_SCC1
;
508 memcpy(bd
->bi_enetaddr
, cp
, 6);
510 /* can busfreq be calculated? */
511 pvr
= mfspr(SPRN_PVR
);
512 if ((pvr
& 0xffff0000) == 0x80820000) {
513 bd
->bi_busfreq
= 100000000;
516 bd
->bi_busfreq
= 66000000;
523 #if defined(CONFIG_EST8260) || defined(CONFIG_TQM8260)
525 embed_config(bd_t
**bdp
)
533 /* This is actually provided by my boot rom. I have it
534 * here for those people that may load the kernel with
535 * a JTAG/COP tool and not the rom monitor.
537 bd
->bi_baudrate
= 115200;
538 bd
->bi_intfreq
= 200000000;
539 bd
->bi_busfreq
= 66666666;
540 bd
->bi_cpmfreq
= 66666666;
541 bd
->bi_brgfreq
= 33333333;
542 bd
->bi_memsize
= 16 * 1024 * 1024;
544 /* The boot rom passes these to us in MHz. Linux now expects
547 bd
->bi_intfreq
*= 1000000;
548 bd
->bi_busfreq
*= 1000000;
549 bd
->bi_cpmfreq
*= 1000000;
550 bd
->bi_brgfreq
*= 1000000;
553 cp
= (u_char
*)def_enet_addr
;
554 for (i
=0; i
<6; i
++) {
555 bd
->bi_enetaddr
[i
] = *cp
++;
560 #ifdef CONFIG_SBS8260
562 embed_config(bd_t
**bdp
)
568 /* This should provided by the boot rom.
572 bd
->bi_baudrate
= 9600;
573 bd
->bi_memsize
= 64 * 1024 * 1024;
575 /* Set all of the clocks. We have to know the speed of the
576 * external clock. The development board had 66 MHz.
578 bd
->bi_busfreq
= 66666666;
581 /* I don't know how to compute this yet.
583 bd
->bi_intfreq
= 133000000;
586 cp
= (u_char
*)def_enet_addr
;
587 for (i
=0; i
<6; i
++) {
588 bd
->bi_enetaddr
[i
] = *cp
++;
593 #ifdef CONFIG_RPX8260
595 embed_config(bd_t
**bdp
)
597 u_char
*cp
, *keyvals
;
601 keyvals
= (u_char
*)*bdp
;
606 /* This is almost identical to the RPX-Lite/Classic functions
607 * on the 8xx boards. It would be nice to have a key lookup
608 * function in a string, but the format of all of the fields
609 * is slightly different.
624 bd
->bi_baudrate
= rpx_baseten(cp
);
631 bd
->bi_memsize
= rpx_baseten(cp
) * 1024 * 1024;
638 bd
->bi_busfreq
= rpx_baseten(cp
);
645 bd
->bi_nvsize
= rpx_baseten(cp
) * 1024 * 1024;
649 /* Scan to the end of the record.
651 while ((*cp
!= '\n') && (*cp
!= 0xff))
654 /* If the next character is a 0 or ff, we are done.
657 if ((*cp
== 0) || (*cp
== 0xff))
662 /* The memory size includes both the 60x and local bus DRAM.
663 * I don't want to use the local bus DRAM for real memory,
664 * so subtract it out. It would be nice if they were separate
667 bd
->bi_memsize
-= 32 * 1024 * 1024;
669 /* Set all of the clocks. We have to know the speed of the
674 /* I don't know how to compute this yet.
676 bd
->bi_intfreq
= 200000000;
678 #endif /* RPX6 for testing */
680 #ifdef CONFIG_ADS8260
682 embed_config(bd_t
**bdp
)
688 /* This should provided by the boot rom.
692 bd
->bi_baudrate
= 9600;
693 bd
->bi_memsize
= 16 * 1024 * 1024;
695 /* Set all of the clocks. We have to know the speed of the
696 * external clock. The development board had 66 MHz.
698 bd
->bi_busfreq
= 66666666;
701 /* I don't know how to compute this yet.
703 bd
->bi_intfreq
= 200000000;
706 cp
= (u_char
*)def_enet_addr
;
707 for (i
=0; i
<6; i
++) {
708 bd
->bi_enetaddr
[i
] = *cp
++;
715 embed_config(bd_t
**bdp
)
721 /* Willow has Open Firmware....I should learn how to get this
722 * information from it.
726 bd
->bi_baudrate
= 9600;
727 bd
->bi_memsize
= 32 * 1024 * 1024;
729 /* Set all of the clocks. We have to know the speed of the
730 * external clock. The development board had 66 MHz.
732 bd
->bi_busfreq
= 66666666;
735 /* I don't know how to compute this yet.
737 bd
->bi_intfreq
= 200000000;
740 cp
= (u_char
*)def_enet_addr
;
741 for (i
=0; i
<6; i
++) {
742 bd
->bi_enetaddr
[i
] = *cp
++;
747 #if defined(CONFIG_XILINX_ML300) || defined(CONFIG_XILINX_ML403)
749 embed_config(bd_t
** bdp
)
751 static const unsigned long line_size
= 32;
752 static const unsigned long congruence_classes
= 256;
760 * Invalidate the data cache if the data cache is turned off.
761 * - The 405 core does not invalidate the data cache on power-up
762 * or reset but does turn off the data cache. We cannot assume
763 * that the cache contents are valid.
764 * - If the data cache is turned on this must have been done by
765 * a bootloader and we assume that the cache contents are
768 __asm__("mfdccr %0": "=r" (dccr
));
771 addr
< (congruence_classes
* line_size
);
773 __asm__("dccci 0,%0": :"b"(addr
));
779 bd
->bi_memsize
= XPAR_DDR_0_SIZE
;
780 bd
->bi_intfreq
= XPAR_CORE_CLOCK_FREQ_HZ
;
781 bd
->bi_busfreq
= XPAR_PLB_CLOCK_FREQ_HZ
;
782 bd
->bi_pci_busfreq
= XPAR_PCI_0_CLOCK_FREQ_HZ
;
784 /* Copy the default ethernet address */
785 cp
= (u_char
*)def_enet_addr
;
787 bd
->bi_enetaddr
[i
] = *cp
++;
789 timebase_period_ns
= 1000000000 / bd
->bi_tbfreq
;
790 /* see bi_tbfreq definition in arch/ppc/platforms/4xx/xilinx_ml300.h */
792 #endif /* CONFIG_XILINX_ML300 || CONFIG_XILINX_ML403 */
794 #ifdef CONFIG_IBM_OPENBIOS
795 /* This could possibly work for all treeboot roms.
797 #if defined(CONFIG_BUBINGA)
798 #define BOARD_INFO_VECTOR 0xFFF80B50 /* openbios 1.19 moved this vector down - armin */
800 #define BOARD_INFO_VECTOR 0xFFFE0B50
804 embed_config(bd_t
**bdp
)
808 bd_t
*bd
, *treeboot_bd
;
809 bd_t
*(*get_board_info
)(void) =
810 (bd_t
*(*)(void))(*(unsigned long *)BOARD_INFO_VECTOR
);
811 #if !defined(CONFIG_STB03xxx)
813 /* shut down the Ethernet controller that the boot rom
814 * sometimes leaves running.
816 mtdcr(DCRN_MALCR(DCRN_MAL_BASE
), MALCR_MMSR
); /* 1st reset MAL */
817 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE
)) & MALCR_MMSR
) {}; /* wait for the reset */
818 out_be32((volatile u32
*)EMAC0_BASE
,0x20000000); /* then reset EMAC */
823 if ((treeboot_bd
= get_board_info()) != NULL
) {
824 memcpy(bd
, treeboot_bd
, sizeof(bd_t
));
827 /* Hmmm...better try to stuff some defaults.
829 bd
->bi_memsize
= 16 * 1024 * 1024;
830 cp
= (u_char
*)def_enet_addr
;
831 for (i
=0; i
<6; i
++) {
832 /* I should probably put different ones here,
833 * hopefully only one is used.
835 bd
->BD_EMAC_ADDR(0,i
) = *cp
;
838 bd
->bi_pci_enetaddr
[i
] = *cp
++;
841 bd
->bi_tbfreq
= 200 * 1000 * 1000;
842 bd
->bi_intfreq
= 200000000;
843 bd
->bi_busfreq
= 100000000;
845 bd
->bi_pci_busfreq
= 66666666;
848 /* Yeah, this look weird, but on Redwood 4 they are
849 * different object in the structure. Sincr Redwwood 5
850 * and Redwood 6 use OpenBIOS, it requires a special value.
852 #if defined(CONFIG_REDWOOD_5) || defined (CONFIG_REDWOOD_6)
853 bd
->bi_tbfreq
= 27 * 1000 * 1000;
855 timebase_period_ns
= 1000000000 / bd
->bi_tbfreq
;
857 #endif /* CONFIG_IBM_OPENBIOS */
860 #include <linux/serial_reg.h>
863 embed_config(bd_t
**bdp
)
869 /* Different versions of the PlanetCore firmware vary in how
870 they set up the serial port - in particular whether they
871 use the internal or external serial clock for UART0. Make
872 sure the UART is in a known state. */
873 /* FIXME: We should use the board's 11.0592MHz external serial
874 clock - it will be more accurate for serial rates. For
875 now, however the baud rates in ep405.h are for the internal
877 chcr0
= mfdcr(DCRN_CHCR0
);
878 if ( (chcr0
& 0x1fff) != 0x103e ) {
879 mtdcr(DCRN_CHCR0
, (chcr0
& 0xffffe000) | 0x103e);
880 /* The following tricks serial_init() into resetting the baud rate */
881 writeb(0, UART0_IO_BASE
+ UART_LCR
);
884 /* We haven't seen actual problems with the EP405 leaving the
885 * EMAC running (as we have on Walnut). But the registers
886 * suggest it may not be left completely quiescent. Reset it
887 * just to be sure. */
888 mtdcr(DCRN_MALCR(DCRN_MAL_BASE
), MALCR_MMSR
); /* 1st reset MAL */
889 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE
)) & MALCR_MMSR
) {}; /* wait for the reset */
890 out_be32((unsigned *)EMAC0_BASE
,0x20000000); /* then reset EMAC */
895 cp
= (u_char
*)0xF0000EE0;
917 rpx_nvramsize(bd
, cp
);
920 while ((*cp
!= '\n') && (*cp
!= 0xff))
924 if ((*cp
== 0) || (*cp
== 0xff))
927 bd
->bi_intfreq
= 200000000;
928 bd
->bi_busfreq
= 100000000;
929 bd
->bi_pci_busfreq
= 33000000 ;
932 bd
->bi_memsize
= 64000000;
933 bd
->bi_intfreq
= 200000000;
934 bd
->bi_busfreq
= 100000000;
935 bd
->bi_pci_busfreq
= 33000000 ;