#include <linux/init.h>
#include <linux/spinlock.h>
-#include <asm/io.h>
+#include <linux/io.h>
#include "usbvideo.h"
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;
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);
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);
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;
}
{
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;
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))) {
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);
}
}
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;
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);
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;
*/
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) {
return;
}
- usb_set_intfdata (intf, NULL);
+ usb_set_intfdata(intf, NULL);
usbvideo_ClientIncModCount(uvd);
if (uvd->debug > 0)
/* 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)
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;
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,
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);
goto allocate_done;
}
}
- uvd->user=0;
+ uvd->user = 0;
uvd->remove_pending = 0;
uvd->last_error = 0;
RingQueue_Initialize(&uvd->dp);
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 */
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);
/*
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;
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;
}
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;
}
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;
/*
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;
return 0;
}
- case VIDIOCGWIN:
+ case VIDIOCGWIN:
{
struct video_window *vw = arg;
vw->flags = 10; /* FIXME: do better! */
return 0;
}
- case VIDIOCGMBUF:
+ case VIDIOCGMBUF:
{
struct video_mbuf *vm = arg;
int i;
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;
return usbvideo_NewFrame(uvd, vm->frame);
}
- case VIDIOCSYNC:
+ case VIDIOCSYNC:
{
int *frameNum = arg;
int ret;
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;
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;
}
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)) {
* 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;
/* 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);
}
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;
}
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;
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);
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;
case FrameState_Error:
{
int ntries, signalPending;
- redo:
+redo:
if (!CAMERA_IS_OPERATIONAL(uvd)) {
if (uvd->debug >= 2)
dev_info(&uvd->dev->dev,
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;
/* 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;
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);
}
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;