From 1b726a02d97cef2471521ae6947416f7374c6590 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 12 Apr 2007 01:33:00 -0400 Subject: Input: gtco - handle errors from input_register_device() Also fix URB leak in gtco_probe error path, formatting fixes. Signed-off-by: Dmitry Torokhov --- drivers/usb/input/gtco.c | 627 ++++++++++++++++++++++------------------------- 1 file changed, 289 insertions(+), 338 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index 203cdc1bbba..aa9c676ca79 100644 --- a/drivers/usb/input/gtco.c +++ b/drivers/usb/input/gtco.c @@ -187,7 +187,6 @@ struct hid_descriptor /* - * * This is an abbreviated parser for the HID Report Descriptor. We * know what devices we are talking to, so this is by no means meant * to be generic. We can make some safe assumptions: @@ -204,7 +203,7 @@ struct hid_descriptor static void parse_hid_report_descriptor(struct gtco *device, char * report, int length) { - int x,i=0; + int x, i = 0; /* Tag primitive vars */ __u8 prefix; @@ -215,7 +214,6 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, __u16 data16 = 0; __u32 data32 = 0; - /* For parsing logic */ int inputnum = 0; __u32 usage = 0; @@ -227,44 +225,44 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, /* Debug stuff */ char maintype='x'; char globtype[12]; - int indent=0; - char indentstr[10]=""; - + int indent = 0; + char indentstr[10] = ""; dbg("======>>>>>>PARSE<<<<<<======"); /* Walk this report and pull out the info we need */ - while (imax_X == 0){ + dbg("GER: X Usage: 0x%x", usage); + if (device->max_X == 0) { device->max_X = globalval[TAG_GLOB_LOG_MAX]; device->min_X = globalval[TAG_GLOB_LOG_MIN]; } - break; + case 1: /* Y coord */ - dbg("GER: Y Usage: 0x%x",usage); - if (device->max_Y == 0){ + dbg("GER: Y Usage: 0x%x", usage); + if (device->max_Y == 0) { device->max_Y = globalval[TAG_GLOB_LOG_MAX]; device->min_Y = globalval[TAG_GLOB_LOG_MIN]; } break; + default: /* Tilt X */ - if (usage == DIGITIZER_USAGE_TILT_X){ - if (device->maxtilt_X == 0){ + if (usage == DIGITIZER_USAGE_TILT_X) { + if (device->maxtilt_X == 0) { device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX]; device->mintilt_X = globalval[TAG_GLOB_LOG_MIN]; } } /* Tilt Y */ - if (usage == DIGITIZER_USAGE_TILT_Y){ - if (device->maxtilt_Y == 0){ + if (usage == DIGITIZER_USAGE_TILT_Y) { + if (device->maxtilt_Y == 0) { device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX]; device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN]; } } - /* Pressure */ - if (usage == DIGITIZER_USAGE_TIP_PRESSURE){ - if (device->maxpressure == 0){ + if (usage == DIGITIZER_USAGE_TIP_PRESSURE) { + if (device->maxpressure == 0) { device->maxpressure = globalval[TAG_GLOB_LOG_MAX]; device->minpressure = globalval[TAG_GLOB_LOG_MIN]; } @@ -341,192 +337,206 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, } inputnum++; - - break; + case TAG_MAIN_OUTPUT: - maintype='O'; + maintype = 'O'; break; + case TAG_MAIN_FEATURE: - maintype='F'; + maintype = 'F'; break; + case TAG_MAIN_COL_START: - maintype='S'; + maintype = 'S'; - if (data==0){ + if (data == 0) { dbg("======>>>>>> Physical"); - strcpy(globtype,"Physical"); - }else{ + strcpy(globtype, "Physical"); + } else dbg("======>>>>>>"); - } /* Indent the debug output */ indent++; - for (x=0;xusage == 0){ + if (device->usage == 0) device->usage = data; - } - strcpy(globtype,"USAGE"); + + strcpy(globtype, "USAGE"); break; - case TAG_GLOB_LOG_MIN : - strcpy(globtype,"LOG_MIN"); + + case TAG_GLOB_LOG_MIN: + strcpy(globtype, "LOG_MIN"); break; - case TAG_GLOB_LOG_MAX : - strcpy(globtype,"LOG_MAX"); + + case TAG_GLOB_LOG_MAX: + strcpy(globtype, "LOG_MAX"); break; - case TAG_GLOB_PHYS_MIN : - strcpy(globtype,"PHYS_MIN"); + + case TAG_GLOB_PHYS_MIN: + strcpy(globtype, "PHYS_MIN"); break; - case TAG_GLOB_PHYS_MAX : - strcpy(globtype,"PHYS_MAX"); + + case TAG_GLOB_PHYS_MAX: + strcpy(globtype, "PHYS_MAX"); break; - case TAG_GLOB_UNIT_EXP : - strcpy(globtype,"EXP"); + + case TAG_GLOB_UNIT_EXP: + strcpy(globtype, "EXP"); break; - case TAG_GLOB_UNIT : - strcpy(globtype,"UNIT"); + + case TAG_GLOB_UNIT: + strcpy(globtype, "UNIT"); break; - case TAG_GLOB_REPORT_SZ : - strcpy(globtype,"REPORT_SZ"); + + case TAG_GLOB_REPORT_SZ: + strcpy(globtype, "REPORT_SZ"); break; - case TAG_GLOB_REPORT_ID : - strcpy(globtype,"REPORT_ID"); + + case TAG_GLOB_REPORT_ID: + strcpy(globtype, "REPORT_ID"); /* New report, restart numbering */ - inputnum=0; + inputnum = 0; break; + case TAG_GLOB_REPORT_CNT: - strcpy(globtype,"REPORT_CNT"); + strcpy(globtype, "REPORT_CNT"); break; - case TAG_GLOB_PUSH : - strcpy(globtype,"PUSH"); + + case TAG_GLOB_PUSH: + strcpy(globtype, "PUSH"); break; + case TAG_GLOB_POP: - strcpy(globtype,"POP"); + strcpy(globtype, "POP"); break; } - /* Check to make sure we have a good tag number so we don't overflow array */ - if (tag < TAG_GLOB_MAX){ - switch (size){ + if (tag < TAG_GLOB_MAX) { + switch (size) { case 1: - dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data); - globalval[tag]=data; + dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", + indentstr, globtype, tag, size, data); + globalval[tag] = data; break; + case 2: - dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data16); - globalval[tag]=data16; + dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", + indentstr, globtype, tag, size, data16); + globalval[tag] = data16; break; + case 4: - dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",indentstr,globtype,tag,size,data32); - globalval[tag]=data32; + dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x", + indentstr, globtype, tag, size, data32); + globalval[tag] = data32; break; } - }else{ + } else { dbg("%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d ", - indentstr,tag,size); + indentstr, tag, size); } - - break; case TYPE_LOCAL: - switch(tag){ + switch (tag) { case TAG_GLOB_USAGE: - strcpy(globtype,"USAGE"); + strcpy(globtype, "USAGE"); /* Always 1 byte */ usage = data; break; - case TAG_GLOB_LOG_MIN : - strcpy(globtype,"MIN"); + + case TAG_GLOB_LOG_MIN: + strcpy(globtype, "MIN"); break; - case TAG_GLOB_LOG_MAX : - strcpy(globtype,"MAX"); + + case TAG_GLOB_LOG_MAX: + strcpy(globtype, "MAX"); break; + default: - strcpy(globtype,"UNKNOWN"); + strcpy(globtype, "UNKNOWN"); + break; } - switch (size){ + switch (size) { case 1: dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", - indentstr,tag,globtype,size,data); + indentstr, tag, globtype, size, data); break; + case 2: dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", - indentstr,tag,globtype,size,data16); + indentstr, tag, globtype, size, data16); break; + case 4: dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x", - indentstr,tag,globtype,size,data32); + indentstr, tag, globtype, size, data32); break; } break; } - } - } - - /* INPUT DRIVER Routines */ - /* - * Called when opening the input device. This will submit the URB to - * the usb system so we start getting reports + * Called when opening the input device. This will submit the URB to + * the usb system so we start getting reports */ static int gtco_input_open(struct input_dev *inputdev) { @@ -534,21 +544,20 @@ static int gtco_input_open(struct input_dev *inputdev) device = inputdev->private; device->urbinfo->dev = device->usbdev; - if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) { + if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) return -EIO; - } + return 0; } -/** - Called when closing the input device. This will unlink the URB -*/ +/* + * Called when closing the input device. This will unlink the URB + */ static void gtco_input_close(struct input_dev *inputdev) { struct gtco *device = inputdev->private; usb_kill_urb(device->urbinfo); - } @@ -564,15 +573,12 @@ static void gtco_setup_caps(struct input_dev *inputdev) { struct gtco *device = inputdev->private; - /* Which events */ inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); - /* Misc event menu block */ inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ; - /* Absolute values based on HID report info */ input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X, 0, 0); @@ -590,17 +596,12 @@ static void gtco_setup_caps(struct input_dev *inputdev) input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure, device->maxpressure, 0, 0); - /* Transducer */ - input_set_abs_params(inputdev, ABS_MISC, 0,0xFF, 0, 0); - + input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0); } - - /* USB Routines */ - /* * URB callback routine. Called when we get IRQ reports from the * digitizer. @@ -610,9 +611,7 @@ static void gtco_setup_caps(struct input_dev *inputdev) */ static void gtco_urb_callback(struct urb *urbinfo) { - - - struct gtco *device = urbinfo->context; + struct gtco *device = urbinfo->context; struct input_dev *inputdev; int rc; u32 val = 0; @@ -621,19 +620,20 @@ static void gtco_urb_callback(struct urb *urbinfo) inputdev = device->inputdevice; - /* Was callback OK? */ - if ((urbinfo->status == -ECONNRESET ) || - (urbinfo->status == -ENOENT ) || - (urbinfo->status == -ESHUTDOWN )){ + if (urbinfo->status == -ECONNRESET || + urbinfo->status == -ENOENT || + urbinfo->status == -ESHUTDOWN) { /* Shutdown is occurring. Return and don't queue up any more */ return; } - if (urbinfo->status != 0 ) { - /* Some unknown error. Hopefully temporary. Just go and */ - /* requeue an URB */ + if (urbinfo->status != 0) { + /* + * Some unknown error. Hopefully temporary. Just go and + * requeue an URB + */ goto resubmit; } @@ -642,10 +642,9 @@ static void gtco_urb_callback(struct urb *urbinfo) */ /* PID dependent when we interpret the report */ - if ((inputdev->id.product == PID_1000 )|| - (inputdev->id.product == PID_1001 )|| - (inputdev->id.product == PID_1002 )) - { + if (inputdev->id.product == PID_1000 || + inputdev->id.product == PID_1001 || + inputdev->id.product == PID_1002) { /* * Switch on the report ID @@ -653,10 +652,10 @@ static void gtco_urb_callback(struct urb *urbinfo) * the report number. We can just fall through the case * statements if we start with the highest number report */ - switch(device->buffer[0]){ + switch (device->buffer[0]) { case 5: /* Pressure is 9 bits */ - val = ((u16)(device->buffer[8]) << 1); + val = ((u16)(device->buffer[8]) << 1); val |= (u16)(device->buffer[7] >> 7); input_report_abs(inputdev, ABS_PRESSURE, device->buffer[8]); @@ -664,7 +663,6 @@ static void gtco_urb_callback(struct urb *urbinfo) /* Mask out the Y tilt value used for pressure */ device->buffer[7] = (u8)((device->buffer[7]) & 0x7F); - /* Fall thru */ case 4: /* Tilt */ @@ -684,11 +682,10 @@ static void gtco_urb_callback(struct urb *urbinfo) input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned); /* Fall thru */ - case 2: case 3: /* Convert buttons, only 5 bits possible */ - val = (device->buffer[5])&MASK_BUTTON; + val = (device->buffer[5]) & MASK_BUTTON; /* We don't apply any meaning to the bitmask, just report */ @@ -696,132 +693,109 @@ static void gtco_urb_callback(struct urb *urbinfo) /* Fall thru */ case 1: - /* All reports have X and Y coords in the same place */ - val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[1]))); + val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); input_report_abs(inputdev, ABS_X, val); - val = le16_to_cpu(get_unaligned((__le16 *) &(device->buffer[3]))); + val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); input_report_abs(inputdev, ABS_Y, val); - /* Ditto for proximity bit */ - if (device->buffer[5]& MASK_INRANGE){ - val = 1; - }else{ - val=0; - } + val = device->buffer[5] & MASK_INRANGE ? 1 : 0; input_report_abs(inputdev, ABS_DISTANCE, val); - /* Report 1 is an exception to how we handle buttons */ /* Buttons are an index, not a bitmask */ - if (device->buffer[0] == 1){ + if (device->buffer[0] == 1) { - /* Convert buttons, 5 bit index */ - /* Report value of index set as one, - the rest as 0 */ - val = device->buffer[5]& MASK_BUTTON; + /* + * Convert buttons, 5 bit index + * Report value of index set as one, + * the rest as 0 + */ + val = device->buffer[5] & MASK_BUTTON; dbg("======>>>>>>REPORT 1: val 0x%X(%d)", - val,val); + val, val); /* * We don't apply any meaning to the button * index, just report it */ input_event(inputdev, EV_MSC, MSC_SERIAL, val); - - } - break; + case 7: /* Menu blocks */ input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]); - - break; - } - - } + /* Other pid class */ - if ((inputdev->id.product == PID_400 )|| - (inputdev->id.product == PID_401 )) - { + if (inputdev->id.product == PID_400 || + inputdev->id.product == PID_401) { /* Report 2 */ - if (device->buffer[0] == 2){ + if (device->buffer[0] == 2) { /* Menu blocks */ - input_event(inputdev, EV_MSC, MSC_SCAN, - device->buffer[1]); + input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]); } /* Report 1 */ - if (device->buffer[0] == 1){ + if (device->buffer[0] == 1) { char buttonbyte; - /* IF X max > 64K, we still a bit from the y report */ - if (device->max_X > 0x10000){ + if (device->max_X > 0x10000) { - val = (u16)(((u16)(device->buffer[2]<<8))|((u8)(device->buffer[1]))); - val |= (u32)(((u8)device->buffer[3]&0x1)<< 16); + val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]); + val |= (u32)(((u8)device->buffer[3] & 0x1) << 16); input_report_abs(inputdev, ABS_X, val); - le_buffer[0] = (u8)((u8)(device->buffer[3])>>1); - le_buffer[0] |= (u8)((device->buffer[3]&0x1)<<7); - - le_buffer[1] = (u8)(device->buffer[4]>>1); - le_buffer[1] |= (u8)((device->buffer[5]&0x1)<<7); + le_buffer[0] = (u8)((u8)(device->buffer[3]) >> 1); + le_buffer[0] |= (u8)((device->buffer[3] & 0x1) << 7); - val = le16_to_cpu(get_unaligned((__le16 *)(le_buffer))); + le_buffer[1] = (u8)(device->buffer[4] >> 1); + le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7); + val = le16_to_cpu(get_unaligned((__le16 *)le_buffer)); input_report_abs(inputdev, ABS_Y, val); - /* * Shift the button byte right by one to * make it look like the standard report */ - buttonbyte = (device->buffer[5])>>1; - }else{ + buttonbyte = device->buffer[5] >> 1; + } else { - val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[1])))); + val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1])); input_report_abs(inputdev, ABS_X, val); - val = le16_to_cpu(get_unaligned((__le16 *) (&(device->buffer[3])))); + val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3])); input_report_abs(inputdev, ABS_Y, val); buttonbyte = device->buffer[5]; - } - /* BUTTONS and PROXIMITY */ - if (buttonbyte& MASK_INRANGE){ - val = 1; - }else{ - val=0; - } + val = buttonbyte & MASK_INRANGE ? 1 : 0; input_report_abs(inputdev, ABS_DISTANCE, val); /* Convert buttons, only 4 bits possible */ - val = buttonbyte&0x0F; + val = buttonbyte & 0x0F; #ifdef USE_BUTTONS - for ( i=0;i<5;i++){ - input_report_key(inputdev, BTN_DIGI+i,val&(1<buffer[6]); - } } @@ -833,10 +807,8 @@ static void gtco_urb_callback(struct urb *urbinfo) resubmit: rc = usb_submit_urb(urbinfo, GFP_ATOMIC); - if (rc != 0) { - err("usb_submit_urb failed rc=0x%x",rc); - } - + if (rc != 0) + err("usb_submit_urb failed rc=0x%x", rc); } /* @@ -854,58 +826,46 @@ static int gtco_probe(struct usb_interface *usbinterface, const struct usb_device_id *id) { - struct gtco *device = NULL; - char path[PATHLENGTH]; - struct input_dev *inputdev; + struct gtco *gtco; + struct input_dev *input_dev; struct hid_descriptor *hid_desc; - char *report; - int result=0, retry; + char *report = NULL; + int result = 0, retry; + int error; struct usb_endpoint_descriptor *endpoint; /* Allocate memory for device structure */ - device = kzalloc(sizeof(struct gtco), GFP_KERNEL); - if (device == NULL) { + gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL); + input_dev = input_allocate_device(); + if (!gtco || !input_dev) { err("No more memory"); - return -ENOMEM; + error = -ENOMEM; + goto err_free_devs; } - - device->inputdevice = input_allocate_device(); - if (!device->inputdevice){ - kfree(device); - err("No more memory"); - return -ENOMEM; - } - - /* Get pointer to the input device */ - inputdev = device->inputdevice; + /* Set pointer to the input device */ + gtco->inputdevice = input_dev; /* Save interface information */ - device->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); - + gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); /* Allocate some data for incoming reports */ - device->buffer = usb_buffer_alloc(device->usbdev, REPORT_MAX_SIZE, - GFP_KERNEL, &(device->buf_dma)); - if (!device->buffer){ - input_free_device(device->inputdevice); - kfree(device); - err("No more memory"); - return -ENOMEM; + gtco->buffer = usb_buffer_alloc(gtco->usbdev, REPORT_MAX_SIZE, + GFP_KERNEL, >co->buf_dma); + if (!gtco->buffer) { + err("No more memory for us buffers"); + error = -ENOMEM; + goto err_free_devs; } /* Allocate URB for reports */ - device->urbinfo = usb_alloc_urb(0, GFP_KERNEL); - if (!device->urbinfo) { - usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, - device->buffer, device->buf_dma); - input_free_device(device->inputdevice); - kfree(device); - err("No more memory"); + gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL); + if (!gtco->urbinfo) { + err("Failed to allocate URB"); return -ENOMEM; + goto err_free_buf; } - /* * The endpoint is always altsetting 0, we know this since we know * this device only has one interrupt endpoint @@ -913,51 +873,43 @@ static int gtco_probe(struct usb_interface *usbinterface, endpoint = &usbinterface->altsetting[0].endpoint[0].desc; /* Some debug */ - dbg("gtco # interfaces: %d",usbinterface->num_altsetting); - dbg("num endpoints: %d",usbinterface->cur_altsetting->desc.bNumEndpoints); - dbg("interface class: %d",usbinterface->cur_altsetting->desc.bInterfaceClass); - dbg("endpoint: attribute:0x%x type:0x%x",endpoint->bmAttributes,endpoint->bDescriptorType); + dbg("gtco # interfaces: %d", usbinterface->num_altsetting); + dbg("num endpoints: %d", usbinterface->cur_altsetting->desc.bNumEndpoints); + dbg("interface class: %d", usbinterface->cur_altsetting->desc.bInterfaceClass); + dbg("endpoint: attribute:0x%x type:0x%x", endpoint->bmAttributes, endpoint->bDescriptorType); if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) dbg("endpoint: we have interrupt endpoint\n"); - dbg("endpoint extra len:%d ",usbinterface->altsetting[0].extralen); - - + dbg("endpoint extra len:%d ", usbinterface->altsetting[0].extralen); /* * Find the HID descriptor so we can find out the size of the * HID report descriptor */ if (usb_get_extra_descriptor(usbinterface->cur_altsetting, - HID_DEVICE_TYPE,&hid_desc) != 0){ + HID_DEVICE_TYPE, &hid_desc) != 0){ err("Can't retrieve exta USB descriptor to get hid report descriptor length"); - usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, - device->buffer, device->buf_dma); - input_free_device(device->inputdevice); - kfree(device); - return -EIO; + error = -EIO; + goto err_free_urb; } dbg("Extra descriptor success: type:%d len:%d", hid_desc->bDescriptorType, hid_desc->wDescriptorLength); - if (!(report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL))) { - usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, - device->buffer, device->buf_dma); - - input_free_device(device->inputdevice); - kfree(device); - err("No more memory"); - return -ENOMEM; + report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); + if (!report) { + err("No more memory for report"); + error = -ENOMEM; + goto err_free_urb; } /* Couple of tries to get reply */ - for (retry=0;retry<3;retry++) { - result = usb_control_msg(device->usbdev, - usb_rcvctrlpipe(device->usbdev, 0), + for (retry = 0; retry < 3; retry++) { + result = usb_control_msg(gtco->usbdev, + usb_rcvctrlpipe(gtco->usbdev, 0), USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, - (REPORT_DEVICE_TYPE << 8), + REPORT_DEVICE_TYPE << 8, 0, /* interface */ report, hid_desc->wDescriptorLength, @@ -969,72 +921,75 @@ static int gtco_probe(struct usb_interface *usbinterface, /* If we didn't get the report, fail */ dbg("usb_control_msg result: :%d", result); - if (result != hid_desc->wDescriptorLength){ - kfree(report); - usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, - device->buffer, device->buf_dma); - input_free_device(device->inputdevice); - kfree(device); + if (result != hid_desc->wDescriptorLength) { err("Failed to get HID Report Descriptor of size: %d", hid_desc->wDescriptorLength); - return -EIO; + error = -EIO; + goto err_free_urb; } - /* Now we parse the report */ - parse_hid_report_descriptor(device,report,result); + parse_hid_report_descriptor(gtco, report, result); /* Now we delete it */ kfree(report); /* Create a device file node */ - usb_make_path(device->usbdev, path, PATHLENGTH); - sprintf(device->usbpath, "%s/input0", path); - + usb_make_path(gtco->usbdev, gtco->usbpath, sizeof(gtco->usbpath)); + strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath)); /* Set Input device functions */ - inputdev->open = gtco_input_open; - inputdev->close = gtco_input_close; + input_dev->open = gtco_input_open; + input_dev->close = gtco_input_close; /* Set input device information */ - inputdev->name = "GTCO_CalComp"; - inputdev->phys = device->usbpath; - inputdev->private = device; - + input_dev->name = "GTCO_CalComp"; + input_dev->phys = gtco->usbpath; + input_dev->private = gtco; /* Now set up all the input device capabilities */ - gtco_setup_caps(inputdev); + gtco_setup_caps(input_dev); /* Set input device required ID information */ - usb_to_input_id(device->usbdev, &device->inputdevice->id); - inputdev->cdev.dev = &usbinterface->dev; + usb_to_input_id(gtco->usbdev, &input_dev->id); + input_dev->cdev.dev = &usbinterface->dev; /* Setup the URB, it will be posted later on open of input device */ endpoint = &usbinterface->altsetting[0].endpoint[0].desc; - usb_fill_int_urb(device->urbinfo, - device->usbdev, - usb_rcvintpipe(device->usbdev, + usb_fill_int_urb(gtco->urbinfo, + gtco->usbdev, + usb_rcvintpipe(gtco->usbdev, endpoint->bEndpointAddress), - device->buffer, + gtco->buffer, REPORT_MAX_SIZE, gtco_urb_callback, - device, + gtco, endpoint->bInterval); - device->urbinfo->transfer_dma = device->buf_dma; - device->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - + gtco->urbinfo->transfer_dma = gtco->buf_dma; + gtco->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - /* Save device pointer in USB interface device */ - usb_set_intfdata(usbinterface, device); + /* Save gtco pointer in USB interface gtco */ + usb_set_intfdata(usbinterface, gtco); /* All done, now register the input device */ - input_register_device(inputdev); + error = input_register_device(input_dev); + if (error) + goto err_free_urb; - info( "gtco driver created usb: %s\n", path); return 0; + err_free_urb: + usb_free_urb(gtco->urbinfo); + err_free_buf: + usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, + gtco->buffer, gtco->buf_dma); + err_free_devs: + kfree(report); + input_free_device(input_dev); + kfree(gtco); + return error; } /* @@ -1044,50 +999,46 @@ static int gtco_probe(struct usb_interface *usbinterface, */ static void gtco_disconnect(struct usb_interface *interface) { - /* Grab private device ptr */ - struct gtco *device = usb_get_intfdata (interface); - struct input_dev *inputdev; - - inputdev = device->inputdevice; + struct gtco *gtco = usb_get_intfdata(interface); /* Now reverse all the registration stuff */ - if (device) { - input_unregister_device(inputdev); - usb_kill_urb(device->urbinfo); - usb_free_urb(device->urbinfo); - usb_buffer_free(device->usbdev, REPORT_MAX_SIZE, - device->buffer, device->buf_dma); - kfree(device); + if (gtco) { + input_unregister_device(gtco->inputdevice); + usb_kill_urb(gtco->urbinfo); + usb_free_urb(gtco->urbinfo); + usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, + gtco->buffer, gtco->buf_dma); + kfree(gtco); } info("gtco driver disconnected"); } - /* STANDARD MODULE LOAD ROUTINES */ static struct usb_driver gtco_driverinfo_table = { -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)) - .owner = THIS_MODULE, -#endif - .name = "gtco", - .id_table = gtco_usbid_table, - .probe = gtco_probe, - .disconnect = gtco_disconnect, + .name = "gtco", + .id_table = gtco_usbid_table, + .probe = gtco_probe, + .disconnect = gtco_disconnect, }; + /* * Register this module with the USB subsystem */ static int __init gtco_init(void) { - int rc; - rc = usb_register(>co_driverinfo_table); - if (rc) { - err("usb_register() failed rc=0x%x", rc); + int error; + + error = usb_register(>co_driverinfo_table); + if (error) { + err("usb_register() failed rc=0x%x", error); + return error; } - printk("GTCO usb driver version: %s",GTCO_VERSION); - return rc; + + printk("GTCO usb driver version: %s", GTCO_VERSION); + return 0; } /* @@ -1098,7 +1049,7 @@ static void __exit gtco_exit(void) usb_deregister(>co_driverinfo_table); } -module_init (gtco_init); -module_exit (gtco_exit); +module_init(gtco_init); +module_exit(gtco_exit); MODULE_LICENSE("GPL"); -- cgit v1.2.3 From a1421d3c780c373d5f74a0ab99b0652041d61876 Mon Sep 17 00:00:00 2001 From: Peter Stokes Date: Thu, 12 Apr 2007 01:33:10 -0400 Subject: Input: add logical channel support for ATI Remote Wonder II The ATI Remote Wonder II can be configured with one of 16 unique logical channels. Allowing up to 16 remotes to be used independently within range of each other. This change adds functionality to configure the receiver and filter the input data to respond or exclude remotes configured with different logical channels. Signed-off-by: Peter Stokes Acked-by: Ville Syrjala Signed-off-by: Greg Kroah-Hartman Signed-off-by: Dmitry Torokhov --- drivers/usb/input/ati_remote2.c | 89 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 9 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/ati_remote2.c b/drivers/usb/input/ati_remote2.c index 83f1f79db7c..6459be90599 100644 --- a/drivers/usb/input/ati_remote2.c +++ b/drivers/usb/input/ati_remote2.c @@ -2,6 +2,7 @@ * ati_remote2 - ATI/Philips USB RF remote driver * * Copyright (C) 2005 Ville Syrjala + * Copyright (C) 2007 Peter Stokes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -11,13 +12,29 @@ #include #define DRIVER_DESC "ATI/Philips USB RF remote driver" -#define DRIVER_VERSION "0.1" +#define DRIVER_VERSION "0.2" MODULE_DESCRIPTION(DRIVER_DESC); MODULE_VERSION(DRIVER_VERSION); MODULE_AUTHOR("Ville Syrjala "); MODULE_LICENSE("GPL"); +/* + * ATI Remote Wonder II Channel Configuration + * + * The remote control can by assigned one of sixteen "channels" in order to facilitate + * the use of multiple remote controls within range of each other. + * A remote's "channel" may be altered by pressing and holding the "PC" button for + * approximately 3 seconds, after which the button will slowly flash the count of the + * currently configured "channel", using the numeric keypad enter a number between 1 and + * 16 and then the "PC" button again, the button will slowly flash the count of the + * newly configured "channel". + */ + +static unsigned int channel_mask = 0xFFFF; +module_param(channel_mask, uint, 0644); +MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); + static unsigned int mode_mask = 0x1F; module_param(mode_mask, uint, 0644); MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); @@ -146,15 +163,23 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2) { struct input_dev *idev = ar2->idev; u8 *data = ar2->buf[0]; + int channel, mode; + + channel = data[0] >> 4; + + if (!((1 << channel) & channel_mask)) + return; - if (data[0] > 4) { + mode = data[0] & 0x0F; + + if (mode > 4) { dev_err(&ar2->intf[0]->dev, "Unknown mode byte (%02x %02x %02x %02x)\n", data[3], data[2], data[1], data[0]); return; } - if (!((1 << data[0]) & mode_mask)) + if (!((1 << mode) & mode_mask)) return; input_event(idev, EV_REL, REL_X, (s8) data[1]); @@ -177,9 +202,16 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2) { struct input_dev *idev = ar2->idev; u8 *data = ar2->buf[1]; - int hw_code, index; + int channel, mode, hw_code, index; + + channel = data[0] >> 4; + + if (!((1 << channel) & channel_mask)) + return; - if (data[0] > 4) { + mode = data[0] & 0x0F; + + if (mode > 4) { dev_err(&ar2->intf[1]->dev, "Unknown mode byte (%02x %02x %02x %02x)\n", data[3], data[2], data[1], data[0]); @@ -199,16 +231,16 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2) * events for the mouse pad so we filter out any subsequent * events from the same mode key. */ - if (ar2->mode == data[0]) + if (ar2->mode == mode) return; if (data[1] == 0) - ar2->mode = data[0]; + ar2->mode = mode; - hw_code |= data[0] << 8; + hw_code |= mode << 8; } - if (!((1 << data[0]) & mode_mask)) + if (!((1 << mode) & mode_mask)) return; index = ati_remote2_lookup(hw_code); @@ -379,6 +411,41 @@ static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2) } } +static int ati_remote2_setup(struct ati_remote2 *ar2) +{ + int r, i, channel; + + /* + * Configure receiver to only accept input from remote "channel" + * channel == 0 -> Accept input from any remote channel + * channel == 1 -> Only accept input from remote channel 1 + * channel == 2 -> Only accept input from remote channel 2 + * ... + * channel == 16 -> Only accept input from remote channel 16 + */ + + channel = 0; + for (i = 0; i < 16; i++) { + if ((1 << i) & channel_mask) { + if (!(~(1 << i) & 0xFFFF & channel_mask)) + channel = i + 1; + break; + } + } + + r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0), + 0x20, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, + channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT); + if (r) { + dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n", + __FUNCTION__, r); + return r; + } + + return 0; +} + static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); @@ -409,6 +476,10 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d if (r) goto fail2; + r = ati_remote2_setup(ar2); + if (r) + goto fail2; + usb_make_path(udev, ar2->phys, sizeof(ar2->phys)); strlcat(ar2->phys, "/input0", sizeof(ar2->phys)); -- cgit v1.2.3 From db61a9124880a1d79b7b320d4b6bef717f23e485 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 12 Apr 2007 01:33:28 -0400 Subject: Input: remove old USB touchscreen drivers itmtoch, mtouchusb and touchkitusb have been replaced with composite usbtouchscreen driver and can be removed now. Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/usb/input/Makefile | 3 - drivers/usb/input/itmtouch.c | 271 --------------------------- drivers/usb/input/mtouchusb.c | 332 ---------------------------------- drivers/usb/input/touchkitusb.c | 392 ---------------------------------------- 4 files changed, 998 deletions(-) delete mode 100644 drivers/usb/input/itmtouch.c delete mode 100644 drivers/usb/input/mtouchusb.c delete mode 100644 drivers/usb/input/touchkitusb.c (limited to 'drivers/usb') diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile index a9d206c945e..f8c35b66c46 100644 --- a/drivers/usb/input/Makefile +++ b/drivers/usb/input/Makefile @@ -38,9 +38,6 @@ obj-$(CONFIG_USB_KBD) += usbkbd.o obj-$(CONFIG_USB_KBTAB) += kbtab.o obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o obj-$(CONFIG_USB_MOUSE) += usbmouse.o -obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o -obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o -obj-$(CONFIG_USB_EGALAX) += touchkitusb.o obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o obj-$(CONFIG_USB_POWERMATE) += powermate.o obj-$(CONFIG_USB_WACOM) += wacom.o diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c deleted file mode 100644 index aac968aab86..00000000000 --- a/drivers/usb/input/itmtouch.c +++ /dev/null @@ -1,271 +0,0 @@ -/****************************************************************************** - * itmtouch.c -- Driver for ITM touchscreen panel - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Based upon original work by Chris Collins . - * - * Kudos to ITM for providing me with the datasheet for the panel, - * even though it was a day later than I had finished writing this - * driver. - * - * It has meant that I've been able to correct my interpretation of the - * protocol packets however. - * - * CC -- 2003/9/29 - * - * History - * 1.0 & 1.1 2003 (CC) vojtech@suse.cz - * Original version for 2.4.x kernels - * - * 1.2 02/03/2005 (HCE) hc@mivu.no - * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints. - * Unfortunately no calibration support at this time. - * - * 1.2.1 09/03/2005 (HCE) hc@mivu.no - * Code cleanup and adjusting syntax to start matching kernel standards - * - * 1.2.2 10/05/2006 (MJA) massad@gmail.com - * Flag for detecting if the screen was being touch was incorrectly - * inverted, so no touch events were being detected. - * - *****************************************************************************/ - -#include -#include -#include -#include -#include - -/* only an 8 byte buffer necessary for a single packet */ -#define ITM_BUFSIZE 8 -#define PATH_SIZE 64 - -#define USB_VENDOR_ID_ITMINC 0x0403 -#define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9 - -#define DRIVER_AUTHOR "Hans-Christian Egtvedt " -#define DRIVER_VERSION "v1.2.2" -#define DRIVER_DESC "USB ITM Inc Touch Panel Driver" -#define DRIVER_LICENSE "GPL" - -MODULE_AUTHOR( DRIVER_AUTHOR ); -MODULE_DESCRIPTION( DRIVER_DESC ); -MODULE_LICENSE( DRIVER_LICENSE ); - -struct itmtouch_dev { - struct usb_device *usbdev; /* usb device */ - struct input_dev *inputdev; /* input device */ - struct urb *readurb; /* urb */ - char rbuf[ITM_BUFSIZE]; /* data */ - int users; - char name[128]; - char phys[64]; -}; - -static struct usb_device_id itmtouch_ids [] = { - { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) }, - { } -}; - -static void itmtouch_irq(struct urb *urb) -{ - struct itmtouch_dev *itmtouch = urb->context; - unsigned char *data = urb->transfer_buffer; - struct input_dev *dev = itmtouch->inputdev; - int retval; - - switch (urb->status) { - case 0: - /* success */ - break; - case -ETIME: - /* this urb is timing out */ - dbg("%s - urb timed out - was the device unplugged?", - __FUNCTION__); - return; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* this urb is terminated, clean up */ - dbg("%s - urb shutting down with status: %d", - __FUNCTION__, urb->status); - return; - default: - dbg("%s - nonzero urb status received: %d", - __FUNCTION__, urb->status); - goto exit; - } - - /* if pressure has been released, then don't report X/Y */ - if (!(data[7] & 0x20)) { - input_report_abs(dev, ABS_X, (data[0] & 0x1F) << 7 | (data[3] & 0x7F)); - input_report_abs(dev, ABS_Y, (data[1] & 0x1F) << 7 | (data[4] & 0x7F)); - } - - input_report_abs(dev, ABS_PRESSURE, (data[2] & 1) << 7 | (data[5] & 0x7F)); - input_report_key(dev, BTN_TOUCH, ~data[7] & 0x20); - input_sync(dev); - -exit: - retval = usb_submit_urb (urb, GFP_ATOMIC); - if (retval) - printk(KERN_ERR "%s - usb_submit_urb failed with result: %d", - __FUNCTION__, retval); -} - -static int itmtouch_open(struct input_dev *input) -{ - struct itmtouch_dev *itmtouch = input->private; - - itmtouch->readurb->dev = itmtouch->usbdev; - - if (usb_submit_urb(itmtouch->readurb, GFP_KERNEL)) - return -EIO; - - return 0; -} - -static void itmtouch_close(struct input_dev *input) -{ - struct itmtouch_dev *itmtouch = input->private; - - usb_kill_urb(itmtouch->readurb); -} - -static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id) -{ - struct itmtouch_dev *itmtouch; - struct input_dev *input_dev; - struct usb_host_interface *interface; - struct usb_endpoint_descriptor *endpoint; - struct usb_device *udev = interface_to_usbdev(intf); - unsigned int pipe; - unsigned int maxp; - - interface = intf->cur_altsetting; - endpoint = &interface->endpoint[0].desc; - - itmtouch = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL); - input_dev = input_allocate_device(); - if (!itmtouch || !input_dev) { - err("%s - Out of memory.", __FUNCTION__); - goto fail; - } - - itmtouch->usbdev = udev; - itmtouch->inputdev = input_dev; - - if (udev->manufacturer) - strlcpy(itmtouch->name, udev->manufacturer, sizeof(itmtouch->name)); - - if (udev->product) { - if (udev->manufacturer) - strlcat(itmtouch->name, " ", sizeof(itmtouch->name)); - strlcat(itmtouch->name, udev->product, sizeof(itmtouch->name)); - } - - if (!strlen(itmtouch->name)) - sprintf(itmtouch->name, "USB ITM touchscreen"); - - usb_make_path(udev, itmtouch->phys, sizeof(itmtouch->phys)); - strlcpy(itmtouch->phys, "/input0", sizeof(itmtouch->phys)); - - input_dev->name = itmtouch->name; - input_dev->phys = itmtouch->phys; - usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; - input_dev->private = itmtouch; - - input_dev->open = itmtouch_open; - input_dev->close = itmtouch_close; - - input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); - input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); - input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - - /* device limits */ - /* as specified by the ITM datasheet, X and Y are 12bit, - * Z (pressure) is 8 bit. However, the fields are defined up - * to 14 bits for future possible expansion. - */ - input_set_abs_params(input_dev, ABS_X, 0, 0x0FFF, 2, 0); - input_set_abs_params(input_dev, ABS_Y, 0, 0x0FFF, 2, 0); - input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xFF, 2, 0); - - /* initialise the URB so we can read from the transport stream */ - pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress); - maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); - - if (maxp > ITM_BUFSIZE) - maxp = ITM_BUFSIZE; - - itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL); - if (!itmtouch->readurb) { - dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__); - goto fail; - } - - usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf, - maxp, itmtouch_irq, itmtouch, endpoint->bInterval); - - input_register_device(itmtouch->inputdev); - - usb_set_intfdata(intf, itmtouch); - - return 0; - - fail: input_free_device(input_dev); - kfree(itmtouch); - return -ENOMEM; -} - -static void itmtouch_disconnect(struct usb_interface *intf) -{ - struct itmtouch_dev *itmtouch = usb_get_intfdata(intf); - - usb_set_intfdata(intf, NULL); - - if (itmtouch) { - input_unregister_device(itmtouch->inputdev); - usb_kill_urb(itmtouch->readurb); - usb_free_urb(itmtouch->readurb); - kfree(itmtouch); - } -} - -MODULE_DEVICE_TABLE(usb, itmtouch_ids); - -static struct usb_driver itmtouch_driver = { - .name = "itmtouch", - .probe = itmtouch_probe, - .disconnect = itmtouch_disconnect, - .id_table = itmtouch_ids, -}; - -static int __init itmtouch_init(void) -{ - info(DRIVER_DESC " " DRIVER_VERSION); - info(DRIVER_AUTHOR); - return usb_register(&itmtouch_driver); -} - -static void __exit itmtouch_exit(void) -{ - usb_deregister(&itmtouch_driver); -} - -module_init(itmtouch_init); -module_exit(itmtouch_exit); diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c deleted file mode 100644 index 92c4e07da4c..00000000000 --- a/drivers/usb/input/mtouchusb.c +++ /dev/null @@ -1,332 +0,0 @@ -/****************************************************************************** - * mtouchusb.c -- Driver for Microtouch (Now 3M) USB Touchscreens - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Based upon original work by Radoslaw Garbacz (usb-support@ite.pl) - * (http://freshmeat.net/projects/3mtouchscreendriver) - * - * History - * - * 0.3 & 0.4 2002 (TEJ) tejohnson@yahoo.com - * Updated to 2.4.18, then 2.4.19 - * Old version still relied on stealing a minor - * - * 0.5 02/26/2004 (TEJ) tejohnson@yahoo.com - * Complete rewrite using Linux Input in 2.6.3 - * Unfortunately no calibration support at this time - * - * 1.4 04/25/2004 (TEJ) tejohnson@yahoo.com - * Changed reset from standard USB dev reset to vendor reset - * Changed data sent to host from compensated to raw coordinates - * Eliminated vendor/product module params - * Performed multiple successful tests with an EXII-5010UC - * - * 1.5 02/27/2005 ddstreet@ieee.org - * Added module parameter to select raw or hw-calibrated coordinate reporting - * - *****************************************************************************/ - -#include -#include -#include -#include -#include - -#define MTOUCHUSB_MIN_XC 0x0 -#define MTOUCHUSB_MAX_RAW_XC 0x4000 -#define MTOUCHUSB_MAX_CALIB_XC 0xffff -#define MTOUCHUSB_XC_FUZZ 0x0 -#define MTOUCHUSB_XC_FLAT 0x0 -#define MTOUCHUSB_MIN_YC 0x0 -#define MTOUCHUSB_MAX_RAW_YC 0x4000 -#define MTOUCHUSB_MAX_CALIB_YC 0xffff -#define MTOUCHUSB_YC_FUZZ 0x0 -#define MTOUCHUSB_YC_FLAT 0x0 - -#define MTOUCHUSB_ASYNC_REPORT 1 -#define MTOUCHUSB_RESET 7 -#define MTOUCHUSB_REPORT_DATA_SIZE 11 -#define MTOUCHUSB_REQ_CTRLLR_ID 10 - -#define MTOUCHUSB_GET_RAW_XC(data) (data[8]<<8 | data[7]) -#define MTOUCHUSB_GET_CALIB_XC(data) (data[4]<<8 | data[3]) -#define MTOUCHUSB_GET_RAW_YC(data) (data[10]<<8 | data[9]) -#define MTOUCHUSB_GET_CALIB_YC(data) (data[6]<<8 | data[5]) -#define MTOUCHUSB_GET_XC(data) (raw_coordinates ? \ - MTOUCHUSB_GET_RAW_XC(data) : \ - MTOUCHUSB_GET_CALIB_XC(data)) -#define MTOUCHUSB_GET_YC(data) (raw_coordinates ? \ - MTOUCHUSB_GET_RAW_YC(data) : \ - MTOUCHUSB_GET_CALIB_YC(data)) -#define MTOUCHUSB_GET_TOUCHED(data) ((data[2] & 0x40) ? 1:0) - -#define DRIVER_VERSION "v1.5" -#define DRIVER_AUTHOR "Todd E. Johnson, tejohnson@yahoo.com" -#define DRIVER_DESC "3M USB Touchscreen Driver" -#define DRIVER_LICENSE "GPL" - -static int raw_coordinates = 1; - -module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR); -MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)"); - -struct mtouch_usb { - unsigned char *data; - dma_addr_t data_dma; - struct urb *irq; - struct usb_device *udev; - struct input_dev *input; - char name[128]; - char phys[64]; -}; - -static struct usb_device_id mtouchusb_devices[] = { - { USB_DEVICE(0x0596, 0x0001) }, - { } -}; - -static void mtouchusb_irq(struct urb *urb) -{ - struct mtouch_usb *mtouch = urb->context; - int retval; - - switch (urb->status) { - case 0: - /* success */ - break; - case -ETIME: - /* this urb is timing out */ - dbg("%s - urb timed out - was the device unplugged?", - __FUNCTION__); - return; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* this urb is terminated, clean up */ - dbg("%s - urb shutting down with status: %d", - __FUNCTION__, urb->status); - return; - default: - dbg("%s - nonzero urb status received: %d", - __FUNCTION__, urb->status); - goto exit; - } - - input_report_key(mtouch->input, BTN_TOUCH, - MTOUCHUSB_GET_TOUCHED(mtouch->data)); - input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); - input_report_abs(mtouch->input, ABS_Y, - (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) - - MTOUCHUSB_GET_YC(mtouch->data)); - input_sync(mtouch->input); - -exit: - retval = usb_submit_urb(urb, GFP_ATOMIC); - if (retval) - err("%s - usb_submit_urb failed with result: %d", - __FUNCTION__, retval); -} - -static int mtouchusb_open(struct input_dev *input) -{ - struct mtouch_usb *mtouch = input->private; - - mtouch->irq->dev = mtouch->udev; - - if (usb_submit_urb(mtouch->irq, GFP_ATOMIC)) - return -EIO; - - return 0; -} - -static void mtouchusb_close(struct input_dev *input) -{ - struct mtouch_usb *mtouch = input->private; - - usb_kill_urb(mtouch->irq); -} - -static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) -{ - dbg("%s - called", __FUNCTION__); - - mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE, - GFP_ATOMIC, &mtouch->data_dma); - - if (!mtouch->data) - return -1; - - return 0; -} - -static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) -{ - dbg("%s - called", __FUNCTION__); - - if (mtouch->data) - usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE, - mtouch->data, mtouch->data_dma); -} - -static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) -{ - struct mtouch_usb *mtouch; - struct input_dev *input_dev; - struct usb_host_interface *interface; - struct usb_endpoint_descriptor *endpoint; - struct usb_device *udev = interface_to_usbdev(intf); - int nRet; - - dbg("%s - called", __FUNCTION__); - - dbg("%s - setting interface", __FUNCTION__); - interface = intf->cur_altsetting; - - dbg("%s - setting endpoint", __FUNCTION__); - endpoint = &interface->endpoint[0].desc; - - mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL); - input_dev = input_allocate_device(); - if (!mtouch || !input_dev) { - err("%s - Out of memory.", __FUNCTION__); - goto fail1; - } - - dbg("%s - allocating buffers", __FUNCTION__); - if (mtouchusb_alloc_buffers(udev, mtouch)) - goto fail2; - - mtouch->udev = udev; - mtouch->input = input_dev; - - if (udev->manufacturer) - strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name)); - - if (udev->product) { - if (udev->manufacturer) - strlcat(mtouch->name, " ", sizeof(mtouch->name)); - strlcat(mtouch->name, udev->product, sizeof(mtouch->name)); - } - - if (!strlen(mtouch->name)) - snprintf(mtouch->name, sizeof(mtouch->name), - "USB Touchscreen %04x:%04x", - le16_to_cpu(udev->descriptor.idVendor), - le16_to_cpu(udev->descriptor.idProduct)); - - usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys)); - strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys)); - - input_dev->name = mtouch->name; - input_dev->phys = mtouch->phys; - usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; - input_dev->private = mtouch; - - input_dev->open = mtouchusb_open; - input_dev->close = mtouchusb_close; - - input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); - input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC, - raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC, - MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT); - input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC, - raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC, - MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT); - - nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), - MTOUCHUSB_RESET, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); - dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", - __FUNCTION__, nRet); - - dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__); - mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); - if (!mtouch->irq) { - dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); - goto fail2; - } - - dbg("%s - usb_fill_int_urb", __FUNCTION__); - usb_fill_int_urb(mtouch->irq, mtouch->udev, - usb_rcvintpipe(mtouch->udev, 0x81), - mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE, - mtouchusb_irq, mtouch, endpoint->bInterval); - - dbg("%s - input_register_device", __FUNCTION__); - input_register_device(mtouch->input); - - nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), - MTOUCHUSB_ASYNC_REPORT, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); - dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", - __FUNCTION__, nRet); - - usb_set_intfdata(intf, mtouch); - return 0; - -fail2: mtouchusb_free_buffers(udev, mtouch); -fail1: input_free_device(input_dev); - kfree(mtouch); - return -ENOMEM; -} - -static void mtouchusb_disconnect(struct usb_interface *intf) -{ - struct mtouch_usb *mtouch = usb_get_intfdata(intf); - - dbg("%s - called", __FUNCTION__); - usb_set_intfdata(intf, NULL); - if (mtouch) { - dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); - usb_kill_urb(mtouch->irq); - input_unregister_device(mtouch->input); - usb_free_urb(mtouch->irq); - mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); - kfree(mtouch); - } -} - -MODULE_DEVICE_TABLE(usb, mtouchusb_devices); - -static struct usb_driver mtouchusb_driver = { - .name = "mtouchusb", - .probe = mtouchusb_probe, - .disconnect = mtouchusb_disconnect, - .id_table = mtouchusb_devices, -}; - -static int __init mtouchusb_init(void) -{ - dbg("%s - called", __FUNCTION__); - return usb_register(&mtouchusb_driver); -} - -static void __exit mtouchusb_cleanup(void) -{ - dbg("%s - called", __FUNCTION__); - usb_deregister(&mtouchusb_driver); -} - -module_init(mtouchusb_init); -module_exit(mtouchusb_cleanup); - -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_LICENSE("GPL"); diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c deleted file mode 100644 index 2a314b06592..00000000000 --- a/drivers/usb/input/touchkitusb.c +++ /dev/null @@ -1,392 +0,0 @@ -/****************************************************************************** - * touchkitusb.c -- Driver for eGalax TouchKit USB Touchscreens - * - * Copyright (C) 2004-2005 by Daniel Ritz - * Copyright (C) by Todd E. Johnson (mtouchusb.c) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Based upon mtouchusb.c - * - *****************************************************************************/ - -//#define DEBUG - -#include -#include -#include -#include -#include - -#define TOUCHKIT_MIN_XC 0x0 -#define TOUCHKIT_MAX_XC 0x07ff -#define TOUCHKIT_XC_FUZZ 0x0 -#define TOUCHKIT_XC_FLAT 0x0 -#define TOUCHKIT_MIN_YC 0x0 -#define TOUCHKIT_MAX_YC 0x07ff -#define TOUCHKIT_YC_FUZZ 0x0 -#define TOUCHKIT_YC_FLAT 0x0 -#define TOUCHKIT_REPORT_DATA_SIZE 16 - -#define TOUCHKIT_DOWN 0x01 - -#define TOUCHKIT_PKT_TYPE_MASK 0xFE -#define TOUCHKIT_PKT_TYPE_REPT 0x80 -#define TOUCHKIT_PKT_TYPE_DIAG 0x0A - -#define DRIVER_VERSION "v0.1" -#define DRIVER_AUTHOR "Daniel Ritz " -#define DRIVER_DESC "eGalax TouchKit USB HID Touchscreen Driver" - -static int swap_xy; -module_param(swap_xy, bool, 0644); -MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped."); - -struct touchkit_usb { - unsigned char *data; - dma_addr_t data_dma; - char buffer[TOUCHKIT_REPORT_DATA_SIZE]; - int buf_len; - struct urb *irq; - struct usb_device *udev; - struct input_dev *input; - char name[128]; - char phys[64]; -}; - -static struct usb_device_id touchkit_devices[] = { - {USB_DEVICE(0x3823, 0x0001)}, - {USB_DEVICE(0x0123, 0x0001)}, - {USB_DEVICE(0x0eef, 0x0001)}, - {USB_DEVICE(0x0eef, 0x0002)}, - {} -}; - -/* helpers to read the data */ -static inline int touchkit_get_touched(char *data) -{ - return (data[0] & TOUCHKIT_DOWN) ? 1 : 0; -} - -static inline int touchkit_get_x(char *data) -{ - return ((data[3] & 0x0F) << 7) | (data[4] & 0x7F); -} - -static inline int touchkit_get_y(char *data) -{ - return ((data[1] & 0x0F) << 7) | (data[2] & 0x7F); -} - - -/* processes one input packet. */ -static void touchkit_process_pkt(struct touchkit_usb *touchkit, char *pkt) -{ - int x, y; - - /* only process report packets */ - if ((pkt[0] & TOUCHKIT_PKT_TYPE_MASK) != TOUCHKIT_PKT_TYPE_REPT) - return; - - if (swap_xy) { - y = touchkit_get_x(pkt); - x = touchkit_get_y(pkt); - } else { - x = touchkit_get_x(pkt); - y = touchkit_get_y(pkt); - } - - input_report_key(touchkit->input, BTN_TOUCH, touchkit_get_touched(pkt)); - input_report_abs(touchkit->input, ABS_X, x); - input_report_abs(touchkit->input, ABS_Y, y); - input_sync(touchkit->input); -} - - -static int touchkit_get_pkt_len(char *buf) -{ - switch (buf[0] & TOUCHKIT_PKT_TYPE_MASK) { - case TOUCHKIT_PKT_TYPE_REPT: - return 5; - - case TOUCHKIT_PKT_TYPE_DIAG: - return buf[1] + 2; - } - - return 0; -} - -static void touchkit_process(struct touchkit_usb *touchkit, int len) -{ - char *buffer; - int pkt_len, buf_len, pos; - - /* if the buffer contains data, append */ - if (unlikely(touchkit->buf_len)) { - int tmp; - - /* if only 1 byte in buffer, add another one to get length */ - if (touchkit->buf_len == 1) - touchkit->buffer[1] = touchkit->data[0]; - - pkt_len = touchkit_get_pkt_len(touchkit->buffer); - - /* unknown packet: drop everything */ - if (!pkt_len) - return; - - /* append, process */ - tmp = pkt_len - touchkit->buf_len; - memcpy(touchkit->buffer + touchkit->buf_len, touchkit->data, tmp); - touchkit_process_pkt(touchkit, touchkit->buffer); - - buffer = touchkit->data + tmp; - buf_len = len - tmp; - } else { - buffer = touchkit->data; - buf_len = len; - } - - /* only one byte left in buffer */ - if (unlikely(buf_len == 1)) { - touchkit->buffer[0] = buffer[0]; - touchkit->buf_len = 1; - return; - } - - /* loop over the buffer */ - pos = 0; - while (pos < buf_len) { - /* get packet len */ - pkt_len = touchkit_get_pkt_len(buffer + pos); - - /* unknown packet: drop everything */ - if (unlikely(!pkt_len)) - return; - - /* full packet: process */ - if (likely(pkt_len <= buf_len)) { - touchkit_process_pkt(touchkit, buffer + pos); - } else { - /* incomplete packet: save in buffer */ - memcpy(touchkit->buffer, buffer + pos, buf_len - pos); - touchkit->buf_len = buf_len - pos; - } - pos += pkt_len; - } -} - - -static void touchkit_irq(struct urb *urb) -{ - struct touchkit_usb *touchkit = urb->context; - int retval; - - switch (urb->status) { - case 0: - /* success */ - break; - case -ETIME: - /* this urb is timing out */ - dbg("%s - urb timed out - was the device unplugged?", - __FUNCTION__); - return; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* this urb is terminated, clean up */ - dbg("%s - urb shutting down with status: %d", - __FUNCTION__, urb->status); - return; - default: - dbg("%s - nonzero urb status received: %d", - __FUNCTION__, urb->status); - goto exit; - } - - touchkit_process(touchkit, urb->actual_length); - -exit: - retval = usb_submit_urb(urb, GFP_ATOMIC); - if (retval) - err("%s - usb_submit_urb failed with result: %d", - __FUNCTION__, retval); -} - -static int touchkit_open(struct input_dev *input) -{ - struct touchkit_usb *touchkit = input->private; - - touchkit->irq->dev = touchkit->udev; - - if (usb_submit_urb(touchkit->irq, GFP_ATOMIC)) - return -EIO; - - return 0; -} - -static void touchkit_close(struct input_dev *input) -{ - struct touchkit_usb *touchkit = input->private; - - usb_kill_urb(touchkit->irq); -} - -static int touchkit_alloc_buffers(struct usb_device *udev, - struct touchkit_usb *touchkit) -{ - touchkit->data = usb_buffer_alloc(udev, TOUCHKIT_REPORT_DATA_SIZE, - GFP_ATOMIC, &touchkit->data_dma); - - if (!touchkit->data) - return -1; - - return 0; -} - -static void touchkit_free_buffers(struct usb_device *udev, - struct touchkit_usb *touchkit) -{ - if (touchkit->data) - usb_buffer_free(udev, TOUCHKIT_REPORT_DATA_SIZE, - touchkit->data, touchkit->data_dma); -} - -static int touchkit_probe(struct usb_interface *intf, - const struct usb_device_id *id) -{ - struct touchkit_usb *touchkit; - struct input_dev *input_dev; - struct usb_host_interface *interface; - struct usb_endpoint_descriptor *endpoint; - struct usb_device *udev = interface_to_usbdev(intf); - - interface = intf->cur_altsetting; - endpoint = &interface->endpoint[0].desc; - - touchkit = kzalloc(sizeof(struct touchkit_usb), GFP_KERNEL); - input_dev = input_allocate_device(); - if (!touchkit || !input_dev) - goto out_free; - - if (touchkit_alloc_buffers(udev, touchkit)) - goto out_free; - - touchkit->irq = usb_alloc_urb(0, GFP_KERNEL); - if (!touchkit->irq) { - dbg("%s - usb_alloc_urb failed: touchkit->irq", __FUNCTION__); - goto out_free_buffers; - } - - touchkit->udev = udev; - touchkit->input = input_dev; - - if (udev->manufacturer) - strlcpy(touchkit->name, udev->manufacturer, sizeof(touchkit->name)); - - if (udev->product) { - if (udev->manufacturer) - strlcat(touchkit->name, " ", sizeof(touchkit->name)); - strlcat(touchkit->name, udev->product, sizeof(touchkit->name)); - } - - if (!strlen(touchkit->name)) - snprintf(touchkit->name, sizeof(touchkit->name), - "USB Touchscreen %04x:%04x", - le16_to_cpu(udev->descriptor.idVendor), - le16_to_cpu(udev->descriptor.idProduct)); - - usb_make_path(udev, touchkit->phys, sizeof(touchkit->phys)); - strlcpy(touchkit->phys, "/input0", sizeof(touchkit->phys)); - - input_dev->name = touchkit->name; - input_dev->phys = touchkit->phys; - usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; - input_dev->private = touchkit; - input_dev->open = touchkit_open; - input_dev->close = touchkit_close; - - input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); - input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - input_set_abs_params(input_dev, ABS_X, TOUCHKIT_MIN_XC, TOUCHKIT_MAX_XC, - TOUCHKIT_XC_FUZZ, TOUCHKIT_XC_FLAT); - input_set_abs_params(input_dev, ABS_Y, TOUCHKIT_MIN_YC, TOUCHKIT_MAX_YC, - TOUCHKIT_YC_FUZZ, TOUCHKIT_YC_FLAT); - - usb_fill_int_urb(touchkit->irq, touchkit->udev, - usb_rcvintpipe(touchkit->udev, 0x81), - touchkit->data, TOUCHKIT_REPORT_DATA_SIZE, - touchkit_irq, touchkit, endpoint->bInterval); - - touchkit->irq->transfer_dma = touchkit->data_dma; - touchkit->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - - input_register_device(touchkit->input); - - usb_set_intfdata(intf, touchkit); - return 0; - -out_free_buffers: - touchkit_free_buffers(udev, touchkit); -out_free: - input_free_device(input_dev); - kfree(touchkit); - return -ENOMEM; -} - -static void touchkit_disconnect(struct usb_interface *intf) -{ - struct touchkit_usb *touchkit = usb_get_intfdata(intf); - - dbg("%s - called", __FUNCTION__); - - if (!touchkit) - return; - - dbg("%s - touchkit is initialized, cleaning up", __FUNCTION__); - usb_set_intfdata(intf, NULL); - usb_kill_urb(touchkit->irq); - input_unregister_device(touchkit->input); - usb_free_urb(touchkit->irq); - touchkit_free_buffers(interface_to_usbdev(intf), touchkit); - kfree(touchkit); -} - -MODULE_DEVICE_TABLE(usb, touchkit_devices); - -static struct usb_driver touchkit_driver = { - .name = "touchkitusb", - .probe = touchkit_probe, - .disconnect = touchkit_disconnect, - .id_table = touchkit_devices, -}; - -static int __init touchkit_init(void) -{ - return usb_register(&touchkit_driver); -} - -static void __exit touchkit_cleanup(void) -{ - usb_deregister(&touchkit_driver); -} - -module_init(touchkit_init); -module_exit(touchkit_cleanup); - -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 5014186de89708d0e9eed60526b698d5b786b707 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 12 Apr 2007 01:33:39 -0400 Subject: Input: USB devices - handle errors when registering input devices Signed-off-by: Dmitry Torokhov --- drivers/usb/input/acecad.c | 19 ++++++++++++++----- drivers/usb/input/aiptek.c | 28 ++++++++++++++-------------- drivers/usb/input/appletouch.c | 20 ++++++++++---------- drivers/usb/input/ati_remote.c | 10 ++++++---- drivers/usb/input/ati_remote2.c | 8 ++++---- drivers/usb/input/kbtab.c | 13 +++++++++---- drivers/usb/input/keyspan_remote.c | 20 +++++++++++--------- drivers/usb/input/powermate.c | 20 ++++++++++++-------- drivers/usb/input/wacom_sys.c | 12 ++++++++---- drivers/usb/input/xpad.c | 12 ++++++++---- drivers/usb/input/yealink.c | 4 +++- 11 files changed, 99 insertions(+), 67 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c index 909138e5aa0..270bb050879 100644 --- a/drivers/usb/input/acecad.c +++ b/drivers/usb/input/acecad.c @@ -135,6 +135,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ struct usb_acecad *acecad; struct input_dev *input_dev; int pipe, maxp; + int err = -ENOMEM; if (interface->desc.bNumEndpoints != 1) return -ENODEV; @@ -149,16 +150,22 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL); input_dev = input_allocate_device(); - if (!acecad || !input_dev) + if (!acecad || !input_dev) { + err = -ENOMEM; goto fail1; + } acecad->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &acecad->data_dma); - if (!acecad->data) + if (!acecad->data) { + err= -ENOMEM; goto fail1; + } acecad->irq = usb_alloc_urb(0, GFP_KERNEL); - if (!acecad->irq) + if (!acecad->irq) { + err = -ENOMEM; goto fail2; + } acecad->usbdev = dev; acecad->input = input_dev; @@ -221,7 +228,9 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ acecad->irq->transfer_dma = acecad->data_dma; acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - input_register_device(acecad->input); + err = input_register_device(acecad->input); + if (err) + goto fail2; usb_set_intfdata(intf, acecad); @@ -230,7 +239,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma); fail1: input_free_device(input_dev); kfree(acecad); - return -ENOMEM; + return err; } static void usb_acecad_disconnect(struct usb_interface *intf) diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c index f857935e615..8c1ab1cbd23 100644 --- a/drivers/usb/input/aiptek.c +++ b/drivers/usb/input/aiptek.c @@ -1972,6 +1972,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) AIPTEK_PROGRAMMABLE_DELAY_200, AIPTEK_PROGRAMMABLE_DELAY_300 }; + int err = -ENOMEM; /* programmableDelay is where the command-line specified * delay is kept. We make it the first element of speeds[], @@ -2133,7 +2134,9 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) /* Register the tablet as an Input Device */ - input_register_device(aiptek->inputdev); + err = input_register_device(aiptek->inputdev); + if (err) + goto fail2; /* We now will look for the evdev device which is mapped to * the tablet. The partial name is kept in the link list of @@ -2165,23 +2168,13 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) return 0; -fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, + fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, aiptek->data_dma); -fail1: input_free_device(inputdev); + fail1: input_free_device(inputdev); kfree(aiptek); - return -ENOMEM; + return err; } -/* Forward declaration */ -static void aiptek_disconnect(struct usb_interface *intf); - -static struct usb_driver aiptek_driver = { - .name = "aiptek", - .probe = aiptek_probe, - .disconnect = aiptek_disconnect, - .id_table = aiptek_ids, -}; - /*********************************************************************** * Deal with tablet disconnecting from the system. */ @@ -2206,6 +2199,13 @@ static void aiptek_disconnect(struct usb_interface *intf) } } +static struct usb_driver aiptek_driver = { + .name = "aiptek", + .probe = aiptek_probe, + .disconnect = aiptek_disconnect, + .id_table = aiptek_ids, +}; + static int __init aiptek_init(void) { int result = usb_register(&aiptek_driver); diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c index c77291d3d06..36221329a4e 100644 --- a/drivers/usb/input/appletouch.c +++ b/drivers/usb/input/appletouch.c @@ -491,8 +491,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int int_in_endpointAddr = 0; - int i, retval = -ENOMEM; - + int i, error = -ENOMEM; /* set up the endpoint information */ /* use only the first interrupt-in endpoint */ @@ -567,17 +566,13 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id } dev->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!dev->urb) { - retval = -ENOMEM; + if (!dev->urb) goto err_free_devs; - } dev->data = usb_buffer_alloc(dev->udev, dev->datalen, GFP_KERNEL, &dev->urb->transfer_dma); - if (!dev->data) { - retval = -ENOMEM; + if (!dev->data) goto err_free_urb; - } usb_fill_int_urb(dev->urb, udev, usb_rcvintpipe(udev, int_in_endpointAddr), @@ -633,20 +628,25 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); set_bit(BTN_LEFT, input_dev->keybit); - input_register_device(dev->input); + error = input_register_device(dev->input); + if (error) + goto err_free_buffer; /* save our data pointer in this interface device */ usb_set_intfdata(iface, dev); return 0; + err_free_buffer: + usb_buffer_free(dev->udev, dev->datalen, + dev->data, dev->urb->transfer_dma); err_free_urb: usb_free_urb(dev->urb); err_free_devs: usb_set_intfdata(iface, NULL); kfree(dev); input_free_device(input_dev); - return retval; + return error; } static void atp_disconnect(struct usb_interface *iface) diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index b724e36f7b9..a1ae9eea574 100644 --- a/drivers/usb/input/ati_remote.c +++ b/drivers/usb/input/ati_remote.c @@ -772,15 +772,17 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de goto fail3; /* Set up and register input device */ - input_register_device(ati_remote->idev); + err = input_register_device(ati_remote->idev); + if (err) + goto fail3; usb_set_intfdata(interface, ati_remote); return 0; -fail3: usb_kill_urb(ati_remote->irq_urb); + fail3: usb_kill_urb(ati_remote->irq_urb); usb_kill_urb(ati_remote->out_urb); -fail2: ati_remote_free_buffers(ati_remote); -fail1: input_free_device(input_dev); + fail2: ati_remote_free_buffers(ati_remote); + fail1: input_free_device(input_dev); kfree(ati_remote); return err; } diff --git a/drivers/usb/input/ati_remote2.c b/drivers/usb/input/ati_remote2.c index 6459be90599..5656278d796 100644 --- a/drivers/usb/input/ati_remote2.c +++ b/drivers/usb/input/ati_remote2.c @@ -337,7 +337,7 @@ static void ati_remote2_complete_key(struct urb *urb) static int ati_remote2_input_init(struct ati_remote2 *ar2) { struct input_dev *idev; - int i; + int i, retval; idev = input_allocate_device(); if (!idev) @@ -364,11 +364,11 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2) usb_to_input_id(ar2->udev, &idev->id); idev->cdev.dev = &ar2->udev->dev; - i = input_register_device(idev); - if (i) + retval = input_register_device(idev); + if (retval) input_free_device(idev); - return i; + return retval; } static int ati_remote2_urb_init(struct ati_remote2 *ar2) diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c index fedbcb127c2..64da9876fe5 100644 --- a/drivers/usb/input/kbtab.c +++ b/drivers/usb/input/kbtab.c @@ -122,6 +122,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i struct usb_endpoint_descriptor *endpoint; struct kbtab *kbtab; struct input_dev *input_dev; + int error = -ENOMEM; kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL); input_dev = input_allocate_device(); @@ -168,15 +169,19 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i kbtab->irq->transfer_dma = kbtab->data_dma; kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - input_register_device(kbtab->dev); + error = input_register_device(kbtab->dev); + if (error) + goto fail3; usb_set_intfdata(intf, kbtab); + return 0; -fail2: usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma); -fail1: input_free_device(input_dev); + fail3: usb_free_urb(kbtab->irq); + fail2: usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma); + fail1: input_free_device(input_dev); kfree(kbtab); - return -ENOMEM; + return error; } static void kbtab_disconnect(struct usb_interface *intf) diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c index 98bd323369c..d32a7684de9 100644 --- a/drivers/usb/input/keyspan_remote.c +++ b/drivers/usb/input/keyspan_remote.c @@ -437,7 +437,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic struct usb_endpoint_descriptor *endpoint; struct usb_keyspan *remote; struct input_dev *input_dev; - int i, retval; + int i, error; endpoint = keyspan_get_in_endpoint(interface->cur_altsetting); if (!endpoint) @@ -446,7 +446,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic remote = kzalloc(sizeof(*remote), GFP_KERNEL); input_dev = input_allocate_device(); if (!remote || !input_dev) { - retval = -ENOMEM; + error = -ENOMEM; goto fail1; } @@ -458,19 +458,19 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic remote->in_buffer = usb_buffer_alloc(udev, RECV_SIZE, GFP_ATOMIC, &remote->in_dma); if (!remote->in_buffer) { - retval = -ENOMEM; + error = -ENOMEM; goto fail1; } remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); if (!remote->irq_urb) { - retval = -ENOMEM; + error = -ENOMEM; goto fail2; } - retval = keyspan_setup(udev); - if (retval) { - retval = -ENODEV; + error = keyspan_setup(udev); + if (error) { + error = -ENODEV; goto fail3; } @@ -517,7 +517,9 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* we can register the device now, as it is ready */ - input_register_device(remote->input); + error = input_register_device(remote->input); + if (error) + goto fail3; /* save our data pointer in this interface device */ usb_set_intfdata(interface, remote); @@ -529,7 +531,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic fail1: kfree(remote); input_free_device(input_dev); - return retval; + return error; } /* diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c index fea97e5437f..ce27449dd69 100644 --- a/drivers/usb/input/powermate.c +++ b/drivers/usb/input/powermate.c @@ -308,7 +308,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i struct powermate_device *pm; struct input_dev *input_dev; int pipe, maxp; - int err = -ENOMEM; + int error = -ENOMEM; interface = intf->cur_altsetting; endpoint = &interface->endpoint[0].desc; @@ -387,11 +387,14 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i /* register our interrupt URB with the USB system */ if (usb_submit_urb(pm->irq, GFP_KERNEL)) { - err = -EIO; + error = -EIO; goto fail4; } - input_register_device(pm->input); + error = input_register_device(pm->input); + if (error) + goto fail5; + /* force an update of everything */ pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS; @@ -400,12 +403,13 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i usb_set_intfdata(intf, pm); return 0; -fail4: usb_free_urb(pm->config); -fail3: usb_free_urb(pm->irq); -fail2: powermate_free_buffers(udev, pm); -fail1: input_free_device(input_dev); + fail5: usb_kill_urb(pm->irq); + fail4: usb_free_urb(pm->config); + fail3: usb_free_urb(pm->irq); + fail2: powermate_free_buffers(udev, pm); + fail1: input_free_device(input_dev); kfree(pm); - return err; + return error; } /* Called when a USB device we've accepted ownership of is removed */ diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c index 12b42746ded..48988e63ebe 100644 --- a/drivers/usb/input/wacom_sys.c +++ b/drivers/usb/input/wacom_sys.c @@ -201,6 +201,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i struct wacom *wacom; struct wacom_wac *wacom_wac; struct input_dev *input_dev; + int error = -ENOMEM; char rep_data[2], limit = 0; wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); @@ -252,7 +253,9 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i wacom->irq->transfer_dma = wacom->data_dma; wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - input_register_device(wacom->dev); + error = input_register_device(wacom->dev); + if (error) + goto fail3; /* Ask the tablet to report tablet data. Repeat until it succeeds */ do { @@ -265,11 +268,12 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i usb_set_intfdata(intf, wacom); return 0; -fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma); -fail1: input_free_device(input_dev); + fail3: usb_free_urb(wacom->irq); + fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma); + fail1: input_free_device(input_dev); kfree(wacom); kfree(wacom_wac); - return -ENOMEM; + return error; } static void wacom_disconnect(struct usb_interface *intf) diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c index e4bc76ebc83..ca03d1fc233 100644 --- a/drivers/usb/input/xpad.c +++ b/drivers/usb/input/xpad.c @@ -312,6 +312,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id struct input_dev *input_dev; struct usb_endpoint_descriptor *ep_irq_in; int i; + int error = -ENOMEM; for (i = 0; xpad_device[i].idVendor; i++) { if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && @@ -373,15 +374,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id xpad->irq_in->transfer_dma = xpad->idata_dma; xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - input_register_device(xpad->dev); + error = input_register_device(xpad->dev); + if (error) + goto fail3; usb_set_intfdata(intf, xpad); return 0; -fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); -fail1: input_free_device(input_dev); + fail3: usb_free_urb(xpad->irq_in); + fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); + fail1: input_free_device(input_dev); kfree(xpad); - return -ENOMEM; + return error; } diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c index caff8e6d744..688abcdf1f0 100644 --- a/drivers/usb/input/yealink.c +++ b/drivers/usb/input/yealink.c @@ -955,7 +955,9 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id) } } - input_register_device(yld->idev); + ret = input_register_device(yld->idev); + if (ret) + return usb_cleanup(yld, ret); usb_set_intfdata(intf, yld); -- cgit v1.2.3 From 7791bdae71243050132ede7ea1558c828b69458f Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 12 Apr 2007 01:34:39 -0400 Subject: Input: drivers/usb/input - don't access dev->private directly Use input_get_drvdata() and input_set_drvdata() instead. Signed-off-by: Dmitry Torokhov --- drivers/usb/input/acecad.c | 7 ++++--- drivers/usb/input/aiptek.c | 8 +++++--- drivers/usb/input/appletouch.c | 7 ++++--- drivers/usb/input/ati_remote.c | 7 ++++--- drivers/usb/input/ati_remote2.c | 6 +++--- drivers/usb/input/gtco.c | 12 ++++++------ drivers/usb/input/kbtab.c | 7 ++++--- drivers/usb/input/keyspan_remote.c | 7 ++++--- drivers/usb/input/powermate.c | 5 +++-- drivers/usb/input/usbtouchscreen.c | 8 +++++--- drivers/usb/input/wacom_sys.c | 8 +++++--- drivers/usb/input/xpad.c | 8 +++++--- drivers/usb/input/yealink.c | 7 ++++--- 13 files changed, 56 insertions(+), 41 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c index 270bb050879..75972b7d4c8 100644 --- a/drivers/usb/input/acecad.c +++ b/drivers/usb/input/acecad.c @@ -111,7 +111,7 @@ resubmit: static int usb_acecad_open(struct input_dev *dev) { - struct usb_acecad *acecad = dev->private; + struct usb_acecad *acecad = input_get_drvdata(dev); acecad->irq->dev = acecad->usbdev; if (usb_submit_urb(acecad->irq, GFP_KERNEL)) @@ -122,7 +122,7 @@ static int usb_acecad_open(struct input_dev *dev) static void usb_acecad_close(struct input_dev *dev) { - struct usb_acecad *acecad = dev->private; + struct usb_acecad *acecad = input_get_drvdata(dev); usb_kill_urb(acecad->irq); } @@ -186,7 +186,8 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ input_dev->phys = acecad->phys; usb_to_input_id(dev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = acecad; + + input_set_drvdata(input_dev, acecad); input_dev->open = usb_acecad_open; input_dev->close = usb_acecad_close; diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c index 8c1ab1cbd23..8b33a8eae8a 100644 --- a/drivers/usb/input/aiptek.c +++ b/drivers/usb/input/aiptek.c @@ -798,7 +798,7 @@ MODULE_DEVICE_TABLE(usb, aiptek_ids); */ static int aiptek_open(struct input_dev *inputdev) { - struct aiptek *aiptek = inputdev->private; + struct aiptek *aiptek = input_get_drvdata(inputdev); aiptek->urb->dev = aiptek->usbdev; if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0) @@ -812,7 +812,7 @@ static int aiptek_open(struct input_dev *inputdev) */ static void aiptek_close(struct input_dev *inputdev) { - struct aiptek *aiptek = inputdev->private; + struct aiptek *aiptek = input_get_drvdata(inputdev); usb_kill_urb(aiptek->urb); } @@ -2045,7 +2045,9 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) inputdev->phys = aiptek->features.usbPath; usb_to_input_id(usbdev, &inputdev->id); inputdev->cdev.dev = &intf->dev; - inputdev->private = aiptek; + + input_set_drvdata(inputdev, aiptek); + inputdev->open = aiptek_open; inputdev->close = aiptek_close; diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c index 36221329a4e..ef6166ab8fe 100644 --- a/drivers/usb/input/appletouch.c +++ b/drivers/usb/input/appletouch.c @@ -466,7 +466,7 @@ exit: static int atp_open(struct input_dev *input) { - struct atp *dev = input->private; + struct atp *dev = input_get_drvdata(input); if (usb_submit_urb(dev->urb, GFP_ATOMIC)) return -EIO; @@ -477,7 +477,7 @@ static int atp_open(struct input_dev *input) static void atp_close(struct input_dev *input) { - struct atp *dev = input->private; + struct atp *dev = input_get_drvdata(input); usb_kill_urb(dev->urb); dev->open = 0; @@ -586,7 +586,8 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id usb_to_input_id(dev->udev, &input_dev->id); input_dev->cdev.dev = &iface->dev; - input_dev->private = dev; + input_set_drvdata(input_dev, dev); + input_dev->open = atp_open; input_dev->close = atp_close; diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index a1ae9eea574..876b2725609 100644 --- a/drivers/usb/input/ati_remote.c +++ b/drivers/usb/input/ati_remote.c @@ -318,7 +318,7 @@ static void ati_remote_dump(unsigned char *data, unsigned int len) */ static int ati_remote_open(struct input_dev *inputdev) { - struct ati_remote *ati_remote = inputdev->private; + struct ati_remote *ati_remote = input_get_drvdata(inputdev); /* On first open, submit the read urb which was set up previously. */ ati_remote->irq_urb->dev = ati_remote->udev; @@ -336,7 +336,7 @@ static int ati_remote_open(struct input_dev *inputdev) */ static void ati_remote_close(struct input_dev *inputdev) { - struct ati_remote *ati_remote = inputdev->private; + struct ati_remote *ati_remote = input_get_drvdata(inputdev); usb_kill_urb(ati_remote->irq_urb); } @@ -653,7 +653,8 @@ static void ati_remote_input_init(struct ati_remote *ati_remote) if (ati_remote_tbl[i].type == EV_KEY) set_bit(ati_remote_tbl[i].code, idev->keybit); - idev->private = ati_remote; + input_set_drvdata(idev, ati_remote); + idev->open = ati_remote_open; idev->close = ati_remote_close; diff --git a/drivers/usb/input/ati_remote2.c b/drivers/usb/input/ati_remote2.c index 5656278d796..3c38ac649d2 100644 --- a/drivers/usb/input/ati_remote2.c +++ b/drivers/usb/input/ati_remote2.c @@ -131,7 +131,7 @@ static struct usb_driver ati_remote2_driver = { static int ati_remote2_open(struct input_dev *idev) { - struct ati_remote2 *ar2 = idev->private; + struct ati_remote2 *ar2 = input_get_drvdata(idev); int r; r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); @@ -153,7 +153,7 @@ static int ati_remote2_open(struct input_dev *idev) static void ati_remote2_close(struct input_dev *idev) { - struct ati_remote2 *ar2 = idev->private; + struct ati_remote2 *ar2 = input_get_drvdata(idev); usb_kill_urb(ar2->urb[0]); usb_kill_urb(ar2->urb[1]); @@ -344,7 +344,7 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2) return -ENOMEM; ar2->idev = idev; - idev->private = ar2; + input_set_drvdata(idev, ar2); idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_REL); idev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT); diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index aa9c676ca79..75cce2a97d2 100644 --- a/drivers/usb/input/gtco.c +++ b/drivers/usb/input/gtco.c @@ -540,8 +540,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, */ static int gtco_input_open(struct input_dev *inputdev) { - struct gtco *device; - device = inputdev->private; + struct gtco *device = input_get_drvdata(inputdev); device->urbinfo->dev = device->usbdev; if (usb_submit_urb(device->urbinfo, GFP_KERNEL)) @@ -555,7 +554,7 @@ static int gtco_input_open(struct input_dev *inputdev) */ static void gtco_input_close(struct input_dev *inputdev) { - struct gtco *device = inputdev->private; + struct gtco *device = input_get_drvdata(inputdev); usb_kill_urb(device->urbinfo); } @@ -569,9 +568,9 @@ static void gtco_input_close(struct input_dev *inputdev) * placed in the struct gtco structure * */ -static void gtco_setup_caps(struct input_dev *inputdev) +static void gtco_setup_caps(struct input_dev *inputdev) { - struct gtco *device = inputdev->private; + struct gtco *device = input_get_drvdata(inputdev); /* Which events */ inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC); @@ -945,7 +944,8 @@ static int gtco_probe(struct usb_interface *usbinterface, /* Set input device information */ input_dev->name = "GTCO_CalComp"; input_dev->phys = gtco->usbpath; - input_dev->private = gtco; + + input_set_drvdata(input_dev, gtco); /* Now set up all the input device capabilities */ gtco_setup_caps(input_dev); diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c index 64da9876fe5..7ec999adb88 100644 --- a/drivers/usb/input/kbtab.c +++ b/drivers/usb/input/kbtab.c @@ -100,7 +100,7 @@ MODULE_DEVICE_TABLE(usb, kbtab_ids); static int kbtab_open(struct input_dev *dev) { - struct kbtab *kbtab = dev->private; + struct kbtab *kbtab = input_get_drvdata(dev); kbtab->irq->dev = kbtab->usbdev; if (usb_submit_urb(kbtab->irq, GFP_KERNEL)) @@ -111,7 +111,7 @@ static int kbtab_open(struct input_dev *dev) static void kbtab_close(struct input_dev *dev) { - struct kbtab *kbtab = dev->private; + struct kbtab *kbtab = input_get_drvdata(dev); usb_kill_urb(kbtab->irq); } @@ -147,7 +147,8 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i input_dev->phys = kbtab->phys; usb_to_input_id(dev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = kbtab; + + input_set_drvdata(input_dev, kbtab); input_dev->open = kbtab_open; input_dev->close = kbtab_close; diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c index d32a7684de9..daf8f218a1f 100644 --- a/drivers/usb/input/keyspan_remote.c +++ b/drivers/usb/input/keyspan_remote.c @@ -394,7 +394,7 @@ resubmit: static int keyspan_open(struct input_dev *dev) { - struct usb_keyspan *remote = dev->private; + struct usb_keyspan *remote = input_get_drvdata(dev); remote->irq_urb->dev = remote->udev; if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) @@ -405,7 +405,7 @@ static int keyspan_open(struct input_dev *dev) static void keyspan_close(struct input_dev *dev) { - struct usb_keyspan *remote = dev->private; + struct usb_keyspan *remote = input_get_drvdata(dev); usb_kill_urb(remote->irq_urb); } @@ -502,7 +502,8 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic if (keyspan_key_table[i] != KEY_RESERVED) set_bit(keyspan_key_table[i], input_dev->keybit); - input_dev->private = remote; + input_set_drvdata(input_dev, remote); + input_dev->open = keyspan_open; input_dev->close = keyspan_close; diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c index ce27449dd69..f951a4482ef 100644 --- a/drivers/usb/input/powermate.c +++ b/drivers/usb/input/powermate.c @@ -252,7 +252,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value) { unsigned int command = (unsigned int)_value; - struct powermate_device *pm = dev->private; + struct powermate_device *pm = input_get_drvdata(dev); if (type == EV_MSC && code == MSC_PULSELED){ /* @@ -360,7 +360,8 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i input_dev->phys = pm->phys; usb_to_input_id(udev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = pm; + + input_set_drvdata(input_dev, pm); input_dev->event = powermate_input_event; diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c index 86e37a20f8e..169692729b8 100644 --- a/drivers/usb/input/usbtouchscreen.c +++ b/drivers/usb/input/usbtouchscreen.c @@ -647,7 +647,7 @@ exit: static int usbtouch_open(struct input_dev *input) { - struct usbtouch_usb *usbtouch = input->private; + struct usbtouch_usb *usbtouch = input_get_drvdata(input); usbtouch->irq->dev = usbtouch->udev; @@ -659,7 +659,7 @@ static int usbtouch_open(struct input_dev *input) static void usbtouch_close(struct input_dev *input) { - struct usbtouch_usb *usbtouch = input->private; + struct usbtouch_usb *usbtouch = input_get_drvdata(input); usb_kill_urb(usbtouch->irq); } @@ -741,7 +741,9 @@ static int usbtouch_probe(struct usb_interface *intf, input_dev->phys = usbtouch->phys; usb_to_input_id(udev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = usbtouch; + + input_set_drvdata(input_dev, usbtouch); + input_dev->open = usbtouch_open; input_dev->close = usbtouch_close; diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c index 48988e63ebe..7793ffbf525 100644 --- a/drivers/usb/input/wacom_sys.c +++ b/drivers/usb/input/wacom_sys.c @@ -122,7 +122,7 @@ void wacom_input_sync(void *wcombo) static int wacom_open(struct input_dev *dev) { - struct wacom *wacom = dev->private; + struct wacom *wacom = input_get_drvdata(dev); wacom->irq->dev = wacom->usbdev; if (usb_submit_urb(wacom->irq, GFP_KERNEL)) @@ -133,7 +133,7 @@ static int wacom_open(struct input_dev *dev) static void wacom_close(struct input_dev *dev) { - struct wacom *wacom = dev->private; + struct wacom *wacom = input_get_drvdata(dev); usb_kill_urb(wacom->irq); } @@ -231,7 +231,9 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i usb_to_input_id(dev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = wacom; + + input_set_drvdata(input_dev, wacom); + input_dev->open = wacom_open; input_dev->close = wacom_close; diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c index ca03d1fc233..b00179626be 100644 --- a/drivers/usb/input/xpad.c +++ b/drivers/usb/input/xpad.c @@ -267,7 +267,7 @@ exit: static int xpad_open (struct input_dev *dev) { - struct usb_xpad *xpad = dev->private; + struct usb_xpad *xpad = input_get_drvdata(dev); xpad->irq_in->dev = xpad->udev; if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) @@ -278,7 +278,7 @@ static int xpad_open (struct input_dev *dev) static void xpad_close (struct input_dev *dev) { - struct usb_xpad *xpad = dev->private; + struct usb_xpad *xpad = input_get_drvdata(dev); usb_kill_urb(xpad->irq_in); } @@ -346,7 +346,9 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id input_dev->phys = xpad->phys; usb_to_input_id(udev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = xpad; + + input_set_drvdata(input_dev, xpad); + input_dev->open = xpad_open; input_dev->close = xpad_close; diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c index 688abcdf1f0..294224e20f4 100644 --- a/drivers/usb/input/yealink.c +++ b/drivers/usb/input/yealink.c @@ -502,7 +502,7 @@ static int input_ev(struct input_dev *dev, unsigned int type, static int input_open(struct input_dev *dev) { - struct yealink_dev *yld = dev->private; + struct yealink_dev *yld = input_get_drvdata(dev); int i, ret; dbg("%s", __FUNCTION__); @@ -529,7 +529,7 @@ static int input_open(struct input_dev *dev) static void input_close(struct input_dev *dev) { - struct yealink_dev *yld = dev->private; + struct yealink_dev *yld = input_get_drvdata(dev); usb_kill_urb(yld->urb_ctl); usb_kill_urb(yld->urb_irq); @@ -939,7 +939,8 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id) usb_to_input_id(udev, &input_dev->id); input_dev->cdev.dev = &intf->dev; - input_dev->private = yld; + input_set_drvdata(input_dev, yld); + input_dev->open = input_open; input_dev->close = input_close; /* input_dev->event = input_ev; TODO */ -- cgit v1.2.3 From c0f82d570c84f2592367e350a92ebd71e72ba68a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 12 Apr 2007 01:35:03 -0400 Subject: Input: USB devices - switch to using input_dev->dev.parent In preparation for struct class_device -> struct device input core conversion, switch to using input_dev->dev.parent when specifying device position in sysfs tree. Signed-off-by: Dmitry Torokhov --- drivers/usb/input/acecad.c | 2 +- drivers/usb/input/aiptek.c | 2 +- drivers/usb/input/appletouch.c | 2 +- drivers/usb/input/ati_remote.c | 2 +- drivers/usb/input/ati_remote2.c | 2 +- drivers/usb/input/gtco.c | 2 +- drivers/usb/input/kbtab.c | 2 +- drivers/usb/input/keyspan_remote.c | 2 +- drivers/usb/input/powermate.c | 2 +- drivers/usb/input/usbtouchscreen.c | 2 +- drivers/usb/input/wacom_sys.c | 2 +- drivers/usb/input/xpad.c | 2 +- drivers/usb/input/yealink.c | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c index 75972b7d4c8..be8e9243c06 100644 --- a/drivers/usb/input/acecad.c +++ b/drivers/usb/input/acecad.c @@ -185,7 +185,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_ input_dev->name = acecad->name; input_dev->phys = acecad->phys; usb_to_input_id(dev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, acecad); diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c index 8b33a8eae8a..cc0a498763d 100644 --- a/drivers/usb/input/aiptek.c +++ b/drivers/usb/input/aiptek.c @@ -2044,7 +2044,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id) inputdev->name = "Aiptek"; inputdev->phys = aiptek->features.usbPath; usb_to_input_id(usbdev, &inputdev->id); - inputdev->cdev.dev = &intf->dev; + inputdev->dev.parent = &intf->dev; input_set_drvdata(inputdev, aiptek); diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c index ef6166ab8fe..e3215267db1 100644 --- a/drivers/usb/input/appletouch.c +++ b/drivers/usb/input/appletouch.c @@ -584,7 +584,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id input_dev->name = "appletouch"; input_dev->phys = dev->phys; usb_to_input_id(dev->udev, &input_dev->id); - input_dev->cdev.dev = &iface->dev; + input_dev->dev.parent = &iface->dev; input_set_drvdata(input_dev, dev); diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index 876b2725609..5d3ddb91666 100644 --- a/drivers/usb/input/ati_remote.c +++ b/drivers/usb/input/ati_remote.c @@ -662,7 +662,7 @@ static void ati_remote_input_init(struct ati_remote *ati_remote) idev->phys = ati_remote->phys; usb_to_input_id(ati_remote->udev, &idev->id); - idev->cdev.dev = &ati_remote->udev->dev; + idev->dev.parent = &ati_remote->udev->dev; } static int ati_remote_initialize(struct ati_remote *ati_remote) diff --git a/drivers/usb/input/ati_remote2.c b/drivers/usb/input/ati_remote2.c index 3c38ac649d2..a9032aa3465 100644 --- a/drivers/usb/input/ati_remote2.c +++ b/drivers/usb/input/ati_remote2.c @@ -362,7 +362,7 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2) idev->phys = ar2->phys; usb_to_input_id(ar2->udev, &idev->id); - idev->cdev.dev = &ar2->udev->dev; + idev->dev.parent = &ar2->udev->dev; retval = input_register_device(idev); if (retval) diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index 75cce2a97d2..dbd207efb8f 100644 --- a/drivers/usb/input/gtco.c +++ b/drivers/usb/input/gtco.c @@ -952,7 +952,7 @@ static int gtco_probe(struct usb_interface *usbinterface, /* Set input device required ID information */ usb_to_input_id(gtco->usbdev, &input_dev->id); - input_dev->cdev.dev = &usbinterface->dev; + input_dev->dev.parent = &usbinterface->dev; /* Setup the URB, it will be posted later on open of input device */ endpoint = &usbinterface->altsetting[0].endpoint[0].desc; diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c index 7ec999adb88..c4781b9d129 100644 --- a/drivers/usb/input/kbtab.c +++ b/drivers/usb/input/kbtab.c @@ -146,7 +146,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i input_dev->name = "KB Gear Tablet"; input_dev->phys = kbtab->phys; usb_to_input_id(dev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, kbtab); diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c index daf8f218a1f..1bffc9fa98c 100644 --- a/drivers/usb/input/keyspan_remote.c +++ b/drivers/usb/input/keyspan_remote.c @@ -495,7 +495,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic input_dev->name = remote->name; input_dev->phys = remote->phys; usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &interface->dev; + input_dev->dev.parent = &interface->dev; input_dev->evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */ for (i = 0; i < ARRAY_SIZE(keyspan_key_table); i++) diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c index f951a4482ef..4f93a760fae 100644 --- a/drivers/usb/input/powermate.c +++ b/drivers/usb/input/powermate.c @@ -359,7 +359,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i input_dev->phys = pm->phys; usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, pm); diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c index 169692729b8..e0829413336 100644 --- a/drivers/usb/input/usbtouchscreen.c +++ b/drivers/usb/input/usbtouchscreen.c @@ -740,7 +740,7 @@ static int usbtouch_probe(struct usb_interface *intf, input_dev->name = usbtouch->name; input_dev->phys = usbtouch->phys; usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, usbtouch); diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c index 7793ffbf525..1fe48208c2f 100644 --- a/drivers/usb/input/wacom_sys.c +++ b/drivers/usb/input/wacom_sys.c @@ -230,7 +230,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i wacom->wacom_wac = wacom_wac; usb_to_input_id(dev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, wacom); diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c index b00179626be..73572391295 100644 --- a/drivers/usb/input/xpad.c +++ b/drivers/usb/input/xpad.c @@ -345,7 +345,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id input_dev->name = xpad_device[i].name; input_dev->phys = xpad->phys; usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, xpad); diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c index 294224e20f4..c54f1a5dcb4 100644 --- a/drivers/usb/input/yealink.c +++ b/drivers/usb/input/yealink.c @@ -937,7 +937,7 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id) input_dev->name = nfo->name; input_dev->phys = yld->phys; usb_to_input_id(udev, &input_dev->id); - input_dev->cdev.dev = &intf->dev; + input_dev->dev.parent = &intf->dev; input_set_drvdata(input_dev, yld); -- cgit v1.2.3 From 0de9550971a0ee614ea4f06655e8a49aa3a942a8 Mon Sep 17 00:00:00 2001 From: Karl Pickett Date: Thu, 12 Apr 2007 01:35:59 -0400 Subject: Input: ati_remote - make button repeat sensitivity configurable ati_remote causes repeats after only .23 seconds with my remote and makes it hard to use comfortably. Make a precise way of setting the repeat delay time in milliseconds and default it to 500ms. The old behavior can be had by setting repeat_delay = 0. Signed-off-by: Karl Pickett Signed-off-by: Vincent Vanackere Signed-off-by: Dmitry Torokhov --- drivers/usb/input/ati_remote.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c index 5d3ddb91666..471aab20644 100644 --- a/drivers/usb/input/ati_remote.c +++ b/drivers/usb/input/ati_remote.c @@ -120,6 +120,7 @@ * behaviour. */ #define FILTER_TIME 60 /* msec */ +#define REPEAT_DELAY 500 /* msec */ static unsigned long channel_mask; module_param(channel_mask, ulong, 0644); @@ -133,6 +134,10 @@ static int repeat_filter = FILTER_TIME; module_param(repeat_filter, int, 0644); MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec"); +static int repeat_delay = REPEAT_DELAY; +module_param(repeat_delay, int, 0644); +MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec"); + #define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) #undef err #define err(format, arg...) printk(KERN_ERR format , ## arg) @@ -174,6 +179,8 @@ struct ati_remote { unsigned char old_data[2]; /* Detect duplicate events */ unsigned long old_jiffies; unsigned long acc_jiffies; /* handle acceleration */ + unsigned long first_jiffies; + unsigned int repeat_count; char name[NAME_BUFSIZE]; @@ -501,21 +508,31 @@ static void ati_remote_input_report(struct urb *urb) } if (ati_remote_tbl[index].kind == KIND_FILTERED) { + unsigned long now = jiffies; + /* Filter duplicate events which happen "too close" together. */ if (ati_remote->old_data[0] == data[1] && ati_remote->old_data[1] == data[2] && - time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(repeat_filter))) { + time_before(now, ati_remote->old_jiffies + + msecs_to_jiffies(repeat_filter))) { ati_remote->repeat_count++; } else { ati_remote->repeat_count = 0; + ati_remote->first_jiffies = now; } ati_remote->old_data[0] = data[1]; ati_remote->old_data[1] = data[2]; - ati_remote->old_jiffies = jiffies; + ati_remote->old_jiffies = now; + /* Ensure we skip at least the 4 first duplicate events (generated + * by a single keypress), and continue skipping until repeat_delay + * msecs have passed + */ if (ati_remote->repeat_count > 0 && - ati_remote->repeat_count < 5) + (ati_remote->repeat_count < 5 || + time_before(now, ati_remote->first_jiffies + + msecs_to_jiffies(repeat_delay)))) return; -- cgit v1.2.3