3 GTCO digitizer USB driver
5 TO CHECK: Is pressure done right on report 5?
7 Copyright (C) 2006 GTCO CalComp
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; version 2
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Permission to use, copy, modify, distribute, and sell this software and its
24 documentation for any purpose is hereby granted without fee, provided that
25 the above copyright notice appear in all copies and that both that
26 copyright notice and this permission notice appear in supporting
27 documentation, and that the name of GTCO-CalComp not be used in advertising
28 or publicity pertaining to distribution of the software without specific,
29 written prior permission. GTCO-CalComp makes no representations about the
30 suitability of this software for any purpose. It is provided "as is"
31 without express or implied warranty.
33 GTCO-CALCOMP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
34 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
35 EVENT SHALL GTCO-CALCOMP BE LIABLE FOR ANY SPECIAL, INDIRECT OR
36 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
37 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 TORTIOUS ACTIONS, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 PERFORMANCE OF THIS SOFTWARE.
45 Jeremy Roberson jroberson@gtcocalcomp.com
46 Scott Hill shill@gtcocalcomp.com
53 #include <linux/kernel.h>
54 #include <linux/module.h>
55 #include <linux/errno.h>
56 #include <linux/slab.h>
57 #include <linux/input.h>
58 #include <linux/usb.h>
59 #include <asm/uaccess.h>
60 #include <asm/unaligned.h>
61 #include <asm/byteorder.h>
62 #include <linux/bitops.h>
64 #include <linux/usb/input.h>
66 /* Version with a Major number of 2 is for kernel inclusion only. */
67 #define GTCO_VERSION "2.00.0006"
72 #define VENDOR_ID_GTCO 0x078C
75 #define PID_1000 0x1000
76 #define PID_1001 0x1001
77 #define PID_1002 0x1002
79 /* Max size of a single report */
80 #define REPORT_MAX_SIZE 10
81 #define MAX_COLLECTION_LEVELS 10
84 /* Bitmask whether pen is in range */
85 #define MASK_INRANGE 0x20
86 #define MASK_BUTTON 0x01F
93 static const struct usb_device_id gtco_usbid_table[] = {
94 { USB_DEVICE(VENDOR_ID_GTCO, PID_400) },
95 { USB_DEVICE(VENDOR_ID_GTCO, PID_401) },
96 { USB_DEVICE(VENDOR_ID_GTCO, PID_1000) },
97 { USB_DEVICE(VENDOR_ID_GTCO, PID_1001) },
98 { USB_DEVICE(VENDOR_ID_GTCO, PID_1002) },
101 MODULE_DEVICE_TABLE (usb, gtco_usbid_table);
104 /* Structure to hold all of our device specific stuff */
107 struct input_dev *inputdevice; /* input device struct pointer */
108 struct usb_device *usbdev; /* the usb device for this device */
109 struct usb_interface *intf; /* the usb interface for this device */
110 struct urb *urbinfo; /* urb for incoming reports */
111 dma_addr_t buf_dma; /* dma addr of the data buffer*/
112 unsigned char * buffer; /* databuffer for reports */
114 char usbpath[PATHLENGTH];
117 /* Information pulled from Report Descriptor */
133 /* Code for parsing the HID REPORT DESCRIPTOR */
135 /* From HID1.11 spec */
136 struct hid_descriptor
138 struct usb_descriptor_header header;
143 __le16 wDescriptorLength;
144 } __attribute__ ((packed));
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
188 * This is an abbreviated parser for the HID Report Descriptor. We
189 * know what devices we are talking to, so this is by no means meant
190 * to be generic. We can make some safe assumptions:
192 * - We know there are no LONG tags, all short
193 * - We know that we have no MAIN Feature and MAIN Output items
194 * - We know what the IRQ reports are supposed to look like.
196 * The main purpose of this is to use the HID report desc to figure
197 * out the mins and maxs of the fields in the IRQ reports. The IRQ
198 * reports for 400/401 change slightly if the max X is bigger than 64K.
201 static void parse_hid_report_descriptor(struct gtco *device, char * report,
204 struct device *ddev = &device->intf->dev;
207 /* Tag primitive vars */
216 /* For parsing logic */
220 /* Global Values, indexed by TAG */
221 __u32 globalval[TAG_GLOB_MAX];
222 __u32 oldval[TAG_GLOB_MAX];
228 char indentstr[MAX_COLLECTION_LEVELS + 1] = { 0 };
230 dev_dbg(ddev, "======>>>>>>PARSE<<<<<<======\n");
232 /* Walk this report and pull out the info we need */
234 prefix = report[i++];
236 /* Determine data size and save the data in the proper variable */
237 size = (1U << PREF_SIZE(prefix)) >> 1;
238 if (i + size > length) {
240 "Not enough data (need %d, have %d)\n",
250 data16 = get_unaligned_le16(&report[i]);
253 data32 = get_unaligned_le32(&report[i]);
257 /* Skip size of data */
260 /* What we do depends on the tag type */
261 tag = PREF_TAG(prefix);
262 type = PREF_TYPE(prefix);
265 strcpy(globtype, "");
270 * The INPUT MAIN tag signifies this is
271 * information from a report. We need to
272 * figure out what it is and store the
278 strcpy(globtype, "Variable");
280 strcpy(globtype, "Var|Const");
282 dev_dbg(ddev, "::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits\n",
283 globalval[TAG_GLOB_REPORT_ID], inputnum,
284 globalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX],
285 globalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN],
286 globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]);
290 We can assume that the first two input items
291 are always the X and Y coordinates. After
292 that, we look for everything else by
296 case 0: /* X coord */
297 dev_dbg(ddev, "GER: X Usage: 0x%x\n", usage);
298 if (device->max_X == 0) {
299 device->max_X = globalval[TAG_GLOB_LOG_MAX];
300 device->min_X = globalval[TAG_GLOB_LOG_MIN];
304 case 1: /* Y coord */
305 dev_dbg(ddev, "GER: Y Usage: 0x%x\n", usage);
306 if (device->max_Y == 0) {
307 device->max_Y = globalval[TAG_GLOB_LOG_MAX];
308 device->min_Y = globalval[TAG_GLOB_LOG_MIN];
314 if (usage == DIGITIZER_USAGE_TILT_X) {
315 if (device->maxtilt_X == 0) {
316 device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];
317 device->mintilt_X = globalval[TAG_GLOB_LOG_MIN];
322 if (usage == DIGITIZER_USAGE_TILT_Y) {
323 if (device->maxtilt_Y == 0) {
324 device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];
325 device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];
330 if (usage == DIGITIZER_USAGE_TIP_PRESSURE) {
331 if (device->maxpressure == 0) {
332 device->maxpressure = globalval[TAG_GLOB_LOG_MAX];
333 device->minpressure = globalval[TAG_GLOB_LOG_MIN];
343 case TAG_MAIN_OUTPUT:
347 case TAG_MAIN_FEATURE:
351 case TAG_MAIN_COL_START:
354 if (indent == MAX_COLLECTION_LEVELS) {
355 dev_err(ddev, "Collection level %d would exceed limit of %d\n",
357 MAX_COLLECTION_LEVELS);
362 dev_dbg(ddev, "======>>>>>> Physical\n");
363 strcpy(globtype, "Physical");
365 dev_dbg(ddev, "======>>>>>>\n");
367 /* Indent the debug output */
369 for (x = 0; x < indent; x++)
373 /* Save global tags */
374 for (x = 0; x < TAG_GLOB_MAX; x++)
375 oldval[x] = globalval[x];
379 case TAG_MAIN_COL_END:
383 dev_err(ddev, "Collection level already at zero\n");
387 dev_dbg(ddev, "<<<<<<======\n");
390 for (x = 0; x < indent; x++)
394 /* Copy global tags back */
395 for (x = 0; x < TAG_GLOB_MAX; x++)
396 globalval[x] = oldval[x];
403 dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
404 indentstr, tag, maintype, size, globtype, data);
408 dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
409 indentstr, tag, maintype, size, globtype, data16);
413 dev_dbg(ddev, "%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x\n",
414 indentstr, tag, maintype, size, globtype, data32);
423 * First time we hit the global usage tag,
424 * it should tell us the type of device
426 if (device->usage == 0)
427 device->usage = data;
429 strcpy(globtype, "USAGE");
432 case TAG_GLOB_LOG_MIN:
433 strcpy(globtype, "LOG_MIN");
436 case TAG_GLOB_LOG_MAX:
437 strcpy(globtype, "LOG_MAX");
440 case TAG_GLOB_PHYS_MIN:
441 strcpy(globtype, "PHYS_MIN");
444 case TAG_GLOB_PHYS_MAX:
445 strcpy(globtype, "PHYS_MAX");
448 case TAG_GLOB_UNIT_EXP:
449 strcpy(globtype, "EXP");
453 strcpy(globtype, "UNIT");
456 case TAG_GLOB_REPORT_SZ:
457 strcpy(globtype, "REPORT_SZ");
460 case TAG_GLOB_REPORT_ID:
461 strcpy(globtype, "REPORT_ID");
462 /* New report, restart numbering */
466 case TAG_GLOB_REPORT_CNT:
467 strcpy(globtype, "REPORT_CNT");
471 strcpy(globtype, "PUSH");
475 strcpy(globtype, "POP");
479 /* Check to make sure we have a good tag number
480 so we don't overflow array */
481 if (tag < TAG_GLOB_MAX) {
484 dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
485 indentstr, globtype, tag, size, data);
486 globalval[tag] = data;
490 dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
491 indentstr, globtype, tag, size, data16);
492 globalval[tag] = data16;
496 dev_dbg(ddev, "%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x\n",
497 indentstr, globtype, tag, size, data32);
498 globalval[tag] = data32;
502 dev_dbg(ddev, "%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d\n",
503 indentstr, tag, size);
510 strcpy(globtype, "USAGE");
515 case TAG_GLOB_LOG_MIN:
516 strcpy(globtype, "MIN");
519 case TAG_GLOB_LOG_MAX:
520 strcpy(globtype, "MAX");
524 strcpy(globtype, "UNKNOWN");
530 dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
531 indentstr, tag, globtype, size, data);
535 dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
536 indentstr, tag, globtype, size, data16);
540 dev_dbg(ddev, "%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x\n",
541 indentstr, tag, globtype, size, data32);
550 /* INPUT DRIVER Routines */
553 * Called when opening the input device. This will submit the URB to
554 * the usb system so we start getting reports
556 static int gtco_input_open(struct input_dev *inputdev)
558 struct gtco *device = input_get_drvdata(inputdev);
560 device->urbinfo->dev = device->usbdev;
561 if (usb_submit_urb(device->urbinfo, GFP_KERNEL))
568 * Called when closing the input device. This will unlink the URB
570 static void gtco_input_close(struct input_dev *inputdev)
572 struct gtco *device = input_get_drvdata(inputdev);
574 usb_kill_urb(device->urbinfo);
579 * Setup input device capabilities. Tell the input system what this
580 * device is capable of generating.
582 * This information is based on what is read from the HID report and
583 * placed in the struct gtco structure
586 static void gtco_setup_caps(struct input_dev *inputdev)
588 struct gtco *device = input_get_drvdata(inputdev);
591 inputdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) |
594 /* Misc event menu block */
595 inputdev->mscbit[0] = BIT_MASK(MSC_SCAN) | BIT_MASK(MSC_SERIAL) |
598 /* Absolute values based on HID report info */
599 input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X,
601 input_set_abs_params(inputdev, ABS_Y, device->min_Y, device->max_Y,
605 input_set_abs_params(inputdev, ABS_DISTANCE, 0, 1, 0, 0);
607 /* Tilt & pressure */
608 input_set_abs_params(inputdev, ABS_TILT_X, device->mintilt_X,
609 device->maxtilt_X, 0, 0);
610 input_set_abs_params(inputdev, ABS_TILT_Y, device->mintilt_Y,
611 device->maxtilt_Y, 0, 0);
612 input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure,
613 device->maxpressure, 0, 0);
616 input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0);
622 * URB callback routine. Called when we get IRQ reports from the
625 * This bridges the USB and input device worlds. It generates events
626 * on the input device based on the USB reports.
628 static void gtco_urb_callback(struct urb *urbinfo)
630 struct gtco *device = urbinfo->context;
631 struct input_dev *inputdev;
636 inputdev = device->inputdevice;
638 /* Was callback OK? */
639 if (urbinfo->status == -ECONNRESET ||
640 urbinfo->status == -ENOENT ||
641 urbinfo->status == -ESHUTDOWN) {
643 /* Shutdown is occurring. Return and don't queue up any more */
647 if (urbinfo->status != 0) {
649 * Some unknown error. Hopefully temporary. Just go and
656 * Good URB, now process
659 /* PID dependent when we interpret the report */
660 if (inputdev->id.product == PID_1000 ||
661 inputdev->id.product == PID_1001 ||
662 inputdev->id.product == PID_1002) {
665 * Switch on the report ID
666 * Conveniently, the reports have more information, the higher
667 * the report number. We can just fall through the case
668 * statements if we start with the highest number report
670 switch (device->buffer[0]) {
672 /* Pressure is 9 bits */
673 val = ((u16)(device->buffer[8]) << 1);
674 val |= (u16)(device->buffer[7] >> 7);
675 input_report_abs(inputdev, ABS_PRESSURE,
678 /* Mask out the Y tilt value used for pressure */
679 device->buffer[7] = (u8)((device->buffer[7]) & 0x7F);
684 input_report_abs(inputdev, ABS_TILT_X,
685 sign_extend32(device->buffer[6], 6));
687 input_report_abs(inputdev, ABS_TILT_Y,
688 sign_extend32(device->buffer[7], 6));
693 /* Convert buttons, only 5 bits possible */
694 val = (device->buffer[5]) & MASK_BUTTON;
696 /* We don't apply any meaning to the bitmask,
698 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
702 /* All reports have X and Y coords in the same place */
703 val = get_unaligned_le16(&device->buffer[1]);
704 input_report_abs(inputdev, ABS_X, val);
706 val = get_unaligned_le16(&device->buffer[3]);
707 input_report_abs(inputdev, ABS_Y, val);
709 /* Ditto for proximity bit */
710 val = device->buffer[5] & MASK_INRANGE ? 1 : 0;
711 input_report_abs(inputdev, ABS_DISTANCE, val);
713 /* Report 1 is an exception to how we handle buttons */
714 /* Buttons are an index, not a bitmask */
715 if (device->buffer[0] == 1) {
718 * Convert buttons, 5 bit index
719 * Report value of index set as one,
722 val = device->buffer[5] & MASK_BUTTON;
723 dev_dbg(&device->intf->dev,
724 "======>>>>>>REPORT 1: val 0x%X(%d)\n",
728 * We don't apply any meaning to the button
729 * index, just report it
731 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
737 input_event(inputdev, EV_MSC, MSC_SCAN,
743 /* Other pid class */
744 if (inputdev->id.product == PID_400 ||
745 inputdev->id.product == PID_401) {
748 if (device->buffer[0] == 2) {
750 input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]);
754 if (device->buffer[0] == 1) {
757 /* IF X max > 64K, we still a bit from the y report */
758 if (device->max_X > 0x10000) {
760 val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]);
761 val |= (u32)(((u8)device->buffer[3] & 0x1) << 16);
763 input_report_abs(inputdev, ABS_X, val);
765 le_buffer[0] = (u8)((u8)(device->buffer[3]) >> 1);
766 le_buffer[0] |= (u8)((device->buffer[3] & 0x1) << 7);
768 le_buffer[1] = (u8)(device->buffer[4] >> 1);
769 le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7);
771 val = get_unaligned_le16(le_buffer);
772 input_report_abs(inputdev, ABS_Y, val);
775 * Shift the button byte right by one to
776 * make it look like the standard report
778 buttonbyte = device->buffer[5] >> 1;
781 val = get_unaligned_le16(&device->buffer[1]);
782 input_report_abs(inputdev, ABS_X, val);
784 val = get_unaligned_le16(&device->buffer[3]);
785 input_report_abs(inputdev, ABS_Y, val);
787 buttonbyte = device->buffer[5];
790 /* BUTTONS and PROXIMITY */
791 val = buttonbyte & MASK_INRANGE ? 1 : 0;
792 input_report_abs(inputdev, ABS_DISTANCE, val);
794 /* Convert buttons, only 4 bits possible */
795 val = buttonbyte & 0x0F;
797 for (i = 0; i < 5; i++)
798 input_report_key(inputdev, BTN_DIGI + i, val & (1 << i));
800 /* We don't apply any meaning to the bitmask, just report */
801 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
805 input_report_abs(inputdev, ABS_MISC, device->buffer[6]);
809 /* Everybody gets report ID's */
810 input_event(inputdev, EV_MSC, MSC_RAW, device->buffer[0]);
813 input_sync(inputdev);
816 rc = usb_submit_urb(urbinfo, GFP_ATOMIC);
818 dev_err(&device->intf->dev,
819 "usb_submit_urb failed rc=0x%x\n", rc);
823 * The probe routine. This is called when the kernel find the matching USB
824 * vendor/product. We do the following:
826 * - Allocate mem for a local structure to manage the device
827 * - Request a HID Report Descriptor from the device and parse it to
828 * find out the device parameters
829 * - Create an input device and assign it attributes
830 * - Allocate an URB so the device can talk to us when the input
833 static int gtco_probe(struct usb_interface *usbinterface,
834 const struct usb_device_id *id)
838 struct input_dev *input_dev;
839 struct hid_descriptor *hid_desc;
841 int result = 0, retry;
843 struct usb_endpoint_descriptor *endpoint;
845 /* Allocate memory for device structure */
846 gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL);
847 input_dev = input_allocate_device();
848 if (!gtco || !input_dev) {
849 dev_err(&usbinterface->dev, "No more memory\n");
854 /* Set pointer to the input device */
855 gtco->inputdevice = input_dev;
857 /* Save interface information */
858 gtco->usbdev = interface_to_usbdev(usbinterface);
859 gtco->intf = usbinterface;
861 /* Allocate some data for incoming reports */
862 gtco->buffer = usb_alloc_coherent(gtco->usbdev, REPORT_MAX_SIZE,
863 GFP_KERNEL, >co->buf_dma);
865 dev_err(&usbinterface->dev, "No more memory for us buffers\n");
870 /* Allocate URB for reports */
871 gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL);
872 if (!gtco->urbinfo) {
873 dev_err(&usbinterface->dev, "Failed to allocate URB\n");
878 /* Sanity check that a device has an endpoint */
879 if (usbinterface->altsetting[0].desc.bNumEndpoints < 1) {
880 dev_err(&usbinterface->dev,
881 "Invalid number of endpoints\n");
887 * The endpoint is always altsetting 0, we know this since we know
888 * this device only has one interrupt endpoint
890 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
893 dev_dbg(&usbinterface->dev, "gtco # interfaces: %d\n", usbinterface->num_altsetting);
894 dev_dbg(&usbinterface->dev, "num endpoints: %d\n", usbinterface->cur_altsetting->desc.bNumEndpoints);
895 dev_dbg(&usbinterface->dev, "interface class: %d\n", usbinterface->cur_altsetting->desc.bInterfaceClass);
896 dev_dbg(&usbinterface->dev, "endpoint: attribute:0x%x type:0x%x\n", endpoint->bmAttributes, endpoint->bDescriptorType);
897 if (usb_endpoint_xfer_int(endpoint))
898 dev_dbg(&usbinterface->dev, "endpoint: we have interrupt endpoint\n");
900 dev_dbg(&usbinterface->dev, "endpoint extra len:%d\n", usbinterface->altsetting[0].extralen);
903 * Find the HID descriptor so we can find out the size of the
904 * HID report descriptor
906 if (usb_get_extra_descriptor(usbinterface->cur_altsetting,
907 HID_DEVICE_TYPE, &hid_desc) != 0) {
908 dev_err(&usbinterface->dev,
909 "Can't retrieve exta USB descriptor to get hid report descriptor length\n");
914 dev_dbg(&usbinterface->dev,
915 "Extra descriptor success: type:%d len:%d\n",
916 hid_desc->bDescriptorType, hid_desc->wDescriptorLength);
918 report = kzalloc(le16_to_cpu(hid_desc->wDescriptorLength), GFP_KERNEL);
920 dev_err(&usbinterface->dev, "No more memory for report\n");
925 /* Couple of tries to get reply */
926 for (retry = 0; retry < 3; retry++) {
927 result = usb_control_msg(gtco->usbdev,
928 usb_rcvctrlpipe(gtco->usbdev, 0),
929 USB_REQ_GET_DESCRIPTOR,
930 USB_RECIP_INTERFACE | USB_DIR_IN,
931 REPORT_DEVICE_TYPE << 8,
934 le16_to_cpu(hid_desc->wDescriptorLength),
937 dev_dbg(&usbinterface->dev, "usb_control_msg result: %d\n", result);
938 if (result == le16_to_cpu(hid_desc->wDescriptorLength)) {
939 parse_hid_report_descriptor(gtco, report, result);
946 /* If we didn't get the report, fail */
947 if (result != le16_to_cpu(hid_desc->wDescriptorLength)) {
948 dev_err(&usbinterface->dev,
949 "Failed to get HID Report Descriptor of size: %d\n",
950 hid_desc->wDescriptorLength);
955 /* Create a device file node */
956 usb_make_path(gtco->usbdev, gtco->usbpath, sizeof(gtco->usbpath));
957 strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath));
959 /* Set Input device functions */
960 input_dev->open = gtco_input_open;
961 input_dev->close = gtco_input_close;
963 /* Set input device information */
964 input_dev->name = "GTCO_CalComp";
965 input_dev->phys = gtco->usbpath;
967 input_set_drvdata(input_dev, gtco);
969 /* Now set up all the input device capabilities */
970 gtco_setup_caps(input_dev);
972 /* Set input device required ID information */
973 usb_to_input_id(gtco->usbdev, &input_dev->id);
974 input_dev->dev.parent = &usbinterface->dev;
976 /* Setup the URB, it will be posted later on open of input device */
977 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
979 usb_fill_int_urb(gtco->urbinfo,
981 usb_rcvintpipe(gtco->usbdev,
982 endpoint->bEndpointAddress),
987 endpoint->bInterval);
989 gtco->urbinfo->transfer_dma = gtco->buf_dma;
990 gtco->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
992 /* Save gtco pointer in USB interface gtco */
993 usb_set_intfdata(usbinterface, gtco);
995 /* All done, now register the input device */
996 error = input_register_device(input_dev);
1003 usb_free_urb(gtco->urbinfo);
1005 usb_free_coherent(gtco->usbdev, REPORT_MAX_SIZE,
1006 gtco->buffer, gtco->buf_dma);
1008 input_free_device(input_dev);
1014 * This function is a standard USB function called when the USB device
1015 * is disconnected. We will get rid of the URV, de-register the input
1016 * device, and free up allocated memory
1018 static void gtco_disconnect(struct usb_interface *interface)
1020 /* Grab private device ptr */
1021 struct gtco *gtco = usb_get_intfdata(interface);
1023 /* Now reverse all the registration stuff */
1025 input_unregister_device(gtco->inputdevice);
1026 usb_kill_urb(gtco->urbinfo);
1027 usb_free_urb(gtco->urbinfo);
1028 usb_free_coherent(gtco->usbdev, REPORT_MAX_SIZE,
1029 gtco->buffer, gtco->buf_dma);
1033 dev_info(&interface->dev, "gtco driver disconnected\n");
1036 /* STANDARD MODULE LOAD ROUTINES */
1038 static struct usb_driver gtco_driverinfo_table = {
1040 .id_table = gtco_usbid_table,
1041 .probe = gtco_probe,
1042 .disconnect = gtco_disconnect,
1045 module_usb_driver(gtco_driverinfo_table);
1047 MODULE_DESCRIPTION("GTCO digitizer USB driver");
1048 MODULE_LICENSE("GPL");