xref: /openbmc/linux/drivers/media/usb/gspca/sn9c20x.c (revision 312487ccfde9df5e39cd23d1c686b5cce8bab046)
10c0d06caSMauro Carvalho Chehab /*
20c0d06caSMauro Carvalho Chehab  *	Sonix sn9c201 sn9c202 library
30c0d06caSMauro Carvalho Chehab  *
40c0d06caSMauro Carvalho Chehab  * Copyright (C) 2012 Jean-Francois Moine <http://moinejf.free.fr>
50c0d06caSMauro Carvalho Chehab  *	Copyright (C) 2008-2009 microdia project <microdia@googlegroups.com>
60c0d06caSMauro Carvalho Chehab  *	Copyright (C) 2009 Brian Johnson <brijohn@gmail.com>
70c0d06caSMauro Carvalho Chehab  *
80c0d06caSMauro Carvalho Chehab  * This program is free software; you can redistribute it and/or modify
90c0d06caSMauro Carvalho Chehab  * it under the terms of the GNU General Public License as published by
100c0d06caSMauro Carvalho Chehab  * the Free Software Foundation; either version 2 of the License, or
110c0d06caSMauro Carvalho Chehab  * any later version.
120c0d06caSMauro Carvalho Chehab  *
130c0d06caSMauro Carvalho Chehab  * This program is distributed in the hope that it will be useful,
140c0d06caSMauro Carvalho Chehab  * but WITHOUT ANY WARRANTY; without even the implied warranty of
150c0d06caSMauro Carvalho Chehab  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160c0d06caSMauro Carvalho Chehab  * GNU General Public License for more details.
170c0d06caSMauro Carvalho Chehab  *
180c0d06caSMauro Carvalho Chehab  * You should have received a copy of the GNU General Public License
190c0d06caSMauro Carvalho Chehab  * along with this program; if not, write to the Free Software
200c0d06caSMauro Carvalho Chehab  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
210c0d06caSMauro Carvalho Chehab  */
220c0d06caSMauro Carvalho Chehab 
230c0d06caSMauro Carvalho Chehab #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
240c0d06caSMauro Carvalho Chehab 
250c0d06caSMauro Carvalho Chehab #include <linux/input.h>
260c0d06caSMauro Carvalho Chehab 
270c0d06caSMauro Carvalho Chehab #include "gspca.h"
280c0d06caSMauro Carvalho Chehab #include "jpeg.h"
290c0d06caSMauro Carvalho Chehab 
300c0d06caSMauro Carvalho Chehab #include <linux/dmi.h>
310c0d06caSMauro Carvalho Chehab 
320c0d06caSMauro Carvalho Chehab MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, "
330c0d06caSMauro Carvalho Chehab 		"microdia project <microdia@googlegroups.com>");
340c0d06caSMauro Carvalho Chehab MODULE_DESCRIPTION("GSPCA/SN9C20X USB Camera Driver");
350c0d06caSMauro Carvalho Chehab MODULE_LICENSE("GPL");
360c0d06caSMauro Carvalho Chehab 
370c0d06caSMauro Carvalho Chehab /*
380c0d06caSMauro Carvalho Chehab  * Pixel format private data
390c0d06caSMauro Carvalho Chehab  */
400c0d06caSMauro Carvalho Chehab #define SCALE_MASK	0x0f
410c0d06caSMauro Carvalho Chehab #define SCALE_160x120	0
420c0d06caSMauro Carvalho Chehab #define SCALE_320x240	1
430c0d06caSMauro Carvalho Chehab #define SCALE_640x480	2
440c0d06caSMauro Carvalho Chehab #define SCALE_1280x1024	3
450c0d06caSMauro Carvalho Chehab #define MODE_RAW	0x10
460c0d06caSMauro Carvalho Chehab #define MODE_JPEG	0x20
470c0d06caSMauro Carvalho Chehab #define MODE_SXGA	0x80
480c0d06caSMauro Carvalho Chehab 
490c0d06caSMauro Carvalho Chehab #define SENSOR_OV9650	0
500c0d06caSMauro Carvalho Chehab #define SENSOR_OV9655	1
510c0d06caSMauro Carvalho Chehab #define SENSOR_SOI968	2
520c0d06caSMauro Carvalho Chehab #define SENSOR_OV7660	3
530c0d06caSMauro Carvalho Chehab #define SENSOR_OV7670	4
540c0d06caSMauro Carvalho Chehab #define SENSOR_MT9V011	5
550c0d06caSMauro Carvalho Chehab #define SENSOR_MT9V111	6
560c0d06caSMauro Carvalho Chehab #define SENSOR_MT9V112	7
570c0d06caSMauro Carvalho Chehab #define SENSOR_MT9M001	8
580c0d06caSMauro Carvalho Chehab #define SENSOR_MT9M111	9
590c0d06caSMauro Carvalho Chehab #define SENSOR_MT9M112  10
600c0d06caSMauro Carvalho Chehab #define SENSOR_HV7131R	11
610c0d06caSMauro Carvalho Chehab #define SENSOR_MT9VPRB	12
620c0d06caSMauro Carvalho Chehab 
630c0d06caSMauro Carvalho Chehab /* camera flags */
640c0d06caSMauro Carvalho Chehab #define HAS_NO_BUTTON	0x1
650c0d06caSMauro Carvalho Chehab #define LED_REVERSE	0x2 /* some cameras unset gpio to turn on leds */
660c0d06caSMauro Carvalho Chehab #define FLIP_DETECT	0x4
670c0d06caSMauro Carvalho Chehab 
680c0d06caSMauro Carvalho Chehab /* specific webcam descriptor */
690c0d06caSMauro Carvalho Chehab struct sd {
700c0d06caSMauro Carvalho Chehab 	struct gspca_dev gspca_dev;
710c0d06caSMauro Carvalho Chehab 
720c0d06caSMauro Carvalho Chehab 	struct { /* color control cluster */
730c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *brightness;
740c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *contrast;
750c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *saturation;
760c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *hue;
770c0d06caSMauro Carvalho Chehab 	};
780c0d06caSMauro Carvalho Chehab 	struct { /* blue/red balance control cluster */
790c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *blue;
800c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *red;
810c0d06caSMauro Carvalho Chehab 	};
820c0d06caSMauro Carvalho Chehab 	struct { /* h/vflip control cluster */
830c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *hflip;
840c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *vflip;
850c0d06caSMauro Carvalho Chehab 	};
860c0d06caSMauro Carvalho Chehab 	struct v4l2_ctrl *gamma;
870c0d06caSMauro Carvalho Chehab 	struct { /* autogain and exposure or gain control cluster */
880c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *autogain;
890c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *exposure;
900c0d06caSMauro Carvalho Chehab 		struct v4l2_ctrl *gain;
910c0d06caSMauro Carvalho Chehab 	};
920c0d06caSMauro Carvalho Chehab 	struct v4l2_ctrl *jpegqual;
930c0d06caSMauro Carvalho Chehab 
940c0d06caSMauro Carvalho Chehab 	struct work_struct work;
950c0d06caSMauro Carvalho Chehab 	struct workqueue_struct *work_thread;
960c0d06caSMauro Carvalho Chehab 
970c0d06caSMauro Carvalho Chehab 	u32 pktsz;			/* (used by pkt_scan) */
980c0d06caSMauro Carvalho Chehab 	u16 npkt;
990c0d06caSMauro Carvalho Chehab 	s8 nchg;
1000c0d06caSMauro Carvalho Chehab 	u8 fmt;				/* (used for JPEG QTAB update */
1010c0d06caSMauro Carvalho Chehab 
1020c0d06caSMauro Carvalho Chehab #define MIN_AVG_LUM 80
1030c0d06caSMauro Carvalho Chehab #define MAX_AVG_LUM 130
1040c0d06caSMauro Carvalho Chehab 	atomic_t avg_lum;
1050c0d06caSMauro Carvalho Chehab 	u8 old_step;
1060c0d06caSMauro Carvalho Chehab 	u8 older_step;
1070c0d06caSMauro Carvalho Chehab 	u8 exposure_step;
1080c0d06caSMauro Carvalho Chehab 
1090c0d06caSMauro Carvalho Chehab 	u8 i2c_addr;
1100c0d06caSMauro Carvalho Chehab 	u8 i2c_intf;
1110c0d06caSMauro Carvalho Chehab 	u8 sensor;
1120c0d06caSMauro Carvalho Chehab 	u8 hstart;
1130c0d06caSMauro Carvalho Chehab 	u8 vstart;
1140c0d06caSMauro Carvalho Chehab 
1150c0d06caSMauro Carvalho Chehab 	u8 jpeg_hdr[JPEG_HDR_SZ];
1160c0d06caSMauro Carvalho Chehab 
1170c0d06caSMauro Carvalho Chehab 	u8 flags;
1180c0d06caSMauro Carvalho Chehab };
1190c0d06caSMauro Carvalho Chehab 
1200c0d06caSMauro Carvalho Chehab static void qual_upd(struct work_struct *work);
1210c0d06caSMauro Carvalho Chehab 
1220c0d06caSMauro Carvalho Chehab struct i2c_reg_u8 {
1230c0d06caSMauro Carvalho Chehab 	u8 reg;
1240c0d06caSMauro Carvalho Chehab 	u8 val;
1250c0d06caSMauro Carvalho Chehab };
1260c0d06caSMauro Carvalho Chehab 
1270c0d06caSMauro Carvalho Chehab struct i2c_reg_u16 {
1280c0d06caSMauro Carvalho Chehab 	u8 reg;
1290c0d06caSMauro Carvalho Chehab 	u16 val;
1300c0d06caSMauro Carvalho Chehab };
1310c0d06caSMauro Carvalho Chehab 
1320c0d06caSMauro Carvalho Chehab static const struct dmi_system_id flip_dmi_table[] = {
1330c0d06caSMauro Carvalho Chehab 	{
1340c0d06caSMauro Carvalho Chehab 		.ident = "MSI MS-1034",
1350c0d06caSMauro Carvalho Chehab 		.matches = {
1360c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD."),
1370c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_PRODUCT_NAME, "MS-1034"),
1380c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_PRODUCT_VERSION, "0341")
1390c0d06caSMauro Carvalho Chehab 		}
1400c0d06caSMauro Carvalho Chehab 	},
1410c0d06caSMauro Carvalho Chehab 	{
1420c0d06caSMauro Carvalho Chehab 		.ident = "MSI MS-1632",
1430c0d06caSMauro Carvalho Chehab 		.matches = {
1440c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
1450c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_NAME, "MS-1632")
1460c0d06caSMauro Carvalho Chehab 		}
1470c0d06caSMauro Carvalho Chehab 	},
1480c0d06caSMauro Carvalho Chehab 	{
1490c0d06caSMauro Carvalho Chehab 		.ident = "MSI MS-1633X",
1500c0d06caSMauro Carvalho Chehab 		.matches = {
1510c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
1520c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_NAME, "MS-1633X")
1530c0d06caSMauro Carvalho Chehab 		}
1540c0d06caSMauro Carvalho Chehab 	},
1550c0d06caSMauro Carvalho Chehab 	{
1560c0d06caSMauro Carvalho Chehab 		.ident = "MSI MS-1635X",
1570c0d06caSMauro Carvalho Chehab 		.matches = {
1580c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
1590c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_NAME, "MS-1635X")
1600c0d06caSMauro Carvalho Chehab 		}
1610c0d06caSMauro Carvalho Chehab 	},
1620c0d06caSMauro Carvalho Chehab 	{
1630c0d06caSMauro Carvalho Chehab 		.ident = "ASUSTeK W7J",
1640c0d06caSMauro Carvalho Chehab 		.matches = {
1650c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."),
1660c0d06caSMauro Carvalho Chehab 			DMI_MATCH(DMI_BOARD_NAME, "W7J       ")
1670c0d06caSMauro Carvalho Chehab 		}
1680c0d06caSMauro Carvalho Chehab 	},
1690c0d06caSMauro Carvalho Chehab 	{}
1700c0d06caSMauro Carvalho Chehab };
1710c0d06caSMauro Carvalho Chehab 
1720c0d06caSMauro Carvalho Chehab static const struct v4l2_pix_format vga_mode[] = {
1730c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
1740c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
1750c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120 * 4 / 8 + 590,
1760c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
1770c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120 | MODE_JPEG},
1780c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
1790c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
1800c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120,
1810c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
1820c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120 | MODE_RAW},
1830c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
1840c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
1850c0d06caSMauro Carvalho Chehab 		.sizeimage = 240 * 120,
1860c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
1870c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120},
1880c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
1890c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
1900c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 * 4 / 8 + 590,
1910c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
1920c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240 | MODE_JPEG},
1930c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
1940c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
1950c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 ,
1960c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
1970c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240 | MODE_RAW},
1980c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
1990c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
2000c0d06caSMauro Carvalho Chehab 		.sizeimage = 480 * 240 ,
2010c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2020c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240},
2030c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
2040c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2050c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480 * 4 / 8 + 590,
2060c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
2070c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480 | MODE_JPEG},
2080c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
2090c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2100c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480,
2110c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2120c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480 | MODE_RAW},
2130c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
2140c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2150c0d06caSMauro Carvalho Chehab 		.sizeimage = 960 * 480,
2160c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2170c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480},
2180c0d06caSMauro Carvalho Chehab };
2190c0d06caSMauro Carvalho Chehab 
2200c0d06caSMauro Carvalho Chehab static const struct v4l2_pix_format sxga_mode[] = {
2210c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
2220c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
2230c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120 * 4 / 8 + 590,
2240c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
2250c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120 | MODE_JPEG},
2260c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
2270c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
2280c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120,
2290c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2300c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120 | MODE_RAW},
2310c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
2320c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
2330c0d06caSMauro Carvalho Chehab 		.sizeimage = 240 * 120,
2340c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2350c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120},
2360c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
2370c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
2380c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 * 4 / 8 + 590,
2390c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
2400c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240 | MODE_JPEG},
2410c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
2420c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
2430c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 ,
2440c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2450c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240 | MODE_RAW},
2460c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
2470c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
2480c0d06caSMauro Carvalho Chehab 		.sizeimage = 480 * 240 ,
2490c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2500c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240},
2510c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
2520c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2530c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480 * 4 / 8 + 590,
2540c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_JPEG,
2550c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480 | MODE_JPEG},
2560c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
2570c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2580c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480,
2590c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2600c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480 | MODE_RAW},
2610c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
2620c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2630c0d06caSMauro Carvalho Chehab 		.sizeimage = 960 * 480,
2640c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2650c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480},
2660c0d06caSMauro Carvalho Chehab 	{1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
2670c0d06caSMauro Carvalho Chehab 		.bytesperline = 1280,
2680c0d06caSMauro Carvalho Chehab 		.sizeimage = 1280 * 1024,
2690c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2700c0d06caSMauro Carvalho Chehab 		.priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
2710c0d06caSMauro Carvalho Chehab };
2720c0d06caSMauro Carvalho Chehab 
2730c0d06caSMauro Carvalho Chehab static const struct v4l2_pix_format mono_mode[] = {
2740c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
2750c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
2760c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120,
2770c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2780c0d06caSMauro Carvalho Chehab 		.priv = SCALE_160x120 | MODE_RAW},
2790c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
2800c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
2810c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 ,
2820c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2830c0d06caSMauro Carvalho Chehab 		.priv = SCALE_320x240 | MODE_RAW},
2840c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
2850c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
2860c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480,
2870c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2880c0d06caSMauro Carvalho Chehab 		.priv = SCALE_640x480 | MODE_RAW},
2890c0d06caSMauro Carvalho Chehab 	{1280, 1024, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
2900c0d06caSMauro Carvalho Chehab 		.bytesperline = 1280,
2910c0d06caSMauro Carvalho Chehab 		.sizeimage = 1280 * 1024,
2920c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
2930c0d06caSMauro Carvalho Chehab 		.priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
2940c0d06caSMauro Carvalho Chehab };
2950c0d06caSMauro Carvalho Chehab 
2960c0d06caSMauro Carvalho Chehab static const s16 hsv_red_x[] = {
2970c0d06caSMauro Carvalho Chehab 	41,  44,  46,  48,  50,  52,  54,  56,
2980c0d06caSMauro Carvalho Chehab 	58,  60,  62,  64,  66,  68,  70,  72,
2990c0d06caSMauro Carvalho Chehab 	74,  76,  78,  80,  81,  83,  85,  87,
3000c0d06caSMauro Carvalho Chehab 	88,  90,  92,  93,  95,  97,  98, 100,
3010c0d06caSMauro Carvalho Chehab 	101, 102, 104, 105, 107, 108, 109, 110,
3020c0d06caSMauro Carvalho Chehab 	112, 113, 114, 115, 116, 117, 118, 119,
3030c0d06caSMauro Carvalho Chehab 	120, 121, 122, 123, 123, 124, 125, 125,
3040c0d06caSMauro Carvalho Chehab 	126, 127, 127, 128, 128, 129, 129, 129,
3050c0d06caSMauro Carvalho Chehab 	130, 130, 130, 130, 131, 131, 131, 131,
3060c0d06caSMauro Carvalho Chehab 	131, 131, 131, 131, 130, 130, 130, 130,
3070c0d06caSMauro Carvalho Chehab 	129, 129, 129, 128, 128, 127, 127, 126,
3080c0d06caSMauro Carvalho Chehab 	125, 125, 124, 123, 122, 122, 121, 120,
3090c0d06caSMauro Carvalho Chehab 	119, 118, 117, 116, 115, 114, 112, 111,
3100c0d06caSMauro Carvalho Chehab 	110, 109, 107, 106, 105, 103, 102, 101,
3110c0d06caSMauro Carvalho Chehab 	99,  98,  96,  94,  93,  91,  90,  88,
3120c0d06caSMauro Carvalho Chehab 	86,  84,  83,  81,  79,  77,  75,  74,
3130c0d06caSMauro Carvalho Chehab 	72,  70,  68,  66,  64,  62,  60,  58,
3140c0d06caSMauro Carvalho Chehab 	56,  54,  52,  49,  47,  45,  43,  41,
3150c0d06caSMauro Carvalho Chehab 	39,  36,  34,  32,  30,  28,  25,  23,
3160c0d06caSMauro Carvalho Chehab 	21,  19,  16,  14,  12,   9,   7,   5,
3170c0d06caSMauro Carvalho Chehab 	3,   0,  -1,  -3,  -6,  -8, -10, -12,
3180c0d06caSMauro Carvalho Chehab 	-15, -17, -19, -22, -24, -26, -28, -30,
3190c0d06caSMauro Carvalho Chehab 	-33, -35, -37, -39, -41, -44, -46, -48,
3200c0d06caSMauro Carvalho Chehab 	-50, -52, -54, -56, -58, -60, -62, -64,
3210c0d06caSMauro Carvalho Chehab 	-66, -68, -70, -72, -74, -76, -78, -80,
3220c0d06caSMauro Carvalho Chehab 	-81, -83, -85, -87, -88, -90, -92, -93,
3230c0d06caSMauro Carvalho Chehab 	-95, -97, -98, -100, -101, -102, -104, -105,
3240c0d06caSMauro Carvalho Chehab 	-107, -108, -109, -110, -112, -113, -114, -115,
3250c0d06caSMauro Carvalho Chehab 	-116, -117, -118, -119, -120, -121, -122, -123,
3260c0d06caSMauro Carvalho Chehab 	-123, -124, -125, -125, -126, -127, -127, -128,
3270c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3280c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3290c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3300c0d06caSMauro Carvalho Chehab 	-128, -127, -127, -126, -125, -125, -124, -123,
3310c0d06caSMauro Carvalho Chehab 	-122, -122, -121, -120, -119, -118, -117, -116,
3320c0d06caSMauro Carvalho Chehab 	-115, -114, -112, -111, -110, -109, -107, -106,
3330c0d06caSMauro Carvalho Chehab 	-105, -103, -102, -101, -99, -98, -96, -94,
3340c0d06caSMauro Carvalho Chehab 	-93, -91, -90, -88, -86, -84, -83, -81,
3350c0d06caSMauro Carvalho Chehab 	-79, -77, -75, -74, -72, -70, -68, -66,
3360c0d06caSMauro Carvalho Chehab 	-64, -62, -60, -58, -56, -54, -52, -49,
3370c0d06caSMauro Carvalho Chehab 	-47, -45, -43, -41, -39, -36, -34, -32,
3380c0d06caSMauro Carvalho Chehab 	-30, -28, -25, -23, -21, -19, -16, -14,
3390c0d06caSMauro Carvalho Chehab 	-12,  -9,  -7,  -5,  -3,   0,   1,   3,
3400c0d06caSMauro Carvalho Chehab 	6,   8,  10,  12,  15,  17,  19,  22,
3410c0d06caSMauro Carvalho Chehab 	24,  26,  28,  30,  33,  35,  37,  39, 41
3420c0d06caSMauro Carvalho Chehab };
3430c0d06caSMauro Carvalho Chehab 
3440c0d06caSMauro Carvalho Chehab static const s16 hsv_red_y[] = {
3450c0d06caSMauro Carvalho Chehab 	82,  80,  78,  76,  74,  73,  71,  69,
3460c0d06caSMauro Carvalho Chehab 	67,  65,  63,  61,  58,  56,  54,  52,
3470c0d06caSMauro Carvalho Chehab 	50,  48,  46,  44,  41,  39,  37,  35,
3480c0d06caSMauro Carvalho Chehab 	32,  30,  28,  26,  23,  21,  19,  16,
3490c0d06caSMauro Carvalho Chehab 	14,  12,  10,   7,   5,   3,   0,  -1,
3500c0d06caSMauro Carvalho Chehab 	-3,  -6,  -8, -10, -13, -15, -17, -19,
3510c0d06caSMauro Carvalho Chehab 	-22, -24, -26, -29, -31, -33, -35, -38,
3520c0d06caSMauro Carvalho Chehab 	-40, -42, -44, -46, -48, -51, -53, -55,
3530c0d06caSMauro Carvalho Chehab 	-57, -59, -61, -63, -65, -67, -69, -71,
3540c0d06caSMauro Carvalho Chehab 	-73, -75, -77, -79, -81, -82, -84, -86,
3550c0d06caSMauro Carvalho Chehab 	-88, -89, -91, -93, -94, -96, -98, -99,
3560c0d06caSMauro Carvalho Chehab 	-101, -102, -104, -105, -106, -108, -109, -110,
3570c0d06caSMauro Carvalho Chehab 	-112, -113, -114, -115, -116, -117, -119, -120,
3580c0d06caSMauro Carvalho Chehab 	-120, -121, -122, -123, -124, -125, -126, -126,
3590c0d06caSMauro Carvalho Chehab 	-127, -128, -128, -128, -128, -128, -128, -128,
3600c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3610c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3620c0d06caSMauro Carvalho Chehab 	-128, -128, -128, -128, -128, -128, -128, -128,
3630c0d06caSMauro Carvalho Chehab 	-127, -127, -126, -125, -125, -124, -123, -122,
3640c0d06caSMauro Carvalho Chehab 	-121, -120, -119, -118, -117, -116, -115, -114,
3650c0d06caSMauro Carvalho Chehab 	-113, -111, -110, -109, -107, -106, -105, -103,
3660c0d06caSMauro Carvalho Chehab 	-102, -100, -99, -97, -96, -94, -92, -91,
3670c0d06caSMauro Carvalho Chehab 	-89, -87, -85, -84, -82, -80, -78, -76,
3680c0d06caSMauro Carvalho Chehab 	-74, -73, -71, -69, -67, -65, -63, -61,
3690c0d06caSMauro Carvalho Chehab 	-58, -56, -54, -52, -50, -48, -46, -44,
3700c0d06caSMauro Carvalho Chehab 	-41, -39, -37, -35, -32, -30, -28, -26,
3710c0d06caSMauro Carvalho Chehab 	-23, -21, -19, -16, -14, -12, -10,  -7,
3720c0d06caSMauro Carvalho Chehab 	-5,  -3,   0,   1,   3,   6,   8,  10,
3730c0d06caSMauro Carvalho Chehab 	13,  15,  17,  19,  22,  24,  26,  29,
3740c0d06caSMauro Carvalho Chehab 	31,  33,  35,  38,  40,  42,  44,  46,
3750c0d06caSMauro Carvalho Chehab 	48,  51,  53,  55,  57,  59,  61,  63,
3760c0d06caSMauro Carvalho Chehab 	65,  67,  69,  71,  73,  75,  77,  79,
3770c0d06caSMauro Carvalho Chehab 	81,  82,  84,  86,  88,  89,  91,  93,
3780c0d06caSMauro Carvalho Chehab 	94,  96,  98,  99, 101, 102, 104, 105,
3790c0d06caSMauro Carvalho Chehab 	106, 108, 109, 110, 112, 113, 114, 115,
3800c0d06caSMauro Carvalho Chehab 	116, 117, 119, 120, 120, 121, 122, 123,
3810c0d06caSMauro Carvalho Chehab 	124, 125, 126, 126, 127, 128, 128, 129,
3820c0d06caSMauro Carvalho Chehab 	129, 130, 130, 131, 131, 131, 131, 132,
3830c0d06caSMauro Carvalho Chehab 	132, 132, 132, 132, 132, 132, 132, 132,
3840c0d06caSMauro Carvalho Chehab 	132, 132, 132, 131, 131, 131, 130, 130,
3850c0d06caSMauro Carvalho Chehab 	130, 129, 129, 128, 127, 127, 126, 125,
3860c0d06caSMauro Carvalho Chehab 	125, 124, 123, 122, 121, 120, 119, 118,
3870c0d06caSMauro Carvalho Chehab 	117, 116, 115, 114, 113, 111, 110, 109,
3880c0d06caSMauro Carvalho Chehab 	107, 106, 105, 103, 102, 100,  99,  97,
3890c0d06caSMauro Carvalho Chehab 	96, 94, 92, 91, 89, 87, 85, 84, 82
3900c0d06caSMauro Carvalho Chehab };
3910c0d06caSMauro Carvalho Chehab 
3920c0d06caSMauro Carvalho Chehab static const s16 hsv_green_x[] = {
3930c0d06caSMauro Carvalho Chehab 	-124, -124, -125, -125, -125, -125, -125, -125,
3940c0d06caSMauro Carvalho Chehab 	-125, -126, -126, -125, -125, -125, -125, -125,
3950c0d06caSMauro Carvalho Chehab 	-125, -124, -124, -124, -123, -123, -122, -122,
3960c0d06caSMauro Carvalho Chehab 	-121, -121, -120, -120, -119, -118, -117, -117,
3970c0d06caSMauro Carvalho Chehab 	-116, -115, -114, -113, -112, -111, -110, -109,
3980c0d06caSMauro Carvalho Chehab 	-108, -107, -105, -104, -103, -102, -100, -99,
3990c0d06caSMauro Carvalho Chehab 	-98, -96, -95, -93, -92, -91, -89, -87,
4000c0d06caSMauro Carvalho Chehab 	-86, -84, -83, -81, -79, -77, -76, -74,
4010c0d06caSMauro Carvalho Chehab 	-72, -70, -69, -67, -65, -63, -61, -59,
4020c0d06caSMauro Carvalho Chehab 	-57, -55, -53, -51, -49, -47, -45, -43,
4030c0d06caSMauro Carvalho Chehab 	-41, -39, -37, -35, -33, -30, -28, -26,
4040c0d06caSMauro Carvalho Chehab 	-24, -22, -20, -18, -15, -13, -11,  -9,
4050c0d06caSMauro Carvalho Chehab 	-7,  -4,  -2,   0,   1,   3,   6,   8,
4060c0d06caSMauro Carvalho Chehab 	10,  12,  14,  17,  19,  21,  23,  25,
4070c0d06caSMauro Carvalho Chehab 	27,  29,  32,  34,  36,  38,  40,  42,
4080c0d06caSMauro Carvalho Chehab 	44,  46,  48,  50,  52,  54,  56,  58,
4090c0d06caSMauro Carvalho Chehab 	60,  62,  64,  66,  68,  70,  71,  73,
4100c0d06caSMauro Carvalho Chehab 	75,  77,  78,  80,  82,  83,  85,  87,
4110c0d06caSMauro Carvalho Chehab 	88,  90,  91,  93,  94,  96,  97,  98,
4120c0d06caSMauro Carvalho Chehab 	100, 101, 102, 104, 105, 106, 107, 108,
4130c0d06caSMauro Carvalho Chehab 	109, 111, 112, 113, 113, 114, 115, 116,
4140c0d06caSMauro Carvalho Chehab 	117, 118, 118, 119, 120, 120, 121, 122,
4150c0d06caSMauro Carvalho Chehab 	122, 123, 123, 124, 124, 124, 125, 125,
4160c0d06caSMauro Carvalho Chehab 	125, 125, 125, 125, 125, 126, 126, 125,
4170c0d06caSMauro Carvalho Chehab 	125, 125, 125, 125, 125, 124, 124, 124,
4180c0d06caSMauro Carvalho Chehab 	123, 123, 122, 122, 121, 121, 120, 120,
4190c0d06caSMauro Carvalho Chehab 	119, 118, 117, 117, 116, 115, 114, 113,
4200c0d06caSMauro Carvalho Chehab 	112, 111, 110, 109, 108, 107, 105, 104,
4210c0d06caSMauro Carvalho Chehab 	103, 102, 100,  99,  98,  96,  95,  93,
4220c0d06caSMauro Carvalho Chehab 	92,  91,  89,  87,  86,  84,  83,  81,
4230c0d06caSMauro Carvalho Chehab 	79,  77,  76,  74,  72,  70,  69,  67,
4240c0d06caSMauro Carvalho Chehab 	65,  63,  61,  59,  57,  55,  53,  51,
4250c0d06caSMauro Carvalho Chehab 	49,  47,  45,  43,  41,  39,  37,  35,
4260c0d06caSMauro Carvalho Chehab 	33,  30,  28,  26,  24,  22,  20,  18,
4270c0d06caSMauro Carvalho Chehab 	15,  13,  11,   9,   7,   4,   2,   0,
4280c0d06caSMauro Carvalho Chehab 	-1,  -3,  -6,  -8, -10, -12, -14, -17,
4290c0d06caSMauro Carvalho Chehab 	-19, -21, -23, -25, -27, -29, -32, -34,
4300c0d06caSMauro Carvalho Chehab 	-36, -38, -40, -42, -44, -46, -48, -50,
4310c0d06caSMauro Carvalho Chehab 	-52, -54, -56, -58, -60, -62, -64, -66,
4320c0d06caSMauro Carvalho Chehab 	-68, -70, -71, -73, -75, -77, -78, -80,
4330c0d06caSMauro Carvalho Chehab 	-82, -83, -85, -87, -88, -90, -91, -93,
4340c0d06caSMauro Carvalho Chehab 	-94, -96, -97, -98, -100, -101, -102, -104,
4350c0d06caSMauro Carvalho Chehab 	-105, -106, -107, -108, -109, -111, -112, -113,
4360c0d06caSMauro Carvalho Chehab 	-113, -114, -115, -116, -117, -118, -118, -119,
4370c0d06caSMauro Carvalho Chehab 	-120, -120, -121, -122, -122, -123, -123, -124, -124
4380c0d06caSMauro Carvalho Chehab };
4390c0d06caSMauro Carvalho Chehab 
4400c0d06caSMauro Carvalho Chehab static const s16 hsv_green_y[] = {
4410c0d06caSMauro Carvalho Chehab 	-100, -99, -98, -97, -95, -94, -93, -91,
4420c0d06caSMauro Carvalho Chehab 	-90, -89, -87, -86, -84, -83, -81, -80,
4430c0d06caSMauro Carvalho Chehab 	-78, -76, -75, -73, -71, -70, -68, -66,
4440c0d06caSMauro Carvalho Chehab 	-64, -63, -61, -59, -57, -55, -53, -51,
4450c0d06caSMauro Carvalho Chehab 	-49, -48, -46, -44, -42, -40, -38, -36,
4460c0d06caSMauro Carvalho Chehab 	-34, -32, -30, -27, -25, -23, -21, -19,
4470c0d06caSMauro Carvalho Chehab 	-17, -15, -13, -11,  -9,  -7,  -4,  -2,
4480c0d06caSMauro Carvalho Chehab 	0,   1,   3,   5,   7,   9,  11,  14,
4490c0d06caSMauro Carvalho Chehab 	16,  18,  20,  22,  24,  26,  28,  30,
4500c0d06caSMauro Carvalho Chehab 	32,  34,  36,  38,  40,  42,  44,  46,
4510c0d06caSMauro Carvalho Chehab 	48,  50,  52,  54,  56,  58,  59,  61,
4520c0d06caSMauro Carvalho Chehab 	63,  65,  67,  68,  70,  72,  74,  75,
4530c0d06caSMauro Carvalho Chehab 	77,  78,  80,  82,  83,  85,  86,  88,
4540c0d06caSMauro Carvalho Chehab 	89,  90,  92,  93,  95,  96,  97,  98,
4550c0d06caSMauro Carvalho Chehab 	100, 101, 102, 103, 104, 105, 106, 107,
4560c0d06caSMauro Carvalho Chehab 	108, 109, 110, 111, 112, 112, 113, 114,
4570c0d06caSMauro Carvalho Chehab 	115, 115, 116, 116, 117, 117, 118, 118,
4580c0d06caSMauro Carvalho Chehab 	119, 119, 119, 120, 120, 120, 120, 120,
4590c0d06caSMauro Carvalho Chehab 	121, 121, 121, 121, 121, 121, 120, 120,
4600c0d06caSMauro Carvalho Chehab 	120, 120, 120, 119, 119, 119, 118, 118,
4610c0d06caSMauro Carvalho Chehab 	117, 117, 116, 116, 115, 114, 114, 113,
4620c0d06caSMauro Carvalho Chehab 	112, 111, 111, 110, 109, 108, 107, 106,
4630c0d06caSMauro Carvalho Chehab 	105, 104, 103, 102, 100,  99,  98,  97,
4640c0d06caSMauro Carvalho Chehab 	95,  94,  93,  91,  90,  89,  87,  86,
4650c0d06caSMauro Carvalho Chehab 	84,  83,  81,  80,  78,  76,  75,  73,
4660c0d06caSMauro Carvalho Chehab 	71,  70,  68,  66,  64,  63,  61,  59,
4670c0d06caSMauro Carvalho Chehab 	57,  55,  53,  51,  49,  48,  46,  44,
4680c0d06caSMauro Carvalho Chehab 	42,  40,  38,  36,  34,  32,  30,  27,
4690c0d06caSMauro Carvalho Chehab 	25,  23,  21,  19,  17,  15,  13,  11,
4700c0d06caSMauro Carvalho Chehab 	9,   7,   4,   2,   0,  -1,  -3,  -5,
4710c0d06caSMauro Carvalho Chehab 	-7,  -9, -11, -14, -16, -18, -20, -22,
4720c0d06caSMauro Carvalho Chehab 	-24, -26, -28, -30, -32, -34, -36, -38,
4730c0d06caSMauro Carvalho Chehab 	-40, -42, -44, -46, -48, -50, -52, -54,
4740c0d06caSMauro Carvalho Chehab 	-56, -58, -59, -61, -63, -65, -67, -68,
4750c0d06caSMauro Carvalho Chehab 	-70, -72, -74, -75, -77, -78, -80, -82,
4760c0d06caSMauro Carvalho Chehab 	-83, -85, -86, -88, -89, -90, -92, -93,
4770c0d06caSMauro Carvalho Chehab 	-95, -96, -97, -98, -100, -101, -102, -103,
4780c0d06caSMauro Carvalho Chehab 	-104, -105, -106, -107, -108, -109, -110, -111,
4790c0d06caSMauro Carvalho Chehab 	-112, -112, -113, -114, -115, -115, -116, -116,
4800c0d06caSMauro Carvalho Chehab 	-117, -117, -118, -118, -119, -119, -119, -120,
4810c0d06caSMauro Carvalho Chehab 	-120, -120, -120, -120, -121, -121, -121, -121,
4820c0d06caSMauro Carvalho Chehab 	-121, -121, -120, -120, -120, -120, -120, -119,
4830c0d06caSMauro Carvalho Chehab 	-119, -119, -118, -118, -117, -117, -116, -116,
4840c0d06caSMauro Carvalho Chehab 	-115, -114, -114, -113, -112, -111, -111, -110,
4850c0d06caSMauro Carvalho Chehab 	-109, -108, -107, -106, -105, -104, -103, -102, -100
4860c0d06caSMauro Carvalho Chehab };
4870c0d06caSMauro Carvalho Chehab 
4880c0d06caSMauro Carvalho Chehab static const s16 hsv_blue_x[] = {
4890c0d06caSMauro Carvalho Chehab 	112, 113, 114, 114, 115, 116, 117, 117,
4900c0d06caSMauro Carvalho Chehab 	118, 118, 119, 119, 120, 120, 120, 121,
4910c0d06caSMauro Carvalho Chehab 	121, 121, 122, 122, 122, 122, 122, 122,
4920c0d06caSMauro Carvalho Chehab 	122, 122, 122, 122, 122, 122, 121, 121,
4930c0d06caSMauro Carvalho Chehab 	121, 120, 120, 120, 119, 119, 118, 118,
4940c0d06caSMauro Carvalho Chehab 	117, 116, 116, 115, 114, 113, 113, 112,
4950c0d06caSMauro Carvalho Chehab 	111, 110, 109, 108, 107, 106, 105, 104,
4960c0d06caSMauro Carvalho Chehab 	103, 102, 100,  99,  98,  97,  95,  94,
4970c0d06caSMauro Carvalho Chehab 	93,  91,  90,  88,  87,  85,  84,  82,
4980c0d06caSMauro Carvalho Chehab 	80,  79,  77,  76,  74,  72,  70,  69,
4990c0d06caSMauro Carvalho Chehab 	67,  65,  63,  61,  60,  58,  56,  54,
5000c0d06caSMauro Carvalho Chehab 	52,  50,  48,  46,  44,  42,  40,  38,
5010c0d06caSMauro Carvalho Chehab 	36,  34,  32,  30,  28,  26,  24,  22,
5020c0d06caSMauro Carvalho Chehab 	19,  17,  15,  13,  11,   9,   7,   5,
5030c0d06caSMauro Carvalho Chehab 	2,   0,  -1,  -3,  -5,  -7,  -9, -12,
5040c0d06caSMauro Carvalho Chehab 	-14, -16, -18, -20, -22, -24, -26, -28,
5050c0d06caSMauro Carvalho Chehab 	-31, -33, -35, -37, -39, -41, -43, -45,
5060c0d06caSMauro Carvalho Chehab 	-47, -49, -51, -53, -54, -56, -58, -60,
5070c0d06caSMauro Carvalho Chehab 	-62, -64, -66, -67, -69, -71, -73, -74,
5080c0d06caSMauro Carvalho Chehab 	-76, -78, -79, -81, -83, -84, -86, -87,
5090c0d06caSMauro Carvalho Chehab 	-89, -90, -92, -93, -94, -96, -97, -98,
5100c0d06caSMauro Carvalho Chehab 	-99, -101, -102, -103, -104, -105, -106, -107,
5110c0d06caSMauro Carvalho Chehab 	-108, -109, -110, -111, -112, -113, -114, -114,
5120c0d06caSMauro Carvalho Chehab 	-115, -116, -117, -117, -118, -118, -119, -119,
5130c0d06caSMauro Carvalho Chehab 	-120, -120, -120, -121, -121, -121, -122, -122,
5140c0d06caSMauro Carvalho Chehab 	-122, -122, -122, -122, -122, -122, -122, -122,
5150c0d06caSMauro Carvalho Chehab 	-122, -122, -121, -121, -121, -120, -120, -120,
5160c0d06caSMauro Carvalho Chehab 	-119, -119, -118, -118, -117, -116, -116, -115,
5170c0d06caSMauro Carvalho Chehab 	-114, -113, -113, -112, -111, -110, -109, -108,
5180c0d06caSMauro Carvalho Chehab 	-107, -106, -105, -104, -103, -102, -100, -99,
5190c0d06caSMauro Carvalho Chehab 	-98, -97, -95, -94, -93, -91, -90, -88,
5200c0d06caSMauro Carvalho Chehab 	-87, -85, -84, -82, -80, -79, -77, -76,
5210c0d06caSMauro Carvalho Chehab 	-74, -72, -70, -69, -67, -65, -63, -61,
5220c0d06caSMauro Carvalho Chehab 	-60, -58, -56, -54, -52, -50, -48, -46,
5230c0d06caSMauro Carvalho Chehab 	-44, -42, -40, -38, -36, -34, -32, -30,
5240c0d06caSMauro Carvalho Chehab 	-28, -26, -24, -22, -19, -17, -15, -13,
5250c0d06caSMauro Carvalho Chehab 	-11,  -9,  -7,  -5,  -2,   0,   1,   3,
5260c0d06caSMauro Carvalho Chehab 	5,   7,   9,  12,  14,  16,  18,  20,
5270c0d06caSMauro Carvalho Chehab 	22,  24,  26,  28,  31,  33,  35,  37,
5280c0d06caSMauro Carvalho Chehab 	39,  41,  43,  45,  47,  49,  51,  53,
5290c0d06caSMauro Carvalho Chehab 	54,  56,  58,  60,  62,  64,  66,  67,
5300c0d06caSMauro Carvalho Chehab 	69,  71,  73,  74,  76,  78,  79,  81,
5310c0d06caSMauro Carvalho Chehab 	83,  84,  86,  87,  89,  90,  92,  93,
5320c0d06caSMauro Carvalho Chehab 	94,  96,  97,  98,  99, 101, 102, 103,
5330c0d06caSMauro Carvalho Chehab 	104, 105, 106, 107, 108, 109, 110, 111, 112
5340c0d06caSMauro Carvalho Chehab };
5350c0d06caSMauro Carvalho Chehab 
5360c0d06caSMauro Carvalho Chehab static const s16 hsv_blue_y[] = {
5370c0d06caSMauro Carvalho Chehab 	-11, -13, -15, -17, -19, -21, -23, -25,
5380c0d06caSMauro Carvalho Chehab 	-27, -29, -31, -33, -35, -37, -39, -41,
5390c0d06caSMauro Carvalho Chehab 	-43, -45, -46, -48, -50, -52, -54, -55,
5400c0d06caSMauro Carvalho Chehab 	-57, -59, -61, -62, -64, -66, -67, -69,
5410c0d06caSMauro Carvalho Chehab 	-71, -72, -74, -75, -77, -78, -80, -81,
5420c0d06caSMauro Carvalho Chehab 	-83, -84, -86, -87, -88, -90, -91, -92,
5430c0d06caSMauro Carvalho Chehab 	-93, -95, -96, -97, -98, -99, -100, -101,
5440c0d06caSMauro Carvalho Chehab 	-102, -103, -104, -105, -106, -106, -107, -108,
5450c0d06caSMauro Carvalho Chehab 	-109, -109, -110, -111, -111, -112, -112, -113,
5460c0d06caSMauro Carvalho Chehab 	-113, -114, -114, -114, -115, -115, -115, -115,
5470c0d06caSMauro Carvalho Chehab 	-116, -116, -116, -116, -116, -116, -116, -116,
5480c0d06caSMauro Carvalho Chehab 	-116, -115, -115, -115, -115, -114, -114, -114,
5490c0d06caSMauro Carvalho Chehab 	-113, -113, -112, -112, -111, -111, -110, -110,
5500c0d06caSMauro Carvalho Chehab 	-109, -108, -108, -107, -106, -105, -104, -103,
5510c0d06caSMauro Carvalho Chehab 	-102, -101, -100, -99, -98, -97, -96, -95,
5520c0d06caSMauro Carvalho Chehab 	-94, -93, -91, -90, -89, -88, -86, -85,
5530c0d06caSMauro Carvalho Chehab 	-84, -82, -81, -79, -78, -76, -75, -73,
5540c0d06caSMauro Carvalho Chehab 	-71, -70, -68, -67, -65, -63, -62, -60,
5550c0d06caSMauro Carvalho Chehab 	-58, -56, -55, -53, -51, -49, -47, -45,
5560c0d06caSMauro Carvalho Chehab 	-44, -42, -40, -38, -36, -34, -32, -30,
5570c0d06caSMauro Carvalho Chehab 	-28, -26, -24, -22, -20, -18, -16, -14,
5580c0d06caSMauro Carvalho Chehab 	-12, -10,  -8,  -6,  -4,  -2,   0,   1,
5590c0d06caSMauro Carvalho Chehab 	3,   5,   7,   9,  11,  13,  15,  17,
5600c0d06caSMauro Carvalho Chehab 	19,  21,  23,  25,  27,  29,  31,  33,
5610c0d06caSMauro Carvalho Chehab 	35,  37,  39,  41,  43,  45,  46,  48,
5620c0d06caSMauro Carvalho Chehab 	50,  52,  54,  55,  57,  59,  61,  62,
5630c0d06caSMauro Carvalho Chehab 	64,  66,  67,  69,  71,  72,  74,  75,
5640c0d06caSMauro Carvalho Chehab 	77,  78,  80,  81,  83,  84,  86,  87,
5650c0d06caSMauro Carvalho Chehab 	88,  90,  91,  92,  93,  95,  96,  97,
5660c0d06caSMauro Carvalho Chehab 	98,  99, 100, 101, 102, 103, 104, 105,
5670c0d06caSMauro Carvalho Chehab 	106, 106, 107, 108, 109, 109, 110, 111,
5680c0d06caSMauro Carvalho Chehab 	111, 112, 112, 113, 113, 114, 114, 114,
5690c0d06caSMauro Carvalho Chehab 	115, 115, 115, 115, 116, 116, 116, 116,
5700c0d06caSMauro Carvalho Chehab 	116, 116, 116, 116, 116, 115, 115, 115,
5710c0d06caSMauro Carvalho Chehab 	115, 114, 114, 114, 113, 113, 112, 112,
5720c0d06caSMauro Carvalho Chehab 	111, 111, 110, 110, 109, 108, 108, 107,
5730c0d06caSMauro Carvalho Chehab 	106, 105, 104, 103, 102, 101, 100,  99,
5740c0d06caSMauro Carvalho Chehab 	98,  97,  96,  95,  94,  93,  91,  90,
5750c0d06caSMauro Carvalho Chehab 	89,  88,  86,  85,  84,  82,  81,  79,
5760c0d06caSMauro Carvalho Chehab 	78,  76,  75,  73,  71,  70,  68,  67,
5770c0d06caSMauro Carvalho Chehab 	65,  63,  62,  60,  58,  56,  55,  53,
5780c0d06caSMauro Carvalho Chehab 	51,  49,  47,  45,  44,  42,  40,  38,
5790c0d06caSMauro Carvalho Chehab 	36,  34,  32,  30,  28,  26,  24,  22,
5800c0d06caSMauro Carvalho Chehab 	20,  18,  16,  14,  12,  10,   8,   6,
5810c0d06caSMauro Carvalho Chehab 	4,   2,   0,  -1,  -3,  -5,  -7,  -9, -11
5820c0d06caSMauro Carvalho Chehab };
5830c0d06caSMauro Carvalho Chehab 
5840c0d06caSMauro Carvalho Chehab static const u16 bridge_init[][2] = {
5850c0d06caSMauro Carvalho Chehab 	{0x1000, 0x78}, {0x1001, 0x40}, {0x1002, 0x1c},
5860c0d06caSMauro Carvalho Chehab 	{0x1020, 0x80}, {0x1061, 0x01}, {0x1067, 0x40},
5870c0d06caSMauro Carvalho Chehab 	{0x1068, 0x30}, {0x1069, 0x20},	{0x106a, 0x10},
5880c0d06caSMauro Carvalho Chehab 	{0x106b, 0x08},	{0x1188, 0x87},	{0x11a1, 0x00},
5890c0d06caSMauro Carvalho Chehab 	{0x11a2, 0x00},	{0x11a3, 0x6a},	{0x11a4, 0x50},
5900c0d06caSMauro Carvalho Chehab 	{0x11ab, 0x00},	{0x11ac, 0x00},	{0x11ad, 0x50},
5910c0d06caSMauro Carvalho Chehab 	{0x11ae, 0x3c},	{0x118a, 0x04},	{0x0395, 0x04},
5920c0d06caSMauro Carvalho Chehab 	{0x11b8, 0x3a},	{0x118b, 0x0e},	{0x10f7, 0x05},
5930c0d06caSMauro Carvalho Chehab 	{0x10f8, 0x14},	{0x10fa, 0xff},	{0x10f9, 0x00},
5940c0d06caSMauro Carvalho Chehab 	{0x11ba, 0x0a},	{0x11a5, 0x2d},	{0x11a6, 0x2d},
5950c0d06caSMauro Carvalho Chehab 	{0x11a7, 0x3a},	{0x11a8, 0x05},	{0x11a9, 0x04},
5960c0d06caSMauro Carvalho Chehab 	{0x11aa, 0x3f},	{0x11af, 0x28},	{0x11b0, 0xd8},
5970c0d06caSMauro Carvalho Chehab 	{0x11b1, 0x14},	{0x11b2, 0xec},	{0x11b3, 0x32},
5980c0d06caSMauro Carvalho Chehab 	{0x11b4, 0xdd},	{0x11b5, 0x32},	{0x11b6, 0xdd},
5990c0d06caSMauro Carvalho Chehab 	{0x10e0, 0x2c},	{0x11bc, 0x40},	{0x11bd, 0x01},
6000c0d06caSMauro Carvalho Chehab 	{0x11be, 0xf0},	{0x11bf, 0x00},	{0x118c, 0x1f},
6010c0d06caSMauro Carvalho Chehab 	{0x118d, 0x1f},	{0x118e, 0x1f},	{0x118f, 0x1f},
6020c0d06caSMauro Carvalho Chehab 	{0x1180, 0x01},	{0x1181, 0x00},	{0x1182, 0x01},
6030c0d06caSMauro Carvalho Chehab 	{0x1183, 0x00},	{0x1184, 0x50},	{0x1185, 0x80},
6040c0d06caSMauro Carvalho Chehab 	{0x1007, 0x00}
6050c0d06caSMauro Carvalho Chehab };
6060c0d06caSMauro Carvalho Chehab 
6070c0d06caSMauro Carvalho Chehab /* Gain = (bit[3:0] / 16 + 1) * (bit[4] + 1) * (bit[5] + 1) * (bit[6] + 1) */
6080c0d06caSMauro Carvalho Chehab static const u8 ov_gain[] = {
6090c0d06caSMauro Carvalho Chehab 	0x00 /* 1x */, 0x04 /* 1.25x */, 0x08 /* 1.5x */, 0x0c /* 1.75x */,
6100c0d06caSMauro Carvalho Chehab 	0x10 /* 2x */, 0x12 /* 2.25x */, 0x14 /* 2.5x */, 0x16 /* 2.75x */,
6110c0d06caSMauro Carvalho Chehab 	0x18 /* 3x */, 0x1a /* 3.25x */, 0x1c /* 3.5x */, 0x1e /* 3.75x */,
6120c0d06caSMauro Carvalho Chehab 	0x30 /* 4x */, 0x31 /* 4.25x */, 0x32 /* 4.5x */, 0x33 /* 4.75x */,
6130c0d06caSMauro Carvalho Chehab 	0x34 /* 5x */, 0x35 /* 5.25x */, 0x36 /* 5.5x */, 0x37 /* 5.75x */,
6140c0d06caSMauro Carvalho Chehab 	0x38 /* 6x */, 0x39 /* 6.25x */, 0x3a /* 6.5x */, 0x3b /* 6.75x */,
6150c0d06caSMauro Carvalho Chehab 	0x3c /* 7x */, 0x3d /* 7.25x */, 0x3e /* 7.5x */, 0x3f /* 7.75x */,
6160c0d06caSMauro Carvalho Chehab 	0x70 /* 8x */
6170c0d06caSMauro Carvalho Chehab };
6180c0d06caSMauro Carvalho Chehab 
6190c0d06caSMauro Carvalho Chehab /* Gain = (bit[8] + 1) * (bit[7] + 1) * (bit[6:0] * 0.03125) */
6200c0d06caSMauro Carvalho Chehab static const u16 micron1_gain[] = {
6210c0d06caSMauro Carvalho Chehab 	/* 1x   1.25x   1.5x    1.75x */
6220c0d06caSMauro Carvalho Chehab 	0x0020, 0x0028, 0x0030, 0x0038,
6230c0d06caSMauro Carvalho Chehab 	/* 2x   2.25x   2.5x    2.75x */
6240c0d06caSMauro Carvalho Chehab 	0x00a0, 0x00a4, 0x00a8, 0x00ac,
6250c0d06caSMauro Carvalho Chehab 	/* 3x   3.25x   3.5x    3.75x */
6260c0d06caSMauro Carvalho Chehab 	0x00b0, 0x00b4, 0x00b8, 0x00bc,
6270c0d06caSMauro Carvalho Chehab 	/* 4x   4.25x   4.5x    4.75x */
6280c0d06caSMauro Carvalho Chehab 	0x00c0, 0x00c4, 0x00c8, 0x00cc,
6290c0d06caSMauro Carvalho Chehab 	/* 5x   5.25x   5.5x    5.75x */
6300c0d06caSMauro Carvalho Chehab 	0x00d0, 0x00d4, 0x00d8, 0x00dc,
6310c0d06caSMauro Carvalho Chehab 	/* 6x   6.25x   6.5x    6.75x */
6320c0d06caSMauro Carvalho Chehab 	0x00e0, 0x00e4, 0x00e8, 0x00ec,
6330c0d06caSMauro Carvalho Chehab 	/* 7x   7.25x   7.5x    7.75x */
6340c0d06caSMauro Carvalho Chehab 	0x00f0, 0x00f4, 0x00f8, 0x00fc,
6350c0d06caSMauro Carvalho Chehab 	/* 8x */
6360c0d06caSMauro Carvalho Chehab 	0x01c0
6370c0d06caSMauro Carvalho Chehab };
6380c0d06caSMauro Carvalho Chehab 
6390c0d06caSMauro Carvalho Chehab /* mt9m001 sensor uses a different gain formula then other micron sensors */
6400c0d06caSMauro Carvalho Chehab /* Gain = (bit[6] + 1) * (bit[5-0] * 0.125) */
6410c0d06caSMauro Carvalho Chehab static const u16 micron2_gain[] = {
6420c0d06caSMauro Carvalho Chehab 	/* 1x   1.25x   1.5x    1.75x */
6430c0d06caSMauro Carvalho Chehab 	0x0008, 0x000a, 0x000c, 0x000e,
6440c0d06caSMauro Carvalho Chehab 	/* 2x   2.25x   2.5x    2.75x */
6450c0d06caSMauro Carvalho Chehab 	0x0010, 0x0012, 0x0014, 0x0016,
6460c0d06caSMauro Carvalho Chehab 	/* 3x   3.25x   3.5x    3.75x */
6470c0d06caSMauro Carvalho Chehab 	0x0018, 0x001a, 0x001c, 0x001e,
6480c0d06caSMauro Carvalho Chehab 	/* 4x   4.25x   4.5x    4.75x */
6490c0d06caSMauro Carvalho Chehab 	0x0020, 0x0051, 0x0052, 0x0053,
6500c0d06caSMauro Carvalho Chehab 	/* 5x   5.25x   5.5x    5.75x */
6510c0d06caSMauro Carvalho Chehab 	0x0054, 0x0055, 0x0056, 0x0057,
6520c0d06caSMauro Carvalho Chehab 	/* 6x   6.25x   6.5x    6.75x */
6530c0d06caSMauro Carvalho Chehab 	0x0058, 0x0059, 0x005a, 0x005b,
6540c0d06caSMauro Carvalho Chehab 	/* 7x   7.25x   7.5x    7.75x */
6550c0d06caSMauro Carvalho Chehab 	0x005c, 0x005d, 0x005e, 0x005f,
6560c0d06caSMauro Carvalho Chehab 	/* 8x */
6570c0d06caSMauro Carvalho Chehab 	0x0060
6580c0d06caSMauro Carvalho Chehab };
6590c0d06caSMauro Carvalho Chehab 
6600c0d06caSMauro Carvalho Chehab /* Gain = .5 + bit[7:0] / 16 */
6610c0d06caSMauro Carvalho Chehab static const u8 hv7131r_gain[] = {
6620c0d06caSMauro Carvalho Chehab 	0x08 /* 1x */, 0x0c /* 1.25x */, 0x10 /* 1.5x */, 0x14 /* 1.75x */,
6630c0d06caSMauro Carvalho Chehab 	0x18 /* 2x */, 0x1c /* 2.25x */, 0x20 /* 2.5x */, 0x24 /* 2.75x */,
6640c0d06caSMauro Carvalho Chehab 	0x28 /* 3x */, 0x2c /* 3.25x */, 0x30 /* 3.5x */, 0x34 /* 3.75x */,
6650c0d06caSMauro Carvalho Chehab 	0x38 /* 4x */, 0x3c /* 4.25x */, 0x40 /* 4.5x */, 0x44 /* 4.75x */,
6660c0d06caSMauro Carvalho Chehab 	0x48 /* 5x */, 0x4c /* 5.25x */, 0x50 /* 5.5x */, 0x54 /* 5.75x */,
6670c0d06caSMauro Carvalho Chehab 	0x58 /* 6x */, 0x5c /* 6.25x */, 0x60 /* 6.5x */, 0x64 /* 6.75x */,
6680c0d06caSMauro Carvalho Chehab 	0x68 /* 7x */, 0x6c /* 7.25x */, 0x70 /* 7.5x */, 0x74 /* 7.75x */,
6690c0d06caSMauro Carvalho Chehab 	0x78 /* 8x */
6700c0d06caSMauro Carvalho Chehab };
6710c0d06caSMauro Carvalho Chehab 
6720c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 soi968_init[] = {
6730c0d06caSMauro Carvalho Chehab 	{0x0c, 0x00}, {0x0f, 0x1f},
6740c0d06caSMauro Carvalho Chehab 	{0x11, 0x80}, {0x38, 0x52}, {0x1e, 0x00},
6750c0d06caSMauro Carvalho Chehab 	{0x33, 0x08}, {0x35, 0x8c}, {0x36, 0x0c},
6760c0d06caSMauro Carvalho Chehab 	{0x37, 0x04}, {0x45, 0x04}, {0x47, 0xff},
6770c0d06caSMauro Carvalho Chehab 	{0x3e, 0x00}, {0x3f, 0x00}, {0x3b, 0x20},
6780c0d06caSMauro Carvalho Chehab 	{0x3a, 0x96}, {0x3d, 0x0a}, {0x14, 0x8e},
6790c0d06caSMauro Carvalho Chehab 	{0x13, 0x8b}, {0x12, 0x40}, {0x17, 0x13},
6800c0d06caSMauro Carvalho Chehab 	{0x18, 0x63}, {0x19, 0x01}, {0x1a, 0x79},
6810c0d06caSMauro Carvalho Chehab 	{0x32, 0x24}, {0x03, 0x00}, {0x11, 0x40},
6820c0d06caSMauro Carvalho Chehab 	{0x2a, 0x10}, {0x2b, 0xe0}, {0x10, 0x32},
6830c0d06caSMauro Carvalho Chehab 	{0x00, 0x00}, {0x01, 0x80}, {0x02, 0x80},
6840c0d06caSMauro Carvalho Chehab };
6850c0d06caSMauro Carvalho Chehab 
6860c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 ov7660_init[] = {
6870c0d06caSMauro Carvalho Chehab 	{0x0e, 0x80}, {0x0d, 0x08}, {0x0f, 0xc3},
6880c0d06caSMauro Carvalho Chehab 	{0x04, 0xc3}, {0x10, 0x40}, {0x11, 0x40},
6890c0d06caSMauro Carvalho Chehab 	{0x12, 0x05}, {0x13, 0xba}, {0x14, 0x2a},
6900c0d06caSMauro Carvalho Chehab 	/* HDG Set hstart and hstop, datasheet default 0x11, 0x61, using
6910c0d06caSMauro Carvalho Chehab 	   0x10, 0x61 and sd->hstart, vstart = 3, fixes ugly colored borders */
6920c0d06caSMauro Carvalho Chehab 	{0x17, 0x10}, {0x18, 0x61},
6930c0d06caSMauro Carvalho Chehab 	{0x37, 0x0f}, {0x38, 0x02}, {0x39, 0x43},
6940c0d06caSMauro Carvalho Chehab 	{0x3a, 0x00}, {0x69, 0x90}, {0x2d, 0x00},
6950c0d06caSMauro Carvalho Chehab 	{0x2e, 0x00}, {0x01, 0x78}, {0x02, 0x50},
6960c0d06caSMauro Carvalho Chehab };
6970c0d06caSMauro Carvalho Chehab 
6980c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 ov7670_init[] = {
6990c0d06caSMauro Carvalho Chehab 	{0x11, 0x80}, {0x3a, 0x04}, {0x12, 0x01},
7000c0d06caSMauro Carvalho Chehab 	{0x32, 0xb6}, {0x03, 0x0a}, {0x0c, 0x00}, {0x3e, 0x00},
7010c0d06caSMauro Carvalho Chehab 	{0x70, 0x3a}, {0x71, 0x35}, {0x72, 0x11}, {0x73, 0xf0},
7020c0d06caSMauro Carvalho Chehab 	{0xa2, 0x02}, {0x13, 0xe0}, {0x00, 0x00}, {0x10, 0x00},
7030c0d06caSMauro Carvalho Chehab 	{0x0d, 0x40}, {0x14, 0x28}, {0xa5, 0x05}, {0xab, 0x07},
7040c0d06caSMauro Carvalho Chehab 	{0x24, 0x95}, {0x25, 0x33}, {0x26, 0xe3}, {0x9f, 0x75},
7050c0d06caSMauro Carvalho Chehab 	{0xa0, 0x65}, {0xa1, 0x0b}, {0xa6, 0xd8}, {0xa7, 0xd8},
7060c0d06caSMauro Carvalho Chehab 	{0xa8, 0xf0}, {0xa9, 0x90}, {0xaa, 0x94}, {0x13, 0xe5},
7070c0d06caSMauro Carvalho Chehab 	{0x0e, 0x61}, {0x0f, 0x4b}, {0x16, 0x02}, {0x1e, 0x27},
7080c0d06caSMauro Carvalho Chehab 	{0x21, 0x02}, {0x22, 0x91}, {0x29, 0x07}, {0x33, 0x0b},
7090c0d06caSMauro Carvalho Chehab 	{0x35, 0x0b}, {0x37, 0x1d}, {0x38, 0x71}, {0x39, 0x2a},
7100c0d06caSMauro Carvalho Chehab 	{0x3c, 0x78}, {0x4d, 0x40}, {0x4e, 0x20}, {0x69, 0x00},
7110c0d06caSMauro Carvalho Chehab 	{0x74, 0x19}, {0x8d, 0x4f}, {0x8e, 0x00}, {0x8f, 0x00},
7120c0d06caSMauro Carvalho Chehab 	{0x90, 0x00}, {0x91, 0x00}, {0x96, 0x00}, {0x9a, 0x80},
7130c0d06caSMauro Carvalho Chehab 	{0xb0, 0x84}, {0xb1, 0x0c}, {0xb2, 0x0e}, {0xb3, 0x82},
7140c0d06caSMauro Carvalho Chehab 	{0xb8, 0x0a}, {0x43, 0x0a}, {0x44, 0xf0}, {0x45, 0x20},
7150c0d06caSMauro Carvalho Chehab 	{0x46, 0x7d}, {0x47, 0x29}, {0x48, 0x4a}, {0x59, 0x8c},
7160c0d06caSMauro Carvalho Chehab 	{0x5a, 0xa5}, {0x5b, 0xde}, {0x5c, 0x96}, {0x5d, 0x66},
7170c0d06caSMauro Carvalho Chehab 	{0x5e, 0x10}, {0x6c, 0x0a}, {0x6d, 0x55}, {0x6e, 0x11},
7180c0d06caSMauro Carvalho Chehab 	{0x6f, 0x9e}, {0x6a, 0x40}, {0x01, 0x40}, {0x02, 0x40},
7190c0d06caSMauro Carvalho Chehab 	{0x13, 0xe7}, {0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x02},
7200c0d06caSMauro Carvalho Chehab 	{0x52, 0x1d}, {0x53, 0x56}, {0x54, 0x73}, {0x55, 0x0a},
7210c0d06caSMauro Carvalho Chehab 	{0x56, 0x55}, {0x57, 0x80}, {0x58, 0x9e}, {0x41, 0x08},
7220c0d06caSMauro Carvalho Chehab 	{0x3f, 0x02}, {0x75, 0x03}, {0x76, 0x63}, {0x4c, 0x04},
7230c0d06caSMauro Carvalho Chehab 	{0x77, 0x06}, {0x3d, 0x02}, {0x4b, 0x09}, {0xc9, 0x30},
7240c0d06caSMauro Carvalho Chehab 	{0x41, 0x08}, {0x56, 0x48}, {0x34, 0x11}, {0xa4, 0x88},
7250c0d06caSMauro Carvalho Chehab 	{0x96, 0x00}, {0x97, 0x30}, {0x98, 0x20}, {0x99, 0x30},
7260c0d06caSMauro Carvalho Chehab 	{0x9a, 0x84}, {0x9b, 0x29}, {0x9c, 0x03}, {0x9d, 0x99},
7270c0d06caSMauro Carvalho Chehab 	{0x9e, 0x7f}, {0x78, 0x04}, {0x79, 0x01}, {0xc8, 0xf0},
7280c0d06caSMauro Carvalho Chehab 	{0x79, 0x0f}, {0xc8, 0x00}, {0x79, 0x10}, {0xc8, 0x7e},
7290c0d06caSMauro Carvalho Chehab 	{0x79, 0x0a}, {0xc8, 0x80}, {0x79, 0x0b}, {0xc8, 0x01},
7300c0d06caSMauro Carvalho Chehab 	{0x79, 0x0c}, {0xc8, 0x0f}, {0x79, 0x0d}, {0xc8, 0x20},
7310c0d06caSMauro Carvalho Chehab 	{0x79, 0x09}, {0xc8, 0x80}, {0x79, 0x02}, {0xc8, 0xc0},
7320c0d06caSMauro Carvalho Chehab 	{0x79, 0x03}, {0xc8, 0x40}, {0x79, 0x05}, {0xc8, 0x30},
7330c0d06caSMauro Carvalho Chehab 	{0x79, 0x26}, {0x62, 0x20}, {0x63, 0x00}, {0x64, 0x06},
7340c0d06caSMauro Carvalho Chehab 	{0x65, 0x00}, {0x66, 0x05}, {0x94, 0x05}, {0x95, 0x0a},
7350c0d06caSMauro Carvalho Chehab 	{0x17, 0x13}, {0x18, 0x01}, {0x19, 0x02}, {0x1a, 0x7a},
7360c0d06caSMauro Carvalho Chehab 	{0x46, 0x59}, {0x47, 0x30}, {0x58, 0x9a}, {0x59, 0x84},
7370c0d06caSMauro Carvalho Chehab 	{0x5a, 0x91}, {0x5b, 0x57}, {0x5c, 0x75}, {0x5d, 0x6d},
7380c0d06caSMauro Carvalho Chehab 	{0x5e, 0x13}, {0x64, 0x07}, {0x94, 0x07}, {0x95, 0x0d},
7390c0d06caSMauro Carvalho Chehab 	{0xa6, 0xdf}, {0xa7, 0xdf}, {0x48, 0x4d}, {0x51, 0x00},
7400c0d06caSMauro Carvalho Chehab 	{0x6b, 0x0a}, {0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00},
7410c0d06caSMauro Carvalho Chehab 	{0x92, 0x00}, {0x93, 0x00}, {0x55, 0x0a}, {0x56, 0x60},
7420c0d06caSMauro Carvalho Chehab 	{0x4f, 0x6e}, {0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d},
7430c0d06caSMauro Carvalho Chehab 	{0x53, 0x56}, {0x54, 0x73}, {0x58, 0x9a}, {0x4f, 0x6e},
7440c0d06caSMauro Carvalho Chehab 	{0x50, 0x70}, {0x51, 0x00}, {0x52, 0x1d}, {0x53, 0x56},
7450c0d06caSMauro Carvalho Chehab 	{0x54, 0x73}, {0x58, 0x9a}, {0x3f, 0x01}, {0x7b, 0x03},
7460c0d06caSMauro Carvalho Chehab 	{0x7c, 0x09}, {0x7d, 0x16}, {0x7e, 0x38}, {0x7f, 0x47},
7470c0d06caSMauro Carvalho Chehab 	{0x80, 0x53}, {0x81, 0x5e}, {0x82, 0x6a}, {0x83, 0x74},
7480c0d06caSMauro Carvalho Chehab 	{0x84, 0x80}, {0x85, 0x8c}, {0x86, 0x9b}, {0x87, 0xb2},
7490c0d06caSMauro Carvalho Chehab 	{0x88, 0xcc}, {0x89, 0xe5}, {0x7a, 0x24}, {0x3b, 0x00},
7500c0d06caSMauro Carvalho Chehab 	{0x9f, 0x76}, {0xa0, 0x65}, {0x13, 0xe2}, {0x6b, 0x0a},
7510c0d06caSMauro Carvalho Chehab 	{0x11, 0x80}, {0x2a, 0x00}, {0x2b, 0x00}, {0x92, 0x00},
7520c0d06caSMauro Carvalho Chehab 	{0x93, 0x00},
7530c0d06caSMauro Carvalho Chehab };
7540c0d06caSMauro Carvalho Chehab 
7550c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 ov9650_init[] = {
7560c0d06caSMauro Carvalho Chehab 	{0x00, 0x00}, {0x01, 0x78},
7570c0d06caSMauro Carvalho Chehab 	{0x02, 0x78}, {0x03, 0x36}, {0x04, 0x03},
7580c0d06caSMauro Carvalho Chehab 	{0x05, 0x00}, {0x06, 0x00}, {0x08, 0x00},
7590c0d06caSMauro Carvalho Chehab 	{0x09, 0x01}, {0x0c, 0x00}, {0x0d, 0x00},
7600c0d06caSMauro Carvalho Chehab 	{0x0e, 0xa0}, {0x0f, 0x52}, {0x10, 0x7c},
7610c0d06caSMauro Carvalho Chehab 	{0x11, 0x80}, {0x12, 0x45}, {0x13, 0xc2},
7620c0d06caSMauro Carvalho Chehab 	{0x14, 0x2e}, {0x15, 0x00}, {0x16, 0x07},
7630c0d06caSMauro Carvalho Chehab 	{0x17, 0x24}, {0x18, 0xc5}, {0x19, 0x00},
7640c0d06caSMauro Carvalho Chehab 	{0x1a, 0x3c}, {0x1b, 0x00}, {0x1e, 0x04},
7650c0d06caSMauro Carvalho Chehab 	{0x1f, 0x00}, {0x24, 0x78}, {0x25, 0x68},
7660c0d06caSMauro Carvalho Chehab 	{0x26, 0xd4}, {0x27, 0x80}, {0x28, 0x80},
7670c0d06caSMauro Carvalho Chehab 	{0x29, 0x30}, {0x2a, 0x00}, {0x2b, 0x00},
7680c0d06caSMauro Carvalho Chehab 	{0x2c, 0x80}, {0x2d, 0x00}, {0x2e, 0x00},
7690c0d06caSMauro Carvalho Chehab 	{0x2f, 0x00}, {0x30, 0x08}, {0x31, 0x30},
7700c0d06caSMauro Carvalho Chehab 	{0x32, 0x84}, {0x33, 0xe2}, {0x34, 0xbf},
7710c0d06caSMauro Carvalho Chehab 	{0x35, 0x81}, {0x36, 0xf9}, {0x37, 0x00},
7720c0d06caSMauro Carvalho Chehab 	{0x38, 0x93}, {0x39, 0x50}, {0x3a, 0x01},
7730c0d06caSMauro Carvalho Chehab 	{0x3b, 0x01}, {0x3c, 0x73}, {0x3d, 0x19},
7740c0d06caSMauro Carvalho Chehab 	{0x3e, 0x0b}, {0x3f, 0x80}, {0x40, 0xc1},
7750c0d06caSMauro Carvalho Chehab 	{0x41, 0x00}, {0x42, 0x08}, {0x67, 0x80},
7760c0d06caSMauro Carvalho Chehab 	{0x68, 0x80}, {0x69, 0x40}, {0x6a, 0x00},
7770c0d06caSMauro Carvalho Chehab 	{0x6b, 0x0a}, {0x8b, 0x06}, {0x8c, 0x20},
7780c0d06caSMauro Carvalho Chehab 	{0x8d, 0x00}, {0x8e, 0x00}, {0x8f, 0xdf},
7790c0d06caSMauro Carvalho Chehab 	{0x92, 0x00}, {0x93, 0x00}, {0x94, 0x88},
7800c0d06caSMauro Carvalho Chehab 	{0x95, 0x88}, {0x96, 0x04}, {0xa1, 0x00},
7810c0d06caSMauro Carvalho Chehab 	{0xa5, 0x80}, {0xa8, 0x80}, {0xa9, 0xb8},
7820c0d06caSMauro Carvalho Chehab 	{0xaa, 0x92}, {0xab, 0x0a},
7830c0d06caSMauro Carvalho Chehab };
7840c0d06caSMauro Carvalho Chehab 
7850c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 ov9655_init[] = {
7860c0d06caSMauro Carvalho Chehab 	{0x0e, 0x61}, {0x11, 0x80}, {0x13, 0xba},
7870c0d06caSMauro Carvalho Chehab 	{0x14, 0x2e}, {0x16, 0x24}, {0x1e, 0x04}, {0x27, 0x08},
7880c0d06caSMauro Carvalho Chehab 	{0x28, 0x08}, {0x29, 0x15}, {0x2c, 0x08}, {0x34, 0x3d},
7890c0d06caSMauro Carvalho Chehab 	{0x35, 0x00}, {0x38, 0x12}, {0x0f, 0x42}, {0x39, 0x57},
7900c0d06caSMauro Carvalho Chehab 	{0x3a, 0x00}, {0x3b, 0xcc}, {0x3c, 0x0c}, {0x3d, 0x19},
7910c0d06caSMauro Carvalho Chehab 	{0x3e, 0x0c}, {0x3f, 0x01}, {0x41, 0x40}, {0x42, 0x80},
7920c0d06caSMauro Carvalho Chehab 	{0x45, 0x46}, {0x46, 0x62}, {0x47, 0x2a}, {0x48, 0x3c},
7930c0d06caSMauro Carvalho Chehab 	{0x4a, 0xf0}, {0x4b, 0xdc}, {0x4c, 0xdc}, {0x4d, 0xdc},
7940c0d06caSMauro Carvalho Chehab 	{0x4e, 0xdc}, {0x6c, 0x04}, {0x6f, 0x9e}, {0x70, 0x05},
7950c0d06caSMauro Carvalho Chehab 	{0x71, 0x78}, {0x77, 0x02}, {0x8a, 0x23}, {0x90, 0x7e},
7960c0d06caSMauro Carvalho Chehab 	{0x91, 0x7c}, {0x9f, 0x6e}, {0xa0, 0x6e}, {0xa5, 0x68},
7970c0d06caSMauro Carvalho Chehab 	{0xa6, 0x60}, {0xa8, 0xc1}, {0xa9, 0xfa}, {0xaa, 0x92},
7980c0d06caSMauro Carvalho Chehab 	{0xab, 0x04}, {0xac, 0x80}, {0xad, 0x80}, {0xae, 0x80},
7990c0d06caSMauro Carvalho Chehab 	{0xaf, 0x80}, {0xb2, 0xf2}, {0xb3, 0x20}, {0xb5, 0x00},
8000c0d06caSMauro Carvalho Chehab 	{0xb6, 0xaf}, {0xbb, 0xae}, {0xbc, 0x44}, {0xbd, 0x44},
8010c0d06caSMauro Carvalho Chehab 	{0xbe, 0x3b}, {0xbf, 0x3a}, {0xc1, 0xc8}, {0xc2, 0x01},
8020c0d06caSMauro Carvalho Chehab 	{0xc4, 0x00}, {0xc6, 0x85}, {0xc7, 0x81}, {0xc9, 0xe0},
8030c0d06caSMauro Carvalho Chehab 	{0xca, 0xe8}, {0xcc, 0xd8}, {0xcd, 0x93}, {0x2d, 0x00},
8040c0d06caSMauro Carvalho Chehab 	{0x2e, 0x00}, {0x01, 0x80}, {0x02, 0x80}, {0x12, 0x61},
8050c0d06caSMauro Carvalho Chehab 	{0x36, 0xfa}, {0x8c, 0x8d}, {0xc0, 0xaa}, {0x69, 0x0a},
8060c0d06caSMauro Carvalho Chehab 	{0x03, 0x09}, {0x17, 0x16}, {0x18, 0x6e}, {0x19, 0x01},
8070c0d06caSMauro Carvalho Chehab 	{0x1a, 0x3e}, {0x32, 0x09}, {0x2a, 0x10}, {0x2b, 0x0a},
8080c0d06caSMauro Carvalho Chehab 	{0x92, 0x00}, {0x93, 0x00}, {0xa1, 0x00}, {0x10, 0x7c},
8090c0d06caSMauro Carvalho Chehab 	{0x04, 0x03}, {0x00, 0x13},
8100c0d06caSMauro Carvalho Chehab };
8110c0d06caSMauro Carvalho Chehab 
8120c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9v112_init[] = {
8130c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0020},
8140c0d06caSMauro Carvalho Chehab 	{0x34, 0xc019}, {0x0a, 0x0011}, {0x0b, 0x000b},
8150c0d06caSMauro Carvalho Chehab 	{0x20, 0x0703}, {0x35, 0x2022}, {0xf0, 0x0001},
8160c0d06caSMauro Carvalho Chehab 	{0x05, 0x0000}, {0x06, 0x340c}, {0x3b, 0x042a},
8170c0d06caSMauro Carvalho Chehab 	{0x3c, 0x0400}, {0xf0, 0x0002}, {0x2e, 0x0c58},
8180c0d06caSMauro Carvalho Chehab 	{0x5b, 0x0001}, {0xc8, 0x9f0b}, {0xf0, 0x0001},
8190c0d06caSMauro Carvalho Chehab 	{0x9b, 0x5300}, {0xf0, 0x0000}, {0x2b, 0x0020},
8200c0d06caSMauro Carvalho Chehab 	{0x2c, 0x002a}, {0x2d, 0x0032}, {0x2e, 0x0020},
8210c0d06caSMauro Carvalho Chehab 	{0x09, 0x01dc}, {0x01, 0x000c}, {0x02, 0x0020},
8220c0d06caSMauro Carvalho Chehab 	{0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
8230c0d06caSMauro Carvalho Chehab 	{0x05, 0x0098}, {0x20, 0x0703}, {0x09, 0x01f2},
8240c0d06caSMauro Carvalho Chehab 	{0x2b, 0x00a0}, {0x2c, 0x00a0}, {0x2d, 0x00a0},
8250c0d06caSMauro Carvalho Chehab 	{0x2e, 0x00a0}, {0x01, 0x000c}, {0x02, 0x0020},
8260c0d06caSMauro Carvalho Chehab 	{0x03, 0x01e0}, {0x04, 0x0280}, {0x06, 0x000c},
8270c0d06caSMauro Carvalho Chehab 	{0x05, 0x0098}, {0x09, 0x01c1}, {0x2b, 0x00ae},
8280c0d06caSMauro Carvalho Chehab 	{0x2c, 0x00ae}, {0x2d, 0x00ae}, {0x2e, 0x00ae},
8290c0d06caSMauro Carvalho Chehab };
8300c0d06caSMauro Carvalho Chehab 
8310c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9v111_init[] = {
8320c0d06caSMauro Carvalho Chehab 	{0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000},
8330c0d06caSMauro Carvalho Chehab 	{0x01, 0x0001}, {0x05, 0x0004}, {0x2d, 0xe0a0},
8340c0d06caSMauro Carvalho Chehab 	{0x2e, 0x0c64},	{0x2f, 0x0064}, {0x06, 0x600e},
8350c0d06caSMauro Carvalho Chehab 	{0x08, 0x0480}, {0x01, 0x0004}, {0x02, 0x0016},
8360c0d06caSMauro Carvalho Chehab 	{0x03, 0x01e7}, {0x04, 0x0287}, {0x05, 0x0004},
8370c0d06caSMauro Carvalho Chehab 	{0x06, 0x002d},	{0x07, 0x3002}, {0x08, 0x0008},
8380c0d06caSMauro Carvalho Chehab 	{0x0e, 0x0008}, {0x20, 0x0000}
8390c0d06caSMauro Carvalho Chehab };
8400c0d06caSMauro Carvalho Chehab 
8410c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9v011_init[] = {
8420c0d06caSMauro Carvalho Chehab 	{0x07, 0x0002},	{0x0d, 0x0001},	{0x0d, 0x0000},
8430c0d06caSMauro Carvalho Chehab 	{0x01, 0x0008},	{0x02, 0x0016},	{0x03, 0x01e1},
8440c0d06caSMauro Carvalho Chehab 	{0x04, 0x0281},	{0x05, 0x0083},	{0x06, 0x0006},
8450c0d06caSMauro Carvalho Chehab 	{0x0d, 0x0002}, {0x0a, 0x0000},	{0x0b, 0x0000},
8460c0d06caSMauro Carvalho Chehab 	{0x0c, 0x0000},	{0x0d, 0x0000},	{0x0e, 0x0000},
8470c0d06caSMauro Carvalho Chehab 	{0x0f, 0x0000},	{0x10, 0x0000},	{0x11, 0x0000},
8480c0d06caSMauro Carvalho Chehab 	{0x12, 0x0000},	{0x13, 0x0000},	{0x14, 0x0000},
8490c0d06caSMauro Carvalho Chehab 	{0x15, 0x0000},	{0x16, 0x0000},	{0x17, 0x0000},
8500c0d06caSMauro Carvalho Chehab 	{0x18, 0x0000},	{0x19, 0x0000},	{0x1a, 0x0000},
8510c0d06caSMauro Carvalho Chehab 	{0x1b, 0x0000},	{0x1c, 0x0000},	{0x1d, 0x0000},
8520c0d06caSMauro Carvalho Chehab 	{0x32, 0x0000},	{0x20, 0x1101},	{0x21, 0x0000},
8530c0d06caSMauro Carvalho Chehab 	{0x22, 0x0000},	{0x23, 0x0000},	{0x24, 0x0000},
8540c0d06caSMauro Carvalho Chehab 	{0x25, 0x0000},	{0x26, 0x0000},	{0x27, 0x0024},
8550c0d06caSMauro Carvalho Chehab 	{0x2f, 0xf7b0},	{0x30, 0x0005},	{0x31, 0x0000},
8560c0d06caSMauro Carvalho Chehab 	{0x32, 0x0000},	{0x33, 0x0000},	{0x34, 0x0100},
8570c0d06caSMauro Carvalho Chehab 	{0x3d, 0x068f},	{0x40, 0x01e0},	{0x41, 0x00d1},
8580c0d06caSMauro Carvalho Chehab 	{0x44, 0x0082},	{0x5a, 0x0000},	{0x5b, 0x0000},
8590c0d06caSMauro Carvalho Chehab 	{0x5c, 0x0000},	{0x5d, 0x0000},	{0x5e, 0x0000},
8600c0d06caSMauro Carvalho Chehab 	{0x5f, 0xa31d},	{0x62, 0x0611},	{0x0a, 0x0000},
8610c0d06caSMauro Carvalho Chehab 	{0x06, 0x0029},	{0x05, 0x0009},	{0x20, 0x1101},
8620c0d06caSMauro Carvalho Chehab 	{0x20, 0x1101},	{0x09, 0x0064},	{0x07, 0x0003},
8630c0d06caSMauro Carvalho Chehab 	{0x2b, 0x0033},	{0x2c, 0x00a0},	{0x2d, 0x00a0},
8640c0d06caSMauro Carvalho Chehab 	{0x2e, 0x0033},	{0x07, 0x0002},	{0x06, 0x0000},
8650c0d06caSMauro Carvalho Chehab 	{0x06, 0x0029},	{0x05, 0x0009},
8660c0d06caSMauro Carvalho Chehab };
8670c0d06caSMauro Carvalho Chehab 
8680c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9m001_init[] = {
8690c0d06caSMauro Carvalho Chehab 	{0x0d, 0x0001},
8700c0d06caSMauro Carvalho Chehab 	{0x0d, 0x0000},
8710c0d06caSMauro Carvalho Chehab 	{0x04, 0x0500},		/* hres = 1280 */
8720c0d06caSMauro Carvalho Chehab 	{0x03, 0x0400},		/* vres = 1024 */
8730c0d06caSMauro Carvalho Chehab 	{0x20, 0x1100},
8740c0d06caSMauro Carvalho Chehab 	{0x06, 0x0010},
8750c0d06caSMauro Carvalho Chehab 	{0x2b, 0x0024},
8760c0d06caSMauro Carvalho Chehab 	{0x2e, 0x0024},
8770c0d06caSMauro Carvalho Chehab 	{0x35, 0x0024},
8780c0d06caSMauro Carvalho Chehab 	{0x2d, 0x0020},
8790c0d06caSMauro Carvalho Chehab 	{0x2c, 0x0020},
8800c0d06caSMauro Carvalho Chehab 	{0x09, 0x0ad4},
8810c0d06caSMauro Carvalho Chehab 	{0x35, 0x0057},
8820c0d06caSMauro Carvalho Chehab };
8830c0d06caSMauro Carvalho Chehab 
8840c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9m111_init[] = {
8850c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
8860c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
8870c0d06caSMauro Carvalho Chehab 	{0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
8880c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0000},
8890c0d06caSMauro Carvalho Chehab };
8900c0d06caSMauro Carvalho Chehab 
8910c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u16 mt9m112_init[] = {
8920c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008},
8930c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300},
8940c0d06caSMauro Carvalho Chehab 	{0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e},
8950c0d06caSMauro Carvalho Chehab 	{0xf0, 0x0000},
8960c0d06caSMauro Carvalho Chehab };
8970c0d06caSMauro Carvalho Chehab 
8980c0d06caSMauro Carvalho Chehab static const struct i2c_reg_u8 hv7131r_init[] = {
8990c0d06caSMauro Carvalho Chehab 	{0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08},
9000c0d06caSMauro Carvalho Chehab 	{0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0},
9010c0d06caSMauro Carvalho Chehab 	{0x22, 0x00}, {0x23, 0x09}, {0x01, 0x08},
9020c0d06caSMauro Carvalho Chehab 	{0x01, 0x08}, {0x01, 0x08}, {0x25, 0x07},
9030c0d06caSMauro Carvalho Chehab 	{0x26, 0xc3}, {0x27, 0x50}, {0x30, 0x62},
9040c0d06caSMauro Carvalho Chehab 	{0x31, 0x10}, {0x32, 0x06}, {0x33, 0x10},
9050c0d06caSMauro Carvalho Chehab 	{0x20, 0x00}, {0x21, 0xd0}, {0x22, 0x00},
9060c0d06caSMauro Carvalho Chehab 	{0x23, 0x09}, {0x01, 0x08},
9070c0d06caSMauro Carvalho Chehab };
9080c0d06caSMauro Carvalho Chehab 
9090c0d06caSMauro Carvalho Chehab static void reg_r(struct gspca_dev *gspca_dev, u16 reg, u16 length)
9100c0d06caSMauro Carvalho Chehab {
9110c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
9120c0d06caSMauro Carvalho Chehab 	int result;
9130c0d06caSMauro Carvalho Chehab 
9140c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
9150c0d06caSMauro Carvalho Chehab 		return;
9160c0d06caSMauro Carvalho Chehab 	result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
9170c0d06caSMauro Carvalho Chehab 			0x00,
9180c0d06caSMauro Carvalho Chehab 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
9190c0d06caSMauro Carvalho Chehab 			reg,
9200c0d06caSMauro Carvalho Chehab 			0x00,
9210c0d06caSMauro Carvalho Chehab 			gspca_dev->usb_buf,
9220c0d06caSMauro Carvalho Chehab 			length,
9230c0d06caSMauro Carvalho Chehab 			500);
9240c0d06caSMauro Carvalho Chehab 	if (unlikely(result < 0 || result != length)) {
9250c0d06caSMauro Carvalho Chehab 		pr_err("Read register %02x failed %d\n", reg, result);
9260c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = result;
9270c0d06caSMauro Carvalho Chehab 	}
9280c0d06caSMauro Carvalho Chehab }
9290c0d06caSMauro Carvalho Chehab 
9300c0d06caSMauro Carvalho Chehab static void reg_w(struct gspca_dev *gspca_dev, u16 reg,
9310c0d06caSMauro Carvalho Chehab 		 const u8 *buffer, int length)
9320c0d06caSMauro Carvalho Chehab {
9330c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
9340c0d06caSMauro Carvalho Chehab 	int result;
9350c0d06caSMauro Carvalho Chehab 
9360c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
9370c0d06caSMauro Carvalho Chehab 		return;
9380c0d06caSMauro Carvalho Chehab 	memcpy(gspca_dev->usb_buf, buffer, length);
9390c0d06caSMauro Carvalho Chehab 	result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
9400c0d06caSMauro Carvalho Chehab 			0x08,
9410c0d06caSMauro Carvalho Chehab 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
9420c0d06caSMauro Carvalho Chehab 			reg,
9430c0d06caSMauro Carvalho Chehab 			0x00,
9440c0d06caSMauro Carvalho Chehab 			gspca_dev->usb_buf,
9450c0d06caSMauro Carvalho Chehab 			length,
9460c0d06caSMauro Carvalho Chehab 			500);
9470c0d06caSMauro Carvalho Chehab 	if (unlikely(result < 0 || result != length)) {
9480c0d06caSMauro Carvalho Chehab 		pr_err("Write register %02x failed %d\n", reg, result);
9490c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = result;
9500c0d06caSMauro Carvalho Chehab 	}
9510c0d06caSMauro Carvalho Chehab }
9520c0d06caSMauro Carvalho Chehab 
9530c0d06caSMauro Carvalho Chehab static void reg_w1(struct gspca_dev *gspca_dev, u16 reg, const u8 value)
9540c0d06caSMauro Carvalho Chehab {
9550c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, reg, &value, 1);
9560c0d06caSMauro Carvalho Chehab }
9570c0d06caSMauro Carvalho Chehab 
9580c0d06caSMauro Carvalho Chehab static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buffer)
9590c0d06caSMauro Carvalho Chehab {
9600c0d06caSMauro Carvalho Chehab 	int i;
9610c0d06caSMauro Carvalho Chehab 
9620c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x10c0, buffer, 8);
9630c0d06caSMauro Carvalho Chehab 	for (i = 0; i < 5; i++) {
9640c0d06caSMauro Carvalho Chehab 		reg_r(gspca_dev, 0x10c0, 1);
9650c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
9660c0d06caSMauro Carvalho Chehab 			return;
9670c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_buf[0] & 0x04) {
9680c0d06caSMauro Carvalho Chehab 			if (gspca_dev->usb_buf[0] & 0x08) {
9690c0d06caSMauro Carvalho Chehab 				pr_err("i2c_w error\n");
9700c0d06caSMauro Carvalho Chehab 				gspca_dev->usb_err = -EIO;
9710c0d06caSMauro Carvalho Chehab 			}
9720c0d06caSMauro Carvalho Chehab 			return;
9730c0d06caSMauro Carvalho Chehab 		}
9740c0d06caSMauro Carvalho Chehab 		msleep(10);
9750c0d06caSMauro Carvalho Chehab 	}
9760c0d06caSMauro Carvalho Chehab 	pr_err("i2c_w reg %02x no response\n", buffer[2]);
9770c0d06caSMauro Carvalho Chehab /*	gspca_dev->usb_err = -EIO;	fixme: may occur */
9780c0d06caSMauro Carvalho Chehab }
9790c0d06caSMauro Carvalho Chehab 
9800c0d06caSMauro Carvalho Chehab static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
9810c0d06caSMauro Carvalho Chehab {
9820c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
9830c0d06caSMauro Carvalho Chehab 	u8 row[8];
9840c0d06caSMauro Carvalho Chehab 
9850c0d06caSMauro Carvalho Chehab 	/*
9860c0d06caSMauro Carvalho Chehab 	 * from the point of view of the bridge, the length
9870c0d06caSMauro Carvalho Chehab 	 * includes the address
9880c0d06caSMauro Carvalho Chehab 	 */
9890c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (2 << 4);
9900c0d06caSMauro Carvalho Chehab 	row[1] = sd->i2c_addr;
9910c0d06caSMauro Carvalho Chehab 	row[2] = reg;
9920c0d06caSMauro Carvalho Chehab 	row[3] = val;
9930c0d06caSMauro Carvalho Chehab 	row[4] = 0x00;
9940c0d06caSMauro Carvalho Chehab 	row[5] = 0x00;
9950c0d06caSMauro Carvalho Chehab 	row[6] = 0x00;
9960c0d06caSMauro Carvalho Chehab 	row[7] = 0x10;
9970c0d06caSMauro Carvalho Chehab 
9980c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
9990c0d06caSMauro Carvalho Chehab }
10000c0d06caSMauro Carvalho Chehab 
10010c0d06caSMauro Carvalho Chehab static void i2c_w1_buf(struct gspca_dev *gspca_dev,
10020c0d06caSMauro Carvalho Chehab 			const struct i2c_reg_u8 *buf, int sz)
10030c0d06caSMauro Carvalho Chehab {
10040c0d06caSMauro Carvalho Chehab 	while (--sz >= 0) {
10050c0d06caSMauro Carvalho Chehab 		i2c_w1(gspca_dev, buf->reg, buf->val);
10060c0d06caSMauro Carvalho Chehab 		buf++;
10070c0d06caSMauro Carvalho Chehab 	}
10080c0d06caSMauro Carvalho Chehab }
10090c0d06caSMauro Carvalho Chehab 
10100c0d06caSMauro Carvalho Chehab static void i2c_w2(struct gspca_dev *gspca_dev, u8 reg, u16 val)
10110c0d06caSMauro Carvalho Chehab {
10120c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
10130c0d06caSMauro Carvalho Chehab 	u8 row[8];
10140c0d06caSMauro Carvalho Chehab 
10150c0d06caSMauro Carvalho Chehab 	/*
10160c0d06caSMauro Carvalho Chehab 	 * from the point of view of the bridge, the length
10170c0d06caSMauro Carvalho Chehab 	 * includes the address
10180c0d06caSMauro Carvalho Chehab 	 */
10190c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (3 << 4);
10200c0d06caSMauro Carvalho Chehab 	row[1] = sd->i2c_addr;
10210c0d06caSMauro Carvalho Chehab 	row[2] = reg;
10220c0d06caSMauro Carvalho Chehab 	row[3] = val >> 8;
10230c0d06caSMauro Carvalho Chehab 	row[4] = val;
10240c0d06caSMauro Carvalho Chehab 	row[5] = 0x00;
10250c0d06caSMauro Carvalho Chehab 	row[6] = 0x00;
10260c0d06caSMauro Carvalho Chehab 	row[7] = 0x10;
10270c0d06caSMauro Carvalho Chehab 
10280c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
10290c0d06caSMauro Carvalho Chehab }
10300c0d06caSMauro Carvalho Chehab 
10310c0d06caSMauro Carvalho Chehab static void i2c_w2_buf(struct gspca_dev *gspca_dev,
10320c0d06caSMauro Carvalho Chehab 			const struct i2c_reg_u16 *buf, int sz)
10330c0d06caSMauro Carvalho Chehab {
10340c0d06caSMauro Carvalho Chehab 	while (--sz >= 0) {
10350c0d06caSMauro Carvalho Chehab 		i2c_w2(gspca_dev, buf->reg, buf->val);
10360c0d06caSMauro Carvalho Chehab 		buf++;
10370c0d06caSMauro Carvalho Chehab 	}
10380c0d06caSMauro Carvalho Chehab }
10390c0d06caSMauro Carvalho Chehab 
10400c0d06caSMauro Carvalho Chehab static void i2c_r1(struct gspca_dev *gspca_dev, u8 reg, u8 *val)
10410c0d06caSMauro Carvalho Chehab {
10420c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
10430c0d06caSMauro Carvalho Chehab 	u8 row[8];
10440c0d06caSMauro Carvalho Chehab 
10450c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (1 << 4);
10460c0d06caSMauro Carvalho Chehab 	row[1] = sd->i2c_addr;
10470c0d06caSMauro Carvalho Chehab 	row[2] = reg;
10480c0d06caSMauro Carvalho Chehab 	row[3] = 0;
10490c0d06caSMauro Carvalho Chehab 	row[4] = 0;
10500c0d06caSMauro Carvalho Chehab 	row[5] = 0;
10510c0d06caSMauro Carvalho Chehab 	row[6] = 0;
10520c0d06caSMauro Carvalho Chehab 	row[7] = 0x10;
10530c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
10540c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (1 << 4) | 0x02;
10550c0d06caSMauro Carvalho Chehab 	row[2] = 0;
10560c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
10570c0d06caSMauro Carvalho Chehab 	reg_r(gspca_dev, 0x10c2, 5);
10580c0d06caSMauro Carvalho Chehab 	*val = gspca_dev->usb_buf[4];
10590c0d06caSMauro Carvalho Chehab }
10600c0d06caSMauro Carvalho Chehab 
10610c0d06caSMauro Carvalho Chehab static void i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
10620c0d06caSMauro Carvalho Chehab {
10630c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
10640c0d06caSMauro Carvalho Chehab 	u8 row[8];
10650c0d06caSMauro Carvalho Chehab 
10660c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (1 << 4);
10670c0d06caSMauro Carvalho Chehab 	row[1] = sd->i2c_addr;
10680c0d06caSMauro Carvalho Chehab 	row[2] = reg;
10690c0d06caSMauro Carvalho Chehab 	row[3] = 0;
10700c0d06caSMauro Carvalho Chehab 	row[4] = 0;
10710c0d06caSMauro Carvalho Chehab 	row[5] = 0;
10720c0d06caSMauro Carvalho Chehab 	row[6] = 0;
10730c0d06caSMauro Carvalho Chehab 	row[7] = 0x10;
10740c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
10750c0d06caSMauro Carvalho Chehab 	row[0] = sd->i2c_intf | (2 << 4) | 0x02;
10760c0d06caSMauro Carvalho Chehab 	row[2] = 0;
10770c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, row);
10780c0d06caSMauro Carvalho Chehab 	reg_r(gspca_dev, 0x10c2, 5);
10790c0d06caSMauro Carvalho Chehab 	*val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
10800c0d06caSMauro Carvalho Chehab }
10810c0d06caSMauro Carvalho Chehab 
10820c0d06caSMauro Carvalho Chehab static void ov9650_init_sensor(struct gspca_dev *gspca_dev)
10830c0d06caSMauro Carvalho Chehab {
10840c0d06caSMauro Carvalho Chehab 	u16 id;
10850c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
10860c0d06caSMauro Carvalho Chehab 
10870c0d06caSMauro Carvalho Chehab 	i2c_r2(gspca_dev, 0x1c, &id);
10880c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
10890c0d06caSMauro Carvalho Chehab 		return;
10900c0d06caSMauro Carvalho Chehab 
10910c0d06caSMauro Carvalho Chehab 	if (id != 0x7fa2) {
10920c0d06caSMauro Carvalho Chehab 		pr_err("sensor id for ov9650 doesn't match (0x%04x)\n", id);
10930c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = -ENODEV;
10940c0d06caSMauro Carvalho Chehab 		return;
10950c0d06caSMauro Carvalho Chehab 	}
10960c0d06caSMauro Carvalho Chehab 
10970c0d06caSMauro Carvalho Chehab 	i2c_w1(gspca_dev, 0x12, 0x80);		/* sensor reset */
10980c0d06caSMauro Carvalho Chehab 	msleep(200);
10990c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, ov9650_init, ARRAY_SIZE(ov9650_init));
11000c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
11010c0d06caSMauro Carvalho Chehab 		pr_err("OV9650 sensor initialization failed\n");
11020c0d06caSMauro Carvalho Chehab 	sd->hstart = 1;
11030c0d06caSMauro Carvalho Chehab 	sd->vstart = 7;
11040c0d06caSMauro Carvalho Chehab }
11050c0d06caSMauro Carvalho Chehab 
11060c0d06caSMauro Carvalho Chehab static void ov9655_init_sensor(struct gspca_dev *gspca_dev)
11070c0d06caSMauro Carvalho Chehab {
11080c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
11090c0d06caSMauro Carvalho Chehab 
11100c0d06caSMauro Carvalho Chehab 	i2c_w1(gspca_dev, 0x12, 0x80);		/* sensor reset */
11110c0d06caSMauro Carvalho Chehab 	msleep(200);
11120c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, ov9655_init, ARRAY_SIZE(ov9655_init));
11130c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
11140c0d06caSMauro Carvalho Chehab 		pr_err("OV9655 sensor initialization failed\n");
11150c0d06caSMauro Carvalho Chehab 
11160c0d06caSMauro Carvalho Chehab 	sd->hstart = 1;
11170c0d06caSMauro Carvalho Chehab 	sd->vstart = 2;
11180c0d06caSMauro Carvalho Chehab }
11190c0d06caSMauro Carvalho Chehab 
11200c0d06caSMauro Carvalho Chehab static void soi968_init_sensor(struct gspca_dev *gspca_dev)
11210c0d06caSMauro Carvalho Chehab {
11220c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
11230c0d06caSMauro Carvalho Chehab 
11240c0d06caSMauro Carvalho Chehab 	i2c_w1(gspca_dev, 0x12, 0x80);		/* sensor reset */
11250c0d06caSMauro Carvalho Chehab 	msleep(200);
11260c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, soi968_init, ARRAY_SIZE(soi968_init));
11270c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
11280c0d06caSMauro Carvalho Chehab 		pr_err("SOI968 sensor initialization failed\n");
11290c0d06caSMauro Carvalho Chehab 
11300c0d06caSMauro Carvalho Chehab 	sd->hstart = 60;
11310c0d06caSMauro Carvalho Chehab 	sd->vstart = 11;
11320c0d06caSMauro Carvalho Chehab }
11330c0d06caSMauro Carvalho Chehab 
11340c0d06caSMauro Carvalho Chehab static void ov7660_init_sensor(struct gspca_dev *gspca_dev)
11350c0d06caSMauro Carvalho Chehab {
11360c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
11370c0d06caSMauro Carvalho Chehab 
11380c0d06caSMauro Carvalho Chehab 	i2c_w1(gspca_dev, 0x12, 0x80);		/* sensor reset */
11390c0d06caSMauro Carvalho Chehab 	msleep(200);
11400c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, ov7660_init, ARRAY_SIZE(ov7660_init));
11410c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
11420c0d06caSMauro Carvalho Chehab 		pr_err("OV7660 sensor initialization failed\n");
11430c0d06caSMauro Carvalho Chehab 	sd->hstart = 3;
11440c0d06caSMauro Carvalho Chehab 	sd->vstart = 3;
11450c0d06caSMauro Carvalho Chehab }
11460c0d06caSMauro Carvalho Chehab 
11470c0d06caSMauro Carvalho Chehab static void ov7670_init_sensor(struct gspca_dev *gspca_dev)
11480c0d06caSMauro Carvalho Chehab {
11490c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
11500c0d06caSMauro Carvalho Chehab 
11510c0d06caSMauro Carvalho Chehab 	i2c_w1(gspca_dev, 0x12, 0x80);		/* sensor reset */
11520c0d06caSMauro Carvalho Chehab 	msleep(200);
11530c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, ov7670_init, ARRAY_SIZE(ov7670_init));
11540c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
11550c0d06caSMauro Carvalho Chehab 		pr_err("OV7670 sensor initialization failed\n");
11560c0d06caSMauro Carvalho Chehab 
11570c0d06caSMauro Carvalho Chehab 	sd->hstart = 0;
11580c0d06caSMauro Carvalho Chehab 	sd->vstart = 1;
11590c0d06caSMauro Carvalho Chehab }
11600c0d06caSMauro Carvalho Chehab 
11610c0d06caSMauro Carvalho Chehab static void mt9v_init_sensor(struct gspca_dev *gspca_dev)
11620c0d06caSMauro Carvalho Chehab {
11630c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
11640c0d06caSMauro Carvalho Chehab 	u16 value;
11650c0d06caSMauro Carvalho Chehab 
11660c0d06caSMauro Carvalho Chehab 	sd->i2c_addr = 0x5d;
11670c0d06caSMauro Carvalho Chehab 	i2c_r2(gspca_dev, 0xff, &value);
11680c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err >= 0
11690c0d06caSMauro Carvalho Chehab 	 && value == 0x8243) {
11700c0d06caSMauro Carvalho Chehab 		i2c_w2_buf(gspca_dev, mt9v011_init, ARRAY_SIZE(mt9v011_init));
11710c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0) {
11720c0d06caSMauro Carvalho Chehab 			pr_err("MT9V011 sensor initialization failed\n");
11730c0d06caSMauro Carvalho Chehab 			return;
11740c0d06caSMauro Carvalho Chehab 		}
11750c0d06caSMauro Carvalho Chehab 		sd->hstart = 2;
11760c0d06caSMauro Carvalho Chehab 		sd->vstart = 2;
11770c0d06caSMauro Carvalho Chehab 		sd->sensor = SENSOR_MT9V011;
11780c0d06caSMauro Carvalho Chehab 		pr_info("MT9V011 sensor detected\n");
11790c0d06caSMauro Carvalho Chehab 		return;
11800c0d06caSMauro Carvalho Chehab 	}
11810c0d06caSMauro Carvalho Chehab 
11820c0d06caSMauro Carvalho Chehab 	gspca_dev->usb_err = 0;
11830c0d06caSMauro Carvalho Chehab 	sd->i2c_addr = 0x5c;
11840c0d06caSMauro Carvalho Chehab 	i2c_w2(gspca_dev, 0x01, 0x0004);
11850c0d06caSMauro Carvalho Chehab 	i2c_r2(gspca_dev, 0xff, &value);
11860c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err >= 0
11870c0d06caSMauro Carvalho Chehab 	 && value == 0x823a) {
11880c0d06caSMauro Carvalho Chehab 		i2c_w2_buf(gspca_dev, mt9v111_init, ARRAY_SIZE(mt9v111_init));
11890c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0) {
11900c0d06caSMauro Carvalho Chehab 			pr_err("MT9V111 sensor initialization failed\n");
11910c0d06caSMauro Carvalho Chehab 			return;
11920c0d06caSMauro Carvalho Chehab 		}
11930c0d06caSMauro Carvalho Chehab 		sd->hstart = 2;
11940c0d06caSMauro Carvalho Chehab 		sd->vstart = 2;
11950c0d06caSMauro Carvalho Chehab 		sd->sensor = SENSOR_MT9V111;
11960c0d06caSMauro Carvalho Chehab 		pr_info("MT9V111 sensor detected\n");
11970c0d06caSMauro Carvalho Chehab 		return;
11980c0d06caSMauro Carvalho Chehab 	}
11990c0d06caSMauro Carvalho Chehab 
12000c0d06caSMauro Carvalho Chehab 	gspca_dev->usb_err = 0;
12010c0d06caSMauro Carvalho Chehab 	sd->i2c_addr = 0x5d;
12020c0d06caSMauro Carvalho Chehab 	i2c_w2(gspca_dev, 0xf0, 0x0000);
12030c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0) {
12040c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = 0;
12050c0d06caSMauro Carvalho Chehab 		sd->i2c_addr = 0x48;
12060c0d06caSMauro Carvalho Chehab 		i2c_w2(gspca_dev, 0xf0, 0x0000);
12070c0d06caSMauro Carvalho Chehab 	}
12080c0d06caSMauro Carvalho Chehab 	i2c_r2(gspca_dev, 0x00, &value);
12090c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err >= 0
12100c0d06caSMauro Carvalho Chehab 	 && value == 0x1229) {
12110c0d06caSMauro Carvalho Chehab 		i2c_w2_buf(gspca_dev, mt9v112_init, ARRAY_SIZE(mt9v112_init));
12120c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0) {
12130c0d06caSMauro Carvalho Chehab 			pr_err("MT9V112 sensor initialization failed\n");
12140c0d06caSMauro Carvalho Chehab 			return;
12150c0d06caSMauro Carvalho Chehab 		}
12160c0d06caSMauro Carvalho Chehab 		sd->hstart = 6;
12170c0d06caSMauro Carvalho Chehab 		sd->vstart = 2;
12180c0d06caSMauro Carvalho Chehab 		sd->sensor = SENSOR_MT9V112;
12190c0d06caSMauro Carvalho Chehab 		pr_info("MT9V112 sensor detected\n");
12200c0d06caSMauro Carvalho Chehab 		return;
12210c0d06caSMauro Carvalho Chehab 	}
12220c0d06caSMauro Carvalho Chehab 
12230c0d06caSMauro Carvalho Chehab 	gspca_dev->usb_err = -ENODEV;
12240c0d06caSMauro Carvalho Chehab }
12250c0d06caSMauro Carvalho Chehab 
12260c0d06caSMauro Carvalho Chehab static void mt9m112_init_sensor(struct gspca_dev *gspca_dev)
12270c0d06caSMauro Carvalho Chehab {
12280c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
12290c0d06caSMauro Carvalho Chehab 
12300c0d06caSMauro Carvalho Chehab 	i2c_w2_buf(gspca_dev, mt9m112_init, ARRAY_SIZE(mt9m112_init));
12310c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
12320c0d06caSMauro Carvalho Chehab 		pr_err("MT9M112 sensor initialization failed\n");
12330c0d06caSMauro Carvalho Chehab 
12340c0d06caSMauro Carvalho Chehab 	sd->hstart = 0;
12350c0d06caSMauro Carvalho Chehab 	sd->vstart = 2;
12360c0d06caSMauro Carvalho Chehab }
12370c0d06caSMauro Carvalho Chehab 
12380c0d06caSMauro Carvalho Chehab static void mt9m111_init_sensor(struct gspca_dev *gspca_dev)
12390c0d06caSMauro Carvalho Chehab {
12400c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
12410c0d06caSMauro Carvalho Chehab 
12420c0d06caSMauro Carvalho Chehab 	i2c_w2_buf(gspca_dev, mt9m111_init, ARRAY_SIZE(mt9m111_init));
12430c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
12440c0d06caSMauro Carvalho Chehab 		pr_err("MT9M111 sensor initialization failed\n");
12450c0d06caSMauro Carvalho Chehab 
12460c0d06caSMauro Carvalho Chehab 	sd->hstart = 0;
12470c0d06caSMauro Carvalho Chehab 	sd->vstart = 2;
12480c0d06caSMauro Carvalho Chehab }
12490c0d06caSMauro Carvalho Chehab 
12500c0d06caSMauro Carvalho Chehab static void mt9m001_init_sensor(struct gspca_dev *gspca_dev)
12510c0d06caSMauro Carvalho Chehab {
12520c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
12530c0d06caSMauro Carvalho Chehab 	u16 id;
12540c0d06caSMauro Carvalho Chehab 
12550c0d06caSMauro Carvalho Chehab 	i2c_r2(gspca_dev, 0x00, &id);
12560c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
12570c0d06caSMauro Carvalho Chehab 		return;
12580c0d06caSMauro Carvalho Chehab 
12590c0d06caSMauro Carvalho Chehab 	/* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
12600c0d06caSMauro Carvalho Chehab 	switch (id) {
12610c0d06caSMauro Carvalho Chehab 	case 0x8411:
12620c0d06caSMauro Carvalho Chehab 	case 0x8421:
12630c0d06caSMauro Carvalho Chehab 		pr_info("MT9M001 color sensor detected\n");
12640c0d06caSMauro Carvalho Chehab 		break;
12650c0d06caSMauro Carvalho Chehab 	case 0x8431:
12660c0d06caSMauro Carvalho Chehab 		pr_info("MT9M001 mono sensor detected\n");
12670c0d06caSMauro Carvalho Chehab 		break;
12680c0d06caSMauro Carvalho Chehab 	default:
12690c0d06caSMauro Carvalho Chehab 		pr_err("No MT9M001 chip detected, ID = %x\n\n", id);
12700c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = -ENODEV;
12710c0d06caSMauro Carvalho Chehab 		return;
12720c0d06caSMauro Carvalho Chehab 	}
12730c0d06caSMauro Carvalho Chehab 
12740c0d06caSMauro Carvalho Chehab 	i2c_w2_buf(gspca_dev, mt9m001_init, ARRAY_SIZE(mt9m001_init));
12750c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
12760c0d06caSMauro Carvalho Chehab 		pr_err("MT9M001 sensor initialization failed\n");
12770c0d06caSMauro Carvalho Chehab 
12780c0d06caSMauro Carvalho Chehab 	sd->hstart = 1;
12790c0d06caSMauro Carvalho Chehab 	sd->vstart = 1;
12800c0d06caSMauro Carvalho Chehab }
12810c0d06caSMauro Carvalho Chehab 
12820c0d06caSMauro Carvalho Chehab static void hv7131r_init_sensor(struct gspca_dev *gspca_dev)
12830c0d06caSMauro Carvalho Chehab {
12840c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
12850c0d06caSMauro Carvalho Chehab 
12860c0d06caSMauro Carvalho Chehab 	i2c_w1_buf(gspca_dev, hv7131r_init, ARRAY_SIZE(hv7131r_init));
12870c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0)
12880c0d06caSMauro Carvalho Chehab 		pr_err("HV7131R Sensor initialization failed\n");
12890c0d06caSMauro Carvalho Chehab 
12900c0d06caSMauro Carvalho Chehab 	sd->hstart = 0;
12910c0d06caSMauro Carvalho Chehab 	sd->vstart = 1;
12920c0d06caSMauro Carvalho Chehab }
12930c0d06caSMauro Carvalho Chehab 
12940c0d06caSMauro Carvalho Chehab static void set_cmatrix(struct gspca_dev *gspca_dev,
12950c0d06caSMauro Carvalho Chehab 		s32 brightness, s32 contrast, s32 satur, s32 hue)
12960c0d06caSMauro Carvalho Chehab {
12970c0d06caSMauro Carvalho Chehab 	s32 hue_coord, hue_index = 180 + hue;
12980c0d06caSMauro Carvalho Chehab 	u8 cmatrix[21];
12990c0d06caSMauro Carvalho Chehab 
13000c0d06caSMauro Carvalho Chehab 	memset(cmatrix, 0, sizeof cmatrix);
13010c0d06caSMauro Carvalho Chehab 	cmatrix[2] = (contrast * 0x25 / 0x100) + 0x26;
13020c0d06caSMauro Carvalho Chehab 	cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25;
13030c0d06caSMauro Carvalho Chehab 	cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25;
13040c0d06caSMauro Carvalho Chehab 	cmatrix[18] = brightness - 0x80;
13050c0d06caSMauro Carvalho Chehab 
13060c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_red_x[hue_index] * satur) >> 8;
13070c0d06caSMauro Carvalho Chehab 	cmatrix[6] = hue_coord;
13080c0d06caSMauro Carvalho Chehab 	cmatrix[7] = (hue_coord >> 8) & 0x0f;
13090c0d06caSMauro Carvalho Chehab 
13100c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_red_y[hue_index] * satur) >> 8;
13110c0d06caSMauro Carvalho Chehab 	cmatrix[8] = hue_coord;
13120c0d06caSMauro Carvalho Chehab 	cmatrix[9] = (hue_coord >> 8) & 0x0f;
13130c0d06caSMauro Carvalho Chehab 
13140c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_green_x[hue_index] * satur) >> 8;
13150c0d06caSMauro Carvalho Chehab 	cmatrix[10] = hue_coord;
13160c0d06caSMauro Carvalho Chehab 	cmatrix[11] = (hue_coord >> 8) & 0x0f;
13170c0d06caSMauro Carvalho Chehab 
13180c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_green_y[hue_index] * satur) >> 8;
13190c0d06caSMauro Carvalho Chehab 	cmatrix[12] = hue_coord;
13200c0d06caSMauro Carvalho Chehab 	cmatrix[13] = (hue_coord >> 8) & 0x0f;
13210c0d06caSMauro Carvalho Chehab 
13220c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_blue_x[hue_index] * satur) >> 8;
13230c0d06caSMauro Carvalho Chehab 	cmatrix[14] = hue_coord;
13240c0d06caSMauro Carvalho Chehab 	cmatrix[15] = (hue_coord >> 8) & 0x0f;
13250c0d06caSMauro Carvalho Chehab 
13260c0d06caSMauro Carvalho Chehab 	hue_coord = (hsv_blue_y[hue_index] * satur) >> 8;
13270c0d06caSMauro Carvalho Chehab 	cmatrix[16] = hue_coord;
13280c0d06caSMauro Carvalho Chehab 	cmatrix[17] = (hue_coord >> 8) & 0x0f;
13290c0d06caSMauro Carvalho Chehab 
13300c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x10e1, cmatrix, 21);
13310c0d06caSMauro Carvalho Chehab }
13320c0d06caSMauro Carvalho Chehab 
13330c0d06caSMauro Carvalho Chehab static void set_gamma(struct gspca_dev *gspca_dev, s32 val)
13340c0d06caSMauro Carvalho Chehab {
13350c0d06caSMauro Carvalho Chehab 	u8 gamma[17];
13360c0d06caSMauro Carvalho Chehab 	u8 gval = val * 0xb8 / 0x100;
13370c0d06caSMauro Carvalho Chehab 
13380c0d06caSMauro Carvalho Chehab 	gamma[0] = 0x0a;
13390c0d06caSMauro Carvalho Chehab 	gamma[1] = 0x13 + (gval * (0xcb - 0x13) / 0xb8);
13400c0d06caSMauro Carvalho Chehab 	gamma[2] = 0x25 + (gval * (0xee - 0x25) / 0xb8);
13410c0d06caSMauro Carvalho Chehab 	gamma[3] = 0x37 + (gval * (0xfa - 0x37) / 0xb8);
13420c0d06caSMauro Carvalho Chehab 	gamma[4] = 0x45 + (gval * (0xfc - 0x45) / 0xb8);
13430c0d06caSMauro Carvalho Chehab 	gamma[5] = 0x55 + (gval * (0xfb - 0x55) / 0xb8);
13440c0d06caSMauro Carvalho Chehab 	gamma[6] = 0x65 + (gval * (0xfc - 0x65) / 0xb8);
13450c0d06caSMauro Carvalho Chehab 	gamma[7] = 0x74 + (gval * (0xfd - 0x74) / 0xb8);
13460c0d06caSMauro Carvalho Chehab 	gamma[8] = 0x83 + (gval * (0xfe - 0x83) / 0xb8);
13470c0d06caSMauro Carvalho Chehab 	gamma[9] = 0x92 + (gval * (0xfc - 0x92) / 0xb8);
13480c0d06caSMauro Carvalho Chehab 	gamma[10] = 0xa1 + (gval * (0xfc - 0xa1) / 0xb8);
13490c0d06caSMauro Carvalho Chehab 	gamma[11] = 0xb0 + (gval * (0xfc - 0xb0) / 0xb8);
13500c0d06caSMauro Carvalho Chehab 	gamma[12] = 0xbf + (gval * (0xfb - 0xbf) / 0xb8);
13510c0d06caSMauro Carvalho Chehab 	gamma[13] = 0xce + (gval * (0xfb - 0xce) / 0xb8);
13520c0d06caSMauro Carvalho Chehab 	gamma[14] = 0xdf + (gval * (0xfd - 0xdf) / 0xb8);
13530c0d06caSMauro Carvalho Chehab 	gamma[15] = 0xea + (gval * (0xf9 - 0xea) / 0xb8);
13540c0d06caSMauro Carvalho Chehab 	gamma[16] = 0xf5;
13550c0d06caSMauro Carvalho Chehab 
13560c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1190, gamma, 17);
13570c0d06caSMauro Carvalho Chehab }
13580c0d06caSMauro Carvalho Chehab 
13590c0d06caSMauro Carvalho Chehab static void set_redblue(struct gspca_dev *gspca_dev, s32 blue, s32 red)
13600c0d06caSMauro Carvalho Chehab {
13610c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x118c, red);
13620c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x118f, blue);
13630c0d06caSMauro Carvalho Chehab }
13640c0d06caSMauro Carvalho Chehab 
13650c0d06caSMauro Carvalho Chehab static void set_hvflip(struct gspca_dev *gspca_dev, s32 hflip, s32 vflip)
13660c0d06caSMauro Carvalho Chehab {
13670c0d06caSMauro Carvalho Chehab 	u8 value, tslb;
13680c0d06caSMauro Carvalho Chehab 	u16 value2;
13690c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
13700c0d06caSMauro Carvalho Chehab 
13710c0d06caSMauro Carvalho Chehab 	if ((sd->flags & FLIP_DETECT) && dmi_check_system(flip_dmi_table)) {
13720c0d06caSMauro Carvalho Chehab 		hflip = !hflip;
13730c0d06caSMauro Carvalho Chehab 		vflip = !vflip;
13740c0d06caSMauro Carvalho Chehab 	}
13750c0d06caSMauro Carvalho Chehab 
13760c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
13770c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7660:
13780c0d06caSMauro Carvalho Chehab 		value = 0x01;
13790c0d06caSMauro Carvalho Chehab 		if (hflip)
13800c0d06caSMauro Carvalho Chehab 			value |= 0x20;
13810c0d06caSMauro Carvalho Chehab 		if (vflip) {
13820c0d06caSMauro Carvalho Chehab 			value |= 0x10;
13830c0d06caSMauro Carvalho Chehab 			sd->vstart = 2;
13840c0d06caSMauro Carvalho Chehab 		} else {
13850c0d06caSMauro Carvalho Chehab 			sd->vstart = 3;
13860c0d06caSMauro Carvalho Chehab 		}
13870c0d06caSMauro Carvalho Chehab 		reg_w1(gspca_dev, 0x1182, sd->vstart);
13880c0d06caSMauro Carvalho Chehab 		i2c_w1(gspca_dev, 0x1e, value);
13890c0d06caSMauro Carvalho Chehab 		break;
13900c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
13910c0d06caSMauro Carvalho Chehab 		i2c_r1(gspca_dev, 0x1e, &value);
13920c0d06caSMauro Carvalho Chehab 		value &= ~0x30;
13930c0d06caSMauro Carvalho Chehab 		tslb = 0x01;
13940c0d06caSMauro Carvalho Chehab 		if (hflip)
13950c0d06caSMauro Carvalho Chehab 			value |= 0x20;
13960c0d06caSMauro Carvalho Chehab 		if (vflip) {
13970c0d06caSMauro Carvalho Chehab 			value |= 0x10;
13980c0d06caSMauro Carvalho Chehab 			tslb = 0x49;
13990c0d06caSMauro Carvalho Chehab 		}
14000c0d06caSMauro Carvalho Chehab 		i2c_w1(gspca_dev, 0x1e, value);
14010c0d06caSMauro Carvalho Chehab 		i2c_w1(gspca_dev, 0x3a, tslb);
14020c0d06caSMauro Carvalho Chehab 		break;
14030c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V111:
14040c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V011:
14050c0d06caSMauro Carvalho Chehab 		i2c_r2(gspca_dev, 0x20, &value2);
14060c0d06caSMauro Carvalho Chehab 		value2 &= ~0xc0a0;
14070c0d06caSMauro Carvalho Chehab 		if (hflip)
14080c0d06caSMauro Carvalho Chehab 			value2 |= 0x8080;
14090c0d06caSMauro Carvalho Chehab 		if (vflip)
14100c0d06caSMauro Carvalho Chehab 			value2 |= 0x4020;
14110c0d06caSMauro Carvalho Chehab 		i2c_w2(gspca_dev, 0x20, value2);
14120c0d06caSMauro Carvalho Chehab 		break;
14130c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M112:
14140c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M111:
14150c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V112:
14160c0d06caSMauro Carvalho Chehab 		i2c_r2(gspca_dev, 0x20, &value2);
14170c0d06caSMauro Carvalho Chehab 		value2 &= ~0x0003;
14180c0d06caSMauro Carvalho Chehab 		if (hflip)
14190c0d06caSMauro Carvalho Chehab 			value2 |= 0x0002;
14200c0d06caSMauro Carvalho Chehab 		if (vflip)
14210c0d06caSMauro Carvalho Chehab 			value2 |= 0x0001;
14220c0d06caSMauro Carvalho Chehab 		i2c_w2(gspca_dev, 0x20, value2);
14230c0d06caSMauro Carvalho Chehab 		break;
14240c0d06caSMauro Carvalho Chehab 	case SENSOR_HV7131R:
14250c0d06caSMauro Carvalho Chehab 		i2c_r1(gspca_dev, 0x01, &value);
14260c0d06caSMauro Carvalho Chehab 		value &= ~0x03;
14270c0d06caSMauro Carvalho Chehab 		if (vflip)
14280c0d06caSMauro Carvalho Chehab 			value |= 0x01;
14290c0d06caSMauro Carvalho Chehab 		if (hflip)
14300c0d06caSMauro Carvalho Chehab 			value |= 0x02;
14310c0d06caSMauro Carvalho Chehab 		i2c_w1(gspca_dev, 0x01, value);
14320c0d06caSMauro Carvalho Chehab 		break;
14330c0d06caSMauro Carvalho Chehab 	}
14340c0d06caSMauro Carvalho Chehab }
14350c0d06caSMauro Carvalho Chehab 
14360c0d06caSMauro Carvalho Chehab static void set_exposure(struct gspca_dev *gspca_dev, s32 expo)
14370c0d06caSMauro Carvalho Chehab {
14380c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
14390c0d06caSMauro Carvalho Chehab 	u8 exp[8] = {sd->i2c_intf, sd->i2c_addr,
14400c0d06caSMauro Carvalho Chehab 				0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
14410c0d06caSMauro Carvalho Chehab 	int expo2;
14420c0d06caSMauro Carvalho Chehab 
14430c0d06caSMauro Carvalho Chehab 	if (gspca_dev->streaming)
14440c0d06caSMauro Carvalho Chehab 		exp[7] = 0x1e;
14450c0d06caSMauro Carvalho Chehab 
14460c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
14470c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7660:
14480c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7670:
14490c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9655:
14500c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
14510c0d06caSMauro Carvalho Chehab 		if (expo > 547)
14520c0d06caSMauro Carvalho Chehab 			expo2 = 547;
14530c0d06caSMauro Carvalho Chehab 		else
14540c0d06caSMauro Carvalho Chehab 			expo2 = expo;
14550c0d06caSMauro Carvalho Chehab 		exp[0] |= (2 << 4);
14560c0d06caSMauro Carvalho Chehab 		exp[2] = 0x10;			/* AECH */
14570c0d06caSMauro Carvalho Chehab 		exp[3] = expo2 >> 2;
14580c0d06caSMauro Carvalho Chehab 		exp[7] = 0x10;
14590c0d06caSMauro Carvalho Chehab 		i2c_w(gspca_dev, exp);
14600c0d06caSMauro Carvalho Chehab 		exp[2] = 0x04;			/* COM1 */
14610c0d06caSMauro Carvalho Chehab 		exp[3] = expo2 & 0x0003;
14620c0d06caSMauro Carvalho Chehab 		exp[7] = 0x10;
14630c0d06caSMauro Carvalho Chehab 		i2c_w(gspca_dev, exp);
14640c0d06caSMauro Carvalho Chehab 		expo -= expo2;
14650c0d06caSMauro Carvalho Chehab 		exp[7] = 0x1e;
14660c0d06caSMauro Carvalho Chehab 		exp[0] |= (3 << 4);
14670c0d06caSMauro Carvalho Chehab 		exp[2] = 0x2d;			/* ADVFL & ADVFH */
14680c0d06caSMauro Carvalho Chehab 		exp[3] = expo;
14690c0d06caSMauro Carvalho Chehab 		exp[4] = expo >> 8;
14700c0d06caSMauro Carvalho Chehab 		break;
14710c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M001:
14720c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V112:
14730c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V011:
14740c0d06caSMauro Carvalho Chehab 		exp[0] |= (3 << 4);
14750c0d06caSMauro Carvalho Chehab 		exp[2] = 0x09;
14760c0d06caSMauro Carvalho Chehab 		exp[3] = expo >> 8;
14770c0d06caSMauro Carvalho Chehab 		exp[4] = expo;
14780c0d06caSMauro Carvalho Chehab 		break;
14790c0d06caSMauro Carvalho Chehab 	case SENSOR_HV7131R:
14800c0d06caSMauro Carvalho Chehab 		exp[0] |= (4 << 4);
14810c0d06caSMauro Carvalho Chehab 		exp[2] = 0x25;
14820c0d06caSMauro Carvalho Chehab 		exp[3] = expo >> 5;
14830c0d06caSMauro Carvalho Chehab 		exp[4] = expo << 3;
14840c0d06caSMauro Carvalho Chehab 		exp[5] = 0;
14850c0d06caSMauro Carvalho Chehab 		break;
14860c0d06caSMauro Carvalho Chehab 	default:
14870c0d06caSMauro Carvalho Chehab 		return;
14880c0d06caSMauro Carvalho Chehab 	}
14890c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, exp);
14900c0d06caSMauro Carvalho Chehab }
14910c0d06caSMauro Carvalho Chehab 
14920c0d06caSMauro Carvalho Chehab static void set_gain(struct gspca_dev *gspca_dev, s32 g)
14930c0d06caSMauro Carvalho Chehab {
14940c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
14950c0d06caSMauro Carvalho Chehab 	u8 gain[8] = {sd->i2c_intf, sd->i2c_addr,
14960c0d06caSMauro Carvalho Chehab 				0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
14970c0d06caSMauro Carvalho Chehab 
14980c0d06caSMauro Carvalho Chehab 	if (gspca_dev->streaming)
14990c0d06caSMauro Carvalho Chehab 		gain[7] = 0x15;		/* or 1d ? */
15000c0d06caSMauro Carvalho Chehab 
15010c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
15020c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7660:
15030c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7670:
15040c0d06caSMauro Carvalho Chehab 	case SENSOR_SOI968:
15050c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9655:
15060c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
15070c0d06caSMauro Carvalho Chehab 		gain[0] |= (2 << 4);
15080c0d06caSMauro Carvalho Chehab 		gain[3] = ov_gain[g];
15090c0d06caSMauro Carvalho Chehab 		break;
15100c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V011:
15110c0d06caSMauro Carvalho Chehab 		gain[0] |= (3 << 4);
15120c0d06caSMauro Carvalho Chehab 		gain[2] = 0x35;
15130c0d06caSMauro Carvalho Chehab 		gain[3] = micron1_gain[g] >> 8;
15140c0d06caSMauro Carvalho Chehab 		gain[4] = micron1_gain[g];
15150c0d06caSMauro Carvalho Chehab 		break;
15160c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9V112:
15170c0d06caSMauro Carvalho Chehab 		gain[0] |= (3 << 4);
15180c0d06caSMauro Carvalho Chehab 		gain[2] = 0x2f;
15190c0d06caSMauro Carvalho Chehab 		gain[3] = micron1_gain[g] >> 8;
15200c0d06caSMauro Carvalho Chehab 		gain[4] = micron1_gain[g];
15210c0d06caSMauro Carvalho Chehab 		break;
15220c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M001:
15230c0d06caSMauro Carvalho Chehab 		gain[0] |= (3 << 4);
15240c0d06caSMauro Carvalho Chehab 		gain[2] = 0x2f;
15250c0d06caSMauro Carvalho Chehab 		gain[3] = micron2_gain[g] >> 8;
15260c0d06caSMauro Carvalho Chehab 		gain[4] = micron2_gain[g];
15270c0d06caSMauro Carvalho Chehab 		break;
15280c0d06caSMauro Carvalho Chehab 	case SENSOR_HV7131R:
15290c0d06caSMauro Carvalho Chehab 		gain[0] |= (2 << 4);
15300c0d06caSMauro Carvalho Chehab 		gain[2] = 0x30;
15310c0d06caSMauro Carvalho Chehab 		gain[3] = hv7131r_gain[g];
15320c0d06caSMauro Carvalho Chehab 		break;
15330c0d06caSMauro Carvalho Chehab 	default:
15340c0d06caSMauro Carvalho Chehab 		return;
15350c0d06caSMauro Carvalho Chehab 	}
15360c0d06caSMauro Carvalho Chehab 	i2c_w(gspca_dev, gain);
15370c0d06caSMauro Carvalho Chehab }
15380c0d06caSMauro Carvalho Chehab 
15390c0d06caSMauro Carvalho Chehab static void set_quality(struct gspca_dev *gspca_dev, s32 val)
15400c0d06caSMauro Carvalho Chehab {
15410c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
15420c0d06caSMauro Carvalho Chehab 
15430c0d06caSMauro Carvalho Chehab 	jpeg_set_qual(sd->jpeg_hdr, val);
15440c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1061, 0x01);	/* stop transfer */
15450c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x10e0, sd->fmt | 0x20); /* write QTAB */
15460c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1100, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
15470c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1140, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
15480c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1061, 0x03);	/* restart transfer */
15490c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x10e0, sd->fmt);
15500c0d06caSMauro Carvalho Chehab 	sd->fmt ^= 0x0c;			/* invert QTAB use + write */
15510c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x10e0, sd->fmt);
15520c0d06caSMauro Carvalho Chehab }
15530c0d06caSMauro Carvalho Chehab 
15540c0d06caSMauro Carvalho Chehab #ifdef CONFIG_VIDEO_ADV_DEBUG
15550c0d06caSMauro Carvalho Chehab static int sd_dbg_g_register(struct gspca_dev *gspca_dev,
15560c0d06caSMauro Carvalho Chehab 			struct v4l2_dbg_register *reg)
15570c0d06caSMauro Carvalho Chehab {
15580c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
15590c0d06caSMauro Carvalho Chehab 
1560f82fadcfSHans Verkuil 	reg->size = 1;
1561b1c85cc0SHans Verkuil 	switch (reg->match.addr) {
1562b1c85cc0SHans Verkuil 	case 0:
15630c0d06caSMauro Carvalho Chehab 		if (reg->reg < 0x1000 || reg->reg > 0x11ff)
15640c0d06caSMauro Carvalho Chehab 			return -EINVAL;
15650c0d06caSMauro Carvalho Chehab 		reg_r(gspca_dev, reg->reg, 1);
15660c0d06caSMauro Carvalho Chehab 		reg->val = gspca_dev->usb_buf[0];
15670c0d06caSMauro Carvalho Chehab 		return gspca_dev->usb_err;
1568b1c85cc0SHans Verkuil 	case 1:
15690c0d06caSMauro Carvalho Chehab 		if (sd->sensor >= SENSOR_MT9V011 &&
15700c0d06caSMauro Carvalho Chehab 		    sd->sensor <= SENSOR_MT9M112) {
15710c0d06caSMauro Carvalho Chehab 			i2c_r2(gspca_dev, reg->reg, (u16 *) &reg->val);
1572f82fadcfSHans Verkuil 			reg->size = 2;
15730c0d06caSMauro Carvalho Chehab 		} else {
15740c0d06caSMauro Carvalho Chehab 			i2c_r1(gspca_dev, reg->reg, (u8 *) &reg->val);
15750c0d06caSMauro Carvalho Chehab 		}
15760c0d06caSMauro Carvalho Chehab 		return gspca_dev->usb_err;
15770c0d06caSMauro Carvalho Chehab 	}
15780c0d06caSMauro Carvalho Chehab 	return -EINVAL;
15790c0d06caSMauro Carvalho Chehab }
15800c0d06caSMauro Carvalho Chehab 
15810c0d06caSMauro Carvalho Chehab static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1582977ba3b1SHans Verkuil 			const struct v4l2_dbg_register *reg)
15830c0d06caSMauro Carvalho Chehab {
15840c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
15850c0d06caSMauro Carvalho Chehab 
1586b1c85cc0SHans Verkuil 	switch (reg->match.addr) {
1587b1c85cc0SHans Verkuil 	case 0:
15880c0d06caSMauro Carvalho Chehab 		if (reg->reg < 0x1000 || reg->reg > 0x11ff)
15890c0d06caSMauro Carvalho Chehab 			return -EINVAL;
15900c0d06caSMauro Carvalho Chehab 		reg_w1(gspca_dev, reg->reg, reg->val);
15910c0d06caSMauro Carvalho Chehab 		return gspca_dev->usb_err;
1592b1c85cc0SHans Verkuil 	case 1:
15930c0d06caSMauro Carvalho Chehab 		if (sd->sensor >= SENSOR_MT9V011 &&
15940c0d06caSMauro Carvalho Chehab 		    sd->sensor <= SENSOR_MT9M112) {
15950c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, reg->reg, reg->val);
15960c0d06caSMauro Carvalho Chehab 		} else {
15970c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, reg->reg, reg->val);
15980c0d06caSMauro Carvalho Chehab 		}
15990c0d06caSMauro Carvalho Chehab 		return gspca_dev->usb_err;
16000c0d06caSMauro Carvalho Chehab 	}
16010c0d06caSMauro Carvalho Chehab 	return -EINVAL;
16020c0d06caSMauro Carvalho Chehab }
16030c0d06caSMauro Carvalho Chehab 
1604b1c85cc0SHans Verkuil static int sd_chip_info(struct gspca_dev *gspca_dev,
1605b1c85cc0SHans Verkuil 			struct v4l2_dbg_chip_info *chip)
16060c0d06caSMauro Carvalho Chehab {
1607b1c85cc0SHans Verkuil 	if (chip->match.addr > 1)
16080c0d06caSMauro Carvalho Chehab 		return -EINVAL;
1609b1c85cc0SHans Verkuil 	if (chip->match.addr == 1)
1610b1c85cc0SHans Verkuil 		strlcpy(chip->name, "sensor", sizeof(chip->name));
16110c0d06caSMauro Carvalho Chehab 	return 0;
16120c0d06caSMauro Carvalho Chehab }
1613b1c85cc0SHans Verkuil #endif
16140c0d06caSMauro Carvalho Chehab 
16150c0d06caSMauro Carvalho Chehab static int sd_config(struct gspca_dev *gspca_dev,
16160c0d06caSMauro Carvalho Chehab 			const struct usb_device_id *id)
16170c0d06caSMauro Carvalho Chehab {
16180c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
16190c0d06caSMauro Carvalho Chehab 	struct cam *cam;
16200c0d06caSMauro Carvalho Chehab 
16210c0d06caSMauro Carvalho Chehab 	cam = &gspca_dev->cam;
16220c0d06caSMauro Carvalho Chehab 	cam->needs_full_bandwidth = 1;
16230c0d06caSMauro Carvalho Chehab 
16240c0d06caSMauro Carvalho Chehab 	sd->sensor = id->driver_info >> 8;
16250c0d06caSMauro Carvalho Chehab 	sd->i2c_addr = id->driver_info;
16260c0d06caSMauro Carvalho Chehab 	sd->flags = id->driver_info >> 16;
16270c0d06caSMauro Carvalho Chehab 	sd->i2c_intf = 0x80;			/* i2c 100 Kb/s */
16280c0d06caSMauro Carvalho Chehab 
16290c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
16300c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M112:
16310c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M111:
16320c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
16330c0d06caSMauro Carvalho Chehab 	case SENSOR_SOI968:
16340c0d06caSMauro Carvalho Chehab 		cam->cam_mode = sxga_mode;
16350c0d06caSMauro Carvalho Chehab 		cam->nmodes = ARRAY_SIZE(sxga_mode);
16360c0d06caSMauro Carvalho Chehab 		break;
16370c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M001:
16380c0d06caSMauro Carvalho Chehab 		cam->cam_mode = mono_mode;
16390c0d06caSMauro Carvalho Chehab 		cam->nmodes = ARRAY_SIZE(mono_mode);
16400c0d06caSMauro Carvalho Chehab 		break;
16410c0d06caSMauro Carvalho Chehab 	case SENSOR_HV7131R:
16420c0d06caSMauro Carvalho Chehab 		sd->i2c_intf = 0x81;			/* i2c 400 Kb/s */
16430c0d06caSMauro Carvalho Chehab 		/* fall thru */
16440c0d06caSMauro Carvalho Chehab 	default:
16450c0d06caSMauro Carvalho Chehab 		cam->cam_mode = vga_mode;
16460c0d06caSMauro Carvalho Chehab 		cam->nmodes = ARRAY_SIZE(vga_mode);
16470c0d06caSMauro Carvalho Chehab 		break;
16480c0d06caSMauro Carvalho Chehab 	}
16490c0d06caSMauro Carvalho Chehab 
16500c0d06caSMauro Carvalho Chehab 	sd->old_step = 0;
16510c0d06caSMauro Carvalho Chehab 	sd->older_step = 0;
16520c0d06caSMauro Carvalho Chehab 	sd->exposure_step = 16;
16530c0d06caSMauro Carvalho Chehab 
16540c0d06caSMauro Carvalho Chehab 	INIT_WORK(&sd->work, qual_upd);
16550c0d06caSMauro Carvalho Chehab 
16560c0d06caSMauro Carvalho Chehab 	return 0;
16570c0d06caSMauro Carvalho Chehab }
16580c0d06caSMauro Carvalho Chehab 
16590c0d06caSMauro Carvalho Chehab static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
16600c0d06caSMauro Carvalho Chehab {
16610c0d06caSMauro Carvalho Chehab 	struct gspca_dev *gspca_dev =
16620c0d06caSMauro Carvalho Chehab 		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
16630c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *)gspca_dev;
16640c0d06caSMauro Carvalho Chehab 
16650c0d06caSMauro Carvalho Chehab 	gspca_dev->usb_err = 0;
16660c0d06caSMauro Carvalho Chehab 
16670c0d06caSMauro Carvalho Chehab 	if (!gspca_dev->streaming)
16680c0d06caSMauro Carvalho Chehab 		return 0;
16690c0d06caSMauro Carvalho Chehab 
16700c0d06caSMauro Carvalho Chehab 	switch (ctrl->id) {
16710c0d06caSMauro Carvalho Chehab 	/* color control cluster */
16720c0d06caSMauro Carvalho Chehab 	case V4L2_CID_BRIGHTNESS:
16730c0d06caSMauro Carvalho Chehab 		set_cmatrix(gspca_dev, sd->brightness->val,
16740c0d06caSMauro Carvalho Chehab 			sd->contrast->val, sd->saturation->val, sd->hue->val);
16750c0d06caSMauro Carvalho Chehab 		break;
16760c0d06caSMauro Carvalho Chehab 	case V4L2_CID_GAMMA:
16770c0d06caSMauro Carvalho Chehab 		set_gamma(gspca_dev, ctrl->val);
16780c0d06caSMauro Carvalho Chehab 		break;
16790c0d06caSMauro Carvalho Chehab 	/* blue/red balance cluster */
16800c0d06caSMauro Carvalho Chehab 	case V4L2_CID_BLUE_BALANCE:
16810c0d06caSMauro Carvalho Chehab 		set_redblue(gspca_dev, sd->blue->val, sd->red->val);
16820c0d06caSMauro Carvalho Chehab 		break;
16830c0d06caSMauro Carvalho Chehab 	/* h/vflip cluster */
16840c0d06caSMauro Carvalho Chehab 	case V4L2_CID_HFLIP:
16850c0d06caSMauro Carvalho Chehab 		set_hvflip(gspca_dev, sd->hflip->val, sd->vflip->val);
16860c0d06caSMauro Carvalho Chehab 		break;
16870c0d06caSMauro Carvalho Chehab 	/* standalone exposure control */
16880c0d06caSMauro Carvalho Chehab 	case V4L2_CID_EXPOSURE:
16890c0d06caSMauro Carvalho Chehab 		set_exposure(gspca_dev, ctrl->val);
16900c0d06caSMauro Carvalho Chehab 		break;
16910c0d06caSMauro Carvalho Chehab 	/* standalone gain control */
16920c0d06caSMauro Carvalho Chehab 	case V4L2_CID_GAIN:
16930c0d06caSMauro Carvalho Chehab 		set_gain(gspca_dev, ctrl->val);
16940c0d06caSMauro Carvalho Chehab 		break;
16950c0d06caSMauro Carvalho Chehab 	/* autogain + exposure or gain control cluster */
16960c0d06caSMauro Carvalho Chehab 	case V4L2_CID_AUTOGAIN:
16970c0d06caSMauro Carvalho Chehab 		if (sd->sensor == SENSOR_SOI968)
16980c0d06caSMauro Carvalho Chehab 			set_gain(gspca_dev, sd->gain->val);
16990c0d06caSMauro Carvalho Chehab 		else
17000c0d06caSMauro Carvalho Chehab 			set_exposure(gspca_dev, sd->exposure->val);
17010c0d06caSMauro Carvalho Chehab 		break;
17020c0d06caSMauro Carvalho Chehab 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:
17030c0d06caSMauro Carvalho Chehab 		set_quality(gspca_dev, ctrl->val);
17040c0d06caSMauro Carvalho Chehab 		break;
17050c0d06caSMauro Carvalho Chehab 	}
17060c0d06caSMauro Carvalho Chehab 	return gspca_dev->usb_err;
17070c0d06caSMauro Carvalho Chehab }
17080c0d06caSMauro Carvalho Chehab 
17090c0d06caSMauro Carvalho Chehab static const struct v4l2_ctrl_ops sd_ctrl_ops = {
17100c0d06caSMauro Carvalho Chehab 	.s_ctrl = sd_s_ctrl,
17110c0d06caSMauro Carvalho Chehab };
17120c0d06caSMauro Carvalho Chehab 
17130c0d06caSMauro Carvalho Chehab static int sd_init_controls(struct gspca_dev *gspca_dev)
17140c0d06caSMauro Carvalho Chehab {
17150c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
17160c0d06caSMauro Carvalho Chehab 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
17170c0d06caSMauro Carvalho Chehab 
17180c0d06caSMauro Carvalho Chehab 	gspca_dev->vdev.ctrl_handler = hdl;
17190c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_handler_init(hdl, 13);
17200c0d06caSMauro Carvalho Chehab 
17210c0d06caSMauro Carvalho Chehab 	sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17220c0d06caSMauro Carvalho Chehab 			V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
17230c0d06caSMauro Carvalho Chehab 	sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17240c0d06caSMauro Carvalho Chehab 			V4L2_CID_CONTRAST, 0, 255, 1, 127);
17250c0d06caSMauro Carvalho Chehab 	sd->saturation = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17260c0d06caSMauro Carvalho Chehab 			V4L2_CID_SATURATION, 0, 255, 1, 127);
17270c0d06caSMauro Carvalho Chehab 	sd->hue = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17280c0d06caSMauro Carvalho Chehab 			V4L2_CID_HUE, -180, 180, 1, 0);
17290c0d06caSMauro Carvalho Chehab 
17300c0d06caSMauro Carvalho Chehab 	sd->gamma = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17310c0d06caSMauro Carvalho Chehab 			V4L2_CID_GAMMA, 0, 255, 1, 0x10);
17320c0d06caSMauro Carvalho Chehab 
17330c0d06caSMauro Carvalho Chehab 	sd->blue = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17340c0d06caSMauro Carvalho Chehab 			V4L2_CID_BLUE_BALANCE, 0, 127, 1, 0x28);
17350c0d06caSMauro Carvalho Chehab 	sd->red = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17360c0d06caSMauro Carvalho Chehab 			V4L2_CID_RED_BALANCE, 0, 127, 1, 0x28);
17370c0d06caSMauro Carvalho Chehab 
17380c0d06caSMauro Carvalho Chehab 	if (sd->sensor != SENSOR_OV9655 && sd->sensor != SENSOR_SOI968 &&
17390c0d06caSMauro Carvalho Chehab 	    sd->sensor != SENSOR_OV7670 && sd->sensor != SENSOR_MT9M001 &&
17400c0d06caSMauro Carvalho Chehab 	    sd->sensor != SENSOR_MT9VPRB) {
17410c0d06caSMauro Carvalho Chehab 		sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17420c0d06caSMauro Carvalho Chehab 			V4L2_CID_HFLIP, 0, 1, 1, 0);
17430c0d06caSMauro Carvalho Chehab 		sd->vflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17440c0d06caSMauro Carvalho Chehab 			V4L2_CID_VFLIP, 0, 1, 1, 0);
17450c0d06caSMauro Carvalho Chehab 	}
17460c0d06caSMauro Carvalho Chehab 
17470c0d06caSMauro Carvalho Chehab 	if (sd->sensor != SENSOR_SOI968 && sd->sensor != SENSOR_MT9VPRB &&
17480c0d06caSMauro Carvalho Chehab 	    sd->sensor != SENSOR_MT9M112 && sd->sensor != SENSOR_MT9M111 &&
17490c0d06caSMauro Carvalho Chehab 	    sd->sensor != SENSOR_MT9V111)
17500c0d06caSMauro Carvalho Chehab 		sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17510c0d06caSMauro Carvalho Chehab 			V4L2_CID_EXPOSURE, 0, 0x1780, 1, 0x33);
17520c0d06caSMauro Carvalho Chehab 
17530c0d06caSMauro Carvalho Chehab 	if (sd->sensor != SENSOR_MT9VPRB && sd->sensor != SENSOR_MT9M112 &&
17540c0d06caSMauro Carvalho Chehab 	    sd->sensor != SENSOR_MT9M111 && sd->sensor != SENSOR_MT9V111) {
17550c0d06caSMauro Carvalho Chehab 		sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17560c0d06caSMauro Carvalho Chehab 			V4L2_CID_GAIN, 0, 28, 1, 0);
17570c0d06caSMauro Carvalho Chehab 		sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17580c0d06caSMauro Carvalho Chehab 			V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
17590c0d06caSMauro Carvalho Chehab 	}
17600c0d06caSMauro Carvalho Chehab 
17610c0d06caSMauro Carvalho Chehab 	sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
17620c0d06caSMauro Carvalho Chehab 			V4L2_CID_JPEG_COMPRESSION_QUALITY, 50, 90, 1, 80);
17630c0d06caSMauro Carvalho Chehab 	if (hdl->error) {
17640c0d06caSMauro Carvalho Chehab 		pr_err("Could not initialize controls\n");
17650c0d06caSMauro Carvalho Chehab 		return hdl->error;
17660c0d06caSMauro Carvalho Chehab 	}
17670c0d06caSMauro Carvalho Chehab 
17680c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_cluster(4, &sd->brightness);
17690c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_cluster(2, &sd->blue);
17700c0d06caSMauro Carvalho Chehab 	if (sd->hflip)
17710c0d06caSMauro Carvalho Chehab 		v4l2_ctrl_cluster(2, &sd->hflip);
17720c0d06caSMauro Carvalho Chehab 	if (sd->autogain) {
17730c0d06caSMauro Carvalho Chehab 		if (sd->sensor == SENSOR_SOI968)
17740c0d06caSMauro Carvalho Chehab 			/* this sensor doesn't have the exposure control and
17750c0d06caSMauro Carvalho Chehab 			   autogain is clustered with gain instead. This works
17760c0d06caSMauro Carvalho Chehab 			   because sd->exposure == NULL. */
17770c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_auto_cluster(3, &sd->autogain, 0, false);
17780c0d06caSMauro Carvalho Chehab 		else
17790c0d06caSMauro Carvalho Chehab 			/* Otherwise autogain is clustered with exposure. */
17800c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_auto_cluster(2, &sd->autogain, 0, false);
17810c0d06caSMauro Carvalho Chehab 	}
17820c0d06caSMauro Carvalho Chehab 	return 0;
17830c0d06caSMauro Carvalho Chehab }
17840c0d06caSMauro Carvalho Chehab 
17850c0d06caSMauro Carvalho Chehab static int sd_init(struct gspca_dev *gspca_dev)
17860c0d06caSMauro Carvalho Chehab {
17870c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
17880c0d06caSMauro Carvalho Chehab 	int i;
17890c0d06caSMauro Carvalho Chehab 	u8 value;
1790*312487ccSMorgan Phillips 	u8 i2c_init[9] = {
1791*312487ccSMorgan Phillips 		0x80, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
1792*312487ccSMorgan Phillips 	};
17930c0d06caSMauro Carvalho Chehab 
17940c0d06caSMauro Carvalho Chehab 	for (i = 0; i < ARRAY_SIZE(bridge_init); i++) {
17950c0d06caSMauro Carvalho Chehab 		value = bridge_init[i][1];
17960c0d06caSMauro Carvalho Chehab 		reg_w(gspca_dev, bridge_init[i][0], &value, 1);
17970c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0) {
17980c0d06caSMauro Carvalho Chehab 			pr_err("Device initialization failed\n");
17990c0d06caSMauro Carvalho Chehab 			return gspca_dev->usb_err;
18000c0d06caSMauro Carvalho Chehab 		}
18010c0d06caSMauro Carvalho Chehab 	}
18020c0d06caSMauro Carvalho Chehab 
18030c0d06caSMauro Carvalho Chehab 	if (sd->flags & LED_REVERSE)
18040c0d06caSMauro Carvalho Chehab 		reg_w1(gspca_dev, 0x1006, 0x00);
18050c0d06caSMauro Carvalho Chehab 	else
18060c0d06caSMauro Carvalho Chehab 		reg_w1(gspca_dev, 0x1006, 0x20);
18070c0d06caSMauro Carvalho Chehab 
18080c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x10c0, i2c_init, 9);
18090c0d06caSMauro Carvalho Chehab 	if (gspca_dev->usb_err < 0) {
18100c0d06caSMauro Carvalho Chehab 		pr_err("Device initialization failed\n");
18110c0d06caSMauro Carvalho Chehab 		return gspca_dev->usb_err;
18120c0d06caSMauro Carvalho Chehab 	}
18130c0d06caSMauro Carvalho Chehab 
18140c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
18150c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
18160c0d06caSMauro Carvalho Chehab 		ov9650_init_sensor(gspca_dev);
18170c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18180c0d06caSMauro Carvalho Chehab 			break;
18190c0d06caSMauro Carvalho Chehab 		pr_info("OV9650 sensor detected\n");
18200c0d06caSMauro Carvalho Chehab 		break;
18210c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9655:
18220c0d06caSMauro Carvalho Chehab 		ov9655_init_sensor(gspca_dev);
18230c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18240c0d06caSMauro Carvalho Chehab 			break;
18250c0d06caSMauro Carvalho Chehab 		pr_info("OV9655 sensor detected\n");
18260c0d06caSMauro Carvalho Chehab 		break;
18270c0d06caSMauro Carvalho Chehab 	case SENSOR_SOI968:
18280c0d06caSMauro Carvalho Chehab 		soi968_init_sensor(gspca_dev);
18290c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18300c0d06caSMauro Carvalho Chehab 			break;
18310c0d06caSMauro Carvalho Chehab 		pr_info("SOI968 sensor detected\n");
18320c0d06caSMauro Carvalho Chehab 		break;
18330c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7660:
18340c0d06caSMauro Carvalho Chehab 		ov7660_init_sensor(gspca_dev);
18350c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18360c0d06caSMauro Carvalho Chehab 			break;
18370c0d06caSMauro Carvalho Chehab 		pr_info("OV7660 sensor detected\n");
18380c0d06caSMauro Carvalho Chehab 		break;
18390c0d06caSMauro Carvalho Chehab 	case SENSOR_OV7670:
18400c0d06caSMauro Carvalho Chehab 		ov7670_init_sensor(gspca_dev);
18410c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18420c0d06caSMauro Carvalho Chehab 			break;
18430c0d06caSMauro Carvalho Chehab 		pr_info("OV7670 sensor detected\n");
18440c0d06caSMauro Carvalho Chehab 		break;
18450c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9VPRB:
18460c0d06caSMauro Carvalho Chehab 		mt9v_init_sensor(gspca_dev);
18470c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18480c0d06caSMauro Carvalho Chehab 			break;
18490c0d06caSMauro Carvalho Chehab 		pr_info("MT9VPRB sensor detected\n");
18500c0d06caSMauro Carvalho Chehab 		break;
18510c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M111:
18520c0d06caSMauro Carvalho Chehab 		mt9m111_init_sensor(gspca_dev);
18530c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18540c0d06caSMauro Carvalho Chehab 			break;
18550c0d06caSMauro Carvalho Chehab 		pr_info("MT9M111 sensor detected\n");
18560c0d06caSMauro Carvalho Chehab 		break;
18570c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M112:
18580c0d06caSMauro Carvalho Chehab 		mt9m112_init_sensor(gspca_dev);
18590c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18600c0d06caSMauro Carvalho Chehab 			break;
18610c0d06caSMauro Carvalho Chehab 		pr_info("MT9M112 sensor detected\n");
18620c0d06caSMauro Carvalho Chehab 		break;
18630c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M001:
18640c0d06caSMauro Carvalho Chehab 		mt9m001_init_sensor(gspca_dev);
18650c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18660c0d06caSMauro Carvalho Chehab 			break;
18670c0d06caSMauro Carvalho Chehab 		break;
18680c0d06caSMauro Carvalho Chehab 	case SENSOR_HV7131R:
18690c0d06caSMauro Carvalho Chehab 		hv7131r_init_sensor(gspca_dev);
18700c0d06caSMauro Carvalho Chehab 		if (gspca_dev->usb_err < 0)
18710c0d06caSMauro Carvalho Chehab 			break;
18720c0d06caSMauro Carvalho Chehab 		pr_info("HV7131R sensor detected\n");
18730c0d06caSMauro Carvalho Chehab 		break;
18740c0d06caSMauro Carvalho Chehab 	default:
18750c0d06caSMauro Carvalho Chehab 		pr_err("Unsupported sensor\n");
18760c0d06caSMauro Carvalho Chehab 		gspca_dev->usb_err = -ENODEV;
18770c0d06caSMauro Carvalho Chehab 	}
18780c0d06caSMauro Carvalho Chehab 	return gspca_dev->usb_err;
18790c0d06caSMauro Carvalho Chehab }
18800c0d06caSMauro Carvalho Chehab 
18810c0d06caSMauro Carvalho Chehab static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode)
18820c0d06caSMauro Carvalho Chehab {
18830c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
18840c0d06caSMauro Carvalho Chehab 	u8 value;
18850c0d06caSMauro Carvalho Chehab 
18860c0d06caSMauro Carvalho Chehab 	switch (sd->sensor) {
18870c0d06caSMauro Carvalho Chehab 	case SENSOR_SOI968:
18880c0d06caSMauro Carvalho Chehab 		if (mode & MODE_SXGA) {
18890c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x17, 0x1d);
18900c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x18, 0xbd);
18910c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x19, 0x01);
18920c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x1a, 0x81);
18930c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x12, 0x00);
18940c0d06caSMauro Carvalho Chehab 			sd->hstart = 140;
18950c0d06caSMauro Carvalho Chehab 			sd->vstart = 19;
18960c0d06caSMauro Carvalho Chehab 		} else {
18970c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x17, 0x13);
18980c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x18, 0x63);
18990c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x19, 0x01);
19000c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x1a, 0x79);
19010c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x12, 0x40);
19020c0d06caSMauro Carvalho Chehab 			sd->hstart = 60;
19030c0d06caSMauro Carvalho Chehab 			sd->vstart = 11;
19040c0d06caSMauro Carvalho Chehab 		}
19050c0d06caSMauro Carvalho Chehab 		break;
19060c0d06caSMauro Carvalho Chehab 	case SENSOR_OV9650:
19070c0d06caSMauro Carvalho Chehab 		if (mode & MODE_SXGA) {
19080c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x17, 0x1b);
19090c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x18, 0xbc);
19100c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x19, 0x01);
19110c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x1a, 0x82);
19120c0d06caSMauro Carvalho Chehab 			i2c_r1(gspca_dev, 0x12, &value);
19130c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x12, value & 0x07);
19140c0d06caSMauro Carvalho Chehab 		} else {
19150c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x17, 0x24);
19160c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x18, 0xc5);
19170c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x19, 0x00);
19180c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x1a, 0x3c);
19190c0d06caSMauro Carvalho Chehab 			i2c_r1(gspca_dev, 0x12, &value);
19200c0d06caSMauro Carvalho Chehab 			i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40);
19210c0d06caSMauro Carvalho Chehab 		}
19220c0d06caSMauro Carvalho Chehab 		break;
19230c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M112:
19240c0d06caSMauro Carvalho Chehab 	case SENSOR_MT9M111:
19250c0d06caSMauro Carvalho Chehab 		if (mode & MODE_SXGA) {
19260c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xf0, 0x0002);
19270c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xc8, 0x970b);
19280c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xf0, 0x0000);
19290c0d06caSMauro Carvalho Chehab 		} else {
19300c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xf0, 0x0002);
19310c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xc8, 0x8000);
19320c0d06caSMauro Carvalho Chehab 			i2c_w2(gspca_dev, 0xf0, 0x0000);
19330c0d06caSMauro Carvalho Chehab 		}
19340c0d06caSMauro Carvalho Chehab 		break;
19350c0d06caSMauro Carvalho Chehab 	}
19360c0d06caSMauro Carvalho Chehab }
19370c0d06caSMauro Carvalho Chehab 
19380c0d06caSMauro Carvalho Chehab static int sd_isoc_init(struct gspca_dev *gspca_dev)
19390c0d06caSMauro Carvalho Chehab {
19400c0d06caSMauro Carvalho Chehab 	struct usb_interface *intf;
19410c0d06caSMauro Carvalho Chehab 	u32 flags = gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv;
19420c0d06caSMauro Carvalho Chehab 
19430c0d06caSMauro Carvalho Chehab 	/*
19440c0d06caSMauro Carvalho Chehab 	 * When using the SN9C20X_I420 fmt the sn9c20x needs more bandwidth
19450c0d06caSMauro Carvalho Chehab 	 * than our regular bandwidth calculations reserve, so we force the
19460c0d06caSMauro Carvalho Chehab 	 * use of a specific altsetting when using the SN9C20X_I420 fmt.
19470c0d06caSMauro Carvalho Chehab 	 */
19480c0d06caSMauro Carvalho Chehab 	if (!(flags & (MODE_RAW | MODE_JPEG))) {
19490c0d06caSMauro Carvalho Chehab 		intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
19500c0d06caSMauro Carvalho Chehab 
19510c0d06caSMauro Carvalho Chehab 		if (intf->num_altsetting != 9) {
19520c0d06caSMauro Carvalho Chehab 			pr_warn("sn9c20x camera with unknown number of alt "
19530c0d06caSMauro Carvalho Chehab 				"settings (%d), please report!\n",
19540c0d06caSMauro Carvalho Chehab 				intf->num_altsetting);
19550c0d06caSMauro Carvalho Chehab 			gspca_dev->alt = intf->num_altsetting;
19560c0d06caSMauro Carvalho Chehab 			return 0;
19570c0d06caSMauro Carvalho Chehab 		}
19580c0d06caSMauro Carvalho Chehab 
19591966bc2aSOndrej Zary 		switch (gspca_dev->pixfmt.width) {
19600c0d06caSMauro Carvalho Chehab 		case 160: /* 160x120 */
19610c0d06caSMauro Carvalho Chehab 			gspca_dev->alt = 2;
19620c0d06caSMauro Carvalho Chehab 			break;
19630c0d06caSMauro Carvalho Chehab 		case 320: /* 320x240 */
19640c0d06caSMauro Carvalho Chehab 			gspca_dev->alt = 6;
19650c0d06caSMauro Carvalho Chehab 			break;
19660c0d06caSMauro Carvalho Chehab 		default:  /* >= 640x480 */
19670c0d06caSMauro Carvalho Chehab 			gspca_dev->alt = 9;
19680c0d06caSMauro Carvalho Chehab 			break;
19690c0d06caSMauro Carvalho Chehab 		}
19700c0d06caSMauro Carvalho Chehab 	}
19710c0d06caSMauro Carvalho Chehab 
19720c0d06caSMauro Carvalho Chehab 	return 0;
19730c0d06caSMauro Carvalho Chehab }
19740c0d06caSMauro Carvalho Chehab 
19750c0d06caSMauro Carvalho Chehab #define HW_WIN(mode, hstart, vstart) \
19760c0d06caSMauro Carvalho Chehab ((const u8 []){hstart, 0, vstart, 0, \
19770c0d06caSMauro Carvalho Chehab (mode & MODE_SXGA ? 1280 >> 4 : 640 >> 4), \
19780c0d06caSMauro Carvalho Chehab (mode & MODE_SXGA ? 1024 >> 3 : 480 >> 3)})
19790c0d06caSMauro Carvalho Chehab 
19800c0d06caSMauro Carvalho Chehab #define CLR_WIN(width, height) \
19810c0d06caSMauro Carvalho Chehab ((const u8 [])\
19820c0d06caSMauro Carvalho Chehab {0, width >> 2, 0, height >> 1,\
19830c0d06caSMauro Carvalho Chehab ((width >> 10) & 0x01) | ((height >> 8) & 0x6)})
19840c0d06caSMauro Carvalho Chehab 
19850c0d06caSMauro Carvalho Chehab static int sd_start(struct gspca_dev *gspca_dev)
19860c0d06caSMauro Carvalho Chehab {
19870c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
19880c0d06caSMauro Carvalho Chehab 	int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
19891966bc2aSOndrej Zary 	int width = gspca_dev->pixfmt.width;
19901966bc2aSOndrej Zary 	int height = gspca_dev->pixfmt.height;
19910c0d06caSMauro Carvalho Chehab 	u8 fmt, scale = 0;
19920c0d06caSMauro Carvalho Chehab 
19930c0d06caSMauro Carvalho Chehab 	jpeg_define(sd->jpeg_hdr, height, width,
19940c0d06caSMauro Carvalho Chehab 			0x21);
19950c0d06caSMauro Carvalho Chehab 	jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
19960c0d06caSMauro Carvalho Chehab 
19970c0d06caSMauro Carvalho Chehab 	if (mode & MODE_RAW)
19980c0d06caSMauro Carvalho Chehab 		fmt = 0x2d;
19990c0d06caSMauro Carvalho Chehab 	else if (mode & MODE_JPEG)
20000c0d06caSMauro Carvalho Chehab 		fmt = 0x24;
20010c0d06caSMauro Carvalho Chehab 	else
20020c0d06caSMauro Carvalho Chehab 		fmt = 0x2f;	/* YUV 420 */
20030c0d06caSMauro Carvalho Chehab 	sd->fmt = fmt;
20040c0d06caSMauro Carvalho Chehab 
20050c0d06caSMauro Carvalho Chehab 	switch (mode & SCALE_MASK) {
20060c0d06caSMauro Carvalho Chehab 	case SCALE_1280x1024:
20070c0d06caSMauro Carvalho Chehab 		scale = 0xc0;
20080c0d06caSMauro Carvalho Chehab 		pr_info("Set 1280x1024\n");
20090c0d06caSMauro Carvalho Chehab 		break;
20100c0d06caSMauro Carvalho Chehab 	case SCALE_640x480:
20110c0d06caSMauro Carvalho Chehab 		scale = 0x80;
20120c0d06caSMauro Carvalho Chehab 		pr_info("Set 640x480\n");
20130c0d06caSMauro Carvalho Chehab 		break;
20140c0d06caSMauro Carvalho Chehab 	case SCALE_320x240:
20150c0d06caSMauro Carvalho Chehab 		scale = 0x90;
20160c0d06caSMauro Carvalho Chehab 		pr_info("Set 320x240\n");
20170c0d06caSMauro Carvalho Chehab 		break;
20180c0d06caSMauro Carvalho Chehab 	case SCALE_160x120:
20190c0d06caSMauro Carvalho Chehab 		scale = 0xa0;
20200c0d06caSMauro Carvalho Chehab 		pr_info("Set 160x120\n");
20210c0d06caSMauro Carvalho Chehab 		break;
20220c0d06caSMauro Carvalho Chehab 	}
20230c0d06caSMauro Carvalho Chehab 
20240c0d06caSMauro Carvalho Chehab 	configure_sensor_output(gspca_dev, mode);
20250c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1100, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
20260c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1140, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
20270c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5);
20280c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6);
20290c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1189, scale);
20300c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x10e0, fmt);
20310c0d06caSMauro Carvalho Chehab 
20320c0d06caSMauro Carvalho Chehab 	set_cmatrix(gspca_dev, v4l2_ctrl_g_ctrl(sd->brightness),
20330c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_g_ctrl(sd->contrast),
20340c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_g_ctrl(sd->saturation),
20350c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_g_ctrl(sd->hue));
20360c0d06caSMauro Carvalho Chehab 	set_gamma(gspca_dev, v4l2_ctrl_g_ctrl(sd->gamma));
20370c0d06caSMauro Carvalho Chehab 	set_redblue(gspca_dev, v4l2_ctrl_g_ctrl(sd->blue),
20380c0d06caSMauro Carvalho Chehab 			v4l2_ctrl_g_ctrl(sd->red));
20390c0d06caSMauro Carvalho Chehab 	if (sd->gain)
20400c0d06caSMauro Carvalho Chehab 		set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain));
20410c0d06caSMauro Carvalho Chehab 	if (sd->exposure)
20420c0d06caSMauro Carvalho Chehab 		set_exposure(gspca_dev, v4l2_ctrl_g_ctrl(sd->exposure));
20430c0d06caSMauro Carvalho Chehab 	if (sd->hflip)
20440c0d06caSMauro Carvalho Chehab 		set_hvflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->hflip),
20450c0d06caSMauro Carvalho Chehab 				v4l2_ctrl_g_ctrl(sd->vflip));
20460c0d06caSMauro Carvalho Chehab 
20470c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1007, 0x20);
20480c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1061, 0x03);
20490c0d06caSMauro Carvalho Chehab 
20500c0d06caSMauro Carvalho Chehab 	/* if JPEG, prepare the compression quality update */
20510c0d06caSMauro Carvalho Chehab 	if (mode & MODE_JPEG) {
20520c0d06caSMauro Carvalho Chehab 		sd->pktsz = sd->npkt = 0;
20530c0d06caSMauro Carvalho Chehab 		sd->nchg = 0;
20540c0d06caSMauro Carvalho Chehab 		sd->work_thread =
20550c0d06caSMauro Carvalho Chehab 			create_singlethread_workqueue(KBUILD_MODNAME);
20560c0d06caSMauro Carvalho Chehab 	}
20570c0d06caSMauro Carvalho Chehab 
20580c0d06caSMauro Carvalho Chehab 	return gspca_dev->usb_err;
20590c0d06caSMauro Carvalho Chehab }
20600c0d06caSMauro Carvalho Chehab 
20610c0d06caSMauro Carvalho Chehab static void sd_stopN(struct gspca_dev *gspca_dev)
20620c0d06caSMauro Carvalho Chehab {
20630c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1007, 0x00);
20640c0d06caSMauro Carvalho Chehab 	reg_w1(gspca_dev, 0x1061, 0x01);
20650c0d06caSMauro Carvalho Chehab }
20660c0d06caSMauro Carvalho Chehab 
20670c0d06caSMauro Carvalho Chehab /* called on streamoff with alt==0 and on disconnect */
20680c0d06caSMauro Carvalho Chehab /* the usb_lock is held at entry - restore on exit */
20690c0d06caSMauro Carvalho Chehab static void sd_stop0(struct gspca_dev *gspca_dev)
20700c0d06caSMauro Carvalho Chehab {
20710c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
20720c0d06caSMauro Carvalho Chehab 
20730c0d06caSMauro Carvalho Chehab 	if (sd->work_thread != NULL) {
20740c0d06caSMauro Carvalho Chehab 		mutex_unlock(&gspca_dev->usb_lock);
20750c0d06caSMauro Carvalho Chehab 		destroy_workqueue(sd->work_thread);
20760c0d06caSMauro Carvalho Chehab 		mutex_lock(&gspca_dev->usb_lock);
20770c0d06caSMauro Carvalho Chehab 		sd->work_thread = NULL;
20780c0d06caSMauro Carvalho Chehab 	}
20790c0d06caSMauro Carvalho Chehab }
20800c0d06caSMauro Carvalho Chehab 
20810c0d06caSMauro Carvalho Chehab static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
20820c0d06caSMauro Carvalho Chehab {
20830c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
20840c0d06caSMauro Carvalho Chehab 	s32 cur_exp = v4l2_ctrl_g_ctrl(sd->exposure);
20850c0d06caSMauro Carvalho Chehab 	s32 max = sd->exposure->maximum - sd->exposure_step;
20860c0d06caSMauro Carvalho Chehab 	s32 min = sd->exposure->minimum + sd->exposure_step;
20870c0d06caSMauro Carvalho Chehab 	s16 new_exp;
20880c0d06caSMauro Carvalho Chehab 
20890c0d06caSMauro Carvalho Chehab 	/*
20900c0d06caSMauro Carvalho Chehab 	 * some hardcoded values are present
20910c0d06caSMauro Carvalho Chehab 	 * like those for maximal/minimal exposure
20920c0d06caSMauro Carvalho Chehab 	 * and exposure steps
20930c0d06caSMauro Carvalho Chehab 	 */
20940c0d06caSMauro Carvalho Chehab 	if (avg_lum < MIN_AVG_LUM) {
20950c0d06caSMauro Carvalho Chehab 		if (cur_exp > max)
20960c0d06caSMauro Carvalho Chehab 			return;
20970c0d06caSMauro Carvalho Chehab 
20980c0d06caSMauro Carvalho Chehab 		new_exp = cur_exp + sd->exposure_step;
20990c0d06caSMauro Carvalho Chehab 		if (new_exp > max)
21000c0d06caSMauro Carvalho Chehab 			new_exp = max;
21010c0d06caSMauro Carvalho Chehab 		if (new_exp < min)
21020c0d06caSMauro Carvalho Chehab 			new_exp = min;
21030c0d06caSMauro Carvalho Chehab 		v4l2_ctrl_s_ctrl(sd->exposure, new_exp);
21040c0d06caSMauro Carvalho Chehab 
21050c0d06caSMauro Carvalho Chehab 		sd->older_step = sd->old_step;
21060c0d06caSMauro Carvalho Chehab 		sd->old_step = 1;
21070c0d06caSMauro Carvalho Chehab 
21080c0d06caSMauro Carvalho Chehab 		if (sd->old_step ^ sd->older_step)
21090c0d06caSMauro Carvalho Chehab 			sd->exposure_step /= 2;
21100c0d06caSMauro Carvalho Chehab 		else
21110c0d06caSMauro Carvalho Chehab 			sd->exposure_step += 2;
21120c0d06caSMauro Carvalho Chehab 	}
21130c0d06caSMauro Carvalho Chehab 	if (avg_lum > MAX_AVG_LUM) {
21140c0d06caSMauro Carvalho Chehab 		if (cur_exp < min)
21150c0d06caSMauro Carvalho Chehab 			return;
21160c0d06caSMauro Carvalho Chehab 		new_exp = cur_exp - sd->exposure_step;
21170c0d06caSMauro Carvalho Chehab 		if (new_exp > max)
21180c0d06caSMauro Carvalho Chehab 			new_exp = max;
21190c0d06caSMauro Carvalho Chehab 		if (new_exp < min)
21200c0d06caSMauro Carvalho Chehab 			new_exp = min;
21210c0d06caSMauro Carvalho Chehab 		v4l2_ctrl_s_ctrl(sd->exposure, new_exp);
21220c0d06caSMauro Carvalho Chehab 		sd->older_step = sd->old_step;
21230c0d06caSMauro Carvalho Chehab 		sd->old_step = 0;
21240c0d06caSMauro Carvalho Chehab 
21250c0d06caSMauro Carvalho Chehab 		if (sd->old_step ^ sd->older_step)
21260c0d06caSMauro Carvalho Chehab 			sd->exposure_step /= 2;
21270c0d06caSMauro Carvalho Chehab 		else
21280c0d06caSMauro Carvalho Chehab 			sd->exposure_step += 2;
21290c0d06caSMauro Carvalho Chehab 	}
21300c0d06caSMauro Carvalho Chehab }
21310c0d06caSMauro Carvalho Chehab 
21320c0d06caSMauro Carvalho Chehab static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
21330c0d06caSMauro Carvalho Chehab {
21340c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
21350c0d06caSMauro Carvalho Chehab 	s32 cur_gain = v4l2_ctrl_g_ctrl(sd->gain);
21360c0d06caSMauro Carvalho Chehab 
21370c0d06caSMauro Carvalho Chehab 	if (avg_lum < MIN_AVG_LUM && cur_gain < sd->gain->maximum)
21380c0d06caSMauro Carvalho Chehab 		v4l2_ctrl_s_ctrl(sd->gain, cur_gain + 1);
21390c0d06caSMauro Carvalho Chehab 	if (avg_lum > MAX_AVG_LUM && cur_gain > sd->gain->minimum)
21400c0d06caSMauro Carvalho Chehab 		v4l2_ctrl_s_ctrl(sd->gain, cur_gain - 1);
21410c0d06caSMauro Carvalho Chehab }
21420c0d06caSMauro Carvalho Chehab 
21430c0d06caSMauro Carvalho Chehab static void sd_dqcallback(struct gspca_dev *gspca_dev)
21440c0d06caSMauro Carvalho Chehab {
21450c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
21460c0d06caSMauro Carvalho Chehab 	int avg_lum;
21470c0d06caSMauro Carvalho Chehab 
21480c0d06caSMauro Carvalho Chehab 	if (sd->autogain == NULL || !v4l2_ctrl_g_ctrl(sd->autogain))
21490c0d06caSMauro Carvalho Chehab 		return;
21500c0d06caSMauro Carvalho Chehab 
21510c0d06caSMauro Carvalho Chehab 	avg_lum = atomic_read(&sd->avg_lum);
21520c0d06caSMauro Carvalho Chehab 	if (sd->sensor == SENSOR_SOI968)
21530c0d06caSMauro Carvalho Chehab 		do_autogain(gspca_dev, avg_lum);
21540c0d06caSMauro Carvalho Chehab 	else
21550c0d06caSMauro Carvalho Chehab 		do_autoexposure(gspca_dev, avg_lum);
21560c0d06caSMauro Carvalho Chehab }
21570c0d06caSMauro Carvalho Chehab 
21580c0d06caSMauro Carvalho Chehab /* JPEG quality update */
21590c0d06caSMauro Carvalho Chehab /* This function is executed from a work queue. */
21600c0d06caSMauro Carvalho Chehab static void qual_upd(struct work_struct *work)
21610c0d06caSMauro Carvalho Chehab {
21620c0d06caSMauro Carvalho Chehab 	struct sd *sd = container_of(work, struct sd, work);
21630c0d06caSMauro Carvalho Chehab 	struct gspca_dev *gspca_dev = &sd->gspca_dev;
21640c0d06caSMauro Carvalho Chehab 	s32 qual = v4l2_ctrl_g_ctrl(sd->jpegqual);
21650c0d06caSMauro Carvalho Chehab 
2166844db450SHans de Goede 	/* To protect gspca_dev->usb_buf and gspca_dev->usb_err */
21670c0d06caSMauro Carvalho Chehab 	mutex_lock(&gspca_dev->usb_lock);
21680c0d06caSMauro Carvalho Chehab 	PDEBUG(D_STREAM, "qual_upd %d%%", qual);
2169844db450SHans de Goede 	gspca_dev->usb_err = 0;
21700c0d06caSMauro Carvalho Chehab 	set_quality(gspca_dev, qual);
21710c0d06caSMauro Carvalho Chehab 	mutex_unlock(&gspca_dev->usb_lock);
21720c0d06caSMauro Carvalho Chehab }
21730c0d06caSMauro Carvalho Chehab 
21748099affaSPeter Senna Tschudin #if IS_ENABLED(CONFIG_INPUT)
21750c0d06caSMauro Carvalho Chehab static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
21760c0d06caSMauro Carvalho Chehab 			u8 *data,		/* interrupt packet */
21770c0d06caSMauro Carvalho Chehab 			int len)		/* interrupt packet length */
21780c0d06caSMauro Carvalho Chehab {
21790c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
21800c0d06caSMauro Carvalho Chehab 
21810c0d06caSMauro Carvalho Chehab 	if (!(sd->flags & HAS_NO_BUTTON) && len == 1) {
21820c0d06caSMauro Carvalho Chehab 		input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
21830c0d06caSMauro Carvalho Chehab 		input_sync(gspca_dev->input_dev);
21840c0d06caSMauro Carvalho Chehab 		input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
21850c0d06caSMauro Carvalho Chehab 		input_sync(gspca_dev->input_dev);
21860c0d06caSMauro Carvalho Chehab 		return 0;
21870c0d06caSMauro Carvalho Chehab 	}
21880c0d06caSMauro Carvalho Chehab 	return -EINVAL;
21890c0d06caSMauro Carvalho Chehab }
21900c0d06caSMauro Carvalho Chehab #endif
21910c0d06caSMauro Carvalho Chehab 
21920c0d06caSMauro Carvalho Chehab /* check the JPEG compression */
21930c0d06caSMauro Carvalho Chehab static void transfer_check(struct gspca_dev *gspca_dev,
21940c0d06caSMauro Carvalho Chehab 			u8 *data)
21950c0d06caSMauro Carvalho Chehab {
21960c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
21970c0d06caSMauro Carvalho Chehab 	int new_qual, r;
21980c0d06caSMauro Carvalho Chehab 
21990c0d06caSMauro Carvalho Chehab 	new_qual = 0;
22000c0d06caSMauro Carvalho Chehab 
22010c0d06caSMauro Carvalho Chehab 	/* if USB error, discard the frame and decrease the quality */
22020c0d06caSMauro Carvalho Chehab 	if (data[6] & 0x08) {				/* USB FIFO full */
22030c0d06caSMauro Carvalho Chehab 		gspca_dev->last_packet_type = DISCARD_PACKET;
22040c0d06caSMauro Carvalho Chehab 		new_qual = -5;
22050c0d06caSMauro Carvalho Chehab 	} else {
22060c0d06caSMauro Carvalho Chehab 
22070c0d06caSMauro Carvalho Chehab 		/* else, compute the filling rate and a new JPEG quality */
22080c0d06caSMauro Carvalho Chehab 		r = (sd->pktsz * 100) /
22090c0d06caSMauro Carvalho Chehab 			(sd->npkt *
22100c0d06caSMauro Carvalho Chehab 				gspca_dev->urb[0]->iso_frame_desc[0].length);
22110c0d06caSMauro Carvalho Chehab 		if (r >= 85)
22120c0d06caSMauro Carvalho Chehab 			new_qual = -3;
22130c0d06caSMauro Carvalho Chehab 		else if (r < 75)
22140c0d06caSMauro Carvalho Chehab 			new_qual = 2;
22150c0d06caSMauro Carvalho Chehab 	}
22160c0d06caSMauro Carvalho Chehab 	if (new_qual != 0) {
22170c0d06caSMauro Carvalho Chehab 		sd->nchg += new_qual;
22180c0d06caSMauro Carvalho Chehab 		if (sd->nchg < -6 || sd->nchg >= 12) {
22190c0d06caSMauro Carvalho Chehab 			/* Note: we are in interrupt context, so we can't
22200c0d06caSMauro Carvalho Chehab 			   use v4l2_ctrl_g/s_ctrl here. Access the value
22210c0d06caSMauro Carvalho Chehab 			   directly instead. */
22220c0d06caSMauro Carvalho Chehab 			s32 curqual = sd->jpegqual->cur.val;
22230c0d06caSMauro Carvalho Chehab 			sd->nchg = 0;
22240c0d06caSMauro Carvalho Chehab 			new_qual += curqual;
22250c0d06caSMauro Carvalho Chehab 			if (new_qual < sd->jpegqual->minimum)
22260c0d06caSMauro Carvalho Chehab 				new_qual = sd->jpegqual->minimum;
22270c0d06caSMauro Carvalho Chehab 			else if (new_qual > sd->jpegqual->maximum)
22280c0d06caSMauro Carvalho Chehab 				new_qual = sd->jpegqual->maximum;
22290c0d06caSMauro Carvalho Chehab 			if (new_qual != curqual) {
22300c0d06caSMauro Carvalho Chehab 				sd->jpegqual->cur.val = new_qual;
22310c0d06caSMauro Carvalho Chehab 				queue_work(sd->work_thread, &sd->work);
22320c0d06caSMauro Carvalho Chehab 			}
22330c0d06caSMauro Carvalho Chehab 		}
22340c0d06caSMauro Carvalho Chehab 	} else {
22350c0d06caSMauro Carvalho Chehab 		sd->nchg = 0;
22360c0d06caSMauro Carvalho Chehab 	}
22370c0d06caSMauro Carvalho Chehab 	sd->pktsz = sd->npkt = 0;
22380c0d06caSMauro Carvalho Chehab }
22390c0d06caSMauro Carvalho Chehab 
22400c0d06caSMauro Carvalho Chehab static void sd_pkt_scan(struct gspca_dev *gspca_dev,
22410c0d06caSMauro Carvalho Chehab 			u8 *data,			/* isoc packet */
22420c0d06caSMauro Carvalho Chehab 			int len)			/* iso packet length */
22430c0d06caSMauro Carvalho Chehab {
22440c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
22450c0d06caSMauro Carvalho Chehab 	int avg_lum, is_jpeg;
2246*312487ccSMorgan Phillips 	static const u8 frame_header[] = {
2247*312487ccSMorgan Phillips 		0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96
2248*312487ccSMorgan Phillips 	};
22490c0d06caSMauro Carvalho Chehab 
22500c0d06caSMauro Carvalho Chehab 	is_jpeg = (sd->fmt & 0x03) == 0;
22510c0d06caSMauro Carvalho Chehab 	if (len >= 64 && memcmp(data, frame_header, 6) == 0) {
22520c0d06caSMauro Carvalho Chehab 		avg_lum = ((data[35] >> 2) & 3) |
22530c0d06caSMauro Carvalho Chehab 			   (data[20] << 2) |
22540c0d06caSMauro Carvalho Chehab 			   (data[19] << 10);
22550c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[35] >> 4) & 3) |
22560c0d06caSMauro Carvalho Chehab 			    (data[22] << 2) |
22570c0d06caSMauro Carvalho Chehab 			    (data[21] << 10);
22580c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[35] >> 6) & 3) |
22590c0d06caSMauro Carvalho Chehab 			    (data[24] << 2) |
22600c0d06caSMauro Carvalho Chehab 			    (data[23] << 10);
22610c0d06caSMauro Carvalho Chehab 		avg_lum += (data[36] & 3) |
22620c0d06caSMauro Carvalho Chehab 			   (data[26] << 2) |
22630c0d06caSMauro Carvalho Chehab 			   (data[25] << 10);
22640c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[36] >> 2) & 3) |
22650c0d06caSMauro Carvalho Chehab 			    (data[28] << 2) |
22660c0d06caSMauro Carvalho Chehab 			    (data[27] << 10);
22670c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[36] >> 4) & 3) |
22680c0d06caSMauro Carvalho Chehab 			    (data[30] << 2) |
22690c0d06caSMauro Carvalho Chehab 			    (data[29] << 10);
22700c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[36] >> 6) & 3) |
22710c0d06caSMauro Carvalho Chehab 			    (data[32] << 2) |
22720c0d06caSMauro Carvalho Chehab 			    (data[31] << 10);
22730c0d06caSMauro Carvalho Chehab 		avg_lum += ((data[44] >> 4) & 3) |
22740c0d06caSMauro Carvalho Chehab 			    (data[34] << 2) |
22750c0d06caSMauro Carvalho Chehab 			    (data[33] << 10);
22760c0d06caSMauro Carvalho Chehab 		avg_lum >>= 9;
22770c0d06caSMauro Carvalho Chehab 		atomic_set(&sd->avg_lum, avg_lum);
22780c0d06caSMauro Carvalho Chehab 
22790c0d06caSMauro Carvalho Chehab 		if (is_jpeg)
22800c0d06caSMauro Carvalho Chehab 			transfer_check(gspca_dev, data);
22810c0d06caSMauro Carvalho Chehab 
22820c0d06caSMauro Carvalho Chehab 		gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
22830c0d06caSMauro Carvalho Chehab 		len -= 64;
22840c0d06caSMauro Carvalho Chehab 		if (len == 0)
22850c0d06caSMauro Carvalho Chehab 			return;
22860c0d06caSMauro Carvalho Chehab 		data += 64;
22870c0d06caSMauro Carvalho Chehab 	}
22880c0d06caSMauro Carvalho Chehab 	if (gspca_dev->last_packet_type == LAST_PACKET) {
22890c0d06caSMauro Carvalho Chehab 		if (is_jpeg) {
22900c0d06caSMauro Carvalho Chehab 			gspca_frame_add(gspca_dev, FIRST_PACKET,
22910c0d06caSMauro Carvalho Chehab 				sd->jpeg_hdr, JPEG_HDR_SZ);
22920c0d06caSMauro Carvalho Chehab 			gspca_frame_add(gspca_dev, INTER_PACKET,
22930c0d06caSMauro Carvalho Chehab 				data, len);
22940c0d06caSMauro Carvalho Chehab 		} else {
22950c0d06caSMauro Carvalho Chehab 			gspca_frame_add(gspca_dev, FIRST_PACKET,
22960c0d06caSMauro Carvalho Chehab 				data, len);
22970c0d06caSMauro Carvalho Chehab 		}
22980c0d06caSMauro Carvalho Chehab 	} else {
22990c0d06caSMauro Carvalho Chehab 		/* if JPEG, count the packets and their size */
23000c0d06caSMauro Carvalho Chehab 		if (is_jpeg) {
23010c0d06caSMauro Carvalho Chehab 			sd->npkt++;
23020c0d06caSMauro Carvalho Chehab 			sd->pktsz += len;
23030c0d06caSMauro Carvalho Chehab 		}
23040c0d06caSMauro Carvalho Chehab 		gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
23050c0d06caSMauro Carvalho Chehab 	}
23060c0d06caSMauro Carvalho Chehab }
23070c0d06caSMauro Carvalho Chehab 
23080c0d06caSMauro Carvalho Chehab /* sub-driver description */
23090c0d06caSMauro Carvalho Chehab static const struct sd_desc sd_desc = {
23100c0d06caSMauro Carvalho Chehab 	.name = KBUILD_MODNAME,
23110c0d06caSMauro Carvalho Chehab 	.config = sd_config,
23120c0d06caSMauro Carvalho Chehab 	.init = sd_init,
23130c0d06caSMauro Carvalho Chehab 	.init_controls = sd_init_controls,
23140c0d06caSMauro Carvalho Chehab 	.isoc_init = sd_isoc_init,
23150c0d06caSMauro Carvalho Chehab 	.start = sd_start,
23160c0d06caSMauro Carvalho Chehab 	.stopN = sd_stopN,
23170c0d06caSMauro Carvalho Chehab 	.stop0 = sd_stop0,
23180c0d06caSMauro Carvalho Chehab 	.pkt_scan = sd_pkt_scan,
23198099affaSPeter Senna Tschudin #if IS_ENABLED(CONFIG_INPUT)
23200c0d06caSMauro Carvalho Chehab 	.int_pkt_scan = sd_int_pkt_scan,
23210c0d06caSMauro Carvalho Chehab #endif
23220c0d06caSMauro Carvalho Chehab 	.dq_callback = sd_dqcallback,
23230c0d06caSMauro Carvalho Chehab #ifdef CONFIG_VIDEO_ADV_DEBUG
23240c0d06caSMauro Carvalho Chehab 	.set_register = sd_dbg_s_register,
23250c0d06caSMauro Carvalho Chehab 	.get_register = sd_dbg_g_register,
2326b1c85cc0SHans Verkuil 	.get_chip_info = sd_chip_info,
23270c0d06caSMauro Carvalho Chehab #endif
23280c0d06caSMauro Carvalho Chehab };
23290c0d06caSMauro Carvalho Chehab 
23300c0d06caSMauro Carvalho Chehab #define SN9C20X(sensor, i2c_addr, flags) \
23310c0d06caSMauro Carvalho Chehab 	.driver_info =  ((flags & 0xff) << 16) \
23320c0d06caSMauro Carvalho Chehab 			| (SENSOR_ ## sensor << 8) \
23330c0d06caSMauro Carvalho Chehab 			| (i2c_addr)
23340c0d06caSMauro Carvalho Chehab 
23350c0d06caSMauro Carvalho Chehab static const struct usb_device_id device_table[] = {
23360c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)},
23370c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)},
23380c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)},
23390c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x624c), SN9C20X(MT9M112, 0x5d, 0)},
23400c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, LED_REVERSE)},
23410c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30,
23420c0d06caSMauro Carvalho Chehab 					     (FLIP_DETECT | HAS_NO_BUTTON))},
23430c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)},
23440c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)},
23450c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6260), SN9C20X(OV7670, 0x21, 0)},
23460c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6270), SN9C20X(MT9VPRB, 0x00, 0)},
23470c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x627b), SN9C20X(OV7660, 0x21, FLIP_DETECT)},
23480c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x627c), SN9C20X(HV7131R, 0x11, 0)},
23490c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x627f), SN9C20X(OV9650, 0x30, 0)},
23500c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6280), SN9C20X(MT9M001, 0x5d, 0)},
23510c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6282), SN9C20X(MT9M111, 0x5d, 0)},
23520c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, 0)},
23530c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x628c), SN9C20X(MT9M112, 0x5d, 0)},
23540c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x628e), SN9C20X(SOI968, 0x30, 0)},
23550c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)},
23560c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)},
23570c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x62b0), SN9C20X(MT9VPRB, 0x00, 0)},
23580c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, LED_REVERSE)},
23590c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, LED_REVERSE)},
23600c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0c45, 0x62bc), SN9C20X(HV7131R, 0x11, 0)},
23610c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)},
23620c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x145f, 0x013d), SN9C20X(OV7660, 0x21, 0)},
23630c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0458, 0x7029), SN9C20X(HV7131R, 0x11, 0)},
236461f03191SWolfram Sang 	{USB_DEVICE(0x0458, 0x7045), SN9C20X(MT9M112, 0x5d, LED_REVERSE)},
23650c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0458, 0x704a), SN9C20X(MT9M112, 0x5d, 0)},
23660c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0458, 0x704c), SN9C20X(MT9M112, 0x5d, 0)},
23670c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0610), SN9C20X(HV7131R, 0x11, 0)},
23680c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0611), SN9C20X(HV7131R, 0x11, 0)},
23690c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0613), SN9C20X(HV7131R, 0x11, 0)},
23700c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0618), SN9C20X(HV7131R, 0x11, 0)},
23710c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0614), SN9C20X(MT9M111, 0x5d, 0)},
23720c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0615), SN9C20X(MT9M111, 0x5d, 0)},
23730c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0xa168, 0x0617), SN9C20X(MT9M111, 0x5d, 0)},
23740c0d06caSMauro Carvalho Chehab 	{}
23750c0d06caSMauro Carvalho Chehab };
23760c0d06caSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, device_table);
23770c0d06caSMauro Carvalho Chehab 
23780c0d06caSMauro Carvalho Chehab /* -- device connect -- */
23790c0d06caSMauro Carvalho Chehab static int sd_probe(struct usb_interface *intf,
23800c0d06caSMauro Carvalho Chehab 		    const struct usb_device_id *id)
23810c0d06caSMauro Carvalho Chehab {
23820c0d06caSMauro Carvalho Chehab 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
23830c0d06caSMauro Carvalho Chehab 				THIS_MODULE);
23840c0d06caSMauro Carvalho Chehab }
23850c0d06caSMauro Carvalho Chehab 
23860c0d06caSMauro Carvalho Chehab static struct usb_driver sd_driver = {
23870c0d06caSMauro Carvalho Chehab 	.name = KBUILD_MODNAME,
23880c0d06caSMauro Carvalho Chehab 	.id_table = device_table,
23890c0d06caSMauro Carvalho Chehab 	.probe = sd_probe,
23900c0d06caSMauro Carvalho Chehab 	.disconnect = gspca_disconnect,
23910c0d06caSMauro Carvalho Chehab #ifdef CONFIG_PM
23920c0d06caSMauro Carvalho Chehab 	.suspend = gspca_suspend,
23930c0d06caSMauro Carvalho Chehab 	.resume = gspca_resume,
23940c0d06caSMauro Carvalho Chehab 	.reset_resume = gspca_resume,
23950c0d06caSMauro Carvalho Chehab #endif
23960c0d06caSMauro Carvalho Chehab };
23970c0d06caSMauro Carvalho Chehab 
23980c0d06caSMauro Carvalho Chehab module_usb_driver(sd_driver);
2399