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