3 GTCO digitizer USB driver
5 Use the err(), dbg() and info() macros from usb.h for system logging
7 TO CHECK: Is pressure done right on report 5?
9 Copyright (C) 2006 GTCO CalComp
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; version 2
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 Permission to use, copy, modify, distribute, and sell this software and its
26 documentation for any purpose is hereby granted without fee, provided that
27 the above copyright notice appear in all copies and that both that
28 copyright notice and this permission notice appear in supporting
29 documentation, and that the name of GTCO-CalComp not be used in advertising
30 or publicity pertaining to distribution of the software without specific,
31 written prior permission. GTCO-CalComp makes no representations about the
32 suitability of this software for any purpose. It is provided "as is"
33 without express or implied warranty.
35 GTCO-CALCOMP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
36 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
37 EVENT SHALL GTCO-CALCOMP BE LIABLE FOR ANY SPECIAL, INDIRECT OR
38 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
39 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
40 TORTIOUS ACTIONS, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41 PERFORMANCE OF THIS SOFTWARE.
47 Jeremy Roberson jroberson@gtcocalcomp.com
48 Scott Hill shill@gtcocalcomp.com
55 #include <linux/kernel.h>
56 #include <linux/module.h>
57 #include <linux/errno.h>
58 #include <linux/init.h>
59 #include <linux/slab.h>
60 #include <linux/input.h>
61 #include <linux/usb.h>
62 #include <asm/uaccess.h>
63 #include <asm/unaligned.h>
64 #include <asm/byteorder.h>
67 #include <linux/version.h>
68 #include <linux/usb/input.h>
70 /* Version with a Major number of 2 is for kernel inclusion only. */
71 #define GTCO_VERSION "2.00.0006"
76 #define VENDOR_ID_GTCO 0x078C
79 #define PID_1000 0x1000
80 #define PID_1001 0x1001
81 #define PID_1002 0x1002
83 /* Max size of a single report */
84 #define REPORT_MAX_SIZE 10
87 /* Bitmask whether pen is in range */
88 #define MASK_INRANGE 0x20
89 #define MASK_BUTTON 0x01F
96 static struct usb_device_id gtco_usbid_table [] = {
97 { USB_DEVICE(VENDOR_ID_GTCO, PID_400) },
98 { USB_DEVICE(VENDOR_ID_GTCO, PID_401) },
99 { USB_DEVICE(VENDOR_ID_GTCO, PID_1000) },
100 { USB_DEVICE(VENDOR_ID_GTCO, PID_1001) },
101 { USB_DEVICE(VENDOR_ID_GTCO, PID_1002) },
104 MODULE_DEVICE_TABLE (usb, gtco_usbid_table);
107 /* Structure to hold all of our device specific stuff */
110 struct input_dev *inputdevice; /* input device struct pointer */
111 struct usb_device *usbdev; /* the usb device for this device */
112 struct urb *urbinfo; /* urb for incoming reports */
113 dma_addr_t buf_dma; /* dma addr of the data buffer*/
114 unsigned char * buffer; /* databuffer for reports */
116 char usbpath[PATHLENGTH];
119 /* Information pulled from Report Descriptor */
135 /* Code for parsing the HID REPORT DESCRIPTOR */
137 /* From HID1.11 spec */
138 struct hid_descriptor
140 struct usb_descriptor_header header;
145 __le16 wDescriptorLength;
146 } __attribute__ ((packed));
149 #define HID_DESCRIPTOR_SIZE 9
150 #define HID_DEVICE_TYPE 33
151 #define REPORT_DEVICE_TYPE 34
154 #define PREF_TAG(x) ((x)>>4)
155 #define PREF_TYPE(x) ((x>>2)&0x03)
156 #define PREF_SIZE(x) ((x)&0x03)
159 #define TYPE_GLOBAL 1
161 #define TYPE_RESERVED 3
163 #define TAG_MAIN_INPUT 0x8
164 #define TAG_MAIN_OUTPUT 0x9
165 #define TAG_MAIN_FEATURE 0xB
166 #define TAG_MAIN_COL_START 0xA
167 #define TAG_MAIN_COL_END 0xC
169 #define TAG_GLOB_USAGE 0
170 #define TAG_GLOB_LOG_MIN 1
171 #define TAG_GLOB_LOG_MAX 2
172 #define TAG_GLOB_PHYS_MIN 3
173 #define TAG_GLOB_PHYS_MAX 4
174 #define TAG_GLOB_UNIT_EXP 5
175 #define TAG_GLOB_UNIT 6
176 #define TAG_GLOB_REPORT_SZ 7
177 #define TAG_GLOB_REPORT_ID 8
178 #define TAG_GLOB_REPORT_CNT 9
179 #define TAG_GLOB_PUSH 10
180 #define TAG_GLOB_POP 11
182 #define TAG_GLOB_MAX 12
184 #define DIGITIZER_USAGE_TIP_PRESSURE 0x30
185 #define DIGITIZER_USAGE_TILT_X 0x3D
186 #define DIGITIZER_USAGE_TILT_Y 0x3E
191 * This is an abbreviated parser for the HID Report Descriptor. We
192 * know what devices we are talking to, so this is by no means meant
193 * to be generic. We can make some safe assumptions:
195 * - We know there are no LONG tags, all short
196 * - We know that we have no MAIN Feature and MAIN Output items
197 * - We know what the IRQ reports are supposed to look like.
199 * The main purpose of this is to use the HID report desc to figure
200 * out the mins and maxs of the fields in the IRQ reports. The IRQ
201 * reports for 400/401 change slightly if the max X is bigger than 64K.
204 static void parse_hid_report_descriptor(struct gtco *device, char * report,
209 /* Tag primitive vars */
219 /* For parsing logic */
223 /* Global Values, indexed by TAG */
224 __u32 globalval[TAG_GLOB_MAX];
225 __u32 oldval[TAG_GLOB_MAX];
231 char indentstr[10]="";
235 dbg("======>>>>>>PARSE<<<<<<======");
237 /* Walk this report and pull out the info we need */
241 /* Skip over prefix */
244 /* Determine data size and save the data in the proper variable */
245 size = PREF_SIZE(prefix);
251 data16 = le16_to_cpu(get_unaligned((__le16*)(&(report[i]))));
255 data32 = le32_to_cpu(get_unaligned((__le32*)(&(report[i]))));
258 /* Skip size of data */
261 /* What we do depends on the tag type */
262 tag = PREF_TAG(prefix);
263 type = PREF_TYPE(prefix);
271 * The INPUT MAIN tag signifies this is
272 * information from a report. We need to
273 * figure out what it is and store the
279 strcpy(globtype,"Variable");
282 strcpy(globtype,"Var|Const");
285 dbg("::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits",
286 globalval[TAG_GLOB_REPORT_ID],inputnum,
287 globalval[TAG_GLOB_LOG_MAX],globalval[TAG_GLOB_LOG_MAX],
288 globalval[TAG_GLOB_LOG_MIN],globalval[TAG_GLOB_LOG_MIN],
289 (globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]));
293 We can assume that the first two input items
294 are always the X and Y coordinates. After
295 that, we look for everything else by
299 case 0: /* X coord */
300 dbg("GER: X Usage: 0x%x",usage);
301 if (device->max_X == 0){
302 device->max_X = globalval[TAG_GLOB_LOG_MAX];
303 device->min_X = globalval[TAG_GLOB_LOG_MIN];
307 case 1: /* Y coord */
308 dbg("GER: Y Usage: 0x%x",usage);
309 if (device->max_Y == 0){
310 device->max_Y = globalval[TAG_GLOB_LOG_MAX];
311 device->min_Y = globalval[TAG_GLOB_LOG_MIN];
316 if (usage == DIGITIZER_USAGE_TILT_X){
317 if (device->maxtilt_X == 0){
318 device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];
319 device->mintilt_X = globalval[TAG_GLOB_LOG_MIN];
324 if (usage == DIGITIZER_USAGE_TILT_Y){
325 if (device->maxtilt_Y == 0){
326 device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];
327 device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];
333 if (usage == DIGITIZER_USAGE_TIP_PRESSURE){
334 if (device->maxpressure == 0){
335 device->maxpressure = globalval[TAG_GLOB_LOG_MAX];
336 device->minpressure = globalval[TAG_GLOB_LOG_MIN];
347 case TAG_MAIN_OUTPUT:
350 case TAG_MAIN_FEATURE:
353 case TAG_MAIN_COL_START:
357 dbg("======>>>>>> Physical");
358 strcpy(globtype,"Physical");
363 /* Indent the debug output */
365 for (x=0;x<indent;x++){
370 /* Save global tags */
371 for (x=0;x<TAG_GLOB_MAX;x++){
372 oldval[x] = globalval[x];
376 case TAG_MAIN_COL_END:
380 for (x=0;x<indent;x++){
385 /* Copy global tags back */
386 for (x=0;x<TAG_GLOB_MAX;x++){
387 globalval[x] = oldval[x];
395 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
396 indentstr,tag,maintype,size,globtype,data);
399 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
400 indentstr,tag,maintype,size,globtype, data16);
403 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
404 indentstr,tag,maintype,size,globtype,data32);
412 * First time we hit the global usage tag,
413 * it should tell us the type of device
415 if (device->usage == 0){
416 device->usage = data;
418 strcpy(globtype,"USAGE");
420 case TAG_GLOB_LOG_MIN :
421 strcpy(globtype,"LOG_MIN");
423 case TAG_GLOB_LOG_MAX :
424 strcpy(globtype,"LOG_MAX");
426 case TAG_GLOB_PHYS_MIN :
427 strcpy(globtype,"PHYS_MIN");
429 case TAG_GLOB_PHYS_MAX :
430 strcpy(globtype,"PHYS_MAX");
432 case TAG_GLOB_UNIT_EXP :
433 strcpy(globtype,"EXP");
436 strcpy(globtype,"UNIT");
438 case TAG_GLOB_REPORT_SZ :
439 strcpy(globtype,"REPORT_SZ");
441 case TAG_GLOB_REPORT_ID :
442 strcpy(globtype,"REPORT_ID");
443 /* New report, restart numbering */
446 case TAG_GLOB_REPORT_CNT:
447 strcpy(globtype,"REPORT_CNT");
450 strcpy(globtype,"PUSH");
453 strcpy(globtype,"POP");
458 /* Check to make sure we have a good tag number
459 so we don't overflow array */
460 if (tag < TAG_GLOB_MAX){
463 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data);
467 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data16);
468 globalval[tag]=data16;
471 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data32);
472 globalval[tag]=data32;
476 dbg("%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d ",
486 strcpy(globtype,"USAGE");
490 case TAG_GLOB_LOG_MIN :
491 strcpy(globtype,"MIN");
493 case TAG_GLOB_LOG_MAX :
494 strcpy(globtype,"MAX");
497 strcpy(globtype,"UNKNOWN");
502 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
503 indentstr,tag,globtype,size,data);
506 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
507 indentstr,tag,globtype,size,data16);
510 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
511 indentstr,tag,globtype,size,data32);
524 /* INPUT DRIVER Routines */
528 * Called when opening the input device. This will submit the URB to
529 * the usb system so we start getting reports
531 static int gtco_input_open(struct input_dev *inputdev)
534 device = inputdev->private;
536 device->urbinfo->dev = device->usbdev;
537 if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) {
544 Called when closing the input device. This will unlink the URB
546 static void gtco_input_close(struct input_dev *inputdev)
548 struct gtco *device = inputdev->private;
550 usb_kill_urb(device->urbinfo);
556 * Setup input device capabilities. Tell the input system what this
557 * device is capable of generating.
559 * This information is based on what is read from the HID report and
560 * placed in the struct gtco structure
563 static void gtco_setup_caps(struct input_dev *inputdev)
565 struct gtco *device = inputdev->private;
569 inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC);
572 /* Misc event menu block */
573 inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ;
576 /* Absolute values based on HID report info */
577 input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X,
579 input_set_abs_params(inputdev, ABS_Y, device->min_Y, device->max_Y,
583 input_set_abs_params(inputdev, ABS_DISTANCE, 0, 1, 0, 0);
585 /* Tilt & pressure */
586 input_set_abs_params(inputdev, ABS_TILT_X, device->mintilt_X,
587 device->maxtilt_X, 0, 0);
588 input_set_abs_params(inputdev, ABS_TILT_Y, device->mintilt_Y,
589 device->maxtilt_Y, 0, 0);
590 input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure,
591 device->maxpressure, 0, 0);
595 input_set_abs_params(inputdev, ABS_MISC, 0,0xFF, 0, 0);
605 * URB callback routine. Called when we get IRQ reports from the
608 * This bridges the USB and input device worlds. It generates events
609 * on the input device based on the USB reports.
611 static void gtco_urb_callback(struct urb *urbinfo)
615 struct gtco *device = urbinfo->context;
616 struct input_dev *inputdev;
622 inputdev = device->inputdevice;
625 /* Was callback OK? */
626 if ((urbinfo->status == -ECONNRESET ) ||
627 (urbinfo->status == -ENOENT ) ||
628 (urbinfo->status == -ESHUTDOWN )){
630 /* Shutdown is occurring. Return and don't queue up any more */
634 if (urbinfo->status != 0 ) {
635 /* Some unknown error. Hopefully temporary. Just go and */
641 * Good URB, now process
644 /* PID dependent when we interpret the report */
645 if ((inputdev->id.product == PID_1000 )||
646 (inputdev->id.product == PID_1001 )||
647 (inputdev->id.product == PID_1002 ))
651 * Switch on the report ID
652 * Conveniently, the reports have more information, the higher
653 * the report number. We can just fall through the case
654 * statements if we start with the highest number report
656 switch(device->buffer[0]){
658 /* Pressure is 9 bits */
659 val = ((u16)(device->buffer[8]) << 1);
660 val |= (u16)(device->buffer[7] >> 7);
661 input_report_abs(inputdev, ABS_PRESSURE,
664 /* Mask out the Y tilt value used for pressure */
665 device->buffer[7] = (u8)((device->buffer[7]) & 0x7F);
672 /* Sign extend these 7 bit numbers. */
673 if (device->buffer[6] & 0x40)
674 device->buffer[6] |= 0x80;
676 if (device->buffer[7] & 0x40)
677 device->buffer[7] |= 0x80;
680 valsigned = (device->buffer[6]);
681 input_report_abs(inputdev, ABS_TILT_X, (s32)valsigned);
683 valsigned = (device->buffer[7]);
684 input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned);
690 /* Convert buttons, only 5 bits possible */
691 val = (device->buffer[5])&MASK_BUTTON;
693 /* We don't apply any meaning to the bitmask,
695 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
700 /* All reports have X and Y coords in the same place */
701 val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[1])));
702 input_report_abs(inputdev, ABS_X, val);
704 val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[3])));
705 input_report_abs(inputdev, ABS_Y, val);
708 /* Ditto for proximity bit */
709 if (device->buffer[5]& MASK_INRANGE){
714 input_report_abs(inputdev, ABS_DISTANCE, val);
717 /* Report 1 is an exception to how we handle buttons */
718 /* Buttons are an index, not a bitmask */
719 if (device->buffer[0] == 1){
721 /* Convert buttons, 5 bit index */
722 /* Report value of index set as one,
724 val = device->buffer[5]& MASK_BUTTON;
725 dbg("======>>>>>>REPORT 1: val 0x%X(%d)",
729 * We don't apply any meaning to the button
730 * index, just report it
732 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
740 input_event(inputdev, EV_MSC, MSC_SCAN,
750 /* Other pid class */
751 if ((inputdev->id.product == PID_400 )||
752 (inputdev->id.product == PID_401 ))
756 if (device->buffer[0] == 2){
758 input_event(inputdev, EV_MSC, MSC_SCAN,
763 if (device->buffer[0] == 1){
767 /* IF X max > 64K, we still a bit from the y report */
768 if (device->max_X > 0x10000){
770 val = (u16)(((u16)(device->buffer[2]<<8))|((u8)(device->buffer[1])));
771 val |= (u32)(((u8)device->buffer[3]&0x1)<< 16);
773 input_report_abs(inputdev, ABS_X, val);
775 le_buffer[0] = (u8)((u8)(device->buffer[3])>>1);
776 le_buffer[0] |= (u8)((device->buffer[3]&0x1)<<7);
778 le_buffer[1] = (u8)(device->buffer[4]>>1);
779 le_buffer[1] |= (u8)((device->buffer[5]&0x1)<<7);
781 val = le16_to_cpu(get_unaligned((__le16 *)(le_buffer)));
783 input_report_abs(inputdev, ABS_Y, val);
787 * Shift the button byte right by one to
788 * make it look like the standard report
790 buttonbyte = (device->buffer[5])>>1;
793 val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[1]))));
794 input_report_abs(inputdev, ABS_X, val);
796 val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[3]))));
797 input_report_abs(inputdev, ABS_Y, val);
799 buttonbyte = device->buffer[5];
804 /* BUTTONS and PROXIMITY */
805 if (buttonbyte& MASK_INRANGE){
810 input_report_abs(inputdev, ABS_DISTANCE, val);
812 /* Convert buttons, only 4 bits possible */
813 val = buttonbyte&0x0F;
816 input_report_key(inputdev, BTN_DIGI+i,val&(1<<i));
819 /* We don't apply any meaning to the bitmask, just report */
820 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
823 input_report_abs(inputdev, ABS_MISC, device->buffer[6]);
828 /* Everybody gets report ID's */
829 input_event(inputdev, EV_MSC, MSC_RAW, device->buffer[0]);
832 input_sync(inputdev);
835 rc = usb_submit_urb(urbinfo, GFP_ATOMIC);
837 err("usb_submit_urb failed rc=0x%x",rc);
843 * The probe routine. This is called when the kernel find the matching USB
844 * vendor/product. We do the following:
846 * - Allocate mem for a local structure to manage the device
847 * - Request a HID Report Descriptor from the device and parse it to
848 * find out the device parameters
849 * - Create an input device and assign it attributes
850 * - Allocate an URB so the device can talk to us when the input
853 static int gtco_probe(struct usb_interface *usbinterface,
854 const struct usb_device_id *id)
857 struct gtco *device = NULL;
858 char path[PATHLENGTH];
859 struct input_dev *inputdev;
860 struct hid_descriptor *hid_desc;
863 struct usb_endpoint_descriptor *endpoint;
865 /* Allocate memory for device structure */
866 device = kzalloc(sizeof(struct gtco), GFP_KERNEL);
867 if (device == NULL) {
868 err("No more memory");
873 device->inputdevice = input_allocate_device();
874 if (!device->inputdevice){
876 err("No more memory");
880 /* Get pointer to the input device */
881 inputdev = device->inputdevice;
883 /* Save interface information */
884 device->usbdev = usb_get_dev(interface_to_usbdev(usbinterface));
887 /* Allocate some data for incoming reports */
888 device->buffer = usb_buffer_alloc(device->usbdev, REPORT_MAX_SIZE,
889 GFP_KERNEL, &(device->buf_dma));
890 if (!device->buffer){
891 input_free_device(device->inputdevice);
893 err("No more memory");
897 /* Allocate URB for reports */
898 device->urbinfo = usb_alloc_urb(0, GFP_KERNEL);
899 if (!device->urbinfo) {
900 usb_buffer_free(device->usbdev, REPORT_MAX_SIZE,
901 device->buffer, device->buf_dma);
902 input_free_device(device->inputdevice);
904 err("No more memory");
910 * The endpoint is always altsetting 0, we know this since we know
911 * this device only has one interrupt endpoint
913 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
916 dbg("gtco # interfaces: %d",usbinterface->num_altsetting);
917 dbg("num endpoints: %d",usbinterface->cur_altsetting->desc.bNumEndpoints);
918 dbg("interface class: %d",usbinterface->cur_altsetting->desc.bInterfaceClass);
919 dbg("endpoint: attribute:0x%x type:0x%x",endpoint->bmAttributes,endpoint->bDescriptorType);
920 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
921 dbg("endpoint: we have interrupt endpoint\n");
923 dbg("endpoint extra len:%d ",usbinterface->altsetting[0].extralen);
928 * Find the HID descriptor so we can find out the size of the
929 * HID report descriptor
931 if (usb_get_extra_descriptor(usbinterface->cur_altsetting,
932 HID_DEVICE_TYPE,&hid_desc) != 0){
933 err("Can't retrieve exta USB descriptor to get hid report descriptor length");
934 usb_buffer_free(device->usbdev, REPORT_MAX_SIZE,
935 device->buffer, device->buf_dma);
936 input_free_device(device->inputdevice);
941 dbg("Extra descriptor success: type:%d len:%d",
942 hid_desc->bDescriptorType, hid_desc->wDescriptorLength);
944 if (!(report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL))) {
945 usb_buffer_free(device->usbdev, REPORT_MAX_SIZE,
946 device->buffer, device->buf_dma);
948 input_free_device(device->inputdevice);
950 err("No more memory");
954 /* Couple of tries to get reply */
955 for (retry=0;retry<3;retry++) {
956 result = usb_control_msg(device->usbdev,
957 usb_rcvctrlpipe(device->usbdev, 0),
958 USB_REQ_GET_DESCRIPTOR,
959 USB_RECIP_INTERFACE | USB_DIR_IN,
960 (REPORT_DEVICE_TYPE << 8),
963 hid_desc->wDescriptorLength,
966 if (result == hid_desc->wDescriptorLength)
970 /* If we didn't get the report, fail */
971 dbg("usb_control_msg result: :%d", result);
972 if (result != hid_desc->wDescriptorLength){
974 usb_buffer_free(device->usbdev, REPORT_MAX_SIZE,
975 device->buffer, device->buf_dma);
976 input_free_device(device->inputdevice);
978 err("Failed to get HID Report Descriptor of size: %d",
979 hid_desc->wDescriptorLength);
984 /* Now we parse the report */
985 parse_hid_report_descriptor(device,report,result);
987 /* Now we delete it */
990 /* Create a device file node */
991 usb_make_path(device->usbdev, path, PATHLENGTH);
992 sprintf(device->usbpath, "%s/input0", path);
995 /* Set Input device functions */
996 inputdev->open = gtco_input_open;
997 inputdev->close = gtco_input_close;
999 /* Set input device information */
1000 inputdev->name = "GTCO_CalComp";
1001 inputdev->phys = device->usbpath;
1002 inputdev->private = device;
1005 /* Now set up all the input device capabilities */
1006 gtco_setup_caps(inputdev);
1008 /* Set input device required ID information */
1009 usb_to_input_id(device->usbdev, &device->inputdevice->id);
1010 inputdev->cdev.dev = &usbinterface->dev;
1012 /* Setup the URB, it will be posted later on open of input device */
1013 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
1015 usb_fill_int_urb(device->urbinfo,
1017 usb_rcvintpipe(device->usbdev,
1018 endpoint->bEndpointAddress),
1023 endpoint->bInterval);
1025 device->urbinfo->transfer_dma = device->buf_dma;
1026 device->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1029 /* Save device pointer in USB interface device */
1030 usb_set_intfdata(usbinterface, device);
1032 /* All done, now register the input device */
1033 input_register_device(inputdev);
1035 info( "gtco driver created usb: %s\n", path);
1041 * This function is a standard USB function called when the USB device
1042 * is disconnected. We will get rid of the URV, de-register the input
1043 * device, and free up allocated memory
1045 static void gtco_disconnect(struct usb_interface *interface)
1048 /* Grab private device ptr */
1049 struct gtco *device = usb_get_intfdata (interface);
1050 struct input_dev *inputdev;
1052 inputdev = device->inputdevice;
1054 /* Now reverse all the registration stuff */
1056 input_unregister_device(inputdev);
1057 usb_kill_urb(device->urbinfo);
1058 usb_free_urb(device->urbinfo);
1059 usb_buffer_free(device->usbdev, REPORT_MAX_SIZE,
1060 device->buffer, device->buf_dma);
1064 info("gtco driver disconnected");
1068 /* STANDARD MODULE LOAD ROUTINES */
1070 static struct usb_driver gtco_driverinfo_table = {
1071 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
1072 .owner = THIS_MODULE,
1075 .id_table = gtco_usbid_table,
1076 .probe = gtco_probe,
1077 .disconnect = gtco_disconnect,
1080 * Register this module with the USB subsystem
1082 static int __init gtco_init(void)
1085 rc = usb_register(>co_driverinfo_table);
1087 err("usb_register() failed rc=0x%x", rc);
1089 printk("GTCO usb driver version: %s",GTCO_VERSION);
1094 * Deregister this module with the USB subsystem
1096 static void __exit gtco_exit(void)
1098 usb_deregister(>co_driverinfo_table);
1101 module_init (gtco_init);
1102 module_exit (gtco_exit);
1104 MODULE_LICENSE("GPL");