2 * Hardware event => input event mapping:
6 input.h:#define BTN_TOOL_PEN 0x140 black
7 input.h:#define BTN_TOOL_RUBBER 0x141 blue
8 input.h:#define BTN_TOOL_BRUSH 0x142 green
9 input.h:#define BTN_TOOL_PENCIL 0x143 red
10 input.h:#define BTN_TOOL_AIRBRUSH 0x144 eraser
11 input.h:#define BTN_TOOL_FINGER 0x145 small eraser
12 input.h:#define BTN_TOOL_MOUSE 0x146 mimio interactive
13 input.h:#define BTN_TOOL_LENS 0x147 mimio interactive but1
14 input.h:#define LOCALBTN_TOOL_EXTRA1 0x14a mimio interactive but2 == BTN_TOUCH
15 input.h:#define LOCALBTN_TOOL_EXTRA2 0x14b mimio extra pens (orange, brown, yellow, purple) == BTN_STYLUS
16 input.h:#define LOCALBTN_TOOL_EXTRA3 0x14c unused == BTN_STYLUS2
17 input.h:#define BTN_TOOL_DOUBLETAP 0x14d unused
18 input.h:#define BTN_TOOL_TRIPLETAP 0x14e unused
20 * MIMIO_EV_PENDOWN(MIMIO_PEN_K) => EV_KEY BIT(BTN_TOOL_PEN)
21 * MIMIO_EV_PENDOWN(MIMIO_PEN_B) => EV_KEY BIT(BTN_TOOL_RUBBER)
22 * MIMIO_EV_PENDOWN(MIMIO_PEN_G) => EV_KEY BIT(BTN_TOOL_BRUSH)
23 * MIMIO_EV_PENDOWN(MIMIO_PEN_R) => EV_KEY BIT(BTN_TOOL_PENCIL)
24 * MIMIO_EV_PENDOWN(MIMIO_PEN_E) => EV_KEY BIT(BTN_TOOL_AIRBRUSH)
25 * MIMIO_EV_PENDOWN(MIMIO_PEN_ES) => EV_KEY BIT(BTN_TOOL_FINGER)
26 * MIMIO_EV_PENDOWN(MIMIO_PEN_I) => EV_KEY BIT(BTN_TOOL_MOUSE)
27 * MIMIO_EV_PENDOWN(MIMIO_PEN_IL) => EV_KEY BIT(BTN_TOOL_LENS)
28 * MIMIO_EV_PENDOWN(MIMIO_PEN_IR) => EV_KEY BIT(BTN_TOOL_DOUBLETAP)
29 * MIMIO_EV_PENDOWN(MIMIO_PEN_EX) => EV_KEY BIT(BTN_TOOL_TRIPLETAP)
30 * MIMIO_EV_PENDATA => EV_ABS BIT(ABS_X), BIT(ABS_Y)
31 * MIMIO_EV_MEMRESET => EV_KEY BIT(BTN_0)
32 * MIMIO_EV_ACC(ACC_NEWPAGE) => EV_KEY BIT(BTN_1)
33 * MIMIO_EV_ACC(ACC_TAGPAGE) => EV_KEY BIT(BTN_2)
34 * MIMIO_EV_ACC(ACC_PRINTPAGE) => EV_KEY BIT(BTN_3)
35 * MIMIO_EV_ACC(ACC_MAXIMIZE) => EV_KEY BIT(BTN_4)
36 * MIMIO_EV_ACC(ACC_FINDCTLPNL) => EV_KEY BIT(BTN_5)
40 * - cold-load of data captured when mimio in standalone mode not yet
41 * supported; need to snoop Win32 box to see datastream for this.
42 * - mimio mouse not yet supported; need to snoop Win32 box to see the
43 * datastream for this.
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/slab.h>
48 #include <linux/spinlock.h>
49 #include <linux/input.h>
50 #include <linux/usb.h>
52 #define DRIVER_VERSION "v0.031"
53 #define DRIVER_AUTHOR "mwilder@cs.nmsu.edu"
54 #define DRIVER_DESC "USB mimio-xi driver"
56 enum {UPVALUE
, DOWNVALUE
, MOVEVALUE
};
58 #define MIMIO_XRANGE_MAX 9600
59 #define MIMIO_YRANGE_MAX 4800
61 #define LOCALBTN_TOOL_EXTRA1 BTN_TOUCH
62 #define LOCALBTN_TOOL_EXTRA2 BTN_STYLUS
63 #define LOCALBTN_TOOL_EXTRA3 BTN_STYLUS2
65 #define MIMIO_VENDOR_ID 0x08d3
66 #define MIMIO_PRODUCT_ID 0x0001
67 #define MIMIO_MAXPAYLOAD (8)
68 #define MIMIO_MAXNAMELEN (64)
69 #define MIMIO_TXWAIT (1)
70 #define MIMIO_TXDONE (2)
72 #define MIMIO_EV_PENDOWN (0x22)
73 #define MIMIO_EV_PENDATA (0x24)
74 #define MIMIO_EV_PENUP (0x51)
75 #define MIMIO_EV_MEMRESET (0x45)
76 #define MIMIO_EV_ACC (0xb2)
78 #define MIMIO_PEN_K (1) /* black pen */
79 #define MIMIO_PEN_B (2) /* blue pen */
80 #define MIMIO_PEN_G (3) /* green pen */
81 #define MIMIO_PEN_R (4) /* red pen */
82 /* 5, 6, 7, 8 are extra pens */
83 #define MIMIO_PEN_E (9) /* big eraser */
84 #define MIMIO_PEN_ES (10) /* lil eraser */
85 #define MIMIO_PENJUMP_START (10)
86 #define MIMIO_PENJUMP (6)
87 #define MIMIO_PEN_I (17) /* mimio interactive */
88 #define MIMIO_PEN_IL (18) /* mimio interactive button 1 */
89 #define MIMIO_PEN_IR (19) /* mimio interactive button 2 */
91 #define MIMIO_PEN_MAX (MIMIO_PEN_IR)
94 #define ACC_NEWPAGE (1)
95 #define ACC_TAGPAGE (2)
96 #define ACC_PRINTPAGE (4)
97 #define ACC_MAXIMIZE (8)
98 #define ACC_FINDCTLPNL (16)
100 #define isvalidtxsize(n) ((n) > 0 && (n) <= MIMIO_MAXPAYLOAD)
105 unsigned char buf
[16];
114 struct usb_endpoint_descriptor
*desc
;
118 struct input_dev
*idev
;
119 struct usb_device
*udev
;
120 struct usb_interface
*uifc
;
125 char phys
[MIMIO_MAXNAMELEN
];
126 struct usbintendpt in
;
127 struct usbintendpt out
;
128 struct pktbuf pktbuf
;
130 wait_queue_head_t waitq
;
132 void (*rxhandler
)(struct mimio
*, unsigned char *, unsigned int);
136 static void mimio_close(struct input_dev
*);
137 static void mimio_dealloc(struct mimio
*);
138 static void mimio_disconnect(struct usb_interface
*);
139 static int mimio_greet(struct mimio
*);
140 static void mimio_irq_in(struct urb
*);
141 static void mimio_irq_out(struct urb
*);
142 static int mimio_open(struct input_dev
*);
143 static int mimio_probe(struct usb_interface
*, const struct usb_device_id
*);
144 static void mimio_rx_handler(struct mimio
*, unsigned char *, unsigned int);
145 static int mimio_tx(struct mimio
*, const char *, int);
147 static char mimio_name
[] = "VirtualInk mimio-Xi";
148 static struct usb_device_id mimio_table
[] = {
149 { USB_DEVICE(MIMIO_VENDOR_ID
, MIMIO_PRODUCT_ID
) },
150 { USB_DEVICE(0x0525, 0xa4a0) }, /* gadget zero firmware */
154 MODULE_DEVICE_TABLE(usb
, mimio_table
);
156 static struct usb_driver mimio_driver
= {
158 .probe
= mimio_probe
,
159 .disconnect
= mimio_disconnect
,
160 .id_table
= mimio_table
,
163 static DECLARE_MUTEX(disconnect_sem
);
165 static void mimio_close(struct input_dev
*idev
)
169 mimio
= input_get_drvdata(idev
);
171 dev_err(&idev
->dev
, "null mimio attached to input device\n");
175 if (mimio
->open
<= 0)
176 dev_err(&idev
->dev
, "mimio not open.\n");
180 if (mimio
->present
== 0 && mimio
->open
== 0)
181 mimio_dealloc(mimio
);
184 static void mimio_dealloc(struct mimio
*mimio
)
189 usb_kill_urb(mimio
->in
.urb
);
191 usb_kill_urb(mimio
->out
.urb
);
194 input_unregister_device(mimio
->idev
);
195 if (mimio
->idev
->grab
)
196 input_close_device(mimio
->idev
->grab
);
198 dev_dbg(&mimio
->idev
->dev
, "mimio->idev->grab == NULL"
199 " -- didn't call input_close_device\n");
202 usb_free_urb(mimio
->in
.urb
);
204 usb_free_urb(mimio
->out
.urb
);
207 usb_buffer_free(mimio
->udev
, MIMIO_MAXPAYLOAD
, mimio
->in
.buf
,
212 usb_buffer_free(mimio
->udev
, MIMIO_MAXPAYLOAD
, mimio
->out
.buf
,
216 input_free_device(mimio
->idev
);
221 static void mimio_disconnect(struct usb_interface
*ifc
)
225 down(&disconnect_sem
);
227 mimio
= usb_get_intfdata(ifc
);
228 usb_set_intfdata(ifc
, NULL
);
229 dev_dbg(&mimio
->idev
->dev
, "disconnect\n");
234 if (mimio
->open
<= 0)
235 mimio_dealloc(mimio
);
241 static int mimio_greet(struct mimio
*mimio
)
243 const struct grtpkt
{
248 { 3, 0, { 0x11, 0x55, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 } },
249 { 5, 0, { 0x53, 0x55, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00 } },
250 { 5, 0, { 0x43, 0x55, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00 } },
251 { 5, 0, { 0x33, 0x55, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00 } },
252 { 5, 0, { 0x13, 0x00, 0x5e, 0x02, 0x4f, 0x00, 0x00, 0x00 } },
253 { 5, 0, { 0x13, 0x00, 0x04, 0x03, 0x14, 0x00, 0x00, 0x00 } },
254 { 5, 2, { 0x13, 0x00, 0x00, 0x04, 0x17, 0x00, 0x00, 0x00 } },
255 { 5, 0, { 0x13, 0x00, 0x0d, 0x08, 0x16, 0x00, 0x00, 0x00 } },
256 { 5, 0, { 0x13, 0x00, 0x4d, 0x01, 0x5f, 0x00, 0x00, 0x00 } },
257 { 3, 0, { 0xf1, 0x55, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00 } },
258 { 7, 2, { 0x52, 0x55, 0x00, 0x07, 0x31, 0x55, 0x64, 0x00 } },
259 { 0, 0, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
262 const struct grtpkt
*pkt
;
264 for (pkt
= grtpkts
; pkt
->nbytes
; pkt
++) {
265 rslt
= mimio_tx(mimio
, pkt
->data
, pkt
->nbytes
);
275 static void mimio_irq_in(struct urb
*urb
)
279 const char *reason
= "going down";
282 mimio
= urb
->context
;
288 switch (urb
->status
) {
293 reason
= "timeout -- unplugged?";
297 dev_dbg(&mimio
->idev
->dev
, "%s.\n", reason
);
300 dev_dbg(&mimio
->idev
->dev
, "unknown urb-status: %d.\n",
304 data
= mimio
->in
.buf
;
306 if (mimio
->rxhandler
)
307 mimio
->rxhandler(mimio
, data
, urb
->actual_length
);
310 * Keep listening to device on same urb.
312 rslt
= usb_submit_urb(urb
, GFP_ATOMIC
);
314 dev_err(&mimio
->idev
->dev
, "usb_submit_urb failure: %d.\n",
318 static void mimio_irq_out(struct urb
*urb
)
323 mimio
= urb
->context
;
326 dev_dbg(&mimio
->idev
->dev
, "urb-status: %d.\n", urb
->status
);
328 spin_lock_irqsave(&mimio
->txlock
, flags
);
329 mimio
->txflags
|= MIMIO_TXDONE
;
330 spin_unlock_irqrestore(&mimio
->txlock
, flags
);
332 wake_up(&mimio
->waitq
);
335 static int mimio_open(struct input_dev
*idev
)
341 down(&disconnect_sem
);
342 mimio
= input_get_drvdata(idev
);
343 dev_dbg(&idev
->dev
, "mimio_open\n");
346 dev_err(&idev
->dev
, "null mimio.\n");
354 if (mimio
->present
&& !mimio
->greeted
) {
355 struct urb
*urb
= mimio
->in
.urb
;
356 mimio
->in
.urb
->dev
= mimio
->udev
;
357 rslt
= usb_submit_urb(mimio
->in
.urb
, GFP_KERNEL
);
359 dev_err(&idev
->dev
, "usb_submit_urb failure "
360 "(res = %d: %s). Not greeting.\n",
362 (!urb
? "urb is NULL" :
363 (urb
->hcpriv
? "urb->hcpriv is non-NULL" :
364 (!urb
->complete
? "urb is not complete" :
365 (urb
->number_of_packets
<= 0 ? "urb has no packets" :
366 (urb
->interval
<= 0 ? "urb interval too small" :
367 "urb interval too large or some other error"))))));
371 rslt
= mimio_greet(mimio
);
373 dev_dbg(&idev
->dev
, "Mimio greeted OK.\n");
376 dev_dbg(&idev
->dev
, "Mimio greet Failure (%d)\n",
386 static int mimio_probe(struct usb_interface
*ifc
,
387 const struct usb_device_id
*id
)
392 struct usb_device
*udev
;
393 struct usb_host_interface
*hostifc
;
394 struct input_dev
*input_dev
;
398 udev
= interface_to_usbdev(ifc
);
400 mimio
= kzalloc(sizeof(struct mimio
), GFP_KERNEL
);
404 input_dev
= input_allocate_device();
406 mimio_dealloc(mimio
);
412 mimio
->pktbuf
.p
= mimio
->pktbuf
.buf
;
413 mimio
->pktbuf
.q
= mimio
->pktbuf
.buf
;
414 /* init_input_dev(mimio->idev); */
415 mimio
->idev
= input_dev
;
416 init_waitqueue_head(&mimio
->waitq
);
417 spin_lock_init(&mimio
->txlock
);
418 hostifc
= ifc
->cur_altsetting
;
420 if (hostifc
->desc
.bNumEndpoints
!= 2) {
421 dev_err(&udev
->dev
, "Unexpected endpoint count: %d.\n",
422 hostifc
->desc
.bNumEndpoints
);
423 mimio_dealloc(mimio
);
427 mimio
->in
.desc
= &(hostifc
->endpoint
[0].desc
);
428 mimio
->out
.desc
= &(hostifc
->endpoint
[1].desc
);
430 mimio
->in
.buf
= usb_buffer_alloc(udev
, MIMIO_MAXPAYLOAD
, GFP_KERNEL
,
432 mimio
->out
.buf
= usb_buffer_alloc(udev
, MIMIO_MAXPAYLOAD
, GFP_KERNEL
,
435 if (mimio
->in
.buf
== NULL
|| mimio
->out
.buf
== NULL
) {
436 dev_err(&udev
->dev
, "usb_buffer_alloc failure.\n");
437 mimio_dealloc(mimio
);
441 mimio
->in
.urb
= usb_alloc_urb(0, GFP_KERNEL
);
442 mimio
->out
.urb
= usb_alloc_urb(0, GFP_KERNEL
);
444 if (mimio
->in
.urb
== NULL
|| mimio
->out
.urb
== NULL
) {
445 dev_err(&udev
->dev
, "usb_alloc_urb failure.\n");
446 mimio_dealloc(mimio
);
451 * Build the input urb.
453 pipe
= usb_rcvintpipe(udev
, mimio
->in
.desc
->bEndpointAddress
);
454 maxp
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
455 if (maxp
> MIMIO_MAXPAYLOAD
)
456 maxp
= MIMIO_MAXPAYLOAD
;
457 usb_fill_int_urb(mimio
->in
.urb
, udev
, pipe
, mimio
->in
.buf
, maxp
,
458 mimio_irq_in
, mimio
, mimio
->in
.desc
->bInterval
);
459 mimio
->in
.urb
->transfer_dma
= mimio
->in
.dma
;
460 mimio
->in
.urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
463 * Build the output urb.
465 pipe
= usb_sndintpipe(udev
, mimio
->out
.desc
->bEndpointAddress
);
466 maxp
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
467 if (maxp
> MIMIO_MAXPAYLOAD
)
468 maxp
= MIMIO_MAXPAYLOAD
;
469 usb_fill_int_urb(mimio
->out
.urb
, udev
, pipe
, mimio
->out
.buf
, maxp
,
470 mimio_irq_out
, mimio
, mimio
->out
.desc
->bInterval
);
471 mimio
->out
.urb
->transfer_dma
= mimio
->out
.dma
;
472 mimio
->out
.urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
475 * Build input device info
477 usb_make_path(udev
, path
, 64);
478 snprintf(mimio
->phys
, MIMIO_MAXNAMELEN
, "%s/input0", path
);
479 input_set_drvdata(input_dev
, mimio
);
480 /* input_dev->dev = &ifc->dev; */
481 input_dev
->open
= mimio_open
;
482 input_dev
->close
= mimio_close
;
483 input_dev
->name
= mimio_name
;
484 input_dev
->phys
= mimio
->phys
;
485 input_dev
->dev
.parent
= &ifc
->dev
;
487 input_dev
->id
.bustype
= BUS_USB
;
488 input_dev
->id
.vendor
= le16_to_cpu(udev
->descriptor
.idVendor
);
489 input_dev
->id
.product
= le16_to_cpu(udev
->descriptor
.idProduct
);
490 input_dev
->id
.version
= le16_to_cpu(udev
->descriptor
.bcdDevice
);
492 input_dev
->evbit
[0] |= BIT(EV_KEY
) | BIT(EV_ABS
);
493 for (i
= BTN_TOOL_PEN
; i
<= LOCALBTN_TOOL_EXTRA2
; ++i
)
494 set_bit(i
, input_dev
->keybit
);
496 input_dev
->keybit
[BIT_WORD(BTN_MISC
)] |= BIT_MASK(BTN_0
) |
502 /* input_dev->keybit[BTN_MOUSE] |= BIT(BTN_LEFT); */
503 input_dev
->absbit
[0] |= BIT_MASK(ABS_X
) | BIT_MASK(ABS_Y
);
504 input_set_abs_params(input_dev
, ABS_X
, 0, MIMIO_XRANGE_MAX
, 0, 0);
505 input_set_abs_params(input_dev
, ABS_Y
, 0, MIMIO_YRANGE_MAX
, 0, 0);
506 input_dev
->absbit
[BIT_WORD(ABS_MISC
)] |= BIT_MASK(ABS_MISC
);
509 input_dev
->absmin
[ABS_X
] = 0;
510 input_dev
->absmin
[ABS_Y
] = 0;
511 input_dev
->absmax
[ABS_X
] = 9600;
512 input_dev
->absmax
[ABS_Y
] = 4800;
513 input_dev
->absfuzz
[ABS_X
] = 0;
514 input_dev
->absfuzz
[ABS_Y
] = 0;
515 input_dev
->absflat
[ABS_X
] = 0;
516 input_dev
->absflat
[ABS_Y
] = 0;
520 /* this will just reduce the precision */
521 input_dev
->absfuzz
[ABS_X
] = 8; /* experimental; may need to change */
522 input_dev
->absfuzz
[ABS_Y
] = 8; /* experimental; may need to change */
526 * Register the input device.
528 res
= input_register_device(mimio
->idev
);
530 dev_err(&udev
->dev
, "input_register_device failure (%d)\n",
532 mimio_dealloc(mimio
);
535 dev_dbg(&mimio
->idev
->dev
, "input: %s on %s (res = %d).\n",
536 input_dev
->name
, input_dev
->phys
, res
);
538 usb_set_intfdata(ifc
, mimio
);
542 * Submit the input urb to the usb subsystem.
544 mimio
->in
.urb
->dev
= mimio
->udev
;
545 res
= usb_submit_urb(mimio
->in
.urb
, GFP_KERNEL
);
547 dev_err(&mimio
->idev
->dev
, "usb_submit_urb failure (%d)\n",
549 mimio_dealloc(mimio
);
554 * Attempt to greet the mimio after giving
555 * it some post-init settling time.
557 * note: sometimes this sleep interval isn't
558 * long enough to permit the device to re-init
559 * after a hot-swap; maybe need to bump it up.
561 * As it is, this probably breaks module unloading support!
565 res
= mimio_greet(mimio
);
567 dev_dbg(&mimio
->idev
->dev
, "Mimio greeted OK.\n");
569 mimio
->rxhandler
= mimio_rx_handler
;
571 dev_dbg(&mimio
->idev
->dev
, "Mimio greet Failure (%d)\n", res
);
577 static int handle_mimio_rx_penupdown(struct mimio
*mimio
,
579 const char *const instr
[],
580 const int instr_ofst
[])
583 if (mimio
->pktbuf
.q
- mimio
->pktbuf
.p
< (down
? 4 : 3))
584 return 1; /* partial pkt */
587 x
= *mimio
->pktbuf
.p
^ *(mimio
->pktbuf
.p
+ 1) ^
588 *(mimio
->pktbuf
.p
+ 2);
589 if (x
!= *(mimio
->pktbuf
.p
+ 3)) {
590 dev_dbg(&mimio
->idev
->dev
, "EV_PEN%s: bad xsum.\n",
592 /* skip this event data */
593 mimio
->pktbuf
.p
+= 4;
594 /* decode any remaining events */
597 penid
= mimio
->pktbuf
.instr
= *(mimio
->pktbuf
.p
+ 2);
598 if (penid
> MIMIO_PEN_MAX
) {
599 dev_dbg(&mimio
->idev
->dev
,
600 "Unmapped penID (not in [0, %d]): %d\n",
601 MIMIO_PEN_MAX
, (int)mimio
->pktbuf
.instr
);
602 penid
= mimio
->pktbuf
.instr
= 0;
604 mimio
->last_pen_down
= penid
;
606 penid
= mimio
->last_pen_down
;
608 dev_dbg(&mimio
->idev
->dev
, "%s (id %d, code %d) %s.\n", instr
[penid
],
609 instr_ofst
[penid
], penid
, down
? "down" : "up");
611 if (instr_ofst
[penid
] >= 0) {
612 int code
= BTN_TOOL_PEN
+ instr_ofst
[penid
];
613 int value
= down
? DOWNVALUE
: UPVALUE
;
615 dev_dbg(&mimio
->idev
->dev
, "input_event will ignore "
616 "-- code (%d) > KEY_MAX\n", code
);
617 if (!test_bit(code
, mimio
->idev
->keybit
))
618 dev_dbg(&mimio
->idev
->dev
, "input_event will ignore "
619 "-- bit for code (%d) not enabled\n", code
);
620 if (!!test_bit(code
, mimio
->idev
->key
) == value
)
621 dev_dbg(&mimio
->idev
->dev
, "input_event will ignore "
622 "-- bit for code (%d) already set to %d\n",
624 if (value
!= DOWNVALUE
) {
625 /* input_regs(mimio->idev, regs); */
626 input_report_key(mimio
->idev
, code
, value
);
627 input_sync(mimio
->idev
);
629 /* wait until we get some coordinates */
632 dev_dbg(&mimio
->idev
->dev
, "penID offset[%d] == %d is < 0 "
633 "- not sending\n", penid
, instr_ofst
[penid
]);
635 mimio
->pktbuf
.p
+= down
? 4 : 3; /* 3 for up, 4 for down */
640 * Stay tuned for partial-packet excitement.
642 * This routine buffers data packets received from the mimio device
643 * in the mimio's data space. This buffering is necessary because
644 * the mimio's in endpoint can serve us partial packets of data, and
645 * we want the driver to support the servicing of multiple mimios.
646 * Empirical evidence gathered so far suggests that the method of
647 * buffering packet data in the mimio's data space works. Previous
648 * versions of this driver did not buffer packet data in each mimio's
649 * data-space, and were therefore not able to service multiple mimios.
650 * Note that since the caller of this routine is running in interrupt
651 * context, care needs to be taken to ensure that this routine does not
652 * become bloated, and it may be that another spinlock is needed in each
653 * mimio to guard the buffered packet data properly.
655 static void mimio_rx_handler(struct mimio
*mimio
,
659 struct device
*dev
= &mimio
->idev
->dev
;
662 static const char * const instr
[] = {
664 "black pen", "blue pen", "green pen", "red pen",
665 "brown pen", "orange pen", "purple pen", "yellow pen",
666 "big eraser", "lil eraser",
667 "?11", "?12", "?13", "?14", "?15", "?16",
668 "mimio interactive", "interactive button1",
669 "interactive button2"
672 /* Mimio Interactive gives:
673 * down: [0x22 0x01 0x11 0x32 0x24]
674 * b1 : [0x22 0x01 0x12 0x31 0x24]
675 * b2 : [0x22 0x01 0x13 0x30 0x24]
677 static const int instr_ofst
[] = {
682 -1, -1, -1, -1, -1, -1,
686 memcpy(mimio
->pktbuf
.q
, data
, nbytes
);
687 mimio
->pktbuf
.q
+= nbytes
;
689 while (mimio
->pktbuf
.p
< mimio
->pktbuf
.q
) {
690 int t
= *mimio
->pktbuf
.p
;
693 case MIMIO_EV_PENDOWN
:
694 if (handle_mimio_rx_penupdown(mimio
,
695 t
== MIMIO_EV_PENDOWN
,
697 return; /* partial packet */
700 case MIMIO_EV_PENDATA
:
701 if (mimio
->pktbuf
.q
- mimio
->pktbuf
.p
< 6)
704 x
= *mimio
->pktbuf
.p
^ *(mimio
->pktbuf
.p
+ 1) ^
705 *(mimio
->pktbuf
.p
+ 2) ^
706 *(mimio
->pktbuf
.p
+ 3) ^
707 *(mimio
->pktbuf
.p
+ 4);
708 if (x
!= *(mimio
->pktbuf
.p
+ 5)) {
709 dev_dbg(dev
, "EV_PENDATA: bad xsum.\n");
710 mimio
->pktbuf
.p
+= 6; /* skip this event data */
711 break; /* decode any remaining events */
713 x
= *(mimio
->pktbuf
.p
+ 1);
715 x
|= *(mimio
->pktbuf
.p
+ 2);
716 y
= *(mimio
->pktbuf
.p
+ 3);
718 y
|= *(mimio
->pktbuf
.p
+ 4);
719 dev_dbg(dev
, "coord: (%d, %d)\n", x
, y
);
720 if (instr_ofst
[mimio
->pktbuf
.instr
] >= 0) {
721 int code
= BTN_TOOL_PEN
+
722 instr_ofst
[mimio
->last_pen_down
];
724 /* Utter hack to ensure we get forwarded _AND_
725 * so we can identify when a complete signal is
727 mimio
->idev
->abs
[ABS_Y
] = -1;
728 mimio
->idev
->abs
[ABS_X
] = -1;
730 /* input_regs(mimio->idev, regs); */
731 input_report_abs(mimio
->idev
, ABS_X
, x
);
732 input_report_abs(mimio
->idev
, ABS_Y
, y
);
734 change_bit(code
, mimio
->idev
->key
);
735 input_report_key(mimio
->idev
,
738 /* always sync here */
739 mimio
->idev
->sync
= 0;
740 input_sync(mimio
->idev
);
742 mimio
->pktbuf
.p
+= 6;
744 case MIMIO_EV_MEMRESET
:
745 if (mimio
->pktbuf
.q
- mimio
->pktbuf
.p
< 7)
748 dev_dbg(dev
, "mem-reset.\n");
749 /* input_regs(mimio->idev, regs); */
750 input_event(mimio
->idev
, EV_KEY
, BTN_0
, 1);
751 input_event(mimio
->idev
, EV_KEY
, BTN_0
, 0);
752 input_sync(mimio
->idev
);
753 mimio
->pktbuf
.p
+= 7;
756 if (mimio
->pktbuf
.q
- mimio
->pktbuf
.p
< 4)
759 x
= *mimio
->pktbuf
.p
^ *(mimio
->pktbuf
.p
+ 1) ^
760 *(mimio
->pktbuf
.p
+ 2);
761 if (x
!= *(mimio
->pktbuf
.p
+ 3)) {
762 dev_dbg(dev
, "EV_ACC: bad xsum.\n");
763 mimio
->pktbuf
.p
+= 4; /* skip this event data */
764 break; /* decode any remaining events */
766 switch (*(mimio
->pktbuf
.p
+ 2)) {
768 dev_dbg(&mimio
->idev
->dev
, "new-page.\n");
769 /* input_regs(mimio->idev, regs); */
770 input_event(mimio
->idev
, EV_KEY
, BTN_1
, 1);
771 input_event(mimio
->idev
, EV_KEY
, BTN_1
, 0);
772 input_sync(mimio
->idev
);
775 dev_dbg(&mimio
->idev
->dev
, "tag-page.\n");
776 /* input_regs(mimio->idev, regs); */
777 input_event(mimio
->idev
, EV_KEY
, BTN_2
, 1);
778 input_event(mimio
->idev
, EV_KEY
, BTN_2
, 0);
779 input_sync(mimio
->idev
);
782 dev_dbg(&mimio
->idev
->dev
, "print-page.\n");
783 /* input_regs(mimio->idev, regs);*/
784 input_event(mimio
->idev
, EV_KEY
, BTN_3
, 1);
785 input_event(mimio
->idev
, EV_KEY
, BTN_3
, 0);
786 input_sync(mimio
->idev
);
789 dev_dbg(&mimio
->idev
->dev
,
790 "maximize-window.\n");
791 /* input_regs(mimio->idev, regs); */
792 input_event(mimio
->idev
, EV_KEY
, BTN_4
, 1);
793 input_event(mimio
->idev
, EV_KEY
, BTN_4
, 0);
794 input_sync(mimio
->idev
);
797 dev_dbg(&mimio
->idev
->dev
, "find-ctl-panel.\n");
798 /* input_regs(mimio->idev, regs); */
799 input_event(mimio
->idev
, EV_KEY
, BTN_5
, 1);
800 input_event(mimio
->idev
, EV_KEY
, BTN_5
, 0);
801 input_sync(mimio
->idev
);
804 dev_dbg(&mimio
->idev
->dev
, "acc-done.\n");
805 /* no event is dispatched to the input
806 * subsystem for this device event.
810 dev_dbg(dev
, "unknown acc event.\n");
813 mimio
->pktbuf
.p
+= 4;
822 * No partial event was received, so reset mimio's pktbuf ptrs.
824 mimio
->pktbuf
.p
= mimio
->pktbuf
.q
= mimio
->pktbuf
.buf
;
827 static int mimio_tx(struct mimio
*mimio
, const char *buf
, int nbytes
)
832 DECLARE_WAITQUEUE(wait
, current
);
834 if (!(isvalidtxsize(nbytes
))) {
835 dev_err(&mimio
->idev
->dev
, "invalid arg: nbytes: %d.\n",
841 * Init the out urb and copy the data to send.
843 mimio
->out
.urb
->dev
= mimio
->udev
;
844 mimio
->out
.urb
->transfer_buffer_length
= nbytes
;
845 memcpy(mimio
->out
.urb
->transfer_buffer
, buf
, nbytes
);
850 spin_lock_irqsave(&mimio
->txlock
, flags
);
851 mimio
->txflags
= MIMIO_TXWAIT
;
852 rslt
= usb_submit_urb(mimio
->out
.urb
, GFP_ATOMIC
);
853 spin_unlock_irqrestore(&mimio
->txlock
, flags
);
854 dev_dbg(&mimio
->idev
->dev
, "rslt: %d.\n", rslt
);
857 dev_err(&mimio
->idev
->dev
, "usb_submit_urb failure: %d.\n",
863 * Wait for completion to be signalled (the mimio_irq_out
864 * completion routine will or MIMIO_TXDONE in with txflags).
867 set_current_state(TASK_INTERRUPTIBLE
);
868 add_wait_queue(&mimio
->waitq
, &wait
);
870 while (timeout
&& ((mimio
->txflags
& MIMIO_TXDONE
) == 0)) {
871 timeout
= schedule_timeout(timeout
);
875 if ((mimio
->txflags
& MIMIO_TXDONE
) == 0)
876 dev_dbg(&mimio
->idev
->dev
, "tx timed out.\n");
879 * Now that completion has been signalled,
880 * unlink the urb so that it can be recycled.
882 set_current_state(TASK_RUNNING
);
883 remove_wait_queue(&mimio
->waitq
, &wait
);
884 usb_unlink_urb(mimio
->out
.urb
);
889 static int __init
mimio_init(void)
893 rslt
= usb_register(&mimio_driver
);
895 err("%s: usb_register failure: %d", __func__
, rslt
);
899 printk(KERN_INFO KBUILD_MODNAME
":"
900 DRIVER_DESC
" " DRIVER_VERSION
"\n");
904 static void __exit
mimio_exit(void)
906 usb_deregister(&mimio_driver
);
909 module_init(mimio_init
);
910 module_exit(mimio_exit
);
912 MODULE_AUTHOR(DRIVER_AUTHOR
);
913 MODULE_DESCRIPTION(DRIVER_DESC
);
914 MODULE_LICENSE("GPL");