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