📄 w9968cf.c
字号:
/*************************************************************************** * Video4Linux driver for W996[87]CF JPEG USB Dual Mode Camera Chip. * * * * Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it> * * * * - Memory management code from bttv driver by Ralph Metzler, * * Marcus Metzler and Gerd Knorr. * * - I2C interface to kernel, high-level image sensor control routines and * * some symbolic names from OV511 driver by Mark W. McClelland. * * - Low-level I2C fast write function by Piotr Czerczak. * * - Low-level I2C read function by Frederic Jouault. * * * * 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. * ***************************************************************************/#include <linux/version.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/kmod.h>#include <linux/init.h>#include <linux/fs.h>#include <linux/vmalloc.h>#include <linux/slab.h>#include <linux/mm.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/ioctl.h>#include <linux/delay.h>#include <linux/stddef.h>#include <asm/page.h>#include <asm/uaccess.h>#include <linux/page-flags.h>#include <linux/moduleparam.h>#include "w9968cf.h"#include "w9968cf_decoder.h"/**************************************************************************** * Module macros and parameters * ****************************************************************************/MODULE_DEVICE_TABLE(usb, winbond_id_table);MODULE_AUTHOR(W9968CF_MODULE_AUTHOR" "W9968CF_AUTHOR_EMAIL);MODULE_DESCRIPTION(W9968CF_MODULE_NAME);MODULE_VERSION(W9968CF_MODULE_VERSION);MODULE_LICENSE(W9968CF_MODULE_LICENSE);MODULE_SUPPORTED_DEVICE("Video");static int ovmod_load = W9968CF_OVMOD_LOAD;static int vppmod_load = W9968CF_VPPMOD_LOAD;static unsigned short simcams = W9968CF_SIMCAMS;static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_PACKET_SIZE};static unsigned short max_buffers[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BUFFERS};static int double_buffer[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_DOUBLE_BUFFER};static int clamping[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLAMPING};static unsigned short filter_type[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_FILTER_TYPE};static int largeview[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_LARGEVIEW};static unsigned short decompression[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_DECOMPRESSION};static int upscaling[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_UPSCALING};static unsigned short force_palette[] = {[0 ... W9968CF_MAX_DEVICES-1] = 0};static int force_rgb[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_FORCE_RGB};static int autobright[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOBRIGHT};static int autoexp[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOEXP};static unsigned short lightfreq[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_LIGHTFREQ};static int bandingfilter[] = {[0 ... W9968CF_MAX_DEVICES-1]= W9968CF_BANDINGFILTER};static short clockdiv[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLOCKDIV};static int backlight[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BACKLIGHT};static int mirror[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_MIRROR};static int monochrome[] = {[0 ... W9968CF_MAX_DEVICES-1]=W9968CF_MONOCHROME};static unsigned int brightness[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BRIGHTNESS};static unsigned int hue[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_HUE};static unsigned int colour[]={[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_COLOUR};static unsigned int contrast[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CONTRAST};static unsigned int whiteness[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_WHITENESS};#ifdef W9968CF_DEBUGstatic unsigned short debug = W9968CF_DEBUG_LEVEL;static int specific_debug = W9968CF_SPECIFIC_DEBUG;#endifstatic unsigned int param_nv[24]; /* number of values per parameter */#ifdef CONFIG_KMODmodule_param(ovmod_load, bool, 0644);module_param(vppmod_load, bool, 0444);#endifmodule_param(simcams, ushort, 0644);module_param_array(video_nr, short, param_nv[0], 0444);module_param_array(packet_size, uint, param_nv[1], 0444);module_param_array(max_buffers, ushort, param_nv[2], 0444);module_param_array(double_buffer, bool, param_nv[3], 0444);module_param_array(clamping, bool, param_nv[4], 0444);module_param_array(filter_type, ushort, param_nv[5], 0444);module_param_array(largeview, bool, param_nv[6], 0444);module_param_array(decompression, ushort, param_nv[7], 0444);module_param_array(upscaling, bool, param_nv[8], 0444);module_param_array(force_palette, ushort, param_nv[9], 0444);module_param_array(force_rgb, ushort, param_nv[10], 0444);module_param_array(autobright, bool, param_nv[11], 0444);module_param_array(autoexp, bool, param_nv[12], 0444);module_param_array(lightfreq, ushort, param_nv[13], 0444);module_param_array(bandingfilter, bool, param_nv[14], 0444);module_param_array(clockdiv, short, param_nv[15], 0444);module_param_array(backlight, bool, param_nv[16], 0444);module_param_array(mirror, bool, param_nv[17], 0444);module_param_array(monochrome, bool, param_nv[18], 0444);module_param_array(brightness, uint, param_nv[19], 0444);module_param_array(hue, uint, param_nv[20], 0444);module_param_array(colour, uint, param_nv[21], 0444);module_param_array(contrast, uint, param_nv[22], 0444);module_param_array(whiteness, uint, param_nv[23], 0444);#ifdef W9968CF_DEBUGmodule_param(debug, ushort, 0644);module_param(specific_debug, bool, 0644);#endif#ifdef CONFIG_KMODMODULE_PARM_DESC(ovmod_load, "\n<0|1> Automatic 'ovcamchip' module loading." "\n0 disabled, 1 enabled." "\nIf enabled,'insmod' searches for the required 'ovcamchip'" "\nmodule in the system, according to its configuration, and" "\nattempts to load that module automatically. This action is" "\nperformed once as soon as the 'w9968cf' module is loaded" "\ninto memory." "\nDefault value is "__MODULE_STRING(W9968CF_OVMOD_LOAD)"." "\n");MODULE_PARM_DESC(vppmod_load, "\n<0|1> Automatic 'w9968cf-vpp' module loading." "\n0 disabled, 1 enabled." "\nIf enabled, every time an application attempts to open a" "\ncamera, 'insmod' searches for the video post-processing" "\nmodule in the system and loads it automatically (if" "\npresent). The optional 'w9968cf-vpp' module adds extra" "\n image manipulation functions to the 'w9968cf' module,like" "\nsoftware up-scaling,colour conversions and video decoding" "\nfor very high frame rates." "\nDefault value is "__MODULE_STRING(W9968CF_VPPMOD_LOAD)"." "\n");#endifMODULE_PARM_DESC(simcams, "\n<n> Number of cameras allowed to stream simultaneously." "\nn may vary from 0 to " __MODULE_STRING(W9968CF_MAX_DEVICES)"." "\nDefault value is "__MODULE_STRING(W9968CF_SIMCAMS)"." "\n");MODULE_PARM_DESC(video_nr, "\n<-1|n[,...]> Specify V4L minor mode number." "\n -1 = use next available (default)" "\n n = use minor number n (integer >= 0)" "\nYou can specify up to "__MODULE_STRING(W9968CF_MAX_DEVICES) " cameras this way." "\nFor example:" "\nvideo_nr=-1,2,-1 would assign minor number 2 to" "\nthe second camera and use auto for the first" "\none and for every other camera." "\n");MODULE_PARM_DESC(packet_size, "\n<n[,...]> Specify the maximum data payload" "\nsize in bytes for alternate settings, for each device." "\nn is scaled between 63 and 1023 " "(default is "__MODULE_STRING(W9968CF_PACKET_SIZE)")." "\n");MODULE_PARM_DESC(max_buffers, "\n<n[,...]> For advanced users." "\nSpecify the maximum number of video frame buffers" "\nto allocate for each device, from 2 to " __MODULE_STRING(W9968CF_MAX_BUFFERS) ". (default is "__MODULE_STRING(W9968CF_BUFFERS)")." "\n");MODULE_PARM_DESC(double_buffer, "\n<0|1[,...]> " "Hardware double buffering: 0 disabled, 1 enabled." "\nIt should be enabled if you want smooth video output: if" "\nyou obtain out of sync. video, disable it, or try to" "\ndecrease the 'clockdiv' module parameter value." "\nDefault value is "__MODULE_STRING(W9968CF_DOUBLE_BUFFER) " for every device." "\n");MODULE_PARM_DESC(clamping, "\n<0|1[,...]> Video data clamping: 0 disabled, 1 enabled." "\nDefault value is "__MODULE_STRING(W9968CF_CLAMPING) " for every device." "\n");MODULE_PARM_DESC(filter_type, "\n<0|1|2[,...]> Video filter type." "\n0 none, 1 (1-2-1) 3-tap filter, " "2 (2-3-6-3-2) 5-tap filter." "\nDefault value is "__MODULE_STRING(W9968CF_FILTER_TYPE) " for every device." "\nThe filter is used to reduce noise and aliasing artifacts" "\nproduced by the CCD or CMOS image sensor, and the scaling" " process." "\n");MODULE_PARM_DESC(largeview, "\n<0|1[,...]> Large view: 0 disabled, 1 enabled." "\nDefault value is "__MODULE_STRING(W9968CF_LARGEVIEW) " for every device." "\n");MODULE_PARM_DESC(upscaling, "\n<0|1[,...]> Software scaling (for non-compressed video):" "\n0 disabled, 1 enabled." "\nDisable it if you have a slow CPU or you don't have" " enough memory." "\nDefault value is "__MODULE_STRING(W9968CF_UPSCALING) " for every device." "\nIf 'w9968cf-vpp' is not present, this parameter is" " set to 0." "\n");MODULE_PARM_DESC(decompression, "\n<0|1|2[,...]> Software video decompression:" "\n- 0 disables decompression (doesn't allow formats needing" " decompression)" "\n- 1 forces decompression (allows formats needing" " decompression only);" "\n- 2 allows any permitted formats." "\nFormats supporting compressed video are YUV422P and" " YUV420P/YUV420 " "\nin any resolutions where both width and height are " "a multiple of 16." "\nDefault value is "__MODULE_STRING(W9968CF_DECOMPRESSION) " for every device." "\nIf 'w9968cf-vpp' is not present, forcing decompression is " "\nnot allowed; in this case this parameter is set to 2." "\n");MODULE_PARM_DESC(force_palette, "\n<0" "|" __MODULE_STRING(VIDEO_PALETTE_UYVY) "|" __MODULE_STRING(VIDEO_PALETTE_YUV420) "|" __MODULE_STRING(VIDEO_PALETTE_YUV422P) "|" __MODULE_STRING(VIDEO_PALETTE_YUV420P) "|" __MODULE_STRING(VIDEO_PALETTE_YUYV) "|" __MODULE_STRING(VIDEO_PALETTE_YUV422) "|" __MODULE_STRING(VIDEO_PALETTE_GREY) "|" __MODULE_STRING(VIDEO_PALETTE_RGB555) "|" __MODULE_STRING(VIDEO_PALETTE_RGB565) "|" __MODULE_STRING(VIDEO_PALETTE_RGB24) "|" __MODULE_STRING(VIDEO_PALETTE_RGB32) "[,...]>" " Force picture palette." "\nIn order:" "\n- 0 allows any of the following formats:" "\n- UYVY 16 bpp - Original video, compression disabled" "\n- YUV420 12 bpp - Original video, compression enabled" "\n- YUV422P 16 bpp - Original video, compression enabled" "\n- YUV420P 12 bpp - Original video, compression enabled" "\n- YUVY 16 bpp - Software conversion from UYVY" "\n- YUV422 16 bpp - Software conversion from UYVY" "\n- GREY 8 bpp - Software conversion from UYVY" "\n- RGB555 16 bpp - Software conversion from UYVY" "\n- RGB565 16 bpp - Software conversion from UYVY" "\n- RGB24 24 bpp - Software conversion from UYVY" "\n- RGB32 32 bpp - Software conversion from UYVY" "\nWhen not 0, this parameter will override 'decompression'." "\nDefault value is 0 for every device." "\nInitial palette is " __MODULE_STRING(W9968CF_PALETTE_DECOMP_ON)"." "\nIf 'w9968cf-vpp' is not present, this parameter is" " set to 9 (UYVY)." "\n");MODULE_PARM_DESC(force_rgb, "\n<0|1[,...]> Read RGB video data instead of BGR:" "\n 1 = use RGB component ordering." "\n 0 = use BGR component ordering." "\nThis parameter has effect when using RGBX palettes only." "\nDefault value is "__MODULE_STRING(W9968CF_FORCE_RGB) " for every device." "\n");MODULE_PARM_DESC(autobright, "\n<0|1[,...]> Image sensor automatically changes brightness:" "\n 0 = no, 1 = yes" "\nDefault value is "__MODULE_STRING(W9968CF_AUTOBRIGHT) " for every device." "\n");MODULE_PARM_DESC(autoexp, "\n<0|1[,...]> Image sensor automatically changes exposure:" "\n 0 = no, 1 = yes" "\nDefault value is "__MODULE_STRING(W9968CF_AUTOEXP) " for every device." "\n");MODULE_PARM_DESC(lightfreq, "\n<50|60[,...]> Light frequency in Hz:" "\n 50 for European and Asian lighting," " 60 for American lighting." "\nDefault value is "__MODULE_STRING(W9968CF_LIGHTFREQ) " for every device." "\n");MODULE_PARM_DESC(bandingfilter, "\n<0|1[,...]> Banding filter to reduce effects of" " fluorescent lighting:" "\n 0 disabled, 1 enabled." "\nThis filter tries to reduce the pattern of horizontal" "\nlight/dark bands caused by some (usually fluorescent)" " lighting." "\nDefault value is "__MODULE_STRING(W9968CF_BANDINGFILTER) " for every device." "\n");MODULE_PARM_DESC(clockdiv, "\n<-1|n[,...]> " "Force pixel clock divisor to a specific value (for experts):" "\n n may vary from 0 to 127." "\n -1 for automatic value." "\nSee also the 'double_buffer' module parameter." "\nDefault value is "__MODULE_STRING(W9968CF_CLOCKDIV) " for every device." "\n");MODULE_PARM_DESC(backlight, "\n<0|1[,...]> Objects are lit from behind:" "\n 0 = no, 1 = yes" "\nDefault value is "__MODULE_STRING(W9968CF_BACKLIGHT) " for every device." "\n");MODULE_PARM_DESC(mirror, "\n<0|1[,...]> Reverse image horizontally:" "\n 0 = no, 1 = yes" "\nDefault value is "__MODULE_STRING(W9968CF_MIRROR) " for every device." "\n");MODULE_PARM_DESC(monochrome, "\n<0|1[,...]> Use image sensor as monochrome sensor:" "\n 0 = no, 1 = yes" "\nNot all the sensors support monochrome color." "\nDefault value is "__MODULE_STRING(W9968CF_MONOCHROME) " for every device." "\n");MODULE_PARM_DESC(brightness, "\n<n[,...]> Set picture brightness (0-65535)." "\nDefault value is "__MODULE_STRING(W9968CF_BRIGHTNESS) " for every device." "\nThis parameter has no effect if 'autobright' is enabled." "\n");MODULE_PARM_DESC(hue, "\n<n[,...]> Set picture hue (0-65535)." "\nDefault value is "__MODULE_STRING(W9968CF_HUE) " for every device." "\n");MODULE_PARM_DESC(colour, "\n<n[,...]> Set picture saturation (0-65535)." "\nDefault value is "__MODULE_STRING(W9968CF_COLOUR)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -