patch-2.3.36 linux/drivers/usb/keybdev.c

Next file: linux/drivers/usb/keyboard.c
Previous file: linux/drivers/usb/joydev.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.35/linux/drivers/usb/keybdev.c linux/drivers/usb/keybdev.c
@@ -0,0 +1,139 @@
+/*
+ *  keybdev.c  Version 0.1
+ *
+ *  Copyright (c) 1999 Vojtech Pavlik
+ *
+ *  Input driver to keyboard driver binding.
+ *
+ *  Sponsored by SuSE
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so either by
+ * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
+ * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
+ */
+
+#include <linux/config.h>
+#include <linux/kbd_ll.h>
+#include <linux/input.h>
+#include <linux/malloc.h>
+#include <linux/init.h>
+#include <linux/module.h>
+
+#ifdef CONFIG_X86
+
+static unsigned char keybdev_x86_e0s[] = 
+	{ 0x1c, 0x1d, 0x35, 0x2a, 0x38, 0x39, 0x47, 0x48,
+	  0x49, 0x4b, 0x4d, 0x4f, 0x50, 0x51, 0x52, 0x53 };
+
+#elif CONFIG_MAC_KEYBOARD
+
+static unsigned char keybdev_mac_codes[256] =
+	{ 0, 53, 18, 19, 20, 21, 23, 22, 26, 28, 25, 29, 27, 24, 51, 48,
+	 12, 13, 14, 15, 17, 16, 32, 34, 31, 35, 33, 30, 36, 54,  0,  1,
+	  2,  3,  5,  4, 38, 40, 37, 41, 39, 50, 56, 42,  6,  7,  8,  9,
+	 11, 45, 46, 43, 47, 44,123, 67, 55, 49, 57,122,120, 99,118, 96,
+	 97, 98,100,101,109, 71,107, 89, 91, 92, 78, 86, 87, 88, 69, 83,
+	 84, 85, 82, 65,  0,  0,  0,103,111,  0,  0,  0,  0,  0,  0,  0,
+	 76,125, 75,  0,124,  0,115, 62,116, 59, 60,119, 61,121,114,117,
+	  0,  0,  0,  0,127, 81,  0,113 };
+
+#endif
+
+void keybdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int down)
+{
+	if (type != EV_KEY || code > 255) return;
+
+#ifdef CONFIG_X86
+
+	if (code >= 125) {
+		handle_scancode(0xe0, 1);
+		handle_scancode(code - 34, down);
+	} else if (code == 119) {
+		handle_scancode(0xe1, 1);
+		handle_scancode(0x1d, down);
+		handle_scancode(0x45, down);
+	} else if (code >= 96) {
+		handle_scancode(0xe0, 1);
+		handle_scancode(keybdev_x86_e0s[code - 96], down);
+		if (code == 99) {
+			handle_scancode(0xe0, 1);
+			handle_scancode(0x37, down);
+		}
+	} else handle_scancode(code, down);
+
+#elif CONFIG_MAC_KEYBOARD
+
+	if (keycode < 128) 
+		handle_scancode(keybdev_mac_codes[code], down);
+
+#else
+#error "Cannot generate rawmode keyboard for your architecture yet."
+#endif
+
+}
+
+static int keybdev_connect(struct input_handler *handler, struct input_dev *dev)
+{
+	struct input_handle *handle;
+
+	if (!test_bit(EV_KEY, dev->evbit) || !test_bit(KEY_A, dev->keybit) || !test_bit(KEY_Z, dev->keybit))
+		return -1;
+
+	if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
+		return -1;
+	memset(handle, 0, sizeof(struct input_handle));
+
+	handle->dev = dev;
+	handle->handler = handler;
+
+	input_open_device(handle);
+
+	printk("keybdev.c: Adding keyboard: input%d\n", dev->number);
+
+	return 0;
+}
+
+static void keybdev_disconnect(struct input_handle *handle)
+{
+	printk("keybdev.c: Removing keyboard: input%d\n", handle->dev->number);
+
+	input_close_device(handle);
+
+	kfree(handle);
+}
+	
+struct input_handler keybdev_handler = {
+	event:		keybdev_event,
+	connect:	keybdev_connect,
+	disconnect:	keybdev_disconnect,
+};
+
+#ifdef MODULE
+void cleanup_module(void)
+{
+	input_unregister_handler(&keybdev_handler);
+}
+int init_module(void)
+#else
+int __init keybdev_init(void)
+#endif
+{
+	input_register_handler(&keybdev_handler);
+	return 0;
+}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)