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