1 /***************************************************************************
2 * Broadcom Corp. Confidential
3 * Copyright 2001 Broadcom Corp. All Rights Reserved.
5 * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED
6 * SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM.
7 * YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT
8 * SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10 ***************************************************************************
11 * File Name : board_api.c
13 * Description: interface for board level calls: flash,
14 * led, soft reset, free memory page, and memory dump.
15 * Adapted form flash_api.c by Yen Tran.
17 * Created on : 02/20/2002 seanl
19 ***************************************************************************/
24 #include <fcntl.h> /* open */
25 #include <unistd.h> /* exit */
26 #include <sys/ioctl.h> /* ioctl */
30 #include <board_api.h>
32 int boardIoctl(int board_ioctl, BOARD_IOCTL_ACTION action, char *string, int strLen, int offset, char *buf)
34 BOARD_IOCTL_PARMS IoctlParms;
37 boardFd = open("/dev/brcmboard", O_RDWR);
38 if ( boardFd != -1 ) {
39 IoctlParms.string = string;
40 IoctlParms.strLen = strLen;
41 IoctlParms.offset = offset;
42 IoctlParms.action = action;
44 ioctl(boardFd, board_ioctl, &IoctlParms);
46 boardFd = IoctlParms.result;
48 printf("Unable to open device /dev/brcmboard.\n");
55 /*****************************************************************************
56 * sysScratchPadGet - get the contents of persistent stratch pad flash memory
57 * INPUT: tokenId -- token id, ASCIZ tokBuf (up to 15 char)
60 * RETURNS: 0 - ok, -1 fail.
62 int sysScratchPadGet(char *tokenId, char *tokBuf, int bufLen)
64 return (boardIoctl(BOARD_IOCTL_FLASH_READ, SCRATCH_PAD, tokenId, bufLen, bufLen, tokBuf));
67 /*****************************************************************************
68 * sysScratchPadSet - write the contents of persistent scratch pad flash memory
69 * INPUT: tokenId -- token id, ASCIZ tokBuf (up to 15 char)
72 * RETURNS: 0 - ok, -1 fail.
74 int sysScratchPadSet(char *tokenId, char *tokBuf, int bufLen)
76 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, SCRATCH_PAD, tokenId, bufLen, bufLen, tokBuf));
80 /*****************************************************************************
81 * sysPersistentGet - get the contents of non-volatile RAM,
82 * RETURNS: OK, always.
84 int sysNvRamGet(char *string, int strLen, int offset)
86 return (boardIoctl(BOARD_IOCTL_FLASH_READ, NVRAM, string, strLen, offset, ""));
89 /*****************************************************************************
90 * sysPersistentSet - write the contents of non-volatile RAM
91 * RETURNS: OK, always.
93 int sysNvRamSet(char *string, int strLen, int offset)
95 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, NVRAM, string, strLen, offset, ""));
98 /*****************************************************************************
99 * sysNrPagesGet - returns number of free system pages. Each page is 4K bytes.
100 * RETURNS: Number of 4K pages.
102 int sysNrPagesGet(void)
104 return (boardIoctl(BOARD_IOCTL_GET_NR_PAGES, 0, "", 0, 0, ""));
107 /*****************************************************************************
108 * sysDumpAddr - Dump kernel memory.
109 * RETURNS: OK, always.
111 int sysDumpAddr(char *addr, int len)
113 return (boardIoctl(BOARD_IOCTL_DUMP_ADDR, 0, addr, len, 0, ""));
116 /*****************************************************************************
117 * sysDumpAddr - Set kernel memory.
118 * RETURNS: OK, always.
120 int sysSetMemory(char *addr, int size, unsigned long value )
122 return (boardIoctl(BOARD_IOCTL_SET_MEMORY, 0, addr, size, (int) value, ""));
125 /*****************************************************************************
126 * image points to image to be programmed to flash; size is the size (in bytes)
128 * if error, return -1; otherwise return 0
133 /*****************************************************************************
134 * sysPersistentGet - get the contents of persistent flash memory
135 * RETURNS: OK, always.
137 int sysPersistentGet(char *string, int strLen, int offset)
139 return (boardIoctl(BOARD_IOCTL_FLASH_READ, PERSISTENT, string, strLen, offset, ""));
142 /*****************************************************************************
143 * sysPersistenSet - write the contents of persistent Scrach Pad flash memory
144 * RETURNS: OK, always.
146 int sysPersistentSet(char *string, int strLen, int offset)
148 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, PERSISTENT, string, strLen, offset, ""));
151 //********************************************************************************
153 //********************************************************************************
154 int sysGetPsiSize( void )
156 return( boardIoctl(BOARD_IOCTL_GET_PSI_SIZE, 0, "", 0, 0, "") );
159 int sysFlashImageSet(void *image, int size, int addr,
160 BOARD_IOCTL_ACTION imageType)
164 result = boardIoctl(BOARD_IOCTL_FLASH_WRITE, imageType, image, size, addr, "");
169 /*****************************************************************************
171 * return int flash size
173 int sysFlashSizeGet(void)
175 return (boardIoctl(BOARD_IOCTL_FLASH_READ, FLASH_SIZE, "", 0, 0, ""));
178 /*****************************************************************************
179 * kerSysMipsSoftReset - soft reset the mips. (reboot, go to 0xbfc00000)
182 void sysMipsSoftReset(void)
184 boardIoctl(BOARD_IOCTL_MIPS_SOFT_RESET, 0, "", 0, 0, "");
187 //********************************************************************************
189 //********************************************************************************
190 int sysGetChipId( void )
192 return( boardIoctl(BOARD_IOCTL_GET_CHIP_ID, 0, "", 0, 0, "") );
195 //********************************************************************************
196 // Wakeup monitor task
197 //********************************************************************************
198 void sysWakeupMonitorTask(void)
200 return (boardIoctl(BOARD_IOCTL_WAKEUP_MONITOR_TASK, 0, "", 0, 0, ""));
204 //********************************************************************************
205 // LED status display: ADSL link: DOWN/UP, PPP: DOWN/STARTING/UP
206 //********************************************************************************
207 void sysLedCtrl(BOARD_LED_NAME ledName, BOARD_LED_STATE ledState)
209 boardIoctl(BOARD_IOCTL_LED_CTRL, 0, "", (int)ledName, (int)ledState, "");
213 //********************************************************************************
215 //********************************************************************************
216 int sysGetBoardIdName(char *name, int length)
218 return( boardIoctl(BOARD_IOCTL_GET_ID, 0, name, length, 0, "") );
222 //********************************************************************************
224 //********************************************************************************
225 int sysGetMacAddress( unsigned char *pucaAddr, unsigned long ulId )
227 return(boardIoctl(BOARD_IOCTL_GET_MAC_ADDRESS, 0, pucaAddr, 6, (int) ulId, ""));
231 //********************************************************************************
232 // Release MAC Address
233 //********************************************************************************
234 int sysReleaseMacAddress( unsigned char *pucaAddr )
236 return( boardIoctl(BOARD_IOCTL_RELEASE_MAC_ADDRESS, 0, pucaAddr, 6, 0, "") );
240 //********************************************************************************
242 //********************************************************************************
243 int sysGetSdramSize( void )
245 return( boardIoctl(BOARD_IOCTL_GET_SDRAM_SIZE, 0, "", 0, 0, "") );
249 /*****************************************************************************
250 * sysGetBooline - get bootline
251 * RETURNS: OK, always.
253 int sysGetBootline(char *string, int strLen)
255 return (boardIoctl(BOARD_IOCTL_GET_BOOTLINE, 0, string, strLen, 0, ""));
258 /*****************************************************************************
259 * sysSetBootline - write the bootline to nvram
260 * RETURNS: OK, always.
262 int sysSetBootline(char *string, int strLen)
264 return (boardIoctl(BOARD_IOCTL_SET_BOOTLINE, 0, string, strLen, 0, ""));
267 //********************************************************************************
269 //********************************************************************************
270 int sysGetBaseMacAddress( unsigned char *pucaAddr )
272 return(boardIoctl(BOARD_IOCTL_GET_BASE_MAC_ADDRESS, 0, pucaAddr, 6, 0, ""));
275 //********************************************************************************
276 // Get number of Ethernet phys
277 //********************************************************************************
278 int sysGetNumEnet(void)
280 return(boardIoctl(BOARD_IOCTL_GET_NUM_ENET, 0, "", 0, 0, ""));
283 //********************************************************************************
284 // Get CFE vesion info
285 //********************************************************************************
286 int sysGetCFEVersion(char *string, int strLen)
288 return (boardIoctl(BOARD_IOCTL_GET_CFE_VER, 0, string, strLen, 0, ""));
291 //********************************************************************************
292 // Get board Ethernet configuration
293 //********************************************************************************
294 int sysGetEnetCfg(char *string, int strLen)
296 return(boardIoctl(BOARD_IOCTL_GET_ENET_CFG, 0, string, strLen, 0, ""));
298 //********************************************************************************
299 // Get Wi-Fi Country selection
300 //********************************************************************************
301 int sysGetCountry(char *string, int strLen)
303 return(boardIoctl(BOARD_IOCTL_GET_CNTRY_SEL, 0, string, strLen, 0, ""));
306 //********************************************************************************
307 // Set monitor loop file descriptor
308 //********************************************************************************
309 int sysSetMonitorFd(int fd)
311 return (boardIoctl(BOARD_IOCTL_SET_MONITOR_FD, 0, "", 0, fd, ""));