2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast keyboard driver
4 * Based on drivers/usb/usbkbd.c
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/timer.h>
13 #include <linux/maple.h>
15 MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
16 MODULE_DESCRIPTION("SEGA Dreamcast keyboard driver");
17 MODULE_LICENSE("GPL");
19 static unsigned char dc_kbd_keycode[256] = {
20 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
21 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
22 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
23 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
24 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
25 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
26 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
27 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
28 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
29 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
35 150,158,159,128,136,177,178,176,142,152,173,140
46 static void dc_scan_kbd(struct dc_kbd *kbd)
49 struct input_dev *dev = &kbd->dev;
53 dc_kbd_keycode[i+224],
58 if(kbd->old[i]>3&&memscan(kbd->new+2, kbd->old[i], 6)==NULL) {
59 if(dc_kbd_keycode[kbd->old[i]])
61 dc_kbd_keycode[kbd->old[i]],
64 printk("Unknown key (scancode %#x) released.",
68 if(kbd->new[i]>3&&memscan(kbd->old+2, kbd->new[i], 6)!=NULL) {
69 if(dc_kbd_keycode[kbd->new[i]])
71 dc_kbd_keycode[kbd->new[i]],
74 printk("Unknown key (scancode %#x) pressed.",
81 memcpy(kbd->old, kbd->new, 8);
85 static void dc_kbd_callback(struct mapleq *mq)
87 struct maple_device *mapledev = mq->dev;
88 struct dc_kbd *kbd = mapledev->private_data;
89 unsigned long *buf = mq->recvbuf;
91 if (buf[1] == mapledev->function) {
92 memcpy(kbd->new, buf+2, 8);
97 static int dc_kbd_connect(struct maple_device *dev)
100 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
103 if (!(kbd = kmalloc(sizeof(struct dc_kbd), GFP_KERNEL)))
105 memset(kbd, 0, sizeof(struct dc_kbd));
107 dev->private_data = kbd;
109 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
111 init_input_dev(&kbd->dev);
113 for (i=0; i<255; i++)
114 set_bit(dc_kbd_keycode[i], kbd->dev.keybit);
116 clear_bit(0, kbd->dev.keybit);
118 kbd->dev.private = kbd;
120 kbd->dev.name = dev->product_name;
121 kbd->dev.id.bustype = BUS_MAPLE;
123 input_register_device(&kbd->dev);
125 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
127 printk(KERN_INFO "input: keyboard(0x%lx): %s\n", data, kbd->dev.name);
133 static void dc_kbd_disconnect(struct maple_device *dev)
135 struct dc_kbd *kbd = dev->private_data;
137 input_unregister_device(&kbd->dev);
142 static struct maple_driver dc_kbd_driver = {
143 .function = MAPLE_FUNC_KEYBOARD,
144 .name = "Dreamcast keyboard",
145 .connect = dc_kbd_connect,
146 .disconnect = dc_kbd_disconnect,
150 static int __init dc_kbd_init(void)
152 maple_register_driver(&dc_kbd_driver);
157 static void __exit dc_kbd_exit(void)
159 maple_unregister_driver(&dc_kbd_driver);
163 module_init(dc_kbd_init);
164 module_exit(dc_kbd_exit);