1 /*
2 * USB IBM C-It Video Camera driver
3 *
4 * Supports Xirlink C-It Video Camera, IBM PC Camera,
5 * IBM NetCamera and Veo Stingray.
6 *
7 * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.com>
8 *
9 * This driver is based on earlier work of:
10 *
11 * (C) Copyright 1999 Johannes Erdfelt
12 * (C) Copyright 1999 Randy Dunlap
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
32 #define MODULE_NAME "xirlink-cit"
33
34 #include <linux/input.h>
35 #include "gspca.h"
36
37 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
38 MODULE_DESCRIPTION("Xirlink C-IT");
39 MODULE_LICENSE("GPL");
40
41 /* FIXME we should autodetect this */
42 static int ibm_netcam_pro;
43 module_param(ibm_netcam_pro, int, 0);
44 MODULE_PARM_DESC(ibm_netcam_pro,
45 "Use IBM Netcamera Pro init sequences for Model 3 cams");
46
47 /* FIXME this should be handled through the V4L2 input selection API */
48 static int rca_input;
49 module_param(rca_input, int, 0644);
50 MODULE_PARM_DESC(rca_input,
51 "Use rca input instead of ccd sensor on Model 3 cams");
52
53 /* specific webcam descriptor */
54 struct sd {
55 struct gspca_dev gspca_dev; /* !! must be the first item */
56 u8 model;
57 #define CIT_MODEL0 0 /* bcd version 0.01 cams ie the xvp-500 */
58 #define CIT_MODEL1 1 /* The model 1 - 4 nomenclature comes from the old */
59 #define CIT_MODEL2 2 /* ibmcam driver */
60 #define CIT_MODEL3 3
61 #define CIT_MODEL4 4
62 #define CIT_IBM_NETCAM_PRO 5
63 u8 input_index;
64 u8 button_state;
65 u8 stop_on_control_change;
66 u8 sof_read;
67 u8 sof_len;
68 u8 contrast;
69 u8 brightness;
70 u8 hue;
71 u8 sharpness;
72 u8 lighting;
73 u8 hflip;
74 };
75
76 /* V4L2 controls supported by the driver */
77 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
78 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
79 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
80 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
81 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
82 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
83 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
84 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
85 static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val);
86 static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val);
87 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
88 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
89 static void sd_stop0(struct gspca_dev *gspca_dev);
90
91 static const struct ctrl sd_ctrls[] = {
92 #define SD_BRIGHTNESS 0
93 {
94 {
95 .id = V4L2_CID_BRIGHTNESS,
96 .type = V4L2_CTRL_TYPE_INTEGER,
97 .name = "Brightness",
98 .minimum = 0,
99 .maximum = 63,
100 .step = 1,
101 #define BRIGHTNESS_DEFAULT 32
102 .default_value = BRIGHTNESS_DEFAULT,
103 .flags = 0,
104 },
105 .set = sd_setbrightness,
106 .get = sd_getbrightness,
107 },
108 #define SD_CONTRAST 1
109 {
110 {
111 .id = V4L2_CID_CONTRAST,
112 .type = V4L2_CTRL_TYPE_INTEGER,
113 .name = "contrast",
114 .minimum = 0,
115 .maximum = 20,
116 .step = 1,
117 #define CONTRAST_DEFAULT 10
118 .default_value = CONTRAST_DEFAULT,
119 .flags = 0,
120 },
121 .set = sd_setcontrast,
122 .get = sd_getcontrast,
123 },
124 #define SD_HUE 2
125 {
126 {
127 .id = V4L2_CID_HUE,
128 .type = V4L2_CTRL_TYPE_INTEGER,
129 .name = "Hue",
130 .minimum = 0,
131 .maximum = 127,
132 .step = 1,
133 #define HUE_DEFAULT 63
134 .default_value = HUE_DEFAULT,
135 .flags = 0,
136 },
137 .set = sd_sethue,
138 .get = sd_gethue,
139 },
140 #define SD_SHARPNESS 3
141 {
142 {
143 .id = V4L2_CID_SHARPNESS,
144 .type = V4L2_CTRL_TYPE_INTEGER,
145 .name = "Sharpness",
146 .minimum = 0,
147 .maximum = 6,
148 .step = 1,
149 #define SHARPNESS_DEFAULT 3
150 .default_value = SHARPNESS_DEFAULT,
151 .flags = 0,
152 },
153 .set = sd_setsharpness,
154 .get = sd_getsharpness,
155 },
156 #define SD_LIGHTING 4
157 {
158 {
159 .id = V4L2_CID_BACKLIGHT_COMPENSATION,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "Lighting",
162 .minimum = 0,
163 .maximum = 2,
164 .step = 1,
165 #define LIGHTING_DEFAULT 1
166 .default_value = LIGHTING_DEFAULT,
167 .flags = 0,
168 },
169 .set = sd_setlighting,
170 .get = sd_getlighting,
171 },
172 #define SD_HFLIP 5
173 {
174 {
175 .id = V4L2_CID_HFLIP,
176 .type = V4L2_CTRL_TYPE_BOOLEAN,
177 .name = "Mirror",
178 .minimum = 0,
179 .maximum = 1,
180 .step = 1,
181 #define HFLIP_DEFAULT 0
182 .default_value = HFLIP_DEFAULT,
183 },
184 .set = sd_sethflip,
185 .get = sd_gethflip,
186 },
187 };
188
189 static const struct v4l2_pix_format cif_yuv_mode[] = {
190 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
191 .bytesperline = 176,
192 .sizeimage = 176 * 144 * 3 / 2 + 4,
193 .colorspace = V4L2_COLORSPACE_SRGB},
194 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
195 .bytesperline = 352,
196 .sizeimage = 352 * 288 * 3 / 2 + 4,
197 .colorspace = V4L2_COLORSPACE_SRGB},
198 };
199
200 static const struct v4l2_pix_format vga_yuv_mode[] = {
201 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
202 .bytesperline = 160,
203 .sizeimage = 160 * 120 * 3 / 2 + 4,
204 .colorspace = V4L2_COLORSPACE_SRGB},
205 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
206 .bytesperline = 320,
207 .sizeimage = 320 * 240 * 3 / 2 + 4,
208 .colorspace = V4L2_COLORSPACE_SRGB},
209 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
210 .bytesperline = 640,
211 .sizeimage = 640 * 480 * 3 / 2 + 4,
212 .colorspace = V4L2_COLORSPACE_SRGB},
213 };
214
215 static const struct v4l2_pix_format model0_mode[] = {
216 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
217 .bytesperline = 160,
218 .sizeimage = 160 * 120 * 3 / 2 + 4,
219 .colorspace = V4L2_COLORSPACE_SRGB},
220 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
221 .bytesperline = 176,
222 .sizeimage = 176 * 144 * 3 / 2 + 4,
223 .colorspace = V4L2_COLORSPACE_SRGB},
224 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
225 .bytesperline = 320,
226 .sizeimage = 320 * 240 * 3 / 2 + 4,
227 .colorspace = V4L2_COLORSPACE_SRGB},
228 };
229
230 static const struct v4l2_pix_format model2_mode[] = {
231 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
232 .bytesperline = 160,
233 .sizeimage = 160 * 120 * 3 / 2 + 4,
234 .colorspace = V4L2_COLORSPACE_SRGB},
235 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
236 .bytesperline = 176,
237 .sizeimage = 176 * 144 * 3 / 2 + 4,
238 .colorspace = V4L2_COLORSPACE_SRGB},
239 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
240 .bytesperline = 320,
241 .sizeimage = 320 * 240 + 4,
242 .colorspace = V4L2_COLORSPACE_SRGB},
243 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
244 .bytesperline = 352,
245 .sizeimage = 352 * 288 + 4,
246 .colorspace = V4L2_COLORSPACE_SRGB},
247 };
248
249 /*
250 * 01.01.08 - Added for RCA video in support -LO
251 * This struct is used to init the Model3 cam to use the RCA video in port
252 * instead of the CCD sensor.
253 */
254 static const u16 rca_initdata[][3] = {
255 {0, 0x0000, 0x010c},
256 {0, 0x0006, 0x012c},
257 {0, 0x0078, 0x012d},
258 {0, 0x0046, 0x012f},
259 {0, 0xd141, 0x0124},
260 {0, 0x0000, 0x0127},
261 {0, 0xfea8, 0x0124},
262 {1, 0x0000, 0x0116},
263 {0, 0x0064, 0x0116},
264 {1, 0x0000, 0x0115},
265 {0, 0x0003, 0x0115},
266 {0, 0x0008, 0x0123},
267 {0, 0x0000, 0x0117},
268 {0, 0x0000, 0x0112},
269 {0, 0x0080, 0x0100},
270 {0, 0x0000, 0x0100},
271 {1, 0x0000, 0x0116},
272 {0, 0x0060, 0x0116},
273 {0, 0x0002, 0x0112},
274 {0, 0x0000, 0x0123},
275 {0, 0x0001, 0x0117},
276 {0, 0x0040, 0x0108},
277 {0, 0x0019, 0x012c},
278 {0, 0x0040, 0x0116},
279 {0, 0x000a, 0x0115},
280 {0, 0x000b, 0x0115},
281 {0, 0x0078, 0x012d},
282 {0, 0x0046, 0x012f},
283 {0, 0xd141, 0x0124},
284 {0, 0x0000, 0x0127},
285 {0, 0xfea8, 0x0124},
286 {0, 0x0064, 0x0116},
287 {0, 0x0000, 0x0115},
288 {0, 0x0001, 0x0115},
289 {0, 0xffff, 0x0124},
290 {0, 0xfff9, 0x0124},
291 {0, 0x0086, 0x0127},
292 {0, 0xfff8, 0x0124},
293 {0, 0xfffd, 0x0124},
294 {0, 0x00aa, 0x0127},
295 {0, 0xfff8, 0x0124},
296 {0, 0xfffd, 0x0124},
297 {0, 0x0000, 0x0127},
298 {0, 0xfff8, 0x0124},
299 {0, 0xfffd, 0x0124},
300 {0, 0xfffa, 0x0124},
301 {0, 0xffff, 0x0124},
302 {0, 0xfff9, 0x0124},
303 {0, 0x0086, 0x0127},
304 {0, 0xfff8, 0x0124},
305 {0, 0xfffd, 0x0124},
306 {0, 0x00f2, 0x0127},
307 {0, 0xfff8, 0x0124},
308 {0, 0xfffd, 0x0124},
309 {0, 0x000f, 0x0127},
310 {0, 0xfff8, 0x0124},
311 {0, 0xfffd, 0x0124},
312 {0, 0xfffa, 0x0124},
313 {0, 0xffff, 0x0124},
314 {0, 0xfff9, 0x0124},
315 {0, 0x0086, 0x0127},
316 {0, 0xfff8, 0x0124},
317 {0, 0xfffd, 0x0124},
318 {0, 0x00f8, 0x0127},
319 {0, 0xfff8, 0x0124},
320 {0, 0xfffd, 0x0124},
321 {0, 0x00fc, 0x0127},
322 {0, 0xfff8, 0x0124},
323 {0, 0xfffd, 0x0124},
324 {0, 0xfffa, 0x0124},
325 {0, 0xffff, 0x0124},
326 {0, 0xfff9, 0x0124},
327 {0, 0x0086, 0x0127},
328 {0, 0xfff8, 0x0124},
329 {0, 0xfffd, 0x0124},
330 {0, 0x00f9, 0x0127},
331 {0, 0xfff8, 0x0124},
332 {0, 0xfffd, 0x0124},
333 {0, 0x003c, 0x0127},
334 {0, 0xfff8, 0x0124},
335 {0, 0xfffd, 0x0124},
336 {0, 0xfffa, 0x0124},
337 {0, 0xffff, 0x0124},
338 {0, 0xfff9, 0x0124},
339 {0, 0x0086, 0x0127},
340 {0, 0xfff8, 0x0124},
341 {0, 0xfffd, 0x0124},
342 {0, 0x0027, 0x0127},
343 {0, 0xfff8, 0x0124},
344 {0, 0xfffd, 0x0124},
345 {0, 0x0019, 0x0127},
346 {0, 0xfff8, 0x0124},
347 {0, 0xfffd, 0x0124},
348 {0, 0xfffa, 0x0124},
349 {0, 0xfff9, 0x0124},
350 {0, 0x0086, 0x0127},
351 {0, 0xfff8, 0x0124},
352 {0, 0xfffd, 0x0124},
353 {0, 0x0037, 0x0127},
354 {0, 0xfff8, 0x0124},
355 {0, 0xfffd, 0x0124},
356 {0, 0x0000, 0x0127},
357 {0, 0xfff8, 0x0124},
358 {0, 0xfffd, 0x0124},
359 {0, 0x0021, 0x0127},
360 {0, 0xfff8, 0x0124},
361 {0, 0xfffd, 0x0124},
362 {0, 0xfffa, 0x0124},
363 {0, 0xfff9, 0x0124},
364 {0, 0x0086, 0x0127},
365 {0, 0xfff8, 0x0124},
366 {0, 0xfffd, 0x0124},
367 {0, 0x0038, 0x0127},
368 {0, 0xfff8, 0x0124},
369 {0, 0xfffd, 0x0124},
370 {0, 0x0006, 0x0127},
371 {0, 0xfff8, 0x0124},
372 {0, 0xfffd, 0x0124},
373 {0, 0x0045, 0x0127},
374 {0, 0xfff8, 0x0124},
375 {0, 0xfffd, 0x0124},
376 {0, 0xfffa, 0x0124},
377 {0, 0xfff9, 0x0124},
378 {0, 0x0086, 0x0127},
379 {0, 0xfff8, 0x0124},
380 {0, 0xfffd, 0x0124},
381 {0, 0x0037, 0x0127},
382 {0, 0xfff8, 0x0124},
383 {0, 0xfffd, 0x0124},
384 {0, 0x0001, 0x0127},
385 {0, 0xfff8, 0x0124},
386 {0, 0xfffd, 0x0124},
387 {0, 0x002a, 0x0127},
388 {0, 0xfff8, 0x0124},
389 {0, 0xfffd, 0x0124},
390 {0, 0xfffa, 0x0124},
391 {0, 0xfff9, 0x0124},
392 {0, 0x0086, 0x0127},
393 {0, 0xfff8, 0x0124},
394 {0, 0xfffd, 0x0124},
395 {0, 0x0038, 0x0127},
396 {0, 0xfff8, 0x0124},
397 {0, 0xfffd, 0x0124},
398 {0, 0x0000, 0x0127},
399 {0, 0xfff8, 0x0124},
400 {0, 0xfffd, 0x0124},
401 {0, 0x000e, 0x0127},
402 {0, 0xfff8, 0x0124},
403 {0, 0xfffd, 0x0124},
404 {0, 0xfffa, 0x0124},
405 {0, 0xfff9, 0x0124},
406 {0, 0x0086, 0x0127},
407 {0, 0xfff8, 0x0124},
408 {0, 0xfffd, 0x0124},
409 {0, 0x0037, 0x0127},
410 {0, 0xfff8, 0x0124},
411 {0, 0xfffd, 0x0124},
412 {0, 0x0001, 0x0127},
413 {0, 0xfff8, 0x0124},
414 {0, 0xfffd, 0x0124},
415 {0, 0x002b, 0x0127},
416 {0, 0xfff8, 0x0124},
417 {0, 0xfffd, 0x0124},
418 {0, 0xfffa, 0x0124},
419 {0, 0xfff9, 0x0124},
420 {0, 0x0086, 0x0127},
421 {0, 0xfff8, 0x0124},
422 {0, 0xfffd, 0x0124},
423 {0, 0x0038, 0x0127},
424 {0, 0xfff8, 0x0124},
425 {0, 0xfffd, 0x0124},
426 {0, 0x0001, 0x0127},
427 {0, 0xfff8, 0x0124},
428 {0, 0xfffd, 0x0124},
429 {0, 0x00f4, 0x0127},
430 {0, 0xfff8, 0x0124},
431 {0, 0xfffd, 0x0124},
432 {0, 0xfffa, 0x0124},
433 {0, 0xfff9, 0x0124},
434 {0, 0x0086, 0x0127},
435 {0, 0xfff8, 0x0124},
436 {0, 0xfffd, 0x0124},
437 {0, 0x0037, 0x0127},
438 {0, 0xfff8, 0x0124},
439 {0, 0xfffd, 0x0124},
440 {0, 0x0001, 0x0127},
441 {0, 0xfff8, 0x0124},
442 {0, 0xfffd, 0x0124},
443 {0, 0x002c, 0x0127},
444 {0, 0xfff8, 0x0124},
445 {0, 0xfffd, 0x0124},
446 {0, 0xfffa, 0x0124},
447 {0, 0xfff9, 0x0124},
448 {0, 0x0086, 0x0127},
449 {0, 0xfff8, 0x0124},
450 {0, 0xfffd, 0x0124},
451 {0, 0x0038, 0x0127},
452 {0, 0xfff8, 0x0124},
453 {0, 0xfffd, 0x0124},
454 {0, 0x0001, 0x0127},
455 {0, 0xfff8, 0x0124},
456 {0, 0xfffd, 0x0124},
457 {0, 0x0004, 0x0127},
458 {0, 0xfff8, 0x0124},
459 {0, 0xfffd, 0x0124},
460 {0, 0xfffa, 0x0124},
461 {0, 0xfff9, 0x0124},
462 {0, 0x0086, 0x0127},
463 {0, 0xfff8, 0x0124},
464 {0, 0xfffd, 0x0124},
465 {0, 0x0037, 0x0127},
466 {0, 0xfff8, 0x0124},
467 {0, 0xfffd, 0x0124},
468 {0, 0x0001, 0x0127},
469 {0, 0xfff8, 0x0124},
470 {0, 0xfffd, 0x0124},
471 {0, 0x002d, 0x0127},
472 {0, 0xfff8, 0x0124},
473 {0, 0xfffd, 0x0124},
474 {0, 0xfffa, 0x0124},
475 {0, 0xfff9, 0x0124},
476 {0, 0x0086, 0x0127},
477 {0, 0xfff8, 0x0124},
478 {0, 0xfffd, 0x0124},
479 {0, 0x0038, 0x0127},
480 {0, 0xfff8, 0x0124},
481 {0, 0xfffd, 0x0124},
482 {0, 0x0000, 0x0127},
483 {0, 0xfff8, 0x0124},
484 {0, 0xfffd, 0x0124},
485 {0, 0x0014, 0x0127},
486 {0, 0xfff8, 0x0124},
487 {0, 0xfffd, 0x0124},
488 {0, 0xfffa, 0x0124},
489 {0, 0xfff9, 0x0124},
490 {0, 0x0086, 0x0127},
491 {0, 0xfff8, 0x0124},
492 {0, 0xfffd, 0x0124},
493 {0, 0x0037, 0x0127},
494 {0, 0xfff8, 0x0124},
495 {0, 0xfffd, 0x0124},
496 {0, 0x0001, 0x0127},
497 {0, 0xfff8, 0x0124},
498 {0, 0xfffd, 0x0124},
499 {0, 0x002e, 0x0127},
500 {0, 0xfff8, 0x0124},
501 {0, 0xfffd, 0x0124},
502 {0, 0xfffa, 0x0124},
503 {0, 0xfff9, 0x0124},
504 {0, 0x0086, 0x0127},
505 {0, 0xfff8, 0x0124},
506 {0, 0xfffd, 0x0124},
507 {0, 0x0038, 0x0127},
508 {0, 0xfff8, 0x0124},
509 {0, 0xfffd, 0x0124},
510 {0, 0x0003, 0x0127},
511 {0, 0xfff8, 0x0124},
512 {0, 0xfffd, 0x0124},
513 {0, 0x0000, 0x0127},
514 {0, 0xfff8, 0x0124},
515 {0, 0xfffd, 0x0124},
516 {0, 0xfffa, 0x0124},
517 {0, 0xfff9, 0x0124},
518 {0, 0x0086, 0x0127},
519 {0, 0xfff8, 0x0124},
520 {0, 0xfffd, 0x0124},
521 {0, 0x0037, 0x0127},
522 {0, 0xfff8, 0x0124},
523 {0, 0xfffd, 0x0124},
524 {0, 0x0001, 0x0127},
525 {0, 0xfff8, 0x0124},
526 {0, 0xfffd, 0x0124},
527 {0, 0x002f, 0x0127},
528 {0, 0xfff8, 0x0124},
529 {0, 0xfffd, 0x0124},
530 {0, 0xfffa, 0x0124},
531 {0, 0xfff9, 0x0124},
532 {0, 0x0086, 0x0127},
533 {0, 0xfff8, 0x0124},
534 {0, 0xfffd, 0x0124},
535 {0, 0x0038, 0x0127},
536 {0, 0xfff8, 0x0124},
537 {0, 0xfffd, 0x0124},
538 {0, 0x0003, 0x0127},
539 {0, 0xfff8, 0x0124},
540 {0, 0xfffd, 0x0124},
541 {0, 0x0014, 0x0127},
542 {0, 0xfff8, 0x0124},
543 {0, 0xfffd, 0x0124},
544 {0, 0xfffa, 0x0124},
545 {0, 0xfff9, 0x0124},
546 {0, 0x0086, 0x0127},
547 {0, 0xfff8, 0x0124},
548 {0, 0xfffd, 0x0124},
549 {0, 0x0037, 0x0127},
550 {0, 0xfff8, 0x0124},
551 {0, 0xfffd, 0x0124},
552 {0, 0x0001, 0x0127},
553 {0, 0xfff8, 0x0124},
554 {0, 0xfffd, 0x0124},
555 {0, 0x0040, 0x0127},
556 {0, 0xfff8, 0x0124},
557 {0, 0xfffd, 0x0124},
558 {0, 0xfffa, 0x0124},
559 {0, 0xfff9, 0x0124},
560 {0, 0x0086, 0x0127},
561 {0, 0xfff8, 0x0124},
562 {0, 0xfffd, 0x0124},
563 {0, 0x0038, 0x0127},
564 {0, 0xfff8, 0x0124},
565 {0, 0xfffd, 0x0124},
566 {0, 0x0000, 0x0127},
567 {0, 0xfff8, 0x0124},
568 {0, 0xfffd, 0x0124},
569 {0, 0x0040, 0x0127},
570 {0, 0xfff8, 0x0124},
571 {0, 0xfffd, 0x0124},
572 {0, 0xfffa, 0x0124},
573 {0, 0xfff9, 0x0124},
574 {0, 0x0086, 0x0127},
575 {0, 0xfff8, 0x0124},
576 {0, 0xfffd, 0x0124},
577 {0, 0x0037, 0x0127},
578 {0, 0xfff8, 0x0124},
579 {0, 0xfffd, 0x0124},
580 {0, 0x0001, 0x0127},
581 {0, 0xfff8, 0x0124},
582 {0, 0xfffd, 0x0124},
583 {0, 0x0053, 0x0127},
584 {0, 0xfff8, 0x0124},
585 {0, 0xfffd, 0x0124},
586 {0, 0xfffa, 0x0124},
587 {0, 0xfff9, 0x0124},
588 {0, 0x0086, 0x0127},
589 {0, 0xfff8, 0x0124},
590 {0, 0xfffd, 0x0124},
591 {0, 0x0038, 0x0127},
592 {0, 0xfff8, 0x0124},
593 {0, 0xfffd, 0x0124},
594 {0, 0x0000, 0x0127},
595 {0, 0xfff8, 0x0124},
596 {0, 0xfffd, 0x0124},
597 {0, 0x0038, 0x0127},
598 {0, 0xfff8, 0x0124},
599 {0, 0xfffd, 0x0124},
600 {0, 0xfffa, 0x0124},
601 {0, 0x0000, 0x0101},
602 {0, 0x00a0, 0x0103},
603 {0, 0x0078, 0x0105},
604 {0, 0x0000, 0x010a},
605 {0, 0x0024, 0x010b},
606 {0, 0x0028, 0x0119},
607 {0, 0x0088, 0x011b},
608 {0, 0x0002, 0x011d},
609 {0, 0x0003, 0x011e},
610 {0, 0x0000, 0x0129},
611 {0, 0x00fc, 0x012b},
612 {0, 0x0008, 0x0102},
613 {0, 0x0000, 0x0104},
614 {0, 0x0008, 0x011a},
615 {0, 0x0028, 0x011c},
616 {0, 0x0021, 0x012a},
617 {0, 0x0000, 0x0118},
618 {0, 0x0000, 0x0132},
619 {0, 0x0000, 0x0109},
620 {0, 0xfff9, 0x0124},
621 {0, 0x0086, 0x0127},
622 {0, 0xfff8, 0x0124},
623 {0, 0xfffd, 0x0124},
624 {0, 0x0037, 0x0127},
625 {0, 0xfff8, 0x0124},
626 {0, 0xfffd, 0x0124},
627 {0, 0x0001, 0x0127},
628 {0, 0xfff8, 0x0124},
629 {0, 0xfffd, 0x0124},
630 {0, 0x0031, 0x0127},
631 {0, 0xfff8, 0x0124},
632 {0, 0xfffd, 0x0124},
633 {0, 0xfffa, 0x0124},
634 {0, 0xfff9, 0x0124},
635 {0, 0x0086, 0x0127},
636 {0, 0xfff8, 0x0124},
637 {0, 0xfffd, 0x0124},
638 {0, 0x0038, 0x0127},
639 {0, 0xfff8, 0x0124},
640 {0, 0xfffd, 0x0124},
641 {0, 0x0000, 0x0127},
642 {0, 0xfff8, 0x0124},
643 {0, 0xfffd, 0x0124},
644 {0, 0x0000, 0x0127},
645 {0, 0xfff8, 0x0124},
646 {0, 0xfffd, 0x0124},
647 {0, 0xfffa, 0x0124},
648 {0, 0xfff9, 0x0124},
649 {0, 0x0086, 0x0127},
650 {0, 0xfff8, 0x0124},
651 {0, 0xfffd, 0x0124},
652 {0, 0x0037, 0x0127},
653 {0, 0xfff8, 0x0124},
654 {0, 0xfffd, 0x0124},
655 {0, 0x0001, 0x0127},
656 {0, 0xfff8, 0x0124},
657 {0, 0xfffd, 0x0124},
658 {0, 0x0040, 0x0127},
659 {0, 0xfff8, 0x0124},
660 {0, 0xfffd, 0x0124},
661 {0, 0xfffa, 0x0124},
662 {0, 0xfff9, 0x0124},
663 {0, 0x0086, 0x0127},
664 {0, 0xfff8, 0x0124},
665 {0, 0xfffd, 0x0124},
666 {0, 0x0038, 0x0127},
667 {0, 0xfff8, 0x0124},
668 {0, 0xfffd, 0x0124},
669 {0, 0x0000, 0x0127},
670 {0, 0xfff8, 0x0124},
671 {0, 0xfffd, 0x0124},
672 {0, 0x0040, 0x0127},
673 {0, 0xfff8, 0x0124},
674 {0, 0xfffd, 0x0124},
675 {0, 0xfffa, 0x0124},
676 {0, 0xfff9, 0x0124},
677 {0, 0x0086, 0x0127},
678 {0, 0xfff8, 0x0124},
679 {0, 0xfffd, 0x0124},
680 {0, 0x0037, 0x0127},
681 {0, 0xfff8, 0x0124},
682 {0, 0xfffd, 0x0124},
683 {0, 0x0000, 0x0127},
684 {0, 0xfff8, 0x0124},
685 {0, 0xfffd, 0x0124},
686 {0, 0x00dc, 0x0127},
687 {0, 0xfff8, 0x0124},
688 {0, 0xfffd, 0x0124},
689 {0, 0xfffa, 0x0124},
690 {0, 0xfff9, 0x0124},
691 {0, 0x0086, 0x0127},
692 {0, 0xfff8, 0x0124},
693 {0, 0xfffd, 0x0124},
694 {0, 0x0038, 0x0127},
695 {0, 0xfff8, 0x0124},
696 {0, 0xfffd, 0x0124},
697 {0, 0x0000, 0x0127},
698 {0, 0xfff8, 0x0124},
699 {0, 0xfffd, 0x0124},
700 {0, 0x0000, 0x0127},
701 {0, 0xfff8, 0x0124},
702 {0, 0xfffd, 0x0124},
703 {0, 0xfffa, 0x0124},
704 {0, 0xfff9, 0x0124},
705 {0, 0x0086, 0x0127},
706 {0, 0xfff8, 0x0124},
707 {0, 0xfffd, 0x0124},
708 {0, 0x0037, 0x0127},
709 {0, 0xfff8, 0x0124},
710 {0, 0xfffd, 0x0124},
711 {0, 0x0001, 0x0127},
712 {0, 0xfff8, 0x0124},
713 {0, 0xfffd, 0x0124},
714 {0, 0x0032, 0x0127},
715 {0, 0xfff8, 0x0124},
716 {0, 0xfffd, 0x0124},
717 {0, 0xfffa, 0x0124},
718 {0, 0xfff9, 0x0124},
719 {0, 0x0086, 0x0127},
720 {0, 0xfff8, 0x0124},
721 {0, 0xfffd, 0x0124},
722 {0, 0x0038, 0x0127},
723 {0, 0xfff8, 0x0124},
724 {0, 0xfffd, 0x0124},
725 {0, 0x0001, 0x0127},
726 {0, 0xfff8, 0x0124},
727 {0, 0xfffd, 0x0124},
728 {0, 0x0020, 0x0127},
729 {0, 0xfff8, 0x0124},
730 {0, 0xfffd, 0x0124},
731 {0, 0xfffa, 0x0124},
732 {0, 0xfff9, 0x0124},
733 {0, 0x0086, 0x0127},
734 {0, 0xfff8, 0x0124},
735 {0, 0xfffd, 0x0124},
736 {0, 0x0037, 0x0127},
737 {0, 0xfff8, 0x0124},
738 {0, 0xfffd, 0x0124},
739 {0, 0x0001, 0x0127},
740 {0, 0xfff8, 0x0124},
741 {0, 0xfffd, 0x0124},
742 {0, 0x0040, 0x0127},
743 {0, 0xfff8, 0x0124},
744 {0, 0xfffd, 0x0124},
745 {0, 0xfffa, 0x0124},
746 {0, 0xfff9, 0x0124},
747 {0, 0x0086, 0x0127},
748 {0, 0xfff8, 0x0124},
749 {0, 0xfffd, 0x0124},
750 {0, 0x0038, 0x0127},
751 {0, 0xfff8, 0x0124},
752 {0, 0xfffd, 0x0124},
753 {0, 0x0000, 0x0127},
754 {0, 0xfff8, 0x0124},
755 {0, 0xfffd, 0x0124},
756 {0, 0x0040, 0x0127},
757 {0, 0xfff8, 0x0124},
758 {0, 0xfffd, 0x0124},
759 {0, 0xfffa, 0x0124},
760 {0, 0xfff9, 0x0124},
761 {0, 0x0086, 0x0127},
762 {0, 0xfff8, 0x0124},
763 {0, 0xfffd, 0x0124},
764 {0, 0x0037, 0x0127},
765 {0, 0xfff8, 0x0124},
766 {0, 0xfffd, 0x0124},
767 {0, 0x0000, 0x0127},
768 {0, 0xfff8, 0x0124},
769 {0, 0xfffd, 0x0124},
770 {0, 0x0030, 0x0127},
771 {0, 0xfff8, 0x0124},
772 {0, 0xfffd, 0x0124},
773 {0, 0xfffa, 0x0124},
774 {0, 0xfff9, 0x0124},
775 {0, 0x0086, 0x0127},
776 {0, 0xfff8, 0x0124},
777 {0, 0xfffd, 0x0124},
778 {0, 0x0038, 0x0127},
779 {0, 0xfff8, 0x0124},
780 {0, 0xfffd, 0x0124},
781 {0, 0x0008, 0x0127},
782 {0, 0xfff8, 0x0124},
783 {0, 0xfffd, 0x0124},
784 {0, 0x0000, 0x0127},
785 {0, 0xfff8, 0x0124},
786 {0, 0xfffd, 0x0124},
787 {0, 0xfffa, 0x0124},
788 {0, 0x0003, 0x0111},
789 };
790
791 /* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we
792 do the same for now (testing needed to see if this is really necessary) */
793 static const int cit_model1_ntries = 5;
794 static const int cit_model1_ntries2 = 2;
795
cit_write_reg(struct gspca_dev * gspca_dev,u16 value,u16 index)796 static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
797 {
798 struct usb_device *udev = gspca_dev->dev;
799 int err;
800
801 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
802 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
803 value, index, NULL, 0, 1000);
804 if (err < 0)
805 pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
806 index, value, err);
807
808 return 0;
809 }
810
cit_read_reg(struct gspca_dev * gspca_dev,u16 index,int verbose)811 static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose)
812 {
813 struct usb_device *udev = gspca_dev->dev;
814 __u8 *buf = gspca_dev->usb_buf;
815 int res;
816
817 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01,
818 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
819 0x00, index, buf, 8, 1000);
820 if (res < 0) {
821 pr_err("Failed to read a register (index 0x%04X, error %d)\n",
822 index, res);
823 return res;
824 }
825
826 if (verbose)
827 PDEBUG(D_PROBE, "Register %04x value: %02x", index, buf[0]);
828
829 return 0;
830 }
831
832 /*
833 * cit_send_FF_04_02()
834 *
835 * This procedure sends magic 3-command prefix to the camera.
836 * The purpose of this prefix is not known.
837 *
838 * History:
839 * 1/2/00 Created.
840 */
cit_send_FF_04_02(struct gspca_dev * gspca_dev)841 static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
842 {
843 cit_write_reg(gspca_dev, 0x00FF, 0x0127);
844 cit_write_reg(gspca_dev, 0x0004, 0x0124);
845 cit_write_reg(gspca_dev, 0x0002, 0x0124);
846 }
847
cit_send_00_04_06(struct gspca_dev * gspca_dev)848 static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
849 {
850 cit_write_reg(gspca_dev, 0x0000, 0x0127);
851 cit_write_reg(gspca_dev, 0x0004, 0x0124);
852 cit_write_reg(gspca_dev, 0x0006, 0x0124);
853 }
854
cit_send_x_00(struct gspca_dev * gspca_dev,unsigned short x)855 static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
856 {
857 cit_write_reg(gspca_dev, x, 0x0127);
858 cit_write_reg(gspca_dev, 0x0000, 0x0124);
859 }
860
cit_send_x_00_05(struct gspca_dev * gspca_dev,unsigned short x)861 static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
862 {
863 cit_send_x_00(gspca_dev, x);
864 cit_write_reg(gspca_dev, 0x0005, 0x0124);
865 }
866
cit_send_x_00_05_02(struct gspca_dev * gspca_dev,unsigned short x)867 static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
868 {
869 cit_write_reg(gspca_dev, x, 0x0127);
870 cit_write_reg(gspca_dev, 0x0000, 0x0124);
871 cit_write_reg(gspca_dev, 0x0005, 0x0124);
872 cit_write_reg(gspca_dev, 0x0002, 0x0124);
873 }
874
cit_send_x_01_00_05(struct gspca_dev * gspca_dev,u16 x)875 static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
876 {
877 cit_write_reg(gspca_dev, x, 0x0127);
878 cit_write_reg(gspca_dev, 0x0001, 0x0124);
879 cit_write_reg(gspca_dev, 0x0000, 0x0124);
880 cit_write_reg(gspca_dev, 0x0005, 0x0124);
881 }
882
cit_send_x_00_05_02_01(struct gspca_dev * gspca_dev,u16 x)883 static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
884 {
885 cit_write_reg(gspca_dev, x, 0x0127);
886 cit_write_reg(gspca_dev, 0x0000, 0x0124);
887 cit_write_reg(gspca_dev, 0x0005, 0x0124);
888 cit_write_reg(gspca_dev, 0x0002, 0x0124);
889 cit_write_reg(gspca_dev, 0x0001, 0x0124);
890 }
891
cit_send_x_00_05_02_08_01(struct gspca_dev * gspca_dev,u16 x)892 static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
893 {
894 cit_write_reg(gspca_dev, x, 0x0127);
895 cit_write_reg(gspca_dev, 0x0000, 0x0124);
896 cit_write_reg(gspca_dev, 0x0005, 0x0124);
897 cit_write_reg(gspca_dev, 0x0002, 0x0124);
898 cit_write_reg(gspca_dev, 0x0008, 0x0124);
899 cit_write_reg(gspca_dev, 0x0001, 0x0124);
900 }
901
cit_Packet_Format1(struct gspca_dev * gspca_dev,u16 fkey,u16 val)902 static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
903 {
904 cit_send_x_01_00_05(gspca_dev, 0x0088);
905 cit_send_x_00_05(gspca_dev, fkey);
906 cit_send_x_00_05_02_08_01(gspca_dev, val);
907 cit_send_x_00_05(gspca_dev, 0x0088);
908 cit_send_x_00_05_02_01(gspca_dev, fkey);
909 cit_send_x_00_05(gspca_dev, 0x0089);
910 cit_send_x_00(gspca_dev, fkey);
911 cit_send_00_04_06(gspca_dev);
912 cit_read_reg(gspca_dev, 0x0126, 0);
913 cit_send_FF_04_02(gspca_dev);
914 }
915
cit_PacketFormat2(struct gspca_dev * gspca_dev,u16 fkey,u16 val)916 static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
917 {
918 cit_send_x_01_00_05(gspca_dev, 0x0088);
919 cit_send_x_00_05(gspca_dev, fkey);
920 cit_send_x_00_05_02(gspca_dev, val);
921 }
922
cit_model2_Packet2(struct gspca_dev * gspca_dev)923 static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
924 {
925 cit_write_reg(gspca_dev, 0x00ff, 0x012d);
926 cit_write_reg(gspca_dev, 0xfea3, 0x0124);
927 }
928
cit_model2_Packet1(struct gspca_dev * gspca_dev,u16 v1,u16 v2)929 static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
930 {
931 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
932 cit_write_reg(gspca_dev, 0x00ff, 0x012e);
933 cit_write_reg(gspca_dev, v1, 0x012f);
934 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
935 cit_write_reg(gspca_dev, 0xc719, 0x0124);
936 cit_write_reg(gspca_dev, v2, 0x0127);
937
938 cit_model2_Packet2(gspca_dev);
939 }
940
941 /*
942 * cit_model3_Packet1()
943 *
944 * 00_0078_012d
945 * 00_0097_012f
946 * 00_d141_0124
947 * 00_0096_0127
948 * 00_fea8_0124
949 */
cit_model3_Packet1(struct gspca_dev * gspca_dev,u16 v1,u16 v2)950 static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
951 {
952 cit_write_reg(gspca_dev, 0x0078, 0x012d);
953 cit_write_reg(gspca_dev, v1, 0x012f);
954 cit_write_reg(gspca_dev, 0xd141, 0x0124);
955 cit_write_reg(gspca_dev, v2, 0x0127);
956 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
957 }
958
cit_model4_Packet1(struct gspca_dev * gspca_dev,u16 v1,u16 v2)959 static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
960 {
961 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
962 cit_write_reg(gspca_dev, v1, 0x012f);
963 cit_write_reg(gspca_dev, 0xd141, 0x0124);
964 cit_write_reg(gspca_dev, v2, 0x0127);
965 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
966 }
967
cit_model4_BrightnessPacket(struct gspca_dev * gspca_dev,u16 val)968 static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
969 {
970 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
971 cit_write_reg(gspca_dev, 0x0026, 0x012f);
972 cit_write_reg(gspca_dev, 0xd141, 0x0124);
973 cit_write_reg(gspca_dev, val, 0x0127);
974 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
975 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
976 cit_write_reg(gspca_dev, 0x0038, 0x012d);
977 cit_write_reg(gspca_dev, 0x0004, 0x012f);
978 cit_write_reg(gspca_dev, 0xd145, 0x0124);
979 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
980 }
981
982 /* this function is called at probe time */
sd_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)983 static int sd_config(struct gspca_dev *gspca_dev,
984 const struct usb_device_id *id)
985 {
986 struct sd *sd = (struct sd *) gspca_dev;
987 struct cam *cam;
988
989 sd->model = id->driver_info;
990 if (sd->model == CIT_MODEL3 && ibm_netcam_pro)
991 sd->model = CIT_IBM_NETCAM_PRO;
992
993 cam = &gspca_dev->cam;
994 switch (sd->model) {
995 case CIT_MODEL0:
996 cam->cam_mode = model0_mode;
997 cam->nmodes = ARRAY_SIZE(model0_mode);
998 gspca_dev->ctrl_dis = ~((1 << SD_CONTRAST) | (1 << SD_HFLIP));
999 sd->sof_len = 4;
1000 break;
1001 case CIT_MODEL1:
1002 cam->cam_mode = cif_yuv_mode;
1003 cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
1004 gspca_dev->ctrl_dis = (1 << SD_HUE) | (1 << SD_HFLIP);
1005 sd->sof_len = 4;
1006 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) |
1011 (1 << SD_SHARPNESS) |
1012 (1 << SD_HFLIP);
1013 break;
1014 case CIT_MODEL3:
1015 cam->cam_mode = vga_yuv_mode;
1016 cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
1017 gspca_dev->ctrl_dis = (1 << SD_HUE) |
1018 (1 << SD_LIGHTING) |
1019 (1 << SD_HFLIP);
1020 sd->stop_on_control_change = 1;
1021 sd->sof_len = 4;
1022 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) |
1028 (1 << SD_LIGHTING) |
1029 (1 << SD_HFLIP);
1030 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);
1036 sd->stop_on_control_change = 1;
1037 sd->sof_len = 4;
1038 break;
1039 }
1040
1041 sd->brightness = BRIGHTNESS_DEFAULT;
1042 sd->contrast = CONTRAST_DEFAULT;
1043 sd->hue = HUE_DEFAULT;
1044 sd->sharpness = SHARPNESS_DEFAULT;
1045 sd->lighting = LIGHTING_DEFAULT;
1046 sd->hflip = HFLIP_DEFAULT;
1047
1048 return 0;
1049 }
1050
cit_init_model0(struct gspca_dev * gspca_dev)1051 static 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);
1071
1072 return 0;
1073 }
1074
cit_init_ibm_netcam_pro(struct gspca_dev * gspca_dev)1075 static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1076 {
1077 cit_read_reg(gspca_dev, 0x128, 1);
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, 0);
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, 1);
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 */
sd_init(struct gspca_dev * gspca_dev)1268 static int sd_init(struct gspca_dev *gspca_dev)
1269 {
1270 struct sd *sd = (struct sd *) gspca_dev;
1271
1272 switch (sd->model) {
1273 case CIT_MODEL0:
1274 cit_init_model0(gspca_dev);
1275 sd_stop0(gspca_dev);
1276 break;
1277 case CIT_MODEL1:
1278 case CIT_MODEL2:
1279 case CIT_MODEL3:
1280 case CIT_MODEL4:
1281 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
cit_set_brightness(struct gspca_dev * gspca_dev)1290 static int cit_set_brightness(struct gspca_dev *gspca_dev)
1291 {
1292 struct sd *sd = (struct sd *) gspca_dev;
1293 int i;
1294
1295 switch (sd->model) {
1296 case CIT_MODEL0:
1297 case CIT_IBM_NETCAM_PRO:
1298 /* No (known) brightness control for these */
1299 break;
1300 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;
1312 case CIT_MODEL3:
1313 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
1314 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);
1324 break;
1325 }
1326
1327 return 0;
1328 }
1329
cit_set_contrast(struct gspca_dev * gspca_dev)1330 static int cit_set_contrast(struct gspca_dev *gspca_dev)
1331 {
1332 struct sd *sd = (struct sd *) gspca_dev;
1333
1334 switch (sd->model) {
1335 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;
1355 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 }
1365 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
cit_set_hue(struct gspca_dev * gspca_dev)1393 static int cit_set_hue(struct gspca_dev *gspca_dev)
1394 {
1395 struct sd *sd = (struct sd *) gspca_dev;
1396
1397 switch (sd->model) {
1398 case CIT_MODEL0:
1399 case CIT_MODEL1:
1400 case CIT_IBM_NETCAM_PRO:
1401 /* No hue control for these models */
1402 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);
1440 break;
1441 }
1442 return 0;
1443 }
1444
cit_set_sharpness(struct gspca_dev * gspca_dev)1445 static int cit_set_sharpness(struct gspca_dev *gspca_dev)
1446 {
1447 struct sd *sd = (struct sd *) gspca_dev;
1448
1449 switch (sd->model) {
1450 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;
1456 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 }
1465 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 }
1491 }
1492 return 0;
1493 }
1494
1495 /*
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 */
cit_set_lighting(struct gspca_dev * gspca_dev)1513 static void cit_set_lighting(struct gspca_dev *gspca_dev)
1514 {
1515 struct sd *sd = (struct sd *) gspca_dev;
1516
1517 switch (sd->model) {
1518 case CIT_MODEL0:
1519 case CIT_MODEL2:
1520 case CIT_MODEL3:
1521 case CIT_MODEL4:
1522 case CIT_IBM_NETCAM_PRO:
1523 break;
1524 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 }
1530 }
1531 }
1532
cit_set_hflip(struct gspca_dev * gspca_dev)1533 static 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:
1545 case CIT_MODEL2:
1546 case CIT_MODEL3:
1547 case CIT_MODEL4:
1548 case CIT_IBM_NETCAM_PRO:
1549 break;
1550 }
1551 }
1552
cit_restart_stream(struct gspca_dev * gspca_dev)1553 static int cit_restart_stream(struct gspca_dev *gspca_dev)
1554 {
1555 struct sd *sd = (struct sd *) gspca_dev;
1556
1557 switch (sd->model) {
1558 case CIT_MODEL0:
1559 case CIT_MODEL1:
1560 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1561 /* Fall through */
1562 case CIT_MODEL2:
1563 case CIT_MODEL4:
1564 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1565 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1566 break;
1567 case CIT_MODEL3:
1568 case CIT_IBM_NETCAM_PRO:
1569 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1570 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1571 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1572 /* Clear button events from while we were not streaming */
1573 cit_write_reg(gspca_dev, 0x0001, 0x0113);
1574 break;
1575 }
1576
1577 sd->sof_read = 0;
1578
1579 return 0;
1580 }
1581
cit_get_packet_size(struct gspca_dev * gspca_dev)1582 static int cit_get_packet_size(struct gspca_dev *gspca_dev)
1583 {
1584 struct usb_host_interface *alt;
1585 struct usb_interface *intf;
1586
1587 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
1588 alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
1589 if (!alt) {
1590 pr_err("Couldn't get altsetting\n");
1591 return -EIO;
1592 }
1593
1594 return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
1595 }
1596
1597 /* Calculate the clockdiv giving us max fps given the available bandwidth */
cit_get_clock_div(struct gspca_dev * gspca_dev)1598 static int cit_get_clock_div(struct gspca_dev *gspca_dev)
1599 {
1600 int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */
1601 int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 };
1602 int packet_size;
1603
1604 packet_size = cit_get_packet_size(gspca_dev);
1605 if (packet_size < 0)
1606 return packet_size;
1607
1608 while (clock_div > 3 &&
1609 1000 * packet_size >
1610 gspca_dev->width * gspca_dev->height *
1611 fps[clock_div - 1] * 3 / 2)
1612 clock_div--;
1613
1614 PDEBUG(D_PROBE,
1615 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)",
1616 packet_size, gspca_dev->width, gspca_dev->height, clock_div,
1617 fps[clock_div]);
1618
1619 return clock_div;
1620 }
1621
cit_start_model0(struct gspca_dev * gspca_dev)1622 static int cit_start_model0(struct gspca_dev *gspca_dev)
1623 {
1624 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1625 int clock_div;
1626
1627 clock_div = cit_get_clock_div(gspca_dev);
1628 if (clock_div < 0)
1629 return clock_div;
1630
1631 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1632 cit_write_reg(gspca_dev, 0x0003, 0x0438);
1633 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1634 cit_write_reg(gspca_dev, 0x0041, 0x042c);
1635 cit_write_reg(gspca_dev, 0x0008, 0x0436);
1636 cit_write_reg(gspca_dev, 0x0024, 0x0403);
1637 cit_write_reg(gspca_dev, 0x002c, 0x0404);
1638 cit_write_reg(gspca_dev, 0x0002, 0x0426);
1639 cit_write_reg(gspca_dev, 0x0014, 0x0427);
1640
1641 switch (gspca_dev->width) {
1642 case 160: /* 160x120 */
1643 cit_write_reg(gspca_dev, 0x0004, 0x010b);
1644 cit_write_reg(gspca_dev, 0x0001, 0x010a);
1645 cit_write_reg(gspca_dev, 0x0010, 0x0102);
1646 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1647 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1648 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1649 break;
1650
1651 case 176: /* 176x144 */
1652 cit_write_reg(gspca_dev, 0x0006, 0x010b);
1653 cit_write_reg(gspca_dev, 0x0000, 0x010a);
1654 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1655 cit_write_reg(gspca_dev, 0x00b0, 0x0103);
1656 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1657 cit_write_reg(gspca_dev, 0x0090, 0x0105);
1658 break;
1659
1660 case 320: /* 320x240 */
1661 cit_write_reg(gspca_dev, 0x0008, 0x010b);
1662 cit_write_reg(gspca_dev, 0x0004, 0x010a);
1663 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1664 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1665 cit_write_reg(gspca_dev, 0x0010, 0x0104);
1666 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1667 break;
1668 }
1669
1670 cit_write_reg(gspca_dev, compression, 0x0109);
1671 cit_write_reg(gspca_dev, clock_div, 0x0111);
1672
1673 return 0;
1674 }
1675
cit_start_model1(struct gspca_dev * gspca_dev)1676 static int cit_start_model1(struct gspca_dev *gspca_dev)
1677 {
1678 struct sd *sd = (struct sd *) gspca_dev;
1679 int i, clock_div;
1680
1681 clock_div = cit_get_clock_div(gspca_dev);
1682 if (clock_div < 0)
1683 return clock_div;
1684
1685 cit_read_reg(gspca_dev, 0x0128, 1);
1686 cit_read_reg(gspca_dev, 0x0100, 0);
1687 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1688 cit_read_reg(gspca_dev, 0x0100, 0);
1689 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1690 cit_read_reg(gspca_dev, 0x0100, 0);
1691 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1692 cit_write_reg(gspca_dev, 0x01, 0x0108);
1693
1694 cit_write_reg(gspca_dev, 0x03, 0x0112);
1695 cit_read_reg(gspca_dev, 0x0115, 0);
1696 cit_write_reg(gspca_dev, 0x06, 0x0115);
1697 cit_read_reg(gspca_dev, 0x0116, 0);
1698 cit_write_reg(gspca_dev, 0x44, 0x0116);
1699 cit_read_reg(gspca_dev, 0x0116, 0);
1700 cit_write_reg(gspca_dev, 0x40, 0x0116);
1701 cit_read_reg(gspca_dev, 0x0115, 0);
1702 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1703 cit_write_reg(gspca_dev, 0x19, 0x012c);
1704
1705 cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
1706 cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
1707 cit_Packet_Format1(gspca_dev, 0x39, 0x09);
1708 cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
1709 cit_Packet_Format1(gspca_dev, 0x28, 0x22);
1710 cit_Packet_Format1(gspca_dev, 0x27, 0x00);
1711 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1712 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1713
1714 for (i = 0; i < cit_model1_ntries; i++)
1715 cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
1716
1717 for (i = 0; i < cit_model1_ntries; i++)
1718 cit_Packet_Format1(gspca_dev, 0x30, 0x14);
1719
1720 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1721 cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
1722 cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
1723 cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
1724 cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
1725 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1726 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1727
1728 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1729 cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
1730 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
1731 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
1732 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
1733 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
1734 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
1735 cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
1736 cit_PacketFormat2(gspca_dev, 0x11, 0xba);
1737 cit_PacketFormat2(gspca_dev, 0x12, 0x53);
1738 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1739 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1740
1741 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1742 cit_PacketFormat2(gspca_dev, 0x16, 0x00);
1743 cit_PacketFormat2(gspca_dev, 0x17, 0x28);
1744 cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
1745 cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
1746 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1747 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1748
1749 for (i = 0; i < cit_model1_ntries; i++)
1750 cit_Packet_Format1(gspca_dev, 0x00, 0x18);
1751 for (i = 0; i < cit_model1_ntries; i++)
1752 cit_Packet_Format1(gspca_dev, 0x13, 0x18);
1753 for (i = 0; i < cit_model1_ntries; i++)
1754 cit_Packet_Format1(gspca_dev, 0x14, 0x06);
1755
1756 /* TESTME These are handled through controls
1757 KEEP until someone can test leaving this out is ok */
1758 if (0) {
1759 /* This is default brightness */
1760 for (i = 0; i < cit_model1_ntries; i++)
1761 cit_Packet_Format1(gspca_dev, 0x31, 0x37);
1762 for (i = 0; i < cit_model1_ntries; i++)
1763 cit_Packet_Format1(gspca_dev, 0x32, 0x46);
1764 for (i = 0; i < cit_model1_ntries; i++)
1765 cit_Packet_Format1(gspca_dev, 0x33, 0x55);
1766 }
1767
1768 cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
1769 for (i = 0; i < cit_model1_ntries; i++)
1770 cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
1771 for (i = 0; i < cit_model1_ntries; i++)
1772 cit_Packet_Format1(gspca_dev, 0x29, 0x80);
1773 cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
1774 cit_Packet_Format1(gspca_dev, 0x30, 0x17);
1775 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1776 for (i = 0; i < cit_model1_ntries; i++)
1777 cit_Packet_Format1(gspca_dev, 0x34, 0x00);
1778
1779 cit_write_reg(gspca_dev, 0x00, 0x0101);
1780 cit_write_reg(gspca_dev, 0x00, 0x010a);
1781
1782 switch (gspca_dev->width) {
1783 case 128: /* 128x96 */
1784 cit_write_reg(gspca_dev, 0x80, 0x0103);
1785 cit_write_reg(gspca_dev, 0x60, 0x0105);
1786 cit_write_reg(gspca_dev, 0x0c, 0x010b);
1787 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1788 cit_write_reg(gspca_dev, 0x0b, 0x011d);
1789 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1790 cit_write_reg(gspca_dev, 0x00, 0x0129);
1791 break;
1792 case 176: /* 176x144 */
1793 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1794 cit_write_reg(gspca_dev, 0x8f, 0x0105);
1795 cit_write_reg(gspca_dev, 0x06, 0x010b);
1796 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1797 cit_write_reg(gspca_dev, 0x0d, 0x011d);
1798 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1799 cit_write_reg(gspca_dev, 0x03, 0x0129);
1800 break;
1801 case 352: /* 352x288 */
1802 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1803 cit_write_reg(gspca_dev, 0x90, 0x0105);
1804 cit_write_reg(gspca_dev, 0x02, 0x010b);
1805 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1806 cit_write_reg(gspca_dev, 0x05, 0x011d);
1807 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1808 cit_write_reg(gspca_dev, 0x00, 0x0129);
1809 break;
1810 }
1811
1812 cit_write_reg(gspca_dev, 0xff, 0x012b);
1813
1814 /* TESTME These are handled through controls
1815 KEEP until someone can test leaving this out is ok */
1816 if (0) {
1817 /* This is another brightness - don't know why */
1818 for (i = 0; i < cit_model1_ntries; i++)
1819 cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
1820 for (i = 0; i < cit_model1_ntries; i++)
1821 cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
1822 for (i = 0; i < cit_model1_ntries; i++)
1823 cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
1824
1825 /* Default contrast */
1826 for (i = 0; i < cit_model1_ntries; i++)
1827 cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
1828
1829 /* Default sharpness */
1830 for (i = 0; i < cit_model1_ntries2; i++)
1831 cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
1832
1833 /* Default lighting conditions */
1834 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1835 }
1836
1837 /* Assorted init */
1838 switch (gspca_dev->width) {
1839 case 128: /* 128x96 */
1840 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1841 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1842 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1843 cit_write_reg(gspca_dev, 0x36, 0x0102);
1844 cit_write_reg(gspca_dev, 0x1a, 0x0104);
1845 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1846 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1847 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1848 break;
1849 case 176: /* 176x144 */
1850 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1851 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1852 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1853 cit_write_reg(gspca_dev, 0x04, 0x0102);
1854 cit_write_reg(gspca_dev, 0x02, 0x0104);
1855 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1856 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1857 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1858 break;
1859 case 352: /* 352x288 */
1860 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1861 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1862 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1863 cit_write_reg(gspca_dev, 0x08, 0x0102);
1864 cit_write_reg(gspca_dev, 0x01, 0x0104);
1865 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1866 cit_write_reg(gspca_dev, 0x2f, 0x011c);
1867 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1868 break;
1869 }
1870
1871 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1872 cit_write_reg(gspca_dev, clock_div, 0x0111);
1873
1874 return 0;
1875 }
1876
cit_start_model2(struct gspca_dev * gspca_dev)1877 static int cit_start_model2(struct gspca_dev *gspca_dev)
1878 {
1879 struct sd *sd = (struct sd *) gspca_dev;
1880 int clock_div = 0;
1881
1882 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1883 cit_read_reg(gspca_dev, 0x0116, 0);
1884 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1885 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1886 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
1887 cit_write_reg(gspca_dev, 0x0008, 0x012b);
1888 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1889 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1890 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1891 switch (gspca_dev->width) {
1892 case 176: /* 176x144 */
1893 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1894 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1895 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1896 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
1897 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
1898 /* TESTME HDG: this does not seem right
1899 (it is 2 for all other resolutions) */
1900 sd->sof_len = 10;
1901 break;
1902 case 320: /* 320x240 */
1903 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
1904 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1905 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1906 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1907 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1908 sd->sof_len = 2;
1909 break;
1910 /* case VIDEOSIZE_352x240: */
1911 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1912 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1913 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1914 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1915 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1916 sd->sof_len = 2;
1917 break;
1918 case 352: /* 352x288 */
1919 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1920 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1921 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1922 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1923 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1924 sd->sof_len = 2;
1925 break;
1926 }
1927
1928 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1929
1930 switch (gspca_dev->width) {
1931 case 176: /* 176x144 */
1932 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1933 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
1934 break;
1935 case 320: /* 320x240 */
1936 case 352: /* 352x288 */
1937 cit_write_reg(gspca_dev, 0x0040, 0x0111);
1938 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
1939 break;
1940 }
1941 cit_write_reg(gspca_dev, 0x009b, 0x010f);
1942 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
1943
1944 /*
1945 * Hardware settings, may affect CMOS sensor; not user controls!
1946 * -------------------------------------------------------------
1947 * 0x0004: no effect
1948 * 0x0006: hardware effect
1949 * 0x0008: no effect
1950 * 0x000a: stops video stream, probably important h/w setting
1951 * 0x000c: changes color in hardware manner (not user setting)
1952 * 0x0012: changes number of colors (does not affect speed)
1953 * 0x002a: no effect
1954 * 0x002c: hardware setting (related to scan lines)
1955 * 0x002e: stops video stream, probably important h/w setting
1956 */
1957 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
1958 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
1959 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
1960 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
1961 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
1962 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
1963 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
1964 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
1965 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
1966
1967 /*
1968 * Function 0x0030 pops up all over the place. Apparently
1969 * it is a hardware control register, with every bit assigned to
1970 * do something.
1971 */
1972 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
1973
1974 /*
1975 * Magic control of CMOS sensor. Only lower values like
1976 * 0-3 work, and picture shifts left or right. Don't change.
1977 */
1978 switch (gspca_dev->width) {
1979 case 176: /* 176x144 */
1980 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1981 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1982 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1983 clock_div = 6;
1984 break;
1985 case 320: /* 320x240 */
1986 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
1987 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
1988 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1989 clock_div = 8;
1990 break;
1991 /* case VIDEOSIZE_352x240: */
1992 /* This mode doesn't work as Windows programs it; changed to work */
1993 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1994 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1995 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1996 clock_div = 10;
1997 break;
1998 case 352: /* 352x288 */
1999 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
2000 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
2001 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
2002 clock_div = 16;
2003 break;
2004 }
2005
2006 /* TESTME These are handled through controls
2007 KEEP until someone can test leaving this out is ok */
2008 if (0)
2009 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
2010
2011 /*
2012 * We have our own frame rate setting varying from 0 (slowest) to 6
2013 * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
2014 # where 0 is also the slowest setting. However for all practical
2015 # reasons high settings make no sense because USB is not fast enough
2016 # to support high FPS. Be aware that the picture datastream will be
2017 # severely disrupted if you ask for frame rate faster than allowed
2018 # for the video size - see below:
2019 *
2020 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
2021 * -----------------------------------------------------------------
2022 * 176x144: [6..31]
2023 * 320x240: [8..31]
2024 * 352x240: [10..31]
2025 * 352x288: [16..31] I have to raise lower threshold for stability...
2026 *
2027 * As usual, slower FPS provides better sensitivity.
2028 */
2029 cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
2030
2031 /*
2032 * This setting does not visibly affect pictures; left it here
2033 * because it was present in Windows USB data stream. This function
2034 * does not allow arbitrary values and apparently is a bit mask, to
2035 * be activated only at appropriate time. Don't change it randomly!
2036 */
2037 switch (gspca_dev->width) {
2038 case 176: /* 176x144 */
2039 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
2040 break;
2041 case 320: /* 320x240 */
2042 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
2043 break;
2044 /* case VIDEOSIZE_352x240: */
2045 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
2046 break;
2047 case 352: /* 352x288 */
2048 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
2049 break;
2050 }
2051
2052 /* FIXME this cannot be changed while streaming, so we
2053 should report a grabbed flag for this control. */
2054 cit_model2_Packet1(gspca_dev, 0x0028, sd->lighting);
2055 /* color balance rg2 */
2056 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
2057 /* saturation */
2058 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
2059 /* color balance yb */
2060 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
2061
2062 /* Hardware control command */
2063 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2064
2065 return 0;
2066 }
2067
cit_start_model3(struct gspca_dev * gspca_dev)2068 static int cit_start_model3(struct gspca_dev *gspca_dev)
2069 {
2070 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2071 int i, clock_div = 0;
2072
2073 /* HDG not in ibmcam driver, added to see if it helps with
2074 auto-detecting between model3 and ibm netcamera pro */
2075 cit_read_reg(gspca_dev, 0x128, 1);
2076
2077 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2078 cit_read_reg(gspca_dev, 0x0116, 0);
2079 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2080 cit_write_reg(gspca_dev, 0x0002, 0x0112);
2081 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2082 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2083 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2084 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2085 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2086 cit_write_reg(gspca_dev, 0x0002, 0x0115);
2087 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2088 cit_read_reg(gspca_dev, 0x0115, 0);
2089 cit_write_reg(gspca_dev, 0x000b, 0x0115);
2090
2091 /* TESTME HDG not in ibmcam driver, added to see if it helps with
2092 auto-detecting between model3 and ibm netcamera pro */
2093 if (0) {
2094 cit_write_reg(gspca_dev, 0x0078, 0x012d);
2095 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2096 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2097 cit_write_reg(gspca_dev, 0x0079, 0x012d);
2098 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
2099 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
2100 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2101 cit_read_reg(gspca_dev, 0x0126, 1);
2102 }
2103
2104 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
2105 cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6);
2106 cit_model3_Packet1(gspca_dev, 0x000c, 0x0002);
2107 cit_model3_Packet1(gspca_dev, 0x000d, 0x0020);
2108 cit_model3_Packet1(gspca_dev, 0x000e, 0x0033);
2109 cit_model3_Packet1(gspca_dev, 0x000f, 0x0007);
2110 cit_model3_Packet1(gspca_dev, 0x0010, 0x0000);
2111 cit_model3_Packet1(gspca_dev, 0x0011, 0x0070);
2112 cit_model3_Packet1(gspca_dev, 0x0012, 0x0030);
2113 cit_model3_Packet1(gspca_dev, 0x0013, 0x0000);
2114 cit_model3_Packet1(gspca_dev, 0x0014, 0x0001);
2115 cit_model3_Packet1(gspca_dev, 0x0015, 0x0001);
2116 cit_model3_Packet1(gspca_dev, 0x0016, 0x0001);
2117 cit_model3_Packet1(gspca_dev, 0x0017, 0x0001);
2118 cit_model3_Packet1(gspca_dev, 0x0018, 0x0000);
2119 cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3);
2120 cit_model3_Packet1(gspca_dev, 0x0020, 0x0000);
2121 cit_model3_Packet1(gspca_dev, 0x0028, 0x0010);
2122 cit_model3_Packet1(gspca_dev, 0x0029, 0x0054);
2123 cit_model3_Packet1(gspca_dev, 0x002a, 0x0013);
2124 cit_model3_Packet1(gspca_dev, 0x002b, 0x0007);
2125 cit_model3_Packet1(gspca_dev, 0x002d, 0x0028);
2126 cit_model3_Packet1(gspca_dev, 0x002e, 0x0000);
2127 cit_model3_Packet1(gspca_dev, 0x0031, 0x0000);
2128 cit_model3_Packet1(gspca_dev, 0x0032, 0x0000);
2129 cit_model3_Packet1(gspca_dev, 0x0033, 0x0000);
2130 cit_model3_Packet1(gspca_dev, 0x0034, 0x0000);
2131 cit_model3_Packet1(gspca_dev, 0x0035, 0x0038);
2132 cit_model3_Packet1(gspca_dev, 0x003a, 0x0001);
2133 cit_model3_Packet1(gspca_dev, 0x003c, 0x001e);
2134 cit_model3_Packet1(gspca_dev, 0x003f, 0x000a);
2135 cit_model3_Packet1(gspca_dev, 0x0041, 0x0000);
2136 cit_model3_Packet1(gspca_dev, 0x0046, 0x003f);
2137 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
2138 cit_model3_Packet1(gspca_dev, 0x0050, 0x0005);
2139 cit_model3_Packet1(gspca_dev, 0x0052, 0x001a);
2140 cit_model3_Packet1(gspca_dev, 0x0053, 0x0003);
2141 cit_model3_Packet1(gspca_dev, 0x005a, 0x006b);
2142 cit_model3_Packet1(gspca_dev, 0x005d, 0x001e);
2143 cit_model3_Packet1(gspca_dev, 0x005e, 0x0030);
2144 cit_model3_Packet1(gspca_dev, 0x005f, 0x0041);
2145 cit_model3_Packet1(gspca_dev, 0x0064, 0x0008);
2146 cit_model3_Packet1(gspca_dev, 0x0065, 0x0015);
2147 cit_model3_Packet1(gspca_dev, 0x0068, 0x000f);
2148 cit_model3_Packet1(gspca_dev, 0x0079, 0x0000);
2149 cit_model3_Packet1(gspca_dev, 0x007a, 0x0000);
2150 cit_model3_Packet1(gspca_dev, 0x007c, 0x003f);
2151 cit_model3_Packet1(gspca_dev, 0x0082, 0x000f);
2152 cit_model3_Packet1(gspca_dev, 0x0085, 0x0000);
2153 cit_model3_Packet1(gspca_dev, 0x0099, 0x0000);
2154 cit_model3_Packet1(gspca_dev, 0x009b, 0x0023);
2155 cit_model3_Packet1(gspca_dev, 0x009c, 0x0022);
2156 cit_model3_Packet1(gspca_dev, 0x009d, 0x0096);
2157 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
2158 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
2159
2160 switch (gspca_dev->width) {
2161 case 160:
2162 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2163 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2164 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2165 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2166 cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */
2167 cit_write_reg(gspca_dev, 0x00a9, 0x0119);
2168 cit_write_reg(gspca_dev, 0x0016, 0x011b);
2169 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2170 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2171 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2172 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2173 cit_write_reg(gspca_dev, 0x0018, 0x0102);
2174 cit_write_reg(gspca_dev, 0x0004, 0x0104);
2175 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2176 cit_write_reg(gspca_dev, 0x0028, 0x011c);
2177 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2178 cit_write_reg(gspca_dev, 0x0000, 0x0118);
2179 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2180 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2181 cit_write_reg(gspca_dev, compression, 0x0109);
2182 clock_div = 3;
2183 break;
2184 case 320:
2185 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2186 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2187 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2188 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2189 cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */
2190 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */
2191 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2192 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2193 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2194 /* 4 commands from 160x120 skipped */
2195 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2196 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2197 cit_write_reg(gspca_dev, compression, 0x0109);
2198 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2199 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2200 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2201 cit_write_reg(gspca_dev, 0x0010, 0x0104);
2202 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2203 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2204 cit_write_reg(gspca_dev, 0x001c, 0x0118);
2205 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2206 clock_div = 5;
2207 break;
2208 case 640:
2209 cit_write_reg(gspca_dev, 0x00f0, 0x0105);
2210 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2211 cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */
2212 cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
2213 cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
2214 cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */
2215 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2216 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2217 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2218 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2219 cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */
2220 cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
2221 cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
2222 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2223 cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
2224 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2225 cit_write_reg(gspca_dev, compression, 0x0109);
2226 cit_write_reg(gspca_dev, 0x0040, 0x0101);
2227 cit_write_reg(gspca_dev, 0x0040, 0x0103);
2228 cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
2229 clock_div = 7;
2230 break;
2231 }
2232
2233 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */
2234 cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */
2235 cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */
2236 cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */
2237 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */
2238 cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */
2239 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2240 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2241 cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */
2242 cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */
2243 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */
2244 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2245 cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */
2246 cit_model3_Packet1(gspca_dev, 0x002f, 0x002a);
2247 cit_model3_Packet1(gspca_dev, 0x0030, 0x0029);
2248 cit_model3_Packet1(gspca_dev, 0x0037, 0x0002);
2249 cit_model3_Packet1(gspca_dev, 0x0038, 0x0059);
2250 cit_model3_Packet1(gspca_dev, 0x003d, 0x002e);
2251 cit_model3_Packet1(gspca_dev, 0x003e, 0x0028);
2252 cit_model3_Packet1(gspca_dev, 0x0078, 0x0005);
2253 cit_model3_Packet1(gspca_dev, 0x007b, 0x0011);
2254 cit_model3_Packet1(gspca_dev, 0x007d, 0x004b);
2255 cit_model3_Packet1(gspca_dev, 0x007f, 0x0022);
2256 cit_model3_Packet1(gspca_dev, 0x0080, 0x000c);
2257 cit_model3_Packet1(gspca_dev, 0x0081, 0x000b);
2258 cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd);
2259 cit_model3_Packet1(gspca_dev, 0x0086, 0x000b);
2260 cit_model3_Packet1(gspca_dev, 0x0087, 0x000b);
2261 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e);
2262 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2263 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2264 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2265
2266 /* FIXME we should probably use cit_get_clock_div() here (in
2267 combination with isoc negotiation using the programmable isoc size)
2268 like with the IBM netcam pro). */
2269 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
2270
2271 switch (gspca_dev->width) {
2272 case 160:
2273 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2274 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2275 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2276 cit_model3_Packet1(gspca_dev, 0x0040, 0x000a);
2277 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2278 break;
2279 case 320:
2280 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2281 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2282 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2283 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2284 cit_model3_Packet1(gspca_dev, 0x0051, 0x000b);
2285 break;
2286 case 640:
2287 cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */
2288 cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */
2289 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2290 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2291 break;
2292 }
2293
2294 /* if (sd->input_index) { */
2295 if (rca_input) {
2296 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2297 if (rca_initdata[i][0])
2298 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2299 else
2300 cit_write_reg(gspca_dev, rca_initdata[i][1],
2301 rca_initdata[i][2]);
2302 }
2303 }
2304
2305 return 0;
2306 }
2307
cit_start_model4(struct gspca_dev * gspca_dev)2308 static int cit_start_model4(struct gspca_dev *gspca_dev)
2309 {
2310 struct sd *sd = (struct sd *) gspca_dev;
2311
2312 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2313 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2314 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
2315 cit_write_reg(gspca_dev, 0x0080, 0x012b);
2316 cit_write_reg(gspca_dev, 0x0000, 0x0108);
2317 cit_write_reg(gspca_dev, 0x0001, 0x0133);
2318 cit_write_reg(gspca_dev, 0x009b, 0x010f);
2319 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
2320 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
2321 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
2322
2323 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2324 cit_write_reg(gspca_dev, 0x0004, 0x012f);
2325 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2326 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2327 cit_write_reg(gspca_dev, 0x00fb, 0x012e);
2328 cit_write_reg(gspca_dev, 0x0000, 0x0130);
2329 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2330 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2331 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2332 cit_write_reg(gspca_dev, 0x000c, 0x0127);
2333 cit_write_reg(gspca_dev, 0x0009, 0x012e);
2334 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2335
2336 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2337 cit_write_reg(gspca_dev, 0x0012, 0x012f);
2338 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2339 cit_write_reg(gspca_dev, 0x0008, 0x0127);
2340 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2341 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2342 cit_write_reg(gspca_dev, 0x002a, 0x012d);
2343 cit_write_reg(gspca_dev, 0x0000, 0x012f);
2344 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2345 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2346 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2347
2348 switch (gspca_dev->width) {
2349 case 128: /* 128x96 */
2350 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2351 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2352 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2353 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2354 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2355 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2356 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2357 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2358 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2359 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2360 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2361 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2362 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2363 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2364 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2365 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2366 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2367 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2368 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2369 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2370 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2371 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2372 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2373 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2374 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2375 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2376 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2377 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2378 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2379 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2380 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2381 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2382 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2383 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2384 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2385 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2386 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2387 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2388 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2389 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2390 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2391 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2392 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2393 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2394 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2395 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2396 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2397 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2398 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2399 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2400 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2401 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2402 sd->sof_len = 2;
2403 break;
2404 case 160: /* 160x120 */
2405 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2406 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2407 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2408 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2409 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2410 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2411 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2412 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2413 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2414 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2415 cit_write_reg(gspca_dev, 0x000b, 0x0127);
2416 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2417 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2418 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2419 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2420 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2421 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2422 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2423 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2424 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2425 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2426 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2427 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2428 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2429 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2430 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2431 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2432 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2433 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2434 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2435 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2436 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2437 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2438 cit_write_reg(gspca_dev, 0x0025, 0x0127);
2439 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2440 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2441 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2442 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2443 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2444 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2445 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2446 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2447 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2448 cit_write_reg(gspca_dev, 0x0048, 0x0127);
2449 cit_write_reg(gspca_dev, 0x0035, 0x012e);
2450 cit_write_reg(gspca_dev, 0x00d0, 0x0130);
2451 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2452 cit_write_reg(gspca_dev, 0x0048, 0x012d);
2453 cit_write_reg(gspca_dev, 0x0090, 0x012f);
2454 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2455 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2456 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2457 sd->sof_len = 2;
2458 break;
2459 case 176: /* 176x144 */
2460 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2461 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2462 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2463 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2464 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2465 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2466 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2467 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2468 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2469 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2470 cit_write_reg(gspca_dev, 0x0007, 0x0127);
2471 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2472 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2473 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2474 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2475 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2476 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2477 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2478 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2479 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2480 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2481 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2482 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2483 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2484 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2485 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2486 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2487 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2488 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2489 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2490 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2491 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2492 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2493 cit_write_reg(gspca_dev, 0x0028, 0x0127);
2494 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2495 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2496 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2497 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2498 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2499 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2500 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2501 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2502 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2503 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2504 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2505 cit_write_reg(gspca_dev, 0x002a, 0x0130);
2506 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2507 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2508 cit_write_reg(gspca_dev, 0x006d, 0x012f);
2509 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2510 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2511 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2512 /* TESTME HDG: this does not seem right
2513 (it is 2 for all other resolutions) */
2514 sd->sof_len = 10;
2515 break;
2516 case 320: /* 320x240 */
2517 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2518 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2519 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2520 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2521 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2522 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2523 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2524 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2525 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2526 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2527 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2528 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2529 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2530 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2531 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2532 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2533 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2534 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2535 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2536 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2537 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2538 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2539 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2540 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2541 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2542 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2543 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2544 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2545 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2546 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2547 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2548 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2549 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2550 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2551 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2552 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2553 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2554 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2555 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2556 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2557 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2558 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2559 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2560 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2561 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2562 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2563 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2564 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2565 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2566 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2567 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2568 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2569 sd->sof_len = 2;
2570 break;
2571 case 352: /* 352x288 */
2572 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2573 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2574 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2575 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2576 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2577 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2578 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2579 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2580 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2581 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2582 cit_write_reg(gspca_dev, 0x0006, 0x0127);
2583 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2584 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2585 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2586 cit_write_reg(gspca_dev, 0x0002, 0x012f);
2587 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2588 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2589 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2590 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2591 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2592 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2593 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2594 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2595 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2596 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2597 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2598 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2599 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2600 cit_write_reg(gspca_dev, 0x00cf, 0x012e);
2601 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2602 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2603 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2604 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2605 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2606 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2607 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2608 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2609 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2610 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2611 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2612 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2613 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2614 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2615 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2616 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2617 cit_write_reg(gspca_dev, 0x0025, 0x0130);
2618 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2619 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2620 cit_write_reg(gspca_dev, 0x0048, 0x012f);
2621 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2622 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2623 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2624 sd->sof_len = 2;
2625 break;
2626 }
2627
2628 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
2629
2630 return 0;
2631 }
2632
cit_start_ibm_netcam_pro(struct gspca_dev * gspca_dev)2633 static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2634 {
2635 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2636 int i, clock_div;
2637
2638 clock_div = cit_get_clock_div(gspca_dev);
2639 if (clock_div < 0)
2640 return clock_div;
2641
2642 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2643 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2644 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2645 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2646 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2647 /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */
2648 cit_write_reg(gspca_dev, 0x0000, 0x0133);
2649 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2650 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2651 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2652 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2653 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2654 /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */
2655
2656 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
2657
2658 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2659 cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */
2660 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2661 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2662 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2663 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2664 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2665 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2666 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2667
2668 switch (gspca_dev->width) {
2669 case 160: /* 160x120 */
2670 cit_write_reg(gspca_dev, 0x0024, 0x010b);
2671 cit_write_reg(gspca_dev, 0x0089, 0x0119);
2672 cit_write_reg(gspca_dev, 0x000a, 0x011b);
2673 cit_write_reg(gspca_dev, 0x0003, 0x011e);
2674 cit_write_reg(gspca_dev, 0x0007, 0x0104);
2675 cit_write_reg(gspca_dev, 0x0009, 0x011a);
2676 cit_write_reg(gspca_dev, 0x008b, 0x011c);
2677 cit_write_reg(gspca_dev, 0x0008, 0x0118);
2678 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2679 break;
2680 case 320: /* 320x240 */
2681 cit_write_reg(gspca_dev, 0x0028, 0x010b);
2682 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2683 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2684 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2685 cit_write_reg(gspca_dev, 0x000e, 0x0104);
2686 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2687 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2688 cit_write_reg(gspca_dev, 0x000c, 0x0118);
2689 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2690 break;
2691 }
2692
2693 cit_model3_Packet1(gspca_dev, 0x0019, 0x0031);
2694 cit_model3_Packet1(gspca_dev, 0x001a, 0x0003);
2695 cit_model3_Packet1(gspca_dev, 0x001b, 0x0038);
2696 cit_model3_Packet1(gspca_dev, 0x001c, 0x0000);
2697 cit_model3_Packet1(gspca_dev, 0x0024, 0x0001);
2698 cit_model3_Packet1(gspca_dev, 0x0027, 0x0001);
2699 cit_model3_Packet1(gspca_dev, 0x002a, 0x0004);
2700 cit_model3_Packet1(gspca_dev, 0x0035, 0x000b);
2701 cit_model3_Packet1(gspca_dev, 0x003f, 0x0001);
2702 cit_model3_Packet1(gspca_dev, 0x0044, 0x0000);
2703 cit_model3_Packet1(gspca_dev, 0x0054, 0x0000);
2704 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000);
2705 cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001);
2706 cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001);
2707 cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000);
2708 cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0);
2709
2710 cit_write_reg(gspca_dev, compression, 0x0109);
2711 cit_write_reg(gspca_dev, clock_div, 0x0111);
2712
2713 /* if (sd->input_index) { */
2714 if (rca_input) {
2715 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2716 if (rca_initdata[i][0])
2717 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2718 else
2719 cit_write_reg(gspca_dev, rca_initdata[i][1],
2720 rca_initdata[i][2]);
2721 }
2722 }
2723
2724 return 0;
2725 }
2726
2727 /* -- start the camera -- */
sd_start(struct gspca_dev * gspca_dev)2728 static int sd_start(struct gspca_dev *gspca_dev)
2729 {
2730 struct sd *sd = (struct sd *) gspca_dev;
2731 int packet_size;
2732
2733 packet_size = cit_get_packet_size(gspca_dev);
2734 if (packet_size < 0)
2735 return packet_size;
2736
2737 switch (sd->model) {
2738 case CIT_MODEL0:
2739 cit_start_model0(gspca_dev);
2740 break;
2741 case CIT_MODEL1:
2742 cit_start_model1(gspca_dev);
2743 break;
2744 case CIT_MODEL2:
2745 cit_start_model2(gspca_dev);
2746 break;
2747 case CIT_MODEL3:
2748 cit_start_model3(gspca_dev);
2749 break;
2750 case CIT_MODEL4:
2751 cit_start_model4(gspca_dev);
2752 break;
2753 case CIT_IBM_NETCAM_PRO:
2754 cit_start_ibm_netcam_pro(gspca_dev);
2755 break;
2756 }
2757
2758 cit_set_brightness(gspca_dev);
2759 cit_set_contrast(gspca_dev);
2760 cit_set_hue(gspca_dev);
2761 cit_set_sharpness(gspca_dev);
2762 cit_set_lighting(gspca_dev);
2763 cit_set_hflip(gspca_dev);
2764
2765 /* Program max isoc packet size */
2766 cit_write_reg(gspca_dev, packet_size >> 8, 0x0106);
2767 cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107);
2768
2769 cit_restart_stream(gspca_dev);
2770
2771 return 0;
2772 }
2773
sd_isoc_init(struct gspca_dev * gspca_dev)2774 static int sd_isoc_init(struct gspca_dev *gspca_dev)
2775 {
2776 struct usb_host_interface *alt;
2777 int max_packet_size;
2778
2779 switch (gspca_dev->width) {
2780 case 160:
2781 max_packet_size = 450;
2782 break;
2783 case 176:
2784 max_packet_size = 600;
2785 break;
2786 default:
2787 max_packet_size = 1022;
2788 break;
2789 }
2790
2791 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
2792 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
2793 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size);
2794
2795 return 0;
2796 }
2797
sd_isoc_nego(struct gspca_dev * gspca_dev)2798 static int sd_isoc_nego(struct gspca_dev *gspca_dev)
2799 {
2800 int ret, packet_size, min_packet_size;
2801 struct usb_host_interface *alt;
2802
2803 switch (gspca_dev->width) {
2804 case 160:
2805 min_packet_size = 200;
2806 break;
2807 case 176:
2808 min_packet_size = 266;
2809 break;
2810 default:
2811 min_packet_size = 400;
2812 break;
2813 }
2814
2815 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
2816 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2817 if (packet_size <= min_packet_size)
2818 return -EIO;
2819
2820 packet_size -= 100;
2821 if (packet_size < min_packet_size)
2822 packet_size = min_packet_size;
2823 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
2824
2825 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
2826 if (ret < 0)
2827 pr_err("set alt 1 err %d\n", ret);
2828
2829 return ret;
2830 }
2831
sd_stopN(struct gspca_dev * gspca_dev)2832 static void sd_stopN(struct gspca_dev *gspca_dev)
2833 {
2834 cit_write_reg(gspca_dev, 0x0000, 0x010c);
2835 }
2836
sd_stop0(struct gspca_dev * gspca_dev)2837 static void sd_stop0(struct gspca_dev *gspca_dev)
2838 {
2839 struct sd *sd = (struct sd *) gspca_dev;
2840
2841 /* We cannot use gspca_dev->present here as that is not set when
2842 sd_init gets called and we get called from sd_init */
2843 if (!gspca_dev->dev)
2844 return;
2845
2846 switch (sd->model) {
2847 case CIT_MODEL0:
2848 /* HDG windows does this, but it causes the cams autogain to
2849 restart from a gain of 0, which does not look good when
2850 changing resolutions. */
2851 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2852 cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */
2853 break;
2854 case CIT_MODEL1:
2855 cit_send_FF_04_02(gspca_dev);
2856 cit_read_reg(gspca_dev, 0x0100, 0);
2857 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2858 break;
2859 case CIT_MODEL2:
2860 case CIT_MODEL4:
2861 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2862
2863 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
2864 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2865 cit_write_reg(gspca_dev, 0x00a0, 0x0111);
2866
2867 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
2868
2869 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2870 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2871 break;
2872 case CIT_MODEL3:
2873 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2874 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
2875 cit_read_reg(gspca_dev, 0x0116, 0);
2876 cit_write_reg(gspca_dev, 0x0064, 0x0116);
2877 cit_read_reg(gspca_dev, 0x0115, 0);
2878 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2879 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2880 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2881 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2882 cit_write_reg(gspca_dev, 0x0080, 0x0100);
2883 break;
2884 case CIT_IBM_NETCAM_PRO:
2885 cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff);
2886 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2887 cit_write_reg(gspca_dev, 0x0000, 0x0116);
2888 /* HDG windows does this, but I cannot get the camera
2889 to restart with this without redoing the entire init
2890 sequence which makes switching modes really slow */
2891 /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */
2892 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2893 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2894 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2895 cit_write_reg(gspca_dev, 0x0000, 0x0111);
2896 /* HDG windows does this, but I get a green picture when
2897 restarting the stream after this */
2898 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2899 cit_write_reg(gspca_dev, 0x00c0, 0x0100);
2900 break;
2901 }
2902
2903 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2904 /* If the last button state is pressed, release it now! */
2905 if (sd->button_state) {
2906 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2907 input_sync(gspca_dev->input_dev);
2908 sd->button_state = 0;
2909 }
2910 #endif
2911 }
2912
cit_find_sof(struct gspca_dev * gspca_dev,u8 * data,int len)2913 static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2914 {
2915 struct sd *sd = (struct sd *) gspca_dev;
2916 u8 byte3 = 0, byte4 = 0;
2917 int i;
2918
2919 switch (sd->model) {
2920 case CIT_MODEL0:
2921 case CIT_MODEL1:
2922 case CIT_MODEL3:
2923 case CIT_IBM_NETCAM_PRO:
2924 switch (gspca_dev->width) {
2925 case 160: /* 160x120 */
2926 byte3 = 0x02;
2927 byte4 = 0x0a;
2928 break;
2929 case 176: /* 176x144 */
2930 byte3 = 0x02;
2931 byte4 = 0x0e;
2932 break;
2933 case 320: /* 320x240 */
2934 byte3 = 0x02;
2935 byte4 = 0x08;
2936 break;
2937 case 352: /* 352x288 */
2938 byte3 = 0x02;
2939 byte4 = 0x00;
2940 break;
2941 case 640:
2942 byte3 = 0x03;
2943 byte4 = 0x08;
2944 break;
2945 }
2946
2947 /* These have a different byte3 */
2948 if (sd->model <= CIT_MODEL1)
2949 byte3 = 0x00;
2950
2951 for (i = 0; i < len; i++) {
2952 /* For this model the SOF always starts at offset 0
2953 so no need to search the entire frame */
2954 if (sd->model == CIT_MODEL0 && sd->sof_read != i)
2955 break;
2956
2957 switch (sd->sof_read) {
2958 case 0:
2959 if (data[i] == 0x00)
2960 sd->sof_read++;
2961 break;
2962 case 1:
2963 if (data[i] == 0xff)
2964 sd->sof_read++;
2965 else if (data[i] == 0x00)
2966 sd->sof_read = 1;
2967 else
2968 sd->sof_read = 0;
2969 break;
2970 case 2:
2971 if (data[i] == byte3)
2972 sd->sof_read++;
2973 else if (data[i] == 0x00)
2974 sd->sof_read = 1;
2975 else
2976 sd->sof_read = 0;
2977 break;
2978 case 3:
2979 if (data[i] == byte4) {
2980 sd->sof_read = 0;
2981 return data + i + (sd->sof_len - 3);
2982 }
2983 if (byte3 == 0x00 && data[i] == 0xff)
2984 sd->sof_read = 2;
2985 else if (data[i] == 0x00)
2986 sd->sof_read = 1;
2987 else
2988 sd->sof_read = 0;
2989 break;
2990 }
2991 }
2992 break;
2993 case CIT_MODEL2:
2994 case CIT_MODEL4:
2995 /* TESTME we need to find a longer sof signature to avoid
2996 false positives */
2997 for (i = 0; i < len; i++) {
2998 switch (sd->sof_read) {
2999 case 0:
3000 if (data[i] == 0x00)
3001 sd->sof_read++;
3002 break;
3003 case 1:
3004 sd->sof_read = 0;
3005 if (data[i] == 0xff) {
3006 if (i >= 4)
3007 PDEBUG(D_FRAM,
3008 "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n",
3009 i - 1,
3010 data[i - 4],
3011 data[i - 3],
3012 data[i],
3013 data[i + 1],
3014 data[i + 2]);
3015 else
3016 PDEBUG(D_FRAM,
3017 "header found at offset: %d: 00 %02x %02x %02x\n",
3018 i - 1,
3019 data[i],
3020 data[i + 1],
3021 data[i + 2]);
3022 return data + i + (sd->sof_len - 1);
3023 }
3024 break;
3025 }
3026 }
3027 break;
3028 }
3029 return NULL;
3030 }
3031
sd_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)3032 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
3033 u8 *data, int len)
3034 {
3035 struct sd *sd = (struct sd *) gspca_dev;
3036 unsigned char *sof;
3037
3038 sof = cit_find_sof(gspca_dev, data, len);
3039 if (sof) {
3040 int n;
3041
3042 /* finish decoding current frame */
3043 n = sof - data;
3044 if (n > sd->sof_len)
3045 n -= sd->sof_len;
3046 else
3047 n = 0;
3048 gspca_frame_add(gspca_dev, LAST_PACKET,
3049 data, n);
3050 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
3051 len -= sof - data;
3052 data = sof;
3053 }
3054
3055 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
3056 }
3057
sd_setbrightness(struct gspca_dev * gspca_dev,__s32 val)3058 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3059 {
3060 struct sd *sd = (struct sd *) gspca_dev;
3061
3062 sd->brightness = val;
3063 if (gspca_dev->streaming) {
3064 if (sd->stop_on_control_change)
3065 sd_stopN(gspca_dev);
3066 cit_set_brightness(gspca_dev);
3067 if (sd->stop_on_control_change)
3068 cit_restart_stream(gspca_dev);
3069 }
3070
3071 return 0;
3072 }
3073
sd_getbrightness(struct gspca_dev * gspca_dev,__s32 * val)3074 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
3075 {
3076 struct sd *sd = (struct sd *) gspca_dev;
3077
3078 *val = sd->brightness;
3079
3080 return 0;
3081 }
3082
sd_setcontrast(struct gspca_dev * gspca_dev,__s32 val)3083 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3084 {
3085 struct sd *sd = (struct sd *) gspca_dev;
3086
3087 sd->contrast = val;
3088 if (gspca_dev->streaming) {
3089 if (sd->stop_on_control_change)
3090 sd_stopN(gspca_dev);
3091 cit_set_contrast(gspca_dev);
3092 if (sd->stop_on_control_change)
3093 cit_restart_stream(gspca_dev);
3094 }
3095
3096 return 0;
3097 }
3098
sd_getcontrast(struct gspca_dev * gspca_dev,__s32 * val)3099 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3100 {
3101 struct sd *sd = (struct sd *) gspca_dev;
3102
3103 *val = sd->contrast;
3104
3105 return 0;
3106 }
3107
sd_sethue(struct gspca_dev * gspca_dev,__s32 val)3108 static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
3109 {
3110 struct sd *sd = (struct sd *) gspca_dev;
3111
3112 sd->hue = val;
3113 if (gspca_dev->streaming) {
3114 if (sd->stop_on_control_change)
3115 sd_stopN(gspca_dev);
3116 cit_set_hue(gspca_dev);
3117 if (sd->stop_on_control_change)
3118 cit_restart_stream(gspca_dev);
3119 }
3120 return 0;
3121 }
3122
sd_gethue(struct gspca_dev * gspca_dev,__s32 * val)3123 static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
3124 {
3125 struct sd *sd = (struct sd *) gspca_dev;
3126
3127 *val = sd->hue;
3128
3129 return 0;
3130 }
3131
sd_setsharpness(struct gspca_dev * gspca_dev,__s32 val)3132 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
3133 {
3134 struct sd *sd = (struct sd *) gspca_dev;
3135
3136 sd->sharpness = val;
3137 if (gspca_dev->streaming) {
3138 if (sd->stop_on_control_change)
3139 sd_stopN(gspca_dev);
3140 cit_set_sharpness(gspca_dev);
3141 if (sd->stop_on_control_change)
3142 cit_restart_stream(gspca_dev);
3143 }
3144 return 0;
3145 }
3146
sd_getsharpness(struct gspca_dev * gspca_dev,__s32 * val)3147 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
3148 {
3149 struct sd *sd = (struct sd *) gspca_dev;
3150
3151 *val = sd->sharpness;
3152
3153 return 0;
3154 }
3155
sd_setlighting(struct gspca_dev * gspca_dev,__s32 val)3156 static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val)
3157 {
3158 struct sd *sd = (struct sd *) gspca_dev;
3159
3160 sd->lighting = val;
3161 if (gspca_dev->streaming) {
3162 if (sd->stop_on_control_change)
3163 sd_stopN(gspca_dev);
3164 cit_set_lighting(gspca_dev);
3165 if (sd->stop_on_control_change)
3166 cit_restart_stream(gspca_dev);
3167 }
3168 return 0;
3169 }
3170
sd_getlighting(struct gspca_dev * gspca_dev,__s32 * val)3171 static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val)
3172 {
3173 struct sd *sd = (struct sd *) gspca_dev;
3174
3175 *val = sd->lighting;
3176
3177 return 0;
3178 }
3179
sd_sethflip(struct gspca_dev * gspca_dev,__s32 val)3180 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3181 {
3182 struct sd *sd = (struct sd *) gspca_dev;
3183
3184 sd->hflip = val;
3185 if (gspca_dev->streaming) {
3186 if (sd->stop_on_control_change)
3187 sd_stopN(gspca_dev);
3188 cit_set_hflip(gspca_dev);
3189 if (sd->stop_on_control_change)
3190 cit_restart_stream(gspca_dev);
3191 }
3192 return 0;
3193 }
3194
sd_gethflip(struct gspca_dev * gspca_dev,__s32 * val)3195 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3196 {
3197 struct sd *sd = (struct sd *) gspca_dev;
3198
3199 *val = sd->hflip;
3200
3201 return 0;
3202 }
3203
3204 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
cit_check_button(struct gspca_dev * gspca_dev)3205 static void cit_check_button(struct gspca_dev *gspca_dev)
3206 {
3207 int new_button_state;
3208 struct sd *sd = (struct sd *)gspca_dev;
3209
3210 switch (sd->model) {
3211 case CIT_MODEL3:
3212 case CIT_IBM_NETCAM_PRO:
3213 break;
3214 default: /* TEST ME unknown if this works on other models too */
3215 return;
3216 }
3217
3218 /* Read the button state */
3219 cit_read_reg(gspca_dev, 0x0113, 0);
3220 new_button_state = !gspca_dev->usb_buf[0];
3221
3222 /* Tell the cam we've seen the button press, notice that this
3223 is a nop (iow the cam keeps reporting pressed) until the
3224 button is actually released. */
3225 if (new_button_state)
3226 cit_write_reg(gspca_dev, 0x01, 0x0113);
3227
3228 if (sd->button_state != new_button_state) {
3229 input_report_key(gspca_dev->input_dev, KEY_CAMERA,
3230 new_button_state);
3231 input_sync(gspca_dev->input_dev);
3232 sd->button_state = new_button_state;
3233 }
3234 }
3235 #endif
3236
3237 /* sub-driver description */
3238 static const struct sd_desc sd_desc = {
3239 .name = MODULE_NAME,
3240 .ctrls = sd_ctrls,
3241 .nctrls = ARRAY_SIZE(sd_ctrls),
3242 .config = sd_config,
3243 .init = sd_init,
3244 .start = sd_start,
3245 .stopN = sd_stopN,
3246 .stop0 = sd_stop0,
3247 .pkt_scan = sd_pkt_scan,
3248 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3249 .dq_callback = cit_check_button,
3250 .other_input = 1,
3251 #endif
3252 };
3253
3254 static const struct sd_desc sd_desc_isoc_nego = {
3255 .name = MODULE_NAME,
3256 .ctrls = sd_ctrls,
3257 .nctrls = ARRAY_SIZE(sd_ctrls),
3258 .config = sd_config,
3259 .init = sd_init,
3260 .start = sd_start,
3261 .isoc_init = sd_isoc_init,
3262 .isoc_nego = sd_isoc_nego,
3263 .stopN = sd_stopN,
3264 .stop0 = sd_stop0,
3265 .pkt_scan = sd_pkt_scan,
3266 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3267 .dq_callback = cit_check_button,
3268 .other_input = 1,
3269 #endif
3270 };
3271
3272 /* -- module initialisation -- */
3273 static const struct usb_device_id device_table[] = {
3274 { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 },
3275 { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 },
3276 { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3277 { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 },
3278 { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3279 { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3280 { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3281 {}
3282 };
3283 MODULE_DEVICE_TABLE(usb, device_table);
3284
3285 /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)3286 static int sd_probe(struct usb_interface *intf,
3287 const struct usb_device_id *id)
3288 {
3289 const struct sd_desc *desc = &sd_desc;
3290
3291 switch (id->driver_info) {
3292 case CIT_MODEL0:
3293 case CIT_MODEL1:
3294 if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
3295 return -ENODEV;
3296 break;
3297 case CIT_MODEL2:
3298 case CIT_MODEL4:
3299 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3300 return -ENODEV;
3301 break;
3302 case CIT_MODEL3:
3303 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3304 return -ENODEV;
3305 /* FIXME this likely applies to all model3 cams and probably
3306 to other models too. */
3307 if (ibm_netcam_pro)
3308 desc = &sd_desc_isoc_nego;
3309 break;
3310 }
3311
3312 return gspca_dev_probe2(intf, id, desc, sizeof(struct sd), THIS_MODULE);
3313 }
3314
3315 static struct usb_driver sd_driver = {
3316 .name = MODULE_NAME,
3317 .id_table = device_table,
3318 .probe = sd_probe,
3319 .disconnect = gspca_disconnect,
3320 #ifdef CONFIG_PM
3321 .suspend = gspca_suspend,
3322 .resume = gspca_resume,
3323 #endif
3324 };
3325
3326 module_usb_driver(sd_driver);
3327