blob: 3b25a643058c9dde38511d646da8700e53c46837 [file] [log] [blame]
Miguel Ojeda351f683b2018-02-17 20:33:13 +01001// SPDX-License-Identifier: GPL-2.0+
Willy Tarreau7005b582008-11-13 17:18:59 -08002/*
Willy Tarreau698b1512008-11-22 11:29:33 +01003 * Front panel driver for Linux
4 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01005 * Copyright (C) 2016-2017 Glider bvba
Willy Tarreau7005b582008-11-13 17:18:59 -08006 *
Willy Tarreau698b1512008-11-22 11:29:33 +01007 * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
8 * connected to a parallel printer port.
Willy Tarreau7005b582008-11-13 17:18:59 -08009 *
Willy Tarreau698b1512008-11-22 11:29:33 +010010 * The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
11 * serial module compatible with Samsung's KS0074. The pins may be connected in
12 * any combination, everything is programmable.
Willy Tarreau7005b582008-11-13 17:18:59 -080013 *
Willy Tarreau698b1512008-11-22 11:29:33 +010014 * The keypad consists in a matrix of push buttons connecting input pins to
15 * data output pins or to the ground. The combinations have to be hard-coded
16 * in the driver, though several profiles exist and adding new ones is easy.
Willy Tarreau7005b582008-11-13 17:18:59 -080017 *
Willy Tarreau698b1512008-11-22 11:29:33 +010018 * Several profiles are provided for commonly found LCD+keypad modules on the
19 * market, such as those found in Nexcom's appliances.
Willy Tarreau7005b582008-11-13 17:18:59 -080020 *
21 * FIXME:
22 * - the initialization/deinitialization process is very dirty and should
23 * be rewritten. It may even be buggy.
24 *
25 * TODO:
26 * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
27 * - make the LCD a part of a virtual screen of Vx*Vy
28 * - make the inputs list smp-safe
29 * - change the keyboard to a double mapping : signals -> key_id -> values
30 * so that applications can change values without knowing signals
31 *
32 */
33
Toshiaki Yamane493aa892012-07-12 22:01:00 +090034#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
Willy Tarreau7005b582008-11-13 17:18:59 -080036#include <linux/module.h>
37
38#include <linux/types.h>
39#include <linux/errno.h>
40#include <linux/signal.h>
41#include <linux/sched.h>
42#include <linux/spinlock.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080043#include <linux/interrupt.h>
44#include <linux/miscdevice.h>
Willy Tarreau698b1512008-11-22 11:29:33 +010045#include <linux/slab.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080046#include <linux/ioport.h>
47#include <linux/fcntl.h>
48#include <linux/init.h>
49#include <linux/delay.h>
Andy Shevchenkod85170e2010-07-22 19:57:08 +030050#include <linux/kernel.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080051#include <linux/ctype.h>
52#include <linux/parport.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080053#include <linux/list.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080054
Willy Tarreau698b1512008-11-22 11:29:33 +010055#include <linux/io.h>
Takanori Suzuki48f658b2010-05-08 22:56:24 +090056#include <linux/uaccess.h>
Willy Tarreau7005b582008-11-13 17:18:59 -080057
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010058#include <misc/charlcd.h>
59
Willy Tarreau7005b582008-11-13 17:18:59 -080060#define KEYPAD_MINOR 185
Willy Tarreau7005b582008-11-13 17:18:59 -080061
Willy Tarreau7005b582008-11-13 17:18:59 -080062#define LCD_MAXBYTES 256 /* max burst write */
63
Willy Tarreau7005b582008-11-13 17:18:59 -080064#define KEYPAD_BUFFER 64
Willy Tarreau7005b582008-11-13 17:18:59 -080065
Henri Häkkinen429ccf02010-06-12 00:27:36 +030066/* poll the keyboard this every second */
Sirnam Swetha2b3c9eb2015-10-27 14:54:51 +053067#define INPUT_POLL_TIME (HZ / 50)
Henri Häkkinen429ccf02010-06-12 00:27:36 +030068/* a key starts to repeat after this times INPUT_POLL_TIME */
69#define KEYPAD_REP_START (10)
70/* a key repeats this times INPUT_POLL_TIME */
71#define KEYPAD_REP_DELAY (2)
72
Willy Tarreau7005b582008-11-13 17:18:59 -080073/* converts an r_str() input to an active high, bits string : 000BAOSE */
74#define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
75
Willy Tarreau698b1512008-11-22 11:29:33 +010076#define PNL_PBUSY 0x80 /* inverted input, active low */
77#define PNL_PACK 0x40 /* direct input, active low */
78#define PNL_POUTPA 0x20 /* direct input, active high */
79#define PNL_PSELECD 0x10 /* direct input, active high */
80#define PNL_PERRORP 0x08 /* direct input, active low */
Willy Tarreau7005b582008-11-13 17:18:59 -080081
Willy Tarreau698b1512008-11-22 11:29:33 +010082#define PNL_PBIDIR 0x20 /* bi-directional ports */
Henri Häkkinen429ccf02010-06-12 00:27:36 +030083/* high to read data in or-ed with data out */
84#define PNL_PINTEN 0x10
Willy Tarreau698b1512008-11-22 11:29:33 +010085#define PNL_PSELECP 0x08 /* inverted output, active low */
86#define PNL_PINITP 0x04 /* direct output, active low */
87#define PNL_PAUTOLF 0x02 /* inverted output, active low */
88#define PNL_PSTROBE 0x01 /* inverted output */
Willy Tarreau7005b582008-11-13 17:18:59 -080089
90#define PNL_PD0 0x01
91#define PNL_PD1 0x02
92#define PNL_PD2 0x04
93#define PNL_PD3 0x08
94#define PNL_PD4 0x10
95#define PNL_PD5 0x20
96#define PNL_PD6 0x40
97#define PNL_PD7 0x80
98
99#define PIN_NONE 0
100#define PIN_STROBE 1
101#define PIN_D0 2
102#define PIN_D1 3
103#define PIN_D2 4
104#define PIN_D3 5
105#define PIN_D4 6
106#define PIN_D5 7
107#define PIN_D6 8
108#define PIN_D7 9
109#define PIN_AUTOLF 14
110#define PIN_INITP 16
111#define PIN_SELECP 17
112#define PIN_NOT_SET 127
113
Mariusz Gorski36277d42014-11-27 22:36:47 +0100114#define NOT_SET -1
115
Willy Tarreau7005b582008-11-13 17:18:59 -0800116/* macros to simplify use of the parallel port */
117#define r_ctr(x) (parport_read_control((x)->port))
118#define r_dtr(x) (parport_read_data((x)->port))
119#define r_str(x) (parport_read_status((x)->port))
Toshiaki Yamane6ebb56d2012-07-25 12:18:12 +0900120#define w_ctr(x, y) (parport_write_control((x)->port, (y)))
121#define w_dtr(x, y) (parport_write_data((x)->port, (y)))
Willy Tarreau7005b582008-11-13 17:18:59 -0800122
123/* this defines which bits are to be used and which ones to be ignored */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300124/* logical or of the output bits involved in the scan matrix */
125static __u8 scan_mask_o;
126/* logical or of the input bits involved in the scan matrix */
127static __u8 scan_mask_i;
Willy Tarreau7005b582008-11-13 17:18:59 -0800128
Willy Tarreau7005b582008-11-13 17:18:59 -0800129enum input_type {
Willy Tarreau698b1512008-11-22 11:29:33 +0100130 INPUT_TYPE_STD,
131 INPUT_TYPE_KBD,
Willy Tarreau7005b582008-11-13 17:18:59 -0800132};
133
134enum input_state {
Willy Tarreau698b1512008-11-22 11:29:33 +0100135 INPUT_ST_LOW,
136 INPUT_ST_RISING,
137 INPUT_ST_HIGH,
138 INPUT_ST_FALLING,
Willy Tarreau7005b582008-11-13 17:18:59 -0800139};
140
141struct logical_input {
Willy Tarreau698b1512008-11-22 11:29:33 +0100142 struct list_head list;
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100143 __u64 mask;
144 __u64 value;
Willy Tarreau698b1512008-11-22 11:29:33 +0100145 enum input_type type;
146 enum input_state state;
147 __u8 rise_time, fall_time;
148 __u8 rise_timer, fall_timer, high_timer;
Willy Tarreau7005b582008-11-13 17:18:59 -0800149
Willy Tarreau698b1512008-11-22 11:29:33 +0100150 union {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300151 struct { /* valid when type == INPUT_TYPE_STD */
Monam Agarwal68d386b2014-02-25 19:40:49 +0530152 void (*press_fct)(int);
153 void (*release_fct)(int);
Willy Tarreau698b1512008-11-22 11:29:33 +0100154 int press_data;
155 int release_data;
156 } std;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300157 struct { /* valid when type == INPUT_TYPE_KBD */
158 /* strings can be non null-terminated */
Willy Tarreau698b1512008-11-22 11:29:33 +0100159 char press_str[sizeof(void *) + sizeof(int)];
160 char repeat_str[sizeof(void *) + sizeof(int)];
161 char release_str[sizeof(void *) + sizeof(int)];
162 } kbd;
163 } u;
Willy Tarreau7005b582008-11-13 17:18:59 -0800164};
165
Peter Huewe36d20412013-02-15 13:47:05 +0100166static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
Willy Tarreau7005b582008-11-13 17:18:59 -0800167
168/* physical contacts history
169 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
170 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
171 * corresponds to the ground.
172 * Within each group, bits are stored in the same order as read on the port :
173 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100174 * So, each __u64 is represented like this :
Willy Tarreau7005b582008-11-13 17:18:59 -0800175 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
176 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
177 */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300178
179/* what has just been read from the I/O ports */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100180static __u64 phys_read;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300181/* previous phys_read */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100182static __u64 phys_read_prev;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300183/* stabilized phys_read (phys_read|phys_read_prev) */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100184static __u64 phys_curr;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300185/* previous phys_curr */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100186static __u64 phys_prev;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300187/* 0 means that at least one logical signal needs be computed */
188static char inputs_stable;
Willy Tarreau7005b582008-11-13 17:18:59 -0800189
Willy Tarreau7005b582008-11-13 17:18:59 -0800190/* these variables are specific to the keypad */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100191static struct {
192 bool enabled;
193} keypad;
194
Willy Tarreau7005b582008-11-13 17:18:59 -0800195static char keypad_buffer[KEYPAD_BUFFER];
Willy Tarreau698b1512008-11-22 11:29:33 +0100196static int keypad_buflen;
197static int keypad_start;
198static char keypressed;
Willy Tarreau7005b582008-11-13 17:18:59 -0800199static wait_queue_head_t keypad_read_wait;
Willy Tarreau7005b582008-11-13 17:18:59 -0800200
201/* lcd-specific variables */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100202static struct {
203 bool enabled;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100204 bool initialized;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100205
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100206 int charset;
207 int proto;
Geert Uytterhoevenfda4ae12017-02-06 15:38:10 +0100208
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100209 /* TODO: use union here? */
210 struct {
211 int e;
212 int rs;
213 int rw;
214 int cl;
215 int da;
216 int bl;
217 } pins;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100218
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100219 struct charlcd *charlcd;
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100220} lcd;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300221
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100222/* Needed only for init */
223static int selected_lcd_type = NOT_SET;
224
Willy Tarreau7005b582008-11-13 17:18:59 -0800225/*
226 * Bit masks to convert LCD signals to parallel port outputs.
227 * _d_ are values for data port, _c_ are for control port.
228 * [0] = signal OFF, [1] = signal ON, [2] = mask
229 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100230#define BIT_CLR 0
231#define BIT_SET 1
232#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800233#define BIT_STATES 3
234/*
235 * one entry for each bit on the LCD
236 */
237#define LCD_BIT_E 0
238#define LCD_BIT_RS 1
239#define LCD_BIT_RW 2
240#define LCD_BIT_BL 3
241#define LCD_BIT_CL 4
242#define LCD_BIT_DA 5
243#define LCD_BITS 6
244
245/*
246 * each bit can be either connected to a DATA or CTRL port
247 */
248#define LCD_PORT_C 0
249#define LCD_PORT_D 1
250#define LCD_PORTS 2
251
252static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
253
254/*
255 * LCD protocols
256 */
257#define LCD_PROTO_PARALLEL 0
258#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400259#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800260
261/*
262 * LCD character sets
263 */
264#define LCD_CHARSET_NORMAL 0
265#define LCD_CHARSET_KS0074 1
266
267/*
268 * LCD types
269 */
270#define LCD_TYPE_NONE 0
Sudip Mukherjee2c20d922015-03-24 16:29:32 +0530271#define LCD_TYPE_CUSTOM 1
272#define LCD_TYPE_OLD 2
273#define LCD_TYPE_KS0074 3
274#define LCD_TYPE_HANTRONIX 4
275#define LCD_TYPE_NEXCOM 5
Willy Tarreau7005b582008-11-13 17:18:59 -0800276
277/*
278 * keypad types
279 */
280#define KEYPAD_TYPE_NONE 0
281#define KEYPAD_TYPE_OLD 1
282#define KEYPAD_TYPE_NEW 2
283#define KEYPAD_TYPE_NEXCOM 3
284
285/*
286 * panel profiles
287 */
288#define PANEL_PROFILE_CUSTOM 0
289#define PANEL_PROFILE_OLD 1
290#define PANEL_PROFILE_NEW 2
291#define PANEL_PROFILE_HANTRONIX 3
292#define PANEL_PROFILE_NEXCOM 4
293#define PANEL_PROFILE_LARGE 5
294
295/*
296 * Construct custom config from the kernel's configuration
297 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800298#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100299#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100300#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
301#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100302#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800303#define DEFAULT_LCD_WIDTH 40
304#define DEFAULT_LCD_BWIDTH 40
305#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100306#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800307#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
308
309#define DEFAULT_LCD_PIN_E PIN_AUTOLF
310#define DEFAULT_LCD_PIN_RS PIN_SELECP
311#define DEFAULT_LCD_PIN_RW PIN_INITP
312#define DEFAULT_LCD_PIN_SCL PIN_STROBE
313#define DEFAULT_LCD_PIN_SDA PIN_D0
314#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800315
Willy Tarreau7005b582008-11-13 17:18:59 -0800316#ifdef CONFIG_PANEL_PARPORT
317#undef DEFAULT_PARPORT
318#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
319#endif
320
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100321#ifdef CONFIG_PANEL_PROFILE
322#undef DEFAULT_PROFILE
323#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
324#endif
325
Willy Tarreau698b1512008-11-22 11:29:33 +0100326#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800327#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100328#undef DEFAULT_KEYPAD_TYPE
329#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800330#endif
331
Willy Tarreau7005b582008-11-13 17:18:59 -0800332#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100333#undef DEFAULT_LCD_TYPE
334#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800335#endif
336
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100337#ifdef CONFIG_PANEL_LCD_HEIGHT
338#undef DEFAULT_LCD_HEIGHT
339#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
340#endif
341
Willy Tarreau7005b582008-11-13 17:18:59 -0800342#ifdef CONFIG_PANEL_LCD_WIDTH
343#undef DEFAULT_LCD_WIDTH
344#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
345#endif
346
347#ifdef CONFIG_PANEL_LCD_BWIDTH
348#undef DEFAULT_LCD_BWIDTH
349#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
350#endif
351
352#ifdef CONFIG_PANEL_LCD_HWIDTH
353#undef DEFAULT_LCD_HWIDTH
354#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
355#endif
356
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100357#ifdef CONFIG_PANEL_LCD_CHARSET
358#undef DEFAULT_LCD_CHARSET
359#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800360#endif
361
362#ifdef CONFIG_PANEL_LCD_PROTO
363#undef DEFAULT_LCD_PROTO
364#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
365#endif
366
367#ifdef CONFIG_PANEL_LCD_PIN_E
368#undef DEFAULT_LCD_PIN_E
369#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
370#endif
371
372#ifdef CONFIG_PANEL_LCD_PIN_RS
373#undef DEFAULT_LCD_PIN_RS
374#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
375#endif
376
377#ifdef CONFIG_PANEL_LCD_PIN_RW
378#undef DEFAULT_LCD_PIN_RW
379#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
380#endif
381
382#ifdef CONFIG_PANEL_LCD_PIN_SCL
383#undef DEFAULT_LCD_PIN_SCL
384#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
385#endif
386
387#ifdef CONFIG_PANEL_LCD_PIN_SDA
388#undef DEFAULT_LCD_PIN_SDA
389#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
390#endif
391
392#ifdef CONFIG_PANEL_LCD_PIN_BL
393#undef DEFAULT_LCD_PIN_BL
394#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
395#endif
396
Willy Tarreau7005b582008-11-13 17:18:59 -0800397#endif /* DEFAULT_PROFILE == 0 */
398
399/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100400
401/* Device single-open policy control */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100402static atomic_t keypad_available = ATOMIC_INIT(1);
403
Willy Tarreau698b1512008-11-22 11:29:33 +0100404static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800405
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100406static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800407
Willy Tarreau698b1512008-11-22 11:29:33 +0100408static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800409static struct timer_list scan_timer;
410
Willy Tarreau630231772008-11-22 12:52:18 +0100411MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100412
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100413static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100414module_param(parport, int, 0000);
415MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100416
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100417static int profile = DEFAULT_PROFILE;
418module_param(profile, int, 0000);
419MODULE_PARM_DESC(profile,
420 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
421 "4=16x2 nexcom; default=40x2, old kp");
422
Mariusz Gorski36277d42014-11-27 22:36:47 +0100423static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100424module_param(keypad_type, int, 0000);
425MODULE_PARM_DESC(keypad_type,
426 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
427
Mariusz Gorski36277d42014-11-27 22:36:47 +0100428static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100429module_param(lcd_type, int, 0000);
430MODULE_PARM_DESC(lcd_type,
Sudip Mukherjee2c20d922015-03-24 16:29:32 +0530431 "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100432
Mariusz Gorski36277d42014-11-27 22:36:47 +0100433static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100434module_param(lcd_height, int, 0000);
435MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100436
Mariusz Gorski36277d42014-11-27 22:36:47 +0100437static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100438module_param(lcd_width, int, 0000);
439MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100440
Mariusz Gorski36277d42014-11-27 22:36:47 +0100441static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100442module_param(lcd_bwidth, int, 0000);
443MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100444
Mariusz Gorski36277d42014-11-27 22:36:47 +0100445static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100446module_param(lcd_hwidth, int, 0000);
447MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100448
Mariusz Gorski36277d42014-11-27 22:36:47 +0100449static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100450module_param(lcd_charset, int, 0000);
451MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100452
Mariusz Gorski36277d42014-11-27 22:36:47 +0100453static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100454module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300455MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200456 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100457
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100458/*
459 * These are the parallel port pins the LCD control signals are connected to.
460 * Set this to 0 if the signal is not used. Set it to its opposite value
461 * (negative) if the signal is negated. -MAXINT is used to indicate that the
462 * pin has not been explicitly specified.
463 *
Willy Tarreau630231772008-11-22 12:52:18 +0100464 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100465 */
466
467static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100468module_param(lcd_e_pin, int, 0000);
469MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530470 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100471
472static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100473module_param(lcd_rs_pin, int, 0000);
474MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530475 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100476
477static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100478module_param(lcd_rw_pin, int, 0000);
479MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530480 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100481
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100482static int lcd_cl_pin = PIN_NOT_SET;
483module_param(lcd_cl_pin, int, 0000);
484MODULE_PARM_DESC(lcd_cl_pin,
485 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100486
487static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100488module_param(lcd_da_pin, int, 0000);
489MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530490 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100491
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100492static int lcd_bl_pin = PIN_NOT_SET;
493module_param(lcd_bl_pin, int, 0000);
494MODULE_PARM_DESC(lcd_bl_pin,
495 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
496
497/* Deprecated module parameters - consider not using them anymore */
498
Mariusz Gorski36277d42014-11-27 22:36:47 +0100499static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100500module_param(lcd_enabled, int, 0000);
501MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
502
Mariusz Gorski36277d42014-11-27 22:36:47 +0100503static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100504module_param(keypad_enabled, int, 0000);
505MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
506
Willy Tarreau7005b582008-11-13 17:18:59 -0800507/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100508static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100509 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
510 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
511 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
512 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
513 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
514 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
515 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
516 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
517 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
518 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
519 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
520 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
521 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
522 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
523 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
524 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
525 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
526 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
527 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
528 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
529 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
530 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
531 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
532 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
533 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
534 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
535 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
536 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
537 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
538 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
539 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
540 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
541 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800542};
543
Peter Huewe36d20412013-02-15 13:47:05 +0100544static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100545 {"S0", "Left\n", "Left\n", ""},
546 {"S1", "Down\n", "Down\n", ""},
547 {"S2", "Up\n", "Up\n", ""},
548 {"S3", "Right\n", "Right\n", ""},
549 {"S4", "Esc\n", "Esc\n", ""},
550 {"S5", "Ret\n", "Ret\n", ""},
551 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800552};
553
554/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100555static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100556 {"S0", "Left\n", "Left\n", ""},
557 {"S1", "Down\n", "Down\n", ""},
558 {"S2", "Up\n", "Up\n", ""},
559 {"S3", "Right\n", "Right\n", ""},
560 {"S4s5", "", "Esc\n", "Esc\n"},
561 {"s4S5", "", "Ret\n", "Ret\n"},
562 {"S4S5", "Help\n", "", ""},
563 /* add new signals above this line */
564 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800565};
566
567/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100568static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100569 {"a-p-e-", "Down\n", "Down\n", ""},
570 {"a-p-E-", "Ret\n", "Ret\n", ""},
571 {"a-P-E-", "Esc\n", "Esc\n", ""},
572 {"a-P-e-", "Up\n", "Up\n", ""},
573 /* add new signals above this line */
574 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800575};
576
Peter Huewe36d20412013-02-15 13:47:05 +0100577static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800578
Daniel Chromikbea74332016-02-11 13:29:23 +0100579static DECLARE_BITMAP(bits, LCD_BITS);
580
581static void lcd_get_bits(unsigned int port, int *val)
582{
583 unsigned int bit, state;
584
585 for (bit = 0; bit < LCD_BITS; bit++) {
586 state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
587 *val &= lcd_bits[port][bit][BIT_MSK];
588 *val |= lcd_bits[port][bit][state];
589 }
590}
Willy Tarreau7005b582008-11-13 17:18:59 -0800591
Willy Tarreau7005b582008-11-13 17:18:59 -0800592/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100593static int set_data_bits(void)
594{
Daniel Chromikbea74332016-02-11 13:29:23 +0100595 int val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800596
Willy Tarreau698b1512008-11-22 11:29:33 +0100597 val = r_dtr(pprt);
Daniel Chromikbea74332016-02-11 13:29:23 +0100598 lcd_get_bits(LCD_PORT_D, &val);
Willy Tarreau698b1512008-11-22 11:29:33 +0100599 w_dtr(pprt, val);
600 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800601}
602
603/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100604static int set_ctrl_bits(void)
605{
Daniel Chromikbea74332016-02-11 13:29:23 +0100606 int val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800607
Willy Tarreau698b1512008-11-22 11:29:33 +0100608 val = r_ctr(pprt);
Daniel Chromikbea74332016-02-11 13:29:23 +0100609 lcd_get_bits(LCD_PORT_C, &val);
Willy Tarreau698b1512008-11-22 11:29:33 +0100610 w_ctr(pprt, val);
611 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800612}
613
614/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530615static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100616{
617 set_data_bits();
618 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800619}
620
621/*
622 * Converts a parallel port pin (from -25 to 25) to data and control ports
623 * masks, and data and control port bits. The signal will be considered
624 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
625 *
626 * Result will be used this way :
627 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
628 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
629 */
Peter Huewe36d20412013-02-15 13:47:05 +0100630static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100631{
632 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800633
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200634 d_val[0] = 0;
635 c_val[0] = 0;
636 d_val[1] = 0;
637 c_val[1] = 0;
638 d_val[2] = 0xFF;
639 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800640
Willy Tarreau698b1512008-11-22 11:29:33 +0100641 if (pin == 0)
642 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800643
Willy Tarreau698b1512008-11-22 11:29:33 +0100644 inv = (pin < 0);
645 if (inv)
646 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800647
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200648 d_bit = 0;
649 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800650
Willy Tarreau698b1512008-11-22 11:29:33 +0100651 switch (pin) {
652 case PIN_STROBE: /* strobe, inverted */
653 c_bit = PNL_PSTROBE;
654 inv = !inv;
655 break;
656 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
657 d_bit = 1 << (pin - 2);
658 break;
659 case PIN_AUTOLF: /* autofeed, inverted */
660 c_bit = PNL_PAUTOLF;
661 inv = !inv;
662 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300663 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100664 c_bit = PNL_PINITP;
665 break;
666 case PIN_SELECP: /* select_in, inverted */
667 c_bit = PNL_PSELECP;
668 inv = !inv;
669 break;
670 default: /* unknown pin, ignore */
671 break;
672 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800673
Willy Tarreau698b1512008-11-22 11:29:33 +0100674 if (c_bit) {
675 c_val[2] &= ~c_bit;
676 c_val[!inv] = c_bit;
677 } else if (d_bit) {
678 d_val[2] &= ~d_bit;
679 d_val[!inv] = d_bit;
680 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800681}
682
Alex Wilson881bf2812015-07-31 11:08:29 -0600683/*
684 * send a serial byte to the LCD panel. The caller is responsible for locking
685 * if needed.
686 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100687static void lcd_send_serial(int byte)
688{
689 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800690
Alex Wilson881bf2812015-07-31 11:08:29 -0600691 /*
692 * the data bit is set on D0, and the clock on STROBE.
693 * LCD reads D0 on STROBE's rising edge.
694 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100695 for (bit = 0; bit < 8; bit++) {
Daniel Chromikbea74332016-02-11 13:29:23 +0100696 clear_bit(LCD_BIT_CL, bits); /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530697 panel_set_bits();
Daniel Chromikbea74332016-02-11 13:29:23 +0100698 if (byte & 1) {
699 set_bit(LCD_BIT_DA, bits);
700 } else {
701 clear_bit(LCD_BIT_DA, bits);
702 }
703
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530704 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300705 udelay(2); /* maintain the data during 2 us before CLK up */
Daniel Chromikbea74332016-02-11 13:29:23 +0100706 set_bit(LCD_BIT_CL, bits); /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530707 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300708 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100709 byte >>= 1;
710 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800711}
712
713/* turn the backlight on or off */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100714static void lcd_backlight(struct charlcd *charlcd, int on)
Willy Tarreau698b1512008-11-22 11:29:33 +0100715{
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100716 if (lcd.pins.bl == PIN_NONE)
717 return;
718
Justin P. Mattock6975e182012-03-19 08:17:52 -0700719 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800720 spin_lock_irq(&pprt_lock);
Daniel Chromikbea74332016-02-11 13:29:23 +0100721 if (on)
722 set_bit(LCD_BIT_BL, bits);
723 else
724 clear_bit(LCD_BIT_BL, bits);
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530725 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800726 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800727}
728
729/* send a command to the LCD panel in serial mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100730static void lcd_write_cmd_s(struct charlcd *charlcd, int cmd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100731{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800732 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100733 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
734 lcd_send_serial(cmd & 0x0F);
735 lcd_send_serial((cmd >> 4) & 0x0F);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530736 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800737 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800738}
739
740/* send data to the LCD panel in serial mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100741static void lcd_write_data_s(struct charlcd *charlcd, int data)
Willy Tarreau698b1512008-11-22 11:29:33 +0100742{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800743 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100744 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
745 lcd_send_serial(data & 0x0F);
746 lcd_send_serial((data >> 4) & 0x0F);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530747 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800748 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800749}
750
751/* send a command to the LCD panel in 8 bits parallel mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100752static void lcd_write_cmd_p8(struct charlcd *charlcd, int cmd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100753{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800754 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800755 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100756 w_dtr(pprt, cmd);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530757 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800758
Daniel Chromikbea74332016-02-11 13:29:23 +0100759 set_bit(LCD_BIT_E, bits);
760 clear_bit(LCD_BIT_RS, bits);
761 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau7005b582008-11-13 17:18:59 -0800762 set_ctrl_bits();
763
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530764 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800765
Daniel Chromikbea74332016-02-11 13:29:23 +0100766 clear_bit(LCD_BIT_E, bits);
Willy Tarreau7005b582008-11-13 17:18:59 -0800767 set_ctrl_bits();
768
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530769 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800770 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100771}
Willy Tarreau7005b582008-11-13 17:18:59 -0800772
Willy Tarreau698b1512008-11-22 11:29:33 +0100773/* send data to the LCD panel in 8 bits parallel mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100774static void lcd_write_data_p8(struct charlcd *charlcd, int data)
Willy Tarreau698b1512008-11-22 11:29:33 +0100775{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800776 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100777 /* present the data to the data port */
778 w_dtr(pprt, data);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530779 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100780
Daniel Chromikbea74332016-02-11 13:29:23 +0100781 set_bit(LCD_BIT_E, bits);
782 set_bit(LCD_BIT_RS, bits);
783 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100784 set_ctrl_bits();
785
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530786 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100787
Daniel Chromikbea74332016-02-11 13:29:23 +0100788 clear_bit(LCD_BIT_E, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100789 set_ctrl_bits();
790
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530791 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800792 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100793}
794
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400795/* send a command to the TI LCD panel */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100796static void lcd_write_cmd_tilcd(struct charlcd *charlcd, int cmd)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400797{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800798 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400799 /* present the data to the control port */
800 w_ctr(pprt, cmd);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530801 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800802 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400803}
804
805/* send data to the TI LCD panel */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100806static void lcd_write_data_tilcd(struct charlcd *charlcd, int data)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400807{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800808 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400809 /* present the data to the data port */
810 w_dtr(pprt, data);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530811 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800812 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400813}
814
Willy Tarreau698b1512008-11-22 11:29:33 +0100815/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100816static void lcd_clear_fast_s(struct charlcd *charlcd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100817{
818 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200819
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800820 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100821 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100822 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
823 lcd_send_serial(' ' & 0x0F);
824 lcd_send_serial((' ' >> 4) & 0x0F);
Ricardo Ruedasdf44f152015-12-08 22:30:40 +0100825 /* the shortest data takes at least 40 us */
Greg Kroah-Hartman4cff7ad2016-02-01 12:50:26 -0800826 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100827 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800828 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100829}
830
831/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100832static void lcd_clear_fast_p8(struct charlcd *charlcd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100833{
834 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200835
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800836 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100837 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100838 /* present the data to the data port */
839 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300840
841 /* maintain the data during 20 us before the strobe */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530842 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100843
Daniel Chromikbea74332016-02-11 13:29:23 +0100844 set_bit(LCD_BIT_E, bits);
845 set_bit(LCD_BIT_RS, bits);
846 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100847 set_ctrl_bits();
848
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300849 /* maintain the strobe during 40 us */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530850 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100851
Daniel Chromikbea74332016-02-11 13:29:23 +0100852 clear_bit(LCD_BIT_E, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100853 set_ctrl_bits();
854
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300855 /* the shortest data takes at least 45 us */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530856 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100857 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800858 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800859}
860
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400861/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100862static void lcd_clear_fast_tilcd(struct charlcd *charlcd)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400863{
864 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200865
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800866 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100867 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400868 /* present the data to the data port */
869 w_dtr(pprt, ' ');
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530870 udelay(60);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400871 }
872
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800873 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400874}
875
Arvind Yadav7b948f12017-07-14 22:04:49 +0530876static const struct charlcd_ops charlcd_serial_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100877 .write_cmd = lcd_write_cmd_s,
878 .write_data = lcd_write_data_s,
879 .clear_fast = lcd_clear_fast_s,
880 .backlight = lcd_backlight,
Willy Tarreau7005b582008-11-13 17:18:59 -0800881};
882
Arvind Yadav7b948f12017-07-14 22:04:49 +0530883static const struct charlcd_ops charlcd_parallel_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100884 .write_cmd = lcd_write_cmd_p8,
885 .write_data = lcd_write_data_p8,
886 .clear_fast = lcd_clear_fast_p8,
887 .backlight = lcd_backlight,
Willy Tarreau7005b582008-11-13 17:18:59 -0800888};
889
Arvind Yadav7b948f12017-07-14 22:04:49 +0530890static const struct charlcd_ops charlcd_tilcd_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100891 .write_cmd = lcd_write_cmd_tilcd,
892 .write_data = lcd_write_data_tilcd,
893 .clear_fast = lcd_clear_fast_tilcd,
894 .backlight = lcd_backlight,
895};
Willy Tarreau7005b582008-11-13 17:18:59 -0800896
Willy Tarreau7005b582008-11-13 17:18:59 -0800897/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +0100898static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100899{
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100900 struct charlcd *charlcd;
901
902 charlcd = charlcd_alloc(0);
903 if (!charlcd)
904 return;
905
906 /*
907 * Init lcd struct with load-time values to preserve exact
908 * current functionality (at least for now).
909 */
910 charlcd->height = lcd_height;
911 charlcd->width = lcd_width;
912 charlcd->bwidth = lcd_bwidth;
913 charlcd->hwidth = lcd_hwidth;
914
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100915 switch (selected_lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300916 case LCD_TYPE_OLD:
917 /* parallel mode, 8 bits */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100918 lcd.proto = LCD_PROTO_PARALLEL;
919 lcd.charset = LCD_CHARSET_NORMAL;
920 lcd.pins.e = PIN_STROBE;
921 lcd.pins.rs = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800922
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100923 charlcd->width = 40;
924 charlcd->bwidth = 40;
925 charlcd->hwidth = 64;
926 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800927 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300928 case LCD_TYPE_KS0074:
929 /* serial mode, ks0074 */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100930 lcd.proto = LCD_PROTO_SERIAL;
931 lcd.charset = LCD_CHARSET_KS0074;
932 lcd.pins.bl = PIN_AUTOLF;
933 lcd.pins.cl = PIN_STROBE;
934 lcd.pins.da = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800935
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100936 charlcd->width = 16;
937 charlcd->bwidth = 40;
938 charlcd->hwidth = 16;
939 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800940 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300941 case LCD_TYPE_NEXCOM:
942 /* parallel mode, 8 bits, generic */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100943 lcd.proto = LCD_PROTO_PARALLEL;
944 lcd.charset = LCD_CHARSET_NORMAL;
945 lcd.pins.e = PIN_AUTOLF;
946 lcd.pins.rs = PIN_SELECP;
947 lcd.pins.rw = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -0800948
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100949 charlcd->width = 16;
950 charlcd->bwidth = 40;
951 charlcd->hwidth = 64;
952 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800953 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300954 case LCD_TYPE_CUSTOM:
955 /* customer-defined */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100956 lcd.proto = DEFAULT_LCD_PROTO;
957 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -0800958 /* default geometry will be set later */
959 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300960 case LCD_TYPE_HANTRONIX:
961 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +0100962 default:
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100963 lcd.proto = LCD_PROTO_PARALLEL;
964 lcd.charset = LCD_CHARSET_NORMAL;
965 lcd.pins.e = PIN_STROBE;
966 lcd.pins.rs = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -0800967
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100968 charlcd->width = 16;
969 charlcd->bwidth = 40;
970 charlcd->hwidth = 64;
971 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800972 break;
Willy Tarreau698b1512008-11-22 11:29:33 +0100973 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800974
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100975 /* Overwrite with module params set on loading */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100976 if (lcd_height != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100977 charlcd->height = lcd_height;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100978 if (lcd_width != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100979 charlcd->width = lcd_width;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100980 if (lcd_bwidth != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100981 charlcd->bwidth = lcd_bwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100982 if (lcd_hwidth != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100983 charlcd->hwidth = lcd_hwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100984 if (lcd_charset != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100985 lcd.charset = lcd_charset;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100986 if (lcd_proto != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100987 lcd.proto = lcd_proto;
988 if (lcd_e_pin != PIN_NOT_SET)
989 lcd.pins.e = lcd_e_pin;
990 if (lcd_rs_pin != PIN_NOT_SET)
991 lcd.pins.rs = lcd_rs_pin;
992 if (lcd_rw_pin != PIN_NOT_SET)
993 lcd.pins.rw = lcd_rw_pin;
994 if (lcd_cl_pin != PIN_NOT_SET)
995 lcd.pins.cl = lcd_cl_pin;
996 if (lcd_da_pin != PIN_NOT_SET)
997 lcd.pins.da = lcd_da_pin;
998 if (lcd_bl_pin != PIN_NOT_SET)
999 lcd.pins.bl = lcd_bl_pin;
Willy Tarreau7005b582008-11-13 17:18:59 -08001000
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001001 /* this is used to catch wrong and default values */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001002 if (charlcd->width <= 0)
1003 charlcd->width = DEFAULT_LCD_WIDTH;
1004 if (charlcd->bwidth <= 0)
1005 charlcd->bwidth = DEFAULT_LCD_BWIDTH;
1006 if (charlcd->hwidth <= 0)
1007 charlcd->hwidth = DEFAULT_LCD_HWIDTH;
1008 if (charlcd->height <= 0)
1009 charlcd->height = DEFAULT_LCD_HEIGHT;
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001010
1011 if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001012 charlcd->ops = &charlcd_serial_ops;
Willy Tarreau7005b582008-11-13 17:18:59 -08001013
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001014 if (lcd.pins.cl == PIN_NOT_SET)
1015 lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
1016 if (lcd.pins.da == PIN_NOT_SET)
1017 lcd.pins.da = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001018
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001019 } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001020 charlcd->ops = &charlcd_parallel_ops;
Willy Tarreau7005b582008-11-13 17:18:59 -08001021
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001022 if (lcd.pins.e == PIN_NOT_SET)
1023 lcd.pins.e = DEFAULT_LCD_PIN_E;
1024 if (lcd.pins.rs == PIN_NOT_SET)
1025 lcd.pins.rs = DEFAULT_LCD_PIN_RS;
1026 if (lcd.pins.rw == PIN_NOT_SET)
1027 lcd.pins.rw = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001028 } else {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001029 charlcd->ops = &charlcd_tilcd_ops;
Willy Tarreau698b1512008-11-22 11:29:33 +01001030 }
1031
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001032 if (lcd.pins.bl == PIN_NOT_SET)
1033 lcd.pins.bl = DEFAULT_LCD_PIN_BL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001034
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001035 if (lcd.pins.e == PIN_NOT_SET)
1036 lcd.pins.e = PIN_NONE;
1037 if (lcd.pins.rs == PIN_NOT_SET)
1038 lcd.pins.rs = PIN_NONE;
1039 if (lcd.pins.rw == PIN_NOT_SET)
1040 lcd.pins.rw = PIN_NONE;
1041 if (lcd.pins.bl == PIN_NOT_SET)
1042 lcd.pins.bl = PIN_NONE;
1043 if (lcd.pins.cl == PIN_NOT_SET)
1044 lcd.pins.cl = PIN_NONE;
1045 if (lcd.pins.da == PIN_NOT_SET)
1046 lcd.pins.da = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001047
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001048 if (lcd.charset == NOT_SET)
1049 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001050
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001051 if (lcd.charset == LCD_CHARSET_KS0074)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001052 charlcd->char_conv = lcd_char_conv_ks0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01001053 else
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001054 charlcd->char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001055
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001056 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
Willy Tarreau698b1512008-11-22 11:29:33 +01001057 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001058 pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
Willy Tarreau698b1512008-11-22 11:29:33 +01001059 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001060 pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
Willy Tarreau698b1512008-11-22 11:29:33 +01001061 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001062 pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001063 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001064 pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001065 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001066 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
Willy Tarreau698b1512008-11-22 11:29:33 +01001067 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001068
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001069 lcd.charlcd = charlcd;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +01001070 lcd.initialized = true;
Willy Tarreau7005b582008-11-13 17:18:59 -08001071}
1072
Willy Tarreau7005b582008-11-13 17:18:59 -08001073/*
1074 * These are the file operation function for user access to /dev/keypad
1075 */
1076
Willy Tarreau698b1512008-11-22 11:29:33 +01001077static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001078 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001079{
Willy Tarreau698b1512008-11-22 11:29:33 +01001080 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001081 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001082
Willy Tarreau698b1512008-11-22 11:29:33 +01001083 if (keypad_buflen == 0) {
1084 if (file->f_flags & O_NONBLOCK)
1085 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001086
Arnd Bergmann310df692014-01-02 13:07:35 +01001087 if (wait_event_interruptible(keypad_read_wait,
1088 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001089 return -EINTR;
1090 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001091
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001092 for (; count-- > 0 && (keypad_buflen > 0);
1093 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001094 put_user(keypad_buffer[keypad_start], tmp);
1095 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1096 }
1097 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001098
Willy Tarreau698b1512008-11-22 11:29:33 +01001099 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001100}
1101
Willy Tarreau698b1512008-11-22 11:29:33 +01001102static int keypad_open(struct inode *inode, struct file *file)
1103{
Willy Tarreau93dc1772017-09-07 15:37:30 +02001104 int ret;
Willy Tarreau7005b582008-11-13 17:18:59 -08001105
Willy Tarreau93dc1772017-09-07 15:37:30 +02001106 ret = -EBUSY;
1107 if (!atomic_dec_and_test(&keypad_available))
1108 goto fail; /* open only once at a time */
1109
1110 ret = -EPERM;
Willy Tarreau698b1512008-11-22 11:29:33 +01001111 if (file->f_mode & FMODE_WRITE) /* device is read-only */
Willy Tarreau93dc1772017-09-07 15:37:30 +02001112 goto fail;
Willy Tarreau7005b582008-11-13 17:18:59 -08001113
Willy Tarreau698b1512008-11-22 11:29:33 +01001114 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001115 return 0;
Willy Tarreau93dc1772017-09-07 15:37:30 +02001116 fail:
1117 atomic_inc(&keypad_available);
1118 return ret;
Willy Tarreau7005b582008-11-13 17:18:59 -08001119}
1120
Willy Tarreau698b1512008-11-22 11:29:33 +01001121static int keypad_release(struct inode *inode, struct file *file)
1122{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001123 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001124 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001125}
1126
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001127static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001128 .read = keypad_read, /* read */
1129 .open = keypad_open, /* open */
1130 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001131 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001132};
1133
1134static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001135 .minor = KEYPAD_MINOR,
1136 .name = "keypad",
1137 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001138};
1139
Peter Huewe36d20412013-02-15 13:47:05 +01001140static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001141{
Willy Tarreau698b1512008-11-22 11:29:33 +01001142 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001143 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001144 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1145 keypad_buffer[(keypad_start + keypad_buflen++) %
1146 KEYPAD_BUFFER] = *string++;
1147 }
1148 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001149 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001150}
1151
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001152/* this function scans all the bits involving at least one logical signal,
1153 * and puts the results in the bitfield "phys_read" (one bit per established
1154 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001155 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001156 * Note: to debounce input signals, we will only consider as switched a signal
1157 * which is stable across 2 measures. Signals which are different between two
1158 * reads will be kept as they previously were in their logical form (phys_prev).
1159 * A signal which has just switched will have a 1 in
1160 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001161 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001162static void phys_scan_contacts(void)
1163{
1164 int bit, bitval;
1165 char oldval;
1166 char bitmask;
1167 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001168
Willy Tarreau698b1512008-11-22 11:29:33 +01001169 phys_prev = phys_curr;
1170 phys_read_prev = phys_read;
1171 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001172
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001173 /* keep track of old value, with all outputs disabled */
1174 oldval = r_dtr(pprt) | scan_mask_o;
1175 /* activate all keyboard outputs (active low) */
1176 w_dtr(pprt, oldval & ~scan_mask_o);
1177
1178 /* will have a 1 for each bit set to gnd */
1179 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1180 /* disable all matrix signals */
1181 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001182
Willy Tarreau698b1512008-11-22 11:29:33 +01001183 /* now that all outputs are cleared, the only active input bits are
1184 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001185 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001186
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001187 /* 1 for each grounded input */
1188 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1189
1190 /* grounded inputs are signals 40-44 */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001191 phys_read |= (__u64)gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001192
Willy Tarreau698b1512008-11-22 11:29:33 +01001193 if (bitmask != gndmask) {
Nayeemahmed Badebade8c178932015-08-27 21:02:46 +05301194 /*
1195 * since clearing the outputs changed some inputs, we know
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001196 * that some input signals are currently tied to some outputs.
1197 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001198 */
1199 for (bit = 0; bit < 8; bit++) {
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301200 bitval = BIT(bit);
Willy Tarreau698b1512008-11-22 11:29:33 +01001201
1202 if (!(scan_mask_o & bitval)) /* skip unused bits */
1203 continue;
1204
1205 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1206 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001207 phys_read |= (__u64)bitmask << (5 * bit);
Willy Tarreau698b1512008-11-22 11:29:33 +01001208 }
1209 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001210 }
Nayeemahmed Badebade8c178932015-08-27 21:02:46 +05301211 /*
1212 * this is easy: use old bits when they are flapping,
1213 * use new ones when stable
1214 */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001215 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1216 (phys_read & ~(phys_read ^ phys_read_prev));
1217}
1218
1219static inline int input_state_high(struct logical_input *input)
1220{
1221#if 0
1222 /* FIXME:
1223 * this is an invalid test. It tries to catch
1224 * transitions from single-key to multiple-key, but
1225 * doesn't take into account the contacts polarity.
1226 * The only solution to the problem is to parse keys
1227 * from the most complex to the simplest combinations,
1228 * and mark them as 'caught' once a combination
1229 * matches, then unmatch it for all other ones.
1230 */
1231
1232 /* try to catch dangerous transitions cases :
1233 * someone adds a bit, so this signal was a false
1234 * positive resulting from a transition. We should
1235 * invalidate the signal immediately and not call the
1236 * release function.
1237 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1238 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001239 if (((phys_prev & input->mask) == input->value) &&
1240 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001241 input->state = INPUT_ST_LOW; /* invalidate */
1242 return 1;
1243 }
1244#endif
1245
1246 if ((phys_curr & input->mask) == input->value) {
1247 if ((input->type == INPUT_TYPE_STD) &&
1248 (input->high_timer == 0)) {
1249 input->high_timer++;
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001250 if (input->u.std.press_fct)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001251 input->u.std.press_fct(input->u.std.press_data);
1252 } else if (input->type == INPUT_TYPE_KBD) {
1253 /* will turn on the light */
1254 keypressed = 1;
1255
1256 if (input->high_timer == 0) {
1257 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001258
Jake Champline6626de2013-05-04 11:21:17 -04001259 if (press_str[0]) {
1260 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001261
Jake Champline6626de2013-05-04 11:21:17 -04001262 keypad_send_key(press_str, s);
1263 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001264 }
1265
1266 if (input->u.kbd.repeat_str[0]) {
1267 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001268
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001269 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001270 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001271
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001272 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001273 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001274 }
1275 /* we will need to come back here soon */
1276 inputs_stable = 0;
1277 }
1278
1279 if (input->high_timer < 255)
1280 input->high_timer++;
1281 }
1282 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001283 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001284
1285 /* else signal falling down. Let's fall through. */
1286 input->state = INPUT_ST_FALLING;
1287 input->fall_timer = 0;
1288
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001289 return 0;
1290}
1291
1292static inline void input_state_falling(struct logical_input *input)
1293{
1294#if 0
1295 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001296 if (((phys_prev & input->mask) == input->value) &&
1297 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001298 input->state = INPUT_ST_LOW; /* invalidate */
1299 return;
1300 }
1301#endif
1302
1303 if ((phys_curr & input->mask) == input->value) {
1304 if (input->type == INPUT_TYPE_KBD) {
1305 /* will turn on the light */
1306 keypressed = 1;
1307
1308 if (input->u.kbd.repeat_str[0]) {
1309 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001310
Jake Champline6626de2013-05-04 11:21:17 -04001311 if (input->high_timer >= KEYPAD_REP_START) {
1312 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001313
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001314 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001315 keypad_send_key(repeat_str, s);
1316 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001317 /* we will need to come back here soon */
1318 inputs_stable = 0;
1319 }
1320
1321 if (input->high_timer < 255)
1322 input->high_timer++;
1323 }
1324 input->state = INPUT_ST_HIGH;
1325 } else if (input->fall_timer >= input->fall_time) {
1326 /* call release event */
1327 if (input->type == INPUT_TYPE_STD) {
1328 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001329
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001330 if (release_fct)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001331 release_fct(input->u.std.release_data);
1332 } else if (input->type == INPUT_TYPE_KBD) {
1333 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001334
Jake Champline6626de2013-05-04 11:21:17 -04001335 if (release_str[0]) {
1336 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001337
Jake Champline6626de2013-05-04 11:21:17 -04001338 keypad_send_key(release_str, s);
1339 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001340 }
1341
1342 input->state = INPUT_ST_LOW;
1343 } else {
1344 input->fall_timer++;
1345 inputs_stable = 0;
1346 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001347}
1348
Willy Tarreau698b1512008-11-22 11:29:33 +01001349static void panel_process_inputs(void)
1350{
Willy Tarreau698b1512008-11-22 11:29:33 +01001351 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001352
Willy Tarreau698b1512008-11-22 11:29:33 +01001353 keypressed = 0;
1354 inputs_stable = 1;
Wei Yongjun4654bdb2017-04-25 16:13:34 +00001355 list_for_each_entry(input, &logical_inputs, list) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001356 switch (input->state) {
1357 case INPUT_ST_LOW:
1358 if ((phys_curr & input->mask) != input->value)
1359 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001360 /* if all needed ones were already set previously,
1361 * this means that this logical signal has been
1362 * activated by the releasing of another combined
1363 * signal, so we don't want to match.
1364 * eg: AB -(release B)-> A -(release A)-> 0 :
1365 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001366 */
1367 if ((phys_prev & input->mask) == input->value)
1368 break;
1369 input->rise_timer = 0;
1370 input->state = INPUT_ST_RISING;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001371 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001372 case INPUT_ST_RISING:
1373 if ((phys_curr & input->mask) != input->value) {
1374 input->state = INPUT_ST_LOW;
1375 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001376 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001377 if (input->rise_timer < input->rise_time) {
1378 inputs_stable = 0;
1379 input->rise_timer++;
1380 break;
1381 }
1382 input->high_timer = 0;
1383 input->state = INPUT_ST_HIGH;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001384 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001385 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001386 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001387 break;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001388 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001389 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001390 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001391 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001392 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001393}
1394
Kees Cook607a6302017-10-19 14:08:22 -07001395static void panel_scan_timer(struct timer_list *unused)
Willy Tarreau698b1512008-11-22 11:29:33 +01001396{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001397 if (keypad.enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001398 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001399 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001400
1401 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001402 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001403 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001404
Willy Tarreau698b1512008-11-22 11:29:33 +01001405 if (!inputs_stable || phys_curr != phys_prev)
1406 panel_process_inputs();
1407 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001408
Geert Uytterhoevenfda4ae12017-02-06 15:38:10 +01001409 if (keypressed && lcd.enabled && lcd.initialized)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001410 charlcd_poke(lcd.charlcd);
Willy Tarreau7005b582008-11-13 17:18:59 -08001411
Willy Tarreau698b1512008-11-22 11:29:33 +01001412 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001413}
1414
Willy Tarreau698b1512008-11-22 11:29:33 +01001415static void init_scan_timer(void)
1416{
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001417 if (scan_timer.function)
Willy Tarreau698b1512008-11-22 11:29:33 +01001418 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001419
Kees Cook607a6302017-10-19 14:08:22 -07001420 timer_setup(&scan_timer, panel_scan_timer, 0);
Willy Tarreau698b1512008-11-22 11:29:33 +01001421 scan_timer.expires = jiffies + INPUT_POLL_TIME;
Willy Tarreau698b1512008-11-22 11:29:33 +01001422 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001423}
1424
1425/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001426 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1427 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001428 * returns 1 if ok, 0 if error (in which case, nothing is written).
1429 */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001430static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
Ksenija Stanojevicd938e1e2016-01-03 20:39:49 +01001431 u8 *imask, u8 *omask)
Willy Tarreau698b1512008-11-22 11:29:33 +01001432{
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001433 const char sigtab[] = "EeSsPpAaBb";
Ksenija Stanojevicd938e1e2016-01-03 20:39:49 +01001434 u8 im, om;
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001435 __u64 m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001436
Ksenija Stanojevicd12f27e2016-01-03 20:42:26 +01001437 om = 0;
1438 im = 0;
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001439 m = 0ULL;
1440 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001441 while (*name) {
1442 int in, out, bit, neg;
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001443 const char *idx;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001444
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001445 idx = strchr(sigtab, *name);
1446 if (!idx)
Willy Tarreau698b1512008-11-22 11:29:33 +01001447 return 0; /* input name not found */
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001448
1449 in = idx - sigtab;
Willy Tarreau698b1512008-11-22 11:29:33 +01001450 neg = (in & 1); /* odd (lower) names are negated */
1451 in >>= 1;
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301452 im |= BIT(in);
Willy Tarreau7005b582008-11-13 17:18:59 -08001453
Willy Tarreau698b1512008-11-22 11:29:33 +01001454 name++;
Ksenija Stanojevic52ebf932016-01-03 20:43:27 +01001455 if (*name >= '0' && *name <= '7') {
Willy Tarreau698b1512008-11-22 11:29:33 +01001456 out = *name - '0';
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301457 om |= BIT(out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001458 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01001459 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001460 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01001461 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001462 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001463
1464 bit = (out * 5) + in;
1465
1466 m |= 1ULL << bit;
1467 if (!neg)
1468 v |= 1ULL << bit;
1469 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08001470 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001471 *mask = m;
1472 *value = v;
1473 if (imask)
1474 *imask |= im;
1475 if (omask)
1476 *omask |= om;
1477 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001478}
1479
1480/* tries to bind a key to the signal name <name>. The key will send the
1481 * strings <press>, <repeat>, <release> for these respective events.
1482 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
1483 */
Peter Huewe36d20412013-02-15 13:47:05 +01001484static struct logical_input *panel_bind_key(const char *name, const char *press,
1485 const char *repeat,
1486 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01001487{
1488 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08001489
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001490 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001491 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01001492 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001493
Willy Tarreau698b1512008-11-22 11:29:33 +01001494 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04001495 &scan_mask_o)) {
1496 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01001497 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04001498 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001499
1500 key->type = INPUT_TYPE_KBD;
1501 key->state = INPUT_ST_LOW;
1502 key->rise_time = 1;
1503 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001504
Willy Tarreau698b1512008-11-22 11:29:33 +01001505 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1506 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1507 strncpy(key->u.kbd.release_str, release,
1508 sizeof(key->u.kbd.release_str));
1509 list_add(&key->list, &logical_inputs);
1510 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08001511}
1512
Willy Tarreau630231772008-11-22 12:52:18 +01001513#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08001514/* tries to bind a callback function to the signal name <name>. The function
1515 * <press_fct> will be called with the <press_data> arg when the signal is
1516 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001517 * Returns the pointer to the new signal if ok, NULL if the signal could not
1518 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08001519 */
1520static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05301521 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01001522 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05301523 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01001524 int release_data)
1525{
1526 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08001527
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001528 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001529 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01001530 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001531
Willy Tarreau698b1512008-11-22 11:29:33 +01001532 memset(callback, 0, sizeof(struct logical_input));
1533 if (!input_name2mask(name, &callback->mask, &callback->value,
1534 &scan_mask_i, &scan_mask_o))
1535 return NULL;
1536
1537 callback->type = INPUT_TYPE_STD;
1538 callback->state = INPUT_ST_LOW;
1539 callback->rise_time = 1;
1540 callback->fall_time = 1;
1541 callback->u.std.press_fct = press_fct;
1542 callback->u.std.press_data = press_data;
1543 callback->u.std.release_fct = release_fct;
1544 callback->u.std.release_data = release_data;
1545 list_add(&callback->list, &logical_inputs);
1546 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08001547}
Willy Tarreau630231772008-11-22 12:52:18 +01001548#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08001549
Willy Tarreau698b1512008-11-22 11:29:33 +01001550static void keypad_init(void)
1551{
1552 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001553
Willy Tarreau698b1512008-11-22 11:29:33 +01001554 init_waitqueue_head(&keypad_read_wait);
1555 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08001556
Willy Tarreau698b1512008-11-22 11:29:33 +01001557 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08001558
Willy Tarreau698b1512008-11-22 11:29:33 +01001559 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
1560 panel_bind_key(keypad_profile[keynum][0],
1561 keypad_profile[keynum][1],
1562 keypad_profile[keynum][2],
1563 keypad_profile[keynum][3]);
1564 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001565
Willy Tarreau698b1512008-11-22 11:29:33 +01001566 init_scan_timer();
1567 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001568}
1569
Willy Tarreau7005b582008-11-13 17:18:59 -08001570/**************************************************/
1571/* device initialization */
1572/**************************************************/
1573
Willy Tarreau698b1512008-11-22 11:29:33 +01001574static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08001575{
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301576 struct pardev_cb panel_cb;
1577
Willy Tarreau698b1512008-11-22 11:29:33 +01001578 if (port->number != parport)
1579 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001580
Willy Tarreau698b1512008-11-22 11:29:33 +01001581 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001582 pr_err("%s: port->number=%d parport=%d, already registered!\n",
1583 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01001584 return;
1585 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001586
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301587 memset(&panel_cb, 0, sizeof(panel_cb));
1588 panel_cb.private = &pprt;
1589 /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
1590
1591 pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001592 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001593 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
1594 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001595 return;
1596 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001597
Willy Tarreau698b1512008-11-22 11:29:33 +01001598 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001599 pr_err("could not claim access to parport%d. Aborting.\n",
1600 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001601 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01001602 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001603
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001604 /* must init LCD first, just in case an IRQ from the keypad is
1605 * generated at keypad init
1606 */
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001607 if (lcd.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001608 lcd_init();
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001609 if (!lcd.charlcd || charlcd_register(lcd.charlcd))
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001610 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01001611 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001612
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001613 if (keypad.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001614 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001615 if (misc_register(&keypad_dev))
1616 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01001617 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001618 return;
1619
1620err_lcd_unreg:
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001621 if (lcd.enabled)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001622 charlcd_unregister(lcd.charlcd);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001623err_unreg_device:
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001624 kfree(lcd.charlcd);
1625 lcd.charlcd = NULL;
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001626 parport_unregister_device(pprt);
1627 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001628}
1629
Willy Tarreau698b1512008-11-22 11:29:33 +01001630static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08001631{
Willy Tarreau698b1512008-11-22 11:29:33 +01001632 if (port->number != parport)
1633 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001634
Willy Tarreau698b1512008-11-22 11:29:33 +01001635 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001636 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
1637 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01001638 return;
1639 }
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001640 if (scan_timer.function)
Sudip Mukherjee7d98c632015-05-12 17:36:08 +05301641 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001642
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001643 if (keypad.enabled) {
1644 misc_deregister(&keypad_dev);
1645 keypad_initialized = 0;
Peter Huewe0b0595b2009-09-29 01:22:40 +02001646 }
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001647
1648 if (lcd.enabled) {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001649 charlcd_unregister(lcd.charlcd);
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001650 lcd.initialized = false;
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001651 kfree(lcd.charlcd);
1652 lcd.charlcd = NULL;
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001653 }
1654
1655 /* TODO: free all input signals */
1656 parport_release(pprt);
1657 parport_unregister_device(pprt);
1658 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001659}
1660
1661static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001662 .name = "panel",
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301663 .match_port = panel_attach,
Willy Tarreau698b1512008-11-22 11:29:33 +01001664 .detach = panel_detach,
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301665 .devmodel = true,
Willy Tarreau7005b582008-11-13 17:18:59 -08001666};
1667
1668/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01001669static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001670{
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301671 int selected_keypad_type = NOT_SET, err;
Willy Tarreau7005b582008-11-13 17:18:59 -08001672
Willy Tarreau698b1512008-11-22 11:29:33 +01001673 /* take care of an eventual profile */
1674 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001675 case PANEL_PROFILE_CUSTOM:
1676 /* custom profile */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001677 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
1678 selected_lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01001679 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001680 case PANEL_PROFILE_OLD:
1681 /* 8 bits, 2*16, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001682 selected_keypad_type = KEYPAD_TYPE_OLD;
1683 selected_lcd_type = LCD_TYPE_OLD;
1684
1685 /* TODO: This two are a little hacky, sort it out later */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001686 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001687 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001688 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001689 lcd_hwidth = 16;
1690 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001691 case PANEL_PROFILE_NEW:
1692 /* serial, 2*16, new keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001693 selected_keypad_type = KEYPAD_TYPE_NEW;
1694 selected_lcd_type = LCD_TYPE_KS0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01001695 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001696 case PANEL_PROFILE_HANTRONIX:
1697 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001698 selected_keypad_type = KEYPAD_TYPE_NONE;
1699 selected_lcd_type = LCD_TYPE_HANTRONIX;
Willy Tarreau698b1512008-11-22 11:29:33 +01001700 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001701 case PANEL_PROFILE_NEXCOM:
1702 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001703 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
1704 selected_lcd_type = LCD_TYPE_NEXCOM;
Willy Tarreau698b1512008-11-22 11:29:33 +01001705 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001706 case PANEL_PROFILE_LARGE:
1707 /* 8 bits, 2*40, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001708 selected_keypad_type = KEYPAD_TYPE_OLD;
1709 selected_lcd_type = LCD_TYPE_OLD;
Willy Tarreau698b1512008-11-22 11:29:33 +01001710 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001711 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001712
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001713 /*
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001714 * Overwrite selection with module param values (both keypad and lcd),
1715 * where the deprecated params have lower prio.
1716 */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001717 if (keypad_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001718 selected_keypad_type = keypad_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001719 if (keypad_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001720 selected_keypad_type = keypad_type;
Willy Tarreau7005b582008-11-13 17:18:59 -08001721
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001722 keypad.enabled = (selected_keypad_type > 0);
1723
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001724 if (lcd_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001725 selected_lcd_type = lcd_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001726 if (lcd_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001727 selected_lcd_type = lcd_type;
1728
1729 lcd.enabled = (selected_lcd_type > 0);
1730
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301731 if (lcd.enabled) {
1732 /*
1733 * Init lcd struct with load-time values to preserve exact
1734 * current functionality (at least for now).
1735 */
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301736 lcd.charset = lcd_charset;
1737 lcd.proto = lcd_proto;
1738 lcd.pins.e = lcd_e_pin;
1739 lcd.pins.rs = lcd_rs_pin;
1740 lcd.pins.rw = lcd_rw_pin;
1741 lcd.pins.cl = lcd_cl_pin;
1742 lcd.pins.da = lcd_da_pin;
1743 lcd.pins.bl = lcd_bl_pin;
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301744 }
1745
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001746 switch (selected_keypad_type) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001747 case KEYPAD_TYPE_OLD:
1748 keypad_profile = old_keypad_profile;
1749 break;
1750 case KEYPAD_TYPE_NEW:
1751 keypad_profile = new_keypad_profile;
1752 break;
1753 case KEYPAD_TYPE_NEXCOM:
1754 keypad_profile = nexcom_keypad_profile;
1755 break;
1756 default:
1757 keypad_profile = NULL;
1758 break;
1759 }
1760
Sudip Mukherjeef43de772015-02-10 17:26:02 +05301761 if (!lcd.enabled && !keypad.enabled) {
1762 /* no device enabled, let's exit */
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001763 pr_err("panel driver disabled.\n");
Sudip Mukherjeef43de772015-02-10 17:26:02 +05301764 return -ENODEV;
1765 }
1766
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301767 err = parport_register_driver(&panel_driver);
1768 if (err) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001769 pr_err("could not register with parport. Aborting.\n");
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301770 return err;
Willy Tarreau698b1512008-11-22 11:29:33 +01001771 }
1772
Willy Tarreau698b1512008-11-22 11:29:33 +01001773 if (pprt)
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001774 pr_info("panel driver registered on parport%d (io=0x%lx).\n",
1775 parport, pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01001776 else
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001777 pr_info("panel driver not yet registered\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01001778 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001779}
1780
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01001781static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001782{
Willy Tarreau698b1512008-11-22 11:29:33 +01001783 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08001784}
Willy Tarreau7005b582008-11-13 17:18:59 -08001785
Willy Tarreau7005b582008-11-13 17:18:59 -08001786module_init(panel_init_module);
1787module_exit(panel_cleanup_module);
1788MODULE_AUTHOR("Willy Tarreau");
1789MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08001790
1791/*
1792 * Local variables:
1793 * c-indent-level: 4
1794 * tab-width: 8
1795 * End:
1796 */