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