blob: 52889905c924584ff3cd611d09fa102f22ad37ef [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 */
215static char keypad_buffer[KEYPAD_BUFFER];
Willy Tarreau698b1512008-11-22 11:29:33 +0100216static int keypad_buflen;
217static int keypad_start;
218static char keypressed;
Willy Tarreau7005b582008-11-13 17:18:59 -0800219static wait_queue_head_t keypad_read_wait;
Willy Tarreau7005b582008-11-13 17:18:59 -0800220
221/* lcd-specific variables */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300222
223/* contains the LCD config state */
224static unsigned long int lcd_flags;
225/* contains the LCD X offset */
226static unsigned long int lcd_addr_x;
227/* contains the LCD Y offset */
228static unsigned long int lcd_addr_y;
229/* current escape sequence, 0 terminated */
230static char lcd_escape[LCD_ESCAPE_LEN + 1];
231/* not in escape state. >=0 = escape cmd len */
232static int lcd_escape_len = -1;
Willy Tarreau7005b582008-11-13 17:18:59 -0800233
Willy Tarreau7005b582008-11-13 17:18:59 -0800234/*
235 * Bit masks to convert LCD signals to parallel port outputs.
236 * _d_ are values for data port, _c_ are for control port.
237 * [0] = signal OFF, [1] = signal ON, [2] = mask
238 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100239#define BIT_CLR 0
240#define BIT_SET 1
241#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800242#define BIT_STATES 3
243/*
244 * one entry for each bit on the LCD
245 */
246#define LCD_BIT_E 0
247#define LCD_BIT_RS 1
248#define LCD_BIT_RW 2
249#define LCD_BIT_BL 3
250#define LCD_BIT_CL 4
251#define LCD_BIT_DA 5
252#define LCD_BITS 6
253
254/*
255 * each bit can be either connected to a DATA or CTRL port
256 */
257#define LCD_PORT_C 0
258#define LCD_PORT_D 1
259#define LCD_PORTS 2
260
261static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
262
263/*
264 * LCD protocols
265 */
266#define LCD_PROTO_PARALLEL 0
267#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400268#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800269
270/*
271 * LCD character sets
272 */
273#define LCD_CHARSET_NORMAL 0
274#define LCD_CHARSET_KS0074 1
275
276/*
277 * LCD types
278 */
279#define LCD_TYPE_NONE 0
280#define LCD_TYPE_OLD 1
281#define LCD_TYPE_KS0074 2
282#define LCD_TYPE_HANTRONIX 3
283#define LCD_TYPE_NEXCOM 4
284#define LCD_TYPE_CUSTOM 5
285
286/*
287 * keypad types
288 */
289#define KEYPAD_TYPE_NONE 0
290#define KEYPAD_TYPE_OLD 1
291#define KEYPAD_TYPE_NEW 2
292#define KEYPAD_TYPE_NEXCOM 3
293
294/*
295 * panel profiles
296 */
297#define PANEL_PROFILE_CUSTOM 0
298#define PANEL_PROFILE_OLD 1
299#define PANEL_PROFILE_NEW 2
300#define PANEL_PROFILE_HANTRONIX 3
301#define PANEL_PROFILE_NEXCOM 4
302#define PANEL_PROFILE_LARGE 5
303
304/*
305 * Construct custom config from the kernel's configuration
306 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800307#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100308#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100309#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
310#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100311#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800312#define DEFAULT_LCD_WIDTH 40
313#define DEFAULT_LCD_BWIDTH 40
314#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100315#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800316#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
317
318#define DEFAULT_LCD_PIN_E PIN_AUTOLF
319#define DEFAULT_LCD_PIN_RS PIN_SELECP
320#define DEFAULT_LCD_PIN_RW PIN_INITP
321#define DEFAULT_LCD_PIN_SCL PIN_STROBE
322#define DEFAULT_LCD_PIN_SDA PIN_D0
323#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800324
Willy Tarreau7005b582008-11-13 17:18:59 -0800325#ifdef CONFIG_PANEL_PARPORT
326#undef DEFAULT_PARPORT
327#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
328#endif
329
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100330#ifdef CONFIG_PANEL_PROFILE
331#undef DEFAULT_PROFILE
332#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
333#endif
334
Willy Tarreau698b1512008-11-22 11:29:33 +0100335#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800336#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100337#undef DEFAULT_KEYPAD_TYPE
338#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800339#endif
340
Willy Tarreau7005b582008-11-13 17:18:59 -0800341#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100342#undef DEFAULT_LCD_TYPE
343#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800344#endif
345
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100346#ifdef CONFIG_PANEL_LCD_HEIGHT
347#undef DEFAULT_LCD_HEIGHT
348#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
349#endif
350
Willy Tarreau7005b582008-11-13 17:18:59 -0800351#ifdef CONFIG_PANEL_LCD_WIDTH
352#undef DEFAULT_LCD_WIDTH
353#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
354#endif
355
356#ifdef CONFIG_PANEL_LCD_BWIDTH
357#undef DEFAULT_LCD_BWIDTH
358#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
359#endif
360
361#ifdef CONFIG_PANEL_LCD_HWIDTH
362#undef DEFAULT_LCD_HWIDTH
363#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
364#endif
365
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100366#ifdef CONFIG_PANEL_LCD_CHARSET
367#undef DEFAULT_LCD_CHARSET
368#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800369#endif
370
371#ifdef CONFIG_PANEL_LCD_PROTO
372#undef DEFAULT_LCD_PROTO
373#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
374#endif
375
376#ifdef CONFIG_PANEL_LCD_PIN_E
377#undef DEFAULT_LCD_PIN_E
378#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
379#endif
380
381#ifdef CONFIG_PANEL_LCD_PIN_RS
382#undef DEFAULT_LCD_PIN_RS
383#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
384#endif
385
386#ifdef CONFIG_PANEL_LCD_PIN_RW
387#undef DEFAULT_LCD_PIN_RW
388#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
389#endif
390
391#ifdef CONFIG_PANEL_LCD_PIN_SCL
392#undef DEFAULT_LCD_PIN_SCL
393#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
394#endif
395
396#ifdef CONFIG_PANEL_LCD_PIN_SDA
397#undef DEFAULT_LCD_PIN_SDA
398#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
399#endif
400
401#ifdef CONFIG_PANEL_LCD_PIN_BL
402#undef DEFAULT_LCD_PIN_BL
403#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
404#endif
405
Willy Tarreau7005b582008-11-13 17:18:59 -0800406#endif /* DEFAULT_PROFILE == 0 */
407
408/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100409
410/* Device single-open policy control */
411static atomic_t lcd_available = ATOMIC_INIT(1);
412static atomic_t keypad_available = ATOMIC_INIT(1);
413
Willy Tarreau698b1512008-11-22 11:29:33 +0100414static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800415
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100416static int lcd_initialized;
417static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800418
Willy Tarreau698b1512008-11-22 11:29:33 +0100419static int light_tempo;
Willy Tarreau7005b582008-11-13 17:18:59 -0800420
Willy Tarreau698b1512008-11-22 11:29:33 +0100421static char lcd_must_clear;
422static char lcd_left_shift;
423static char init_in_progress;
Willy Tarreau7005b582008-11-13 17:18:59 -0800424
Monam Agarwal68d386b2014-02-25 19:40:49 +0530425static void (*lcd_write_cmd)(int);
426static void (*lcd_write_data)(int);
427static void (*lcd_clear_fast)(void);
Willy Tarreau7005b582008-11-13 17:18:59 -0800428
Willy Tarreau698b1512008-11-22 11:29:33 +0100429static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800430static struct timer_list scan_timer;
431
Willy Tarreau630231772008-11-22 12:52:18 +0100432MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100433
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100434static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100435module_param(parport, int, 0000);
436MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100437
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100438static int profile = DEFAULT_PROFILE;
439module_param(profile, int, 0000);
440MODULE_PARM_DESC(profile,
441 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
442 "4=16x2 nexcom; default=40x2, old kp");
443
Mariusz Gorski36277d42014-11-27 22:36:47 +0100444static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100445module_param(keypad_type, int, 0000);
446MODULE_PARM_DESC(keypad_type,
447 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
448
Mariusz Gorski36277d42014-11-27 22:36:47 +0100449static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100450module_param(lcd_type, int, 0000);
451MODULE_PARM_DESC(lcd_type,
452 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
453
Mariusz Gorski36277d42014-11-27 22:36:47 +0100454static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100455module_param(lcd_height, int, 0000);
456MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100457
Mariusz Gorski36277d42014-11-27 22:36:47 +0100458static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100459module_param(lcd_width, int, 0000);
460MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100461
Mariusz Gorski36277d42014-11-27 22:36:47 +0100462static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100463module_param(lcd_bwidth, int, 0000);
464MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100465
Mariusz Gorski36277d42014-11-27 22:36:47 +0100466static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100467module_param(lcd_hwidth, int, 0000);
468MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100469
Mariusz Gorski36277d42014-11-27 22:36:47 +0100470static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100471module_param(lcd_charset, int, 0000);
472MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100473
Mariusz Gorski36277d42014-11-27 22:36:47 +0100474static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100475module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300476MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200477 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100478
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100479/*
480 * These are the parallel port pins the LCD control signals are connected to.
481 * Set this to 0 if the signal is not used. Set it to its opposite value
482 * (negative) if the signal is negated. -MAXINT is used to indicate that the
483 * pin has not been explicitly specified.
484 *
Willy Tarreau630231772008-11-22 12:52:18 +0100485 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100486 */
487
488static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100489module_param(lcd_e_pin, int, 0000);
490MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530491 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100492
493static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100494module_param(lcd_rs_pin, int, 0000);
495MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530496 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100497
498static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100499module_param(lcd_rw_pin, int, 0000);
500MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530501 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100502
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100503static int lcd_cl_pin = PIN_NOT_SET;
504module_param(lcd_cl_pin, int, 0000);
505MODULE_PARM_DESC(lcd_cl_pin,
506 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100507
508static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100509module_param(lcd_da_pin, int, 0000);
510MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530511 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100512
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100513static int lcd_bl_pin = PIN_NOT_SET;
514module_param(lcd_bl_pin, int, 0000);
515MODULE_PARM_DESC(lcd_bl_pin,
516 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
517
518/* Deprecated module parameters - consider not using them anymore */
519
Mariusz Gorski36277d42014-11-27 22:36:47 +0100520static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100521module_param(lcd_enabled, int, 0000);
522MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
523
Mariusz Gorski36277d42014-11-27 22:36:47 +0100524static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100525module_param(keypad_enabled, int, 0000);
526MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
527
Willy Tarreau7005b582008-11-13 17:18:59 -0800528
Peter Huewe36d20412013-02-15 13:47:05 +0100529static const unsigned char *lcd_char_conv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800530
531/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100532static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100533 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
534 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
535 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
536 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
537 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
538 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
539 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
540 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
541 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
542 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
543 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
544 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
545 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
546 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
547 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
548 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
549 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
550 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
551 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
552 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
553 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
554 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
555 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
556 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
557 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
558 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
559 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
560 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
561 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
562 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
563 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
564 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
565 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800566};
567
Peter Huewe36d20412013-02-15 13:47:05 +0100568static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100569 {"S0", "Left\n", "Left\n", ""},
570 {"S1", "Down\n", "Down\n", ""},
571 {"S2", "Up\n", "Up\n", ""},
572 {"S3", "Right\n", "Right\n", ""},
573 {"S4", "Esc\n", "Esc\n", ""},
574 {"S5", "Ret\n", "Ret\n", ""},
575 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800576};
577
578/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100579static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100580 {"S0", "Left\n", "Left\n", ""},
581 {"S1", "Down\n", "Down\n", ""},
582 {"S2", "Up\n", "Up\n", ""},
583 {"S3", "Right\n", "Right\n", ""},
584 {"S4s5", "", "Esc\n", "Esc\n"},
585 {"s4S5", "", "Ret\n", "Ret\n"},
586 {"S4S5", "Help\n", "", ""},
587 /* add new signals above this line */
588 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800589};
590
591/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100592static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100593 {"a-p-e-", "Down\n", "Down\n", ""},
594 {"a-p-E-", "Ret\n", "Ret\n", ""},
595 {"a-P-E-", "Esc\n", "Esc\n", ""},
596 {"a-P-e-", "Up\n", "Up\n", ""},
597 /* add new signals above this line */
598 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800599};
600
Peter Huewe36d20412013-02-15 13:47:05 +0100601static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800602
603/* FIXME: this should be converted to a bit array containing signals states */
604static struct {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300605 unsigned char e; /* parallel LCD E (data latch on falling edge) */
606 unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */
607 unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */
608 unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */
609 unsigned char cl; /* serial LCD clock (latch on rising edge) */
610 unsigned char da; /* serial LCD data */
Willy Tarreau7005b582008-11-13 17:18:59 -0800611} bits;
612
613static void init_scan_timer(void);
614
615/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100616static int set_data_bits(void)
617{
618 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800619
Willy Tarreau698b1512008-11-22 11:29:33 +0100620 val = r_dtr(pprt);
621 for (bit = 0; bit < LCD_BITS; bit++)
622 val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800623
Willy Tarreau698b1512008-11-22 11:29:33 +0100624 val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e]
625 | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs]
626 | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw]
627 | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl]
628 | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl]
629 | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800630
Willy Tarreau698b1512008-11-22 11:29:33 +0100631 w_dtr(pprt, val);
632 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800633}
634
635/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100636static int set_ctrl_bits(void)
637{
638 int val, bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800639
Willy Tarreau698b1512008-11-22 11:29:33 +0100640 val = r_ctr(pprt);
641 for (bit = 0; bit < LCD_BITS; bit++)
642 val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK];
Willy Tarreau7005b582008-11-13 17:18:59 -0800643
Willy Tarreau698b1512008-11-22 11:29:33 +0100644 val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e]
645 | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs]
646 | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw]
647 | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl]
648 | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl]
649 | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da];
Willy Tarreau7005b582008-11-13 17:18:59 -0800650
Willy Tarreau698b1512008-11-22 11:29:33 +0100651 w_ctr(pprt, val);
652 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800653}
654
655/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530656static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100657{
658 set_data_bits();
659 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800660}
661
662/*
663 * Converts a parallel port pin (from -25 to 25) to data and control ports
664 * masks, and data and control port bits. The signal will be considered
665 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
666 *
667 * Result will be used this way :
668 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
669 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
670 */
Peter Huewe36d20412013-02-15 13:47:05 +0100671static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100672{
673 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800674
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200675 d_val[0] = 0;
676 c_val[0] = 0;
677 d_val[1] = 0;
678 c_val[1] = 0;
679 d_val[2] = 0xFF;
680 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800681
Willy Tarreau698b1512008-11-22 11:29:33 +0100682 if (pin == 0)
683 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800684
Willy Tarreau698b1512008-11-22 11:29:33 +0100685 inv = (pin < 0);
686 if (inv)
687 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800688
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200689 d_bit = 0;
690 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800691
Willy Tarreau698b1512008-11-22 11:29:33 +0100692 switch (pin) {
693 case PIN_STROBE: /* strobe, inverted */
694 c_bit = PNL_PSTROBE;
695 inv = !inv;
696 break;
697 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
698 d_bit = 1 << (pin - 2);
699 break;
700 case PIN_AUTOLF: /* autofeed, inverted */
701 c_bit = PNL_PAUTOLF;
702 inv = !inv;
703 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300704 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100705 c_bit = PNL_PINITP;
706 break;
707 case PIN_SELECP: /* select_in, inverted */
708 c_bit = PNL_PSELECP;
709 inv = !inv;
710 break;
711 default: /* unknown pin, ignore */
712 break;
713 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800714
Willy Tarreau698b1512008-11-22 11:29:33 +0100715 if (c_bit) {
716 c_val[2] &= ~c_bit;
717 c_val[!inv] = c_bit;
718 } else if (d_bit) {
719 d_val[2] &= ~d_bit;
720 d_val[!inv] = d_bit;
721 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800722}
723
724/* sleeps that many milliseconds with a reschedule */
Willy Tarreau698b1512008-11-22 11:29:33 +0100725static void long_sleep(int ms)
726{
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200727 if (in_interrupt()) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100728 mdelay(ms);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +0200729 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +0100730 current->state = TASK_INTERRUPTIBLE;
731 schedule_timeout((ms * HZ + 999) / 1000);
732 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800733}
734
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300735/* send a serial byte to the LCD panel. The caller is responsible for locking
736 if needed. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100737static void lcd_send_serial(int byte)
738{
739 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800740
Willy Tarreau698b1512008-11-22 11:29:33 +0100741 /* the data bit is set on D0, and the clock on STROBE.
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300742 * LCD reads D0 on STROBE's rising edge. */
Willy Tarreau698b1512008-11-22 11:29:33 +0100743 for (bit = 0; bit < 8; bit++) {
744 bits.cl = BIT_CLR; /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530745 panel_set_bits();
Willy Tarreau698b1512008-11-22 11:29:33 +0100746 bits.da = byte & 1;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530747 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300748 udelay(2); /* maintain the data during 2 us before CLK up */
Willy Tarreau698b1512008-11-22 11:29:33 +0100749 bits.cl = BIT_SET; /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530750 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300751 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100752 byte >>= 1;
753 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800754}
755
756/* turn the backlight on or off */
Willy Tarreau698b1512008-11-22 11:29:33 +0100757static void lcd_backlight(int on)
758{
759 if (lcd_bl_pin == PIN_NONE)
760 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800761
Justin P. Mattock6975e182012-03-19 08:17:52 -0700762 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800763 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100764 bits.bl = on;
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530765 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800766 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800767}
768
769/* send a command to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100770static void lcd_write_cmd_s(int cmd)
771{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800772 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100773 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
774 lcd_send_serial(cmd & 0x0F);
775 lcd_send_serial((cmd >> 4) & 0x0F);
776 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800777 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800778}
779
780/* send data to the LCD panel in serial mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100781static void lcd_write_data_s(int data)
782{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800783 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100784 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
785 lcd_send_serial(data & 0x0F);
786 lcd_send_serial((data >> 4) & 0x0F);
787 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800788 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800789}
790
791/* send a command to the LCD panel in 8 bits parallel mode */
Willy Tarreau698b1512008-11-22 11:29:33 +0100792static void lcd_write_cmd_p8(int cmd)
793{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800794 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800795 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100796 w_dtr(pprt, cmd);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300797 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800798
Willy Tarreau698b1512008-11-22 11:29:33 +0100799 bits.e = BIT_SET;
800 bits.rs = BIT_CLR;
801 bits.rw = BIT_CLR;
Willy Tarreau7005b582008-11-13 17:18:59 -0800802 set_ctrl_bits();
803
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300804 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800805
806 bits.e = BIT_CLR;
807 set_ctrl_bits();
808
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300809 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800810 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100811}
Willy Tarreau7005b582008-11-13 17:18:59 -0800812
Willy Tarreau698b1512008-11-22 11:29:33 +0100813/* send data to the LCD panel in 8 bits parallel mode */
814static void lcd_write_data_p8(int data)
815{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800816 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100817 /* present the data to the data port */
818 w_dtr(pprt, data);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300819 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100820
821 bits.e = BIT_SET;
822 bits.rs = BIT_SET;
823 bits.rw = BIT_CLR;
824 set_ctrl_bits();
825
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300826 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100827
828 bits.e = BIT_CLR;
829 set_ctrl_bits();
830
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300831 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800832 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100833}
834
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400835/* send a command to the TI LCD panel */
836static void lcd_write_cmd_tilcd(int cmd)
837{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800838 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400839 /* present the data to the control port */
840 w_ctr(pprt, cmd);
841 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800842 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400843}
844
845/* send data to the TI LCD panel */
846static void lcd_write_data_tilcd(int data)
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 data port */
850 w_dtr(pprt, data);
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
Willy Tarreau698b1512008-11-22 11:29:33 +0100855static void lcd_gotoxy(void)
856{
857 lcd_write_cmd(0x80 /* set DDRAM address */
858 | (lcd_addr_y ? lcd_hwidth : 0)
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300859 /* we force the cursor to stay at the end of the
860 line if it wants to go farther */
Willy Tarreau698b1512008-11-22 11:29:33 +0100861 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x &
862 (lcd_hwidth - 1) : lcd_bwidth - 1));
863}
864
865static void lcd_print(char c)
866{
867 if (lcd_addr_x < lcd_bwidth) {
868 if (lcd_char_conv != NULL)
869 c = lcd_char_conv[(unsigned char)c];
870 lcd_write_data(c);
871 lcd_addr_x++;
872 }
873 /* prevents the cursor from wrapping onto the next line */
874 if (lcd_addr_x == lcd_bwidth)
875 lcd_gotoxy();
876}
877
878/* fills the display with spaces and resets X/Y */
879static void lcd_clear_fast_s(void)
880{
881 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200882
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200883 lcd_addr_x = 0;
884 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100885 lcd_gotoxy();
886
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800887 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100888 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
889 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
890 lcd_send_serial(' ' & 0x0F);
891 lcd_send_serial((' ' >> 4) & 0x0F);
892 udelay(40); /* the shortest data takes at least 40 us */
893 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800894 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100895
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200896 lcd_addr_x = 0;
897 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100898 lcd_gotoxy();
899}
900
901/* fills the display with spaces and resets X/Y */
902static void lcd_clear_fast_p8(void)
903{
904 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200905
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
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800910 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100911 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
912 /* present the data to the data port */
913 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300914
915 /* maintain the data during 20 us before the strobe */
916 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100917
918 bits.e = BIT_SET;
919 bits.rs = BIT_SET;
920 bits.rw = BIT_CLR;
921 set_ctrl_bits();
922
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300923 /* maintain the strobe during 40 us */
924 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100925
926 bits.e = BIT_CLR;
927 set_ctrl_bits();
928
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300929 /* the shortest data takes at least 45 us */
930 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100931 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800932 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100933
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200934 lcd_addr_x = 0;
935 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100936 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -0800937}
938
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400939/* fills the display with spaces and resets X/Y */
940static void lcd_clear_fast_tilcd(void)
941{
942 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200943
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200944 lcd_addr_x = 0;
945 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400946 lcd_gotoxy();
947
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800948 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400949 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) {
950 /* present the data to the data port */
951 w_dtr(pprt, ' ');
952 udelay(60);
953 }
954
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800955 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400956
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200957 lcd_addr_x = 0;
958 lcd_addr_y = 0;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400959 lcd_gotoxy();
960}
961
Willy Tarreau7005b582008-11-13 17:18:59 -0800962/* clears the display and resets X/Y */
Willy Tarreau698b1512008-11-22 11:29:33 +0100963static void lcd_clear_display(void)
964{
965 lcd_write_cmd(0x01); /* clear display */
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200966 lcd_addr_x = 0;
967 lcd_addr_y = 0;
Willy Tarreau698b1512008-11-22 11:29:33 +0100968 /* we must wait a few milliseconds (15) */
969 long_sleep(15);
Willy Tarreau7005b582008-11-13 17:18:59 -0800970}
971
Willy Tarreau698b1512008-11-22 11:29:33 +0100972static void lcd_init_display(void)
973{
Willy Tarreau698b1512008-11-22 11:29:33 +0100974 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0)
975 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
Willy Tarreau7005b582008-11-13 17:18:59 -0800976
Willy Tarreau698b1512008-11-22 11:29:33 +0100977 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
Willy Tarreau7005b582008-11-13 17:18:59 -0800978
Willy Tarreau698b1512008-11-22 11:29:33 +0100979 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
980 long_sleep(10);
981 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
982 long_sleep(10);
983 lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */
984 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800985
Willy Tarreau698b1512008-11-22 11:29:33 +0100986 lcd_write_cmd(0x30 /* set font height and lines number */
987 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
988 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)
989 );
990 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800991
Willy Tarreau698b1512008-11-22 11:29:33 +0100992 lcd_write_cmd(0x08); /* display off, cursor off, blink off */
993 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -0800994
Willy Tarreau698b1512008-11-22 11:29:33 +0100995 lcd_write_cmd(0x08 /* set display mode */
996 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
997 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
998 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)
999 );
Willy Tarreau7005b582008-11-13 17:18:59 -08001000
Willy Tarreau698b1512008-11-22 11:29:33 +01001001 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08001002
Willy Tarreau698b1512008-11-22 11:29:33 +01001003 long_sleep(10);
Willy Tarreau7005b582008-11-13 17:18:59 -08001004
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001005 /* entry mode set : increment, cursor shifting */
1006 lcd_write_cmd(0x06);
Willy Tarreau7005b582008-11-13 17:18:59 -08001007
Willy Tarreau698b1512008-11-22 11:29:33 +01001008 lcd_clear_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001009}
1010
1011/*
1012 * These are the file operation function for user access to /dev/lcd
1013 * This function can also be called from inside the kernel, by
1014 * setting file and ppos to NULL.
1015 *
1016 */
1017
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001018static inline int handle_lcd_special_code(void)
1019{
1020 /* LCD special codes */
1021
1022 int processed = 0;
1023
1024 char *esc = lcd_escape + 2;
1025 int oldflags = lcd_flags;
1026
1027 /* check for display mode flags */
1028 switch (*esc) {
1029 case 'D': /* Display ON */
1030 lcd_flags |= LCD_FLAG_D;
1031 processed = 1;
1032 break;
1033 case 'd': /* Display OFF */
1034 lcd_flags &= ~LCD_FLAG_D;
1035 processed = 1;
1036 break;
1037 case 'C': /* Cursor ON */
1038 lcd_flags |= LCD_FLAG_C;
1039 processed = 1;
1040 break;
1041 case 'c': /* Cursor OFF */
1042 lcd_flags &= ~LCD_FLAG_C;
1043 processed = 1;
1044 break;
1045 case 'B': /* Blink ON */
1046 lcd_flags |= LCD_FLAG_B;
1047 processed = 1;
1048 break;
1049 case 'b': /* Blink OFF */
1050 lcd_flags &= ~LCD_FLAG_B;
1051 processed = 1;
1052 break;
1053 case '+': /* Back light ON */
1054 lcd_flags |= LCD_FLAG_L;
1055 processed = 1;
1056 break;
1057 case '-': /* Back light OFF */
1058 lcd_flags &= ~LCD_FLAG_L;
1059 processed = 1;
1060 break;
1061 case '*':
1062 /* flash back light using the keypad timer */
1063 if (scan_timer.function != NULL) {
1064 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1065 lcd_backlight(1);
1066 light_tempo = FLASH_LIGHT_TEMPO;
1067 }
1068 processed = 1;
1069 break;
1070 case 'f': /* Small Font */
1071 lcd_flags &= ~LCD_FLAG_F;
1072 processed = 1;
1073 break;
1074 case 'F': /* Large Font */
1075 lcd_flags |= LCD_FLAG_F;
1076 processed = 1;
1077 break;
1078 case 'n': /* One Line */
1079 lcd_flags &= ~LCD_FLAG_N;
1080 processed = 1;
1081 break;
1082 case 'N': /* Two Lines */
1083 lcd_flags |= LCD_FLAG_N;
1084 break;
1085 case 'l': /* Shift Cursor Left */
1086 if (lcd_addr_x > 0) {
1087 /* back one char if not at end of line */
1088 if (lcd_addr_x < lcd_bwidth)
1089 lcd_write_cmd(0x10);
1090 lcd_addr_x--;
1091 }
1092 processed = 1;
1093 break;
1094 case 'r': /* shift cursor right */
1095 if (lcd_addr_x < lcd_width) {
1096 /* allow the cursor to pass the end of the line */
1097 if (lcd_addr_x <
1098 (lcd_bwidth - 1))
1099 lcd_write_cmd(0x14);
1100 lcd_addr_x++;
1101 }
1102 processed = 1;
1103 break;
1104 case 'L': /* shift display left */
1105 lcd_left_shift++;
1106 lcd_write_cmd(0x18);
1107 processed = 1;
1108 break;
1109 case 'R': /* shift display right */
1110 lcd_left_shift--;
1111 lcd_write_cmd(0x1C);
1112 processed = 1;
1113 break;
1114 case 'k': { /* kill end of line */
1115 int x;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001116
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001117 for (x = lcd_addr_x; x < lcd_bwidth; x++)
1118 lcd_write_data(' ');
1119
1120 /* restore cursor position */
1121 lcd_gotoxy();
1122 processed = 1;
1123 break;
1124 }
1125 case 'I': /* reinitialize display */
1126 lcd_init_display();
1127 lcd_left_shift = 0;
1128 processed = 1;
1129 break;
1130 case 'G': {
1131 /* Generator : LGcxxxxx...xx; must have <c> between '0'
1132 * and '7', representing the numerical ASCII code of the
1133 * redefined character, and <xx...xx> a sequence of 16
1134 * hex digits representing 8 bytes for each character.
1135 * Most LCDs will only use 5 lower bits of the 7 first
1136 * bytes.
1137 */
1138
1139 unsigned char cgbytes[8];
1140 unsigned char cgaddr;
1141 int cgoffset;
1142 int shift;
1143 char value;
1144 int addr;
1145
1146 if (strchr(esc, ';') == NULL)
1147 break;
1148
1149 esc++;
1150
1151 cgaddr = *(esc++) - '0';
1152 if (cgaddr > 7) {
1153 processed = 1;
1154 break;
1155 }
1156
1157 cgoffset = 0;
1158 shift = 0;
1159 value = 0;
1160 while (*esc && cgoffset < 8) {
1161 shift ^= 4;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001162 if (*esc >= '0' && *esc <= '9') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001163 value |= (*esc - '0') << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001164 } else if (*esc >= 'A' && *esc <= 'Z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001165 value |= (*esc - 'A' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001166 } else if (*esc >= 'a' && *esc <= 'z') {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001167 value |= (*esc - 'a' + 10) << shift;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001168 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001169 esc++;
1170 continue;
1171 }
1172
1173 if (shift == 0) {
1174 cgbytes[cgoffset++] = value;
1175 value = 0;
1176 }
1177
1178 esc++;
1179 }
1180
1181 lcd_write_cmd(0x40 | (cgaddr * 8));
1182 for (addr = 0; addr < cgoffset; addr++)
1183 lcd_write_data(cgbytes[addr]);
1184
1185 /* ensures that we stop writing to CGRAM */
1186 lcd_gotoxy();
1187 processed = 1;
1188 break;
1189 }
1190 case 'x': /* gotoxy : LxXXX[yYYY]; */
1191 case 'y': /* gotoxy : LyYYY[xXXX]; */
1192 if (strchr(esc, ';') == NULL)
1193 break;
1194
1195 while (*esc) {
1196 if (*esc == 'x') {
1197 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001198 if (kstrtoul(esc, 10, &lcd_addr_x) < 0)
1199 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001200 } else if (*esc == 'y') {
1201 esc++;
Pelle Windestam12995702011-08-30 20:29:24 +02001202 if (kstrtoul(esc, 10, &lcd_addr_y) < 0)
1203 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001204 } else {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001205 break;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001206 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001207 }
1208
1209 lcd_gotoxy();
1210 processed = 1;
1211 break;
1212 }
1213
Adam Buchbinderf2635892012-09-19 21:51:07 -04001214 /* Check whether one flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001215 if (oldflags != lcd_flags) {
1216 /* check whether one of B,C,D flags were changed */
1217 if ((oldflags ^ lcd_flags) &
1218 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1219 /* set display mode */
1220 lcd_write_cmd(0x08
1221 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0)
1222 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0)
1223 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0));
1224 /* check whether one of F,N flags was changed */
1225 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N))
1226 lcd_write_cmd(0x30
1227 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0)
1228 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0));
Adam Buchbinderf2635892012-09-19 21:51:07 -04001229 /* check whether L flag was changed */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001230 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) {
1231 if (lcd_flags & (LCD_FLAG_L))
1232 lcd_backlight(1);
1233 else if (light_tempo == 0)
1234 /* switch off the light only when the tempo
1235 lighting is gone */
1236 lcd_backlight(0);
1237 }
1238 }
1239
1240 return processed;
1241}
1242
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001243static void lcd_write_char(char c)
Willy Tarreau698b1512008-11-22 11:29:33 +01001244{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001245 /* first, we'll test if we're in escape mode */
1246 if ((c != '\n') && lcd_escape_len >= 0) {
1247 /* yes, let's add this char to the buffer */
1248 lcd_escape[lcd_escape_len++] = c;
1249 lcd_escape[lcd_escape_len] = 0;
1250 } else {
1251 /* aborts any previous escape sequence */
1252 lcd_escape_len = -1;
1253
1254 switch (c) {
1255 case LCD_ESCAPE_CHAR:
1256 /* start of an escape sequence */
1257 lcd_escape_len = 0;
1258 lcd_escape[lcd_escape_len] = 0;
1259 break;
1260 case '\b':
1261 /* go back one char and clear it */
1262 if (lcd_addr_x > 0) {
1263 /* check if we're not at the
1264 end of the line */
1265 if (lcd_addr_x < lcd_bwidth)
1266 /* back one char */
1267 lcd_write_cmd(0x10);
1268 lcd_addr_x--;
1269 }
1270 /* replace with a space */
1271 lcd_write_data(' ');
1272 /* back one char again */
1273 lcd_write_cmd(0x10);
1274 break;
1275 case '\014':
1276 /* quickly clear the display */
1277 lcd_clear_fast();
1278 break;
1279 case '\n':
1280 /* flush the remainder of the current line and
1281 go to the beginning of the next line */
1282 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++)
1283 lcd_write_data(' ');
1284 lcd_addr_x = 0;
1285 lcd_addr_y = (lcd_addr_y + 1) % lcd_height;
1286 lcd_gotoxy();
1287 break;
1288 case '\r':
1289 /* go to the beginning of the same line */
1290 lcd_addr_x = 0;
1291 lcd_gotoxy();
1292 break;
1293 case '\t':
1294 /* print a space instead of the tab */
1295 lcd_print(' ');
1296 break;
1297 default:
1298 /* simply print this char */
1299 lcd_print(c);
1300 break;
1301 }
1302 }
1303
1304 /* now we'll see if we're in an escape mode and if the current
1305 escape sequence can be understood. */
1306 if (lcd_escape_len >= 2) {
1307 int processed = 0;
1308
1309 if (!strcmp(lcd_escape, "[2J")) {
1310 /* clear the display */
1311 lcd_clear_fast();
1312 processed = 1;
1313 } else if (!strcmp(lcd_escape, "[H")) {
1314 /* cursor to home */
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001315 lcd_addr_x = 0;
1316 lcd_addr_y = 0;
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001317 lcd_gotoxy();
1318 processed = 1;
1319 }
1320 /* codes starting with ^[[L */
1321 else if ((lcd_escape_len >= 3) &&
1322 (lcd_escape[0] == '[') &&
1323 (lcd_escape[1] == 'L')) {
1324 processed = handle_lcd_special_code();
1325 }
1326
1327 /* LCD special escape codes */
1328 /* flush the escape sequence if it's been processed
1329 or if it is getting too long. */
1330 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN))
1331 lcd_escape_len = -1;
1332 } /* escape codes */
1333}
1334
1335static ssize_t lcd_write(struct file *file,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001336 const char __user *buf, size_t count, loff_t *ppos)
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001337{
1338 const char __user *tmp = buf;
Willy Tarreau698b1512008-11-22 11:29:33 +01001339 char c;
Willy Tarreau7005b582008-11-13 17:18:59 -08001340
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001341 for (; count-- > 0; (*ppos)++, tmp++) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001342 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001343 /* let's be a little nice with other processes
1344 that need some CPU */
1345 schedule();
Willy Tarreau7005b582008-11-13 17:18:59 -08001346
Bastien Armand6a4193a2014-04-23 19:42:11 +02001347 if (get_user(c, tmp))
Willy Tarreau698b1512008-11-22 11:29:33 +01001348 return -EFAULT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001349
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001350 lcd_write_char(c);
Willy Tarreau7005b582008-11-13 17:18:59 -08001351 }
1352
Willy Tarreau698b1512008-11-22 11:29:33 +01001353 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001354}
1355
Willy Tarreau698b1512008-11-22 11:29:33 +01001356static int lcd_open(struct inode *inode, struct file *file)
1357{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001358 if (!atomic_dec_and_test(&lcd_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001359 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001360
Willy Tarreau698b1512008-11-22 11:29:33 +01001361 if (file->f_mode & FMODE_READ) /* device is write-only */
1362 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001363
Willy Tarreau698b1512008-11-22 11:29:33 +01001364 if (lcd_must_clear) {
1365 lcd_clear_display();
1366 lcd_must_clear = 0;
1367 }
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001368 return nonseekable_open(inode, file);
Willy Tarreau7005b582008-11-13 17:18:59 -08001369}
1370
Willy Tarreau698b1512008-11-22 11:29:33 +01001371static int lcd_release(struct inode *inode, struct file *file)
1372{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001373 atomic_inc(&lcd_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001374 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001375}
1376
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001377static const struct file_operations lcd_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001378 .write = lcd_write,
1379 .open = lcd_open,
1380 .release = lcd_release,
Arnd Bergmann3ff81012010-07-07 23:40:09 +02001381 .llseek = no_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001382};
1383
1384static struct miscdevice lcd_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001385 .minor = LCD_MINOR,
1386 .name = "lcd",
1387 .fops = &lcd_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001388};
1389
Willy Tarreau7005b582008-11-13 17:18:59 -08001390/* public function usable from the kernel for any purpose */
Peter Huewe36d20412013-02-15 13:47:05 +01001391static void panel_lcd_print(const char *s)
Willy Tarreau698b1512008-11-22 11:29:33 +01001392{
Bastien Armand70a8c3e2014-04-18 18:10:57 +02001393 const char *tmp = s;
1394 int count = strlen(s);
1395
1396 if (lcd_enabled && lcd_initialized) {
1397 for (; count-- > 0; tmp++) {
1398 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1399 /* let's be a little nice with other processes
1400 that need some CPU */
1401 schedule();
1402
1403 lcd_write_char(*tmp);
1404 }
1405 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001406}
1407
Willy Tarreau7005b582008-11-13 17:18:59 -08001408/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +01001409static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001410{
1411 switch (lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001412 case LCD_TYPE_OLD:
1413 /* parallel mode, 8 bits */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001414 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001415 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001416 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001417 lcd_charset = LCD_CHARSET_NORMAL;
1418 if (lcd_e_pin == PIN_NOT_SET)
1419 lcd_e_pin = PIN_STROBE;
1420 if (lcd_rs_pin == PIN_NOT_SET)
1421 lcd_rs_pin = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -08001422
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001423 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001424 lcd_width = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001425 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001426 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001427 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001428 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001429 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001430 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001431 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001432 case LCD_TYPE_KS0074:
1433 /* serial mode, ks0074 */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001434 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001435 lcd_proto = LCD_PROTO_SERIAL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001436 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001437 lcd_charset = LCD_CHARSET_KS0074;
1438 if (lcd_bl_pin == PIN_NOT_SET)
1439 lcd_bl_pin = PIN_AUTOLF;
1440 if (lcd_cl_pin == PIN_NOT_SET)
1441 lcd_cl_pin = PIN_STROBE;
1442 if (lcd_da_pin == PIN_NOT_SET)
1443 lcd_da_pin = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001444
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001445 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001446 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001447 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001448 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001449 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001450 lcd_hwidth = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001451 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001452 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001453 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001454 case LCD_TYPE_NEXCOM:
1455 /* parallel mode, 8 bits, generic */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001456 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001457 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001458 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001459 lcd_charset = LCD_CHARSET_NORMAL;
1460 if (lcd_e_pin == PIN_NOT_SET)
1461 lcd_e_pin = PIN_AUTOLF;
1462 if (lcd_rs_pin == PIN_NOT_SET)
1463 lcd_rs_pin = PIN_SELECP;
1464 if (lcd_rw_pin == PIN_NOT_SET)
1465 lcd_rw_pin = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001466
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001467 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001468 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001469 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001470 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001471 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001472 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001473 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001474 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001475 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001476 case LCD_TYPE_CUSTOM:
1477 /* customer-defined */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001478 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001479 lcd_proto = DEFAULT_LCD_PROTO;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001480 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001481 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001482 /* default geometry will be set later */
1483 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001484 case LCD_TYPE_HANTRONIX:
1485 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +01001486 default:
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001487 if (lcd_proto == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001488 lcd_proto = LCD_PROTO_PARALLEL;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001489 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001490 lcd_charset = LCD_CHARSET_NORMAL;
1491 if (lcd_e_pin == PIN_NOT_SET)
1492 lcd_e_pin = PIN_STROBE;
1493 if (lcd_rs_pin == PIN_NOT_SET)
1494 lcd_rs_pin = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -08001495
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001496 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001497 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001498 if (lcd_bwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001499 lcd_bwidth = 40;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001500 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001501 lcd_hwidth = 64;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001502 if (lcd_height == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001503 lcd_height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -08001504 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001505 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001506
Willy Tarreau698b1512008-11-22 11:29:33 +01001507 /* this is used to catch wrong and default values */
1508 if (lcd_width <= 0)
1509 lcd_width = DEFAULT_LCD_WIDTH;
1510 if (lcd_bwidth <= 0)
1511 lcd_bwidth = DEFAULT_LCD_BWIDTH;
1512 if (lcd_hwidth <= 0)
1513 lcd_hwidth = DEFAULT_LCD_HWIDTH;
1514 if (lcd_height <= 0)
1515 lcd_height = DEFAULT_LCD_HEIGHT;
Willy Tarreau7005b582008-11-13 17:18:59 -08001516
Willy Tarreau698b1512008-11-22 11:29:33 +01001517 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */
1518 lcd_write_cmd = lcd_write_cmd_s;
1519 lcd_write_data = lcd_write_data_s;
1520 lcd_clear_fast = lcd_clear_fast_s;
Willy Tarreau7005b582008-11-13 17:18:59 -08001521
Willy Tarreau698b1512008-11-22 11:29:33 +01001522 if (lcd_cl_pin == PIN_NOT_SET)
1523 lcd_cl_pin = DEFAULT_LCD_PIN_SCL;
1524 if (lcd_da_pin == PIN_NOT_SET)
1525 lcd_da_pin = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001526
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001527 } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Willy Tarreau698b1512008-11-22 11:29:33 +01001528 lcd_write_cmd = lcd_write_cmd_p8;
1529 lcd_write_data = lcd_write_data_p8;
1530 lcd_clear_fast = lcd_clear_fast_p8;
Willy Tarreau7005b582008-11-13 17:18:59 -08001531
Willy Tarreau698b1512008-11-22 11:29:33 +01001532 if (lcd_e_pin == PIN_NOT_SET)
1533 lcd_e_pin = DEFAULT_LCD_PIN_E;
1534 if (lcd_rs_pin == PIN_NOT_SET)
1535 lcd_rs_pin = DEFAULT_LCD_PIN_RS;
1536 if (lcd_rw_pin == PIN_NOT_SET)
1537 lcd_rw_pin = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001538 } else {
1539 lcd_write_cmd = lcd_write_cmd_tilcd;
1540 lcd_write_data = lcd_write_data_tilcd;
1541 lcd_clear_fast = lcd_clear_fast_tilcd;
Willy Tarreau698b1512008-11-22 11:29:33 +01001542 }
1543
1544 if (lcd_bl_pin == PIN_NOT_SET)
1545 lcd_bl_pin = DEFAULT_LCD_PIN_BL;
1546
1547 if (lcd_e_pin == PIN_NOT_SET)
1548 lcd_e_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001549 if (lcd_rs_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001550 lcd_rs_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001551 if (lcd_rw_pin == PIN_NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001552 lcd_rw_pin = PIN_NONE;
1553 if (lcd_bl_pin == PIN_NOT_SET)
1554 lcd_bl_pin = PIN_NONE;
1555 if (lcd_cl_pin == PIN_NOT_SET)
1556 lcd_cl_pin = PIN_NONE;
1557 if (lcd_da_pin == PIN_NOT_SET)
1558 lcd_da_pin = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001559
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001560 if (lcd_charset == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001561 lcd_charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001562
Willy Tarreau698b1512008-11-22 11:29:33 +01001563 if (lcd_charset == LCD_CHARSET_KS0074)
1564 lcd_char_conv = lcd_char_conv_ks0074;
1565 else
1566 lcd_char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001567
Willy Tarreau698b1512008-11-22 11:29:33 +01001568 if (lcd_bl_pin != PIN_NONE)
1569 init_scan_timer();
Willy Tarreau7005b582008-11-13 17:18:59 -08001570
Willy Tarreau698b1512008-11-22 11:29:33 +01001571 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1572 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1573 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1574 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1575 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1576 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1577 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1578 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1579 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1580 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1581 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1582 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001583
Willy Tarreau698b1512008-11-22 11:29:33 +01001584 /* before this line, we must NOT send anything to the display.
1585 * Since lcd_init_display() needs to write data, we have to
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001586 * enable mark the LCD initialized just before. */
Willy Tarreau698b1512008-11-22 11:29:33 +01001587 lcd_initialized = 1;
1588 lcd_init_display();
Willy Tarreau7005b582008-11-13 17:18:59 -08001589
Willy Tarreau698b1512008-11-22 11:29:33 +01001590 /* display a short message */
Willy Tarreau7005b582008-11-13 17:18:59 -08001591#ifdef CONFIG_PANEL_CHANGE_MESSAGE
1592#ifdef CONFIG_PANEL_BOOT_MESSAGE
Willy Tarreau698b1512008-11-22 11:29:33 +01001593 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
Willy Tarreau7005b582008-11-13 17:18:59 -08001594#endif
1595#else
Willy Tarreau698b1512008-11-22 11:29:33 +01001596 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1597 PANEL_VERSION);
Willy Tarreau7005b582008-11-13 17:18:59 -08001598#endif
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001599 lcd_addr_x = 0;
1600 lcd_addr_y = 0;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001601 /* clear the display on the next device opening */
1602 lcd_must_clear = 1;
Willy Tarreau698b1512008-11-22 11:29:33 +01001603 lcd_gotoxy();
Willy Tarreau7005b582008-11-13 17:18:59 -08001604}
1605
Willy Tarreau7005b582008-11-13 17:18:59 -08001606/*
1607 * These are the file operation function for user access to /dev/keypad
1608 */
1609
Willy Tarreau698b1512008-11-22 11:29:33 +01001610static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001611 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001612{
Willy Tarreau698b1512008-11-22 11:29:33 +01001613 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001614 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001615
Willy Tarreau698b1512008-11-22 11:29:33 +01001616 if (keypad_buflen == 0) {
1617 if (file->f_flags & O_NONBLOCK)
1618 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001619
Arnd Bergmann310df692014-01-02 13:07:35 +01001620 if (wait_event_interruptible(keypad_read_wait,
1621 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001622 return -EINTR;
1623 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001624
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001625 for (; count-- > 0 && (keypad_buflen > 0);
1626 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001627 put_user(keypad_buffer[keypad_start], tmp);
1628 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1629 }
1630 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001631
Willy Tarreau698b1512008-11-22 11:29:33 +01001632 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001633}
1634
Willy Tarreau698b1512008-11-22 11:29:33 +01001635static int keypad_open(struct inode *inode, struct file *file)
1636{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001637 if (!atomic_dec_and_test(&keypad_available))
Willy Tarreau698b1512008-11-22 11:29:33 +01001638 return -EBUSY; /* open only once at a time */
Willy Tarreau7005b582008-11-13 17:18:59 -08001639
Willy Tarreau698b1512008-11-22 11:29:33 +01001640 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1641 return -EPERM;
Willy Tarreau7005b582008-11-13 17:18:59 -08001642
Willy Tarreau698b1512008-11-22 11:29:33 +01001643 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001644 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001645}
1646
Willy Tarreau698b1512008-11-22 11:29:33 +01001647static int keypad_release(struct inode *inode, struct file *file)
1648{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001649 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001650 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001651}
1652
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001653static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001654 .read = keypad_read, /* read */
1655 .open = keypad_open, /* open */
1656 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001657 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001658};
1659
1660static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001661 .minor = KEYPAD_MINOR,
1662 .name = "keypad",
1663 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001664};
1665
Peter Huewe36d20412013-02-15 13:47:05 +01001666static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001667{
1668 if (init_in_progress)
1669 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001670
Willy Tarreau698b1512008-11-22 11:29:33 +01001671 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001672 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001673 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1674 keypad_buffer[(keypad_start + keypad_buflen++) %
1675 KEYPAD_BUFFER] = *string++;
1676 }
1677 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001678 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001679}
1680
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001681/* this function scans all the bits involving at least one logical signal,
1682 * and puts the results in the bitfield "phys_read" (one bit per established
1683 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001684 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001685 * Note: to debounce input signals, we will only consider as switched a signal
1686 * which is stable across 2 measures. Signals which are different between two
1687 * reads will be kept as they previously were in their logical form (phys_prev).
1688 * A signal which has just switched will have a 1 in
1689 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001690 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001691static void phys_scan_contacts(void)
1692{
1693 int bit, bitval;
1694 char oldval;
1695 char bitmask;
1696 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001697
Willy Tarreau698b1512008-11-22 11:29:33 +01001698 phys_prev = phys_curr;
1699 phys_read_prev = phys_read;
1700 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001701
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001702 /* keep track of old value, with all outputs disabled */
1703 oldval = r_dtr(pprt) | scan_mask_o;
1704 /* activate all keyboard outputs (active low) */
1705 w_dtr(pprt, oldval & ~scan_mask_o);
1706
1707 /* will have a 1 for each bit set to gnd */
1708 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1709 /* disable all matrix signals */
1710 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001711
Willy Tarreau698b1512008-11-22 11:29:33 +01001712 /* now that all outputs are cleared, the only active input bits are
1713 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001714 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001715
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001716 /* 1 for each grounded input */
1717 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1718
1719 /* grounded inputs are signals 40-44 */
1720 phys_read |= (pmask_t) gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001721
Willy Tarreau698b1512008-11-22 11:29:33 +01001722 if (bitmask != gndmask) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001723 /* since clearing the outputs changed some inputs, we know
1724 * that some input signals are currently tied to some outputs.
1725 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001726 */
1727 for (bit = 0; bit < 8; bit++) {
1728 bitval = 1 << bit;
1729
1730 if (!(scan_mask_o & bitval)) /* skip unused bits */
1731 continue;
1732
1733 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1734 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
1735 phys_read |= (pmask_t) bitmask << (5 * bit);
1736 }
1737 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001738 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001739 /* this is easy: use old bits when they are flapping,
1740 * use new ones when stable */
1741 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1742 (phys_read & ~(phys_read ^ phys_read_prev));
1743}
1744
1745static inline int input_state_high(struct logical_input *input)
1746{
1747#if 0
1748 /* FIXME:
1749 * this is an invalid test. It tries to catch
1750 * transitions from single-key to multiple-key, but
1751 * doesn't take into account the contacts polarity.
1752 * The only solution to the problem is to parse keys
1753 * from the most complex to the simplest combinations,
1754 * and mark them as 'caught' once a combination
1755 * matches, then unmatch it for all other ones.
1756 */
1757
1758 /* try to catch dangerous transitions cases :
1759 * someone adds a bit, so this signal was a false
1760 * positive resulting from a transition. We should
1761 * invalidate the signal immediately and not call the
1762 * release function.
1763 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1764 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001765 if (((phys_prev & input->mask) == input->value) &&
1766 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001767 input->state = INPUT_ST_LOW; /* invalidate */
1768 return 1;
1769 }
1770#endif
1771
1772 if ((phys_curr & input->mask) == input->value) {
1773 if ((input->type == INPUT_TYPE_STD) &&
1774 (input->high_timer == 0)) {
1775 input->high_timer++;
1776 if (input->u.std.press_fct != NULL)
1777 input->u.std.press_fct(input->u.std.press_data);
1778 } else if (input->type == INPUT_TYPE_KBD) {
1779 /* will turn on the light */
1780 keypressed = 1;
1781
1782 if (input->high_timer == 0) {
1783 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001784
Jake Champline6626de2013-05-04 11:21:17 -04001785 if (press_str[0]) {
1786 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001787
Jake Champline6626de2013-05-04 11:21:17 -04001788 keypad_send_key(press_str, s);
1789 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001790 }
1791
1792 if (input->u.kbd.repeat_str[0]) {
1793 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001794
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001795 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001796 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001797
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001798 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001799 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001800 }
1801 /* we will need to come back here soon */
1802 inputs_stable = 0;
1803 }
1804
1805 if (input->high_timer < 255)
1806 input->high_timer++;
1807 }
1808 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001809 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001810
1811 /* else signal falling down. Let's fall through. */
1812 input->state = INPUT_ST_FALLING;
1813 input->fall_timer = 0;
1814
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001815 return 0;
1816}
1817
1818static inline void input_state_falling(struct logical_input *input)
1819{
1820#if 0
1821 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001822 if (((phys_prev & input->mask) == input->value) &&
1823 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001824 input->state = INPUT_ST_LOW; /* invalidate */
1825 return;
1826 }
1827#endif
1828
1829 if ((phys_curr & input->mask) == input->value) {
1830 if (input->type == INPUT_TYPE_KBD) {
1831 /* will turn on the light */
1832 keypressed = 1;
1833
1834 if (input->u.kbd.repeat_str[0]) {
1835 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001836
Jake Champline6626de2013-05-04 11:21:17 -04001837 if (input->high_timer >= KEYPAD_REP_START) {
1838 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001839
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001840 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001841 keypad_send_key(repeat_str, s);
1842 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001843 /* we will need to come back here soon */
1844 inputs_stable = 0;
1845 }
1846
1847 if (input->high_timer < 255)
1848 input->high_timer++;
1849 }
1850 input->state = INPUT_ST_HIGH;
1851 } else if (input->fall_timer >= input->fall_time) {
1852 /* call release event */
1853 if (input->type == INPUT_TYPE_STD) {
1854 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001855
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001856 if (release_fct != NULL)
1857 release_fct(input->u.std.release_data);
1858 } else if (input->type == INPUT_TYPE_KBD) {
1859 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001860
Jake Champline6626de2013-05-04 11:21:17 -04001861 if (release_str[0]) {
1862 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001863
Jake Champline6626de2013-05-04 11:21:17 -04001864 keypad_send_key(release_str, s);
1865 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001866 }
1867
1868 input->state = INPUT_ST_LOW;
1869 } else {
1870 input->fall_timer++;
1871 inputs_stable = 0;
1872 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001873}
1874
Willy Tarreau698b1512008-11-22 11:29:33 +01001875static void panel_process_inputs(void)
1876{
1877 struct list_head *item;
1878 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001879
Willy Tarreau698b1512008-11-22 11:29:33 +01001880 keypressed = 0;
1881 inputs_stable = 1;
1882 list_for_each(item, &logical_inputs) {
1883 input = list_entry(item, struct logical_input, list);
Willy Tarreau7005b582008-11-13 17:18:59 -08001884
Willy Tarreau698b1512008-11-22 11:29:33 +01001885 switch (input->state) {
1886 case INPUT_ST_LOW:
1887 if ((phys_curr & input->mask) != input->value)
1888 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001889 /* if all needed ones were already set previously,
1890 * this means that this logical signal has been
1891 * activated by the releasing of another combined
1892 * signal, so we don't want to match.
1893 * eg: AB -(release B)-> A -(release A)-> 0 :
1894 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001895 */
1896 if ((phys_prev & input->mask) == input->value)
1897 break;
1898 input->rise_timer = 0;
1899 input->state = INPUT_ST_RISING;
1900 /* no break here, fall through */
1901 case INPUT_ST_RISING:
1902 if ((phys_curr & input->mask) != input->value) {
1903 input->state = INPUT_ST_LOW;
1904 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001905 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001906 if (input->rise_timer < input->rise_time) {
1907 inputs_stable = 0;
1908 input->rise_timer++;
1909 break;
1910 }
1911 input->high_timer = 0;
1912 input->state = INPUT_ST_HIGH;
1913 /* no break here, fall through */
1914 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001915 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001916 break;
Willy Tarreau698b1512008-11-22 11:29:33 +01001917 /* no break here, fall through */
1918 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001919 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001920 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001921 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001922}
1923
Willy Tarreau698b1512008-11-22 11:29:33 +01001924static void panel_scan_timer(void)
1925{
Willy Tarreau630231772008-11-22 12:52:18 +01001926 if (keypad_enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001927 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001928 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001929
1930 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001931 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001932 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001933
Willy Tarreau698b1512008-11-22 11:29:33 +01001934 if (!inputs_stable || phys_curr != phys_prev)
1935 panel_process_inputs();
1936 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001937
Willy Tarreau698b1512008-11-22 11:29:33 +01001938 if (lcd_enabled && lcd_initialized) {
1939 if (keypressed) {
1940 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1941 lcd_backlight(1);
1942 light_tempo = FLASH_LIGHT_TEMPO;
1943 } else if (light_tempo > 0) {
1944 light_tempo--;
1945 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0))
1946 lcd_backlight(0);
1947 }
1948 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001949
Willy Tarreau698b1512008-11-22 11:29:33 +01001950 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001951}
1952
Willy Tarreau698b1512008-11-22 11:29:33 +01001953static void init_scan_timer(void)
1954{
1955 if (scan_timer.function != NULL)
1956 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001957
Willy Tarreau698b1512008-11-22 11:29:33 +01001958 init_timer(&scan_timer);
1959 scan_timer.expires = jiffies + INPUT_POLL_TIME;
1960 scan_timer.data = 0;
1961 scan_timer.function = (void *)&panel_scan_timer;
1962 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001963}
1964
1965/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001966 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1967 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001968 * returns 1 if ok, 0 if error (in which case, nothing is written).
1969 */
Peter Huewe36d20412013-02-15 13:47:05 +01001970static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
Willy Tarreau698b1512008-11-22 11:29:33 +01001971 char *imask, char *omask)
1972{
1973 static char sigtab[10] = "EeSsPpAaBb";
1974 char im, om;
1975 pmask_t m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001976
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001977 om = 0ULL;
1978 im = 0ULL;
1979 m = 0ULL;
1980 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001981 while (*name) {
1982 int in, out, bit, neg;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001983
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001984 for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
1985 in++)
Willy Tarreau698b1512008-11-22 11:29:33 +01001986 ;
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001987
Willy Tarreau698b1512008-11-22 11:29:33 +01001988 if (in >= sizeof(sigtab))
1989 return 0; /* input name not found */
1990 neg = (in & 1); /* odd (lower) names are negated */
1991 in >>= 1;
1992 im |= (1 << in);
Willy Tarreau7005b582008-11-13 17:18:59 -08001993
Willy Tarreau698b1512008-11-22 11:29:33 +01001994 name++;
1995 if (isdigit(*name)) {
1996 out = *name - '0';
1997 om |= (1 << out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001998 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01001999 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002000 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01002001 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02002002 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002003
2004 bit = (out * 5) + in;
2005
2006 m |= 1ULL << bit;
2007 if (!neg)
2008 v |= 1ULL << bit;
2009 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08002010 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002011 *mask = m;
2012 *value = v;
2013 if (imask)
2014 *imask |= im;
2015 if (omask)
2016 *omask |= om;
2017 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002018}
2019
2020/* tries to bind a key to the signal name <name>. The key will send the
2021 * strings <press>, <repeat>, <release> for these respective events.
2022 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
2023 */
Peter Huewe36d20412013-02-15 13:47:05 +01002024static struct logical_input *panel_bind_key(const char *name, const char *press,
2025 const char *repeat,
2026 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01002027{
2028 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002029
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002030 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002031 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01002032 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002033
Willy Tarreau698b1512008-11-22 11:29:33 +01002034 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002035 &scan_mask_o)) {
2036 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01002037 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04002038 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002039
2040 key->type = INPUT_TYPE_KBD;
2041 key->state = INPUT_ST_LOW;
2042 key->rise_time = 1;
2043 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002044
Willy Tarreau698b1512008-11-22 11:29:33 +01002045 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
2046 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
2047 strncpy(key->u.kbd.release_str, release,
2048 sizeof(key->u.kbd.release_str));
2049 list_add(&key->list, &logical_inputs);
2050 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08002051}
2052
Willy Tarreau630231772008-11-22 12:52:18 +01002053#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08002054/* tries to bind a callback function to the signal name <name>. The function
2055 * <press_fct> will be called with the <press_data> arg when the signal is
2056 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002057 * Returns the pointer to the new signal if ok, NULL if the signal could not
2058 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08002059 */
2060static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302061 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002062 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05302063 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01002064 int release_data)
2065{
2066 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002067
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02002068 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002069 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01002070 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002071
Willy Tarreau698b1512008-11-22 11:29:33 +01002072 memset(callback, 0, sizeof(struct logical_input));
2073 if (!input_name2mask(name, &callback->mask, &callback->value,
2074 &scan_mask_i, &scan_mask_o))
2075 return NULL;
2076
2077 callback->type = INPUT_TYPE_STD;
2078 callback->state = INPUT_ST_LOW;
2079 callback->rise_time = 1;
2080 callback->fall_time = 1;
2081 callback->u.std.press_fct = press_fct;
2082 callback->u.std.press_data = press_data;
2083 callback->u.std.release_fct = release_fct;
2084 callback->u.std.release_data = release_data;
2085 list_add(&callback->list, &logical_inputs);
2086 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08002087}
Willy Tarreau630231772008-11-22 12:52:18 +01002088#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08002089
Willy Tarreau698b1512008-11-22 11:29:33 +01002090static void keypad_init(void)
2091{
2092 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02002093
Willy Tarreau698b1512008-11-22 11:29:33 +01002094 init_waitqueue_head(&keypad_read_wait);
2095 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08002096
Willy Tarreau698b1512008-11-22 11:29:33 +01002097 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08002098
Willy Tarreau698b1512008-11-22 11:29:33 +01002099 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
2100 panel_bind_key(keypad_profile[keynum][0],
2101 keypad_profile[keynum][1],
2102 keypad_profile[keynum][2],
2103 keypad_profile[keynum][3]);
2104 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002105
Willy Tarreau698b1512008-11-22 11:29:33 +01002106 init_scan_timer();
2107 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08002108}
2109
Willy Tarreau7005b582008-11-13 17:18:59 -08002110/**************************************************/
2111/* device initialization */
2112/**************************************************/
2113
Willy Tarreau698b1512008-11-22 11:29:33 +01002114static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2115 void *unused)
2116{
2117 if (lcd_enabled && lcd_initialized) {
2118 switch (code) {
2119 case SYS_DOWN:
2120 panel_lcd_print
2121 ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
2122 break;
2123 case SYS_HALT:
2124 panel_lcd_print
2125 ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
2126 break;
2127 case SYS_POWER_OFF:
2128 panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
2129 break;
2130 default:
2131 break;
2132 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002133 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002134 return NOTIFY_DONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08002135}
2136
2137static struct notifier_block panel_notifier = {
2138 panel_notify_sys,
2139 NULL,
2140 0
2141};
2142
Willy Tarreau698b1512008-11-22 11:29:33 +01002143static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002144{
Willy Tarreau698b1512008-11-22 11:29:33 +01002145 if (port->number != parport)
2146 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002147
Willy Tarreau698b1512008-11-22 11:29:33 +01002148 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002149 pr_err("%s: port->number=%d parport=%d, already registered!\n",
2150 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002151 return;
2152 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002153
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002154 pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */
Willy Tarreau698b1512008-11-22 11:29:33 +01002155 NULL,
2156 /*PARPORT_DEV_EXCL */
2157 0, (void *)&pprt);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002158 if (pprt == NULL) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002159 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
2160 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002161 return;
2162 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002163
Willy Tarreau698b1512008-11-22 11:29:33 +01002164 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002165 pr_err("could not claim access to parport%d. Aborting.\n",
2166 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002167 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002168 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002169
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002170 /* must init LCD first, just in case an IRQ from the keypad is
2171 * generated at keypad init
2172 */
Willy Tarreau698b1512008-11-22 11:29:33 +01002173 if (lcd_enabled) {
2174 lcd_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002175 if (misc_register(&lcd_dev))
2176 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01002177 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002178
Willy Tarreau698b1512008-11-22 11:29:33 +01002179 if (keypad_enabled) {
2180 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002181 if (misc_register(&keypad_dev))
2182 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01002183 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04002184 return;
2185
2186err_lcd_unreg:
2187 if (lcd_enabled)
2188 misc_deregister(&lcd_dev);
2189err_unreg_device:
2190 parport_unregister_device(pprt);
2191 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002192}
2193
Willy Tarreau698b1512008-11-22 11:29:33 +01002194static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08002195{
Willy Tarreau698b1512008-11-22 11:29:33 +01002196 if (port->number != parport)
2197 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08002198
Willy Tarreau698b1512008-11-22 11:29:33 +01002199 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002200 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
2201 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01002202 return;
2203 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002204
Peter Huewe0b0595b2009-09-29 01:22:40 +02002205 if (keypad_enabled && keypad_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002206 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002207 keypad_initialized = 0;
2208 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002209
Peter Huewe0b0595b2009-09-29 01:22:40 +02002210 if (lcd_enabled && lcd_initialized) {
Willy Tarreau698b1512008-11-22 11:29:33 +01002211 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002212 lcd_initialized = 0;
2213 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002214
Willy Tarreau698b1512008-11-22 11:29:33 +01002215 parport_release(pprt);
2216 parport_unregister_device(pprt);
2217 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08002218}
2219
2220static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01002221 .name = "panel",
2222 .attach = panel_attach,
2223 .detach = panel_detach,
Willy Tarreau7005b582008-11-13 17:18:59 -08002224};
2225
2226/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01002227static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002228{
2229 /* for backwards compatibility */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002230 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002231 keypad_type = keypad_enabled;
Willy Tarreau7005b582008-11-13 17:18:59 -08002232
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002233 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002234 lcd_type = lcd_enabled;
Willy Tarreau7005b582008-11-13 17:18:59 -08002235
Willy Tarreau698b1512008-11-22 11:29:33 +01002236 /* take care of an eventual profile */
2237 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002238 case PANEL_PROFILE_CUSTOM:
2239 /* custom profile */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002240 if (keypad_type == NOT_SET)
Mariusz Gorski98fac3d2014-11-12 02:08:09 +01002241 keypad_type = DEFAULT_KEYPAD_TYPE;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002242 if (lcd_type == NOT_SET)
Mariusz Gorski98fac3d2014-11-12 02:08:09 +01002243 lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01002244 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002245 case PANEL_PROFILE_OLD:
2246 /* 8 bits, 2*16, old keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002247 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002248 keypad_type = KEYPAD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002249 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002250 lcd_type = LCD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002251 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002252 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002253 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002254 lcd_hwidth = 16;
2255 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002256 case PANEL_PROFILE_NEW:
2257 /* serial, 2*16, new keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002258 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002259 keypad_type = KEYPAD_TYPE_NEW;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002260 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002261 lcd_type = LCD_TYPE_KS0074;
2262 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002263 case PANEL_PROFILE_HANTRONIX:
2264 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002265 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002266 keypad_type = KEYPAD_TYPE_NONE;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002267 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002268 lcd_type = LCD_TYPE_HANTRONIX;
2269 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002270 case PANEL_PROFILE_NEXCOM:
2271 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002272 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002273 keypad_type = KEYPAD_TYPE_NEXCOM;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002274 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002275 lcd_type = LCD_TYPE_NEXCOM;
2276 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002277 case PANEL_PROFILE_LARGE:
2278 /* 8 bits, 2*40, old keypad */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002279 if (keypad_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002280 keypad_type = KEYPAD_TYPE_OLD;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01002281 if (lcd_type == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01002282 lcd_type = LCD_TYPE_OLD;
2283 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08002284 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002285
Willy Tarreau698b1512008-11-22 11:29:33 +01002286 lcd_enabled = (lcd_type > 0);
2287 keypad_enabled = (keypad_type > 0);
Willy Tarreau7005b582008-11-13 17:18:59 -08002288
Willy Tarreau698b1512008-11-22 11:29:33 +01002289 switch (keypad_type) {
2290 case KEYPAD_TYPE_OLD:
2291 keypad_profile = old_keypad_profile;
2292 break;
2293 case KEYPAD_TYPE_NEW:
2294 keypad_profile = new_keypad_profile;
2295 break;
2296 case KEYPAD_TYPE_NEXCOM:
2297 keypad_profile = nexcom_keypad_profile;
2298 break;
2299 default:
2300 keypad_profile = NULL;
2301 break;
2302 }
2303
2304 /* tells various subsystems about the fact that we are initializing */
2305 init_in_progress = 1;
2306
2307 if (parport_register_driver(&panel_driver)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002308 pr_err("could not register with parport. Aborting.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002309 return -EIO;
2310 }
2311
Willy Tarreau630231772008-11-22 12:52:18 +01002312 if (!lcd_enabled && !keypad_enabled) {
2313 /* no device enabled, let's release the parport */
Willy Tarreau698b1512008-11-22 11:29:33 +01002314 if (pprt) {
2315 parport_release(pprt);
2316 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002317 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002318 }
2319 parport_unregister_driver(&panel_driver);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09002320 pr_err("driver version " PANEL_VERSION " disabled.\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01002321 return -ENODEV;
2322 }
2323
2324 register_reboot_notifier(&panel_notifier);
2325
2326 if (pprt)
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002327 pr_info("driver version " PANEL_VERSION
2328 " registered on parport%d (io=0x%lx).\n", parport,
2329 pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01002330 else
Toshiaki Yamane493aa892012-07-12 22:01:00 +09002331 pr_info("driver version " PANEL_VERSION
2332 " not yet registered\n");
Henri Häkkinen429ccf02010-06-12 00:27:36 +03002333 /* tells various subsystems about the fact that initialization
2334 is finished */
Willy Tarreau698b1512008-11-22 11:29:33 +01002335 init_in_progress = 0;
2336 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08002337}
2338
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01002339static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01002340{
2341 unregister_reboot_notifier(&panel_notifier);
Willy Tarreau7005b582008-11-13 17:18:59 -08002342
Willy Tarreau698b1512008-11-22 11:29:33 +01002343 if (scan_timer.function != NULL)
Julia Lawalle112f892014-03-26 22:33:41 +01002344 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08002345
Costantino Leandro57898132009-02-17 11:10:48 -05002346 if (pprt != NULL) {
Peter Huewe0b0595b2009-09-29 01:22:40 +02002347 if (keypad_enabled) {
Costantino Leandro57898132009-02-17 11:10:48 -05002348 misc_deregister(&keypad_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002349 keypad_initialized = 0;
2350 }
Willy Tarreau7005b582008-11-13 17:18:59 -08002351
Costantino Leandro57898132009-02-17 11:10:48 -05002352 if (lcd_enabled) {
2353 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2354 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2355 misc_deregister(&lcd_dev);
Peter Huewe0b0595b2009-09-29 01:22:40 +02002356 lcd_initialized = 0;
Costantino Leandro57898132009-02-17 11:10:48 -05002357 }
2358
2359 /* TODO: free all input signals */
2360 parport_release(pprt);
2361 parport_unregister_device(pprt);
Peter Huewe060132a2010-07-07 04:52:16 +02002362 pprt = NULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01002363 }
Willy Tarreau698b1512008-11-22 11:29:33 +01002364 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08002365}
Willy Tarreau7005b582008-11-13 17:18:59 -08002366
Willy Tarreau7005b582008-11-13 17:18:59 -08002367module_init(panel_init_module);
2368module_exit(panel_cleanup_module);
2369MODULE_AUTHOR("Willy Tarreau");
2370MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08002371
2372/*
2373 * Local variables:
2374 * c-indent-level: 4
2375 * tab-width: 8
2376 * End:
2377 */