2 * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast mouse driver
4 * Based on drivers/usb/usbmouse.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 mouse driver");
18 static void dc_mouse_callback(struct mapleq *mq)
20 int buttons, relx, rely, relz;
21 struct maple_device *mapledev = mq->dev;
22 struct input_dev *dev = mapledev->private_data;
23 unsigned char *res = mq->recvbuf;
26 relx = *(unsigned short *)(res + 12) - 512;
27 rely = *(unsigned short *)(res + 14) - 512;
28 relz = *(unsigned short *)(res + 16) - 512;
30 input_report_key(dev, BTN_LEFT, buttons & 4);
31 input_report_key(dev, BTN_MIDDLE, buttons & 9);
32 input_report_key(dev, BTN_RIGHT, buttons & 2);
33 input_report_rel(dev, REL_X, relx);
34 input_report_rel(dev, REL_Y, rely);
35 input_report_rel(dev, REL_WHEEL, relz);
39 static int dc_mouse_connect(struct maple_device *dev)
41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
42 struct input_dev *input_dev;
44 if (!(input_dev = kmalloc(sizeof(struct input_dev), GFP_KERNEL)))
47 dev->private_data = input_dev;
49 memset(input_dev, 0, sizeof(struct dc_mouse));
50 init_input_dev(input_dev);
51 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
52 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
53 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
55 input_dev->name = dev->product_name;
56 input_dev->id.bustype = BUS_MAPLE;
58 input_register_device(input_dev);
60 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
62 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, input_dev->name);
68 static void dc_mouse_disconnect(struct maple_device *dev)
70 struct input_dev *input_dev = dev->private_data;
72 input_unregister_device(input_dev);
77 static struct maple_driver dc_mouse_driver = {
78 .function = MAPLE_FUNC_MOUSE,
79 .name = "Dreamcast mouse",
80 .connect = dc_mouse_connect,
81 .disconnect = dc_mouse_disconnect,
85 static int __init dc_mouse_init(void)
87 maple_register_driver(&dc_mouse_driver);
92 static void __exit dc_mouse_exit(void)
94 maple_unregister_driver(&dc_mouse_driver);
98 module_init(dc_mouse_init);
99 module_exit(dc_mouse_exit);