Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / usb / gspca / xirlink_cit.c
blobfa65c3eaa7259e12c7b4376144a3d19e5d98a03a
1 /*
2 * USB IBM C-It Video Camera driver
4 * Supports Xirlink C-It Video Camera, IBM PC Camera,
5 * IBM NetCamera and Veo Stingray.
7 * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.com>
9 * This driver is based on earlier work of:
11 * (C) Copyright 1999 Johannes Erdfelt
12 * (C) Copyright 1999 Randy Dunlap
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.
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.
26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #define MODULE_NAME "xirlink-cit"
30 #include <linux/input.h>
31 #include "gspca.h"
33 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
34 MODULE_DESCRIPTION("Xirlink C-IT");
35 MODULE_LICENSE("GPL");
37 /* FIXME we should autodetect this */
38 static int ibm_netcam_pro;
39 module_param(ibm_netcam_pro, int, 0);
40 MODULE_PARM_DESC(ibm_netcam_pro,
41 "Use IBM Netcamera Pro init sequences for Model 3 cams");
43 /* FIXME this should be handled through the V4L2 input selection API */
44 static int rca_input;
45 module_param(rca_input, int, 0644);
46 MODULE_PARM_DESC(rca_input,
47 "Use rca input instead of ccd sensor on Model 3 cams");
49 /* specific webcam descriptor */
50 struct sd {
51 struct gspca_dev gspca_dev; /* !! must be the first item */
52 struct v4l2_ctrl *lighting;
53 u8 model;
54 #define CIT_MODEL0 0 /* bcd version 0.01 cams ie the xvp-500 */
55 #define CIT_MODEL1 1 /* The model 1 - 4 nomenclature comes from the old */
56 #define CIT_MODEL2 2 /* ibmcam driver */
57 #define CIT_MODEL3 3
58 #define CIT_MODEL4 4
59 #define CIT_IBM_NETCAM_PRO 5
60 u8 input_index;
61 u8 button_state;
62 u8 stop_on_control_change;
63 u8 sof_read;
64 u8 sof_len;
67 static void sd_stop0(struct gspca_dev *gspca_dev);
69 static const struct v4l2_pix_format cif_yuv_mode[] = {
70 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
71 .bytesperline = 176,
72 .sizeimage = 176 * 144 * 3 / 2 + 4,
73 .colorspace = V4L2_COLORSPACE_SRGB},
74 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
75 .bytesperline = 352,
76 .sizeimage = 352 * 288 * 3 / 2 + 4,
77 .colorspace = V4L2_COLORSPACE_SRGB},
80 static const struct v4l2_pix_format vga_yuv_mode[] = {
81 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
82 .bytesperline = 160,
83 .sizeimage = 160 * 120 * 3 / 2 + 4,
84 .colorspace = V4L2_COLORSPACE_SRGB},
85 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
86 .bytesperline = 320,
87 .sizeimage = 320 * 240 * 3 / 2 + 4,
88 .colorspace = V4L2_COLORSPACE_SRGB},
89 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
90 .bytesperline = 640,
91 .sizeimage = 640 * 480 * 3 / 2 + 4,
92 .colorspace = V4L2_COLORSPACE_SRGB},
95 static const struct v4l2_pix_format model0_mode[] = {
96 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
97 .bytesperline = 160,
98 .sizeimage = 160 * 120 * 3 / 2 + 4,
99 .colorspace = V4L2_COLORSPACE_SRGB},
100 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
101 .bytesperline = 176,
102 .sizeimage = 176 * 144 * 3 / 2 + 4,
103 .colorspace = V4L2_COLORSPACE_SRGB},
104 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
105 .bytesperline = 320,
106 .sizeimage = 320 * 240 * 3 / 2 + 4,
107 .colorspace = V4L2_COLORSPACE_SRGB},
110 static const struct v4l2_pix_format model2_mode[] = {
111 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
112 .bytesperline = 160,
113 .sizeimage = 160 * 120 * 3 / 2 + 4,
114 .colorspace = V4L2_COLORSPACE_SRGB},
115 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
116 .bytesperline = 176,
117 .sizeimage = 176 * 144 * 3 / 2 + 4,
118 .colorspace = V4L2_COLORSPACE_SRGB},
119 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
120 .bytesperline = 320,
121 .sizeimage = 320 * 240 + 4,
122 .colorspace = V4L2_COLORSPACE_SRGB},
123 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
124 .bytesperline = 352,
125 .sizeimage = 352 * 288 + 4,
126 .colorspace = V4L2_COLORSPACE_SRGB},
130 * 01.01.08 - Added for RCA video in support -LO
131 * This struct is used to init the Model3 cam to use the RCA video in port
132 * instead of the CCD sensor.
134 static const u16 rca_initdata[][3] = {
135 {0, 0x0000, 0x010c},
136 {0, 0x0006, 0x012c},
137 {0, 0x0078, 0x012d},
138 {0, 0x0046, 0x012f},
139 {0, 0xd141, 0x0124},
140 {0, 0x0000, 0x0127},
141 {0, 0xfea8, 0x0124},
142 {1, 0x0000, 0x0116},
143 {0, 0x0064, 0x0116},
144 {1, 0x0000, 0x0115},
145 {0, 0x0003, 0x0115},
146 {0, 0x0008, 0x0123},
147 {0, 0x0000, 0x0117},
148 {0, 0x0000, 0x0112},
149 {0, 0x0080, 0x0100},
150 {0, 0x0000, 0x0100},
151 {1, 0x0000, 0x0116},
152 {0, 0x0060, 0x0116},
153 {0, 0x0002, 0x0112},
154 {0, 0x0000, 0x0123},
155 {0, 0x0001, 0x0117},
156 {0, 0x0040, 0x0108},
157 {0, 0x0019, 0x012c},
158 {0, 0x0040, 0x0116},
159 {0, 0x000a, 0x0115},
160 {0, 0x000b, 0x0115},
161 {0, 0x0078, 0x012d},
162 {0, 0x0046, 0x012f},
163 {0, 0xd141, 0x0124},
164 {0, 0x0000, 0x0127},
165 {0, 0xfea8, 0x0124},
166 {0, 0x0064, 0x0116},
167 {0, 0x0000, 0x0115},
168 {0, 0x0001, 0x0115},
169 {0, 0xffff, 0x0124},
170 {0, 0xfff9, 0x0124},
171 {0, 0x0086, 0x0127},
172 {0, 0xfff8, 0x0124},
173 {0, 0xfffd, 0x0124},
174 {0, 0x00aa, 0x0127},
175 {0, 0xfff8, 0x0124},
176 {0, 0xfffd, 0x0124},
177 {0, 0x0000, 0x0127},
178 {0, 0xfff8, 0x0124},
179 {0, 0xfffd, 0x0124},
180 {0, 0xfffa, 0x0124},
181 {0, 0xffff, 0x0124},
182 {0, 0xfff9, 0x0124},
183 {0, 0x0086, 0x0127},
184 {0, 0xfff8, 0x0124},
185 {0, 0xfffd, 0x0124},
186 {0, 0x00f2, 0x0127},
187 {0, 0xfff8, 0x0124},
188 {0, 0xfffd, 0x0124},
189 {0, 0x000f, 0x0127},
190 {0, 0xfff8, 0x0124},
191 {0, 0xfffd, 0x0124},
192 {0, 0xfffa, 0x0124},
193 {0, 0xffff, 0x0124},
194 {0, 0xfff9, 0x0124},
195 {0, 0x0086, 0x0127},
196 {0, 0xfff8, 0x0124},
197 {0, 0xfffd, 0x0124},
198 {0, 0x00f8, 0x0127},
199 {0, 0xfff8, 0x0124},
200 {0, 0xfffd, 0x0124},
201 {0, 0x00fc, 0x0127},
202 {0, 0xfff8, 0x0124},
203 {0, 0xfffd, 0x0124},
204 {0, 0xfffa, 0x0124},
205 {0, 0xffff, 0x0124},
206 {0, 0xfff9, 0x0124},
207 {0, 0x0086, 0x0127},
208 {0, 0xfff8, 0x0124},
209 {0, 0xfffd, 0x0124},
210 {0, 0x00f9, 0x0127},
211 {0, 0xfff8, 0x0124},
212 {0, 0xfffd, 0x0124},
213 {0, 0x003c, 0x0127},
214 {0, 0xfff8, 0x0124},
215 {0, 0xfffd, 0x0124},
216 {0, 0xfffa, 0x0124},
217 {0, 0xffff, 0x0124},
218 {0, 0xfff9, 0x0124},
219 {0, 0x0086, 0x0127},
220 {0, 0xfff8, 0x0124},
221 {0, 0xfffd, 0x0124},
222 {0, 0x0027, 0x0127},
223 {0, 0xfff8, 0x0124},
224 {0, 0xfffd, 0x0124},
225 {0, 0x0019, 0x0127},
226 {0, 0xfff8, 0x0124},
227 {0, 0xfffd, 0x0124},
228 {0, 0xfffa, 0x0124},
229 {0, 0xfff9, 0x0124},
230 {0, 0x0086, 0x0127},
231 {0, 0xfff8, 0x0124},
232 {0, 0xfffd, 0x0124},
233 {0, 0x0037, 0x0127},
234 {0, 0xfff8, 0x0124},
235 {0, 0xfffd, 0x0124},
236 {0, 0x0000, 0x0127},
237 {0, 0xfff8, 0x0124},
238 {0, 0xfffd, 0x0124},
239 {0, 0x0021, 0x0127},
240 {0, 0xfff8, 0x0124},
241 {0, 0xfffd, 0x0124},
242 {0, 0xfffa, 0x0124},
243 {0, 0xfff9, 0x0124},
244 {0, 0x0086, 0x0127},
245 {0, 0xfff8, 0x0124},
246 {0, 0xfffd, 0x0124},
247 {0, 0x0038, 0x0127},
248 {0, 0xfff8, 0x0124},
249 {0, 0xfffd, 0x0124},
250 {0, 0x0006, 0x0127},
251 {0, 0xfff8, 0x0124},
252 {0, 0xfffd, 0x0124},
253 {0, 0x0045, 0x0127},
254 {0, 0xfff8, 0x0124},
255 {0, 0xfffd, 0x0124},
256 {0, 0xfffa, 0x0124},
257 {0, 0xfff9, 0x0124},
258 {0, 0x0086, 0x0127},
259 {0, 0xfff8, 0x0124},
260 {0, 0xfffd, 0x0124},
261 {0, 0x0037, 0x0127},
262 {0, 0xfff8, 0x0124},
263 {0, 0xfffd, 0x0124},
264 {0, 0x0001, 0x0127},
265 {0, 0xfff8, 0x0124},
266 {0, 0xfffd, 0x0124},
267 {0, 0x002a, 0x0127},
268 {0, 0xfff8, 0x0124},
269 {0, 0xfffd, 0x0124},
270 {0, 0xfffa, 0x0124},
271 {0, 0xfff9, 0x0124},
272 {0, 0x0086, 0x0127},
273 {0, 0xfff8, 0x0124},
274 {0, 0xfffd, 0x0124},
275 {0, 0x0038, 0x0127},
276 {0, 0xfff8, 0x0124},
277 {0, 0xfffd, 0x0124},
278 {0, 0x0000, 0x0127},
279 {0, 0xfff8, 0x0124},
280 {0, 0xfffd, 0x0124},
281 {0, 0x000e, 0x0127},
282 {0, 0xfff8, 0x0124},
283 {0, 0xfffd, 0x0124},
284 {0, 0xfffa, 0x0124},
285 {0, 0xfff9, 0x0124},
286 {0, 0x0086, 0x0127},
287 {0, 0xfff8, 0x0124},
288 {0, 0xfffd, 0x0124},
289 {0, 0x0037, 0x0127},
290 {0, 0xfff8, 0x0124},
291 {0, 0xfffd, 0x0124},
292 {0, 0x0001, 0x0127},
293 {0, 0xfff8, 0x0124},
294 {0, 0xfffd, 0x0124},
295 {0, 0x002b, 0x0127},
296 {0, 0xfff8, 0x0124},
297 {0, 0xfffd, 0x0124},
298 {0, 0xfffa, 0x0124},
299 {0, 0xfff9, 0x0124},
300 {0, 0x0086, 0x0127},
301 {0, 0xfff8, 0x0124},
302 {0, 0xfffd, 0x0124},
303 {0, 0x0038, 0x0127},
304 {0, 0xfff8, 0x0124},
305 {0, 0xfffd, 0x0124},
306 {0, 0x0001, 0x0127},
307 {0, 0xfff8, 0x0124},
308 {0, 0xfffd, 0x0124},
309 {0, 0x00f4, 0x0127},
310 {0, 0xfff8, 0x0124},
311 {0, 0xfffd, 0x0124},
312 {0, 0xfffa, 0x0124},
313 {0, 0xfff9, 0x0124},
314 {0, 0x0086, 0x0127},
315 {0, 0xfff8, 0x0124},
316 {0, 0xfffd, 0x0124},
317 {0, 0x0037, 0x0127},
318 {0, 0xfff8, 0x0124},
319 {0, 0xfffd, 0x0124},
320 {0, 0x0001, 0x0127},
321 {0, 0xfff8, 0x0124},
322 {0, 0xfffd, 0x0124},
323 {0, 0x002c, 0x0127},
324 {0, 0xfff8, 0x0124},
325 {0, 0xfffd, 0x0124},
326 {0, 0xfffa, 0x0124},
327 {0, 0xfff9, 0x0124},
328 {0, 0x0086, 0x0127},
329 {0, 0xfff8, 0x0124},
330 {0, 0xfffd, 0x0124},
331 {0, 0x0038, 0x0127},
332 {0, 0xfff8, 0x0124},
333 {0, 0xfffd, 0x0124},
334 {0, 0x0001, 0x0127},
335 {0, 0xfff8, 0x0124},
336 {0, 0xfffd, 0x0124},
337 {0, 0x0004, 0x0127},
338 {0, 0xfff8, 0x0124},
339 {0, 0xfffd, 0x0124},
340 {0, 0xfffa, 0x0124},
341 {0, 0xfff9, 0x0124},
342 {0, 0x0086, 0x0127},
343 {0, 0xfff8, 0x0124},
344 {0, 0xfffd, 0x0124},
345 {0, 0x0037, 0x0127},
346 {0, 0xfff8, 0x0124},
347 {0, 0xfffd, 0x0124},
348 {0, 0x0001, 0x0127},
349 {0, 0xfff8, 0x0124},
350 {0, 0xfffd, 0x0124},
351 {0, 0x002d, 0x0127},
352 {0, 0xfff8, 0x0124},
353 {0, 0xfffd, 0x0124},
354 {0, 0xfffa, 0x0124},
355 {0, 0xfff9, 0x0124},
356 {0, 0x0086, 0x0127},
357 {0, 0xfff8, 0x0124},
358 {0, 0xfffd, 0x0124},
359 {0, 0x0038, 0x0127},
360 {0, 0xfff8, 0x0124},
361 {0, 0xfffd, 0x0124},
362 {0, 0x0000, 0x0127},
363 {0, 0xfff8, 0x0124},
364 {0, 0xfffd, 0x0124},
365 {0, 0x0014, 0x0127},
366 {0, 0xfff8, 0x0124},
367 {0, 0xfffd, 0x0124},
368 {0, 0xfffa, 0x0124},
369 {0, 0xfff9, 0x0124},
370 {0, 0x0086, 0x0127},
371 {0, 0xfff8, 0x0124},
372 {0, 0xfffd, 0x0124},
373 {0, 0x0037, 0x0127},
374 {0, 0xfff8, 0x0124},
375 {0, 0xfffd, 0x0124},
376 {0, 0x0001, 0x0127},
377 {0, 0xfff8, 0x0124},
378 {0, 0xfffd, 0x0124},
379 {0, 0x002e, 0x0127},
380 {0, 0xfff8, 0x0124},
381 {0, 0xfffd, 0x0124},
382 {0, 0xfffa, 0x0124},
383 {0, 0xfff9, 0x0124},
384 {0, 0x0086, 0x0127},
385 {0, 0xfff8, 0x0124},
386 {0, 0xfffd, 0x0124},
387 {0, 0x0038, 0x0127},
388 {0, 0xfff8, 0x0124},
389 {0, 0xfffd, 0x0124},
390 {0, 0x0003, 0x0127},
391 {0, 0xfff8, 0x0124},
392 {0, 0xfffd, 0x0124},
393 {0, 0x0000, 0x0127},
394 {0, 0xfff8, 0x0124},
395 {0, 0xfffd, 0x0124},
396 {0, 0xfffa, 0x0124},
397 {0, 0xfff9, 0x0124},
398 {0, 0x0086, 0x0127},
399 {0, 0xfff8, 0x0124},
400 {0, 0xfffd, 0x0124},
401 {0, 0x0037, 0x0127},
402 {0, 0xfff8, 0x0124},
403 {0, 0xfffd, 0x0124},
404 {0, 0x0001, 0x0127},
405 {0, 0xfff8, 0x0124},
406 {0, 0xfffd, 0x0124},
407 {0, 0x002f, 0x0127},
408 {0, 0xfff8, 0x0124},
409 {0, 0xfffd, 0x0124},
410 {0, 0xfffa, 0x0124},
411 {0, 0xfff9, 0x0124},
412 {0, 0x0086, 0x0127},
413 {0, 0xfff8, 0x0124},
414 {0, 0xfffd, 0x0124},
415 {0, 0x0038, 0x0127},
416 {0, 0xfff8, 0x0124},
417 {0, 0xfffd, 0x0124},
418 {0, 0x0003, 0x0127},
419 {0, 0xfff8, 0x0124},
420 {0, 0xfffd, 0x0124},
421 {0, 0x0014, 0x0127},
422 {0, 0xfff8, 0x0124},
423 {0, 0xfffd, 0x0124},
424 {0, 0xfffa, 0x0124},
425 {0, 0xfff9, 0x0124},
426 {0, 0x0086, 0x0127},
427 {0, 0xfff8, 0x0124},
428 {0, 0xfffd, 0x0124},
429 {0, 0x0037, 0x0127},
430 {0, 0xfff8, 0x0124},
431 {0, 0xfffd, 0x0124},
432 {0, 0x0001, 0x0127},
433 {0, 0xfff8, 0x0124},
434 {0, 0xfffd, 0x0124},
435 {0, 0x0040, 0x0127},
436 {0, 0xfff8, 0x0124},
437 {0, 0xfffd, 0x0124},
438 {0, 0xfffa, 0x0124},
439 {0, 0xfff9, 0x0124},
440 {0, 0x0086, 0x0127},
441 {0, 0xfff8, 0x0124},
442 {0, 0xfffd, 0x0124},
443 {0, 0x0038, 0x0127},
444 {0, 0xfff8, 0x0124},
445 {0, 0xfffd, 0x0124},
446 {0, 0x0000, 0x0127},
447 {0, 0xfff8, 0x0124},
448 {0, 0xfffd, 0x0124},
449 {0, 0x0040, 0x0127},
450 {0, 0xfff8, 0x0124},
451 {0, 0xfffd, 0x0124},
452 {0, 0xfffa, 0x0124},
453 {0, 0xfff9, 0x0124},
454 {0, 0x0086, 0x0127},
455 {0, 0xfff8, 0x0124},
456 {0, 0xfffd, 0x0124},
457 {0, 0x0037, 0x0127},
458 {0, 0xfff8, 0x0124},
459 {0, 0xfffd, 0x0124},
460 {0, 0x0001, 0x0127},
461 {0, 0xfff8, 0x0124},
462 {0, 0xfffd, 0x0124},
463 {0, 0x0053, 0x0127},
464 {0, 0xfff8, 0x0124},
465 {0, 0xfffd, 0x0124},
466 {0, 0xfffa, 0x0124},
467 {0, 0xfff9, 0x0124},
468 {0, 0x0086, 0x0127},
469 {0, 0xfff8, 0x0124},
470 {0, 0xfffd, 0x0124},
471 {0, 0x0038, 0x0127},
472 {0, 0xfff8, 0x0124},
473 {0, 0xfffd, 0x0124},
474 {0, 0x0000, 0x0127},
475 {0, 0xfff8, 0x0124},
476 {0, 0xfffd, 0x0124},
477 {0, 0x0038, 0x0127},
478 {0, 0xfff8, 0x0124},
479 {0, 0xfffd, 0x0124},
480 {0, 0xfffa, 0x0124},
481 {0, 0x0000, 0x0101},
482 {0, 0x00a0, 0x0103},
483 {0, 0x0078, 0x0105},
484 {0, 0x0000, 0x010a},
485 {0, 0x0024, 0x010b},
486 {0, 0x0028, 0x0119},
487 {0, 0x0088, 0x011b},
488 {0, 0x0002, 0x011d},
489 {0, 0x0003, 0x011e},
490 {0, 0x0000, 0x0129},
491 {0, 0x00fc, 0x012b},
492 {0, 0x0008, 0x0102},
493 {0, 0x0000, 0x0104},
494 {0, 0x0008, 0x011a},
495 {0, 0x0028, 0x011c},
496 {0, 0x0021, 0x012a},
497 {0, 0x0000, 0x0118},
498 {0, 0x0000, 0x0132},
499 {0, 0x0000, 0x0109},
500 {0, 0xfff9, 0x0124},
501 {0, 0x0086, 0x0127},
502 {0, 0xfff8, 0x0124},
503 {0, 0xfffd, 0x0124},
504 {0, 0x0037, 0x0127},
505 {0, 0xfff8, 0x0124},
506 {0, 0xfffd, 0x0124},
507 {0, 0x0001, 0x0127},
508 {0, 0xfff8, 0x0124},
509 {0, 0xfffd, 0x0124},
510 {0, 0x0031, 0x0127},
511 {0, 0xfff8, 0x0124},
512 {0, 0xfffd, 0x0124},
513 {0, 0xfffa, 0x0124},
514 {0, 0xfff9, 0x0124},
515 {0, 0x0086, 0x0127},
516 {0, 0xfff8, 0x0124},
517 {0, 0xfffd, 0x0124},
518 {0, 0x0038, 0x0127},
519 {0, 0xfff8, 0x0124},
520 {0, 0xfffd, 0x0124},
521 {0, 0x0000, 0x0127},
522 {0, 0xfff8, 0x0124},
523 {0, 0xfffd, 0x0124},
524 {0, 0x0000, 0x0127},
525 {0, 0xfff8, 0x0124},
526 {0, 0xfffd, 0x0124},
527 {0, 0xfffa, 0x0124},
528 {0, 0xfff9, 0x0124},
529 {0, 0x0086, 0x0127},
530 {0, 0xfff8, 0x0124},
531 {0, 0xfffd, 0x0124},
532 {0, 0x0037, 0x0127},
533 {0, 0xfff8, 0x0124},
534 {0, 0xfffd, 0x0124},
535 {0, 0x0001, 0x0127},
536 {0, 0xfff8, 0x0124},
537 {0, 0xfffd, 0x0124},
538 {0, 0x0040, 0x0127},
539 {0, 0xfff8, 0x0124},
540 {0, 0xfffd, 0x0124},
541 {0, 0xfffa, 0x0124},
542 {0, 0xfff9, 0x0124},
543 {0, 0x0086, 0x0127},
544 {0, 0xfff8, 0x0124},
545 {0, 0xfffd, 0x0124},
546 {0, 0x0038, 0x0127},
547 {0, 0xfff8, 0x0124},
548 {0, 0xfffd, 0x0124},
549 {0, 0x0000, 0x0127},
550 {0, 0xfff8, 0x0124},
551 {0, 0xfffd, 0x0124},
552 {0, 0x0040, 0x0127},
553 {0, 0xfff8, 0x0124},
554 {0, 0xfffd, 0x0124},
555 {0, 0xfffa, 0x0124},
556 {0, 0xfff9, 0x0124},
557 {0, 0x0086, 0x0127},
558 {0, 0xfff8, 0x0124},
559 {0, 0xfffd, 0x0124},
560 {0, 0x0037, 0x0127},
561 {0, 0xfff8, 0x0124},
562 {0, 0xfffd, 0x0124},
563 {0, 0x0000, 0x0127},
564 {0, 0xfff8, 0x0124},
565 {0, 0xfffd, 0x0124},
566 {0, 0x00dc, 0x0127},
567 {0, 0xfff8, 0x0124},
568 {0, 0xfffd, 0x0124},
569 {0, 0xfffa, 0x0124},
570 {0, 0xfff9, 0x0124},
571 {0, 0x0086, 0x0127},
572 {0, 0xfff8, 0x0124},
573 {0, 0xfffd, 0x0124},
574 {0, 0x0038, 0x0127},
575 {0, 0xfff8, 0x0124},
576 {0, 0xfffd, 0x0124},
577 {0, 0x0000, 0x0127},
578 {0, 0xfff8, 0x0124},
579 {0, 0xfffd, 0x0124},
580 {0, 0x0000, 0x0127},
581 {0, 0xfff8, 0x0124},
582 {0, 0xfffd, 0x0124},
583 {0, 0xfffa, 0x0124},
584 {0, 0xfff9, 0x0124},
585 {0, 0x0086, 0x0127},
586 {0, 0xfff8, 0x0124},
587 {0, 0xfffd, 0x0124},
588 {0, 0x0037, 0x0127},
589 {0, 0xfff8, 0x0124},
590 {0, 0xfffd, 0x0124},
591 {0, 0x0001, 0x0127},
592 {0, 0xfff8, 0x0124},
593 {0, 0xfffd, 0x0124},
594 {0, 0x0032, 0x0127},
595 {0, 0xfff8, 0x0124},
596 {0, 0xfffd, 0x0124},
597 {0, 0xfffa, 0x0124},
598 {0, 0xfff9, 0x0124},
599 {0, 0x0086, 0x0127},
600 {0, 0xfff8, 0x0124},
601 {0, 0xfffd, 0x0124},
602 {0, 0x0038, 0x0127},
603 {0, 0xfff8, 0x0124},
604 {0, 0xfffd, 0x0124},
605 {0, 0x0001, 0x0127},
606 {0, 0xfff8, 0x0124},
607 {0, 0xfffd, 0x0124},
608 {0, 0x0020, 0x0127},
609 {0, 0xfff8, 0x0124},
610 {0, 0xfffd, 0x0124},
611 {0, 0xfffa, 0x0124},
612 {0, 0xfff9, 0x0124},
613 {0, 0x0086, 0x0127},
614 {0, 0xfff8, 0x0124},
615 {0, 0xfffd, 0x0124},
616 {0, 0x0037, 0x0127},
617 {0, 0xfff8, 0x0124},
618 {0, 0xfffd, 0x0124},
619 {0, 0x0001, 0x0127},
620 {0, 0xfff8, 0x0124},
621 {0, 0xfffd, 0x0124},
622 {0, 0x0040, 0x0127},
623 {0, 0xfff8, 0x0124},
624 {0, 0xfffd, 0x0124},
625 {0, 0xfffa, 0x0124},
626 {0, 0xfff9, 0x0124},
627 {0, 0x0086, 0x0127},
628 {0, 0xfff8, 0x0124},
629 {0, 0xfffd, 0x0124},
630 {0, 0x0038, 0x0127},
631 {0, 0xfff8, 0x0124},
632 {0, 0xfffd, 0x0124},
633 {0, 0x0000, 0x0127},
634 {0, 0xfff8, 0x0124},
635 {0, 0xfffd, 0x0124},
636 {0, 0x0040, 0x0127},
637 {0, 0xfff8, 0x0124},
638 {0, 0xfffd, 0x0124},
639 {0, 0xfffa, 0x0124},
640 {0, 0xfff9, 0x0124},
641 {0, 0x0086, 0x0127},
642 {0, 0xfff8, 0x0124},
643 {0, 0xfffd, 0x0124},
644 {0, 0x0037, 0x0127},
645 {0, 0xfff8, 0x0124},
646 {0, 0xfffd, 0x0124},
647 {0, 0x0000, 0x0127},
648 {0, 0xfff8, 0x0124},
649 {0, 0xfffd, 0x0124},
650 {0, 0x0030, 0x0127},
651 {0, 0xfff8, 0x0124},
652 {0, 0xfffd, 0x0124},
653 {0, 0xfffa, 0x0124},
654 {0, 0xfff9, 0x0124},
655 {0, 0x0086, 0x0127},
656 {0, 0xfff8, 0x0124},
657 {0, 0xfffd, 0x0124},
658 {0, 0x0038, 0x0127},
659 {0, 0xfff8, 0x0124},
660 {0, 0xfffd, 0x0124},
661 {0, 0x0008, 0x0127},
662 {0, 0xfff8, 0x0124},
663 {0, 0xfffd, 0x0124},
664 {0, 0x0000, 0x0127},
665 {0, 0xfff8, 0x0124},
666 {0, 0xfffd, 0x0124},
667 {0, 0xfffa, 0x0124},
668 {0, 0x0003, 0x0111},
671 /* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we
672 do the same for now (testing needed to see if this is really necessary) */
673 static const int cit_model1_ntries = 5;
674 static const int cit_model1_ntries2 = 2;
676 static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
678 struct usb_device *udev = gspca_dev->dev;
679 int err;
681 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
682 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
683 value, index, NULL, 0, 1000);
684 if (err < 0)
685 pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
686 index, value, err);
688 return 0;
691 static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose)
693 struct usb_device *udev = gspca_dev->dev;
694 __u8 *buf = gspca_dev->usb_buf;
695 int res;
697 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01,
698 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
699 0x00, index, buf, 8, 1000);
700 if (res < 0) {
701 pr_err("Failed to read a register (index 0x%04X, error %d)\n",
702 index, res);
703 return res;
706 if (verbose)
707 gspca_dbg(gspca_dev, D_PROBE, "Register %04x value: %02x\n",
708 index, buf[0]);
710 return 0;
714 * cit_send_FF_04_02()
716 * This procedure sends magic 3-command prefix to the camera.
717 * The purpose of this prefix is not known.
719 * History:
720 * 1/2/00 Created.
722 static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
724 cit_write_reg(gspca_dev, 0x00FF, 0x0127);
725 cit_write_reg(gspca_dev, 0x0004, 0x0124);
726 cit_write_reg(gspca_dev, 0x0002, 0x0124);
729 static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
731 cit_write_reg(gspca_dev, 0x0000, 0x0127);
732 cit_write_reg(gspca_dev, 0x0004, 0x0124);
733 cit_write_reg(gspca_dev, 0x0006, 0x0124);
736 static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
738 cit_write_reg(gspca_dev, x, 0x0127);
739 cit_write_reg(gspca_dev, 0x0000, 0x0124);
742 static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
744 cit_send_x_00(gspca_dev, x);
745 cit_write_reg(gspca_dev, 0x0005, 0x0124);
748 static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
750 cit_write_reg(gspca_dev, x, 0x0127);
751 cit_write_reg(gspca_dev, 0x0000, 0x0124);
752 cit_write_reg(gspca_dev, 0x0005, 0x0124);
753 cit_write_reg(gspca_dev, 0x0002, 0x0124);
756 static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
758 cit_write_reg(gspca_dev, x, 0x0127);
759 cit_write_reg(gspca_dev, 0x0001, 0x0124);
760 cit_write_reg(gspca_dev, 0x0000, 0x0124);
761 cit_write_reg(gspca_dev, 0x0005, 0x0124);
764 static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
766 cit_write_reg(gspca_dev, x, 0x0127);
767 cit_write_reg(gspca_dev, 0x0000, 0x0124);
768 cit_write_reg(gspca_dev, 0x0005, 0x0124);
769 cit_write_reg(gspca_dev, 0x0002, 0x0124);
770 cit_write_reg(gspca_dev, 0x0001, 0x0124);
773 static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
775 cit_write_reg(gspca_dev, x, 0x0127);
776 cit_write_reg(gspca_dev, 0x0000, 0x0124);
777 cit_write_reg(gspca_dev, 0x0005, 0x0124);
778 cit_write_reg(gspca_dev, 0x0002, 0x0124);
779 cit_write_reg(gspca_dev, 0x0008, 0x0124);
780 cit_write_reg(gspca_dev, 0x0001, 0x0124);
783 static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
785 cit_send_x_01_00_05(gspca_dev, 0x0088);
786 cit_send_x_00_05(gspca_dev, fkey);
787 cit_send_x_00_05_02_08_01(gspca_dev, val);
788 cit_send_x_00_05(gspca_dev, 0x0088);
789 cit_send_x_00_05_02_01(gspca_dev, fkey);
790 cit_send_x_00_05(gspca_dev, 0x0089);
791 cit_send_x_00(gspca_dev, fkey);
792 cit_send_00_04_06(gspca_dev);
793 cit_read_reg(gspca_dev, 0x0126, 0);
794 cit_send_FF_04_02(gspca_dev);
797 static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
799 cit_send_x_01_00_05(gspca_dev, 0x0088);
800 cit_send_x_00_05(gspca_dev, fkey);
801 cit_send_x_00_05_02(gspca_dev, val);
804 static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
806 cit_write_reg(gspca_dev, 0x00ff, 0x012d);
807 cit_write_reg(gspca_dev, 0xfea3, 0x0124);
810 static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
812 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
813 cit_write_reg(gspca_dev, 0x00ff, 0x012e);
814 cit_write_reg(gspca_dev, v1, 0x012f);
815 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
816 cit_write_reg(gspca_dev, 0xc719, 0x0124);
817 cit_write_reg(gspca_dev, v2, 0x0127);
819 cit_model2_Packet2(gspca_dev);
823 * cit_model3_Packet1()
825 * 00_0078_012d
826 * 00_0097_012f
827 * 00_d141_0124
828 * 00_0096_0127
829 * 00_fea8_0124
831 static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
833 cit_write_reg(gspca_dev, 0x0078, 0x012d);
834 cit_write_reg(gspca_dev, v1, 0x012f);
835 cit_write_reg(gspca_dev, 0xd141, 0x0124);
836 cit_write_reg(gspca_dev, v2, 0x0127);
837 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
840 static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
842 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
843 cit_write_reg(gspca_dev, v1, 0x012f);
844 cit_write_reg(gspca_dev, 0xd141, 0x0124);
845 cit_write_reg(gspca_dev, v2, 0x0127);
846 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
849 static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
851 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
852 cit_write_reg(gspca_dev, 0x0026, 0x012f);
853 cit_write_reg(gspca_dev, 0xd141, 0x0124);
854 cit_write_reg(gspca_dev, val, 0x0127);
855 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
856 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
857 cit_write_reg(gspca_dev, 0x0038, 0x012d);
858 cit_write_reg(gspca_dev, 0x0004, 0x012f);
859 cit_write_reg(gspca_dev, 0xd145, 0x0124);
860 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
863 /* this function is called at probe time */
864 static int sd_config(struct gspca_dev *gspca_dev,
865 const struct usb_device_id *id)
867 struct sd *sd = (struct sd *) gspca_dev;
868 struct cam *cam;
870 sd->model = id->driver_info;
871 if (sd->model == CIT_MODEL3 && ibm_netcam_pro)
872 sd->model = CIT_IBM_NETCAM_PRO;
874 cam = &gspca_dev->cam;
875 switch (sd->model) {
876 case CIT_MODEL0:
877 cam->cam_mode = model0_mode;
878 cam->nmodes = ARRAY_SIZE(model0_mode);
879 sd->sof_len = 4;
880 break;
881 case CIT_MODEL1:
882 cam->cam_mode = cif_yuv_mode;
883 cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
884 sd->sof_len = 4;
885 break;
886 case CIT_MODEL2:
887 cam->cam_mode = model2_mode + 1; /* no 160x120 */
888 cam->nmodes = 3;
889 break;
890 case CIT_MODEL3:
891 cam->cam_mode = vga_yuv_mode;
892 cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
893 sd->stop_on_control_change = 1;
894 sd->sof_len = 4;
895 break;
896 case CIT_MODEL4:
897 cam->cam_mode = model2_mode;
898 cam->nmodes = ARRAY_SIZE(model2_mode);
899 break;
900 case CIT_IBM_NETCAM_PRO:
901 cam->cam_mode = vga_yuv_mode;
902 cam->nmodes = 2; /* no 640 x 480 */
903 cam->input_flags = V4L2_IN_ST_VFLIP;
904 sd->stop_on_control_change = 1;
905 sd->sof_len = 4;
906 break;
909 return 0;
912 static int cit_init_model0(struct gspca_dev *gspca_dev)
914 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
915 cit_write_reg(gspca_dev, 0x0001, 0x0112); /* turn on autogain ? */
916 cit_write_reg(gspca_dev, 0x0000, 0x0400);
917 cit_write_reg(gspca_dev, 0x0001, 0x0400);
918 cit_write_reg(gspca_dev, 0x0000, 0x0420);
919 cit_write_reg(gspca_dev, 0x0001, 0x0420);
920 cit_write_reg(gspca_dev, 0x000d, 0x0409);
921 cit_write_reg(gspca_dev, 0x0002, 0x040a);
922 cit_write_reg(gspca_dev, 0x0018, 0x0405);
923 cit_write_reg(gspca_dev, 0x0008, 0x0435);
924 cit_write_reg(gspca_dev, 0x0026, 0x040b);
925 cit_write_reg(gspca_dev, 0x0007, 0x0437);
926 cit_write_reg(gspca_dev, 0x0015, 0x042f);
927 cit_write_reg(gspca_dev, 0x002b, 0x0439);
928 cit_write_reg(gspca_dev, 0x0026, 0x043a);
929 cit_write_reg(gspca_dev, 0x0008, 0x0438);
930 cit_write_reg(gspca_dev, 0x001e, 0x042b);
931 cit_write_reg(gspca_dev, 0x0041, 0x042c);
933 return 0;
936 static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
938 cit_read_reg(gspca_dev, 0x128, 1);
939 cit_write_reg(gspca_dev, 0x0003, 0x0133);
940 cit_write_reg(gspca_dev, 0x0000, 0x0117);
941 cit_write_reg(gspca_dev, 0x0008, 0x0123);
942 cit_write_reg(gspca_dev, 0x0000, 0x0100);
943 cit_read_reg(gspca_dev, 0x0116, 0);
944 cit_write_reg(gspca_dev, 0x0060, 0x0116);
945 cit_write_reg(gspca_dev, 0x0002, 0x0112);
946 cit_write_reg(gspca_dev, 0x0000, 0x0133);
947 cit_write_reg(gspca_dev, 0x0000, 0x0123);
948 cit_write_reg(gspca_dev, 0x0001, 0x0117);
949 cit_write_reg(gspca_dev, 0x0040, 0x0108);
950 cit_write_reg(gspca_dev, 0x0019, 0x012c);
951 cit_write_reg(gspca_dev, 0x0060, 0x0116);
952 cit_write_reg(gspca_dev, 0x0002, 0x0115);
953 cit_write_reg(gspca_dev, 0x000b, 0x0115);
955 cit_write_reg(gspca_dev, 0x0078, 0x012d);
956 cit_write_reg(gspca_dev, 0x0001, 0x012f);
957 cit_write_reg(gspca_dev, 0xd141, 0x0124);
958 cit_write_reg(gspca_dev, 0x0079, 0x012d);
959 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
960 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
961 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
962 cit_read_reg(gspca_dev, 0x0126, 1);
964 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000);
965 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001);
966 cit_model3_Packet1(gspca_dev, 0x000b, 0x0000);
967 cit_model3_Packet1(gspca_dev, 0x000c, 0x0008);
968 cit_model3_Packet1(gspca_dev, 0x000d, 0x003a);
969 cit_model3_Packet1(gspca_dev, 0x000e, 0x0060);
970 cit_model3_Packet1(gspca_dev, 0x000f, 0x0060);
971 cit_model3_Packet1(gspca_dev, 0x0010, 0x0008);
972 cit_model3_Packet1(gspca_dev, 0x0011, 0x0004);
973 cit_model3_Packet1(gspca_dev, 0x0012, 0x0028);
974 cit_model3_Packet1(gspca_dev, 0x0013, 0x0002);
975 cit_model3_Packet1(gspca_dev, 0x0014, 0x0000);
976 cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb);
977 cit_model3_Packet1(gspca_dev, 0x0016, 0x0002);
978 cit_model3_Packet1(gspca_dev, 0x0017, 0x0037);
979 cit_model3_Packet1(gspca_dev, 0x0018, 0x0036);
980 cit_model3_Packet1(gspca_dev, 0x001e, 0x0000);
981 cit_model3_Packet1(gspca_dev, 0x001f, 0x0008);
982 cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1);
983 cit_model3_Packet1(gspca_dev, 0x0021, 0x0034);
984 cit_model3_Packet1(gspca_dev, 0x0022, 0x0034);
985 cit_model3_Packet1(gspca_dev, 0x0025, 0x0002);
986 cit_model3_Packet1(gspca_dev, 0x0028, 0x0022);
987 cit_model3_Packet1(gspca_dev, 0x0029, 0x000a);
988 cit_model3_Packet1(gspca_dev, 0x002b, 0x0000);
989 cit_model3_Packet1(gspca_dev, 0x002c, 0x0000);
990 cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff);
991 cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff);
992 cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff);
993 cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff);
994 cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff);
995 cit_model3_Packet1(gspca_dev, 0x0032, 0x0007);
996 cit_model3_Packet1(gspca_dev, 0x0033, 0x0005);
997 cit_model3_Packet1(gspca_dev, 0x0037, 0x0040);
998 cit_model3_Packet1(gspca_dev, 0x0039, 0x0000);
999 cit_model3_Packet1(gspca_dev, 0x003a, 0x0000);
1000 cit_model3_Packet1(gspca_dev, 0x003b, 0x0001);
1001 cit_model3_Packet1(gspca_dev, 0x003c, 0x0000);
1002 cit_model3_Packet1(gspca_dev, 0x0040, 0x000c);
1003 cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb);
1004 cit_model3_Packet1(gspca_dev, 0x0042, 0x0002);
1005 cit_model3_Packet1(gspca_dev, 0x0043, 0x0000);
1006 cit_model3_Packet1(gspca_dev, 0x0045, 0x0000);
1007 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
1008 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
1009 cit_model3_Packet1(gspca_dev, 0x0048, 0x0000);
1010 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
1011 cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff);
1012 cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff);
1013 cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff);
1014 cit_model3_Packet1(gspca_dev, 0x004f, 0x0000);
1015 cit_model3_Packet1(gspca_dev, 0x0050, 0x0000);
1016 cit_model3_Packet1(gspca_dev, 0x0051, 0x0002);
1017 cit_model3_Packet1(gspca_dev, 0x0055, 0x0000);
1018 cit_model3_Packet1(gspca_dev, 0x0056, 0x0000);
1019 cit_model3_Packet1(gspca_dev, 0x0057, 0x0000);
1020 cit_model3_Packet1(gspca_dev, 0x0058, 0x0002);
1021 cit_model3_Packet1(gspca_dev, 0x0059, 0x0000);
1022 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016);
1023 cit_model3_Packet1(gspca_dev, 0x005d, 0x0022);
1024 cit_model3_Packet1(gspca_dev, 0x005e, 0x003c);
1025 cit_model3_Packet1(gspca_dev, 0x005f, 0x0050);
1026 cit_model3_Packet1(gspca_dev, 0x0060, 0x0044);
1027 cit_model3_Packet1(gspca_dev, 0x0061, 0x0005);
1028 cit_model3_Packet1(gspca_dev, 0x006a, 0x007e);
1029 cit_model3_Packet1(gspca_dev, 0x006f, 0x0000);
1030 cit_model3_Packet1(gspca_dev, 0x0072, 0x001b);
1031 cit_model3_Packet1(gspca_dev, 0x0073, 0x0005);
1032 cit_model3_Packet1(gspca_dev, 0x0074, 0x000a);
1033 cit_model3_Packet1(gspca_dev, 0x0075, 0x001b);
1034 cit_model3_Packet1(gspca_dev, 0x0076, 0x002a);
1035 cit_model3_Packet1(gspca_dev, 0x0077, 0x003c);
1036 cit_model3_Packet1(gspca_dev, 0x0078, 0x0050);
1037 cit_model3_Packet1(gspca_dev, 0x007b, 0x0000);
1038 cit_model3_Packet1(gspca_dev, 0x007c, 0x0011);
1039 cit_model3_Packet1(gspca_dev, 0x007d, 0x0024);
1040 cit_model3_Packet1(gspca_dev, 0x007e, 0x0043);
1041 cit_model3_Packet1(gspca_dev, 0x007f, 0x005a);
1042 cit_model3_Packet1(gspca_dev, 0x0084, 0x0020);
1043 cit_model3_Packet1(gspca_dev, 0x0085, 0x0033);
1044 cit_model3_Packet1(gspca_dev, 0x0086, 0x000a);
1045 cit_model3_Packet1(gspca_dev, 0x0087, 0x0030);
1046 cit_model3_Packet1(gspca_dev, 0x0088, 0x0070);
1047 cit_model3_Packet1(gspca_dev, 0x008b, 0x0008);
1048 cit_model3_Packet1(gspca_dev, 0x008f, 0x0000);
1049 cit_model3_Packet1(gspca_dev, 0x0090, 0x0006);
1050 cit_model3_Packet1(gspca_dev, 0x0091, 0x0028);
1051 cit_model3_Packet1(gspca_dev, 0x0092, 0x005a);
1052 cit_model3_Packet1(gspca_dev, 0x0093, 0x0082);
1053 cit_model3_Packet1(gspca_dev, 0x0096, 0x0014);
1054 cit_model3_Packet1(gspca_dev, 0x0097, 0x0020);
1055 cit_model3_Packet1(gspca_dev, 0x0098, 0x0000);
1056 cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046);
1057 cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000);
1058 cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000);
1059 cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004);
1060 cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007);
1061 cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002);
1062 cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004);
1063 cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000);
1064 cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001);
1065 cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000);
1066 cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000);
1067 cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8);
1068 cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014);
1069 cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001);
1070 cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000);
1071 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004);
1072 cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf);
1073 cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf);
1074 cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf);
1075 cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000);
1076 cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020);
1077 cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040);
1078 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1079 cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
1080 cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf);
1081 cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf);
1082 cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008);
1083 cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000);
1084 cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8);
1085 cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001);
1086 cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022);
1087 cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000);
1088 cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028);
1089 cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002);
1090 cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000);
1091 cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000);
1092 cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001);
1093 cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000);
1094 cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000);
1095 cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000);
1096 cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000);
1098 cit_model3_Packet1(gspca_dev, 0x00be, 0x0003);
1099 cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000);
1100 cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020);
1101 cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040);
1102 cit_model3_Packet1(gspca_dev, 0x0053, 0x0001);
1103 cit_model3_Packet1(gspca_dev, 0x0082, 0x000e);
1104 cit_model3_Packet1(gspca_dev, 0x0083, 0x0020);
1105 cit_model3_Packet1(gspca_dev, 0x0034, 0x003c);
1106 cit_model3_Packet1(gspca_dev, 0x006e, 0x0055);
1107 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005);
1108 cit_model3_Packet1(gspca_dev, 0x0063, 0x0008);
1109 cit_model3_Packet1(gspca_dev, 0x0066, 0x000a);
1110 cit_model3_Packet1(gspca_dev, 0x0067, 0x0006);
1111 cit_model3_Packet1(gspca_dev, 0x006b, 0x0010);
1112 cit_model3_Packet1(gspca_dev, 0x005a, 0x0001);
1113 cit_model3_Packet1(gspca_dev, 0x005b, 0x000a);
1114 cit_model3_Packet1(gspca_dev, 0x0023, 0x0006);
1115 cit_model3_Packet1(gspca_dev, 0x0026, 0x0004);
1116 cit_model3_Packet1(gspca_dev, 0x0036, 0x0069);
1117 cit_model3_Packet1(gspca_dev, 0x0038, 0x0064);
1118 cit_model3_Packet1(gspca_dev, 0x003d, 0x0003);
1119 cit_model3_Packet1(gspca_dev, 0x003e, 0x0001);
1120 cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014);
1121 cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014);
1122 cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004);
1123 cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001);
1125 return 0;
1128 /* this function is called at probe and resume time */
1129 static int sd_init(struct gspca_dev *gspca_dev)
1131 struct sd *sd = (struct sd *) gspca_dev;
1133 switch (sd->model) {
1134 case CIT_MODEL0:
1135 cit_init_model0(gspca_dev);
1136 sd_stop0(gspca_dev);
1137 break;
1138 case CIT_MODEL1:
1139 case CIT_MODEL2:
1140 case CIT_MODEL3:
1141 case CIT_MODEL4:
1142 break; /* All is done in sd_start */
1143 case CIT_IBM_NETCAM_PRO:
1144 cit_init_ibm_netcam_pro(gspca_dev);
1145 sd_stop0(gspca_dev);
1146 break;
1148 return 0;
1151 static int cit_set_brightness(struct gspca_dev *gspca_dev, s32 val)
1153 struct sd *sd = (struct sd *) gspca_dev;
1154 int i;
1156 switch (sd->model) {
1157 case CIT_MODEL0:
1158 case CIT_IBM_NETCAM_PRO:
1159 /* No (known) brightness control for these */
1160 break;
1161 case CIT_MODEL1:
1162 /* Model 1: Brightness range 0 - 63 */
1163 cit_Packet_Format1(gspca_dev, 0x0031, val);
1164 cit_Packet_Format1(gspca_dev, 0x0032, val);
1165 cit_Packet_Format1(gspca_dev, 0x0033, val);
1166 break;
1167 case CIT_MODEL2:
1168 /* Model 2: Brightness range 0x60 - 0xee */
1169 /* Scale 0 - 63 to 0x60 - 0xee */
1170 i = 0x60 + val * 2254 / 1000;
1171 cit_model2_Packet1(gspca_dev, 0x001a, i);
1172 break;
1173 case CIT_MODEL3:
1174 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
1175 i = val;
1176 if (i < 0x0c)
1177 i = 0x0c;
1178 cit_model3_Packet1(gspca_dev, 0x0036, i);
1179 break;
1180 case CIT_MODEL4:
1181 /* Model 4: Brightness range 'i' in [0x04..0xb4] */
1182 /* Scale 0 - 63 to 0x04 - 0xb4 */
1183 i = 0x04 + val * 2794 / 1000;
1184 cit_model4_BrightnessPacket(gspca_dev, i);
1185 break;
1188 return 0;
1191 static int cit_set_contrast(struct gspca_dev *gspca_dev, s32 val)
1193 struct sd *sd = (struct sd *) gspca_dev;
1195 switch (sd->model) {
1196 case CIT_MODEL0: {
1197 int i;
1198 /* gain 0-15, 0-20 -> 0-15 */
1199 i = val * 1000 / 1333;
1200 cit_write_reg(gspca_dev, i, 0x0422);
1201 /* gain 0-31, may not be lower then 0x0422, 0-20 -> 0-31 */
1202 i = val * 2000 / 1333;
1203 cit_write_reg(gspca_dev, i, 0x0423);
1204 /* gain 0-127, may not be lower then 0x0423, 0-20 -> 0-63 */
1205 i = val * 4000 / 1333;
1206 cit_write_reg(gspca_dev, i, 0x0424);
1207 /* gain 0-127, may not be lower then 0x0424, , 0-20 -> 0-127 */
1208 i = val * 8000 / 1333;
1209 cit_write_reg(gspca_dev, i, 0x0425);
1210 break;
1212 case CIT_MODEL2:
1213 case CIT_MODEL4:
1214 /* These models do not have this control. */
1215 break;
1216 case CIT_MODEL1:
1218 /* Scale 0 - 20 to 15 - 0 */
1219 int i, new_contrast = (20 - val) * 1000 / 1333;
1220 for (i = 0; i < cit_model1_ntries; i++) {
1221 cit_Packet_Format1(gspca_dev, 0x0014, new_contrast);
1222 cit_send_FF_04_02(gspca_dev);
1224 break;
1226 case CIT_MODEL3:
1227 { /* Preset hardware values */
1228 static const struct {
1229 unsigned short cv1;
1230 unsigned short cv2;
1231 unsigned short cv3;
1232 } cv[7] = {
1233 { 0x05, 0x05, 0x0f }, /* Minimum */
1234 { 0x04, 0x04, 0x16 },
1235 { 0x02, 0x03, 0x16 },
1236 { 0x02, 0x08, 0x16 },
1237 { 0x01, 0x0c, 0x16 },
1238 { 0x01, 0x0e, 0x16 },
1239 { 0x01, 0x10, 0x16 } /* Maximum */
1241 int i = val / 3;
1242 cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1);
1243 cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2);
1244 cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3);
1245 break;
1247 case CIT_IBM_NETCAM_PRO:
1248 cit_model3_Packet1(gspca_dev, 0x005b, val + 1);
1249 break;
1251 return 0;
1254 static int cit_set_hue(struct gspca_dev *gspca_dev, s32 val)
1256 struct sd *sd = (struct sd *) gspca_dev;
1258 switch (sd->model) {
1259 case CIT_MODEL0:
1260 case CIT_MODEL1:
1261 case CIT_IBM_NETCAM_PRO:
1262 /* No hue control for these models */
1263 break;
1264 case CIT_MODEL2:
1265 cit_model2_Packet1(gspca_dev, 0x0024, val);
1266 /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */
1267 break;
1268 case CIT_MODEL3: {
1269 /* Model 3: Brightness range 'i' in [0x05..0x37] */
1270 /* TESTME according to the ibmcam driver this does not work */
1271 if (0) {
1272 /* Scale 0 - 127 to 0x05 - 0x37 */
1273 int i = 0x05 + val * 1000 / 2540;
1274 cit_model3_Packet1(gspca_dev, 0x007e, i);
1276 break;
1278 case CIT_MODEL4:
1279 /* HDG: taken from ibmcam, setting the color gains does not
1280 * really belong here.
1282 * I am not sure r/g/b_gain variables exactly control gain
1283 * of those channels. Most likely they subtly change some
1284 * very internal image processing settings in the camera.
1285 * In any case, here is what they do, and feel free to tweak:
1287 * r_gain: seriously affects red gain
1288 * g_gain: seriously affects green gain
1289 * b_gain: seriously affects blue gain
1290 * hue: changes average color from violet (0) to red (0xFF)
1292 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
1293 cit_write_reg(gspca_dev, 0x001e, 0x012f);
1294 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1295 cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */
1296 cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */
1297 cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */
1298 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
1299 cit_write_reg(gspca_dev, val, 0x012d); /* Hue */
1300 cit_write_reg(gspca_dev, 0xf545, 0x0124);
1301 break;
1303 return 0;
1306 static int cit_set_sharpness(struct gspca_dev *gspca_dev, s32 val)
1308 struct sd *sd = (struct sd *) gspca_dev;
1310 switch (sd->model) {
1311 case CIT_MODEL0:
1312 case CIT_MODEL2:
1313 case CIT_MODEL4:
1314 case CIT_IBM_NETCAM_PRO:
1315 /* These models do not have this control */
1316 break;
1317 case CIT_MODEL1: {
1318 int i;
1319 static const unsigned short sa[] = {
1320 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
1322 for (i = 0; i < cit_model1_ntries; i++)
1323 cit_PacketFormat2(gspca_dev, 0x0013, sa[val]);
1324 break;
1326 case CIT_MODEL3:
1327 { /*
1328 * "Use a table of magic numbers.
1329 * This setting doesn't really change much.
1330 * But that's how Windows does it."
1332 static const struct {
1333 unsigned short sv1;
1334 unsigned short sv2;
1335 unsigned short sv3;
1336 unsigned short sv4;
1337 } sv[7] = {
1338 { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */
1339 { 0x01, 0x04, 0x05, 0x14 },
1340 { 0x02, 0x04, 0x05, 0x14 },
1341 { 0x03, 0x04, 0x05, 0x14 },
1342 { 0x03, 0x05, 0x05, 0x14 },
1343 { 0x03, 0x06, 0x05, 0x14 },
1344 { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */
1346 cit_model3_Packet1(gspca_dev, 0x0060, sv[val].sv1);
1347 cit_model3_Packet1(gspca_dev, 0x0061, sv[val].sv2);
1348 cit_model3_Packet1(gspca_dev, 0x0062, sv[val].sv3);
1349 cit_model3_Packet1(gspca_dev, 0x0063, sv[val].sv4);
1350 break;
1353 return 0;
1357 * cit_set_lighting()
1359 * Camera model 1:
1360 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
1362 * Camera model 2:
1363 * We have 16 levels of lighting, 0 for bright light and up to 15 for
1364 * low light. But values above 5 or so are useless because camera is
1365 * not really capable to produce anything worth viewing at such light.
1366 * This setting may be altered only in certain camera state.
1368 * Low lighting forces slower FPS.
1370 * History:
1371 * 1/5/00 Created.
1372 * 2/20/00 Added support for Model 2 cameras.
1374 static void cit_set_lighting(struct gspca_dev *gspca_dev, s32 val)
1376 struct sd *sd = (struct sd *) gspca_dev;
1378 switch (sd->model) {
1379 case CIT_MODEL0:
1380 case CIT_MODEL2:
1381 case CIT_MODEL3:
1382 case CIT_MODEL4:
1383 case CIT_IBM_NETCAM_PRO:
1384 break;
1385 case CIT_MODEL1: {
1386 int i;
1387 for (i = 0; i < cit_model1_ntries; i++)
1388 cit_Packet_Format1(gspca_dev, 0x0027, val);
1389 break;
1394 static void cit_set_hflip(struct gspca_dev *gspca_dev, s32 val)
1396 struct sd *sd = (struct sd *) gspca_dev;
1398 switch (sd->model) {
1399 case CIT_MODEL0:
1400 if (val)
1401 cit_write_reg(gspca_dev, 0x0020, 0x0115);
1402 else
1403 cit_write_reg(gspca_dev, 0x0040, 0x0115);
1404 break;
1405 case CIT_MODEL1:
1406 case CIT_MODEL2:
1407 case CIT_MODEL3:
1408 case CIT_MODEL4:
1409 case CIT_IBM_NETCAM_PRO:
1410 break;
1414 static int cit_restart_stream(struct gspca_dev *gspca_dev)
1416 struct sd *sd = (struct sd *) gspca_dev;
1418 switch (sd->model) {
1419 case CIT_MODEL0:
1420 case CIT_MODEL1:
1421 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1422 /* Fall through */
1423 case CIT_MODEL2:
1424 case CIT_MODEL4:
1425 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1426 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1427 break;
1428 case CIT_MODEL3:
1429 case CIT_IBM_NETCAM_PRO:
1430 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1431 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1432 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1433 /* Clear button events from while we were not streaming */
1434 cit_write_reg(gspca_dev, 0x0001, 0x0113);
1435 break;
1438 sd->sof_read = 0;
1440 return 0;
1443 static int cit_get_packet_size(struct gspca_dev *gspca_dev)
1445 struct usb_host_interface *alt;
1446 struct usb_interface *intf;
1448 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
1449 alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
1450 if (!alt) {
1451 pr_err("Couldn't get altsetting\n");
1452 return -EIO;
1455 if (alt->desc.bNumEndpoints < 1)
1456 return -ENODEV;
1458 return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
1461 /* Calculate the clockdiv giving us max fps given the available bandwidth */
1462 static int cit_get_clock_div(struct gspca_dev *gspca_dev)
1464 int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */
1465 int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 };
1466 int packet_size;
1468 packet_size = cit_get_packet_size(gspca_dev);
1469 if (packet_size < 0)
1470 return packet_size;
1472 while (clock_div > 3 &&
1473 1000 * packet_size >
1474 gspca_dev->pixfmt.width * gspca_dev->pixfmt.height *
1475 fps[clock_div - 1] * 3 / 2)
1476 clock_div--;
1478 gspca_dbg(gspca_dev, D_PROBE,
1479 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)\n",
1480 packet_size,
1481 gspca_dev->pixfmt.width, gspca_dev->pixfmt.height,
1482 clock_div, fps[clock_div]);
1484 return clock_div;
1487 static int cit_start_model0(struct gspca_dev *gspca_dev)
1489 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1490 int clock_div;
1492 clock_div = cit_get_clock_div(gspca_dev);
1493 if (clock_div < 0)
1494 return clock_div;
1496 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
1497 cit_write_reg(gspca_dev, 0x0003, 0x0438);
1498 cit_write_reg(gspca_dev, 0x001e, 0x042b);
1499 cit_write_reg(gspca_dev, 0x0041, 0x042c);
1500 cit_write_reg(gspca_dev, 0x0008, 0x0436);
1501 cit_write_reg(gspca_dev, 0x0024, 0x0403);
1502 cit_write_reg(gspca_dev, 0x002c, 0x0404);
1503 cit_write_reg(gspca_dev, 0x0002, 0x0426);
1504 cit_write_reg(gspca_dev, 0x0014, 0x0427);
1506 switch (gspca_dev->pixfmt.width) {
1507 case 160: /* 160x120 */
1508 cit_write_reg(gspca_dev, 0x0004, 0x010b);
1509 cit_write_reg(gspca_dev, 0x0001, 0x010a);
1510 cit_write_reg(gspca_dev, 0x0010, 0x0102);
1511 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1512 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1513 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1514 break;
1516 case 176: /* 176x144 */
1517 cit_write_reg(gspca_dev, 0x0006, 0x010b);
1518 cit_write_reg(gspca_dev, 0x0000, 0x010a);
1519 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1520 cit_write_reg(gspca_dev, 0x00b0, 0x0103);
1521 cit_write_reg(gspca_dev, 0x0000, 0x0104);
1522 cit_write_reg(gspca_dev, 0x0090, 0x0105);
1523 break;
1525 case 320: /* 320x240 */
1526 cit_write_reg(gspca_dev, 0x0008, 0x010b);
1527 cit_write_reg(gspca_dev, 0x0004, 0x010a);
1528 cit_write_reg(gspca_dev, 0x0005, 0x0102);
1529 cit_write_reg(gspca_dev, 0x00a0, 0x0103);
1530 cit_write_reg(gspca_dev, 0x0010, 0x0104);
1531 cit_write_reg(gspca_dev, 0x0078, 0x0105);
1532 break;
1535 cit_write_reg(gspca_dev, compression, 0x0109);
1536 cit_write_reg(gspca_dev, clock_div, 0x0111);
1538 return 0;
1541 static int cit_start_model1(struct gspca_dev *gspca_dev)
1543 struct sd *sd = (struct sd *) gspca_dev;
1544 int i, clock_div;
1546 clock_div = cit_get_clock_div(gspca_dev);
1547 if (clock_div < 0)
1548 return clock_div;
1550 cit_read_reg(gspca_dev, 0x0128, 1);
1551 cit_read_reg(gspca_dev, 0x0100, 0);
1552 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1553 cit_read_reg(gspca_dev, 0x0100, 0);
1554 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1555 cit_read_reg(gspca_dev, 0x0100, 0);
1556 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1557 cit_write_reg(gspca_dev, 0x01, 0x0108);
1559 cit_write_reg(gspca_dev, 0x03, 0x0112);
1560 cit_read_reg(gspca_dev, 0x0115, 0);
1561 cit_write_reg(gspca_dev, 0x06, 0x0115);
1562 cit_read_reg(gspca_dev, 0x0116, 0);
1563 cit_write_reg(gspca_dev, 0x44, 0x0116);
1564 cit_read_reg(gspca_dev, 0x0116, 0);
1565 cit_write_reg(gspca_dev, 0x40, 0x0116);
1566 cit_read_reg(gspca_dev, 0x0115, 0);
1567 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1568 cit_write_reg(gspca_dev, 0x19, 0x012c);
1570 cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
1571 cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
1572 cit_Packet_Format1(gspca_dev, 0x39, 0x09);
1573 cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
1574 cit_Packet_Format1(gspca_dev, 0x28, 0x22);
1575 cit_Packet_Format1(gspca_dev, 0x27, 0x00);
1576 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1577 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1579 for (i = 0; i < cit_model1_ntries; i++)
1580 cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
1582 for (i = 0; i < cit_model1_ntries; i++)
1583 cit_Packet_Format1(gspca_dev, 0x30, 0x14);
1585 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1586 cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
1587 cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
1588 cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
1589 cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
1590 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1591 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1593 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1594 cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
1595 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
1596 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
1597 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
1598 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
1599 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
1600 cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
1601 cit_PacketFormat2(gspca_dev, 0x11, 0xba);
1602 cit_PacketFormat2(gspca_dev, 0x12, 0x53);
1603 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1604 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1606 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1607 cit_PacketFormat2(gspca_dev, 0x16, 0x00);
1608 cit_PacketFormat2(gspca_dev, 0x17, 0x28);
1609 cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
1610 cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
1611 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1612 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1614 for (i = 0; i < cit_model1_ntries; i++)
1615 cit_Packet_Format1(gspca_dev, 0x00, 0x18);
1616 for (i = 0; i < cit_model1_ntries; i++)
1617 cit_Packet_Format1(gspca_dev, 0x13, 0x18);
1618 for (i = 0; i < cit_model1_ntries; i++)
1619 cit_Packet_Format1(gspca_dev, 0x14, 0x06);
1621 /* TESTME These are handled through controls
1622 KEEP until someone can test leaving this out is ok */
1623 if (0) {
1624 /* This is default brightness */
1625 for (i = 0; i < cit_model1_ntries; i++)
1626 cit_Packet_Format1(gspca_dev, 0x31, 0x37);
1627 for (i = 0; i < cit_model1_ntries; i++)
1628 cit_Packet_Format1(gspca_dev, 0x32, 0x46);
1629 for (i = 0; i < cit_model1_ntries; i++)
1630 cit_Packet_Format1(gspca_dev, 0x33, 0x55);
1633 cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
1634 for (i = 0; i < cit_model1_ntries; i++)
1635 cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
1636 for (i = 0; i < cit_model1_ntries; i++)
1637 cit_Packet_Format1(gspca_dev, 0x29, 0x80);
1638 cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
1639 cit_Packet_Format1(gspca_dev, 0x30, 0x17);
1640 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1641 for (i = 0; i < cit_model1_ntries; i++)
1642 cit_Packet_Format1(gspca_dev, 0x34, 0x00);
1644 cit_write_reg(gspca_dev, 0x00, 0x0101);
1645 cit_write_reg(gspca_dev, 0x00, 0x010a);
1647 switch (gspca_dev->pixfmt.width) {
1648 case 128: /* 128x96 */
1649 cit_write_reg(gspca_dev, 0x80, 0x0103);
1650 cit_write_reg(gspca_dev, 0x60, 0x0105);
1651 cit_write_reg(gspca_dev, 0x0c, 0x010b);
1652 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1653 cit_write_reg(gspca_dev, 0x0b, 0x011d);
1654 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1655 cit_write_reg(gspca_dev, 0x00, 0x0129);
1656 break;
1657 case 176: /* 176x144 */
1658 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1659 cit_write_reg(gspca_dev, 0x8f, 0x0105);
1660 cit_write_reg(gspca_dev, 0x06, 0x010b);
1661 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1662 cit_write_reg(gspca_dev, 0x0d, 0x011d);
1663 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1664 cit_write_reg(gspca_dev, 0x03, 0x0129);
1665 break;
1666 case 352: /* 352x288 */
1667 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1668 cit_write_reg(gspca_dev, 0x90, 0x0105);
1669 cit_write_reg(gspca_dev, 0x02, 0x010b);
1670 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1671 cit_write_reg(gspca_dev, 0x05, 0x011d);
1672 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1673 cit_write_reg(gspca_dev, 0x00, 0x0129);
1674 break;
1677 cit_write_reg(gspca_dev, 0xff, 0x012b);
1679 /* TESTME These are handled through controls
1680 KEEP until someone can test leaving this out is ok */
1681 if (0) {
1682 /* This is another brightness - don't know why */
1683 for (i = 0; i < cit_model1_ntries; i++)
1684 cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
1685 for (i = 0; i < cit_model1_ntries; i++)
1686 cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
1687 for (i = 0; i < cit_model1_ntries; i++)
1688 cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
1690 /* Default contrast */
1691 for (i = 0; i < cit_model1_ntries; i++)
1692 cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
1694 /* Default sharpness */
1695 for (i = 0; i < cit_model1_ntries2; i++)
1696 cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
1698 /* Default lighting conditions */
1699 cit_Packet_Format1(gspca_dev, 0x0027,
1700 v4l2_ctrl_g_ctrl(sd->lighting));
1703 /* Assorted init */
1704 switch (gspca_dev->pixfmt.width) {
1705 case 128: /* 128x96 */
1706 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1707 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1708 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1709 cit_write_reg(gspca_dev, 0x36, 0x0102);
1710 cit_write_reg(gspca_dev, 0x1a, 0x0104);
1711 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1712 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1713 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1714 break;
1715 case 176: /* 176x144 */
1716 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1717 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1718 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1719 cit_write_reg(gspca_dev, 0x04, 0x0102);
1720 cit_write_reg(gspca_dev, 0x02, 0x0104);
1721 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1722 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1723 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1724 break;
1725 case 352: /* 352x288 */
1726 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1727 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1728 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1729 cit_write_reg(gspca_dev, 0x08, 0x0102);
1730 cit_write_reg(gspca_dev, 0x01, 0x0104);
1731 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1732 cit_write_reg(gspca_dev, 0x2f, 0x011c);
1733 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1734 break;
1737 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1738 cit_write_reg(gspca_dev, clock_div, 0x0111);
1740 return 0;
1743 static int cit_start_model2(struct gspca_dev *gspca_dev)
1745 struct sd *sd = (struct sd *) gspca_dev;
1746 int clock_div = 0;
1748 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1749 cit_read_reg(gspca_dev, 0x0116, 0);
1750 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1751 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1752 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
1753 cit_write_reg(gspca_dev, 0x0008, 0x012b);
1754 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1755 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1756 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1757 switch (gspca_dev->pixfmt.width) {
1758 case 176: /* 176x144 */
1759 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1760 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1761 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1762 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
1763 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
1764 /* TESTME HDG: this does not seem right
1765 (it is 2 for all other resolutions) */
1766 sd->sof_len = 10;
1767 break;
1768 case 320: /* 320x240 */
1769 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
1770 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1771 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1772 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1773 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1774 sd->sof_len = 2;
1775 break;
1776 #if 0
1777 case VIDEOSIZE_352x240:
1778 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1779 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1780 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1781 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1782 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1783 sd->sof_len = 2;
1784 break;
1785 #endif
1786 case 352: /* 352x288 */
1787 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1788 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1789 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1790 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1791 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1792 sd->sof_len = 2;
1793 break;
1796 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1798 switch (gspca_dev->pixfmt.width) {
1799 case 176: /* 176x144 */
1800 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1801 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
1802 break;
1803 case 320: /* 320x240 */
1804 case 352: /* 352x288 */
1805 cit_write_reg(gspca_dev, 0x0040, 0x0111);
1806 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
1807 break;
1809 cit_write_reg(gspca_dev, 0x009b, 0x010f);
1810 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
1813 * Hardware settings, may affect CMOS sensor; not user controls!
1814 * -------------------------------------------------------------
1815 * 0x0004: no effect
1816 * 0x0006: hardware effect
1817 * 0x0008: no effect
1818 * 0x000a: stops video stream, probably important h/w setting
1819 * 0x000c: changes color in hardware manner (not user setting)
1820 * 0x0012: changes number of colors (does not affect speed)
1821 * 0x002a: no effect
1822 * 0x002c: hardware setting (related to scan lines)
1823 * 0x002e: stops video stream, probably important h/w setting
1825 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
1826 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
1827 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
1828 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
1829 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
1830 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
1831 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
1832 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
1833 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
1836 * Function 0x0030 pops up all over the place. Apparently
1837 * it is a hardware control register, with every bit assigned to
1838 * do something.
1840 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
1843 * Magic control of CMOS sensor. Only lower values like
1844 * 0-3 work, and picture shifts left or right. Don't change.
1846 switch (gspca_dev->pixfmt.width) {
1847 case 176: /* 176x144 */
1848 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1849 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1850 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1851 clock_div = 6;
1852 break;
1853 case 320: /* 320x240 */
1854 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
1855 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
1856 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1857 clock_div = 8;
1858 break;
1859 #if 0
1860 case VIDEOSIZE_352x240:
1861 /* This mode doesn't work as Windows programs it; changed to work */
1862 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1863 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1864 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1865 clock_div = 10;
1866 break;
1867 #endif
1868 case 352: /* 352x288 */
1869 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
1870 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1871 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1872 clock_div = 16;
1873 break;
1876 /* TESTME These are handled through controls
1877 KEEP until someone can test leaving this out is ok */
1878 if (0)
1879 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
1882 * We have our own frame rate setting varying from 0 (slowest) to 6
1883 * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
1884 # where 0 is also the slowest setting. However for all practical
1885 # reasons high settings make no sense because USB is not fast enough
1886 # to support high FPS. Be aware that the picture datastream will be
1887 # severely disrupted if you ask for frame rate faster than allowed
1888 # for the video size - see below:
1890 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
1891 * -----------------------------------------------------------------
1892 * 176x144: [6..31]
1893 * 320x240: [8..31]
1894 * 352x240: [10..31]
1895 * 352x288: [16..31] I have to raise lower threshold for stability...
1897 * As usual, slower FPS provides better sensitivity.
1899 cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
1902 * This setting does not visibly affect pictures; left it here
1903 * because it was present in Windows USB data stream. This function
1904 * does not allow arbitrary values and apparently is a bit mask, to
1905 * be activated only at appropriate time. Don't change it randomly!
1907 switch (gspca_dev->pixfmt.width) {
1908 case 176: /* 176x144 */
1909 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
1910 break;
1911 case 320: /* 320x240 */
1912 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
1913 break;
1914 #if 0
1915 case VIDEOSIZE_352x240:
1916 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
1917 break;
1918 #endif
1919 case 352: /* 352x288 */
1920 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
1921 break;
1924 cit_model2_Packet1(gspca_dev, 0x0028, v4l2_ctrl_g_ctrl(sd->lighting));
1925 /* model2 cannot change the backlight compensation while streaming */
1926 v4l2_ctrl_grab(sd->lighting, true);
1928 /* color balance rg2 */
1929 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
1930 /* saturation */
1931 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
1932 /* color balance yb */
1933 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
1935 /* Hardware control command */
1936 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
1938 return 0;
1941 static int cit_start_model3(struct gspca_dev *gspca_dev)
1943 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1944 int i, clock_div = 0;
1946 /* HDG not in ibmcam driver, added to see if it helps with
1947 auto-detecting between model3 and ibm netcamera pro */
1948 cit_read_reg(gspca_dev, 0x128, 1);
1950 cit_write_reg(gspca_dev, 0x0000, 0x0100);
1951 cit_read_reg(gspca_dev, 0x0116, 0);
1952 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1953 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1954 cit_write_reg(gspca_dev, 0x0000, 0x0123);
1955 cit_write_reg(gspca_dev, 0x0001, 0x0117);
1956 cit_write_reg(gspca_dev, 0x0040, 0x0108);
1957 cit_write_reg(gspca_dev, 0x0019, 0x012c);
1958 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1959 cit_write_reg(gspca_dev, 0x0002, 0x0115);
1960 cit_write_reg(gspca_dev, 0x0003, 0x0115);
1961 cit_read_reg(gspca_dev, 0x0115, 0);
1962 cit_write_reg(gspca_dev, 0x000b, 0x0115);
1964 /* TESTME HDG not in ibmcam driver, added to see if it helps with
1965 auto-detecting between model3 and ibm netcamera pro */
1966 if (0) {
1967 cit_write_reg(gspca_dev, 0x0078, 0x012d);
1968 cit_write_reg(gspca_dev, 0x0001, 0x012f);
1969 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1970 cit_write_reg(gspca_dev, 0x0079, 0x012d);
1971 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
1972 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
1973 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
1974 cit_read_reg(gspca_dev, 0x0126, 1);
1977 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
1978 cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6);
1979 cit_model3_Packet1(gspca_dev, 0x000c, 0x0002);
1980 cit_model3_Packet1(gspca_dev, 0x000d, 0x0020);
1981 cit_model3_Packet1(gspca_dev, 0x000e, 0x0033);
1982 cit_model3_Packet1(gspca_dev, 0x000f, 0x0007);
1983 cit_model3_Packet1(gspca_dev, 0x0010, 0x0000);
1984 cit_model3_Packet1(gspca_dev, 0x0011, 0x0070);
1985 cit_model3_Packet1(gspca_dev, 0x0012, 0x0030);
1986 cit_model3_Packet1(gspca_dev, 0x0013, 0x0000);
1987 cit_model3_Packet1(gspca_dev, 0x0014, 0x0001);
1988 cit_model3_Packet1(gspca_dev, 0x0015, 0x0001);
1989 cit_model3_Packet1(gspca_dev, 0x0016, 0x0001);
1990 cit_model3_Packet1(gspca_dev, 0x0017, 0x0001);
1991 cit_model3_Packet1(gspca_dev, 0x0018, 0x0000);
1992 cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3);
1993 cit_model3_Packet1(gspca_dev, 0x0020, 0x0000);
1994 cit_model3_Packet1(gspca_dev, 0x0028, 0x0010);
1995 cit_model3_Packet1(gspca_dev, 0x0029, 0x0054);
1996 cit_model3_Packet1(gspca_dev, 0x002a, 0x0013);
1997 cit_model3_Packet1(gspca_dev, 0x002b, 0x0007);
1998 cit_model3_Packet1(gspca_dev, 0x002d, 0x0028);
1999 cit_model3_Packet1(gspca_dev, 0x002e, 0x0000);
2000 cit_model3_Packet1(gspca_dev, 0x0031, 0x0000);
2001 cit_model3_Packet1(gspca_dev, 0x0032, 0x0000);
2002 cit_model3_Packet1(gspca_dev, 0x0033, 0x0000);
2003 cit_model3_Packet1(gspca_dev, 0x0034, 0x0000);
2004 cit_model3_Packet1(gspca_dev, 0x0035, 0x0038);
2005 cit_model3_Packet1(gspca_dev, 0x003a, 0x0001);
2006 cit_model3_Packet1(gspca_dev, 0x003c, 0x001e);
2007 cit_model3_Packet1(gspca_dev, 0x003f, 0x000a);
2008 cit_model3_Packet1(gspca_dev, 0x0041, 0x0000);
2009 cit_model3_Packet1(gspca_dev, 0x0046, 0x003f);
2010 cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
2011 cit_model3_Packet1(gspca_dev, 0x0050, 0x0005);
2012 cit_model3_Packet1(gspca_dev, 0x0052, 0x001a);
2013 cit_model3_Packet1(gspca_dev, 0x0053, 0x0003);
2014 cit_model3_Packet1(gspca_dev, 0x005a, 0x006b);
2015 cit_model3_Packet1(gspca_dev, 0x005d, 0x001e);
2016 cit_model3_Packet1(gspca_dev, 0x005e, 0x0030);
2017 cit_model3_Packet1(gspca_dev, 0x005f, 0x0041);
2018 cit_model3_Packet1(gspca_dev, 0x0064, 0x0008);
2019 cit_model3_Packet1(gspca_dev, 0x0065, 0x0015);
2020 cit_model3_Packet1(gspca_dev, 0x0068, 0x000f);
2021 cit_model3_Packet1(gspca_dev, 0x0079, 0x0000);
2022 cit_model3_Packet1(gspca_dev, 0x007a, 0x0000);
2023 cit_model3_Packet1(gspca_dev, 0x007c, 0x003f);
2024 cit_model3_Packet1(gspca_dev, 0x0082, 0x000f);
2025 cit_model3_Packet1(gspca_dev, 0x0085, 0x0000);
2026 cit_model3_Packet1(gspca_dev, 0x0099, 0x0000);
2027 cit_model3_Packet1(gspca_dev, 0x009b, 0x0023);
2028 cit_model3_Packet1(gspca_dev, 0x009c, 0x0022);
2029 cit_model3_Packet1(gspca_dev, 0x009d, 0x0096);
2030 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
2031 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
2033 switch (gspca_dev->pixfmt.width) {
2034 case 160:
2035 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2036 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2037 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2038 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2039 cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */
2040 cit_write_reg(gspca_dev, 0x00a9, 0x0119);
2041 cit_write_reg(gspca_dev, 0x0016, 0x011b);
2042 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2043 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2044 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2045 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2046 cit_write_reg(gspca_dev, 0x0018, 0x0102);
2047 cit_write_reg(gspca_dev, 0x0004, 0x0104);
2048 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2049 cit_write_reg(gspca_dev, 0x0028, 0x011c);
2050 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2051 cit_write_reg(gspca_dev, 0x0000, 0x0118);
2052 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2053 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2054 cit_write_reg(gspca_dev, compression, 0x0109);
2055 clock_div = 3;
2056 break;
2057 case 320:
2058 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2059 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2060 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2061 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2062 cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */
2063 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */
2064 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2065 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2066 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2067 /* 4 commands from 160x120 skipped */
2068 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2069 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2070 cit_write_reg(gspca_dev, compression, 0x0109);
2071 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2072 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2073 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2074 cit_write_reg(gspca_dev, 0x0010, 0x0104);
2075 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2076 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2077 cit_write_reg(gspca_dev, 0x001c, 0x0118);
2078 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2079 clock_div = 5;
2080 break;
2081 case 640:
2082 cit_write_reg(gspca_dev, 0x00f0, 0x0105);
2083 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2084 cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */
2085 cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
2086 cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
2087 cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */
2088 cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
2089 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2090 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2091 cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
2092 cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */
2093 cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
2094 cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
2095 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2096 cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
2097 cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
2098 cit_write_reg(gspca_dev, compression, 0x0109);
2099 cit_write_reg(gspca_dev, 0x0040, 0x0101);
2100 cit_write_reg(gspca_dev, 0x0040, 0x0103);
2101 cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
2102 clock_div = 7;
2103 break;
2106 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */
2107 cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */
2108 cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */
2109 cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */
2110 cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */
2111 cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */
2112 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2113 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2114 cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */
2115 cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */
2116 cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */
2117 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2118 cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */
2119 cit_model3_Packet1(gspca_dev, 0x002f, 0x002a);
2120 cit_model3_Packet1(gspca_dev, 0x0030, 0x0029);
2121 cit_model3_Packet1(gspca_dev, 0x0037, 0x0002);
2122 cit_model3_Packet1(gspca_dev, 0x0038, 0x0059);
2123 cit_model3_Packet1(gspca_dev, 0x003d, 0x002e);
2124 cit_model3_Packet1(gspca_dev, 0x003e, 0x0028);
2125 cit_model3_Packet1(gspca_dev, 0x0078, 0x0005);
2126 cit_model3_Packet1(gspca_dev, 0x007b, 0x0011);
2127 cit_model3_Packet1(gspca_dev, 0x007d, 0x004b);
2128 cit_model3_Packet1(gspca_dev, 0x007f, 0x0022);
2129 cit_model3_Packet1(gspca_dev, 0x0080, 0x000c);
2130 cit_model3_Packet1(gspca_dev, 0x0081, 0x000b);
2131 cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd);
2132 cit_model3_Packet1(gspca_dev, 0x0086, 0x000b);
2133 cit_model3_Packet1(gspca_dev, 0x0087, 0x000b);
2134 cit_model3_Packet1(gspca_dev, 0x007e, 0x000e);
2135 cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
2136 cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
2137 cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
2139 /* FIXME we should probably use cit_get_clock_div() here (in
2140 combination with isoc negotiation using the programmable isoc size)
2141 like with the IBM netcam pro). */
2142 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
2144 switch (gspca_dev->pixfmt.width) {
2145 case 160:
2146 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2147 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2148 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2149 cit_model3_Packet1(gspca_dev, 0x0040, 0x000a);
2150 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2151 break;
2152 case 320:
2153 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2154 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
2155 cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
2156 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2157 cit_model3_Packet1(gspca_dev, 0x0051, 0x000b);
2158 break;
2159 case 640:
2160 cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */
2161 cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */
2162 cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
2163 cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
2164 break;
2167 /* if (sd->input_index) { */
2168 if (rca_input) {
2169 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2170 if (rca_initdata[i][0])
2171 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2172 else
2173 cit_write_reg(gspca_dev, rca_initdata[i][1],
2174 rca_initdata[i][2]);
2178 return 0;
2181 static int cit_start_model4(struct gspca_dev *gspca_dev)
2183 struct sd *sd = (struct sd *) gspca_dev;
2185 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2186 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2187 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
2188 cit_write_reg(gspca_dev, 0x0080, 0x012b);
2189 cit_write_reg(gspca_dev, 0x0000, 0x0108);
2190 cit_write_reg(gspca_dev, 0x0001, 0x0133);
2191 cit_write_reg(gspca_dev, 0x009b, 0x010f);
2192 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
2193 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
2194 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
2196 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2197 cit_write_reg(gspca_dev, 0x0004, 0x012f);
2198 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2199 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2200 cit_write_reg(gspca_dev, 0x00fb, 0x012e);
2201 cit_write_reg(gspca_dev, 0x0000, 0x0130);
2202 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2203 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2204 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2205 cit_write_reg(gspca_dev, 0x000c, 0x0127);
2206 cit_write_reg(gspca_dev, 0x0009, 0x012e);
2207 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2209 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2210 cit_write_reg(gspca_dev, 0x0012, 0x012f);
2211 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2212 cit_write_reg(gspca_dev, 0x0008, 0x0127);
2213 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2214 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2215 cit_write_reg(gspca_dev, 0x002a, 0x012d);
2216 cit_write_reg(gspca_dev, 0x0000, 0x012f);
2217 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2218 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2219 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2221 switch (gspca_dev->pixfmt.width) {
2222 case 128: /* 128x96 */
2223 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2224 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2225 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2226 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2227 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2228 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2229 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2230 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2231 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2232 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2233 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2234 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2235 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2236 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2237 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2238 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2239 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2240 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2241 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2242 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2243 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2244 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2245 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2246 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2247 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2248 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2249 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2250 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2251 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2252 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2253 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2254 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2255 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2256 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2257 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2258 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2259 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2260 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2261 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2262 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2263 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2264 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2265 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2266 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2267 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2268 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2269 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2270 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2271 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2272 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2273 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2274 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2275 sd->sof_len = 2;
2276 break;
2277 case 160: /* 160x120 */
2278 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2279 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2280 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2281 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2282 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2283 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2284 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2285 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2286 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2287 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2288 cit_write_reg(gspca_dev, 0x000b, 0x0127);
2289 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2290 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2291 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2292 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2293 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2294 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2295 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2296 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2297 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2298 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2299 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2300 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2301 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2302 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2303 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2304 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2305 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2306 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2307 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2308 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2309 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2310 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2311 cit_write_reg(gspca_dev, 0x0025, 0x0127);
2312 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2313 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2314 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2315 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2316 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2317 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2318 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2319 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2320 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2321 cit_write_reg(gspca_dev, 0x0048, 0x0127);
2322 cit_write_reg(gspca_dev, 0x0035, 0x012e);
2323 cit_write_reg(gspca_dev, 0x00d0, 0x0130);
2324 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2325 cit_write_reg(gspca_dev, 0x0048, 0x012d);
2326 cit_write_reg(gspca_dev, 0x0090, 0x012f);
2327 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2328 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2329 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2330 sd->sof_len = 2;
2331 break;
2332 case 176: /* 176x144 */
2333 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2334 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2335 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2336 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2337 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2338 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2339 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2340 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2341 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2342 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2343 cit_write_reg(gspca_dev, 0x0007, 0x0127);
2344 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2345 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2346 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2347 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2348 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2349 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2350 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2351 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2352 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2353 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2354 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2355 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2356 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2357 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2358 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2359 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2360 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2361 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2362 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2363 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2364 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2365 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2366 cit_write_reg(gspca_dev, 0x0028, 0x0127);
2367 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2368 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2369 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2370 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2371 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2372 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2373 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2374 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2375 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2376 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2377 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2378 cit_write_reg(gspca_dev, 0x002a, 0x0130);
2379 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2380 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2381 cit_write_reg(gspca_dev, 0x006d, 0x012f);
2382 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2383 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2384 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2385 /* TESTME HDG: this does not seem right
2386 (it is 2 for all other resolutions) */
2387 sd->sof_len = 10;
2388 break;
2389 case 320: /* 320x240 */
2390 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2391 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2392 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2393 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2394 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2395 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2396 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2397 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2398 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2399 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2400 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2401 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2402 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2403 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2404 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2405 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2406 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2407 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2408 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2409 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2410 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2411 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2412 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2413 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2414 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2415 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2416 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2417 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2418 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2419 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2420 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2421 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2422 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2423 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2424 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2425 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2426 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2427 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2428 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2429 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2430 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2431 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2432 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2433 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2434 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2435 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2436 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2437 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2438 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2439 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2440 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2441 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2442 sd->sof_len = 2;
2443 break;
2444 case 352: /* 352x288 */
2445 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2446 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2447 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2448 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2449 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2450 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2451 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2452 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2453 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2454 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2455 cit_write_reg(gspca_dev, 0x0006, 0x0127);
2456 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2457 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2458 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2459 cit_write_reg(gspca_dev, 0x0002, 0x012f);
2460 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2461 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2462 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2463 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2464 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2465 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2466 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2467 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2468 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2469 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2470 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2471 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2472 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2473 cit_write_reg(gspca_dev, 0x00cf, 0x012e);
2474 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2475 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2476 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2477 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2478 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2479 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2480 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2481 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2482 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2483 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2484 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2485 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2486 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2487 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2488 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2489 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2490 cit_write_reg(gspca_dev, 0x0025, 0x0130);
2491 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2492 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2493 cit_write_reg(gspca_dev, 0x0048, 0x012f);
2494 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2495 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2496 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2497 sd->sof_len = 2;
2498 break;
2501 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
2503 return 0;
2506 static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2508 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
2509 int i, clock_div;
2511 clock_div = cit_get_clock_div(gspca_dev);
2512 if (clock_div < 0)
2513 return clock_div;
2515 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2516 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2517 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2518 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2519 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2520 /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */
2521 cit_write_reg(gspca_dev, 0x0000, 0x0133);
2522 cit_write_reg(gspca_dev, 0x0000, 0x0123);
2523 cit_write_reg(gspca_dev, 0x0001, 0x0117);
2524 cit_write_reg(gspca_dev, 0x0040, 0x0108);
2525 cit_write_reg(gspca_dev, 0x0019, 0x012c);
2526 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2527 /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */
2529 cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
2531 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2532 cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */
2533 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
2534 cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
2535 cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
2536 cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
2537 cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
2538 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2539 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2541 switch (gspca_dev->pixfmt.width) {
2542 case 160: /* 160x120 */
2543 cit_write_reg(gspca_dev, 0x0024, 0x010b);
2544 cit_write_reg(gspca_dev, 0x0089, 0x0119);
2545 cit_write_reg(gspca_dev, 0x000a, 0x011b);
2546 cit_write_reg(gspca_dev, 0x0003, 0x011e);
2547 cit_write_reg(gspca_dev, 0x0007, 0x0104);
2548 cit_write_reg(gspca_dev, 0x0009, 0x011a);
2549 cit_write_reg(gspca_dev, 0x008b, 0x011c);
2550 cit_write_reg(gspca_dev, 0x0008, 0x0118);
2551 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2552 break;
2553 case 320: /* 320x240 */
2554 cit_write_reg(gspca_dev, 0x0028, 0x010b);
2555 cit_write_reg(gspca_dev, 0x00d9, 0x0119);
2556 cit_write_reg(gspca_dev, 0x0006, 0x011b);
2557 cit_write_reg(gspca_dev, 0x0000, 0x011e);
2558 cit_write_reg(gspca_dev, 0x000e, 0x0104);
2559 cit_write_reg(gspca_dev, 0x0004, 0x011a);
2560 cit_write_reg(gspca_dev, 0x003f, 0x011c);
2561 cit_write_reg(gspca_dev, 0x000c, 0x0118);
2562 cit_write_reg(gspca_dev, 0x0000, 0x0132);
2563 break;
2566 cit_model3_Packet1(gspca_dev, 0x0019, 0x0031);
2567 cit_model3_Packet1(gspca_dev, 0x001a, 0x0003);
2568 cit_model3_Packet1(gspca_dev, 0x001b, 0x0038);
2569 cit_model3_Packet1(gspca_dev, 0x001c, 0x0000);
2570 cit_model3_Packet1(gspca_dev, 0x0024, 0x0001);
2571 cit_model3_Packet1(gspca_dev, 0x0027, 0x0001);
2572 cit_model3_Packet1(gspca_dev, 0x002a, 0x0004);
2573 cit_model3_Packet1(gspca_dev, 0x0035, 0x000b);
2574 cit_model3_Packet1(gspca_dev, 0x003f, 0x0001);
2575 cit_model3_Packet1(gspca_dev, 0x0044, 0x0000);
2576 cit_model3_Packet1(gspca_dev, 0x0054, 0x0000);
2577 cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000);
2578 cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001);
2579 cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001);
2580 cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000);
2581 cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0);
2583 cit_write_reg(gspca_dev, compression, 0x0109);
2584 cit_write_reg(gspca_dev, clock_div, 0x0111);
2586 /* if (sd->input_index) { */
2587 if (rca_input) {
2588 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2589 if (rca_initdata[i][0])
2590 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2591 else
2592 cit_write_reg(gspca_dev, rca_initdata[i][1],
2593 rca_initdata[i][2]);
2597 return 0;
2600 /* -- start the camera -- */
2601 static int sd_start(struct gspca_dev *gspca_dev)
2603 struct sd *sd = (struct sd *) gspca_dev;
2604 int packet_size;
2606 packet_size = cit_get_packet_size(gspca_dev);
2607 if (packet_size < 0)
2608 return packet_size;
2610 switch (sd->model) {
2611 case CIT_MODEL0:
2612 cit_start_model0(gspca_dev);
2613 break;
2614 case CIT_MODEL1:
2615 cit_start_model1(gspca_dev);
2616 break;
2617 case CIT_MODEL2:
2618 cit_start_model2(gspca_dev);
2619 break;
2620 case CIT_MODEL3:
2621 cit_start_model3(gspca_dev);
2622 break;
2623 case CIT_MODEL4:
2624 cit_start_model4(gspca_dev);
2625 break;
2626 case CIT_IBM_NETCAM_PRO:
2627 cit_start_ibm_netcam_pro(gspca_dev);
2628 break;
2631 /* Program max isoc packet size */
2632 cit_write_reg(gspca_dev, packet_size >> 8, 0x0106);
2633 cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107);
2635 cit_restart_stream(gspca_dev);
2637 return 0;
2640 static int sd_isoc_init(struct gspca_dev *gspca_dev)
2642 struct usb_interface_cache *intfc;
2643 struct usb_host_interface *alt;
2644 int max_packet_size;
2646 switch (gspca_dev->pixfmt.width) {
2647 case 160:
2648 max_packet_size = 450;
2649 break;
2650 case 176:
2651 max_packet_size = 600;
2652 break;
2653 default:
2654 max_packet_size = 1022;
2655 break;
2658 intfc = gspca_dev->dev->actconfig->intf_cache[0];
2660 if (intfc->num_altsetting < 2)
2661 return -ENODEV;
2663 alt = &intfc->altsetting[1];
2665 if (alt->desc.bNumEndpoints < 1)
2666 return -ENODEV;
2668 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
2669 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size);
2671 return 0;
2674 static int sd_isoc_nego(struct gspca_dev *gspca_dev)
2676 int ret, packet_size, min_packet_size;
2677 struct usb_host_interface *alt;
2679 switch (gspca_dev->pixfmt.width) {
2680 case 160:
2681 min_packet_size = 200;
2682 break;
2683 case 176:
2684 min_packet_size = 266;
2685 break;
2686 default:
2687 min_packet_size = 400;
2688 break;
2692 * Existence of altsetting and endpoint was verified in sd_isoc_init()
2694 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
2695 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2696 if (packet_size <= min_packet_size)
2697 return -EIO;
2699 packet_size -= 100;
2700 if (packet_size < min_packet_size)
2701 packet_size = min_packet_size;
2702 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
2704 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
2705 if (ret < 0)
2706 pr_err("set alt 1 err %d\n", ret);
2708 return ret;
2711 static void sd_stopN(struct gspca_dev *gspca_dev)
2713 cit_write_reg(gspca_dev, 0x0000, 0x010c);
2716 static void sd_stop0(struct gspca_dev *gspca_dev)
2718 struct sd *sd = (struct sd *) gspca_dev;
2720 if (!gspca_dev->present)
2721 return;
2723 switch (sd->model) {
2724 case CIT_MODEL0:
2725 /* HDG windows does this, but it causes the cams autogain to
2726 restart from a gain of 0, which does not look good when
2727 changing resolutions. */
2728 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2729 cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */
2730 break;
2731 case CIT_MODEL1:
2732 cit_send_FF_04_02(gspca_dev);
2733 cit_read_reg(gspca_dev, 0x0100, 0);
2734 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2735 break;
2736 case CIT_MODEL2:
2737 v4l2_ctrl_grab(sd->lighting, false);
2738 /* Fall through! */
2739 case CIT_MODEL4:
2740 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2742 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
2743 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2744 cit_write_reg(gspca_dev, 0x00a0, 0x0111);
2746 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
2748 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2749 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2750 break;
2751 case CIT_MODEL3:
2752 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2753 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
2754 cit_read_reg(gspca_dev, 0x0116, 0);
2755 cit_write_reg(gspca_dev, 0x0064, 0x0116);
2756 cit_read_reg(gspca_dev, 0x0115, 0);
2757 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2758 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2759 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2760 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2761 cit_write_reg(gspca_dev, 0x0080, 0x0100);
2762 break;
2763 case CIT_IBM_NETCAM_PRO:
2764 cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff);
2765 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2766 cit_write_reg(gspca_dev, 0x0000, 0x0116);
2767 /* HDG windows does this, but I cannot get the camera
2768 to restart with this without redoing the entire init
2769 sequence which makes switching modes really slow */
2770 /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */
2771 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2772 cit_write_reg(gspca_dev, 0x0000, 0x0117);
2773 cit_write_reg(gspca_dev, 0x0003, 0x0133);
2774 cit_write_reg(gspca_dev, 0x0000, 0x0111);
2775 /* HDG windows does this, but I get a green picture when
2776 restarting the stream after this */
2777 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2778 cit_write_reg(gspca_dev, 0x00c0, 0x0100);
2779 break;
2782 #if IS_ENABLED(CONFIG_INPUT)
2783 /* If the last button state is pressed, release it now! */
2784 if (sd->button_state) {
2785 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2786 input_sync(gspca_dev->input_dev);
2787 sd->button_state = 0;
2789 #endif
2792 static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2794 struct sd *sd = (struct sd *) gspca_dev;
2795 u8 byte3 = 0, byte4 = 0;
2796 int i;
2798 switch (sd->model) {
2799 case CIT_MODEL0:
2800 case CIT_MODEL1:
2801 case CIT_MODEL3:
2802 case CIT_IBM_NETCAM_PRO:
2803 switch (gspca_dev->pixfmt.width) {
2804 case 160: /* 160x120 */
2805 byte3 = 0x02;
2806 byte4 = 0x0a;
2807 break;
2808 case 176: /* 176x144 */
2809 byte3 = 0x02;
2810 byte4 = 0x0e;
2811 break;
2812 case 320: /* 320x240 */
2813 byte3 = 0x02;
2814 byte4 = 0x08;
2815 break;
2816 case 352: /* 352x288 */
2817 byte3 = 0x02;
2818 byte4 = 0x00;
2819 break;
2820 case 640:
2821 byte3 = 0x03;
2822 byte4 = 0x08;
2823 break;
2826 /* These have a different byte3 */
2827 if (sd->model <= CIT_MODEL1)
2828 byte3 = 0x00;
2830 for (i = 0; i < len; i++) {
2831 /* For this model the SOF always starts at offset 0
2832 so no need to search the entire frame */
2833 if (sd->model == CIT_MODEL0 && sd->sof_read != i)
2834 break;
2836 switch (sd->sof_read) {
2837 case 0:
2838 if (data[i] == 0x00)
2839 sd->sof_read++;
2840 break;
2841 case 1:
2842 if (data[i] == 0xff)
2843 sd->sof_read++;
2844 else if (data[i] == 0x00)
2845 sd->sof_read = 1;
2846 else
2847 sd->sof_read = 0;
2848 break;
2849 case 2:
2850 if (data[i] == byte3)
2851 sd->sof_read++;
2852 else if (data[i] == 0x00)
2853 sd->sof_read = 1;
2854 else
2855 sd->sof_read = 0;
2856 break;
2857 case 3:
2858 if (data[i] == byte4) {
2859 sd->sof_read = 0;
2860 return data + i + (sd->sof_len - 3);
2862 if (byte3 == 0x00 && data[i] == 0xff)
2863 sd->sof_read = 2;
2864 else if (data[i] == 0x00)
2865 sd->sof_read = 1;
2866 else
2867 sd->sof_read = 0;
2868 break;
2871 break;
2872 case CIT_MODEL2:
2873 case CIT_MODEL4:
2874 /* TESTME we need to find a longer sof signature to avoid
2875 false positives */
2876 for (i = 0; i < len; i++) {
2877 switch (sd->sof_read) {
2878 case 0:
2879 if (data[i] == 0x00)
2880 sd->sof_read++;
2881 break;
2882 case 1:
2883 sd->sof_read = 0;
2884 if (data[i] == 0xff) {
2885 if (i >= 4)
2886 gspca_dbg(gspca_dev, D_FRAM,
2887 "header found at offset: %d: %02x %02x 00 %3ph\n\n",
2888 i - 1,
2889 data[i - 4],
2890 data[i - 3],
2891 &data[i]);
2892 else
2893 gspca_dbg(gspca_dev, D_FRAM,
2894 "header found at offset: %d: 00 %3ph\n\n",
2895 i - 1,
2896 &data[i]);
2897 return data + i + (sd->sof_len - 1);
2899 break;
2902 break;
2904 return NULL;
2907 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2908 u8 *data, int len)
2910 struct sd *sd = (struct sd *) gspca_dev;
2911 unsigned char *sof;
2913 sof = cit_find_sof(gspca_dev, data, len);
2914 if (sof) {
2915 int n;
2917 /* finish decoding current frame */
2918 n = sof - data;
2919 if (n > sd->sof_len)
2920 n -= sd->sof_len;
2921 else
2922 n = 0;
2923 gspca_frame_add(gspca_dev, LAST_PACKET,
2924 data, n);
2925 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
2926 len -= sof - data;
2927 data = sof;
2930 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
2933 #if IS_ENABLED(CONFIG_INPUT)
2934 static void cit_check_button(struct gspca_dev *gspca_dev)
2936 int new_button_state;
2937 struct sd *sd = (struct sd *)gspca_dev;
2939 switch (sd->model) {
2940 case CIT_MODEL3:
2941 case CIT_IBM_NETCAM_PRO:
2942 break;
2943 default: /* TEST ME unknown if this works on other models too */
2944 return;
2947 /* Read the button state */
2948 cit_read_reg(gspca_dev, 0x0113, 0);
2949 new_button_state = !gspca_dev->usb_buf[0];
2951 /* Tell the cam we've seen the button press, notice that this
2952 is a nop (iow the cam keeps reporting pressed) until the
2953 button is actually released. */
2954 if (new_button_state)
2955 cit_write_reg(gspca_dev, 0x01, 0x0113);
2957 if (sd->button_state != new_button_state) {
2958 input_report_key(gspca_dev->input_dev, KEY_CAMERA,
2959 new_button_state);
2960 input_sync(gspca_dev->input_dev);
2961 sd->button_state = new_button_state;
2964 #endif
2966 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
2968 struct gspca_dev *gspca_dev =
2969 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
2970 struct sd *sd = (struct sd *)gspca_dev;
2972 gspca_dev->usb_err = 0;
2974 if (!gspca_dev->streaming)
2975 return 0;
2977 if (sd->stop_on_control_change)
2978 sd_stopN(gspca_dev);
2979 switch (ctrl->id) {
2980 case V4L2_CID_BRIGHTNESS:
2981 cit_set_brightness(gspca_dev, ctrl->val);
2982 break;
2983 case V4L2_CID_CONTRAST:
2984 cit_set_contrast(gspca_dev, ctrl->val);
2985 break;
2986 case V4L2_CID_HUE:
2987 cit_set_hue(gspca_dev, ctrl->val);
2988 break;
2989 case V4L2_CID_HFLIP:
2990 cit_set_hflip(gspca_dev, ctrl->val);
2991 break;
2992 case V4L2_CID_SHARPNESS:
2993 cit_set_sharpness(gspca_dev, ctrl->val);
2994 break;
2995 case V4L2_CID_BACKLIGHT_COMPENSATION:
2996 cit_set_lighting(gspca_dev, ctrl->val);
2997 break;
2999 if (sd->stop_on_control_change)
3000 cit_restart_stream(gspca_dev);
3001 return gspca_dev->usb_err;
3004 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
3005 .s_ctrl = sd_s_ctrl,
3008 static int sd_init_controls(struct gspca_dev *gspca_dev)
3010 struct sd *sd = (struct sd *)gspca_dev;
3011 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
3012 bool has_brightness;
3013 bool has_contrast;
3014 bool has_hue;
3015 bool has_sharpness;
3016 bool has_lighting;
3017 bool has_hflip;
3019 has_brightness = has_contrast = has_hue =
3020 has_sharpness = has_hflip = has_lighting = false;
3021 switch (sd->model) {
3022 case CIT_MODEL0:
3023 has_contrast = has_hflip = true;
3024 break;
3025 case CIT_MODEL1:
3026 has_brightness = has_contrast =
3027 has_sharpness = has_lighting = true;
3028 break;
3029 case CIT_MODEL2:
3030 has_brightness = has_hue = has_lighting = true;
3031 break;
3032 case CIT_MODEL3:
3033 has_brightness = has_contrast = has_sharpness = true;
3034 break;
3035 case CIT_MODEL4:
3036 has_brightness = has_hue = true;
3037 break;
3038 case CIT_IBM_NETCAM_PRO:
3039 has_brightness = has_hue =
3040 has_sharpness = has_hflip = has_lighting = true;
3041 break;
3043 gspca_dev->vdev.ctrl_handler = hdl;
3044 v4l2_ctrl_handler_init(hdl, 5);
3045 if (has_brightness)
3046 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3047 V4L2_CID_BRIGHTNESS, 0, 63, 1, 32);
3048 if (has_contrast)
3049 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3050 V4L2_CID_CONTRAST, 0, 20, 1, 10);
3051 if (has_hue)
3052 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3053 V4L2_CID_HUE, 0, 127, 1, 63);
3054 if (has_sharpness)
3055 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3056 V4L2_CID_SHARPNESS, 0, 6, 1, 3);
3057 if (has_lighting)
3058 sd->lighting = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3059 V4L2_CID_BACKLIGHT_COMPENSATION, 0, 2, 1, 1);
3060 if (has_hflip)
3061 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
3062 V4L2_CID_HFLIP, 0, 1, 1, 0);
3064 if (hdl->error) {
3065 pr_err("Could not initialize controls\n");
3066 return hdl->error;
3068 return 0;
3071 /* sub-driver description */
3072 static const struct sd_desc sd_desc = {
3073 .name = MODULE_NAME,
3074 .config = sd_config,
3075 .init = sd_init,
3076 .init_controls = sd_init_controls,
3077 .start = sd_start,
3078 .stopN = sd_stopN,
3079 .stop0 = sd_stop0,
3080 .pkt_scan = sd_pkt_scan,
3081 #if IS_ENABLED(CONFIG_INPUT)
3082 .dq_callback = cit_check_button,
3083 .other_input = 1,
3084 #endif
3087 static const struct sd_desc sd_desc_isoc_nego = {
3088 .name = MODULE_NAME,
3089 .config = sd_config,
3090 .init = sd_init,
3091 .init_controls = sd_init_controls,
3092 .start = sd_start,
3093 .isoc_init = sd_isoc_init,
3094 .isoc_nego = sd_isoc_nego,
3095 .stopN = sd_stopN,
3096 .stop0 = sd_stop0,
3097 .pkt_scan = sd_pkt_scan,
3098 #if IS_ENABLED(CONFIG_INPUT)
3099 .dq_callback = cit_check_button,
3100 .other_input = 1,
3101 #endif
3104 /* -- module initialisation -- */
3105 static const struct usb_device_id device_table[] = {
3106 { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 },
3107 { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 },
3108 { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3109 { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 },
3110 { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3111 { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
3112 { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
3115 MODULE_DEVICE_TABLE(usb, device_table);
3117 /* -- device connect -- */
3118 static int sd_probe(struct usb_interface *intf,
3119 const struct usb_device_id *id)
3121 const struct sd_desc *desc = &sd_desc;
3123 switch (id->driver_info) {
3124 case CIT_MODEL0:
3125 case CIT_MODEL1:
3126 if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
3127 return -ENODEV;
3128 break;
3129 case CIT_MODEL2:
3130 case CIT_MODEL4:
3131 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3132 return -ENODEV;
3133 break;
3134 case CIT_MODEL3:
3135 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
3136 return -ENODEV;
3137 /* FIXME this likely applies to all model3 cams and probably
3138 to other models too. */
3139 if (ibm_netcam_pro)
3140 desc = &sd_desc_isoc_nego;
3141 break;
3144 return gspca_dev_probe2(intf, id, desc, sizeof(struct sd), THIS_MODULE);
3147 static struct usb_driver sd_driver = {
3148 .name = MODULE_NAME,
3149 .id_table = device_table,
3150 .probe = sd_probe,
3151 .disconnect = gspca_disconnect,
3152 #ifdef CONFIG_PM
3153 .suspend = gspca_suspend,
3154 .resume = gspca_resume,
3155 .reset_resume = gspca_resume,
3156 #endif
3159 module_usb_driver(sd_driver);