2009-08-03 01:13:23 -06:00
|
|
|
/*
|
|
|
|
* Jeilinj subdriver
|
|
|
|
*
|
|
|
|
* Supports some Jeilin dual-mode cameras which use bulk transport and
|
|
|
|
* download raw JPEG data.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Theodore Kilgore
|
2011-04-18 14:42:06 -06:00
|
|
|
*
|
|
|
|
* Sportscam DV15 support and control settings are
|
2011-04-18 14:37:06 -06:00
|
|
|
* Copyright (C) 2011 Patrice Chotard
|
2009-08-03 01:13:23 -06: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
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2011-08-21 16:56:57 -06:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
#define MODULE_NAME "jeilinj"
|
|
|
|
|
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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2009-08-03 01:13:23 -06:00
|
|
|
#include "gspca.h"
|
|
|
|
#include "jpeg.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
|
|
|
|
MODULE_DESCRIPTION("GSPCA/JEILINJ USB Camera Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* Default timeouts, in ms */
|
|
|
|
#define JEILINJ_CMD_TIMEOUT 500
|
2011-04-18 14:40:54 -06:00
|
|
|
#define JEILINJ_CMD_DELAY 160
|
2009-08-03 01:13:23 -06:00
|
|
|
#define JEILINJ_DATA_TIMEOUT 1000
|
|
|
|
|
|
|
|
/* Maximum transfer size to use. */
|
|
|
|
#define JEILINJ_MAX_TRANSFER 0x200
|
|
|
|
#define FRAME_HEADER_LEN 0x10
|
2011-04-18 14:37:06 -06:00
|
|
|
#define FRAME_START 0xFFFFFFFF
|
2009-08-03 01:13:23 -06:00
|
|
|
|
2011-04-18 14:40:54 -06:00
|
|
|
enum {
|
|
|
|
SAKAR_57379,
|
|
|
|
SPORTSCAM_DV15,
|
|
|
|
};
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
#define CAMQUALITY_MIN 0 /* highest cam quality */
|
|
|
|
#define CAMQUALITY_MAX 97 /* lowest cam quality */
|
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
/* Structure to hold all of our device specific stuff */
|
|
|
|
struct sd {
|
|
|
|
struct gspca_dev gspca_dev; /* !! must be the first item */
|
2011-04-18 14:37:06 -06:00
|
|
|
int blocks_left;
|
2009-08-03 01:13:23 -06:00
|
|
|
const struct v4l2_pix_format *cap_mode;
|
2012-05-14 03:30:06 -06:00
|
|
|
struct v4l2_ctrl *freq;
|
|
|
|
struct v4l2_ctrl *jpegqual;
|
2009-08-03 01:13:23 -06:00
|
|
|
/* Driver stuff */
|
2011-04-18 14:40:54 -06:00
|
|
|
u8 type;
|
2009-08-03 01:13:23 -06:00
|
|
|
u8 quality; /* image quality */
|
2011-04-18 14:42:06 -06:00
|
|
|
#define QUALITY_MIN 35
|
|
|
|
#define QUALITY_MAX 85
|
|
|
|
#define QUALITY_DEF 85
|
2010-06-04 02:26:42 -06:00
|
|
|
u8 jpeg_hdr[JPEG_HDR_SZ];
|
2009-08-03 01:13:23 -06:00
|
|
|
};
|
|
|
|
|
2011-04-18 14:37:06 -06:00
|
|
|
struct jlj_command {
|
|
|
|
unsigned char instruction[2];
|
|
|
|
unsigned char ack_wanted;
|
2011-04-18 14:40:54 -06:00
|
|
|
unsigned char delay;
|
2011-04-18 14:37:06 -06:00
|
|
|
};
|
2009-08-03 01:13:23 -06:00
|
|
|
|
|
|
|
/* AFAICT these cameras will only do 320x240. */
|
|
|
|
static struct v4l2_pix_format jlj_mode[] = {
|
|
|
|
{ 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
|
|
|
|
.bytesperline = 320,
|
|
|
|
.sizeimage = 320 * 240,
|
|
|
|
.colorspace = V4L2_COLORSPACE_JPEG,
|
2011-04-18 14:39:38 -06:00
|
|
|
.priv = 0},
|
|
|
|
{ 640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
|
|
|
|
.bytesperline = 640,
|
|
|
|
.sizeimage = 640 * 480,
|
|
|
|
.colorspace = V4L2_COLORSPACE_JPEG,
|
2009-08-03 01:13:23 -06:00
|
|
|
.priv = 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cam uses endpoint 0x03 to send commands, 0x84 for read commands,
|
|
|
|
* and 0x82 for bulk transfer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* All commands are two bytes only */
|
2011-04-18 14:38:37 -06:00
|
|
|
static void jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command)
|
2009-08-03 01:13:23 -06:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2011-04-18 14:38:37 -06:00
|
|
|
if (gspca_dev->usb_err < 0)
|
|
|
|
return;
|
2009-08-03 01:13:23 -06:00
|
|
|
memcpy(gspca_dev->usb_buf, command, 2);
|
|
|
|
retval = usb_bulk_msg(gspca_dev->dev,
|
|
|
|
usb_sndbulkpipe(gspca_dev->dev, 3),
|
|
|
|
gspca_dev->usb_buf, 2, NULL, 500);
|
2011-04-18 14:38:37 -06:00
|
|
|
if (retval < 0) {
|
2011-08-21 16:56:57 -06:00
|
|
|
pr_err("command write [%02x] error %d\n",
|
|
|
|
gspca_dev->usb_buf[0], retval);
|
2011-04-18 14:38:37 -06:00
|
|
|
gspca_dev->usb_err = retval;
|
|
|
|
}
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Responses are one byte only */
|
2012-10-27 11:54:01 -06:00
|
|
|
static void jlj_read1(struct gspca_dev *gspca_dev, unsigned char *response)
|
2009-08-03 01:13:23 -06:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2011-04-18 14:38:37 -06:00
|
|
|
if (gspca_dev->usb_err < 0)
|
|
|
|
return;
|
2009-08-03 01:13:23 -06:00
|
|
|
retval = usb_bulk_msg(gspca_dev->dev,
|
|
|
|
usb_rcvbulkpipe(gspca_dev->dev, 0x84),
|
|
|
|
gspca_dev->usb_buf, 1, NULL, 500);
|
2012-10-27 11:54:01 -06:00
|
|
|
*response = gspca_dev->usb_buf[0];
|
2011-04-18 14:38:37 -06:00
|
|
|
if (retval < 0) {
|
2011-08-21 16:56:57 -06:00
|
|
|
pr_err("read command [%02x] error %d\n",
|
|
|
|
gspca_dev->usb_buf[0], retval);
|
2011-04-18 14:38:37 -06:00
|
|
|
gspca_dev->usb_err = retval;
|
|
|
|
}
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setfreq(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 freq_commands[][2] = {
|
|
|
|
{0x71, 0x80},
|
|
|
|
{0x70, 0x07}
|
|
|
|
};
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
freq_commands[0][1] |= val >> 1;
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
jlj_write2(gspca_dev, freq_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, freq_commands[1]);
|
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setcamquality(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 quality_commands[][2] = {
|
|
|
|
{0x71, 0x1E},
|
|
|
|
{0x70, 0x06}
|
|
|
|
};
|
|
|
|
u8 camquality;
|
|
|
|
|
|
|
|
/* adapt camera quality from jpeg quality */
|
2012-05-14 03:30:06 -06:00
|
|
|
camquality = ((QUALITY_MAX - val) * CAMQUALITY_MAX)
|
2011-04-18 14:42:06 -06:00
|
|
|
/ (QUALITY_MAX - QUALITY_MIN);
|
|
|
|
quality_commands[0][1] += camquality;
|
|
|
|
|
|
|
|
jlj_write2(gspca_dev, quality_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, quality_commands[1]);
|
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setautogain(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 autogain_commands[][2] = {
|
|
|
|
{0x94, 0x02},
|
|
|
|
{0xcf, 0x00}
|
|
|
|
};
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
autogain_commands[1][1] = val << 4;
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
jlj_write2(gspca_dev, autogain_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, autogain_commands[1]);
|
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setred(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 setred_commands[][2] = {
|
|
|
|
{0x94, 0x02},
|
|
|
|
{0xe6, 0x00}
|
|
|
|
};
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
setred_commands[1][1] = val;
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
jlj_write2(gspca_dev, setred_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, setred_commands[1]);
|
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setgreen(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 setgreen_commands[][2] = {
|
|
|
|
{0x94, 0x02},
|
|
|
|
{0xe7, 0x00}
|
|
|
|
};
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
setgreen_commands[1][1] = val;
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
jlj_write2(gspca_dev, setgreen_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, setgreen_commands[1]);
|
|
|
|
}
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static void setblue(struct gspca_dev *gspca_dev, s32 val)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
u8 setblue_commands[][2] = {
|
|
|
|
{0x94, 0x02},
|
|
|
|
{0xe9, 0x00}
|
|
|
|
};
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
setblue_commands[1][1] = val;
|
2011-04-18 14:42:06 -06:00
|
|
|
|
|
|
|
jlj_write2(gspca_dev, setblue_commands[0]);
|
|
|
|
jlj_write2(gspca_dev, setblue_commands[1]);
|
|
|
|
}
|
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
static int jlj_start(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
int i;
|
2011-04-18 14:40:54 -06:00
|
|
|
int start_commands_size;
|
2009-08-03 01:13:23 -06:00
|
|
|
u8 response = 0xff;
|
2011-04-18 14:37:06 -06:00
|
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
2009-08-03 01:13:23 -06:00
|
|
|
struct jlj_command start_commands[] = {
|
2011-04-18 14:40:54 -06:00
|
|
|
{{0x71, 0x81}, 0, 0},
|
|
|
|
{{0x70, 0x05}, 0, JEILINJ_CMD_DELAY},
|
|
|
|
{{0x95, 0x70}, 1, 0},
|
|
|
|
{{0x71, 0x81 - gspca_dev->curr_mode}, 0, 0},
|
|
|
|
{{0x70, 0x04}, 0, JEILINJ_CMD_DELAY},
|
|
|
|
{{0x95, 0x70}, 1, 0},
|
|
|
|
{{0x71, 0x00}, 0, 0}, /* start streaming ??*/
|
|
|
|
{{0x70, 0x08}, 0, JEILINJ_CMD_DELAY},
|
|
|
|
{{0x95, 0x70}, 1, 0},
|
|
|
|
#define SPORTSCAM_DV15_CMD_SIZE 9
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xde, 0x24}, 0, 0},
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xdd, 0xf0}, 0, 0},
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xe3, 0x2c}, 0, 0},
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xe4, 0x00}, 0, 0},
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xe5, 0x00}, 0, 0},
|
|
|
|
{{0x94, 0x02}, 0, 0},
|
|
|
|
{{0xe6, 0x2c}, 0, 0},
|
|
|
|
{{0x94, 0x03}, 0, 0},
|
2011-04-18 14:42:06 -06:00
|
|
|
{{0xaa, 0x00}, 0, 0}
|
2009-08-03 01:13:23 -06:00
|
|
|
};
|
2011-04-18 14:37:06 -06:00
|
|
|
|
|
|
|
sd->blocks_left = 0;
|
2011-04-18 14:40:54 -06:00
|
|
|
/* Under Windows, USB spy shows that only the 9 first start
|
|
|
|
* commands are used for SPORTSCAM_DV15 webcam
|
|
|
|
*/
|
|
|
|
if (sd->type == SPORTSCAM_DV15)
|
|
|
|
start_commands_size = SPORTSCAM_DV15_CMD_SIZE;
|
|
|
|
else
|
|
|
|
start_commands_size = ARRAY_SIZE(start_commands);
|
|
|
|
|
|
|
|
for (i = 0; i < start_commands_size; i++) {
|
2011-04-18 14:38:37 -06:00
|
|
|
jlj_write2(gspca_dev, start_commands[i].instruction);
|
2011-04-18 14:40:54 -06:00
|
|
|
if (start_commands[i].delay)
|
|
|
|
msleep(start_commands[i].delay);
|
2009-08-03 01:13:23 -06:00
|
|
|
if (start_commands[i].ack_wanted)
|
2012-10-27 11:54:01 -06:00
|
|
|
jlj_read1(gspca_dev, &response);
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
2012-05-14 03:30:06 -06:00
|
|
|
setcamquality(gspca_dev, v4l2_ctrl_g_ctrl(sd->jpegqual));
|
2011-04-18 14:42:06 -06:00
|
|
|
msleep(2);
|
2012-05-14 03:30:06 -06:00
|
|
|
setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq));
|
2011-04-18 14:38:37 -06:00
|
|
|
if (gspca_dev->usb_err < 0)
|
2013-02-04 09:17:55 -07:00
|
|
|
PERR("Start streaming command failed");
|
2011-04-18 14:38:37 -06:00
|
|
|
return gspca_dev->usb_err;
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
2011-04-18 14:37:06 -06:00
|
|
|
static void sd_pkt_scan(struct gspca_dev *gspca_dev,
|
|
|
|
u8 *data, int len)
|
2009-08-03 01:13:23 -06:00
|
|
|
{
|
2011-04-18 14:37:06 -06:00
|
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
2009-08-03 01:13:23 -06:00
|
|
|
int packet_type;
|
2011-04-18 14:37:06 -06:00
|
|
|
u32 header_marker;
|
2009-08-03 01:13:23 -06:00
|
|
|
|
2011-04-18 14:37:06 -06:00
|
|
|
PDEBUG(D_STREAM, "Got %d bytes out of %d for Block 0",
|
|
|
|
len, JEILINJ_MAX_TRANSFER);
|
|
|
|
if (len != JEILINJ_MAX_TRANSFER) {
|
|
|
|
PDEBUG(D_PACK, "bad length");
|
|
|
|
goto discard;
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
2011-04-18 14:37:06 -06:00
|
|
|
/* check if it's start of frame */
|
|
|
|
header_marker = ((u32 *)data)[0];
|
|
|
|
if (header_marker == FRAME_START) {
|
|
|
|
sd->blocks_left = data[0x0a] - 1;
|
|
|
|
PDEBUG(D_STREAM, "blocks_left = 0x%x", sd->blocks_left);
|
2009-10-09 00:58:35 -06:00
|
|
|
/* Start a new frame, and add the JPEG header, first thing */
|
2009-11-13 05:21:03 -07:00
|
|
|
gspca_frame_add(gspca_dev, FIRST_PACKET,
|
2011-04-18 14:37:06 -06:00
|
|
|
sd->jpeg_hdr, JPEG_HDR_SZ);
|
2009-11-13 05:21:03 -07:00
|
|
|
/* Toss line 0 of data block 0, keep the rest. */
|
|
|
|
gspca_frame_add(gspca_dev, INTER_PACKET,
|
2011-04-18 14:37:06 -06:00
|
|
|
data + FRAME_HEADER_LEN,
|
2009-08-03 01:13:23 -06:00
|
|
|
JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN);
|
2011-04-18 14:37:06 -06:00
|
|
|
} else if (sd->blocks_left > 0) {
|
|
|
|
PDEBUG(D_STREAM, "%d blocks remaining for frame",
|
|
|
|
sd->blocks_left);
|
|
|
|
sd->blocks_left -= 1;
|
|
|
|
if (sd->blocks_left == 0)
|
|
|
|
packet_type = LAST_PACKET;
|
|
|
|
else
|
|
|
|
packet_type = INTER_PACKET;
|
|
|
|
gspca_frame_add(gspca_dev, packet_type,
|
|
|
|
data, JEILINJ_MAX_TRANSFER);
|
|
|
|
} else
|
|
|
|
goto discard;
|
|
|
|
return;
|
|
|
|
discard:
|
|
|
|
/* Discard data until a new frame starts. */
|
|
|
|
gspca_dev->last_packet_type = DISCARD_PACKET;
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is called at probe time just before sd_init */
|
|
|
|
static int sd_config(struct gspca_dev *gspca_dev,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct cam *cam = &gspca_dev->cam;
|
|
|
|
struct sd *dev = (struct sd *) gspca_dev;
|
|
|
|
|
2011-04-18 14:40:54 -06:00
|
|
|
dev->type = id->driver_info;
|
2011-04-18 14:42:06 -06:00
|
|
|
dev->quality = QUALITY_DEF;
|
2011-07-03 04:27:24 -06:00
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
cam->cam_mode = jlj_mode;
|
2011-04-18 14:39:38 -06:00
|
|
|
cam->nmodes = ARRAY_SIZE(jlj_mode);
|
2009-08-03 01:13:23 -06:00
|
|
|
cam->bulk = 1;
|
2011-04-18 14:37:06 -06:00
|
|
|
cam->bulk_nurbs = 1;
|
|
|
|
cam->bulk_size = JEILINJ_MAX_TRANSFER;
|
2009-08-03 01:13:23 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-18 14:37:06 -06:00
|
|
|
static void sd_stopN(struct gspca_dev *gspca_dev)
|
2009-08-03 01:13:23 -06:00
|
|
|
{
|
2011-04-18 14:37:06 -06:00
|
|
|
int i;
|
|
|
|
u8 *buf;
|
2011-07-03 04:27:24 -06:00
|
|
|
static u8 stop_commands[][2] = {
|
2011-04-18 14:37:06 -06:00
|
|
|
{0x71, 0x00},
|
|
|
|
{0x70, 0x09},
|
|
|
|
{0x71, 0x80},
|
|
|
|
{0x70, 0x05}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* get the image remaining blocks */
|
|
|
|
usb_bulk_msg(gspca_dev->dev,
|
|
|
|
gspca_dev->urb[0]->pipe,
|
|
|
|
gspca_dev->urb[0]->transfer_buffer,
|
|
|
|
JEILINJ_MAX_TRANSFER, NULL,
|
|
|
|
JEILINJ_DATA_TIMEOUT);
|
2009-08-03 01:13:23 -06:00
|
|
|
|
2011-04-18 14:37:06 -06:00
|
|
|
/* search for 0xff 0xd9 (EOF for JPEG) */
|
|
|
|
i = 0;
|
|
|
|
buf = gspca_dev->urb[0]->transfer_buffer;
|
|
|
|
while ((i < (JEILINJ_MAX_TRANSFER - 1)) &&
|
|
|
|
((buf[i] != 0xff) || (buf[i+1] != 0xd9)))
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i != (JEILINJ_MAX_TRANSFER - 1))
|
|
|
|
/* last remaining block found */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(stop_commands); i++)
|
|
|
|
jlj_write2(gspca_dev, stop_commands[i]);
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called at probe and resume time */
|
|
|
|
static int sd_init(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
2011-04-18 14:38:37 -06:00
|
|
|
return gspca_dev->usb_err;
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up for getting frames. */
|
|
|
|
static int sd_start(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
struct sd *dev = (struct sd *) gspca_dev;
|
|
|
|
|
|
|
|
/* create the JPEG header */
|
2013-08-30 14:54:23 -06:00
|
|
|
jpeg_define(dev->jpeg_hdr, gspca_dev->pixfmt.height,
|
|
|
|
gspca_dev->pixfmt.width,
|
2009-08-03 01:13:23 -06:00
|
|
|
0x21); /* JPEG 422 */
|
|
|
|
jpeg_set_qual(dev->jpeg_hdr, dev->quality);
|
2011-04-18 14:39:38 -06:00
|
|
|
PDEBUG(D_STREAM, "Start streaming at %dx%d",
|
2013-08-30 14:54:23 -06:00
|
|
|
gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
|
2011-04-18 14:38:37 -06:00
|
|
|
jlj_start(gspca_dev);
|
|
|
|
return gspca_dev->usb_err;
|
2009-08-03 01:13:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Table of supported USB devices */
|
2011-01-13 01:20:29 -07:00
|
|
|
static const struct usb_device_id device_table[] = {
|
2011-04-18 14:40:54 -06:00
|
|
|
{USB_DEVICE(0x0979, 0x0280), .driver_info = SAKAR_57379},
|
|
|
|
{USB_DEVICE(0x0979, 0x0270), .driver_info = SPORTSCAM_DV15},
|
2009-08-03 01:13:23 -06:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, device_table);
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
2012-05-14 03:30:06 -06:00
|
|
|
struct gspca_dev *gspca_dev =
|
|
|
|
container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
|
|
|
|
struct sd *sd = (struct sd *)gspca_dev;
|
|
|
|
|
|
|
|
gspca_dev->usb_err = 0;
|
|
|
|
|
|
|
|
if (!gspca_dev->streaming)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
2011-04-18 14:42:06 -06:00
|
|
|
case V4L2_CID_POWER_LINE_FREQUENCY:
|
2012-05-14 03:30:06 -06:00
|
|
|
setfreq(gspca_dev, ctrl->val);
|
|
|
|
break;
|
|
|
|
case V4L2_CID_RED_BALANCE:
|
|
|
|
setred(gspca_dev, ctrl->val);
|
|
|
|
break;
|
|
|
|
case V4L2_CID_GAIN:
|
|
|
|
setgreen(gspca_dev, ctrl->val);
|
|
|
|
break;
|
|
|
|
case V4L2_CID_BLUE_BALANCE:
|
|
|
|
setblue(gspca_dev, ctrl->val);
|
|
|
|
break;
|
|
|
|
case V4L2_CID_AUTOGAIN:
|
|
|
|
setautogain(gspca_dev, ctrl->val);
|
|
|
|
break;
|
|
|
|
case V4L2_CID_JPEG_COMPRESSION_QUALITY:
|
|
|
|
jpeg_set_qual(sd->jpeg_hdr, ctrl->val);
|
|
|
|
setcamquality(gspca_dev, ctrl->val);
|
2011-04-18 14:42:06 -06:00
|
|
|
break;
|
|
|
|
}
|
2012-05-14 03:30:06 -06:00
|
|
|
return gspca_dev->usb_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
|
|
|
|
.s_ctrl = sd_s_ctrl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sd_init_controls(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
struct sd *sd = (struct sd *)gspca_dev;
|
|
|
|
struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
|
|
|
|
static const struct v4l2_ctrl_config custom_autogain = {
|
|
|
|
.ops = &sd_ctrl_ops,
|
|
|
|
.id = V4L2_CID_AUTOGAIN,
|
|
|
|
.type = V4L2_CTRL_TYPE_INTEGER,
|
|
|
|
.name = "Automatic Gain (and Exposure)",
|
|
|
|
.max = 3,
|
|
|
|
.step = 1,
|
|
|
|
.def = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
gspca_dev->vdev.ctrl_handler = hdl;
|
|
|
|
v4l2_ctrl_handler_init(hdl, 6);
|
|
|
|
sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
|
|
|
|
V4L2_CID_POWER_LINE_FREQUENCY,
|
|
|
|
V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 1,
|
|
|
|
V4L2_CID_POWER_LINE_FREQUENCY_60HZ);
|
|
|
|
v4l2_ctrl_new_custom(hdl, &custom_autogain, NULL);
|
|
|
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
|
|
|
V4L2_CID_RED_BALANCE, 0, 3, 1, 2);
|
|
|
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
|
|
|
V4L2_CID_GAIN, 0, 3, 1, 2);
|
|
|
|
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
|
|
|
V4L2_CID_BLUE_BALANCE, 0, 3, 1, 2);
|
|
|
|
sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
|
|
|
|
V4L2_CID_JPEG_COMPRESSION_QUALITY,
|
|
|
|
QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF);
|
|
|
|
|
|
|
|
if (hdl->error) {
|
|
|
|
pr_err("Could not initialize controls\n");
|
|
|
|
return hdl->error;
|
|
|
|
}
|
|
|
|
return 0;
|
2011-04-18 14:42:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sd_set_jcomp(struct gspca_dev *gspca_dev,
|
2012-09-17 02:05:25 -06:00
|
|
|
const struct v4l2_jpegcompression *jcomp)
|
2011-04-18 14:42:06 -06:00
|
|
|
{
|
|
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
|
|
|
2012-05-14 03:30:06 -06:00
|
|
|
v4l2_ctrl_s_ctrl(sd->jpegqual, jcomp->quality);
|
2011-04-18 14:42:06 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sd_get_jcomp(struct gspca_dev *gspca_dev,
|
|
|
|
struct v4l2_jpegcompression *jcomp)
|
|
|
|
{
|
|
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
|
|
|
|
|
|
memset(jcomp, 0, sizeof *jcomp);
|
2012-05-14 03:30:06 -06:00
|
|
|
jcomp->quality = v4l2_ctrl_g_ctrl(sd->jpegqual);
|
2011-04-18 14:42:06 -06:00
|
|
|
jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
|
|
|
|
| V4L2_JPEG_MARKER_DQT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
/* sub-driver description */
|
2011-04-18 14:40:54 -06:00
|
|
|
static const struct sd_desc sd_desc_sakar_57379 = {
|
|
|
|
.name = MODULE_NAME,
|
|
|
|
.config = sd_config,
|
|
|
|
.init = sd_init,
|
|
|
|
.start = sd_start,
|
|
|
|
.stopN = sd_stopN,
|
|
|
|
.pkt_scan = sd_pkt_scan,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* sub-driver description */
|
|
|
|
static const struct sd_desc sd_desc_sportscam_dv15 = {
|
2009-08-03 01:13:23 -06:00
|
|
|
.name = MODULE_NAME,
|
|
|
|
.config = sd_config,
|
|
|
|
.init = sd_init,
|
2012-05-14 03:30:06 -06:00
|
|
|
.init_controls = sd_init_controls,
|
2009-08-03 01:13:23 -06:00
|
|
|
.start = sd_start,
|
2011-04-18 14:37:06 -06:00
|
|
|
.stopN = sd_stopN,
|
|
|
|
.pkt_scan = sd_pkt_scan,
|
2011-04-18 14:42:06 -06:00
|
|
|
.get_jcomp = sd_get_jcomp,
|
|
|
|
.set_jcomp = sd_set_jcomp,
|
2009-08-03 01:13:23 -06:00
|
|
|
};
|
|
|
|
|
2011-04-18 14:40:54 -06:00
|
|
|
static const struct sd_desc *sd_desc[2] = {
|
|
|
|
&sd_desc_sakar_57379,
|
|
|
|
&sd_desc_sportscam_dv15
|
|
|
|
};
|
|
|
|
|
2009-08-03 01:13:23 -06:00
|
|
|
/* -- device connect -- */
|
|
|
|
static int sd_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
return gspca_dev_probe(intf, id,
|
2011-04-18 14:40:54 -06:00
|
|
|
sd_desc[id->driver_info],
|
2009-08-03 01:13:23 -06:00
|
|
|
sizeof(struct sd),
|
|
|
|
THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver sd_driver = {
|
|
|
|
.name = MODULE_NAME,
|
|
|
|
.id_table = device_table,
|
|
|
|
.probe = sd_probe,
|
|
|
|
.disconnect = gspca_disconnect,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = gspca_suspend,
|
|
|
|
.resume = gspca_resume,
|
2012-06-30 03:44:47 -06:00
|
|
|
.reset_resume = gspca_resume,
|
2009-08-03 01:13:23 -06:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2011-11-18 10:46:12 -07:00
|
|
|
module_usb_driver(sd_driver);
|