Merge to kernel-2.6.20-1.2949.fc6.vs2.2.0.1
[linux-2.6.git] / drivers / media / video / w9968cf.c
similarity index 78%
rename from drivers/usb/media/w9968cf.c
rename to drivers/media/video/w9968cf.c
index 9937fc6..9f403af 100644 (file)
 #include "w9968cf.h"
 #include "w9968cf_decoder.h"
 
+static struct w9968cf_vpp_t* w9968cf_vpp;
+static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
+
+static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
+static DEFINE_MUTEX(w9968cf_devlist_mutex); /* semaphore for list traversal */
+
+static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
 
 
 /****************************************************************************
@@ -64,39 +71,39 @@ MODULE_SUPPORTED_DEVICE("Video");
 static int ovmod_load = W9968CF_OVMOD_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 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 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 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 unsigned short lightfreq[] = {[0 ... W9968CF_MAX_DEVICES-1] =
+                                    W9968CF_LIGHTFREQ};
 static int bandingfilter[] = {[0 ... W9968CF_MAX_DEVICES-1]=
-                              W9968CF_BANDINGFILTER};
+                             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 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};
+static unsigned int contrast[] = {[0 ... W9968CF_MAX_DEVICES-1] =
+                                 W9968CF_CONTRAST};
+static unsigned int whiteness[] = {[0 ... W9968CF_MAX_DEVICES-1] =
+                                  W9968CF_WHITENESS};
 #ifdef W9968CF_DEBUG
 static unsigned short debug = W9968CF_DEBUG_LEVEL;
 static int specific_debug = W9968CF_SPECIFIC_DEBUG;
@@ -138,251 +145,251 @@ module_param(specific_debug, bool, 0644);
 #endif
 
 #ifdef CONFIG_KMOD
-MODULE_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(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");
 #endif
-MODULE_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(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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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");
+                "\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)
-                 " for every device."
-                 "\n");
-MODULE_PARM_DESC(contrast, 
-                 "\n<n[,...]> Set picture contrast (0-65535)."
-                 "\nDefault value is "__MODULE_STRING(W9968CF_CONTRAST)
-                 " for every device."
-                 "\n");
-MODULE_PARM_DESC(whiteness, 
-                 "\n<n[,...]> Set picture whiteness (0-65535)."
-                 "\nDefault value is "__MODULE_STRING(W9968CF_WHITENESS)
-                 " for every device."
-                 "\n");
+                "\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)
+                " for every device."
+                "\n");
+MODULE_PARM_DESC(contrast,
+                "\n<n[,...]> Set picture contrast (0-65535)."
+                "\nDefault value is "__MODULE_STRING(W9968CF_CONTRAST)
+                " for every device."
+                "\n");
+MODULE_PARM_DESC(whiteness,
+                "\n<n[,...]> Set picture whiteness (0-65535)."
+                "\nDefault value is "__MODULE_STRING(W9968CF_WHITENESS)
+                " for every device."
+                "\n");
 #ifdef W9968CF_DEBUG
 MODULE_PARM_DESC(debug,
-                 "\n<n> Debugging information level, from 0 to 6:"
-                 "\n0 = none (use carefully)"
-                 "\n1 = critical errors"
-                 "\n2 = significant informations"
-                 "\n3 = configuration or general messages"
-                 "\n4 = warnings"
-                 "\n5 = called functions"
-                 "\n6 = function internals"
-                 "\nLevel 5 and 6 are useful for testing only, when only "
-                 "one device is used."
-                 "\nDefault value is "__MODULE_STRING(W9968CF_DEBUG_LEVEL)"."
-                 "\n");
+                "\n<n> Debugging information level, from 0 to 6:"
+                "\n0 = none (use carefully)"
+                "\n1 = critical errors"
+                "\n2 = significant informations"
+                "\n3 = configuration or general messages"
+                "\n4 = warnings"
+                "\n5 = called functions"
+                "\n6 = function internals"
+                "\nLevel 5 and 6 are useful for testing only, when only "
+                "one device is used."
+                "\nDefault value is "__MODULE_STRING(W9968CF_DEBUG_LEVEL)"."
+                "\n");
 MODULE_PARM_DESC(specific_debug,
-                 "\n<0|1> Enable or disable specific debugging messages:"
-                 "\n0 = print messages concerning every level"
-                 " <= 'debug' level."
-                 "\n1 = print messages concerning the level"
-                 " indicated by 'debug'."
-                 "\nDefault value is "
-                 __MODULE_STRING(W9968CF_SPECIFIC_DEBUG)"."
-                 "\n");
+                "\n<0|1> Enable or disable specific debugging messages:"
+                "\n0 = print messages concerning every level"
+                " <= 'debug' level."
+                "\n1 = print messages concerning the level"
+                " indicated by 'debug'."
+                "\nDefault value is "
+                __MODULE_STRING(W9968CF_SPECIFIC_DEBUG)"."
+                "\n");
 #endif /* W9968CF_DEBUG */
 
 
@@ -399,7 +406,7 @@ static int w9968cf_mmap(struct file*, struct vm_area_struct*);
 static int w9968cf_ioctl(struct inode*, struct file*, unsigned, unsigned long);
 static ssize_t w9968cf_read(struct file*, char __user *, size_t, loff_t*);
 static int w9968cf_v4l_ioctl(struct inode*, struct file*, unsigned int,
-                             void __user *);
+                            void __user *);
 
 /* USB-specific */
 static int w9968cf_start_transfer(struct w9968cf_device*);
@@ -410,7 +417,7 @@ static int w9968cf_write_fsb(struct w9968cf_device*, u16* data);
 static int w9968cf_write_sb(struct w9968cf_device*, u16 value);
 static int w9968cf_read_sb(struct w9968cf_device*);
 static int w9968cf_upload_quantizationtables(struct w9968cf_device*);
-static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs);
+static void w9968cf_urb_complete(struct urb *urb);
 
 /* Low-level I2C (SMBus) I/O */
 static int w9968cf_smbus_start(struct w9968cf_device*);
@@ -421,25 +428,25 @@ static int w9968cf_smbus_write_ack(struct w9968cf_device*);
 static int w9968cf_smbus_read_ack(struct w9968cf_device*);
 static int w9968cf_smbus_refresh_bus(struct w9968cf_device*);
 static int w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
-                                      u16 address, u8* value);
-static int w9968cf_i2c_adap_read_byte_data(struct w9968cf_device*, u16 address, 
-                                           u8 subaddress, u8* value);
+                                     u16 address, u8* value);
+static int w9968cf_i2c_adap_read_byte_data(struct w9968cf_device*, u16 address,
+                                          u8 subaddress, u8* value);
 static int w9968cf_i2c_adap_write_byte(struct w9968cf_device*,
-                                       u16 address, u8 subaddress);
+                                      u16 address, u8 subaddress);
 static int w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device*,
-                                                u16 address, u8 subaddress,
-                                                u8 value);
+                                               u16 address, u8 subaddress,
+                                               u8 value);
 
 /* I2C interface to kernel */
 static int w9968cf_i2c_init(struct w9968cf_device*);
-static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr, 
-                                  unsigned short flags, char read_write, 
-                                  u8 command, int size, union i2c_smbus_data*);
+static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr,
+                                 unsigned short flags, char read_write,
+                                 u8 command, int size, union i2c_smbus_data*);
 static u32 w9968cf_i2c_func(struct i2c_adapter*);
 static int w9968cf_i2c_attach_inform(struct i2c_client*);
 static int w9968cf_i2c_detach_inform(struct i2c_client*);
 static int w9968cf_i2c_control(struct i2c_adapter*, unsigned int cmd,
-                               unsigned long arg);
+                              unsigned long arg);
 
 /* Memory management */
 static void* rvmalloc(unsigned long size);
@@ -451,17 +458,17 @@ static int  w9968cf_allocate_memory(struct w9968cf_device*);
 static int w9968cf_sensor_set_control(struct w9968cf_device*,int cid,int val);
 static int w9968cf_sensor_get_control(struct w9968cf_device*,int cid,int *val);
 static int w9968cf_sensor_cmd(struct w9968cf_device*,
-                              unsigned int cmd, void *arg);
+                             unsigned int cmd, void *arg);
 static int w9968cf_sensor_init(struct w9968cf_device*);
 static int w9968cf_sensor_update_settings(struct w9968cf_device*);
 static int w9968cf_sensor_get_picture(struct w9968cf_device*);
-static int w9968cf_sensor_update_picture(struct w9968cf_device*, 
-                                         struct video_picture pict);
+static int w9968cf_sensor_update_picture(struct w9968cf_device*,
+                                        struct video_picture pict);
 
 /* Other helper functions */
 static void w9968cf_configure_camera(struct w9968cf_device*,struct usb_device*,
-                                     enum w9968cf_model_id, 
-                                     const unsigned short dev_nr);
+                                    enum w9968cf_model_id,
+                                    const unsigned short dev_nr);
 static void w9968cf_adjust_configuration(struct w9968cf_device*);
 static int w9968cf_turn_on_led(struct w9968cf_device*);
 static int w9968cf_init_chip(struct w9968cf_device*);
@@ -470,8 +477,8 @@ static inline u16 w9968cf_valid_depth(u16 palette);
 static inline u8 w9968cf_need_decompression(u16 palette);
 static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture);
 static int w9968cf_set_window(struct w9968cf_device*, struct video_window);
-static int w9968cf_postprocess_frame(struct w9968cf_device*, 
-                                     struct w9968cf_frame_t*);
+static int w9968cf_postprocess_frame(struct w9968cf_device*,
+                                    struct w9968cf_frame_t*);
 static int w9968cf_adjust_window_size(struct w9968cf_device*, u16* w, u16* h);
 static void w9968cf_init_framelist(struct w9968cf_device*);
 static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num);
@@ -490,11 +497,11 @@ struct w9968cf_symbolic_list {
        const char *name;
 };
 
-/*-------------------------------------------------------------------------- 
+/*--------------------------------------------------------------------------
   Returns the name of the matching element in the symbolic_list array. The
   end of the list must be marked with an element that has a NULL name.
   --------------------------------------------------------------------------*/
-static inline const char * 
+static inline const char *
 symbolic(struct w9968cf_symbolic_list list[], const int num)
 {
        int i;
@@ -561,7 +568,7 @@ static struct w9968cf_symbolic_list v4l1_plist[] = {
 static struct w9968cf_symbolic_list decoder_errlist[] = {
        { W9968CF_DEC_ERR_CORRUPTED_DATA, "Corrupted data" },
        { W9968CF_DEC_ERR_BUF_OVERFLOW,   "Buffer overflow" },
-       { W9968CF_DEC_ERR_NO_SOI,         "SOI marker not found" },     
+       { W9968CF_DEC_ERR_NO_SOI,         "SOI marker not found" },
        { W9968CF_DEC_ERR_NO_SOF0,        "SOF0 marker not found" },
        { W9968CF_DEC_ERR_NO_SOS,         "SOS marker not found" },
        { W9968CF_DEC_ERR_NO_EOI,         "EOI marker not found" },
@@ -579,15 +586,14 @@ static struct w9968cf_symbolic_list urb_errlist[] = {
        { -EFBIG,     "Too much ISO frames requested" },
        { -ENOSR,     "Buffer error (overrun)" },
        { -EPIPE,     "Specified endpoint is stalled (device not responding)"},
-       { -EOVERFLOW, "Babble (bad cable?)" },
+       { -EOVERFLOW, "Babble (too much data)" },
        { -EPROTO,    "Bit-stuff error (bad cable?)" },
        { -EILSEQ,    "CRC/Timeout" },
-       { -ETIMEDOUT, "NAK (device does not respond)" },
+       { -ETIME,     "Device does not respond to token" },
+       { -ETIMEDOUT, "Device does not respond to command" },
        { -1, NULL }
 };
 
-
-
 /****************************************************************************
  * Memory management functions                                              *
  ****************************************************************************/
@@ -688,20 +694,19 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
        bpp = (w9968cf_vpp) ? 4 : 2;
        if (cam->upscaling)
                vpp_bufsize = max(W9968CF_MAX_WIDTH*W9968CF_MAX_HEIGHT*bpp,
-                                 cam->maxwidth*cam->maxheight*bpp);
+                                 cam->maxwidth*cam->maxheight*bpp);
        else
                vpp_bufsize = cam->maxwidth*cam->maxheight*bpp;
 
        /* Allocate memory for the isochronous transfer buffers */
        for (i = 0; i < W9968CF_URBS; i++) {
                if (!(cam->transfer_buffer[i] =
-                     kmalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) {
+                     kzalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) {
                        DBG(1, "Couldn't allocate memory for the isochronous "
-                              "transfer buffers (%u bytes)", 
+                              "transfer buffers (%u bytes)",
                            p_size * W9968CF_ISO_PACKETS)
                        return -ENOMEM;
                }
-               memset(cam->transfer_buffer[i], 0, W9968CF_ISO_PACKETS*p_size);
        }
 
        /* Allocate memory for the temporary frame buffer */
@@ -774,9 +779,9 @@ static int w9968cf_allocate_memory(struct w9968cf_device* cam)
   of the next video frame; if an error is encountered in a packet, the entire
   video frame is discarded and grabbed again.
   If there are no requested frames in the FIFO list, packets are collected into
-  a temporary buffer. 
+  a temporary buffer.
   --------------------------------------------------------------------------*/
-static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
+static void w9968cf_urb_complete(struct urb *urb)
 {
        struct w9968cf_device* cam = (struct w9968cf_device*)urb->context;
        struct w9968cf_frame_t** f;
@@ -793,7 +798,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
        /* "(*f)" will be used instead of "cam->frame_current" */
        f = &cam->frame_current;
 
-       /* If a frame has been requested and we are grabbing into  
+       /* If a frame has been requested and we are grabbing into
           the temporary frame, we'll switch to that requested frame */
        if ((*f) == &cam->frame_tmp && *cam->requested_frame) {
                if (cam->frame_tmp.status == F_GRABBING) {
@@ -802,7 +807,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
                        (*f)->length = cam->frame_tmp.length;
                        memcpy((*f)->buffer, cam->frame_tmp.buffer,
                               (*f)->length);
-                       DBG(6, "Switched from temp. frame to frame #%d", 
+                       DBG(6, "Switched from temp. frame to frame #%d",
                            (*f)->number)
                }
        }
@@ -844,7 +849,7 @@ static void w9968cf_urb_complete(struct urb *urb, struct pt_regs *regs)
 
                        if (cam->vpp_flag & VPP_DECOMPRESSION) {
                                err = w9968cf_vpp->check_headers((*f)->buffer,
-                                                                (*f)->length);
+                                                                (*f)->length);
                                if (err) {
                                        DBG(4, "Skip corrupted frame: %s",
                                            symbolic(decoder_errlist, err))
@@ -969,7 +974,7 @@ static int w9968cf_start_transfer(struct w9968cf_device* cam)
        cam->frame_current = &cam->frame_tmp;
 
        if (!(cam->vpp_flag & VPP_DECOMPRESSION))
-               DBG(5, "Isochronous transfer size: %lu bytes/frame", 
+               DBG(5, "Isochronous transfer size: %lu bytes/frame",
                    (unsigned long)t_size*2)
 
        DBG(5, "Starting the isochronous transfer...")
@@ -986,7 +991,7 @@ static int w9968cf_start_transfer(struct w9968cf_device* cam)
                                usb_free_urb(cam->urb[j]);
                        }
                        DBG(1, "Couldn't send a transfer request to the "
-                              "USB core (error #%d, %s)", err, 
+                              "USB core (error #%d, %s)", err,
                            symbolic(urb_errlist, err))
                        return err;
                }
@@ -1010,7 +1015,7 @@ static int w9968cf_stop_transfer(struct w9968cf_device* cam)
        if (!cam->streaming)
                return 0;
 
-       /* This avoids race conditions with usb_submit_urb() 
+       /* This avoids race conditions with usb_submit_urb()
           in the URB completition handler */
        spin_lock_irqsave(&cam->urb_lock, lock_flags);
        cam->streaming = 0;
@@ -1044,7 +1049,7 @@ exit:
 
 
 /*--------------------------------------------------------------------------
-  Write a W9968CF register. 
+  Write a W9968CF register.
   Return 0 on success, -1 otherwise.
   --------------------------------------------------------------------------*/
 static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
@@ -1053,8 +1058,8 @@ static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
        int res;
 
        res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
-                             USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
-                             value, index, NULL, 0, W9968CF_USB_CTRL_TIMEOUT);
+                             USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
+                             value, index, NULL, 0, W9968CF_USB_CTRL_TIMEOUT);
 
        if (res < 0)
                DBG(4, "Failed to write a register "
@@ -1066,7 +1071,7 @@ static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
 
 
 /*--------------------------------------------------------------------------
-  Read a W9968CF register. 
+  Read a W9968CF register.
   Return the register value on success, -1 otherwise.
   --------------------------------------------------------------------------*/
 static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index)
@@ -1076,8 +1081,8 @@ static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index)
        int res;
 
        res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 1,
-                             USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-                             0, index, buff, 2, W9968CF_USB_CTRL_TIMEOUT);
+                             USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                             0, index, buff, 2, W9968CF_USB_CTRL_TIMEOUT);
 
        if (res < 0)
                DBG(4, "Failed to read a register "
@@ -1101,8 +1106,8 @@ static int w9968cf_write_fsb(struct w9968cf_device* cam, u16* data)
        value = *data++;
 
        res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
-                             USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
-                             value, 0x06, data, 6, W9968CF_USB_CTRL_TIMEOUT);
+                             USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
+                             value, 0x06, data, 6, W9968CF_USB_CTRL_TIMEOUT);
 
        if (res < 0)
                DBG(4, "Failed to write the FSB registers "
@@ -1281,9 +1286,9 @@ static int w9968cf_smbus_refresh_bus(struct w9968cf_device* cam)
 
 
 /* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */
-static int 
-w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam, 
-                                     u16 address, u8 subaddress,u8 value)
+static int
+w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
+                                    u16 address, u8 subaddress,u8 value)
 {
        u16* data = cam->data_buffer;
        int err = 0;
@@ -1342,7 +1347,7 @@ w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
                       "value 0x%02X", address, subaddress, value)
        else
                DBG(5, "I2C write byte data failed, addr.0x%04X, "
-                      "subaddr.0x%02X, value 0x%02X", 
+                      "subaddr.0x%02X, value 0x%02X",
                    address, subaddress, value)
 
        return err;
@@ -1350,10 +1355,10 @@ w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
 
 
 /* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */
-static int 
-w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam, 
-                                u16 address, u8 subaddress, 
-                                u8* value)
+static int
+w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
+                               u16 address, u8 subaddress,
+                               u8* value)
 {
        int err = 0;
 
@@ -1378,7 +1383,7 @@ w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
 
        if (!err)
                DBG(5, "I2C read byte data done, addr.0x%04X, "
-                      "subaddr.0x%02X, value 0x%02X", 
+                      "subaddr.0x%02X, value 0x%02X",
                    address, subaddress, *value)
        else
                DBG(5, "I2C read byte data failed, addr.0x%04X, "
@@ -1390,9 +1395,9 @@ w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
 
 
 /* SMBus protocol: S Addr+1 Rd [A] [Value] NA P */
-static int 
+static int
 w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
-                           u16 address, u8* value)
+                          u16 address, u8* value)
 {
        int err = 0;
 
@@ -1405,7 +1410,7 @@ w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
        err += w9968cf_smbus_read_byte(cam, value);
        err += w9968cf_smbus_write_ack(cam);
        err += w9968cf_smbus_stop(cam);
+
        /* Serial data disable */
        err += w9968cf_write_sb(cam, 0x0000);
 
@@ -1421,9 +1426,9 @@ w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
 
 
 /* SMBus protocol: S Addr Wr [A] Value [A] P */
-static int 
+static int
 w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam,
-                            u16 address, u8 value)
+                           u16 address, u8 value)
 {
        DBG(4, "i2c_write_byte() is an unsupported transfer mode")
        return -EINVAL;
@@ -1436,13 +1441,13 @@ w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam,
  ****************************************************************************/
 
 static int
-w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, 
-                       unsigned short flags, char read_write, u8 command,
-                       int size, union i2c_smbus_data *data)
+w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
+                      unsigned short flags, char read_write, u8 command,
+                      int size, union i2c_smbus_data *data)
 {
        struct w9968cf_device* cam = i2c_get_adapdata(adapter);
        u8 i;
-       int err = 0; 
+       int err = 0;
 
        switch (addr) {
                case OV6xx0_SID:
@@ -1458,20 +1463,20 @@ w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
                addr <<= 1;
 
                if (read_write == I2C_SMBUS_WRITE)
-                       err = w9968cf_i2c_adap_write_byte(cam, addr, command);
-               else if (read_write == I2C_SMBUS_READ) 
+                       err = w9968cf_i2c_adap_write_byte(cam, addr, command);
+               else if (read_write == I2C_SMBUS_READ)
                        err = w9968cf_i2c_adap_read_byte(cam,addr,&data->byte);
 
        } else if (size == I2C_SMBUS_BYTE_DATA) {
                addr <<= 1;
 
                if (read_write == I2C_SMBUS_WRITE)
-                       err = w9968cf_i2c_adap_fastwrite_byte_data(cam, addr,
-                                                         command, data->byte);
+                       err = w9968cf_i2c_adap_fastwrite_byte_data(cam, addr,
+                                                         command, data->byte);
                else if (read_write == I2C_SMBUS_READ) {
                        for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) {
                                err = w9968cf_i2c_adap_read_byte_data(cam,addr,
-                                                        command, &data->byte);
+                                                        command, &data->byte);
                                if (err) {
                                        if (w9968cf_smbus_refresh_bus(cam)) {
                                                err = -EIO;
@@ -1514,7 +1519,7 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client)
                        return err;
                }
        } else {
-               DBG(4, "Rejected client [%s] with driver [%s]", 
+               DBG(4, "Rejected client [%s] with driver [%s]",
                    client->name, client->driver->driver.name)
                return -EINVAL;
        }
@@ -1539,9 +1544,9 @@ static int w9968cf_i2c_detach_inform(struct i2c_client* client)
 }
 
 
-static int 
+static int
 w9968cf_i2c_control(struct i2c_adapter* adapter, unsigned int cmd,
-                    unsigned long arg)
+                   unsigned long arg)
 {
        return 0;
 }
@@ -1619,12 +1624,12 @@ static int w9968cf_turn_on_led(struct w9968cf_device* cam)
 static int w9968cf_init_chip(struct w9968cf_device* cam)
 {
        unsigned long hw_bufsize = cam->maxwidth*cam->maxheight*2,
-                     y0 = 0x0000,
-                     u0 = y0 + hw_bufsize/2,
-                     v0 = u0 + hw_bufsize/4,
-                     y1 = v0 + hw_bufsize/4,
-                     u1 = y1 + hw_bufsize/2,
-                     v1 = u1 + hw_bufsize/4;
+                     y0 = 0x0000,
+                     u0 = y0 + hw_bufsize/2,
+                     v0 = u0 + hw_bufsize/4,
+                     y1 = v0 + hw_bufsize/4,
+                     u1 = y1 + hw_bufsize/2,
+                     v1 = u1 + hw_bufsize/4;
        int err = 0;
 
        err += w9968cf_write_reg(cam, 0xff00, 0x00); /* power off */
@@ -1756,7 +1761,7 @@ w9968cf_set_picture(struct w9968cf_device* cam, struct video_picture pict)
                        cam->vpp_flag = VPP_SWAP_YUV_BYTES;
                        hw_palette = VIDEO_PALETTE_UYVY;
                        break;
-               /* Original video is used instead of RGBX palettes. 
+               /* Original video is used instead of RGBX palettes.
                   Software conversion later. */
                case VIDEO_PALETTE_GREY:
                case VIDEO_PALETTE_RGB555:
@@ -1771,7 +1776,7 @@ w9968cf_set_picture(struct w9968cf_device* cam, struct video_picture pict)
        }
 
        /* NOTE: due to memory issues, it is better to disable the hardware
-                double buffering during compression */
+                double buffering during compression */
        if (cam->double_buffer && !(cam->vpp_flag & VPP_DECOMPRESSION))
                reg_v |= 0x0080;
 
@@ -1822,24 +1827,24 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
        int err = 0;
 
        /* Work around to avoid FP arithmetics */
-       #define __SC(x) ((x) << 10)
-       #define __UNSC(x) ((x) >> 10)
+       #define SC(x) ((x) << 10)
+       #define UNSC(x) ((x) >> 10)
 
        /* Make sure we are using a supported resolution */
-       if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, 
-                                             (u16*)&win.height)))
+       if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
+                                             (u16*)&win.height)))
                goto error;
 
        /* Scaling factors */
-       fw = __SC(win.width) / cam->maxwidth;
-       fh = __SC(win.height) / cam->maxheight;
+       fw = SC(win.width) / cam->maxwidth;
+       fh = SC(win.height) / cam->maxheight;
 
        /* Set up the width and height values used by the chip */
        if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) {
                cam->vpp_flag |= VPP_UPSCALE;
                /* Calculate largest w,h mantaining the same w/h ratio */
-               w = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh;
-               h = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight;
+               w = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
+               h = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
                if (w < cam->minwidth) /* just in case */
                        w = cam->minwidth;
                if (h < cam->minheight) /* just in case */
@@ -1856,8 +1861,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
 
        /* Calculate cropped area manteining the right w/h ratio */
        if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) {
-               cw = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh;
-               ch = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight;
+               cw = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
+               ch = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
        } else {
                cw = w;
                ch = h;
@@ -1896,8 +1901,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
        /* We have to scale win.x and win.y offsets */
        if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
             || (cam->vpp_flag & VPP_UPSCALE) ) {
-               ax = __SC(win.x)/fw;
-               ay = __SC(win.y)/fh;
+               ax = SC(win.x)/fw;
+               ay = SC(win.y)/fh;
        } else {
                ax = win.x;
                ay = win.y;
@@ -1912,8 +1917,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
        /* Adjust win.x, win.y */
        if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
             || (cam->vpp_flag & VPP_UPSCALE) ) {
-               win.x = __UNSC(ax*fw);
-               win.y = __UNSC(ay*fh);
+               win.x = UNSC(ax*fw);
+               win.y = UNSC(ay*fh);
        } else {
                win.x = ax;
                win.y = ay;
@@ -1956,7 +1961,7 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
        /* Settings changed, so we clear the frame buffers */
        memset(cam->frame[0].buffer, 0, cam->nbuffers*cam->frame[0].size);
 
-       DBG(4, "The capture area is %dx%d, Offset (x,y)=(%u,%u)", 
+       DBG(4, "The capture area is %dx%d, Offset (x,y)=(%u,%u)",
            win.width, win.height, win.x, win.y)
 
        PDBGG("x=%u ,y=%u, w=%u, h=%u, ax=%u, ay=%u, s_win.x=%u, s_win.y=%u, "
@@ -1972,11 +1977,11 @@ error:
 }
 
 
-/*-------------------------------------------------------------------------- 
+/*--------------------------------------------------------------------------
   Adjust the asked values for window width and height.
   Return 0 on success, -1 otherwise.
   --------------------------------------------------------------------------*/
-static int 
+static int
 w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height)
 {
        u16 maxw, maxh;
@@ -1986,10 +1991,10 @@ w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height)
 
        maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
               w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
-                          : cam->maxwidth;
+                          : cam->maxwidth;
        maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
               w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
-                          : cam->maxheight;
+                          : cam->maxheight;
 
        if (*width > maxw)
                *width = maxw;
@@ -2048,7 +2053,7 @@ static void w9968cf_push_frame(struct w9968cf_device* cam, u8 f_num)
   Read, store and remove the first pointer in the FIFO list of requested
   frames. This function is called in interrupt context.
   --------------------------------------------------------------------------*/
-static void 
+static void
 w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep)
 {
        u8 i;
@@ -2072,9 +2077,9 @@ w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep)
   High-level video post-processing routine on grabbed frames.
   Return 0 on success, a negative number otherwise.
   --------------------------------------------------------------------------*/
-static int 
-w9968cf_postprocess_frame(struct w9968cf_device* cam, 
-                          struct w9968cf_frame_t* fr)
+static int
+w9968cf_postprocess_frame(struct w9968cf_device* cam,
+                         struct w9968cf_frame_t* fr)
 {
        void *pIn = fr->buffer, *pOut = cam->frame_vpp.buffer, *tmp;
        u16 w = cam->window.width,
@@ -2121,7 +2126,7 @@ w9968cf_postprocess_frame(struct w9968cf_device* cam,
                w9968cf_vpp->uyvy_to_rgbx(pIn, fr->length, pOut, fmt, rgb);
                fr->length = (w*h*d)/8;
                _PSWAP(pIn, pOut)
-               DBG(6, "UYVY-16bit to %s conversion done", 
+               DBG(6, "UYVY-16bit to %s conversion done",
                    symbolic(v4l1_plist, fmt))
        }
 
@@ -2137,7 +2142,7 @@ w9968cf_postprocess_frame(struct w9968cf_device* cam,
  * Image sensor control routines                                            *
  ****************************************************************************/
 
-static int 
+static int
 w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val)
 {
        struct ovcamchip_control ctl;
@@ -2152,7 +2157,7 @@ w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val)
 }
 
 
-static int 
+static int
 w9968cf_sensor_get_control(struct w9968cf_device* cam, int cid, int* val)
 {
        struct ovcamchip_control ctl;
@@ -2192,38 +2197,38 @@ static int w9968cf_sensor_update_settings(struct w9968cf_device* cam)
        int err = 0;
 
        /* Auto brightness */
-       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOBRIGHT, 
-                                        cam->auto_brt);
+       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOBRIGHT,
+                                        cam->auto_brt);
        if (err)
                return err;
 
        /* Auto exposure */
-       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOEXP, 
-                                        cam->auto_exp);
+       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOEXP,
+                                        cam->auto_exp);
        if (err)
                return err;
 
        /* Banding filter */
-       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BANDFILT, 
-                                        cam->bandfilt);
+       err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BANDFILT,
+                                        cam->bandfilt);
        if (err)
                return err;
 
        /* Light frequency */
        err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_FREQ,
-                                        cam->lightfreq);
+                                        cam->lightfreq);
        if (err)
                return err;
 
        /* Back light */
        err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BACKLIGHT,
-                                        cam->backlight);
+                                        cam->backlight);
        if (err)
                return err;
 
        /* Mirror */
        err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_MIRROR,
-                                        cam->mirror);
+                                        cam->mirror);
        if (err)
                return err;
 
@@ -2275,15 +2280,15 @@ static int w9968cf_sensor_get_picture(struct w9968cf_device* cam)
   Returns: 0 on success, a negative number otherwise.
   --------------------------------------------------------------------------*/
 static int
-w9968cf_sensor_update_picture(struct w9968cf_device* cam, 
-                              struct video_picture pict)
+w9968cf_sensor_update_picture(struct w9968cf_device* cam,
+                             struct video_picture pict)
 {
        int err = 0;
 
        if ((!cam->sensor_initialized)
            || pict.contrast != cam->picture.contrast) {
                err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_CONT,
-                                                pict.contrast);
+                                                pict.contrast);
                if (err)
                        goto fail;
                DBG(4, "Contrast changed from %u to %u",
@@ -2291,10 +2296,10 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
                cam->picture.contrast = pict.contrast;
        }
 
-       if (((!cam->sensor_initialized) || 
+       if (((!cam->sensor_initialized) ||
            pict.brightness != cam->picture.brightness) && (!cam->auto_brt)) {
-               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BRIGHT, 
-                                                pict.brightness);
+               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BRIGHT,
+                                                pict.brightness);
                if (err)
                        goto fail;
                DBG(4, "Brightness changed from %u to %u",
@@ -2303,8 +2308,8 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
        }
 
        if ((!cam->sensor_initialized) || pict.colour != cam->picture.colour) {
-               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_SAT, 
-                                                pict.colour);
+               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_SAT,
+                                                pict.colour);
                if (err)
                        goto fail;
                DBG(4, "Colour changed from %u to %u",
@@ -2313,8 +2318,8 @@ w9968cf_sensor_update_picture(struct w9968cf_device* cam,
        }
 
        if ((!cam->sensor_initialized) || pict.hue != cam->picture.hue) {
-               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_HUE, 
-                                                pict.hue);
+               err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_HUE,
+                                                pict.hue);
                if (err)
                        goto fail;
                DBG(4, "Hue changed from %u to %u",
@@ -2343,12 +2348,12 @@ static int w9968cf_sensor_init(struct w9968cf_device* cam)
 {
        int err = 0;
 
-       if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_INITIALIZE, 
-                                     &cam->monochrome)))
+       if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_INITIALIZE,
+                                     &cam->monochrome)))
                goto error;
 
-       if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_Q_SUBTYPE, 
-                                     &cam->sensor)))
+       if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_Q_SUBTYPE,
+                                     &cam->sensor)))
                goto error;
 
        /* NOTE: Make sure width and height are a multiple of 16 */
@@ -2410,16 +2415,16 @@ error:
 
 /*--------------------------------------------------------------------------
   Fill some basic fields in the main device data structure.
-  This function is called once on w9968cf_usb_probe() for each recognized 
+  This function is called once on w9968cf_usb_probe() for each recognized
   camera.
   --------------------------------------------------------------------------*/
 static void
 w9968cf_configure_camera(struct w9968cf_device* cam,
-                         struct usb_device* udev,
-                         enum w9968cf_model_id mod_id,
-                         const unsigned short dev_nr)
+                        struct usb_device* udev,
+                        enum w9968cf_model_id mod_id,
+                        const unsigned short dev_nr)
 {
-       init_MUTEX(&cam->fileop_sem);
+       mutex_init(&cam->fileop_mutex);
        init_waitqueue_head(&cam->open);
        spin_lock_init(&cam->urb_lock);
        spin_lock_init(&cam->flist_lock);
@@ -2438,60 +2443,60 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
             packet_size[dev_nr] < wMaxPacketSize[cam->altsetting-1];
             cam->altsetting++);
 
-       cam->max_buffers = (max_buffers[dev_nr] < 2 || 
-                           max_buffers[dev_nr] > W9968CF_MAX_BUFFERS)
-                          ? W9968CF_BUFFERS : (u8)max_buffers[dev_nr];
+       cam->max_buffers = (max_buffers[dev_nr] < 2 ||
+                           max_buffers[dev_nr] > W9968CF_MAX_BUFFERS)
+                          ? W9968CF_BUFFERS : (u8)max_buffers[dev_nr];
 
-       cam->double_buffer = (double_buffer[dev_nr] == 0 || 
-                             double_buffer[dev_nr] == 1)
-                            ? (u8)double_buffer[dev_nr]:W9968CF_DOUBLE_BUFFER;
+       cam->double_buffer = (double_buffer[dev_nr] == 0 ||
+                             double_buffer[dev_nr] == 1)
+                            ? (u8)double_buffer[dev_nr]:W9968CF_DOUBLE_BUFFER;
 
        cam->clamping = (clamping[dev_nr] == 0 || clamping[dev_nr] == 1)
-                       ? (u8)clamping[dev_nr] : W9968CF_CLAMPING;
-       
+                       ? (u8)clamping[dev_nr] : W9968CF_CLAMPING;
+
        cam->filter_type = (filter_type[dev_nr] == 0 ||
-                           filter_type[dev_nr] == 1 ||
-                           filter_type[dev_nr] == 2)
-                          ? (u8)filter_type[dev_nr] : W9968CF_FILTER_TYPE;
+                           filter_type[dev_nr] == 1 ||
+                           filter_type[dev_nr] == 2)
+                          ? (u8)filter_type[dev_nr] : W9968CF_FILTER_TYPE;
 
        cam->capture = 1;
 
        cam->largeview = (largeview[dev_nr] == 0 || largeview[dev_nr] == 1)
-                        ? (u8)largeview[dev_nr] : W9968CF_LARGEVIEW;
+                        ? (u8)largeview[dev_nr] : W9968CF_LARGEVIEW;
 
-       cam->decompression = (decompression[dev_nr] == 0 || 
-                             decompression[dev_nr] == 1 ||
-                             decompression[dev_nr] == 2)
-                            ? (u8)decompression[dev_nr]:W9968CF_DECOMPRESSION;
+       cam->decompression = (decompression[dev_nr] == 0 ||
+                             decompression[dev_nr] == 1 ||
+                             decompression[dev_nr] == 2)
+                            ? (u8)decompression[dev_nr]:W9968CF_DECOMPRESSION;
 
-       cam->upscaling = (upscaling[dev_nr] == 0 || 
-                         upscaling[dev_nr] == 1)
-                        ? (u8)upscaling[dev_nr] : W9968CF_UPSCALING;
+       cam->upscaling = (upscaling[dev_nr] == 0 ||
+                         upscaling[dev_nr] == 1)
+                        ? (u8)upscaling[dev_nr] : W9968CF_UPSCALING;
 
        cam->auto_brt = (autobright[dev_nr] == 0 || autobright[dev_nr] == 1)
-                       ? (u8)autobright[dev_nr] : W9968CF_AUTOBRIGHT;
+                       ? (u8)autobright[dev_nr] : W9968CF_AUTOBRIGHT;
 
        cam->auto_exp = (autoexp[dev_nr] == 0 || autoexp[dev_nr] == 1)
-                       ? (u8)autoexp[dev_nr] : W9968CF_AUTOEXP;
+                       ? (u8)autoexp[dev_nr] : W9968CF_AUTOEXP;
 
        cam->lightfreq = (lightfreq[dev_nr] == 50 || lightfreq[dev_nr] == 60)
-                        ? (u8)lightfreq[dev_nr] : W9968CF_LIGHTFREQ;
+                        ? (u8)lightfreq[dev_nr] : W9968CF_LIGHTFREQ;
 
-       cam->bandfilt = (bandingfilter[dev_nr] == 0 || 
-                        bandingfilter[dev_nr] == 1)
-                       ? (u8)bandingfilter[dev_nr] : W9968CF_BANDINGFILTER;
+       cam->bandfilt = (bandingfilter[dev_nr] == 0 ||
+                        bandingfilter[dev_nr] == 1)
+                       ? (u8)bandingfilter[dev_nr] : W9968CF_BANDINGFILTER;
 
        cam->backlight = (backlight[dev_nr] == 0 || backlight[dev_nr] == 1)
-                        ? (u8)backlight[dev_nr] : W9968CF_BACKLIGHT;
+                        ? (u8)backlight[dev_nr] : W9968CF_BACKLIGHT;
 
        cam->clockdiv = (clockdiv[dev_nr] == -1 || clockdiv[dev_nr] >= 0)
-                       ? (s8)clockdiv[dev_nr] : W9968CF_CLOCKDIV;
+                       ? (s8)clockdiv[dev_nr] : W9968CF_CLOCKDIV;
 
        cam->mirror = (mirror[dev_nr] == 0 || mirror[dev_nr] == 1)
-                     ? (u8)mirror[dev_nr] : W9968CF_MIRROR;
+                     ? (u8)mirror[dev_nr] : W9968CF_MIRROR;
 
        cam->monochrome = (monochrome[dev_nr] == 0 || monochrome[dev_nr] == 1)
-                         ? monochrome[dev_nr] : W9968CF_MONOCHROME;
+                         ? monochrome[dev_nr] : W9968CF_MONOCHROME;
 
        cam->picture.brightness = (u16)brightness[dev_nr];
        cam->picture.hue = (u16)hue[dev_nr];
@@ -2513,7 +2518,7 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
        cam->picture.depth = w9968cf_valid_depth(cam->picture.palette);
 
        cam->force_rgb = (force_rgb[dev_nr] == 0 || force_rgb[dev_nr] == 1)
-                        ? (u8)force_rgb[dev_nr] : W9968CF_FORCE_RGB;
+                        ? (u8)force_rgb[dev_nr] : W9968CF_FORCE_RGB;
 
        cam->window.x = 0;
        cam->window.y = 0;
@@ -2525,16 +2530,16 @@ w9968cf_configure_camera(struct w9968cf_device* cam,
 
        DBG(3, "%s configured with settings #%u:",
            symbolic(camlist, cam->id), dev_nr)
-       
+
        DBG(3, "- Data packet size for USB isochrnous transfer: %u bytes",
            wMaxPacketSize[cam->altsetting-1])
-       
+
        DBG(3, "- Number of requested video frame buffers: %u",
            cam->max_buffers)
 
        if (cam->double_buffer)
                DBG(3, "- Hardware double buffering enabled")
-       else 
+       else
                DBG(3, "- Hardware double buffering disabled")
 
        if (cam->filter_type == 0)
@@ -2642,12 +2647,12 @@ static void w9968cf_adjust_configuration(struct w9968cf_device* cam)
 
 /*--------------------------------------------------------------------------
   Release the resources used by the driver.
-  This function is called on disconnect 
+  This function is called on disconnect
   (or on close if deallocation has been deferred)
   --------------------------------------------------------------------------*/
 static void w9968cf_release_resources(struct w9968cf_device* cam)
 {
-       down(&w9968cf_devlist_sem);
+       mutex_lock(&w9968cf_devlist_mutex);
 
        DBG(2, "V4L device deregistered: /dev/video%d", cam->v4ldev->minor)
 
@@ -2658,7 +2663,7 @@ static void w9968cf_release_resources(struct w9968cf_device* cam)
        kfree(cam->control_buffer);
        kfree(cam->data_buffer);
 
-       up(&w9968cf_devlist_sem);
+       mutex_unlock(&w9968cf_devlist_mutex);
 }
 
 
@@ -2678,14 +2683,14 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
 
        cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
 
-       down(&cam->dev_sem);
+       mutex_lock(&cam->dev_mutex);
 
        if (cam->sensor == CC_UNKNOWN) {
                DBG(2, "No supported image sensor has been detected by the "
                       "'ovcamchip' module for the %s (/dev/video%d). Make "
                       "sure it is loaded *before* (re)connecting the camera.",
                    symbolic(camlist, cam->id), cam->v4ldev->minor)
-               up(&cam->dev_sem);
+               mutex_unlock(&cam->dev_mutex);
                up_read(&w9968cf_disconnect);
                return -ENODEV;
        }
@@ -2694,14 +2699,14 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
                DBG(2, "%s (/dev/video%d) has been already occupied by '%s'",
                    symbolic(camlist, cam->id),cam->v4ldev->minor,cam->command)
                if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) {
-                       up(&cam->dev_sem);
+                       mutex_unlock(&cam->dev_mutex);
                        up_read(&w9968cf_disconnect);
                        return -EWOULDBLOCK;
                }
-               up(&cam->dev_sem);
+               mutex_unlock(&cam->dev_mutex);
                err = wait_event_interruptible_exclusive(cam->open,
-                                                        cam->disconnected ||
-                                                        !cam->users);
+                                                        cam->disconnected ||
+                                                        !cam->users);
                if (err) {
                        up_read(&w9968cf_disconnect);
                        return err;
@@ -2710,7 +2715,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
                        up_read(&w9968cf_disconnect);
                        return -ENODEV;
                }
-               down(&cam->dev_sem);
+               mutex_lock(&cam->dev_mutex);
        }
 
        DBG(5, "Opening '%s', /dev/video%d ...",
@@ -2739,7 +2744,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
 
        DBG(5, "Video device is open")
 
-       up(&cam->dev_sem);
+       mutex_unlock(&cam->dev_mutex);
        up_read(&w9968cf_disconnect);
 
        return 0;
@@ -2747,7 +2752,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
 deallocate_memory:
        w9968cf_deallocate_memory(cam);
        DBG(2, "Failed to open the video device")
-       up(&cam->dev_sem);
+       mutex_unlock(&cam->dev_mutex);
        up_read(&w9968cf_disconnect);
        return err;
 }
@@ -2759,13 +2764,13 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
 
        cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
 
-       down(&cam->dev_sem); /* prevent disconnect() to be called */
+       mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
 
        w9968cf_stop_transfer(cam);
 
        if (cam->disconnected) {
                w9968cf_release_resources(cam);
-               up(&cam->dev_sem);
+               mutex_unlock(&cam->dev_mutex);
                kfree(cam);
                return 0;
        }
@@ -2775,7 +2780,7 @@ static int w9968cf_release(struct inode* inode, struct file* filp)
        wake_up_interruptible_nr(&cam->open, 1);
 
        DBG(5, "Video device closed")
-       up(&cam->dev_sem);
+       mutex_unlock(&cam->dev_mutex);
        return 0;
 }
 
@@ -2792,18 +2797,18 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
        if (filp->f_flags & O_NONBLOCK)
                return -EWOULDBLOCK;
 
-       if (down_interruptible(&cam->fileop_sem))
+       if (mutex_lock_interruptible(&cam->fileop_mutex))
                return -ERESTARTSYS;
 
        if (cam->disconnected) {
                DBG(2, "Device not present")
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -ENODEV;
        }
 
        if (cam->misconfigured) {
                DBG(2, "The camera is misconfigured. Close and open it again.")
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -EIO;
        }
 
@@ -2814,15 +2819,15 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
                w9968cf_push_frame(cam, 1);
 
        err = wait_event_interruptible(cam->wait_queue,
-                                      cam->frame[0].status == F_READY ||
-                                      cam->frame[1].status == F_READY ||
-                                      cam->disconnected);
+                                      cam->frame[0].status == F_READY ||
+                                      cam->frame[1].status == F_READY ||
+                                      cam->disconnected);
        if (err) {
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return err;
        }
        if (cam->disconnected) {
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -ENODEV;
        }
 
@@ -2836,7 +2841,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
 
        if (copy_to_user(buf, fr->buffer, count)) {
                fr->status = F_UNUSED;
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -EFAULT;
        }
        *f_pos += count;
@@ -2845,7 +2850,7 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
 
        DBG(5, "%zu bytes read", count)
 
-       up(&cam->fileop_sem);
+       mutex_unlock(&cam->fileop_mutex);
        return count;
 }
 
@@ -2853,12 +2858,12 @@ w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
 static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
 {
        struct w9968cf_device* cam = (struct w9968cf_device*)
-                                    video_get_drvdata(video_devdata(filp));
+                                    video_get_drvdata(video_devdata(filp));
        unsigned long vsize = vma->vm_end - vma->vm_start,
-                     psize = cam->nbuffers * cam->frame[0].size,
-                     start = vma->vm_start,
-                     pos = (unsigned long)cam->frame[0].buffer,
-                     page;
+                     psize = cam->nbuffers * cam->frame[0].size,
+                     start = vma->vm_start,
+                     pos = (unsigned long)cam->frame[0].buffer,
+                     page;
 
        if (cam->disconnected) {
                DBG(2, "Device not present")
@@ -2892,51 +2897,51 @@ static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
 
 static int
 w9968cf_ioctl(struct inode* inode, struct file* filp,
-              unsigned int cmd, unsigned long arg)
+             unsigned int cmd, unsigned long arg)
 {
        struct w9968cf_device* cam;
        int err;
 
        cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
 
-       if (down_interruptible(&cam->fileop_sem))
+       if (mutex_lock_interruptible(&cam->fileop_mutex))
                return -ERESTARTSYS;
 
        if (cam->disconnected) {
                DBG(2, "Device not present")
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -ENODEV;
        }
 
        if (cam->misconfigured) {
                DBG(2, "The camera is misconfigured. Close and open it again.")
-               up(&cam->fileop_sem);
+               mutex_unlock(&cam->fileop_mutex);
                return -EIO;
        }
 
        err = w9968cf_v4l_ioctl(inode, filp, cmd, (void __user *)arg);
 
-       up(&cam->fileop_sem);
+       mutex_unlock(&cam->fileop_mutex);
        return err;
 }
 
 
 static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
-                             unsigned int cmd, void __user * arg)
+                            unsigned int cmd, void __user * arg)
 {
        struct w9968cf_device* cam;
        const char* v4l1_ioctls[] = {
-               "?", "CGAP", "GCHAN", "SCHAN", "GTUNER", "STUNER", 
+               "?", "CGAP", "GCHAN", "SCHAN", "GTUNER", "STUNER",
                "GPICT", "SPICT", "CCAPTURE", "GWIN", "SWIN", "GFBUF",
                "SFBUF", "KEY", "GFREQ", "SFREQ", "GAUDIO", "SAUDIO",
                "SYNC", "MCAPTURE", "GMBUF", "GUNIT", "GCAPTURE", "SCAPTURE",
-               "SPLAYMODE", "SWRITEMODE", "GPLAYINFO", "SMICROCODE", 
-               "GVBIFMT", "SVBIFMT" 
+               "SPLAYMODE", "SWRITEMODE", "GPLAYINFO", "SMICROCODE",
+               "GVBIFMT", "SVBIFMT"
        };
 
        #define V4L1_IOCTL(cmd) \
-               ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \
-               v4l1_ioctls[_IOC_NR((cmd))] : "?")
+               ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \
+               v4l1_ioctls[_IOC_NR((cmd))] : "?")
 
        cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
 
@@ -2951,14 +2956,14 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                        .minwidth = cam->minwidth,
                        .minheight = cam->minheight,
                };
-               sprintf(cap.name, "W996[87]CF USB Camera #%d", 
-                       cam->v4ldev->minor);
+               sprintf(cap.name, "W996[87]CF USB Camera #%d",
+                       cam->v4ldev->minor);
                cap.maxwidth = (cam->upscaling && w9968cf_vpp)
-                              ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth) 
-                                : cam->maxwidth;
+                              ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
+                                : cam->maxwidth;
                cap.maxheight = (cam->upscaling && w9968cf_vpp)
-                               ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
-                                 : cam->maxheight;
+                               ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
+                                 : cam->maxheight;
 
                if (copy_to_user(arg, &cap, sizeof(cap)))
                        return -EFAULT;
@@ -3023,7 +3028,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                if (copy_from_user(&pict, arg, sizeof(pict)))
                        return -EFAULT;
 
-               if ( (cam->force_palette || !w9968cf_vpp) 
+               if ( (cam->force_palette || !w9968cf_vpp)
                     && pict.palette != cam->picture.palette ) {
                        DBG(4, "Palette %s rejected: only %s is allowed",
                            symbolic(v4l1_plist, pict.palette),
@@ -3040,24 +3045,24 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                if (!cam->force_palette) {
                   if (cam->decompression == 0) {
                      if (w9968cf_need_decompression(pict.palette)) {
-                        DBG(4, "Decompression disabled: palette %s is not "
-                               "allowed. VIDIOCSPICT failed",
-                            symbolic(v4l1_plist, pict.palette))
-                        return -EINVAL;
+                        DBG(4, "Decompression disabled: palette %s is not "
+                               "allowed. VIDIOCSPICT failed",
+                            symbolic(v4l1_plist, pict.palette))
+                        return -EINVAL;
                      }
                   } else if (cam->decompression == 1) {
                      if (!w9968cf_need_decompression(pict.palette)) {
-                        DBG(4, "Decompression forced: palette %s is not "
-                               "allowed. VIDIOCSPICT failed",
-                            symbolic(v4l1_plist, pict.palette))
-                        return -EINVAL;
+                        DBG(4, "Decompression forced: palette %s is not "
+                               "allowed. VIDIOCSPICT failed",
+                            symbolic(v4l1_plist, pict.palette))
+                        return -EINVAL;
                      }
                   }
                }
 
                if (pict.depth != w9968cf_valid_depth(pict.palette)) {
                        DBG(4, "Requested depth %u bpp is not valid for %s "
-                              "palette: ignored and changed to %u bpp", 
+                              "palette: ignored and changed to %u bpp",
                            pict.depth, symbolic(v4l1_plist, pict.palette),
                            w9968cf_valid_depth(pict.palette))
                        pict.depth = w9968cf_valid_depth(pict.palette);
@@ -3068,9 +3073,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                           || cam->frame_current->queued) {
                                err = wait_event_interruptible
                                      ( cam->wait_queue,
-                                       cam->disconnected ||
-                                       (!*cam->requested_frame &&
-                                        !cam->frame_current->queued) );
+                                       cam->disconnected ||
+                                       (!*cam->requested_frame &&
+                                        !cam->frame_current->queued) );
                                if (err)
                                        return err;
                                if (cam->disconnected)
@@ -3110,7 +3115,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                        return -EINVAL;
 
                if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
-                                                     (u16*)&win.height))) {
+                                                     (u16*)&win.height))) {
                        DBG(4, "Resolution not supported (%ux%u). "
                               "VIDIOCSWIN failed", win.width, win.height)
                        return err;
@@ -3124,9 +3129,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                           || cam->frame_current->queued) {
                                err = wait_event_interruptible
                                      ( cam->wait_queue,
-                                       cam->disconnected ||
-                                       (!*cam->requested_frame &&
-                                        !cam->frame_current->queued) );
+                                       cam->disconnected ||
+                                       (!*cam->requested_frame &&
+                                        !cam->frame_current->queued) );
                                if (err)
                                        return err;
                                if (cam->disconnected)
@@ -3169,7 +3174,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                mbuf.frames = cam->nbuffers;
                for (i = 0; i < cam->nbuffers; i++)
                        mbuf.offsets[i] = (unsigned long)cam->frame[i].buffer -
-                                         (unsigned long)cam->frame[0].buffer;
+                                         (unsigned long)cam->frame[0].buffer;
 
                if (copy_to_user(arg, &mbuf, sizeof(mbuf)))
                        return -EFAULT;
@@ -3188,7 +3193,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                        return -EFAULT;
 
                DBG(6, "VIDIOCMCAPTURE called: frame #%u, format=%s, %dx%d",
-                   mmap.frame, symbolic(v4l1_plist, mmap.format), 
+                   mmap.frame, symbolic(v4l1_plist, mmap.format),
                    mmap.width, mmap.height)
 
                if (mmap.frame >= cam->nbuffers) {
@@ -3197,7 +3202,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                        return -EINVAL;
                }
 
-               if (mmap.format!=cam->picture.palette && 
+               if (mmap.format!=cam->picture.palette &&
                    (cam->force_palette || !w9968cf_vpp)) {
                        DBG(4, "Palette %s rejected: only %s is allowed",
                            symbolic(v4l1_plist, mmap.format),
@@ -3207,7 +3212,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
 
                if (!w9968cf_valid_palette(mmap.format)) {
                        DBG(4, "Palette %s not supported. "
-                              "VIDIOCMCAPTURE failed", 
+                              "VIDIOCMCAPTURE failed",
                            symbolic(v4l1_plist, mmap.format))
                        return -EINVAL;
                }
@@ -3215,23 +3220,23 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                if (!cam->force_palette) {
                   if (cam->decompression == 0) {
                      if (w9968cf_need_decompression(mmap.format)) {
-                        DBG(4, "Decompression disabled: palette %s is not "
-                               "allowed. VIDIOCSPICT failed",
-                            symbolic(v4l1_plist, mmap.format))
-                        return -EINVAL;
+                        DBG(4, "Decompression disabled: palette %s is not "
+                               "allowed. VIDIOCSPICT failed",
+                            symbolic(v4l1_plist, mmap.format))
+                        return -EINVAL;
                      }
                   } else if (cam->decompression == 1) {
                      if (!w9968cf_need_decompression(mmap.format)) {
-                        DBG(4, "Decompression forced: palette %s is not "
-                               "allowed. VIDIOCSPICT failed",
-                            symbolic(v4l1_plist, mmap.format))
-                        return -EINVAL;
+                        DBG(4, "Decompression forced: palette %s is not "
+                               "allowed. VIDIOCSPICT failed",
+                            symbolic(v4l1_plist, mmap.format))
+                        return -EINVAL;
                      }
                   }
                }
 
-               if ((err = w9968cf_adjust_window_size(cam, (u16*)&mmap.width, 
-                                                     (u16*)&mmap.height))) {
+               if ((err = w9968cf_adjust_window_size(cam, (u16*)&mmap.width,
+                                                     (u16*)&mmap.height))) {
                        DBG(4, "Resolution not supported (%dx%d). "
                               "VIDIOCMCAPTURE failed",
                            mmap.width, mmap.height)
@@ -3252,12 +3257,12 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                                DBG(6, "VIDIOCMCAPTURE. Change settings for "
                                       "frame #%u: %dx%d, format %s. Wait...",
                                    mmap.frame, mmap.width, mmap.height,
-                                   symbolic(v4l1_plist, mmap.format))
+                                   symbolic(v4l1_plist, mmap.format))
                                err = wait_event_interruptible
                                      ( cam->wait_queue,
-                                       cam->disconnected ||
-                                       (!*cam->requested_frame &&
-                                        !cam->frame_current->queued) );
+                                       cam->disconnected ||
+                                       (!*cam->requested_frame &&
+                                        !cam->frame_current->queued) );
                                if (err)
                                        return err;
                                if (cam->disconnected)
@@ -3274,7 +3279,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                                goto ioctl_fail;
 
                        /* This before set_window */
-                       if (w9968cf_set_picture(cam, pict)) 
+                       if (w9968cf_set_picture(cam, pict))
                                goto ioctl_fail;
 
                        if (w9968cf_set_window(cam, win))
@@ -3286,10 +3291,10 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                } else  if (fr->queued) {
 
                        DBG(6, "Wait until frame #%u is free", mmap.frame)
-                       
-                       err = wait_event_interruptible(cam->wait_queue, 
-                                                      cam->disconnected ||
-                                                      (!fr->queued));
+
+                       err = wait_event_interruptible(cam->wait_queue,
+                                                      cam->disconnected ||
+                                                      (!fr->queued));
                        if (err)
                                return err;
                        if (cam->disconnected)
@@ -3329,9 +3334,9 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                        }
                case F_ERROR:
                case F_GRABBING:
-                       err = wait_event_interruptible(cam->wait_queue, 
-                                                      (fr->status == F_READY)
-                                                      || cam->disconnected);
+                       err = wait_event_interruptible(cam->wait_queue,
+                                                      (fr->status == F_READY)
+                                                      || cam->disconnected);
                        if (err)
                                return err;
                        if (cam->disconnected)
@@ -3433,7 +3438,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
                DBG(4, "Unsupported V4L1 IOCtl: VIDIOC%s "
                       "(type 0x%01X, "
                       "n. 0x%01X, "
-                      "dir. 0x%01X, " 
+                      "dir. 0x%01X, "
                       "size 0x%02X)",
                    V4L1_IOCTL(cmd),
                    _IOC_TYPE(cmd),_IOC_NR(cmd),_IOC_DIR(cmd),_IOC_SIZE(cmd))
@@ -3493,20 +3498,18 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
            le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct)
                mod_id = W9968CF_MOD_CLVBWGP; /* see camlist[] table */
        else if (le16_to_cpu(udev->descriptor.idVendor)  == winbond_id_table[1].idVendor &&
-                le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[1].idProduct)
+                le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[1].idProduct)
                mod_id = W9968CF_MOD_GENERIC; /* see camlist[] table */
        else
                return -ENODEV;
 
        cam = (struct w9968cf_device*)
-                 kmalloc(sizeof(struct w9968cf_device), GFP_KERNEL);
+                 kzalloc(sizeof(struct w9968cf_device), GFP_KERNEL);
        if (!cam)
                return -ENOMEM;
 
-       memset(cam, 0, sizeof(*cam));
-
-       init_MUTEX(&cam->dev_sem);
-       down(&cam->dev_sem);
+       mutex_init(&cam->dev_mutex);
+       mutex_lock(&cam->dev_mutex);
 
        cam->usbdev = udev;
        /* NOTE: a local copy is used to avoid possible race conditions */
@@ -3518,10 +3521,10 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
                simcams = W9968CF_SIMCAMS;
 
        /* How many cameras are connected ? */
-       down(&w9968cf_devlist_sem);
+       mutex_lock(&w9968cf_devlist_mutex);
        list_for_each(ptr, &w9968cf_dev_list)
                sc++;
-       up(&w9968cf_devlist_sem);
+       mutex_unlock(&w9968cf_devlist_mutex);
 
        if (sc >= simcams) {
                DBG(2, "Device rejected: too many connected cameras "
@@ -3532,21 +3535,19 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
 
 
        /* Allocate 2 bytes of memory for camera control USB transfers */
-       if (!(cam->control_buffer = kmalloc(2, GFP_KERNEL))) {
+       if (!(cam->control_buffer = kzalloc(2, GFP_KERNEL))) {
                DBG(1,"Couldn't allocate memory for camera control transfers")
                err = -ENOMEM;
                goto fail;
        }
-       memset(cam->control_buffer, 0, 2);
 
        /* Allocate 8 bytes of memory for USB data transfers to the FSB */
-       if (!(cam->data_buffer = kmalloc(8, GFP_KERNEL))) {
+       if (!(cam->data_buffer = kzalloc(8, GFP_KERNEL))) {
                DBG(1, "Couldn't allocate memory for data "
                       "transfers to the FSB")
                err = -ENOMEM;
                goto fail;
        }
-       memset(cam->data_buffer, 0, 8);
 
        /* Register the V4L device */
        cam->v4ldev = video_device_alloc();
@@ -3567,7 +3568,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        cam->v4ldev->dev = &cam->dev;
 
        err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
-                                   video_nr[dev_nr]);
+                                   video_nr[dev_nr]);
        if (err) {
                DBG(1, "V4L device registration failed")
                if (err == -ENFILE && video_nr[dev_nr] == -1)
@@ -3583,9 +3584,9 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        w9968cf_configure_camera(cam, udev, mod_id, dev_nr);
 
        /* Add a new entry into the list of V4L registered devices */
-       down(&w9968cf_devlist_sem);
+       mutex_lock(&w9968cf_devlist_mutex);
        list_add(&cam->v4llist, &w9968cf_dev_list);
-       up(&w9968cf_devlist_sem);
+       mutex_unlock(&w9968cf_devlist_mutex);
        dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0;
 
        w9968cf_turn_on_led(cam);
@@ -3593,7 +3594,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        w9968cf_i2c_init(cam);
 
        usb_set_intfdata(intf, cam);
-       up(&cam->dev_sem);
+       mutex_unlock(&cam->dev_mutex);
        return 0;
 
 fail: /* Free unused memory */
@@ -3601,7 +3602,7 @@ fail: /* Free unused memory */
        kfree(cam->data_buffer);
        if (cam->v4ldev)
                video_device_release(cam->v4ldev);
-       up(&cam->dev_sem);
+       mutex_unlock(&cam->dev_mutex);
        kfree(cam);
        return err;
 }
@@ -3609,14 +3610,14 @@ fail: /* Free unused memory */
 
 static void w9968cf_usb_disconnect(struct usb_interface* intf)
 {
-       struct w9968cf_device* cam = 
+       struct w9968cf_device* cam =
           (struct w9968cf_device*)usb_get_intfdata(intf);
 
        down_write(&w9968cf_disconnect);
 
        if (cam) {
                /* Prevent concurrent accesses to data */
-               down(&cam->dev_sem); 
+               mutex_lock(&cam->dev_mutex);
 
                cam->disconnected = 1;
 
@@ -3635,7 +3636,7 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
                } else
                        w9968cf_release_resources(cam);
 
-               up(&cam->dev_sem);
+               mutex_unlock(&cam->dev_mutex);
 
                if (!cam->users)
                        kfree(cam);