2 * Front panel driver for Linux
3 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
10 * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
11 * connected to a parallel printer port.
13 * The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
14 * serial module compatible with Samsung's KS0074. The pins may be connected in
15 * any combination, everything is programmable.
17 * The keypad consists in a matrix of push buttons connecting input pins to
18 * data output pins or to the ground. The combinations have to be hard-coded
19 * in the driver, though several profiles exist and adding new ones is easy.
21 * Several profiles are provided for commonly found LCD+keypad modules on the
22 * market, such as those found in Nexcom's appliances.
25 * - the initialization/deinitialization process is very dirty and should
26 * be rewritten. It may even be buggy.
29 * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
30 * - make the LCD a part of a virtual screen of Vx*Vy
31 * - make the inputs list smp-safe
32 * - change the keyboard to a double mapping : signals -> key_id -> values
33 * so that applications can change values without knowing signals
37 #include <linux/module.h>
39 #include <linux/types.h>
40 #include <linux/errno.h>
41 #include <linux/signal.h>
42 #include <linux/sched.h>
43 #include <linux/spinlock.h>
44 #include <linux/smp_lock.h>
45 #include <linux/interrupt.h>
46 #include <linux/miscdevice.h>
47 #include <linux/slab.h>
48 #include <linux/ioport.h>
49 #include <linux/fcntl.h>
50 #include <linux/init.h>
51 #include <linux/delay.h>
52 #include <linux/ctype.h>
53 #include <linux/parport.h>
54 #include <linux/version.h>
55 #include <linux/list.h>
56 #include <linux/notifier.h>
57 #include <linux/reboot.h>
58 #include <linux/utsrelease.h>
61 #include <asm/uaccess.h>
62 #include <asm/system.h>
64 /* smartcard length */
65 #define SMARTCARD_BYTES 64
67 #define KEYPAD_MINOR 185
68 #define SMARTCARD_MINOR 186
70 #define PANEL_VERSION "0.9.5"
72 #define LCD_MAXBYTES 256 /* max burst write */
74 #define SMARTCARD_LOGICAL_DETECTOR "S6" /* D6 wired to SELECT = card inserted */
76 #define KEYPAD_BUFFER 64
77 #define INPUT_POLL_TIME (HZ/50) /* poll the keyboard this every second */
78 #define KEYPAD_REP_START (10) /* a key starts to repeat after this times INPUT_POLL_TIME */
79 #define KEYPAD_REP_DELAY (2) /* a key repeats this times INPUT_POLL_TIME */
81 #define FLASH_LIGHT_TEMPO (200) /* keep the light on this times INPUT_POLL_TIME for each flash */
83 /* converts an r_str() input to an active high, bits string : 000BAOSE */
84 #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
86 #define PNL_PBUSY 0x80 /* inverted input, active low */
87 #define PNL_PACK 0x40 /* direct input, active low */
88 #define PNL_POUTPA 0x20 /* direct input, active high */
89 #define PNL_PSELECD 0x10 /* direct input, active high */
90 #define PNL_PERRORP 0x08 /* direct input, active low */
92 #define PNL_PBIDIR 0x20 /* bi-directional ports */
93 #define PNL_PINTEN 0x10 /* high to read data in or-ed with data out */
94 #define PNL_PSELECP 0x08 /* inverted output, active low */
95 #define PNL_PINITP 0x04 /* direct output, active low */
96 #define PNL_PAUTOLF 0x02 /* inverted output, active low */
97 #define PNL_PSTROBE 0x01 /* inverted output */
118 #define PIN_AUTOLF 14
120 #define PIN_SELECP 17
121 #define PIN_NOT_SET 127
123 /* some smartcard-specific signals */
124 #define PNL_SC_IO PNL_PD1 /* Warning! inverted output, 0=highZ */
125 #define PNL_SC_RST PNL_PD2
126 #define PNL_SC_CLK PNL_PD3
127 #define PNL_SC_RW PNL_PD4
128 #define PNL_SC_ENA PNL_PINITP
129 #define PNL_SC_IOR PNL_PACK
130 #define PNL_SC_BITS (PNL_SC_IO | PNL_SC_RST | PNL_SC_CLK | PNL_SC_RW)
132 #define LCD_FLAG_S 0x0001
133 #define LCD_FLAG_ID 0x0002
134 #define LCD_FLAG_B 0x0004 /* blink on */
135 #define LCD_FLAG_C 0x0008 /* cursor on */
136 #define LCD_FLAG_D 0x0010 /* display on */
137 #define LCD_FLAG_F 0x0020 /* large font mode */
138 #define LCD_FLAG_N 0x0040 /* 2-rows mode */
139 #define LCD_FLAG_L 0x0080 /* backlight enabled */
141 #define LCD_ESCAPE_LEN 24 /* 24 chars max for an LCD escape command */
142 #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
144 /* macros to simplify use of the parallel port */
145 #define r_ctr(x) (parport_read_control((x)->port))
146 #define r_dtr(x) (parport_read_data((x)->port))
147 #define r_str(x) (parport_read_status((x)->port))
148 #define w_ctr(x, y) do { parport_write_control((x)->port, (y)); } while (0)
149 #define w_dtr(x, y) do { parport_write_data((x)->port, (y)); } while (0)
151 /* this defines which bits are to be used and which ones to be ignored */
152 static __u8 scan_mask_o
; /* logical or of the output bits involved in the scan matrix */
153 static __u8 scan_mask_i
; /* logical or of the input bits involved in the scan matrix */
155 typedef __u64 pmask_t
;
169 struct logical_input
{
170 struct list_head list
;
173 enum input_type type
;
174 enum input_state state
;
175 __u8 rise_time
, fall_time
;
176 __u8 rise_timer
, fall_timer
, high_timer
;
179 struct { /* this structure is valid when type == INPUT_TYPE_STD */
180 void (*press_fct
) (int);
181 void (*release_fct
) (int);
185 struct { /* this structure is valid when type == INPUT_TYPE_KBD */
186 /* strings can be full-length (ie. non null-terminated) */
187 char press_str
[sizeof(void *) + sizeof(int)];
188 char repeat_str
[sizeof(void *) + sizeof(int)];
189 char release_str
[sizeof(void *) + sizeof(int)];
194 LIST_HEAD(logical_inputs
); /* list of all defined logical inputs */
196 /* physical contacts history
197 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
198 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
199 * corresponds to the ground.
200 * Within each group, bits are stored in the same order as read on the port :
201 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
202 * So, each __u64 (or pmask_t) is represented like this :
203 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
204 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
206 static pmask_t phys_read
; /* what has just been read from the I/O ports */
207 static pmask_t phys_read_prev
; /* previous phys_read */
208 static pmask_t phys_curr
; /* stabilized phys_read (phys_read|phys_read_prev) */
209 static pmask_t phys_prev
; /* previous phys_curr */
210 static char inputs_stable
; /* 0 means that at least one logical signal needs be computed */
212 /* these variables are specific to the smartcard */
213 static __u8 smartcard_data
[SMARTCARD_BYTES
];
214 static int smartcard_ptr
; /* pointer to half bytes in smartcard_data */
216 /* these variables are specific to the keypad */
217 static char keypad_buffer
[KEYPAD_BUFFER
];
218 static int keypad_buflen
;
219 static int keypad_start
;
220 static char keypressed
;
221 static wait_queue_head_t keypad_read_wait
;
222 static wait_queue_head_t smartcard_read_wait
;
224 /* lcd-specific variables */
225 static unsigned long int lcd_flags
; /* contains the LCD config state */
226 static unsigned long int lcd_addr_x
; /* contains the LCD X offset */
227 static unsigned long int lcd_addr_y
; /* contains the LCD Y offset */
228 static char lcd_escape
[LCD_ESCAPE_LEN
+ 1]; /* current escape sequence, 0 terminated */
229 static int lcd_escape_len
= -1; /* not in escape state. >=0 = escape cmd len */
232 * Bit masks to convert LCD signals to parallel port outputs.
233 * _d_ are values for data port, _c_ are for control port.
234 * [0] = signal OFF, [1] = signal ON, [2] = mask
241 * one entry for each bit on the LCD
252 * each bit can be either connected to a DATA or CTRL port
258 static unsigned char lcd_bits
[LCD_PORTS
][LCD_BITS
][BIT_STATES
];
263 #define LCD_PROTO_PARALLEL 0
264 #define LCD_PROTO_SERIAL 1
269 #define LCD_CHARSET_NORMAL 0
270 #define LCD_CHARSET_KS0074 1
275 #define LCD_TYPE_NONE 0
276 #define LCD_TYPE_OLD 1
277 #define LCD_TYPE_KS0074 2
278 #define LCD_TYPE_HANTRONIX 3
279 #define LCD_TYPE_NEXCOM 4
280 #define LCD_TYPE_CUSTOM 5
285 #define KEYPAD_TYPE_NONE 0
286 #define KEYPAD_TYPE_OLD 1
287 #define KEYPAD_TYPE_NEW 2
288 #define KEYPAD_TYPE_NEXCOM 3
293 #define PANEL_PROFILE_CUSTOM 0
294 #define PANEL_PROFILE_OLD 1
295 #define PANEL_PROFILE_NEW 2
296 #define PANEL_PROFILE_HANTRONIX 3
297 #define PANEL_PROFILE_NEXCOM 4
298 #define PANEL_PROFILE_LARGE 5
301 * Construct custom config from the kernel's configuration
303 #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
304 #define DEFAULT_PARPORT 0
305 #define DEFAULT_LCD LCD_TYPE_OLD
306 #define DEFAULT_KEYPAD KEYPAD_TYPE_OLD
307 #define DEFAULT_SMARTCARD 0
308 #define DEFAULT_LCD_WIDTH 40
309 #define DEFAULT_LCD_BWIDTH 40
310 #define DEFAULT_LCD_HWIDTH 64
311 #define DEFAULT_LCD_HEIGHT 2
312 #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
314 #define DEFAULT_LCD_PIN_E PIN_AUTOLF
315 #define DEFAULT_LCD_PIN_RS PIN_SELECP
316 #define DEFAULT_LCD_PIN_RW PIN_INITP
317 #define DEFAULT_LCD_PIN_SCL PIN_STROBE
318 #define DEFAULT_LCD_PIN_SDA PIN_D0
319 #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
320 #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
322 #ifdef CONFIG_PANEL_PROFILE
323 #undef DEFAULT_PROFILE
324 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
327 #ifdef CONFIG_PANEL_PARPORT
328 #undef DEFAULT_PARPORT
329 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
332 #if DEFAULT_PROFILE == 0 /* custom */
333 #ifdef CONFIG_PANEL_KEYPAD
334 #undef DEFAULT_KEYPAD
335 #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD
338 #ifdef CONFIG_PANEL_SMARTCARD
339 #undef DEFAULT_SMARTCARD
340 #define DEFAULT_SMARTCARD 1
343 #ifdef CONFIG_PANEL_LCD
345 #define DEFAULT_LCD CONFIG_PANEL_LCD
348 #ifdef CONFIG_PANEL_LCD_WIDTH
349 #undef DEFAULT_LCD_WIDTH
350 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
353 #ifdef CONFIG_PANEL_LCD_BWIDTH
354 #undef DEFAULT_LCD_BWIDTH
355 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
358 #ifdef CONFIG_PANEL_LCD_HWIDTH
359 #undef DEFAULT_LCD_HWIDTH
360 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
363 #ifdef CONFIG_PANEL_LCD_HEIGHT
364 #undef DEFAULT_LCD_HEIGHT
365 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
368 #ifdef CONFIG_PANEL_LCD_PROTO
369 #undef DEFAULT_LCD_PROTO
370 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
373 #ifdef CONFIG_PANEL_LCD_PIN_E
374 #undef DEFAULT_LCD_PIN_E
375 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
378 #ifdef CONFIG_PANEL_LCD_PIN_RS
379 #undef DEFAULT_LCD_PIN_RS
380 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
383 #ifdef CONFIG_PANEL_LCD_PIN_RW
384 #undef DEFAULT_LCD_PIN_RW
385 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
388 #ifdef CONFIG_PANEL_LCD_PIN_SCL
389 #undef DEFAULT_LCD_PIN_SCL
390 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
393 #ifdef CONFIG_PANEL_LCD_PIN_SDA
394 #undef DEFAULT_LCD_PIN_SDA
395 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
398 #ifdef CONFIG_PANEL_LCD_PIN_BL
399 #undef DEFAULT_LCD_PIN_BL
400 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
403 #ifdef CONFIG_PANEL_LCD_CHARSET
404 #undef DEFAULT_LCD_CHARSET
405 #define DEFAULT_LCD_CHARSET
408 #endif /* DEFAULT_PROFILE == 0 */
410 /* global variables */
411 static int smartcard_open_cnt
; /* #times opened */
412 static int keypad_open_cnt
; /* #times opened */
413 static int lcd_open_cnt
; /* #times opened */
414 static struct pardevice
*pprt
;
416 static int lcd_initialized
;
417 static int keypad_initialized
;
418 static int smartcard_initialized
;
420 static int light_tempo
;
422 static char lcd_must_clear
;
423 static char lcd_left_shift
;
424 static char init_in_progress
;
426 static void (*lcd_write_cmd
) (int);
427 static void (*lcd_write_data
) (int);
428 static void (*lcd_clear_fast
) (void);
430 static DEFINE_SPINLOCK(pprt_lock
);
431 static struct timer_list scan_timer
;
433 MODULE_DESCRIPTION("Generic parallel port LCD/Keypad/Smartcard driver");
435 static int parport
= -1;
436 module_param(parport
, int, 0000);
437 MODULE_PARM_DESC(parport
, "Parallel port index (0=lpt1, 1=lpt2, ...)");
439 static int lcd_height
= -1;
440 module_param(lcd_height
, int, 0000);
441 MODULE_PARM_DESC(lcd_height
, "Number of lines on the LCD");
443 static int lcd_width
= -1;
444 module_param(lcd_width
, int, 0000);
445 MODULE_PARM_DESC(lcd_width
, "Number of columns on the LCD");
447 static int lcd_bwidth
= -1; /* internal buffer width (usually 40) */
448 module_param(lcd_bwidth
, int, 0000);
449 MODULE_PARM_DESC(lcd_bwidth
, "Internal LCD line width (40)");
451 static int lcd_hwidth
= -1; /* hardware buffer width (usually 64) */
452 module_param(lcd_hwidth
, int, 0000);
453 MODULE_PARM_DESC(lcd_hwidth
, "LCD line hardware address (64)");
455 static int lcd_enabled
= -1;
456 module_param(lcd_enabled
, int, 0000);
457 MODULE_PARM_DESC(lcd_enabled
, "Deprecated option, use lcd_type instead");
459 static int keypad_enabled
= -1;
460 module_param(keypad_enabled
, int, 0000);
461 MODULE_PARM_DESC(keypad_enabled
, "Deprecated option, use keypad_type instead");
463 static int lcd_type
= -1;
464 module_param(lcd_type
, int, 0000);
465 MODULE_PARM_DESC(lcd_type
,
466 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
468 static int lcd_proto
= -1;
469 module_param(lcd_proto
, int, 0000);
470 MODULE_PARM_DESC(lcd_proto
, "LCD communication: 0=parallel (//), 1=serial");
472 static int lcd_charset
= -1;
473 module_param(lcd_charset
, int, 0000);
474 MODULE_PARM_DESC(lcd_charset
, "LCD character set: 0=standard, 1=KS0074");
476 static int keypad_type
= -1;
477 module_param(keypad_type
, int, 0000);
478 MODULE_PARM_DESC(keypad_type
,
479 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
481 static int smartcard_enabled
= -1;
482 module_param(smartcard_enabled
, int, 0000);
483 MODULE_PARM_DESC(smartcard_enabled
,
484 "Smartcard reader: 0=disabled (default), 1=enabled");
486 static int profile
= DEFAULT_PROFILE
;
487 module_param(profile
, int, 0000);
488 MODULE_PARM_DESC(profile
,
489 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; 4=16x2 nexcom; default=40x2, old kp");
492 * These are the parallel port pins the LCD control signals are connected to.
493 * Set this to 0 if the signal is not used. Set it to its opposite value
494 * (negative) if the signal is negated. -MAXINT is used to indicate that the
495 * pin has not been explicitly specified.
497 * WARNING! no check will be performed about collisions with keypad/smartcard !
500 static int lcd_e_pin
= PIN_NOT_SET
;
501 module_param(lcd_e_pin
, int, 0000);
502 MODULE_PARM_DESC(lcd_e_pin
,
503 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
505 static int lcd_rs_pin
= PIN_NOT_SET
;
506 module_param(lcd_rs_pin
, int, 0000);
507 MODULE_PARM_DESC(lcd_rs_pin
,
508 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
510 static int lcd_rw_pin
= PIN_NOT_SET
;
511 module_param(lcd_rw_pin
, int, 0000);
512 MODULE_PARM_DESC(lcd_rw_pin
,
513 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
515 static int lcd_bl_pin
= PIN_NOT_SET
;
516 module_param(lcd_bl_pin
, int, 0000);
517 MODULE_PARM_DESC(lcd_bl_pin
,
518 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
520 static int lcd_da_pin
= PIN_NOT_SET
;
521 module_param(lcd_da_pin
, int, 0000);
522 MODULE_PARM_DESC(lcd_da_pin
,
523 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
525 static int lcd_cl_pin
= PIN_NOT_SET
;
526 module_param(lcd_cl_pin
, int, 0000);
527 MODULE_PARM_DESC(lcd_cl_pin
,
528 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
530 static unsigned char *lcd_char_conv
;
532 /* for some LCD drivers (ks0074) we need a charset conversion table. */
533 static unsigned char lcd_char_conv_ks0074
[256] = {
534 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
535 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
536 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
537 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
538 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
539 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
540 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
541 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
542 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
543 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
544 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
545 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
546 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
547 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
548 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
549 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
550 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
551 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
552 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
553 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
554 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
555 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
556 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
557 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
558 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
559 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
560 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
561 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
562 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
563 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
564 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
565 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
566 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
569 char old_keypad_profile
[][4][9] = {
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", ""},
579 /* signals, press, repeat, release */
580 char new_keypad_profile
[][4][9] = {
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", "", ""},
588 /* add new signals above this line */
592 /* signals, press, repeat, release */
593 char nexcom_keypad_profile
[][4][9] = {
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", ""},
598 /* add new signals above this line */
602 static char (*keypad_profile
)[4][9] = old_keypad_profile
;
604 /* FIXME: this should be converted to a bit array containing signals states */
606 unsigned char e
; /* parallel LCD E (data latch on falling edge) */
607 unsigned char rs
; /* parallel LCD RS (0 = cmd, 1 = data) */
608 unsigned char rw
; /* parallel LCD R/W (0 = W, 1 = R) */
609 unsigned char bl
; /* parallel LCD backlight (0 = off, 1 = on) */
610 unsigned char cl
; /* serial LCD clock (latch on rising edge) */
611 unsigned char da
; /* serial LCD data */
614 static void init_scan_timer(void);
616 /* sets data port bits according to current signals values */
617 static int set_data_bits(void)
622 for (bit
= 0; bit
< LCD_BITS
; bit
++)
623 val
&= lcd_bits
[LCD_PORT_D
][bit
][BIT_MSK
];
625 val
|= lcd_bits
[LCD_PORT_D
][LCD_BIT_E
][bits
.e
]
626 | lcd_bits
[LCD_PORT_D
][LCD_BIT_RS
][bits
.rs
]
627 | lcd_bits
[LCD_PORT_D
][LCD_BIT_RW
][bits
.rw
]
628 | lcd_bits
[LCD_PORT_D
][LCD_BIT_BL
][bits
.bl
]
629 | lcd_bits
[LCD_PORT_D
][LCD_BIT_CL
][bits
.cl
]
630 | lcd_bits
[LCD_PORT_D
][LCD_BIT_DA
][bits
.da
];
636 /* sets ctrl port bits according to current signals values */
637 static int set_ctrl_bits(void)
642 for (bit
= 0; bit
< LCD_BITS
; bit
++)
643 val
&= lcd_bits
[LCD_PORT_C
][bit
][BIT_MSK
];
645 val
|= lcd_bits
[LCD_PORT_C
][LCD_BIT_E
][bits
.e
]
646 | lcd_bits
[LCD_PORT_C
][LCD_BIT_RS
][bits
.rs
]
647 | lcd_bits
[LCD_PORT_C
][LCD_BIT_RW
][bits
.rw
]
648 | lcd_bits
[LCD_PORT_C
][LCD_BIT_BL
][bits
.bl
]
649 | lcd_bits
[LCD_PORT_C
][LCD_BIT_CL
][bits
.cl
]
650 | lcd_bits
[LCD_PORT_C
][LCD_BIT_DA
][bits
.da
];
656 /* sets ctrl & data port bits according to current signals values */
657 static void set_bits(void)
664 * Converts a parallel port pin (from -25 to 25) to data and control ports
665 * masks, and data and control port bits. The signal will be considered
666 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
668 * Result will be used this way :
669 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
670 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
672 void pin_to_bits(int pin
, unsigned char *d_val
, unsigned char *c_val
)
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;
689 case PIN_STROBE
: /* strobe, inverted */
693 case PIN_D0
...PIN_D7
: /* D0 - D7 = 2 - 9 */
694 d_bit
= 1 << (pin
- 2);
696 case PIN_AUTOLF
: /* autofeed, inverted */
700 case PIN_INITP
: /* init, direct */
703 case PIN_SELECP
: /* select_in, inverted */
707 default: /* unknown pin, ignore */
720 /* sleeps that many milliseconds with a reschedule */
721 static void long_sleep(int ms
)
727 current
->state
= TASK_INTERRUPTIBLE
;
728 schedule_timeout((ms
* HZ
+ 999) / 1000);
732 /* send a serial byte to the LCD panel. The caller is responsible for locking if needed. */
733 static void lcd_send_serial(int byte
)
737 /* the data bit is set on D0, and the clock on STROBE.
738 * LCD reads D0 on STROBE's rising edge.
740 for (bit
= 0; bit
< 8; bit
++) {
741 bits
.cl
= BIT_CLR
; /* CLK low */
745 udelay(2); /* maintain the data during 2 us before CLK up */
746 bits
.cl
= BIT_SET
; /* CLK high */
748 udelay(1); /* maintain the strobe during 1 us */
753 /* turn the backlight on or off */
754 static void lcd_backlight(int on
)
756 if (lcd_bl_pin
== PIN_NONE
)
759 /* The backlight is activated by seting the AUTOFEED line to +5V */
760 spin_lock(&pprt_lock
);
763 spin_unlock(&pprt_lock
);
766 /* send a command to the LCD panel in serial mode */
767 static void lcd_write_cmd_s(int cmd
)
769 spin_lock(&pprt_lock
);
770 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
771 lcd_send_serial(cmd
& 0x0F);
772 lcd_send_serial((cmd
>> 4) & 0x0F);
773 udelay(40); /* the shortest command takes at least 40 us */
774 spin_unlock(&pprt_lock
);
777 /* send data to the LCD panel in serial mode */
778 static void lcd_write_data_s(int data
)
780 spin_lock(&pprt_lock
);
781 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
782 lcd_send_serial(data
& 0x0F);
783 lcd_send_serial((data
>> 4) & 0x0F);
784 udelay(40); /* the shortest data takes at least 40 us */
785 spin_unlock(&pprt_lock
);
788 /* send a command to the LCD panel in 8 bits parallel mode */
789 static void lcd_write_cmd_p8(int cmd
)
791 spin_lock(&pprt_lock
);
792 /* present the data to the data port */
794 udelay(20); /* maintain the data during 20 us before the strobe */
801 udelay(40); /* maintain the strobe during 40 us */
806 udelay(120); /* the shortest command takes at least 120 us */
807 spin_unlock(&pprt_lock
);
810 /* send data to the LCD panel in 8 bits parallel mode */
811 static void lcd_write_data_p8(int data
)
813 spin_lock(&pprt_lock
);
814 /* present the data to the data port */
816 udelay(20); /* maintain the data during 20 us before the strobe */
823 udelay(40); /* maintain the strobe during 40 us */
828 udelay(45); /* the shortest data takes at least 45 us */
829 spin_unlock(&pprt_lock
);
832 static void lcd_gotoxy(void)
834 lcd_write_cmd(0x80 /* set DDRAM address */
835 | (lcd_addr_y
? lcd_hwidth
: 0)
836 /* we force the cursor to stay at the end of the line if it wants to go farther */
837 | ((lcd_addr_x
< lcd_bwidth
) ? lcd_addr_x
&
838 (lcd_hwidth
- 1) : lcd_bwidth
- 1));
841 static void lcd_print(char c
)
843 if (lcd_addr_x
< lcd_bwidth
) {
844 if (lcd_char_conv
!= NULL
)
845 c
= lcd_char_conv
[(unsigned char)c
];
849 /* prevents the cursor from wrapping onto the next line */
850 if (lcd_addr_x
== lcd_bwidth
)
854 /* fills the display with spaces and resets X/Y */
855 static void lcd_clear_fast_s(void)
858 lcd_addr_x
= lcd_addr_y
= 0;
861 spin_lock(&pprt_lock
);
862 for (pos
= 0; pos
< lcd_height
* lcd_hwidth
; pos
++) {
863 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
864 lcd_send_serial(' ' & 0x0F);
865 lcd_send_serial((' ' >> 4) & 0x0F);
866 udelay(40); /* the shortest data takes at least 40 us */
868 spin_unlock(&pprt_lock
);
870 lcd_addr_x
= lcd_addr_y
= 0;
874 /* fills the display with spaces and resets X/Y */
875 static void lcd_clear_fast_p8(void)
878 lcd_addr_x
= lcd_addr_y
= 0;
881 spin_lock(&pprt_lock
);
882 for (pos
= 0; pos
< lcd_height
* lcd_hwidth
; pos
++) {
883 /* present the data to the data port */
885 udelay(20); /* maintain the data during 20 us before the strobe */
892 udelay(40); /* maintain the strobe during 40 us */
897 udelay(45); /* the shortest data takes at least 45 us */
899 spin_unlock(&pprt_lock
);
901 lcd_addr_x
= lcd_addr_y
= 0;
905 /* clears the display and resets X/Y */
906 static void lcd_clear_display(void)
908 lcd_write_cmd(0x01); /* clear display */
909 lcd_addr_x
= lcd_addr_y
= 0;
910 /* we must wait a few milliseconds (15) */
914 static void lcd_init_display(void)
917 lcd_flags
= ((lcd_height
> 1) ? LCD_FLAG_N
: 0)
918 | LCD_FLAG_D
| LCD_FLAG_C
| LCD_FLAG_B
;
920 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
922 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
924 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
926 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
929 lcd_write_cmd(0x30 /* set font height and lines number */
930 | ((lcd_flags
& LCD_FLAG_F
) ? 4 : 0)
931 | ((lcd_flags
& LCD_FLAG_N
) ? 8 : 0)
935 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
938 lcd_write_cmd(0x08 /* set display mode */
939 | ((lcd_flags
& LCD_FLAG_D
) ? 4 : 0)
940 | ((lcd_flags
& LCD_FLAG_C
) ? 2 : 0)
941 | ((lcd_flags
& LCD_FLAG_B
) ? 1 : 0)
944 lcd_backlight((lcd_flags
& LCD_FLAG_L
) ? 1 : 0);
948 lcd_write_cmd(0x06); /* entry mode set : increment, cursor shifting */
954 * These are the file operation function for user access to /dev/lcd
955 * This function can also be called from inside the kernel, by
956 * setting file and ppos to NULL.
960 static ssize_t
lcd_write(struct file
*file
,
961 const char *buf
, size_t count
, loff_t
*ppos
)
964 const char *tmp
= buf
;
967 for (; count
-- > 0; (ppos
? (*ppos
)++ : 0), ++tmp
) {
968 if (!in_interrupt() && (((count
+ 1) & 0x1f) == 0))
969 schedule(); /* let's be a little nice with other processes that need some CPU */
971 if (ppos
== NULL
&& file
== NULL
)
972 c
= *tmp
; /* let's not use get_user() from the kernel ! */
973 else if (get_user(c
, tmp
))
976 /* first, we'll test if we're in escape mode */
977 if ((c
!= '\n') && lcd_escape_len
>= 0) { /* yes, let's add this char to the buffer */
978 lcd_escape
[lcd_escape_len
++] = c
;
979 lcd_escape
[lcd_escape_len
] = 0;
981 lcd_escape_len
= -1; /* aborts any previous escape sequence */
984 case LCD_ESCAPE_CHAR
: /* start of an escape sequence */
986 lcd_escape
[lcd_escape_len
] = 0;
988 case '\b': /* go back one char and clear it */
989 if (lcd_addr_x
> 0) {
990 if (lcd_addr_x
< lcd_bwidth
) /* check if we're not at the end of the line */
991 lcd_write_cmd(0x10); /* back one char */
994 lcd_write_data(' '); /* replace with a space */
995 lcd_write_cmd(0x10); /* back one char again */
997 case '\014': /* quickly clear the display */
1000 case '\n': /* flush the remainder of the current line and go to the
1001 beginning of the next line */
1002 for (; lcd_addr_x
< lcd_bwidth
; lcd_addr_x
++)
1003 lcd_write_data(' ');
1005 lcd_addr_y
= (lcd_addr_y
+ 1) % lcd_height
;
1008 case '\r': /* go to the beginning of the same line */
1012 case '\t': /* print a space instead of the tab */
1015 default: /* simply print this char */
1021 /* now we'll see if we're in an escape mode and if the current
1022 escape sequence can be understood.
1024 if (lcd_escape_len
>= 2) { /* minimal length for an escape command */
1025 int processed
= 0; /* 1 means the command has been processed */
1027 if (!strcmp(lcd_escape
, "[2J")) { /* Clear the display */
1028 lcd_clear_fast(); /* clear display */
1030 } else if (!strcmp(lcd_escape
, "[H")) { /* Cursor to home */
1031 lcd_addr_x
= lcd_addr_y
= 0;
1035 /* codes starting with ^[[L */
1036 else if ((lcd_escape_len
>= 3) &&
1037 (lcd_escape
[0] == '[') && (lcd_escape
[1] == 'L')) { /* LCD special codes */
1039 char *esc
= lcd_escape
+ 2;
1040 int oldflags
= lcd_flags
;
1042 /* check for display mode flags */
1044 case 'D': /* Display ON */
1045 lcd_flags
|= LCD_FLAG_D
;
1048 case 'd': /* Display OFF */
1049 lcd_flags
&= ~LCD_FLAG_D
;
1052 case 'C': /* Cursor ON */
1053 lcd_flags
|= LCD_FLAG_C
;
1056 case 'c': /* Cursor OFF */
1057 lcd_flags
&= ~LCD_FLAG_C
;
1060 case 'B': /* Blink ON */
1061 lcd_flags
|= LCD_FLAG_B
;
1064 case 'b': /* Blink OFF */
1065 lcd_flags
&= ~LCD_FLAG_B
;
1068 case '+': /* Back light ON */
1069 lcd_flags
|= LCD_FLAG_L
;
1072 case '-': /* Back light OFF */
1073 lcd_flags
&= ~LCD_FLAG_L
;
1076 case '*': /* flash back light using the keypad timer */
1077 if (scan_timer
.function
!= NULL
) {
1078 if (light_tempo
== 0
1079 && ((lcd_flags
& LCD_FLAG_L
)
1082 light_tempo
= FLASH_LIGHT_TEMPO
;
1086 case 'f': /* Small Font */
1087 lcd_flags
&= ~LCD_FLAG_F
;
1090 case 'F': /* Large Font */
1091 lcd_flags
|= LCD_FLAG_F
;
1094 case 'n': /* One Line */
1095 lcd_flags
&= ~LCD_FLAG_N
;
1098 case 'N': /* Two Lines */
1099 lcd_flags
|= LCD_FLAG_N
;
1102 case 'l': /* Shift Cursor Left */
1103 if (lcd_addr_x
> 0) {
1104 if (lcd_addr_x
< lcd_bwidth
)
1105 lcd_write_cmd(0x10); /* back one char if not at end of line */
1111 case 'r': /* shift cursor right */
1112 if (lcd_addr_x
< lcd_width
) {
1113 if (lcd_addr_x
< (lcd_bwidth
- 1))
1114 lcd_write_cmd(0x14); /* allow the cursor to pass the end of the line */
1120 case 'L': /* shift display left */
1122 lcd_write_cmd(0x18);
1126 case 'R': /* shift display right */
1128 lcd_write_cmd(0x1C);
1132 case 'k':{ /* kill end of line */
1134 for (x
= lcd_addr_x
; x
< lcd_bwidth
; x
++)
1135 lcd_write_data(' ');
1136 lcd_gotoxy(); /* restore cursor position */
1140 case 'I': /* reinitialize display */
1146 case 'G': /* Generator : LGcxxxxx...xx; */ {
1147 /* must have <c> between '0' and '7', representing the numerical
1148 * ASCII code of the redefined character, and <xx...xx> a sequence
1149 * of 16 hex digits representing 8 bytes for each character. Most
1150 * LCDs will only use 5 lower bits of the 7 first bytes.
1153 unsigned char cgbytes
[8];
1154 unsigned char cgaddr
;
1160 if (strchr(esc
, ';') == NULL
)
1165 cgaddr
= *(esc
++) - '0';
1174 while (*esc
&& cgoffset
< 8) {
1176 if (*esc
>= '0' && *esc
<= '9')
1177 value
|= (*esc
- '0') << shift
;
1178 else if (*esc
>= 'A' && *esc
<= 'Z')
1179 value
|= (*esc
- 'A' + 10) << shift
;
1180 else if (*esc
>= 'a' && *esc
<= 'z')
1181 value
|= (*esc
- 'a' + 10) << shift
;
1188 cgbytes
[cgoffset
++] = value
;
1195 lcd_write_cmd(0x40 | (cgaddr
* 8));
1196 for (addr
= 0; addr
< cgoffset
; addr
++)
1197 lcd_write_data(cgbytes
[addr
]);
1199 lcd_gotoxy(); /* ensures that we stop writing to CGRAM */
1203 case 'x': /* gotoxy : LxXXX[yYYY]; */
1204 case 'y': /* gotoxy : LyYYY[xXXX]; */
1205 if (strchr(esc
, ';') == NULL
)
1212 while (isdigit(*esc
)) {
1219 } else if (*esc
== 'y') {
1222 while (isdigit(*esc
)) {
1236 } /* end of switch */
1238 /* Check wether one flag was changed */
1239 if (oldflags
!= lcd_flags
) {
1240 /* check wether one of B,C,D flags was changed */
1241 if ((oldflags
^ lcd_flags
) &
1242 (LCD_FLAG_B
| LCD_FLAG_C
| LCD_FLAG_D
))
1243 /* set display mode */
1244 lcd_write_cmd(0x08 |
1245 ((lcd_flags
& LCD_FLAG_D
) ? 4 : 0) |
1246 ((lcd_flags
& LCD_FLAG_C
) ? 2 : 0) |
1247 ((lcd_flags
& LCD_FLAG_B
) ? 1 : 0));
1248 /* check wether one of F,N flags was changed */
1249 else if ((oldflags
^ lcd_flags
) &
1250 (LCD_FLAG_F
| LCD_FLAG_N
))
1251 lcd_write_cmd(0x30 |
1252 ((lcd_flags
& LCD_FLAG_F
) ? 4 : 0) |
1253 ((lcd_flags
& LCD_FLAG_N
) ? 8 : 0));
1254 /* check wether L flag was changed */
1255 else if ((oldflags
^ lcd_flags
) &
1257 if (lcd_flags
& (LCD_FLAG_L
))
1259 else if (light_tempo
== 0) /* switch off the light only when the tempo lighting is gone */
1265 /* LCD special escape codes */
1266 /* flush the escape sequence if it's been processed or if it is
1267 getting too long. */
1268 if (processed
|| (lcd_escape_len
>= LCD_ESCAPE_LEN
))
1269 lcd_escape_len
= -1;
1270 } /* escape codes */
1276 static int lcd_open(struct inode
*inode
, struct file
*file
)
1279 return -EBUSY
; /* open only once at a time */
1281 if (file
->f_mode
& FMODE_READ
) /* device is write-only */
1284 if (lcd_must_clear
) {
1285 lcd_clear_display();
1292 static int lcd_release(struct inode
*inode
, struct file
*file
)
1298 static struct file_operations lcd_fops
= {
1301 .release
= lcd_release
,
1304 static struct miscdevice lcd_dev
= {
1310 /* public function usable from the kernel for any purpose */
1311 void panel_lcd_print(char *s
)
1313 if (lcd_enabled
&& lcd_initialized
)
1314 lcd_write(NULL
, s
, strlen(s
), NULL
);
1317 /* initialize the LCD driver */
1321 case LCD_TYPE_OLD
: /* parallel mode, 8 bits */
1323 lcd_proto
= LCD_PROTO_PARALLEL
;
1324 if (lcd_charset
< 0)
1325 lcd_charset
= LCD_CHARSET_NORMAL
;
1326 if (lcd_e_pin
== PIN_NOT_SET
)
1327 lcd_e_pin
= PIN_STROBE
;
1328 if (lcd_rs_pin
== PIN_NOT_SET
)
1329 lcd_rs_pin
= PIN_AUTOLF
;
1340 case LCD_TYPE_KS0074
: /* serial mode, ks0074 */
1342 lcd_proto
= LCD_PROTO_SERIAL
;
1343 if (lcd_charset
< 0)
1344 lcd_charset
= LCD_CHARSET_KS0074
;
1345 if (lcd_bl_pin
== PIN_NOT_SET
)
1346 lcd_bl_pin
= PIN_AUTOLF
;
1347 if (lcd_cl_pin
== PIN_NOT_SET
)
1348 lcd_cl_pin
= PIN_STROBE
;
1349 if (lcd_da_pin
== PIN_NOT_SET
)
1350 lcd_da_pin
= PIN_D0
;
1361 case LCD_TYPE_NEXCOM
: /* parallel mode, 8 bits, generic */
1363 lcd_proto
= LCD_PROTO_PARALLEL
;
1364 if (lcd_charset
< 0)
1365 lcd_charset
= LCD_CHARSET_NORMAL
;
1366 if (lcd_e_pin
== PIN_NOT_SET
)
1367 lcd_e_pin
= PIN_AUTOLF
;
1368 if (lcd_rs_pin
== PIN_NOT_SET
)
1369 lcd_rs_pin
= PIN_SELECP
;
1370 if (lcd_rw_pin
== PIN_NOT_SET
)
1371 lcd_rw_pin
= PIN_INITP
;
1382 case LCD_TYPE_CUSTOM
: /* customer-defined */
1384 lcd_proto
= DEFAULT_LCD_PROTO
;
1385 if (lcd_charset
< 0)
1386 lcd_charset
= DEFAULT_LCD_CHARSET
;
1387 /* default geometry will be set later */
1389 case LCD_TYPE_HANTRONIX
: /* parallel mode, 8 bits, hantronix-like */
1392 lcd_proto
= LCD_PROTO_PARALLEL
;
1393 if (lcd_charset
< 0)
1394 lcd_charset
= LCD_CHARSET_NORMAL
;
1395 if (lcd_e_pin
== PIN_NOT_SET
)
1396 lcd_e_pin
= PIN_STROBE
;
1397 if (lcd_rs_pin
== PIN_NOT_SET
)
1398 lcd_rs_pin
= PIN_SELECP
;
1411 /* this is used to catch wrong and default values */
1413 lcd_width
= DEFAULT_LCD_WIDTH
;
1414 if (lcd_bwidth
<= 0)
1415 lcd_bwidth
= DEFAULT_LCD_BWIDTH
;
1416 if (lcd_hwidth
<= 0)
1417 lcd_hwidth
= DEFAULT_LCD_HWIDTH
;
1418 if (lcd_height
<= 0)
1419 lcd_height
= DEFAULT_LCD_HEIGHT
;
1421 if (lcd_proto
== LCD_PROTO_SERIAL
) { /* SERIAL */
1422 lcd_write_cmd
= lcd_write_cmd_s
;
1423 lcd_write_data
= lcd_write_data_s
;
1424 lcd_clear_fast
= lcd_clear_fast_s
;
1426 if (lcd_cl_pin
== PIN_NOT_SET
)
1427 lcd_cl_pin
= DEFAULT_LCD_PIN_SCL
;
1428 if (lcd_da_pin
== PIN_NOT_SET
)
1429 lcd_da_pin
= DEFAULT_LCD_PIN_SDA
;
1431 } else { /* PARALLEL */
1432 lcd_write_cmd
= lcd_write_cmd_p8
;
1433 lcd_write_data
= lcd_write_data_p8
;
1434 lcd_clear_fast
= lcd_clear_fast_p8
;
1436 if (lcd_e_pin
== PIN_NOT_SET
)
1437 lcd_e_pin
= DEFAULT_LCD_PIN_E
;
1438 if (lcd_rs_pin
== PIN_NOT_SET
)
1439 lcd_rs_pin
= DEFAULT_LCD_PIN_RS
;
1440 if (lcd_rw_pin
== PIN_NOT_SET
)
1441 lcd_rw_pin
= DEFAULT_LCD_PIN_RW
;
1444 if (lcd_bl_pin
== PIN_NOT_SET
)
1445 lcd_bl_pin
= DEFAULT_LCD_PIN_BL
;
1447 if (lcd_e_pin
== PIN_NOT_SET
)
1448 lcd_e_pin
= PIN_NONE
;
1449 if (lcd_rs_pin
== PIN_NOT_SET
)
1450 lcd_rs_pin
= PIN_NONE
;
1451 if (lcd_rw_pin
== PIN_NOT_SET
)
1452 lcd_rw_pin
= PIN_NONE
;
1453 if (lcd_bl_pin
== PIN_NOT_SET
)
1454 lcd_bl_pin
= PIN_NONE
;
1455 if (lcd_cl_pin
== PIN_NOT_SET
)
1456 lcd_cl_pin
= PIN_NONE
;
1457 if (lcd_da_pin
== PIN_NOT_SET
)
1458 lcd_da_pin
= PIN_NONE
;
1460 if (lcd_charset
< 0)
1461 lcd_charset
= DEFAULT_LCD_CHARSET
;
1463 if (lcd_charset
== LCD_CHARSET_KS0074
)
1464 lcd_char_conv
= lcd_char_conv_ks0074
;
1466 lcd_char_conv
= NULL
;
1468 if (lcd_bl_pin
!= PIN_NONE
)
1471 pin_to_bits(lcd_e_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_E
],
1472 lcd_bits
[LCD_PORT_C
][LCD_BIT_E
]);
1473 pin_to_bits(lcd_rs_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_RS
],
1474 lcd_bits
[LCD_PORT_C
][LCD_BIT_RS
]);
1475 pin_to_bits(lcd_rw_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_RW
],
1476 lcd_bits
[LCD_PORT_C
][LCD_BIT_RW
]);
1477 pin_to_bits(lcd_bl_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_BL
],
1478 lcd_bits
[LCD_PORT_C
][LCD_BIT_BL
]);
1479 pin_to_bits(lcd_cl_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_CL
],
1480 lcd_bits
[LCD_PORT_C
][LCD_BIT_CL
]);
1481 pin_to_bits(lcd_da_pin
, lcd_bits
[LCD_PORT_D
][LCD_BIT_DA
],
1482 lcd_bits
[LCD_PORT_C
][LCD_BIT_DA
]);
1484 /* before this line, we must NOT send anything to the display.
1485 * Since lcd_init_display() needs to write data, we have to
1486 * enable mark the LCD initialized just before.
1488 lcd_initialized
= 1;
1491 /* display a short message */
1492 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1493 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1494 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE
);
1497 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE
"\nPanel-"
1500 lcd_addr_x
= lcd_addr_y
= 0;
1501 lcd_must_clear
= 1; /* clear the display on the next device opening */
1506 * These are the file operation function for user access to /dev/keypad
1509 static ssize_t
keypad_read(struct file
*file
,
1510 char *buf
, size_t count
, loff_t
*ppos
)
1516 if (keypad_buflen
== 0) {
1517 if (file
->f_flags
& O_NONBLOCK
)
1520 interruptible_sleep_on(&keypad_read_wait
);
1521 if (signal_pending(current
))
1525 for (; count
-- > 0 && (keypad_buflen
> 0); ++i
, ++tmp
, --keypad_buflen
) {
1526 put_user(keypad_buffer
[keypad_start
], tmp
);
1527 keypad_start
= (keypad_start
+ 1) % KEYPAD_BUFFER
;
1534 static int keypad_open(struct inode
*inode
, struct file
*file
)
1537 if (keypad_open_cnt
)
1538 return -EBUSY
; /* open only once at a time */
1540 if (file
->f_mode
& FMODE_WRITE
) /* device is read-only */
1543 keypad_buflen
= 0; /* flush the buffer on opening */
1548 static int keypad_release(struct inode
*inode
, struct file
*file
)
1554 static struct file_operations keypad_fops
= {
1555 .read
= keypad_read
, /* read */
1556 .open
= keypad_open
, /* open */
1557 .release
= keypad_release
, /* close */
1560 static struct miscdevice keypad_dev
= {
1566 static void keypad_send_key(char *string
, int max_len
)
1568 if (init_in_progress
)
1571 /* send the key to the device only if a process is attached to it. */
1572 if (keypad_open_cnt
> 0) {
1573 while (max_len
-- && keypad_buflen
< KEYPAD_BUFFER
&& *string
) {
1574 keypad_buffer
[(keypad_start
+ keypad_buflen
++) %
1575 KEYPAD_BUFFER
] = *string
++;
1577 wake_up_interruptible(&keypad_read_wait
);
1581 /* this function scans all the bits involving at least one logical signal, and puts the
1582 * results in the bitfield "phys_read" (one bit per established contact), and sets
1583 * "phys_read_prev" to "phys_read".
1585 * Note: to debounce input signals, we will only consider as switched a signal which is
1586 * stable across 2 measures. Signals which are different between two reads will be kept
1587 * as they previously were in their logical form (phys_prev). A signal which has just
1588 * switched will have a 1 in (phys_read ^ phys_read_prev).
1590 static void phys_scan_contacts(void)
1597 phys_prev
= phys_curr
;
1598 phys_read_prev
= phys_read
;
1599 phys_read
= 0; /* flush all signals */
1601 oldval
= r_dtr(pprt
) | scan_mask_o
; /* keep track of old value, with all outputs disabled */
1602 w_dtr(pprt
, oldval
& ~scan_mask_o
); /* activate all keyboard outputs (active low) */
1603 bitmask
= PNL_PINPUT(r_str(pprt
)) & scan_mask_i
; /* will have a 1 for each bit set to gnd */
1604 w_dtr(pprt
, oldval
); /* disable all matrix signals */
1606 /* now that all outputs are cleared, the only active input bits are
1607 * directly connected to the ground
1609 gndmask
= PNL_PINPUT(r_str(pprt
)) & scan_mask_i
; /* 1 for each grounded input */
1611 phys_read
|= (pmask_t
) gndmask
<< 40; /* grounded inputs are signals 40-44 */
1613 if (bitmask
!= gndmask
) {
1614 /* since clearing the outputs changed some inputs, we know that some
1615 * input signals are currently tied to some outputs. So we'll scan them.
1617 for (bit
= 0; bit
< 8; bit
++) {
1620 if (!(scan_mask_o
& bitval
)) /* skip unused bits */
1623 w_dtr(pprt
, oldval
& ~bitval
); /* enable this output */
1624 bitmask
= PNL_PINPUT(r_str(pprt
)) & ~gndmask
;
1625 phys_read
|= (pmask_t
) bitmask
<< (5 * bit
);
1627 w_dtr(pprt
, oldval
); /* disable all outputs */
1629 /* this is easy: use old bits when they are flapping, use new ones when stable */
1631 (phys_prev
& (phys_read
^ phys_read_prev
)) | (phys_read
&
1636 static void panel_process_inputs(void)
1638 struct list_head
*item
;
1639 struct logical_input
*input
;
1643 "entering panel_process_inputs with pp=%016Lx & pc=%016Lx\n",
1644 phys_prev
, phys_curr
);
1649 list_for_each(item
, &logical_inputs
) {
1650 input
= list_entry(item
, struct logical_input
, list
);
1652 switch (input
->state
) {
1654 if ((phys_curr
& input
->mask
) != input
->value
)
1656 /* if all needed ones were already set previously, this means that
1657 * this logical signal has been activated by the releasing of
1658 * another combined signal, so we don't want to match.
1659 * eg: AB -(release B)-> A -(release A)-> 0 : don't match A.
1661 if ((phys_prev
& input
->mask
) == input
->value
)
1663 input
->rise_timer
= 0;
1664 input
->state
= INPUT_ST_RISING
;
1665 /* no break here, fall through */
1666 case INPUT_ST_RISING
:
1667 if ((phys_curr
& input
->mask
) != input
->value
) {
1668 input
->state
= INPUT_ST_LOW
;
1671 if (input
->rise_timer
< input
->rise_time
) {
1673 input
->rise_timer
++;
1676 input
->high_timer
= 0;
1677 input
->state
= INPUT_ST_HIGH
;
1678 /* no break here, fall through */
1682 * this is an invalid test. It tries to catch transitions from single-key
1683 * to multiple-key, but doesn't take into account the contacts polarity.
1684 * The only solution to the problem is to parse keys from the most complex
1685 * to the simplest combinations, and mark them as 'caught' once a combination
1686 * matches, then unmatch it for all other ones.
1689 /* try to catch dangerous transitions cases :
1690 * someone adds a bit, so this signal was a false
1691 * positive resulting from a transition. We should invalidate
1692 * the signal immediately and not call the release function.
1693 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1695 if (((phys_prev
& input
->mask
) == input
->value
)
1696 && ((phys_curr
& input
->mask
) > input
->value
)) {
1697 input
->state
= INPUT_ST_LOW
; /* invalidate */
1702 if ((phys_curr
& input
->mask
) == input
->value
) {
1703 if ((input
->type
== INPUT_TYPE_STD
)
1704 && (input
->high_timer
== 0)) {
1705 input
->high_timer
++;
1706 if (input
->u
.std
.press_fct
!= NULL
)
1707 input
->u
.std
.press_fct(input
->u
.
1710 } else if (input
->type
== INPUT_TYPE_KBD
) {
1711 keypressed
= 1; /* will turn on the light */
1713 if (input
->high_timer
== 0) {
1714 if (input
->u
.kbd
.press_str
[0])
1715 keypad_send_key(input
->
1724 if (input
->u
.kbd
.repeat_str
[0]) {
1725 if (input
->high_timer
>=
1727 input
->high_timer
-=
1729 keypad_send_key(input
->
1737 inputs_stable
= 0; /* we will need to come back here soon */
1740 if (input
->high_timer
< 255)
1741 input
->high_timer
++;
1745 /* else signal falling down. Let's fall through. */
1746 input
->state
= INPUT_ST_FALLING
;
1747 input
->fall_timer
= 0;
1749 /* no break here, fall through */
1750 case INPUT_ST_FALLING
:
1752 /* FIXME !!! same comment as above */
1753 if (((phys_prev
& input
->mask
) == input
->value
)
1754 && ((phys_curr
& input
->mask
) > input
->value
)) {
1755 input
->state
= INPUT_ST_LOW
; /* invalidate */
1760 if ((phys_curr
& input
->mask
) == input
->value
) {
1761 if (input
->type
== INPUT_TYPE_KBD
) {
1762 keypressed
= 1; /* will turn on the light */
1764 if (input
->u
.kbd
.repeat_str
[0]) {
1765 if (input
->high_timer
>= KEYPAD_REP_START
)
1766 input
->high_timer
-= KEYPAD_REP_DELAY
;
1767 keypad_send_key(input
->u
.kbd
.repeat_str
,
1768 sizeof(input
->u
.kbd
.repeat_str
));
1769 inputs_stable
= 0; /* we will need to come back here soon */
1772 if (input
->high_timer
< 255)
1773 input
->high_timer
++;
1775 input
->state
= INPUT_ST_HIGH
;
1777 } else if (input
->fall_timer
>= input
->fall_time
) {
1778 /* call release event */
1779 if (input
->type
== INPUT_TYPE_STD
) {
1780 if (input
->u
.std
.release_fct
!= NULL
)
1781 input
->u
.std
.release_fct(input
->u
.std
.release_data
);
1783 } else if (input
->type
== INPUT_TYPE_KBD
) {
1784 if (input
->u
.kbd
.release_str
[0])
1785 keypad_send_key(input
->u
.kbd
.release_str
,
1786 sizeof(input
->u
.kbd
.release_str
));
1789 input
->state
= INPUT_ST_LOW
;
1792 input
->fall_timer
++;
1800 static void panel_scan_timer(void)
1802 if ((keypad_enabled
&& keypad_initialized
)
1803 || (smartcard_enabled
&& smartcard_enabled
)) {
1805 if (spin_trylock(&pprt_lock
)) {
1806 phys_scan_contacts();
1807 spin_unlock(&pprt_lock
); /* no need for the parport anymore */
1810 if (!inputs_stable
|| phys_curr
!= phys_prev
)
1811 panel_process_inputs();
1814 if (lcd_enabled
&& lcd_initialized
) {
1816 if (light_tempo
== 0 && ((lcd_flags
& LCD_FLAG_L
) == 0))
1818 light_tempo
= FLASH_LIGHT_TEMPO
;
1819 } else if (light_tempo
> 0) {
1821 if (light_tempo
== 0 && ((lcd_flags
& LCD_FLAG_L
) == 0))
1826 mod_timer(&scan_timer
, jiffies
+ INPUT_POLL_TIME
);
1829 /* send a high / low clock impulse of <duration> microseconds high and low */
1830 static void smartcard_send_clock(int duration
)
1834 w_dtr(pprt
, (old
= r_dtr(pprt
)) | PNL_SC_CLK
);
1836 w_dtr(pprt
, (old
& ~PNL_SC_CLK
));
1840 static void smartcard_insert(int dummy
)
1844 spin_lock(&pprt_lock
);
1845 w_dtr(pprt
, (r_dtr(pprt
) & ~PNL_SC_BITS
));
1846 w_ctr(pprt
, (r_ctr(pprt
) | PNL_SC_ENA
));
1848 udelay(30); /* ensure the rst is low at least 30 us */
1850 smartcard_send_clock(100); /* reset address counter */
1852 w_dtr(pprt
, r_dtr(pprt
) | PNL_SC_RST
);
1853 udelay(30); /* ensure the rst is high at least 30 us */
1855 for (ofs
= 0; ofs
< SMARTCARD_BYTES
; ofs
++) {
1858 for (bit
= 128; bit
> 0; bit
>>= 1) {
1859 if (!(r_str(pprt
) & PNL_SC_IOR
))
1861 smartcard_send_clock(15); /* 15 us are enough for data */
1863 smartcard_data
[ofs
] = byte
;
1866 w_dtr(pprt
, (r_dtr(pprt
) & ~PNL_SC_BITS
));
1867 w_ctr(pprt
, (r_ctr(pprt
) & ~PNL_SC_ENA
));
1869 spin_unlock(&pprt_lock
);
1871 printk(KERN_INFO
"Panel: smart card inserted : %02x%02x%02x%02x%1x\n",
1872 smartcard_data
[2], smartcard_data
[3], smartcard_data
[4],
1873 smartcard_data
[5], smartcard_data
[6] >> 4);
1874 keypad_send_key("CardIn\n", 7);
1877 static void smartcard_remove(int dummy
)
1879 printk(KERN_INFO
"Panel: smart card removed : %02x%02x%02x%02x%1x\n",
1880 smartcard_data
[2], smartcard_data
[3], smartcard_data
[4],
1881 smartcard_data
[5], smartcard_data
[6] >> 4);
1882 memset(smartcard_data
, 0, sizeof(smartcard_data
));
1883 keypad_send_key("CardOut\n", 8);
1887 * These are the file operation function for user access to /dev/smartcard
1890 static ssize_t
smartcard_read(struct file
*file
,
1891 char *buf
, size_t count
, loff_t
*ppos
)
1897 for (; count
-- > 0 && (smartcard_ptr
< 9); ++i
, ++tmp
, ++smartcard_ptr
) {
1898 if (smartcard_ptr
& 1)
1900 (smartcard_data
[2 + (smartcard_ptr
>> 1)] &
1904 (smartcard_data
[2 + (smartcard_ptr
>> 1)] >>
1912 static int smartcard_open(struct inode
*inode
, struct file
*file
)
1915 if (smartcard_open_cnt
)
1916 return -EBUSY
; /* open only once at a time */
1918 if (file
->f_mode
& FMODE_WRITE
) /* device is read-only */
1921 smartcard_ptr
= 0; /* flush the buffer on opening */
1922 smartcard_open_cnt
++;
1926 static int smartcard_release(struct inode
*inode
, struct file
*file
)
1928 smartcard_open_cnt
--;
1932 static struct file_operations smartcard_fops
= {
1933 .read
= smartcard_read
, /* read */
1934 .open
= smartcard_open
, /* open */
1935 .release
= smartcard_release
, /* close */
1938 static struct miscdevice smartcard_dev
= {
1944 static void init_scan_timer(void)
1946 if (scan_timer
.function
!= NULL
)
1947 return; /* already started */
1949 init_timer(&scan_timer
);
1950 scan_timer
.expires
= jiffies
+ INPUT_POLL_TIME
;
1951 scan_timer
.data
= 0;
1952 scan_timer
.function
= (void *)&panel_scan_timer
;
1953 add_timer(&scan_timer
);
1956 /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
1957 * if <omask> or <imask> are non-null, they will be or'ed with the bits corresponding
1958 * to out and in bits respectively.
1959 * returns 1 if ok, 0 if error (in which case, nothing is written).
1961 static int input_name2mask(char *name
, pmask_t
*mask
, pmask_t
*value
,
1962 char *imask
, char *omask
)
1964 static char sigtab
[10] = "EeSsPpAaBb";
1968 om
= im
= m
= v
= 0ULL;
1970 int in
, out
, bit
, neg
;
1971 for (in
= 0; (in
< sizeof(sigtab
)) && (sigtab
[in
] != *name
); in
++)
1973 if (in
>= sizeof(sigtab
))
1974 return 0; /* input name not found */
1975 neg
= (in
& 1); /* odd (lower) names are negated */
1980 if (isdigit(*name
)) {
1983 } else if (*name
== '-')
1986 return 0; /* unknown bit name */
1988 bit
= (out
* 5) + in
;
2004 /* tries to bind a key to the signal name <name>. The key will send the
2005 * strings <press>, <repeat>, <release> for these respective events.
2006 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2008 static struct logical_input
*panel_bind_key(char *name
, char *press
,
2009 char *repeat
, char *release
)
2011 struct logical_input
*key
;
2013 key
= kmalloc(sizeof(struct logical_input
), GFP_KERNEL
);
2015 printk(KERN_ERR
"panel: not enough memory\n");
2018 memset(key
, 0, sizeof(struct logical_input
));
2019 if (!input_name2mask(name
, &key
->mask
, &key
->value
, &scan_mask_i
,
2023 key
->type
= INPUT_TYPE_KBD
;
2024 key
->state
= INPUT_ST_LOW
;
2029 printk(KERN_DEBUG
"bind: <%s> : m=%016Lx v=%016Lx\n", name
, key
->mask
,
2032 strncpy(key
->u
.kbd
.press_str
, press
, sizeof(key
->u
.kbd
.press_str
));
2033 strncpy(key
->u
.kbd
.repeat_str
, repeat
, sizeof(key
->u
.kbd
.repeat_str
));
2034 strncpy(key
->u
.kbd
.release_str
, release
,
2035 sizeof(key
->u
.kbd
.release_str
));
2036 list_add(&key
->list
, &logical_inputs
);
2040 /* tries to bind a callback function to the signal name <name>. The function
2041 * <press_fct> will be called with the <press_data> arg when the signal is
2042 * activated, and so on for <release_fct>/<release_data>
2043 * Returns the pointer to the new signal if ok, NULL if the signal could not be bound.
2045 static struct logical_input
*panel_bind_callback(char *name
,
2046 void (*press_fct
) (int),
2048 void (*release_fct
) (int),
2051 struct logical_input
*callback
;
2053 callback
= kmalloc(sizeof(struct logical_input
), GFP_KERNEL
);
2055 printk(KERN_ERR
"panel: not enough memory\n");
2058 memset(callback
, 0, sizeof(struct logical_input
));
2059 if (!input_name2mask(name
, &callback
->mask
, &callback
->value
,
2060 &scan_mask_i
, &scan_mask_o
))
2063 callback
->type
= INPUT_TYPE_STD
;
2064 callback
->state
= INPUT_ST_LOW
;
2065 callback
->rise_time
= 1;
2066 callback
->fall_time
= 1;
2067 callback
->u
.std
.press_fct
= press_fct
;
2068 callback
->u
.std
.press_data
= press_data
;
2069 callback
->u
.std
.release_fct
= release_fct
;
2070 callback
->u
.std
.release_data
= release_data
;
2071 list_add(&callback
->list
, &logical_inputs
);
2075 static void keypad_init(void)
2078 init_waitqueue_head(&keypad_read_wait
);
2079 keypad_buflen
= 0; /* flushes any eventual noisy keystroke */
2081 /* Let's create all known keys */
2083 for (keynum
= 0; keypad_profile
[keynum
][0][0]; keynum
++) {
2084 panel_bind_key(keypad_profile
[keynum
][0],
2085 keypad_profile
[keynum
][1],
2086 keypad_profile
[keynum
][2],
2087 keypad_profile
[keynum
][3]);
2091 keypad_initialized
= 1;
2094 static void smartcard_init(void)
2096 init_waitqueue_head(&smartcard_read_wait
);
2098 panel_bind_callback(SMARTCARD_LOGICAL_DETECTOR
, &smartcard_insert
, 0,
2099 &smartcard_remove
, 0);
2101 smartcard_enabled
= 1;
2104 /**************************************************/
2105 /* device initialization */
2106 /**************************************************/
2108 static int panel_notify_sys(struct notifier_block
*this, unsigned long code
,
2111 if (lcd_enabled
&& lcd_initialized
) {
2115 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2119 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2122 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2131 static struct notifier_block panel_notifier
= {
2137 static void panel_attach(struct parport
*port
)
2139 if (port
->number
!= parport
)
2144 "panel_attach(): port->number=%d parport=%d, already registered !\n",
2145 port
->number
, parport
);
2149 pprt
= parport_register_device(port
, "panel", NULL
, NULL
, /* pf, kf */
2151 /*PARPORT_DEV_EXCL */
2154 if (parport_claim(pprt
)) {
2156 "Panel: could not claim access to parport%d. Aborting.\n",
2161 /* must init LCD first, just in case an IRQ from the keypad is generated at keypad init */
2164 misc_register(&lcd_dev
);
2167 if (keypad_enabled
) {
2169 misc_register(&keypad_dev
);
2172 if (smartcard_enabled
) {
2174 misc_register(&smartcard_dev
);
2178 static void panel_detach(struct parport
*port
)
2180 if (port
->number
!= parport
)
2185 "panel_detach(): port->number=%d parport=%d, nothing to unregister.\n",
2186 port
->number
, parport
);
2190 if (smartcard_enabled
&& smartcard_initialized
)
2191 misc_deregister(&smartcard_dev
);
2193 if (keypad_enabled
&& keypad_initialized
)
2194 misc_deregister(&keypad_dev
);
2196 if (lcd_enabled
&& lcd_initialized
)
2197 misc_deregister(&lcd_dev
);
2199 parport_release(pprt
);
2200 parport_unregister_device(pprt
);
2204 static struct parport_driver panel_driver
= {
2206 .attach
= panel_attach
,
2207 .detach
= panel_detach
,
2211 int panel_init(void)
2213 /* for backwards compatibility */
2214 if (keypad_type
< 0)
2215 keypad_type
= keypad_enabled
;
2218 lcd_type
= lcd_enabled
;
2221 parport
= DEFAULT_PARPORT
;
2223 /* take care of an eventual profile */
2225 case PANEL_PROFILE_CUSTOM
: /* custom profile */
2226 if (keypad_type
< 0)
2227 keypad_type
= DEFAULT_KEYPAD
;
2228 if (smartcard_enabled
< 0)
2229 smartcard_enabled
= DEFAULT_SMARTCARD
;
2231 lcd_type
= DEFAULT_LCD
;
2233 case PANEL_PROFILE_OLD
: /* 8 bits, 2*16, old keypad */
2234 if (keypad_type
< 0)
2235 keypad_type
= KEYPAD_TYPE_OLD
;
2236 if (smartcard_enabled
< 0)
2237 smartcard_enabled
= 0;
2239 lcd_type
= LCD_TYPE_OLD
;
2245 case PANEL_PROFILE_NEW
: /* serial, 2*16, new keypad */
2246 if (keypad_type
< 0)
2247 keypad_type
= KEYPAD_TYPE_NEW
;
2248 if (smartcard_enabled
< 0)
2249 smartcard_enabled
= 1;
2251 lcd_type
= LCD_TYPE_KS0074
;
2253 case PANEL_PROFILE_HANTRONIX
: /* 8 bits, 2*16 hantronix-like, no keypad */
2254 if (keypad_type
< 0)
2255 keypad_type
= KEYPAD_TYPE_NONE
;
2256 if (smartcard_enabled
< 0)
2257 smartcard_enabled
= 0;
2259 lcd_type
= LCD_TYPE_HANTRONIX
;
2261 case PANEL_PROFILE_NEXCOM
: /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2262 if (keypad_type
< 0)
2263 keypad_type
= KEYPAD_TYPE_NEXCOM
;
2264 if (smartcard_enabled
< 0)
2265 smartcard_enabled
= 0;
2267 lcd_type
= LCD_TYPE_NEXCOM
;
2269 case PANEL_PROFILE_LARGE
: /* 8 bits, 2*40, old keypad */
2270 if (keypad_type
< 0)
2271 keypad_type
= KEYPAD_TYPE_OLD
;
2272 if (smartcard_enabled
< 0)
2273 smartcard_enabled
= 0;
2275 lcd_type
= LCD_TYPE_OLD
;
2279 lcd_enabled
= (lcd_type
> 0);
2280 keypad_enabled
= (keypad_type
> 0);
2282 switch (keypad_type
) {
2283 case KEYPAD_TYPE_OLD
:
2284 keypad_profile
= old_keypad_profile
;
2286 case KEYPAD_TYPE_NEW
:
2287 keypad_profile
= new_keypad_profile
;
2289 case KEYPAD_TYPE_NEXCOM
:
2290 keypad_profile
= nexcom_keypad_profile
;
2293 keypad_profile
= NULL
;
2297 /* tells various subsystems about the fact that we are initializing */
2298 init_in_progress
= 1;
2300 if (parport_register_driver(&panel_driver
)) {
2302 "Panel: could not register with parport. Aborting.\n");
2306 if (!lcd_enabled
&& !keypad_enabled
&& !smartcard_enabled
) { /* no device enabled, let's release the parport */
2308 parport_release(pprt
);
2309 parport_unregister_device(pprt
);
2311 parport_unregister_driver(&panel_driver
);
2312 printk(KERN_ERR
"Panel driver version " PANEL_VERSION
2317 register_reboot_notifier(&panel_notifier
);
2320 printk(KERN_INFO
"Panel driver version " PANEL_VERSION
2321 " registered on parport%d (io=0x%lx).\n", parport
,
2324 printk(KERN_INFO
"Panel driver version " PANEL_VERSION
2325 " not yet registered\n");
2326 /* tells various subsystems about the fact that initialization is finished */
2327 init_in_progress
= 0;
2331 static int __init
panel_init_module(void)
2333 return panel_init();
2336 static void __exit
panel_cleanup_module(void)
2338 unregister_reboot_notifier(&panel_notifier
);
2340 if (scan_timer
.function
!= NULL
)
2341 del_timer(&scan_timer
);
2344 misc_deregister(&keypad_dev
);
2346 if (smartcard_enabled
)
2347 misc_deregister(&smartcard_dev
);
2350 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2351 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2352 misc_deregister(&lcd_dev
);
2355 /* TODO: free all input signals */
2357 parport_release(pprt
);
2358 parport_unregister_device(pprt
);
2359 parport_unregister_driver(&panel_driver
);
2362 module_init(panel_init_module
);
2363 module_exit(panel_cleanup_module
);
2364 MODULE_AUTHOR("Willy Tarreau");
2365 MODULE_LICENSE("GPL");