blob: 7e5bb53c4a8adaa71e4aedfa10376b213647b950 [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;
228} lcd;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300229
230/* contains the LCD config state */
231static unsigned long int lcd_flags;
232/* contains the LCD X offset */
233static unsigned long int lcd_addr_x;
234/* contains the LCD Y offset */
235static unsigned long int lcd_addr_y;
236/* current escape sequence, 0 terminated */
237static char lcd_escape[LCD_ESCAPE_LEN + 1];
238/* not in escape state. >=0 = escape cmd len */
239static int lcd_escape_len = -1;
Willy Tarreau7005b582008-11-13 17:18:59 -0800240
Willy Tarreau7005b582008-11-13 17:18:59 -0800241/*
242 * Bit masks to convert LCD signals to parallel port outputs.
243 * _d_ are values for data port, _c_ are for control port.
244 * [0] = signal OFF, [1] = signal ON, [2] = mask
245 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100246#define BIT_CLR 0
247#define BIT_SET 1
248#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800249#define BIT_STATES 3
250/*
251 * one entry for each bit on the LCD
252 */
253#define LCD_BIT_E 0
254#define LCD_BIT_RS 1
255#define LCD_BIT_RW 2
256#define LCD_BIT_BL 3
257#define LCD_BIT_CL 4
258#define LCD_BIT_DA 5
259#define LCD_BITS 6
260
261/*
262 * each bit can be either connected to a DATA or CTRL port
263 */
264#define LCD_PORT_C 0
265#define LCD_PORT_D 1
266#define LCD_PORTS 2
267
268static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
269
270/*
271 * LCD protocols
272 */
273#define LCD_PROTO_PARALLEL 0
274#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400275#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800276
277/*
278 * LCD character sets
279 */
280#define LCD_CHARSET_NORMAL 0
281#define LCD_CHARSET_KS0074 1
282
283/*
284 * LCD types
285 */
286#define LCD_TYPE_NONE 0
287#define LCD_TYPE_OLD 1
288#define LCD_TYPE_KS0074 2
289#define LCD_TYPE_HANTRONIX 3
290#define LCD_TYPE_NEXCOM 4
291#define LCD_TYPE_CUSTOM 5
292
293/*
294 * keypad types
295 */
296#define KEYPAD_TYPE_NONE 0
297#define KEYPAD_TYPE_OLD 1
298#define KEYPAD_TYPE_NEW 2
299#define KEYPAD_TYPE_NEXCOM 3
300
301/*
302 * panel profiles
303 */
304#define PANEL_PROFILE_CUSTOM 0
305#define PANEL_PROFILE_OLD 1
306#define PANEL_PROFILE_NEW 2
307#define PANEL_PROFILE_HANTRONIX 3
308#define PANEL_PROFILE_NEXCOM 4
309#define PANEL_PROFILE_LARGE 5
310
311/*
312 * Construct custom config from the kernel's configuration
313 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800314#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100315#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100316#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
317#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100318#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800319#define DEFAULT_LCD_WIDTH 40
320#define DEFAULT_LCD_BWIDTH 40
321#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100322#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800323#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
324
325#define DEFAULT_LCD_PIN_E PIN_AUTOLF
326#define DEFAULT_LCD_PIN_RS PIN_SELECP
327#define DEFAULT_LCD_PIN_RW PIN_INITP
328#define DEFAULT_LCD_PIN_SCL PIN_STROBE
329#define DEFAULT_LCD_PIN_SDA PIN_D0
330#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800331
Willy Tarreau7005b582008-11-13 17:18:59 -0800332#ifdef CONFIG_PANEL_PARPORT
333#undef DEFAULT_PARPORT
334#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
335#endif
336
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100337#ifdef CONFIG_PANEL_PROFILE
338#undef DEFAULT_PROFILE
339#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
340#endif
341
Willy Tarreau698b1512008-11-22 11:29:33 +0100342#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800343#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100344#undef DEFAULT_KEYPAD_TYPE
345#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800346#endif
347
Willy Tarreau7005b582008-11-13 17:18:59 -0800348#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100349#undef DEFAULT_LCD_TYPE
350#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800351#endif
352
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100353#ifdef CONFIG_PANEL_LCD_HEIGHT
354#undef DEFAULT_LCD_HEIGHT
355#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
356#endif
357
Willy Tarreau7005b582008-11-13 17:18:59 -0800358#ifdef CONFIG_PANEL_LCD_WIDTH
359#undef DEFAULT_LCD_WIDTH
360#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
361#endif
362
363#ifdef CONFIG_PANEL_LCD_BWIDTH
364#undef DEFAULT_LCD_BWIDTH
365#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
366#endif
367
368#ifdef CONFIG_PANEL_LCD_HWIDTH
369#undef DEFAULT_LCD_HWIDTH
370#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
371#endif
372
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100373#ifdef CONFIG_PANEL_LCD_CHARSET
374#undef DEFAULT_LCD_CHARSET
375#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800376#endif
377
378#ifdef CONFIG_PANEL_LCD_PROTO
379#undef DEFAULT_LCD_PROTO
380#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
381#endif
382
383#ifdef CONFIG_PANEL_LCD_PIN_E
384#undef DEFAULT_LCD_PIN_E
385#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
386#endif
387
388#ifdef CONFIG_PANEL_LCD_PIN_RS
389#undef DEFAULT_LCD_PIN_RS
390#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
391#endif
392
393#ifdef CONFIG_PANEL_LCD_PIN_RW
394#undef DEFAULT_LCD_PIN_RW
395#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
396#endif
397
398#ifdef CONFIG_PANEL_LCD_PIN_SCL
399#undef DEFAULT_LCD_PIN_SCL
400#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
401#endif
402
403#ifdef CONFIG_PANEL_LCD_PIN_SDA
404#undef DEFAULT_LCD_PIN_SDA
405#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
406#endif
407
408#ifdef CONFIG_PANEL_LCD_PIN_BL
409#undef DEFAULT_LCD_PIN_BL
410#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
411#endif
412
Willy Tarreau7005b582008-11-13 17:18:59 -0800413#endif /* DEFAULT_PROFILE == 0 */
414
415/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100416
417/* Device single-open policy control */
418static atomic_t lcd_available = ATOMIC_INIT(1);
419static atomic_t keypad_available = ATOMIC_INIT(1);
420
Willy Tarreau698b1512008-11-22 11:29:33 +0100421static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800422
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100423static int lcd_initialized;
424static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800425
Willy Tarreau698b1512008-11-22 11:29:33 +0100426static int light_tempo;
Willy Tarreau7005b582008-11-13 17:18:59 -0800427
Willy Tarreau698b1512008-11-22 11:29:33 +0100428static char lcd_must_clear;
429static char lcd_left_shift;
430static char init_in_progress;
Willy Tarreau7005b582008-11-13 17:18:59 -0800431
Monam Agarwal68d386b2014-02-25 19:40:49 +0530432static void (*lcd_write_cmd)(int);
433static void (*lcd_write_data)(int);
434static void (*lcd_clear_fast)(void);
Willy Tarreau7005b582008-11-13 17:18:59 -0800435
Willy Tarreau698b1512008-11-22 11:29:33 +0100436static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800437static struct timer_list scan_timer;
438
Willy Tarreau630231772008-11-22 12:52:18 +0100439MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100440
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100441static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100442module_param(parport, int, 0000);
443MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100444
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100445static int profile = DEFAULT_PROFILE;
446module_param(profile, int, 0000);
447MODULE_PARM_DESC(profile,
448 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
449 "4=16x2 nexcom; default=40x2, old kp");
450
Mariusz Gorski36277d42014-11-27 22:36:47 +0100451static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100452module_param(keypad_type, int, 0000);
453MODULE_PARM_DESC(keypad_type,
454 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
455
Mariusz Gorski36277d42014-11-27 22:36:47 +0100456static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100457module_param(lcd_type, int, 0000);
458MODULE_PARM_DESC(lcd_type,
459 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
460
Mariusz Gorski36277d42014-11-27 22:36:47 +0100461static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100462module_param(lcd_height, int, 0000);
463MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100464
Mariusz Gorski36277d42014-11-27 22:36:47 +0100465static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100466module_param(lcd_width, int, 0000);
467MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100468
Mariusz Gorski36277d42014-11-27 22:36:47 +0100469static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100470module_param(lcd_bwidth, int, 0000);
471MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100472
Mariusz Gorski36277d42014-11-27 22:36:47 +0100473static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100474module_param(lcd_hwidth, int, 0000);
475MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100476
Mariusz Gorski36277d42014-11-27 22:36:47 +0100477static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100478module_param(lcd_charset, int, 0000);
479MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100480
Mariusz Gorski36277d42014-11-27 22:36:47 +0100481static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100482module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300483MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200484 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100485
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100486/*
487 * These are the parallel port pins the LCD control signals are connected to.
488 * Set this to 0 if the signal is not used. Set it to its opposite value
489 * (negative) if the signal is negated. -MAXINT is used to indicate that the
490 * pin has not been explicitly specified.
491 *
Willy Tarreau630231772008-11-22 12:52:18 +0100492 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100493 */
494
495static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100496module_param(lcd_e_pin, int, 0000);
497MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530498 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100499
500static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100501module_param(lcd_rs_pin, int, 0000);
502MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530503 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100504
505static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100506module_param(lcd_rw_pin, int, 0000);
507MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530508 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100509
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100510static int lcd_cl_pin = PIN_NOT_SET;
511module_param(lcd_cl_pin, int, 0000);
512MODULE_PARM_DESC(lcd_cl_pin,
513 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100514
515static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100516module_param(lcd_da_pin, int, 0000);
517MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530518 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100519
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100520static int lcd_bl_pin = PIN_NOT_SET;
521module_param(lcd_bl_pin, int, 0000);
522MODULE_PARM_DESC(lcd_bl_pin,
523 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
524
525/* Deprecated module parameters - consider not using them anymore */
526
Mariusz Gorski36277d42014-11-27 22:36:47 +0100527static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100528module_param(lcd_enabled, int, 0000);
529MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
530
Mariusz Gorski36277d42014-11-27 22:36:47 +0100531static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100532module_param(keypad_enabled, int, 0000);
533MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
534
Willy Tarreau7005b582008-11-13 17:18:59 -0800535
Peter Huewe36d20412013-02-15 13:47:05 +0100536static const unsigned char *lcd_char_conv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800537
538/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100539static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100540 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
541 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
542 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
543 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
544 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
545 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
546 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
547 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
548 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
549 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
550 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
551 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
552 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
553 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
554 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
555 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
556 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
557 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
558 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
559 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
560 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
561 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
562 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
563 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
564 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
565 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
566 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
567 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
568 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
569 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
570 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
571 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
572 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800573};
574
Peter Huewe36d20412013-02-15 13:47:05 +0100575static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100576 {"S0", "Left\n", "Left\n", ""},
577 {"S1", "Down\n", "Down\n", ""},
578 {"S2", "Up\n", "Up\n", ""},
579 {"S3", "Right\n", "Right\n", ""},
580 {"S4", "Esc\n", "Esc\n", ""},
581 {"S5", "Ret\n", "Ret\n", ""},
582 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800583};
584
585/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100586static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100587 {"S0", "Left\n", "Left\n", ""},
588 {"S1", "Down\n", "Down\n", ""},
589 {"S2", "Up\n", "Up\n", ""},
590 {"S3", "Right\n", "Right\n", ""},
591 {"S4s5", "", "Esc\n", "Esc\n"},
592 {"s4S5", "", "Ret\n", "Ret\n"},
593 {"S4S5", "Help\n", "", ""},
594 /* add new signals above this line */
595 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800596};
597
598/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100599static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100600 {"a-p-e-", "Down\n", "Down\n", ""},
601 {"a-p-E-", "Ret\n", "Ret\n", ""},
602 {"a-P-E-", "Esc\n", "Esc\n", ""},
603 {"a-P-e-", "Up\n", "Up\n", ""},
604 /* add new signals above this line */
605 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800606};
607
Peter Huewe36d20412013-02-15 13:47:05 +0100608static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800609
610/* FIXME: this should be converted to a bit array containing signals states */
611static struct {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300612 unsigned char e; /* parallel LCD E (data latch on falling edge) */
613 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
614 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
615 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
616 unsigned char cl; /* serial LCD clock (latch on rising edge) */
617 unsigned char da; /* serial LCD data */
Willy Tarreau7005b582008-11-13 17:18:59 -0800618} bits;
619
620static void init_scan_timer(void);
621
622/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100623static int set_data_bits(void)
624{
625 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800626
Willy Tarreau698b1512008-11-22 11:29:33 +0100627 val = r_dtr(pprt);
628 for (bit = 0; bit < LCD_BITS; bit++)
629 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800630
Willy Tarreau698b1512008-11-22 11:29:33 +0100631 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
632 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
633 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
634 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
635 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
636 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800637
Willy Tarreau698b1512008-11-22 11:29:33 +0100638 w_dtr(pprt, val);
639 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800640}
641
642/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100643static int set_ctrl_bits(void)
644{
645 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800646
Willy Tarreau698b1512008-11-22 11:29:33 +0100647 val = r_ctr(pprt);
648 for (bit = 0; bit < LCD_BITS; bit++)
649 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800650
Willy Tarreau698b1512008-11-22 11:29:33 +0100651 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
652 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
653 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
654 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
655 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
656 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800657
Willy Tarreau698b1512008-11-22 11:29:33 +0100658 w_ctr(pprt, val);
659 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800660}
661
662/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530663static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100664{
665 set_data_bits();
666 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800667}
668
669/*
670 * Converts a parallel port pin (from -25 to 25) to data and control ports
671 * masks, and data and control port bits. The signal will be considered
672 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
673 *
674 * Result will be used this way :
675 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
676 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
677 */
Peter Huewe36d20412013-02-15 13:47:05 +0100678static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100679{
680 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800681
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200682 d_val[0] = 0;
683 c_val[0] = 0;
684 d_val[1] = 0;
685 c_val[1] = 0;
686 d_val[2] = 0xFF;
687 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800688
Willy Tarreau698b1512008-11-22 11:29:33 +0100689 if (pin == 0)
690 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800691
Willy Tarreau698b1512008-11-22 11:29:33 +0100692 inv = (pin < 0);
693 if (inv)
694 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800695
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200696 d_bit = 0;
697 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800698
Willy Tarreau698b1512008-11-22 11:29:33 +0100699 switch (pin) {
700 case PIN_STROBE: /* strobe, inverted */
701 c_bit = PNL_PSTROBE;
702 inv = !inv;
703 break;
704 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
705 d_bit = 1 << (pin - 2);
706 break;
707 case PIN_AUTOLF: /* autofeed, inverted */
708 c_bit = PNL_PAUTOLF;
709 inv = !inv;
710 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300711 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100712 c_bit = PNL_PINITP;
713 break;
714 case PIN_SELECP: /* select_in, inverted */
715 c_bit = PNL_PSELECP;
716 inv = !inv;
717 break;
718 default: /* unknown pin, ignore */
719 break;
720 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800721
Willy Tarreau698b1512008-11-22 11:29:33 +0100722 if (c_bit) {
723 c_val[2] &= ~c_bit;
724 c_val[!inv] = c_bit;
725 } else if (d_bit) {
726 d_val[2] &= ~d_bit;
727 d_val[!inv] = d_bit;
728 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800729}
730
731/* sleeps that many milliseconds with a reschedule */
Willy Tarreau698b1512008-11-22 11:29:33 +0100732static void long_sleep(int ms)
733{
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200734 if (in_interrupt()) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100735 mdelay(ms);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200736 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +0100737 current->state = TASK_INTERRUPTIBLE;
738 schedule_timeout((ms * HZ + 999) / 1000);
739 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800740}
741
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300742/* send a serial byte to the LCD panel. The caller is responsible for locking
743 if needed. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100744static void lcd_send_serial(int byte)
745{
746 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800747
Willy Tarreau698b1512008-11-22 11:29:33 +0100748 /* the data bit is set on D0, and the clock on STROBE.
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300749 * LCD reads D0 on STROBE's rising edge. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100750 for (bit = 0; bit < 8; bit++) {
751 bits.cl = BIT_CLR; /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530752 panel_set_bits();
Willy Tarreau698b1512008-11-22 11:29:33 +0100753 bits.da = byte & 1;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530754 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300755 udelay(2); /* maintain the data during 2 us before CLK up */
Willy Tarreau698b1512008-11-22 11:29:33 +0100756 bits.cl = BIT_SET; /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530757 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300758 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100759 byte >>= 1;
760 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800761}
762
763/* turn the backlight on or off */
Willy Tarreau698b1512008-11-22 11:29:33 +0100764static void lcd_backlight(int on)
765{
766 if (lcd_bl_pin == PIN_NONE)
767 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800768
Justin P. Mattock6975e182012-03-19 08:17:52 -0700769 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800770 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100771 bits.bl = on;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530772 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800773 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800774}
775
776/* send a command to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100777static void lcd_write_cmd_s(int cmd)
778{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800779 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100780 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
781 lcd_send_serial(cmd & 0x0F);
782 lcd_send_serial((cmd >> 4) & 0x0F);
783 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800784 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800785}
786
787/* send data to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100788static void lcd_write_data_s(int data)
789{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800790 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100791 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
792 lcd_send_serial(data & 0x0F);
793 lcd_send_serial((data >> 4) & 0x0F);
794 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800795 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800796}
797
798/* send a command to the LCD panel in 8 bits parallel mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100799static void lcd_write_cmd_p8(int cmd)
800{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800801 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800802 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100803 w_dtr(pprt, cmd);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300804 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800805
Willy Tarreau698b1512008-11-22 11:29:33 +0100806 bits.e = BIT_SET;
807 bits.rs = BIT_CLR;
808 bits.rw = BIT_CLR;
Willy Tarreau7005b582008-11-13 17:18:59 -0800809 set_ctrl_bits();
810
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300811 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800812
813 bits.e = BIT_CLR;
814 set_ctrl_bits();
815
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300816 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800817 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100818}
Willy Tarreau7005b582008-11-13 17:18:59 -0800819
Willy Tarreau698b1512008-11-22 11:29:33 +0100820/* send data to the LCD panel in 8 bits parallel mode */
821static void lcd_write_data_p8(int data)
822{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800823 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100824 /* present the data to the data port */
825 w_dtr(pprt, data);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300826 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100827
828 bits.e = BIT_SET;
829 bits.rs = BIT_SET;
830 bits.rw = BIT_CLR;
831 set_ctrl_bits();
832
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300833 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100834
835 bits.e = BIT_CLR;
836 set_ctrl_bits();
837
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300838 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800839 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100840}
841
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400842/* send a command to the TI LCD panel */
843static void lcd_write_cmd_tilcd(int cmd)
844{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800845 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400846 /* present the data to the control port */
847 w_ctr(pprt, cmd);
848 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800849 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400850}
851
852/* send data to the TI LCD panel */
853static void lcd_write_data_tilcd(int data)
854{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800855 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400856 /* present the data to the data port */
857 w_dtr(pprt, data);
858 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800859 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400860}
861
Willy Tarreau698b1512008-11-22 11:29:33 +0100862static void lcd_gotoxy(void)
863{
864 lcd_write_cmd(0x80 /* set DDRAM address */
865 | (lcd_addr_y ? lcd_hwidth : 0)
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300866 /* we force the cursor to stay at the end of the
867 line if it wants to go farther */
Willy Tarreau698b1512008-11-22 11:29:33 +0100868 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
869 (lcd_hwidth - 1) : lcd_bwidth - 1));
870}
871
872static void lcd_print(char c)
873{
874 if (lcd_addr_x < lcd_bwidth) {
875 if (lcd_char_conv != NULL)
876 c = lcd_char_conv[(unsigned char)c];
877 lcd_write_data(c);
878 lcd_addr_x++;
879 }
880 /* prevents the cursor from wrapping onto the next line */
881 if (lcd_addr_x == lcd_bwidth)
882 lcd_gotoxy();
883}
884
885/* fills the display with spaces and resets X/Y */
886static void lcd_clear_fast_s(void)
887{
888 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200889
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200890 lcd_addr_x = 0;
891 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100892 lcd_gotoxy();
893
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800894 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100895 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
896 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
897 lcd_send_serial(' ' & 0x0F);
898 lcd_send_serial((' ' >> 4) & 0x0F);
899 udelay(40); /* the shortest data takes at least 40 us */
900 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800901 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100902
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200903 lcd_addr_x = 0;
904 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100905 lcd_gotoxy();
906}
907
908/* fills the display with spaces and resets X/Y */
909static void lcd_clear_fast_p8(void)
910{
911 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200912
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200913 lcd_addr_x = 0;
914 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100915 lcd_gotoxy();
916
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800917 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100918 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
919 /* present the data to the data port */
920 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300921
922 /* maintain the data during 20 us before the strobe */
923 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100924
925 bits.e = BIT_SET;
926 bits.rs = BIT_SET;
927 bits.rw = BIT_CLR;
928 set_ctrl_bits();
929
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300930 /* maintain the strobe during 40 us */
931 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100932
933 bits.e = BIT_CLR;
934 set_ctrl_bits();
935
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300936 /* the shortest data takes at least 45 us */
937 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100938 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800939 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100940
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200941 lcd_addr_x = 0;
942 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100943 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -0800944}
945
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400946/* fills the display with spaces and resets X/Y */
947static void lcd_clear_fast_tilcd(void)
948{
949 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200950
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200951 lcd_addr_x = 0;
952 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400953 lcd_gotoxy();
954
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800955 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400956 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
957 /* present the data to the data port */
958 w_dtr(pprt, ' ');
959 udelay(60);
960 }
961
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800962 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400963
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200964 lcd_addr_x = 0;
965 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400966 lcd_gotoxy();
967}
968
Willy Tarreau7005b582008-11-13 17:18:59 -0800969/* clears the display and resets X/Y */
Willy Tarreau698b1512008-11-22 11:29:33 +0100970static void lcd_clear_display(void)
971{
972 lcd_write_cmd(0x01); /* clear display */
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200973 lcd_addr_x = 0;
974 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100975 /* we must wait a few milliseconds (15) */
976 long_sleep(15);
Willy Tarreau7005b582008-11-13 17:18:59 -0800977}
978
Willy Tarreau698b1512008-11-22 11:29:33 +0100979static void lcd_init_display(void)
980{
Willy Tarreau698b1512008-11-22 11:29:33 +0100981 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
982 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
Willy Tarreau7005b582008-11-13 17:18:59 -0800983
Willy Tarreau698b1512008-11-22 11:29:33 +0100984 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
Willy Tarreau7005b582008-11-13 17:18:59 -0800985
Willy Tarreau698b1512008-11-22 11:29:33 +0100986 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
987 long_sleep(10);
988 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
989 long_sleep(10);
990 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
991 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800992
Willy Tarreau698b1512008-11-22 11:29:33 +0100993 lcd_write_cmd(0x30 /* set font height and lines number */
994 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
995 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
996 );
997 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800998
Willy Tarreau698b1512008-11-22 11:29:33 +0100999 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
1000 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001001
Willy Tarreau698b1512008-11-22 11:29:33 +01001002 lcd_write_cmd(0x08 /* set display mode */
1003 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1004 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1005 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
1006 );
Willy Tarreau7005b582008-11-13 17:18:59 -08001007
Willy Tarreau698b1512008-11-22 11:29:33 +01001008 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08001009
Willy Tarreau698b1512008-11-22 11:29:33 +01001010 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001011
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001012 /* entry mode set : increment, cursor shifting */
1013 lcd_write_cmd(0x06);
Willy Tarreau7005b582008-11-13 17:18:59 -08001014
Willy Tarreau698b1512008-11-22 11:29:33 +01001015 lcd_clear_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001016}
1017
1018/*
1019 * These are the file operation function for user access to /dev/lcd
1020 * This function can also be called from inside the kernel, by
1021 * setting file and ppos to NULL.
1022 *
1023 */
1024
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001025static inline int handle_lcd_special_code(void)
1026{
1027 /* LCD special codes */
1028
1029 int processed = 0;
1030
1031 char *esc = lcd_escape + 2;
1032 int oldflags = lcd_flags;
1033
1034 /* check for display mode flags */
1035 switch (*esc) {
1036 case 'D': /* Display ON */
1037 lcd_flags |= LCD_FLAG_D;
1038 processed = 1;
1039 break;
1040 case 'd': /* Display OFF */
1041 lcd_flags &= ~LCD_FLAG_D;
1042 processed = 1;
1043 break;
1044 case 'C': /* Cursor ON */
1045 lcd_flags |= LCD_FLAG_C;
1046 processed = 1;
1047 break;
1048 case 'c': /* Cursor OFF */
1049 lcd_flags &= ~LCD_FLAG_C;
1050 processed = 1;
1051 break;
1052 case 'B': /* Blink ON */
1053 lcd_flags |= LCD_FLAG_B;
1054 processed = 1;
1055 break;
1056 case 'b': /* Blink OFF */
1057 lcd_flags &= ~LCD_FLAG_B;
1058 processed = 1;
1059 break;
1060 case '+': /* Back light ON */
1061 lcd_flags |= LCD_FLAG_L;
1062 processed = 1;
1063 break;
1064 case '-': /* Back light OFF */
1065 lcd_flags &= ~LCD_FLAG_L;
1066 processed = 1;
1067 break;
1068 case '*':
1069 /* flash back light using the keypad timer */
1070 if (scan_timer.function != NULL) {
1071 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1072 lcd_backlight(1);
1073 light_tempo = FLASH_LIGHT_TEMPO;
1074 }
1075 processed = 1;
1076 break;
1077 case 'f': /* Small Font */
1078 lcd_flags &= ~LCD_FLAG_F;
1079 processed = 1;
1080 break;
1081 case 'F': /* Large Font */
1082 lcd_flags |= LCD_FLAG_F;
1083 processed = 1;
1084 break;
1085 case 'n': /* One Line */
1086 lcd_flags &= ~LCD_FLAG_N;
1087 processed = 1;
1088 break;
1089 case 'N': /* Two Lines */
1090 lcd_flags |= LCD_FLAG_N;
1091 break;
1092 case 'l': /* Shift Cursor Left */
1093 if (lcd_addr_x > 0) {
1094 /* back one char if not at end of line */
1095 if (lcd_addr_x < lcd_bwidth)
1096 lcd_write_cmd(0x10);
1097 lcd_addr_x--;
1098 }
1099 processed = 1;
1100 break;
1101 case 'r': /* shift cursor right */
1102 if (lcd_addr_x < lcd_width) {
1103 /* allow the cursor to pass the end of the line */
1104 if (lcd_addr_x <
1105 (lcd_bwidth - 1))
1106 lcd_write_cmd(0x14);
1107 lcd_addr_x++;
1108 }
1109 processed = 1;
1110 break;
1111 case 'L': /* shift display left */
1112 lcd_left_shift++;
1113 lcd_write_cmd(0x18);
1114 processed = 1;
1115 break;
1116 case 'R': /* shift display right */
1117 lcd_left_shift--;
1118 lcd_write_cmd(0x1C);
1119 processed = 1;
1120 break;
1121 case 'k': { /* kill end of line */
1122 int x;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001123
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001124 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1125 lcd_write_data(' ');
1126
1127 /* restore cursor position */
1128 lcd_gotoxy();
1129 processed = 1;
1130 break;
1131 }
1132 case 'I': /* reinitialize display */
1133 lcd_init_display();
1134 lcd_left_shift = 0;
1135 processed = 1;
1136 break;
1137 case 'G': {
1138 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1139 * and '7', representing the numerical ASCII code of the
1140 * redefined character, and <xx...xx> a sequence of 16
1141 * hex digits representing 8 bytes for each character.
1142 * Most LCDs will only use 5 lower bits of the 7 first
1143 * bytes.
1144 */
1145
1146 unsigned char cgbytes[8];
1147 unsigned char cgaddr;
1148 int cgoffset;
1149 int shift;
1150 char value;
1151 int addr;
1152
1153 if (strchr(esc, ';') == NULL)
1154 break;
1155
1156 esc++;
1157
1158 cgaddr = *(esc++) - '0';
1159 if (cgaddr > 7) {
1160 processed = 1;
1161 break;
1162 }
1163
1164 cgoffset = 0;
1165 shift = 0;
1166 value = 0;
1167 while (*esc && cgoffset < 8) {
1168 shift ^= 4;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001169 if (*esc >= '0' && *esc <= '9') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001170 value |= (*esc - '0') << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001171 } else if (*esc >= 'A' && *esc <= 'Z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001172 value |= (*esc - 'A' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001173 } else if (*esc >= 'a' && *esc <= 'z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001174 value |= (*esc - 'a' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001175 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001176 esc++;
1177 continue;
1178 }
1179
1180 if (shift == 0) {
1181 cgbytes[cgoffset++] = value;
1182 value = 0;
1183 }
1184
1185 esc++;
1186 }
1187
1188 lcd_write_cmd(0x40 | (cgaddr * 8));
1189 for (addr = 0; addr < cgoffset; addr++)
1190 lcd_write_data(cgbytes[addr]);
1191
1192 /* ensures that we stop writing to CGRAM */
1193 lcd_gotoxy();
1194 processed = 1;
1195 break;
1196 }
1197 case 'x': /* gotoxy : LxXXX[yYYY]; */
1198 case 'y': /* gotoxy : LyYYY[xXXX]; */
1199 if (strchr(esc, ';') == NULL)
1200 break;
1201
1202 while (*esc) {
1203 if (*esc == 'x') {
1204 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001205 if (kstrtoul(esc, 10, &lcd_addr_x) < 0)
1206 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001207 } else if (*esc == 'y') {
1208 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001209 if (kstrtoul(esc, 10, &lcd_addr_y) < 0)
1210 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001211 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001212 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001213 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001214 }
1215
1216 lcd_gotoxy();
1217 processed = 1;
1218 break;
1219 }
1220
Adam Buchbinderf2635892012-09-19 21:51:07 -04001221 /* Check whether one flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001222 if (oldflags != lcd_flags) {
1223 /* check whether one of B,C,D flags were changed */
1224 if ((oldflags ^ lcd_flags) &
1225 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1226 /* set display mode */
1227 lcd_write_cmd(0x08
1228 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1229 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1230 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1231 /* check whether one of F,N flags was changed */
1232 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1233 lcd_write_cmd(0x30
1234 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1235 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
Adam Buchbinderf2635892012-09-19 21:51:07 -04001236 /* check whether L flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001237 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1238 if (lcd_flags & (LCD_FLAG_L))
1239 lcd_backlight(1);
1240 else if (light_tempo == 0)
1241 /* switch off the light only when the tempo
1242 lighting is gone */
1243 lcd_backlight(0);
1244 }
1245 }
1246
1247 return processed;
1248}
1249
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001250static void lcd_write_char(char c)
Willy Tarreau698b1512008-11-22 11:29:33 +01001251{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001252 /* first, we'll test if we're in escape mode */
1253 if ((c != '\n') && lcd_escape_len >= 0) {
1254 /* yes, let's add this char to the buffer */
1255 lcd_escape[lcd_escape_len++] = c;
1256 lcd_escape[lcd_escape_len] = 0;
1257 } else {
1258 /* aborts any previous escape sequence */
1259 lcd_escape_len = -1;
1260
1261 switch (c) {
1262 case LCD_ESCAPE_CHAR:
1263 /* start of an escape sequence */
1264 lcd_escape_len = 0;
1265 lcd_escape[lcd_escape_len] = 0;
1266 break;
1267 case '\b':
1268 /* go back one char and clear it */
1269 if (lcd_addr_x > 0) {
1270 /* check if we're not at the
1271 end of the line */
1272 if (lcd_addr_x < lcd_bwidth)
1273 /* back one char */
1274 lcd_write_cmd(0x10);
1275 lcd_addr_x--;
1276 }
1277 /* replace with a space */
1278 lcd_write_data(' ');
1279 /* back one char again */
1280 lcd_write_cmd(0x10);
1281 break;
1282 case '\014':
1283 /* quickly clear the display */
1284 lcd_clear_fast();
1285 break;
1286 case '\n':
1287 /* flush the remainder of the current line and
1288 go to the beginning of the next line */
1289 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1290 lcd_write_data(' ');
1291 lcd_addr_x = 0;
1292 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1293 lcd_gotoxy();
1294 break;
1295 case '\r':
1296 /* go to the beginning of the same line */
1297 lcd_addr_x = 0;
1298 lcd_gotoxy();
1299 break;
1300 case '\t':
1301 /* print a space instead of the tab */
1302 lcd_print(' ');
1303 break;
1304 default:
1305 /* simply print this char */
1306 lcd_print(c);
1307 break;
1308 }
1309 }
1310
1311 /* now we'll see if we're in an escape mode and if the current
1312 escape sequence can be understood. */
1313 if (lcd_escape_len >= 2) {
1314 int processed = 0;
1315
1316 if (!strcmp(lcd_escape, "[2J")) {
1317 /* clear the display */
1318 lcd_clear_fast();
1319 processed = 1;
1320 } else if (!strcmp(lcd_escape, "[H")) {
1321 /* cursor to home */
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001322 lcd_addr_x = 0;
1323 lcd_addr_y = 0;
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001324 lcd_gotoxy();
1325 processed = 1;
1326 }
1327 /* codes starting with ^[[L */
1328 else if ((lcd_escape_len >= 3) &&
1329 (lcd_escape[0] == '[') &&
1330 (lcd_escape[1] == 'L')) {
1331 processed = handle_lcd_special_code();
1332 }
1333
1334 /* LCD special escape codes */
1335 /* flush the escape sequence if it's been processed
1336 or if it is getting too long. */
1337 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1338 lcd_escape_len = -1;
1339 } /* escape codes */
1340}
1341
1342static ssize_t lcd_write(struct file *file,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001343 const char __user *buf, size_t count, loff_t *ppos)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001344{
1345 const char __user *tmp = buf;
Willy Tarreau698b1512008-11-22 11:29:33 +01001346 char c;
Willy Tarreau7005b582008-11-13 17:18:59 -08001347
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001348 for (; count-- > 0; (*ppos)++, tmp++) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001349 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001350 /* let's be a little nice with other processes
1351 that need some CPU */
1352 schedule();
Willy Tarreau7005b582008-11-13 17:18:59 -08001353
Bastien Armand6a4193a2014-04-23 19:42:11 +02001354 if (get_user(c, tmp))
Willy Tarreau698b1512008-11-22 11:29:33 +01001355 return -EFAULT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001356
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001357 lcd_write_char(c);
Willy Tarreau7005b582008-11-13 17:18:59 -08001358 }
1359
Willy Tarreau698b1512008-11-22 11:29:33 +01001360 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001361}
1362
Willy Tarreau698b1512008-11-22 11:29:33 +01001363static int lcd_open(struct inode *inode, struct file *file)
1364{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001365 if (!atomic_dec_and_test(&lcd_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001366 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001367
Willy Tarreau698b1512008-11-22 11:29:33 +01001368 if (file->f_mode & FMODE_READ) /* device is write-only */
1369 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001370
Willy Tarreau698b1512008-11-22 11:29:33 +01001371 if (lcd_must_clear) {
1372 lcd_clear_display();
1373 lcd_must_clear = 0;
1374 }
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001375 return nonseekable_open(inode, file);
Willy Tarreau7005b582008-11-13 17:18:59 -08001376}
1377
Willy Tarreau698b1512008-11-22 11:29:33 +01001378static int lcd_release(struct inode *inode, struct file *file)
1379{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001380 atomic_inc(&lcd_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001381 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001382}
1383
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001384static const struct file_operations lcd_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001385 .write = lcd_write,
1386 .open = lcd_open,
1387 .release = lcd_release,
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001388 .llseek = no_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001389};
1390
1391static struct miscdevice lcd_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001392 .minor = LCD_MINOR,
1393 .name = "lcd",
1394 .fops = &lcd_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001395};
1396
Willy Tarreau7005b582008-11-13 17:18:59 -08001397/* public function usable from the kernel for any purpose */
Peter Huewe36d20412013-02-15 13:47:05 +01001398static void panel_lcd_print(const char *s)
Willy Tarreau698b1512008-11-22 11:29:33 +01001399{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001400 const char *tmp = s;
1401 int count = strlen(s);
1402
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001403 if (lcd.enabled && lcd_initialized) {
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001404 for (; count-- > 0; tmp++) {
1405 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1406 /* let's be a little nice with other processes
1407 that need some CPU */
1408 schedule();
1409
1410 lcd_write_char(*tmp);
1411 }
1412 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001413}
1414
Willy Tarreau7005b582008-11-13 17:18:59 -08001415/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +01001416static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001417{
1418 switch (lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001419 case LCD_TYPE_OLD:
1420 /* parallel mode, 8 bits */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001421 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001422 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001423 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001424 lcd_charset = LCD_CHARSET_NORMAL;
1425 if (lcd_e_pin == PIN_NOT_SET)
1426 lcd_e_pin = PIN_STROBE;
1427 if (lcd_rs_pin == PIN_NOT_SET)
1428 lcd_rs_pin = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -08001429
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001430 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001431 lcd_width = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001432 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001433 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001434 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001435 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001436 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001437 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001438 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001439 case LCD_TYPE_KS0074:
1440 /* serial mode, ks0074 */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001441 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001442 lcd_proto = LCD_PROTO_SERIAL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001443 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001444 lcd_charset = LCD_CHARSET_KS0074;
1445 if (lcd_bl_pin == PIN_NOT_SET)
1446 lcd_bl_pin = PIN_AUTOLF;
1447 if (lcd_cl_pin == PIN_NOT_SET)
1448 lcd_cl_pin = PIN_STROBE;
1449 if (lcd_da_pin == PIN_NOT_SET)
1450 lcd_da_pin = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001451
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001452 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001453 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001454 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001455 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001456 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001457 lcd_hwidth = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001458 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001459 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001460 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001461 case LCD_TYPE_NEXCOM:
1462 /* parallel mode, 8 bits, generic */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001463 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001464 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001465 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001466 lcd_charset = LCD_CHARSET_NORMAL;
1467 if (lcd_e_pin == PIN_NOT_SET)
1468 lcd_e_pin = PIN_AUTOLF;
1469 if (lcd_rs_pin == PIN_NOT_SET)
1470 lcd_rs_pin = PIN_SELECP;
1471 if (lcd_rw_pin == PIN_NOT_SET)
1472 lcd_rw_pin = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001473
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001474 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001475 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001476 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001477 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001478 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001479 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001480 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001481 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001482 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001483 case LCD_TYPE_CUSTOM:
1484 /* customer-defined */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001485 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001486 lcd_proto = DEFAULT_LCD_PROTO;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001487 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001488 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001489 /* default geometry will be set later */
1490 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001491 case LCD_TYPE_HANTRONIX:
1492 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +01001493 default:
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001494 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001495 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001496 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001497 lcd_charset = LCD_CHARSET_NORMAL;
1498 if (lcd_e_pin == PIN_NOT_SET)
1499 lcd_e_pin = PIN_STROBE;
1500 if (lcd_rs_pin == PIN_NOT_SET)
1501 lcd_rs_pin = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001502
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001503 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001504 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001505 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001506 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001507 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001508 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001509 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001510 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001511 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001512 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001513
Willy Tarreau698b1512008-11-22 11:29:33 +01001514 /* this is used to catch wrong and default values */
1515 if (lcd_width <= 0)
1516 lcd_width = DEFAULT_LCD_WIDTH;
1517 if (lcd_bwidth <= 0)
1518 lcd_bwidth = DEFAULT_LCD_BWIDTH;
1519 if (lcd_hwidth <= 0)
1520 lcd_hwidth = DEFAULT_LCD_HWIDTH;
1521 if (lcd_height <= 0)
1522 lcd_height = DEFAULT_LCD_HEIGHT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001523
Willy Tarreau698b1512008-11-22 11:29:33 +01001524 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */
1525 lcd_write_cmd = lcd_write_cmd_s;
1526 lcd_write_data = lcd_write_data_s;
1527 lcd_clear_fast = lcd_clear_fast_s;
Willy Tarreau7005b582008-11-13 17:18:59 -08001528
Willy Tarreau698b1512008-11-22 11:29:33 +01001529 if (lcd_cl_pin == PIN_NOT_SET)
1530 lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1531 if (lcd_da_pin == PIN_NOT_SET)
1532 lcd_da_pin = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001533
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001534 } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Willy Tarreau698b1512008-11-22 11:29:33 +01001535 lcd_write_cmd = lcd_write_cmd_p8;
1536 lcd_write_data = lcd_write_data_p8;
1537 lcd_clear_fast = lcd_clear_fast_p8;
Willy Tarreau7005b582008-11-13 17:18:59 -08001538
Willy Tarreau698b1512008-11-22 11:29:33 +01001539 if (lcd_e_pin == PIN_NOT_SET)
1540 lcd_e_pin = DEFAULT_LCD_PIN_E;
1541 if (lcd_rs_pin == PIN_NOT_SET)
1542 lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1543 if (lcd_rw_pin == PIN_NOT_SET)
1544 lcd_rw_pin = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001545 } else {
1546 lcd_write_cmd = lcd_write_cmd_tilcd;
1547 lcd_write_data = lcd_write_data_tilcd;
1548 lcd_clear_fast = lcd_clear_fast_tilcd;
Willy Tarreau698b1512008-11-22 11:29:33 +01001549 }
1550
1551 if (lcd_bl_pin == PIN_NOT_SET)
1552 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1553
1554 if (lcd_e_pin == PIN_NOT_SET)
1555 lcd_e_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001556 if (lcd_rs_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001557 lcd_rs_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001558 if (lcd_rw_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001559 lcd_rw_pin = PIN_NONE;
1560 if (lcd_bl_pin == PIN_NOT_SET)
1561 lcd_bl_pin = PIN_NONE;
1562 if (lcd_cl_pin == PIN_NOT_SET)
1563 lcd_cl_pin = PIN_NONE;
1564 if (lcd_da_pin == PIN_NOT_SET)
1565 lcd_da_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001566
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001567 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001568 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001569
Willy Tarreau698b1512008-11-22 11:29:33 +01001570 if (lcd_charset == LCD_CHARSET_KS0074)
1571 lcd_char_conv = lcd_char_conv_ks0074;
1572 else
1573 lcd_char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001574
Willy Tarreau698b1512008-11-22 11:29:33 +01001575 if (lcd_bl_pin != PIN_NONE)
1576 init_scan_timer();
Willy Tarreau7005b582008-11-13 17:18:59 -08001577
Willy Tarreau698b1512008-11-22 11:29:33 +01001578 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1579 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1580 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1581 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1582 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1583 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1584 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1585 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1586 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1587 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1588 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1589 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001590
Willy Tarreau698b1512008-11-22 11:29:33 +01001591 /* before this line, we must NOT send anything to the display.
1592 * Since lcd_init_display() needs to write data, we have to
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001593 * enable mark the LCD initialized just before. */
Willy Tarreau698b1512008-11-22 11:29:33 +01001594 lcd_initialized = 1;
1595 lcd_init_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001596
Willy Tarreau698b1512008-11-22 11:29:33 +01001597 /* display a short message */
Willy Tarreau7005b582008-11-13 17:18:59 -08001598#ifdef CONFIG_PANEL_CHANGE_MESSAGE
1599#ifdef CONFIG_PANEL_BOOT_MESSAGE
Willy Tarreau698b1512008-11-22 11:29:33 +01001600 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
Willy Tarreau7005b582008-11-13 17:18:59 -08001601#endif
1602#else
Willy Tarreau698b1512008-11-22 11:29:33 +01001603 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1604 PANEL_VERSION);
Willy Tarreau7005b582008-11-13 17:18:59 -08001605#endif
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001606 lcd_addr_x = 0;
1607 lcd_addr_y = 0;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001608 /* clear the display on the next device opening */
1609 lcd_must_clear = 1;
Willy Tarreau698b1512008-11-22 11:29:33 +01001610 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -08001611}
1612
Willy Tarreau7005b582008-11-13 17:18:59 -08001613/*
1614 * These are the file operation function for user access to /dev/keypad
1615 */
1616
Willy Tarreau698b1512008-11-22 11:29:33 +01001617static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001618 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001619{
Willy Tarreau698b1512008-11-22 11:29:33 +01001620 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001621 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001622
Willy Tarreau698b1512008-11-22 11:29:33 +01001623 if (keypad_buflen == 0) {
1624 if (file->f_flags & O_NONBLOCK)
1625 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001626
Arnd Bergmann310df692014-01-02 13:07:35 +01001627 if (wait_event_interruptible(keypad_read_wait,
1628 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001629 return -EINTR;
1630 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001631
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001632 for (; count-- > 0 && (keypad_buflen > 0);
1633 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001634 put_user(keypad_buffer[keypad_start], tmp);
1635 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1636 }
1637 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001638
Willy Tarreau698b1512008-11-22 11:29:33 +01001639 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001640}
1641
Willy Tarreau698b1512008-11-22 11:29:33 +01001642static int keypad_open(struct inode *inode, struct file *file)
1643{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001644 if (!atomic_dec_and_test(&keypad_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001645 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001646
Willy Tarreau698b1512008-11-22 11:29:33 +01001647 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1648 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001649
Willy Tarreau698b1512008-11-22 11:29:33 +01001650 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001651 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001652}
1653
Willy Tarreau698b1512008-11-22 11:29:33 +01001654static int keypad_release(struct inode *inode, struct file *file)
1655{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001656 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001657 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001658}
1659
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001660static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001661 .read = keypad_read, /* read */
1662 .open = keypad_open, /* open */
1663 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001664 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001665};
1666
1667static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001668 .minor = KEYPAD_MINOR,
1669 .name = "keypad",
1670 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001671};
1672
Peter Huewe36d20412013-02-15 13:47:05 +01001673static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001674{
1675 if (init_in_progress)
1676 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001677
Willy Tarreau698b1512008-11-22 11:29:33 +01001678 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001679 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001680 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1681 keypad_buffer[(keypad_start + keypad_buflen++) %
1682 KEYPAD_BUFFER] = *string++;
1683 }
1684 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001685 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001686}
1687
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001688/* this function scans all the bits involving at least one logical signal,
1689 * and puts the results in the bitfield "phys_read" (one bit per established
1690 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001691 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001692 * Note: to debounce input signals, we will only consider as switched a signal
1693 * which is stable across 2 measures. Signals which are different between two
1694 * reads will be kept as they previously were in their logical form (phys_prev).
1695 * A signal which has just switched will have a 1 in
1696 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001697 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001698static void phys_scan_contacts(void)
1699{
1700 int bit, bitval;
1701 char oldval;
1702 char bitmask;
1703 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001704
Willy Tarreau698b1512008-11-22 11:29:33 +01001705 phys_prev = phys_curr;
1706 phys_read_prev = phys_read;
1707 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001708
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001709 /* keep track of old value, with all outputs disabled */
1710 oldval = r_dtr(pprt) | scan_mask_o;
1711 /* activate all keyboard outputs (active low) */
1712 w_dtr(pprt, oldval & ~scan_mask_o);
1713
1714 /* will have a 1 for each bit set to gnd */
1715 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1716 /* disable all matrix signals */
1717 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001718
Willy Tarreau698b1512008-11-22 11:29:33 +01001719 /* now that all outputs are cleared, the only active input bits are
1720 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001721 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001722
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001723 /* 1 for each grounded input */
1724 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1725
1726 /* grounded inputs are signals 40-44 */
1727 phys_read |= (pmask_t) gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001728
Willy Tarreau698b1512008-11-22 11:29:33 +01001729 if (bitmask != gndmask) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001730 /* since clearing the outputs changed some inputs, we know
1731 * that some input signals are currently tied to some outputs.
1732 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001733 */
1734 for (bit = 0; bit < 8; bit++) {
1735 bitval = 1 << bit;
1736
1737 if (!(scan_mask_o & bitval)) /* skip unused bits */
1738 continue;
1739
1740 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1741 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1742 phys_read |= (pmask_t) bitmask << (5 * bit);
1743 }
1744 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001745 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001746 /* this is easy: use old bits when they are flapping,
1747 * use new ones when stable */
1748 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1749 (phys_read & ~(phys_read ^ phys_read_prev));
1750}
1751
1752static inline int input_state_high(struct logical_input *input)
1753{
1754#if 0
1755 /* FIXME:
1756 * this is an invalid test. It tries to catch
1757 * transitions from single-key to multiple-key, but
1758 * doesn't take into account the contacts polarity.
1759 * The only solution to the problem is to parse keys
1760 * from the most complex to the simplest combinations,
1761 * and mark them as 'caught' once a combination
1762 * matches, then unmatch it for all other ones.
1763 */
1764
1765 /* try to catch dangerous transitions cases :
1766 * someone adds a bit, so this signal was a false
1767 * positive resulting from a transition. We should
1768 * invalidate the signal immediately and not call the
1769 * release function.
1770 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1771 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001772 if (((phys_prev & input->mask) == input->value) &&
1773 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001774 input->state = INPUT_ST_LOW; /* invalidate */
1775 return 1;
1776 }
1777#endif
1778
1779 if ((phys_curr & input->mask) == input->value) {
1780 if ((input->type == INPUT_TYPE_STD) &&
1781 (input->high_timer == 0)) {
1782 input->high_timer++;
1783 if (input->u.std.press_fct != NULL)
1784 input->u.std.press_fct(input->u.std.press_data);
1785 } else if (input->type == INPUT_TYPE_KBD) {
1786 /* will turn on the light */
1787 keypressed = 1;
1788
1789 if (input->high_timer == 0) {
1790 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001791
Jake Champline6626de2013-05-04 11:21:17 -04001792 if (press_str[0]) {
1793 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001794
Jake Champline6626de2013-05-04 11:21:17 -04001795 keypad_send_key(press_str, s);
1796 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001797 }
1798
1799 if (input->u.kbd.repeat_str[0]) {
1800 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001801
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001802 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001803 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001804
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001805 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001806 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001807 }
1808 /* we will need to come back here soon */
1809 inputs_stable = 0;
1810 }
1811
1812 if (input->high_timer < 255)
1813 input->high_timer++;
1814 }
1815 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001816 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001817
1818 /* else signal falling down. Let's fall through. */
1819 input->state = INPUT_ST_FALLING;
1820 input->fall_timer = 0;
1821
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001822 return 0;
1823}
1824
1825static inline void input_state_falling(struct logical_input *input)
1826{
1827#if 0
1828 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001829 if (((phys_prev & input->mask) == input->value) &&
1830 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001831 input->state = INPUT_ST_LOW; /* invalidate */
1832 return;
1833 }
1834#endif
1835
1836 if ((phys_curr & input->mask) == input->value) {
1837 if (input->type == INPUT_TYPE_KBD) {
1838 /* will turn on the light */
1839 keypressed = 1;
1840
1841 if (input->u.kbd.repeat_str[0]) {
1842 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001843
Jake Champline6626de2013-05-04 11:21:17 -04001844 if (input->high_timer >= KEYPAD_REP_START) {
1845 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001846
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001847 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001848 keypad_send_key(repeat_str, s);
1849 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001850 /* we will need to come back here soon */
1851 inputs_stable = 0;
1852 }
1853
1854 if (input->high_timer < 255)
1855 input->high_timer++;
1856 }
1857 input->state = INPUT_ST_HIGH;
1858 } else if (input->fall_timer >= input->fall_time) {
1859 /* call release event */
1860 if (input->type == INPUT_TYPE_STD) {
1861 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001862
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001863 if (release_fct != NULL)
1864 release_fct(input->u.std.release_data);
1865 } else if (input->type == INPUT_TYPE_KBD) {
1866 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001867
Jake Champline6626de2013-05-04 11:21:17 -04001868 if (release_str[0]) {
1869 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001870
Jake Champline6626de2013-05-04 11:21:17 -04001871 keypad_send_key(release_str, s);
1872 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001873 }
1874
1875 input->state = INPUT_ST_LOW;
1876 } else {
1877 input->fall_timer++;
1878 inputs_stable = 0;
1879 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001880}
1881
Willy Tarreau698b1512008-11-22 11:29:33 +01001882static void panel_process_inputs(void)
1883{
1884 struct list_head *item;
1885 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001886
Willy Tarreau698b1512008-11-22 11:29:33 +01001887 keypressed = 0;
1888 inputs_stable = 1;
1889 list_for_each(item, &logical_inputs) {
1890 input = list_entry(item, struct logical_input, list);
Willy Tarreau7005b582008-11-13 17:18:59 -08001891
Willy Tarreau698b1512008-11-22 11:29:33 +01001892 switch (input->state) {
1893 case INPUT_ST_LOW:
1894 if ((phys_curr & input->mask) != input->value)
1895 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001896 /* if all needed ones were already set previously,
1897 * this means that this logical signal has been
1898 * activated by the releasing of another combined
1899 * signal, so we don't want to match.
1900 * eg: AB -(release B)-> A -(release A)-> 0 :
1901 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001902 */
1903 if ((phys_prev & input->mask) == input->value)
1904 break;
1905 input->rise_timer = 0;
1906 input->state = INPUT_ST_RISING;
1907 /* no break here, fall through */
1908 case INPUT_ST_RISING:
1909 if ((phys_curr & input->mask) != input->value) {
1910 input->state = INPUT_ST_LOW;
1911 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001912 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001913 if (input->rise_timer < input->rise_time) {
1914 inputs_stable = 0;
1915 input->rise_timer++;
1916 break;
1917 }
1918 input->high_timer = 0;
1919 input->state = INPUT_ST_HIGH;
1920 /* no break here, fall through */
1921 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001922 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001923 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001924 /* no break here, fall through */
1925 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001926 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001927 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001928 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001929}
1930
Willy Tarreau698b1512008-11-22 11:29:33 +01001931static void panel_scan_timer(void)
1932{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001933 if (keypad.enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001934 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001935 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001936
1937 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001938 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001939 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001940
Willy Tarreau698b1512008-11-22 11:29:33 +01001941 if (!inputs_stable || phys_curr != phys_prev)
1942 panel_process_inputs();
1943 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001944
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001945 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001946 if (keypressed) {
1947 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1948 lcd_backlight(1);
1949 light_tempo = FLASH_LIGHT_TEMPO;
1950 } else if (light_tempo > 0) {
1951 light_tempo--;
1952 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1953 lcd_backlight(0);
1954 }
1955 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001956
Willy Tarreau698b1512008-11-22 11:29:33 +01001957 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001958}
1959
Willy Tarreau698b1512008-11-22 11:29:33 +01001960static void init_scan_timer(void)
1961{
1962 if (scan_timer.function != NULL)
1963 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001964
Willy Tarreau698b1512008-11-22 11:29:33 +01001965 init_timer(&scan_timer);
1966 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1967 scan_timer.data = 0;
1968 scan_timer.function = (void *)&panel_scan_timer;
1969 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001970}
1971
1972/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001973 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1974 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001975 * returns 1 if ok, 0 if error (in which case, nothing is written).
1976 */
Peter Huewe36d20412013-02-15 13:47:05 +01001977static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
Willy Tarreau698b1512008-11-22 11:29:33 +01001978 char *imask, char *omask)
1979{
1980 static char sigtab[10] = "EeSsPpAaBb";
1981 char im, om;
1982 pmask_t m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001983
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001984 om = 0ULL;
1985 im = 0ULL;
1986 m = 0ULL;
1987 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001988 while (*name) {
1989 int in, out, bit, neg;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001990
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001991 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
1992 in++)
Willy Tarreau698b1512008-11-22 11:29:33 +01001993 ;
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001994
Willy Tarreau698b1512008-11-22 11:29:33 +01001995 if (in >= sizeof(sigtab))
1996 return 0; /* input name not found */
1997 neg = (in & 1); /* odd (lower) names are negated */
1998 in >>= 1;
1999 im |= (1 << in);
Willy Tarreau7005b582008-11-13 17:18:59 -08002000
Willy Tarreau698b1512008-11-22 11:29:33 +01002001 name++;
2002 if (isdigit(*name)) {
2003 out = *name - '0';
2004 om |= (1 << out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002005 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01002006 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002007 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01002008 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002009 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002010
2011 bit = (out * 5) + in;
2012
2013 m |= 1ULL << bit;
2014 if (!neg)
2015 v |= 1ULL << bit;
2016 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08002017 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002018 *mask = m;
2019 *value = v;
2020 if (imask)
2021 *imask |= im;
2022 if (omask)
2023 *omask |= om;
2024 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002025}
2026
2027/* tries to bind a key to the signal name <name>. The key will send the
2028 * strings <press>, <repeat>, <release> for these respective events.
2029 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2030 */
Peter Huewe36d20412013-02-15 13:47:05 +01002031static struct logical_input *panel_bind_key(const char *name, const char *press,
2032 const char *repeat,
2033 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01002034{
2035 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002036
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002037 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002038 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01002039 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002040
Willy Tarreau698b1512008-11-22 11:29:33 +01002041 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002042 &scan_mask_o)) {
2043 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01002044 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002045 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002046
2047 key->type = INPUT_TYPE_KBD;
2048 key->state = INPUT_ST_LOW;
2049 key->rise_time = 1;
2050 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002051
Willy Tarreau698b1512008-11-22 11:29:33 +01002052 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
2053 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
2054 strncpy(key->u.kbd.release_str, release,
2055 sizeof(key->u.kbd.release_str));
2056 list_add(&key->list, &logical_inputs);
2057 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002058}
2059
Willy Tarreau630231772008-11-22 12:52:18 +01002060#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08002061/* tries to bind a callback function to the signal name <name>. The function
2062 * <press_fct> will be called with the <press_data> arg when the signal is
2063 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002064 * Returns the pointer to the new signal if ok, NULL if the signal could not
2065 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08002066 */
2067static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302068 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002069 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302070 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002071 int release_data)
2072{
2073 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002074
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002075 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002076 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01002077 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002078
Willy Tarreau698b1512008-11-22 11:29:33 +01002079 memset(callback, 0, sizeof(struct logical_input));
2080 if (!input_name2mask(name, &callback->mask, &callback->value,
2081 &scan_mask_i, &scan_mask_o))
2082 return NULL;
2083
2084 callback->type = INPUT_TYPE_STD;
2085 callback->state = INPUT_ST_LOW;
2086 callback->rise_time = 1;
2087 callback->fall_time = 1;
2088 callback->u.std.press_fct = press_fct;
2089 callback->u.std.press_data = press_data;
2090 callback->u.std.release_fct = release_fct;
2091 callback->u.std.release_data = release_data;
2092 list_add(&callback->list, &logical_inputs);
2093 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002094}
Willy Tarreau630231772008-11-22 12:52:18 +01002095#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08002096
Willy Tarreau698b1512008-11-22 11:29:33 +01002097static void keypad_init(void)
2098{
2099 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02002100
Willy Tarreau698b1512008-11-22 11:29:33 +01002101 init_waitqueue_head(&keypad_read_wait);
2102 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08002103
Willy Tarreau698b1512008-11-22 11:29:33 +01002104 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08002105
Willy Tarreau698b1512008-11-22 11:29:33 +01002106 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
2107 panel_bind_key(keypad_profile[keynum][0],
2108 keypad_profile[keynum][1],
2109 keypad_profile[keynum][2],
2110 keypad_profile[keynum][3]);
2111 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002112
Willy Tarreau698b1512008-11-22 11:29:33 +01002113 init_scan_timer();
2114 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002115}
2116
Willy Tarreau7005b582008-11-13 17:18:59 -08002117/**************************************************/
2118/* device initialization */
2119/**************************************************/
2120
Willy Tarreau698b1512008-11-22 11:29:33 +01002121static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2122 void *unused)
2123{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002124 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002125 switch (code) {
2126 case SYS_DOWN:
2127 panel_lcd_print
2128 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2129 break;
2130 case SYS_HALT:
2131 panel_lcd_print
2132 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2133 break;
2134 case SYS_POWER_OFF:
2135 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2136 break;
2137 default:
2138 break;
2139 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002140 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002141 return NOTIFY_DONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08002142}
2143
2144static struct notifier_block panel_notifier = {
2145 panel_notify_sys,
2146 NULL,
2147 0
2148};
2149
Willy Tarreau698b1512008-11-22 11:29:33 +01002150static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002151{
Willy Tarreau698b1512008-11-22 11:29:33 +01002152 if (port->number != parport)
2153 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002154
Willy Tarreau698b1512008-11-22 11:29:33 +01002155 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002156 pr_err("%s: port->number=%d parport=%d, already registered!\n",
2157 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002158 return;
2159 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002160
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002161 pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */
Willy Tarreau698b1512008-11-22 11:29:33 +01002162 NULL,
2163 /*PARPORT_DEV_EXCL */
2164 0, (void *)&pprt);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002165 if (pprt == NULL) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002166 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
2167 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002168 return;
2169 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002170
Willy Tarreau698b1512008-11-22 11:29:33 +01002171 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002172 pr_err("could not claim access to parport%d. Aborting.\n",
2173 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002174 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002175 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002176
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002177 /* must init LCD first, just in case an IRQ from the keypad is
2178 * generated at keypad init
2179 */
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002180 if (lcd.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002181 lcd_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002182 if (misc_register(&lcd_dev))
2183 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002184 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002185
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002186 if (keypad.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002187 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002188 if (misc_register(&keypad_dev))
2189 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01002190 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002191 return;
2192
2193err_lcd_unreg:
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002194 if (lcd.enabled)
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002195 misc_deregister(&lcd_dev);
2196err_unreg_device:
2197 parport_unregister_device(pprt);
2198 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002199}
2200
Willy Tarreau698b1512008-11-22 11:29:33 +01002201static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002202{
Willy Tarreau698b1512008-11-22 11:29:33 +01002203 if (port->number != parport)
2204 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002205
Willy Tarreau698b1512008-11-22 11:29:33 +01002206 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002207 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
2208 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002209 return;
2210 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002211
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002212 if (keypad.enabled && keypad_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002213 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002214 keypad_initialized = 0;
2215 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002216
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002217 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002218 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002219 lcd_initialized = 0;
2220 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002221
Willy Tarreau698b1512008-11-22 11:29:33 +01002222 parport_release(pprt);
2223 parport_unregister_device(pprt);
2224 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002225}
2226
2227static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01002228 .name = "panel",
2229 .attach = panel_attach,
2230 .detach = panel_detach,
Willy Tarreau7005b582008-11-13 17:18:59 -08002231};
2232
2233/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01002234static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002235{
2236 /* for backwards compatibility */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002237 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002238 keypad_type = keypad_enabled;
Willy Tarreau7005b582008-11-13 17:18:59 -08002239
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002240 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002241 lcd_type = lcd_enabled;
Willy Tarreau7005b582008-11-13 17:18:59 -08002242
Willy Tarreau698b1512008-11-22 11:29:33 +01002243 /* take care of an eventual profile */
2244 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002245 case PANEL_PROFILE_CUSTOM:
2246 /* custom profile */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002247 if (keypad_type == NOT_SET)
Mariusz Gorski98fac3d2014-11-12 02:08:09 +01002248 keypad_type = DEFAULT_KEYPAD_TYPE;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002249 if (lcd_type == NOT_SET)
Mariusz Gorski98fac3d2014-11-12 02:08:09 +01002250 lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01002251 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002252 case PANEL_PROFILE_OLD:
2253 /* 8 bits, 2*16, old keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002254 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002255 keypad_type = KEYPAD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002256 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002257 lcd_type = LCD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002258 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002259 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002260 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002261 lcd_hwidth = 16;
2262 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002263 case PANEL_PROFILE_NEW:
2264 /* serial, 2*16, new keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002265 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002266 keypad_type = KEYPAD_TYPE_NEW;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002267 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002268 lcd_type = LCD_TYPE_KS0074;
2269 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002270 case PANEL_PROFILE_HANTRONIX:
2271 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002272 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002273 keypad_type = KEYPAD_TYPE_NONE;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002274 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002275 lcd_type = LCD_TYPE_HANTRONIX;
2276 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002277 case PANEL_PROFILE_NEXCOM:
2278 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002279 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002280 keypad_type = KEYPAD_TYPE_NEXCOM;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002281 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002282 lcd_type = LCD_TYPE_NEXCOM;
2283 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002284 case PANEL_PROFILE_LARGE:
2285 /* 8 bits, 2*40, old keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002286 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002287 keypad_type = KEYPAD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002288 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002289 lcd_type = LCD_TYPE_OLD;
2290 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08002291 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002292
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002293 lcd.enabled = (lcd_type > 0);
2294 keypad.enabled = (keypad_type > 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08002295
Willy Tarreau698b1512008-11-22 11:29:33 +01002296 switch (keypad_type) {
2297 case KEYPAD_TYPE_OLD:
2298 keypad_profile = old_keypad_profile;
2299 break;
2300 case KEYPAD_TYPE_NEW:
2301 keypad_profile = new_keypad_profile;
2302 break;
2303 case KEYPAD_TYPE_NEXCOM:
2304 keypad_profile = nexcom_keypad_profile;
2305 break;
2306 default:
2307 keypad_profile = NULL;
2308 break;
2309 }
2310
2311 /* tells various subsystems about the fact that we are initializing */
2312 init_in_progress = 1;
2313
2314 if (parport_register_driver(&panel_driver)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002315 pr_err("could not register with parport. Aborting.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002316 return -EIO;
2317 }
2318
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002319 if (!lcd.enabled && !keypad.enabled) {
Willy Tarreau630231772008-11-22 12:52:18 +01002320 /* no device enabled, let's release the parport */
Willy Tarreau698b1512008-11-22 11:29:33 +01002321 if (pprt) {
2322 parport_release(pprt);
2323 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002324 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002325 }
2326 parport_unregister_driver(&panel_driver);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002327 pr_err("driver version " PANEL_VERSION " disabled.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002328 return -ENODEV;
2329 }
2330
2331 register_reboot_notifier(&panel_notifier);
2332
2333 if (pprt)
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002334 pr_info("driver version " PANEL_VERSION
2335 " registered on parport%d (io=0x%lx).\n", parport,
2336 pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01002337 else
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002338 pr_info("driver version " PANEL_VERSION
2339 " not yet registered\n");
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002340 /* tells various subsystems about the fact that initialization
2341 is finished */
Willy Tarreau698b1512008-11-22 11:29:33 +01002342 init_in_progress = 0;
2343 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08002344}
2345
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01002346static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002347{
2348 unregister_reboot_notifier(&panel_notifier);
Willy Tarreau7005b582008-11-13 17:18:59 -08002349
Willy Tarreau698b1512008-11-22 11:29:33 +01002350 if (scan_timer.function != NULL)
Julia Lawalle112f892014-03-26 22:33:41 +01002351 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08002352
Costantino Leandro57898132009-02-17 11:10:48 -05002353 if (pprt != NULL) {
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002354 if (keypad.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002355 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002356 keypad_initialized = 0;
2357 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002358
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002359 if (lcd.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002360 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2361 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2362 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002363 lcd_initialized = 0;
Costantino Leandro57898132009-02-17 11:10:48 -05002364 }
2365
2366 /* TODO: free all input signals */
2367 parport_release(pprt);
2368 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002369 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002370 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002371 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08002372}
Willy Tarreau7005b582008-11-13 17:18:59 -08002373
Willy Tarreau7005b582008-11-13 17:18:59 -08002374module_init(panel_init_module);
2375module_exit(panel_cleanup_module);
2376MODULE_AUTHOR("Willy Tarreau");
2377MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08002378
2379/*
2380 * Local variables:
2381 * c-indent-level: 4
2382 * tab-width: 8
2383 * End:
2384 */