GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / panel / panel.c
blob056c5da8a036f0b9ef02c4388e4e32d18facde99
3 #include <linux/module.h>
5 #include <linux/types.h>
6 #include <linux/errno.h>
7 #include <linux/signal.h>
8 #include <linux/sched.h>
9 #include <linux/spinlock.h>
10 #include <linux/interrupt.h>
11 #include <linux/miscdevice.h>
12 #include <linux/slab.h>
13 #include <linux/ioport.h>
14 #include <linux/fcntl.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/kernel.h>
18 #include <linux/ctype.h>
19 #include <linux/parport.h>
20 #include <linux/version.h>
21 #include <linux/list.h>
22 #include <linux/notifier.h>
23 #include <linux/reboot.h>
24 #include <generated/utsrelease.h>
26 #include <linux/io.h>
27 #include <linux/uaccess.h>
28 #include <asm/system.h>
30 #define LCD_MINOR 156
31 #define KEYPAD_MINOR 185
33 #define PANEL_VERSION "0.9.5"
35 #define LCD_MAXBYTES 256 /* max burst write */
37 #define KEYPAD_BUFFER 64
39 /* poll the keyboard this every second */
40 #define INPUT_POLL_TIME (HZ/50)
41 /* a key starts to repeat after this times INPUT_POLL_TIME */
42 #define KEYPAD_REP_START (10)
43 /* a key repeats this times INPUT_POLL_TIME */
44 #define KEYPAD_REP_DELAY (2)
46 /* keep the light on this times INPUT_POLL_TIME for each flash */
47 #define FLASH_LIGHT_TEMPO (200)
49 /* converts an r_str() input to an active high, bits string : 000BAOSE */
50 #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
52 #define PNL_PBUSY 0x80 /* inverted input, active low */
53 #define PNL_PACK 0x40 /* direct input, active low */
54 #define PNL_POUTPA 0x20 /* direct input, active high */
55 #define PNL_PSELECD 0x10 /* direct input, active high */
56 #define PNL_PERRORP 0x08 /* direct input, active low */
58 #define PNL_PBIDIR 0x20 /* bi-directional ports */
59 /* high to read data in or-ed with data out */
60 #define PNL_PINTEN 0x10
61 #define PNL_PSELECP 0x08 /* inverted output, active low */
62 #define PNL_PINITP 0x04 /* direct output, active low */
63 #define PNL_PAUTOLF 0x02 /* inverted output, active low */
64 #define PNL_PSTROBE 0x01 /* inverted output */
66 #define PNL_PD0 0x01
67 #define PNL_PD1 0x02
68 #define PNL_PD2 0x04
69 #define PNL_PD3 0x08
70 #define PNL_PD4 0x10
71 #define PNL_PD5 0x20
72 #define PNL_PD6 0x40
73 #define PNL_PD7 0x80
75 #define PIN_NONE 0
76 #define PIN_STROBE 1
77 #define PIN_D0 2
78 #define PIN_D1 3
79 #define PIN_D2 4
80 #define PIN_D3 5
81 #define PIN_D4 6
82 #define PIN_D5 7
83 #define PIN_D6 8
84 #define PIN_D7 9
85 #define PIN_AUTOLF 14
86 #define PIN_INITP 16
87 #define PIN_SELECP 17
88 #define PIN_NOT_SET 127
90 #define LCD_FLAG_S 0x0001
91 #define LCD_FLAG_ID 0x0002
92 #define LCD_FLAG_B 0x0004 /* blink on */
93 #define LCD_FLAG_C 0x0008 /* cursor on */
94 #define LCD_FLAG_D 0x0010 /* display on */
95 #define LCD_FLAG_F 0x0020 /* large font mode */
96 #define LCD_FLAG_N 0x0040 /* 2-rows mode */
97 #define LCD_FLAG_L 0x0080 /* backlight enabled */
99 #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
100 #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
102 /* macros to simplify use of the parallel port */
103 #define r_ctr(x) (parport_read_control((x)->port))
104 #define r_dtr(x) (parport_read_data((x)->port))
105 #define r_str(x) (parport_read_status((x)->port))
106 #define w_ctr(x, y) do { parport_write_control((x)->port, (y)); } while (0)
107 #define w_dtr(x, y) do { parport_write_data((x)->port, (y)); } while (0)
109 /* this defines which bits are to be used and which ones to be ignored */
110 /* logical or of the output bits involved in the scan matrix */
111 static __u8 scan_mask_o;
112 /* logical or of the input bits involved in the scan matrix */
113 static __u8 scan_mask_i;
115 typedef __u64 pmask_t;
117 enum input_type {
118 INPUT_TYPE_STD,
119 INPUT_TYPE_KBD,
122 enum input_state {
123 INPUT_ST_LOW,
124 INPUT_ST_RISING,
125 INPUT_ST_HIGH,
126 INPUT_ST_FALLING,
129 struct logical_input {
130 struct list_head list;
131 pmask_t mask;
132 pmask_t value;
133 enum input_type type;
134 enum input_state state;
135 __u8 rise_time, fall_time;
136 __u8 rise_timer, fall_timer, high_timer;
138 union {
139 struct { /* valid when type == INPUT_TYPE_STD */
140 void (*press_fct) (int);
141 void (*release_fct) (int);
142 int press_data;
143 int release_data;
144 } std;
145 struct { /* valid when type == INPUT_TYPE_KBD */
146 /* strings can be non null-terminated */
147 char press_str[sizeof(void *) + sizeof(int)];
148 char repeat_str[sizeof(void *) + sizeof(int)];
149 char release_str[sizeof(void *) + sizeof(int)];
150 } kbd;
151 } u;
154 LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
156 /* physical contacts history
157 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
158 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
159 * corresponds to the ground.
160 * Within each group, bits are stored in the same order as read on the port :
161 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
162 * So, each __u64 (or pmask_t) is represented like this :
163 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
164 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
167 /* what has just been read from the I/O ports */
168 static pmask_t phys_read;
169 /* previous phys_read */
170 static pmask_t phys_read_prev;
171 /* stabilized phys_read (phys_read|phys_read_prev) */
172 static pmask_t phys_curr;
173 /* previous phys_curr */
174 static pmask_t phys_prev;
175 /* 0 means that at least one logical signal needs be computed */
176 static char inputs_stable;
178 /* these variables are specific to the keypad */
179 static char keypad_buffer[KEYPAD_BUFFER];
180 static int keypad_buflen;
181 static int keypad_start;
182 static char keypressed;
183 static wait_queue_head_t keypad_read_wait;
185 /* lcd-specific variables */
187 /* contains the LCD config state */
188 static unsigned long int lcd_flags;
189 /* contains the LCD X offset */
190 static unsigned long int lcd_addr_x;
191 /* contains the LCD Y offset */
192 static unsigned long int lcd_addr_y;
193 /* current escape sequence, 0 terminated */
194 static char lcd_escape[LCD_ESCAPE_LEN + 1];
195 /* not in escape state. >=0 = escape cmd len */
196 static int lcd_escape_len = -1;
199 * Bit masks to convert LCD signals to parallel port outputs.
200 * _d_ are values for data port, _c_ are for control port.
201 * [0] = signal OFF, [1] = signal ON, [2] = mask
203 #define BIT_CLR 0
204 #define BIT_SET 1
205 #define BIT_MSK 2
206 #define BIT_STATES 3
208 * one entry for each bit on the LCD
210 #define LCD_BIT_E 0
211 #define LCD_BIT_RS 1
212 #define LCD_BIT_RW 2
213 #define LCD_BIT_BL 3
214 #define LCD_BIT_CL 4
215 #define LCD_BIT_DA 5
216 #define LCD_BITS 6
219 * each bit can be either connected to a DATA or CTRL port
221 #define LCD_PORT_C 0
222 #define LCD_PORT_D 1
223 #define LCD_PORTS 2
225 static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
228 * LCD protocols
230 #define LCD_PROTO_PARALLEL 0
231 #define LCD_PROTO_SERIAL 1
232 #define LCD_PROTO_TI_DA8XX_LCD 2
235 * LCD character sets
237 #define LCD_CHARSET_NORMAL 0
238 #define LCD_CHARSET_KS0074 1
241 * LCD types
243 #define LCD_TYPE_NONE 0
244 #define LCD_TYPE_OLD 1
245 #define LCD_TYPE_KS0074 2
246 #define LCD_TYPE_HANTRONIX 3
247 #define LCD_TYPE_NEXCOM 4
248 #define LCD_TYPE_CUSTOM 5
251 * keypad types
253 #define KEYPAD_TYPE_NONE 0
254 #define KEYPAD_TYPE_OLD 1
255 #define KEYPAD_TYPE_NEW 2
256 #define KEYPAD_TYPE_NEXCOM 3
259 * panel profiles
261 #define PANEL_PROFILE_CUSTOM 0
262 #define PANEL_PROFILE_OLD 1
263 #define PANEL_PROFILE_NEW 2
264 #define PANEL_PROFILE_HANTRONIX 3
265 #define PANEL_PROFILE_NEXCOM 4
266 #define PANEL_PROFILE_LARGE 5
269 * Construct custom config from the kernel's configuration
271 #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
272 #define DEFAULT_PARPORT 0
273 #define DEFAULT_LCD LCD_TYPE_OLD
274 #define DEFAULT_KEYPAD KEYPAD_TYPE_OLD
275 #define DEFAULT_LCD_WIDTH 40
276 #define DEFAULT_LCD_BWIDTH 40
277 #define DEFAULT_LCD_HWIDTH 64
278 #define DEFAULT_LCD_HEIGHT 2
279 #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
281 #define DEFAULT_LCD_PIN_E PIN_AUTOLF
282 #define DEFAULT_LCD_PIN_RS PIN_SELECP
283 #define DEFAULT_LCD_PIN_RW PIN_INITP
284 #define DEFAULT_LCD_PIN_SCL PIN_STROBE
285 #define DEFAULT_LCD_PIN_SDA PIN_D0
286 #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
287 #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
289 #ifdef CONFIG_PANEL_PROFILE
290 #undef DEFAULT_PROFILE
291 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
292 #endif
294 #ifdef CONFIG_PANEL_PARPORT
295 #undef DEFAULT_PARPORT
296 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
297 #endif
299 #if DEFAULT_PROFILE == 0 /* custom */
300 #ifdef CONFIG_PANEL_KEYPAD
301 #undef DEFAULT_KEYPAD
302 #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD
303 #endif
305 #ifdef CONFIG_PANEL_LCD
306 #undef DEFAULT_LCD
307 #define DEFAULT_LCD CONFIG_PANEL_LCD
308 #endif
310 #ifdef CONFIG_PANEL_LCD_WIDTH
311 #undef DEFAULT_LCD_WIDTH
312 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
313 #endif
315 #ifdef CONFIG_PANEL_LCD_BWIDTH
316 #undef DEFAULT_LCD_BWIDTH
317 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
318 #endif
320 #ifdef CONFIG_PANEL_LCD_HWIDTH
321 #undef DEFAULT_LCD_HWIDTH
322 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
323 #endif
325 #ifdef CONFIG_PANEL_LCD_HEIGHT
326 #undef DEFAULT_LCD_HEIGHT
327 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
328 #endif
330 #ifdef CONFIG_PANEL_LCD_PROTO
331 #undef DEFAULT_LCD_PROTO
332 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
333 #endif
335 #ifdef CONFIG_PANEL_LCD_PIN_E
336 #undef DEFAULT_LCD_PIN_E
337 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
338 #endif
340 #ifdef CONFIG_PANEL_LCD_PIN_RS
341 #undef DEFAULT_LCD_PIN_RS
342 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
343 #endif
345 #ifdef CONFIG_PANEL_LCD_PIN_RW
346 #undef DEFAULT_LCD_PIN_RW
347 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
348 #endif
350 #ifdef CONFIG_PANEL_LCD_PIN_SCL
351 #undef DEFAULT_LCD_PIN_SCL
352 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
353 #endif
355 #ifdef CONFIG_PANEL_LCD_PIN_SDA
356 #undef DEFAULT_LCD_PIN_SDA
357 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
358 #endif
360 #ifdef CONFIG_PANEL_LCD_PIN_BL
361 #undef DEFAULT_LCD_PIN_BL
362 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
363 #endif
365 #ifdef CONFIG_PANEL_LCD_CHARSET
366 #undef DEFAULT_LCD_CHARSET
367 #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
368 #endif
370 #endif /* DEFAULT_PROFILE == 0 */
372 /* global variables */
373 static int keypad_open_cnt; /* #times opened */
374 static int lcd_open_cnt; /* #times opened */
375 static struct pardevice *pprt;
377 static int lcd_initialized;
378 static int keypad_initialized;
380 static int light_tempo;
382 static char lcd_must_clear;
383 static char lcd_left_shift;
384 static char init_in_progress;
386 static void (*lcd_write_cmd) (int);
387 static void (*lcd_write_data) (int);
388 static void (*lcd_clear_fast) (void);
390 static DEFINE_SPINLOCK(pprt_lock);
391 static struct timer_list scan_timer;
393 MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
395 static int parport = -1;
396 module_param(parport, int, 0000);
397 MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
399 static int lcd_height = -1;
400 module_param(lcd_height, int, 0000);
401 MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
403 static int lcd_width = -1;
404 module_param(lcd_width, int, 0000);
405 MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
407 static int lcd_bwidth = -1; /* internal buffer width (usually 40) */
408 module_param(lcd_bwidth, int, 0000);
409 MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
411 static int lcd_hwidth = -1; /* hardware buffer width (usually 64) */
412 module_param(lcd_hwidth, int, 0000);
413 MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
415 static int lcd_enabled = -1;
416 module_param(lcd_enabled, int, 0000);
417 MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
419 static int keypad_enabled = -1;
420 module_param(keypad_enabled, int, 0000);
421 MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
423 static int lcd_type = -1;
424 module_param(lcd_type, int, 0000);
425 MODULE_PARM_DESC(lcd_type,
426 "LCD type: 0=none, 1=old //, 2=serial ks0074, "
427 "3=hantronix //, 4=nexcom //, 5=compiled-in");
429 static int lcd_proto = -1;
430 module_param(lcd_proto, int, 0000);
431 MODULE_PARM_DESC(lcd_proto,
432 "LCD communication: 0=parallel (//), 1=serial,"
433 "2=TI LCD Interface");
435 static int lcd_charset = -1;
436 module_param(lcd_charset, int, 0000);
437 MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
439 static int keypad_type = -1;
440 module_param(keypad_type, int, 0000);
441 MODULE_PARM_DESC(keypad_type,
442 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, "
443 "3=nexcom 4 keys");
445 static int profile = DEFAULT_PROFILE;
446 module_param(profile, int, 0000);
447 MODULE_PARM_DESC(profile,
448 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
449 "4=16x2 nexcom; default=40x2, old kp");
452 * These are the parallel port pins the LCD control signals are connected to.
453 * Set this to 0 if the signal is not used. Set it to its opposite value
454 * (negative) if the signal is negated. -MAXINT is used to indicate that the
455 * pin has not been explicitly specified.
457 * WARNING! no check will be performed about collisions with keypad !
460 static int lcd_e_pin = PIN_NOT_SET;
461 module_param(lcd_e_pin, int, 0000);
462 MODULE_PARM_DESC(lcd_e_pin,
463 "# of the // port pin connected to LCD 'E' signal, "
464 "with polarity (-17..17)");
466 static int lcd_rs_pin = PIN_NOT_SET;
467 module_param(lcd_rs_pin, int, 0000);
468 MODULE_PARM_DESC(lcd_rs_pin,
469 "# of the // port pin connected to LCD 'RS' signal, "
470 "with polarity (-17..17)");
472 static int lcd_rw_pin = PIN_NOT_SET;
473 module_param(lcd_rw_pin, int, 0000);
474 MODULE_PARM_DESC(lcd_rw_pin,
475 "# of the // port pin connected to LCD 'RW' signal, "
476 "with polarity (-17..17)");
478 static int lcd_bl_pin = PIN_NOT_SET;
479 module_param(lcd_bl_pin, int, 0000);
480 MODULE_PARM_DESC(lcd_bl_pin,
481 "# of the // port pin connected to LCD backlight, "
482 "with polarity (-17..17)");
484 static int lcd_da_pin = PIN_NOT_SET;
485 module_param(lcd_da_pin, int, 0000);
486 MODULE_PARM_DESC(lcd_da_pin,
487 "# of the // port pin connected to serial LCD 'SDA' "
488 "signal, with polarity (-17..17)");
490 static int lcd_cl_pin = PIN_NOT_SET;
491 module_param(lcd_cl_pin, int, 0000);
492 MODULE_PARM_DESC(lcd_cl_pin,
493 "# of the // port pin connected to serial LCD 'SCL' "
494 "signal, with polarity (-17..17)");
496 static unsigned char *lcd_char_conv;
498 /* for some LCD drivers (ks0074) we need a charset conversion table. */
499 static unsigned char lcd_char_conv_ks0074[256] = {
500 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
501 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
502 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
503 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
504 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
505 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
506 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
507 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
508 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
509 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
510 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
511 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
512 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
513 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
514 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
515 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
516 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
517 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
518 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
519 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
520 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
521 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
522 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
523 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
524 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
525 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
526 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
527 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
528 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
529 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
530 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
531 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
532 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
535 char old_keypad_profile[][4][9] = {
536 {"S0", "Left\n", "Left\n", ""},
537 {"S1", "Down\n", "Down\n", ""},
538 {"S2", "Up\n", "Up\n", ""},
539 {"S3", "Right\n", "Right\n", ""},
540 {"S4", "Esc\n", "Esc\n", ""},
541 {"S5", "Ret\n", "Ret\n", ""},
542 {"", "", "", ""}
545 /* signals, press, repeat, release */
546 char new_keypad_profile[][4][9] = {
547 {"S0", "Left\n", "Left\n", ""},
548 {"S1", "Down\n", "Down\n", ""},
549 {"S2", "Up\n", "Up\n", ""},
550 {"S3", "Right\n", "Right\n", ""},
551 {"S4s5", "", "Esc\n", "Esc\n"},
552 {"s4S5", "", "Ret\n", "Ret\n"},
553 {"S4S5", "Help\n", "", ""},
554 /* add new signals above this line */
555 {"", "", "", ""}
558 /* signals, press, repeat, release */
559 char nexcom_keypad_profile[][4][9] = {
560 {"a-p-e-", "Down\n", "Down\n", ""},
561 {"a-p-E-", "Ret\n", "Ret\n", ""},
562 {"a-P-E-", "Esc\n", "Esc\n", ""},
563 {"a-P-e-", "Up\n", "Up\n", ""},
564 /* add new signals above this line */
565 {"", "", "", ""}
568 static char (*keypad_profile)[4][9] = old_keypad_profile;
570 static struct {
571 unsigned char e; /* parallel LCD E (data latch on falling edge) */
572 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
573 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
574 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
575 unsigned char cl; /* serial LCD clock (latch on rising edge) */
576 unsigned char da; /* serial LCD data */
577 } bits;
579 static void init_scan_timer(void);
581 /* sets data port bits according to current signals values */
582 static int set_data_bits(void)
584 int val, bit;
586 val = r_dtr(pprt);
587 for (bit = 0; bit < LCD_BITS; bit++)
588 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
590 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
591 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
592 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
593 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
594 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
595 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
597 w_dtr(pprt, val);
598 return val;
601 /* sets ctrl port bits according to current signals values */
602 static int set_ctrl_bits(void)
604 int val, bit;
606 val = r_ctr(pprt);
607 for (bit = 0; bit < LCD_BITS; bit++)
608 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
610 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
611 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
612 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
613 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
614 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
615 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
617 w_ctr(pprt, val);
618 return val;
621 /* sets ctrl & data port bits according to current signals values */
622 static void panel_set_bits(void)
624 set_data_bits();
625 set_ctrl_bits();
629 * Converts a parallel port pin (from -25 to 25) to data and control ports
630 * masks, and data and control port bits. The signal will be considered
631 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
633 * Result will be used this way :
634 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
635 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
637 void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
639 int d_bit, c_bit, inv;
641 d_val[0] = c_val[0] = d_val[1] = c_val[1] = 0;
642 d_val[2] = c_val[2] = 0xFF;
644 if (pin == 0)
645 return;
647 inv = (pin < 0);
648 if (inv)
649 pin = -pin;
651 d_bit = c_bit = 0;
653 switch (pin) {
654 case PIN_STROBE: /* strobe, inverted */
655 c_bit = PNL_PSTROBE;
656 inv = !inv;
657 break;
658 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
659 d_bit = 1 << (pin - 2);
660 break;
661 case PIN_AUTOLF: /* autofeed, inverted */
662 c_bit = PNL_PAUTOLF;
663 inv = !inv;
664 break;
665 case PIN_INITP: /* init, direct */
666 c_bit = PNL_PINITP;
667 break;
668 case PIN_SELECP: /* select_in, inverted */
669 c_bit = PNL_PSELECP;
670 inv = !inv;
671 break;
672 default: /* unknown pin, ignore */
673 break;
676 if (c_bit) {
677 c_val[2] &= ~c_bit;
678 c_val[!inv] = c_bit;
679 } else if (d_bit) {
680 d_val[2] &= ~d_bit;
681 d_val[!inv] = d_bit;
685 /* sleeps that many milliseconds with a reschedule */
686 static void long_sleep(int ms)
689 if (in_interrupt())
690 mdelay(ms);
691 else {
692 current->state = TASK_INTERRUPTIBLE;
693 schedule_timeout((ms * HZ + 999) / 1000);
697 /* send a serial byte to the LCD panel. The caller is responsible for locking
698 if needed. */
699 static void lcd_send_serial(int byte)
701 int bit;
703 /* the data bit is set on D0, and the clock on STROBE.
704 * LCD reads D0 on STROBE's rising edge. */
705 for (bit = 0; bit < 8; bit++) {
706 bits.cl = BIT_CLR; /* CLK low */
707 panel_set_bits();
708 bits.da = byte & 1;
709 panel_set_bits();
710 udelay(2); /* maintain the data during 2 us before CLK up */
711 bits.cl = BIT_SET; /* CLK high */
712 panel_set_bits();
713 udelay(1); /* maintain the strobe during 1 us */
714 byte >>= 1;
718 /* turn the backlight on or off */
719 static void lcd_backlight(int on)
721 if (lcd_bl_pin == PIN_NONE)
722 return;
724 /* The backlight is activated by seting the AUTOFEED line to +5V */
725 spin_lock(&pprt_lock);
726 bits.bl = on;
727 panel_set_bits();
728 spin_unlock(&pprt_lock);
731 /* send a command to the LCD panel in serial mode */
732 static void lcd_write_cmd_s(int cmd)
734 spin_lock(&pprt_lock);
735 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
736 lcd_send_serial(cmd & 0x0F);
737 lcd_send_serial((cmd >> 4) & 0x0F);
738 udelay(40); /* the shortest command takes at least 40 us */
739 spin_unlock(&pprt_lock);
742 /* send data to the LCD panel in serial mode */
743 static void lcd_write_data_s(int data)
745 spin_lock(&pprt_lock);
746 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
747 lcd_send_serial(data & 0x0F);
748 lcd_send_serial((data >> 4) & 0x0F);
749 udelay(40); /* the shortest data takes at least 40 us */
750 spin_unlock(&pprt_lock);
753 /* send a command to the LCD panel in 8 bits parallel mode */
754 static void lcd_write_cmd_p8(int cmd)
756 spin_lock(&pprt_lock);
757 /* present the data to the data port */
758 w_dtr(pprt, cmd);
759 udelay(20); /* maintain the data during 20 us before the strobe */
761 bits.e = BIT_SET;
762 bits.rs = BIT_CLR;
763 bits.rw = BIT_CLR;
764 set_ctrl_bits();
766 udelay(40); /* maintain the strobe during 40 us */
768 bits.e = BIT_CLR;
769 set_ctrl_bits();
771 udelay(120); /* the shortest command takes at least 120 us */
772 spin_unlock(&pprt_lock);
775 /* send data to the LCD panel in 8 bits parallel mode */
776 static void lcd_write_data_p8(int data)
778 spin_lock(&pprt_lock);
779 /* present the data to the data port */
780 w_dtr(pprt, data);
781 udelay(20); /* maintain the data during 20 us before the strobe */
783 bits.e = BIT_SET;
784 bits.rs = BIT_SET;
785 bits.rw = BIT_CLR;
786 set_ctrl_bits();
788 udelay(40); /* maintain the strobe during 40 us */
790 bits.e = BIT_CLR;
791 set_ctrl_bits();
793 udelay(45); /* the shortest data takes at least 45 us */
794 spin_unlock(&pprt_lock);
797 /* send a command to the TI LCD panel */
798 static void lcd_write_cmd_tilcd(int cmd)
800 spin_lock(&pprt_lock);
801 /* present the data to the control port */
802 w_ctr(pprt, cmd);
803 udelay(60);
804 spin_unlock(&pprt_lock);
807 /* send data to the TI LCD panel */
808 static void lcd_write_data_tilcd(int data)
810 spin_lock(&pprt_lock);
811 /* present the data to the data port */
812 w_dtr(pprt, data);
813 udelay(60);
814 spin_unlock(&pprt_lock);
817 static void lcd_gotoxy(void)
819 lcd_write_cmd(0x80 /* set DDRAM address */
820 | (lcd_addr_y ? lcd_hwidth : 0)
821 /* we force the cursor to stay at the end of the
822 line if it wants to go farther */
823 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
824 (lcd_hwidth - 1) : lcd_bwidth - 1));
827 static void lcd_print(char c)
829 if (lcd_addr_x < lcd_bwidth) {
830 if (lcd_char_conv != NULL)
831 c = lcd_char_conv[(unsigned char)c];
832 lcd_write_data(c);
833 lcd_addr_x++;
835 /* prevents the cursor from wrapping onto the next line */
836 if (lcd_addr_x == lcd_bwidth)
837 lcd_gotoxy();
840 /* fills the display with spaces and resets X/Y */
841 static void lcd_clear_fast_s(void)
843 int pos;
844 lcd_addr_x = lcd_addr_y = 0;
845 lcd_gotoxy();
847 spin_lock(&pprt_lock);
848 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
849 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
850 lcd_send_serial(' ' & 0x0F);
851 lcd_send_serial((' ' >> 4) & 0x0F);
852 udelay(40); /* the shortest data takes at least 40 us */
854 spin_unlock(&pprt_lock);
856 lcd_addr_x = lcd_addr_y = 0;
857 lcd_gotoxy();
860 /* fills the display with spaces and resets X/Y */
861 static void lcd_clear_fast_p8(void)
863 int pos;
864 lcd_addr_x = lcd_addr_y = 0;
865 lcd_gotoxy();
867 spin_lock(&pprt_lock);
868 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
869 /* present the data to the data port */
870 w_dtr(pprt, ' ');
872 /* maintain the data during 20 us before the strobe */
873 udelay(20);
875 bits.e = BIT_SET;
876 bits.rs = BIT_SET;
877 bits.rw = BIT_CLR;
878 set_ctrl_bits();
880 /* maintain the strobe during 40 us */
881 udelay(40);
883 bits.e = BIT_CLR;
884 set_ctrl_bits();
886 /* the shortest data takes at least 45 us */
887 udelay(45);
889 spin_unlock(&pprt_lock);
891 lcd_addr_x = lcd_addr_y = 0;
892 lcd_gotoxy();
895 /* fills the display with spaces and resets X/Y */
896 static void lcd_clear_fast_tilcd(void)
898 int pos;
899 lcd_addr_x = lcd_addr_y = 0;
900 lcd_gotoxy();
902 spin_lock(&pprt_lock);
903 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
904 /* present the data to the data port */
905 w_dtr(pprt, ' ');
906 udelay(60);
909 spin_unlock(&pprt_lock);
911 lcd_addr_x = lcd_addr_y = 0;
912 lcd_gotoxy();
915 /* clears the display and resets X/Y */
916 static void lcd_clear_display(void)
918 lcd_write_cmd(0x01); /* clear display */
919 lcd_addr_x = lcd_addr_y = 0;
920 /* we must wait a few milliseconds (15) */
921 long_sleep(15);
924 static void lcd_init_display(void)
927 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
928 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
930 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
932 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
933 long_sleep(10);
934 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
935 long_sleep(10);
936 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
937 long_sleep(10);
939 lcd_write_cmd(0x30 /* set font height and lines number */
940 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
941 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
943 long_sleep(10);
945 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
946 long_sleep(10);
948 lcd_write_cmd(0x08 /* set display mode */
949 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
950 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
951 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
954 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
956 long_sleep(10);
958 /* entry mode set : increment, cursor shifting */
959 lcd_write_cmd(0x06);
961 lcd_clear_display();
965 * These are the file operation function for user access to /dev/lcd
966 * This function can also be called from inside the kernel, by
967 * setting file and ppos to NULL.
971 static inline int handle_lcd_special_code(void)
973 /* LCD special codes */
975 int processed = 0;
977 char *esc = lcd_escape + 2;
978 int oldflags = lcd_flags;
980 /* check for display mode flags */
981 switch (*esc) {
982 case 'D': /* Display ON */
983 lcd_flags |= LCD_FLAG_D;
984 processed = 1;
985 break;
986 case 'd': /* Display OFF */
987 lcd_flags &= ~LCD_FLAG_D;
988 processed = 1;
989 break;
990 case 'C': /* Cursor ON */
991 lcd_flags |= LCD_FLAG_C;
992 processed = 1;
993 break;
994 case 'c': /* Cursor OFF */
995 lcd_flags &= ~LCD_FLAG_C;
996 processed = 1;
997 break;
998 case 'B': /* Blink ON */
999 lcd_flags |= LCD_FLAG_B;
1000 processed = 1;
1001 break;
1002 case 'b': /* Blink OFF */
1003 lcd_flags &= ~LCD_FLAG_B;
1004 processed = 1;
1005 break;
1006 case '+': /* Back light ON */
1007 lcd_flags |= LCD_FLAG_L;
1008 processed = 1;
1009 break;
1010 case '-': /* Back light OFF */
1011 lcd_flags &= ~LCD_FLAG_L;
1012 processed = 1;
1013 break;
1014 case '*':
1015 /* flash back light using the keypad timer */
1016 if (scan_timer.function != NULL) {
1017 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1018 lcd_backlight(1);
1019 light_tempo = FLASH_LIGHT_TEMPO;
1021 processed = 1;
1022 break;
1023 case 'f': /* Small Font */
1024 lcd_flags &= ~LCD_FLAG_F;
1025 processed = 1;
1026 break;
1027 case 'F': /* Large Font */
1028 lcd_flags |= LCD_FLAG_F;
1029 processed = 1;
1030 break;
1031 case 'n': /* One Line */
1032 lcd_flags &= ~LCD_FLAG_N;
1033 processed = 1;
1034 break;
1035 case 'N': /* Two Lines */
1036 lcd_flags |= LCD_FLAG_N;
1037 break;
1038 case 'l': /* Shift Cursor Left */
1039 if (lcd_addr_x > 0) {
1040 /* back one char if not at end of line */
1041 if (lcd_addr_x < lcd_bwidth)
1042 lcd_write_cmd(0x10);
1043 lcd_addr_x--;
1045 processed = 1;
1046 break;
1047 case 'r': /* shift cursor right */
1048 if (lcd_addr_x < lcd_width) {
1049 /* allow the cursor to pass the end of the line */
1050 if (lcd_addr_x <
1051 (lcd_bwidth - 1))
1052 lcd_write_cmd(0x14);
1053 lcd_addr_x++;
1055 processed = 1;
1056 break;
1057 case 'L': /* shift display left */
1058 lcd_left_shift++;
1059 lcd_write_cmd(0x18);
1060 processed = 1;
1061 break;
1062 case 'R': /* shift display right */
1063 lcd_left_shift--;
1064 lcd_write_cmd(0x1C);
1065 processed = 1;
1066 break;
1067 case 'k': { /* kill end of line */
1068 int x;
1069 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1070 lcd_write_data(' ');
1072 /* restore cursor position */
1073 lcd_gotoxy();
1074 processed = 1;
1075 break;
1077 case 'I': /* reinitialize display */
1078 lcd_init_display();
1079 lcd_left_shift = 0;
1080 processed = 1;
1081 break;
1082 case 'G': {
1083 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1084 * and '7', representing the numerical ASCII code of the
1085 * redefined character, and <xx...xx> a sequence of 16
1086 * hex digits representing 8 bytes for each character.
1087 * Most LCDs will only use 5 lower bits of the 7 first
1088 * bytes.
1091 unsigned char cgbytes[8];
1092 unsigned char cgaddr;
1093 int cgoffset;
1094 int shift;
1095 char value;
1096 int addr;
1098 if (strchr(esc, ';') == NULL)
1099 break;
1101 esc++;
1103 cgaddr = *(esc++) - '0';
1104 if (cgaddr > 7) {
1105 processed = 1;
1106 break;
1109 cgoffset = 0;
1110 shift = 0;
1111 value = 0;
1112 while (*esc && cgoffset < 8) {
1113 shift ^= 4;
1114 if (*esc >= '0' && *esc <= '9')
1115 value |= (*esc - '0') << shift;
1116 else if (*esc >= 'A' && *esc <= 'Z')
1117 value |= (*esc - 'A' + 10) << shift;
1118 else if (*esc >= 'a' && *esc <= 'z')
1119 value |= (*esc - 'a' + 10) << shift;
1120 else {
1121 esc++;
1122 continue;
1125 if (shift == 0) {
1126 cgbytes[cgoffset++] = value;
1127 value = 0;
1130 esc++;
1133 lcd_write_cmd(0x40 | (cgaddr * 8));
1134 for (addr = 0; addr < cgoffset; addr++)
1135 lcd_write_data(cgbytes[addr]);
1137 /* ensures that we stop writing to CGRAM */
1138 lcd_gotoxy();
1139 processed = 1;
1140 break;
1142 case 'x': /* gotoxy : LxXXX[yYYY]; */
1143 case 'y':
1144 if (strchr(esc, ';') == NULL)
1145 break;
1147 while (*esc) {
1148 char *endp;
1150 if (*esc == 'x') {
1151 esc++;
1152 lcd_addr_x = simple_strtoul(esc, &endp, 10);
1153 esc = endp;
1154 } else if (*esc == 'y') {
1155 esc++;
1156 lcd_addr_y = simple_strtoul(esc, &endp, 10);
1157 esc = endp;
1158 } else
1159 break;
1162 lcd_gotoxy();
1163 processed = 1;
1164 break;
1167 /* Check wether one flag was changed */
1168 if (oldflags != lcd_flags) {
1169 /* check whether one of B,C,D flags were changed */
1170 if ((oldflags ^ lcd_flags) &
1171 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1172 /* set display mode */
1173 lcd_write_cmd(0x08
1174 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1175 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1176 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1177 /* check whether one of F,N flags was changed */
1178 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1179 lcd_write_cmd(0x30
1180 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1181 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
1182 /* check wether L flag was changed */
1183 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1184 if (lcd_flags & (LCD_FLAG_L))
1185 lcd_backlight(1);
1186 else if (light_tempo == 0)
1187 /* switch off the light only when the tempo
1188 lighting is gone */
1189 lcd_backlight(0);
1193 return processed;
1196 static ssize_t lcd_write(struct file *file,
1197 const char *buf, size_t count, loff_t *ppos)
1199 const char *tmp = buf;
1200 char c;
1202 for (; count-- > 0; (ppos ? (*ppos)++ : 0), ++tmp) {
1203 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1204 /* let's be a little nice with other processes
1205 that need some CPU */
1206 schedule();
1208 if (ppos == NULL && file == NULL)
1209 /* let's not use get_user() from the kernel ! */
1210 c = *tmp;
1211 else if (get_user(c, tmp))
1212 return -EFAULT;
1214 /* first, we'll test if we're in escape mode */
1215 if ((c != '\n') && lcd_escape_len >= 0) {
1216 /* yes, let's add this char to the buffer */
1217 lcd_escape[lcd_escape_len++] = c;
1218 lcd_escape[lcd_escape_len] = 0;
1219 } else {
1220 /* aborts any previous escape sequence */
1221 lcd_escape_len = -1;
1223 switch (c) {
1224 case LCD_ESCAPE_CHAR:
1225 /* start of an escape sequence */
1226 lcd_escape_len = 0;
1227 lcd_escape[lcd_escape_len] = 0;
1228 break;
1229 case '\b':
1230 /* go back one char and clear it */
1231 if (lcd_addr_x > 0) {
1232 /* check if we're not at the
1233 end of the line */
1234 if (lcd_addr_x < lcd_bwidth)
1235 /* back one char */
1236 lcd_write_cmd(0x10);
1237 lcd_addr_x--;
1239 /* replace with a space */
1240 lcd_write_data(' ');
1241 /* back one char again */
1242 lcd_write_cmd(0x10);
1243 break;
1244 case '\014':
1245 /* quickly clear the display */
1246 lcd_clear_fast();
1247 break;
1248 case '\n':
1249 /* flush the remainder of the current line and
1250 go to the beginning of the next line */
1251 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1252 lcd_write_data(' ');
1253 lcd_addr_x = 0;
1254 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1255 lcd_gotoxy();
1256 break;
1257 case '\r':
1258 /* go to the beginning of the same line */
1259 lcd_addr_x = 0;
1260 lcd_gotoxy();
1261 break;
1262 case '\t':
1263 /* print a space instead of the tab */
1264 lcd_print(' ');
1265 break;
1266 default:
1267 /* simply print this char */
1268 lcd_print(c);
1269 break;
1273 /* now we'll see if we're in an escape mode and if the current
1274 escape sequence can be understood. */
1275 if (lcd_escape_len >= 2) {
1276 int processed = 0;
1278 if (!strcmp(lcd_escape, "[2J")) {
1279 /* clear the display */
1280 lcd_clear_fast();
1281 processed = 1;
1282 } else if (!strcmp(lcd_escape, "[H")) {
1283 /* cursor to home */
1284 lcd_addr_x = lcd_addr_y = 0;
1285 lcd_gotoxy();
1286 processed = 1;
1288 /* codes starting with ^[[L */
1289 else if ((lcd_escape_len >= 3) &&
1290 (lcd_escape[0] == '[') &&
1291 (lcd_escape[1] == 'L')) {
1292 processed = handle_lcd_special_code();
1295 /* LCD special escape codes */
1296 /* flush the escape sequence if it's been processed
1297 or if it is getting too long. */
1298 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1299 lcd_escape_len = -1;
1300 } /* escape codes */
1303 return tmp - buf;
1306 static int lcd_open(struct inode *inode, struct file *file)
1308 if (lcd_open_cnt)
1309 return -EBUSY; /* open only once at a time */
1311 if (file->f_mode & FMODE_READ) /* device is write-only */
1312 return -EPERM;
1314 if (lcd_must_clear) {
1315 lcd_clear_display();
1316 lcd_must_clear = 0;
1318 lcd_open_cnt++;
1319 return nonseekable_open(inode, file);
1322 static int lcd_release(struct inode *inode, struct file *file)
1324 lcd_open_cnt--;
1325 return 0;
1328 static const struct file_operations lcd_fops = {
1329 .write = lcd_write,
1330 .open = lcd_open,
1331 .release = lcd_release,
1332 .llseek = no_llseek,
1335 static struct miscdevice lcd_dev = {
1336 LCD_MINOR,
1337 "lcd",
1338 &lcd_fops
1341 /* public function usable from the kernel for any purpose */
1342 void panel_lcd_print(char *s)
1344 if (lcd_enabled && lcd_initialized)
1345 lcd_write(NULL, s, strlen(s), NULL);
1348 /* initialize the LCD driver */
1349 void lcd_init(void)
1351 switch (lcd_type) {
1352 case LCD_TYPE_OLD:
1353 /* parallel mode, 8 bits */
1354 if (lcd_proto < 0)
1355 lcd_proto = LCD_PROTO_PARALLEL;
1356 if (lcd_charset < 0)
1357 lcd_charset = LCD_CHARSET_NORMAL;
1358 if (lcd_e_pin == PIN_NOT_SET)
1359 lcd_e_pin = PIN_STROBE;
1360 if (lcd_rs_pin == PIN_NOT_SET)
1361 lcd_rs_pin = PIN_AUTOLF;
1363 if (lcd_width < 0)
1364 lcd_width = 40;
1365 if (lcd_bwidth < 0)
1366 lcd_bwidth = 40;
1367 if (lcd_hwidth < 0)
1368 lcd_hwidth = 64;
1369 if (lcd_height < 0)
1370 lcd_height = 2;
1371 break;
1372 case LCD_TYPE_KS0074:
1373 /* serial mode, ks0074 */
1374 if (lcd_proto < 0)
1375 lcd_proto = LCD_PROTO_SERIAL;
1376 if (lcd_charset < 0)
1377 lcd_charset = LCD_CHARSET_KS0074;
1378 if (lcd_bl_pin == PIN_NOT_SET)
1379 lcd_bl_pin = PIN_AUTOLF;
1380 if (lcd_cl_pin == PIN_NOT_SET)
1381 lcd_cl_pin = PIN_STROBE;
1382 if (lcd_da_pin == PIN_NOT_SET)
1383 lcd_da_pin = PIN_D0;
1385 if (lcd_width < 0)
1386 lcd_width = 16;
1387 if (lcd_bwidth < 0)
1388 lcd_bwidth = 40;
1389 if (lcd_hwidth < 0)
1390 lcd_hwidth = 16;
1391 if (lcd_height < 0)
1392 lcd_height = 2;
1393 break;
1394 case LCD_TYPE_NEXCOM:
1395 /* parallel mode, 8 bits, generic */
1396 if (lcd_proto < 0)
1397 lcd_proto = LCD_PROTO_PARALLEL;
1398 if (lcd_charset < 0)
1399 lcd_charset = LCD_CHARSET_NORMAL;
1400 if (lcd_e_pin == PIN_NOT_SET)
1401 lcd_e_pin = PIN_AUTOLF;
1402 if (lcd_rs_pin == PIN_NOT_SET)
1403 lcd_rs_pin = PIN_SELECP;
1404 if (lcd_rw_pin == PIN_NOT_SET)
1405 lcd_rw_pin = PIN_INITP;
1407 if (lcd_width < 0)
1408 lcd_width = 16;
1409 if (lcd_bwidth < 0)
1410 lcd_bwidth = 40;
1411 if (lcd_hwidth < 0)
1412 lcd_hwidth = 64;
1413 if (lcd_height < 0)
1414 lcd_height = 2;
1415 break;
1416 case LCD_TYPE_CUSTOM:
1417 /* customer-defined */
1418 if (lcd_proto < 0)
1419 lcd_proto = DEFAULT_LCD_PROTO;
1420 if (lcd_charset < 0)
1421 lcd_charset = DEFAULT_LCD_CHARSET;
1422 /* default geometry will be set later */
1423 break;
1424 case LCD_TYPE_HANTRONIX:
1425 /* parallel mode, 8 bits, hantronix-like */
1426 default:
1427 if (lcd_proto < 0)
1428 lcd_proto = LCD_PROTO_PARALLEL;
1429 if (lcd_charset < 0)
1430 lcd_charset = LCD_CHARSET_NORMAL;
1431 if (lcd_e_pin == PIN_NOT_SET)
1432 lcd_e_pin = PIN_STROBE;
1433 if (lcd_rs_pin == PIN_NOT_SET)
1434 lcd_rs_pin = PIN_SELECP;
1436 if (lcd_width < 0)
1437 lcd_width = 16;
1438 if (lcd_bwidth < 0)
1439 lcd_bwidth = 40;
1440 if (lcd_hwidth < 0)
1441 lcd_hwidth = 64;
1442 if (lcd_height < 0)
1443 lcd_height = 2;
1444 break;
1447 /* this is used to catch wrong and default values */
1448 if (lcd_width <= 0)
1449 lcd_width = DEFAULT_LCD_WIDTH;
1450 if (lcd_bwidth <= 0)
1451 lcd_bwidth = DEFAULT_LCD_BWIDTH;
1452 if (lcd_hwidth <= 0)
1453 lcd_hwidth = DEFAULT_LCD_HWIDTH;
1454 if (lcd_height <= 0)
1455 lcd_height = DEFAULT_LCD_HEIGHT;
1457 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */
1458 lcd_write_cmd = lcd_write_cmd_s;
1459 lcd_write_data = lcd_write_data_s;
1460 lcd_clear_fast = lcd_clear_fast_s;
1462 if (lcd_cl_pin == PIN_NOT_SET)
1463 lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1464 if (lcd_da_pin == PIN_NOT_SET)
1465 lcd_da_pin = DEFAULT_LCD_PIN_SDA;
1467 } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
1468 lcd_write_cmd = lcd_write_cmd_p8;
1469 lcd_write_data = lcd_write_data_p8;
1470 lcd_clear_fast = lcd_clear_fast_p8;
1472 if (lcd_e_pin == PIN_NOT_SET)
1473 lcd_e_pin = DEFAULT_LCD_PIN_E;
1474 if (lcd_rs_pin == PIN_NOT_SET)
1475 lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1476 if (lcd_rw_pin == PIN_NOT_SET)
1477 lcd_rw_pin = DEFAULT_LCD_PIN_RW;
1478 } else {
1479 lcd_write_cmd = lcd_write_cmd_tilcd;
1480 lcd_write_data = lcd_write_data_tilcd;
1481 lcd_clear_fast = lcd_clear_fast_tilcd;
1484 if (lcd_bl_pin == PIN_NOT_SET)
1485 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1487 if (lcd_e_pin == PIN_NOT_SET)
1488 lcd_e_pin = PIN_NONE;
1489 if (lcd_rs_pin == PIN_NOT_SET)
1490 lcd_rs_pin = PIN_NONE;
1491 if (lcd_rw_pin == PIN_NOT_SET)
1492 lcd_rw_pin = PIN_NONE;
1493 if (lcd_bl_pin == PIN_NOT_SET)
1494 lcd_bl_pin = PIN_NONE;
1495 if (lcd_cl_pin == PIN_NOT_SET)
1496 lcd_cl_pin = PIN_NONE;
1497 if (lcd_da_pin == PIN_NOT_SET)
1498 lcd_da_pin = PIN_NONE;
1500 if (lcd_charset < 0)
1501 lcd_charset = DEFAULT_LCD_CHARSET;
1503 if (lcd_charset == LCD_CHARSET_KS0074)
1504 lcd_char_conv = lcd_char_conv_ks0074;
1505 else
1506 lcd_char_conv = NULL;
1508 if (lcd_bl_pin != PIN_NONE)
1509 init_scan_timer();
1511 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1512 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1513 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1514 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1515 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1516 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1517 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1518 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1519 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1520 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1521 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1522 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
1524 /* before this line, we must NOT send anything to the display.
1525 * Since lcd_init_display() needs to write data, we have to
1526 * enable mark the LCD initialized just before. */
1527 lcd_initialized = 1;
1528 lcd_init_display();
1530 /* display a short message */
1531 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1532 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1533 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
1534 #endif
1535 #else
1536 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1537 PANEL_VERSION);
1538 #endif
1539 lcd_addr_x = lcd_addr_y = 0;
1540 /* clear the display on the next device opening */
1541 lcd_must_clear = 1;
1542 lcd_gotoxy();
1546 * These are the file operation function for user access to /dev/keypad
1549 static ssize_t keypad_read(struct file *file,
1550 char *buf, size_t count, loff_t *ppos)
1553 unsigned i = *ppos;
1554 char *tmp = buf;
1556 if (keypad_buflen == 0) {
1557 if (file->f_flags & O_NONBLOCK)
1558 return -EAGAIN;
1560 interruptible_sleep_on(&keypad_read_wait);
1561 if (signal_pending(current))
1562 return -EINTR;
1565 for (; count-- > 0 && (keypad_buflen > 0);
1566 ++i, ++tmp, --keypad_buflen) {
1567 put_user(keypad_buffer[keypad_start], tmp);
1568 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1570 *ppos = i;
1572 return tmp - buf;
1575 static int keypad_open(struct inode *inode, struct file *file)
1578 if (keypad_open_cnt)
1579 return -EBUSY; /* open only once at a time */
1581 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1582 return -EPERM;
1584 keypad_buflen = 0; /* flush the buffer on opening */
1585 keypad_open_cnt++;
1586 return 0;
1589 static int keypad_release(struct inode *inode, struct file *file)
1591 keypad_open_cnt--;
1592 return 0;
1595 static const struct file_operations keypad_fops = {
1596 .read = keypad_read, /* read */
1597 .open = keypad_open, /* open */
1598 .release = keypad_release, /* close */
1601 static struct miscdevice keypad_dev = {
1602 KEYPAD_MINOR,
1603 "keypad",
1604 &keypad_fops
1607 static void keypad_send_key(char *string, int max_len)
1609 if (init_in_progress)
1610 return;
1612 /* send the key to the device only if a process is attached to it. */
1613 if (keypad_open_cnt > 0) {
1614 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1615 keypad_buffer[(keypad_start + keypad_buflen++) %
1616 KEYPAD_BUFFER] = *string++;
1618 wake_up_interruptible(&keypad_read_wait);
1622 /* this function scans all the bits involving at least one logical signal,
1623 * and puts the results in the bitfield "phys_read" (one bit per established
1624 * contact), and sets "phys_read_prev" to "phys_read".
1626 * Note: to debounce input signals, we will only consider as switched a signal
1627 * which is stable across 2 measures. Signals which are different between two
1628 * reads will be kept as they previously were in their logical form (phys_prev).
1629 * A signal which has just switched will have a 1 in
1630 * (phys_read ^ phys_read_prev).
1632 static void phys_scan_contacts(void)
1634 int bit, bitval;
1635 char oldval;
1636 char bitmask;
1637 char gndmask;
1639 phys_prev = phys_curr;
1640 phys_read_prev = phys_read;
1641 phys_read = 0; /* flush all signals */
1643 /* keep track of old value, with all outputs disabled */
1644 oldval = r_dtr(pprt) | scan_mask_o;
1645 /* activate all keyboard outputs (active low) */
1646 w_dtr(pprt, oldval & ~scan_mask_o);
1648 /* will have a 1 for each bit set to gnd */
1649 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1650 /* disable all matrix signals */
1651 w_dtr(pprt, oldval);
1653 /* now that all outputs are cleared, the only active input bits are
1654 * directly connected to the ground
1657 /* 1 for each grounded input */
1658 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1660 /* grounded inputs are signals 40-44 */
1661 phys_read |= (pmask_t) gndmask << 40;
1663 if (bitmask != gndmask) {
1664 /* since clearing the outputs changed some inputs, we know
1665 * that some input signals are currently tied to some outputs.
1666 * So we'll scan them.
1668 for (bit = 0; bit < 8; bit++) {
1669 bitval = 1 << bit;
1671 if (!(scan_mask_o & bitval)) /* skip unused bits */
1672 continue;
1674 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1675 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1676 phys_read |= (pmask_t) bitmask << (5 * bit);
1678 w_dtr(pprt, oldval); /* disable all outputs */
1680 /* this is easy: use old bits when they are flapping,
1681 * use new ones when stable */
1682 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1683 (phys_read & ~(phys_read ^ phys_read_prev));
1686 static inline int input_state_high(struct logical_input *input)
1689 if ((phys_curr & input->mask) == input->value) {
1690 if ((input->type == INPUT_TYPE_STD) &&
1691 (input->high_timer == 0)) {
1692 input->high_timer++;
1693 if (input->u.std.press_fct != NULL)
1694 input->u.std.press_fct(input->u.std.press_data);
1695 } else if (input->type == INPUT_TYPE_KBD) {
1696 /* will turn on the light */
1697 keypressed = 1;
1699 if (input->high_timer == 0) {
1700 char *press_str = input->u.kbd.press_str;
1701 if (press_str[0])
1702 keypad_send_key(press_str,
1703 sizeof(press_str));
1706 if (input->u.kbd.repeat_str[0]) {
1707 char *repeat_str = input->u.kbd.repeat_str;
1708 if (input->high_timer >= KEYPAD_REP_START) {
1709 input->high_timer -= KEYPAD_REP_DELAY;
1710 keypad_send_key(repeat_str,
1711 sizeof(repeat_str));
1713 /* we will need to come back here soon */
1714 inputs_stable = 0;
1717 if (input->high_timer < 255)
1718 input->high_timer++;
1720 return 1;
1721 } else {
1722 /* else signal falling down. Let's fall through. */
1723 input->state = INPUT_ST_FALLING;
1724 input->fall_timer = 0;
1726 return 0;
1729 static inline void input_state_falling(struct logical_input *input)
1732 if ((phys_curr & input->mask) == input->value) {
1733 if (input->type == INPUT_TYPE_KBD) {
1734 /* will turn on the light */
1735 keypressed = 1;
1737 if (input->u.kbd.repeat_str[0]) {
1738 char *repeat_str = input->u.kbd.repeat_str;
1739 if (input->high_timer >= KEYPAD_REP_START)
1740 input->high_timer -= KEYPAD_REP_DELAY;
1741 keypad_send_key(repeat_str,
1742 sizeof(repeat_str));
1743 /* we will need to come back here soon */
1744 inputs_stable = 0;
1747 if (input->high_timer < 255)
1748 input->high_timer++;
1750 input->state = INPUT_ST_HIGH;
1751 } else if (input->fall_timer >= input->fall_time) {
1752 /* call release event */
1753 if (input->type == INPUT_TYPE_STD) {
1754 void (*release_fct)(int) = input->u.std.release_fct;
1755 if (release_fct != NULL)
1756 release_fct(input->u.std.release_data);
1757 } else if (input->type == INPUT_TYPE_KBD) {
1758 char *release_str = input->u.kbd.release_str;
1759 if (release_str[0])
1760 keypad_send_key(release_str,
1761 sizeof(release_str));
1764 input->state = INPUT_ST_LOW;
1765 } else {
1766 input->fall_timer++;
1767 inputs_stable = 0;
1771 static void panel_process_inputs(void)
1773 struct list_head *item;
1774 struct logical_input *input;
1777 keypressed = 0;
1778 inputs_stable = 1;
1779 list_for_each(item, &logical_inputs) {
1780 input = list_entry(item, struct logical_input, list);
1782 switch (input->state) {
1783 case INPUT_ST_LOW:
1784 if ((phys_curr & input->mask) != input->value)
1785 break;
1786 /* if all needed ones were already set previously,
1787 * this means that this logical signal has been
1788 * activated by the releasing of another combined
1789 * signal, so we don't want to match.
1790 * eg: AB -(release B)-> A -(release A)-> 0 :
1791 * don't match A.
1793 if ((phys_prev & input->mask) == input->value)
1794 break;
1795 input->rise_timer = 0;
1796 input->state = INPUT_ST_RISING;
1797 /* no break here, fall through */
1798 case INPUT_ST_RISING:
1799 if ((phys_curr & input->mask) != input->value) {
1800 input->state = INPUT_ST_LOW;
1801 break;
1803 if (input->rise_timer < input->rise_time) {
1804 inputs_stable = 0;
1805 input->rise_timer++;
1806 break;
1808 input->high_timer = 0;
1809 input->state = INPUT_ST_HIGH;
1810 /* no break here, fall through */
1811 case INPUT_ST_HIGH:
1812 if (input_state_high(input))
1813 break;
1814 /* no break here, fall through */
1815 case INPUT_ST_FALLING:
1816 input_state_falling(input);
1821 static void panel_scan_timer(void)
1823 if (keypad_enabled && keypad_initialized) {
1824 if (spin_trylock(&pprt_lock)) {
1825 phys_scan_contacts();
1827 /* no need for the parport anymore */
1828 spin_unlock(&pprt_lock);
1831 if (!inputs_stable || phys_curr != phys_prev)
1832 panel_process_inputs();
1835 if (lcd_enabled && lcd_initialized) {
1836 if (keypressed) {
1837 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1838 lcd_backlight(1);
1839 light_tempo = FLASH_LIGHT_TEMPO;
1840 } else if (light_tempo > 0) {
1841 light_tempo--;
1842 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1843 lcd_backlight(0);
1847 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
1850 static void init_scan_timer(void)
1852 if (scan_timer.function != NULL)
1853 return; /* already started */
1855 init_timer(&scan_timer);
1856 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1857 scan_timer.data = 0;
1858 scan_timer.function = (void *)&panel_scan_timer;
1859 add_timer(&scan_timer);
1862 /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
1863 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1864 * corresponding to out and in bits respectively.
1865 * returns 1 if ok, 0 if error (in which case, nothing is written).
1867 static int input_name2mask(char *name, pmask_t *mask, pmask_t *value,
1868 char *imask, char *omask)
1870 static char sigtab[10] = "EeSsPpAaBb";
1871 char im, om;
1872 pmask_t m, v;
1874 om = im = m = v = 0ULL;
1875 while (*name) {
1876 int in, out, bit, neg;
1877 for (in = 0; (in < sizeof(sigtab)) &&
1878 (sigtab[in] != *name); in++)
1880 if (in >= sizeof(sigtab))
1881 return 0; /* input name not found */
1882 neg = (in & 1); /* odd (lower) names are negated */
1883 in >>= 1;
1884 im |= (1 << in);
1886 name++;
1887 if (isdigit(*name)) {
1888 out = *name - '0';
1889 om |= (1 << out);
1890 } else if (*name == '-')
1891 out = 8;
1892 else
1893 return 0; /* unknown bit name */
1895 bit = (out * 5) + in;
1897 m |= 1ULL << bit;
1898 if (!neg)
1899 v |= 1ULL << bit;
1900 name++;
1902 *mask = m;
1903 *value = v;
1904 if (imask)
1905 *imask |= im;
1906 if (omask)
1907 *omask |= om;
1908 return 1;
1911 /* tries to bind a key to the signal name <name>. The key will send the
1912 * strings <press>, <repeat>, <release> for these respective events.
1913 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
1915 static struct logical_input *panel_bind_key(char *name, char *press,
1916 char *repeat, char *release)
1918 struct logical_input *key;
1920 key = kzalloc(sizeof(struct logical_input), GFP_KERNEL);
1921 if (!key) {
1922 printk(KERN_ERR "panel: not enough memory\n");
1923 return NULL;
1925 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
1926 &scan_mask_o)) {
1927 kfree(key);
1928 return NULL;
1931 key->type = INPUT_TYPE_KBD;
1932 key->state = INPUT_ST_LOW;
1933 key->rise_time = 1;
1934 key->fall_time = 1;
1936 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1937 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1938 strncpy(key->u.kbd.release_str, release,
1939 sizeof(key->u.kbd.release_str));
1940 list_add(&key->list, &logical_inputs);
1941 return key;
1945 static void keypad_init(void)
1947 int keynum;
1948 init_waitqueue_head(&keypad_read_wait);
1949 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
1951 /* Let's create all known keys */
1953 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
1954 panel_bind_key(keypad_profile[keynum][0],
1955 keypad_profile[keynum][1],
1956 keypad_profile[keynum][2],
1957 keypad_profile[keynum][3]);
1960 init_scan_timer();
1961 keypad_initialized = 1;
1964 /**************************************************/
1965 /* device initialization */
1966 /**************************************************/
1968 static int panel_notify_sys(struct notifier_block *this, unsigned long code,
1969 void *unused)
1971 if (lcd_enabled && lcd_initialized) {
1972 switch (code) {
1973 case SYS_DOWN:
1974 panel_lcd_print
1975 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
1976 break;
1977 case SYS_HALT:
1978 panel_lcd_print
1979 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
1980 break;
1981 case SYS_POWER_OFF:
1982 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
1983 break;
1984 default:
1985 break;
1988 return NOTIFY_DONE;
1991 static struct notifier_block panel_notifier = {
1992 panel_notify_sys,
1993 NULL,
1997 static void panel_attach(struct parport *port)
1999 if (port->number != parport)
2000 return;
2002 if (pprt) {
2003 printk(KERN_ERR
2004 "panel_attach(): port->number=%d parport=%d, "
2005 "already registered !\n",
2006 port->number, parport);
2007 return;
2010 pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */
2011 NULL,
2012 /*PARPORT_DEV_EXCL */
2013 0, (void *)&pprt);
2014 if (pprt == NULL) {
2015 pr_err("panel_attach(): port->number=%d parport=%d, "
2016 "parport_register_device() failed\n",
2017 port->number, parport);
2018 return;
2021 if (parport_claim(pprt)) {
2022 printk(KERN_ERR
2023 "Panel: could not claim access to parport%d. "
2024 "Aborting.\n", parport);
2025 goto err_unreg_device;
2028 /* must init LCD first, just in case an IRQ from the keypad is
2029 * generated at keypad init
2031 if (lcd_enabled) {
2032 lcd_init();
2033 if (misc_register(&lcd_dev))
2034 goto err_unreg_device;
2037 if (keypad_enabled) {
2038 keypad_init();
2039 if (misc_register(&keypad_dev))
2040 goto err_lcd_unreg;
2042 return;
2044 err_lcd_unreg:
2045 if (lcd_enabled)
2046 misc_deregister(&lcd_dev);
2047 err_unreg_device:
2048 parport_unregister_device(pprt);
2049 pprt = NULL;
2052 static void panel_detach(struct parport *port)
2054 if (port->number != parport)
2055 return;
2057 if (!pprt) {
2058 printk(KERN_ERR
2059 "panel_detach(): port->number=%d parport=%d, "
2060 "nothing to unregister.\n",
2061 port->number, parport);
2062 return;
2065 if (keypad_enabled && keypad_initialized) {
2066 misc_deregister(&keypad_dev);
2067 keypad_initialized = 0;
2070 if (lcd_enabled && lcd_initialized) {
2071 misc_deregister(&lcd_dev);
2072 lcd_initialized = 0;
2075 parport_release(pprt);
2076 parport_unregister_device(pprt);
2077 pprt = NULL;
2080 static struct parport_driver panel_driver = {
2081 .name = "panel",
2082 .attach = panel_attach,
2083 .detach = panel_detach,
2086 /* init function */
2087 int panel_init(void)
2089 /* for backwards compatibility */
2090 if (keypad_type < 0)
2091 keypad_type = keypad_enabled;
2093 if (lcd_type < 0)
2094 lcd_type = lcd_enabled;
2096 if (parport < 0)
2097 parport = DEFAULT_PARPORT;
2099 /* take care of an eventual profile */
2100 switch (profile) {
2101 case PANEL_PROFILE_CUSTOM:
2102 /* custom profile */
2103 if (keypad_type < 0)
2104 keypad_type = DEFAULT_KEYPAD;
2105 if (lcd_type < 0)
2106 lcd_type = DEFAULT_LCD;
2107 break;
2108 case PANEL_PROFILE_OLD:
2109 /* 8 bits, 2*16, old keypad */
2110 if (keypad_type < 0)
2111 keypad_type = KEYPAD_TYPE_OLD;
2112 if (lcd_type < 0)
2113 lcd_type = LCD_TYPE_OLD;
2114 if (lcd_width < 0)
2115 lcd_width = 16;
2116 if (lcd_hwidth < 0)
2117 lcd_hwidth = 16;
2118 break;
2119 case PANEL_PROFILE_NEW:
2120 /* serial, 2*16, new keypad */
2121 if (keypad_type < 0)
2122 keypad_type = KEYPAD_TYPE_NEW;
2123 if (lcd_type < 0)
2124 lcd_type = LCD_TYPE_KS0074;
2125 break;
2126 case PANEL_PROFILE_HANTRONIX:
2127 /* 8 bits, 2*16 hantronix-like, no keypad */
2128 if (keypad_type < 0)
2129 keypad_type = KEYPAD_TYPE_NONE;
2130 if (lcd_type < 0)
2131 lcd_type = LCD_TYPE_HANTRONIX;
2132 break;
2133 case PANEL_PROFILE_NEXCOM:
2134 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2135 if (keypad_type < 0)
2136 keypad_type = KEYPAD_TYPE_NEXCOM;
2137 if (lcd_type < 0)
2138 lcd_type = LCD_TYPE_NEXCOM;
2139 break;
2140 case PANEL_PROFILE_LARGE:
2141 /* 8 bits, 2*40, old keypad */
2142 if (keypad_type < 0)
2143 keypad_type = KEYPAD_TYPE_OLD;
2144 if (lcd_type < 0)
2145 lcd_type = LCD_TYPE_OLD;
2146 break;
2149 lcd_enabled = (lcd_type > 0);
2150 keypad_enabled = (keypad_type > 0);
2152 switch (keypad_type) {
2153 case KEYPAD_TYPE_OLD:
2154 keypad_profile = old_keypad_profile;
2155 break;
2156 case KEYPAD_TYPE_NEW:
2157 keypad_profile = new_keypad_profile;
2158 break;
2159 case KEYPAD_TYPE_NEXCOM:
2160 keypad_profile = nexcom_keypad_profile;
2161 break;
2162 default:
2163 keypad_profile = NULL;
2164 break;
2167 /* tells various subsystems about the fact that we are initializing */
2168 init_in_progress = 1;
2170 if (parport_register_driver(&panel_driver)) {
2171 printk(KERN_ERR
2172 "Panel: could not register with parport. Aborting.\n");
2173 return -EIO;
2176 if (!lcd_enabled && !keypad_enabled) {
2177 /* no device enabled, let's release the parport */
2178 if (pprt) {
2179 parport_release(pprt);
2180 parport_unregister_device(pprt);
2181 pprt = NULL;
2183 parport_unregister_driver(&panel_driver);
2184 printk(KERN_ERR "Panel driver version " PANEL_VERSION
2185 " disabled.\n");
2186 return -ENODEV;
2189 register_reboot_notifier(&panel_notifier);
2191 if (pprt)
2192 printk(KERN_INFO "Panel driver version " PANEL_VERSION
2193 " registered on parport%d (io=0x%lx).\n", parport,
2194 pprt->port->base);
2195 else
2196 printk(KERN_INFO "Panel driver version " PANEL_VERSION
2197 " not yet registered\n");
2198 /* tells various subsystems about the fact that initialization
2199 is finished */
2200 init_in_progress = 0;
2201 return 0;
2204 static int __init panel_init_module(void)
2206 return panel_init();
2209 static void __exit panel_cleanup_module(void)
2211 unregister_reboot_notifier(&panel_notifier);
2213 if (scan_timer.function != NULL)
2214 del_timer(&scan_timer);
2216 if (pprt != NULL) {
2217 if (keypad_enabled) {
2218 misc_deregister(&keypad_dev);
2219 keypad_initialized = 0;
2222 if (lcd_enabled) {
2223 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2224 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2225 misc_deregister(&lcd_dev);
2226 lcd_initialized = 0;
2229 /* TODO: free all input signals */
2230 parport_release(pprt);
2231 parport_unregister_device(pprt);
2232 pprt = NULL;
2234 parport_unregister_driver(&panel_driver);
2237 module_init(panel_init_module);
2238 module_exit(panel_cleanup_module);
2239 MODULE_AUTHOR("Willy Tarreau");
2240 MODULE_LICENSE("GPL");
2243 * Local variables:
2244 * c-indent-level: 4
2245 * tab-width: 8
2246 * End: