RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / cfe / cfe / arch / mips / board / bcm96345 / src / bcm6345_devs.c
blob5e4399bfd540748921eb193dca18c88d41a25560
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Board device initialization File: bcm94710_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 * XX Copyright 2000,2001
15 * Broadcom Corporation. All rights reserved.
17 * BROADCOM PROPRIETARY AND CONFIDENTIAL
19 * This software is furnished under license and may be used and
20 * copied only in accordance with the license.
21 ********************************************************************* */
23 #include "lib_types.h"
24 #include "lib_printf.h"
25 #include "cfe_timer.h"
26 #include "cfe.h"
27 #include "6345_map.h"
28 #include "board.h"
29 #include "bcmTag.h"
30 #include "dev_bcm63xx_flash.h"
31 #include "bcm63xx_util.h"
32 #include "cfiflash.h"
34 void checkForResetHold(void);
35 void kerSysMipsSoftReset(void);
36 int sysGetBoardId(void);
37 const char *get_system_type(void);
38 PFILE_TAG kerSysImageTagGet(void);
40 /* *********************************************************************
41 * Devices we're importing
42 ********************************************************************* */
44 extern cfe_driver_t bcm63xx_uart;
45 extern cfe_driver_t bcm6345_enet;
46 extern cfe_driver_t flashdrv;
48 /* *********************************************************************
49 * Some board-specific parameters
50 ********************************************************************* */
53 /* *********************************************************************
54 * board_console_init()
56 * Add the console device and set it to be the primary
57 * console.
59 * Input parameters:
60 * nothing
62 * Return value:
63 * nothing
64 ********************************************************************* */
66 void board_console_init(void)
68 /* Add the serial port driver. */
69 cfe_add_device(&bcm63xx_uart,0xFFFE0300,0,0);
71 cfe_set_console( "uart0" );
75 /* *********************************************************************
76 * board_device_init()
78 * Initialize and add other devices. Add everything you need
79 * for bootstrap here, like disk drives, flash memory, UARTs,
80 * network controllers, etc.
82 * Input parameters:
83 * nothing
85 * Return value:
86 * nothing
87 ********************************************************************* */
89 void board_device_init(void)
91 PFILE_TAG pTag = NULL;
93 /* Add the ethernet driver. */
94 cfe_add_device( &bcm6345_enet, 0, 0, 0);
96 kerSysFlashInit();
98 if ((pTag = kerSysImageTagGet()))
100 int flash_addr_kernel = atoi(pTag->kernelAddress) + TAG_LEN;
101 int flash_len_kernel = atoi(pTag->kernelLen);
102 if( flash_len_kernel > 0 )
103 cfe_add_device(&flashdrv, flash_addr_kernel, flash_len_kernel, NULL);
104 else
105 printf( "Kernel image not found on flash.\n" );
107 else
109 // Used to load an RTEMS image.
110 cfe_add_device(&flashdrv, FLASH45_IMAGE_START_ADDR, 0x100000, NULL);
111 printf("\r\n** Using flash start address 0x%8.8lx **\r\n\r\n",
112 FLASH45_IMAGE_START_ADDR);
118 /* *********************************************************************
119 * board_device_reset()
121 * Reset devices. This call is done when the firmware is restarted,
122 * as might happen when an operating system exits, just before the
123 * "reset" command is applied to the installed devices. You can
124 * do whatever board-specific things are here to keep the system
125 * stable, like stopping DMA sources, interrupts, etc.
127 * Input parameters:
128 * nothing
130 * Return value:
131 * nothing
132 ********************************************************************* */
134 void board_device_reset(void)
139 /* *********************************************************************
140 * board_final_init()
142 * Do any final initialization, such as adding commands to the
143 * user interface.
145 * If you don't want a user interface, put the startup code here.
146 * This routine is called just before CFE starts its user interface.
148 * Input parameters:
149 * nothing
151 * Return value:
152 * nothing
153 ********************************************************************* */
155 void board_final_init(void)
157 checkForResetHold();
158 bcm63xx_run();
161 /* *********************************************************************
162 * Miscellaneous Board Functions
163 ********************************************************************* */
165 /* *********************************************************************
166 * checkForResetHold()
168 * Determines if the user is holding the reset button in a depressed
169 * state for 3 seconds. If it is, default settings are restored.
171 * Input parameters:
172 * nothing
174 * Return value:
175 * nothing
176 ********************************************************************* */
178 void checkForResetHold(void)
180 const int nResetHoldDelay = 3;
181 int i;
183 for (i = 0; i < nResetHoldDelay; i++)
185 if ((GPIO->GPIOio & (unsigned short) GPIO_PRESS_AND_HOLD_RESET))
186 break;
187 cfe_sleep(CFE_HZ/2);
189 if (i == nResetHoldDelay)
191 printf("\n*** Restore to Factory Default Setting ***\n\n");
192 kerSysErasePsi();
193 flash_reset();
194 setDefaultBootline();
200 /* *********************************************************************
201 * kerSysMipsSoftReset()
203 * Resets the board.
205 * Input parameters:
206 * nothing
208 * Return value:
209 * nothing
210 ********************************************************************* */
211 void kerSysMipsSoftReset(void)
213 INTC->pll_control |= SOFT_RESET; // soft reset mips
216 /* *********************************************************************
217 * kerSysImageTagGet()
218 * Get the image tag
219 * Input parameters:
220 * none
221 * Return value:
222 * point to tag in flash -- Found
223 * NULL -- failed
224 ********************************************************************* */
225 PFILE_TAG kerSysImageTagGet(void)
227 int i;
228 int totalBlks = flash_get_numsectors();
229 UINT32 crc;
230 unsigned char *sectAddr;
231 PFILE_TAG pTag;
233 // start from 2nd blk, assume 1st one is always CFE
234 for (i = 2; i < totalBlks; i++)
236 sectAddr = flash_get_memptr((byte) i);
237 crc = CRC32_INIT_VALUE;
238 crc = getCrc32(sectAddr, (UINT32)TAG_LEN-TOKEN_LEN, crc);
239 pTag = (PFILE_TAG) sectAddr;
240 if (crc == (UINT32)(*(UINT32*)(pTag->tagValidationToken)))
241 return pTag;
244 return (PFILE_TAG) NULL;
247 /* *********************************************************************
248 * get_system_type()
250 * Returns board id constant.
252 * Input parameters:
253 * nothing
255 * Return value:
256 * Board id constant.
257 ********************************************************************* */
259 int sysGetBoardId( void )
261 GPIO->GPIODir &= (unsigned short) ~BOARD_ID_BCM9634X_MASK;
262 return( (int) (GPIO->GPIOio & BOARD_ID_BCM9634X_MASK) );
263 } /* sysGetBoardId */