Commit 046d747e authored by Timo von Holtz's avatar Timo von Holtz Committed by Greg Kroah-Hartman

Staging: usbvideo: vicam: fixed some coding style issues

fixed coding style issues.
Signed-off-by: default avatarTimo von Holtz <tvh@informatik.uni-kiel.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 61ceb7f9
...@@ -48,13 +48,13 @@ ...@@ -48,13 +48,13 @@
#include <linux/ihex.h> #include <linux/ihex.h>
#include "usbvideo.h" #include "usbvideo.h"
// #define VICAM_DEBUG /* #define VICAM_DEBUG */
#ifdef VICAM_DEBUG #ifdef VICAM_DEBUG
#define ADBG(lineno,fmt,args...) printk(fmt, jiffies, __func__, lineno, ##args) #define ADBG(lineno, fmt, args...) printk(fmt, jiffies, __func__, lineno, ##args)
#define DBG(fmt,args...) ADBG((__LINE__),KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt,##args) #define DBG(fmt, args...) ADBG((__LINE__), KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt, ##args)
#else #else
#define DBG(fmn,args...) do {} while(0) #define DBG(fmn, args...) do {} while (0)
#endif #endif
#define DRIVER_AUTHOR "Joe Burks, jburks@wavicle.org" #define DRIVER_AUTHOR "Joe Burks, jburks@wavicle.org"
...@@ -118,15 +118,15 @@ static void rvfree(void *mem, unsigned long size) ...@@ -118,15 +118,15 @@ static void rvfree(void *mem, unsigned long size)
} }
struct vicam_camera { struct vicam_camera {
u16 shutter_speed; // capture shutter speed u16 shutter_speed; /* capture shutter speed */
u16 gain; // capture gain u16 gain; /* capture gain */
u8 *raw_image; // raw data captured from the camera u8 *raw_image; /* raw data captured from the camera */
u8 *framebuf; // processed data in RGB24 format u8 *framebuf; /* processed data in RGB24 format */
u8 *cntrlbuf; // area used to send control msgs u8 *cntrlbuf; /* area used to send control msgs */
struct video_device vdev; // v4l video device struct video_device vdev; /* v4l video device */
struct usb_device *udev; // usb device struct usb_device *udev; /* usb device */
/* guard against simultaneous accesses to the camera */ /* guard against simultaneous accesses to the camera */
struct mutex cam_lock; struct mutex cam_lock;
...@@ -137,7 +137,7 @@ struct vicam_camera { ...@@ -137,7 +137,7 @@ struct vicam_camera {
int needsDummyRead; int needsDummyRead;
}; };
static int vicam_probe( struct usb_interface *intf, const struct usb_device_id *id); static int vicam_probe(struct usb_interface *intf, const struct usb_device_id *id);
static void vicam_disconnect(struct usb_interface *intf); static void vicam_disconnect(struct usb_interface *intf);
static void read_frame(struct vicam_camera *cam, int framenum); static void read_frame(struct vicam_camera *cam, int framenum);
static void vicam_decode_color(const u8 *, u8 *); static void vicam_decode_color(const u8 *, u8 *);
...@@ -219,12 +219,12 @@ set_camera_power(struct vicam_camera *cam, int state) ...@@ -219,12 +219,12 @@ set_camera_power(struct vicam_camera *cam, int state)
{ {
int status; int status;
if ((status = send_control_msg(cam, 0x50, state, 0, NULL, 0)) < 0) status = send_control_msg(cam, 0x50, state, 0, NULL, 0));
if (status < 0)
return status; return status;
if (state) { if (state)
send_control_msg(cam, 0x55, 1, 0, NULL, 0); send_control_msg(cam, 0x55, 1, 0, NULL, 0);
}
return 0; return 0;
} }
...@@ -307,11 +307,11 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -307,11 +307,11 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
{ {
struct video_picture vp; struct video_picture vp;
DBG("VIDIOCGPICT\n"); DBG("VIDIOCGPICT\n");
memset(&vp, 0, sizeof (struct video_picture)); memset(&vp, 0, sizeof(struct video_picture));
vp.brightness = cam->gain << 8; vp.brightness = cam->gain << 8;
vp.depth = 24; vp.depth = 24;
vp.palette = VIDEO_PALETTE_RGB24; vp.palette = VIDEO_PALETTE_RGB24;
if (copy_to_user(user_arg, &vp, sizeof (struct video_picture))) if (copy_to_user(user_arg, &vp, sizeof(struct video_picture)))
retval = -EFAULT; retval = -EFAULT;
break; break;
} }
...@@ -355,8 +355,8 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -355,8 +355,8 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
if (copy_to_user(user_arg, (void *)&vw, sizeof(vw))) if (copy_to_user(user_arg, (void *)&vw, sizeof(vw)))
retval = -EFAULT; retval = -EFAULT;
// I'm not sure what the deal with a capture window is, it is very poorly described /* I'm not sure what the deal with a capture window is, it is very poorly described
// in the doc. So I won't support it now. * in the doc. So I won't support it now. */
break; break;
} }
...@@ -372,7 +372,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -372,7 +372,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
DBG("VIDIOCSWIN %d x %d\n", vw.width, vw.height); DBG("VIDIOCSWIN %d x %d\n", vw.width, vw.height);
if ( vw.width != 320 || vw.height != 240 ) if (vw.width != 320 || vw.height != 240)
retval = -EFAULT; retval = -EFAULT;
break; break;
...@@ -385,7 +385,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -385,7 +385,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
int i; int i;
DBG("VIDIOCGMBUF\n"); DBG("VIDIOCGMBUF\n");
memset(&vm, 0, sizeof (vm)); memset(&vm, 0, sizeof(vm));
vm.size = vm.size =
VICAM_MAX_FRAME_SIZE * VICAM_FRAMES; VICAM_MAX_FRAME_SIZE * VICAM_FRAMES;
vm.frames = VICAM_FRAMES; vm.frames = VICAM_FRAMES;
...@@ -401,23 +401,24 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -401,23 +401,24 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
case VIDIOCMCAPTURE: case VIDIOCMCAPTURE:
{ {
struct video_mmap vm; struct video_mmap vm;
// int video_size; /* int video_size; */
if (copy_from_user((void *)&vm, user_arg, sizeof(vm))) { if (copy_from_user((void *)&vm, user_arg, sizeof(vm))) {
retval = -EFAULT; retval = -EFAULT;
break; break;
} }
DBG("VIDIOCMCAPTURE frame=%d, height=%d, width=%d, format=%d.\n",vm.frame,vm.width,vm.height,vm.format); DBG("VIDIOCMCAPTURE frame=%d, height=%d, width=%d, format=%d.\n",
vm.frame, vm.width, vm.height, vm.format);
if ( vm.frame >= VICAM_FRAMES || vm.format != VIDEO_PALETTE_RGB24 ) if (vm.frame >= VICAM_FRAMES || vm.format != VIDEO_PALETTE_RGB24)
retval = -EINVAL; retval = -EINVAL;
// in theory right here we'd start the image capturing /* in theory right here we'd start the image capturing
// (fill in a bulk urb and submit it asynchronously) * (fill in a bulk urb and submit it asynchronously)
// *
// Instead we're going to do a total hack job for now and * Instead we're going to do a total hack job for now and
// retrieve the frame in VIDIOCSYNC * retrieve the frame in VIDIOCSYNC */
break; break;
} }
...@@ -435,7 +436,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) ...@@ -435,7 +436,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg)
read_frame(cam, frame); read_frame(cam, frame);
vicam_decode_color(cam->raw_image, vicam_decode_color(cam->raw_image,
cam->framebuf + cam->framebuf +
frame * VICAM_MAX_FRAME_SIZE ); frame * VICAM_MAX_FRAME_SIZE);
break; break;
} }
...@@ -522,7 +523,7 @@ vicam_open(struct file *file) ...@@ -522,7 +523,7 @@ vicam_open(struct file *file)
mutex_unlock(&cam->cam_lock); mutex_unlock(&cam->cam_lock);
// First upload firmware, then turn the camera on /* First upload firmware, then turn the camera on */
if (!cam->is_initialized) { if (!cam->is_initialized) {
initialize_camera(cam); initialize_camera(cam);
...@@ -562,9 +563,8 @@ vicam_close(struct file *file) ...@@ -562,9 +563,8 @@ vicam_close(struct file *file)
mutex_unlock(&cam->cam_lock); mutex_unlock(&cam->cam_lock);
if (!open_count && !udev) { if (!open_count && !udev)
kfree(cam); kfree(cam);
}
return 0; return 0;
} }
...@@ -582,57 +582,55 @@ static void vicam_decode_color(const u8 *data, u8 *rgb) ...@@ -582,57 +582,55 @@ static void vicam_decode_color(const u8 *data, u8 *rgb)
data += VICAM_HEADER_SIZE; data += VICAM_HEADER_SIZE;
for( i = 0; i < 240; i++, data += 512 ) { for (i = 0; i < 240; i++, data += 512) {
const int y = ( i * 242 ) / 240; const int y = (i * 242) / 240;
int j, prevX, nextX; int j, prevX, nextX;
int Y, Cr, Cb; int Y, Cr, Cb;
if ( y == 242 - 1 ) { if (y == 242 - 1)
nextY = -512; nextY = -512;
}
prevX = 1; prevX = 1;
nextX = 1; nextX = 1;
for ( j = 0; j < 320; j++, rgb += 3 ) { for (j = 0; j < 320; j++, rgb += 3) {
const int x = ( j * 512 ) / 320; const int x = (j * 512) / 320;
const u8 * const src = &data[x]; const u8 * const src = &data[x];
if ( x == 512 - 1 ) { if (x == 512 - 1)
nextX = -1; nextX = -1;
}
Cr = ( src[prevX] - src[0] ) + Cr = (src[prevX] - src[0]) +
( src[nextX] - src[0] ); (src[nextX] - src[0]);
Cr /= 2; Cr /= 2;
Cb = ( src[prevY] - src[prevX + prevY] ) + Cb = (src[prevY] - src[prevX + prevY]) +
( src[prevY] - src[nextX + prevY] ) + (src[prevY] - src[nextX + prevY]) +
( src[nextY] - src[prevX + nextY] ) + (src[nextY] - src[prevX + nextY]) +
( src[nextY] - src[nextX + nextY] ); (src[nextY] - src[nextX + nextY]);
Cb /= 4; Cb /= 4;
Y = 1160 * ( src[0] + ( Cr / 2 ) - 16 ); Y = 1160 * (src[0] + (Cr / 2) - 16);
if ( i & 1 ) { if (i & 1) {
int Ct = Cr; int Ct = Cr;
Cr = Cb; Cr = Cb;
Cb = Ct; Cb = Ct;
} }
if ( ( x ^ i ) & 1 ) { if ((x ^ i) & 1) {
Cr = -Cr; Cr = -Cr;
Cb = -Cb; Cb = -Cb;
} }
rgb[0] = clamp( ( ( Y + ( 2017 * Cb ) ) + rgb[0] = clamp(((Y + (2017 * Cb)) +
500 ) / 900, 0, 255 ); 500) / 900, 0, 255);
rgb[1] = clamp( ( ( Y - ( 392 * Cb ) - rgb[1] = clamp(((Y - (392 * Cb) -
( 813 * Cr ) ) + (813 * Cr)) +
500 ) / 1000, 0, 255 ); 500) / 1000, 0, 255);
rgb[2] = clamp( ( ( Y + ( 1594 * Cr ) ) + rgb[2] = clamp(((Y + (1594 * Cr)) +
500 ) / 1300, 0, 255 ); 500) / 1300, 0, 255);
prevX = -1; prevX = -1;
} }
...@@ -655,15 +653,15 @@ read_frame(struct vicam_camera *cam, int framenum) ...@@ -655,15 +653,15 @@ read_frame(struct vicam_camera *cam, int framenum)
} }
memset(request, 0, 16); memset(request, 0, 16);
request[0] = cam->gain; // 0 = 0% gain, FF = 100% gain request[0] = cam->gain; /* 0 = 0% gain, FF = 100% gain */
request[1] = 0; // 512x242 capture request[1] = 0; /* 512x242 capture */
request[2] = 0x90; // the function of these two bytes request[2] = 0x90; /* the function of these two bytes */
request[3] = 0x07; // is not yet understood request[3] = 0x07; /* is not yet understood */
if (cam->shutter_speed > 60) { if (cam->shutter_speed > 60) {
// Short exposure /* Short exposure */
realShutter = realShutter =
((-15631900 / cam->shutter_speed) + 260533) / 1000; ((-15631900 / cam->shutter_speed) + 260533) / 1000;
request[4] = realShutter & 0xFF; request[4] = realShutter & 0xFF;
...@@ -671,7 +669,7 @@ read_frame(struct vicam_camera *cam, int framenum) ...@@ -671,7 +669,7 @@ read_frame(struct vicam_camera *cam, int framenum)
request[6] = 0x03; request[6] = 0x03;
request[7] = 0x01; request[7] = 0x01;
} else { } else {
// Long exposure /* Long exposure */
realShutter = 15600 / cam->shutter_speed - 1; realShutter = 15600 / cam->shutter_speed - 1;
request[4] = 0; request[4] = 0;
request[5] = 0; request[5] = 0;
...@@ -679,15 +677,14 @@ read_frame(struct vicam_camera *cam, int framenum) ...@@ -679,15 +677,14 @@ read_frame(struct vicam_camera *cam, int framenum)
request[7] = realShutter >> 8; request[7] = realShutter >> 8;
} }
// Per John Markus Bjørndalen, byte at index 8 causes problems if it isn't 0 /* Per John Markus Bjørndalen, byte at index 8 causes problems if it isn't 0*/
request[8] = 0; request[8] = 0;
// bytes 9-15 do not seem to affect exposure or image quality /* bytes 9-15 do not seem to affect exposure or image quality */
mutex_lock(&cam->cam_lock); mutex_lock(&cam->cam_lock);
if (!cam->udev) { if (!cam->udev)
goto done; goto done;
}
n = __send_control_msg(cam, 0x51, 0x80, 0, request, 16); n = __send_control_msg(cam, 0x51, 0x80, 0, request, 16);
...@@ -712,7 +709,7 @@ read_frame(struct vicam_camera *cam, int framenum) ...@@ -712,7 +709,7 @@ read_frame(struct vicam_camera *cam, int framenum)
} }
static ssize_t static ssize_t
vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos ) vicam_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{ {
struct vicam_camera *cam = file->private_data; struct vicam_camera *cam = file->private_data;
...@@ -732,15 +729,13 @@ vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos ) ...@@ -732,15 +729,13 @@ vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos )
count = min_t(size_t, count, VICAM_MAX_FRAME_SIZE - *ppos); count = min_t(size_t, count, VICAM_MAX_FRAME_SIZE - *ppos);
if (copy_to_user(buf, &cam->framebuf[*ppos], count)) { if (copy_to_user(buf, &cam->framebuf[*ppos], count))
count = -EFAULT; count = -EFAULT;
} else { else
*ppos += count; *ppos += count;
}
if (count == VICAM_MAX_FRAME_SIZE) { if (count == VICAM_MAX_FRAME_SIZE)
*ppos = 0; *ppos = 0;
}
return count; return count;
} }
...@@ -749,7 +744,7 @@ vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos ) ...@@ -749,7 +744,7 @@ vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos )
static int static int
vicam_mmap(struct file *file, struct vm_area_struct *vma) vicam_mmap(struct file *file, struct vm_area_struct *vma)
{ {
// TODO: allocate the raw frame buffer if necessary /* TODO: allocate the raw frame buffer if necessary */
unsigned long page, pos; unsigned long page, pos;
unsigned long start = vma->vm_start; unsigned long start = vma->vm_start;
unsigned long size = vma->vm_end-vma->vm_start; unsigned long size = vma->vm_end-vma->vm_start;
...@@ -793,9 +788,9 @@ static const struct v4l2_file_operations vicam_fops = { ...@@ -793,9 +788,9 @@ static const struct v4l2_file_operations vicam_fops = {
}; };
static struct video_device vicam_template = { static struct video_device vicam_template = {
.name = "ViCam-based USB Camera", .name = "ViCam-based USB Camera",
.fops = &vicam_fops, .fops = &vicam_fops,
.release = video_device_release_empty, .release = video_device_release_empty,
}; };
/* table of devices that work with this driver */ /* table of devices that work with this driver */
...@@ -823,7 +818,7 @@ static struct usb_driver vicam_driver = { ...@@ -823,7 +818,7 @@ static struct usb_driver vicam_driver = {
* this driver might be interested in. * this driver might be interested in.
*/ */
static int static int
vicam_probe( struct usb_interface *intf, const struct usb_device_id *id) vicam_probe(struct usb_interface *intf, const struct usb_device_id *id)
{ {
struct usb_device *dev = interface_to_usbdev(intf); struct usb_device *dev = interface_to_usbdev(intf);
int bulkEndpoint = 0; int bulkEndpoint = 0;
...@@ -847,8 +842,8 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id) ...@@ -847,8 +842,8 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
"No bulk in endpoint was found ?! (this is bad)\n"); "No bulk in endpoint was found ?! (this is bad)\n");
} }
if ((cam = cam = kzalloc(sizeof(struct vicam_camera), GFP_KERNEL);
kzalloc(sizeof (struct vicam_camera), GFP_KERNEL)) == NULL) { if (cam == NULL) {
printk(KERN_WARNING printk(KERN_WARNING
"could not allocate kernel memory for vicam_camera struct\n"); "could not allocate kernel memory for vicam_camera struct\n");
return -ENOMEM; return -ENOMEM;
...@@ -874,7 +869,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id) ...@@ -874,7 +869,7 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
printk(KERN_INFO "ViCam webcam driver now controlling device %s\n", printk(KERN_INFO "ViCam webcam driver now controlling device %s\n",
video_device_node_name(&cam->vdev)); video_device_node_name(&cam->vdev));
usb_set_intfdata (intf, cam); usb_set_intfdata(intf, cam);
return 0; return 0;
} }
...@@ -883,8 +878,8 @@ static void ...@@ -883,8 +878,8 @@ static void
vicam_disconnect(struct usb_interface *intf) vicam_disconnect(struct usb_interface *intf)
{ {
int open_count; int open_count;
struct vicam_camera *cam = usb_get_intfdata (intf); struct vicam_camera *cam = usb_get_intfdata(intf);
usb_set_intfdata (intf, NULL); usb_set_intfdata(intf, NULL);
/* we must unregister the device before taking its /* we must unregister the device before taking its
* cam_lock. This is because the video open call * cam_lock. This is because the video open call
...@@ -914,9 +909,8 @@ vicam_disconnect(struct usb_interface *intf) ...@@ -914,9 +909,8 @@ vicam_disconnect(struct usb_interface *intf)
mutex_unlock(&cam->cam_lock); mutex_unlock(&cam->cam_lock);
if (!open_count) { if (!open_count)
kfree(cam); kfree(cam);
}
printk(KERN_DEBUG "ViCam-based WebCam disconnected\n"); printk(KERN_DEBUG "ViCam-based WebCam disconnected\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment