blob: 85965953683e4cf78e58081c1f8eb17107a74df1 [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
Masahiro Yamada75354282019-08-06 16:14:44 +090058#include "charlcd.h"
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +010059
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 */
Miguel Ojeda98cade02018-08-14 21:38:26 +0200158 char press_str[sizeof(void *) + sizeof(int)] __nonstring;
159 char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
160 char release_str[sizeof(void *) + sizeof(int)] __nonstring;
Willy Tarreau698b1512008-11-22 11:29:33 +0100161 } kbd;
162 } u;
Willy Tarreau7005b582008-11-13 17:18:59 -0800163};
164
Peter Huewe36d20412013-02-15 13:47:05 +0100165static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
Willy Tarreau7005b582008-11-13 17:18:59 -0800166
167/* physical contacts history
168 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
169 * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
170 * corresponds to the ground.
171 * Within each group, bits are stored in the same order as read on the port :
172 * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100173 * So, each __u64 is represented like this :
Willy Tarreau7005b582008-11-13 17:18:59 -0800174 * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
175 * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
176 */
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300177
178/* what has just been read from the I/O ports */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100179static __u64 phys_read;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300180/* previous phys_read */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100181static __u64 phys_read_prev;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300182/* stabilized phys_read (phys_read|phys_read_prev) */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100183static __u64 phys_curr;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300184/* previous phys_curr */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +0100185static __u64 phys_prev;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300186/* 0 means that at least one logical signal needs be computed */
187static char inputs_stable;
Willy Tarreau7005b582008-11-13 17:18:59 -0800188
Willy Tarreau7005b582008-11-13 17:18:59 -0800189/* these variables are specific to the keypad */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100190static struct {
191 bool enabled;
192} keypad;
193
Willy Tarreau7005b582008-11-13 17:18:59 -0800194static char keypad_buffer[KEYPAD_BUFFER];
Willy Tarreau698b1512008-11-22 11:29:33 +0100195static int keypad_buflen;
196static int keypad_start;
197static char keypressed;
Willy Tarreau7005b582008-11-13 17:18:59 -0800198static wait_queue_head_t keypad_read_wait;
Willy Tarreau7005b582008-11-13 17:18:59 -0800199
200/* lcd-specific variables */
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100201static struct {
202 bool enabled;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100203 bool initialized;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100204
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100205 int charset;
206 int proto;
Geert Uytterhoevenfda4ae12017-02-06 15:38:10 +0100207
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100208 /* TODO: use union here? */
209 struct {
210 int e;
211 int rs;
212 int rw;
213 int cl;
214 int da;
215 int bl;
216 } pins;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +0100217
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100218 struct charlcd *charlcd;
Mariusz Gorskia8b25802014-11-27 22:36:49 +0100219} lcd;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300220
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100221/* Needed only for init */
222static int selected_lcd_type = NOT_SET;
223
Willy Tarreau7005b582008-11-13 17:18:59 -0800224/*
225 * Bit masks to convert LCD signals to parallel port outputs.
226 * _d_ are values for data port, _c_ are for control port.
227 * [0] = signal OFF, [1] = signal ON, [2] = mask
228 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100229#define BIT_CLR 0
230#define BIT_SET 1
231#define BIT_MSK 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800232#define BIT_STATES 3
233/*
234 * one entry for each bit on the LCD
235 */
236#define LCD_BIT_E 0
237#define LCD_BIT_RS 1
238#define LCD_BIT_RW 2
239#define LCD_BIT_BL 3
240#define LCD_BIT_CL 4
241#define LCD_BIT_DA 5
242#define LCD_BITS 6
243
244/*
245 * each bit can be either connected to a DATA or CTRL port
246 */
247#define LCD_PORT_C 0
248#define LCD_PORT_D 1
249#define LCD_PORTS 2
250
251static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
252
253/*
254 * LCD protocols
255 */
256#define LCD_PROTO_PARALLEL 0
257#define LCD_PROTO_SERIAL 1
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400258#define LCD_PROTO_TI_DA8XX_LCD 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800259
260/*
261 * LCD character sets
262 */
263#define LCD_CHARSET_NORMAL 0
264#define LCD_CHARSET_KS0074 1
265
266/*
267 * LCD types
268 */
269#define LCD_TYPE_NONE 0
Sudip Mukherjee2c20d922015-03-24 16:29:32 +0530270#define LCD_TYPE_CUSTOM 1
271#define LCD_TYPE_OLD 2
272#define LCD_TYPE_KS0074 3
273#define LCD_TYPE_HANTRONIX 4
274#define LCD_TYPE_NEXCOM 5
Willy Tarreau7005b582008-11-13 17:18:59 -0800275
276/*
277 * keypad types
278 */
279#define KEYPAD_TYPE_NONE 0
280#define KEYPAD_TYPE_OLD 1
281#define KEYPAD_TYPE_NEW 2
282#define KEYPAD_TYPE_NEXCOM 3
283
284/*
285 * panel profiles
286 */
287#define PANEL_PROFILE_CUSTOM 0
288#define PANEL_PROFILE_OLD 1
289#define PANEL_PROFILE_NEW 2
290#define PANEL_PROFILE_HANTRONIX 3
291#define PANEL_PROFILE_NEXCOM 4
292#define PANEL_PROFILE_LARGE 5
293
294/*
295 * Construct custom config from the kernel's configuration
296 */
Willy Tarreau7005b582008-11-13 17:18:59 -0800297#define DEFAULT_PARPORT 0
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100298#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100299#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
300#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100301#define DEFAULT_LCD_HEIGHT 2
Willy Tarreau7005b582008-11-13 17:18:59 -0800302#define DEFAULT_LCD_WIDTH 40
303#define DEFAULT_LCD_BWIDTH 40
304#define DEFAULT_LCD_HWIDTH 64
Mariusz Gorskife4d7e22014-11-12 02:08:06 +0100305#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
Willy Tarreau7005b582008-11-13 17:18:59 -0800306#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
307
308#define DEFAULT_LCD_PIN_E PIN_AUTOLF
309#define DEFAULT_LCD_PIN_RS PIN_SELECP
310#define DEFAULT_LCD_PIN_RW PIN_INITP
311#define DEFAULT_LCD_PIN_SCL PIN_STROBE
312#define DEFAULT_LCD_PIN_SDA PIN_D0
313#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
Willy Tarreau7005b582008-11-13 17:18:59 -0800314
Willy Tarreau7005b582008-11-13 17:18:59 -0800315#ifdef CONFIG_PANEL_PARPORT
316#undef DEFAULT_PARPORT
317#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
318#endif
319
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100320#ifdef CONFIG_PANEL_PROFILE
321#undef DEFAULT_PROFILE
322#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
323#endif
324
Willy Tarreau698b1512008-11-22 11:29:33 +0100325#if DEFAULT_PROFILE == 0 /* custom */
Willy Tarreau7005b582008-11-13 17:18:59 -0800326#ifdef CONFIG_PANEL_KEYPAD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100327#undef DEFAULT_KEYPAD_TYPE
328#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
Willy Tarreau7005b582008-11-13 17:18:59 -0800329#endif
330
Willy Tarreau7005b582008-11-13 17:18:59 -0800331#ifdef CONFIG_PANEL_LCD
Mariusz Gorski98fac3d2014-11-12 02:08:09 +0100332#undef DEFAULT_LCD_TYPE
333#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
Willy Tarreau7005b582008-11-13 17:18:59 -0800334#endif
335
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100336#ifdef CONFIG_PANEL_LCD_HEIGHT
337#undef DEFAULT_LCD_HEIGHT
338#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
339#endif
340
Willy Tarreau7005b582008-11-13 17:18:59 -0800341#ifdef CONFIG_PANEL_LCD_WIDTH
342#undef DEFAULT_LCD_WIDTH
343#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
344#endif
345
346#ifdef CONFIG_PANEL_LCD_BWIDTH
347#undef DEFAULT_LCD_BWIDTH
348#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
349#endif
350
351#ifdef CONFIG_PANEL_LCD_HWIDTH
352#undef DEFAULT_LCD_HWIDTH
353#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
354#endif
355
Mariusz Gorski1e13e8a2014-11-12 02:08:07 +0100356#ifdef CONFIG_PANEL_LCD_CHARSET
357#undef DEFAULT_LCD_CHARSET
358#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
Willy Tarreau7005b582008-11-13 17:18:59 -0800359#endif
360
361#ifdef CONFIG_PANEL_LCD_PROTO
362#undef DEFAULT_LCD_PROTO
363#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
364#endif
365
366#ifdef CONFIG_PANEL_LCD_PIN_E
367#undef DEFAULT_LCD_PIN_E
368#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
369#endif
370
371#ifdef CONFIG_PANEL_LCD_PIN_RS
372#undef DEFAULT_LCD_PIN_RS
373#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
374#endif
375
376#ifdef CONFIG_PANEL_LCD_PIN_RW
377#undef DEFAULT_LCD_PIN_RW
378#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
379#endif
380
381#ifdef CONFIG_PANEL_LCD_PIN_SCL
382#undef DEFAULT_LCD_PIN_SCL
383#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
384#endif
385
386#ifdef CONFIG_PANEL_LCD_PIN_SDA
387#undef DEFAULT_LCD_PIN_SDA
388#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
389#endif
390
391#ifdef CONFIG_PANEL_LCD_PIN_BL
392#undef DEFAULT_LCD_PIN_BL
393#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
394#endif
395
Willy Tarreau7005b582008-11-13 17:18:59 -0800396#endif /* DEFAULT_PROFILE == 0 */
397
398/* global variables */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100399
400/* Device single-open policy control */
Mariusz Gorskif4757af2014-11-04 22:47:19 +0100401static atomic_t keypad_available = ATOMIC_INIT(1);
402
Willy Tarreau698b1512008-11-22 11:29:33 +0100403static struct pardevice *pprt;
Willy Tarreau7005b582008-11-13 17:18:59 -0800404
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100405static int keypad_initialized;
Willy Tarreau7005b582008-11-13 17:18:59 -0800406
Willy Tarreau698b1512008-11-22 11:29:33 +0100407static DEFINE_SPINLOCK(pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800408static struct timer_list scan_timer;
409
Willy Tarreau630231772008-11-22 12:52:18 +0100410MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100411
Mariusz Gorski59a66a22014-11-27 22:36:45 +0100412static int parport = DEFAULT_PARPORT;
Willy Tarreau698b1512008-11-22 11:29:33 +0100413module_param(parport, int, 0000);
414MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100415
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100416static int profile = DEFAULT_PROFILE;
417module_param(profile, int, 0000);
418MODULE_PARM_DESC(profile,
419 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
420 "4=16x2 nexcom; default=40x2, old kp");
421
Mariusz Gorski36277d42014-11-27 22:36:47 +0100422static int keypad_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100423module_param(keypad_type, int, 0000);
424MODULE_PARM_DESC(keypad_type,
425 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
426
Mariusz Gorski36277d42014-11-27 22:36:47 +0100427static int lcd_type = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100428module_param(lcd_type, int, 0000);
429MODULE_PARM_DESC(lcd_type,
Sudip Mukherjee2c20d922015-03-24 16:29:32 +0530430 "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100431
Mariusz Gorski36277d42014-11-27 22:36:47 +0100432static int lcd_height = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100433module_param(lcd_height, int, 0000);
434MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100435
Mariusz Gorski36277d42014-11-27 22:36:47 +0100436static int lcd_width = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100437module_param(lcd_width, int, 0000);
438MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100439
Mariusz Gorski36277d42014-11-27 22:36:47 +0100440static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100441module_param(lcd_bwidth, int, 0000);
442MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100443
Mariusz Gorski36277d42014-11-27 22:36:47 +0100444static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
Willy Tarreau698b1512008-11-22 11:29:33 +0100445module_param(lcd_hwidth, int, 0000);
446MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100447
Mariusz Gorski36277d42014-11-27 22:36:47 +0100448static int lcd_charset = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100449module_param(lcd_charset, int, 0000);
450MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100451
Mariusz Gorski36277d42014-11-27 22:36:47 +0100452static int lcd_proto = NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100453module_param(lcd_proto, int, 0000);
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300454MODULE_PARM_DESC(lcd_proto,
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +0200455 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100456
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100457/*
458 * These are the parallel port pins the LCD control signals are connected to.
459 * Set this to 0 if the signal is not used. Set it to its opposite value
460 * (negative) if the signal is negated. -MAXINT is used to indicate that the
461 * pin has not been explicitly specified.
462 *
Willy Tarreau630231772008-11-22 12:52:18 +0100463 * WARNING! no check will be performed about collisions with keypad !
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100464 */
465
466static int lcd_e_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100467module_param(lcd_e_pin, int, 0000);
468MODULE_PARM_DESC(lcd_e_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530469 "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100470
471static int lcd_rs_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100472module_param(lcd_rs_pin, int, 0000);
473MODULE_PARM_DESC(lcd_rs_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530474 "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100475
476static int lcd_rw_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100477module_param(lcd_rw_pin, int, 0000);
478MODULE_PARM_DESC(lcd_rw_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530479 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100480
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100481static int lcd_cl_pin = PIN_NOT_SET;
482module_param(lcd_cl_pin, int, 0000);
483MODULE_PARM_DESC(lcd_cl_pin,
484 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100485
486static int lcd_da_pin = PIN_NOT_SET;
Willy Tarreau698b1512008-11-22 11:29:33 +0100487module_param(lcd_da_pin, int, 0000);
488MODULE_PARM_DESC(lcd_da_pin,
Monam Agarwalfe5d2e02014-02-25 19:42:46 +0530489 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +0100490
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100491static int lcd_bl_pin = PIN_NOT_SET;
492module_param(lcd_bl_pin, int, 0000);
493MODULE_PARM_DESC(lcd_bl_pin,
494 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
495
496/* Deprecated module parameters - consider not using them anymore */
497
Mariusz Gorski36277d42014-11-27 22:36:47 +0100498static int lcd_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100499module_param(lcd_enabled, int, 0000);
500MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
501
Mariusz Gorski36277d42014-11-27 22:36:47 +0100502static int keypad_enabled = NOT_SET;
Mariusz Gorski98e0e762014-11-12 02:08:08 +0100503module_param(keypad_enabled, int, 0000);
504MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
505
Willy Tarreau7005b582008-11-13 17:18:59 -0800506/* for some LCD drivers (ks0074) we need a charset conversion table. */
Peter Huewe36d20412013-02-15 13:47:05 +0100507static const unsigned char lcd_char_conv_ks0074[256] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100508 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
509 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
510 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
511 /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
512 /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
513 /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
514 /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
515 /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
516 /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
517 /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
518 /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
519 /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
520 /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
521 /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
522 /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
523 /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
524 /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
525 /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
526 /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
527 /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
528 /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
529 /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
530 /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
531 /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
532 /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
533 /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
534 /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
535 /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
536 /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
537 /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
538 /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
539 /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
540 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
Willy Tarreau7005b582008-11-13 17:18:59 -0800541};
542
Peter Huewe36d20412013-02-15 13:47:05 +0100543static const char old_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100544 {"S0", "Left\n", "Left\n", ""},
545 {"S1", "Down\n", "Down\n", ""},
546 {"S2", "Up\n", "Up\n", ""},
547 {"S3", "Right\n", "Right\n", ""},
548 {"S4", "Esc\n", "Esc\n", ""},
549 {"S5", "Ret\n", "Ret\n", ""},
550 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800551};
552
553/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100554static const char new_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100555 {"S0", "Left\n", "Left\n", ""},
556 {"S1", "Down\n", "Down\n", ""},
557 {"S2", "Up\n", "Up\n", ""},
558 {"S3", "Right\n", "Right\n", ""},
559 {"S4s5", "", "Esc\n", "Esc\n"},
560 {"s4S5", "", "Ret\n", "Ret\n"},
561 {"S4S5", "Help\n", "", ""},
562 /* add new signals above this line */
563 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800564};
565
566/* signals, press, repeat, release */
Peter Huewe36d20412013-02-15 13:47:05 +0100567static const char nexcom_keypad_profile[][4][9] = {
Willy Tarreau698b1512008-11-22 11:29:33 +0100568 {"a-p-e-", "Down\n", "Down\n", ""},
569 {"a-p-E-", "Ret\n", "Ret\n", ""},
570 {"a-P-E-", "Esc\n", "Esc\n", ""},
571 {"a-P-e-", "Up\n", "Up\n", ""},
572 /* add new signals above this line */
573 {"", "", "", ""}
Willy Tarreau7005b582008-11-13 17:18:59 -0800574};
575
Peter Huewe36d20412013-02-15 13:47:05 +0100576static const char (*keypad_profile)[4][9] = old_keypad_profile;
Willy Tarreau7005b582008-11-13 17:18:59 -0800577
Daniel Chromikbea74332016-02-11 13:29:23 +0100578static DECLARE_BITMAP(bits, LCD_BITS);
579
580static void lcd_get_bits(unsigned int port, int *val)
581{
582 unsigned int bit, state;
583
584 for (bit = 0; bit < LCD_BITS; bit++) {
585 state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
586 *val &= lcd_bits[port][bit][BIT_MSK];
587 *val |= lcd_bits[port][bit][state];
588 }
589}
Willy Tarreau7005b582008-11-13 17:18:59 -0800590
Willy Tarreau7005b582008-11-13 17:18:59 -0800591/* sets data port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100592static int set_data_bits(void)
593{
Daniel Chromikbea74332016-02-11 13:29:23 +0100594 int val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800595
Willy Tarreau698b1512008-11-22 11:29:33 +0100596 val = r_dtr(pprt);
Daniel Chromikbea74332016-02-11 13:29:23 +0100597 lcd_get_bits(LCD_PORT_D, &val);
Willy Tarreau698b1512008-11-22 11:29:33 +0100598 w_dtr(pprt, val);
599 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800600}
601
602/* sets ctrl port bits according to current signals values */
Willy Tarreau698b1512008-11-22 11:29:33 +0100603static int set_ctrl_bits(void)
604{
Daniel Chromikbea74332016-02-11 13:29:23 +0100605 int val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800606
Willy Tarreau698b1512008-11-22 11:29:33 +0100607 val = r_ctr(pprt);
Daniel Chromikbea74332016-02-11 13:29:23 +0100608 lcd_get_bits(LCD_PORT_C, &val);
Willy Tarreau698b1512008-11-22 11:29:33 +0100609 w_ctr(pprt, val);
610 return val;
Willy Tarreau7005b582008-11-13 17:18:59 -0800611}
612
613/* sets ctrl & data port bits according to current signals values */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530614static void panel_set_bits(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100615{
616 set_data_bits();
617 set_ctrl_bits();
Willy Tarreau7005b582008-11-13 17:18:59 -0800618}
619
620/*
621 * Converts a parallel port pin (from -25 to 25) to data and control ports
622 * masks, and data and control port bits. The signal will be considered
623 * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
624 *
625 * Result will be used this way :
626 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
627 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
628 */
Peter Huewe36d20412013-02-15 13:47:05 +0100629static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
Willy Tarreau698b1512008-11-22 11:29:33 +0100630{
631 int d_bit, c_bit, inv;
Willy Tarreau7005b582008-11-13 17:18:59 -0800632
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200633 d_val[0] = 0;
634 c_val[0] = 0;
635 d_val[1] = 0;
636 c_val[1] = 0;
637 d_val[2] = 0xFF;
638 c_val[2] = 0xFF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800639
Willy Tarreau698b1512008-11-22 11:29:33 +0100640 if (pin == 0)
641 return;
Willy Tarreau7005b582008-11-13 17:18:59 -0800642
Willy Tarreau698b1512008-11-22 11:29:33 +0100643 inv = (pin < 0);
644 if (inv)
645 pin = -pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800646
Dominique van den Broeck2d534262014-05-24 01:35:24 +0200647 d_bit = 0;
648 c_bit = 0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800649
Willy Tarreau698b1512008-11-22 11:29:33 +0100650 switch (pin) {
651 case PIN_STROBE: /* strobe, inverted */
652 c_bit = PNL_PSTROBE;
653 inv = !inv;
654 break;
655 case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
656 d_bit = 1 << (pin - 2);
657 break;
658 case PIN_AUTOLF: /* autofeed, inverted */
659 c_bit = PNL_PAUTOLF;
660 inv = !inv;
661 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300662 case PIN_INITP: /* init, direct */
Willy Tarreau698b1512008-11-22 11:29:33 +0100663 c_bit = PNL_PINITP;
664 break;
665 case PIN_SELECP: /* select_in, inverted */
666 c_bit = PNL_PSELECP;
667 inv = !inv;
668 break;
669 default: /* unknown pin, ignore */
670 break;
671 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800672
Willy Tarreau698b1512008-11-22 11:29:33 +0100673 if (c_bit) {
674 c_val[2] &= ~c_bit;
675 c_val[!inv] = c_bit;
676 } else if (d_bit) {
677 d_val[2] &= ~d_bit;
678 d_val[!inv] = d_bit;
679 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800680}
681
Alex Wilson881bf2812015-07-31 11:08:29 -0600682/*
683 * send a serial byte to the LCD panel. The caller is responsible for locking
684 * if needed.
685 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100686static void lcd_send_serial(int byte)
687{
688 int bit;
Willy Tarreau7005b582008-11-13 17:18:59 -0800689
Alex Wilson881bf2812015-07-31 11:08:29 -0600690 /*
691 * the data bit is set on D0, and the clock on STROBE.
692 * LCD reads D0 on STROBE's rising edge.
693 */
Willy Tarreau698b1512008-11-22 11:29:33 +0100694 for (bit = 0; bit < 8; bit++) {
Daniel Chromikbea74332016-02-11 13:29:23 +0100695 clear_bit(LCD_BIT_CL, bits); /* CLK low */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530696 panel_set_bits();
Daniel Chromikbea74332016-02-11 13:29:23 +0100697 if (byte & 1) {
698 set_bit(LCD_BIT_DA, bits);
699 } else {
700 clear_bit(LCD_BIT_DA, bits);
701 }
702
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530703 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300704 udelay(2); /* maintain the data during 2 us before CLK up */
Daniel Chromikbea74332016-02-11 13:29:23 +0100705 set_bit(LCD_BIT_CL, bits); /* CLK high */
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530706 panel_set_bits();
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300707 udelay(1); /* maintain the strobe during 1 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100708 byte >>= 1;
709 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800710}
711
712/* turn the backlight on or off */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100713static void lcd_backlight(struct charlcd *charlcd, int on)
Willy Tarreau698b1512008-11-22 11:29:33 +0100714{
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100715 if (lcd.pins.bl == PIN_NONE)
716 return;
717
Justin P. Mattock6975e182012-03-19 08:17:52 -0700718 /* The backlight is activated by setting the AUTOFEED line to +5V */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800719 spin_lock_irq(&pprt_lock);
Daniel Chromikbea74332016-02-11 13:29:23 +0100720 if (on)
721 set_bit(LCD_BIT_BL, bits);
722 else
723 clear_bit(LCD_BIT_BL, bits);
Sachin P. Sant6136ac82009-02-03 21:10:58 +0530724 panel_set_bits();
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800725 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800726}
727
728/* send a command to the LCD panel in serial mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100729static void lcd_write_cmd_s(struct charlcd *charlcd, int cmd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100730{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800731 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100732 lcd_send_serial(0x1F); /* R/W=W, RS=0 */
733 lcd_send_serial(cmd & 0x0F);
734 lcd_send_serial((cmd >> 4) & 0x0F);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530735 udelay(40); /* the shortest command takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800736 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800737}
738
739/* send data to the LCD panel in serial mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100740static void lcd_write_data_s(struct charlcd *charlcd, int data)
Willy Tarreau698b1512008-11-22 11:29:33 +0100741{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800742 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100743 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
744 lcd_send_serial(data & 0x0F);
745 lcd_send_serial((data >> 4) & 0x0F);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530746 udelay(40); /* the shortest data takes at least 40 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800747 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800748}
749
750/* send a command to the LCD panel in 8 bits parallel mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100751static void lcd_write_cmd_p8(struct charlcd *charlcd, int cmd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100752{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800753 spin_lock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800754 /* present the data to the data port */
Willy Tarreau698b1512008-11-22 11:29:33 +0100755 w_dtr(pprt, cmd);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530756 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau7005b582008-11-13 17:18:59 -0800757
Daniel Chromikbea74332016-02-11 13:29:23 +0100758 set_bit(LCD_BIT_E, bits);
759 clear_bit(LCD_BIT_RS, bits);
760 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau7005b582008-11-13 17:18:59 -0800761 set_ctrl_bits();
762
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530763 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau7005b582008-11-13 17:18:59 -0800764
Daniel Chromikbea74332016-02-11 13:29:23 +0100765 clear_bit(LCD_BIT_E, bits);
Willy Tarreau7005b582008-11-13 17:18:59 -0800766 set_ctrl_bits();
767
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530768 udelay(120); /* the shortest command takes at least 120 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800769 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100770}
Willy Tarreau7005b582008-11-13 17:18:59 -0800771
Willy Tarreau698b1512008-11-22 11:29:33 +0100772/* send data to the LCD panel in 8 bits parallel mode */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100773static void lcd_write_data_p8(struct charlcd *charlcd, int data)
Willy Tarreau698b1512008-11-22 11:29:33 +0100774{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800775 spin_lock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100776 /* present the data to the data port */
777 w_dtr(pprt, data);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530778 udelay(20); /* maintain the data during 20 us before the strobe */
Willy Tarreau698b1512008-11-22 11:29:33 +0100779
Daniel Chromikbea74332016-02-11 13:29:23 +0100780 set_bit(LCD_BIT_E, bits);
781 set_bit(LCD_BIT_RS, bits);
782 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100783 set_ctrl_bits();
784
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530785 udelay(40); /* maintain the strobe during 40 us */
Willy Tarreau698b1512008-11-22 11:29:33 +0100786
Daniel Chromikbea74332016-02-11 13:29:23 +0100787 clear_bit(LCD_BIT_E, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100788 set_ctrl_bits();
789
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530790 udelay(45); /* the shortest data takes at least 45 us */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800791 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100792}
793
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400794/* send a command to the TI LCD panel */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100795static void lcd_write_cmd_tilcd(struct charlcd *charlcd, int cmd)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400796{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800797 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400798 /* present the data to the control port */
799 w_ctr(pprt, cmd);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530800 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800801 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400802}
803
804/* send data to the TI LCD panel */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100805static void lcd_write_data_tilcd(struct charlcd *charlcd, int data)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400806{
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800807 spin_lock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400808 /* present the data to the data port */
809 w_dtr(pprt, data);
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530810 udelay(60);
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800811 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400812}
813
Willy Tarreau698b1512008-11-22 11:29:33 +0100814/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100815static void lcd_clear_fast_s(struct charlcd *charlcd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100816{
817 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200818
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800819 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100820 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100821 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
822 lcd_send_serial(' ' & 0x0F);
823 lcd_send_serial((' ' >> 4) & 0x0F);
Ricardo Ruedasdf44f152015-12-08 22:30:40 +0100824 /* the shortest data takes at least 40 us */
Greg Kroah-Hartman4cff7ad2016-02-01 12:50:26 -0800825 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100826 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800827 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +0100828}
829
830/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100831static void lcd_clear_fast_p8(struct charlcd *charlcd)
Willy Tarreau698b1512008-11-22 11:29:33 +0100832{
833 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200834
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800835 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100836 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Willy Tarreau698b1512008-11-22 11:29:33 +0100837 /* present the data to the data port */
838 w_dtr(pprt, ' ');
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300839
840 /* maintain the data during 20 us before the strobe */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530841 udelay(20);
Willy Tarreau698b1512008-11-22 11:29:33 +0100842
Daniel Chromikbea74332016-02-11 13:29:23 +0100843 set_bit(LCD_BIT_E, bits);
844 set_bit(LCD_BIT_RS, bits);
845 clear_bit(LCD_BIT_RW, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100846 set_ctrl_bits();
847
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300848 /* maintain the strobe during 40 us */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530849 udelay(40);
Willy Tarreau698b1512008-11-22 11:29:33 +0100850
Daniel Chromikbea74332016-02-11 13:29:23 +0100851 clear_bit(LCD_BIT_E, bits);
Willy Tarreau698b1512008-11-22 11:29:33 +0100852 set_ctrl_bits();
853
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300854 /* the shortest data takes at least 45 us */
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530855 udelay(45);
Willy Tarreau698b1512008-11-22 11:29:33 +0100856 }
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800857 spin_unlock_irq(&pprt_lock);
Willy Tarreau7005b582008-11-13 17:18:59 -0800858}
859
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400860/* fills the display with spaces and resets X/Y */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100861static void lcd_clear_fast_tilcd(struct charlcd *charlcd)
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400862{
863 int pos;
Bastien Armandc3ed0af2014-04-04 21:45:07 +0200864
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800865 spin_lock_irq(&pprt_lock);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100866 for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400867 /* present the data to the data port */
868 w_dtr(pprt, ' ');
Sudip Mukherjeeb64a1cb2016-01-23 14:49:20 +0530869 udelay(60);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400870 }
871
Fengguang Wud4d2dbc2012-09-09 16:23:46 +0800872 spin_unlock_irq(&pprt_lock);
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -0400873}
874
Arvind Yadav7b948f12017-07-14 22:04:49 +0530875static const struct charlcd_ops charlcd_serial_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100876 .write_cmd = lcd_write_cmd_s,
877 .write_data = lcd_write_data_s,
878 .clear_fast = lcd_clear_fast_s,
879 .backlight = lcd_backlight,
Willy Tarreau7005b582008-11-13 17:18:59 -0800880};
881
Arvind Yadav7b948f12017-07-14 22:04:49 +0530882static const struct charlcd_ops charlcd_parallel_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100883 .write_cmd = lcd_write_cmd_p8,
884 .write_data = lcd_write_data_p8,
885 .clear_fast = lcd_clear_fast_p8,
886 .backlight = lcd_backlight,
Willy Tarreau7005b582008-11-13 17:18:59 -0800887};
888
Arvind Yadav7b948f12017-07-14 22:04:49 +0530889static const struct charlcd_ops charlcd_tilcd_ops = {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100890 .write_cmd = lcd_write_cmd_tilcd,
891 .write_data = lcd_write_data_tilcd,
892 .clear_fast = lcd_clear_fast_tilcd,
893 .backlight = lcd_backlight,
894};
Willy Tarreau7005b582008-11-13 17:18:59 -0800895
Willy Tarreau7005b582008-11-13 17:18:59 -0800896/* initialize the LCD driver */
Peter Huewe36d20412013-02-15 13:47:05 +0100897static void lcd_init(void)
Willy Tarreau698b1512008-11-22 11:29:33 +0100898{
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100899 struct charlcd *charlcd;
900
901 charlcd = charlcd_alloc(0);
902 if (!charlcd)
903 return;
904
905 /*
906 * Init lcd struct with load-time values to preserve exact
907 * current functionality (at least for now).
908 */
909 charlcd->height = lcd_height;
910 charlcd->width = lcd_width;
911 charlcd->bwidth = lcd_bwidth;
912 charlcd->hwidth = lcd_hwidth;
913
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +0100914 switch (selected_lcd_type) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300915 case LCD_TYPE_OLD:
916 /* parallel mode, 8 bits */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100917 lcd.proto = LCD_PROTO_PARALLEL;
918 lcd.charset = LCD_CHARSET_NORMAL;
919 lcd.pins.e = PIN_STROBE;
920 lcd.pins.rs = PIN_AUTOLF;
Willy Tarreau7005b582008-11-13 17:18:59 -0800921
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100922 charlcd->width = 40;
923 charlcd->bwidth = 40;
924 charlcd->hwidth = 64;
925 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800926 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300927 case LCD_TYPE_KS0074:
928 /* serial mode, ks0074 */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100929 lcd.proto = LCD_PROTO_SERIAL;
930 lcd.charset = LCD_CHARSET_KS0074;
931 lcd.pins.bl = PIN_AUTOLF;
932 lcd.pins.cl = PIN_STROBE;
933 lcd.pins.da = PIN_D0;
Willy Tarreau7005b582008-11-13 17:18:59 -0800934
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100935 charlcd->width = 16;
936 charlcd->bwidth = 40;
937 charlcd->hwidth = 16;
938 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800939 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300940 case LCD_TYPE_NEXCOM:
941 /* parallel mode, 8 bits, generic */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100942 lcd.proto = LCD_PROTO_PARALLEL;
943 lcd.charset = LCD_CHARSET_NORMAL;
944 lcd.pins.e = PIN_AUTOLF;
945 lcd.pins.rs = PIN_SELECP;
946 lcd.pins.rw = PIN_INITP;
Willy Tarreau7005b582008-11-13 17:18:59 -0800947
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100948 charlcd->width = 16;
949 charlcd->bwidth = 40;
950 charlcd->hwidth = 64;
951 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800952 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300953 case LCD_TYPE_CUSTOM:
954 /* customer-defined */
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100955 lcd.proto = DEFAULT_LCD_PROTO;
956 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -0800957 /* default geometry will be set later */
958 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +0300959 case LCD_TYPE_HANTRONIX:
960 /* parallel mode, 8 bits, hantronix-like */
Willy Tarreau698b1512008-11-22 11:29:33 +0100961 default:
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100962 lcd.proto = LCD_PROTO_PARALLEL;
963 lcd.charset = LCD_CHARSET_NORMAL;
964 lcd.pins.e = PIN_STROBE;
965 lcd.pins.rs = PIN_SELECP;
Willy Tarreau7005b582008-11-13 17:18:59 -0800966
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100967 charlcd->width = 16;
968 charlcd->bwidth = 40;
969 charlcd->hwidth = 64;
970 charlcd->height = 2;
Willy Tarreau7005b582008-11-13 17:18:59 -0800971 break;
Willy Tarreau698b1512008-11-22 11:29:33 +0100972 }
Willy Tarreau7005b582008-11-13 17:18:59 -0800973
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100974 /* Overwrite with module params set on loading */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100975 if (lcd_height != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100976 charlcd->height = lcd_height;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100977 if (lcd_width != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100978 charlcd->width = lcd_width;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100979 if (lcd_bwidth != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100980 charlcd->bwidth = lcd_bwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100981 if (lcd_hwidth != NOT_SET)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +0100982 charlcd->hwidth = lcd_hwidth;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100983 if (lcd_charset != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100984 lcd.charset = lcd_charset;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +0100985 if (lcd_proto != NOT_SET)
Mariusz Gorski8037e2a2014-11-27 22:36:51 +0100986 lcd.proto = lcd_proto;
987 if (lcd_e_pin != PIN_NOT_SET)
988 lcd.pins.e = lcd_e_pin;
989 if (lcd_rs_pin != PIN_NOT_SET)
990 lcd.pins.rs = lcd_rs_pin;
991 if (lcd_rw_pin != PIN_NOT_SET)
992 lcd.pins.rw = lcd_rw_pin;
993 if (lcd_cl_pin != PIN_NOT_SET)
994 lcd.pins.cl = lcd_cl_pin;
995 if (lcd_da_pin != PIN_NOT_SET)
996 lcd.pins.da = lcd_da_pin;
997 if (lcd_bl_pin != PIN_NOT_SET)
998 lcd.pins.bl = lcd_bl_pin;
Willy Tarreau7005b582008-11-13 17:18:59 -0800999
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001000 /* this is used to catch wrong and default values */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001001 if (charlcd->width <= 0)
1002 charlcd->width = DEFAULT_LCD_WIDTH;
1003 if (charlcd->bwidth <= 0)
1004 charlcd->bwidth = DEFAULT_LCD_BWIDTH;
1005 if (charlcd->hwidth <= 0)
1006 charlcd->hwidth = DEFAULT_LCD_HWIDTH;
1007 if (charlcd->height <= 0)
1008 charlcd->height = DEFAULT_LCD_HEIGHT;
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001009
1010 if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001011 charlcd->ops = &charlcd_serial_ops;
Willy Tarreau7005b582008-11-13 17:18:59 -08001012
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001013 if (lcd.pins.cl == PIN_NOT_SET)
1014 lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
1015 if (lcd.pins.da == PIN_NOT_SET)
1016 lcd.pins.da = DEFAULT_LCD_PIN_SDA;
Willy Tarreau7005b582008-11-13 17:18:59 -08001017
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001018 } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001019 charlcd->ops = &charlcd_parallel_ops;
Willy Tarreau7005b582008-11-13 17:18:59 -08001020
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001021 if (lcd.pins.e == PIN_NOT_SET)
1022 lcd.pins.e = DEFAULT_LCD_PIN_E;
1023 if (lcd.pins.rs == PIN_NOT_SET)
1024 lcd.pins.rs = DEFAULT_LCD_PIN_RS;
1025 if (lcd.pins.rw == PIN_NOT_SET)
1026 lcd.pins.rw = DEFAULT_LCD_PIN_RW;
Sudhakar Rajashekhara77943d32009-08-20 18:13:18 -04001027 } else {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001028 charlcd->ops = &charlcd_tilcd_ops;
Willy Tarreau698b1512008-11-22 11:29:33 +01001029 }
1030
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001031 if (lcd.pins.bl == PIN_NOT_SET)
1032 lcd.pins.bl = DEFAULT_LCD_PIN_BL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001033
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001034 if (lcd.pins.e == PIN_NOT_SET)
1035 lcd.pins.e = PIN_NONE;
1036 if (lcd.pins.rs == PIN_NOT_SET)
1037 lcd.pins.rs = PIN_NONE;
1038 if (lcd.pins.rw == PIN_NOT_SET)
1039 lcd.pins.rw = PIN_NONE;
1040 if (lcd.pins.bl == PIN_NOT_SET)
1041 lcd.pins.bl = PIN_NONE;
1042 if (lcd.pins.cl == PIN_NOT_SET)
1043 lcd.pins.cl = PIN_NONE;
1044 if (lcd.pins.da == PIN_NOT_SET)
1045 lcd.pins.da = PIN_NONE;
Willy Tarreau7005b582008-11-13 17:18:59 -08001046
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001047 if (lcd.charset == NOT_SET)
1048 lcd.charset = DEFAULT_LCD_CHARSET;
Willy Tarreau7005b582008-11-13 17:18:59 -08001049
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001050 if (lcd.charset == LCD_CHARSET_KS0074)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001051 charlcd->char_conv = lcd_char_conv_ks0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01001052 else
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001053 charlcd->char_conv = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001054
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001055 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
Willy Tarreau698b1512008-11-22 11:29:33 +01001056 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001057 pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
Willy Tarreau698b1512008-11-22 11:29:33 +01001058 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001059 pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
Willy Tarreau698b1512008-11-22 11:29:33 +01001060 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001061 pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001062 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001063 pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
Willy Tarreau698b1512008-11-22 11:29:33 +01001064 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001065 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
Willy Tarreau698b1512008-11-22 11:29:33 +01001066 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
Willy Tarreau7005b582008-11-13 17:18:59 -08001067
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001068 lcd.charlcd = charlcd;
Mariusz Gorski6d8b5882014-11-27 22:36:53 +01001069 lcd.initialized = true;
Willy Tarreau7005b582008-11-13 17:18:59 -08001070}
1071
Willy Tarreau7005b582008-11-13 17:18:59 -08001072/*
1073 * These are the file operation function for user access to /dev/keypad
1074 */
1075
Willy Tarreau698b1512008-11-22 11:29:33 +01001076static ssize_t keypad_read(struct file *file,
Bastien Armandcce75f42014-04-18 18:10:08 +02001077 char __user *buf, size_t count, loff_t *ppos)
Willy Tarreau698b1512008-11-22 11:29:33 +01001078{
Willy Tarreau698b1512008-11-22 11:29:33 +01001079 unsigned i = *ppos;
Bastien Armandcce75f42014-04-18 18:10:08 +02001080 char __user *tmp = buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001081
Willy Tarreau698b1512008-11-22 11:29:33 +01001082 if (keypad_buflen == 0) {
1083 if (file->f_flags & O_NONBLOCK)
1084 return -EAGAIN;
Willy Tarreau7005b582008-11-13 17:18:59 -08001085
Arnd Bergmann310df692014-01-02 13:07:35 +01001086 if (wait_event_interruptible(keypad_read_wait,
1087 keypad_buflen != 0))
Willy Tarreau698b1512008-11-22 11:29:33 +01001088 return -EINTR;
1089 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001090
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001091 for (; count-- > 0 && (keypad_buflen > 0);
1092 ++i, ++tmp, --keypad_buflen) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001093 put_user(keypad_buffer[keypad_start], tmp);
1094 keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
1095 }
1096 *ppos = i;
Willy Tarreau7005b582008-11-13 17:18:59 -08001097
Willy Tarreau698b1512008-11-22 11:29:33 +01001098 return tmp - buf;
Willy Tarreau7005b582008-11-13 17:18:59 -08001099}
1100
Willy Tarreau698b1512008-11-22 11:29:33 +01001101static int keypad_open(struct inode *inode, struct file *file)
1102{
Willy Tarreau93dc1772017-09-07 15:37:30 +02001103 int ret;
Willy Tarreau7005b582008-11-13 17:18:59 -08001104
Willy Tarreau93dc1772017-09-07 15:37:30 +02001105 ret = -EBUSY;
1106 if (!atomic_dec_and_test(&keypad_available))
1107 goto fail; /* open only once at a time */
1108
1109 ret = -EPERM;
Willy Tarreau698b1512008-11-22 11:29:33 +01001110 if (file->f_mode & FMODE_WRITE) /* device is read-only */
Willy Tarreau93dc1772017-09-07 15:37:30 +02001111 goto fail;
Willy Tarreau7005b582008-11-13 17:18:59 -08001112
Willy Tarreau698b1512008-11-22 11:29:33 +01001113 keypad_buflen = 0; /* flush the buffer on opening */
Willy Tarreau698b1512008-11-22 11:29:33 +01001114 return 0;
Willy Tarreau93dc1772017-09-07 15:37:30 +02001115 fail:
1116 atomic_inc(&keypad_available);
1117 return ret;
Willy Tarreau7005b582008-11-13 17:18:59 -08001118}
1119
Willy Tarreau698b1512008-11-22 11:29:33 +01001120static int keypad_release(struct inode *inode, struct file *file)
1121{
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001122 atomic_inc(&keypad_available);
Willy Tarreau698b1512008-11-22 11:29:33 +01001123 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001124}
1125
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001126static const struct file_operations keypad_fops = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001127 .read = keypad_read, /* read */
1128 .open = keypad_open, /* open */
1129 .release = keypad_release, /* close */
Arnd Bergmann6038f372010-08-15 18:52:59 +02001130 .llseek = default_llseek,
Willy Tarreau7005b582008-11-13 17:18:59 -08001131};
1132
1133static struct miscdevice keypad_dev = {
Mariusz Gorski6c3773de2014-10-29 23:32:30 +01001134 .minor = KEYPAD_MINOR,
1135 .name = "keypad",
1136 .fops = &keypad_fops,
Willy Tarreau7005b582008-11-13 17:18:59 -08001137};
1138
Peter Huewe36d20412013-02-15 13:47:05 +01001139static void keypad_send_key(const char *string, int max_len)
Willy Tarreau698b1512008-11-22 11:29:33 +01001140{
Willy Tarreau698b1512008-11-22 11:29:33 +01001141 /* send the key to the device only if a process is attached to it. */
Mariusz Gorskif4757af2014-11-04 22:47:19 +01001142 if (!atomic_read(&keypad_available)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001143 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1144 keypad_buffer[(keypad_start + keypad_buflen++) %
1145 KEYPAD_BUFFER] = *string++;
1146 }
1147 wake_up_interruptible(&keypad_read_wait);
Willy Tarreau7005b582008-11-13 17:18:59 -08001148 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001149}
1150
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001151/* this function scans all the bits involving at least one logical signal,
1152 * and puts the results in the bitfield "phys_read" (one bit per established
1153 * contact), and sets "phys_read_prev" to "phys_read".
Willy Tarreau7005b582008-11-13 17:18:59 -08001154 *
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001155 * Note: to debounce input signals, we will only consider as switched a signal
1156 * which is stable across 2 measures. Signals which are different between two
1157 * reads will be kept as they previously were in their logical form (phys_prev).
1158 * A signal which has just switched will have a 1 in
1159 * (phys_read ^ phys_read_prev).
Willy Tarreau7005b582008-11-13 17:18:59 -08001160 */
Willy Tarreau698b1512008-11-22 11:29:33 +01001161static void phys_scan_contacts(void)
1162{
1163 int bit, bitval;
1164 char oldval;
1165 char bitmask;
1166 char gndmask;
Willy Tarreau7005b582008-11-13 17:18:59 -08001167
Willy Tarreau698b1512008-11-22 11:29:33 +01001168 phys_prev = phys_curr;
1169 phys_read_prev = phys_read;
1170 phys_read = 0; /* flush all signals */
Willy Tarreau7005b582008-11-13 17:18:59 -08001171
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001172 /* keep track of old value, with all outputs disabled */
1173 oldval = r_dtr(pprt) | scan_mask_o;
1174 /* activate all keyboard outputs (active low) */
1175 w_dtr(pprt, oldval & ~scan_mask_o);
1176
1177 /* will have a 1 for each bit set to gnd */
1178 bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1179 /* disable all matrix signals */
1180 w_dtr(pprt, oldval);
Willy Tarreau7005b582008-11-13 17:18:59 -08001181
Willy Tarreau698b1512008-11-22 11:29:33 +01001182 /* now that all outputs are cleared, the only active input bits are
1183 * directly connected to the ground
Willy Tarreau7005b582008-11-13 17:18:59 -08001184 */
Willy Tarreau7005b582008-11-13 17:18:59 -08001185
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001186 /* 1 for each grounded input */
1187 gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
1188
1189 /* grounded inputs are signals 40-44 */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001190 phys_read |= (__u64)gndmask << 40;
Willy Tarreau7005b582008-11-13 17:18:59 -08001191
Willy Tarreau698b1512008-11-22 11:29:33 +01001192 if (bitmask != gndmask) {
Nayeemahmed Badebade8c178932015-08-27 21:02:46 +05301193 /*
1194 * since clearing the outputs changed some inputs, we know
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001195 * that some input signals are currently tied to some outputs.
1196 * So we'll scan them.
Willy Tarreau698b1512008-11-22 11:29:33 +01001197 */
1198 for (bit = 0; bit < 8; bit++) {
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301199 bitval = BIT(bit);
Willy Tarreau698b1512008-11-22 11:29:33 +01001200
1201 if (!(scan_mask_o & bitval)) /* skip unused bits */
1202 continue;
1203
1204 w_dtr(pprt, oldval & ~bitval); /* enable this output */
1205 bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001206 phys_read |= (__u64)bitmask << (5 * bit);
Willy Tarreau698b1512008-11-22 11:29:33 +01001207 }
1208 w_dtr(pprt, oldval); /* disable all outputs */
Willy Tarreau7005b582008-11-13 17:18:59 -08001209 }
Nayeemahmed Badebade8c178932015-08-27 21:02:46 +05301210 /*
1211 * this is easy: use old bits when they are flapping,
1212 * use new ones when stable
1213 */
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001214 phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
1215 (phys_read & ~(phys_read ^ phys_read_prev));
1216}
1217
1218static inline int input_state_high(struct logical_input *input)
1219{
1220#if 0
1221 /* FIXME:
1222 * this is an invalid test. It tries to catch
1223 * transitions from single-key to multiple-key, but
1224 * doesn't take into account the contacts polarity.
1225 * The only solution to the problem is to parse keys
1226 * from the most complex to the simplest combinations,
1227 * and mark them as 'caught' once a combination
1228 * matches, then unmatch it for all other ones.
1229 */
1230
1231 /* try to catch dangerous transitions cases :
1232 * someone adds a bit, so this signal was a false
1233 * positive resulting from a transition. We should
1234 * invalidate the signal immediately and not call the
1235 * release function.
1236 * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
1237 */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001238 if (((phys_prev & input->mask) == input->value) &&
1239 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001240 input->state = INPUT_ST_LOW; /* invalidate */
1241 return 1;
1242 }
1243#endif
1244
1245 if ((phys_curr & input->mask) == input->value) {
1246 if ((input->type == INPUT_TYPE_STD) &&
1247 (input->high_timer == 0)) {
1248 input->high_timer++;
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001249 if (input->u.std.press_fct)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001250 input->u.std.press_fct(input->u.std.press_data);
1251 } else if (input->type == INPUT_TYPE_KBD) {
1252 /* will turn on the light */
1253 keypressed = 1;
1254
1255 if (input->high_timer == 0) {
1256 char *press_str = input->u.kbd.press_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001257
Jake Champline6626de2013-05-04 11:21:17 -04001258 if (press_str[0]) {
1259 int s = sizeof(input->u.kbd.press_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001260
Jake Champline6626de2013-05-04 11:21:17 -04001261 keypad_send_key(press_str, s);
1262 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001263 }
1264
1265 if (input->u.kbd.repeat_str[0]) {
1266 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001267
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001268 if (input->high_timer >= KEYPAD_REP_START) {
Jake Champline6626de2013-05-04 11:21:17 -04001269 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001270
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001271 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001272 keypad_send_key(repeat_str, s);
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001273 }
1274 /* we will need to come back here soon */
1275 inputs_stable = 0;
1276 }
1277
1278 if (input->high_timer < 255)
1279 input->high_timer++;
1280 }
1281 return 1;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001282 }
Vincent Heuken083b3632014-07-10 03:34:28 -07001283
1284 /* else signal falling down. Let's fall through. */
1285 input->state = INPUT_ST_FALLING;
1286 input->fall_timer = 0;
1287
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001288 return 0;
1289}
1290
1291static inline void input_state_falling(struct logical_input *input)
1292{
1293#if 0
1294 /* FIXME !!! same comment as in input_state_high */
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001295 if (((phys_prev & input->mask) == input->value) &&
1296 ((phys_curr & input->mask) > input->value)) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001297 input->state = INPUT_ST_LOW; /* invalidate */
1298 return;
1299 }
1300#endif
1301
1302 if ((phys_curr & input->mask) == input->value) {
1303 if (input->type == INPUT_TYPE_KBD) {
1304 /* will turn on the light */
1305 keypressed = 1;
1306
1307 if (input->u.kbd.repeat_str[0]) {
1308 char *repeat_str = input->u.kbd.repeat_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001309
Jake Champline6626de2013-05-04 11:21:17 -04001310 if (input->high_timer >= KEYPAD_REP_START) {
1311 int s = sizeof(input->u.kbd.repeat_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001312
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001313 input->high_timer -= KEYPAD_REP_DELAY;
Jake Champline6626de2013-05-04 11:21:17 -04001314 keypad_send_key(repeat_str, s);
1315 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001316 /* we will need to come back here soon */
1317 inputs_stable = 0;
1318 }
1319
1320 if (input->high_timer < 255)
1321 input->high_timer++;
1322 }
1323 input->state = INPUT_ST_HIGH;
1324 } else if (input->fall_timer >= input->fall_time) {
1325 /* call release event */
1326 if (input->type == INPUT_TYPE_STD) {
1327 void (*release_fct)(int) = input->u.std.release_fct;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001328
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001329 if (release_fct)
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001330 release_fct(input->u.std.release_data);
1331 } else if (input->type == INPUT_TYPE_KBD) {
1332 char *release_str = input->u.kbd.release_str;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001333
Jake Champline6626de2013-05-04 11:21:17 -04001334 if (release_str[0]) {
1335 int s = sizeof(input->u.kbd.release_str);
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001336
Jake Champline6626de2013-05-04 11:21:17 -04001337 keypad_send_key(release_str, s);
1338 }
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001339 }
1340
1341 input->state = INPUT_ST_LOW;
1342 } else {
1343 input->fall_timer++;
1344 inputs_stable = 0;
1345 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001346}
1347
Willy Tarreau698b1512008-11-22 11:29:33 +01001348static void panel_process_inputs(void)
1349{
Willy Tarreau698b1512008-11-22 11:29:33 +01001350 struct logical_input *input;
Willy Tarreau7005b582008-11-13 17:18:59 -08001351
Willy Tarreau698b1512008-11-22 11:29:33 +01001352 keypressed = 0;
1353 inputs_stable = 1;
Wei Yongjun4654bdb2017-04-25 16:13:34 +00001354 list_for_each_entry(input, &logical_inputs, list) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001355 switch (input->state) {
1356 case INPUT_ST_LOW:
1357 if ((phys_curr & input->mask) != input->value)
1358 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001359 /* if all needed ones were already set previously,
1360 * this means that this logical signal has been
1361 * activated by the releasing of another combined
1362 * signal, so we don't want to match.
1363 * eg: AB -(release B)-> A -(release A)-> 0 :
1364 * don't match A.
Willy Tarreau698b1512008-11-22 11:29:33 +01001365 */
1366 if ((phys_prev & input->mask) == input->value)
1367 break;
1368 input->rise_timer = 0;
1369 input->state = INPUT_ST_RISING;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001370 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001371 case INPUT_ST_RISING:
1372 if ((phys_curr & input->mask) != input->value) {
1373 input->state = INPUT_ST_LOW;
1374 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001375 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001376 if (input->rise_timer < input->rise_time) {
1377 inputs_stable = 0;
1378 input->rise_timer++;
1379 break;
1380 }
1381 input->high_timer = 0;
1382 input->state = INPUT_ST_HIGH;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001383 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001384 case INPUT_ST_HIGH:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001385 if (input_state_high(input))
Willy Tarreau698b1512008-11-22 11:29:33 +01001386 break;
Miguel Ojeda5617c592018-02-19 16:02:48 +01001387 /* fall through */
Willy Tarreau698b1512008-11-22 11:29:33 +01001388 case INPUT_ST_FALLING:
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001389 input_state_falling(input);
Willy Tarreau698b1512008-11-22 11:29:33 +01001390 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001391 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001392}
1393
Kees Cook607a6302017-10-19 14:08:22 -07001394static void panel_scan_timer(struct timer_list *unused)
Willy Tarreau698b1512008-11-22 11:29:33 +01001395{
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001396 if (keypad.enabled && keypad_initialized) {
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001397 if (spin_trylock_irq(&pprt_lock)) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001398 phys_scan_contacts();
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001399
1400 /* no need for the parport anymore */
Fengguang Wud4d2dbc2012-09-09 16:23:46 +08001401 spin_unlock_irq(&pprt_lock);
Willy Tarreau698b1512008-11-22 11:29:33 +01001402 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001403
Willy Tarreau698b1512008-11-22 11:29:33 +01001404 if (!inputs_stable || phys_curr != phys_prev)
1405 panel_process_inputs();
1406 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001407
Geert Uytterhoevenfda4ae12017-02-06 15:38:10 +01001408 if (keypressed && lcd.enabled && lcd.initialized)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001409 charlcd_poke(lcd.charlcd);
Willy Tarreau7005b582008-11-13 17:18:59 -08001410
Willy Tarreau698b1512008-11-22 11:29:33 +01001411 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
Willy Tarreau7005b582008-11-13 17:18:59 -08001412}
1413
Willy Tarreau698b1512008-11-22 11:29:33 +01001414static void init_scan_timer(void)
1415{
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001416 if (scan_timer.function)
Willy Tarreau698b1512008-11-22 11:29:33 +01001417 return; /* already started */
Willy Tarreau7005b582008-11-13 17:18:59 -08001418
Kees Cook607a6302017-10-19 14:08:22 -07001419 timer_setup(&scan_timer, panel_scan_timer, 0);
Willy Tarreau698b1512008-11-22 11:29:33 +01001420 scan_timer.expires = jiffies + INPUT_POLL_TIME;
Willy Tarreau698b1512008-11-22 11:29:33 +01001421 add_timer(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001422}
1423
1424/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001425 * if <omask> or <imask> are non-null, they will be or'ed with the bits
1426 * corresponding to out and in bits respectively.
Willy Tarreau7005b582008-11-13 17:18:59 -08001427 * returns 1 if ok, 0 if error (in which case, nothing is written).
1428 */
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001429static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
Ksenija Stanojevicd938e1e2016-01-03 20:39:49 +01001430 u8 *imask, u8 *omask)
Willy Tarreau698b1512008-11-22 11:29:33 +01001431{
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001432 const char sigtab[] = "EeSsPpAaBb";
Ksenija Stanojevicd938e1e2016-01-03 20:39:49 +01001433 u8 im, om;
Ksenija Stanojevic35fe0872016-01-03 20:40:58 +01001434 __u64 m, v;
Willy Tarreau7005b582008-11-13 17:18:59 -08001435
Ksenija Stanojevicd12f27e2016-01-03 20:42:26 +01001436 om = 0;
1437 im = 0;
Dominique van den Broeck2d534262014-05-24 01:35:24 +02001438 m = 0ULL;
1439 v = 0ULL;
Willy Tarreau698b1512008-11-22 11:29:33 +01001440 while (*name) {
1441 int in, out, bit, neg;
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001442 const char *idx;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001443
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001444 idx = strchr(sigtab, *name);
1445 if (!idx)
Willy Tarreau698b1512008-11-22 11:29:33 +01001446 return 0; /* input name not found */
Ksenija Stanojevic8aa73072016-01-03 20:44:44 +01001447
1448 in = idx - sigtab;
Willy Tarreau698b1512008-11-22 11:29:33 +01001449 neg = (in & 1); /* odd (lower) names are negated */
1450 in >>= 1;
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301451 im |= BIT(in);
Willy Tarreau7005b582008-11-13 17:18:59 -08001452
Willy Tarreau698b1512008-11-22 11:29:33 +01001453 name++;
Ksenija Stanojevic52ebf932016-01-03 20:43:27 +01001454 if (*name >= '0' && *name <= '7') {
Willy Tarreau698b1512008-11-22 11:29:33 +01001455 out = *name - '0';
Amitoj Kaur Chawla79f2af62015-10-16 22:11:36 +05301456 om |= BIT(out);
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001457 } else if (*name == '-') {
Willy Tarreau698b1512008-11-22 11:29:33 +01001458 out = 8;
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001459 } else {
Willy Tarreau698b1512008-11-22 11:29:33 +01001460 return 0; /* unknown bit name */
Dominique van den Broeck3ac76902014-05-21 14:09:59 +02001461 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001462
1463 bit = (out * 5) + in;
1464
1465 m |= 1ULL << bit;
1466 if (!neg)
1467 v |= 1ULL << bit;
1468 name++;
Willy Tarreau7005b582008-11-13 17:18:59 -08001469 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001470 *mask = m;
1471 *value = v;
1472 if (imask)
1473 *imask |= im;
1474 if (omask)
1475 *omask |= om;
1476 return 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001477}
1478
1479/* tries to bind a key to the signal name <name>. The key will send the
1480 * strings <press>, <repeat>, <release> for these respective events.
1481 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
1482 */
Peter Huewe36d20412013-02-15 13:47:05 +01001483static struct logical_input *panel_bind_key(const char *name, const char *press,
1484 const char *repeat,
1485 const char *release)
Willy Tarreau698b1512008-11-22 11:29:33 +01001486{
1487 struct logical_input *key;
Willy Tarreau7005b582008-11-13 17:18:59 -08001488
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001489 key = kzalloc(sizeof(*key), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001490 if (!key)
Willy Tarreau698b1512008-11-22 11:29:33 +01001491 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001492
Willy Tarreau698b1512008-11-22 11:29:33 +01001493 if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04001494 &scan_mask_o)) {
1495 kfree(key);
Willy Tarreau698b1512008-11-22 11:29:33 +01001496 return NULL;
Kulikov Vasiliycb46f472010-07-12 18:48:24 +04001497 }
Willy Tarreau698b1512008-11-22 11:29:33 +01001498
1499 key->type = INPUT_TYPE_KBD;
1500 key->state = INPUT_ST_LOW;
1501 key->rise_time = 1;
1502 key->fall_time = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001503
Willy Tarreau698b1512008-11-22 11:29:33 +01001504 strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
1505 strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
1506 strncpy(key->u.kbd.release_str, release,
1507 sizeof(key->u.kbd.release_str));
1508 list_add(&key->list, &logical_inputs);
1509 return key;
Willy Tarreau7005b582008-11-13 17:18:59 -08001510}
1511
Willy Tarreau630231772008-11-22 12:52:18 +01001512#if 0
Willy Tarreau7005b582008-11-13 17:18:59 -08001513/* tries to bind a callback function to the signal name <name>. The function
1514 * <press_fct> will be called with the <press_data> arg when the signal is
1515 * activated, and so on for <release_fct>/<release_data>
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001516 * Returns the pointer to the new signal if ok, NULL if the signal could not
1517 * be bound.
Willy Tarreau7005b582008-11-13 17:18:59 -08001518 */
1519static struct logical_input *panel_bind_callback(char *name,
Monam Agarwal68d386b2014-02-25 19:40:49 +05301520 void (*press_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01001521 int press_data,
Monam Agarwal68d386b2014-02-25 19:40:49 +05301522 void (*release_fct)(int),
Willy Tarreau698b1512008-11-22 11:29:33 +01001523 int release_data)
1524{
1525 struct logical_input *callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08001526
Dominique van den Broeckfdf4a4942014-05-21 14:10:00 +02001527 callback = kmalloc(sizeof(*callback), GFP_KERNEL);
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001528 if (!callback)
Willy Tarreau698b1512008-11-22 11:29:33 +01001529 return NULL;
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001530
Willy Tarreau698b1512008-11-22 11:29:33 +01001531 memset(callback, 0, sizeof(struct logical_input));
1532 if (!input_name2mask(name, &callback->mask, &callback->value,
1533 &scan_mask_i, &scan_mask_o))
1534 return NULL;
1535
1536 callback->type = INPUT_TYPE_STD;
1537 callback->state = INPUT_ST_LOW;
1538 callback->rise_time = 1;
1539 callback->fall_time = 1;
1540 callback->u.std.press_fct = press_fct;
1541 callback->u.std.press_data = press_data;
1542 callback->u.std.release_fct = release_fct;
1543 callback->u.std.release_data = release_data;
1544 list_add(&callback->list, &logical_inputs);
1545 return callback;
Willy Tarreau7005b582008-11-13 17:18:59 -08001546}
Willy Tarreau630231772008-11-22 12:52:18 +01001547#endif
Willy Tarreau7005b582008-11-13 17:18:59 -08001548
Willy Tarreau698b1512008-11-22 11:29:33 +01001549static void keypad_init(void)
1550{
1551 int keynum;
Bastien Armandc3ed0af2014-04-04 21:45:07 +02001552
Willy Tarreau698b1512008-11-22 11:29:33 +01001553 init_waitqueue_head(&keypad_read_wait);
1554 keypad_buflen = 0; /* flushes any eventual noisy keystroke */
Willy Tarreau7005b582008-11-13 17:18:59 -08001555
Willy Tarreau698b1512008-11-22 11:29:33 +01001556 /* Let's create all known keys */
Willy Tarreau7005b582008-11-13 17:18:59 -08001557
Willy Tarreau698b1512008-11-22 11:29:33 +01001558 for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
1559 panel_bind_key(keypad_profile[keynum][0],
1560 keypad_profile[keynum][1],
1561 keypad_profile[keynum][2],
1562 keypad_profile[keynum][3]);
1563 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001564
Willy Tarreau698b1512008-11-22 11:29:33 +01001565 init_scan_timer();
1566 keypad_initialized = 1;
Willy Tarreau7005b582008-11-13 17:18:59 -08001567}
1568
Willy Tarreau7005b582008-11-13 17:18:59 -08001569/**************************************************/
1570/* device initialization */
1571/**************************************************/
1572
Willy Tarreau698b1512008-11-22 11:29:33 +01001573static void panel_attach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08001574{
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301575 struct pardev_cb panel_cb;
1576
Willy Tarreau698b1512008-11-22 11:29:33 +01001577 if (port->number != parport)
1578 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001579
Willy Tarreau698b1512008-11-22 11:29:33 +01001580 if (pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001581 pr_err("%s: port->number=%d parport=%d, already registered!\n",
1582 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01001583 return;
1584 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001585
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301586 memset(&panel_cb, 0, sizeof(panel_cb));
1587 panel_cb.private = &pprt;
1588 /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
1589
1590 pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001591 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001592 pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
1593 __func__, port->number, parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001594 return;
1595 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001596
Willy Tarreau698b1512008-11-22 11:29:33 +01001597 if (parport_claim(pprt)) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001598 pr_err("could not claim access to parport%d. Aborting.\n",
1599 parport);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001600 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01001601 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001602
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001603 /* must init LCD first, just in case an IRQ from the keypad is
1604 * generated at keypad init
1605 */
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001606 if (lcd.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001607 lcd_init();
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001608 if (!lcd.charlcd || charlcd_register(lcd.charlcd))
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001609 goto err_unreg_device;
Willy Tarreau698b1512008-11-22 11:29:33 +01001610 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001611
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001612 if (keypad.enabled) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001613 keypad_init();
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001614 if (misc_register(&keypad_dev))
1615 goto err_lcd_unreg;
Willy Tarreau698b1512008-11-22 11:29:33 +01001616 }
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001617 return;
1618
1619err_lcd_unreg:
zhengbinb33d5672019-07-08 20:42:18 +08001620 if (scan_timer.function)
1621 del_timer_sync(&scan_timer);
Mariusz Gorskia8b25802014-11-27 22:36:49 +01001622 if (lcd.enabled)
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001623 charlcd_unregister(lcd.charlcd);
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001624err_unreg_device:
Andy Shevchenko9b11d632019-03-12 16:44:31 +02001625 charlcd_free(lcd.charlcd);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001626 lcd.charlcd = NULL;
Kulikov Vasiliy10f3f5b2010-07-30 15:08:20 +04001627 parport_unregister_device(pprt);
1628 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001629}
1630
Willy Tarreau698b1512008-11-22 11:29:33 +01001631static void panel_detach(struct parport *port)
Willy Tarreau7005b582008-11-13 17:18:59 -08001632{
Willy Tarreau698b1512008-11-22 11:29:33 +01001633 if (port->number != parport)
1634 return;
Willy Tarreau7005b582008-11-13 17:18:59 -08001635
Willy Tarreau698b1512008-11-22 11:29:33 +01001636 if (!pprt) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001637 pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
1638 __func__, port->number, parport);
Willy Tarreau698b1512008-11-22 11:29:33 +01001639 return;
1640 }
Aybuke Ozdemirb565b3f2015-10-03 14:52:09 +03001641 if (scan_timer.function)
Sudip Mukherjee7d98c632015-05-12 17:36:08 +05301642 del_timer_sync(&scan_timer);
Willy Tarreau7005b582008-11-13 17:18:59 -08001643
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001644 if (keypad.enabled) {
1645 misc_deregister(&keypad_dev);
1646 keypad_initialized = 0;
Peter Huewe0b0595b2009-09-29 01:22:40 +02001647 }
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001648
1649 if (lcd.enabled) {
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001650 charlcd_unregister(lcd.charlcd);
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001651 lcd.initialized = false;
Andy Shevchenko9b11d632019-03-12 16:44:31 +02001652 charlcd_free(lcd.charlcd);
Geert Uytterhoeven39f8ea42017-03-10 15:15:17 +01001653 lcd.charlcd = NULL;
Geert Uytterhoeven3f77b432017-02-06 15:38:08 +01001654 }
1655
1656 /* TODO: free all input signals */
1657 parport_release(pprt);
1658 parport_unregister_device(pprt);
1659 pprt = NULL;
Willy Tarreau7005b582008-11-13 17:18:59 -08001660}
1661
1662static struct parport_driver panel_driver = {
Willy Tarreau698b1512008-11-22 11:29:33 +01001663 .name = "panel",
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301664 .match_port = panel_attach,
Willy Tarreau698b1512008-11-22 11:29:33 +01001665 .detach = panel_detach,
Sudip Mukherjee9be83c02015-05-20 20:56:58 +05301666 .devmodel = true,
Willy Tarreau7005b582008-11-13 17:18:59 -08001667};
1668
1669/* init function */
Mariusz Gorskid9114762014-11-27 22:36:46 +01001670static int __init panel_init_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001671{
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301672 int selected_keypad_type = NOT_SET, err;
Willy Tarreau7005b582008-11-13 17:18:59 -08001673
Willy Tarreau698b1512008-11-22 11:29:33 +01001674 /* take care of an eventual profile */
1675 switch (profile) {
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001676 case PANEL_PROFILE_CUSTOM:
1677 /* custom profile */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001678 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
1679 selected_lcd_type = DEFAULT_LCD_TYPE;
Willy Tarreau698b1512008-11-22 11:29:33 +01001680 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001681 case PANEL_PROFILE_OLD:
1682 /* 8 bits, 2*16, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001683 selected_keypad_type = KEYPAD_TYPE_OLD;
1684 selected_lcd_type = LCD_TYPE_OLD;
1685
1686 /* TODO: This two are a little hacky, sort it out later */
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001687 if (lcd_width == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001688 lcd_width = 16;
Mariusz Gorski2d35bcf2014-11-27 22:36:48 +01001689 if (lcd_hwidth == NOT_SET)
Willy Tarreau698b1512008-11-22 11:29:33 +01001690 lcd_hwidth = 16;
1691 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001692 case PANEL_PROFILE_NEW:
1693 /* serial, 2*16, new keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001694 selected_keypad_type = KEYPAD_TYPE_NEW;
1695 selected_lcd_type = LCD_TYPE_KS0074;
Willy Tarreau698b1512008-11-22 11:29:33 +01001696 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001697 case PANEL_PROFILE_HANTRONIX:
1698 /* 8 bits, 2*16 hantronix-like, no keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001699 selected_keypad_type = KEYPAD_TYPE_NONE;
1700 selected_lcd_type = LCD_TYPE_HANTRONIX;
Willy Tarreau698b1512008-11-22 11:29:33 +01001701 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001702 case PANEL_PROFILE_NEXCOM:
1703 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001704 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
1705 selected_lcd_type = LCD_TYPE_NEXCOM;
Willy Tarreau698b1512008-11-22 11:29:33 +01001706 break;
Henri Häkkinen429ccf02010-06-12 00:27:36 +03001707 case PANEL_PROFILE_LARGE:
1708 /* 8 bits, 2*40, old keypad */
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001709 selected_keypad_type = KEYPAD_TYPE_OLD;
1710 selected_lcd_type = LCD_TYPE_OLD;
Willy Tarreau698b1512008-11-22 11:29:33 +01001711 break;
Willy Tarreau7005b582008-11-13 17:18:59 -08001712 }
Willy Tarreau7005b582008-11-13 17:18:59 -08001713
Mariusz Gorski8037e2a2014-11-27 22:36:51 +01001714 /*
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001715 * Overwrite selection with module param values (both keypad and lcd),
1716 * where the deprecated params have lower prio.
1717 */
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001718 if (keypad_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001719 selected_keypad_type = keypad_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001720 if (keypad_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001721 selected_keypad_type = keypad_type;
Willy Tarreau7005b582008-11-13 17:18:59 -08001722
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001723 keypad.enabled = (selected_keypad_type > 0);
1724
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001725 if (lcd_enabled != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001726 selected_lcd_type = lcd_enabled;
Mariusz Gorski1a4b2e32014-11-27 22:36:52 +01001727 if (lcd_type != NOT_SET)
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001728 selected_lcd_type = lcd_type;
1729
1730 lcd.enabled = (selected_lcd_type > 0);
1731
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301732 if (lcd.enabled) {
1733 /*
1734 * Init lcd struct with load-time values to preserve exact
1735 * current functionality (at least for now).
1736 */
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301737 lcd.charset = lcd_charset;
1738 lcd.proto = lcd_proto;
1739 lcd.pins.e = lcd_e_pin;
1740 lcd.pins.rs = lcd_rs_pin;
1741 lcd.pins.rw = lcd_rw_pin;
1742 lcd.pins.cl = lcd_cl_pin;
1743 lcd.pins.da = lcd_da_pin;
1744 lcd.pins.bl = lcd_bl_pin;
Sudip Mukherjee733345e2015-02-11 16:57:08 +05301745 }
1746
Mariusz Gorski87b8e0c2014-11-27 22:36:50 +01001747 switch (selected_keypad_type) {
Willy Tarreau698b1512008-11-22 11:29:33 +01001748 case KEYPAD_TYPE_OLD:
1749 keypad_profile = old_keypad_profile;
1750 break;
1751 case KEYPAD_TYPE_NEW:
1752 keypad_profile = new_keypad_profile;
1753 break;
1754 case KEYPAD_TYPE_NEXCOM:
1755 keypad_profile = nexcom_keypad_profile;
1756 break;
1757 default:
1758 keypad_profile = NULL;
1759 break;
1760 }
1761
Sudip Mukherjeef43de772015-02-10 17:26:02 +05301762 if (!lcd.enabled && !keypad.enabled) {
1763 /* no device enabled, let's exit */
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001764 pr_err("panel driver disabled.\n");
Sudip Mukherjeef43de772015-02-10 17:26:02 +05301765 return -ENODEV;
1766 }
1767
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301768 err = parport_register_driver(&panel_driver);
1769 if (err) {
Toshiaki Yamaneeb073a92012-07-12 22:01:17 +09001770 pr_err("could not register with parport. Aborting.\n");
Sudip Mukherjeee1342012015-03-09 20:08:24 +05301771 return err;
Willy Tarreau698b1512008-11-22 11:29:33 +01001772 }
1773
Willy Tarreau698b1512008-11-22 11:29:33 +01001774 if (pprt)
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001775 pr_info("panel driver registered on parport%d (io=0x%lx).\n",
1776 parport, pprt->port->base);
Willy Tarreau698b1512008-11-22 11:29:33 +01001777 else
Geert Uytterhoeven30f468b2017-02-06 15:38:04 +01001778 pr_info("panel driver not yet registered\n");
Willy Tarreau698b1512008-11-22 11:29:33 +01001779 return 0;
Willy Tarreau7005b582008-11-13 17:18:59 -08001780}
1781
Willy Tarreauf6d1fcf2008-11-22 12:04:19 +01001782static void __exit panel_cleanup_module(void)
Willy Tarreau698b1512008-11-22 11:29:33 +01001783{
Willy Tarreau698b1512008-11-22 11:29:33 +01001784 parport_unregister_driver(&panel_driver);
Willy Tarreau7005b582008-11-13 17:18:59 -08001785}
Willy Tarreau7005b582008-11-13 17:18:59 -08001786
Willy Tarreau7005b582008-11-13 17:18:59 -08001787module_init(panel_init_module);
1788module_exit(panel_cleanup_module);
1789MODULE_AUTHOR("Willy Tarreau");
1790MODULE_LICENSE("GPL");
Willy Tarreau7005b582008-11-13 17:18:59 -08001791
1792/*
1793 * Local variables:
1794 * c-indent-level: 4
1795 * tab-width: 8
1796 * End:
1797 */