--- ezcam24.c 2005-04-14 07:15:25.000000000 +0900 +++ ezcam26.c 2005-04-14 07:10:48.000000000 +0900 @@ -2,11 +2,11 @@ * USB EZCam Camera driver by Device Drivers Limited (http://www.devdrv.co.jp/) * Modified from IBM USB NB Camera driver * 9/26/2003 + * 4/11/2005 ported to linux 2.6 */ #include #include -#include #include #include @@ -27,7 +27,7 @@ } ezcam_t; #define EZCAM_T(uvd) ((ezcam_t *)((uvd)->user_data)) -static usbvideo_t *cams = NULL; +static struct usbvideo *cams = NULL; static int debug = 5; @@ -59,7 +59,7 @@ static int init_color = 128; static int init_hue = 128; -MODULE_PARM(debug, "i"); +module_param(debug, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)"); /* @@ -73,7 +73,7 @@ * 06-Nov-2000 Rewrote to dump all data into frame. */ -void ezcam_ProcessIsocData(uvd_t *uvd, usbvideo_frame_t *frame) +static void ezcam_ProcessIsocData(struct uvd *uvd, struct usbvideo_frame *frame) { int n, i, c; int m = -1; @@ -154,7 +154,7 @@ /* * ezcam_calculate_fps() */ -static int ezcam_calculate_fps(uvd_t *uvd) +static int ezcam_calculate_fps(struct uvd *uvd) { return 3 + framerate*4 + framerate/2; } @@ -165,7 +165,7 @@ * This procedure gets called from V4L interface to update picture settings. * Here we change brightness and contrast. */ -static void ezcam_adjust_picture(uvd_t *uvd) +static void ezcam_adjust_picture(struct uvd *uvd) { } @@ -175,19 +175,19 @@ * This code tells camera to stop streaming. The interface remains * configured and bandwidth - claimed. */ -static void ezcam_video_stop(uvd_t *uvd) +static void ezcam_video_stop(struct uvd *uvd) { if (debug >= 1) info("ezcam_video_start"); } -static void ezcam_video_start(uvd_t *uvd) +static void ezcam_video_start(struct uvd *uvd) { if (debug >= 1) info("ezcam_video_start"); } -static int ezcam_resetPipe(uvd_t *uvd) +static int ezcam_resetPipe(struct uvd *uvd) { usb_clear_halt(uvd->dev, uvd->video_endp); return 0; @@ -196,7 +196,7 @@ /* * Return negative code on failure, 0 on success. */ -static int ezcam_setup_on_open(uvd_t *uvd) +static int ezcam_setup_on_open(struct uvd *uvd) { int setup_ok = 0; /* Success by default */ /* Send init sequence only once, it's large! */ @@ -207,7 +207,7 @@ return setup_ok; } -static void ezcam_configure_video(uvd_t *uvd) +static void ezcam_configure_video(struct uvd *uvd) { if (uvd == NULL) return; @@ -249,99 +249,99 @@ * History: * 12-Nov-2000 Reworked to comply with new probe() signature. * 23-Jan-2001 Added compatibility with 2.2.x kernels. + * 11-Apl-2005 ported to linux 2.6 */ -static void *ezcam_probe(struct usb_device *dev, unsigned int ifnum ,const struct usb_device_id *devid) +static int ezcam_probe(struct usb_interface *intf, const struct usb_device_id *devid) { - uvd_t *uvd = NULL; - int i, nas; + struct usb_device *dev = interface_to_usbdev(intf); + struct uvd *uvd = NULL; + int ix, i=0, nas; int actInterface=-1, inactInterface=-1, maxPS=0; unsigned char video_ep = 0; if (debug >= 1) - info("ezcam_probe(%p,%u.)", dev, ifnum); + info("ezcam_probe(%p,%p)", dev, intf); /* We don't handle multi-config cameras */ if (dev->descriptor.bNumConfigurations != 1) - return NULL; + return -ENODEV; - /* Is it an IBM camera? */ - if ((dev->descriptor.idVendor != EZCAM_VENDOR_ID) || - (dev->descriptor.idProduct != EZCAM_PRODUCT_ID)) - return NULL; - - info("Device Drivers EZ camera found (rev. 0x%04x)", dev->descriptor.bcdDevice); + info("Device Drivers EZ camera found (rev. 0x%04x)", + le16_to_cpu(dev->descriptor.bcdDevice)); /* Validate found interface: must have one ISO endpoint */ - nas = dev->actconfig->interface[ifnum].num_altsetting; + nas = intf->num_altsetting; if (debug > 0) { info("Nunmber of alternate settings=%d.", nas); } /* Validate all alternate settings */ - for(i = 0; i < nas; i++) { - const struct usb_interface_descriptor *interface; + for(ix = 0; ix < nas; ix++) { + const struct usb_host_interface *interface; const struct usb_endpoint_descriptor *endpoint; - interface = &dev->actconfig->interface[ifnum].altsetting[i]; - if (interface->bNumEndpoints != 1) { - err("Interface %d. has %u. endpoints!", - ifnum, (unsigned)(interface->bNumEndpoints)); - return NULL; + interface = &intf->altsetting[ix]; + i = interface->desc.bAlternateSetting; + if (interface->desc.bNumEndpoints != 1) { + err("Interface %d. has %u. endpoints!", + interface->desc.bInterfaceNumber, + (unsigned)(interface->desc.bNumEndpoints)); + return -ENODEV; } - endpoint = &interface->endpoint[0]; + endpoint = &interface->endpoint[0].desc; if (video_ep == 0) video_ep = endpoint->bEndpointAddress; else if (video_ep != endpoint->bEndpointAddress) { err("Alternate settings have different endpoint addresses!"); - return NULL; + return -ENODEV; } if ((endpoint->bmAttributes & 0x03) != 0x01) { - err("Interface %d. has non-ISO endpoint!", ifnum); - return NULL; + err("Interface %d. has non-ISO endpoint!", + interface->desc.bInterfaceNumber); + return -ENODEV; } if ((endpoint->bEndpointAddress & 0x80) == 0) { - err("Interface %d. has ISO OUT endpoint!", ifnum); - return NULL; + err("Interface %d. has ISO OUT endpoint!", + interface->desc.bInterfaceNumber); + return -ENODEV; } - if (endpoint->wMaxPacketSize == 0) { - if (inactInterface < 0) - inactInterface = i; - else { - err("More than one inactive alt. setting!"); - return NULL; - } + if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) { + if (inactInterface < 0) + inactInterface = i; + else { + err("More than one inactive alt. setting!"); + return -ENODEV; + } } else { - if (actInterface < 0) { - actInterface = i; - maxPS = endpoint->wMaxPacketSize; - if (debug > 0) - info("Active setting=%d. maxPS=%d.", i, maxPS); - } else { - /* Got another active alt. setting */ - if (maxPS < endpoint->wMaxPacketSize) { - /* This one is better! */ - actInterface = i; - maxPS = endpoint->wMaxPacketSize; - if (debug > 0) { - info("Even better ctive setting=%d. maxPS=%d.", - i, maxPS); - } - } - } + if (actInterface < 0) { + actInterface = i; + maxPS = le16_to_cpu(endpoint->wMaxPacketSize); + if (debug > 0) + info("Active setting=%d. maxPS=%d.", i, maxPS); + } else { + /* Got another active alt. setting */ + if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) { + /* This one is better! */ + actInterface = i; + maxPS = le16_to_cpu(endpoint->wMaxPacketSize); + if (debug > 0) { + info("Even better ctive setting=%d. maxPS=%d.", + i, maxPS); + } + } + } } } if (debug > 0) { info("maxPS = %d, actInterface = %d, inactInterface = %d", maxPS, actInterface, inactInterface); } - /* Code below may sleep, need to lock module while we are here */ - MOD_INC_USE_COUNT; uvd = usbvideo_AllocateDevice(cams); if (uvd != NULL) { - /* Here uvd is a fully allocated uvd_t object */ + /* Here uvd is a fully allocated struct uvd object */ uvd->flags = flags; uvd->debug = debug; uvd->dev = dev; - uvd->iface = ifnum; + uvd->iface = intf->altsetting->desc.bInterfaceNumber; /* uvd->ifaceAltInactive = inactInterface; */ /* uvd->ifaceAltActive = actInterface; */ uvd->video_endp = video_ep; @@ -364,10 +364,18 @@ uvd = NULL; } } - MOD_DEC_USE_COUNT; - return uvd; + if (uvd) { + usb_set_intfdata (intf, uvd); + return 0; + } + return -EIO; } +static struct usb_device_id id_table[] = { + { USB_DEVICE(EZCAM_VENDOR_ID, EZCAM_PRODUCT_ID) }, + { } /* Terminating entry */ +}; + /* * ezcam_init() * @@ -375,7 +383,7 @@ */ static int __init ezcam_init(void) { - usbvideo_cb_t cbTbl; + struct usbvideo_cb cbTbl; memset(&cbTbl, 0, sizeof(cbTbl)); cbTbl.probe = ezcam_probe; cbTbl.setupOnOpen = ezcam_setup_on_open; @@ -391,7 +399,8 @@ sizeof(ezcam_t), "ezcam", &cbTbl, - THIS_MODULE); + THIS_MODULE, + id_table); } static void __exit ezcam_cleanup(void) @@ -399,16 +408,7 @@ usbvideo_Deregister(&cams); } -#if defined(usb_device_id_ver) - -static __devinitdata struct usb_device_id id_table[] = { - { USB_DEVICE(EZCAM_VENDOR_ID, EZCAM_PRODUCT_ID) }, - { } /* Terminating entry */ -}; MODULE_DEVICE_TABLE(usb, id_table); - - -#endif /* defined(usb_device_id_ver) */ MODULE_LICENSE("GPL"); module_init(ezcam_init);