blob: 3b503b50b82e95f6fcc24c9c612632714a545438 [file] [log] [blame]
Hans de Goede1f33de02010-09-05 16:05:22 -03001/*
2 * USB IBM C-It Video Camera driver
3 *
4 * Supports Xirlink C-It Video Camera, IBM PC Camera,
5 * IBM NetCamera and Veo Stingray.
6 *
7 * Copyright (C) 2010 Hans de Goede <hdgoede@redhat.com>
8 *
9 * This driver is based on earlier work of:
10 *
11 * (C) Copyright 1999 Johannes Erdfelt
12 * (C) Copyright 1999 Randy Dunlap
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30#define MODULE_NAME "xirlink-cit"
31
32#include "gspca.h"
33
34MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>");
35MODULE_DESCRIPTION("Xirlink C-IT");
36MODULE_LICENSE("GPL");
37
38/* FIXME we should autodetect this */
39static int ibm_netcam_pro;
40module_param(ibm_netcam_pro, int, 0);
41MODULE_PARM_DESC(ibm_netcam_pro,
42 "Use IBM Netcamera Pro init sequences for Model 3 cams");
43
44/* FIXME this should be handled through the V4L2 input selection API */
45static int rca_input;
46module_param(rca_input, int, 0644);
47MODULE_PARM_DESC(rca_input,
48 "Use rca input instead of ccd sensor on Model 3 cams");
49
50/* specific webcam descriptor */
51struct sd {
52 struct gspca_dev gspca_dev; /* !! must be the first item */
53 u8 model;
Hans de Goede659fefa2010-09-05 16:19:19 -030054#define CIT_MODEL0 0 /* bcd version 0.01 cams ie the xvp-500 */
55#define CIT_MODEL1 1 /* The model 1 - 4 nomenclature comes from the old */
56#define CIT_MODEL2 2 /* ibmcam driver */
57#define CIT_MODEL3 3
58#define CIT_MODEL4 4
59#define CIT_IBM_NETCAM_PRO 5
Hans de Goede1f33de02010-09-05 16:05:22 -030060 u8 input_index;
Hans de Goede59f90a02010-06-09 11:39:50 -030061 u8 stop_on_control_change;
Hans de Goede1f33de02010-09-05 16:05:22 -030062 u8 sof_read;
Hans de Goede59f90a02010-06-09 11:39:50 -030063 u8 sof_len;
Hans de Goede1f33de02010-09-05 16:05:22 -030064 u8 contrast;
65 u8 brightness;
66 u8 hue;
67 u8 sharpness;
Hans de Goede59f90a02010-06-09 11:39:50 -030068 u8 lighting;
Hans de Goede659fefa2010-09-05 16:19:19 -030069 u8 hflip;
Hans de Goede1f33de02010-09-05 16:05:22 -030070};
71
72/* V4L2 controls supported by the driver */
73static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
74static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
75static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
76static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
77static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
78static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
79static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
80static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede59f90a02010-06-09 11:39:50 -030081static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val);
82static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede659fefa2010-09-05 16:19:19 -030083static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
84static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede1f33de02010-09-05 16:05:22 -030085static void sd_stop0(struct gspca_dev *gspca_dev);
86
87static const struct ctrl sd_ctrls[] = {
88#define SD_BRIGHTNESS 0
89 {
90 {
91 .id = V4L2_CID_BRIGHTNESS,
92 .type = V4L2_CTRL_TYPE_INTEGER,
93 .name = "Brightness",
Hans de Goede59f90a02010-06-09 11:39:50 -030094 .minimum = 0,
95 .maximum = 63,
Hans de Goede1f33de02010-09-05 16:05:22 -030096 .step = 1,
Hans de Goede59f90a02010-06-09 11:39:50 -030097#define BRIGHTNESS_DEFAULT 32
Hans de Goede1f33de02010-09-05 16:05:22 -030098 .default_value = BRIGHTNESS_DEFAULT,
99 .flags = 0,
100 },
101 .set = sd_setbrightness,
102 .get = sd_getbrightness,
103 },
104#define SD_CONTRAST 1
105 {
106 {
107 .id = V4L2_CID_CONTRAST,
108 .type = V4L2_CTRL_TYPE_INTEGER,
109 .name = "contrast",
110 .minimum = 0,
111 .maximum = 20,
112 .step = 1,
113#define CONTRAST_DEFAULT 10
114 .default_value = CONTRAST_DEFAULT,
115 .flags = 0,
116 },
117 .set = sd_setcontrast,
118 .get = sd_getcontrast,
119 },
120#define SD_HUE 2
121 {
122 {
123 .id = V4L2_CID_HUE,
124 .type = V4L2_CTRL_TYPE_INTEGER,
125 .name = "Hue",
Hans de Goede59f90a02010-06-09 11:39:50 -0300126 .minimum = 0,
127 .maximum = 127,
Hans de Goede1f33de02010-09-05 16:05:22 -0300128 .step = 1,
Hans de Goede59f90a02010-06-09 11:39:50 -0300129#define HUE_DEFAULT 63
Hans de Goede1f33de02010-09-05 16:05:22 -0300130 .default_value = HUE_DEFAULT,
131 .flags = 0,
132 },
133 .set = sd_sethue,
134 .get = sd_gethue,
135 },
136#define SD_SHARPNESS 3
137 {
138 {
139 .id = V4L2_CID_SHARPNESS,
140 .type = V4L2_CTRL_TYPE_INTEGER,
141 .name = "Sharpness",
142 .minimum = 0,
143 .maximum = 6,
144 .step = 1,
145#define SHARPNESS_DEFAULT 3
146 .default_value = SHARPNESS_DEFAULT,
147 .flags = 0,
148 },
149 .set = sd_setsharpness,
150 .get = sd_getsharpness,
151 },
Hans de Goede59f90a02010-06-09 11:39:50 -0300152#define SD_LIGHTING 4
153 {
154 {
155 .id = V4L2_CID_BACKLIGHT_COMPENSATION,
156 .type = V4L2_CTRL_TYPE_INTEGER,
157 .name = "Lighting",
158 .minimum = 0,
159 .maximum = 2,
160 .step = 1,
161#define LIGHTING_DEFAULT 1
162 .default_value = LIGHTING_DEFAULT,
163 .flags = 0,
164 },
165 .set = sd_setlighting,
166 .get = sd_getlighting,
167 },
Hans de Goede659fefa2010-09-05 16:19:19 -0300168#define SD_HFLIP 5
169 {
170 {
171 .id = V4L2_CID_HFLIP,
172 .type = V4L2_CTRL_TYPE_BOOLEAN,
173 .name = "Mirror",
174 .minimum = 0,
175 .maximum = 1,
176 .step = 1,
177#define HFLIP_DEFAULT 0
178 .default_value = HFLIP_DEFAULT,
179 },
180 .set = sd_sethflip,
181 .get = sd_gethflip,
182 },
Hans de Goede59f90a02010-06-09 11:39:50 -0300183};
184
185static const struct v4l2_pix_format cif_yuv_mode[] = {
186 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
187 .bytesperline = 176,
Hans de Goede659fefa2010-09-05 16:19:19 -0300188 .sizeimage = 176 * 144 * 3 / 2,
Hans de Goede59f90a02010-06-09 11:39:50 -0300189 .colorspace = V4L2_COLORSPACE_SRGB},
190 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
191 .bytesperline = 352,
192 .sizeimage = 352 * 288 * 3 / 2,
193 .colorspace = V4L2_COLORSPACE_SRGB},
Hans de Goede1f33de02010-09-05 16:05:22 -0300194};
195
196static const struct v4l2_pix_format vga_yuv_mode[] = {
197 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
198 .bytesperline = 160,
199 .sizeimage = 160 * 120 * 3 / 2,
200 .colorspace = V4L2_COLORSPACE_SRGB},
201 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
202 .bytesperline = 320,
203 .sizeimage = 320 * 240 * 3 / 2,
204 .colorspace = V4L2_COLORSPACE_SRGB},
205 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
206 .bytesperline = 640,
207 .sizeimage = 640 * 480 * 3 / 2,
208 .colorspace = V4L2_COLORSPACE_SRGB},
209};
210
Hans de Goede659fefa2010-09-05 16:19:19 -0300211static const struct v4l2_pix_format model0_mode[] = {
212 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
213 .bytesperline = 160,
214 .sizeimage = 160 * 120 * 3 / 2,
215 .colorspace = V4L2_COLORSPACE_SRGB},
216 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
217 .bytesperline = 176,
218 .sizeimage = 176 * 144 * 3 / 2,
219 .colorspace = V4L2_COLORSPACE_SRGB},
220 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
221 .bytesperline = 320,
222 .sizeimage = 320 * 240 * 3 / 2,
223 .colorspace = V4L2_COLORSPACE_SRGB},
224};
225
Hans de Goede59f90a02010-06-09 11:39:50 -0300226static const struct v4l2_pix_format model2_mode[] = {
227 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
228 .bytesperline = 160,
229 .sizeimage = 160 * 120 * 3 / 2,
230 .colorspace = V4L2_COLORSPACE_SRGB},
231 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
232 .bytesperline = 176,
233 .sizeimage = 176 * 144 * 3 / 2,
234 .colorspace = V4L2_COLORSPACE_SRGB},
235 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
236 .bytesperline = 320,
237 .sizeimage = 320 * 240,
238 .colorspace = V4L2_COLORSPACE_SRGB},
239 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
240 .bytesperline = 352,
241 .sizeimage = 352 * 288,
242 .colorspace = V4L2_COLORSPACE_SRGB},
243};
244
Hans de Goede1f33de02010-09-05 16:05:22 -0300245/*
246 * 01.01.08 - Added for RCA video in support -LO
247 * This struct is used to init the Model3 cam to use the RCA video in port
248 * instead of the CCD sensor.
249 */
250static const u16 rca_initdata[][3] = {
251 {0, 0x0000, 0x010c},
252 {0, 0x0006, 0x012c},
253 {0, 0x0078, 0x012d},
254 {0, 0x0046, 0x012f},
255 {0, 0xd141, 0x0124},
256 {0, 0x0000, 0x0127},
257 {0, 0xfea8, 0x0124},
258 {1, 0x0000, 0x0116},
259 {0, 0x0064, 0x0116},
260 {1, 0x0000, 0x0115},
261 {0, 0x0003, 0x0115},
262 {0, 0x0008, 0x0123},
263 {0, 0x0000, 0x0117},
264 {0, 0x0000, 0x0112},
265 {0, 0x0080, 0x0100},
266 {0, 0x0000, 0x0100},
267 {1, 0x0000, 0x0116},
268 {0, 0x0060, 0x0116},
269 {0, 0x0002, 0x0112},
270 {0, 0x0000, 0x0123},
271 {0, 0x0001, 0x0117},
272 {0, 0x0040, 0x0108},
273 {0, 0x0019, 0x012c},
274 {0, 0x0040, 0x0116},
275 {0, 0x000a, 0x0115},
276 {0, 0x000b, 0x0115},
277 {0, 0x0078, 0x012d},
278 {0, 0x0046, 0x012f},
279 {0, 0xd141, 0x0124},
280 {0, 0x0000, 0x0127},
281 {0, 0xfea8, 0x0124},
282 {0, 0x0064, 0x0116},
283 {0, 0x0000, 0x0115},
284 {0, 0x0001, 0x0115},
285 {0, 0xffff, 0x0124},
286 {0, 0xfff9, 0x0124},
287 {0, 0x0086, 0x0127},
288 {0, 0xfff8, 0x0124},
289 {0, 0xfffd, 0x0124},
290 {0, 0x00aa, 0x0127},
291 {0, 0xfff8, 0x0124},
292 {0, 0xfffd, 0x0124},
293 {0, 0x0000, 0x0127},
294 {0, 0xfff8, 0x0124},
295 {0, 0xfffd, 0x0124},
296 {0, 0xfffa, 0x0124},
297 {0, 0xffff, 0x0124},
298 {0, 0xfff9, 0x0124},
299 {0, 0x0086, 0x0127},
300 {0, 0xfff8, 0x0124},
301 {0, 0xfffd, 0x0124},
302 {0, 0x00f2, 0x0127},
303 {0, 0xfff8, 0x0124},
304 {0, 0xfffd, 0x0124},
305 {0, 0x000f, 0x0127},
306 {0, 0xfff8, 0x0124},
307 {0, 0xfffd, 0x0124},
308 {0, 0xfffa, 0x0124},
309 {0, 0xffff, 0x0124},
310 {0, 0xfff9, 0x0124},
311 {0, 0x0086, 0x0127},
312 {0, 0xfff8, 0x0124},
313 {0, 0xfffd, 0x0124},
314 {0, 0x00f8, 0x0127},
315 {0, 0xfff8, 0x0124},
316 {0, 0xfffd, 0x0124},
317 {0, 0x00fc, 0x0127},
318 {0, 0xfff8, 0x0124},
319 {0, 0xfffd, 0x0124},
320 {0, 0xfffa, 0x0124},
321 {0, 0xffff, 0x0124},
322 {0, 0xfff9, 0x0124},
323 {0, 0x0086, 0x0127},
324 {0, 0xfff8, 0x0124},
325 {0, 0xfffd, 0x0124},
326 {0, 0x00f9, 0x0127},
327 {0, 0xfff8, 0x0124},
328 {0, 0xfffd, 0x0124},
329 {0, 0x003c, 0x0127},
330 {0, 0xfff8, 0x0124},
331 {0, 0xfffd, 0x0124},
332 {0, 0xfffa, 0x0124},
333 {0, 0xffff, 0x0124},
334 {0, 0xfff9, 0x0124},
335 {0, 0x0086, 0x0127},
336 {0, 0xfff8, 0x0124},
337 {0, 0xfffd, 0x0124},
338 {0, 0x0027, 0x0127},
339 {0, 0xfff8, 0x0124},
340 {0, 0xfffd, 0x0124},
341 {0, 0x0019, 0x0127},
342 {0, 0xfff8, 0x0124},
343 {0, 0xfffd, 0x0124},
344 {0, 0xfffa, 0x0124},
345 {0, 0xfff9, 0x0124},
346 {0, 0x0086, 0x0127},
347 {0, 0xfff8, 0x0124},
348 {0, 0xfffd, 0x0124},
349 {0, 0x0037, 0x0127},
350 {0, 0xfff8, 0x0124},
351 {0, 0xfffd, 0x0124},
352 {0, 0x0000, 0x0127},
353 {0, 0xfff8, 0x0124},
354 {0, 0xfffd, 0x0124},
355 {0, 0x0021, 0x0127},
356 {0, 0xfff8, 0x0124},
357 {0, 0xfffd, 0x0124},
358 {0, 0xfffa, 0x0124},
359 {0, 0xfff9, 0x0124},
360 {0, 0x0086, 0x0127},
361 {0, 0xfff8, 0x0124},
362 {0, 0xfffd, 0x0124},
363 {0, 0x0038, 0x0127},
364 {0, 0xfff8, 0x0124},
365 {0, 0xfffd, 0x0124},
366 {0, 0x0006, 0x0127},
367 {0, 0xfff8, 0x0124},
368 {0, 0xfffd, 0x0124},
369 {0, 0x0045, 0x0127},
370 {0, 0xfff8, 0x0124},
371 {0, 0xfffd, 0x0124},
372 {0, 0xfffa, 0x0124},
373 {0, 0xfff9, 0x0124},
374 {0, 0x0086, 0x0127},
375 {0, 0xfff8, 0x0124},
376 {0, 0xfffd, 0x0124},
377 {0, 0x0037, 0x0127},
378 {0, 0xfff8, 0x0124},
379 {0, 0xfffd, 0x0124},
380 {0, 0x0001, 0x0127},
381 {0, 0xfff8, 0x0124},
382 {0, 0xfffd, 0x0124},
383 {0, 0x002a, 0x0127},
384 {0, 0xfff8, 0x0124},
385 {0, 0xfffd, 0x0124},
386 {0, 0xfffa, 0x0124},
387 {0, 0xfff9, 0x0124},
388 {0, 0x0086, 0x0127},
389 {0, 0xfff8, 0x0124},
390 {0, 0xfffd, 0x0124},
391 {0, 0x0038, 0x0127},
392 {0, 0xfff8, 0x0124},
393 {0, 0xfffd, 0x0124},
394 {0, 0x0000, 0x0127},
395 {0, 0xfff8, 0x0124},
396 {0, 0xfffd, 0x0124},
397 {0, 0x000e, 0x0127},
398 {0, 0xfff8, 0x0124},
399 {0, 0xfffd, 0x0124},
400 {0, 0xfffa, 0x0124},
401 {0, 0xfff9, 0x0124},
402 {0, 0x0086, 0x0127},
403 {0, 0xfff8, 0x0124},
404 {0, 0xfffd, 0x0124},
405 {0, 0x0037, 0x0127},
406 {0, 0xfff8, 0x0124},
407 {0, 0xfffd, 0x0124},
408 {0, 0x0001, 0x0127},
409 {0, 0xfff8, 0x0124},
410 {0, 0xfffd, 0x0124},
411 {0, 0x002b, 0x0127},
412 {0, 0xfff8, 0x0124},
413 {0, 0xfffd, 0x0124},
414 {0, 0xfffa, 0x0124},
415 {0, 0xfff9, 0x0124},
416 {0, 0x0086, 0x0127},
417 {0, 0xfff8, 0x0124},
418 {0, 0xfffd, 0x0124},
419 {0, 0x0038, 0x0127},
420 {0, 0xfff8, 0x0124},
421 {0, 0xfffd, 0x0124},
422 {0, 0x0001, 0x0127},
423 {0, 0xfff8, 0x0124},
424 {0, 0xfffd, 0x0124},
425 {0, 0x00f4, 0x0127},
426 {0, 0xfff8, 0x0124},
427 {0, 0xfffd, 0x0124},
428 {0, 0xfffa, 0x0124},
429 {0, 0xfff9, 0x0124},
430 {0, 0x0086, 0x0127},
431 {0, 0xfff8, 0x0124},
432 {0, 0xfffd, 0x0124},
433 {0, 0x0037, 0x0127},
434 {0, 0xfff8, 0x0124},
435 {0, 0xfffd, 0x0124},
436 {0, 0x0001, 0x0127},
437 {0, 0xfff8, 0x0124},
438 {0, 0xfffd, 0x0124},
439 {0, 0x002c, 0x0127},
440 {0, 0xfff8, 0x0124},
441 {0, 0xfffd, 0x0124},
442 {0, 0xfffa, 0x0124},
443 {0, 0xfff9, 0x0124},
444 {0, 0x0086, 0x0127},
445 {0, 0xfff8, 0x0124},
446 {0, 0xfffd, 0x0124},
447 {0, 0x0038, 0x0127},
448 {0, 0xfff8, 0x0124},
449 {0, 0xfffd, 0x0124},
450 {0, 0x0001, 0x0127},
451 {0, 0xfff8, 0x0124},
452 {0, 0xfffd, 0x0124},
453 {0, 0x0004, 0x0127},
454 {0, 0xfff8, 0x0124},
455 {0, 0xfffd, 0x0124},
456 {0, 0xfffa, 0x0124},
457 {0, 0xfff9, 0x0124},
458 {0, 0x0086, 0x0127},
459 {0, 0xfff8, 0x0124},
460 {0, 0xfffd, 0x0124},
461 {0, 0x0037, 0x0127},
462 {0, 0xfff8, 0x0124},
463 {0, 0xfffd, 0x0124},
464 {0, 0x0001, 0x0127},
465 {0, 0xfff8, 0x0124},
466 {0, 0xfffd, 0x0124},
467 {0, 0x002d, 0x0127},
468 {0, 0xfff8, 0x0124},
469 {0, 0xfffd, 0x0124},
470 {0, 0xfffa, 0x0124},
471 {0, 0xfff9, 0x0124},
472 {0, 0x0086, 0x0127},
473 {0, 0xfff8, 0x0124},
474 {0, 0xfffd, 0x0124},
475 {0, 0x0038, 0x0127},
476 {0, 0xfff8, 0x0124},
477 {0, 0xfffd, 0x0124},
478 {0, 0x0000, 0x0127},
479 {0, 0xfff8, 0x0124},
480 {0, 0xfffd, 0x0124},
481 {0, 0x0014, 0x0127},
482 {0, 0xfff8, 0x0124},
483 {0, 0xfffd, 0x0124},
484 {0, 0xfffa, 0x0124},
485 {0, 0xfff9, 0x0124},
486 {0, 0x0086, 0x0127},
487 {0, 0xfff8, 0x0124},
488 {0, 0xfffd, 0x0124},
489 {0, 0x0037, 0x0127},
490 {0, 0xfff8, 0x0124},
491 {0, 0xfffd, 0x0124},
492 {0, 0x0001, 0x0127},
493 {0, 0xfff8, 0x0124},
494 {0, 0xfffd, 0x0124},
495 {0, 0x002e, 0x0127},
496 {0, 0xfff8, 0x0124},
497 {0, 0xfffd, 0x0124},
498 {0, 0xfffa, 0x0124},
499 {0, 0xfff9, 0x0124},
500 {0, 0x0086, 0x0127},
501 {0, 0xfff8, 0x0124},
502 {0, 0xfffd, 0x0124},
503 {0, 0x0038, 0x0127},
504 {0, 0xfff8, 0x0124},
505 {0, 0xfffd, 0x0124},
506 {0, 0x0003, 0x0127},
507 {0, 0xfff8, 0x0124},
508 {0, 0xfffd, 0x0124},
509 {0, 0x0000, 0x0127},
510 {0, 0xfff8, 0x0124},
511 {0, 0xfffd, 0x0124},
512 {0, 0xfffa, 0x0124},
513 {0, 0xfff9, 0x0124},
514 {0, 0x0086, 0x0127},
515 {0, 0xfff8, 0x0124},
516 {0, 0xfffd, 0x0124},
517 {0, 0x0037, 0x0127},
518 {0, 0xfff8, 0x0124},
519 {0, 0xfffd, 0x0124},
520 {0, 0x0001, 0x0127},
521 {0, 0xfff8, 0x0124},
522 {0, 0xfffd, 0x0124},
523 {0, 0x002f, 0x0127},
524 {0, 0xfff8, 0x0124},
525 {0, 0xfffd, 0x0124},
526 {0, 0xfffa, 0x0124},
527 {0, 0xfff9, 0x0124},
528 {0, 0x0086, 0x0127},
529 {0, 0xfff8, 0x0124},
530 {0, 0xfffd, 0x0124},
531 {0, 0x0038, 0x0127},
532 {0, 0xfff8, 0x0124},
533 {0, 0xfffd, 0x0124},
534 {0, 0x0003, 0x0127},
535 {0, 0xfff8, 0x0124},
536 {0, 0xfffd, 0x0124},
537 {0, 0x0014, 0x0127},
538 {0, 0xfff8, 0x0124},
539 {0, 0xfffd, 0x0124},
540 {0, 0xfffa, 0x0124},
541 {0, 0xfff9, 0x0124},
542 {0, 0x0086, 0x0127},
543 {0, 0xfff8, 0x0124},
544 {0, 0xfffd, 0x0124},
545 {0, 0x0037, 0x0127},
546 {0, 0xfff8, 0x0124},
547 {0, 0xfffd, 0x0124},
548 {0, 0x0001, 0x0127},
549 {0, 0xfff8, 0x0124},
550 {0, 0xfffd, 0x0124},
551 {0, 0x0040, 0x0127},
552 {0, 0xfff8, 0x0124},
553 {0, 0xfffd, 0x0124},
554 {0, 0xfffa, 0x0124},
555 {0, 0xfff9, 0x0124},
556 {0, 0x0086, 0x0127},
557 {0, 0xfff8, 0x0124},
558 {0, 0xfffd, 0x0124},
559 {0, 0x0038, 0x0127},
560 {0, 0xfff8, 0x0124},
561 {0, 0xfffd, 0x0124},
562 {0, 0x0000, 0x0127},
563 {0, 0xfff8, 0x0124},
564 {0, 0xfffd, 0x0124},
565 {0, 0x0040, 0x0127},
566 {0, 0xfff8, 0x0124},
567 {0, 0xfffd, 0x0124},
568 {0, 0xfffa, 0x0124},
569 {0, 0xfff9, 0x0124},
570 {0, 0x0086, 0x0127},
571 {0, 0xfff8, 0x0124},
572 {0, 0xfffd, 0x0124},
573 {0, 0x0037, 0x0127},
574 {0, 0xfff8, 0x0124},
575 {0, 0xfffd, 0x0124},
576 {0, 0x0001, 0x0127},
577 {0, 0xfff8, 0x0124},
578 {0, 0xfffd, 0x0124},
579 {0, 0x0053, 0x0127},
580 {0, 0xfff8, 0x0124},
581 {0, 0xfffd, 0x0124},
582 {0, 0xfffa, 0x0124},
583 {0, 0xfff9, 0x0124},
584 {0, 0x0086, 0x0127},
585 {0, 0xfff8, 0x0124},
586 {0, 0xfffd, 0x0124},
587 {0, 0x0038, 0x0127},
588 {0, 0xfff8, 0x0124},
589 {0, 0xfffd, 0x0124},
590 {0, 0x0000, 0x0127},
591 {0, 0xfff8, 0x0124},
592 {0, 0xfffd, 0x0124},
593 {0, 0x0038, 0x0127},
594 {0, 0xfff8, 0x0124},
595 {0, 0xfffd, 0x0124},
596 {0, 0xfffa, 0x0124},
597 {0, 0x0000, 0x0101},
598 {0, 0x00a0, 0x0103},
599 {0, 0x0078, 0x0105},
600 {0, 0x0000, 0x010a},
601 {0, 0x0024, 0x010b},
602 {0, 0x0028, 0x0119},
603 {0, 0x0088, 0x011b},
604 {0, 0x0002, 0x011d},
605 {0, 0x0003, 0x011e},
606 {0, 0x0000, 0x0129},
607 {0, 0x00fc, 0x012b},
608 {0, 0x0008, 0x0102},
609 {0, 0x0000, 0x0104},
610 {0, 0x0008, 0x011a},
611 {0, 0x0028, 0x011c},
612 {0, 0x0021, 0x012a},
613 {0, 0x0000, 0x0118},
614 {0, 0x0000, 0x0132},
615 {0, 0x0000, 0x0109},
616 {0, 0xfff9, 0x0124},
617 {0, 0x0086, 0x0127},
618 {0, 0xfff8, 0x0124},
619 {0, 0xfffd, 0x0124},
620 {0, 0x0037, 0x0127},
621 {0, 0xfff8, 0x0124},
622 {0, 0xfffd, 0x0124},
623 {0, 0x0001, 0x0127},
624 {0, 0xfff8, 0x0124},
625 {0, 0xfffd, 0x0124},
626 {0, 0x0031, 0x0127},
627 {0, 0xfff8, 0x0124},
628 {0, 0xfffd, 0x0124},
629 {0, 0xfffa, 0x0124},
630 {0, 0xfff9, 0x0124},
631 {0, 0x0086, 0x0127},
632 {0, 0xfff8, 0x0124},
633 {0, 0xfffd, 0x0124},
634 {0, 0x0038, 0x0127},
635 {0, 0xfff8, 0x0124},
636 {0, 0xfffd, 0x0124},
637 {0, 0x0000, 0x0127},
638 {0, 0xfff8, 0x0124},
639 {0, 0xfffd, 0x0124},
640 {0, 0x0000, 0x0127},
641 {0, 0xfff8, 0x0124},
642 {0, 0xfffd, 0x0124},
643 {0, 0xfffa, 0x0124},
644 {0, 0xfff9, 0x0124},
645 {0, 0x0086, 0x0127},
646 {0, 0xfff8, 0x0124},
647 {0, 0xfffd, 0x0124},
648 {0, 0x0037, 0x0127},
649 {0, 0xfff8, 0x0124},
650 {0, 0xfffd, 0x0124},
651 {0, 0x0001, 0x0127},
652 {0, 0xfff8, 0x0124},
653 {0, 0xfffd, 0x0124},
654 {0, 0x0040, 0x0127},
655 {0, 0xfff8, 0x0124},
656 {0, 0xfffd, 0x0124},
657 {0, 0xfffa, 0x0124},
658 {0, 0xfff9, 0x0124},
659 {0, 0x0086, 0x0127},
660 {0, 0xfff8, 0x0124},
661 {0, 0xfffd, 0x0124},
662 {0, 0x0038, 0x0127},
663 {0, 0xfff8, 0x0124},
664 {0, 0xfffd, 0x0124},
665 {0, 0x0000, 0x0127},
666 {0, 0xfff8, 0x0124},
667 {0, 0xfffd, 0x0124},
668 {0, 0x0040, 0x0127},
669 {0, 0xfff8, 0x0124},
670 {0, 0xfffd, 0x0124},
671 {0, 0xfffa, 0x0124},
672 {0, 0xfff9, 0x0124},
673 {0, 0x0086, 0x0127},
674 {0, 0xfff8, 0x0124},
675 {0, 0xfffd, 0x0124},
676 {0, 0x0037, 0x0127},
677 {0, 0xfff8, 0x0124},
678 {0, 0xfffd, 0x0124},
679 {0, 0x0000, 0x0127},
680 {0, 0xfff8, 0x0124},
681 {0, 0xfffd, 0x0124},
682 {0, 0x00dc, 0x0127},
683 {0, 0xfff8, 0x0124},
684 {0, 0xfffd, 0x0124},
685 {0, 0xfffa, 0x0124},
686 {0, 0xfff9, 0x0124},
687 {0, 0x0086, 0x0127},
688 {0, 0xfff8, 0x0124},
689 {0, 0xfffd, 0x0124},
690 {0, 0x0038, 0x0127},
691 {0, 0xfff8, 0x0124},
692 {0, 0xfffd, 0x0124},
693 {0, 0x0000, 0x0127},
694 {0, 0xfff8, 0x0124},
695 {0, 0xfffd, 0x0124},
696 {0, 0x0000, 0x0127},
697 {0, 0xfff8, 0x0124},
698 {0, 0xfffd, 0x0124},
699 {0, 0xfffa, 0x0124},
700 {0, 0xfff9, 0x0124},
701 {0, 0x0086, 0x0127},
702 {0, 0xfff8, 0x0124},
703 {0, 0xfffd, 0x0124},
704 {0, 0x0037, 0x0127},
705 {0, 0xfff8, 0x0124},
706 {0, 0xfffd, 0x0124},
707 {0, 0x0001, 0x0127},
708 {0, 0xfff8, 0x0124},
709 {0, 0xfffd, 0x0124},
710 {0, 0x0032, 0x0127},
711 {0, 0xfff8, 0x0124},
712 {0, 0xfffd, 0x0124},
713 {0, 0xfffa, 0x0124},
714 {0, 0xfff9, 0x0124},
715 {0, 0x0086, 0x0127},
716 {0, 0xfff8, 0x0124},
717 {0, 0xfffd, 0x0124},
718 {0, 0x0038, 0x0127},
719 {0, 0xfff8, 0x0124},
720 {0, 0xfffd, 0x0124},
721 {0, 0x0001, 0x0127},
722 {0, 0xfff8, 0x0124},
723 {0, 0xfffd, 0x0124},
724 {0, 0x0020, 0x0127},
725 {0, 0xfff8, 0x0124},
726 {0, 0xfffd, 0x0124},
727 {0, 0xfffa, 0x0124},
728 {0, 0xfff9, 0x0124},
729 {0, 0x0086, 0x0127},
730 {0, 0xfff8, 0x0124},
731 {0, 0xfffd, 0x0124},
732 {0, 0x0037, 0x0127},
733 {0, 0xfff8, 0x0124},
734 {0, 0xfffd, 0x0124},
735 {0, 0x0001, 0x0127},
736 {0, 0xfff8, 0x0124},
737 {0, 0xfffd, 0x0124},
738 {0, 0x0040, 0x0127},
739 {0, 0xfff8, 0x0124},
740 {0, 0xfffd, 0x0124},
741 {0, 0xfffa, 0x0124},
742 {0, 0xfff9, 0x0124},
743 {0, 0x0086, 0x0127},
744 {0, 0xfff8, 0x0124},
745 {0, 0xfffd, 0x0124},
746 {0, 0x0038, 0x0127},
747 {0, 0xfff8, 0x0124},
748 {0, 0xfffd, 0x0124},
749 {0, 0x0000, 0x0127},
750 {0, 0xfff8, 0x0124},
751 {0, 0xfffd, 0x0124},
752 {0, 0x0040, 0x0127},
753 {0, 0xfff8, 0x0124},
754 {0, 0xfffd, 0x0124},
755 {0, 0xfffa, 0x0124},
756 {0, 0xfff9, 0x0124},
757 {0, 0x0086, 0x0127},
758 {0, 0xfff8, 0x0124},
759 {0, 0xfffd, 0x0124},
760 {0, 0x0037, 0x0127},
761 {0, 0xfff8, 0x0124},
762 {0, 0xfffd, 0x0124},
763 {0, 0x0000, 0x0127},
764 {0, 0xfff8, 0x0124},
765 {0, 0xfffd, 0x0124},
766 {0, 0x0030, 0x0127},
767 {0, 0xfff8, 0x0124},
768 {0, 0xfffd, 0x0124},
769 {0, 0xfffa, 0x0124},
770 {0, 0xfff9, 0x0124},
771 {0, 0x0086, 0x0127},
772 {0, 0xfff8, 0x0124},
773 {0, 0xfffd, 0x0124},
774 {0, 0x0038, 0x0127},
775 {0, 0xfff8, 0x0124},
776 {0, 0xfffd, 0x0124},
777 {0, 0x0008, 0x0127},
778 {0, 0xfff8, 0x0124},
779 {0, 0xfffd, 0x0124},
780 {0, 0x0000, 0x0127},
781 {0, 0xfff8, 0x0124},
782 {0, 0xfffd, 0x0124},
783 {0, 0xfffa, 0x0124},
784 {0, 0x0003, 0x0111},
785};
786
Hans de Goede59f90a02010-06-09 11:39:50 -0300787/* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we
788 do the same for now (testing needed to see if this is really necessary) */
789static const int cit_model1_ntries = 5;
790static const int cit_model1_ntries2 = 2;
791
Hans de Goede1f33de02010-09-05 16:05:22 -0300792static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
793{
794 struct usb_device *udev = gspca_dev->dev;
795 int err;
796
797 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
798 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
799 value, index, NULL, 0, 1000);
800 if (err < 0)
801 PDEBUG(D_ERR, "Failed to write a register (index 0x%04X,"
802 " value 0x%02X, error %d)", index, value, err);
803
804 return 0;
805}
806
807static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index)
808{
809 struct usb_device *udev = gspca_dev->dev;
810 __u8 *buf = gspca_dev->usb_buf;
811 int res;
812
813 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01,
814 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
815 0x00, index, buf, 8, 1000);
816 if (res < 0) {
817 PDEBUG(D_ERR,
818 "Failed to read a register (index 0x%04X, error %d)",
819 index, res);
820 return res;
821 }
822
823 PDEBUG(D_PROBE,
824 "Register %04x value: %02x %02x %02x %02x %02x %02x %02x %02x",
825 index,
826 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
827
828 return 0;
829}
830
831/*
Hans de Goede59f90a02010-06-09 11:39:50 -0300832 * cit_send_FF_04_02()
833 *
834 * This procedure sends magic 3-command prefix to the camera.
835 * The purpose of this prefix is not known.
836 *
837 * History:
838 * 1/2/00 Created.
839 */
840static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
841{
842 cit_write_reg(gspca_dev, 0x00FF, 0x0127);
843 cit_write_reg(gspca_dev, 0x0004, 0x0124);
844 cit_write_reg(gspca_dev, 0x0002, 0x0124);
845}
846
847static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
848{
849 cit_write_reg(gspca_dev, 0x0000, 0x0127);
850 cit_write_reg(gspca_dev, 0x0004, 0x0124);
851 cit_write_reg(gspca_dev, 0x0006, 0x0124);
852}
853
854static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
855{
856 cit_write_reg(gspca_dev, x, 0x0127);
857 cit_write_reg(gspca_dev, 0x0000, 0x0124);
858}
859
860static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
861{
862 cit_send_x_00(gspca_dev, x);
863 cit_write_reg(gspca_dev, 0x0005, 0x0124);
864}
865
866static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
867{
868 cit_write_reg(gspca_dev, x, 0x0127);
869 cit_write_reg(gspca_dev, 0x0000, 0x0124);
870 cit_write_reg(gspca_dev, 0x0005, 0x0124);
871 cit_write_reg(gspca_dev, 0x0002, 0x0124);
872}
873
874static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
875{
876 cit_write_reg(gspca_dev, x, 0x0127);
877 cit_write_reg(gspca_dev, 0x0001, 0x0124);
878 cit_write_reg(gspca_dev, 0x0000, 0x0124);
879 cit_write_reg(gspca_dev, 0x0005, 0x0124);
880}
881
882static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
883{
884 cit_write_reg(gspca_dev, x, 0x0127);
885 cit_write_reg(gspca_dev, 0x0000, 0x0124);
886 cit_write_reg(gspca_dev, 0x0005, 0x0124);
887 cit_write_reg(gspca_dev, 0x0002, 0x0124);
888 cit_write_reg(gspca_dev, 0x0001, 0x0124);
889}
890
891static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
892{
893 cit_write_reg(gspca_dev, x, 0x0127);
894 cit_write_reg(gspca_dev, 0x0000, 0x0124);
895 cit_write_reg(gspca_dev, 0x0005, 0x0124);
896 cit_write_reg(gspca_dev, 0x0002, 0x0124);
897 cit_write_reg(gspca_dev, 0x0008, 0x0124);
898 cit_write_reg(gspca_dev, 0x0001, 0x0124);
899}
900
901static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
902{
903 cit_send_x_01_00_05(gspca_dev, 0x0088);
904 cit_send_x_00_05(gspca_dev, fkey);
905 cit_send_x_00_05_02_08_01(gspca_dev, val);
906 cit_send_x_00_05(gspca_dev, 0x0088);
907 cit_send_x_00_05_02_01(gspca_dev, fkey);
908 cit_send_x_00_05(gspca_dev, 0x0089);
909 cit_send_x_00(gspca_dev, fkey);
910 cit_send_00_04_06(gspca_dev);
911 cit_read_reg(gspca_dev, 0x0126);
912 cit_send_FF_04_02(gspca_dev);
913}
914
915static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
916{
917 cit_send_x_01_00_05(gspca_dev, 0x0088);
918 cit_send_x_00_05(gspca_dev, fkey);
919 cit_send_x_00_05_02(gspca_dev, val);
920}
921
922static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
923{
924 cit_write_reg(gspca_dev, 0x00ff, 0x012d);
925 cit_write_reg(gspca_dev, 0xfea3, 0x0124);
926}
927
928static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
929{
930 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
931 cit_write_reg(gspca_dev, 0x00ff, 0x012e);
932 cit_write_reg(gspca_dev, v1, 0x012f);
933 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
934 cit_write_reg(gspca_dev, 0xc719, 0x0124);
935 cit_write_reg(gspca_dev, v2, 0x0127);
936
937 cit_model2_Packet2(gspca_dev);
938}
939
940/*
941 * cit_model3_Packet1()
Hans de Goede1f33de02010-09-05 16:05:22 -0300942 *
943 * 00_0078_012d
944 * 00_0097_012f
945 * 00_d141_0124
946 * 00_0096_0127
947 * 00_fea8_0124
948*/
949static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
950{
951 cit_write_reg(gspca_dev, 0x0078, 0x012d);
952 cit_write_reg(gspca_dev, v1, 0x012f);
953 cit_write_reg(gspca_dev, 0xd141, 0x0124);
954 cit_write_reg(gspca_dev, v2, 0x0127);
955 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
956}
957
Hans de Goede59f90a02010-06-09 11:39:50 -0300958static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
959{
960 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
961 cit_write_reg(gspca_dev, v1, 0x012f);
962 cit_write_reg(gspca_dev, 0xd141, 0x0124);
963 cit_write_reg(gspca_dev, v2, 0x0127);
964 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
965}
966
967static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
968{
969 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
970 cit_write_reg(gspca_dev, 0x0026, 0x012f);
971 cit_write_reg(gspca_dev, 0xd141, 0x0124);
972 cit_write_reg(gspca_dev, val, 0x0127);
973 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
974 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
975 cit_write_reg(gspca_dev, 0x0038, 0x012d);
976 cit_write_reg(gspca_dev, 0x0004, 0x012f);
977 cit_write_reg(gspca_dev, 0xd145, 0x0124);
978 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
979}
980
Hans de Goede1f33de02010-09-05 16:05:22 -0300981/* this function is called at probe time */
982static int sd_config(struct gspca_dev *gspca_dev,
983 const struct usb_device_id *id)
984{
985 struct sd *sd = (struct sd *) gspca_dev;
986 struct cam *cam;
987
988 sd->model = id->driver_info;
989 if (sd->model == CIT_MODEL3 && ibm_netcam_pro)
990 sd->model = CIT_IBM_NETCAM_PRO;
991
992 cam = &gspca_dev->cam;
993 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -0300994 case CIT_MODEL0:
995 cam->cam_mode = model0_mode;
996 cam->nmodes = ARRAY_SIZE(model0_mode);
997 cam->reverse_alts = 1;
998 gspca_dev->ctrl_dis = ~((1 << SD_CONTRAST) | (1 << SD_HFLIP));
999 sd->sof_len = 4;
1000 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001001 case CIT_MODEL1:
1002 cam->cam_mode = cif_yuv_mode;
1003 cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
Hans de Goede659fefa2010-09-05 16:19:19 -03001004 cam->reverse_alts = 1;
1005 gspca_dev->ctrl_dis = (1 << SD_HUE) | (1 << SD_HFLIP);
1006 sd->sof_len = 4;
Hans de Goede59f90a02010-06-09 11:39:50 -03001007 break;
1008 case CIT_MODEL2:
1009 cam->cam_mode = model2_mode + 1; /* no 160x120 */
1010 cam->nmodes = 3;
1011 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
Hans de Goede659fefa2010-09-05 16:19:19 -03001012 (1 << SD_SHARPNESS) |
1013 (1 << SD_HFLIP);
Hans de Goede59f90a02010-06-09 11:39:50 -03001014 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001015 case CIT_MODEL3:
1016 cam->cam_mode = vga_yuv_mode;
1017 cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
Hans de Goede659fefa2010-09-05 16:19:19 -03001018 gspca_dev->ctrl_dis = (1 << SD_HUE) |
1019 (1 << SD_LIGHTING) |
1020 (1 << SD_HFLIP);
Hans de Goede59f90a02010-06-09 11:39:50 -03001021 sd->stop_on_control_change = 1;
Hans de Goede659fefa2010-09-05 16:19:19 -03001022 sd->sof_len = 4;
Hans de Goede59f90a02010-06-09 11:39:50 -03001023 break;
1024 case CIT_MODEL4:
1025 cam->cam_mode = model2_mode;
1026 cam->nmodes = ARRAY_SIZE(model2_mode);
1027 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
1028 (1 << SD_SHARPNESS) |
Hans de Goede659fefa2010-09-05 16:19:19 -03001029 (1 << SD_LIGHTING) |
1030 (1 << SD_HFLIP);
Hans de Goede1f33de02010-09-05 16:05:22 -03001031 break;
1032 case CIT_IBM_NETCAM_PRO:
1033 cam->cam_mode = vga_yuv_mode;
1034 cam->nmodes = 2; /* no 640 x 480 */
1035 cam->input_flags = V4L2_IN_ST_VFLIP;
1036 gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST);
Hans de Goede59f90a02010-06-09 11:39:50 -03001037 sd->stop_on_control_change = 1;
Hans de Goede659fefa2010-09-05 16:19:19 -03001038 sd->sof_len = 4;
Hans de Goede1f33de02010-09-05 16:05:22 -03001039 break;
1040 }
1041
1042 sd->brightness = BRIGHTNESS_DEFAULT;
1043 sd->contrast = CONTRAST_DEFAULT;
1044 sd->hue = HUE_DEFAULT;
1045 sd->sharpness = SHARPNESS_DEFAULT;
Hans de Goede59f90a02010-06-09 11:39:50 -03001046 sd->lighting = LIGHTING_DEFAULT;
Hans de Goede659fefa2010-09-05 16:19:19 -03001047 sd->hflip = HFLIP_DEFAULT;
1048
1049 return 0;
1050}
1051
1052static int cit_init_model0(struct gspca_dev *gspca_dev)
1053{
1054 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1055 cit_write_reg(gspca_dev, 0x0001, 0x0112); /* turn on autogain ? */
1056 cit_write_reg(gspca_dev, 0x0000, 0x0400);
1057 cit_write_reg(gspca_dev, 0x0001, 0x0400);
1058 cit_write_reg(gspca_dev, 0x0000, 0x0420);
1059 cit_write_reg(gspca_dev, 0x0001, 0x0420);
1060 cit_write_reg(gspca_dev, 0x000d, 0x0409);
1061 cit_write_reg(gspca_dev, 0x0002, 0x040a);
1062 cit_write_reg(gspca_dev, 0x0018, 0x0405);
1063 cit_write_reg(gspca_dev, 0x0008, 0x0435);
1064 cit_write_reg(gspca_dev, 0x0026, 0x040b);
1065 cit_write_reg(gspca_dev, 0x0007, 0x0437);
1066 cit_write_reg(gspca_dev, 0x0015, 0x042f);
1067 cit_write_reg(gspca_dev, 0x002b, 0x0439);
1068 cit_write_reg(gspca_dev, 0x0026, 0x043a);
1069 cit_write_reg(gspca_dev, 0x0008, 0x0438);
1070 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1071 cit_write_reg(gspca_dev, 0x0041, 0x042c);
Hans de Goede1f33de02010-09-05 16:05:22 -03001072
1073 return 0;
1074}
1075
1076static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1077{
1078 cit_read_reg(gspca_dev, 0x128);
1079 cit_write_reg(gspca_dev, 0x0003, 0x0133);
1080 cit_write_reg(gspca_dev, 0x0000, 0x0117);
1081 cit_write_reg(gspca_dev, 0x0008, 0x0123);
1082 cit_write_reg(gspca_dev, 0x0000, 0x0100);
1083 cit_read_reg(gspca_dev, 0x0116);
1084 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1085 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1086 cit_write_reg(gspca_dev, 0x0000, 0x0133);
1087 cit_write_reg(gspca_dev, 0x0000, 0x0123);
1088 cit_write_reg(gspca_dev, 0x0001, 0x0117);
1089 cit_write_reg(gspca_dev, 0x0040, 0x0108);
1090 cit_write_reg(gspca_dev, 0x0019, 0x012c);
1091 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1092 cit_write_reg(gspca_dev, 0x0002, 0x0115);
1093 cit_write_reg(gspca_dev, 0x000b, 0x0115);
1094
1095 cit_write_reg(gspca_dev, 0x0078, 0x012d);
1096 cit_write_reg(gspca_dev, 0x0001, 0x012f);
1097 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1098 cit_write_reg(gspca_dev, 0x0079, 0x012d);
1099 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
1100 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
1101 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
1102 cit_read_reg(gspca_dev, 0x0126);
1103
1104 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000);
1105 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001);
1106 cit_model3_Packet1(gspca_dev, 0x000b, 0x0000);
1107 cit_model3_Packet1(gspca_dev, 0x000c, 0x0008);
1108 cit_model3_Packet1(gspca_dev, 0x000d, 0x003a);
1109 cit_model3_Packet1(gspca_dev, 0x000e, 0x0060);
1110 cit_model3_Packet1(gspca_dev, 0x000f, 0x0060);
1111 cit_model3_Packet1(gspca_dev, 0x0010, 0x0008);
1112 cit_model3_Packet1(gspca_dev, 0x0011, 0x0004);
1113 cit_model3_Packet1(gspca_dev, 0x0012, 0x0028);
1114 cit_model3_Packet1(gspca_dev, 0x0013, 0x0002);
1115 cit_model3_Packet1(gspca_dev, 0x0014, 0x0000);
1116 cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb);
1117 cit_model3_Packet1(gspca_dev, 0x0016, 0x0002);
1118 cit_model3_Packet1(gspca_dev, 0x0017, 0x0037);
1119 cit_model3_Packet1(gspca_dev, 0x0018, 0x0036);
1120 cit_model3_Packet1(gspca_dev, 0x001e, 0x0000);
1121 cit_model3_Packet1(gspca_dev, 0x001f, 0x0008);
1122 cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1);
1123 cit_model3_Packet1(gspca_dev, 0x0021, 0x0034);
1124 cit_model3_Packet1(gspca_dev, 0x0022, 0x0034);
1125 cit_model3_Packet1(gspca_dev, 0x0025, 0x0002);
1126 cit_model3_Packet1(gspca_dev, 0x0028, 0x0022);
1127 cit_model3_Packet1(gspca_dev, 0x0029, 0x000a);
1128 cit_model3_Packet1(gspca_dev, 0x002b, 0x0000);
1129 cit_model3_Packet1(gspca_dev, 0x002c, 0x0000);
1130 cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff);
1131 cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff);
1132 cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff);
1133 cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff);
1134 cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff);
1135 cit_model3_Packet1(gspca_dev, 0x0032, 0x0007);
1136 cit_model3_Packet1(gspca_dev, 0x0033, 0x0005);
1137 cit_model3_Packet1(gspca_dev, 0x0037, 0x0040);
1138 cit_model3_Packet1(gspca_dev, 0x0039, 0x0000);
1139 cit_model3_Packet1(gspca_dev, 0x003a, 0x0000);
1140 cit_model3_Packet1(gspca_dev, 0x003b, 0x0001);
1141 cit_model3_Packet1(gspca_dev, 0x003c, 0x0000);
1142 cit_model3_Packet1(gspca_dev, 0x0040, 0x000c);
1143 cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb);
1144 cit_model3_Packet1(gspca_dev, 0x0042, 0x0002);
1145 cit_model3_Packet1(gspca_dev, 0x0043, 0x0000);
1146 cit_model3_Packet1(gspca_dev, 0x0045, 0x0000);
1147 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
1148 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
1149 cit_model3_Packet1(gspca_dev, 0x0048, 0x0000);
1150 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
1151 cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff);
1152 cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff);
1153 cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff);
1154 cit_model3_Packet1(gspca_dev, 0x004f, 0x0000);
1155 cit_model3_Packet1(gspca_dev, 0x0050, 0x0000);
1156 cit_model3_Packet1(gspca_dev, 0x0051, 0x0002);
1157 cit_model3_Packet1(gspca_dev, 0x0055, 0x0000);
1158 cit_model3_Packet1(gspca_dev, 0x0056, 0x0000);
1159 cit_model3_Packet1(gspca_dev, 0x0057, 0x0000);
1160 cit_model3_Packet1(gspca_dev, 0x0058, 0x0002);
1161 cit_model3_Packet1(gspca_dev, 0x0059, 0x0000);
1162 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016);
1163 cit_model3_Packet1(gspca_dev, 0x005d, 0x0022);
1164 cit_model3_Packet1(gspca_dev, 0x005e, 0x003c);
1165 cit_model3_Packet1(gspca_dev, 0x005f, 0x0050);
1166 cit_model3_Packet1(gspca_dev, 0x0060, 0x0044);
1167 cit_model3_Packet1(gspca_dev, 0x0061, 0x0005);
1168 cit_model3_Packet1(gspca_dev, 0x006a, 0x007e);
1169 cit_model3_Packet1(gspca_dev, 0x006f, 0x0000);
1170 cit_model3_Packet1(gspca_dev, 0x0072, 0x001b);
1171 cit_model3_Packet1(gspca_dev, 0x0073, 0x0005);
1172 cit_model3_Packet1(gspca_dev, 0x0074, 0x000a);
1173 cit_model3_Packet1(gspca_dev, 0x0075, 0x001b);
1174 cit_model3_Packet1(gspca_dev, 0x0076, 0x002a);
1175 cit_model3_Packet1(gspca_dev, 0x0077, 0x003c);
1176 cit_model3_Packet1(gspca_dev, 0x0078, 0x0050);
1177 cit_model3_Packet1(gspca_dev, 0x007b, 0x0000);
1178 cit_model3_Packet1(gspca_dev, 0x007c, 0x0011);
1179 cit_model3_Packet1(gspca_dev, 0x007d, 0x0024);
1180 cit_model3_Packet1(gspca_dev, 0x007e, 0x0043);
1181 cit_model3_Packet1(gspca_dev, 0x007f, 0x005a);
1182 cit_model3_Packet1(gspca_dev, 0x0084, 0x0020);
1183 cit_model3_Packet1(gspca_dev, 0x0085, 0x0033);
1184 cit_model3_Packet1(gspca_dev, 0x0086, 0x000a);
1185 cit_model3_Packet1(gspca_dev, 0x0087, 0x0030);
1186 cit_model3_Packet1(gspca_dev, 0x0088, 0x0070);
1187 cit_model3_Packet1(gspca_dev, 0x008b, 0x0008);
1188 cit_model3_Packet1(gspca_dev, 0x008f, 0x0000);
1189 cit_model3_Packet1(gspca_dev, 0x0090, 0x0006);
1190 cit_model3_Packet1(gspca_dev, 0x0091, 0x0028);
1191 cit_model3_Packet1(gspca_dev, 0x0092, 0x005a);
1192 cit_model3_Packet1(gspca_dev, 0x0093, 0x0082);
1193 cit_model3_Packet1(gspca_dev, 0x0096, 0x0014);
1194 cit_model3_Packet1(gspca_dev, 0x0097, 0x0020);
1195 cit_model3_Packet1(gspca_dev, 0x0098, 0x0000);
1196 cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046);
1197 cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000);
1198 cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000);
1199 cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004);
1200 cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007);
1201 cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002);
1202 cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004);
1203 cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000);
1204 cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001);
1205 cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000);
1206 cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000);
1207 cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8);
1208 cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014);
1209 cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001);
1210 cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000);
1211 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004);
1212 cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf);
1213 cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf);
1214 cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf);
1215 cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000);
1216 cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020);
1217 cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040);
1218 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1219 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1220 cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf);
1221 cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf);
1222 cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008);
1223 cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000);
1224 cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8);
1225 cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001);
1226 cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022);
1227 cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000);
1228 cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028);
1229 cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002);
1230 cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000);
1231 cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000);
1232 cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001);
1233 cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000);
1234 cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000);
1235 cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000);
1236 cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000);
1237
1238 cit_model3_Packet1(gspca_dev, 0x00be, 0x0003);
1239 cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000);
1240 cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020);
1241 cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040);
1242 cit_model3_Packet1(gspca_dev, 0x0053, 0x0001);
1243 cit_model3_Packet1(gspca_dev, 0x0082, 0x000e);
1244 cit_model3_Packet1(gspca_dev, 0x0083, 0x0020);
1245 cit_model3_Packet1(gspca_dev, 0x0034, 0x003c);
1246 cit_model3_Packet1(gspca_dev, 0x006e, 0x0055);
1247 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005);
1248 cit_model3_Packet1(gspca_dev, 0x0063, 0x0008);
1249 cit_model3_Packet1(gspca_dev, 0x0066, 0x000a);
1250 cit_model3_Packet1(gspca_dev, 0x0067, 0x0006);
1251 cit_model3_Packet1(gspca_dev, 0x006b, 0x0010);
1252 cit_model3_Packet1(gspca_dev, 0x005a, 0x0001);
1253 cit_model3_Packet1(gspca_dev, 0x005b, 0x000a);
1254 cit_model3_Packet1(gspca_dev, 0x0023, 0x0006);
1255 cit_model3_Packet1(gspca_dev, 0x0026, 0x0004);
1256 cit_model3_Packet1(gspca_dev, 0x0036, 0x0069);
1257 cit_model3_Packet1(gspca_dev, 0x0038, 0x0064);
1258 cit_model3_Packet1(gspca_dev, 0x003d, 0x0003);
1259 cit_model3_Packet1(gspca_dev, 0x003e, 0x0001);
1260 cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014);
1261 cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014);
1262 cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004);
1263 cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001);
1264
1265 return 0;
1266}
1267
1268/* this function is called at probe and resume time */
1269static int sd_init(struct gspca_dev *gspca_dev)
1270{
1271 struct sd *sd = (struct sd *) gspca_dev;
1272
1273 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001274 case CIT_MODEL0:
1275 cit_init_model0(gspca_dev);
1276 sd_stop0(gspca_dev);
1277 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001278 case CIT_MODEL1:
1279 case CIT_MODEL2:
Hans de Goede1f33de02010-09-05 16:05:22 -03001280 case CIT_MODEL3:
Hans de Goede59f90a02010-06-09 11:39:50 -03001281 case CIT_MODEL4:
Hans de Goede1f33de02010-09-05 16:05:22 -03001282 break; /* All is done in sd_start */
1283 case CIT_IBM_NETCAM_PRO:
1284 cit_init_ibm_netcam_pro(gspca_dev);
1285 sd_stop0(gspca_dev);
1286 break;
1287 }
1288 return 0;
1289}
1290
1291static int cit_set_brightness(struct gspca_dev *gspca_dev)
1292{
1293 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede59f90a02010-06-09 11:39:50 -03001294 int i;
Hans de Goede1f33de02010-09-05 16:05:22 -03001295
1296 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001297 case CIT_MODEL0:
1298 case CIT_IBM_NETCAM_PRO:
1299 /* No (known) brightness control for these */
1300 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001301 case CIT_MODEL1:
1302 /* Model 1: Brightness range 0 - 63 */
1303 cit_Packet_Format1(gspca_dev, 0x0031, sd->brightness);
1304 cit_Packet_Format1(gspca_dev, 0x0032, sd->brightness);
1305 cit_Packet_Format1(gspca_dev, 0x0033, sd->brightness);
1306 break;
1307 case CIT_MODEL2:
1308 /* Model 2: Brightness range 0x60 - 0xee */
1309 /* Scale 0 - 63 to 0x60 - 0xee */
1310 i = 0x60 + sd->brightness * 2254 / 1000;
1311 cit_model2_Packet1(gspca_dev, 0x001a, i);
1312 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001313 case CIT_MODEL3:
1314 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
Hans de Goede59f90a02010-06-09 11:39:50 -03001315 i = sd->brightness;
1316 if (i < 0x0c)
1317 i = 0x0c;
1318 cit_model3_Packet1(gspca_dev, 0x0036, i);
1319 break;
1320 case CIT_MODEL4:
1321 /* Model 4: Brightness range 'i' in [0x04..0xb4] */
1322 /* Scale 0 - 63 to 0x04 - 0xb4 */
1323 i = 0x04 + sd->brightness * 2794 / 1000;
1324 cit_model4_BrightnessPacket(gspca_dev, i);
Hans de Goede1f33de02010-09-05 16:05:22 -03001325 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001326 }
1327
1328 return 0;
1329}
1330
1331static int cit_set_contrast(struct gspca_dev *gspca_dev)
1332{
1333 struct sd *sd = (struct sd *) gspca_dev;
1334
1335 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001336 case CIT_MODEL0: {
1337 int i;
1338 /* gain 0-15, 0-20 -> 0-15 */
1339 i = sd->contrast * 1000 / 1333;
1340 cit_write_reg(gspca_dev, i, 0x0422);
1341 /* gain 0-31, may not be lower then 0x0422, 0-20 -> 0-31 */
1342 i = sd->contrast * 2000 / 1333;
1343 cit_write_reg(gspca_dev, i, 0x0423);
1344 /* gain 0-127, may not be lower then 0x0423, 0-20 -> 0-63 */
1345 i = sd->contrast * 4000 / 1333;
1346 cit_write_reg(gspca_dev, i, 0x0424);
1347 /* gain 0-127, may not be lower then 0x0424, , 0-20 -> 0-127 */
1348 i = sd->contrast * 8000 / 1333;
1349 cit_write_reg(gspca_dev, i, 0x0425);
1350 break;
1351 }
1352 case CIT_MODEL2:
1353 case CIT_MODEL4:
1354 /* These models do not have this control. */
1355 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001356 case CIT_MODEL1:
1357 {
1358 /* Scale 0 - 20 to 15 - 0 */
1359 int i, new_contrast = (20 - sd->contrast) * 1000 / 1333;
1360 for (i = 0; i < cit_model1_ntries; i++) {
1361 cit_Packet_Format1(gspca_dev, 0x0014, new_contrast);
1362 cit_send_FF_04_02(gspca_dev);
1363 }
1364 break;
1365 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001366 case CIT_MODEL3:
1367 { /* Preset hardware values */
1368 static const struct {
1369 unsigned short cv1;
1370 unsigned short cv2;
1371 unsigned short cv3;
1372 } cv[7] = {
1373 { 0x05, 0x05, 0x0f }, /* Minimum */
1374 { 0x04, 0x04, 0x16 },
1375 { 0x02, 0x03, 0x16 },
1376 { 0x02, 0x08, 0x16 },
1377 { 0x01, 0x0c, 0x16 },
1378 { 0x01, 0x0e, 0x16 },
1379 { 0x01, 0x10, 0x16 } /* Maximum */
1380 };
1381 int i = sd->contrast / 3;
1382 cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1);
1383 cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2);
1384 cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3);
1385 break;
1386 }
1387 case CIT_IBM_NETCAM_PRO:
1388 cit_model3_Packet1(gspca_dev, 0x005b, sd->contrast + 1);
1389 break;
1390 }
1391 return 0;
1392}
1393
1394static int cit_set_hue(struct gspca_dev *gspca_dev)
1395{
1396 struct sd *sd = (struct sd *) gspca_dev;
1397
1398 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001399 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03001400 case CIT_MODEL1:
Hans de Goede659fefa2010-09-05 16:19:19 -03001401 case CIT_IBM_NETCAM_PRO:
1402 /* No hue control for these models */
Hans de Goede59f90a02010-06-09 11:39:50 -03001403 break;
1404 case CIT_MODEL2:
1405 cit_model2_Packet1(gspca_dev, 0x0024, sd->hue);
1406 /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */
1407 break;
1408 case CIT_MODEL3: {
1409 /* Model 3: Brightness range 'i' in [0x05..0x37] */
1410 /* TESTME according to the ibmcam driver this does not work */
1411 if (0) {
1412 /* Scale 0 - 127 to 0x05 - 0x37 */
1413 int i = 0x05 + sd->hue * 1000 / 2540;
1414 cit_model3_Packet1(gspca_dev, 0x007e, i);
1415 }
1416 break;
1417 }
1418 case CIT_MODEL4:
1419 /* HDG: taken from ibmcam, setting the color gains does not
1420 * really belong here.
1421 *
1422 * I am not sure r/g/b_gain variables exactly control gain
1423 * of those channels. Most likely they subtly change some
1424 * very internal image processing settings in the camera.
1425 * In any case, here is what they do, and feel free to tweak:
1426 *
1427 * r_gain: seriously affects red gain
1428 * g_gain: seriously affects green gain
1429 * b_gain: seriously affects blue gain
1430 * hue: changes average color from violet (0) to red (0xFF)
1431 */
1432 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
1433 cit_write_reg(gspca_dev, 0x001e, 0x012f);
1434 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1435 cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */
1436 cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */
1437 cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */
1438 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
1439 cit_write_reg(gspca_dev, sd->hue, 0x012d); /* Hue */
1440 cit_write_reg(gspca_dev, 0xf545, 0x0124);
Hans de Goede1f33de02010-09-05 16:05:22 -03001441 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001442 }
1443 return 0;
1444}
1445
1446static int cit_set_sharpness(struct gspca_dev *gspca_dev)
1447{
1448 struct sd *sd = (struct sd *) gspca_dev;
1449
1450 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001451 case CIT_MODEL0:
1452 case CIT_MODEL2:
1453 case CIT_MODEL4:
1454 case CIT_IBM_NETCAM_PRO:
1455 /* These models do not have this control */
1456 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001457 case CIT_MODEL1: {
1458 int i;
1459 const unsigned short sa[] = {
1460 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
1461
1462 for (i = 0; i < cit_model1_ntries; i++)
1463 cit_PacketFormat2(gspca_dev, 0x0013, sa[sd->sharpness]);
1464 break;
1465 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001466 case CIT_MODEL3:
1467 { /*
1468 * "Use a table of magic numbers.
1469 * This setting doesn't really change much.
1470 * But that's how Windows does it."
1471 */
1472 static const struct {
1473 unsigned short sv1;
1474 unsigned short sv2;
1475 unsigned short sv3;
1476 unsigned short sv4;
1477 } sv[7] = {
1478 { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */
1479 { 0x01, 0x04, 0x05, 0x14 },
1480 { 0x02, 0x04, 0x05, 0x14 },
1481 { 0x03, 0x04, 0x05, 0x14 },
1482 { 0x03, 0x05, 0x05, 0x14 },
1483 { 0x03, 0x06, 0x05, 0x14 },
1484 { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */
1485 };
1486 cit_model3_Packet1(gspca_dev, 0x0060, sv[sd->sharpness].sv1);
1487 cit_model3_Packet1(gspca_dev, 0x0061, sv[sd->sharpness].sv2);
1488 cit_model3_Packet1(gspca_dev, 0x0062, sv[sd->sharpness].sv3);
1489 cit_model3_Packet1(gspca_dev, 0x0063, sv[sd->sharpness].sv4);
1490 break;
1491 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001492 }
1493 return 0;
1494}
1495
Hans de Goede59f90a02010-06-09 11:39:50 -03001496/*
1497 * cit_set_lighting()
1498 *
1499 * Camera model 1:
1500 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
1501 *
1502 * Camera model 2:
1503 * We have 16 levels of lighting, 0 for bright light and up to 15 for
1504 * low light. But values above 5 or so are useless because camera is
1505 * not really capable to produce anything worth viewing at such light.
1506 * This setting may be altered only in certain camera state.
1507 *
1508 * Low lighting forces slower FPS.
1509 *
1510 * History:
1511 * 1/5/00 Created.
1512 * 2/20/00 Added support for Model 2 cameras.
1513 */
1514static void cit_set_lighting(struct gspca_dev *gspca_dev)
1515{
1516 struct sd *sd = (struct sd *) gspca_dev;
1517
1518 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001519 case CIT_MODEL0:
1520 case CIT_MODEL2:
1521 case CIT_MODEL3:
1522 case CIT_MODEL4:
1523 case CIT_IBM_NETCAM_PRO:
1524 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001525 case CIT_MODEL1: {
1526 int i;
1527 for (i = 0; i < cit_model1_ntries; i++)
1528 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1529 break;
1530 }
Hans de Goede659fefa2010-09-05 16:19:19 -03001531 }
1532}
1533
1534static void cit_set_hflip(struct gspca_dev *gspca_dev)
1535{
1536 struct sd *sd = (struct sd *) gspca_dev;
1537
1538 switch (sd->model) {
1539 case CIT_MODEL0:
1540 if (sd->hflip)
1541 cit_write_reg(gspca_dev, 0x0020, 0x0115);
1542 else
1543 cit_write_reg(gspca_dev, 0x0040, 0x0115);
1544 break;
1545 case CIT_MODEL1:
Hans de Goede59f90a02010-06-09 11:39:50 -03001546 case CIT_MODEL2:
1547 case CIT_MODEL3:
1548 case CIT_MODEL4:
1549 case CIT_IBM_NETCAM_PRO:
1550 break;
1551 }
1552}
1553
Hans de Goede1f33de02010-09-05 16:05:22 -03001554static int cit_restart_stream(struct gspca_dev *gspca_dev)
1555{
1556 struct sd *sd = (struct sd *) gspca_dev;
1557
1558 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001559 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03001560 case CIT_MODEL1:
Hans de Goede1f33de02010-09-05 16:05:22 -03001561 case CIT_MODEL3:
1562 case CIT_IBM_NETCAM_PRO:
1563 cit_write_reg(gspca_dev, 0x0001, 0x0114);
Hans de Goede59f90a02010-06-09 11:39:50 -03001564 /* Fall through */
1565 case CIT_MODEL2:
1566 case CIT_MODEL4:
Hans de Goede1f33de02010-09-05 16:05:22 -03001567 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1568 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
Hans de Goede59f90a02010-06-09 11:39:50 -03001569 /* This happens repeatedly while streaming with the ibm netcam
1570 pro and the ibmcam driver did it for model3 after changing
1571 settings, but it does not seem to have any effect. */
1572 /* cit_write_reg(gspca_dev, 0x0001, 0x0113); */
1573 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001574 }
1575
1576 sd->sof_read = 0;
1577
1578 return 0;
1579}
1580
Hans de Goede659fefa2010-09-05 16:19:19 -03001581static int cit_get_packet_size(struct gspca_dev *gspca_dev)
1582{
1583 struct usb_host_interface *alt;
1584 struct usb_interface *intf;
1585
1586 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
1587 alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
1588 if (!alt) {
1589 PDEBUG(D_ERR, "Couldn't get altsetting");
1590 return -EIO;
1591 }
1592
1593 return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
1594}
1595
1596static int cit_start_model0(struct gspca_dev *gspca_dev)
1597{
1598 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1599 int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */
1600 int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 };
1601 int packet_size;
1602
1603 packet_size = cit_get_packet_size(gspca_dev);
1604 if (packet_size < 0)
1605 return packet_size;
1606
1607 while (clock_div > 3 &&
1608 1000 * packet_size >
1609 gspca_dev->width * gspca_dev->height *
1610 fps[clock_div - 1] * 3 / 2)
1611 clock_div--;
1612
1613 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1614 cit_write_reg(gspca_dev, 0x0003, 0x0438);
1615 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1616 cit_write_reg(gspca_dev, 0x0041, 0x042c);
1617 cit_write_reg(gspca_dev, 0x0008, 0x0436);
1618 cit_write_reg(gspca_dev, 0x0024, 0x0403);
1619 cit_write_reg(gspca_dev, 0x002c, 0x0404);
1620 cit_write_reg(gspca_dev, 0x0002, 0x0426);
1621 cit_write_reg(gspca_dev, 0x0014, 0x0427);
1622
1623 switch (gspca_dev->width) {
1624 case 160: /* 160x120 */
1625 cit_write_reg(gspca_dev, 0x0004, 0x010b);
1626 cit_write_reg(gspca_dev, 0x0001, 0x010a);
1627 cit_write_reg(gspca_dev, 0x0010, 0x0102);
1628 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1629 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1630 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1631 break;
1632
1633 case 176: /* 176x144 */
1634 cit_write_reg(gspca_dev, 0x0006, 0x010b);
1635 cit_write_reg(gspca_dev, 0x0000, 0x010a);
1636 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1637 cit_write_reg(gspca_dev, 0x00b0, 0x0103);
1638 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1639 cit_write_reg(gspca_dev, 0x0090, 0x0105);
1640 break;
1641
1642 case 320: /* 320x240 */
1643 cit_write_reg(gspca_dev, 0x0008, 0x010b);
1644 cit_write_reg(gspca_dev, 0x0004, 0x010a);
1645 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1646 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1647 cit_write_reg(gspca_dev, 0x0010, 0x0104);
1648 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1649 break;
1650 }
1651
1652 cit_write_reg(gspca_dev, compression, 0x0109);
1653 cit_write_reg(gspca_dev, clock_div, 0x0111);
1654 PDEBUG(D_PROBE, "Using clockdiv: %d", clock_div);
1655
1656 return 0;
1657}
1658
Hans de Goede59f90a02010-06-09 11:39:50 -03001659static int cit_start_model1(struct gspca_dev *gspca_dev)
1660{
1661 struct sd *sd = (struct sd *) gspca_dev;
1662 int i, clock_div = 0;
1663
1664 cit_read_reg(gspca_dev, 0x0128);
1665 cit_read_reg(gspca_dev, 0x0100);
1666 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1667 cit_read_reg(gspca_dev, 0x0100);
1668 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1669 cit_read_reg(gspca_dev, 0x0100);
1670 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1671 cit_write_reg(gspca_dev, 0x01, 0x0108);
1672
1673 cit_write_reg(gspca_dev, 0x03, 0x0112);
1674 cit_read_reg(gspca_dev, 0x0115);
1675 cit_write_reg(gspca_dev, 0x06, 0x0115);
1676 cit_read_reg(gspca_dev, 0x0116);
1677 cit_write_reg(gspca_dev, 0x44, 0x0116);
1678 cit_read_reg(gspca_dev, 0x0116);
1679 cit_write_reg(gspca_dev, 0x40, 0x0116);
1680 cit_read_reg(gspca_dev, 0x0115);
1681 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1682 cit_write_reg(gspca_dev, 0x19, 0x012c);
1683
1684 cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
1685 cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
1686 cit_Packet_Format1(gspca_dev, 0x39, 0x09);
1687 cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
1688 cit_Packet_Format1(gspca_dev, 0x28, 0x22);
1689 cit_Packet_Format1(gspca_dev, 0x27, 0x00);
1690 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1691 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1692
1693 for (i = 0; i < cit_model1_ntries; i++)
1694 cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
1695
1696 for (i = 0; i < cit_model1_ntries; i++)
1697 cit_Packet_Format1(gspca_dev, 0x30, 0x14);
1698
1699 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1700 cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
1701 cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
1702 cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
1703 cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
1704 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1705 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1706
1707 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1708 cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
1709 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
1710 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
1711 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
1712 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
1713 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
1714 cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
1715 cit_PacketFormat2(gspca_dev, 0x11, 0xba);
1716 cit_PacketFormat2(gspca_dev, 0x12, 0x53);
1717 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1718 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1719
1720 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1721 cit_PacketFormat2(gspca_dev, 0x16, 0x00);
1722 cit_PacketFormat2(gspca_dev, 0x17, 0x28);
1723 cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
1724 cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
1725 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1726 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1727
1728 for (i = 0; i < cit_model1_ntries; i++)
1729 cit_Packet_Format1(gspca_dev, 0x00, 0x18);
1730 for (i = 0; i < cit_model1_ntries; i++)
1731 cit_Packet_Format1(gspca_dev, 0x13, 0x18);
1732 for (i = 0; i < cit_model1_ntries; i++)
1733 cit_Packet_Format1(gspca_dev, 0x14, 0x06);
1734
1735 /* TESTME These are handled through controls
1736 KEEP until someone can test leaving this out is ok */
1737 if (0) {
1738 /* This is default brightness */
1739 for (i = 0; i < cit_model1_ntries; i++)
1740 cit_Packet_Format1(gspca_dev, 0x31, 0x37);
1741 for (i = 0; i < cit_model1_ntries; i++)
1742 cit_Packet_Format1(gspca_dev, 0x32, 0x46);
1743 for (i = 0; i < cit_model1_ntries; i++)
1744 cit_Packet_Format1(gspca_dev, 0x33, 0x55);
1745 }
1746
1747 cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
1748 for (i = 0; i < cit_model1_ntries; i++)
1749 cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
1750 for (i = 0; i < cit_model1_ntries; i++)
1751 cit_Packet_Format1(gspca_dev, 0x29, 0x80);
1752 cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
1753 cit_Packet_Format1(gspca_dev, 0x30, 0x17);
1754 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1755 for (i = 0; i < cit_model1_ntries; i++)
1756 cit_Packet_Format1(gspca_dev, 0x34, 0x00);
1757
1758 cit_write_reg(gspca_dev, 0x00, 0x0101);
1759 cit_write_reg(gspca_dev, 0x00, 0x010a);
1760
1761 switch (gspca_dev->width) {
1762 case 128: /* 128x96 */
1763 cit_write_reg(gspca_dev, 0x80, 0x0103);
1764 cit_write_reg(gspca_dev, 0x60, 0x0105);
1765 cit_write_reg(gspca_dev, 0x0c, 0x010b);
1766 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1767 cit_write_reg(gspca_dev, 0x0b, 0x011d);
1768 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1769 cit_write_reg(gspca_dev, 0x00, 0x0129);
1770 clock_div = 3;
1771 break;
1772 case 176: /* 176x144 */
1773 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1774 cit_write_reg(gspca_dev, 0x8f, 0x0105);
1775 cit_write_reg(gspca_dev, 0x06, 0x010b);
1776 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1777 cit_write_reg(gspca_dev, 0x0d, 0x011d);
1778 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1779 cit_write_reg(gspca_dev, 0x03, 0x0129);
1780 clock_div = 3;
1781 break;
1782 case 352: /* 352x288 */
1783 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1784 cit_write_reg(gspca_dev, 0x90, 0x0105);
1785 cit_write_reg(gspca_dev, 0x02, 0x010b);
1786 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1787 cit_write_reg(gspca_dev, 0x05, 0x011d);
1788 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1789 cit_write_reg(gspca_dev, 0x00, 0x0129);
1790 clock_div = 5;
1791 break;
1792 }
1793
1794 cit_write_reg(gspca_dev, 0xff, 0x012b);
1795
1796 /* TESTME These are handled through controls
1797 KEEP until someone can test leaving this out is ok */
1798 if (0) {
1799 /* This is another brightness - don't know why */
1800 for (i = 0; i < cit_model1_ntries; i++)
1801 cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
1802 for (i = 0; i < cit_model1_ntries; i++)
1803 cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
1804 for (i = 0; i < cit_model1_ntries; i++)
1805 cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
1806
1807 /* Default contrast */
1808 for (i = 0; i < cit_model1_ntries; i++)
1809 cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
1810
1811 /* Default sharpness */
1812 for (i = 0; i < cit_model1_ntries2; i++)
1813 cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
1814
1815 /* Default lighting conditions */
1816 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1817 }
1818
1819 /* Assorted init */
1820 switch (gspca_dev->width) {
1821 case 128: /* 128x96 */
1822 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1823 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1824 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1825 cit_write_reg(gspca_dev, 0x36, 0x0102);
1826 cit_write_reg(gspca_dev, 0x1a, 0x0104);
1827 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1828 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1829 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1830 break;
1831 case 176: /* 176x144 */
1832 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1833 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1834 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1835 cit_write_reg(gspca_dev, 0x04, 0x0102);
1836 cit_write_reg(gspca_dev, 0x02, 0x0104);
1837 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1838 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1839 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1840 break;
1841 case 352: /* 352x288 */
1842 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1843 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1844 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1845 cit_write_reg(gspca_dev, 0x08, 0x0102);
1846 cit_write_reg(gspca_dev, 0x01, 0x0104);
1847 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1848 cit_write_reg(gspca_dev, 0x2f, 0x011c);
1849 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1850 break;
1851 }
1852
1853 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1854 cit_write_reg(gspca_dev, clock_div, 0x0111);
1855
Hans de Goede59f90a02010-06-09 11:39:50 -03001856 return 0;
1857}
1858
1859static int cit_start_model2(struct gspca_dev *gspca_dev)
1860{
1861 struct sd *sd = (struct sd *) gspca_dev;
1862 int clock_div = 0;
1863
1864 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1865 cit_read_reg(gspca_dev, 0x0116);
1866 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1867 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1868 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
1869 cit_write_reg(gspca_dev, 0x0008, 0x012b);
1870 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1871 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1872 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1873 switch (gspca_dev->width) {
1874 case 176: /* 176x144 */
1875 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1876 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1877 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1878 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
1879 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
1880 /* TESTME HDG: this does not seem right
1881 (it is 2 for all other resolutions) */
1882 sd->sof_len = 10;
1883 break;
1884 case 320: /* 320x240 */
1885 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
1886 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1887 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1888 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1889 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1890 sd->sof_len = 2;
1891 break;
1892 /* case VIDEOSIZE_352x240: */
1893 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1894 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1895 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1896 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1897 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1898 sd->sof_len = 2;
1899 break;
1900 case 352: /* 352x288 */
1901 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1902 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1903 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1904 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1905 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1906 sd->sof_len = 2;
1907 break;
1908 }
1909
1910 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1911
1912 switch (gspca_dev->width) {
1913 case 176: /* 176x144 */
1914 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1915 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
1916 break;
1917 case 320: /* 320x240 */
1918 case 352: /* 352x288 */
1919 cit_write_reg(gspca_dev, 0x0040, 0x0111);
1920 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
1921 break;
1922 }
1923 cit_write_reg(gspca_dev, 0x009b, 0x010f);
1924 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
1925
1926 /*
1927 * Hardware settings, may affect CMOS sensor; not user controls!
1928 * -------------------------------------------------------------
1929 * 0x0004: no effect
1930 * 0x0006: hardware effect
1931 * 0x0008: no effect
1932 * 0x000a: stops video stream, probably important h/w setting
1933 * 0x000c: changes color in hardware manner (not user setting)
1934 * 0x0012: changes number of colors (does not affect speed)
1935 * 0x002a: no effect
1936 * 0x002c: hardware setting (related to scan lines)
1937 * 0x002e: stops video stream, probably important h/w setting
1938 */
1939 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
1940 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
1941 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
1942 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
1943 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
1944 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
1945 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
1946 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
1947 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
1948
1949 /*
1950 * Function 0x0030 pops up all over the place. Apparently
1951 * it is a hardware control register, with every bit assigned to
1952 * do something.
1953 */
1954 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
1955
1956 /*
1957 * Magic control of CMOS sensor. Only lower values like
1958 * 0-3 work, and picture shifts left or right. Don't change.
1959 */
1960 switch (gspca_dev->width) {
1961 case 176: /* 176x144 */
1962 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1963 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1964 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1965 clock_div = 6;
1966 break;
1967 case 320: /* 320x240 */
1968 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
1969 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
1970 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1971 clock_div = 8;
1972 break;
1973 /* case VIDEOSIZE_352x240: */
1974 /* This mode doesn't work as Windows programs it; changed to work */
1975 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1976 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1977 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1978 clock_div = 10;
1979 break;
1980 case 352: /* 352x288 */
1981 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
1982 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1983 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1984 clock_div = 16;
1985 break;
1986 }
1987
1988 /* TESTME These are handled through controls
1989 KEEP until someone can test leaving this out is ok */
1990 if (0)
1991 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
1992
1993 /*
1994 * We have our own frame rate setting varying from 0 (slowest) to 6
1995 * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
1996 # where 0 is also the slowest setting. However for all practical
1997 # reasons high settings make no sense because USB is not fast enough
1998 # to support high FPS. Be aware that the picture datastream will be
1999 # severely disrupted if you ask for frame rate faster than allowed
2000 # for the video size - see below:
2001 *
2002 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
2003 * -----------------------------------------------------------------
2004 * 176x144: [6..31]
2005 * 320x240: [8..31]
2006 * 352x240: [10..31]
2007 * 352x288: [16..31] I have to raise lower threshold for stability...
2008 *
2009 * As usual, slower FPS provides better sensitivity.
2010 */
2011 cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
2012
2013 /*
2014 * This setting does not visibly affect pictures; left it here
2015 * because it was present in Windows USB data stream. This function
2016 * does not allow arbitrary values and apparently is a bit mask, to
2017 * be activated only at appropriate time. Don't change it randomly!
2018 */
2019 switch (gspca_dev->width) {
2020 case 176: /* 176x144 */
2021 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
2022 break;
2023 case 320: /* 320x240 */
2024 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
2025 break;
2026 /* case VIDEOSIZE_352x240: */
2027 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
2028 break;
2029 case 352: /* 352x288 */
2030 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
2031 break;
2032 }
2033
2034 /* FIXME this cannot be changed while streaming, so we
2035 should report a grabbed flag for this control. */
2036 cit_model2_Packet1(gspca_dev, 0x0028, sd->lighting);
2037 /* color balance rg2 */
2038 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
2039 /* saturation */
2040 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
2041 /* color balance yb */
2042 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
2043
2044 /* Hardware control command */
2045 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2046
2047 return 0;
2048}
2049
Hans de Goede1f33de02010-09-05 16:05:22 -03002050static int cit_start_model3(struct gspca_dev *gspca_dev)
2051{
2052 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2053 int i, clock_div = 0;
2054
2055 /* HDG not in ibmcam driver, added to see if it helps with
2056 auto-detecting between model3 and ibm netcamera pro */
2057 cit_read_reg(gspca_dev, 0x128);
2058
2059 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2060 cit_read_reg(gspca_dev, 0x0116);
2061 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2062 cit_write_reg(gspca_dev, 0x0002, 0x0112);
2063 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2064 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2065 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2066 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2067 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2068 cit_write_reg(gspca_dev, 0x0002, 0x0115);
2069 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2070 cit_read_reg(gspca_dev, 0x0115);
2071 cit_write_reg(gspca_dev, 0x000b, 0x0115);
2072
Hans de Goede59f90a02010-06-09 11:39:50 -03002073 /* TESTME HDG not in ibmcam driver, added to see if it helps with
Hans de Goede1f33de02010-09-05 16:05:22 -03002074 auto-detecting between model3 and ibm netcamera pro */
2075 if (0) {
2076 cit_write_reg(gspca_dev, 0x0078, 0x012d);
2077 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2078 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2079 cit_write_reg(gspca_dev, 0x0079, 0x012d);
2080 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
2081 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
2082 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2083 cit_read_reg(gspca_dev, 0x0126);
2084 }
2085
2086 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
2087 cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6);
2088 cit_model3_Packet1(gspca_dev, 0x000c, 0x0002);
2089 cit_model3_Packet1(gspca_dev, 0x000d, 0x0020);
2090 cit_model3_Packet1(gspca_dev, 0x000e, 0x0033);
2091 cit_model3_Packet1(gspca_dev, 0x000f, 0x0007);
2092 cit_model3_Packet1(gspca_dev, 0x0010, 0x0000);
2093 cit_model3_Packet1(gspca_dev, 0x0011, 0x0070);
2094 cit_model3_Packet1(gspca_dev, 0x0012, 0x0030);
2095 cit_model3_Packet1(gspca_dev, 0x0013, 0x0000);
2096 cit_model3_Packet1(gspca_dev, 0x0014, 0x0001);
2097 cit_model3_Packet1(gspca_dev, 0x0015, 0x0001);
2098 cit_model3_Packet1(gspca_dev, 0x0016, 0x0001);
2099 cit_model3_Packet1(gspca_dev, 0x0017, 0x0001);
2100 cit_model3_Packet1(gspca_dev, 0x0018, 0x0000);
2101 cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3);
2102 cit_model3_Packet1(gspca_dev, 0x0020, 0x0000);
2103 cit_model3_Packet1(gspca_dev, 0x0028, 0x0010);
2104 cit_model3_Packet1(gspca_dev, 0x0029, 0x0054);
2105 cit_model3_Packet1(gspca_dev, 0x002a, 0x0013);
2106 cit_model3_Packet1(gspca_dev, 0x002b, 0x0007);
2107 cit_model3_Packet1(gspca_dev, 0x002d, 0x0028);
2108 cit_model3_Packet1(gspca_dev, 0x002e, 0x0000);
2109 cit_model3_Packet1(gspca_dev, 0x0031, 0x0000);
2110 cit_model3_Packet1(gspca_dev, 0x0032, 0x0000);
2111 cit_model3_Packet1(gspca_dev, 0x0033, 0x0000);
2112 cit_model3_Packet1(gspca_dev, 0x0034, 0x0000);
2113 cit_model3_Packet1(gspca_dev, 0x0035, 0x0038);
2114 cit_model3_Packet1(gspca_dev, 0x003a, 0x0001);
2115 cit_model3_Packet1(gspca_dev, 0x003c, 0x001e);
2116 cit_model3_Packet1(gspca_dev, 0x003f, 0x000a);
2117 cit_model3_Packet1(gspca_dev, 0x0041, 0x0000);
2118 cit_model3_Packet1(gspca_dev, 0x0046, 0x003f);
2119 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
2120 cit_model3_Packet1(gspca_dev, 0x0050, 0x0005);
2121 cit_model3_Packet1(gspca_dev, 0x0052, 0x001a);
2122 cit_model3_Packet1(gspca_dev, 0x0053, 0x0003);
2123 cit_model3_Packet1(gspca_dev, 0x005a, 0x006b);
2124 cit_model3_Packet1(gspca_dev, 0x005d, 0x001e);
2125 cit_model3_Packet1(gspca_dev, 0x005e, 0x0030);
2126 cit_model3_Packet1(gspca_dev, 0x005f, 0x0041);
2127 cit_model3_Packet1(gspca_dev, 0x0064, 0x0008);
2128 cit_model3_Packet1(gspca_dev, 0x0065, 0x0015);
2129 cit_model3_Packet1(gspca_dev, 0x0068, 0x000f);
2130 cit_model3_Packet1(gspca_dev, 0x0079, 0x0000);
2131 cit_model3_Packet1(gspca_dev, 0x007a, 0x0000);
2132 cit_model3_Packet1(gspca_dev, 0x007c, 0x003f);
2133 cit_model3_Packet1(gspca_dev, 0x0082, 0x000f);
2134 cit_model3_Packet1(gspca_dev, 0x0085, 0x0000);
2135 cit_model3_Packet1(gspca_dev, 0x0099, 0x0000);
2136 cit_model3_Packet1(gspca_dev, 0x009b, 0x0023);
2137 cit_model3_Packet1(gspca_dev, 0x009c, 0x0022);
2138 cit_model3_Packet1(gspca_dev, 0x009d, 0x0096);
2139 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
2140 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
2141
2142 switch (gspca_dev->width) {
2143 case 160:
2144 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2145 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2146 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2147 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2148 cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */
2149 cit_write_reg(gspca_dev, 0x00a9, 0x0119);
2150 cit_write_reg(gspca_dev, 0x0016, 0x011b);
2151 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2152 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2153 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2154 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2155 cit_write_reg(gspca_dev, 0x0018, 0x0102);
2156 cit_write_reg(gspca_dev, 0x0004, 0x0104);
2157 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2158 cit_write_reg(gspca_dev, 0x0028, 0x011c);
2159 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2160 cit_write_reg(gspca_dev, 0x0000, 0x0118);
2161 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2162 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2163 cit_write_reg(gspca_dev, compression, 0x0109);
2164 clock_div = 3;
2165 break;
2166 case 320:
2167 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2168 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2169 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2170 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2171 cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */
2172 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */
2173 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2174 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2175 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2176 /* 4 commands from 160x120 skipped */
2177 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2178 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2179 cit_write_reg(gspca_dev, compression, 0x0109);
2180 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2181 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2182 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2183 cit_write_reg(gspca_dev, 0x0010, 0x0104);
2184 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2185 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2186 cit_write_reg(gspca_dev, 0x001c, 0x0118);
2187 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2188 clock_div = 5;
2189 break;
2190 case 640:
2191 cit_write_reg(gspca_dev, 0x00f0, 0x0105);
2192 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2193 cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */
2194 cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
2195 cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
2196 cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */
2197 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2198 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2199 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2200 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2201 cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */
2202 cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
2203 cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
2204 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2205 cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
2206 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2207 cit_write_reg(gspca_dev, compression, 0x0109);
2208 cit_write_reg(gspca_dev, 0x0040, 0x0101);
2209 cit_write_reg(gspca_dev, 0x0040, 0x0103);
2210 cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
2211 clock_div = 7;
2212 break;
2213 }
2214
2215 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */
2216 cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */
2217 cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */
2218 cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */
2219 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */
2220 cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */
2221 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2222 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2223 cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */
2224 cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */
2225 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */
2226 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2227 cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */
2228 cit_model3_Packet1(gspca_dev, 0x002f, 0x002a);
2229 cit_model3_Packet1(gspca_dev, 0x0030, 0x0029);
2230 cit_model3_Packet1(gspca_dev, 0x0037, 0x0002);
2231 cit_model3_Packet1(gspca_dev, 0x0038, 0x0059);
2232 cit_model3_Packet1(gspca_dev, 0x003d, 0x002e);
2233 cit_model3_Packet1(gspca_dev, 0x003e, 0x0028);
2234 cit_model3_Packet1(gspca_dev, 0x0078, 0x0005);
2235 cit_model3_Packet1(gspca_dev, 0x007b, 0x0011);
2236 cit_model3_Packet1(gspca_dev, 0x007d, 0x004b);
2237 cit_model3_Packet1(gspca_dev, 0x007f, 0x0022);
2238 cit_model3_Packet1(gspca_dev, 0x0080, 0x000c);
2239 cit_model3_Packet1(gspca_dev, 0x0081, 0x000b);
2240 cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd);
2241 cit_model3_Packet1(gspca_dev, 0x0086, 0x000b);
2242 cit_model3_Packet1(gspca_dev, 0x0087, 0x000b);
2243 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e);
2244 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2245 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2246 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2247
2248 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
2249
2250 switch (gspca_dev->width) {
2251 case 160:
2252 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2253 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2254 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2255 cit_model3_Packet1(gspca_dev, 0x0040, 0x000a);
2256 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2257 break;
2258 case 320:
2259 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2260 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2261 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2262 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2263 cit_model3_Packet1(gspca_dev, 0x0051, 0x000b);
2264 break;
2265 case 640:
2266 cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */
2267 cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */
2268 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2269 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2270 break;
2271 }
2272
2273/* if (sd->input_index) { */
2274 if (rca_input) {
2275 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2276 if (rca_initdata[i][0])
2277 cit_read_reg(gspca_dev, rca_initdata[i][2]);
2278 else
2279 cit_write_reg(gspca_dev, rca_initdata[i][1],
2280 rca_initdata[i][2]);
2281 }
2282 }
2283
Hans de Goede59f90a02010-06-09 11:39:50 -03002284 return 0;
2285}
2286
2287static int cit_start_model4(struct gspca_dev *gspca_dev)
2288{
2289 struct sd *sd = (struct sd *) gspca_dev;
2290
2291 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2292 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2293 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
2294 cit_write_reg(gspca_dev, 0x0080, 0x012b);
2295 cit_write_reg(gspca_dev, 0x0000, 0x0108);
2296 cit_write_reg(gspca_dev, 0x0001, 0x0133);
2297 cit_write_reg(gspca_dev, 0x009b, 0x010f);
2298 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
2299 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
2300 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
2301
2302 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2303 cit_write_reg(gspca_dev, 0x0004, 0x012f);
2304 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2305 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2306 cit_write_reg(gspca_dev, 0x00fb, 0x012e);
2307 cit_write_reg(gspca_dev, 0x0000, 0x0130);
2308 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2309 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2310 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2311 cit_write_reg(gspca_dev, 0x000c, 0x0127);
2312 cit_write_reg(gspca_dev, 0x0009, 0x012e);
2313 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2314
2315 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2316 cit_write_reg(gspca_dev, 0x0012, 0x012f);
2317 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2318 cit_write_reg(gspca_dev, 0x0008, 0x0127);
2319 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2320 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2321 cit_write_reg(gspca_dev, 0x002a, 0x012d);
2322 cit_write_reg(gspca_dev, 0x0000, 0x012f);
2323 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2324 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2325 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2326
2327 switch (gspca_dev->width) {
2328 case 128: /* 128x96 */
2329 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2330 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2331 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2332 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2333 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2334 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2335 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2336 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2337 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2338 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2339 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2340 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2341 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2342 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2343 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2344 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2345 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2346 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2347 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2348 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2349 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2350 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2351 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2352 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2353 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2354 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2355 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2356 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2357 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2358 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2359 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2360 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2361 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2362 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2363 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2364 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2365 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2366 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2367 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2368 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2369 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2370 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2371 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2372 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2373 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2374 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2375 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2376 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2377 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2378 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2379 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2380 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2381 sd->sof_len = 2;
2382 break;
2383 case 160: /* 160x120 */
2384 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2385 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2386 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2387 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2388 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2389 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2390 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2391 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2392 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2393 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2394 cit_write_reg(gspca_dev, 0x000b, 0x0127);
2395 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2396 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2397 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2398 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2399 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2400 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2401 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2402 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2403 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2404 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2405 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2406 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2407 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2408 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2409 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2410 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2411 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2412 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2413 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2414 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2415 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2416 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2417 cit_write_reg(gspca_dev, 0x0025, 0x0127);
2418 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2419 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2420 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2421 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2422 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2423 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2424 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2425 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2426 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2427 cit_write_reg(gspca_dev, 0x0048, 0x0127);
2428 cit_write_reg(gspca_dev, 0x0035, 0x012e);
2429 cit_write_reg(gspca_dev, 0x00d0, 0x0130);
2430 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2431 cit_write_reg(gspca_dev, 0x0048, 0x012d);
2432 cit_write_reg(gspca_dev, 0x0090, 0x012f);
2433 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2434 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2435 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2436 sd->sof_len = 2;
2437 break;
2438 case 176: /* 176x144 */
2439 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2440 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2441 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2442 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2443 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2444 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2445 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2446 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2447 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2448 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2449 cit_write_reg(gspca_dev, 0x0007, 0x0127);
2450 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2451 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2452 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2453 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2454 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2455 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2456 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2457 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2458 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2459 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2460 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2461 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2462 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2463 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2464 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2465 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2466 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2467 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2468 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2469 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2470 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2471 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2472 cit_write_reg(gspca_dev, 0x0028, 0x0127);
2473 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2474 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2475 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2476 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2477 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2478 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2479 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2480 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2481 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2482 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2483 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2484 cit_write_reg(gspca_dev, 0x002a, 0x0130);
2485 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2486 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2487 cit_write_reg(gspca_dev, 0x006d, 0x012f);
2488 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2489 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2490 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2491 /* TESTME HDG: this does not seem right
2492 (it is 2 for all other resolutions) */
2493 sd->sof_len = 10;
2494 break;
2495 case 320: /* 320x240 */
2496 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2497 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2498 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2499 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2500 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2501 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2502 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2503 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2504 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2505 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2506 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2507 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2508 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2509 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2510 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2511 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2512 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2513 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2514 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2515 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2516 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2517 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2518 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2519 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2520 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2521 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2522 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2523 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2524 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2525 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2526 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2527 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2528 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2529 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2530 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2531 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2532 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2533 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2534 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2535 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2536 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2537 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2538 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2539 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2540 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2541 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2542 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2543 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2544 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2545 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2546 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2547 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2548 sd->sof_len = 2;
2549 break;
2550 case 352: /* 352x288 */
2551 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2552 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2553 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2554 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2555 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2556 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2557 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2558 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2559 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2560 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2561 cit_write_reg(gspca_dev, 0x0006, 0x0127);
2562 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2563 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2564 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2565 cit_write_reg(gspca_dev, 0x0002, 0x012f);
2566 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2567 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2568 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2569 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2570 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2571 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2572 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2573 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2574 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2575 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2576 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2577 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2578 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2579 cit_write_reg(gspca_dev, 0x00cf, 0x012e);
2580 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2581 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2582 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2583 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2584 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2585 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2586 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2587 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2588 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2589 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2590 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2591 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2592 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2593 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2594 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2595 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2596 cit_write_reg(gspca_dev, 0x0025, 0x0130);
2597 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2598 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2599 cit_write_reg(gspca_dev, 0x0048, 0x012f);
2600 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2601 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2602 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2603 sd->sof_len = 2;
2604 break;
2605 }
2606
2607 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
2608
Hans de Goede1f33de02010-09-05 16:05:22 -03002609 return 0;
2610}
2611
2612static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2613{
2614 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2615 int i, clock_div = 0;
2616
2617 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2618 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2619 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2620 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2621 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2622 /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */
2623 cit_write_reg(gspca_dev, 0x0000, 0x0133);
2624 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2625 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2626 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2627 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2628 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2629 /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */
2630
2631 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
2632
2633 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2634 cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */
2635 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2636 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2637 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2638 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2639 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2640 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2641 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2642
2643 switch (gspca_dev->width) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002644 case 160: /* 160x120 */
Hans de Goede1f33de02010-09-05 16:05:22 -03002645 cit_write_reg(gspca_dev, 0x0024, 0x010b);
2646 cit_write_reg(gspca_dev, 0x0089, 0x0119);
2647 cit_write_reg(gspca_dev, 0x000a, 0x011b);
2648 cit_write_reg(gspca_dev, 0x0003, 0x011e);
2649 cit_write_reg(gspca_dev, 0x0007, 0x0104);
2650 cit_write_reg(gspca_dev, 0x0009, 0x011a);
2651 cit_write_reg(gspca_dev, 0x008b, 0x011c);
2652 cit_write_reg(gspca_dev, 0x0008, 0x0118);
2653 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2654 clock_div = 3;
2655 break;
Hans de Goede659fefa2010-09-05 16:19:19 -03002656 case 320: /* 320x240 */
Hans de Goede1f33de02010-09-05 16:05:22 -03002657 cit_write_reg(gspca_dev, 0x0028, 0x010b);
2658 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2659 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2660 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2661 cit_write_reg(gspca_dev, 0x000e, 0x0104);
2662 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2663 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2664 cit_write_reg(gspca_dev, 0x000c, 0x0118);
2665 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2666 clock_div = 5;
2667 break;
2668 }
2669
2670 cit_model3_Packet1(gspca_dev, 0x0019, 0x0031);
2671 cit_model3_Packet1(gspca_dev, 0x001a, 0x0003);
2672 cit_model3_Packet1(gspca_dev, 0x001b, 0x0038);
2673 cit_model3_Packet1(gspca_dev, 0x001c, 0x0000);
2674 cit_model3_Packet1(gspca_dev, 0x0024, 0x0001);
2675 cit_model3_Packet1(gspca_dev, 0x0027, 0x0001);
2676 cit_model3_Packet1(gspca_dev, 0x002a, 0x0004);
2677 cit_model3_Packet1(gspca_dev, 0x0035, 0x000b);
2678 cit_model3_Packet1(gspca_dev, 0x003f, 0x0001);
2679 cit_model3_Packet1(gspca_dev, 0x0044, 0x0000);
2680 cit_model3_Packet1(gspca_dev, 0x0054, 0x0000);
2681 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000);
2682 cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001);
2683 cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001);
2684 cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000);
2685 cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0);
2686
2687 cit_write_reg(gspca_dev, compression, 0x0109);
2688 cit_write_reg(gspca_dev, clock_div, 0x0111);
2689
2690/* if (sd->input_index) { */
2691 if (rca_input) {
2692 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2693 if (rca_initdata[i][0])
2694 cit_read_reg(gspca_dev, rca_initdata[i][2]);
2695 else
2696 cit_write_reg(gspca_dev, rca_initdata[i][1],
2697 rca_initdata[i][2]);
2698 }
2699 }
2700
2701 return 0;
2702}
2703
2704/* -- start the camera -- */
2705static int sd_start(struct gspca_dev *gspca_dev)
2706{
2707 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1f33de02010-09-05 16:05:22 -03002708 int packet_size;
2709
Hans de Goede659fefa2010-09-05 16:19:19 -03002710 packet_size = cit_get_packet_size(gspca_dev);
2711 if (packet_size < 0)
2712 return packet_size;
2713
Hans de Goede1f33de02010-09-05 16:05:22 -03002714 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002715 case CIT_MODEL0:
2716 cit_start_model0(gspca_dev);
2717 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002718 case CIT_MODEL1:
2719 cit_start_model1(gspca_dev);
2720 break;
2721 case CIT_MODEL2:
2722 cit_start_model2(gspca_dev);
2723 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002724 case CIT_MODEL3:
2725 cit_start_model3(gspca_dev);
2726 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002727 case CIT_MODEL4:
2728 cit_start_model4(gspca_dev);
2729 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002730 case CIT_IBM_NETCAM_PRO:
2731 cit_start_ibm_netcam_pro(gspca_dev);
2732 break;
2733 }
2734
2735 cit_set_brightness(gspca_dev);
2736 cit_set_contrast(gspca_dev);
2737 cit_set_hue(gspca_dev);
2738 cit_set_sharpness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03002739 cit_set_lighting(gspca_dev);
Hans de Goede659fefa2010-09-05 16:19:19 -03002740 cit_set_hflip(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03002741
Hans de Goede659fefa2010-09-05 16:19:19 -03002742 /* Program max isoc packet size */
Hans de Goede1f33de02010-09-05 16:05:22 -03002743 cit_write_reg(gspca_dev, packet_size >> 8, 0x0106);
2744 cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107);
2745
2746 cit_restart_stream(gspca_dev);
2747
2748 return 0;
2749}
2750
2751static void sd_stopN(struct gspca_dev *gspca_dev)
2752{
Hans de Goede59f90a02010-06-09 11:39:50 -03002753 cit_write_reg(gspca_dev, 0x0000, 0x010c);
Hans de Goede1f33de02010-09-05 16:05:22 -03002754}
2755
2756static void sd_stop0(struct gspca_dev *gspca_dev)
2757{
2758 struct sd *sd = (struct sd *) gspca_dev;
2759
2760 /* We cannot use gspca_dev->present here as that is not set when
2761 sd_init gets called and we get called from sd_init */
2762 if (!gspca_dev->dev)
2763 return;
2764
2765 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002766 case CIT_MODEL0:
2767 /* HDG windows does this, but it causes the cams autogain to
2768 restart from a gain of 0, which does not look good when
2769 changing resolutions. */
2770 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2771 cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */
2772 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002773 case CIT_MODEL1:
2774 cit_send_FF_04_02(gspca_dev);
2775 cit_read_reg(gspca_dev, 0x0100);
2776 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2777 break;
2778 case CIT_MODEL2:
2779 case CIT_MODEL4:
2780 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2781
2782 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
2783 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2784 cit_write_reg(gspca_dev, 0x00a0, 0x0111);
2785
2786 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
2787
2788 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2789 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2790 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002791 case CIT_MODEL3:
2792 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2793 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
2794 cit_read_reg(gspca_dev, 0x0116);
2795 cit_write_reg(gspca_dev, 0x0064, 0x0116);
2796 cit_read_reg(gspca_dev, 0x0115);
2797 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2798 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2799 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2800 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2801 cit_write_reg(gspca_dev, 0x0080, 0x0100);
2802 break;
2803 case CIT_IBM_NETCAM_PRO:
2804 cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff);
2805 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2806 cit_write_reg(gspca_dev, 0x0000, 0x0116);
2807 /* HDG windows does this, but I cannot get the camera
2808 to restart with this without redoing the entire init
2809 sequence which makes switching modes really slow */
2810 /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */
2811 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2812 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2813 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2814 cit_write_reg(gspca_dev, 0x0000, 0x0111);
2815 /* HDG windows does this, but I get a green picture when
2816 restarting the stream after this */
2817 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2818 cit_write_reg(gspca_dev, 0x00c0, 0x0100);
2819 break;
2820 }
2821}
2822
2823static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2824{
2825 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede659fefa2010-09-05 16:19:19 -03002826 u8 byte3 = 0, byte4 = 0;
Hans de Goede1f33de02010-09-05 16:05:22 -03002827 int i;
2828
2829 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002830 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03002831 case CIT_MODEL1:
Hans de Goede1f33de02010-09-05 16:05:22 -03002832 case CIT_MODEL3:
2833 case CIT_IBM_NETCAM_PRO:
Hans de Goede659fefa2010-09-05 16:19:19 -03002834 switch (gspca_dev->width) {
2835 case 160: /* 160x120 */
Hans de Goede59f90a02010-06-09 11:39:50 -03002836 byte3 = 0x02;
Hans de Goede659fefa2010-09-05 16:19:19 -03002837 byte4 = 0x0a;
2838 break;
2839 case 176: /* 176x144 */
2840 byte3 = 0x02;
2841 byte4 = 0x0e;
2842 break;
2843 case 320: /* 320x240 */
2844 byte3 = 0x02;
2845 byte4 = 0x08;
2846 break;
2847 case 352: /* 352x288 */
2848 byte3 = 0x02;
2849 byte4 = 0x00;
2850 break;
2851 case 640:
2852 byte3 = 0x03;
2853 byte4 = 0x08;
2854 break;
2855 }
2856
2857 /* These have a different byte3 */
2858 if (sd->model <= CIT_MODEL1)
2859 byte3 = 0x00;
Hans de Goede59f90a02010-06-09 11:39:50 -03002860
Hans de Goede1f33de02010-09-05 16:05:22 -03002861 for (i = 0; i < len; i++) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002862 /* For this model the SOF always starts at offset 0
2863 so no need to search the entire frame */
2864 if (sd->model == CIT_MODEL0 && sd->sof_read != i)
2865 break;
2866
Hans de Goede1f33de02010-09-05 16:05:22 -03002867 switch (sd->sof_read) {
2868 case 0:
2869 if (data[i] == 0x00)
2870 sd->sof_read++;
2871 break;
2872 case 1:
2873 if (data[i] == 0xff)
2874 sd->sof_read++;
Hans de Goede659fefa2010-09-05 16:19:19 -03002875 else if (data[i] == 0x00)
2876 sd->sof_read = 1;
Hans de Goede1f33de02010-09-05 16:05:22 -03002877 else
2878 sd->sof_read = 0;
2879 break;
2880 case 2:
Hans de Goede659fefa2010-09-05 16:19:19 -03002881 if (data[i] == byte3)
2882 sd->sof_read++;
2883 else if (data[i] == 0x00)
2884 sd->sof_read = 1;
2885 else
2886 sd->sof_read = 0;
2887 break;
2888 case 3:
2889 if (data[i] == byte4) {
2890 sd->sof_read = 0;
2891 return data + i + (sd->sof_len - 3);
Hans de Goede59f90a02010-06-09 11:39:50 -03002892 }
Hans de Goede659fefa2010-09-05 16:19:19 -03002893 if (byte3 == 0x00 && data[i] == 0xff)
2894 sd->sof_read = 2;
2895 else if (data[i] == 0x00)
2896 sd->sof_read = 1;
2897 else
2898 sd->sof_read = 0;
Hans de Goede59f90a02010-06-09 11:39:50 -03002899 break;
2900 }
2901 }
2902 break;
2903 case CIT_MODEL2:
2904 case CIT_MODEL4:
2905 /* TESTME we need to find a longer sof signature to avoid
2906 false positives */
2907 for (i = 0; i < len; i++) {
2908 switch (sd->sof_read) {
2909 case 0:
2910 if (data[i] == 0x00)
2911 sd->sof_read++;
2912 break;
2913 case 1:
2914 sd->sof_read = 0;
2915 if (data[i] == 0xff) {
2916 if (i >= 4)
2917 PDEBUG(D_FRAM,
Hans de Goede659fefa2010-09-05 16:19:19 -03002918 "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n",
2919 i - 1,
Hans de Goede59f90a02010-06-09 11:39:50 -03002920 data[i - 4],
2921 data[i - 3],
2922 data[i],
Hans de Goede659fefa2010-09-05 16:19:19 -03002923 data[i + 1],
2924 data[i + 2]);
2925 else
2926 PDEBUG(D_FRAM,
2927 "header found at offset: %d: 00 %02x %02x %02x\n",
2928 i - 1,
2929 data[i],
2930 data[i + 1],
2931 data[i + 2]);
2932 return data + i + (sd->sof_len - 1);
Hans de Goede1f33de02010-09-05 16:05:22 -03002933 }
2934 break;
2935 }
2936 }
2937 break;
2938 }
2939 return NULL;
2940}
2941
2942static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2943 u8 *data, int len)
2944{
Hans de Goede59f90a02010-06-09 11:39:50 -03002945 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1f33de02010-09-05 16:05:22 -03002946 unsigned char *sof;
2947
2948 sof = cit_find_sof(gspca_dev, data, len);
2949 if (sof) {
2950 int n;
2951
2952 /* finish decoding current frame */
2953 n = sof - data;
Hans de Goede59f90a02010-06-09 11:39:50 -03002954 if (n > sd->sof_len)
2955 n -= sd->sof_len;
Hans de Goede1f33de02010-09-05 16:05:22 -03002956 else
2957 n = 0;
2958 gspca_frame_add(gspca_dev, LAST_PACKET,
2959 data, n);
2960 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
2961 len -= sof - data;
2962 data = sof;
2963 }
2964
2965 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
2966}
2967
2968static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2969{
2970 struct sd *sd = (struct sd *) gspca_dev;
2971
2972 sd->brightness = val;
2973 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03002974 if (sd->stop_on_control_change)
2975 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03002976 cit_set_brightness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03002977 if (sd->stop_on_control_change)
2978 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03002979 }
2980
2981 return 0;
2982}
2983
2984static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2985{
2986 struct sd *sd = (struct sd *) gspca_dev;
2987
2988 *val = sd->brightness;
2989
2990 return 0;
2991}
2992
2993static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2994{
2995 struct sd *sd = (struct sd *) gspca_dev;
2996
2997 sd->contrast = val;
2998 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03002999 if (sd->stop_on_control_change)
3000 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003001 cit_set_contrast(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003002 if (sd->stop_on_control_change)
3003 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003004 }
3005
3006 return 0;
3007}
3008
3009static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3010{
3011 struct sd *sd = (struct sd *) gspca_dev;
3012
3013 *val = sd->contrast;
3014
3015 return 0;
3016}
3017
3018static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
3019{
3020 struct sd *sd = (struct sd *) gspca_dev;
3021
3022 sd->hue = val;
3023 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003024 if (sd->stop_on_control_change)
3025 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003026 cit_set_hue(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003027 if (sd->stop_on_control_change)
3028 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003029 }
3030 return 0;
3031}
3032
3033static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
3034{
3035 struct sd *sd = (struct sd *) gspca_dev;
3036
3037 *val = sd->hue;
3038
3039 return 0;
3040}
3041
3042static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
3043{
3044 struct sd *sd = (struct sd *) gspca_dev;
3045
3046 sd->sharpness = val;
3047 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003048 if (sd->stop_on_control_change)
3049 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003050 cit_set_sharpness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003051 if (sd->stop_on_control_change)
3052 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003053 }
3054 return 0;
3055}
3056
3057static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
3058{
3059 struct sd *sd = (struct sd *) gspca_dev;
3060
3061 *val = sd->sharpness;
3062
3063 return 0;
3064}
3065
Hans de Goede59f90a02010-06-09 11:39:50 -03003066static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val)
3067{
3068 struct sd *sd = (struct sd *) gspca_dev;
3069
3070 sd->lighting = val;
3071 if (gspca_dev->streaming) {
3072 if (sd->stop_on_control_change)
3073 sd_stopN(gspca_dev);
3074 cit_set_lighting(gspca_dev);
3075 if (sd->stop_on_control_change)
3076 cit_restart_stream(gspca_dev);
3077 }
3078 return 0;
3079}
3080
3081static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val)
3082{
3083 struct sd *sd = (struct sd *) gspca_dev;
3084
3085 *val = sd->lighting;
3086
3087 return 0;
3088}
3089
Hans de Goede659fefa2010-09-05 16:19:19 -03003090static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3091{
3092 struct sd *sd = (struct sd *) gspca_dev;
3093
3094 sd->hflip = val;
3095 if (gspca_dev->streaming) {
3096 if (sd->stop_on_control_change)
3097 sd_stopN(gspca_dev);
3098 cit_set_hflip(gspca_dev);
3099 if (sd->stop_on_control_change)
3100 cit_restart_stream(gspca_dev);
3101 }
3102 return 0;
3103}
3104
3105static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3106{
3107 struct sd *sd = (struct sd *) gspca_dev;
3108
3109 *val = sd->hflip;
3110
3111 return 0;
3112}
3113
Hans de Goede1f33de02010-09-05 16:05:22 -03003114
3115/* sub-driver description */
3116static const struct sd_desc sd_desc = {
3117 .name = MODULE_NAME,
3118 .ctrls = sd_ctrls,
3119 .nctrls = ARRAY_SIZE(sd_ctrls),
3120 .config = sd_config,
3121 .init = sd_init,
3122 .start = sd_start,
3123 .stopN = sd_stopN,
3124 .stop0 = sd_stop0,
3125 .pkt_scan = sd_pkt_scan,
3126};
3127
3128/* -- module initialisation -- */
3129static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede659fefa2010-09-05 16:19:19 -03003130 { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 },
Hans de Goede1f33de02010-09-05 16:05:22 -03003131 { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 },
3132 { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3133 { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 },
3134 { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3135 { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3136 { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3137 {}
3138};
3139MODULE_DEVICE_TABLE(usb, device_table);
3140
3141/* -- device connect -- */
3142static int sd_probe(struct usb_interface *intf,
3143 const struct usb_device_id *id)
3144{
Hans de Goede659fefa2010-09-05 16:19:19 -03003145 switch (id->driver_info) {
3146 case CIT_MODEL0:
3147 case CIT_MODEL1:
3148 if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
3149 return -ENODEV;
3150 break;
3151 case CIT_MODEL2:
3152 case CIT_MODEL3:
3153 case CIT_MODEL4:
3154 case CIT_IBM_NETCAM_PRO:
3155 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3156 return -ENODEV;
3157 break;
3158 }
3159
Hans de Goede1f33de02010-09-05 16:05:22 -03003160 return gspca_dev_probe2(intf, id, &sd_desc, sizeof(struct sd),
3161 THIS_MODULE);
3162}
3163
3164static struct usb_driver sd_driver = {
3165 .name = MODULE_NAME,
3166 .id_table = device_table,
3167 .probe = sd_probe,
3168 .disconnect = gspca_disconnect,
3169#ifdef CONFIG_PM
3170 .suspend = gspca_suspend,
3171 .resume = gspca_resume,
3172#endif
3173};
3174
3175/* -- module insert / remove -- */
3176static int __init sd_mod_init(void)
3177{
3178 int ret;
3179 ret = usb_register(&sd_driver);
3180 if (ret < 0)
3181 return ret;
3182 PDEBUG(D_PROBE, "registered");
3183 return 0;
3184}
3185static void __exit sd_mod_exit(void)
3186{
3187 usb_deregister(&sd_driver);
3188 PDEBUG(D_PROBE, "deregistered");
3189}
3190
3191module_init(sd_mod_init);
3192module_exit(sd_mod_exit);