Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1 | /* |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2 | * Front panel driver for Linux |
| 3 | * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 4 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version |
| 8 | * 2 of the License, or (at your option) any later version. |
Willy 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 | * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad) |
| 11 | * connected to a parallel printer port. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 12 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 13 | * The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit |
| 14 | * serial module compatible with Samsung's KS0074. The pins may be connected in |
| 15 | * any combination, everything is programmable. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 16 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 17 | * The keypad consists in a matrix of push buttons connecting input pins to |
| 18 | * data output pins or to the ground. The combinations have to be hard-coded |
| 19 | * in the driver, though several profiles exist and adding new ones is easy. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 20 | * |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 21 | * Several profiles are provided for commonly found LCD+keypad modules on the |
| 22 | * market, such as those found in Nexcom's appliances. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 23 | * |
| 24 | * FIXME: |
| 25 | * - the initialization/deinitialization process is very dirty and should |
| 26 | * be rewritten. It may even be buggy. |
| 27 | * |
| 28 | * TODO: |
| 29 | * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs) |
| 30 | * - make the LCD a part of a virtual screen of Vx*Vy |
| 31 | * - make the inputs list smp-safe |
| 32 | * - change the keyboard to a double mapping : signals -> key_id -> values |
| 33 | * so that applications can change values without knowing signals |
| 34 | * |
| 35 | */ |
| 36 | |
Toshiaki Yamane | 493aa89 | 2012-07-12 22:01:00 +0900 | [diff] [blame] | 37 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 38 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 39 | #include <linux/module.h> |
| 40 | |
| 41 | #include <linux/types.h> |
| 42 | #include <linux/errno.h> |
| 43 | #include <linux/signal.h> |
| 44 | #include <linux/sched.h> |
| 45 | #include <linux/spinlock.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/miscdevice.h> |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 48 | #include <linux/slab.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 49 | #include <linux/ioport.h> |
| 50 | #include <linux/fcntl.h> |
| 51 | #include <linux/init.h> |
| 52 | #include <linux/delay.h> |
Andy Shevchenko | d85170e | 2010-07-22 19:57:08 +0300 | [diff] [blame] | 53 | #include <linux/kernel.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 54 | #include <linux/ctype.h> |
| 55 | #include <linux/parport.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 56 | #include <linux/list.h> |
| 57 | #include <linux/notifier.h> |
| 58 | #include <linux/reboot.h> |
Sam Ravnborg | 273b281 | 2009-10-18 00:52:28 +0200 | [diff] [blame] | 59 | #include <generated/utsrelease.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 60 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 61 | #include <linux/io.h> |
Takanori Suzuki | 48f658b | 2010-05-08 22:56:24 +0900 | [diff] [blame] | 62 | #include <linux/uaccess.h> |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 63 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 64 | #define LCD_MINOR 156 |
| 65 | #define KEYPAD_MINOR 185 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 66 | |
| 67 | #define PANEL_VERSION "0.9.5" |
| 68 | |
| 69 | #define LCD_MAXBYTES 256 /* max burst write */ |
| 70 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 71 | #define KEYPAD_BUFFER 64 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 72 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 73 | /* poll the keyboard this every second */ |
| 74 | #define INPUT_POLL_TIME (HZ/50) |
| 75 | /* a key starts to repeat after this times INPUT_POLL_TIME */ |
| 76 | #define KEYPAD_REP_START (10) |
| 77 | /* a key repeats this times INPUT_POLL_TIME */ |
| 78 | #define KEYPAD_REP_DELAY (2) |
| 79 | |
| 80 | /* keep the light on this times INPUT_POLL_TIME for each flash */ |
| 81 | #define FLASH_LIGHT_TEMPO (200) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 82 | |
| 83 | /* converts an r_str() input to an active high, bits string : 000BAOSE */ |
| 84 | #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3) |
| 85 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 86 | #define PNL_PBUSY 0x80 /* inverted input, active low */ |
| 87 | #define PNL_PACK 0x40 /* direct input, active low */ |
| 88 | #define PNL_POUTPA 0x20 /* direct input, active high */ |
| 89 | #define PNL_PSELECD 0x10 /* direct input, active high */ |
| 90 | #define PNL_PERRORP 0x08 /* direct input, active low */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 91 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 92 | #define PNL_PBIDIR 0x20 /* bi-directional ports */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 93 | /* high to read data in or-ed with data out */ |
| 94 | #define PNL_PINTEN 0x10 |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 95 | #define PNL_PSELECP 0x08 /* inverted output, active low */ |
| 96 | #define PNL_PINITP 0x04 /* direct output, active low */ |
| 97 | #define PNL_PAUTOLF 0x02 /* inverted output, active low */ |
| 98 | #define PNL_PSTROBE 0x01 /* inverted output */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 99 | |
| 100 | #define PNL_PD0 0x01 |
| 101 | #define PNL_PD1 0x02 |
| 102 | #define PNL_PD2 0x04 |
| 103 | #define PNL_PD3 0x08 |
| 104 | #define PNL_PD4 0x10 |
| 105 | #define PNL_PD5 0x20 |
| 106 | #define PNL_PD6 0x40 |
| 107 | #define PNL_PD7 0x80 |
| 108 | |
| 109 | #define PIN_NONE 0 |
| 110 | #define PIN_STROBE 1 |
| 111 | #define PIN_D0 2 |
| 112 | #define PIN_D1 3 |
| 113 | #define PIN_D2 4 |
| 114 | #define PIN_D3 5 |
| 115 | #define PIN_D4 6 |
| 116 | #define PIN_D5 7 |
| 117 | #define PIN_D6 8 |
| 118 | #define PIN_D7 9 |
| 119 | #define PIN_AUTOLF 14 |
| 120 | #define PIN_INITP 16 |
| 121 | #define PIN_SELECP 17 |
| 122 | #define PIN_NOT_SET 127 |
| 123 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 124 | #define LCD_FLAG_S 0x0001 |
| 125 | #define LCD_FLAG_ID 0x0002 |
| 126 | #define LCD_FLAG_B 0x0004 /* blink on */ |
| 127 | #define LCD_FLAG_C 0x0008 /* cursor on */ |
| 128 | #define LCD_FLAG_D 0x0010 /* display on */ |
| 129 | #define LCD_FLAG_F 0x0020 /* large font mode */ |
| 130 | #define LCD_FLAG_N 0x0040 /* 2-rows mode */ |
| 131 | #define LCD_FLAG_L 0x0080 /* backlight enabled */ |
| 132 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 133 | #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 134 | #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */ |
| 135 | |
| 136 | /* macros to simplify use of the parallel port */ |
| 137 | #define r_ctr(x) (parport_read_control((x)->port)) |
| 138 | #define r_dtr(x) (parport_read_data((x)->port)) |
| 139 | #define r_str(x) (parport_read_status((x)->port)) |
Toshiaki Yamane | 6ebb56d | 2012-07-25 12:18:12 +0900 | [diff] [blame] | 140 | #define w_ctr(x, y) (parport_write_control((x)->port, (y))) |
| 141 | #define w_dtr(x, y) (parport_write_data((x)->port, (y))) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 142 | |
| 143 | /* 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] | 144 | /* logical or of the output bits involved in the scan matrix */ |
| 145 | static __u8 scan_mask_o; |
| 146 | /* logical or of the input bits involved in the scan matrix */ |
| 147 | static __u8 scan_mask_i; |
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 | typedef __u64 pmask_t; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 150 | |
| 151 | enum input_type { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 152 | INPUT_TYPE_STD, |
| 153 | INPUT_TYPE_KBD, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | enum input_state { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 157 | INPUT_ST_LOW, |
| 158 | INPUT_ST_RISING, |
| 159 | INPUT_ST_HIGH, |
| 160 | INPUT_ST_FALLING, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | struct logical_input { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 164 | struct list_head list; |
| 165 | pmask_t mask; |
| 166 | pmask_t value; |
| 167 | enum input_type type; |
| 168 | enum input_state state; |
| 169 | __u8 rise_time, fall_time; |
| 170 | __u8 rise_timer, fall_timer, high_timer; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 171 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 172 | union { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 173 | struct { /* valid when type == INPUT_TYPE_STD */ |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 174 | void (*press_fct)(int); |
| 175 | void (*release_fct)(int); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 176 | int press_data; |
| 177 | int release_data; |
| 178 | } std; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 179 | struct { /* valid when type == INPUT_TYPE_KBD */ |
| 180 | /* strings can be non null-terminated */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 181 | char press_str[sizeof(void *) + sizeof(int)]; |
| 182 | char repeat_str[sizeof(void *) + sizeof(int)]; |
| 183 | char release_str[sizeof(void *) + sizeof(int)]; |
| 184 | } kbd; |
| 185 | } u; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 186 | }; |
| 187 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 188 | static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 189 | |
| 190 | /* physical contacts history |
| 191 | * Physical contacts are a 45 bits string of 9 groups of 5 bits each. |
| 192 | * The 8 lower groups correspond to output bits 0 to 7, and the 9th group |
| 193 | * corresponds to the ground. |
| 194 | * Within each group, bits are stored in the same order as read on the port : |
| 195 | * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0). |
| 196 | * So, each __u64 (or pmask_t) is represented like this : |
| 197 | * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE |
| 198 | * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00> |
| 199 | */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 200 | |
| 201 | /* what has just been read from the I/O ports */ |
| 202 | static pmask_t phys_read; |
| 203 | /* previous phys_read */ |
| 204 | static pmask_t phys_read_prev; |
| 205 | /* stabilized phys_read (phys_read|phys_read_prev) */ |
| 206 | static pmask_t phys_curr; |
| 207 | /* previous phys_curr */ |
| 208 | static pmask_t phys_prev; |
| 209 | /* 0 means that at least one logical signal needs be computed */ |
| 210 | static char inputs_stable; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 211 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 212 | /* these variables are specific to the keypad */ |
| 213 | static char keypad_buffer[KEYPAD_BUFFER]; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 214 | static int keypad_buflen; |
| 215 | static int keypad_start; |
| 216 | static char keypressed; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 217 | static wait_queue_head_t keypad_read_wait; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 218 | |
| 219 | /* lcd-specific variables */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 220 | |
| 221 | /* contains the LCD config state */ |
| 222 | static unsigned long int lcd_flags; |
| 223 | /* contains the LCD X offset */ |
| 224 | static unsigned long int lcd_addr_x; |
| 225 | /* contains the LCD Y offset */ |
| 226 | static unsigned long int lcd_addr_y; |
| 227 | /* current escape sequence, 0 terminated */ |
| 228 | static char lcd_escape[LCD_ESCAPE_LEN + 1]; |
| 229 | /* not in escape state. >=0 = escape cmd len */ |
| 230 | static int lcd_escape_len = -1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 231 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 232 | /* |
| 233 | * Bit masks to convert LCD signals to parallel port outputs. |
| 234 | * _d_ are values for data port, _c_ are for control port. |
| 235 | * [0] = signal OFF, [1] = signal ON, [2] = mask |
| 236 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 237 | #define BIT_CLR 0 |
| 238 | #define BIT_SET 1 |
| 239 | #define BIT_MSK 2 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 240 | #define BIT_STATES 3 |
| 241 | /* |
| 242 | * one entry for each bit on the LCD |
| 243 | */ |
| 244 | #define LCD_BIT_E 0 |
| 245 | #define LCD_BIT_RS 1 |
| 246 | #define LCD_BIT_RW 2 |
| 247 | #define LCD_BIT_BL 3 |
| 248 | #define LCD_BIT_CL 4 |
| 249 | #define LCD_BIT_DA 5 |
| 250 | #define LCD_BITS 6 |
| 251 | |
| 252 | /* |
| 253 | * each bit can be either connected to a DATA or CTRL port |
| 254 | */ |
| 255 | #define LCD_PORT_C 0 |
| 256 | #define LCD_PORT_D 1 |
| 257 | #define LCD_PORTS 2 |
| 258 | |
| 259 | static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES]; |
| 260 | |
| 261 | /* |
| 262 | * LCD protocols |
| 263 | */ |
| 264 | #define LCD_PROTO_PARALLEL 0 |
| 265 | #define LCD_PROTO_SERIAL 1 |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 266 | #define LCD_PROTO_TI_DA8XX_LCD 2 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * LCD character sets |
| 270 | */ |
| 271 | #define LCD_CHARSET_NORMAL 0 |
| 272 | #define LCD_CHARSET_KS0074 1 |
| 273 | |
| 274 | /* |
| 275 | * LCD types |
| 276 | */ |
| 277 | #define LCD_TYPE_NONE 0 |
| 278 | #define LCD_TYPE_OLD 1 |
| 279 | #define LCD_TYPE_KS0074 2 |
| 280 | #define LCD_TYPE_HANTRONIX 3 |
| 281 | #define LCD_TYPE_NEXCOM 4 |
| 282 | #define LCD_TYPE_CUSTOM 5 |
| 283 | |
| 284 | /* |
| 285 | * keypad types |
| 286 | */ |
| 287 | #define KEYPAD_TYPE_NONE 0 |
| 288 | #define KEYPAD_TYPE_OLD 1 |
| 289 | #define KEYPAD_TYPE_NEW 2 |
| 290 | #define KEYPAD_TYPE_NEXCOM 3 |
| 291 | |
| 292 | /* |
| 293 | * panel profiles |
| 294 | */ |
| 295 | #define PANEL_PROFILE_CUSTOM 0 |
| 296 | #define PANEL_PROFILE_OLD 1 |
| 297 | #define PANEL_PROFILE_NEW 2 |
| 298 | #define PANEL_PROFILE_HANTRONIX 3 |
| 299 | #define PANEL_PROFILE_NEXCOM 4 |
| 300 | #define PANEL_PROFILE_LARGE 5 |
| 301 | |
| 302 | /* |
| 303 | * Construct custom config from the kernel's configuration |
| 304 | */ |
| 305 | #define DEFAULT_PROFILE PANEL_PROFILE_LARGE |
| 306 | #define DEFAULT_PARPORT 0 |
| 307 | #define DEFAULT_LCD LCD_TYPE_OLD |
| 308 | #define DEFAULT_KEYPAD KEYPAD_TYPE_OLD |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 309 | #define DEFAULT_LCD_WIDTH 40 |
| 310 | #define DEFAULT_LCD_BWIDTH 40 |
| 311 | #define DEFAULT_LCD_HWIDTH 64 |
| 312 | #define DEFAULT_LCD_HEIGHT 2 |
| 313 | #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL |
| 314 | |
| 315 | #define DEFAULT_LCD_PIN_E PIN_AUTOLF |
| 316 | #define DEFAULT_LCD_PIN_RS PIN_SELECP |
| 317 | #define DEFAULT_LCD_PIN_RW PIN_INITP |
| 318 | #define DEFAULT_LCD_PIN_SCL PIN_STROBE |
| 319 | #define DEFAULT_LCD_PIN_SDA PIN_D0 |
| 320 | #define DEFAULT_LCD_PIN_BL PIN_NOT_SET |
| 321 | #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL |
| 322 | |
| 323 | #ifdef CONFIG_PANEL_PROFILE |
| 324 | #undef DEFAULT_PROFILE |
| 325 | #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE |
| 326 | #endif |
| 327 | |
| 328 | #ifdef CONFIG_PANEL_PARPORT |
| 329 | #undef DEFAULT_PARPORT |
| 330 | #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT |
| 331 | #endif |
| 332 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 333 | #if DEFAULT_PROFILE == 0 /* custom */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 334 | #ifdef CONFIG_PANEL_KEYPAD |
| 335 | #undef DEFAULT_KEYPAD |
| 336 | #define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD |
| 337 | #endif |
| 338 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 339 | #ifdef CONFIG_PANEL_LCD |
| 340 | #undef DEFAULT_LCD |
| 341 | #define DEFAULT_LCD CONFIG_PANEL_LCD |
| 342 | #endif |
| 343 | |
| 344 | #ifdef CONFIG_PANEL_LCD_WIDTH |
| 345 | #undef DEFAULT_LCD_WIDTH |
| 346 | #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH |
| 347 | #endif |
| 348 | |
| 349 | #ifdef CONFIG_PANEL_LCD_BWIDTH |
| 350 | #undef DEFAULT_LCD_BWIDTH |
| 351 | #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH |
| 352 | #endif |
| 353 | |
| 354 | #ifdef CONFIG_PANEL_LCD_HWIDTH |
| 355 | #undef DEFAULT_LCD_HWIDTH |
| 356 | #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH |
| 357 | #endif |
| 358 | |
| 359 | #ifdef CONFIG_PANEL_LCD_HEIGHT |
| 360 | #undef DEFAULT_LCD_HEIGHT |
| 361 | #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT |
| 362 | #endif |
| 363 | |
| 364 | #ifdef CONFIG_PANEL_LCD_PROTO |
| 365 | #undef DEFAULT_LCD_PROTO |
| 366 | #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO |
| 367 | #endif |
| 368 | |
| 369 | #ifdef CONFIG_PANEL_LCD_PIN_E |
| 370 | #undef DEFAULT_LCD_PIN_E |
| 371 | #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E |
| 372 | #endif |
| 373 | |
| 374 | #ifdef CONFIG_PANEL_LCD_PIN_RS |
| 375 | #undef DEFAULT_LCD_PIN_RS |
| 376 | #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS |
| 377 | #endif |
| 378 | |
| 379 | #ifdef CONFIG_PANEL_LCD_PIN_RW |
| 380 | #undef DEFAULT_LCD_PIN_RW |
| 381 | #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW |
| 382 | #endif |
| 383 | |
| 384 | #ifdef CONFIG_PANEL_LCD_PIN_SCL |
| 385 | #undef DEFAULT_LCD_PIN_SCL |
| 386 | #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL |
| 387 | #endif |
| 388 | |
| 389 | #ifdef CONFIG_PANEL_LCD_PIN_SDA |
| 390 | #undef DEFAULT_LCD_PIN_SDA |
| 391 | #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA |
| 392 | #endif |
| 393 | |
| 394 | #ifdef CONFIG_PANEL_LCD_PIN_BL |
| 395 | #undef DEFAULT_LCD_PIN_BL |
| 396 | #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL |
| 397 | #endif |
| 398 | |
| 399 | #ifdef CONFIG_PANEL_LCD_CHARSET |
| 400 | #undef DEFAULT_LCD_CHARSET |
Peter Huewe | a6a6c90 | 2009-12-15 06:21:45 +0100 | [diff] [blame] | 401 | #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 402 | #endif |
| 403 | |
| 404 | #endif /* DEFAULT_PROFILE == 0 */ |
| 405 | |
| 406 | /* global variables */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 407 | static int keypad_open_cnt; /* #times opened */ |
| 408 | static int lcd_open_cnt; /* #times opened */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 409 | static struct pardevice *pprt; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 410 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 411 | static int lcd_initialized; |
| 412 | static int keypad_initialized; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 413 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 414 | static int light_tempo; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 415 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 416 | static char lcd_must_clear; |
| 417 | static char lcd_left_shift; |
| 418 | static char init_in_progress; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 419 | |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 420 | static void (*lcd_write_cmd)(int); |
| 421 | static void (*lcd_write_data)(int); |
| 422 | static void (*lcd_clear_fast)(void); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 423 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 424 | static DEFINE_SPINLOCK(pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 425 | static struct timer_list scan_timer; |
| 426 | |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 427 | MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 428 | |
| 429 | static int parport = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 430 | module_param(parport, int, 0000); |
| 431 | MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 432 | |
| 433 | static int lcd_height = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 434 | module_param(lcd_height, int, 0000); |
| 435 | MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 436 | |
| 437 | static int lcd_width = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 438 | module_param(lcd_width, int, 0000); |
| 439 | MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 440 | |
| 441 | static int lcd_bwidth = -1; /* internal buffer width (usually 40) */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 442 | module_param(lcd_bwidth, int, 0000); |
| 443 | MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 444 | |
| 445 | static int lcd_hwidth = -1; /* hardware buffer width (usually 64) */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 446 | module_param(lcd_hwidth, int, 0000); |
| 447 | MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 448 | |
| 449 | static int lcd_enabled = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 450 | module_param(lcd_enabled, int, 0000); |
| 451 | MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 452 | |
| 453 | static int keypad_enabled = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 454 | module_param(keypad_enabled, int, 0000); |
| 455 | MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 456 | |
| 457 | static int lcd_type = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 458 | module_param(lcd_type, int, 0000); |
| 459 | MODULE_PARM_DESC(lcd_type, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 460 | "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 461 | |
| 462 | static int lcd_proto = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 463 | module_param(lcd_proto, int, 0000); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 464 | MODULE_PARM_DESC(lcd_proto, |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 465 | "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 466 | |
| 467 | static int lcd_charset = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 468 | module_param(lcd_charset, int, 0000); |
| 469 | MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 470 | |
| 471 | static int keypad_type = -1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 472 | module_param(keypad_type, int, 0000); |
| 473 | MODULE_PARM_DESC(keypad_type, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 474 | "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 475 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 476 | static int profile = DEFAULT_PROFILE; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 477 | module_param(profile, int, 0000); |
| 478 | MODULE_PARM_DESC(profile, |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 479 | "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; " |
| 480 | "4=16x2 nexcom; default=40x2, old kp"); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 481 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 482 | /* |
| 483 | * These are the parallel port pins the LCD control signals are connected to. |
| 484 | * Set this to 0 if the signal is not used. Set it to its opposite value |
| 485 | * (negative) if the signal is negated. -MAXINT is used to indicate that the |
| 486 | * pin has not been explicitly specified. |
| 487 | * |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 488 | * WARNING! no check will be performed about collisions with keypad ! |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 489 | */ |
| 490 | |
| 491 | static int lcd_e_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 492 | module_param(lcd_e_pin, int, 0000); |
| 493 | MODULE_PARM_DESC(lcd_e_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 494 | "# 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] | 495 | |
| 496 | static int lcd_rs_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 497 | module_param(lcd_rs_pin, int, 0000); |
| 498 | MODULE_PARM_DESC(lcd_rs_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 499 | "# 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] | 500 | |
| 501 | static int lcd_rw_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 502 | module_param(lcd_rw_pin, int, 0000); |
| 503 | MODULE_PARM_DESC(lcd_rw_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 504 | "# 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] | 505 | |
| 506 | static int lcd_bl_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 507 | module_param(lcd_bl_pin, int, 0000); |
| 508 | MODULE_PARM_DESC(lcd_bl_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 509 | "# of the // port pin connected to LCD backlight, with polarity (-17..17)"); |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 510 | |
| 511 | static int lcd_da_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 512 | module_param(lcd_da_pin, int, 0000); |
| 513 | MODULE_PARM_DESC(lcd_da_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 514 | "# 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] | 515 | |
| 516 | static int lcd_cl_pin = PIN_NOT_SET; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 517 | module_param(lcd_cl_pin, int, 0000); |
| 518 | MODULE_PARM_DESC(lcd_cl_pin, |
Monam Agarwal | fe5d2e0 | 2014-02-25 19:42:46 +0530 | [diff] [blame] | 519 | "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)"); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 520 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 521 | static const unsigned char *lcd_char_conv; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 522 | |
| 523 | /* for some LCD drivers (ks0074) we need a charset conversion table. */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 524 | static const unsigned char lcd_char_conv_ks0074[256] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 525 | /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */ |
| 526 | /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 527 | /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 528 | /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 529 | /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 530 | /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27, |
| 531 | /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, |
| 532 | /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
| 533 | /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, |
| 534 | /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
| 535 | /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, |
| 536 | /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, |
| 537 | /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4, |
| 538 | /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 539 | /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
| 540 | /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 541 | /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20, |
| 542 | /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 543 | /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, |
| 544 | /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 545 | /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, |
| 546 | /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f, |
| 547 | /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96, |
| 548 | /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd, |
| 549 | /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60, |
| 550 | /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9, |
| 551 | /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3, |
| 552 | /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78, |
| 553 | /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe, |
| 554 | /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8, |
| 555 | /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69, |
| 556 | /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25, |
| 557 | /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 558 | }; |
| 559 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 560 | static const char old_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 561 | {"S0", "Left\n", "Left\n", ""}, |
| 562 | {"S1", "Down\n", "Down\n", ""}, |
| 563 | {"S2", "Up\n", "Up\n", ""}, |
| 564 | {"S3", "Right\n", "Right\n", ""}, |
| 565 | {"S4", "Esc\n", "Esc\n", ""}, |
| 566 | {"S5", "Ret\n", "Ret\n", ""}, |
| 567 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 568 | }; |
| 569 | |
| 570 | /* signals, press, repeat, release */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 571 | static const char new_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 572 | {"S0", "Left\n", "Left\n", ""}, |
| 573 | {"S1", "Down\n", "Down\n", ""}, |
| 574 | {"S2", "Up\n", "Up\n", ""}, |
| 575 | {"S3", "Right\n", "Right\n", ""}, |
| 576 | {"S4s5", "", "Esc\n", "Esc\n"}, |
| 577 | {"s4S5", "", "Ret\n", "Ret\n"}, |
| 578 | {"S4S5", "Help\n", "", ""}, |
| 579 | /* add new signals above this line */ |
| 580 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | /* signals, press, repeat, release */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 584 | static const char nexcom_keypad_profile[][4][9] = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 585 | {"a-p-e-", "Down\n", "Down\n", ""}, |
| 586 | {"a-p-E-", "Ret\n", "Ret\n", ""}, |
| 587 | {"a-P-E-", "Esc\n", "Esc\n", ""}, |
| 588 | {"a-P-e-", "Up\n", "Up\n", ""}, |
| 589 | /* add new signals above this line */ |
| 590 | {"", "", "", ""} |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 591 | }; |
| 592 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 593 | static const char (*keypad_profile)[4][9] = old_keypad_profile; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 594 | |
| 595 | /* FIXME: this should be converted to a bit array containing signals states */ |
| 596 | static struct { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 597 | unsigned char e; /* parallel LCD E (data latch on falling edge) */ |
| 598 | unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */ |
| 599 | unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */ |
| 600 | unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */ |
| 601 | unsigned char cl; /* serial LCD clock (latch on rising edge) */ |
| 602 | unsigned char da; /* serial LCD data */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 603 | } bits; |
| 604 | |
| 605 | static void init_scan_timer(void); |
| 606 | |
| 607 | /* sets data port bits according to current signals values */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 608 | static int set_data_bits(void) |
| 609 | { |
| 610 | int val, bit; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 611 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 612 | val = r_dtr(pprt); |
| 613 | for (bit = 0; bit < LCD_BITS; bit++) |
| 614 | val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK]; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 615 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 616 | val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e] |
| 617 | | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs] |
| 618 | | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw] |
| 619 | | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl] |
| 620 | | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl] |
| 621 | | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da]; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 622 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 623 | w_dtr(pprt, val); |
| 624 | return val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* sets ctrl port bits according to current signals values */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 628 | static int set_ctrl_bits(void) |
| 629 | { |
| 630 | int val, bit; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 631 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 632 | val = r_ctr(pprt); |
| 633 | for (bit = 0; bit < LCD_BITS; bit++) |
| 634 | val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK]; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 635 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 636 | val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e] |
| 637 | | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs] |
| 638 | | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw] |
| 639 | | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl] |
| 640 | | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl] |
| 641 | | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da]; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 642 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 643 | w_ctr(pprt, val); |
| 644 | return val; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* sets ctrl & data port bits according to current signals values */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 648 | static void panel_set_bits(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 649 | { |
| 650 | set_data_bits(); |
| 651 | set_ctrl_bits(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Converts a parallel port pin (from -25 to 25) to data and control ports |
| 656 | * masks, and data and control port bits. The signal will be considered |
| 657 | * unconnected if it's on pin 0 or an invalid pin (<-25 or >25). |
| 658 | * |
| 659 | * Result will be used this way : |
| 660 | * out(dport, in(dport) & d_val[2] | d_val[signal_state]) |
| 661 | * out(cport, in(cport) & c_val[2] | c_val[signal_state]) |
| 662 | */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 663 | 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] | 664 | { |
| 665 | int d_bit, c_bit, inv; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 666 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 667 | d_val[0] = 0; |
| 668 | c_val[0] = 0; |
| 669 | d_val[1] = 0; |
| 670 | c_val[1] = 0; |
| 671 | d_val[2] = 0xFF; |
| 672 | c_val[2] = 0xFF; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 673 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 674 | if (pin == 0) |
| 675 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 676 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 677 | inv = (pin < 0); |
| 678 | if (inv) |
| 679 | pin = -pin; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 680 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 681 | d_bit = 0; |
| 682 | c_bit = 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 683 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 684 | switch (pin) { |
| 685 | case PIN_STROBE: /* strobe, inverted */ |
| 686 | c_bit = PNL_PSTROBE; |
| 687 | inv = !inv; |
| 688 | break; |
| 689 | case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */ |
| 690 | d_bit = 1 << (pin - 2); |
| 691 | break; |
| 692 | case PIN_AUTOLF: /* autofeed, inverted */ |
| 693 | c_bit = PNL_PAUTOLF; |
| 694 | inv = !inv; |
| 695 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 696 | case PIN_INITP: /* init, direct */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 697 | c_bit = PNL_PINITP; |
| 698 | break; |
| 699 | case PIN_SELECP: /* select_in, inverted */ |
| 700 | c_bit = PNL_PSELECP; |
| 701 | inv = !inv; |
| 702 | break; |
| 703 | default: /* unknown pin, ignore */ |
| 704 | break; |
| 705 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 706 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 707 | if (c_bit) { |
| 708 | c_val[2] &= ~c_bit; |
| 709 | c_val[!inv] = c_bit; |
| 710 | } else if (d_bit) { |
| 711 | d_val[2] &= ~d_bit; |
| 712 | d_val[!inv] = d_bit; |
| 713 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /* sleeps that many milliseconds with a reschedule */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 717 | static void long_sleep(int ms) |
| 718 | { |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 719 | if (in_interrupt()) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 720 | mdelay(ms); |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 721 | } else { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 722 | current->state = TASK_INTERRUPTIBLE; |
| 723 | schedule_timeout((ms * HZ + 999) / 1000); |
| 724 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 727 | /* send a serial byte to the LCD panel. The caller is responsible for locking |
| 728 | if needed. */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 729 | static void lcd_send_serial(int byte) |
| 730 | { |
| 731 | int bit; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 732 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 733 | /* the data bit is set on D0, and the clock on STROBE. |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 734 | * LCD reads D0 on STROBE's rising edge. */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 735 | for (bit = 0; bit < 8; bit++) { |
| 736 | bits.cl = BIT_CLR; /* CLK low */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 737 | panel_set_bits(); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 738 | bits.da = byte & 1; |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 739 | panel_set_bits(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 740 | udelay(2); /* maintain the data during 2 us before CLK up */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 741 | bits.cl = BIT_SET; /* CLK high */ |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 742 | panel_set_bits(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 743 | udelay(1); /* maintain the strobe during 1 us */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 744 | byte >>= 1; |
| 745 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* turn the backlight on or off */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 749 | static void lcd_backlight(int on) |
| 750 | { |
| 751 | if (lcd_bl_pin == PIN_NONE) |
| 752 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 753 | |
Justin P. Mattock | 6975e18 | 2012-03-19 08:17:52 -0700 | [diff] [blame] | 754 | /* The backlight is activated by setting the AUTOFEED line to +5V */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 755 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 756 | bits.bl = on; |
Sachin P. Sant | 6136ac8 | 2009-02-03 21:10:58 +0530 | [diff] [blame] | 757 | panel_set_bits(); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 758 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /* send a command to the LCD panel in serial mode */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 762 | static void lcd_write_cmd_s(int cmd) |
| 763 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 764 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 765 | lcd_send_serial(0x1F); /* R/W=W, RS=0 */ |
| 766 | lcd_send_serial(cmd & 0x0F); |
| 767 | lcd_send_serial((cmd >> 4) & 0x0F); |
| 768 | udelay(40); /* the shortest command takes at least 40 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 769 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* send data to the LCD panel in serial mode */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 773 | static void lcd_write_data_s(int data) |
| 774 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 775 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 776 | lcd_send_serial(0x5F); /* R/W=W, RS=1 */ |
| 777 | lcd_send_serial(data & 0x0F); |
| 778 | lcd_send_serial((data >> 4) & 0x0F); |
| 779 | udelay(40); /* the shortest data takes at least 40 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 780 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* send a command to the LCD panel in 8 bits parallel mode */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 784 | static void lcd_write_cmd_p8(int cmd) |
| 785 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 786 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 787 | /* present the data to the data port */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 788 | w_dtr(pprt, cmd); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 789 | udelay(20); /* maintain the data during 20 us before the strobe */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 790 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 791 | bits.e = BIT_SET; |
| 792 | bits.rs = BIT_CLR; |
| 793 | bits.rw = BIT_CLR; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 794 | set_ctrl_bits(); |
| 795 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 796 | udelay(40); /* maintain the strobe during 40 us */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 797 | |
| 798 | bits.e = BIT_CLR; |
| 799 | set_ctrl_bits(); |
| 800 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 801 | udelay(120); /* the shortest command takes at least 120 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 802 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 803 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 804 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 805 | /* send data to the LCD panel in 8 bits parallel mode */ |
| 806 | static void lcd_write_data_p8(int data) |
| 807 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 808 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 809 | /* present the data to the data port */ |
| 810 | w_dtr(pprt, data); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 811 | udelay(20); /* maintain the data during 20 us before the strobe */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 812 | |
| 813 | bits.e = BIT_SET; |
| 814 | bits.rs = BIT_SET; |
| 815 | bits.rw = BIT_CLR; |
| 816 | set_ctrl_bits(); |
| 817 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 818 | udelay(40); /* maintain the strobe during 40 us */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 819 | |
| 820 | bits.e = BIT_CLR; |
| 821 | set_ctrl_bits(); |
| 822 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 823 | udelay(45); /* the shortest data takes at least 45 us */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 824 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 825 | } |
| 826 | |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 827 | /* send a command to the TI LCD panel */ |
| 828 | static void lcd_write_cmd_tilcd(int cmd) |
| 829 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 830 | spin_lock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 831 | /* present the data to the control port */ |
| 832 | w_ctr(pprt, cmd); |
| 833 | udelay(60); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 834 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* send data to the TI LCD panel */ |
| 838 | static void lcd_write_data_tilcd(int data) |
| 839 | { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 840 | spin_lock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 841 | /* present the data to the data port */ |
| 842 | w_dtr(pprt, data); |
| 843 | udelay(60); |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 844 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 845 | } |
| 846 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 847 | static void lcd_gotoxy(void) |
| 848 | { |
| 849 | lcd_write_cmd(0x80 /* set DDRAM address */ |
| 850 | | (lcd_addr_y ? lcd_hwidth : 0) |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 851 | /* we force the cursor to stay at the end of the |
| 852 | line if it wants to go farther */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 853 | | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x & |
| 854 | (lcd_hwidth - 1) : lcd_bwidth - 1)); |
| 855 | } |
| 856 | |
| 857 | static void lcd_print(char c) |
| 858 | { |
| 859 | if (lcd_addr_x < lcd_bwidth) { |
| 860 | if (lcd_char_conv != NULL) |
| 861 | c = lcd_char_conv[(unsigned char)c]; |
| 862 | lcd_write_data(c); |
| 863 | lcd_addr_x++; |
| 864 | } |
| 865 | /* prevents the cursor from wrapping onto the next line */ |
| 866 | if (lcd_addr_x == lcd_bwidth) |
| 867 | lcd_gotoxy(); |
| 868 | } |
| 869 | |
| 870 | /* fills the display with spaces and resets X/Y */ |
| 871 | static void lcd_clear_fast_s(void) |
| 872 | { |
| 873 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 874 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 875 | lcd_addr_x = 0; |
| 876 | lcd_addr_y = 0; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 877 | lcd_gotoxy(); |
| 878 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 879 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 880 | for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { |
| 881 | lcd_send_serial(0x5F); /* R/W=W, RS=1 */ |
| 882 | lcd_send_serial(' ' & 0x0F); |
| 883 | lcd_send_serial((' ' >> 4) & 0x0F); |
| 884 | udelay(40); /* the shortest data takes at least 40 us */ |
| 885 | } |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 886 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 887 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 888 | lcd_addr_x = 0; |
| 889 | lcd_addr_y = 0; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 890 | lcd_gotoxy(); |
| 891 | } |
| 892 | |
| 893 | /* fills the display with spaces and resets X/Y */ |
| 894 | static void lcd_clear_fast_p8(void) |
| 895 | { |
| 896 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 897 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 898 | lcd_addr_x = 0; |
| 899 | lcd_addr_y = 0; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 900 | lcd_gotoxy(); |
| 901 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 902 | spin_lock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 903 | for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { |
| 904 | /* present the data to the data port */ |
| 905 | w_dtr(pprt, ' '); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 906 | |
| 907 | /* maintain the data during 20 us before the strobe */ |
| 908 | udelay(20); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 909 | |
| 910 | bits.e = BIT_SET; |
| 911 | bits.rs = BIT_SET; |
| 912 | bits.rw = BIT_CLR; |
| 913 | set_ctrl_bits(); |
| 914 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 915 | /* maintain the strobe during 40 us */ |
| 916 | udelay(40); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 917 | |
| 918 | bits.e = BIT_CLR; |
| 919 | set_ctrl_bits(); |
| 920 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 921 | /* the shortest data takes at least 45 us */ |
| 922 | udelay(45); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 923 | } |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 924 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 925 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 926 | lcd_addr_x = 0; |
| 927 | lcd_addr_y = 0; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 928 | lcd_gotoxy(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 931 | /* fills the display with spaces and resets X/Y */ |
| 932 | static void lcd_clear_fast_tilcd(void) |
| 933 | { |
| 934 | int pos; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 935 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 936 | lcd_addr_x = 0; |
| 937 | lcd_addr_y = 0; |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 938 | lcd_gotoxy(); |
| 939 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 940 | spin_lock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 941 | for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { |
| 942 | /* present the data to the data port */ |
| 943 | w_dtr(pprt, ' '); |
| 944 | udelay(60); |
| 945 | } |
| 946 | |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 947 | spin_unlock_irq(&pprt_lock); |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 948 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 949 | lcd_addr_x = 0; |
| 950 | lcd_addr_y = 0; |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 951 | lcd_gotoxy(); |
| 952 | } |
| 953 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 954 | /* clears the display and resets X/Y */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 955 | static void lcd_clear_display(void) |
| 956 | { |
| 957 | lcd_write_cmd(0x01); /* clear display */ |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 958 | lcd_addr_x = 0; |
| 959 | lcd_addr_y = 0; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 960 | /* we must wait a few milliseconds (15) */ |
| 961 | long_sleep(15); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 962 | } |
| 963 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 964 | static void lcd_init_display(void) |
| 965 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 966 | lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0) |
| 967 | | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 968 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 969 | long_sleep(20); /* wait 20 ms after power-up for the paranoid */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 970 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 971 | lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ |
| 972 | long_sleep(10); |
| 973 | lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ |
| 974 | long_sleep(10); |
| 975 | lcd_write_cmd(0x30); /* 8bits, 1 line, small fonts */ |
| 976 | long_sleep(10); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 977 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 978 | lcd_write_cmd(0x30 /* set font height and lines number */ |
| 979 | | ((lcd_flags & LCD_FLAG_F) ? 4 : 0) |
| 980 | | ((lcd_flags & LCD_FLAG_N) ? 8 : 0) |
| 981 | ); |
| 982 | long_sleep(10); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 983 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 984 | lcd_write_cmd(0x08); /* display off, cursor off, blink off */ |
| 985 | long_sleep(10); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 986 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 987 | lcd_write_cmd(0x08 /* set display mode */ |
| 988 | | ((lcd_flags & LCD_FLAG_D) ? 4 : 0) |
| 989 | | ((lcd_flags & LCD_FLAG_C) ? 2 : 0) |
| 990 | | ((lcd_flags & LCD_FLAG_B) ? 1 : 0) |
| 991 | ); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 992 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 993 | lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 994 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 995 | long_sleep(10); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 996 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 997 | /* entry mode set : increment, cursor shifting */ |
| 998 | lcd_write_cmd(0x06); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 999 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1000 | lcd_clear_display(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | * These are the file operation function for user access to /dev/lcd |
| 1005 | * This function can also be called from inside the kernel, by |
| 1006 | * setting file and ppos to NULL. |
| 1007 | * |
| 1008 | */ |
| 1009 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1010 | static inline int handle_lcd_special_code(void) |
| 1011 | { |
| 1012 | /* LCD special codes */ |
| 1013 | |
| 1014 | int processed = 0; |
| 1015 | |
| 1016 | char *esc = lcd_escape + 2; |
| 1017 | int oldflags = lcd_flags; |
| 1018 | |
| 1019 | /* check for display mode flags */ |
| 1020 | switch (*esc) { |
| 1021 | case 'D': /* Display ON */ |
| 1022 | lcd_flags |= LCD_FLAG_D; |
| 1023 | processed = 1; |
| 1024 | break; |
| 1025 | case 'd': /* Display OFF */ |
| 1026 | lcd_flags &= ~LCD_FLAG_D; |
| 1027 | processed = 1; |
| 1028 | break; |
| 1029 | case 'C': /* Cursor ON */ |
| 1030 | lcd_flags |= LCD_FLAG_C; |
| 1031 | processed = 1; |
| 1032 | break; |
| 1033 | case 'c': /* Cursor OFF */ |
| 1034 | lcd_flags &= ~LCD_FLAG_C; |
| 1035 | processed = 1; |
| 1036 | break; |
| 1037 | case 'B': /* Blink ON */ |
| 1038 | lcd_flags |= LCD_FLAG_B; |
| 1039 | processed = 1; |
| 1040 | break; |
| 1041 | case 'b': /* Blink OFF */ |
| 1042 | lcd_flags &= ~LCD_FLAG_B; |
| 1043 | processed = 1; |
| 1044 | break; |
| 1045 | case '+': /* Back light ON */ |
| 1046 | lcd_flags |= LCD_FLAG_L; |
| 1047 | processed = 1; |
| 1048 | break; |
| 1049 | case '-': /* Back light OFF */ |
| 1050 | lcd_flags &= ~LCD_FLAG_L; |
| 1051 | processed = 1; |
| 1052 | break; |
| 1053 | case '*': |
| 1054 | /* flash back light using the keypad timer */ |
| 1055 | if (scan_timer.function != NULL) { |
| 1056 | if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) |
| 1057 | lcd_backlight(1); |
| 1058 | light_tempo = FLASH_LIGHT_TEMPO; |
| 1059 | } |
| 1060 | processed = 1; |
| 1061 | break; |
| 1062 | case 'f': /* Small Font */ |
| 1063 | lcd_flags &= ~LCD_FLAG_F; |
| 1064 | processed = 1; |
| 1065 | break; |
| 1066 | case 'F': /* Large Font */ |
| 1067 | lcd_flags |= LCD_FLAG_F; |
| 1068 | processed = 1; |
| 1069 | break; |
| 1070 | case 'n': /* One Line */ |
| 1071 | lcd_flags &= ~LCD_FLAG_N; |
| 1072 | processed = 1; |
| 1073 | break; |
| 1074 | case 'N': /* Two Lines */ |
| 1075 | lcd_flags |= LCD_FLAG_N; |
| 1076 | break; |
| 1077 | case 'l': /* Shift Cursor Left */ |
| 1078 | if (lcd_addr_x > 0) { |
| 1079 | /* back one char if not at end of line */ |
| 1080 | if (lcd_addr_x < lcd_bwidth) |
| 1081 | lcd_write_cmd(0x10); |
| 1082 | lcd_addr_x--; |
| 1083 | } |
| 1084 | processed = 1; |
| 1085 | break; |
| 1086 | case 'r': /* shift cursor right */ |
| 1087 | if (lcd_addr_x < lcd_width) { |
| 1088 | /* allow the cursor to pass the end of the line */ |
| 1089 | if (lcd_addr_x < |
| 1090 | (lcd_bwidth - 1)) |
| 1091 | lcd_write_cmd(0x14); |
| 1092 | lcd_addr_x++; |
| 1093 | } |
| 1094 | processed = 1; |
| 1095 | break; |
| 1096 | case 'L': /* shift display left */ |
| 1097 | lcd_left_shift++; |
| 1098 | lcd_write_cmd(0x18); |
| 1099 | processed = 1; |
| 1100 | break; |
| 1101 | case 'R': /* shift display right */ |
| 1102 | lcd_left_shift--; |
| 1103 | lcd_write_cmd(0x1C); |
| 1104 | processed = 1; |
| 1105 | break; |
| 1106 | case 'k': { /* kill end of line */ |
| 1107 | int x; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1108 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1109 | for (x = lcd_addr_x; x < lcd_bwidth; x++) |
| 1110 | lcd_write_data(' '); |
| 1111 | |
| 1112 | /* restore cursor position */ |
| 1113 | lcd_gotoxy(); |
| 1114 | processed = 1; |
| 1115 | break; |
| 1116 | } |
| 1117 | case 'I': /* reinitialize display */ |
| 1118 | lcd_init_display(); |
| 1119 | lcd_left_shift = 0; |
| 1120 | processed = 1; |
| 1121 | break; |
| 1122 | case 'G': { |
| 1123 | /* Generator : LGcxxxxx...xx; must have <c> between '0' |
| 1124 | * and '7', representing the numerical ASCII code of the |
| 1125 | * redefined character, and <xx...xx> a sequence of 16 |
| 1126 | * hex digits representing 8 bytes for each character. |
| 1127 | * Most LCDs will only use 5 lower bits of the 7 first |
| 1128 | * bytes. |
| 1129 | */ |
| 1130 | |
| 1131 | unsigned char cgbytes[8]; |
| 1132 | unsigned char cgaddr; |
| 1133 | int cgoffset; |
| 1134 | int shift; |
| 1135 | char value; |
| 1136 | int addr; |
| 1137 | |
| 1138 | if (strchr(esc, ';') == NULL) |
| 1139 | break; |
| 1140 | |
| 1141 | esc++; |
| 1142 | |
| 1143 | cgaddr = *(esc++) - '0'; |
| 1144 | if (cgaddr > 7) { |
| 1145 | processed = 1; |
| 1146 | break; |
| 1147 | } |
| 1148 | |
| 1149 | cgoffset = 0; |
| 1150 | shift = 0; |
| 1151 | value = 0; |
| 1152 | while (*esc && cgoffset < 8) { |
| 1153 | shift ^= 4; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1154 | if (*esc >= '0' && *esc <= '9') { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1155 | value |= (*esc - '0') << shift; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1156 | } else if (*esc >= 'A' && *esc <= 'Z') { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1157 | value |= (*esc - 'A' + 10) << shift; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1158 | } else if (*esc >= 'a' && *esc <= 'z') { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1159 | value |= (*esc - 'a' + 10) << shift; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1160 | } else { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1161 | esc++; |
| 1162 | continue; |
| 1163 | } |
| 1164 | |
| 1165 | if (shift == 0) { |
| 1166 | cgbytes[cgoffset++] = value; |
| 1167 | value = 0; |
| 1168 | } |
| 1169 | |
| 1170 | esc++; |
| 1171 | } |
| 1172 | |
| 1173 | lcd_write_cmd(0x40 | (cgaddr * 8)); |
| 1174 | for (addr = 0; addr < cgoffset; addr++) |
| 1175 | lcd_write_data(cgbytes[addr]); |
| 1176 | |
| 1177 | /* ensures that we stop writing to CGRAM */ |
| 1178 | lcd_gotoxy(); |
| 1179 | processed = 1; |
| 1180 | break; |
| 1181 | } |
| 1182 | case 'x': /* gotoxy : LxXXX[yYYY]; */ |
| 1183 | case 'y': /* gotoxy : LyYYY[xXXX]; */ |
| 1184 | if (strchr(esc, ';') == NULL) |
| 1185 | break; |
| 1186 | |
| 1187 | while (*esc) { |
| 1188 | if (*esc == 'x') { |
| 1189 | esc++; |
Pelle Windestam | 1299570 | 2011-08-30 20:29:24 +0200 | [diff] [blame] | 1190 | if (kstrtoul(esc, 10, &lcd_addr_x) < 0) |
| 1191 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1192 | } else if (*esc == 'y') { |
| 1193 | esc++; |
Pelle Windestam | 1299570 | 2011-08-30 20:29:24 +0200 | [diff] [blame] | 1194 | if (kstrtoul(esc, 10, &lcd_addr_y) < 0) |
| 1195 | break; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1196 | } else { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1197 | break; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1198 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | lcd_gotoxy(); |
| 1202 | processed = 1; |
| 1203 | break; |
| 1204 | } |
| 1205 | |
Adam Buchbinder | f263589 | 2012-09-19 21:51:07 -0400 | [diff] [blame] | 1206 | /* Check whether one flag was changed */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1207 | if (oldflags != lcd_flags) { |
| 1208 | /* check whether one of B,C,D flags were changed */ |
| 1209 | if ((oldflags ^ lcd_flags) & |
| 1210 | (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D)) |
| 1211 | /* set display mode */ |
| 1212 | lcd_write_cmd(0x08 |
| 1213 | | ((lcd_flags & LCD_FLAG_D) ? 4 : 0) |
| 1214 | | ((lcd_flags & LCD_FLAG_C) ? 2 : 0) |
| 1215 | | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)); |
| 1216 | /* check whether one of F,N flags was changed */ |
| 1217 | else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N)) |
| 1218 | lcd_write_cmd(0x30 |
| 1219 | | ((lcd_flags & LCD_FLAG_F) ? 4 : 0) |
| 1220 | | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)); |
Adam Buchbinder | f263589 | 2012-09-19 21:51:07 -0400 | [diff] [blame] | 1221 | /* check whether L flag was changed */ |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1222 | else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) { |
| 1223 | if (lcd_flags & (LCD_FLAG_L)) |
| 1224 | lcd_backlight(1); |
| 1225 | else if (light_tempo == 0) |
| 1226 | /* switch off the light only when the tempo |
| 1227 | lighting is gone */ |
| 1228 | lcd_backlight(0); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | return processed; |
| 1233 | } |
| 1234 | |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1235 | static void lcd_write_char(char c) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1236 | { |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1237 | /* first, we'll test if we're in escape mode */ |
| 1238 | if ((c != '\n') && lcd_escape_len >= 0) { |
| 1239 | /* yes, let's add this char to the buffer */ |
| 1240 | lcd_escape[lcd_escape_len++] = c; |
| 1241 | lcd_escape[lcd_escape_len] = 0; |
| 1242 | } else { |
| 1243 | /* aborts any previous escape sequence */ |
| 1244 | lcd_escape_len = -1; |
| 1245 | |
| 1246 | switch (c) { |
| 1247 | case LCD_ESCAPE_CHAR: |
| 1248 | /* start of an escape sequence */ |
| 1249 | lcd_escape_len = 0; |
| 1250 | lcd_escape[lcd_escape_len] = 0; |
| 1251 | break; |
| 1252 | case '\b': |
| 1253 | /* go back one char and clear it */ |
| 1254 | if (lcd_addr_x > 0) { |
| 1255 | /* check if we're not at the |
| 1256 | end of the line */ |
| 1257 | if (lcd_addr_x < lcd_bwidth) |
| 1258 | /* back one char */ |
| 1259 | lcd_write_cmd(0x10); |
| 1260 | lcd_addr_x--; |
| 1261 | } |
| 1262 | /* replace with a space */ |
| 1263 | lcd_write_data(' '); |
| 1264 | /* back one char again */ |
| 1265 | lcd_write_cmd(0x10); |
| 1266 | break; |
| 1267 | case '\014': |
| 1268 | /* quickly clear the display */ |
| 1269 | lcd_clear_fast(); |
| 1270 | break; |
| 1271 | case '\n': |
| 1272 | /* flush the remainder of the current line and |
| 1273 | go to the beginning of the next line */ |
| 1274 | for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++) |
| 1275 | lcd_write_data(' '); |
| 1276 | lcd_addr_x = 0; |
| 1277 | lcd_addr_y = (lcd_addr_y + 1) % lcd_height; |
| 1278 | lcd_gotoxy(); |
| 1279 | break; |
| 1280 | case '\r': |
| 1281 | /* go to the beginning of the same line */ |
| 1282 | lcd_addr_x = 0; |
| 1283 | lcd_gotoxy(); |
| 1284 | break; |
| 1285 | case '\t': |
| 1286 | /* print a space instead of the tab */ |
| 1287 | lcd_print(' '); |
| 1288 | break; |
| 1289 | default: |
| 1290 | /* simply print this char */ |
| 1291 | lcd_print(c); |
| 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /* now we'll see if we're in an escape mode and if the current |
| 1297 | escape sequence can be understood. */ |
| 1298 | if (lcd_escape_len >= 2) { |
| 1299 | int processed = 0; |
| 1300 | |
| 1301 | if (!strcmp(lcd_escape, "[2J")) { |
| 1302 | /* clear the display */ |
| 1303 | lcd_clear_fast(); |
| 1304 | processed = 1; |
| 1305 | } else if (!strcmp(lcd_escape, "[H")) { |
| 1306 | /* cursor to home */ |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 1307 | lcd_addr_x = 0; |
| 1308 | lcd_addr_y = 0; |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1309 | lcd_gotoxy(); |
| 1310 | processed = 1; |
| 1311 | } |
| 1312 | /* codes starting with ^[[L */ |
| 1313 | else if ((lcd_escape_len >= 3) && |
| 1314 | (lcd_escape[0] == '[') && |
| 1315 | (lcd_escape[1] == 'L')) { |
| 1316 | processed = handle_lcd_special_code(); |
| 1317 | } |
| 1318 | |
| 1319 | /* LCD special escape codes */ |
| 1320 | /* flush the escape sequence if it's been processed |
| 1321 | or if it is getting too long. */ |
| 1322 | if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN)) |
| 1323 | lcd_escape_len = -1; |
| 1324 | } /* escape codes */ |
| 1325 | } |
| 1326 | |
| 1327 | static ssize_t lcd_write(struct file *file, |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1328 | const char __user *buf, size_t count, loff_t *ppos) |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1329 | { |
| 1330 | const char __user *tmp = buf; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1331 | char c; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1332 | |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1333 | for (; count-- > 0; (*ppos)++, tmp++) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1334 | if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1335 | /* let's be a little nice with other processes |
| 1336 | that need some CPU */ |
| 1337 | schedule(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1338 | |
Bastien Armand | 6a4193a | 2014-04-23 19:42:11 +0200 | [diff] [blame] | 1339 | if (get_user(c, tmp)) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1340 | return -EFAULT; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1341 | |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1342 | lcd_write_char(c); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1343 | } |
| 1344 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1345 | return tmp - buf; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1348 | static int lcd_open(struct inode *inode, struct file *file) |
| 1349 | { |
| 1350 | if (lcd_open_cnt) |
| 1351 | return -EBUSY; /* open only once at a time */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1352 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1353 | if (file->f_mode & FMODE_READ) /* device is write-only */ |
| 1354 | return -EPERM; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1355 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1356 | if (lcd_must_clear) { |
| 1357 | lcd_clear_display(); |
| 1358 | lcd_must_clear = 0; |
| 1359 | } |
| 1360 | lcd_open_cnt++; |
Arnd Bergmann | 3ff8101 | 2010-07-07 23:40:09 +0200 | [diff] [blame] | 1361 | return nonseekable_open(inode, file); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1364 | static int lcd_release(struct inode *inode, struct file *file) |
| 1365 | { |
| 1366 | lcd_open_cnt--; |
| 1367 | return 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1370 | static const struct file_operations lcd_fops = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1371 | .write = lcd_write, |
| 1372 | .open = lcd_open, |
| 1373 | .release = lcd_release, |
Arnd Bergmann | 3ff8101 | 2010-07-07 23:40:09 +0200 | [diff] [blame] | 1374 | .llseek = no_llseek, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1375 | }; |
| 1376 | |
| 1377 | static struct miscdevice lcd_dev = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1378 | LCD_MINOR, |
| 1379 | "lcd", |
| 1380 | &lcd_fops |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1381 | }; |
| 1382 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1383 | /* public function usable from the kernel for any purpose */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1384 | static void panel_lcd_print(const char *s) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1385 | { |
Bastien Armand | 70a8c3e | 2014-04-18 18:10:57 +0200 | [diff] [blame] | 1386 | const char *tmp = s; |
| 1387 | int count = strlen(s); |
| 1388 | |
| 1389 | if (lcd_enabled && lcd_initialized) { |
| 1390 | for (; count-- > 0; tmp++) { |
| 1391 | if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) |
| 1392 | /* let's be a little nice with other processes |
| 1393 | that need some CPU */ |
| 1394 | schedule(); |
| 1395 | |
| 1396 | lcd_write_char(*tmp); |
| 1397 | } |
| 1398 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1401 | /* initialize the LCD driver */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1402 | static void lcd_init(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1403 | { |
| 1404 | switch (lcd_type) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1405 | case LCD_TYPE_OLD: |
| 1406 | /* parallel mode, 8 bits */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1407 | if (lcd_proto < 0) |
| 1408 | lcd_proto = LCD_PROTO_PARALLEL; |
| 1409 | if (lcd_charset < 0) |
| 1410 | lcd_charset = LCD_CHARSET_NORMAL; |
| 1411 | if (lcd_e_pin == PIN_NOT_SET) |
| 1412 | lcd_e_pin = PIN_STROBE; |
| 1413 | if (lcd_rs_pin == PIN_NOT_SET) |
| 1414 | lcd_rs_pin = PIN_AUTOLF; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1415 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1416 | if (lcd_width < 0) |
| 1417 | lcd_width = 40; |
| 1418 | if (lcd_bwidth < 0) |
| 1419 | lcd_bwidth = 40; |
| 1420 | if (lcd_hwidth < 0) |
| 1421 | lcd_hwidth = 64; |
| 1422 | if (lcd_height < 0) |
| 1423 | lcd_height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1424 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1425 | case LCD_TYPE_KS0074: |
| 1426 | /* serial mode, ks0074 */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1427 | if (lcd_proto < 0) |
| 1428 | lcd_proto = LCD_PROTO_SERIAL; |
| 1429 | if (lcd_charset < 0) |
| 1430 | lcd_charset = LCD_CHARSET_KS0074; |
| 1431 | if (lcd_bl_pin == PIN_NOT_SET) |
| 1432 | lcd_bl_pin = PIN_AUTOLF; |
| 1433 | if (lcd_cl_pin == PIN_NOT_SET) |
| 1434 | lcd_cl_pin = PIN_STROBE; |
| 1435 | if (lcd_da_pin == PIN_NOT_SET) |
| 1436 | lcd_da_pin = PIN_D0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1437 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1438 | if (lcd_width < 0) |
| 1439 | lcd_width = 16; |
| 1440 | if (lcd_bwidth < 0) |
| 1441 | lcd_bwidth = 40; |
| 1442 | if (lcd_hwidth < 0) |
| 1443 | lcd_hwidth = 16; |
| 1444 | if (lcd_height < 0) |
| 1445 | lcd_height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1446 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1447 | case LCD_TYPE_NEXCOM: |
| 1448 | /* parallel mode, 8 bits, generic */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1449 | if (lcd_proto < 0) |
| 1450 | lcd_proto = LCD_PROTO_PARALLEL; |
| 1451 | if (lcd_charset < 0) |
| 1452 | lcd_charset = LCD_CHARSET_NORMAL; |
| 1453 | if (lcd_e_pin == PIN_NOT_SET) |
| 1454 | lcd_e_pin = PIN_AUTOLF; |
| 1455 | if (lcd_rs_pin == PIN_NOT_SET) |
| 1456 | lcd_rs_pin = PIN_SELECP; |
| 1457 | if (lcd_rw_pin == PIN_NOT_SET) |
| 1458 | lcd_rw_pin = PIN_INITP; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1459 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1460 | if (lcd_width < 0) |
| 1461 | lcd_width = 16; |
| 1462 | if (lcd_bwidth < 0) |
| 1463 | lcd_bwidth = 40; |
| 1464 | if (lcd_hwidth < 0) |
| 1465 | lcd_hwidth = 64; |
| 1466 | if (lcd_height < 0) |
| 1467 | lcd_height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1468 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1469 | case LCD_TYPE_CUSTOM: |
| 1470 | /* customer-defined */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1471 | if (lcd_proto < 0) |
| 1472 | lcd_proto = DEFAULT_LCD_PROTO; |
| 1473 | if (lcd_charset < 0) |
| 1474 | lcd_charset = DEFAULT_LCD_CHARSET; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1475 | /* default geometry will be set later */ |
| 1476 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1477 | case LCD_TYPE_HANTRONIX: |
| 1478 | /* parallel mode, 8 bits, hantronix-like */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1479 | default: |
| 1480 | if (lcd_proto < 0) |
| 1481 | lcd_proto = LCD_PROTO_PARALLEL; |
| 1482 | if (lcd_charset < 0) |
| 1483 | lcd_charset = LCD_CHARSET_NORMAL; |
| 1484 | if (lcd_e_pin == PIN_NOT_SET) |
| 1485 | lcd_e_pin = PIN_STROBE; |
| 1486 | if (lcd_rs_pin == PIN_NOT_SET) |
| 1487 | lcd_rs_pin = PIN_SELECP; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1488 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1489 | if (lcd_width < 0) |
| 1490 | lcd_width = 16; |
| 1491 | if (lcd_bwidth < 0) |
| 1492 | lcd_bwidth = 40; |
| 1493 | if (lcd_hwidth < 0) |
| 1494 | lcd_hwidth = 64; |
| 1495 | if (lcd_height < 0) |
| 1496 | lcd_height = 2; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1497 | break; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1498 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1499 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1500 | /* this is used to catch wrong and default values */ |
| 1501 | if (lcd_width <= 0) |
| 1502 | lcd_width = DEFAULT_LCD_WIDTH; |
| 1503 | if (lcd_bwidth <= 0) |
| 1504 | lcd_bwidth = DEFAULT_LCD_BWIDTH; |
| 1505 | if (lcd_hwidth <= 0) |
| 1506 | lcd_hwidth = DEFAULT_LCD_HWIDTH; |
| 1507 | if (lcd_height <= 0) |
| 1508 | lcd_height = DEFAULT_LCD_HEIGHT; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1509 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1510 | if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */ |
| 1511 | lcd_write_cmd = lcd_write_cmd_s; |
| 1512 | lcd_write_data = lcd_write_data_s; |
| 1513 | lcd_clear_fast = lcd_clear_fast_s; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1514 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1515 | if (lcd_cl_pin == PIN_NOT_SET) |
| 1516 | lcd_cl_pin = DEFAULT_LCD_PIN_SCL; |
| 1517 | if (lcd_da_pin == PIN_NOT_SET) |
| 1518 | lcd_da_pin = DEFAULT_LCD_PIN_SDA; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1519 | |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 1520 | } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1521 | lcd_write_cmd = lcd_write_cmd_p8; |
| 1522 | lcd_write_data = lcd_write_data_p8; |
| 1523 | lcd_clear_fast = lcd_clear_fast_p8; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1524 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1525 | if (lcd_e_pin == PIN_NOT_SET) |
| 1526 | lcd_e_pin = DEFAULT_LCD_PIN_E; |
| 1527 | if (lcd_rs_pin == PIN_NOT_SET) |
| 1528 | lcd_rs_pin = DEFAULT_LCD_PIN_RS; |
| 1529 | if (lcd_rw_pin == PIN_NOT_SET) |
| 1530 | lcd_rw_pin = DEFAULT_LCD_PIN_RW; |
Sudhakar Rajashekhara | 77943d3 | 2009-08-20 18:13:18 -0400 | [diff] [blame] | 1531 | } else { |
| 1532 | lcd_write_cmd = lcd_write_cmd_tilcd; |
| 1533 | lcd_write_data = lcd_write_data_tilcd; |
| 1534 | lcd_clear_fast = lcd_clear_fast_tilcd; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | if (lcd_bl_pin == PIN_NOT_SET) |
| 1538 | lcd_bl_pin = DEFAULT_LCD_PIN_BL; |
| 1539 | |
| 1540 | if (lcd_e_pin == PIN_NOT_SET) |
| 1541 | lcd_e_pin = PIN_NONE; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1542 | if (lcd_rs_pin == PIN_NOT_SET) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1543 | lcd_rs_pin = PIN_NONE; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1544 | if (lcd_rw_pin == PIN_NOT_SET) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1545 | lcd_rw_pin = PIN_NONE; |
| 1546 | if (lcd_bl_pin == PIN_NOT_SET) |
| 1547 | lcd_bl_pin = PIN_NONE; |
| 1548 | if (lcd_cl_pin == PIN_NOT_SET) |
| 1549 | lcd_cl_pin = PIN_NONE; |
| 1550 | if (lcd_da_pin == PIN_NOT_SET) |
| 1551 | lcd_da_pin = PIN_NONE; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1552 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1553 | if (lcd_charset < 0) |
| 1554 | lcd_charset = DEFAULT_LCD_CHARSET; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1555 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1556 | if (lcd_charset == LCD_CHARSET_KS0074) |
| 1557 | lcd_char_conv = lcd_char_conv_ks0074; |
| 1558 | else |
| 1559 | lcd_char_conv = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1560 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1561 | if (lcd_bl_pin != PIN_NONE) |
| 1562 | init_scan_timer(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1563 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1564 | pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E], |
| 1565 | lcd_bits[LCD_PORT_C][LCD_BIT_E]); |
| 1566 | pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS], |
| 1567 | lcd_bits[LCD_PORT_C][LCD_BIT_RS]); |
| 1568 | pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW], |
| 1569 | lcd_bits[LCD_PORT_C][LCD_BIT_RW]); |
| 1570 | pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL], |
| 1571 | lcd_bits[LCD_PORT_C][LCD_BIT_BL]); |
| 1572 | pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL], |
| 1573 | lcd_bits[LCD_PORT_C][LCD_BIT_CL]); |
| 1574 | pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA], |
| 1575 | lcd_bits[LCD_PORT_C][LCD_BIT_DA]); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1576 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1577 | /* before this line, we must NOT send anything to the display. |
| 1578 | * Since lcd_init_display() needs to write data, we have to |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1579 | * enable mark the LCD initialized just before. */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1580 | lcd_initialized = 1; |
| 1581 | lcd_init_display(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1582 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1583 | /* display a short message */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1584 | #ifdef CONFIG_PANEL_CHANGE_MESSAGE |
| 1585 | #ifdef CONFIG_PANEL_BOOT_MESSAGE |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1586 | panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1587 | #endif |
| 1588 | #else |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1589 | panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-" |
| 1590 | PANEL_VERSION); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1591 | #endif |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 1592 | lcd_addr_x = 0; |
| 1593 | lcd_addr_y = 0; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1594 | /* clear the display on the next device opening */ |
| 1595 | lcd_must_clear = 1; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1596 | lcd_gotoxy(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1599 | /* |
| 1600 | * These are the file operation function for user access to /dev/keypad |
| 1601 | */ |
| 1602 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1603 | static ssize_t keypad_read(struct file *file, |
Bastien Armand | cce75f4 | 2014-04-18 18:10:08 +0200 | [diff] [blame] | 1604 | char __user *buf, size_t count, loff_t *ppos) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1605 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1606 | unsigned i = *ppos; |
Bastien Armand | cce75f4 | 2014-04-18 18:10:08 +0200 | [diff] [blame] | 1607 | char __user *tmp = buf; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1608 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1609 | if (keypad_buflen == 0) { |
| 1610 | if (file->f_flags & O_NONBLOCK) |
| 1611 | return -EAGAIN; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1612 | |
Arnd Bergmann | 310df69 | 2014-01-02 13:07:35 +0100 | [diff] [blame] | 1613 | if (wait_event_interruptible(keypad_read_wait, |
| 1614 | keypad_buflen != 0)) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1615 | return -EINTR; |
| 1616 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1617 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1618 | for (; count-- > 0 && (keypad_buflen > 0); |
| 1619 | ++i, ++tmp, --keypad_buflen) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1620 | put_user(keypad_buffer[keypad_start], tmp); |
| 1621 | keypad_start = (keypad_start + 1) % KEYPAD_BUFFER; |
| 1622 | } |
| 1623 | *ppos = i; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1624 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1625 | return tmp - buf; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1628 | static int keypad_open(struct inode *inode, struct file *file) |
| 1629 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1630 | if (keypad_open_cnt) |
| 1631 | return -EBUSY; /* open only once at a time */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1632 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1633 | if (file->f_mode & FMODE_WRITE) /* device is read-only */ |
| 1634 | return -EPERM; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1635 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1636 | keypad_buflen = 0; /* flush the buffer on opening */ |
| 1637 | keypad_open_cnt++; |
| 1638 | return 0; |
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 int keypad_release(struct inode *inode, struct file *file) |
| 1642 | { |
| 1643 | keypad_open_cnt--; |
| 1644 | return 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1647 | static const struct file_operations keypad_fops = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1648 | .read = keypad_read, /* read */ |
| 1649 | .open = keypad_open, /* open */ |
| 1650 | .release = keypad_release, /* close */ |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1651 | .llseek = default_llseek, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1652 | }; |
| 1653 | |
| 1654 | static struct miscdevice keypad_dev = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1655 | KEYPAD_MINOR, |
| 1656 | "keypad", |
| 1657 | &keypad_fops |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1658 | }; |
| 1659 | |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1660 | static void keypad_send_key(const char *string, int max_len) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1661 | { |
| 1662 | if (init_in_progress) |
| 1663 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1664 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1665 | /* send the key to the device only if a process is attached to it. */ |
| 1666 | if (keypad_open_cnt > 0) { |
| 1667 | while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) { |
| 1668 | keypad_buffer[(keypad_start + keypad_buflen++) % |
| 1669 | KEYPAD_BUFFER] = *string++; |
| 1670 | } |
| 1671 | wake_up_interruptible(&keypad_read_wait); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1672 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1675 | /* this function scans all the bits involving at least one logical signal, |
| 1676 | * and puts the results in the bitfield "phys_read" (one bit per established |
| 1677 | * contact), and sets "phys_read_prev" to "phys_read". |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1678 | * |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1679 | * Note: to debounce input signals, we will only consider as switched a signal |
| 1680 | * which is stable across 2 measures. Signals which are different between two |
| 1681 | * reads will be kept as they previously were in their logical form (phys_prev). |
| 1682 | * A signal which has just switched will have a 1 in |
| 1683 | * (phys_read ^ phys_read_prev). |
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 | static void phys_scan_contacts(void) |
| 1686 | { |
| 1687 | int bit, bitval; |
| 1688 | char oldval; |
| 1689 | char bitmask; |
| 1690 | char gndmask; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1691 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1692 | phys_prev = phys_curr; |
| 1693 | phys_read_prev = phys_read; |
| 1694 | phys_read = 0; /* flush all signals */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1695 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1696 | /* keep track of old value, with all outputs disabled */ |
| 1697 | oldval = r_dtr(pprt) | scan_mask_o; |
| 1698 | /* activate all keyboard outputs (active low) */ |
| 1699 | w_dtr(pprt, oldval & ~scan_mask_o); |
| 1700 | |
| 1701 | /* will have a 1 for each bit set to gnd */ |
| 1702 | bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; |
| 1703 | /* disable all matrix signals */ |
| 1704 | w_dtr(pprt, oldval); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1705 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1706 | /* now that all outputs are cleared, the only active input bits are |
| 1707 | * directly connected to the ground |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1708 | */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1709 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1710 | /* 1 for each grounded input */ |
| 1711 | gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i; |
| 1712 | |
| 1713 | /* grounded inputs are signals 40-44 */ |
| 1714 | phys_read |= (pmask_t) gndmask << 40; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1715 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1716 | if (bitmask != gndmask) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1717 | /* since clearing the outputs changed some inputs, we know |
| 1718 | * that some input signals are currently tied to some outputs. |
| 1719 | * So we'll scan them. |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1720 | */ |
| 1721 | for (bit = 0; bit < 8; bit++) { |
| 1722 | bitval = 1 << bit; |
| 1723 | |
| 1724 | if (!(scan_mask_o & bitval)) /* skip unused bits */ |
| 1725 | continue; |
| 1726 | |
| 1727 | w_dtr(pprt, oldval & ~bitval); /* enable this output */ |
| 1728 | bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask; |
| 1729 | phys_read |= (pmask_t) bitmask << (5 * bit); |
| 1730 | } |
| 1731 | w_dtr(pprt, oldval); /* disable all outputs */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1732 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1733 | /* this is easy: use old bits when they are flapping, |
| 1734 | * use new ones when stable */ |
| 1735 | phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) | |
| 1736 | (phys_read & ~(phys_read ^ phys_read_prev)); |
| 1737 | } |
| 1738 | |
| 1739 | static inline int input_state_high(struct logical_input *input) |
| 1740 | { |
| 1741 | #if 0 |
| 1742 | /* FIXME: |
| 1743 | * this is an invalid test. It tries to catch |
| 1744 | * transitions from single-key to multiple-key, but |
| 1745 | * doesn't take into account the contacts polarity. |
| 1746 | * The only solution to the problem is to parse keys |
| 1747 | * from the most complex to the simplest combinations, |
| 1748 | * and mark them as 'caught' once a combination |
| 1749 | * matches, then unmatch it for all other ones. |
| 1750 | */ |
| 1751 | |
| 1752 | /* try to catch dangerous transitions cases : |
| 1753 | * someone adds a bit, so this signal was a false |
| 1754 | * positive resulting from a transition. We should |
| 1755 | * invalidate the signal immediately and not call the |
| 1756 | * release function. |
| 1757 | * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release. |
| 1758 | */ |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1759 | if (((phys_prev & input->mask) == input->value) && |
| 1760 | ((phys_curr & input->mask) > input->value)) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1761 | input->state = INPUT_ST_LOW; /* invalidate */ |
| 1762 | return 1; |
| 1763 | } |
| 1764 | #endif |
| 1765 | |
| 1766 | if ((phys_curr & input->mask) == input->value) { |
| 1767 | if ((input->type == INPUT_TYPE_STD) && |
| 1768 | (input->high_timer == 0)) { |
| 1769 | input->high_timer++; |
| 1770 | if (input->u.std.press_fct != NULL) |
| 1771 | input->u.std.press_fct(input->u.std.press_data); |
| 1772 | } else if (input->type == INPUT_TYPE_KBD) { |
| 1773 | /* will turn on the light */ |
| 1774 | keypressed = 1; |
| 1775 | |
| 1776 | if (input->high_timer == 0) { |
| 1777 | char *press_str = input->u.kbd.press_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1778 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1779 | if (press_str[0]) { |
| 1780 | int s = sizeof(input->u.kbd.press_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1781 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1782 | keypad_send_key(press_str, s); |
| 1783 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | if (input->u.kbd.repeat_str[0]) { |
| 1787 | char *repeat_str = input->u.kbd.repeat_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1788 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1789 | if (input->high_timer >= KEYPAD_REP_START) { |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1790 | int s = sizeof(input->u.kbd.repeat_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1791 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1792 | input->high_timer -= KEYPAD_REP_DELAY; |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1793 | keypad_send_key(repeat_str, s); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1794 | } |
| 1795 | /* we will need to come back here soon */ |
| 1796 | inputs_stable = 0; |
| 1797 | } |
| 1798 | |
| 1799 | if (input->high_timer < 255) |
| 1800 | input->high_timer++; |
| 1801 | } |
| 1802 | return 1; |
| 1803 | } else { |
| 1804 | /* else signal falling down. Let's fall through. */ |
| 1805 | input->state = INPUT_ST_FALLING; |
| 1806 | input->fall_timer = 0; |
| 1807 | } |
| 1808 | return 0; |
| 1809 | } |
| 1810 | |
| 1811 | static inline void input_state_falling(struct logical_input *input) |
| 1812 | { |
| 1813 | #if 0 |
| 1814 | /* FIXME !!! same comment as in input_state_high */ |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1815 | if (((phys_prev & input->mask) == input->value) && |
| 1816 | ((phys_curr & input->mask) > input->value)) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1817 | input->state = INPUT_ST_LOW; /* invalidate */ |
| 1818 | return; |
| 1819 | } |
| 1820 | #endif |
| 1821 | |
| 1822 | if ((phys_curr & input->mask) == input->value) { |
| 1823 | if (input->type == INPUT_TYPE_KBD) { |
| 1824 | /* will turn on the light */ |
| 1825 | keypressed = 1; |
| 1826 | |
| 1827 | if (input->u.kbd.repeat_str[0]) { |
| 1828 | char *repeat_str = input->u.kbd.repeat_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1829 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1830 | if (input->high_timer >= KEYPAD_REP_START) { |
| 1831 | int s = sizeof(input->u.kbd.repeat_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1832 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1833 | input->high_timer -= KEYPAD_REP_DELAY; |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1834 | keypad_send_key(repeat_str, s); |
| 1835 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1836 | /* we will need to come back here soon */ |
| 1837 | inputs_stable = 0; |
| 1838 | } |
| 1839 | |
| 1840 | if (input->high_timer < 255) |
| 1841 | input->high_timer++; |
| 1842 | } |
| 1843 | input->state = INPUT_ST_HIGH; |
| 1844 | } else if (input->fall_timer >= input->fall_time) { |
| 1845 | /* call release event */ |
| 1846 | if (input->type == INPUT_TYPE_STD) { |
| 1847 | void (*release_fct)(int) = input->u.std.release_fct; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1848 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1849 | if (release_fct != NULL) |
| 1850 | release_fct(input->u.std.release_data); |
| 1851 | } else if (input->type == INPUT_TYPE_KBD) { |
| 1852 | char *release_str = input->u.kbd.release_str; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1853 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1854 | if (release_str[0]) { |
| 1855 | int s = sizeof(input->u.kbd.release_str); |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1856 | |
Jake Champlin | e6626de | 2013-05-04 11:21:17 -0400 | [diff] [blame] | 1857 | keypad_send_key(release_str, s); |
| 1858 | } |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | input->state = INPUT_ST_LOW; |
| 1862 | } else { |
| 1863 | input->fall_timer++; |
| 1864 | inputs_stable = 0; |
| 1865 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1868 | static void panel_process_inputs(void) |
| 1869 | { |
| 1870 | struct list_head *item; |
| 1871 | struct logical_input *input; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1872 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1873 | keypressed = 0; |
| 1874 | inputs_stable = 1; |
| 1875 | list_for_each(item, &logical_inputs) { |
| 1876 | input = list_entry(item, struct logical_input, list); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1877 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1878 | switch (input->state) { |
| 1879 | case INPUT_ST_LOW: |
| 1880 | if ((phys_curr & input->mask) != input->value) |
| 1881 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1882 | /* if all needed ones were already set previously, |
| 1883 | * this means that this logical signal has been |
| 1884 | * activated by the releasing of another combined |
| 1885 | * signal, so we don't want to match. |
| 1886 | * eg: AB -(release B)-> A -(release A)-> 0 : |
| 1887 | * don't match A. |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1888 | */ |
| 1889 | if ((phys_prev & input->mask) == input->value) |
| 1890 | break; |
| 1891 | input->rise_timer = 0; |
| 1892 | input->state = INPUT_ST_RISING; |
| 1893 | /* no break here, fall through */ |
| 1894 | case INPUT_ST_RISING: |
| 1895 | if ((phys_curr & input->mask) != input->value) { |
| 1896 | input->state = INPUT_ST_LOW; |
| 1897 | break; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1898 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1899 | if (input->rise_timer < input->rise_time) { |
| 1900 | inputs_stable = 0; |
| 1901 | input->rise_timer++; |
| 1902 | break; |
| 1903 | } |
| 1904 | input->high_timer = 0; |
| 1905 | input->state = INPUT_ST_HIGH; |
| 1906 | /* no break here, fall through */ |
| 1907 | case INPUT_ST_HIGH: |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1908 | if (input_state_high(input)) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1909 | break; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1910 | /* no break here, fall through */ |
| 1911 | case INPUT_ST_FALLING: |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1912 | input_state_falling(input); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1913 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1914 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1915 | } |
| 1916 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1917 | static void panel_scan_timer(void) |
| 1918 | { |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 1919 | if (keypad_enabled && keypad_initialized) { |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 1920 | if (spin_trylock_irq(&pprt_lock)) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1921 | phys_scan_contacts(); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 1922 | |
| 1923 | /* no need for the parport anymore */ |
Fengguang Wu | d4d2dbc | 2012-09-09 16:23:46 +0800 | [diff] [blame] | 1924 | spin_unlock_irq(&pprt_lock); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1925 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1926 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1927 | if (!inputs_stable || phys_curr != phys_prev) |
| 1928 | panel_process_inputs(); |
| 1929 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1930 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1931 | if (lcd_enabled && lcd_initialized) { |
| 1932 | if (keypressed) { |
| 1933 | if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) |
| 1934 | lcd_backlight(1); |
| 1935 | light_tempo = FLASH_LIGHT_TEMPO; |
| 1936 | } else if (light_tempo > 0) { |
| 1937 | light_tempo--; |
| 1938 | if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) |
| 1939 | lcd_backlight(0); |
| 1940 | } |
| 1941 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1942 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1943 | mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1944 | } |
| 1945 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1946 | static void init_scan_timer(void) |
| 1947 | { |
| 1948 | if (scan_timer.function != NULL) |
| 1949 | return; /* already started */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1950 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1951 | init_timer(&scan_timer); |
| 1952 | scan_timer.expires = jiffies + INPUT_POLL_TIME; |
| 1953 | scan_timer.data = 0; |
| 1954 | scan_timer.function = (void *)&panel_scan_timer; |
| 1955 | add_timer(&scan_timer); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* 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] | 1959 | * if <omask> or <imask> are non-null, they will be or'ed with the bits |
| 1960 | * corresponding to out and in bits respectively. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1961 | * returns 1 if ok, 0 if error (in which case, nothing is written). |
| 1962 | */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 1963 | static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value, |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1964 | char *imask, char *omask) |
| 1965 | { |
| 1966 | static char sigtab[10] = "EeSsPpAaBb"; |
| 1967 | char im, om; |
| 1968 | pmask_t m, v; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1969 | |
Dominique van den Broeck | 2d53426 | 2014-05-24 01:35:24 +0200 | [diff] [blame^] | 1970 | om = 0ULL; |
| 1971 | im = 0ULL; |
| 1972 | m = 0ULL; |
| 1973 | v = 0ULL; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1974 | while (*name) { |
| 1975 | int in, out, bit, neg; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 1976 | |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1977 | for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name); |
| 1978 | in++) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1979 | ; |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 1980 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1981 | if (in >= sizeof(sigtab)) |
| 1982 | return 0; /* input name not found */ |
| 1983 | neg = (in & 1); /* odd (lower) names are negated */ |
| 1984 | in >>= 1; |
| 1985 | im |= (1 << in); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 1986 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1987 | name++; |
| 1988 | if (isdigit(*name)) { |
| 1989 | out = *name - '0'; |
| 1990 | om |= (1 << out); |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1991 | } else if (*name == '-') { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1992 | out = 8; |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1993 | } else { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1994 | return 0; /* unknown bit name */ |
Dominique van den Broeck | 3ac7690 | 2014-05-21 14:09:59 +0200 | [diff] [blame] | 1995 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 1996 | |
| 1997 | bit = (out * 5) + in; |
| 1998 | |
| 1999 | m |= 1ULL << bit; |
| 2000 | if (!neg) |
| 2001 | v |= 1ULL << bit; |
| 2002 | name++; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2003 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2004 | *mask = m; |
| 2005 | *value = v; |
| 2006 | if (imask) |
| 2007 | *imask |= im; |
| 2008 | if (omask) |
| 2009 | *omask |= om; |
| 2010 | return 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /* tries to bind a key to the signal name <name>. The key will send the |
| 2014 | * strings <press>, <repeat>, <release> for these respective events. |
| 2015 | * Returns the pointer to the new key if ok, NULL if the key could not be bound. |
| 2016 | */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 2017 | static struct logical_input *panel_bind_key(const char *name, const char *press, |
| 2018 | const char *repeat, |
| 2019 | const char *release) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2020 | { |
| 2021 | struct logical_input *key; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2022 | |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 2023 | key = kzalloc(sizeof(*key), GFP_KERNEL); |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2024 | if (!key) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2025 | return NULL; |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2026 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2027 | if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i, |
Kulikov Vasiliy | cb46f47 | 2010-07-12 18:48:24 +0400 | [diff] [blame] | 2028 | &scan_mask_o)) { |
| 2029 | kfree(key); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2030 | return NULL; |
Kulikov Vasiliy | cb46f47 | 2010-07-12 18:48:24 +0400 | [diff] [blame] | 2031 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2032 | |
| 2033 | key->type = INPUT_TYPE_KBD; |
| 2034 | key->state = INPUT_ST_LOW; |
| 2035 | key->rise_time = 1; |
| 2036 | key->fall_time = 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2037 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2038 | strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str)); |
| 2039 | strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str)); |
| 2040 | strncpy(key->u.kbd.release_str, release, |
| 2041 | sizeof(key->u.kbd.release_str)); |
| 2042 | list_add(&key->list, &logical_inputs); |
| 2043 | return key; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 2046 | #if 0 |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2047 | /* tries to bind a callback function to the signal name <name>. The function |
| 2048 | * <press_fct> will be called with the <press_data> arg when the signal is |
| 2049 | * activated, and so on for <release_fct>/<release_data> |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2050 | * Returns the pointer to the new signal if ok, NULL if the signal could not |
| 2051 | * be bound. |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2052 | */ |
| 2053 | static struct logical_input *panel_bind_callback(char *name, |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 2054 | void (*press_fct)(int), |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2055 | int press_data, |
Monam Agarwal | 68d386b | 2014-02-25 19:40:49 +0530 | [diff] [blame] | 2056 | void (*release_fct)(int), |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2057 | int release_data) |
| 2058 | { |
| 2059 | struct logical_input *callback; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2060 | |
Dominique van den Broeck | fdf4a494 | 2014-05-21 14:10:00 +0200 | [diff] [blame] | 2061 | callback = kmalloc(sizeof(*callback), GFP_KERNEL); |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2062 | if (!callback) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2063 | return NULL; |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2064 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2065 | memset(callback, 0, sizeof(struct logical_input)); |
| 2066 | if (!input_name2mask(name, &callback->mask, &callback->value, |
| 2067 | &scan_mask_i, &scan_mask_o)) |
| 2068 | return NULL; |
| 2069 | |
| 2070 | callback->type = INPUT_TYPE_STD; |
| 2071 | callback->state = INPUT_ST_LOW; |
| 2072 | callback->rise_time = 1; |
| 2073 | callback->fall_time = 1; |
| 2074 | callback->u.std.press_fct = press_fct; |
| 2075 | callback->u.std.press_data = press_data; |
| 2076 | callback->u.std.release_fct = release_fct; |
| 2077 | callback->u.std.release_data = release_data; |
| 2078 | list_add(&callback->list, &logical_inputs); |
| 2079 | return callback; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2080 | } |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 2081 | #endif |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2082 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2083 | static void keypad_init(void) |
| 2084 | { |
| 2085 | int keynum; |
Bastien Armand | c3ed0af | 2014-04-04 21:45:07 +0200 | [diff] [blame] | 2086 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2087 | init_waitqueue_head(&keypad_read_wait); |
| 2088 | keypad_buflen = 0; /* flushes any eventual noisy keystroke */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2089 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2090 | /* Let's create all known keys */ |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2091 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2092 | for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) { |
| 2093 | panel_bind_key(keypad_profile[keynum][0], |
| 2094 | keypad_profile[keynum][1], |
| 2095 | keypad_profile[keynum][2], |
| 2096 | keypad_profile[keynum][3]); |
| 2097 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2098 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2099 | init_scan_timer(); |
| 2100 | keypad_initialized = 1; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2103 | /**************************************************/ |
| 2104 | /* device initialization */ |
| 2105 | /**************************************************/ |
| 2106 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2107 | static int panel_notify_sys(struct notifier_block *this, unsigned long code, |
| 2108 | void *unused) |
| 2109 | { |
| 2110 | if (lcd_enabled && lcd_initialized) { |
| 2111 | switch (code) { |
| 2112 | case SYS_DOWN: |
| 2113 | panel_lcd_print |
| 2114 | ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+"); |
| 2115 | break; |
| 2116 | case SYS_HALT: |
| 2117 | panel_lcd_print |
| 2118 | ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 2119 | break; |
| 2120 | case SYS_POWER_OFF: |
| 2121 | panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); |
| 2122 | break; |
| 2123 | default: |
| 2124 | break; |
| 2125 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2126 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2127 | return NOTIFY_DONE; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | static struct notifier_block panel_notifier = { |
| 2131 | panel_notify_sys, |
| 2132 | NULL, |
| 2133 | 0 |
| 2134 | }; |
| 2135 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2136 | static void panel_attach(struct parport *port) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2137 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2138 | if (port->number != parport) |
| 2139 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2140 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2141 | if (pprt) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2142 | pr_err("%s: port->number=%d parport=%d, already registered!\n", |
| 2143 | __func__, port->number, parport); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2144 | return; |
| 2145 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2146 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2147 | pprt = parport_register_device(port, "panel", NULL, NULL, /* pf, kf */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2148 | NULL, |
| 2149 | /*PARPORT_DEV_EXCL */ |
| 2150 | 0, (void *)&pprt); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2151 | if (pprt == NULL) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2152 | pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n", |
| 2153 | __func__, port->number, parport); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2154 | return; |
| 2155 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2156 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2157 | if (parport_claim(pprt)) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2158 | pr_err("could not claim access to parport%d. Aborting.\n", |
| 2159 | parport); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2160 | goto err_unreg_device; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2161 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2162 | |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2163 | /* must init LCD first, just in case an IRQ from the keypad is |
| 2164 | * generated at keypad init |
| 2165 | */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2166 | if (lcd_enabled) { |
| 2167 | lcd_init(); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2168 | if (misc_register(&lcd_dev)) |
| 2169 | goto err_unreg_device; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2170 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2171 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2172 | if (keypad_enabled) { |
| 2173 | keypad_init(); |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2174 | if (misc_register(&keypad_dev)) |
| 2175 | goto err_lcd_unreg; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2176 | } |
Kulikov Vasiliy | 10f3f5b | 2010-07-30 15:08:20 +0400 | [diff] [blame] | 2177 | return; |
| 2178 | |
| 2179 | err_lcd_unreg: |
| 2180 | if (lcd_enabled) |
| 2181 | misc_deregister(&lcd_dev); |
| 2182 | err_unreg_device: |
| 2183 | parport_unregister_device(pprt); |
| 2184 | pprt = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2187 | static void panel_detach(struct parport *port) |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2188 | { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2189 | if (port->number != parport) |
| 2190 | return; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2191 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2192 | if (!pprt) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2193 | pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n", |
| 2194 | __func__, port->number, parport); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2195 | return; |
| 2196 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2197 | |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2198 | if (keypad_enabled && keypad_initialized) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2199 | misc_deregister(&keypad_dev); |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2200 | keypad_initialized = 0; |
| 2201 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2202 | |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2203 | if (lcd_enabled && lcd_initialized) { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2204 | misc_deregister(&lcd_dev); |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2205 | lcd_initialized = 0; |
| 2206 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2207 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2208 | parport_release(pprt); |
| 2209 | parport_unregister_device(pprt); |
| 2210 | pprt = NULL; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | static struct parport_driver panel_driver = { |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2214 | .name = "panel", |
| 2215 | .attach = panel_attach, |
| 2216 | .detach = panel_detach, |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2217 | }; |
| 2218 | |
| 2219 | /* init function */ |
Peter Huewe | 36d2041 | 2013-02-15 13:47:05 +0100 | [diff] [blame] | 2220 | static int panel_init(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2221 | { |
| 2222 | /* for backwards compatibility */ |
| 2223 | if (keypad_type < 0) |
| 2224 | keypad_type = keypad_enabled; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2225 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2226 | if (lcd_type < 0) |
| 2227 | lcd_type = lcd_enabled; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2228 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2229 | if (parport < 0) |
| 2230 | parport = DEFAULT_PARPORT; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2231 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2232 | /* take care of an eventual profile */ |
| 2233 | switch (profile) { |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2234 | case PANEL_PROFILE_CUSTOM: |
| 2235 | /* custom profile */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2236 | if (keypad_type < 0) |
| 2237 | keypad_type = DEFAULT_KEYPAD; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2238 | if (lcd_type < 0) |
| 2239 | lcd_type = DEFAULT_LCD; |
| 2240 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2241 | case PANEL_PROFILE_OLD: |
| 2242 | /* 8 bits, 2*16, old keypad */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2243 | if (keypad_type < 0) |
| 2244 | keypad_type = KEYPAD_TYPE_OLD; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2245 | if (lcd_type < 0) |
| 2246 | lcd_type = LCD_TYPE_OLD; |
| 2247 | if (lcd_width < 0) |
| 2248 | lcd_width = 16; |
| 2249 | if (lcd_hwidth < 0) |
| 2250 | lcd_hwidth = 16; |
| 2251 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2252 | case PANEL_PROFILE_NEW: |
| 2253 | /* serial, 2*16, new keypad */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2254 | if (keypad_type < 0) |
| 2255 | keypad_type = KEYPAD_TYPE_NEW; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2256 | if (lcd_type < 0) |
| 2257 | lcd_type = LCD_TYPE_KS0074; |
| 2258 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2259 | case PANEL_PROFILE_HANTRONIX: |
| 2260 | /* 8 bits, 2*16 hantronix-like, no keypad */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2261 | if (keypad_type < 0) |
| 2262 | keypad_type = KEYPAD_TYPE_NONE; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2263 | if (lcd_type < 0) |
| 2264 | lcd_type = LCD_TYPE_HANTRONIX; |
| 2265 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2266 | case PANEL_PROFILE_NEXCOM: |
| 2267 | /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2268 | if (keypad_type < 0) |
| 2269 | keypad_type = KEYPAD_TYPE_NEXCOM; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2270 | if (lcd_type < 0) |
| 2271 | lcd_type = LCD_TYPE_NEXCOM; |
| 2272 | break; |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2273 | case PANEL_PROFILE_LARGE: |
| 2274 | /* 8 bits, 2*40, old keypad */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2275 | if (keypad_type < 0) |
| 2276 | keypad_type = KEYPAD_TYPE_OLD; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2277 | if (lcd_type < 0) |
| 2278 | lcd_type = LCD_TYPE_OLD; |
| 2279 | break; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2280 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2281 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2282 | lcd_enabled = (lcd_type > 0); |
| 2283 | keypad_enabled = (keypad_type > 0); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2284 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2285 | switch (keypad_type) { |
| 2286 | case KEYPAD_TYPE_OLD: |
| 2287 | keypad_profile = old_keypad_profile; |
| 2288 | break; |
| 2289 | case KEYPAD_TYPE_NEW: |
| 2290 | keypad_profile = new_keypad_profile; |
| 2291 | break; |
| 2292 | case KEYPAD_TYPE_NEXCOM: |
| 2293 | keypad_profile = nexcom_keypad_profile; |
| 2294 | break; |
| 2295 | default: |
| 2296 | keypad_profile = NULL; |
| 2297 | break; |
| 2298 | } |
| 2299 | |
| 2300 | /* tells various subsystems about the fact that we are initializing */ |
| 2301 | init_in_progress = 1; |
| 2302 | |
| 2303 | if (parport_register_driver(&panel_driver)) { |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2304 | pr_err("could not register with parport. Aborting.\n"); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2305 | return -EIO; |
| 2306 | } |
| 2307 | |
Willy Tarreau | 63023177 | 2008-11-22 12:52:18 +0100 | [diff] [blame] | 2308 | if (!lcd_enabled && !keypad_enabled) { |
| 2309 | /* no device enabled, let's release the parport */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2310 | if (pprt) { |
| 2311 | parport_release(pprt); |
| 2312 | parport_unregister_device(pprt); |
Peter Huewe | 060132a | 2010-07-07 04:52:16 +0200 | [diff] [blame] | 2313 | pprt = NULL; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2314 | } |
| 2315 | parport_unregister_driver(&panel_driver); |
Toshiaki Yamane | eb073a9 | 2012-07-12 22:01:17 +0900 | [diff] [blame] | 2316 | pr_err("driver version " PANEL_VERSION " disabled.\n"); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2317 | return -ENODEV; |
| 2318 | } |
| 2319 | |
| 2320 | register_reboot_notifier(&panel_notifier); |
| 2321 | |
| 2322 | if (pprt) |
Toshiaki Yamane | 493aa89 | 2012-07-12 22:01:00 +0900 | [diff] [blame] | 2323 | pr_info("driver version " PANEL_VERSION |
| 2324 | " registered on parport%d (io=0x%lx).\n", parport, |
| 2325 | pprt->port->base); |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2326 | else |
Toshiaki Yamane | 493aa89 | 2012-07-12 22:01:00 +0900 | [diff] [blame] | 2327 | pr_info("driver version " PANEL_VERSION |
| 2328 | " not yet registered\n"); |
Henri Häkkinen | 429ccf0 | 2010-06-12 00:27:36 +0300 | [diff] [blame] | 2329 | /* tells various subsystems about the fact that initialization |
| 2330 | is finished */ |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2331 | init_in_progress = 0; |
| 2332 | return 0; |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2333 | } |
| 2334 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 2335 | static int __init panel_init_module(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2336 | { |
| 2337 | return panel_init(); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
Willy Tarreau | f6d1fcf | 2008-11-22 12:04:19 +0100 | [diff] [blame] | 2340 | static void __exit panel_cleanup_module(void) |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2341 | { |
| 2342 | unregister_reboot_notifier(&panel_notifier); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2343 | |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2344 | if (scan_timer.function != NULL) |
Julia Lawall | e112f89 | 2014-03-26 22:33:41 +0100 | [diff] [blame] | 2345 | del_timer_sync(&scan_timer); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2346 | |
Costantino Leandro | 5789813 | 2009-02-17 11:10:48 -0500 | [diff] [blame] | 2347 | if (pprt != NULL) { |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2348 | if (keypad_enabled) { |
Costantino Leandro | 5789813 | 2009-02-17 11:10:48 -0500 | [diff] [blame] | 2349 | misc_deregister(&keypad_dev); |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2350 | keypad_initialized = 0; |
| 2351 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2352 | |
Costantino Leandro | 5789813 | 2009-02-17 11:10:48 -0500 | [diff] [blame] | 2353 | if (lcd_enabled) { |
| 2354 | panel_lcd_print("\x0cLCD driver " PANEL_VERSION |
| 2355 | "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-"); |
| 2356 | misc_deregister(&lcd_dev); |
Peter Huewe | 0b0595b | 2009-09-29 01:22:40 +0200 | [diff] [blame] | 2357 | lcd_initialized = 0; |
Costantino Leandro | 5789813 | 2009-02-17 11:10:48 -0500 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /* TODO: free all input signals */ |
| 2361 | parport_release(pprt); |
| 2362 | parport_unregister_device(pprt); |
Peter Huewe | 060132a | 2010-07-07 04:52:16 +0200 | [diff] [blame] | 2363 | pprt = NULL; |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2364 | } |
Willy Tarreau | 698b151 | 2008-11-22 11:29:33 +0100 | [diff] [blame] | 2365 | parport_unregister_driver(&panel_driver); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2366 | } |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2367 | |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2368 | module_init(panel_init_module); |
| 2369 | module_exit(panel_cleanup_module); |
| 2370 | MODULE_AUTHOR("Willy Tarreau"); |
| 2371 | MODULE_LICENSE("GPL"); |
Willy Tarreau | 7005b58 | 2008-11-13 17:18:59 -0800 | [diff] [blame] | 2372 | |
| 2373 | /* |
| 2374 | * Local variables: |
| 2375 | * c-indent-level: 4 |
| 2376 | * tab-width: 8 |
| 2377 | * End: |
| 2378 | */ |