blob: 706f96f9265444bc3676a2269c97e35be8735850 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
2 * sonix sn9c102 (bayer) library
3 * Copyright (C) 2003 2004 Michel Xhaard mxhaard@magic.fr
4 * Add Pas106 Stefano Mozzi (C) 2004
5 *
6 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
7 *
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
260x10 high nibble red gain low nibble blue gain
270x11 low nibble green gain
280x12 hstart
290x13 vstart
300x15 hsize (hsize = register-value * 16)
310x16 vsize (vsize = register-value * 16)
320x17 bit 0 toggle compression quality (according to sn9c102 driver)
330x18 bit 7 enables compression, bit 4-5 set image down scaling:
34 00 scale 1, 01 scale 1/2, 10, scale 1/4
350x19 high-nibble is sensor clock divider, changes exposure on sensors which
36 use a clock generated by the bridge. Some sensors have their own clock.
370x1c auto_exposure area (for avg_lum) startx (startx = register-value * 32)
380x1d auto_exposure area (for avg_lum) starty (starty = register-value * 32)
390x1e auto_exposure area (for avg_lum) stopx (hsize = (0x1e - 0x1c) * 32)
400x1f auto_exposure area (for avg_lum) stopy (vsize = (0x1f - 0x1d) * 32)
41*/
42
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030043#define MODULE_NAME "sonixb"
44
Hans de Goedef65e93d2010-01-31 10:35:15 -030045#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030046#include "gspca.h"
47
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030048MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
49MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
50MODULE_LICENSE("GPL");
51
52/* specific webcam descriptor */
53struct sd {
54 struct gspca_dev gspca_dev; /* !! must be the first item */
Hans de Goededcef3232008-07-10 10:40:53 -030055 atomic_t avg_lum;
Hans de Goedebf2a2202008-09-04 16:22:56 -030056 int prev_avg_lum;
Hans de Goede26984b02010-02-01 13:18:37 -030057 int exp_too_low_cnt;
58 int exp_too_high_cnt;
Hans de Goededcef3232008-07-10 10:40:53 -030059
Hans de Goede26984b02010-02-01 13:18:37 -030060 unsigned short exposure;
Hans de Goedead5ef80d2008-07-14 10:11:42 -030061 unsigned char gain;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030062 unsigned char brightness;
Hans de Goededcef3232008-07-10 10:40:53 -030063 unsigned char autogain;
64 unsigned char autogain_ignore_frames;
Hans de Goede6af492e2008-07-22 07:09:33 -030065 unsigned char frames_to_drop;
Hans de Goede66f35822008-07-16 10:16:28 -030066 unsigned char freq; /* light freq filter setting */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030067
Hans de Goedef45f06b2008-09-03 17:12:21 -030068 __u8 bridge; /* Type of bridge */
69#define BRIDGE_101 0
70#define BRIDGE_102 0 /* We make no difference between 101 and 102 */
71#define BRIDGE_103 1
72
73 __u8 sensor; /* Type of image sensor chip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030074#define SENSOR_HV7131R 0
75#define SENSOR_OV6650 1
76#define SENSOR_OV7630 2
Hans de Goede6af492e2008-07-22 07:09:33 -030077#define SENSOR_PAS106 3
78#define SENSOR_PAS202 4
Hans de Goedeb10af3f2010-01-10 19:31:34 -030079#define SENSOR_TAS5110C 5
80#define SENSOR_TAS5110D 6
81#define SENSOR_TAS5130CXX 7
Hans de Goede6af492e2008-07-22 07:09:33 -030082 __u8 reg11;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030083};
84
Hans de Goedef45f06b2008-09-03 17:12:21 -030085typedef const __u8 sensor_init_t[8];
86
87struct sensor_data {
88 const __u8 *bridge_init[2];
89 int bridge_init_size[2];
90 sensor_init_t *sensor_init;
91 int sensor_init_size;
92 sensor_init_t *sensor_bridge_init[2];
93 int sensor_bridge_init_size[2];
94 int flags;
95 unsigned ctrl_dis;
96 __u8 sensor_addr;
97};
98
99/* sensor_data flags */
Jean-Francois Moine5da162e2008-07-26 14:17:23 -0300100#define F_GAIN 0x01 /* has gain */
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300101#define F_SIF 0x02 /* sif or vga */
Hans de Goede26984b02010-02-01 13:18:37 -0300102#define F_COARSE_EXPO 0x04 /* exposure control is coarse */
Hans de Goedec437d652008-09-03 17:12:22 -0300103
104/* priv field of struct v4l2_pix_format flags (do not use low nibble!) */
105#define MODE_RAW 0x10 /* raw bayer mode */
Hans de Goede93627732008-09-04 16:20:12 -0300106#define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300107
108/* ctrl_dis helper macros */
Hans de Goede26984b02010-02-01 13:18:37 -0300109#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << COARSE_EXPOSURE_IDX) | \
110 (1 << AUTOGAIN_IDX))
Hans de Goedef45f06b2008-09-03 17:12:21 -0300111#define NO_FREQ (1 << FREQ_IDX)
112#define NO_BRIGHTNESS (1 << BRIGHTNESS_IDX)
Jean-Francois Moine5da162e2008-07-26 14:17:23 -0300113
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300114#define COMP2 0x8f
115#define COMP 0xc7 /* 0x87 //0x07 */
116#define COMP1 0xc9 /* 0x89 //0x09 */
117
118#define MCK_INIT 0x63
119#define MCK_INIT1 0x20 /*fixme: Bayer - 0x50 for JPEG ??*/
120
121#define SYS_CLK 0x04
122
Hans de Goedef45f06b2008-09-03 17:12:21 -0300123#define SENS(bridge_1, bridge_3, sensor, sensor_1, \
124 sensor_3, _flags, _ctrl_dis, _sensor_addr) \
125{ \
126 .bridge_init = { bridge_1, bridge_3 }, \
127 .bridge_init_size = { sizeof(bridge_1), sizeof(bridge_3) }, \
128 .sensor_init = sensor, \
129 .sensor_init_size = sizeof(sensor), \
130 .sensor_bridge_init = { sensor_1, sensor_3,}, \
131 .sensor_bridge_init_size = { sizeof(sensor_1), sizeof(sensor_3)}, \
132 .flags = _flags, .ctrl_dis = _ctrl_dis, .sensor_addr = _sensor_addr \
133}
134
Hans de Goededcef3232008-07-10 10:40:53 -0300135/* We calculate the autogain at the end of the transfer of a frame, at this
Hans de Goede26984b02010-02-01 13:18:37 -0300136 moment a frame with the old settings is being captured and transmitted. So
137 if we adjust the gain or exposure we must ignore atleast the next frame for
138 the new settings to come into effect before doing any other adjustments. */
139#define AUTOGAIN_IGNORE_FRAMES 1
Hans de Goededcef3232008-07-10 10:40:53 -0300140
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300141/* V4L2 controls supported by the driver */
142static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
143static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goededcef3232008-07-10 10:40:53 -0300144static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
145static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
146static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
147static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
148static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
149static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede66f35822008-07-16 10:16:28 -0300150static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
151static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300152
Marton Nemeth7e64dc42009-12-30 09:12:41 -0300153static const struct ctrl sd_ctrls[] = {
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300154#define BRIGHTNESS_IDX 0
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300155 {
156 {
157 .id = V4L2_CID_BRIGHTNESS,
158 .type = V4L2_CTRL_TYPE_INTEGER,
159 .name = "Brightness",
160 .minimum = 0,
161 .maximum = 255,
162 .step = 1,
Hans de Goededcef3232008-07-10 10:40:53 -0300163#define BRIGHTNESS_DEF 127
164 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300165 },
166 .set = sd_setbrightness,
167 .get = sd_getbrightness,
168 },
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300169#define GAIN_IDX 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300170 {
171 {
Hans de Goededcef3232008-07-10 10:40:53 -0300172 .id = V4L2_CID_GAIN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173 .type = V4L2_CTRL_TYPE_INTEGER,
Hans de Goededcef3232008-07-10 10:40:53 -0300174 .name = "Gain",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 .minimum = 0,
Hans de Goedead5ef80d2008-07-14 10:11:42 -0300176 .maximum = 255,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300177 .step = 1,
Hans de Goedead5ef80d2008-07-14 10:11:42 -0300178#define GAIN_DEF 127
Hans de Goede82e839c2010-02-03 14:37:30 -0300179#define GAIN_KNEE 230
Hans de Goededcef3232008-07-10 10:40:53 -0300180 .default_value = GAIN_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300181 },
Hans de Goededcef3232008-07-10 10:40:53 -0300182 .set = sd_setgain,
183 .get = sd_getgain,
184 },
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300185#define EXPOSURE_IDX 2
Hans de Goededcef3232008-07-10 10:40:53 -0300186 {
187 {
188 .id = V4L2_CID_EXPOSURE,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "Exposure",
Hans de Goede421763e2010-02-10 18:57:40 -0300191#define EXPOSURE_DEF 66 /* 33 ms / 30 fps (except on PASXXX) */
192#define EXPOSURE_KNEE 200 /* 100 ms / 10 fps (except on PASXXX) */
Hans de Goededcef3232008-07-10 10:40:53 -0300193 .minimum = 0,
Hans de Goede82e839c2010-02-03 14:37:30 -0300194 .maximum = 1023,
Hans de Goededcef3232008-07-10 10:40:53 -0300195 .step = 1,
196 .default_value = EXPOSURE_DEF,
197 .flags = 0,
198 },
199 .set = sd_setexposure,
200 .get = sd_getexposure,
201 },
Hans de Goede26984b02010-02-01 13:18:37 -0300202#define COARSE_EXPOSURE_IDX 3
203 {
204 {
205 .id = V4L2_CID_EXPOSURE,
206 .type = V4L2_CTRL_TYPE_INTEGER,
207 .name = "Exposure",
208#define COARSE_EXPOSURE_DEF 2 /* 30 fps */
209 .minimum = 2,
210 .maximum = 15,
211 .step = 1,
212 .default_value = COARSE_EXPOSURE_DEF,
213 .flags = 0,
214 },
215 .set = sd_setexposure,
216 .get = sd_getexposure,
217 },
218#define AUTOGAIN_IDX 4
Hans de Goededcef3232008-07-10 10:40:53 -0300219 {
220 {
221 .id = V4L2_CID_AUTOGAIN,
222 .type = V4L2_CTRL_TYPE_BOOLEAN,
223 .name = "Automatic Gain (and Exposure)",
224 .minimum = 0,
225 .maximum = 1,
226 .step = 1,
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300227#define AUTOGAIN_DEF 1
228 .default_value = AUTOGAIN_DEF,
Hans de Goededcef3232008-07-10 10:40:53 -0300229 .flags = 0,
230 },
231 .set = sd_setautogain,
232 .get = sd_getautogain,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300233 },
Hans de Goede26984b02010-02-01 13:18:37 -0300234#define FREQ_IDX 5
Hans de Goede66f35822008-07-16 10:16:28 -0300235 {
236 {
237 .id = V4L2_CID_POWER_LINE_FREQUENCY,
238 .type = V4L2_CTRL_TYPE_MENU,
239 .name = "Light frequency filter",
240 .minimum = 0,
241 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
242 .step = 1,
Hans de Goede606f8422010-02-10 06:49:23 -0300243#define FREQ_DEF 0
Hans de Goede66f35822008-07-16 10:16:28 -0300244 .default_value = FREQ_DEF,
245 },
246 .set = sd_setfreq,
247 .get = sd_getfreq,
248 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300249};
250
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300251static const struct v4l2_pix_format vga_mode[] = {
Hans de Goedec437d652008-09-03 17:12:22 -0300252 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
253 .bytesperline = 160,
Mauro Carvalho Chehab2389b362008-08-06 20:13:46 -0300254 .sizeimage = 160 * 120,
Hans de Goedec437d652008-09-03 17:12:22 -0300255 .colorspace = V4L2_COLORSPACE_SRGB,
256 .priv = 2 | MODE_RAW},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300257 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
258 .bytesperline = 160,
Hans de Goede5c515182008-09-03 17:12:22 -0300259 .sizeimage = 160 * 120 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300260 .colorspace = V4L2_COLORSPACE_SRGB,
261 .priv = 2},
262 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
263 .bytesperline = 320,
Hans de Goede5c515182008-09-03 17:12:22 -0300264 .sizeimage = 320 * 240 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300265 .colorspace = V4L2_COLORSPACE_SRGB,
266 .priv = 1},
267 {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
268 .bytesperline = 640,
Hans de Goede5c515182008-09-03 17:12:22 -0300269 .sizeimage = 640 * 480 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300270 .colorspace = V4L2_COLORSPACE_SRGB,
271 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300272};
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300273static const struct v4l2_pix_format sif_mode[] = {
Hans de Goede93627732008-09-04 16:20:12 -0300274 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
275 .bytesperline = 160,
276 .sizeimage = 160 * 120,
277 .colorspace = V4L2_COLORSPACE_SRGB,
278 .priv = 1 | MODE_RAW | MODE_REDUCED_SIF},
279 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
280 .bytesperline = 160,
281 .sizeimage = 160 * 120 * 5 / 4,
282 .colorspace = V4L2_COLORSPACE_SRGB,
283 .priv = 1 | MODE_REDUCED_SIF},
Hans de Goedec437d652008-09-03 17:12:22 -0300284 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
285 .bytesperline = 176,
Mauro Carvalho Chehab2389b362008-08-06 20:13:46 -0300286 .sizeimage = 176 * 144,
Hans de Goedec437d652008-09-03 17:12:22 -0300287 .colorspace = V4L2_COLORSPACE_SRGB,
288 .priv = 1 | MODE_RAW},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300289 {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
290 .bytesperline = 176,
Hans de Goede5c515182008-09-03 17:12:22 -0300291 .sizeimage = 176 * 144 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300292 .colorspace = V4L2_COLORSPACE_SRGB,
293 .priv = 1},
Hans de Goede93627732008-09-04 16:20:12 -0300294 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
295 .bytesperline = 320,
296 .sizeimage = 320 * 240 * 5 / 4,
297 .colorspace = V4L2_COLORSPACE_SRGB,
298 .priv = 0 | MODE_REDUCED_SIF},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300299 {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
300 .bytesperline = 352,
Hans de Goede5c515182008-09-03 17:12:22 -0300301 .sizeimage = 352 * 288 * 5 / 4,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300302 .colorspace = V4L2_COLORSPACE_SRGB,
303 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300304};
305
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300306static const __u8 initHv7131[] = {
307 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
308 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300309 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300310 0x28, 0x1e, 0x60, 0x8a, 0x20,
311 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
312};
313static const __u8 hv7131_sensor_init[][8] = {
314 {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
315 {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
316 {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
317 {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
318 {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
319};
320static const __u8 initOv6650[] = {
321 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
322 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300323 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b,
Hans de Goede93627732008-09-04 16:20:12 -0300324 0x10, 0x1d, 0x10, 0x02, 0x02, 0x09, 0x07
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300325};
Jean-François Moine780e3122010-10-19 04:29:10 -0300326static const __u8 ov6650_sensor_init[][8] = {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200327 /* Bright, contrast, etc are set through SCBB interface.
Jean-François Moine780e3122010-10-19 04:29:10 -0300328 * AVCAP on win2 do not send any data on this controls. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300329 /* Anyway, some registers appears to alter bright and constrat */
Hans de Goededcef3232008-07-10 10:40:53 -0300330
331 /* Reset sensor */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300332 {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
Hans de Goededcef3232008-07-10 10:40:53 -0300333 /* Set clock register 0x11 low nibble is clock divider */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300334 {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
Hans de Goededcef3232008-07-10 10:40:53 -0300335 /* Next some unknown stuff */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300336 {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
337/* {0xa0, 0x60, 0x1b, 0x01, 0x02, 0x18, 0xc1, 0x10},
338 * THIS SET GREEN SCREEN
339 * (pixels could be innverted in decode kind of "brg",
340 * but blue wont be there. Avoid this data ... */
341 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
342 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
343 {0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10},
Hans de Goede722103e2008-07-17 10:24:47 -0300344 /* Enable rgb brightness control */
345 {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
346 /* HDG: Note windows uses the line below, which sets both register 0x60
347 and 0x61 I believe these registers of the ov6650 are identical as
348 those of the ov7630, because if this is true the windows settings
349 add a bit additional red gain and a lot additional blue gain, which
350 matches my findings that the windows settings make blue much too
351 blue and red a little too red.
352 {0xb0, 0x60, 0x60, 0x66, 0x68, 0xd8, 0xa4, 0x10}, */
Hans de Goededcef3232008-07-10 10:40:53 -0300353 /* Some more unknown stuff */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300354 {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
355 {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300356};
Hans de Goededcef3232008-07-10 10:40:53 -0300357
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300358static const __u8 initOv7630[] = {
359 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* r01 .. r08 */
360 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
Hans de Goedec437d652008-09-03 17:12:22 -0300361 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300362 0x28, 0x1e, /* H & V sizes r15 .. r16 */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300363 0x68, COMP2, MCK_INIT1, /* r17 .. r19 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300364 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */
365};
366static const __u8 initOv7630_3[] = {
367 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */
Hans de Goede4efcfa02010-02-01 07:48:17 -0300368 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
Hans de Goede4cce1652008-09-04 16:22:57 -0300369 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
Hans de Goede3647fea2008-07-15 05:36:30 -0300370 0x28, 0x1e, /* H & V sizes r15 .. r16 */
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300371 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
372 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c, 0x00, /* r1a .. r20 */
373 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */
374 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff /* r29 .. r30 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300375};
Hans de Goede6af492e2008-07-22 07:09:33 -0300376static const __u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300377 {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
378 {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
379/* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
Andoni Zubimendi794af522008-07-16 08:33:14 -0300380 {0xd0, 0x21, 0x12, 0x1c, 0x00, 0x80, 0x34, 0x10}, /* jfm */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300381 {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
382 {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
383 {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
384 {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
385 {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
386 {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
387 {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
Andoni Zubimendi794af522008-07-16 08:33:14 -0300388 {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},
389/* {0xb0, 0x21, 0x60, 0xa9, 0x42, 0xa0, 0x30, 0x10}, * jfm */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300390 {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
391 {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
392 {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
393 {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
394 {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
395 {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
396};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300397
Hans de Goedef45f06b2008-09-03 17:12:21 -0300398static const __u8 ov7630_sensor_init_3[][8] = {
399 {0xa0, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
400};
401
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300402static const __u8 initPas106[] = {
403 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
404 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300405 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
Hans de Goedef45f06b2008-09-03 17:12:21 -0300406 0x16, 0x12, 0x24, COMP1, MCK_INIT1,
Hans de Goede93627732008-09-04 16:20:12 -0300407 0x18, 0x10, 0x02, 0x02, 0x09, 0x07
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300408};
409/* compression 0x86 mckinit1 0x2b */
Hans de Goede421763e2010-02-10 18:57:40 -0300410
411/* "Known" PAS106B registers:
412 0x02 clock divider
413 0x03 Variable framerate bits 4-11
414 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !!
415 The variable framerate control must never be set lower then 300,
416 which sets the framerate at 90 / reg02, otherwise vsync is lost.
417 0x05 Shutter Time Line Offset, this can be used as an exposure control:
418 0 = use full frame time, 255 = no exposure at all
419 Note this may never be larger then "var-framerate control" / 2 - 2.
420 When var-framerate control is < 514, no exposure is reached at the max
421 allowed value for the framerate control value, rather then at 255.
422 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but
423 only a very little bit, leave at 0xcd
424 0x07 offset sign bit (bit0 1 > negative offset)
425 0x08 offset
426 0x09 Blue Gain
427 0x0a Green1 Gain
428 0x0b Green2 Gain
429 0x0c Red Gain
430 0x0e Global gain
431 0x13 Write 1 to commit settings to sensor
432*/
433
Hans de Goedef45f06b2008-09-03 17:12:21 -0300434static const __u8 pas106_sensor_init[][8] = {
435 /* Pixel Clock Divider 6 */
436 { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },
437 /* Frame Time MSB (also seen as 0x12) */
438 { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 },
439 /* Frame Time LSB (also seen as 0x05) */
440 { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 },
441 /* Shutter Time Line Offset (also seen as 0x6d) */
442 { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 },
443 /* Shutter Time Pixel Offset (also seen as 0xb1) */
444 { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 },
445 /* Black Level Subtract Sign (also seen 0x00) */
446 { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 },
447 /* Black Level Subtract Level (also seen 0x01) */
448 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
449 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
450 /* Color Gain B Pixel 5 a */
451 { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 },
452 /* Color Gain G1 Pixel 1 5 */
453 { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 },
454 /* Color Gain G2 Pixel 1 0 5 */
455 { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 },
456 /* Color Gain R Pixel 3 1 */
457 { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 },
458 /* Color GainH Pixel */
459 { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 },
460 /* Global Gain */
461 { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 },
462 /* Contrast */
463 { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 },
464 /* H&V synchro polarity */
465 { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 },
466 /* ?default */
467 { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 },
468 /* DAC scale */
469 { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 },
470 /* ?default */
471 { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 },
472 /* Validate Settings */
473 { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300474};
Hans de Goedef45f06b2008-09-03 17:12:21 -0300475
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300476static const __u8 initPas202[] = {
477 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
478 0x00, 0x00,
Hans de Goedec437d652008-09-03 17:12:22 -0300479 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a,
Hans de Goede82e839c2010-02-03 14:37:30 -0300480 0x28, 0x1e, 0x20, 0x89, 0x20,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300481 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c
482};
Hans de Goede82e839c2010-02-03 14:37:30 -0300483
484/* "Known" PAS202BCB registers:
485 0x02 clock divider
486 0x04 Variable framerate bits 6-11 (*)
487 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !!
488 0x07 Blue Gain
489 0x08 Green Gain
490 0x09 Red Gain
491 0x0b offset sign bit (bit0 1 > negative offset)
492 0x0c offset
493 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too,
494 leave at 1 otherwise we get a jump in our exposure control
495 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all
496 0x10 Master gain 0 - 31
497 0x11 write 1 to apply changes
498 (*) The variable framerate control must never be set lower then 500
499 which sets the framerate at 30 / reg02, otherwise vsync is lost.
500*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300501static const __u8 pas202_sensor_init[][8] = {
Hans de Goede82e839c2010-02-03 14:37:30 -0300502 /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like
503 to set it lower, but for some reason the bridge starts missing
504 vsync's then */
505 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300506 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
507 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
Hans de Goede82e839c2010-02-03 14:37:30 -0300508 {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x01, 0x32, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300509 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
510 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
511 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
512 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
513 {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
514 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300515};
516
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300517static const __u8 initTas5110c[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300518 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
519 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300520 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300521 0x16, 0x12, 0x60, 0x86, 0x2b,
522 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
523};
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300524/* Same as above, except a different hstart */
525static const __u8 initTas5110d[] = {
526 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
527 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300528 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a,
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300529 0x16, 0x12, 0x60, 0x86, 0x2b,
530 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
531};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300532static const __u8 tas5110_sensor_init[][8] = {
533 {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
534 {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
535 {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
536};
537
538static const __u8 initTas5130[] = {
539 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
540 0x00, 0x00,
Hans de Goede4efcfa02010-02-01 07:48:17 -0300541 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300542 0x28, 0x1e, 0x60, COMP, MCK_INIT,
543 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
544};
545static const __u8 tas5130_sensor_init[][8] = {
Jean-François Moine780e3122010-10-19 04:29:10 -0300546/* {0x30, 0x11, 0x00, 0x40, 0x47, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300547 * shutter 0x47 short exposure? */
548 {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
549 /* shutter 0x01 long exposure */
550 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
551};
552
Hans Verkuild45b9b82008-09-04 03:33:43 -0300553static struct sensor_data sensor_data[] = {
Hans de Goedef45f06b2008-09-03 17:12:21 -0300554SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0),
Hans de Goede93627732008-09-04 16:20:12 -0300555SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60),
Hans de Goedef45f06b2008-09-03 17:12:21 -0300556SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3,
557 F_GAIN, 0, 0x21),
Hans de Goede421763e2010-02-10 18:57:40 -0300558SENS(initPas106, NULL, pas106_sensor_init, NULL, NULL, F_GAIN|F_SIF, NO_FREQ,
Hans de Goedef45f06b2008-09-03 17:12:21 -0300559 0),
Hans de Goede82e839c2010-02-03 14:37:30 -0300560SENS(initPas202, initPas202, pas202_sensor_init, NULL, NULL, F_GAIN,
561 NO_FREQ, 0),
Hans de Goede26984b02010-02-01 13:18:37 -0300562SENS(initTas5110c, NULL, tas5110_sensor_init, NULL, NULL,
563 F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0),
564SENS(initTas5110d, NULL, tas5110_sensor_init, NULL, NULL,
565 F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0),
Hans de Goedef45f06b2008-09-03 17:12:21 -0300566SENS(initTas5130, NULL, tas5130_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ,
567 0),
568};
569
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300570/* get one byte in gspca_dev->usb_buf */
571static void reg_r(struct gspca_dev *gspca_dev,
572 __u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300573{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300574 usb_control_msg(gspca_dev->dev,
575 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300576 0, /* request */
577 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
578 value,
579 0, /* index */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300580 gspca_dev->usb_buf, 1,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300581 500);
582}
583
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300584static void reg_w(struct gspca_dev *gspca_dev,
585 __u16 value,
586 const __u8 *buffer,
587 int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300588{
Jean-Francois Moine335b3f82008-07-30 04:53:02 -0300589#ifdef GSPCA_DEBUG
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300590 if (len > USB_BUF_SZ) {
Hans de Goede0d2a7222008-07-03 08:15:22 -0300591 PDEBUG(D_ERR|D_PACK, "reg_w: buffer overflow");
592 return;
593 }
594#endif
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300595 memcpy(gspca_dev->usb_buf, buffer, len);
596 usb_control_msg(gspca_dev->dev,
597 usb_sndctrlpipe(gspca_dev->dev, 0),
598 0x08, /* request */
599 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
600 value,
601 0, /* index */
602 gspca_dev->usb_buf, len,
603 500);
604}
605
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300606static int i2c_w(struct gspca_dev *gspca_dev, const __u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300607{
608 int retry = 60;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300609
610 /* is i2c ready */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300611 reg_w(gspca_dev, 0x08, buffer, 8);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300612 while (retry--) {
613 msleep(10);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300614 reg_r(gspca_dev, 0x08);
Andoni Zubimendib7474cf2008-07-16 08:40:30 -0300615 if (gspca_dev->usb_buf[0] & 0x04) {
616 if (gspca_dev->usb_buf[0] & 0x08)
617 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300618 return 0;
Andoni Zubimendib7474cf2008-07-16 08:40:30 -0300619 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300620 }
621 return -1;
622}
623
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300624static void i2c_w_vector(struct gspca_dev *gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300625 const __u8 buffer[][8], int len)
626{
627 for (;;) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300628 reg_w(gspca_dev, 0x08, *buffer, 8);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300629 len -= 8;
630 if (len <= 0)
631 break;
632 buffer++;
633 }
634}
635
636static void setbrightness(struct gspca_dev *gspca_dev)
637{
638 struct sd *sd = (struct sd *) gspca_dev;
639 __u8 value;
640
641 switch (sd->sensor) {
Hans de Goedea975a522008-07-16 15:29:11 -0300642 case SENSOR_OV6650:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300643 case SENSOR_OV7630: {
644 __u8 i2cOV[] =
Hans de Goedea975a522008-07-16 15:29:11 -0300645 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300646
647 /* change reg 0x06 */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300648 i2cOV[1] = sensor_data[sd->sensor].sensor_addr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300649 i2cOV[3] = sd->brightness;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300650 if (i2c_w(gspca_dev, i2cOV) < 0)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300651 goto err;
652 break;
653 }
Hans de Goede421763e2010-02-10 18:57:40 -0300654 case SENSOR_PAS106:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300655 case SENSOR_PAS202: {
Hans de Goede82e839c2010-02-03 14:37:30 -0300656 __u8 i2cpbright[] =
657 {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
Hans de Goede421763e2010-02-10 18:57:40 -0300658 __u8 i2cpdoit[] =
Hans de Goede82e839c2010-02-03 14:37:30 -0300659 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300660
Hans de Goede421763e2010-02-10 18:57:40 -0300661 /* PAS106 uses reg 7 and 8 instead of b and c */
662 if (sd->sensor == SENSOR_PAS106) {
663 i2cpbright[2] = 7;
664 i2cpdoit[2] = 0x13;
665 }
666
Hans de Goede82e839c2010-02-03 14:37:30 -0300667 if (sd->brightness < 127) {
668 /* change reg 0x0b, signreg */
669 i2cpbright[3] = 0x01;
670 /* set reg 0x0c, offset */
671 i2cpbright[4] = 127 - sd->brightness;
672 } else
673 i2cpbright[4] = sd->brightness - 127;
674
675 if (i2c_w(gspca_dev, i2cpbright) < 0)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300676 goto err;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300677 if (i2c_w(gspca_dev, i2cpdoit) < 0)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300678 goto err;
679 break;
680 }
Hans de Goededcef3232008-07-10 10:40:53 -0300681 case SENSOR_TAS5130CXX: {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300682 __u8 i2c[] =
683 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
684
685 value = 0xff - sd->brightness;
686 i2c[4] = value;
687 PDEBUG(D_CONF, "brightness %d : %d", value, i2c[4]);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300688 if (i2c_w(gspca_dev, i2c) < 0)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300689 goto err;
690 break;
691 }
692 }
693 return;
694err:
695 PDEBUG(D_ERR, "i2c error brightness");
696}
Hans de Goededcef3232008-07-10 10:40:53 -0300697
698static void setsensorgain(struct gspca_dev *gspca_dev)
699{
700 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedea975a522008-07-16 15:29:11 -0300701 unsigned char gain = sd->gain;
Hans de Goededcef3232008-07-10 10:40:53 -0300702
703 switch (sd->sensor) {
704
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300705 case SENSOR_TAS5110C:
706 case SENSOR_TAS5110D: {
Hans de Goededcef3232008-07-10 10:40:53 -0300707 __u8 i2c[] =
708 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
709
Hans de Goedea975a522008-07-16 15:29:11 -0300710 i2c[4] = 255 - gain;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300711 if (i2c_w(gspca_dev, i2c) < 0)
Hans de Goededcef3232008-07-10 10:40:53 -0300712 goto err;
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300713 break;
714 }
Hans de Goedead5ef80d2008-07-14 10:11:42 -0300715
Hans de Goedea975a522008-07-16 15:29:11 -0300716 case SENSOR_OV6650:
717 gain >>= 1;
718 /* fall thru */
Hans de Goede6af492e2008-07-22 07:09:33 -0300719 case SENSOR_OV7630: {
Hans de Goedea975a522008-07-16 15:29:11 -0300720 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
Andoni Zubimendi794af522008-07-16 08:33:14 -0300721
Hans de Goedef45f06b2008-09-03 17:12:21 -0300722 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Hans de Goedea975a522008-07-16 15:29:11 -0300723 i2c[3] = gain >> 2;
Andoni Zubimendi794af522008-07-16 08:33:14 -0300724 if (i2c_w(gspca_dev, i2c) < 0)
725 goto err;
726 break;
727 }
Hans de Goede421763e2010-02-10 18:57:40 -0300728 case SENSOR_PAS106:
Hans de Goede82e839c2010-02-03 14:37:30 -0300729 case SENSOR_PAS202: {
730 __u8 i2cpgain[] =
Hans de Goede421763e2010-02-10 18:57:40 -0300731 {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
Hans de Goede82e839c2010-02-03 14:37:30 -0300732 __u8 i2cpcolorgain[] =
733 {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
Hans de Goede421763e2010-02-10 18:57:40 -0300734 __u8 i2cpdoit[] =
735 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
736
737 /* PAS106 uses different regs (and has split green gains) */
738 if (sd->sensor == SENSOR_PAS106) {
739 i2cpgain[2] = 0x0e;
740 i2cpcolorgain[0] = 0xd0;
741 i2cpcolorgain[2] = 0x09;
742 i2cpdoit[2] = 0x13;
743 }
Hans de Goede82e839c2010-02-03 14:37:30 -0300744
745 i2cpgain[3] = sd->gain >> 3;
746 i2cpcolorgain[3] = sd->gain >> 4;
747 i2cpcolorgain[4] = sd->gain >> 4;
748 i2cpcolorgain[5] = sd->gain >> 4;
Hans de Goede421763e2010-02-10 18:57:40 -0300749 i2cpcolorgain[6] = sd->gain >> 4;
Hans de Goede82e839c2010-02-03 14:37:30 -0300750
751 if (i2c_w(gspca_dev, i2cpgain) < 0)
752 goto err;
753 if (i2c_w(gspca_dev, i2cpcolorgain) < 0)
754 goto err;
755 if (i2c_w(gspca_dev, i2cpdoit) < 0)
756 goto err;
757 break;
758 }
Hans de Goededcef3232008-07-10 10:40:53 -0300759 }
760 return;
761err:
762 PDEBUG(D_ERR, "i2c error gain");
763}
764
765static void setgain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300766{
767 struct sd *sd = (struct sd *) gspca_dev;
768 __u8 gain;
Hans de Goede4efcfa02010-02-01 07:48:17 -0300769 __u8 buf[2] = { 0, 0 };
770
771 if (sensor_data[sd->sensor].flags & F_GAIN) {
772 /* Use the sensor gain to do the actual gain */
773 setsensorgain(gspca_dev);
774 return;
775 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300776
Hans de Goedead5ef80d2008-07-14 10:11:42 -0300777 gain = sd->gain >> 4;
Hans de Goededcef3232008-07-10 10:40:53 -0300778
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300779 /* red and blue gain */
Hans de Goede4efcfa02010-02-01 07:48:17 -0300780 buf[0] = gain << 4 | gain;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300781 /* green gain */
Hans de Goede4efcfa02010-02-01 07:48:17 -0300782 buf[1] = gain;
783 reg_w(gspca_dev, 0x10, buf, 2);
Hans de Goededcef3232008-07-10 10:40:53 -0300784}
785
786static void setexposure(struct gspca_dev *gspca_dev)
787{
788 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goededcef3232008-07-10 10:40:53 -0300789
790 switch (sd->sensor) {
Hans de Goedeb10af3f2010-01-10 19:31:34 -0300791 case SENSOR_TAS5110C:
792 case SENSOR_TAS5110D: {
Hans de Goededcef3232008-07-10 10:40:53 -0300793 /* register 19's high nibble contains the sn9c10x clock divider
794 The high nibble configures the no fps according to the
795 formula: 60 / high_nibble. With a maximum of 30 fps */
Hans de Goede26984b02010-02-01 13:18:37 -0300796 __u8 reg = sd->exposure;
Hans de Goededcef3232008-07-10 10:40:53 -0300797 reg = (reg << 4) | 0x0b;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300798 reg_w(gspca_dev, 0x19, &reg, 1);
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -0300799 break;
800 }
Hans de Goedea975a522008-07-16 15:29:11 -0300801 case SENSOR_OV6650:
Hans de Goede6af492e2008-07-22 07:09:33 -0300802 case SENSOR_OV7630: {
Hans de Goedea975a522008-07-16 15:29:11 -0300803 /* The ov6650 / ov7630 have 2 registers which both influence
804 exposure, register 11, whose low nibble sets the nr off fps
Hans de Goedef4d52022008-07-15 09:36:42 -0300805 according to: fps = 30 / (low_nibble + 1)
806
807 The fps configures the maximum exposure setting, but it is
808 possible to use less exposure then what the fps maximum
809 allows by setting register 10. register 10 configures the
810 actual exposure as quotient of the full exposure, with 0
811 being no exposure at all (not very usefull) and reg10_max
812 being max exposure possible at that framerate.
813
814 The code maps our 0 - 510 ms exposure ctrl to these 2
815 registers, trying to keep fps as high as possible.
816 */
Hans de Goede6af492e2008-07-22 07:09:33 -0300817 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
818 int reg10, reg11, reg10_max;
819
Hans de Goede66f35822008-07-16 10:16:28 -0300820 /* ov6645 datasheet says reg10_max is 9a, but that uses
821 tline * 2 * reg10 as formula for calculating texpo, the
822 ov6650 probably uses the same formula as the 7730 which uses
823 tline * 4 * reg10, which explains why the reg10max we've
824 found experimentally for the ov6650 is exactly half that of
Hans de Goedea975a522008-07-16 15:29:11 -0300825 the ov6645. The ov7630 datasheet says the max is 0x41. */
Hans de Goede6af492e2008-07-22 07:09:33 -0300826 if (sd->sensor == SENSOR_OV6650) {
827 reg10_max = 0x4d;
828 i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */
829 } else
830 reg10_max = 0x41;
Hans de Goedef4d52022008-07-15 09:36:42 -0300831
Hans de Goede82e839c2010-02-03 14:37:30 -0300832 reg11 = (15 * sd->exposure + 999) / 1000;
Hans de Goedef4d52022008-07-15 09:36:42 -0300833 if (reg11 < 1)
834 reg11 = 1;
835 else if (reg11 > 16)
836 reg11 = 16;
837
Hans de Goede10bb7532010-02-04 06:10:55 -0300838 /* In 640x480, if the reg11 has less than 4, the image is
839 unstable (the bridge goes into a higher compression mode
840 which we have not reverse engineered yet). */
841 if (gspca_dev->width == 640 && reg11 < 4)
842 reg11 = 4;
Hans de Goedee2ad2a52008-09-03 17:12:15 -0300843
Hans de Goedef4d52022008-07-15 09:36:42 -0300844 /* frame exposure time in ms = 1000 * reg11 / 30 ->
Hans de Goede82e839c2010-02-03 14:37:30 -0300845 reg10 = (sd->exposure / 2) * reg10_max / (1000 * reg11 / 30) */
846 reg10 = (sd->exposure * 15 * reg10_max) / (1000 * reg11);
Hans de Goedea975a522008-07-16 15:29:11 -0300847
848 /* Don't allow this to get below 10 when using autogain, the
849 steps become very large (relatively) when below 10 causing
850 the image to oscilate from much too dark, to much too bright
851 and back again. */
852 if (sd->autogain && reg10 < 10)
853 reg10 = 10;
Hans de Goedef4d52022008-07-15 09:36:42 -0300854 else if (reg10 > reg10_max)
855 reg10 = reg10_max;
856
857 /* Write reg 10 and reg11 low nibble */
Hans de Goedef45f06b2008-09-03 17:12:21 -0300858 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Andoni Zubimendi794af522008-07-16 08:33:14 -0300859 i2c[3] = reg10;
860 i2c[4] |= reg11 - 1;
Hans de Goede6af492e2008-07-22 07:09:33 -0300861
862 /* If register 11 didn't change, don't change it */
Jean-François Moine780e3122010-10-19 04:29:10 -0300863 if (sd->reg11 == reg11)
Hans de Goede6af492e2008-07-22 07:09:33 -0300864 i2c[0] = 0xa0;
865
866 if (i2c_w(gspca_dev, i2c) == 0)
867 sd->reg11 = reg11;
868 else
Hans de Goede82e839c2010-02-03 14:37:30 -0300869 goto err;
870 break;
871 }
872 case SENSOR_PAS202: {
873 __u8 i2cpframerate[] =
874 {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
875 __u8 i2cpexpo[] =
876 {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
877 const __u8 i2cpdoit[] =
878 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
879 int framerate_ctrl;
880
881 /* The exposure knee for the autogain algorithm is 200
882 (100 ms / 10 fps on other sensors), for values below this
883 use the control for setting the partial frame expose time,
884 above that use variable framerate. This way we run at max
885 framerate (640x480@7.5 fps, 320x240@10fps) until the knee
886 is reached. Using the variable framerate control above 200
887 is better then playing around with both clockdiv + partial
888 frame exposure times (like we are doing with the ov chips),
889 as that sometimes leads to jumps in the exposure control,
890 which are bad for auto exposure. */
891 if (sd->exposure < 200) {
892 i2cpexpo[3] = 255 - (sd->exposure * 255) / 200;
893 framerate_ctrl = 500;
894 } else {
895 /* The PAS202's exposure control goes from 0 - 4095,
896 but anything below 500 causes vsync issues, so scale
897 our 200-1023 to 500-4095 */
898 framerate_ctrl = (sd->exposure - 200) * 1000 / 229 +
899 500;
900 }
901
902 i2cpframerate[3] = framerate_ctrl >> 6;
903 i2cpframerate[4] = framerate_ctrl & 0x3f;
904 if (i2c_w(gspca_dev, i2cpframerate) < 0)
905 goto err;
906 if (i2c_w(gspca_dev, i2cpexpo) < 0)
907 goto err;
908 if (i2c_w(gspca_dev, i2cpdoit) < 0)
909 goto err;
Andoni Zubimendi794af522008-07-16 08:33:14 -0300910 break;
911 }
Hans de Goede421763e2010-02-10 18:57:40 -0300912 case SENSOR_PAS106: {
913 __u8 i2cpframerate[] =
914 {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
915 __u8 i2cpexpo[] =
916 {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
917 const __u8 i2cpdoit[] =
918 {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
919 int framerate_ctrl;
920
921 /* For values below 150 use partial frame exposure, above
922 that use framerate ctrl */
923 if (sd->exposure < 150) {
924 i2cpexpo[3] = 150 - sd->exposure;
925 framerate_ctrl = 300;
926 } else {
927 /* The PAS106's exposure control goes from 0 - 4095,
928 but anything below 300 causes vsync issues, so scale
929 our 150-1023 to 300-4095 */
930 framerate_ctrl = (sd->exposure - 150) * 1000 / 230 +
931 300;
932 }
933
934 i2cpframerate[3] = framerate_ctrl >> 4;
935 i2cpframerate[4] = framerate_ctrl & 0x0f;
936 if (i2c_w(gspca_dev, i2cpframerate) < 0)
937 goto err;
938 if (i2c_w(gspca_dev, i2cpexpo) < 0)
939 goto err;
940 if (i2c_w(gspca_dev, i2cpdoit) < 0)
941 goto err;
942 break;
943 }
Hans de Goededcef3232008-07-10 10:40:53 -0300944 }
Hans de Goede82e839c2010-02-03 14:37:30 -0300945 return;
946err:
947 PDEBUG(D_ERR, "i2c error exposure");
Hans de Goededcef3232008-07-10 10:40:53 -0300948}
949
Hans de Goede66f35822008-07-16 10:16:28 -0300950static void setfreq(struct gspca_dev *gspca_dev)
951{
952 struct sd *sd = (struct sd *) gspca_dev;
953
954 switch (sd->sensor) {
Andoni Zubimendid87616f2008-07-17 05:35:52 -0300955 case SENSOR_OV6650:
Hans de Goede6af492e2008-07-22 07:09:33 -0300956 case SENSOR_OV7630: {
Hans de Goede66f35822008-07-16 10:16:28 -0300957 /* Framerate adjust register for artificial light 50 hz flicker
Hans de Goede6af492e2008-07-22 07:09:33 -0300958 compensation, for the ov6650 this is identical to ov6630
959 0x2b register, see ov6630 datasheet.
960 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */
Andoni Zubimendid87616f2008-07-17 05:35:52 -0300961 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
Hans de Goede66f35822008-07-16 10:16:28 -0300962 switch (sd->freq) {
963 default:
964/* case 0: * no filter*/
965/* case 2: * 60 hz */
966 i2c[3] = 0;
967 break;
968 case 1: /* 50 hz */
Hans de Goede722103e2008-07-17 10:24:47 -0300969 i2c[3] = (sd->sensor == SENSOR_OV6650)
970 ? 0x4f : 0x8a;
Hans de Goede66f35822008-07-16 10:16:28 -0300971 break;
972 }
Hans de Goedef45f06b2008-09-03 17:12:21 -0300973 i2c[1] = sensor_data[sd->sensor].sensor_addr;
Hans de Goede66f35822008-07-16 10:16:28 -0300974 if (i2c_w(gspca_dev, i2c) < 0)
975 PDEBUG(D_ERR, "i2c error setfreq");
976 break;
977 }
978 }
979}
980
Hans de Goede26984b02010-02-01 13:18:37 -0300981#include "coarse_expo_autogain.h"
982
Hans de Goededcef3232008-07-10 10:40:53 -0300983static void do_autogain(struct gspca_dev *gspca_dev)
984{
Hans de Goede26984b02010-02-01 13:18:37 -0300985 int deadzone, desired_avg_lum, result;
Hans de Goededcef3232008-07-10 10:40:53 -0300986 struct sd *sd = (struct sd *) gspca_dev;
987 int avg_lum = atomic_read(&sd->avg_lum);
988
Hans de Goede26984b02010-02-01 13:18:37 -0300989 if (avg_lum == -1 || !sd->autogain)
Hans de Goededcef3232008-07-10 10:40:53 -0300990 return;
991
Hans de Goede26984b02010-02-01 13:18:37 -0300992 if (sd->autogain_ignore_frames > 0) {
993 sd->autogain_ignore_frames--;
994 return;
995 }
996
Hans de Goede5017c7b2008-10-22 04:59:29 -0300997 /* SIF / VGA sensors have a different autoexposure area and thus
998 different avg_lum values for the same picture brightness */
999 if (sensor_data[sd->sensor].flags & F_SIF) {
Hans de Goede26984b02010-02-01 13:18:37 -03001000 deadzone = 500;
1001 /* SIF sensors tend to overexpose, so keep this small */
1002 desired_avg_lum = 5000;
Hans de Goede5017c7b2008-10-22 04:59:29 -03001003 } else {
Hans de Goede26984b02010-02-01 13:18:37 -03001004 deadzone = 1500;
Hans de Goede606f8422010-02-10 06:49:23 -03001005 desired_avg_lum = 18000;
Hans de Goede5017c7b2008-10-22 04:59:29 -03001006 }
1007
Hans de Goede26984b02010-02-01 13:18:37 -03001008 if (sensor_data[sd->sensor].flags & F_COARSE_EXPO)
1009 result = gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
1010 sd->brightness * desired_avg_lum / 127,
1011 deadzone);
1012 else
1013 result = gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
1014 sd->brightness * desired_avg_lum / 127,
1015 deadzone, GAIN_KNEE, EXPOSURE_KNEE);
1016
1017 if (result) {
Jean-Francois Moine1c44d812008-11-10 05:56:55 -03001018 PDEBUG(D_FRAM, "autogain: gain changed: gain: %d expo: %d",
Hans de Goedea975a522008-07-16 15:29:11 -03001019 (int)sd->gain, (int)sd->exposure);
Hans de Goededcef3232008-07-10 10:40:53 -03001020 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
Hans de Goedea975a522008-07-16 15:29:11 -03001021 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001022}
1023
1024/* this function is called at probe time */
1025static int sd_config(struct gspca_dev *gspca_dev,
1026 const struct usb_device_id *id)
1027{
1028 struct sd *sd = (struct sd *) gspca_dev;
1029 struct cam *cam;
Hans de Goede65f33392008-09-03 17:12:15 -03001030
1031 reg_r(gspca_dev, 0x00);
1032 if (gspca_dev->usb_buf[0] != 0x10)
1033 return -ENODEV;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001034
Jean-Francois Moine5da162e2008-07-26 14:17:23 -03001035 /* copy the webcam info from the device id */
Hans de Goedef45f06b2008-09-03 17:12:21 -03001036 sd->sensor = id->driver_info >> 8;
1037 sd->bridge = id->driver_info & 0xff;
1038 gspca_dev->ctrl_dis = sensor_data[sd->sensor].ctrl_dis;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001039
1040 cam = &gspca_dev->cam;
Hans de Goedef45f06b2008-09-03 17:12:21 -03001041 if (!(sensor_data[sd->sensor].flags & F_SIF)) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001042 cam->cam_mode = vga_mode;
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -03001043 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001044 } else {
1045 cam->cam_mode = sif_mode;
Andoni Zubimendi51fc8e32008-07-10 11:12:24 -03001046 cam->nmodes = ARRAY_SIZE(sif_mode);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001047 }
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -03001048 cam->npkt = 36; /* 36 packets per ISOC message */
1049
Hans de Goededcef3232008-07-10 10:40:53 -03001050 sd->brightness = BRIGHTNESS_DEF;
1051 sd->gain = GAIN_DEF;
Hans de Goede26984b02010-02-01 13:18:37 -03001052 if (sensor_data[sd->sensor].flags & F_COARSE_EXPO) {
1053 sd->exposure = COARSE_EXPOSURE_DEF;
1054 gspca_dev->ctrl_dis |= (1 << EXPOSURE_IDX);
1055 } else {
1056 sd->exposure = EXPOSURE_DEF;
1057 gspca_dev->ctrl_dis |= (1 << COARSE_EXPOSURE_IDX);
1058 }
Hans de Goedee2ad2a52008-09-03 17:12:15 -03001059 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1060 sd->autogain = 0; /* Disable do_autogain callback */
1061 else
1062 sd->autogain = AUTOGAIN_DEF;
Hans de Goede12ff9122008-07-17 10:30:56 -03001063 sd->freq = FREQ_DEF;
Hans de Goede6af492e2008-07-22 07:09:33 -03001064
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001065 return 0;
1066}
1067
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001068/* this function is called at probe and resume time */
1069static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001070{
Hans de Goede271315a2008-09-03 17:12:19 -03001071 const __u8 stop = 0x09; /* Disable stream turn of LED */
1072
1073 reg_w(gspca_dev, 0x01, &stop, 1);
1074
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001075 return 0;
1076}
1077
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001078/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001079static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001080{
1081 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede93627732008-09-04 16:20:12 -03001082 struct cam *cam = &gspca_dev->cam;
Hans de Goedef45f06b2008-09-03 17:12:21 -03001083 int mode, l;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001084 const __u8 *sn9c10x;
Hans de Goede93627732008-09-04 16:20:12 -03001085 __u8 reg12_19[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001086
Hans de Goede93627732008-09-04 16:20:12 -03001087 mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07;
Hans de Goedef45f06b2008-09-03 17:12:21 -03001088 sn9c10x = sensor_data[sd->sensor].bridge_init[sd->bridge];
1089 l = sensor_data[sd->sensor].bridge_init_size[sd->bridge];
Hans de Goede93627732008-09-04 16:20:12 -03001090 memcpy(reg12_19, &sn9c10x[0x12 - 1], 8);
1091 reg12_19[6] = sn9c10x[0x18 - 1] | (mode << 4);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001092 /* Special cases where reg 17 and or 19 value depends on mode */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001093 switch (sd->sensor) {
Hans de Goedef45f06b2008-09-03 17:12:21 -03001094 case SENSOR_TAS5130CXX:
1095 /* probably not mode specific at all most likely the upper
1096 nibble of 0x19 is exposure (clock divider) just as with
1097 the tas5110, we need someone to test this. */
Hans de Goede93627732008-09-04 16:20:12 -03001098 reg12_19[7] = mode ? 0x23 : 0x43;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001099 break;
1100 }
Hans de Goedec437d652008-09-03 17:12:22 -03001101 /* Disable compression when the raw bayer format has been selected */
Hans de Goede93627732008-09-04 16:20:12 -03001102 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW)
1103 reg12_19[6] &= ~0x80;
1104
1105 /* Vga mode emulation on SIF sensor? */
1106 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) {
1107 reg12_19[0] += 16; /* 0x12: hstart adjust */
1108 reg12_19[1] += 24; /* 0x13: vstart adjust */
1109 reg12_19[3] = 320 / 16; /* 0x15: hsize */
1110 reg12_19[4] = 240 / 16; /* 0x16: vsize */
1111 }
Hans de Goede6af492e2008-07-22 07:09:33 -03001112
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001113 /* reg 0x01 bit 2 video transfert on */
Hans de Goedefff42052008-07-23 07:04:39 -03001114 reg_w(gspca_dev, 0x01, &sn9c10x[0x01 - 1], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001115 /* reg 0x17 SensorClk enable inv Clk 0x60 */
Hans de Goedefff42052008-07-23 07:04:39 -03001116 reg_w(gspca_dev, 0x17, &sn9c10x[0x17 - 1], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001117 /* Set the registers from the template */
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001118 reg_w(gspca_dev, 0x01, sn9c10x, l);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001119
1120 /* Init the sensor */
1121 i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init,
1122 sensor_data[sd->sensor].sensor_init_size);
1123 if (sensor_data[sd->sensor].sensor_bridge_init[sd->bridge])
1124 i2c_w_vector(gspca_dev,
1125 sensor_data[sd->sensor].sensor_bridge_init[sd->bridge],
1126 sensor_data[sd->sensor].sensor_bridge_init_size[
1127 sd->bridge]);
1128
Hans de Goede82e839c2010-02-03 14:37:30 -03001129 /* Mode specific sensor setup */
1130 switch (sd->sensor) {
1131 case SENSOR_PAS202: {
1132 const __u8 i2cpclockdiv[] =
1133 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
1134 /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */
1135 if (mode)
1136 i2c_w(gspca_dev, i2cpclockdiv);
1137 }
1138 }
Hans de Goede3647fea2008-07-15 05:36:30 -03001139 /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */
Hans de Goede93627732008-09-04 16:20:12 -03001140 reg_w(gspca_dev, 0x15, &reg12_19[3], 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001141 /* compression register */
Hans de Goede93627732008-09-04 16:20:12 -03001142 reg_w(gspca_dev, 0x18, &reg12_19[6], 1);
Andoni Zubimendi794af522008-07-16 08:33:14 -03001143 /* H_start */
Hans de Goede93627732008-09-04 16:20:12 -03001144 reg_w(gspca_dev, 0x12, &reg12_19[0], 1);
Andoni Zubimendi794af522008-07-16 08:33:14 -03001145 /* V_START */
Hans de Goede93627732008-09-04 16:20:12 -03001146 reg_w(gspca_dev, 0x13, &reg12_19[1], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001147 /* reset 0x17 SensorClk enable inv Clk 0x60 */
1148 /*fixme: ov7630 [17]=68 8f (+20 if 102)*/
Hans de Goede93627732008-09-04 16:20:12 -03001149 reg_w(gspca_dev, 0x17, &reg12_19[5], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001150 /*MCKSIZE ->3 */ /*fixme: not ov7630*/
Hans de Goede93627732008-09-04 16:20:12 -03001151 reg_w(gspca_dev, 0x19, &reg12_19[7], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001152 /* AE_STRX AE_STRY AE_ENDX AE_ENDY */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001153 reg_w(gspca_dev, 0x1c, &sn9c10x[0x1c - 1], 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001154 /* Enable video transfert */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001155 reg_w(gspca_dev, 0x01, &sn9c10x[0], 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001156 /* Compression */
Hans de Goede93627732008-09-04 16:20:12 -03001157 reg_w(gspca_dev, 0x18, &reg12_19[6], 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001158 msleep(20);
1159
Hans de Goede6af492e2008-07-22 07:09:33 -03001160 sd->reg11 = -1;
1161
Hans de Goededcef3232008-07-10 10:40:53 -03001162 setgain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001163 setbrightness(gspca_dev);
Hans de Goededcef3232008-07-10 10:40:53 -03001164 setexposure(gspca_dev);
Hans de Goede66f35822008-07-16 10:16:28 -03001165 setfreq(gspca_dev);
Hans de Goededcef3232008-07-10 10:40:53 -03001166
Hans de Goede6af492e2008-07-22 07:09:33 -03001167 sd->frames_to_drop = 0;
Hans de Goededcef3232008-07-10 10:40:53 -03001168 sd->autogain_ignore_frames = 0;
Hans de Goede26984b02010-02-01 13:18:37 -03001169 sd->exp_too_high_cnt = 0;
1170 sd->exp_too_low_cnt = 0;
Hans de Goededcef3232008-07-10 10:40:53 -03001171 atomic_set(&sd->avg_lum, -1);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001172 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001173}
1174
1175static void sd_stopN(struct gspca_dev *gspca_dev)
1176{
Hans de Goedef45f06b2008-09-03 17:12:21 -03001177 sd_init(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001178}
1179
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001180static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001181 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001182 int len) /* iso packet length */
1183{
Hans de Goede0d2a7222008-07-03 08:15:22 -03001184 int i;
Hans de Goededcef3232008-07-10 10:40:53 -03001185 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedec437d652008-09-03 17:12:22 -03001186 struct cam *cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001187
Hans de Goedec36260e2008-07-16 09:56:07 -03001188 /* frames start with:
1189 * ff ff 00 c4 c4 96 synchro
1190 * 00 (unknown)
1191 * xx (frame sequence / size / compression)
1192 * (xx) (idem - extra byte for sn9c103)
1193 * ll mm brightness sum inside auto exposure
1194 * ll mm brightness sum outside auto exposure
1195 * (xx xx xx xx xx) audio values for snc103
1196 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001197 if (len > 6 && len < 24) {
Hans de Goede0d2a7222008-07-03 08:15:22 -03001198 for (i = 0; i < len - 6; i++) {
1199 if (data[0 + i] == 0xff
1200 && data[1 + i] == 0xff
1201 && data[2 + i] == 0x00
1202 && data[3 + i] == 0xc4
1203 && data[4 + i] == 0xc4
1204 && data[5 + i] == 0x96) { /* start of frame */
Hans de Goede6af492e2008-07-22 07:09:33 -03001205 int lum = -1;
1206 int pkt_type = LAST_PACKET;
Hans de Goedef45f06b2008-09-03 17:12:21 -03001207 int fr_h_sz = (sd->bridge == BRIDGE_103) ?
1208 18 : 12;
Hans de Goede6af492e2008-07-22 07:09:33 -03001209
Hans de Goedef45f06b2008-09-03 17:12:21 -03001210 if (len - i < fr_h_sz) {
Hans de Goedec36260e2008-07-16 09:56:07 -03001211 PDEBUG(D_STREAM, "packet too short to"
1212 " get avg brightness");
Hans de Goedef45f06b2008-09-03 17:12:21 -03001213 } else if (sd->bridge == BRIDGE_103) {
Hans de Goede6af492e2008-07-22 07:09:33 -03001214 lum = data[i + 9] +
1215 (data[i + 10] << 8);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001216 } else {
1217 lum = data[i + 8] + (data[i + 9] << 8);
Hans de Goededcef3232008-07-10 10:40:53 -03001218 }
Hans de Goedebf2a2202008-09-04 16:22:56 -03001219 /* When exposure changes midway a frame we
1220 get a lum of 0 in this case drop 2 frames
1221 as the frames directly after an exposure
1222 change have an unstable image. Sometimes lum
1223 *really* is 0 (cam used in low light with
1224 low exposure setting), so do not drop frames
1225 if the previous lum was 0 too. */
1226 if (lum == 0 && sd->prev_avg_lum != 0) {
Hans de Goede6af492e2008-07-22 07:09:33 -03001227 lum = -1;
1228 sd->frames_to_drop = 2;
Hans de Goedebf2a2202008-09-04 16:22:56 -03001229 sd->prev_avg_lum = 0;
1230 } else
1231 sd->prev_avg_lum = lum;
Hans de Goede6af492e2008-07-22 07:09:33 -03001232 atomic_set(&sd->avg_lum, lum);
1233
1234 if (sd->frames_to_drop) {
1235 sd->frames_to_drop--;
1236 pkt_type = DISCARD_PACKET;
1237 }
1238
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001239 gspca_frame_add(gspca_dev, pkt_type,
1240 NULL, 0);
Hans de Goedef45f06b2008-09-03 17:12:21 -03001241 data += i + fr_h_sz;
1242 len -= i + fr_h_sz;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001243 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001244 data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001245 return;
1246 }
1247 }
1248 }
Hans de Goedec437d652008-09-03 17:12:22 -03001249
1250 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1251 /* In raw mode we sometimes get some garbage after the frame
1252 ignore this */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001253 int used;
Hans de Goedec437d652008-09-03 17:12:22 -03001254 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
1255
Jean-François Moineb192ca92010-06-27 03:08:19 -03001256 used = gspca_dev->image_len;
Hans de Goedec437d652008-09-03 17:12:22 -03001257 if (used + len > size)
1258 len = size - used;
1259 }
1260
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001261 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001262}
1263
1264static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1265{
1266 struct sd *sd = (struct sd *) gspca_dev;
1267
1268 sd->brightness = val;
1269 if (gspca_dev->streaming)
1270 setbrightness(gspca_dev);
1271 return 0;
1272}
1273
1274static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1275{
1276 struct sd *sd = (struct sd *) gspca_dev;
1277
1278 *val = sd->brightness;
1279 return 0;
1280}
1281
Hans de Goededcef3232008-07-10 10:40:53 -03001282static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001283{
1284 struct sd *sd = (struct sd *) gspca_dev;
1285
Hans de Goededcef3232008-07-10 10:40:53 -03001286 sd->gain = val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001287 if (gspca_dev->streaming)
Hans de Goededcef3232008-07-10 10:40:53 -03001288 setgain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001289 return 0;
1290}
1291
Hans de Goededcef3232008-07-10 10:40:53 -03001292static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001293{
1294 struct sd *sd = (struct sd *) gspca_dev;
1295
Hans de Goededcef3232008-07-10 10:40:53 -03001296 *val = sd->gain;
1297 return 0;
1298}
1299
1300static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1301{
1302 struct sd *sd = (struct sd *) gspca_dev;
1303
1304 sd->exposure = val;
1305 if (gspca_dev->streaming)
1306 setexposure(gspca_dev);
1307 return 0;
1308}
1309
1310static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1311{
1312 struct sd *sd = (struct sd *) gspca_dev;
1313
1314 *val = sd->exposure;
1315 return 0;
1316}
1317
1318static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1319{
1320 struct sd *sd = (struct sd *) gspca_dev;
1321
1322 sd->autogain = val;
Hans de Goede26984b02010-02-01 13:18:37 -03001323 sd->exp_too_high_cnt = 0;
1324 sd->exp_too_low_cnt = 0;
1325
Hans de Goededcef3232008-07-10 10:40:53 -03001326 /* when switching to autogain set defaults to make sure
1327 we are on a valid point of the autogain gain /
1328 exposure knee graph, and give this change time to
1329 take effect before doing autogain. */
Hans de Goede26984b02010-02-01 13:18:37 -03001330 if (sd->autogain && !(sensor_data[sd->sensor].flags & F_COARSE_EXPO)) {
Hans de Goededcef3232008-07-10 10:40:53 -03001331 sd->exposure = EXPOSURE_DEF;
1332 sd->gain = GAIN_DEF;
1333 if (gspca_dev->streaming) {
1334 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
1335 setexposure(gspca_dev);
1336 setgain(gspca_dev);
1337 }
1338 }
1339
1340 return 0;
1341}
1342
1343static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1344{
1345 struct sd *sd = (struct sd *) gspca_dev;
1346
1347 *val = sd->autogain;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001348 return 0;
1349}
1350
Hans de Goede66f35822008-07-16 10:16:28 -03001351static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
1352{
1353 struct sd *sd = (struct sd *) gspca_dev;
1354
1355 sd->freq = val;
1356 if (gspca_dev->streaming)
1357 setfreq(gspca_dev);
1358 return 0;
1359}
1360
1361static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
1362{
1363 struct sd *sd = (struct sd *) gspca_dev;
1364
1365 *val = sd->freq;
1366 return 0;
1367}
1368
1369static int sd_querymenu(struct gspca_dev *gspca_dev,
1370 struct v4l2_querymenu *menu)
1371{
1372 switch (menu->id) {
1373 case V4L2_CID_POWER_LINE_FREQUENCY:
1374 switch (menu->index) {
1375 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1376 strcpy((char *) menu->name, "NoFliker");
1377 return 0;
1378 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1379 strcpy((char *) menu->name, "50 Hz");
1380 return 0;
1381 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1382 strcpy((char *) menu->name, "60 Hz");
1383 return 0;
1384 }
1385 break;
1386 }
1387 return -EINVAL;
1388}
1389
Jean-François Moine28566432010-10-01 07:33:26 -03001390#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goedef65e93d2010-01-31 10:35:15 -03001391static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1392 u8 *data, /* interrupt packet data */
1393 int len) /* interrupt packet length */
1394{
1395 int ret = -EINVAL;
1396
1397 if (len == 1 && data[0] == 1) {
1398 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1399 input_sync(gspca_dev->input_dev);
1400 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1401 input_sync(gspca_dev->input_dev);
1402 ret = 0;
1403 }
1404
1405 return ret;
1406}
1407#endif
1408
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001409/* sub-driver description */
Hans de Goededcef3232008-07-10 10:40:53 -03001410static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001411 .name = MODULE_NAME,
1412 .ctrls = sd_ctrls,
1413 .nctrls = ARRAY_SIZE(sd_ctrls),
1414 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001415 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001416 .start = sd_start,
1417 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001418 .pkt_scan = sd_pkt_scan,
Hans de Goede66f35822008-07-16 10:16:28 -03001419 .querymenu = sd_querymenu,
Hans de Goedee2ad2a52008-09-03 17:12:15 -03001420 .dq_callback = do_autogain,
Jean-François Moine28566432010-10-01 07:33:26 -03001421#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goedef65e93d2010-01-31 10:35:15 -03001422 .int_pkt_scan = sd_int_pkt_scan,
1423#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001424};
1425
1426/* -- module initialisation -- */
Hans de Goedef45f06b2008-09-03 17:12:21 -03001427#define SB(sensor, bridge) \
1428 .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge
1429
Hans de Goedee2ad2a52008-09-03 17:12:15 -03001430
Márton Németh37b372e2009-12-10 11:31:09 -03001431static const struct usb_device_id device_table[] __devinitconst = {
Hans de Goedeb10af3f2010-01-10 19:31:34 -03001432 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */
1433 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */
Hans de Goede222a07f2008-09-03 17:12:20 -03001434#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Hans de Goedeb10af3f2010-01-10 19:31:34 -03001435 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */
Hans de Goede0e4b91c2010-02-10 20:29:43 -03001436#endif
Hans de Goedef45f06b2008-09-03 17:12:21 -03001437 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1438 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001439 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
Hans de Goede222a07f2008-09-03 17:12:20 -03001440#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Hans de Goedef45f06b2008-09-03 17:12:21 -03001441 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1442 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1443 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
Hans de Goede0e4b91c2010-02-10 20:29:43 -03001444#endif
Hans de Goedef45f06b2008-09-03 17:12:21 -03001445 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1446 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
Jean-Francois Moine29fbdf32008-11-07 04:53:28 -03001447 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001448 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
Hans de Goedef45f06b2008-09-03 17:12:21 -03001449 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
Hans de Goede4cce1652008-09-04 16:22:57 -03001450 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
1451#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1452 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
1453#endif
1454 {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001455 {}
1456};
1457MODULE_DEVICE_TABLE(usb, device_table);
1458
1459/* -- device connect -- */
Márton Németh37b372e2009-12-10 11:31:09 -03001460static int __devinit sd_probe(struct usb_interface *intf,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001461 const struct usb_device_id *id)
1462{
1463 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1464 THIS_MODULE);
1465}
1466
1467static struct usb_driver sd_driver = {
1468 .name = MODULE_NAME,
1469 .id_table = device_table,
1470 .probe = sd_probe,
1471 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03001472#ifdef CONFIG_PM
1473 .suspend = gspca_suspend,
1474 .resume = gspca_resume,
1475#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001476};
1477
1478/* -- module insert / remove -- */
1479static int __init sd_mod_init(void)
1480{
Jean-François Moine54826432010-09-13 04:53:03 -03001481 return usb_register(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001482}
1483static void __exit sd_mod_exit(void)
1484{
1485 usb_deregister(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001486}
1487
1488module_init(sd_mod_init);
1489module_exit(sd_mod_exit);