Miguel Ojeda | 351f683b | 2018-02-17 20:33:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2 | /* |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 3 | * Front panel driver for Linux |
| 4 | * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 5 | * Copyright (C) 2016-2017 Glider bvba |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 6 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 7 | * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad) |
| 8 | * connected to a parallel printer port. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 9 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 10 | * 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 Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 13 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 14 | * 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 Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 17 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 18 | * Several profiles are provided for commonly found LCD+keypad modules on the |
| 19 | * market, such as those found in Nexcom's appliances. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 20 | * |
| 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 Yamane | 493aa89 | 2012-07-12 22:01:00 +0900 | [diff] [blame] | 34 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 35 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 36 | #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 Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/miscdevice.h> |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 45 | #include <linux/slab.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 46 | #include <linux/ioport.h> |
| 47 | #include <linux/fcntl.h> |
| 48 | #include <linux/init.h> |
| 49 | #include <linux/delay.h> |
Andy Shevchenko | d85170e | 2010-07-22 19:57:08 +0300 | [diff] [blame] | 50 | #include <linux/kernel.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 51 | #include <linux/ctype.h> |
| 52 | #include <linux/parport.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 53 | #include <linux/list.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 54 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 55 | #include <linux/io.h> |
Takanori Suzuki | 48f658b | 2010-05-08 22:56:24 +0900 | [diff] [blame] | 56 | #include <linux/uaccess.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 57 | |
Masahiro Yamada | 7535428 | 2019-08-06 16:14:44 +0900 | [diff] [blame] | 58 | #include "charlcd.h" |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 59 | #include "hd44780_common.h" |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 60 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 61 | #define LCD_MAXBYTES 256 /* max burst write */ |
| 62 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 63 | #define KEYPAD_BUFFER 64 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 64 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 65 | /* poll the keyboard this every second */ |
Sirnam Swetha | 2b3c9eb | 2015-10-27 14:54:51 +0530 | [diff] [blame] | 66 | #define INPUT_POLL_TIME (HZ / 50) |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 67 | /* a key starts to repeat after this times INPUT_POLL_TIME */ |
| 68 | #define KEYPAD_REP_START (10) |
| 69 | /* a key repeats this times INPUT_POLL_TIME */ |
| 70 | #define KEYPAD_REP_DELAY (2) |
| 71 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 72 | /* converts an r_str() input to an active high, bits string : 000BAOSE */ |
| 73 | #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3) |
| 74 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 75 | #define PNL_PBUSY 0x80 /* inverted input, active low */ |
| 76 | #define PNL_PACK 0x40 /* direct input, active low */ |
| 77 | #define PNL_POUTPA 0x20 /* direct input, active high */ |
| 78 | #define PNL_PSELECD 0x10 /* direct input, active high */ |
| 79 | #define PNL_PERRORP 0x08 /* direct input, active low */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 80 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 81 | #define PNL_PBIDIR 0x20 /* bi-directional ports */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 82 | /* high to read data in or-ed with data out */ |
| 83 | #define PNL_PINTEN 0x10 |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 84 | #define PNL_PSELECP 0x08 /* inverted output, active low */ |
| 85 | #define PNL_PINITP 0x04 /* direct output, active low */ |
| 86 | #define PNL_PAUTOLF 0x02 /* inverted output, active low */ |
| 87 | #define PNL_PSTROBE 0x01 /* inverted output */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 88 | |
| 89 | #define PNL_PD0 0x01 |
| 90 | #define PNL_PD1 0x02 |
| 91 | #define PNL_PD2 0x04 |
| 92 | #define PNL_PD3 0x08 |
| 93 | #define PNL_PD4 0x10 |
| 94 | #define PNL_PD5 0x20 |
| 95 | #define PNL_PD6 0x40 |
| 96 | #define PNL_PD7 0x80 |
| 97 | |
| 98 | #define PIN_NONE 0 |
| 99 | #define PIN_STROBE 1 |
| 100 | #define PIN_D0 2 |
| 101 | #define PIN_D1 3 |
| 102 | #define PIN_D2 4 |
| 103 | #define PIN_D3 5 |
| 104 | #define PIN_D4 6 |
| 105 | #define PIN_D5 7 |
| 106 | #define PIN_D6 8 |
| 107 | #define PIN_D7 9 |
| 108 | #define PIN_AUTOLF 14 |
| 109 | #define PIN_INITP 16 |
| 110 | #define PIN_SELECP 17 |
| 111 | #define PIN_NOT_SET 127 |
| 112 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 113 | #define NOT_SET -1 |
| 114 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 115 | /* macros to simplify use of the parallel port */ |
| 116 | #define r_ctr(x) (parport_read_control((x)->port)) |
| 117 | #define r_dtr(x) (parport_read_data((x)->port)) |
| 118 | #define r_str(x) (parport_read_status((x)->port)) |
Toshiaki Yamane | 6ebb56d | 2012-07-25 12:18:12 +0900 | [diff] [blame] | 119 | #define w_ctr(x, y) (parport_write_control((x)->port, (y))) |
| 120 | #define w_dtr(x, y) (parport_write_data((x)->port, (y))) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 121 | |
| 122 | /* this defines which bits are to be used and which ones to be ignored */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 123 | /* logical or of the output bits involved in the scan matrix */ |
| 124 | static __u8 scan_mask_o; |
| 125 | /* logical or of the input bits involved in the scan matrix */ |
| 126 | static __u8 scan_mask_i; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 127 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 128 | enum input_type { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 129 | INPUT_TYPE_STD, |
| 130 | INPUT_TYPE_KBD, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | enum input_state { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 134 | INPUT_ST_LOW, |
| 135 | INPUT_ST_RISING, |
| 136 | INPUT_ST_HIGH, |
| 137 | INPUT_ST_FALLING, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | struct logical_input { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 141 | struct list_head list; |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 142 | __u64 mask; |
| 143 | __u64 value; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 144 | enum input_type type; |
| 145 | enum input_state state; |
| 146 | __u8 rise_time, fall_time; |
| 147 | __u8 rise_timer, fall_timer, high_timer; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 148 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 149 | union { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 150 | struct { /* valid when type == INPUT_TYPE_STD */ |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 151 | void (*press_fct)(int); |
| 152 | void (*release_fct)(int); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 153 | int press_data; |
| 154 | int release_data; |
| 155 | } std; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 156 | struct { /* valid when type == INPUT_TYPE_KBD */ |
Miguel Ojeda | 98cade0 | 2018-08-14 21:38:26 +0200 | [diff] [blame] | 157 | char press_str[sizeof(void *) + sizeof(int)] __nonstring; |
| 158 | char repeat_str[sizeof(void *) + sizeof(int)] __nonstring; |
| 159 | char release_str[sizeof(void *) + sizeof(int)] __nonstring; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 160 | } kbd; |
| 161 | } u; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 164 | static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 165 | |
| 166 | /* physical contacts history |
| 167 | * Physical contacts are a 45 bits string of 9 groups of 5 bits each. |
| 168 | * The 8 lower groups correspond to output bits 0 to 7, and the 9th group |
| 169 | * corresponds to the ground. |
| 170 | * Within each group, bits are stored in the same order as read on the port : |
| 171 | * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0). |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 172 | * So, each __u64 is represented like this : |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 173 | * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE |
| 174 | * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00> |
| 175 | */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 176 | |
| 177 | /* what has just been read from the I/O ports */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 178 | static __u64 phys_read; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 179 | /* previous phys_read */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 180 | static __u64 phys_read_prev; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 181 | /* stabilized phys_read (phys_read|phys_read_prev) */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 182 | static __u64 phys_curr; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 183 | /* previous phys_curr */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 184 | static __u64 phys_prev; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 185 | /* 0 means that at least one logical signal needs be computed */ |
| 186 | static char inputs_stable; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 187 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 188 | /* these variables are specific to the keypad */ |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 189 | static struct { |
| 190 | bool enabled; |
| 191 | } keypad; |
| 192 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 193 | static char keypad_buffer[KEYPAD_BUFFER]; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 194 | static int keypad_buflen; |
| 195 | static int keypad_start; |
| 196 | static char keypressed; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 197 | static wait_queue_head_t keypad_read_wait; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 198 | |
| 199 | /* lcd-specific variables */ |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 200 | static struct { |
| 201 | bool enabled; |
Mariusz Gorski | 6d8b588 | 2014-11-27 22:36:53 +0100 | [diff] [blame] | 202 | bool initialized; |
Mariusz Gorski | 6d8b588 | 2014-11-27 22:36:53 +0100 | [diff] [blame] | 203 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 204 | int charset; |
| 205 | int proto; |
Geert Uytterhoeven | fda4ae1 | 2017-02-06 15:38:10 +0100 | [diff] [blame] | 206 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 207 | /* TODO: use union here? */ |
| 208 | struct { |
| 209 | int e; |
| 210 | int rs; |
| 211 | int rw; |
| 212 | int cl; |
| 213 | int da; |
| 214 | int bl; |
| 215 | } pins; |
Mariusz Gorski | 6d8b588 | 2014-11-27 22:36:53 +0100 | [diff] [blame] | 216 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 217 | struct charlcd *charlcd; |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 218 | } lcd; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 219 | |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 220 | /* Needed only for init */ |
| 221 | static int selected_lcd_type = NOT_SET; |
| 222 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 223 | /* |
| 224 | * Bit masks to convert LCD signals to parallel port outputs. |
| 225 | * _d_ are values for data port, _c_ are for control port. |
| 226 | * [0] = signal OFF, [1] = signal ON, [2] = mask |
| 227 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 228 | #define BIT_CLR 0 |
| 229 | #define BIT_SET 1 |
| 230 | #define BIT_MSK 2 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 231 | #define BIT_STATES 3 |
| 232 | /* |
| 233 | * one entry for each bit on the LCD |
| 234 | */ |
| 235 | #define LCD_BIT_E 0 |
| 236 | #define LCD_BIT_RS 1 |
| 237 | #define LCD_BIT_RW 2 |
| 238 | #define LCD_BIT_BL 3 |
| 239 | #define LCD_BIT_CL 4 |
| 240 | #define LCD_BIT_DA 5 |
| 241 | #define LCD_BITS 6 |
| 242 | |
| 243 | /* |
| 244 | * each bit can be either connected to a DATA or CTRL port |
| 245 | */ |
| 246 | #define LCD_PORT_C 0 |
| 247 | #define LCD_PORT_D 1 |
| 248 | #define LCD_PORTS 2 |
| 249 | |
| 250 | static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES]; |
| 251 | |
| 252 | /* |
| 253 | * LCD protocols |
| 254 | */ |
| 255 | #define LCD_PROTO_PARALLEL 0 |
| 256 | #define LCD_PROTO_SERIAL 1 |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 257 | #define LCD_PROTO_TI_DA8XX_LCD 2 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * LCD character sets |
| 261 | */ |
| 262 | #define LCD_CHARSET_NORMAL 0 |
| 263 | #define LCD_CHARSET_KS0074 1 |
| 264 | |
| 265 | /* |
| 266 | * LCD types |
| 267 | */ |
| 268 | #define LCD_TYPE_NONE 0 |
Sudip Mukherjee | 2c20d92 | 2015-03-24 16:29:32 +0530 | [diff] [blame] | 269 | #define LCD_TYPE_CUSTOM 1 |
| 270 | #define LCD_TYPE_OLD 2 |
| 271 | #define LCD_TYPE_KS0074 3 |
| 272 | #define LCD_TYPE_HANTRONIX 4 |
| 273 | #define LCD_TYPE_NEXCOM 5 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * keypad types |
| 277 | */ |
| 278 | #define KEYPAD_TYPE_NONE 0 |
| 279 | #define KEYPAD_TYPE_OLD 1 |
| 280 | #define KEYPAD_TYPE_NEW 2 |
| 281 | #define KEYPAD_TYPE_NEXCOM 3 |
| 282 | |
| 283 | /* |
| 284 | * panel profiles |
| 285 | */ |
| 286 | #define PANEL_PROFILE_CUSTOM 0 |
| 287 | #define PANEL_PROFILE_OLD 1 |
| 288 | #define PANEL_PROFILE_NEW 2 |
| 289 | #define PANEL_PROFILE_HANTRONIX 3 |
| 290 | #define PANEL_PROFILE_NEXCOM 4 |
| 291 | #define PANEL_PROFILE_LARGE 5 |
| 292 | |
| 293 | /* |
| 294 | * Construct custom config from the kernel's configuration |
| 295 | */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 296 | #define DEFAULT_PARPORT 0 |
Mariusz Gorski | fe4d7e2 | 2014-11-12 02:08:06 +0100 | [diff] [blame] | 297 | #define DEFAULT_PROFILE PANEL_PROFILE_LARGE |
Mariusz Gorski | 98fac3d | 2014-11-12 02:08:09 +0100 | [diff] [blame] | 298 | #define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD |
| 299 | #define DEFAULT_LCD_TYPE LCD_TYPE_OLD |
Mariusz Gorski | fe4d7e2 | 2014-11-12 02:08:06 +0100 | [diff] [blame] | 300 | #define DEFAULT_LCD_HEIGHT 2 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 301 | #define DEFAULT_LCD_WIDTH 40 |
Mariusz Gorski | fe4d7e2 | 2014-11-12 02:08:06 +0100 | [diff] [blame] | 302 | #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 303 | #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL |
| 304 | |
| 305 | #define DEFAULT_LCD_PIN_E PIN_AUTOLF |
| 306 | #define DEFAULT_LCD_PIN_RS PIN_SELECP |
| 307 | #define DEFAULT_LCD_PIN_RW PIN_INITP |
| 308 | #define DEFAULT_LCD_PIN_SCL PIN_STROBE |
| 309 | #define DEFAULT_LCD_PIN_SDA PIN_D0 |
| 310 | #define DEFAULT_LCD_PIN_BL PIN_NOT_SET |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 311 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 312 | #ifdef CONFIG_PANEL_PARPORT |
| 313 | #undef DEFAULT_PARPORT |
| 314 | #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT |
| 315 | #endif |
| 316 | |
Mariusz Gorski | 1e13e8a | 2014-11-12 02:08:07 +0100 | [diff] [blame] | 317 | #ifdef CONFIG_PANEL_PROFILE |
| 318 | #undef DEFAULT_PROFILE |
| 319 | #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE |
| 320 | #endif |
| 321 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 322 | #if DEFAULT_PROFILE == 0 /* custom */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 323 | #ifdef CONFIG_PANEL_KEYPAD |
Mariusz Gorski | 98fac3d | 2014-11-12 02:08:09 +0100 | [diff] [blame] | 324 | #undef DEFAULT_KEYPAD_TYPE |
| 325 | #define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 326 | #endif |
| 327 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 328 | #ifdef CONFIG_PANEL_LCD |
Mariusz Gorski | 98fac3d | 2014-11-12 02:08:09 +0100 | [diff] [blame] | 329 | #undef DEFAULT_LCD_TYPE |
| 330 | #define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 331 | #endif |
| 332 | |
Mariusz Gorski | 1e13e8a | 2014-11-12 02:08:07 +0100 | [diff] [blame] | 333 | #ifdef CONFIG_PANEL_LCD_HEIGHT |
| 334 | #undef DEFAULT_LCD_HEIGHT |
| 335 | #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT |
| 336 | #endif |
| 337 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 338 | #ifdef CONFIG_PANEL_LCD_WIDTH |
| 339 | #undef DEFAULT_LCD_WIDTH |
| 340 | #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH |
| 341 | #endif |
| 342 | |
| 343 | #ifdef CONFIG_PANEL_LCD_BWIDTH |
| 344 | #undef DEFAULT_LCD_BWIDTH |
| 345 | #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH |
| 346 | #endif |
| 347 | |
| 348 | #ifdef CONFIG_PANEL_LCD_HWIDTH |
| 349 | #undef DEFAULT_LCD_HWIDTH |
| 350 | #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH |
| 351 | #endif |
| 352 | |
Mariusz Gorski | 1e13e8a | 2014-11-12 02:08:07 +0100 | [diff] [blame] | 353 | #ifdef CONFIG_PANEL_LCD_CHARSET |
| 354 | #undef DEFAULT_LCD_CHARSET |
| 355 | #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 356 | #endif |
| 357 | |
| 358 | #ifdef CONFIG_PANEL_LCD_PROTO |
| 359 | #undef DEFAULT_LCD_PROTO |
| 360 | #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO |
| 361 | #endif |
| 362 | |
| 363 | #ifdef CONFIG_PANEL_LCD_PIN_E |
| 364 | #undef DEFAULT_LCD_PIN_E |
| 365 | #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E |
| 366 | #endif |
| 367 | |
| 368 | #ifdef CONFIG_PANEL_LCD_PIN_RS |
| 369 | #undef DEFAULT_LCD_PIN_RS |
| 370 | #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS |
| 371 | #endif |
| 372 | |
| 373 | #ifdef CONFIG_PANEL_LCD_PIN_RW |
| 374 | #undef DEFAULT_LCD_PIN_RW |
| 375 | #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW |
| 376 | #endif |
| 377 | |
| 378 | #ifdef CONFIG_PANEL_LCD_PIN_SCL |
| 379 | #undef DEFAULT_LCD_PIN_SCL |
| 380 | #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL |
| 381 | #endif |
| 382 | |
| 383 | #ifdef CONFIG_PANEL_LCD_PIN_SDA |
| 384 | #undef DEFAULT_LCD_PIN_SDA |
| 385 | #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA |
| 386 | #endif |
| 387 | |
| 388 | #ifdef CONFIG_PANEL_LCD_PIN_BL |
| 389 | #undef DEFAULT_LCD_PIN_BL |
| 390 | #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL |
| 391 | #endif |
| 392 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 393 | #endif /* DEFAULT_PROFILE == 0 */ |
| 394 | |
| 395 | /* global variables */ |
Mariusz Gorski | f4757af | 2014-11-04 22:47:19 +0100 | [diff] [blame] | 396 | |
| 397 | /* Device single-open policy control */ |
Mariusz Gorski | f4757af | 2014-11-04 22:47:19 +0100 | [diff] [blame] | 398 | static atomic_t keypad_available = ATOMIC_INIT(1); |
| 399 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 400 | static struct pardevice *pprt; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 401 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 402 | static int keypad_initialized; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 403 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 404 | static DEFINE_SPINLOCK(pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 405 | static struct timer_list scan_timer; |
| 406 | |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 407 | MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 408 | |
Mariusz Gorski | 59a66a2 | 2014-11-27 22:36:45 +0100 | [diff] [blame] | 409 | static int parport = DEFAULT_PARPORT; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 410 | module_param(parport, int, 0000); |
| 411 | MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 412 | |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 413 | static int profile = DEFAULT_PROFILE; |
| 414 | module_param(profile, int, 0000); |
| 415 | MODULE_PARM_DESC(profile, |
| 416 | "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; " |
| 417 | "4=16x2 nexcom; default=40x2, old kp"); |
| 418 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 419 | static int keypad_type = NOT_SET; |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 420 | module_param(keypad_type, int, 0000); |
| 421 | MODULE_PARM_DESC(keypad_type, |
| 422 | "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys"); |
| 423 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 424 | static int lcd_type = NOT_SET; |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 425 | module_param(lcd_type, int, 0000); |
| 426 | MODULE_PARM_DESC(lcd_type, |
Sudip Mukherjee | 2c20d92 | 2015-03-24 16:29:32 +0530 | [diff] [blame] | 427 | "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom"); |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 428 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 429 | static int lcd_height = NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 430 | module_param(lcd_height, int, 0000); |
| 431 | MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 432 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 433 | static int lcd_width = NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 434 | module_param(lcd_width, int, 0000); |
| 435 | MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 436 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 437 | static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 438 | module_param(lcd_bwidth, int, 0000); |
| 439 | MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 440 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 441 | static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 442 | module_param(lcd_hwidth, int, 0000); |
| 443 | MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 444 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 445 | static int lcd_charset = NOT_SET; |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 446 | module_param(lcd_charset, int, 0000); |
| 447 | MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 448 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 449 | static int lcd_proto = NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 450 | module_param(lcd_proto, int, 0000); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 451 | MODULE_PARM_DESC(lcd_proto, |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 452 | "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 453 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 454 | /* |
| 455 | * These are the parallel port pins the LCD control signals are connected to. |
| 456 | * Set this to 0 if the signal is not used. Set it to its opposite value |
| 457 | * (negative) if the signal is negated. -MAXINT is used to indicate that the |
| 458 | * pin has not been explicitly specified. |
| 459 | * |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 460 | * WARNING! no check will be performed about collisions with keypad ! |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 461 | */ |
| 462 | |
| 463 | static int lcd_e_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 464 | module_param(lcd_e_pin, int, 0000); |
| 465 | MODULE_PARM_DESC(lcd_e_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 466 | "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 467 | |
| 468 | static int lcd_rs_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 469 | module_param(lcd_rs_pin, int, 0000); |
| 470 | MODULE_PARM_DESC(lcd_rs_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 471 | "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 472 | |
| 473 | static int lcd_rw_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 474 | module_param(lcd_rw_pin, int, 0000); |
| 475 | MODULE_PARM_DESC(lcd_rw_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 476 | "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 477 | |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 478 | static int lcd_cl_pin = PIN_NOT_SET; |
| 479 | module_param(lcd_cl_pin, int, 0000); |
| 480 | MODULE_PARM_DESC(lcd_cl_pin, |
| 481 | "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 482 | |
| 483 | static int lcd_da_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 484 | module_param(lcd_da_pin, int, 0000); |
| 485 | MODULE_PARM_DESC(lcd_da_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 486 | "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 487 | |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 488 | static int lcd_bl_pin = PIN_NOT_SET; |
| 489 | module_param(lcd_bl_pin, int, 0000); |
| 490 | MODULE_PARM_DESC(lcd_bl_pin, |
| 491 | "# of the // port pin connected to LCD backlight, with polarity (-17..17)"); |
| 492 | |
| 493 | /* Deprecated module parameters - consider not using them anymore */ |
| 494 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 495 | static int lcd_enabled = NOT_SET; |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 496 | module_param(lcd_enabled, int, 0000); |
| 497 | MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead"); |
| 498 | |
Mariusz Gorski | 36277d4 | 2014-11-27 22:36:47 +0100 | [diff] [blame] | 499 | static int keypad_enabled = NOT_SET; |
Mariusz Gorski | 98e0e76 | 2014-11-12 02:08:08 +0100 | [diff] [blame] | 500 | module_param(keypad_enabled, int, 0000); |
| 501 | MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead"); |
| 502 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 503 | /* for some LCD drivers (ks0074) we need a charset conversion table. */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 504 | static const unsigned char lcd_char_conv_ks0074[256] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 505 | /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */ |
| 506 | /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 507 | /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 508 | /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 509 | /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 510 | /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27, |
| 511 | /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, |
| 512 | /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
| 513 | /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, |
| 514 | /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
| 515 | /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, |
| 516 | /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, |
| 517 | /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4, |
| 518 | /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 519 | /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
| 520 | /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 521 | /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20, |
| 522 | /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 523 | /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, |
| 524 | /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 525 | /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, |
| 526 | /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f, |
| 527 | /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96, |
| 528 | /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd, |
| 529 | /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60, |
| 530 | /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9, |
| 531 | /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3, |
| 532 | /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78, |
| 533 | /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe, |
| 534 | /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8, |
| 535 | /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69, |
| 536 | /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25, |
| 537 | /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 538 | }; |
| 539 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 540 | static const char old_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 541 | {"S0", "Left\n", "Left\n", ""}, |
| 542 | {"S1", "Down\n", "Down\n", ""}, |
| 543 | {"S2", "Up\n", "Up\n", ""}, |
| 544 | {"S3", "Right\n", "Right\n", ""}, |
| 545 | {"S4", "Esc\n", "Esc\n", ""}, |
| 546 | {"S5", "Ret\n", "Ret\n", ""}, |
| 547 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 548 | }; |
| 549 | |
| 550 | /* signals, press, repeat, release */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 551 | static const char new_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 552 | {"S0", "Left\n", "Left\n", ""}, |
| 553 | {"S1", "Down\n", "Down\n", ""}, |
| 554 | {"S2", "Up\n", "Up\n", ""}, |
| 555 | {"S3", "Right\n", "Right\n", ""}, |
| 556 | {"S4s5", "", "Esc\n", "Esc\n"}, |
| 557 | {"s4S5", "", "Ret\n", "Ret\n"}, |
| 558 | {"S4S5", "Help\n", "", ""}, |
| 559 | /* add new signals above this line */ |
| 560 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 561 | }; |
| 562 | |
| 563 | /* signals, press, repeat, release */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 564 | static const char nexcom_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 565 | {"a-p-e-", "Down\n", "Down\n", ""}, |
| 566 | {"a-p-E-", "Ret\n", "Ret\n", ""}, |
| 567 | {"a-P-E-", "Esc\n", "Esc\n", ""}, |
| 568 | {"a-P-e-", "Up\n", "Up\n", ""}, |
| 569 | /* add new signals above this line */ |
| 570 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 571 | }; |
| 572 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 573 | static const char (*keypad_profile)[4][9] = old_keypad_profile; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 574 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 575 | static DECLARE_BITMAP(bits, LCD_BITS); |
| 576 | |
| 577 | static void lcd_get_bits(unsigned int port, int *val) |
| 578 | { |
| 579 | unsigned int bit, state; |
| 580 | |
| 581 | for (bit = 0; bit < LCD_BITS; bit++) { |
| 582 | state = test_bit(bit, bits) ? BIT_SET : BIT_CLR; |
| 583 | *val &= lcd_bits[port][bit][BIT_MSK]; |
| 584 | *val |= lcd_bits[port][bit][state]; |
| 585 | } |
| 586 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 587 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 588 | /* sets data port bits according to current signals values */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 589 | static int set_data_bits(void) |
| 590 | { |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 591 | int val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 592 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 593 | val = r_dtr(pprt); |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 594 | lcd_get_bits(LCD_PORT_D, &val); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 595 | w_dtr(pprt, val); |
| 596 | return val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* sets ctrl port bits according to current signals values */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 600 | static int set_ctrl_bits(void) |
| 601 | { |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 602 | int val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 603 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 604 | val = r_ctr(pprt); |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 605 | lcd_get_bits(LCD_PORT_C, &val); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 606 | w_ctr(pprt, val); |
| 607 | return val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* sets ctrl & data port bits according to current signals values */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 611 | static void panel_set_bits(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 612 | { |
| 613 | set_data_bits(); |
| 614 | set_ctrl_bits(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Converts a parallel port pin (from -25 to 25) to data and control ports |
| 619 | * masks, and data and control port bits. The signal will be considered |
| 620 | * unconnected if it's on pin 0 or an invalid pin (<-25 or >25). |
| 621 | * |
| 622 | * Result will be used this way : |
| 623 | * out(dport, in(dport) & d_val[2] | d_val[signal_state]) |
| 624 | * out(cport, in(cport) & c_val[2] | c_val[signal_state]) |
| 625 | */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 626 | static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 627 | { |
| 628 | int d_bit, c_bit, inv; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 629 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame] | 630 | d_val[0] = 0; |
| 631 | c_val[0] = 0; |
| 632 | d_val[1] = 0; |
| 633 | c_val[1] = 0; |
| 634 | d_val[2] = 0xFF; |
| 635 | c_val[2] = 0xFF; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 636 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 637 | if (pin == 0) |
| 638 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 639 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 640 | inv = (pin < 0); |
| 641 | if (inv) |
| 642 | pin = -pin; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 643 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame] | 644 | d_bit = 0; |
| 645 | c_bit = 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 646 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 647 | switch (pin) { |
| 648 | case PIN_STROBE: /* strobe, inverted */ |
| 649 | c_bit = PNL_PSTROBE; |
| 650 | inv = !inv; |
| 651 | break; |
| 652 | case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */ |
| 653 | d_bit = 1 << (pin - 2); |
| 654 | break; |
| 655 | case PIN_AUTOLF: /* autofeed, inverted */ |
| 656 | c_bit = PNL_PAUTOLF; |
| 657 | inv = !inv; |
| 658 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 659 | case PIN_INITP: /* init, direct */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 660 | c_bit = PNL_PINITP; |
| 661 | break; |
| 662 | case PIN_SELECP: /* select_in, inverted */ |
| 663 | c_bit = PNL_PSELECP; |
| 664 | inv = !inv; |
| 665 | break; |
| 666 | default: /* unknown pin, ignore */ |
| 667 | break; |
| 668 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 669 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 670 | if (c_bit) { |
| 671 | c_val[2] &= ~c_bit; |
| 672 | c_val[!inv] = c_bit; |
| 673 | } else if (d_bit) { |
| 674 | d_val[2] &= ~d_bit; |
| 675 | d_val[!inv] = d_bit; |
| 676 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Alex Wilson | 881bf281 | 2015-07-31 11:08:29 -0600 | [diff] [blame] | 679 | /* |
| 680 | * send a serial byte to the LCD panel. The caller is responsible for locking |
| 681 | * if needed. |
| 682 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 683 | static void lcd_send_serial(int byte) |
| 684 | { |
| 685 | int bit; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 686 | |
Alex Wilson | 881bf281 | 2015-07-31 11:08:29 -0600 | [diff] [blame] | 687 | /* |
| 688 | * the data bit is set on D0, and the clock on STROBE. |
| 689 | * LCD reads D0 on STROBE's rising edge. |
| 690 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 691 | for (bit = 0; bit < 8; bit++) { |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 692 | clear_bit(LCD_BIT_CL, bits); /* CLK low */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 693 | panel_set_bits(); |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 694 | if (byte & 1) { |
| 695 | set_bit(LCD_BIT_DA, bits); |
| 696 | } else { |
| 697 | clear_bit(LCD_BIT_DA, bits); |
| 698 | } |
| 699 | |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 700 | panel_set_bits(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 701 | udelay(2); /* maintain the data during 2 us before CLK up */ |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 702 | set_bit(LCD_BIT_CL, bits); /* CLK high */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 703 | panel_set_bits(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 704 | udelay(1); /* maintain the strobe during 1 us */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 705 | byte >>= 1; |
| 706 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* turn the backlight on or off */ |
Lars Poeschel | 66ce7d5 | 2020-11-03 10:58:04 +0100 | [diff] [blame] | 710 | static void lcd_backlight(struct charlcd *charlcd, enum charlcd_onoff on) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 711 | { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 712 | if (lcd.pins.bl == PIN_NONE) |
| 713 | return; |
| 714 | |
Justin P. Mattock | 6975e18 | 2012-03-19 08:17:52 -0700 | [diff] [blame] | 715 | /* The backlight is activated by setting the AUTOFEED line to +5V */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 716 | spin_lock_irq(&pprt_lock); |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 717 | if (on) |
| 718 | set_bit(LCD_BIT_BL, bits); |
| 719 | else |
| 720 | clear_bit(LCD_BIT_BL, bits); |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 721 | panel_set_bits(); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 722 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /* send a command to the LCD panel in serial mode */ |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 726 | static void lcd_write_cmd_s(struct hd44780_common *hdc, int cmd) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 727 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 728 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 729 | lcd_send_serial(0x1F); /* R/W=W, RS=0 */ |
| 730 | lcd_send_serial(cmd & 0x0F); |
| 731 | lcd_send_serial((cmd >> 4) & 0x0F); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 732 | udelay(40); /* the shortest command takes at least 40 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 733 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /* send data to the LCD panel in serial mode */ |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 737 | static void lcd_write_data_s(struct hd44780_common *hdc, int data) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 738 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 739 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 740 | lcd_send_serial(0x5F); /* R/W=W, RS=1 */ |
| 741 | lcd_send_serial(data & 0x0F); |
| 742 | lcd_send_serial((data >> 4) & 0x0F); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 743 | udelay(40); /* the shortest data takes at least 40 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 744 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /* send a command to the LCD panel in 8 bits parallel mode */ |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 748 | static void lcd_write_cmd_p8(struct hd44780_common *hdc, int cmd) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 749 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 750 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 751 | /* present the data to the data port */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 752 | w_dtr(pprt, cmd); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 753 | udelay(20); /* maintain the data during 20 us before the strobe */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 754 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 755 | set_bit(LCD_BIT_E, bits); |
| 756 | clear_bit(LCD_BIT_RS, bits); |
| 757 | clear_bit(LCD_BIT_RW, bits); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 758 | set_ctrl_bits(); |
| 759 | |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 760 | udelay(40); /* maintain the strobe during 40 us */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 761 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 762 | clear_bit(LCD_BIT_E, bits); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 763 | set_ctrl_bits(); |
| 764 | |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 765 | udelay(120); /* the shortest command takes at least 120 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 766 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 767 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 768 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 769 | /* send data to the LCD panel in 8 bits parallel mode */ |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 770 | static void lcd_write_data_p8(struct hd44780_common *hdc, int data) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 771 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 772 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 773 | /* present the data to the data port */ |
| 774 | w_dtr(pprt, data); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 775 | udelay(20); /* maintain the data during 20 us before the strobe */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 776 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 777 | set_bit(LCD_BIT_E, bits); |
| 778 | set_bit(LCD_BIT_RS, bits); |
| 779 | clear_bit(LCD_BIT_RW, bits); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 780 | set_ctrl_bits(); |
| 781 | |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 782 | udelay(40); /* maintain the strobe during 40 us */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 783 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 784 | clear_bit(LCD_BIT_E, bits); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 785 | set_ctrl_bits(); |
| 786 | |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 787 | udelay(45); /* the shortest data takes at least 45 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 788 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 789 | } |
| 790 | |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 791 | /* send a command to the TI LCD panel */ |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 792 | static void lcd_write_cmd_tilcd(struct hd44780_common *hdc, int cmd) |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 793 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 794 | spin_lock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 795 | /* present the data to the control port */ |
| 796 | w_ctr(pprt, cmd); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 797 | udelay(60); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 798 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /* send data to the TI LCD panel */ |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 802 | static void lcd_write_data_tilcd(struct hd44780_common *hdc, int data) |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 803 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 804 | spin_lock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 805 | /* present the data to the data port */ |
| 806 | w_dtr(pprt, data); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 807 | udelay(60); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 808 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 811 | /* fills the display with spaces and resets X/Y */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 812 | static void lcd_clear_fast_s(struct charlcd *charlcd) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 813 | { |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 814 | struct hd44780_common *hdc = charlcd->drvdata; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 815 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 816 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 817 | spin_lock_irq(&pprt_lock); |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 818 | for (pos = 0; pos < charlcd->height * hdc->hwidth; pos++) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 819 | lcd_send_serial(0x5F); /* R/W=W, RS=1 */ |
| 820 | lcd_send_serial(' ' & 0x0F); |
| 821 | lcd_send_serial((' ' >> 4) & 0x0F); |
Ricardo Ruedas | df44f15 | 2015-12-08 22:30:40 +0100 | [diff] [blame] | 822 | /* the shortest data takes at least 40 us */ |
Greg Kroah-Hartman | 4cff7ad | 2016-02-01 12:50:26 -0800 | [diff] [blame] | 823 | udelay(40); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 824 | } |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 825 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /* fills the display with spaces and resets X/Y */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 829 | static void lcd_clear_fast_p8(struct charlcd *charlcd) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 830 | { |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 831 | struct hd44780_common *hdc = charlcd->drvdata; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 832 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 833 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 834 | spin_lock_irq(&pprt_lock); |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 835 | for (pos = 0; pos < charlcd->height * hdc->hwidth; pos++) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 836 | /* present the data to the data port */ |
| 837 | w_dtr(pprt, ' '); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 838 | |
| 839 | /* maintain the data during 20 us before the strobe */ |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 840 | udelay(20); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 841 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 842 | set_bit(LCD_BIT_E, bits); |
| 843 | set_bit(LCD_BIT_RS, bits); |
| 844 | clear_bit(LCD_BIT_RW, bits); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 845 | set_ctrl_bits(); |
| 846 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 847 | /* maintain the strobe during 40 us */ |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 848 | udelay(40); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 849 | |
Daniel Chromik | bea7433 | 2016-02-11 13:29:23 +0100 | [diff] [blame] | 850 | clear_bit(LCD_BIT_E, bits); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 851 | set_ctrl_bits(); |
| 852 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 853 | /* the shortest data takes at least 45 us */ |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 854 | udelay(45); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 855 | } |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 856 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 859 | /* fills the display with spaces and resets X/Y */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 860 | static void lcd_clear_fast_tilcd(struct charlcd *charlcd) |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 861 | { |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 862 | struct hd44780_common *hdc = charlcd->drvdata; |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 863 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 864 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 865 | spin_lock_irq(&pprt_lock); |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 866 | for (pos = 0; pos < charlcd->height * hdc->hwidth; pos++) { |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 867 | /* present the data to the data port */ |
| 868 | w_dtr(pprt, ' '); |
Sudip Mukherjee | b64a1cb | 2016-01-23 14:49:20 +0530 | [diff] [blame] | 869 | udelay(60); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 872 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 873 | } |
| 874 | |
Arvind Yadav | 7b948f1 | 2017-07-14 22:04:49 +0530 | [diff] [blame] | 875 | static const struct charlcd_ops charlcd_serial_ops = { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 876 | .clear_fast = lcd_clear_fast_s, |
| 877 | .backlight = lcd_backlight, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 878 | }; |
| 879 | |
Arvind Yadav | 7b948f1 | 2017-07-14 22:04:49 +0530 | [diff] [blame] | 880 | static const struct charlcd_ops charlcd_parallel_ops = { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 881 | .clear_fast = lcd_clear_fast_p8, |
| 882 | .backlight = lcd_backlight, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 883 | }; |
| 884 | |
Arvind Yadav | 7b948f1 | 2017-07-14 22:04:49 +0530 | [diff] [blame] | 885 | static const struct charlcd_ops charlcd_tilcd_ops = { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 886 | .clear_fast = lcd_clear_fast_tilcd, |
| 887 | .backlight = lcd_backlight, |
| 888 | }; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 889 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 890 | /* initialize the LCD driver */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 891 | static void lcd_init(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 892 | { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 893 | struct charlcd *charlcd; |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 894 | struct hd44780_common *hdc; |
| 895 | |
| 896 | hdc = hd44780_common_alloc(); |
| 897 | if (!hdc) |
| 898 | return; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 899 | |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 900 | charlcd = charlcd_alloc(); |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 901 | if (!charlcd) { |
| 902 | kfree(hdc); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 903 | return; |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | hdc->hd44780 = &lcd; |
| 907 | charlcd->drvdata = hdc; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 908 | |
| 909 | /* |
| 910 | * Init lcd struct with load-time values to preserve exact |
| 911 | * current functionality (at least for now). |
| 912 | */ |
| 913 | charlcd->height = lcd_height; |
| 914 | charlcd->width = lcd_width; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 915 | hdc->bwidth = lcd_bwidth; |
| 916 | hdc->hwidth = lcd_hwidth; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 917 | |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 918 | switch (selected_lcd_type) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 919 | case LCD_TYPE_OLD: |
| 920 | /* parallel mode, 8 bits */ |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 921 | lcd.proto = LCD_PROTO_PARALLEL; |
| 922 | lcd.charset = LCD_CHARSET_NORMAL; |
| 923 | lcd.pins.e = PIN_STROBE; |
| 924 | lcd.pins.rs = PIN_AUTOLF; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 925 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 926 | charlcd->width = 40; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 927 | hdc->bwidth = 40; |
| 928 | hdc->hwidth = 64; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 929 | charlcd->height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 930 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 931 | case LCD_TYPE_KS0074: |
| 932 | /* serial mode, ks0074 */ |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 933 | lcd.proto = LCD_PROTO_SERIAL; |
| 934 | lcd.charset = LCD_CHARSET_KS0074; |
| 935 | lcd.pins.bl = PIN_AUTOLF; |
| 936 | lcd.pins.cl = PIN_STROBE; |
| 937 | lcd.pins.da = PIN_D0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 938 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 939 | charlcd->width = 16; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 940 | hdc->bwidth = 40; |
| 941 | hdc->hwidth = 16; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 942 | charlcd->height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 943 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 944 | case LCD_TYPE_NEXCOM: |
| 945 | /* parallel mode, 8 bits, generic */ |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 946 | lcd.proto = LCD_PROTO_PARALLEL; |
| 947 | lcd.charset = LCD_CHARSET_NORMAL; |
| 948 | lcd.pins.e = PIN_AUTOLF; |
| 949 | lcd.pins.rs = PIN_SELECP; |
| 950 | lcd.pins.rw = PIN_INITP; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 951 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 952 | charlcd->width = 16; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 953 | hdc->bwidth = 40; |
| 954 | hdc->hwidth = 64; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 955 | charlcd->height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 956 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 957 | case LCD_TYPE_CUSTOM: |
| 958 | /* customer-defined */ |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 959 | lcd.proto = DEFAULT_LCD_PROTO; |
| 960 | lcd.charset = DEFAULT_LCD_CHARSET; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 961 | /* default geometry will be set later */ |
| 962 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 963 | case LCD_TYPE_HANTRONIX: |
| 964 | /* parallel mode, 8 bits, hantronix-like */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 965 | default: |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 966 | lcd.proto = LCD_PROTO_PARALLEL; |
| 967 | lcd.charset = LCD_CHARSET_NORMAL; |
| 968 | lcd.pins.e = PIN_STROBE; |
| 969 | lcd.pins.rs = PIN_SELECP; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 970 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 971 | charlcd->width = 16; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 972 | hdc->bwidth = 40; |
| 973 | hdc->hwidth = 64; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 974 | charlcd->height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 975 | break; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 976 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 977 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 978 | /* Overwrite with module params set on loading */ |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 979 | if (lcd_height != NOT_SET) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 980 | charlcd->height = lcd_height; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 981 | if (lcd_width != NOT_SET) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 982 | charlcd->width = lcd_width; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 983 | if (lcd_bwidth != NOT_SET) |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 984 | hdc->bwidth = lcd_bwidth; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 985 | if (lcd_hwidth != NOT_SET) |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 986 | hdc->hwidth = lcd_hwidth; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 987 | if (lcd_charset != NOT_SET) |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 988 | lcd.charset = lcd_charset; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 989 | if (lcd_proto != NOT_SET) |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 990 | lcd.proto = lcd_proto; |
| 991 | if (lcd_e_pin != PIN_NOT_SET) |
| 992 | lcd.pins.e = lcd_e_pin; |
| 993 | if (lcd_rs_pin != PIN_NOT_SET) |
| 994 | lcd.pins.rs = lcd_rs_pin; |
| 995 | if (lcd_rw_pin != PIN_NOT_SET) |
| 996 | lcd.pins.rw = lcd_rw_pin; |
| 997 | if (lcd_cl_pin != PIN_NOT_SET) |
| 998 | lcd.pins.cl = lcd_cl_pin; |
| 999 | if (lcd_da_pin != PIN_NOT_SET) |
| 1000 | lcd.pins.da = lcd_da_pin; |
| 1001 | if (lcd_bl_pin != PIN_NOT_SET) |
| 1002 | lcd.pins.bl = lcd_bl_pin; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1003 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1004 | /* this is used to catch wrong and default values */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1005 | if (charlcd->width <= 0) |
| 1006 | charlcd->width = DEFAULT_LCD_WIDTH; |
Lars Poeschel | 2545c1c | 2020-11-03 10:58:06 +0100 | [diff] [blame] | 1007 | if (hdc->bwidth <= 0) |
| 1008 | hdc->bwidth = DEFAULT_LCD_BWIDTH; |
| 1009 | if (hdc->hwidth <= 0) |
| 1010 | hdc->hwidth = DEFAULT_LCD_HWIDTH; |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1011 | if (charlcd->height <= 0) |
| 1012 | charlcd->height = DEFAULT_LCD_HEIGHT; |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1013 | |
| 1014 | if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1015 | charlcd->ops = &charlcd_serial_ops; |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 1016 | hdc->write_data = lcd_write_data_s; |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 1017 | hdc->write_cmd = lcd_write_cmd_s; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1018 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1019 | if (lcd.pins.cl == PIN_NOT_SET) |
| 1020 | lcd.pins.cl = DEFAULT_LCD_PIN_SCL; |
| 1021 | if (lcd.pins.da == PIN_NOT_SET) |
| 1022 | lcd.pins.da = DEFAULT_LCD_PIN_SDA; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1023 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1024 | } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */ |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1025 | charlcd->ops = &charlcd_parallel_ops; |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 1026 | hdc->write_data = lcd_write_data_p8; |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 1027 | hdc->write_cmd = lcd_write_cmd_p8; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1028 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1029 | if (lcd.pins.e == PIN_NOT_SET) |
| 1030 | lcd.pins.e = DEFAULT_LCD_PIN_E; |
| 1031 | if (lcd.pins.rs == PIN_NOT_SET) |
| 1032 | lcd.pins.rs = DEFAULT_LCD_PIN_RS; |
| 1033 | if (lcd.pins.rw == PIN_NOT_SET) |
| 1034 | lcd.pins.rw = DEFAULT_LCD_PIN_RW; |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 1035 | } else { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1036 | charlcd->ops = &charlcd_tilcd_ops; |
Lars Poeschel | 71ff701 | 2020-11-03 10:58:08 +0100 | [diff] [blame] | 1037 | hdc->write_data = lcd_write_data_tilcd; |
Lars Poeschel | 2c6a82f | 2020-11-03 10:58:09 +0100 | [diff] [blame^] | 1038 | hdc->write_cmd = lcd_write_cmd_tilcd; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1041 | if (lcd.pins.bl == PIN_NOT_SET) |
| 1042 | lcd.pins.bl = DEFAULT_LCD_PIN_BL; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1043 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1044 | if (lcd.pins.e == PIN_NOT_SET) |
| 1045 | lcd.pins.e = PIN_NONE; |
| 1046 | if (lcd.pins.rs == PIN_NOT_SET) |
| 1047 | lcd.pins.rs = PIN_NONE; |
| 1048 | if (lcd.pins.rw == PIN_NOT_SET) |
| 1049 | lcd.pins.rw = PIN_NONE; |
| 1050 | if (lcd.pins.bl == PIN_NOT_SET) |
| 1051 | lcd.pins.bl = PIN_NONE; |
| 1052 | if (lcd.pins.cl == PIN_NOT_SET) |
| 1053 | lcd.pins.cl = PIN_NONE; |
| 1054 | if (lcd.pins.da == PIN_NOT_SET) |
| 1055 | lcd.pins.da = PIN_NONE; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1056 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1057 | if (lcd.charset == NOT_SET) |
| 1058 | lcd.charset = DEFAULT_LCD_CHARSET; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1059 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1060 | if (lcd.charset == LCD_CHARSET_KS0074) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1061 | charlcd->char_conv = lcd_char_conv_ks0074; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1062 | else |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1063 | charlcd->char_conv = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1064 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1065 | pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1066 | lcd_bits[LCD_PORT_C][LCD_BIT_E]); |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1067 | pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1068 | lcd_bits[LCD_PORT_C][LCD_BIT_RS]); |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1069 | pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1070 | lcd_bits[LCD_PORT_C][LCD_BIT_RW]); |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1071 | pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1072 | lcd_bits[LCD_PORT_C][LCD_BIT_BL]); |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1073 | pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1074 | lcd_bits[LCD_PORT_C][LCD_BIT_CL]); |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1075 | pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA], |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1076 | lcd_bits[LCD_PORT_C][LCD_BIT_DA]); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1077 | |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1078 | lcd.charlcd = charlcd; |
Mariusz Gorski | 6d8b588 | 2014-11-27 22:36:53 +0100 | [diff] [blame] | 1079 | lcd.initialized = true; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1082 | /* |
| 1083 | * These are the file operation function for user access to /dev/keypad |
| 1084 | */ |
| 1085 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1086 | static ssize_t keypad_read(struct file *file, |
Bastien Armand | cce75f4 | 2014-04-18 18:10:08 +0200 | [diff] [blame] | 1087 | char __user *buf, size_t count, loff_t *ppos) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1088 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1089 | unsigned i = *ppos; |
Bastien Armand | cce75f4 | 2014-04-18 18:10:08 +0200 | [diff] [blame] | 1090 | char __user *tmp = buf; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1091 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1092 | if (keypad_buflen == 0) { |
| 1093 | if (file->f_flags & O_NONBLOCK) |
| 1094 | return -EAGAIN; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1095 | |
Arnd Bergmann | 310df69 | 2014-01-02 13:07:35 +0100 | [diff] [blame] | 1096 | if (wait_event_interruptible(keypad_read_wait, |
| 1097 | keypad_buflen != 0)) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1098 | return -EINTR; |
| 1099 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1100 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1101 | for (; count-- > 0 && (keypad_buflen > 0); |
| 1102 | ++i, ++tmp, --keypad_buflen) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1103 | put_user(keypad_buffer[keypad_start], tmp); |
| 1104 | keypad_start = (keypad_start + 1) % KEYPAD_BUFFER; |
| 1105 | } |
| 1106 | *ppos = i; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1107 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1108 | return tmp - buf; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1111 | static int keypad_open(struct inode *inode, struct file *file) |
| 1112 | { |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 1113 | int ret; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1114 | |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 1115 | ret = -EBUSY; |
| 1116 | if (!atomic_dec_and_test(&keypad_available)) |
| 1117 | goto fail; /* open only once at a time */ |
| 1118 | |
| 1119 | ret = -EPERM; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1120 | if (file->f_mode & FMODE_WRITE) /* device is read-only */ |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 1121 | goto fail; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1122 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1123 | keypad_buflen = 0; /* flush the buffer on opening */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1124 | return 0; |
Willy Tarreau | 93dc177 | 2017-09-07 15:37:30 +0200 | [diff] [blame] | 1125 | fail: |
| 1126 | atomic_inc(&keypad_available); |
| 1127 | return ret; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1130 | static int keypad_release(struct inode *inode, struct file *file) |
| 1131 | { |
Mariusz Gorski | f4757af | 2014-11-04 22:47:19 +0100 | [diff] [blame] | 1132 | atomic_inc(&keypad_available); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1133 | return 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1134 | } |
| 1135 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1136 | static const struct file_operations keypad_fops = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1137 | .read = keypad_read, /* read */ |
| 1138 | .open = keypad_open, /* open */ |
| 1139 | .release = keypad_release, /* close */ |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1140 | .llseek = default_llseek, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1141 | }; |
| 1142 | |
| 1143 | static struct miscdevice keypad_dev = { |
Mariusz Gorski | 6c3773de | 2014-10-29 23:32:30 +0100 | [diff] [blame] | 1144 | .minor = KEYPAD_MINOR, |
| 1145 | .name = "keypad", |
| 1146 | .fops = &keypad_fops, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1147 | }; |
| 1148 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1149 | static void keypad_send_key(const char *string, int max_len) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1150 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1151 | /* send the key to the device only if a process is attached to it. */ |
Mariusz Gorski | f4757af | 2014-11-04 22:47:19 +0100 | [diff] [blame] | 1152 | if (!atomic_read(&keypad_available)) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1153 | while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) { |
| 1154 | keypad_buffer[(keypad_start + keypad_buflen++) % |
| 1155 | KEYPAD_BUFFER] = *string++; |
| 1156 | } |
| 1157 | wake_up_interruptible(&keypad_read_wait); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1158 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1161 | /* this function scans all the bits involving at least one logical signal, |
| 1162 | * and puts the results in the bitfield "phys_read" (one bit per established |
| 1163 | * contact), and sets "phys_read_prev" to "phys_read". |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1164 | * |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1165 | * Note: to debounce input signals, we will only consider as switched a signal |
| 1166 | * which is stable across 2 measures. Signals which are different between two |
| 1167 | * reads will be kept as they previously were in their logical form (phys_prev). |
| 1168 | * A signal which has just switched will have a 1 in |
| 1169 | * (phys_read ^ phys_read_prev). |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1170 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1171 | static void phys_scan_contacts(void) |
| 1172 | { |
| 1173 | int bit, bitval; |
| 1174 | char oldval; |
| 1175 | char bitmask; |
| 1176 | char gndmask; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1177 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1178 | phys_prev = phys_curr; |
| 1179 | phys_read_prev = phys_read; |
| 1180 | phys_read = 0; /* flush all signals */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1181 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1182 | /* keep track of old value, with all outputs disabled */ |
| 1183 | oldval = r_dtr(pprt) | scan_mask_o; |
| 1184 | /* activate all keyboard outputs (active low) */ |
| 1185 | w_dtr(pprt, oldval & ~scan_mask_o); |
| 1186 | |
| 1187 | /* will have a 1 for each bit set to gnd */ |
| 1188 | bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; |
| 1189 | /* disable all matrix signals */ |
| 1190 | w_dtr(pprt, oldval); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1191 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1192 | /* now that all outputs are cleared, the only active input bits are |
| 1193 | * directly connected to the ground |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1194 | */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1195 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1196 | /* 1 for each grounded input */ |
| 1197 | gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; |
| 1198 | |
| 1199 | /* grounded inputs are signals 40-44 */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 1200 | phys_read |= (__u64)gndmask << 40; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1201 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1202 | if (bitmask != gndmask) { |
Nayeemahmed Badebade | 8c17893 | 2015-08-27 21:02:46 +0530 | [diff] [blame] | 1203 | /* |
| 1204 | * since clearing the outputs changed some inputs, we know |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1205 | * that some input signals are currently tied to some outputs. |
| 1206 | * So we'll scan them. |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1207 | */ |
| 1208 | for (bit = 0; bit < 8; bit++) { |
Amitoj Kaur Chawla | 79f2af6 | 2015-10-16 22:11:36 +0530 | [diff] [blame] | 1209 | bitval = BIT(bit); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1210 | |
| 1211 | if (!(scan_mask_o & bitval)) /* skip unused bits */ |
| 1212 | continue; |
| 1213 | |
| 1214 | w_dtr(pprt, oldval & ~bitval); /* enable this output */ |
| 1215 | bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask; |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 1216 | phys_read |= (__u64)bitmask << (5 * bit); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1217 | } |
| 1218 | w_dtr(pprt, oldval); /* disable all outputs */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1219 | } |
Nayeemahmed Badebade | 8c17893 | 2015-08-27 21:02:46 +0530 | [diff] [blame] | 1220 | /* |
| 1221 | * this is easy: use old bits when they are flapping, |
| 1222 | * use new ones when stable |
| 1223 | */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1224 | phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) | |
| 1225 | (phys_read & ~(phys_read ^ phys_read_prev)); |
| 1226 | } |
| 1227 | |
| 1228 | static inline int input_state_high(struct logical_input *input) |
| 1229 | { |
| 1230 | #if 0 |
| 1231 | /* FIXME: |
| 1232 | * this is an invalid test. It tries to catch |
| 1233 | * transitions from single-key to multiple-key, but |
| 1234 | * doesn't take into account the contacts polarity. |
| 1235 | * The only solution to the problem is to parse keys |
| 1236 | * from the most complex to the simplest combinations, |
| 1237 | * and mark them as 'caught' once a combination |
| 1238 | * matches, then unmatch it for all other ones. |
| 1239 | */ |
| 1240 | |
| 1241 | /* try to catch dangerous transitions cases : |
| 1242 | * someone adds a bit, so this signal was a false |
| 1243 | * positive resulting from a transition. We should |
| 1244 | * invalidate the signal immediately and not call the |
| 1245 | * release function. |
| 1246 | * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release. |
| 1247 | */ |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1248 | if (((phys_prev & input->mask) == input->value) && |
| 1249 | ((phys_curr & input->mask) > input->value)) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1250 | input->state = INPUT_ST_LOW; /* invalidate */ |
| 1251 | return 1; |
| 1252 | } |
| 1253 | #endif |
| 1254 | |
| 1255 | if ((phys_curr & input->mask) == input->value) { |
| 1256 | if ((input->type == INPUT_TYPE_STD) && |
| 1257 | (input->high_timer == 0)) { |
| 1258 | input->high_timer++; |
Aybuke Ozdemir | b565b3f | 2015-10-03 14:52:09 +0300 | [diff] [blame] | 1259 | if (input->u.std.press_fct) |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1260 | input->u.std.press_fct(input->u.std.press_data); |
| 1261 | } else if (input->type == INPUT_TYPE_KBD) { |
| 1262 | /* will turn on the light */ |
| 1263 | keypressed = 1; |
| 1264 | |
| 1265 | if (input->high_timer == 0) { |
| 1266 | char *press_str = input->u.kbd.press_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1267 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1268 | if (press_str[0]) { |
| 1269 | int s = sizeof(input->u.kbd.press_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1270 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1271 | keypad_send_key(press_str, s); |
| 1272 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | if (input->u.kbd.repeat_str[0]) { |
| 1276 | char *repeat_str = input->u.kbd.repeat_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1277 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1278 | if (input->high_timer >= KEYPAD_REP_START) { |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1279 | int s = sizeof(input->u.kbd.repeat_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1280 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1281 | input->high_timer -= KEYPAD_REP_DELAY; |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1282 | keypad_send_key(repeat_str, s); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1283 | } |
| 1284 | /* we will need to come back here soon */ |
| 1285 | inputs_stable = 0; |
| 1286 | } |
| 1287 | |
| 1288 | if (input->high_timer < 255) |
| 1289 | input->high_timer++; |
| 1290 | } |
| 1291 | return 1; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1292 | } |
Vincent Heuken | 083b363 | 2014-07-10 03:34:28 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* else signal falling down. Let's fall through. */ |
| 1295 | input->state = INPUT_ST_FALLING; |
| 1296 | input->fall_timer = 0; |
| 1297 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static inline void input_state_falling(struct logical_input *input) |
| 1302 | { |
| 1303 | #if 0 |
| 1304 | /* FIXME !!! same comment as in input_state_high */ |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1305 | if (((phys_prev & input->mask) == input->value) && |
| 1306 | ((phys_curr & input->mask) > input->value)) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1307 | input->state = INPUT_ST_LOW; /* invalidate */ |
| 1308 | return; |
| 1309 | } |
| 1310 | #endif |
| 1311 | |
| 1312 | if ((phys_curr & input->mask) == input->value) { |
| 1313 | if (input->type == INPUT_TYPE_KBD) { |
| 1314 | /* will turn on the light */ |
| 1315 | keypressed = 1; |
| 1316 | |
| 1317 | if (input->u.kbd.repeat_str[0]) { |
| 1318 | char *repeat_str = input->u.kbd.repeat_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1319 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1320 | if (input->high_timer >= KEYPAD_REP_START) { |
| 1321 | int s = sizeof(input->u.kbd.repeat_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1322 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1323 | input->high_timer -= KEYPAD_REP_DELAY; |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1324 | keypad_send_key(repeat_str, s); |
| 1325 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1326 | /* we will need to come back here soon */ |
| 1327 | inputs_stable = 0; |
| 1328 | } |
| 1329 | |
| 1330 | if (input->high_timer < 255) |
| 1331 | input->high_timer++; |
| 1332 | } |
| 1333 | input->state = INPUT_ST_HIGH; |
| 1334 | } else if (input->fall_timer >= input->fall_time) { |
| 1335 | /* call release event */ |
| 1336 | if (input->type == INPUT_TYPE_STD) { |
| 1337 | void (*release_fct)(int) = input->u.std.release_fct; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1338 | |
Aybuke Ozdemir | b565b3f | 2015-10-03 14:52:09 +0300 | [diff] [blame] | 1339 | if (release_fct) |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1340 | release_fct(input->u.std.release_data); |
| 1341 | } else if (input->type == INPUT_TYPE_KBD) { |
| 1342 | char *release_str = input->u.kbd.release_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1343 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1344 | if (release_str[0]) { |
| 1345 | int s = sizeof(input->u.kbd.release_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1346 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1347 | keypad_send_key(release_str, s); |
| 1348 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | input->state = INPUT_ST_LOW; |
| 1352 | } else { |
| 1353 | input->fall_timer++; |
| 1354 | inputs_stable = 0; |
| 1355 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1358 | static void panel_process_inputs(void) |
| 1359 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1360 | struct logical_input *input; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1361 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1362 | keypressed = 0; |
| 1363 | inputs_stable = 1; |
Wei Yongjun | 4654bdb | 2017-04-25 16:13:34 +0000 | [diff] [blame] | 1364 | list_for_each_entry(input, &logical_inputs, list) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1365 | switch (input->state) { |
| 1366 | case INPUT_ST_LOW: |
| 1367 | if ((phys_curr & input->mask) != input->value) |
| 1368 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1369 | /* if all needed ones were already set previously, |
| 1370 | * this means that this logical signal has been |
| 1371 | * activated by the releasing of another combined |
| 1372 | * signal, so we don't want to match. |
| 1373 | * eg: AB -(release B)-> A -(release A)-> 0 : |
| 1374 | * don't match A. |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1375 | */ |
| 1376 | if ((phys_prev & input->mask) == input->value) |
| 1377 | break; |
| 1378 | input->rise_timer = 0; |
| 1379 | input->state = INPUT_ST_RISING; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1380 | fallthrough; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1381 | case INPUT_ST_RISING: |
| 1382 | if ((phys_curr & input->mask) != input->value) { |
| 1383 | input->state = INPUT_ST_LOW; |
| 1384 | break; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1385 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1386 | if (input->rise_timer < input->rise_time) { |
| 1387 | inputs_stable = 0; |
| 1388 | input->rise_timer++; |
| 1389 | break; |
| 1390 | } |
| 1391 | input->high_timer = 0; |
| 1392 | input->state = INPUT_ST_HIGH; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1393 | fallthrough; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1394 | case INPUT_ST_HIGH: |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1395 | if (input_state_high(input)) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1396 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1397 | fallthrough; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1398 | case INPUT_ST_FALLING: |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1399 | input_state_falling(input); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1400 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1401 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Kees Cook | 607a630 | 2017-10-19 14:08:22 -0700 | [diff] [blame] | 1404 | static void panel_scan_timer(struct timer_list *unused) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1405 | { |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 1406 | if (keypad.enabled && keypad_initialized) { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 1407 | if (spin_trylock_irq(&pprt_lock)) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1408 | phys_scan_contacts(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1409 | |
| 1410 | /* no need for the parport anymore */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 1411 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1412 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1413 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1414 | if (!inputs_stable || phys_curr != phys_prev) |
| 1415 | panel_process_inputs(); |
| 1416 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1417 | |
Geert Uytterhoeven | fda4ae1 | 2017-02-06 15:38:10 +0100 | [diff] [blame] | 1418 | if (keypressed && lcd.enabled && lcd.initialized) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1419 | charlcd_poke(lcd.charlcd); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1420 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1421 | mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1424 | static void init_scan_timer(void) |
| 1425 | { |
Aybuke Ozdemir | b565b3f | 2015-10-03 14:52:09 +0300 | [diff] [blame] | 1426 | if (scan_timer.function) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1427 | return; /* already started */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1428 | |
Kees Cook | 607a630 | 2017-10-19 14:08:22 -0700 | [diff] [blame] | 1429 | timer_setup(&scan_timer, panel_scan_timer, 0); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1430 | scan_timer.expires = jiffies + INPUT_POLL_TIME; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1431 | add_timer(&scan_timer); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits. |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1435 | * if <omask> or <imask> are non-null, they will be or'ed with the bits |
| 1436 | * corresponding to out and in bits respectively. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1437 | * returns 1 if ok, 0 if error (in which case, nothing is written). |
| 1438 | */ |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 1439 | static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value, |
Ksenija Stanojevic | d938e1e | 2016-01-03 20:39:49 +0100 | [diff] [blame] | 1440 | u8 *imask, u8 *omask) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1441 | { |
Ksenija Stanojevic | 8aa7307 | 2016-01-03 20:44:44 +0100 | [diff] [blame] | 1442 | const char sigtab[] = "EeSsPpAaBb"; |
Ksenija Stanojevic | d938e1e | 2016-01-03 20:39:49 +0100 | [diff] [blame] | 1443 | u8 im, om; |
Ksenija Stanojevic | 35fe087 | 2016-01-03 20:40:58 +0100 | [diff] [blame] | 1444 | __u64 m, v; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1445 | |
Ksenija Stanojevic | d12f27e | 2016-01-03 20:42:26 +0100 | [diff] [blame] | 1446 | om = 0; |
| 1447 | im = 0; |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame] | 1448 | m = 0ULL; |
| 1449 | v = 0ULL; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1450 | while (*name) { |
| 1451 | int in, out, bit, neg; |
Ksenija Stanojevic | 8aa7307 | 2016-01-03 20:44:44 +0100 | [diff] [blame] | 1452 | const char *idx; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1453 | |
Ksenija Stanojevic | 8aa7307 | 2016-01-03 20:44:44 +0100 | [diff] [blame] | 1454 | idx = strchr(sigtab, *name); |
| 1455 | if (!idx) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1456 | return 0; /* input name not found */ |
Ksenija Stanojevic | 8aa7307 | 2016-01-03 20:44:44 +0100 | [diff] [blame] | 1457 | |
| 1458 | in = idx - sigtab; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1459 | neg = (in & 1); /* odd (lower) names are negated */ |
| 1460 | in >>= 1; |
Amitoj Kaur Chawla | 79f2af6 | 2015-10-16 22:11:36 +0530 | [diff] [blame] | 1461 | im |= BIT(in); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1462 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1463 | name++; |
Ksenija Stanojevic | 52ebf93 | 2016-01-03 20:43:27 +0100 | [diff] [blame] | 1464 | if (*name >= '0' && *name <= '7') { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1465 | out = *name - '0'; |
Amitoj Kaur Chawla | 79f2af6 | 2015-10-16 22:11:36 +0530 | [diff] [blame] | 1466 | om |= BIT(out); |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1467 | } else if (*name == '-') { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1468 | out = 8; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1469 | } else { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1470 | return 0; /* unknown bit name */ |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1471 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1472 | |
| 1473 | bit = (out * 5) + in; |
| 1474 | |
| 1475 | m |= 1ULL << bit; |
| 1476 | if (!neg) |
| 1477 | v |= 1ULL << bit; |
| 1478 | name++; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1479 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1480 | *mask = m; |
| 1481 | *value = v; |
| 1482 | if (imask) |
| 1483 | *imask |= im; |
| 1484 | if (omask) |
| 1485 | *omask |= om; |
| 1486 | return 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /* tries to bind a key to the signal name <name>. The key will send the |
| 1490 | * strings <press>, <repeat>, <release> for these respective events. |
| 1491 | * Returns the pointer to the new key if ok, NULL if the key could not be bound. |
| 1492 | */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1493 | static struct logical_input *panel_bind_key(const char *name, const char *press, |
| 1494 | const char *repeat, |
| 1495 | const char *release) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1496 | { |
| 1497 | struct logical_input *key; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1498 | |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1499 | key = kzalloc(sizeof(*key), GFP_KERNEL); |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1500 | if (!key) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1501 | return NULL; |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1502 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1503 | if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i, |
Kulikov Vasiliy | cb46f47 | 2010-07-12 18:48:24 +0400 | [diff] [blame] | 1504 | &scan_mask_o)) { |
| 1505 | kfree(key); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1506 | return NULL; |
Kulikov Vasiliy | cb46f47 | 2010-07-12 18:48:24 +0400 | [diff] [blame] | 1507 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1508 | |
| 1509 | key->type = INPUT_TYPE_KBD; |
| 1510 | key->state = INPUT_ST_LOW; |
| 1511 | key->rise_time = 1; |
| 1512 | key->fall_time = 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1513 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1514 | strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str)); |
| 1515 | strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str)); |
| 1516 | strncpy(key->u.kbd.release_str, release, |
| 1517 | sizeof(key->u.kbd.release_str)); |
| 1518 | list_add(&key->list, &logical_inputs); |
| 1519 | return key; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1520 | } |
| 1521 | |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 1522 | #if 0 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1523 | /* tries to bind a callback function to the signal name <name>. The function |
| 1524 | * <press_fct> will be called with the <press_data> arg when the signal is |
| 1525 | * activated, and so on for <release_fct>/<release_data> |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1526 | * Returns the pointer to the new signal if ok, NULL if the signal could not |
| 1527 | * be bound. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1528 | */ |
| 1529 | static struct logical_input *panel_bind_callback(char *name, |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 1530 | void (*press_fct)(int), |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1531 | int press_data, |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 1532 | void (*release_fct)(int), |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1533 | int release_data) |
| 1534 | { |
| 1535 | struct logical_input *callback; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1536 | |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1537 | callback = kmalloc(sizeof(*callback), GFP_KERNEL); |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1538 | if (!callback) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1539 | return NULL; |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1540 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1541 | memset(callback, 0, sizeof(struct logical_input)); |
| 1542 | if (!input_name2mask(name, &callback->mask, &callback->value, |
| 1543 | &scan_mask_i, &scan_mask_o)) |
| 1544 | return NULL; |
| 1545 | |
| 1546 | callback->type = INPUT_TYPE_STD; |
| 1547 | callback->state = INPUT_ST_LOW; |
| 1548 | callback->rise_time = 1; |
| 1549 | callback->fall_time = 1; |
| 1550 | callback->u.std.press_fct = press_fct; |
| 1551 | callback->u.std.press_data = press_data; |
| 1552 | callback->u.std.release_fct = release_fct; |
| 1553 | callback->u.std.release_data = release_data; |
| 1554 | list_add(&callback->list, &logical_inputs); |
| 1555 | return callback; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1556 | } |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 1557 | #endif |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1558 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1559 | static void keypad_init(void) |
| 1560 | { |
| 1561 | int keynum; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1562 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1563 | init_waitqueue_head(&keypad_read_wait); |
| 1564 | keypad_buflen = 0; /* flushes any eventual noisy keystroke */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1565 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1566 | /* Let's create all known keys */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1567 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1568 | for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) { |
| 1569 | panel_bind_key(keypad_profile[keynum][0], |
| 1570 | keypad_profile[keynum][1], |
| 1571 | keypad_profile[keynum][2], |
| 1572 | keypad_profile[keynum][3]); |
| 1573 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1574 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1575 | init_scan_timer(); |
| 1576 | keypad_initialized = 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1577 | } |
| 1578 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1579 | /**************************************************/ |
| 1580 | /* device initialization */ |
| 1581 | /**************************************************/ |
| 1582 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1583 | static void panel_attach(struct parport *port) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1584 | { |
Sudip Mukherjee | 9be83c0 | 2015-05-20 20:56:58 +0530 | [diff] [blame] | 1585 | struct pardev_cb panel_cb; |
| 1586 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1587 | if (port->number != parport) |
| 1588 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1589 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1590 | if (pprt) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1591 | pr_err("%s: port->number=%d parport=%d, already registered!\n", |
| 1592 | __func__, port->number, parport); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1593 | return; |
| 1594 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1595 | |
Sudip Mukherjee | 9be83c0 | 2015-05-20 20:56:58 +0530 | [diff] [blame] | 1596 | memset(&panel_cb, 0, sizeof(panel_cb)); |
| 1597 | panel_cb.private = &pprt; |
| 1598 | /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */ |
| 1599 | |
| 1600 | pprt = parport_register_dev_model(port, "panel", &panel_cb, 0); |
Aybuke Ozdemir | b565b3f | 2015-10-03 14:52:09 +0300 | [diff] [blame] | 1601 | if (!pprt) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1602 | pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n", |
| 1603 | __func__, port->number, parport); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1604 | return; |
| 1605 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1606 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1607 | if (parport_claim(pprt)) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1608 | pr_err("could not claim access to parport%d. Aborting.\n", |
| 1609 | parport); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1610 | goto err_unreg_device; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1611 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1612 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1613 | /* must init LCD first, just in case an IRQ from the keypad is |
| 1614 | * generated at keypad init |
| 1615 | */ |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 1616 | if (lcd.enabled) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1617 | lcd_init(); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1618 | if (!lcd.charlcd || charlcd_register(lcd.charlcd)) |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1619 | goto err_unreg_device; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1620 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1621 | |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 1622 | if (keypad.enabled) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1623 | keypad_init(); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1624 | if (misc_register(&keypad_dev)) |
| 1625 | goto err_lcd_unreg; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1626 | } |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1627 | return; |
| 1628 | |
| 1629 | err_lcd_unreg: |
zhengbin | b33d567 | 2019-07-08 20:42:18 +0800 | [diff] [blame] | 1630 | if (scan_timer.function) |
| 1631 | del_timer_sync(&scan_timer); |
Mariusz Gorski | a8b2580 | 2014-11-27 22:36:49 +0100 | [diff] [blame] | 1632 | if (lcd.enabled) |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1633 | charlcd_unregister(lcd.charlcd); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1634 | err_unreg_device: |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 1635 | kfree(lcd.charlcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1636 | lcd.charlcd = NULL; |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 1637 | parport_unregister_device(pprt); |
| 1638 | pprt = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1641 | static void panel_detach(struct parport *port) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1642 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1643 | if (port->number != parport) |
| 1644 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1645 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1646 | if (!pprt) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1647 | pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n", |
| 1648 | __func__, port->number, parport); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1649 | return; |
| 1650 | } |
Aybuke Ozdemir | b565b3f | 2015-10-03 14:52:09 +0300 | [diff] [blame] | 1651 | if (scan_timer.function) |
Sudip Mukherjee | 7d98c63 | 2015-05-12 17:36:08 +0530 | [diff] [blame] | 1652 | del_timer_sync(&scan_timer); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1653 | |
Geert Uytterhoeven | 3f77b43 | 2017-02-06 15:38:08 +0100 | [diff] [blame] | 1654 | if (keypad.enabled) { |
| 1655 | misc_deregister(&keypad_dev); |
| 1656 | keypad_initialized = 0; |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 1657 | } |
Geert Uytterhoeven | 3f77b43 | 2017-02-06 15:38:08 +0100 | [diff] [blame] | 1658 | |
| 1659 | if (lcd.enabled) { |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1660 | charlcd_unregister(lcd.charlcd); |
Geert Uytterhoeven | 3f77b43 | 2017-02-06 15:38:08 +0100 | [diff] [blame] | 1661 | lcd.initialized = false; |
Lars Poeschel | 718e05e | 2020-11-03 10:58:05 +0100 | [diff] [blame] | 1662 | kfree(lcd.charlcd->drvdata); |
| 1663 | kfree(lcd.charlcd); |
Geert Uytterhoeven | 39f8ea4 | 2017-03-10 15:15:17 +0100 | [diff] [blame] | 1664 | lcd.charlcd = NULL; |
Geert Uytterhoeven | 3f77b43 | 2017-02-06 15:38:08 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /* TODO: free all input signals */ |
| 1668 | parport_release(pprt); |
| 1669 | parport_unregister_device(pprt); |
| 1670 | pprt = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | static struct parport_driver panel_driver = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1674 | .name = "panel", |
Sudip Mukherjee | 9be83c0 | 2015-05-20 20:56:58 +0530 | [diff] [blame] | 1675 | .match_port = panel_attach, |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1676 | .detach = panel_detach, |
Sudip Mukherjee | 9be83c0 | 2015-05-20 20:56:58 +0530 | [diff] [blame] | 1677 | .devmodel = true, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1678 | }; |
| 1679 | |
| 1680 | /* init function */ |
Mariusz Gorski | d911476 | 2014-11-27 22:36:46 +0100 | [diff] [blame] | 1681 | static int __init panel_init_module(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1682 | { |
Sudip Mukherjee | e134201 | 2015-03-09 20:08:24 +0530 | [diff] [blame] | 1683 | int selected_keypad_type = NOT_SET, err; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1684 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1685 | /* take care of an eventual profile */ |
| 1686 | switch (profile) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1687 | case PANEL_PROFILE_CUSTOM: |
| 1688 | /* custom profile */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1689 | selected_keypad_type = DEFAULT_KEYPAD_TYPE; |
| 1690 | selected_lcd_type = DEFAULT_LCD_TYPE; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1691 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1692 | case PANEL_PROFILE_OLD: |
| 1693 | /* 8 bits, 2*16, old keypad */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1694 | selected_keypad_type = KEYPAD_TYPE_OLD; |
| 1695 | selected_lcd_type = LCD_TYPE_OLD; |
| 1696 | |
| 1697 | /* TODO: This two are a little hacky, sort it out later */ |
Mariusz Gorski | 2d35bcf | 2014-11-27 22:36:48 +0100 | [diff] [blame] | 1698 | if (lcd_width == NOT_SET) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1699 | lcd_width = 16; |
Mariusz Gorski | 2d35bcf | 2014-11-27 22:36:48 +0100 | [diff] [blame] | 1700 | if (lcd_hwidth == NOT_SET) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1701 | lcd_hwidth = 16; |
| 1702 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1703 | case PANEL_PROFILE_NEW: |
| 1704 | /* serial, 2*16, new keypad */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1705 | selected_keypad_type = KEYPAD_TYPE_NEW; |
| 1706 | selected_lcd_type = LCD_TYPE_KS0074; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1707 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1708 | case PANEL_PROFILE_HANTRONIX: |
| 1709 | /* 8 bits, 2*16 hantronix-like, no keypad */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1710 | selected_keypad_type = KEYPAD_TYPE_NONE; |
| 1711 | selected_lcd_type = LCD_TYPE_HANTRONIX; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1712 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1713 | case PANEL_PROFILE_NEXCOM: |
| 1714 | /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1715 | selected_keypad_type = KEYPAD_TYPE_NEXCOM; |
| 1716 | selected_lcd_type = LCD_TYPE_NEXCOM; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1717 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1718 | case PANEL_PROFILE_LARGE: |
| 1719 | /* 8 bits, 2*40, old keypad */ |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1720 | selected_keypad_type = KEYPAD_TYPE_OLD; |
| 1721 | selected_lcd_type = LCD_TYPE_OLD; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1722 | break; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1723 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1724 | |
Mariusz Gorski | 8037e2a | 2014-11-27 22:36:51 +0100 | [diff] [blame] | 1725 | /* |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1726 | * Overwrite selection with module param values (both keypad and lcd), |
| 1727 | * where the deprecated params have lower prio. |
| 1728 | */ |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 1729 | if (keypad_enabled != NOT_SET) |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1730 | selected_keypad_type = keypad_enabled; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 1731 | if (keypad_type != NOT_SET) |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1732 | selected_keypad_type = keypad_type; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1733 | |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1734 | keypad.enabled = (selected_keypad_type > 0); |
| 1735 | |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 1736 | if (lcd_enabled != NOT_SET) |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1737 | selected_lcd_type = lcd_enabled; |
Mariusz Gorski | 1a4b2e3 | 2014-11-27 22:36:52 +0100 | [diff] [blame] | 1738 | if (lcd_type != NOT_SET) |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1739 | selected_lcd_type = lcd_type; |
| 1740 | |
| 1741 | lcd.enabled = (selected_lcd_type > 0); |
| 1742 | |
Sudip Mukherjee | 733345e | 2015-02-11 16:57:08 +0530 | [diff] [blame] | 1743 | if (lcd.enabled) { |
| 1744 | /* |
| 1745 | * Init lcd struct with load-time values to preserve exact |
| 1746 | * current functionality (at least for now). |
| 1747 | */ |
Sudip Mukherjee | 733345e | 2015-02-11 16:57:08 +0530 | [diff] [blame] | 1748 | lcd.charset = lcd_charset; |
| 1749 | lcd.proto = lcd_proto; |
| 1750 | lcd.pins.e = lcd_e_pin; |
| 1751 | lcd.pins.rs = lcd_rs_pin; |
| 1752 | lcd.pins.rw = lcd_rw_pin; |
| 1753 | lcd.pins.cl = lcd_cl_pin; |
| 1754 | lcd.pins.da = lcd_da_pin; |
| 1755 | lcd.pins.bl = lcd_bl_pin; |
Sudip Mukherjee | 733345e | 2015-02-11 16:57:08 +0530 | [diff] [blame] | 1756 | } |
| 1757 | |
Mariusz Gorski | 87b8e0c | 2014-11-27 22:36:50 +0100 | [diff] [blame] | 1758 | switch (selected_keypad_type) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1759 | case KEYPAD_TYPE_OLD: |
| 1760 | keypad_profile = old_keypad_profile; |
| 1761 | break; |
| 1762 | case KEYPAD_TYPE_NEW: |
| 1763 | keypad_profile = new_keypad_profile; |
| 1764 | break; |
| 1765 | case KEYPAD_TYPE_NEXCOM: |
| 1766 | keypad_profile = nexcom_keypad_profile; |
| 1767 | break; |
| 1768 | default: |
| 1769 | keypad_profile = NULL; |
| 1770 | break; |
| 1771 | } |
| 1772 | |
Sudip Mukherjee | f43de77 | 2015-02-10 17:26:02 +0530 | [diff] [blame] | 1773 | if (!lcd.enabled && !keypad.enabled) { |
| 1774 | /* no device enabled, let's exit */ |
Geert Uytterhoeven | 30f468b | 2017-02-06 15:38:04 +0100 | [diff] [blame] | 1775 | pr_err("panel driver disabled.\n"); |
Sudip Mukherjee | f43de77 | 2015-02-10 17:26:02 +0530 | [diff] [blame] | 1776 | return -ENODEV; |
| 1777 | } |
| 1778 | |
Sudip Mukherjee | e134201 | 2015-03-09 20:08:24 +0530 | [diff] [blame] | 1779 | err = parport_register_driver(&panel_driver); |
| 1780 | if (err) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 1781 | pr_err("could not register with parport. Aborting.\n"); |
Sudip Mukherjee | e134201 | 2015-03-09 20:08:24 +0530 | [diff] [blame] | 1782 | return err; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1783 | } |
| 1784 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1785 | if (pprt) |
Geert Uytterhoeven | 30f468b | 2017-02-06 15:38:04 +0100 | [diff] [blame] | 1786 | pr_info("panel driver registered on parport%d (io=0x%lx).\n", |
| 1787 | parport, pprt->port->base); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1788 | else |
Geert Uytterhoeven | 30f468b | 2017-02-06 15:38:04 +0100 | [diff] [blame] | 1789 | pr_info("panel driver not yet registered\n"); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1790 | return 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 1793 | static void __exit panel_cleanup_module(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1794 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1795 | parport_unregister_driver(&panel_driver); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1796 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1797 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1798 | module_init(panel_init_module); |
| 1799 | module_exit(panel_cleanup_module); |
| 1800 | MODULE_AUTHOR("Willy Tarreau"); |
| 1801 | MODULE_LICENSE("GPL"); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1802 | |
| 1803 | /* |
| 1804 | * Local variables: |
| 1805 | * c-indent-level: 4 |
| 1806 | * tab-width: 8 |
| 1807 | * End: |
| 1808 | */ |