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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
36#include <linux/module.h>
37
38#include <linux/types.h>
39#include <linux/errno.h>
40#include <linux/signal.h>
41#include <linux/sched.h>
42#include <linux/spinlock.h>
43#include <linux/interrupt.h>
44#include <linux/miscdevice.h>
45#include <linux/slab.h>
46#include <linux/ioport.h>
47#include <linux/fcntl.h>
48#include <linux/init.h>
49#include <linux/delay.h>
50#include <linux/kernel.h>
51#include <linux/ctype.h>
52#include <linux/parport.h>
53#include <linux/list.h>
54
55#include <linux/io.h>
56#include <linux/uaccess.h>
57
58#include "charlcd.h"
59#include "hd44780_common.h"
60
61#define LCD_MAXBYTES 256
62
63#define KEYPAD_BUFFER 64
64
65
66#define INPUT_POLL_TIME (HZ / 50)
67
68#define KEYPAD_REP_START (10)
69
70#define KEYPAD_REP_DELAY (2)
71
72
73#define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
74
75#define PNL_PBUSY 0x80
76#define PNL_PACK 0x40
77#define PNL_POUTPA 0x20
78#define PNL_PSELECD 0x10
79#define PNL_PERRORP 0x08
80
81#define PNL_PBIDIR 0x20
82
83#define PNL_PINTEN 0x10
84#define PNL_PSELECP 0x08
85#define PNL_PINITP 0x04
86#define PNL_PAUTOLF 0x02
87#define PNL_PSTROBE 0x01
88
89#define PNL_PD0 0x01
90#define PNL_PD1 0x02
91#define PNL_PD2 0x04
92#define PNL_PD3 0x08
93#define PNL_PD4 0x10
94#define PNL_PD5 0x20
95#define PNL_PD6 0x40
96#define PNL_PD7 0x80
97
98#define PIN_NONE 0
99#define PIN_STROBE 1
100#define PIN_D0 2
101#define PIN_D1 3
102#define PIN_D2 4
103#define PIN_D3 5
104#define PIN_D4 6
105#define PIN_D5 7
106#define PIN_D6 8
107#define PIN_D7 9
108#define PIN_AUTOLF 14
109#define PIN_INITP 16
110#define PIN_SELECP 17
111#define PIN_NOT_SET 127
112
113#define NOT_SET -1
114
115
116#define r_ctr(x) (parport_read_control((x)->port))
117#define r_dtr(x) (parport_read_data((x)->port))
118#define r_str(x) (parport_read_status((x)->port))
119#define w_ctr(x, y) (parport_write_control((x)->port, (y)))
120#define w_dtr(x, y) (parport_write_data((x)->port, (y)))
121
122
123
124static __u8 scan_mask_o;
125
126static __u8 scan_mask_i;
127
128enum input_type {
129 INPUT_TYPE_STD,
130 INPUT_TYPE_KBD,
131};
132
133enum input_state {
134 INPUT_ST_LOW,
135 INPUT_ST_RISING,
136 INPUT_ST_HIGH,
137 INPUT_ST_FALLING,
138};
139
140struct logical_input {
141 struct list_head list;
142 __u64 mask;
143 __u64 value;
144 enum input_type type;
145 enum input_state state;
146 __u8 rise_time, fall_time;
147 __u8 rise_timer, fall_timer, high_timer;
148
149 union {
150 struct {
151 void (*press_fct)(int);
152 void (*release_fct)(int);
153 int press_data;
154 int release_data;
155 } std;
156 struct {
157 char press_str[sizeof(void *) + sizeof(int)] __nonstring;
158 char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
159 char release_str[sizeof(void *) + sizeof(int)] __nonstring;
160 } kbd;
161 } u;
162};
163
164static LIST_HEAD(logical_inputs);
165
166
167
168
169
170
171
172
173
174
175
176
177
178static __u64 phys_read;
179
180static __u64 phys_read_prev;
181
182static __u64 phys_curr;
183
184static __u64 phys_prev;
185
186static char inputs_stable;
187
188
189static struct {
190 bool enabled;
191} keypad;
192
193static char keypad_buffer[KEYPAD_BUFFER];
194static int keypad_buflen;
195static int keypad_start;
196static char keypressed;
197static wait_queue_head_t keypad_read_wait;
198
199
200static struct {
201 bool enabled;
202 bool initialized;
203
204 int charset;
205 int proto;
206
207
208 struct {
209 int e;
210 int rs;
211 int rw;
212 int cl;
213 int da;
214 int bl;
215 } pins;
216
217 struct charlcd *charlcd;
218} lcd;
219
220
221static int selected_lcd_type = NOT_SET;
222
223
224
225
226
227
228#define BIT_CLR 0
229#define BIT_SET 1
230#define BIT_MSK 2
231#define BIT_STATES 3
232
233
234
235#define LCD_BIT_E 0
236#define LCD_BIT_RS 1
237#define LCD_BIT_RW 2
238#define LCD_BIT_BL 3
239#define LCD_BIT_CL 4
240#define LCD_BIT_DA 5
241#define LCD_BITS 6
242
243
244
245
246#define LCD_PORT_C 0
247#define LCD_PORT_D 1
248#define LCD_PORTS 2
249
250static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
251
252
253
254
255#define LCD_PROTO_PARALLEL 0
256#define LCD_PROTO_SERIAL 1
257#define LCD_PROTO_TI_DA8XX_LCD 2
258
259
260
261
262#define LCD_CHARSET_NORMAL 0
263#define LCD_CHARSET_KS0074 1
264
265
266
267
268#define LCD_TYPE_NONE 0
269#define LCD_TYPE_CUSTOM 1
270#define LCD_TYPE_OLD 2
271#define LCD_TYPE_KS0074 3
272#define LCD_TYPE_HANTRONIX 4
273#define LCD_TYPE_NEXCOM 5
274
275
276
277
278#define KEYPAD_TYPE_NONE 0
279#define KEYPAD_TYPE_OLD 1
280#define KEYPAD_TYPE_NEW 2
281#define KEYPAD_TYPE_NEXCOM 3
282
283
284
285
286#define PANEL_PROFILE_CUSTOM 0
287#define PANEL_PROFILE_OLD 1
288#define PANEL_PROFILE_NEW 2
289#define PANEL_PROFILE_HANTRONIX 3
290#define PANEL_PROFILE_NEXCOM 4
291#define PANEL_PROFILE_LARGE 5
292
293
294
295
296#define DEFAULT_PARPORT 0
297#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
298#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
299#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
300#define DEFAULT_LCD_HEIGHT 2
301#define DEFAULT_LCD_WIDTH 40
302#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
303#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
304
305#define DEFAULT_LCD_PIN_E PIN_AUTOLF
306#define DEFAULT_LCD_PIN_RS PIN_SELECP
307#define DEFAULT_LCD_PIN_RW PIN_INITP
308#define DEFAULT_LCD_PIN_SCL PIN_STROBE
309#define DEFAULT_LCD_PIN_SDA PIN_D0
310#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
311
312#ifdef CONFIG_PANEL_PARPORT
313#undef DEFAULT_PARPORT
314#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
315#endif
316
317#ifdef CONFIG_PANEL_PROFILE
318#undef DEFAULT_PROFILE
319#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
320#endif
321
322#if DEFAULT_PROFILE == 0
323#ifdef CONFIG_PANEL_KEYPAD
324#undef DEFAULT_KEYPAD_TYPE
325#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
326#endif
327
328#ifdef CONFIG_PANEL_LCD
329#undef DEFAULT_LCD_TYPE
330#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
331#endif
332
333#ifdef CONFIG_PANEL_LCD_HEIGHT
334#undef DEFAULT_LCD_HEIGHT
335#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
336#endif
337
338#ifdef CONFIG_PANEL_LCD_WIDTH
339#undef DEFAULT_LCD_WIDTH
340#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
341#endif
342
343#ifdef CONFIG_PANEL_LCD_BWIDTH
344#undef DEFAULT_LCD_BWIDTH
345#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
346#endif
347
348#ifdef CONFIG_PANEL_LCD_HWIDTH
349#undef DEFAULT_LCD_HWIDTH
350#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
351#endif
352
353#ifdef CONFIG_PANEL_LCD_CHARSET
354#undef DEFAULT_LCD_CHARSET
355#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
356#endif
357
358#ifdef CONFIG_PANEL_LCD_PROTO
359#undef DEFAULT_LCD_PROTO
360#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
361#endif
362
363#ifdef CONFIG_PANEL_LCD_PIN_E
364#undef DEFAULT_LCD_PIN_E
365#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
366#endif
367
368#ifdef CONFIG_PANEL_LCD_PIN_RS
369#undef DEFAULT_LCD_PIN_RS
370#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
371#endif
372
373#ifdef CONFIG_PANEL_LCD_PIN_RW
374#undef DEFAULT_LCD_PIN_RW
375#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
376#endif
377
378#ifdef CONFIG_PANEL_LCD_PIN_SCL
379#undef DEFAULT_LCD_PIN_SCL
380#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
381#endif
382
383#ifdef CONFIG_PANEL_LCD_PIN_SDA
384#undef DEFAULT_LCD_PIN_SDA
385#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
386#endif
387
388#ifdef CONFIG_PANEL_LCD_PIN_BL
389#undef DEFAULT_LCD_PIN_BL
390#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
391#endif
392
393#endif
394
395
396
397
398static atomic_t keypad_available = ATOMIC_INIT(1);
399
400static struct pardevice *pprt;
401
402static int keypad_initialized;
403
404static DEFINE_SPINLOCK(pprt_lock);
405static struct timer_list scan_timer;
406
407MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
408
409static int parport = DEFAULT_PARPORT;
410module_param(parport, int, 0000);
411MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
412
413static int profile = DEFAULT_PROFILE;
414module_param(profile, int, 0000);
415MODULE_PARM_DESC(profile,
416 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
417 "4=16x2 nexcom; default=40x2, old kp");
418
419static int keypad_type = NOT_SET;
420module_param(keypad_type, int, 0000);
421MODULE_PARM_DESC(keypad_type,
422 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
423
424static int lcd_type = NOT_SET;
425module_param(lcd_type, int, 0000);
426MODULE_PARM_DESC(lcd_type,
427 "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
428
429static int lcd_height = NOT_SET;
430module_param(lcd_height, int, 0000);
431MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
432
433static int lcd_width = NOT_SET;
434module_param(lcd_width, int, 0000);
435MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
436
437static int lcd_bwidth = NOT_SET;
438module_param(lcd_bwidth, int, 0000);
439MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
440
441static int lcd_hwidth = NOT_SET;
442module_param(lcd_hwidth, int, 0000);
443MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
444
445static int lcd_charset = NOT_SET;
446module_param(lcd_charset, int, 0000);
447MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
448
449static int lcd_proto = NOT_SET;
450module_param(lcd_proto, int, 0000);
451MODULE_PARM_DESC(lcd_proto,
452 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
453
454
455
456
457
458
459
460
461
462
463static int lcd_e_pin = PIN_NOT_SET;
464module_param(lcd_e_pin, int, 0000);
465MODULE_PARM_DESC(lcd_e_pin,
466 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
467
468static int lcd_rs_pin = PIN_NOT_SET;
469module_param(lcd_rs_pin, int, 0000);
470MODULE_PARM_DESC(lcd_rs_pin,
471 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
472
473static int lcd_rw_pin = PIN_NOT_SET;
474module_param(lcd_rw_pin, int, 0000);
475MODULE_PARM_DESC(lcd_rw_pin,
476 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
477
478static int lcd_cl_pin = PIN_NOT_SET;
479module_param(lcd_cl_pin, int, 0000);
480MODULE_PARM_DESC(lcd_cl_pin,
481 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
482
483static int lcd_da_pin = PIN_NOT_SET;
484module_param(lcd_da_pin, int, 0000);
485MODULE_PARM_DESC(lcd_da_pin,
486 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
487
488static int lcd_bl_pin = PIN_NOT_SET;
489module_param(lcd_bl_pin, int, 0000);
490MODULE_PARM_DESC(lcd_bl_pin,
491 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
492
493
494
495static int lcd_enabled = NOT_SET;
496module_param(lcd_enabled, int, 0000);
497MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
498
499static int keypad_enabled = NOT_SET;
500module_param(keypad_enabled, int, 0000);
501MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
502
503
504static const unsigned char lcd_char_conv_ks0074[256] = {
505
506 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
507 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
508 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
509 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
510 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
511 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
512 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
513 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
514 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
515 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
516 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
517 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
518 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
519 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
520 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
521 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
522 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
523 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
524 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
525 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
526 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
527 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
528 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
529 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
530 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
531 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
532 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
533 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
534 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
535 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
536 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
537 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
538};
539
540static const char old_keypad_profile[][4][9] = {
541 {"S0", "Left\n", "Left\n", ""},
542 {"S1", "Down\n", "Down\n", ""},
543 {"S2", "Up\n", "Up\n", ""},
544 {"S3", "Right\n", "Right\n", ""},
545 {"S4", "Esc\n", "Esc\n", ""},
546 {"S5", "Ret\n", "Ret\n", ""},
547 {"", "", "", ""}
548};
549
550
551static const char new_keypad_profile[][4][9] = {
552 {"S0", "Left\n", "Left\n", ""},
553 {"S1", "Down\n", "Down\n", ""},
554 {"S2", "Up\n", "Up\n", ""},
555 {"S3", "Right\n", "Right\n", ""},
556 {"S4s5", "", "Esc\n", "Esc\n"},
557 {"s4S5", "", "Ret\n", "Ret\n"},
558 {"S4S5", "Help\n", "", ""},
559
560 {"", "", "", ""}
561};
562
563
564static const char nexcom_keypad_profile[][4][9] = {
565 {"a-p-e-", "Down\n", "Down\n", ""},
566 {"a-p-E-", "Ret\n", "Ret\n", ""},
567 {"a-P-E-", "Esc\n", "Esc\n", ""},
568 {"a-P-e-", "Up\n", "Up\n", ""},
569
570 {"", "", "", ""}
571};
572
573static const char (*keypad_profile)[4][9] = old_keypad_profile;
574
575static DECLARE_BITMAP(bits, LCD_BITS);
576
577static void lcd_get_bits(unsigned int port, int *val)
578{
579 unsigned int bit, state;
580
581 for (bit = 0; bit < LCD_BITS; bit++) {
582 state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
583 *val &= lcd_bits[port][bit][BIT_MSK];
584 *val |= lcd_bits[port][bit][state];
585 }
586}
587
588
589static int set_data_bits(void)
590{
591 int val;
592
593 val = r_dtr(pprt);
594 lcd_get_bits(LCD_PORT_D, &val);
595 w_dtr(pprt, val);
596 return val;
597}
598
599
600static int set_ctrl_bits(void)
601{
602 int val;
603
604 val = r_ctr(pprt);
605 lcd_get_bits(LCD_PORT_C, &val);
606 w_ctr(pprt, val);
607 return val;
608}
609
610
611static void panel_set_bits(void)
612{
613 set_data_bits();
614 set_ctrl_bits();
615}
616
617
618
619
620
621
622
623
624
625
626static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
627{
628 int d_bit, c_bit, inv;
629
630 d_val[0] = 0;
631 c_val[0] = 0;
632 d_val[1] = 0;
633 c_val[1] = 0;
634 d_val[2] = 0xFF;
635 c_val[2] = 0xFF;
636
637 if (pin == 0)
638 return;
639
640 inv = (pin < 0);
641 if (inv)
642 pin = -pin;
643
644 d_bit = 0;
645 c_bit = 0;
646
647 switch (pin) {
648 case PIN_STROBE:
649 c_bit = PNL_PSTROBE;
650 inv = !inv;
651 break;
652 case PIN_D0...PIN_D7:
653 d_bit = 1 << (pin - 2);
654 break;
655 case PIN_AUTOLF:
656 c_bit = PNL_PAUTOLF;
657 inv = !inv;
658 break;
659 case PIN_INITP:
660 c_bit = PNL_PINITP;
661 break;
662 case PIN_SELECP:
663 c_bit = PNL_PSELECP;
664 inv = !inv;
665 break;
666 default:
667 break;
668 }
669
670 if (c_bit) {
671 c_val[2] &= ~c_bit;
672 c_val[!inv] = c_bit;
673 } else if (d_bit) {
674 d_val[2] &= ~d_bit;
675 d_val[!inv] = d_bit;
676 }
677}
678
679
680
681
682
683static void lcd_send_serial(int byte)
684{
685 int bit;
686
687
688
689
690
691 for (bit = 0; bit < 8; bit++) {
692 clear_bit(LCD_BIT_CL, bits);
693 panel_set_bits();
694 if (byte & 1) {
695 set_bit(LCD_BIT_DA, bits);
696 } else {
697 clear_bit(LCD_BIT_DA, bits);
698 }
699
700 panel_set_bits();
701 udelay(2);
702 set_bit(LCD_BIT_CL, bits);
703 panel_set_bits();
704 udelay(1);
705 byte >>= 1;
706 }
707}
708
709
710static void lcd_backlight(struct charlcd *charlcd, enum charlcd_onoff on)
711{
712 if (lcd.pins.bl == PIN_NONE)
713 return;
714
715
716 spin_lock_irq(&pprt_lock);
717 if (on)
718 set_bit(LCD_BIT_BL, bits);
719 else
720 clear_bit(LCD_BIT_BL, bits);
721 panel_set_bits();
722 spin_unlock_irq(&pprt_lock);
723}
724
725
726static void lcd_write_cmd_s(struct hd44780_common *hdc, int cmd)
727{
728 spin_lock_irq(&pprt_lock);
729 lcd_send_serial(0x1F);
730 lcd_send_serial(cmd & 0x0F);
731 lcd_send_serial((cmd >> 4) & 0x0F);
732 udelay(40);
733 spin_unlock_irq(&pprt_lock);
734}
735
736
737static void lcd_write_data_s(struct hd44780_common *hdc, int data)
738{
739 spin_lock_irq(&pprt_lock);
740 lcd_send_serial(0x5F);
741 lcd_send_serial(data & 0x0F);
742 lcd_send_serial((data >> 4) & 0x0F);
743 udelay(40);
744 spin_unlock_irq(&pprt_lock);
745}
746
747
748static void lcd_write_cmd_p8(struct hd44780_common *hdc, int cmd)
749{
750 spin_lock_irq(&pprt_lock);
751
752 w_dtr(pprt, cmd);
753 udelay(20);
754
755 set_bit(LCD_BIT_E, bits);
756 clear_bit(LCD_BIT_RS, bits);
757 clear_bit(LCD_BIT_RW, bits);
758 set_ctrl_bits();
759
760 udelay(40);
761
762 clear_bit(LCD_BIT_E, bits);
763 set_ctrl_bits();
764
765 udelay(120);
766 spin_unlock_irq(&pprt_lock);
767}
768
769
770static void lcd_write_data_p8(struct hd44780_common *hdc, int data)
771{
772 spin_lock_irq(&pprt_lock);
773
774 w_dtr(pprt, data);
775 udelay(20);
776
777 set_bit(LCD_BIT_E, bits);
778 set_bit(LCD_BIT_RS, bits);
779 clear_bit(LCD_BIT_RW, bits);
780 set_ctrl_bits();
781
782 udelay(40);
783
784 clear_bit(LCD_BIT_E, bits);
785 set_ctrl_bits();
786
787 udelay(45);
788 spin_unlock_irq(&pprt_lock);
789}
790
791
792static void lcd_write_cmd_tilcd(struct hd44780_common *hdc, int cmd)
793{
794 spin_lock_irq(&pprt_lock);
795
796 w_ctr(pprt, cmd);
797 udelay(60);
798 spin_unlock_irq(&pprt_lock);
799}
800
801
802static void lcd_write_data_tilcd(struct hd44780_common *hdc, int data)
803{
804 spin_lock_irq(&pprt_lock);
805
806 w_dtr(pprt, data);
807 udelay(60);
808 spin_unlock_irq(&pprt_lock);
809}
810
811static const struct charlcd_ops charlcd_ops = {
812 .backlight = lcd_backlight,
813 .print = hd44780_common_print,
814 .gotoxy = hd44780_common_gotoxy,
815 .home = hd44780_common_home,
816 .clear_display = hd44780_common_clear_display,
817 .init_display = hd44780_common_init_display,
818 .shift_cursor = hd44780_common_shift_cursor,
819 .shift_display = hd44780_common_shift_display,
820 .display = hd44780_common_display,
821 .cursor = hd44780_common_cursor,
822 .blink = hd44780_common_blink,
823 .fontsize = hd44780_common_fontsize,
824 .lines = hd44780_common_lines,
825 .redefine_char = hd44780_common_redefine_char,
826};
827
828
829static void lcd_init(void)
830{
831 struct charlcd *charlcd;
832 struct hd44780_common *hdc;
833
834 hdc = hd44780_common_alloc();
835 if (!hdc)
836 return;
837
838 charlcd = charlcd_alloc();
839 if (!charlcd) {
840 kfree(hdc);
841 return;
842 }
843
844 hdc->hd44780 = &lcd;
845 charlcd->drvdata = hdc;
846
847
848
849
850
851 charlcd->height = lcd_height;
852 charlcd->width = lcd_width;
853 hdc->bwidth = lcd_bwidth;
854 hdc->hwidth = lcd_hwidth;
855
856 switch (selected_lcd_type) {
857 case LCD_TYPE_OLD:
858
859 lcd.proto = LCD_PROTO_PARALLEL;
860 lcd.charset = LCD_CHARSET_NORMAL;
861 lcd.pins.e = PIN_STROBE;
862 lcd.pins.rs = PIN_AUTOLF;
863
864 charlcd->width = 40;
865 hdc->bwidth = 40;
866 hdc->hwidth = 64;
867 charlcd->height = 2;
868 break;
869 case LCD_TYPE_KS0074:
870
871 lcd.proto = LCD_PROTO_SERIAL;
872 lcd.charset = LCD_CHARSET_KS0074;
873 lcd.pins.bl = PIN_AUTOLF;
874 lcd.pins.cl = PIN_STROBE;
875 lcd.pins.da = PIN_D0;
876
877 charlcd->width = 16;
878 hdc->bwidth = 40;
879 hdc->hwidth = 16;
880 charlcd->height = 2;
881 break;
882 case LCD_TYPE_NEXCOM:
883
884 lcd.proto = LCD_PROTO_PARALLEL;
885 lcd.charset = LCD_CHARSET_NORMAL;
886 lcd.pins.e = PIN_AUTOLF;
887 lcd.pins.rs = PIN_SELECP;
888 lcd.pins.rw = PIN_INITP;
889
890 charlcd->width = 16;
891 hdc->bwidth = 40;
892 hdc->hwidth = 64;
893 charlcd->height = 2;
894 break;
895 case LCD_TYPE_CUSTOM:
896
897 lcd.proto = DEFAULT_LCD_PROTO;
898 lcd.charset = DEFAULT_LCD_CHARSET;
899
900 break;
901 case LCD_TYPE_HANTRONIX:
902
903 default:
904 lcd.proto = LCD_PROTO_PARALLEL;
905 lcd.charset = LCD_CHARSET_NORMAL;
906 lcd.pins.e = PIN_STROBE;
907 lcd.pins.rs = PIN_SELECP;
908
909 charlcd->width = 16;
910 hdc->bwidth = 40;
911 hdc->hwidth = 64;
912 charlcd->height = 2;
913 break;
914 }
915
916
917 if (lcd_height != NOT_SET)
918 charlcd->height = lcd_height;
919 if (lcd_width != NOT_SET)
920 charlcd->width = lcd_width;
921 if (lcd_bwidth != NOT_SET)
922 hdc->bwidth = lcd_bwidth;
923 if (lcd_hwidth != NOT_SET)
924 hdc->hwidth = lcd_hwidth;
925 if (lcd_charset != NOT_SET)
926 lcd.charset = lcd_charset;
927 if (lcd_proto != NOT_SET)
928 lcd.proto = lcd_proto;
929 if (lcd_e_pin != PIN_NOT_SET)
930 lcd.pins.e = lcd_e_pin;
931 if (lcd_rs_pin != PIN_NOT_SET)
932 lcd.pins.rs = lcd_rs_pin;
933 if (lcd_rw_pin != PIN_NOT_SET)
934 lcd.pins.rw = lcd_rw_pin;
935 if (lcd_cl_pin != PIN_NOT_SET)
936 lcd.pins.cl = lcd_cl_pin;
937 if (lcd_da_pin != PIN_NOT_SET)
938 lcd.pins.da = lcd_da_pin;
939 if (lcd_bl_pin != PIN_NOT_SET)
940 lcd.pins.bl = lcd_bl_pin;
941
942
943 if (charlcd->width <= 0)
944 charlcd->width = DEFAULT_LCD_WIDTH;
945 if (hdc->bwidth <= 0)
946 hdc->bwidth = DEFAULT_LCD_BWIDTH;
947 if (hdc->hwidth <= 0)
948 hdc->hwidth = DEFAULT_LCD_HWIDTH;
949 if (charlcd->height <= 0)
950 charlcd->height = DEFAULT_LCD_HEIGHT;
951
952 if (lcd.proto == LCD_PROTO_SERIAL) {
953 charlcd->ops = &charlcd_ops;
954 hdc->write_data = lcd_write_data_s;
955 hdc->write_cmd = lcd_write_cmd_s;
956
957 if (lcd.pins.cl == PIN_NOT_SET)
958 lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
959 if (lcd.pins.da == PIN_NOT_SET)
960 lcd.pins.da = DEFAULT_LCD_PIN_SDA;
961
962 } else if (lcd.proto == LCD_PROTO_PARALLEL) {
963 charlcd->ops = &charlcd_ops;
964 hdc->write_data = lcd_write_data_p8;
965 hdc->write_cmd = lcd_write_cmd_p8;
966
967 if (lcd.pins.e == PIN_NOT_SET)
968 lcd.pins.e = DEFAULT_LCD_PIN_E;
969 if (lcd.pins.rs == PIN_NOT_SET)
970 lcd.pins.rs = DEFAULT_LCD_PIN_RS;
971 if (lcd.pins.rw == PIN_NOT_SET)
972 lcd.pins.rw = DEFAULT_LCD_PIN_RW;
973 } else {
974 charlcd->ops = &charlcd_ops;
975 hdc->write_data = lcd_write_data_tilcd;
976 hdc->write_cmd = lcd_write_cmd_tilcd;
977 }
978
979 if (lcd.pins.bl == PIN_NOT_SET)
980 lcd.pins.bl = DEFAULT_LCD_PIN_BL;
981
982 if (lcd.pins.e == PIN_NOT_SET)
983 lcd.pins.e = PIN_NONE;
984 if (lcd.pins.rs == PIN_NOT_SET)
985 lcd.pins.rs = PIN_NONE;
986 if (lcd.pins.rw == PIN_NOT_SET)
987 lcd.pins.rw = PIN_NONE;
988 if (lcd.pins.bl == PIN_NOT_SET)
989 lcd.pins.bl = PIN_NONE;
990 if (lcd.pins.cl == PIN_NOT_SET)
991 lcd.pins.cl = PIN_NONE;
992 if (lcd.pins.da == PIN_NOT_SET)
993 lcd.pins.da = PIN_NONE;
994
995 if (lcd.charset == NOT_SET)
996 lcd.charset = DEFAULT_LCD_CHARSET;
997
998 if (lcd.charset == LCD_CHARSET_KS0074)
999 charlcd->char_conv = lcd_char_conv_ks0074;
1000 else
1001 charlcd->char_conv = NULL;
1002
1003 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1004 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1005 pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1006 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1007 pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1008 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1009 pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1010 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1011 pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1012 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1013 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1014 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
1015
1016 lcd.charlcd = charlcd;
1017 lcd.initialized = true;
1018}
1019
1020
1021
1022
1023
1024static ssize_t keypad_read(struct file *file,
1025 char __user *buf, size_t count, loff_t *ppos)
1026{
1027 unsigned i = *ppos;
1028 char __user *tmp = buf;
1029
1030 if (keypad_buflen == 0) {
1031 if (file->f_flags & O_NONBLOCK)
1032 return -EAGAIN;
1033
1034 if (wait_event_interruptible(keypad_read_wait,
1035 keypad_buflen != 0))
1036 return -EINTR;
1037 }
1038
1039 for (; count-- > 0 && (keypad_buflen > 0);
1040 ++i, ++tmp, --keypad_buflen) {
1041 put_user(keypad_buffer[keypad_start], tmp);
1042 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1043 }
1044 *ppos = i;
1045
1046 return tmp - buf;
1047}
1048
1049static int keypad_open(struct inode *inode, struct file *file)
1050{
1051 int ret;
1052
1053 ret = -EBUSY;
1054 if (!atomic_dec_and_test(&keypad_available))
1055 goto fail;
1056
1057 ret = -EPERM;
1058 if (file->f_mode & FMODE_WRITE)
1059 goto fail;
1060
1061 keypad_buflen = 0;
1062 return 0;
1063 fail:
1064 atomic_inc(&keypad_available);
1065 return ret;
1066}
1067
1068static int keypad_release(struct inode *inode, struct file *file)
1069{
1070 atomic_inc(&keypad_available);
1071 return 0;
1072}
1073
1074static const struct file_operations keypad_fops = {
1075 .read = keypad_read,
1076 .open = keypad_open,
1077 .release = keypad_release,
1078 .llseek = default_llseek,
1079};
1080
1081static struct miscdevice keypad_dev = {
1082 .minor = KEYPAD_MINOR,
1083 .name = "keypad",
1084 .fops = &keypad_fops,
1085};
1086
1087static void keypad_send_key(const char *string, int max_len)
1088{
1089
1090 if (!atomic_read(&keypad_available)) {
1091 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1092 keypad_buffer[(keypad_start + keypad_buflen++) %
1093 KEYPAD_BUFFER] = *string++;
1094 }
1095 wake_up_interruptible(&keypad_read_wait);
1096 }
1097}
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109static void phys_scan_contacts(void)
1110{
1111 int bit, bitval;
1112 char oldval;
1113 char bitmask;
1114 char gndmask;
1115
1116 phys_prev = phys_curr;
1117 phys_read_prev = phys_read;
1118 phys_read = 0;
1119
1120
1121 oldval = r_dtr(pprt) | scan_mask_o;
1122
1123 w_dtr(pprt, oldval & ~scan_mask_o);
1124
1125
1126 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1127
1128 w_dtr(pprt, oldval);
1129
1130
1131
1132
1133
1134
1135 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1136
1137
1138 phys_read |= (__u64)gndmask << 40;
1139
1140 if (bitmask != gndmask) {
1141
1142
1143
1144
1145
1146 for (bit = 0; bit < 8; bit++) {
1147 bitval = BIT(bit);
1148
1149 if (!(scan_mask_o & bitval))
1150 continue;
1151
1152 w_dtr(pprt, oldval & ~bitval);
1153 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1154 phys_read |= (__u64)bitmask << (5 * bit);
1155 }
1156 w_dtr(pprt, oldval);
1157 }
1158
1159
1160
1161
1162 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1163 (phys_read & ~(phys_read ^ phys_read_prev));
1164}
1165
1166static inline int input_state_high(struct logical_input *input)
1167{
1168#if 0
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 if (((phys_prev & input->mask) == input->value) &&
1187 ((phys_curr & input->mask) > input->value)) {
1188 input->state = INPUT_ST_LOW;
1189 return 1;
1190 }
1191#endif
1192
1193 if ((phys_curr & input->mask) == input->value) {
1194 if ((input->type == INPUT_TYPE_STD) &&
1195 (input->high_timer == 0)) {
1196 input->high_timer++;
1197 if (input->u.std.press_fct)
1198 input->u.std.press_fct(input->u.std.press_data);
1199 } else if (input->type == INPUT_TYPE_KBD) {
1200
1201 keypressed = 1;
1202
1203 if (input->high_timer == 0) {
1204 char *press_str = input->u.kbd.press_str;
1205
1206 if (press_str[0]) {
1207 int s = sizeof(input->u.kbd.press_str);
1208
1209 keypad_send_key(press_str, s);
1210 }
1211 }
1212
1213 if (input->u.kbd.repeat_str[0]) {
1214 char *repeat_str = input->u.kbd.repeat_str;
1215
1216 if (input->high_timer >= KEYPAD_REP_START) {
1217 int s = sizeof(input->u.kbd.repeat_str);
1218
1219 input->high_timer -= KEYPAD_REP_DELAY;
1220 keypad_send_key(repeat_str, s);
1221 }
1222
1223 inputs_stable = 0;
1224 }
1225
1226 if (input->high_timer < 255)
1227 input->high_timer++;
1228 }
1229 return 1;
1230 }
1231
1232
1233 input->state = INPUT_ST_FALLING;
1234 input->fall_timer = 0;
1235
1236 return 0;
1237}
1238
1239static inline void input_state_falling(struct logical_input *input)
1240{
1241#if 0
1242
1243 if (((phys_prev & input->mask) == input->value) &&
1244 ((phys_curr & input->mask) > input->value)) {
1245 input->state = INPUT_ST_LOW;
1246 return;
1247 }
1248#endif
1249
1250 if ((phys_curr & input->mask) == input->value) {
1251 if (input->type == INPUT_TYPE_KBD) {
1252
1253 keypressed = 1;
1254
1255 if (input->u.kbd.repeat_str[0]) {
1256 char *repeat_str = input->u.kbd.repeat_str;
1257
1258 if (input->high_timer >= KEYPAD_REP_START) {
1259 int s = sizeof(input->u.kbd.repeat_str);
1260
1261 input->high_timer -= KEYPAD_REP_DELAY;
1262 keypad_send_key(repeat_str, s);
1263 }
1264
1265 inputs_stable = 0;
1266 }
1267
1268 if (input->high_timer < 255)
1269 input->high_timer++;
1270 }
1271 input->state = INPUT_ST_HIGH;
1272 } else if (input->fall_timer >= input->fall_time) {
1273
1274 if (input->type == INPUT_TYPE_STD) {
1275 void (*release_fct)(int) = input->u.std.release_fct;
1276
1277 if (release_fct)
1278 release_fct(input->u.std.release_data);
1279 } else if (input->type == INPUT_TYPE_KBD) {
1280 char *release_str = input->u.kbd.release_str;
1281
1282 if (release_str[0]) {
1283 int s = sizeof(input->u.kbd.release_str);
1284
1285 keypad_send_key(release_str, s);
1286 }
1287 }
1288
1289 input->state = INPUT_ST_LOW;
1290 } else {
1291 input->fall_timer++;
1292 inputs_stable = 0;
1293 }
1294}
1295
1296static void panel_process_inputs(void)
1297{
1298 struct logical_input *input;
1299
1300 keypressed = 0;
1301 inputs_stable = 1;
1302 list_for_each_entry(input, &logical_inputs, list) {
1303 switch (input->state) {
1304 case INPUT_ST_LOW:
1305 if ((phys_curr & input->mask) != input->value)
1306 break;
1307
1308
1309
1310
1311
1312
1313
1314 if ((phys_prev & input->mask) == input->value)
1315 break;
1316 input->rise_timer = 0;
1317 input->state = INPUT_ST_RISING;
1318 fallthrough;
1319 case INPUT_ST_RISING:
1320 if ((phys_curr & input->mask) != input->value) {
1321 input->state = INPUT_ST_LOW;
1322 break;
1323 }
1324 if (input->rise_timer < input->rise_time) {
1325 inputs_stable = 0;
1326 input->rise_timer++;
1327 break;
1328 }
1329 input->high_timer = 0;
1330 input->state = INPUT_ST_HIGH;
1331 fallthrough;
1332 case INPUT_ST_HIGH:
1333 if (input_state_high(input))
1334 break;
1335 fallthrough;
1336 case INPUT_ST_FALLING:
1337 input_state_falling(input);
1338 }
1339 }
1340}
1341
1342static void panel_scan_timer(struct timer_list *unused)
1343{
1344 if (keypad.enabled && keypad_initialized) {
1345 if (spin_trylock_irq(&pprt_lock)) {
1346 phys_scan_contacts();
1347
1348
1349 spin_unlock_irq(&pprt_lock);
1350 }
1351
1352 if (!inputs_stable || phys_curr != phys_prev)
1353 panel_process_inputs();
1354 }
1355
1356 if (keypressed && lcd.enabled && lcd.initialized)
1357 charlcd_poke(lcd.charlcd);
1358
1359 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
1360}
1361
1362static void init_scan_timer(void)
1363{
1364 if (scan_timer.function)
1365 return;
1366
1367 timer_setup(&scan_timer, panel_scan_timer, 0);
1368 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1369 add_timer(&scan_timer);
1370}
1371
1372
1373
1374
1375
1376
1377static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
1378 u8 *imask, u8 *omask)
1379{
1380 const char sigtab[] = "EeSsPpAaBb";
1381 u8 im, om;
1382 __u64 m, v;
1383
1384 om = 0;
1385 im = 0;
1386 m = 0ULL;
1387 v = 0ULL;
1388 while (*name) {
1389 int in, out, bit, neg;
1390 const char *idx;
1391
1392 idx = strchr(sigtab, *name);
1393 if (!idx)
1394 return 0;
1395
1396 in = idx - sigtab;
1397 neg = (in & 1);
1398 in >>= 1;
1399 im |= BIT(in);
1400
1401 name++;
1402 if (*name >= '0' && *name <= '7') {
1403 out = *name - '0';
1404 om |= BIT(out);
1405 } else if (*name == '-') {
1406 out = 8;
1407 } else {
1408 return 0;
1409 }
1410
1411 bit = (out * 5) + in;
1412
1413 m |= 1ULL << bit;
1414 if (!neg)
1415 v |= 1ULL << bit;
1416 name++;
1417 }
1418 *mask = m;
1419 *value = v;
1420 if (imask)
1421 *imask |= im;
1422 if (omask)
1423 *omask |= om;
1424 return 1;
1425}
1426
1427
1428
1429
1430
1431static struct logical_input *panel_bind_key(const char *name, const char *press,
1432 const char *repeat,
1433 const char *release)
1434{
1435 struct logical_input *key;
1436
1437 key = kzalloc(sizeof(*key), GFP_KERNEL);
1438 if (!key)
1439 return NULL;
1440
1441 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
1442 &scan_mask_o)) {
1443 kfree(key);
1444 return NULL;
1445 }
1446
1447 key->type = INPUT_TYPE_KBD;
1448 key->state = INPUT_ST_LOW;
1449 key->rise_time = 1;
1450 key->fall_time = 1;
1451
1452 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1453 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1454 strncpy(key->u.kbd.release_str, release,
1455 sizeof(key->u.kbd.release_str));
1456 list_add(&key->list, &logical_inputs);
1457 return key;
1458}
1459
1460#if 0
1461
1462
1463
1464
1465
1466
1467static struct logical_input *panel_bind_callback(char *name,
1468 void (*press_fct)(int),
1469 int press_data,
1470 void (*release_fct)(int),
1471 int release_data)
1472{
1473 struct logical_input *callback;
1474
1475 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
1476 if (!callback)
1477 return NULL;
1478
1479 memset(callback, 0, sizeof(struct logical_input));
1480 if (!input_name2mask(name, &callback->mask, &callback->value,
1481 &scan_mask_i, &scan_mask_o))
1482 return NULL;
1483
1484 callback->type = INPUT_TYPE_STD;
1485 callback->state = INPUT_ST_LOW;
1486 callback->rise_time = 1;
1487 callback->fall_time = 1;
1488 callback->u.std.press_fct = press_fct;
1489 callback->u.std.press_data = press_data;
1490 callback->u.std.release_fct = release_fct;
1491 callback->u.std.release_data = release_data;
1492 list_add(&callback->list, &logical_inputs);
1493 return callback;
1494}
1495#endif
1496
1497static void keypad_init(void)
1498{
1499 int keynum;
1500
1501 init_waitqueue_head(&keypad_read_wait);
1502 keypad_buflen = 0;
1503
1504
1505
1506 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
1507 panel_bind_key(keypad_profile[keynum][0],
1508 keypad_profile[keynum][1],
1509 keypad_profile[keynum][2],
1510 keypad_profile[keynum][3]);
1511 }
1512
1513 init_scan_timer();
1514 keypad_initialized = 1;
1515}
1516
1517
1518
1519
1520
1521static void panel_attach(struct parport *port)
1522{
1523 struct pardev_cb panel_cb;
1524
1525 if (port->number != parport)
1526 return;
1527
1528 if (pprt) {
1529 pr_err("%s: port->number=%d parport=%d, already registered!\n",
1530 __func__, port->number, parport);
1531 return;
1532 }
1533
1534 memset(&panel_cb, 0, sizeof(panel_cb));
1535 panel_cb.private = &pprt;
1536
1537
1538 pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
1539 if (!pprt) {
1540 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
1541 __func__, port->number, parport);
1542 return;
1543 }
1544
1545 if (parport_claim(pprt)) {
1546 pr_err("could not claim access to parport%d. Aborting.\n",
1547 parport);
1548 goto err_unreg_device;
1549 }
1550
1551
1552
1553
1554 if (lcd.enabled) {
1555 lcd_init();
1556 if (!lcd.charlcd || charlcd_register(lcd.charlcd))
1557 goto err_unreg_device;
1558 }
1559
1560 if (keypad.enabled) {
1561 keypad_init();
1562 if (misc_register(&keypad_dev))
1563 goto err_lcd_unreg;
1564 }
1565 return;
1566
1567err_lcd_unreg:
1568 if (scan_timer.function)
1569 del_timer_sync(&scan_timer);
1570 if (lcd.enabled)
1571 charlcd_unregister(lcd.charlcd);
1572err_unreg_device:
1573 kfree(lcd.charlcd);
1574 lcd.charlcd = NULL;
1575 parport_unregister_device(pprt);
1576 pprt = NULL;
1577}
1578
1579static void panel_detach(struct parport *port)
1580{
1581 if (port->number != parport)
1582 return;
1583
1584 if (!pprt) {
1585 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
1586 __func__, port->number, parport);
1587 return;
1588 }
1589 if (scan_timer.function)
1590 del_timer_sync(&scan_timer);
1591
1592 if (keypad.enabled) {
1593 misc_deregister(&keypad_dev);
1594 keypad_initialized = 0;
1595 }
1596
1597 if (lcd.enabled) {
1598 charlcd_unregister(lcd.charlcd);
1599 lcd.initialized = false;
1600 kfree(lcd.charlcd->drvdata);
1601 kfree(lcd.charlcd);
1602 lcd.charlcd = NULL;
1603 }
1604
1605
1606 parport_release(pprt);
1607 parport_unregister_device(pprt);
1608 pprt = NULL;
1609}
1610
1611static struct parport_driver panel_driver = {
1612 .name = "panel",
1613 .match_port = panel_attach,
1614 .detach = panel_detach,
1615 .devmodel = true,
1616};
1617
1618
1619static int __init panel_init_module(void)
1620{
1621 int selected_keypad_type = NOT_SET, err;
1622
1623
1624 switch (profile) {
1625 case PANEL_PROFILE_CUSTOM:
1626
1627 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
1628 selected_lcd_type = DEFAULT_LCD_TYPE;
1629 break;
1630 case PANEL_PROFILE_OLD:
1631
1632 selected_keypad_type = KEYPAD_TYPE_OLD;
1633 selected_lcd_type = LCD_TYPE_OLD;
1634
1635
1636 if (lcd_width == NOT_SET)
1637 lcd_width = 16;
1638 if (lcd_hwidth == NOT_SET)
1639 lcd_hwidth = 16;
1640 break;
1641 case PANEL_PROFILE_NEW:
1642
1643 selected_keypad_type = KEYPAD_TYPE_NEW;
1644 selected_lcd_type = LCD_TYPE_KS0074;
1645 break;
1646 case PANEL_PROFILE_HANTRONIX:
1647
1648 selected_keypad_type = KEYPAD_TYPE_NONE;
1649 selected_lcd_type = LCD_TYPE_HANTRONIX;
1650 break;
1651 case PANEL_PROFILE_NEXCOM:
1652
1653 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
1654 selected_lcd_type = LCD_TYPE_NEXCOM;
1655 break;
1656 case PANEL_PROFILE_LARGE:
1657
1658 selected_keypad_type = KEYPAD_TYPE_OLD;
1659 selected_lcd_type = LCD_TYPE_OLD;
1660 break;
1661 }
1662
1663
1664
1665
1666
1667 if (keypad_enabled != NOT_SET)
1668 selected_keypad_type = keypad_enabled;
1669 if (keypad_type != NOT_SET)
1670 selected_keypad_type = keypad_type;
1671
1672 keypad.enabled = (selected_keypad_type > 0);
1673
1674 if (lcd_enabled != NOT_SET)
1675 selected_lcd_type = lcd_enabled;
1676 if (lcd_type != NOT_SET)
1677 selected_lcd_type = lcd_type;
1678
1679 lcd.enabled = (selected_lcd_type > 0);
1680
1681 if (lcd.enabled) {
1682
1683
1684
1685
1686 lcd.charset = lcd_charset;
1687 lcd.proto = lcd_proto;
1688 lcd.pins.e = lcd_e_pin;
1689 lcd.pins.rs = lcd_rs_pin;
1690 lcd.pins.rw = lcd_rw_pin;
1691 lcd.pins.cl = lcd_cl_pin;
1692 lcd.pins.da = lcd_da_pin;
1693 lcd.pins.bl = lcd_bl_pin;
1694 }
1695
1696 switch (selected_keypad_type) {
1697 case KEYPAD_TYPE_OLD:
1698 keypad_profile = old_keypad_profile;
1699 break;
1700 case KEYPAD_TYPE_NEW:
1701 keypad_profile = new_keypad_profile;
1702 break;
1703 case KEYPAD_TYPE_NEXCOM:
1704 keypad_profile = nexcom_keypad_profile;
1705 break;
1706 default:
1707 keypad_profile = NULL;
1708 break;
1709 }
1710
1711 if (!lcd.enabled && !keypad.enabled) {
1712
1713 pr_err("panel driver disabled.\n");
1714 return -ENODEV;
1715 }
1716
1717 err = parport_register_driver(&panel_driver);
1718 if (err) {
1719 pr_err("could not register with parport. Aborting.\n");
1720 return err;
1721 }
1722
1723 if (pprt)
1724 pr_info("panel driver registered on parport%d (io=0x%lx).\n",
1725 parport, pprt->port->base);
1726 else
1727 pr_info("panel driver not yet registered\n");
1728 return 0;
1729}
1730
1731static void __exit panel_cleanup_module(void)
1732{
1733 parport_unregister_driver(&panel_driver);
1734}
1735
1736module_init(panel_init_module);
1737module_exit(panel_cleanup_module);
1738MODULE_AUTHOR("Willy Tarreau");
1739MODULE_LICENSE("GPL");
1740