-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathix_matrix_keybd.c
1140 lines (996 loc) · 31.2 KB
/
ix_matrix_keybd.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
/*
* linux/drivers/input/keyboard/pxa27x_keypad.c
*
* Driver for the pxa27x matrix keyboard controller.
*
* Created: Feb 22, 2007
* Author: Rodolfo Giometti <giometti@linux.it>
*
* Based on a previous implementations by Kevin O'Connor
* <kevin_at_koconnor.net> and Alex Osborne <bobofdoom@gmail.com> and
* on some suggestions by Nicolas Pitre <nico@cam.org>.
*
* 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.
*/
/*Variacion para Kira N7000 por mkpuig*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <mach/hardware.h>
#include <linux/gpio.h>
#include "ix_matrix_keybd.h"
#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off))
#define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off))
static int caps_locking = 0;
static spinlock_t *caps_spinlock = NULL;
int span_key_locking = 0;
EXPORT_SYMBOL(span_key_locking);
static int span_key_mark = 0;
static spinlock_t *span_key_spinlock = NULL;
int span2_key_locking = 0;
EXPORT_SYMBOL(span2_key_locking);
static int span2_key_mark = 0;
static spinlock_t *span2_key_spinlock = NULL;
bool init = false;
static int shift_pressing = 0;
static int leftshift_pressing = 0;
static int rightshift_pressing = 0;
static int leftalt_pressing = 0;
static int rightalt_pressing = 0;
static int shift_key_locking = 0;
static spinlock_t *shift_key_spinlock = NULL;
static int alt_key_locking = 0;
static spinlock_t *alt_key_spinlock = NULL;
static int left_alt_locking = 0;
static int right_alt_locking = 0;
extern int imap_timer_setup(int channel,unsigned long g_tcnt,unsigned long gtcmp);
//uncomendado
extern void gpio_switch_keybd_work(void);
extern int current_intensity;
volatile int flag_NUML = 0;
volatile int flag_fn = 0;
volatile int flag_CAPS=0;
volatile int flag_shift=0;
unsigned int keybd_cs;
unsigned int led_capslock;
unsigned int led_numlock;
struct key_flag {
int keycode;
int scancode;
int state;
};
static struct key_flag key_flags[] = {
{
.keycode = KEY_F1,
.scancode = KEY_VOLUMEUP,
},
{
.keycode = KEY_F2,
.scancode = KEY_VOLUMEDOWN,
},
{
.keycode = 86,
.scancode = KEY_SYSRQ,
},
{
.keycode = KEY_LEFT,
.scancode = KEY_HOME,
},
{
.keycode = KEY_RIGHT,
.scancode = KEY_END,
},
{
.keycode = KEY_7,
.scancode = KEY_7,
},
{
.keycode = KEY_8,
.scancode = KEY_8,
},
{
.keycode = KEY_9,
.scancode = KEY_9,
},
{
.keycode = KEY_0,
.scancode = KEY_KPSLASH,
},
{
.keycode = KEY_U,
.scancode = KEY_4,
},
{
.keycode = KEY_I,
.scancode = KEY_5,
},
{
.keycode = KEY_O,
.scancode = KEY_6,
},
{
.keycode = KEY_P,
.scancode = KEY_KPASTERISK,
},
{
.keycode = KEY_J,
.scancode = KEY_1,
},
{
.keycode = KEY_K,
.scancode = KEY_2,
},
{ .keycode = KEY_L,
.scancode = KEY_3,
},
{
.keycode = KEY_M,
.scancode = KEY_0,
},
{
.keycode = 39, //EÑE
.scancode = KEY_MINUS,
},
{
.keycode = KEY_DOT,
.scancode = KEY_DOT,
},
{
.keycode = 53,
.scancode = KEY_KPPLUS,
},
};
int keyinput_get_caps_locking_status(void)
{
int status = 0;
spin_lock(caps_spinlock);
status = caps_locking;
printk("keyinput_get_caps_locking_status is %d\n",caps_locking);
spin_unlock(caps_spinlock);
return status;
}
EXPORT_SYMBOL(keyinput_get_caps_locking_status);
int keyinput_get_span_key_locking_status(void)
{
int status = 0;
spin_lock(span_key_spinlock);
status = span_key_locking;
spin_unlock(span_key_spinlock);
return status;
}
EXPORT_SYMBOL(keyinput_get_span_key_locking_status);
void keyinput_clear_span_key_locking_status(void)
{
spin_lock(span_key_spinlock);
span_key_locking = 0;
spin_unlock(span_key_spinlock);
}
EXPORT_SYMBOL(keyinput_clear_span_key_locking_status);
int keyinput_get_span2_key_locking_status(void)
{
int status = 0;
spin_lock(span2_key_spinlock);
status = span2_key_locking;
spin_unlock(span2_key_spinlock);
return status;
}
EXPORT_SYMBOL(keyinput_get_span2_key_locking_status);
void keyinput_clear_span2_key_locking_status(void)
{
spin_lock(span2_key_spinlock);
span2_key_locking = 0;
spin_unlock(span2_key_spinlock);
}
EXPORT_SYMBOL(keyinput_clear_span2_key_locking_status);
int keyinput_get_key_shift_locking_status(void)
{
int status = 0;
spin_lock(shift_key_spinlock);
status = shift_key_locking;
spin_unlock(shift_key_spinlock);
return status;
}
EXPORT_SYMBOL(keyinput_get_key_shift_locking_status);
int keyinput_get_key_alt_locking_status(void)
{
int status = 0;
spin_lock(alt_key_spinlock);
status = alt_key_locking;
spin_unlock(alt_key_spinlock);
return status;
}
EXPORT_SYMBOL(keyinput_get_key_alt_locking_status);
struct imapx200_keybd{
struct imapx200_keybd_platform_data *pdata;
struct input_dev *input_dev;
struct clk *clk;
void __iomem *mmio_base;
int irq;
unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM];
unsigned int matrix_key_state[MAX_MATRIX_KEY_ROWS];
int suspend;
};
int keyinput_enable_matrix_keyboard(void)
{
imapx_gpio_setpin(keybd_cs, 0, IG_NORMAL);
return;
}
EXPORT_SYMBOL(keyinput_enable_matrix_keyboard);
int keyinput_disable_matrix_keyboard(void)
{
imapx_gpio_setpin(keybd_cs, 1, IG_NORMAL);
return;
}
EXPORT_SYMBOL(keyinput_disable_matrix_keyboard);
static void imapx200_keybd_build_keycode(struct imapx200_keybd *keypad)
{
struct imapx200_keybd_platform_data *pdata = keypad->pdata;
struct input_dev *input_dev = keypad->input_dev;
unsigned int *key;
int i;
key = &pdata->matrix_key_map[0];
for (i = 0; i < pdata->matrix_key_map_size; i++, key++) {
int row = ((*key) >> 24) & 0xff;
int col = ((*key) >> 20) & 0xf;
int code = (*key) & 0xfffff;
keypad->matrix_keycodes[(row << 3) + col] = code;
//uncomentado
// printk("scancode...row:%x,col:%x....keycode:%x\r\n",row,col,code);
set_bit(code, input_dev->keybit);
}
}
static inline unsigned int lookup_matrix_keycode(
struct imapx200_keybd *keypad, int row, int col)
{
return keypad->matrix_keycodes[(row << 3) + col];
}
static void imapx200_keybd_scan_matrix(struct imapx200_keybd *keypad)
{
struct imapx200_keybd_platform_data *pdata = keypad->pdata;
int iRow, iCol;
uint32_t kbRowData[MAX_MATRIX_KEY_ROWS];
volatile int key;
int intensity;
int index = 0;
memset(kbRowData, 0, sizeof(kbRowData));
kbRowData[0] = keypad_readl(rKBROWD0) & 0xff;
kbRowData[1] = (keypad_readl(rKBROWD0) & (0xff<<8))>>8;
kbRowData[2] = (keypad_readl(rKBROWD0) & (0xff<<16))>>16;
kbRowData[3] = (keypad_readl(rKBROWD0) & (0xff<<24))>>24;
kbRowData[4] = keypad_readl(rKBROWD1) & 0xff;
kbRowData[5] = (keypad_readl(rKBROWD1) & (0xff<<8))>>8;
kbRowData[6] = (keypad_readl(rKBROWD1) & (0xff<<16))>>16;
kbRowData[7] = (keypad_readl(rKBROWD1) & (0xff<<24))>>24;
kbRowData[8] = keypad_readl(rKBROWD2) & 0xff;
kbRowData[9] = (keypad_readl(rKBROWD2) & (0xff<<8))>>8;
kbRowData[10] = (keypad_readl(rKBROWD2) & (0xff<<16))>>16;
kbRowData[11] = (keypad_readl(rKBROWD2) & (0xff<<24))>>24;
kbRowData[12] = keypad_readl(rKBROWD3) & 0xff;
kbRowData[13] = (keypad_readl(rKBROWD3) & (0xff<<8))>>8;
kbRowData[14] = (keypad_readl(rKBROWD3) & (0xff<<16))>>16;
kbRowData[15] = (keypad_readl(rKBROWD3) & (0xff<<24))>>24;
kbRowData[16] = keypad_readl(rKBROWD4) & 0xff;
kbRowData[17] = (keypad_readl(rKBROWD4) & (0xff<<8))>>8;
for (iRow = 0; iRow < pdata->matrix_key_rows; iRow++)
{
uint32_t bits_changed;
bits_changed = keypad->matrix_key_state[iRow] ^ kbRowData[iRow];
if (bits_changed == 0)
continue;
for (iCol = 0; iCol < pdata->matrix_key_cols; iCol++)
{
if ((bits_changed & (1 << iCol)) == 0)
continue;
key =lookup_matrix_keycode(keypad, iRow, iCol);
//KEL UNCOMMENT
//printk(" R:%d C:%d, K:%d ",iRow,iCol,key);
//KEL UNCOMMENT_END
if (key == KEY_FN)
{
flag_fn++;
if (flag_fn == 3) {
for (index = 0;index < sizeof(key_flags)/sizeof(key_flags[0]);index ++)
if (key_flags[index].state) {
key_flags[index].state = 0;
input_report_key(keypad->input_dev, key_flags[index].scancode, 0);
}
}
if( flag_fn == 3)
flag_fn = 1;
//printk("...................flag_fn is ok...............\n");
}
//printk("....................KEY_FN is %d...................\n",flag_fn);
if (!(kbRowData[iRow] & (1 << iCol)) && (key == KEY_CAPSLOCK)) {
spin_lock(caps_spinlock);
if (caps_locking) {
caps_locking = 0;
//printk(KERN_ALERT "Capslock is disabled.\n");
} else {
caps_locking = 1;
//printk(KERN_ALERT "Capslock is enabled.\n");
}
spin_unlock(caps_spinlock);
}
if(key == KEY_CAPSLOCK)
{
flag_CAPS++;
if(flag_CAPS==2)
{
flag_CAPS=0;
imapx_gpio_setpin(led_capslock,
!imapx_gpio_getpin(led_capslock, IG_NORMAL), IG_NORMAL);
}
}
if (key == KEY_LEFTSHIFT) {
if (!(kbRowData[iRow] & (1 << iCol))) {
leftshift_pressing = 1;
} else {
leftshift_pressing = 0;
}
}
if (key == KEY_RIGHTSHIFT) {
if (!(kbRowData[iRow] & (1 << iCol))) {
rightshift_pressing = 1;
} else {
rightshift_pressing = 0;
}
}
if (key == KEY_LEFTALT) {
if (!(kbRowData[iRow] & (1 << iCol))) {
leftalt_pressing = 1;
} else {
leftalt_pressing = 0;
}
}
if (key == KEY_RIGHTALT) {
if (!(kbRowData[iRow] & (1 << iCol))) {
rightalt_pressing = 1;
} else {
rightalt_pressing = 0;
}
}
if (key == KEY_LEFTSHIFT || key == KEY_RIGHTSHIFT) {
spin_lock(shift_key_spinlock);
if (leftshift_pressing || rightshift_pressing) {
shift_key_locking = 1;
} else if (shift_key_locking) {
shift_key_locking = 0;
}
spin_unlock(shift_key_spinlock);
}
if (key == KEY_LEFTALT ||key == KEY_RIGHTALT) {
spin_lock(alt_key_spinlock);
if (rightalt_pressing || leftalt_pressing) {
alt_key_locking = 1;
} else if (alt_key_locking) {
alt_key_locking = 0;
}
spin_unlock(alt_key_spinlock);
}
/* KEY_APOSTROPHE is used to do spankey status record. */
/* if (key == KEY_F17) {
if (!(kbRowData[iRow] & (1 << iCol))) {
spin_lock(span_key_spinlock);
span2_key_locking = 0;
if (span_key_locking) {
span_key_locking = 0;
spin_unlock(span_key_spinlock);
input_report_key(keypad->input_dev,span_key_mark,1);
input_report_key(keypad->input_dev,span_key_mark,0);
} else {
if (leftalt_pressing || rightalt_pressing) {
spin_unlock(span_key_spinlock);
input_report_key(keypad->input_dev,KEY_F17,1);
input_report_key(keypad->input_dev,KEY_F17,0);
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
}
if (leftshift_pressing || rightshift_pressing) {
span_key_mark = KEY_F19;
span_key_locking = 2;
} else {
span_key_mark = KEY_F17;
span_key_locking = 1;
}
spin_unlock(span_key_spinlock);
}
}
if (init) {
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
}
}
if (key == KEY_GRAVE) {
if (!(kbRowData[iRow] & (1 << iCol))) {
spin_lock(span2_key_spinlock);
span_key_locking = 0;
if (span2_key_locking) {
span2_key_locking = 0;
spin_unlock(span2_key_spinlock);
input_report_key(keypad->input_dev,span2_key_mark,1);
input_report_key(keypad->input_dev,span2_key_mark,0);
} else {
if (leftalt_pressing || rightalt_pressing) {
spin_unlock(span2_key_spinlock);
input_report_key(keypad->input_dev,KEY_GRAVE,1);
input_report_key(keypad->input_dev,KEY_GRAVE,0);
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
}
if (leftshift_pressing || rightshift_pressing) {
span2_key_mark = KEY_F20;
span2_key_locking = 2;
} else {
span2_key_mark = KEY_GRAVE;
span2_key_locking = 1;
}
spin_unlock(span2_key_spinlock);
}
}
if (init) {
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
}
}*/
//printk("span_key_locking is %d\n",span_key_locking);
/* This part of code is without lock protection but nothing matters. */
/* if (!(kbRowData[iRow] & (1 << iCol)) && (key != KEY_F17) ) {
if (span_key_locking) {
switch (key) {
case KEY_A:
case KEY_E:
case KEY_I:
case KEY_O:
case KEY_U:
case KEY_LEFTSHIFT:
case KEY_RIGHTSHIFT:
case KEY_LEFTALT:
case KEY_RIGHTALT:
case KEY_CAPSLOCK:
case KEY_ENTER:
case KEY_BACKSPACE:
case KEY_ESC:
case KEY_LEFTCTRL:
case KEY_RIGHTCTRL:
case KEY_MENU:
case KEY_HOME:
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
case KEY_F1:
case KEY_F2:
case KEY_F3:
case KEY_F4:
case KEY_F5:
case KEY_F6:
case KEY_F7:
case KEY_F8:
case KEY_F9:
case KEY_F10:
case KEY_F11:
case KEY_F12:
case KEY_VOLUMEDOWN:
case KEY_VOLUMEUP:
case KEY_NUMLOCK:
case KEY_DELETE:
case KEY_END:
break;
case KEY_SPACE:
input_report_key(keypad->input_dev,span_key_mark,1);
input_report_key(keypad->input_dev,span_key_mark,0);
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
default:
input_report_key(keypad->input_dev,span_key_mark,1);
input_report_key(keypad->input_dev,span_key_mark,0);
break;
}
}
if (span2_key_locking) {
switch (key) {
case KEY_A:
case KEY_E:
case KEY_I:
case KEY_O:
case KEY_U:
case KEY_LEFTSHIFT:
case KEY_RIGHTSHIFT:
case KEY_LEFTALT:
case KEY_RIGHTALT:
case KEY_CAPSLOCK:
case KEY_ENTER:
case KEY_BACKSPACE:
case KEY_ESC:
case KEY_LEFTCTRL:
case KEY_RIGHTCTRL:
case KEY_MENU:
case KEY_HOME:
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
case KEY_F1:
case KEY_F2:
case KEY_F3:
case KEY_F4:
case KEY_F5:
case KEY_F6:
case KEY_F7:
case KEY_F8:
case KEY_F9:
case KEY_F10:
case KEY_F11:
case KEY_F12:
case KEY_VOLUMEDOWN:
case KEY_VOLUMEUP:
case KEY_NUMLOCK:
case KEY_DELETE:
case KEY_END:
break;
case KEY_SPACE:
input_report_key(keypad->input_dev,span2_key_mark,1);
input_report_key(keypad->input_dev,span2_key_mark,0);
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
return;
default:
input_report_key(keypad->input_dev,span2_key_mark,1);
input_report_key(keypad->input_dev,span2_key_mark,0);
break;
}
}
}*/
//printk(".....................KEY_shift is %d...................\n",flag_shift);
if(key == KEY_LEFTSHIFT||key == KEY_RIGHTSHIFT)
{
flag_shift++;
if(flag_shift==4)
flag_shift=2;
}
//printk("....................KEY_CAPSLOCK is %d...................\n",flag_CAPS);
//printk(".....................KEY_shift is %d...................\n",flag_shift);
if (flag_fn == 2)
{
for (index = 0; index < sizeof(key_flags) / sizeof(key_flags[0]); index++) {
if (key_flags[index].keycode == key) {
if (key_flags[index].state)
key_flags[index].state = 0;
else
key_flags[index].state = 1;
input_report_key(keypad->input_dev, key_flags[index].scancode,
!(kbRowData[iRow] & (1 << iCol)));
}
}
if (key == KEY_F11)
if(!(kbRowData[iRow] & (1 << iCol)))
{
if(flag_NUML)
flag_NUML = 0;
else
flag_NUML = 1;
input_report_key(keypad->input_dev,KEY_NUMLOCK,
!(kbRowData[iRow] & (1 << iCol)));
imapx_gpio_setpin(led_numlock,
!imapx_gpio_getpin(led_numlock, IG_NORMAL), IG_NORMAL);
}
}
if (flag_NUML == 1)
{
//printk("NumLock is set!\r\n");
if (flag_fn!=2) {
switch( key )
{
case KEY_7:
input_report_key(keypad->input_dev,KEY_KP7,
!(kbRowData[iRow] & (1 << iCol)));
//printk(".....................!(kbRowData[iRow] & (1 << iCol)) is %d.....................\n",!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_8:
input_report_key(keypad->input_dev,KEY_KP8,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_9:
input_report_key(keypad->input_dev,KEY_KP9,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_0:
input_report_key(keypad->input_dev,KEY_KPSLASH,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_U:
input_report_key(keypad->input_dev,KEY_KP4,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_I:
input_report_key(keypad->input_dev,KEY_KP5,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_O:
input_report_key(keypad->input_dev,KEY_KP6,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_P:
input_report_key(keypad->input_dev,KEY_KPASTERISK,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_J:
input_report_key(keypad->input_dev,KEY_KP1,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_K:
input_report_key(keypad->input_dev,KEY_KP2,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_L:
input_report_key(keypad->input_dev,KEY_KP3,
!(kbRowData[iRow] & (1 << iCol)));
break;
case 39:
input_report_key(keypad->input_dev,KEY_KPMINUS,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_M:
input_report_key(keypad->input_dev,KEY_KP0,
!(kbRowData[iRow] & (1 << iCol)));
break;
case KEY_DOT:
input_report_key(keypad->input_dev,KEY_KPDOT,
!(kbRowData[iRow] & (1 << iCol)));
break;
case 53:
input_report_key(keypad->input_dev,KEY_F18,
!(kbRowData[iRow] & (1 << iCol)));
break;
default:
if(flag_fn!=2)
input_report_key(keypad->input_dev,
lookup_matrix_keycode(keypad, iRow, iCol),
!(kbRowData[iRow] & (1 << iCol)));
//printk("............3...................\n");
break;
}
}
}
if (key == KEY_LEFTALT){
if (!(kbRowData[iRow] & (1 << iCol)) == 1 ) {
left_alt_locking++;
} else {
left_alt_locking=0;
}
}
if (key == KEY_RIGHTALT){
if (!(kbRowData[iRow] & (1 << iCol)) == 1 )
right_alt_locking++;
else
right_alt_locking=0;
}
if((left_alt_locking!=0||right_alt_locking!=0)&&(key == KEY_LEFT||key == KEY_RIGHT))
//printk("....................alt_locking is ok\n");
;
else if (key == KEY_LEFTCTRL && !(kbRowData[iRow] & (1 << iCol)) == 1)
;
else if ((left_alt_locking!=0||right_alt_locking!=0)&&key == KEY_F1&&!(kbRowData[iRow] & (1 << iCol))) {
input_report_key(keypad->input_dev,KEY_LEFTALT,0);
input_report_key(keypad->input_dev,
lookup_matrix_keycode(keypad, iRow, iCol),
!(kbRowData[iRow] & (1 << iCol)));
} else
if(flag_NUML!=1&&flag_fn!=2)
{
input_report_key(keypad->input_dev,
lookup_matrix_keycode(keypad, iRow, iCol),
!(kbRowData[iRow] & (1 << iCol)));
}
}
}
init = true;
input_sync(keypad->input_dev);
memcpy(keypad->matrix_key_state, kbRowData, sizeof(kbRowData));
}
static irqreturn_t imapx200_keybd_irq_handler(int irq, void *dev_id)
{
struct imapx200_keybd *keypad = dev_id;
//clear keybd interrupt
keypad_writel(rKBINT , 0x1ffff);
while(1)
{
if(keypad_readl(rKBINT) == 0)
{
break;
}
else
{
keypad_writel(rKBINT , 0x1ffff);
}
}
imapx200_keybd_scan_matrix(keypad);
// //clear keybd interrupt
//uncomentado
keypad_writel(rKBINT , KBDCNT_DRDYINT);
return IRQ_HANDLED;
}
static int imapx200_keybd_open(struct input_dev *dev)
{
struct imapx200_keybd *keypad = input_get_drvdata(dev);
/* Enable unit clock */
clk_enable(keypad->clk);
/* enable matrix keys with automatic scan */
keypad_writel(rKBCKD , 1024);
keypad_writel(rKBDCNT , 100);
keypad_writel(rKBCOLD , 0);
keypad_writel(rKBRPTC , 1024*6);
keypad_writel(rKBCON , (KBCON_RPTEN |KBCON_FCEN| KBCON_DFEN | KBCON_DRDYINTEN));
keypad_writel(rKBCOEN , (KBCOEN_COLNUM | KBCOEN_COLOEN));
//clear keybd interrupt
keypad_writel(rKBINT , 0x1ffff);
while(1)
{
if(keypad_readl(rKBINT) == 0)
{
break;
}
else
{
keypad_writel(rKBINT , 0x1ffff);
}
}
return 0;
}
static void imapx200_keybd_close(struct input_dev *dev)
{
struct imapx200_keybd *keypad = input_get_drvdata(dev);
/* Disable clock unit */
clk_disable(keypad->clk);
}
//#ifdef CONFIG_PM
#if 0
static int imapx200_keybd_suspend(struct platform_device *pdev, pm_message_t state)
{
struct imapx200_keybd *keypad = platform_get_drvdata(pdev);
clk_disable(keypad->clk);
if (device_may_wakeup(&pdev->dev))
enable_irq_wake(keypad->irq);
return 0;
}
static int imapx200_keybd_resume(struct platform_device *pdev)
{
struct imapx200_keybd *keypad = platform_get_drvdata(pdev);
struct input_dev *input_dev = keypad->input_dev;
if (device_may_wakeup(&pdev->dev))
disable_irq_wake(keypad->irq);
mutex_lock(&input_dev->mutex);
if (input_dev->users) {
/* Enable unit clock */
clk_enable(keypad->clk);
pxa27x_keypad_config(keypad);
}
mutex_unlock(&input_dev->mutex);
return 0;
}
#else
#define imapx200_keybd_suspend NULL
#define imapx200_keybd_resume NULL
#endif
#define res_size(res) ((res)->end - (res)->start + 1)
static int __devinit imapx200_keybd_probe(struct platform_device *pdev)
{
struct imapx200_keybd *keypad;
struct input_dev *input_dev;
struct resource *res;
int irq, error, i;
int gphcon, gpicon, gpjcon,gpocon,gpmcon,gplcon;
//keyboard enable/disable
keybd_cs = __imapx_name_to_gpio(CONFIG_KEYBOARD_MATRIX_CS);
if(keybd_cs == IMAPX_GPIO_ERROR) {
printk(KERN_ERR "failed to get keybd_cs pin.\n");
return -1;
}
imapx_gpio_setcfg(keybd_cs, IG_OUTPUT, IG_NORMAL);
//led_capslock control
led_capslock = __imapx_name_to_gpio(CONFIG_KEYBOARD_LED_CAPS);
if(led_capslock == IMAPX_GPIO_ERROR) {
printk(KERN_ERR "failed to get led_capslock pin.\n");
return -1;
}
imapx_gpio_setcfg(led_capslock, IG_OUTPUT, IG_NORMAL);
imapx_gpio_setpin(led_capslock, 0, IG_NORMAL);
//led_numlock control
led_numlock = __imapx_name_to_gpio(CONFIG_KEYBOARD_LED_NUML);
if(led_numlock == IMAPX_GPIO_ERROR) {
printk(KERN_ERR "failed to get led_numlock pin.\n");
return -1;
}
imapx_gpio_setcfg(led_numlock, IG_OUTPUT, IG_NORMAL);
imapx_gpio_setpin(led_numlock, 0, IG_NORMAL);
//config the GPIO port for keyboard
imapx_gpio_setcfg(IMAPX_GPH_RANGE(0,3), IG_CTRL1, IG_NORMAL);
imapx_gpio_setcfg(IMAPX_GPI_RANGE(0,13), IG_CTRL1, IG_NORMAL);
imapx_gpio_setcfg(IMAPX_GPJ_RANGE(0,8), IG_CTRL1, IG_NORMAL);
pdev->dev.platform_data = &imapx200_keybd_info;
keypad = kzalloc(sizeof(struct imapx200_keybd), GFP_KERNEL);
if (keypad == NULL) {
dev_err(&pdev->dev, "failed to allocate driver data\n");
return -ENOMEM;
}
keypad->pdata = pdev->dev.platform_data;
if (keypad->pdata == NULL) {
dev_err(&pdev->dev, "no platform data defined\n");
error = -EINVAL;
goto failed_free;
}
//uncomentado
memset(keypad->matrix_key_state,0,sizeof(keypad->matrix_key_state));
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_err(&pdev->dev, "failed to get keypad irq\n");
error = -ENXIO;
goto failed_free;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "failed to get I/O memory\n");
error = -ENXIO;
goto failed_free;
}
res = request_mem_region(res->start, res_size(res), pdev->name);
if (res == NULL) {
dev_err(&pdev->dev, "failed to request I/O memory\n");
error = -EBUSY;
goto failed_free;
}
keypad->mmio_base = ioremap(res->start, res_size(res));
if (keypad->mmio_base == NULL) {
dev_err(&pdev->dev, "failed to remap I/O memory\n");
error = -ENXIO;
goto failed_free_mem;
}
keypad->clk = clk_get(&pdev->dev, "kb");
if (IS_ERR(keypad->clk)) {
dev_err(&pdev->dev, "failed to get keypad clock\n");
error = PTR_ERR(keypad->clk);
goto failed_free_io;
}
if (caps_spinlock == NULL) {
caps_spinlock = (spinlock_t *)kmalloc(sizeof(spinlock_t), GFP_KERNEL);
if (caps_spinlock == NULL) {
printk(KERN_ERR "kmalloc() for capslock key spinlock error.\n");
return -1;
}
spin_lock_init(caps_spinlock);
}
if (span_key_spinlock == NULL) {
span_key_spinlock = (spinlock_t *)kmalloc(sizeof(spinlock_t), GFP_KERNEL);
if (span_key_spinlock == NULL) {
printk(KERN_ERR "kmalloc() for span key spinlock error.\n");
return -1;
}
spin_lock_init(span_key_spinlock);
}