1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73#include <linux/jiffies.h>
74#include <linux/kernel.h>
75#include <linux/slab.h>
76#include <linux/module.h>
77#include <linux/usb/input.h>
78#include <linux/uaccess.h>
79#include <asm/unaligned.h>
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178#define USB_VENDOR_ID_AIPTEK 0x08ca
179#define USB_VENDOR_ID_KYE 0x0458
180#define USB_REQ_GET_REPORT 0x01
181#define USB_REQ_SET_REPORT 0x09
182
183
184
185#define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
186#define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
187#define AIPTEK_POINTER_EITHER_MODE 2
188
189#define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
190 (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
191 a == AIPTEK_POINTER_EITHER_MODE)
192#define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
193 (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
194 a == AIPTEK_POINTER_EITHER_MODE)
195
196
197
198#define AIPTEK_COORDINATE_RELATIVE_MODE 0
199#define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
200
201
202
203#define AIPTEK_TILT_MIN (-128)
204#define AIPTEK_TILT_MAX 127
205#define AIPTEK_TILT_DISABLE (-10101)
206
207
208
209#define AIPTEK_WHEEL_MIN 0
210#define AIPTEK_WHEEL_MAX 1024
211#define AIPTEK_WHEEL_DISABLE (-10101)
212
213
214
215
216
217
218
219#define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
220#define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
221#define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
222#define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
223#define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
224#define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
225#define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
226
227
228
229#define AIPTEK_DIAGNOSTIC_NA 0
230#define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
231#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
232#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
233
234
235
236
237#define AIPTEK_JITTER_DELAY_DEFAULT 50
238
239
240
241
242
243#define AIPTEK_PROGRAMMABLE_DELAY_25 25
244#define AIPTEK_PROGRAMMABLE_DELAY_50 50
245#define AIPTEK_PROGRAMMABLE_DELAY_100 100
246#define AIPTEK_PROGRAMMABLE_DELAY_200 200
247#define AIPTEK_PROGRAMMABLE_DELAY_300 300
248#define AIPTEK_PROGRAMMABLE_DELAY_400 400
249#define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
250
251
252
253#define AIPTEK_MOUSE_LEFT_BUTTON 0x04
254#define AIPTEK_MOUSE_RIGHT_BUTTON 0x08
255#define AIPTEK_MOUSE_MIDDLE_BUTTON 0x10
256
257
258
259#define AIPTEK_STYLUS_LOWER_BUTTON 0x08
260#define AIPTEK_STYLUS_UPPER_BUTTON 0x10
261
262
263
264#define AIPTEK_PACKET_LENGTH 8
265
266
267
268
269
270
271#define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
272#define AIPTEK_REPORT_TOOL_STYLUS 0x20
273#define AIPTEK_REPORT_TOOL_MOUSE 0x40
274
275static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
276static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
277
278struct aiptek_features {
279 int odmCode;
280 int modelCode;
281 int firmwareCode;
282 char usbPath[64 + 1];
283};
284
285struct aiptek_settings {
286 int pointerMode;
287 int coordinateMode;
288 int toolMode;
289 int xTilt;
290 int yTilt;
291 int wheel;
292 int stylusButtonUpper;
293 int stylusButtonLower;
294 int mouseButtonLeft;
295 int mouseButtonMiddle;
296 int mouseButtonRight;
297 int programmableDelay;
298 int jitterDelay;
299};
300
301struct aiptek {
302 struct input_dev *inputdev;
303 struct usb_interface *intf;
304 struct urb *urb;
305 dma_addr_t data_dma;
306 struct aiptek_features features;
307 struct aiptek_settings curSetting;
308 struct aiptek_settings newSetting;
309 unsigned int ifnum;
310 int diagnostic;
311 unsigned long eventCount;
312 int inDelay;
313 unsigned long endDelay;
314 int previousJitterable;
315
316 int lastMacro;
317 int previousToolMode;
318 unsigned char *data;
319};
320
321static const int eventTypes[] = {
322 EV_KEY, EV_ABS, EV_REL, EV_MSC,
323};
324
325static const int absEvents[] = {
326 ABS_X, ABS_Y, ABS_PRESSURE, ABS_TILT_X, ABS_TILT_Y,
327 ABS_WHEEL, ABS_MISC,
328};
329
330static const int relEvents[] = {
331 REL_X, REL_Y, REL_WHEEL,
332};
333
334static const int buttonEvents[] = {
335 BTN_LEFT, BTN_RIGHT, BTN_MIDDLE,
336 BTN_TOOL_PEN, BTN_TOOL_RUBBER, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH,
337 BTN_TOOL_BRUSH, BTN_TOOL_MOUSE, BTN_TOOL_LENS, BTN_TOUCH,
338 BTN_STYLUS, BTN_STYLUS2,
339};
340
341
342
343
344
345
346static const int macroKeyEvents[] = {
347 KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
348 KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
349 KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
350 KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
351 KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
352 KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
353};
354
355
356
357
358
359#define AIPTEK_INVALID_VALUE -1
360
361struct aiptek_map {
362 const char *string;
363 int value;
364};
365
366static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
367{
368 const struct aiptek_map *p;
369
370 if (str[count - 1] == '\n')
371 count--;
372
373 for (p = map; p->string; p++)
374 if (!strncmp(str, p->string, count))
375 return p->value;
376
377 return AIPTEK_INVALID_VALUE;
378}
379
380static const char *map_val_to_str(const struct aiptek_map *map, int val)
381{
382 const struct aiptek_map *p;
383
384 for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
385 if (val == p->value)
386 return p->string;
387
388 return "unknown";
389}
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425static void aiptek_irq(struct urb *urb)
426{
427 struct aiptek *aiptek = urb->context;
428 unsigned char *data = aiptek->data;
429 struct input_dev *inputdev = aiptek->inputdev;
430 struct usb_interface *intf = aiptek->intf;
431 int jitterable = 0;
432 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
433
434 switch (urb->status) {
435 case 0:
436
437 break;
438
439 case -ECONNRESET:
440 case -ENOENT:
441 case -ESHUTDOWN:
442
443 dev_dbg(&intf->dev, "%s - urb shutting down with status: %d\n",
444 __func__, urb->status);
445 return;
446
447 default:
448 dev_dbg(&intf->dev, "%s - nonzero urb status received: %d\n",
449 __func__, urb->status);
450 goto exit;
451 }
452
453
454
455 if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
456 goto exit;
457 }
458
459 aiptek->inDelay = 0;
460 aiptek->eventCount++;
461
462
463
464
465
466 if (data[0] == 1) {
467 if (aiptek->curSetting.coordinateMode ==
468 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
469 aiptek->diagnostic =
470 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
471 } else {
472 x = (signed char) data[2];
473 y = (signed char) data[3];
474
475
476
477
478
479
480
481
482 jitterable = data[1] & 0x07;
483
484 left = (data[1] & aiptek->curSetting.mouseButtonLeft >> 2) != 0 ? 1 : 0;
485 right = (data[1] & aiptek->curSetting.mouseButtonRight >> 2) != 0 ? 1 : 0;
486 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle >> 2) != 0 ? 1 : 0;
487
488 input_report_key(inputdev, BTN_LEFT, left);
489 input_report_key(inputdev, BTN_MIDDLE, middle);
490 input_report_key(inputdev, BTN_RIGHT, right);
491
492 input_report_abs(inputdev, ABS_MISC,
493 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
494 input_report_rel(inputdev, REL_X, x);
495 input_report_rel(inputdev, REL_Y, y);
496
497
498
499
500 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
501 input_report_rel(inputdev, REL_WHEEL,
502 aiptek->curSetting.wheel);
503 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
504 }
505 if (aiptek->lastMacro != -1) {
506 input_report_key(inputdev,
507 macroKeyEvents[aiptek->lastMacro], 0);
508 aiptek->lastMacro = -1;
509 }
510 input_sync(inputdev);
511 }
512 }
513
514
515
516 else if (data[0] == 2) {
517 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
518 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
519 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
520 (aiptek->curSetting.pointerMode)) {
521 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
522 } else {
523 x = get_unaligned_le16(data + 1);
524 y = get_unaligned_le16(data + 3);
525 z = get_unaligned_le16(data + 6);
526
527 dv = (data[5] & 0x01) != 0 ? 1 : 0;
528 p = (data[5] & 0x02) != 0 ? 1 : 0;
529 tip = (data[5] & 0x04) != 0 ? 1 : 0;
530
531
532
533 jitterable = data[5] & 0x18;
534
535 bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
536 pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
537
538
539
540
541
542 if (dv != 0) {
543
544
545
546 if (aiptek->previousToolMode !=
547 aiptek->curSetting.toolMode) {
548 input_report_key(inputdev,
549 aiptek->previousToolMode, 0);
550 input_report_key(inputdev,
551 aiptek->curSetting.toolMode,
552 1);
553 aiptek->previousToolMode =
554 aiptek->curSetting.toolMode;
555 }
556
557 if (p != 0) {
558 input_report_abs(inputdev, ABS_X, x);
559 input_report_abs(inputdev, ABS_Y, y);
560 input_report_abs(inputdev, ABS_PRESSURE, z);
561
562 input_report_key(inputdev, BTN_TOUCH, tip);
563 input_report_key(inputdev, BTN_STYLUS, bs);
564 input_report_key(inputdev, BTN_STYLUS2, pck);
565
566 if (aiptek->curSetting.xTilt !=
567 AIPTEK_TILT_DISABLE) {
568 input_report_abs(inputdev,
569 ABS_TILT_X,
570 aiptek->curSetting.xTilt);
571 }
572 if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
573 input_report_abs(inputdev,
574 ABS_TILT_Y,
575 aiptek->curSetting.yTilt);
576 }
577
578
579
580
581 if (aiptek->curSetting.wheel !=
582 AIPTEK_WHEEL_DISABLE) {
583 input_report_abs(inputdev,
584 ABS_WHEEL,
585 aiptek->curSetting.wheel);
586 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
587 }
588 }
589 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
590 if (aiptek->lastMacro != -1) {
591 input_report_key(inputdev,
592 macroKeyEvents[aiptek->lastMacro], 0);
593 aiptek->lastMacro = -1;
594 }
595 input_sync(inputdev);
596 }
597 }
598 }
599
600
601 else if (data[0] == 3) {
602 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
603 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
604 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
605 (aiptek->curSetting.pointerMode)) {
606 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
607 } else {
608 x = get_unaligned_le16(data + 1);
609 y = get_unaligned_le16(data + 3);
610
611 jitterable = data[5] & 0x1c;
612
613 dv = (data[5] & 0x01) != 0 ? 1 : 0;
614 p = (data[5] & 0x02) != 0 ? 1 : 0;
615 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
616 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
617 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
618
619 if (dv != 0) {
620
621
622
623 if (aiptek->previousToolMode !=
624 aiptek->curSetting.toolMode) {
625 input_report_key(inputdev,
626 aiptek->previousToolMode, 0);
627 input_report_key(inputdev,
628 aiptek->curSetting.toolMode,
629 1);
630 aiptek->previousToolMode =
631 aiptek->curSetting.toolMode;
632 }
633
634 if (p != 0) {
635 input_report_abs(inputdev, ABS_X, x);
636 input_report_abs(inputdev, ABS_Y, y);
637
638 input_report_key(inputdev, BTN_LEFT, left);
639 input_report_key(inputdev, BTN_MIDDLE, middle);
640 input_report_key(inputdev, BTN_RIGHT, right);
641
642
643
644
645 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
646 input_report_abs(inputdev,
647 ABS_WHEEL,
648 aiptek->curSetting.wheel);
649 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
650 }
651 }
652 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
653 if (aiptek->lastMacro != -1) {
654 input_report_key(inputdev,
655 macroKeyEvents[aiptek->lastMacro], 0);
656 aiptek->lastMacro = -1;
657 }
658 input_sync(inputdev);
659 }
660 }
661 }
662
663
664 else if (data[0] == 4) {
665 jitterable = data[1] & 0x18;
666
667 dv = (data[1] & 0x01) != 0 ? 1 : 0;
668 p = (data[1] & 0x02) != 0 ? 1 : 0;
669 tip = (data[1] & 0x04) != 0 ? 1 : 0;
670 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
671 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
672
673 macro = dv && p && tip && !(data[3] & 1) ? (data[3] >> 1) : -1;
674 z = get_unaligned_le16(data + 4);
675
676 if (dv) {
677
678
679
680 if (aiptek->previousToolMode !=
681 aiptek->curSetting.toolMode) {
682 input_report_key(inputdev,
683 aiptek->previousToolMode, 0);
684 input_report_key(inputdev,
685 aiptek->curSetting.toolMode,
686 1);
687 aiptek->previousToolMode =
688 aiptek->curSetting.toolMode;
689 }
690 }
691
692 if (aiptek->lastMacro != -1 && aiptek->lastMacro != macro) {
693 input_report_key(inputdev, macroKeyEvents[aiptek->lastMacro], 0);
694 aiptek->lastMacro = -1;
695 }
696
697 if (macro != -1 && macro != aiptek->lastMacro) {
698 input_report_key(inputdev, macroKeyEvents[macro], 1);
699 aiptek->lastMacro = macro;
700 }
701 input_report_abs(inputdev, ABS_MISC,
702 p | AIPTEK_REPORT_TOOL_STYLUS);
703 input_sync(inputdev);
704 }
705
706
707 else if (data[0] == 5) {
708 jitterable = data[1] & 0x1c;
709
710 dv = (data[1] & 0x01) != 0 ? 1 : 0;
711 p = (data[1] & 0x02) != 0 ? 1 : 0;
712 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
713 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
714 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
715 macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : 0;
716
717 if (dv) {
718
719
720
721 if (aiptek->previousToolMode !=
722 aiptek->curSetting.toolMode) {
723 input_report_key(inputdev,
724 aiptek->previousToolMode, 0);
725 input_report_key(inputdev,
726 aiptek->curSetting.toolMode, 1);
727 aiptek->previousToolMode = aiptek->curSetting.toolMode;
728 }
729 }
730
731 if (aiptek->lastMacro != -1 && aiptek->lastMacro != macro) {
732 input_report_key(inputdev, macroKeyEvents[aiptek->lastMacro], 0);
733 aiptek->lastMacro = -1;
734 }
735
736 if (macro != -1 && macro != aiptek->lastMacro) {
737 input_report_key(inputdev, macroKeyEvents[macro], 1);
738 aiptek->lastMacro = macro;
739 }
740
741 input_report_abs(inputdev, ABS_MISC,
742 p | AIPTEK_REPORT_TOOL_MOUSE);
743 input_sync(inputdev);
744 }
745
746
747
748
749
750
751 else if (data[0] == 6) {
752 macro = get_unaligned_le16(data + 1);
753 if (macro > 0) {
754 input_report_key(inputdev, macroKeyEvents[macro - 1],
755 0);
756 }
757 if (macro < 25) {
758 input_report_key(inputdev, macroKeyEvents[macro + 1],
759 0);
760 }
761
762
763
764
765 if (aiptek->previousToolMode !=
766 aiptek->curSetting.toolMode) {
767 input_report_key(inputdev,
768 aiptek->previousToolMode, 0);
769 input_report_key(inputdev,
770 aiptek->curSetting.toolMode,
771 1);
772 aiptek->previousToolMode =
773 aiptek->curSetting.toolMode;
774 }
775
776 input_report_key(inputdev, macroKeyEvents[macro], 1);
777 input_report_abs(inputdev, ABS_MISC,
778 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
779 input_sync(inputdev);
780 } else {
781 dev_dbg(&intf->dev, "Unknown report %d\n", data[0]);
782 }
783
784
785
786
787
788
789
790
791
792
793
794
795
796 if (aiptek->previousJitterable != jitterable &&
797 aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
798 aiptek->endDelay = jiffies +
799 ((aiptek->curSetting.jitterDelay * HZ) / 1000);
800 aiptek->inDelay = 1;
801 }
802 aiptek->previousJitterable = jitterable;
803
804exit:
805 retval = usb_submit_urb(urb, GFP_ATOMIC);
806 if (retval != 0) {
807 dev_err(&intf->dev,
808 "%s - usb_submit_urb failed with result %d\n",
809 __func__, retval);
810 }
811}
812
813
814
815
816
817
818
819
820
821static const struct usb_device_id aiptek_ids[] = {
822 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
823 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
824 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
825 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
826 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
827 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
828 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
829 {USB_DEVICE(USB_VENDOR_ID_KYE, 0x5003)},
830 {}
831};
832
833MODULE_DEVICE_TABLE(usb, aiptek_ids);
834
835
836
837
838static int aiptek_open(struct input_dev *inputdev)
839{
840 struct aiptek *aiptek = input_get_drvdata(inputdev);
841
842 aiptek->urb->dev = interface_to_usbdev(aiptek->intf);
843 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
844 return -EIO;
845
846 return 0;
847}
848
849
850
851
852static void aiptek_close(struct input_dev *inputdev)
853{
854 struct aiptek *aiptek = input_get_drvdata(inputdev);
855
856 usb_kill_urb(aiptek->urb);
857}
858
859
860
861
862
863static int
864aiptek_set_report(struct aiptek *aiptek,
865 unsigned char report_type,
866 unsigned char report_id, void *buffer, int size)
867{
868 struct usb_device *udev = interface_to_usbdev(aiptek->intf);
869
870 return usb_control_msg(udev,
871 usb_sndctrlpipe(udev, 0),
872 USB_REQ_SET_REPORT,
873 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
874 USB_DIR_OUT, (report_type << 8) + report_id,
875 aiptek->ifnum, buffer, size, 5000);
876}
877
878static int
879aiptek_get_report(struct aiptek *aiptek,
880 unsigned char report_type,
881 unsigned char report_id, void *buffer, int size)
882{
883 struct usb_device *udev = interface_to_usbdev(aiptek->intf);
884
885 return usb_control_msg(udev,
886 usb_rcvctrlpipe(udev, 0),
887 USB_REQ_GET_REPORT,
888 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
889 USB_DIR_IN, (report_type << 8) + report_id,
890 aiptek->ifnum, buffer, size, 5000);
891}
892
893
894
895
896static int
897aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
898{
899 const int sizeof_buf = 3 * sizeof(u8);
900 int ret;
901 u8 *buf;
902
903 buf = kmalloc(sizeof_buf, GFP_KERNEL);
904 if (!buf)
905 return -ENOMEM;
906
907 buf[0] = 2;
908 buf[1] = command;
909 buf[2] = data;
910
911 if ((ret =
912 aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
913 dev_dbg(&aiptek->intf->dev,
914 "aiptek_program: failed, tried to send: 0x%02x 0x%02x\n",
915 command, data);
916 }
917 kfree(buf);
918 return ret < 0 ? ret : 0;
919}
920
921
922
923
924
925
926static int
927aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
928{
929 const int sizeof_buf = 3 * sizeof(u8);
930 int ret;
931 u8 *buf;
932
933 buf = kmalloc(sizeof_buf, GFP_KERNEL);
934 if (!buf)
935 return -ENOMEM;
936
937 buf[0] = 2;
938 buf[1] = command;
939 buf[2] = data;
940
941 if (aiptek_command(aiptek, command, data) != 0) {
942 kfree(buf);
943 return -EIO;
944 }
945 msleep(aiptek->curSetting.programmableDelay);
946
947 if ((ret =
948 aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
949 dev_dbg(&aiptek->intf->dev,
950 "aiptek_query failed: returned 0x%02x 0x%02x 0x%02x\n",
951 buf[0], buf[1], buf[2]);
952 ret = -EIO;
953 } else {
954 ret = get_unaligned_le16(buf + 1);
955 }
956 kfree(buf);
957 return ret;
958}
959
960
961
962
963
964static int aiptek_program_tablet(struct aiptek *aiptek)
965{
966 int ret;
967
968 if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
969 return ret;
970
971
972 if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
973 return ret;
974 aiptek->features.modelCode = ret & 0xff;
975
976
977 if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
978 return ret;
979 aiptek->features.odmCode = ret;
980
981
982 if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
983 return ret;
984 aiptek->features.firmwareCode = ret;
985
986
987 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
988 return ret;
989 input_set_abs_params(aiptek->inputdev, ABS_X, 0, ret - 1, 0, 0);
990
991
992 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
993 return ret;
994 input_set_abs_params(aiptek->inputdev, ABS_Y, 0, ret - 1, 0, 0);
995
996
997 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
998 return ret;
999 input_set_abs_params(aiptek->inputdev, ABS_PRESSURE, 0, ret - 1, 0, 0);
1000
1001
1002
1003
1004 if (aiptek->curSetting.coordinateMode ==
1005 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
1006
1007 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
1008 return ret;
1009 }
1010 } else {
1011
1012 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
1013 return ret;
1014 }
1015 }
1016
1017
1018 if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
1019 return ret;
1020#if 0
1021
1022 if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
1023 return ret;
1024#endif
1025
1026
1027 if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
1028 return ret;
1029
1030
1031
1032 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
1033 aiptek->eventCount = 0;
1034
1035 return 0;
1036}
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
1049{
1050 struct aiptek *aiptek = dev_get_drvdata(dev);
1051
1052 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1053 input_abs_get_max(aiptek->inputdev, ABS_X) + 1,
1054 input_abs_get_max(aiptek->inputdev, ABS_Y) + 1);
1055}
1056
1057
1058
1059
1060
1061
1062
1063static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1064
1065
1066
1067
1068
1069static struct aiptek_map pointer_mode_map[] = {
1070 { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
1071 { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
1072 { "either", AIPTEK_POINTER_EITHER_MODE },
1073 { NULL, AIPTEK_INVALID_VALUE }
1074};
1075
1076static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
1077{
1078 struct aiptek *aiptek = dev_get_drvdata(dev);
1079
1080 return snprintf(buf, PAGE_SIZE, "%s\n",
1081 map_val_to_str(pointer_mode_map,
1082 aiptek->curSetting.pointerMode));
1083}
1084
1085static ssize_t
1086store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1087{
1088 struct aiptek *aiptek = dev_get_drvdata(dev);
1089 int new_mode = map_str_to_val(pointer_mode_map, buf, count);
1090
1091 if (new_mode == AIPTEK_INVALID_VALUE)
1092 return -EINVAL;
1093
1094 aiptek->newSetting.pointerMode = new_mode;
1095 return count;
1096}
1097
1098static DEVICE_ATTR(pointer_mode,
1099 S_IRUGO | S_IWUSR,
1100 show_tabletPointerMode, store_tabletPointerMode);
1101
1102
1103
1104
1105
1106
1107static struct aiptek_map coordinate_mode_map[] = {
1108 { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
1109 { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
1110 { NULL, AIPTEK_INVALID_VALUE }
1111};
1112
1113static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
1114{
1115 struct aiptek *aiptek = dev_get_drvdata(dev);
1116
1117 return snprintf(buf, PAGE_SIZE, "%s\n",
1118 map_val_to_str(coordinate_mode_map,
1119 aiptek->curSetting.coordinateMode));
1120}
1121
1122static ssize_t
1123store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1124{
1125 struct aiptek *aiptek = dev_get_drvdata(dev);
1126 int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
1127
1128 if (new_mode == AIPTEK_INVALID_VALUE)
1129 return -EINVAL;
1130
1131 aiptek->newSetting.coordinateMode = new_mode;
1132 return count;
1133}
1134
1135static DEVICE_ATTR(coordinate_mode,
1136 S_IRUGO | S_IWUSR,
1137 show_tabletCoordinateMode, store_tabletCoordinateMode);
1138
1139
1140
1141
1142
1143
1144static struct aiptek_map tool_mode_map[] = {
1145 { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
1146 { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
1147 { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
1148 { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
1149 { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
1150 { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
1151 { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
1152 { NULL, AIPTEK_INVALID_VALUE }
1153};
1154
1155static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
1156{
1157 struct aiptek *aiptek = dev_get_drvdata(dev);
1158
1159 return snprintf(buf, PAGE_SIZE, "%s\n",
1160 map_val_to_str(tool_mode_map,
1161 aiptek->curSetting.toolMode));
1162}
1163
1164static ssize_t
1165store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1166{
1167 struct aiptek *aiptek = dev_get_drvdata(dev);
1168 int new_mode = map_str_to_val(tool_mode_map, buf, count);
1169
1170 if (new_mode == AIPTEK_INVALID_VALUE)
1171 return -EINVAL;
1172
1173 aiptek->newSetting.toolMode = new_mode;
1174 return count;
1175}
1176
1177static DEVICE_ATTR(tool_mode,
1178 S_IRUGO | S_IWUSR,
1179 show_tabletToolMode, store_tabletToolMode);
1180
1181
1182
1183
1184
1185static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
1186{
1187 struct aiptek *aiptek = dev_get_drvdata(dev);
1188
1189 if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1190 return snprintf(buf, PAGE_SIZE, "disable\n");
1191 } else {
1192 return snprintf(buf, PAGE_SIZE, "%d\n",
1193 aiptek->curSetting.xTilt);
1194 }
1195}
1196
1197static ssize_t
1198store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1199{
1200 struct aiptek *aiptek = dev_get_drvdata(dev);
1201 int x;
1202
1203 if (kstrtoint(buf, 10, &x)) {
1204 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1205
1206 if (strncmp(buf, "disable", len))
1207 return -EINVAL;
1208
1209 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1210 } else {
1211 if (x < AIPTEK_TILT_MIN || x > AIPTEK_TILT_MAX)
1212 return -EINVAL;
1213
1214 aiptek->newSetting.xTilt = x;
1215 }
1216
1217 return count;
1218}
1219
1220static DEVICE_ATTR(xtilt,
1221 S_IRUGO | S_IWUSR, show_tabletXtilt, store_tabletXtilt);
1222
1223
1224
1225
1226
1227static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
1228{
1229 struct aiptek *aiptek = dev_get_drvdata(dev);
1230
1231 if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1232 return snprintf(buf, PAGE_SIZE, "disable\n");
1233 } else {
1234 return snprintf(buf, PAGE_SIZE, "%d\n",
1235 aiptek->curSetting.yTilt);
1236 }
1237}
1238
1239static ssize_t
1240store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1241{
1242 struct aiptek *aiptek = dev_get_drvdata(dev);
1243 int y;
1244
1245 if (kstrtoint(buf, 10, &y)) {
1246 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1247
1248 if (strncmp(buf, "disable", len))
1249 return -EINVAL;
1250
1251 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1252 } else {
1253 if (y < AIPTEK_TILT_MIN || y > AIPTEK_TILT_MAX)
1254 return -EINVAL;
1255
1256 aiptek->newSetting.yTilt = y;
1257 }
1258
1259 return count;
1260}
1261
1262static DEVICE_ATTR(ytilt,
1263 S_IRUGO | S_IWUSR, show_tabletYtilt, store_tabletYtilt);
1264
1265
1266
1267
1268
1269static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
1270{
1271 struct aiptek *aiptek = dev_get_drvdata(dev);
1272
1273 return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1274}
1275
1276static ssize_t
1277store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1278{
1279 struct aiptek *aiptek = dev_get_drvdata(dev);
1280 int err, j;
1281
1282 err = kstrtoint(buf, 10, &j);
1283 if (err)
1284 return err;
1285
1286 aiptek->newSetting.jitterDelay = j;
1287 return count;
1288}
1289
1290static DEVICE_ATTR(jitter,
1291 S_IRUGO | S_IWUSR,
1292 show_tabletJitterDelay, store_tabletJitterDelay);
1293
1294
1295
1296
1297
1298static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
1299{
1300 struct aiptek *aiptek = dev_get_drvdata(dev);
1301
1302 return snprintf(buf, PAGE_SIZE, "%d\n",
1303 aiptek->curSetting.programmableDelay);
1304}
1305
1306static ssize_t
1307store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1308{
1309 struct aiptek *aiptek = dev_get_drvdata(dev);
1310 int err, d;
1311
1312 err = kstrtoint(buf, 10, &d);
1313 if (err)
1314 return err;
1315
1316 aiptek->newSetting.programmableDelay = d;
1317 return count;
1318}
1319
1320static DEVICE_ATTR(delay,
1321 S_IRUGO | S_IWUSR,
1322 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1323
1324
1325
1326
1327
1328static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
1329{
1330 struct aiptek *aiptek = dev_get_drvdata(dev);
1331
1332 return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1333}
1334
1335static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1336
1337
1338
1339
1340
1341static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
1342{
1343 struct aiptek *aiptek = dev_get_drvdata(dev);
1344 char *retMsg;
1345
1346 switch (aiptek->diagnostic) {
1347 case AIPTEK_DIAGNOSTIC_NA:
1348 retMsg = "no errors\n";
1349 break;
1350
1351 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1352 retMsg = "Error: receiving relative reports\n";
1353 break;
1354
1355 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1356 retMsg = "Error: receiving absolute reports\n";
1357 break;
1358
1359 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1360 if (aiptek->curSetting.pointerMode ==
1361 AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1362 retMsg = "Error: receiving stylus reports\n";
1363 } else {
1364 retMsg = "Error: receiving mouse reports\n";
1365 }
1366 break;
1367
1368 default:
1369 return 0;
1370 }
1371 return snprintf(buf, PAGE_SIZE, retMsg);
1372}
1373
1374static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1375
1376
1377
1378
1379
1380
1381static struct aiptek_map stylus_button_map[] = {
1382 { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
1383 { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
1384 { NULL, AIPTEK_INVALID_VALUE }
1385};
1386
1387static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
1388{
1389 struct aiptek *aiptek = dev_get_drvdata(dev);
1390
1391 return snprintf(buf, PAGE_SIZE, "%s\n",
1392 map_val_to_str(stylus_button_map,
1393 aiptek->curSetting.stylusButtonUpper));
1394}
1395
1396static ssize_t
1397store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1398{
1399 struct aiptek *aiptek = dev_get_drvdata(dev);
1400 int new_button = map_str_to_val(stylus_button_map, buf, count);
1401
1402 if (new_button == AIPTEK_INVALID_VALUE)
1403 return -EINVAL;
1404
1405 aiptek->newSetting.stylusButtonUpper = new_button;
1406 return count;
1407}
1408
1409static DEVICE_ATTR(stylus_upper,
1410 S_IRUGO | S_IWUSR,
1411 show_tabletStylusUpper, store_tabletStylusUpper);
1412
1413
1414
1415
1416
1417
1418static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
1419{
1420 struct aiptek *aiptek = dev_get_drvdata(dev);
1421
1422 return snprintf(buf, PAGE_SIZE, "%s\n",
1423 map_val_to_str(stylus_button_map,
1424 aiptek->curSetting.stylusButtonLower));
1425}
1426
1427static ssize_t
1428store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1429{
1430 struct aiptek *aiptek = dev_get_drvdata(dev);
1431 int new_button = map_str_to_val(stylus_button_map, buf, count);
1432
1433 if (new_button == AIPTEK_INVALID_VALUE)
1434 return -EINVAL;
1435
1436 aiptek->newSetting.stylusButtonLower = new_button;
1437 return count;
1438}
1439
1440static DEVICE_ATTR(stylus_lower,
1441 S_IRUGO | S_IWUSR,
1442 show_tabletStylusLower, store_tabletStylusLower);
1443
1444
1445
1446
1447
1448
1449static struct aiptek_map mouse_button_map[] = {
1450 { "left", AIPTEK_MOUSE_LEFT_BUTTON },
1451 { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
1452 { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
1453 { NULL, AIPTEK_INVALID_VALUE }
1454};
1455
1456static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
1457{
1458 struct aiptek *aiptek = dev_get_drvdata(dev);
1459
1460 return snprintf(buf, PAGE_SIZE, "%s\n",
1461 map_val_to_str(mouse_button_map,
1462 aiptek->curSetting.mouseButtonLeft));
1463}
1464
1465static ssize_t
1466store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1467{
1468 struct aiptek *aiptek = dev_get_drvdata(dev);
1469 int new_button = map_str_to_val(mouse_button_map, buf, count);
1470
1471 if (new_button == AIPTEK_INVALID_VALUE)
1472 return -EINVAL;
1473
1474 aiptek->newSetting.mouseButtonLeft = new_button;
1475 return count;
1476}
1477
1478static DEVICE_ATTR(mouse_left,
1479 S_IRUGO | S_IWUSR,
1480 show_tabletMouseLeft, store_tabletMouseLeft);
1481
1482
1483
1484
1485
1486static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
1487{
1488 struct aiptek *aiptek = dev_get_drvdata(dev);
1489
1490 return snprintf(buf, PAGE_SIZE, "%s\n",
1491 map_val_to_str(mouse_button_map,
1492 aiptek->curSetting.mouseButtonMiddle));
1493}
1494
1495static ssize_t
1496store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1497{
1498 struct aiptek *aiptek = dev_get_drvdata(dev);
1499 int new_button = map_str_to_val(mouse_button_map, buf, count);
1500
1501 if (new_button == AIPTEK_INVALID_VALUE)
1502 return -EINVAL;
1503
1504 aiptek->newSetting.mouseButtonMiddle = new_button;
1505 return count;
1506}
1507
1508static DEVICE_ATTR(mouse_middle,
1509 S_IRUGO | S_IWUSR,
1510 show_tabletMouseMiddle, store_tabletMouseMiddle);
1511
1512
1513
1514
1515
1516static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
1517{
1518 struct aiptek *aiptek = dev_get_drvdata(dev);
1519
1520 return snprintf(buf, PAGE_SIZE, "%s\n",
1521 map_val_to_str(mouse_button_map,
1522 aiptek->curSetting.mouseButtonRight));
1523}
1524
1525static ssize_t
1526store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1527{
1528 struct aiptek *aiptek = dev_get_drvdata(dev);
1529 int new_button = map_str_to_val(mouse_button_map, buf, count);
1530
1531 if (new_button == AIPTEK_INVALID_VALUE)
1532 return -EINVAL;
1533
1534 aiptek->newSetting.mouseButtonRight = new_button;
1535 return count;
1536}
1537
1538static DEVICE_ATTR(mouse_right,
1539 S_IRUGO | S_IWUSR,
1540 show_tabletMouseRight, store_tabletMouseRight);
1541
1542
1543
1544
1545
1546static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
1547{
1548 struct aiptek *aiptek = dev_get_drvdata(dev);
1549
1550 if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1551 return snprintf(buf, PAGE_SIZE, "disable\n");
1552 } else {
1553 return snprintf(buf, PAGE_SIZE, "%d\n",
1554 aiptek->curSetting.wheel);
1555 }
1556}
1557
1558static ssize_t
1559store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1560{
1561 struct aiptek *aiptek = dev_get_drvdata(dev);
1562 int err, w;
1563
1564 err = kstrtoint(buf, 10, &w);
1565 if (err)
1566 return err;
1567
1568 aiptek->newSetting.wheel = w;
1569 return count;
1570}
1571
1572static DEVICE_ATTR(wheel,
1573 S_IRUGO | S_IWUSR, show_tabletWheel, store_tabletWheel);
1574
1575
1576
1577
1578
1579static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
1580{
1581
1582
1583
1584 return snprintf(buf, PAGE_SIZE,
1585 "Write anything to this file to program your tablet.\n");
1586}
1587
1588static ssize_t
1589store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1590{
1591 struct aiptek *aiptek = dev_get_drvdata(dev);
1592
1593
1594
1595
1596 memcpy(&aiptek->curSetting, &aiptek->newSetting,
1597 sizeof(struct aiptek_settings));
1598
1599 if (aiptek_program_tablet(aiptek) < 0)
1600 return -EIO;
1601
1602 return count;
1603}
1604
1605static DEVICE_ATTR(execute,
1606 S_IRUGO | S_IWUSR, show_tabletExecute, store_tabletExecute);
1607
1608
1609
1610
1611
1612static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
1613{
1614 struct aiptek *aiptek = dev_get_drvdata(dev);
1615
1616 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1617}
1618
1619static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1620
1621
1622
1623
1624
1625static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
1626{
1627 struct aiptek *aiptek = dev_get_drvdata(dev);
1628
1629 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1630}
1631
1632static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1633
1634
1635
1636
1637
1638static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
1639{
1640 struct aiptek *aiptek = dev_get_drvdata(dev);
1641
1642 return snprintf(buf, PAGE_SIZE, "%04x\n",
1643 aiptek->features.firmwareCode);
1644}
1645
1646static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1647
1648static struct attribute *aiptek_attributes[] = {
1649 &dev_attr_size.attr,
1650 &dev_attr_pointer_mode.attr,
1651 &dev_attr_coordinate_mode.attr,
1652 &dev_attr_tool_mode.attr,
1653 &dev_attr_xtilt.attr,
1654 &dev_attr_ytilt.attr,
1655 &dev_attr_jitter.attr,
1656 &dev_attr_delay.attr,
1657 &dev_attr_event_count.attr,
1658 &dev_attr_diagnostic.attr,
1659 &dev_attr_odm_code.attr,
1660 &dev_attr_model_code.attr,
1661 &dev_attr_firmware_code.attr,
1662 &dev_attr_stylus_lower.attr,
1663 &dev_attr_stylus_upper.attr,
1664 &dev_attr_mouse_left.attr,
1665 &dev_attr_mouse_middle.attr,
1666 &dev_attr_mouse_right.attr,
1667 &dev_attr_wheel.attr,
1668 &dev_attr_execute.attr,
1669 NULL
1670};
1671
1672static const struct attribute_group aiptek_attribute_group = {
1673 .attrs = aiptek_attributes,
1674};
1675
1676
1677
1678
1679
1680static int
1681aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1682{
1683 struct usb_device *usbdev = interface_to_usbdev(intf);
1684 struct usb_endpoint_descriptor *endpoint;
1685 struct aiptek *aiptek;
1686 struct input_dev *inputdev;
1687 int i;
1688 int speeds[] = { 0,
1689 AIPTEK_PROGRAMMABLE_DELAY_50,
1690 AIPTEK_PROGRAMMABLE_DELAY_400,
1691 AIPTEK_PROGRAMMABLE_DELAY_25,
1692 AIPTEK_PROGRAMMABLE_DELAY_100,
1693 AIPTEK_PROGRAMMABLE_DELAY_200,
1694 AIPTEK_PROGRAMMABLE_DELAY_300
1695 };
1696 int err = -ENOMEM;
1697
1698
1699
1700
1701
1702
1703
1704 speeds[0] = programmableDelay;
1705
1706 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
1707 inputdev = input_allocate_device();
1708 if (!aiptek || !inputdev) {
1709 dev_warn(&intf->dev,
1710 "cannot allocate memory or input device\n");
1711 goto fail1;
1712 }
1713
1714 aiptek->data = usb_alloc_coherent(usbdev, AIPTEK_PACKET_LENGTH,
1715 GFP_ATOMIC, &aiptek->data_dma);
1716 if (!aiptek->data) {
1717 dev_warn(&intf->dev, "cannot allocate usb buffer\n");
1718 goto fail1;
1719 }
1720
1721 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
1722 if (!aiptek->urb) {
1723 dev_warn(&intf->dev, "cannot allocate urb\n");
1724 goto fail2;
1725 }
1726
1727 aiptek->inputdev = inputdev;
1728 aiptek->intf = intf;
1729 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
1730 aiptek->inDelay = 0;
1731 aiptek->endDelay = 0;
1732 aiptek->previousJitterable = 0;
1733 aiptek->lastMacro = -1;
1734
1735
1736
1737
1738
1739
1740
1741 aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1742 aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
1743 aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1744 aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
1745 aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
1746 aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1747 aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
1748 aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1749 aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
1750 aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
1751 aiptek->curSetting.jitterDelay = jitterDelay;
1752 aiptek->curSetting.programmableDelay = programmableDelay;
1753
1754
1755
1756 aiptek->newSetting = aiptek->curSetting;
1757
1758
1759
1760
1761
1762
1763
1764
1765 usb_make_path(usbdev, aiptek->features.usbPath,
1766 sizeof(aiptek->features.usbPath));
1767 strlcat(aiptek->features.usbPath, "/input0",
1768 sizeof(aiptek->features.usbPath));
1769
1770
1771
1772
1773 inputdev->name = "Aiptek";
1774 inputdev->phys = aiptek->features.usbPath;
1775 usb_to_input_id(usbdev, &inputdev->id);
1776 inputdev->dev.parent = &intf->dev;
1777
1778 input_set_drvdata(inputdev, aiptek);
1779
1780 inputdev->open = aiptek_open;
1781 inputdev->close = aiptek_close;
1782
1783
1784
1785
1786 for (i = 0; i < ARRAY_SIZE(eventTypes); ++i)
1787 __set_bit(eventTypes[i], inputdev->evbit);
1788
1789 for (i = 0; i < ARRAY_SIZE(absEvents); ++i)
1790 __set_bit(absEvents[i], inputdev->absbit);
1791
1792 for (i = 0; i < ARRAY_SIZE(relEvents); ++i)
1793 __set_bit(relEvents[i], inputdev->relbit);
1794
1795 __set_bit(MSC_SERIAL, inputdev->mscbit);
1796
1797
1798 for (i = 0; i < ARRAY_SIZE(buttonEvents); ++i)
1799 __set_bit(buttonEvents[i], inputdev->keybit);
1800
1801 for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
1802 __set_bit(macroKeyEvents[i], inputdev->keybit);
1803
1804
1805
1806
1807
1808
1809
1810 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
1811 input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
1812 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
1813 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1814 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1815 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
1816
1817
1818 if (intf->altsetting[0].desc.bNumEndpoints < 1) {
1819 dev_err(&intf->dev,
1820 "interface has %d endpoints, but must have minimum 1\n",
1821 intf->altsetting[0].desc.bNumEndpoints);
1822 err = -EINVAL;
1823 goto fail3;
1824 }
1825 endpoint = &intf->altsetting[0].endpoint[0].desc;
1826
1827
1828
1829
1830 usb_fill_int_urb(aiptek->urb,
1831 usbdev,
1832 usb_rcvintpipe(usbdev,
1833 endpoint->bEndpointAddress),
1834 aiptek->data, 8, aiptek_irq, aiptek,
1835 endpoint->bInterval);
1836
1837 aiptek->urb->transfer_dma = aiptek->data_dma;
1838 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
1852 aiptek->curSetting.programmableDelay = speeds[i];
1853 (void)aiptek_program_tablet(aiptek);
1854 if (input_abs_get_max(aiptek->inputdev, ABS_X) > 0) {
1855 dev_info(&intf->dev,
1856 "Aiptek using %d ms programming speed\n",
1857 aiptek->curSetting.programmableDelay);
1858 break;
1859 }
1860 }
1861
1862
1863
1864 if (i == ARRAY_SIZE(speeds)) {
1865 dev_info(&intf->dev,
1866 "Aiptek tried all speeds, no sane response\n");
1867 err = -EINVAL;
1868 goto fail3;
1869 }
1870
1871
1872
1873 usb_set_intfdata(intf, aiptek);
1874
1875
1876
1877 err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
1878 if (err) {
1879 dev_warn(&intf->dev, "cannot create sysfs group err: %d\n",
1880 err);
1881 goto fail3;
1882 }
1883
1884
1885
1886 err = input_register_device(aiptek->inputdev);
1887 if (err) {
1888 dev_warn(&intf->dev,
1889 "input_register_device returned err: %d\n", err);
1890 goto fail4;
1891 }
1892 return 0;
1893
1894 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1895 fail3: usb_free_urb(aiptek->urb);
1896 fail2: usb_free_coherent(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
1897 aiptek->data_dma);
1898 fail1: usb_set_intfdata(intf, NULL);
1899 input_free_device(inputdev);
1900 kfree(aiptek);
1901 return err;
1902}
1903
1904
1905
1906
1907static void aiptek_disconnect(struct usb_interface *intf)
1908{
1909 struct aiptek *aiptek = usb_get_intfdata(intf);
1910
1911
1912
1913 usb_set_intfdata(intf, NULL);
1914 if (aiptek != NULL) {
1915
1916
1917 usb_kill_urb(aiptek->urb);
1918 input_unregister_device(aiptek->inputdev);
1919 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1920 usb_free_urb(aiptek->urb);
1921 usb_free_coherent(interface_to_usbdev(intf),
1922 AIPTEK_PACKET_LENGTH,
1923 aiptek->data, aiptek->data_dma);
1924 kfree(aiptek);
1925 }
1926}
1927
1928static struct usb_driver aiptek_driver = {
1929 .name = "aiptek",
1930 .probe = aiptek_probe,
1931 .disconnect = aiptek_disconnect,
1932 .id_table = aiptek_ids,
1933};
1934
1935module_usb_driver(aiptek_driver);
1936
1937MODULE_AUTHOR("Bryan W. Headley/Chris Atenasio/Cedric Brun/Rene van Paassen");
1938MODULE_DESCRIPTION("Aiptek HyperPen USB Tablet Driver");
1939MODULE_LICENSE("GPL");
1940
1941module_param(programmableDelay, int, 0);
1942MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
1943module_param(jitterDelay, int, 0);
1944MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
1945