diff options
Diffstat (limited to 'drivers/staging/usbvideo')
-rw-r--r-- | drivers/staging/usbvideo/usbvideo.c | 170 | ||||
-rw-r--r-- | drivers/staging/usbvideo/vicam.c | 164 |
2 files changed, 160 insertions, 174 deletions
diff --git a/drivers/staging/usbvideo/usbvideo.c b/drivers/staging/usbvideo/usbvideo.c index f1fcf97..cd4c73a 100644 --- a/drivers/staging/usbvideo/usbvideo.c +++ b/drivers/staging/usbvideo/usbvideo.c @@ -24,7 +24,7 @@ #include <linux/init.h> #include <linux/spinlock.h> -#include <asm/io.h> +#include <linux/io.h> #include "usbvideo.h" @@ -112,9 +112,9 @@ static void RingQueue_Allocate(struct RingQueue *rq, int rqLen) assert(rq != NULL); assert(rqLen > 0); - while(rqLen >> i) + while (rqLen >> i) i++; - if(rqLen != 1 << (i-1)) + if (rqLen != 1 << (i-1)) rqLen = 1 << i; rq->length = rqLen; @@ -148,15 +148,15 @@ int RingQueue_Dequeue(struct RingQueue *rq, unsigned char *dst, int len) assert(dst != NULL); rql = RingQueue_GetLength(rq); - if(!rql) + if (!rql) return 0; /* Clip requested length to available data */ - if(len > rql) + if (len > rql) len = rql; toread = len; - if(rq->ri > rq->wi) { + if (rq->ri > rq->wi) { /* Read data from tail */ int read = (toread < (rq->length - rq->ri)) ? toread : rq->length - rq->ri; memcpy(dst, rq->queue + rq->ri, read); @@ -164,7 +164,7 @@ int RingQueue_Dequeue(struct RingQueue *rq, unsigned char *dst, int len) dst += read; rq->ri = (rq->ri + read) & (rq->length-1); } - if(toread) { + if (toread) { /* Read data from head */ memcpy(dst, rq->queue + rq->ri, toread); rq->ri = (rq->ri + toread) & (rq->length-1); @@ -292,12 +292,11 @@ static void usbvideo_OverlayChar(struct uvd *uvd, struct usbvideo_frame *frame, return; digit = digits[value]; - for (iy=0; iy < 5; iy++) { - for (ix=0; ix < 3; ix++) { + for (iy = 0; iy < 5; iy++) { + for (ix = 0; ix < 3; ix++) { if (digit & 0x8000) { - if (uvd->paletteBits & (1L << VIDEO_PALETTE_RGB24)) { + if (uvd->paletteBits & (1L << VIDEO_PALETTE_RGB24)) /* TODO */ RGB24_PUTPIXEL(frame, x+ix, y+iy, 0xFF, 0xFF, 0xFF); - } } digit = digit << 1; } @@ -332,7 +331,7 @@ static void usbvideo_OverlayStats(struct uvd *uvd, struct usbvideo_frame *frame) { const int y_diff = 8; char tmp[16]; - int x = 10, y=10; + int x = 10, y = 10; long i, j, barLength; const int qi_x1 = 60, qi_y1 = 10; const int qi_x2 = VIDEOSIZE_X(frame->request) - 10, qi_h = 10; @@ -375,8 +374,8 @@ static void usbvideo_OverlayStats(struct uvd *uvd, struct usbvideo_frame *frame) m_lo = (u_lo > 0) ? (qi_x1 + ((barLength * u_lo) / uvd->dp.length)) : -1; m_hi = qi_x1 + ((barLength * u_hi) / uvd->dp.length); - for (j=qi_y1; j < (qi_y1 + qi_h); j++) { - for (i=qi_x1; i < qi_x2; i++) { + for (j = qi_y1; j < (qi_y1 + qi_h); j++) { + for (i = qi_x1; i < qi_x2; i++) { /* Draw border lines */ if ((j == qi_y1) || (j == (qi_y1 + qi_h - 1)) || (i == qi_x1) || (i == (qi_x2 - 1))) { @@ -384,11 +383,11 @@ static void usbvideo_OverlayStats(struct uvd *uvd, struct usbvideo_frame *frame) continue; } /* For all other points the Y coordinate does not matter */ - if ((i >= m_ri) && (i <= (m_ri + 3))) { + if ((i >= m_ri) && (i <= (m_ri + 3))) RGB24_PUTPIXEL(frame, i, j, 0x00, 0xFF, 0x00); - } else if ((i >= m_wi) && (i <= (m_wi + 3))) { + else if ((i >= m_wi) && (i <= (m_wi + 3))) RGB24_PUTPIXEL(frame, i, j, 0xFF, 0x00, 0x00); - } else if ((i < m_lo) || ((i > m_ri) && (i < m_hi))) + else if ((i < m_lo) || ((i > m_ri) && (i < m_hi))) RGB24_PUTPIXEL(frame, i, j, 0x00, 0x00, 0xFF); } } @@ -551,8 +550,8 @@ void usbvideo_TestPattern(struct uvd *uvd, int fullframe, int pmode) int i; unsigned char *f = frame->data + (VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL * frame->curline); - for (i=0; i < VIDEOSIZE_X(frame->request); i++) { - unsigned char cb=0x80; + for (i = 0; i < VIDEOSIZE_X(frame->request); i++) { + unsigned char cb = 0x80; unsigned char cg = 0; unsigned char cr = 0; @@ -605,10 +604,10 @@ void usbvideo_HexDump(const unsigned char *data, int len) char tmp[128]; /* 32*3 + 5 */ int i, k; - for (i=k=0; len > 0; i++, len--) { + for (i = k = 0; len > 0; i++, len--) { if (i > 0 && ((i % bytes_per_line) == 0)) { printk("%s\n", tmp); - k=0; + k = 0; } if ((i % bytes_per_line) == 0) k += sprintf(&tmp[k], "%04x: ", i); @@ -787,7 +786,7 @@ void usbvideo_Deregister(struct usbvideo **pCams) usb_deregister(&cams->usbdrv); dbg("%s: Deallocating cams=$%p (%d. cameras)", __func__, cams, cams->num_cameras); - for (i=0; i < cams->num_cameras; i++) { + for (i = 0; i < cams->num_cameras; i++) { struct uvd *up = &cams->cam[i]; int warning = 0; @@ -840,7 +839,7 @@ EXPORT_SYMBOL(usbvideo_Deregister); */ static void usbvideo_Disconnect(struct usb_interface *intf) { - struct uvd *uvd = usb_get_intfdata (intf); + struct uvd *uvd = usb_get_intfdata(intf); int i; if (uvd == NULL) { @@ -848,7 +847,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf) return; } - usb_set_intfdata (intf, NULL); + usb_set_intfdata(intf, NULL); usbvideo_ClientIncModCount(uvd); if (uvd->debug > 0) @@ -860,11 +859,11 @@ static void usbvideo_Disconnect(struct usb_interface *intf) /* At this time we ask to cancel outstanding URBs */ GET_CALLBACK(uvd, stopDataPump)(uvd); - for (i=0; i < USBVIDEO_NUMSBUF; i++) + for (i = 0; i < USBVIDEO_NUMSBUF; i++) usb_free_urb(uvd->sbuf[i].urb); usb_put_dev(uvd->dev); - uvd->dev = NULL; /* USB device is no more */ + uvd->dev = NULL; /* USB device is no more */ video_unregister_device(&uvd->vdev); if (uvd->debug > 0) @@ -925,8 +924,7 @@ static int usbvideo_find_struct(struct usbvideo *cams) mutex_lock(&cams->lock); for (u = 0; u < cams->num_cameras; u++) { struct uvd *uvd = &cams->cam[u]; - if (!uvd->uvd_used) /* This one is free */ - { + if (!uvd->uvd_used) { /* This one is free */ uvd->uvd_used = 1; /* In use now */ mutex_init(&uvd->lock); /* to 1 == available */ uvd->dev = NULL; @@ -941,10 +939,10 @@ static int usbvideo_find_struct(struct usbvideo *cams) static const struct v4l2_file_operations usbvideo_fops = { .owner = THIS_MODULE, .open = usbvideo_v4l_open, - .release =usbvideo_v4l_close, - .read = usbvideo_v4l_read, - .mmap = usbvideo_v4l_mmap, - .ioctl = usbvideo_v4l_ioctl, + .release = usbvideo_v4l_close, + .read = usbvideo_v4l_read, + .mmap = usbvideo_v4l_mmap, + .ioctl = usbvideo_v4l_ioctl, }; static const struct video_device usbvideo_template = { .fops = &usbvideo_fops, @@ -972,7 +970,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams) usbvideo_ClientIncModCount(uvd); mutex_lock(&uvd->lock); - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { uvd->sbuf[i].urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL); if (uvd->sbuf[i].urb == NULL) { err("usb_alloc_urb(%d.) failed.", FRAMES_PER_DESC); @@ -981,7 +979,7 @@ struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams) goto allocate_done; } } - uvd->user=0; + uvd->user = 0; uvd->remove_pending = 0; uvd->last_error = 0; RingQueue_Initialize(&uvd->dp); @@ -1127,7 +1125,7 @@ static int usbvideo_v4l_open(struct file *file) memset(&uvd->stats, 0, sizeof(uvd->stats)); /* Clean pointers so we know if we allocated something */ - for (i=0; i < USBVIDEO_NUMSBUF; i++) + for (i = 0; i < USBVIDEO_NUMSBUF; i++) uvd->sbuf[i].data = NULL; /* Allocate memory for the frame buffers */ @@ -1140,7 +1138,7 @@ static int usbvideo_v4l_open(struct file *file) errCode = -ENOMEM; } else { /* Allocate all buffers */ - for (i=0; i < USBVIDEO_NUMFRAMES; i++) { + for (i = 0; i < USBVIDEO_NUMFRAMES; i++) { uvd->frame[i].frameState = FrameState_Unused; uvd->frame[i].data = uvd->fbuf + i*(uvd->max_frame_size); /* @@ -1150,7 +1148,7 @@ static int usbvideo_v4l_open(struct file *file) uvd->frame[i].canvas = uvd->canvas; uvd->frame[i].seqRead_Index = 0; } - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { uvd->sbuf[i].data = kmalloc(sb_size, GFP_KERNEL); if (uvd->sbuf[i].data == NULL) { errCode = -ENOMEM; @@ -1165,7 +1163,7 @@ static int usbvideo_v4l_open(struct file *file) uvd->fbuf = NULL; } RingQueue_Free(&uvd->dp); - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { kfree(uvd->sbuf[i].data); uvd->sbuf[i].data = NULL; } @@ -1240,7 +1238,7 @@ static int usbvideo_v4l_close(struct file *file) uvd->fbuf = NULL; RingQueue_Free(&uvd->dp); - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { kfree(uvd->sbuf[i].data); uvd->sbuf[i].data = NULL; } @@ -1281,32 +1279,32 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg return -EIO; switch (cmd) { - case VIDIOCGCAP: + case VIDIOCGCAP: { struct video_capability *b = arg; *b = uvd->vcap; return 0; } - case VIDIOCGCHAN: + case VIDIOCGCHAN: { struct video_channel *v = arg; *v = uvd->vchan; return 0; } - case VIDIOCSCHAN: + case VIDIOCSCHAN: { struct video_channel *v = arg; if (v->channel != 0) return -EINVAL; return 0; } - case VIDIOCGPICT: + case VIDIOCGPICT: { struct video_picture *pic = arg; *pic = uvd->vpic; return 0; } - case VIDIOCSPICT: + case VIDIOCSPICT: { struct video_picture *pic = arg; /* @@ -1321,13 +1319,12 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg uvd->settingsAdjusted = 0; /* Will force new settings */ return 0; } - case VIDIOCSWIN: + case VIDIOCSWIN: { struct video_window *vw = arg; - if(VALID_CALLBACK(uvd, setVideoMode)) { + if (VALID_CALLBACK(uvd, setVideoMode)) return GET_CALLBACK(uvd, setVideoMode)(uvd, vw); - } if (vw->flags) return -EINVAL; @@ -1340,7 +1337,7 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg return 0; } - case VIDIOCGWIN: + case VIDIOCGWIN: { struct video_window *vw = arg; @@ -1355,7 +1352,7 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg vw->flags = 10; /* FIXME: do better! */ return 0; } - case VIDIOCGMBUF: + case VIDIOCGMBUF: { struct video_mbuf *vm = arg; int i; @@ -1363,12 +1360,12 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg memset(vm, 0, sizeof(*vm)); vm->size = uvd->max_frame_size * USBVIDEO_NUMFRAMES; vm->frames = USBVIDEO_NUMFRAMES; - for(i = 0; i < USBVIDEO_NUMFRAMES; i++) - vm->offsets[i] = i * uvd->max_frame_size; + for (i = 0; i < USBVIDEO_NUMFRAMES; i++) + vm->offsets[i] = i * uvd->max_frame_size; return 0; } - case VIDIOCMCAPTURE: + case VIDIOCMCAPTURE: { struct video_mmap *vm = arg; @@ -1429,7 +1426,7 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg return usbvideo_NewFrame(uvd, vm->frame); } - case VIDIOCSYNC: + case VIDIOCSYNC: { int *frameNum = arg; int ret; @@ -1445,9 +1442,8 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg ret = usbvideo_GetFrame(uvd, *frameNum); else if (VALID_CALLBACK(uvd, getFrame)) { ret = GET_CALLBACK(uvd, getFrame)(uvd, *frameNum); - if ((ret < 0) && (uvd->debug >= 1)) { + if ((ret < 0) && (uvd->debug >= 1)) err("VIDIOCSYNC: getFrame() returned %d.", ret); - } } else { err("VIDIOCSYNC: getFrame is not set"); ret = -EFAULT; @@ -1462,33 +1458,33 @@ static long usbvideo_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg uvd->frame[*frameNum].frameState = FrameState_Unused; return ret; } - case VIDIOCGFBUF: + case VIDIOCGFBUF: { struct video_buffer *vb = arg; memset(vb, 0, sizeof(*vb)); return 0; } - case VIDIOCKEY: - return 0; + case VIDIOCKEY: + return 0; - case VIDIOCCAPTURE: - return -EINVAL; + case VIDIOCCAPTURE: + return -EINVAL; - case VIDIOCSFBUF: + case VIDIOCSFBUF: - case VIDIOCGTUNER: - case VIDIOCSTUNER: + case VIDIOCGTUNER: + case VIDIOCSTUNER: - case VIDIOCGFREQ: - case VIDIOCSFREQ: + case VIDIOCGFREQ: + case VIDIOCSFREQ: - case VIDIOCGAUDIO: - case VIDIOCSAUDIO: - return -EINVAL; + case VIDIOCGAUDIO: + case VIDIOCSAUDIO: + return -EINVAL; - default: - return -ENOIOCTLCMD; + default: + return -ENOIOCTLCMD; } return 0; } @@ -1529,7 +1525,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf, mutex_lock(&uvd->lock); /* See if a frame is completed, then use it. */ - for(i = 0; i < USBVIDEO_NUMFRAMES; i++) { + for (i = 0; i < USBVIDEO_NUMFRAMES; i++) { if ((uvd->frame[i].frameState == FrameState_Done) || (uvd->frame[i].frameState == FrameState_Done_Hold) || (uvd->frame[i].frameState == FrameState_Error)) { @@ -1550,7 +1546,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf, * We will need to wait until it becomes cooked, of course. */ if (frmx == -1) { - for(i = 0; i < USBVIDEO_NUMFRAMES; i++) { + for (i = 0; i < USBVIDEO_NUMFRAMES; i++) { if (uvd->frame[i].frameState == FrameState_Grabbing) { frmx = i; break; @@ -1653,9 +1649,8 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf, /* Mark it as available to be used again. */ uvd->frame[frmx].frameState = FrameState_Unused; - if (usbvideo_NewFrame(uvd, (frmx + 1) % USBVIDEO_NUMFRAMES)) { + if (usbvideo_NewFrame(uvd, (frmx + 1) % USBVIDEO_NUMFRAMES)) err("%s: usbvideo_NewFrame failed.", __func__); - } } read_done: mutex_unlock(&uvd->lock); @@ -1744,8 +1739,8 @@ urb_done_with: } urb->status = 0; urb->dev = uvd->dev; - ret = usb_submit_urb (urb, GFP_KERNEL); - if(ret) + ret = usb_submit_urb(urb, GFP_KERNEL); + if (ret) err("usb_submit_urb error (%d)", ret); return; } @@ -1785,7 +1780,7 @@ static int usbvideo_StartDataPump(struct uvd *uvd) err("%s: videoStart not set", __func__); /* We double buffer the Iso lists */ - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { int j, k; struct urb *urb = uvd->sbuf[i].urb; urb->dev = dev; @@ -1797,14 +1792,14 @@ static int usbvideo_StartDataPump(struct uvd *uvd) urb->complete = usbvideo_IsocIrq; urb->number_of_packets = FRAMES_PER_DESC; urb->transfer_buffer_length = uvd->iso_packet_len * FRAMES_PER_DESC; - for (j=k=0; j < FRAMES_PER_DESC; j++, k += uvd->iso_packet_len) { + for (j = k = 0; j < FRAMES_PER_DESC; j++, k += uvd->iso_packet_len) { urb->iso_frame_desc[j].offset = k; urb->iso_frame_desc[j].length = uvd->iso_packet_len; } } /* Submit all URBs */ - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) { errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL); if (errFlag) err("%s: usb_submit_isoc(%d) ret %d", __func__, i, errFlag); @@ -1839,9 +1834,8 @@ static void usbvideo_StopDataPump(struct uvd *uvd) dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, uvd); /* Unschedule all of the iso td's */ - for (i=0; i < USBVIDEO_NUMSBUF; i++) { + for (i = 0; i < USBVIDEO_NUMSBUF; i++) usb_kill_urb(uvd->sbuf[i].urb); - } if (uvd->debug > 1) dev_info(&uvd->dev->dev, "%s: streaming=0\n", __func__); uvd->streaming = 0; @@ -1995,7 +1989,7 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum) case FrameState_Error: { int ntries, signalPending; - redo: +redo: if (!CAMERA_IS_OPERATIONAL(uvd)) { if (uvd->debug >= 2) dev_info(&uvd->dev->dev, @@ -2133,8 +2127,7 @@ void usbvideo_DeinterlaceFrame(struct uvd *uvd, struct usbvideo_frame *frame) return; if ((frame->deinterlace == Deinterlace_FillEvenLines) || - (frame->deinterlace == Deinterlace_FillOddLines)) - { + (frame->deinterlace == Deinterlace_FillOddLines)) { const int v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL; int i = (frame->deinterlace == Deinterlace_FillEvenLines) ? 0 : 1; @@ -2160,8 +2153,7 @@ void usbvideo_DeinterlaceFrame(struct uvd *uvd, struct usbvideo_frame *frame) /* Sanity check */ if ((ip < 0) || (in < 0) || (ip >= VIDEOSIZE_Y(frame->request)) || - (in >= VIDEOSIZE_Y(frame->request))) - { + (in >= VIDEOSIZE_Y(frame->request))) { err("Error: ip=%d. in=%d. req.height=%ld.", ip, in, VIDEOSIZE_Y(frame->request)); break; @@ -2173,7 +2165,7 @@ void usbvideo_DeinterlaceFrame(struct uvd *uvd, struct usbvideo_frame *frame) fd = frame->data + (v4l_linesize * i); /* Average lines around destination */ - for (j=0; j < v4l_linesize; j++) { + for (j = 0; j < v4l_linesize; j++) { fd[j] = (unsigned char)((((unsigned) fs1[j]) + ((unsigned)fs2[j])) >> 1); } @@ -2215,9 +2207,9 @@ static void usbvideo_SoftwareContrastAdjustment(struct uvd *uvd, return; } v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL; - for (i=0; i < VIDEOSIZE_Y(frame->request); i++) { + for (i = 0; i < VIDEOSIZE_Y(frame->request); i++) { unsigned char *fd = frame->data + (v4l_linesize * i); - for (j=0; j < v4l_linesize; j++) { + for (j = 0; j < v4l_linesize; j++) { signed long v = (signed long) fd[j]; /* Magnify up to 2 times, reduce down to zero */ v = 128 + ((ccm + adj) * (v - 128)) / ccm; diff --git a/drivers/staging/usbvideo/vicam.c b/drivers/staging/usbvideo/vicam.c index ecdb121..38a373a 100644 --- a/drivers/staging/usbvideo/vicam.c +++ b/drivers/staging/usbvideo/vicam.c @@ -48,13 +48,13 @@ #include <linux/ihex.h> #include "usbvideo.h" -// #define VICAM_DEBUG +/* #define VICAM_DEBUG */ #ifdef VICAM_DEBUG -#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 ADBG(lineno, fmt, args...) printk(fmt, jiffies, __func__, lineno, ##args) +#define DBG(fmt, args...) ADBG((__LINE__), KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt, ##args) #else -#define DBG(fmn,args...) do {} while(0) +#define DBG(fmn, args...) do {} while (0) #endif #define DRIVER_AUTHOR "Joe Burks, jburks@wavicle.org" @@ -118,15 +118,15 @@ static void rvfree(void *mem, unsigned long size) } struct vicam_camera { - u16 shutter_speed; // capture shutter speed - u16 gain; // capture gain + u16 shutter_speed; /* capture shutter speed */ + u16 gain; /* capture gain */ - u8 *raw_image; // raw data captured from the camera - u8 *framebuf; // processed data in RGB24 format - u8 *cntrlbuf; // area used to send control msgs + u8 *raw_image; /* raw data captured from the camera */ + u8 *framebuf; /* processed data in RGB24 format */ + u8 *cntrlbuf; /* area used to send control msgs */ - struct video_device vdev; // v4l video device - struct usb_device *udev; // usb device + struct video_device vdev; /* v4l video device */ + struct usb_device *udev; /* usb device */ /* guard against simultaneous accesses to the camera */ struct mutex cam_lock; @@ -137,7 +137,7 @@ struct vicam_camera { 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 read_frame(struct vicam_camera *cam, int framenum); static void vicam_decode_color(const u8 *, u8 *); @@ -219,12 +219,12 @@ set_camera_power(struct vicam_camera *cam, int state) { 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; - if (state) { + if (state) send_control_msg(cam, 0x55, 1, 0, NULL, 0); - } return 0; } @@ -307,11 +307,11 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) { struct video_picture vp; DBG("VIDIOCGPICT\n"); - memset(&vp, 0, sizeof (struct video_picture)); + memset(&vp, 0, sizeof(struct video_picture)); vp.brightness = cam->gain << 8; vp.depth = 24; 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; break; } @@ -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))) retval = -EFAULT; - // 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. + /* 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. */ break; } @@ -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); - if ( vw.width != 320 || vw.height != 240 ) + if (vw.width != 320 || vw.height != 240) retval = -EFAULT; break; @@ -385,7 +385,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) int i; DBG("VIDIOCGMBUF\n"); - memset(&vm, 0, sizeof (vm)); + memset(&vm, 0, sizeof(vm)); vm.size = VICAM_MAX_FRAME_SIZE * VICAM_FRAMES; vm.frames = VICAM_FRAMES; @@ -401,23 +401,24 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) case VIDIOCMCAPTURE: { struct video_mmap vm; - // int video_size; + /* int video_size; */ if (copy_from_user((void *)&vm, user_arg, sizeof(vm))) { retval = -EFAULT; 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; - // in theory right here we'd start the image capturing - // (fill in a bulk urb and submit it asynchronously) - // - // Instead we're going to do a total hack job for now and - // retrieve the frame in VIDIOCSYNC + /* in theory right here we'd start the image capturing + * (fill in a bulk urb and submit it asynchronously) + * + * Instead we're going to do a total hack job for now and + * retrieve the frame in VIDIOCSYNC */ break; } @@ -435,7 +436,7 @@ vicam_ioctl(struct file *file, unsigned int ioctlnr, unsigned long arg) read_frame(cam, frame); vicam_decode_color(cam->raw_image, cam->framebuf + - frame * VICAM_MAX_FRAME_SIZE ); + frame * VICAM_MAX_FRAME_SIZE); break; } @@ -522,7 +523,7 @@ vicam_open(struct file *file) 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) { initialize_camera(cam); @@ -562,9 +563,8 @@ vicam_close(struct file *file) mutex_unlock(&cam->cam_lock); - if (!open_count && !udev) { + if (!open_count && !udev) kfree(cam); - } return 0; } @@ -582,57 +582,55 @@ static void vicam_decode_color(const u8 *data, u8 *rgb) data += VICAM_HEADER_SIZE; - for( i = 0; i < 240; i++, data += 512 ) { - const int y = ( i * 242 ) / 240; + for (i = 0; i < 240; i++, data += 512) { + const int y = (i * 242) / 240; int j, prevX, nextX; int Y, Cr, Cb; - if ( y == 242 - 1 ) { + if (y == 242 - 1) nextY = -512; - } prevX = 1; nextX = 1; - for ( j = 0; j < 320; j++, rgb += 3 ) { - const int x = ( j * 512 ) / 320; + for (j = 0; j < 320; j++, rgb += 3) { + const int x = (j * 512) / 320; const u8 * const src = &data[x]; - if ( x == 512 - 1 ) { + if (x == 512 - 1) nextX = -1; - } - Cr = ( src[prevX] - src[0] ) + - ( src[nextX] - src[0] ); + Cr = (src[prevX] - src[0]) + + (src[nextX] - src[0]); Cr /= 2; - Cb = ( src[prevY] - src[prevX + prevY] ) + - ( src[prevY] - src[nextX + prevY] ) + - ( src[nextY] - src[prevX + nextY] ) + - ( src[nextY] - src[nextX + nextY] ); + Cb = (src[prevY] - src[prevX + prevY]) + + (src[prevY] - src[nextX + prevY]) + + (src[nextY] - src[prevX + nextY]) + + (src[nextY] - src[nextX + nextY]); 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; Cr = Cb; Cb = Ct; } - if ( ( x ^ i ) & 1 ) { + if ((x ^ i) & 1) { Cr = -Cr; Cb = -Cb; } - rgb[0] = clamp( ( ( Y + ( 2017 * Cb ) ) + - 500 ) / 900, 0, 255 ); - rgb[1] = clamp( ( ( Y - ( 392 * Cb ) - - ( 813 * Cr ) ) + - 500 ) / 1000, 0, 255 ); - rgb[2] = clamp( ( ( Y + ( 1594 * Cr ) ) + - 500 ) / 1300, 0, 255 ); + rgb[0] = clamp(((Y + (2017 * Cb)) + + 500) / 900, 0, 255); + rgb[1] = clamp(((Y - (392 * Cb) - + (813 * Cr)) + + 500) / 1000, 0, 255); + rgb[2] = clamp(((Y + (1594 * Cr)) + + 500) / 1300, 0, 255); prevX = -1; } @@ -655,15 +653,15 @@ read_frame(struct vicam_camera *cam, int framenum) } 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[3] = 0x07; // is not yet understood + request[2] = 0x90; /* the function of these two bytes */ + request[3] = 0x07; /* is not yet understood */ if (cam->shutter_speed > 60) { - // Short exposure + /* Short exposure */ realShutter = ((-15631900 / cam->shutter_speed) + 260533) / 1000; request[4] = realShutter & 0xFF; @@ -671,7 +669,7 @@ read_frame(struct vicam_camera *cam, int framenum) request[6] = 0x03; request[7] = 0x01; } else { - // Long exposure + /* Long exposure */ realShutter = 15600 / cam->shutter_speed - 1; request[4] = 0; request[5] = 0; @@ -679,15 +677,14 @@ read_frame(struct vicam_camera *cam, int framenum) 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; - // 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); - if (!cam->udev) { + if (!cam->udev) goto done; - } n = __send_control_msg(cam, 0x51, 0x80, 0, request, 16); @@ -712,7 +709,7 @@ read_frame(struct vicam_camera *cam, int framenum) } 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; @@ -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); - if (copy_to_user(buf, &cam->framebuf[*ppos], count)) { + if (copy_to_user(buf, &cam->framebuf[*ppos], count)) count = -EFAULT; - } else { + else *ppos += count; - } - if (count == VICAM_MAX_FRAME_SIZE) { + if (count == VICAM_MAX_FRAME_SIZE) *ppos = 0; - } return count; } @@ -749,7 +744,7 @@ vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos ) static int 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 start = vma->vm_start; unsigned long size = vma->vm_end-vma->vm_start; @@ -793,9 +788,9 @@ static const struct v4l2_file_operations vicam_fops = { }; static struct video_device vicam_template = { - .name = "ViCam-based USB Camera", - .fops = &vicam_fops, - .release = video_device_release_empty, + .name = "ViCam-based USB Camera", + .fops = &vicam_fops, + .release = video_device_release_empty, }; /* table of devices that work with this driver */ @@ -823,7 +818,7 @@ static struct usb_driver vicam_driver = { * this driver might be interested in. */ 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); int bulkEndpoint = 0; @@ -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"); } - if ((cam = - kzalloc(sizeof (struct vicam_camera), GFP_KERNEL)) == NULL) { + cam = kzalloc(sizeof(struct vicam_camera), GFP_KERNEL); + if (cam == NULL) { printk(KERN_WARNING "could not allocate kernel memory for vicam_camera struct\n"); return -ENOMEM; @@ -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", video_device_node_name(&cam->vdev)); - usb_set_intfdata (intf, cam); + usb_set_intfdata(intf, cam); return 0; } @@ -883,8 +878,8 @@ static void vicam_disconnect(struct usb_interface *intf) { int open_count; - struct vicam_camera *cam = usb_get_intfdata (intf); - usb_set_intfdata (intf, NULL); + struct vicam_camera *cam = usb_get_intfdata(intf); + usb_set_intfdata(intf, NULL); /* we must unregister the device before taking its * cam_lock. This is because the video open call @@ -914,9 +909,8 @@ vicam_disconnect(struct usb_interface *intf) mutex_unlock(&cam->cam_lock); - if (!open_count) { + if (!open_count) kfree(cam); - } printk(KERN_DEBUG "ViCam-based WebCam disconnected\n"); } |