⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwc-if.c

📁 webcam device driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	else if (vendor_id == 0x04cc) {		switch(product_id) {		case 0x8116:			PWC_INFO("Sotec Afina Eye USB webcam detected.\n");			name = "Sotec Afina Eye";			type_id = 730;			break;		default:			return -ENODEV;			break;		}	}	else if (vendor_id == 0x06be) {		switch(product_id) {		case 0x8116:			/* This is essentially the same cam as the Sotec Afina Eye */			PWC_INFO("AME Co. Afina Eye USB webcam detected.\n");			name = "AME Co. Afina Eye";			type_id = 750;			break;		default:			return -ENODEV;			break;		}		}	else if (vendor_id == 0x0d81) {		switch(product_id) {		case 0x1900:			PWC_INFO("Visionite VCS-UC300 USB webcam detected.\n");			name = "Visionite VCS-UC300";			type_id = 740; /* CCD sensor */			break;		case 0x1910:			PWC_INFO("Visionite VCS-UM100 USB webcam detected.\n");			name = "Visionite VCS-UM100";			type_id = 730; /* CMOS sensor */			break;		default:			return -ENODEV;			break;		}	}	else 		return -ENODEV; /* Not any of the know types; but the list keeps growing. */	memset(serial_number, 0, 30);	usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29);	PWC_DEBUG_PROBE("Device serial number is %s\n", serial_number);	if (udev->descriptor.bNumConfigurations > 1)		PWC_WARNING("Warning: more than 1 configuration available.\n");	/* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */	pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL);	if (pdev == NULL) {		PWC_ERROR("Oops, could not allocate memory for pwc_device.\n");		return -ENOMEM;	}	pdev->type = type_id;	pdev->vsize = default_size;	pdev->vframes = default_fps;	strcpy(pdev->serial, serial_number);	pdev->features = features;	if (vendor_id == 0x046D && product_id == 0x08B5)	{		/* Logitech QuickCam Orbit	           The ranges have been determined experimentally; they may differ from cam to cam.	           Also, the exact ranges left-right and up-down are different for my cam	          */		pdev->angle_range.pan_min  = -7000;		pdev->angle_range.pan_max  =  7000;		pdev->angle_range.tilt_min = -3000;		pdev->angle_range.tilt_max =  2500;	}	init_MUTEX(&pdev->modlock);	spin_lock_init(&pdev->ptrlock);	pdev->udev = udev;	init_waitqueue_head(&pdev->frameq);	pdev->vcompression = pwc_preferred_compression;	/* Allocate video_device structure */	pdev->vdev = video_device_alloc();	if (pdev->vdev == 0)	{		PWC_ERROR("Err, cannot allocate video_device struture. Failing probe.");		kfree(pdev);		return -ENOMEM;	}	memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template));	pdev->vdev->dev = &(udev->dev);	strcpy(pdev->vdev->name, name);	pdev->vdev->owner = THIS_MODULE;	video_set_drvdata(pdev->vdev, pdev);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)	pdev->release = udev->descriptor.bcdDevice;#else	pdev->release = le16_to_cpu(udev->descriptor.bcdDevice);#endif	PWC_DEBUG_PROBE("Release: %04x\n", pdev->release);	/* Now search device_hint[] table for a match, so we can hint a node number. */	for (hint = 0; hint < MAX_DEV_HINTS; hint++) {		if (((device_hint[hint].type == -1) || (device_hint[hint].type == pdev->type)) &&		     (device_hint[hint].pdev == NULL)) {			/* so far, so good... try serial number */			if ((device_hint[hint].serial_number[0] == '*') || !strcmp(device_hint[hint].serial_number, serial_number)) {			    	/* match! */			    	video_nr = device_hint[hint].device_node;			    	PWC_DEBUG_PROBE("Found hint, will try to register as /dev/video%d\n", video_nr);			    	break;			}		}	}	pdev->vdev->release = video_device_release;	i = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr);	if (i < 0) {		PWC_ERROR("Failed to register as video device (%d).\n", i);		video_device_release(pdev->vdev); /* Drip... drip... drip... */		kfree(pdev); /* Oops, no memory leaks please */		return -EIO;	}	else {		PWC_INFO("Registered as /dev/video%d.\n", pdev->vdev->minor & 0x3F);	}	/* occupy slot */	if (hint < MAX_DEV_HINTS) 		device_hint[hint].pdev = pdev;	PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev);	usb_set_intfdata (intf, pdev);	pwc_create_sysfs_files(pdev->vdev);	/* Set the leds off */	pwc_set_leds(pdev, 0, 0);	pwc_camera_power(pdev, 0);	return 0;}/* The user janked out the cable... */static void usb_pwc_disconnect(struct usb_interface *intf){	struct pwc_device *pdev;	int hint;	lock_kernel();	pdev = usb_get_intfdata (intf);	usb_set_intfdata (intf, NULL);	if (pdev == NULL) {		PWC_ERROR("pwc_disconnect() Called without private pointer.\n");		goto disconnect_out;	}	if (pdev->udev == NULL) {		PWC_ERROR("pwc_disconnect() already called for %p\n", pdev);		goto disconnect_out;	}	if (pdev->udev != interface_to_usbdev(intf)) {		PWC_ERROR("pwc_disconnect() Woops: pointer mismatch udev/pdev.\n");		goto disconnect_out;	}	/* We got unplugged; this is signalled by an EPIPE error code */	if (pdev->vopen) {		PWC_INFO("Disconnected while webcam is in use!\n");		pdev->error_status = EPIPE;	}	/* Alert waiting processes */	wake_up_interruptible(&pdev->frameq);	/* Wait until device is closed */	while (pdev->vopen)		schedule();	/* Device is now closed, so we can safely unregister it */	PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n");	pwc_remove_sysfs_files(pdev->vdev);	video_unregister_device(pdev->vdev);	/* Free memory (don't set pdev to 0 just yet) */	kfree(pdev);disconnect_out:	/* search device_hint[] table if we occupy a slot, by any chance */	for (hint = 0; hint < MAX_DEV_HINTS; hint++)		if (device_hint[hint].pdev == pdev)			device_hint[hint].pdev = NULL;	unlock_kernel();}/* *grunt* We have to do atoi ourselves :-( */static int pwc_atoi(const char *s){	int k = 0;	k = 0;	while (*s != '\0' && *s >= '0' && *s <= '9') {		k = 10 * k + (*s - '0');		s++;	}	return k;}/*  * Initialization code & module stuff  */static char *size;static int fps;static int fbufs;static int mbufs;static int compression = -1;static int leds[2] = { -1, -1 };static int leds_nargs;static char *dev_hint[MAX_DEV_HINTS];static int dev_hint_nargs;module_param(size, charp, 0444);module_param(fps, int, 0444);module_param(fbufs, int, 0444);module_param(mbufs, int, 0444);#if CONFIG_PWC_DEBUGmodule_param_named(trace, pwc_trace, int, 0644);#endifmodule_param(power_save, int, 0444);module_param(compression, int, 0444);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)module_param_array(leds, int, leds_nargs, 0444);module_param_array(dev_hint, charp, dev_hint_nargs, 0444);#elsemodule_param_array(leds, int, &leds_nargs, 0444);module_param_array(dev_hint, charp, &dev_hint_nargs, 0444);#endifMODULE_PARM_DESC(size, "Initial image size. One of sqcif, qsif, qcif, sif, cif, vga");MODULE_PARM_DESC(fps, "Initial frames per second. Varies with model, useful range 5-30");MODULE_PARM_DESC(fbufs, "Number of internal frame buffers to reserve");MODULE_PARM_DESC(mbufs, "Number of external (mmap()ed) image buffers");MODULE_PARM_DESC(trace, "For debugging purposes");MODULE_PARM_DESC(power_save, "Turn power save feature in camera on or off");MODULE_PARM_DESC(compression, "Preferred compression quality. Range 0 (uncompressed) to 3 (high compression)");MODULE_PARM_DESC(leds, "LED on,off time in milliseconds");MODULE_PARM_DESC(dev_hint, "Device node hints");MODULE_DESCRIPTION("Philips & OEM USB webcam driver");MODULE_AUTHOR("Luc Saillard <luc@saillard.org>");MODULE_LICENSE("GPL");MODULE_ALIAS("pwcx");MODULE_VERSION( PWC_VERSION );static int __init usb_pwc_init(void){	int i, sz;	char *sizenames[PSZ_MAX] = { "sqcif", "qsif", "qcif", "sif", "cif", "vga" };	PWC_INFO("Philips webcam module version " PWC_VERSION " loaded.\n");	PWC_INFO("Supports Philips PCA645/646, PCVC675/680/690, PCVC720[40]/730/740/750 & PCVC830/840.\n");	PWC_INFO("Also supports the Askey VC010, various Logitech Quickcams, Samsung MPC-C10 and MPC-C30,\n");	PWC_INFO("the Creative WebCam 5 & Pro Ex, SOTEC Afina Eye and Visionite VCS-UC300 and VCS-UM100.\n");	if (fps) {		if (fps < 4 || fps > 30) {			PWC_ERROR("Framerate out of bounds (4-30).\n");			return -EINVAL;		}		default_fps = fps;		PWC_DEBUG_MODULE("Default framerate set to %d.\n", default_fps);	}	if (size) {		/* string; try matching with array */		for (sz = 0; sz < PSZ_MAX; sz++) {			if (!strcmp(sizenames[sz], size)) { /* Found! */				default_size = sz;				break;			}		}		if (sz == PSZ_MAX) {			PWC_ERROR("Size not recognized; try size=[sqcif | qsif | qcif | sif | cif | vga].\n");			return -EINVAL;		}		PWC_DEBUG_MODULE("Default image size set to %s [%dx%d].\n", sizenames[default_size], pwc_image_sizes[default_size].x, pwc_image_sizes[default_size].y);	}	if (mbufs) {		if (mbufs < 1 || mbufs > MAX_IMAGES) {			PWC_ERROR("Illegal number of mmap() buffers; use a number between 1 and %d.\n", MAX_IMAGES);			return -EINVAL;		}		pwc_mbufs = mbufs;		PWC_DEBUG_MODULE("Number of image buffers set to %d.\n", pwc_mbufs);	}	if (fbufs) {		if (fbufs < 2 || fbufs > MAX_FRAMES) {			PWC_ERROR("Illegal number of frame buffers; use a number between 2 and %d.\n", MAX_FRAMES);			return -EINVAL;		}		default_fbufs = fbufs;		PWC_DEBUG_MODULE("Number of frame buffers set to %d.\n", default_fbufs);	}#if CONFIG_PWC_DEBUG	if (pwc_trace >= 0) {		PWC_DEBUG_MODULE("Trace options: 0x%04x\n", pwc_trace);	}#endif	if (compression >= 0) {		if (compression > 3) {			PWC_ERROR("Invalid compression setting; use a number between 0 (uncompressed) and 3 (high).\n");			return -EINVAL;		}		pwc_preferred_compression = compression;		PWC_DEBUG_MODULE("Preferred compression set to %d.\n", pwc_preferred_compression);	}	if (power_save)		PWC_DEBUG_MODULE("Enabling power save on open/close.\n");	if (leds[0] >= 0)		led_on = leds[0];	if (leds[1] >= 0)		led_off = leds[1];	/* Big device node whoopla. Basically, it allows you to assign a	   device node (/dev/videoX) to a camera, based on its type	   & serial number. The format is [type[.serialnumber]:]node.	   Any camera that isn't matched by these rules gets the next	   available free device node.	 */	for (i = 0; i < MAX_DEV_HINTS; i++) {		char *s, *colon, *dot;		/* This loop also initializes the array */		device_hint[i].pdev = NULL;		s = dev_hint[i];		if (s != NULL && *s != '\0') {			device_hint[i].type = -1; /* wildcard */			strcpy(device_hint[i].serial_number, "*");			/* parse string: chop at ':' & '/' */			colon = dot = s;			while (*colon != '\0' && *colon != ':')				colon++;			while (*dot != '\0' && *dot != '.')				dot++;			/* Few sanity checks */			if (*dot != '\0' && dot > colon) {				PWC_ERROR("Malformed camera hint: the colon must be after the dot.\n");				return -EINVAL;			}			if (*colon == '\0') {				/* No colon */				if (*dot != '\0') {					PWC_ERROR("Malformed camera hint: no colon + device node given.\n");					return -EINVAL;				}				else {					/* No type or serial number specified, just a number. */					device_hint[i].device_node = pwc_atoi(s);				}			}			else {				/* There's a colon, so we have at least a type and a device node */				device_hint[i].type = pwc_atoi(s);				device_hint[i].device_node = pwc_atoi(colon + 1);				if (*dot != '\0') {					/* There's a serial number as well */					int k;										dot++;					k = 0;					while (*dot != ':' && k < 29) {						device_hint[i].serial_number[k++] = *dot;						dot++;					}					device_hint[i].serial_number[k] = '\0';				}			}			PWC_TRACE("device_hint[%d]:\n", i);			PWC_TRACE("  type    : %d\n", device_hint[i].type);			PWC_TRACE("  serial# : %s\n", device_hint[i].serial_number);			PWC_TRACE("  node    : %d\n", device_hint[i].device_node);		}		else			device_hint[i].type = 0; /* not filled */	} /* ..for MAX_DEV_HINTS */ 	PWC_DEBUG_PROBE("Registering driver at address 0x%p.\n", &pwc_driver);	return usb_register(&pwc_driver);}static void __exit usb_pwc_exit(void){	PWC_DEBUG_MODULE("Deregistering driver.\n");	usb_deregister(&pwc_driver);	PWC_INFO("Philips webcam module removed.\n");}module_init(usb_pwc_init);module_exit(usb_pwc_exit);/* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -