This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
board.c
executable file
·6740 lines (5919 loc) · 210 KB
/
board.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
<:copyright-BRCM:2002:GPL/GPL:standard
Copyright (c) 2002 Broadcom Corporation
All Rights Reserved
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as published by
the Free Software Foundation (the "GPL").
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GPL is available at http://www.broadcom.com/licenses/GPLv2.php, or by
writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
:>
*/
/***************************************************************************
* File Name : board.c
*
* Description: This file contains Linux character device driver entry
* for the board related ioctl calls: flash, get free kernel
* page and dump kernel memory, etc.
*
*
***************************************************************************/
/* Includes. */
#include <linux/version.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/capability.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/pagemap.h>
#include <asm/uaccess.h>
#include <linux/wait.h>
#include <linux/poll.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/if.h>
#include <linux/pci.h>
#include <linux/ctype.h>
#include <linux/proc_fs.h>
#include <linux/smp.h>
#include <linux/version.h>
#include <linux/reboot.h>
#include <linux/bcm_assert_locks.h>
#include <asm/delay.h>
#include <linux/fcntl.h>
#include <linux/syscalls.h>
#include <linux/fs.h>
#include <bcmnetlink.h>
#include <net/sock.h>
#include <bcm_map_part.h>
#include <board.h>
#include <spidevices.h>
#define BCMTAG_EXE_USE
#include <bcmTag.h>
#include <boardparms.h>
#include <boardparms_voice.h>
#include <flash_api.h>
#include <bcm_intr.h>
#include <flash_common.h>
#if defined(CONFIG_11ac_throughput_patch_from_412L08)
#include <shared_utils.h>
#endif
#include <bcmpci.h>
#include <linux/bcm_log.h>
#include <bcmSpiRes.h>
#if 1// __MSTC__, Paul Ho, for WLAN/WPS Button
#include <linux/signal.h>
#endif
//extern unsigned int flash_get_reserved_bytes_at_end(const FLASH_ADDR_INFO *fInfo);
/* Typedefs. */
#if defined (WIRELESS)
#define SES_EVENT_BTN_PRESSED 0x00000001
#define SES_EVENTS SES_EVENT_BTN_PRESSED /*OR all values if any*/
#define SES_LED_OFF 0
#define SES_LED_ON 1
#define SES_LED_BLINK 2
#if defined(CONFIG_BCM96362) || defined(CONFIG_BCM963268) || defined(CONFIG_BCM96318)
#define WLAN_ONBOARD_SLOT WLAN_ONCHIP_DEV_SLOT
#else
#define WLAN_ONBOARD_SLOT 1 /* Corresponds to IDSEL -- EBI_A11/PCI_AD12 */
#endif
#define BRCM_VENDOR_ID 0x14e4
#define BRCM_WLAN_DEVICE_IDS 0x4300
#define BRCM_WLAN_DEVICE_IDS_DEC 43
#define WLAN_ON 1
#define WLAN_OFF 0
#endif
#if 1 /* Support the CLI command to test incorrect bad block tables(BBT), __CHT__, MitraStar SeanLu, 20140328 */
/*ChenHe@MSTC merge from http://svn.mitrastar.com.tw/svn/CPE_TRUNK/BRCM_412/Products/DSL-401GNU-B1B_V2_CTL/132VFX0. r16481*/
extern void dumpNandInformation(void);
extern void setNandBadBlockEntry (BRCMNAND_ACTION_t action, int Value);
extern int MinBadBlockSet;
extern int MaxBadBlockSet;
#endif
typedef struct
{
unsigned long ulId;
char chInUse;
char chReserved[3];
} MAC_ADDR_INFO, *PMAC_ADDR_INFO;
typedef struct
{
unsigned long ulNumMacAddrs;
unsigned char ucaBaseMacAddr[NVRAM_MAC_ADDRESS_LEN];
MAC_ADDR_INFO MacAddrs[1];
} MAC_INFO, *PMAC_INFO;
typedef struct
{
unsigned char gponSerialNumber[NVRAM_GPON_SERIAL_NUMBER_LEN];
unsigned char gponPassword[NVRAM_GPON_PASSWORD_LEN];
} GPON_INFO, *PGPON_INFO;
typedef struct
{
unsigned long eventmask;
} BOARD_IOC, *PBOARD_IOC;
/*Dyinggasp callback*/
typedef void (*cb_dgasp_t)(void *arg);
typedef struct _CB_DGASP__LIST
{
struct list_head list;
char name[IFNAMSIZ];
cb_dgasp_t cb_dgasp_fn;
void *context;
}CB_DGASP_LIST , *PCB_DGASP_LIST;
/* Externs. */
extern struct file *fget_light(unsigned int fd, int *fput_needed);
extern unsigned long getMemorySize(void);
extern void __init boardLedInit(void);
extern void boardLedCtrl(BOARD_LED_NAME, BOARD_LED_STATE);
#ifdef CONFIG_MSTC_WDT
extern int mstc_wdt_init(void);
extern void mstc_wdt_exit(void);
extern int mstc_wdt_add_proc(void);
extern void mstc_wdt_del_proc(void);
#endif
/* Prototypes. */
static void set_mac_info( void );
static void set_gpon_info( void );
static int board_open( struct inode *inode, struct file *filp );
static int board_ioctl( struct inode *inode, struct file *flip, unsigned int command, unsigned long arg );
static ssize_t board_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos);
static unsigned int board_poll(struct file *filp, struct poll_table_struct *wait);
static int board_release(struct inode *inode, struct file *filp);
static BOARD_IOC* borad_ioc_alloc(void);
static void borad_ioc_free(BOARD_IOC* board_ioc);
/*
* flashImageMutex must be acquired for all write operations to
* nvram, CFE, or fs+kernel image. (cfe and nvram may share a sector).
*/
DEFINE_MUTEX(flashImageMutex);
static void writeNvramDataCrcLocked(PNVRAM_DATA pNvramData);
static PNVRAM_DATA readNvramData(void);
#if 1 //__MSTC__, Dennis
static void mustUpdateNvramfield(PNVRAM_DATA nData,PNVRAM_DATA oData);
#endif
/* DyingGasp function prototype */
static irqreturn_t kerSysDyingGaspIsr(int irq, void * dev_id);
static void __init kerSysInitDyingGaspHandler( void );
static void __exit kerSysDeinitDyingGaspHandler( void );
/* -DyingGasp function prototype - */
/* dgaspMutex protects list add and delete, but is ignored during isr. */
static DEFINE_MUTEX(dgaspMutex);
static int ConfigCs(BOARD_IOCTL_PARMS *parms);
#if defined (WIRELESS) && !defined(MSTC_WPS_BTN_SCE) // __MSTC__, Paul Ho, __MSTC__, Autumn
#if defined(CONFIG_BCM96368) || defined(CONFIG_BCM96328) || defined(CONFIG_BCM963268)
static GPIO_STATE_t GetGpio(int gpio);
#endif
#endif /* !defined(MSTC_WPS_BTN_SCE) */
#if defined (WIRELESS)
static irqreturn_t sesBtn_isr(int irq, void *dev_id);
static void __init sesBtn_mapIntr(int context);
static Bool sesBtn_pressed(void);
static unsigned int sesBtn_poll(struct file *file, struct poll_table_struct *wait);
static ssize_t sesBtn_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
static void __init sesLed_mapGpio(void);
static void sesLed_ctrl(int action, BOARD_LED_NAME ledName);
static void __init ses_board_init(void);
static void __exit ses_board_deinit(void);
static void __init kerSysScreenPciDevices(void);
static void kerSetWirelessPD(int state);
#endif
#if defined(CONFIG_BCM96816) || defined(CONFIG_BCM96362) || defined(CONFIG_BCM96328) || defined(CONFIG_BCM963268) || defined(CONFIG_BCM96318)
static void __init kerSysCheckPowerDownPcie(void);
#endif
static void str_to_num(char* in, char *out, int len);
static int add_proc_files(void);
static int del_proc_files(void);
static int proc_get_param(char *page, char **start, off_t off, int cnt, int *eof, void *data);
static int proc_set_param(struct file *f, const char *buf, unsigned long cnt, void *data);
static int proc_set_led(struct file *f, const char *buf, unsigned long cnt, void *data);
static irqreturn_t reset_isr(int irq, void *dev_id);
// macAddrMutex is used by kerSysGetMacAddress and kerSysReleaseMacAddress
// to protect access to g_pMacInfo
static DEFINE_MUTEX(macAddrMutex);
static PMAC_INFO g_pMacInfo = NULL;
static PGPON_INFO g_pGponInfo = NULL;
static unsigned long g_ulSdramSize;
#if defined(CONFIG_BCM96368)
static unsigned long g_ulSdramWidth;
#endif
static int g_ledInitialized = 0;
static wait_queue_head_t g_board_wait_queue;
static CB_DGASP_LIST *g_cb_dgasp_list_head = NULL;
#define MAX_PAYLOAD_LEN 64
static struct sock *g_monitor_nl_sk;
static int g_monitor_nl_pid = 0 ;
static void kerSysInitMonitorSocket( void );
static void kerSysCleanupMonitorSocket( void );
#if defined(CONFIG_BCM96368)
static void ChipSoftReset(void);
static void ResetPiRegisters( void );
static void PI_upper_set( volatile uint32 *PI_reg, int newPhaseInt );
static void PI_lower_set( volatile uint32 *PI_reg, int newPhaseInt );
static void TurnOffSyncMode( void );
#endif
#if defined(CONFIG_BCM96816)
void board_Init6829( void );
#endif
#if defined(BUILD_11ac_throughput_patch_from_412L07)
static kerSysMacAddressNotifyHook_t kerSysMacAddressNotifyHook = NULL;
#endif
#if !defined(CONFIG_AUXFS_JFFS2)
/* restore default work structure */
static struct work_struct restoreDefaultWork;
#endif
static struct file_operations board_fops =
{
open: board_open,
ioctl: board_ioctl,
poll: board_poll,
read: board_read,
release: board_release,
};
uint32 board_major = 0;
#if 1 //__MSTC__, Leo, support LED power management
static int pwrMngtOn_usb0 = 1;
static int pwrMngtOn_usb1 = 1;
#endif
#if 1 //__MSTC__, RaynorChung: Ssupport USB LED
int chkUsbtimer=0;
static int isUSBDevice0Inserted=0;
static int isUSBDevice1Inserted=0;
struct timer_list gUsbTimer;
#endif
#if 1 /* PeterSu */
static int ledctl_usb_te_test = 0;
#endif
#if defined (WIRELESS)
static unsigned short sesBtn_irq = BP_NOT_DEFINED;
static unsigned short sesLed_gpio = BP_NOT_DEFINED;
#ifdef MSTC_WLAN_WPS_BTN_SEPARATE //__MSTC__, Eason, WLAN_WPS_BTN_SEPARATE
static unsigned short wlanBtn_irq = BP_NOT_DEFINED;
#endif
#if 1 // __MSTC__, Paul Ho, for WLAN/WPS Button
struct timer_list gResetTimer;
#if defined(MSTC_WPS_BTN_SCE)
static int chkWlanEnCounter = 0;
#else
int chkWlanBtnTimer; /* add for WLAN Button */
struct timer_list gWlanTimer; /* add for WLAN Button */
#endif /* defined(MSTC_WPS_BTN_SCE) */
#ifdef MSTC_WLAN_WPS_BTN_SEPARATE //__MSTC__, Eason, WLAN_WPS_BTN_SEPARATE
struct timer_list gResetTimerWlanBtn;
static int chkWlanBtnCounter = 0;
#endif
pid_t pid_no;
#endif // end, __MSTC__, Paul Ho
#endif /* defined (WIRELESS) */
#if 1 //__MSTC__, FuChia
uint8 stopblinkwl = 0;
uint8 stopblink = 0;
uint8 buttonTest = 0;
#define ktimems (HZ/10)
int ktimems_v = ktimems;
static unsigned short resetBtn_irq = BP_NOT_DEFINED;
int chkResetCounter = 0;
#endif //__MSTC__, FuChia
#if 1 /* chchien , disable wlan button in the front panel */
uint8 disWLANbutton = 0;
#endif
#ifdef CONFIG_MSTC_RECORD_CALL_TRACE
extern char oops_folder_path[64];
extern int oops_file_num;
static void mstc_koops_init(void)
{
strcpy(oops_folder_path, CONFIG_MSTC_RECORD_CALL_TRACE_PATH);
oops_file_num = CONFIG_MSTC_OOPS_FILE_NUM;
return;
}
static int proc_koops_folder_get(char *page, char **start, off_t off, int cnt, int *eof, void *data)
{
int len;
len = sprintf(page, "Default folder: %s\nCurrent folder: %s\n", CONFIG_MSTC_RECORD_CALL_TRACE_PATH, oops_folder_path);
return len;
}
static int proc_koops_folder_set(struct file *f, const char *buf, unsigned long cnt, void *data)
{
char input[64];
char tmp[64];
int len = 0;
int ret = -1;
memset(input, 0, sizeof(input));
memset(tmp, 0, sizeof(tmp));
if ((cnt > 63) || (copy_from_user(input, buf, cnt) != 0)) {
printk("Invalid value!");
return -EFAULT;
}
ret = sscanf(input, "%s\n", tmp);
len = strlen(tmp);
if((ret != 1) || (len <= 0)) {
printk("Invalid value!");
return -EFAULT;
}
if(tmp[len - 1] != '/') {
if(len < 63) {
tmp[len] = '/';
} else {
printk("Invalid value!");
return -EFAULT;
}
}
strcpy(oops_folder_path, tmp);
return cnt;
}
static int proc_koops_fn_get(char *page, char **start, off_t off, int cnt, int *eof, void *data)
{
int len;
len = sprintf(page, "Default file_num: %d\nCurrent file_num: %d\n", CONFIG_MSTC_OOPS_FILE_NUM, oops_file_num);
return len;
}
static int proc_koops_fn_set(struct file *f, const char *buf, unsigned long cnt, void *data)
{
char input[64];
int fn;
int ret = -1;
memset(input, 0, sizeof(input));
if ((cnt > 63) || (copy_from_user(input, buf, cnt) != 0)) {
printk("Invalid value!");
return -EFAULT;
}
ret = sscanf(input, "%d\n", &fn);
if((ret != 1) || (fn <= 0)) {
printk("Invalid value!");
return -EFAULT;
}
oops_file_num = fn;
return cnt;
}
static int mstc_koops_add_proc(void)
{
struct proc_dir_entry *koops_dir = NULL;
struct proc_dir_entry *koops_folder = NULL;
struct proc_dir_entry *koops_file_num = NULL;
koops_dir = proc_mkdir("mstc_koops", NULL);
if (koops_dir == NULL) {
printk(KERN_ERR "add_proc_files: failed to create mstc_kd proc files!\n");
return -1;
}
koops_folder = create_proc_entry("oops_folder", 0644, koops_dir);
if (koops_folder == NULL) {
printk(KERN_ERR "add_proc_files: failed to create koops_folder proc files!\n");
return -1;
}
koops_folder->read_proc = proc_koops_folder_get;
koops_folder->write_proc = proc_koops_folder_set;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
/* New linux no longer requires proc_dir_entry->owner field. */
#else
koops_folder->owner = THIS_MODULE;
#endif
koops_file_num = create_proc_entry("file_num", 0644, koops_dir);
if (koops_file_num == NULL) {
printk(KERN_ERR "add_proc_files: failed to create coredump_preThreshold proc files!\n");
return -1;
}
koops_file_num->read_proc = proc_koops_fn_get;
koops_file_num->write_proc = proc_koops_fn_set;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
/* New linux no longer requires proc_dir_entry->owner field. */
#else
koops_file_num->owner = THIS_MODULE;
#endif
return 0;
}
static void mstc_koops_del_proc(void)
{
remove_proc_entry("oops_folder", NULL);
remove_proc_entry("file_num", NULL);
return;
}
#endif
#ifdef CONFIG_MSTC_DEC_AND_GZIP_CORE
extern char core_folder_path[64];
extern int core_pre_threshold;
extern int core_post_threshold;
static void mstc_coredump_init(void)
{
strcpy(core_folder_path, CONFIG_MSTC_COREDUMP_FOLDER_PATH);
core_pre_threshold = CONFIG_MSTC_CORE_SIZE_PRE_THRESHOLD;
core_post_threshold = CONFIG_MSTC_CORE_SIZE_POST_THRESHOLD;
return;
}
static int proc_coredump_folder_get(char *page, char **start, off_t off, int cnt, int *eof, void *data)
{
int len;
len = sprintf(page, "Default folder: %s\nCurrent folder: %s\n", CONFIG_MSTC_COREDUMP_FOLDER_PATH, core_folder_path);
return len;
}
static int proc_coredump_folder_set(struct file *f, const char *buf, unsigned long cnt, void *data)
{
char input[64];
char tmp[64];
int len = 0;
int ret = -1;
memset(input, 0, sizeof(input));
memset(tmp, 0, sizeof(tmp));
if ((cnt > 63) || (copy_from_user(input, buf, cnt) != 0)) {
printk("Invalid value!");
return -EFAULT;
}
ret = sscanf(input, "%s\n", tmp);
len = strlen(tmp);
if((ret != 1) || (len <= 0)) {
printk("Invalid value!");
return -EFAULT;
}
if(tmp[len - 1] != '/') {
if(len < 63) {
tmp[len] = '/';
} else {
printk("Invalid value!");
return -EFAULT;
}
}
strcpy(core_folder_path, tmp);
return cnt;
}
static int proc_coredump_preThreshold_get(char *page, char **start, off_t off, int cnt, int *eof, void *data)
{
int len;
len = sprintf(page, "Default preThreshold: %d\nCurrent preThreshold: %d\n", CONFIG_MSTC_CORE_SIZE_PRE_THRESHOLD, core_pre_threshold);
return len;
}
static int proc_coredump_preThreshold_set(struct file *f, const char *buf, unsigned long cnt, void *data)
{
char input[64];
int threshold;
int ret = -1;
memset(input, 0, sizeof(input));
if ((cnt > 63) || (copy_from_user(input, buf, cnt) != 0)) {
printk("Invalid value!");
return -EFAULT;
}
ret = sscanf(input, "%d\n", &threshold);
if((ret != 1) || (threshold <= 0)) {
printk("Invalid value!");
return -EFAULT;
}
core_pre_threshold = threshold;
return cnt;
}
static int proc_coredump_postThreshold_get(char *page, char **start, off_t off, int cnt, int *eof, void *data)
{
int len;
len = sprintf(page, "Default postThreshold: %d\nCurrent postThreshold: %d\n", CONFIG_MSTC_CORE_SIZE_POST_THRESHOLD, core_post_threshold);
return len;
}
static int proc_coredump_postThreshold_set(struct file *f, const char *buf, unsigned long cnt, void *data)
{
char input[64];
int threshold;
int ret = -1;
memset(input, 0, sizeof(input));
if ((cnt > 63) || (copy_from_user(input, buf, cnt) != 0)) {
printk("Invalid value!");
return -EFAULT;
}
ret = sscanf(input, "%d\n", &threshold);
if((ret != 1) || (threshold <= 0)) {
printk("Invalid value!");
return -EFAULT;
}
core_post_threshold = threshold;
return cnt;
}
static int mstc_coredump_add_proc(void)
{
struct proc_dir_entry *coredump_dir = NULL;
struct proc_dir_entry *coredump_folder = NULL;
struct proc_dir_entry *coredump_preThreshold = NULL;
struct proc_dir_entry *coredump_postThreshold = NULL;
coredump_dir = proc_mkdir("mstc_coredump", NULL);
if (coredump_dir == NULL) {
printk(KERN_ERR "add_proc_files: failed to create mstc_kd proc files!\n");
return -1;
}
coredump_folder = create_proc_entry("coredump_folder", 0644, coredump_dir);
if (coredump_folder == NULL) {
printk(KERN_ERR "add_proc_files: failed to create coredump_folder proc files!\n");
return -1;
}
coredump_folder->read_proc = proc_coredump_folder_get;
coredump_folder->write_proc = proc_coredump_folder_set;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
/* New linux no longer requires proc_dir_entry->owner field. */
#else
coredump_folder->owner = THIS_MODULE;
#endif
coredump_preThreshold = create_proc_entry("preThreshold", 0644, coredump_dir);
if (coredump_preThreshold == NULL) {
printk(KERN_ERR "add_proc_files: failed to create coredump_preThreshold proc files!\n");
return -1;
}
coredump_preThreshold->read_proc = proc_coredump_preThreshold_get;
coredump_preThreshold->write_proc = proc_coredump_preThreshold_set;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
/* New linux no longer requires proc_dir_entry->owner field. */
#else
coredump_preThreshold->owner = THIS_MODULE;
#endif
coredump_postThreshold = create_proc_entry("postThreshold", 0644, coredump_dir);
if (coredump_postThreshold == NULL) {
printk(KERN_ERR "add_proc_files: failed to create coredump_postThreshold proc files!\n");
return -1;
}
coredump_postThreshold->read_proc = proc_coredump_postThreshold_get;
coredump_postThreshold->write_proc = proc_coredump_postThreshold_set;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
/* New linux no longer requires proc_dir_entry->owner field. */
#else
coredump_postThreshold->owner = THIS_MODULE;
#endif
return 0;
}
static void mstc_coredump_del_proc(void)
{
remove_proc_entry("coredump_folder", NULL);
remove_proc_entry("preThreshold", NULL);
remove_proc_entry("postThreshold", NULL);
return;
}
#endif
#if 1 //__MSTC__, RaynorChung: Ssupport USB LED
void setUsbDeviceInserted(BOARD_LED_NAME ledName, int status){
if (status == 1)
{
#if 1 //__MSTC__, Leo, support LED power management
if (ledName == kLedUSB0){
isUSBDevice0Inserted = 1;
pwrMngtOn_usb0 = 1;
}
if (ledName == kLedUSB1){
isUSBDevice1Inserted = 1;
pwrMngtOn_usb1 = 1;
}
#else
if (ledName == kLedUSB0)
isUSBDevice0Inserted = 1;
else if (ledName == kLedUSB1)
isUSBDevice1Inserted = 1;
#endif
} else if (status == 0)
{
if (ledName == kLedUSB0)
isUSBDevice0Inserted = 0;
else if (ledName == kLedUSB1)
isUSBDevice1Inserted = 0;
}
ledctl_usb_te_test = 0;
return;
}
void UsbTimerExpire(void)
{
chkUsbtimer++;
if (chkUsbtimer > 5) /*check every 500 mini seconds*/
{
#if 1 /* PeterSu */
if (ledctl_usb_te_test == 0)
#endif
{
#if 1 //__MSTC__, Leo, support LED power management
if (isUSBDevice0Inserted && pwrMngtOn_usb0)
#else
if (isUSBDevice0Inserted)
#endif
kerSysLedCtrl(kLedUSB0,kLedStateOn);
else
kerSysLedCtrl(kLedUSB0,kLedStateOff);
#if 1 //__MSTC__, Leo, support LED power management
if (isUSBDevice1Inserted && pwrMngtOn_usb1)
#else
if (isUSBDevice1Inserted)
#endif
kerSysLedCtrl(kLedUSB1,kLedStateOn);
else
kerSysLedCtrl(kLedUSB1,kLedStateOff);
}
chkUsbtimer =0;
}
// start timer
init_timer(&gUsbTimer);
gUsbTimer.function = (void*)UsbTimerExpire;
gUsbTimer.expires = jiffies+ktimems_v; // timer expires in ~100ms
add_timer (&gUsbTimer);
}
#endif
#if defined (WIRELESS) && !defined(MSTC_WPS_BTN_SCE) // __MSTC__, Paul Ho, for WLAN Button
void WlanTimerExpire(void)
{
struct task_struct *p;
const int CV_WLAN_BTN_PERIOD = 1; /* "Pressing the button for at least 1 second is enabling / disabling the WLAN." */
unsigned short wlBtnGpio;
if (BpGetWirelessBtnGpio(&wlBtnGpio) != BP_SUCCESS)
{
printk(KERN_ERR "Cannot get WLAN on/off button GPIO!!\n");
return;
}
if (GetGpio(wlBtnGpio) == 0)
{
chkWlanBtnTimer++;
}
else
{
if ( chkWlanBtnTimer >= CV_WLAN_BTN_PERIOD*10 ) {
printk(KERN_WARNING "\r\n WLAN Behavior %d\n", chkWlanBtnTimer);
/*if ( buttonTest == 1 ) {
if ( stopblinkwl == 0 ) {
kerSysLedCtrl(kLedPowerG, kLedStateFastBlinkContinues);
stopblinkwl = 1;
}
else {
kerSysLedCtrl(kLedPowerG, kLedStateOn);
stopblinkwl = 0;
}
}
else*/ {
printk(KERN_WARNING "\r\n WLAN Button Pressed, send SIGUSR1 to wlmngr pid_no:%d\n", pid_no);
p = find_task_by_vpid(pid_no);
if(p!=NULL)
send_sig(SIGUSR1,p,0);
else
printk(KERN_ERR "WLAN on/off can't work.\n");
}
}
/*else if ( chkWlanBtnTimer >0 && buttonTest == 1 )
{
printk(KERN_ERR "\r\n WLAN Button Pressed\n");
if ( stopblinkwl == 0 ) {
kerSysLedCtrl(kLedPowerG, kLedStateFastBlinkContinues);
stopblinkwl = 1;
}
else {
kerSysLedCtrl(kLedPowerG, kLedStateOn);
stopblinkwl = 0;
}
}*/
chkWlanBtnTimer = 0;
}
// start timer
init_timer(&gWlanTimer);
gWlanTimer.function = (void*)WlanTimerExpire;
gWlanTimer.expires = jiffies+ktimems_v; // timer expires in ~100ms
add_timer (&gWlanTimer);
}
#endif /* defined (WIRELESS) */
#if defined(MODULE)
int init_module(void)
{
return( brcm_board_init() );
}
void cleanup_module(void)
{
if (MOD_IN_USE)
printk("brcm flash: cleanup_module failed because module is in use\n");
else
brcm_board_cleanup();
}
#endif //MODULE
static int map_external_irq (int irq)
{
int map_irq;
switch (irq) {
case BP_EXT_INTR_0 :
map_irq = INTERRUPT_ID_EXTERNAL_0;
break ;
case BP_EXT_INTR_1 :
map_irq = INTERRUPT_ID_EXTERNAL_1;
break ;
case BP_EXT_INTR_2 :
map_irq = INTERRUPT_ID_EXTERNAL_2;
break ;
case BP_EXT_INTR_3 :
map_irq = INTERRUPT_ID_EXTERNAL_3;
break ;
#if defined(CONFIG_BCM96368) || defined(CONFIG_BCM96816)
case BP_EXT_INTR_4 :
map_irq = INTERRUPT_ID_EXTERNAL_4;
break ;
case BP_EXT_INTR_5 :
map_irq = INTERRUPT_ID_EXTERNAL_5;
break ;
#endif
default :
printk ("Invalid External Interrupt definition \n") ;
map_irq = 0 ;
break ;
}
return (map_irq) ;
}
/* A global variable used by Power Management and other features to determine if Voice is idle or not */
volatile int isVoiceIdle = 1;
EXPORT_SYMBOL(isVoiceIdle);
#if defined(CONFIG_BCM_AVS_PWRSAVE) && !defined(CONFIG_11ac_throughput_patch_from_412L08)
/* A generic kernel thread for board related maintenance activities */
/* Only used if AVS is configured, but feel free to change */
static DECLARE_COMPLETION(poll_done);
static atomic_t poll_lock = ATOMIC_INIT(1);
static int poll_pid = -1;
/* The AVS algorith lowers 1V2 until the slowest ring osc (the one with
the largest count) reaches the RING_OSC_LOWER_BOUND. Then the algorithm
will re-increase the voltage if the ring osc continues to slow down to a
point where its count exceeds the RING_OSC_UPPER_BOUND. */
#if defined(CONFIG_BCM_PWRMNGT_MODULE)
int AvsEnabled = -1; // Wait for the module to control if it is enabled or not
#else
int AvsEnabled = 1; // There is no control so force it to be enabled
#endif
void kerSysBcmEnableAvs(int enable)
{
unsigned short vregVsel1P2;
/* Set target 1V2 level */
if (BpGetVregSel1P2(&vregVsel1P2) == BP_SUCCESS ) {
AvsEnabled = -1;
printk("Adaptive Voltage Scaling is disabled because 1V2 is forced to a specific level by design\n");
} else {
AvsEnabled = enable;
printk("Adaptive Voltage Scaling is now %s\n", (enable==1?"enabled":(enable==0?"disabled":"stopped")));
}
}
int kerSysBcmAvsEnabled(void)
{
return AvsEnabled;
}
#if defined(CONFIG_BCM96362)
/* 36483, Highest ring osc count read during successful PVT
a small margin is included to avoid ever reaching this highest count */
//#define RING_OSC_UPPER_BOUND (0x8E83 - 100)
#define RING_OSC_UPPER_BOUND (0x6F1C - 100) // 3.6 MHz + tidbits
/* 1100 is about the max ring osc variation when doing a 1V2 step change */
#define RING_OSC_LOWER_BOUND (RING_OSC_UPPER_BOUND - 1100)
/* 1V2 is set by default to 1.225. HW team is asking that we don't allow the
voltage to go below 1.19 V. */
#define VREG_VSEL1P2_LOWER_BOUND ((VREG_VSEL1P2_MIDDLE+1) - 3)
/* 6362 Slow parts need to have their voltage increased to avoid WLAN issues
This is the threshold we use to identify what looks like a slow part.
A large enough delta is needed between this threshold and the
RING_OSC_UPPER_BOUND (~2 MHz here) */
#define RING_OSC_SS_UPPER_BOUND (0x75A5) // 3.4 MHz
#define VREG_VSEL1P2_SS_TARGET (VREG_VSEL1P2_MIDDLE+1)
#endif
#if defined(CONFIG_BCM96816)
/* PVT suggests we can go as high as A6AA but choosing to be conservative */
#define RING_OSC_UPPER_BOUND (0x9000 - 100)
#define RING_OSC_LOWER_BOUND (RING_OSC_UPPER_BOUND - 1100)
#define VREG_VSEL1P2_LOWER_BOUND ((VREG_VSEL1P2_MIDDLE+1) - 4)
#endif
#if defined(CONFIG_BCM96368)
#define RING_OSC_UPPER_BOUND (0x84FA - 100)
#define RING_OSC_LOWER_BOUND (RING_OSC_UPPER_BOUND - 1500)
#define VREG_VSEL1P2_LOWER_BOUND ((VREG_VSEL1P2_MIDDLE+1) - 4)
#endif
#if defined(CONFIG_BCM96328)
#define RING_OSC_UPPER_BOUND
#define RING_OSC_LOWER_BOUND
#define VREG_VSEL1P2_LOWER_BOUND
#endif
#if defined(CONFIG_BCM963268) // untested
#define RING_OSC_UPPER_BOUND (0x84FA - 100)
#define RING_OSC_LOWER_BOUND (RING_OSC_UPPER_BOUND - 1500)
#define VREG_VSEL1P2_LOWER_BOUND ((VREG_VSEL1P2_MIDDLE+1) - 4)
#endif
#define AVSDEBUG(f, ...)
//#define AVSDEBUG(f, ...) printk(f, __VA_ARGS__)
static void brcm_adaptive_voltage_scaling(void)
{
static int max_count = 0;
static int is_ss_part = 0;
int ring_osc_select = 0;
int current_1v2 = 0;
int next_1v2 = 0;
uint32 RingOscCtrl1 = GPIO->RingOscCtrl1;
/* Verify is AVS is not forced off */
if (AvsEnabled != -1) {
/* Verify if the ring oscillator has completed a measurement */
/* This will only fail on the very first call to this function */
if (RingOscCtrl1 & RING_OSC_IRQ)
{
AVSDEBUG("Read ring osc %d: %lx\n",
(RingOscCtrl1 & RING_OSC_SELECT_MASK) >> RING_OSC_SELECT_SHIFT,
RingOscCtrl1 & RING_OSC_COUNT_MASK);
if ((RingOscCtrl1 & RING_OSC_COUNT_MASK) > max_count)
{
max_count = RingOscCtrl1 & RING_OSC_COUNT_MASK;
AVSDEBUG("max_count: %x\n", max_count);
}
/* Move to the next enabled ring osc */
ring_osc_select = (RingOscCtrl1 & RING_OSC_SELECT_MASK) >> RING_OSC_SELECT_SHIFT;
while (++ring_osc_select < RING_OSC_MAX)
{
if ((((1<<ring_osc_select)<<RING_OSC_ENABLE_SHIFT) & RING_OSC_ENABLE_MASK) != 0)
{
break;
}
}
/* If we have read all ring osc, determine if the voltage should be changed */
if (ring_osc_select == RING_OSC_MAX)
{
/* All ring osc have been read, prepare for the next round */
/* 0 is always a valid ring osc so no need to verify if it is enabled */
ring_osc_select = 0;
/* Check if the voltage should be adjusted */
if ((max_count < RING_OSC_LOWER_BOUND) && AvsEnabled && !is_ss_part)
{
/* The ring osc is too fast, reduce the voltage if it is not too low */
#if defined(CONFIG_BCM96368) || defined(CONFIG_BCM96816)
current_1v2 = (GPIO->VregConfig & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#elif defined(CONFIG_BCM96362)
current_1v2 = (MISC->miscVregCtrl1 & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#else
current_1v2 = (MISC->miscVregCtrl0 & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#endif
next_1v2 = current_1v2;
if (current_1v2 == 0)
{
next_1v2 = VREG_VSEL1P2_MIDDLE;
}
else if (current_1v2 > VREG_VSEL1P2_LOWER_BOUND)
{
next_1v2--;
}
AVSDEBUG("ring_osc is fast, can reduce voltage: %d to %d\n", current_1v2, next_1v2);
}
else if ((max_count > RING_OSC_UPPER_BOUND) || !AvsEnabled || is_ss_part)
{
/* The ring osc is too slow, increase the voltage up to the default of 0 */
/* If AVS is disabled, we need to force the voltage to come back up to default */
#if defined(CONFIG_BCM96368) || defined(CONFIG_BCM96816)
current_1v2 = (GPIO->VregConfig & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#elif defined(CONFIG_BCM96362)
current_1v2 = (MISC->miscVregCtrl1 & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#else
current_1v2 = (MISC->miscVregCtrl0 & VREG_VSEL1P2_MASK) >> VREG_VSEL1P2_SHIFT;
#endif