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#include <linux/kernel.h>
57#include <linux/slab.h>
58#include <linux/input.h>
59#include <linux/module.h>
60#include <linux/init.h>
61#include <linux/usb.h>
62#include <linux/proc_fs.h>
63#include <asm/uaccess.h>
64
65
66
67
68#define DRIVER_VERSION "v1.0 Mar-8-2003"
69#define DRIVER_AUTHOR "Bryan W. Headley/Chris Atenasio"
70#define DRIVER_DESC "Aiptek HyperPen USB Tablet Driver (Linux 2.4.x)"
71
72MODULE_AUTHOR(DRIVER_AUTHOR);
73MODULE_DESCRIPTION(DRIVER_DESC);
74MODULE_LICENSE("GPL");
75
76
77
78
79
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338#define USB_VENDOR_ID_AIPTEK 0x08ca
339
340#define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
341#define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
342#define AIPTEK_POINTER_EITHER_MODE 2
343
344#define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
345 (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
346 a == AIPTEK_POINTER_EITHER_MODE)
347#define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
348 (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
349 a == AIPTEK_POINTER_EITHER_MODE)
350
351#define AIPTEK_COORDINATE_RELATIVE_MODE 0
352#define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
353
354#define AIPTEK_TILT_MIN (-128)
355#define AIPTEK_TILT_MAX 127
356#define AIPTEK_TILT_DISABLE (-10101)
357
358#define AIPTEK_TOOL_BUTTON_PEN_MODE 0
359#define AIPTEK_TOOL_BUTTON_PENCIL_MODE 1
360#define AIPTEK_TOOL_BUTTON_BRUSH_MODE 2
361#define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE 3
362#define AIPTEK_TOOL_BUTTON_RUBBER_MODE 4
363#define AIPTEK_TOOL_BUTTON_MOUSE_MODE 5
364
365#define AIPTEK_DIAGNOSTIC_NA 0
366#define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
367#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
368#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
369
370
371
372#define AIPTEK_JITTER_DELAY_DEFAULT 50
373
374struct aiptek_features {
375 char *name;
376 int pktlen;
377 int x_max;
378 int y_max;
379 int pressure_max;
380 int odmCode;
381 int modelCode;
382 int firmwareCode;
383 void (*irq) (struct urb * urb);
384};
385
386struct aiptek {
387 signed char data[10];
388 struct input_dev dev;
389 struct usb_device *usbdev;
390 struct urb *irq;
391 struct aiptek_features *features;
392 unsigned int ifnum;
393 int open_count;
394 int pointer_mode;
395 int coordinate_mode;
396 int tool_mode;
397 int xTilt;
398 int yTilt;
399 int diagnostic;
400 unsigned long eventCount;
401 int jitterDelay;
402#ifdef CONFIG_PROC_FS
403 struct proc_dir_entry *usbProcfsEntry;
404 struct proc_dir_entry *aiptekProcfsEntry;
405#endif
406};
407
408
409
410
411
412
413static int macroKeyEvents[] = { KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6,
414 KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,
415 KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18,
416 KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23, KEY_F24,
417 KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO, KEY_FRONT, KEY_COPY,
418 KEY_OPEN, KEY_PASTE, 0
419};
420
421#ifdef CONFIG_PROC_FS
422extern struct proc_dir_entry *proc_root_driver;
423#endif
424
425static int
426aiptek_convert_from_2s_complement(unsigned char c)
427{
428 unsigned char b = c;
429 int negate = 0;
430 int ret;
431
432 if (b & 0x80) {
433 b = ~b;
434 b--;
435 negate = 1;
436 }
437 ret = b;
438 ret = (negate == 1) ? -ret : ret;
439 return ret;
440}
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472static void
473aiptek_irq(struct urb *urb)
474{
475 struct aiptek *aiptek = urb->context;
476 unsigned char *data = aiptek->data;
477 struct input_dev *dev = &aiptek->dev;
478 int jitterable = 0;
479
480 if (urb->status)
481 return;
482
483 aiptek->eventCount++;
484
485
486
487 if (data[0] == 1) {
488 if (aiptek->coordinate_mode == AIPTEK_COORDINATE_ABSOLUTE_MODE) {
489 aiptek->diagnostic =
490 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
491 } else {
492 int x, y, left, right, middle;
493
494 if (aiptek->tool_mode != AIPTEK_TOOL_BUTTON_MOUSE_MODE) {
495 aiptek->tool_mode =
496 AIPTEK_TOOL_BUTTON_MOUSE_MODE;
497 input_report_key(dev, BTN_TOOL_MOUSE, 1);
498 }
499 x = aiptek_convert_from_2s_complement(data[2]);
500 y = aiptek_convert_from_2s_complement(data[3]);
501
502 left = data[5] & 0x01;
503 right = data[5] & 0x02;
504 middle = data[5] & 0x04;
505
506 jitterable = left | right | middle;
507
508 input_report_key(dev, BTN_LEFT, left);
509 input_report_key(dev, BTN_MIDDLE, middle);
510 input_report_key(dev, BTN_RIGHT, right);
511 input_report_rel(dev, REL_X, x);
512 input_report_rel(dev, REL_Y, y);
513 input_report_rel(dev, REL_MISC, 1);
514
515 input_event(dev, EV_MSC, MSC_SERIAL, 0);
516 }
517 }
518
519
520 else if (data[0] == 2) {
521 if (aiptek->coordinate_mode == AIPTEK_COORDINATE_RELATIVE_MODE) {
522 aiptek->diagnostic =
523 AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
524 } else
525 if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE(aiptek->pointer_mode))
526 {
527 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
528 } else {
529 int x = ((__u32) data[1]) | ((__u32) data[2] << 8);
530 int y = ((__u32) data[3]) | ((__u32) data[4] << 8);
531 int z = ((__u32) data[6]) | ((__u32) data[7] << 8);
532
533 int p = data[5] & 0x01;
534 int dv = data[5] & 0x02;
535 int tip = data[5] & 0x04;
536 int bs = data[5] & 0x08;
537 int pck = data[5] & 0x10;
538
539
540
541
542 if (dv != 0) {
543 switch (aiptek->tool_mode) {
544 case AIPTEK_TOOL_BUTTON_PEN_MODE:
545 {
546 input_report_key(dev,
547 BTN_TOOL_PEN,
548 1);
549 }
550 break;
551
552 case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
553 {
554 input_report_key(dev,
555 BTN_TOOL_PENCIL,
556 1);
557 }
558 break;
559
560 case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
561 {
562 input_report_key(dev,
563 BTN_TOOL_BRUSH,
564 1);
565 }
566 break;
567
568 case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
569 {
570 input_report_key(dev,
571 BTN_TOOL_AIRBRUSH,
572 1);
573 }
574 break;
575
576 case AIPTEK_TOOL_BUTTON_RUBBER_MODE:
577 {
578 input_report_key(dev,
579 BTN_TOOL_RUBBER,
580 1);
581 }
582 break;
583
584 case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
585 {
586 input_report_key(dev,
587 BTN_TOOL_MOUSE,
588 1);
589 }
590 break;
591 }
592
593 input_report_abs(dev, ABS_X, x);
594 input_report_abs(dev, ABS_Y, y);
595
596
597
598
599
600
601
602
603
604
605
606
607
608 if (aiptek->tool_mode ==
609 AIPTEK_TOOL_BUTTON_MOUSE_MODE) {
610 input_report_key(dev, BTN_LEFT, tip);
611 input_report_key(dev, BTN_RIGHT, bs);
612 input_report_key(dev, BTN_MIDDLE, pck);
613
614 jitterable = tip | bs | pck;
615 } else {
616 input_report_abs(dev, ABS_PRESSURE, z);
617
618 input_report_key(dev, BTN_TOUCH, tip);
619 input_report_key(dev, BTN_STYLUS, bs);
620 input_report_key(dev, BTN_STYLUS2, pck);
621
622 jitterable = tip | bs | pck;
623
624 if (aiptek->xTilt !=
625 AIPTEK_TILT_DISABLE)
626 input_report_abs(dev,
627 ABS_TILT_X,
628 aiptek->xTilt);
629 if (aiptek->yTilt !=
630 AIPTEK_TILT_DISABLE)
631 input_report_abs(dev,
632 ABS_TILT_Y,
633 aiptek->yTilt);
634 }
635 input_report_abs(dev, ABS_MISC, p);
636 input_event(dev, EV_MSC, MSC_SERIAL, 0);
637 }
638 }
639 }
640
641 else if (data[0] == 3) {
642 if (aiptek->coordinate_mode == AIPTEK_COORDINATE_RELATIVE_MODE) {
643 aiptek->diagnostic =
644 AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
645 } else
646 if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE(aiptek->pointer_mode))
647 {
648 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
649 } else {
650 int x = ((__u32) data[1]) | ((__u32) data[2] << 8);
651 int y = ((__u32) data[3]) | ((__u32) data[4] << 8);
652 int p = data[5] & 0x01;
653 int dv = data[5] & 0x02;
654 int left = data[5] & 0x04;
655 int right = data[5] & 0x08;
656 int middle = data[5] & 0x10;
657
658 if (dv != 0) {
659 input_report_key(dev, BTN_TOOL_MOUSE, 1);
660 input_report_abs(dev, ABS_X, x);
661 input_report_abs(dev, ABS_Y, y);
662
663 input_report_key(dev, BTN_LEFT, left);
664 input_report_key(dev, BTN_MIDDLE, middle);
665 input_report_key(dev, BTN_RIGHT, right);
666
667 jitterable = left | middle | right;
668
669 input_report_rel(dev, REL_MISC, p);
670 input_event(dev, EV_MSC, MSC_SERIAL, 0);
671 }
672 }
673 }
674
675 else if (data[0] == 4) {
676 int p = data[1] & 0x01;
677 int dv = data[1] & 0x02;
678 int tip = data[1] & 0x04;
679 int bs = data[1] & 0x08;
680 int pck = data[1] & 0x10;
681
682 int m = data[3];
683 int z = ((__u32) data[4]) | ((__u32) data[5] << 8);
684
685 if (dv != 0) {
686 input_report_key(dev, BTN_TOUCH, tip);
687 input_report_key(dev, BTN_STYLUS, bs);
688 input_report_key(dev, BTN_STYLUS2, pck);
689
690 jitterable = tip | bs | pck;
691
692 input_report_key(dev, macroKeyEvents[m - 1], 1);
693 input_report_abs(dev, ABS_PRESSURE, z);
694 input_report_abs(dev, ABS_MISC, p);
695 input_event(dev, EV_MSC, MSC_SERIAL, 0);
696 }
697 }
698
699 else if (data[0] == 5) {
700 int p = data[1] & 0x01;
701 int dv = data[1] & 0x02;
702 int left = data[1] & 0x04;
703 int right = data[1] & 0x08;
704 int middle = data[1] & 0x10;
705 int macro = data[3];
706
707 if (dv != 0) {
708 input_report_key(dev, BTN_LEFT, left);
709 input_report_key(dev, BTN_MIDDLE, middle);
710 input_report_key(dev, BTN_RIGHT, right);
711
712 jitterable = left | middle | right;
713
714 input_report_key(dev, macroKeyEvents[macro - 1], 1);
715 input_report_rel(dev, ABS_MISC, p);
716 input_event(dev, EV_MSC, MSC_SERIAL, 0);
717 }
718 }
719
720
721
722
723
724 else if (data[0] == 6) {
725 int macro = ((__u32) data[1]) | ((__u32) data[2] << 8);
726
727 input_report_key(dev, macroKeyEvents[macro - 1], 1);
728 input_report_abs(dev, ABS_MISC, 1);
729 input_event(dev, EV_MSC, MSC_SERIAL, 0);
730 } else {
731 dbg("Unknown report %d", data[0]);
732 }
733
734
735
736
737
738 if (jitterable != 0 && aiptek->jitterDelay != 0) {
739 wait_ms(aiptek->jitterDelay);
740 }
741}
742
743
744
745
746
747
748
749struct aiptek_features aiptek_features[] = {
750 {"Aiptek", 8, 0, 0, 0, 0, 0, 0, aiptek_irq},
751 {NULL, 0}
752};
753
754
755
756
757
758
759
760
761
762
763struct usb_device_id aiptek_ids[] = {
764 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01), driver_info:0},
765 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10), driver_info:0},
766 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20), driver_info:0},
767 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21), driver_info:0},
768 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22), driver_info:0},
769 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23), driver_info:0},
770 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24), driver_info:0},
771 {}
772};
773
774MODULE_DEVICE_TABLE(usb, aiptek_ids);
775
776static int
777aiptek_open(struct input_dev *dev)
778{
779 struct aiptek *aiptek = dev->private;
780 if (aiptek->open_count++)
781 return 0;
782
783 aiptek->irq->dev = aiptek->usbdev;
784 if (usb_submit_urb(aiptek->irq))
785 return -EIO;
786
787 return 0;
788}
789
790static void
791aiptek_close(struct input_dev *dev)
792{
793 struct aiptek *aiptek = dev->private;
794
795 if (!--aiptek->open_count)
796 usb_unlink_urb(aiptek->irq);
797}
798
799
800
801
802static void
803aiptek_command(struct usb_device *dev, unsigned int ifnum,
804 unsigned char command, unsigned char data)
805{
806 __u8 buf[3];
807
808 buf[0] = 2;
809 buf[1] = command;
810 buf[2] = data;
811
812 if (usb_set_report(dev, ifnum, 3, 2, buf, sizeof (buf)) != sizeof (buf)) {
813 dbg("aiptek_command failed, sending: 0x%02x 0x%02x", command,
814 data);
815 }
816}
817
818
819
820
821
822
823static unsigned int
824aiptek_query(struct usb_device *dev, unsigned int ifnum,
825 unsigned char command, unsigned char data)
826{
827 unsigned int ret;
828 __u8 buf[8];
829 buf[0] = 2;
830 buf[1] = command;
831 buf[2] = data;
832
833 aiptek_command(dev, ifnum, command, data);
834 wait_ms(400);
835
836 if (usb_get_report(dev, ifnum, 3, 2, buf, 3) < 3) {
837 dbg("aiptek_query failed: returns 0x%02x 0x%02x 0x%02x",
838 buf[0], buf[1], buf[2]);
839 return 0;
840 }
841 ret = ((__u32) buf[1]) | ((__u32) buf[2] << 8);
842 return ret;
843}
844
845
846
847
848
849
850static void
851aiptek_program_tablet(struct aiptek *aiptek)
852{
853 int modelCode, odmCode, firmwareCode;
854 int xResolution, yResolution, zResolution;
855
856 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
857
858
859 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x18, 0x04);
860
861 modelCode = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x02, 0x00);
862
863 odmCode = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x03, 0x00);
864
865 firmwareCode = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x04, 0x00);
866
867 xResolution = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x01, 0x00);
868
869 yResolution = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x01, 0x01);
870
871 zResolution = aiptek_query(aiptek->usbdev, aiptek->ifnum, 0x08, 0x00);
872
873
874
875 if (aiptek->coordinate_mode == AIPTEK_COORDINATE_ABSOLUTE_MODE) {
876
877 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x10, 0x01);
878 } else {
879
880 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x10, 0x00);
881 }
882
883 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x11, 0x02);
884
885 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x17, 0x00);
886
887 aiptek_command(aiptek->usbdev, aiptek->ifnum, 0x12, 0xff);
888
889 aiptek->features->odmCode = odmCode;
890 aiptek->features->modelCode = modelCode & 0xff;
891 aiptek->features->firmwareCode = firmwareCode;
892 aiptek->features->pressure_max = zResolution;
893 aiptek->features->x_max = xResolution;
894 aiptek->features->y_max = yResolution;
895
896 aiptek->eventCount = 0;
897}
898
899#if defined(CONFIG_PROC_FS)
900
901
902
903
904
905static void
906aiptek_procfs_parse(struct aiptek *aiptek, char *keyword, char *value)
907{
908 if (strcmp(keyword, "pointer") == 0) {
909 if (strcmp(value, "stylus") == 0) {
910 aiptek->pointer_mode = AIPTEK_POINTER_ONLY_STYLUS_MODE;
911 } else if (strcmp(value, "mouse") == 0) {
912 aiptek->pointer_mode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
913 } else if (strcmp(value, "either") == 0) {
914 aiptek->pointer_mode = AIPTEK_POINTER_EITHER_MODE;
915 }
916 } else if (strcmp(keyword, "coordinate") == 0) {
917 if (strcmp(value, "relative") == 0) {
918 aiptek->coordinate_mode =
919 AIPTEK_COORDINATE_RELATIVE_MODE;
920 } else if (strcmp(value, "absolute") == 0) {
921 aiptek->coordinate_mode =
922 AIPTEK_COORDINATE_ABSOLUTE_MODE;
923 }
924 } else if (strcmp(keyword, "xtilt") == 0) {
925 if (strcmp(value, "disable") == 0) {
926 aiptek->xTilt = AIPTEK_TILT_DISABLE;
927 } else {
928 int x = (int) simple_strtol(value, 0, 10);
929 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX)
930 aiptek->xTilt = x;
931 }
932 } else if (strcmp(keyword, "ytilt") == 0) {
933 if (strcmp(value, "disable") == 0) {
934 aiptek->yTilt = AIPTEK_TILT_DISABLE;
935 } else {
936 int y = (int) simple_strtol(value, 0, 10);
937 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX)
938 aiptek->yTilt = y;
939 }
940 } else if (strcmp(keyword, "jitter") == 0) {
941 aiptek->jitterDelay = (int) simple_strtol(value, 0, 10);
942 } else if (strcmp(keyword, "tool") == 0) {
943 if (strcmp(value, "mouse") == 0) {
944 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_MOUSE_MODE;
945 } else if (strcmp(value, "rubber") == 0) {
946 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_RUBBER_MODE;
947 } else if (strcmp(value, "pencil") == 0) {
948 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
949 } else if (strcmp(value, "pen") == 0) {
950 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_PEN_MODE;
951 } else if (strcmp(value, "brush") == 0) {
952 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
953 } else if (strcmp(value, "airbrush") == 0) {
954 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
955 }
956 }
957}
958
959
960
961
962
963
964static int
965aiptek_procfs_read(char *page, char **start, off_t offset, int count,
966 int *eof, void *data)
967{
968 int len;
969 char *out = page;
970 struct aiptek *aiptek = data;
971
972 out +=
973 sprintf(out, "Aiptek Tablet (%dx%d)\n",
974 aiptek->features->x_max, aiptek->features->y_max);
975
976 out +=
977 sprintf(out,
978 "(USB VendorID 0x%04x, ProductID 0x%04x, ODMCode 0x%04x\n",
979 aiptek->dev.idvendor, aiptek->dev.idproduct,
980 aiptek->features->odmCode);
981 out +=
982 sprintf(out, " ModelCode: 0x%02x, FirmwareCode: 0x%04x)\n",
983 aiptek->features->modelCode,
984 aiptek->features->firmwareCode);
985
986 out += sprintf(out, "on /dev/input/event%d\n", aiptek->dev.number);
987 out += sprintf(out, "pointer=%s\n",
988 (aiptek->pointer_mode == AIPTEK_POINTER_ONLY_MOUSE_MODE
989 ? "mouse"
990 : (aiptek->pointer_mode ==
991 AIPTEK_POINTER_ONLY_STYLUS_MODE ? "stylus" :
992 "either")));
993 out +=
994 sprintf(out, "coordinate=%s\n",
995 (aiptek->coordinate_mode ==
996 AIPTEK_COORDINATE_RELATIVE_MODE ? "relative" :
997 "absolute"));
998
999 out += sprintf(out, "tool=");
1000 switch (aiptek->tool_mode) {
1001 case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
1002 out += sprintf(out, "mouse\n");
1003 break;
1004
1005 case AIPTEK_TOOL_BUTTON_RUBBER_MODE:
1006 out += sprintf(out, "rubber\n");
1007 break;
1008
1009 case AIPTEK_TOOL_BUTTON_PEN_MODE:
1010 out += sprintf(out, "pen\n");
1011 break;
1012
1013 case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
1014 out += sprintf(out, "pencil\n");
1015 break;
1016
1017 case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
1018 out += sprintf(out, "brush\n");
1019 break;
1020
1021 case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
1022 out += sprintf(out, "airbrush\n");
1023 break;
1024 }
1025
1026 out += sprintf(out, "xtilt=");
1027 if (aiptek->xTilt == AIPTEK_TILT_DISABLE) {
1028 out += sprintf(out, "disable\n");
1029 } else {
1030 out += sprintf(out, "%d\n", aiptek->xTilt);
1031 }
1032
1033 out += sprintf(out, "ytilt=");
1034 if (aiptek->yTilt == AIPTEK_TILT_DISABLE) {
1035 out += sprintf(out, "disable\n");
1036 } else {
1037 out += sprintf(out, "%d\n", aiptek->yTilt);
1038 }
1039
1040 out += sprintf(out, "jitter=%d\n", aiptek->jitterDelay);
1041
1042 out += sprintf(out, "diagnostic=");
1043 switch (aiptek->diagnostic) {
1044 case AIPTEK_DIAGNOSTIC_NA:
1045 out += sprintf(out, "none\n");
1046 break;
1047 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1048 out += sprintf(out, "tablet sending relative reports\n");
1049 break;
1050 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1051 out += sprintf(out, "tablet sending absolute reports\n");
1052 break;
1053 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1054 out += sprintf(out, "tablet seeing reports from ");
1055 if (aiptek->pointer_mode == AIPTEK_POINTER_ONLY_MOUSE_MODE)
1056 out += sprintf(out, "stylus\n");
1057 else
1058 out += sprintf(out, "mouse\n");
1059 break;
1060 }
1061
1062 out += sprintf(out, "eventsReceived=%lu\n", aiptek->eventCount);
1063
1064 len = out - page;
1065 len -= offset;
1066 if (len < count) {
1067 *eof = 1;
1068 if (len <= 0) {
1069 return 0;
1070 }
1071 } else {
1072 len = count;
1073 }
1074
1075 *start = page + offset;
1076
1077 return len;
1078}
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093static int
1094aiptek_procfs_write(struct file *file, const char *buffer, unsigned long count,
1095 void *data)
1096{
1097 char buf[64];
1098 char *scan;
1099 char *keyword = NULL;
1100 char *value = NULL;
1101 struct aiptek *aiptek = data;
1102 int num;
1103
1104 num = (count < 64) ? count : 64;
1105 if (copy_from_user(buf, buffer, num))
1106 return -EFAULT;
1107 buf[num] = '\0';
1108
1109 scan = buf;
1110 while (*scan) {
1111 if (*scan == '\n' || *scan == '\0') {
1112 if (*scan == '\n') {
1113 *scan = '\0';
1114 scan++;
1115 }
1116 if (keyword && value) {
1117 aiptek_procfs_parse(aiptek, keyword, value);
1118 }
1119 keyword = NULL;
1120 value = NULL;
1121 continue;
1122 }
1123
1124 if (*scan != '=' && keyword == NULL) {
1125 keyword = scan;
1126 } else if (*scan == '=') {
1127 *scan++ = '\0';
1128 value = scan;
1129 }
1130 scan++;
1131 }
1132
1133 if (keyword && value) {
1134 aiptek_procfs_parse(aiptek, keyword, value);
1135 }
1136
1137 aiptek_program_tablet(aiptek);
1138
1139 return num;
1140}
1141
1142
1143
1144
1145
1146static void
1147destroy_procfs_file(struct aiptek *aiptek)
1148{
1149 if (aiptek->aiptekProcfsEntry)
1150 remove_proc_entry("aiptek", aiptek->usbProcfsEntry);
1151 if (aiptek->usbProcfsEntry)
1152 remove_proc_entry("usb", proc_root_driver);
1153
1154 aiptek->usbProcfsEntry = NULL;
1155 aiptek->aiptekProcfsEntry = NULL;
1156}
1157
1158
1159
1160
1161
1162static void
1163create_procfs_file(struct aiptek *aiptek)
1164{
1165
1166 aiptek->usbProcfsEntry = create_proc_entry("usb", S_IFDIR,
1167 proc_root_driver);
1168 if (!aiptek->usbProcfsEntry) {
1169 dbg("create_procfs_file failed; no procfs/driver/usb control file.");
1170 destroy_procfs_file(aiptek);
1171 return;
1172 }
1173 aiptek->usbProcfsEntry->owner = THIS_MODULE;
1174
1175
1176 aiptek->aiptekProcfsEntry = create_proc_entry("aiptek",
1177 S_IFREG | S_IRUGO |
1178 S_IWUGO,
1179 aiptek->usbProcfsEntry);
1180 if (!aiptek->aiptekProcfsEntry) {
1181 dbg("create_procfs_file failed; no procfs/driver/usb control file.");
1182 destroy_procfs_file(aiptek);
1183 return;
1184 }
1185 aiptek->aiptekProcfsEntry->owner = THIS_MODULE;
1186 aiptek->aiptekProcfsEntry->data = aiptek;
1187 aiptek->aiptekProcfsEntry->read_proc = aiptek_procfs_read;
1188 aiptek->aiptekProcfsEntry->write_proc = aiptek_procfs_write;
1189}
1190#endif
1191
1192static void *
1193aiptek_probe(struct usb_device *dev, unsigned int ifnum,
1194 const struct usb_device_id *id)
1195{
1196 struct usb_endpoint_descriptor *endpoint;
1197 struct aiptek *aiptek;
1198 int i;
1199
1200 if (!(aiptek = kmalloc(sizeof (struct aiptek), GFP_KERNEL)))
1201 return NULL;
1202
1203 memset(aiptek, 0, sizeof (struct aiptek));
1204
1205 aiptek->irq = usb_alloc_urb(0);
1206 if (!aiptek->irq) {
1207 kfree(aiptek);
1208 return NULL;
1209 }
1210
1211
1212
1213
1214 aiptek->features = aiptek_features;
1215
1216
1217
1218
1219
1220
1221
1222
1223 aiptek->usbdev = dev;
1224 aiptek->ifnum = ifnum;
1225 aiptek->pointer_mode = AIPTEK_POINTER_EITHER_MODE;
1226 aiptek->coordinate_mode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
1227 aiptek->tool_mode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1228 aiptek->xTilt = AIPTEK_TILT_DISABLE;
1229 aiptek->yTilt = AIPTEK_TILT_DISABLE;
1230 aiptek->jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
1231
1232#ifdef CONFIG_PROC_FS
1233 create_procfs_file(aiptek);
1234#endif
1235
1236 aiptek_program_tablet(aiptek);
1237
1238 aiptek->dev.evbit[0] |= BIT(EV_KEY)
1239 | BIT(EV_ABS)
1240 | BIT(EV_MSC);
1241
1242 aiptek->dev.absbit[0] |= BIT(ABS_X)
1243 | BIT(ABS_Y)
1244 | BIT(ABS_PRESSURE)
1245 | BIT(ABS_TILT_X)
1246 | BIT(ABS_TILT_Y)
1247 | BIT(ABS_MISC);
1248
1249 aiptek->dev.relbit[0] |= BIT(REL_X)
1250 | BIT(REL_Y)
1251 | BIT(REL_MISC);
1252
1253
1254
1255
1256 for (i = 0; i < sizeof (macroKeyEvents) / sizeof (macroKeyEvents[0]);
1257 ++i) {
1258 set_bit(macroKeyEvents[i], aiptek->dev.keybit);
1259 }
1260
1261 aiptek->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT)
1262 | BIT(BTN_RIGHT)
1263 | BIT(BTN_MIDDLE);
1264
1265 aiptek->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN)
1266 | BIT(BTN_TOOL_RUBBER)
1267 | BIT(BTN_TOOL_PENCIL)
1268 | BIT(BTN_TOOL_AIRBRUSH)
1269 | BIT(BTN_TOOL_BRUSH)
1270 | BIT(BTN_TOOL_MOUSE)
1271 | BIT(BTN_TOUCH)
1272 | BIT(BTN_STYLUS)
1273 | BIT(BTN_STYLUS2);
1274
1275 aiptek->dev.mscbit[0] = BIT(MSC_SERIAL);
1276
1277 aiptek->dev.absmax[ABS_X] = aiptek->features->x_max;
1278 aiptek->dev.absmax[ABS_Y] = aiptek->features->y_max;
1279 aiptek->dev.absmax[ABS_PRESSURE] = aiptek->features->pressure_max;
1280 aiptek->dev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX;
1281 aiptek->dev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX;
1282 aiptek->dev.absfuzz[ABS_X] = 0;
1283 aiptek->dev.absfuzz[ABS_Y] = 0;
1284
1285 aiptek->dev.private = aiptek;
1286 aiptek->dev.open = aiptek_open;
1287 aiptek->dev.close = aiptek_close;
1288
1289 aiptek->dev.name = aiptek->features->name;
1290 aiptek->dev.idbus = BUS_USB;
1291 aiptek->dev.idvendor = dev->descriptor.idVendor;
1292 aiptek->dev.idproduct = dev->descriptor.idProduct;
1293 aiptek->dev.idversion = dev->descriptor.bcdDevice;
1294 aiptek->usbdev = dev;
1295
1296 endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
1297
1298 usb_fill_int_urb(aiptek->irq,
1299 dev,
1300 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
1301 aiptek->data,
1302 aiptek->features->pktlen,
1303 aiptek->features->irq, aiptek, endpoint->bInterval);
1304
1305 input_register_device(&aiptek->dev);
1306
1307 printk(KERN_INFO "input%d: %s on usb%d:%d.%d\n",
1308 aiptek->dev.number,
1309 aiptek->features->name, dev->bus->busnum, dev->devnum, ifnum);
1310
1311 return aiptek;
1312}
1313
1314static struct usb_driver aiptek_driver;
1315
1316static void
1317aiptek_disconnect(struct usb_device *dev, void *ptr)
1318{
1319 struct aiptek *aiptek = ptr;
1320#ifdef CONFIG_PROC_FS
1321 destroy_procfs_file(aiptek);
1322#endif
1323 usb_unlink_urb(aiptek->irq);
1324 input_unregister_device(&aiptek->dev);
1325 usb_free_urb(aiptek->irq);
1326 kfree(aiptek);
1327}
1328
1329static struct usb_driver aiptek_driver = {
1330 name:"aiptek",
1331 probe:aiptek_probe,
1332 disconnect:aiptek_disconnect,
1333 id_table:aiptek_ids,
1334};
1335
1336static int __init
1337aiptek_init(void)
1338{
1339 usb_register(&aiptek_driver);
1340 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
1341 info(DRIVER_DESC);
1342 return 0;
1343}
1344
1345static void __exit
1346aiptek_exit(void)
1347{
1348 usb_deregister(&aiptek_driver);
1349}
1350
1351module_init(aiptek_init);
1352module_exit(aiptek_exit);
1353