// SPDX-License-Identifier: GPL-2.0-or-later
/*
* T613 subdriver
*
* Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
*
*Notes: * t613 + tas5130A
* * Focus to light do not balance well as in win.
* Quality in win is not good, but its kinda better.
* * Fix some "extraneous bytes", most of apps will show the image anyway
* * Gamma table, is there, but its really doing something?
* * 7~8 Fps, its ok, max on win its 10.
* Costantino Leandro
*/
#define pr_fmt(fmt) KBUILD_MODNAME
": " fmt
#define MODULE_NAME
"t613"
#include <linux/input.h>
#include <linux/slab.h>
#include "gspca.h"
MODULE_AUTHOR(
"Leandro Costantino <le_costantino@pixartargentina.com.ar>" );
MODULE_DESCRIPTION(
"GSPCA/T613 (JPEG Compliance) USB Camera Driver" );
MODULE_LICENSE(
"GPL" );
struct sd {
struct gspca_dev gspca_dev;
/* !! must be the first item */
struct v4l2_ctrl *freq;
struct {
/* awb / color gains control cluster */
struct v4l2_ctrl *awb;
struct v4l2_ctrl *gain;
struct v4l2_ctrl *red_balance;
struct v4l2_ctrl *blue_balance;
};
u8 sensor;
u8 button_pressed;
};
enum sensors {
SENSOR_OM6802,
SENSOR_OTHER,
SENSOR_TAS5130A,
SENSOR_LT168G,
/* must verify if this is the actual model */
};
static const struct v4l2_pix_format vga_mode_t16[] = {
{
160 ,
120 , V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline =
160 ,
.sizeimage =
160 *
120 *
4 /
8 +
590 ,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv =
4 },
#if 0 /* HDG: broken with my test cam, so lets disable it */
{
176 ,
144 , V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline =
176 ,
.sizeimage =
176 *
144 *
3 /
8 +
590 ,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv =
3 },
#endif
{
320 ,
240 , V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline =
320 ,
.sizeimage =
320 *
240 *
3 /
8 +
590 ,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv =
2 },
#if 0 /* HDG: broken with my test cam, so lets disable it */
{
352 ,
288 , V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline =
352 ,
.sizeimage =
352 *
288 *
3 /
8 +
590 ,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv =
1 },
#endif
{
640 ,
480 , V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline =
640 ,
.sizeimage =
640 *
480 *
3 /
8 +
590 ,
.colorspace = V4L2_COLORSPACE_JPEG,
.priv =
0 },
};
/* sensor specific data */
struct additional_sensor_data {
const u8 n3[
6 ];
const u8 *n4, n4sz;
const u8 reg80, reg8e;
const u8 nset8[
6 ];
const u8 data1[
10 ];
const u8 data2[
9 ];
const u8 data3[
9 ];
const u8 data5[
6 ];
const u8 stream[
4 ];
};
static const u8 n4_om6802[] = {
0 x09,
0 x01,
0 x12,
0 x04,
0 x66,
0 x8a,
0 x80,
0 x3c,
0 x81,
0 x22,
0 x84,
0 x50,
0 x8a,
0 x78,
0 x8b,
0 x68,
0 x8c,
0 x88,
0 x8e,
0 x33,
0 x8f,
0 x24,
0 xaa,
0 xb1,
0 xa2,
0 x60,
0 xa5,
0 x30,
0 xa6,
0 x3a,
0 xa8,
0 xe8,
0 xae,
0 x05,
0 xb1,
0 x00,
0 xbb,
0 x04,
0 xbc,
0 x48,
0 xbe,
0 x36,
0 xc6,
0 x88,
0 xe9,
0 x00,
0 xc5,
0 xc0,
0 x65,
0 x0a,
0 xbb,
0 x86,
0 xaf,
0 x58,
0 xb0,
0 x68,
0 x87,
0 x40,
0 x89,
0 x2b,
0 x8d,
0 xff,
0 x83,
0 x40,
0 xac,
0 x84,
0 xad,
0 x86,
0 xaf,
0 x46
};
static const u8 n4_other[] = {
0 x66,
0 x00,
0 x7f,
0 x00,
0 x80,
0 xac,
0 x81,
0 x69,
0 x84,
0 x40,
0 x85,
0 x70,
0 x86,
0 x20,
0 x8a,
0 x68,
0 x8b,
0 x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xda,
0 x8e,
0 xdb,
0 xca,
0 xdc,
0 xa8,
0 xdd,
0 x8c,
0 xde,
0 x44,
0 xdf,
0 x0c,
0 xe9,
0 x80
};
static const struct additional_sensor_data sensor_data[] = {
[SENSOR_OM6802] = {
.n3 =
{
0 x61,
0 x68,
0 x65,
0 x0a,
0 x60,
0 x04},
.n4 = n4_om6802,
.n4sz =
sizeof n4_om6802,
.reg80 =
0 x3c,
.reg8e =
0 x33,
.nset8 = {
0 xa8,
0 xf0,
0 xc6,
0 x88,
0 xc0,
0 x00},
.data1 =
{
0 xc2,
0 x28,
0 x0f,
0 x22,
0 xcd,
0 x27,
0 x2c,
0 x06,
0 xb3,
0 xfc},
.data2 =
{
0 x80,
0 xff,
0 xff,
0 x80,
0 xff,
0 xff,
0 x80,
0 xff,
0 xff},
.data3 =
{
0 x80,
0 xff,
0 xff,
0 x80,
0 xff,
0 xff,
0 x80,
0 xff,
0 xff},
.data5 =
/* this could be removed later */
{
0 x0c,
0 x03,
0 xab,
0 x13,
0 x81,
0 x23},
.stream =
{
0 x0b,
0 x04,
0 x0a,
0 x78},
},
[SENSOR_OTHER] = {
.n3 =
{
0 x61,
0 xc2,
0 x65,
0 x88,
0 x60,
0 x00},
.n4 = n4_other,
.n4sz =
sizeof n4_other,
.reg80 =
0 xac,
.reg8e =
0 xb8,
.nset8 = {
0 xa8,
0 xa8,
0 xc6,
0 xda,
0 xc0,
0 x00},
.data1 =
{
0 xc1,
0 x48,
0 x04,
0 x1b,
0 xca,
0 x2e,
0 x33,
0 x3a,
0 xe8,
0 xfc},
.data2 =
{
0 x4e,
0 x9c,
0 xec,
0 x40,
0 x80,
0 xc0,
0 x48,
0 x96,
0 xd9},
.data3 =
{
0 x4e,
0 x9c,
0 xec,
0 x40,
0 x80,
0 xc0,
0 x48,
0 x96,
0 xd9},
.data5 =
{
0 x0c,
0 x03,
0 xab,
0 x29,
0 x81,
0 x69},
.stream =
{
0 x0b,
0 x04,
0 x0a,
0 x00},
},
[SENSOR_TAS5130A] = {
.n3 =
{
0 x61,
0 xc2,
0 x65,
0 x0d,
0 x60,
0 x08},
.n4 = n4_tas5130a,
.n4sz =
sizeof n4_tas5130a,
.reg80 =
0 x3c,
.reg8e =
0 xb4,
.nset8 = {
0 xa8,
0 xf0,
0 xc6,
0 xda,
0 xc0,
0 x00},
.data1 =
{
0 xbb,
0 x28,
0 x10,
0 x10,
0 xbb,
0 x28,
0 x1e,
0 x27,
0 xc8,
0 xfc},
.data2 =
{
0 x60,
0 xa8,
0 xe0,
0 x60,
0 xa8,
0 xe0,
0 x60,
0 xa8,
0 xe0},
.data3 =
{
0 x60,
0 xa8,
0 xe0,
0 x60,
0 xa8,
0 xe0,
0 x60,
0 xa8,
0 xe0},
.data5 =
{
0 x0c,
0 x03,
0 xab,
0 x10,
0 x81,
0 x20},
.stream =
{
0 x0b,
0 x04,
0 x0a,
0 x40},
},
[SENSOR_LT168G] = {
.n3 = {
0 x61,
0 xc2,
0 x65,
0 x68,
0 x60,
0 x00},
.n4 = n4_lt168g,
.n4sz =
sizeof n4_lt168g,
.reg80 =
0 x7c,
.reg8e =
0 xb3,
.nset8 = {
0 xa8,
0 xf0,
0 xc6,
0 xba,
0 xc0,
0 x00},
.data1 = {
0 xc0,
0 x38,
0 x08,
0 x10,
0 xc0,
0 x30,
0 x10,
0 x40,
0 xb0,
0 xf4},
.data2 = {
0 x40,
0 x80,
0 xc0,
0 x50,
0 xa0,
0 xf0,
0 x53,
0 xa6,
0 xff},
.data3 = {
0 x40,
0 x80,
0 xc0,
0 x50,
0 xa0,
0 xf0,
0 x53,
0 xa6,
0 xff},
.data5 = {
0 x0c,
0 x03,
0 xab,
0 x4b,
0 x81,
0 x2b},
.stream = {
0 x0b,
0 x04,
0 x0a,
0 x28},
},
};
#define MAX_EFFECTS
7
static const u8 effects_table[MAX_EFFECTS][
6 ] = {
{
0 xa8,
0 xe8,
0 xc6,
0 xd2,
0 xc0,
0 x00},
/* Normal */
{
0 xa8,
0 xc8,
0 xc6,
0 x52,
0 xc0,
0 x04},
/* Repujar */
{
0 xa8,
0 xe8,
0 xc6,
0 xd2,
0 xc0,
0 x20},
/* Monochrome */
{
0 xa8,
0 xe8,
0 xc6,
0 xd2,
0 xc0,
0 x80},
/* Sepia */
{
0 xa8,
0 xc8,
0 xc6,
0 x52,
0 xc0,
0 x02},
/* Croquis */
{
0 xa8,
0 xc8,
0 xc6,
0 xd2,
0 xc0,
0 x10},
/* Sun Effect */
{
0 xa8,
0 xc8,
0 xc6,
0 xd2,
0 xc0,
0 x40},
/* Negative */
};
#define GAMMA_MAX (
15 )
static const u8 gamma_table[GAMMA_MAX+
1 ][
17 ] = {
/* gamma table from cam1690.ini */
{
0 x00,
0 x00,
0 x01,
0 x04,
0 x08,
0 x0e,
0 x16,
0 x21,
/* 0 */
0 x2e,
0 x3d,
0 x50,
0 x65,
0 x7d,
0 x99,
0 xb8,
0 xdb,
0 xff},
{
0 x00,
0 x01,
0 x03,
0 x08,
0 x0e,
0 x16,
0 x21,
0 x2d,
/* 1 */
0 x3c,
0 x4d,
0 x60,
0 x75,
0 x8d,
0 xa6,
0 xc2,
0 xe1,
0 xff},
{
0 x00,
0 x01,
0 x05,
0 x0b,
0 x12,
0 x1c,
0 x28,
0 x35,
/* 2 */
0 x45,
0 x56,
0 x69,
0 x7e,
0 x95,
0 xad,
0 xc7,
0 xe3,
0 xff},
{
0 x00,
0 x02,
0 x07,
0 x0f,
0 x18,
0 x24,
0 x30,
0 x3f,
/* 3 */
0 x4f,
0 x61,
0 x73,
0 x88,
0 x9d,
0 xb4,
0 xcd,
0 xe6,
0 xff},
{
0 x00,
0 x04,
0 x0b,
0 x15,
0 x20,
0 x2d,
0 x3b,
0 x4a,
/* 4 */
0 x5b,
0 x6c,
0 x7f,
0 x92,
0 xa7,
0 xbc,
0 xd2,
0 xe9,
0 xff},
{
0 x00,
0 x07,
0 x11,
0 x15,
0 x20,
0 x2d,
0 x48,
0 x58,
/* 5 */
0 x68,
0 x79,
0 x8b,
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
0 x9a,
0 xa8,
0 xb3,
0 xbd,
0 xc6,
/* 14 */
0 xcf,
0 xd6,
0 xdd,
0 xe3,
0 xe9,
0 xef,
0 xf4,
0 xfa,
0 xff},
{
0 x00,
0 x93,
0 xa8,
0 xb7,
0 xc1,
0 xca,
0 xd2,
0 xd8,
/* 15 */
0 xde,
0 xe3,
0 xe8,
0 xed,
0 xf1,
0 xf5,
0 xf8,
0 xfc,
0 xff}
};
static const u8 tas5130a_sensor_init[][
8 ] = {
{
0 x62,
0 x08,
0 x63,
0 x70,
0 x64,
0 x1d,
0 x60,
0 x09},
{
0 x62,
0 x20,
0 x63,
0 x01,
0 x64,
0 x02,
0 x60,
0 x09},
{
0 x62,
0 x07,
0 x63,
0 x03,
0 x64,
0 x00,
0 x60,
0 x09},
};
static u8 sensor_reset[] = {
0 x61,
0 x68,
0 x62,
0 xff,
0 x60,
0 x07};
/* read 1 byte */
static u8 reg_r(
struct gspca_dev *gspca_dev,
u16 index)
{
usb_control_msg(gspca_dev->dev,
usb_rcvctrlpipe(gspca_dev->dev,
0 ),
0 ,
/* request */
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0 ,
/* value */
index,
gspca_dev->usb_buf,
1 ,
500 );
return gspca_dev->usb_buf[
0 ];
}
static void reg_w(
struct gspca_dev *gspca_dev,
u16 index)
{
usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev,
0 ),
0 ,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0 , index,
NULL,
0 ,
500 );
}
static void reg_w_buf(
struct gspca_dev *gspca_dev,
const u8 *buffer, u16 len)
{
if (len <= USB_BUF_SZ) {
memcpy(gspca_dev->usb_buf, buffer, len);
usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev,
0 ),
0 ,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0 x01,
0 ,
gspca_dev->usb_buf, len,
500 );
}
else {
u8 *tmpbuf;
tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
if (!tmpbuf) {
pr_err(
"Out of memory\n" );
return ;
}
usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev,
0 ),
0 ,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0 x01,
0 ,
tmpbuf, len,
500 );
kfree(tmpbuf);
}
}
/* write values to consecutive registers */
static void reg_w_ixbuf(
struct gspca_dev *gspca_dev,
u8 reg,
const u8 *buffer, u16 len)
{
int i;
u8 *p, *tmpbuf;
if (len *
2 <= USB_BUF_SZ) {
p = tmpbuf = gspca_dev->usb_buf;
}
else {
p = tmpbuf = kmalloc_array(len,
2 , GFP_KERNEL);
if (!tmpbuf) {
pr_err(
"Out of memory\n" );
return ;
}
}
i = len;
while (--i >=
0 ) {
*p++ = reg++;
*p++ = *buffer++;
}
usb_control_msg(gspca_dev->dev,
usb_sndctrlpipe(gspca_dev->dev,
0 ),
0 ,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0 x01,
0 ,
tmpbuf, len *
2 ,
500 );
if (len *
2 > USB_BUF_SZ)
kfree(tmpbuf);
}
static void om6802_sensor_init(
struct gspca_dev *gspca_dev)
{
int i;
const u8 *p;
u8 byte;
u8 val[
6 ] = {
0 x62,
0 ,
0 x64,
0 ,
0 x60,
0 x05};
static const u8 sensor_init[] = {
0 xdf,
0 x6d,
0 xdd,
0 x18,
0 x5a,
0 xe0,
0 x5c,
0 x07,
0 x5d,
0 xb0,
0 x5e,
0 x1e,
0 x60,
0 x71,
0 xef,
0 x00,
0 xe9,
0 x00,
0 xea,
0 x00,
0 x90,
0 x24,
0 x91,
0 xb2,
0 x82,
0 x32,
0 xfd,
0 x41,
0 x00
/* table end */
};
reg_w_buf(gspca_dev, sensor_reset,
sizeof sensor_reset);
msleep(
100 );
i =
4 ;
while (--i >
0 ) {
byte = reg_r(gspca_dev,
0 x0060);
if (!(byte &
0 x01))
break ;
msleep(
100 );
}
byte = reg_r(gspca_dev,
0 x0063);
if (byte !=
0 x17) {
pr_err(
"Bad sensor reset %02x\n" , byte);
/* continue? */
}
p = sensor_init;
while (*p !=
0 ) {
val[
1 ] = *p++;
val[
3 ] = *p++;
if (*p ==
0 )
reg_w(gspca_dev,
0 x3c80);
reg_w_buf(gspca_dev, val,
sizeof val);
i =
4 ;
while (--i >=
0 ) {
msleep(
15 );
byte = reg_r(gspca_dev,
0 x60);
if (!(byte &
0 x01))
break ;
}
}
msleep(
15 );
reg_w(gspca_dev,
0 x3c80);
}
/* this function is called at probe time */
static int sd_config(
struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
{
struct cam *cam = &gspca_dev->cam;
cam->cam_mode = vga_mode_t16;
cam->nmodes = ARRAY_SIZE(vga_mode_t16);
return 0 ;
}
static void setbrightness(
struct gspca_dev *gspca_dev, s32 brightness)
{
u8 set6[
4 ] = {
0 x8f,
0 x24,
0 xc3,
0 x00 };
if (brightness <
7 ) {
set6[
1 ] =
0 x26;
set6[
3 ] =
0 x70 - brightness *
0 x10;
}
else {
set6[
3 ] =
0 x00 + ((brightness -
7 ) *
0 x10);
}
reg_w_buf(gspca_dev, set6,
sizeof set6);
}
static void setcontrast(
struct gspca_dev *gspca_dev, s32 contrast)
{
u16 reg_to_write;
if (contrast <
7 )
reg_to_write =
0 x8ea9 - contrast *
0 x200;
else
reg_to_write =
0 x00a9 + (contrast -
7 ) *
0 x200;
reg_w(gspca_dev, reg_to_write);
}
static void setcolors(
struct gspca_dev *gspca_dev, s32 val)
{
u16 reg_to_write;
reg_to_write =
0 x80bb + val *
0 x100;
/* was 0xc0 */
reg_w(gspca_dev, reg_to_write);
}
static void setgamma(
struct gspca_dev *gspca_dev, s32 val)
{
gspca_dbg(gspca_dev, D_CONF,
"Gamma: %d\n" , val);
reg_w_ixbuf(gspca_dev,
0 x90,
gamma_table[val],
sizeof gamma_table[
0 ]);
}
static void setawb_n_RGB(
struct gspca_dev *gspca_dev)
{
struct sd *sd = (
struct sd *) gspca_dev;
u8 all_gain_reg[
8 ] = {
0 x87,
0 x00,
0 x88,
0 x00,
0 x89,
0 x00,
0 x80,
0 x00 };
s32 red_gain, blue_gain, green_gain;
green_gain = sd->gain->val;
red_gain = green_gain + sd->red_balance->val;
if (red_gain >
0 x40)
red_gain =
0 x40;
else if (red_gain <
0 x10)
red_gain =
0 x10;
blue_gain = green_gain + sd->blue_balance->val;
if (blue_gain >
0 x40)
blue_gain =
0 x40;
else if (blue_gain <
0 x10)
blue_gain =
0 x10;
all_gain_reg[
1 ] = red_gain;
all_gain_reg[
3 ] = blue_gain;
all_gain_reg[
5 ] = green_gain;
all_gain_reg[
7 ] = sensor_data[sd->sensor].reg80;
if (!sd->awb->val)
all_gain_reg[
7 ] &= ~
0 x04;
/* AWB off */
reg_w_buf(gspca_dev, all_gain_reg,
sizeof all_gain_reg);
}
static void setsharpness(
struct gspca_dev *gspca_dev, s32 val)
{
u16 reg_to_write;
reg_to_write =
0 x0aa6 +
0 x1000 * val;
reg_w(gspca_dev, reg_to_write);
}
static void setfreq(
struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (
struct sd *) gspca_dev;
u8 reg66;
u8 freq[
4 ] = {
0 x66,
0 x00,
0 xa8,
0 xe8 };
switch (sd->sensor) {
case SENSOR_LT168G:
if (val !=
0 )
freq[
3 ] =
0 xa8;
reg66 =
0 x41;
break ;
case SENSOR_OM6802:
reg66 =
0 xca;
break ;
default :
reg66 =
0 x40;
break ;
}
switch (val) {
case 0 :
/* no flicker */
freq[
3 ] =
0 xf0;
break ;
case 2 :
/* 60Hz */
reg66 &= ~
0 x40;
break ;
}
freq[
1 ] = reg66;
reg_w_buf(gspca_dev, freq,
sizeof freq);
}
/* this function is called at probe and resume time */
static int sd_init(
struct gspca_dev *gspca_dev)
{
/* some of this registers are not really needed, because
* they are overridden by setbrigthness, setcontrast, etc.,
* but won't hurt anyway, and can help someone with similar webcam
* to see the initial parameters.*/
struct sd *sd = (
struct sd *) gspca_dev;
const struct additional_sensor_data *sensor;
int i;
u16 sensor_id;
u8 test_byte =
0 ;
static const u8 read_indexs[] =
{
0 x0a,
0 x0b,
0 x66,
0 x80,
0 x81,
0 x8e,
0 x8f,
0 xa5,
0 xa6,
0 xa8,
0 xbb,
0 xbc,
0 xc6,
0 x00 };
static const u8 n1[] =
{
0 x08,
0 x03,
0 x09,
0 x03,
0 x12,
0 x04};
static const u8 n2[] =
{
0 x08,
0 x00};
sensor_id = (reg_r(gspca_dev,
0 x06) <<
8 )
| reg_r(gspca_dev,
0 x07);
switch (sensor_id &
0 xff0f) {
case 0 x0801:
gspca_dbg(gspca_dev, D_PROBE,
"sensor tas5130a\n" );
sd->sensor = SENSOR_TAS5130A;
break ;
case 0 x0802:
gspca_dbg(gspca_dev, D_PROBE,
"sensor lt168g\n" );
sd->sensor = SENSOR_LT168G;
break ;
case 0 x0803:
gspca_dbg(gspca_dev, D_PROBE,
"sensor 'other'\n" );
sd->sensor = SENSOR_OTHER;
break ;
case 0 x0807:
gspca_dbg(gspca_dev, D_PROBE,
"sensor om6802\n" );
sd->sensor = SENSOR_OM6802;
break ;
default :
pr_err(
"unknown sensor %04x\n" , sensor_id);
return -EINVAL;
}
if (sd->sensor == SENSOR_OM6802) {
reg_w_buf(gspca_dev, n1,
sizeof n1);
i =
5 ;
while (--i >=
0 ) {
reg_w_buf(gspca_dev, sensor_reset,
sizeof sensor_reset);
test_byte = reg_r(gspca_dev,
0 x0063);
msleep(
100 );
if (test_byte ==
0 x17)
break ;
/* OK */
}
if (i <
0 ) {
pr_err(
"Bad sensor reset %02x\n" , test_byte);
return -EIO;
}
reg_w_buf(gspca_dev, n2,
sizeof n2);
}
i =
0 ;
while (read_indexs[i] !=
0 x00) {
test_byte = reg_r(gspca_dev, read_indexs[i]);
gspca_dbg(gspca_dev, D_STREAM,
"Reg 0x%02x = 0x%02x\n" ,
read_indexs[i], test_byte);
i++;
}
sensor = &sensor_data[sd->sensor];
reg_w_buf(gspca_dev, sensor->n3,
sizeof sensor->n3);
reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
if (sd->sensor == SENSOR_LT168G) {
test_byte = reg_r(gspca_dev,
0 x80);
gspca_dbg(gspca_dev, D_STREAM,
"Reg 0x%02x = 0x%02x\n" ,
0 x80,
test_byte);
reg_w(gspca_dev,
0 x6c80);
}
reg_w_ixbuf(gspca_dev,
0 xd0, sensor->data1,
sizeof sensor->data1);
reg_w_ixbuf(gspca_dev,
0 xc7, sensor->data2,
sizeof sensor->data2);
reg_w_ixbuf(gspca_dev,
0 xe0, sensor->data3,
sizeof sensor->data3);
reg_w(gspca_dev, (sensor->reg80 <<
8 ) +
0 x80);
reg_w(gspca_dev, (sensor->reg80 <<
8 ) +
0 x80);
reg_w(gspca_dev, (sensor->reg8e <<
8 ) +
0 x8e);
reg_w(gspca_dev, (
0 x20 <<
8 ) +
0 x87);
reg_w(gspca_dev, (
0 x20 <<
8 ) +
0 x88);
reg_w(gspca_dev, (
0 x20 <<
8 ) +
0 x89);
reg_w_buf(gspca_dev, sensor->data5,
sizeof sensor->data5);
reg_w_buf(gspca_dev, sensor->nset8,
sizeof sensor->nset8);
reg_w_buf(gspca_dev, sensor->stream,
sizeof sensor->stream);
if (sd->sensor == SENSOR_LT168G) {
test_byte = reg_r(gspca_dev,
0 x80);
gspca_dbg(gspca_dev, D_STREAM,
"Reg 0x%02x = 0x%02x\n" ,
0 x80,
test_byte);
reg_w(gspca_dev,
0 x6c80);
}
reg_w_ixbuf(gspca_dev,
0 xd0, sensor->data1,
sizeof sensor->data1);
reg_w_ixbuf(gspca_dev,
0 xc7, sensor->data2,
sizeof sensor->data2);
reg_w_ixbuf(gspca_dev,
0 xe0, sensor->data3,
sizeof sensor->data3);
return 0 ;
}
static void setmirror(
struct gspca_dev *gspca_dev, s32 val)
{
u8 hflipcmd[
8 ] =
{
0 x62,
0 x07,
0 x63,
0 x03,
0 x64,
0 x00,
0 x60,
0 x09};
if (val)
hflipcmd[
3 ] =
0 x01;
reg_w_buf(gspca_dev, hflipcmd,
sizeof hflipcmd);
}
static void seteffect(
struct gspca_dev *gspca_dev, s32 val)
{
int idx =
0 ;
switch (val) {
case V4L2_COLORFX_NONE:
break ;
case V4L2_COLORFX_BW:
idx =
2 ;
break ;
case V4L2_COLORFX_SEPIA:
idx =
3 ;
break ;
case V4L2_COLORFX_SKETCH:
idx =
4 ;
break ;
case V4L2_COLORFX_NEGATIVE:
idx =
6 ;
break ;
default :
break ;
}
reg_w_buf(gspca_dev, effects_table[idx],
sizeof effects_table[
0 ]);
if (val == V4L2_COLORFX_SKETCH)
reg_w(gspca_dev,
0 x4aa6);
else
reg_w(gspca_dev,
0 xfaa6);
}
/* Is this really needed?
* i added some module parameters for test with some users */
static void poll_sensor(
struct gspca_dev *gspca_dev)
{
static const u8 poll1[] =
{
0 x67,
0 x05,
0 x68,
0 x81,
0 x69,
0 x80,
0 x6a,
0 x82,
0 x6b,
0 x68,
0 x6c,
0 x69,
0 x72,
0 xd9,
0 x73,
0 x34,
0 x74,
0 x32,
0 x75,
0 x92,
0 x76,
0 x00,
0 x09,
0 x01,
0 x60,
0 x14};
static const u8 poll2[] =
{
0 x67,
0 x02,
0 x68,
0 x71,
0 x69,
0 x72,
0 x72,
0 xa9,
0 x73,
0 x02,
0 x73,
0 x02,
0 x60,
0 x14};
static const u8 noise03[] =
/* (some differences / ms-drv) */
{
0 xa6,
0 x0a,
0 xea,
0 xcf,
0 xbe,
0 x26,
0 xb1,
0 x5f,
0 xa1,
0 xb1,
0 xda,
0 x6b,
0 xdb,
0 x98,
0 xdf,
0 x0c,
0 xc2,
0 x80,
0 xc3,
0 x10};
gspca_dbg(gspca_dev, D_STREAM,
"[Sensor requires polling]\n" );
reg_w_buf(gspca_dev, poll1,
sizeof poll1);
reg_w_buf(gspca_dev, poll2,
sizeof poll2);
reg_w_buf(gspca_dev, noise03,
sizeof noise03);
}
static int sd_start(
struct gspca_dev *gspca_dev)
{
struct sd *sd = (
struct sd *) gspca_dev;
const struct additional_sensor_data *sensor;
int i, mode;
u8 t2[] = {
0 x07,
0 x00,
0 x0d,
0 x60,
0 x0e,
0 x80 };
static const u8 t3[] =
{
0 x07,
0 x00,
0 x88,
0 x02,
0 x06,
0 x00,
0 xe7,
0 x01 };
mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
switch (mode) {
case 0 :
/* 640x480 (0x00) */
break ;
case 1 :
/* 352x288 */
t2[
1 ] =
0 x40;
break ;
case 2 :
/* 320x240 */
t2[
1 ] =
0 x10;
break ;
case 3 :
/* 176x144 */
t2[
1 ] =
0 x50;
break ;
default :
/* case 4: * 160x120 */
t2[
1 ] =
0 x20;
break ;
}
switch (sd->sensor) {
case SENSOR_OM6802:
om6802_sensor_init(gspca_dev);
break ;
case SENSOR_TAS5130A:
i =
0 ;
for (;;) {
reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
sizeof tas5130a_sensor_init[
0 ]);
if (i >= ARRAY_SIZE(tas5130a_sensor_init) -
1 )
break ;
i++;
}
reg_w(gspca_dev,
0 x3c80);
/* just in case and to keep sync with logs (for mine) */
reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
sizeof tas5130a_sensor_init[
0 ]);
reg_w(gspca_dev,
0 x3c80);
break ;
}
sensor = &sensor_data[sd->sensor];
setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq));
reg_r(gspca_dev,
0 x0012);
reg_w_buf(gspca_dev, t2,
sizeof t2);
reg_w_ixbuf(gspca_dev,
0 xb3, t3,
sizeof t3);
reg_w(gspca_dev,
0 x0013);
msleep(
15 );
reg_w_buf(gspca_dev, sensor->stream,
sizeof sensor->stream);
reg_w_buf(gspca_dev, sensor->stream,
sizeof sensor->stream);
if (sd->sensor == SENSOR_OM6802)
poll_sensor(gspca_dev);
return 0 ;
}
static void sd_stopN(
struct gspca_dev *gspca_dev)
{
struct sd *sd = (
struct sd *) gspca_dev;
reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
sizeof sensor_data[sd->sensor].stream);
reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
sizeof sensor_data[sd->sensor].stream);
if (sd->sensor == SENSOR_OM6802) {
msleep(
20 );
reg_w(gspca_dev,
0 x0309);
}
#if IS_ENABLED(CONFIG_INPUT)
/* If the last button state is pressed, release it now! */
if (sd->button_pressed) {
input_report_key(gspca_dev->input_dev, KEY_CAMERA,
0 );
input_sync(gspca_dev->input_dev);
sd->button_pressed =
0 ;
}
#endif
}
static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
u8 *data,
/* isoc packet */
int len)
/* iso packet length */
{
struct sd *sd __maybe_unused = (
struct sd *) gspca_dev;
int pkt_type;
if (data[
0 ] ==
0 x5a) {
#if IS_ENABLED(CONFIG_INPUT)
if (len >
20 ) {
u8 state = (data[
20 ] &
0 x80) ?
1 :
0 ;
if (sd->button_pressed != state) {
input_report_key(gspca_dev->input_dev,
KEY_CAMERA, state);
input_sync(gspca_dev->input_dev);
sd->button_pressed = state;
}
}
#endif
/* Control Packet, after this came the header again,
* but extra bytes came in the packet before this,
* sometimes an EOF arrives, sometimes not... */
return ;
}
data +=
2 ;
len -=
2 ;
if (data[
0 ] ==
0 xff && data[
1 ] ==
0 xd8)
pkt_type = FIRST_PACKET;
else if (data[len -
2 ] ==
0 xff && data[len -
1 ] ==
0 xd9)
pkt_type = LAST_PACKET;
else
pkt_type = INTER_PACKET;
gspca_frame_add(gspca_dev, pkt_type, data, len);
}
static int sd_g_volatile_ctrl(
struct v4l2_ctrl *ctrl)
{
struct gspca_dev *gspca_dev =
container_of(ctrl->handler,
struct gspca_dev, ctrl_handler);
struct sd *sd = (
struct sd *)gspca_dev;
s32 red_gain, blue_gain, green_gain;
gspca_dev->usb_err =
0 ;
switch (ctrl->id) {
case V4L2_CID_AUTO_WHITE_BALANCE:
red_gain = reg_r(gspca_dev,
0 x0087);
if (red_gain >
0 x40)
red_gain =
0 x40;
else if (red_gain <
0 x10)
red_gain =
0 x10;
blue_gain = reg_r(gspca_dev,
0 x0088);
if (blue_gain >
0 x40)
blue_gain =
0 x40;
else if (blue_gain <
0 x10)
blue_gain =
0 x10;
green_gain = reg_r(gspca_dev,
0 x0089);
if (green_gain >
0 x40)
green_gain =
0 x40;
else if (green_gain <
0 x10)
green_gain =
0 x10;
sd->gain->val = green_gain;
sd->red_balance->val = red_gain - green_gain;
sd->blue_balance->val = blue_gain - green_gain;
break ;
}
return 0 ;
}
static int sd_s_ctrl(
struct v4l2_ctrl *ctrl)
{
struct gspca_dev *gspca_dev =
container_of(ctrl->handler,
struct gspca_dev, ctrl_handler);
gspca_dev->usb_err =
0 ;
if (!gspca_dev->streaming)
return 0 ;
switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS:
setbrightness(gspca_dev, ctrl->val);
break ;
case V4L2_CID_CONTRAST:
setcontrast(gspca_dev, ctrl->val);
break ;
case V4L2_CID_SATURATION:
setcolors(gspca_dev, ctrl->val);
break ;
case V4L2_CID_GAMMA:
setgamma(gspca_dev, ctrl->val);
break ;
case V4L2_CID_HFLIP:
setmirror(gspca_dev, ctrl->val);
break ;
case V4L2_CID_SHARPNESS:
setsharpness(gspca_dev, ctrl->val);
break ;
case V4L2_CID_POWER_LINE_FREQUENCY:
setfreq(gspca_dev, ctrl->val);
break ;
case V4L2_CID_BACKLIGHT_COMPENSATION:
reg_w(gspca_dev, ctrl->val ?
0 xf48e :
0 xb48e);
break ;
case V4L2_CID_AUTO_WHITE_BALANCE:
setawb_n_RGB(gspca_dev);
break ;
case V4L2_CID_COLORFX:
seteffect(gspca_dev, ctrl->val);
break ;
}
return gspca_dev->usb_err;
}
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
.g_volatile_ctrl = sd_g_volatile_ctrl,
.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;
gspca_dev->vdev.ctrl_handler = hdl;
v4l2_ctrl_handler_init(hdl,
12 );
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BRIGHTNESS,
0 ,
14 ,
1 ,
8 );
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_CONTRAST,
0 ,
0 x0d,
1 ,
7 );
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SATURATION,
0 ,
0 xf,
1 ,
5 );
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_GAMMA,
0 , GAMMA_MAX,
1 ,
10 );
/* Activate lowlight, some apps don't bring up the
backlight_compensation control) */
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BACKLIGHT_COMPENSATION,
0 ,
1 ,
1 ,
1 );
if (sd->sensor == SENSOR_TAS5130A)
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_HFLIP,
0 ,
1 ,
1 ,
0 );
sd->awb = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_AUTO_WHITE_BALANCE,
0 ,
1 ,
1 ,
1 );
sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_GAIN,
0 x10,
0 x40,
1 ,
0 x20);
sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BLUE_BALANCE, -
0 x30,
0 x30,
1 ,
0 );
sd->red_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_RED_BALANCE, -
0 x30,
0 x30,
1 ,
0 );
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SHARPNESS,
0 ,
15 ,
1 ,
6 );
v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
V4L2_CID_COLORFX, V4L2_COLORFX_SKETCH,
~((
1 << V4L2_COLORFX_NONE) |
(
1 << V4L2_COLORFX_BW) |
(
1 << V4L2_COLORFX_SEPIA) |
(
1 << V4L2_COLORFX_SKETCH) |
(
1 << V4L2_COLORFX_NEGATIVE)),
V4L2_COLORFX_NONE);
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_50HZ);
if (hdl->error) {
pr_err(
"Could not initialize controls\n" );
return hdl->error;
}
v4l2_ctrl_auto_cluster(
4 , &sd->awb,
0 ,
true );
return 0 ;
}
/* sub-driver description */
static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
.config = sd_config,
.init = sd_init,
.init_controls = sd_init_controls,
.start = sd_start,
.stopN = sd_stopN,
.pkt_scan = sd_pkt_scan,
#if IS_ENABLED(CONFIG_INPUT)
.other_input =
1 ,
#endif
};
/* -- module initialisation -- */
static const struct usb_device_id device_table[] = {
{USB_DEVICE(
0 x17a1,
0 x0128)},
{}
};
MODULE_DEVICE_TABLE(usb, device_table);
/* -- device connect -- */
static int sd_probe(
struct usb_interface *intf,
const struct usb_device_id *id)
{
return gspca_dev_probe(intf, id, &sd_desc,
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,
.reset_resume = gspca_resume,
#endif
};
module_usb_driver(sd_driver);
Messung V0.5 in Prozent C=95 H=91 G=92
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-05)
¤
*© Formatika GbR, Deutschland