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