2006-12-04 19:30:53 +08:00
|
|
|
/*
|
2006-12-04 19:31:45 +08:00
|
|
|
* usbvision-core.c - driver for NT100x USB video capture devices
|
2006-12-09 22:43:31 +08:00
|
|
|
*
|
2006-12-04 19:30:53 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
|
2006-12-04 19:31:45 +08:00
|
|
|
* Dwaine Garden <dwainegarden@rogers.com>
|
2006-12-04 19:30:53 +08:00
|
|
|
*
|
|
|
|
* This module is part of usbvision driver project.
|
2006-12-04 19:31:45 +08:00
|
|
|
* Updates to driver completed by Dwaine P. Garden
|
2006-12-04 19:30:53 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/timer.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2006-12-04 19:30:53 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
2010-12-30 00:53:21 +08:00
|
|
|
#include <linux/io.h>
|
2006-12-04 19:30:53 +08:00
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
|
2006-12-04 19:31:11 +08:00
|
|
|
#include <media/saa7115.h>
|
|
|
|
#include <media/v4l2-common.h>
|
2006-12-04 19:30:53 +08:00
|
|
|
#include <media/tuner.h>
|
|
|
|
|
2006-12-09 22:41:59 +08:00
|
|
|
#include <linux/workqueue.h>
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
#include "usbvision.h"
|
|
|
|
|
2008-04-23 01:41:48 +08:00
|
|
|
static unsigned int core_debug;
|
2010-12-30 00:53:21 +08:00
|
|
|
module_param(core_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static int adjust_compression = 1; /* Set the compression to be adaptive */
|
|
|
|
module_param(adjust_compression, int, 0444);
|
|
|
|
MODULE_PARM_DESC(adjust_compression, " Set the ADPCM compression for the device. Default: 1 (On)");
|
2006-12-04 19:31:45 +08:00
|
|
|
|
2008-04-23 01:41:48 +08:00
|
|
|
/* To help people with Black and White output with using s-video input.
|
|
|
|
* Some cables and input device are wired differently. */
|
2010-12-20 07:21:36 +08:00
|
|
|
static int switch_svideo_input;
|
|
|
|
module_param(switch_svideo_input, int, 0444);
|
|
|
|
MODULE_PARM_DESC(switch_svideo_input, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)");
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static unsigned int adjust_x_offset = -1;
|
|
|
|
module_param(adjust_x_offset, int, 0644);
|
|
|
|
MODULE_PARM_DESC(adjust_x_offset, "adjust X offset display [core]");
|
2008-01-10 04:34:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static unsigned int adjust_y_offset = -1;
|
|
|
|
module_param(adjust_y_offset, int, 0644);
|
|
|
|
MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]");
|
2008-01-10 04:34:53 +08:00
|
|
|
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
#define ENABLE_HEXDUMP 0 /* Enable if you need it */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef USBVISION_DEBUG
|
2008-04-05 08:00:57 +08:00
|
|
|
#define PDEBUG(level, fmt, args...) { \
|
|
|
|
if (core_debug & (level)) \
|
2008-10-10 16:08:23 +08:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
|
|
|
|
__func__, __LINE__ , ## args); \
|
2008-04-05 08:00:57 +08:00
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
#else
|
2010-12-30 00:53:21 +08:00
|
|
|
#define PDEBUG(level, fmt, args...) do {} while (0)
|
2006-12-04 19:30:53 +08:00
|
|
|
#endif
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
#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)
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
static const int max_imgwidth = MAX_FRAME_WIDTH;
|
|
|
|
static const int max_imgheight = MAX_FRAME_HEIGHT;
|
|
|
|
static const int min_imgwidth = MIN_FRAME_WIDTH;
|
|
|
|
static const int min_imgheight = MIN_FRAME_HEIGHT;
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/* The value of 'scratch_buf_size' affects quality of the picture
|
2006-12-04 19:30:53 +08:00
|
|
|
* in many ways. Shorter buffers may cause loss of data when client
|
|
|
|
* is too slow. Larger buffers are memory-consuming and take longer
|
|
|
|
* to work with. This setting can be adjusted, but the default value
|
|
|
|
* should be OK for most desktop users.
|
|
|
|
*/
|
2010-12-20 07:33:51 +08:00
|
|
|
#define DEFAULT_SCRATCH_BUF_SIZE (0x20000) /* 128kB memory scratch buffer */
|
2006-12-04 19:30:53 +08:00
|
|
|
static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE;
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* Function prototypes */
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_request_intra(struct usb_usbvision *usbvision);
|
|
|
|
static int usbvision_unrequest_intra(struct usb_usbvision *usbvision);
|
|
|
|
static int usbvision_adjust_compression(struct usb_usbvision *usbvision);
|
|
|
|
static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/*******************************/
|
|
|
|
/* Memory management functions */
|
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we want the physical address of the memory.
|
|
|
|
* This is used when initializing the contents of the area.
|
|
|
|
*/
|
|
|
|
|
2006-12-12 02:51:36 +08:00
|
|
|
static void *usbvision_rvmalloc(unsigned long size)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
unsigned long adr;
|
|
|
|
|
|
|
|
size = PAGE_ALIGN(size);
|
|
|
|
mem = vmalloc_32(size);
|
|
|
|
if (!mem)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(mem, 0, size); /* Clear the ram out, no junk to the user */
|
2006-12-04 19:31:45 +08:00
|
|
|
adr = (unsigned long) mem;
|
|
|
|
while (size > 0) {
|
|
|
|
SetPageReserved(vmalloc_to_page((void *)adr));
|
|
|
|
adr += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-29 20:57:26 +08:00
|
|
|
static void usbvision_rvfree(void *mem, unsigned long size)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2006-12-04 19:31:45 +08:00
|
|
|
unsigned long adr;
|
|
|
|
|
|
|
|
if (!mem)
|
|
|
|
return;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
size = PAGE_ALIGN(size);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
adr = (unsigned long) mem;
|
|
|
|
while ((long) size > 0) {
|
|
|
|
ClearPageReserved(vmalloc_to_page((void *)adr));
|
|
|
|
adr += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
vfree(mem);
|
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if ENABLE_HEXDUMP
|
|
|
|
static void usbvision_hexdump(const unsigned char *data, int len)
|
|
|
|
{
|
2006-12-04 19:31:45 +08:00
|
|
|
char tmp[80];
|
|
|
|
int i, k;
|
|
|
|
|
|
|
|
for (i = k = 0; len > 0; i++, len--) {
|
|
|
|
if (i > 0 && (i % 16 == 0)) {
|
|
|
|
printk("%s\n", tmp);
|
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
k += sprintf(&tmp[k], "%02x ", data[i]);
|
|
|
|
}
|
|
|
|
if (k > 0)
|
2010-12-30 00:53:21 +08:00
|
|
|
printk(KERN_CONT "%s\n", tmp);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/********************************
|
|
|
|
* scratch ring buffer handling
|
|
|
|
********************************/
|
2010-12-20 07:33:51 +08:00
|
|
|
static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
|
2010-12-30 00:53:21 +08:00
|
|
|
|
|
|
|
if (len < 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
len += scratch_buf_size;
|
|
|
|
PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This returns the free space left in the buffer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static int scratch_free(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
|
2010-12-30 00:53:21 +08:00
|
|
|
if (free <= 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
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 */
|
|
|
|
}
|
|
|
|
PDEBUG(DBG_SCRATCH, "return %d\n", free);
|
|
|
|
|
|
|
|
return free;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This puts data into the buffer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
|
|
|
|
int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int len_part;
|
|
|
|
|
|
|
|
if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
|
|
|
|
memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
|
|
|
|
usbvision->scratch_write_ptr += len;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
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 */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
memcpy(usbvision->scratch, data + len_part, len - len_part);
|
|
|
|
usbvision->scratch_write_ptr = len - len_part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "len=%d, new write_ptr=%d\n", len, usbvision->scratch_write_ptr);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This marks the write_ptr as position of new frame header */
|
2006-12-12 02:51:36 +08:00
|
|
|
static void scratch_mark_header(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
|
|
|
|
|
|
|
|
usbvision->scratch_headermarker[usbvision->scratch_headermarker_write_ptr] =
|
|
|
|
usbvision->scratch_write_ptr;
|
|
|
|
usbvision->scratch_headermarker_write_ptr += 1;
|
|
|
|
usbvision->scratch_headermarker_write_ptr %= USBVISION_NUM_HEADERMARKER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This gets data from the buffer at the given "ptr" position */
|
2006-12-12 02:51:36 +08:00
|
|
|
static int scratch_get_extra(struct usb_usbvision *usbvision,
|
|
|
|
unsigned char *data, int *ptr, int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int len_part;
|
2010-12-30 00:53:21 +08:00
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
if (*ptr + len < scratch_buf_size) {
|
|
|
|
memcpy(data, usbvision->scratch + *ptr, len);
|
|
|
|
*ptr += len;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
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 */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
memcpy(data + len_part, usbvision->scratch, len - len_part);
|
|
|
|
*ptr = len - len_part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "len=%d, new ptr=%d\n", len, *ptr);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This sets the scratch extra read pointer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
|
|
|
|
int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-30 00:53:21 +08:00
|
|
|
*ptr = (usbvision->scratch_read_ptr + len) % scratch_buf_size;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* This increments the scratch extra read pointer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static void scratch_inc_extra_ptr(int *ptr, int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
*ptr = (*ptr + len) % scratch_buf_size;
|
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This gets data from the buffer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
|
|
|
|
int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int len_part;
|
2010-12-30 00:53:21 +08:00
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
|
|
|
|
memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
|
|
|
|
usbvision->scratch_read_ptr += len;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
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 */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
memcpy(data + len_part, usbvision->scratch, len - len_part);
|
|
|
|
usbvision->scratch_read_ptr = len - len_part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "len=%d, new read_ptr=%d\n", len, usbvision->scratch_read_ptr);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This sets read pointer to next header and returns it */
|
2006-12-12 02:51:36 +08:00
|
|
|
static int scratch_get_header(struct usb_usbvision *usbvision,
|
|
|
|
struct usbvision_frame_header *header)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr);
|
|
|
|
|
|
|
|
while (usbvision->scratch_headermarker_write_ptr -
|
|
|
|
usbvision->scratch_headermarker_read_ptr != 0) {
|
|
|
|
usbvision->scratch_read_ptr =
|
|
|
|
usbvision->scratch_headermarker[usbvision->scratch_headermarker_read_ptr];
|
|
|
|
usbvision->scratch_headermarker_read_ptr += 1;
|
|
|
|
usbvision->scratch_headermarker_read_ptr %= USBVISION_NUM_HEADERMARKER;
|
|
|
|
scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH);
|
|
|
|
if ((header->magic_1 == USBVISION_MAGIC_1)
|
|
|
|
&& (header->magic_2 == USBVISION_MAGIC_2)
|
2010-12-20 07:21:36 +08:00
|
|
|
&& (header->header_length == USBVISION_HEADER_LENGTH)) {
|
|
|
|
err_code = USBVISION_HEADER_LENGTH;
|
|
|
|
header->frame_width = header->frame_width_lo + (header->frame_width_hi << 8);
|
|
|
|
header->frame_height = header->frame_height_lo + (header->frame_height_hi << 8);
|
2006-12-04 19:30:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* This removes len bytes of old data from the buffer */
|
2006-12-12 02:51:36 +08:00
|
|
|
static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* This resets the buffer - kills all data in it too */
|
2006-12-12 02:51:36 +08:00
|
|
|
static void scratch_reset(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
PDEBUG(DBG_SCRATCH, "\n");
|
|
|
|
|
|
|
|
usbvision->scratch_read_ptr = 0;
|
|
|
|
usbvision->scratch_write_ptr = 0;
|
|
|
|
usbvision->scratch_headermarker_read_ptr = 0;
|
|
|
|
usbvision->scratch_headermarker_write_ptr = 0;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isocstate = isoc_state_no_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2006-12-16 03:46:53 +08:00
|
|
|
usbvision->scratch = vmalloc_32(scratch_buf_size);
|
2006-12-04 19:31:45 +08:00
|
|
|
scratch_reset(usbvision);
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->scratch == NULL) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: unable to allocate %d bytes for scratch\n",
|
|
|
|
__func__, scratch_buf_size);
|
2006-12-04 19:31:45 +08:00
|
|
|
return -ENOMEM;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2006-12-04 19:31:45 +08:00
|
|
|
return 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
void usbvision_scratch_free(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2009-06-11 21:33:31 +08:00
|
|
|
vfree(usbvision->scratch);
|
|
|
|
usbvision->scratch = NULL;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-12-04 19:31:45 +08:00
|
|
|
* usbvision_decompress_alloc()
|
|
|
|
*
|
|
|
|
* allocates intermediate buffer for decompression
|
2006-12-04 19:30:53 +08:00
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
|
2010-12-30 00:53:21 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
|
|
|
|
if (usbvision->intra_frame_buffer == NULL) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: unable to allocate %d for compr. frame buffer\n",
|
|
|
|
__func__, IFB_size);
|
2006-12-04 19:31:45 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_decompress_free()
|
|
|
|
*
|
|
|
|
* frees intermediate buffer for decompression
|
|
|
|
*/
|
|
|
|
void usbvision_decompress_free(struct usb_usbvision *usbvision)
|
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
vfree(usbvision->intra_frame_buffer);
|
|
|
|
usbvision->intra_frame_buffer = NULL;
|
2009-06-11 21:33:31 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* Here comes the data parsing stuff that is run as interrupt
|
|
|
|
************************************************************/
|
2006-12-04 19:30:53 +08:00
|
|
|
/*
|
|
|
|
* usbvision_find_header()
|
|
|
|
*
|
|
|
|
* Locate one of supported header markers in the scratch buffer.
|
|
|
|
*/
|
2010-12-20 07:21:36 +08:00
|
|
|
static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
struct usbvision_frame *frame;
|
2010-12-20 07:21:36 +08:00
|
|
|
int found_header = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
frame = usbvision->cur_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
while (scratch_get_header(usbvision, &frame->isoc_header) == USBVISION_HEADER_LENGTH) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* found header in scratch */
|
2006-12-04 19:30:53 +08:00
|
|
|
PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u",
|
2010-12-20 07:21:36 +08:00
|
|
|
frame->isoc_header.magic_2,
|
|
|
|
frame->isoc_header.magic_1,
|
|
|
|
frame->isoc_header.header_length,
|
|
|
|
frame->isoc_header.frame_num,
|
|
|
|
frame->isoc_header.frame_phase,
|
|
|
|
frame->isoc_header.frame_latency,
|
|
|
|
frame->isoc_header.data_format,
|
|
|
|
frame->isoc_header.format_param,
|
|
|
|
frame->isoc_header.frame_width,
|
|
|
|
frame->isoc_header.frame_height);
|
|
|
|
|
|
|
|
if (usbvision->request_intra) {
|
|
|
|
if (frame->isoc_header.format_param & 0x80) {
|
|
|
|
found_header = 1;
|
2010-12-20 07:33:51 +08:00
|
|
|
usbvision->last_isoc_frame_num = -1; /* do not check for lost frames this time */
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_unrequest_intra(usbvision);
|
|
|
|
break;
|
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
found_header = 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (found_header) {
|
|
|
|
frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width;
|
|
|
|
frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height;
|
2010-12-30 00:53:21 +08:00
|
|
|
frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3;
|
|
|
|
} else { /* no header found */
|
2006-12-04 19:30:53 +08:00
|
|
|
PDEBUG(DBG_HEADER, "skipping scratch data, no header");
|
|
|
|
scratch_reset(usbvision);
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_end_parse;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* found header */
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->isoc_header.data_format == ISOC_MODE_COMPRESS) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* check isoc_header.frame_num for lost frames */
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->last_isoc_frame_num >= 0) {
|
|
|
|
if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* unexpected frame drop: need to request new intra frame */
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isoc_header.frame_num);
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_request_intra(usbvision);
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->last_isoc_frame_num = frame->isoc_header.frame_num;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
usbvision->header_count++;
|
2010-12-20 07:21:36 +08:00
|
|
|
frame->scanstate = scan_state_lines;
|
2006-12-04 19:30:53 +08:00
|
|
|
frame->curline = 0;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_continue;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvision,
|
2006-12-04 19:30:53 +08:00
|
|
|
long *pcopylen)
|
|
|
|
{
|
|
|
|
volatile struct usbvision_frame *frame;
|
|
|
|
unsigned char *f;
|
|
|
|
int len;
|
|
|
|
int i;
|
2010-12-30 00:53:21 +08:00
|
|
|
unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */
|
2010-12-20 07:33:51 +08:00
|
|
|
unsigned char rv, gv, bv; /* RGB components */
|
2006-12-04 19:30:53 +08:00
|
|
|
int clipmask_index, bytes_per_pixel;
|
|
|
|
int stretch_bytes, clipmask_add;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
frame = usbvision->cur_frame;
|
2006-12-04 19:31:45 +08:00
|
|
|
f = frame->data + (frame->v4l2_linesize * frame->curline);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/* Make sure there's enough data for the entire line */
|
2010-12-30 00:53:21 +08:00
|
|
|
len = (frame->isoc_header.frame_width * 2) + 5;
|
2006-12-04 19:30:53 +08:00
|
|
|
if (scratch_len(usbvision) < len) {
|
|
|
|
PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len);
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_out;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if ((frame->curline + 1) >= frame->frmheight)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
|
|
|
|
stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
|
|
|
|
clipmask_index = frame->curline * MAX_FRAME_WIDTH;
|
|
|
|
clipmask_add = usbvision->stretch_width;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
|
2006-12-04 19:30:53 +08:00
|
|
|
scratch_get(usbvision, &yuyv[0], 4);
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2010-12-20 07:33:51 +08:00
|
|
|
*f++ = yuyv[0]; /* Y */
|
|
|
|
*f++ = yuyv[3]; /* U */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x07 & (gv >> 3)) |
|
|
|
|
(0xF8 & bv);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
f++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x03 & (gv >> 3)) |
|
|
|
|
(0x7C & (bv << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_index += clipmask_add;
|
|
|
|
f += stretch_bytes;
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2010-12-20 07:33:51 +08:00
|
|
|
*f++ = yuyv[2]; /* Y */
|
|
|
|
*f++ = yuyv[1]; /* V */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x07 & (gv >> 3)) |
|
|
|
|
(0xF8 & bv);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
f++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x03 & (gv >> 3)) |
|
|
|
|
(0x7C & (bv << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_index += clipmask_add;
|
|
|
|
f += stretch_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->curline += usbvision->stretch_height;
|
|
|
|
*pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->curline >= frame->frmheight)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2010-12-30 00:53:21 +08:00
|
|
|
return parse_state_continue;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/* The decompression routine */
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed,
|
2010-12-20 07:21:36 +08:00
|
|
|
unsigned char *decompressed, int *start_pos,
|
|
|
|
int *block_typestart_pos, int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2012-04-20 18:30:48 +08:00
|
|
|
int rest_pixel, idx, pos, extra_pos, block_len, block_type_pos, block_type_len;
|
2010-12-20 07:21:36 +08:00
|
|
|
unsigned char block_byte, block_code, block_type, block_type_byte, integrator;
|
|
|
|
|
|
|
|
integrator = 0;
|
|
|
|
pos = *start_pos;
|
|
|
|
block_type_pos = *block_typestart_pos;
|
|
|
|
extra_pos = pos;
|
|
|
|
block_len = 0;
|
|
|
|
block_byte = 0;
|
|
|
|
block_code = 0;
|
|
|
|
block_type = 0;
|
|
|
|
block_type_byte = 0;
|
|
|
|
block_type_len = 0;
|
|
|
|
rest_pixel = len;
|
|
|
|
|
|
|
|
for (idx = 0; idx < len; idx++) {
|
|
|
|
if (block_len == 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
if (block_type_len == 0) {
|
2010-12-20 07:21:36 +08:00
|
|
|
block_type_byte = compressed[block_type_pos];
|
|
|
|
block_type_pos++;
|
|
|
|
block_type_len = 4;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
block_type = (block_type_byte & 0xC0) >> 6;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* statistic: */
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->compr_block_types[block_type]++;
|
|
|
|
|
|
|
|
pos = extra_pos;
|
|
|
|
if (block_type == 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
if (rest_pixel >= 24) {
|
2010-12-20 07:21:36 +08:00
|
|
|
idx += 23;
|
|
|
|
rest_pixel -= 24;
|
|
|
|
integrator = decompressed[idx];
|
2006-12-04 19:30:53 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
idx += rest_pixel - 1;
|
|
|
|
rest_pixel = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
block_code = compressed[pos];
|
|
|
|
pos++;
|
2010-12-30 00:53:21 +08:00
|
|
|
if (rest_pixel >= 24)
|
2010-12-20 07:21:36 +08:00
|
|
|
block_len = 24;
|
2010-12-30 00:53:21 +08:00
|
|
|
else
|
2010-12-20 07:21:36 +08:00
|
|
|
block_len = rest_pixel;
|
|
|
|
rest_pixel -= block_len;
|
|
|
|
extra_pos = pos + (block_len / 4);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
block_type_byte <<= 2;
|
|
|
|
block_type_len -= 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
if (block_len > 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
if ((block_len % 4) == 0) {
|
2010-12-20 07:21:36 +08:00
|
|
|
block_byte = compressed[pos];
|
|
|
|
pos++;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
if (block_type == 1) /* inter Block */
|
2010-12-20 07:21:36 +08:00
|
|
|
integrator = decompressed[idx];
|
|
|
|
switch (block_byte & 0xC0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
case 0x03 << 6:
|
|
|
|
integrator += compressed[extra_pos];
|
|
|
|
extra_pos++;
|
|
|
|
break;
|
|
|
|
case 0x02 << 6:
|
|
|
|
integrator += block_code;
|
|
|
|
break;
|
|
|
|
case 0x00:
|
|
|
|
integrator -= block_code;
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
decompressed[idx] = integrator;
|
|
|
|
block_byte <<= 2;
|
|
|
|
block_len -= 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
*start_pos = extra_pos;
|
|
|
|
*block_typestart_pos = block_type_pos;
|
|
|
|
return idx;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_parse_compress()
|
|
|
|
*
|
|
|
|
* Parse compressed frame from the scratch buffer, put
|
|
|
|
* decoded RGB value into the current frame buffer and add the written
|
|
|
|
* number of bytes (RGB) to the *pcopylen.
|
|
|
|
*
|
|
|
|
*/
|
2010-12-20 07:21:36 +08:00
|
|
|
static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision,
|
2006-12-04 19:30:53 +08:00
|
|
|
long *pcopylen)
|
|
|
|
{
|
|
|
|
#define USBVISION_STRIP_MAGIC 0x5A
|
|
|
|
#define USBVISION_STRIP_LEN_MAX 400
|
|
|
|
#define USBVISION_STRIP_HEADER_LEN 3
|
|
|
|
|
|
|
|
struct usbvision_frame *frame;
|
2010-12-30 00:53:21 +08:00
|
|
|
unsigned char *f, *u = NULL, *v = NULL;
|
2010-12-20 07:21:36 +08:00
|
|
|
unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
|
|
|
|
unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
|
2010-12-30 00:53:21 +08:00
|
|
|
int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
|
2012-04-20 18:30:48 +08:00
|
|
|
int clipmask_index;
|
2010-12-20 07:21:36 +08:00
|
|
|
int image_size;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char rv, gv, bv;
|
|
|
|
static unsigned char *Y, *U, *V;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
frame = usbvision->cur_frame;
|
2010-12-20 07:21:36 +08:00
|
|
|
image_size = frame->frmwidth * frame->frmheight;
|
2010-12-30 00:53:21 +08:00
|
|
|
if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
|
|
|
|
(frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) { /* this is a planar format */
|
2010-12-20 07:33:51 +08:00
|
|
|
/* ... v4l2_linesize not used here. */
|
2006-12-04 19:31:45 +08:00
|
|
|
f = frame->data + (frame->width * frame->curline);
|
|
|
|
} else
|
|
|
|
f = frame->data + (frame->v4l2_linesize * frame->curline);
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
|
2010-12-20 07:33:51 +08:00
|
|
|
/* get base of u and b planes add halfoffset */
|
2006-12-04 19:31:45 +08:00
|
|
|
u = frame->data
|
2010-12-20 07:21:36 +08:00
|
|
|
+ image_size
|
2010-12-30 00:53:21 +08:00
|
|
|
+ (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);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->curline == 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_adjust_compression(usbvision);
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_out;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* get strip header without changing the scratch_read_ptr */
|
2010-12-20 07:21:36 +08:00
|
|
|
scratch_set_extra_ptr(usbvision, &strip_ptr, 0);
|
|
|
|
scratch_get_extra(usbvision, &strip_header[0], &strip_ptr,
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_STRIP_HEADER_LEN);
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (strip_header[0] != USBVISION_STRIP_MAGIC) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* wrong strip magic */
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->strip_magic_errors++;
|
|
|
|
return parse_state_next_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (frame->curline != (int)strip_header[2]) {
|
2010-12-30 00:53:21 +08:00
|
|
|
/* line number mismatch error */
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->strip_line_number_errors++;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
strip_len = 2 * (unsigned int)strip_header[1];
|
|
|
|
if (strip_len > USBVISION_STRIP_LEN_MAX) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* strip overrun */
|
|
|
|
/* I think this never happens */
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_request_intra(usbvision);
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (scratch_len(usbvision) < strip_len) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* there is not enough data for the strip */
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_out;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->intra_frame_buffer) {
|
|
|
|
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);
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clipmask_index = frame->curline * MAX_FRAME_WIDTH;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
scratch_get(usbvision, strip_data, strip_len);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
idx_end = frame->frmwidth;
|
|
|
|
block_type_pos = USBVISION_STRIP_HEADER_LEN;
|
2010-12-30 00:53:21 +08:00
|
|
|
startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2;
|
|
|
|
block_pos = startblock_pos;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->block_pos = block_pos;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2012-04-20 18:30:48 +08:00
|
|
|
usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end);
|
2010-12-30 00:53:21 +08:00
|
|
|
if (strip_len > usbvision->max_strip_len)
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->max_strip_len = strip_len;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->curline % 2)
|
2012-04-20 18:30:48 +08:00
|
|
|
usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2);
|
2010-12-30 00:53:21 +08:00
|
|
|
else
|
2012-04-20 18:30:48 +08:00
|
|
|
usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (block_pos > usbvision->comprblock_pos)
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->comprblock_pos = block_pos;
|
2010-12-30 00:53:21 +08:00
|
|
|
if (block_pos > strip_len)
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->strip_len_errors++;
|
2006-12-04 19:31:11 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
for (idx = 0; idx < idx_end; idx++) {
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2010-12-20 07:21:36 +08:00
|
|
|
*f++ = Y[idx];
|
2010-12-30 00:53:21 +08:00
|
|
|
*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
|
|
|
|
} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
|
2010-12-20 07:21:36 +08:00
|
|
|
*f++ = Y[idx];
|
2010-12-30 00:53:21 +08:00
|
|
|
if (idx & 0x01)
|
|
|
|
*u++ = U[idx >> 1];
|
2006-12-04 19:30:53 +08:00
|
|
|
else
|
2010-12-30 00:53:21 +08:00
|
|
|
*v++ = V[idx >> 1];
|
|
|
|
} 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];
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
|
|
|
YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
|
2006-12-04 19:30:53 +08:00
|
|
|
switch (frame->v4l2_format.format) {
|
2010-12-30 00:53:21 +08:00
|
|
|
case V4L2_PIX_FMT_GREY:
|
|
|
|
*f++ = Y[idx];
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x03 & (gv >> 3)) |
|
|
|
|
(0x7C & (bv << 2));
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
*f++ = (0x1F & rv) |
|
|
|
|
(0xE0 & (gv << 5));
|
|
|
|
*f++ = (0x07 & (gv >> 3)) |
|
|
|
|
(0xF8 & bv);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f++ = rv;
|
|
|
|
*f++ = gv;
|
|
|
|
*f++ = bv;
|
|
|
|
f++;
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_index++;
|
|
|
|
}
|
2006-12-04 19:31:11 +08:00
|
|
|
/* Deal with non-integer no. of bytes for YUV420P */
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420)
|
2006-12-04 19:31:11 +08:00
|
|
|
*pcopylen += frame->v4l2_linesize;
|
|
|
|
else
|
|
|
|
*pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
|
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
frame->curline += 1;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->curline >= frame->frmheight)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2010-12-30 00:53:21 +08:00
|
|
|
return parse_state_continue;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_parse_lines_420()
|
|
|
|
*
|
|
|
|
* Parse two lines from the scratch buffer, put
|
|
|
|
* decoded RGB value into the current frame buffer and add the written
|
|
|
|
* number of bytes (RGB) to the *pcopylen.
|
|
|
|
*
|
|
|
|
*/
|
2010-12-20 07:21:36 +08:00
|
|
|
static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvision,
|
2006-12-04 19:30:53 +08:00
|
|
|
long *pcopylen)
|
|
|
|
{
|
|
|
|
struct usbvision_frame *frame;
|
|
|
|
unsigned char *f_even = NULL, *f_odd = NULL;
|
|
|
|
unsigned int pixel_per_line, block;
|
|
|
|
int pixel, block_split;
|
|
|
|
int y_ptr, u_ptr, v_ptr, y_odd_offset;
|
2010-12-30 00:53:21 +08:00
|
|
|
const int y_block_size = 128;
|
|
|
|
const int uv_block_size = 64;
|
2006-12-04 19:30:53 +08:00
|
|
|
const int sub_block_size = 32;
|
2010-12-30 00:53:21 +08:00
|
|
|
const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
|
|
|
|
const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char y[2], u, v; /* YUV components */
|
|
|
|
int y_, u_, v_, vb, uvg, ur;
|
|
|
|
int r_, g_, b_; /* RGB components */
|
|
|
|
unsigned char g;
|
|
|
|
int clipmask_even_index, clipmask_odd_index, bytes_per_pixel;
|
|
|
|
int clipmask_add, stretch_bytes;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
frame = usbvision->cur_frame;
|
2006-12-04 19:31:45 +08:00
|
|
|
f_even = frame->data + (frame->v4l2_linesize * frame->curline);
|
|
|
|
f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/* Make sure there's enough data for the entire line */
|
|
|
|
/* In this mode usbvision transfer 3 bytes for every 2 pixels */
|
|
|
|
/* I need two lines to decode the color */
|
2006-12-04 19:31:11 +08:00
|
|
|
bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
|
2006-12-04 19:30:53 +08:00
|
|
|
stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
|
|
|
|
clipmask_even_index = frame->curline * MAX_FRAME_WIDTH;
|
|
|
|
clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH;
|
|
|
|
clipmask_add = usbvision->stretch_width;
|
2010-12-20 07:21:36 +08:00
|
|
|
pixel_per_line = frame->isoc_header.frame_width;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* printk(KERN_DEBUG "out of data, need %d\n", len); */
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_out;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if ((frame->curline + 1) >= frame->frmheight)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size)
|
|
|
|
+ block_split * uv_block_size;
|
|
|
|
|
|
|
|
scratch_set_extra_ptr(usbvision, &y_ptr, y_odd_offset);
|
|
|
|
scratch_set_extra_ptr(usbvision, &u_ptr, y_block_size);
|
|
|
|
scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
|
|
|
|
+ (4 - block_split) * sub_block_size);
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
for (block = 0; block < (pixel_per_line / sub_block_size); block++) {
|
|
|
|
for (pixel = 0; pixel < sub_block_size; pixel += 2) {
|
2006-12-04 19:30:53 +08:00
|
|
|
scratch_get(usbvision, &y[0], 2);
|
|
|
|
scratch_get_extra(usbvision, &u, &u_ptr, 1);
|
|
|
|
scratch_get_extra(usbvision, &v, &v_ptr, 1);
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* I don't use the YUV_TO_RGB macro for better performance */
|
2006-12-04 19:30:53 +08:00
|
|
|
v_ = v - 128;
|
|
|
|
u_ = u - 128;
|
2010-12-30 00:53:21 +08:00
|
|
|
vb = 132252 * v_;
|
|
|
|
uvg = -53281 * u_ - 25625 * v_;
|
2006-12-04 19:30:53 +08:00
|
|
|
ur = 104595 * u_;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2006-12-04 19:30:53 +08:00
|
|
|
*f_even++ = y[0];
|
|
|
|
*f_even++ = v;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
y_ = 76284 * (y[0] - 16);
|
|
|
|
|
|
|
|
b_ = (y_ + vb) >> 16;
|
2010-12-30 00:53:21 +08:00
|
|
|
g_ = (y_ + uvg) >> 16;
|
2006-12-04 19:30:53 +08:00
|
|
|
r_ = (y_ + ur) >> 16;
|
|
|
|
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_even++ =
|
|
|
|
(0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_even++ =
|
|
|
|
(0x07 & (g >> 3)) |
|
|
|
|
(0xF8 & LIMIT_RGB(b_));
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f_even++ = LIMIT_RGB(r_);
|
|
|
|
*f_even++ = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = LIMIT_RGB(b_);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f_even++ = LIMIT_RGB(r_);
|
|
|
|
*f_even++ = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = LIMIT_RGB(b_);
|
|
|
|
f_even++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = (0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_even++ = (0x03 & (g >> 3)) |
|
|
|
|
(0x7C & (LIMIT_RGB(b_) << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_even_index += clipmask_add;
|
|
|
|
f_even += stretch_bytes;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2006-12-04 19:30:53 +08:00
|
|
|
*f_even++ = y[1];
|
|
|
|
*f_even++ = u;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
y_ = 76284 * (y[1] - 16);
|
|
|
|
|
|
|
|
b_ = (y_ + vb) >> 16;
|
2010-12-30 00:53:21 +08:00
|
|
|
g_ = (y_ + uvg) >> 16;
|
2006-12-04 19:30:53 +08:00
|
|
|
r_ = (y_ + ur) >> 16;
|
|
|
|
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_even++ =
|
|
|
|
(0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_even++ =
|
|
|
|
(0x07 & (g >> 3)) |
|
|
|
|
(0xF8 & LIMIT_RGB(b_));
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f_even++ = LIMIT_RGB(r_);
|
|
|
|
*f_even++ = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = LIMIT_RGB(b_);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f_even++ = LIMIT_RGB(r_);
|
|
|
|
*f_even++ = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = LIMIT_RGB(b_);
|
|
|
|
f_even++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_even++ = (0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_even++ = (0x03 & (g >> 3)) |
|
|
|
|
(0x7C & (LIMIT_RGB(b_) << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_even_index += clipmask_add;
|
|
|
|
f_even += stretch_bytes;
|
|
|
|
|
|
|
|
scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2006-12-04 19:30:53 +08:00
|
|
|
*f_odd++ = y[0];
|
|
|
|
*f_odd++ = v;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
y_ = 76284 * (y[0] - 16);
|
|
|
|
|
|
|
|
b_ = (y_ + vb) >> 16;
|
2010-12-30 00:53:21 +08:00
|
|
|
g_ = (y_ + uvg) >> 16;
|
2006-12-04 19:30:53 +08:00
|
|
|
r_ = (y_ + ur) >> 16;
|
|
|
|
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ =
|
|
|
|
(0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_odd++ =
|
|
|
|
(0x07 & (g >> 3)) |
|
|
|
|
(0xF8 & LIMIT_RGB(b_));
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f_odd++ = LIMIT_RGB(r_);
|
|
|
|
*f_odd++ = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = LIMIT_RGB(b_);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f_odd++ = LIMIT_RGB(r_);
|
|
|
|
*f_odd++ = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = LIMIT_RGB(b_);
|
|
|
|
f_odd++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_odd++ = (0x03 & (g >> 3)) |
|
|
|
|
(0x7C & (LIMIT_RGB(b_) << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_odd_index += clipmask_add;
|
|
|
|
f_odd += stretch_bytes;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
|
2006-12-04 19:30:53 +08:00
|
|
|
*f_odd++ = y[1];
|
|
|
|
*f_odd++ = u;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
y_ = 76284 * (y[1] - 16);
|
|
|
|
|
|
|
|
b_ = (y_ + vb) >> 16;
|
2010-12-30 00:53:21 +08:00
|
|
|
g_ = (y_ + uvg) >> 16;
|
2006-12-04 19:30:53 +08:00
|
|
|
r_ = (y_ + ur) >> 16;
|
|
|
|
|
|
|
|
switch (frame->v4l2_format.format) {
|
2008-01-11 05:20:34 +08:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ =
|
|
|
|
(0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_odd++ =
|
|
|
|
(0x07 & (g >> 3)) |
|
|
|
|
(0xF8 & LIMIT_RGB(b_));
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
*f_odd++ = LIMIT_RGB(r_);
|
|
|
|
*f_odd++ = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = LIMIT_RGB(b_);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
*f_odd++ = LIMIT_RGB(r_);
|
|
|
|
*f_odd++ = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = LIMIT_RGB(b_);
|
|
|
|
f_odd++;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB555:
|
|
|
|
g = LIMIT_RGB(g_);
|
|
|
|
*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
|
|
|
|
(0xE0 & (g << 5));
|
|
|
|
*f_odd++ = (0x03 & (g >> 3)) |
|
|
|
|
(0x7C & (LIMIT_RGB(b_) << 2));
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clipmask_odd_index += clipmask_add;
|
|
|
|
f_odd += stretch_bytes;
|
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
scratch_rm_old(usbvision, y_step[block % y_step_size] * sub_block_size);
|
2006-12-04 19:30:53 +08:00
|
|
|
scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size]
|
|
|
|
* sub_block_size);
|
|
|
|
scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size]
|
|
|
|
* sub_block_size);
|
|
|
|
scratch_inc_extra_ptr(&v_ptr, uv_step[(block + 2 * block_split) % uv_step_size]
|
|
|
|
* sub_block_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
scratch_rm_old(usbvision, pixel_per_line * 3 / 2
|
|
|
|
+ block_split * sub_block_size);
|
|
|
|
|
|
|
|
frame->curline += 2 * usbvision->stretch_height;
|
|
|
|
*pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height;
|
|
|
|
|
|
|
|
if (frame->curline >= frame->frmheight)
|
2010-12-20 07:21:36 +08:00
|
|
|
return parse_state_next_frame;
|
2010-12-30 00:53:21 +08:00
|
|
|
return parse_state_continue;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_parse_data()
|
|
|
|
*
|
|
|
|
* Generic routine to parse the scratch buffer. It employs either
|
|
|
|
* usbvision_find_header() or usbvision_parse_lines() to do most
|
|
|
|
* of work.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void usbvision_parse_data(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
struct usbvision_frame *frame;
|
2010-12-20 07:21:36 +08:00
|
|
|
enum parse_state newstate;
|
2006-12-04 19:30:53 +08:00
|
|
|
long copylen = 0;
|
2006-12-04 19:31:14 +08:00
|
|
|
unsigned long lock_flags;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
frame = usbvision->cur_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
|
|
|
|
|
|
|
|
while (1) {
|
2010-12-20 07:21:36 +08:00
|
|
|
newstate = parse_state_out;
|
2006-12-04 19:30:53 +08:00
|
|
|
if (scratch_len(usbvision)) {
|
2010-12-20 07:21:36 +08:00
|
|
|
if (frame->scanstate == scan_state_scanning) {
|
2006-12-04 19:30:53 +08:00
|
|
|
newstate = usbvision_find_header(usbvision);
|
2010-12-30 00:53:21 +08:00
|
|
|
} else if (frame->scanstate == scan_state_lines) {
|
|
|
|
if (usbvision->isoc_mode == ISOC_MODE_YUV420)
|
2006-12-04 19:30:53 +08:00
|
|
|
newstate = usbvision_parse_lines_420(usbvision, ©len);
|
2010-12-30 00:53:21 +08:00
|
|
|
else if (usbvision->isoc_mode == ISOC_MODE_YUV422)
|
2006-12-04 19:30:53 +08:00
|
|
|
newstate = usbvision_parse_lines_422(usbvision, ©len);
|
2010-12-30 00:53:21 +08:00
|
|
|
else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
|
2006-12-04 19:30:53 +08:00
|
|
|
newstate = usbvision_parse_compress(usbvision, ©len);
|
|
|
|
}
|
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
if (newstate == parse_state_continue)
|
2006-12-04 19:30:53 +08:00
|
|
|
continue;
|
2010-12-30 00:53:21 +08:00
|
|
|
if ((newstate == parse_state_next_frame) || (newstate == parse_state_out))
|
2006-12-04 19:30:53 +08:00
|
|
|
break;
|
2010-12-30 00:53:21 +08:00
|
|
|
return; /* parse_state_end_parse */
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (newstate == parse_state_next_frame) {
|
|
|
|
frame->grabstate = frame_state_done;
|
2012-09-16 02:14:42 +08:00
|
|
|
v4l2_get_timestamp(&(frame->timestamp));
|
2006-12-04 19:30:53 +08:00
|
|
|
frame->sequence = usbvision->frame_num;
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
|
|
|
|
list_move_tail(&(frame->frame), &usbvision->outqueue);
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->cur_frame = NULL;
|
2006-12-04 19:31:45 +08:00
|
|
|
spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
|
|
|
|
|
|
|
|
usbvision->frame_num++;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/* This will cause the process to request another frame. */
|
2006-12-04 19:31:14 +08:00
|
|
|
if (waitqueue_active(&usbvision->wait_frame)) {
|
|
|
|
PDEBUG(DBG_PARSE, "Wake up !");
|
|
|
|
wake_up_interruptible(&usbvision->wait_frame);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
frame->grabstate = frame_state_grabbing;
|
2010-12-30 00:53:21 +08:00
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/* Update the frame's uncompressed length. */
|
|
|
|
frame->scanlength += copylen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make all of the blocks of data contiguous
|
|
|
|
*/
|
|
|
|
static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
|
2006-12-04 19:31:14 +08:00
|
|
|
struct urb *urb)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
unsigned char *packet_data;
|
|
|
|
int i, totlen = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < urb->number_of_packets; i++) {
|
|
|
|
int packet_len = urb->iso_frame_desc[i].actual_length;
|
|
|
|
int packet_stat = urb->iso_frame_desc[i].status;
|
|
|
|
|
|
|
|
packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
|
|
|
|
|
|
|
|
/* Detect and ignore errored packets */
|
2010-12-20 07:33:51 +08:00
|
|
|
if (packet_stat) { /* packet_stat != 0 ????????????? */
|
2006-12-04 19:30:53 +08:00
|
|
|
PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat);
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_err_count++;
|
2006-12-04 19:30:53 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect and ignore empty packets */
|
|
|
|
if (packet_len < 0) {
|
|
|
|
PDEBUG(DBG_ISOC, "error packet [%d]", i);
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_skip_count++;
|
2006-12-04 19:30:53 +08:00
|
|
|
continue;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else if (packet_len == 0) { /* Frame end ????? */
|
2006-12-04 19:30:53 +08:00
|
|
|
PDEBUG(DBG_ISOC, "null packet [%d]", i);
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->isocstate = isoc_state_no_frame;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_skip_count++;
|
2006-12-04 19:30:53 +08:00
|
|
|
continue;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else if (packet_len > usbvision->isoc_packet_size) {
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i);
|
|
|
|
usbvision->isoc_skip_count++;
|
2006-12-04 19:30:53 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len);
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->isocstate == isoc_state_no_frame) { /* new frame begins */
|
|
|
|
usbvision->isocstate = isoc_state_in_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
scratch_mark_header(usbvision);
|
|
|
|
usbvision_measure_bandwidth(usbvision);
|
|
|
|
PDEBUG(DBG_ISOC, "packet with header");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If usbvision continues to feed us with data but there is no
|
|
|
|
* consumption (if, for example, V4L client fell asleep) we
|
|
|
|
* may overflow the buffer. We have to move old data over to
|
|
|
|
* free room for new data. This is bad for old data. If we
|
|
|
|
* just drop new data then it's bad for new data... choose
|
|
|
|
* 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);
|
|
|
|
scratch_rm_old(usbvision, packet_len - scratch_free(usbvision));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we know that there is enough room in scratch buffer */
|
|
|
|
scratch_put(usbvision, packet_data, packet_len);
|
|
|
|
totlen += packet_len;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_data_count += packet_len;
|
|
|
|
usbvision->isoc_packet_count++;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
#if ENABLE_HEXDUMP
|
|
|
|
if (totlen > 0) {
|
2008-04-23 01:41:48 +08:00
|
|
|
static int foo;
|
2010-12-30 00:53:21 +08:00
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
if (foo < 1) {
|
|
|
|
printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
|
|
|
|
usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
|
|
|
|
++foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-12-30 00:53:21 +08:00
|
|
|
return totlen;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static void usbvision_isoc_irq(struct urb *urb)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:31:14 +08:00
|
|
|
int len;
|
|
|
|
struct usb_usbvision *usbvision = urb->context;
|
|
|
|
int i;
|
2010-12-20 07:21:36 +08:00
|
|
|
unsigned long start_time = jiffies;
|
2006-12-04 19:31:14 +08:00
|
|
|
struct usbvision_frame **f;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:14 +08:00
|
|
|
/* We don't want to do anything if we are about to be removed! */
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2007-05-28 04:21:17 +08:00
|
|
|
/* any urb with wrong status is ignored without acknowledgement */
|
2010-12-30 00:53:21 +08:00
|
|
|
if (urb->status == -ENOENT)
|
2007-05-28 04:21:17 +08:00
|
|
|
return;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
f = &usbvision->cur_frame;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:14 +08:00
|
|
|
/* Manage streaming interruption */
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->streaming == stream_interrupt) {
|
|
|
|
usbvision->streaming = stream_idle;
|
2006-12-04 19:31:14 +08:00
|
|
|
if ((*f)) {
|
2010-12-20 07:21:36 +08:00
|
|
|
(*f)->grabstate = frame_state_ready;
|
|
|
|
(*f)->scanstate = scan_state_scanning;
|
2006-12-04 19:31:14 +08:00
|
|
|
}
|
|
|
|
PDEBUG(DBG_IRQ, "stream interrupted");
|
|
|
|
wake_up_interruptible(&usbvision->wait_stream);
|
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:14 +08:00
|
|
|
/* Copy the data received into our scratch buffer */
|
|
|
|
len = usbvision_compress_isochronous(usbvision, urb);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_urb_count++;
|
2006-12-04 19:31:14 +08:00
|
|
|
usbvision->urb_length = len;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->streaming == stream_on) {
|
2006-12-04 19:31:14 +08:00
|
|
|
/* If we collected enough data let's parse! */
|
2010-12-30 00:53:21 +08:00
|
|
|
if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH &&
|
|
|
|
!list_empty(&(usbvision->inqueue))) {
|
2007-05-28 04:21:17 +08:00
|
|
|
if (!(*f)) {
|
|
|
|
(*f) = list_entry(usbvision->inqueue.next,
|
|
|
|
struct usbvision_frame,
|
|
|
|
frame);
|
2006-12-04 19:31:14 +08:00
|
|
|
}
|
2007-05-28 04:21:17 +08:00
|
|
|
usbvision_parse_data(usbvision);
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* If we don't have a frame
|
2007-05-28 04:21:17 +08:00
|
|
|
we're current working on, complain */
|
|
|
|
PDEBUG(DBG_IRQ,
|
|
|
|
"received data, but no one needs it");
|
|
|
|
scratch_reset(usbvision);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:31:24 +08:00
|
|
|
PDEBUG(DBG_IRQ, "received data, but no one needs it");
|
|
|
|
scratch_reset(usbvision);
|
|
|
|
}
|
2006-12-04 19:31:14 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->time_in_irq += jiffies - start_time;
|
2006-12-04 19:31:14 +08:00
|
|
|
|
|
|
|
for (i = 0; i < USBVISION_URB_FRAMES; i++) {
|
|
|
|
urb->iso_frame_desc[i].status = 0;
|
|
|
|
urb->iso_frame_desc[i].actual_length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
urb->status = 0;
|
|
|
|
urb->dev = usbvision->dev;
|
2010-12-30 00:53:21 +08:00
|
|
|
err_code = usb_submit_urb(urb, GFP_ATOMIC);
|
2006-12-04 19:31:14 +08:00
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (err_code) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: usb_submit_urb failed: error %d\n",
|
2010-12-20 07:21:36 +08:00
|
|
|
__func__, err_code);
|
2007-05-28 04:21:17 +08:00
|
|
|
}
|
2006-12-04 19:31:14 +08:00
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************/
|
|
|
|
/* Low level usbvision access functions */
|
|
|
|
/*************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_read_reg()
|
|
|
|
*
|
|
|
|
* return < 0 -> Error
|
|
|
|
* >= 0 -> Data
|
|
|
|
*/
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char buffer[1];
|
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return -1;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1),
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
|
|
|
|
0, (__u16) reg, buffer, 1, HZ);
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (err_code < 0) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
2010-12-20 07:21:36 +08:00
|
|
|
"%s: failed: error %d\n", __func__, err_code);
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
return buffer[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_write_reg()
|
|
|
|
*
|
|
|
|
* return 1 -> Reg written
|
|
|
|
* 0 -> usbvision is not yet ready
|
|
|
|
* -1 -> Something went wrong
|
|
|
|
*/
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char value)
|
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ);
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (err_code < 0) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
2010-12-20 07:21:36 +08:00
|
|
|
"%s: failed: error %d\n", __func__, err_code);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static void usbvision_ctrl_urb_complete(struct urb *urb)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context;
|
|
|
|
|
|
|
|
PDEBUG(DBG_IRQ, "");
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->ctrl_urb_busy = 0;
|
2010-12-30 00:53:21 +08:00
|
|
|
if (waitqueue_active(&usbvision->ctrl_urb_wq))
|
2010-12-20 07:21:36 +08:00
|
|
|
wake_up_interruptible(&usbvision->ctrl_urb_wq);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address,
|
|
|
|
unsigned char *data, int len)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_IRQ, "");
|
2010-12-30 00:53:21 +08:00
|
|
|
if (len > 8)
|
2006-12-04 19:30:53 +08:00
|
|
|
return -EFAULT;
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->ctrl_urb_busy)
|
2006-12-04 19:30:53 +08:00
|
|
|
return -EBUSY;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->ctrl_urb_busy = 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
|
|
|
|
usbvision->ctrl_urb_setup.bRequest = USBVISION_OP_CODE;
|
|
|
|
usbvision->ctrl_urb_setup.wValue = 0;
|
|
|
|
usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address);
|
|
|
|
usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len);
|
2010-12-30 00:53:21 +08:00
|
|
|
usb_fill_control_urb(usbvision->ctrl_urb, usbvision->dev,
|
2006-12-04 19:30:53 +08:00
|
|
|
usb_sndctrlpipe(usbvision->dev, 1),
|
2010-12-20 07:21:36 +08:00
|
|
|
(unsigned char *)&usbvision->ctrl_urb_setup,
|
|
|
|
(void *)usbvision->ctrl_urb_buffer, len,
|
|
|
|
usbvision_ctrl_urb_complete,
|
2006-12-04 19:30:53 +08:00
|
|
|
(void *)usbvision);
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
memcpy(usbvision->ctrl_urb_buffer, data, len);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_submit_urb(usbvision->ctrl_urb, GFP_ATOMIC);
|
|
|
|
if (err_code < 0) {
|
2010-12-20 07:33:51 +08:00
|
|
|
/* error in usb_submit_urb() */
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->ctrl_urb_busy = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, err_code);
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int usbvision_init_compression(struct usb_usbvision *usbvision)
|
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
|
|
|
|
|
|
|
usbvision->last_isoc_frame_num = -1;
|
|
|
|
usbvision->isoc_data_count = 0;
|
|
|
|
usbvision->isoc_packet_count = 0;
|
|
|
|
usbvision->isoc_skip_count = 0;
|
|
|
|
usbvision->compr_level = 50;
|
|
|
|
usbvision->last_compr_level = -1;
|
|
|
|
usbvision->isoc_urb_count = 0;
|
|
|
|
usbvision->request_intra = 1;
|
|
|
|
usbvision->isoc_measure_bandwidth_count = 0;
|
|
|
|
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function measures the used bandwidth since last call
|
|
|
|
* return: 0 : no error
|
2010-12-20 07:21:36 +08:00
|
|
|
* sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size
|
2006-12-04 19:30:53 +08:00
|
|
|
*/
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
if (usbvision->isoc_measure_bandwidth_count < 2) { /* this gives an average bandwidth of 3 frames */
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_measure_bandwidth_count++;
|
|
|
|
return err_code;
|
|
|
|
}
|
|
|
|
if ((usbvision->isoc_packet_size > 0) && (usbvision->isoc_packet_count > 0)) {
|
|
|
|
usbvision->used_bandwidth = usbvision->isoc_data_count /
|
|
|
|
(usbvision->isoc_packet_count + usbvision->isoc_skip_count) *
|
|
|
|
100 / usbvision->isoc_packet_size;
|
|
|
|
}
|
|
|
|
usbvision->isoc_measure_bandwidth_count = 0;
|
|
|
|
usbvision->isoc_data_count = 0;
|
|
|
|
usbvision->isoc_packet_count = 0;
|
|
|
|
usbvision->isoc_skip_count = 0;
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_adjust_compression(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char buffer[6];
|
|
|
|
|
|
|
|
PDEBUG(DBG_IRQ, "");
|
2010-12-20 07:21:36 +08:00
|
|
|
if ((adjust_compression) && (usbvision->used_bandwidth > 0)) {
|
|
|
|
usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2;
|
|
|
|
RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100);
|
|
|
|
if (usbvision->compr_level != usbvision->last_compr_level) {
|
2010-12-30 00:53:21 +08:00
|
|
|
int distortion;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) {
|
2010-12-20 07:33:51 +08:00
|
|
|
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 */
|
2010-12-30 00:53:21 +08:00
|
|
|
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 */
|
2010-12-20 07:33:51 +08:00
|
|
|
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 */
|
2010-12-30 00:53:21 +08:00
|
|
|
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 */
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
|
2010-12-30 00:53:21 +08:00
|
|
|
if (err_code == 0) {
|
2006-12-04 19:30:53 +08:00
|
|
|
PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0],
|
|
|
|
buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->last_compr_level = usbvision->compr_level;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_request_intra(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char buffer[1];
|
|
|
|
|
|
|
|
PDEBUG(DBG_IRQ, "");
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->request_intra = 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
buffer[0] = 1;
|
|
|
|
usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
static int usbvision_unrequest_intra(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char buffer[1];
|
|
|
|
|
|
|
|
PDEBUG(DBG_IRQ, "");
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->request_intra = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
buffer[0] = 0;
|
|
|
|
usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/*******************************
|
|
|
|
* usbvision utility functions
|
|
|
|
*******************************/
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_power_off(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_FUNC, "");
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
|
2010-12-30 00:53:21 +08:00
|
|
|
if (err_code == 1)
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->power = 0;
|
2010-12-30 00:53:21 +08:00
|
|
|
PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code);
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 04:36:05 +08:00
|
|
|
/* configure webcam image sensor using the serial port */
|
|
|
|
static int usbvision_init_webcam(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
static char init_values[38][3] = {
|
|
|
|
{ 0x04, 0x12, 0x08 }, { 0x05, 0xff, 0xc8 }, { 0x06, 0x18, 0x07 }, { 0x07, 0x90, 0x00 },
|
|
|
|
{ 0x09, 0x00, 0x00 }, { 0x0a, 0x00, 0x00 }, { 0x0b, 0x08, 0x00 }, { 0x0d, 0xcc, 0xcc },
|
|
|
|
{ 0x0e, 0x13, 0x14 }, { 0x10, 0x9b, 0x83 }, { 0x11, 0x5a, 0x3f }, { 0x12, 0xe4, 0x73 },
|
|
|
|
{ 0x13, 0x88, 0x84 }, { 0x14, 0x89, 0x80 }, { 0x15, 0x00, 0x20 }, { 0x16, 0x00, 0x00 },
|
|
|
|
{ 0x17, 0xff, 0xa0 }, { 0x18, 0x6b, 0x20 }, { 0x19, 0x22, 0x40 }, { 0x1a, 0x10, 0x07 },
|
|
|
|
{ 0x1b, 0x00, 0x47 }, { 0x1c, 0x03, 0xe0 }, { 0x1d, 0x00, 0x00 }, { 0x1e, 0x00, 0x00 },
|
|
|
|
{ 0x1f, 0x00, 0x00 }, { 0x20, 0x00, 0x00 }, { 0x21, 0x00, 0x00 }, { 0x22, 0x00, 0x00 },
|
|
|
|
{ 0x23, 0x00, 0x00 }, { 0x24, 0x00, 0x00 }, { 0x25, 0x00, 0x00 }, { 0x26, 0x00, 0x00 },
|
|
|
|
{ 0x27, 0x00, 0x00 }, { 0x28, 0x00, 0x00 }, { 0x29, 0x00, 0x00 }, { 0x08, 0x80, 0x60 },
|
|
|
|
{ 0x0f, 0x2d, 0x24 }, { 0x0c, 0x80, 0x80 }
|
|
|
|
};
|
|
|
|
char value[3];
|
|
|
|
|
|
|
|
/* the only difference between PAL and NTSC init_values */
|
|
|
|
if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_NTSC)
|
|
|
|
init_values[4][1] = 0x34;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(init_values) / 3; i++) {
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT);
|
|
|
|
memcpy(value, init_values[i], 3);
|
|
|
|
rc = usb_control_msg(usbvision->dev,
|
|
|
|
usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_SER_DAT1, value,
|
|
|
|
3, HZ);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SIO);
|
|
|
|
/* write 3 bytes to the serial port using SIO mode */
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_CONT, 3 | 0x10);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, 0);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_IO_2);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_DAT_IO);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT | USBVISION_DAT_IO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
/*
|
|
|
|
* usbvision_set_video_format()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format)
|
|
|
|
{
|
|
|
|
static const char proc[] = "usbvision_set_video_format";
|
|
|
|
int rc;
|
|
|
|
unsigned char value[2];
|
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_FUNC, "isoc_mode %#02x", format);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
if ((format != ISOC_MODE_YUV422)
|
|
|
|
&& (format != ISOC_MODE_YUV420)
|
|
|
|
&& (format != ISOC_MODE_COMPRESS)) {
|
|
|
|
printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420",
|
|
|
|
format);
|
|
|
|
format = ISOC_MODE_YUV420;
|
|
|
|
}
|
2010-12-20 07:33:51 +08:00
|
|
|
value[0] = 0x0A; /* TODO: See the effect of the filter */
|
|
|
|
value[1] = format; /* Sets the VO_MODE register which follows FILT_CONT */
|
2006-12-04 19:30:53 +08:00
|
|
|
rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_FILT_CONT, value, 2, HZ);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - "
|
|
|
|
"reconnect or reload driver.\n", proc, rc);
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_mode = format;
|
2006-12-04 19:30:53 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_set_output()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_set_output(struct usb_usbvision *usbvision, int width,
|
|
|
|
int height)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
|
|
|
int usb_width, usb_height;
|
2010-12-30 00:53:21 +08:00
|
|
|
unsigned int frame_rate = 0, frame_drop = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
unsigned char value[4];
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
2006-12-04 19:30:53 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (width > MAX_USB_WIDTH) {
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_width = width / 2;
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->stretch_width = 2;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_width = width;
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->stretch_width = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height > MAX_USB_HEIGHT) {
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_height = height / 2;
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->stretch_height = 2;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_height = height;
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->stretch_height = 1;
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
RESTRICT_TO_RANGE(usb_width, MIN_FRAME_WIDTH, MAX_USB_WIDTH);
|
|
|
|
usb_width &= ~(MIN_FRAME_WIDTH-1);
|
|
|
|
RESTRICT_TO_RANGE(usb_height, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT);
|
|
|
|
usb_height &= ~(1);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d",
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_width, usb_height, width, height,
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->stretch_width, usbvision->stretch_height);
|
|
|
|
|
|
|
|
/* I'll not rewrite the same values */
|
2010-12-20 07:21:36 +08:00
|
|
|
if ((usb_width != usbvision->curwidth) || (usb_height != usbvision->curheight)) {
|
2010-12-20 07:33:51 +08:00
|
|
|
value[0] = usb_width & 0xff; /* LSB */
|
|
|
|
value[1] = (usb_width >> 8) & 0x03; /* MSB */
|
|
|
|
value[2] = usb_height & 0xff; /* LSB */
|
|
|
|
value[3] = (usb_height >> 8) & 0x03; /* MSB */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
|
|
|
|
0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (err_code < 0) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
2010-12-20 07:21:36 +08:00
|
|
|
"%s failed: error %d\n", __func__, err_code);
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->curwidth = usbvision->stretch_width * usb_width;
|
|
|
|
usbvision->curheight = usbvision->stretch_height * usb_height;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->isoc_mode == ISOC_MODE_YUV422)
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2);
|
2010-12-30 00:53:21 +08:00
|
|
|
else if (usbvision->isoc_mode == ISOC_MODE_YUV420)
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8);
|
2010-12-30 00:53:21 +08:00
|
|
|
else
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_rate = FRAMERATE_MAX;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->tvnorm_id & V4L2_STD_625_50)
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_drop = frame_rate * 32 / 25 - 1;
|
2010-12-30 00:53:21 +08:00
|
|
|
else if (usbvision->tvnorm_id & V4L2_STD_525_60)
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_drop = frame_rate * 32 / 30 - 1;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2011-04-28 04:36:05 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
|
|
|
|
if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_PAL)
|
|
|
|
frame_drop = 25;
|
|
|
|
else
|
|
|
|
frame_drop = 30;
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
/* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ...
|
|
|
|
=> frame_skip = 4;
|
|
|
|
=> frame_rate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
frame_drop = 9; => frame_phase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ...
|
|
|
|
=> frame_skip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ...
|
|
|
|
=> frame_rate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125;
|
2006-12-04 19:30:53 +08:00
|
|
|
*/
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frame_drop);
|
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/*
|
|
|
|
* usbvision_frames_alloc
|
2007-02-07 21:13:11 +08:00
|
|
|
* allocate the required frames
|
2006-12-04 19:31:45 +08:00
|
|
|
*/
|
2007-02-07 21:13:11 +08:00
|
|
|
int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames)
|
2006-12-04 19:31:45 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* needs to be page aligned cause the buffers can be mapped individually! */
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
|
2007-02-07 21:13:11 +08:00
|
|
|
usbvision->curheight *
|
|
|
|
usbvision->palette.bytes_per_pixel);
|
2006-12-04 19:31:45 +08:00
|
|
|
|
2007-02-07 21:13:11 +08:00
|
|
|
/* Try to do my best to allocate the frames the user want in the remaining memory */
|
|
|
|
usbvision->num_frames = number_of_frames;
|
|
|
|
while (usbvision->num_frames > 0) {
|
|
|
|
usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
|
|
|
|
if (usbvision->fbuf)
|
2007-02-07 21:13:11 +08:00
|
|
|
break;
|
|
|
|
usbvision->num_frames--;
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
2007-02-07 21:13:11 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
spin_lock_init(&usbvision->queue_lock);
|
|
|
|
init_waitqueue_head(&usbvision->wait_frame);
|
|
|
|
init_waitqueue_head(&usbvision->wait_stream);
|
|
|
|
|
|
|
|
/* Allocate all buffers */
|
2007-02-07 21:13:11 +08:00
|
|
|
for (i = 0; i < usbvision->num_frames; i++) {
|
2006-12-04 19:31:45 +08:00
|
|
|
usbvision->frame[i].index = i;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->frame[i].grabstate = frame_state_unused;
|
2006-12-04 19:31:45 +08:00
|
|
|
usbvision->frame[i].data = usbvision->fbuf +
|
|
|
|
i * usbvision->max_frame_size;
|
|
|
|
/*
|
|
|
|
* Set default sizes for read operation.
|
|
|
|
*/
|
|
|
|
usbvision->stretch_width = 1;
|
|
|
|
usbvision->stretch_height = 1;
|
|
|
|
usbvision->frame[i].width = usbvision->curwidth;
|
|
|
|
usbvision->frame[i].height = usbvision->curheight;
|
|
|
|
usbvision->frame[i].bytes_read = 0;
|
|
|
|
}
|
2010-12-30 00:53:21 +08:00
|
|
|
PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",
|
|
|
|
usbvision->num_frames, usbvision->max_frame_size);
|
2007-02-07 21:13:11 +08:00
|
|
|
return usbvision->num_frames;
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_frames_free
|
|
|
|
* frees memory allocated for the frames
|
|
|
|
*/
|
|
|
|
void usbvision_frames_free(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
/* Have to free all that memory */
|
2010-12-30 00:53:21 +08:00
|
|
|
PDEBUG(DBG_FUNC, "free %d frames", usbvision->num_frames);
|
2007-02-07 21:13:11 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
if (usbvision->fbuf != NULL) {
|
|
|
|
usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
|
|
|
|
usbvision->fbuf = NULL;
|
2007-02-07 21:13:11 +08:00
|
|
|
|
|
|
|
usbvision->num_frames = 0;
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
}
|
2006-12-04 19:31:14 +08:00
|
|
|
/*
|
|
|
|
* usbvision_empty_framequeues()
|
|
|
|
* prepare queues for incoming and outgoing frames
|
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
void usbvision_empty_framequeues(struct usb_usbvision *usbvision)
|
2006-12-04 19:31:14 +08:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&(usbvision->inqueue));
|
|
|
|
INIT_LIST_HEAD(&(usbvision->outqueue));
|
|
|
|
|
|
|
|
for (i = 0; i < USBVISION_NUMFRAMES; i++) {
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->frame[i].grabstate = frame_state_unused;
|
2006-12-04 19:31:14 +08:00
|
|
|
usbvision->frame[i].bytes_read = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_stream_interrupt()
|
|
|
|
* stops streaming
|
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_stream_interrupt(struct usb_usbvision *usbvision)
|
2006-12-04 19:31:14 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* stop reading from the device */
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->streaming = stream_interrupt;
|
2006-12-04 19:31:14 +08:00
|
|
|
ret = wait_event_timeout(usbvision->wait_stream,
|
2010-12-20 07:21:36 +08:00
|
|
|
(usbvision->streaming == stream_idle),
|
2006-12-04 19:31:14 +08:00
|
|
|
msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
/*
|
|
|
|
* usbvision_set_compress_params()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
static const char proc[] = "usbvision_set_compresion_params: ";
|
|
|
|
int rc;
|
|
|
|
unsigned char value[6];
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
value[0] = 0x0F; /* Intra-Compression cycle */
|
|
|
|
value[1] = 0x01; /* Reg.45 one line per strip */
|
|
|
|
value[2] = 0x00; /* Reg.46 Force intra mode on all new frames */
|
|
|
|
value[3] = 0x00; /* Reg.47 FORCE_UP <- 0 normal operation (not force) */
|
|
|
|
value[4] = 0xA2; /* Reg.48 BUF_THR I'm not sure if this does something in not compressed mode. */
|
|
|
|
value[5] = 0x00; /* Reg.49 DVI_YUV This has nothing to do with compression */
|
|
|
|
|
|
|
|
/* catched values for NT1004 */
|
|
|
|
/* value[0] = 0xFF; Never apply intra mode automatically */
|
|
|
|
/* value[1] = 0xF1; Use full frame height for virtual strip width; One line per strip */
|
|
|
|
/* value[2] = 0x01; Force intra mode on all new frames */
|
|
|
|
/* value[3] = 0x00; Strip size 400 Bytes; do not force up */
|
|
|
|
/* value[4] = 0xA2; */
|
2006-12-04 19:30:53 +08:00
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_INTRA_CYC, value, 5, HZ);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
|
|
|
|
"reconnect or reload driver.\n", proc, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->bridge_type == BRIDGE_NT1004) {
|
2010-12-20 07:33:51 +08:00
|
|
|
value[0] = 20; /* PCM Threshold 1 */
|
|
|
|
value[1] = 12; /* PCM Threshold 2 */
|
2010-12-30 00:53:21 +08:00
|
|
|
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 {
|
2010-12-20 07:33:51 +08:00
|
|
|
value[0] = 20; /* PCM Threshold 1 */
|
|
|
|
value[1] = 12; /* PCM Threshold 2 */
|
2010-12-30 00:53:21 +08:00
|
|
|
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 */
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_PCM_THR1, value, 6, HZ);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
|
|
|
|
"reconnect or reload driver.\n", proc, rc);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_set_input()
|
|
|
|
*
|
|
|
|
* Set the input (saa711x, ...) size x y and other misc input params
|
|
|
|
* I've no idea if this parameters are right
|
|
|
|
*
|
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_set_input(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
static const char proc[] = "usbvision_set_input: ";
|
|
|
|
int rc;
|
|
|
|
unsigned char value[8];
|
|
|
|
unsigned char dvi_yuv_value;
|
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Set input format expected from decoder*/
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) {
|
|
|
|
value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
|
2006-12-04 19:30:53 +08:00
|
|
|
/* SAA7113 uses 8 bit output */
|
|
|
|
value[0] = USBVISION_8_422_SYNC;
|
|
|
|
} else {
|
|
|
|
/* I'm sure only about d2-d0 [010] 16 bit 4:2:2 usin sync pulses
|
|
|
|
* as that is how saa7111 is configured */
|
|
|
|
value[0] = USBVISION_16_422_SYNC;
|
|
|
|
/* | USBVISION_VSNC_POL | USBVISION_VCLK_POL);*/
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]);
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
|
|
|
|
"reconnect or reload driver.\n", proc, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->tvnorm_id & V4L2_STD_PAL) {
|
2006-12-04 19:30:53 +08:00
|
|
|
value[0] = 0xC0;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[2] = 0x20;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[4] = 0x60;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[5] = 0x00; /* 0x0060 -> 96 Input video h offset */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[6] = 0x16;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[7] = 0x00; /* 0x0016 -> 22 Input video v offset */
|
2010-12-20 07:21:36 +08:00
|
|
|
} else if (usbvision->tvnorm_id & V4L2_STD_SECAM) {
|
2006-12-04 19:30:53 +08:00
|
|
|
value[0] = 0xC0;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[2] = 0x20;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[4] = 0x01;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[5] = 0x00; /* 0x0001 -> 01 Input video h offset */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[6] = 0x01;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[7] = 0x00; /* 0x0001 -> 01 Input video v offset */
|
2006-12-04 19:30:53 +08:00
|
|
|
} else { /* V4L2_STD_NTSC */
|
|
|
|
value[0] = 0xD0;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[1] = 0x02; /* 0x02D0 -> 720 Input video line length */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[2] = 0xF0;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[3] = 0x00; /* 0x00F0 -> 240 Input video number of lines */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[4] = 0x50;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[5] = 0x00; /* 0x0050 -> 80 Input video h offset */
|
2006-12-04 19:30:53 +08:00
|
|
|
value[6] = 0x10;
|
2010-12-20 07:33:51 +08:00
|
|
|
value[7] = 0x00; /* 0x0010 -> 16 Input video v offset */
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 04:36:05 +08:00
|
|
|
/* webcam is only 480 pixels wide, both PAL and NTSC version */
|
|
|
|
if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
|
|
|
|
value[0] = 0xe0;
|
|
|
|
value[1] = 0x01; /* 0x01E0 -> 480 Input video line length */
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
value[4] = usbvision_device_data[usbvision->dev_model].x_offset & 0xff;
|
|
|
|
value[5] = (usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (adjust_x_offset != -1) {
|
|
|
|
value[4] = adjust_x_offset & 0xff;
|
|
|
|
value[5] = (adjust_x_offset & 0x0300) >> 8;
|
2008-01-10 04:34:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
value[6] = usbvision_device_data[usbvision->dev_model].y_offset & 0xff;
|
|
|
|
value[7] = (usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (adjust_y_offset != -1) {
|
|
|
|
value[6] = adjust_y_offset & 0xff;
|
|
|
|
value[7] = (adjust_y_offset & 0x0300) >> 8;
|
2008-01-10 04:34:53 +08:00
|
|
|
}
|
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE, /* USBVISION specific code */
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_LXSIZE_I, value, 8, HZ);
|
|
|
|
if (rc < 0) {
|
|
|
|
printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
|
|
|
|
"reconnect or reload driver.\n", proc, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) {
|
2010-12-20 07:21:36 +08:00
|
|
|
dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv;
|
2010-12-30 00:53:21 +08:00
|
|
|
} else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
|
|
|
|
/* This changes as the fine sync control changes. Further investigation necessary */
|
2006-12-04 19:30:53 +08:00
|
|
|
dvi_yuv_value = 0x06;
|
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_set_dram_settings()
|
|
|
|
*
|
|
|
|
* Set the buffer address needed by the usbvision dram to operate
|
|
|
|
* This values has been taken with usbsnoop.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned char value[8];
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
|
2006-12-04 19:30:53 +08:00
|
|
|
value[0] = 0x42;
|
|
|
|
value[1] = 0x71;
|
|
|
|
value[2] = 0xff;
|
|
|
|
value[3] = 0x00;
|
|
|
|
value[4] = 0x98;
|
|
|
|
value[5] = 0xe0;
|
|
|
|
value[6] = 0x71;
|
|
|
|
value[7] = 0xff;
|
2010-12-20 07:33:51 +08:00
|
|
|
/* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */
|
|
|
|
/* FDL: 0x00000-0x0E099 = 57498 Words */
|
|
|
|
/* VDW: 0x0E3FF-0x3FFFF */
|
2010-12-30 00:53:21 +08:00
|
|
|
} else {
|
2006-12-04 19:30:53 +08:00
|
|
|
value[0] = 0x42;
|
|
|
|
value[1] = 0x00;
|
|
|
|
value[2] = 0xff;
|
|
|
|
value[3] = 0x00;
|
|
|
|
value[4] = 0x00;
|
|
|
|
value[5] = 0x00;
|
|
|
|
value[6] = 0x00;
|
|
|
|
value[7] = 0xff;
|
|
|
|
}
|
|
|
|
/* These are the values of the address of the video buffer,
|
|
|
|
* they have to be loaded into the USBVISION_DRM_PRM1-8
|
|
|
|
*
|
2010-12-30 00:53:21 +08:00
|
|
|
* Start address of video output buffer for read: drm_prm1-2 -> 0x00000
|
|
|
|
* End address of video output buffer for read: drm_prm1-3 -> 0x1ffff
|
|
|
|
* Start address of video frame delay buffer: drm_prm1-4 -> 0x20000
|
2006-12-04 19:30:53 +08:00
|
|
|
* Only used in compressed mode
|
2010-12-30 00:53:21 +08:00
|
|
|
* End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff
|
2006-12-04 19:30:53 +08:00
|
|
|
* Only used in compressed mode
|
2010-12-30 00:53:21 +08:00
|
|
|
* Start address of video output buffer for write: drm_prm1-7 -> 0x00000
|
|
|
|
* End address of video output buffer for write: drm_prm1-8 -> 0x1ffff
|
2006-12-04 19:30:53 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
|
|
|
|
USBVISION_OP_CODE, /* USBVISION specific code */
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR |
|
|
|
|
USB_RECIP_ENDPOINT, 0,
|
|
|
|
(__u16) USBVISION_DRM_PRM1, value, 8, HZ);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
2011-04-28 04:36:05 +08:00
|
|
|
dev_err(&usbvision->dev->dev, "%s: ERROR=%d\n", __func__, rc);
|
2006-12-04 19:30:53 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restart the video buffer logic */
|
2010-12-30 00:53:21 +08:00
|
|
|
rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
|
|
|
|
USBVISION_RES_FDL | USBVISION_RES_VDW);
|
|
|
|
if (rc < 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
return rc;
|
|
|
|
rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ()
|
|
|
|
*
|
|
|
|
* Power on the device, enables suspend-resume logic
|
|
|
|
* & reset the isoc End-Point
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_power_on(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code = 0;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_FUNC, "");
|
|
|
|
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_PWR_REG,
|
2010-12-30 00:53:21 +08:00
|
|
|
USBVISION_SSPND_EN | USBVISION_RES2);
|
2006-12-16 03:46:53 +08:00
|
|
|
|
2011-04-28 04:36:05 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_VIN_REG1,
|
|
|
|
USBVISION_16_422_SYNC | USBVISION_HVALID_PO);
|
|
|
|
usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
|
|
|
|
USBVISION_NOHVALID | USBVISION_KEEP_BLANK);
|
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_write_reg(usbvision, USBVISION_PWR_REG,
|
2010-12-30 00:53:21 +08:00
|
|
|
USBVISION_SSPND_EN | USBVISION_PWR_VID);
|
2011-04-28 04:36:05 +08:00
|
|
|
mdelay(10);
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
|
2010-12-30 00:53:21 +08:00
|
|
|
USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2);
|
|
|
|
if (err_code == 1)
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision->power = 1;
|
2010-12-30 00:53:21 +08:00
|
|
|
PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code);
|
2010-12-20 07:21:36 +08:00
|
|
|
return err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/*
|
|
|
|
* usbvision timer stuff
|
|
|
|
*/
|
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* to call usbvision_power_off from task queue */
|
2006-12-10 10:14:21 +08:00
|
|
|
static void call_usbvision_power_off(struct work_struct *work)
|
2006-12-04 19:31:45 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, power_off_work);
|
2006-12-04 19:31:45 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_FUNC, "");
|
2010-12-18 22:06:09 +08:00
|
|
|
if (mutex_lock_interruptible(&usbvision->v4l2_lock))
|
2007-10-25 04:31:15 +08:00
|
|
|
return;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->user == 0) {
|
2007-04-15 03:23:49 +08:00
|
|
|
usbvision_i2c_unregister(usbvision);
|
2006-12-10 10:14:21 +08:00
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
usbvision_power_off(usbvision);
|
|
|
|
usbvision->initialized = 0;
|
|
|
|
}
|
2010-12-18 22:06:09 +08:00
|
|
|
mutex_unlock(&usbvision->v4l2_lock);
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
static void usbvision_power_off_timer(unsigned long data)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-30 00:53:21 +08:00
|
|
|
struct usb_usbvision *usbvision = (void *)data;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
PDEBUG(DBG_FUNC, "");
|
2010-12-20 07:21:36 +08:00
|
|
|
del_timer(&usbvision->power_off_timer);
|
|
|
|
INIT_WORK(&usbvision->power_off_work, call_usbvision_power_off);
|
|
|
|
(void) schedule_work(&usbvision->power_off_work);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
void usbvision_init_power_off_timer(struct usb_usbvision *usbvision)
|
2006-12-04 19:31:45 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
init_timer(&usbvision->power_off_timer);
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->power_off_timer.data = (long)usbvision;
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->power_off_timer.function = usbvision_power_off_timer;
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
void usbvision_set_power_off_timer(struct usb_usbvision *usbvision)
|
2006-12-04 19:31:45 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
mod_timer(&usbvision->power_off_timer, jiffies + USBVISION_POWEROFF_TIME);
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
|
2006-12-04 19:31:45 +08:00
|
|
|
{
|
2010-12-30 00:53:21 +08:00
|
|
|
if (timer_pending(&usbvision->power_off_timer))
|
2010-12-20 07:21:36 +08:00
|
|
|
del_timer(&usbvision->power_off_timer);
|
2006-12-04 19:31:45 +08:00
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_begin_streaming()
|
|
|
|
* Sure you have to put bit 7 to 0, if not incoming frames are droped, but no
|
|
|
|
* idea about the rest
|
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_begin_streaming(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_init_compression(usbvision);
|
2010-12-30 00:53:21 +08:00
|
|
|
return usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
|
|
|
|
USBVISION_NOHVALID | usbvision->vin_reg2_preset);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_restart_isoc()
|
|
|
|
* Not sure yet if touching here PWR_REG make loose the config
|
|
|
|
*/
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_restart_isoc(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
|
|
|
|
USBVISION_SSPND_EN | USBVISION_PWR_VID);
|
|
|
|
if (ret < 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
return ret;
|
2010-12-30 00:53:21 +08:00
|
|
|
ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_SSPND_EN | USBVISION_PWR_VID |
|
2010-12-30 00:53:21 +08:00
|
|
|
USBVISION_RES2);
|
|
|
|
if (ret < 0)
|
2006-12-04 19:30:53 +08:00
|
|
|
return ret;
|
2010-12-30 00:53:21 +08:00
|
|
|
ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
|
2006-12-04 19:30:53 +08:00
|
|
|
USBVISION_KEEP_BLANK | USBVISION_NOHVALID |
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->vin_reg2_preset);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
/* TODO: schedule timeout */
|
2010-12-30 00:53:21 +08:00
|
|
|
while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1)
|
|
|
|
;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_audio_off(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
|
|
|
if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
|
2010-12-30 00:53:21 +08:00
|
|
|
printk(KERN_ERR "usbvision_audio_off: can't write reg\n");
|
2006-12-04 19:30:53 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->audio_mute = 0;
|
|
|
|
usbvision->audio_channel = USBVISION_AUDIO_MUTE;
|
2006-12-04 19:30:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
if (!usbvision->audio_mute) {
|
|
|
|
if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, audio_channel) < 0) {
|
2006-12-04 19:30:53 +08:00
|
|
|
printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->audio_channel = audio_channel;
|
2006-12-04 19:30:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
int usbvision_setup(struct usb_usbvision *usbvision, int format)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2011-04-28 04:36:05 +08:00
|
|
|
if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM)
|
|
|
|
usbvision_init_webcam(usbvision);
|
2006-12-04 19:31:45 +08:00
|
|
|
usbvision_set_video_format(usbvision, format);
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_set_dram_settings(usbvision);
|
|
|
|
usbvision_set_compress_params(usbvision);
|
|
|
|
usbvision_set_input(usbvision);
|
|
|
|
usbvision_set_output(usbvision, MAX_USB_WIDTH, MAX_USB_HEIGHT);
|
|
|
|
usbvision_restart_isoc(usbvision);
|
2006-12-04 19:31:11 +08:00
|
|
|
|
2006-12-04 19:30:53 +08:00
|
|
|
/* cosas del PCM */
|
|
|
|
return USBVISION_IS_OPERATIONAL(usbvision);
|
|
|
|
}
|
|
|
|
|
2007-02-07 21:14:38 +08:00
|
|
|
int usbvision_set_alternate(struct usb_usbvision *dev)
|
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int err_code, prev_alt = dev->iface_alt;
|
2007-02-07 21:14:38 +08:00
|
|
|
int i;
|
|
|
|
|
2010-12-30 00:53:21 +08:00
|
|
|
dev->iface_alt = 0;
|
|
|
|
for (i = 0; i < dev->num_alt; i++)
|
|
|
|
if (dev->alt_max_pkt_size[i] > dev->alt_max_pkt_size[dev->iface_alt])
|
|
|
|
dev->iface_alt = i;
|
2010-12-20 07:21:36 +08:00
|
|
|
|
|
|
|
if (dev->iface_alt != prev_alt) {
|
|
|
|
dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt];
|
2010-12-30 00:53:21 +08:00
|
|
|
PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u",
|
|
|
|
dev->iface_alt, dev->isoc_packet_size);
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt);
|
|
|
|
if (err_code < 0) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&dev->dev->dev,
|
|
|
|
"cannot change alternate number to %d (error=%i)\n",
|
2010-12-20 07:21:36 +08:00
|
|
|
dev->iface_alt, err_code);
|
|
|
|
return err_code;
|
2007-02-07 21:14:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isoc_packet_size);
|
2007-02-07 21:14:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
/*
|
|
|
|
* usbvision_init_isoc()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int usbvision_init_isoc(struct usb_usbvision *usbvision)
|
|
|
|
{
|
|
|
|
struct usb_device *dev = usbvision->dev;
|
2010-12-20 07:21:36 +08:00
|
|
|
int buf_idx, err_code, reg_value;
|
2007-05-28 04:21:17 +08:00
|
|
|
int sb_size;
|
2006-12-04 19:31:45 +08:00
|
|
|
|
|
|
|
if (!USBVISION_IS_OPERATIONAL(usbvision))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->cur_frame = NULL;
|
2006-12-04 19:31:45 +08:00
|
|
|
scratch_reset(usbvision);
|
|
|
|
|
|
|
|
/* Alternate interface 1 is is the biggest frame size */
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usbvision_set_alternate(usbvision);
|
|
|
|
if (err_code < 0) {
|
|
|
|
usbvision->last_error = err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
reg_value = (16 - usbvision_read_reg(usbvision,
|
2007-05-28 04:21:17 +08:00
|
|
|
USBVISION_ALTER_REG)) & 0x0F;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->usb_bandwidth = reg_value >> 1;
|
2007-05-28 04:21:17 +08:00
|
|
|
PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec",
|
|
|
|
usbvision->usb_bandwidth);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* We double buffer the Iso lists */
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
|
2006-12-04 19:30:53 +08:00
|
|
|
int j, k;
|
|
|
|
struct urb *urb;
|
|
|
|
|
2006-12-09 22:41:59 +08:00
|
|
|
urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
|
2006-12-04 19:30:53 +08:00
|
|
|
if (urb == NULL) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: usb_alloc_urb() failed\n", __func__);
|
2006-12-04 19:30:53 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->sbuf[buf_idx].urb = urb;
|
|
|
|
usbvision->sbuf[buf_idx].data =
|
2010-04-12 19:17:25 +08:00
|
|
|
usb_alloc_coherent(usbvision->dev,
|
|
|
|
sb_size,
|
|
|
|
GFP_KERNEL,
|
|
|
|
&urb->transfer_dma);
|
2006-12-04 19:30:53 +08:00
|
|
|
urb->dev = dev;
|
|
|
|
urb->context = usbvision;
|
|
|
|
urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
|
2009-03-23 10:39:12 +08:00
|
|
|
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
2006-12-04 19:30:53 +08:00
|
|
|
urb->interval = 1;
|
2010-12-20 07:21:36 +08:00
|
|
|
urb->transfer_buffer = usbvision->sbuf[buf_idx].data;
|
|
|
|
urb->complete = usbvision_isoc_irq;
|
2006-12-04 19:30:53 +08:00
|
|
|
urb->number_of_packets = USBVISION_URB_FRAMES;
|
|
|
|
urb->transfer_buffer_length =
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_packet_size * USBVISION_URB_FRAMES;
|
2006-12-04 19:30:53 +08:00
|
|
|
for (j = k = 0; j < USBVISION_URB_FRAMES; j++,
|
2010-12-20 07:21:36 +08:00
|
|
|
k += usbvision->isoc_packet_size) {
|
2006-12-04 19:30:53 +08:00
|
|
|
urb->iso_frame_desc[j].offset = k;
|
2007-05-28 04:21:17 +08:00
|
|
|
urb->iso_frame_desc[j].length =
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_packet_size;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Submit all URBs */
|
2010-12-20 07:21:36 +08:00
|
|
|
for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
|
|
|
|
err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb,
|
2007-05-28 04:21:17 +08:00
|
|
|
GFP_KERNEL);
|
2010-12-20 07:21:36 +08:00
|
|
|
if (err_code) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: usb_submit_urb(%d) failed: error %d\n",
|
2010-12-20 07:21:36 +08:00
|
|
|
__func__, buf_idx, err_code);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->streaming = stream_idle;
|
2007-05-28 04:21:17 +08:00
|
|
|
PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x",
|
2008-04-05 07:50:07 +08:00
|
|
|
__func__,
|
2007-05-28 04:21:17 +08:00
|
|
|
usbvision->video_endp);
|
2006-12-04 19:30:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbvision_stop_isoc()
|
|
|
|
*
|
|
|
|
* This procedure stops streaming and deallocates URBs. Then it
|
|
|
|
* activates zero-bandwidth alt. setting of the video interface.
|
|
|
|
*
|
|
|
|
*/
|
2006-12-04 19:31:45 +08:00
|
|
|
void usbvision_stop_isoc(struct usb_usbvision *usbvision)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2010-12-20 07:21:36 +08:00
|
|
|
int buf_idx, err_code, reg_value;
|
|
|
|
int sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
if ((usbvision->streaming == stream_off) || (usbvision->dev == NULL))
|
2006-12-04 19:30:53 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Unschedule all of the iso td's */
|
2010-12-20 07:21:36 +08:00
|
|
|
for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
|
|
|
|
usb_kill_urb(usbvision->sbuf[buf_idx].urb);
|
2010-12-30 00:53:21 +08:00
|
|
|
if (usbvision->sbuf[buf_idx].data) {
|
2010-04-12 19:17:25 +08:00
|
|
|
usb_free_coherent(usbvision->dev,
|
|
|
|
sb_size,
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->sbuf[buf_idx].data,
|
|
|
|
usbvision->sbuf[buf_idx].urb->transfer_dma);
|
2006-12-16 03:46:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
usb_free_urb(usbvision->sbuf[buf_idx].urb);
|
|
|
|
usbvision->sbuf[buf_idx].urb = NULL;
|
2006-12-04 19:31:11 +08:00
|
|
|
}
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
PDEBUG(DBG_ISOC, "%s: streaming=stream_off\n", __func__);
|
|
|
|
usbvision->streaming = stream_off;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
if (!usbvision->remove_pending) {
|
|
|
|
/* Set packet size to 0 */
|
2010-12-30 00:53:21 +08:00
|
|
|
usbvision->iface_alt = 0;
|
2010-12-20 07:21:36 +08:00
|
|
|
err_code = usb_set_interface(usbvision->dev, usbvision->iface,
|
|
|
|
usbvision->iface_alt);
|
|
|
|
if (err_code < 0) {
|
2009-01-08 20:13:42 +08:00
|
|
|
dev_err(&usbvision->dev->dev,
|
|
|
|
"%s: usb_set_interface() failed: error %d\n",
|
2010-12-20 07:21:36 +08:00
|
|
|
__func__, err_code);
|
|
|
|
usbvision->last_error = err_code;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2010-12-20 07:21:36 +08:00
|
|
|
reg_value = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
|
|
|
|
usbvision->isoc_packet_size =
|
|
|
|
(reg_value == 0) ? 0 : (reg_value * 64) - 1;
|
2007-05-28 04:21:17 +08:00
|
|
|
PDEBUG(DBG_ISOC, "ISO Packet Length:%d",
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->isoc_packet_size);
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
usbvision->usb_bandwidth = reg_value >> 1;
|
2007-05-28 04:21:17 +08:00
|
|
|
PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec",
|
|
|
|
usbvision->usb_bandwidth);
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-04 19:31:45 +08:00
|
|
|
int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
|
2006-12-04 19:30:53 +08:00
|
|
|
{
|
2007-06-27 03:35:30 +08:00
|
|
|
/* inputs #0 and #3 are constant for every SAA711x. */
|
|
|
|
/* inputs #1 and #2 are variable for SAA7111 and SAA7113 */
|
2010-12-30 00:53:21 +08:00
|
|
|
int mode[4] = { SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3 };
|
|
|
|
int audio[] = { 1, 0, 0, 0 };
|
2010-12-20 07:33:51 +08:00
|
|
|
/* channel 0 is TV with audiochannel 1 (tuner mono) */
|
|
|
|
/* channel 1 is Composite with audio channel 0 (line in) */
|
|
|
|
/* channel 2 is S-Video with audio channel 0 (line in) */
|
|
|
|
/* channel 3 is additional video inputs to the device with audio channel 0 (line in) */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
|
|
|
RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
|
2006-12-04 19:31:14 +08:00
|
|
|
usbvision->ctl_input = channel;
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:33:51 +08:00
|
|
|
/* set the new channel */
|
|
|
|
/* Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video */
|
|
|
|
/* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */
|
2006-12-04 19:30:53 +08:00
|
|
|
|
2010-12-20 07:21:36 +08:00
|
|
|
switch (usbvision_device_data[usbvision->dev_model].codec) {
|
2010-12-30 00:53:21 +08:00
|
|
|
case CODEC_SAA7113:
|
|
|
|
mode[1] = SAA7115_COMPOSITE2;
|
|
|
|
if (switch_svideo_input) {
|
|
|
|
/* To handle problems with S-Video Input for
|
|
|
|
* some devices. Use switch_svideo_input
|
|
|
|
* parameter when loading the module.*/
|
|
|
|
mode[2] = SAA7115_COMPOSITE1;
|
|
|
|
} else {
|
2007-06-27 03:35:30 +08:00
|
|
|
mode[2] = SAA7115_SVIDEO1;
|
2010-12-30 00:53:21 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CODEC_SAA7111:
|
|
|
|
default:
|
|
|
|
/* modes for saa7111 */
|
|
|
|
mode[1] = SAA7115_COMPOSITE1;
|
|
|
|
mode[2] = SAA7115_SVIDEO1;
|
|
|
|
break;
|
2006-12-04 19:30:53 +08:00
|
|
|
}
|
2009-04-02 22:26:22 +08:00
|
|
|
call_all(usbvision, video, s_routing, mode[channel], 0, 0);
|
2006-12-04 19:30:53 +08:00
|
|
|
usbvision_set_audio(usbvision, audio[channel]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overrides for Emacs so that we follow Linus's tabbing style.
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|