1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Board device initialization File: swarm_devs.c
6 * This is the "C" part of the board support package. The
7 * routines to create and initialize the console, wire up
8 * device drivers, and do other customization live here.
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
52 #include "lib_types.h"
53 #include "lib_queue.h"
54 #include "lib_printf.h"
55 #include "lib_string.h"
57 #include "cfe_device.h"
58 #include "cfe_timer.h"
62 #include "sb1250_defs.h"
63 #include "sb1250_regs.h"
64 #include "sb1250_scd.h"
65 #include "sb1250_smbus.h"
66 #include "sb1250_wid.h"
68 #include "bsp_config.h"
73 #include "dev_newflash.h"
75 #include "cfe_loader.h"
76 #include "cfe_autoboot.h"
78 /* *********************************************************************
79 * Devices we're importing
80 ********************************************************************* */
82 extern cfe_driver_t m41t81_clock
; /* M41T81 SMBus RTC */
83 extern cfe_driver_t x1241_clock
; /* Xicor SMBus RTC */
84 extern cfe_driver_t promice_uart
; /* promice serial port */
85 extern cfe_driver_t sb1250_uart
; /* SB1250 serial ports */
86 extern cfe_driver_t sb1250_ether
; /* SB1250 MACs */
87 extern cfe_driver_t sb1250_x1240eeprom
; /* Xicor SMBus NVRAM */
88 extern cfe_driver_t sb1250_24lc128eeprom
; /* Microchip EEPROM */
89 extern cfe_driver_t newflashdrv
; /* flash */
90 extern cfe_driver_t idedrv
; /* IDE disk */
91 extern cfe_driver_t pcmciadrv
; /* PCMCIA card */
93 extern void pci_add_devices(int init
); /* driver collection du jour */
96 extern cfe_driver_t tcpconsole
; /* TCP/IP console */
99 extern cfe_driver_t pcconsole2
; /* VGA Console */
100 static int vgainit_ok
= FALSE
;
101 extern int vga_biosinit(void);
104 extern int usb_init(void);
105 extern cfe_driver_t usb_disk
; /* USB mass-storage */
106 extern cfe_driver_t usb_uart
; /* USB serial ports */
109 /* *********************************************************************
110 * UI command initialization
111 ********************************************************************* */
113 extern void ui_init_cpu1cmds(void);
114 extern void ui_init_swarmcmds(void);
115 extern int ui_init_corecmds(void);
116 extern int ui_init_soccmds(void);
117 extern int ui_init_testcmds(void);
118 extern int ui_init_tempsensorcmds(void);
119 extern int ui_init_toyclockcmds(void);
120 extern int ui_init_memtestcmds(void);
121 extern int ui_init_resetcmds(void);
122 extern int ui_init_phycmds(void);
123 extern int ui_init_spdcmds(void);
124 extern int ui_init_disktestcmds(void);
125 extern int ui_init_ethertestcmds(void);
126 extern int ui_init_flashtestcmds(void);
129 extern int ui_init_usbcmds(void);
132 /* *********************************************************************
134 ********************************************************************* */
136 extern void sb1250_show_cpu_type(void);
138 /* *********************************************************************
139 * Some board-specific parameters
140 ********************************************************************* */
143 * Note! Configure the PROMICE for burst mode zero (one byte per
147 #define PROMICE_BASE (0x1FDFFC00)
148 #define PROMICE_WORDSIZE 1
150 #define REAL_BOOTROM_SIZE (2*1024*1024) /* region is 4MB, but rom is 2MB */
152 /* *********************************************************************
153 * SysConfig switch settings and related parameters
154 ********************************************************************* */
157 int swarm_config_switch
;
159 #define SWARM_PROMICE_CONSOLE 0x00000001
160 #define SWARM_VGA_CONSOLE 0x00000002
162 const unsigned int swarm_startflags
[16] = {
163 0, /* 0 : UART console, no PCI */
164 SWARM_PROMICE_CONSOLE
, /* 1 : PromICE console, no PCI */
165 CFE_INIT_PCI
, /* 2 : UART console, PCI */
166 CFE_INIT_PCI
| SWARM_PROMICE_CONSOLE
, /* 3 : PromICE console, PCI */
169 CFE_INIT_PCI
| CFE_LDT_SLAVE
, /* 6 : 2, plus LDT slave mode */
170 CFE_INIT_SAFE
, /* 7 : UART console, no pci, safe mode */
173 CFE_INIT_PCI
| SWARM_VGA_CONSOLE
, /* 10 : PCI, VGA Console */
182 unsigned int cpu_revision
;
185 /* *********************************************************************
186 * board_console_init()
188 * Add the console device and set it to be the primary
196 ********************************************************************* */
198 void board_console_init(void)
203 syscfg
= SBREADCSR(A_SCD_SYSTEM_CFG
);
205 cpu_revision
= (unsigned int) (SBREADCSR(A_SCD_SYSTEM_REVISION
) &
206 (M_SYS_PART
| M_SYS_REVISION
));
209 cfe_add_device(&sb1250_uart
,A_DUART
,0,0);
210 cfe_add_device(&promice_uart
,PROMICE_BASE
,PROMICE_WORDSIZE
,0);
213 /* VGA console, for the truly adventurous! */
214 cfe_add_device(&pcconsole2
,0,0,0);
218 * Read the config switch and decide how we are going to set up
219 * the console. This is actually board revision dependent.
221 * Note that the human-readable board revision is (swarm_board_rev+1).
223 swarm_board_rev
= G_SYS_CONFIG(syscfg
) & 0x3;
224 switch (swarm_board_rev
) {
227 * Board revision 0. The config switch sets bits 3..5 of the
228 * SYS_CONFIG field of the syscfg register.
230 swarm_config_switch
= (G_SYS_CONFIG(syscfg
) >> 3) & 0x07;
235 * In later board revisions, the config switch sets bits 2..5.
237 swarm_config_switch
= (G_SYS_CONFIG(syscfg
) >> 2) & 0x0f;
241 cfe_startflags
= swarm_startflags
[swarm_config_switch
];
244 * Choose which console we're going to use. Our three choices
245 * are the PromICE AI2 port, the "VGA" console, and
248 * The UART is the "normal" console, of course.
251 if (cfe_startflags
& SWARM_PROMICE_CONSOLE
) {
252 cfe_set_console("promice0");
256 * If VGA console, "buffer" the console messages until the
259 else if (cfe_startflags
& SWARM_VGA_CONSOLE
) {
260 cfe_set_console(CFE_BUFFER_CONSOLE
);
264 cfe_set_console("uart0");
268 * Set variable that contains CPU speed, spit out config register
271 plldiv
= G_SYS_PLL_DIV(syscfg
);
277 cfe_cpu_speed
= 500000; /* wire func sim at 500KHz */
279 cfe_cpu_speed
= 50000000 * plldiv
; /* use PLL divisor */
283 * NVRAM (environment variables - These depend on the SWARM
284 * board version since SWARM rev3 (and later) do not have Xicor
285 * clock chips. Instead, a second 24lc128 is on SMBus 1.
288 switch (swarm_board_rev
) {
291 cfe_add_device(&sb1250_x1240eeprom
,X1240_SMBUS_CHAN
,X1240_SMBUS_DEV
,0);
295 cfe_add_device(&sb1250_24lc128eeprom
,BIGEEPROM_SMBUS_CHAN_1
,BIGEEPROM_SMBUS_DEV_1
,0);
299 cfe_set_envdevice("eeprom0"); /* Connect NVRAM subsystem to EEPROM */
303 /* *********************************************************************
304 * board_smbus_waitready(chan)
306 * Wait until the SMBus channel is ready. We simply poll
307 * the busy bit until it clears.
310 * chan - channel (0 or 1)
314 ********************************************************************* */
315 static int board_smbus_waitready(int chan
)
320 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_STATUS
));
323 status
= SBREADCSR(reg
);
324 if (status
& M_SMB_BUSY
) continue;
328 if (status
& M_SMB_ERROR
) {
330 SBWRITECSR(reg
,(status
& M_SMB_ERROR
));
336 /* *********************************************************************
337 * board_probe_x1241(chan,dev)
339 * Probe for a Xicor X1241 at the specified device and channel.
341 * Actually, we just probe for anything at this address, and
342 * assume it's a Xicor.
345 * chan - SMBus channel
349 * TRUE - X1241 is present
350 * FALSE - not present
351 ********************************************************************* */
353 static int board_probe_x1241(int chan
,int slaveaddr
)
360 * Initialize the SMBus channel
363 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_FREQ
));
365 SBWRITECSR(reg
,K_SMB_FREQ_400KHZ
);
367 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_CONTROL
));
369 SBWRITECSR(reg
,0); /* not in direct mode, no interrupts, will poll */
372 * Make sure the bus is idle (probably should
376 if (board_smbus_waitready(chan
) < 0) return FALSE
;
379 * Write the device address to the controller. There are two
380 * parts, the high part goes in the "CMD" field, and the
381 * low part is the data field.
384 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_CMD
));
385 SBWRITECSR(reg
,((devaddr
>> 8) & 0x7));
388 * Write the data to the controller
391 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_DATA
));
392 SBWRITECSR(reg
,((devaddr
& 0xFF) & 0xFF));
398 reg
= PHYS_TO_K1(A_SMB_REGISTER(chan
,R_SMB_START
));
399 SBWRITECSR(reg
,V_SMB_TT(K_SMB_TT_WR2BYTE
) | slaveaddr
);
405 err
= board_smbus_waitready(chan
);
406 if (err
< 0) return FALSE
;
410 /* *********************************************************************
411 * board_device_init()
413 * Initialize and add other devices. Add everything you need
414 * for bootstrap here, like disk drives, flash memory, UARTs,
415 * network controllers, etc.
422 ********************************************************************* */
424 void board_device_init(void)
427 * Print out the board version number.
429 printf("%s board revision %d\n", CFG_BOARDNAME
, swarm_board_rev
+ 1);
435 cfe_add_device(&sb1250_uart
,A_DUART
,1,0);
438 * Boot ROM, using "new" flash driver
441 cfe_add_device(&newflashdrv
,
443 REAL_BOOTROM_SIZE
| FLASH_FLG_BUS8
| FLASH_FLG_DEV16
,
445 cfe_add_device(&newflashdrv
,
447 REAL_BOOTROM_SIZE
| FLASH_FLG_BUS8
| FLASH_FLG_DEV16
,
452 * As a hack, we instantiate another flash at 0x1100_0000 (the PCMCIA area)
453 * when running in the functional simulator. We can preload an image into
454 * that region for faster booting. (see build/broadcom/sim/runcfe)
456 cfe_add_device(&newflashdrv
,0x11000000,64*1024*1024,NULL
);
460 * This is the 24LC128 on SMBus0. CFE doesn't use it for anything,
461 * but you can load data into it and then boot from it by changing a jumper.
464 cfe_add_device(&sb1250_24lc128eeprom
,BIGEEPROM_SMBUS_CHAN
,BIGEEPROM_SMBUS_DEV
,0);
467 * MACs - must init after environment, since the hw address is stored there
470 cfe_add_device(&sb1250_ether
,A_MAC_BASE_0
,0,env_getenv("ETH0_HWADDR"));
471 cfe_add_device(&sb1250_ether
,A_MAC_BASE_1
,1,env_getenv("ETH1_HWADDR"));
477 cfe_add_device(&idedrv
,IDE_PHYS
+(0x1F0<<5),
478 IDE_PROBE_MASTER_TYPE(IDE_DEVTYPE_DISK
) |
479 IDE_PROBE_SLAVE_TYPE(IDE_DEVTYPE_NOPROBE
),
486 cfe_add_device(&pcmciadrv
,PCMCIA_PHYS
,0,NULL
);
489 pci_add_devices(cfe_startflags
& CFE_INIT_PCI
);
493 * Clock - depends on the hardware version number, since the older
494 * boards have Xicor clocks and the newer boards have ST Micro parts.
497 switch (swarm_board_rev
) {
499 cfe_add_device(&x1241_clock
,X1240_SMBUS_CHAN
,X1240_SMBUS_DEV
,0);
505 if (board_probe_x1241(X1240_SMBUS_CHAN
,X1240_SMBUS_DEV
)) {
506 cfe_add_device(&x1241_clock
,X1240_SMBUS_CHAN
,X1240_SMBUS_DEV
,0);
509 /* Add ST Micro clock driver here */
510 cfe_add_device(&m41t81_clock
,M41T81_SMBUS_CHAN
,M41T81_SMBUS_DEV
,0);
516 * VGA Console - try to init a VGA console, fall back to
520 if (cfe_startflags
& SWARM_VGA_CONSOLE
) {
522 vgainit_ok
= vga_biosinit();
523 if (vgainit_ok
== 0) cfe_set_console("pcconsole0");
524 else cfe_set_console("uart0");
530 * Set variable that contains CPU speed, spit out config register
533 printf("Config switch: %d\n", swarm_config_switch
);
535 sb1250_show_cpu_type();
538 * Reset the MAC address for MAC 2, since it's hooked
539 * to the video codec. This prevents the OS from
542 SBWRITECSR(A_MAC_REGISTER(2,R_MAC_ETHERNET_ADDR
),0);
545 * Some misc devices go here, mostly for playing.
549 cfe_add_device(&tcpconsole
,0,0,0);
554 cfe_add_device(&usb_disk
,0,0,0);
555 cfe_add_device(&usb_uart
,0,0,0);
561 /* *********************************************************************
562 * board_device_reset()
564 * Reset devices. This call is done when the firmware is restarted,
565 * as might happen when an operating system exits, just before the
566 * "reset" command is applied to the installed devices. You can
567 * do whatever board-specific things are here to keep the system
568 * stable, like stopping DMA sources, interrupts, etc.
575 ********************************************************************* */
577 void board_device_reset(void)
580 * Reset the MAC address for MAC 2, since it's hooked
581 * to the video codec. This prevents the OS from
584 SBWRITECSR(A_MAC_REGISTER(2,R_MAC_ETHERNET_ADDR
),0);
588 /* *********************************************************************
589 * board_setup_autoboot()
591 * Set up autoboot methods. This routine sets up the list of
592 * places to find a boot program.
599 ********************************************************************* */
600 static void board_setup_autoboot(void)
603 * First try PCMCIA. Try to load an elf file called 'autoboot'
604 * from the root directory of the FAT filesystem on the PCMCIA card.
607 cfe_add_autoboot(CFE_AUTOBOOT_DISK
,0,"pcmcia0","elf","fat","autoboot");
610 * Uncomment to try IDE next. We leave this disabled for now due
611 * to the long timeout if you don't have an IDE disk connected.
614 /* cfe_add_autoboot(CFE_AUTOBOOT_DISK,0,"ide0.0","raw","raw",NULL); */
617 * If you had partitioned your flash, you could boot from it like this:
620 /* cfe_add_autoboot(CFE_AUTOBOOT_RAW,0,"flash0.os","elf","raw",NULL); */
623 * Now try running a script (file containing CFE commands) from
624 * the TFTP server. Your DHCP server must set option 130
625 * to contain the name of the script. Option 130 gets stored
626 * in "BOOT_SCRIPT" when a DHCP reply is received.
629 cfe_add_autoboot(CFE_AUTOBOOT_NETWORK
,LOADFLG_BATCH
,
630 "eth0","raw","tftp","$BOOT_SERVER:$BOOT_SCRIPT");
633 * Finally, try loading whatever the DHCP server says is the boot
634 * program. Do this as an ELF file, and failing that, try a
638 cfe_add_autoboot(CFE_AUTOBOOT_NETWORK
,0,"eth0","elf","tftp",NULL
);
639 cfe_add_autoboot(CFE_AUTOBOOT_NETWORK
,0,"eth0","raw","tftp",NULL
);
643 /* *********************************************************************
646 * Do any final initialization, such as adding commands to the
649 * If you don't want a user interface, put the startup code here.
650 * This routine is called just before CFE starts its user interface.
657 ********************************************************************* */
659 void board_final_init(void)
666 ui_init_toyclockcmds();
667 ui_init_tempsensorcmds();
668 ui_init_memtestcmds();
675 ui_init_disktestcmds();
676 ui_init_ethertestcmds();
677 ui_init_flashtestcmds();
679 board_setup_autoboot();