[media] usbvision: coding style

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil
2010-12-29 13:53:21 -03:00
committed by Mauro Carvalho Chehab
parent 52cb0bf275
commit 6d6a48e51f
5 changed files with 557 additions and 686 deletions

View File

@@ -33,7 +33,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <asm/io.h>
#include <linux/io.h>
#include <linux/videodev2.h>
#include <linux/i2c.h>
@@ -85,12 +85,12 @@ MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]");
#define PDEBUG(level, fmt, args...) do {} while (0)
#endif
#define DBG_HEADER 1<<0
#define DBG_IRQ 1<<1
#define DBG_ISOC 1<<2
#define DBG_PARSE 1<<3
#define DBG_SCRATCH 1<<4
#define DBG_FUNC 1<<5
#define DBG_HEADER (1 << 0)
#define DBG_IRQ (1 << 1)
#define DBG_ISOC (1 << 2)
#define DBG_PARSE (1 << 3)
#define DBG_SCRATCH (1 << 4)
#define DBG_FUNC (1 << 5)
static const int max_imgwidth = MAX_FRAME_WIDTH;
static const int max_imgheight = MAX_FRAME_HEIGHT;
@@ -176,7 +176,7 @@ static void usbvision_hexdump(const unsigned char *data, int len)
k += sprintf(&tmp[k], "%02x ", data[i]);
}
if (k > 0)
printk("%s\n", tmp);
printk(KERN_CONT "%s\n", tmp);
}
#endif
@@ -186,9 +186,9 @@ static void usbvision_hexdump(const unsigned char *data, int len)
static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */
{
int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
if (len < 0) {
if (len < 0)
len += scratch_buf_size;
}
PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len);
return len;
@@ -199,9 +199,8 @@ static int scratch_len(struct usb_usbvision *usbvision) /* This returns the a
static int scratch_free(struct usb_usbvision *usbvision)
{
int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
if (free <= 0) {
if (free <= 0)
free += scratch_buf_size;
}
if (free) {
free -= 1; /* at least one byte in the buffer must */
/* left blank, otherwise there is no chance to differ between full and empty */
@@ -221,14 +220,12 @@ static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
usbvision->scratch_write_ptr += len;
}
else {
} else {
len_part = scratch_buf_size - usbvision->scratch_write_ptr;
memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part);
if (len == len_part) {
usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */
}
else {
} else {
memcpy(usbvision->scratch, data + len_part, len - len_part);
usbvision->scratch_write_ptr = len - len_part;
}
@@ -255,17 +252,16 @@ static int scratch_get_extra(struct usb_usbvision *usbvision,
unsigned char *data, int *ptr, int len)
{
int len_part;
if (*ptr + len < scratch_buf_size) {
memcpy(data, usbvision->scratch + *ptr, len);
*ptr += len;
}
else {
} else {
len_part = scratch_buf_size - *ptr;
memcpy(data, usbvision->scratch + *ptr, len_part);
if (len == len_part) {
*ptr = 0; /* just set the y_ptr to zero */
}
else {
} else {
memcpy(data + len_part, usbvision->scratch, len - len_part);
*ptr = len - len_part;
}
@@ -301,17 +297,16 @@ static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
int len)
{
int len_part;
if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
usbvision->scratch_read_ptr += len;
}
else {
} else {
len_part = scratch_buf_size - usbvision->scratch_read_ptr;
memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part);
if (len == len_part) {
usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */
}
else {
} else {
memcpy(data + len_part, usbvision->scratch, len - len_part);
usbvision->scratch_read_ptr = len - len_part;
}
@@ -355,7 +350,6 @@ static int scratch_get_header(struct usb_usbvision *usbvision,
/* This removes len bytes of old data from the buffer */
static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
{
usbvision->scratch_read_ptr += len;
usbvision->scratch_read_ptr %= scratch_buf_size;
PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr);
@@ -391,7 +385,6 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
{
vfree(usbvision->scratch);
usbvision->scratch = NULL;
}
/*
@@ -476,7 +469,6 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
frame->grabstate = frame_state_done;
frame->scanlength += scan_length;
++num_pass;
}
/*
@@ -487,6 +479,7 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
{
int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
if (usbvision->intra_frame_buffer == NULL) {
dev_err(&usbvision->dev->dev,
@@ -545,8 +538,7 @@ static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
usbvision_unrequest_intra(usbvision);
break;
}
}
else {
} else {
found_header = 1;
break;
}
@@ -556,8 +548,7 @@ static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width;
frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height;
frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3;
}
else { /* no header found */
} else { /* no header found */
PDEBUG(DBG_HEADER, "skipping scratch data, no header");
scratch_reset(usbvision);
return parse_state_end_parse;
@@ -609,9 +600,8 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
return parse_state_out;
}
if ((frame->curline + 1) >= frame->frmheight) {
if ((frame->curline + 1) >= frame->frmheight)
return parse_state_next_frame;
}
bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
@@ -619,15 +609,12 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
clipmask_add = usbvision->stretch_width;
for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
scratch_get(usbvision, &yuyv[0], 4);
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f++ = yuyv[0]; /* Y */
*f++ = yuyv[3]; /* U */
}
else {
} else {
YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
switch (frame->v4l2_format.format) {
case V4L2_PIX_FMT_RGB565:
@@ -661,9 +648,7 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f++ = yuyv[2]; /* Y */
*f++ = yuyv[1]; /* V */
}
else {
} else {
YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
switch (frame->v4l2_format.format) {
case V4L2_PIX_FMT_RGB565:
@@ -698,13 +683,10 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
frame->curline += usbvision->stretch_height;
*pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
if (frame->curline >= frame->frmheight) {
if (frame->curline >= frame->frmheight)
return parse_state_next_frame;
}
else {
return parse_state_continue;
}
}
/* The decompression routine */
static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed,
@@ -728,7 +710,6 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
rest_pixel = len;
for (idx = 0; idx < len; idx++) {
if (block_len == 0) {
if (block_type_len == 0) {
block_type_byte = compressed[block_type_pos];
@@ -753,11 +734,10 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
} else {
block_code = compressed[pos];
pos++;
if (rest_pixel >= 24) {
if (rest_pixel >= 24)
block_len = 24;
} else {
else
block_len = rest_pixel;
}
rest_pixel -= block_len;
extra_pos = pos + (block_len / 4);
}
@@ -769,9 +749,8 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
block_byte = compressed[pos];
pos++;
}
if (block_type == 1) { /* inter Block */
if (block_type == 1) /* inter Block */
integrator = decompressed[idx];
}
switch (block_byte & 0xC0) {
case 0x03 << 6:
integrator += compressed[extra_pos];
@@ -814,7 +793,7 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
unsigned char *f, *u = NULL, *v = NULL;
unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
int idx, idx_end, strip_len, strip_ptr, Startblock_pos, block_pos, block_type_pos;
int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
int clipmask_index, bytes_per_pixel, rc;
int image_size;
unsigned char rv, gv, bv;
@@ -831,25 +810,20 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
/* get base of u and b planes add halfoffset */
u = frame->data
+ image_size
+ (frame->frmwidth >> 1) * frame->curline;
v = u + (image_size >> 1);
} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2);
u = v + (image_size >> 2);
}
if (frame->curline == 0) {
if (frame->curline == 0)
usbvision_adjust_compression(usbvision);
}
if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) {
if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN)
return parse_state_out;
}
/* get strip header without changing the scratch_read_ptr */
scratch_set_extra_ptr(usbvision, &strip_ptr, 0);
@@ -863,7 +837,7 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
}
if (frame->curline != (int)strip_header[2]) {
/* line number missmatch error */
/* line number mismatch error */
usbvision->strip_line_number_errors++;
}
@@ -883,8 +857,7 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline;
U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2);
V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2);
}
else {
} else {
return parse_state_next_frame;
}
@@ -895,61 +868,44 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
idx_end = frame->frmwidth;
block_type_pos = USBVISION_STRIP_HEADER_LEN;
Startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2;
block_pos = Startblock_pos;
startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2;
block_pos = startblock_pos;
usbvision->block_pos = block_pos;
if ((rc = usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end)) != idx_end) {
/* return parse_state_continue; */
}
if (strip_len > usbvision->max_strip_len) {
rc = usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end);
if (strip_len > usbvision->max_strip_len)
usbvision->max_strip_len = strip_len;
}
if (frame->curline%2) {
if ((rc = usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end/2)) != idx_end/2) {
/* return parse_state_continue; */
}
}
else {
if ((rc = usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end/2)) != idx_end/2) {
/* return parse_state_continue; */
}
}
if (frame->curline % 2)
rc = usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2);
else
rc = usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2);
if (block_pos > usbvision->comprblock_pos) {
if (block_pos > usbvision->comprblock_pos)
usbvision->comprblock_pos = block_pos;
}
if (block_pos > strip_len) {
if (block_pos > strip_len)
usbvision->strip_len_errors++;
}
for (idx = 0; idx < idx_end; idx++) {
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f++ = Y[idx];
*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
}
else if(frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
*f++ = Y[idx];
if (idx & 0x01)
*u++ = U[idx >> 1];
else
*v++ = V[idx >> 1];
}
else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
*f++ = Y[idx];
if (!((idx & 0x01) | (frame->curline & 0x01))) {
/* only need do this for 1 in 4 pixels */
/* intraframe buffer is YUV420 format */
*u++ = U[idx >> 1];
*v++ = V[idx >> 1];
}
}
else {
} else {
YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
switch (frame->v4l2_format.format) {
case V4L2_PIX_FMT_GREY:
@@ -990,12 +946,9 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
frame->curline += 1;
if (frame->curline >= frame->frmheight) {
if (frame->curline >= frame->frmheight)
return parse_state_next_frame;
}
else {
return parse_state_continue;
}
}
@@ -1047,9 +1000,8 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
return parse_state_out;
}
if ((frame->curline + 1) >= frame->frmheight) {
if ((frame->curline + 1) >= frame->frmheight)
return parse_state_next_frame;
}
block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */
@@ -1061,10 +1013,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
+ (4 - block_split) * sub_block_size);
for (block = 0; block < (pixel_per_line / sub_block_size);
block++) {
for (block = 0; block < (pixel_per_line / sub_block_size); block++) {
for (pixel = 0; pixel < sub_block_size; pixel += 2) {
scratch_get(usbvision, &y[0], 2);
scratch_get_extra(usbvision, &u, &u_ptr, 1);
@@ -1080,8 +1029,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f_even++ = y[0];
*f_even++ = v;
}
else {
} else {
y_ = 76284 * (y[0] - 16);
b_ = (y_ + vb) >> 16;
@@ -1124,8 +1072,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f_even++ = y[1];
*f_even++ = u;
}
else {
} else {
y_ = 76284 * (y[1] - 16);
b_ = (y_ + vb) >> 16;
@@ -1170,8 +1117,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f_odd++ = y[0];
*f_odd++ = v;
}
else {
} else {
y_ = 76284 * (y[0] - 16);
b_ = (y_ + vb) >> 16;
@@ -1214,8 +1160,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
*f_odd++ = y[1];
*f_odd++ = u;
}
else {
} else {
y_ = 76284 * (y[1] - 16);
b_ = (y_ + vb) >> 16;
@@ -1273,7 +1218,6 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
if (frame->curline >= frame->frmheight)
return parse_state_next_frame;
else
return parse_state_continue;
}
@@ -1297,35 +1241,25 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
while (1) {
newstate = parse_state_out;
if (scratch_len(usbvision)) {
if (frame->scanstate == scan_state_scanning) {
newstate = usbvision_find_header(usbvision);
}
else if (frame->scanstate == scan_state_lines) {
if (usbvision->isoc_mode == ISOC_MODE_YUV420) {
} else if (frame->scanstate == scan_state_lines) {
if (usbvision->isoc_mode == ISOC_MODE_YUV420)
newstate = usbvision_parse_lines_420(usbvision, &copylen);
}
else if (usbvision->isoc_mode == ISOC_MODE_YUV422) {
else if (usbvision->isoc_mode == ISOC_MODE_YUV422)
newstate = usbvision_parse_lines_422(usbvision, &copylen);
}
else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
newstate = usbvision_parse_compress(usbvision, &copylen);
}
}
}
if (newstate == parse_state_continue) {
if (newstate == parse_state_continue)
continue;
}
else if ((newstate == parse_state_next_frame) || (newstate == parse_state_out)) {
if ((newstate == parse_state_next_frame) || (newstate == parse_state_out))
break;
}
else {
return; /* parse_state_end_parse */
}
}
if (newstate == parse_state_next_frame) {
frame->grabstate = frame_state_done;
@@ -1344,10 +1278,9 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
PDEBUG(DBG_PARSE, "Wake up !");
wake_up_interruptible(&usbvision->wait_frame);
}
}
else
} else {
frame->grabstate = frame_state_grabbing;
}
/* Update the frame's uncompressed length. */
frame->scanlength += copylen;
@@ -1381,14 +1314,12 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
PDEBUG(DBG_ISOC, "error packet [%d]", i);
usbvision->isoc_skip_count++;
continue;
}
else if (packet_len == 0) { /* Frame end ????? */
} else if (packet_len == 0) { /* Frame end ????? */
PDEBUG(DBG_ISOC, "null packet [%d]", i);
usbvision->isocstate = isoc_state_no_frame;
usbvision->isoc_skip_count++;
continue;
}
else if (packet_len > usbvision->isoc_packet_size) {
} else if (packet_len > usbvision->isoc_packet_size) {
PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i);
usbvision->isoc_skip_count++;
continue;
@@ -1412,7 +1343,6 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
* your favorite evil here.
*/
if (scratch_free(usbvision) < packet_len) {
usbvision->scratch_ovf_count++;
PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d",
scratch_len(usbvision), packet_len);
@@ -1428,6 +1358,7 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
#if ENABLE_HEXDUMP
if (totlen > 0) {
static int foo;
if (foo < 1) {
printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
@@ -1452,9 +1383,8 @@ static void usbvision_isoc_irq(struct urb *urb)
return;
/* any urb with wrong status is ignored without acknowledgement */
if (urb->status == -ENOENT) {
if (urb->status == -ENOENT)
return;
}
f = &usbvision->cur_frame;
@@ -1476,26 +1406,23 @@ static void usbvision_isoc_irq(struct urb *urb)
usbvision->urb_length = len;
if (usbvision->streaming == stream_on) {
/* If we collected enough data let's parse! */
if ((scratch_len(usbvision) > USBVISION_HEADER_LENGTH) &&
(!list_empty(&(usbvision->inqueue))) ) {
if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH &&
!list_empty(&(usbvision->inqueue))) {
if (!(*f)) {
(*f) = list_entry(usbvision->inqueue.next,
struct usbvision_frame,
frame);
}
usbvision_parse_data(usbvision);
}
else {
} else {
/* If we don't have a frame
we're current working on, complain */
PDEBUG(DBG_IRQ,
"received data, but no one needs it");
scratch_reset(usbvision);
}
}
else {
} else {
PDEBUG(DBG_IRQ, "received data, but no one needs it");
scratch_reset(usbvision);
}
@@ -1587,10 +1514,9 @@ static void usbvision_ctrl_urb_complete(struct urb *urb)
PDEBUG(DBG_IRQ, "");
usbvision->ctrl_urb_busy = 0;
if (waitqueue_active(&usbvision->ctrl_urb_wq)) {
if (waitqueue_active(&usbvision->ctrl_urb_wq))
wake_up_interruptible(&usbvision->ctrl_urb_wq);
}
}
static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address,
@@ -1599,12 +1525,10 @@ static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address,
int err_code = 0;
PDEBUG(DBG_IRQ, "");
if (len > 8) {
if (len > 8)
return -EFAULT;
}
if (usbvision->ctrl_urb_busy) {
if (usbvision->ctrl_urb_busy)
return -EBUSY;
}
usbvision->ctrl_urb_busy = 1;
usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
@@ -1682,26 +1606,26 @@ static int usbvision_adjust_compression (struct usb_usbvision *usbvision)
usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2;
RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100);
if (usbvision->compr_level != usbvision->last_compr_level) {
int distorsion;
int distortion;
if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) {
buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */
buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */
distorsion = 7 + 248 * usbvision->compr_level / 100;
buffer[2] = (unsigned char)(distorsion & 0xFF); /* Average distorsion Threshold (inter) */
buffer[3] = (unsigned char)(distorsion & 0xFF); /* Average distorsion Threshold (intra) */
distorsion = 1 + 42 * usbvision->compr_level / 100;
buffer[4] = (unsigned char)(distorsion & 0xFF); /* Maximum distorsion Threshold (inter) */
buffer[5] = (unsigned char)(distorsion & 0xFF); /* Maximum distorsion Threshold (intra) */
}
else { /* BRIDGE_NT1003 */
distortion = 7 + 248 * usbvision->compr_level / 100;
buffer[2] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (inter) */
buffer[3] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (intra) */
distortion = 1 + 42 * usbvision->compr_level / 100;
buffer[4] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (inter) */
buffer[5] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (intra) */
} else { /* BRIDGE_NT1003 */
buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */
buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */
distorsion = 2 + 253 * usbvision->compr_level / 100;
buffer[2] = (unsigned char)(distorsion & 0xFF); /* distorsion threshold bit0-7 */
buffer[3] = 0; /* (unsigned char)((distorsion >> 8) & 0x0F); distorsion threshold bit 8-11 */
distorsion = 0 + 43 * usbvision->compr_level / 100;
buffer[4] = (unsigned char)(distorsion & 0xFF); /* maximum distorsion bit0-7 */
buffer[5] = 0; /* (unsigned char)((distorsion >> 8) & 0x01); maximum distorsion bit 8 */
distortion = 2 + 253 * usbvision->compr_level / 100;
buffer[2] = (unsigned char)(distortion & 0xFF); /* distortion threshold bit0-7 */
buffer[3] = 0; /* (unsigned char)((distortion >> 8) & 0x0F); distortion threshold bit 8-11 */
distortion = 0 + 43 * usbvision->compr_level / 100;
buffer[4] = (unsigned char)(distortion & 0xFF); /* maximum distortion bit0-7 */
buffer[5] = 0; /* (unsigned char)((distortion >> 8) & 0x01); maximum distortion bit 8 */
}
err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
if (err_code == 0) {
@@ -1749,9 +1673,8 @@ int usbvision_power_off(struct usb_usbvision *usbvision)
PDEBUG(DBG_FUNC, "");
err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
if (err_code == 1) {
if (err_code == 1)
usbvision->power = 0;
}
PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code);
return err_code;
}
@@ -1807,15 +1730,13 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
unsigned int frame_rate = 0, frame_drop = 0;
unsigned char value[4];
if (!USBVISION_IS_OPERATIONAL(usbvision)) {
if (!USBVISION_IS_OPERATIONAL(usbvision))
return 0;
}
if (width > MAX_USB_WIDTH) {
usb_width = width / 2;
usbvision->stretch_width = 2;
}
else {
} else {
usb_width = width;
usbvision->stretch_width = 1;
}
@@ -1823,8 +1744,7 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
if (height > MAX_USB_HEIGHT) {
usb_height = height / 2;
usbvision->stretch_height = 2;
}
else {
} else {
usb_height = height;
usbvision->stretch_height = 1;
}
@@ -1859,22 +1779,17 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
usbvision->curheight = usbvision->stretch_height * usb_height;
}
if (usbvision->isoc_mode == ISOC_MODE_YUV422) {
if (usbvision->isoc_mode == ISOC_MODE_YUV422)
frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2);
}
else if (usbvision->isoc_mode == ISOC_MODE_YUV420) {
else if (usbvision->isoc_mode == ISOC_MODE_YUV420)
frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8);
}
else {
else
frame_rate = FRAMERATE_MAX;
}
if (usbvision->tvnorm_id & V4L2_STD_625_50) {
if (usbvision->tvnorm_id & V4L2_STD_625_50)
frame_drop = frame_rate * 32 / 25 - 1;
}
else if (usbvision->tvnorm_id & V4L2_STD_525_60) {
else if (usbvision->tvnorm_id & V4L2_STD_525_60)
frame_drop = frame_rate * 32 / 30 - 1;
}
RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX);
@@ -1912,9 +1827,9 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
usbvision->num_frames = number_of_frames;
while (usbvision->num_frames > 0) {
usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) {
usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
if (usbvision->fbuf)
break;
}
usbvision->num_frames--;
}
@@ -1937,7 +1852,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
usbvision->frame[i].height = usbvision->curheight;
usbvision->frame[i].bytes_read = 0;
}
PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size);
PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",
usbvision->num_frames, usbvision->max_frame_size);
return usbvision->num_frames;
}
@@ -2033,18 +1949,17 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
if (usbvision->bridge_type == BRIDGE_NT1004) {
value[0] = 20; /* PCM Threshold 1 */
value[1] = 12; /* PCM Threshold 2 */
value[2] = 255; /* Distorsion Threshold inter */
value[3] = 255; /* Distorsion Threshold intra */
value[4] = 43; /* Max Distorsion inter */
value[5] = 43; /* Max Distorsion intra */
}
else {
value[2] = 255; /* Distortion Threshold inter */
value[3] = 255; /* Distortion Threshold intra */
value[4] = 43; /* Max Distortion inter */
value[5] = 43; /* Max Distortion intra */
} else {
value[0] = 20; /* PCM Threshold 1 */
value[1] = 12; /* PCM Threshold 2 */
value[2] = 255; /* Distorsion Threshold d7-d0 */
value[3] = 0; /* Distorsion Threshold d11-d8 */
value[4] = 43; /* Max Distorsion d7-d0 */
value[5] = 0; /* Max Distorsion d8 */
value[2] = 255; /* Distortion Threshold d7-d0 */
value[3] = 0; /* Distortion Threshold d11-d8 */
value[4] = 43; /* Max Distortion d7-d0 */
value[5] = 0; /* Max Distortion d8 */
}
if (!USBVISION_IS_OPERATIONAL(usbvision))
@@ -2059,10 +1974,7 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
if (rc < 0) {
printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
"reconnect or reload driver.\n", proc, rc);
return rc;
}
return rc;
}
@@ -2169,13 +2081,12 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) {
dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv;
}
else if(usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
} else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
/* This changes as the fine sync control changes. Further investigation necessary */
dvi_yuv_value = 0x06;
}
return (usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value));
return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value);
}
@@ -2204,8 +2115,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
/* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */
/* FDL: 0x00000-0x0E099 = 57498 Words */
/* VDW: 0x0E3FF-0x3FFFF */
}
else {
} else {
value[0] = 0x42;
value[1] = 0x00;
value[2] = 0xff;
@@ -2243,8 +2153,9 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
}
/* Restart the video buffer logic */
if ((rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
USBVISION_RES_FDL | USBVISION_RES_VDW)) < 0)
rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
USBVISION_RES_FDL | USBVISION_RES_VDW);
if (rc < 0)
return rc;
rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
@@ -2273,9 +2184,8 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
USBVISION_SSPND_EN | USBVISION_PWR_VID);
err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2);
if (err_code == 1) {
if (err_code == 1)
usbvision->power = 1;
}
PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code);
return err_code;
}
@@ -2327,10 +2237,9 @@ void usbvision_set_power_off_timer(struct usb_usbvision *usbvision)
void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
{
if (timer_pending(&usbvision->power_off_timer)) {
if (timer_pending(&usbvision->power_off_timer))
del_timer(&usbvision->power_off_timer);
}
}
/*
* usbvision_begin_streaming()
@@ -2339,14 +2248,10 @@ void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
*/
int usbvision_begin_streaming(struct usb_usbvision *usbvision)
{
int err_code = 0;
if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
usbvision_init_compression(usbvision);
}
err_code = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, USBVISION_NOHVALID |
usbvision->vin_reg2_preset);
return err_code;
return usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
USBVISION_NOHVALID | usbvision->vin_reg2_preset);
}
/*
@@ -2358,25 +2263,24 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
{
int ret;
if (
(ret =
usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_PWR_VID)) < 0)
ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_PWR_VID);
if (ret < 0)
return ret;
if (
(ret =
usbvision_write_reg(usbvision, USBVISION_PWR_REG,
ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_PWR_VID |
USBVISION_RES2)) < 0)
USBVISION_RES2);
if (ret < 0)
return ret;
if (
(ret =
usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
USBVISION_KEEP_BLANK | USBVISION_NOHVALID |
usbvision->vin_reg2_preset)) < 0) return ret;
usbvision->vin_reg2_preset);
if (ret < 0)
return ret;
/* TODO: schedule timeout */
while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1);
while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1)
;
return 0;
}
@@ -2384,7 +2288,7 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
int usbvision_audio_off(struct usb_usbvision *usbvision)
{
if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
printk(KERN_ERR "usbvision_audio_off: can't wirte reg\n");
printk(KERN_ERR "usbvision_audio_off: can't write reg\n");
return -1;
}
usbvision->audio_mute = 0;
@@ -2429,7 +2333,8 @@ int usbvision_set_alternate(struct usb_usbvision *dev)
if (dev->iface_alt != prev_alt) {
dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt];
PDEBUG(DBG_FUNC,"setting alternate %d with max_packet_size=%u", dev->iface_alt,dev->isoc_packet_size);
PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u",
dev->iface_alt, dev->isoc_packet_size);
err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt);
if (err_code < 0) {
dev_err(&dev->dev->dev,
@@ -2563,7 +2468,6 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
usbvision->streaming = stream_off;
if (!usbvision->remove_pending) {
/* Set packet size to 0 */
usbvision->iface_alt = 0;
err_code = usb_set_interface(usbvision->dev, usbvision->iface,
@@ -2612,8 +2516,7 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
* some devices. Use switch_svideo_input
* parameter when loading the module.*/
mode[2] = SAA7115_COMPOSITE1;
}
else {
} else {
mode[2] = SAA7115_SVIDEO1;
}
break;

View File

@@ -28,14 +28,14 @@
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/usb.h>
#include <linux/i2c.h>
#include "usbvision.h"
#define DBG_I2C 1<<0
#define DBG_I2C (1 << 0)
static int i2c_debug;
@@ -143,10 +143,9 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
else
ret = try_write_address(i2c_adap, addr, retries);
if (ret != 1) {
if (ret != 1)
return -EREMOTEIO;
}
}
return 0;
}
@@ -171,17 +170,15 @@ usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
if (pmsg->flags & I2C_M_RD) {
/* read bytes into buffer */
ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len));
if (ret < pmsg->len) {
if (ret < pmsg->len)
return (ret < 0) ? ret : -EREMOTEIO;
}
} else {
/* write bytes from buffer */
ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len));
if (ret < pmsg->len) {
if (ret < pmsg->len)
return (ret < 0) ? ret : -EREMOTEIO;
}
}
}
return num;
}
@@ -355,10 +352,10 @@ usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr,
if (i2c_debug & DBG_I2C) {
int idx;
for (idx = 0; idx < len; idx++) {
for (idx = 0; idx < len; idx++)
PDEBUG(DBG_I2C, "read %x from address %x", (unsigned char)buf[idx], addr);
}
}
return len;
}
@@ -416,10 +413,10 @@ static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision,
if (i2c_debug & DBG_I2C) {
int idx;
for (idx = 0; idx < len; idx++) {
for (idx = 0; idx < len; idx++)
PDEBUG(DBG_I2C, "wrote %x at address %x", (unsigned char)buf[idx], addr);
}
}
return len;
}

View File

@@ -56,7 +56,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <asm/io.h>
#include <linux/io.h>
#include <linux/videodev2.h>
#include <linux/i2c.h>
@@ -99,9 +99,9 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
#define PDEBUG(level, fmt, args...) do {} while (0)
#endif
#define DBG_IO 1<<1
#define DBG_PROBE 1<<2
#define DBG_MMAP 1<<3
#define DBG_IO (1 << 1)
#define DBG_PROBE (1 << 2)
#define DBG_MMAP (1 << 3)
/* String operations */
#define rmspace(str) while (*str == ' ') str++;
@@ -291,6 +291,7 @@ static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
static void usbvision_create_sysfs(struct video_device *vdev)
{
int res;
if (!vdev)
return;
do {
@@ -531,11 +532,11 @@ static int vidioc_enum_input (struct file *file, void *priv,
if (vi->index >= usbvision->video_inputs)
return -EINVAL;
if (usbvision->have_tuner) {
if (usbvision->have_tuner)
chan = vi->index;
} else {
else
chan = vi->index + 1; /* skip Television string*/
}
/* Determine the requested input characteristics
specific for each usbvision card model */
switch (chan) {
@@ -552,20 +553,18 @@ static int vidioc_enum_input (struct file *file, void *priv,
break;
case 1:
vi->type = V4L2_INPUT_TYPE_CAMERA;
if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
strcpy(vi->name, "Green Video Input");
} else {
else
strcpy(vi->name, "Composite Video Input");
}
vi->std = V4L2_STD_PAL;
break;
case 2:
vi->type = V4L2_INPUT_TYPE_CAMERA;
if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
strcpy(vi->name, "Yellow Video Input");
} else {
else
strcpy(vi->name, "S-Video Input");
}
vi->std = V4L2_STD_PAL;
break;
case 3:
@@ -652,11 +651,10 @@ static int vidioc_g_frequency (struct file *file, void *priv,
struct usb_usbvision *usbvision = video_drvdata(file);
freq->tuner = 0; /* Only one tuner */
if(usbvision->radio) {
if (usbvision->radio)
freq->type = V4L2_TUNER_RADIO;
} else {
else
freq->type = V4L2_TUNER_ANALOG_TV;
}
freq->frequency = usbvision->freq;
return 0;
@@ -681,11 +679,10 @@ static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
{
struct usb_usbvision *usbvision = video_drvdata(file);
if(usbvision->radio) {
if (usbvision->radio)
strcpy(a->name, "Radio");
} else {
else
strcpy(a->name, "TV");
}
return 0;
}
@@ -693,10 +690,8 @@ static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
static int vidioc_s_audio(struct file *file, void *fh,
struct v4l2_audio *a)
{
if(a->index) {
if (a->index)
return -EINVAL;
}
return 0;
}
@@ -717,8 +712,8 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct usb_usbvision *usbvision = video_drvdata(file);
call_all(usbvision, core, g_ctrl, ctrl);
call_all(usbvision, core, g_ctrl, ctrl);
return 0;
}
@@ -726,8 +721,8 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct usb_usbvision *usbvision = video_drvdata(file);
call_all(usbvision, core, s_ctrl, ctrl);
call_all(usbvision, core, s_ctrl, ctrl);
return 0;
}
@@ -745,7 +740,8 @@ static int vidioc_reqbufs (struct file *file,
return -EINVAL;
if (usbvision->streaming == stream_on) {
if ((ret = usbvision_stream_interrupt(usbvision)))
ret = usbvision_stream_interrupt(usbvision);
if (ret)
return ret;
}
@@ -766,9 +762,8 @@ static int vidioc_querybuf (struct file *file,
/* FIXME : must control
that buffers are mapped (VIDIOC_REQBUFS has been called) */
if(vb->index>=usbvision->num_frames) {
if (vb->index >= usbvision->num_frames)
return -EINVAL;
}
/* Updating the corresponding frame state */
vb->flags = 0;
frame = &usbvision->frame[vb->index];
@@ -799,15 +794,13 @@ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
unsigned long lock_flags;
/* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
if(vb->index>=usbvision->num_frames) {
if (vb->index >= usbvision->num_frames)
return -EINVAL;
}
frame = &usbvision->frame[vb->index];
if (frame->grabstate != frame_state_unused) {
if (frame->grabstate != frame_state_unused)
return -EAGAIN;
}
/* Mark it as ready and enqueue frame */
frame->grabstate = frame_state_ready;
@@ -895,9 +888,8 @@ static int vidioc_streamoff(struct file *file,
static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *vfd)
{
if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) {
if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
return -EINVAL;
}
strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
return 0;
@@ -934,9 +926,8 @@ static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
}
}
/* robustness */
if(format_idx == USBVISION_SUPPORTED_PALETTES) {
if (format_idx == USBVISION_SUPPORTED_PALETTES)
return -EINVAL;
}
RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
@@ -953,13 +944,14 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct usb_usbvision *usbvision = video_drvdata(file);
int ret;
if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) {
ret = vidioc_try_fmt_vid_cap(file, priv, vf);
if (ret)
return ret;
}
/* stop io in case it is already in progress */
if (usbvision->streaming == stream_on) {
if ((ret = usbvision_stream_interrupt(usbvision)))
ret = usbvision_stream_interrupt(usbvision);
if (ret)
return ret;
}
usbvision_frames_free(usbvision);
@@ -979,7 +971,6 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
struct usb_usbvision *usbvision = video_drvdata(file);
int noblock = file->f_flags & O_NONBLOCK;
unsigned long lock_flags;
int ret, i;
struct usbvision_frame *frame;
@@ -1059,9 +1050,8 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
count = frame->scanlength - frame->bytes_read;
if (copy_to_user(buf, frame->data + frame->bytes_read, count)) {
if (copy_to_user(buf, frame->data + frame->bytes_read, count))
return -EFAULT;
}
frame->bytes_read += count;
PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
@@ -1089,9 +1079,8 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
PDEBUG(DBG_MMAP, "mmap");
if (!USBVISION_IS_OPERATIONAL(usbvision)) {
if (!USBVISION_IS_OPERATIONAL(usbvision))
return -EFAULT;
}
if (!(vma->vm_flags & VM_WRITE) ||
size != PAGE_ALIGN(usbvision->max_frame_size)) {
@@ -1115,7 +1104,6 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
pos = usbvision->frame[i].data;
while (size > 0) {
if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
return -EAGAIN;
@@ -1145,8 +1133,7 @@ static int usbvision_radio_open(struct file *file)
"%s: Someone tried to open an already opened USBVision Radio!\n",
__func__);
err_code = -EBUSY;
}
else {
} else {
if (power_on_at_open) {
usbvision_reset_power_off_timer(usbvision);
if (usbvision->power == 0) {
@@ -1315,9 +1302,8 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
}
vdev = video_device_alloc();
if (NULL == vdev) {
if (NULL == vdev)
return NULL;
}
*vdev = *vdev_template;
vdev->lock = &usbvision->v4l2_lock;
vdev->v4l2_dev = &usbvision->v4l2_dev;
@@ -1333,11 +1319,10 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
if (usbvision->rdev) {
PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
video_device_node_name(usbvision->rdev));
if (video_is_registered(usbvision->rdev)) {
if (video_is_registered(usbvision->rdev))
video_unregister_device(usbvision->rdev);
} else {
else
video_device_release(usbvision->rdev);
}
usbvision->rdev = NULL;
}
@@ -1345,11 +1330,10 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
if (usbvision->vdev) {
PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
video_device_node_name(usbvision->vdev));
if (video_is_registered(usbvision->vdev)) {
if (video_is_registered(usbvision->vdev))
video_unregister_device(usbvision->vdev);
} else {
else
video_device_release(usbvision->vdev);
}
usbvision->vdev = NULL;
}
}
@@ -1361,14 +1345,10 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
usbvision->vdev = usbvision_vdev_init(usbvision,
&usbvision_video_template,
"USBVision Video");
if (usbvision->vdev == NULL) {
if (usbvision->vdev == NULL)
goto err_exit;
}
if (video_register_device(usbvision->vdev,
VFL_TYPE_GRABBER,
video_nr)<0) {
if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
goto err_exit;
}
printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
usbvision->nr, video_device_node_name(usbvision->vdev));
@@ -1378,14 +1358,10 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
usbvision->rdev = usbvision_vdev_init(usbvision,
&usbvision_radio_template,
"USBVision Radio");
if (usbvision->rdev == NULL) {
if (usbvision->rdev == NULL)
goto err_exit;
}
if (video_register_device(usbvision->rdev,
VFL_TYPE_RADIO,
radio_nr)<0) {
if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
goto err_exit;
}
printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
usbvision->nr, video_device_node_name(usbvision->rdev));
}
@@ -1459,9 +1435,7 @@ static void usbvision_release(struct usb_usbvision *usbvision)
usbvision_remove_sysfs(usbvision->vdev);
usbvision_unregister_video(usbvision);
if (usbvision->ctrl_urb) {
usb_free_urb(usbvision->ctrl_urb);
}
v4l2_device_unregister(&usbvision->v4l2_dev);
kfree(usbvision);
@@ -1527,18 +1501,17 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
dev->descriptor.idProduct, ifnum);
model = devid->driver_info;
if ( (model<0) || (model>=usbvision_device_data_size) ) {
if (model < 0 || model >= usbvision_device_data_size) {
PDEBUG(DBG_PROBE, "model out of bounds %d", model);
return -ENODEV;
}
printk(KERN_INFO "%s: %s found\n", __func__,
usbvision_device_data[model].model_string);
if (usbvision_device_data[model].interface >= 0) {
if (usbvision_device_data[model].interface >= 0)
interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];
} else {
else
interface = &dev->actconfig->interface[ifnum]->altsetting[0];
}
endpoint = &interface->endpoint[1].desc;
if (!usb_endpoint_xfer_isoc(endpoint)) {
dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
@@ -1559,13 +1532,12 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
return -ENOMEM;
}
if (dev->descriptor.bNumConfigurations > 1) {
if (dev->descriptor.bNumConfigurations > 1)
usbvision->bridge_type = BRIDGE_NT1004;
} else if (model == DAZZLE_DVC_90_REV_1_SECAM) {
else if (model == DAZZLE_DVC_90_REV_1_SECAM)
usbvision->bridge_type = BRIDGE_NT1005;
} else {
else
usbvision->bridge_type = BRIDGE_NT1003;
}
PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type);
/* compute alternate max packet sizes */
@@ -1573,8 +1545,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
usbvision->num_alt = uif->num_altsetting;
PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
usbvision->alt_max_pkt_size = kmalloc(32*
usbvision->num_alt,GFP_KERNEL);
usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
if (usbvision->alt_max_pkt_size == NULL) {
dev_err(&intf->dev, "usbvision: out of memory!\n");
return -ENOMEM;
@@ -1593,9 +1564,8 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
usbvision->nr = usbvision_nr++;
usbvision->have_tuner = usbvision_device_data[model].tuner;
if (usbvision->have_tuner) {
if (usbvision->have_tuner)
usbvision->tuner_type = usbvision_device_data[model].tuner_type;
}
usbvision->dev_model = model;
usbvision->remove_pending = 0;

View File

@@ -148,7 +148,7 @@
#define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */
#define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */
#define USBVISION_POWEROFF_TIME 3 * (HZ) /* 3 seconds */
#define USBVISION_POWEROFF_TIME (3 * HZ) /* 3 seconds */
#define FRAMERATE_MIN 0
@@ -161,7 +161,8 @@ enum {
};
/* This macro restricts an int variable to an inclusive range */
#define RESTRICT_TO_RANGE(v,mi,ma) { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
#define RESTRICT_TO_RANGE(v, mi, ma) \
{ if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
/*
* We use macros to do YUV -> RGB conversion because this is