53 #include <linux/kernel.h>
54 #include <linux/module.h>
55 #include <linux/errno.h>
57 #include <linux/slab.h>
58 #include <linux/input.h>
60 #include <asm/uaccess.h>
61 #include <asm/unaligned.h>
62 #include <asm/byteorder.h>
68 #define GTCO_VERSION "2.00.0006"
73 #define VENDOR_ID_GTCO 0x078C
76 #define PID_1000 0x1000
77 #define PID_1001 0x1001
78 #define PID_1002 0x1002
81 #define REPORT_MAX_SIZE 10
85 #define MASK_INRANGE 0x20
86 #define MASK_BUTTON 0x01F
147 #define HID_DESCRIPTOR_SIZE 9
148 #define HID_DEVICE_TYPE 33
149 #define REPORT_DEVICE_TYPE 34
152 #define PREF_TAG(x) ((x)>>4)
153 #define PREF_TYPE(x) ((x>>2)&0x03)
154 #define PREF_SIZE(x) ((x)&0x03)
157 #define TYPE_GLOBAL 1
159 #define TYPE_RESERVED 3
161 #define TAG_MAIN_INPUT 0x8
162 #define TAG_MAIN_OUTPUT 0x9
163 #define TAG_MAIN_FEATURE 0xB
164 #define TAG_MAIN_COL_START 0xA
165 #define TAG_MAIN_COL_END 0xC
167 #define TAG_GLOB_USAGE 0
168 #define TAG_GLOB_LOG_MIN 1
169 #define TAG_GLOB_LOG_MAX 2
170 #define TAG_GLOB_PHYS_MIN 3
171 #define TAG_GLOB_PHYS_MAX 4
172 #define TAG_GLOB_UNIT_EXP 5
173 #define TAG_GLOB_UNIT 6
174 #define TAG_GLOB_REPORT_SZ 7
175 #define TAG_GLOB_REPORT_ID 8
176 #define TAG_GLOB_REPORT_CNT 9
177 #define TAG_GLOB_PUSH 10
178 #define TAG_GLOB_POP 11
180 #define TAG_GLOB_MAX 12
182 #define DIGITIZER_USAGE_TIP_PRESSURE 0x30
183 #define DIGITIZER_USAGE_TILT_X 0x3D
184 #define DIGITIZER_USAGE_TILT_Y 0x3E
204 struct device *ddev = &device->
intf->dev;
228 char indentstr[10] =
"";
231 dev_dbg(ddev,
"======>>>>>>PARSE<<<<<<======\n");
247 data16 = get_unaligned_le16(&report[i]);
276 strcpy(globtype,
"Variable");
278 strcpy(globtype,
"Var|Const");
280 dev_dbg(ddev,
"::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits\n",
295 dev_dbg(ddev,
"GER: X Usage: 0x%x\n", usage);
296 if (device->
max_X == 0) {
303 dev_dbg(ddev,
"GER: Y Usage: 0x%x\n", usage);
304 if (device->
max_Y == 0) {
353 dev_dbg(ddev,
"======>>>>>> Physical\n");
354 strcpy(globtype,
"Physical");
356 dev_dbg(ddev,
"======>>>>>>\n");
360 for (x = 0; x < indent; x++)
366 oldval[x] = globalval[x];
371 dev_dbg(ddev,
"<<<<<<======\n");
374 for (x = 0; x < indent; x++)
380 globalval[x] = oldval[x];
387 dev_dbg(ddev,
"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
388 indentstr, tag, maintype, size, globtype, data);
392 dev_dbg(ddev,
"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
393 indentstr, tag, maintype, size, globtype, data16);
397 dev_dbg(ddev,
"%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
398 indentstr, tag, maintype, size, globtype, data32);
410 if (device->
usage == 0)
413 strcpy(globtype,
"USAGE");
417 strcpy(globtype,
"LOG_MIN");
421 strcpy(globtype,
"LOG_MAX");
425 strcpy(globtype,
"PHYS_MIN");
429 strcpy(globtype,
"PHYS_MAX");
441 strcpy(globtype,
"REPORT_SZ");
445 strcpy(globtype,
"REPORT_ID");
451 strcpy(globtype,
"REPORT_CNT");
468 dev_dbg(ddev,
"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
469 indentstr, globtype, tag, size, data);
474 dev_dbg(ddev,
"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
475 indentstr, globtype, tag, size, data16);
476 globalval[
tag] = data16;
480 dev_dbg(ddev,
"%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
481 indentstr, globtype, tag, size, data32);
482 globalval[
tag] = data32;
486 dev_dbg(ddev,
"%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d\n",
487 indentstr, tag, size);
494 strcpy(globtype,
"USAGE");
508 strcpy(globtype,
"UNKNOWN");
514 dev_dbg(ddev,
"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
515 indentstr, tag, globtype, size, data);
519 dev_dbg(ddev,
"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
520 indentstr, tag, globtype, size, data16);
524 dev_dbg(ddev,
"%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
525 indentstr, tag, globtype, size, data32);
540 static int gtco_input_open(
struct input_dev *inputdev)
542 struct gtco *
device = input_get_drvdata(inputdev);
554 static void gtco_input_close(
struct input_dev *inputdev)
556 struct gtco *device = input_get_drvdata(inputdev);
570 static void gtco_setup_caps(
struct input_dev *inputdev)
572 struct gtco *device = input_get_drvdata(inputdev);
589 input_set_abs_params(inputdev,
ABS_DISTANCE, 0, 1, 0, 0);
600 input_set_abs_params(inputdev,
ABS_MISC, 0, 0xFF, 0, 0);
612 static void gtco_urb_callback(
struct urb *
urbinfo)
614 struct gtco *device = urbinfo->context;
615 struct input_dev *inputdev;
625 urbinfo->status == -
ENOENT ||
632 if (urbinfo->status != 0) {
645 if (inputdev->id.product ==
PID_1000 ||
655 switch (device->
buffer[0]) {
671 if (device->
buffer[6] & 0x40)
672 device->
buffer[6] |= 0x80;
674 if (device->
buffer[7] & 0x40)
675 device->
buffer[7] |= 0x80;
678 valsigned = (device->
buffer[6]);
681 valsigned = (device->
buffer[7]);
697 val = get_unaligned_le16(&device->
buffer[1]);
698 input_report_abs(inputdev,
ABS_X, val);
700 val = get_unaligned_le16(&device->
buffer[3]);
701 input_report_abs(inputdev,
ABS_Y, val);
709 if (device->
buffer[0] == 1) {
718 "======>>>>>>REPORT 1: val 0x%X(%d)\n",
738 if (inputdev->id.product ==
PID_400 ||
739 inputdev->id.product ==
PID_401) {
742 if (device->
buffer[0] == 2) {
748 if (device->
buffer[0] == 1) {
752 if (device->
max_X > 0x10000) {
757 input_report_abs(inputdev,
ABS_X, val);
759 le_buffer[0] = (
u8)((
u8)(device->
buffer[3]) >> 1);
760 le_buffer[0] |= (
u8)((device->
buffer[3] & 0x1) << 7);
762 le_buffer[1] = (
u8)(device->
buffer[4] >> 1);
763 le_buffer[1] |= (
u8)((device->
buffer[5] & 0x1) << 7);
765 val = get_unaligned_le16(le_buffer);
766 input_report_abs(inputdev,
ABS_Y, val);
772 buttonbyte = device->
buffer[5] >> 1;
775 val = get_unaligned_le16(&device->
buffer[1]);
776 input_report_abs(inputdev,
ABS_X, val);
778 val = get_unaligned_le16(&device->
buffer[3]);
779 input_report_abs(inputdev,
ABS_Y, val);
781 buttonbyte = device->
buffer[5];
789 val = buttonbyte & 0x0F;
791 for (
i = 0;
i < 5;
i++)
792 input_report_key(inputdev,
BTN_DIGI +
i, val & (1 <<
i));
807 input_sync(inputdev);
813 "usb_submit_urb failed rc=0x%x\n", rc);
832 struct input_dev *input_dev;
840 gtco = kzalloc(
sizeof(
struct gtco),
GFP_KERNEL);
841 input_dev = input_allocate_device();
842 if (!gtco || !input_dev) {
843 dev_err(&usbinterface->dev,
"No more memory\n");
853 gtco->
intf = usbinterface;
859 dev_err(&usbinterface->dev,
"No more memory for us buffers\n");
867 dev_err(&usbinterface->dev,
"Failed to allocate URB\n");
876 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
879 dev_dbg(&usbinterface->dev,
"gtco # interfaces: %d\n", usbinterface->num_altsetting);
880 dev_dbg(&usbinterface->dev,
"num endpoints: %d\n", usbinterface->cur_altsetting->desc.bNumEndpoints);
881 dev_dbg(&usbinterface->dev,
"interface class: %d\n", usbinterface->cur_altsetting->desc.bInterfaceClass);
883 if (usb_endpoint_xfer_int(endpoint))
884 dev_dbg(&usbinterface->dev,
"endpoint: we have interrupt endpoint\n");
886 dev_dbg(&usbinterface->dev,
"endpoint extra len:%d\n", usbinterface->altsetting[0].extralen);
892 if (usb_get_extra_descriptor(usbinterface->cur_altsetting,
895 "Can't retrieve exta USB descriptor to get hid report descriptor length\n");
901 "Extra descriptor success: type:%d len:%d\n",
906 dev_err(&usbinterface->dev,
"No more memory for report\n");
914 usb_rcvctrlpipe(gtco->
usbdev, 0),
923 dev_dbg(&usbinterface->dev,
"usb_control_msg result: %d\n", result);
925 parse_hid_report_descriptor(gtco, report, result);
935 "Failed to get HID Report Descriptor of size: %d\n",
946 input_dev->open = gtco_input_open;
947 input_dev->close = gtco_input_close;
950 input_dev->name =
"GTCO_CalComp";
951 input_dev->phys = gtco->
usbpath;
953 input_set_drvdata(input_dev, gtco);
956 gtco_setup_caps(input_dev);
959 usb_to_input_id(gtco->
usbdev, &input_dev->id);
960 input_dev->dev.parent = &usbinterface->dev;
963 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
965 usb_fill_int_urb(gtco->
urbinfo,
967 usb_rcvintpipe(gtco->
usbdev,
976 gtco->
urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
979 usb_set_intfdata(usbinterface, gtco);
982 error = input_register_device(input_dev);
994 input_free_device(input_dev);
1007 struct gtco *gtco = usb_get_intfdata(interface);
1019 dev_info(&interface->dev,
"gtco driver disconnected\n");
1024 static struct usb_driver gtco_driverinfo_table = {
1026 .id_table = gtco_usbid_table,
1027 .probe = gtco_probe,
1028 .disconnect = gtco_disconnect,