aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/usbvision/usbvision-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/usbvision/usbvision-core.c')
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c695
1 files changed, 299 insertions, 396 deletions
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 64a913323181..c8feb0d6fccf 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -33,7 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <asm/io.h> 36#include <linux/io.h>
37#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39 39
@@ -46,12 +46,12 @@
46#include "usbvision.h" 46#include "usbvision.h"
47 47
48static unsigned int core_debug; 48static unsigned int core_debug;
49module_param(core_debug,int,0644); 49module_param(core_debug, int, 0644);
50MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 50MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
51 51
52static unsigned int force_testpattern; 52static unsigned int force_testpattern;
53module_param(force_testpattern,int,0644); 53module_param(force_testpattern, int, 0644);
54MODULE_PARM_DESC(force_testpattern,"enable test pattern display [core]"); 54MODULE_PARM_DESC(force_testpattern, "enable test pattern display [core]");
55 55
56static int adjust_compression = 1; /* Set the compression to be adaptive */ 56static int adjust_compression = 1; /* Set the compression to be adaptive */
57module_param(adjust_compression, int, 0444); 57module_param(adjust_compression, int, 0444);
@@ -82,15 +82,15 @@ MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]");
82 __func__, __LINE__ , ## args); \ 82 __func__, __LINE__ , ## args); \
83 } 83 }
84#else 84#else
85 #define PDEBUG(level, fmt, args...) do {} while(0) 85 #define PDEBUG(level, fmt, args...) do {} while (0)
86#endif 86#endif
87 87
88#define DBG_HEADER 1<<0 88#define DBG_HEADER (1 << 0)
89#define DBG_IRQ 1<<1 89#define DBG_IRQ (1 << 1)
90#define DBG_ISOC 1<<2 90#define DBG_ISOC (1 << 2)
91#define DBG_PARSE 1<<3 91#define DBG_PARSE (1 << 3)
92#define DBG_SCRATCH 1<<4 92#define DBG_SCRATCH (1 << 4)
93#define DBG_FUNC 1<<5 93#define DBG_FUNC (1 << 5)
94 94
95static const int max_imgwidth = MAX_FRAME_WIDTH; 95static const int max_imgwidth = MAX_FRAME_WIDTH;
96static const int max_imgheight = MAX_FRAME_HEIGHT; 96static const int max_imgheight = MAX_FRAME_HEIGHT;
@@ -107,10 +107,10 @@ static const int min_imgheight = MIN_FRAME_HEIGHT;
107static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE; 107static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE;
108 108
109/* Function prototypes */ 109/* Function prototypes */
110static int usbvision_request_intra (struct usb_usbvision *usbvision); 110static int usbvision_request_intra(struct usb_usbvision *usbvision);
111static int usbvision_unrequest_intra (struct usb_usbvision *usbvision); 111static int usbvision_unrequest_intra(struct usb_usbvision *usbvision);
112static int usbvision_adjust_compression (struct usb_usbvision *usbvision); 112static int usbvision_adjust_compression(struct usb_usbvision *usbvision);
113static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision); 113static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision);
114 114
115/*******************************/ 115/*******************************/
116/* Memory management functions */ 116/* Memory management functions */
@@ -176,7 +176,7 @@ static void usbvision_hexdump(const unsigned char *data, int len)
176 k += sprintf(&tmp[k], "%02x ", data[i]); 176 k += sprintf(&tmp[k], "%02x ", data[i]);
177 } 177 }
178 if (k > 0) 178 if (k > 0)
179 printk("%s\n", tmp); 179 printk(KERN_CONT "%s\n", tmp);
180} 180}
181#endif 181#endif
182 182
@@ -186,9 +186,9 @@ static void usbvision_hexdump(const unsigned char *data, int len)
186static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */ 186static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */
187{ 187{
188 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 188 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
189 if (len < 0) { 189
190 if (len < 0)
190 len += scratch_buf_size; 191 len += scratch_buf_size;
191 }
192 PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len); 192 PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len);
193 193
194 return len; 194 return len;
@@ -199,9 +199,8 @@ static int scratch_len(struct usb_usbvision *usbvision) /* This returns the a
199static int scratch_free(struct usb_usbvision *usbvision) 199static int scratch_free(struct usb_usbvision *usbvision)
200{ 200{
201 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 201 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
202 if (free <= 0) { 202 if (free <= 0)
203 free += scratch_buf_size; 203 free += scratch_buf_size;
204 }
205 if (free) { 204 if (free) {
206 free -= 1; /* at least one byte in the buffer must */ 205 free -= 1; /* at least one byte in the buffer must */
207 /* left blank, otherwise there is no chance to differ between full and empty */ 206 /* 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,
221 if (usbvision->scratch_write_ptr + len < scratch_buf_size) { 220 if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
222 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len); 221 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
223 usbvision->scratch_write_ptr += len; 222 usbvision->scratch_write_ptr += len;
224 } 223 } else {
225 else {
226 len_part = scratch_buf_size - usbvision->scratch_write_ptr; 224 len_part = scratch_buf_size - usbvision->scratch_write_ptr;
227 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part); 225 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part);
228 if (len == len_part) { 226 if (len == len_part) {
229 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */ 227 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */
230 } 228 } else {
231 else {
232 memcpy(usbvision->scratch, data + len_part, len - len_part); 229 memcpy(usbvision->scratch, data + len_part, len - len_part);
233 usbvision->scratch_write_ptr = len - len_part; 230 usbvision->scratch_write_ptr = len - len_part;
234 } 231 }
@@ -255,17 +252,16 @@ static int scratch_get_extra(struct usb_usbvision *usbvision,
255 unsigned char *data, int *ptr, int len) 252 unsigned char *data, int *ptr, int len)
256{ 253{
257 int len_part; 254 int len_part;
255
258 if (*ptr + len < scratch_buf_size) { 256 if (*ptr + len < scratch_buf_size) {
259 memcpy(data, usbvision->scratch + *ptr, len); 257 memcpy(data, usbvision->scratch + *ptr, len);
260 *ptr += len; 258 *ptr += len;
261 } 259 } else {
262 else {
263 len_part = scratch_buf_size - *ptr; 260 len_part = scratch_buf_size - *ptr;
264 memcpy(data, usbvision->scratch + *ptr, len_part); 261 memcpy(data, usbvision->scratch + *ptr, len_part);
265 if (len == len_part) { 262 if (len == len_part) {
266 *ptr = 0; /* just set the y_ptr to zero */ 263 *ptr = 0; /* just set the y_ptr to zero */
267 } 264 } else {
268 else {
269 memcpy(data + len_part, usbvision->scratch, len - len_part); 265 memcpy(data + len_part, usbvision->scratch, len - len_part);
270 *ptr = len - len_part; 266 *ptr = len - len_part;
271 } 267 }
@@ -281,7 +277,7 @@ static int scratch_get_extra(struct usb_usbvision *usbvision,
281static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, 277static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
282 int len) 278 int len)
283{ 279{
284 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size; 280 *ptr = (usbvision->scratch_read_ptr + len) % scratch_buf_size;
285 281
286 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); 282 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
287} 283}
@@ -301,17 +297,16 @@ static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
301 int len) 297 int len)
302{ 298{
303 int len_part; 299 int len_part;
300
304 if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 301 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
305 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len); 302 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
306 usbvision->scratch_read_ptr += len; 303 usbvision->scratch_read_ptr += len;
307 } 304 } else {
308 else {
309 len_part = scratch_buf_size - usbvision->scratch_read_ptr; 305 len_part = scratch_buf_size - usbvision->scratch_read_ptr;
310 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part); 306 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part);
311 if (len == len_part) { 307 if (len == len_part) {
312 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */ 308 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */
313 } 309 } else {
314 else {
315 memcpy(data + len_part, usbvision->scratch, len - len_part); 310 memcpy(data + len_part, usbvision->scratch, len - len_part);
316 usbvision->scratch_read_ptr = len - len_part; 311 usbvision->scratch_read_ptr = len - len_part;
317 } 312 }
@@ -355,7 +350,6 @@ static int scratch_get_header(struct usb_usbvision *usbvision,
355/* This removes len bytes of old data from the buffer */ 350/* This removes len bytes of old data from the buffer */
356static void scratch_rm_old(struct usb_usbvision *usbvision, int len) 351static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
357{ 352{
358
359 usbvision->scratch_read_ptr += len; 353 usbvision->scratch_read_ptr += len;
360 usbvision->scratch_read_ptr %= scratch_buf_size; 354 usbvision->scratch_read_ptr %= scratch_buf_size;
361 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr); 355 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr);
@@ -378,7 +372,7 @@ int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
378{ 372{
379 usbvision->scratch = vmalloc_32(scratch_buf_size); 373 usbvision->scratch = vmalloc_32(scratch_buf_size);
380 scratch_reset(usbvision); 374 scratch_reset(usbvision);
381 if(usbvision->scratch == NULL) { 375 if (usbvision->scratch == NULL) {
382 dev_err(&usbvision->dev->dev, 376 dev_err(&usbvision->dev->dev,
383 "%s: unable to allocate %d bytes for scratch\n", 377 "%s: unable to allocate %d bytes for scratch\n",
384 __func__, scratch_buf_size); 378 __func__, scratch_buf_size);
@@ -391,7 +385,6 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
391{ 385{
392 vfree(usbvision->scratch); 386 vfree(usbvision->scratch);
393 usbvision->scratch = NULL; 387 usbvision->scratch = NULL;
394
395} 388}
396 389
397/* 390/*
@@ -476,7 +469,6 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
476 frame->grabstate = frame_state_done; 469 frame->grabstate = frame_state_done;
477 frame->scanlength += scan_length; 470 frame->scanlength += scan_length;
478 ++num_pass; 471 ++num_pass;
479
480} 472}
481 473
482/* 474/*
@@ -487,6 +479,7 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
487int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 479int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
488{ 480{
489 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 481 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
482
490 usbvision->intra_frame_buffer = vmalloc_32(IFB_size); 483 usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
491 if (usbvision->intra_frame_buffer == NULL) { 484 if (usbvision->intra_frame_buffer == NULL) {
492 dev_err(&usbvision->dev->dev, 485 dev_err(&usbvision->dev->dev,
@@ -545,8 +538,7 @@ static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
545 usbvision_unrequest_intra(usbvision); 538 usbvision_unrequest_intra(usbvision);
546 break; 539 break;
547 } 540 }
548 } 541 } else {
549 else {
550 found_header = 1; 542 found_header = 1;
551 break; 543 break;
552 } 544 }
@@ -555,16 +547,15 @@ static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
555 if (found_header) { 547 if (found_header) {
556 frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width; 548 frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width;
557 frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height; 549 frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height;
558 frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth)>> 3; 550 frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3;
559 } 551 } else { /* no header found */
560 else { /* no header found */
561 PDEBUG(DBG_HEADER, "skipping scratch data, no header"); 552 PDEBUG(DBG_HEADER, "skipping scratch data, no header");
562 scratch_reset(usbvision); 553 scratch_reset(usbvision);
563 return parse_state_end_parse; 554 return parse_state_end_parse;
564 } 555 }
565 556
566 /* found header */ 557 /* found header */
567 if (frame->isoc_header.data_format==ISOC_MODE_COMPRESS) { 558 if (frame->isoc_header.data_format == ISOC_MODE_COMPRESS) {
568 /* check isoc_header.frame_num for lost frames */ 559 /* check isoc_header.frame_num for lost frames */
569 if (usbvision->last_isoc_frame_num >= 0) { 560 if (usbvision->last_isoc_frame_num >= 0) {
570 if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) { 561 if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) {
@@ -594,7 +585,7 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
594 unsigned char *f; 585 unsigned char *f;
595 int len; 586 int len;
596 int i; 587 int i;
597 unsigned char yuyv[4]={180, 128, 10, 128}; /* YUV components */ 588 unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */
598 unsigned char rv, gv, bv; /* RGB components */ 589 unsigned char rv, gv, bv; /* RGB components */
599 int clipmask_index, bytes_per_pixel; 590 int clipmask_index, bytes_per_pixel;
600 int stretch_bytes, clipmask_add; 591 int stretch_bytes, clipmask_add;
@@ -603,31 +594,27 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
603 f = frame->data + (frame->v4l2_linesize * frame->curline); 594 f = frame->data + (frame->v4l2_linesize * frame->curline);
604 595
605 /* Make sure there's enough data for the entire line */ 596 /* Make sure there's enough data for the entire line */
606 len = (frame->isoc_header.frame_width * 2)+5; 597 len = (frame->isoc_header.frame_width * 2) + 5;
607 if (scratch_len(usbvision) < len) { 598 if (scratch_len(usbvision) < len) {
608 PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len); 599 PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len);
609 return parse_state_out; 600 return parse_state_out;
610 } 601 }
611 602
612 if ((frame->curline + 1) >= frame->frmheight) { 603 if ((frame->curline + 1) >= frame->frmheight)
613 return parse_state_next_frame; 604 return parse_state_next_frame;
614 }
615 605
616 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; 606 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
617 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; 607 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
618 clipmask_index = frame->curline * MAX_FRAME_WIDTH; 608 clipmask_index = frame->curline * MAX_FRAME_WIDTH;
619 clipmask_add = usbvision->stretch_width; 609 clipmask_add = usbvision->stretch_width;
620 610
621 for (i = 0; i < frame->frmwidth; i+=(2 * usbvision->stretch_width)) { 611 for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
622
623 scratch_get(usbvision, &yuyv[0], 4); 612 scratch_get(usbvision, &yuyv[0], 4);
624 613
625 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 614 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
626 *f++ = yuyv[0]; /* Y */ 615 *f++ = yuyv[0]; /* Y */
627 *f++ = yuyv[3]; /* U */ 616 *f++ = yuyv[3]; /* U */
628 } 617 } else {
629 else {
630
631 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv); 618 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
632 switch (frame->v4l2_format.format) { 619 switch (frame->v4l2_format.format) {
633 case V4L2_PIX_FMT_RGB565: 620 case V4L2_PIX_FMT_RGB565:
@@ -661,9 +648,7 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
661 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 648 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
662 *f++ = yuyv[2]; /* Y */ 649 *f++ = yuyv[2]; /* Y */
663 *f++ = yuyv[1]; /* V */ 650 *f++ = yuyv[1]; /* V */
664 } 651 } else {
665 else {
666
667 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv); 652 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
668 switch (frame->v4l2_format.format) { 653 switch (frame->v4l2_format.format) {
669 case V4L2_PIX_FMT_RGB565: 654 case V4L2_PIX_FMT_RGB565:
@@ -698,16 +683,13 @@ static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvisio
698 frame->curline += usbvision->stretch_height; 683 frame->curline += usbvision->stretch_height;
699 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height; 684 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
700 685
701 if (frame->curline >= frame->frmheight) { 686 if (frame->curline >= frame->frmheight)
702 return parse_state_next_frame; 687 return parse_state_next_frame;
703 } 688 return parse_state_continue;
704 else {
705 return parse_state_continue;
706 }
707} 689}
708 690
709/* The decompression routine */ 691/* The decompression routine */
710static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *compressed, 692static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed,
711 unsigned char *decompressed, int *start_pos, 693 unsigned char *decompressed, int *start_pos,
712 int *block_typestart_pos, int len) 694 int *block_typestart_pos, int len)
713{ 695{
@@ -728,9 +710,8 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
728 rest_pixel = len; 710 rest_pixel = len;
729 711
730 for (idx = 0; idx < len; idx++) { 712 for (idx = 0; idx < len; idx++) {
731
732 if (block_len == 0) { 713 if (block_len == 0) {
733 if (block_type_len==0) { 714 if (block_type_len == 0) {
734 block_type_byte = compressed[block_type_pos]; 715 block_type_byte = compressed[block_type_pos];
735 block_type_pos++; 716 block_type_pos++;
736 block_type_len = 4; 717 block_type_len = 4;
@@ -742,7 +723,7 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
742 723
743 pos = extra_pos; 724 pos = extra_pos;
744 if (block_type == 0) { 725 if (block_type == 0) {
745 if(rest_pixel >= 24) { 726 if (rest_pixel >= 24) {
746 idx += 23; 727 idx += 23;
747 rest_pixel -= 24; 728 rest_pixel -= 24;
748 integrator = decompressed[idx]; 729 integrator = decompressed[idx];
@@ -753,11 +734,10 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
753 } else { 734 } else {
754 block_code = compressed[pos]; 735 block_code = compressed[pos];
755 pos++; 736 pos++;
756 if (rest_pixel >= 24) { 737 if (rest_pixel >= 24)
757 block_len = 24; 738 block_len = 24;
758 } else { 739 else
759 block_len = rest_pixel; 740 block_len = rest_pixel;
760 }
761 rest_pixel -= block_len; 741 rest_pixel -= block_len;
762 extra_pos = pos + (block_len / 4); 742 extra_pos = pos + (block_len / 4);
763 } 743 }
@@ -765,24 +745,23 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *c
765 block_type_len -= 1; 745 block_type_len -= 1;
766 } 746 }
767 if (block_len > 0) { 747 if (block_len > 0) {
768 if ((block_len%4) == 0) { 748 if ((block_len % 4) == 0) {
769 block_byte = compressed[pos]; 749 block_byte = compressed[pos];
770 pos++; 750 pos++;
771 } 751 }
772 if (block_type == 1) { /* inter Block */ 752 if (block_type == 1) /* inter Block */
773 integrator = decompressed[idx]; 753 integrator = decompressed[idx];
774 }
775 switch (block_byte & 0xC0) { 754 switch (block_byte & 0xC0) {
776 case 0x03<<6: 755 case 0x03 << 6:
777 integrator += compressed[extra_pos]; 756 integrator += compressed[extra_pos];
778 extra_pos++; 757 extra_pos++;
779 break; 758 break;
780 case 0x02<<6: 759 case 0x02 << 6:
781 integrator += block_code; 760 integrator += block_code;
782 break; 761 break;
783 case 0x00: 762 case 0x00:
784 integrator -= block_code; 763 integrator -= block_code;
785 break; 764 break;
786 } 765 }
787 decompressed[idx] = integrator; 766 decompressed[idx] = integrator;
788 block_byte <<= 2; 767 block_byte <<= 2;
@@ -811,45 +790,40 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
811#define USBVISION_STRIP_HEADER_LEN 3 790#define USBVISION_STRIP_HEADER_LEN 3
812 791
813 struct usbvision_frame *frame; 792 struct usbvision_frame *frame;
814 unsigned char *f,*u = NULL ,*v = NULL; 793 unsigned char *f, *u = NULL, *v = NULL;
815 unsigned char strip_data[USBVISION_STRIP_LEN_MAX]; 794 unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
816 unsigned char strip_header[USBVISION_STRIP_HEADER_LEN]; 795 unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
817 int idx, idx_end, strip_len, strip_ptr, Startblock_pos, block_pos, block_type_pos; 796 int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
818 int clipmask_index, bytes_per_pixel, rc; 797 int clipmask_index, bytes_per_pixel, rc;
819 int image_size; 798 int image_size;
820 unsigned char rv, gv, bv; 799 unsigned char rv, gv, bv;
821 static unsigned char *Y, *U, *V; 800 static unsigned char *Y, *U, *V;
822 801
823 frame = usbvision->cur_frame; 802 frame = usbvision->cur_frame;
824 image_size = frame->frmwidth * frame->frmheight; 803 image_size = frame->frmwidth * frame->frmheight;
825 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) || 804 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
826 (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) ) { /* this is a planar format */ 805 (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) { /* this is a planar format */
827 /* ... v4l2_linesize not used here. */ 806 /* ... v4l2_linesize not used here. */
828 f = frame->data + (frame->width * frame->curline); 807 f = frame->data + (frame->width * frame->curline);
829 } else 808 } else
830 f = frame->data + (frame->v4l2_linesize * frame->curline); 809 f = frame->data + (frame->v4l2_linesize * frame->curline);
831 810
832 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV){ /* initialise u and v pointers */ 811 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
833 /* get base of u and b planes add halfoffset */ 812 /* get base of u and b planes add halfoffset */
834
835 u = frame->data 813 u = frame->data
836 + image_size 814 + image_size
837 + (frame->frmwidth >>1) * frame->curline ; 815 + (frame->frmwidth >> 1) * frame->curline;
838 v = u + (image_size >>1 ); 816 v = u + (image_size >> 1);
839 817 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
840 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420){ 818 v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2);
841 819 u = v + (image_size >> 2);
842 v = frame->data + image_size + ((frame->curline* (frame->width))>>2) ;
843 u = v + (image_size >>2) ;
844 } 820 }
845 821
846 if (frame->curline == 0) { 822 if (frame->curline == 0)
847 usbvision_adjust_compression(usbvision); 823 usbvision_adjust_compression(usbvision);
848 }
849 824
850 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) { 825 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN)
851 return parse_state_out; 826 return parse_state_out;
852 }
853 827
854 /* get strip header without changing the scratch_read_ptr */ 828 /* get strip header without changing the scratch_read_ptr */
855 scratch_set_extra_ptr(usbvision, &strip_ptr, 0); 829 scratch_set_extra_ptr(usbvision, &strip_ptr, 0);
@@ -863,7 +837,7 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
863 } 837 }
864 838
865 if (frame->curline != (int)strip_header[2]) { 839 if (frame->curline != (int)strip_header[2]) {
866 /* line number missmatch error */ 840 /* line number mismatch error */
867 usbvision->strip_line_number_errors++; 841 usbvision->strip_line_number_errors++;
868 } 842 }
869 843
@@ -883,8 +857,7 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
883 Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline; 857 Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline;
884 U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2); 858 U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2);
885 V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2); 859 V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2);
886 } 860 } else {
887 else {
888 return parse_state_next_frame; 861 return parse_state_next_frame;
889 } 862 }
890 863
@@ -895,107 +868,87 @@ static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision
895 868
896 idx_end = frame->frmwidth; 869 idx_end = frame->frmwidth;
897 block_type_pos = USBVISION_STRIP_HEADER_LEN; 870 block_type_pos = USBVISION_STRIP_HEADER_LEN;
898 Startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2; 871 startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2;
899 block_pos = Startblock_pos; 872 block_pos = startblock_pos;
900 873
901 usbvision->block_pos = block_pos; 874 usbvision->block_pos = block_pos;
902 875
903 if ((rc = usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end)) != idx_end) { 876 rc = usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end);
904 /* return parse_state_continue; */ 877 if (strip_len > usbvision->max_strip_len)
905 }
906 if (strip_len > usbvision->max_strip_len) {
907 usbvision->max_strip_len = strip_len; 878 usbvision->max_strip_len = strip_len;
908 }
909 879
910 if (frame->curline%2) { 880 if (frame->curline % 2)
911 if ((rc = usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end/2)) != idx_end/2) { 881 rc = usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2);
912 /* return parse_state_continue; */ 882 else
913 } 883 rc = usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2);
914 }
915 else {
916 if ((rc = usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end/2)) != idx_end/2) {
917 /* return parse_state_continue; */
918 }
919 }
920 884
921 if (block_pos > usbvision->comprblock_pos) { 885 if (block_pos > usbvision->comprblock_pos)
922 usbvision->comprblock_pos = block_pos; 886 usbvision->comprblock_pos = block_pos;
923 } 887 if (block_pos > strip_len)
924 if (block_pos > strip_len) {
925 usbvision->strip_len_errors++; 888 usbvision->strip_len_errors++;
926 }
927 889
928 for (idx = 0; idx < idx_end; idx++) { 890 for (idx = 0; idx < idx_end; idx++) {
929 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 891 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
930 *f++ = Y[idx]; 892 *f++ = Y[idx];
931 *f++ = idx & 0x01 ? U[idx/2] : V[idx/2]; 893 *f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
932 } 894 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
933 else if(frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
934 *f++ = Y[idx]; 895 *f++ = Y[idx];
935 if ( idx & 0x01) 896 if (idx & 0x01)
936 *u++ = U[idx>>1] ; 897 *u++ = U[idx >> 1];
937 else 898 else
938 *v++ = V[idx>>1]; 899 *v++ = V[idx >> 1];
939 } 900 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
940 else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { 901 *f++ = Y[idx];
941 *f++ = Y [idx]; 902 if (!((idx & 0x01) | (frame->curline & 0x01))) {
942 if ( !(( idx & 0x01 ) | ( frame->curline & 0x01 )) ){ 903 /* only need do this for 1 in 4 pixels */
943 904 /* intraframe buffer is YUV420 format */
944/* only need do this for 1 in 4 pixels */ 905 *u++ = U[idx >> 1];
945/* intraframe buffer is YUV420 format */ 906 *v++ = V[idx >> 1];
946
947 *u++ = U[idx >>1];
948 *v++ = V[idx >>1];
949 } 907 }
950 908 } else {
951 } 909 YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
952 else {
953 YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx/2], V[idx/2], rv, gv, bv);
954 switch (frame->v4l2_format.format) { 910 switch (frame->v4l2_format.format) {
955 case V4L2_PIX_FMT_GREY: 911 case V4L2_PIX_FMT_GREY:
956 *f++ = Y[idx]; 912 *f++ = Y[idx];
957 break; 913 break;
958 case V4L2_PIX_FMT_RGB555: 914 case V4L2_PIX_FMT_RGB555:
959 *f++ = (0x1F & rv) | 915 *f++ = (0x1F & rv) |
960 (0xE0 & (gv << 5)); 916 (0xE0 & (gv << 5));
961 *f++ = (0x03 & (gv >> 3)) | 917 *f++ = (0x03 & (gv >> 3)) |
962 (0x7C & (bv << 2)); 918 (0x7C & (bv << 2));
963 break; 919 break;
964 case V4L2_PIX_FMT_RGB565: 920 case V4L2_PIX_FMT_RGB565:
965 *f++ = (0x1F & rv) | 921 *f++ = (0x1F & rv) |
966 (0xE0 & (gv << 5)); 922 (0xE0 & (gv << 5));
967 *f++ = (0x07 & (gv >> 3)) | 923 *f++ = (0x07 & (gv >> 3)) |
968 (0xF8 & bv); 924 (0xF8 & bv);
969 break; 925 break;
970 case V4L2_PIX_FMT_RGB24: 926 case V4L2_PIX_FMT_RGB24:
971 *f++ = rv; 927 *f++ = rv;
972 *f++ = gv; 928 *f++ = gv;
973 *f++ = bv; 929 *f++ = bv;
974 break; 930 break;
975 case V4L2_PIX_FMT_RGB32: 931 case V4L2_PIX_FMT_RGB32:
976 *f++ = rv; 932 *f++ = rv;
977 *f++ = gv; 933 *f++ = gv;
978 *f++ = bv; 934 *f++ = bv;
979 f++; 935 f++;
980 break; 936 break;
981 } 937 }
982 } 938 }
983 clipmask_index++; 939 clipmask_index++;
984 } 940 }
985 /* Deal with non-integer no. of bytes for YUV420P */ 941 /* Deal with non-integer no. of bytes for YUV420P */
986 if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420 ) 942 if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420)
987 *pcopylen += frame->v4l2_linesize; 943 *pcopylen += frame->v4l2_linesize;
988 else 944 else
989 *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1; 945 *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
990 946
991 frame->curline += 1; 947 frame->curline += 1;
992 948
993 if (frame->curline >= frame->frmheight) { 949 if (frame->curline >= frame->frmheight)
994 return parse_state_next_frame; 950 return parse_state_next_frame;
995 } 951 return parse_state_continue;
996 else {
997 return parse_state_continue;
998 }
999 952
1000} 953}
1001 954
@@ -1016,11 +969,11 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1016 unsigned int pixel_per_line, block; 969 unsigned int pixel_per_line, block;
1017 int pixel, block_split; 970 int pixel, block_split;
1018 int y_ptr, u_ptr, v_ptr, y_odd_offset; 971 int y_ptr, u_ptr, v_ptr, y_odd_offset;
1019 const int y_block_size = 128; 972 const int y_block_size = 128;
1020 const int uv_block_size = 64; 973 const int uv_block_size = 64;
1021 const int sub_block_size = 32; 974 const int sub_block_size = 32;
1022 const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4; 975 const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
1023 const int uv_step[]= { 0, 0, 0, 4 }, uv_step_size = 4; 976 const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4;
1024 unsigned char y[2], u, v; /* YUV components */ 977 unsigned char y[2], u, v; /* YUV components */
1025 int y_, u_, v_, vb, uvg, ur; 978 int y_, u_, v_, vb, uvg, ur;
1026 int r_, g_, b_; /* RGB components */ 979 int r_, g_, b_; /* RGB components */
@@ -1047,9 +1000,8 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1047 return parse_state_out; 1000 return parse_state_out;
1048 } 1001 }
1049 1002
1050 if ((frame->curline + 1) >= frame->frmheight) { 1003 if ((frame->curline + 1) >= frame->frmheight)
1051 return parse_state_next_frame; 1004 return parse_state_next_frame;
1052 }
1053 1005
1054 block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */ 1006 block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */
1055 1007
@@ -1061,11 +1013,8 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1061 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset 1013 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
1062 + (4 - block_split) * sub_block_size); 1014 + (4 - block_split) * sub_block_size);
1063 1015
1064 for (block = 0; block < (pixel_per_line / sub_block_size); 1016 for (block = 0; block < (pixel_per_line / sub_block_size); block++) {
1065 block++) { 1017 for (pixel = 0; pixel < sub_block_size; pixel += 2) {
1066
1067
1068 for (pixel = 0; pixel < sub_block_size; pixel +=2) {
1069 scratch_get(usbvision, &y[0], 2); 1018 scratch_get(usbvision, &y[0], 2);
1070 scratch_get_extra(usbvision, &u, &u_ptr, 1); 1019 scratch_get_extra(usbvision, &u, &u_ptr, 1);
1071 scratch_get_extra(usbvision, &v, &v_ptr, 1); 1020 scratch_get_extra(usbvision, &v, &v_ptr, 1);
@@ -1073,19 +1022,18 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1073 /* I don't use the YUV_TO_RGB macro for better performance */ 1022 /* I don't use the YUV_TO_RGB macro for better performance */
1074 v_ = v - 128; 1023 v_ = v - 128;
1075 u_ = u - 128; 1024 u_ = u - 128;
1076 vb = 132252 * v_; 1025 vb = 132252 * v_;
1077 uvg= -53281 * u_ - 25625 * v_; 1026 uvg = -53281 * u_ - 25625 * v_;
1078 ur = 104595 * u_; 1027 ur = 104595 * u_;
1079 1028
1080 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1029 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1081 *f_even++ = y[0]; 1030 *f_even++ = y[0];
1082 *f_even++ = v; 1031 *f_even++ = v;
1083 } 1032 } else {
1084 else {
1085 y_ = 76284 * (y[0] - 16); 1033 y_ = 76284 * (y[0] - 16);
1086 1034
1087 b_ = (y_ + vb) >> 16; 1035 b_ = (y_ + vb) >> 16;
1088 g_ = (y_ + uvg)>> 16; 1036 g_ = (y_ + uvg) >> 16;
1089 r_ = (y_ + ur) >> 16; 1037 r_ = (y_ + ur) >> 16;
1090 1038
1091 switch (frame->v4l2_format.format) { 1039 switch (frame->v4l2_format.format) {
@@ -1121,15 +1069,14 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1121 clipmask_even_index += clipmask_add; 1069 clipmask_even_index += clipmask_add;
1122 f_even += stretch_bytes; 1070 f_even += stretch_bytes;
1123 1071
1124 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1072 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1125 *f_even++ = y[1]; 1073 *f_even++ = y[1];
1126 *f_even++ = u; 1074 *f_even++ = u;
1127 } 1075 } else {
1128 else {
1129 y_ = 76284 * (y[1] - 16); 1076 y_ = 76284 * (y[1] - 16);
1130 1077
1131 b_ = (y_ + vb) >> 16; 1078 b_ = (y_ + vb) >> 16;
1132 g_ = (y_ + uvg)>> 16; 1079 g_ = (y_ + uvg) >> 16;
1133 r_ = (y_ + ur) >> 16; 1080 r_ = (y_ + ur) >> 16;
1134 1081
1135 switch (frame->v4l2_format.format) { 1082 switch (frame->v4l2_format.format) {
@@ -1167,15 +1114,14 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1167 1114
1168 scratch_get_extra(usbvision, &y[0], &y_ptr, 2); 1115 scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
1169 1116
1170 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1117 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1171 *f_odd++ = y[0]; 1118 *f_odd++ = y[0];
1172 *f_odd++ = v; 1119 *f_odd++ = v;
1173 } 1120 } else {
1174 else {
1175 y_ = 76284 * (y[0] - 16); 1121 y_ = 76284 * (y[0] - 16);
1176 1122
1177 b_ = (y_ + vb) >> 16; 1123 b_ = (y_ + vb) >> 16;
1178 g_ = (y_ + uvg)>> 16; 1124 g_ = (y_ + uvg) >> 16;
1179 r_ = (y_ + ur) >> 16; 1125 r_ = (y_ + ur) >> 16;
1180 1126
1181 switch (frame->v4l2_format.format) { 1127 switch (frame->v4l2_format.format) {
@@ -1211,15 +1157,14 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1211 clipmask_odd_index += clipmask_add; 1157 clipmask_odd_index += clipmask_add;
1212 f_odd += stretch_bytes; 1158 f_odd += stretch_bytes;
1213 1159
1214 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1160 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1215 *f_odd++ = y[1]; 1161 *f_odd++ = y[1];
1216 *f_odd++ = u; 1162 *f_odd++ = u;
1217 } 1163 } else {
1218 else {
1219 y_ = 76284 * (y[1] - 16); 1164 y_ = 76284 * (y[1] - 16);
1220 1165
1221 b_ = (y_ + vb) >> 16; 1166 b_ = (y_ + vb) >> 16;
1222 g_ = (y_ + uvg)>> 16; 1167 g_ = (y_ + uvg) >> 16;
1223 r_ = (y_ + ur) >> 16; 1168 r_ = (y_ + ur) >> 16;
1224 1169
1225 switch (frame->v4l2_format.format) { 1170 switch (frame->v4l2_format.format) {
@@ -1256,7 +1201,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1256 f_odd += stretch_bytes; 1201 f_odd += stretch_bytes;
1257 } 1202 }
1258 1203
1259 scratch_rm_old(usbvision,y_step[block % y_step_size] * sub_block_size); 1204 scratch_rm_old(usbvision, y_step[block % y_step_size] * sub_block_size);
1260 scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size] 1205 scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size]
1261 * sub_block_size); 1206 * sub_block_size);
1262 scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size] 1207 scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size]
@@ -1273,8 +1218,7 @@ static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvisio
1273 1218
1274 if (frame->curline >= frame->frmheight) 1219 if (frame->curline >= frame->frmheight)
1275 return parse_state_next_frame; 1220 return parse_state_next_frame;
1276 else 1221 return parse_state_continue;
1277 return parse_state_continue;
1278} 1222}
1279 1223
1280/* 1224/*
@@ -1297,34 +1241,24 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
1297 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision)); 1241 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
1298 1242
1299 while (1) { 1243 while (1) {
1300
1301 newstate = parse_state_out; 1244 newstate = parse_state_out;
1302 if (scratch_len(usbvision)) { 1245 if (scratch_len(usbvision)) {
1303 if (frame->scanstate == scan_state_scanning) { 1246 if (frame->scanstate == scan_state_scanning) {
1304 newstate = usbvision_find_header(usbvision); 1247 newstate = usbvision_find_header(usbvision);
1305 } 1248 } else if (frame->scanstate == scan_state_lines) {
1306 else if (frame->scanstate == scan_state_lines) { 1249 if (usbvision->isoc_mode == ISOC_MODE_YUV420)
1307 if (usbvision->isoc_mode == ISOC_MODE_YUV420) {
1308 newstate = usbvision_parse_lines_420(usbvision, &copylen); 1250 newstate = usbvision_parse_lines_420(usbvision, &copylen);
1309 } 1251 else if (usbvision->isoc_mode == ISOC_MODE_YUV422)
1310 else if (usbvision->isoc_mode == ISOC_MODE_YUV422) {
1311 newstate = usbvision_parse_lines_422(usbvision, &copylen); 1252 newstate = usbvision_parse_lines_422(usbvision, &copylen);
1312 } 1253 else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
1313 else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
1314 newstate = usbvision_parse_compress(usbvision, &copylen); 1254 newstate = usbvision_parse_compress(usbvision, &copylen);
1315 }
1316
1317 } 1255 }
1318 } 1256 }
1319 if (newstate == parse_state_continue) { 1257 if (newstate == parse_state_continue)
1320 continue; 1258 continue;
1321 } 1259 if ((newstate == parse_state_next_frame) || (newstate == parse_state_out))
1322 else if ((newstate == parse_state_next_frame) || (newstate == parse_state_out)) {
1323 break; 1260 break;
1324 } 1261 return; /* parse_state_end_parse */
1325 else {
1326 return; /* parse_state_end_parse */
1327 }
1328 } 1262 }
1329 1263
1330 if (newstate == parse_state_next_frame) { 1264 if (newstate == parse_state_next_frame) {
@@ -1344,10 +1278,9 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
1344 PDEBUG(DBG_PARSE, "Wake up !"); 1278 PDEBUG(DBG_PARSE, "Wake up !");
1345 wake_up_interruptible(&usbvision->wait_frame); 1279 wake_up_interruptible(&usbvision->wait_frame);
1346 } 1280 }
1347 } 1281 } else {
1348 else
1349 frame->grabstate = frame_state_grabbing; 1282 frame->grabstate = frame_state_grabbing;
1350 1283 }
1351 1284
1352 /* Update the frame's uncompressed length. */ 1285 /* Update the frame's uncompressed length. */
1353 frame->scanlength += copylen; 1286 frame->scanlength += copylen;
@@ -1381,14 +1314,12 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1381 PDEBUG(DBG_ISOC, "error packet [%d]", i); 1314 PDEBUG(DBG_ISOC, "error packet [%d]", i);
1382 usbvision->isoc_skip_count++; 1315 usbvision->isoc_skip_count++;
1383 continue; 1316 continue;
1384 } 1317 } else if (packet_len == 0) { /* Frame end ????? */
1385 else if (packet_len == 0) { /* Frame end ????? */
1386 PDEBUG(DBG_ISOC, "null packet [%d]", i); 1318 PDEBUG(DBG_ISOC, "null packet [%d]", i);
1387 usbvision->isocstate=isoc_state_no_frame; 1319 usbvision->isocstate = isoc_state_no_frame;
1388 usbvision->isoc_skip_count++; 1320 usbvision->isoc_skip_count++;
1389 continue; 1321 continue;
1390 } 1322 } else if (packet_len > usbvision->isoc_packet_size) {
1391 else if (packet_len > usbvision->isoc_packet_size) {
1392 PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i); 1323 PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i);
1393 usbvision->isoc_skip_count++; 1324 usbvision->isoc_skip_count++;
1394 continue; 1325 continue;
@@ -1396,8 +1327,8 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1396 1327
1397 PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len); 1328 PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len);
1398 1329
1399 if (usbvision->isocstate==isoc_state_no_frame) { /* new frame begins */ 1330 if (usbvision->isocstate == isoc_state_no_frame) { /* new frame begins */
1400 usbvision->isocstate=isoc_state_in_frame; 1331 usbvision->isocstate = isoc_state_in_frame;
1401 scratch_mark_header(usbvision); 1332 scratch_mark_header(usbvision);
1402 usbvision_measure_bandwidth(usbvision); 1333 usbvision_measure_bandwidth(usbvision);
1403 PDEBUG(DBG_ISOC, "packet with header"); 1334 PDEBUG(DBG_ISOC, "packet with header");
@@ -1412,7 +1343,6 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1412 * your favorite evil here. 1343 * your favorite evil here.
1413 */ 1344 */
1414 if (scratch_free(usbvision) < packet_len) { 1345 if (scratch_free(usbvision) < packet_len) {
1415
1416 usbvision->scratch_ovf_count++; 1346 usbvision->scratch_ovf_count++;
1417 PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d", 1347 PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d",
1418 scratch_len(usbvision), packet_len); 1348 scratch_len(usbvision), packet_len);
@@ -1428,6 +1358,7 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1428#if ENABLE_HEXDUMP 1358#if ENABLE_HEXDUMP
1429 if (totlen > 0) { 1359 if (totlen > 0) {
1430 static int foo; 1360 static int foo;
1361
1431 if (foo < 1) { 1362 if (foo < 1) {
1432 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen); 1363 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
1433 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen); 1364 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
@@ -1435,7 +1366,7 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1435 } 1366 }
1436 } 1367 }
1437#endif 1368#endif
1438 return totlen; 1369 return totlen;
1439} 1370}
1440 1371
1441static void usbvision_isoc_irq(struct urb *urb) 1372static void usbvision_isoc_irq(struct urb *urb)
@@ -1452,9 +1383,8 @@ static void usbvision_isoc_irq(struct urb *urb)
1452 return; 1383 return;
1453 1384
1454 /* any urb with wrong status is ignored without acknowledgement */ 1385 /* any urb with wrong status is ignored without acknowledgement */
1455 if (urb->status == -ENOENT) { 1386 if (urb->status == -ENOENT)
1456 return; 1387 return;
1457 }
1458 1388
1459 f = &usbvision->cur_frame; 1389 f = &usbvision->cur_frame;
1460 1390
@@ -1476,26 +1406,23 @@ static void usbvision_isoc_irq(struct urb *urb)
1476 usbvision->urb_length = len; 1406 usbvision->urb_length = len;
1477 1407
1478 if (usbvision->streaming == stream_on) { 1408 if (usbvision->streaming == stream_on) {
1479
1480 /* If we collected enough data let's parse! */ 1409 /* If we collected enough data let's parse! */
1481 if ((scratch_len(usbvision) > USBVISION_HEADER_LENGTH) && 1410 if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH &&
1482 (!list_empty(&(usbvision->inqueue))) ) { 1411 !list_empty(&(usbvision->inqueue))) {
1483 if (!(*f)) { 1412 if (!(*f)) {
1484 (*f) = list_entry(usbvision->inqueue.next, 1413 (*f) = list_entry(usbvision->inqueue.next,
1485 struct usbvision_frame, 1414 struct usbvision_frame,
1486 frame); 1415 frame);
1487 } 1416 }
1488 usbvision_parse_data(usbvision); 1417 usbvision_parse_data(usbvision);
1489 } 1418 } else {
1490 else {
1491 /* If we don't have a frame 1419 /* If we don't have a frame
1492 we're current working on, complain */ 1420 we're current working on, complain */
1493 PDEBUG(DBG_IRQ, 1421 PDEBUG(DBG_IRQ,
1494 "received data, but no one needs it"); 1422 "received data, but no one needs it");
1495 scratch_reset(usbvision); 1423 scratch_reset(usbvision);
1496 } 1424 }
1497 } 1425 } else {
1498 else {
1499 PDEBUG(DBG_IRQ, "received data, but no one needs it"); 1426 PDEBUG(DBG_IRQ, "received data, but no one needs it");
1500 scratch_reset(usbvision); 1427 scratch_reset(usbvision);
1501 } 1428 }
@@ -1509,9 +1436,9 @@ static void usbvision_isoc_irq(struct urb *urb)
1509 1436
1510 urb->status = 0; 1437 urb->status = 0;
1511 urb->dev = usbvision->dev; 1438 urb->dev = usbvision->dev;
1512 err_code = usb_submit_urb (urb, GFP_ATOMIC); 1439 err_code = usb_submit_urb(urb, GFP_ATOMIC);
1513 1440
1514 if(err_code) { 1441 if (err_code) {
1515 dev_err(&usbvision->dev->dev, 1442 dev_err(&usbvision->dev->dev,
1516 "%s: usb_submit_urb failed: error %d\n", 1443 "%s: usb_submit_urb failed: error %d\n",
1517 __func__, err_code); 1444 __func__, err_code);
@@ -1587,24 +1514,21 @@ static void usbvision_ctrl_urb_complete(struct urb *urb)
1587 1514
1588 PDEBUG(DBG_IRQ, ""); 1515 PDEBUG(DBG_IRQ, "");
1589 usbvision->ctrl_urb_busy = 0; 1516 usbvision->ctrl_urb_busy = 0;
1590 if (waitqueue_active(&usbvision->ctrl_urb_wq)) { 1517 if (waitqueue_active(&usbvision->ctrl_urb_wq))
1591 wake_up_interruptible(&usbvision->ctrl_urb_wq); 1518 wake_up_interruptible(&usbvision->ctrl_urb_wq);
1592 }
1593} 1519}
1594 1520
1595 1521
1596static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address, 1522static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address,
1597 unsigned char *data, int len) 1523 unsigned char *data, int len)
1598{ 1524{
1599 int err_code = 0; 1525 int err_code = 0;
1600 1526
1601 PDEBUG(DBG_IRQ, ""); 1527 PDEBUG(DBG_IRQ, "");
1602 if (len > 8) { 1528 if (len > 8)
1603 return -EFAULT; 1529 return -EFAULT;
1604 } 1530 if (usbvision->ctrl_urb_busy)
1605 if (usbvision->ctrl_urb_busy) {
1606 return -EBUSY; 1531 return -EBUSY;
1607 }
1608 usbvision->ctrl_urb_busy = 1; 1532 usbvision->ctrl_urb_busy = 1;
1609 1533
1610 usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 1534 usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
@@ -1612,7 +1536,7 @@ static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address,
1612 usbvision->ctrl_urb_setup.wValue = 0; 1536 usbvision->ctrl_urb_setup.wValue = 0;
1613 usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address); 1537 usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address);
1614 usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len); 1538 usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len);
1615 usb_fill_control_urb (usbvision->ctrl_urb, usbvision->dev, 1539 usb_fill_control_urb(usbvision->ctrl_urb, usbvision->dev,
1616 usb_sndctrlpipe(usbvision->dev, 1), 1540 usb_sndctrlpipe(usbvision->dev, 1),
1617 (unsigned char *)&usbvision->ctrl_urb_setup, 1541 (unsigned char *)&usbvision->ctrl_urb_setup,
1618 (void *)usbvision->ctrl_urb_buffer, len, 1542 (void *)usbvision->ctrl_urb_buffer, len,
@@ -1652,7 +1576,7 @@ static int usbvision_init_compression(struct usb_usbvision *usbvision)
1652 * return: 0 : no error 1576 * return: 0 : no error
1653 * sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size 1577 * sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size
1654 */ 1578 */
1655static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision) 1579static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision)
1656{ 1580{
1657 int err_code = 0; 1581 int err_code = 0;
1658 1582
@@ -1672,7 +1596,7 @@ static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision)
1672 return err_code; 1596 return err_code;
1673} 1597}
1674 1598
1675static int usbvision_adjust_compression (struct usb_usbvision *usbvision) 1599static int usbvision_adjust_compression(struct usb_usbvision *usbvision)
1676{ 1600{
1677 int err_code = 0; 1601 int err_code = 0;
1678 unsigned char buffer[6]; 1602 unsigned char buffer[6];
@@ -1682,29 +1606,29 @@ static int usbvision_adjust_compression (struct usb_usbvision *usbvision)
1682 usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2; 1606 usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2;
1683 RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100); 1607 RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100);
1684 if (usbvision->compr_level != usbvision->last_compr_level) { 1608 if (usbvision->compr_level != usbvision->last_compr_level) {
1685 int distorsion; 1609 int distortion;
1610
1686 if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) { 1611 if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) {
1687 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */ 1612 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */
1688 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */ 1613 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */
1689 distorsion = 7 + 248 * usbvision->compr_level / 100; 1614 distortion = 7 + 248 * usbvision->compr_level / 100;
1690 buffer[2] = (unsigned char)(distorsion & 0xFF); /* Average distorsion Threshold (inter) */ 1615 buffer[2] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (inter) */
1691 buffer[3] = (unsigned char)(distorsion & 0xFF); /* Average distorsion Threshold (intra) */ 1616 buffer[3] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (intra) */
1692 distorsion = 1 + 42 * usbvision->compr_level / 100; 1617 distortion = 1 + 42 * usbvision->compr_level / 100;
1693 buffer[4] = (unsigned char)(distorsion & 0xFF); /* Maximum distorsion Threshold (inter) */ 1618 buffer[4] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (inter) */
1694 buffer[5] = (unsigned char)(distorsion & 0xFF); /* Maximum distorsion Threshold (intra) */ 1619 buffer[5] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (intra) */
1695 } 1620 } else { /* BRIDGE_NT1003 */
1696 else { /* BRIDGE_NT1003 */
1697 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */ 1621 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */
1698 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */ 1622 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */
1699 distorsion = 2 + 253 * usbvision->compr_level / 100; 1623 distortion = 2 + 253 * usbvision->compr_level / 100;
1700 buffer[2] = (unsigned char)(distorsion & 0xFF); /* distorsion threshold bit0-7 */ 1624 buffer[2] = (unsigned char)(distortion & 0xFF); /* distortion threshold bit0-7 */
1701 buffer[3] = 0; /* (unsigned char)((distorsion >> 8) & 0x0F); distorsion threshold bit 8-11 */ 1625 buffer[3] = 0; /* (unsigned char)((distortion >> 8) & 0x0F); distortion threshold bit 8-11 */
1702 distorsion = 0 + 43 * usbvision->compr_level / 100; 1626 distortion = 0 + 43 * usbvision->compr_level / 100;
1703 buffer[4] = (unsigned char)(distorsion & 0xFF); /* maximum distorsion bit0-7 */ 1627 buffer[4] = (unsigned char)(distortion & 0xFF); /* maximum distortion bit0-7 */
1704 buffer[5] = 0; /* (unsigned char)((distorsion >> 8) & 0x01); maximum distorsion bit 8 */ 1628 buffer[5] = 0; /* (unsigned char)((distortion >> 8) & 0x01); maximum distortion bit 8 */
1705 } 1629 }
1706 err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6); 1630 err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
1707 if (err_code == 0){ 1631 if (err_code == 0) {
1708 PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0], 1632 PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0],
1709 buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]); 1633 buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
1710 usbvision->last_compr_level = usbvision->compr_level; 1634 usbvision->last_compr_level = usbvision->compr_level;
@@ -1714,7 +1638,7 @@ static int usbvision_adjust_compression (struct usb_usbvision *usbvision)
1714 return err_code; 1638 return err_code;
1715} 1639}
1716 1640
1717static int usbvision_request_intra (struct usb_usbvision *usbvision) 1641static int usbvision_request_intra(struct usb_usbvision *usbvision)
1718{ 1642{
1719 int err_code = 0; 1643 int err_code = 0;
1720 unsigned char buffer[1]; 1644 unsigned char buffer[1];
@@ -1726,7 +1650,7 @@ static int usbvision_request_intra (struct usb_usbvision *usbvision)
1726 return err_code; 1650 return err_code;
1727} 1651}
1728 1652
1729static int usbvision_unrequest_intra (struct usb_usbvision *usbvision) 1653static int usbvision_unrequest_intra(struct usb_usbvision *usbvision)
1730{ 1654{
1731 int err_code = 0; 1655 int err_code = 0;
1732 unsigned char buffer[1]; 1656 unsigned char buffer[1];
@@ -1749,10 +1673,9 @@ int usbvision_power_off(struct usb_usbvision *usbvision)
1749 PDEBUG(DBG_FUNC, ""); 1673 PDEBUG(DBG_FUNC, "");
1750 1674
1751 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 1675 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
1752 if (err_code == 1) { 1676 if (err_code == 1)
1753 usbvision->power = 0; 1677 usbvision->power = 0;
1754 } 1678 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code);
1755 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code!=1)?"ERROR":"power is off", err_code);
1756 return err_code; 1679 return err_code;
1757} 1680}
1758 1681
@@ -1804,18 +1727,16 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1804{ 1727{
1805 int err_code = 0; 1728 int err_code = 0;
1806 int usb_width, usb_height; 1729 int usb_width, usb_height;
1807 unsigned int frame_rate=0, frame_drop=0; 1730 unsigned int frame_rate = 0, frame_drop = 0;
1808 unsigned char value[4]; 1731 unsigned char value[4];
1809 1732
1810 if (!USBVISION_IS_OPERATIONAL(usbvision)) { 1733 if (!USBVISION_IS_OPERATIONAL(usbvision))
1811 return 0; 1734 return 0;
1812 }
1813 1735
1814 if (width > MAX_USB_WIDTH) { 1736 if (width > MAX_USB_WIDTH) {
1815 usb_width = width / 2; 1737 usb_width = width / 2;
1816 usbvision->stretch_width = 2; 1738 usbvision->stretch_width = 2;
1817 } 1739 } else {
1818 else {
1819 usb_width = width; 1740 usb_width = width;
1820 usbvision->stretch_width = 1; 1741 usbvision->stretch_width = 1;
1821 } 1742 }
@@ -1823,8 +1744,7 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1823 if (height > MAX_USB_HEIGHT) { 1744 if (height > MAX_USB_HEIGHT) {
1824 usb_height = height / 2; 1745 usb_height = height / 2;
1825 usbvision->stretch_height = 2; 1746 usbvision->stretch_height = 2;
1826 } 1747 } else {
1827 else {
1828 usb_height = height; 1748 usb_height = height;
1829 usbvision->stretch_height = 1; 1749 usbvision->stretch_height = 1;
1830 } 1750 }
@@ -1859,28 +1779,23 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1859 usbvision->curheight = usbvision->stretch_height * usb_height; 1779 usbvision->curheight = usbvision->stretch_height * usb_height;
1860 } 1780 }
1861 1781
1862 if (usbvision->isoc_mode == ISOC_MODE_YUV422) { 1782 if (usbvision->isoc_mode == ISOC_MODE_YUV422)
1863 frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2); 1783 frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2);
1864 } 1784 else if (usbvision->isoc_mode == ISOC_MODE_YUV420)
1865 else if (usbvision->isoc_mode == ISOC_MODE_YUV420) {
1866 frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8); 1785 frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8);
1867 } 1786 else
1868 else {
1869 frame_rate = FRAMERATE_MAX; 1787 frame_rate = FRAMERATE_MAX;
1870 }
1871 1788
1872 if (usbvision->tvnorm_id & V4L2_STD_625_50) { 1789 if (usbvision->tvnorm_id & V4L2_STD_625_50)
1873 frame_drop = frame_rate * 32 / 25 - 1; 1790 frame_drop = frame_rate * 32 / 25 - 1;
1874 } 1791 else if (usbvision->tvnorm_id & V4L2_STD_525_60)
1875 else if (usbvision->tvnorm_id & V4L2_STD_525_60) {
1876 frame_drop = frame_rate * 32 / 30 - 1; 1792 frame_drop = frame_rate * 32 / 30 - 1;
1877 }
1878 1793
1879 RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX); 1794 RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX);
1880 1795
1881 PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop); 1796 PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop);
1882 1797
1883 frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */ 1798 frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */
1884 1799
1885 /* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ... 1800 /* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ...
1886 => frame_skip = 4; 1801 => frame_skip = 4;
@@ -1904,7 +1819,7 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1904 int i; 1819 int i;
1905 1820
1906 /* needs to be page aligned cause the buffers can be mapped individually! */ 1821 /* needs to be page aligned cause the buffers can be mapped individually! */
1907 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth * 1822 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
1908 usbvision->curheight * 1823 usbvision->curheight *
1909 usbvision->palette.bytes_per_pixel); 1824 usbvision->palette.bytes_per_pixel);
1910 1825
@@ -1912,9 +1827,9 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1912 usbvision->num_frames = number_of_frames; 1827 usbvision->num_frames = number_of_frames;
1913 while (usbvision->num_frames > 0) { 1828 while (usbvision->num_frames > 0) {
1914 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size; 1829 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
1915 if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) { 1830 usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
1831 if (usbvision->fbuf)
1916 break; 1832 break;
1917 }
1918 usbvision->num_frames--; 1833 usbvision->num_frames--;
1919 } 1834 }
1920 1835
@@ -1937,7 +1852,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1937 usbvision->frame[i].height = usbvision->curheight; 1852 usbvision->frame[i].height = usbvision->curheight;
1938 usbvision->frame[i].bytes_read = 0; 1853 usbvision->frame[i].bytes_read = 0;
1939 } 1854 }
1940 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size); 1855 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",
1856 usbvision->num_frames, usbvision->max_frame_size);
1941 return usbvision->num_frames; 1857 return usbvision->num_frames;
1942} 1858}
1943 1859
@@ -1948,7 +1864,7 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1948void usbvision_frames_free(struct usb_usbvision *usbvision) 1864void usbvision_frames_free(struct usb_usbvision *usbvision)
1949{ 1865{
1950 /* Have to free all that memory */ 1866 /* Have to free all that memory */
1951 PDEBUG(DBG_FUNC, "free %d frames",usbvision->num_frames); 1867 PDEBUG(DBG_FUNC, "free %d frames", usbvision->num_frames);
1952 1868
1953 if (usbvision->fbuf != NULL) { 1869 if (usbvision->fbuf != NULL) {
1954 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 1870 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
@@ -2033,18 +1949,17 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2033 if (usbvision->bridge_type == BRIDGE_NT1004) { 1949 if (usbvision->bridge_type == BRIDGE_NT1004) {
2034 value[0] = 20; /* PCM Threshold 1 */ 1950 value[0] = 20; /* PCM Threshold 1 */
2035 value[1] = 12; /* PCM Threshold 2 */ 1951 value[1] = 12; /* PCM Threshold 2 */
2036 value[2] = 255; /* Distorsion Threshold inter */ 1952 value[2] = 255; /* Distortion Threshold inter */
2037 value[3] = 255; /* Distorsion Threshold intra */ 1953 value[3] = 255; /* Distortion Threshold intra */
2038 value[4] = 43; /* Max Distorsion inter */ 1954 value[4] = 43; /* Max Distortion inter */
2039 value[5] = 43; /* Max Distorsion intra */ 1955 value[5] = 43; /* Max Distortion intra */
2040 } 1956 } else {
2041 else {
2042 value[0] = 20; /* PCM Threshold 1 */ 1957 value[0] = 20; /* PCM Threshold 1 */
2043 value[1] = 12; /* PCM Threshold 2 */ 1958 value[1] = 12; /* PCM Threshold 2 */
2044 value[2] = 255; /* Distorsion Threshold d7-d0 */ 1959 value[2] = 255; /* Distortion Threshold d7-d0 */
2045 value[3] = 0; /* Distorsion Threshold d11-d8 */ 1960 value[3] = 0; /* Distortion Threshold d11-d8 */
2046 value[4] = 43; /* Max Distorsion d7-d0 */ 1961 value[4] = 43; /* Max Distortion d7-d0 */
2047 value[5] = 0; /* Max Distorsion d8 */ 1962 value[5] = 0; /* Max Distortion d8 */
2048 } 1963 }
2049 1964
2050 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1965 if (!USBVISION_IS_OPERATIONAL(usbvision))
@@ -2059,10 +1974,7 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2059 if (rc < 0) { 1974 if (rc < 0) {
2060 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " 1975 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
2061 "reconnect or reload driver.\n", proc, rc); 1976 "reconnect or reload driver.\n", proc, rc);
2062 return rc;
2063 } 1977 }
2064
2065
2066 return rc; 1978 return rc;
2067} 1979}
2068 1980
@@ -2087,7 +1999,7 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2087 /* Set input format expected from decoder*/ 1999 /* Set input format expected from decoder*/
2088 if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) { 2000 if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) {
2089 value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1; 2001 value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1;
2090 } else if(usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { 2002 } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
2091 /* SAA7113 uses 8 bit output */ 2003 /* SAA7113 uses 8 bit output */
2092 value[0] = USBVISION_8_422_SYNC; 2004 value[0] = USBVISION_8_422_SYNC;
2093 } else { 2005 } else {
@@ -2135,8 +2047,8 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2135 } 2047 }
2136 2048
2137 if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) { 2049 if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) {
2138 value[4]=usbvision_device_data[usbvision->dev_model].x_offset & 0xff; 2050 value[4] = usbvision_device_data[usbvision->dev_model].x_offset & 0xff;
2139 value[5]=(usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8; 2051 value[5] = (usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8;
2140 } 2052 }
2141 2053
2142 if (adjust_x_offset != -1) { 2054 if (adjust_x_offset != -1) {
@@ -2145,8 +2057,8 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2145 } 2057 }
2146 2058
2147 if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) { 2059 if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) {
2148 value[6]=usbvision_device_data[usbvision->dev_model].y_offset & 0xff; 2060 value[6] = usbvision_device_data[usbvision->dev_model].y_offset & 0xff;
2149 value[7]=(usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8; 2061 value[7] = (usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8;
2150 } 2062 }
2151 2063
2152 if (adjust_y_offset != -1) { 2064 if (adjust_y_offset != -1) {
@@ -2167,15 +2079,14 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2167 2079
2168 dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */ 2080 dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */
2169 2081
2170 if(usbvision_device_data[usbvision->dev_model].dvi_yuv_override){ 2082 if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) {
2171 dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv; 2083 dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv;
2172 } 2084 } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
2173 else if(usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { 2085 /* This changes as the fine sync control changes. Further investigation necessary */
2174 /* This changes as the fine sync control changes. Further investigation necessary */
2175 dvi_yuv_value = 0x06; 2086 dvi_yuv_value = 0x06;
2176 } 2087 }
2177 2088
2178 return (usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value)); 2089 return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value);
2179} 2090}
2180 2091
2181 2092
@@ -2204,8 +2115,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2204 /* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */ 2115 /* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */
2205 /* FDL: 0x00000-0x0E099 = 57498 Words */ 2116 /* FDL: 0x00000-0x0E099 = 57498 Words */
2206 /* VDW: 0x0E3FF-0x3FFFF */ 2117 /* VDW: 0x0E3FF-0x3FFFF */
2207 } 2118 } else {
2208 else {
2209 value[0] = 0x42; 2119 value[0] = 0x42;
2210 value[1] = 0x00; 2120 value[1] = 0x00;
2211 value[2] = 0xff; 2121 value[2] = 0xff;
@@ -2218,14 +2128,14 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2218 /* These are the values of the address of the video buffer, 2128 /* These are the values of the address of the video buffer,
2219 * they have to be loaded into the USBVISION_DRM_PRM1-8 2129 * they have to be loaded into the USBVISION_DRM_PRM1-8
2220 * 2130 *
2221 * Start address of video output buffer for read: drm_prm1-2 -> 0x00000 2131 * Start address of video output buffer for read: drm_prm1-2 -> 0x00000
2222 * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff 2132 * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff
2223 * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000 2133 * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000
2224 * Only used in compressed mode 2134 * Only used in compressed mode
2225 * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff 2135 * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff
2226 * Only used in compressed mode 2136 * Only used in compressed mode
2227 * Start address of video output buffer for write: drm_prm1-7 -> 0x00000 2137 * Start address of video output buffer for write: drm_prm1-7 -> 0x00000
2228 * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff 2138 * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff
2229 */ 2139 */
2230 2140
2231 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2141 if (!USBVISION_IS_OPERATIONAL(usbvision))
@@ -2243,8 +2153,9 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2243 } 2153 }
2244 2154
2245 /* Restart the video buffer logic */ 2155 /* Restart the video buffer logic */
2246 if ((rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR | 2156 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
2247 USBVISION_RES_FDL | USBVISION_RES_VDW)) < 0) 2157 USBVISION_RES_FDL | USBVISION_RES_VDW);
2158 if (rc < 0)
2248 return rc; 2159 return rc;
2249 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00); 2160 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
2250 2161
@@ -2267,16 +2178,15 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
2267 2178
2268 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2179 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2269 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2180 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2270 USBVISION_SSPND_EN | USBVISION_RES2); 2181 USBVISION_SSPND_EN | USBVISION_RES2);
2271 2182
2272 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2183 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2273 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2184 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2274 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2185 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2275 USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2); 2186 USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2);
2276 if (err_code == 1) { 2187 if (err_code == 1)
2277 usbvision->power = 1; 2188 usbvision->power = 1;
2278 } 2189 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code);
2279 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code<0)?"ERROR":"power is on", err_code);
2280 return err_code; 2190 return err_code;
2281} 2191}
2282 2192
@@ -2294,7 +2204,7 @@ static void call_usbvision_power_off(struct work_struct *work)
2294 if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 2204 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
2295 return; 2205 return;
2296 2206
2297 if(usbvision->user == 0) { 2207 if (usbvision->user == 0) {
2298 usbvision_i2c_unregister(usbvision); 2208 usbvision_i2c_unregister(usbvision);
2299 2209
2300 usbvision_power_off(usbvision); 2210 usbvision_power_off(usbvision);
@@ -2305,7 +2215,7 @@ static void call_usbvision_power_off(struct work_struct *work)
2305 2215
2306static void usbvision_power_off_timer(unsigned long data) 2216static void usbvision_power_off_timer(unsigned long data)
2307{ 2217{
2308 struct usb_usbvision *usbvision = (void *) data; 2218 struct usb_usbvision *usbvision = (void *)data;
2309 2219
2310 PDEBUG(DBG_FUNC, ""); 2220 PDEBUG(DBG_FUNC, "");
2311 del_timer(&usbvision->power_off_timer); 2221 del_timer(&usbvision->power_off_timer);
@@ -2316,7 +2226,7 @@ static void usbvision_power_off_timer(unsigned long data)
2316void usbvision_init_power_off_timer(struct usb_usbvision *usbvision) 2226void usbvision_init_power_off_timer(struct usb_usbvision *usbvision)
2317{ 2227{
2318 init_timer(&usbvision->power_off_timer); 2228 init_timer(&usbvision->power_off_timer);
2319 usbvision->power_off_timer.data = (long) usbvision; 2229 usbvision->power_off_timer.data = (long)usbvision;
2320 usbvision->power_off_timer.function = usbvision_power_off_timer; 2230 usbvision->power_off_timer.function = usbvision_power_off_timer;
2321} 2231}
2322 2232
@@ -2327,9 +2237,8 @@ void usbvision_set_power_off_timer(struct usb_usbvision *usbvision)
2327 2237
2328void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision) 2238void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
2329{ 2239{
2330 if (timer_pending(&usbvision->power_off_timer)) { 2240 if (timer_pending(&usbvision->power_off_timer))
2331 del_timer(&usbvision->power_off_timer); 2241 del_timer(&usbvision->power_off_timer);
2332 }
2333} 2242}
2334 2243
2335/* 2244/*
@@ -2339,14 +2248,10 @@ void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
2339 */ 2248 */
2340int usbvision_begin_streaming(struct usb_usbvision *usbvision) 2249int usbvision_begin_streaming(struct usb_usbvision *usbvision)
2341{ 2250{
2342 int err_code = 0; 2251 if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
2343
2344 if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
2345 usbvision_init_compression(usbvision); 2252 usbvision_init_compression(usbvision);
2346 } 2253 return usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2347 err_code = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, USBVISION_NOHVALID | 2254 USBVISION_NOHVALID | usbvision->vin_reg2_preset);
2348 usbvision->vin_reg2_preset);
2349 return err_code;
2350} 2255}
2351 2256
2352/* 2257/*
@@ -2358,25 +2263,24 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2358{ 2263{
2359 int ret; 2264 int ret;
2360 2265
2361 if ( 2266 ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2362 (ret = 2267 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2363 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2268 if (ret < 0)
2364 USBVISION_SSPND_EN | USBVISION_PWR_VID)) < 0)
2365 return ret; 2269 return ret;
2366 if ( 2270 ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2367 (ret =
2368 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2369 USBVISION_SSPND_EN | USBVISION_PWR_VID | 2271 USBVISION_SSPND_EN | USBVISION_PWR_VID |
2370 USBVISION_RES2)) < 0) 2272 USBVISION_RES2);
2273 if (ret < 0)
2371 return ret; 2274 return ret;
2372 if ( 2275 ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2373 (ret =
2374 usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2375 USBVISION_KEEP_BLANK | USBVISION_NOHVALID | 2276 USBVISION_KEEP_BLANK | USBVISION_NOHVALID |
2376 usbvision->vin_reg2_preset)) < 0) return ret; 2277 usbvision->vin_reg2_preset);
2278 if (ret < 0)
2279 return ret;
2377 2280
2378 /* TODO: schedule timeout */ 2281 /* TODO: schedule timeout */
2379 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1); 2282 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1)
2283 ;
2380 2284
2381 return 0; 2285 return 0;
2382} 2286}
@@ -2384,7 +2288,7 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2384int usbvision_audio_off(struct usb_usbvision *usbvision) 2288int usbvision_audio_off(struct usb_usbvision *usbvision)
2385{ 2289{
2386 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) { 2290 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
2387 printk(KERN_ERR "usbvision_audio_off: can't wirte reg\n"); 2291 printk(KERN_ERR "usbvision_audio_off: can't write reg\n");
2388 return -1; 2292 return -1;
2389 } 2293 }
2390 usbvision->audio_mute = 0; 2294 usbvision->audio_mute = 0;
@@ -2404,7 +2308,7 @@ int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel)
2404 return 0; 2308 return 0;
2405} 2309}
2406 2310
2407int usbvision_setup(struct usb_usbvision *usbvision,int format) 2311int usbvision_setup(struct usb_usbvision *usbvision, int format)
2408{ 2312{
2409 usbvision_set_video_format(usbvision, format); 2313 usbvision_set_video_format(usbvision, format);
2410 usbvision_set_dram_settings(usbvision); 2314 usbvision_set_dram_settings(usbvision);
@@ -2422,14 +2326,15 @@ int usbvision_set_alternate(struct usb_usbvision *dev)
2422 int err_code, prev_alt = dev->iface_alt; 2326 int err_code, prev_alt = dev->iface_alt;
2423 int i; 2327 int i;
2424 2328
2425 dev->iface_alt=0; 2329 dev->iface_alt = 0;
2426 for(i=0;i< dev->num_alt; i++) 2330 for (i = 0; i < dev->num_alt; i++)
2427 if(dev->alt_max_pkt_size[i]>dev->alt_max_pkt_size[dev->iface_alt]) 2331 if (dev->alt_max_pkt_size[i] > dev->alt_max_pkt_size[dev->iface_alt])
2428 dev->iface_alt=i; 2332 dev->iface_alt = i;
2429 2333
2430 if (dev->iface_alt != prev_alt) { 2334 if (dev->iface_alt != prev_alt) {
2431 dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt]; 2335 dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt];
2432 PDEBUG(DBG_FUNC,"setting alternate %d with max_packet_size=%u", dev->iface_alt,dev->isoc_packet_size); 2336 PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u",
2337 dev->iface_alt, dev->isoc_packet_size);
2433 err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt); 2338 err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt);
2434 if (err_code < 0) { 2339 if (err_code < 0) {
2435 dev_err(&dev->dev->dev, 2340 dev_err(&dev->dev->dev,
@@ -2549,7 +2454,7 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2549 /* Unschedule all of the iso td's */ 2454 /* Unschedule all of the iso td's */
2550 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { 2455 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
2551 usb_kill_urb(usbvision->sbuf[buf_idx].urb); 2456 usb_kill_urb(usbvision->sbuf[buf_idx].urb);
2552 if (usbvision->sbuf[buf_idx].data){ 2457 if (usbvision->sbuf[buf_idx].data) {
2553 usb_free_coherent(usbvision->dev, 2458 usb_free_coherent(usbvision->dev,
2554 sb_size, 2459 sb_size,
2555 usbvision->sbuf[buf_idx].data, 2460 usbvision->sbuf[buf_idx].data,
@@ -2563,9 +2468,8 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2563 usbvision->streaming = stream_off; 2468 usbvision->streaming = stream_off;
2564 2469
2565 if (!usbvision->remove_pending) { 2470 if (!usbvision->remove_pending) {
2566
2567 /* Set packet size to 0 */ 2471 /* Set packet size to 0 */
2568 usbvision->iface_alt=0; 2472 usbvision->iface_alt = 0;
2569 err_code = usb_set_interface(usbvision->dev, usbvision->iface, 2473 err_code = usb_set_interface(usbvision->dev, usbvision->iface,
2570 usbvision->iface_alt); 2474 usbvision->iface_alt);
2571 if (err_code < 0) { 2475 if (err_code < 0) {
@@ -2590,8 +2494,8 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2590{ 2494{
2591 /* inputs #0 and #3 are constant for every SAA711x. */ 2495 /* inputs #0 and #3 are constant for every SAA711x. */
2592 /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */ 2496 /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */
2593 int mode[4]= {SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3}; 2497 int mode[4] = { SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3 };
2594 int audio[]= {1, 0, 0, 0}; 2498 int audio[] = { 1, 0, 0, 0 };
2595 /* channel 0 is TV with audiochannel 1 (tuner mono) */ 2499 /* channel 0 is TV with audiochannel 1 (tuner mono) */
2596 /* channel 1 is Composite with audio channel 0 (line in) */ 2500 /* channel 1 is Composite with audio channel 0 (line in) */
2597 /* channel 2 is S-Video with audio channel 0 (line in) */ 2501 /* channel 2 is S-Video with audio channel 0 (line in) */
@@ -2605,24 +2509,23 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2605 /* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */ 2509 /* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */
2606 2510
2607 switch (usbvision_device_data[usbvision->dev_model].codec) { 2511 switch (usbvision_device_data[usbvision->dev_model].codec) {
2608 case CODEC_SAA7113: 2512 case CODEC_SAA7113:
2609 mode[1] = SAA7115_COMPOSITE2; 2513 mode[1] = SAA7115_COMPOSITE2;
2610 if (switch_svideo_input) { 2514 if (switch_svideo_input) {
2611 /* To handle problems with S-Video Input for 2515 /* To handle problems with S-Video Input for
2612 * some devices. Use switch_svideo_input 2516 * some devices. Use switch_svideo_input
2613 * parameter when loading the module.*/ 2517 * parameter when loading the module.*/
2614 mode[2] = SAA7115_COMPOSITE1; 2518 mode[2] = SAA7115_COMPOSITE1;
2615 } 2519 } else {
2616 else {
2617 mode[2] = SAA7115_SVIDEO1;
2618 }
2619 break;
2620 case CODEC_SAA7111:
2621 default:
2622 /* modes for saa7111 */
2623 mode[1] = SAA7115_COMPOSITE1;
2624 mode[2] = SAA7115_SVIDEO1; 2520 mode[2] = SAA7115_SVIDEO1;
2625 break; 2521 }
2522 break;
2523 case CODEC_SAA7111:
2524 default:
2525 /* modes for saa7111 */
2526 mode[1] = SAA7115_COMPOSITE1;
2527 mode[2] = SAA7115_SVIDEO1;
2528 break;
2626 } 2529 }
2627 call_all(usbvision, video, s_routing, mode[channel], 0, 0); 2530 call_all(usbvision, video, s_routing, mode[channel], 0, 0);
2628 usbvision_set_audio(usbvision, audio[channel]); 2531 usbvision_set_audio(usbvision, audio[channel]);