Linux problems with USB HID keyboards and patches
Subsystems (2)
[Not subscribed to l-k, so please CC me]
Hi,
I've been experiencing some problems with a Logitech iTouch Internet Navigator USB connected keyboard (model Y-BF37). I solved some of them by patching the kernel, while others I don't know how to handle. Kernel is an ACPI enabled version of RH 2.4.20-19.9.
They problems are:
* Problem 1. Pressing Shift+Alt_R generates a fake Cltr_R key press event with no Ctrl_R key up event, so the Ctrl key gets stuck. Pressing the Ctrl_R key just after generates only a key release event and then everything gets back to normal. I added some printk messages to keybdev, hid-input and hid-core and this is what I got:
# ---> Press Right Shift
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe5, code 54hidinput_hid_event: key 54 (0x36), down = 1 hid_core.c:hid_input_field: count = 6hidinput_hid_event: key 54 (0x36), down = 2
# ---> Press Right Alt
# but Right Ctrl synthetized in HW or hid_input_field()
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe4, code 97 keybdev event key 97 (0x61), down = 1hidinput_hid_event: page 0x7, usage 0xe6, code 100 keybdev event key 100 (0x64), down = 1 hid_core.c:hid_input_field: count = 6
# ---> Release Right Alt
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe6, code 100 keybdev event key 100 (0x64), down = 0 hid_core.c:hid_input_field: count = 6
# ---> Release Right Shift hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe5, code 54hidinput_hid_event: key 54 (0x36), down = 0 hid_core.c:hid_input_field: count = 6
# ---> Press Right Shift
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe5, code 54 keybdev event key 54 (0x36), down = 1 hid_core.c:hid_input_field: count = 6
keybdev event key 54 (0x36), down = 2
# ---> Press Right Alt
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe6, code 100 keybdev event key 100 (0x64), down = 1 hid_core.c:hid_input_field: count = 6
# ---> Release Right Alt
hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe6, code 100 keybdev event key 100 (0x64), down = 0 hid_core.c:hid_input_field: count = 6
# ---> Release Right Shift hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe5, code 54 keybdev event key 54 (0x36), down = 0 hid_core.c:hid_input_field: count = 6
# ---> Press and Release Right Ctrl, but only release reported hid_core.c:hid_input_field: count = 8hidinput_hid_event: page 0x7, usage 0xe4, code 97 keybdev event key 97 (0x61), down = 0 hid_core.c:hid_input_field: count = 6
In the above count is the count variable in hid_input_field(), page and usage the page and usage parts of the usage->hid value in hidinput_hid_event() and code is the usage->code value in the same function. Finally key is the value of code in keybdev_event(), decimal and hex.
Any ideas what's going wrong? Is it a buggy keyboard? Or a problem in hid_input_field()? Or something else?
* Problem 2: The mapping of HID keys to event keys and from event keys to PS/2 scancodes are not very nice for "internet" keyboards. I reworked them to recognize many more HID keys and use the standard MS scancodes, supplemented by the MS Office keyboard mappings too. That is implemented by the patch linux-2.4.20-18.9.acpi.4-input.patch. These mappings could be worth having in 2.4 and also in 2.6 (2.6 has better mappings, but many are still non-standard).
* Problem 3: My keyboard (and I guess some others too) report some of the special keys as buttons. They get assigned the BTN_* event keys. However, these are interpreted by mousedev as regular mouse buttons and are ignored by keybdev, which is quite annoying. The attached linux-2.4.20-18.9.acpi.4-keyb-but.patch makes mousedev ignore those and assigns KEY_PROG* event keys to those in keybdev, so that they behave as programmable keys.
Any feedback about the patches is appreciated.
Best,
Diego
Signature · 10 lines
------------------------------------------------------- Diego Santa Cruz - PhD Publications available at http://ltswww.epfl.ch/~dsanta Signal Processing Institute (LTS1 / ITS / STI) Swiss Federal Institute of Technology (EPFL) EPFL - STI - ITS, CH-1015 Lausanne, Switzerland E-mail: [email protected] Phone: +41 - 21 - 693 26 57 Fax: +41 - 21 - 693 76 00 -------------------------------------------------------
D Recognize more keys on USB keyboards, in particular many keys D defined in the HID consumer page.
D Use MS standard and MS Office keyboard USB HID to PS/2 scancode D mapping, plus custom mapping for other keys, this makes the scancodes D for USB keyboards compatible with most PS/2 keyboards.
D
include/linux/input.h renamed from include/linux/input.h.orig +51 -1
@@ -7,6 +7,9 @@* Copyright (c) 1999-2000 Vojtech Pavlik * * Sponsored by SuSE +* +* 2003.07.29, Diego Santa Cruz <[email protected]> +* Updated USB HID to event keycode mapping */ /*
@@ -305,11 +308,58 @@#define KEY_SUSPEND 205#define KEY_CLOSE 206 -#define KEY_UNKNOWN 220 +/* #define KEY_UNKNOWN 220 */ #define KEY_BRIGHTNESSDOWN 224#define KEY_BRIGHTNESSUP 225 +/* Extra key definitions from kernel 2.6 */ +#define KEY_PLAY 207 +#define KEY_FASTFORWARD 208 +#define KEY_BASSBOOST 209 +#define KEY_PRINT 210 +#define KEY_HP 211 +#define KEY_CAMERA 212 +#define KEY_SOUND 213 +#define KEY_QUESTION 214 +#define KEY_EMAIL 215 +#define KEY_CHAT 216 +#define KEY_SEARCH 217 +#define KEY_CONNECT 218 +#define KEY_FINANCE 219 +#define KEY_SPORT 220 +#define KEY_SHOP 221 +#define KEY_ALTERASE 222 +#define KEY_CANCEL 223 +#define KEY_MEDIA 226 + +/* Extra key definitions (private) */ +#define KEY_SELECT 199 +#define KEY_WORDPROCESSOR 227 +#define KEY_SPREADSHEET 228 +#define KEY_CALENDAR 229 +#define KEY_LANBROWSER 230 +#define KEY_LOGOFF 231 +#define KEY_NEXTTASK 232 +#define KEY_PREVTASK 233 +#define KEY_DOCUMENTS 234 +#define KEY_DESKTOP 235 +#define KEY_SPELLCHECK 236 +#define KEY_PICTURES 237 +#define KEY_MUSIC 238 +#define KEY_NEW 239 +#define KEY_SAVE 240 +#define KEY_HISTORY 241 +#define KEY_REPLY 242 +#define KEY_FORWARDMSG 243 +#define KEY_SEND 244 +#define KEY_ZOOMIN 245 +#define KEY_ZOOMOUT 246 +#define KEY_ZOOM 247 +#define KEY_SCROLL 248 + +#define KEY_UNKNOWN 255 +#define BTN_MISC 0x100#define BTN_0 0x100#define BTN_1 0x101
drivers/usb/hid-input.c renamed from drivers/usb/hid-input.c.orig +92 -23
160 lines not on this page · raw message
drivers/input/keybdev.c renamed from drivers/input/keybdev.c.orig +184 -23
225 lines not on this page · raw message
D Do not map keyboard buttons to PS/2 mouse buttons but to D programmable keys.
D
drivers/input/keybdev.c renamed from drivers/input/keybdev.c.orig +7 -0
@@ -337,6 +337,13 @@ {if (type !=EV_KEY )return ; +switch (code) {/* map keyboard buttons to programmable keys */ +case BTN_0 : code =KEY_PROG1 ;break ; +case BTN_1 : code =KEY_PROG2 ;break ; +case BTN_2 : code =KEY_PROG3 ;break ; +case BTN_3 : code =KEY_PROG4 ;break ; + } +if (emulate_raw (code, down))printk (KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n" , code);
drivers/input/mousedev.c renamed from drivers/input/mousedev.c.orig +0 -5
@@ -122,17 +122,12 @@case EV_KEY :switch (code) { -case BTN_0 :case BTN_TOUCH :case BTN_LEFT : index =0 ;break ; -case BTN_4 :case BTN_EXTRA :if (list->mode ==2 ) { index =4 ;break ; }case BTN_STYLUS : -case BTN_1 :case BTN_RIGHT : index =1 ;break ; -case BTN_3 :case BTN_SIDE :if (list->mode ==2 ) { index =3 ;break ; } -case BTN_2 :case BTN_STYLUS2 :case BTN_MIDDLE : index =2 ;break ;default :return ;