diff options
Diffstat (limited to 'drivers/input/mouse/maplemouse.c')
-rw-r--r-- | drivers/input/mouse/maplemouse.c | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c new file mode 100644 index 000000000000..12dc0ef5020f --- /dev/null +++ b/drivers/input/mouse/maplemouse.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
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 | ||
5 | */ | ||
6 | |||
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> | ||
14 | |||
15 | MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>"); | ||
16 | MODULE_DESCRIPTION("SEGA Dreamcast mouse driver"); | ||
17 | |||
18 | struct dc_mouse { | ||
19 | struct input_dev dev; | ||
20 | int open; | ||
21 | }; | ||
22 | |||
23 | |||
24 | static void dc_mouse_callback(struct mapleq *mq) | ||
25 | { | ||
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; | ||
31 | |||
32 | buttons = ~res[8]; | ||
33 | relx=*(unsigned short *)(res+12)-512; | ||
34 | rely=*(unsigned short *)(res+14)-512; | ||
35 | relz=*(unsigned short *)(res+16)-512; | ||
36 | |||
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); | ||
43 | input_sync(dev); | ||
44 | } | ||
45 | |||
46 | |||
47 | static int dc_mouse_open(struct input_dev *dev) | ||
48 | { | ||
49 | struct dc_mouse *mouse = dev->private; | ||
50 | mouse->open++; | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | |||
55 | static void dc_mouse_close(struct input_dev *dev) | ||
56 | { | ||
57 | struct dc_mouse *mouse = dev->private; | ||
58 | mouse->open--; | ||
59 | } | ||
60 | |||
61 | |||
62 | static int dc_mouse_connect(struct maple_device *dev) | ||
63 | { | ||
64 | unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); | ||
65 | struct dc_mouse *mouse; | ||
66 | |||
67 | if (!(mouse = kmalloc(sizeof(struct dc_mouse), GFP_KERNEL))) | ||
68 | return -1; | ||
69 | memset(mouse, 0, sizeof(struct dc_mouse)); | ||
70 | |||
71 | dev->private_data = mouse; | ||
72 | |||
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); | ||
76 | |||
77 | init_input_dev(&mouse->dev); | ||
78 | |||
79 | mouse->dev.private = mouse; | ||
80 | mouse->dev.open = dc_mouse_open; | ||
81 | mouse->dev.close = dc_mouse_close; | ||
82 | mouse->dev.event = NULL; | ||
83 | |||
84 | mouse->dev.name = dev->product_name; | ||
85 | mouse->dev.id.bustype = BUS_MAPLE; | ||
86 | |||
87 | input_register_device(&mouse->dev); | ||
88 | |||
89 | maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); | ||
90 | |||
91 | printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, mouse->dev.name); | ||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | |||
97 | static void dc_mouse_disconnect(struct maple_device *dev) | ||
98 | { | ||
99 | struct dc_mouse *mouse = dev->private_data; | ||
100 | |||
101 | input_unregister_device(&mouse->dev); | ||
102 | kfree(mouse); | ||
103 | } | ||
104 | |||
105 | |||
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, | ||
111 | }; | ||
112 | |||
113 | |||
114 | static int __init dc_mouse_init(void) | ||
115 | { | ||
116 | maple_register_driver(&dc_mouse_driver); | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | |||
121 | static void __exit dc_mouse_exit(void) | ||
122 | { | ||
123 | maple_unregister_driver(&dc_mouse_driver); | ||
124 | } | ||
125 | |||
126 | |||
127 | module_init(dc_mouse_init); | ||
128 | module_exit(dc_mouse_exit); | ||
129 | |||
130 | /* | ||
131 | * Local variables: | ||
132 | * c-basic-offset: 8 | ||
133 | * End: | ||
134 | */ | ||