blob: 19f6767731e9f4be5080f61541325e860fa78791 [file] [log] [blame]
Willy Tarreau7005b582008-11-13 17:18:59 -08001/*
Willy Tarreau698b1512008-11-22 11:29:33 +01002 * Front panel driver for Linux
3 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
Willy Tarreau7005b582008-11-13 17:18:59 -08004 *
Willy Tarreau698b1512008-11-22 11:29:33 +01005 * 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.
Willy Tarreau7005b582008-11-13 17:18:59 -08009 *
Willy Tarreau698b1512008-11-22 11:29:33 +010010 * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
11 * connected to a parallel printer port.
Willy Tarreau7005b582008-11-13 17:18:59 -080012 *
Willy Tarreau698b1512008-11-22 11:29:33 +010013 * 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.
Willy Tarreau7005b582008-11-13 17:18:59 -080016 *
Willy Tarreau698b1512008-11-22 11:29:33 +010017 * 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.
Willy Tarreau7005b582008-11-13 17:18:59 -080020 *
Willy Tarreau698b1512008-11-22 11:29:33 +010021 * Several profiles are provided for commonly found LCD+keypad modules on the
22 * market, such as those found in Nexcom's appliances.
Willy Tarreau7005b582008-11-13 17:18:59 -080023 *
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
Toshiaki Yamane493aa892012-07-12 22:01:00 +090037#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
Willy Tarreau7005b582008-11-13 17:18:59 -080039#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>
Willy Tarreau7005b582008-11-13 17:18:59 -080046#include <linux/interrupt.h>
47#include <linux/miscdevice.h>
Willy Tarreau698b1512008-11-22 11:29:33 +010048#include <linux/slab.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080049#include <linux/ioport.h>
50#include <linux/fcntl.h>
51#include <linux/init.h>
52#include <linux/delay.h>
Andy Shevchenkod85170e2010-07-22 19:57:08 +030053#include <linux/kernel.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080054#include <linux/ctype.h>
55#include <linux/parport.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080056#include <linux/list.h>
57#include <linux/notifier.h>
58#include <linux/reboot.h>
Sam Ravnborg273b2812009-10-18 00:52:28 +020059#include <generated/utsrelease.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080060
Willy Tarreau698b1512008-11-22 11:29:33 +010061#include <linux/io.h>
Takanori Suzuki48f658b2010-05-08 22:56:24 +090062#include <linux/uaccess.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080063
Willy Tarreau7005b582008-11-13 17:18:59 -080064#define LCD_MINOR 156
65#define KEYPAD_MINOR 185
Willy Tarreau7005b582008-11-13 17:18:59 -080066
67#define PANEL_VERSION "0.9.5"
68
69#define LCD_MAXBYTES 256 /* max burst write */
70
Willy Tarreau7005b582008-11-13 17:18:59 -080071#define KEYPAD_BUFFER 64
Willy Tarreau7005b582008-11-13 17:18:59 -080072
Henri Häkkinen429ccf02010-06-12 00:27:36 +030073/* 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)
Willy Tarreau7005b582008-11-13 17:18:59 -080082
83/* converts an r_str() input to an active high, bits string : 000BAOSE */
84#define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
85
Willy Tarreau698b1512008-11-22 11:29:33 +010086#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 */
Willy Tarreau7005b582008-11-13 17:18:59 -080091
Willy Tarreau698b1512008-11-22 11:29:33 +010092#define PNL_PBIDIR 0x20 /* bi-directional ports */
Henri Häkkinen429ccf02010-06-12 00:27:36 +030093/* high to read data in or-ed with data out */
94#define PNL_PINTEN 0x10
Willy Tarreau698b1512008-11-22 11:29:33 +010095#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 */
Willy Tarreau7005b582008-11-13 17:18:59 -080099
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
Willy Tarreau7005b582008-11-13 17:18:59 -0800124#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
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300133#define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
Willy Tarreau7005b582008-11-13 17:18:59 -0800134#define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
135
Mariusz Gorski36277d42014-11-27 22:36:47 +0100136#define NOT_SET -1
137
Willy Tarreau7005b582008-11-13 17:18:59 -0800138/* macros to simplify use of the parallel port */
139#define r_ctr(x) (parport_read_control((x)->port))
140#define r_dtr(x) (parport_read_data((x)->port))
141#define r_str(x) (parport_read_status((x)->port))
Toshiaki Yamane6ebb56d2012-07-25 12:18:12 +0900142#define w_ctr(x, y) (parport_write_control((x)->port, (y)))
143#define w_dtr(x, y) (parport_write_data((x)->port, (y)))
Willy Tarreau7005b582008-11-13 17:18:59 -0800144
145/* this defines which bits are to be used and which ones to be ignored */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300146/* logical or of the output bits involved in the scan matrix */
147static __u8 scan_mask_o;
148/* logical or of the input bits involved in the scan matrix */
149static __u8 scan_mask_i;
Willy Tarreau7005b582008-11-13 17:18:59 -0800150
Willy Tarreau698b1512008-11-22 11:29:33 +0100151typedef __u64 pmask_t;
Willy Tarreau7005b582008-11-13 17:18:59 -0800152
153enum input_type {
Willy Tarreau698b1512008-11-22 11:29:33 +0100154 INPUT_TYPE_STD,
155 INPUT_TYPE_KBD,
Willy Tarreau7005b582008-11-13 17:18:59 -0800156};
157
158enum input_state {
Willy Tarreau698b1512008-11-22 11:29:33 +0100159 INPUT_ST_LOW,
160 INPUT_ST_RISING,
161 INPUT_ST_HIGH,
162 INPUT_ST_FALLING,
Willy Tarreau7005b582008-11-13 17:18:59 -0800163};
164
165struct logical_input {
Willy Tarreau698b1512008-11-22 11:29:33 +0100166 struct list_head list;
167 pmask_t mask;
168 pmask_t value;
169 enum input_type type;
170 enum input_state state;
171 __u8 rise_time, fall_time;
172 __u8 rise_timer, fall_timer, high_timer;
Willy Tarreau7005b582008-11-13 17:18:59 -0800173
Willy Tarreau698b1512008-11-22 11:29:33 +0100174 union {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300175 struct { /* valid when type == INPUT_TYPE_STD */
Monam Agarwal68d386b2014-02-25 19:40:49 +0530176 void (*press_fct)(int);
177 void (*release_fct)(int);
Willy Tarreau698b1512008-11-22 11:29:33 +0100178 int press_data;
179 int release_data;
180 } std;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300181 struct { /* valid when type == INPUT_TYPE_KBD */
182 /* strings can be non null-terminated */
Willy Tarreau698b1512008-11-22 11:29:33 +0100183 char press_str[sizeof(void *) + sizeof(int)];
184 char repeat_str[sizeof(void *) + sizeof(int)];
185 char release_str[sizeof(void *) + sizeof(int)];
186 } kbd;
187 } u;
Willy Tarreau7005b582008-11-13 17:18:59 -0800188};
189
Peter Huewe36d20412013-02-15 13:47:05 +0100190static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
Willy Tarreau7005b582008-11-13 17:18:59 -0800191
192/* physical contacts history
193 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
194 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
195 * corresponds to the ground.
196 * Within each group, bits are stored in the same order as read on the port :
197 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
198 * So, each __u64 (or pmask_t) is represented like this :
199 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
200 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
201 */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300202
203/* what has just been read from the I/O ports */
204static pmask_t phys_read;
205/* previous phys_read */
206static pmask_t phys_read_prev;
207/* stabilized phys_read (phys_read|phys_read_prev) */
208static pmask_t phys_curr;
209/* previous phys_curr */
210static pmask_t phys_prev;
211/* 0 means that at least one logical signal needs be computed */
212static char inputs_stable;
Willy Tarreau7005b582008-11-13 17:18:59 -0800213
Willy Tarreau7005b582008-11-13 17:18:59 -0800214/* these variables are specific to the keypad */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100215static struct {
216 bool enabled;
217} keypad;
218
Willy Tarreau7005b582008-11-13 17:18:59 -0800219static char keypad_buffer[KEYPAD_BUFFER];
Willy Tarreau698b1512008-11-22 11:29:33 +0100220static int keypad_buflen;
221static int keypad_start;
222static char keypressed;
Willy Tarreau7005b582008-11-13 17:18:59 -0800223static wait_queue_head_t keypad_read_wait;
Willy Tarreau7005b582008-11-13 17:18:59 -0800224
225/* lcd-specific variables */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100226static struct {
227 bool enabled;
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100228 int height;
229 int width;
230 int bwidth;
231 int hwidth;
232 int charset;
233 int proto;
234 /* TODO: use union here? */
235 struct {
236 int e;
237 int rs;
238 int rw;
239 int cl;
240 int da;
241 int bl;
242 } pins;
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100243} lcd;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300244
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100245/* Needed only for init */
246static int selected_lcd_type = NOT_SET;
247
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300248/* contains the LCD config state */
249static unsigned long int lcd_flags;
250/* contains the LCD X offset */
251static unsigned long int lcd_addr_x;
252/* contains the LCD Y offset */
253static unsigned long int lcd_addr_y;
254/* current escape sequence, 0 terminated */
255static char lcd_escape[LCD_ESCAPE_LEN + 1];
256/* not in escape state. >=0 = escape cmd len */
257static int lcd_escape_len = -1;
Willy Tarreau7005b582008-11-13 17:18:59 -0800258
Willy Tarreau7005b582008-11-13 17:18:59 -0800259/*
260 * Bit masks to convert LCD signals to parallel port outputs.
261 * _d_ are values for data port, _c_ are for control port.
262 * [0] = signal OFF, [1] = signal ON, [2] = mask
263 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100264#define BIT_CLR 0
265#define BIT_SET 1
266#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800267#define BIT_STATES 3
268/*
269 * one entry for each bit on the LCD
270 */
271#define LCD_BIT_E 0
272#define LCD_BIT_RS 1
273#define LCD_BIT_RW 2
274#define LCD_BIT_BL 3
275#define LCD_BIT_CL 4
276#define LCD_BIT_DA 5
277#define LCD_BITS 6
278
279/*
280 * each bit can be either connected to a DATA or CTRL port
281 */
282#define LCD_PORT_C 0
283#define LCD_PORT_D 1
284#define LCD_PORTS 2
285
286static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
287
288/*
289 * LCD protocols
290 */
291#define LCD_PROTO_PARALLEL 0
292#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400293#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800294
295/*
296 * LCD character sets
297 */
298#define LCD_CHARSET_NORMAL 0
299#define LCD_CHARSET_KS0074 1
300
301/*
302 * LCD types
303 */
304#define LCD_TYPE_NONE 0
305#define LCD_TYPE_OLD 1
306#define LCD_TYPE_KS0074 2
307#define LCD_TYPE_HANTRONIX 3
308#define LCD_TYPE_NEXCOM 4
309#define LCD_TYPE_CUSTOM 5
310
311/*
312 * keypad types
313 */
314#define KEYPAD_TYPE_NONE 0
315#define KEYPAD_TYPE_OLD 1
316#define KEYPAD_TYPE_NEW 2
317#define KEYPAD_TYPE_NEXCOM 3
318
319/*
320 * panel profiles
321 */
322#define PANEL_PROFILE_CUSTOM 0
323#define PANEL_PROFILE_OLD 1
324#define PANEL_PROFILE_NEW 2
325#define PANEL_PROFILE_HANTRONIX 3
326#define PANEL_PROFILE_NEXCOM 4
327#define PANEL_PROFILE_LARGE 5
328
329/*
330 * Construct custom config from the kernel's configuration
331 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800332#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100333#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100334#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
335#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100336#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800337#define DEFAULT_LCD_WIDTH 40
338#define DEFAULT_LCD_BWIDTH 40
339#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100340#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800341#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
342
343#define DEFAULT_LCD_PIN_E PIN_AUTOLF
344#define DEFAULT_LCD_PIN_RS PIN_SELECP
345#define DEFAULT_LCD_PIN_RW PIN_INITP
346#define DEFAULT_LCD_PIN_SCL PIN_STROBE
347#define DEFAULT_LCD_PIN_SDA PIN_D0
348#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800349
Willy Tarreau7005b582008-11-13 17:18:59 -0800350#ifdef CONFIG_PANEL_PARPORT
351#undef DEFAULT_PARPORT
352#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
353#endif
354
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100355#ifdef CONFIG_PANEL_PROFILE
356#undef DEFAULT_PROFILE
357#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
358#endif
359
Willy Tarreau698b1512008-11-22 11:29:33 +0100360#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800361#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100362#undef DEFAULT_KEYPAD_TYPE
363#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800364#endif
365
Willy Tarreau7005b582008-11-13 17:18:59 -0800366#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100367#undef DEFAULT_LCD_TYPE
368#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800369#endif
370
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100371#ifdef CONFIG_PANEL_LCD_HEIGHT
372#undef DEFAULT_LCD_HEIGHT
373#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
374#endif
375
Willy Tarreau7005b582008-11-13 17:18:59 -0800376#ifdef CONFIG_PANEL_LCD_WIDTH
377#undef DEFAULT_LCD_WIDTH
378#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
379#endif
380
381#ifdef CONFIG_PANEL_LCD_BWIDTH
382#undef DEFAULT_LCD_BWIDTH
383#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
384#endif
385
386#ifdef CONFIG_PANEL_LCD_HWIDTH
387#undef DEFAULT_LCD_HWIDTH
388#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
389#endif
390
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100391#ifdef CONFIG_PANEL_LCD_CHARSET
392#undef DEFAULT_LCD_CHARSET
393#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800394#endif
395
396#ifdef CONFIG_PANEL_LCD_PROTO
397#undef DEFAULT_LCD_PROTO
398#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
399#endif
400
401#ifdef CONFIG_PANEL_LCD_PIN_E
402#undef DEFAULT_LCD_PIN_E
403#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
404#endif
405
406#ifdef CONFIG_PANEL_LCD_PIN_RS
407#undef DEFAULT_LCD_PIN_RS
408#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
409#endif
410
411#ifdef CONFIG_PANEL_LCD_PIN_RW
412#undef DEFAULT_LCD_PIN_RW
413#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
414#endif
415
416#ifdef CONFIG_PANEL_LCD_PIN_SCL
417#undef DEFAULT_LCD_PIN_SCL
418#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
419#endif
420
421#ifdef CONFIG_PANEL_LCD_PIN_SDA
422#undef DEFAULT_LCD_PIN_SDA
423#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
424#endif
425
426#ifdef CONFIG_PANEL_LCD_PIN_BL
427#undef DEFAULT_LCD_PIN_BL
428#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
429#endif
430
Willy Tarreau7005b582008-11-13 17:18:59 -0800431#endif /* DEFAULT_PROFILE == 0 */
432
433/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100434
435/* Device single-open policy control */
436static atomic_t lcd_available = ATOMIC_INIT(1);
437static atomic_t keypad_available = ATOMIC_INIT(1);
438
Willy Tarreau698b1512008-11-22 11:29:33 +0100439static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800440
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100441static int lcd_initialized;
442static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800443
Willy Tarreau698b1512008-11-22 11:29:33 +0100444static int light_tempo;
Willy Tarreau7005b582008-11-13 17:18:59 -0800445
Willy Tarreau698b1512008-11-22 11:29:33 +0100446static char lcd_must_clear;
447static char lcd_left_shift;
448static char init_in_progress;
Willy Tarreau7005b582008-11-13 17:18:59 -0800449
Monam Agarwal68d386b2014-02-25 19:40:49 +0530450static void (*lcd_write_cmd)(int);
451static void (*lcd_write_data)(int);
452static void (*lcd_clear_fast)(void);
Willy Tarreau7005b582008-11-13 17:18:59 -0800453
Willy Tarreau698b1512008-11-22 11:29:33 +0100454static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800455static struct timer_list scan_timer;
456
Willy Tarreau630231772008-11-22 12:52:18 +0100457MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100458
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100459static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100460module_param(parport, int, 0000);
461MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100462
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100463static int profile = DEFAULT_PROFILE;
464module_param(profile, int, 0000);
465MODULE_PARM_DESC(profile,
466 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
467 "4=16x2 nexcom; default=40x2, old kp");
468
Mariusz Gorski36277d42014-11-27 22:36:47 +0100469static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100470module_param(keypad_type, int, 0000);
471MODULE_PARM_DESC(keypad_type,
472 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
473
Mariusz Gorski36277d42014-11-27 22:36:47 +0100474static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100475module_param(lcd_type, int, 0000);
476MODULE_PARM_DESC(lcd_type,
477 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
478
Mariusz Gorski36277d42014-11-27 22:36:47 +0100479static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100480module_param(lcd_height, int, 0000);
481MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100482
Mariusz Gorski36277d42014-11-27 22:36:47 +0100483static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100484module_param(lcd_width, int, 0000);
485MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100486
Mariusz Gorski36277d42014-11-27 22:36:47 +0100487static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100488module_param(lcd_bwidth, int, 0000);
489MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100490
Mariusz Gorski36277d42014-11-27 22:36:47 +0100491static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100492module_param(lcd_hwidth, int, 0000);
493MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100494
Mariusz Gorski36277d42014-11-27 22:36:47 +0100495static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100496module_param(lcd_charset, int, 0000);
497MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100498
Mariusz Gorski36277d42014-11-27 22:36:47 +0100499static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100500module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300501MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200502 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100503
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100504/*
505 * These are the parallel port pins the LCD control signals are connected to.
506 * Set this to 0 if the signal is not used. Set it to its opposite value
507 * (negative) if the signal is negated. -MAXINT is used to indicate that the
508 * pin has not been explicitly specified.
509 *
Willy Tarreau630231772008-11-22 12:52:18 +0100510 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100511 */
512
513static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100514module_param(lcd_e_pin, int, 0000);
515MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530516 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100517
518static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100519module_param(lcd_rs_pin, int, 0000);
520MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530521 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100522
523static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100524module_param(lcd_rw_pin, int, 0000);
525MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530526 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100527
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100528static int lcd_cl_pin = PIN_NOT_SET;
529module_param(lcd_cl_pin, int, 0000);
530MODULE_PARM_DESC(lcd_cl_pin,
531 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100532
533static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100534module_param(lcd_da_pin, int, 0000);
535MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530536 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100537
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100538static int lcd_bl_pin = PIN_NOT_SET;
539module_param(lcd_bl_pin, int, 0000);
540MODULE_PARM_DESC(lcd_bl_pin,
541 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
542
543/* Deprecated module parameters - consider not using them anymore */
544
Mariusz Gorski36277d42014-11-27 22:36:47 +0100545static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100546module_param(lcd_enabled, int, 0000);
547MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
548
Mariusz Gorski36277d42014-11-27 22:36:47 +0100549static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100550module_param(keypad_enabled, int, 0000);
551MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
552
Willy Tarreau7005b582008-11-13 17:18:59 -0800553
Peter Huewe36d20412013-02-15 13:47:05 +0100554static const unsigned char *lcd_char_conv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800555
556/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100557static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100558 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
559 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
560 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
561 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
562 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
563 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
564 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
565 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
566 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
567 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
568 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
569 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
570 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
571 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
572 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
573 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
574 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
575 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
576 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
577 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
578 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
579 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
580 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
581 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
582 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
583 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
584 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
585 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
586 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
587 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
588 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
589 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
590 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800591};
592
Peter Huewe36d20412013-02-15 13:47:05 +0100593static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100594 {"S0", "Left\n", "Left\n", ""},
595 {"S1", "Down\n", "Down\n", ""},
596 {"S2", "Up\n", "Up\n", ""},
597 {"S3", "Right\n", "Right\n", ""},
598 {"S4", "Esc\n", "Esc\n", ""},
599 {"S5", "Ret\n", "Ret\n", ""},
600 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800601};
602
603/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100604static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100605 {"S0", "Left\n", "Left\n", ""},
606 {"S1", "Down\n", "Down\n", ""},
607 {"S2", "Up\n", "Up\n", ""},
608 {"S3", "Right\n", "Right\n", ""},
609 {"S4s5", "", "Esc\n", "Esc\n"},
610 {"s4S5", "", "Ret\n", "Ret\n"},
611 {"S4S5", "Help\n", "", ""},
612 /* add new signals above this line */
613 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800614};
615
616/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100617static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100618 {"a-p-e-", "Down\n", "Down\n", ""},
619 {"a-p-E-", "Ret\n", "Ret\n", ""},
620 {"a-P-E-", "Esc\n", "Esc\n", ""},
621 {"a-P-e-", "Up\n", "Up\n", ""},
622 /* add new signals above this line */
623 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800624};
625
Peter Huewe36d20412013-02-15 13:47:05 +0100626static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800627
628/* FIXME: this should be converted to a bit array containing signals states */
629static struct {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300630 unsigned char e; /* parallel LCD E (data latch on falling edge) */
631 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
632 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
633 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
634 unsigned char cl; /* serial LCD clock (latch on rising edge) */
635 unsigned char da; /* serial LCD data */
Willy Tarreau7005b582008-11-13 17:18:59 -0800636} bits;
637
638static void init_scan_timer(void);
639
640/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100641static int set_data_bits(void)
642{
643 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800644
Willy Tarreau698b1512008-11-22 11:29:33 +0100645 val = r_dtr(pprt);
646 for (bit = 0; bit < LCD_BITS; bit++)
647 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800648
Willy Tarreau698b1512008-11-22 11:29:33 +0100649 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
650 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
651 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
652 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
653 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
654 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800655
Willy Tarreau698b1512008-11-22 11:29:33 +0100656 w_dtr(pprt, val);
657 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800658}
659
660/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100661static int set_ctrl_bits(void)
662{
663 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800664
Willy Tarreau698b1512008-11-22 11:29:33 +0100665 val = r_ctr(pprt);
666 for (bit = 0; bit < LCD_BITS; bit++)
667 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800668
Willy Tarreau698b1512008-11-22 11:29:33 +0100669 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
670 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
671 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
672 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
673 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
674 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800675
Willy Tarreau698b1512008-11-22 11:29:33 +0100676 w_ctr(pprt, val);
677 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800678}
679
680/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530681static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100682{
683 set_data_bits();
684 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800685}
686
687/*
688 * Converts a parallel port pin (from -25 to 25) to data and control ports
689 * masks, and data and control port bits. The signal will be considered
690 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
691 *
692 * Result will be used this way :
693 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
694 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
695 */
Peter Huewe36d20412013-02-15 13:47:05 +0100696static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100697{
698 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800699
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200700 d_val[0] = 0;
701 c_val[0] = 0;
702 d_val[1] = 0;
703 c_val[1] = 0;
704 d_val[2] = 0xFF;
705 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800706
Willy Tarreau698b1512008-11-22 11:29:33 +0100707 if (pin == 0)
708 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800709
Willy Tarreau698b1512008-11-22 11:29:33 +0100710 inv = (pin < 0);
711 if (inv)
712 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800713
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200714 d_bit = 0;
715 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800716
Willy Tarreau698b1512008-11-22 11:29:33 +0100717 switch (pin) {
718 case PIN_STROBE: /* strobe, inverted */
719 c_bit = PNL_PSTROBE;
720 inv = !inv;
721 break;
722 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
723 d_bit = 1 << (pin - 2);
724 break;
725 case PIN_AUTOLF: /* autofeed, inverted */
726 c_bit = PNL_PAUTOLF;
727 inv = !inv;
728 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300729 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100730 c_bit = PNL_PINITP;
731 break;
732 case PIN_SELECP: /* select_in, inverted */
733 c_bit = PNL_PSELECP;
734 inv = !inv;
735 break;
736 default: /* unknown pin, ignore */
737 break;
738 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800739
Willy Tarreau698b1512008-11-22 11:29:33 +0100740 if (c_bit) {
741 c_val[2] &= ~c_bit;
742 c_val[!inv] = c_bit;
743 } else if (d_bit) {
744 d_val[2] &= ~d_bit;
745 d_val[!inv] = d_bit;
746 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800747}
748
749/* sleeps that many milliseconds with a reschedule */
Willy Tarreau698b1512008-11-22 11:29:33 +0100750static void long_sleep(int ms)
751{
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200752 if (in_interrupt()) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100753 mdelay(ms);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200754 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +0100755 current->state = TASK_INTERRUPTIBLE;
756 schedule_timeout((ms * HZ + 999) / 1000);
757 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800758}
759
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300760/* send a serial byte to the LCD panel. The caller is responsible for locking
761 if needed. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100762static void lcd_send_serial(int byte)
763{
764 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800765
Willy Tarreau698b1512008-11-22 11:29:33 +0100766 /* the data bit is set on D0, and the clock on STROBE.
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300767 * LCD reads D0 on STROBE's rising edge. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100768 for (bit = 0; bit < 8; bit++) {
769 bits.cl = BIT_CLR; /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530770 panel_set_bits();
Willy Tarreau698b1512008-11-22 11:29:33 +0100771 bits.da = byte & 1;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530772 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300773 udelay(2); /* maintain the data during 2 us before CLK up */
Willy Tarreau698b1512008-11-22 11:29:33 +0100774 bits.cl = BIT_SET; /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530775 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300776 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100777 byte >>= 1;
778 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800779}
780
781/* turn the backlight on or off */
Willy Tarreau698b1512008-11-22 11:29:33 +0100782static void lcd_backlight(int on)
783{
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100784 if (lcd.pins.bl == PIN_NONE)
Willy Tarreau698b1512008-11-22 11:29:33 +0100785 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800786
Justin P. Mattock6975e182012-03-19 08:17:52 -0700787 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800788 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100789 bits.bl = on;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530790 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800791 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800792}
793
794/* send a command to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100795static void lcd_write_cmd_s(int cmd)
796{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800797 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100798 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
799 lcd_send_serial(cmd & 0x0F);
800 lcd_send_serial((cmd >> 4) & 0x0F);
801 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800802 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800803}
804
805/* send data to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100806static void lcd_write_data_s(int data)
807{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800808 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100809 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
810 lcd_send_serial(data & 0x0F);
811 lcd_send_serial((data >> 4) & 0x0F);
812 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800813 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800814}
815
816/* send a command to the LCD panel in 8 bits parallel mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100817static void lcd_write_cmd_p8(int cmd)
818{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800819 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800820 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100821 w_dtr(pprt, cmd);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300822 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800823
Willy Tarreau698b1512008-11-22 11:29:33 +0100824 bits.e = BIT_SET;
825 bits.rs = BIT_CLR;
826 bits.rw = BIT_CLR;
Willy Tarreau7005b582008-11-13 17:18:59 -0800827 set_ctrl_bits();
828
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300829 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800830
831 bits.e = BIT_CLR;
832 set_ctrl_bits();
833
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300834 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800835 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100836}
Willy Tarreau7005b582008-11-13 17:18:59 -0800837
Willy Tarreau698b1512008-11-22 11:29:33 +0100838/* send data to the LCD panel in 8 bits parallel mode */
839static void lcd_write_data_p8(int data)
840{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800841 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100842 /* present the data to the data port */
843 w_dtr(pprt, data);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300844 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100845
846 bits.e = BIT_SET;
847 bits.rs = BIT_SET;
848 bits.rw = BIT_CLR;
849 set_ctrl_bits();
850
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300851 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100852
853 bits.e = BIT_CLR;
854 set_ctrl_bits();
855
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300856 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800857 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100858}
859
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400860/* send a command to the TI LCD panel */
861static void lcd_write_cmd_tilcd(int cmd)
862{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800863 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400864 /* present the data to the control port */
865 w_ctr(pprt, cmd);
866 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800867 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400868}
869
870/* send data to the TI LCD panel */
871static void lcd_write_data_tilcd(int data)
872{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800873 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400874 /* present the data to the data port */
875 w_dtr(pprt, data);
876 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800877 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400878}
879
Willy Tarreau698b1512008-11-22 11:29:33 +0100880static void lcd_gotoxy(void)
881{
882 lcd_write_cmd(0x80 /* set DDRAM address */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100883 | (lcd_addr_y ? lcd.hwidth : 0)
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300884 /* we force the cursor to stay at the end of the
885 line if it wants to go farther */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100886 | ((lcd_addr_x < lcd.bwidth) ? lcd_addr_x &
887 (lcd.hwidth - 1) : lcd.bwidth - 1));
Willy Tarreau698b1512008-11-22 11:29:33 +0100888}
889
890static void lcd_print(char c)
891{
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100892 if (lcd_addr_x < lcd.bwidth) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100893 if (lcd_char_conv != NULL)
894 c = lcd_char_conv[(unsigned char)c];
895 lcd_write_data(c);
896 lcd_addr_x++;
897 }
898 /* prevents the cursor from wrapping onto the next line */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100899 if (lcd_addr_x == lcd.bwidth)
Willy Tarreau698b1512008-11-22 11:29:33 +0100900 lcd_gotoxy();
901}
902
903/* fills the display with spaces and resets X/Y */
904static void lcd_clear_fast_s(void)
905{
906 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200907
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200908 lcd_addr_x = 0;
909 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100910 lcd_gotoxy();
911
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800912 spin_lock_irq(&pprt_lock);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100913 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100914 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
915 lcd_send_serial(' ' & 0x0F);
916 lcd_send_serial((' ' >> 4) & 0x0F);
917 udelay(40); /* the shortest data takes at least 40 us */
918 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800919 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100920
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200921 lcd_addr_x = 0;
922 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100923 lcd_gotoxy();
924}
925
926/* fills the display with spaces and resets X/Y */
927static void lcd_clear_fast_p8(void)
928{
929 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200930
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200931 lcd_addr_x = 0;
932 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100933 lcd_gotoxy();
934
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800935 spin_lock_irq(&pprt_lock);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100936 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100937 /* present the data to the data port */
938 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300939
940 /* maintain the data during 20 us before the strobe */
941 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100942
943 bits.e = BIT_SET;
944 bits.rs = BIT_SET;
945 bits.rw = BIT_CLR;
946 set_ctrl_bits();
947
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300948 /* maintain the strobe during 40 us */
949 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100950
951 bits.e = BIT_CLR;
952 set_ctrl_bits();
953
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300954 /* the shortest data takes at least 45 us */
955 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100956 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800957 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100958
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200959 lcd_addr_x = 0;
960 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100961 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -0800962}
963
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400964/* fills the display with spaces and resets X/Y */
965static void lcd_clear_fast_tilcd(void)
966{
967 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200968
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200969 lcd_addr_x = 0;
970 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400971 lcd_gotoxy();
972
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800973 spin_lock_irq(&pprt_lock);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100974 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400975 /* present the data to the data port */
976 w_dtr(pprt, ' ');
977 udelay(60);
978 }
979
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800980 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400981
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200982 lcd_addr_x = 0;
983 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400984 lcd_gotoxy();
985}
986
Willy Tarreau7005b582008-11-13 17:18:59 -0800987/* clears the display and resets X/Y */
Willy Tarreau698b1512008-11-22 11:29:33 +0100988static void lcd_clear_display(void)
989{
990 lcd_write_cmd(0x01); /* clear display */
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200991 lcd_addr_x = 0;
992 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100993 /* we must wait a few milliseconds (15) */
994 long_sleep(15);
Willy Tarreau7005b582008-11-13 17:18:59 -0800995}
996
Willy Tarreau698b1512008-11-22 11:29:33 +0100997static void lcd_init_display(void)
998{
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100999 lcd_flags = ((lcd.height > 1) ? LCD_FLAG_N : 0)
Willy Tarreau698b1512008-11-22 11:29:33 +01001000 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
Willy Tarreau7005b582008-11-13 17:18:59 -08001001
Willy Tarreau698b1512008-11-22 11:29:33 +01001002 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
Willy Tarreau7005b582008-11-13 17:18:59 -08001003
Willy Tarreau698b1512008-11-22 11:29:33 +01001004 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1005 long_sleep(10);
1006 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1007 long_sleep(10);
1008 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
1009 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001010
Willy Tarreau698b1512008-11-22 11:29:33 +01001011 lcd_write_cmd(0x30 /* set font height and lines number */
1012 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1013 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
1014 );
1015 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001016
Willy Tarreau698b1512008-11-22 11:29:33 +01001017 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
1018 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001019
Willy Tarreau698b1512008-11-22 11:29:33 +01001020 lcd_write_cmd(0x08 /* set display mode */
1021 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1022 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1023 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
1024 );
Willy Tarreau7005b582008-11-13 17:18:59 -08001025
Willy Tarreau698b1512008-11-22 11:29:33 +01001026 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08001027
Willy Tarreau698b1512008-11-22 11:29:33 +01001028 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001029
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001030 /* entry mode set : increment, cursor shifting */
1031 lcd_write_cmd(0x06);
Willy Tarreau7005b582008-11-13 17:18:59 -08001032
Willy Tarreau698b1512008-11-22 11:29:33 +01001033 lcd_clear_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001034}
1035
1036/*
1037 * These are the file operation function for user access to /dev/lcd
1038 * This function can also be called from inside the kernel, by
1039 * setting file and ppos to NULL.
1040 *
1041 */
1042
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001043static inline int handle_lcd_special_code(void)
1044{
1045 /* LCD special codes */
1046
1047 int processed = 0;
1048
1049 char *esc = lcd_escape + 2;
1050 int oldflags = lcd_flags;
1051
1052 /* check for display mode flags */
1053 switch (*esc) {
1054 case 'D': /* Display ON */
1055 lcd_flags |= LCD_FLAG_D;
1056 processed = 1;
1057 break;
1058 case 'd': /* Display OFF */
1059 lcd_flags &= ~LCD_FLAG_D;
1060 processed = 1;
1061 break;
1062 case 'C': /* Cursor ON */
1063 lcd_flags |= LCD_FLAG_C;
1064 processed = 1;
1065 break;
1066 case 'c': /* Cursor OFF */
1067 lcd_flags &= ~LCD_FLAG_C;
1068 processed = 1;
1069 break;
1070 case 'B': /* Blink ON */
1071 lcd_flags |= LCD_FLAG_B;
1072 processed = 1;
1073 break;
1074 case 'b': /* Blink OFF */
1075 lcd_flags &= ~LCD_FLAG_B;
1076 processed = 1;
1077 break;
1078 case '+': /* Back light ON */
1079 lcd_flags |= LCD_FLAG_L;
1080 processed = 1;
1081 break;
1082 case '-': /* Back light OFF */
1083 lcd_flags &= ~LCD_FLAG_L;
1084 processed = 1;
1085 break;
1086 case '*':
1087 /* flash back light using the keypad timer */
1088 if (scan_timer.function != NULL) {
1089 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1090 lcd_backlight(1);
1091 light_tempo = FLASH_LIGHT_TEMPO;
1092 }
1093 processed = 1;
1094 break;
1095 case 'f': /* Small Font */
1096 lcd_flags &= ~LCD_FLAG_F;
1097 processed = 1;
1098 break;
1099 case 'F': /* Large Font */
1100 lcd_flags |= LCD_FLAG_F;
1101 processed = 1;
1102 break;
1103 case 'n': /* One Line */
1104 lcd_flags &= ~LCD_FLAG_N;
1105 processed = 1;
1106 break;
1107 case 'N': /* Two Lines */
1108 lcd_flags |= LCD_FLAG_N;
1109 break;
1110 case 'l': /* Shift Cursor Left */
1111 if (lcd_addr_x > 0) {
1112 /* back one char if not at end of line */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001113 if (lcd_addr_x < lcd.bwidth)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001114 lcd_write_cmd(0x10);
1115 lcd_addr_x--;
1116 }
1117 processed = 1;
1118 break;
1119 case 'r': /* shift cursor right */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001120 if (lcd_addr_x < lcd.width) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001121 /* allow the cursor to pass the end of the line */
1122 if (lcd_addr_x <
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001123 (lcd.bwidth - 1))
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001124 lcd_write_cmd(0x14);
1125 lcd_addr_x++;
1126 }
1127 processed = 1;
1128 break;
1129 case 'L': /* shift display left */
1130 lcd_left_shift++;
1131 lcd_write_cmd(0x18);
1132 processed = 1;
1133 break;
1134 case 'R': /* shift display right */
1135 lcd_left_shift--;
1136 lcd_write_cmd(0x1C);
1137 processed = 1;
1138 break;
1139 case 'k': { /* kill end of line */
1140 int x;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001141
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001142 for (x = lcd_addr_x; x < lcd.bwidth; x++)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001143 lcd_write_data(' ');
1144
1145 /* restore cursor position */
1146 lcd_gotoxy();
1147 processed = 1;
1148 break;
1149 }
1150 case 'I': /* reinitialize display */
1151 lcd_init_display();
1152 lcd_left_shift = 0;
1153 processed = 1;
1154 break;
1155 case 'G': {
1156 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1157 * and '7', representing the numerical ASCII code of the
1158 * redefined character, and <xx...xx> a sequence of 16
1159 * hex digits representing 8 bytes for each character.
1160 * Most LCDs will only use 5 lower bits of the 7 first
1161 * bytes.
1162 */
1163
1164 unsigned char cgbytes[8];
1165 unsigned char cgaddr;
1166 int cgoffset;
1167 int shift;
1168 char value;
1169 int addr;
1170
1171 if (strchr(esc, ';') == NULL)
1172 break;
1173
1174 esc++;
1175
1176 cgaddr = *(esc++) - '0';
1177 if (cgaddr > 7) {
1178 processed = 1;
1179 break;
1180 }
1181
1182 cgoffset = 0;
1183 shift = 0;
1184 value = 0;
1185 while (*esc && cgoffset < 8) {
1186 shift ^= 4;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001187 if (*esc >= '0' && *esc <= '9') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001188 value |= (*esc - '0') << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001189 } else if (*esc >= 'A' && *esc <= 'Z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001190 value |= (*esc - 'A' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001191 } else if (*esc >= 'a' && *esc <= 'z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001192 value |= (*esc - 'a' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001193 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001194 esc++;
1195 continue;
1196 }
1197
1198 if (shift == 0) {
1199 cgbytes[cgoffset++] = value;
1200 value = 0;
1201 }
1202
1203 esc++;
1204 }
1205
1206 lcd_write_cmd(0x40 | (cgaddr * 8));
1207 for (addr = 0; addr < cgoffset; addr++)
1208 lcd_write_data(cgbytes[addr]);
1209
1210 /* ensures that we stop writing to CGRAM */
1211 lcd_gotoxy();
1212 processed = 1;
1213 break;
1214 }
1215 case 'x': /* gotoxy : LxXXX[yYYY]; */
1216 case 'y': /* gotoxy : LyYYY[xXXX]; */
1217 if (strchr(esc, ';') == NULL)
1218 break;
1219
1220 while (*esc) {
1221 if (*esc == 'x') {
1222 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001223 if (kstrtoul(esc, 10, &lcd_addr_x) < 0)
1224 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001225 } else if (*esc == 'y') {
1226 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001227 if (kstrtoul(esc, 10, &lcd_addr_y) < 0)
1228 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001229 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001230 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001231 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001232 }
1233
1234 lcd_gotoxy();
1235 processed = 1;
1236 break;
1237 }
1238
Adam Buchbinderf2635892012-09-19 21:51:07 -04001239 /* Check whether one flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001240 if (oldflags != lcd_flags) {
1241 /* check whether one of B,C,D flags were changed */
1242 if ((oldflags ^ lcd_flags) &
1243 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1244 /* set display mode */
1245 lcd_write_cmd(0x08
1246 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1247 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1248 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1249 /* check whether one of F,N flags was changed */
1250 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1251 lcd_write_cmd(0x30
1252 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1253 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
Adam Buchbinderf2635892012-09-19 21:51:07 -04001254 /* check whether L flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001255 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1256 if (lcd_flags & (LCD_FLAG_L))
1257 lcd_backlight(1);
1258 else if (light_tempo == 0)
1259 /* switch off the light only when the tempo
1260 lighting is gone */
1261 lcd_backlight(0);
1262 }
1263 }
1264
1265 return processed;
1266}
1267
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001268static void lcd_write_char(char c)
Willy Tarreau698b1512008-11-22 11:29:33 +01001269{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001270 /* first, we'll test if we're in escape mode */
1271 if ((c != '\n') && lcd_escape_len >= 0) {
1272 /* yes, let's add this char to the buffer */
1273 lcd_escape[lcd_escape_len++] = c;
1274 lcd_escape[lcd_escape_len] = 0;
1275 } else {
1276 /* aborts any previous escape sequence */
1277 lcd_escape_len = -1;
1278
1279 switch (c) {
1280 case LCD_ESCAPE_CHAR:
1281 /* start of an escape sequence */
1282 lcd_escape_len = 0;
1283 lcd_escape[lcd_escape_len] = 0;
1284 break;
1285 case '\b':
1286 /* go back one char and clear it */
1287 if (lcd_addr_x > 0) {
1288 /* check if we're not at the
1289 end of the line */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001290 if (lcd_addr_x < lcd.bwidth)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001291 /* back one char */
1292 lcd_write_cmd(0x10);
1293 lcd_addr_x--;
1294 }
1295 /* replace with a space */
1296 lcd_write_data(' ');
1297 /* back one char again */
1298 lcd_write_cmd(0x10);
1299 break;
1300 case '\014':
1301 /* quickly clear the display */
1302 lcd_clear_fast();
1303 break;
1304 case '\n':
1305 /* flush the remainder of the current line and
1306 go to the beginning of the next line */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001307 for (; lcd_addr_x < lcd.bwidth; lcd_addr_x++)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001308 lcd_write_data(' ');
1309 lcd_addr_x = 0;
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001310 lcd_addr_y = (lcd_addr_y + 1) % lcd.height;
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001311 lcd_gotoxy();
1312 break;
1313 case '\r':
1314 /* go to the beginning of the same line */
1315 lcd_addr_x = 0;
1316 lcd_gotoxy();
1317 break;
1318 case '\t':
1319 /* print a space instead of the tab */
1320 lcd_print(' ');
1321 break;
1322 default:
1323 /* simply print this char */
1324 lcd_print(c);
1325 break;
1326 }
1327 }
1328
1329 /* now we'll see if we're in an escape mode and if the current
1330 escape sequence can be understood. */
1331 if (lcd_escape_len >= 2) {
1332 int processed = 0;
1333
1334 if (!strcmp(lcd_escape, "[2J")) {
1335 /* clear the display */
1336 lcd_clear_fast();
1337 processed = 1;
1338 } else if (!strcmp(lcd_escape, "[H")) {
1339 /* cursor to home */
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001340 lcd_addr_x = 0;
1341 lcd_addr_y = 0;
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001342 lcd_gotoxy();
1343 processed = 1;
1344 }
1345 /* codes starting with ^[[L */
1346 else if ((lcd_escape_len >= 3) &&
1347 (lcd_escape[0] == '[') &&
1348 (lcd_escape[1] == 'L')) {
1349 processed = handle_lcd_special_code();
1350 }
1351
1352 /* LCD special escape codes */
1353 /* flush the escape sequence if it's been processed
1354 or if it is getting too long. */
1355 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1356 lcd_escape_len = -1;
1357 } /* escape codes */
1358}
1359
1360static ssize_t lcd_write(struct file *file,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001361 const char __user *buf, size_t count, loff_t *ppos)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001362{
1363 const char __user *tmp = buf;
Willy Tarreau698b1512008-11-22 11:29:33 +01001364 char c;
Willy Tarreau7005b582008-11-13 17:18:59 -08001365
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001366 for (; count-- > 0; (*ppos)++, tmp++) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001367 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001368 /* let's be a little nice with other processes
1369 that need some CPU */
1370 schedule();
Willy Tarreau7005b582008-11-13 17:18:59 -08001371
Bastien Armand6a4193a2014-04-23 19:42:11 +02001372 if (get_user(c, tmp))
Willy Tarreau698b1512008-11-22 11:29:33 +01001373 return -EFAULT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001374
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001375 lcd_write_char(c);
Willy Tarreau7005b582008-11-13 17:18:59 -08001376 }
1377
Willy Tarreau698b1512008-11-22 11:29:33 +01001378 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001379}
1380
Willy Tarreau698b1512008-11-22 11:29:33 +01001381static int lcd_open(struct inode *inode, struct file *file)
1382{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001383 if (!atomic_dec_and_test(&lcd_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001384 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001385
Willy Tarreau698b1512008-11-22 11:29:33 +01001386 if (file->f_mode & FMODE_READ) /* device is write-only */
1387 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001388
Willy Tarreau698b1512008-11-22 11:29:33 +01001389 if (lcd_must_clear) {
1390 lcd_clear_display();
1391 lcd_must_clear = 0;
1392 }
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001393 return nonseekable_open(inode, file);
Willy Tarreau7005b582008-11-13 17:18:59 -08001394}
1395
Willy Tarreau698b1512008-11-22 11:29:33 +01001396static int lcd_release(struct inode *inode, struct file *file)
1397{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001398 atomic_inc(&lcd_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001399 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001400}
1401
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001402static const struct file_operations lcd_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001403 .write = lcd_write,
1404 .open = lcd_open,
1405 .release = lcd_release,
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001406 .llseek = no_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001407};
1408
1409static struct miscdevice lcd_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001410 .minor = LCD_MINOR,
1411 .name = "lcd",
1412 .fops = &lcd_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001413};
1414
Willy Tarreau7005b582008-11-13 17:18:59 -08001415/* public function usable from the kernel for any purpose */
Peter Huewe36d20412013-02-15 13:47:05 +01001416static void panel_lcd_print(const char *s)
Willy Tarreau698b1512008-11-22 11:29:33 +01001417{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001418 const char *tmp = s;
1419 int count = strlen(s);
1420
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001421 if (lcd.enabled && lcd_initialized) {
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001422 for (; count-- > 0; tmp++) {
1423 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1424 /* let's be a little nice with other processes
1425 that need some CPU */
1426 schedule();
1427
1428 lcd_write_char(*tmp);
1429 }
1430 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001431}
1432
Willy Tarreau7005b582008-11-13 17:18:59 -08001433/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +01001434static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001435{
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001436 switch (selected_lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001437 case LCD_TYPE_OLD:
1438 /* parallel mode, 8 bits */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001439 lcd.proto = LCD_PROTO_PARALLEL;
1440 lcd.charset = LCD_CHARSET_NORMAL;
1441 lcd.pins.e = PIN_STROBE;
1442 lcd.pins.rs = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -08001443
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001444 lcd.width = 40;
1445 lcd.bwidth = 40;
1446 lcd.hwidth = 64;
1447 lcd.height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001448 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001449 case LCD_TYPE_KS0074:
1450 /* serial mode, ks0074 */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001451 lcd.proto = LCD_PROTO_SERIAL;
1452 lcd.charset = LCD_CHARSET_KS0074;
1453 lcd.pins.bl = PIN_AUTOLF;
1454 lcd.pins.cl = PIN_STROBE;
1455 lcd.pins.da = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001456
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001457 lcd.width = 16;
1458 lcd.bwidth = 40;
1459 lcd.hwidth = 16;
1460 lcd.height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001461 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001462 case LCD_TYPE_NEXCOM:
1463 /* parallel mode, 8 bits, generic */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001464 lcd.proto = LCD_PROTO_PARALLEL;
1465 lcd.charset = LCD_CHARSET_NORMAL;
1466 lcd.pins.e = PIN_AUTOLF;
1467 lcd.pins.rs = PIN_SELECP;
1468 lcd.pins.rw = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001469
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001470 lcd.width = 16;
1471 lcd.bwidth = 40;
1472 lcd.hwidth = 64;
1473 lcd.height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001474 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001475 case LCD_TYPE_CUSTOM:
1476 /* customer-defined */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001477 lcd.proto = DEFAULT_LCD_PROTO;
1478 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001479 /* default geometry will be set later */
1480 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001481 case LCD_TYPE_HANTRONIX:
1482 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +01001483 default:
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001484 lcd.proto = LCD_PROTO_PARALLEL;
1485 lcd.charset = LCD_CHARSET_NORMAL;
1486 lcd.pins.e = PIN_STROBE;
1487 lcd.pins.rs = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001488
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001489 lcd.width = 16;
1490 lcd.bwidth = 40;
1491 lcd.hwidth = 64;
1492 lcd.height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001493 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001494 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001495
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001496 /* Overwrite with module params set on loading */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001497 if (lcd_height != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001498 lcd.height = lcd_height;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001499 if (lcd_width != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001500 lcd.width = lcd_width;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001501 if (lcd_bwidth != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001502 lcd.bwidth = lcd_bwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001503 if (lcd_hwidth != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001504 lcd.hwidth = lcd_hwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001505 if (lcd_charset != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001506 lcd.charset = lcd_charset;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001507 if (lcd_proto != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001508 lcd.proto = lcd_proto;
1509 if (lcd_e_pin != PIN_NOT_SET)
1510 lcd.pins.e = lcd_e_pin;
1511 if (lcd_rs_pin != PIN_NOT_SET)
1512 lcd.pins.rs = lcd_rs_pin;
1513 if (lcd_rw_pin != PIN_NOT_SET)
1514 lcd.pins.rw = lcd_rw_pin;
1515 if (lcd_cl_pin != PIN_NOT_SET)
1516 lcd.pins.cl = lcd_cl_pin;
1517 if (lcd_da_pin != PIN_NOT_SET)
1518 lcd.pins.da = lcd_da_pin;
1519 if (lcd_bl_pin != PIN_NOT_SET)
1520 lcd.pins.bl = lcd_bl_pin;
Willy Tarreau7005b582008-11-13 17:18:59 -08001521
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001522 /* this is used to catch wrong and default values */
1523 if (lcd.width <= 0)
1524 lcd.width = DEFAULT_LCD_WIDTH;
1525 if (lcd.bwidth <= 0)
1526 lcd.bwidth = DEFAULT_LCD_BWIDTH;
1527 if (lcd.hwidth <= 0)
1528 lcd.hwidth = DEFAULT_LCD_HWIDTH;
1529 if (lcd.height <= 0)
1530 lcd.height = DEFAULT_LCD_HEIGHT;
1531
1532 if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
Willy Tarreau698b1512008-11-22 11:29:33 +01001533 lcd_write_cmd = lcd_write_cmd_s;
1534 lcd_write_data = lcd_write_data_s;
1535 lcd_clear_fast = lcd_clear_fast_s;
Willy Tarreau7005b582008-11-13 17:18:59 -08001536
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001537 if (lcd.pins.cl == PIN_NOT_SET)
1538 lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
1539 if (lcd.pins.da == PIN_NOT_SET)
1540 lcd.pins.da = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001541
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001542 } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Willy Tarreau698b1512008-11-22 11:29:33 +01001543 lcd_write_cmd = lcd_write_cmd_p8;
1544 lcd_write_data = lcd_write_data_p8;
1545 lcd_clear_fast = lcd_clear_fast_p8;
Willy Tarreau7005b582008-11-13 17:18:59 -08001546
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001547 if (lcd.pins.e == PIN_NOT_SET)
1548 lcd.pins.e = DEFAULT_LCD_PIN_E;
1549 if (lcd.pins.rs == PIN_NOT_SET)
1550 lcd.pins.rs = DEFAULT_LCD_PIN_RS;
1551 if (lcd.pins.rw == PIN_NOT_SET)
1552 lcd.pins.rw = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001553 } else {
1554 lcd_write_cmd = lcd_write_cmd_tilcd;
1555 lcd_write_data = lcd_write_data_tilcd;
1556 lcd_clear_fast = lcd_clear_fast_tilcd;
Willy Tarreau698b1512008-11-22 11:29:33 +01001557 }
1558
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001559 if (lcd.pins.bl == PIN_NOT_SET)
1560 lcd.pins.bl = DEFAULT_LCD_PIN_BL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001561
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001562 if (lcd.pins.e == PIN_NOT_SET)
1563 lcd.pins.e = PIN_NONE;
1564 if (lcd.pins.rs == PIN_NOT_SET)
1565 lcd.pins.rs = PIN_NONE;
1566 if (lcd.pins.rw == PIN_NOT_SET)
1567 lcd.pins.rw = PIN_NONE;
1568 if (lcd.pins.bl == PIN_NOT_SET)
1569 lcd.pins.bl = PIN_NONE;
1570 if (lcd.pins.cl == PIN_NOT_SET)
1571 lcd.pins.cl = PIN_NONE;
1572 if (lcd.pins.da == PIN_NOT_SET)
1573 lcd.pins.da = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001574
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001575 if (lcd.charset == NOT_SET)
1576 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001577
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001578 if (lcd.charset == LCD_CHARSET_KS0074)
Willy Tarreau698b1512008-11-22 11:29:33 +01001579 lcd_char_conv = lcd_char_conv_ks0074;
1580 else
1581 lcd_char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001582
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001583 if (lcd.pins.bl != PIN_NONE)
Willy Tarreau698b1512008-11-22 11:29:33 +01001584 init_scan_timer();
Willy Tarreau7005b582008-11-13 17:18:59 -08001585
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001586 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
Willy Tarreau698b1512008-11-22 11:29:33 +01001587 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001588 pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
Willy Tarreau698b1512008-11-22 11:29:33 +01001589 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001590 pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
Willy Tarreau698b1512008-11-22 11:29:33 +01001591 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001592 pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001593 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001594 pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001595 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001596 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
Willy Tarreau698b1512008-11-22 11:29:33 +01001597 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001598
Willy Tarreau698b1512008-11-22 11:29:33 +01001599 /* before this line, we must NOT send anything to the display.
1600 * Since lcd_init_display() needs to write data, we have to
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001601 * enable mark the LCD initialized just before. */
Willy Tarreau698b1512008-11-22 11:29:33 +01001602 lcd_initialized = 1;
1603 lcd_init_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001604
Willy Tarreau698b1512008-11-22 11:29:33 +01001605 /* display a short message */
Willy Tarreau7005b582008-11-13 17:18:59 -08001606#ifdef CONFIG_PANEL_CHANGE_MESSAGE
1607#ifdef CONFIG_PANEL_BOOT_MESSAGE
Willy Tarreau698b1512008-11-22 11:29:33 +01001608 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
Willy Tarreau7005b582008-11-13 17:18:59 -08001609#endif
1610#else
Willy Tarreau698b1512008-11-22 11:29:33 +01001611 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1612 PANEL_VERSION);
Willy Tarreau7005b582008-11-13 17:18:59 -08001613#endif
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001614 lcd_addr_x = 0;
1615 lcd_addr_y = 0;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001616 /* clear the display on the next device opening */
1617 lcd_must_clear = 1;
Willy Tarreau698b1512008-11-22 11:29:33 +01001618 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -08001619}
1620
Willy Tarreau7005b582008-11-13 17:18:59 -08001621/*
1622 * These are the file operation function for user access to /dev/keypad
1623 */
1624
Willy Tarreau698b1512008-11-22 11:29:33 +01001625static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001626 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001627{
Willy Tarreau698b1512008-11-22 11:29:33 +01001628 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001629 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001630
Willy Tarreau698b1512008-11-22 11:29:33 +01001631 if (keypad_buflen == 0) {
1632 if (file->f_flags & O_NONBLOCK)
1633 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001634
Arnd Bergmann310df692014-01-02 13:07:35 +01001635 if (wait_event_interruptible(keypad_read_wait,
1636 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001637 return -EINTR;
1638 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001639
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001640 for (; count-- > 0 && (keypad_buflen > 0);
1641 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001642 put_user(keypad_buffer[keypad_start], tmp);
1643 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1644 }
1645 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001646
Willy Tarreau698b1512008-11-22 11:29:33 +01001647 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001648}
1649
Willy Tarreau698b1512008-11-22 11:29:33 +01001650static int keypad_open(struct inode *inode, struct file *file)
1651{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001652 if (!atomic_dec_and_test(&keypad_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001653 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001654
Willy Tarreau698b1512008-11-22 11:29:33 +01001655 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1656 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001657
Willy Tarreau698b1512008-11-22 11:29:33 +01001658 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001659 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001660}
1661
Willy Tarreau698b1512008-11-22 11:29:33 +01001662static int keypad_release(struct inode *inode, struct file *file)
1663{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001664 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001665 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001666}
1667
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001668static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001669 .read = keypad_read, /* read */
1670 .open = keypad_open, /* open */
1671 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001672 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001673};
1674
1675static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001676 .minor = KEYPAD_MINOR,
1677 .name = "keypad",
1678 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001679};
1680
Peter Huewe36d20412013-02-15 13:47:05 +01001681static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001682{
1683 if (init_in_progress)
1684 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001685
Willy Tarreau698b1512008-11-22 11:29:33 +01001686 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001687 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001688 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1689 keypad_buffer[(keypad_start + keypad_buflen++) %
1690 KEYPAD_BUFFER] = *string++;
1691 }
1692 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001693 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001694}
1695
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001696/* this function scans all the bits involving at least one logical signal,
1697 * and puts the results in the bitfield "phys_read" (one bit per established
1698 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001699 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001700 * Note: to debounce input signals, we will only consider as switched a signal
1701 * which is stable across 2 measures. Signals which are different between two
1702 * reads will be kept as they previously were in their logical form (phys_prev).
1703 * A signal which has just switched will have a 1 in
1704 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001705 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001706static void phys_scan_contacts(void)
1707{
1708 int bit, bitval;
1709 char oldval;
1710 char bitmask;
1711 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001712
Willy Tarreau698b1512008-11-22 11:29:33 +01001713 phys_prev = phys_curr;
1714 phys_read_prev = phys_read;
1715 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001716
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001717 /* keep track of old value, with all outputs disabled */
1718 oldval = r_dtr(pprt) | scan_mask_o;
1719 /* activate all keyboard outputs (active low) */
1720 w_dtr(pprt, oldval & ~scan_mask_o);
1721
1722 /* will have a 1 for each bit set to gnd */
1723 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1724 /* disable all matrix signals */
1725 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001726
Willy Tarreau698b1512008-11-22 11:29:33 +01001727 /* now that all outputs are cleared, the only active input bits are
1728 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001729 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001730
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001731 /* 1 for each grounded input */
1732 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1733
1734 /* grounded inputs are signals 40-44 */
1735 phys_read |= (pmask_t) gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001736
Willy Tarreau698b1512008-11-22 11:29:33 +01001737 if (bitmask != gndmask) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001738 /* since clearing the outputs changed some inputs, we know
1739 * that some input signals are currently tied to some outputs.
1740 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001741 */
1742 for (bit = 0; bit < 8; bit++) {
1743 bitval = 1 << bit;
1744
1745 if (!(scan_mask_o & bitval)) /* skip unused bits */
1746 continue;
1747
1748 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1749 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1750 phys_read |= (pmask_t) bitmask << (5 * bit);
1751 }
1752 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001753 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001754 /* this is easy: use old bits when they are flapping,
1755 * use new ones when stable */
1756 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1757 (phys_read & ~(phys_read ^ phys_read_prev));
1758}
1759
1760static inline int input_state_high(struct logical_input *input)
1761{
1762#if 0
1763 /* FIXME:
1764 * this is an invalid test. It tries to catch
1765 * transitions from single-key to multiple-key, but
1766 * doesn't take into account the contacts polarity.
1767 * The only solution to the problem is to parse keys
1768 * from the most complex to the simplest combinations,
1769 * and mark them as 'caught' once a combination
1770 * matches, then unmatch it for all other ones.
1771 */
1772
1773 /* try to catch dangerous transitions cases :
1774 * someone adds a bit, so this signal was a false
1775 * positive resulting from a transition. We should
1776 * invalidate the signal immediately and not call the
1777 * release function.
1778 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1779 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001780 if (((phys_prev & input->mask) == input->value) &&
1781 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001782 input->state = INPUT_ST_LOW; /* invalidate */
1783 return 1;
1784 }
1785#endif
1786
1787 if ((phys_curr & input->mask) == input->value) {
1788 if ((input->type == INPUT_TYPE_STD) &&
1789 (input->high_timer == 0)) {
1790 input->high_timer++;
1791 if (input->u.std.press_fct != NULL)
1792 input->u.std.press_fct(input->u.std.press_data);
1793 } else if (input->type == INPUT_TYPE_KBD) {
1794 /* will turn on the light */
1795 keypressed = 1;
1796
1797 if (input->high_timer == 0) {
1798 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001799
Jake Champline6626de2013-05-04 11:21:17 -04001800 if (press_str[0]) {
1801 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001802
Jake Champline6626de2013-05-04 11:21:17 -04001803 keypad_send_key(press_str, s);
1804 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001805 }
1806
1807 if (input->u.kbd.repeat_str[0]) {
1808 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001809
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001810 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001811 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001812
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001813 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001814 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001815 }
1816 /* we will need to come back here soon */
1817 inputs_stable = 0;
1818 }
1819
1820 if (input->high_timer < 255)
1821 input->high_timer++;
1822 }
1823 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001824 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001825
1826 /* else signal falling down. Let's fall through. */
1827 input->state = INPUT_ST_FALLING;
1828 input->fall_timer = 0;
1829
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001830 return 0;
1831}
1832
1833static inline void input_state_falling(struct logical_input *input)
1834{
1835#if 0
1836 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001837 if (((phys_prev & input->mask) == input->value) &&
1838 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001839 input->state = INPUT_ST_LOW; /* invalidate */
1840 return;
1841 }
1842#endif
1843
1844 if ((phys_curr & input->mask) == input->value) {
1845 if (input->type == INPUT_TYPE_KBD) {
1846 /* will turn on the light */
1847 keypressed = 1;
1848
1849 if (input->u.kbd.repeat_str[0]) {
1850 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001851
Jake Champline6626de2013-05-04 11:21:17 -04001852 if (input->high_timer >= KEYPAD_REP_START) {
1853 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001854
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001855 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001856 keypad_send_key(repeat_str, s);
1857 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001858 /* we will need to come back here soon */
1859 inputs_stable = 0;
1860 }
1861
1862 if (input->high_timer < 255)
1863 input->high_timer++;
1864 }
1865 input->state = INPUT_ST_HIGH;
1866 } else if (input->fall_timer >= input->fall_time) {
1867 /* call release event */
1868 if (input->type == INPUT_TYPE_STD) {
1869 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001870
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001871 if (release_fct != NULL)
1872 release_fct(input->u.std.release_data);
1873 } else if (input->type == INPUT_TYPE_KBD) {
1874 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001875
Jake Champline6626de2013-05-04 11:21:17 -04001876 if (release_str[0]) {
1877 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001878
Jake Champline6626de2013-05-04 11:21:17 -04001879 keypad_send_key(release_str, s);
1880 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001881 }
1882
1883 input->state = INPUT_ST_LOW;
1884 } else {
1885 input->fall_timer++;
1886 inputs_stable = 0;
1887 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001888}
1889
Willy Tarreau698b1512008-11-22 11:29:33 +01001890static void panel_process_inputs(void)
1891{
1892 struct list_head *item;
1893 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001894
Willy Tarreau698b1512008-11-22 11:29:33 +01001895 keypressed = 0;
1896 inputs_stable = 1;
1897 list_for_each(item, &logical_inputs) {
1898 input = list_entry(item, struct logical_input, list);
Willy Tarreau7005b582008-11-13 17:18:59 -08001899
Willy Tarreau698b1512008-11-22 11:29:33 +01001900 switch (input->state) {
1901 case INPUT_ST_LOW:
1902 if ((phys_curr & input->mask) != input->value)
1903 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001904 /* if all needed ones were already set previously,
1905 * this means that this logical signal has been
1906 * activated by the releasing of another combined
1907 * signal, so we don't want to match.
1908 * eg: AB -(release B)-> A -(release A)-> 0 :
1909 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001910 */
1911 if ((phys_prev & input->mask) == input->value)
1912 break;
1913 input->rise_timer = 0;
1914 input->state = INPUT_ST_RISING;
1915 /* no break here, fall through */
1916 case INPUT_ST_RISING:
1917 if ((phys_curr & input->mask) != input->value) {
1918 input->state = INPUT_ST_LOW;
1919 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001920 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001921 if (input->rise_timer < input->rise_time) {
1922 inputs_stable = 0;
1923 input->rise_timer++;
1924 break;
1925 }
1926 input->high_timer = 0;
1927 input->state = INPUT_ST_HIGH;
1928 /* no break here, fall through */
1929 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001930 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001931 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001932 /* no break here, fall through */
1933 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001934 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001935 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001936 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001937}
1938
Willy Tarreau698b1512008-11-22 11:29:33 +01001939static void panel_scan_timer(void)
1940{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001941 if (keypad.enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001942 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001943 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001944
1945 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001946 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001947 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001948
Willy Tarreau698b1512008-11-22 11:29:33 +01001949 if (!inputs_stable || phys_curr != phys_prev)
1950 panel_process_inputs();
1951 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001952
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001953 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001954 if (keypressed) {
1955 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1956 lcd_backlight(1);
1957 light_tempo = FLASH_LIGHT_TEMPO;
1958 } else if (light_tempo > 0) {
1959 light_tempo--;
1960 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1961 lcd_backlight(0);
1962 }
1963 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001964
Willy Tarreau698b1512008-11-22 11:29:33 +01001965 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001966}
1967
Willy Tarreau698b1512008-11-22 11:29:33 +01001968static void init_scan_timer(void)
1969{
1970 if (scan_timer.function != NULL)
1971 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001972
Willy Tarreau698b1512008-11-22 11:29:33 +01001973 init_timer(&scan_timer);
1974 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1975 scan_timer.data = 0;
1976 scan_timer.function = (void *)&panel_scan_timer;
1977 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001978}
1979
1980/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001981 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1982 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001983 * returns 1 if ok, 0 if error (in which case, nothing is written).
1984 */
Peter Huewe36d20412013-02-15 13:47:05 +01001985static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
Willy Tarreau698b1512008-11-22 11:29:33 +01001986 char *imask, char *omask)
1987{
1988 static char sigtab[10] = "EeSsPpAaBb";
1989 char im, om;
1990 pmask_t m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001991
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001992 om = 0ULL;
1993 im = 0ULL;
1994 m = 0ULL;
1995 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001996 while (*name) {
1997 int in, out, bit, neg;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001998
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001999 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
2000 in++)
Willy Tarreau698b1512008-11-22 11:29:33 +01002001 ;
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002002
Willy Tarreau698b1512008-11-22 11:29:33 +01002003 if (in >= sizeof(sigtab))
2004 return 0; /* input name not found */
2005 neg = (in & 1); /* odd (lower) names are negated */
2006 in >>= 1;
2007 im |= (1 << in);
Willy Tarreau7005b582008-11-13 17:18:59 -08002008
Willy Tarreau698b1512008-11-22 11:29:33 +01002009 name++;
2010 if (isdigit(*name)) {
2011 out = *name - '0';
2012 om |= (1 << out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002013 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01002014 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002015 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01002016 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002017 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002018
2019 bit = (out * 5) + in;
2020
2021 m |= 1ULL << bit;
2022 if (!neg)
2023 v |= 1ULL << bit;
2024 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08002025 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002026 *mask = m;
2027 *value = v;
2028 if (imask)
2029 *imask |= im;
2030 if (omask)
2031 *omask |= om;
2032 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002033}
2034
2035/* tries to bind a key to the signal name <name>. The key will send the
2036 * strings <press>, <repeat>, <release> for these respective events.
2037 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2038 */
Peter Huewe36d20412013-02-15 13:47:05 +01002039static struct logical_input *panel_bind_key(const char *name, const char *press,
2040 const char *repeat,
2041 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01002042{
2043 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002044
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002045 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002046 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01002047 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002048
Willy Tarreau698b1512008-11-22 11:29:33 +01002049 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002050 &scan_mask_o)) {
2051 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01002052 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002053 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002054
2055 key->type = INPUT_TYPE_KBD;
2056 key->state = INPUT_ST_LOW;
2057 key->rise_time = 1;
2058 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002059
Willy Tarreau698b1512008-11-22 11:29:33 +01002060 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
2061 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
2062 strncpy(key->u.kbd.release_str, release,
2063 sizeof(key->u.kbd.release_str));
2064 list_add(&key->list, &logical_inputs);
2065 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002066}
2067
Willy Tarreau630231772008-11-22 12:52:18 +01002068#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08002069/* tries to bind a callback function to the signal name <name>. The function
2070 * <press_fct> will be called with the <press_data> arg when the signal is
2071 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002072 * Returns the pointer to the new signal if ok, NULL if the signal could not
2073 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08002074 */
2075static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302076 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002077 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302078 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002079 int release_data)
2080{
2081 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002082
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002083 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002084 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01002085 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002086
Willy Tarreau698b1512008-11-22 11:29:33 +01002087 memset(callback, 0, sizeof(struct logical_input));
2088 if (!input_name2mask(name, &callback->mask, &callback->value,
2089 &scan_mask_i, &scan_mask_o))
2090 return NULL;
2091
2092 callback->type = INPUT_TYPE_STD;
2093 callback->state = INPUT_ST_LOW;
2094 callback->rise_time = 1;
2095 callback->fall_time = 1;
2096 callback->u.std.press_fct = press_fct;
2097 callback->u.std.press_data = press_data;
2098 callback->u.std.release_fct = release_fct;
2099 callback->u.std.release_data = release_data;
2100 list_add(&callback->list, &logical_inputs);
2101 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002102}
Willy Tarreau630231772008-11-22 12:52:18 +01002103#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08002104
Willy Tarreau698b1512008-11-22 11:29:33 +01002105static void keypad_init(void)
2106{
2107 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02002108
Willy Tarreau698b1512008-11-22 11:29:33 +01002109 init_waitqueue_head(&keypad_read_wait);
2110 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08002111
Willy Tarreau698b1512008-11-22 11:29:33 +01002112 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08002113
Willy Tarreau698b1512008-11-22 11:29:33 +01002114 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
2115 panel_bind_key(keypad_profile[keynum][0],
2116 keypad_profile[keynum][1],
2117 keypad_profile[keynum][2],
2118 keypad_profile[keynum][3]);
2119 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002120
Willy Tarreau698b1512008-11-22 11:29:33 +01002121 init_scan_timer();
2122 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002123}
2124
Willy Tarreau7005b582008-11-13 17:18:59 -08002125/**************************************************/
2126/* device initialization */
2127/**************************************************/
2128
Willy Tarreau698b1512008-11-22 11:29:33 +01002129static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2130 void *unused)
2131{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002132 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002133 switch (code) {
2134 case SYS_DOWN:
2135 panel_lcd_print
2136 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2137 break;
2138 case SYS_HALT:
2139 panel_lcd_print
2140 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2141 break;
2142 case SYS_POWER_OFF:
2143 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2144 break;
2145 default:
2146 break;
2147 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002148 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002149 return NOTIFY_DONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08002150}
2151
2152static struct notifier_block panel_notifier = {
2153 panel_notify_sys,
2154 NULL,
2155 0
2156};
2157
Willy Tarreau698b1512008-11-22 11:29:33 +01002158static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002159{
Willy Tarreau698b1512008-11-22 11:29:33 +01002160 if (port->number != parport)
2161 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002162
Willy Tarreau698b1512008-11-22 11:29:33 +01002163 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002164 pr_err("%s: port->number=%d parport=%d, already registered!\n",
2165 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002166 return;
2167 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002168
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002169 pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */
Willy Tarreau698b1512008-11-22 11:29:33 +01002170 NULL,
2171 /*PARPORT_DEV_EXCL */
2172 0, (void *)&pprt);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002173 if (pprt == NULL) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002174 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
2175 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002176 return;
2177 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002178
Willy Tarreau698b1512008-11-22 11:29:33 +01002179 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002180 pr_err("could not claim access to parport%d. Aborting.\n",
2181 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002182 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002183 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002184
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002185 /* must init LCD first, just in case an IRQ from the keypad is
2186 * generated at keypad init
2187 */
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002188 if (lcd.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002189 lcd_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002190 if (misc_register(&lcd_dev))
2191 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002192 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002193
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002194 if (keypad.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002195 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002196 if (misc_register(&keypad_dev))
2197 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01002198 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002199 return;
2200
2201err_lcd_unreg:
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002202 if (lcd.enabled)
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002203 misc_deregister(&lcd_dev);
2204err_unreg_device:
2205 parport_unregister_device(pprt);
2206 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002207}
2208
Willy Tarreau698b1512008-11-22 11:29:33 +01002209static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002210{
Willy Tarreau698b1512008-11-22 11:29:33 +01002211 if (port->number != parport)
2212 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002213
Willy Tarreau698b1512008-11-22 11:29:33 +01002214 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002215 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
2216 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002217 return;
2218 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002219
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002220 if (keypad.enabled && keypad_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002221 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002222 keypad_initialized = 0;
2223 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002224
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002225 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002226 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002227 lcd_initialized = 0;
2228 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002229
Willy Tarreau698b1512008-11-22 11:29:33 +01002230 parport_release(pprt);
2231 parport_unregister_device(pprt);
2232 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002233}
2234
2235static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01002236 .name = "panel",
2237 .attach = panel_attach,
2238 .detach = panel_detach,
Willy Tarreau7005b582008-11-13 17:18:59 -08002239};
2240
2241/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01002242static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002243{
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002244 int selected_keypad_type = NOT_SET;
Willy Tarreau7005b582008-11-13 17:18:59 -08002245
Willy Tarreau698b1512008-11-22 11:29:33 +01002246 /* take care of an eventual profile */
2247 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002248 case PANEL_PROFILE_CUSTOM:
2249 /* custom profile */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002250 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
2251 selected_lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01002252 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002253 case PANEL_PROFILE_OLD:
2254 /* 8 bits, 2*16, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002255 selected_keypad_type = KEYPAD_TYPE_OLD;
2256 selected_lcd_type = LCD_TYPE_OLD;
2257
2258 /* TODO: This two are a little hacky, sort it out later */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002259 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002260 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002261 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002262 lcd_hwidth = 16;
2263 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002264 case PANEL_PROFILE_NEW:
2265 /* serial, 2*16, new keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002266 selected_keypad_type = KEYPAD_TYPE_NEW;
2267 selected_lcd_type = LCD_TYPE_KS0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01002268 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002269 case PANEL_PROFILE_HANTRONIX:
2270 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002271 selected_keypad_type = KEYPAD_TYPE_NONE;
2272 selected_lcd_type = LCD_TYPE_HANTRONIX;
Willy Tarreau698b1512008-11-22 11:29:33 +01002273 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002274 case PANEL_PROFILE_NEXCOM:
2275 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002276 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
2277 selected_lcd_type = LCD_TYPE_NEXCOM;
Willy Tarreau698b1512008-11-22 11:29:33 +01002278 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002279 case PANEL_PROFILE_LARGE:
2280 /* 8 bits, 2*40, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002281 selected_keypad_type = KEYPAD_TYPE_OLD;
2282 selected_lcd_type = LCD_TYPE_OLD;
Willy Tarreau698b1512008-11-22 11:29:33 +01002283 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08002284 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002285
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002286 /*
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01002287 * Init lcd struct with load-time values to preserve exact current
2288 * functionality (at least for now).
2289 */
2290 lcd.height = lcd_height;
2291 lcd.width = lcd_width;
2292 lcd.bwidth = lcd_bwidth;
2293 lcd.hwidth = lcd_hwidth;
2294 lcd.charset = lcd_charset;
2295 lcd.proto = lcd_proto;
2296 lcd.pins.e = lcd_e_pin;
2297 lcd.pins.rs = lcd_rs_pin;
2298 lcd.pins.rw = lcd_rw_pin;
2299 lcd.pins.cl = lcd_cl_pin;
2300 lcd.pins.da = lcd_da_pin;
2301 lcd.pins.bl = lcd_bl_pin;
2302
2303 /*
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002304 * Overwrite selection with module param values (both keypad and lcd),
2305 * where the deprecated params have lower prio.
2306 */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01002307 if (keypad_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002308 selected_keypad_type = keypad_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01002309 if (keypad_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002310 selected_keypad_type = keypad_type;
Willy Tarreau7005b582008-11-13 17:18:59 -08002311
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002312 keypad.enabled = (selected_keypad_type > 0);
2313
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01002314 if (lcd_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002315 selected_lcd_type = lcd_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01002316 if (lcd_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002317 selected_lcd_type = lcd_type;
2318
2319 lcd.enabled = (selected_lcd_type > 0);
2320
2321 switch (selected_keypad_type) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002322 case KEYPAD_TYPE_OLD:
2323 keypad_profile = old_keypad_profile;
2324 break;
2325 case KEYPAD_TYPE_NEW:
2326 keypad_profile = new_keypad_profile;
2327 break;
2328 case KEYPAD_TYPE_NEXCOM:
2329 keypad_profile = nexcom_keypad_profile;
2330 break;
2331 default:
2332 keypad_profile = NULL;
2333 break;
2334 }
2335
2336 /* tells various subsystems about the fact that we are initializing */
2337 init_in_progress = 1;
2338
2339 if (parport_register_driver(&panel_driver)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002340 pr_err("could not register with parport. Aborting.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002341 return -EIO;
2342 }
2343
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002344 if (!lcd.enabled && !keypad.enabled) {
Willy Tarreau630231772008-11-22 12:52:18 +01002345 /* no device enabled, let's release the parport */
Willy Tarreau698b1512008-11-22 11:29:33 +01002346 if (pprt) {
2347 parport_release(pprt);
2348 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002349 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002350 }
2351 parport_unregister_driver(&panel_driver);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002352 pr_err("driver version " PANEL_VERSION " disabled.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002353 return -ENODEV;
2354 }
2355
2356 register_reboot_notifier(&panel_notifier);
2357
2358 if (pprt)
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002359 pr_info("driver version " PANEL_VERSION
2360 " registered on parport%d (io=0x%lx).\n", parport,
2361 pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01002362 else
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002363 pr_info("driver version " PANEL_VERSION
2364 " not yet registered\n");
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002365 /* tells various subsystems about the fact that initialization
2366 is finished */
Willy Tarreau698b1512008-11-22 11:29:33 +01002367 init_in_progress = 0;
2368 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08002369}
2370
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01002371static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002372{
2373 unregister_reboot_notifier(&panel_notifier);
Willy Tarreau7005b582008-11-13 17:18:59 -08002374
Willy Tarreau698b1512008-11-22 11:29:33 +01002375 if (scan_timer.function != NULL)
Julia Lawalle112f892014-03-26 22:33:41 +01002376 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08002377
Costantino Leandro57898132009-02-17 11:10:48 -05002378 if (pprt != NULL) {
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002379 if (keypad.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002380 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002381 keypad_initialized = 0;
2382 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002383
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002384 if (lcd.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002385 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2386 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2387 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002388 lcd_initialized = 0;
Costantino Leandro57898132009-02-17 11:10:48 -05002389 }
2390
2391 /* TODO: free all input signals */
2392 parport_release(pprt);
2393 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002394 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002395 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002396 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08002397}
Willy Tarreau7005b582008-11-13 17:18:59 -08002398
Willy Tarreau7005b582008-11-13 17:18:59 -08002399module_init(panel_init_module);
2400module_exit(panel_cleanup_module);
2401MODULE_AUTHOR("Willy Tarreau");
2402MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08002403
2404/*
2405 * Local variables:
2406 * c-indent-level: 4
2407 * tab-width: 8
2408 * End:
2409 */