2 * Hardware event => input event mapping:
4 * BTN_TOOL_PEN 0x140 black
5 * BTN_TOOL_RUBBER 0x141 blue
6 * BTN_TOOL_BRUSH 0x142 green
7 * BTN_TOOL_PENCIL 0x143 red
8 * BTN_TOOL_AIRBRUSH 0x144 eraser
9 * BTN_TOOL_FINGER 0x145 small eraser
10 * BTN_TOOL_MOUSE 0x146 mimio interactive
11 * BTN_TOOL_LENS 0x147 mimio interactive but1
12 * LOCALBTN_TOOL_EXTRA1 0x14a mimio interactive but2 == BTN_TOUCH
13 * LOCALBTN_TOOL_EXTRA2 0x14b mimio extra pens (orange, brown, yellow,
14 * purple) == BTN_STYLUS
15 * LOCALBTN_TOOL_EXTRA3 0x14c unused == BTN_STYLUS2
16 * BTN_TOOL_DOUBLETAP 0x14d unused
17 * BTN_TOOL_TRIPLETAP 0x14e unused
19 * MIMIO_EV_PENDOWN(MIMIO_PEN_K) => EV_KEY BIT(BTN_TOOL_PEN)
20 * MIMIO_EV_PENDOWN(MIMIO_PEN_B) => EV_KEY BIT(BTN_TOOL_RUBBER)
21 * MIMIO_EV_PENDOWN(MIMIO_PEN_G) => EV_KEY BIT(BTN_TOOL_BRUSH)
22 * MIMIO_EV_PENDOWN(MIMIO_PEN_R) => EV_KEY BIT(BTN_TOOL_PENCIL)
23 * MIMIO_EV_PENDOWN(MIMIO_PEN_E) => EV_KEY BIT(BTN_TOOL_AIRBRUSH)
24 * MIMIO_EV_PENDOWN(MIMIO_PEN_ES) => EV_KEY BIT(BTN_TOOL_FINGER)
25 * MIMIO_EV_PENDOWN(MIMIO_PEN_I) => EV_KEY BIT(BTN_TOOL_MOUSE)
26 * MIMIO_EV_PENDOWN(MIMIO_PEN_IL) => EV_KEY BIT(BTN_TOOL_LENS)
27 * MIMIO_EV_PENDOWN(MIMIO_PEN_IR) => EV_KEY BIT(BTN_TOOL_DOUBLETAP)
28 * MIMIO_EV_PENDOWN(MIMIO_PEN_EX) => EV_KEY BIT(BTN_TOOL_TRIPLETAP)
29 * MIMIO_EV_PENDATA => EV_ABS BIT(ABS_X), BIT(ABS_Y)
30 * MIMIO_EV_MEMRESET => EV_KEY BIT(BTN_0)
31 * MIMIO_EV_ACC(ACC_NEWPAGE) => EV_KEY BIT(BTN_1)
32 * MIMIO_EV_ACC(ACC_TAGPAGE) => EV_KEY BIT(BTN_2)
33 * MIMIO_EV_ACC(ACC_PRINTPAGE) => EV_KEY BIT(BTN_3)
34 * MIMIO_EV_ACC(ACC_MAXIMIZE) => EV_KEY BIT(BTN_4)
35 * MIMIO_EV_ACC(ACC_FINDCTLPNL) => EV_KEY BIT(BTN_5)
38 * - cold-load of data captured when mimio in standalone mode not yet
39 * supported; need to snoop Win32 box to see datastream for this.
40 * - mimio mouse not yet supported; need to snoop Win32 box to see the
41 * datastream for this.
44 #include <linux/kernel.h>
45 #include <linux/init.h>
46 #include <linux/slab.h>
47 #include <linux/spinlock.h>
48 #include <linux/input.h>
49 #include <linux/usb.h>
51 #define DRIVER_VERSION "v0.031"
52 #define DRIVER_AUTHOR "mwilder@cs.nmsu.edu"
53 #define DRIVER_DESC "USB mimio-xi driver"
55 enum {UPVALUE, DOWNVALUE, MOVEVALUE};
57 #define MIMIO_XRANGE_MAX 9600
58 #define MIMIO_YRANGE_MAX 4800
60 #define LOCALBTN_TOOL_EXTRA1 BTN_TOUCH
61 #define LOCALBTN_TOOL_EXTRA2 BTN_STYLUS
62 #define LOCALBTN_TOOL_EXTRA3 BTN_STYLUS2
64 #define MIMIO_VENDOR_ID 0x08d3
65 #define MIMIO_PRODUCT_ID 0x0001
66 #define MIMIO_MAXPAYLOAD (8)
67 #define MIMIO_MAXNAMELEN (64)
68 #define MIMIO_TXWAIT (1)
69 #define MIMIO_TXDONE (2)
71 #define MIMIO_EV_PENDOWN (0x22)
72 #define MIMIO_EV_PENDATA (0x24)
73 #define MIMIO_EV_PENUP (0x51)
74 #define MIMIO_EV_MEMRESET (0x45)
75 #define MIMIO_EV_ACC (0xb2)
77 #define MIMIO_PEN_K (1) /* black pen */
78 #define MIMIO_PEN_B (2) /* blue pen */
79 #define MIMIO_PEN_G (3) /* green pen */
80 #define MIMIO_PEN_R (4) /* red pen */
81 /* 5, 6, 7, 8 are extra pens */
82 #define MIMIO_PEN_E (9) /* big eraser */
83 #define MIMIO_PEN_ES (10) /* lil eraser */
84 #define MIMIO_PENJUMP_START (10)
85 #define MIMIO_PENJUMP (6)
86 #define MIMIO_PEN_I (17) /* mimio interactive */
87 #define MIMIO_PEN_IL (18) /* mimio interactive button 1 */
88 #define MIMIO_PEN_IR (19) /* mimio interactive button 2 */
90 #define MIMIO_PEN_MAX (MIMIO_PEN_IR)
93 #define ACC_NEWPAGE (1)
94 #define ACC_TAGPAGE (2)
95 #define ACC_PRINTPAGE (4)
96 #define ACC_MAXIMIZE (8)
97 #define ACC_FINDCTLPNL (16)
99 #define isvalidtxsize(n) ((n) > 0 && (n) <= MIMIO_MAXPAYLOAD)
104 unsigned char buf[16];
113 struct usb_endpoint_descriptor *desc;
117 struct input_dev *idev;
118 struct usb_device *udev;
119 struct usb_interface *uifc;
124 char phys[MIMIO_MAXNAMELEN];
125 struct usbintendpt in;
126 struct usbintendpt out;
127 struct pktbuf pktbuf;
129 wait_queue_head_t waitq;
131 void (*rxhandler)(struct mimio *, unsigned char *, unsigned int);
135 static void mimio_close(struct input_dev *);
136 static void mimio_dealloc(struct mimio *);
137 static void mimio_disconnect(struct usb_interface *);
138 static int mimio_greet(struct mimio *);
139 static void mimio_irq_in(struct urb *);
140 static void mimio_irq_out(struct urb *);
141 static int mimio_open(struct input_dev *);
142 static int mimio_probe(struct usb_interface *, const struct usb_device_id *);
143 static void mimio_rx_handler(struct mimio *, unsigned char *, unsigned int);
144 static int mimio_tx(struct mimio *, const char *, int);
146 static char mimio_name[] = "VirtualInk mimio-Xi";
147 static struct usb_device_id mimio_table[] = {
148 { USB_DEVICE(MIMIO_VENDOR_ID, MIMIO_PRODUCT_ID) },
149 { USB_DEVICE(0x0525, 0xa4a0) }, /* gadget zero firmware */
153 MODULE_DEVICE_TABLE(usb, mimio_table);
155 static struct usb_driver mimio_driver = {
157 .probe = mimio_probe,
158 .disconnect = mimio_disconnect,
159 .id_table = mimio_table,
162 static DECLARE_MUTEX(disconnect_sem);
164 static void mimio_close(struct input_dev *idev)
168 mimio = input_get_drvdata(idev);
170 dev_err(&idev->dev, "null mimio attached to input device\n");
174 if (mimio->open <= 0)
175 dev_err(&idev->dev, "mimio not open.\n");
179 if (mimio->present == 0 && mimio->open == 0)
180 mimio_dealloc(mimio);
183 static void mimio_dealloc(struct mimio *mimio)
188 usb_kill_urb(mimio->in.urb);
190 usb_kill_urb(mimio->out.urb);
193 input_unregister_device(mimio->idev);
194 if (mimio->idev->grab)
195 input_close_device(mimio->idev->grab);
197 dev_dbg(&mimio->idev->dev, "mimio->idev->grab == NULL"
198 " -- didn't call input_close_device\n");
201 usb_free_urb(mimio->in.urb);
203 usb_free_urb(mimio->out.urb);
206 usb_buffer_free(mimio->udev, MIMIO_MAXPAYLOAD, mimio->in.buf,
211 usb_buffer_free(mimio->udev, MIMIO_MAXPAYLOAD, mimio->out.buf,
215 input_free_device(mimio->idev);
220 static void mimio_disconnect(struct usb_interface *ifc)
224 down(&disconnect_sem);
226 mimio = usb_get_intfdata(ifc);
227 usb_set_intfdata(ifc, NULL);
228 dev_dbg(&mimio->idev->dev, "disconnect\n");
233 if (mimio->open <= 0)
234 mimio_dealloc(mimio);
240 static int mimio_greet(struct mimio *mimio)
242 const struct grtpkt {
247 { 3, 0, { 0x11, 0x55, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 } },
248 { 5, 0, { 0x53, 0x55, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00 } },
249 { 5, 0, { 0x43, 0x55, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00 } },
250 { 5, 0, { 0x33, 0x55, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00 } },
251 { 5, 0, { 0x13, 0x00, 0x5e, 0x02, 0x4f, 0x00, 0x00, 0x00 } },
252 { 5, 0, { 0x13, 0x00, 0x04, 0x03, 0x14, 0x00, 0x00, 0x00 } },
253 { 5, 2, { 0x13, 0x00, 0x00, 0x04, 0x17, 0x00, 0x00, 0x00 } },
254 { 5, 0, { 0x13, 0x00, 0x0d, 0x08, 0x16, 0x00, 0x00, 0x00 } },
255 { 5, 0, { 0x13, 0x00, 0x4d, 0x01, 0x5f, 0x00, 0x00, 0x00 } },
256 { 3, 0, { 0xf1, 0x55, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00 } },
257 { 7, 2, { 0x52, 0x55, 0x00, 0x07, 0x31, 0x55, 0x64, 0x00 } },
258 { 0, 0, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
261 const struct grtpkt *pkt;
263 for (pkt = grtpkts; pkt->nbytes; pkt++) {
264 rslt = mimio_tx(mimio, pkt->data, pkt->nbytes);
274 static void mimio_irq_in(struct urb *urb)
278 const char *reason = "going down";
281 mimio = urb->context;
287 switch (urb->status) {
292 reason = "timeout -- unplugged?";
296 dev_dbg(&mimio->idev->dev, "%s.\n", reason);
299 dev_dbg(&mimio->idev->dev, "unknown urb-status: %d.\n",
303 data = mimio->in.buf;
305 if (mimio->rxhandler)
306 mimio->rxhandler(mimio, data, urb->actual_length);
309 * Keep listening to device on same urb.
311 rslt = usb_submit_urb(urb, GFP_ATOMIC);
313 dev_err(&mimio->idev->dev, "usb_submit_urb failure: %d.\n",
317 static void mimio_irq_out(struct urb *urb)
322 mimio = urb->context;
325 dev_dbg(&mimio->idev->dev, "urb-status: %d.\n", urb->status);
327 spin_lock_irqsave(&mimio->txlock, flags);
328 mimio->txflags |= MIMIO_TXDONE;
329 spin_unlock_irqrestore(&mimio->txlock, flags);
331 wake_up(&mimio->waitq);
334 static int mimio_open(struct input_dev *idev)
340 down(&disconnect_sem);
341 mimio = input_get_drvdata(idev);
342 dev_dbg(&idev->dev, "mimio_open\n");
345 dev_err(&idev->dev, "null mimio.\n");
353 if (mimio->present && !mimio->greeted) {
354 struct urb *urb = mimio->in.urb;
355 mimio->in.urb->dev = mimio->udev;
356 rslt = usb_submit_urb(mimio->in.urb, GFP_KERNEL);
358 dev_err(&idev->dev, "usb_submit_urb failure "
359 "(res = %d: ", rslt);
361 dev_err(&idev->dev, "urb is NULL");
362 else if (urb->hcpriv)
363 dev_err(&idev->dev, "urb->hcpriv is non-NULL");
364 else if (!urb->complete)
365 dev_err(&idev->dev, "urb is not complete");
366 else if (urb->number_of_packets <= 0)
367 dev_err(&idev->dev, "urb has no packets");
368 else if (urb->interval <= 0)
369 dev_err(&idev->dev, "urb interval too small");
371 dev_err(&idev->dev, "urb interval too large " \
372 "or some other error");
373 dev_err(&idev->dev, "). Not greeting.\n");
377 rslt = mimio_greet(mimio);
379 dev_dbg(&idev->dev, "Mimio greeted OK.\n");
382 dev_dbg(&idev->dev, "Mimio greet Failure (%d)\n",
392 static int mimio_probe(struct usb_interface *ifc,
393 const struct usb_device_id *id)
398 struct usb_device *udev;
399 struct usb_host_interface *hostifc;
400 struct input_dev *input_dev;
404 udev = interface_to_usbdev(ifc);
406 mimio = kzalloc(sizeof(struct mimio), GFP_KERNEL);
410 input_dev = input_allocate_device();
412 mimio_dealloc(mimio);
418 mimio->pktbuf.p = mimio->pktbuf.buf;
419 mimio->pktbuf.q = mimio->pktbuf.buf;
420 /* init_input_dev(mimio->idev); */
421 mimio->idev = input_dev;
422 init_waitqueue_head(&mimio->waitq);
423 spin_lock_init(&mimio->txlock);
424 hostifc = ifc->cur_altsetting;
426 if (hostifc->desc.bNumEndpoints != 2) {
427 dev_err(&udev->dev, "Unexpected endpoint count: %d.\n",
428 hostifc->desc.bNumEndpoints);
429 mimio_dealloc(mimio);
433 mimio->in.desc = &(hostifc->endpoint[0].desc);
434 mimio->out.desc = &(hostifc->endpoint[1].desc);
436 mimio->in.buf = usb_buffer_alloc(udev, MIMIO_MAXPAYLOAD, GFP_KERNEL,
438 mimio->out.buf = usb_buffer_alloc(udev, MIMIO_MAXPAYLOAD, GFP_KERNEL,
441 if (mimio->in.buf == NULL || mimio->out.buf == NULL) {
442 dev_err(&udev->dev, "usb_buffer_alloc failure.\n");
443 mimio_dealloc(mimio);
447 mimio->in.urb = usb_alloc_urb(0, GFP_KERNEL);
448 mimio->out.urb = usb_alloc_urb(0, GFP_KERNEL);
450 if (mimio->in.urb == NULL || mimio->out.urb == NULL) {
451 dev_err(&udev->dev, "usb_alloc_urb failure.\n");
452 mimio_dealloc(mimio);
457 * Build the input urb.
459 pipe = usb_rcvintpipe(udev, mimio->in.desc->bEndpointAddress);
460 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
461 if (maxp > MIMIO_MAXPAYLOAD)
462 maxp = MIMIO_MAXPAYLOAD;
463 usb_fill_int_urb(mimio->in.urb, udev, pipe, mimio->in.buf, maxp,
464 mimio_irq_in, mimio, mimio->in.desc->bInterval);
465 mimio->in.urb->transfer_dma = mimio->in.dma;
466 mimio->in.urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
469 * Build the output urb.
471 pipe = usb_sndintpipe(udev, mimio->out.desc->bEndpointAddress);
472 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
473 if (maxp > MIMIO_MAXPAYLOAD)
474 maxp = MIMIO_MAXPAYLOAD;
475 usb_fill_int_urb(mimio->out.urb, udev, pipe, mimio->out.buf, maxp,
476 mimio_irq_out, mimio, mimio->out.desc->bInterval);
477 mimio->out.urb->transfer_dma = mimio->out.dma;
478 mimio->out.urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
481 * Build input device info
483 usb_make_path(udev, path, 64);
484 snprintf(mimio->phys, MIMIO_MAXNAMELEN, "%s/input0", path);
485 input_set_drvdata(input_dev, mimio);
486 /* input_dev->dev = &ifc->dev; */
487 input_dev->open = mimio_open;
488 input_dev->close = mimio_close;
489 input_dev->name = mimio_name;
490 input_dev->phys = mimio->phys;
491 input_dev->dev.parent = &ifc->dev;
493 input_dev->id.bustype = BUS_USB;
494 input_dev->id.vendor = le16_to_cpu(udev->descriptor.idVendor);
495 input_dev->id.product = le16_to_cpu(udev->descriptor.idProduct);
496 input_dev->id.version = le16_to_cpu(udev->descriptor.bcdDevice);
498 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
499 for (i = BTN_TOOL_PEN; i <= LOCALBTN_TOOL_EXTRA2; ++i)
500 set_bit(i, input_dev->keybit);
502 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
508 /* input_dev->keybit[BTN_MOUSE] |= BIT(BTN_LEFT); */
509 input_dev->absbit[0] |= BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
510 input_set_abs_params(input_dev, ABS_X, 0, MIMIO_XRANGE_MAX, 0, 0);
511 input_set_abs_params(input_dev, ABS_Y, 0, MIMIO_YRANGE_MAX, 0, 0);
512 input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
515 * Register the input device.
517 res = input_register_device(mimio->idev);
519 dev_err(&udev->dev, "input_register_device failure (%d)\n",
521 mimio_dealloc(mimio);
524 dev_dbg(&mimio->idev->dev, "input: %s on %s (res = %d).\n",
525 input_dev->name, input_dev->phys, res);
527 usb_set_intfdata(ifc, mimio);
531 * Submit the input urb to the usb subsystem.
533 mimio->in.urb->dev = mimio->udev;
534 res = usb_submit_urb(mimio->in.urb, GFP_KERNEL);
536 dev_err(&mimio->idev->dev, "usb_submit_urb failure (%d)\n",
538 mimio_dealloc(mimio);
543 * Attempt to greet the mimio after giving
544 * it some post-init settling time.
546 * note: sometimes this sleep interval isn't
547 * long enough to permit the device to re-init
548 * after a hot-swap; maybe need to bump it up.
550 * As it is, this probably breaks module unloading support!
554 res = mimio_greet(mimio);
556 dev_dbg(&mimio->idev->dev, "Mimio greeted OK.\n");
558 mimio->rxhandler = mimio_rx_handler;
560 dev_dbg(&mimio->idev->dev, "Mimio greet Failure (%d)\n", res);
566 static int handle_mimio_rx_penupdown(struct mimio *mimio,
568 const char *const instr[],
569 const int instr_ofst[])
572 if (mimio->pktbuf.q - mimio->pktbuf.p < (down ? 4 : 3))
573 return 1; /* partial pkt */
576 x = *mimio->pktbuf.p ^ *(mimio->pktbuf.p + 1) ^
577 *(mimio->pktbuf.p + 2);
578 if (x != *(mimio->pktbuf.p + 3)) {
579 dev_dbg(&mimio->idev->dev, "EV_PEN%s: bad xsum.\n",
580 down ? "DOWN" : "UP");
581 /* skip this event data */
582 mimio->pktbuf.p += 4;
583 /* decode any remaining events */
586 penid = mimio->pktbuf.instr = *(mimio->pktbuf.p + 2);
587 if (penid > MIMIO_PEN_MAX) {
588 dev_dbg(&mimio->idev->dev,
589 "Unmapped penID (not in [0, %d]): %d\n",
590 MIMIO_PEN_MAX, (int)mimio->pktbuf.instr);
591 penid = mimio->pktbuf.instr = 0;
593 mimio->last_pen_down = penid;
595 penid = mimio->last_pen_down;
597 dev_dbg(&mimio->idev->dev, "%s (id %d, code %d) %s.\n", instr[penid],
598 instr_ofst[penid], penid, down ? "down" : "up");
600 if (instr_ofst[penid] >= 0) {
601 int code = BTN_TOOL_PEN + instr_ofst[penid];
602 int value = down ? DOWNVALUE : UPVALUE;
604 dev_dbg(&mimio->idev->dev, "input_event will ignore "
605 "-- code (%d) > KEY_MAX\n", code);
606 if (!test_bit(code, mimio->idev->keybit))
607 dev_dbg(&mimio->idev->dev, "input_event will ignore "
608 "-- bit for code (%d) not enabled\n", code);
609 if (!!test_bit(code, mimio->idev->key) == value)
610 dev_dbg(&mimio->idev->dev, "input_event will ignore "
611 "-- bit for code (%d) already set to %d\n",
613 if (value != DOWNVALUE) {
614 /* input_regs(mimio->idev, regs); */
615 input_report_key(mimio->idev, code, value);
616 input_sync(mimio->idev);
618 /* wait until we get some coordinates */
621 dev_dbg(&mimio->idev->dev, "penID offset[%d] == %d is < 0 "
622 "- not sending\n", penid, instr_ofst[penid]);
624 mimio->pktbuf.p += down ? 4 : 3; /* 3 for up, 4 for down */
629 * Stay tuned for partial-packet excitement.
631 * This routine buffers data packets received from the mimio device
632 * in the mimio's data space. This buffering is necessary because
633 * the mimio's in endpoint can serve us partial packets of data, and
634 * we want the driver to support the servicing of multiple mimios.
635 * Empirical evidence gathered so far suggests that the method of
636 * buffering packet data in the mimio's data space works. Previous
637 * versions of this driver did not buffer packet data in each mimio's
638 * data-space, and were therefore not able to service multiple mimios.
639 * Note that since the caller of this routine is running in interrupt
640 * context, care needs to be taken to ensure that this routine does not
641 * become bloated, and it may be that another spinlock is needed in each
642 * mimio to guard the buffered packet data properly.
644 static void mimio_rx_handler(struct mimio *mimio,
648 struct device *dev = &mimio->idev->dev;
651 static const char * const instr[] = {
653 "black pen", "blue pen", "green pen", "red pen",
654 "brown pen", "orange pen", "purple pen", "yellow pen",
655 "big eraser", "lil eraser",
656 "?11", "?12", "?13", "?14", "?15", "?16",
657 "mimio interactive", "interactive button1",
658 "interactive button2"
661 /* Mimio Interactive gives:
662 * down: [0x22 0x01 0x11 0x32 0x24]
663 * b1 : [0x22 0x01 0x12 0x31 0x24]
664 * b2 : [0x22 0x01 0x13 0x30 0x24]
666 static const int instr_ofst[] = {
671 -1, -1, -1, -1, -1, -1,
675 memcpy(mimio->pktbuf.q, data, nbytes);
676 mimio->pktbuf.q += nbytes;
678 while (mimio->pktbuf.p < mimio->pktbuf.q) {
679 int t = *mimio->pktbuf.p;
682 case MIMIO_EV_PENDOWN:
683 if (handle_mimio_rx_penupdown(mimio,
684 t == MIMIO_EV_PENDOWN,
686 return; /* partial packet */
689 case MIMIO_EV_PENDATA:
690 if (mimio->pktbuf.q - mimio->pktbuf.p < 6)
693 x = *mimio->pktbuf.p ^ *(mimio->pktbuf.p + 1) ^
694 *(mimio->pktbuf.p + 2) ^
695 *(mimio->pktbuf.p + 3) ^
696 *(mimio->pktbuf.p + 4);
697 if (x != *(mimio->pktbuf.p + 5)) {
698 dev_dbg(dev, "EV_PENDATA: bad xsum.\n");
699 mimio->pktbuf.p += 6; /* skip this event data */
700 break; /* decode any remaining events */
702 x = *(mimio->pktbuf.p + 1);
704 x |= *(mimio->pktbuf.p + 2);
705 y = *(mimio->pktbuf.p + 3);
707 y |= *(mimio->pktbuf.p + 4);
708 dev_dbg(dev, "coord: (%d, %d)\n", x, y);
709 if (instr_ofst[mimio->pktbuf.instr] >= 0) {
710 int code = BTN_TOOL_PEN +
711 instr_ofst[mimio->last_pen_down];
712 /* input_regs(mimio->idev, regs); */
713 input_report_abs(mimio->idev, ABS_X, x);
714 input_report_abs(mimio->idev, ABS_Y, y);
716 change_bit(code, mimio->idev->key);
717 input_report_key(mimio->idev,
720 /* always sync here */
721 mimio->idev->sync = 0;
722 input_sync(mimio->idev);
724 mimio->pktbuf.p += 6;
726 case MIMIO_EV_MEMRESET:
727 if (mimio->pktbuf.q - mimio->pktbuf.p < 7)
730 dev_dbg(dev, "mem-reset.\n");
731 /* input_regs(mimio->idev, regs); */
732 input_event(mimio->idev, EV_KEY, BTN_0, 1);
733 input_event(mimio->idev, EV_KEY, BTN_0, 0);
734 input_sync(mimio->idev);
735 mimio->pktbuf.p += 7;
738 if (mimio->pktbuf.q - mimio->pktbuf.p < 4)
741 x = *mimio->pktbuf.p ^ *(mimio->pktbuf.p + 1) ^
742 *(mimio->pktbuf.p + 2);
743 if (x != *(mimio->pktbuf.p + 3)) {
744 dev_dbg(dev, "EV_ACC: bad xsum.\n");
745 mimio->pktbuf.p += 4; /* skip this event data */
746 break; /* decode any remaining events */
748 switch (*(mimio->pktbuf.p + 2)) {
750 dev_dbg(&mimio->idev->dev, "new-page.\n");
751 /* input_regs(mimio->idev, regs); */
752 input_event(mimio->idev, EV_KEY, BTN_1, 1);
753 input_event(mimio->idev, EV_KEY, BTN_1, 0);
754 input_sync(mimio->idev);
757 dev_dbg(&mimio->idev->dev, "tag-page.\n");
758 /* input_regs(mimio->idev, regs); */
759 input_event(mimio->idev, EV_KEY, BTN_2, 1);
760 input_event(mimio->idev, EV_KEY, BTN_2, 0);
761 input_sync(mimio->idev);
764 dev_dbg(&mimio->idev->dev, "print-page.\n");
765 /* input_regs(mimio->idev, regs);*/
766 input_event(mimio->idev, EV_KEY, BTN_3, 1);
767 input_event(mimio->idev, EV_KEY, BTN_3, 0);
768 input_sync(mimio->idev);
771 dev_dbg(&mimio->idev->dev,
772 "maximize-window.\n");
773 /* input_regs(mimio->idev, regs); */
774 input_event(mimio->idev, EV_KEY, BTN_4, 1);
775 input_event(mimio->idev, EV_KEY, BTN_4, 0);
776 input_sync(mimio->idev);
779 dev_dbg(&mimio->idev->dev, "find-ctl-panel.\n");
780 /* input_regs(mimio->idev, regs); */
781 input_event(mimio->idev, EV_KEY, BTN_5, 1);
782 input_event(mimio->idev, EV_KEY, BTN_5, 0);
783 input_sync(mimio->idev);
786 dev_dbg(&mimio->idev->dev, "acc-done.\n");
787 /* no event is dispatched to the input
788 * subsystem for this device event.
792 dev_dbg(dev, "unknown acc event.\n");
795 mimio->pktbuf.p += 4;
804 * No partial event was received, so reset mimio's pktbuf ptrs.
806 mimio->pktbuf.p = mimio->pktbuf.q = mimio->pktbuf.buf;
809 static int mimio_tx(struct mimio *mimio, const char *buf, int nbytes)
814 DECLARE_WAITQUEUE(wait, current);
816 if (!(isvalidtxsize(nbytes))) {
817 dev_err(&mimio->idev->dev, "invalid arg: nbytes: %d.\n",
823 * Init the out urb and copy the data to send.
825 mimio->out.urb->dev = mimio->udev;
826 mimio->out.urb->transfer_buffer_length = nbytes;
827 memcpy(mimio->out.urb->transfer_buffer, buf, nbytes);
832 spin_lock_irqsave(&mimio->txlock, flags);
833 mimio->txflags = MIMIO_TXWAIT;
834 rslt = usb_submit_urb(mimio->out.urb, GFP_ATOMIC);
835 spin_unlock_irqrestore(&mimio->txlock, flags);
836 dev_dbg(&mimio->idev->dev, "rslt: %d.\n", rslt);
839 dev_err(&mimio->idev->dev, "usb_submit_urb failure: %d.\n",
845 * Wait for completion to be signalled (the mimio_irq_out
846 * completion routine will or MIMIO_TXDONE in with txflags).
849 set_current_state(TASK_INTERRUPTIBLE);
850 add_wait_queue(&mimio->waitq, &wait);
852 while (timeout && ((mimio->txflags & MIMIO_TXDONE) == 0)) {
853 timeout = schedule_timeout(timeout);
857 if ((mimio->txflags & MIMIO_TXDONE) == 0)
858 dev_dbg(&mimio->idev->dev, "tx timed out.\n");
861 * Now that completion has been signalled,
862 * unlink the urb so that it can be recycled.
864 set_current_state(TASK_RUNNING);
865 remove_wait_queue(&mimio->waitq, &wait);
866 usb_unlink_urb(mimio->out.urb);
871 static int __init mimio_init(void)
875 rslt = usb_register(&mimio_driver);
877 err("%s: usb_register failure: %d", __func__, rslt);
881 printk(KERN_INFO KBUILD_MODNAME ":"
882 DRIVER_DESC " " DRIVER_VERSION "\n");
886 static void __exit mimio_exit(void)
888 usb_deregister(&mimio_driver);
891 module_init(mimio_init);
892 module_exit(mimio_exit);
894 MODULE_AUTHOR(DRIVER_AUTHOR);
895 MODULE_DESCRIPTION(DRIVER_DESC);
896 MODULE_LICENSE("GPL");