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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
39 #include <linux/module.h>
41 #include <linux/types.h>
42 #include <linux/errno.h>
43 #include <linux/signal.h>
44 #include <linux/sched.h>
45 #include <linux/spinlock.h>
46 #include <linux/interrupt.h>
47 #include <linux/miscdevice.h>
48 #include <linux/slab.h>
49 #include <linux/ioport.h>
50 #include <linux/fcntl.h>
51 #include <linux/init.h>
52 #include <linux/delay.h>
53 #include <linux/kernel.h>
54 #include <linux/ctype.h>
55 #include <linux/parport.h>
56 #include <linux/list.h>
57 #include <linux/notifier.h>
58 #include <linux/reboot.h>
59 #include <generated/utsrelease.h>
62 #include <linux/uaccess.h>
65 #define KEYPAD_MINOR 185
67 #define PANEL_VERSION "0.9.5"
69 #define LCD_MAXBYTES 256 /* max burst write */
71 #define KEYPAD_BUFFER 64
73 /* poll the keyboard this every second */
74 #define INPUT_POLL_TIME (HZ/50)
75 /* a key starts to repeat after this times INPUT_POLL_TIME */
76 #define KEYPAD_REP_START (10)
77 /* a key repeats this times INPUT_POLL_TIME */
78 #define KEYPAD_REP_DELAY (2)
80 /* keep the light on this times INPUT_POLL_TIME for each flash */
81 #define FLASH_LIGHT_TEMPO (200)
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 /* high to read data in or-ed with data out */
94 #define PNL_PINTEN 0x10
95 #define PNL_PSELECP 0x08 /* inverted output, active low */
96 #define PNL_PINITP 0x04 /* direct output, active low */
97 #define PNL_PAUTOLF 0x02 /* inverted output, active low */
98 #define PNL_PSTROBE 0x01 /* inverted output */
119 #define PIN_AUTOLF 14
121 #define PIN_SELECP 17
122 #define PIN_NOT_SET 127
124 #define LCD_FLAG_S 0x0001
125 #define LCD_FLAG_ID 0x0002
126 #define LCD_FLAG_B 0x0004 /* blink on */
127 #define LCD_FLAG_C 0x0008 /* cursor on */
128 #define LCD_FLAG_D 0x0010 /* display on */
129 #define LCD_FLAG_F 0x0020 /* large font mode */
130 #define LCD_FLAG_N 0x0040 /* 2-rows mode */
131 #define LCD_FLAG_L 0x0080 /* backlight enabled */
133 #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
134 #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
138 /* macros to simplify use of the parallel port */
139 #define r_ctr(x) (parport_read_control((x)->port))
140 #define r_dtr(x) (parport_read_data((x)->port))
141 #define r_str(x) (parport_read_status((x)->port))
142 #define w_ctr(x, y) (parport_write_control((x)->port, (y)))
143 #define w_dtr(x, y) (parport_write_data((x)->port, (y)))
145 /* this defines which bits are to be used and which ones to be ignored */
146 /* logical or of the output bits involved in the scan matrix */
147 static __u8 scan_mask_o
;
148 /* logical or of the input bits involved in the scan matrix */
149 static __u8 scan_mask_i
;
151 typedef __u64 pmask_t
;
165 struct logical_input
{
166 struct list_head list
;
169 enum input_type type
;
170 enum input_state state
;
171 __u8 rise_time
, fall_time
;
172 __u8 rise_timer
, fall_timer
, high_timer
;
175 struct { /* valid when type == INPUT_TYPE_STD */
176 void (*press_fct
)(int);
177 void (*release_fct
)(int);
181 struct { /* valid when type == INPUT_TYPE_KBD */
182 /* strings can be non null-terminated */
183 char press_str
[sizeof(void *) + sizeof(int)];
184 char repeat_str
[sizeof(void *) + sizeof(int)];
185 char release_str
[sizeof(void *) + sizeof(int)];
190 static LIST_HEAD(logical_inputs
); /* list of all defined logical inputs */
192 /* physical contacts history
193 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
194 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
195 * corresponds to the ground.
196 * Within each group, bits are stored in the same order as read on the port :
197 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
198 * So, each __u64 (or pmask_t) is represented like this :
199 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
200 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
203 /* what has just been read from the I/O ports */
204 static pmask_t phys_read
;
205 /* previous phys_read */
206 static pmask_t phys_read_prev
;
207 /* stabilized phys_read (phys_read|phys_read_prev) */
208 static pmask_t phys_curr
;
209 /* previous phys_curr */
210 static pmask_t phys_prev
;
211 /* 0 means that at least one logical signal needs be computed */
212 static char inputs_stable
;
214 /* these variables are specific to the keypad */
219 static char keypad_buffer
[KEYPAD_BUFFER
];
220 static int keypad_buflen
;
221 static int keypad_start
;
222 static char keypressed
;
223 static wait_queue_head_t keypad_read_wait
;
225 /* lcd-specific variables */
234 /* TODO: use union here? */
245 /* Needed only for init */
246 static int selected_lcd_type
= NOT_SET
;
248 /* contains the LCD config state */
249 static unsigned long int lcd_flags
;
250 /* contains the LCD X offset */
251 static unsigned long int lcd_addr_x
;
252 /* contains the LCD Y offset */
253 static unsigned long int lcd_addr_y
;
254 /* current escape sequence, 0 terminated */
255 static char lcd_escape
[LCD_ESCAPE_LEN
+ 1];
256 /* not in escape state. >=0 = escape cmd len */
257 static int lcd_escape_len
= -1;
260 * Bit masks to convert LCD signals to parallel port outputs.
261 * _d_ are values for data port, _c_ are for control port.
262 * [0] = signal OFF, [1] = signal ON, [2] = mask
269 * one entry for each bit on the LCD
280 * each bit can be either connected to a DATA or CTRL port
286 static unsigned char lcd_bits
[LCD_PORTS
][LCD_BITS
][BIT_STATES
];
291 #define LCD_PROTO_PARALLEL 0
292 #define LCD_PROTO_SERIAL 1
293 #define LCD_PROTO_TI_DA8XX_LCD 2
298 #define LCD_CHARSET_NORMAL 0
299 #define LCD_CHARSET_KS0074 1
304 #define LCD_TYPE_NONE 0
305 #define LCD_TYPE_OLD 1
306 #define LCD_TYPE_KS0074 2
307 #define LCD_TYPE_HANTRONIX 3
308 #define LCD_TYPE_NEXCOM 4
309 #define LCD_TYPE_CUSTOM 5
314 #define KEYPAD_TYPE_NONE 0
315 #define KEYPAD_TYPE_OLD 1
316 #define KEYPAD_TYPE_NEW 2
317 #define KEYPAD_TYPE_NEXCOM 3
322 #define PANEL_PROFILE_CUSTOM 0
323 #define PANEL_PROFILE_OLD 1
324 #define PANEL_PROFILE_NEW 2
325 #define PANEL_PROFILE_HANTRONIX 3
326 #define PANEL_PROFILE_NEXCOM 4
327 #define PANEL_PROFILE_LARGE 5
330 * Construct custom config from the kernel's configuration
332 #define DEFAULT_PARPORT 0
333 #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
334 #define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
335 #define DEFAULT_LCD_TYPE LCD_TYPE_OLD
336 #define DEFAULT_LCD_HEIGHT 2
337 #define DEFAULT_LCD_WIDTH 40
338 #define DEFAULT_LCD_BWIDTH 40
339 #define DEFAULT_LCD_HWIDTH 64
340 #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
341 #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
343 #define DEFAULT_LCD_PIN_E PIN_AUTOLF
344 #define DEFAULT_LCD_PIN_RS PIN_SELECP
345 #define DEFAULT_LCD_PIN_RW PIN_INITP
346 #define DEFAULT_LCD_PIN_SCL PIN_STROBE
347 #define DEFAULT_LCD_PIN_SDA PIN_D0
348 #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
350 #ifdef CONFIG_PANEL_PARPORT
351 #undef DEFAULT_PARPORT
352 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
355 #ifdef CONFIG_PANEL_PROFILE
356 #undef DEFAULT_PROFILE
357 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
360 #if DEFAULT_PROFILE == 0 /* custom */
361 #ifdef CONFIG_PANEL_KEYPAD
362 #undef DEFAULT_KEYPAD_TYPE
363 #define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
366 #ifdef CONFIG_PANEL_LCD
367 #undef DEFAULT_LCD_TYPE
368 #define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
371 #ifdef CONFIG_PANEL_LCD_HEIGHT
372 #undef DEFAULT_LCD_HEIGHT
373 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
376 #ifdef CONFIG_PANEL_LCD_WIDTH
377 #undef DEFAULT_LCD_WIDTH
378 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
381 #ifdef CONFIG_PANEL_LCD_BWIDTH
382 #undef DEFAULT_LCD_BWIDTH
383 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
386 #ifdef CONFIG_PANEL_LCD_HWIDTH
387 #undef DEFAULT_LCD_HWIDTH
388 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
391 #ifdef CONFIG_PANEL_LCD_CHARSET
392 #undef DEFAULT_LCD_CHARSET
393 #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
396 #ifdef CONFIG_PANEL_LCD_PROTO
397 #undef DEFAULT_LCD_PROTO
398 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
401 #ifdef CONFIG_PANEL_LCD_PIN_E
402 #undef DEFAULT_LCD_PIN_E
403 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
406 #ifdef CONFIG_PANEL_LCD_PIN_RS
407 #undef DEFAULT_LCD_PIN_RS
408 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
411 #ifdef CONFIG_PANEL_LCD_PIN_RW
412 #undef DEFAULT_LCD_PIN_RW
413 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
416 #ifdef CONFIG_PANEL_LCD_PIN_SCL
417 #undef DEFAULT_LCD_PIN_SCL
418 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
421 #ifdef CONFIG_PANEL_LCD_PIN_SDA
422 #undef DEFAULT_LCD_PIN_SDA
423 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
426 #ifdef CONFIG_PANEL_LCD_PIN_BL
427 #undef DEFAULT_LCD_PIN_BL
428 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
431 #endif /* DEFAULT_PROFILE == 0 */
433 /* global variables */
435 /* Device single-open policy control */
436 static atomic_t lcd_available
= ATOMIC_INIT(1);
437 static atomic_t keypad_available
= ATOMIC_INIT(1);
439 static struct pardevice
*pprt
;
441 static int lcd_initialized
;
442 static int keypad_initialized
;
444 static int light_tempo
;
446 static char lcd_must_clear
;
447 static char lcd_left_shift
;
448 static char init_in_progress
;
450 static void (*lcd_write_cmd
)(int);
451 static void (*lcd_write_data
)(int);
452 static void (*lcd_clear_fast
)(void);
454 static DEFINE_SPINLOCK(pprt_lock
);
455 static struct timer_list scan_timer
;
457 MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
459 static int parport
= DEFAULT_PARPORT
;
460 module_param(parport
, int, 0000);
461 MODULE_PARM_DESC(parport
, "Parallel port index (0=lpt1, 1=lpt2, ...)");
463 static int profile
= DEFAULT_PROFILE
;
464 module_param(profile
, int, 0000);
465 MODULE_PARM_DESC(profile
,
466 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
467 "4=16x2 nexcom; default=40x2, old kp");
469 static int keypad_type
= NOT_SET
;
470 module_param(keypad_type
, int, 0000);
471 MODULE_PARM_DESC(keypad_type
,
472 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
474 static int lcd_type
= NOT_SET
;
475 module_param(lcd_type
, int, 0000);
476 MODULE_PARM_DESC(lcd_type
,
477 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
479 static int lcd_height
= NOT_SET
;
480 module_param(lcd_height
, int, 0000);
481 MODULE_PARM_DESC(lcd_height
, "Number of lines on the LCD");
483 static int lcd_width
= NOT_SET
;
484 module_param(lcd_width
, int, 0000);
485 MODULE_PARM_DESC(lcd_width
, "Number of columns on the LCD");
487 static int lcd_bwidth
= NOT_SET
; /* internal buffer width (usually 40) */
488 module_param(lcd_bwidth
, int, 0000);
489 MODULE_PARM_DESC(lcd_bwidth
, "Internal LCD line width (40)");
491 static int lcd_hwidth
= NOT_SET
; /* hardware buffer width (usually 64) */
492 module_param(lcd_hwidth
, int, 0000);
493 MODULE_PARM_DESC(lcd_hwidth
, "LCD line hardware address (64)");
495 static int lcd_charset
= NOT_SET
;
496 module_param(lcd_charset
, int, 0000);
497 MODULE_PARM_DESC(lcd_charset
, "LCD character set: 0=standard, 1=KS0074");
499 static int lcd_proto
= NOT_SET
;
500 module_param(lcd_proto
, int, 0000);
501 MODULE_PARM_DESC(lcd_proto
,
502 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
505 * These are the parallel port pins the LCD control signals are connected to.
506 * Set this to 0 if the signal is not used. Set it to its opposite value
507 * (negative) if the signal is negated. -MAXINT is used to indicate that the
508 * pin has not been explicitly specified.
510 * WARNING! no check will be performed about collisions with keypad !
513 static int lcd_e_pin
= PIN_NOT_SET
;
514 module_param(lcd_e_pin
, int, 0000);
515 MODULE_PARM_DESC(lcd_e_pin
,
516 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
518 static int lcd_rs_pin
= PIN_NOT_SET
;
519 module_param(lcd_rs_pin
, int, 0000);
520 MODULE_PARM_DESC(lcd_rs_pin
,
521 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
523 static int lcd_rw_pin
= PIN_NOT_SET
;
524 module_param(lcd_rw_pin
, int, 0000);
525 MODULE_PARM_DESC(lcd_rw_pin
,
526 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
528 static int lcd_cl_pin
= PIN_NOT_SET
;
529 module_param(lcd_cl_pin
, int, 0000);
530 MODULE_PARM_DESC(lcd_cl_pin
,
531 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
533 static int lcd_da_pin
= PIN_NOT_SET
;
534 module_param(lcd_da_pin
, int, 0000);
535 MODULE_PARM_DESC(lcd_da_pin
,
536 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
538 static int lcd_bl_pin
= PIN_NOT_SET
;
539 module_param(lcd_bl_pin
, int, 0000);
540 MODULE_PARM_DESC(lcd_bl_pin
,
541 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
543 /* Deprecated module parameters - consider not using them anymore */
545 static int lcd_enabled
= NOT_SET
;
546 module_param(lcd_enabled
, int, 0000);
547 MODULE_PARM_DESC(lcd_enabled
, "Deprecated option, use lcd_type instead");
549 static int keypad_enabled
= NOT_SET
;
550 module_param(keypad_enabled
, int, 0000);
551 MODULE_PARM_DESC(keypad_enabled
, "Deprecated option, use keypad_type instead");
554 static const unsigned char *lcd_char_conv
;
556 /* for some LCD drivers (ks0074) we need a charset conversion table. */
557 static const unsigned char lcd_char_conv_ks0074
[256] = {
558 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
559 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
560 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
561 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
562 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
563 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
564 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
565 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
566 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
567 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
568 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
569 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
570 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
571 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
572 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
573 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
574 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
575 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
576 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
577 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
578 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
579 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
580 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
581 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
582 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
583 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
584 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
585 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
586 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
587 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
588 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
589 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
590 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
593 static const char old_keypad_profile
[][4][9] = {
594 {"S0", "Left\n", "Left\n", ""},
595 {"S1", "Down\n", "Down\n", ""},
596 {"S2", "Up\n", "Up\n", ""},
597 {"S3", "Right\n", "Right\n", ""},
598 {"S4", "Esc\n", "Esc\n", ""},
599 {"S5", "Ret\n", "Ret\n", ""},
603 /* signals, press, repeat, release */
604 static const char new_keypad_profile
[][4][9] = {
605 {"S0", "Left\n", "Left\n", ""},
606 {"S1", "Down\n", "Down\n", ""},
607 {"S2", "Up\n", "Up\n", ""},
608 {"S3", "Right\n", "Right\n", ""},
609 {"S4s5", "", "Esc\n", "Esc\n"},
610 {"s4S5", "", "Ret\n", "Ret\n"},
611 {"S4S5", "Help\n", "", ""},
612 /* add new signals above this line */
616 /* signals, press, repeat, release */
617 static const char nexcom_keypad_profile
[][4][9] = {
618 {"a-p-e-", "Down\n", "Down\n", ""},
619 {"a-p-E-", "Ret\n", "Ret\n", ""},
620 {"a-P-E-", "Esc\n", "Esc\n", ""},
621 {"a-P-e-", "Up\n", "Up\n", ""},
622 /* add new signals above this line */
626 static const char (*keypad_profile
)[4][9] = old_keypad_profile
;
628 /* FIXME: this should be converted to a bit array containing signals states */
630 unsigned char e
; /* parallel LCD E (data latch on falling edge) */
631 unsigned char rs
; /* parallel LCD RS (0 = cmd, 1 = data) */
632 unsigned char rw
; /* parallel LCD R/W (0 = W, 1 = R) */
633 unsigned char bl
; /* parallel LCD backlight (0 = off, 1 = on) */
634 unsigned char cl
; /* serial LCD clock (latch on rising edge) */
635 unsigned char da
; /* serial LCD data */
638 static void init_scan_timer(void);
640 /* sets data port bits according to current signals values */
641 static int set_data_bits(void)
646 for (bit
= 0; bit
< LCD_BITS
; bit
++)
647 val
&= lcd_bits
[LCD_PORT_D
][bit
][BIT_MSK
];
649 val
|= lcd_bits
[LCD_PORT_D
][LCD_BIT_E
][bits
.e
]
650 | lcd_bits
[LCD_PORT_D
][LCD_BIT_RS
][bits
.rs
]
651 | lcd_bits
[LCD_PORT_D
][LCD_BIT_RW
][bits
.rw
]
652 | lcd_bits
[LCD_PORT_D
][LCD_BIT_BL
][bits
.bl
]
653 | lcd_bits
[LCD_PORT_D
][LCD_BIT_CL
][bits
.cl
]
654 | lcd_bits
[LCD_PORT_D
][LCD_BIT_DA
][bits
.da
];
660 /* sets ctrl port bits according to current signals values */
661 static int set_ctrl_bits(void)
666 for (bit
= 0; bit
< LCD_BITS
; bit
++)
667 val
&= lcd_bits
[LCD_PORT_C
][bit
][BIT_MSK
];
669 val
|= lcd_bits
[LCD_PORT_C
][LCD_BIT_E
][bits
.e
]
670 | lcd_bits
[LCD_PORT_C
][LCD_BIT_RS
][bits
.rs
]
671 | lcd_bits
[LCD_PORT_C
][LCD_BIT_RW
][bits
.rw
]
672 | lcd_bits
[LCD_PORT_C
][LCD_BIT_BL
][bits
.bl
]
673 | lcd_bits
[LCD_PORT_C
][LCD_BIT_CL
][bits
.cl
]
674 | lcd_bits
[LCD_PORT_C
][LCD_BIT_DA
][bits
.da
];
680 /* sets ctrl & data port bits according to current signals values */
681 static void panel_set_bits(void)
688 * Converts a parallel port pin (from -25 to 25) to data and control ports
689 * masks, and data and control port bits. The signal will be considered
690 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
692 * Result will be used this way :
693 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
694 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
696 static void pin_to_bits(int pin
, unsigned char *d_val
, unsigned char *c_val
)
698 int d_bit
, c_bit
, inv
;
718 case PIN_STROBE
: /* strobe, inverted */
722 case PIN_D0
...PIN_D7
: /* D0 - D7 = 2 - 9 */
723 d_bit
= 1 << (pin
- 2);
725 case PIN_AUTOLF
: /* autofeed, inverted */
729 case PIN_INITP
: /* init, direct */
732 case PIN_SELECP
: /* select_in, inverted */
736 default: /* unknown pin, ignore */
749 /* sleeps that many milliseconds with a reschedule */
750 static void long_sleep(int ms
)
752 if (in_interrupt()) {
755 current
->state
= TASK_INTERRUPTIBLE
;
756 schedule_timeout((ms
* HZ
+ 999) / 1000);
760 /* send a serial byte to the LCD panel. The caller is responsible for locking
762 static void lcd_send_serial(int byte
)
766 /* the data bit is set on D0, and the clock on STROBE.
767 * LCD reads D0 on STROBE's rising edge. */
768 for (bit
= 0; bit
< 8; bit
++) {
769 bits
.cl
= BIT_CLR
; /* CLK low */
773 udelay(2); /* maintain the data during 2 us before CLK up */
774 bits
.cl
= BIT_SET
; /* CLK high */
776 udelay(1); /* maintain the strobe during 1 us */
781 /* turn the backlight on or off */
782 static void lcd_backlight(int on
)
784 if (lcd
.pins
.bl
== PIN_NONE
)
787 /* The backlight is activated by setting the AUTOFEED line to +5V */
788 spin_lock_irq(&pprt_lock
);
791 spin_unlock_irq(&pprt_lock
);
794 /* send a command to the LCD panel in serial mode */
795 static void lcd_write_cmd_s(int cmd
)
797 spin_lock_irq(&pprt_lock
);
798 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
799 lcd_send_serial(cmd
& 0x0F);
800 lcd_send_serial((cmd
>> 4) & 0x0F);
801 udelay(40); /* the shortest command takes at least 40 us */
802 spin_unlock_irq(&pprt_lock
);
805 /* send data to the LCD panel in serial mode */
806 static void lcd_write_data_s(int data
)
808 spin_lock_irq(&pprt_lock
);
809 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
810 lcd_send_serial(data
& 0x0F);
811 lcd_send_serial((data
>> 4) & 0x0F);
812 udelay(40); /* the shortest data takes at least 40 us */
813 spin_unlock_irq(&pprt_lock
);
816 /* send a command to the LCD panel in 8 bits parallel mode */
817 static void lcd_write_cmd_p8(int cmd
)
819 spin_lock_irq(&pprt_lock
);
820 /* present the data to the data port */
822 udelay(20); /* maintain the data during 20 us before the strobe */
829 udelay(40); /* maintain the strobe during 40 us */
834 udelay(120); /* the shortest command takes at least 120 us */
835 spin_unlock_irq(&pprt_lock
);
838 /* send data to the LCD panel in 8 bits parallel mode */
839 static void lcd_write_data_p8(int data
)
841 spin_lock_irq(&pprt_lock
);
842 /* present the data to the data port */
844 udelay(20); /* maintain the data during 20 us before the strobe */
851 udelay(40); /* maintain the strobe during 40 us */
856 udelay(45); /* the shortest data takes at least 45 us */
857 spin_unlock_irq(&pprt_lock
);
860 /* send a command to the TI LCD panel */
861 static void lcd_write_cmd_tilcd(int cmd
)
863 spin_lock_irq(&pprt_lock
);
864 /* present the data to the control port */
867 spin_unlock_irq(&pprt_lock
);
870 /* send data to the TI LCD panel */
871 static void lcd_write_data_tilcd(int data
)
873 spin_lock_irq(&pprt_lock
);
874 /* present the data to the data port */
877 spin_unlock_irq(&pprt_lock
);
880 static void lcd_gotoxy(void)
882 lcd_write_cmd(0x80 /* set DDRAM address */
883 | (lcd_addr_y
? lcd
.hwidth
: 0)
884 /* we force the cursor to stay at the end of the
885 line if it wants to go farther */
886 | ((lcd_addr_x
< lcd
.bwidth
) ? lcd_addr_x
&
887 (lcd
.hwidth
- 1) : lcd
.bwidth
- 1));
890 static void lcd_print(char c
)
892 if (lcd_addr_x
< lcd
.bwidth
) {
893 if (lcd_char_conv
!= NULL
)
894 c
= lcd_char_conv
[(unsigned char)c
];
898 /* prevents the cursor from wrapping onto the next line */
899 if (lcd_addr_x
== lcd
.bwidth
)
903 /* fills the display with spaces and resets X/Y */
904 static void lcd_clear_fast_s(void)
912 spin_lock_irq(&pprt_lock
);
913 for (pos
= 0; pos
< lcd
.height
* lcd
.hwidth
; pos
++) {
914 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
915 lcd_send_serial(' ' & 0x0F);
916 lcd_send_serial((' ' >> 4) & 0x0F);
917 udelay(40); /* the shortest data takes at least 40 us */
919 spin_unlock_irq(&pprt_lock
);
926 /* fills the display with spaces and resets X/Y */
927 static void lcd_clear_fast_p8(void)
935 spin_lock_irq(&pprt_lock
);
936 for (pos
= 0; pos
< lcd
.height
* lcd
.hwidth
; pos
++) {
937 /* present the data to the data port */
940 /* maintain the data during 20 us before the strobe */
948 /* maintain the strobe during 40 us */
954 /* the shortest data takes at least 45 us */
957 spin_unlock_irq(&pprt_lock
);
964 /* fills the display with spaces and resets X/Y */
965 static void lcd_clear_fast_tilcd(void)
973 spin_lock_irq(&pprt_lock
);
974 for (pos
= 0; pos
< lcd
.height
* lcd
.hwidth
; pos
++) {
975 /* present the data to the data port */
980 spin_unlock_irq(&pprt_lock
);
987 /* clears the display and resets X/Y */
988 static void lcd_clear_display(void)
990 lcd_write_cmd(0x01); /* clear display */
993 /* we must wait a few milliseconds (15) */
997 static void lcd_init_display(void)
999 lcd_flags
= ((lcd
.height
> 1) ? LCD_FLAG_N
: 0)
1000 | LCD_FLAG_D
| LCD_FLAG_C
| LCD_FLAG_B
;
1002 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
1004 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1006 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1008 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1011 lcd_write_cmd(0x30 /* set font height and lines number */
1012 | ((lcd_flags
& LCD_FLAG_F
) ? 4 : 0)
1013 | ((lcd_flags
& LCD_FLAG_N
) ? 8 : 0)
1017 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
1020 lcd_write_cmd(0x08 /* set display mode */
1021 | ((lcd_flags
& LCD_FLAG_D
) ? 4 : 0)
1022 | ((lcd_flags
& LCD_FLAG_C
) ? 2 : 0)
1023 | ((lcd_flags
& LCD_FLAG_B
) ? 1 : 0)
1026 lcd_backlight((lcd_flags
& LCD_FLAG_L
) ? 1 : 0);
1030 /* entry mode set : increment, cursor shifting */
1031 lcd_write_cmd(0x06);
1033 lcd_clear_display();
1037 * These are the file operation function for user access to /dev/lcd
1038 * This function can also be called from inside the kernel, by
1039 * setting file and ppos to NULL.
1043 static inline int handle_lcd_special_code(void)
1045 /* LCD special codes */
1049 char *esc
= lcd_escape
+ 2;
1050 int oldflags
= lcd_flags
;
1052 /* check for display mode flags */
1054 case 'D': /* Display ON */
1055 lcd_flags
|= LCD_FLAG_D
;
1058 case 'd': /* Display OFF */
1059 lcd_flags
&= ~LCD_FLAG_D
;
1062 case 'C': /* Cursor ON */
1063 lcd_flags
|= LCD_FLAG_C
;
1066 case 'c': /* Cursor OFF */
1067 lcd_flags
&= ~LCD_FLAG_C
;
1070 case 'B': /* Blink ON */
1071 lcd_flags
|= LCD_FLAG_B
;
1074 case 'b': /* Blink OFF */
1075 lcd_flags
&= ~LCD_FLAG_B
;
1078 case '+': /* Back light ON */
1079 lcd_flags
|= LCD_FLAG_L
;
1082 case '-': /* Back light OFF */
1083 lcd_flags
&= ~LCD_FLAG_L
;
1087 /* flash back light using the keypad timer */
1088 if (scan_timer
.function
!= NULL
) {
1089 if (light_tempo
== 0 && ((lcd_flags
& LCD_FLAG_L
) == 0))
1091 light_tempo
= FLASH_LIGHT_TEMPO
;
1095 case 'f': /* Small Font */
1096 lcd_flags
&= ~LCD_FLAG_F
;
1099 case 'F': /* Large Font */
1100 lcd_flags
|= LCD_FLAG_F
;
1103 case 'n': /* One Line */
1104 lcd_flags
&= ~LCD_FLAG_N
;
1107 case 'N': /* Two Lines */
1108 lcd_flags
|= LCD_FLAG_N
;
1110 case 'l': /* Shift Cursor Left */
1111 if (lcd_addr_x
> 0) {
1112 /* back one char if not at end of line */
1113 if (lcd_addr_x
< lcd
.bwidth
)
1114 lcd_write_cmd(0x10);
1119 case 'r': /* shift cursor right */
1120 if (lcd_addr_x
< lcd
.width
) {
1121 /* allow the cursor to pass the end of the line */
1124 lcd_write_cmd(0x14);
1129 case 'L': /* shift display left */
1131 lcd_write_cmd(0x18);
1134 case 'R': /* shift display right */
1136 lcd_write_cmd(0x1C);
1139 case 'k': { /* kill end of line */
1142 for (x
= lcd_addr_x
; x
< lcd
.bwidth
; x
++)
1143 lcd_write_data(' ');
1145 /* restore cursor position */
1150 case 'I': /* reinitialize display */
1156 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1157 * and '7', representing the numerical ASCII code of the
1158 * redefined character, and <xx...xx> a sequence of 16
1159 * hex digits representing 8 bytes for each character.
1160 * Most LCDs will only use 5 lower bits of the 7 first
1164 unsigned char cgbytes
[8];
1165 unsigned char cgaddr
;
1171 if (strchr(esc
, ';') == NULL
)
1176 cgaddr
= *(esc
++) - '0';
1185 while (*esc
&& cgoffset
< 8) {
1187 if (*esc
>= '0' && *esc
<= '9') {
1188 value
|= (*esc
- '0') << shift
;
1189 } else if (*esc
>= 'A' && *esc
<= 'Z') {
1190 value
|= (*esc
- 'A' + 10) << shift
;
1191 } else if (*esc
>= 'a' && *esc
<= 'z') {
1192 value
|= (*esc
- 'a' + 10) << shift
;
1199 cgbytes
[cgoffset
++] = value
;
1206 lcd_write_cmd(0x40 | (cgaddr
* 8));
1207 for (addr
= 0; addr
< cgoffset
; addr
++)
1208 lcd_write_data(cgbytes
[addr
]);
1210 /* ensures that we stop writing to CGRAM */
1215 case 'x': /* gotoxy : LxXXX[yYYY]; */
1216 case 'y': /* gotoxy : LyYYY[xXXX]; */
1217 if (strchr(esc
, ';') == NULL
)
1223 if (kstrtoul(esc
, 10, &lcd_addr_x
) < 0)
1225 } else if (*esc
== 'y') {
1227 if (kstrtoul(esc
, 10, &lcd_addr_y
) < 0)
1239 /* Check whether one flag was changed */
1240 if (oldflags
!= lcd_flags
) {
1241 /* check whether one of B,C,D flags were changed */
1242 if ((oldflags
^ lcd_flags
) &
1243 (LCD_FLAG_B
| LCD_FLAG_C
| LCD_FLAG_D
))
1244 /* set display mode */
1246 | ((lcd_flags
& LCD_FLAG_D
) ? 4 : 0)
1247 | ((lcd_flags
& LCD_FLAG_C
) ? 2 : 0)
1248 | ((lcd_flags
& LCD_FLAG_B
) ? 1 : 0));
1249 /* check whether one of F,N flags was changed */
1250 else if ((oldflags
^ lcd_flags
) & (LCD_FLAG_F
| LCD_FLAG_N
))
1252 | ((lcd_flags
& LCD_FLAG_F
) ? 4 : 0)
1253 | ((lcd_flags
& LCD_FLAG_N
) ? 8 : 0));
1254 /* check whether L flag was changed */
1255 else if ((oldflags
^ lcd_flags
) & (LCD_FLAG_L
)) {
1256 if (lcd_flags
& (LCD_FLAG_L
))
1258 else if (light_tempo
== 0)
1259 /* switch off the light only when the tempo
1268 static void lcd_write_char(char c
)
1270 /* first, we'll test if we're in escape mode */
1271 if ((c
!= '\n') && lcd_escape_len
>= 0) {
1272 /* yes, let's add this char to the buffer */
1273 lcd_escape
[lcd_escape_len
++] = c
;
1274 lcd_escape
[lcd_escape_len
] = 0;
1276 /* aborts any previous escape sequence */
1277 lcd_escape_len
= -1;
1280 case LCD_ESCAPE_CHAR
:
1281 /* start of an escape sequence */
1283 lcd_escape
[lcd_escape_len
] = 0;
1286 /* go back one char and clear it */
1287 if (lcd_addr_x
> 0) {
1288 /* check if we're not at the
1290 if (lcd_addr_x
< lcd
.bwidth
)
1292 lcd_write_cmd(0x10);
1295 /* replace with a space */
1296 lcd_write_data(' ');
1297 /* back one char again */
1298 lcd_write_cmd(0x10);
1301 /* quickly clear the display */
1305 /* flush the remainder of the current line and
1306 go to the beginning of the next line */
1307 for (; lcd_addr_x
< lcd
.bwidth
; lcd_addr_x
++)
1308 lcd_write_data(' ');
1310 lcd_addr_y
= (lcd_addr_y
+ 1) % lcd
.height
;
1314 /* go to the beginning of the same line */
1319 /* print a space instead of the tab */
1323 /* simply print this char */
1329 /* now we'll see if we're in an escape mode and if the current
1330 escape sequence can be understood. */
1331 if (lcd_escape_len
>= 2) {
1334 if (!strcmp(lcd_escape
, "[2J")) {
1335 /* clear the display */
1338 } else if (!strcmp(lcd_escape
, "[H")) {
1339 /* cursor to home */
1345 /* codes starting with ^[[L */
1346 else if ((lcd_escape_len
>= 3) &&
1347 (lcd_escape
[0] == '[') &&
1348 (lcd_escape
[1] == 'L')) {
1349 processed
= handle_lcd_special_code();
1352 /* LCD special escape codes */
1353 /* flush the escape sequence if it's been processed
1354 or if it is getting too long. */
1355 if (processed
|| (lcd_escape_len
>= LCD_ESCAPE_LEN
))
1356 lcd_escape_len
= -1;
1357 } /* escape codes */
1360 static ssize_t
lcd_write(struct file
*file
,
1361 const char __user
*buf
, size_t count
, loff_t
*ppos
)
1363 const char __user
*tmp
= buf
;
1366 for (; count
-- > 0; (*ppos
)++, tmp
++) {
1367 if (!in_interrupt() && (((count
+ 1) & 0x1f) == 0))
1368 /* let's be a little nice with other processes
1369 that need some CPU */
1372 if (get_user(c
, tmp
))
1381 static int lcd_open(struct inode
*inode
, struct file
*file
)
1383 if (!atomic_dec_and_test(&lcd_available
))
1384 return -EBUSY
; /* open only once at a time */
1386 if (file
->f_mode
& FMODE_READ
) /* device is write-only */
1389 if (lcd_must_clear
) {
1390 lcd_clear_display();
1393 return nonseekable_open(inode
, file
);
1396 static int lcd_release(struct inode
*inode
, struct file
*file
)
1398 atomic_inc(&lcd_available
);
1402 static const struct file_operations lcd_fops
= {
1405 .release
= lcd_release
,
1406 .llseek
= no_llseek
,
1409 static struct miscdevice lcd_dev
= {
1415 /* public function usable from the kernel for any purpose */
1416 static void panel_lcd_print(const char *s
)
1418 const char *tmp
= s
;
1419 int count
= strlen(s
);
1421 if (lcd
.enabled
&& lcd_initialized
) {
1422 for (; count
-- > 0; tmp
++) {
1423 if (!in_interrupt() && (((count
+ 1) & 0x1f) == 0))
1424 /* let's be a little nice with other processes
1425 that need some CPU */
1428 lcd_write_char(*tmp
);
1433 /* initialize the LCD driver */
1434 static void lcd_init(void)
1436 switch (selected_lcd_type
) {
1438 /* parallel mode, 8 bits */
1439 lcd
.proto
= LCD_PROTO_PARALLEL
;
1440 lcd
.charset
= LCD_CHARSET_NORMAL
;
1441 lcd
.pins
.e
= PIN_STROBE
;
1442 lcd
.pins
.rs
= PIN_AUTOLF
;
1449 case LCD_TYPE_KS0074
:
1450 /* serial mode, ks0074 */
1451 lcd
.proto
= LCD_PROTO_SERIAL
;
1452 lcd
.charset
= LCD_CHARSET_KS0074
;
1453 lcd
.pins
.bl
= PIN_AUTOLF
;
1454 lcd
.pins
.cl
= PIN_STROBE
;
1455 lcd
.pins
.da
= PIN_D0
;
1462 case LCD_TYPE_NEXCOM
:
1463 /* parallel mode, 8 bits, generic */
1464 lcd
.proto
= LCD_PROTO_PARALLEL
;
1465 lcd
.charset
= LCD_CHARSET_NORMAL
;
1466 lcd
.pins
.e
= PIN_AUTOLF
;
1467 lcd
.pins
.rs
= PIN_SELECP
;
1468 lcd
.pins
.rw
= PIN_INITP
;
1475 case LCD_TYPE_CUSTOM
:
1476 /* customer-defined */
1477 lcd
.proto
= DEFAULT_LCD_PROTO
;
1478 lcd
.charset
= DEFAULT_LCD_CHARSET
;
1479 /* default geometry will be set later */
1481 case LCD_TYPE_HANTRONIX
:
1482 /* parallel mode, 8 bits, hantronix-like */
1484 lcd
.proto
= LCD_PROTO_PARALLEL
;
1485 lcd
.charset
= LCD_CHARSET_NORMAL
;
1486 lcd
.pins
.e
= PIN_STROBE
;
1487 lcd
.pins
.rs
= PIN_SELECP
;
1496 /* Overwrite with module params set on loading */
1497 if (lcd_height
> -1)
1498 lcd
.height
= lcd_height
;
1500 lcd
.width
= lcd_width
;
1501 if (lcd_bwidth
> -1)
1502 lcd
.bwidth
= lcd_bwidth
;
1503 if (lcd_hwidth
> -1)
1504 lcd
.hwidth
= lcd_hwidth
;
1505 if (lcd_charset
> -1)
1506 lcd
.charset
= lcd_charset
;
1508 lcd
.proto
= lcd_proto
;
1509 if (lcd_e_pin
!= PIN_NOT_SET
)
1510 lcd
.pins
.e
= lcd_e_pin
;
1511 if (lcd_rs_pin
!= PIN_NOT_SET
)
1512 lcd
.pins
.rs
= lcd_rs_pin
;
1513 if (lcd_rw_pin
!= PIN_NOT_SET
)
1514 lcd
.pins
.rw
= lcd_rw_pin
;
1515 if (lcd_cl_pin
!= PIN_NOT_SET
)
1516 lcd
.pins
.cl
= lcd_cl_pin
;
1517 if (lcd_da_pin
!= PIN_NOT_SET
)
1518 lcd
.pins
.da
= lcd_da_pin
;
1519 if (lcd_bl_pin
!= PIN_NOT_SET
)
1520 lcd
.pins
.bl
= lcd_bl_pin
;
1522 /* this is used to catch wrong and default values */
1524 lcd
.width
= DEFAULT_LCD_WIDTH
;
1525 if (lcd
.bwidth
<= 0)
1526 lcd
.bwidth
= DEFAULT_LCD_BWIDTH
;
1527 if (lcd
.hwidth
<= 0)
1528 lcd
.hwidth
= DEFAULT_LCD_HWIDTH
;
1529 if (lcd
.height
<= 0)
1530 lcd
.height
= DEFAULT_LCD_HEIGHT
;
1532 if (lcd
.proto
== LCD_PROTO_SERIAL
) { /* SERIAL */
1533 lcd_write_cmd
= lcd_write_cmd_s
;
1534 lcd_write_data
= lcd_write_data_s
;
1535 lcd_clear_fast
= lcd_clear_fast_s
;
1537 if (lcd
.pins
.cl
== PIN_NOT_SET
)
1538 lcd
.pins
.cl
= DEFAULT_LCD_PIN_SCL
;
1539 if (lcd
.pins
.da
== PIN_NOT_SET
)
1540 lcd
.pins
.da
= DEFAULT_LCD_PIN_SDA
;
1542 } else if (lcd
.proto
== LCD_PROTO_PARALLEL
) { /* PARALLEL */
1543 lcd_write_cmd
= lcd_write_cmd_p8
;
1544 lcd_write_data
= lcd_write_data_p8
;
1545 lcd_clear_fast
= lcd_clear_fast_p8
;
1547 if (lcd
.pins
.e
== PIN_NOT_SET
)
1548 lcd
.pins
.e
= DEFAULT_LCD_PIN_E
;
1549 if (lcd
.pins
.rs
== PIN_NOT_SET
)
1550 lcd
.pins
.rs
= DEFAULT_LCD_PIN_RS
;
1551 if (lcd
.pins
.rw
== PIN_NOT_SET
)
1552 lcd
.pins
.rw
= DEFAULT_LCD_PIN_RW
;
1554 lcd_write_cmd
= lcd_write_cmd_tilcd
;
1555 lcd_write_data
= lcd_write_data_tilcd
;
1556 lcd_clear_fast
= lcd_clear_fast_tilcd
;
1559 if (lcd
.pins
.bl
== PIN_NOT_SET
)
1560 lcd
.pins
.bl
= DEFAULT_LCD_PIN_BL
;
1562 if (lcd
.pins
.e
== PIN_NOT_SET
)
1563 lcd
.pins
.e
= PIN_NONE
;
1564 if (lcd
.pins
.rs
== PIN_NOT_SET
)
1565 lcd
.pins
.rs
= PIN_NONE
;
1566 if (lcd
.pins
.rw
== PIN_NOT_SET
)
1567 lcd
.pins
.rw
= PIN_NONE
;
1568 if (lcd
.pins
.bl
== PIN_NOT_SET
)
1569 lcd
.pins
.bl
= PIN_NONE
;
1570 if (lcd
.pins
.cl
== PIN_NOT_SET
)
1571 lcd
.pins
.cl
= PIN_NONE
;
1572 if (lcd
.pins
.da
== PIN_NOT_SET
)
1573 lcd
.pins
.da
= PIN_NONE
;
1575 if (lcd
.charset
== NOT_SET
)
1576 lcd
.charset
= DEFAULT_LCD_CHARSET
;
1578 if (lcd
.charset
== LCD_CHARSET_KS0074
)
1579 lcd_char_conv
= lcd_char_conv_ks0074
;
1581 lcd_char_conv
= NULL
;
1583 if (lcd
.pins
.bl
!= PIN_NONE
)
1586 pin_to_bits(lcd
.pins
.e
, lcd_bits
[LCD_PORT_D
][LCD_BIT_E
],
1587 lcd_bits
[LCD_PORT_C
][LCD_BIT_E
]);
1588 pin_to_bits(lcd
.pins
.rs
, lcd_bits
[LCD_PORT_D
][LCD_BIT_RS
],
1589 lcd_bits
[LCD_PORT_C
][LCD_BIT_RS
]);
1590 pin_to_bits(lcd
.pins
.rw
, lcd_bits
[LCD_PORT_D
][LCD_BIT_RW
],
1591 lcd_bits
[LCD_PORT_C
][LCD_BIT_RW
]);
1592 pin_to_bits(lcd
.pins
.bl
, lcd_bits
[LCD_PORT_D
][LCD_BIT_BL
],
1593 lcd_bits
[LCD_PORT_C
][LCD_BIT_BL
]);
1594 pin_to_bits(lcd
.pins
.cl
, lcd_bits
[LCD_PORT_D
][LCD_BIT_CL
],
1595 lcd_bits
[LCD_PORT_C
][LCD_BIT_CL
]);
1596 pin_to_bits(lcd
.pins
.da
, lcd_bits
[LCD_PORT_D
][LCD_BIT_DA
],
1597 lcd_bits
[LCD_PORT_C
][LCD_BIT_DA
]);
1599 /* before this line, we must NOT send anything to the display.
1600 * Since lcd_init_display() needs to write data, we have to
1601 * enable mark the LCD initialized just before. */
1602 lcd_initialized
= 1;
1605 /* display a short message */
1606 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1607 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1608 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE
);
1611 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE
"\nPanel-"
1616 /* clear the display on the next device opening */
1622 * These are the file operation function for user access to /dev/keypad
1625 static ssize_t
keypad_read(struct file
*file
,
1626 char __user
*buf
, size_t count
, loff_t
*ppos
)
1629 char __user
*tmp
= buf
;
1631 if (keypad_buflen
== 0) {
1632 if (file
->f_flags
& O_NONBLOCK
)
1635 if (wait_event_interruptible(keypad_read_wait
,
1636 keypad_buflen
!= 0))
1640 for (; count
-- > 0 && (keypad_buflen
> 0);
1641 ++i
, ++tmp
, --keypad_buflen
) {
1642 put_user(keypad_buffer
[keypad_start
], tmp
);
1643 keypad_start
= (keypad_start
+ 1) % KEYPAD_BUFFER
;
1650 static int keypad_open(struct inode
*inode
, struct file
*file
)
1652 if (!atomic_dec_and_test(&keypad_available
))
1653 return -EBUSY
; /* open only once at a time */
1655 if (file
->f_mode
& FMODE_WRITE
) /* device is read-only */
1658 keypad_buflen
= 0; /* flush the buffer on opening */
1662 static int keypad_release(struct inode
*inode
, struct file
*file
)
1664 atomic_inc(&keypad_available
);
1668 static const struct file_operations keypad_fops
= {
1669 .read
= keypad_read
, /* read */
1670 .open
= keypad_open
, /* open */
1671 .release
= keypad_release
, /* close */
1672 .llseek
= default_llseek
,
1675 static struct miscdevice keypad_dev
= {
1676 .minor
= KEYPAD_MINOR
,
1678 .fops
= &keypad_fops
,
1681 static void keypad_send_key(const char *string
, int max_len
)
1683 if (init_in_progress
)
1686 /* send the key to the device only if a process is attached to it. */
1687 if (!atomic_read(&keypad_available
)) {
1688 while (max_len
-- && keypad_buflen
< KEYPAD_BUFFER
&& *string
) {
1689 keypad_buffer
[(keypad_start
+ keypad_buflen
++) %
1690 KEYPAD_BUFFER
] = *string
++;
1692 wake_up_interruptible(&keypad_read_wait
);
1696 /* this function scans all the bits involving at least one logical signal,
1697 * and puts the results in the bitfield "phys_read" (one bit per established
1698 * contact), and sets "phys_read_prev" to "phys_read".
1700 * Note: to debounce input signals, we will only consider as switched a signal
1701 * which is stable across 2 measures. Signals which are different between two
1702 * reads will be kept as they previously were in their logical form (phys_prev).
1703 * A signal which has just switched will have a 1 in
1704 * (phys_read ^ phys_read_prev).
1706 static void phys_scan_contacts(void)
1713 phys_prev
= phys_curr
;
1714 phys_read_prev
= phys_read
;
1715 phys_read
= 0; /* flush all signals */
1717 /* keep track of old value, with all outputs disabled */
1718 oldval
= r_dtr(pprt
) | scan_mask_o
;
1719 /* activate all keyboard outputs (active low) */
1720 w_dtr(pprt
, oldval
& ~scan_mask_o
);
1722 /* will have a 1 for each bit set to gnd */
1723 bitmask
= PNL_PINPUT(r_str(pprt
)) & scan_mask_i
;
1724 /* disable all matrix signals */
1725 w_dtr(pprt
, oldval
);
1727 /* now that all outputs are cleared, the only active input bits are
1728 * directly connected to the ground
1731 /* 1 for each grounded input */
1732 gndmask
= PNL_PINPUT(r_str(pprt
)) & scan_mask_i
;
1734 /* grounded inputs are signals 40-44 */
1735 phys_read
|= (pmask_t
) gndmask
<< 40;
1737 if (bitmask
!= gndmask
) {
1738 /* since clearing the outputs changed some inputs, we know
1739 * that some input signals are currently tied to some outputs.
1740 * So we'll scan them.
1742 for (bit
= 0; bit
< 8; bit
++) {
1745 if (!(scan_mask_o
& bitval
)) /* skip unused bits */
1748 w_dtr(pprt
, oldval
& ~bitval
); /* enable this output */
1749 bitmask
= PNL_PINPUT(r_str(pprt
)) & ~gndmask
;
1750 phys_read
|= (pmask_t
) bitmask
<< (5 * bit
);
1752 w_dtr(pprt
, oldval
); /* disable all outputs */
1754 /* this is easy: use old bits when they are flapping,
1755 * use new ones when stable */
1756 phys_curr
= (phys_prev
& (phys_read
^ phys_read_prev
)) |
1757 (phys_read
& ~(phys_read
^ phys_read_prev
));
1760 static inline int input_state_high(struct logical_input
*input
)
1764 * this is an invalid test. It tries to catch
1765 * transitions from single-key to multiple-key, but
1766 * doesn't take into account the contacts polarity.
1767 * The only solution to the problem is to parse keys
1768 * from the most complex to the simplest combinations,
1769 * and mark them as 'caught' once a combination
1770 * matches, then unmatch it for all other ones.
1773 /* try to catch dangerous transitions cases :
1774 * someone adds a bit, so this signal was a false
1775 * positive resulting from a transition. We should
1776 * invalidate the signal immediately and not call the
1778 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1780 if (((phys_prev
& input
->mask
) == input
->value
) &&
1781 ((phys_curr
& input
->mask
) > input
->value
)) {
1782 input
->state
= INPUT_ST_LOW
; /* invalidate */
1787 if ((phys_curr
& input
->mask
) == input
->value
) {
1788 if ((input
->type
== INPUT_TYPE_STD
) &&
1789 (input
->high_timer
== 0)) {
1790 input
->high_timer
++;
1791 if (input
->u
.std
.press_fct
!= NULL
)
1792 input
->u
.std
.press_fct(input
->u
.std
.press_data
);
1793 } else if (input
->type
== INPUT_TYPE_KBD
) {
1794 /* will turn on the light */
1797 if (input
->high_timer
== 0) {
1798 char *press_str
= input
->u
.kbd
.press_str
;
1801 int s
= sizeof(input
->u
.kbd
.press_str
);
1803 keypad_send_key(press_str
, s
);
1807 if (input
->u
.kbd
.repeat_str
[0]) {
1808 char *repeat_str
= input
->u
.kbd
.repeat_str
;
1810 if (input
->high_timer
>= KEYPAD_REP_START
) {
1811 int s
= sizeof(input
->u
.kbd
.repeat_str
);
1813 input
->high_timer
-= KEYPAD_REP_DELAY
;
1814 keypad_send_key(repeat_str
, s
);
1816 /* we will need to come back here soon */
1820 if (input
->high_timer
< 255)
1821 input
->high_timer
++;
1826 /* else signal falling down. Let's fall through. */
1827 input
->state
= INPUT_ST_FALLING
;
1828 input
->fall_timer
= 0;
1833 static inline void input_state_falling(struct logical_input
*input
)
1836 /* FIXME !!! same comment as in input_state_high */
1837 if (((phys_prev
& input
->mask
) == input
->value
) &&
1838 ((phys_curr
& input
->mask
) > input
->value
)) {
1839 input
->state
= INPUT_ST_LOW
; /* invalidate */
1844 if ((phys_curr
& input
->mask
) == input
->value
) {
1845 if (input
->type
== INPUT_TYPE_KBD
) {
1846 /* will turn on the light */
1849 if (input
->u
.kbd
.repeat_str
[0]) {
1850 char *repeat_str
= input
->u
.kbd
.repeat_str
;
1852 if (input
->high_timer
>= KEYPAD_REP_START
) {
1853 int s
= sizeof(input
->u
.kbd
.repeat_str
);
1855 input
->high_timer
-= KEYPAD_REP_DELAY
;
1856 keypad_send_key(repeat_str
, s
);
1858 /* we will need to come back here soon */
1862 if (input
->high_timer
< 255)
1863 input
->high_timer
++;
1865 input
->state
= INPUT_ST_HIGH
;
1866 } else if (input
->fall_timer
>= input
->fall_time
) {
1867 /* call release event */
1868 if (input
->type
== INPUT_TYPE_STD
) {
1869 void (*release_fct
)(int) = input
->u
.std
.release_fct
;
1871 if (release_fct
!= NULL
)
1872 release_fct(input
->u
.std
.release_data
);
1873 } else if (input
->type
== INPUT_TYPE_KBD
) {
1874 char *release_str
= input
->u
.kbd
.release_str
;
1876 if (release_str
[0]) {
1877 int s
= sizeof(input
->u
.kbd
.release_str
);
1879 keypad_send_key(release_str
, s
);
1883 input
->state
= INPUT_ST_LOW
;
1885 input
->fall_timer
++;
1890 static void panel_process_inputs(void)
1892 struct list_head
*item
;
1893 struct logical_input
*input
;
1897 list_for_each(item
, &logical_inputs
) {
1898 input
= list_entry(item
, struct logical_input
, list
);
1900 switch (input
->state
) {
1902 if ((phys_curr
& input
->mask
) != input
->value
)
1904 /* if all needed ones were already set previously,
1905 * this means that this logical signal has been
1906 * activated by the releasing of another combined
1907 * signal, so we don't want to match.
1908 * eg: AB -(release B)-> A -(release A)-> 0 :
1911 if ((phys_prev
& input
->mask
) == input
->value
)
1913 input
->rise_timer
= 0;
1914 input
->state
= INPUT_ST_RISING
;
1915 /* no break here, fall through */
1916 case INPUT_ST_RISING
:
1917 if ((phys_curr
& input
->mask
) != input
->value
) {
1918 input
->state
= INPUT_ST_LOW
;
1921 if (input
->rise_timer
< input
->rise_time
) {
1923 input
->rise_timer
++;
1926 input
->high_timer
= 0;
1927 input
->state
= INPUT_ST_HIGH
;
1928 /* no break here, fall through */
1930 if (input_state_high(input
))
1932 /* no break here, fall through */
1933 case INPUT_ST_FALLING
:
1934 input_state_falling(input
);
1939 static void panel_scan_timer(void)
1941 if (keypad
.enabled
&& keypad_initialized
) {
1942 if (spin_trylock_irq(&pprt_lock
)) {
1943 phys_scan_contacts();
1945 /* no need for the parport anymore */
1946 spin_unlock_irq(&pprt_lock
);
1949 if (!inputs_stable
|| phys_curr
!= phys_prev
)
1950 panel_process_inputs();
1953 if (lcd
.enabled
&& lcd_initialized
) {
1955 if (light_tempo
== 0 && ((lcd_flags
& LCD_FLAG_L
) == 0))
1957 light_tempo
= FLASH_LIGHT_TEMPO
;
1958 } else if (light_tempo
> 0) {
1960 if (light_tempo
== 0 && ((lcd_flags
& LCD_FLAG_L
) == 0))
1965 mod_timer(&scan_timer
, jiffies
+ INPUT_POLL_TIME
);
1968 static void init_scan_timer(void)
1970 if (scan_timer
.function
!= NULL
)
1971 return; /* already started */
1973 init_timer(&scan_timer
);
1974 scan_timer
.expires
= jiffies
+ INPUT_POLL_TIME
;
1975 scan_timer
.data
= 0;
1976 scan_timer
.function
= (void *)&panel_scan_timer
;
1977 add_timer(&scan_timer
);
1980 /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
1981 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1982 * corresponding to out and in bits respectively.
1983 * returns 1 if ok, 0 if error (in which case, nothing is written).
1985 static int input_name2mask(const char *name
, pmask_t
*mask
, pmask_t
*value
,
1986 char *imask
, char *omask
)
1988 static char sigtab
[10] = "EeSsPpAaBb";
1997 int in
, out
, bit
, neg
;
1999 for (in
= 0; (in
< sizeof(sigtab
)) && (sigtab
[in
] != *name
);
2003 if (in
>= sizeof(sigtab
))
2004 return 0; /* input name not found */
2005 neg
= (in
& 1); /* odd (lower) names are negated */
2010 if (isdigit(*name
)) {
2013 } else if (*name
== '-') {
2016 return 0; /* unknown bit name */
2019 bit
= (out
* 5) + in
;
2035 /* tries to bind a key to the signal name <name>. The key will send the
2036 * strings <press>, <repeat>, <release> for these respective events.
2037 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2039 static struct logical_input
*panel_bind_key(const char *name
, const char *press
,
2041 const char *release
)
2043 struct logical_input
*key
;
2045 key
= kzalloc(sizeof(*key
), GFP_KERNEL
);
2049 if (!input_name2mask(name
, &key
->mask
, &key
->value
, &scan_mask_i
,
2055 key
->type
= INPUT_TYPE_KBD
;
2056 key
->state
= INPUT_ST_LOW
;
2060 strncpy(key
->u
.kbd
.press_str
, press
, sizeof(key
->u
.kbd
.press_str
));
2061 strncpy(key
->u
.kbd
.repeat_str
, repeat
, sizeof(key
->u
.kbd
.repeat_str
));
2062 strncpy(key
->u
.kbd
.release_str
, release
,
2063 sizeof(key
->u
.kbd
.release_str
));
2064 list_add(&key
->list
, &logical_inputs
);
2069 /* tries to bind a callback function to the signal name <name>. The function
2070 * <press_fct> will be called with the <press_data> arg when the signal is
2071 * activated, and so on for <release_fct>/<release_data>
2072 * Returns the pointer to the new signal if ok, NULL if the signal could not
2075 static struct logical_input
*panel_bind_callback(char *name
,
2076 void (*press_fct
)(int),
2078 void (*release_fct
)(int),
2081 struct logical_input
*callback
;
2083 callback
= kmalloc(sizeof(*callback
), GFP_KERNEL
);
2087 memset(callback
, 0, sizeof(struct logical_input
));
2088 if (!input_name2mask(name
, &callback
->mask
, &callback
->value
,
2089 &scan_mask_i
, &scan_mask_o
))
2092 callback
->type
= INPUT_TYPE_STD
;
2093 callback
->state
= INPUT_ST_LOW
;
2094 callback
->rise_time
= 1;
2095 callback
->fall_time
= 1;
2096 callback
->u
.std
.press_fct
= press_fct
;
2097 callback
->u
.std
.press_data
= press_data
;
2098 callback
->u
.std
.release_fct
= release_fct
;
2099 callback
->u
.std
.release_data
= release_data
;
2100 list_add(&callback
->list
, &logical_inputs
);
2105 static void keypad_init(void)
2109 init_waitqueue_head(&keypad_read_wait
);
2110 keypad_buflen
= 0; /* flushes any eventual noisy keystroke */
2112 /* Let's create all known keys */
2114 for (keynum
= 0; keypad_profile
[keynum
][0][0]; keynum
++) {
2115 panel_bind_key(keypad_profile
[keynum
][0],
2116 keypad_profile
[keynum
][1],
2117 keypad_profile
[keynum
][2],
2118 keypad_profile
[keynum
][3]);
2122 keypad_initialized
= 1;
2125 /**************************************************/
2126 /* device initialization */
2127 /**************************************************/
2129 static int panel_notify_sys(struct notifier_block
*this, unsigned long code
,
2132 if (lcd
.enabled
&& lcd_initialized
) {
2136 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2140 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2143 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2152 static struct notifier_block panel_notifier
= {
2158 static void panel_attach(struct parport
*port
)
2160 if (port
->number
!= parport
)
2164 pr_err("%s: port->number=%d parport=%d, already registered!\n",
2165 __func__
, port
->number
, parport
);
2169 pprt
= parport_register_device(port
, "panel", NULL
, NULL
, /* pf, kf */
2171 /*PARPORT_DEV_EXCL */
2174 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
2175 __func__
, port
->number
, parport
);
2179 if (parport_claim(pprt
)) {
2180 pr_err("could not claim access to parport%d. Aborting.\n",
2182 goto err_unreg_device
;
2185 /* must init LCD first, just in case an IRQ from the keypad is
2186 * generated at keypad init
2190 if (misc_register(&lcd_dev
))
2191 goto err_unreg_device
;
2194 if (keypad
.enabled
) {
2196 if (misc_register(&keypad_dev
))
2203 misc_deregister(&lcd_dev
);
2205 parport_unregister_device(pprt
);
2209 static void panel_detach(struct parport
*port
)
2211 if (port
->number
!= parport
)
2215 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
2216 __func__
, port
->number
, parport
);
2220 if (keypad
.enabled
&& keypad_initialized
) {
2221 misc_deregister(&keypad_dev
);
2222 keypad_initialized
= 0;
2225 if (lcd
.enabled
&& lcd_initialized
) {
2226 misc_deregister(&lcd_dev
);
2227 lcd_initialized
= 0;
2230 parport_release(pprt
);
2231 parport_unregister_device(pprt
);
2235 static struct parport_driver panel_driver
= {
2237 .attach
= panel_attach
,
2238 .detach
= panel_detach
,
2242 static int __init
panel_init_module(void)
2244 int selected_keypad_type
= NOT_SET
;
2246 /* take care of an eventual profile */
2248 case PANEL_PROFILE_CUSTOM
:
2249 /* custom profile */
2250 selected_keypad_type
= DEFAULT_KEYPAD_TYPE
;
2251 selected_lcd_type
= DEFAULT_LCD_TYPE
;
2253 case PANEL_PROFILE_OLD
:
2254 /* 8 bits, 2*16, old keypad */
2255 selected_keypad_type
= KEYPAD_TYPE_OLD
;
2256 selected_lcd_type
= LCD_TYPE_OLD
;
2258 /* TODO: This two are a little hacky, sort it out later */
2259 if (lcd_width
== NOT_SET
)
2261 if (lcd_hwidth
== NOT_SET
)
2264 case PANEL_PROFILE_NEW
:
2265 /* serial, 2*16, new keypad */
2266 selected_keypad_type
= KEYPAD_TYPE_NEW
;
2267 selected_lcd_type
= LCD_TYPE_KS0074
;
2269 case PANEL_PROFILE_HANTRONIX
:
2270 /* 8 bits, 2*16 hantronix-like, no keypad */
2271 selected_keypad_type
= KEYPAD_TYPE_NONE
;
2272 selected_lcd_type
= LCD_TYPE_HANTRONIX
;
2274 case PANEL_PROFILE_NEXCOM
:
2275 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2276 selected_keypad_type
= KEYPAD_TYPE_NEXCOM
;
2277 selected_lcd_type
= LCD_TYPE_NEXCOM
;
2279 case PANEL_PROFILE_LARGE
:
2280 /* 8 bits, 2*40, old keypad */
2281 selected_keypad_type
= KEYPAD_TYPE_OLD
;
2282 selected_lcd_type
= LCD_TYPE_OLD
;
2287 * Init lcd struct with load-time values to preserve exact current
2288 * functionality (at least for now).
2290 lcd
.height
= lcd_height
;
2291 lcd
.width
= lcd_width
;
2292 lcd
.bwidth
= lcd_bwidth
;
2293 lcd
.hwidth
= lcd_hwidth
;
2294 lcd
.charset
= lcd_charset
;
2295 lcd
.proto
= lcd_proto
;
2296 lcd
.pins
.e
= lcd_e_pin
;
2297 lcd
.pins
.rs
= lcd_rs_pin
;
2298 lcd
.pins
.rw
= lcd_rw_pin
;
2299 lcd
.pins
.cl
= lcd_cl_pin
;
2300 lcd
.pins
.da
= lcd_da_pin
;
2301 lcd
.pins
.bl
= lcd_bl_pin
;
2304 * Overwrite selection with module param values (both keypad and lcd),
2305 * where the deprecated params have lower prio.
2307 if (keypad_enabled
> -1)
2308 selected_keypad_type
= keypad_enabled
;
2309 if (keypad_type
> -1)
2310 selected_keypad_type
= keypad_type
;
2312 keypad
.enabled
= (selected_keypad_type
> 0);
2314 if (lcd_enabled
> -1)
2315 selected_lcd_type
= lcd_enabled
;
2317 selected_lcd_type
= lcd_type
;
2319 lcd
.enabled
= (selected_lcd_type
> 0);
2321 switch (selected_keypad_type
) {
2322 case KEYPAD_TYPE_OLD
:
2323 keypad_profile
= old_keypad_profile
;
2325 case KEYPAD_TYPE_NEW
:
2326 keypad_profile
= new_keypad_profile
;
2328 case KEYPAD_TYPE_NEXCOM
:
2329 keypad_profile
= nexcom_keypad_profile
;
2332 keypad_profile
= NULL
;
2336 /* tells various subsystems about the fact that we are initializing */
2337 init_in_progress
= 1;
2339 if (parport_register_driver(&panel_driver
)) {
2340 pr_err("could not register with parport. Aborting.\n");
2344 if (!lcd
.enabled
&& !keypad
.enabled
) {
2345 /* no device enabled, let's release the parport */
2347 parport_release(pprt
);
2348 parport_unregister_device(pprt
);
2351 parport_unregister_driver(&panel_driver
);
2352 pr_err("driver version " PANEL_VERSION
" disabled.\n");
2356 register_reboot_notifier(&panel_notifier
);
2359 pr_info("driver version " PANEL_VERSION
2360 " registered on parport%d (io=0x%lx).\n", parport
,
2363 pr_info("driver version " PANEL_VERSION
2364 " not yet registered\n");
2365 /* tells various subsystems about the fact that initialization
2367 init_in_progress
= 0;
2371 static void __exit
panel_cleanup_module(void)
2373 unregister_reboot_notifier(&panel_notifier
);
2375 if (scan_timer
.function
!= NULL
)
2376 del_timer_sync(&scan_timer
);
2379 if (keypad
.enabled
) {
2380 misc_deregister(&keypad_dev
);
2381 keypad_initialized
= 0;
2385 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2386 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2387 misc_deregister(&lcd_dev
);
2388 lcd_initialized
= 0;
2391 /* TODO: free all input signals */
2392 parport_release(pprt
);
2393 parport_unregister_device(pprt
);
2396 parport_unregister_driver(&panel_driver
);
2399 module_init(panel_init_module
);
2400 module_exit(panel_cleanup_module
);
2401 MODULE_AUTHOR("Willy Tarreau");
2402 MODULE_LICENSE("GPL");