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