sonixb.c

来自「trident tm5600的linux驱动」· C语言 代码 · 共 1,309 行 · 第 1/3 页

C
1,309
字号
/* *		sonix sn9c102 (bayer) library *		Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr * Add Pas106 Stefano Mozzi (C) 2004 * * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> * * 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 *//* Some documentation on known sonixb registers:Reg	Use0x10	high nibble red gain low nibble blue gain0x11	low nibble green gain0x12	hstart0x13	vstart0x15	hsize (hsize = register-value * 16)0x16	vsize (vsize = register-value * 16)0x17	bit 0 toggle compression quality (according to sn9c102 driver)0x18	bit 7 enables compression, bit 4-5 set image down scaling:	00 scale 1, 01 scale 1/2, 10, scale 1/40x19	high-nibble is sensor clock divider, changes exposure on sensors which	use a clock generated by the bridge. Some sensors have their own clock.0x1c	auto_exposure area (for avg_lum) startx (startx = register-value * 32)0x1d	auto_exposure area (for avg_lum) starty (starty = register-value * 32)0x1e	auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32)0x1f	auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32)*/#define MODULE_NAME "sonixb"#include "gspca.h"MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");MODULE_LICENSE("GPL");/* specific webcam descriptor */struct sd {	struct gspca_dev gspca_dev;	/* !! must be the first item */	atomic_t avg_lum;	int prev_avg_lum;	unsigned char gain;	unsigned char exposure;	unsigned char brightness;	unsigned char autogain;	unsigned char autogain_ignore_frames;	unsigned char frames_to_drop;	unsigned char freq;		/* light freq filter setting */	__u8 bridge;			/* Type of bridge */#define BRIDGE_101 0#define BRIDGE_102 0 /* We make no difference between 101 and 102 */#define BRIDGE_103 1	__u8 sensor;			/* Type of image sensor chip */#define SENSOR_HV7131R 0#define SENSOR_OV6650 1#define SENSOR_OV7630 2#define SENSOR_PAS106 3#define SENSOR_PAS202 4#define SENSOR_TAS5110 5#define SENSOR_TAS5130CXX 6	__u8 reg11;};typedef const __u8 sensor_init_t[8];struct sensor_data {	const __u8 *bridge_init[2];	int bridge_init_size[2];	sensor_init_t *sensor_init;	int sensor_init_size;	sensor_init_t *sensor_bridge_init[2];	int sensor_bridge_init_size[2];	int flags;	unsigned ctrl_dis;	__u8 sensor_addr;};/* sensor_data flags */#define F_GAIN 0x01		/* has gain */#define F_SIF  0x02		/* sif or vga *//* priv field of struct v4l2_pix_format flags (do not use low nibble!) */#define MODE_RAW 0x10		/* raw bayer mode */#define MODE_REDUCED_SIF 0x20	/* vga mode (320x240 / 160x120) on sif cam *//* ctrl_dis helper macros */#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX))#define NO_FREQ (1 << FREQ_IDX)#define NO_BRIGHTNESS (1 << BRIGHTNESS_IDX)#define COMP2 0x8f#define COMP 0xc7		/* 0x87 //0x07 */#define COMP1 0xc9		/* 0x89 //0x09 */#define MCK_INIT 0x63#define MCK_INIT1 0x20		/*fixme: Bayer - 0x50 for JPEG ??*/#define SYS_CLK 0x04#define SENS(bridge_1, bridge_3, sensor, sensor_1, \	sensor_3, _flags, _ctrl_dis, _sensor_addr) \{ \	.bridge_init = { bridge_1, bridge_3 }, \	.bridge_init_size = { sizeof(bridge_1), sizeof(bridge_3) }, \	.sensor_init = sensor, \	.sensor_init_size = sizeof(sensor), \	.sensor_bridge_init = { sensor_1, sensor_3,}, \	.sensor_bridge_init_size = { sizeof(sensor_1), sizeof(sensor_3)}, \	.flags = _flags, .ctrl_dis = _ctrl_dis, .sensor_addr = _sensor_addr \}/* We calculate the autogain at the end of the transfer of a frame, at this   moment a frame with the old settings is being transmitted, and a frame is   being captured with the old settings. So if we adjust the autogain we must   ignore atleast the 2 next frames for the new settings to come into effect   before doing any other adjustments */#define AUTOGAIN_IGNORE_FRAMES 3#define AUTOGAIN_DEADZONE 1000#define DESIRED_AVG_LUM 7000/* V4L2 controls supported by the driver */static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);static struct ctrl sd_ctrls[] = {#define BRIGHTNESS_IDX 0	{	    {		.id      = V4L2_CID_BRIGHTNESS,		.type    = V4L2_CTRL_TYPE_INTEGER,		.name    = "Brightness",		.minimum = 0,		.maximum = 255,		.step    = 1,#define BRIGHTNESS_DEF 127		.default_value = BRIGHTNESS_DEF,	    },	    .set = sd_setbrightness,	    .get = sd_getbrightness,	},#define GAIN_IDX 1	{	    {		.id      = V4L2_CID_GAIN,		.type    = V4L2_CTRL_TYPE_INTEGER,		.name    = "Gain",		.minimum = 0,		.maximum = 255,		.step    = 1,#define GAIN_DEF 127#define GAIN_KNEE 200		.default_value = GAIN_DEF,	    },	    .set = sd_setgain,	    .get = sd_getgain,	},#define EXPOSURE_IDX 2	{		{			.id = V4L2_CID_EXPOSURE,			.type = V4L2_CTRL_TYPE_INTEGER,			.name = "Exposure",#define EXPOSURE_DEF  16 /*  32 ms / 30 fps */#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */			.minimum = 0,			.maximum = 255,			.step = 1,			.default_value = EXPOSURE_DEF,			.flags = 0,		},		.set = sd_setexposure,		.get = sd_getexposure,	},#define AUTOGAIN_IDX 3	{		{			.id = V4L2_CID_AUTOGAIN,			.type = V4L2_CTRL_TYPE_BOOLEAN,			.name = "Automatic Gain (and Exposure)",			.minimum = 0,			.maximum = 1,			.step = 1,#define AUTOGAIN_DEF 1			.default_value = AUTOGAIN_DEF,			.flags = 0,		},		.set = sd_setautogain,		.get = sd_getautogain,	},#define FREQ_IDX 4	{		{			.id	 = V4L2_CID_POWER_LINE_FREQUENCY,			.type    = V4L2_CTRL_TYPE_MENU,			.name    = "Light frequency filter",			.minimum = 0,			.maximum = 2,	/* 0: 0, 1: 50Hz, 2:60Hz */			.step    = 1,#define FREQ_DEF 1			.default_value = FREQ_DEF,		},		.set = sd_setfreq,		.get = sd_getfreq,	},};static struct v4l2_pix_format vga_mode[] = {	{160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,		.bytesperline = 160,		.sizeimage = 160 * 120,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 2 | MODE_RAW},	{160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 160,		.sizeimage = 160 * 120 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 2},	{320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 320,		.sizeimage = 320 * 240 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 1},	{640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 640,		.sizeimage = 640 * 480 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 0},};static struct v4l2_pix_format sif_mode[] = {	{160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,		.bytesperline = 160,		.sizeimage = 160 * 120,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 1 | MODE_RAW | MODE_REDUCED_SIF},	{160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 160,		.sizeimage = 160 * 120 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 1 | MODE_REDUCED_SIF},	{176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,		.bytesperline = 176,		.sizeimage = 176 * 144,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 1 | MODE_RAW},	{176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 176,		.sizeimage = 176 * 144 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 1},	{320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 320,		.sizeimage = 320 * 240 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 0 | MODE_REDUCED_SIF},	{352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,		.bytesperline = 352,		.sizeimage = 352 * 288 * 5 / 4,		.colorspace = V4L2_COLORSPACE_SRGB,		.priv = 0},};static const __u8 initHv7131[] = {	0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,	0x00, 0x00,	0x00, 0x00, 0x00, 0x02, 0x01, 0x00,	0x28, 0x1e, 0x60, 0x8a, 0x20,	0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c};static const __u8 hv7131_sensor_init[][8] = {	{0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},	{0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},	{0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},	{0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},	{0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},};static const __u8 initOv6650[] = {#if 1	0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,	0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b,	0x10, 0x1d, 0x10, 0x02, 0x02, 0x09, 0x07#else/* old version? */	0x64, 0x44, 0x28, 0x00, 0x00, 0x00, 0x00, 0x10,	0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	0x00, 0x01, 0x01, 0x0a, 0x14, 0x0f, 0x68, 0x8b,	0x10, 0x1d, 0x10, 0x01, 0x01, 0x07, 0x06#endif};static const __u8 ov6650_sensor_init[][8] ={	/* Bright, contrast, etc are set througth SCBB interface.	 * AVCAP on win2 do not send any data on this 	controls. */	/* Anyway, some registers appears to alter bright and constrat */	/* Reset sensor */	{0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},	/* Set clock register 0x11 low nibble is clock divider */	{0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},	/* Next some unknown stuff */	{0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},/*	{0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},		 * THIS SET GREEN SCREEN		 * (pixels could be innverted in decode kind of "brg",		 * but blue wont be there. Avoid this data ... */	{0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */	{0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},	{0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10},	/* Enable rgb brightness control */	{0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},	/* HDG: Note windows uses the line below, which sets both register 0x60	   and 0x61 I believe these registers of the ov6650 are identical as	   those of the ov7630, because if this is true the windows settings	   add a bit additional red gain and a lot additional blue gain, which	   matches my findings that the windows settings make blue much too	   blue and red a little too red.	{0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */	/* Some more unknown stuff */	{0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},	{0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */#if 0	/* HDG, don't change registers 0x2d, 0x32 & 0x33 from their reset	   defaults, doing so mucks up the framerate, where as the defaults	   seem to work good, the combinations below have been observed	   under windows and are kept for future reference */	{0xa0, 0x60, 0x2d, 0x0a, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x33, 0x40, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x2d, 0x2a, 0x99, 0x04, 0x94, 0x15},	{0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x33, 0x00, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16},	{0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16},		/* Low Light (Enabled: 0x32 0x1 | Disabled: 0x32 0x00) */	{0xa0, 0x60, 0x33, 0x29, 0x99, 0x04, 0x94, 0x16},		/* Low Ligth (Enabled: 0x33 0x13 | Disabled: 0x33 0x29) */#endif};static const __u8 initOv7630[] = {	0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,	/* r01 .. r08 */	0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* r09 .. r10 */	0x00, 0x01, 0x01, 0x0a,				/* r11 .. r14 */	0x28, 0x1e,			/* H & V sizes     r15 .. r16 */	0x68, COMP2, MCK_INIT1,				/* r17 .. r19 */#if 1	0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c		/* r1a .. r1f */#else /* jfm from win */	0x1d, 0x10, 0x06, 0x01, 0x00, 0x03		/* r1a .. r1f */#endif};static const __u8 initOv7630_3[] = {	0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80,	/* r01 .. r08 */	0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,	/* r09 .. r10 */	0x00, 0x02, 0x01, 0x0a,				/* r11 .. r14 */	0x28, 0x1e,			/* H & V sizes     r15 .. r16 */	0x68, 0x8f, MCK_INIT1,				/* r17 .. r19 */	0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c, 0x00,	/* r1a .. r20 */	0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */	0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff  /* r29 .. r30 */};static const __u8 ov7630_sensor_init[][8] = {	{0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},	{0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},/*	{0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10},	   jfm */	{0xd0, 0x21, 0x12, 0x1c, 0x00, 0x80, 0x34, 0x10},	/* jfm */	{0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},	{0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},	{0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},	{0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},	{0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},	{0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},	{0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},	{0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},/*	{0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10},	 * jfm */	{0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},	{0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},	{0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},	{0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},	{0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},	{0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},};static const __u8 ov7630_sensor_init_3[][8] = {	{0xa0, 0x21, 0x13, 0x80, 0x00,	0x00, 0x00, 0x10},};static const __u8 initPas106[] = {	0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,	0x00, 0x00,	0x00, 0x00, 0x00, 0x04, 0x01, 0x00,	0x16, 0x12, 0x24, COMP1, MCK_INIT1,	0x18, 0x10, 0x02, 0x02, 0x09, 0x07};/* compression 0x86 mckinit1 0x2b */static const __u8 pas106_sensor_init[][8] = {	/* Pixel Clock Divider 6 */	{ 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },	/* Frame Time MSB (also seen as 0x12) */	{ 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 },	/* Frame Time LSB (also seen as 0x05) */	{ 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 },	/* Shutter Time Line Offset (also seen as 0x6d) */	{ 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 },	/* Shutter Time Pixel Offset (also seen as 0xb1) */	{ 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 },	/* Black Level Subtract Sign (also seen 0x00) */	{ 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 },	/* Black Level Subtract Level (also seen 0x01) */	{ 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },	{ 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?