forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.c
1739 lines (1488 loc) · 45.4 KB
/
panel.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
// SPDX-License-Identifier: GPL-2.0+
/*
* Front panel driver for Linux
* Copyright (C) 2000-2008, Willy Tarreau <[email protected]>
* Copyright (C) 2016-2017 Glider bvba
*
* This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
* connected to a parallel printer port.
*
* The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
* serial module compatible with Samsung's KS0074. The pins may be connected in
* any combination, everything is programmable.
*
* The keypad consists in a matrix of push buttons connecting input pins to
* data output pins or to the ground. The combinations have to be hard-coded
* in the driver, though several profiles exist and adding new ones is easy.
*
* Several profiles are provided for commonly found LCD+keypad modules on the
* market, such as those found in Nexcom's appliances.
*
* FIXME:
* - the initialization/deinitialization process is very dirty and should
* be rewritten. It may even be buggy.
*
* TODO:
* - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
* - make the LCD a part of a virtual screen of Vx*Vy
* - make the inputs list smp-safe
* - change the keyboard to a double mapping : signals -> key_id -> values
* so that applications can change values without knowing signals
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/ctype.h>
#include <linux/parport.h>
#include <linux/list.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include "charlcd.h"
#include "hd44780_common.h"
#define LCD_MAXBYTES 256 /* max burst write */
#define KEYPAD_BUFFER 64
/* poll the keyboard this every second */
#define INPUT_POLL_TIME (HZ / 50)
/* a key starts to repeat after this times INPUT_POLL_TIME */
#define KEYPAD_REP_START (10)
/* a key repeats this times INPUT_POLL_TIME */
#define KEYPAD_REP_DELAY (2)
/* converts an r_str() input to an active high, bits string : 000BAOSE */
#define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
#define PNL_PBUSY 0x80 /* inverted input, active low */
#define PNL_PACK 0x40 /* direct input, active low */
#define PNL_POUTPA 0x20 /* direct input, active high */
#define PNL_PSELECD 0x10 /* direct input, active high */
#define PNL_PERRORP 0x08 /* direct input, active low */
#define PNL_PBIDIR 0x20 /* bi-directional ports */
/* high to read data in or-ed with data out */
#define PNL_PINTEN 0x10
#define PNL_PSELECP 0x08 /* inverted output, active low */
#define PNL_PINITP 0x04 /* direct output, active low */
#define PNL_PAUTOLF 0x02 /* inverted output, active low */
#define PNL_PSTROBE 0x01 /* inverted output */
#define PNL_PD0 0x01
#define PNL_PD1 0x02
#define PNL_PD2 0x04
#define PNL_PD3 0x08
#define PNL_PD4 0x10
#define PNL_PD5 0x20
#define PNL_PD6 0x40
#define PNL_PD7 0x80
#define PIN_NONE 0
#define PIN_STROBE 1
#define PIN_D0 2
#define PIN_D1 3
#define PIN_D2 4
#define PIN_D3 5
#define PIN_D4 6
#define PIN_D5 7
#define PIN_D6 8
#define PIN_D7 9
#define PIN_AUTOLF 14
#define PIN_INITP 16
#define PIN_SELECP 17
#define PIN_NOT_SET 127
#define NOT_SET -1
/* macros to simplify use of the parallel port */
#define r_ctr(x) (parport_read_control((x)->port))
#define r_dtr(x) (parport_read_data((x)->port))
#define r_str(x) (parport_read_status((x)->port))
#define w_ctr(x, y) (parport_write_control((x)->port, (y)))
#define w_dtr(x, y) (parport_write_data((x)->port, (y)))
/* this defines which bits are to be used and which ones to be ignored */
/* logical or of the output bits involved in the scan matrix */
static __u8 scan_mask_o;
/* logical or of the input bits involved in the scan matrix */
static __u8 scan_mask_i;
enum input_type {
INPUT_TYPE_STD,
INPUT_TYPE_KBD,
};
enum input_state {
INPUT_ST_LOW,
INPUT_ST_RISING,
INPUT_ST_HIGH,
INPUT_ST_FALLING,
};
struct logical_input {
struct list_head list;
__u64 mask;
__u64 value;
enum input_type type;
enum input_state state;
__u8 rise_time, fall_time;
__u8 rise_timer, fall_timer, high_timer;
union {
struct { /* valid when type == INPUT_TYPE_STD */
void (*press_fct)(int);
void (*release_fct)(int);
int press_data;
int release_data;
} std;
struct { /* valid when type == INPUT_TYPE_KBD */
char press_str[sizeof(void *) + sizeof(int)] __nonstring;
char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
char release_str[sizeof(void *) + sizeof(int)] __nonstring;
} kbd;
} u;
};
static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
/* physical contacts history
* Physical contacts are a 45 bits string of 9 groups of 5 bits each.
* The 8 lower groups correspond to output bits 0 to 7, and the 9th group
* corresponds to the ground.
* Within each group, bits are stored in the same order as read on the port :
* BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
* So, each __u64 is represented like this :
* 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
* <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
*/
/* what has just been read from the I/O ports */
static __u64 phys_read;
/* previous phys_read */
static __u64 phys_read_prev;
/* stabilized phys_read (phys_read|phys_read_prev) */
static __u64 phys_curr;
/* previous phys_curr */
static __u64 phys_prev;
/* 0 means that at least one logical signal needs be computed */
static char inputs_stable;
/* these variables are specific to the keypad */
static struct {
bool enabled;
} keypad;
static char keypad_buffer[KEYPAD_BUFFER];
static int keypad_buflen;
static int keypad_start;
static char keypressed;
static wait_queue_head_t keypad_read_wait;
/* lcd-specific variables */
static struct {
bool enabled;
bool initialized;
int charset;
int proto;
/* TODO: use union here? */
struct {
int e;
int rs;
int rw;
int cl;
int da;
int bl;
} pins;
struct charlcd *charlcd;
} lcd;
/* Needed only for init */
static int selected_lcd_type = NOT_SET;
/*
* Bit masks to convert LCD signals to parallel port outputs.
* _d_ are values for data port, _c_ are for control port.
* [0] = signal OFF, [1] = signal ON, [2] = mask
*/
#define BIT_CLR 0
#define BIT_SET 1
#define BIT_MSK 2
#define BIT_STATES 3
/*
* one entry for each bit on the LCD
*/
#define LCD_BIT_E 0
#define LCD_BIT_RS 1
#define LCD_BIT_RW 2
#define LCD_BIT_BL 3
#define LCD_BIT_CL 4
#define LCD_BIT_DA 5
#define LCD_BITS 6
/*
* each bit can be either connected to a DATA or CTRL port
*/
#define LCD_PORT_C 0
#define LCD_PORT_D 1
#define LCD_PORTS 2
static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
/*
* LCD protocols
*/
#define LCD_PROTO_PARALLEL 0
#define LCD_PROTO_SERIAL 1
#define LCD_PROTO_TI_DA8XX_LCD 2
/*
* LCD character sets
*/
#define LCD_CHARSET_NORMAL 0
#define LCD_CHARSET_KS0074 1
/*
* LCD types
*/
#define LCD_TYPE_NONE 0
#define LCD_TYPE_CUSTOM 1
#define LCD_TYPE_OLD 2
#define LCD_TYPE_KS0074 3
#define LCD_TYPE_HANTRONIX 4
#define LCD_TYPE_NEXCOM 5
/*
* keypad types
*/
#define KEYPAD_TYPE_NONE 0
#define KEYPAD_TYPE_OLD 1
#define KEYPAD_TYPE_NEW 2
#define KEYPAD_TYPE_NEXCOM 3
/*
* panel profiles
*/
#define PANEL_PROFILE_CUSTOM 0
#define PANEL_PROFILE_OLD 1
#define PANEL_PROFILE_NEW 2
#define PANEL_PROFILE_HANTRONIX 3
#define PANEL_PROFILE_NEXCOM 4
#define PANEL_PROFILE_LARGE 5
/*
* Construct custom config from the kernel's configuration
*/
#define DEFAULT_PARPORT 0
#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
#define DEFAULT_LCD_HEIGHT 2
#define DEFAULT_LCD_WIDTH 40
#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
#define DEFAULT_LCD_PIN_E PIN_AUTOLF
#define DEFAULT_LCD_PIN_RS PIN_SELECP
#define DEFAULT_LCD_PIN_RW PIN_INITP
#define DEFAULT_LCD_PIN_SCL PIN_STROBE
#define DEFAULT_LCD_PIN_SDA PIN_D0
#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
#ifdef CONFIG_PANEL_PARPORT
#undef DEFAULT_PARPORT
#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
#endif
#ifdef CONFIG_PANEL_PROFILE
#undef DEFAULT_PROFILE
#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
#endif
#if DEFAULT_PROFILE == 0 /* custom */
#ifdef CONFIG_PANEL_KEYPAD
#undef DEFAULT_KEYPAD_TYPE
#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
#endif
#ifdef CONFIG_PANEL_LCD
#undef DEFAULT_LCD_TYPE
#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
#endif
#ifdef CONFIG_PANEL_LCD_HEIGHT
#undef DEFAULT_LCD_HEIGHT
#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
#endif
#ifdef CONFIG_PANEL_LCD_WIDTH
#undef DEFAULT_LCD_WIDTH
#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
#endif
#ifdef CONFIG_PANEL_LCD_BWIDTH
#undef DEFAULT_LCD_BWIDTH
#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
#endif
#ifdef CONFIG_PANEL_LCD_HWIDTH
#undef DEFAULT_LCD_HWIDTH
#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
#endif
#ifdef CONFIG_PANEL_LCD_CHARSET
#undef DEFAULT_LCD_CHARSET
#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
#endif
#ifdef CONFIG_PANEL_LCD_PROTO
#undef DEFAULT_LCD_PROTO
#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
#endif
#ifdef CONFIG_PANEL_LCD_PIN_E
#undef DEFAULT_LCD_PIN_E
#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
#endif
#ifdef CONFIG_PANEL_LCD_PIN_RS
#undef DEFAULT_LCD_PIN_RS
#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
#endif
#ifdef CONFIG_PANEL_LCD_PIN_RW
#undef DEFAULT_LCD_PIN_RW
#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
#endif
#ifdef CONFIG_PANEL_LCD_PIN_SCL
#undef DEFAULT_LCD_PIN_SCL
#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
#endif
#ifdef CONFIG_PANEL_LCD_PIN_SDA
#undef DEFAULT_LCD_PIN_SDA
#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
#endif
#ifdef CONFIG_PANEL_LCD_PIN_BL
#undef DEFAULT_LCD_PIN_BL
#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
#endif
#endif /* DEFAULT_PROFILE == 0 */
/* global variables */
/* Device single-open policy control */
static atomic_t keypad_available = ATOMIC_INIT(1);
static struct pardevice *pprt;
static int keypad_initialized;
static DEFINE_SPINLOCK(pprt_lock);
static struct timer_list scan_timer;
MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
static int parport = DEFAULT_PARPORT;
module_param(parport, int, 0000);
MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
static int profile = DEFAULT_PROFILE;
module_param(profile, int, 0000);
MODULE_PARM_DESC(profile,
"1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
"4=16x2 nexcom; default=40x2, old kp");
static int keypad_type = NOT_SET;
module_param(keypad_type, int, 0000);
MODULE_PARM_DESC(keypad_type,
"Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
static int lcd_type = NOT_SET;
module_param(lcd_type, int, 0000);
MODULE_PARM_DESC(lcd_type,
"LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
static int lcd_height = NOT_SET;
module_param(lcd_height, int, 0000);
MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
static int lcd_width = NOT_SET;
module_param(lcd_width, int, 0000);
MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
module_param(lcd_bwidth, int, 0000);
MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
module_param(lcd_hwidth, int, 0000);
MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
static int lcd_charset = NOT_SET;
module_param(lcd_charset, int, 0000);
MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
static int lcd_proto = NOT_SET;
module_param(lcd_proto, int, 0000);
MODULE_PARM_DESC(lcd_proto,
"LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
/*
* These are the parallel port pins the LCD control signals are connected to.
* Set this to 0 if the signal is not used. Set it to its opposite value
* (negative) if the signal is negated. -MAXINT is used to indicate that the
* pin has not been explicitly specified.
*
* WARNING! no check will be performed about collisions with keypad !
*/
static int lcd_e_pin = PIN_NOT_SET;
module_param(lcd_e_pin, int, 0000);
MODULE_PARM_DESC(lcd_e_pin,
"# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
static int lcd_rs_pin = PIN_NOT_SET;
module_param(lcd_rs_pin, int, 0000);
MODULE_PARM_DESC(lcd_rs_pin,
"# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
static int lcd_rw_pin = PIN_NOT_SET;
module_param(lcd_rw_pin, int, 0000);
MODULE_PARM_DESC(lcd_rw_pin,
"# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
static int lcd_cl_pin = PIN_NOT_SET;
module_param(lcd_cl_pin, int, 0000);
MODULE_PARM_DESC(lcd_cl_pin,
"# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
static int lcd_da_pin = PIN_NOT_SET;
module_param(lcd_da_pin, int, 0000);
MODULE_PARM_DESC(lcd_da_pin,
"# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
static int lcd_bl_pin = PIN_NOT_SET;
module_param(lcd_bl_pin, int, 0000);
MODULE_PARM_DESC(lcd_bl_pin,
"# of the // port pin connected to LCD backlight, with polarity (-17..17)");
/* Deprecated module parameters - consider not using them anymore */
static int lcd_enabled = NOT_SET;
module_param(lcd_enabled, int, 0000);
MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
static int keypad_enabled = NOT_SET;
module_param(keypad_enabled, int, 0000);
MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
/* for some LCD drivers (ks0074) we need a charset conversion table. */
static const unsigned char lcd_char_conv_ks0074[256] = {
/* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
/* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
/* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
/* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
/* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
/* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
/* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
/* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
/* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
/* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
/* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
/* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
/* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
/* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
/* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
/* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
/* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
/* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
/* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
/* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
/* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
/* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
/* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
/* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
/* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
/* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
/* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
/* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
/* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
/* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
/* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
/* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
/* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
};
static const char old_keypad_profile[][4][9] = {
{"S0", "Left\n", "Left\n", ""},
{"S1", "Down\n", "Down\n", ""},
{"S2", "Up\n", "Up\n", ""},
{"S3", "Right\n", "Right\n", ""},
{"S4", "Esc\n", "Esc\n", ""},
{"S5", "Ret\n", "Ret\n", ""},
{"", "", "", ""}
};
/* signals, press, repeat, release */
static const char new_keypad_profile[][4][9] = {
{"S0", "Left\n", "Left\n", ""},
{"S1", "Down\n", "Down\n", ""},
{"S2", "Up\n", "Up\n", ""},
{"S3", "Right\n", "Right\n", ""},
{"S4s5", "", "Esc\n", "Esc\n"},
{"s4S5", "", "Ret\n", "Ret\n"},
{"S4S5", "Help\n", "", ""},
/* add new signals above this line */
{"", "", "", ""}
};
/* signals, press, repeat, release */
static const char nexcom_keypad_profile[][4][9] = {
{"a-p-e-", "Down\n", "Down\n", ""},
{"a-p-E-", "Ret\n", "Ret\n", ""},
{"a-P-E-", "Esc\n", "Esc\n", ""},
{"a-P-e-", "Up\n", "Up\n", ""},
/* add new signals above this line */
{"", "", "", ""}
};
static const char (*keypad_profile)[4][9] = old_keypad_profile;
static DECLARE_BITMAP(bits, LCD_BITS);
static void lcd_get_bits(unsigned int port, int *val)
{
unsigned int bit, state;
for (bit = 0; bit < LCD_BITS; bit++) {
state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
*val &= lcd_bits[port][bit][BIT_MSK];
*val |= lcd_bits[port][bit][state];
}
}
/* sets data port bits according to current signals values */
static int set_data_bits(void)
{
int val;
val = r_dtr(pprt);
lcd_get_bits(LCD_PORT_D, &val);
w_dtr(pprt, val);
return val;
}
/* sets ctrl port bits according to current signals values */
static int set_ctrl_bits(void)
{
int val;
val = r_ctr(pprt);
lcd_get_bits(LCD_PORT_C, &val);
w_ctr(pprt, val);
return val;
}
/* sets ctrl & data port bits according to current signals values */
static void panel_set_bits(void)
{
set_data_bits();
set_ctrl_bits();
}
/*
* Converts a parallel port pin (from -25 to 25) to data and control ports
* masks, and data and control port bits. The signal will be considered
* unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
*
* Result will be used this way :
* out(dport, in(dport) & d_val[2] | d_val[signal_state])
* out(cport, in(cport) & c_val[2] | c_val[signal_state])
*/
static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
{
int d_bit, c_bit, inv;
d_val[0] = 0;
c_val[0] = 0;
d_val[1] = 0;
c_val[1] = 0;
d_val[2] = 0xFF;
c_val[2] = 0xFF;
if (pin == 0)
return;
inv = (pin < 0);
if (inv)
pin = -pin;
d_bit = 0;
c_bit = 0;
switch (pin) {
case PIN_STROBE: /* strobe, inverted */
c_bit = PNL_PSTROBE;
inv = !inv;
break;
case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
d_bit = 1 << (pin - 2);
break;
case PIN_AUTOLF: /* autofeed, inverted */
c_bit = PNL_PAUTOLF;
inv = !inv;
break;
case PIN_INITP: /* init, direct */
c_bit = PNL_PINITP;
break;
case PIN_SELECP: /* select_in, inverted */
c_bit = PNL_PSELECP;
inv = !inv;
break;
default: /* unknown pin, ignore */
break;
}
if (c_bit) {
c_val[2] &= ~c_bit;
c_val[!inv] = c_bit;
} else if (d_bit) {
d_val[2] &= ~d_bit;
d_val[!inv] = d_bit;
}
}
/*
* send a serial byte to the LCD panel. The caller is responsible for locking
* if needed.
*/
static void lcd_send_serial(int byte)
{
int bit;
/*
* the data bit is set on D0, and the clock on STROBE.
* LCD reads D0 on STROBE's rising edge.
*/
for (bit = 0; bit < 8; bit++) {
clear_bit(LCD_BIT_CL, bits); /* CLK low */
panel_set_bits();
if (byte & 1) {
set_bit(LCD_BIT_DA, bits);
} else {
clear_bit(LCD_BIT_DA, bits);
}
panel_set_bits();
udelay(2); /* maintain the data during 2 us before CLK up */
set_bit(LCD_BIT_CL, bits); /* CLK high */
panel_set_bits();
udelay(1); /* maintain the strobe during 1 us */
byte >>= 1;
}
}
/* turn the backlight on or off */
static void lcd_backlight(struct charlcd *charlcd, enum charlcd_onoff on)
{
if (lcd.pins.bl == PIN_NONE)
return;
/* The backlight is activated by setting the AUTOFEED line to +5V */
spin_lock_irq(&pprt_lock);
if (on)
set_bit(LCD_BIT_BL, bits);
else
clear_bit(LCD_BIT_BL, bits);
panel_set_bits();
spin_unlock_irq(&pprt_lock);
}
/* send a command to the LCD panel in serial mode */
static void lcd_write_cmd_s(struct hd44780_common *hdc, int cmd)
{
spin_lock_irq(&pprt_lock);
lcd_send_serial(0x1F); /* R/W=W, RS=0 */
lcd_send_serial(cmd & 0x0F);
lcd_send_serial((cmd >> 4) & 0x0F);
udelay(40); /* the shortest command takes at least 40 us */
spin_unlock_irq(&pprt_lock);
}
/* send data to the LCD panel in serial mode */
static void lcd_write_data_s(struct hd44780_common *hdc, int data)
{
spin_lock_irq(&pprt_lock);
lcd_send_serial(0x5F); /* R/W=W, RS=1 */
lcd_send_serial(data & 0x0F);
lcd_send_serial((data >> 4) & 0x0F);
udelay(40); /* the shortest data takes at least 40 us */
spin_unlock_irq(&pprt_lock);
}
/* send a command to the LCD panel in 8 bits parallel mode */
static void lcd_write_cmd_p8(struct hd44780_common *hdc, int cmd)
{
spin_lock_irq(&pprt_lock);
/* present the data to the data port */
w_dtr(pprt, cmd);
udelay(20); /* maintain the data during 20 us before the strobe */
set_bit(LCD_BIT_E, bits);
clear_bit(LCD_BIT_RS, bits);
clear_bit(LCD_BIT_RW, bits);
set_ctrl_bits();
udelay(40); /* maintain the strobe during 40 us */
clear_bit(LCD_BIT_E, bits);
set_ctrl_bits();
udelay(120); /* the shortest command takes at least 120 us */
spin_unlock_irq(&pprt_lock);
}
/* send data to the LCD panel in 8 bits parallel mode */
static void lcd_write_data_p8(struct hd44780_common *hdc, int data)
{
spin_lock_irq(&pprt_lock);
/* present the data to the data port */
w_dtr(pprt, data);
udelay(20); /* maintain the data during 20 us before the strobe */
set_bit(LCD_BIT_E, bits);
set_bit(LCD_BIT_RS, bits);
clear_bit(LCD_BIT_RW, bits);
set_ctrl_bits();
udelay(40); /* maintain the strobe during 40 us */
clear_bit(LCD_BIT_E, bits);
set_ctrl_bits();
udelay(45); /* the shortest data takes at least 45 us */
spin_unlock_irq(&pprt_lock);
}
/* send a command to the TI LCD panel */
static void lcd_write_cmd_tilcd(struct hd44780_common *hdc, int cmd)
{
spin_lock_irq(&pprt_lock);
/* present the data to the control port */
w_ctr(pprt, cmd);
udelay(60);
spin_unlock_irq(&pprt_lock);
}
/* send data to the TI LCD panel */
static void lcd_write_data_tilcd(struct hd44780_common *hdc, int data)
{
spin_lock_irq(&pprt_lock);
/* present the data to the data port */
w_dtr(pprt, data);
udelay(60);
spin_unlock_irq(&pprt_lock);
}
static const struct charlcd_ops charlcd_ops = {
.backlight = lcd_backlight,
.print = hd44780_common_print,
.gotoxy = hd44780_common_gotoxy,
.home = hd44780_common_home,
.clear_display = hd44780_common_clear_display,
.init_display = hd44780_common_init_display,
.shift_cursor = hd44780_common_shift_cursor,
.shift_display = hd44780_common_shift_display,
.display = hd44780_common_display,
.cursor = hd44780_common_cursor,
.blink = hd44780_common_blink,
.fontsize = hd44780_common_fontsize,
.lines = hd44780_common_lines,
.redefine_char = hd44780_common_redefine_char,
};
/* initialize the LCD driver */
static void lcd_init(void)
{
struct charlcd *charlcd;
struct hd44780_common *hdc;
hdc = hd44780_common_alloc();
if (!hdc)
return;
charlcd = charlcd_alloc();
if (!charlcd) {
kfree(hdc);
return;
}
hdc->hd44780 = &lcd;
charlcd->drvdata = hdc;
/*
* Init lcd struct with load-time values to preserve exact
* current functionality (at least for now).
*/
charlcd->height = lcd_height;
charlcd->width = lcd_width;
hdc->bwidth = lcd_bwidth;
hdc->hwidth = lcd_hwidth;
switch (selected_lcd_type) {
case LCD_TYPE_OLD:
/* parallel mode, 8 bits */
lcd.proto = LCD_PROTO_PARALLEL;
lcd.charset = LCD_CHARSET_NORMAL;
lcd.pins.e = PIN_STROBE;
lcd.pins.rs = PIN_AUTOLF;
charlcd->width = 40;
hdc->bwidth = 40;
hdc->hwidth = 64;
charlcd->height = 2;
break;
case LCD_TYPE_KS0074:
/* serial mode, ks0074 */
lcd.proto = LCD_PROTO_SERIAL;
lcd.charset = LCD_CHARSET_KS0074;
lcd.pins.bl = PIN_AUTOLF;
lcd.pins.cl = PIN_STROBE;
lcd.pins.da = PIN_D0;
charlcd->width = 16;
hdc->bwidth = 40;
hdc->hwidth = 16;
charlcd->height = 2;
break;
case LCD_TYPE_NEXCOM:
/* parallel mode, 8 bits, generic */
lcd.proto = LCD_PROTO_PARALLEL;
lcd.charset = LCD_CHARSET_NORMAL;
lcd.pins.e = PIN_AUTOLF;
lcd.pins.rs = PIN_SELECP;
lcd.pins.rw = PIN_INITP;
charlcd->width = 16;
hdc->bwidth = 40;
hdc->hwidth = 64;
charlcd->height = 2;
break;
case LCD_TYPE_CUSTOM:
/* customer-defined */
lcd.proto = DEFAULT_LCD_PROTO;
lcd.charset = DEFAULT_LCD_CHARSET;
/* default geometry will be set later */
break;
case LCD_TYPE_HANTRONIX:
/* parallel mode, 8 bits, hantronix-like */
default:
lcd.proto = LCD_PROTO_PARALLEL;
lcd.charset = LCD_CHARSET_NORMAL;
lcd.pins.e = PIN_STROBE;
lcd.pins.rs = PIN_SELECP;
charlcd->width = 16;
hdc->bwidth = 40;
hdc->hwidth = 64;
charlcd->height = 2;
break;
}
/* Overwrite with module params set on loading */
if (lcd_height != NOT_SET)
charlcd->height = lcd_height;
if (lcd_width != NOT_SET)
charlcd->width = lcd_width;
if (lcd_bwidth != NOT_SET)
hdc->bwidth = lcd_bwidth;
if (lcd_hwidth != NOT_SET)
hdc->hwidth = lcd_hwidth;
if (lcd_charset != NOT_SET)
lcd.charset = lcd_charset;
if (lcd_proto != NOT_SET)
lcd.proto = lcd_proto;
if (lcd_e_pin != PIN_NOT_SET)
lcd.pins.e = lcd_e_pin;
if (lcd_rs_pin != PIN_NOT_SET)
lcd.pins.rs = lcd_rs_pin;
if (lcd_rw_pin != PIN_NOT_SET)
lcd.pins.rw = lcd_rw_pin;
if (lcd_cl_pin != PIN_NOT_SET)
lcd.pins.cl = lcd_cl_pin;
if (lcd_da_pin != PIN_NOT_SET)
lcd.pins.da = lcd_da_pin;
if (lcd_bl_pin != PIN_NOT_SET)
lcd.pins.bl = lcd_bl_pin;
/* this is used to catch wrong and default values */
if (charlcd->width <= 0)
charlcd->width = DEFAULT_LCD_WIDTH;
if (hdc->bwidth <= 0)
hdc->bwidth = DEFAULT_LCD_BWIDTH;
if (hdc->hwidth <= 0)
hdc->hwidth = DEFAULT_LCD_HWIDTH;
if (charlcd->height <= 0)
charlcd->height = DEFAULT_LCD_HEIGHT;
if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
charlcd->ops = &charlcd_ops;
hdc->write_data = lcd_write_data_s;
hdc->write_cmd = lcd_write_cmd_s;
if (lcd.pins.cl == PIN_NOT_SET)
lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
if (lcd.pins.da == PIN_NOT_SET)
lcd.pins.da = DEFAULT_LCD_PIN_SDA;
} else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
charlcd->ops = &charlcd_ops;
hdc->write_data = lcd_write_data_p8;
hdc->write_cmd = lcd_write_cmd_p8;
if (lcd.pins.e == PIN_NOT_SET)
lcd.pins.e = DEFAULT_LCD_PIN_E;
if (lcd.pins.rs == PIN_NOT_SET)
lcd.pins.rs = DEFAULT_LCD_PIN_RS;
if (lcd.pins.rw == PIN_NOT_SET)
lcd.pins.rw = DEFAULT_LCD_PIN_RW;
} else {
charlcd->ops = &charlcd_ops;
hdc->write_data = lcd_write_data_tilcd;
hdc->write_cmd = lcd_write_cmd_tilcd;
}
if (lcd.pins.bl == PIN_NOT_SET)
lcd.pins.bl = DEFAULT_LCD_PIN_BL;
if (lcd.pins.e == PIN_NOT_SET)
lcd.pins.e = PIN_NONE;
if (lcd.pins.rs == PIN_NOT_SET)
lcd.pins.rs = PIN_NONE;
if (lcd.pins.rw == PIN_NOT_SET)
lcd.pins.rw = PIN_NONE;
if (lcd.pins.bl == PIN_NOT_SET)
lcd.pins.bl = PIN_NONE;
if (lcd.pins.cl == PIN_NOT_SET)
lcd.pins.cl = PIN_NONE;
if (lcd.pins.da == PIN_NOT_SET)
lcd.pins.da = PIN_NONE;
if (lcd.charset == NOT_SET)
lcd.charset = DEFAULT_LCD_CHARSET;
if (lcd.charset == LCD_CHARSET_KS0074)
charlcd->char_conv = lcd_char_conv_ks0074;
else