BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / cfe / cfe / arch / mips / board / pt1120 / src / pt1120_devs.c
blobb175d8cb96849253ba1354eaf0c6cefb645a78c1
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Board device initialization File: pt1120_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,26jun02,gtb derived from ptswarm_devs.
15 * -Deleted intiatialization of 3rd ethernet port.
16 * -Added M41T81 SMBus RTC
17 * -NVRAM environment variables moved to
18 * eeprom on SMBus 0
21 *********************************************************************
23 * Copyright 2000,2001
24 * Broadcom Corporation. All rights reserved.
26 * This software is furnished under license and may be used and
27 * copied only in accordance with the following terms and
28 * conditions. Subject to these conditions, you may download,
29 * copy, install, use, modify and distribute modified or unmodified
30 * copies of this software in source and/or binary form. No title
31 * or ownership is transferred hereby.
33 * 1) Any source code used, modified or distributed must reproduce
34 * and retain this copyright notice and list of conditions as
35 * they appear in the source file.
37 * 2) No right is granted to use any trade name, trademark, or
38 * logo of Broadcom Corporation. Neither the "Broadcom
39 * Corporation" name nor any trademark or logo of Broadcom
40 * Corporation may be used to endorse or promote products
41 * derived from this software without the prior written
42 * permission of Broadcom Corporation.
44 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
46 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
47 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
48 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
49 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
51 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
52 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
53 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
54 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
55 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
57 ********************************************************************* */
61 #include "sbmips.h"
62 #include "lib_types.h"
63 #include "lib_queue.h"
64 #include "lib_printf.h"
65 #include "lib_string.h"
66 #include "cfe_iocb.h"
67 #include "cfe_device.h"
68 #include "cfe_timer.h"
69 #include "dev_ptflash.h"
70 #include "env_subr.h"
71 #include "cfe.h"
73 #include "sb1250_defs.h"
74 #include "sb1250_regs.h"
75 #include "sb1250_pci.h"
76 #include "sb1250_ldt.h"
77 #include "sb1250_scd.h"
78 #include "sb1250_wid.h"
79 #include "sb1250_smbus.h"
81 #include "bsp_config.h"
83 #include "pt1120.h"
84 #include "dev_ide.h"
86 /* *********************************************************************
87 * Devices we're importing
88 ********************************************************************* */
89 extern cfe_driver_t ns16550_uart; /* external UART on the I/O bus */
90 extern cfe_driver_t promice_uart; /* promice serial port */
91 extern cfe_driver_t sb1250_uart; /* SB1250 serial ports */
92 extern cfe_driver_t sb1250_ether; /* SB1250 MACs */
93 extern cfe_driver_t sb1250_x1240eeprom; /* Xicor SMBus NVRAM */
94 extern cfe_driver_t sb1250_24lc128eeprom; /* Microchip EEPROM */
95 extern cfe_driver_t ptflashdrv; /* AMD-style flash */
96 extern cfe_driver_t ptflashdrv_ro; /* AMD-style flash */
98 extern cfe_driver_t m41t81_clock; /* M41T81 SMBus RTC */
100 extern void ui_init_cpu1cmds(void);
101 extern void ui_init_swarmcmds(void);
102 extern int ui_init_corecmds(void);
103 extern int ui_init_soccmds(void);
104 extern int ui_init_testcmds(void);
105 extern int ui_init_resetcmds(void);
106 extern int ui_init_tempsensorcmds(void);
107 extern int ui_init_toyclockcmds(void);
108 extern void cs0_remap(void);
109 extern void cs1_remap(void);
111 extern void sb1250_show_cpu_type(void);
113 /* *********************************************************************
114 * Forward declarations
115 ********************************************************************* */
116 static void bootrom_add(unsigned int addr);
117 static void alt_bootrom_add(unsigned int addr);
119 /* *********************************************************************
120 * Some board-specific parameters
121 ********************************************************************* */
124 * Note! Configure the PROMICE for burst mode zero (one byte per
125 * access).
128 #define PROMICE_BASE (0x1FDFFC00)
129 #define PROMICE_WORDSIZE 1
131 /* *********************************************************************
132 * SysConfig switch settings
133 ********************************************************************* */
135 #define PT1120_PROMICE_CONSOLE 0x00000001
136 #define PT1120_EXTERNAL_UART_CONSOLE 0x00000002
137 #define PT1120_INTERNAL_UART_CONSOLE 0x00000004
138 #define PT1120_PROMICE_BOOT 0x00000008
141 * There are 8 possible configurations of CFE. They are redundant -- so
142 * customize as you like. The default configuration of '7' is set by the
143 * FPGA as of when the file was created. The FPGA sets the six-bit config
144 * field of the * system config register 0x39. CFE uses the upper 3 bits,
145 * which are all set, giving array index 7.
147 const unsigned int pt1120_startflags[8] = {
148 PT1120_EXTERNAL_UART_CONSOLE, /* 0 : External UART console */
149 PT1120_PROMICE_CONSOLE, /* 1 : PromICE console */
150 PT1120_INTERNAL_UART_CONSOLE, /* 2 : Internal UART console */
151 PT1120_EXTERNAL_UART_CONSOLE, /* 3 : External UART console */
152 PT1120_EXTERNAL_UART_CONSOLE, /* 4 : External UART Console */
153 PT1120_EXTERNAL_UART_CONSOLE, /* 5 : External UART Console */
154 PT1120_EXTERNAL_UART_CONSOLE | PT1120_PROMICE_BOOT, /* 6 */
155 CFE_INIT_SAFE | PT1120_EXTERNAL_UART_CONSOLE /* 7 : External UART console, safe mode */
160 /* *********************************************************************
161 * board_console_init()
163 * Add the console device and set it to be the primary
164 * console.
166 * Input parameters:
167 * nothing
169 * Return value:
170 * nothing
171 ********************************************************************* */
173 void board_console_init(void)
175 uint64_t syscfg;
176 unsigned temp;
177 int plldiv;
179 syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
182 * External UART is device "uart0". On the PT1120 it's the connector
183 * nearest the motherboard.
186 cfe_add_device(&ns16550_uart,UART_PHYS,0,0);
188 /* Internal UART0 is device "uart1" */
190 cfe_add_device(&sb1250_uart,A_DUART,0,0);
192 /* Add the PromICE UART, device "promice0", for good measure */
194 cfe_add_device(&promice_uart,PROMICE_BASE,PROMICE_WORDSIZE,0);
197 * Get the CFE startflags from the upper 3 bits of the "config" field
198 * in the sysconfig register. Only 3 bits are used, because that's
199 * what the CSWARM does.
202 cfe_startflags = pt1120_startflags[(G_SYS_CONFIG(syscfg)/8) & 0x07];
204 if (cfe_startflags & PT1120_PROMICE_CONSOLE) {
205 cfe_set_console("promice0");
207 else if (cfe_startflags & PT1120_INTERNAL_UART_CONSOLE) {
208 cfe_set_console("uart1");
210 else {
211 cfe_set_console("uart0");
215 * Set variable that contains CPU speed, spit out config register
218 plldiv = G_SYS_PLL_DIV(syscfg);
220 cfe_cpu_speed = 50000000 * plldiv;
223 * NVRAM (environment variables
226 cfe_add_device(&sb1250_24lc128eeprom,BIGEEPROM_SMBUS_CHAN,BIGEEPROM_SMBUS_DEV,0);
230 * Turn off the safe flag so the ethernet MAC addresses will get read
231 * from NVRAM
233 temp = cfe_startflags;
234 cfe_startflags &= ~CFE_INIT_SAFE;
236 cfe_set_envdevice("eeprom0"); /* Connect NVRAM subsystem to EEPROM */
238 /* restore SAFE flag if it was set */
239 cfe_startflags = temp;
244 /* *********************************************************************
245 * bootrom_add()
247 * Add the physical flash device to the system
249 * Input parameters:
250 * nothing
252 * Return value:
253 * nothing
254 ********************************************************************* */
256 void bootrom_add(unsigned int addr)
258 #ifndef OLD_FLASHDRV
259 flash_probe_t flashdesc;
260 memset(&flashdesc,0,sizeof(flash_probe_t));
261 flashdesc.flash_phys = addr;
262 flashdesc.flash_size = BOOTROM_SIZE*K64;
263 flashdesc.flash_flags = FLASH_FLG_WIDE;
264 flashdesc.nchips = BOOTROM_NCHIPS;
265 flashdesc.chipsize = BOOTROM_CHIPSIZE;
266 cfe_add_device(&ptflashdrv,NULL,NULL,&flashdesc);
267 memset(&flashdesc,0,sizeof(flash_probe_t));
268 flashdesc.flash_phys = addr;
269 flashdesc.flash_size = BOOTROM_SIZE*K64;
270 flashdesc.flash_flags = FLASH_FLG_WIDE | FLASH_FLG_MANUAL;
271 flashdesc.flash_cmdset = 0x12345678;
272 cfe_add_device(&ptflashdrv_ro,NULL,NULL,&flashdesc);
273 #else
274 cfe_add_device(&ptflashdrv,BOOTROM_PHYS,BOOTROM_SIZE*K64,NULL);
275 #endif
277 /* *********************************************************************
278 * alt_bootrom_add()
280 * Add the promice device to the system as flash
282 * Input parameters:
283 * nothing
285 * Return value:
286 * nothing
287 ********************************************************************* */
289 void alt_bootrom_add(unsigned int addr)
291 #ifndef OLD_FLASHDRV
292 flash_probe_t flashdesc;
293 /* When CS0 is jumped to PromICE, this will be flash */
294 memset(&flashdesc,0,sizeof(flash_probe_t));
295 flashdesc.flash_phys = addr;
296 flashdesc.flash_size = ALT_BOOTROM_SIZE*K64;
297 flashdesc.flash_flags = FLASH_FLG_WIDE;
298 flashdesc.nchips = ALT_BOOTROM_NCHIPS;
299 flashdesc.chipsize = ALT_BOOTROM_CHIPSIZE;
300 cfe_add_device(&ptflashdrv,NULL,NULL,&flashdesc);
301 #else
302 cfe_add_device(&ptflashdrv,ALT_BOOTROM_PHYS,ALT_BOOTROM_SIZE*K64,NULL);
303 #endif
307 /* *********************************************************************
308 * board_device_init()
310 * Initialize and add other devices. Add everything you need
311 * for bootstrap here, like disk drives, flash memory, UARTs,
312 * network controllers, etc.
314 * Input parameters:
315 * nothing
317 * Return value:
318 * nothing
319 ********************************************************************* */
321 void board_device_init(void)
323 uint64_t syscfg;
324 int promice_boot;
327 * Boot ROM
330 syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
331 promice_boot = pt1120_startflags[(G_SYS_CONFIG(syscfg)/8) & 0x07] & \
332 PT1120_PROMICE_BOOT;
335 * Don't remap chip select 0 when using PromICE, since
336 * PromICE only emulates 2 Meg and we set ALT_BOOTROM
337 * to 2 Meg
339 if (!promice_boot)
341 cs0_remap(); /* Expand CS0 -- this is bootrom and flash */
342 bootrom_add(BOOTROM_PHYS);
343 alt_bootrom_add(ALT_BOOTROM_PHYS);
345 else
347 cs1_remap(); /* Expand CS1 -- it's all flash */
348 alt_bootrom_add(BOOTROM_PHYS);
349 bootrom_add(ALT_BOOTROM_PHYS);
352 cfe_add_device(&m41t81_clock,M41T81_SMBUS_CHAN,M41T81_SMBUS_DEV,0);
355 * MACs - must init after environment, since the hw address is stored there
357 cfe_add_device(&sb1250_ether,A_MAC_BASE_0,0,env_getenv("ETH0_HWADDR"));
358 #ifndef _PT1120_DIAG_CFG_
359 cfe_add_device(&sb1250_ether,A_MAC_BASE_1,1,env_getenv("ETH1_HWADDR"));
360 #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();