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