2 * Front panel driver for Linux - 20000810 - Willy Tarreau - willy@meta-x.org.
3 * It includes and LCD display (/dev/lcd), a 4-key keypad (/dev/keypad), and a
4 * smart card reader (/dev/smartcard).
6 * Updates for this driver may be found here :
8 * http://w.ods.org/linux/kernel/lcdpanel/
10 * the driver skeleton has been stolen from nvram.c which was clearly written.
14 * - keypad now scrolls LCD when not opened
20 * - Reposition LCD when opening /dev/keypad (WIP)
23 * - Start of port to kernel 2.4.1
25 * - implementation of a 24-key keyboard scanner with less electronics
26 * around, thus allowing to release the IRQ line.
28 * - the driver now compiles and works with both 2.4.2 and 2.2.18 kernels
30 * - implementation of KS0074-based serial LCD (load with lcd_enabled=2 and lcd_hwidth=16)
32 * - added back-light support, released 0.7.1
34 * - added charset conversion table for ks0074, released 0.7.2
36 * - start of rewriting towards v0.8
38 * - replaced linux/malloc.h with linux/slab.h to be 2.4 compliant
39 * - definition of the multi-layer input system with its naming scheme
40 * - profile support for simplified configuration
42 * - smartcard now works for telecards. /dev/smartcard returns the card serial number
44 * - fix too short sleep for lcd_clear
46 * - add support for hantronix LCD modules (RS on SELECTIN instead of AUTOLF)
47 * (load with lcd_enabled=3 or profile=3)
49 * - changed all parallel LCD functions to be more generic. Now any
50 * connection of control signal is allowed with lcd_*_pin.
52 * - cleaned up some code
53 * - added support for keypads with inverted inputs
54 * - added support for Nexcom's LCD/Keypad on profile 4
55 * - added character generator for chars 0-7 : "\e[LG{0-7}{8*2 hexdigits};"
57 * - deprecated lcd_enabled and keypad_enabled in profit of *_type
58 * - changed configuration so that the user can choose everything at
59 * kernel compilation time
61 * - fixed a stupid copy-paste bug affecting only the serial LCD
62 * - moved display geometries to lcd_init() to avoid problems with custom profiles.
64 * - added a system notifier callback to print the system state on the LCD
65 * during reboots or halts.
68 * - first working port on kernel 2.6
71 * - fixed a long standing bug in 2.6 causing panics during reboot/kexec
72 * if the LCD was enabled but not initialized due to lack of parport.
75 * - the initialization/deinitialization process is very dirty and should
76 * be rewritten. It may even be buggy.
79 * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
80 * - make the LCD a part of a virtual screen of Vx*Vy
81 * - make the inputs list smp-safe
82 * - change the keyboard to a double mapping : signals -> key_id -> values
83 * so that applications can change values without knowing signals
87 #include <linux/module.h>
89 #include <linux/types.h>
90 #include <linux/errno.h>
91 #include <linux/signal.h>
92 #include <linux/sched.h>
93 #include <linux/spinlock.h>
94 #include <linux/smp_lock.h>
95 #include <linux/interrupt.h>
96 #include <linux/miscdevice.h>
97 #include <linux/slab.h> // previously <linux/malloc.h>
98 #include <linux/ioport.h>
99 #include <linux/fcntl.h>
100 #include <linux/init.h>
101 #include <linux/delay.h>
102 #include <linux/ctype.h>
103 #include <linux/parport.h>
104 #include <linux/version.h>
105 #include <linux/list.h>
106 #include <linux/notifier.h>
107 #include <linux/reboot.h>
108 #include <linux/utsrelease.h>
111 #include <asm/uaccess.h>
112 #include <asm/system.h>
114 /* smartcard length */
115 #define SMARTCARD_BYTES 64
116 #define LCD_MINOR 156
117 #define KEYPAD_MINOR 185
118 #define SMARTCARD_MINOR 186
120 #define PANEL_VERSION "0.9.5"
122 #define LCD_MAXBYTES 256 /* max burst write */
124 #define SMARTCARD_LOGICAL_DETECTOR "S6" /* D6 wired to SELECT = card inserted */
126 #define KEYPAD_BUFFER 64
127 #define INPUT_POLL_TIME (HZ/50) /* poll the keyboard this every second */
128 #define KEYPAD_REP_START (10) /* a key starts to repeat after this times INPUT_POLL_TIME */
129 #define KEYPAD_REP_DELAY (2) /* a key repeats this times INPUT_POLL_TIME */
131 #define FLASH_LIGHT_TEMPO (200) /* keep the light on this times INPUT_POLL_TIME for each flash */
133 /* converts an r_str() input to an active high, bits string : 000BAOSE */
134 #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
136 #define PNL_PBUSY 0x80 /* inverted input, active low */
137 #define PNL_PACK 0x40 /* direct input, active low */
138 #define PNL_POUTPA 0x20 /* direct input, active high */
139 #define PNL_PSELECD 0x10 /* direct input, active high */
140 #define PNL_PERRORP 0x08 /* direct input, active low */
142 #define PNL_PBIDIR 0x20 /* bi-directional ports */
143 #define PNL_PINTEN 0x10 /* high to read data in or-ed with data out */
144 #define PNL_PSELECP 0x08 /* inverted output, active low */
145 #define PNL_PINITP 0x04 /* direct output, active low */
146 #define PNL_PAUTOLF 0x02 /* inverted output, active low */
147 #define PNL_PSTROBE 0x01 /* inverted output */
168 #define PIN_AUTOLF 14
170 #define PIN_SELECP 17
171 #define PIN_NOT_SET 127
173 /* some smartcard-specific signals */
174 #define PNL_SC_IO PNL_PD1 /* Warning! inverted output, 0=highZ */
175 #define PNL_SC_RST PNL_PD2
176 #define PNL_SC_CLK PNL_PD3
177 #define PNL_SC_RW PNL_PD4
178 #define PNL_SC_ENA PNL_PINITP
179 #define PNL_SC_IOR PNL_PACK
180 #define PNL_SC_BITS (PNL_SC_IO | PNL_SC_RST | PNL_SC_CLK | PNL_SC_RW)
182 #define LCD_FLAG_S 0x0001
183 #define LCD_FLAG_ID 0x0002
184 #define LCD_FLAG_B 0x0004 /* blink on */
185 #define LCD_FLAG_C 0x0008 /* cursor on */
186 #define LCD_FLAG_D 0x0010 /* display on */
187 #define LCD_FLAG_F 0x0020 /* large font mode */
188 #define LCD_FLAG_N 0x0040 /* 2-rows mode */
189 #define LCD_FLAG_L 0x0080 /* backlight enabled */
191 #define LCD_ESCAPE_LEN 24 /* 24 chars max for an LCD escape command */
192 #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
194 /* macros to simplify use of the parallel port */
195 #define r_ctr(x) (parport_read_control((x)->port))
196 #define r_dtr(x) (parport_read_data((x)->port))
197 #define r_str(x) (parport_read_status((x)->port))
198 #define w_ctr(x,y) do { parport_write_control((x)->port, (y)); } while (0)
199 #define w_dtr(x,y) do { parport_write_data((x)->port, (y)); } while (0)
201 /* this defines which bits are to be used and which ones to be ignored */
202 static __u8 scan_mask_o = 0; /* logical or of the output bits involved in the scan matrix */
203 static __u8 scan_mask_i = 0; /* logical or of the input bits involved in the scan matrix */
205 typedef __u64 pmask_t;
219 struct logical_input {
220 struct list_head list;
223 enum input_type type;
224 enum input_state state;
225 __u8 rise_time, fall_time;
226 __u8 rise_timer, fall_timer, high_timer;
229 struct { /* this structure is valid when type == INPUT_TYPE_STD */
230 void(*press_fct)(int);
231 void(*release_fct)(int);
235 struct { /* this structure is valid when type == INPUT_TYPE_KBD */
236 /* strings can be full-length (ie. non null-terminated) */
237 char press_str[sizeof(void *) + sizeof (int)];
238 char repeat_str[sizeof(void *) + sizeof (int)];
239 char release_str[sizeof(void *) + sizeof (int)];
244 LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
246 /* physical contacts history
247 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
248 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
249 * corresponds to the ground.
250 * Within each group, bits are stored in the same order as read on the port :
251 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
252 * So, each __u64 (or pmask_t) is represented like this :
253 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
254 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
256 static pmask_t phys_read; /* what has just been read from the I/O ports */
257 static pmask_t phys_read_prev; /* previous phys_read */
258 static pmask_t phys_curr; /* stabilized phys_read (phys_read|phys_read_prev) */
259 static pmask_t phys_prev; /* previous phys_curr */
260 static char inputs_stable = 0; /* 0 means that at least one logical signal needs be computed */
262 /* these variables are specific to the smartcard */
263 static __u8 smartcard_data[SMARTCARD_BYTES];
264 static int smartcard_ptr = 0; /* pointer to half bytes in smartcard_data */
266 /* these variables are specific to the keypad */
267 static char keypad_buffer[KEYPAD_BUFFER];
268 static int keypad_buflen = 0;
269 static int keypad_start = 0;
270 static char keypressed = 0;
271 static wait_queue_head_t keypad_read_wait;
272 static wait_queue_head_t smartcard_read_wait;
274 /* lcd-specific variables */
275 static unsigned long int lcd_flags = 0; /* contains the LCD config state */
276 static unsigned long int lcd_addr_x = 0; /* contains the LCD X offset */
277 static unsigned long int lcd_addr_y = 0; /* contains the LCD Y offset */
278 static char lcd_escape[LCD_ESCAPE_LEN+1]; /* current escape sequence, 0 terminated */
279 static int lcd_escape_len = -1; /* not in escape state. >=0 = escape cmd len */
281 static int lcd_height = -1;
282 static int lcd_width = -1;
283 static int lcd_hwidth = -1; /* hardware buffer width (usually 64) */
284 static int lcd_bwidth = -1; /* internal buffer width (usually 40) */
287 * These are the parallel port pins the LCD control signals are connected to.
288 * Set this to 0 if the signal is not used. Set it to its opposite value
289 * (negative) if the signal is negated. -MAXINT is used to indicate that the
290 * pin has not been explicitly specified.
292 * WARNING! no check will be performed about collisions with keypad/smartcard !
294 static int lcd_e_pin = PIN_NOT_SET;
295 static int lcd_rs_pin = PIN_NOT_SET;
296 static int lcd_rw_pin = PIN_NOT_SET;
297 static int lcd_bl_pin = PIN_NOT_SET;
298 static int lcd_cl_pin = PIN_NOT_SET;
299 static int lcd_da_pin = PIN_NOT_SET;
302 * Bit masks to convert LCD signals to parallel port outputs.
303 * _d_ are values for data port, _c_ are for control port.
304 * [0] = signal OFF, [1] = signal ON, [2] = mask
311 * one entry for each bit on the LCD
322 * each bit can be either connected to a DATA or CTRL port
328 static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
333 #define LCD_PROTO_PARALLEL 0
334 #define LCD_PROTO_SERIAL 1
339 #define LCD_CHARSET_NORMAL 0
340 #define LCD_CHARSET_KS0074 1
345 #define LCD_TYPE_NONE 0
346 #define LCD_TYPE_OLD 1
347 #define LCD_TYPE_KS0074 2
348 #define LCD_TYPE_HANTRONIX 3
349 #define LCD_TYPE_NEXCOM 4
350 #define LCD_TYPE_CUSTOM 5
355 #define KEYPAD_TYPE_NONE 0
356 #define KEYPAD_TYPE_OLD 1
357 #define KEYPAD_TYPE_NEW 2
358 #define KEYPAD_TYPE_NEXCOM 3
363 #define PANEL_PROFILE_CUSTOM 0
364 #define PANEL_PROFILE_OLD 1
365 #define PANEL_PROFILE_NEW 2
366 #define PANEL_PROFILE_HANTRONIX 3
367 #define PANEL_PROFILE_NEXCOM 4
368 #define PANEL_PROFILE_LARGE 5
371 * Construct custom config from the kernel's configuration
373 #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
374 #define DEFAULT_PARPORT 0
375 #define DEFAULT_LCD LCD_TYPE_OLD
376 #define DEFAULT_KEYPAD KEYPAD_TYPE_OLD
377 #define DEFAULT_SMARTCARD 0
378 #define DEFAULT_LCD_WIDTH 40
379 #define DEFAULT_LCD_BWIDTH 40
380 #define DEFAULT_LCD_HWIDTH 64
381 #define DEFAULT_LCD_HEIGHT 2
382 #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
384 #define DEFAULT_LCD_PIN_E PIN_AUTOLF
385 #define DEFAULT_LCD_PIN_RS PIN_SELECP
386 #define DEFAULT_LCD_PIN_RW PIN_INITP
387 #define DEFAULT_LCD_PIN_SCL PIN_STROBE
388 #define DEFAULT_LCD_PIN_SDA PIN_D0
389 #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
390 #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
392 #ifdef CONFIG_PANEL_PROFILE
393 #undef DEFAULT_PROFILE
394 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
397 #ifdef CONFIG_PANEL_PARPORT
398 #undef DEFAULT_PARPORT
399 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
402 #if DEFAULT_PROFILE==0 /* custom */
403 #ifdef CONFIG_PANEL_KEYPAD
404 #undef DEFAULT_KEYPAD
405 #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD
408 #ifdef CONFIG_PANEL_SMARTCARD
409 #undef DEFAULT_SMARTCARD
410 #define DEFAULT_SMARTCARD 1
413 #ifdef CONFIG_PANEL_LCD
415 #define DEFAULT_LCD CONFIG_PANEL_LCD
418 #ifdef CONFIG_PANEL_LCD_WIDTH
419 #undef DEFAULT_LCD_WIDTH
420 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
423 #ifdef CONFIG_PANEL_LCD_BWIDTH
424 #undef DEFAULT_LCD_BWIDTH
425 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
428 #ifdef CONFIG_PANEL_LCD_HWIDTH
429 #undef DEFAULT_LCD_HWIDTH
430 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
433 #ifdef CONFIG_PANEL_LCD_HEIGHT
434 #undef DEFAULT_LCD_HEIGHT
435 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
438 #ifdef CONFIG_PANEL_LCD_PROTO
439 #undef DEFAULT_LCD_PROTO
440 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
443 #ifdef CONFIG_PANEL_LCD_PIN_E
444 #undef DEFAULT_LCD_PIN_E
445 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
448 #ifdef CONFIG_PANEL_LCD_PIN_RS
449 #undef DEFAULT_LCD_PIN_RS
450 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
453 #ifdef CONFIG_PANEL_LCD_PIN_RW
454 #undef DEFAULT_LCD_PIN_RW
455 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
458 #ifdef CONFIG_PANEL_LCD_PIN_SCL
459 #undef DEFAULT_LCD_PIN_SCL
460 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
463 #ifdef CONFIG_PANEL_LCD_PIN_SDA
464 #undef DEFAULT_LCD_PIN_SDA
465 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
468 #ifdef CONFIG_PANEL_LCD_PIN_BL
469 #undef DEFAULT_LCD_PIN_BL
470 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
473 #ifdef CONFIG_PANEL_LCD_CHARSET
474 #undef DEFAULT_LCD_CHARSET
475 #define DEFAULT_LCD_CHARSET
478 #endif /* DEFAULT_PROFILE == 0 */
480 /* global variables */
481 static int smartcard_open_cnt = 0; /* #times opened */
482 static int keypad_open_cnt = 0; /* #times opened */
483 static int lcd_open_cnt = 0; /* #times opened */
485 static int profile = DEFAULT_PROFILE;
486 static struct pardevice *pprt = NULL;
487 static int parport = -1;
488 static int lcd_enabled = -1;
489 static int lcd_type = -1;
490 static int lcd_proto = -1;
491 static int lcd_charset = -1;
492 static int keypad_enabled = -1;
493 static int keypad_type = -1;
494 static int smartcard_enabled = -1;
496 static int lcd_initialized, keypad_initialized, smartcard_initialized;
498 static int light_tempo = 0;
500 static char lcd_must_clear = 0;
501 static char lcd_left_shift = 0;
502 static char init_in_progress = 0;
504 static void(*lcd_write_cmd)(int) = NULL;
505 static void(*lcd_write_data)(int) = NULL;
506 static void(*lcd_clear_fast)(void) = NULL;
508 static spinlock_t pprt_lock = SPIN_LOCK_UNLOCKED;
509 static struct timer_list scan_timer;
513 MODULE_DESCRIPTION("Generic parallel port LCD/Keypad/Smartcard driver");
514 module_param(parport, int, 0000);MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
515 module_param(lcd_height, int, 0000);MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
516 module_param(lcd_width, int, 0000);MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
517 module_param(lcd_bwidth, int, 0000);MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
518 module_param(lcd_hwidth, int, 0000);MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
519 module_param(lcd_enabled, int, 0000);MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
520 module_param(keypad_enabled, int, 0000);MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
521 module_param(lcd_type, int, 0000);MODULE_PARM_DESC(lcd_type, "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
522 module_param(lcd_proto, int, 0000);MODULE_PARM_DESC(lcd_proto, "LCD communication: 0=parallel (//), 1=serial");
523 module_param(lcd_charset, int, 0000);MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
524 module_param(keypad_type, int, 0000);MODULE_PARM_DESC(keypad_type, "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
525 module_param(smartcard_enabled, int, 0000);MODULE_PARM_DESC(smartcard_enabled, "Smartcard reader: 0=disabled (default), 1=enabled");
526 module_param(profile, int, 0000); MODULE_PARM_DESC(profile, "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; 4=16x2 nexcom; default=40x2, old kp");
528 module_param(lcd_e_pin, int, 0000); MODULE_PARM_DESC(lcd_e_pin, "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
529 module_param(lcd_rs_pin, int, 0000);MODULE_PARM_DESC(lcd_rs_pin, "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
530 module_param(lcd_rw_pin, int, 0000);MODULE_PARM_DESC(lcd_rw_pin, "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
531 module_param(lcd_bl_pin, int, 0000);MODULE_PARM_DESC(lcd_bl_pin, "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
532 module_param(lcd_da_pin, int, 0000);MODULE_PARM_DESC(lcd_da_pin, "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
533 module_param(lcd_cl_pin, int, 0000);MODULE_PARM_DESC(lcd_cl_pin, "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
537 static unsigned char *lcd_char_conv = NULL;
539 /* for some LCD drivers (ks0074) we need a charset conversion table. */
540 static unsigned char lcd_char_conv_ks0074[256] = {
541 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
542 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
543 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
544 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
545 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
546 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
547 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
548 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
549 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
550 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
551 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
552 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f, 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
553 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd, 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
554 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9, 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
555 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78, 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
556 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8, 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
557 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25, 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
560 char old_keypad_profile[][4][9] = {
561 {"S0", "Left\n", "Left\n", ""},
562 {"S1", "Down\n", "Down\n", ""},
563 {"S2", "Up\n", "Up\n", ""},
564 {"S3", "Right\n", "Right\n", ""},
565 {"S4", "Esc\n", "Esc\n", ""},
566 {"S5", "Ret\n", "Ret\n", ""},
570 /* signals, press, repeat, release */
571 char new_keypad_profile[][4][9] = {
572 {"S0", "Left\n", "Left\n", ""},
573 {"S1", "Down\n", "Down\n", ""},
574 {"S2", "Up\n", "Up\n", ""},
575 {"S3", "Right\n", "Right\n", ""},
576 {"S4s5", "", "Esc\n", "Esc\n"},
577 {"s4S5", "", "Ret\n", "Ret\n"},
578 {"S4S5", "Help\n", "", ""},
579 /* add new signals above this line */
583 /* signals, press, repeat, release */
584 char nexcom_keypad_profile[][4][9] = {
585 {"a-p-e-", "Down\n", "Down\n", ""}, // Down
586 {"a-p-E-", "Ret\n", "Ret\n", ""}, // Enter
587 {"a-P-E-", "Esc\n", "Esc\n", ""}, // Esc
588 {"a-P-e-", "Up\n", "Up\n", ""}, // Up
589 /* add new signals above this line */
593 static char (*keypad_profile)[4][9] = old_keypad_profile;
595 /* FIXME: this should be converted to a bit array containing signals states */
597 unsigned char e; /* parallel LCD E (data latch on falling edge) */
598 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
599 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
600 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
601 unsigned char cl; /* serial LCD clock (latch on rising edge) */
602 unsigned char da; /* serial LCD data */
605 static void init_scan_timer(void);
607 /* sets data port bits according to current signals values */
608 static int set_data_bits(void) {
612 for (bit = 0; bit < LCD_BITS; bit++)
613 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
615 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
616 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
617 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
618 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
619 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
620 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
626 /* sets ctrl port bits according to current signals values */
627 static int set_ctrl_bits(void) {
631 for (bit = 0; bit < LCD_BITS; bit++)
632 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
634 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
635 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
636 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
637 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
638 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
639 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
645 /* sets ctrl & data port bits according to current signals values */
646 static void set_bits(void) {
652 * Converts a parallel port pin (from -25 to 25) to data and control ports
653 * masks, and data and control port bits. The signal will be considered
654 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
656 * Result will be used this way :
657 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
658 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
660 void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val) {
661 int d_bit, c_bit, inv;
663 d_val[0] = c_val[0] = d_val[1] = c_val[1] = 0;
664 d_val[2] = c_val[2] = 0xFF;
676 case PIN_STROBE: /* strobe, inverted */
680 case PIN_D0 ... PIN_D7: /* D0 - D7 = 2 - 9 */
681 d_bit = 1 << (pin - 2);
683 case PIN_AUTOLF: /* autofeed, inverted */
687 case PIN_INITP: /* init, direct */
690 case PIN_SELECP: /* select_in, inverted */
694 default: /* unknown pin, ignore */
707 /* sleeps that many milliseconds with a reschedule */
708 static void long_sleep(int ms) {
713 current->state = TASK_INTERRUPTIBLE;
714 schedule_timeout((ms*HZ+999)/1000);
719 /* send a serial byte to the LCD panel. The caller is responsible for locking if needed. */
720 static void lcd_send_serial(int byte) {
723 /* the data bit is set on D0, and the clock on STROBE.
724 * LCD reads D0 on STROBE's rising edge.
726 for (bit = 0; bit < 8; bit++) {
727 bits.cl = BIT_CLR; /* CLK low */
731 udelay(2); /* maintain the data during 2 us before CLK up */
732 bits.cl = BIT_SET; /* CLK high */
734 udelay(1); /* maintain the strobe during 1 us */
739 /* turn the backlight on or off */
740 static void lcd_backlight(int on) {
741 if (lcd_bl_pin == PIN_NONE)
744 /* The backlight is activated by seting the AUTOFEED line to +5V */
745 spin_lock(&pprt_lock);
748 spin_unlock(&pprt_lock);
751 /* send a command to the LCD panel in serial mode */
752 static void lcd_write_cmd_s(int cmd) {
753 spin_lock(&pprt_lock);
754 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
755 lcd_send_serial(cmd & 0x0F);
756 lcd_send_serial((cmd >> 4) & 0x0F);
757 udelay(40); /* the shortest command takes at least 40 us */
758 spin_unlock(&pprt_lock);
761 /* send data to the LCD panel in serial mode */
762 static void lcd_write_data_s(int data) {
763 spin_lock(&pprt_lock);
764 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
765 lcd_send_serial(data & 0x0F);
766 lcd_send_serial((data >> 4) & 0x0F);
767 udelay(40); /* the shortest data takes at least 40 us */
768 spin_unlock(&pprt_lock);
771 /* send a command to the LCD panel in 8 bits parallel mode */
772 static void lcd_write_cmd_p8(int cmd) {
773 spin_lock(&pprt_lock);
774 /* present the data to the data port */
776 udelay(20); /* maintain the data during 20 us before the strobe */
778 bits.e = BIT_SET ; bits.rs = BIT_CLR ; bits.rw = BIT_CLR;
781 udelay(40); /* maintain the strobe during 40 us */
786 udelay(120); /* the shortest command takes at least 120 us */
787 spin_unlock(&pprt_lock);
790 /* send data to the LCD panel in 8 bits parallel mode */
791 static void lcd_write_data_p8(int data) {
792 spin_lock(&pprt_lock);
793 /* present the data to the data port */
795 udelay(20); /* maintain the data during 20 us before the strobe */
797 bits.e = BIT_SET ; bits.rs = BIT_SET ; bits.rw = BIT_CLR;
800 udelay(40); /* maintain the strobe during 40 us */
805 udelay(45); /* the shortest data takes at least 45 us */
806 spin_unlock(&pprt_lock);
809 static void lcd_gotoxy(void) {
810 lcd_write_cmd(0x80 /* set DDRAM address */
811 | (lcd_addr_y ? lcd_hwidth : 0)
812 /* we force the cursor to stay at the end of the line if it wants to go farther */
813 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x & (lcd_hwidth-1) : lcd_bwidth - 1));
816 static void lcd_print(char c) {
817 if (lcd_addr_x < lcd_bwidth) {
818 if (lcd_char_conv != NULL)
819 c = lcd_char_conv[(unsigned char)c];
823 /* prevents the cursor from wrapping onto the next line */
824 if (lcd_addr_x == lcd_bwidth) {
829 /* fills the display with spaces and resets X/Y */
830 static void lcd_clear_fast_s(void) {
832 lcd_addr_x = lcd_addr_y = 0;
835 spin_lock(&pprt_lock);
836 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
837 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
838 lcd_send_serial(' ' & 0x0F);
839 lcd_send_serial((' ' >> 4) & 0x0F);
840 udelay(40); /* the shortest data takes at least 40 us */
842 spin_unlock(&pprt_lock);
844 lcd_addr_x = lcd_addr_y = 0;
848 /* fills the display with spaces and resets X/Y */
849 static void lcd_clear_fast_p8(void) {
851 lcd_addr_x = lcd_addr_y = 0;
854 spin_lock(&pprt_lock);
855 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
856 /* present the data to the data port */
858 udelay(20); /* maintain the data during 20 us before the strobe */
860 bits.e = BIT_SET ; bits.rs = BIT_SET ; bits.rw = BIT_CLR;
863 udelay(40); /* maintain the strobe during 40 us */
868 udelay(45); /* the shortest data takes at least 45 us */
870 spin_unlock(&pprt_lock);
872 lcd_addr_x = lcd_addr_y = 0;
876 /* clears the display and resets X/Y */
877 static void lcd_clear_display(void) {
878 lcd_write_cmd(0x01); /* clear display */
879 lcd_addr_x = lcd_addr_y = 0;
880 /* we must wait a few milliseconds (15) */
884 static void lcd_init_display(void) {
886 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
887 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
889 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
891 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
893 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
895 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
898 lcd_write_cmd(0x30 /* set font height and lines number */
899 | ((lcd_flags & LCD_FLAG_F)?4:0)
900 | ((lcd_flags & LCD_FLAG_N)?8:0)
904 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
907 lcd_write_cmd(0x08 /* set display mode */
908 | ((lcd_flags & LCD_FLAG_D)?4:0)
909 | ((lcd_flags & LCD_FLAG_C)?2:0)
910 | ((lcd_flags & LCD_FLAG_B)?1:0)
913 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
917 lcd_write_cmd(0x06); /* entry mode set : increment, cursor shifting */
923 * These are the file operation function for user access to /dev/lcd
924 * This function can also be called from inside the kernel, by
925 * setting file and ppos to NULL.
929 static ssize_t lcd_write(struct file * file,
930 const char * buf, size_t count, loff_t *ppos ) {
932 const char *tmp = buf;
935 for( ; count-- > 0; (ppos ? (*ppos)++ : 0), ++tmp ) {
936 if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) {
937 schedule(); /* let's be a little nice with other processes that need some CPU */
939 if (ppos == NULL && file == NULL)
940 c = *tmp; /* let's not use get_user() from the kernel ! */
941 else if (get_user( c, tmp ))
944 /* first, we'll test if we're in escape mode */
945 if ((c != '\n') && lcd_escape_len >= 0) { /* yes, let's add this char to the buffer */
946 lcd_escape[lcd_escape_len++] = c;
947 lcd_escape[lcd_escape_len] = 0;
950 lcd_escape_len = -1; /* aborts any previous escape sequence */
953 case LCD_ESCAPE_CHAR: /* start of an escape sequence */
955 lcd_escape[lcd_escape_len] = 0;
957 case '\b': /* go back one char and clear it */
958 if (lcd_addr_x > 0) {
959 if (lcd_addr_x < lcd_bwidth) /* check if we're not at the end of the line */
960 lcd_write_cmd(0x10); /* back one char */
963 lcd_write_data(' '); /* replace with a space */
964 lcd_write_cmd(0x10); /* back one char again */
966 case '\014': /* quickly clear the display */
969 case '\n': /* flush the remainder of the current line and go to the
970 beginning of the next line */
971 for (; lcd_addr_x<lcd_bwidth; lcd_addr_x++)
974 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
977 case '\r': /* go to the beginning of the same line */
981 case '\t': /* print a space instead of the tab */
984 default : /* simply print this char */
990 /* now we'll see if we're in an escape mode and if the current
991 escape sequence can be understood.
993 if (lcd_escape_len >= 2) { /* minimal length for an escape command */
994 int processed = 0; /* 1 means the command has been processed */
996 if (!strcmp(lcd_escape,"[2J")) { /* Clear the display */
997 lcd_clear_fast(); /* clear display */
1000 else if (!strcmp(lcd_escape,"[H")) { /* Cursor to home */
1001 lcd_addr_x = lcd_addr_y = 0;
1005 /* codes starting with ^[[L */
1006 else if ((lcd_escape_len >= 3) &&
1007 (lcd_escape[0]=='[') && (lcd_escape[1]=='L')) { /* LCD special codes */
1009 char *esc = lcd_escape + 2;
1010 int oldflags = lcd_flags;
1012 /* check for display mode flags */
1014 case 'D' : /* Display ON */
1015 lcd_flags |= LCD_FLAG_D;
1018 case 'd' : /* Display OFF */
1019 lcd_flags &= ~LCD_FLAG_D;
1022 case 'C' : /* Cursor ON */
1023 lcd_flags |= LCD_FLAG_C;
1026 case 'c' : /* Cursor OFF */
1027 lcd_flags &= ~LCD_FLAG_C;
1030 case 'B' : /* Blink ON */
1031 lcd_flags |= LCD_FLAG_B;
1034 case 'b' : /* Blink OFF */
1035 lcd_flags &= ~LCD_FLAG_B;
1038 case '+' : /* Back light ON */
1039 lcd_flags |= LCD_FLAG_L;
1042 case '-' : /* Back light OFF */
1043 lcd_flags &= ~LCD_FLAG_L;
1046 case '*' : /* flash back light using the keypad timer */
1047 if (scan_timer.function != NULL) {
1048 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1050 light_tempo = FLASH_LIGHT_TEMPO;
1054 case 'f' : /* Small Font */
1055 lcd_flags &= ~LCD_FLAG_F;
1058 case 'F' : /* Large Font */
1059 lcd_flags |= LCD_FLAG_F;
1062 case 'n' : /* One Line */
1063 lcd_flags &= ~LCD_FLAG_N;
1066 case 'N' : /* Two Lines */
1067 lcd_flags |= LCD_FLAG_N;
1070 case 'l' : /* Shift Cursor Left */
1071 if (lcd_addr_x > 0) {
1072 if (lcd_addr_x < lcd_bwidth)
1073 lcd_write_cmd(0x10); /* back one char if not at end of line */
1079 case 'r' : /* shift cursor right */
1080 if (lcd_addr_x < lcd_width) {
1081 if (lcd_addr_x < (lcd_bwidth - 1))
1082 lcd_write_cmd(0x14); /* allow the cursor to pass the end of the line */
1088 case 'L' : /* shift display left */
1090 lcd_write_cmd(0x18);
1094 case 'R' : /* shift display right */
1096 lcd_write_cmd(0x1C);
1100 case 'k' : { /* kill end of line */
1102 for (x=lcd_addr_x; x<lcd_bwidth; x++)
1103 lcd_write_data(' ');
1104 lcd_gotoxy(); /* restore cursor position */
1108 case 'I' : /* reinitialize display */
1114 case 'G' : /* Generator : LGcxxxxx...xx; */ {
1115 /* must have <c> between '0' and '7', representing the numerical
1116 * ASCII code of the redefined character, and <xx...xx> a sequence
1117 * of 16 hex digits representing 8 bytes for each character. Most
1118 * LCDs will only use 5 lower bits of the 7 first bytes.
1121 unsigned char cgbytes[8];
1122 unsigned char cgaddr;
1128 if (strchr(esc, ';') == NULL)
1133 cgaddr = *(esc++) - '0';
1142 while (*esc && cgoffset < 8) {
1144 if (*esc >= '0' && *esc <='9')
1145 value |= (*esc - '0') << shift;
1146 else if (*esc >= 'A' && *esc <='Z')
1147 value |= (*esc - 'A' + 10) << shift;
1148 else if (*esc >= 'a' && *esc <='z')
1149 value |= (*esc - 'a' + 10) << shift;
1156 cgbytes[cgoffset++] = value;
1163 lcd_write_cmd(0x40 | (cgaddr * 8));
1164 for (addr = 0; addr < cgoffset; addr++) {
1165 lcd_write_data(cgbytes[addr]);
1168 lcd_gotoxy(); /* ensures that we stop writing to CGRAM */
1172 case 'x' : /* gotoxy : LxXXX[yYYY]; */
1173 case 'y' : /* gotoxy : LyYYY[xXXX]; */
1174 if (strchr(esc, ';') == NULL)
1181 while (isdigit(*esc)) {
1182 lcd_addr_x = lcd_addr_x*10 + (*esc - '0');
1186 else if (*esc == 'y') {
1189 while (isdigit(*esc)) {
1190 lcd_addr_y = lcd_addr_y*10 + (*esc - '0');
1200 } /* end of switch */
1202 /* Check wether one flag was changed */
1203 if (oldflags != lcd_flags) {
1204 /* check wether one of B,C,D flags was changed */
1205 if ((oldflags ^ lcd_flags) & (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1206 lcd_write_cmd(0x08 /* set display mode */
1207 | ((lcd_flags & LCD_FLAG_D)?4:0)
1208 | ((lcd_flags & LCD_FLAG_C)?2:0)
1209 | ((lcd_flags & LCD_FLAG_B)?1:0)
1211 /* check wether one of F,N flags was changed */
1212 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1214 | ((lcd_flags & LCD_FLAG_F)?4:0)
1215 | ((lcd_flags & LCD_FLAG_N)?8:0)
1217 /* check wether L flag was changed */
1218 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1219 if (lcd_flags & (LCD_FLAG_L))
1221 else if (light_tempo == 0) /* switch off the light only when the tempo lighting is gone */
1225 } /* LCD special escape codes */
1227 /* flush the escape sequence if it's been processed or if it is
1228 getting too long. */
1229 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1230 lcd_escape_len = -1;
1231 } /* escape codes */
1234 return( tmp - buf );
1237 static int lcd_open( struct inode *inode, struct file *file ) {
1239 return( -EBUSY ); /* open only once at a time */
1241 if (file->f_mode & FMODE_READ) /* device is write-only */
1244 if (lcd_must_clear) {
1245 lcd_clear_display();
1252 static int lcd_release( struct inode *inode, struct file *file ) {
1258 static struct file_operations lcd_fops = {
1261 release: lcd_release,
1264 static struct miscdevice lcd_dev = {
1272 /* public function usable from the kernel for any purpose */
1273 void panel_lcd_print(char *s) {
1274 if (lcd_enabled && lcd_initialized)
1275 lcd_write(NULL, s, strlen(s), NULL);
1279 /* initialize the LCD driver */
1280 void lcd_init(void) {
1282 case LCD_TYPE_OLD : /* parallel mode, 8 bits */
1283 if (lcd_proto < 0) lcd_proto = LCD_PROTO_PARALLEL;
1284 if (lcd_charset < 0) lcd_charset = LCD_CHARSET_NORMAL;
1285 if (lcd_e_pin == PIN_NOT_SET) lcd_e_pin = PIN_STROBE;
1286 if (lcd_rs_pin == PIN_NOT_SET) lcd_rs_pin = PIN_AUTOLF;
1288 if (lcd_width < 0) lcd_width = 40;
1289 if (lcd_bwidth < 0) lcd_bwidth = 40;
1290 if (lcd_hwidth < 0) lcd_hwidth = 64;
1291 if (lcd_height < 0) lcd_height = 2;
1293 case LCD_TYPE_KS0074 : /* serial mode, ks0074 */
1294 if (lcd_proto < 0) lcd_proto = LCD_PROTO_SERIAL;
1295 if (lcd_charset < 0) lcd_charset = LCD_CHARSET_KS0074;
1296 if (lcd_bl_pin == PIN_NOT_SET) lcd_bl_pin = PIN_AUTOLF;
1297 if (lcd_cl_pin == PIN_NOT_SET) lcd_cl_pin = PIN_STROBE;
1298 if (lcd_da_pin == PIN_NOT_SET) lcd_da_pin = PIN_D0;
1300 if (lcd_width < 0) lcd_width = 16;
1301 if (lcd_bwidth < 0) lcd_bwidth = 40;
1302 if (lcd_hwidth < 0) lcd_hwidth = 16;
1303 if (lcd_height < 0) lcd_height = 2;
1305 case LCD_TYPE_NEXCOM : /* parallel mode, 8 bits, generic */
1306 if (lcd_proto < 0) lcd_proto = LCD_PROTO_PARALLEL;
1307 if (lcd_charset < 0) lcd_charset = LCD_CHARSET_NORMAL;
1308 if (lcd_e_pin == PIN_NOT_SET) lcd_e_pin = PIN_AUTOLF;
1309 if (lcd_rs_pin == PIN_NOT_SET) lcd_rs_pin = PIN_SELECP;
1310 if (lcd_rw_pin == PIN_NOT_SET) lcd_rw_pin = PIN_INITP;
1312 if (lcd_width < 0) lcd_width = 16;
1313 if (lcd_bwidth < 0) lcd_bwidth = 40;
1314 if (lcd_hwidth < 0) lcd_hwidth = 64;
1315 if (lcd_height < 0) lcd_height = 2;
1317 case LCD_TYPE_CUSTOM : /* customer-defined */
1318 if (lcd_proto < 0) lcd_proto = DEFAULT_LCD_PROTO;
1319 if (lcd_charset < 0) lcd_charset = DEFAULT_LCD_CHARSET;
1320 /* default geometry will be set later */
1322 case LCD_TYPE_HANTRONIX : /* parallel mode, 8 bits, hantronix-like */
1324 if (lcd_proto < 0) lcd_proto = LCD_PROTO_PARALLEL;
1325 if (lcd_charset < 0) lcd_charset = LCD_CHARSET_NORMAL;
1326 if (lcd_e_pin == PIN_NOT_SET) lcd_e_pin = PIN_STROBE;
1327 if (lcd_rs_pin == PIN_NOT_SET) lcd_rs_pin = PIN_SELECP;
1329 if (lcd_width < 0) lcd_width = 16;
1330 if (lcd_bwidth < 0) lcd_bwidth = 40;
1331 if (lcd_hwidth < 0) lcd_hwidth = 64;
1332 if (lcd_height < 0) lcd_height = 2;
1336 /* this is used to catch wrong and default values */
1337 if (lcd_width <= 0) lcd_width = DEFAULT_LCD_WIDTH;
1338 if (lcd_bwidth <= 0) lcd_bwidth = DEFAULT_LCD_BWIDTH;
1339 if (lcd_hwidth <= 0) lcd_hwidth = DEFAULT_LCD_HWIDTH;
1340 if (lcd_height <= 0) lcd_height = DEFAULT_LCD_HEIGHT;
1342 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */
1343 lcd_write_cmd = lcd_write_cmd_s;
1344 lcd_write_data = lcd_write_data_s;
1345 lcd_clear_fast = lcd_clear_fast_s;
1347 if (lcd_cl_pin == PIN_NOT_SET)
1348 lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1349 if (lcd_da_pin == PIN_NOT_SET)
1350 lcd_da_pin = DEFAULT_LCD_PIN_SDA;
1352 } else { /* PARALLEL */
1353 lcd_write_cmd = lcd_write_cmd_p8;
1354 lcd_write_data = lcd_write_data_p8;
1355 lcd_clear_fast = lcd_clear_fast_p8;
1357 if (lcd_e_pin == PIN_NOT_SET)
1358 lcd_e_pin = DEFAULT_LCD_PIN_E;
1359 if (lcd_rs_pin == PIN_NOT_SET)
1360 lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1361 if (lcd_rw_pin == PIN_NOT_SET)
1362 lcd_rw_pin = DEFAULT_LCD_PIN_RW;
1365 if (lcd_bl_pin == PIN_NOT_SET)
1366 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1368 if (lcd_e_pin == PIN_NOT_SET) lcd_e_pin = PIN_NONE;
1369 if (lcd_rs_pin == PIN_NOT_SET) lcd_rs_pin = PIN_NONE;
1370 if (lcd_rw_pin == PIN_NOT_SET) lcd_rw_pin = PIN_NONE;
1371 if (lcd_bl_pin == PIN_NOT_SET) lcd_bl_pin = PIN_NONE;
1372 if (lcd_cl_pin == PIN_NOT_SET) lcd_cl_pin = PIN_NONE;
1373 if (lcd_da_pin == PIN_NOT_SET) lcd_da_pin = PIN_NONE;
1375 if (lcd_charset < 0)
1376 lcd_charset = DEFAULT_LCD_CHARSET;
1378 if (lcd_charset == LCD_CHARSET_KS0074)
1379 lcd_char_conv = lcd_char_conv_ks0074;
1381 lcd_char_conv = NULL;
1383 if (lcd_bl_pin != PIN_NONE)
1386 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E], lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1387 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS], lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1388 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW], lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1389 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL], lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1390 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL], lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1391 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA], lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
1393 /* before this line, we must NOT send anything to the display.
1394 * Since lcd_init_display() needs to write data, we have to
1395 * enable mark the LCD initialized just before.
1397 lcd_initialized = 1;
1400 /* display a short message */
1401 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1402 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1403 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
1406 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-" PANEL_VERSION);
1408 lcd_addr_x = lcd_addr_y = 0;
1409 lcd_must_clear = 1; /* clear the display on the next device opening */
1415 * These are the file operation function for user access to /dev/keypad
1418 static ssize_t keypad_read(struct file * file,
1419 char * buf, size_t count, loff_t *ppos ) {
1424 if (keypad_buflen == 0) {
1425 if (file->f_flags & O_NONBLOCK)
1428 //printk(KERN_ERR "keypad_read():1 len=%d", keypad_buflen);
1429 interruptible_sleep_on(&keypad_read_wait);
1430 //printk(KERN_ERR "keypad_read():2 len=%d", keypad_buflen);
1431 if (signal_pending(current))
1435 //printk(KERN_ERR "keypad_read():3 len=%d", keypad_buflen);
1436 for( ; count-- > 0 && (keypad_buflen > 0); ++i, ++tmp, --keypad_buflen ) {
1437 put_user( keypad_buffer[keypad_start], tmp );
1438 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1441 //printk(KERN_ERR "keypad_read():4 len=%d", keypad_buflen);
1443 return( tmp - buf );
1447 static int keypad_open( struct inode *inode, struct file *file ) {
1449 if (keypad_open_cnt)
1450 return( -EBUSY ); /* open only once at a time */
1452 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1455 keypad_buflen = 0; /* flush the buffer on opening */
1460 static int keypad_release( struct inode *inode, struct file *file ) {
1465 static struct file_operations keypad_fops = {
1466 read: keypad_read, /* read */
1467 open: keypad_open, /* open */
1468 release: keypad_release, /* close */
1471 static struct miscdevice keypad_dev = {
1477 static void keypad_send_key(char *string, int max_len) {
1478 //printk(KERN_ERR "keypad_send_key(%c,%d):1\n", *string,max_len);
1479 if (init_in_progress)
1481 //printk(KERN_ERR "keypad_send_key(%c,%d):2\n", *string,max_len);
1483 /* send the key to the device only if a process is attached to it. */
1484 if (keypad_open_cnt > 0) {
1485 //printk(KERN_ERR "keypad_send_key(%c,%d):3\n", *string,max_len);
1486 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1487 keypad_buffer[(keypad_start + keypad_buflen++) % KEYPAD_BUFFER] = *string++;
1489 //printk(KERN_ERR "keypad_send_key(%d):4\n", *string,max_len);
1490 wake_up_interruptible(&keypad_read_wait);
1492 //printk(KERN_ERR "keypad_send_key(%d):5\n", *string,max_len);
1496 /* this function scans all the bits involving at least one logical signal, and puts the
1497 * results in the bitfield "phys_read" (one bit per established contact), and sets
1498 * "phys_read_prev" to "phys_read".
1500 * Note: to debounce input signals, we will only consider as switched a signal which is
1501 * stable across 2 measures. Signals which are different between two reads will be kept
1502 * as they previously were in their logical form (phys_prev). A signal which has just
1503 * switched will have a 1 in (phys_read ^ phys_read_prev).
1505 static void phys_scan_contacts(void) {
1511 phys_prev = phys_curr;
1512 phys_read_prev = phys_read;
1513 phys_read = 0; /* flush all signals */
1515 oldval = r_dtr(pprt) | scan_mask_o; /* keep track of old value, with all outputs disabled */
1516 w_dtr(pprt, oldval & ~scan_mask_o); /* activate all keyboard outputs (active low) */
1517 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; /* will have a 1 for each bit set to gnd */
1518 w_dtr(pprt, oldval); /* disable all matrix signals */
1520 /* now that all outputs are cleared, the only active input bits are
1521 * directly connected to the ground
1523 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; /* 1 for each grounded input */
1525 phys_read |= (pmask_t)gndmask << 40; /* grounded inputs are signals 40-44 */
1527 if (bitmask != gndmask) {
1528 /* since clearing the outputs changed some inputs, we know that some
1529 * input signals are currently tied to some outputs. So we'll scan them.
1531 for (bit = 0; bit < 8; bit ++) {
1534 if (!(scan_mask_o & bitval)) /* skip unused bits */
1537 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1538 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1539 phys_read |= (pmask_t) bitmask << (5*bit);
1541 w_dtr(pprt, oldval); /* disable all outputs */
1543 /* this is easy: use old bits when they are flapping, use new ones when stable */
1544 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) | (phys_read & ~(phys_read ^ phys_read_prev));
1547 static void panel_process_inputs(void) {
1548 struct list_head *item;
1549 struct logical_input *input;
1552 printk(KERN_DEBUG "entering panel_process_inputs with pp=%016Lx & pc=%016Lx\n",
1553 phys_prev, phys_curr);
1558 list_for_each(item, &logical_inputs) {
1559 input = list_entry(item, struct logical_input, list);
1561 switch (input->state) {
1563 if ((phys_curr & input->mask) != input->value)
1565 /* if all needed ones were already set previously, this means that
1566 * this logical signal has been activated by the releasing of
1567 * another combined signal, so we don't want to match.
1568 * eg: AB -(release B)-> A -(release A)-> 0 : don't match A.
1570 if ((phys_prev & input->mask) == input->value)
1572 input->rise_timer = 0;
1573 input->state = INPUT_ST_RISING;
1574 /* no break here, fall through */
1575 case INPUT_ST_RISING:
1576 if ((phys_curr & input->mask) != input->value) {
1577 input->state = INPUT_ST_LOW;
1580 if (input->rise_timer < input->rise_time) {
1582 input->rise_timer++;
1585 input->high_timer = 0;
1586 input->state = INPUT_ST_HIGH;
1587 /* no break here, fall through */
1591 * this is an invalid test. It tries to catch transitions from single-key
1592 * to multiple-key, but doesn't take into account the contacts polarity.
1593 * The only solution to the problem is to parse keys from the most complex
1594 * to the simplest combinations, and mark them as 'caught' once a combination
1595 * matches, then unmatch it for all other ones.
1598 /* try to catch dangerous transitions cases :
1599 * someone adds a bit, so this signal was a false
1600 * positive resulting from a transition. We should invalidate
1601 * the signal immediately and not call the release function.
1602 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1604 if (((phys_prev & input->mask) == input->value)
1605 && ((phys_curr & input->mask) > input->value)) {
1606 input->state = INPUT_ST_LOW; /* invalidate */
1612 if ((phys_curr & input->mask) == input->value) {
1613 if ((input->type == INPUT_TYPE_STD) && (input->high_timer == 0)) {
1614 input->high_timer++;
1615 if (input->u.std.press_fct != NULL)
1616 input->u.std.press_fct(input->u.std.press_data);
1618 else if (input->type == INPUT_TYPE_KBD) {
1619 keypressed = 1; /* will turn on the light */
1621 if (input->high_timer == 0) {
1622 if (input->u.kbd.press_str[0])
1623 keypad_send_key(input->u.kbd.press_str, sizeof(input->u.kbd.press_str));
1626 if (input->u.kbd.repeat_str[0]) {
1627 if (input->high_timer >= KEYPAD_REP_START) {
1628 input->high_timer -= KEYPAD_REP_DELAY;
1629 keypad_send_key(input->u.kbd.repeat_str, sizeof(input->u.kbd.repeat_str));
1631 inputs_stable = 0; /* we will need to come back here soon */
1634 if (input->high_timer < 255) {
1635 input->high_timer++;
1641 /* else signal falling down. Let's fall through. */
1642 input->state = INPUT_ST_FALLING;
1643 input->fall_timer = 0;
1645 /* no break here, fall through */
1646 case INPUT_ST_FALLING:
1648 /* FIXME !!! same comment as above */
1649 if (((phys_prev & input->mask) == input->value)
1650 && ((phys_curr & input->mask) > input->value)) {
1651 input->state = INPUT_ST_LOW; /* invalidate */
1657 if ((phys_curr & input->mask) == input->value) {
1658 if (input->type == INPUT_TYPE_KBD) {
1659 keypressed = 1; /* will turn on the light */
1661 if (input->u.kbd.repeat_str[0]) {
1662 if (input->high_timer >= KEYPAD_REP_START)
1663 input->high_timer -= KEYPAD_REP_DELAY;
1664 keypad_send_key(input->u.kbd.repeat_str, sizeof(input->u.kbd.repeat_str));
1665 inputs_stable = 0; /* we will need to come back here soon */
1668 if (input->high_timer < 255) {
1669 input->high_timer++;
1672 input->state = INPUT_ST_HIGH;
1675 else if (input->fall_timer >= input->fall_time) {
1676 /* call release event */
1677 if (input->type == INPUT_TYPE_STD) {
1678 if (input->u.std.release_fct != NULL)
1679 input->u.std.release_fct(input->u.std.release_data);
1681 else if (input->type == INPUT_TYPE_KBD) {
1682 if (input->u.kbd.release_str[0])
1683 keypad_send_key(input->u.kbd.release_str, sizeof(input->u.kbd.release_str));
1686 input->state = INPUT_ST_LOW;
1690 input->fall_timer++;
1698 static void panel_scan_timer(void) {
1699 if ((keypad_enabled && keypad_initialized)
1700 || (smartcard_enabled && smartcard_enabled)) {
1702 if (spin_trylock(&pprt_lock)) {
1703 phys_scan_contacts();
1704 spin_unlock(&pprt_lock); /* no need for the parport anymore */
1707 if (!inputs_stable || phys_curr != phys_prev) {
1708 panel_process_inputs();
1712 if (lcd_enabled && lcd_initialized) {
1714 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1716 light_tempo = FLASH_LIGHT_TEMPO;
1718 else if (light_tempo > 0) {
1720 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1725 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
1728 /* send a high / low clock impulse of <duration> microseconds high and low */
1729 static void smartcard_send_clock(int duration) {
1732 w_dtr(pprt, (old = r_dtr(pprt)) | PNL_SC_CLK);
1734 w_dtr(pprt, (old & ~PNL_SC_CLK));
1738 static void smartcard_insert(int dummy) {
1741 spin_lock(&pprt_lock);
1742 w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
1743 w_ctr(pprt, (r_ctr(pprt) | PNL_SC_ENA));
1745 udelay(30); /* ensure the rst is low at least 30 us */
1747 smartcard_send_clock(100); /* reset address counter */
1749 w_dtr(pprt, r_dtr(pprt) | PNL_SC_RST);
1750 udelay(30); /* ensure the rst is high at least 30 us */
1752 for (ofs = 0; ofs < SMARTCARD_BYTES; ofs++) {
1755 for (bit = 128; bit > 0; bit >>= 1) {
1756 if (!(r_str(pprt) & PNL_SC_IOR))
1758 smartcard_send_clock(15); /* 15 us are enough for data */
1760 smartcard_data[ofs] = byte;
1763 w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
1764 w_ctr(pprt, (r_ctr(pprt) & ~PNL_SC_ENA));
1766 spin_unlock(&pprt_lock);
1768 printk(KERN_INFO "Panel: smart card inserted : %02x%02x%02x%02x%1x\n",
1769 smartcard_data[2], smartcard_data[3], smartcard_data[4],
1770 smartcard_data[5], smartcard_data[6] >> 4);
1771 keypad_send_key("CardIn\n", 7);
1774 static void smartcard_remove(int dummy) {
1775 printk(KERN_INFO "Panel: smart card removed : %02x%02x%02x%02x%1x\n",
1776 smartcard_data[2], smartcard_data[3], smartcard_data[4],
1777 smartcard_data[5], smartcard_data[6] >> 4);
1778 memset(smartcard_data, 0, sizeof(smartcard_data));
1779 keypad_send_key("CardOut\n", 8);
1783 * These are the file operation function for user access to /dev/smartcard
1786 static ssize_t smartcard_read(struct file * file,
1787 char * buf, size_t count, loff_t *ppos ) {
1792 for( ; count-- > 0 && (smartcard_ptr < 9); ++i, ++tmp, ++smartcard_ptr ) {
1793 if (smartcard_ptr & 1)
1794 put_user( '0' + (smartcard_data[2 + (smartcard_ptr >> 1)] & 0xF), tmp );
1796 put_user( '0' + (smartcard_data[2 + (smartcard_ptr >> 1)] >> 4), tmp );
1800 return( tmp - buf );
1804 static int smartcard_open( struct inode *inode, struct file *file ) {
1806 if (smartcard_open_cnt)
1807 return( -EBUSY ); /* open only once at a time */
1809 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1812 smartcard_ptr = 0; /* flush the buffer on opening */
1813 smartcard_open_cnt++;
1817 static int smartcard_release( struct inode *inode, struct file *file ) {
1818 smartcard_open_cnt--;
1822 static struct file_operations smartcard_fops = {
1823 read: smartcard_read, /* read */
1824 open: smartcard_open, /* open */
1825 release: smartcard_release, /* close */
1828 static struct miscdevice smartcard_dev = {
1834 static void init_scan_timer(void) {
1835 if (scan_timer.function != NULL)
1836 return; /* already started */
1838 init_timer(&scan_timer);
1839 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1840 scan_timer.data = 0;
1841 scan_timer.function = (void *)&panel_scan_timer;
1842 add_timer(&scan_timer);
1845 /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
1846 * if <omask> or <imask> are non-null, they will be or'ed with the bits corresponding
1847 * to out and in bits respectively.
1848 * returns 1 if ok, 0 if error (in which case, nothing is written).
1850 static int input_name2mask(char *name, pmask_t *mask, pmask_t *value, char *imask, char *omask) {
1851 static char sigtab[10]="EeSsPpAaBb";
1855 om = im = m = v = 0ULL;
1857 int in, out, bit, neg;
1858 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name); in++);
1859 if (in >= sizeof(sigtab))
1860 return 0; /* input name not found */
1861 neg = (in & 1); /* odd (lower) names are negated */
1866 if (isdigit(*name)) {
1870 else if (*name == '-')
1873 return 0; /* unknown bit name */
1875 bit = (out * 5) + in;
1891 /* tries to bind a key to the signal name <name>. The key will send the
1892 * strings <press>, <repeat>, <release> for these respective events.
1893 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
1895 static struct logical_input *panel_bind_key(char *name, char *press, char *repeat, char *release) {
1896 struct logical_input *key;
1898 key = (struct logical_input*)kmalloc(sizeof(struct logical_input), GFP_KERNEL);
1900 printk(KERN_ERR "panel: not enough memory\n");
1903 memset(key, 0, sizeof(struct logical_input));
1904 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i, &scan_mask_o))
1906 key->type = INPUT_TYPE_KBD;
1907 key->state = INPUT_ST_LOW;
1912 printk(KERN_DEBUG "bind: <%s> : m=%016Lx v=%016Lx\n", name, key->mask, key->value);
1914 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1915 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1916 strncpy(key->u.kbd.release_str, release, sizeof(key->u.kbd.release_str));
1917 list_add(&key->list, &logical_inputs);
1921 /* tries to bind a callback function to the signal name <name>. The function
1922 * <press_fct> will be called with the <press_data> arg when the signal is
1923 * activated, and so on for <release_fct>/<release_data>
1924 * Returns the pointer to the new signal if ok, NULL if the signal could not be bound.
1926 static struct logical_input *panel_bind_callback(char *name,
1927 void (*press_fct)(int), int press_data,
1928 void (*release_fct)(int), int release_data) {
1929 struct logical_input *callback;
1931 callback = (struct logical_input*)kmalloc(sizeof(struct logical_input), GFP_KERNEL);
1933 printk(KERN_ERR "panel: not enough memory\n");
1936 memset(callback, 0, sizeof(struct logical_input));
1937 if (!input_name2mask(name, &callback->mask, &callback->value, &scan_mask_i, &scan_mask_o))
1939 callback->type = INPUT_TYPE_STD;
1940 callback->state = INPUT_ST_LOW;
1941 callback->rise_time = 1;
1942 callback->fall_time = 1;
1943 callback->u.std.press_fct = press_fct;
1944 callback->u.std.press_data = press_data;
1945 callback->u.std.release_fct = release_fct;
1946 callback->u.std.release_data = release_data;
1947 list_add(&callback->list, &logical_inputs);
1951 static void keypad_init(void) {
1953 init_waitqueue_head(&keypad_read_wait);
1954 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
1956 /* Let's create all known keys */
1958 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
1959 panel_bind_key(keypad_profile[keynum][0],
1960 keypad_profile[keynum][1],
1961 keypad_profile[keynum][2],
1962 keypad_profile[keynum][3]);
1966 keypad_initialized = 1;
1970 static void smartcard_init(void) {
1971 init_waitqueue_head(&smartcard_read_wait);
1973 panel_bind_callback(SMARTCARD_LOGICAL_DETECTOR, &smartcard_insert, 0, &smartcard_remove, 0);
1975 smartcard_enabled = 1;
1979 /**************************************************/
1980 /* device initialization */
1981 /**************************************************/
1983 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1984 #define INIT_FUNC static int __init panel_init_module
1985 #define CLEANUP_FUNC static void __exit panel_cleanup_module
1986 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1987 #define INIT_FUNC static int __init panel_init_module
1988 #define CLEANUP_FUNC static void panel_cleanup_module
1990 #define INIT_FUNC int init_module
1991 #define CLEANUP_FUNC int cleanup_module
1995 /* called when compiled into the kernel */
1996 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1997 static int __init panel_setup(char *str)
1999 __initfunc(void panel_setup(char *str, int *ints))
2004 int helpdisplayed = 0;
2012 /* let's parse each of the command line parameters of the following form :
2013 panel=[parport:x],[lcd_height:x],[lcd_width:x],[lcd_bwidth:x],[lcd_hwidth:x]
2015 if (!strncmp(str, "parport:", 8)) {
2019 else if (!strncmp(str, "disabled", 8)) {
2022 else if (!strncmp(str, "lcd_height:", 11)) {
2024 where = &lcd_height;
2026 else if (!strncmp(str, "lcd_width:", 10)) {
2030 else if (!strncmp(str, "lcd_bwidth:", 11)) {
2032 where = &lcd_bwidth;
2034 else if (!strncmp(str, "lcd_hwidth:", 11)) {
2036 where = &lcd_hwidth;
2038 else if (!strncmp(str, "lcd_enabled:", 12)) {
2040 where = &lcd_enabled;
2042 else if (!strncmp(str, "keypad_enabled:", 15)) {
2044 where = &keypad_enabled;
2046 else if (!strncmp(str, "smartcard_enabled:", 18)) {
2048 where = &smartcard_enabled;
2050 else if (!strncmp(str, "profile:", 8)) {
2054 else if (!helpdisplayed) {
2056 printk(KERN_ERR "Panel version " PANEL_VERSION ": invalid argument. Known arguments are :\n"
2057 " parport:, lcd_{height,width,bwidth,enabled}:, keypad_enabled:\n");
2060 /* see if we need to read a number */
2061 if (where != NULL) {
2063 while (isdigit(*str)) {
2064 dummy = (dummy*10) + (*str - '0');
2070 /* look for next arg */
2071 while (*str && (*str != ','))
2079 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2080 __setup("panel=", panel_setup );
2082 __setup("panel", panel_setup );
2085 #endif /* !MODULE */
2087 static int panel_notify_sys(struct notifier_block *this, unsigned long code, void *unused) {
2088 if (lcd_enabled && lcd_initialized) {
2091 panel_lcd_print("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2094 panel_lcd_print("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2097 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2106 static struct notifier_block panel_notifier = {
2113 static void panel_attach (struct parport *port)
2115 if (port->number != parport)
2119 printk(KERN_ERR "panel_attach(): port->number=%d parport=%d, already registered !\n", port->number, parport);
2123 pprt = parport_register_device(port, "panel",
2124 NULL, NULL, /* pf, kf */
2126 /*PARPORT_DEV_EXCL*/
2130 if (parport_claim(pprt)) {
2131 printk(KERN_ERR "Panel: could not claim access to parport%d. Aborting.\n", parport);
2132 //parport_unregister_device(pprt);
2133 //parport_unregister_driver(&panel_driver);
2139 // port->ops->disable_irq(port);
2141 /* must init LCD first, just in case an IRQ from the keypad is generated at keypad init */
2144 misc_register( &lcd_dev );
2147 if (keypad_enabled) {
2149 misc_register( &keypad_dev );
2152 if (smartcard_enabled) {
2154 misc_register( &smartcard_dev );
2158 static void panel_detach (struct parport *port)
2160 if (port->number != parport)
2164 printk(KERN_ERR "panel_detach(): port->number=%d parport=%d, nothing to unregister.\n",
2165 port->number, parport);
2169 if (smartcard_enabled && smartcard_initialized) {
2170 misc_deregister( &smartcard_dev );
2173 if (keypad_enabled && keypad_initialized) {
2174 misc_deregister( &keypad_dev );
2177 if (lcd_enabled && lcd_initialized) {
2178 misc_deregister( &lcd_dev );
2181 parport_release(pprt);
2182 parport_unregister_device(pprt);
2186 static struct parport_driver panel_driver = {
2188 .attach = panel_attach,
2189 .detach = panel_detach,
2193 int panel_init (void) {
2194 /* for backwards compatibility */
2195 if (keypad_type < 0)
2196 keypad_type = keypad_enabled;
2199 lcd_type = lcd_enabled;
2202 parport = DEFAULT_PARPORT;
2204 /* take care of an eventual profile */
2206 case PANEL_PROFILE_CUSTOM: /* custom profile */
2207 if (keypad_type < 0) keypad_type = DEFAULT_KEYPAD;
2208 if (smartcard_enabled < 0) smartcard_enabled = DEFAULT_SMARTCARD;
2209 if (lcd_type < 0) lcd_type = DEFAULT_LCD;
2211 case PANEL_PROFILE_OLD: /* 8 bits, 2*16, old keypad */
2212 if (keypad_type < 0) keypad_type = KEYPAD_TYPE_OLD;
2213 if (smartcard_enabled < 0) smartcard_enabled = 0;
2214 if (lcd_type < 0) lcd_type = LCD_TYPE_OLD;
2215 if (lcd_width < 0) lcd_width = 16;
2216 if (lcd_hwidth < 0) lcd_hwidth = 16;
2218 case PANEL_PROFILE_NEW: /* serial, 2*16, new keypad */
2219 if (keypad_type < 0) keypad_type = KEYPAD_TYPE_NEW;
2220 if (smartcard_enabled < 0) smartcard_enabled = 1;
2221 if (lcd_type < 0) lcd_type = LCD_TYPE_KS0074;
2223 case PANEL_PROFILE_HANTRONIX: /* 8 bits, 2*16 hantronix-like, no keypad */
2224 if (keypad_type < 0) keypad_type = KEYPAD_TYPE_NONE;
2225 if (smartcard_enabled < 0) smartcard_enabled = 0;
2226 if (lcd_type < 0) lcd_type = LCD_TYPE_HANTRONIX;
2228 case PANEL_PROFILE_NEXCOM: /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2229 if (keypad_type < 0) keypad_type = KEYPAD_TYPE_NEXCOM;
2230 if (smartcard_enabled < 0) smartcard_enabled = 0;
2231 if (lcd_type < 0) lcd_type = LCD_TYPE_NEXCOM;
2233 case PANEL_PROFILE_LARGE: /* 8 bits, 2*40, old keypad */
2234 if (keypad_type < 0) keypad_type = KEYPAD_TYPE_OLD;
2235 if (smartcard_enabled < 0) smartcard_enabled = 0;
2236 if (lcd_type < 0) lcd_type = LCD_TYPE_OLD;
2240 lcd_enabled = (lcd_type > 0);
2241 keypad_enabled = (keypad_type > 0);
2243 switch (keypad_type) {
2244 case KEYPAD_TYPE_OLD:
2245 keypad_profile = old_keypad_profile;
2247 case KEYPAD_TYPE_NEW:
2248 keypad_profile = new_keypad_profile;
2250 case KEYPAD_TYPE_NEXCOM:
2251 keypad_profile = nexcom_keypad_profile;
2254 keypad_profile = NULL;
2258 /* tells various subsystems about the fact that we are initializing */
2259 init_in_progress = 1;
2261 if (parport_register_driver(&panel_driver)) {
2262 printk(KERN_ERR "Panel: could not register with parport. Aborting.\n");
2266 // The parport can be asynchronously registered later.
2267 //if (pprt == NULL) {
2268 // printk(KERN_ERR "Panel: could not register parport%d. Aborting.\n", parport);
2269 // parport_unregister_driver(&panel_driver);
2270 // return -ENODEV; /* port not found */
2274 if (!lcd_enabled && !keypad_enabled && !smartcard_enabled) { /* no device enabled, let's release the parport */
2276 parport_release(pprt);
2277 parport_unregister_device(pprt);
2279 parport_unregister_driver(&panel_driver);
2280 printk(KERN_ERR "Panel driver version " PANEL_VERSION " disabled.\n");
2284 register_reboot_notifier(&panel_notifier);
2287 printk(KERN_INFO "Panel driver version " PANEL_VERSION " registered on parport%d (io=0x%lx).\n",
2288 parport, pprt->port->base);
2290 printk(KERN_INFO "Panel driver version " PANEL_VERSION " not yet registered\n");
2291 /* tells various subsystems about the fact that initialization is finished */
2292 init_in_progress = 0;
2297 #if defined(MODULE) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
2299 return panel_init();
2302 CLEANUP_FUNC (void) {
2303 unregister_reboot_notifier(&panel_notifier);
2305 if (scan_timer.function != NULL) {
2306 del_timer(&scan_timer);
2309 if (keypad_enabled) {
2310 misc_deregister( &keypad_dev );
2313 if (smartcard_enabled) {
2314 misc_deregister( &smartcard_dev );
2318 panel_lcd_print("\x0cLCD driver " PANEL_VERSION "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2319 misc_deregister( &lcd_dev );
2322 /* TODO: free all input signals */
2324 parport_release(pprt);
2325 parport_unregister_device(pprt);
2326 parport_unregister_driver(&panel_driver);
2330 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2331 module_init(panel_init_module);
2332 module_exit(panel_cleanup_module);
2333 MODULE_AUTHOR("Willy Tarreau");
2334 MODULE_LICENSE("GPL");