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>
31 int boardIoctl(int board_ioctl, BOARD_IOCTL_ACTION action, char *string, int strLen, int offset, char *buf)
33 BOARD_IOCTL_PARMS IoctlParms;
36 boardFd = open("/dev/brcmboard", O_RDWR);
37 if ( boardFd != -1 ) {
38 IoctlParms.string = string;
39 IoctlParms.strLen = strLen;
40 IoctlParms.offset = offset;
41 IoctlParms.action = action;
43 ioctl(boardFd, board_ioctl, &IoctlParms);
45 boardFd = IoctlParms.result;
47 printf("Unable to open device /dev/brcmboard.\n");
54 /*****************************************************************************
55 * sysScratchPadGet - get the contents of persistent stratch pad flash memory
56 * INPUT: tokenId -- token id, ASCIZ tokBuf (up to 15 char)
59 * RETURNS: 0 - ok, -1 fail.
61 int sysScratchPadGet(char *tokenId, char *tokBuf, int bufLen)
63 return (boardIoctl(BOARD_IOCTL_FLASH_READ, SCRATCH_PAD, tokenId, bufLen, bufLen, tokBuf));
66 /*****************************************************************************
67 * sysScratchPadSet - write the contents of persistent scratch pad flash memory
68 * INPUT: tokenId -- token id, ASCIZ tokBuf (up to 15 char)
71 * RETURNS: 0 - ok, -1 fail.
73 int sysScratchPadSet(char *tokenId, char *tokBuf, int bufLen)
75 char *buf = malloc(bufLen);
77 //If the data associated with the tokenId already exists in the scratch pad,
78 //we don't want to set it again.
79 //Note that writing to the scratch pad is a non-preemptive time consuming
80 //operation that should be avoided.
82 boardIoctl(BOARD_IOCTL_FLASH_READ, SCRATCH_PAD, tokenId, bufLen, bufLen, buf) >= 0) {
83 if (bcmp(buf, tokBuf, bufLen) == 0) {
88 if (buf != NULL) free(buf);
90 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, SCRATCH_PAD, tokenId, bufLen, bufLen, tokBuf));
93 /*****************************************************************************
94 * sysScratchPadClearAll - wipeout the scratch pad
95 * RETURNS: 0 - ok, -1 fail.
97 int sysScratchPadClearAll(void)
99 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, SCRATCH_PAD, "", -1, -1, ""));
102 /*****************************************************************************
103 * sysPersistentGet - get the contents of non-volatile RAM,
104 * RETURNS: OK, always.
106 int sysNvRamGet(char *string, int strLen, int offset)
108 return (boardIoctl(BOARD_IOCTL_FLASH_READ, NVRAM, string, strLen, offset, ""));
113 /*****************************************************************************
114 * sysPersistentSet - write the contents of non-volatile RAM
115 * RETURNS: OK, always.
117 int sysNvRamSet(char *string, int strLen, int offset)
119 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, NVRAM, string, strLen, offset, ""));
122 /*****************************************************************************
123 * sysNrPagesGet - returns number of free system pages. Each page is 4K bytes.
124 * RETURNS: Number of 4K pages.
126 int sysNrPagesGet(void)
128 return (boardIoctl(BOARD_IOCTL_GET_NR_PAGES, 0, "", 0, 0, ""));
131 /*****************************************************************************
132 * sysDumpAddr - Dump kernel memory.
133 * RETURNS: OK, always.
135 int sysDumpAddr(char *addr, int len)
137 return (boardIoctl(BOARD_IOCTL_DUMP_ADDR, 0, addr, len, 0, ""));
140 /*****************************************************************************
141 * sysDumpAddr - Set kernel memory.
142 * RETURNS: OK, always.
144 int sysSetMemory(char *addr, int size, unsigned long value )
146 return (boardIoctl(BOARD_IOCTL_SET_MEMORY, 0, addr, size, (int) value, ""));
149 /*****************************************************************************
150 * image points to image to be programmed to flash; size is the size (in bytes)
152 * if error, return -1; otherwise return 0
157 /*****************************************************************************
158 * sysPersistentGet - get the contents of persistent flash memory
159 * RETURNS: OK, always.
161 int sysPersistentGet(char *string, int strLen, int offset)
163 return (boardIoctl(BOARD_IOCTL_FLASH_READ, PERSISTENT, string, strLen, offset, ""));
166 /*****************************************************************************
167 * sysPersistenSet - write the contents of persistent Scrach Pad flash memory
168 * RETURNS: OK, always.
170 int sysPersistentSet(char *string, int strLen, int offset)
172 return (boardIoctl(BOARD_IOCTL_FLASH_WRITE, PERSISTENT, string, strLen, offset, ""));
175 //********************************************************************************
177 //********************************************************************************
178 int sysGetPsiSize( void )
180 return( boardIoctl(BOARD_IOCTL_GET_PSI_SIZE, 0, "", 0, 0, "") );
183 int sysFlashImageSet(void *image, int size, int addr,
184 BOARD_IOCTL_ACTION imageType)
188 result = boardIoctl(BOARD_IOCTL_FLASH_WRITE, imageType, image, size, addr, "");
193 /*****************************************************************************
195 * return int flash size
197 int sysFlashSizeGet(void)
199 return (boardIoctl(BOARD_IOCTL_FLASH_READ, FLASH_SIZE, "", 0, 0, ""));
202 /*****************************************************************************
203 * kerSysMipsSoftReset - soft reset the mips. (reboot, go to 0xbfc00000)
206 void sysMipsSoftReset(void)
208 boardIoctl(BOARD_IOCTL_MIPS_SOFT_RESET, 0, "", 0, 0, "");
211 //********************************************************************************
213 //********************************************************************************
214 int sysGetChipId( void )
216 return( boardIoctl(BOARD_IOCTL_GET_CHIP_ID, 0, "", 0, 0, "") );
219 //********************************************************************************
220 // Wakeup monitor task
221 //********************************************************************************
222 void sysWakeupMonitorTask(void)
224 boardIoctl(BOARD_IOCTL_WAKEUP_MONITOR_TASK, 0, "", 0, 0, "");
228 //********************************************************************************
229 // LED status display: ADSL link: DOWN/UP, PPP: DOWN/STARTING/UP
230 //********************************************************************************
231 void sysLedCtrl(BOARD_LED_NAME ledName, BOARD_LED_STATE ledState)
233 boardIoctl(BOARD_IOCTL_LED_CTRL, 0, "", (int)ledName, (int)ledState, "");
237 //********************************************************************************
239 //********************************************************************************
240 int sysGetBoardIdName(char *name, int length)
242 return( boardIoctl(BOARD_IOCTL_GET_ID, 0, name, length, 0, "") );
246 //********************************************************************************
248 //********************************************************************************
249 int sysGetMacAddress( unsigned char *pucaAddr, unsigned long ulId )
251 return(boardIoctl(BOARD_IOCTL_GET_MAC_ADDRESS, 0, pucaAddr, 6, (int) ulId, ""));
255 //********************************************************************************
256 // Release MAC Address
257 //********************************************************************************
258 int sysReleaseMacAddress( unsigned char *pucaAddr )
260 return( boardIoctl(BOARD_IOCTL_RELEASE_MAC_ADDRESS, 0, pucaAddr, 6, 0, "") );
264 //********************************************************************************
266 //********************************************************************************
267 int sysGetSdramSize( void )
269 return( boardIoctl(BOARD_IOCTL_GET_SDRAM_SIZE, 0, "", 0, 0, "") );
273 /*****************************************************************************
274 * sysGetBooline - get bootline
275 * RETURNS: OK, always.
277 int sysGetBootline(char *string, int strLen)
279 return (boardIoctl(BOARD_IOCTL_GET_BOOTLINE, 0, string, strLen, 0, ""));
282 /*****************************************************************************
283 * sysSetBootline - write the bootline to nvram
284 * RETURNS: OK, always.
286 int sysSetBootline(char *string, int strLen)
288 return (boardIoctl(BOARD_IOCTL_SET_BOOTLINE, 0, string, strLen, 0, ""));
291 //********************************************************************************
293 //********************************************************************************
294 int sysGetBaseMacAddress( unsigned char *pucaAddr )
296 return(boardIoctl(BOARD_IOCTL_GET_BASE_MAC_ADDRESS, 0, pucaAddr, 6, 0, ""));
299 //********************************************************************************
300 // Get number of Ethernet phys
301 //********************************************************************************
302 int sysGetNumEnet(void)
304 return(boardIoctl(BOARD_IOCTL_GET_NUM_ENET, 0, "", 0, 0, ""));
307 //********************************************************************************
308 // Get CFE vesion info
309 //********************************************************************************
310 int sysGetCFEVersion(char *string, int strLen)
312 return (boardIoctl(BOARD_IOCTL_GET_CFE_VER, 0, string, strLen, 0, ""));
315 //********************************************************************************
316 // Get board Ethernet configuration
317 //********************************************************************************
318 int sysGetEnetCfg(char *string, int strLen)
320 return(boardIoctl(BOARD_IOCTL_GET_ENET_CFG, 0, string, strLen, 0, ""));
322 //********************************************************************************
323 // Get Wi-Fi Country selection
324 //********************************************************************************
325 int sysGetCountry(char *string, int strLen)
327 return(boardIoctl(BOARD_IOCTL_GET_CNTRY_SEL, 0, string, strLen, 0, ""));
330 //********************************************************************************
331 // Set monitor loop file descriptor
332 //********************************************************************************
333 int sysSetMonitorFd(int fd)
335 return (boardIoctl(BOARD_IOCTL_SET_MONITOR_FD, 0, "", 0, fd, ""));
338 //******************************************************************************
339 // Get VCOPE board information: cs, gpio, board revision
340 //******************************************************************************
341 int sysGetVcopeInfo(int info_type)
343 return(boardIoctl(BOARD_IOCTL_GET_VCOPE_GPIO, 0, "", 0, info_type, ""));
346 //******************************************************************************
347 // Configure Chip Select, by setting given parameter to a passed value
348 //******************************************************************************
349 int sysConfigCs (int cs_number, void *cs_info)
351 return(boardIoctl(BOARD_IOCTL_SET_CS_PAR, 0, "", 0, cs_number, cs_info));
354 //******************************************************************************
355 // Set up PLL clock register according to the passed values
356 //******************************************************************************
357 int sysSetPllClockRegister(mask, value)
359 return(boardIoctl(BOARD_IOCTL_SET_PLL, 0, "", mask, value, ""));
362 //******************************************************************************
363 // Configure GPIO bit according to the passed values
364 //******************************************************************************
365 int sysSetGpioBit (int gpio_bit, GPIO_STATE_t flag)
367 return(boardIoctl(BOARD_IOCTL_SET_GPIO, 0, "", gpio_bit, flag, ""));