forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmx50_ntx_io.c
executable file
·3082 lines (2674 loc) · 90 KB
/
mx50_ntx_io.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
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <mach/hardware.h>
#include <mach/gpio.h>
#include <mach/iomux-mx50.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <generated/autoconf.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/wait.h>
#include <linux/miscdevice.h>
#include <linux/irq.h>
#include <linux/freezer.h>
#include <linux/wakelock.h>
#include <mach/common.h>
#include <linux/gpio_keys.h>
#include <linux/input.h>
#include "../../../drivers/video/mxc/lk_tps65185.h"
#include "ntx_hwconfig.h"
#define _WIFI_ALWAYS_ON_ // wifi always on for startic
#define KEY_FL 90
#define GPIO_ACIN_PG (3*32 + 19) /*GPIO_4_19 */
#define GPIO_CHG (3*32 + 18) /*GPIO_4_18 */
#define GPIO_ACIN_ID (3*32 + 16) /*GPIO_4_16 */
//#define GPIO_LED_ON (0*32 + 24) /*GPIO_1_24 */
#define GPIO_LED_ON gGPIO_LED_ON /* default=GPIO_1_24 */
//#define GPIO_ACT_ON (5*32 + 24) /*GPIO_6_24 */
#define GPIO_ACT_ON gGPIO_ACT_ON /* default=GPIO_6_24 */
#define GPIO_CHG_LED (0*32 + 25) /*GPIO_1_25 */
#define GPIO_PWR_SW (3*32 + 10) /*GPIO_4_10 */
#define GPIO_WIFI_3V3 (3*32 + 12) /*GPIO_4_12 */
#define GPIO_WIFI_RST (4*32 + 14) /*GPIO_5_14 */
#define GPIO_WIFI_RST_4_17 (3*32 + 17) /*GPIO_4_17 */
#define GPIO_WIFI_INT (3*32 + 8) /*GPIO_4_8 */
#define GPIO_MSP_INT (3*32 + 11) /*GPIO_4_11 */
#define SD2_CD (4*32 + 17) /*GPIO_5_17 */
#define SD2_WP (4*32 + 16) /*GPIO_5_16 */
#define TOUCH_PWR (3*32 + 16) /*GPIO_4_16 */
#define TP_PWEN (3*32 + 9) /*GPIO_4_9 */
#define TOUCH_RST (4*32 + 28) /*GPIO_5_28 */
#define TOUCH_RST_5_12 (4*32 + 12) /*GPIO_5_12 */
#define TOUCH_EN (4*32 + 26) /*GPIO_5_26 */
#define TOUCH_INT (4*32 + 15) /*GPIO_5_15 */
#define C_TOUCH_INT (4*32 + 27) /*GPIO_5_27 */
#define C_TOUCH_INT_5_13 (4*32 + 13) /*GPIO_5_13 */
#define GPIO_I2C3_SDA (5*32 + 23) /*GPIO_6_23 */
#define GPIO_I2C3_SCL (5*32 + 22) /*GPIO_6_22 */
#define GPIO_AUDIO_PWR (3*32 + 17) /*GPIO_4_17 */
//#define G_SENSOR_INT (4*32 + 25) /*GPIO_5_25 */
//#define E50602_G_SENSOR_INT (3*32 + 15) /*GPIO_4_15 */
#define SPD_EN (3*32 + 13) /*GPIO_4_13 */
#define FL_EN (3*32 + 14) /*GPIO_4_14 */
#define FL_R_EN (3*32 + 22) /*GPIO_4_22 */
#define E606C2_G_SENSOR_INT (4*32 + 27) /*GPIO_5_27 */
#define GPIO_TP56 (3*32 + 23) /*GPIO_4_23 */
#define GPIO_MSP430_TP_INT (3*32 + 7) /*GPIO_4_7 */
#define GPIO_KEY_FL (3*32 + 23) /*GPIO_4_23 */
#define GPIO_KEY_HOME (3*32 + 1) /*GPIO_4_1 */
#define GPIO_KEY_COL_0 (3*32 + 0) /*GPIO_4_0 */
#define GPIO_KEY_ROW_0 (3*32 + 1) /*GPIO_4_1 */
#define GPIO_KEY_COL_1 (3*32 + 2) /*GPIO_4_2 */
#define GPIO_KEY_ROW_1 (3*32 + 3) /*GPIO_4_3 */
#define GPIO_KEY_COL_2 (3*32 + 4) /*GPIO_4_4 */
#define GPIO_KEY_ROW_2 (3*32 + 5) /*GPIO_4_5 */
#define GPIO_KEY_COL_3 (3*32 + 6) /*GPIO_4_6 */
#define GPIO_KEY_ROW_3 (3*32 + 7) /*GPIO_4_7 */
#define GPIO_HWID_1 (5*32 + 14) /*GPIO_6_14 */
#define GPIO_HWID_2 (5*32 + 15) /*GPIO_6_15 */
#define GPIO_HWID_3 (5*32 + 17) /*GPIO_6_17 */
#define GPIO_HWID_4 (4*32 + 16) /*GPIO_5_16 */
#define EIM_DA0 (0*32 + 0) /*GPIO_1_0*/
#define EIM_DA1 (0*32 + 1) /*GPIO_1_1*/
#define EIM_DA2 (0*32 + 2) /*GPIO_1_2*/
#define EIM_DA3 (0*32 + 3) /*GPIO_1_3*/
#define EIM_DA4 (0*32 + 4) /*GPIO_1_4*/
#define EIM_DA5 (0*32 + 5) /*GPIO_1_5*/
#define EIM_DA6 (0*32 + 6) /*GPIO_1_6*/
#define EIM_DA7 (0*32 + 7) /*GPIO_1_7*/
#define EIM_DA8 (0*32 + 8) /*GPIO_1_8*/
#define EIM_DA9 (0*32 + 9) /*GPIO_1_9*/
#define EIM_DA10 (0*32 + 10) /*GPIO_1_10*/
#define EIM_DA11 (0*32 + 11) /*GPIO_1_11*/
#define EIM_DA12 (0*32 + 12) /*GPIO_1_12*/
#define EIM_DA13 (0*32 + 13) /*GPIO_1_13*/
#define EIM_DA14 (0*32 + 14) /*GPIO_1_14*/
#define EIM_DA15 (0*32 + 15) /*GPIO_1_15*/
#define EIM_CS2 (0*32 + 16) /*GPIO_1_16*/
#define EIM_CS1 (0*32 + 17) /*GPIO_1_17*/
#define EIM_CS0 (0*32 + 18) /*GPIO_1_18*/
#define EIM_EB0 (0*32 + 19) /*GPIO_1_19*/
#define EIM_EB1 (0*32 + 20) /*GPIO_1_20*/
#define EIM_WAIT (0*32 + 21) /*GPIO_1_21*/
#define EIM_BCLK (0*32 + 22) /*GPIO_1_22*/
#define EIM_RDY (0*32 + 23) /*GPIO_1_23*/
#define GPIO_ISD_PWR (0*32 + 26) /*GPIO_1_26*/
#define DEVICE_NAME "ntx_io" // "pvi_io"
#define DEVICE_MINOR 190
#define CM_PLATFORM 164
#define CM_HWCONFIG 165
#define CM_SET_HWCONFIG 166
#define CM_SD_IN 117
#define AC_IN 118
#define CM_PWR_ON2 112
#define CM_AUDIO_PWR 113
#define CM_POWER_BTN 110
#define CM_USB_Plug_IN 108
#define CM_AC_CK 109
#define CM_CHARGE_STATUS 204
#define CM_nLED 101
#define CM_nLED_CPU 102
#define POWER_OFF_COMMAND 0xC0 // 192
#define SYS_RESET_COMMAND 193 // Joseph 091223
#define GET_LnBATT_CPU 0XC2 // 194
#define GET_VBATT_TH 0XC3 // 195
#define CM_SIGUSR1 104
//kay 20081110 for detecting SD write protect
#define CM_SD_PROTECT 120
//20090216 for detecting controller
#define CM_CONTROLLER 121
//20090416 for detecting controller
#define CM_USB_AC_STATUS 122
#define CM_RTC_WAKEUP_FLAG 123
#define CM_SYSTEM_RESET 124
#define CM_USB_HOST_PWR 125
#define CM_BLUETOOTH_PWR 126
#define CM_TELLPID 99
#define CM_LED_BLINK 127
#define CM_TOUCH_LOCK 128
#define CM_DEVICE_MODULE 129
#define CM_BLUETOOTH_RESET 130
#define CM_DEVICE_INFO 131
//Joseph 091211 for 3G
#define CM_3G_POWER 150
#define CM_3G_RF_OFF 151
#define CM_3G_RESET 152
#define CM_3G_GET_WAKE_STATUS 153
//Joseph 091209
#define CM_ROTARY_STATUS 200
#define CM_GET_KEY_STATUS 201
#define CM_GET_WHEEL_KEY_STATUS 202
#define POWER_KEEP_COMMAND 205
#define CM_GET_BATTERY_STATUS 206
#define CM_SET_ALARM_WAKEUP 207
#define CM_WIFI_CTRL 208
#define CM_ROTARY_ENABLE 209
#define CM_GET_UP_VERSION 215
// gallen 100621
// Audio functions ...
#define CM_AUDIO_GET_VOLUME 230
#define CM_AUDIO_SET_VOLUME 240
#define CM_GET_KEYS 107
static volatile unsigned gGPIO_LED_ON=(0*32 + 24),gGPIO_ACT_ON=(5*32 + 24);
// Terry add 20121220 : Terry param
#define CM_GET_FB_DONE_RENDER 241
#define CM_SET_WANT_TO_CHECK_FB_RENDER_STATE 242
#define CM_SET_SLEEPSCREEN_STATE 243
#define CM_GET_SLEEPSCREEN_STATE 244
#define CM_CRITICALLOW_OCCUR 1000
#define CM_SET_LAST_SHUTDOWN_CRITICALLOW_OCCUR 1001
#define UNSET -1;
#define DEVICE_NORMAL_STATE 1
#define DEVICE_SLEEP_STATE 2
// Terry add 20130510 : FixBug: battery level is unstable while plugin-out USB
#define BATTERY_PERCENTAGE_SMOOTH
int g_last_shutdown_due_to_critical_low = 0;
unsigned short __EBRMAIN_PID__ = 0;
unsigned char __USB_ADAPTOR__=0;
EXPORT_SYMBOL(__USB_ADAPTOR__);
static int Driver_Count = -1;
unsigned char __TOUCH_LOCK__= 0;
int gSleep_Mode_Suspend;
int gFinishKernelBoot = 0; // Terry add 20130119 : add kernel finish booting process flag
//terry add 20130301
static struct fasync_struct *fasync_queue;
extern volatile NTX_HWCONFIG *gptHWCFG;
typedef enum __DEV_MODULE_NAME{
EB500=0,
EB600=1,
EB600E=2,
EB600EM=3,
COOKIE=4,
}__dev_module_name;
typedef enum __DEV_MODULE_CPU{
CPU_S3C2410=0,
CPU_S3C2440=1,
CPU_S3C2416=2,
CPU_CORETEX_A8=3,
CPU_COOKIE=4,
}__dev_module_cpu;
typedef enum __DEV_MODULE_CONTROLLER{
CONTROLLER_PVI=0,
CONTROLLER_EPSON=1,
CONTROLLER_SW=2,
}__dev_module_controller;
typedef enum __DEV_MODULE_WIFI{
WIFI_NONE=0,
WIFI_MARVELL=1,
WIFI_OTHER=2,
}__dev_module_wifi;
typedef enum __DEV_MODULE_BLUETOOTH{
BLUETOOTH_NONE=0,
BLUETOOTH_TI=1,
BLUETOOTH_CSR=2,
}__devi_module_bluetooth;
struct ebook_device_info {
char device_name;
char cpu;
char controller;
char wifi;
char bluetooth;
};
//kay for LED thread
//static unsigned char LED_conitnuous=0;
static unsigned char LED_conitnuous=1;
static int LED_Flash_Count;
static int gKeepPowerAlive;
int gMxcPowerKeyIrqTriggered, gIsMSP430IntTriggered, g_power_key_pressed;
volatile int gBatteryPercentage = 0;
volatile int g_mxc_touch_triggered = 1; //gallen 100420
int g_wakeup_by_alarm;
int gWifiEnabled=0;
static unsigned long g_usb_in_tick; // Joseph 101001
static int g_ioctl_SD_status, g_ioctl_USB_status, g_ioctl_rotary_status,g_Cus_Ctrl_Led;
static unsigned gw_gpio_wifi_rst = GPIO_WIFI_RST;
int g_mmc_card_detect_changed; // Joseph 20110125
static DEFINE_SPINLOCK(led_flash_lock);
static DECLARE_WAIT_QUEUE_HEAD(LED_blink_WaitQueue);
static DECLARE_WAIT_QUEUE_HEAD(LED_freeze_WaitQueue);
static DECLARE_WAIT_QUEUE_HEAD(WheelKey_WaitQueue);
////////////////////
static DECLARE_WAIT_QUEUE_HEAD(Reset_WaitQueue);
extern int gIsCustomerUi;
extern void gpio_sdhc_inactive(int module);
extern void gpio_uart_inactive(int port, int no_irda);
extern void mxc_mmc_force_detect(int id);
extern int get_FB_State();
extern void set_want_to_check_fb_state(int want_to_check);
extern iomux_v3_cfg_t mx50_sd1_enable_pads[6];
extern iomux_v3_cfg_t mx50_sd1_disable_pads[6];
extern unsigned mx50_sd1_gpioA[6];
extern iomux_v3_cfg_t mx50_sd3_hi4bits_disable_pads[];
extern unsigned long gdw_mx50_sd3_hi4bits_disable_pads;
extern iomux_v3_cfg_t mx50_sd3_hi4bits_enable_pads[];
extern unsigned long gdw_mx50_sd3_hi4bits_enable_pads;
extern iomux_v3_cfg_t mx50_sd3_disable_pads[];
extern unsigned long gdw_mx50_sd3_disable_pads;
extern iomux_v3_cfg_t mx50_sd3_enable_pads[];
extern unsigned long gdw_mx50_sd3_enable_pads;
extern unsigned mx50_sd3_gpioA[6];
extern unsigned mx50_sd3_hi4bits_gpioA[6];
extern iomux_v3_cfg_t mx50_sd2_disable_pads[];
extern unsigned long gdw_mx50_sd2_disable_pads;
int ntx_charge_status (void);
int ntx_get_battery_vol (void);
static struct timer_list power_key_timer;
extern void mxc_kpp_report_power(int isDown);
int g_pwr_key = 0;
static int my_fasync(int fd, struct file * filp, int on)
{
int retval;
//printk("pass signal to userspace!!\n");
retval=fasync_helper(fd,filp,on,&fasync_queue);
if(retval<0)
return retval;
return 0;
}
int my_release(struct inode *inode, struct file *filp)
{
my_fasync(-1, filp, 0);
}
//kay 20090925
//check WiFi ID
static int check_hardware_wifi(void)
{
return WIFI_NONE;
}
//check Bluetooth ID
static int check_hardware_bt(void)
{
return BLUETOOTH_NONE;
}
static int check_hardware_cpu(void)
{
return CPU_S3C2440;
}
//static int check_hardeare_name(void)
int check_hardware_name(void)
{
static int pcb_id = -1;
if (0 >= pcb_id) {
mxc_iomux_v3_setup_pad(MX50_PAD_UART3_TXD__GPIO_6_14);
mxc_iomux_v3_setup_pad(MX50_PAD_UART3_RXD__GPIO_6_15);
mxc_iomux_v3_setup_pad(MX50_PAD_UART4_RXD__GPIO_6_17);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_WP_HWID0__GPIO_5_16);
gpio_request(GPIO_HWID_1, "hwid_1");
gpio_direction_input (GPIO_HWID_1);
gpio_request(GPIO_HWID_2, "hwid_2");
gpio_direction_input (GPIO_HWID_2);
gpio_request(GPIO_HWID_3, "hwid_3");
gpio_direction_input (GPIO_HWID_3);
gpio_request(GPIO_HWID_4, "hwid_4");
gpio_direction_input (GPIO_HWID_4);
#if 0 //READ HW ID
/*
* Note:
* Comparing to the schematic diagram
* the lower 3 bits are in reversed order
* the higher (4th) bit is inverted (1 <-> 0)
* ** Noted by William Chen
*/
pcb_id = (gpio_get_value (GPIO_HWID_1)?1:0);
pcb_id |= (gpio_get_value (GPIO_HWID_2)?2:0);
pcb_id |= (gpio_get_value (GPIO_HWID_3)?4:0);
pcb_id |= (gpio_get_value (GPIO_HWID_4)?0:8);
if (7 == pcb_id)
pcb_id = 4;
#else //READ HWCONFIG
switch(gptHWCFG->m_val.bPCB)
{
case 12: //E60610
case 20: //E60610C
case 21: //E60610D
pcb_id = 1;
break;
case 15: //E60620
pcb_id = 4;
break;
case 16: //E60630
pcb_id = 6;
break;
case 18: //E50600
pcb_id = 2;
break;
case 19: //E60680
pcb_id = 3;
break;
case 22: //E606A0
pcb_id = 10;
break;
case 23: //E60670
pcb_id = 5;
break;
case 24: //E606B0
pcb_id = 14;
break;
case 27: //E50610
pcb_id = 9;
break;
case 28: //E606C0
pcb_id = 11;
break;
default:
pcb_id = gptHWCFG->m_val.bPCB;
// printk ("[%s-%d] undefined PCBA ID\n",__func__,__LINE__);
break;
}
#endif
printk ("[%s-%d] PCBA ID is %d\n",__func__,__LINE__,pcb_id);
}
return pcb_id;
}
EXPORT_SYMBOL(check_hardware_name);
int isInternalEmmc(void)
{
u32 reg;
void __iomem *src_base;
src_base = ioremap(MX53_BASE_ADDR(SRC_BASE_ADDR), PAGE_SIZE);
reg = __raw_readl(src_base + 0x4);
iounmap(src_base);
if ( reg & 0x20 ) printk("EMMC\n");
else printk("ISD\n");
return ( reg & 0x20 ) ? 1 : 0; //cfg1[5] == 1 means eMMC
}
EXPORT_SYMBOL(isInternalEmmc);
static int check_hardware_controller(void)
{
return CONTROLLER_EPSON;
}
static void collect_hardware_info(struct ebook_device_info *info)
{
info->cpu = check_hardware_cpu();
info->device_name = check_hardware_name();
info->controller = check_hardware_controller();
info->wifi = check_hardware_wifi();
info->bluetooth = check_hardware_bt();
}
static int openDriver(struct inode *inode,struct file *filp)
{
if(!Driver_Count)
Driver_Count++;
return 0;
}
static int releaseDriver(struct inode *inode,struct file *filp)
{
if(Driver_Count)
Driver_Count--;
my_release(inode,filp);
return 0;
}
static void bluetooth_reset(int i)
{
}
static void bluetooth_pwr(int i)
{
}
static void wifi_sdio_enable (int isEnable)
{
int iHWID;
iHWID=check_hardware_name();
if(9==iHWID || 11==iHWID || 35==gptHWCFG->m_val.bPCB ||41==iHWID) {
// E5061X/E606CX/E606FXB/E606G2
//
//printk("E50612=> %s(%d)\n",__FUNCTION__,isEnable);
if (isEnable) {
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_CLK__SD2_CLK_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_CMD__SD2_CMD_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_D0__SD2_D0_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_D1__SD2_D1_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_D2__SD2_D2_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD2_D3__SD2_D3_WIFI);
}
else {
mxc_iomux_v3_setup_multiple_pads(mx50_sd2_disable_pads, gdw_mx50_sd2_disable_pads);
}
}
else {
if (isEnable) {
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_CLK__SD3_CLK_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_CMD__SD3_CMD_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_D0__SD3_D0_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_D1__SD3_D1_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_D2__SD3_D2_WIFI);
mxc_iomux_v3_setup_pad(MX50_PAD_SD3_D3__SD3_D3_WIFI);
}
else {
mxc_iomux_v3_setup_multiple_pads(mx50_sd3_disable_pads, gdw_mx50_sd3_disable_pads);
}
}
}
//#define TIMEDOUT_WAITING_FOR_UPDATE_COMPLETION_WORK_ARROUND 1
extern int dvfs_core_is_active;
extern void stop_dvfs(void);
extern int start_dvfs(void);
void ntx_wifi_power_ctrl (int isWifiEnable)
{
int iHWID;
static int giRestore_DVFS_State=-1;
extern int mxc_epdc_fb_enable_reagl(int iIsEnable);
gWifiEnabled=isWifiEnable;
printk("Wifi / BT power control %d rst %d\n", isWifiEnable, gw_gpio_wifi_rst);
if(isWifiEnable == 0){
gpio_direction_input(GPIO_WIFI_3V3); // turn off Wifi_3V3_on
gpio_direction_output(gw_gpio_wifi_rst, 0); // turn on wifi_RST
wifi_sdio_enable (0);
#ifdef _WIFI_ALWAYS_ON_
disable_irq_wake(gpio_to_irq(GPIO_WIFI_INT));
#endif
#ifdef TIMEDOUT_WAITING_FOR_UPDATE_COMPLETION_WORK_ARROUND //[
if(1==giRestore_DVFS_State) {
printk("re-active dvfs while wifi disabled ...\n");
start_dvfs();
}
mxc_epdc_fb_enable_reagl(1);
#endif //]TIMEDOUT_WAITING_FOR_UPDATE_COMPLETION_WORK_ARROUND
}
else
{
#ifdef TIMEDOUT_WAITING_FOR_UPDATE_COMPLETION_WORK_ARROUND //[
mxc_epdc_fb_enable_reagl(0);
if(dvfs_core_is_active) {
printk("disable dvfs while wifi enabled ...\n");
stop_dvfs();
giRestore_DVFS_State=1;
}
else {
giRestore_DVFS_State=-1;
}
#endif //]TIMEDOUT_WAITING_FOR_UPDATE_COMPLETION_WORK_ARROUND
gpio_direction_output(GPIO_WIFI_3V3, 0); // turn on Wifi_3V3_on
sleep_on_timeout(&Reset_WaitQueue,HZ/50);
gpio_direction_output(gw_gpio_wifi_rst, 1); // turn on wifi_RST
wifi_sdio_enable (1);
#ifdef _WIFI_ALWAYS_ON_
enable_irq_wake(gpio_to_irq(GPIO_WIFI_INT));
#endif
}
sleep_on_timeout(&Reset_WaitQueue,HZ/10);
iHWID=check_hardware_name();
if(9==iHWID||11==iHWID||35==gptHWCFG->m_val.bPCB||41==iHWID) {
// E5061X/E606CX/E606FXB/E606G2
mxc_mmc_force_detect (1);
}
else {
mxc_mmc_force_detect (2);
}
schedule_timeout (500);
}
EXPORT_SYMBOL(ntx_wifi_power_ctrl);
extern u16 msp430_deviceid(void);
extern void msp430_poweroff(void);
extern void msp430_reset(void);
extern void msp430_powerkeep(int n);
extern int msp430_battery(void);
int msp430_check_wakeup(void);
int msp430_setwatchdog(int n);
extern int msp430_write(unsigned int reg, unsigned int value);
extern unsigned int msp430_read(unsigned int reg);
extern int mma7660_read_orient (void);
extern int mma7660_irqwake_enable (int iIsEnable);
int gTSC2004_exist; // Joseph 20100723
unsigned long gLastBatTick, gUSB_Change_Tick;
int gLastBatValue;
int g_power_key_debounce; // Joseph 20100921 for ESD
#if 1 // UPG
unsigned long long hwconfig = 0x0000000011000001LL;
EXPORT_SYMBOL(hwconfig);
unsigned char platform_type[32];
EXPORT_SYMBOL(platform_type);
static int __init early_hw(char *p)
{
hwconfig = simple_strtoull(p, NULL, 16);
printk("hwconfig: %16llX\n", hwconfig);
return 0;
}
early_param("hwconfig", early_hw);
//to parse hardware configuration bits
static int __init early_board(char *p)
{
strncpy(platform_type, p, sizeof(platform_type));
printk("board: %s\n", platform_type);
return 0;
}
early_param("board", early_board);
#endif
//Terry add 20121220 : save device state
static int g_device_state = UNSET;
void setDeviceState (int current_state) {
g_device_state = current_state;
}
int getDeviceState () {
return g_device_state;
}
static int ioctlDriver(struct inode *inode, struct file *filp, unsigned int command, unsigned long arg)
{
unsigned long i = 0, temp;
unsigned int p = arg;//*(unsigned int *)arg;
struct ebook_device_info info;
int FB_state = UNSET;
int want_to_check = UNSET;
int current_device_state = UNSET;
if(!Driver_Count){
printk("pvi_io : do not open\n");
return -1;
}
switch(command)
{
case POWER_OFF_COMMAND:
if (!gKeepPowerAlive) {
LED_conitnuous = 0;
gpio_set_value (GPIO_LED_ON,1);
while (1) {
printk("Kernel---Power Down ---\n");
msp430_poweroff();
sleep_on_timeout(&Reset_WaitQueue, 14*HZ/10);
}
}
else {
printk("Kernel---in keep alive mode ---\n");
}
break;
case SYS_RESET_COMMAND:
while (1) {
printk("Kernel---System reset ---\n");
gKeepPowerAlive = 0;
msp430_reset();
sleep_on_timeout(&Reset_WaitQueue, 14*HZ/10);
}
break;
case POWER_KEEP_COMMAND:
printk("Kernel---System Keep Alive --- %d\n",p);
gKeepPowerAlive=p;
if (gKeepPowerAlive) {
msp430_powerkeep(1);
wake_up_interruptible(&LED_freeze_WaitQueue);
}
else
msp430_powerkeep(0);
break;
case CM_GET_BATTERY_STATUS:
if (gUSB_Change_Tick) {
if (500 < (jiffies - gUSB_Change_Tick)) {
gUSB_Change_Tick = 0;
gLastBatValue = 0;
}
}
if ((6 == check_hardware_name()) || (2 == check_hardware_name())) { // E60632 || E50602
i = 1023;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
}
if (gIsMSP430IntTriggered || !gLastBatValue || ((0==gUSB_Change_Tick) && (time_after (jiffies, gLastBatTick)))) {
gLastBatTick = jiffies+200;
i = msp430_battery ();
if (i) {
temp = msp430_read (0x60);
if (0x8000 & temp) {
printk ("[%s-%d] =================> Micro P MSP430 alarm triggered <===================\n", __func__, __LINE__);
g_wakeup_by_alarm = 1;
}
if ((0x01 & temp) || (0x8000 & i)) {
printk ("[%s-%d] =================> Micro P MSP430 Critical_Battery_Low <===================\n", __func__, __LINE__);
i |= 0x8000;
gIsMSP430IntTriggered = 1;
}
else {
// printk ("[%s-%d] battery ===> %d\n", __func__, __LINE__,i);
if (!gLastBatValue)
gLastBatValue = i;
if (gpio_get_value (GPIO_ACIN_PG)) {// not charging
if (gLastBatValue > i)
gLastBatValue = i;
else
i = gLastBatValue;
}
else {
if (gLastBatValue < i)
gLastBatValue = i;
else
i = gLastBatValue;
}
}
}
else {
gLastBatTick = jiffies;
printk ("[%s-%d] MSP430 read failed\n", __func__, __LINE__);
i = 0x7FFF;
}
}
else
i = gLastBatValue;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case AC_IN:
i = gpio_get_value (GPIO_ACIN_PG)?0:1;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_SD_IN:
g_ioctl_SD_status = gpio_get_value (SD2_CD);
i = (g_ioctl_SD_status)?0:1;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_USB_Plug_IN:
g_ioctl_USB_status = gpio_get_value (GPIO_ACIN_PG);
#if 0
if (!g_ioctl_USB_status && g_usb_in_tick && (50 < (jiffies - g_usb_in_tick)))
g_ioctl_USB_status = 0;
else
g_ioctl_USB_status = 1;
#endif
i = (g_ioctl_USB_status)?0:1;
if (!g_Cus_Ctrl_Led)
gpio_set_value (GPIO_CHG_LED,g_ioctl_USB_status);
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case GET_LnBATT_CPU:
break;
case GET_VBATT_TH:
break;
case CM_AC_CK:
break;
case CM_CHARGE_STATUS:
i = ntx_charge_status();
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_PWR_ON2:
break;
case CM_AUDIO_PWR:
if (p) {
// Turn on audio power
// gpio_direction_output(GPIO_AUDIO_PWR, 0);
mxc_iomux_v3_setup_pad(MX50_PAD_PWM2__PWMO);
// gpio_activate_audio_ports(); // �|�y��IO REQUEST ERROR !?
}
else { // turn off audio power
mxc_iomux_v3_setup_pad(MX50_PAD_PWM2__GPIO_6_25);
// gpio_direction_input(GPIO_AUDIO_PWR);
// gpio_inactivate_audio_ports(); // �|�y��IO REQUEST ERROR !?
}
break;
case CM_nLED:
//printk("CM_nLED %d\n",p);
if (1 == check_hardware_name())
gpio_set_value (GPIO_LED_ON,p);
else
gpio_set_value (GPIO_ACT_ON,p);
break;
case CM_nLED_CPU:
break;
case CM_SD_PROTECT:
#if 1
i = 0;
#else
i = (gpio_get_value (SD2_WP))?1:0;
#endif
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_CONTROLLER:
i = 2; // 2: Epson controller. for micro window
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_USB_AC_STATUS:
i = 0;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_RTC_WAKEUP_FLAG:
if (!g_wakeup_by_alarm) {
int tmp = msp430_read (0x60);
if (0x8000 & tmp) {
printk ("[%s-%d] =================> Micro P MSP430 alarm triggered <===================\n", __func__, __LINE__);
g_wakeup_by_alarm = 1;
}
}
i = g_wakeup_by_alarm; // Joseph 091221 for slide show test.
if (g_wakeup_by_alarm) {
gIsMSP430IntTriggered = 0;
g_wakeup_by_alarm = 0;
}
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_SYSTEM_RESET:
printk("Kernel---System reset ---\n");
gKeepPowerAlive = 0;
msp430_reset();
break;
case CM_USB_HOST_PWR:
break;
case CM_BLUETOOTH_PWR:
ntx_wifi_power_ctrl (p);
break;
case CM_TELLPID:
if(p!=0){
printk("PID %d\n",p);
__EBRMAIN_PID__= p;
}
break;
case CM_LED_BLINK:
if (2==p) {
spin_lock(&led_flash_lock);
LED_Flash_Count++;
spin_unlock(&led_flash_lock);
}
if (!LED_conitnuous)
wake_up_interruptible(&LED_freeze_WaitQueue);
LED_conitnuous = p;
break;
case CM_TOUCH_LOCK:
if(p==0)
{
__TOUCH_LOCK__ = 0;
}else{
__TOUCH_LOCK__ = 1;
}
break;
case CM_DEVICE_MODULE:
i = check_hardware_name();
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_BLUETOOTH_RESET:
gpio_direction_output(gw_gpio_wifi_rst, 0); // WIFI_RST
sleep_on_timeout(&Reset_WaitQueue,HZ/100);
gpio_direction_output(gw_gpio_wifi_rst, 1);
mxc_mmc_force_detect (2);
schedule_timeout (500);
break;
case CM_DEVICE_INFO:
collect_hardware_info(&info);
copy_to_user((void __user *)arg, &info, sizeof(info));
break;
case CM_ROTARY_STATUS:
if (2==gptHWCFG->m_val.bRSensor) {
i = mma7660_read_orient ();
#if 0
if (2 == check_hardware_name()) {
if (5 == (++i))
i = 1;
}
else if (28 == gptHWCFG->m_val.bPCB) {
if (0 == (--i))
i = 4;
}
#endif
//printk("CM_ROTARY_STAUS=%d\n",i);
}
else
i = 0;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_ROTARY_ENABLE:
mma7660_irqwake_enable (p);
break;
case CM_GET_KEYS:
i = 0;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_POWER_BTN:
case CM_GET_KEY_STATUS:
if (gIsMSP430IntTriggered) {
if ((6 != check_hardware_name()) && (2 != check_hardware_name())) {
unsigned int tmp;
tmp = msp430_read (0x60);
// printk ("[%s-%d] Micro P MSP430 status 0x%04X ....\n", __func__, __LINE__,tmp);
if (0x8000 & tmp) {
printk ("[%s-%d] =================> Micro P MSP430 alarm triggered <===================\n", __func__, __LINE__);
g_wakeup_by_alarm = 1;
}
if (0x01 & tmp) {
printk ("[%s-%d] =================> Micro P MSP430 Critical_Battery_Low <===================\n", __func__, __LINE__);
gMxcPowerKeyIrqTriggered = 1;
g_power_key_debounce = 5; // Joseph 20100921 for ESD
g_power_key_pressed = 1;
gLastBatTick = jiffies;
}
else
gIsMSP430IntTriggered = 0;
}
}
if (g_power_key_pressed) {
g_power_key_pressed = 0;
i = 1;
}
else {
if ((6 == check_hardware_name()) || (2 == check_hardware_name())) // E60632 || E50602
i = (gpio_get_value (GPIO_PWR_SW))?1:0; // POWER key
else
i = (gpio_get_value (GPIO_PWR_SW))?0:1; // POWER key
if (i) {
if (2 >= g_power_key_debounce) { // Joseph 20100921 for ESD
printk ("[%s-%d] power key bounce detected %d\n",__func__,__LINE__, g_power_key_debounce);
i=0;
}
else {
gMxcPowerKeyIrqTriggered = 0;
}
}
else if (gMxcPowerKeyIrqTriggered) { // POWER key interrupt triggered.
if (2 < g_power_key_debounce) {
i = 1;
}
else
printk ("[%s-%d] power key bounce detected %d\n",__func__,__LINE__,g_power_key_debounce);
gMxcPowerKeyIrqTriggered = 0;
}
}
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
g_mxc_touch_triggered = 0;
break;
case CM_GET_WHEEL_KEY_STATUS:
i=0;
copy_to_user((void __user *)arg, &i, sizeof(unsigned long));
break;
case CM_3G_POWER:
break;
case CM_3G_RF_OFF: