Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / input / keyboard / maple_keyb.c
blobcc6aaf9e85bef05c09d6e94d8db144f3492ca38d
1 /*
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
5 */
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
39 struct dc_kbd {
40 struct input_dev *dev;
41 unsigned char new[8];
42 unsigned char old[8];
46 static void dc_scan_kbd(struct dc_kbd *kbd)
48 int i;
49 struct input_dev *dev = kbd->dev;
51 for (i = 0; i < 8; i++)
52 input_report_key(dev, dc_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
54 for (i = 2; i < 8; i++) {
56 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == NULL) {
57 if (dc_kbd_keycode[kbd->old[i]])
58 input_report_key(dev, dc_kbd_keycode[kbd->old[i]], 0);
59 else
60 printk("Unknown key (scancode %#x) released.",
61 kbd->old[i]);
64 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) != NULL) {
65 if(dc_kbd_keycode[kbd->new[i]])
66 input_report_key(dev, dc_kbd_keycode[kbd->new[i]], 1);
67 else
68 printk("Unknown key (scancode %#x) pressed.",
69 kbd->new[i]);
73 input_sync(dev);
75 memcpy(kbd->old, kbd->new, 8);
79 static void dc_kbd_callback(struct mapleq *mq)
81 struct maple_device *mapledev = mq->dev;
82 struct dc_kbd *kbd = mapledev->private_data;
83 unsigned long *buf = mq->recvbuf;
85 if (buf[1] == mapledev->function) {
86 memcpy(kbd->new, buf + 2, 8);
87 dc_scan_kbd(kbd);
91 static int dc_kbd_connect(struct maple_device *dev)
93 struct dc_kbd *kbd;
94 struct input_dev *input_dev;
95 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
96 int i;
98 dev->private_data = kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
99 input_dev = input_allocate_device();
100 if (!kbd || !input_dev) {
101 kfree(kbd);
102 input_free_device(input_dev);
103 return -ENOMEM;
106 kbd->dev = input_dev;
108 input_dev->name = dev->product_name;
109 input_dev->id.bustype = BUS_MAPLE;
110 input_dev->private = kbd;
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 for (i = 0; i < 255; i++)
113 set_bit(dc_kbd_keycode[i], input_dev->keybit);
114 clear_bit(0, input_dev->keybit);
116 input_register_device(kbd->dev);
118 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
119 return 0;
123 static void dc_kbd_disconnect(struct maple_device *dev)
125 struct dc_kbd *kbd = dev->private_data;
127 input_unregister_device(kbd->dev);
128 kfree(kbd);
132 static struct maple_driver dc_kbd_driver = {
133 .function = MAPLE_FUNC_KEYBOARD,
134 .name = "Dreamcast keyboard",
135 .connect = dc_kbd_connect,
136 .disconnect = dc_kbd_disconnect,
140 static int __init dc_kbd_init(void)
142 maple_register_driver(&dc_kbd_driver);
143 return 0;
147 static void __exit dc_kbd_exit(void)
149 maple_unregister_driver(&dc_kbd_driver);
153 module_init(dc_kbd_init);
154 module_exit(dc_kbd_exit);
157 * Local variables:
158 * c-basic-offset: 8
159 * End: