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