blob: 157fbedbf493c4e18cbe962ca4f97671e04fb1e8 [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 *
Hans de Goede1fddcf02010-09-05 07:06:04 -03007 * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.com>
Hans de Goede1f33de02010-09-05 16:05:22 -03008 *
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
Hans de Goede1fddcf02010-09-05 07:06:04 -030034MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
Hans de Goede1f33de02010-09-05 16:05:22 -030035MODULE_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 Goede2c4e7762010-10-26 17:21:33 -0300188 .sizeimage = 176 * 144 * 3 / 2 + 4,
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,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300192 .sizeimage = 352 * 288 * 3 / 2 + 4,
Hans de Goede59f90a02010-06-09 11:39:50 -0300193 .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,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300199 .sizeimage = 160 * 120 * 3 / 2 + 4,
Hans de Goede1f33de02010-09-05 16:05:22 -0300200 .colorspace = V4L2_COLORSPACE_SRGB},
201 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
202 .bytesperline = 320,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300203 .sizeimage = 320 * 240 * 3 / 2 + 4,
Hans de Goede1f33de02010-09-05 16:05:22 -0300204 .colorspace = V4L2_COLORSPACE_SRGB},
205 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
206 .bytesperline = 640,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300207 .sizeimage = 640 * 480 * 3 / 2 + 4,
Hans de Goede1f33de02010-09-05 16:05:22 -0300208 .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,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300214 .sizeimage = 160 * 120 * 3 / 2 + 4,
Hans de Goede659fefa2010-09-05 16:19:19 -0300215 .colorspace = V4L2_COLORSPACE_SRGB},
216 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
217 .bytesperline = 176,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300218 .sizeimage = 176 * 144 * 3 / 2 + 4,
Hans de Goede659fefa2010-09-05 16:19:19 -0300219 .colorspace = V4L2_COLORSPACE_SRGB},
220 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
221 .bytesperline = 320,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300222 .sizeimage = 320 * 240 * 3 / 2 + 4,
Hans de Goede659fefa2010-09-05 16:19:19 -0300223 .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,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300229 .sizeimage = 160 * 120 * 3 / 2 + 4,
Hans de Goede59f90a02010-06-09 11:39:50 -0300230 .colorspace = V4L2_COLORSPACE_SRGB},
231 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
232 .bytesperline = 176,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300233 .sizeimage = 176 * 144 * 3 / 2 + 4,
Hans de Goede59f90a02010-06-09 11:39:50 -0300234 .colorspace = V4L2_COLORSPACE_SRGB},
235 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
236 .bytesperline = 320,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300237 .sizeimage = 320 * 240 + 4,
Hans de Goede59f90a02010-06-09 11:39:50 -0300238 .colorspace = V4L2_COLORSPACE_SRGB},
239 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
240 .bytesperline = 352,
Hans de Goede2c4e7762010-10-26 17:21:33 -0300241 .sizeimage = 352 * 288 + 4,
Hans de Goede59f90a02010-06-09 11:39:50 -0300242 .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)
Jean-François Moine0b656322010-09-13 05:19:58 -0300801 err("Failed to write a register (index 0x%04X,"
Hans de Goede1f33de02010-09-05 16:05:22 -0300802 " 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) {
Jean-François Moine0b656322010-09-13 05:19:58 -0300817 err("Failed to read a register (index 0x%04X, error %d)",
Hans de Goede1f33de02010-09-05 16:05:22 -0300818 index, res);
819 return res;
820 }
821
822 PDEBUG(D_PROBE,
823 "Register %04x value: %02x %02x %02x %02x %02x %02x %02x %02x",
824 index,
825 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
826
827 return 0;
828}
829
830/*
Hans de Goede59f90a02010-06-09 11:39:50 -0300831 * cit_send_FF_04_02()
832 *
833 * This procedure sends magic 3-command prefix to the camera.
834 * The purpose of this prefix is not known.
835 *
836 * History:
837 * 1/2/00 Created.
838 */
839static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
840{
841 cit_write_reg(gspca_dev, 0x00FF, 0x0127);
842 cit_write_reg(gspca_dev, 0x0004, 0x0124);
843 cit_write_reg(gspca_dev, 0x0002, 0x0124);
844}
845
846static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
847{
848 cit_write_reg(gspca_dev, 0x0000, 0x0127);
849 cit_write_reg(gspca_dev, 0x0004, 0x0124);
850 cit_write_reg(gspca_dev, 0x0006, 0x0124);
851}
852
853static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
854{
855 cit_write_reg(gspca_dev, x, 0x0127);
856 cit_write_reg(gspca_dev, 0x0000, 0x0124);
857}
858
859static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
860{
861 cit_send_x_00(gspca_dev, x);
862 cit_write_reg(gspca_dev, 0x0005, 0x0124);
863}
864
865static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
866{
867 cit_write_reg(gspca_dev, x, 0x0127);
868 cit_write_reg(gspca_dev, 0x0000, 0x0124);
869 cit_write_reg(gspca_dev, 0x0005, 0x0124);
870 cit_write_reg(gspca_dev, 0x0002, 0x0124);
871}
872
873static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
874{
875 cit_write_reg(gspca_dev, x, 0x0127);
876 cit_write_reg(gspca_dev, 0x0001, 0x0124);
877 cit_write_reg(gspca_dev, 0x0000, 0x0124);
878 cit_write_reg(gspca_dev, 0x0005, 0x0124);
879}
880
881static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
882{
883 cit_write_reg(gspca_dev, x, 0x0127);
884 cit_write_reg(gspca_dev, 0x0000, 0x0124);
885 cit_write_reg(gspca_dev, 0x0005, 0x0124);
886 cit_write_reg(gspca_dev, 0x0002, 0x0124);
887 cit_write_reg(gspca_dev, 0x0001, 0x0124);
888}
889
890static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
891{
892 cit_write_reg(gspca_dev, x, 0x0127);
893 cit_write_reg(gspca_dev, 0x0000, 0x0124);
894 cit_write_reg(gspca_dev, 0x0005, 0x0124);
895 cit_write_reg(gspca_dev, 0x0002, 0x0124);
896 cit_write_reg(gspca_dev, 0x0008, 0x0124);
897 cit_write_reg(gspca_dev, 0x0001, 0x0124);
898}
899
900static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
901{
902 cit_send_x_01_00_05(gspca_dev, 0x0088);
903 cit_send_x_00_05(gspca_dev, fkey);
904 cit_send_x_00_05_02_08_01(gspca_dev, val);
905 cit_send_x_00_05(gspca_dev, 0x0088);
906 cit_send_x_00_05_02_01(gspca_dev, fkey);
907 cit_send_x_00_05(gspca_dev, 0x0089);
908 cit_send_x_00(gspca_dev, fkey);
909 cit_send_00_04_06(gspca_dev);
910 cit_read_reg(gspca_dev, 0x0126);
911 cit_send_FF_04_02(gspca_dev);
912}
913
914static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
915{
916 cit_send_x_01_00_05(gspca_dev, 0x0088);
917 cit_send_x_00_05(gspca_dev, fkey);
918 cit_send_x_00_05_02(gspca_dev, val);
919}
920
921static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
922{
923 cit_write_reg(gspca_dev, 0x00ff, 0x012d);
924 cit_write_reg(gspca_dev, 0xfea3, 0x0124);
925}
926
927static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
928{
929 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
930 cit_write_reg(gspca_dev, 0x00ff, 0x012e);
931 cit_write_reg(gspca_dev, v1, 0x012f);
932 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
933 cit_write_reg(gspca_dev, 0xc719, 0x0124);
934 cit_write_reg(gspca_dev, v2, 0x0127);
935
936 cit_model2_Packet2(gspca_dev);
937}
938
939/*
940 * cit_model3_Packet1()
Hans de Goede1f33de02010-09-05 16:05:22 -0300941 *
942 * 00_0078_012d
943 * 00_0097_012f
944 * 00_d141_0124
945 * 00_0096_0127
946 * 00_fea8_0124
947*/
948static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
949{
950 cit_write_reg(gspca_dev, 0x0078, 0x012d);
951 cit_write_reg(gspca_dev, v1, 0x012f);
952 cit_write_reg(gspca_dev, 0xd141, 0x0124);
953 cit_write_reg(gspca_dev, v2, 0x0127);
954 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
955}
956
Hans de Goede59f90a02010-06-09 11:39:50 -0300957static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
958{
959 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
960 cit_write_reg(gspca_dev, v1, 0x012f);
961 cit_write_reg(gspca_dev, 0xd141, 0x0124);
962 cit_write_reg(gspca_dev, v2, 0x0127);
963 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
964}
965
966static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
967{
968 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
969 cit_write_reg(gspca_dev, 0x0026, 0x012f);
970 cit_write_reg(gspca_dev, 0xd141, 0x0124);
971 cit_write_reg(gspca_dev, val, 0x0127);
972 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
973 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
974 cit_write_reg(gspca_dev, 0x0038, 0x012d);
975 cit_write_reg(gspca_dev, 0x0004, 0x012f);
976 cit_write_reg(gspca_dev, 0xd145, 0x0124);
977 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
978}
979
Hans de Goede1f33de02010-09-05 16:05:22 -0300980/* this function is called at probe time */
981static int sd_config(struct gspca_dev *gspca_dev,
982 const struct usb_device_id *id)
983{
984 struct sd *sd = (struct sd *) gspca_dev;
985 struct cam *cam;
986
987 sd->model = id->driver_info;
988 if (sd->model == CIT_MODEL3 && ibm_netcam_pro)
989 sd->model = CIT_IBM_NETCAM_PRO;
990
991 cam = &gspca_dev->cam;
992 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -0300993 case CIT_MODEL0:
994 cam->cam_mode = model0_mode;
995 cam->nmodes = ARRAY_SIZE(model0_mode);
996 cam->reverse_alts = 1;
997 gspca_dev->ctrl_dis = ~((1 << SD_CONTRAST) | (1 << SD_HFLIP));
998 sd->sof_len = 4;
999 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001000 case CIT_MODEL1:
1001 cam->cam_mode = cif_yuv_mode;
1002 cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
Hans de Goede659fefa2010-09-05 16:19:19 -03001003 cam->reverse_alts = 1;
1004 gspca_dev->ctrl_dis = (1 << SD_HUE) | (1 << SD_HFLIP);
1005 sd->sof_len = 4;
Hans de Goede59f90a02010-06-09 11:39:50 -03001006 break;
1007 case CIT_MODEL2:
1008 cam->cam_mode = model2_mode + 1; /* no 160x120 */
1009 cam->nmodes = 3;
1010 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
Hans de Goede659fefa2010-09-05 16:19:19 -03001011 (1 << SD_SHARPNESS) |
1012 (1 << SD_HFLIP);
Hans de Goede59f90a02010-06-09 11:39:50 -03001013 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001014 case CIT_MODEL3:
1015 cam->cam_mode = vga_yuv_mode;
1016 cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
Hans de Goede659fefa2010-09-05 16:19:19 -03001017 gspca_dev->ctrl_dis = (1 << SD_HUE) |
1018 (1 << SD_LIGHTING) |
1019 (1 << SD_HFLIP);
Hans de Goede59f90a02010-06-09 11:39:50 -03001020 sd->stop_on_control_change = 1;
Hans de Goede659fefa2010-09-05 16:19:19 -03001021 sd->sof_len = 4;
Hans de Goede59f90a02010-06-09 11:39:50 -03001022 break;
1023 case CIT_MODEL4:
1024 cam->cam_mode = model2_mode;
1025 cam->nmodes = ARRAY_SIZE(model2_mode);
1026 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
1027 (1 << SD_SHARPNESS) |
Hans de Goede659fefa2010-09-05 16:19:19 -03001028 (1 << SD_LIGHTING) |
1029 (1 << SD_HFLIP);
Hans de Goede1f33de02010-09-05 16:05:22 -03001030 break;
1031 case CIT_IBM_NETCAM_PRO:
1032 cam->cam_mode = vga_yuv_mode;
1033 cam->nmodes = 2; /* no 640 x 480 */
1034 cam->input_flags = V4L2_IN_ST_VFLIP;
1035 gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST);
Hans de Goede59f90a02010-06-09 11:39:50 -03001036 sd->stop_on_control_change = 1;
Hans de Goede659fefa2010-09-05 16:19:19 -03001037 sd->sof_len = 4;
Hans de Goede1f33de02010-09-05 16:05:22 -03001038 break;
1039 }
1040
1041 sd->brightness = BRIGHTNESS_DEFAULT;
1042 sd->contrast = CONTRAST_DEFAULT;
1043 sd->hue = HUE_DEFAULT;
1044 sd->sharpness = SHARPNESS_DEFAULT;
Hans de Goede59f90a02010-06-09 11:39:50 -03001045 sd->lighting = LIGHTING_DEFAULT;
Hans de Goede659fefa2010-09-05 16:19:19 -03001046 sd->hflip = HFLIP_DEFAULT;
1047
1048 return 0;
1049}
1050
1051static int cit_init_model0(struct gspca_dev *gspca_dev)
1052{
1053 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1054 cit_write_reg(gspca_dev, 0x0001, 0x0112); /* turn on autogain ? */
1055 cit_write_reg(gspca_dev, 0x0000, 0x0400);
1056 cit_write_reg(gspca_dev, 0x0001, 0x0400);
1057 cit_write_reg(gspca_dev, 0x0000, 0x0420);
1058 cit_write_reg(gspca_dev, 0x0001, 0x0420);
1059 cit_write_reg(gspca_dev, 0x000d, 0x0409);
1060 cit_write_reg(gspca_dev, 0x0002, 0x040a);
1061 cit_write_reg(gspca_dev, 0x0018, 0x0405);
1062 cit_write_reg(gspca_dev, 0x0008, 0x0435);
1063 cit_write_reg(gspca_dev, 0x0026, 0x040b);
1064 cit_write_reg(gspca_dev, 0x0007, 0x0437);
1065 cit_write_reg(gspca_dev, 0x0015, 0x042f);
1066 cit_write_reg(gspca_dev, 0x002b, 0x0439);
1067 cit_write_reg(gspca_dev, 0x0026, 0x043a);
1068 cit_write_reg(gspca_dev, 0x0008, 0x0438);
1069 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1070 cit_write_reg(gspca_dev, 0x0041, 0x042c);
Hans de Goede1f33de02010-09-05 16:05:22 -03001071
1072 return 0;
1073}
1074
1075static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1076{
1077 cit_read_reg(gspca_dev, 0x128);
1078 cit_write_reg(gspca_dev, 0x0003, 0x0133);
1079 cit_write_reg(gspca_dev, 0x0000, 0x0117);
1080 cit_write_reg(gspca_dev, 0x0008, 0x0123);
1081 cit_write_reg(gspca_dev, 0x0000, 0x0100);
1082 cit_read_reg(gspca_dev, 0x0116);
1083 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1084 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1085 cit_write_reg(gspca_dev, 0x0000, 0x0133);
1086 cit_write_reg(gspca_dev, 0x0000, 0x0123);
1087 cit_write_reg(gspca_dev, 0x0001, 0x0117);
1088 cit_write_reg(gspca_dev, 0x0040, 0x0108);
1089 cit_write_reg(gspca_dev, 0x0019, 0x012c);
1090 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1091 cit_write_reg(gspca_dev, 0x0002, 0x0115);
1092 cit_write_reg(gspca_dev, 0x000b, 0x0115);
1093
1094 cit_write_reg(gspca_dev, 0x0078, 0x012d);
1095 cit_write_reg(gspca_dev, 0x0001, 0x012f);
1096 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1097 cit_write_reg(gspca_dev, 0x0079, 0x012d);
1098 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
1099 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
1100 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
1101 cit_read_reg(gspca_dev, 0x0126);
1102
1103 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000);
1104 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001);
1105 cit_model3_Packet1(gspca_dev, 0x000b, 0x0000);
1106 cit_model3_Packet1(gspca_dev, 0x000c, 0x0008);
1107 cit_model3_Packet1(gspca_dev, 0x000d, 0x003a);
1108 cit_model3_Packet1(gspca_dev, 0x000e, 0x0060);
1109 cit_model3_Packet1(gspca_dev, 0x000f, 0x0060);
1110 cit_model3_Packet1(gspca_dev, 0x0010, 0x0008);
1111 cit_model3_Packet1(gspca_dev, 0x0011, 0x0004);
1112 cit_model3_Packet1(gspca_dev, 0x0012, 0x0028);
1113 cit_model3_Packet1(gspca_dev, 0x0013, 0x0002);
1114 cit_model3_Packet1(gspca_dev, 0x0014, 0x0000);
1115 cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb);
1116 cit_model3_Packet1(gspca_dev, 0x0016, 0x0002);
1117 cit_model3_Packet1(gspca_dev, 0x0017, 0x0037);
1118 cit_model3_Packet1(gspca_dev, 0x0018, 0x0036);
1119 cit_model3_Packet1(gspca_dev, 0x001e, 0x0000);
1120 cit_model3_Packet1(gspca_dev, 0x001f, 0x0008);
1121 cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1);
1122 cit_model3_Packet1(gspca_dev, 0x0021, 0x0034);
1123 cit_model3_Packet1(gspca_dev, 0x0022, 0x0034);
1124 cit_model3_Packet1(gspca_dev, 0x0025, 0x0002);
1125 cit_model3_Packet1(gspca_dev, 0x0028, 0x0022);
1126 cit_model3_Packet1(gspca_dev, 0x0029, 0x000a);
1127 cit_model3_Packet1(gspca_dev, 0x002b, 0x0000);
1128 cit_model3_Packet1(gspca_dev, 0x002c, 0x0000);
1129 cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff);
1130 cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff);
1131 cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff);
1132 cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff);
1133 cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff);
1134 cit_model3_Packet1(gspca_dev, 0x0032, 0x0007);
1135 cit_model3_Packet1(gspca_dev, 0x0033, 0x0005);
1136 cit_model3_Packet1(gspca_dev, 0x0037, 0x0040);
1137 cit_model3_Packet1(gspca_dev, 0x0039, 0x0000);
1138 cit_model3_Packet1(gspca_dev, 0x003a, 0x0000);
1139 cit_model3_Packet1(gspca_dev, 0x003b, 0x0001);
1140 cit_model3_Packet1(gspca_dev, 0x003c, 0x0000);
1141 cit_model3_Packet1(gspca_dev, 0x0040, 0x000c);
1142 cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb);
1143 cit_model3_Packet1(gspca_dev, 0x0042, 0x0002);
1144 cit_model3_Packet1(gspca_dev, 0x0043, 0x0000);
1145 cit_model3_Packet1(gspca_dev, 0x0045, 0x0000);
1146 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
1147 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
1148 cit_model3_Packet1(gspca_dev, 0x0048, 0x0000);
1149 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
1150 cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff);
1151 cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff);
1152 cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff);
1153 cit_model3_Packet1(gspca_dev, 0x004f, 0x0000);
1154 cit_model3_Packet1(gspca_dev, 0x0050, 0x0000);
1155 cit_model3_Packet1(gspca_dev, 0x0051, 0x0002);
1156 cit_model3_Packet1(gspca_dev, 0x0055, 0x0000);
1157 cit_model3_Packet1(gspca_dev, 0x0056, 0x0000);
1158 cit_model3_Packet1(gspca_dev, 0x0057, 0x0000);
1159 cit_model3_Packet1(gspca_dev, 0x0058, 0x0002);
1160 cit_model3_Packet1(gspca_dev, 0x0059, 0x0000);
1161 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016);
1162 cit_model3_Packet1(gspca_dev, 0x005d, 0x0022);
1163 cit_model3_Packet1(gspca_dev, 0x005e, 0x003c);
1164 cit_model3_Packet1(gspca_dev, 0x005f, 0x0050);
1165 cit_model3_Packet1(gspca_dev, 0x0060, 0x0044);
1166 cit_model3_Packet1(gspca_dev, 0x0061, 0x0005);
1167 cit_model3_Packet1(gspca_dev, 0x006a, 0x007e);
1168 cit_model3_Packet1(gspca_dev, 0x006f, 0x0000);
1169 cit_model3_Packet1(gspca_dev, 0x0072, 0x001b);
1170 cit_model3_Packet1(gspca_dev, 0x0073, 0x0005);
1171 cit_model3_Packet1(gspca_dev, 0x0074, 0x000a);
1172 cit_model3_Packet1(gspca_dev, 0x0075, 0x001b);
1173 cit_model3_Packet1(gspca_dev, 0x0076, 0x002a);
1174 cit_model3_Packet1(gspca_dev, 0x0077, 0x003c);
1175 cit_model3_Packet1(gspca_dev, 0x0078, 0x0050);
1176 cit_model3_Packet1(gspca_dev, 0x007b, 0x0000);
1177 cit_model3_Packet1(gspca_dev, 0x007c, 0x0011);
1178 cit_model3_Packet1(gspca_dev, 0x007d, 0x0024);
1179 cit_model3_Packet1(gspca_dev, 0x007e, 0x0043);
1180 cit_model3_Packet1(gspca_dev, 0x007f, 0x005a);
1181 cit_model3_Packet1(gspca_dev, 0x0084, 0x0020);
1182 cit_model3_Packet1(gspca_dev, 0x0085, 0x0033);
1183 cit_model3_Packet1(gspca_dev, 0x0086, 0x000a);
1184 cit_model3_Packet1(gspca_dev, 0x0087, 0x0030);
1185 cit_model3_Packet1(gspca_dev, 0x0088, 0x0070);
1186 cit_model3_Packet1(gspca_dev, 0x008b, 0x0008);
1187 cit_model3_Packet1(gspca_dev, 0x008f, 0x0000);
1188 cit_model3_Packet1(gspca_dev, 0x0090, 0x0006);
1189 cit_model3_Packet1(gspca_dev, 0x0091, 0x0028);
1190 cit_model3_Packet1(gspca_dev, 0x0092, 0x005a);
1191 cit_model3_Packet1(gspca_dev, 0x0093, 0x0082);
1192 cit_model3_Packet1(gspca_dev, 0x0096, 0x0014);
1193 cit_model3_Packet1(gspca_dev, 0x0097, 0x0020);
1194 cit_model3_Packet1(gspca_dev, 0x0098, 0x0000);
1195 cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046);
1196 cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000);
1197 cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000);
1198 cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004);
1199 cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007);
1200 cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002);
1201 cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004);
1202 cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000);
1203 cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001);
1204 cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000);
1205 cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000);
1206 cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8);
1207 cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014);
1208 cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001);
1209 cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000);
1210 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004);
1211 cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf);
1212 cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf);
1213 cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf);
1214 cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000);
1215 cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020);
1216 cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040);
1217 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1218 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1219 cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf);
1220 cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf);
1221 cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008);
1222 cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000);
1223 cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8);
1224 cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001);
1225 cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022);
1226 cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000);
1227 cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028);
1228 cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002);
1229 cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000);
1230 cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000);
1231 cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001);
1232 cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000);
1233 cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000);
1234 cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000);
1235 cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000);
1236
1237 cit_model3_Packet1(gspca_dev, 0x00be, 0x0003);
1238 cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000);
1239 cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020);
1240 cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040);
1241 cit_model3_Packet1(gspca_dev, 0x0053, 0x0001);
1242 cit_model3_Packet1(gspca_dev, 0x0082, 0x000e);
1243 cit_model3_Packet1(gspca_dev, 0x0083, 0x0020);
1244 cit_model3_Packet1(gspca_dev, 0x0034, 0x003c);
1245 cit_model3_Packet1(gspca_dev, 0x006e, 0x0055);
1246 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005);
1247 cit_model3_Packet1(gspca_dev, 0x0063, 0x0008);
1248 cit_model3_Packet1(gspca_dev, 0x0066, 0x000a);
1249 cit_model3_Packet1(gspca_dev, 0x0067, 0x0006);
1250 cit_model3_Packet1(gspca_dev, 0x006b, 0x0010);
1251 cit_model3_Packet1(gspca_dev, 0x005a, 0x0001);
1252 cit_model3_Packet1(gspca_dev, 0x005b, 0x000a);
1253 cit_model3_Packet1(gspca_dev, 0x0023, 0x0006);
1254 cit_model3_Packet1(gspca_dev, 0x0026, 0x0004);
1255 cit_model3_Packet1(gspca_dev, 0x0036, 0x0069);
1256 cit_model3_Packet1(gspca_dev, 0x0038, 0x0064);
1257 cit_model3_Packet1(gspca_dev, 0x003d, 0x0003);
1258 cit_model3_Packet1(gspca_dev, 0x003e, 0x0001);
1259 cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014);
1260 cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014);
1261 cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004);
1262 cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001);
1263
1264 return 0;
1265}
1266
1267/* this function is called at probe and resume time */
1268static int sd_init(struct gspca_dev *gspca_dev)
1269{
1270 struct sd *sd = (struct sd *) gspca_dev;
1271
1272 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001273 case CIT_MODEL0:
1274 cit_init_model0(gspca_dev);
1275 sd_stop0(gspca_dev);
1276 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001277 case CIT_MODEL1:
1278 case CIT_MODEL2:
Hans de Goede1f33de02010-09-05 16:05:22 -03001279 case CIT_MODEL3:
Hans de Goede59f90a02010-06-09 11:39:50 -03001280 case CIT_MODEL4:
Hans de Goede1f33de02010-09-05 16:05:22 -03001281 break; /* All is done in sd_start */
1282 case CIT_IBM_NETCAM_PRO:
1283 cit_init_ibm_netcam_pro(gspca_dev);
1284 sd_stop0(gspca_dev);
1285 break;
1286 }
1287 return 0;
1288}
1289
1290static int cit_set_brightness(struct gspca_dev *gspca_dev)
1291{
1292 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede59f90a02010-06-09 11:39:50 -03001293 int i;
Hans de Goede1f33de02010-09-05 16:05:22 -03001294
1295 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001296 case CIT_MODEL0:
1297 case CIT_IBM_NETCAM_PRO:
1298 /* No (known) brightness control for these */
1299 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001300 case CIT_MODEL1:
1301 /* Model 1: Brightness range 0 - 63 */
1302 cit_Packet_Format1(gspca_dev, 0x0031, sd->brightness);
1303 cit_Packet_Format1(gspca_dev, 0x0032, sd->brightness);
1304 cit_Packet_Format1(gspca_dev, 0x0033, sd->brightness);
1305 break;
1306 case CIT_MODEL2:
1307 /* Model 2: Brightness range 0x60 - 0xee */
1308 /* Scale 0 - 63 to 0x60 - 0xee */
1309 i = 0x60 + sd->brightness * 2254 / 1000;
1310 cit_model2_Packet1(gspca_dev, 0x001a, i);
1311 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001312 case CIT_MODEL3:
1313 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
Hans de Goede59f90a02010-06-09 11:39:50 -03001314 i = sd->brightness;
1315 if (i < 0x0c)
1316 i = 0x0c;
1317 cit_model3_Packet1(gspca_dev, 0x0036, i);
1318 break;
1319 case CIT_MODEL4:
1320 /* Model 4: Brightness range 'i' in [0x04..0xb4] */
1321 /* Scale 0 - 63 to 0x04 - 0xb4 */
1322 i = 0x04 + sd->brightness * 2794 / 1000;
1323 cit_model4_BrightnessPacket(gspca_dev, i);
Hans de Goede1f33de02010-09-05 16:05:22 -03001324 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001325 }
1326
1327 return 0;
1328}
1329
1330static int cit_set_contrast(struct gspca_dev *gspca_dev)
1331{
1332 struct sd *sd = (struct sd *) gspca_dev;
1333
1334 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001335 case CIT_MODEL0: {
1336 int i;
1337 /* gain 0-15, 0-20 -> 0-15 */
1338 i = sd->contrast * 1000 / 1333;
1339 cit_write_reg(gspca_dev, i, 0x0422);
1340 /* gain 0-31, may not be lower then 0x0422, 0-20 -> 0-31 */
1341 i = sd->contrast * 2000 / 1333;
1342 cit_write_reg(gspca_dev, i, 0x0423);
1343 /* gain 0-127, may not be lower then 0x0423, 0-20 -> 0-63 */
1344 i = sd->contrast * 4000 / 1333;
1345 cit_write_reg(gspca_dev, i, 0x0424);
1346 /* gain 0-127, may not be lower then 0x0424, , 0-20 -> 0-127 */
1347 i = sd->contrast * 8000 / 1333;
1348 cit_write_reg(gspca_dev, i, 0x0425);
1349 break;
1350 }
1351 case CIT_MODEL2:
1352 case CIT_MODEL4:
1353 /* These models do not have this control. */
1354 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001355 case CIT_MODEL1:
1356 {
1357 /* Scale 0 - 20 to 15 - 0 */
1358 int i, new_contrast = (20 - sd->contrast) * 1000 / 1333;
1359 for (i = 0; i < cit_model1_ntries; i++) {
1360 cit_Packet_Format1(gspca_dev, 0x0014, new_contrast);
1361 cit_send_FF_04_02(gspca_dev);
1362 }
1363 break;
1364 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001365 case CIT_MODEL3:
1366 { /* Preset hardware values */
1367 static const struct {
1368 unsigned short cv1;
1369 unsigned short cv2;
1370 unsigned short cv3;
1371 } cv[7] = {
1372 { 0x05, 0x05, 0x0f }, /* Minimum */
1373 { 0x04, 0x04, 0x16 },
1374 { 0x02, 0x03, 0x16 },
1375 { 0x02, 0x08, 0x16 },
1376 { 0x01, 0x0c, 0x16 },
1377 { 0x01, 0x0e, 0x16 },
1378 { 0x01, 0x10, 0x16 } /* Maximum */
1379 };
1380 int i = sd->contrast / 3;
1381 cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1);
1382 cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2);
1383 cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3);
1384 break;
1385 }
1386 case CIT_IBM_NETCAM_PRO:
1387 cit_model3_Packet1(gspca_dev, 0x005b, sd->contrast + 1);
1388 break;
1389 }
1390 return 0;
1391}
1392
1393static int cit_set_hue(struct gspca_dev *gspca_dev)
1394{
1395 struct sd *sd = (struct sd *) gspca_dev;
1396
1397 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001398 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03001399 case CIT_MODEL1:
Hans de Goede659fefa2010-09-05 16:19:19 -03001400 case CIT_IBM_NETCAM_PRO:
1401 /* No hue control for these models */
Hans de Goede59f90a02010-06-09 11:39:50 -03001402 break;
1403 case CIT_MODEL2:
1404 cit_model2_Packet1(gspca_dev, 0x0024, sd->hue);
1405 /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */
1406 break;
1407 case CIT_MODEL3: {
1408 /* Model 3: Brightness range 'i' in [0x05..0x37] */
1409 /* TESTME according to the ibmcam driver this does not work */
1410 if (0) {
1411 /* Scale 0 - 127 to 0x05 - 0x37 */
1412 int i = 0x05 + sd->hue * 1000 / 2540;
1413 cit_model3_Packet1(gspca_dev, 0x007e, i);
1414 }
1415 break;
1416 }
1417 case CIT_MODEL4:
1418 /* HDG: taken from ibmcam, setting the color gains does not
1419 * really belong here.
1420 *
1421 * I am not sure r/g/b_gain variables exactly control gain
1422 * of those channels. Most likely they subtly change some
1423 * very internal image processing settings in the camera.
1424 * In any case, here is what they do, and feel free to tweak:
1425 *
1426 * r_gain: seriously affects red gain
1427 * g_gain: seriously affects green gain
1428 * b_gain: seriously affects blue gain
1429 * hue: changes average color from violet (0) to red (0xFF)
1430 */
1431 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
1432 cit_write_reg(gspca_dev, 0x001e, 0x012f);
1433 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1434 cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */
1435 cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */
1436 cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */
1437 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
1438 cit_write_reg(gspca_dev, sd->hue, 0x012d); /* Hue */
1439 cit_write_reg(gspca_dev, 0xf545, 0x0124);
Hans de Goede1f33de02010-09-05 16:05:22 -03001440 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001441 }
1442 return 0;
1443}
1444
1445static int cit_set_sharpness(struct gspca_dev *gspca_dev)
1446{
1447 struct sd *sd = (struct sd *) gspca_dev;
1448
1449 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001450 case CIT_MODEL0:
1451 case CIT_MODEL2:
1452 case CIT_MODEL4:
1453 case CIT_IBM_NETCAM_PRO:
1454 /* These models do not have this control */
1455 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001456 case CIT_MODEL1: {
1457 int i;
1458 const unsigned short sa[] = {
1459 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
1460
1461 for (i = 0; i < cit_model1_ntries; i++)
1462 cit_PacketFormat2(gspca_dev, 0x0013, sa[sd->sharpness]);
1463 break;
1464 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001465 case CIT_MODEL3:
1466 { /*
1467 * "Use a table of magic numbers.
1468 * This setting doesn't really change much.
1469 * But that's how Windows does it."
1470 */
1471 static const struct {
1472 unsigned short sv1;
1473 unsigned short sv2;
1474 unsigned short sv3;
1475 unsigned short sv4;
1476 } sv[7] = {
1477 { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */
1478 { 0x01, 0x04, 0x05, 0x14 },
1479 { 0x02, 0x04, 0x05, 0x14 },
1480 { 0x03, 0x04, 0x05, 0x14 },
1481 { 0x03, 0x05, 0x05, 0x14 },
1482 { 0x03, 0x06, 0x05, 0x14 },
1483 { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */
1484 };
1485 cit_model3_Packet1(gspca_dev, 0x0060, sv[sd->sharpness].sv1);
1486 cit_model3_Packet1(gspca_dev, 0x0061, sv[sd->sharpness].sv2);
1487 cit_model3_Packet1(gspca_dev, 0x0062, sv[sd->sharpness].sv3);
1488 cit_model3_Packet1(gspca_dev, 0x0063, sv[sd->sharpness].sv4);
1489 break;
1490 }
Hans de Goede1f33de02010-09-05 16:05:22 -03001491 }
1492 return 0;
1493}
1494
Hans de Goede59f90a02010-06-09 11:39:50 -03001495/*
1496 * cit_set_lighting()
1497 *
1498 * Camera model 1:
1499 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
1500 *
1501 * Camera model 2:
1502 * We have 16 levels of lighting, 0 for bright light and up to 15 for
1503 * low light. But values above 5 or so are useless because camera is
1504 * not really capable to produce anything worth viewing at such light.
1505 * This setting may be altered only in certain camera state.
1506 *
1507 * Low lighting forces slower FPS.
1508 *
1509 * History:
1510 * 1/5/00 Created.
1511 * 2/20/00 Added support for Model 2 cameras.
1512 */
1513static void cit_set_lighting(struct gspca_dev *gspca_dev)
1514{
1515 struct sd *sd = (struct sd *) gspca_dev;
1516
1517 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001518 case CIT_MODEL0:
1519 case CIT_MODEL2:
1520 case CIT_MODEL3:
1521 case CIT_MODEL4:
1522 case CIT_IBM_NETCAM_PRO:
1523 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03001524 case CIT_MODEL1: {
1525 int i;
1526 for (i = 0; i < cit_model1_ntries; i++)
1527 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1528 break;
1529 }
Hans de Goede659fefa2010-09-05 16:19:19 -03001530 }
1531}
1532
1533static void cit_set_hflip(struct gspca_dev *gspca_dev)
1534{
1535 struct sd *sd = (struct sd *) gspca_dev;
1536
1537 switch (sd->model) {
1538 case CIT_MODEL0:
1539 if (sd->hflip)
1540 cit_write_reg(gspca_dev, 0x0020, 0x0115);
1541 else
1542 cit_write_reg(gspca_dev, 0x0040, 0x0115);
1543 break;
1544 case CIT_MODEL1:
Hans de Goede59f90a02010-06-09 11:39:50 -03001545 case CIT_MODEL2:
1546 case CIT_MODEL3:
1547 case CIT_MODEL4:
1548 case CIT_IBM_NETCAM_PRO:
1549 break;
1550 }
1551}
1552
Hans de Goede1f33de02010-09-05 16:05:22 -03001553static int cit_restart_stream(struct gspca_dev *gspca_dev)
1554{
1555 struct sd *sd = (struct sd *) gspca_dev;
1556
1557 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03001558 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03001559 case CIT_MODEL1:
Hans de Goede1f33de02010-09-05 16:05:22 -03001560 case CIT_MODEL3:
1561 case CIT_IBM_NETCAM_PRO:
1562 cit_write_reg(gspca_dev, 0x0001, 0x0114);
Hans de Goede59f90a02010-06-09 11:39:50 -03001563 /* Fall through */
1564 case CIT_MODEL2:
1565 case CIT_MODEL4:
Hans de Goede1f33de02010-09-05 16:05:22 -03001566 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1567 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
Hans de Goede59f90a02010-06-09 11:39:50 -03001568 /* This happens repeatedly while streaming with the ibm netcam
1569 pro and the ibmcam driver did it for model3 after changing
1570 settings, but it does not seem to have any effect. */
1571 /* cit_write_reg(gspca_dev, 0x0001, 0x0113); */
1572 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03001573 }
1574
1575 sd->sof_read = 0;
1576
1577 return 0;
1578}
1579
Hans de Goede659fefa2010-09-05 16:19:19 -03001580static int cit_get_packet_size(struct gspca_dev *gspca_dev)
1581{
1582 struct usb_host_interface *alt;
1583 struct usb_interface *intf;
1584
1585 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
1586 alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
1587 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03001588 err("Couldn't get altsetting");
Hans de Goede659fefa2010-09-05 16:19:19 -03001589 return -EIO;
1590 }
1591
1592 return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
1593}
1594
Hans de Goede41f424b2010-09-06 05:24:21 -03001595/* Calculate the clockdiv giving us max fps given the available bandwidth */
1596static int cit_get_clock_div(struct gspca_dev *gspca_dev)
Hans de Goede659fefa2010-09-05 16:19:19 -03001597{
Hans de Goede659fefa2010-09-05 16:19:19 -03001598 int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */
1599 int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 };
1600 int packet_size;
1601
1602 packet_size = cit_get_packet_size(gspca_dev);
1603 if (packet_size < 0)
1604 return packet_size;
1605
1606 while (clock_div > 3 &&
1607 1000 * packet_size >
1608 gspca_dev->width * gspca_dev->height *
1609 fps[clock_div - 1] * 3 / 2)
1610 clock_div--;
1611
Hans de Goede41f424b2010-09-06 05:24:21 -03001612 PDEBUG(D_PROBE,
1613 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)",
1614 packet_size, gspca_dev->width, gspca_dev->height, clock_div,
1615 fps[clock_div]);
1616
1617 return clock_div;
1618}
1619
1620static int cit_start_model0(struct gspca_dev *gspca_dev)
1621{
1622 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1623 int clock_div;
1624
1625 clock_div = cit_get_clock_div(gspca_dev);
1626 if (clock_div < 0)
1627 return clock_div;
1628
Hans de Goede659fefa2010-09-05 16:19:19 -03001629 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1630 cit_write_reg(gspca_dev, 0x0003, 0x0438);
1631 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1632 cit_write_reg(gspca_dev, 0x0041, 0x042c);
1633 cit_write_reg(gspca_dev, 0x0008, 0x0436);
1634 cit_write_reg(gspca_dev, 0x0024, 0x0403);
1635 cit_write_reg(gspca_dev, 0x002c, 0x0404);
1636 cit_write_reg(gspca_dev, 0x0002, 0x0426);
1637 cit_write_reg(gspca_dev, 0x0014, 0x0427);
1638
1639 switch (gspca_dev->width) {
1640 case 160: /* 160x120 */
1641 cit_write_reg(gspca_dev, 0x0004, 0x010b);
1642 cit_write_reg(gspca_dev, 0x0001, 0x010a);
1643 cit_write_reg(gspca_dev, 0x0010, 0x0102);
1644 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1645 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1646 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1647 break;
1648
1649 case 176: /* 176x144 */
1650 cit_write_reg(gspca_dev, 0x0006, 0x010b);
1651 cit_write_reg(gspca_dev, 0x0000, 0x010a);
1652 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1653 cit_write_reg(gspca_dev, 0x00b0, 0x0103);
1654 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1655 cit_write_reg(gspca_dev, 0x0090, 0x0105);
1656 break;
1657
1658 case 320: /* 320x240 */
1659 cit_write_reg(gspca_dev, 0x0008, 0x010b);
1660 cit_write_reg(gspca_dev, 0x0004, 0x010a);
1661 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1662 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1663 cit_write_reg(gspca_dev, 0x0010, 0x0104);
1664 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1665 break;
1666 }
1667
1668 cit_write_reg(gspca_dev, compression, 0x0109);
1669 cit_write_reg(gspca_dev, clock_div, 0x0111);
Hans de Goede659fefa2010-09-05 16:19:19 -03001670
1671 return 0;
1672}
1673
Hans de Goede59f90a02010-06-09 11:39:50 -03001674static int cit_start_model1(struct gspca_dev *gspca_dev)
1675{
1676 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede41f424b2010-09-06 05:24:21 -03001677 int i, clock_div;
Hans de Goede55c1b7d2010-08-30 14:47:45 -03001678
Hans de Goede41f424b2010-09-06 05:24:21 -03001679 clock_div = cit_get_clock_div(gspca_dev);
1680 if (clock_div < 0)
1681 return clock_div;
Hans de Goede59f90a02010-06-09 11:39:50 -03001682
1683 cit_read_reg(gspca_dev, 0x0128);
1684 cit_read_reg(gspca_dev, 0x0100);
1685 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1686 cit_read_reg(gspca_dev, 0x0100);
1687 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1688 cit_read_reg(gspca_dev, 0x0100);
1689 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1690 cit_write_reg(gspca_dev, 0x01, 0x0108);
1691
1692 cit_write_reg(gspca_dev, 0x03, 0x0112);
1693 cit_read_reg(gspca_dev, 0x0115);
1694 cit_write_reg(gspca_dev, 0x06, 0x0115);
1695 cit_read_reg(gspca_dev, 0x0116);
1696 cit_write_reg(gspca_dev, 0x44, 0x0116);
1697 cit_read_reg(gspca_dev, 0x0116);
1698 cit_write_reg(gspca_dev, 0x40, 0x0116);
1699 cit_read_reg(gspca_dev, 0x0115);
1700 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1701 cit_write_reg(gspca_dev, 0x19, 0x012c);
1702
1703 cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
1704 cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
1705 cit_Packet_Format1(gspca_dev, 0x39, 0x09);
1706 cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
1707 cit_Packet_Format1(gspca_dev, 0x28, 0x22);
1708 cit_Packet_Format1(gspca_dev, 0x27, 0x00);
1709 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1710 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1711
1712 for (i = 0; i < cit_model1_ntries; i++)
1713 cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
1714
1715 for (i = 0; i < cit_model1_ntries; i++)
1716 cit_Packet_Format1(gspca_dev, 0x30, 0x14);
1717
1718 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1719 cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
1720 cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
1721 cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
1722 cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
1723 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1724 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1725
1726 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1727 cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
1728 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
1729 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
1730 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
1731 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
1732 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
1733 cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
1734 cit_PacketFormat2(gspca_dev, 0x11, 0xba);
1735 cit_PacketFormat2(gspca_dev, 0x12, 0x53);
1736 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1737 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1738
1739 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1740 cit_PacketFormat2(gspca_dev, 0x16, 0x00);
1741 cit_PacketFormat2(gspca_dev, 0x17, 0x28);
1742 cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
1743 cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
1744 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1745 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1746
1747 for (i = 0; i < cit_model1_ntries; i++)
1748 cit_Packet_Format1(gspca_dev, 0x00, 0x18);
1749 for (i = 0; i < cit_model1_ntries; i++)
1750 cit_Packet_Format1(gspca_dev, 0x13, 0x18);
1751 for (i = 0; i < cit_model1_ntries; i++)
1752 cit_Packet_Format1(gspca_dev, 0x14, 0x06);
1753
1754 /* TESTME These are handled through controls
1755 KEEP until someone can test leaving this out is ok */
1756 if (0) {
1757 /* This is default brightness */
1758 for (i = 0; i < cit_model1_ntries; i++)
1759 cit_Packet_Format1(gspca_dev, 0x31, 0x37);
1760 for (i = 0; i < cit_model1_ntries; i++)
1761 cit_Packet_Format1(gspca_dev, 0x32, 0x46);
1762 for (i = 0; i < cit_model1_ntries; i++)
1763 cit_Packet_Format1(gspca_dev, 0x33, 0x55);
1764 }
1765
1766 cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
1767 for (i = 0; i < cit_model1_ntries; i++)
1768 cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
1769 for (i = 0; i < cit_model1_ntries; i++)
1770 cit_Packet_Format1(gspca_dev, 0x29, 0x80);
1771 cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
1772 cit_Packet_Format1(gspca_dev, 0x30, 0x17);
1773 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1774 for (i = 0; i < cit_model1_ntries; i++)
1775 cit_Packet_Format1(gspca_dev, 0x34, 0x00);
1776
1777 cit_write_reg(gspca_dev, 0x00, 0x0101);
1778 cit_write_reg(gspca_dev, 0x00, 0x010a);
1779
1780 switch (gspca_dev->width) {
1781 case 128: /* 128x96 */
1782 cit_write_reg(gspca_dev, 0x80, 0x0103);
1783 cit_write_reg(gspca_dev, 0x60, 0x0105);
1784 cit_write_reg(gspca_dev, 0x0c, 0x010b);
1785 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1786 cit_write_reg(gspca_dev, 0x0b, 0x011d);
1787 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1788 cit_write_reg(gspca_dev, 0x00, 0x0129);
Hans de Goede59f90a02010-06-09 11:39:50 -03001789 break;
1790 case 176: /* 176x144 */
1791 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1792 cit_write_reg(gspca_dev, 0x8f, 0x0105);
1793 cit_write_reg(gspca_dev, 0x06, 0x010b);
1794 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1795 cit_write_reg(gspca_dev, 0x0d, 0x011d);
1796 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1797 cit_write_reg(gspca_dev, 0x03, 0x0129);
Hans de Goede59f90a02010-06-09 11:39:50 -03001798 break;
1799 case 352: /* 352x288 */
1800 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1801 cit_write_reg(gspca_dev, 0x90, 0x0105);
1802 cit_write_reg(gspca_dev, 0x02, 0x010b);
1803 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1804 cit_write_reg(gspca_dev, 0x05, 0x011d);
1805 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1806 cit_write_reg(gspca_dev, 0x00, 0x0129);
Hans de Goede59f90a02010-06-09 11:39:50 -03001807 break;
1808 }
1809
1810 cit_write_reg(gspca_dev, 0xff, 0x012b);
1811
1812 /* TESTME These are handled through controls
1813 KEEP until someone can test leaving this out is ok */
1814 if (0) {
1815 /* This is another brightness - don't know why */
1816 for (i = 0; i < cit_model1_ntries; i++)
1817 cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
1818 for (i = 0; i < cit_model1_ntries; i++)
1819 cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
1820 for (i = 0; i < cit_model1_ntries; i++)
1821 cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
1822
1823 /* Default contrast */
1824 for (i = 0; i < cit_model1_ntries; i++)
1825 cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
1826
1827 /* Default sharpness */
1828 for (i = 0; i < cit_model1_ntries2; i++)
1829 cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
1830
1831 /* Default lighting conditions */
1832 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1833 }
1834
1835 /* Assorted init */
1836 switch (gspca_dev->width) {
1837 case 128: /* 128x96 */
1838 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1839 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1840 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1841 cit_write_reg(gspca_dev, 0x36, 0x0102);
1842 cit_write_reg(gspca_dev, 0x1a, 0x0104);
1843 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1844 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1845 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1846 break;
1847 case 176: /* 176x144 */
1848 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1849 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1850 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1851 cit_write_reg(gspca_dev, 0x04, 0x0102);
1852 cit_write_reg(gspca_dev, 0x02, 0x0104);
1853 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1854 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1855 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1856 break;
1857 case 352: /* 352x288 */
1858 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1859 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1860 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1861 cit_write_reg(gspca_dev, 0x08, 0x0102);
1862 cit_write_reg(gspca_dev, 0x01, 0x0104);
1863 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1864 cit_write_reg(gspca_dev, 0x2f, 0x011c);
1865 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1866 break;
1867 }
1868
1869 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1870 cit_write_reg(gspca_dev, clock_div, 0x0111);
1871
Hans de Goede59f90a02010-06-09 11:39:50 -03001872 return 0;
1873}
1874
1875static int cit_start_model2(struct gspca_dev *gspca_dev)
1876{
1877 struct sd *sd = (struct sd *) gspca_dev;
1878 int clock_div = 0;
1879
1880 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1881 cit_read_reg(gspca_dev, 0x0116);
1882 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1883 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1884 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
1885 cit_write_reg(gspca_dev, 0x0008, 0x012b);
1886 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1887 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1888 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1889 switch (gspca_dev->width) {
1890 case 176: /* 176x144 */
1891 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1892 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1893 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1894 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
1895 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
1896 /* TESTME HDG: this does not seem right
1897 (it is 2 for all other resolutions) */
1898 sd->sof_len = 10;
1899 break;
1900 case 320: /* 320x240 */
1901 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
1902 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1903 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
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 /* case VIDEOSIZE_352x240: */
1909 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1910 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1911 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1912 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1913 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1914 sd->sof_len = 2;
1915 break;
1916 case 352: /* 352x288 */
1917 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1918 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1919 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1920 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1921 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1922 sd->sof_len = 2;
1923 break;
1924 }
1925
1926 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1927
1928 switch (gspca_dev->width) {
1929 case 176: /* 176x144 */
1930 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1931 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
1932 break;
1933 case 320: /* 320x240 */
1934 case 352: /* 352x288 */
1935 cit_write_reg(gspca_dev, 0x0040, 0x0111);
1936 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
1937 break;
1938 }
1939 cit_write_reg(gspca_dev, 0x009b, 0x010f);
1940 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
1941
1942 /*
1943 * Hardware settings, may affect CMOS sensor; not user controls!
1944 * -------------------------------------------------------------
1945 * 0x0004: no effect
1946 * 0x0006: hardware effect
1947 * 0x0008: no effect
1948 * 0x000a: stops video stream, probably important h/w setting
1949 * 0x000c: changes color in hardware manner (not user setting)
1950 * 0x0012: changes number of colors (does not affect speed)
1951 * 0x002a: no effect
1952 * 0x002c: hardware setting (related to scan lines)
1953 * 0x002e: stops video stream, probably important h/w setting
1954 */
1955 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
1956 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
1957 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
1958 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
1959 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
1960 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
1961 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
1962 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
1963 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
1964
1965 /*
1966 * Function 0x0030 pops up all over the place. Apparently
1967 * it is a hardware control register, with every bit assigned to
1968 * do something.
1969 */
1970 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
1971
1972 /*
1973 * Magic control of CMOS sensor. Only lower values like
1974 * 0-3 work, and picture shifts left or right. Don't change.
1975 */
1976 switch (gspca_dev->width) {
1977 case 176: /* 176x144 */
1978 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1979 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1980 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1981 clock_div = 6;
1982 break;
1983 case 320: /* 320x240 */
1984 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
1985 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
1986 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1987 clock_div = 8;
1988 break;
1989 /* case VIDEOSIZE_352x240: */
1990 /* This mode doesn't work as Windows programs it; changed to work */
1991 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1992 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1993 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1994 clock_div = 10;
1995 break;
1996 case 352: /* 352x288 */
1997 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
1998 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1999 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
2000 clock_div = 16;
2001 break;
2002 }
2003
2004 /* TESTME These are handled through controls
2005 KEEP until someone can test leaving this out is ok */
2006 if (0)
2007 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
2008
2009 /*
2010 * We have our own frame rate setting varying from 0 (slowest) to 6
2011 * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
2012 # where 0 is also the slowest setting. However for all practical
2013 # reasons high settings make no sense because USB is not fast enough
2014 # to support high FPS. Be aware that the picture datastream will be
2015 # severely disrupted if you ask for frame rate faster than allowed
2016 # for the video size - see below:
2017 *
2018 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
2019 * -----------------------------------------------------------------
2020 * 176x144: [6..31]
2021 * 320x240: [8..31]
2022 * 352x240: [10..31]
2023 * 352x288: [16..31] I have to raise lower threshold for stability...
2024 *
2025 * As usual, slower FPS provides better sensitivity.
2026 */
2027 cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
2028
2029 /*
2030 * This setting does not visibly affect pictures; left it here
2031 * because it was present in Windows USB data stream. This function
2032 * does not allow arbitrary values and apparently is a bit mask, to
2033 * be activated only at appropriate time. Don't change it randomly!
2034 */
2035 switch (gspca_dev->width) {
2036 case 176: /* 176x144 */
2037 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
2038 break;
2039 case 320: /* 320x240 */
2040 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
2041 break;
2042 /* case VIDEOSIZE_352x240: */
2043 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
2044 break;
2045 case 352: /* 352x288 */
2046 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
2047 break;
2048 }
2049
2050 /* FIXME this cannot be changed while streaming, so we
2051 should report a grabbed flag for this control. */
2052 cit_model2_Packet1(gspca_dev, 0x0028, sd->lighting);
2053 /* color balance rg2 */
2054 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
2055 /* saturation */
2056 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
2057 /* color balance yb */
2058 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
2059
2060 /* Hardware control command */
2061 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2062
2063 return 0;
2064}
2065
Hans de Goede1f33de02010-09-05 16:05:22 -03002066static int cit_start_model3(struct gspca_dev *gspca_dev)
2067{
2068 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2069 int i, clock_div = 0;
2070
2071 /* HDG not in ibmcam driver, added to see if it helps with
2072 auto-detecting between model3 and ibm netcamera pro */
2073 cit_read_reg(gspca_dev, 0x128);
2074
2075 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2076 cit_read_reg(gspca_dev, 0x0116);
2077 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2078 cit_write_reg(gspca_dev, 0x0002, 0x0112);
2079 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2080 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2081 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2082 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2083 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2084 cit_write_reg(gspca_dev, 0x0002, 0x0115);
2085 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2086 cit_read_reg(gspca_dev, 0x0115);
2087 cit_write_reg(gspca_dev, 0x000b, 0x0115);
2088
Hans de Goede59f90a02010-06-09 11:39:50 -03002089 /* TESTME HDG not in ibmcam driver, added to see if it helps with
Hans de Goede1f33de02010-09-05 16:05:22 -03002090 auto-detecting between model3 and ibm netcamera pro */
2091 if (0) {
2092 cit_write_reg(gspca_dev, 0x0078, 0x012d);
2093 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2094 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2095 cit_write_reg(gspca_dev, 0x0079, 0x012d);
2096 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
2097 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
2098 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2099 cit_read_reg(gspca_dev, 0x0126);
2100 }
2101
2102 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
2103 cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6);
2104 cit_model3_Packet1(gspca_dev, 0x000c, 0x0002);
2105 cit_model3_Packet1(gspca_dev, 0x000d, 0x0020);
2106 cit_model3_Packet1(gspca_dev, 0x000e, 0x0033);
2107 cit_model3_Packet1(gspca_dev, 0x000f, 0x0007);
2108 cit_model3_Packet1(gspca_dev, 0x0010, 0x0000);
2109 cit_model3_Packet1(gspca_dev, 0x0011, 0x0070);
2110 cit_model3_Packet1(gspca_dev, 0x0012, 0x0030);
2111 cit_model3_Packet1(gspca_dev, 0x0013, 0x0000);
2112 cit_model3_Packet1(gspca_dev, 0x0014, 0x0001);
2113 cit_model3_Packet1(gspca_dev, 0x0015, 0x0001);
2114 cit_model3_Packet1(gspca_dev, 0x0016, 0x0001);
2115 cit_model3_Packet1(gspca_dev, 0x0017, 0x0001);
2116 cit_model3_Packet1(gspca_dev, 0x0018, 0x0000);
2117 cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3);
2118 cit_model3_Packet1(gspca_dev, 0x0020, 0x0000);
2119 cit_model3_Packet1(gspca_dev, 0x0028, 0x0010);
2120 cit_model3_Packet1(gspca_dev, 0x0029, 0x0054);
2121 cit_model3_Packet1(gspca_dev, 0x002a, 0x0013);
2122 cit_model3_Packet1(gspca_dev, 0x002b, 0x0007);
2123 cit_model3_Packet1(gspca_dev, 0x002d, 0x0028);
2124 cit_model3_Packet1(gspca_dev, 0x002e, 0x0000);
2125 cit_model3_Packet1(gspca_dev, 0x0031, 0x0000);
2126 cit_model3_Packet1(gspca_dev, 0x0032, 0x0000);
2127 cit_model3_Packet1(gspca_dev, 0x0033, 0x0000);
2128 cit_model3_Packet1(gspca_dev, 0x0034, 0x0000);
2129 cit_model3_Packet1(gspca_dev, 0x0035, 0x0038);
2130 cit_model3_Packet1(gspca_dev, 0x003a, 0x0001);
2131 cit_model3_Packet1(gspca_dev, 0x003c, 0x001e);
2132 cit_model3_Packet1(gspca_dev, 0x003f, 0x000a);
2133 cit_model3_Packet1(gspca_dev, 0x0041, 0x0000);
2134 cit_model3_Packet1(gspca_dev, 0x0046, 0x003f);
2135 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
2136 cit_model3_Packet1(gspca_dev, 0x0050, 0x0005);
2137 cit_model3_Packet1(gspca_dev, 0x0052, 0x001a);
2138 cit_model3_Packet1(gspca_dev, 0x0053, 0x0003);
2139 cit_model3_Packet1(gspca_dev, 0x005a, 0x006b);
2140 cit_model3_Packet1(gspca_dev, 0x005d, 0x001e);
2141 cit_model3_Packet1(gspca_dev, 0x005e, 0x0030);
2142 cit_model3_Packet1(gspca_dev, 0x005f, 0x0041);
2143 cit_model3_Packet1(gspca_dev, 0x0064, 0x0008);
2144 cit_model3_Packet1(gspca_dev, 0x0065, 0x0015);
2145 cit_model3_Packet1(gspca_dev, 0x0068, 0x000f);
2146 cit_model3_Packet1(gspca_dev, 0x0079, 0x0000);
2147 cit_model3_Packet1(gspca_dev, 0x007a, 0x0000);
2148 cit_model3_Packet1(gspca_dev, 0x007c, 0x003f);
2149 cit_model3_Packet1(gspca_dev, 0x0082, 0x000f);
2150 cit_model3_Packet1(gspca_dev, 0x0085, 0x0000);
2151 cit_model3_Packet1(gspca_dev, 0x0099, 0x0000);
2152 cit_model3_Packet1(gspca_dev, 0x009b, 0x0023);
2153 cit_model3_Packet1(gspca_dev, 0x009c, 0x0022);
2154 cit_model3_Packet1(gspca_dev, 0x009d, 0x0096);
2155 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
2156 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
2157
2158 switch (gspca_dev->width) {
2159 case 160:
2160 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2161 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2162 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2163 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2164 cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */
2165 cit_write_reg(gspca_dev, 0x00a9, 0x0119);
2166 cit_write_reg(gspca_dev, 0x0016, 0x011b);
2167 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2168 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2169 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2170 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2171 cit_write_reg(gspca_dev, 0x0018, 0x0102);
2172 cit_write_reg(gspca_dev, 0x0004, 0x0104);
2173 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2174 cit_write_reg(gspca_dev, 0x0028, 0x011c);
2175 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2176 cit_write_reg(gspca_dev, 0x0000, 0x0118);
2177 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2178 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2179 cit_write_reg(gspca_dev, compression, 0x0109);
2180 clock_div = 3;
2181 break;
2182 case 320:
2183 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2184 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2185 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2186 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2187 cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */
2188 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */
2189 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2190 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2191 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2192 /* 4 commands from 160x120 skipped */
2193 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2194 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2195 cit_write_reg(gspca_dev, compression, 0x0109);
2196 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2197 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2198 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2199 cit_write_reg(gspca_dev, 0x0010, 0x0104);
2200 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2201 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2202 cit_write_reg(gspca_dev, 0x001c, 0x0118);
2203 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2204 clock_div = 5;
2205 break;
2206 case 640:
2207 cit_write_reg(gspca_dev, 0x00f0, 0x0105);
2208 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2209 cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */
2210 cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
2211 cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
2212 cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */
2213 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2214 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2215 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2216 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2217 cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */
2218 cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
2219 cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
2220 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2221 cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
2222 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2223 cit_write_reg(gspca_dev, compression, 0x0109);
2224 cit_write_reg(gspca_dev, 0x0040, 0x0101);
2225 cit_write_reg(gspca_dev, 0x0040, 0x0103);
2226 cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
2227 clock_div = 7;
2228 break;
2229 }
2230
2231 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */
2232 cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */
2233 cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */
2234 cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */
2235 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */
2236 cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */
2237 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2238 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2239 cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */
2240 cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */
2241 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */
2242 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2243 cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */
2244 cit_model3_Packet1(gspca_dev, 0x002f, 0x002a);
2245 cit_model3_Packet1(gspca_dev, 0x0030, 0x0029);
2246 cit_model3_Packet1(gspca_dev, 0x0037, 0x0002);
2247 cit_model3_Packet1(gspca_dev, 0x0038, 0x0059);
2248 cit_model3_Packet1(gspca_dev, 0x003d, 0x002e);
2249 cit_model3_Packet1(gspca_dev, 0x003e, 0x0028);
2250 cit_model3_Packet1(gspca_dev, 0x0078, 0x0005);
2251 cit_model3_Packet1(gspca_dev, 0x007b, 0x0011);
2252 cit_model3_Packet1(gspca_dev, 0x007d, 0x004b);
2253 cit_model3_Packet1(gspca_dev, 0x007f, 0x0022);
2254 cit_model3_Packet1(gspca_dev, 0x0080, 0x000c);
2255 cit_model3_Packet1(gspca_dev, 0x0081, 0x000b);
2256 cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd);
2257 cit_model3_Packet1(gspca_dev, 0x0086, 0x000b);
2258 cit_model3_Packet1(gspca_dev, 0x0087, 0x000b);
2259 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e);
2260 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2261 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2262 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2263
Hans de Goede41f424b2010-09-06 05:24:21 -03002264 /* FIXME we should probably use cit_get_clock_div() here (in
2265 combination with isoc negotiation using the programmable isoc size)
2266 like with the IBM netcam pro). */
Hans de Goede1f33de02010-09-05 16:05:22 -03002267 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
2268
2269 switch (gspca_dev->width) {
2270 case 160:
2271 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2272 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2273 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2274 cit_model3_Packet1(gspca_dev, 0x0040, 0x000a);
2275 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2276 break;
2277 case 320:
2278 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2279 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2280 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2281 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2282 cit_model3_Packet1(gspca_dev, 0x0051, 0x000b);
2283 break;
2284 case 640:
2285 cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */
2286 cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */
2287 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2288 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2289 break;
2290 }
2291
2292/* if (sd->input_index) { */
2293 if (rca_input) {
2294 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2295 if (rca_initdata[i][0])
2296 cit_read_reg(gspca_dev, rca_initdata[i][2]);
2297 else
2298 cit_write_reg(gspca_dev, rca_initdata[i][1],
2299 rca_initdata[i][2]);
2300 }
2301 }
2302
Hans de Goede59f90a02010-06-09 11:39:50 -03002303 return 0;
2304}
2305
2306static int cit_start_model4(struct gspca_dev *gspca_dev)
2307{
2308 struct sd *sd = (struct sd *) gspca_dev;
2309
2310 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2311 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2312 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
2313 cit_write_reg(gspca_dev, 0x0080, 0x012b);
2314 cit_write_reg(gspca_dev, 0x0000, 0x0108);
2315 cit_write_reg(gspca_dev, 0x0001, 0x0133);
2316 cit_write_reg(gspca_dev, 0x009b, 0x010f);
2317 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
2318 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
2319 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
2320
2321 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2322 cit_write_reg(gspca_dev, 0x0004, 0x012f);
2323 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2324 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2325 cit_write_reg(gspca_dev, 0x00fb, 0x012e);
2326 cit_write_reg(gspca_dev, 0x0000, 0x0130);
2327 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2328 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2329 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2330 cit_write_reg(gspca_dev, 0x000c, 0x0127);
2331 cit_write_reg(gspca_dev, 0x0009, 0x012e);
2332 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2333
2334 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2335 cit_write_reg(gspca_dev, 0x0012, 0x012f);
2336 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2337 cit_write_reg(gspca_dev, 0x0008, 0x0127);
2338 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2339 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2340 cit_write_reg(gspca_dev, 0x002a, 0x012d);
2341 cit_write_reg(gspca_dev, 0x0000, 0x012f);
2342 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2343 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2344 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2345
2346 switch (gspca_dev->width) {
2347 case 128: /* 128x96 */
2348 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2349 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2350 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2351 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2352 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2353 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2354 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2355 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2356 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2357 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2358 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2359 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2360 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2361 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2362 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2363 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2364 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2365 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2366 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2367 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2368 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2369 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2370 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2371 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2372 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2373 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2374 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2375 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2376 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2377 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2378 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2379 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2380 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2381 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2382 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2383 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2384 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2385 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2386 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2387 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2388 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2389 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2390 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2391 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2392 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2393 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2394 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2395 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2396 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2397 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2398 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2399 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2400 sd->sof_len = 2;
2401 break;
2402 case 160: /* 160x120 */
2403 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2404 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2405 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2406 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2407 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2408 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2409 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2410 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2411 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2412 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2413 cit_write_reg(gspca_dev, 0x000b, 0x0127);
2414 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2415 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2416 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2417 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2418 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2419 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2420 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2421 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2422 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2423 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2424 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2425 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2426 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2427 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2428 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2429 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2430 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2431 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2432 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2433 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2434 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2435 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2436 cit_write_reg(gspca_dev, 0x0025, 0x0127);
2437 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2438 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2439 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2440 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2441 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2442 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2443 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2444 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2445 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2446 cit_write_reg(gspca_dev, 0x0048, 0x0127);
2447 cit_write_reg(gspca_dev, 0x0035, 0x012e);
2448 cit_write_reg(gspca_dev, 0x00d0, 0x0130);
2449 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2450 cit_write_reg(gspca_dev, 0x0048, 0x012d);
2451 cit_write_reg(gspca_dev, 0x0090, 0x012f);
2452 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2453 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2454 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2455 sd->sof_len = 2;
2456 break;
2457 case 176: /* 176x144 */
2458 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2459 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2460 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2461 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2462 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2463 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2464 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2465 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2466 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2467 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2468 cit_write_reg(gspca_dev, 0x0007, 0x0127);
2469 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2470 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2471 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2472 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2473 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2474 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2475 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2476 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2477 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2478 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2479 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2480 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2481 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2482 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2483 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2484 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2485 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2486 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2487 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2488 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2489 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2490 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2491 cit_write_reg(gspca_dev, 0x0028, 0x0127);
2492 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2493 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2494 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2495 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2496 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2497 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2498 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2499 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2500 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2501 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2502 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2503 cit_write_reg(gspca_dev, 0x002a, 0x0130);
2504 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2505 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2506 cit_write_reg(gspca_dev, 0x006d, 0x012f);
2507 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2508 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2509 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2510 /* TESTME HDG: this does not seem right
2511 (it is 2 for all other resolutions) */
2512 sd->sof_len = 10;
2513 break;
2514 case 320: /* 320x240 */
2515 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2516 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2517 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2518 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2519 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2520 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2521 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2522 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2523 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2524 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2525 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2526 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2527 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2528 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2529 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2530 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2531 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2532 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2533 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2534 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2535 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2536 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2537 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2538 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2539 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2540 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2541 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2542 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2543 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2544 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2545 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2546 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2547 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2548 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2549 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2550 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2551 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2552 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2553 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2554 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2555 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2556 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2557 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2558 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2559 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2560 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2561 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2562 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2563 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2564 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2565 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2566 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2567 sd->sof_len = 2;
2568 break;
2569 case 352: /* 352x288 */
2570 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2571 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2572 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2573 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2574 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2575 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2576 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2577 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2578 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2579 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2580 cit_write_reg(gspca_dev, 0x0006, 0x0127);
2581 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2582 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2583 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2584 cit_write_reg(gspca_dev, 0x0002, 0x012f);
2585 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2586 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2587 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2588 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2589 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2590 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2591 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2592 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2593 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2594 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2595 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2596 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2597 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2598 cit_write_reg(gspca_dev, 0x00cf, 0x012e);
2599 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2600 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2601 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2602 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2603 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2604 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2605 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2606 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2607 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2608 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2609 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2610 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2611 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2612 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2613 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2614 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2615 cit_write_reg(gspca_dev, 0x0025, 0x0130);
2616 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2617 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2618 cit_write_reg(gspca_dev, 0x0048, 0x012f);
2619 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2620 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2621 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2622 sd->sof_len = 2;
2623 break;
2624 }
2625
2626 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
2627
Hans de Goede1f33de02010-09-05 16:05:22 -03002628 return 0;
2629}
2630
2631static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2632{
2633 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
Hans de Goede41f424b2010-09-06 05:24:21 -03002634 int i, clock_div;
2635
2636 clock_div = cit_get_clock_div(gspca_dev);
2637 if (clock_div < 0)
2638 return clock_div;
Hans de Goede1f33de02010-09-05 16:05:22 -03002639
2640 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2641 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2642 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2643 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2644 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2645 /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */
2646 cit_write_reg(gspca_dev, 0x0000, 0x0133);
2647 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2648 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2649 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2650 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2651 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2652 /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */
2653
2654 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
2655
2656 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2657 cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */
2658 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2659 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2660 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2661 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2662 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2663 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2664 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2665
2666 switch (gspca_dev->width) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002667 case 160: /* 160x120 */
Hans de Goede1f33de02010-09-05 16:05:22 -03002668 cit_write_reg(gspca_dev, 0x0024, 0x010b);
2669 cit_write_reg(gspca_dev, 0x0089, 0x0119);
2670 cit_write_reg(gspca_dev, 0x000a, 0x011b);
2671 cit_write_reg(gspca_dev, 0x0003, 0x011e);
2672 cit_write_reg(gspca_dev, 0x0007, 0x0104);
2673 cit_write_reg(gspca_dev, 0x0009, 0x011a);
2674 cit_write_reg(gspca_dev, 0x008b, 0x011c);
2675 cit_write_reg(gspca_dev, 0x0008, 0x0118);
2676 cit_write_reg(gspca_dev, 0x0000, 0x0132);
Hans de Goede1f33de02010-09-05 16:05:22 -03002677 break;
Hans de Goede659fefa2010-09-05 16:19:19 -03002678 case 320: /* 320x240 */
Hans de Goede1f33de02010-09-05 16:05:22 -03002679 cit_write_reg(gspca_dev, 0x0028, 0x010b);
2680 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2681 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2682 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2683 cit_write_reg(gspca_dev, 0x000e, 0x0104);
2684 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2685 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2686 cit_write_reg(gspca_dev, 0x000c, 0x0118);
2687 cit_write_reg(gspca_dev, 0x0000, 0x0132);
Hans de Goede1f33de02010-09-05 16:05:22 -03002688 break;
2689 }
2690
2691 cit_model3_Packet1(gspca_dev, 0x0019, 0x0031);
2692 cit_model3_Packet1(gspca_dev, 0x001a, 0x0003);
2693 cit_model3_Packet1(gspca_dev, 0x001b, 0x0038);
2694 cit_model3_Packet1(gspca_dev, 0x001c, 0x0000);
2695 cit_model3_Packet1(gspca_dev, 0x0024, 0x0001);
2696 cit_model3_Packet1(gspca_dev, 0x0027, 0x0001);
2697 cit_model3_Packet1(gspca_dev, 0x002a, 0x0004);
2698 cit_model3_Packet1(gspca_dev, 0x0035, 0x000b);
2699 cit_model3_Packet1(gspca_dev, 0x003f, 0x0001);
2700 cit_model3_Packet1(gspca_dev, 0x0044, 0x0000);
2701 cit_model3_Packet1(gspca_dev, 0x0054, 0x0000);
2702 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000);
2703 cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001);
2704 cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001);
2705 cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000);
2706 cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0);
2707
2708 cit_write_reg(gspca_dev, compression, 0x0109);
2709 cit_write_reg(gspca_dev, clock_div, 0x0111);
2710
2711/* if (sd->input_index) { */
2712 if (rca_input) {
2713 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2714 if (rca_initdata[i][0])
2715 cit_read_reg(gspca_dev, rca_initdata[i][2]);
2716 else
2717 cit_write_reg(gspca_dev, rca_initdata[i][1],
2718 rca_initdata[i][2]);
2719 }
2720 }
2721
2722 return 0;
2723}
2724
2725/* -- start the camera -- */
2726static int sd_start(struct gspca_dev *gspca_dev)
2727{
2728 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1f33de02010-09-05 16:05:22 -03002729 int packet_size;
2730
Hans de Goede659fefa2010-09-05 16:19:19 -03002731 packet_size = cit_get_packet_size(gspca_dev);
2732 if (packet_size < 0)
2733 return packet_size;
2734
Hans de Goede1f33de02010-09-05 16:05:22 -03002735 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002736 case CIT_MODEL0:
2737 cit_start_model0(gspca_dev);
2738 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002739 case CIT_MODEL1:
2740 cit_start_model1(gspca_dev);
2741 break;
2742 case CIT_MODEL2:
2743 cit_start_model2(gspca_dev);
2744 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002745 case CIT_MODEL3:
2746 cit_start_model3(gspca_dev);
2747 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002748 case CIT_MODEL4:
2749 cit_start_model4(gspca_dev);
2750 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002751 case CIT_IBM_NETCAM_PRO:
2752 cit_start_ibm_netcam_pro(gspca_dev);
2753 break;
2754 }
2755
2756 cit_set_brightness(gspca_dev);
2757 cit_set_contrast(gspca_dev);
2758 cit_set_hue(gspca_dev);
2759 cit_set_sharpness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03002760 cit_set_lighting(gspca_dev);
Hans de Goede659fefa2010-09-05 16:19:19 -03002761 cit_set_hflip(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03002762
Hans de Goede659fefa2010-09-05 16:19:19 -03002763 /* Program max isoc packet size */
Hans de Goede1f33de02010-09-05 16:05:22 -03002764 cit_write_reg(gspca_dev, packet_size >> 8, 0x0106);
2765 cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107);
2766
2767 cit_restart_stream(gspca_dev);
2768
2769 return 0;
2770}
2771
Hans de Goedebc46bae2010-10-26 11:18:59 -03002772static int sd_isoc_init(struct gspca_dev *gspca_dev)
2773{
2774 struct usb_host_interface *alt;
2775 int max_packet_size;
2776
2777 switch (gspca_dev->width) {
2778 case 160:
2779 max_packet_size = 450;
2780 break;
2781 case 176:
2782 max_packet_size = 600;
2783 break;
2784 default:
2785 max_packet_size = 1022;
2786 break;
2787 }
2788
2789 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
2790 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
2791 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size);
2792
2793 return 0;
2794}
2795
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002796static int sd_isoc_nego(struct gspca_dev *gspca_dev)
2797{
Hans de Goedebc46bae2010-10-26 11:18:59 -03002798 int ret, packet_size, min_packet_size;
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002799 struct usb_host_interface *alt;
2800
Hans de Goedebc46bae2010-10-26 11:18:59 -03002801 switch (gspca_dev->width) {
2802 case 160:
2803 min_packet_size = 200;
2804 break;
2805 case 176:
2806 min_packet_size = 266;
2807 break;
2808 default:
2809 min_packet_size = 400;
2810 break;
2811 }
2812
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002813 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
2814 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
Hans de Goedebc46bae2010-10-26 11:18:59 -03002815 if (packet_size <= min_packet_size)
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002816 return -EIO;
Hans de Goedebc46bae2010-10-26 11:18:59 -03002817
2818 packet_size -= 100;
2819 if (packet_size < min_packet_size)
2820 packet_size = min_packet_size;
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002821 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
2822
2823 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
2824 if (ret < 0)
Jean-François Moine0b656322010-09-13 05:19:58 -03002825 err("set alt 1 err %d", ret);
Hans de Goede59f8b0b2010-09-05 07:03:48 -03002826
2827 return ret;
2828}
2829
Hans de Goede1f33de02010-09-05 16:05:22 -03002830static void sd_stopN(struct gspca_dev *gspca_dev)
2831{
Hans de Goede59f90a02010-06-09 11:39:50 -03002832 cit_write_reg(gspca_dev, 0x0000, 0x010c);
Hans de Goede1f33de02010-09-05 16:05:22 -03002833}
2834
2835static void sd_stop0(struct gspca_dev *gspca_dev)
2836{
2837 struct sd *sd = (struct sd *) gspca_dev;
2838
2839 /* We cannot use gspca_dev->present here as that is not set when
2840 sd_init gets called and we get called from sd_init */
2841 if (!gspca_dev->dev)
2842 return;
2843
2844 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002845 case CIT_MODEL0:
2846 /* HDG windows does this, but it causes the cams autogain to
2847 restart from a gain of 0, which does not look good when
2848 changing resolutions. */
2849 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2850 cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */
2851 break;
Hans de Goede59f90a02010-06-09 11:39:50 -03002852 case CIT_MODEL1:
2853 cit_send_FF_04_02(gspca_dev);
2854 cit_read_reg(gspca_dev, 0x0100);
2855 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2856 break;
2857 case CIT_MODEL2:
2858 case CIT_MODEL4:
2859 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2860
2861 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
2862 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2863 cit_write_reg(gspca_dev, 0x00a0, 0x0111);
2864
2865 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
2866
2867 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2868 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2869 break;
Hans de Goede1f33de02010-09-05 16:05:22 -03002870 case CIT_MODEL3:
2871 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2872 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
2873 cit_read_reg(gspca_dev, 0x0116);
2874 cit_write_reg(gspca_dev, 0x0064, 0x0116);
2875 cit_read_reg(gspca_dev, 0x0115);
2876 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2877 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2878 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2879 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2880 cit_write_reg(gspca_dev, 0x0080, 0x0100);
2881 break;
2882 case CIT_IBM_NETCAM_PRO:
2883 cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff);
2884 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2885 cit_write_reg(gspca_dev, 0x0000, 0x0116);
2886 /* HDG windows does this, but I cannot get the camera
2887 to restart with this without redoing the entire init
2888 sequence which makes switching modes really slow */
2889 /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */
2890 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2891 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2892 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2893 cit_write_reg(gspca_dev, 0x0000, 0x0111);
2894 /* HDG windows does this, but I get a green picture when
2895 restarting the stream after this */
2896 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2897 cit_write_reg(gspca_dev, 0x00c0, 0x0100);
2898 break;
2899 }
2900}
2901
2902static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2903{
2904 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede659fefa2010-09-05 16:19:19 -03002905 u8 byte3 = 0, byte4 = 0;
Hans de Goede1f33de02010-09-05 16:05:22 -03002906 int i;
2907
2908 switch (sd->model) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002909 case CIT_MODEL0:
Hans de Goede59f90a02010-06-09 11:39:50 -03002910 case CIT_MODEL1:
Hans de Goede1f33de02010-09-05 16:05:22 -03002911 case CIT_MODEL3:
2912 case CIT_IBM_NETCAM_PRO:
Hans de Goede659fefa2010-09-05 16:19:19 -03002913 switch (gspca_dev->width) {
2914 case 160: /* 160x120 */
Hans de Goede59f90a02010-06-09 11:39:50 -03002915 byte3 = 0x02;
Hans de Goede659fefa2010-09-05 16:19:19 -03002916 byte4 = 0x0a;
2917 break;
2918 case 176: /* 176x144 */
2919 byte3 = 0x02;
2920 byte4 = 0x0e;
2921 break;
2922 case 320: /* 320x240 */
2923 byte3 = 0x02;
2924 byte4 = 0x08;
2925 break;
2926 case 352: /* 352x288 */
2927 byte3 = 0x02;
2928 byte4 = 0x00;
2929 break;
2930 case 640:
2931 byte3 = 0x03;
2932 byte4 = 0x08;
2933 break;
2934 }
2935
2936 /* These have a different byte3 */
2937 if (sd->model <= CIT_MODEL1)
2938 byte3 = 0x00;
Hans de Goede59f90a02010-06-09 11:39:50 -03002939
Hans de Goede1f33de02010-09-05 16:05:22 -03002940 for (i = 0; i < len; i++) {
Hans de Goede659fefa2010-09-05 16:19:19 -03002941 /* For this model the SOF always starts at offset 0
2942 so no need to search the entire frame */
2943 if (sd->model == CIT_MODEL0 && sd->sof_read != i)
2944 break;
2945
Hans de Goede1f33de02010-09-05 16:05:22 -03002946 switch (sd->sof_read) {
2947 case 0:
2948 if (data[i] == 0x00)
2949 sd->sof_read++;
2950 break;
2951 case 1:
2952 if (data[i] == 0xff)
2953 sd->sof_read++;
Hans de Goede659fefa2010-09-05 16:19:19 -03002954 else if (data[i] == 0x00)
2955 sd->sof_read = 1;
Hans de Goede1f33de02010-09-05 16:05:22 -03002956 else
2957 sd->sof_read = 0;
2958 break;
2959 case 2:
Hans de Goede659fefa2010-09-05 16:19:19 -03002960 if (data[i] == byte3)
2961 sd->sof_read++;
2962 else if (data[i] == 0x00)
2963 sd->sof_read = 1;
2964 else
2965 sd->sof_read = 0;
2966 break;
2967 case 3:
2968 if (data[i] == byte4) {
2969 sd->sof_read = 0;
2970 return data + i + (sd->sof_len - 3);
Hans de Goede59f90a02010-06-09 11:39:50 -03002971 }
Hans de Goede659fefa2010-09-05 16:19:19 -03002972 if (byte3 == 0x00 && data[i] == 0xff)
2973 sd->sof_read = 2;
2974 else if (data[i] == 0x00)
2975 sd->sof_read = 1;
2976 else
2977 sd->sof_read = 0;
Hans de Goede59f90a02010-06-09 11:39:50 -03002978 break;
2979 }
2980 }
2981 break;
2982 case CIT_MODEL2:
2983 case CIT_MODEL4:
2984 /* TESTME we need to find a longer sof signature to avoid
2985 false positives */
2986 for (i = 0; i < len; i++) {
2987 switch (sd->sof_read) {
2988 case 0:
2989 if (data[i] == 0x00)
2990 sd->sof_read++;
2991 break;
2992 case 1:
2993 sd->sof_read = 0;
2994 if (data[i] == 0xff) {
2995 if (i >= 4)
2996 PDEBUG(D_FRAM,
Hans de Goede659fefa2010-09-05 16:19:19 -03002997 "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n",
2998 i - 1,
Hans de Goede59f90a02010-06-09 11:39:50 -03002999 data[i - 4],
3000 data[i - 3],
3001 data[i],
Hans de Goede659fefa2010-09-05 16:19:19 -03003002 data[i + 1],
3003 data[i + 2]);
3004 else
3005 PDEBUG(D_FRAM,
3006 "header found at offset: %d: 00 %02x %02x %02x\n",
3007 i - 1,
3008 data[i],
3009 data[i + 1],
3010 data[i + 2]);
3011 return data + i + (sd->sof_len - 1);
Hans de Goede1f33de02010-09-05 16:05:22 -03003012 }
3013 break;
3014 }
3015 }
3016 break;
3017 }
3018 return NULL;
3019}
3020
3021static void sd_pkt_scan(struct gspca_dev *gspca_dev,
3022 u8 *data, int len)
3023{
Hans de Goede59f90a02010-06-09 11:39:50 -03003024 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1f33de02010-09-05 16:05:22 -03003025 unsigned char *sof;
3026
3027 sof = cit_find_sof(gspca_dev, data, len);
3028 if (sof) {
3029 int n;
3030
3031 /* finish decoding current frame */
3032 n = sof - data;
Hans de Goede59f90a02010-06-09 11:39:50 -03003033 if (n > sd->sof_len)
3034 n -= sd->sof_len;
Hans de Goede1f33de02010-09-05 16:05:22 -03003035 else
3036 n = 0;
3037 gspca_frame_add(gspca_dev, LAST_PACKET,
3038 data, n);
3039 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
3040 len -= sof - data;
3041 data = sof;
3042 }
3043
3044 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
3045}
3046
3047static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3048{
3049 struct sd *sd = (struct sd *) gspca_dev;
3050
3051 sd->brightness = val;
3052 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003053 if (sd->stop_on_control_change)
3054 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003055 cit_set_brightness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003056 if (sd->stop_on_control_change)
3057 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003058 }
3059
3060 return 0;
3061}
3062
3063static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
3064{
3065 struct sd *sd = (struct sd *) gspca_dev;
3066
3067 *val = sd->brightness;
3068
3069 return 0;
3070}
3071
3072static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3073{
3074 struct sd *sd = (struct sd *) gspca_dev;
3075
3076 sd->contrast = val;
3077 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003078 if (sd->stop_on_control_change)
3079 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003080 cit_set_contrast(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003081 if (sd->stop_on_control_change)
3082 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003083 }
3084
3085 return 0;
3086}
3087
3088static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3089{
3090 struct sd *sd = (struct sd *) gspca_dev;
3091
3092 *val = sd->contrast;
3093
3094 return 0;
3095}
3096
3097static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
3098{
3099 struct sd *sd = (struct sd *) gspca_dev;
3100
3101 sd->hue = val;
3102 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003103 if (sd->stop_on_control_change)
3104 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003105 cit_set_hue(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003106 if (sd->stop_on_control_change)
3107 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003108 }
3109 return 0;
3110}
3111
3112static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
3113{
3114 struct sd *sd = (struct sd *) gspca_dev;
3115
3116 *val = sd->hue;
3117
3118 return 0;
3119}
3120
3121static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
3122{
3123 struct sd *sd = (struct sd *) gspca_dev;
3124
3125 sd->sharpness = val;
3126 if (gspca_dev->streaming) {
Hans de Goede59f90a02010-06-09 11:39:50 -03003127 if (sd->stop_on_control_change)
3128 sd_stopN(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003129 cit_set_sharpness(gspca_dev);
Hans de Goede59f90a02010-06-09 11:39:50 -03003130 if (sd->stop_on_control_change)
3131 cit_restart_stream(gspca_dev);
Hans de Goede1f33de02010-09-05 16:05:22 -03003132 }
3133 return 0;
3134}
3135
3136static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
3137{
3138 struct sd *sd = (struct sd *) gspca_dev;
3139
3140 *val = sd->sharpness;
3141
3142 return 0;
3143}
3144
Hans de Goede59f90a02010-06-09 11:39:50 -03003145static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val)
3146{
3147 struct sd *sd = (struct sd *) gspca_dev;
3148
3149 sd->lighting = val;
3150 if (gspca_dev->streaming) {
3151 if (sd->stop_on_control_change)
3152 sd_stopN(gspca_dev);
3153 cit_set_lighting(gspca_dev);
3154 if (sd->stop_on_control_change)
3155 cit_restart_stream(gspca_dev);
3156 }
3157 return 0;
3158}
3159
3160static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val)
3161{
3162 struct sd *sd = (struct sd *) gspca_dev;
3163
3164 *val = sd->lighting;
3165
3166 return 0;
3167}
3168
Hans de Goede659fefa2010-09-05 16:19:19 -03003169static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3170{
3171 struct sd *sd = (struct sd *) gspca_dev;
3172
3173 sd->hflip = val;
3174 if (gspca_dev->streaming) {
3175 if (sd->stop_on_control_change)
3176 sd_stopN(gspca_dev);
3177 cit_set_hflip(gspca_dev);
3178 if (sd->stop_on_control_change)
3179 cit_restart_stream(gspca_dev);
3180 }
3181 return 0;
3182}
3183
3184static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3185{
3186 struct sd *sd = (struct sd *) gspca_dev;
3187
3188 *val = sd->hflip;
3189
3190 return 0;
3191}
3192
Hans de Goede1f33de02010-09-05 16:05:22 -03003193
3194/* sub-driver description */
3195static const struct sd_desc sd_desc = {
3196 .name = MODULE_NAME,
3197 .ctrls = sd_ctrls,
3198 .nctrls = ARRAY_SIZE(sd_ctrls),
3199 .config = sd_config,
3200 .init = sd_init,
3201 .start = sd_start,
3202 .stopN = sd_stopN,
3203 .stop0 = sd_stop0,
3204 .pkt_scan = sd_pkt_scan,
3205};
3206
Hans de Goede59f8b0b2010-09-05 07:03:48 -03003207static const struct sd_desc sd_desc_isoc_nego = {
3208 .name = MODULE_NAME,
3209 .ctrls = sd_ctrls,
3210 .nctrls = ARRAY_SIZE(sd_ctrls),
3211 .config = sd_config,
3212 .init = sd_init,
3213 .start = sd_start,
Hans de Goedebc46bae2010-10-26 11:18:59 -03003214 .isoc_init = sd_isoc_init,
Hans de Goede59f8b0b2010-09-05 07:03:48 -03003215 .isoc_nego = sd_isoc_nego,
3216 .stopN = sd_stopN,
3217 .stop0 = sd_stop0,
3218 .pkt_scan = sd_pkt_scan,
3219};
3220
Hans de Goede1f33de02010-09-05 16:05:22 -03003221/* -- module initialisation -- */
3222static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede659fefa2010-09-05 16:19:19 -03003223 { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 },
Hans de Goede1f33de02010-09-05 16:05:22 -03003224 { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 },
3225 { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3226 { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 },
3227 { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3228 { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3229 { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3230 {}
3231};
3232MODULE_DEVICE_TABLE(usb, device_table);
3233
3234/* -- device connect -- */
3235static int sd_probe(struct usb_interface *intf,
3236 const struct usb_device_id *id)
3237{
Hans de Goede59f8b0b2010-09-05 07:03:48 -03003238 const struct sd_desc *desc = &sd_desc;
3239
Hans de Goede659fefa2010-09-05 16:19:19 -03003240 switch (id->driver_info) {
3241 case CIT_MODEL0:
3242 case CIT_MODEL1:
3243 if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
3244 return -ENODEV;
3245 break;
3246 case CIT_MODEL2:
Hans de Goede659fefa2010-09-05 16:19:19 -03003247 case CIT_MODEL4:
Hans de Goede659fefa2010-09-05 16:19:19 -03003248 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3249 return -ENODEV;
3250 break;
Hans de Goede59f8b0b2010-09-05 07:03:48 -03003251 case CIT_MODEL3:
3252 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3253 return -ENODEV;
3254 /* FIXME this likely applies to all model3 cams and probably
3255 to other models too. */
3256 if (ibm_netcam_pro)
3257 desc = &sd_desc_isoc_nego;
3258 break;
Hans de Goede659fefa2010-09-05 16:19:19 -03003259 }
3260
Hans de Goede59f8b0b2010-09-05 07:03:48 -03003261 return gspca_dev_probe2(intf, id, desc, sizeof(struct sd), THIS_MODULE);
Hans de Goede1f33de02010-09-05 16:05:22 -03003262}
3263
3264static struct usb_driver sd_driver = {
3265 .name = MODULE_NAME,
3266 .id_table = device_table,
3267 .probe = sd_probe,
3268 .disconnect = gspca_disconnect,
3269#ifdef CONFIG_PM
3270 .suspend = gspca_suspend,
3271 .resume = gspca_resume,
3272#endif
3273};
3274
3275/* -- module insert / remove -- */
3276static int __init sd_mod_init(void)
3277{
Jean-François Moine54826432010-09-13 04:53:03 -03003278 return usb_register(&sd_driver);
Hans de Goede1f33de02010-09-05 16:05:22 -03003279}
3280static void __exit sd_mod_exit(void)
3281{
3282 usb_deregister(&sd_driver);
Hans de Goede1f33de02010-09-05 16:05:22 -03003283}
3284
3285module_init(sd_mod_init);
3286module_exit(sd_mod_exit);