37 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
39 #include <linux/module.h>
41 #include <linux/types.h>
42 #include <linux/errno.h>
43 #include <linux/signal.h>
44 #include <linux/sched.h>
48 #include <linux/slab.h>
50 #include <linux/fcntl.h>
53 #include <linux/kernel.h>
54 #include <linux/ctype.h>
55 #include <linux/parport.h>
56 #include <linux/list.h>
58 #include <linux/reboot.h>
59 #include <generated/utsrelease.h>
65 #define KEYPAD_MINOR 185
67 #define PANEL_VERSION "0.9.5"
69 #define LCD_MAXBYTES 256
71 #define KEYPAD_BUFFER 64
74 #define INPUT_POLL_TIME (HZ/50)
76 #define KEYPAD_REP_START (10)
78 #define KEYPAD_REP_DELAY (2)
81 #define FLASH_LIGHT_TEMPO (200)
84 #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
86 #define PNL_PBUSY 0x80
88 #define PNL_POUTPA 0x20
89 #define PNL_PSELECD 0x10
90 #define PNL_PERRORP 0x08
92 #define PNL_PBIDIR 0x20
94 #define PNL_PINTEN 0x10
95 #define PNL_PSELECP 0x08
96 #define PNL_PINITP 0x04
97 #define PNL_PAUTOLF 0x02
98 #define PNL_PSTROBE 0x01
119 #define PIN_AUTOLF 14
121 #define PIN_SELECP 17
122 #define PIN_NOT_SET 127
124 #define LCD_FLAG_S 0x0001
125 #define LCD_FLAG_ID 0x0002
126 #define LCD_FLAG_B 0x0004
127 #define LCD_FLAG_C 0x0008
128 #define LCD_FLAG_D 0x0010
129 #define LCD_FLAG_F 0x0020
130 #define LCD_FLAG_N 0x0040
131 #define LCD_FLAG_L 0x0080
133 #define LCD_ESCAPE_LEN 24
134 #define LCD_ESCAPE_CHAR 27
137 #define r_ctr(x) (parport_read_control((x)->port))
138 #define r_dtr(x) (parport_read_data((x)->port))
139 #define r_str(x) (parport_read_status((x)->port))
140 #define w_ctr(x, y) (parport_write_control((x)->port, (y)))
141 #define w_dtr(x, y) (parport_write_data((x)->port, (y)))
145 static __u8 scan_mask_o;
147 static __u8 scan_mask_i;
210 static char inputs_stable;
214 static int keypad_buflen;
215 static int keypad_start;
216 static char keypressed;
222 static unsigned long int lcd_flags;
224 static unsigned long int lcd_addr_x;
226 static unsigned long int lcd_addr_y;
230 static int lcd_escape_len = -1;
264 #define LCD_PROTO_PARALLEL 0
265 #define LCD_PROTO_SERIAL 1
266 #define LCD_PROTO_TI_DA8XX_LCD 2
271 #define LCD_CHARSET_NORMAL 0
272 #define LCD_CHARSET_KS0074 1
277 #define LCD_TYPE_NONE 0
278 #define LCD_TYPE_OLD 1
279 #define LCD_TYPE_KS0074 2
280 #define LCD_TYPE_HANTRONIX 3
281 #define LCD_TYPE_NEXCOM 4
282 #define LCD_TYPE_CUSTOM 5
287 #define KEYPAD_TYPE_NONE 0
288 #define KEYPAD_TYPE_OLD 1
289 #define KEYPAD_TYPE_NEW 2
290 #define KEYPAD_TYPE_NEXCOM 3
295 #define PANEL_PROFILE_CUSTOM 0
296 #define PANEL_PROFILE_OLD 1
297 #define PANEL_PROFILE_NEW 2
298 #define PANEL_PROFILE_HANTRONIX 3
299 #define PANEL_PROFILE_NEXCOM 4
300 #define PANEL_PROFILE_LARGE 5
305 #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
306 #define DEFAULT_PARPORT 0
307 #define DEFAULT_LCD LCD_TYPE_OLD
308 #define DEFAULT_KEYPAD KEYPAD_TYPE_OLD
309 #define DEFAULT_LCD_WIDTH 40
310 #define DEFAULT_LCD_BWIDTH 40
311 #define DEFAULT_LCD_HWIDTH 64
312 #define DEFAULT_LCD_HEIGHT 2
313 #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
315 #define DEFAULT_LCD_PIN_E PIN_AUTOLF
316 #define DEFAULT_LCD_PIN_RS PIN_SELECP
317 #define DEFAULT_LCD_PIN_RW PIN_INITP
318 #define DEFAULT_LCD_PIN_SCL PIN_STROBE
319 #define DEFAULT_LCD_PIN_SDA PIN_D0
320 #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
321 #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
323 #ifdef CONFIG_PANEL_PROFILE
324 #undef DEFAULT_PROFILE
325 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
328 #ifdef CONFIG_PANEL_PARPORT
329 #undef DEFAULT_PARPORT
330 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
333 #if DEFAULT_PROFILE == 0
334 #ifdef CONFIG_PANEL_KEYPAD
335 #undef DEFAULT_KEYPAD
336 #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD
339 #ifdef CONFIG_PANEL_LCD
341 #define DEFAULT_LCD CONFIG_PANEL_LCD
344 #ifdef CONFIG_PANEL_LCD_WIDTH
345 #undef DEFAULT_LCD_WIDTH
346 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
349 #ifdef CONFIG_PANEL_LCD_BWIDTH
350 #undef DEFAULT_LCD_BWIDTH
351 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
354 #ifdef CONFIG_PANEL_LCD_HWIDTH
355 #undef DEFAULT_LCD_HWIDTH
356 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
359 #ifdef CONFIG_PANEL_LCD_HEIGHT
360 #undef DEFAULT_LCD_HEIGHT
361 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
364 #ifdef CONFIG_PANEL_LCD_PROTO
365 #undef DEFAULT_LCD_PROTO
366 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
369 #ifdef CONFIG_PANEL_LCD_PIN_E
370 #undef DEFAULT_LCD_PIN_E
371 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
374 #ifdef CONFIG_PANEL_LCD_PIN_RS
375 #undef DEFAULT_LCD_PIN_RS
376 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
379 #ifdef CONFIG_PANEL_LCD_PIN_RW
380 #undef DEFAULT_LCD_PIN_RW
381 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
384 #ifdef CONFIG_PANEL_LCD_PIN_SCL
385 #undef DEFAULT_LCD_PIN_SCL
386 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
389 #ifdef CONFIG_PANEL_LCD_PIN_SDA
390 #undef DEFAULT_LCD_PIN_SDA
391 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
394 #ifdef CONFIG_PANEL_LCD_PIN_BL
395 #undef DEFAULT_LCD_PIN_BL
396 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
399 #ifdef CONFIG_PANEL_LCD_CHARSET
400 #undef DEFAULT_LCD_CHARSET
401 #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
407 static int keypad_open_cnt;
408 static int lcd_open_cnt;
411 static int lcd_initialized;
412 static int keypad_initialized;
414 static int light_tempo;
416 static char lcd_must_clear;
417 static char lcd_left_shift;
418 static char init_in_progress;
420 static void (*lcd_write_cmd) (
int);
421 static void (*lcd_write_data) (
int);
422 static void (*lcd_clear_fast) (
void);
433 static int lcd_height = -1;
437 static int lcd_width = -1;
441 static int lcd_bwidth = -1;
445 static int lcd_hwidth = -1;
449 static int lcd_enabled = -1;
453 static int keypad_enabled = -1;
455 MODULE_PARM_DESC(keypad_enabled,
"Deprecated option, use keypad_type instead");
457 static int lcd_type = -1;
460 "LCD type: 0=none, 1=old //, 2=serial ks0074, "
461 "3=hantronix //, 4=nexcom //, 5=compiled-in");
463 static int lcd_proto = -1;
466 "LCD communication: 0=parallel (//), 1=serial,"
467 "2=TI LCD Interface");
469 static int lcd_charset = -1;
473 static int keypad_type = -1;
476 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, "
482 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
483 "4=16x2 nexcom; default=40x2, old kp");
497 "# of the // port pin connected to LCD 'E' signal, "
498 "with polarity (-17..17)");
503 "# of the // port pin connected to LCD 'RS' signal, "
504 "with polarity (-17..17)");
509 "# of the // port pin connected to LCD 'RW' signal, "
510 "with polarity (-17..17)");
515 "# of the // port pin connected to LCD backlight, "
516 "with polarity (-17..17)");
521 "# of the // port pin connected to serial LCD 'SDA' "
522 "signal, with polarity (-17..17)");
527 "# of the // port pin connected to serial LCD 'SCL' "
528 "signal, with polarity (-17..17)");
530 static unsigned char *lcd_char_conv;
533 static unsigned char lcd_char_conv_ks0074[256] = {
535 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
536 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
537 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
538 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
539 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
540 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
541 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
542 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
543 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
544 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
545 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
546 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
547 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
548 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
549 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
550 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
551 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
552 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
553 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
554 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
555 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
556 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
557 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
558 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
559 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
560 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
561 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
562 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
563 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
564 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
565 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
566 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
570 {
"S0",
"Left\n",
"Left\n",
""},
571 {
"S1",
"Down\n",
"Down\n",
""},
572 {
"S2",
"Up\n",
"Up\n",
""},
573 {
"S3",
"Right\n",
"Right\n",
""},
574 {
"S4",
"Esc\n",
"Esc\n",
""},
575 {
"S5",
"Ret\n",
"Ret\n",
""},
581 {
"S0",
"Left\n",
"Left\n",
""},
582 {
"S1",
"Down\n",
"Down\n",
""},
583 {
"S2",
"Up\n",
"Up\n",
""},
584 {
"S3",
"Right\n",
"Right\n",
""},
585 {
"S4s5",
"",
"Esc\n",
"Esc\n"},
586 {
"s4S5",
"",
"Ret\n",
"Ret\n"},
587 {
"S4S5",
"Help\n",
"",
""},
594 {
"a-p-e-",
"Down\n",
"Down\n",
""},
595 {
"a-p-E-",
"Ret\n",
"Ret\n",
""},
596 {
"a-P-E-",
"Esc\n",
"Esc\n",
""},
597 {
"a-P-e-",
"Up\n",
"Up\n",
""},
614 static void init_scan_timer(
void);
617 static int set_data_bits(
void)
622 for (bit = 0; bit <
LCD_BITS; bit++)
637 static int set_ctrl_bits(
void)
642 for (bit = 0; bit <
LCD_BITS; bit++)
657 static void panel_set_bits(
void)
674 int d_bit, c_bit, inv;
676 d_val[0] = c_val[0] = d_val[1] = c_val[1] = 0;
677 d_val[2] = c_val[2] = 0xFF;
694 d_bit = 1 << (pin - 2);
721 static void long_sleep(
int ms)
734 static void lcd_send_serial(
int byte)
740 for (bit = 0; bit < 8; bit++) {
754 static void lcd_backlight(
int on)
760 spin_lock_irq(&pprt_lock);
763 spin_unlock_irq(&pprt_lock);
767 static void lcd_write_cmd_s(
int cmd)
769 spin_lock_irq(&pprt_lock);
770 lcd_send_serial(0x1F);
771 lcd_send_serial(cmd & 0x0F);
772 lcd_send_serial((cmd >> 4) & 0x0F);
774 spin_unlock_irq(&pprt_lock);
778 static void lcd_write_data_s(
int data)
780 spin_lock_irq(&pprt_lock);
781 lcd_send_serial(0x5F);
782 lcd_send_serial(data & 0x0F);
783 lcd_send_serial((data >> 4) & 0x0F);
785 spin_unlock_irq(&pprt_lock);
789 static void lcd_write_cmd_p8(
int cmd)
791 spin_lock_irq(&pprt_lock);
807 spin_unlock_irq(&pprt_lock);
811 static void lcd_write_data_p8(
int data)
813 spin_lock_irq(&pprt_lock);
829 spin_unlock_irq(&pprt_lock);
833 static void lcd_write_cmd_tilcd(
int cmd)
835 spin_lock_irq(&pprt_lock);
839 spin_unlock_irq(&pprt_lock);
843 static void lcd_write_data_tilcd(
int data)
845 spin_lock_irq(&pprt_lock);
849 spin_unlock_irq(&pprt_lock);
852 static void lcd_gotoxy(
void)
855 | (lcd_addr_y ? lcd_hwidth : 0)
858 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
859 (lcd_hwidth - 1) : lcd_bwidth - 1));
864 if (lcd_addr_x < lcd_bwidth) {
865 if (lcd_char_conv !=
NULL)
866 c = lcd_char_conv[(
unsigned char)c];
871 if (lcd_addr_x == lcd_bwidth)
876 static void lcd_clear_fast_s(
void)
879 lcd_addr_x = lcd_addr_y = 0;
882 spin_lock_irq(&pprt_lock);
883 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
884 lcd_send_serial(0x5F);
885 lcd_send_serial(
' ' & 0x0F);
886 lcd_send_serial((
' ' >> 4) & 0x0F);
889 spin_unlock_irq(&pprt_lock);
891 lcd_addr_x = lcd_addr_y = 0;
896 static void lcd_clear_fast_p8(
void)
899 lcd_addr_x = lcd_addr_y = 0;
902 spin_lock_irq(&pprt_lock);
903 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
924 spin_unlock_irq(&pprt_lock);
926 lcd_addr_x = lcd_addr_y = 0;
931 static void lcd_clear_fast_tilcd(
void)
934 lcd_addr_x = lcd_addr_y = 0;
937 spin_lock_irq(&pprt_lock);
938 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
944 spin_unlock_irq(&pprt_lock);
946 lcd_addr_x = lcd_addr_y = 0;
951 static void lcd_clear_display(
void)
954 lcd_addr_x = lcd_addr_y = 0;
959 static void lcd_init_display(
void)
962 lcd_flags = ((lcd_height > 1) ?
LCD_FLAG_N : 0)
989 lcd_backlight((lcd_flags &
LCD_FLAG_L) ? 1 : 0);
1006 static inline int handle_lcd_special_code(
void)
1012 char *esc = lcd_escape + 2;
1013 int oldflags = lcd_flags;
1022 lcd_flags &= ~LCD_FLAG_D;
1030 lcd_flags &= ~LCD_FLAG_C;
1051 if (scan_timer.function !=
NULL) {
1052 if (light_tempo == 0 && ((lcd_flags &
LCD_FLAG_L) == 0))
1059 lcd_flags &= ~LCD_FLAG_F;
1074 if (lcd_addr_x > 0) {
1076 if (lcd_addr_x < lcd_bwidth)
1077 lcd_write_cmd(0x10);
1083 if (lcd_addr_x < lcd_width) {
1087 lcd_write_cmd(0x14);
1094 lcd_write_cmd(0x18);
1099 lcd_write_cmd(0x1C);
1104 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1105 lcd_write_data(
' ');
1126 unsigned char cgbytes[8];
1127 unsigned char cgaddr;
1138 cgaddr = *(esc++) -
'0';
1147 while (*esc && cgoffset < 8) {
1149 if (*esc >=
'0' && *esc <=
'9')
1150 value |= (*esc -
'0') << shift;
1151 else if (*esc >=
'A' && *esc <=
'Z')
1152 value |= (*esc -
'A' + 10) << shift;
1153 else if (*esc >=
'a' && *esc <=
'z')
1154 value |= (*esc -
'a' + 10) << shift;
1161 cgbytes[cgoffset++] =
value;
1168 lcd_write_cmd(0x40 | (cgaddr * 8));
1169 for (addr = 0; addr < cgoffset; addr++)
1170 lcd_write_data(cgbytes[addr]);
1185 if (kstrtoul(esc, 10, &lcd_addr_x) < 0)
1187 }
else if (*esc ==
'y') {
1189 if (kstrtoul(esc, 10, &lcd_addr_y) < 0)
1201 if (oldflags != lcd_flags) {
1203 if ((oldflags ^ lcd_flags) &
1207 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1208 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1211 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F |
LCD_FLAG_N))
1213 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1216 else if ((oldflags ^ lcd_flags) & (
LCD_FLAG_L)) {
1219 else if (light_tempo == 0)
1230 const char *
buf,
size_t count, loff_t *ppos)
1235 for (; count-- > 0; (ppos ? (*ppos)++ : 0), ++tmp) {
1248 if ((c !=
'\n') && lcd_escape_len >= 0) {
1250 lcd_escape[lcd_escape_len++] =
c;
1251 lcd_escape[lcd_escape_len] = 0;
1254 lcd_escape_len = -1;
1260 lcd_escape[lcd_escape_len] = 0;
1264 if (lcd_addr_x > 0) {
1267 if (lcd_addr_x < lcd_bwidth)
1269 lcd_write_cmd(0x10);
1273 lcd_write_data(
' ');
1275 lcd_write_cmd(0x10);
1284 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1285 lcd_write_data(
' ');
1287 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1308 if (lcd_escape_len >= 2) {
1311 if (!
strcmp(lcd_escape,
"[2J")) {
1315 }
else if (!
strcmp(lcd_escape,
"[H")) {
1317 lcd_addr_x = lcd_addr_y = 0;
1322 else if ((lcd_escape_len >= 3) &&
1323 (lcd_escape[0] ==
'[') &&
1324 (lcd_escape[1] ==
'L')) {
1325 processed = handle_lcd_special_code();
1332 lcd_escape_len = -1;
1339 static int lcd_open(
struct inode *
inode,
struct file *file)
1347 if (lcd_must_clear) {
1348 lcd_clear_display();
1355 static int lcd_release(
struct inode *inode,
struct file *file)
1364 .release = lcd_release,
1377 if (lcd_enabled && lcd_initialized)
1389 if (lcd_charset < 0)
1409 if (lcd_charset < 0)
1431 if (lcd_charset < 0)
1453 if (lcd_charset < 0)
1462 if (lcd_charset < 0)
1483 if (lcd_bwidth <= 0)
1485 if (lcd_hwidth <= 0)
1487 if (lcd_height <= 0)
1491 lcd_write_cmd = lcd_write_cmd_s;
1492 lcd_write_data = lcd_write_data_s;
1493 lcd_clear_fast = lcd_clear_fast_s;
1501 lcd_write_cmd = lcd_write_cmd_p8;
1502 lcd_write_data = lcd_write_data_p8;
1503 lcd_clear_fast = lcd_clear_fast_p8;
1512 lcd_write_cmd = lcd_write_cmd_tilcd;
1513 lcd_write_data = lcd_write_data_tilcd;
1514 lcd_clear_fast = lcd_clear_fast_tilcd;
1533 if (lcd_charset < 0)
1537 lcd_char_conv = lcd_char_conv_ks0074;
1539 lcd_char_conv =
NULL;
1560 lcd_initialized = 1;
1564 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1565 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1572 lcd_addr_x = lcd_addr_y = 0;
1583 char *buf,
size_t count, loff_t *ppos)
1589 if (keypad_buflen == 0) {
1598 for (; count-- > 0 && (keypad_buflen > 0);
1599 ++
i, ++
tmp, --keypad_buflen) {
1600 put_user(keypad_buffer[keypad_start], tmp);
1608 static int keypad_open(
struct inode *inode,
struct file *file)
1611 if (keypad_open_cnt)
1622 static int keypad_release(
struct inode *inode,
struct file *file)
1630 .open = keypad_open,
1631 .release = keypad_release,
1641 static void keypad_send_key(
char *
string,
int max_len)
1643 if (init_in_progress)
1647 if (keypad_open_cnt > 0) {
1648 while (max_len-- && keypad_buflen <
KEYPAD_BUFFER && *
string) {
1649 keypad_buffer[(keypad_start + keypad_buflen++) %
1666 static void phys_scan_contacts(
void)
1673 phys_prev = phys_curr;
1674 phys_read_prev = phys_read;
1678 oldval =
r_dtr(pprt) | scan_mask_o;
1680 w_dtr(pprt, oldval & ~scan_mask_o);
1685 w_dtr(pprt, oldval);
1695 phys_read |= (
pmask_t) gndmask << 40;
1697 if (bitmask != gndmask) {
1702 for (bit = 0; bit < 8; bit++) {
1705 if (!(scan_mask_o & bitval))
1708 w_dtr(pprt, oldval & ~bitval);
1710 phys_read |= (
pmask_t) bitmask << (5 * bit);
1712 w_dtr(pprt, oldval);
1716 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1717 (phys_read & ~(phys_read ^ phys_read_prev));
1740 if (((phys_prev & input->
mask) == input->
value)
1741 && ((phys_curr & input->
mask) > input->
value)) {
1747 if ((phys_curr & input->
mask) == input->
value) {
1751 if (input->
u.
std.press_fct !=
NULL)
1752 input->
u.
std.press_fct(input->
u.
std.press_data);
1758 char *press_str = input->
u.
kbd.press_str;
1760 keypad_send_key(press_str,
1764 if (input->
u.
kbd.repeat_str[0]) {
1765 char *repeat_str = input->
u.
kbd.repeat_str;
1768 keypad_send_key(repeat_str,
1769 sizeof(repeat_str));
1787 static inline void input_state_falling(
struct logical_input *input)
1791 if (((phys_prev & input->
mask) == input->
value)
1792 && ((phys_curr & input->
mask) > input->
value)) {
1798 if ((phys_curr & input->
mask) == input->
value) {
1803 if (input->
u.
kbd.repeat_str[0]) {
1804 char *repeat_str = input->
u.
kbd.repeat_str;
1807 keypad_send_key(repeat_str,
1808 sizeof(repeat_str));
1820 void (*release_fct)(
int) = input->
u.
std.release_fct;
1822 release_fct(input->
u.
std.release_data);
1824 char *release_str = input->
u.
kbd.release_str;
1826 keypad_send_key(release_str,
1827 sizeof(release_str));
1837 static void panel_process_inputs(
void)
1847 switch (input->
state) {
1849 if ((phys_curr & input->
mask) != input->
value)
1858 if ((phys_prev & input->
mask) == input->
value)
1864 if ((phys_curr & input->
mask) != input->
value) {
1877 if (input_state_high(input))
1881 input_state_falling(input);
1886 static void panel_scan_timer(
void)
1888 if (keypad_enabled && keypad_initialized) {
1889 if (spin_trylock_irq(&pprt_lock)) {
1890 phys_scan_contacts();
1893 spin_unlock_irq(&pprt_lock);
1896 if (!inputs_stable || phys_curr != phys_prev)
1897 panel_process_inputs();
1900 if (lcd_enabled && lcd_initialized) {
1902 if (light_tempo == 0 && ((lcd_flags &
LCD_FLAG_L) == 0))
1905 }
else if (light_tempo > 0) {
1907 if (light_tempo == 0 && ((lcd_flags &
LCD_FLAG_L) == 0))
1915 static void init_scan_timer(
void)
1917 if (scan_timer.function !=
NULL)
1922 scan_timer.data = 0;
1923 scan_timer.function = (
void *)&panel_scan_timer;
1933 char *imask,
char *omask)
1935 static char sigtab[10] =
"EeSsPpAaBb";
1939 om = im = m = v = 0ULL;
1942 for (in = 0; (in <
sizeof(sigtab)) &&
1943 (sigtab[
in] != *
name); in++)
1945 if (in >=
sizeof(sigtab))
1955 }
else if (*name ==
'-')
1960 bit = (out * 5) + in;
1980 static struct logical_input *panel_bind_key(
char *name,
char *press,
1989 if (!input_name2mask(name, &key->
mask, &key->
value, &scan_mask_i,
2001 strncpy(key->
u.
kbd.repeat_str, repeat,
sizeof(key->
u.
kbd.repeat_str));
2003 sizeof(key->
u.
kbd.release_str));
2004 list_add(&key->
list, &logical_inputs);
2015 static struct logical_input *panel_bind_callback(
char *name,
2028 if (!input_name2mask(name, &callback->
mask, &callback->
value,
2029 &scan_mask_i, &scan_mask_o))
2040 list_add(&callback->
list, &logical_inputs);
2045 static void keypad_init(
void)
2053 for (keynum = 0; keypad_profile[
keynum][0][0]; keynum++) {
2054 panel_bind_key(keypad_profile[keynum][0],
2055 keypad_profile[keynum][1],
2056 keypad_profile[keynum][2],
2057 keypad_profile[keynum][3]);
2061 keypad_initialized = 1;
2071 if (lcd_enabled && lcd_initialized) {
2075 (
"\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2079 (
"\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2103 pr_err(
"%s: port->number=%d parport=%d, already registered!\n",
2113 pr_err(
"%s: port->number=%d parport=%d, parport_register_device() failed\n",
2119 pr_err(
"could not claim access to parport%d. Aborting.\n",
2121 goto err_unreg_device;
2130 goto err_unreg_device;
2133 if (keypad_enabled) {
2148 static void panel_detach(
struct parport *port)
2154 pr_err(
"%s: port->number=%d parport=%d, nothing to unregister.\n",
2159 if (keypad_enabled && keypad_initialized) {
2161 keypad_initialized = 0;
2164 if (lcd_enabled && lcd_initialized) {
2166 lcd_initialized = 0;
2176 .attach = panel_attach,
2177 .detach = panel_detach,
2184 if (keypad_type < 0)
2185 keypad_type = keypad_enabled;
2188 lcd_type = lcd_enabled;
2197 if (keypad_type < 0)
2204 if (keypad_type < 0)
2215 if (keypad_type < 0)
2222 if (keypad_type < 0)
2229 if (keypad_type < 0)
2236 if (keypad_type < 0)
2243 lcd_enabled = (lcd_type > 0);
2244 keypad_enabled = (keypad_type > 0);
2246 switch (keypad_type) {
2257 keypad_profile =
NULL;
2262 init_in_progress = 1;
2265 pr_err(
"could not register with parport. Aborting.\n");
2269 if (!lcd_enabled && !keypad_enabled) {
2285 " registered on parport%d (io=0x%lx).\n",
parport,
2289 " not yet registered\n");
2292 init_in_progress = 0;
2296 static int __init panel_init_module(
void)
2301 static void __exit panel_cleanup_module(
void)
2305 if (scan_timer.function !=
NULL)
2309 if (keypad_enabled) {
2311 keypad_initialized = 0;
2316 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2318 lcd_initialized = 0;