blob: 6696b2ec34e969dd631a91ca2dbe6b3ac5fac1fd [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
2 * sonix sn9c102 (bayer) library
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003 *
Jean-François Moine75b79ff2011-03-13 16:07:25 -03004 * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
5 * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr
6 * Add Pas106 Stefano Mozzi (C) 2004
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Hans de Goede93627732008-09-04 16:20:12 -030023/* Some documentation on known sonixb registers:
24
25Reg Use
Hans de Goede0a76cb82011-01-05 13:55:43 -030026sn9c101 / sn9c102:
Hans de Goede93627732008-09-04 16:20:12 -0300270x10 high nibble red gain low nibble blue gain
280x11 low nibble green gain
Hans de Goede0a76cb82011-01-05 13:55:43 -030029sn9c103:
300x05 red gain 0-127
310x06 blue gain 0-127
320x07 green gain 0-127
33all:
340x08-0x0f i2c / 3wire registers
Hans de Goede93627732008-09-04 16:20:12 -0300350x12 hstart
360x13 vstart
370x15 hsize (hsize = register-value * 16)
380x16 vsize (vsize = register-value * 16)
390x17 bit 0 toggle compression quality (according to sn9c102 driver)
400x18 bit 7 enables compression, bit 4-5 set image down scaling:
41 00 scale 1, 01 scale 1/2, 10, scale 1/4
420x19 high-nibble is sensor clock divider, changes exposure on sensors which
43 use a clock generated by the bridge. Some sensors have their own clock.
440x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32)
450x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32)
460x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32)
470x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32)
48*/
49
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030050#define MODULE_NAME "sonixb"
51
Hans de Goedef65e93d2010-01-31 10:35:15 -030052#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030053#include "gspca.h"
54
Jean-François Moine75b79ff2011-03-13 16:07:25 -030055MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030056MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
57MODULE_LICENSE("GPL");
58
59/* specific webcam descriptor */
60struct sd {
61 struct gspca_dev gspca_dev; /* !! must be the first item */
Jean-François Moinef51a8ca2011-03-13 15:04:11 -030062
Hans de Goede9153ac32012-05-15 04:23:55 -030063 struct v4l2_ctrl *brightness;
64 struct v4l2_ctrl *plfreq;
Jean-François Moinef51a8ca2011-03-13 15:04:11 -030065
Hans de Goededcef3232008-07-10 10:40:53 -030066 atomic_t avg_lum;
Hans de Goedebf2a2202008-09-04 16:22:56 -030067 int prev_avg_lum;
Hans de Goede9153ac32012-05-15 04:23:55 -030068 int exposure_knee;
Hans de Goede2b3e2842010-12-12 08:55:04 -030069 int header_read;
70 u8 header[12]; /* Header without sof marker */
Hans de Goededcef3232008-07-10 10:40:53 -030071
Hans de Goededcef3232008-07-10 10:40:53 -030072 unsigned char autogain_ignore_frames;
Hans de Goede6af492e2008-07-22 07:09:33 -030073 unsigned char frames_to_drop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030074
Hans de Goedef45f06b2008-09-03 17:12:21 -030075 __u8 bridge; /* Type of bridge */
76#define BRIDGE_101 0
77#define BRIDGE_102 0 /* We make no difference between 101 and 102 */
78#define BRIDGE_103 1
79
80 __u8 sensor; /* Type of image sensor chip */
Hans de Goede00765f12010-12-12 15:55:03 -030081#define SENSOR_HV7131D 0
82#define SENSOR_HV7131R 1
83#define SENSOR_OV6650 2
84#define SENSOR_OV7630 3
85#define SENSOR_PAS106 4
86#define SENSOR_PAS202 5
87#define SENSOR_TAS5110C 6
88#define SENSOR_TAS5110D 7
89#define SENSOR_TAS5130CXX 8
Hans de Goede6af492e2008-07-22 07:09:33 -030090 __u8 reg11;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030091};
92
Hans de Goedef45f06b2008-09-03 17:12:21 -030093typedef const __u8 sensor_init_t[8];
94
95struct sensor_data {
Hans de Goede0a76cb82011-01-05 13:55:43 -030096 const __u8 *bridge_init;
Hans de Goedef45f06b2008-09-03 17:12:21 -030097 sensor_init_t *sensor_init;
98 int sensor_init_size;
Hans de Goedef45f06b2008-09-03 17:12:21 -030099 int flags;
Hans de Goedef45f06b2008-09-03 17:12:21 -0300100 __u8 sensor_addr;
101};
102
103/* sensor_data flags */
Hans de Goede9153ac32012-05-15 04:23:55 -0300104#define F_SIF 0x01 /* sif or vga */
Hans de Goedec437d652008-09-03 17:12:22 -0300105
106/* priv field of struct v4l2_pix_format flags (do not use low nibble!) */
107#define MODE_RAW 0x10 /* raw bayer mode */
Hans de Goede93627732008-09-04 16:20:12 -0300108#define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300109
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300110#define COMP 0xc7 /* 0x87 //0x07 */
111#define COMP1 0xc9 /* 0x89 //0x09 */
112
113#define MCK_INIT 0x63
114#define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
115
116#define SYS_CLK 0x04
117
Hans de Goede9153ac32012-05-15 04:23:55 -0300118#define SENS(bridge, sensor, _flags, _sensor_addr) \
Hans de Goedef45f06b2008-09-03 17:12:21 -0300119{ \
Hans de Goede0a76cb82011-01-05 13:55:43 -0300120 .bridge_init = bridge, \
Hans de Goedef45f06b2008-09-03 17:12:21 -0300121 .sensor_init = sensor, \
122 .sensor_init_size = sizeof(sensor), \
Hans de Goede9153ac32012-05-15 04:23:55 -0300123 .flags = _flags, .sensor_addr = _sensor_addr \
Hans de Goedef45f06b2008-09-03 17:12:21 -0300124}
125
Hans de Goededcef3232008-07-10 10:40:53 -0300126/* We calculate the autogain at the end of the transfer of a frame, at this
Hans de Goede26984b02010-02-01 13:18:37 -0300127 moment a frame with the old settings is being captured and transmitted. So
128 if we adjust the gain or exposure we must ignore atleast the next frame for
129 the new settings to come into effect before doing any other adjustments. */
130#define AUTOGAIN_IGNORE_FRAMES 1
Hans de Goededcef3232008-07-10 10:40:53 -0300131
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300132static const struct v4l2_pix_format vga_mode[] = {
Hans de Goedec437d652008-09-03 17:12:22 -0300133 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
134 .bytesperline = 160,
Mauro Carvalho Chehab2389b362008-08-06 20:13:46 -0300135 .sizeimage = 160 * 120,
Hans de Goedec437d652008-09-03 17:12:22 -0300136 .colorspace = V4L2_COLORSPACE_SRGB,
137 .priv = 2 | MODE_RAW},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300138 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
139 .bytesperline = 160,
Hans de Goede5c515182008-09-03 17:12:22 -0300140 .sizeimage = 160 * 120 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300141 .colorspace = V4L2_COLORSPACE_SRGB,
142 .priv = 2},
143 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
144 .bytesperline = 320,
Hans de Goede5c515182008-09-03 17:12:22 -0300145 .sizeimage = 320 * 240 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300146 .colorspace = V4L2_COLORSPACE_SRGB,
147 .priv = 1},
148 {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
149 .bytesperline = 640,
Hans de Goede5c515182008-09-03 17:12:22 -0300150 .sizeimage = 640 * 480 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300151 .colorspace = V4L2_COLORSPACE_SRGB,
152 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300153};
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300154static const struct v4l2_pix_format sif_mode[] = {
Hans de Goede93627732008-09-04 16:20:12 -0300155 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
156 .bytesperline = 160,
157 .sizeimage = 160 * 120,
158 .colorspace = V4L2_COLORSPACE_SRGB,
159 .priv = 1 | MODE_RAW | MODE_REDUCED_SIF},
160 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
161 .bytesperline = 160,
162 .sizeimage = 160 * 120 * 5 / 4,
163 .colorspace = V4L2_COLORSPACE_SRGB,
164 .priv = 1 | MODE_REDUCED_SIF},
Hans de Goedec437d652008-09-03 17:12:22 -0300165 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
166 .bytesperline = 176,
Mauro Carvalho Chehab2389b362008-08-06 20:13:46 -0300167 .sizeimage = 176 * 144,
Hans de Goedec437d652008-09-03 17:12:22 -0300168 .colorspace = V4L2_COLORSPACE_SRGB,
169 .priv = 1 | MODE_RAW},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300170 {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
171 .bytesperline = 176,
Hans de Goede5c515182008-09-03 17:12:22 -0300172 .sizeimage = 176 * 144 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300173 .colorspace = V4L2_COLORSPACE_SRGB,
174 .priv = 1},
Hans de Goede93627732008-09-04 16:20:12 -0300175 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
176 .bytesperline = 320,
177 .sizeimage = 320 * 240 * 5 / 4,
178 .colorspace = V4L2_COLORSPACE_SRGB,
179 .priv = 0 | MODE_REDUCED_SIF},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300180 {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
181 .bytesperline = 352,
Hans de Goede5c515182008-09-03 17:12:22 -0300182 .sizeimage = 352 * 288 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300183 .colorspace = V4L2_COLORSPACE_SRGB,
184 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185};
186
Hans de Goede00765f12010-12-12 15:55:03 -0300187static const __u8 initHv7131d[] = {
188 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
189 0x00, 0x00,
190 0x00, 0x00, 0x00, 0x02, 0x02, 0x00,
191 0x28, 0x1e, 0x60, 0x8e, 0x42,
Hans de Goede00765f12010-12-12 15:55:03 -0300192};
193static const __u8 hv7131d_sensor_init[][8] = {
194 {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17},
195 {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17},
196 {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17},
197 {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17}, /* reset level */
198 {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17}, /* pixel bias volt */
199};
200
201static const __u8 initHv7131r[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300202 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
203 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300204 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300205 0x28, 0x1e, 0x60, 0x8a, 0x20,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300206};
Hans de Goede00765f12010-12-12 15:55:03 -0300207static const __u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300208 {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
209 {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
210 {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
211 {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
212 {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
213};
214static const __u8 initOv6650[] = {
215 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
216 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300217 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b,
Hans de Goede0a76cb82011-01-05 13:55:43 -0300218 0x10,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300219};
Jean-François Moine780e3122010-10-19 04:29:10 -0300220static const __u8 ov6650_sensor_init[][8] = {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200221 /* Bright, contrast, etc are set through SCBB interface.
Jean-François Moine780e3122010-10-19 04:29:10 -0300222 * AVCAP on win2 do not send any data on this controls. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300223 /* Anyway, some registers appears to alter bright and constrat */
Hans de Goededcef3232008-07-10 10:40:53 -0300224
225 /* Reset sensor */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300226 {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
Hans de Goededcef3232008-07-10 10:40:53 -0300227 /* Set clock register 0x11 low nibble is clock divider */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300228 {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
Hans de Goededcef3232008-07-10 10:40:53 -0300229 /* Next some unknown stuff */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300230 {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
231/* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
232 * THIS SET GREEN SCREEN
233 * (pixels could be innverted in decode kind of "brg",
234 * but blue wont be there. Avoid this data ... */
235 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
236 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
Jean-François Moine1d00d6c2010-10-29 13:58:22 -0300237 {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10},
Hans de Goede722103e2008-07-17 10:24:47 -0300238 /* Enable rgb brightness control */
239 {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
240 /* HDG: Note windows uses the line below, which sets both register 0x60
241 and 0x61 I believe these registers of the ov6650 are identical as
242 those of the ov7630, because if this is true the windows settings
243 add a bit additional red gain and a lot additional blue gain, which
244 matches my findings that the windows settings make blue much too
245 blue and red a little too red.
246 {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */
Hans de Goededcef3232008-07-10 10:40:53 -0300247 /* Some more unknown stuff */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300248 {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
249 {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300250};
Hans de Goededcef3232008-07-10 10:40:53 -0300251
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300252static const __u8 initOv7630[] = {
253 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
254 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
Hans de Goedec437d652008-09-03 17:12:22 -0300255 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300256 0x28, 0x1e, /* H & V sizes r15 .. r16 */
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300257 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300258};
Hans de Goede6af492e2008-07-22 07:09:33 -0300259static const __u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300260 {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
261 {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
262/* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
Hans de Goede4c775902011-01-07 07:29:24 -0300263 {0xd0, 0x21, 0x12, 0x5c, 0x00, 0x80, 0x34, 0x10}, /* jfm */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300264 {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
265 {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
266 {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
267 {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
268 {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
269 {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
270 {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
Andoni Zubimendi794af522008-07-16 08:33:14 -0300271 {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},
272/* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300273 {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
274 {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
275 {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
276 {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
277 {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
278 {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
279};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300280
281static const __u8 initPas106[] = {
282 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
283 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300284 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
Hans de Goedef45f06b2008-09-03 17:12:21 -0300285 0x16, 0x12, 0x24, COMP1, MCK_INIT1,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300286};
287/* compression 0x86 mckinit1 0x2b */
Hans de Goede421763e2010-02-10 18:57:40 -0300288
289/* "Known" PAS106B registers:
290 0x02 clock divider
291 0x03 Variable framerate bits 4-11
292 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !!
293 The variable framerate control must never be set lower then 300,
294 which sets the framerate at 90 / reg02, otherwise vsync is lost.
295 0x05 Shutter Time Line Offset, this can be used as an exposure control:
296 0 = use full frame time, 255 = no exposure at all
297 Note this may never be larger then "var-framerate control" / 2 - 2.
298 When var-framerate control is < 514, no exposure is reached at the max
299 allowed value for the framerate control value, rather then at 255.
300 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but
301 only a very little bit, leave at 0xcd
302 0x07 offset sign bit (bit0 1 > negative offset)
303 0x08 offset
304 0x09 Blue Gain
305 0x0a Green1 Gain
306 0x0b Green2 Gain
307 0x0c Red Gain
308 0x0e Global gain
309 0x13 Write 1 to commit settings to sensor
310*/
311
Hans de Goedef45f06b2008-09-03 17:12:21 -0300312static const __u8 pas106_sensor_init[][8] = {
313 /* Pixel Clock Divider 6 */
314 { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },
315 /* Frame Time MSB (also seen as 0x12) */
316 { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 },
317 /* Frame Time LSB (also seen as 0x05) */
318 { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 },
319 /* Shutter Time Line Offset (also seen as 0x6d) */
320 { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 },
321 /* Shutter Time Pixel Offset (also seen as 0xb1) */
322 { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 },
323 /* Black Level Subtract Sign (also seen 0x00) */
324 { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 },
325 /* Black Level Subtract Level (also seen 0x01) */
326 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
327 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
328 /* Color Gain B Pixel 5 a */
329 { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 },
330 /* Color Gain G1 Pixel 1 5 */
331 { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 },
332 /* Color Gain G2 Pixel 1 0 5 */
333 { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 },
334 /* Color Gain R Pixel 3 1 */
335 { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 },
336 /* Color GainH Pixel */
337 { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 },
338 /* Global Gain */
339 { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 },
340 /* Contrast */
341 { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 },
342 /* H&V synchro polarity */
343 { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 },
344 /* ?default */
345 { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 },
346 /* DAC scale */
347 { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 },
348 /* ?default */
349 { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 },
350 /* Validate Settings */
351 { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300352};
Hans de Goedef45f06b2008-09-03 17:12:21 -0300353
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300354static const __u8 initPas202[] = {
355 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
356 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300357 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a,
Hans de Goede82e839c2010-02-03 14:37:30 -0300358 0x28, 0x1e, 0x20, 0x89, 0x20,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300359};
Hans de Goede82e839c2010-02-03 14:37:30 -0300360
361/* "Known" PAS202BCB registers:
362 0x02 clock divider
363 0x04 Variable framerate bits 6-11 (*)
364 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !!
365 0x07 Blue Gain
366 0x08 Green Gain
367 0x09 Red Gain
368 0x0b offset sign bit (bit0 1 > negative offset)
369 0x0c offset
370 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too,
371 leave at 1 otherwise we get a jump in our exposure control
372 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all
373 0x10 Master gain 0 - 31
374 0x11 write 1 to apply changes
375 (*) The variable framerate control must never be set lower then 500
376 which sets the framerate at 30 / reg02, otherwise vsync is lost.
377*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300378static const __u8 pas202_sensor_init[][8] = {
Hans de Goede82e839c2010-02-03 14:37:30 -0300379 /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like
380 to set it lower, but for some reason the bridge starts missing
381 vsync's then */
382 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300383 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
384 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
Jean-François Moine1d00d6c2010-10-29 13:58:22 -0300385 {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300386 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
387 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
388 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
389 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
390 {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
391 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300392};
393
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300394static const __u8 initTas5110c[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300395 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
396 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300397 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300398 0x16, 0x12, 0x60, 0x86, 0x2b,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300399};
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300400/* Same as above, except a different hstart */
401static const __u8 initTas5110d[] = {
402 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
403 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300404 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a,
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300405 0x16, 0x12, 0x60, 0x86, 0x2b,
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300406};
Hans de Goede0d0d7ef2011-01-06 07:55:20 -0300407/* tas5110c is 3 wire, tas5110d is 2 wire (regular i2c) */
408static const __u8 tas5110c_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300409 {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
410 {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
Hans de Goede0d0d7ef2011-01-06 07:55:20 -0300411};
412/* Known TAS5110D registers
413 * reg02: gain, bit order reversed!! 0 == max gain, 255 == min gain
414 * reg03: bit3: vflip, bit4: ~hflip, bit7: ~gainboost (~ == inverted)
415 * Note: writing reg03 seems to only work when written together with 02
416 */
417static const __u8 tas5110d_sensor_init[][8] = {
418 {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17}, /* reset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300419};
420
421static const __u8 initTas5130[] = {
422 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
423 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300424 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300425 0x28, 0x1e, 0x60, COMP, MCK_INIT,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300426};
427static const __u8 tas5130_sensor_init[][8] = {
Jean-François Moine780e3122010-10-19 04:29:10 -0300428/* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300429 * shutter 0x47 short exposure? */
430 {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
431 /* shutter 0x01 long exposure */
432 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
433};
434
Jean-François Moine75b79ff2011-03-13 16:07:25 -0300435static const struct sensor_data sensor_data[] = {
Hans de Goede9153ac32012-05-15 04:23:55 -0300436 SENS(initHv7131d, hv7131d_sensor_init, 0, 0),
437 SENS(initHv7131r, hv7131r_sensor_init, 0, 0),
438 SENS(initOv6650, ov6650_sensor_init, F_SIF, 0x60),
439 SENS(initOv7630, ov7630_sensor_init, 0, 0x21),
440 SENS(initPas106, pas106_sensor_init, F_SIF, 0),
441 SENS(initPas202, pas202_sensor_init, 0, 0),
442 SENS(initTas5110c, tas5110c_sensor_init, F_SIF, 0),
443 SENS(initTas5110d, tas5110d_sensor_init, F_SIF, 0),
444 SENS(initTas5130, tas5130_sensor_init, 0, 0),
Hans de Goedef45f06b2008-09-03 17:12:21 -0300445};
446
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300447/* get one byte in gspca_dev->usb_buf */
448static void reg_r(struct gspca_dev *gspca_dev,
449 __u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300450{
Hans de Goede4848ea72012-05-14 15:21:25 -0300451 int res;
452
453 if (gspca_dev->usb_err < 0)
454 return;
455
456 res = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300457 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300458 0, /* request */
459 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
460 value,
461 0, /* index */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300462 gspca_dev->usb_buf, 1,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300463 500);
Hans de Goede4848ea72012-05-14 15:21:25 -0300464
465 if (res < 0) {
466 dev_err(gspca_dev->v4l2_dev.dev,
467 "Error reading register %02x: %d\n", value, res);
468 gspca_dev->usb_err = res;
469 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300470}
471
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300472static void reg_w(struct gspca_dev *gspca_dev,
473 __u16 value,
474 const __u8 *buffer,
475 int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300476{
Hans de Goede4848ea72012-05-14 15:21:25 -0300477 int res;
478
479 if (gspca_dev->usb_err < 0)
Hans de Goede0d2a7222008-07-03 08:15:22 -0300480 return;
Hans de Goede4848ea72012-05-14 15:21:25 -0300481
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300482 memcpy(gspca_dev->usb_buf, buffer, len);
Hans de Goede4848ea72012-05-14 15:21:25 -0300483 res = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300484 usb_sndctrlpipe(gspca_dev->dev, 0),
485 0x08, /* request */
486 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
487 value,
488 0, /* index */
489 gspca_dev->usb_buf, len,
490 500);
Hans de Goede4848ea72012-05-14 15:21:25 -0300491
492 if (res < 0) {
493 dev_err(gspca_dev->v4l2_dev.dev,
494 "Error writing register %02x: %d\n", value, res);
495 gspca_dev->usb_err = res;
496 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300497}
498
Hans de Goede18fa0d32012-12-21 08:08:47 -0300499static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300500{
501 int retry = 60;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502
Hans de Goede4848ea72012-05-14 15:21:25 -0300503 if (gspca_dev->usb_err < 0)
504 return;
505
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300506 /* is i2c ready */
Hans de Goede18fa0d32012-12-21 08:08:47 -0300507 reg_w(gspca_dev, 0x08, buf, 8);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300508 while (retry--) {
Hans de Goede4848ea72012-05-14 15:21:25 -0300509 if (gspca_dev->usb_err < 0)
510 return;
Hans de Goede18fa0d32012-12-21 08:08:47 -0300511 msleep(1);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300512 reg_r(gspca_dev, 0x08);
Andoni Zubimendib7474cf92008-07-16 08:40:30 -0300513 if (gspca_dev->usb_buf[0] & 0x04) {
Hans de Goede4848ea72012-05-14 15:21:25 -0300514 if (gspca_dev->usb_buf[0] & 0x08) {
515 dev_err(gspca_dev->v4l2_dev.dev,
Andy Shevchenkoee35fa22013-09-03 09:31:37 -0300516 "i2c error writing %8ph\n", buf);
Hans de Goede4848ea72012-05-14 15:21:25 -0300517 gspca_dev->usb_err = -EIO;
518 }
519 return;
Andoni Zubimendib7474cf92008-07-16 08:40:30 -0300520 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300521 }
Hans de Goede4848ea72012-05-14 15:21:25 -0300522
523 dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n");
524 gspca_dev->usb_err = -EIO;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300525}
526
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300527static void i2c_w_vector(struct gspca_dev *gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300528 const __u8 buffer[][8], int len)
529{
530 for (;;) {
Hans de Goede4848ea72012-05-14 15:21:25 -0300531 if (gspca_dev->usb_err < 0)
532 return;
Hans de Goede18fa0d32012-12-21 08:08:47 -0300533 i2c_w(gspca_dev, *buffer);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300534 len -= 8;
535 if (len <= 0)
536 break;
537 buffer++;
538 }
539}
540
541static void setbrightness(struct gspca_dev *gspca_dev)
542{
543 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300544
545 switch (sd->sensor) {
Hans de Goedea975a522008-07-16 15:29:11 -0300546 case SENSOR_OV6650:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300547 case SENSOR_OV7630: {
548 __u8 i2cOV[] =
Hans de Goedea975a522008-07-16 15:29:11 -0300549 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300550
551 /* change reg 0x06 */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300552 i2cOV[1] = sensor_data[sd->sensor].sensor_addr;
Hans de Goede9153ac32012-05-15 04:23:55 -0300553 i2cOV[3] = sd->brightness->val;
Hans de Goede4848ea72012-05-14 15:21:25 -0300554 i2c_w(gspca_dev, i2cOV);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300555 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300556 }
Hans de Goede421763e2010-02-10 18:57:40 -0300557 case SENSOR_PAS106:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300558 case SENSOR_PAS202: {
Hans de Goede82e839c2010-02-03 14:37:30 -0300559 __u8 i2cpbright[] =
560 {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
Hans de Goede421763e2010-02-10 18:57:40 -0300561 __u8 i2cpdoit[] =
Hans de Goede82e839c2010-02-03 14:37:30 -0300562 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300563
Hans de Goede421763e2010-02-10 18:57:40 -0300564 /* PAS106 uses reg 7 and 8 instead of b and c */
565 if (sd->sensor == SENSOR_PAS106) {
566 i2cpbright[2] = 7;
567 i2cpdoit[2] = 0x13;
568 }
569
Hans de Goede9153ac32012-05-15 04:23:55 -0300570 if (sd->brightness->val < 127) {
Hans de Goede82e839c2010-02-03 14:37:30 -0300571 /* change reg 0x0b, signreg */
572 i2cpbright[3] = 0x01;
573 /* set reg 0x0c, offset */
Hans de Goede9153ac32012-05-15 04:23:55 -0300574 i2cpbright[4] = 127 - sd->brightness->val;
Hans de Goede82e839c2010-02-03 14:37:30 -0300575 } else
Hans de Goede9153ac32012-05-15 04:23:55 -0300576 i2cpbright[4] = sd->brightness->val - 127;
Hans de Goede82e839c2010-02-03 14:37:30 -0300577
Hans de Goede4848ea72012-05-14 15:21:25 -0300578 i2c_w(gspca_dev, i2cpbright);
579 i2c_w(gspca_dev, i2cpdoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300580 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300581 }
Hans de Goede4848ea72012-05-14 15:21:25 -0300582 default:
583 break;
584 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300585}
Hans de Goededcef3232008-07-10 10:40:53 -0300586
Hans de Goede9153ac32012-05-15 04:23:55 -0300587static void setgain(struct gspca_dev *gspca_dev)
Hans de Goededcef3232008-07-10 10:40:53 -0300588{
589 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede9153ac32012-05-15 04:23:55 -0300590 u8 gain = gspca_dev->gain->val;
Hans de Goededcef3232008-07-10 10:40:53 -0300591
592 switch (sd->sensor) {
Hans de Goede00765f12010-12-12 15:55:03 -0300593 case SENSOR_HV7131D: {
594 __u8 i2c[] =
595 {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17};
Hans de Goededcef3232008-07-10 10:40:53 -0300596
Hans de Goede9153ac32012-05-15 04:23:55 -0300597 i2c[3] = 0x3f - gain;
598 i2c[4] = 0x3f - gain;
599 i2c[5] = 0x3f - gain;
Hans de Goede00765f12010-12-12 15:55:03 -0300600
Hans de Goede4848ea72012-05-14 15:21:25 -0300601 i2c_w(gspca_dev, i2c);
Hans de Goede00765f12010-12-12 15:55:03 -0300602 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300603 }
Hans de Goede4e17cd22011-01-06 10:58:53 -0300604 case SENSOR_TAS5110C:
605 case SENSOR_TAS5130CXX: {
Hans de Goededcef3232008-07-10 10:40:53 -0300606 __u8 i2c[] =
607 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
608
Hans de Goedea975a522008-07-16 15:29:11 -0300609 i2c[4] = 255 - gain;
Hans de Goede4848ea72012-05-14 15:21:25 -0300610 i2c_w(gspca_dev, i2c);
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300611 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300612 }
Hans de Goede0d0d7ef2011-01-06 07:55:20 -0300613 case SENSOR_TAS5110D: {
614 __u8 i2c[] = {
615 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 };
616 gain = 255 - gain;
617 /* The bits in the register are the wrong way around!! */
618 i2c[3] |= (gain & 0x80) >> 7;
619 i2c[3] |= (gain & 0x40) >> 5;
620 i2c[3] |= (gain & 0x20) >> 3;
621 i2c[3] |= (gain & 0x10) >> 1;
622 i2c[3] |= (gain & 0x08) << 1;
623 i2c[3] |= (gain & 0x04) << 3;
624 i2c[3] |= (gain & 0x02) << 5;
625 i2c[3] |= (gain & 0x01) << 7;
Hans de Goede4848ea72012-05-14 15:21:25 -0300626 i2c_w(gspca_dev, i2c);
Hans de Goede0d0d7ef2011-01-06 07:55:20 -0300627 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300628 }
Hans de Goedea975a522008-07-16 15:29:11 -0300629 case SENSOR_OV6650:
Hans de Goede6af492e2008-07-22 07:09:33 -0300630 case SENSOR_OV7630: {
Hans de Goedea975a522008-07-16 15:29:11 -0300631 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
Andoni Zubimendi794af522008-07-16 08:33:14 -0300632
Hans de Goede8b3a19b2012-05-16 07:14:54 -0300633 /*
634 * The ov7630's gain is weird, at 32 the gain drops to the
635 * same level as at 16, so skip 32-47 (of the 0-63 scale).
636 */
637 if (sd->sensor == SENSOR_OV7630 && gain >= 32)
638 gain += 16;
639
Hans de Goedef45f06b2008-09-03 17:12:21 -0300640 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Hans de Goede9153ac32012-05-15 04:23:55 -0300641 i2c[3] = gain;
Hans de Goede4848ea72012-05-14 15:21:25 -0300642 i2c_w(gspca_dev, i2c);
Andoni Zubimendi794af522008-07-16 08:33:14 -0300643 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300644 }
Hans de Goede421763e2010-02-10 18:57:40 -0300645 case SENSOR_PAS106:
Hans de Goede82e839c2010-02-03 14:37:30 -0300646 case SENSOR_PAS202: {
647 __u8 i2cpgain[] =
Hans de Goede421763e2010-02-10 18:57:40 -0300648 {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
Hans de Goede82e839c2010-02-03 14:37:30 -0300649 __u8 i2cpcolorgain[] =
650 {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
Hans de Goede421763e2010-02-10 18:57:40 -0300651 __u8 i2cpdoit[] =
652 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
653
654 /* PAS106 uses different regs (and has split green gains) */
655 if (sd->sensor == SENSOR_PAS106) {
656 i2cpgain[2] = 0x0e;
657 i2cpcolorgain[0] = 0xd0;
658 i2cpcolorgain[2] = 0x09;
659 i2cpdoit[2] = 0x13;
660 }
Hans de Goede82e839c2010-02-03 14:37:30 -0300661
Hans de Goede9153ac32012-05-15 04:23:55 -0300662 i2cpgain[3] = gain;
663 i2cpcolorgain[3] = gain >> 1;
664 i2cpcolorgain[4] = gain >> 1;
665 i2cpcolorgain[5] = gain >> 1;
666 i2cpcolorgain[6] = gain >> 1;
Hans de Goede82e839c2010-02-03 14:37:30 -0300667
Hans de Goede4848ea72012-05-14 15:21:25 -0300668 i2c_w(gspca_dev, i2cpgain);
669 i2c_w(gspca_dev, i2cpcolorgain);
670 i2c_w(gspca_dev, i2cpdoit);
Hans de Goede82e839c2010-02-03 14:37:30 -0300671 break;
Hans de Goededcef3232008-07-10 10:40:53 -0300672 }
Hans de Goede4848ea72012-05-14 15:21:25 -0300673 default:
Hans de Goede9153ac32012-05-15 04:23:55 -0300674 if (sd->bridge == BRIDGE_103) {
675 u8 buf[3] = { gain, gain, gain }; /* R, G, B */
676 reg_w(gspca_dev, 0x05, buf, 3);
677 } else {
678 u8 buf[2];
679 buf[0] = gain << 4 | gain; /* Red and blue */
680 buf[1] = gain; /* Green */
681 reg_w(gspca_dev, 0x10, buf, 2);
682 }
Hans de Goede0a76cb82011-01-05 13:55:43 -0300683 }
Hans de Goededcef3232008-07-10 10:40:53 -0300684}
685
686static void setexposure(struct gspca_dev *gspca_dev)
687{
688 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goededcef3232008-07-10 10:40:53 -0300689
690 switch (sd->sensor) {
Hans de Goede00765f12010-12-12 15:55:03 -0300691 case SENSOR_HV7131D: {
692 /* Note the datasheet wrongly says line mode exposure uses reg
693 0x26 and 0x27, testing has shown 0x25 + 0x26 */
694 __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17};
Hans de Goede9153ac32012-05-15 04:23:55 -0300695 u16 reg = gspca_dev->exposure->val;
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300696
Hans de Goede00765f12010-12-12 15:55:03 -0300697 i2c[3] = reg >> 8;
698 i2c[4] = reg & 0xff;
Hans de Goede4848ea72012-05-14 15:21:25 -0300699 i2c_w(gspca_dev, i2c);
Hans de Goede00765f12010-12-12 15:55:03 -0300700 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300701 }
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300702 case SENSOR_TAS5110C:
703 case SENSOR_TAS5110D: {
Hans de Goededcef3232008-07-10 10:40:53 -0300704 /* register 19's high nibble contains the sn9c10x clock divider
705 The high nibble configures the no fps according to the
706 formula: 60 / high_nibble. With a maximum of 30 fps */
Hans de Goede9153ac32012-05-15 04:23:55 -0300707 u8 reg = gspca_dev->exposure->val;
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300708
Hans de Goededcef3232008-07-10 10:40:53 -0300709 reg = (reg << 4) | 0x0b;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300710 reg_w(gspca_dev, 0x19, &reg, 1);
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300711 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300712 }
Hans de Goedea975a522008-07-16 15:29:11 -0300713 case SENSOR_OV6650:
Hans de Goede6af492e2008-07-22 07:09:33 -0300714 case SENSOR_OV7630: {
Hans de Goedea975a522008-07-16 15:29:11 -0300715 /* The ov6650 / ov7630 have 2 registers which both influence
716 exposure, register 11, whose low nibble sets the nr off fps
Hans de Goedef4d52022008-07-15 09:36:42 -0300717 according to: fps = 30 / (low_nibble + 1)
718
719 The fps configures the maximum exposure setting, but it is
720 possible to use less exposure then what the fps maximum
721 allows by setting register 10. register 10 configures the
722 actual exposure as quotient of the full exposure, with 0
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300723 being no exposure at all (not very useful) and reg10_max
Hans de Goedef4d52022008-07-15 09:36:42 -0300724 being max exposure possible at that framerate.
725
726 The code maps our 0 - 510 ms exposure ctrl to these 2
727 registers, trying to keep fps as high as possible.
728 */
Hans de Goede6af492e2008-07-22 07:09:33 -0300729 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
730 int reg10, reg11, reg10_max;
731
Hans de Goede66f35822008-07-16 10:16:28 -0300732 /* ov6645 datasheet says reg10_max is 9a, but that uses
733 tline * 2 * reg10 as formula for calculating texpo, the
734 ov6650 probably uses the same formula as the 7730 which uses
735 tline * 4 * reg10, which explains why the reg10max we've
736 found experimentally for the ov6650 is exactly half that of
Hans de Goedea975a522008-07-16 15:29:11 -0300737 the ov6645. The ov7630 datasheet says the max is 0x41. */
Hans de Goede6af492e2008-07-22 07:09:33 -0300738 if (sd->sensor == SENSOR_OV6650) {
739 reg10_max = 0x4d;
740 i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */
741 } else
742 reg10_max = 0x41;
Hans de Goedef4d52022008-07-15 09:36:42 -0300743
Hans de Goede9153ac32012-05-15 04:23:55 -0300744 reg11 = (15 * gspca_dev->exposure->val + 999) / 1000;
Hans de Goedef4d52022008-07-15 09:36:42 -0300745 if (reg11 < 1)
746 reg11 = 1;
747 else if (reg11 > 16)
748 reg11 = 16;
749
Hans de Goede10bb7532010-02-04 06:10:55 -0300750 /* In 640x480, if the reg11 has less than 4, the image is
751 unstable (the bridge goes into a higher compression mode
752 which we have not reverse engineered yet). */
Ondrej Zary1966bc22013-08-30 17:54:23 -0300753 if (gspca_dev->pixfmt.width == 640 && reg11 < 4)
Hans de Goede10bb7532010-02-04 06:10:55 -0300754 reg11 = 4;
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300755
Hans de Goedef4d52022008-07-15 09:36:42 -0300756 /* frame exposure time in ms = 1000 * reg11 / 30 ->
Hans de Goede9153ac32012-05-15 04:23:55 -0300757 reg10 = (gspca_dev->exposure->val / 2) * reg10_max
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300758 / (1000 * reg11 / 30) */
Hans de Goede9153ac32012-05-15 04:23:55 -0300759 reg10 = (gspca_dev->exposure->val * 15 * reg10_max)
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300760 / (1000 * reg11);
Hans de Goedea975a522008-07-16 15:29:11 -0300761
762 /* Don't allow this to get below 10 when using autogain, the
763 steps become very large (relatively) when below 10 causing
764 the image to oscilate from much too dark, to much too bright
765 and back again. */
Hans de Goede9153ac32012-05-15 04:23:55 -0300766 if (gspca_dev->autogain->val && reg10 < 10)
Hans de Goedea975a522008-07-16 15:29:11 -0300767 reg10 = 10;
Hans de Goedef4d52022008-07-15 09:36:42 -0300768 else if (reg10 > reg10_max)
769 reg10 = reg10_max;
770
771 /* Write reg 10 and reg11 low nibble */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300772 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Andoni Zubimendi794af522008-07-16 08:33:14 -0300773 i2c[3] = reg10;
774 i2c[4] |= reg11 - 1;
Hans de Goede6af492e2008-07-22 07:09:33 -0300775
776 /* If register 11 didn't change, don't change it */
Jean-François Moine780e3122010-10-19 04:29:10 -0300777 if (sd->reg11 == reg11)
Hans de Goede6af492e2008-07-22 07:09:33 -0300778 i2c[0] = 0xa0;
779
Hans de Goede4848ea72012-05-14 15:21:25 -0300780 i2c_w(gspca_dev, i2c);
781 if (gspca_dev->usb_err == 0)
Hans de Goede6af492e2008-07-22 07:09:33 -0300782 sd->reg11 = reg11;
Hans de Goede82e839c2010-02-03 14:37:30 -0300783 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300784 }
Hans de Goede82e839c2010-02-03 14:37:30 -0300785 case SENSOR_PAS202: {
786 __u8 i2cpframerate[] =
787 {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
788 __u8 i2cpexpo[] =
789 {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
790 const __u8 i2cpdoit[] =
791 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
792 int framerate_ctrl;
793
794 /* The exposure knee for the autogain algorithm is 200
795 (100 ms / 10 fps on other sensors), for values below this
796 use the control for setting the partial frame expose time,
797 above that use variable framerate. This way we run at max
798 framerate (640x480@7.5 fps, 320x240@10fps) until the knee
799 is reached. Using the variable framerate control above 200
800 is better then playing around with both clockdiv + partial
801 frame exposure times (like we are doing with the ov chips),
802 as that sometimes leads to jumps in the exposure control,
803 which are bad for auto exposure. */
Hans de Goede9153ac32012-05-15 04:23:55 -0300804 if (gspca_dev->exposure->val < 200) {
805 i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255)
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300806 / 200;
Hans de Goede82e839c2010-02-03 14:37:30 -0300807 framerate_ctrl = 500;
808 } else {
809 /* The PAS202's exposure control goes from 0 - 4095,
810 but anything below 500 causes vsync issues, so scale
811 our 200-1023 to 500-4095 */
Hans de Goede9153ac32012-05-15 04:23:55 -0300812 framerate_ctrl = (gspca_dev->exposure->val - 200)
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300813 * 1000 / 229 + 500;
Hans de Goede82e839c2010-02-03 14:37:30 -0300814 }
815
816 i2cpframerate[3] = framerate_ctrl >> 6;
817 i2cpframerate[4] = framerate_ctrl & 0x3f;
Hans de Goede4848ea72012-05-14 15:21:25 -0300818 i2c_w(gspca_dev, i2cpframerate);
819 i2c_w(gspca_dev, i2cpexpo);
820 i2c_w(gspca_dev, i2cpdoit);
Andoni Zubimendi794af522008-07-16 08:33:14 -0300821 break;
Hans de Goede4848ea72012-05-14 15:21:25 -0300822 }
Hans de Goede421763e2010-02-10 18:57:40 -0300823 case SENSOR_PAS106: {
824 __u8 i2cpframerate[] =
825 {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
826 __u8 i2cpexpo[] =
827 {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
828 const __u8 i2cpdoit[] =
829 {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
830 int framerate_ctrl;
831
832 /* For values below 150 use partial frame exposure, above
833 that use framerate ctrl */
Hans de Goede9153ac32012-05-15 04:23:55 -0300834 if (gspca_dev->exposure->val < 150) {
835 i2cpexpo[3] = 150 - gspca_dev->exposure->val;
Hans de Goede421763e2010-02-10 18:57:40 -0300836 framerate_ctrl = 300;
837 } else {
838 /* The PAS106's exposure control goes from 0 - 4095,
839 but anything below 300 causes vsync issues, so scale
840 our 150-1023 to 300-4095 */
Hans de Goede9153ac32012-05-15 04:23:55 -0300841 framerate_ctrl = (gspca_dev->exposure->val - 150)
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300842 * 1000 / 230 + 300;
Hans de Goede421763e2010-02-10 18:57:40 -0300843 }
844
845 i2cpframerate[3] = framerate_ctrl >> 4;
846 i2cpframerate[4] = framerate_ctrl & 0x0f;
Hans de Goede4848ea72012-05-14 15:21:25 -0300847 i2c_w(gspca_dev, i2cpframerate);
848 i2c_w(gspca_dev, i2cpexpo);
849 i2c_w(gspca_dev, i2cpdoit);
Hans de Goede421763e2010-02-10 18:57:40 -0300850 break;
Hans de Goededcef3232008-07-10 10:40:53 -0300851 }
Hans de Goede4848ea72012-05-14 15:21:25 -0300852 default:
853 break;
854 }
Hans de Goededcef3232008-07-10 10:40:53 -0300855}
856
Hans de Goede66f35822008-07-16 10:16:28 -0300857static void setfreq(struct gspca_dev *gspca_dev)
858{
859 struct sd *sd = (struct sd *) gspca_dev;
860
Hans de Goede4848ea72012-05-14 15:21:25 -0300861 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) {
Hans de Goede66f35822008-07-16 10:16:28 -0300862 /* Framerate adjust register for artificial light 50 hz flicker
Hans de Goede6af492e2008-07-22 07:09:33 -0300863 compensation, for the ov6650 this is identical to ov6630
864 0x2b register, see ov6630 datasheet.
865 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */
Andoni Zubimendid87616f2008-07-17 05:35:52 -0300866 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
Hans de Goede9153ac32012-05-15 04:23:55 -0300867 switch (sd->plfreq->val) {
Hans de Goede66f35822008-07-16 10:16:28 -0300868 default:
869/* case 0: * no filter*/
870/* case 2: * 60 hz */
871 i2c[3] = 0;
872 break;
873 case 1: /* 50 hz */
Hans de Goede722103e2008-07-17 10:24:47 -0300874 i2c[3] = (sd->sensor == SENSOR_OV6650)
875 ? 0x4f : 0x8a;
Hans de Goede66f35822008-07-16 10:16:28 -0300876 break;
877 }
Hans de Goedef45f06b2008-09-03 17:12:21 -0300878 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Hans de Goede4848ea72012-05-14 15:21:25 -0300879 i2c_w(gspca_dev, i2c);
Hans de Goede66f35822008-07-16 10:16:28 -0300880 }
881}
882
Hans de Goededcef3232008-07-10 10:40:53 -0300883static void do_autogain(struct gspca_dev *gspca_dev)
884{
885 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede9153ac32012-05-15 04:23:55 -0300886 int deadzone, desired_avg_lum, avg_lum;
Hans de Goededcef3232008-07-10 10:40:53 -0300887
Hans de Goede9153ac32012-05-15 04:23:55 -0300888 avg_lum = atomic_read(&sd->avg_lum);
889 if (avg_lum == -1)
Hans de Goededcef3232008-07-10 10:40:53 -0300890 return;
891
Hans de Goede26984b02010-02-01 13:18:37 -0300892 if (sd->autogain_ignore_frames > 0) {
893 sd->autogain_ignore_frames--;
894 return;
895 }
896
Hans de Goede5017c7b2008-10-22 04:59:29 -0300897 /* SIF / VGA sensors have a different autoexposure area and thus
898 different avg_lum values for the same picture brightness */
899 if (sensor_data[sd->sensor].flags & F_SIF) {
Hans de Goede26984b02010-02-01 13:18:37 -0300900 deadzone = 500;
901 /* SIF sensors tend to overexpose, so keep this small */
902 desired_avg_lum = 5000;
Hans de Goede5017c7b2008-10-22 04:59:29 -0300903 } else {
Hans de Goede26984b02010-02-01 13:18:37 -0300904 deadzone = 1500;
Hans de Goedef913c002011-01-05 16:01:16 -0300905 desired_avg_lum = 13000;
Hans de Goede5017c7b2008-10-22 04:59:29 -0300906 }
907
Hans de Goede9153ac32012-05-15 04:23:55 -0300908 if (sd->brightness)
909 desired_avg_lum = sd->brightness->val * desired_avg_lum / 127;
Hans de Goede26984b02010-02-01 13:18:37 -0300910
Hans de Goede9153ac32012-05-15 04:23:55 -0300911 if (gspca_dev->exposure->maximum < 500) {
912 if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
913 desired_avg_lum, deadzone))
914 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
915 } else {
Hans Verkuil0d5e8c42014-07-17 12:31:23 -0300916 int gain_knee = (s32)gspca_dev->gain->maximum * 9 / 10;
Hans de Goede9153ac32012-05-15 04:23:55 -0300917 if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum,
918 deadzone, gain_knee, sd->exposure_knee))
919 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
Hans de Goedea975a522008-07-16 15:29:11 -0300920 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300921}
922
923/* this function is called at probe time */
924static int sd_config(struct gspca_dev *gspca_dev,
925 const struct usb_device_id *id)
926{
927 struct sd *sd = (struct sd *) gspca_dev;
928 struct cam *cam;
Hans de Goede65f33392008-09-03 17:12:15 -0300929
930 reg_r(gspca_dev, 0x00);
931 if (gspca_dev->usb_buf[0] != 0x10)
932 return -ENODEV;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300933
Jean-Francois Moine5da162e2008-07-26 14:17:23 -0300934 /* copy the webcam info from the device id */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300935 sd->sensor = id->driver_info >> 8;
936 sd->bridge = id->driver_info & 0xff;
Jean-François Moinef51a8ca2011-03-13 15:04:11 -0300937
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300938 cam = &gspca_dev->cam;
Hans de Goedef45f06b2008-09-03 17:12:21 -0300939 if (!(sensor_data[sd->sensor].flags & F_SIF)) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300940 cam->cam_mode = vga_mode;
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300941 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300942 } else {
943 cam->cam_mode = sif_mode;
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300944 cam->nmodes = ARRAY_SIZE(sif_mode);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300945 }
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -0300946 cam->npkt = 36; /* 36 packets per ISOC message */
947
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300948 return 0;
949}
950
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300951/* this function is called at probe and resume time */
952static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300953{
Hans de Goede271315a2008-09-03 17:12:19 -0300954 const __u8 stop = 0x09; /* Disable stream turn of LED */
955
956 reg_w(gspca_dev, 0x01, &stop, 1);
957
Hans de Goede4848ea72012-05-14 15:21:25 -0300958 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300959}
960
Hans de Goede9153ac32012-05-15 04:23:55 -0300961static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
962{
963 struct gspca_dev *gspca_dev =
964 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
965 struct sd *sd = (struct sd *)gspca_dev;
966
967 gspca_dev->usb_err = 0;
968
969 if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) {
970 /* when switching to autogain set defaults to make sure
971 we are on a valid point of the autogain gain /
972 exposure knee graph, and give this change time to
973 take effect before doing autogain. */
974 gspca_dev->gain->val = gspca_dev->gain->default_value;
975 gspca_dev->exposure->val = gspca_dev->exposure->default_value;
976 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
977 }
978
979 if (!gspca_dev->streaming)
980 return 0;
981
982 switch (ctrl->id) {
983 case V4L2_CID_BRIGHTNESS:
984 setbrightness(gspca_dev);
985 break;
986 case V4L2_CID_AUTOGAIN:
987 if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
988 setexposure(gspca_dev);
989 if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
990 setgain(gspca_dev);
991 break;
992 case V4L2_CID_POWER_LINE_FREQUENCY:
993 setfreq(gspca_dev);
994 break;
995 default:
996 return -EINVAL;
997 }
998 return gspca_dev->usb_err;
999}
1000
1001static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1002 .s_ctrl = sd_s_ctrl,
1003};
1004
1005/* this function is called at probe time */
1006static int sd_init_controls(struct gspca_dev *gspca_dev)
1007{
1008 struct sd *sd = (struct sd *) gspca_dev;
1009 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1010
1011 gspca_dev->vdev.ctrl_handler = hdl;
1012 v4l2_ctrl_handler_init(hdl, 5);
1013
1014 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 ||
1015 sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202)
1016 sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1017 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
1018
1019 /* Gain range is sensor dependent */
1020 switch (sd->sensor) {
1021 case SENSOR_OV6650:
1022 case SENSOR_PAS106:
1023 case SENSOR_PAS202:
1024 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1025 V4L2_CID_GAIN, 0, 31, 1, 15);
1026 break;
Hans de Goede9153ac32012-05-15 04:23:55 -03001027 case SENSOR_OV7630:
1028 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
Hans de Goede8b3a19b2012-05-16 07:14:54 -03001029 V4L2_CID_GAIN, 0, 47, 1, 31);
1030 break;
1031 case SENSOR_HV7131D:
1032 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
Hans de Goede9153ac32012-05-15 04:23:55 -03001033 V4L2_CID_GAIN, 0, 63, 1, 31);
1034 break;
1035 case SENSOR_TAS5110C:
1036 case SENSOR_TAS5110D:
1037 case SENSOR_TAS5130CXX:
1038 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1039 V4L2_CID_GAIN, 0, 255, 1, 127);
1040 break;
1041 default:
1042 if (sd->bridge == BRIDGE_103) {
1043 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1044 V4L2_CID_GAIN, 0, 127, 1, 63);
1045 } else {
1046 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1047 V4L2_CID_GAIN, 0, 15, 1, 7);
1048 }
1049 }
1050
1051 /* Exposure range is sensor dependent, and not all have exposure */
1052 switch (sd->sensor) {
1053 case SENSOR_HV7131D:
1054 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1055 V4L2_CID_EXPOSURE, 0, 8191, 1, 482);
1056 sd->exposure_knee = 964;
1057 break;
1058 case SENSOR_OV6650:
1059 case SENSOR_OV7630:
1060 case SENSOR_PAS106:
1061 case SENSOR_PAS202:
1062 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1063 V4L2_CID_EXPOSURE, 0, 1023, 1, 66);
1064 sd->exposure_knee = 200;
1065 break;
1066 case SENSOR_TAS5110C:
1067 case SENSOR_TAS5110D:
1068 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1069 V4L2_CID_EXPOSURE, 2, 15, 1, 2);
1070 break;
1071 }
1072
1073 if (gspca_dev->exposure) {
1074 gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1075 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1076 }
1077
1078 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630)
1079 sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
1080 V4L2_CID_POWER_LINE_FREQUENCY,
1081 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
1082 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED);
1083
1084 if (hdl->error) {
1085 pr_err("Could not initialize controls\n");
1086 return hdl->error;
1087 }
1088
1089 if (gspca_dev->autogain)
1090 v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
1091
1092 return 0;
1093}
1094
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001095/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001096static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001097{
1098 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede93627732008-09-04 16:20:12 -03001099 struct cam *cam = &gspca_dev->cam;
Hans de Goede0a76cb82011-01-05 13:55:43 -03001100 int i, mode;
1101 __u8 regs[0x31];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001102
Hans de Goede93627732008-09-04 16:20:12 -03001103 mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07;
Hans de Goede0a76cb82011-01-05 13:55:43 -03001104 /* Copy registers 0x01 - 0x19 from the template */
1105 memcpy(&regs[0x01], sensor_data[sd->sensor].bridge_init, 0x19);
1106 /* Set the mode */
1107 regs[0x18] |= mode << 4;
1108
1109 /* Set bridge gain to 1.0 */
1110 if (sd->bridge == BRIDGE_103) {
1111 regs[0x05] = 0x20; /* Red */
1112 regs[0x06] = 0x20; /* Green */
1113 regs[0x07] = 0x20; /* Blue */
1114 } else {
1115 regs[0x10] = 0x00; /* Red and blue */
1116 regs[0x11] = 0x00; /* Green */
1117 }
1118
1119 /* Setup pixel numbers and auto exposure window */
1120 if (sensor_data[sd->sensor].flags & F_SIF) {
1121 regs[0x1a] = 0x14; /* HO_SIZE 640, makes no sense */
1122 regs[0x1b] = 0x0a; /* VO_SIZE 320, makes no sense */
1123 regs[0x1c] = 0x02; /* AE H-start 64 */
1124 regs[0x1d] = 0x02; /* AE V-start 64 */
1125 regs[0x1e] = 0x09; /* AE H-end 288 */
1126 regs[0x1f] = 0x07; /* AE V-end 224 */
1127 } else {
1128 regs[0x1a] = 0x1d; /* HO_SIZE 960, makes no sense */
1129 regs[0x1b] = 0x10; /* VO_SIZE 512, makes no sense */
Hans de Goedef913c002011-01-05 16:01:16 -03001130 regs[0x1c] = 0x05; /* AE H-start 160 */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001131 regs[0x1d] = 0x03; /* AE V-start 96 */
1132 regs[0x1e] = 0x0f; /* AE H-end 480 */
1133 regs[0x1f] = 0x0c; /* AE V-end 384 */
1134 }
1135
1136 /* Setup the gamma table (only used with the sn9c103 bridge) */
1137 for (i = 0; i < 16; i++)
1138 regs[0x20 + i] = i * 16;
1139 regs[0x20 + i] = 255;
1140
1141 /* Special cases where some regs depend on mode or bridge */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001142 switch (sd->sensor) {
Hans de Goedef45f06b2008-09-03 17:12:21 -03001143 case SENSOR_TAS5130CXX:
Hans de Goede0a76cb82011-01-05 13:55:43 -03001144 /* FIXME / TESTME
1145 probably not mode specific at all most likely the upper
Hans de Goedef45f06b2008-09-03 17:12:21 -03001146 nibble of 0x19 is exposure (clock divider) just as with
1147 the tas5110, we need someone to test this. */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001148 regs[0x19] = mode ? 0x23 : 0x43;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001149 break;
Hans de Goede0a76cb82011-01-05 13:55:43 -03001150 case SENSOR_OV7630:
1151 /* FIXME / TESTME for some reason with the 101/102 bridge the
1152 clock is set to 12 Mhz (reg1 == 0x04), rather then 24.
1153 Also the hstart needs to go from 1 to 2 when using a 103,
1154 which is likely related. This does not seem right. */
1155 if (sd->bridge == BRIDGE_103) {
1156 regs[0x01] = 0x44; /* Select 24 Mhz clock */
1157 regs[0x12] = 0x02; /* Set hstart to 2 */
1158 }
Hans de Goede0391dc12013-04-29 08:54:14 -03001159 break;
1160 case SENSOR_PAS202:
1161 /* For some unknown reason we need to increase hstart by 1 on
1162 the sn9c103, otherwise we get wrong colors (bayer shift). */
1163 if (sd->bridge == BRIDGE_103)
1164 regs[0x12] += 1;
1165 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001166 }
Hans de Goedec437d652008-09-03 17:12:22 -03001167 /* Disable compression when the raw bayer format has been selected */
Hans de Goede93627732008-09-04 16:20:12 -03001168 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW)
Hans de Goede0a76cb82011-01-05 13:55:43 -03001169 regs[0x18] &= ~0x80;
Hans de Goede93627732008-09-04 16:20:12 -03001170
1171 /* Vga mode emulation on SIF sensor? */
1172 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) {
Hans de Goede0a76cb82011-01-05 13:55:43 -03001173 regs[0x12] += 16; /* hstart adjust */
1174 regs[0x13] += 24; /* vstart adjust */
1175 regs[0x15] = 320 / 16; /* hsize */
1176 regs[0x16] = 240 / 16; /* vsize */
Hans de Goede93627732008-09-04 16:20:12 -03001177 }
Hans de Goede6af492e2008-07-22 07:09:33 -03001178
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001179 /* reg 0x01 bit 2 video transfert on */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001180 reg_w(gspca_dev, 0x01, &regs[0x01], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001181 /* reg 0x17 SensorClk enable inv Clk 0x60 */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001182 reg_w(gspca_dev, 0x17, &regs[0x17], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001183 /* Set the registers from the template */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001184 reg_w(gspca_dev, 0x01, &regs[0x01],
1185 (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001186
1187 /* Init the sensor */
1188 i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init,
1189 sensor_data[sd->sensor].sensor_init_size);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001190
Hans de Goede0a76cb82011-01-05 13:55:43 -03001191 /* Mode / bridge specific sensor setup */
Hans de Goede82e839c2010-02-03 14:37:30 -03001192 switch (sd->sensor) {
1193 case SENSOR_PAS202: {
1194 const __u8 i2cpclockdiv[] =
1195 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
1196 /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */
1197 if (mode)
1198 i2c_w(gspca_dev, i2cpclockdiv);
Hans de Goede0a76cb82011-01-05 13:55:43 -03001199 break;
Hans de Goede82e839c2010-02-03 14:37:30 -03001200 }
Hans de Goede0a76cb82011-01-05 13:55:43 -03001201 case SENSOR_OV7630:
1202 /* FIXME / TESTME We should be able to handle this identical
1203 for the 101/102 and the 103 case */
1204 if (sd->bridge == BRIDGE_103) {
1205 const __u8 i2c[] = { 0xa0, 0x21, 0x13,
1206 0x80, 0x00, 0x00, 0x00, 0x10 };
1207 i2c_w(gspca_dev, i2c);
1208 }
1209 break;
Hans de Goede82e839c2010-02-03 14:37:30 -03001210 }
Hans de Goede3647fea2008-07-15 05:36:30 -03001211 /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001212 reg_w(gspca_dev, 0x15, &regs[0x15], 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001213 /* compression register */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001214 reg_w(gspca_dev, 0x18, &regs[0x18], 1);
Andoni Zubimendi794af522008-07-16 08:33:14 -03001215 /* H_start */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001216 reg_w(gspca_dev, 0x12, &regs[0x12], 1);
Andoni Zubimendi794af522008-07-16 08:33:14 -03001217 /* V_START */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001218 reg_w(gspca_dev, 0x13, &regs[0x13], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001219 /* reset 0x17 SensorClk enable inv Clk 0x60 */
1220 /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
Hans de Goede0a76cb82011-01-05 13:55:43 -03001221 reg_w(gspca_dev, 0x17, &regs[0x17], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001222 /*MCKSIZE ->3 */ /*fixme: not ov7630*/
Hans de Goede0a76cb82011-01-05 13:55:43 -03001223 reg_w(gspca_dev, 0x19, &regs[0x19], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001224 /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001225 reg_w(gspca_dev, 0x1c, &regs[0x1c], 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001226 /* Enable video transfert */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001227 reg_w(gspca_dev, 0x01, &regs[0x01], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001228 /* Compression */
Hans de Goede0a76cb82011-01-05 13:55:43 -03001229 reg_w(gspca_dev, 0x18, &regs[0x18], 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001230 msleep(20);
1231
Hans de Goede6af492e2008-07-22 07:09:33 -03001232 sd->reg11 = -1;
1233
Hans de Goededcef3232008-07-10 10:40:53 -03001234 setgain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001235 setbrightness(gspca_dev);
Hans de Goededcef3232008-07-10 10:40:53 -03001236 setexposure(gspca_dev);
Hans de Goede66f35822008-07-16 10:16:28 -03001237 setfreq(gspca_dev);
Hans de Goededcef3232008-07-10 10:40:53 -03001238
Hans de Goede6af492e2008-07-22 07:09:33 -03001239 sd->frames_to_drop = 0;
Hans de Goededcef3232008-07-10 10:40:53 -03001240 sd->autogain_ignore_frames = 0;
Hans de Goede9153ac32012-05-15 04:23:55 -03001241 gspca_dev->exp_too_high_cnt = 0;
1242 gspca_dev->exp_too_low_cnt = 0;
Hans de Goededcef3232008-07-10 10:40:53 -03001243 atomic_set(&sd->avg_lum, -1);
Hans de Goede4848ea72012-05-14 15:21:25 -03001244 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001245}
1246
1247static void sd_stopN(struct gspca_dev *gspca_dev)
1248{
Hans de Goedef45f06b2008-09-03 17:12:21 -03001249 sd_init(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001250}
1251
Hans de Goede2b3e2842010-12-12 08:55:04 -03001252static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001253{
Hans de Goededcef3232008-07-10 10:40:53 -03001254 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede2b3e2842010-12-12 08:55:04 -03001255 int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001256
Hans de Goedec36260ee2008-07-16 09:56:07 -03001257 /* frames start with:
1258 * ff ff 00 c4 c4 96 synchro
1259 * 00 (unknown)
1260 * xx (frame sequence / size / compression)
1261 * (xx) (idem - extra byte for sn9c103)
1262 * ll mm brightness sum inside auto exposure
1263 * ll mm brightness sum outside auto exposure
1264 * (xx xx xx xx xx) audio values for snc103
1265 */
Hans de Goede2b3e2842010-12-12 08:55:04 -03001266 for (i = 0; i < len; i++) {
1267 switch (sd->header_read) {
1268 case 0:
1269 if (data[i] == 0xff)
1270 sd->header_read++;
1271 break;
1272 case 1:
1273 if (data[i] == 0xff)
1274 sd->header_read++;
1275 else
1276 sd->header_read = 0;
1277 break;
1278 case 2:
1279 if (data[i] == 0x00)
1280 sd->header_read++;
1281 else if (data[i] != 0xff)
1282 sd->header_read = 0;
1283 break;
1284 case 3:
1285 if (data[i] == 0xc4)
1286 sd->header_read++;
1287 else if (data[i] == 0xff)
1288 sd->header_read = 1;
1289 else
1290 sd->header_read = 0;
1291 break;
1292 case 4:
1293 if (data[i] == 0xc4)
1294 sd->header_read++;
1295 else if (data[i] == 0xff)
1296 sd->header_read = 1;
1297 else
1298 sd->header_read = 0;
1299 break;
1300 case 5:
1301 if (data[i] == 0x96)
1302 sd->header_read++;
1303 else if (data[i] == 0xff)
1304 sd->header_read = 1;
1305 else
1306 sd->header_read = 0;
1307 break;
1308 default:
1309 sd->header[sd->header_read - 6] = data[i];
1310 sd->header_read++;
1311 if (sd->header_read == header_size) {
1312 sd->header_read = 0;
1313 return data + i + 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001314 }
1315 }
1316 }
Hans de Goede2b3e2842010-12-12 08:55:04 -03001317 return NULL;
1318}
1319
1320static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1321 u8 *data, /* isoc packet */
1322 int len) /* iso packet length */
1323{
1324 int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0;
1325 struct sd *sd = (struct sd *) gspca_dev;
1326 struct cam *cam = &gspca_dev->cam;
1327 u8 *sof;
1328
1329 sof = find_sof(gspca_dev, data, len);
1330 if (sof) {
1331 if (sd->bridge == BRIDGE_103) {
1332 fr_h_sz = 18;
1333 lum_offset = 3;
1334 } else {
1335 fr_h_sz = 12;
1336 lum_offset = 2;
1337 }
1338
1339 len_after_sof = len - (sof - data);
1340 len = (sof - data) - fr_h_sz;
1341 if (len < 0)
1342 len = 0;
1343 }
Hans de Goedec437d652008-09-03 17:12:22 -03001344
1345 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1346 /* In raw mode we sometimes get some garbage after the frame
1347 ignore this */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001348 int used;
Hans de Goedec437d652008-09-03 17:12:22 -03001349 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
1350
Jean-François Moineb192ca92010-06-27 03:08:19 -03001351 used = gspca_dev->image_len;
Hans de Goedec437d652008-09-03 17:12:22 -03001352 if (used + len > size)
1353 len = size - used;
1354 }
1355
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001356 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede2b3e2842010-12-12 08:55:04 -03001357
1358 if (sof) {
1359 int lum = sd->header[lum_offset] +
1360 (sd->header[lum_offset + 1] << 8);
1361
1362 /* When exposure changes midway a frame we
1363 get a lum of 0 in this case drop 2 frames
1364 as the frames directly after an exposure
1365 change have an unstable image. Sometimes lum
1366 *really* is 0 (cam used in low light with
1367 low exposure setting), so do not drop frames
1368 if the previous lum was 0 too. */
1369 if (lum == 0 && sd->prev_avg_lum != 0) {
1370 lum = -1;
1371 sd->frames_to_drop = 2;
1372 sd->prev_avg_lum = 0;
1373 } else
1374 sd->prev_avg_lum = lum;
1375 atomic_set(&sd->avg_lum, lum);
1376
1377 if (sd->frames_to_drop)
1378 sd->frames_to_drop--;
1379 else
1380 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1381
1382 gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof);
1383 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001384}
1385
Peter Senna Tschudinf5b6de92013-01-24 19:29:07 -03001386#if IS_ENABLED(CONFIG_INPUT)
Hans de Goedef65e93d2010-01-31 10:35:15 -03001387static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1388 u8 *data, /* interrupt packet data */
1389 int len) /* interrupt packet length */
1390{
1391 int ret = -EINVAL;
1392
1393 if (len == 1 && data[0] == 1) {
1394 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1395 input_sync(gspca_dev->input_dev);
1396 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1397 input_sync(gspca_dev->input_dev);
1398 ret = 0;
1399 }
1400
1401 return ret;
1402}
1403#endif
1404
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001405/* sub-driver description */
Hans de Goededcef3232008-07-10 10:40:53 -03001406static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001407 .name = MODULE_NAME,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001408 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001409 .init = sd_init,
Hans de Goede9153ac32012-05-15 04:23:55 -03001410 .init_controls = sd_init_controls,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001411 .start = sd_start,
1412 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001413 .pkt_scan = sd_pkt_scan,
Hans de Goedee2ad2a52008-09-03 17:12:15 -03001414 .dq_callback = do_autogain,
Peter Senna Tschudinf5b6de92013-01-24 19:29:07 -03001415#if IS_ENABLED(CONFIG_INPUT)
Hans de Goedef65e93d2010-01-31 10:35:15 -03001416 .int_pkt_scan = sd_int_pkt_scan,
1417#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001418};
1419
1420/* -- module initialisation -- */
Hans de Goedef45f06b2008-09-03 17:12:21 -03001421#define SB(sensor, bridge) \
1422 .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge
1423
Hans de Goedee2ad2a52008-09-03 17:12:15 -03001424
Jean-François Moine95c967c2011-01-13 05:20:29 -03001425static const struct usb_device_id device_table[] = {
Hans de Goedeb10af3f2010-01-10 19:31:34 -03001426 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */
1427 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */
Hans de Goedeb10af3f2010-01-10 19:31:34 -03001428 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */
Hans de Goedef45f06b2008-09-03 17:12:21 -03001429 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1430 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001431 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001432 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1433 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1434 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
Hans de Goedef72c77a2012-11-04 17:12:10 -03001435 {USB_DEVICE(0x0c45, 0x6027), SB(OV7630, 101)}, /* Genius Eye 310 */
Hans de Goedef45f06b2008-09-03 17:12:21 -03001436 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1437 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
Hans de Goede00765f12010-12-12 15:55:03 -03001438 {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)},
1439 /* {USB_DEVICE(0x0c45, 0x602b), SB(MI0343, 102)}, */
Jean-Francois Moine29fbdf32008-11-07 04:53:28 -03001440 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001441 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001442 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
Hans de Goede69ffd252011-01-06 11:56:30 -03001443 /* {USB_DEVICE(0x0c45, 0x6030), SB(MI03XX, 102)}, */ /* MI0343 MI0360 MI0330 */
1444 /* {USB_DEVICE(0x0c45, 0x6082), SB(MI03XX, 103)}, */ /* MI0343 MI0360 */
1445 {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)},
1446 {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)},
1447 /* {USB_DEVICE(0x0c45, 0x608e), SB(CISVF10, 103)}, */
Hans de Goede4cce1652008-09-04 16:22:57 -03001448 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
Hans de Goede69ffd252011-01-06 11:56:30 -03001449 {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)},
1450 {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)},
Hans de Goede4cce1652008-09-04 16:22:57 -03001451 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
Hans de Goede4cce1652008-09-04 16:22:57 -03001452 {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001453 {}
1454};
1455MODULE_DEVICE_TABLE(usb, device_table);
1456
1457/* -- device connect -- */
Jean-François Moine95c967c2011-01-13 05:20:29 -03001458static int sd_probe(struct usb_interface *intf,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001459 const struct usb_device_id *id)
1460{
1461 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1462 THIS_MODULE);
1463}
1464
1465static struct usb_driver sd_driver = {
1466 .name = MODULE_NAME,
1467 .id_table = device_table,
1468 .probe = sd_probe,
1469 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03001470#ifdef CONFIG_PM
1471 .suspend = gspca_suspend,
1472 .resume = gspca_resume,
Hans de Goede8bb58962012-06-30 06:44:47 -03001473 .reset_resume = gspca_resume,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03001474#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001475};
1476
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001477module_usb_driver(sd_driver);