diff options
Diffstat (limited to 'drivers/input/mouse/sermouse.c')
-rw-r--r-- | drivers/input/mouse/sermouse.c | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c index d12b93ae3900..4bf584364d28 100644 --- a/drivers/input/mouse/sermouse.c +++ b/drivers/input/mouse/sermouse.c | |||
@@ -48,7 +48,7 @@ static char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse" | |||
48 | "Logitech MZ++ Mouse"}; | 48 | "Logitech MZ++ Mouse"}; |
49 | 49 | ||
50 | struct sermouse { | 50 | struct sermouse { |
51 | struct input_dev dev; | 51 | struct input_dev *dev; |
52 | signed char buf[8]; | 52 | signed char buf[8]; |
53 | unsigned char count; | 53 | unsigned char count; |
54 | unsigned char type; | 54 | unsigned char type; |
@@ -64,7 +64,7 @@ struct sermouse { | |||
64 | 64 | ||
65 | static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs) | 65 | static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs) |
66 | { | 66 | { |
67 | struct input_dev *dev = &sermouse->dev; | 67 | struct input_dev *dev = sermouse->dev; |
68 | signed char *buf = sermouse->buf; | 68 | signed char *buf = sermouse->buf; |
69 | 69 | ||
70 | input_regs(dev, regs); | 70 | input_regs(dev, regs); |
@@ -107,7 +107,7 @@ static void sermouse_process_msc(struct sermouse *sermouse, signed char data, st | |||
107 | 107 | ||
108 | static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs) | 108 | static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs) |
109 | { | 109 | { |
110 | struct input_dev *dev = &sermouse->dev; | 110 | struct input_dev *dev = sermouse->dev; |
111 | signed char *buf = sermouse->buf; | 111 | signed char *buf = sermouse->buf; |
112 | 112 | ||
113 | if (data & 0x40) sermouse->count = 0; | 113 | if (data & 0x40) sermouse->count = 0; |
@@ -230,9 +230,9 @@ static void sermouse_disconnect(struct serio *serio) | |||
230 | { | 230 | { |
231 | struct sermouse *sermouse = serio_get_drvdata(serio); | 231 | struct sermouse *sermouse = serio_get_drvdata(serio); |
232 | 232 | ||
233 | input_unregister_device(&sermouse->dev); | ||
234 | serio_close(serio); | 233 | serio_close(serio); |
235 | serio_set_drvdata(serio, NULL); | 234 | serio_set_drvdata(serio, NULL); |
235 | input_unregister_device(sermouse->dev); | ||
236 | kfree(sermouse); | 236 | kfree(sermouse); |
237 | } | 237 | } |
238 | 238 | ||
@@ -244,56 +244,52 @@ static void sermouse_disconnect(struct serio *serio) | |||
244 | static int sermouse_connect(struct serio *serio, struct serio_driver *drv) | 244 | static int sermouse_connect(struct serio *serio, struct serio_driver *drv) |
245 | { | 245 | { |
246 | struct sermouse *sermouse; | 246 | struct sermouse *sermouse; |
247 | unsigned char c; | 247 | struct input_dev *input_dev; |
248 | int err; | 248 | unsigned char c = serio->id.extra; |
249 | int err = -ENOMEM; | ||
249 | 250 | ||
250 | if (!serio->id.proto || serio->id.proto > SERIO_MZPP) | 251 | sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL); |
251 | return -ENODEV; | 252 | input_dev = input_allocate_device(); |
252 | 253 | if (!sermouse || !input_dev) | |
253 | if (!(sermouse = kmalloc(sizeof(struct sermouse), GFP_KERNEL))) | 254 | goto fail; |
254 | return -ENOMEM; | ||
255 | |||
256 | memset(sermouse, 0, sizeof(struct sermouse)); | ||
257 | |||
258 | init_input_dev(&sermouse->dev); | ||
259 | sermouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | ||
260 | sermouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT); | ||
261 | sermouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); | ||
262 | sermouse->dev.private = sermouse; | ||
263 | |||
264 | sermouse->type = serio->id.proto; | ||
265 | c = serio->id.extra; | ||
266 | |||
267 | if (c & 0x01) set_bit(BTN_MIDDLE, sermouse->dev.keybit); | ||
268 | if (c & 0x02) set_bit(BTN_SIDE, sermouse->dev.keybit); | ||
269 | if (c & 0x04) set_bit(BTN_EXTRA, sermouse->dev.keybit); | ||
270 | if (c & 0x10) set_bit(REL_WHEEL, sermouse->dev.relbit); | ||
271 | if (c & 0x20) set_bit(REL_HWHEEL, sermouse->dev.relbit); | ||
272 | 255 | ||
256 | sermouse->dev = input_dev; | ||
273 | sprintf(sermouse->phys, "%s/input0", serio->phys); | 257 | sprintf(sermouse->phys, "%s/input0", serio->phys); |
258 | sermouse->type = serio->id.proto; | ||
274 | 259 | ||
275 | sermouse->dev.name = sermouse_protocols[sermouse->type]; | 260 | input_dev->name = sermouse_protocols[sermouse->type]; |
276 | sermouse->dev.phys = sermouse->phys; | 261 | input_dev->phys = sermouse->phys; |
277 | sermouse->dev.id.bustype = BUS_RS232; | 262 | input_dev->id.bustype = BUS_RS232; |
278 | sermouse->dev.id.vendor = sermouse->type; | 263 | input_dev->id.vendor = sermouse->type; |
279 | sermouse->dev.id.product = c; | 264 | input_dev->id.product = c; |
280 | sermouse->dev.id.version = 0x0100; | 265 | input_dev->id.version = 0x0100; |
281 | sermouse->dev.dev = &serio->dev; | 266 | input_dev->cdev.dev = &serio->dev; |
267 | |||
268 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | ||
269 | input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT); | ||
270 | input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); | ||
271 | input_dev->private = sermouse; | ||
272 | |||
273 | if (c & 0x01) set_bit(BTN_MIDDLE, input_dev->keybit); | ||
274 | if (c & 0x02) set_bit(BTN_SIDE, input_dev->keybit); | ||
275 | if (c & 0x04) set_bit(BTN_EXTRA, input_dev->keybit); | ||
276 | if (c & 0x10) set_bit(REL_WHEEL, input_dev->relbit); | ||
277 | if (c & 0x20) set_bit(REL_HWHEEL, input_dev->relbit); | ||
282 | 278 | ||
283 | serio_set_drvdata(serio, sermouse); | 279 | serio_set_drvdata(serio, sermouse); |
284 | 280 | ||
285 | err = serio_open(serio, drv); | 281 | err = serio_open(serio, drv); |
286 | if (err) { | 282 | if (err) |
287 | serio_set_drvdata(serio, NULL); | 283 | goto fail; |
288 | kfree(sermouse); | ||
289 | return err; | ||
290 | } | ||
291 | |||
292 | input_register_device(&sermouse->dev); | ||
293 | 284 | ||
294 | printk(KERN_INFO "input: %s on %s\n", sermouse_protocols[sermouse->type], serio->phys); | 285 | input_register_device(sermouse->dev); |
295 | 286 | ||
296 | return 0; | 287 | return 0; |
288 | |||
289 | fail: serio_set_drvdata(serio, NULL); | ||
290 | input_free_device(input_dev); | ||
291 | kfree(sermouse); | ||
292 | return err; | ||
297 | } | 293 | } |
298 | 294 | ||
299 | static struct serio_device_id sermouse_serio_ids[] = { | 295 | static struct serio_device_id sermouse_serio_ids[] = { |