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");
24 static void dc_mouse_callback(struct mapleq
*mq
)
26 int buttons
, relx
, rely
, relz
;
27 struct maple_device
*mapledev
= mq
->dev
;
28 struct dc_mouse
*mouse
= mapledev
->private_data
;
29 struct input_dev
*dev
= &mouse
->dev
;
30 unsigned char *res
= mq
->recvbuf
;
33 relx
=*(unsigned short *)(res
+12)-512;
34 rely
=*(unsigned short *)(res
+14)-512;
35 relz
=*(unsigned short *)(res
+16)-512;
37 input_report_key(dev
, BTN_LEFT
, buttons
&4);
38 input_report_key(dev
, BTN_MIDDLE
, buttons
&9);
39 input_report_key(dev
, BTN_RIGHT
, buttons
&2);
40 input_report_rel(dev
, REL_X
, relx
);
41 input_report_rel(dev
, REL_Y
, rely
);
42 input_report_rel(dev
, REL_WHEEL
, relz
);
47 static int dc_mouse_open(struct input_dev
*dev
)
49 struct dc_mouse
*mouse
= dev
->private;
55 static void dc_mouse_close(struct input_dev
*dev
)
57 struct dc_mouse
*mouse
= dev
->private;
62 static int dc_mouse_connect(struct maple_device
*dev
)
64 unsigned long data
= be32_to_cpu(dev
->devinfo
.function_data
[0]);
65 struct dc_mouse
*mouse
;
67 if (!(mouse
= kmalloc(sizeof(struct dc_mouse
), GFP_KERNEL
)))
69 memset(mouse
, 0, sizeof(struct dc_mouse
));
71 dev
->private_data
= mouse
;
73 mouse
->dev
.evbit
[0] = BIT(EV_KEY
) | BIT(EV_REL
);
74 mouse
->dev
.keybit
[LONG(BTN_MOUSE
)] = BIT(BTN_LEFT
) | BIT(BTN_RIGHT
) | BIT(BTN_MIDDLE
);
75 mouse
->dev
.relbit
[0] = BIT(REL_X
) | BIT(REL_Y
) | BIT(REL_WHEEL
);
77 init_input_dev(&mouse
->dev
);
79 mouse
->dev
.private = mouse
;
80 mouse
->dev
.open
= dc_mouse_open
;
81 mouse
->dev
.close
= dc_mouse_close
;
82 mouse
->dev
.event
= NULL
;
84 mouse
->dev
.name
= dev
->product_name
;
85 mouse
->dev
.id
.bustype
= BUS_MAPLE
;
87 input_register_device(&mouse
->dev
);
89 maple_getcond_callback(dev
, dc_mouse_callback
, 1, MAPLE_FUNC_MOUSE
);
91 printk(KERN_INFO
"input: mouse(0x%lx): %s\n", data
, mouse
->dev
.name
);
97 static void dc_mouse_disconnect(struct maple_device
*dev
)
99 struct dc_mouse
*mouse
= dev
->private_data
;
101 input_unregister_device(&mouse
->dev
);
106 static struct maple_driver dc_mouse_driver
= {
107 .function
= MAPLE_FUNC_MOUSE
,
108 .name
= "Dreamcast mouse",
109 .connect
= dc_mouse_connect
,
110 .disconnect
= dc_mouse_disconnect
,
114 static int __init
dc_mouse_init(void)
116 maple_register_driver(&dc_mouse_driver
);
121 static void __exit
dc_mouse_exit(void)
123 maple_unregister_driver(&dc_mouse_driver
);
127 module_init(dc_mouse_init
);
128 module_exit(dc_mouse_exit
);