]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/panel/panel.c
Staging: panel: remove ifdefs and code for pre-2.6 kernels
[mv-sheeva.git] / drivers / staging / panel / panel.c
1 /*
2  * Front panel driver for Linux
3  * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
4  *
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.
9  *
10  * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
11  * connected to a parallel printer port.
12  *
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.
16  *
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.
20  *
21  * Several profiles are provided for commonly found LCD+keypad modules on the
22  * market, such as those found in Nexcom's appliances.
23  *
24  * FIXME:
25  *      - the initialization/deinitialization process is very dirty and should
26  *        be rewritten. It may even be buggy.
27  *
28  * TODO:
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
34  *
35  */
36
37 #include <linux/module.h>
38
39 #include <linux/types.h>
40 #include <linux/errno.h>
41 #include <linux/signal.h>
42 #include <linux/sched.h>
43 #include <linux/spinlock.h>
44 #include <linux/smp_lock.h>
45 #include <linux/interrupt.h>
46 #include <linux/miscdevice.h>
47 #include <linux/slab.h>
48 #include <linux/ioport.h>
49 #include <linux/fcntl.h>
50 #include <linux/init.h>
51 #include <linux/delay.h>
52 #include <linux/ctype.h>
53 #include <linux/parport.h>
54 #include <linux/version.h>
55 #include <linux/list.h>
56 #include <linux/notifier.h>
57 #include <linux/reboot.h>
58 #include <linux/utsrelease.h>
59
60 #include <linux/io.h>
61 #include <asm/uaccess.h>
62 #include <asm/system.h>
63
64 /* smartcard length */
65 #define SMARTCARD_BYTES         64
66 #define LCD_MINOR               156
67 #define KEYPAD_MINOR            185
68 #define SMARTCARD_MINOR         186
69
70 #define PANEL_VERSION           "0.9.5"
71
72 #define LCD_MAXBYTES            256     /* max burst write */
73
74 #define SMARTCARD_LOGICAL_DETECTOR      "S6"    /* D6 wired to SELECT = card inserted */
75
76 #define KEYPAD_BUFFER           64
77 #define INPUT_POLL_TIME         (HZ/50) /* poll the keyboard this every second */
78 #define KEYPAD_REP_START        (10)    /* a key starts to repeat after this times INPUT_POLL_TIME */
79 #define KEYPAD_REP_DELAY        (2)     /* a key repeats this times INPUT_POLL_TIME */
80
81 #define FLASH_LIGHT_TEMPO       (200)   /* keep the light on this times INPUT_POLL_TIME for each flash */
82
83 /* converts an r_str() input to an active high, bits string : 000BAOSE */
84 #define PNL_PINPUT(a)           ((((unsigned char)(a)) ^ 0x7F) >> 3)
85
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 */
91
92 #define PNL_PBIDIR              0x20    /* bi-directional ports */
93 #define PNL_PINTEN              0x10    /* high to read data in or-ed with data out */
94 #define PNL_PSELECP             0x08    /* inverted output, active low */
95 #define PNL_PINITP              0x04    /* direct output, active low */
96 #define PNL_PAUTOLF             0x02    /* inverted output, active low */
97 #define PNL_PSTROBE             0x01    /* inverted output */
98
99 #define PNL_PD0                 0x01
100 #define PNL_PD1                 0x02
101 #define PNL_PD2                 0x04
102 #define PNL_PD3                 0x08
103 #define PNL_PD4                 0x10
104 #define PNL_PD5                 0x20
105 #define PNL_PD6                 0x40
106 #define PNL_PD7                 0x80
107
108 #define PIN_NONE                0
109 #define PIN_STROBE              1
110 #define PIN_D0                  2
111 #define PIN_D1                  3
112 #define PIN_D2                  4
113 #define PIN_D3                  5
114 #define PIN_D4                  6
115 #define PIN_D5                  7
116 #define PIN_D6                  8
117 #define PIN_D7                  9
118 #define PIN_AUTOLF              14
119 #define PIN_INITP               16
120 #define PIN_SELECP              17
121 #define PIN_NOT_SET             127
122
123 /* some smartcard-specific signals */
124 #define PNL_SC_IO               PNL_PD1 /* Warning! inverted output, 0=highZ */
125 #define PNL_SC_RST              PNL_PD2
126 #define PNL_SC_CLK              PNL_PD3
127 #define PNL_SC_RW               PNL_PD4
128 #define PNL_SC_ENA              PNL_PINITP
129 #define PNL_SC_IOR              PNL_PACK
130 #define PNL_SC_BITS             (PNL_SC_IO | PNL_SC_RST | PNL_SC_CLK | PNL_SC_RW)
131
132 #define LCD_FLAG_S              0x0001
133 #define LCD_FLAG_ID             0x0002
134 #define LCD_FLAG_B              0x0004  /* blink on */
135 #define LCD_FLAG_C              0x0008  /* cursor on */
136 #define LCD_FLAG_D              0x0010  /* display on */
137 #define LCD_FLAG_F              0x0020  /* large font mode */
138 #define LCD_FLAG_N              0x0040  /* 2-rows mode */
139 #define LCD_FLAG_L              0x0080  /* backlight enabled */
140
141 #define LCD_ESCAPE_LEN          24      /* 24 chars max for an LCD escape command */
142 #define LCD_ESCAPE_CHAR 27      /* use char 27 for escape command */
143
144 /* macros to simplify use of the parallel port */
145 #define r_ctr(x)        (parport_read_control((x)->port))
146 #define r_dtr(x)        (parport_read_data((x)->port))
147 #define r_str(x)        (parport_read_status((x)->port))
148 #define w_ctr(x, y)     do { parport_write_control((x)->port, (y)); } while (0)
149 #define w_dtr(x, y)     do { parport_write_data((x)->port, (y)); } while (0)
150
151 /* this defines which bits are to be used and which ones to be ignored */
152 static __u8 scan_mask_o;        /* logical or of the output bits involved in the scan matrix */
153 static __u8 scan_mask_i;        /* logical or of the input bits involved in the scan matrix */
154
155 typedef __u64 pmask_t;
156
157 enum input_type {
158         INPUT_TYPE_STD,
159         INPUT_TYPE_KBD,
160 };
161
162 enum input_state {
163         INPUT_ST_LOW,
164         INPUT_ST_RISING,
165         INPUT_ST_HIGH,
166         INPUT_ST_FALLING,
167 };
168
169 struct logical_input {
170         struct list_head list;
171         pmask_t mask;
172         pmask_t value;
173         enum input_type type;
174         enum input_state state;
175         __u8 rise_time, fall_time;
176         __u8 rise_timer, fall_timer, high_timer;
177
178         union {
179                 struct {        /* this structure is valid when type == INPUT_TYPE_STD */
180                         void (*press_fct) (int);
181                         void (*release_fct) (int);
182                         int press_data;
183                         int release_data;
184                 } std;
185                 struct {        /* this structure is valid when type == INPUT_TYPE_KBD */
186                         /* strings can be full-length (ie. non null-terminated) */
187                         char press_str[sizeof(void *) + sizeof(int)];
188                         char repeat_str[sizeof(void *) + sizeof(int)];
189                         char release_str[sizeof(void *) + sizeof(int)];
190                 } kbd;
191         } u;
192 };
193
194 LIST_HEAD(logical_inputs);      /* list of all defined logical inputs */
195
196 /* physical contacts history
197  * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
198  * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
199  * corresponds to the ground.
200  * Within each group, bits are stored in the same order as read on the port :
201  * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
202  * So, each __u64 (or pmask_t) is represented like this :
203  * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
204  * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
205  */
206 static pmask_t phys_read;       /* what has just been read from the I/O ports */
207 static pmask_t phys_read_prev;  /* previous phys_read */
208 static pmask_t phys_curr;       /* stabilized phys_read (phys_read|phys_read_prev) */
209 static pmask_t phys_prev;       /* previous phys_curr */
210 static char inputs_stable;      /* 0 means that at least one logical signal needs be computed */
211
212 /* these variables are specific to the smartcard */
213 static __u8 smartcard_data[SMARTCARD_BYTES];
214 static int smartcard_ptr;       /* pointer to half bytes in smartcard_data */
215
216 /* these variables are specific to the keypad */
217 static char keypad_buffer[KEYPAD_BUFFER];
218 static int keypad_buflen;
219 static int keypad_start;
220 static char keypressed;
221 static wait_queue_head_t keypad_read_wait;
222 static wait_queue_head_t smartcard_read_wait;
223
224 /* lcd-specific variables */
225 static unsigned long int lcd_flags;     /* contains the LCD config state */
226 static unsigned long int lcd_addr_x;    /* contains the LCD X offset */
227 static unsigned long int lcd_addr_y;    /* contains the LCD Y offset */
228 static char lcd_escape[LCD_ESCAPE_LEN + 1];     /* current escape sequence, 0 terminated */
229 static int lcd_escape_len = -1; /* not in escape state. >=0 = escape cmd len */
230
231 /*
232  * Bit masks to convert LCD signals to parallel port outputs.
233  * _d_ are values for data port, _c_ are for control port.
234  * [0] = signal OFF, [1] = signal ON, [2] = mask
235  */
236 #define BIT_CLR         0
237 #define BIT_SET         1
238 #define BIT_MSK         2
239 #define BIT_STATES      3
240 /*
241  * one entry for each bit on the LCD
242  */
243 #define LCD_BIT_E       0
244 #define LCD_BIT_RS      1
245 #define LCD_BIT_RW      2
246 #define LCD_BIT_BL      3
247 #define LCD_BIT_CL      4
248 #define LCD_BIT_DA      5
249 #define LCD_BITS        6
250
251 /*
252  * each bit can be either connected to a DATA or CTRL port
253  */
254 #define LCD_PORT_C      0
255 #define LCD_PORT_D      1
256 #define LCD_PORTS       2
257
258 static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
259
260 /*
261  * LCD protocols
262  */
263 #define LCD_PROTO_PARALLEL      0
264 #define LCD_PROTO_SERIAL        1
265
266 /*
267  * LCD character sets
268  */
269 #define LCD_CHARSET_NORMAL      0
270 #define LCD_CHARSET_KS0074      1
271
272 /*
273  * LCD types
274  */
275 #define LCD_TYPE_NONE           0
276 #define LCD_TYPE_OLD            1
277 #define LCD_TYPE_KS0074         2
278 #define LCD_TYPE_HANTRONIX      3
279 #define LCD_TYPE_NEXCOM         4
280 #define LCD_TYPE_CUSTOM         5
281
282 /*
283  * keypad types
284  */
285 #define KEYPAD_TYPE_NONE        0
286 #define KEYPAD_TYPE_OLD         1
287 #define KEYPAD_TYPE_NEW         2
288 #define KEYPAD_TYPE_NEXCOM      3
289
290 /*
291  * panel profiles
292  */
293 #define PANEL_PROFILE_CUSTOM    0
294 #define PANEL_PROFILE_OLD       1
295 #define PANEL_PROFILE_NEW       2
296 #define PANEL_PROFILE_HANTRONIX 3
297 #define PANEL_PROFILE_NEXCOM    4
298 #define PANEL_PROFILE_LARGE     5
299
300 /*
301  * Construct custom config from the kernel's configuration
302  */
303 #define DEFAULT_PROFILE         PANEL_PROFILE_LARGE
304 #define DEFAULT_PARPORT         0
305 #define DEFAULT_LCD             LCD_TYPE_OLD
306 #define DEFAULT_KEYPAD          KEYPAD_TYPE_OLD
307 #define DEFAULT_SMARTCARD       0
308 #define DEFAULT_LCD_WIDTH       40
309 #define DEFAULT_LCD_BWIDTH      40
310 #define DEFAULT_LCD_HWIDTH      64
311 #define DEFAULT_LCD_HEIGHT      2
312 #define DEFAULT_LCD_PROTO       LCD_PROTO_PARALLEL
313
314 #define DEFAULT_LCD_PIN_E       PIN_AUTOLF
315 #define DEFAULT_LCD_PIN_RS      PIN_SELECP
316 #define DEFAULT_LCD_PIN_RW      PIN_INITP
317 #define DEFAULT_LCD_PIN_SCL     PIN_STROBE
318 #define DEFAULT_LCD_PIN_SDA     PIN_D0
319 #define DEFAULT_LCD_PIN_BL      PIN_NOT_SET
320 #define DEFAULT_LCD_CHARSET     LCD_CHARSET_NORMAL
321
322 #ifdef CONFIG_PANEL_PROFILE
323 #undef DEFAULT_PROFILE
324 #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
325 #endif
326
327 #ifdef CONFIG_PANEL_PARPORT
328 #undef DEFAULT_PARPORT
329 #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
330 #endif
331
332 #if DEFAULT_PROFILE == 0        /* custom */
333 #ifdef CONFIG_PANEL_KEYPAD
334 #undef DEFAULT_KEYPAD
335 #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD
336 #endif
337
338 #ifdef CONFIG_PANEL_SMARTCARD
339 #undef DEFAULT_SMARTCARD
340 #define DEFAULT_SMARTCARD 1
341 #endif
342
343 #ifdef CONFIG_PANEL_LCD
344 #undef DEFAULT_LCD
345 #define DEFAULT_LCD CONFIG_PANEL_LCD
346 #endif
347
348 #ifdef CONFIG_PANEL_LCD_WIDTH
349 #undef DEFAULT_LCD_WIDTH
350 #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
351 #endif
352
353 #ifdef CONFIG_PANEL_LCD_BWIDTH
354 #undef DEFAULT_LCD_BWIDTH
355 #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
356 #endif
357
358 #ifdef CONFIG_PANEL_LCD_HWIDTH
359 #undef DEFAULT_LCD_HWIDTH
360 #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
361 #endif
362
363 #ifdef CONFIG_PANEL_LCD_HEIGHT
364 #undef DEFAULT_LCD_HEIGHT
365 #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
366 #endif
367
368 #ifdef CONFIG_PANEL_LCD_PROTO
369 #undef DEFAULT_LCD_PROTO
370 #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
371 #endif
372
373 #ifdef CONFIG_PANEL_LCD_PIN_E
374 #undef DEFAULT_LCD_PIN_E
375 #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
376 #endif
377
378 #ifdef CONFIG_PANEL_LCD_PIN_RS
379 #undef DEFAULT_LCD_PIN_RS
380 #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
381 #endif
382
383 #ifdef CONFIG_PANEL_LCD_PIN_RW
384 #undef DEFAULT_LCD_PIN_RW
385 #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
386 #endif
387
388 #ifdef CONFIG_PANEL_LCD_PIN_SCL
389 #undef DEFAULT_LCD_PIN_SCL
390 #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
391 #endif
392
393 #ifdef CONFIG_PANEL_LCD_PIN_SDA
394 #undef DEFAULT_LCD_PIN_SDA
395 #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
396 #endif
397
398 #ifdef CONFIG_PANEL_LCD_PIN_BL
399 #undef DEFAULT_LCD_PIN_BL
400 #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
401 #endif
402
403 #ifdef CONFIG_PANEL_LCD_CHARSET
404 #undef DEFAULT_LCD_CHARSET
405 #define DEFAULT_LCD_CHARSET
406 #endif
407
408 #endif /* DEFAULT_PROFILE == 0 */
409
410 /* global variables */
411 static int smartcard_open_cnt;  /* #times opened */
412 static int keypad_open_cnt;     /* #times opened */
413 static int lcd_open_cnt;        /* #times opened */
414 static struct pardevice *pprt;
415
416 static int lcd_initialized;
417 static int keypad_initialized;
418 static int smartcard_initialized;
419
420 static int light_tempo;
421
422 static char lcd_must_clear;
423 static char lcd_left_shift;
424 static char init_in_progress;
425
426 static void (*lcd_write_cmd) (int);
427 static void (*lcd_write_data) (int);
428 static void (*lcd_clear_fast) (void);
429
430 static DEFINE_SPINLOCK(pprt_lock);
431 static struct timer_list scan_timer;
432
433 MODULE_DESCRIPTION("Generic parallel port LCD/Keypad/Smartcard driver");
434
435 static int parport = -1;
436 module_param(parport, int, 0000);
437 MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
438
439 static int lcd_height = -1;
440 module_param(lcd_height, int, 0000);
441 MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
442
443 static int lcd_width = -1;
444 module_param(lcd_width, int, 0000);
445 MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
446
447 static int lcd_bwidth = -1;     /* internal buffer width (usually 40) */
448 module_param(lcd_bwidth, int, 0000);
449 MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
450
451 static int lcd_hwidth = -1;     /* hardware buffer width (usually 64) */
452 module_param(lcd_hwidth, int, 0000);
453 MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
454
455 static int lcd_enabled = -1;
456 module_param(lcd_enabled, int, 0000);
457 MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
458
459 static int keypad_enabled = -1;
460 module_param(keypad_enabled, int, 0000);
461 MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
462
463 static int lcd_type = -1;
464 module_param(lcd_type, int, 0000);
465 MODULE_PARM_DESC(lcd_type,
466                  "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
467
468 static int lcd_proto = -1;
469 module_param(lcd_proto, int, 0000);
470 MODULE_PARM_DESC(lcd_proto, "LCD communication: 0=parallel (//), 1=serial");
471
472 static int lcd_charset = -1;
473 module_param(lcd_charset, int, 0000);
474 MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
475
476 static int keypad_type = -1;
477 module_param(keypad_type, int, 0000);
478 MODULE_PARM_DESC(keypad_type,
479                  "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
480
481 static int smartcard_enabled = -1;
482 module_param(smartcard_enabled, int, 0000);
483 MODULE_PARM_DESC(smartcard_enabled,
484                  "Smartcard reader: 0=disabled (default), 1=enabled");
485
486 static int profile = DEFAULT_PROFILE;
487 module_param(profile, int, 0000);
488 MODULE_PARM_DESC(profile,
489                  "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; 4=16x2 nexcom; default=40x2, old kp");
490
491 /*
492  * These are the parallel port pins the LCD control signals are connected to.
493  * Set this to 0 if the signal is not used. Set it to its opposite value
494  * (negative) if the signal is negated. -MAXINT is used to indicate that the
495  * pin has not been explicitly specified.
496  *
497  * WARNING! no check will be performed about collisions with keypad/smartcard !
498  */
499
500 static int lcd_e_pin  = PIN_NOT_SET;
501 module_param(lcd_e_pin, int, 0000);
502 MODULE_PARM_DESC(lcd_e_pin,
503                  "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
504
505 static int lcd_rs_pin = PIN_NOT_SET;
506 module_param(lcd_rs_pin, int, 0000);
507 MODULE_PARM_DESC(lcd_rs_pin,
508                  "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
509
510 static int lcd_rw_pin = PIN_NOT_SET;
511 module_param(lcd_rw_pin, int, 0000);
512 MODULE_PARM_DESC(lcd_rw_pin,
513                  "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
514
515 static int lcd_bl_pin = PIN_NOT_SET;
516 module_param(lcd_bl_pin, int, 0000);
517 MODULE_PARM_DESC(lcd_bl_pin,
518                  "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
519
520 static int lcd_da_pin = PIN_NOT_SET;
521 module_param(lcd_da_pin, int, 0000);
522 MODULE_PARM_DESC(lcd_da_pin,
523                  "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
524
525 static int lcd_cl_pin = PIN_NOT_SET;
526 module_param(lcd_cl_pin, int, 0000);
527 MODULE_PARM_DESC(lcd_cl_pin,
528                  "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
529
530 static unsigned char *lcd_char_conv;
531
532 /* for some LCD drivers (ks0074) we need a charset conversion table. */
533 static unsigned char lcd_char_conv_ks0074[256] = {
534         /*          0|8   1|9   2|A   3|B   4|C   5|D   6|E   7|F */
535         /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
536         /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
537         /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
538         /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
539         /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
540         /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
541         /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
542         /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
543         /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
544         /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
545         /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
546         /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
547         /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
548         /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
549         /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
550         /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
551         /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
552         /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
553         /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
554         /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
555         /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
556         /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
557         /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
558         /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
559         /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
560         /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
561         /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
562         /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
563         /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
564         /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
565         /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
566         /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
567 };
568
569 char old_keypad_profile[][4][9] = {
570         {"S0", "Left\n", "Left\n", ""},
571         {"S1", "Down\n", "Down\n", ""},
572         {"S2", "Up\n", "Up\n", ""},
573         {"S3", "Right\n", "Right\n", ""},
574         {"S4", "Esc\n", "Esc\n", ""},
575         {"S5", "Ret\n", "Ret\n", ""},
576         {"", "", "", ""}
577 };
578
579 /* signals, press, repeat, release */
580 char new_keypad_profile[][4][9] = {
581         {"S0", "Left\n", "Left\n", ""},
582         {"S1", "Down\n", "Down\n", ""},
583         {"S2", "Up\n", "Up\n", ""},
584         {"S3", "Right\n", "Right\n", ""},
585         {"S4s5", "", "Esc\n", "Esc\n"},
586         {"s4S5", "", "Ret\n", "Ret\n"},
587         {"S4S5", "Help\n", "", ""},
588         /* add new signals above this line */
589         {"", "", "", ""}
590 };
591
592 /* signals, press, repeat, release */
593 char nexcom_keypad_profile[][4][9] = {
594         {"a-p-e-", "Down\n", "Down\n", ""},
595         {"a-p-E-", "Ret\n", "Ret\n", ""},
596         {"a-P-E-", "Esc\n", "Esc\n", ""},
597         {"a-P-e-", "Up\n", "Up\n", ""},
598         /* add new signals above this line */
599         {"", "", "", ""}
600 };
601
602 static char (*keypad_profile)[4][9] = old_keypad_profile;
603
604 /* FIXME: this should be converted to a bit array containing signals states */
605 static struct {
606         unsigned char e;        /* parallel LCD E   (data latch on falling edge) */
607         unsigned char rs;       /* parallel LCD RS  (0 = cmd, 1 = data) */
608         unsigned char rw;       /* parallel LCD R/W (0 = W, 1 = R) */
609         unsigned char bl;       /* parallel LCD backlight (0 = off, 1 = on) */
610         unsigned char cl;       /* serial LCD clock (latch on rising edge) */
611         unsigned char da;       /* serial LCD data */
612 } bits;
613
614 static void init_scan_timer(void);
615
616 /* sets data port bits according to current signals values */
617 static int set_data_bits(void)
618 {
619         int val, bit;
620
621         val = r_dtr(pprt);
622         for (bit = 0; bit < LCD_BITS; bit++)
623                 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
624
625         val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
626             | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
627             | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
628             | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
629             | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
630             | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
631
632         w_dtr(pprt, val);
633         return val;
634 }
635
636 /* sets ctrl port bits according to current signals values */
637 static int set_ctrl_bits(void)
638 {
639         int val, bit;
640
641         val = r_ctr(pprt);
642         for (bit = 0; bit < LCD_BITS; bit++)
643                 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
644
645         val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
646             | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
647             | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
648             | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
649             | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
650             | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
651
652         w_ctr(pprt, val);
653         return val;
654 }
655
656 /* sets ctrl & data port bits according to current signals values */
657 static void set_bits(void)
658 {
659         set_data_bits();
660         set_ctrl_bits();
661 }
662
663 /*
664  * Converts a parallel port pin (from -25 to 25) to data and control ports
665  * masks, and data and control port bits. The signal will be considered
666  * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
667  *
668  * Result will be used this way :
669  *   out(dport, in(dport) & d_val[2] | d_val[signal_state])
670  *   out(cport, in(cport) & c_val[2] | c_val[signal_state])
671  */
672 void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
673 {
674         int d_bit, c_bit, inv;
675
676         d_val[0] = c_val[0] = d_val[1] = c_val[1] = 0;
677         d_val[2] = c_val[2] = 0xFF;
678
679         if (pin == 0)
680                 return;
681
682         inv = (pin < 0);
683         if (inv)
684                 pin = -pin;
685
686         d_bit = c_bit = 0;
687
688         switch (pin) {
689         case PIN_STROBE:        /* strobe, inverted */
690                 c_bit = PNL_PSTROBE;
691                 inv = !inv;
692                 break;
693         case PIN_D0...PIN_D7:   /* D0 - D7 = 2 - 9 */
694                 d_bit = 1 << (pin - 2);
695                 break;
696         case PIN_AUTOLF:        /* autofeed, inverted */
697                 c_bit = PNL_PAUTOLF;
698                 inv = !inv;
699                 break;
700         case PIN_INITP: /* init, direct */
701                 c_bit = PNL_PINITP;
702                 break;
703         case PIN_SELECP:        /* select_in, inverted */
704                 c_bit = PNL_PSELECP;
705                 inv = !inv;
706                 break;
707         default:                /* unknown pin, ignore */
708                 break;
709         }
710
711         if (c_bit) {
712                 c_val[2] &= ~c_bit;
713                 c_val[!inv] = c_bit;
714         } else if (d_bit) {
715                 d_val[2] &= ~d_bit;
716                 d_val[!inv] = d_bit;
717         }
718 }
719
720 /* sleeps that many milliseconds with a reschedule */
721 static void long_sleep(int ms)
722 {
723
724         if (in_interrupt())
725                 mdelay(ms);
726         else {
727                 current->state = TASK_INTERRUPTIBLE;
728                 schedule_timeout((ms * HZ + 999) / 1000);
729         }
730 }
731
732 /* send a serial byte to the LCD panel. The caller is responsible for locking if needed. */
733 static void lcd_send_serial(int byte)
734 {
735         int bit;
736
737         /* the data bit is set on D0, and the clock on STROBE.
738          * LCD reads D0 on STROBE's rising edge.
739          */
740         for (bit = 0; bit < 8; bit++) {
741                 bits.cl = BIT_CLR;      /* CLK low */
742                 set_bits();
743                 bits.da = byte & 1;
744                 set_bits();
745                 udelay(2);      /* maintain the data during 2 us before CLK up */
746                 bits.cl = BIT_SET;      /* CLK high */
747                 set_bits();
748                 udelay(1);      /* maintain the strobe during 1 us */
749                 byte >>= 1;
750         }
751 }
752
753 /* turn the backlight on or off */
754 static void lcd_backlight(int on)
755 {
756         if (lcd_bl_pin == PIN_NONE)
757                 return;
758
759         /* The backlight is activated by seting the AUTOFEED line to +5V  */
760         spin_lock(&pprt_lock);
761         bits.bl = on;
762         set_bits();
763         spin_unlock(&pprt_lock);
764 }
765
766 /* send a command to the LCD panel in serial mode */
767 static void lcd_write_cmd_s(int cmd)
768 {
769         spin_lock(&pprt_lock);
770         lcd_send_serial(0x1F);  /* R/W=W, RS=0 */
771         lcd_send_serial(cmd & 0x0F);
772         lcd_send_serial((cmd >> 4) & 0x0F);
773         udelay(40);             /* the shortest command takes at least 40 us */
774         spin_unlock(&pprt_lock);
775 }
776
777 /* send data to the LCD panel in serial mode */
778 static void lcd_write_data_s(int data)
779 {
780         spin_lock(&pprt_lock);
781         lcd_send_serial(0x5F);  /* R/W=W, RS=1 */
782         lcd_send_serial(data & 0x0F);
783         lcd_send_serial((data >> 4) & 0x0F);
784         udelay(40);             /* the shortest data takes at least 40 us */
785         spin_unlock(&pprt_lock);
786 }
787
788 /* send a command to the LCD panel in 8 bits parallel mode */
789 static void lcd_write_cmd_p8(int cmd)
790 {
791         spin_lock(&pprt_lock);
792         /* present the data to the data port */
793         w_dtr(pprt, cmd);
794         udelay(20);             /* maintain the data during 20 us before the strobe */
795
796         bits.e = BIT_SET;
797         bits.rs = BIT_CLR;
798         bits.rw = BIT_CLR;
799         set_ctrl_bits();
800
801         udelay(40);             /* maintain the strobe during 40 us */
802
803         bits.e = BIT_CLR;
804         set_ctrl_bits();
805
806         udelay(120);            /* the shortest command takes at least 120 us */
807         spin_unlock(&pprt_lock);
808 }
809
810 /* send data to the LCD panel in 8 bits parallel mode */
811 static void lcd_write_data_p8(int data)
812 {
813         spin_lock(&pprt_lock);
814         /* present the data to the data port */
815         w_dtr(pprt, data);
816         udelay(20);             /* maintain the data during 20 us before the strobe */
817
818         bits.e = BIT_SET;
819         bits.rs = BIT_SET;
820         bits.rw = BIT_CLR;
821         set_ctrl_bits();
822
823         udelay(40);             /* maintain the strobe during 40 us */
824
825         bits.e = BIT_CLR;
826         set_ctrl_bits();
827
828         udelay(45);             /* the shortest data takes at least 45 us */
829         spin_unlock(&pprt_lock);
830 }
831
832 static void lcd_gotoxy(void)
833 {
834         lcd_write_cmd(0x80      /* set DDRAM address */
835                       | (lcd_addr_y ? lcd_hwidth : 0)
836                       /* we force the cursor to stay at the end of the line if it wants to go farther */
837                       | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
838                          (lcd_hwidth - 1) : lcd_bwidth - 1));
839 }
840
841 static void lcd_print(char c)
842 {
843         if (lcd_addr_x < lcd_bwidth) {
844                 if (lcd_char_conv != NULL)
845                         c = lcd_char_conv[(unsigned char)c];
846                 lcd_write_data(c);
847                 lcd_addr_x++;
848         }
849         /* prevents the cursor from wrapping onto the next line */
850         if (lcd_addr_x == lcd_bwidth)
851                 lcd_gotoxy();
852 }
853
854 /* fills the display with spaces and resets X/Y */
855 static void lcd_clear_fast_s(void)
856 {
857         int pos;
858         lcd_addr_x = lcd_addr_y = 0;
859         lcd_gotoxy();
860
861         spin_lock(&pprt_lock);
862         for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
863                 lcd_send_serial(0x5F);  /* R/W=W, RS=1 */
864                 lcd_send_serial(' ' & 0x0F);
865                 lcd_send_serial((' ' >> 4) & 0x0F);
866                 udelay(40);     /* the shortest data takes at least 40 us */
867         }
868         spin_unlock(&pprt_lock);
869
870         lcd_addr_x = lcd_addr_y = 0;
871         lcd_gotoxy();
872 }
873
874 /* fills the display with spaces and resets X/Y */
875 static void lcd_clear_fast_p8(void)
876 {
877         int pos;
878         lcd_addr_x = lcd_addr_y = 0;
879         lcd_gotoxy();
880
881         spin_lock(&pprt_lock);
882         for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
883                 /* present the data to the data port */
884                 w_dtr(pprt, ' ');
885                 udelay(20);     /* maintain the data during 20 us before the strobe */
886
887                 bits.e = BIT_SET;
888                 bits.rs = BIT_SET;
889                 bits.rw = BIT_CLR;
890                 set_ctrl_bits();
891
892                 udelay(40);     /* maintain the strobe during 40 us */
893
894                 bits.e = BIT_CLR;
895                 set_ctrl_bits();
896
897                 udelay(45);     /* the shortest data takes at least 45 us */
898         }
899         spin_unlock(&pprt_lock);
900
901         lcd_addr_x = lcd_addr_y = 0;
902         lcd_gotoxy();
903 }
904
905 /* clears the display and resets X/Y */
906 static void lcd_clear_display(void)
907 {
908         lcd_write_cmd(0x01);    /* clear display */
909         lcd_addr_x = lcd_addr_y = 0;
910         /* we must wait a few milliseconds (15) */
911         long_sleep(15);
912 }
913
914 static void lcd_init_display(void)
915 {
916
917         lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
918             | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
919
920         long_sleep(20);         /* wait 20 ms after power-up for the paranoid */
921
922         lcd_write_cmd(0x30);    /* 8bits, 1 line, small fonts */
923         long_sleep(10);
924         lcd_write_cmd(0x30);    /* 8bits, 1 line, small fonts */
925         long_sleep(10);
926         lcd_write_cmd(0x30);    /* 8bits, 1 line, small fonts */
927         long_sleep(10);
928
929         lcd_write_cmd(0x30      /* set font height and lines number */
930                       | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
931                       | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
932             );
933         long_sleep(10);
934
935         lcd_write_cmd(0x08);    /* display off, cursor off, blink off */
936         long_sleep(10);
937
938         lcd_write_cmd(0x08      /* set display mode */
939                       | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
940                       | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
941                       | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
942             );
943
944         lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
945
946         long_sleep(10);
947
948         lcd_write_cmd(0x06);    /* entry mode set : increment, cursor shifting */
949
950         lcd_clear_display();
951 }
952
953 /*
954  * These are the file operation function for user access to /dev/lcd
955  * This function can also be called from inside the kernel, by
956  * setting file and ppos to NULL.
957  *
958  */
959
960 static ssize_t lcd_write(struct file *file,
961                          const char *buf, size_t count, loff_t *ppos)
962 {
963
964         const char *tmp = buf;
965         char c;
966
967         for (; count-- > 0; (ppos ? (*ppos)++ : 0), ++tmp) {
968                 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
969                         schedule();     /* let's be a little nice with other processes that need some CPU */
970
971                 if (ppos == NULL && file == NULL)
972                         c = *tmp;       /* let's not use get_user() from the kernel ! */
973                 else if (get_user(c, tmp))
974                         return -EFAULT;
975
976                 /* first, we'll test if we're in escape mode */
977                 if ((c != '\n') && lcd_escape_len >= 0) {       /* yes, let's add this char to the buffer */
978                         lcd_escape[lcd_escape_len++] = c;
979                         lcd_escape[lcd_escape_len] = 0;
980                 } else {
981                         lcd_escape_len = -1;    /* aborts any previous escape sequence */
982
983                         switch (c) {
984                         case LCD_ESCAPE_CHAR:   /* start of an escape sequence */
985                                 lcd_escape_len = 0;
986                                 lcd_escape[lcd_escape_len] = 0;
987                                 break;
988                         case '\b':      /* go back one char and clear it */
989                                 if (lcd_addr_x > 0) {
990                                         if (lcd_addr_x < lcd_bwidth)    /* check if we're not at the end of the line */
991                                                 lcd_write_cmd(0x10);    /* back one char */
992                                         lcd_addr_x--;
993                                 }
994                                 lcd_write_data(' ');    /* replace with a space */
995                                 lcd_write_cmd(0x10);    /* back one char again */
996                                 break;
997                         case '\014':    /* quickly clear the display */
998                                 lcd_clear_fast();
999                                 break;
1000                         case '\n':      /* flush the remainder of the current line and go to the
1001                                            beginning of the next line */
1002                                 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1003                                         lcd_write_data(' ');
1004                                 lcd_addr_x = 0;
1005                                 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1006                                 lcd_gotoxy();
1007                                 break;
1008                         case '\r':      /* go to the beginning of the same line */
1009                                 lcd_addr_x = 0;
1010                                 lcd_gotoxy();
1011                                 break;
1012                         case '\t':      /* print a space instead of the tab */
1013                                 lcd_print(' ');
1014                                 break;
1015                         default:        /* simply print this char */
1016                                 lcd_print(c);
1017                                 break;
1018                         }
1019                 }
1020
1021                 /* now we'll see if we're in an escape mode and if the current
1022                    escape sequence can be understood.
1023                  */
1024                 if (lcd_escape_len >= 2) {      /* minimal length for an escape command */
1025                         int processed = 0;      /* 1 means the command has been processed */
1026
1027                         if (!strcmp(lcd_escape, "[2J")) {       /* Clear the display */
1028                                 lcd_clear_fast();       /* clear display */
1029                                 processed = 1;
1030                         } else if (!strcmp(lcd_escape, "[H")) { /* Cursor to home */
1031                                 lcd_addr_x = lcd_addr_y = 0;
1032                                 lcd_gotoxy();
1033                                 processed = 1;
1034                         }
1035                         /* codes starting with ^[[L */
1036                         else if ((lcd_escape_len >= 3) &&
1037                                  (lcd_escape[0] == '[') && (lcd_escape[1] == 'L')) {    /* LCD special codes */
1038
1039                                 char *esc = lcd_escape + 2;
1040                                 int oldflags = lcd_flags;
1041
1042                                 /* check for display mode flags */
1043                                 switch (*esc) {
1044                                 case 'D':       /* Display ON */
1045                                         lcd_flags |= LCD_FLAG_D;
1046                                         processed = 1;
1047                                         break;
1048                                 case 'd':       /* Display OFF */
1049                                         lcd_flags &= ~LCD_FLAG_D;
1050                                         processed = 1;
1051                                         break;
1052                                 case 'C':       /* Cursor ON */
1053                                         lcd_flags |= LCD_FLAG_C;
1054                                         processed = 1;
1055                                         break;
1056                                 case 'c':       /* Cursor OFF */
1057                                         lcd_flags &= ~LCD_FLAG_C;
1058                                         processed = 1;
1059                                         break;
1060                                 case 'B':       /* Blink ON */
1061                                         lcd_flags |= LCD_FLAG_B;
1062                                         processed = 1;
1063                                         break;
1064                                 case 'b':       /* Blink OFF */
1065                                         lcd_flags &= ~LCD_FLAG_B;
1066                                         processed = 1;
1067                                         break;
1068                                 case '+':       /* Back light ON */
1069                                         lcd_flags |= LCD_FLAG_L;
1070                                         processed = 1;
1071                                         break;
1072                                 case '-':       /* Back light OFF */
1073                                         lcd_flags &= ~LCD_FLAG_L;
1074                                         processed = 1;
1075                                         break;
1076                                 case '*':       /* flash back light using the keypad timer */
1077                                         if (scan_timer.function != NULL) {
1078                                                 if (light_tempo == 0
1079                                                     && ((lcd_flags & LCD_FLAG_L)
1080                                                         == 0))
1081                                                         lcd_backlight(1);
1082                                                 light_tempo = FLASH_LIGHT_TEMPO;
1083                                         }
1084                                         processed = 1;
1085                                         break;
1086                                 case 'f':       /* Small Font */
1087                                         lcd_flags &= ~LCD_FLAG_F;
1088                                         processed = 1;
1089                                         break;
1090                                 case 'F':       /* Large Font */
1091                                         lcd_flags |= LCD_FLAG_F;
1092                                         processed = 1;
1093                                         break;
1094                                 case 'n':       /* One Line */
1095                                         lcd_flags &= ~LCD_FLAG_N;
1096                                         processed = 1;
1097                                         break;
1098                                 case 'N':       /* Two Lines */
1099                                         lcd_flags |= LCD_FLAG_N;
1100                                         break;
1101
1102                                 case 'l':       /* Shift Cursor Left */
1103                                         if (lcd_addr_x > 0) {
1104                                                 if (lcd_addr_x < lcd_bwidth)
1105                                                         lcd_write_cmd(0x10);    /* back one char if not at end of line */
1106                                                 lcd_addr_x--;
1107                                         }
1108                                         processed = 1;
1109                                         break;
1110
1111                                 case 'r':       /* shift cursor right */
1112                                         if (lcd_addr_x < lcd_width) {
1113                                                 if (lcd_addr_x < (lcd_bwidth - 1))
1114                                                         lcd_write_cmd(0x14);    /* allow the cursor to pass the end of the line */
1115                                                 lcd_addr_x++;
1116                                         }
1117                                         processed = 1;
1118                                         break;
1119
1120                                 case 'L':       /* shift display left */
1121                                         lcd_left_shift++;
1122                                         lcd_write_cmd(0x18);
1123                                         processed = 1;
1124                                         break;
1125
1126                                 case 'R':       /* shift display right */
1127                                         lcd_left_shift--;
1128                                         lcd_write_cmd(0x1C);
1129                                         processed = 1;
1130                                         break;
1131
1132                                 case 'k':{      /* kill end of line */
1133                                                 int x;
1134                                                 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1135                                                         lcd_write_data(' ');
1136                                                 lcd_gotoxy();   /* restore cursor position */
1137                                                 processed = 1;
1138                                                 break;
1139                                         }
1140                                 case 'I':       /* reinitialize display */
1141                                         lcd_init_display();
1142                                         lcd_left_shift = 0;
1143                                         processed = 1;
1144                                         break;
1145
1146                                 case 'G':       /* Generator : LGcxxxxx...xx; */  {
1147                                                 /* must have <c> between '0' and '7', representing the numerical
1148                                                  * ASCII code of the redefined character, and <xx...xx> a sequence
1149                                                  * of 16 hex digits representing 8 bytes for each character. Most
1150                                                  * LCDs will only use 5 lower bits of the 7 first bytes.
1151                                                  */
1152
1153                                                 unsigned char cgbytes[8];
1154                                                 unsigned char cgaddr;
1155                                                 int cgoffset;
1156                                                 int shift;
1157                                                 char value;
1158                                                 int addr;
1159
1160                                                 if (strchr(esc, ';') == NULL)
1161                                                         break;
1162
1163                                                 esc++;
1164
1165                                                 cgaddr = *(esc++) - '0';
1166                                                 if (cgaddr > 7) {
1167                                                         processed = 1;
1168                                                         break;
1169                                                 }
1170
1171                                                 cgoffset = 0;
1172                                                 shift = 0;
1173                                                 value = 0;
1174                                                 while (*esc && cgoffset < 8) {
1175                                                         shift ^= 4;
1176                                                         if (*esc >= '0' && *esc <= '9')
1177                                                                 value |= (*esc - '0') << shift;
1178                                                         else if (*esc >= 'A' && *esc <= 'Z')
1179                                                                 value |= (*esc - 'A' + 10) << shift;
1180                                                         else if (*esc >= 'a' && *esc <= 'z')
1181                                                                 value |= (*esc - 'a' + 10) << shift;
1182                                                         else {
1183                                                                 esc++;
1184                                                                 continue;
1185                                                         }
1186
1187                                                         if (shift == 0) {
1188                                                                 cgbytes[cgoffset++] = value;
1189                                                                 value = 0;
1190                                                         }
1191
1192                                                         esc++;
1193                                                 }
1194
1195                                                 lcd_write_cmd(0x40 | (cgaddr * 8));
1196                                                 for (addr = 0; addr < cgoffset; addr++)
1197                                                         lcd_write_data(cgbytes[addr]);
1198
1199                                                 lcd_gotoxy();   /* ensures that we stop writing to CGRAM */
1200                                                 processed = 1;
1201                                                 break;
1202                                         }
1203                                 case 'x':       /* gotoxy : LxXXX[yYYY]; */
1204                                 case 'y':       /* gotoxy : LyYYY[xXXX]; */
1205                                         if (strchr(esc, ';') == NULL)
1206                                                 break;
1207
1208                                         while (*esc) {
1209                                                 if (*esc == 'x') {
1210                                                         esc++;
1211                                                         lcd_addr_x = 0;
1212                                                         while (isdigit(*esc)) {
1213                                                                 lcd_addr_x =
1214                                                                     lcd_addr_x *
1215                                                                     10 + (*esc -
1216                                                                           '0');
1217                                                                 esc++;
1218                                                         }
1219                                                 } else if (*esc == 'y') {
1220                                                         esc++;
1221                                                         lcd_addr_y = 0;
1222                                                         while (isdigit(*esc)) {
1223                                                                 lcd_addr_y =
1224                                                                     lcd_addr_y *
1225                                                                     10 + (*esc -
1226                                                                           '0');
1227                                                                 esc++;
1228                                                         }
1229                                                 } else
1230                                                         break;
1231                                         }
1232
1233                                         lcd_gotoxy();
1234                                         processed = 1;
1235                                         break;
1236                                 }       /* end of switch */
1237
1238                                 /* Check wether one flag was changed */
1239                                 if (oldflags != lcd_flags) {
1240                                         /* check wether one of B,C,D flags was changed */
1241                                         if ((oldflags ^ lcd_flags) &
1242                                             (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1243                                                 /* set display mode */
1244                                                 lcd_write_cmd(0x08 |
1245                                                               ((lcd_flags & LCD_FLAG_D) ? 4 : 0) |
1246                                                               ((lcd_flags & LCD_FLAG_C) ? 2 : 0) |
1247                                                               ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1248                                         /* check wether one of F,N flags was changed */
1249                                         else if ((oldflags ^ lcd_flags) &
1250                                                  (LCD_FLAG_F | LCD_FLAG_N))
1251                                                 lcd_write_cmd(0x30 |
1252                                                               ((lcd_flags & LCD_FLAG_F) ? 4 : 0) |
1253                                                               ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
1254                                         /* check wether L flag was changed */
1255                                         else if ((oldflags ^ lcd_flags) &
1256                                                  (LCD_FLAG_L)) {
1257                                                 if (lcd_flags & (LCD_FLAG_L))
1258                                                         lcd_backlight(1);
1259                                                 else if (light_tempo == 0)      /* switch off the light only when the tempo lighting is gone */
1260                                                         lcd_backlight(0);
1261                                         }
1262                                 }
1263                         }
1264
1265                         /* LCD special escape codes */
1266                         /* flush the escape sequence if it's been processed or if it is
1267                            getting too long. */
1268                         if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1269                                 lcd_escape_len = -1;
1270                 }               /* escape codes */
1271         }
1272
1273         return tmp - buf;
1274 }
1275
1276 static int lcd_open(struct inode *inode, struct file *file)
1277 {
1278         if (lcd_open_cnt)
1279                 return -EBUSY;  /* open only once at a time */
1280
1281         if (file->f_mode & FMODE_READ)  /* device is write-only */
1282                 return -EPERM;
1283
1284         if (lcd_must_clear) {
1285                 lcd_clear_display();
1286                 lcd_must_clear = 0;
1287         }
1288         lcd_open_cnt++;
1289         return 0;
1290 }
1291
1292 static int lcd_release(struct inode *inode, struct file *file)
1293 {
1294         lcd_open_cnt--;
1295         return 0;
1296 }
1297
1298 static struct file_operations lcd_fops = {
1299         .write   = lcd_write,
1300         .open    = lcd_open,
1301         .release = lcd_release,
1302 };
1303
1304 static struct miscdevice lcd_dev = {
1305         LCD_MINOR,
1306         "lcd",
1307         &lcd_fops
1308 };
1309
1310 /* public function usable from the kernel for any purpose */
1311 void panel_lcd_print(char *s)
1312 {
1313         if (lcd_enabled && lcd_initialized)
1314                 lcd_write(NULL, s, strlen(s), NULL);
1315 }
1316
1317 /* initialize the LCD driver */
1318 void lcd_init(void)
1319 {
1320         switch (lcd_type) {
1321         case LCD_TYPE_OLD:      /* parallel mode, 8 bits */
1322                 if (lcd_proto < 0)
1323                         lcd_proto = LCD_PROTO_PARALLEL;
1324                 if (lcd_charset < 0)
1325                         lcd_charset = LCD_CHARSET_NORMAL;
1326                 if (lcd_e_pin == PIN_NOT_SET)
1327                         lcd_e_pin = PIN_STROBE;
1328                 if (lcd_rs_pin == PIN_NOT_SET)
1329                         lcd_rs_pin = PIN_AUTOLF;
1330
1331                 if (lcd_width < 0)
1332                         lcd_width = 40;
1333                 if (lcd_bwidth < 0)
1334                         lcd_bwidth = 40;
1335                 if (lcd_hwidth < 0)
1336                         lcd_hwidth = 64;
1337                 if (lcd_height < 0)
1338                         lcd_height = 2;
1339                 break;
1340         case LCD_TYPE_KS0074:   /* serial mode, ks0074 */
1341                 if (lcd_proto < 0)
1342                         lcd_proto = LCD_PROTO_SERIAL;
1343                 if (lcd_charset < 0)
1344                         lcd_charset = LCD_CHARSET_KS0074;
1345                 if (lcd_bl_pin == PIN_NOT_SET)
1346                         lcd_bl_pin = PIN_AUTOLF;
1347                 if (lcd_cl_pin == PIN_NOT_SET)
1348                         lcd_cl_pin = PIN_STROBE;
1349                 if (lcd_da_pin == PIN_NOT_SET)
1350                         lcd_da_pin = PIN_D0;
1351
1352                 if (lcd_width < 0)
1353                         lcd_width = 16;
1354                 if (lcd_bwidth < 0)
1355                         lcd_bwidth = 40;
1356                 if (lcd_hwidth < 0)
1357                         lcd_hwidth = 16;
1358                 if (lcd_height < 0)
1359                         lcd_height = 2;
1360                 break;
1361         case LCD_TYPE_NEXCOM:   /* parallel mode, 8 bits, generic */
1362                 if (lcd_proto < 0)
1363                         lcd_proto = LCD_PROTO_PARALLEL;
1364                 if (lcd_charset < 0)
1365                         lcd_charset = LCD_CHARSET_NORMAL;
1366                 if (lcd_e_pin == PIN_NOT_SET)
1367                         lcd_e_pin = PIN_AUTOLF;
1368                 if (lcd_rs_pin == PIN_NOT_SET)
1369                         lcd_rs_pin = PIN_SELECP;
1370                 if (lcd_rw_pin == PIN_NOT_SET)
1371                         lcd_rw_pin = PIN_INITP;
1372
1373                 if (lcd_width < 0)
1374                         lcd_width = 16;
1375                 if (lcd_bwidth < 0)
1376                         lcd_bwidth = 40;
1377                 if (lcd_hwidth < 0)
1378                         lcd_hwidth = 64;
1379                 if (lcd_height < 0)
1380                         lcd_height = 2;
1381                 break;
1382         case LCD_TYPE_CUSTOM:   /* customer-defined */
1383                 if (lcd_proto < 0)
1384                         lcd_proto = DEFAULT_LCD_PROTO;
1385                 if (lcd_charset < 0)
1386                         lcd_charset = DEFAULT_LCD_CHARSET;
1387                 /* default geometry will be set later */
1388                 break;
1389         case LCD_TYPE_HANTRONIX:        /* parallel mode, 8 bits, hantronix-like */
1390         default:
1391                 if (lcd_proto < 0)
1392                         lcd_proto = LCD_PROTO_PARALLEL;
1393                 if (lcd_charset < 0)
1394                         lcd_charset = LCD_CHARSET_NORMAL;
1395                 if (lcd_e_pin == PIN_NOT_SET)
1396                         lcd_e_pin = PIN_STROBE;
1397                 if (lcd_rs_pin == PIN_NOT_SET)
1398                         lcd_rs_pin = PIN_SELECP;
1399
1400                 if (lcd_width < 0)
1401                         lcd_width = 16;
1402                 if (lcd_bwidth < 0)
1403                         lcd_bwidth = 40;
1404                 if (lcd_hwidth < 0)
1405                         lcd_hwidth = 64;
1406                 if (lcd_height < 0)
1407                         lcd_height = 2;
1408                 break;
1409         }
1410
1411         /* this is used to catch wrong and default values */
1412         if (lcd_width <= 0)
1413                 lcd_width = DEFAULT_LCD_WIDTH;
1414         if (lcd_bwidth <= 0)
1415                 lcd_bwidth = DEFAULT_LCD_BWIDTH;
1416         if (lcd_hwidth <= 0)
1417                 lcd_hwidth = DEFAULT_LCD_HWIDTH;
1418         if (lcd_height <= 0)
1419                 lcd_height = DEFAULT_LCD_HEIGHT;
1420
1421         if (lcd_proto == LCD_PROTO_SERIAL) {    /* SERIAL */
1422                 lcd_write_cmd = lcd_write_cmd_s;
1423                 lcd_write_data = lcd_write_data_s;
1424                 lcd_clear_fast = lcd_clear_fast_s;
1425
1426                 if (lcd_cl_pin == PIN_NOT_SET)
1427                         lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1428                 if (lcd_da_pin == PIN_NOT_SET)
1429                         lcd_da_pin = DEFAULT_LCD_PIN_SDA;
1430
1431         } else {                /* PARALLEL */
1432                 lcd_write_cmd = lcd_write_cmd_p8;
1433                 lcd_write_data = lcd_write_data_p8;
1434                 lcd_clear_fast = lcd_clear_fast_p8;
1435
1436                 if (lcd_e_pin == PIN_NOT_SET)
1437                         lcd_e_pin = DEFAULT_LCD_PIN_E;
1438                 if (lcd_rs_pin == PIN_NOT_SET)
1439                         lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1440                 if (lcd_rw_pin == PIN_NOT_SET)
1441                         lcd_rw_pin = DEFAULT_LCD_PIN_RW;
1442         }
1443
1444         if (lcd_bl_pin == PIN_NOT_SET)
1445                 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1446
1447         if (lcd_e_pin == PIN_NOT_SET)
1448                 lcd_e_pin = PIN_NONE;
1449         if (lcd_rs_pin == PIN_NOT_SET)
1450                 lcd_rs_pin = PIN_NONE;
1451         if (lcd_rw_pin == PIN_NOT_SET)
1452                 lcd_rw_pin = PIN_NONE;
1453         if (lcd_bl_pin == PIN_NOT_SET)
1454                 lcd_bl_pin = PIN_NONE;
1455         if (lcd_cl_pin == PIN_NOT_SET)
1456                 lcd_cl_pin = PIN_NONE;
1457         if (lcd_da_pin == PIN_NOT_SET)
1458                 lcd_da_pin = PIN_NONE;
1459
1460         if (lcd_charset < 0)
1461                 lcd_charset = DEFAULT_LCD_CHARSET;
1462
1463         if (lcd_charset == LCD_CHARSET_KS0074)
1464                 lcd_char_conv = lcd_char_conv_ks0074;
1465         else
1466                 lcd_char_conv = NULL;
1467
1468         if (lcd_bl_pin != PIN_NONE)
1469                 init_scan_timer();
1470
1471         pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1472                     lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1473         pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1474                     lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1475         pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1476                     lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1477         pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1478                     lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1479         pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1480                     lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1481         pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1482                     lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
1483
1484         /* before this line, we must NOT send anything to the display.
1485          * Since lcd_init_display() needs to write data, we have to
1486          * enable mark the LCD initialized just before.
1487          */
1488         lcd_initialized = 1;
1489         lcd_init_display();
1490
1491         /* display a short message */
1492 #ifdef CONFIG_PANEL_CHANGE_MESSAGE
1493 #ifdef CONFIG_PANEL_BOOT_MESSAGE
1494         panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
1495 #endif
1496 #else
1497         panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1498                         PANEL_VERSION);
1499 #endif
1500         lcd_addr_x = lcd_addr_y = 0;
1501         lcd_must_clear = 1;     /* clear the display on the next device opening */
1502         lcd_gotoxy();
1503 }
1504
1505 /*
1506  * These are the file operation function for user access to /dev/keypad
1507  */
1508
1509 static ssize_t keypad_read(struct file *file,
1510                            char *buf, size_t count, loff_t *ppos)
1511 {
1512
1513         unsigned i = *ppos;
1514         char *tmp = buf;
1515
1516         if (keypad_buflen == 0) {
1517                 if (file->f_flags & O_NONBLOCK)
1518                         return -EAGAIN;
1519
1520                 interruptible_sleep_on(&keypad_read_wait);
1521                 if (signal_pending(current))
1522                         return -EINTR;
1523         }
1524
1525         for (; count-- > 0 && (keypad_buflen > 0); ++i, ++tmp, --keypad_buflen) {
1526                 put_user(keypad_buffer[keypad_start], tmp);
1527                 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1528         }
1529         *ppos = i;
1530
1531         return tmp - buf;
1532 }
1533
1534 static int keypad_open(struct inode *inode, struct file *file)
1535 {
1536
1537         if (keypad_open_cnt)
1538                 return -EBUSY;  /* open only once at a time */
1539
1540         if (file->f_mode & FMODE_WRITE) /* device is read-only */
1541                 return -EPERM;
1542
1543         keypad_buflen = 0;      /* flush the buffer on opening */
1544         keypad_open_cnt++;
1545         return 0;
1546 }
1547
1548 static int keypad_release(struct inode *inode, struct file *file)
1549 {
1550         keypad_open_cnt--;
1551         return 0;
1552 }
1553
1554 static struct file_operations keypad_fops = {
1555         .read    = keypad_read,         /* read */
1556         .open    = keypad_open,         /* open */
1557         .release = keypad_release,      /* close */
1558 };
1559
1560 static struct miscdevice keypad_dev = {
1561         KEYPAD_MINOR,
1562         "keypad",
1563         &keypad_fops
1564 };
1565
1566 static void keypad_send_key(char *string, int max_len)
1567 {
1568         if (init_in_progress)
1569                 return;
1570
1571         /* send the key to the device only if a process is attached to it. */
1572         if (keypad_open_cnt > 0) {
1573                 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1574                         keypad_buffer[(keypad_start + keypad_buflen++) %
1575                                       KEYPAD_BUFFER] = *string++;
1576                 }
1577                 wake_up_interruptible(&keypad_read_wait);
1578         }
1579 }
1580
1581 /* this function scans all the bits involving at least one logical signal, and puts the
1582  * results in the bitfield "phys_read" (one bit per established contact), and sets
1583  * "phys_read_prev" to "phys_read".
1584  *
1585  * Note: to debounce input signals, we will only consider as switched a signal which is
1586  * stable across 2 measures. Signals which are different between two reads will be kept
1587  * as they previously were in their logical form (phys_prev). A signal which has just
1588  * switched will have a 1 in (phys_read ^ phys_read_prev).
1589  */
1590 static void phys_scan_contacts(void)
1591 {
1592         int bit, bitval;
1593         char oldval;
1594         char bitmask;
1595         char gndmask;
1596
1597         phys_prev = phys_curr;
1598         phys_read_prev = phys_read;
1599         phys_read = 0;          /* flush all signals */
1600
1601         oldval = r_dtr(pprt) | scan_mask_o;     /* keep track of old value, with all outputs disabled */
1602         w_dtr(pprt, oldval & ~scan_mask_o);     /* activate all keyboard outputs (active low) */
1603         bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;        /* will have a 1 for each bit set to gnd */
1604         w_dtr(pprt, oldval);    /* disable all matrix signals */
1605
1606         /* now that all outputs are cleared, the only active input bits are
1607          * directly connected to the ground
1608          */
1609         gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;        /* 1 for each grounded input */
1610
1611         phys_read |= (pmask_t) gndmask << 40;   /* grounded inputs are signals 40-44 */
1612
1613         if (bitmask != gndmask) {
1614                 /* since clearing the outputs changed some inputs, we know that some
1615                  * input signals are currently tied to some outputs. So we'll scan them.
1616                  */
1617                 for (bit = 0; bit < 8; bit++) {
1618                         bitval = 1 << bit;
1619
1620                         if (!(scan_mask_o & bitval))    /* skip unused bits */
1621                                 continue;
1622
1623                         w_dtr(pprt, oldval & ~bitval);  /* enable this output */
1624                         bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1625                         phys_read |= (pmask_t) bitmask << (5 * bit);
1626                 }
1627                 w_dtr(pprt, oldval);    /* disable all outputs */
1628         }
1629         /* this is easy: use old bits when they are flapping, use new ones when stable */
1630         phys_curr =
1631             (phys_prev & (phys_read ^ phys_read_prev)) | (phys_read &
1632                                                           ~(phys_read ^
1633                                                             phys_read_prev));
1634 }
1635
1636 static void panel_process_inputs(void)
1637 {
1638         struct list_head *item;
1639         struct logical_input *input;
1640
1641 #if 0
1642         printk(KERN_DEBUG
1643                "entering panel_process_inputs with pp=%016Lx & pc=%016Lx\n",
1644                phys_prev, phys_curr);
1645 #endif
1646
1647         keypressed = 0;
1648         inputs_stable = 1;
1649         list_for_each(item, &logical_inputs) {
1650                 input = list_entry(item, struct logical_input, list);
1651
1652                 switch (input->state) {
1653                 case INPUT_ST_LOW:
1654                         if ((phys_curr & input->mask) != input->value)
1655                                 break;
1656                         /* if all needed ones were already set previously, this means that
1657                          * this logical signal has been activated by the releasing of
1658                          * another combined signal, so we don't want to match.
1659                          * eg: AB -(release B)-> A -(release A)-> 0 : don't match A.
1660                          */
1661                         if ((phys_prev & input->mask) == input->value)
1662                                 break;
1663                         input->rise_timer = 0;
1664                         input->state = INPUT_ST_RISING;
1665                         /* no break here, fall through */
1666                 case INPUT_ST_RISING:
1667                         if ((phys_curr & input->mask) != input->value) {
1668                                 input->state = INPUT_ST_LOW;
1669                                 break;
1670                         }
1671                         if (input->rise_timer < input->rise_time) {
1672                                 inputs_stable = 0;
1673                                 input->rise_timer++;
1674                                 break;
1675                         }
1676                         input->high_timer = 0;
1677                         input->state = INPUT_ST_HIGH;
1678                         /* no break here, fall through */
1679                 case INPUT_ST_HIGH:
1680 #if 0
1681                         /* FIXME:
1682                          * this is an invalid test. It tries to catch transitions from single-key
1683                          * to multiple-key, but doesn't take into account the contacts polarity.
1684                          * The only solution to the problem is to parse keys from the most complex
1685                          * to the simplest combinations, and mark them as 'caught' once a combination
1686                          * matches, then unmatch it for all other ones.
1687                          */
1688
1689                         /* try to catch dangerous transitions cases :
1690                          * someone adds a bit, so this signal was a false
1691                          * positive resulting from a transition. We should invalidate
1692                          * the signal immediately and not call the release function.
1693                          * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1694                          */
1695                         if (((phys_prev & input->mask) == input->value)
1696                             && ((phys_curr & input->mask) > input->value)) {
1697                                 input->state = INPUT_ST_LOW;    /* invalidate */
1698                                 break;
1699                         }
1700 #endif
1701
1702                         if ((phys_curr & input->mask) == input->value) {
1703                                 if ((input->type == INPUT_TYPE_STD)
1704                                     && (input->high_timer == 0)) {
1705                                         input->high_timer++;
1706                                         if (input->u.std.press_fct != NULL)
1707                                                 input->u.std.press_fct(input->u.
1708                                                                        std.
1709                                                                        press_data);
1710                                 } else if (input->type == INPUT_TYPE_KBD) {
1711                                         keypressed = 1; /* will turn on the light */
1712
1713                                         if (input->high_timer == 0) {
1714                                                 if (input->u.kbd.press_str[0])
1715                                                         keypad_send_key(input->
1716                                                                         u.kbd.
1717                                                                         press_str,
1718                                                                         sizeof
1719                                                                         (input->
1720                                                                          u.kbd.
1721                                                                          press_str));
1722                                         }
1723
1724                                         if (input->u.kbd.repeat_str[0]) {
1725                                                 if (input->high_timer >=
1726                                                     KEYPAD_REP_START) {
1727                                                         input->high_timer -=
1728                                                             KEYPAD_REP_DELAY;
1729                                                         keypad_send_key(input->
1730                                                                         u.kbd.
1731                                                                         repeat_str,
1732                                                                         sizeof
1733                                                                         (input->
1734                                                                          u.kbd.
1735                                                                          repeat_str));
1736                                                 }
1737                                                 inputs_stable = 0;      /* we will need to come back here soon */
1738                                         }
1739
1740                                         if (input->high_timer < 255)
1741                                                 input->high_timer++;
1742                                 }
1743                                 break;
1744                         } else {
1745                                 /* else signal falling down. Let's fall through. */
1746                                 input->state = INPUT_ST_FALLING;
1747                                 input->fall_timer = 0;
1748                         }
1749                         /* no break here, fall through */
1750                 case INPUT_ST_FALLING:
1751 #if 0
1752                         /* FIXME !!! same comment as above */
1753                         if (((phys_prev & input->mask) == input->value)
1754                             && ((phys_curr & input->mask) > input->value)) {
1755                                 input->state = INPUT_ST_LOW;    /* invalidate */
1756                                 break;
1757                         }
1758 #endif
1759
1760                         if ((phys_curr & input->mask) == input->value) {
1761                                 if (input->type == INPUT_TYPE_KBD) {
1762                                         keypressed = 1; /* will turn on the light */
1763
1764                                         if (input->u.kbd.repeat_str[0]) {
1765                                                 if (input->high_timer >= KEYPAD_REP_START)
1766                                                         input->high_timer -= KEYPAD_REP_DELAY;
1767                                                 keypad_send_key(input->u.kbd.repeat_str,
1768                                                                 sizeof(input->u.kbd.repeat_str));
1769                                                 inputs_stable = 0;      /* we will need to come back here soon */
1770                                         }
1771
1772                                         if (input->high_timer < 255)
1773                                                 input->high_timer++;
1774                                 }
1775                                 input->state = INPUT_ST_HIGH;
1776                                 break;
1777                         } else if (input->fall_timer >= input->fall_time) {
1778                                 /* call release event */
1779                                 if (input->type == INPUT_TYPE_STD) {
1780                                         if (input->u.std.release_fct != NULL)
1781                                                 input->u.std.release_fct(input->u.std.release_data);
1782
1783                                 } else if (input->type == INPUT_TYPE_KBD) {
1784                                         if (input->u.kbd.release_str[0])
1785                                                 keypad_send_key(input->u.kbd.release_str,
1786                                                                 sizeof(input->u.kbd.release_str));
1787                                 }
1788
1789                                 input->state = INPUT_ST_LOW;
1790                                 break;
1791                         } else {
1792                                 input->fall_timer++;
1793                                 inputs_stable = 0;
1794                                 break;
1795                         }
1796                 }
1797         }
1798 }
1799
1800 static void panel_scan_timer(void)
1801 {
1802         if ((keypad_enabled && keypad_initialized)
1803             || (smartcard_enabled && smartcard_enabled)) {
1804
1805                 if (spin_trylock(&pprt_lock)) {
1806                         phys_scan_contacts();
1807                         spin_unlock(&pprt_lock);        /* no need for the parport anymore */
1808                 }
1809
1810                 if (!inputs_stable || phys_curr != phys_prev)
1811                         panel_process_inputs();
1812         }
1813
1814         if (lcd_enabled && lcd_initialized) {
1815                 if (keypressed) {
1816                         if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1817                                 lcd_backlight(1);
1818                         light_tempo = FLASH_LIGHT_TEMPO;
1819                 } else if (light_tempo > 0) {
1820                         light_tempo--;
1821                         if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1822                                 lcd_backlight(0);
1823                 }
1824         }
1825
1826         mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
1827 }
1828
1829 /* send a high / low clock impulse of <duration> microseconds high and low */
1830 static void smartcard_send_clock(int duration)
1831 {
1832         int old;
1833
1834         w_dtr(pprt, (old = r_dtr(pprt)) | PNL_SC_CLK);
1835         udelay(duration);
1836         w_dtr(pprt, (old & ~PNL_SC_CLK));
1837         udelay(duration);
1838 }
1839
1840 static void smartcard_insert(int dummy)
1841 {
1842         int ofs;
1843
1844         spin_lock(&pprt_lock);
1845         w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
1846         w_ctr(pprt, (r_ctr(pprt) | PNL_SC_ENA));
1847
1848         udelay(30);             /* ensure the rst is low at least 30 us */
1849
1850         smartcard_send_clock(100);      /* reset address counter */
1851
1852         w_dtr(pprt, r_dtr(pprt) | PNL_SC_RST);
1853         udelay(30);             /* ensure the rst is high at least 30 us */
1854
1855         for (ofs = 0; ofs < SMARTCARD_BYTES; ofs++) {
1856                 int bit, byte;
1857                 byte = 0;
1858                 for (bit = 128; bit > 0; bit >>= 1) {
1859                         if (!(r_str(pprt) & PNL_SC_IOR))
1860                                 byte |= bit;
1861                         smartcard_send_clock(15);       /* 15 us are enough for data */
1862                 }
1863                 smartcard_data[ofs] = byte;
1864         }
1865
1866         w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
1867         w_ctr(pprt, (r_ctr(pprt) & ~PNL_SC_ENA));
1868
1869         spin_unlock(&pprt_lock);
1870
1871         printk(KERN_INFO "Panel: smart card inserted : %02x%02x%02x%02x%1x\n",
1872                smartcard_data[2], smartcard_data[3], smartcard_data[4],
1873                smartcard_data[5], smartcard_data[6] >> 4);
1874         keypad_send_key("CardIn\n", 7);
1875 }
1876
1877 static void smartcard_remove(int dummy)
1878 {
1879         printk(KERN_INFO "Panel: smart card removed : %02x%02x%02x%02x%1x\n",
1880                smartcard_data[2], smartcard_data[3], smartcard_data[4],
1881                smartcard_data[5], smartcard_data[6] >> 4);
1882         memset(smartcard_data, 0, sizeof(smartcard_data));
1883         keypad_send_key("CardOut\n", 8);
1884 }
1885
1886 /*
1887  * These are the file operation function for user access to /dev/smartcard
1888  */
1889
1890 static ssize_t smartcard_read(struct file *file,
1891                               char *buf, size_t count, loff_t *ppos)
1892 {
1893
1894         unsigned i = *ppos;
1895         char *tmp = buf;
1896
1897         for (; count-- > 0 && (smartcard_ptr < 9); ++i, ++tmp, ++smartcard_ptr) {
1898                 if (smartcard_ptr & 1)
1899                         put_user('0' +
1900                                  (smartcard_data[2 + (smartcard_ptr >> 1)] &
1901                                   0xF), tmp);
1902                 else
1903                         put_user('0' +
1904                                  (smartcard_data[2 + (smartcard_ptr >> 1)] >>
1905                                   4), tmp);
1906         }
1907         *ppos = i;
1908
1909         return tmp - buf;
1910 }
1911
1912 static int smartcard_open(struct inode *inode, struct file *file)
1913 {
1914
1915         if (smartcard_open_cnt)
1916                 return -EBUSY;  /* open only once at a time */
1917
1918         if (file->f_mode & FMODE_WRITE) /* device is read-only */
1919                 return -EPERM;
1920
1921         smartcard_ptr = 0;      /* flush the buffer on opening */
1922         smartcard_open_cnt++;
1923         return 0;
1924 }
1925
1926 static int smartcard_release(struct inode *inode, struct file *file)
1927 {
1928         smartcard_open_cnt--;
1929         return 0;
1930 }
1931
1932 static struct file_operations smartcard_fops = {
1933         .read    = smartcard_read,      /* read */
1934         .open    = smartcard_open,      /* open */
1935         .release = smartcard_release,   /* close */
1936 };
1937
1938 static struct miscdevice smartcard_dev = {
1939         SMARTCARD_MINOR,
1940         "smartcard",
1941         &smartcard_fops
1942 };
1943
1944 static void init_scan_timer(void)
1945 {
1946         if (scan_timer.function != NULL)
1947                 return;         /* already started */
1948
1949         init_timer(&scan_timer);
1950         scan_timer.expires = jiffies + INPUT_POLL_TIME;
1951         scan_timer.data = 0;
1952         scan_timer.function = (void *)&panel_scan_timer;
1953         add_timer(&scan_timer);
1954 }
1955
1956 /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
1957  * if <omask> or <imask> are non-null, they will be or'ed with the bits corresponding
1958  * to out and in bits respectively.
1959  * returns 1 if ok, 0 if error (in which case, nothing is written).
1960  */
1961 static int input_name2mask(char *name, pmask_t *mask, pmask_t *value,
1962                            char *imask, char *omask)
1963 {
1964         static char sigtab[10] = "EeSsPpAaBb";
1965         char im, om;
1966         pmask_t m, v;
1967
1968         om = im = m = v = 0ULL;
1969         while (*name) {
1970                 int in, out, bit, neg;
1971                 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name); in++)
1972                         ;
1973                 if (in >= sizeof(sigtab))
1974                         return 0;       /* input name not found */
1975                 neg = (in & 1); /* odd (lower) names are negated */
1976                 in >>= 1;
1977                 im |= (1 << in);
1978
1979                 name++;
1980                 if (isdigit(*name)) {
1981                         out = *name - '0';
1982                         om |= (1 << out);
1983                 } else if (*name == '-')
1984                         out = 8;
1985                 else
1986                         return 0;       /* unknown bit name */
1987
1988                 bit = (out * 5) + in;
1989
1990                 m |= 1ULL << bit;
1991                 if (!neg)
1992                         v |= 1ULL << bit;
1993                 name++;
1994         }
1995         *mask = m;
1996         *value = v;
1997         if (imask)
1998                 *imask |= im;
1999         if (omask)
2000                 *omask |= om;
2001         return 1;
2002 }
2003
2004 /* tries to bind a key to the signal name <name>. The key will send the
2005  * strings <press>, <repeat>, <release> for these respective events.
2006  * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2007  */
2008 static struct logical_input *panel_bind_key(char *name, char *press,
2009                                             char *repeat, char *release)
2010 {
2011         struct logical_input *key;
2012
2013         key = kmalloc(sizeof(struct logical_input), GFP_KERNEL);
2014         if (!key) {
2015                 printk(KERN_ERR "panel: not enough memory\n");
2016                 return NULL;
2017         }
2018         memset(key, 0, sizeof(struct logical_input));
2019         if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
2020                              &scan_mask_o))
2021                 return NULL;
2022
2023         key->type = INPUT_TYPE_KBD;
2024         key->state = INPUT_ST_LOW;
2025         key->rise_time = 1;
2026         key->fall_time = 1;
2027
2028 #if 0
2029         printk(KERN_DEBUG "bind: <%s> : m=%016Lx v=%016Lx\n", name, key->mask,
2030                key->value);
2031 #endif
2032         strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
2033         strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
2034         strncpy(key->u.kbd.release_str, release,
2035                 sizeof(key->u.kbd.release_str));
2036         list_add(&key->list, &logical_inputs);
2037         return key;
2038 }
2039
2040 /* tries to bind a callback function to the signal name <name>. The function
2041  * <press_fct> will be called with the <press_data> arg when the signal is
2042  * activated, and so on for <release_fct>/<release_data>
2043  * Returns the pointer to the new signal if ok, NULL if the signal could not be bound.
2044  */
2045 static struct logical_input *panel_bind_callback(char *name,
2046                                                  void (*press_fct) (int),
2047                                                  int press_data,
2048                                                  void (*release_fct) (int),
2049                                                  int release_data)
2050 {
2051         struct logical_input *callback;
2052
2053         callback = kmalloc(sizeof(struct logical_input), GFP_KERNEL);
2054         if (!callback) {
2055                 printk(KERN_ERR "panel: not enough memory\n");
2056                 return NULL;
2057         }
2058         memset(callback, 0, sizeof(struct logical_input));
2059         if (!input_name2mask(name, &callback->mask, &callback->value,
2060                              &scan_mask_i, &scan_mask_o))
2061                 return NULL;
2062
2063         callback->type = INPUT_TYPE_STD;
2064         callback->state = INPUT_ST_LOW;
2065         callback->rise_time = 1;
2066         callback->fall_time = 1;
2067         callback->u.std.press_fct = press_fct;
2068         callback->u.std.press_data = press_data;
2069         callback->u.std.release_fct = release_fct;
2070         callback->u.std.release_data = release_data;
2071         list_add(&callback->list, &logical_inputs);
2072         return callback;
2073 }
2074
2075 static void keypad_init(void)
2076 {
2077         int keynum;
2078         init_waitqueue_head(&keypad_read_wait);
2079         keypad_buflen = 0;      /* flushes any eventual noisy keystroke */
2080
2081         /* Let's create all known keys */
2082
2083         for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
2084                 panel_bind_key(keypad_profile[keynum][0],
2085                                keypad_profile[keynum][1],
2086                                keypad_profile[keynum][2],
2087                                keypad_profile[keynum][3]);
2088         }
2089
2090         init_scan_timer();
2091         keypad_initialized = 1;
2092 }
2093
2094 static void smartcard_init(void)
2095 {
2096         init_waitqueue_head(&smartcard_read_wait);
2097
2098         panel_bind_callback(SMARTCARD_LOGICAL_DETECTOR, &smartcard_insert, 0,
2099                             &smartcard_remove, 0);
2100         init_scan_timer();
2101         smartcard_enabled = 1;
2102 }
2103
2104 /**************************************************/
2105 /* device initialization                          */
2106 /**************************************************/
2107
2108 static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2109                             void *unused)
2110 {
2111         if (lcd_enabled && lcd_initialized) {
2112                 switch (code) {
2113                 case SYS_DOWN:
2114                         panel_lcd_print
2115                             ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2116                         break;
2117                 case SYS_HALT:
2118                         panel_lcd_print
2119                             ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2120                         break;
2121                 case SYS_POWER_OFF:
2122                         panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2123                         break;
2124                 default:
2125                         break;
2126                 }
2127         }
2128         return NOTIFY_DONE;
2129 }
2130
2131 static struct notifier_block panel_notifier = {
2132         panel_notify_sys,
2133         NULL,
2134         0
2135 };
2136
2137 static void panel_attach(struct parport *port)
2138 {
2139         if (port->number != parport)
2140                 return;
2141
2142         if (pprt) {
2143                 printk(KERN_ERR
2144                        "panel_attach(): port->number=%d parport=%d, already registered !\n",
2145                        port->number, parport);
2146                 return;
2147         }
2148
2149         pprt = parport_register_device(port, "panel", NULL, NULL,       /* pf, kf */
2150                                        NULL,
2151                                        /*PARPORT_DEV_EXCL */
2152                                        0, (void *)&pprt);
2153
2154         if (parport_claim(pprt)) {
2155                 printk(KERN_ERR
2156                        "Panel: could not claim access to parport%d. Aborting.\n",
2157                        parport);
2158                 return;
2159         }
2160
2161         /* must init LCD first, just in case an IRQ from the keypad is generated at keypad init */
2162         if (lcd_enabled) {
2163                 lcd_init();
2164                 misc_register(&lcd_dev);
2165         }
2166
2167         if (keypad_enabled) {
2168                 keypad_init();
2169                 misc_register(&keypad_dev);
2170         }
2171
2172         if (smartcard_enabled) {
2173                 smartcard_init();
2174                 misc_register(&smartcard_dev);
2175         }
2176 }
2177
2178 static void panel_detach(struct parport *port)
2179 {
2180         if (port->number != parport)
2181                 return;
2182
2183         if (!pprt) {
2184                 printk(KERN_ERR
2185                        "panel_detach(): port->number=%d parport=%d, nothing to unregister.\n",
2186                        port->number, parport);
2187                 return;
2188         }
2189
2190         if (smartcard_enabled && smartcard_initialized)
2191                 misc_deregister(&smartcard_dev);
2192
2193         if (keypad_enabled && keypad_initialized)
2194                 misc_deregister(&keypad_dev);
2195
2196         if (lcd_enabled && lcd_initialized)
2197                 misc_deregister(&lcd_dev);
2198
2199         parport_release(pprt);
2200         parport_unregister_device(pprt);
2201         pprt = NULL;
2202 }
2203
2204 static struct parport_driver panel_driver = {
2205         .name = "panel",
2206         .attach = panel_attach,
2207         .detach = panel_detach,
2208 };
2209
2210 /* init function */
2211 int panel_init(void)
2212 {
2213         /* for backwards compatibility */
2214         if (keypad_type < 0)
2215                 keypad_type = keypad_enabled;
2216
2217         if (lcd_type < 0)
2218                 lcd_type = lcd_enabled;
2219
2220         if (parport < 0)
2221                 parport = DEFAULT_PARPORT;
2222
2223         /* take care of an eventual profile */
2224         switch (profile) {
2225         case PANEL_PROFILE_CUSTOM:      /* custom profile */
2226                 if (keypad_type < 0)
2227                         keypad_type = DEFAULT_KEYPAD;
2228                 if (smartcard_enabled < 0)
2229                         smartcard_enabled = DEFAULT_SMARTCARD;
2230                 if (lcd_type < 0)
2231                         lcd_type = DEFAULT_LCD;
2232                 break;
2233         case PANEL_PROFILE_OLD: /* 8 bits, 2*16, old keypad */
2234                 if (keypad_type < 0)
2235                         keypad_type = KEYPAD_TYPE_OLD;
2236                 if (smartcard_enabled < 0)
2237                         smartcard_enabled = 0;
2238                 if (lcd_type < 0)
2239                         lcd_type = LCD_TYPE_OLD;
2240                 if (lcd_width < 0)
2241                         lcd_width = 16;
2242                 if (lcd_hwidth < 0)
2243                         lcd_hwidth = 16;
2244                 break;
2245         case PANEL_PROFILE_NEW: /* serial, 2*16, new keypad */
2246                 if (keypad_type < 0)
2247                         keypad_type = KEYPAD_TYPE_NEW;
2248                 if (smartcard_enabled < 0)
2249                         smartcard_enabled = 1;
2250                 if (lcd_type < 0)
2251                         lcd_type = LCD_TYPE_KS0074;
2252                 break;
2253         case PANEL_PROFILE_HANTRONIX:   /* 8 bits, 2*16 hantronix-like, no keypad */
2254                 if (keypad_type < 0)
2255                         keypad_type = KEYPAD_TYPE_NONE;
2256                 if (smartcard_enabled < 0)
2257                         smartcard_enabled = 0;
2258                 if (lcd_type < 0)
2259                         lcd_type = LCD_TYPE_HANTRONIX;
2260                 break;
2261         case PANEL_PROFILE_NEXCOM:      /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2262                 if (keypad_type < 0)
2263                         keypad_type = KEYPAD_TYPE_NEXCOM;
2264                 if (smartcard_enabled < 0)
2265                         smartcard_enabled = 0;
2266                 if (lcd_type < 0)
2267                         lcd_type = LCD_TYPE_NEXCOM;
2268                 break;
2269         case PANEL_PROFILE_LARGE:       /* 8 bits, 2*40, old keypad */
2270                 if (keypad_type < 0)
2271                         keypad_type = KEYPAD_TYPE_OLD;
2272                 if (smartcard_enabled < 0)
2273                         smartcard_enabled = 0;
2274                 if (lcd_type < 0)
2275                         lcd_type = LCD_TYPE_OLD;
2276                 break;
2277         }
2278
2279         lcd_enabled = (lcd_type > 0);
2280         keypad_enabled = (keypad_type > 0);
2281
2282         switch (keypad_type) {
2283         case KEYPAD_TYPE_OLD:
2284                 keypad_profile = old_keypad_profile;
2285                 break;
2286         case KEYPAD_TYPE_NEW:
2287                 keypad_profile = new_keypad_profile;
2288                 break;
2289         case KEYPAD_TYPE_NEXCOM:
2290                 keypad_profile = nexcom_keypad_profile;
2291                 break;
2292         default:
2293                 keypad_profile = NULL;
2294                 break;
2295         }
2296
2297         /* tells various subsystems about the fact that we are initializing */
2298         init_in_progress = 1;
2299
2300         if (parport_register_driver(&panel_driver)) {
2301                 printk(KERN_ERR
2302                        "Panel: could not register with parport. Aborting.\n");
2303                 return -EIO;
2304         }
2305
2306         if (!lcd_enabled && !keypad_enabled && !smartcard_enabled) {    /* no device enabled, let's release the parport */
2307                 if (pprt) {
2308                         parport_release(pprt);
2309                         parport_unregister_device(pprt);
2310                 }
2311                 parport_unregister_driver(&panel_driver);
2312                 printk(KERN_ERR "Panel driver version " PANEL_VERSION
2313                        " disabled.\n");
2314                 return -ENODEV;
2315         }
2316
2317         register_reboot_notifier(&panel_notifier);
2318
2319         if (pprt)
2320                 printk(KERN_INFO "Panel driver version " PANEL_VERSION
2321                        " registered on parport%d (io=0x%lx).\n", parport,
2322                        pprt->port->base);
2323         else
2324                 printk(KERN_INFO "Panel driver version " PANEL_VERSION
2325                        " not yet registered\n");
2326         /* tells various subsystems about the fact that initialization is finished */
2327         init_in_progress = 0;
2328         return 0;
2329 }
2330
2331 static int __init panel_init_module(void)
2332 {
2333         return panel_init();
2334 }
2335
2336 static void __exit panel_cleanup_module(void)
2337 {
2338         unregister_reboot_notifier(&panel_notifier);
2339
2340         if (scan_timer.function != NULL)
2341                 del_timer(&scan_timer);
2342
2343         if (keypad_enabled)
2344                 misc_deregister(&keypad_dev);
2345
2346         if (smartcard_enabled)
2347                 misc_deregister(&smartcard_dev);
2348
2349         if (lcd_enabled) {
2350                 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2351                                 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2352                 misc_deregister(&lcd_dev);
2353         }
2354
2355         /* TODO: free all input signals */
2356
2357         parport_release(pprt);
2358         parport_unregister_device(pprt);
2359         parport_unregister_driver(&panel_driver);
2360 }
2361
2362 module_init(panel_init_module);
2363 module_exit(panel_cleanup_module);
2364 MODULE_AUTHOR("Willy Tarreau");
2365 MODULE_LICENSE("GPL");
2366
2367 /*
2368  * Local variables:
2369  *  c-indent-level: 4
2370  *  tab-width: 8
2371  * End:
2372  */