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