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