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/config.h>
12 #include <linux/string.h>
15 #include <asm/mpc8xx.h>
18 #include <asm/mpc8260.h>
19 #include <asm/immap_cpm2.h>
24 #ifdef CONFIG_XILINX_VIRTEX
25 #include <platforms/4xx/xparameters/xparameters.h>
27 extern unsigned long timebase_period_ns
;
29 /* For those boards that don't provide one.
31 #if !defined(CONFIG_MBX)
36 * These are just the basic master read/write operations so we can
37 * examine serial EEPROM.
39 extern void iic_read(uint devaddr
, u_char
*buf
, uint offset
, uint count
);
41 /* Supply a default Ethernet address for those eval boards that don't
42 * ship with one. This is an address from the MBX board I have, so
43 * it is unlikely you will find it on your network.
45 static ushort def_enet_addr
[] = { 0x0800, 0x3e26, 0x1559 };
47 #if defined(CONFIG_MBX)
49 /* The MBX hands us a pretty much ready to go board descriptor. This
50 * is where the idea started in the first place.
53 embed_config(bd_t
**bdp
)
62 /* Read the first 128 bytes of the EEPROM. There is more,
63 * but this is all we need.
65 iic_read(0xa4, eebuf
, 0, 128);
67 /* All we are looking for is the Ethernet MAC address. The
68 * first 8 bytes are 'MOTOROLA', so check for part of that.
69 * Next, the VPD describes a MAC 'packet' as being of type 08
70 * and size 06. So we look for that and the MAC must follow.
71 * If there are more than one, we still only care about the first.
72 * If it's there, assume we have a valid MAC address. If not,
73 * grab our default one.
75 if ((*(uint
*)eebuf
) == 0x4d4f544f) {
76 while (i
< 127 && !(eebuf
[i
] == 0x08 && eebuf
[i
+ 1] == 0x06))
77 i
+= eebuf
[i
+ 1] + 2; /* skip this packet */
79 if (i
== 127) /* Couldn't find. */
80 mp
= (u_char
*)def_enet_addr
;
85 mp
= (u_char
*)def_enet_addr
;
88 bd
->bi_enetaddr
[i
] = *mp
++;
90 /* The boot rom passes these to us in MHz. Linux now expects
93 bd
->bi_intfreq
*= 1000000;
94 bd
->bi_busfreq
*= 1000000;
96 /* Stuff a baud rate here as well.
98 bd
->bi_baudrate
= 9600;
100 #endif /* CONFIG_MBX */
102 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || \
103 defined(CONFIG_RPX8260) || defined(CONFIG_EP405)
104 /* Helper functions for Embedded Planet boards.
106 /* Because I didn't find anything that would do this.......
109 aschex_to_byte(u_char
*cp
)
115 if ((c
>= 'A') && (c
<= 'F')) {
118 } else if ((c
>= 'a') && (c
<= 'f')) {
128 if ((c
>= 'A') && (c
<= 'F')) {
131 } else if ((c
>= 'a') && (c
<= 'f')) {
143 rpx_eth(bd_t
*bd
, u_char
*cp
)
147 for (i
=0; i
<6; i
++) {
148 bd
->bi_enetaddr
[i
] = aschex_to_byte(cp
);
153 #ifdef CONFIG_RPX8260
155 rpx_baseten(u_char
*cp
)
161 while (*cp
!= '\n') {
163 retval
+= (*cp
) - '0';
170 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
172 rpx_brate(bd_t
*bd
, u_char
*cp
)
178 while (*cp
!= '\n') {
184 bd
->bi_baudrate
= rate
* 100;
188 rpx_cpuspeed(bd_t
*bd
, u_char
*cp
)
194 while (*cp
!= '\n') {
205 /* I don't know why the RPX just can't state the actual
212 bd
->bi_intfreq
= bd
->bi_busfreq
= num
* 1000000;
214 /* The 8xx can only run a maximum 50 MHz bus speed (until
215 * Motorola changes this :-). Greater than 50 MHz parts
216 * run internal/2 for bus speed.
223 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_EP405)
225 rpx_memsize(bd_t
*bd
, u_char
*cp
)
231 while (*cp
!= '\n') {
237 bd
->bi_memsize
= size
* 1024 * 1024;
239 #endif /* LITE || CLASSIC || EP405 */
240 #if defined(CONFIG_EP405)
242 rpx_nvramsize(bd_t
*bd
, u_char
*cp
)
248 while (*cp
!= '\n') {
254 bd
->bi_nvramsize
= size
* 1024;
256 #endif /* CONFIG_EP405 */
258 #endif /* Embedded Planet boards */
260 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
262 /* Read the EEPROM on the RPX-Lite board.
265 embed_config(bd_t
**bdp
)
267 u_char eebuf
[256], *cp
;
270 /* Read the first 256 bytes of the EEPROM. I think this
271 * is really all there is, and I hope if it gets bigger the
272 * info we want is still up front.
278 iic_read(0xa8, eebuf
, 0, 128);
279 iic_read(0xa8, &eebuf
[128], 128, 128);
281 /* We look for two things, the Ethernet address and the
282 * serial baud rate. The records are separated by
312 rpx_cpuspeed(bd
, cp
);
316 /* Scan to the end of the record.
318 while ((*cp
!= '\n') && (*cp
!= 0xff))
321 /* If the next character is a 0 or ff, we are done.
324 if ((*cp
== 0) || (*cp
== 0xff))
329 /* For boards without initialized EEPROM.
332 bd
->bi_memsize
= (8 * 1024 * 1024);
333 bd
->bi_intfreq
= 48000000;
334 bd
->bi_busfreq
= 48000000;
335 bd
->bi_baudrate
= 9600;
338 #endif /* RPXLITE || RPXCLASSIC */
341 /* Build a board information structure for the BSE ip-Engine.
342 * There is more to come since we will add some environment
343 * variables and a function to read them.
346 embed_config(bd_t
**bdp
)
355 /* Baud rate and processor speed will eventually come
356 * from the environment variables.
358 bd
->bi_baudrate
= 9600;
360 /* Get the Ethernet station address from the Flash ROM.
362 cp
= (u_char
*)0xfe003ffa;
363 for (i
=0; i
<6; i
++) {
364 bd
->bi_enetaddr
[i
] = *cp
++;
367 /* The rest of this should come from the environment as well.
370 bd
->bi_memsize
= (16 * 1024 * 1024);
371 bd
->bi_intfreq
= 48000000;
372 bd
->bi_busfreq
= 48000000;
377 /* Build a board information structure for the FADS.
380 embed_config(bd_t
**bdp
)
389 /* Just fill in some known values.
391 bd
->bi_baudrate
= 9600;
395 cp
= (u_char
*)def_enet_addr
;
396 for (i
=0; i
<6; i
++) {
397 bd
->bi_enetaddr
[i
] = *cp
++;
401 bd
->bi_memsize
= (8 * 1024 * 1024);
402 bd
->bi_intfreq
= 40000000;
403 bd
->bi_busfreq
= 40000000;
408 /* Compute 8260 clock values if the rom doesn't provide them.
410 static unsigned char bus2core_8260
[] = {
411 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
412 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, 2,
413 6, 5, 13, 2, 14, 4, 15, 2, 3, 11, 8, 10, 16, 12, 7, 2,
419 uint scmr
, vco_out
, clkin
;
420 uint plldf
, pllmf
, corecnf
;
421 volatile cpm2_map_t
*ip
;
423 ip
= (cpm2_map_t
*)CPM_MAP_ADDR
;
424 scmr
= ip
->im_clkrst
.car_scmr
;
426 /* The clkin is always bus frequency.
428 clkin
= bd
->bi_busfreq
;
430 /* Collect the bits from the scmr.
432 plldf
= (scmr
>> 12) & 1;
433 pllmf
= scmr
& 0xfff;
434 corecnf
= (scmr
>> 24) &0x1f;
436 /* This is arithmetic from the 8260 manual.
438 vco_out
= clkin
/ (plldf
+ 1);
439 vco_out
*= 2 * (pllmf
+ 1);
440 bd
->bi_vco
= vco_out
; /* Save for later */
442 bd
->bi_cpmfreq
= vco_out
/ 2; /* CPM Freq, in MHz */
443 bd
->bi_intfreq
= bd
->bi_busfreq
* bus2core_8260
[corecnf
] / 2;
445 /* Set Baud rate divisor. The power up default is divide by 16,
446 * but we set it again here in case it was changed.
448 ip
->im_clkrst
.car_sccr
= 1; /* DIV 16 BRG */
449 bd
->bi_brgfreq
= vco_out
/ 16;
452 static unsigned char bus2core_8280
[] = {
453 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
454 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, 2,
455 6, 5, 13, 2, 14, 2, 15, 2, 3, 2, 2, 2, 16, 2, 2, 2,
461 uint scmr
, main_clk
, clkin
;
463 volatile cpm2_map_t
*ip
;
465 ip
= (cpm2_map_t
*)CPM_MAP_ADDR
;
466 scmr
= ip
->im_clkrst
.car_scmr
;
468 /* The clkin is always bus frequency.
470 clkin
= bd
->bi_busfreq
;
472 /* Collect the bits from the scmr.
475 corecnf
= (scmr
>> 24) & 0x1f;
477 /* This is arithmetic from the 8280 manual.
479 main_clk
= clkin
* (pllmf
+ 1);
481 bd
->bi_cpmfreq
= main_clk
/ 2; /* CPM Freq, in MHz */
482 bd
->bi_intfreq
= bd
->bi_busfreq
* bus2core_8280
[corecnf
] / 2;
484 /* Set Baud rate divisor. The power up default is divide by 16,
485 * but we set it again here in case it was changed.
487 ip
->im_clkrst
.car_sccr
= (ip
->im_clkrst
.car_sccr
& 0x3) | 0x1;
488 bd
->bi_brgfreq
= main_clk
/ 16;
492 #ifdef CONFIG_SBC82xx
494 embed_config(bd_t
**bdp
)
505 bd
->bi_baudrate
= 9600;
506 bd
->bi_memsize
= 256 * 1024 * 1024; /* just a guess */
508 cp
= (void*)SBC82xx_MACADDR_NVRAM_SCC1
;
509 memcpy(bd
->bi_enetaddr
, cp
, 6);
511 /* can busfreq be calculated? */
512 pvr
= mfspr(SPRN_PVR
);
513 if ((pvr
& 0xffff0000) == 0x80820000) {
514 bd
->bi_busfreq
= 100000000;
517 bd
->bi_busfreq
= 66000000;
524 #if defined(CONFIG_EST8260) || defined(CONFIG_TQM8260)
526 embed_config(bd_t
**bdp
)
534 /* This is actually provided by my boot rom. I have it
535 * here for those people that may load the kernel with
536 * a JTAG/COP tool and not the rom monitor.
538 bd
->bi_baudrate
= 115200;
539 bd
->bi_intfreq
= 200000000;
540 bd
->bi_busfreq
= 66666666;
541 bd
->bi_cpmfreq
= 66666666;
542 bd
->bi_brgfreq
= 33333333;
543 bd
->bi_memsize
= 16 * 1024 * 1024;
545 /* The boot rom passes these to us in MHz. Linux now expects
548 bd
->bi_intfreq
*= 1000000;
549 bd
->bi_busfreq
*= 1000000;
550 bd
->bi_cpmfreq
*= 1000000;
551 bd
->bi_brgfreq
*= 1000000;
554 cp
= (u_char
*)def_enet_addr
;
555 for (i
=0; i
<6; i
++) {
556 bd
->bi_enetaddr
[i
] = *cp
++;
561 #ifdef CONFIG_SBS8260
563 embed_config(bd_t
**bdp
)
569 /* This should provided by the boot rom.
573 bd
->bi_baudrate
= 9600;
574 bd
->bi_memsize
= 64 * 1024 * 1024;
576 /* Set all of the clocks. We have to know the speed of the
577 * external clock. The development board had 66 MHz.
579 bd
->bi_busfreq
= 66666666;
582 /* I don't know how to compute this yet.
584 bd
->bi_intfreq
= 133000000;
587 cp
= (u_char
*)def_enet_addr
;
588 for (i
=0; i
<6; i
++) {
589 bd
->bi_enetaddr
[i
] = *cp
++;
594 #ifdef CONFIG_RPX8260
596 embed_config(bd_t
**bdp
)
598 u_char
*cp
, *keyvals
;
602 keyvals
= (u_char
*)*bdp
;
607 /* This is almost identical to the RPX-Lite/Classic functions
608 * on the 8xx boards. It would be nice to have a key lookup
609 * function in a string, but the format of all of the fields
610 * is slightly different.
625 bd
->bi_baudrate
= rpx_baseten(cp
);
632 bd
->bi_memsize
= rpx_baseten(cp
) * 1024 * 1024;
639 bd
->bi_busfreq
= rpx_baseten(cp
);
646 bd
->bi_nvsize
= rpx_baseten(cp
) * 1024 * 1024;
650 /* Scan to the end of the record.
652 while ((*cp
!= '\n') && (*cp
!= 0xff))
655 /* If the next character is a 0 or ff, we are done.
658 if ((*cp
== 0) || (*cp
== 0xff))
663 /* The memory size includes both the 60x and local bus DRAM.
664 * I don't want to use the local bus DRAM for real memory,
665 * so subtract it out. It would be nice if they were separate
668 bd
->bi_memsize
-= 32 * 1024 * 1024;
670 /* Set all of the clocks. We have to know the speed of the
675 /* I don't know how to compute this yet.
677 bd
->bi_intfreq
= 200000000;
679 #endif /* RPX6 for testing */
681 #ifdef CONFIG_ADS8260
683 embed_config(bd_t
**bdp
)
689 /* This should provided by the boot rom.
693 bd
->bi_baudrate
= 9600;
694 bd
->bi_memsize
= 16 * 1024 * 1024;
696 /* Set all of the clocks. We have to know the speed of the
697 * external clock. The development board had 66 MHz.
699 bd
->bi_busfreq
= 66666666;
702 /* I don't know how to compute this yet.
704 bd
->bi_intfreq
= 200000000;
707 cp
= (u_char
*)def_enet_addr
;
708 for (i
=0; i
<6; i
++) {
709 bd
->bi_enetaddr
[i
] = *cp
++;
716 embed_config(bd_t
**bdp
)
722 /* Willow has Open Firmware....I should learn how to get this
723 * information from it.
727 bd
->bi_baudrate
= 9600;
728 bd
->bi_memsize
= 32 * 1024 * 1024;
730 /* Set all of the clocks. We have to know the speed of the
731 * external clock. The development board had 66 MHz.
733 bd
->bi_busfreq
= 66666666;
736 /* I don't know how to compute this yet.
738 bd
->bi_intfreq
= 200000000;
741 cp
= (u_char
*)def_enet_addr
;
742 for (i
=0; i
<6; i
++) {
743 bd
->bi_enetaddr
[i
] = *cp
++;
748 #if defined(CONFIG_XILINX_ML300) || defined(CONFIG_XILINX_ML403)
750 embed_config(bd_t
** bdp
)
752 static const unsigned long line_size
= 32;
753 static const unsigned long congruence_classes
= 256;
759 * Invalidate the data cache if the data cache is turned off.
760 * - The 405 core does not invalidate the data cache on power-up
761 * or reset but does turn off the data cache. We cannot assume
762 * that the cache contents are valid.
763 * - If the data cache is turned on this must have been done by
764 * a bootloader and we assume that the cache contents are
767 __asm__("mfdccr %0": "=r" (dccr
));
770 addr
< (congruence_classes
* line_size
);
772 __asm__("dccci 0,%0": :"b"(addr
));
778 bd
->bi_memsize
= XPAR_DDR_0_SIZE
;
779 bd
->bi_intfreq
= XPAR_CORE_CLOCK_FREQ_HZ
;
780 bd
->bi_busfreq
= XPAR_PLB_CLOCK_FREQ_HZ
;
781 bd
->bi_pci_busfreq
= XPAR_PCI_0_CLOCK_FREQ_HZ
;
782 timebase_period_ns
= 1000000000 / bd
->bi_tbfreq
;
783 /* see bi_tbfreq definition in arch/ppc/platforms/4xx/xilinx_ml300.h */
785 #endif /* CONFIG_XILINX_ML300 || CONFIG_XILINX_ML403 */
787 #ifdef CONFIG_IBM_OPENBIOS
788 /* This could possibly work for all treeboot roms.
790 #if defined(CONFIG_BUBINGA)
791 #define BOARD_INFO_VECTOR 0xFFF80B50 /* openbios 1.19 moved this vector down - armin */
793 #define BOARD_INFO_VECTOR 0xFFFE0B50
797 embed_config(bd_t
**bdp
)
801 bd_t
*bd
, *treeboot_bd
;
802 bd_t
*(*get_board_info
)(void) =
803 (bd_t
*(*)(void))(*(unsigned long *)BOARD_INFO_VECTOR
);
804 #if !defined(CONFIG_STB03xxx)
806 /* shut down the Ethernet controller that the boot rom
807 * sometimes leaves running.
809 mtdcr(DCRN_MALCR(DCRN_MAL_BASE
), MALCR_MMSR
); /* 1st reset MAL */
810 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE
)) & MALCR_MMSR
) {}; /* wait for the reset */
811 out_be32((volatile u32
*)EMAC0_BASE
,0x20000000); /* then reset EMAC */
816 if ((treeboot_bd
= get_board_info()) != NULL
) {
817 memcpy(bd
, treeboot_bd
, sizeof(bd_t
));
820 /* Hmmm...better try to stuff some defaults.
822 bd
->bi_memsize
= 16 * 1024 * 1024;
823 cp
= (u_char
*)def_enet_addr
;
824 for (i
=0; i
<6; i
++) {
825 /* I should probably put different ones here,
826 * hopefully only one is used.
828 bd
->BD_EMAC_ADDR(0,i
) = *cp
;
831 bd
->bi_pci_enetaddr
[i
] = *cp
++;
834 bd
->bi_tbfreq
= 200 * 1000 * 1000;
835 bd
->bi_intfreq
= 200000000;
836 bd
->bi_busfreq
= 100000000;
838 bd
->bi_pci_busfreq
= 66666666;
841 /* Yeah, this look weird, but on Redwood 4 they are
842 * different object in the structure. Sincr Redwwood 5
843 * and Redwood 6 use OpenBIOS, it requires a special value.
845 #if defined(CONFIG_REDWOOD_5) || defined (CONFIG_REDWOOD_6)
846 bd
->bi_tbfreq
= 27 * 1000 * 1000;
848 timebase_period_ns
= 1000000000 / bd
->bi_tbfreq
;
850 #endif /* CONFIG_IBM_OPENBIOS */
853 #include <linux/serial_reg.h>
856 embed_config(bd_t
**bdp
)
862 /* Different versions of the PlanetCore firmware vary in how
863 they set up the serial port - in particular whether they
864 use the internal or external serial clock for UART0. Make
865 sure the UART is in a known state. */
866 /* FIXME: We should use the board's 11.0592MHz external serial
867 clock - it will be more accurate for serial rates. For
868 now, however the baud rates in ep405.h are for the internal
870 chcr0
= mfdcr(DCRN_CHCR0
);
871 if ( (chcr0
& 0x1fff) != 0x103e ) {
872 mtdcr(DCRN_CHCR0
, (chcr0
& 0xffffe000) | 0x103e);
873 /* The following tricks serial_init() into resetting the baud rate */
874 writeb(0, UART0_IO_BASE
+ UART_LCR
);
877 /* We haven't seen actual problems with the EP405 leaving the
878 * EMAC running (as we have on Walnut). But the registers
879 * suggest it may not be left completely quiescent. Reset it
880 * just to be sure. */
881 mtdcr(DCRN_MALCR(DCRN_MAL_BASE
), MALCR_MMSR
); /* 1st reset MAL */
882 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE
)) & MALCR_MMSR
) {}; /* wait for the reset */
883 out_be32((unsigned *)EMAC0_BASE
,0x20000000); /* then reset EMAC */
888 cp
= (u_char
*)0xF0000EE0;
910 rpx_nvramsize(bd
, cp
);
913 while ((*cp
!= '\n') && (*cp
!= 0xff))
917 if ((*cp
== 0) || (*cp
== 0xff))
920 bd
->bi_intfreq
= 200000000;
921 bd
->bi_busfreq
= 100000000;
922 bd
->bi_pci_busfreq
= 33000000 ;
925 bd
->bi_memsize
= 64000000;
926 bd
->bi_intfreq
= 200000000;
927 bd
->bi_busfreq
= 100000000;
928 bd
->bi_pci_busfreq
= 33000000 ;