allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / cfe / cfe / arch / mips / board / pt1125 / src / pt1125_devs.c
blob86959a2aad515c8550828361b5834a76addab35b
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Board device initialization File: pt1125_devs.c
5 *
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.
9 *
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 * modification history
13 * --------------------
14 * 01a,01aug02,gtb derived from pt1125_devs.c
18 *********************************************************************
20 * Copyright 2000,2001
21 * Broadcom Corporation. All rights reserved.
23 * This software is furnished under license and may be used and
24 * copied only in accordance with the following terms and
25 * conditions. Subject to these conditions, you may download,
26 * copy, install, use, modify and distribute modified or unmodified
27 * copies of this software in source and/or binary form. No title
28 * or ownership is transferred hereby.
30 * 1) Any source code used, modified or distributed must reproduce
31 * and retain this copyright notice and list of conditions as
32 * they appear in the source file.
34 * 2) No right is granted to use any trade name, trademark, or
35 * logo of Broadcom Corporation. Neither the "Broadcom
36 * Corporation" name nor any trademark or logo of Broadcom
37 * Corporation may be used to endorse or promote products
38 * derived from this software without the prior written
39 * permission of Broadcom Corporation.
41 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
42 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
43 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
44 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
45 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
46 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
47 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
48 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
50 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
51 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
52 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
53 * THE POSSIBILITY OF SUCH DAMAGE.
54 ********************************************************************* */
58 #include "sbmips.h"
59 #include "lib_types.h"
60 #include "lib_queue.h"
61 #include "lib_printf.h"
62 #include "lib_string.h"
63 #include "cfe_iocb.h"
64 #include "cfe_device.h"
65 #include "cfe_timer.h"
66 #include "dev_ptflash.h"
67 #include "env_subr.h"
68 #include "cfe.h"
70 #include "sb1250_defs.h"
71 #include "sb1250_regs.h"
72 #include "sb1250_pci.h"
73 #include "sb1250_ldt.h"
74 #include "sb1250_scd.h"
75 #include "sb1250_wid.h"
76 #include "sb1250_smbus.h"
78 #include "bsp_config.h"
80 #include "pt1125.h"
81 #include "dev_ide.h"
83 /* *********************************************************************
84 * Devices we're importing
85 ********************************************************************* */
86 extern cfe_driver_t ns16550_uart; /* external UART on the I/O bus */
87 extern cfe_driver_t promice_uart; /* promice serial port */
88 extern cfe_driver_t sb1250_uart; /* SB1250 serial ports */
89 extern cfe_driver_t sb1250_ether; /* SB1250 MACs */
90 extern cfe_driver_t sb1250_x1240eeprom; /* Xicor SMBus NVRAM */
91 extern cfe_driver_t sb1250_24lc128eeprom; /* Microchip EEPROM */
92 extern cfe_driver_t ptflashdrv; /* AMD-style flash */
93 extern cfe_driver_t ptflashdrv_ro; /* AMD-style flash */
95 extern cfe_driver_t m41t81_clock; /* M41T81 SMBus RTC */
98 extern void ui_init_cpu1cmds(void);
99 extern void ui_init_swarmcmds(void);
100 extern int ui_init_corecmds(void);
101 extern int ui_init_soccmds(void);
102 extern int ui_init_testcmds(void);
103 extern int ui_init_resetcmds(void);
104 extern int ui_init_tempsensorcmds(void);
105 extern int ui_init_toyclockcmds(void);
106 extern void cs0_remap(void);
107 extern void cs1_remap(void);
109 extern void sb1250_show_cpu_type(void);
111 /* *********************************************************************
112 * Forward declarations
113 ********************************************************************* */
114 static void bootrom_add(unsigned int addr);
115 static void alt_bootrom_add(unsigned int addr);
117 /* *********************************************************************
118 * Some board-specific parameters
119 ********************************************************************* */
122 * Note! Configure the PROMICE for burst mode zero (one byte per
123 * access).
126 #define PROMICE_BASE (0x1FDFFC00)
127 #define PROMICE_WORDSIZE 1
129 /* *********************************************************************
130 * SysConfig switch settings
131 ********************************************************************* */
133 #define PT1125_PROMICE_CONSOLE 0x00000001
134 #define PT1125_EXTERNAL_UART_CONSOLE 0x00000002
135 #define PT1125_INTERNAL_UART_CONSOLE 0x00000004
136 #define PT1125_PROMICE_BOOT 0x00000008
139 * There are 8 possible configurations of CFE. They are redundant -- so
140 * customize as you like. The default configuration of '7' is set by the
141 * FPGA as of when the file was created. The FPGA sets the six-bit config
142 * field of the * system config register 0x39. CFE uses the upper 3 bits,
143 * which are all set, giving array index 7.
145 const unsigned int pt1125_startflags[8] = {
146 PT1125_EXTERNAL_UART_CONSOLE, /* 0 : External UART console */
147 PT1125_PROMICE_CONSOLE, /* 1 : PromICE console */
148 PT1125_INTERNAL_UART_CONSOLE, /* 2 : Internal UART console */
149 PT1125_EXTERNAL_UART_CONSOLE, /* 3 : External UART console */
150 CFE_INIT_PCI | CFE_LDT_SLAVE | PT1125_EXTERNAL_UART_CONSOLE, /* 4:ext UART,PCI.LDT slave*/
151 CFE_INIT_PCI | PT1125_EXTERNAL_UART_CONSOLE, /* 5:ext UART,PCI*/
152 CFE_INIT_PCI | PT1125_EXTERNAL_UART_CONSOLE | PT1125_PROMICE_BOOT, /* 6 */
153 CFE_INIT_SAFE | PT1125_EXTERNAL_UART_CONSOLE /* 7 : External UART console, safe mode */
158 /* *********************************************************************
159 * board_console_init()
161 * Add the console device and set it to be the primary
162 * console.
164 * Input parameters:
165 * nothing
167 * Return value:
168 * nothing
169 ********************************************************************* */
171 void board_console_init(void)
173 uint64_t syscfg;
174 unsigned temp;
175 int plldiv;
177 syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
180 * External UART is device "uart0". On the PT1125 it's the connector
181 * nearest the motherboard.
184 cfe_add_device(&ns16550_uart,UART_PHYS,0,0);
186 /* Internal UART0 is device "uart1" */
188 cfe_add_device(&sb1250_uart,A_DUART,0,0);
190 /* Add the PromICE UART, device "promice0", for good measure */
192 cfe_add_device(&promice_uart,PROMICE_BASE,PROMICE_WORDSIZE,0);
195 * Get the CFE startflags from the upper 3 bits of the "config" field
196 * in the sysconfig register. Only 3 bits are used, because that's
197 * what the CSWARM does.
200 cfe_startflags = pt1125_startflags[(G_SYS_CONFIG(syscfg)/8) & 0x07];
202 if (cfe_startflags & PT1125_PROMICE_CONSOLE) {
203 cfe_set_console("promice0");
205 else if (cfe_startflags & PT1125_INTERNAL_UART_CONSOLE) {
206 cfe_set_console("uart1");
208 else {
209 cfe_set_console("uart0");
213 * Set variable that contains CPU speed, spit out config register
216 plldiv = G_SYS_PLL_DIV(syscfg);
218 cfe_cpu_speed = 50000000 * plldiv;
221 * NVRAM (environment variables
224 cfe_add_device(&sb1250_24lc128eeprom,BIGEEPROM_SMBUS_CHAN,BIGEEPROM_SMBUS_DEV,0);
228 * Turn off the safe flag so the ethernet MAC addresses will get read
229 * from NVRAM
231 temp = cfe_startflags;
232 cfe_startflags &= ~CFE_INIT_SAFE;
234 cfe_set_envdevice("eeprom0"); /* Connect NVRAM subsystem to EEPROM */
236 /* restore SAFE flag if it was set */
237 cfe_startflags = temp;
242 /* *********************************************************************
243 * bootrom_add()
245 * Add the physical flash device to the system
247 * Input parameters:
248 * nothing
250 * Return value:
251 * nothing
252 ********************************************************************* */
254 void bootrom_add(unsigned int addr)
256 #ifndef OLD_FLASHDRV
257 flash_probe_t flashdesc;
258 memset(&flashdesc,0,sizeof(flash_probe_t));
259 flashdesc.flash_phys = addr;
260 flashdesc.flash_size = BOOTROM_SIZE*K64;
261 flashdesc.flash_flags = FLASH_FLG_WIDE;
262 flashdesc.nchips = BOOTROM_NCHIPS;
263 flashdesc.chipsize = BOOTROM_CHIPSIZE;
264 cfe_add_device(&ptflashdrv,NULL,NULL,&flashdesc);
265 memset(&flashdesc,0,sizeof(flash_probe_t));
266 flashdesc.flash_phys = addr;
267 flashdesc.flash_size = BOOTROM_SIZE*K64;
268 flashdesc.flash_flags = FLASH_FLG_WIDE | FLASH_FLG_MANUAL;
269 flashdesc.flash_cmdset = 0x12345678;
270 cfe_add_device(&ptflashdrv_ro,NULL,NULL,&flashdesc);
271 #else
272 cfe_add_device(&ptflashdrv,BOOTROM_PHYS,BOOTROM_SIZE*K64,NULL);
273 #endif
275 /* *********************************************************************
276 * alt_bootrom_add()
278 * Add the promice device to the system as flash
280 * Input parameters:
281 * nothing
283 * Return value:
284 * nothing
285 ********************************************************************* */
287 void alt_bootrom_add(unsigned int addr)
289 #ifndef OLD_FLASHDRV
290 flash_probe_t flashdesc;
291 /* When CS0 is jumped to PromICE, this will be flash */
292 memset(&flashdesc,0,sizeof(flash_probe_t));
293 flashdesc.flash_phys = addr;
294 flashdesc.flash_size = ALT_BOOTROM_SIZE*K64;
295 flashdesc.flash_flags = FLASH_FLG_WIDE;
296 flashdesc.nchips = ALT_BOOTROM_NCHIPS;
297 flashdesc.chipsize = ALT_BOOTROM_CHIPSIZE;
298 cfe_add_device(&ptflashdrv,NULL,NULL,&flashdesc);
299 #else
300 cfe_add_device(&ptflashdrv,ALT_BOOTROM_PHYS,ALT_BOOTROM_SIZE*K64,NULL);
301 #endif
305 /* *********************************************************************
306 * board_device_init()
308 * Initialize and add other devices. Add everything you need
309 * for bootstrap here, like disk drives, flash memory, UARTs,
310 * network controllers, etc.
312 * Input parameters:
313 * nothing
315 * Return value:
316 * nothing
317 ********************************************************************* */
319 void board_device_init(void)
321 uint64_t syscfg;
322 int promice_boot;
325 * Boot ROM
328 syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
329 promice_boot = pt1125_startflags[(G_SYS_CONFIG(syscfg)/8) & 0x07] & \
330 PT1125_PROMICE_BOOT;
333 * Don't remap chip select 0 when using PromICE, since
334 * PromICE only emulates 2 Meg and we set ALT_BOOTROM
335 * to 2 Meg
337 if (!promice_boot)
339 cs0_remap(); /* Expand CS0 -- this is bootrom and flash */
340 bootrom_add(BOOTROM_PHYS);
341 alt_bootrom_add(ALT_BOOTROM_PHYS);
343 else
345 cs1_remap(); /* Expand CS1 -- it's all flash */
346 alt_bootrom_add(BOOTROM_PHYS);
347 bootrom_add(ALT_BOOTROM_PHYS);
350 cfe_add_device(&m41t81_clock,M41T81_SMBUS_CHAN,M41T81_SMBUS_DEV,0);
353 * MACs - must init after environment, since the hw address is stored there
355 cfe_add_device(&sb1250_ether,A_MAC_BASE_0,0,env_getenv("ETH0_HWADDR"));
356 #ifndef _PT1125_DIAG_CFG_
357 cfe_add_device(&sb1250_ether,A_MAC_BASE_1,1,env_getenv("ETH1_HWADDR"));
358 #endif
363 * Set variable that contains CPU speed, spit out config register
366 syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
367 printf("Config switch: %d\n",G_SYS_CONFIG(syscfg));
370 * Display CPU status
373 sb1250_show_cpu_type();
379 /* *********************************************************************
380 * board_device_reset()
382 * Reset devices. This call is done when the firmware is restarted,
383 * as might happen when an operating system exits, just before the
384 * "reset" command is applied to the installed devices. You can
385 * do whatever board-specific things are here to keep the system
386 * stable, like stopping DMA sources, interrupts, etc.
388 * Input parameters:
389 * nothing
391 * Return value:
392 * nothing
393 ********************************************************************* */
395 void board_device_reset(void)
401 /* *********************************************************************
402 * board_final_init()
404 * Do any final initialization, such as adding commands to the
405 * user interface.
407 * If you don't want a user interface, put the startup code here.
408 * This routine is called just before CFE starts its user interface.
410 * Input parameters:
411 * nothing
413 * Return value:
414 * nothing
415 ********************************************************************* */
417 void board_final_init(void)
419 ui_init_cpu1cmds();
420 ui_init_swarmcmds();
421 ui_init_corecmds();
422 ui_init_soccmds();
423 ui_init_testcmds();
424 ui_init_resetcmds();
425 ui_init_tempsensorcmds();
426 ui_init_toyclockcmds();