Fix brcm63xx support. Now a kernel is booting, detecting the flash, and can probably...
[openwrt/svn-archive/archive.git] / openwrt / target / linux / brcm63xx-2.6 / patches / 001-brcm_boards.patch
1 diff -urN linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/bcm63xx_flash.c linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/bcm63xx_flash.c
2 --- linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/bcm63xx_flash.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/bcm63xx_flash.c 2006-07-07 22:16:32.000000000 +0200
4 @@ -0,0 +1,775 @@
5 +/*
6 +<:copyright-gpl
7 + Copyright 2002 Broadcom Corp. All Rights Reserved.
8 +
9 + This program is free software; you can distribute it and/or modify it
10 + under the terms of the GNU General Public License (Version 2) as
11 + published by the Free Software Foundation.
12 +
13 + This program is distributed in the hope it will be useful, but WITHOUT
14 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 + for more details.
17 +
18 + You should have received a copy of the GNU General Public License along
19 + with this program; if not, write to the Free Software Foundation, Inc.,
20 + 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 +:>
22 +*/
23 +/*
24 + ***************************************************************************
25 + * File Name : bcm63xx_flash.c
26 + *
27 + * Description: This file contains the flash device driver APIs for bcm63xx board.
28 + *
29 + * Created on : 8/10/2002 seanl: use cfiflash.c, cfliflash.h (AMD specific)
30 + *
31 + ***************************************************************************/
32 +
33 +
34 +/* Includes. */
35 +#include <linux/fs.h>
36 +#include <linux/capability.h>
37 +#include <linux/slab.h>
38 +#include <linux/errno.h>
39 +#include <linux/module.h>
40 +#include <asm/uaccess.h>
41 +
42 +#include <bcm_map_part.h>
43 +#include <board.h>
44 +#define BCMTAG_EXE_USE
45 +#include <bcmTag.h>
46 +#include "cfiflash.h"
47 +#include "boardparms.h"
48 +
49 +//#define DEBUG_FLASH
50 +
51 +static FLASH_ADDR_INFO fInfo;
52 +static int flashInitialized = 0;
53 +
54 +void *retriedKmalloc(size_t size)
55 +{
56 + void *pBuf;
57 + int tryCount = 0;
58 +
59 + // try 1000 times before quit
60 + while (((pBuf = kmalloc(size, GFP_KERNEL)) == NULL) && (tryCount++ < 1000))
61 + {
62 + current->state = TASK_INTERRUPTIBLE;
63 + schedule_timeout(HZ/10);
64 + }
65 + if (tryCount >= 1000)
66 + pBuf = NULL;
67 + else
68 + memset(pBuf, 0, size);
69 +
70 + return pBuf;
71 +}
72 +
73 +void retriedKfree(void *pBuf)
74 +{
75 + kfree(pBuf);
76 +}
77 +
78 +/***************************************************************************
79 +// Function Name: getCrc32
80 +// Description : caculate the CRC 32 of the given data.
81 +// Parameters : pdata - array of data.
82 +// size - number of input data bytes.
83 +// crc - either CRC32_INIT_VALUE or previous return value.
84 +// Returns : crc.
85 +****************************************************************************/
86 +UINT32 getCrc32(byte *pdata, UINT32 size, UINT32 crc)
87 +{
88 + while (size-- > 0)
89 + crc = (crc >> 8) ^ Crc32_table[(crc ^ *pdata++) & 0xff];
90 +
91 + return crc;
92 +}
93 +
94 +// get the nvram start addr
95 +//
96 +unsigned long get_nvram_start_addr(void)
97 +{
98 + return ((unsigned long)
99 + (flash_get_memptr(fInfo.flash_nvram_start_blk) + fInfo.flash_nvram_blk_offset));
100 +}
101 +
102 +// get the scratch_pad start addr
103 +//
104 +unsigned long get_scratch_pad_start_addr(void)
105 +{
106 + return ((unsigned long)
107 + (flash_get_memptr(fInfo.flash_scratch_pad_start_blk) + fInfo.flash_scratch_pad_blk_offset));
108 +}
109 +
110 +
111 +
112 +/* *********************************************************************
113 + * kerSysImageTagGet()
114 + * Get the image tag
115 + * Input parameters:
116 + * none
117 + * Return value:
118 + * point to tag -- Found
119 + * NULL -- failed
120 + ********************************************************************* */
121 +PFILE_TAG kerSysImageTagGet(void)
122 +{
123 + int i;
124 + int totalBlks = flash_get_numsectors();
125 + UINT32 crc;
126 + unsigned char *sectAddr;
127 + PFILE_TAG pTag;
128 +
129 +#if defined(DEBUG_FLASH)
130 + printk("totalblks in tagGet=%d\n", totalBlks);
131 +#endif
132 +
133 + // start from 2nd blk, assume 1st one is always CFE
134 + for (i = 1; i < totalBlks; i++)
135 + {
136 + sectAddr = flash_get_memptr((byte) i);
137 + crc = CRC32_INIT_VALUE;
138 + crc = getCrc32(sectAddr, (UINT32)TAG_LEN-TOKEN_LEN, crc);
139 + pTag = (PFILE_TAG) sectAddr;
140 +
141 +#if defined(DEBUG_FLASH)
142 + printk("Check Tag crc on blk [%d]\n", i);
143 +#endif
144 +
145 + if (crc == (UINT32)(*(UINT32*)(pTag->tagValidationToken)))
146 + return pTag;
147 + }
148 +
149 + return (PFILE_TAG) NULL;
150 +}
151 +
152 +// Initialize the flash and fill out the fInfo structure
153 +void kerSysFlashInit( void )
154 +{
155 + int i = 0;
156 + int totalBlks = 0;
157 + int totalSize = 0;
158 + int startAddr = 0;
159 + int usedBlkSize = 0;
160 + NVRAM_DATA nvramData;
161 + UINT32 crc = CRC32_INIT_VALUE, savedCrc;
162 + PFILE_TAG pTag = NULL;
163 + unsigned long kernelEndAddr = 0;
164 + unsigned long spAddr = 0;
165 +
166 + if (flashInitialized)
167 + return;
168 +
169 + flashInitialized = 1;
170 + flash_init();
171 +
172 + totalBlks = flash_get_numsectors();
173 + totalSize = flash_get_total_size();
174 +
175 + printk("Total Flash size: %dK with %d sectors\n", totalSize/1024, totalBlks);
176 +
177 + /* nvram is always at the end of flash */
178 + fInfo.flash_nvram_length = FLASH45_LENGTH_NVRAM;
179 + fInfo.flash_nvram_start_blk = 0; /* always the first block */
180 + fInfo.flash_nvram_number_blk = 1; /*always fits in the first block */
181 + fInfo.flash_nvram_blk_offset = NVRAM_DATA_OFFSET;
182 +
183 + // check nvram CRC
184 + memcpy((char *)&nvramData, (char *)get_nvram_start_addr(), sizeof(NVRAM_DATA));
185 + savedCrc = nvramData.ulCheckSum;
186 + nvramData.ulCheckSum = 0;
187 + crc = getCrc32((char *)&nvramData, (UINT32) sizeof(NVRAM_DATA), crc);
188 +
189 + BpSetBoardId( nvramData.szBoardId );
190 +
191 + fInfo.flash_persistent_length = NVRAM_PSI_DEFAULT;
192 + if (savedCrc != crc)
193 + {
194 + printk("***Board is not initialized****: Using the default PSI size: %d\n",
195 + fInfo.flash_persistent_length);
196 + }
197 + else
198 + {
199 + unsigned long ulPsiSize;
200 + if( BpGetPsiSize( &ulPsiSize ) == BP_SUCCESS )
201 + fInfo.flash_persistent_length = ulPsiSize;
202 + else
203 + {
204 + printk("***Board id is not set****: Using the default PSI size: %d\n",
205 + fInfo.flash_persistent_length);
206 + }
207 + }
208 +
209 + fInfo.flash_persistent_length *= ONEK;
210 + startAddr = totalSize - fInfo.flash_persistent_length;
211 + fInfo.flash_persistent_start_blk = flash_get_blk(startAddr+FLASH_BASE_ADDR_REG);
212 + fInfo.flash_persistent_number_blk = totalBlks - fInfo.flash_persistent_start_blk;
213 + // save abs SP address (Scratch Pad). it is before PSI
214 + spAddr = startAddr - SP_MAX_LEN ;
215 + // find out the offset in the start_blk
216 + usedBlkSize = 0;
217 + for (i = fInfo.flash_persistent_start_blk;
218 + i < (fInfo.flash_persistent_start_blk + fInfo.flash_persistent_number_blk); i++)
219 + {
220 + usedBlkSize += flash_get_sector_size((byte) i);
221 + }
222 + fInfo.flash_persistent_blk_offset = usedBlkSize - fInfo.flash_persistent_length;
223 +
224 + // get the info for sp
225 + if (!(pTag = kerSysImageTagGet()))
226 + {
227 + printk("Failed to read image tag from flash\n");
228 + return;
229 + }
230 + kernelEndAddr = (unsigned long) simple_strtoul(pTag->kernelAddress, NULL, 10) + \
231 + (unsigned long) simple_strtoul(pTag->kernelLen, NULL, 10);
232 +
233 + // make suer sp does not share kernel block
234 + fInfo.flash_scratch_pad_start_blk = flash_get_blk(spAddr+FLASH_BASE_ADDR_REG);
235 + if (fInfo.flash_scratch_pad_start_blk != flash_get_blk(kernelEndAddr))
236 + {
237 + fInfo.flash_scratch_pad_length = SP_MAX_LEN;
238 + if (fInfo.flash_persistent_start_blk == fInfo.flash_scratch_pad_start_blk) // share blk
239 + {
240 +#if 1 /* do not used scratch pad unless it's in its own sector */
241 + printk("Scratch pad is not used for this flash part.\n");
242 + fInfo.flash_scratch_pad_length = 0; // no sp
243 +#else /* allow scratch pad to share a sector with another section such as PSI */
244 + fInfo.flash_scratch_pad_number_blk = 1;
245 + fInfo.flash_scratch_pad_blk_offset = fInfo.flash_persistent_blk_offset - fInfo.flash_scratch_pad_length;
246 +#endif
247 + }
248 + else // on different blk
249 + {
250 + fInfo.flash_scratch_pad_number_blk = fInfo.flash_persistent_start_blk\
251 + - fInfo.flash_scratch_pad_start_blk;
252 + // find out the offset in the start_blk
253 + usedBlkSize = 0;
254 + for (i = fInfo.flash_scratch_pad_start_blk;
255 + i < (fInfo.flash_scratch_pad_start_blk + fInfo.flash_scratch_pad_number_blk); i++)
256 + usedBlkSize += flash_get_sector_size((byte) i);
257 + fInfo.flash_scratch_pad_blk_offset = usedBlkSize - fInfo.flash_scratch_pad_length;
258 + }
259 + }
260 + else
261 + {
262 + printk("No flash for scratch pad!\n");
263 + fInfo.flash_scratch_pad_length = 0; // no sp
264 + }
265 +
266 +#if defined(DEBUG_FLASH)
267 + printk("fInfo.flash_scratch_pad_start_blk = %d\n", fInfo.flash_scratch_pad_start_blk);
268 + printk("fInfo.flash_scratch_pad_number_blk = %d\n", fInfo.flash_scratch_pad_number_blk);
269 + printk("fInfo.flash_scratch_pad_length = 0x%x\n", fInfo.flash_scratch_pad_length);
270 + printk("fInfo.flash_scratch_pad_blk_offset = 0x%x\n", (unsigned int)fInfo.flash_scratch_pad_blk_offset);
271 +
272 + printk("fInfo.flash_nvram_start_blk = %d\n", fInfo.flash_nvram_start_blk);
273 + printk("fInfo.flash_nvram_blk_offset = 0x%x\n", (unsigned int)fInfo.flash_nvram_blk_offset);
274 + printk("fInfo.flash_nvram_number_blk = %d\n", fInfo.flash_nvram_number_blk);
275 +
276 + printk("psi startAddr = %x\n", startAddr+FLASH_BASE_ADDR_REG);
277 + printk("fInfo.flash_persistent_start_blk = %d\n", fInfo.flash_persistent_start_blk);
278 + printk("fInfo.flash_persistent_blk_offset = 0x%x\n", (unsigned int)fInfo.flash_persistent_blk_offset);
279 + printk("fInfo.flash_persistent_number_blk = %d\n", fInfo.flash_persistent_number_blk);
280 +#endif
281 +
282 +}
283 +
284 +
285 +
286 +/***********************************************************************
287 + * Function Name: kerSysFlashAddrInfoGet
288 + * Description : Fills in a structure with information about the NVRAM
289 + * and persistent storage sections of flash memory.
290 + * Fro physmap.c to mount the fs vol.
291 + * Returns : None.
292 + ***********************************************************************/
293 +void kerSysFlashAddrInfoGet(PFLASH_ADDR_INFO pflash_addr_info)
294 +{
295 + pflash_addr_info->flash_nvram_blk_offset = fInfo.flash_nvram_blk_offset;
296 + pflash_addr_info->flash_nvram_length = fInfo.flash_nvram_length;
297 + pflash_addr_info->flash_nvram_number_blk = fInfo.flash_nvram_number_blk;
298 + pflash_addr_info->flash_nvram_start_blk = fInfo.flash_nvram_start_blk;
299 + pflash_addr_info->flash_persistent_blk_offset = fInfo.flash_persistent_blk_offset;
300 + pflash_addr_info->flash_persistent_length = fInfo.flash_persistent_length;
301 + pflash_addr_info->flash_persistent_number_blk = fInfo.flash_persistent_number_blk;
302 + pflash_addr_info->flash_persistent_start_blk = fInfo.flash_persistent_start_blk;
303 +}
304 +
305 +
306 +// get shared blks into *** pTempBuf *** which has to be released bye the caller!
307 +// return: if pTempBuf != NULL, poits to the data with the dataSize of the buffer
308 +// !NULL -- ok
309 +// NULL -- fail
310 +static char *getSharedBlks(int start_blk, int end_blk)
311 +{
312 + int i = 0;
313 + int usedBlkSize = 0;
314 + int sect_size = 0;
315 + char *pTempBuf = NULL;
316 + char *pBuf = NULL;
317 +
318 + for (i = start_blk; i < end_blk; i++)
319 + usedBlkSize += flash_get_sector_size((byte) i);
320 +
321 +#if defined(DEBUG_FLASH)
322 + printk("usedBlkSize = %d\n", usedBlkSize);
323 +#endif
324 +
325 + if ((pTempBuf = (char *) retriedKmalloc(usedBlkSize)) == NULL)
326 + {
327 + printk("failed to allocate memory with size: %d\n", usedBlkSize);
328 + return pTempBuf;
329 + }
330 +
331 + pBuf = pTempBuf;
332 + for (i = start_blk; i < end_blk; i++)
333 + {
334 + sect_size = flash_get_sector_size((byte) i);
335 +
336 +#if defined(DEBUG_FLASH)
337 + printk("i = %d, sect_size = %d, end_blk = %d\n", i, sect_size, end_blk);
338 +#endif
339 + flash_read_buf((byte)i, 0, pBuf, sect_size);
340 + pBuf += sect_size;
341 + }
342 +
343 + return pTempBuf;
344 +}
345 +
346 +
347 +
348 +// Set the pTempBuf to flash from start_blk to end_blk
349 +// return:
350 +// 0 -- ok
351 +// -1 -- fail
352 +static int setSharedBlks(int start_blk, int end_blk, char *pTempBuf)
353 +{
354 + int i = 0;
355 + int sect_size = 0;
356 + int sts = 0;
357 + char *pBuf = pTempBuf;
358 +
359 + for (i = start_blk; i < end_blk; i++)
360 + {
361 + sect_size = flash_get_sector_size((byte) i);
362 + flash_sector_erase_int(i);
363 + if (flash_write_buf(i, 0, pBuf, sect_size) != sect_size)
364 + {
365 + printk("Error writing flash sector %d.", i);
366 + sts = -1;
367 + break;
368 + }
369 + pBuf += sect_size;
370 + }
371 +
372 + return sts;
373 +}
374 +
375 +
376 +
377 +/*******************************************************************************
378 + * NVRAM functions
379 + *******************************************************************************/
380 +
381 +// get nvram data
382 +// return:
383 +// 0 - ok
384 +// -1 - fail
385 +int kerSysNvRamGet(char *string, int strLen, int offset)
386 +{
387 + char *pBuf = NULL;
388 +
389 + if (!flashInitialized)
390 + kerSysFlashInit();
391 +
392 + if (strLen > FLASH45_LENGTH_NVRAM)
393 + return -1;
394 +
395 + if ((pBuf = getSharedBlks(fInfo.flash_nvram_start_blk,
396 + (fInfo.flash_nvram_start_blk + fInfo.flash_nvram_number_blk))) == NULL)
397 + return -1;
398 +
399 + // get string off the memory buffer
400 + memcpy(string, (pBuf + fInfo.flash_nvram_blk_offset + offset), strLen);
401 +
402 + retriedKfree(pBuf);
403 +
404 + return 0;
405 +}
406 +
407 +
408 +// set nvram
409 +// return:
410 +// 0 - ok
411 +// -1 - fail
412 +int kerSysNvRamSet(char *string, int strLen, int offset)
413 +{
414 + int sts = 0;
415 + char *pBuf = NULL;
416 +
417 + if (strLen > FLASH45_LENGTH_NVRAM)
418 + return -1;
419 +
420 + if ((pBuf = getSharedBlks(fInfo.flash_nvram_start_blk,
421 + (fInfo.flash_nvram_start_blk + fInfo.flash_nvram_number_blk))) == NULL)
422 + return -1;
423 +
424 + // set string to the memory buffer
425 + memcpy((pBuf + fInfo.flash_nvram_blk_offset + offset), string, strLen);
426 +
427 + if (setSharedBlks(fInfo.flash_nvram_start_blk,
428 + (fInfo.flash_nvram_number_blk + fInfo.flash_nvram_start_blk), pBuf) != 0)
429 + sts = -1;
430 +
431 + retriedKfree(pBuf);
432 +
433 + return sts;
434 +}
435 +
436 +
437 +/***********************************************************************
438 + * Function Name: kerSysEraseNvRam
439 + * Description : Erase the NVRAM storage section of flash memory.
440 + * Returns : 1 -- ok, 0 -- fail
441 + ***********************************************************************/
442 +int kerSysEraseNvRam(void)
443 +{
444 + int sts = 1;
445 + char *tempStorage = retriedKmalloc(FLASH45_LENGTH_NVRAM);
446 +
447 + // just write the whole buf with '0xff' to the flash
448 + if (!tempStorage)
449 + sts = 0;
450 + else
451 + {
452 + memset(tempStorage, 0xff, FLASH45_LENGTH_NVRAM);
453 + if (kerSysNvRamSet(tempStorage, FLASH45_LENGTH_NVRAM, 0) != 0)
454 + sts = 0;
455 + retriedKfree(tempStorage);
456 + }
457 +
458 + return sts;
459 +}
460 +
461 +
462 +/*******************************************************************************
463 + * PSI functions
464 + *******************************************************************************/
465 +// get psi data
466 +// return:
467 +// 0 - ok
468 +// -1 - fail
469 +int kerSysPersistentGet(char *string, int strLen, int offset)
470 +{
471 + char *pBuf = NULL;
472 +
473 + if (strLen > fInfo.flash_persistent_length)
474 + return -1;
475 +
476 + if ((pBuf = getSharedBlks(fInfo.flash_persistent_start_blk,
477 + (fInfo.flash_persistent_start_blk + fInfo.flash_persistent_number_blk))) == NULL)
478 + return -1;
479 +
480 + // get string off the memory buffer
481 + memcpy(string, (pBuf + fInfo.flash_persistent_blk_offset + offset), strLen);
482 +
483 + retriedKfree(pBuf);
484 +
485 + return 0;
486 +}
487 +
488 +
489 +// set psi
490 +// return:
491 +// 0 - ok
492 +// -1 - fail
493 +int kerSysPersistentSet(char *string, int strLen, int offset)
494 +{
495 + int sts = 0;
496 + char *pBuf = NULL;
497 +
498 + if (strLen > fInfo.flash_persistent_length)
499 + return -1;
500 +
501 + if ((pBuf = getSharedBlks(fInfo.flash_persistent_start_blk,
502 + (fInfo.flash_persistent_start_blk + fInfo.flash_persistent_number_blk))) == NULL)
503 + return -1;
504 +
505 + // set string to the memory buffer
506 + memcpy((pBuf + fInfo.flash_persistent_blk_offset + offset), string, strLen);
507 +
508 + if (setSharedBlks(fInfo.flash_persistent_start_blk,
509 + (fInfo.flash_persistent_number_blk + fInfo.flash_persistent_start_blk), pBuf) != 0)
510 + sts = -1;
511 +
512 + retriedKfree(pBuf);
513 +
514 + return sts;
515 +}
516 +
517 +
518 +// flash bcm image
519 +// return:
520 +// 0 - ok
521 +// !0 - the sector number fail to be flashed (should not be 0)
522 +int kerSysBcmImageSet( int flash_start_addr, char *string, int size)
523 +{
524 + int sts;
525 + int sect_size;
526 + int blk_start;
527 + int i;
528 + char *pTempBuf = NULL;
529 + int whole_image = 0;
530 +
531 + blk_start = flash_get_blk(flash_start_addr);
532 + if( blk_start < 0 )
533 + return( -1 );
534 +
535 + if (flash_start_addr == FLASH_BASE && size > FLASH45_LENGTH_BOOT_ROM)
536 + whole_image = 1;
537 +
538 + /* write image to flash memory */
539 + do
540 + {
541 + sect_size = flash_get_sector_size(blk_start);
542 +// NOTE: for memory problem in multiple PVC configuration, temporary get rid of kmalloc this 64K for now.
543 +// if ((pTempBuf = (char *)retriedKmalloc(sect_size)) == NULL)
544 +// {
545 +// printk("Failed to allocate memory with size: %d. Reset the router...\n", sect_size);
546 +// kerSysMipsSoftReset(); // reset the board right away.
547 +// }
548 + // for whole image, no check on psi
549 + if (!whole_image && blk_start == fInfo.flash_persistent_start_blk) // share the blk with psi
550 + {
551 + if (size > (sect_size - fInfo.flash_persistent_length))
552 + {
553 + printk("Image is too big\n");
554 + break; // image is too big. Can not overwrite to nvram
555 + }
556 + if ((pTempBuf = (char *)retriedKmalloc(sect_size)) == NULL)
557 + {
558 + printk("Failed to allocate memory with size: %d. Reset the router...\n", sect_size);
559 + kerSysMipsSoftReset(); // reset the board right away.
560 + }
561 + flash_read_buf((byte)blk_start, 0, pTempBuf, sect_size);
562 + if (copy_from_user((void *)pTempBuf,(void *)string, size) != 0)
563 + break; // failed ?
564 + flash_sector_erase_int(blk_start); // erase blk before flash
565 + if (flash_write_buf(blk_start, 0, pTempBuf, sect_size) == sect_size)
566 + size = 0; // break out and say all is ok
567 + retriedKfree(pTempBuf);
568 + break;
569 + }
570 +
571 + flash_sector_erase_int(blk_start); // erase blk before flash
572 +
573 + if (sect_size > size)
574 + {
575 + if (size & 1)
576 + size++;
577 + sect_size = size;
578 + }
579 +
580 + if ((i = flash_write_buf(blk_start, 0, string, sect_size)) != sect_size) {
581 + break;
582 + }
583 + blk_start++;
584 + string += sect_size;
585 + size -= sect_size;
586 + } while (size > 0);
587 +
588 + if (whole_image)
589 + {
590 + // If flashing a whole image, erase to end of flash.
591 + int total_blks = flash_get_numsectors();
592 + while( blk_start < total_blks )
593 + {
594 + flash_sector_erase_int(blk_start);
595 + blk_start++;
596 + }
597 + }
598 + if (pTempBuf)
599 + retriedKfree(pTempBuf);
600 +
601 + if( size == 0 )
602 + sts = 0; // ok
603 + else
604 + sts = blk_start; // failed to flash this sector
605 +
606 + return sts;
607 +}
608 +
609 +/*******************************************************************************
610 + * SP functions
611 + *******************************************************************************/
612 +// get sp data. NOTE: memcpy work here -- not using copy_from/to_user
613 +// return:
614 +// 0 - ok
615 +// -1 - fail
616 +int kerSysScratchPadGet(char *tokenId, char *tokBuf, int bufLen)
617 +{
618 + PSP_HEADER pHead = NULL;
619 + PSP_TOKEN pToken = NULL;
620 + char *pBuf = NULL;
621 + char *pShareBuf = NULL;
622 + char *startPtr = NULL;
623 + char *endPtr = NULL;
624 + char *spEndPtr = NULL;
625 + int sts = -1;
626 +
627 + if (fInfo.flash_scratch_pad_length == 0)
628 + return sts;
629 +
630 + if (bufLen >= (fInfo.flash_scratch_pad_length - sizeof(SP_HEADER) - sizeof(SP_TOKEN)))
631 + {
632 + printk("Exceed scratch pad space by %d\n", bufLen - fInfo.flash_scratch_pad_length \
633 + - sizeof(SP_HEADER) - sizeof(SP_TOKEN));
634 + return sts;
635 + }
636 +
637 + if ((pShareBuf = getSharedBlks(fInfo.flash_scratch_pad_start_blk,
638 + (fInfo.flash_scratch_pad_start_blk + fInfo.flash_scratch_pad_number_blk))) == NULL)
639 + return sts;
640 +
641 + // pBuf points to SP buf
642 + pBuf = pShareBuf + fInfo.flash_scratch_pad_blk_offset;
643 +
644 + pHead = (PSP_HEADER) pBuf;
645 + if (memcmp(pHead->SPMagicNum, MAGIC_NUMBER, MAGIC_NUM_LEN) != 0)
646 + {
647 + printk("Scrap pad is not initialized.\n");
648 + return sts;
649 + }
650 +
651 + // search up to SPUsedLen for the token
652 + startPtr = pBuf + sizeof(SP_HEADER);
653 + endPtr = pBuf + pHead->SPUsedLen;
654 + spEndPtr = pBuf + SP_MAX_LEN;
655 + while (startPtr < endPtr && startPtr < spEndPtr)
656 + {
657 + pToken = (PSP_TOKEN) startPtr;
658 + if (strncmp(pToken->tokenName, tokenId, TOKEN_NAME_LEN) == 0)
659 + {
660 + memcpy(tokBuf, startPtr + sizeof(SP_TOKEN), bufLen);
661 + sts = 0;
662 + break;
663 + }
664 + // get next token
665 + startPtr += sizeof(SP_TOKEN) + pToken->tokenLen;
666 + }
667 +
668 + retriedKfree(pShareBuf);
669 +
670 + return sts;
671 +}
672 +
673 +
674 +// set sp. NOTE: memcpy work here -- not using copy_from/to_user
675 +// return:
676 +// 0 - ok
677 +// -1 - fail
678 +int kerSysScratchPadSet(char *tokenId, char *tokBuf, int bufLen)
679 +{
680 + PSP_TOKEN pToken = NULL;
681 + PSP_HEADER pHead = NULL;
682 + char *pShareBuf = NULL;
683 + char *pBuf = NULL;
684 + SP_HEADER SPHead;
685 + SP_TOKEN SPToken;
686 + char *curPtr;
687 + int sts = -1;
688 +
689 + if (fInfo.flash_scratch_pad_length == 0)
690 + return sts;
691 +
692 + if (bufLen >= (fInfo.flash_scratch_pad_length - sizeof(SP_HEADER) - sizeof(SP_TOKEN)))
693 + {
694 + printk("Exceed scratch pad space by %d\n", bufLen - fInfo.flash_scratch_pad_length \
695 + - sizeof(SP_HEADER) - sizeof(SP_TOKEN));
696 + return sts;
697 + }
698 +
699 + if ((pShareBuf = getSharedBlks(fInfo.flash_scratch_pad_start_blk,
700 + (fInfo.flash_scratch_pad_start_blk + fInfo.flash_scratch_pad_number_blk))) == NULL)
701 + return sts;
702 +
703 + // pBuf points to SP buf
704 + pBuf = pShareBuf + fInfo.flash_scratch_pad_blk_offset;
705 + pHead = (PSP_HEADER) pBuf;
706 +
707 + // form header info. SPUsedLen later on...
708 + memset((char *)&SPHead, 0, sizeof(SP_HEADER));
709 + memcpy(SPHead.SPMagicNum, MAGIC_NUMBER, MAGIC_NUM_LEN);
710 + SPHead.SPVersion = SP_VERSION;
711 +
712 + // form token info.
713 + memset((char*)&SPToken, 0, sizeof(SP_TOKEN));
714 + strncpy(SPToken.tokenName, tokenId, TOKEN_NAME_LEN - 1);
715 + SPToken.tokenLen = bufLen;
716 + if (memcmp(pHead->SPMagicNum, MAGIC_NUMBER, MAGIC_NUM_LEN) != 0)
717 + {
718 + // new sp, so just flash the token
719 + printk("No Scrap pad found. Initialize scratch pad...\n");
720 + SPHead.SPUsedLen = sizeof(SP_HEADER) + sizeof(SP_TOKEN) + bufLen;
721 + memcpy(pBuf, (char *)&SPHead, sizeof(SP_HEADER));
722 + curPtr = pBuf + sizeof(SP_HEADER);
723 + memcpy(curPtr, (char *)&SPToken, sizeof(SP_TOKEN));
724 + curPtr += sizeof(SP_TOKEN);
725 + memcpy(curPtr, tokBuf, bufLen);
726 + }
727 + else
728 + {
729 + // need search for the token, if exist with same size overwrite it. if sizes differ,
730 + // move over the later token data over and put the new one at the end
731 + char *endPtr = pBuf + pHead->SPUsedLen;
732 + char *spEndPtr = pBuf + SP_MAX_LEN;
733 + curPtr = pBuf + sizeof(SP_HEADER);
734 + while (curPtr < endPtr && curPtr < spEndPtr)
735 + {
736 + pToken = (PSP_TOKEN) curPtr;
737 + if (strncmp(pToken->tokenName, tokenId, TOKEN_NAME_LEN) == 0)
738 + {
739 + if (pToken->tokenLen == bufLen) // overwirte it
740 + {
741 + memcpy((curPtr+sizeof(SP_TOKEN)), tokBuf, bufLen);
742 + break;
743 + }
744 + else // move later data over and put the new token at the end
745 + {
746 + memcpy((curPtr+sizeof(SP_TOKEN)), tokBuf, bufLen); // ~~~
747 + break;
748 + }
749 + }
750 + else // not same token ~~~
751 + {
752 + }
753 + // get next token
754 + curPtr += sizeof(SP_TOKEN) + pToken->tokenLen;
755 + } // end while
756 + SPHead.SPUsedLen = sizeof(SP_HEADER) + sizeof(SP_TOKEN) + bufLen; // ~~~
757 + if (SPHead.SPUsedLen > SP_MAX_LEN)
758 + {
759 + printk("No more Scratch pad space left! Over limit by %d bytes\n", SPHead.SPUsedLen - SP_MAX_LEN);
760 + return sts;
761 + }
762 +
763 + } // else if not new sp
764 +
765 + sts = setSharedBlks(fInfo.flash_scratch_pad_start_blk,
766 + (fInfo.flash_scratch_pad_number_blk + fInfo.flash_scratch_pad_start_blk), pShareBuf);
767 +
768 + retriedKfree(pShareBuf);
769 +
770 + return sts;
771 +
772 +
773 +}
774 +
775 +int kerSysFlashSizeGet(void)
776 +{
777 + return flash_get_total_size();
778 +}
779 +
780 diff -urN linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/bcm63xx_led.c linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/bcm63xx_led.c
781 --- linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/bcm63xx_led.c 1970-01-01 01:00:00.000000000 +0100
782 +++ linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/bcm63xx_led.c 2006-07-07 22:16:32.000000000 +0200
783 @@ -0,0 +1,582 @@
784 +/*
785 +<:copyright-gpl
786 + Copyright 2002 Broadcom Corp. All Rights Reserved.
787 +
788 + This program is free software; you can distribute it and/or modify it
789 + under the terms of the GNU General Public License (Version 2) as
790 + published by the Free Software Foundation.
791 +
792 + This program is distributed in the hope it will be useful, but WITHOUT
793 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
794 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
795 + for more details.
796 +
797 + You should have received a copy of the GNU General Public License along
798 + with this program; if not, write to the Free Software Foundation, Inc.,
799 + 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
800 +:>
801 +*/
802 +/***************************************************************************
803 + * File Name : bcm63xx_led.c
804 + *
805 + * Description:
806 + *
807 + * This file contains bcm963xx board led control API functions.
808 + *
809 + * To use it, do the following
810 + *
811 + * 1). define in the board.c the following led mappping (this is for 6345GW board):
812 + * const LED_MAP_PAIR cLedMapping45GW[] =
813 + * { // led name Initial state physical pin (ledMask)
814 + * {kLedUsb, kLedStateOff, GPIO_LED_PIN_7},
815 + * {kLedAdsl, kLedStateOff, GPIO_LED_PIN_8},
816 + * {kLedPPP, kLedStateOff, GPIO_LED_PIN_9}, // PPP and WanData share PIN_9
817 + * {kLedWanData, kLedStateOff, GPIO_LED_PIN_9},
818 + * {kLedWireless, kLedStateOff, GPIO_LED_PIN_10},
819 + * {kLedEnd, kLedStateOff, 0 } // NOTE: kLedEnd has to be at the end.
820 + *
821 + * 2). };To initialize led API and initial state of the leds, call the following function with the mapping
822 + * pointer from the above struct
823 + *
824 + * boardLedInit((PLED_MAP_PAIR) &cLedMapping45R);
825 + *
826 + * 3). Sample call for kernel mode:
827 + *
828 + * kerSysLedCtrl(kLedAdsl, kLedStateBlinkOnce); // kLedxxx defines in board.h
829 + *
830 + * 4). Sample call for user mode
831 + *
832 + * sysLedCtrl(kLedAdsl, kLedStateBlinkOnce); // kLedxxx defines in board_api.h
833 + *
834 + *
835 + * Created on : 10/28/2002 seanl
836 + *
837 + ***************************************************************************/
838 +
839 +/* Includes. */
840 +#include <linux/init.h>
841 +#include <linux/fs.h>
842 +#include <linux/capability.h>
843 +#include <linux/slab.h>
844 +#include <linux/errno.h>
845 +#include <linux/module.h>
846 +#include <linux/netdevice.h>
847 +#include <asm/uaccess.h>
848 +
849 +#include <bcm_map_part.h>
850 +#include <board.h>
851 +
852 +#define k100ms (HZ / 10) // ~100 ms
853 +#define kFastBlinkCount 0 // ~100ms
854 +#define kSlowBlinkCount 5 // ~600ms
855 +
856 +#define MAX_VIRT_LEDS 12
857 +
858 +// uncomment // for debug led
859 +//#define DEBUG_LED
860 +
861 +// global variables:
862 +struct timer_list gLedTimer;
863 +int gTimerOn = FALSE;
864 +int gLedCount = 0;
865 +
866 +typedef struct ledinfo
867 +{
868 + unsigned short ledMask; // mask for led: ie. giop 10 = 0x0400
869 + unsigned short ledActiveLow; // GPIO bit reset to turn on LED
870 + unsigned short ledMaskFail; // mask for led: ie. giop 10 = 0x0400
871 + unsigned short ledActiveLowFail;// GPIO bit reset to turn on LED
872 + BOARD_LED_STATE ledState; // current led state
873 + BOARD_LED_STATE savedLedState; // used in blink once for restore to the orignal ledState
874 + int blinkCountDown; // if == 0, do blink (toggle). Is assgined value and dec by 1 at each timer.
875 +} LED_INFO, *PLED_INFO;
876 +
877 +static PLED_INFO gLed = NULL;
878 +static PLED_INFO gpVirtLeds[MAX_VIRT_LEDS];
879 +static HANDLE_LED_FUNC gLedHwFunc[MAX_VIRT_LEDS];
880 +static HANDLE_LED_FUNC gLedHwFailFunc[MAX_VIRT_LEDS];
881 +
882 +#if 0 /* BROKEN */
883 +#if defined(CONFIG_BCM96348) || defined(CONFIG_BCM96338)
884 +static int gLedOffInBridgeMode = 1;
885 +#elif defined(CONFIG_BCM96345)
886 +static int gLedOffInBridgeMode = 0;
887 +#endif
888 +#endif
889 +
890 +void ledTimerExpire(void);
891 +int initLedInfo( PLED_MAP_PAIR pCurMap, PLED_INFO pCurLed );
892 +
893 +//**************************************************************************************
894 +// LED operations
895 +//**************************************************************************************
896 +
897 +// turn led on and set the ledState
898 +void ledOn(PLED_INFO pLed)
899 +{
900 + if( pLed->ledMask )
901 + {
902 + GPIO->GPIODir |= pLed->ledMask; // turn on the direction bit in case was turned off by some one
903 + if( pLed->ledActiveLow )
904 + GPIO->GPIOio &= ~pLed->ledMask; // turn on the led
905 + else
906 + GPIO->GPIOio |= pLed->ledMask; // turn on the led
907 + pLed->ledState = pLed->savedLedState = kLedStateOn;
908 + }
909 +}
910 +
911 +
912 +// turn led off and set the ledState
913 +void ledOff(PLED_INFO pLed)
914 +{
915 + if( pLed->ledMask )
916 + {
917 + GPIO->GPIODir |= pLed->ledMask; // turn on the direction bit in case was turned off by some one
918 + if( pLed->ledActiveLow )
919 + GPIO->GPIOio |= pLed->ledMask; // turn off the led
920 + else
921 + GPIO->GPIOio &= ~pLed->ledMask; // turn off the led
922 + pLed->ledState = pLed->savedLedState = kLedStateOff;
923 + }
924 +}
925 +
926 +// turn led on and set the ledState
927 +void ledOnFail(PLED_INFO pLed)
928 +{
929 + if( pLed->ledMaskFail )
930 + {
931 + GPIO->GPIODir |= pLed->ledMaskFail; // turn on the direction bit in case was turned off by some one
932 + if( pLed->ledActiveLowFail )
933 + GPIO->GPIOio &= ~pLed->ledMaskFail;// turn on the led
934 + else
935 + GPIO->GPIOio |= pLed->ledMaskFail; // turn on the led
936 + pLed->ledState = pLed->savedLedState = kLedStateFail;
937 + }
938 +}
939 +
940 +
941 +// turn led off and set the ledState
942 +void ledOffFail(PLED_INFO pLed)
943 +{
944 + if( pLed->ledMaskFail )
945 + {
946 + GPIO->GPIODir |= pLed->ledMaskFail; // turn on the direction bit in case was turned off by some one
947 + if( pLed->ledActiveLowFail )
948 + GPIO->GPIOio |= pLed->ledMaskFail; // turn off the led
949 + else
950 + GPIO->GPIOio &= ~pLed->ledMaskFail;// turn off the led
951 + pLed->ledState = pLed->savedLedState = kLedStateOff;
952 + }
953 +}
954 +
955 +
956 +// toggle the led and return the current ledState
957 +BOARD_LED_STATE ledToggle(PLED_INFO pLed)
958 +{
959 + GPIO->GPIODir |= pLed->ledMask; // turn on the direction bit in case was turned off by some one
960 + if (GPIO->GPIOio & pLed->ledMask)
961 + {
962 + GPIO->GPIOio &= ~(pLed->ledMask);
963 + return( (pLed->ledActiveLow) ? kLedStateOn : kLedStateOff );
964 + }
965 + else
966 + {
967 + GPIO->GPIOio |= pLed->ledMask;
968 + return( (pLed->ledActiveLow) ? kLedStateOff : kLedStateOn );
969 + }
970 +}
971 +
972 +
973 +// led timer. Will return if timer is already on
974 +void ledTimerStart(void)
975 +{
976 + if (gTimerOn)
977 + return;
978 +
979 +#if defined(DEBUG_LED)
980 + printk("led: add_timer\n");
981 +#endif
982 +
983 + init_timer(&gLedTimer);
984 + gLedTimer.function = (void*)ledTimerExpire;
985 + gLedTimer.expires = jiffies + k100ms; // timer expires in ~100ms
986 + add_timer (&gLedTimer);
987 + gTimerOn = TRUE;
988 +}
989 +
990 +
991 +// led timer expire kicks in about ~100ms and perform the led operation according to the ledState and
992 +// restart the timer according to ledState
993 +void ledTimerExpire(void)
994 +{
995 + int i;
996 + PLED_INFO pCurLed;
997 +
998 + gTimerOn = FALSE;
999 +
1000 + for (i = 0, pCurLed = gLed; i < gLedCount; i++, pCurLed++)
1001 + {
1002 +#if defined(DEBUG_LED)
1003 + printk("led[%d]: Mask=0x%04x, State = %d, blcd=%d\n", i, pCurLed->ledMask, pCurLed->ledState, pCurLed->blinkCountDown);
1004 +#endif
1005 + switch (pCurLed->ledState)
1006 + {
1007 + case kLedStateOn:
1008 + case kLedStateOff:
1009 + case kLedStateFail:
1010 + pCurLed->blinkCountDown = 0; // reset the blink count down
1011 + break;
1012 +
1013 + case kLedStateBlinkOnce:
1014 + ledToggle(pCurLed);
1015 + pCurLed->blinkCountDown = 0; // reset to 0
1016 + pCurLed->ledState = pCurLed->savedLedState;
1017 + if (pCurLed->ledState == kLedStateSlowBlinkContinues ||
1018 + pCurLed->ledState == kLedStateFastBlinkContinues)
1019 + ledTimerStart(); // start timer if in blinkContinues stats
1020 + break;
1021 +
1022 + case kLedStateSlowBlinkContinues:
1023 + if (pCurLed->blinkCountDown-- == 0)
1024 + {
1025 + pCurLed->blinkCountDown = kSlowBlinkCount;
1026 + ledToggle(pCurLed);
1027 + }
1028 + ledTimerStart();
1029 + break;
1030 +
1031 + case kLedStateFastBlinkContinues:
1032 + if (pCurLed->blinkCountDown-- == 0)
1033 + {
1034 + pCurLed->blinkCountDown = kFastBlinkCount;
1035 + ledToggle(pCurLed);
1036 + }
1037 + ledTimerStart();
1038 + break;
1039 +
1040 + default:
1041 + printk("Invalid state = %d\n", pCurLed->ledState);
1042 + }
1043 + }
1044 +}
1045 +
1046 +// initialize the gLedCount and allocate and fill gLed struct
1047 +void __init boardLedInit(PLED_MAP_PAIR cLedMapping)
1048 +{
1049 + PLED_MAP_PAIR p1, p2;
1050 + PLED_INFO pCurLed;
1051 + int needTimer = FALSE;
1052 + int alreadyUsed = 0;
1053 +
1054 +#if defined(CONFIG_BCM96348) || defined(CONFIG_BCM96338)
1055 + /* Set blink rate for BCM6348/BCM6338 hardware LEDs. */
1056 + GPIO->LEDCtrl &= ~LED_INTERVAL_SET_MASK;
1057 + GPIO->LEDCtrl |= LED_INTERVAL_SET_80MS;
1058 +#endif
1059 +
1060 + memset( gpVirtLeds, 0x00, sizeof(gpVirtLeds) );
1061 + memset( gLedHwFunc, 0x00, sizeof(gLedHwFunc) );
1062 + memset( gLedHwFailFunc, 0x00, sizeof(gLedHwFailFunc) );
1063 +
1064 + gLedCount = 0;
1065 +
1066 + // Check for multiple LED names and multiple LED GPIO pins that share the
1067 + // same physical board LED.
1068 + for( p1 = cLedMapping; p1->ledName != kLedEnd; p1++ )
1069 + {
1070 + alreadyUsed = 0;
1071 + for( p2 = cLedMapping; p2 != p1; p2++ )
1072 + {
1073 + if( (p1->ledMask && p1->ledMask == p2->ledMask) ||
1074 + (p1->ledMaskFail && p1->ledMaskFail == p2->ledMaskFail) )
1075 + {
1076 + alreadyUsed = 1;
1077 + break;
1078 + }
1079 + }
1080 +
1081 + if( alreadyUsed == 0 )
1082 + gLedCount++;
1083 + }
1084 +
1085 + gLed = (PLED_INFO) kmalloc((gLedCount * sizeof(LED_INFO)), GFP_KERNEL);
1086 + if( gLed == NULL )
1087 + {
1088 + printk( "LED memory allocation error.\n" );
1089 + return;
1090 + }
1091 +
1092 + memset( gLed, 0x00, gLedCount * sizeof(LED_INFO) );
1093 +
1094 + // initial the gLed with unique ledMask and initial state. If more than 1 ledNames share the physical led
1095 + // (ledMask) the first defined led's ledInitState will be used.
1096 + pCurLed = gLed;
1097 + for( p1 = cLedMapping; p1->ledName != kLedEnd; p1++ )
1098 + {
1099 + if( (int) p1->ledName > MAX_VIRT_LEDS )
1100 + continue;
1101 +
1102 + alreadyUsed = 0;
1103 + for( p2 = cLedMapping; p2 != p1; p2++ )
1104 + {
1105 + if( (p1->ledMask && p1->ledMask == p2->ledMask) ||
1106 + (p1->ledMaskFail && p1->ledMaskFail == p2->ledMaskFail) )
1107 + {
1108 + alreadyUsed = 1;
1109 + break;
1110 + }
1111 + }
1112 +
1113 + if( alreadyUsed == 0 )
1114 + {
1115 + // Initialize the board LED for the first time.
1116 + needTimer = initLedInfo( p1, pCurLed );
1117 + gpVirtLeds[(int) p1->ledName] = pCurLed;
1118 + pCurLed++;
1119 + }
1120 + else
1121 + {
1122 + PLED_INFO pLed;
1123 + for( pLed = gLed; pLed != pCurLed; pLed++ )
1124 + {
1125 + // Find the LED_INFO structure that has already been initialized.
1126 + if((pLed->ledMask && pLed->ledMask == p1->ledMask) ||
1127 + (pLed->ledMaskFail && pLed->ledMaskFail==p1->ledMaskFail))
1128 + {
1129 + // The board LED has already been initialized but possibly
1130 + // not completely initialized.
1131 + if( p1->ledMask )
1132 + {
1133 + pLed->ledMask = p1->ledMask;
1134 + pLed->ledActiveLow = p1->ledActiveLow;
1135 + }
1136 + if( p1->ledMaskFail )
1137 + {
1138 + pLed->ledMaskFail = p1->ledMaskFail;
1139 + pLed->ledActiveLowFail = p1->ledActiveLowFail;
1140 + }
1141 + gpVirtLeds[(int) p1->ledName] = pLed;
1142 + break;
1143 + }
1144 + }
1145 + }
1146 + }
1147 +
1148 + if (needTimer)
1149 + ledTimerStart();
1150 +
1151 +#if defined(DEBUG_LED)
1152 + int i;
1153 + for (i=0; i < gLedCount; i++)
1154 + printk("initLed: led[%d]: mask=0x%04x, state=%d\n", i,(gLed+i)->ledMask, (gLed+i)->ledState);
1155 +#endif
1156 +
1157 +}
1158 +
1159 +// Initialize a structure that contains information about a physical board LED
1160 +// control. The board LED may contain more than one GPIO pin to control a
1161 +// normal condition (green) or a failure condition (red).
1162 +int initLedInfo( PLED_MAP_PAIR pCurMap, PLED_INFO pCurLed )
1163 +{
1164 + int needTimer = FALSE;
1165 + pCurLed->ledState = pCurLed->savedLedState = pCurMap->ledInitState;
1166 + pCurLed->ledMask = pCurMap->ledMask;
1167 + pCurLed->ledActiveLow = pCurMap->ledActiveLow;
1168 + pCurLed->ledMaskFail = pCurMap->ledMaskFail;
1169 + pCurLed->ledActiveLowFail = pCurMap->ledActiveLowFail;
1170 +
1171 + switch (pCurLed->ledState)
1172 + {
1173 + case kLedStateOn:
1174 + pCurLed->blinkCountDown = 0; // reset the blink count down
1175 + ledOn(pCurLed);
1176 + break;
1177 + case kLedStateOff:
1178 + pCurLed->blinkCountDown = 0; // reset the blink count down
1179 + ledOff(pCurLed);
1180 + break;
1181 + case kLedStateFail:
1182 + pCurLed->blinkCountDown = 0; // reset the blink count down
1183 + ledOnFail(pCurLed);
1184 + break;
1185 + case kLedStateBlinkOnce:
1186 + pCurLed->blinkCountDown = 1;
1187 + needTimer = TRUE;
1188 + break;
1189 + case kLedStateSlowBlinkContinues:
1190 + pCurLed->blinkCountDown = kSlowBlinkCount;
1191 + needTimer = TRUE;
1192 + break;
1193 + case kLedStateFastBlinkContinues:
1194 + pCurLed->blinkCountDown = kFastBlinkCount;
1195 + needTimer = TRUE;
1196 + break;
1197 + default:
1198 + printk("Invalid state = %d\n", pCurLed->ledState);
1199 + }
1200 +
1201 + return( needTimer );
1202 +}
1203 +
1204 +#if 0 /* BROKEN */
1205 +// Determines if there is at least one interface in bridge mode. Bridge mode
1206 +// is determined by the cfm convention of naming bridge interfaces nas17
1207 +// through nas24.
1208 +static int isBridgedProtocol(void)
1209 +{
1210 + extern int dev_get(const char *name);
1211 + const int firstBridgeId = 17;
1212 + const int lastBridgeId = 24;
1213 + int i;
1214 + int ret = FALSE;
1215 + char name[16];
1216 +
1217 + for( i = firstBridgeId; i <= lastBridgeId; i++ )
1218 + {
1219 + sprintf( name, "nas%d", i );
1220 +
1221 + if( dev_get(name) )
1222 + {
1223 + ret = TRUE;
1224 + break;
1225 + }
1226 + }
1227 +
1228 + return(ret);
1229 +}
1230 +#endif
1231 +
1232 +// led ctrl. Maps the ledName to the corresponding ledInfoPtr and perform the led operation
1233 +void boardLedCtrl(BOARD_LED_NAME ledName, BOARD_LED_STATE ledState)
1234 +{
1235 + PLED_INFO ledInfoPtr;
1236 +
1237 + // do the mapping from virtual to physical led
1238 + if( (int) ledName < MAX_VIRT_LEDS )
1239 + ledInfoPtr = gpVirtLeds[(int) ledName];
1240 + else
1241 + ledInfoPtr = NULL;
1242 +
1243 + if (ledInfoPtr == NULL)
1244 + return;
1245 +
1246 + if( ledState != kLedStateFail && gLedHwFunc[(int) ledName] )
1247 + {
1248 + (*gLedHwFunc[(int) ledName]) (ledName, ledState);
1249 + ledOffFail(ledInfoPtr);
1250 + return;
1251 + }
1252 + else
1253 + if( ledState == kLedStateFail && gLedHwFailFunc[(int) ledName] )
1254 + {
1255 + (*gLedHwFailFunc[(int) ledName]) (ledName, ledState);
1256 + ledOff(ledInfoPtr);
1257 + return;
1258 + }
1259 +
1260 +#if 0 /* BROKEN */
1261 + // Do not blink the WAN Data LED if at least one interface is in bridge mode.
1262 + if(gLedOffInBridgeMode == 1 && (ledName == kLedWanData || ledName == kLedPPP))
1263 + {
1264 + static int BridgedProtocol = -1;
1265 +
1266 + if( BridgedProtocol == -1 )
1267 + BridgedProtocol = isBridgedProtocol();
1268 +
1269 + if( BridgedProtocol == TRUE )
1270 + return;
1271 + }
1272 +#endif
1273 +
1274 + // If the state is kLedStateFail and there is not a failure LED defined
1275 + // in the board parameters, change the state to kLedStateFastBlinkContinues.
1276 + if( ledState == kLedStateFail && ledInfoPtr->ledMaskFail == 0 )
1277 + ledState = kLedStateFastBlinkContinues;
1278 +
1279 + switch (ledState)
1280 + {
1281 + case kLedStateOn:
1282 + // First, turn off the complimentary (failure) LED GPIO.
1283 + if( ledInfoPtr->ledMaskFail )
1284 + ledOffFail(ledInfoPtr);
1285 + else
1286 + if( gLedHwFailFunc[(int) ledName] )
1287 + (*gLedHwFailFunc[(int) ledName]) (ledName, kLedStateOff);
1288 +
1289 + // Next, turn on the specified LED GPIO.
1290 + ledOn(ledInfoPtr);
1291 + break;
1292 +
1293 + case kLedStateOff:
1294 + // First, turn off the complimentary (failure) LED GPIO.
1295 + if( ledInfoPtr->ledMaskFail )
1296 + ledOffFail(ledInfoPtr);
1297 + else
1298 + if( gLedHwFailFunc[(int) ledName] )
1299 + (*gLedHwFailFunc[(int) ledName]) (ledName, kLedStateOff);
1300 +
1301 + // Next, turn off the specified LED GPIO.
1302 + ledOff(ledInfoPtr);
1303 + break;
1304 +
1305 + case kLedStateFail:
1306 + // First, turn off the complimentary (normal) LED GPIO.
1307 + if( ledInfoPtr->ledMask )
1308 + ledOff(ledInfoPtr);
1309 + else
1310 + if( gLedHwFunc[(int) ledName] )
1311 + (*gLedHwFunc[(int) ledName]) (ledName, kLedStateOff);
1312 +
1313 + // Next, turn on (red) the specified LED GPIO.
1314 + ledOnFail(ledInfoPtr);
1315 + break;
1316 +
1317 + case kLedStateBlinkOnce:
1318 + // skip blinkOnce if it is already in Slow/Fast blink continues state
1319 + if (ledInfoPtr->savedLedState == kLedStateSlowBlinkContinues ||
1320 + ledInfoPtr->savedLedState == kLedStateFastBlinkContinues)
1321 + ;
1322 + else
1323 + {
1324 + if (ledInfoPtr->blinkCountDown == 0) // skip the call if it is 1
1325 + {
1326 + ledToggle(ledInfoPtr);
1327 + ledInfoPtr->blinkCountDown = 1; // it will be reset to 0 when timer expires
1328 + ledInfoPtr->ledState = kLedStateBlinkOnce;
1329 + ledTimerStart();
1330 + }
1331 + }
1332 + break;
1333 +
1334 + case kLedStateSlowBlinkContinues:
1335 + ledInfoPtr->blinkCountDown = kSlowBlinkCount;
1336 + ledInfoPtr->ledState = kLedStateSlowBlinkContinues;
1337 + ledInfoPtr->savedLedState = kLedStateSlowBlinkContinues;
1338 + ledTimerStart();
1339 + break;
1340 +
1341 + case kLedStateFastBlinkContinues:
1342 + ledInfoPtr->blinkCountDown = kFastBlinkCount;
1343 + ledInfoPtr->ledState = kLedStateFastBlinkContinues;
1344 + ledInfoPtr->savedLedState = kLedStateFastBlinkContinues;
1345 + ledTimerStart();
1346 + break;
1347 +
1348 + default:
1349 + printk("Invalid led state\n");
1350 + }
1351 +}
1352 +
1353 +// This function is called for an LED that is controlled by hardware.
1354 +void kerSysLedRegisterHwHandler( BOARD_LED_NAME ledName,
1355 + HANDLE_LED_FUNC ledHwFunc, int ledFailType )
1356 +{
1357 + if( (int) ledName < MAX_VIRT_LEDS )
1358 + {
1359 + if( ledFailType == 1 )
1360 + gLedHwFailFunc[(int) ledName] = ledHwFunc;
1361 + else
1362 + gLedHwFunc[(int) ledName] = ledHwFunc;
1363 + }
1364 +}
1365 +
1366 diff -urN linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/board.c linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/board.c
1367 --- linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/board.c 1970-01-01 01:00:00.000000000 +0100
1368 +++ linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/board.c 2006-07-07 22:16:43.000000000 +0200
1369 @@ -0,0 +1,1614 @@
1370 +/*
1371 +<:copyright-gpl
1372 + Copyright 2002 Broadcom Corp. All Rights Reserved.
1373 +
1374 + This program is free software; you can distribute it and/or modify it
1375 + under the terms of the GNU General Public License (Version 2) as
1376 + published by the Free Software Foundation.
1377 +
1378 + This program is distributed in the hope it will be useful, but WITHOUT
1379 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1380 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1381 + for more details.
1382 +
1383 + You should have received a copy of the GNU General Public License along
1384 + with this program; if not, write to the Free Software Foundation, Inc.,
1385 + 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
1386 +:>
1387 +*/
1388 +/***************************************************************************
1389 + * File Name : board.c
1390 + *
1391 + * Description: This file contains Linux character device driver entry
1392 + * for the board related ioctl calls: flash, get free kernel
1393 + * page and dump kernel memory, etc.
1394 + *
1395 + * Created on : 2/20/2002 seanl: use cfiflash.c, cfliflash.h (AMD specific)
1396 + *
1397 + ***************************************************************************/
1398 +
1399 +
1400 +/* Includes. */
1401 +#include <linux/version.h>
1402 +#include <linux/init.h>
1403 +#include <linux/fs.h>
1404 +#include <linux/interrupt.h>
1405 +#include <linux/capability.h>
1406 +#include <linux/slab.h>
1407 +#include <linux/errno.h>
1408 +#include <linux/module.h>
1409 +#include <linux/pagemap.h>
1410 +#include <asm/uaccess.h>
1411 +#include <linux/wait.h>
1412 +#include <linux/poll.h>
1413 +#include <linux/sched.h>
1414 +#include <linux/list.h>
1415 +#include <linux/if.h>
1416 +
1417 +#include <bcm_map_part.h>
1418 +#include <board.h>
1419 +#include <bcmTag.h>
1420 +#include "boardparms.h"
1421 +#include "cfiflash.h"
1422 +#include "bcm_intr.h"
1423 +#include "board.h"
1424 +#include "bcm_map_part.h"
1425 +
1426 +/* Typedefs. */
1427 +#if defined (NON_CONSECUTIVE_MAC)
1428 +// used to be the last octet. Now changed to the first 5 bits of the the forth octet
1429 +// to reduced the duplicated MAC addresses.
1430 +#define CHANGED_OCTET 3
1431 +#define SHIFT_BITS 3
1432 +#else
1433 +#define CHANGED_OCTET 1
1434 +#define SHIFT_BITS 0
1435 +#endif
1436 +
1437 +#if defined (WIRELESS)
1438 +#define SES_BTN_PRESSED 0x00000001
1439 +#define SES_EVENTS SES_BTN_PRESSED /*OR all values if any*/
1440 +#define SES_LED_OFF 0
1441 +#define SES_LED_ON 1
1442 +#define SES_LED_BLINK 2
1443 +#endif
1444 +
1445 +typedef struct
1446 +{
1447 + unsigned long ulId;
1448 + char chInUse;
1449 + char chReserved[3];
1450 +} MAC_ADDR_INFO, *PMAC_ADDR_INFO;
1451 +
1452 +typedef struct
1453 +{
1454 + unsigned long ulSdramSize;
1455 + unsigned long ulPsiSize;
1456 + unsigned long ulNumMacAddrs;
1457 + unsigned long ucaBaseMacAddr[NVRAM_MAC_ADDRESS_LEN];
1458 + MAC_ADDR_INFO MacAddrs[1];
1459 +} NVRAM_INFO, *PNVRAM_INFO;
1460 +
1461 +typedef struct
1462 +{
1463 + unsigned long eventmask;
1464 +} BOARD_IOC, *PBOARD_IOC;
1465 +
1466 +
1467 +/*Dyinggasp callback*/
1468 +typedef void (*cb_dgasp_t)(void *arg);
1469 +typedef struct _CB_DGASP__LIST
1470 +{
1471 + struct list_head list;
1472 + char name[IFNAMSIZ];
1473 + cb_dgasp_t cb_dgasp_fn;
1474 + void *context;
1475 +}CB_DGASP_LIST , *PCB_DGASP_LIST;
1476 +
1477 +
1478 +static LED_MAP_PAIR LedMapping[] =
1479 +{ // led name Initial state physical pin (ledMask)
1480 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1481 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1482 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1483 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1484 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1485 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1486 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1487 + {kLedEnd, kLedStateOff, 0, 0, 0, 0},
1488 + {kLedEnd, kLedStateOff, 0, 0, 0, 0} // NOTE: kLedEnd has to be at the end.
1489 +};
1490 +
1491 +/* Externs. */
1492 +extern struct file fastcall *fget_light(unsigned int fd, int *fput_needed);
1493 +extern unsigned int nr_free_pages (void);
1494 +extern const char *get_system_type(void);
1495 +extern void kerSysFlashInit(void);
1496 +extern unsigned long get_nvram_start_addr(void);
1497 +extern unsigned long get_scratch_pad_start_addr(void);
1498 +extern unsigned long getMemorySize(void);
1499 +extern void __init boardLedInit(PLED_MAP_PAIR);
1500 +extern void boardLedCtrl(BOARD_LED_NAME, BOARD_LED_STATE);
1501 +extern void kerSysLedRegisterHandler( BOARD_LED_NAME ledName,
1502 + HANDLE_LED_FUNC ledHwFunc, int ledFailType );
1503 +
1504 +/* Prototypes. */
1505 +void __init InitNvramInfo( void );
1506 +static int board_open( struct inode *inode, struct file *filp );
1507 +static int board_ioctl( struct inode *inode, struct file *flip, unsigned int command, unsigned long arg );
1508 +static ssize_t board_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos);
1509 +static unsigned int board_poll(struct file *filp, struct poll_table_struct *wait);
1510 +static int board_release(struct inode *inode, struct file *filp);
1511 +
1512 +static BOARD_IOC* borad_ioc_alloc(void);
1513 +static void borad_ioc_free(BOARD_IOC* board_ioc);
1514 +
1515 +/* DyingGasp function prototype */
1516 +static void __init kerSysDyingGaspMapIntr(void);
1517 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1518 +static irqreturn_t kerSysDyingGaspIsr(int irq, void * dev_id, struct pt_regs * regs);
1519 +#else
1520 +static unsigned int kerSysDyingGaspIsr(void);
1521 +#endif
1522 +static void __init kerSysInitDyingGaspHandler( void );
1523 +static void __exit kerSysDeinitDyingGaspHandler( void );
1524 +/* -DyingGasp function prototype - */
1525 +
1526 +
1527 +#if defined (WIRELESS)
1528 +static irqreturn_t sesBtn_isr(int irq, void *dev_id, struct pt_regs *ptregs);
1529 +static void __init sesBtn_mapGpio(void);
1530 +static void __init sesBtn_mapIntr(int context);
1531 +static unsigned int sesBtn_poll(struct file *file, struct poll_table_struct *wait);
1532 +static ssize_t sesBtn_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
1533 +static void __init sesLed_mapGpio(void);
1534 +static void sesLed_ctrl(int action);
1535 +static void __init ses_board_init(void);
1536 +static void __exit ses_board_deinit(void);
1537 +#endif
1538 +
1539 +static PNVRAM_INFO g_pNvramInfo = NULL;
1540 +static int g_ledInitialized = 0;
1541 +static wait_queue_head_t g_board_wait_queue;
1542 +static CB_DGASP_LIST *g_cb_dgasp_list_head = NULL;
1543 +
1544 +static int g_wakeup_monitor = 0;
1545 +static struct file *g_monitor_file = NULL;
1546 +static struct task_struct *g_monitor_task = NULL;
1547 +static unsigned int (*g_orig_fop_poll)
1548 + (struct file *, struct poll_table_struct *) = NULL;
1549 +
1550 +static struct file_operations board_fops =
1551 +{
1552 + open: board_open,
1553 + ioctl: board_ioctl,
1554 + poll: board_poll,
1555 + read: board_read,
1556 + release: board_release,
1557 +};
1558 +
1559 +uint32 board_major = 0;
1560 +
1561 +#if defined (WIRELESS)
1562 +static unsigned short sesBtn_irq = BP_NOT_DEFINED;
1563 +static unsigned short sesBtn_gpio = BP_NOT_DEFINED;
1564 +static unsigned short sesLed_gpio = BP_NOT_DEFINED;
1565 +#endif
1566 +
1567 +#if defined(MODULE)
1568 +int init_module(void)
1569 +{
1570 + return( brcm_board_init() );
1571 +}
1572 +
1573 +void cleanup_module(void)
1574 +{
1575 + if (MOD_IN_USE)
1576 + printk("brcm flash: cleanup_module failed because module is in use\n");
1577 + else
1578 + brcm_board_cleanup();
1579 +}
1580 +#endif //MODULE
1581 +
1582 +
1583 +
1584 +static int __init brcm_board_init( void )
1585 +{
1586 + typedef int (*BP_LED_FUNC) (unsigned short *);
1587 + static struct BpLedInformation
1588 + {
1589 + BOARD_LED_NAME ledName;
1590 + BP_LED_FUNC bpFunc;
1591 + BP_LED_FUNC bpFuncFail;
1592 + } bpLedInfo[] =
1593 + {{kLedAdsl, BpGetAdslLedGpio, BpGetAdslFailLedGpio},
1594 + {kLedWireless, BpGetWirelessLedGpio, NULL},
1595 + {kLedUsb, BpGetUsbLedGpio, NULL},
1596 + {kLedHpna, BpGetHpnaLedGpio, NULL},
1597 + {kLedWanData, BpGetWanDataLedGpio, NULL},
1598 + {kLedPPP, BpGetPppLedGpio, BpGetPppFailLedGpio},
1599 + {kLedVoip, BpGetVoipLedGpio, NULL},
1600 + {kLedSes, BpGetWirelessSesLedGpio, NULL},
1601 + {kLedEnd, NULL, NULL}
1602 + };
1603 +
1604 + int ret;
1605 +
1606 + ret = register_chrdev(BOARD_DRV_MAJOR, "bcrmboard", &board_fops );
1607 + if (ret < 0)
1608 + printk( "brcm_board_init(major %d): fail to register device.\n",BOARD_DRV_MAJOR);
1609 + else
1610 + {
1611 + PLED_MAP_PAIR pLedMap = LedMapping;
1612 + unsigned short gpio;
1613 + struct BpLedInformation *pInfo;
1614 +
1615 + printk("brcmboard: brcm_board_init entry\n");
1616 + board_major = BOARD_DRV_MAJOR;
1617 + InitNvramInfo();
1618 +
1619 + for( pInfo = bpLedInfo; pInfo->ledName != kLedEnd; pInfo++ )
1620 + {
1621 + if( pInfo->bpFunc && (*pInfo->bpFunc) (&gpio) == BP_SUCCESS )
1622 + {
1623 + pLedMap->ledName = pInfo->ledName;
1624 + pLedMap->ledMask = GPIO_NUM_TO_MASK(gpio);
1625 + pLedMap->ledActiveLow = (gpio & BP_ACTIVE_LOW) ? 1 : 0;
1626 + }
1627 + if( pInfo->bpFuncFail && (*pInfo->bpFuncFail) (&gpio) == BP_SUCCESS )
1628 + {
1629 + pLedMap->ledName = pInfo->ledName;
1630 + pLedMap->ledMaskFail = GPIO_NUM_TO_MASK(gpio);
1631 + pLedMap->ledActiveLowFail = (gpio & BP_ACTIVE_LOW) ? 1 : 0;
1632 + }
1633 + if( pLedMap->ledName != kLedEnd )
1634 + pLedMap++;
1635 + }
1636 +
1637 + init_waitqueue_head(&g_board_wait_queue);
1638 +#if defined (WIRELESS)
1639 + ses_board_init();
1640 +#endif
1641 + kerSysInitDyingGaspHandler();
1642 + kerSysDyingGaspMapIntr();
1643 +
1644 + boardLedInit(LedMapping);
1645 + g_ledInitialized = 1;
1646 + }
1647 +
1648 + return ret;
1649 +}
1650 +
1651 +void __init InitNvramInfo( void )
1652 +{
1653 + PNVRAM_DATA pNvramData = (PNVRAM_DATA) get_nvram_start_addr();
1654 + unsigned long ulNumMacAddrs = pNvramData->ulNumMacAddrs;
1655 +
1656 + if( ulNumMacAddrs > 0 && ulNumMacAddrs <= NVRAM_MAC_COUNT_MAX )
1657 + {
1658 + unsigned long ulNvramInfoSize =
1659 + sizeof(NVRAM_INFO) + ((sizeof(MAC_ADDR_INFO) - 1) * ulNumMacAddrs);
1660 +
1661 + g_pNvramInfo = (PNVRAM_INFO) kmalloc( ulNvramInfoSize, GFP_KERNEL );
1662 +
1663 + if( g_pNvramInfo )
1664 + {
1665 + unsigned long ulPsiSize;
1666 + if( BpGetPsiSize( &ulPsiSize ) != BP_SUCCESS )
1667 + ulPsiSize = NVRAM_PSI_DEFAULT;
1668 + memset( g_pNvramInfo, 0x00, ulNvramInfoSize );
1669 + g_pNvramInfo->ulPsiSize = ulPsiSize * 1024;
1670 + g_pNvramInfo->ulNumMacAddrs = pNvramData->ulNumMacAddrs;
1671 + memcpy( g_pNvramInfo->ucaBaseMacAddr, pNvramData->ucaBaseMacAddr,
1672 + NVRAM_MAC_ADDRESS_LEN );
1673 + g_pNvramInfo->ulSdramSize = getMemorySize();
1674 + }
1675 + else
1676 + printk("ERROR - Could not allocate memory for NVRAM data\n");
1677 + }
1678 + else
1679 + printk("ERROR - Invalid number of MAC addresses (%ld) is configured.\n",
1680 + ulNumMacAddrs);
1681 +}
1682 +
1683 +void __exit brcm_board_cleanup( void )
1684 +{
1685 + printk("brcm_board_cleanup()\n");
1686 +
1687 + if (board_major != -1)
1688 + {
1689 +#if defined (WIRELESS)
1690 + ses_board_deinit();
1691 +#endif
1692 + kerSysDeinitDyingGaspHandler();
1693 + unregister_chrdev(board_major, "board_ioctl");
1694 + }
1695 +}
1696 +
1697 +static BOARD_IOC* borad_ioc_alloc(void)
1698 +{
1699 + BOARD_IOC *board_ioc =NULL;
1700 + board_ioc = (BOARD_IOC*) kmalloc( sizeof(BOARD_IOC) , GFP_KERNEL );
1701 + if(board_ioc)
1702 + {
1703 + memset(board_ioc, 0, sizeof(BOARD_IOC));
1704 + }
1705 + return board_ioc;
1706 +}
1707 +
1708 +static void borad_ioc_free(BOARD_IOC* board_ioc)
1709 +{
1710 + if(board_ioc)
1711 + {
1712 + kfree(board_ioc);
1713 + }
1714 +}
1715 +
1716 +
1717 +static int board_open( struct inode *inode, struct file *filp )
1718 +{
1719 + filp->private_data = borad_ioc_alloc();
1720 +
1721 + if (filp->private_data == NULL)
1722 + return -ENOMEM;
1723 +
1724 + return( 0 );
1725 +}
1726 +
1727 +static int board_release(struct inode *inode, struct file *filp)
1728 +{
1729 + BOARD_IOC *board_ioc = filp->private_data;
1730 +
1731 + wait_event_interruptible(g_board_wait_queue, 1);
1732 + borad_ioc_free(board_ioc);
1733 +
1734 + return( 0 );
1735 +}
1736 +
1737 +
1738 +static unsigned int board_poll(struct file *filp, struct poll_table_struct *wait)
1739 +{
1740 + unsigned int mask = 0;
1741 +#if defined (WIRELESS)
1742 + BOARD_IOC *board_ioc = filp->private_data;
1743 +#endif
1744 +
1745 + poll_wait(filp, &g_board_wait_queue, wait);
1746 +#if defined (WIRELESS)
1747 + if(board_ioc->eventmask & SES_EVENTS){
1748 + mask |= sesBtn_poll(filp, wait);
1749 + }
1750 +#endif
1751 +
1752 + return mask;
1753 +}
1754 +
1755 +
1756 +static ssize_t board_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos)
1757 +{
1758 +#if defined (WIRELESS)
1759 + BOARD_IOC *board_ioc = filp->private_data;
1760 + if(board_ioc->eventmask & SES_EVENTS){
1761 + return sesBtn_read(filp, buffer, count, ppos);
1762 + }
1763 +#endif
1764 + return 0;
1765 +}
1766 +
1767 +//**************************************************************************************
1768 +// Utitlities for dump memory, free kernel pages, mips soft reset, etc.
1769 +//**************************************************************************************
1770 +
1771 +/***********************************************************************
1772 + * Function Name: dumpaddr
1773 + * Description : Display a hex dump of the specified address.
1774 + ***********************************************************************/
1775 +void dumpaddr( unsigned char *pAddr, int nLen )
1776 +{
1777 + static char szHexChars[] = "0123456789abcdef";
1778 + char szLine[80];
1779 + char *p = szLine;
1780 + unsigned char ch, *q;
1781 + int i, j;
1782 + unsigned long ul;
1783 +
1784 + while( nLen > 0 )
1785 + {
1786 + sprintf( szLine, "%8.8lx: ", (unsigned long) pAddr );
1787 + p = szLine + strlen(szLine);
1788 +
1789 + for(i = 0; i < 16 && nLen > 0; i += sizeof(long), nLen -= sizeof(long))
1790 + {
1791 + ul = *(unsigned long *) &pAddr[i];
1792 + q = (unsigned char *) &ul;
1793 + for( j = 0; j < sizeof(long); j++ )
1794 + {
1795 + *p++ = szHexChars[q[j] >> 4];
1796 + *p++ = szHexChars[q[j] & 0x0f];
1797 + *p++ = ' ';
1798 + }
1799 + }
1800 +
1801 + for( j = 0; j < 16 - i; j++ )
1802 + *p++ = ' ', *p++ = ' ', *p++ = ' ';
1803 +
1804 + *p++ = ' ', *p++ = ' ', *p++ = ' ';
1805 +
1806 + for( j = 0; j < i; j++ )
1807 + {
1808 + ch = pAddr[j];
1809 + *p++ = (ch > ' ' && ch < '~') ? ch : '.';
1810 + }
1811 +
1812 + *p++ = '\0';
1813 + printk( "%s\r\n", szLine );
1814 +
1815 + pAddr += i;
1816 + }
1817 + printk( "\r\n" );
1818 +} /* dumpaddr */
1819 +
1820 +
1821 +void kerSysMipsSoftReset(void)
1822 +{
1823 +#if defined(CONFIG_BCM96348)
1824 + if (PERF->RevID == 0x634800A1) {
1825 + typedef void (*FNPTR) (void);
1826 + FNPTR bootaddr = (FNPTR) FLASH_BASE;
1827 + int i;
1828 +
1829 + /* Disable interrupts. */
1830 + cli();
1831 +
1832 + /* Reset all blocks. */
1833 + PERF->BlockSoftReset &= ~BSR_ALL_BLOCKS;
1834 + for( i = 0; i < 1000000; i++ )
1835 + ;
1836 + PERF->BlockSoftReset |= BSR_ALL_BLOCKS;
1837 + /* Jump to the power on address. */
1838 + (*bootaddr) ();
1839 + }
1840 + else
1841 + PERF->pll_control |= SOFT_RESET; // soft reset mips
1842 +#else
1843 + PERF->pll_control |= SOFT_RESET; // soft reset mips
1844 +#endif
1845 +}
1846 +
1847 +
1848 +int kerSysGetMacAddress( unsigned char *pucaMacAddr, unsigned long ulId )
1849 +{
1850 + int nRet = 0;
1851 + PMAC_ADDR_INFO pMai = NULL;
1852 + PMAC_ADDR_INFO pMaiFreeNoId = NULL;
1853 + PMAC_ADDR_INFO pMaiFreeId = NULL;
1854 + unsigned long i = 0, ulIdxNoId = 0, ulIdxId = 0, shiftedIdx = 0;
1855 +
1856 + for( i = 0, pMai = g_pNvramInfo->MacAddrs; i < g_pNvramInfo->ulNumMacAddrs;
1857 + i++, pMai++ )
1858 + {
1859 + if( ulId == pMai->ulId || ulId == MAC_ADDRESS_ANY )
1860 + {
1861 + /* This MAC address has been used by the caller in the past. */
1862 + memcpy( pucaMacAddr, g_pNvramInfo->ucaBaseMacAddr,
1863 + NVRAM_MAC_ADDRESS_LEN );
1864 + shiftedIdx = i;
1865 + pucaMacAddr[NVRAM_MAC_ADDRESS_LEN - CHANGED_OCTET] += (shiftedIdx << SHIFT_BITS);
1866 + pMai->chInUse = 1;
1867 + pMaiFreeNoId = pMaiFreeId = NULL;
1868 + break;
1869 + }
1870 + else
1871 + if( pMai->chInUse == 0 )
1872 + {
1873 + if( pMai->ulId == 0 && pMaiFreeNoId == NULL )
1874 + {
1875 + /* This is an available MAC address that has never been
1876 + * used.
1877 + */
1878 + pMaiFreeNoId = pMai;
1879 + ulIdxNoId = i;
1880 + }
1881 + else
1882 + if( pMai->ulId != 0 && pMaiFreeId == NULL )
1883 + {
1884 + /* This is an available MAC address that has been used
1885 + * before. Use addresses that have never been used
1886 + * first, before using this one.
1887 + */
1888 + pMaiFreeId = pMai;
1889 + ulIdxId = i;
1890 + }
1891 + }
1892 + }
1893 +
1894 + if( pMaiFreeNoId || pMaiFreeId )
1895 + {
1896 + /* An available MAC address was found. */
1897 + memcpy(pucaMacAddr, g_pNvramInfo->ucaBaseMacAddr,NVRAM_MAC_ADDRESS_LEN);
1898 + if( pMaiFreeNoId )
1899 + {
1900 + shiftedIdx = ulIdxNoId;
1901 + pucaMacAddr[NVRAM_MAC_ADDRESS_LEN - CHANGED_OCTET] += (shiftedIdx << SHIFT_BITS);
1902 + pMaiFreeNoId->ulId = ulId;
1903 + pMaiFreeNoId->chInUse = 1;
1904 + }
1905 + else
1906 + {
1907 + shiftedIdx = ulIdxId;
1908 + pucaMacAddr[NVRAM_MAC_ADDRESS_LEN - CHANGED_OCTET] += (shiftedIdx << SHIFT_BITS);
1909 + pMaiFreeId->ulId = ulId;
1910 + pMaiFreeId->chInUse = 1;
1911 + }
1912 + }
1913 + else
1914 + if( i == g_pNvramInfo->ulNumMacAddrs )
1915 + nRet = -EADDRNOTAVAIL;
1916 +
1917 + return( nRet );
1918 +} /* kerSysGetMacAddr */
1919 +
1920 +int kerSysReleaseMacAddress( unsigned char *pucaMacAddr )
1921 +{
1922 + int nRet = -EINVAL;
1923 + unsigned long ulIdx = 0;
1924 + int idx = (pucaMacAddr[NVRAM_MAC_ADDRESS_LEN - CHANGED_OCTET] -
1925 + g_pNvramInfo->ucaBaseMacAddr[NVRAM_MAC_ADDRESS_LEN - CHANGED_OCTET]);
1926 +
1927 + // if overflow 255 (negitive), add 256 to have the correct index
1928 + if (idx < 0)
1929 + idx += 256;
1930 + ulIdx = (unsigned long) (idx >> SHIFT_BITS);
1931 +
1932 + if( ulIdx < g_pNvramInfo->ulNumMacAddrs )
1933 + {
1934 + PMAC_ADDR_INFO pMai = &g_pNvramInfo->MacAddrs[ulIdx];
1935 + if( pMai->chInUse == 1 )
1936 + {
1937 + pMai->chInUse = 0;
1938 + nRet = 0;
1939 + }
1940 + }
1941 +
1942 + return( nRet );
1943 +} /* kerSysReleaseMacAddr */
1944 +
1945 +int kerSysGetSdramSize( void )
1946 +{
1947 + return( (int) g_pNvramInfo->ulSdramSize );
1948 +} /* kerSysGetSdramSize */
1949 +
1950 +
1951 +void kerSysLedCtrl(BOARD_LED_NAME ledName, BOARD_LED_STATE ledState)
1952 +{
1953 + if (g_ledInitialized)
1954 + boardLedCtrl(ledName, ledState);
1955 +}
1956 +
1957 +unsigned int kerSysMonitorPollHook( struct file *f, struct poll_table_struct *t)
1958 +{
1959 + int mask = (*g_orig_fop_poll) (f, t);
1960 +
1961 + if( g_wakeup_monitor == 1 && g_monitor_file == f )
1962 + {
1963 + /* If g_wakeup_monitor is non-0, the user mode application needs to
1964 + * return from a blocking select function. Return POLLPRI which will
1965 + * cause the select to return with the exception descriptor set.
1966 + */
1967 + mask |= POLLPRI;
1968 + g_wakeup_monitor = 0;
1969 + }
1970 +
1971 + return( mask );
1972 +}
1973 +
1974 +/* Put the user mode application that monitors link state on a run queue. */
1975 +void kerSysWakeupMonitorTask( void )
1976 +{
1977 + g_wakeup_monitor = 1;
1978 + if( g_monitor_task )
1979 + wake_up_process( g_monitor_task );
1980 +}
1981 +
1982 +//<<JUNHON, 2004/09/15, get reset button status , tim hou , 05/04/12
1983 +int kerSysGetResetHold(void)
1984 +{
1985 + unsigned short gpio;
1986 +
1987 + if( BpGetPressAndHoldResetGpio( &gpio ) == BP_SUCCESS )
1988 + {
1989 +#if defined(CONFIG_BCM96338)
1990 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(gpio);
1991 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
1992 +#endif
1993 +#if defined(CONFIG_BCM96345)
1994 + unsigned short gpio_mask = GPIO_NUM_TO_MASK(gpio);
1995 + volatile unsigned short *gpio_reg = &GPIO->GPIOio;
1996 +#endif
1997 +#if defined(CONFIG_BCM96348)
1998 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(gpio);
1999 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2000 +
2001 + if( (gpio & ~BP_ACTIVE_MASK) >= 32 )
2002 + {
2003 + gpio_mask = GPIO_NUM_TO_MASK_HIGH(gpio);
2004 + gpio_reg = &GPIO->GPIOio_high;
2005 + }
2006 +#endif
2007 + //printk("gpio=%04x,gpio_mask=%04x,gpio_reg=%04x\n",gpio,gpio_mask,*gpio_reg);
2008 + if(*gpio_reg & gpio_mask) //press down
2009 + return RESET_BUTTON_UP;
2010 + }
2011 + return RESET_BUTTON_PRESSDOWN;
2012 +}
2013 +//<<JUNHON, 2004/09/15
2014 +
2015 +//********************************************************************************************
2016 +// misc. ioctl calls come to here. (flash, led, reset, kernel memory access, etc.)
2017 +//********************************************************************************************
2018 +static int board_ioctl( struct inode *inode, struct file *flip,
2019 + unsigned int command, unsigned long arg )
2020 +{
2021 + int ret = 0;
2022 + BOARD_IOCTL_PARMS ctrlParms;
2023 + unsigned char ucaMacAddr[NVRAM_MAC_ADDRESS_LEN];
2024 + int allowedSize;
2025 +
2026 + switch (command)
2027 + {
2028 + case BOARD_IOCTL_FLASH_INIT:
2029 + // not used for now. kerSysBcmImageInit();
2030 + break;
2031 +
2032 +
2033 + case BOARD_IOCTL_FLASH_WRITE:
2034 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2035 + {
2036 + NVRAM_DATA SaveNvramData;
2037 + PNVRAM_DATA pNvramData = (PNVRAM_DATA) get_nvram_start_addr();
2038 +
2039 + switch (ctrlParms.action)
2040 + {
2041 + case SCRATCH_PAD:
2042 + ret = kerSysScratchPadSet(ctrlParms.string, ctrlParms.buf, ctrlParms.offset);
2043 + break;
2044 +
2045 + case PERSISTENT:
2046 + ret = kerSysPersistentSet(ctrlParms.string, ctrlParms.strLen, ctrlParms.offset);
2047 + break;
2048 +
2049 + case NVRAM:
2050 + ret = kerSysNvRamSet(ctrlParms.string, ctrlParms.strLen, ctrlParms.offset);
2051 + break;
2052 +
2053 + case BCM_IMAGE_CFE:
2054 + if( ctrlParms.strLen <= 0 || ctrlParms.strLen > FLASH45_LENGTH_BOOT_ROM )
2055 + {
2056 + printk("Illegal CFE size [%d]. Size allowed: [%d]\n",
2057 + ctrlParms.strLen, FLASH45_LENGTH_BOOT_ROM);
2058 + ret = -1;
2059 + break;
2060 + }
2061 +
2062 + // save NVRAM data into a local structure
2063 + memcpy( &SaveNvramData, pNvramData, sizeof(NVRAM_DATA) );
2064 +
2065 + // set memory type field
2066 + BpGetSdramSize( (unsigned long *) &ctrlParms.string[SDRAM_TYPE_ADDRESS_OFFSET] );
2067 +
2068 + ret = kerSysBcmImageSet(ctrlParms.offset, ctrlParms.string, ctrlParms.strLen);
2069 +
2070 + // if nvram is not valid, restore the current nvram settings
2071 + if( BpSetBoardId( pNvramData->szBoardId ) != BP_SUCCESS &&
2072 + *(unsigned long *) pNvramData == NVRAM_DATA_ID )
2073 + {
2074 + kerSysNvRamSet((char *) &SaveNvramData, sizeof(SaveNvramData), 0);
2075 + }
2076 + break;
2077 +
2078 + case BCM_IMAGE_FS:
2079 + allowedSize = (int) flash_get_total_size() - \
2080 + FLASH_RESERVED_AT_END - TAG_LEN - FLASH45_LENGTH_BOOT_ROM;
2081 + if( ctrlParms.strLen <= 0 || ctrlParms.strLen > allowedSize)
2082 + {
2083 + printk("Illegal root file system size [%d]. Size allowed: [%d]\n",
2084 + ctrlParms.strLen, allowedSize);
2085 + ret = -1;
2086 + break;
2087 + }
2088 + ret = kerSysBcmImageSet(ctrlParms.offset, ctrlParms.string, ctrlParms.strLen);
2089 + kerSysMipsSoftReset();
2090 + break;
2091 +
2092 + case BCM_IMAGE_KERNEL: // not used for now.
2093 + break;
2094 + case BCM_IMAGE_WHOLE:
2095 + if(ctrlParms.strLen <= 0)
2096 + {
2097 + printk("Illegal flash image size [%d].\n", ctrlParms.strLen);
2098 + ret = -1;
2099 + break;
2100 + }
2101 +
2102 + // save NVRAM data into a local structure
2103 + memcpy( &SaveNvramData, pNvramData, sizeof(NVRAM_DATA) );
2104 +
2105 + ret = kerSysBcmImageSet(ctrlParms.offset, ctrlParms.string, ctrlParms.strLen);
2106 +
2107 + // if nvram is not valid, restore the current nvram settings
2108 + if( BpSetBoardId( pNvramData->szBoardId ) != BP_SUCCESS &&
2109 + *(unsigned long *) pNvramData == NVRAM_DATA_ID )
2110 + {
2111 + kerSysNvRamSet((char *) &SaveNvramData, sizeof(SaveNvramData), 0);
2112 + }
2113 +
2114 + kerSysMipsSoftReset();
2115 + break;
2116 +
2117 + default:
2118 + ret = -EINVAL;
2119 + printk("flash_ioctl_command: invalid command %d\n", ctrlParms.action);
2120 + break;
2121 + }
2122 + ctrlParms.result = ret;
2123 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2124 + }
2125 + else
2126 + ret = -EFAULT;
2127 + break;
2128 +
2129 + case BOARD_IOCTL_FLASH_READ:
2130 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2131 + {
2132 + switch (ctrlParms.action)
2133 + {
2134 + case SCRATCH_PAD:
2135 + ret = kerSysScratchPadGet(ctrlParms.string, ctrlParms.buf, ctrlParms.offset);
2136 + break;
2137 +
2138 + case PERSISTENT:
2139 + ret = kerSysPersistentGet(ctrlParms.string, ctrlParms.strLen, ctrlParms.offset);
2140 + break;
2141 +
2142 + case NVRAM:
2143 + ret = kerSysNvRamGet(ctrlParms.string, ctrlParms.strLen, ctrlParms.offset);
2144 + break;
2145 +
2146 + case FLASH_SIZE:
2147 + ret = kerSysFlashSizeGet();
2148 + break;
2149 +
2150 + default:
2151 + ret = -EINVAL;
2152 + printk("Not supported. invalid command %d\n", ctrlParms.action);
2153 + break;
2154 + }
2155 + ctrlParms.result = ret;
2156 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2157 + }
2158 + else
2159 + ret = -EFAULT;
2160 + break;
2161 +
2162 + case BOARD_IOCTL_GET_NR_PAGES:
2163 + ctrlParms.result = nr_free_pages() + get_page_cache_size();
2164 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2165 + ret = 0;
2166 + break;
2167 +
2168 + case BOARD_IOCTL_DUMP_ADDR:
2169 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2170 + {
2171 + dumpaddr( (unsigned char *) ctrlParms.string, ctrlParms.strLen );
2172 + ctrlParms.result = 0;
2173 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2174 + ret = 0;
2175 + }
2176 + else
2177 + ret = -EFAULT;
2178 + break;
2179 +
2180 + case BOARD_IOCTL_SET_MEMORY:
2181 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2182 + {
2183 + unsigned long *pul = (unsigned long *) ctrlParms.string;
2184 + unsigned short *pus = (unsigned short *) ctrlParms.string;
2185 + unsigned char *puc = (unsigned char *) ctrlParms.string;
2186 + switch( ctrlParms.strLen )
2187 + {
2188 + case 4:
2189 + *pul = (unsigned long) ctrlParms.offset;
2190 + break;
2191 + case 2:
2192 + *pus = (unsigned short) ctrlParms.offset;
2193 + break;
2194 + case 1:
2195 + *puc = (unsigned char) ctrlParms.offset;
2196 + break;
2197 + }
2198 + dumpaddr( (unsigned char *) ctrlParms.string, sizeof(long) );
2199 + ctrlParms.result = 0;
2200 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2201 + ret = 0;
2202 + }
2203 + else
2204 + ret = -EFAULT;
2205 + break;
2206 +
2207 + case BOARD_IOCTL_MIPS_SOFT_RESET:
2208 + kerSysMipsSoftReset();
2209 + break;
2210 +
2211 + case BOARD_IOCTL_LED_CTRL:
2212 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2213 + {
2214 + kerSysLedCtrl((BOARD_LED_NAME)ctrlParms.strLen, (BOARD_LED_STATE)ctrlParms.offset);
2215 + ret = 0;
2216 + }
2217 + break;
2218 +
2219 + case BOARD_IOCTL_GET_ID:
2220 + if (copy_from_user((void*)&ctrlParms, (void*)arg,
2221 + sizeof(ctrlParms)) == 0)
2222 + {
2223 + if( ctrlParms.string )
2224 + {
2225 + char *p = (char *) get_system_type();
2226 + if( strlen(p) + 1 < ctrlParms.strLen )
2227 + ctrlParms.strLen = strlen(p) + 1;
2228 + __copy_to_user(ctrlParms.string, p, ctrlParms.strLen);
2229 + }
2230 +
2231 + ctrlParms.result = 0;
2232 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms,
2233 + sizeof(BOARD_IOCTL_PARMS));
2234 + }
2235 + break;
2236 +
2237 + case BOARD_IOCTL_GET_MAC_ADDRESS:
2238 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2239 + {
2240 + ctrlParms.result = kerSysGetMacAddress( ucaMacAddr,
2241 + ctrlParms.offset );
2242 +
2243 + if( ctrlParms.result == 0 )
2244 + {
2245 + __copy_to_user(ctrlParms.string, ucaMacAddr,
2246 + sizeof(ucaMacAddr));
2247 + }
2248 +
2249 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms,
2250 + sizeof(BOARD_IOCTL_PARMS));
2251 + ret = 0;
2252 + }
2253 + else
2254 + ret = -EFAULT;
2255 + break;
2256 +
2257 + case BOARD_IOCTL_RELEASE_MAC_ADDRESS:
2258 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2259 + {
2260 + if (copy_from_user((void*)ucaMacAddr, (void*)ctrlParms.string, \
2261 + NVRAM_MAC_ADDRESS_LEN) == 0)
2262 + {
2263 + ctrlParms.result = kerSysReleaseMacAddress( ucaMacAddr );
2264 + }
2265 + else
2266 + {
2267 + ctrlParms.result = -EACCES;
2268 + }
2269 +
2270 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms,
2271 + sizeof(BOARD_IOCTL_PARMS));
2272 + ret = 0;
2273 + }
2274 + else
2275 + ret = -EFAULT;
2276 + break;
2277 +
2278 + case BOARD_IOCTL_GET_PSI_SIZE:
2279 + ctrlParms.result = (int) g_pNvramInfo->ulPsiSize;
2280 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2281 + ret = 0;
2282 + break;
2283 +
2284 + case BOARD_IOCTL_GET_SDRAM_SIZE:
2285 + ctrlParms.result = (int) g_pNvramInfo->ulSdramSize;
2286 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2287 + ret = 0;
2288 + break;
2289 +
2290 + case BOARD_IOCTL_GET_BASE_MAC_ADDRESS:
2291 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0)
2292 + {
2293 + __copy_to_user(ctrlParms.string, g_pNvramInfo->ucaBaseMacAddr, NVRAM_MAC_ADDRESS_LEN);
2294 + ctrlParms.result = 0;
2295 +
2296 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms,
2297 + sizeof(BOARD_IOCTL_PARMS));
2298 + ret = 0;
2299 + }
2300 + else
2301 + ret = -EFAULT;
2302 + break;
2303 +
2304 + case BOARD_IOCTL_GET_CHIP_ID:
2305 + ctrlParms.result = (int) (PERF->RevID & 0xFFFF0000) >> 16;
2306 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2307 + ret = 0;
2308 + break;
2309 +
2310 + case BOARD_IOCTL_GET_NUM_ENET: {
2311 + ETHERNET_MAC_INFO EnetInfos[BP_MAX_ENET_MACS];
2312 + int i, numeth = 0;
2313 + if (BpGetEthernetMacInfo(EnetInfos, BP_MAX_ENET_MACS) == BP_SUCCESS) {
2314 + for( i = 0; i < BP_MAX_ENET_MACS; i++) {
2315 + if (EnetInfos[i].ucPhyType != BP_ENET_NO_PHY) {
2316 + numeth++;
2317 + }
2318 + }
2319 + ctrlParms.result = numeth;
2320 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2321 + ret = 0;
2322 + }
2323 + else {
2324 + ret = -EFAULT;
2325 + }
2326 + break;
2327 + }
2328 +
2329 + case BOARD_IOCTL_GET_CFE_VER:
2330 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2331 + char *vertag = (char *)(FLASH_BASE + CFE_VERSION_OFFSET);
2332 + if (ctrlParms.strLen < CFE_VERSION_SIZE) {
2333 + ctrlParms.result = 0;
2334 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2335 + ret = -EFAULT;
2336 + }
2337 + else if (strncmp(vertag, "cfe-v", 5)) { // no tag info in flash
2338 + ctrlParms.result = 0;
2339 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2340 + ret = 0;
2341 + }
2342 + else {
2343 + ctrlParms.result = 1;
2344 + __copy_to_user(ctrlParms.string, vertag+CFE_VERSION_MARK_SIZE, CFE_VERSION_SIZE);
2345 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2346 + ret = 0;
2347 + }
2348 + }
2349 + else {
2350 + ret = -EFAULT;
2351 + }
2352 + break;
2353 +
2354 + case BOARD_IOCTL_GET_ENET_CFG:
2355 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2356 + ETHERNET_MAC_INFO EnetInfos[BP_MAX_ENET_MACS];
2357 + if (BpGetEthernetMacInfo(EnetInfos, BP_MAX_ENET_MACS) == BP_SUCCESS) {
2358 + if (ctrlParms.strLen == sizeof(EnetInfos)) {
2359 + __copy_to_user(ctrlParms.string, EnetInfos, sizeof(EnetInfos));
2360 + ctrlParms.result = 0;
2361 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2362 + ret = 0;
2363 + } else
2364 + ret = -EFAULT;
2365 + }
2366 + else {
2367 + ret = -EFAULT;
2368 + }
2369 + break;
2370 + }
2371 + else {
2372 + ret = -EFAULT;
2373 + }
2374 + break;
2375 +//<<JUNHON, 2004/09/15, get reset button status , tim hou , 05/04/12
2376 + case BOARD_IOCTL_GET_RESETHOLD:
2377 + ctrlParms.result = kerSysGetResetHold();
2378 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2379 + ret = 0;
2380 + break;
2381 +//>>JUNHON, 2004/09/15
2382 +
2383 +
2384 +#if defined (WIRELESS)
2385 + case BOARD_IOCTL_GET_WLAN_ANT_INUSE:
2386 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2387 + unsigned short antInUse = 0;
2388 + if (BpGetWirelessAntInUse(&antInUse) == BP_SUCCESS) {
2389 + if (ctrlParms.strLen == sizeof(antInUse)) {
2390 + __copy_to_user(ctrlParms.string, &antInUse, sizeof(antInUse));
2391 + ctrlParms.result = 0;
2392 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2393 + ret = 0;
2394 + } else
2395 + ret = -EFAULT;
2396 + }
2397 + else {
2398 + ret = -EFAULT;
2399 + }
2400 + break;
2401 + }
2402 + else {
2403 + ret = -EFAULT;
2404 + }
2405 + break;
2406 +#endif
2407 + case BOARD_IOCTL_SET_TRIGGER_EVENT:
2408 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2409 + BOARD_IOC *board_ioc = (BOARD_IOC *)flip->private_data;
2410 + ctrlParms.result = -EFAULT;
2411 + ret = -EFAULT;
2412 + if (ctrlParms.strLen == sizeof(unsigned long)) {
2413 + board_ioc->eventmask |= *((int*)ctrlParms.string);
2414 +#if defined (WIRELESS)
2415 + if((board_ioc->eventmask & SES_EVENTS)) {
2416 + if(sesBtn_irq != BP_NOT_DEFINED) {
2417 + BcmHalInterruptEnable(sesBtn_irq);
2418 + ctrlParms.result = 0;
2419 + ret = 0;
2420 + }
2421 + }
2422 +#endif
2423 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2424 + }
2425 + break;
2426 + }
2427 + else {
2428 + ret = -EFAULT;
2429 + }
2430 + break;
2431 +
2432 + case BOARD_IOCTL_GET_TRIGGER_EVENT:
2433 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2434 + BOARD_IOC *board_ioc = (BOARD_IOC *)flip->private_data;
2435 + if (ctrlParms.strLen == sizeof(unsigned long)) {
2436 + __copy_to_user(ctrlParms.string, &board_ioc->eventmask, sizeof(unsigned long));
2437 + ctrlParms.result = 0;
2438 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2439 + ret = 0;
2440 + } else
2441 + ret = -EFAULT;
2442 +
2443 + break;
2444 + }
2445 + else {
2446 + ret = -EFAULT;
2447 + }
2448 + break;
2449 +
2450 + case BOARD_IOCTL_UNSET_TRIGGER_EVENT:
2451 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2452 + if (ctrlParms.strLen == sizeof(unsigned long)) {
2453 + BOARD_IOC *board_ioc = (BOARD_IOC *)flip->private_data;
2454 + board_ioc->eventmask &= (~(*((int*)ctrlParms.string)));
2455 + ctrlParms.result = 0;
2456 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2457 + ret = 0;
2458 + } else
2459 + ret = -EFAULT;
2460 +
2461 + break;
2462 + }
2463 + else {
2464 + ret = -EFAULT;
2465 + }
2466 + break;
2467 +#if defined (WIRELESS)
2468 + case BOARD_IOCTL_SET_SES_LED:
2469 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2470 + if (ctrlParms.strLen == sizeof(int)) {
2471 + sesLed_ctrl(*(int*)ctrlParms.string);
2472 + ctrlParms.result = 0;
2473 + __copy_to_user((BOARD_IOCTL_PARMS*)arg, &ctrlParms, sizeof(BOARD_IOCTL_PARMS));
2474 + ret = 0;
2475 + } else
2476 + ret = -EFAULT;
2477 +
2478 + break;
2479 + }
2480 + else {
2481 + ret = -EFAULT;
2482 + }
2483 + break;
2484 +#endif
2485 +
2486 + case BOARD_IOCTL_SET_MONITOR_FD:
2487 + if (copy_from_user((void*)&ctrlParms, (void*)arg, sizeof(ctrlParms)) == 0) {
2488 + int fput_needed = 0;
2489 +
2490 + g_monitor_file = fget_light( ctrlParms.offset, &fput_needed );
2491 + if( g_monitor_file ) {
2492 + /* Hook this file descriptor's poll function in order to set
2493 + * the exception descriptor when there is a change in link
2494 + * state.
2495 + */
2496 + g_monitor_task = current;
2497 + g_orig_fop_poll = g_monitor_file->f_op->poll;
2498 + g_monitor_file->f_op->poll = kerSysMonitorPollHook;
2499 + }
2500 + }
2501 + break;
2502 +
2503 + case BOARD_IOCTL_WAKEUP_MONITOR_TASK:
2504 + kerSysWakeupMonitorTask();
2505 + break;
2506 +
2507 + default:
2508 + ret = -EINVAL;
2509 + ctrlParms.result = 0;
2510 + printk("board_ioctl: invalid command %x, cmd %d .\n",command,_IOC_NR(command));
2511 + break;
2512 +
2513 + } /* switch */
2514 +
2515 + return (ret);
2516 +
2517 +} /* board_ioctl */
2518 +
2519 +/***************************************************************************
2520 + * SES Button ISR/GPIO/LED functions.
2521 + ***************************************************************************/
2522 +#if defined (WIRELESS)
2523 +static irqreturn_t sesBtn_isr(int irq, void *dev_id, struct pt_regs *ptregs)
2524 +{
2525 +#if defined(_BCM96338_) || defined(CONFIG_BCM96338)
2526 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2527 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2528 +#endif
2529 +#if defined(_BCM96345_) || defined(CONFIG_BCM96345)
2530 + unsigned short gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2531 + volatile unsigned short *gpio_reg = &GPIO->GPIOio;
2532 +#endif
2533 +#if defined(_BCM96348_) || defined (CONFIG_BCM96348)
2534 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2535 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2536 +
2537 + if( (sesBtn_gpio & ~BP_ACTIVE_MASK) >= 32 )
2538 + {
2539 + gpio_mask = GPIO_NUM_TO_MASK_HIGH(sesBtn_gpio);
2540 + gpio_reg = &GPIO->GPIOio_high;
2541 + }
2542 +#endif
2543 +
2544 + if (!(*gpio_reg & gpio_mask)){
2545 + wake_up_interruptible(&g_board_wait_queue);
2546 + return IRQ_RETVAL(1);
2547 + } else {
2548 + return IRQ_RETVAL(0);
2549 + }
2550 +}
2551 +
2552 +static void __init sesBtn_mapGpio()
2553 +{
2554 + if( BpGetWirelessSesBtnGpio(&sesBtn_gpio) == BP_SUCCESS )
2555 + {
2556 + printk("SES: Button GPIO 0x%x is enabled\n", sesBtn_gpio);
2557 + }
2558 +}
2559 +
2560 +static void __init sesBtn_mapIntr(int context)
2561 +{
2562 + if( BpGetWirelessSesExtIntr(&sesBtn_irq) == BP_SUCCESS )
2563 + {
2564 + printk("SES: Button Interrupt 0x%x is enabled\n", sesBtn_irq);
2565 + }
2566 + else
2567 + return;
2568 +
2569 + sesBtn_irq += INTERRUPT_ID_EXTERNAL_0;
2570 +
2571 + if (BcmHalMapInterrupt((FN_HANDLER)sesBtn_isr, context, sesBtn_irq)) {
2572 + printk("SES: Interrupt mapping failed\n");
2573 + }
2574 + BcmHalInterruptEnable(sesBtn_irq);
2575 +}
2576 +
2577 +
2578 +static unsigned int sesBtn_poll(struct file *file, struct poll_table_struct *wait)
2579 +{
2580 +#if defined(_BCM96338_) || defined(CONFIG_BCM96338)
2581 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2582 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2583 +#endif
2584 +#if defined(_BCM96345_) || defined(CONFIG_BCM96345)
2585 + unsigned short gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2586 + volatile unsigned short *gpio_reg = &GPIO->GPIOio;
2587 +#endif
2588 +#if defined(_BCM96348_) || defined (CONFIG_BCM96348)
2589 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2590 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2591 +
2592 + if( (sesBtn_gpio & ~BP_ACTIVE_MASK) >= 32 )
2593 + {
2594 + gpio_mask = GPIO_NUM_TO_MASK_HIGH(sesBtn_gpio);
2595 + gpio_reg = &GPIO->GPIOio_high;
2596 + }
2597 +#endif
2598 +
2599 + if (!(*gpio_reg & gpio_mask)){
2600 + return POLLIN;
2601 + }
2602 + return 0;
2603 +}
2604 +
2605 +static ssize_t sesBtn_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2606 +{
2607 + volatile unsigned int event=0;
2608 + ssize_t ret=0;
2609 +
2610 +#if defined(_BCM96338_) || defined (CONFIG_BCM96338)
2611 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2612 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2613 +#endif
2614 +#if defined(_BCM96345_) || defined (CONFIG_BCM96345)
2615 + unsigned short gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2616 + volatile unsigned short *gpio_reg = &GPIO->GPIOio;
2617 +#endif
2618 +#if defined(_BCM96348_) || defined (CONFIG_BCM96348)
2619 + unsigned long gpio_mask = GPIO_NUM_TO_MASK(sesBtn_gpio);
2620 + volatile unsigned long *gpio_reg = &GPIO->GPIOio;
2621 +
2622 + if( (sesBtn_gpio & ~BP_ACTIVE_MASK) >= 32 )
2623 + {
2624 + gpio_mask = GPIO_NUM_TO_MASK_HIGH(sesBtn_gpio);
2625 + gpio_reg = &GPIO->GPIOio_high;
2626 + }
2627 +#endif
2628 +
2629 + if(*gpio_reg & gpio_mask){
2630 + BcmHalInterruptEnable(sesBtn_irq);
2631 + return ret;
2632 + }
2633 + event = SES_EVENTS;
2634 + __copy_to_user((char*)buffer, (char*)&event, sizeof(event));
2635 + BcmHalInterruptEnable(sesBtn_irq);
2636 + count -= sizeof(event);
2637 + buffer += sizeof(event);
2638 + ret += sizeof(event);
2639 + return ret;
2640 +}
2641 +
2642 +static void __init sesLed_mapGpio()
2643 +{
2644 + if( BpGetWirelessSesBtnGpio(&sesLed_gpio) == BP_SUCCESS )
2645 + {
2646 + printk("SES: LED GPIO 0x%x is enabled\n", sesBtn_gpio);
2647 + }
2648 +}
2649 +
2650 +static void sesLed_ctrl(int action)
2651 +{
2652 +
2653 + //char status = ((action >> 8) & 0xff); /* extract status */
2654 + //char event = ((action >> 16) & 0xff); /* extract event */
2655 + //char blinktype = ((action >> 24) & 0xff); /* extract blink type for SES_LED_BLINK */
2656 +
2657 + BOARD_LED_STATE led;
2658 +
2659 + if(sesLed_gpio == BP_NOT_DEFINED)
2660 + return;
2661 +
2662 + action &= 0xff; /* extract led */
2663 +
2664 + //printk("blinktype=%d, event=%d, status=%d\n",(int)blinktype, (int)event, (int)status);
2665 +
2666 + switch (action)
2667 + {
2668 + case SES_LED_ON:
2669 + //printk("SES: led on\n");
2670 + led = kLedStateOn;
2671 + break;
2672 + case SES_LED_BLINK:
2673 + //printk("SES: led blink\n");
2674 + led = kLedStateSlowBlinkContinues;
2675 + break;
2676 + case SES_LED_OFF:
2677 + default:
2678 + //printk("SES: led off\n");
2679 + led = kLedStateOff;
2680 + }
2681 +
2682 + kerSysLedCtrl(kLedSes, led);
2683 +}
2684 +
2685 +static void __init ses_board_init()
2686 +{
2687 + sesBtn_mapGpio();
2688 + sesBtn_mapIntr(0);
2689 + sesLed_mapGpio();
2690 +}
2691 +static void __exit ses_board_deinit()
2692 +{
2693 + if(sesBtn_irq)
2694 + BcmHalInterruptDisable(sesBtn_irq);
2695 +}
2696 +#endif
2697 +
2698 +/***************************************************************************
2699 + * Dying gasp ISR and functions.
2700 + ***************************************************************************/
2701 +#define KERSYS_DBG printk
2702 +
2703 +#if defined(CONFIG_BCM96345)
2704 +#define CYCLE_PER_US 70
2705 +#elif defined(CONFIG_BCM96348) || defined(CONFIG_BCM96338)
2706 +/* The BCM6348 cycles per microsecond is really variable since the BCM6348
2707 + * MIPS speed can vary depending on the PLL settings. However, an appoximate
2708 + * value of 120 will still work OK for the test being done.
2709 + */
2710 +#define CYCLE_PER_US 120
2711 +#endif
2712 +#define DG_GLITCH_TO (100*CYCLE_PER_US)
2713 +
2714 +static void __init kerSysDyingGaspMapIntr()
2715 +{
2716 + unsigned long ulIntr;
2717 +
2718 +#if defined(CONFIG_BCM96348) || defined(_BCM96348_) || defined(CONFIG_BCM96338) || defined(_BCM96338_)
2719 + if( BpGetAdslDyingGaspExtIntr( &ulIntr ) == BP_SUCCESS ) {
2720 + BcmHalMapInterrupt((FN_HANDLER)kerSysDyingGaspIsr, 0, INTERRUPT_ID_DG);
2721 + BcmHalInterruptEnable( INTERRUPT_ID_DG );
2722 + }
2723 +#elif defined(CONFIG_BCM96345) || defined(_BCM96345_)
2724 + if( BpGetAdslDyingGaspExtIntr( &ulIntr ) == BP_SUCCESS ) {
2725 + ulIntr += INTERRUPT_ID_EXTERNAL_0;
2726 + BcmHalMapInterrupt((FN_HANDLER)kerSysDyingGaspIsr, 0, ulIntr);
2727 + BcmHalInterruptEnable( ulIntr );
2728 + }
2729 +#endif
2730 +
2731 +}
2732 +
2733 +void kerSysSetWdTimer(ulong timeUs)
2734 +{
2735 + TIMER->WatchDogDefCount = timeUs * (FPERIPH/1000000);
2736 + TIMER->WatchDogCtl = 0xFF00;
2737 + TIMER->WatchDogCtl = 0x00FF;
2738 +}
2739 +
2740 +ulong kerSysGetCycleCount(void)
2741 +{
2742 + ulong cnt;
2743 +#ifdef _WIN32_WCE
2744 + cnt = 0;
2745 +#else
2746 + __asm volatile("mfc0 %0, $9":"=d"(cnt));
2747 +#endif
2748 + return(cnt);
2749 +}
2750 +
2751 +static Bool kerSysDyingGaspCheckPowerLoss(void)
2752 +{
2753 + ulong clk0;
2754 + ulong ulIntr;
2755 +
2756 + ulIntr = 0;
2757 + clk0 = kerSysGetCycleCount();
2758 +
2759 + UART->Data = 'D';
2760 + UART->Data = '%';
2761 + UART->Data = 'G';
2762 +
2763 +#if defined(CONFIG_BCM96345)
2764 + BpGetAdslDyingGaspExtIntr( &ulIntr );
2765 +
2766 + do {
2767 + ulong clk1;
2768 +
2769 + clk1 = kerSysGetCycleCount(); /* time cleared */
2770 + /* wait a little to get new reading */
2771 + while ((kerSysGetCycleCount()-clk1) < CYCLE_PER_US*2)
2772 + ;
2773 + } while ((0 == (PERF->ExtIrqCfg & (1 << (ulIntr + EI_STATUS_SHFT)))) && ((kerSysGetCycleCount() - clk0) < DG_GLITCH_TO));
2774 +
2775 + if (PERF->ExtIrqCfg & (1 << (ulIntr + EI_STATUS_SHFT))) { /* power glitch */
2776 + BcmHalInterruptEnable( ulIntr + INTERRUPT_ID_EXTERNAL_0);
2777 + KERSYS_DBG(" - Power glitch detected. Duration: %ld us\n", (kerSysGetCycleCount() - clk0)/CYCLE_PER_US);
2778 + return 0;
2779 + }
2780 +#elif (defined(CONFIG_BCM96348) || defined(CONFIG_BCM96338)) && !defined(VXWORKS)
2781 + do {
2782 + ulong clk1;
2783 +
2784 + clk1 = kerSysGetCycleCount(); /* time cleared */
2785 + /* wait a little to get new reading */
2786 + while ((kerSysGetCycleCount()-clk1) < CYCLE_PER_US*2)
2787 + ;
2788 + } while ((PERF->IrqStatus & (1 << (INTERRUPT_ID_DG - INTERNAL_ISR_TABLE_OFFSET))) && ((kerSysGetCycleCount() - clk0) < DG_GLITCH_TO));
2789 +
2790 + if (!(PERF->IrqStatus & (1 << (INTERRUPT_ID_DG - INTERNAL_ISR_TABLE_OFFSET)))) {
2791 + BcmHalInterruptEnable( INTERRUPT_ID_DG );
2792 + KERSYS_DBG(" - Power glitch detected. Duration: %ld us\n", (kerSysGetCycleCount() - clk0)/CYCLE_PER_US);
2793 + return 0;
2794 + }
2795 +#endif
2796 + return 1;
2797 +}
2798 +
2799 +static void kerSysDyingGaspShutdown( void )
2800 +{
2801 + kerSysSetWdTimer(1000000);
2802 +#if defined(CONFIG_BCM96345)
2803 + PERF->blkEnables &= ~(EMAC_CLK_EN | USB_CLK_EN | CPU_CLK_EN);
2804 +#elif defined(CONFIG_BCM96348)
2805 + PERF->blkEnables &= ~(EMAC_CLK_EN | USBS_CLK_EN | USBH_CLK_EN | SAR_CLK_EN);
2806 +#endif
2807 +}
2808 +
2809 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
2810 +static irqreturn_t kerSysDyingGaspIsr(int irq, void * dev_id, struct pt_regs * regs)
2811 +#else
2812 +static unsigned int kerSysDyingGaspIsr(void)
2813 +#endif
2814 +{
2815 + struct list_head *pos;
2816 + CB_DGASP_LIST *tmp, *dsl = NULL;
2817 +
2818 + if (kerSysDyingGaspCheckPowerLoss()) {
2819 +
2820 + /* first to turn off everything other than dsl */
2821 + list_for_each(pos, &g_cb_dgasp_list_head->list) {
2822 + tmp = list_entry(pos, CB_DGASP_LIST, list);
2823 + if(strncmp(tmp->name, "dsl", 3)) {
2824 + (tmp->cb_dgasp_fn)(tmp->context);
2825 + }else {
2826 + dsl = tmp;
2827 + }
2828 + }
2829 +
2830 + /* now send dgasp */
2831 + if(dsl)
2832 + (dsl->cb_dgasp_fn)(dsl->context);
2833 +
2834 + /* reset and shutdown system */
2835 + kerSysDyingGaspShutdown();
2836 + }
2837 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
2838 +return( IRQ_HANDLED );
2839 +#else
2840 + return( 1 );
2841 +#endif
2842 +}
2843 +
2844 +static void __init kerSysInitDyingGaspHandler( void )
2845 +{
2846 + CB_DGASP_LIST *new_node;
2847 +
2848 + if( g_cb_dgasp_list_head != NULL) {
2849 + printk("Error: kerSysInitDyingGaspHandler: list head is not null\n");
2850 + return;
2851 + }
2852 + new_node= (CB_DGASP_LIST *)kmalloc(sizeof(CB_DGASP_LIST), GFP_KERNEL);
2853 + memset(new_node, 0x00, sizeof(CB_DGASP_LIST));
2854 + INIT_LIST_HEAD(&new_node->list);
2855 + g_cb_dgasp_list_head = new_node;
2856 +
2857 +} /* kerSysInitDyingGaspHandler */
2858 +
2859 +static void __exit kerSysDeinitDyingGaspHandler( void )
2860 +{
2861 + struct list_head *pos;
2862 + CB_DGASP_LIST *tmp;
2863 +
2864 + if(g_cb_dgasp_list_head == NULL)
2865 + return;
2866 +
2867 + list_for_each(pos, &g_cb_dgasp_list_head->list) {
2868 + tmp = list_entry(pos, CB_DGASP_LIST, list);
2869 + list_del(pos);
2870 + kfree(tmp);
2871 + }
2872 +
2873 + kfree(g_cb_dgasp_list_head);
2874 + g_cb_dgasp_list_head = NULL;
2875 +
2876 +} /* kerSysDeinitDyingGaspHandler */
2877 +
2878 +void kerSysRegisterDyingGaspHandler(char *devname, void *cbfn, void *context)
2879 +{
2880 + CB_DGASP_LIST *new_node;
2881 +
2882 + if( g_cb_dgasp_list_head == NULL) {
2883 + printk("Error: kerSysRegisterDyingGaspHandler: list head is null\n");
2884 + return;
2885 + }
2886 +
2887 + if( devname == NULL || cbfn == NULL ) {
2888 + printk("Error: kerSysRegisterDyingGaspHandler: register info not enough (%s,%x,%x)\n", devname, (unsigned int)cbfn, (unsigned int)context);
2889 + return;
2890 + }
2891 +
2892 + new_node= (CB_DGASP_LIST *)kmalloc(sizeof(CB_DGASP_LIST), GFP_KERNEL);
2893 + memset(new_node, 0x00, sizeof(CB_DGASP_LIST));
2894 + INIT_LIST_HEAD(&new_node->list);
2895 + strncpy(new_node->name, devname, IFNAMSIZ);
2896 + new_node->cb_dgasp_fn = (cb_dgasp_t)cbfn;
2897 + new_node->context = context;
2898 + list_add(&new_node->list, &g_cb_dgasp_list_head->list);
2899 +
2900 + printk("dgasp: kerSysRegisterDyingGaspHandler: %s registered \n", devname);
2901 +
2902 +} /* kerSysRegisterDyingGaspHandler */
2903 +
2904 +void kerSysDeregisterDyingGaspHandler(char *devname)
2905 +{
2906 + struct list_head *pos;
2907 + CB_DGASP_LIST *tmp;
2908 +
2909 + if(g_cb_dgasp_list_head == NULL) {
2910 + printk("Error: kerSysDeregisterDyingGaspHandler: list head is null\n");
2911 + return;
2912 + }
2913 +
2914 + if(devname == NULL) {
2915 + printk("Error: kerSysDeregisterDyingGaspHandler: devname is null\n");
2916 + return;
2917 + }
2918 +
2919 + printk("kerSysDeregisterDyingGaspHandler: %s is deregistering\n", devname);
2920 +
2921 + list_for_each(pos, &g_cb_dgasp_list_head->list) {
2922 + tmp = list_entry(pos, CB_DGASP_LIST, list);
2923 + if(!strcmp(tmp->name, devname)) {
2924 + list_del(pos);
2925 + kfree(tmp);
2926 + printk("kerSysDeregisterDyingGaspHandler: %s is deregistered\n", devname);
2927 + return;
2928 + }
2929 + }
2930 + printk("kerSysDeregisterDyingGaspHandler: %s not (de)registered\n", devname);
2931 +
2932 +} /* kerSysDeregisterDyingGaspHandler */
2933 +
2934 +/***************************************************************************
2935 + * MACRO to call driver initialization and cleanup functions.
2936 + ***************************************************************************/
2937 +module_init( brcm_board_init );
2938 +module_exit( brcm_board_cleanup );
2939 +
2940 +EXPORT_SYMBOL(kerSysNvRamGet);
2941 +EXPORT_SYMBOL(dumpaddr);
2942 +EXPORT_SYMBOL(kerSysGetMacAddress);
2943 +EXPORT_SYMBOL(kerSysReleaseMacAddress);
2944 +EXPORT_SYMBOL(kerSysGetSdramSize);
2945 +EXPORT_SYMBOL(kerSysLedCtrl);
2946 +//<<JUNHON, 2004/09/15, get reset button status , tim hou , 05/04/12
2947 +EXPORT_SYMBOL(kerSysGetResetHold);
2948 +//>>JUNHON, 2004/09/15
2949 +EXPORT_SYMBOL(kerSysLedRegisterHwHandler);
2950 +EXPORT_SYMBOL(BpGetBoardIds);
2951 +EXPORT_SYMBOL(BpGetSdramSize);
2952 +EXPORT_SYMBOL(BpGetPsiSize);
2953 +EXPORT_SYMBOL(BpGetEthernetMacInfo);
2954 +EXPORT_SYMBOL(BpGetRj11InnerOuterPairGpios);
2955 +EXPORT_SYMBOL(BpGetPressAndHoldResetGpio);
2956 +EXPORT_SYMBOL(BpGetVoipResetGpio);
2957 +EXPORT_SYMBOL(BpGetVoipIntrGpio);
2958 +EXPORT_SYMBOL(BpGetPcmciaResetGpio);
2959 +EXPORT_SYMBOL(BpGetRtsCtsUartGpios);
2960 +EXPORT_SYMBOL(BpGetAdslLedGpio);
2961 +EXPORT_SYMBOL(BpGetAdslFailLedGpio);
2962 +EXPORT_SYMBOL(BpGetWirelessLedGpio);
2963 +EXPORT_SYMBOL(BpGetUsbLedGpio);
2964 +EXPORT_SYMBOL(BpGetHpnaLedGpio);
2965 +EXPORT_SYMBOL(BpGetWanDataLedGpio);
2966 +EXPORT_SYMBOL(BpGetPppLedGpio);
2967 +EXPORT_SYMBOL(BpGetPppFailLedGpio);
2968 +EXPORT_SYMBOL(BpGetVoipLedGpio);
2969 +EXPORT_SYMBOL(BpGetWirelessExtIntr);
2970 +EXPORT_SYMBOL(BpGetAdslDyingGaspExtIntr);
2971 +EXPORT_SYMBOL(BpGetVoipExtIntr);
2972 +EXPORT_SYMBOL(BpGetHpnaExtIntr);
2973 +EXPORT_SYMBOL(BpGetHpnaChipSelect);
2974 +EXPORT_SYMBOL(BpGetVoipChipSelect);
2975 +EXPORT_SYMBOL(BpGetWirelessSesBtnGpio);
2976 +EXPORT_SYMBOL(BpGetWirelessSesExtIntr);
2977 +EXPORT_SYMBOL(BpGetWirelessSesLedGpio);
2978 +EXPORT_SYMBOL(kerSysRegisterDyingGaspHandler);
2979 +EXPORT_SYMBOL(kerSysDeregisterDyingGaspHandler);
2980 +EXPORT_SYMBOL(kerSysGetCycleCount);
2981 +EXPORT_SYMBOL(kerSysSetWdTimer);
2982 +EXPORT_SYMBOL(kerSysWakeupMonitorTask);
2983 +
2984 diff -urN linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/boardparms.c linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/boardparms.c
2985 --- linux-2.6.16.7/arch/mips/brcm-boards/bcm963xx/boardparms.c 1970-01-01 01:00:00.000000000 +0100
2986 +++ linux-2.6.16.7-brcm63xx/arch/mips/brcm-boards/bcm963xx/boardparms.c 2006-07-07 22:16:11.000000000 +0200
2987 @@ -0,0 +1,2391 @@
2988 +/*
2989 +<:copyright-gpl
2990 +
2991 + Copyright 2003 Broadcom Corp. All Rights Reserved.
2992 +
2993 + This program is free software; you can distribute it and/or modify it
2994 + under the terms of the GNU General Public License (Version 2) as
2995 + published by the Free Software Foundation.
2996 +
2997 + This program is distributed in the hope it will be useful, but WITHOUT
2998 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2999 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3000 + for more details.
3001 +
3002 + You should have received a copy of the GNU General Public License along
3003 + with this program; if not, write to the Free Software Foundation, Inc.,
3004 + 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
3005 +
3006 +:>
3007 +*/
3008 +/**************************************************************************
3009 + * File Name : boardparms.c
3010 + *
3011 + * Description: This file contains the implementation for the BCM63xx board
3012 + * parameter access functions.
3013 + *
3014 + * Updates : 07/14/2003 Created.
3015 + ***************************************************************************/
3016 +
3017 +/* Includes. */
3018 +#include "boardparms.h"
3019 +
3020 +/* Defines. */
3021 +
3022 +/* Default psi size in K bytes */
3023 +#define BP_PSI_DEFAULT_SIZE 24
3024 +
3025 +/* Typedefs */
3026 +typedef struct boardparameters
3027 +{
3028 + char szBoardId[BP_BOARD_ID_LEN]; /* board id string */
3029 + ETHERNET_MAC_INFO EnetMacInfos[BP_MAX_ENET_MACS];
3030 + VOIP_DSP_INFO VoIPDspInfo[BP_MAX_VOIP_DSP];
3031 + unsigned short usSdramSize; /* SDRAM size and type */
3032 + unsigned short usPsiSize; /* persistent storage in K bytes */
3033 + unsigned short usGpioRj11InnerPair; /* GPIO pin or not defined */
3034 + unsigned short usGpioRj11OuterPair; /* GPIO pin or not defined */
3035 + unsigned short usGpioPressAndHoldReset; /* GPIO pin or not defined */
3036 + unsigned short usGpioPcmciaReset; /* GPIO pin or not defined */
3037 + unsigned short usGpioUartRts; /* GPIO pin or not defined */
3038 + unsigned short usGpioUartCts; /* GPIO pin or not defined */
3039 + unsigned short usGpioLedAdsl; /* GPIO pin or not defined */
3040 + unsigned short usGpioLedAdslFail; /* GPIO pin or not defined */
3041 + unsigned short usGpioLedWireless; /* GPIO pin or not defined */
3042 + unsigned short usGpioLedUsb; /* GPIO pin or not defined */
3043 + unsigned short usGpioLedHpna; /* GPIO pin or not defined */
3044 + unsigned short usGpioLedWanData; /* GPIO pin or not defined */
3045 + unsigned short usGpioLedPpp; /* GPIO pin or not defined */
3046 + unsigned short usGpioLedPppFail; /* GPIO pin or not defined */
3047 + unsigned short usGpioLedBlPowerOn; /* GPIO pin or not defined */
3048 + unsigned short usGpioLedBlAlarm; /* GPIO pin or not defined */
3049 + unsigned short usGpioLedBlResetCfg; /* GPIO pin or not defined */
3050 + unsigned short usGpioLedBlStop; /* GPIO pin or not defined */
3051 + unsigned short usExtIntrWireless; /* ext intr or not defined */
3052 + unsigned short usExtIntrAdslDyingGasp; /* ext intr or not defined */
3053 + unsigned short usExtIntrHpna; /* ext intr or not defined */
3054 + unsigned short usCsHpna; /* chip select not defined */
3055 + unsigned short usAntInUseWireless; /* antenna in use or not defined */
3056 + unsigned short usGpioSesBtnWireless; /* GPIO pin or not defined */
3057 + unsigned short usExtIntrSesBtnWireless; /* ext intr or not defined */
3058 + unsigned short usGpioLedSesWireless; /* GPIO pin or not defined */
3059 +} BOARD_PARAMETERS, *PBOARD_PARAMETERS;
3060 +
3061 +/* Variables */
3062 +#if defined(_BCM96338_) || defined(CONFIG_BCM96338)
3063 +static BOARD_PARAMETERS g_bcm96338sv =
3064 +{
3065 + "96338SV", /* szBoardId */
3066 + {{BP_ENET_INTERNAL_PHY, /* ucPhyType */
3067 + 0x01, /* ucPhyAddress */
3068 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3069 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3070 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3071 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3072 + BP_NOT_DEFINED, /* usGpioPhyReset */
3073 + 0x01, /* numSwitchPorts */
3074 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3075 + BP_NOT_DEFINED}, /* usReverseMii */
3076 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3077 + {{BP_VOIP_NO_DSP}, /* ucDspType */
3078 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3079 + BP_MEMORY_16MB_1_CHIP, /* usSdramSize */
3080 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3081 + BP_NOT_DEFINED, /* usGpioRj11InnerPair */
3082 + BP_NOT_DEFINED, /* usGpioRj11OuterPair */
3083 + BP_NOT_DEFINED, /* usGpioPressAndHoldReset */
3084 + BP_NOT_DEFINED, /* usGpioPcmciaReset */
3085 + BP_NOT_DEFINED, /* usGpioUartRts */
3086 + BP_NOT_DEFINED, /* usGpioUartCts */
3087 + BP_NOT_DEFINED, /* usGpioLedAdsl */
3088 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3089 + BP_NOT_DEFINED, /* usGpioLedWireless */
3090 + BP_NOT_DEFINED, /* usGpioLedUsb */
3091 + BP_NOT_DEFINED, /* usGpioLedHpna */
3092 + BP_NOT_DEFINED, /* usGpioLedWanData */
3093 + BP_NOT_DEFINED, /* usGpioLedPpp */
3094 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3095 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3096 + BP_NOT_DEFINED, /* usGpioLedBlAlarm */
3097 + BP_NOT_DEFINED, /* usGpioLedBlResetCfg */
3098 + BP_NOT_DEFINED, /* usGpioLedBlStop */
3099 + BP_NOT_DEFINED, /* usExtIntrWireless */
3100 + BP_HW_DEFINED, /* usExtIntrAdslDyingGasp */
3101 + BP_NOT_DEFINED, /* usExtIntrHpna */
3102 + BP_NOT_DEFINED, /* usCsHpna */
3103 + BP_NOT_DEFINED, /* usAntInUseWireless */
3104 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3105 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3106 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3107 +};
3108 +static BOARD_PARAMETERS g_bcm96338l2m8m =
3109 +{
3110 + "96338L-2M-8M", /* szBoardId */
3111 + {{BP_ENET_INTERNAL_PHY, /* ucPhyType */
3112 + 0x01, /* ucPhyAddress */
3113 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3114 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3115 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3116 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3117 + BP_NOT_DEFINED, /* usGpioPhyReset */
3118 + 0x01, /* numSwitchPorts */
3119 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3120 + BP_NOT_DEFINED}, /* usReverseMii */
3121 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3122 + {{BP_VOIP_NO_DSP}, /* ucDspType */
3123 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3124 + BP_MEMORY_8MB_1_CHIP, /* usSdramSize */
3125 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3126 + BP_NOT_DEFINED, /* usGpioRj11InnerPair */
3127 + BP_NOT_DEFINED, /* usGpioRj11OuterPair */
3128 + BP_NOT_DEFINED, /* usGpioPressAndHoldReset */
3129 + BP_NOT_DEFINED, /* usGpioPcmciaReset */
3130 + BP_NOT_DEFINED, /* usGpioUartRts */
3131 + BP_NOT_DEFINED, /* usGpioUartCts */
3132 + BP_NOT_DEFINED, /* usGpioLedAdsl */
3133 + BP_GPIO_2_AL, /* usGpioLedAdslFail */
3134 + BP_NOT_DEFINED, /* usGpioLedWireless */
3135 + BP_NOT_DEFINED, /* usGpioLedUsb */
3136 + BP_NOT_DEFINED, /* usGpioLedHpna */
3137 + BP_GPIO_3_AL, /* usGpioLedWanData */
3138 + BP_GPIO_3_AL, /* usGpioLedPpp */
3139 + BP_GPIO_4_AL, /* usGpioLedPppFail */
3140 + BP_GPIO_0_AL, /* usGpioLedBlPowerOn */
3141 + BP_NOT_DEFINED, /* usGpioLedBlAlarm */
3142 + BP_GPIO_3_AL, /* usGpioLedBlResetCfg */
3143 + BP_GPIO_1_AL, /* usGpioLedBlStop */
3144 + BP_NOT_DEFINED, /* usExtIntrWireless */
3145 + BP_HW_DEFINED, /* usExtIntrAdslDyingGasp */
3146 + BP_NOT_DEFINED, /* usExtIntrHpna */
3147 + BP_NOT_DEFINED, /* usCsHpna */
3148 + BP_NOT_DEFINED, /* usAntInUseWireless */
3149 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3150 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3151 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3152 +};
3153 +static PBOARD_PARAMETERS g_BoardParms[] =
3154 + {&g_bcm96338sv, &g_bcm96338l2m8m, 0};
3155 +#endif
3156 +
3157 +#if defined(_BCM96345_) || defined(CONFIG_BCM96345)
3158 +static BOARD_PARAMETERS g_bcm96345r =
3159 +{
3160 + "96345R", /* szBoardId */
3161 + {{BP_ENET_INTERNAL_PHY, /* ucPhyType */
3162 + 0x01, /* ucPhyAddress */
3163 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3164 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3165 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3166 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3167 + BP_NOT_DEFINED, /* usGpioPhyReset */
3168 + 0x01, /* numSwitchPorts */
3169 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3170 + BP_NOT_DEFINED}, /* usReverseMii */
3171 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3172 + {{BP_VOIP_NO_DSP}, /* ucDspType */
3173 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3174 + BP_MEMORY_8MB_1_CHIP, /* usSdramSize */
3175 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3176 + BP_GPIO_11_AH, /* usGpioRj11InnerPair */
3177 + BP_GPIO_12_AH, /* usGpioRj11OuterPair */
3178 + BP_GPIO_13_AH, /* usGpioPressAndHoldReset */
3179 + BP_NOT_DEFINED, /* usGpioPcmciaReset */
3180 + BP_NOT_DEFINED, /* usGpioUartRts */
3181 + BP_NOT_DEFINED, /* usGpioUartCts */
3182 + BP_GPIO_8_AH, /* usGpioLedAdsl */
3183 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3184 + BP_NOT_DEFINED, /* usGpioLedWireless */
3185 + BP_NOT_DEFINED, /* usGpioLedUsb */
3186 + BP_NOT_DEFINED, /* usGpioLedHpna */
3187 + BP_GPIO_8_AH, /* usGpioLedWanData */
3188 + BP_GPIO_9_AH, /* usGpioLedPpp */
3189 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3190 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3191 + BP_GPIO_10_AH, /* usGpioLedBlAlarm */
3192 + BP_GPIO_9_AH, /* usGpioLedBlResetCfg */
3193 + BP_GPIO_8_AH, /* usGpioLedBlStop */
3194 + BP_NOT_DEFINED, /* usExtIntrWireless */
3195 + BP_EXT_INTR_0, /* usExtIntrAdslDyingGasp */
3196 + BP_NOT_DEFINED, /* usExtIntrHpna */
3197 + BP_NOT_DEFINED, /* usCsHpna */
3198 + BP_NOT_DEFINED, /* usAntInUseWireless */
3199 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3200 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3201 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3202 +};
3203 +
3204 +static BOARD_PARAMETERS g_bcm96345gw2 =
3205 +{
3206 + /* A hardware jumper determines whether GPIO 13 is used for Press and Hold
3207 + * Reset or RTS.
3208 + */
3209 + "96345GW2", /* szBoardId */
3210 + {{BP_ENET_EXTERNAL_SWITCH, /* ucPhyType */
3211 + 0x00, /* ucPhyAddress */
3212 + BP_GPIO_0_AH, /* usGpioPhySpiSck */
3213 + BP_GPIO_4_AH, /* usGpioPhySpiSs */
3214 + BP_GPIO_12_AH, /* usGpioPhySpiMosi */
3215 + BP_GPIO_11_AH, /* usGpioPhySpiMiso */
3216 + BP_NOT_DEFINED, /* usGpioPhyReset */
3217 + 0x04, /* numSwitchPorts */
3218 + BP_ENET_CONFIG_GPIO, /* usConfigType */
3219 + BP_ENET_REVERSE_MII}, /* usReverseMii */
3220 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3221 + {{BP_VOIP_DSP, /* ucDspType */
3222 + 0x00, /* ucDspAddress */
3223 + BP_EXT_INTR_1, /* usExtIntrVoip */
3224 + BP_GPIO_6_AH, /* usGpioVoipReset */
3225 + BP_GPIO_15_AH, /* usGpioVoipIntr */
3226 + BP_NOT_DEFINED, /* usGpioLedVoip */
3227 + BP_CS_2}, /* usCsVoip */
3228 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3229 + BP_MEMORY_16MB_1_CHIP, /* usSdramSize */
3230 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3231 + BP_NOT_DEFINED, /* usGpioRj11InnerPair */
3232 + BP_NOT_DEFINED, /* usGpioRj11OuterPair */
3233 + BP_GPIO_13_AH, /* usGpioPressAndHoldReset */
3234 + BP_GPIO_2_AH, /* usGpioPcmciaReset */
3235 + BP_GPIO_13_AH, /* usGpioUartRts */
3236 + BP_GPIO_9_AH, /* usGpioUartCts */
3237 + BP_GPIO_8_AH, /* usGpioLedAdsl */
3238 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3239 + BP_NOT_DEFINED, /* usGpioLedWireless */
3240 + BP_GPIO_7_AH, /* usGpioLedUsb */
3241 + BP_NOT_DEFINED, /* usGpioLedHpna */
3242 + BP_GPIO_8_AH, /* usGpioLedWanData */
3243 + BP_NOT_DEFINED, /* usGpioLedPpp */
3244 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3245 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3246 + BP_GPIO_10_AH, /* usGpioLedBlAlarm */
3247 + BP_GPIO_7_AH, /* usGpioLedBlResetCfg */
3248 + BP_GPIO_8_AH, /* usGpioLedBlStop */
3249 + BP_EXT_INTR_2, /* usExtIntrWireless */
3250 + BP_EXT_INTR_0, /* usExtIntrAdslDyingGasp */
3251 + BP_NOT_DEFINED, /* usExtIntrHpna */
3252 + BP_NOT_DEFINED, /* usCsHpna */
3253 + BP_WLAN_ANT_MAIN, /* usAntInUseWireless */
3254 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3255 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3256 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3257 +};
3258 +
3259 +static BOARD_PARAMETERS g_bcm96345gw =
3260 +{
3261 + "96345GW", /* szBoardId */
3262 + {{BP_ENET_EXTERNAL_SWITCH, /* ucPhyType */
3263 + 0x00, /* ucPhyAddress */
3264 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3265 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3266 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3267 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3268 + BP_NOT_DEFINED, /* usGpioPhyReset */
3269 + 0x04, /* numSwitchPorts */
3270 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3271 + BP_ENET_NO_REVERSE_MII}, /* usReverseMii */
3272 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3273 + {{BP_VOIP_DSP, /* ucDspType */
3274 + 0x00, /* ucDspAddress */
3275 + BP_EXT_INTR_1, /* usExtIntrVoip */
3276 + BP_GPIO_6_AH, /* usGpioVoipReset */
3277 + BP_GPIO_15_AH, /* usGpioVoipIntr */
3278 + BP_NOT_DEFINED, /* usGpioLedVoip */
3279 + BP_CS_2}, /* usCsVoip */
3280 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3281 + BP_MEMORY_16MB_1_CHIP, /* usSdramSize */
3282 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3283 + BP_GPIO_11_AH, /* usGpioRj11InnerPair */
3284 + BP_GPIO_1_AH, /* usGpioRj11OuterPair */
3285 + BP_GPIO_13_AH, /* usGpioPressAndHoldReset */
3286 + BP_GPIO_2_AH, /* usGpioPcmciaReset */
3287 + BP_NOT_DEFINED, /* usGpioUartRts */
3288 + BP_NOT_DEFINED, /* usGpioUartCts */
3289 + BP_GPIO_8_AH, /* usGpioLedAdsl */
3290 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3291 + BP_GPIO_10_AH, /* usGpioLedWireless */
3292 + BP_GPIO_7_AH, /* usGpioLedUsb */
3293 + BP_NOT_DEFINED, /* usGpioLedHpna */
3294 + BP_GPIO_8_AH, /* usGpioLedWanData */
3295 + BP_NOT_DEFINED, /* usGpioLedPpp */
3296 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3297 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3298 + BP_GPIO_9_AH, /* usGpioLedBlAlarm */
3299 + BP_GPIO_10_AH, /* usGpioLedBlResetCfg */
3300 + BP_GPIO_8_AH, /* usGpioLedBlStop */
3301 + BP_EXT_INTR_2, /* usExtIntrWireless */
3302 + BP_EXT_INTR_0, /* usExtIntrAdslDyingGasp */
3303 + BP_EXT_INTR_3, /* usExtIntrHpna */
3304 + BP_CS_1, /* usCsHpna */
3305 + BP_WLAN_ANT_MAIN, /* usAntInUseWireless */
3306 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3307 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3308 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3309 +};
3310 +
3311 +static BOARD_PARAMETERS g_bcm96335r =
3312 +{
3313 + "96335R", /* szBoardId */
3314 + {{BP_ENET_INTERNAL_PHY, /* ucPhyType */
3315 + 0x01, /* ucPhyAddress */
3316 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3317 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3318 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3319 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3320 + BP_NOT_DEFINED, /* usGpioPhyReset */
3321 + 0x01, /* numSwitchPorts */
3322 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3323 + BP_NOT_DEFINED}, /* usReverseMii */
3324 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3325 + {{BP_VOIP_NO_DSP}, /* ucDspType */
3326 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3327 + BP_MEMORY_8MB_1_CHIP, /* usSdramSize */
3328 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3329 + BP_NOT_DEFINED, /* usGpioRj11InnerPair */
3330 + BP_NOT_DEFINED, /* usGpioRj11OuterPair */
3331 + BP_GPIO_14_AH, /* usGpioPressAndHoldReset */
3332 + BP_NOT_DEFINED, /* usGpioPcmciaReset */
3333 + BP_NOT_DEFINED, /* usGpioUartRts */
3334 + BP_NOT_DEFINED, /* usGpioUartCts */
3335 + BP_GPIO_9_AH, /* usGpioLedAdsl */
3336 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3337 + BP_NOT_DEFINED, /* usGpioLedWireless */
3338 + BP_NOT_DEFINED, /* usGpioLedUsb */
3339 + BP_NOT_DEFINED, /* usGpioLedHpna */
3340 + BP_GPIO_9_AH, /* usGpioLedWanData */
3341 + BP_GPIO_8_AH, /* usGpioLedPpp */
3342 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3343 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3344 + BP_GPIO_10_AH, /* usGpioLedBlAlarm */
3345 + BP_GPIO_8_AH, /* usGpioLedBlResetCfg */
3346 + BP_GPIO_9_AH, /* usGpioLedBlStop */
3347 + BP_NOT_DEFINED, /* usExtIntrWireless */
3348 + BP_NOT_DEFINED, /* usExtIntrAdslDyingGasp */
3349 + BP_NOT_DEFINED, /* usExtIntrHpna */
3350 + BP_NOT_DEFINED, /* usCsHpna */
3351 + BP_NOT_DEFINED, /* usAntInUseWireless */
3352 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3353 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */
3354 + BP_NOT_DEFINED /* usGpioLedSesWireless */
3355 +};
3356 +
3357 +static BOARD_PARAMETERS g_bcm96345r0 =
3358 +{
3359 + "96345R0", /* szBoardId */
3360 + {{BP_ENET_INTERNAL_PHY, /* ucPhyType */
3361 + 0x01, /* ucPhyAddress */
3362 + BP_NOT_DEFINED, /* usGpioPhySpiSck */
3363 + BP_NOT_DEFINED, /* usGpioPhySpiSs */
3364 + BP_NOT_DEFINED, /* usGpioPhySpiMosi */
3365 + BP_NOT_DEFINED, /* usGpioPhySpiMiso */
3366 + BP_NOT_DEFINED, /* usGpioPhyReset */
3367 + 0x01, /* numSwitchPorts */
3368 + BP_ENET_CONFIG_MDIO, /* usConfigType */
3369 + BP_NOT_DEFINED}, /* usReverseMii */
3370 + {BP_ENET_NO_PHY}}, /* ucPhyType */
3371 + {{BP_VOIP_NO_DSP}, /* ucDspType */
3372 + {BP_VOIP_NO_DSP}}, /* ucDspType */
3373 + BP_MEMORY_8MB_1_CHIP, /* usSdramSize */
3374 + BP_PSI_DEFAULT_SIZE, /* usPsiSize */
3375 + BP_NOT_DEFINED, /* usGpioRj11InnerPair */
3376 + BP_NOT_DEFINED, /* usGpioRj11OuterPair */
3377 + BP_NOT_DEFINED, /* usGpioPressAndHoldReset */
3378 + BP_NOT_DEFINED, /* usGpioPcmciaReset */
3379 + BP_NOT_DEFINED, /* usGpioUartRts */
3380 + BP_NOT_DEFINED, /* usGpioUartCts */
3381 + BP_GPIO_8_AH, /* usGpioLedAdsl */
3382 + BP_NOT_DEFINED, /* usGpioLedAdslFail */
3383 + BP_NOT_DEFINED, /* usGpioLedWireless */
3384 + BP_NOT_DEFINED, /* usGpioLedUsb */
3385 + BP_NOT_DEFINED, /* usGpioLedHpna */
3386 + BP_GPIO_9_AH, /* usGpioLedWanData */
3387 + BP_GPIO_9_AH, /* usGpioLedPpp */
3388 + BP_NOT_DEFINED, /* usGpioLedPppFail */
3389 + BP_NOT_DEFINED, /* usGpioLedBlPowerOn */
3390 + BP_GPIO_9_AH, /* usGpioLedBlAlarm */
3391 + BP_GPIO_8_AH, /* usGpioLedBlResetCfg */
3392 + BP_GPIO_8_AH, /* usGpioLedBlStop */
3393 + BP_NOT_DEFINED, /* usExtIntrWireless */
3394 + BP_NOT_DEFINED, /* usExtIntrAdslDyingGasp */
3395 + BP_NOT_DEFINED, /* usExtIntrHpna */
3396 + BP_NOT_DEFINED, /* usCsHpna */
3397 + BP_NOT_DEFINED, /* usAntInUseWireless */
3398 + BP_NOT_DEFINED, /* usGpioSesBtnWireless */
3399 + BP_NOT_DEFINED, /* usExtIntrSesBtnWireless */