blob: 5868a2813b30113c8763ef16b2344f132101188a [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
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100230/* Needed only for init */
231static int selected_lcd_type = NOT_SET;
232
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300233/* contains the LCD config state */
234static unsigned long int lcd_flags;
235/* contains the LCD X offset */
236static unsigned long int lcd_addr_x;
237/* contains the LCD Y offset */
238static unsigned long int lcd_addr_y;
239/* current escape sequence, 0 terminated */
240static char lcd_escape[LCD_ESCAPE_LEN + 1];
241/* not in escape state. >=0 = escape cmd len */
242static int lcd_escape_len = -1;
Willy Tarreau7005b582008-11-13 17:18:59 -0800243
Willy Tarreau7005b582008-11-13 17:18:59 -0800244/*
245 * Bit masks to convert LCD signals to parallel port outputs.
246 * _d_ are values for data port, _c_ are for control port.
247 * [0] = signal OFF, [1] = signal ON, [2] = mask
248 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100249#define BIT_CLR 0
250#define BIT_SET 1
251#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800252#define BIT_STATES 3
253/*
254 * one entry for each bit on the LCD
255 */
256#define LCD_BIT_E 0
257#define LCD_BIT_RS 1
258#define LCD_BIT_RW 2
259#define LCD_BIT_BL 3
260#define LCD_BIT_CL 4
261#define LCD_BIT_DA 5
262#define LCD_BITS 6
263
264/*
265 * each bit can be either connected to a DATA or CTRL port
266 */
267#define LCD_PORT_C 0
268#define LCD_PORT_D 1
269#define LCD_PORTS 2
270
271static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
272
273/*
274 * LCD protocols
275 */
276#define LCD_PROTO_PARALLEL 0
277#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400278#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800279
280/*
281 * LCD character sets
282 */
283#define LCD_CHARSET_NORMAL 0
284#define LCD_CHARSET_KS0074 1
285
286/*
287 * LCD types
288 */
289#define LCD_TYPE_NONE 0
290#define LCD_TYPE_OLD 1
291#define LCD_TYPE_KS0074 2
292#define LCD_TYPE_HANTRONIX 3
293#define LCD_TYPE_NEXCOM 4
294#define LCD_TYPE_CUSTOM 5
295
296/*
297 * keypad types
298 */
299#define KEYPAD_TYPE_NONE 0
300#define KEYPAD_TYPE_OLD 1
301#define KEYPAD_TYPE_NEW 2
302#define KEYPAD_TYPE_NEXCOM 3
303
304/*
305 * panel profiles
306 */
307#define PANEL_PROFILE_CUSTOM 0
308#define PANEL_PROFILE_OLD 1
309#define PANEL_PROFILE_NEW 2
310#define PANEL_PROFILE_HANTRONIX 3
311#define PANEL_PROFILE_NEXCOM 4
312#define PANEL_PROFILE_LARGE 5
313
314/*
315 * Construct custom config from the kernel's configuration
316 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800317#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100318#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100319#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
320#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100321#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800322#define DEFAULT_LCD_WIDTH 40
323#define DEFAULT_LCD_BWIDTH 40
324#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100325#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800326#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
327
328#define DEFAULT_LCD_PIN_E PIN_AUTOLF
329#define DEFAULT_LCD_PIN_RS PIN_SELECP
330#define DEFAULT_LCD_PIN_RW PIN_INITP
331#define DEFAULT_LCD_PIN_SCL PIN_STROBE
332#define DEFAULT_LCD_PIN_SDA PIN_D0
333#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800334
Willy Tarreau7005b582008-11-13 17:18:59 -0800335#ifdef CONFIG_PANEL_PARPORT
336#undef DEFAULT_PARPORT
337#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
338#endif
339
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100340#ifdef CONFIG_PANEL_PROFILE
341#undef DEFAULT_PROFILE
342#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
343#endif
344
Willy Tarreau698b1512008-11-22 11:29:33 +0100345#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800346#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100347#undef DEFAULT_KEYPAD_TYPE
348#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800349#endif
350
Willy Tarreau7005b582008-11-13 17:18:59 -0800351#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100352#undef DEFAULT_LCD_TYPE
353#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800354#endif
355
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100356#ifdef CONFIG_PANEL_LCD_HEIGHT
357#undef DEFAULT_LCD_HEIGHT
358#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
359#endif
360
Willy Tarreau7005b582008-11-13 17:18:59 -0800361#ifdef CONFIG_PANEL_LCD_WIDTH
362#undef DEFAULT_LCD_WIDTH
363#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
364#endif
365
366#ifdef CONFIG_PANEL_LCD_BWIDTH
367#undef DEFAULT_LCD_BWIDTH
368#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
369#endif
370
371#ifdef CONFIG_PANEL_LCD_HWIDTH
372#undef DEFAULT_LCD_HWIDTH
373#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
374#endif
375
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100376#ifdef CONFIG_PANEL_LCD_CHARSET
377#undef DEFAULT_LCD_CHARSET
378#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800379#endif
380
381#ifdef CONFIG_PANEL_LCD_PROTO
382#undef DEFAULT_LCD_PROTO
383#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
384#endif
385
386#ifdef CONFIG_PANEL_LCD_PIN_E
387#undef DEFAULT_LCD_PIN_E
388#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
389#endif
390
391#ifdef CONFIG_PANEL_LCD_PIN_RS
392#undef DEFAULT_LCD_PIN_RS
393#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
394#endif
395
396#ifdef CONFIG_PANEL_LCD_PIN_RW
397#undef DEFAULT_LCD_PIN_RW
398#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
399#endif
400
401#ifdef CONFIG_PANEL_LCD_PIN_SCL
402#undef DEFAULT_LCD_PIN_SCL
403#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
404#endif
405
406#ifdef CONFIG_PANEL_LCD_PIN_SDA
407#undef DEFAULT_LCD_PIN_SDA
408#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
409#endif
410
411#ifdef CONFIG_PANEL_LCD_PIN_BL
412#undef DEFAULT_LCD_PIN_BL
413#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
414#endif
415
Willy Tarreau7005b582008-11-13 17:18:59 -0800416#endif /* DEFAULT_PROFILE == 0 */
417
418/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100419
420/* Device single-open policy control */
421static atomic_t lcd_available = ATOMIC_INIT(1);
422static atomic_t keypad_available = ATOMIC_INIT(1);
423
Willy Tarreau698b1512008-11-22 11:29:33 +0100424static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800425
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100426static int lcd_initialized;
427static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800428
Willy Tarreau698b1512008-11-22 11:29:33 +0100429static int light_tempo;
Willy Tarreau7005b582008-11-13 17:18:59 -0800430
Willy Tarreau698b1512008-11-22 11:29:33 +0100431static char lcd_must_clear;
432static char lcd_left_shift;
433static char init_in_progress;
Willy Tarreau7005b582008-11-13 17:18:59 -0800434
Monam Agarwal68d386b2014-02-25 19:40:49 +0530435static void (*lcd_write_cmd)(int);
436static void (*lcd_write_data)(int);
437static void (*lcd_clear_fast)(void);
Willy Tarreau7005b582008-11-13 17:18:59 -0800438
Willy Tarreau698b1512008-11-22 11:29:33 +0100439static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800440static struct timer_list scan_timer;
441
Willy Tarreau630231772008-11-22 12:52:18 +0100442MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100443
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100444static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100445module_param(parport, int, 0000);
446MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100447
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100448static int profile = DEFAULT_PROFILE;
449module_param(profile, int, 0000);
450MODULE_PARM_DESC(profile,
451 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
452 "4=16x2 nexcom; default=40x2, old kp");
453
Mariusz Gorski36277d42014-11-27 22:36:47 +0100454static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100455module_param(keypad_type, int, 0000);
456MODULE_PARM_DESC(keypad_type,
457 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
458
Mariusz Gorski36277d42014-11-27 22:36:47 +0100459static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100460module_param(lcd_type, int, 0000);
461MODULE_PARM_DESC(lcd_type,
462 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
463
Mariusz Gorski36277d42014-11-27 22:36:47 +0100464static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100465module_param(lcd_height, int, 0000);
466MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100467
Mariusz Gorski36277d42014-11-27 22:36:47 +0100468static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100469module_param(lcd_width, int, 0000);
470MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100471
Mariusz Gorski36277d42014-11-27 22:36:47 +0100472static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100473module_param(lcd_bwidth, int, 0000);
474MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100475
Mariusz Gorski36277d42014-11-27 22:36:47 +0100476static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100477module_param(lcd_hwidth, int, 0000);
478MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100479
Mariusz Gorski36277d42014-11-27 22:36:47 +0100480static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100481module_param(lcd_charset, int, 0000);
482MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100483
Mariusz Gorski36277d42014-11-27 22:36:47 +0100484static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100485module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300486MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200487 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100488
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100489/*
490 * These are the parallel port pins the LCD control signals are connected to.
491 * Set this to 0 if the signal is not used. Set it to its opposite value
492 * (negative) if the signal is negated. -MAXINT is used to indicate that the
493 * pin has not been explicitly specified.
494 *
Willy Tarreau630231772008-11-22 12:52:18 +0100495 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100496 */
497
498static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100499module_param(lcd_e_pin, int, 0000);
500MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530501 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100502
503static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100504module_param(lcd_rs_pin, int, 0000);
505MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530506 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100507
508static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100509module_param(lcd_rw_pin, int, 0000);
510MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530511 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100512
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100513static int lcd_cl_pin = PIN_NOT_SET;
514module_param(lcd_cl_pin, int, 0000);
515MODULE_PARM_DESC(lcd_cl_pin,
516 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100517
518static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100519module_param(lcd_da_pin, int, 0000);
520MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530521 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100522
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100523static int lcd_bl_pin = PIN_NOT_SET;
524module_param(lcd_bl_pin, int, 0000);
525MODULE_PARM_DESC(lcd_bl_pin,
526 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
527
528/* Deprecated module parameters - consider not using them anymore */
529
Mariusz Gorski36277d42014-11-27 22:36:47 +0100530static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100531module_param(lcd_enabled, int, 0000);
532MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
533
Mariusz Gorski36277d42014-11-27 22:36:47 +0100534static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100535module_param(keypad_enabled, int, 0000);
536MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
537
Willy Tarreau7005b582008-11-13 17:18:59 -0800538
Peter Huewe36d20412013-02-15 13:47:05 +0100539static const unsigned char *lcd_char_conv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800540
541/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100542static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100543 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
544 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
545 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
546 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
547 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
548 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
549 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
550 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
551 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
552 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
553 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
554 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
555 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
556 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
557 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
558 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
559 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
560 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
561 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
562 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
563 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
564 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
565 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
566 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
567 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
568 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
569 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
570 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
571 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
572 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
573 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
574 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
575 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800576};
577
Peter Huewe36d20412013-02-15 13:47:05 +0100578static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100579 {"S0", "Left\n", "Left\n", ""},
580 {"S1", "Down\n", "Down\n", ""},
581 {"S2", "Up\n", "Up\n", ""},
582 {"S3", "Right\n", "Right\n", ""},
583 {"S4", "Esc\n", "Esc\n", ""},
584 {"S5", "Ret\n", "Ret\n", ""},
585 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800586};
587
588/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100589static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100590 {"S0", "Left\n", "Left\n", ""},
591 {"S1", "Down\n", "Down\n", ""},
592 {"S2", "Up\n", "Up\n", ""},
593 {"S3", "Right\n", "Right\n", ""},
594 {"S4s5", "", "Esc\n", "Esc\n"},
595 {"s4S5", "", "Ret\n", "Ret\n"},
596 {"S4S5", "Help\n", "", ""},
597 /* add new signals above this line */
598 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800599};
600
601/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100602static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100603 {"a-p-e-", "Down\n", "Down\n", ""},
604 {"a-p-E-", "Ret\n", "Ret\n", ""},
605 {"a-P-E-", "Esc\n", "Esc\n", ""},
606 {"a-P-e-", "Up\n", "Up\n", ""},
607 /* add new signals above this line */
608 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800609};
610
Peter Huewe36d20412013-02-15 13:47:05 +0100611static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800612
613/* FIXME: this should be converted to a bit array containing signals states */
614static struct {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300615 unsigned char e; /* parallel LCD E (data latch on falling edge) */
616 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
617 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
618 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
619 unsigned char cl; /* serial LCD clock (latch on rising edge) */
620 unsigned char da; /* serial LCD data */
Willy Tarreau7005b582008-11-13 17:18:59 -0800621} bits;
622
623static void init_scan_timer(void);
624
625/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100626static int set_data_bits(void)
627{
628 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800629
Willy Tarreau698b1512008-11-22 11:29:33 +0100630 val = r_dtr(pprt);
631 for (bit = 0; bit < LCD_BITS; bit++)
632 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800633
Willy Tarreau698b1512008-11-22 11:29:33 +0100634 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
635 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
636 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
637 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
638 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
639 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800640
Willy Tarreau698b1512008-11-22 11:29:33 +0100641 w_dtr(pprt, val);
642 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800643}
644
645/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100646static int set_ctrl_bits(void)
647{
648 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800649
Willy Tarreau698b1512008-11-22 11:29:33 +0100650 val = r_ctr(pprt);
651 for (bit = 0; bit < LCD_BITS; bit++)
652 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800653
Willy Tarreau698b1512008-11-22 11:29:33 +0100654 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
655 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
656 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
657 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
658 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
659 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800660
Willy Tarreau698b1512008-11-22 11:29:33 +0100661 w_ctr(pprt, val);
662 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800663}
664
665/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530666static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100667{
668 set_data_bits();
669 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800670}
671
672/*
673 * Converts a parallel port pin (from -25 to 25) to data and control ports
674 * masks, and data and control port bits. The signal will be considered
675 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
676 *
677 * Result will be used this way :
678 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
679 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
680 */
Peter Huewe36d20412013-02-15 13:47:05 +0100681static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100682{
683 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800684
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200685 d_val[0] = 0;
686 c_val[0] = 0;
687 d_val[1] = 0;
688 c_val[1] = 0;
689 d_val[2] = 0xFF;
690 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800691
Willy Tarreau698b1512008-11-22 11:29:33 +0100692 if (pin == 0)
693 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800694
Willy Tarreau698b1512008-11-22 11:29:33 +0100695 inv = (pin < 0);
696 if (inv)
697 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800698
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200699 d_bit = 0;
700 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800701
Willy Tarreau698b1512008-11-22 11:29:33 +0100702 switch (pin) {
703 case PIN_STROBE: /* strobe, inverted */
704 c_bit = PNL_PSTROBE;
705 inv = !inv;
706 break;
707 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
708 d_bit = 1 << (pin - 2);
709 break;
710 case PIN_AUTOLF: /* autofeed, inverted */
711 c_bit = PNL_PAUTOLF;
712 inv = !inv;
713 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300714 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100715 c_bit = PNL_PINITP;
716 break;
717 case PIN_SELECP: /* select_in, inverted */
718 c_bit = PNL_PSELECP;
719 inv = !inv;
720 break;
721 default: /* unknown pin, ignore */
722 break;
723 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800724
Willy Tarreau698b1512008-11-22 11:29:33 +0100725 if (c_bit) {
726 c_val[2] &= ~c_bit;
727 c_val[!inv] = c_bit;
728 } else if (d_bit) {
729 d_val[2] &= ~d_bit;
730 d_val[!inv] = d_bit;
731 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800732}
733
734/* sleeps that many milliseconds with a reschedule */
Willy Tarreau698b1512008-11-22 11:29:33 +0100735static void long_sleep(int ms)
736{
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200737 if (in_interrupt()) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100738 mdelay(ms);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200739 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +0100740 current->state = TASK_INTERRUPTIBLE;
741 schedule_timeout((ms * HZ + 999) / 1000);
742 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800743}
744
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300745/* send a serial byte to the LCD panel. The caller is responsible for locking
746 if needed. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100747static void lcd_send_serial(int byte)
748{
749 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800750
Willy Tarreau698b1512008-11-22 11:29:33 +0100751 /* the data bit is set on D0, and the clock on STROBE.
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300752 * LCD reads D0 on STROBE's rising edge. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100753 for (bit = 0; bit < 8; bit++) {
754 bits.cl = BIT_CLR; /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530755 panel_set_bits();
Willy Tarreau698b1512008-11-22 11:29:33 +0100756 bits.da = byte & 1;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530757 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300758 udelay(2); /* maintain the data during 2 us before CLK up */
Willy Tarreau698b1512008-11-22 11:29:33 +0100759 bits.cl = BIT_SET; /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530760 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300761 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100762 byte >>= 1;
763 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800764}
765
766/* turn the backlight on or off */
Willy Tarreau698b1512008-11-22 11:29:33 +0100767static void lcd_backlight(int on)
768{
769 if (lcd_bl_pin == PIN_NONE)
770 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800771
Justin P. Mattock6975e182012-03-19 08:17:52 -0700772 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800773 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100774 bits.bl = on;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530775 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800776 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800777}
778
779/* send a command to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100780static void lcd_write_cmd_s(int cmd)
781{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800782 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100783 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
784 lcd_send_serial(cmd & 0x0F);
785 lcd_send_serial((cmd >> 4) & 0x0F);
786 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800787 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800788}
789
790/* send data to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100791static void lcd_write_data_s(int data)
792{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800793 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100794 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
795 lcd_send_serial(data & 0x0F);
796 lcd_send_serial((data >> 4) & 0x0F);
797 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800798 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800799}
800
801/* send a command to the LCD panel in 8 bits parallel mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100802static void lcd_write_cmd_p8(int cmd)
803{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800804 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800805 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100806 w_dtr(pprt, cmd);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300807 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800808
Willy Tarreau698b1512008-11-22 11:29:33 +0100809 bits.e = BIT_SET;
810 bits.rs = BIT_CLR;
811 bits.rw = BIT_CLR;
Willy Tarreau7005b582008-11-13 17:18:59 -0800812 set_ctrl_bits();
813
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300814 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800815
816 bits.e = BIT_CLR;
817 set_ctrl_bits();
818
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300819 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800820 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100821}
Willy Tarreau7005b582008-11-13 17:18:59 -0800822
Willy Tarreau698b1512008-11-22 11:29:33 +0100823/* send data to the LCD panel in 8 bits parallel mode */
824static void lcd_write_data_p8(int data)
825{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800826 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100827 /* present the data to the data port */
828 w_dtr(pprt, data);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300829 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100830
831 bits.e = BIT_SET;
832 bits.rs = BIT_SET;
833 bits.rw = BIT_CLR;
834 set_ctrl_bits();
835
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300836 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100837
838 bits.e = BIT_CLR;
839 set_ctrl_bits();
840
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300841 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800842 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100843}
844
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400845/* send a command to the TI LCD panel */
846static void lcd_write_cmd_tilcd(int cmd)
847{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800848 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400849 /* present the data to the control port */
850 w_ctr(pprt, cmd);
851 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800852 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400853}
854
855/* send data to the TI LCD panel */
856static void lcd_write_data_tilcd(int data)
857{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800858 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400859 /* present the data to the data port */
860 w_dtr(pprt, data);
861 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800862 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400863}
864
Willy Tarreau698b1512008-11-22 11:29:33 +0100865static void lcd_gotoxy(void)
866{
867 lcd_write_cmd(0x80 /* set DDRAM address */
868 | (lcd_addr_y ? lcd_hwidth : 0)
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300869 /* we force the cursor to stay at the end of the
870 line if it wants to go farther */
Willy Tarreau698b1512008-11-22 11:29:33 +0100871 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
872 (lcd_hwidth - 1) : lcd_bwidth - 1));
873}
874
875static void lcd_print(char c)
876{
877 if (lcd_addr_x < lcd_bwidth) {
878 if (lcd_char_conv != NULL)
879 c = lcd_char_conv[(unsigned char)c];
880 lcd_write_data(c);
881 lcd_addr_x++;
882 }
883 /* prevents the cursor from wrapping onto the next line */
884 if (lcd_addr_x == lcd_bwidth)
885 lcd_gotoxy();
886}
887
888/* fills the display with spaces and resets X/Y */
889static void lcd_clear_fast_s(void)
890{
891 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200892
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200893 lcd_addr_x = 0;
894 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100895 lcd_gotoxy();
896
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800897 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100898 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
899 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
900 lcd_send_serial(' ' & 0x0F);
901 lcd_send_serial((' ' >> 4) & 0x0F);
902 udelay(40); /* the shortest data takes at least 40 us */
903 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800904 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100905
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200906 lcd_addr_x = 0;
907 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100908 lcd_gotoxy();
909}
910
911/* fills the display with spaces and resets X/Y */
912static void lcd_clear_fast_p8(void)
913{
914 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200915
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200916 lcd_addr_x = 0;
917 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100918 lcd_gotoxy();
919
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800920 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100921 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
922 /* present the data to the data port */
923 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300924
925 /* maintain the data during 20 us before the strobe */
926 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100927
928 bits.e = BIT_SET;
929 bits.rs = BIT_SET;
930 bits.rw = BIT_CLR;
931 set_ctrl_bits();
932
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300933 /* maintain the strobe during 40 us */
934 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100935
936 bits.e = BIT_CLR;
937 set_ctrl_bits();
938
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300939 /* the shortest data takes at least 45 us */
940 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100941 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800942 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100943
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200944 lcd_addr_x = 0;
945 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100946 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -0800947}
948
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400949/* fills the display with spaces and resets X/Y */
950static void lcd_clear_fast_tilcd(void)
951{
952 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200953
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200954 lcd_addr_x = 0;
955 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400956 lcd_gotoxy();
957
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800958 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400959 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
960 /* present the data to the data port */
961 w_dtr(pprt, ' ');
962 udelay(60);
963 }
964
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800965 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400966
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200967 lcd_addr_x = 0;
968 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400969 lcd_gotoxy();
970}
971
Willy Tarreau7005b582008-11-13 17:18:59 -0800972/* clears the display and resets X/Y */
Willy Tarreau698b1512008-11-22 11:29:33 +0100973static void lcd_clear_display(void)
974{
975 lcd_write_cmd(0x01); /* clear display */
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200976 lcd_addr_x = 0;
977 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100978 /* we must wait a few milliseconds (15) */
979 long_sleep(15);
Willy Tarreau7005b582008-11-13 17:18:59 -0800980}
981
Willy Tarreau698b1512008-11-22 11:29:33 +0100982static void lcd_init_display(void)
983{
Willy Tarreau698b1512008-11-22 11:29:33 +0100984 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
985 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
Willy Tarreau7005b582008-11-13 17:18:59 -0800986
Willy Tarreau698b1512008-11-22 11:29:33 +0100987 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
Willy Tarreau7005b582008-11-13 17:18:59 -0800988
Willy Tarreau698b1512008-11-22 11:29:33 +0100989 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
990 long_sleep(10);
991 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
992 long_sleep(10);
993 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
994 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800995
Willy Tarreau698b1512008-11-22 11:29:33 +0100996 lcd_write_cmd(0x30 /* set font height and lines number */
997 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
998 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
999 );
1000 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001001
Willy Tarreau698b1512008-11-22 11:29:33 +01001002 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
1003 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001004
Willy Tarreau698b1512008-11-22 11:29:33 +01001005 lcd_write_cmd(0x08 /* set display mode */
1006 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1007 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1008 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
1009 );
Willy Tarreau7005b582008-11-13 17:18:59 -08001010
Willy Tarreau698b1512008-11-22 11:29:33 +01001011 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08001012
Willy Tarreau698b1512008-11-22 11:29:33 +01001013 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001014
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001015 /* entry mode set : increment, cursor shifting */
1016 lcd_write_cmd(0x06);
Willy Tarreau7005b582008-11-13 17:18:59 -08001017
Willy Tarreau698b1512008-11-22 11:29:33 +01001018 lcd_clear_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001019}
1020
1021/*
1022 * These are the file operation function for user access to /dev/lcd
1023 * This function can also be called from inside the kernel, by
1024 * setting file and ppos to NULL.
1025 *
1026 */
1027
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001028static inline int handle_lcd_special_code(void)
1029{
1030 /* LCD special codes */
1031
1032 int processed = 0;
1033
1034 char *esc = lcd_escape + 2;
1035 int oldflags = lcd_flags;
1036
1037 /* check for display mode flags */
1038 switch (*esc) {
1039 case 'D': /* Display ON */
1040 lcd_flags |= LCD_FLAG_D;
1041 processed = 1;
1042 break;
1043 case 'd': /* Display OFF */
1044 lcd_flags &= ~LCD_FLAG_D;
1045 processed = 1;
1046 break;
1047 case 'C': /* Cursor ON */
1048 lcd_flags |= LCD_FLAG_C;
1049 processed = 1;
1050 break;
1051 case 'c': /* Cursor OFF */
1052 lcd_flags &= ~LCD_FLAG_C;
1053 processed = 1;
1054 break;
1055 case 'B': /* Blink ON */
1056 lcd_flags |= LCD_FLAG_B;
1057 processed = 1;
1058 break;
1059 case 'b': /* Blink OFF */
1060 lcd_flags &= ~LCD_FLAG_B;
1061 processed = 1;
1062 break;
1063 case '+': /* Back light ON */
1064 lcd_flags |= LCD_FLAG_L;
1065 processed = 1;
1066 break;
1067 case '-': /* Back light OFF */
1068 lcd_flags &= ~LCD_FLAG_L;
1069 processed = 1;
1070 break;
1071 case '*':
1072 /* flash back light using the keypad timer */
1073 if (scan_timer.function != NULL) {
1074 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1075 lcd_backlight(1);
1076 light_tempo = FLASH_LIGHT_TEMPO;
1077 }
1078 processed = 1;
1079 break;
1080 case 'f': /* Small Font */
1081 lcd_flags &= ~LCD_FLAG_F;
1082 processed = 1;
1083 break;
1084 case 'F': /* Large Font */
1085 lcd_flags |= LCD_FLAG_F;
1086 processed = 1;
1087 break;
1088 case 'n': /* One Line */
1089 lcd_flags &= ~LCD_FLAG_N;
1090 processed = 1;
1091 break;
1092 case 'N': /* Two Lines */
1093 lcd_flags |= LCD_FLAG_N;
1094 break;
1095 case 'l': /* Shift Cursor Left */
1096 if (lcd_addr_x > 0) {
1097 /* back one char if not at end of line */
1098 if (lcd_addr_x < lcd_bwidth)
1099 lcd_write_cmd(0x10);
1100 lcd_addr_x--;
1101 }
1102 processed = 1;
1103 break;
1104 case 'r': /* shift cursor right */
1105 if (lcd_addr_x < lcd_width) {
1106 /* allow the cursor to pass the end of the line */
1107 if (lcd_addr_x <
1108 (lcd_bwidth - 1))
1109 lcd_write_cmd(0x14);
1110 lcd_addr_x++;
1111 }
1112 processed = 1;
1113 break;
1114 case 'L': /* shift display left */
1115 lcd_left_shift++;
1116 lcd_write_cmd(0x18);
1117 processed = 1;
1118 break;
1119 case 'R': /* shift display right */
1120 lcd_left_shift--;
1121 lcd_write_cmd(0x1C);
1122 processed = 1;
1123 break;
1124 case 'k': { /* kill end of line */
1125 int x;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001126
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001127 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1128 lcd_write_data(' ');
1129
1130 /* restore cursor position */
1131 lcd_gotoxy();
1132 processed = 1;
1133 break;
1134 }
1135 case 'I': /* reinitialize display */
1136 lcd_init_display();
1137 lcd_left_shift = 0;
1138 processed = 1;
1139 break;
1140 case 'G': {
1141 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1142 * and '7', representing the numerical ASCII code of the
1143 * redefined character, and <xx...xx> a sequence of 16
1144 * hex digits representing 8 bytes for each character.
1145 * Most LCDs will only use 5 lower bits of the 7 first
1146 * bytes.
1147 */
1148
1149 unsigned char cgbytes[8];
1150 unsigned char cgaddr;
1151 int cgoffset;
1152 int shift;
1153 char value;
1154 int addr;
1155
1156 if (strchr(esc, ';') == NULL)
1157 break;
1158
1159 esc++;
1160
1161 cgaddr = *(esc++) - '0';
1162 if (cgaddr > 7) {
1163 processed = 1;
1164 break;
1165 }
1166
1167 cgoffset = 0;
1168 shift = 0;
1169 value = 0;
1170 while (*esc && cgoffset < 8) {
1171 shift ^= 4;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001172 if (*esc >= '0' && *esc <= '9') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001173 value |= (*esc - '0') << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001174 } else if (*esc >= 'A' && *esc <= 'Z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001175 value |= (*esc - 'A' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001176 } else if (*esc >= 'a' && *esc <= 'z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001177 value |= (*esc - 'a' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001178 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001179 esc++;
1180 continue;
1181 }
1182
1183 if (shift == 0) {
1184 cgbytes[cgoffset++] = value;
1185 value = 0;
1186 }
1187
1188 esc++;
1189 }
1190
1191 lcd_write_cmd(0x40 | (cgaddr * 8));
1192 for (addr = 0; addr < cgoffset; addr++)
1193 lcd_write_data(cgbytes[addr]);
1194
1195 /* ensures that we stop writing to CGRAM */
1196 lcd_gotoxy();
1197 processed = 1;
1198 break;
1199 }
1200 case 'x': /* gotoxy : LxXXX[yYYY]; */
1201 case 'y': /* gotoxy : LyYYY[xXXX]; */
1202 if (strchr(esc, ';') == NULL)
1203 break;
1204
1205 while (*esc) {
1206 if (*esc == 'x') {
1207 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001208 if (kstrtoul(esc, 10, &lcd_addr_x) < 0)
1209 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001210 } else if (*esc == 'y') {
1211 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001212 if (kstrtoul(esc, 10, &lcd_addr_y) < 0)
1213 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001214 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001215 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001216 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001217 }
1218
1219 lcd_gotoxy();
1220 processed = 1;
1221 break;
1222 }
1223
Adam Buchbinderf2635892012-09-19 21:51:07 -04001224 /* Check whether one flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001225 if (oldflags != lcd_flags) {
1226 /* check whether one of B,C,D flags were changed */
1227 if ((oldflags ^ lcd_flags) &
1228 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1229 /* set display mode */
1230 lcd_write_cmd(0x08
1231 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1232 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1233 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1234 /* check whether one of F,N flags was changed */
1235 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1236 lcd_write_cmd(0x30
1237 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1238 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
Adam Buchbinderf2635892012-09-19 21:51:07 -04001239 /* check whether L flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001240 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1241 if (lcd_flags & (LCD_FLAG_L))
1242 lcd_backlight(1);
1243 else if (light_tempo == 0)
1244 /* switch off the light only when the tempo
1245 lighting is gone */
1246 lcd_backlight(0);
1247 }
1248 }
1249
1250 return processed;
1251}
1252
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001253static void lcd_write_char(char c)
Willy Tarreau698b1512008-11-22 11:29:33 +01001254{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001255 /* first, we'll test if we're in escape mode */
1256 if ((c != '\n') && lcd_escape_len >= 0) {
1257 /* yes, let's add this char to the buffer */
1258 lcd_escape[lcd_escape_len++] = c;
1259 lcd_escape[lcd_escape_len] = 0;
1260 } else {
1261 /* aborts any previous escape sequence */
1262 lcd_escape_len = -1;
1263
1264 switch (c) {
1265 case LCD_ESCAPE_CHAR:
1266 /* start of an escape sequence */
1267 lcd_escape_len = 0;
1268 lcd_escape[lcd_escape_len] = 0;
1269 break;
1270 case '\b':
1271 /* go back one char and clear it */
1272 if (lcd_addr_x > 0) {
1273 /* check if we're not at the
1274 end of the line */
1275 if (lcd_addr_x < lcd_bwidth)
1276 /* back one char */
1277 lcd_write_cmd(0x10);
1278 lcd_addr_x--;
1279 }
1280 /* replace with a space */
1281 lcd_write_data(' ');
1282 /* back one char again */
1283 lcd_write_cmd(0x10);
1284 break;
1285 case '\014':
1286 /* quickly clear the display */
1287 lcd_clear_fast();
1288 break;
1289 case '\n':
1290 /* flush the remainder of the current line and
1291 go to the beginning of the next line */
1292 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1293 lcd_write_data(' ');
1294 lcd_addr_x = 0;
1295 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1296 lcd_gotoxy();
1297 break;
1298 case '\r':
1299 /* go to the beginning of the same line */
1300 lcd_addr_x = 0;
1301 lcd_gotoxy();
1302 break;
1303 case '\t':
1304 /* print a space instead of the tab */
1305 lcd_print(' ');
1306 break;
1307 default:
1308 /* simply print this char */
1309 lcd_print(c);
1310 break;
1311 }
1312 }
1313
1314 /* now we'll see if we're in an escape mode and if the current
1315 escape sequence can be understood. */
1316 if (lcd_escape_len >= 2) {
1317 int processed = 0;
1318
1319 if (!strcmp(lcd_escape, "[2J")) {
1320 /* clear the display */
1321 lcd_clear_fast();
1322 processed = 1;
1323 } else if (!strcmp(lcd_escape, "[H")) {
1324 /* cursor to home */
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001325 lcd_addr_x = 0;
1326 lcd_addr_y = 0;
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001327 lcd_gotoxy();
1328 processed = 1;
1329 }
1330 /* codes starting with ^[[L */
1331 else if ((lcd_escape_len >= 3) &&
1332 (lcd_escape[0] == '[') &&
1333 (lcd_escape[1] == 'L')) {
1334 processed = handle_lcd_special_code();
1335 }
1336
1337 /* LCD special escape codes */
1338 /* flush the escape sequence if it's been processed
1339 or if it is getting too long. */
1340 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1341 lcd_escape_len = -1;
1342 } /* escape codes */
1343}
1344
1345static ssize_t lcd_write(struct file *file,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001346 const char __user *buf, size_t count, loff_t *ppos)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001347{
1348 const char __user *tmp = buf;
Willy Tarreau698b1512008-11-22 11:29:33 +01001349 char c;
Willy Tarreau7005b582008-11-13 17:18:59 -08001350
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001351 for (; count-- > 0; (*ppos)++, tmp++) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001352 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001353 /* let's be a little nice with other processes
1354 that need some CPU */
1355 schedule();
Willy Tarreau7005b582008-11-13 17:18:59 -08001356
Bastien Armand6a4193a2014-04-23 19:42:11 +02001357 if (get_user(c, tmp))
Willy Tarreau698b1512008-11-22 11:29:33 +01001358 return -EFAULT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001359
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001360 lcd_write_char(c);
Willy Tarreau7005b582008-11-13 17:18:59 -08001361 }
1362
Willy Tarreau698b1512008-11-22 11:29:33 +01001363 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001364}
1365
Willy Tarreau698b1512008-11-22 11:29:33 +01001366static int lcd_open(struct inode *inode, struct file *file)
1367{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001368 if (!atomic_dec_and_test(&lcd_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001369 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001370
Willy Tarreau698b1512008-11-22 11:29:33 +01001371 if (file->f_mode & FMODE_READ) /* device is write-only */
1372 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001373
Willy Tarreau698b1512008-11-22 11:29:33 +01001374 if (lcd_must_clear) {
1375 lcd_clear_display();
1376 lcd_must_clear = 0;
1377 }
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001378 return nonseekable_open(inode, file);
Willy Tarreau7005b582008-11-13 17:18:59 -08001379}
1380
Willy Tarreau698b1512008-11-22 11:29:33 +01001381static int lcd_release(struct inode *inode, struct file *file)
1382{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001383 atomic_inc(&lcd_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001384 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001385}
1386
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001387static const struct file_operations lcd_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001388 .write = lcd_write,
1389 .open = lcd_open,
1390 .release = lcd_release,
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001391 .llseek = no_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001392};
1393
1394static struct miscdevice lcd_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001395 .minor = LCD_MINOR,
1396 .name = "lcd",
1397 .fops = &lcd_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001398};
1399
Willy Tarreau7005b582008-11-13 17:18:59 -08001400/* public function usable from the kernel for any purpose */
Peter Huewe36d20412013-02-15 13:47:05 +01001401static void panel_lcd_print(const char *s)
Willy Tarreau698b1512008-11-22 11:29:33 +01001402{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001403 const char *tmp = s;
1404 int count = strlen(s);
1405
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001406 if (lcd.enabled && lcd_initialized) {
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001407 for (; count-- > 0; tmp++) {
1408 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1409 /* let's be a little nice with other processes
1410 that need some CPU */
1411 schedule();
1412
1413 lcd_write_char(*tmp);
1414 }
1415 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001416}
1417
Willy Tarreau7005b582008-11-13 17:18:59 -08001418/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +01001419static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001420{
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001421 switch (selected_lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001422 case LCD_TYPE_OLD:
1423 /* parallel mode, 8 bits */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001424 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001425 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001426 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001427 lcd_charset = LCD_CHARSET_NORMAL;
1428 if (lcd_e_pin == PIN_NOT_SET)
1429 lcd_e_pin = PIN_STROBE;
1430 if (lcd_rs_pin == PIN_NOT_SET)
1431 lcd_rs_pin = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -08001432
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001433 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001434 lcd_width = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001435 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001436 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001437 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001438 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001439 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001440 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001441 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001442 case LCD_TYPE_KS0074:
1443 /* serial mode, ks0074 */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001444 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001445 lcd_proto = LCD_PROTO_SERIAL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001446 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001447 lcd_charset = LCD_CHARSET_KS0074;
1448 if (lcd_bl_pin == PIN_NOT_SET)
1449 lcd_bl_pin = PIN_AUTOLF;
1450 if (lcd_cl_pin == PIN_NOT_SET)
1451 lcd_cl_pin = PIN_STROBE;
1452 if (lcd_da_pin == PIN_NOT_SET)
1453 lcd_da_pin = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001454
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001455 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001456 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001457 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001458 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001459 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001460 lcd_hwidth = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001461 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001462 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001463 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001464 case LCD_TYPE_NEXCOM:
1465 /* parallel mode, 8 bits, generic */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001466 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001467 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001468 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001469 lcd_charset = LCD_CHARSET_NORMAL;
1470 if (lcd_e_pin == PIN_NOT_SET)
1471 lcd_e_pin = PIN_AUTOLF;
1472 if (lcd_rs_pin == PIN_NOT_SET)
1473 lcd_rs_pin = PIN_SELECP;
1474 if (lcd_rw_pin == PIN_NOT_SET)
1475 lcd_rw_pin = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001476
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001477 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001478 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001479 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001480 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001481 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001482 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001483 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001484 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001485 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001486 case LCD_TYPE_CUSTOM:
1487 /* customer-defined */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001488 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001489 lcd_proto = DEFAULT_LCD_PROTO;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001490 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001491 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001492 /* default geometry will be set later */
1493 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001494 case LCD_TYPE_HANTRONIX:
1495 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +01001496 default:
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001497 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001498 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001499 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001500 lcd_charset = LCD_CHARSET_NORMAL;
1501 if (lcd_e_pin == PIN_NOT_SET)
1502 lcd_e_pin = PIN_STROBE;
1503 if (lcd_rs_pin == PIN_NOT_SET)
1504 lcd_rs_pin = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001505
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001506 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001507 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001508 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001509 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001510 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001511 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001512 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001513 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001514 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001515 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001516
Willy Tarreau698b1512008-11-22 11:29:33 +01001517 /* this is used to catch wrong and default values */
1518 if (lcd_width <= 0)
1519 lcd_width = DEFAULT_LCD_WIDTH;
1520 if (lcd_bwidth <= 0)
1521 lcd_bwidth = DEFAULT_LCD_BWIDTH;
1522 if (lcd_hwidth <= 0)
1523 lcd_hwidth = DEFAULT_LCD_HWIDTH;
1524 if (lcd_height <= 0)
1525 lcd_height = DEFAULT_LCD_HEIGHT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001526
Willy Tarreau698b1512008-11-22 11:29:33 +01001527 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */
1528 lcd_write_cmd = lcd_write_cmd_s;
1529 lcd_write_data = lcd_write_data_s;
1530 lcd_clear_fast = lcd_clear_fast_s;
Willy Tarreau7005b582008-11-13 17:18:59 -08001531
Willy Tarreau698b1512008-11-22 11:29:33 +01001532 if (lcd_cl_pin == PIN_NOT_SET)
1533 lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1534 if (lcd_da_pin == PIN_NOT_SET)
1535 lcd_da_pin = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001536
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001537 } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Willy Tarreau698b1512008-11-22 11:29:33 +01001538 lcd_write_cmd = lcd_write_cmd_p8;
1539 lcd_write_data = lcd_write_data_p8;
1540 lcd_clear_fast = lcd_clear_fast_p8;
Willy Tarreau7005b582008-11-13 17:18:59 -08001541
Willy Tarreau698b1512008-11-22 11:29:33 +01001542 if (lcd_e_pin == PIN_NOT_SET)
1543 lcd_e_pin = DEFAULT_LCD_PIN_E;
1544 if (lcd_rs_pin == PIN_NOT_SET)
1545 lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1546 if (lcd_rw_pin == PIN_NOT_SET)
1547 lcd_rw_pin = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001548 } else {
1549 lcd_write_cmd = lcd_write_cmd_tilcd;
1550 lcd_write_data = lcd_write_data_tilcd;
1551 lcd_clear_fast = lcd_clear_fast_tilcd;
Willy Tarreau698b1512008-11-22 11:29:33 +01001552 }
1553
1554 if (lcd_bl_pin == PIN_NOT_SET)
1555 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1556
1557 if (lcd_e_pin == PIN_NOT_SET)
1558 lcd_e_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001559 if (lcd_rs_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001560 lcd_rs_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001561 if (lcd_rw_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001562 lcd_rw_pin = PIN_NONE;
1563 if (lcd_bl_pin == PIN_NOT_SET)
1564 lcd_bl_pin = PIN_NONE;
1565 if (lcd_cl_pin == PIN_NOT_SET)
1566 lcd_cl_pin = PIN_NONE;
1567 if (lcd_da_pin == PIN_NOT_SET)
1568 lcd_da_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001569
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001570 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001571 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001572
Willy Tarreau698b1512008-11-22 11:29:33 +01001573 if (lcd_charset == LCD_CHARSET_KS0074)
1574 lcd_char_conv = lcd_char_conv_ks0074;
1575 else
1576 lcd_char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001577
Willy Tarreau698b1512008-11-22 11:29:33 +01001578 if (lcd_bl_pin != PIN_NONE)
1579 init_scan_timer();
Willy Tarreau7005b582008-11-13 17:18:59 -08001580
Willy Tarreau698b1512008-11-22 11:29:33 +01001581 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1582 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1583 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1584 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1585 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1586 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1587 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1588 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1589 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1590 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1591 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1592 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001593
Willy Tarreau698b1512008-11-22 11:29:33 +01001594 /* before this line, we must NOT send anything to the display.
1595 * Since lcd_init_display() needs to write data, we have to
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001596 * enable mark the LCD initialized just before. */
Willy Tarreau698b1512008-11-22 11:29:33 +01001597 lcd_initialized = 1;
1598 lcd_init_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001599
Willy Tarreau698b1512008-11-22 11:29:33 +01001600 /* display a short message */
Willy Tarreau7005b582008-11-13 17:18:59 -08001601#ifdef CONFIG_PANEL_CHANGE_MESSAGE
1602#ifdef CONFIG_PANEL_BOOT_MESSAGE
Willy Tarreau698b1512008-11-22 11:29:33 +01001603 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
Willy Tarreau7005b582008-11-13 17:18:59 -08001604#endif
1605#else
Willy Tarreau698b1512008-11-22 11:29:33 +01001606 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1607 PANEL_VERSION);
Willy Tarreau7005b582008-11-13 17:18:59 -08001608#endif
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001609 lcd_addr_x = 0;
1610 lcd_addr_y = 0;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001611 /* clear the display on the next device opening */
1612 lcd_must_clear = 1;
Willy Tarreau698b1512008-11-22 11:29:33 +01001613 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -08001614}
1615
Willy Tarreau7005b582008-11-13 17:18:59 -08001616/*
1617 * These are the file operation function for user access to /dev/keypad
1618 */
1619
Willy Tarreau698b1512008-11-22 11:29:33 +01001620static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001621 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001622{
Willy Tarreau698b1512008-11-22 11:29:33 +01001623 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001624 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001625
Willy Tarreau698b1512008-11-22 11:29:33 +01001626 if (keypad_buflen == 0) {
1627 if (file->f_flags & O_NONBLOCK)
1628 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001629
Arnd Bergmann310df692014-01-02 13:07:35 +01001630 if (wait_event_interruptible(keypad_read_wait,
1631 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001632 return -EINTR;
1633 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001634
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001635 for (; count-- > 0 && (keypad_buflen > 0);
1636 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001637 put_user(keypad_buffer[keypad_start], tmp);
1638 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1639 }
1640 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001641
Willy Tarreau698b1512008-11-22 11:29:33 +01001642 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001643}
1644
Willy Tarreau698b1512008-11-22 11:29:33 +01001645static int keypad_open(struct inode *inode, struct file *file)
1646{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001647 if (!atomic_dec_and_test(&keypad_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001648 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001649
Willy Tarreau698b1512008-11-22 11:29:33 +01001650 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1651 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001652
Willy Tarreau698b1512008-11-22 11:29:33 +01001653 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001654 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001655}
1656
Willy Tarreau698b1512008-11-22 11:29:33 +01001657static int keypad_release(struct inode *inode, struct file *file)
1658{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001659 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001660 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001661}
1662
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001663static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001664 .read = keypad_read, /* read */
1665 .open = keypad_open, /* open */
1666 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001667 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001668};
1669
1670static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001671 .minor = KEYPAD_MINOR,
1672 .name = "keypad",
1673 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001674};
1675
Peter Huewe36d20412013-02-15 13:47:05 +01001676static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001677{
1678 if (init_in_progress)
1679 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001680
Willy Tarreau698b1512008-11-22 11:29:33 +01001681 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001682 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001683 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1684 keypad_buffer[(keypad_start + keypad_buflen++) %
1685 KEYPAD_BUFFER] = *string++;
1686 }
1687 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001688 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001689}
1690
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001691/* this function scans all the bits involving at least one logical signal,
1692 * and puts the results in the bitfield "phys_read" (one bit per established
1693 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001694 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001695 * Note: to debounce input signals, we will only consider as switched a signal
1696 * which is stable across 2 measures. Signals which are different between two
1697 * reads will be kept as they previously were in their logical form (phys_prev).
1698 * A signal which has just switched will have a 1 in
1699 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001700 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001701static void phys_scan_contacts(void)
1702{
1703 int bit, bitval;
1704 char oldval;
1705 char bitmask;
1706 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001707
Willy Tarreau698b1512008-11-22 11:29:33 +01001708 phys_prev = phys_curr;
1709 phys_read_prev = phys_read;
1710 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001711
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001712 /* keep track of old value, with all outputs disabled */
1713 oldval = r_dtr(pprt) | scan_mask_o;
1714 /* activate all keyboard outputs (active low) */
1715 w_dtr(pprt, oldval & ~scan_mask_o);
1716
1717 /* will have a 1 for each bit set to gnd */
1718 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1719 /* disable all matrix signals */
1720 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001721
Willy Tarreau698b1512008-11-22 11:29:33 +01001722 /* now that all outputs are cleared, the only active input bits are
1723 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001724 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001725
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001726 /* 1 for each grounded input */
1727 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1728
1729 /* grounded inputs are signals 40-44 */
1730 phys_read |= (pmask_t) gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001731
Willy Tarreau698b1512008-11-22 11:29:33 +01001732 if (bitmask != gndmask) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001733 /* since clearing the outputs changed some inputs, we know
1734 * that some input signals are currently tied to some outputs.
1735 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001736 */
1737 for (bit = 0; bit < 8; bit++) {
1738 bitval = 1 << bit;
1739
1740 if (!(scan_mask_o & bitval)) /* skip unused bits */
1741 continue;
1742
1743 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1744 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1745 phys_read |= (pmask_t) bitmask << (5 * bit);
1746 }
1747 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001748 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001749 /* this is easy: use old bits when they are flapping,
1750 * use new ones when stable */
1751 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1752 (phys_read & ~(phys_read ^ phys_read_prev));
1753}
1754
1755static inline int input_state_high(struct logical_input *input)
1756{
1757#if 0
1758 /* FIXME:
1759 * this is an invalid test. It tries to catch
1760 * transitions from single-key to multiple-key, but
1761 * doesn't take into account the contacts polarity.
1762 * The only solution to the problem is to parse keys
1763 * from the most complex to the simplest combinations,
1764 * and mark them as 'caught' once a combination
1765 * matches, then unmatch it for all other ones.
1766 */
1767
1768 /* try to catch dangerous transitions cases :
1769 * someone adds a bit, so this signal was a false
1770 * positive resulting from a transition. We should
1771 * invalidate the signal immediately and not call the
1772 * release function.
1773 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1774 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001775 if (((phys_prev & input->mask) == input->value) &&
1776 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001777 input->state = INPUT_ST_LOW; /* invalidate */
1778 return 1;
1779 }
1780#endif
1781
1782 if ((phys_curr & input->mask) == input->value) {
1783 if ((input->type == INPUT_TYPE_STD) &&
1784 (input->high_timer == 0)) {
1785 input->high_timer++;
1786 if (input->u.std.press_fct != NULL)
1787 input->u.std.press_fct(input->u.std.press_data);
1788 } else if (input->type == INPUT_TYPE_KBD) {
1789 /* will turn on the light */
1790 keypressed = 1;
1791
1792 if (input->high_timer == 0) {
1793 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001794
Jake Champline6626de2013-05-04 11:21:17 -04001795 if (press_str[0]) {
1796 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001797
Jake Champline6626de2013-05-04 11:21:17 -04001798 keypad_send_key(press_str, s);
1799 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001800 }
1801
1802 if (input->u.kbd.repeat_str[0]) {
1803 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001804
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001805 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001806 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001807
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001808 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001809 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001810 }
1811 /* we will need to come back here soon */
1812 inputs_stable = 0;
1813 }
1814
1815 if (input->high_timer < 255)
1816 input->high_timer++;
1817 }
1818 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001819 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001820
1821 /* else signal falling down. Let's fall through. */
1822 input->state = INPUT_ST_FALLING;
1823 input->fall_timer = 0;
1824
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001825 return 0;
1826}
1827
1828static inline void input_state_falling(struct logical_input *input)
1829{
1830#if 0
1831 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001832 if (((phys_prev & input->mask) == input->value) &&
1833 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001834 input->state = INPUT_ST_LOW; /* invalidate */
1835 return;
1836 }
1837#endif
1838
1839 if ((phys_curr & input->mask) == input->value) {
1840 if (input->type == INPUT_TYPE_KBD) {
1841 /* will turn on the light */
1842 keypressed = 1;
1843
1844 if (input->u.kbd.repeat_str[0]) {
1845 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001846
Jake Champline6626de2013-05-04 11:21:17 -04001847 if (input->high_timer >= KEYPAD_REP_START) {
1848 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001849
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001850 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001851 keypad_send_key(repeat_str, s);
1852 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001853 /* we will need to come back here soon */
1854 inputs_stable = 0;
1855 }
1856
1857 if (input->high_timer < 255)
1858 input->high_timer++;
1859 }
1860 input->state = INPUT_ST_HIGH;
1861 } else if (input->fall_timer >= input->fall_time) {
1862 /* call release event */
1863 if (input->type == INPUT_TYPE_STD) {
1864 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001865
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001866 if (release_fct != NULL)
1867 release_fct(input->u.std.release_data);
1868 } else if (input->type == INPUT_TYPE_KBD) {
1869 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001870
Jake Champline6626de2013-05-04 11:21:17 -04001871 if (release_str[0]) {
1872 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001873
Jake Champline6626de2013-05-04 11:21:17 -04001874 keypad_send_key(release_str, s);
1875 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001876 }
1877
1878 input->state = INPUT_ST_LOW;
1879 } else {
1880 input->fall_timer++;
1881 inputs_stable = 0;
1882 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001883}
1884
Willy Tarreau698b1512008-11-22 11:29:33 +01001885static void panel_process_inputs(void)
1886{
1887 struct list_head *item;
1888 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001889
Willy Tarreau698b1512008-11-22 11:29:33 +01001890 keypressed = 0;
1891 inputs_stable = 1;
1892 list_for_each(item, &logical_inputs) {
1893 input = list_entry(item, struct logical_input, list);
Willy Tarreau7005b582008-11-13 17:18:59 -08001894
Willy Tarreau698b1512008-11-22 11:29:33 +01001895 switch (input->state) {
1896 case INPUT_ST_LOW:
1897 if ((phys_curr & input->mask) != input->value)
1898 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001899 /* if all needed ones were already set previously,
1900 * this means that this logical signal has been
1901 * activated by the releasing of another combined
1902 * signal, so we don't want to match.
1903 * eg: AB -(release B)-> A -(release A)-> 0 :
1904 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001905 */
1906 if ((phys_prev & input->mask) == input->value)
1907 break;
1908 input->rise_timer = 0;
1909 input->state = INPUT_ST_RISING;
1910 /* no break here, fall through */
1911 case INPUT_ST_RISING:
1912 if ((phys_curr & input->mask) != input->value) {
1913 input->state = INPUT_ST_LOW;
1914 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001915 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001916 if (input->rise_timer < input->rise_time) {
1917 inputs_stable = 0;
1918 input->rise_timer++;
1919 break;
1920 }
1921 input->high_timer = 0;
1922 input->state = INPUT_ST_HIGH;
1923 /* no break here, fall through */
1924 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001925 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001926 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001927 /* no break here, fall through */
1928 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001929 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001930 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001931 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001932}
1933
Willy Tarreau698b1512008-11-22 11:29:33 +01001934static void panel_scan_timer(void)
1935{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001936 if (keypad.enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001937 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001938 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001939
1940 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001941 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001942 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001943
Willy Tarreau698b1512008-11-22 11:29:33 +01001944 if (!inputs_stable || phys_curr != phys_prev)
1945 panel_process_inputs();
1946 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001947
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001948 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001949 if (keypressed) {
1950 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1951 lcd_backlight(1);
1952 light_tempo = FLASH_LIGHT_TEMPO;
1953 } else if (light_tempo > 0) {
1954 light_tempo--;
1955 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1956 lcd_backlight(0);
1957 }
1958 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001959
Willy Tarreau698b1512008-11-22 11:29:33 +01001960 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001961}
1962
Willy Tarreau698b1512008-11-22 11:29:33 +01001963static void init_scan_timer(void)
1964{
1965 if (scan_timer.function != NULL)
1966 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001967
Willy Tarreau698b1512008-11-22 11:29:33 +01001968 init_timer(&scan_timer);
1969 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1970 scan_timer.data = 0;
1971 scan_timer.function = (void *)&panel_scan_timer;
1972 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001973}
1974
1975/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001976 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1977 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001978 * returns 1 if ok, 0 if error (in which case, nothing is written).
1979 */
Peter Huewe36d20412013-02-15 13:47:05 +01001980static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
Willy Tarreau698b1512008-11-22 11:29:33 +01001981 char *imask, char *omask)
1982{
1983 static char sigtab[10] = "EeSsPpAaBb";
1984 char im, om;
1985 pmask_t m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001986
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001987 om = 0ULL;
1988 im = 0ULL;
1989 m = 0ULL;
1990 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001991 while (*name) {
1992 int in, out, bit, neg;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001993
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001994 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
1995 in++)
Willy Tarreau698b1512008-11-22 11:29:33 +01001996 ;
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001997
Willy Tarreau698b1512008-11-22 11:29:33 +01001998 if (in >= sizeof(sigtab))
1999 return 0; /* input name not found */
2000 neg = (in & 1); /* odd (lower) names are negated */
2001 in >>= 1;
2002 im |= (1 << in);
Willy Tarreau7005b582008-11-13 17:18:59 -08002003
Willy Tarreau698b1512008-11-22 11:29:33 +01002004 name++;
2005 if (isdigit(*name)) {
2006 out = *name - '0';
2007 om |= (1 << out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002008 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01002009 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002010 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01002011 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002012 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002013
2014 bit = (out * 5) + in;
2015
2016 m |= 1ULL << bit;
2017 if (!neg)
2018 v |= 1ULL << bit;
2019 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08002020 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002021 *mask = m;
2022 *value = v;
2023 if (imask)
2024 *imask |= im;
2025 if (omask)
2026 *omask |= om;
2027 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002028}
2029
2030/* tries to bind a key to the signal name <name>. The key will send the
2031 * strings <press>, <repeat>, <release> for these respective events.
2032 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2033 */
Peter Huewe36d20412013-02-15 13:47:05 +01002034static struct logical_input *panel_bind_key(const char *name, const char *press,
2035 const char *repeat,
2036 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01002037{
2038 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002039
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002040 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002041 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01002042 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002043
Willy Tarreau698b1512008-11-22 11:29:33 +01002044 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002045 &scan_mask_o)) {
2046 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01002047 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002048 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002049
2050 key->type = INPUT_TYPE_KBD;
2051 key->state = INPUT_ST_LOW;
2052 key->rise_time = 1;
2053 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002054
Willy Tarreau698b1512008-11-22 11:29:33 +01002055 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
2056 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
2057 strncpy(key->u.kbd.release_str, release,
2058 sizeof(key->u.kbd.release_str));
2059 list_add(&key->list, &logical_inputs);
2060 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002061}
2062
Willy Tarreau630231772008-11-22 12:52:18 +01002063#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08002064/* tries to bind a callback function to the signal name <name>. The function
2065 * <press_fct> will be called with the <press_data> arg when the signal is
2066 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002067 * Returns the pointer to the new signal if ok, NULL if the signal could not
2068 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08002069 */
2070static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302071 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002072 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302073 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002074 int release_data)
2075{
2076 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002077
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002078 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002079 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01002080 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002081
Willy Tarreau698b1512008-11-22 11:29:33 +01002082 memset(callback, 0, sizeof(struct logical_input));
2083 if (!input_name2mask(name, &callback->mask, &callback->value,
2084 &scan_mask_i, &scan_mask_o))
2085 return NULL;
2086
2087 callback->type = INPUT_TYPE_STD;
2088 callback->state = INPUT_ST_LOW;
2089 callback->rise_time = 1;
2090 callback->fall_time = 1;
2091 callback->u.std.press_fct = press_fct;
2092 callback->u.std.press_data = press_data;
2093 callback->u.std.release_fct = release_fct;
2094 callback->u.std.release_data = release_data;
2095 list_add(&callback->list, &logical_inputs);
2096 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002097}
Willy Tarreau630231772008-11-22 12:52:18 +01002098#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08002099
Willy Tarreau698b1512008-11-22 11:29:33 +01002100static void keypad_init(void)
2101{
2102 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02002103
Willy Tarreau698b1512008-11-22 11:29:33 +01002104 init_waitqueue_head(&keypad_read_wait);
2105 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08002106
Willy Tarreau698b1512008-11-22 11:29:33 +01002107 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08002108
Willy Tarreau698b1512008-11-22 11:29:33 +01002109 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
2110 panel_bind_key(keypad_profile[keynum][0],
2111 keypad_profile[keynum][1],
2112 keypad_profile[keynum][2],
2113 keypad_profile[keynum][3]);
2114 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002115
Willy Tarreau698b1512008-11-22 11:29:33 +01002116 init_scan_timer();
2117 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002118}
2119
Willy Tarreau7005b582008-11-13 17:18:59 -08002120/**************************************************/
2121/* device initialization */
2122/**************************************************/
2123
Willy Tarreau698b1512008-11-22 11:29:33 +01002124static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2125 void *unused)
2126{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002127 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002128 switch (code) {
2129 case SYS_DOWN:
2130 panel_lcd_print
2131 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2132 break;
2133 case SYS_HALT:
2134 panel_lcd_print
2135 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2136 break;
2137 case SYS_POWER_OFF:
2138 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2139 break;
2140 default:
2141 break;
2142 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002143 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002144 return NOTIFY_DONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08002145}
2146
2147static struct notifier_block panel_notifier = {
2148 panel_notify_sys,
2149 NULL,
2150 0
2151};
2152
Willy Tarreau698b1512008-11-22 11:29:33 +01002153static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002154{
Willy Tarreau698b1512008-11-22 11:29:33 +01002155 if (port->number != parport)
2156 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002157
Willy Tarreau698b1512008-11-22 11:29:33 +01002158 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002159 pr_err("%s: port->number=%d parport=%d, already registered!\n",
2160 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002161 return;
2162 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002163
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002164 pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */
Willy Tarreau698b1512008-11-22 11:29:33 +01002165 NULL,
2166 /*PARPORT_DEV_EXCL */
2167 0, (void *)&pprt);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002168 if (pprt == NULL) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002169 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
2170 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002171 return;
2172 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002173
Willy Tarreau698b1512008-11-22 11:29:33 +01002174 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002175 pr_err("could not claim access to parport%d. Aborting.\n",
2176 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002177 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002178 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002179
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002180 /* must init LCD first, just in case an IRQ from the keypad is
2181 * generated at keypad init
2182 */
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002183 if (lcd.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002184 lcd_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002185 if (misc_register(&lcd_dev))
2186 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002187 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002188
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002189 if (keypad.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002190 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002191 if (misc_register(&keypad_dev))
2192 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01002193 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002194 return;
2195
2196err_lcd_unreg:
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002197 if (lcd.enabled)
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002198 misc_deregister(&lcd_dev);
2199err_unreg_device:
2200 parport_unregister_device(pprt);
2201 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002202}
2203
Willy Tarreau698b1512008-11-22 11:29:33 +01002204static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002205{
Willy Tarreau698b1512008-11-22 11:29:33 +01002206 if (port->number != parport)
2207 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002208
Willy Tarreau698b1512008-11-22 11:29:33 +01002209 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002210 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
2211 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002212 return;
2213 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002214
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002215 if (keypad.enabled && keypad_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002216 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002217 keypad_initialized = 0;
2218 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002219
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002220 if (lcd.enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002221 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002222 lcd_initialized = 0;
2223 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002224
Willy Tarreau698b1512008-11-22 11:29:33 +01002225 parport_release(pprt);
2226 parport_unregister_device(pprt);
2227 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002228}
2229
2230static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01002231 .name = "panel",
2232 .attach = panel_attach,
2233 .detach = panel_detach,
Willy Tarreau7005b582008-11-13 17:18:59 -08002234};
2235
2236/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01002237static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002238{
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002239 int selected_keypad_type = NOT_SET;
Willy Tarreau7005b582008-11-13 17:18:59 -08002240
Willy Tarreau698b1512008-11-22 11:29:33 +01002241 /* take care of an eventual profile */
2242 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002243 case PANEL_PROFILE_CUSTOM:
2244 /* custom profile */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002245 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
2246 selected_lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01002247 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002248 case PANEL_PROFILE_OLD:
2249 /* 8 bits, 2*16, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002250 selected_keypad_type = KEYPAD_TYPE_OLD;
2251 selected_lcd_type = LCD_TYPE_OLD;
2252
2253 /* TODO: This two are a little hacky, sort it out later */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002254 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002255 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002256 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002257 lcd_hwidth = 16;
2258 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002259 case PANEL_PROFILE_NEW:
2260 /* serial, 2*16, new keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002261 selected_keypad_type = KEYPAD_TYPE_NEW;
2262 selected_lcd_type = LCD_TYPE_KS0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01002263 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002264 case PANEL_PROFILE_HANTRONIX:
2265 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002266 selected_keypad_type = KEYPAD_TYPE_NONE;
2267 selected_lcd_type = LCD_TYPE_HANTRONIX;
Willy Tarreau698b1512008-11-22 11:29:33 +01002268 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002269 case PANEL_PROFILE_NEXCOM:
2270 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002271 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
2272 selected_lcd_type = LCD_TYPE_NEXCOM;
Willy Tarreau698b1512008-11-22 11:29:33 +01002273 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002274 case PANEL_PROFILE_LARGE:
2275 /* 8 bits, 2*40, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002276 selected_keypad_type = KEYPAD_TYPE_OLD;
2277 selected_lcd_type = LCD_TYPE_OLD;
Willy Tarreau698b1512008-11-22 11:29:33 +01002278 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08002279 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002280
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002281 /*
2282 * Overwrite selection with module param values (both keypad and lcd),
2283 * where the deprecated params have lower prio.
2284 */
2285 if (keypad_enabled > -1)
2286 selected_keypad_type = keypad_enabled;
2287 if (keypad_type > -1)
2288 selected_keypad_type = keypad_type;
Willy Tarreau7005b582008-11-13 17:18:59 -08002289
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01002290 keypad.enabled = (selected_keypad_type > 0);
2291
2292 if (lcd_enabled > -1)
2293 selected_lcd_type = lcd_enabled;
2294 if (lcd_type > -1)
2295 selected_lcd_type = lcd_type;
2296
2297 lcd.enabled = (selected_lcd_type > 0);
2298
2299 switch (selected_keypad_type) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002300 case KEYPAD_TYPE_OLD:
2301 keypad_profile = old_keypad_profile;
2302 break;
2303 case KEYPAD_TYPE_NEW:
2304 keypad_profile = new_keypad_profile;
2305 break;
2306 case KEYPAD_TYPE_NEXCOM:
2307 keypad_profile = nexcom_keypad_profile;
2308 break;
2309 default:
2310 keypad_profile = NULL;
2311 break;
2312 }
2313
2314 /* tells various subsystems about the fact that we are initializing */
2315 init_in_progress = 1;
2316
2317 if (parport_register_driver(&panel_driver)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002318 pr_err("could not register with parport. Aborting.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002319 return -EIO;
2320 }
2321
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002322 if (!lcd.enabled && !keypad.enabled) {
Willy Tarreau630231772008-11-22 12:52:18 +01002323 /* no device enabled, let's release the parport */
Willy Tarreau698b1512008-11-22 11:29:33 +01002324 if (pprt) {
2325 parport_release(pprt);
2326 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002327 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002328 }
2329 parport_unregister_driver(&panel_driver);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002330 pr_err("driver version " PANEL_VERSION " disabled.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002331 return -ENODEV;
2332 }
2333
2334 register_reboot_notifier(&panel_notifier);
2335
2336 if (pprt)
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002337 pr_info("driver version " PANEL_VERSION
2338 " registered on parport%d (io=0x%lx).\n", parport,
2339 pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01002340 else
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002341 pr_info("driver version " PANEL_VERSION
2342 " not yet registered\n");
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002343 /* tells various subsystems about the fact that initialization
2344 is finished */
Willy Tarreau698b1512008-11-22 11:29:33 +01002345 init_in_progress = 0;
2346 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08002347}
2348
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01002349static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002350{
2351 unregister_reboot_notifier(&panel_notifier);
Willy Tarreau7005b582008-11-13 17:18:59 -08002352
Willy Tarreau698b1512008-11-22 11:29:33 +01002353 if (scan_timer.function != NULL)
Julia Lawalle112f892014-03-26 22:33:41 +01002354 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08002355
Costantino Leandro57898132009-02-17 11:10:48 -05002356 if (pprt != NULL) {
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002357 if (keypad.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002358 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002359 keypad_initialized = 0;
2360 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002361
Mariusz Gorskia8b25802014-11-27 22:36:49 +01002362 if (lcd.enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002363 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2364 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2365 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002366 lcd_initialized = 0;
Costantino Leandro57898132009-02-17 11:10:48 -05002367 }
2368
2369 /* TODO: free all input signals */
2370 parport_release(pprt);
2371 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002372 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002373 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002374 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08002375}
Willy Tarreau7005b582008-11-13 17:18:59 -08002376
Willy Tarreau7005b582008-11-13 17:18:59 -08002377module_init(panel_init_module);
2378module_exit(panel_cleanup_module);
2379MODULE_AUTHOR("Willy Tarreau");
2380MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08002381
2382/*
2383 * Local variables:
2384 * c-indent-level: 4
2385 * tab-width: 8
2386 * End:
2387 */