1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#define MODULE_NAME "sonixb"
51
52#include <linux/input.h>
53#include "gspca.h"
54
55MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
56MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
57MODULE_LICENSE("GPL");
58
59
60struct sd {
61 struct gspca_dev gspca_dev;
62
63 struct v4l2_ctrl *brightness;
64 struct v4l2_ctrl *plfreq;
65
66 atomic_t avg_lum;
67 int prev_avg_lum;
68 int exposure_knee;
69 int header_read;
70 u8 header[12];
71
72 unsigned char autogain_ignore_frames;
73 unsigned char frames_to_drop;
74
75 __u8 bridge;
76#define BRIDGE_101 0
77#define BRIDGE_102 0
78#define BRIDGE_103 1
79
80 __u8 sensor;
81#define SENSOR_HV7131D 0
82#define SENSOR_HV7131R 1
83#define SENSOR_OV6650 2
84#define SENSOR_OV7630 3
85#define SENSOR_PAS106 4
86#define SENSOR_PAS202 5
87#define SENSOR_TAS5110C 6
88#define SENSOR_TAS5110D 7
89#define SENSOR_TAS5130CXX 8
90 __u8 reg11;
91};
92
93typedef const __u8 sensor_init_t[8];
94
95struct sensor_data {
96 const __u8 *bridge_init;
97 sensor_init_t *sensor_init;
98 int sensor_init_size;
99 int flags;
100 __u8 sensor_addr;
101};
102
103
104#define F_SIF 0x01
105
106
107#define MODE_RAW 0x10
108#define MODE_REDUCED_SIF 0x20
109
110#define COMP 0xc7
111#define COMP1 0xc9
112
113#define MCK_INIT 0x63
114#define MCK_INIT1 0x20
115
116#define SYS_CLK 0x04
117
118#define SENS(bridge, sensor, _flags, _sensor_addr) \
119{ \
120 .bridge_init = bridge, \
121 .sensor_init = sensor, \
122 .sensor_init_size = sizeof(sensor), \
123 .flags = _flags, .sensor_addr = _sensor_addr \
124}
125
126
127
128
129
130#define AUTOGAIN_IGNORE_FRAMES 1
131
132static const struct v4l2_pix_format vga_mode[] = {
133 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
134 .bytesperline = 160,
135 .sizeimage = 160 * 120,
136 .colorspace = V4L2_COLORSPACE_SRGB,
137 .priv = 2 | MODE_RAW},
138 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
139 .bytesperline = 160,
140 .sizeimage = 160 * 120 * 5 / 4,
141 .colorspace = V4L2_COLORSPACE_SRGB,
142 .priv = 2},
143 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
144 .bytesperline = 320,
145 .sizeimage = 320 * 240 * 5 / 4,
146 .colorspace = V4L2_COLORSPACE_SRGB,
147 .priv = 1},
148 {640, 480, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
149 .bytesperline = 640,
150 .sizeimage = 640 * 480 * 5 / 4,
151 .colorspace = V4L2_COLORSPACE_SRGB,
152 .priv = 0},
153};
154static const struct v4l2_pix_format sif_mode[] = {
155 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
156 .bytesperline = 160,
157 .sizeimage = 160 * 120,
158 .colorspace = V4L2_COLORSPACE_SRGB,
159 .priv = 1 | MODE_RAW | MODE_REDUCED_SIF},
160 {160, 120, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
161 .bytesperline = 160,
162 .sizeimage = 160 * 120 * 5 / 4,
163 .colorspace = V4L2_COLORSPACE_SRGB,
164 .priv = 1 | MODE_REDUCED_SIF},
165 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
166 .bytesperline = 176,
167 .sizeimage = 176 * 144,
168 .colorspace = V4L2_COLORSPACE_SRGB,
169 .priv = 1 | MODE_RAW},
170 {176, 144, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
171 .bytesperline = 176,
172 .sizeimage = 176 * 144 * 5 / 4,
173 .colorspace = V4L2_COLORSPACE_SRGB,
174 .priv = 1},
175 {320, 240, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
176 .bytesperline = 320,
177 .sizeimage = 320 * 240 * 5 / 4,
178 .colorspace = V4L2_COLORSPACE_SRGB,
179 .priv = 0 | MODE_REDUCED_SIF},
180 {352, 288, V4L2_PIX_FMT_SN9C10X, V4L2_FIELD_NONE,
181 .bytesperline = 352,
182 .sizeimage = 352 * 288 * 5 / 4,
183 .colorspace = V4L2_COLORSPACE_SRGB,
184 .priv = 0},
185};
186
187static const __u8 initHv7131d[] = {
188 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
189 0x00, 0x00,
190 0x00, 0x00, 0x00, 0x02, 0x02, 0x00,
191 0x28, 0x1e, 0x60, 0x8e, 0x42,
192};
193static const __u8 hv7131d_sensor_init[][8] = {
194 {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17},
195 {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17},
196 {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17},
197 {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17},
198 {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17},
199};
200
201static const __u8 initHv7131r[] = {
202 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
203 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
205 0x28, 0x1e, 0x60, 0x8a, 0x20,
206};
207static const __u8 hv7131r_sensor_init[][8] = {
208 {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
209 {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
210 {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
211 {0xc0, 0x11, 0x25, 0x03, 0x0e, 0x28, 0x00, 0x16},
212 {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15},
213};
214static const __u8 initOv6650[] = {
215 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
216 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b,
218 0x10,
219};
220static const __u8 ov6650_sensor_init[][8] = {
221
222
223
224
225
226 {0xa0, 0x60, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
227
228 {0xd0, 0x60, 0x11, 0xc0, 0x1b, 0x18, 0xc1, 0x10},
229
230 {0xb0, 0x60, 0x15, 0x00, 0x02, 0x18, 0xc1, 0x10},
231
232
233
234
235 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
236 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
237 {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10},
238
239 {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
240
241
242
243
244
245
246
247
248 {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10},
249 {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10},
250};
251
252static const __u8 initOv7630[] = {
253 0x04, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
254 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x01, 0x01, 0x0a,
256 0x28, 0x1e,
257 0x68, 0x8f, MCK_INIT1,
258};
259static const __u8 ov7630_sensor_init[][8] = {
260 {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
261 {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
262
263 {0xd0, 0x21, 0x12, 0x5c, 0x00, 0x80, 0x34, 0x10},
264 {0xa0, 0x21, 0x1b, 0x04, 0x00, 0x80, 0x34, 0x10},
265 {0xa0, 0x21, 0x20, 0x44, 0x00, 0x80, 0x34, 0x10},
266 {0xa0, 0x21, 0x23, 0xee, 0x00, 0x80, 0x34, 0x10},
267 {0xd0, 0x21, 0x26, 0xa0, 0x9a, 0xa0, 0x30, 0x10},
268 {0xb0, 0x21, 0x2a, 0x80, 0x00, 0xa0, 0x30, 0x10},
269 {0xb0, 0x21, 0x2f, 0x3d, 0x24, 0xa0, 0x30, 0x10},
270 {0xa0, 0x21, 0x32, 0x86, 0x24, 0xa0, 0x30, 0x10},
271 {0xb0, 0x21, 0x60, 0xa9, 0x4a, 0xa0, 0x30, 0x10},
272
273 {0xa0, 0x21, 0x65, 0x00, 0x42, 0xa0, 0x30, 0x10},
274 {0xa0, 0x21, 0x69, 0x38, 0x42, 0xa0, 0x30, 0x10},
275 {0xc0, 0x21, 0x6f, 0x88, 0x0b, 0x00, 0x30, 0x10},
276 {0xc0, 0x21, 0x74, 0x21, 0x8e, 0x00, 0x30, 0x10},
277 {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
278 {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
279};
280
281static const __u8 initPas106[] = {
282 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
283 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x04, 0x01, 0x00,
285 0x16, 0x12, 0x24, COMP1, MCK_INIT1,
286};
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312static const __u8 pas106_sensor_init[][8] = {
313
314 { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },
315
316 { 0xa1, 0x40, 0x03, 0x13, 0x00, 0x00, 0x00, 0x14 },
317
318 { 0xa1, 0x40, 0x04, 0x06, 0x00, 0x00, 0x00, 0x14 },
319
320 { 0xa1, 0x40, 0x05, 0x65, 0x00, 0x00, 0x00, 0x14 },
321
322 { 0xa1, 0x40, 0x06, 0xcd, 0x00, 0x00, 0x00, 0x14 },
323
324 { 0xa1, 0x40, 0x07, 0xc1, 0x00, 0x00, 0x00, 0x14 },
325
326 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
327 { 0xa1, 0x40, 0x08, 0x06, 0x00, 0x00, 0x00, 0x14 },
328
329 { 0xa1, 0x40, 0x09, 0x05, 0x00, 0x00, 0x00, 0x14 },
330
331 { 0xa1, 0x40, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x14 },
332
333 { 0xa1, 0x40, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x14 },
334
335 { 0xa1, 0x40, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x14 },
336
337 { 0xa1, 0x40, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x14 },
338
339 { 0xa1, 0x40, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x14 },
340
341 { 0xa1, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x14 },
342
343 { 0xa1, 0x40, 0x10, 0x06, 0x00, 0x00, 0x00, 0x14 },
344
345 { 0xa1, 0x40, 0x11, 0x06, 0x00, 0x00, 0x00, 0x14 },
346
347 { 0xa1, 0x40, 0x12, 0x06, 0x00, 0x00, 0x00, 0x14 },
348
349 { 0xa1, 0x40, 0x14, 0x02, 0x00, 0x00, 0x00, 0x14 },
350
351 { 0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14 },
352};
353
354static const __u8 initPas202[] = {
355 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
356 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a,
358 0x28, 0x1e, 0x20, 0x89, 0x20,
359};
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378static const __u8 pas202_sensor_init[][8] = {
379
380
381
382 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
383 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
384 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
385 {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10},
386 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
387 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
388 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
389 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
390 {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
391 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
392};
393
394static const __u8 initTas5110c[] = {
395 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
396 0x00, 0x00,
397 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a,
398 0x16, 0x12, 0x60, 0x86, 0x2b,
399};
400
401static const __u8 initTas5110d[] = {
402 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
403 0x00, 0x00,
404 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a,
405 0x16, 0x12, 0x60, 0x86, 0x2b,
406};
407
408static const __u8 tas5110c_sensor_init[][8] = {
409 {0x30, 0x11, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10},
410 {0x30, 0x11, 0x02, 0x20, 0xa9, 0x00, 0x00, 0x10},
411};
412
413
414
415
416
417static const __u8 tas5110d_sensor_init[][8] = {
418 {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
419};
420
421static const __u8 initTas5130[] = {
422 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
423 0x00, 0x00,
424 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a,
425 0x28, 0x1e, 0x60, COMP, MCK_INIT,
426};
427static const __u8 tas5130_sensor_init[][8] = {
428
429
430 {0x30, 0x11, 0x00, 0x40, 0x01, 0x00, 0x00, 0x10},
431
432 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
433};
434
435static const struct sensor_data sensor_data[] = {
436 SENS(initHv7131d, hv7131d_sensor_init, 0, 0),
437 SENS(initHv7131r, hv7131r_sensor_init, 0, 0),
438 SENS(initOv6650, ov6650_sensor_init, F_SIF, 0x60),
439 SENS(initOv7630, ov7630_sensor_init, 0, 0x21),
440 SENS(initPas106, pas106_sensor_init, F_SIF, 0),
441 SENS(initPas202, pas202_sensor_init, 0, 0),
442 SENS(initTas5110c, tas5110c_sensor_init, F_SIF, 0),
443 SENS(initTas5110d, tas5110d_sensor_init, F_SIF, 0),
444 SENS(initTas5130, tas5130_sensor_init, 0, 0),
445};
446
447
448static void reg_r(struct gspca_dev *gspca_dev,
449 __u16 value)
450{
451 int res;
452
453 if (gspca_dev->usb_err < 0)
454 return;
455
456 res = usb_control_msg(gspca_dev->dev,
457 usb_rcvctrlpipe(gspca_dev->dev, 0),
458 0,
459 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
460 value,
461 0,
462 gspca_dev->usb_buf, 1,
463 500);
464
465 if (res < 0) {
466 dev_err(gspca_dev->v4l2_dev.dev,
467 "Error reading register %02x: %d\n", value, res);
468 gspca_dev->usb_err = res;
469 }
470}
471
472static void reg_w(struct gspca_dev *gspca_dev,
473 __u16 value,
474 const __u8 *buffer,
475 int len)
476{
477 int res;
478
479 if (gspca_dev->usb_err < 0)
480 return;
481
482 memcpy(gspca_dev->usb_buf, buffer, len);
483 res = usb_control_msg(gspca_dev->dev,
484 usb_sndctrlpipe(gspca_dev->dev, 0),
485 0x08,
486 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
487 value,
488 0,
489 gspca_dev->usb_buf, len,
490 500);
491
492 if (res < 0) {
493 dev_err(gspca_dev->v4l2_dev.dev,
494 "Error writing register %02x: %d\n", value, res);
495 gspca_dev->usb_err = res;
496 }
497}
498
499static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
500{
501 int retry = 60;
502
503 if (gspca_dev->usb_err < 0)
504 return;
505
506
507 reg_w(gspca_dev, 0x08, buf, 8);
508 while (retry--) {
509 if (gspca_dev->usb_err < 0)
510 return;
511 msleep(1);
512 reg_r(gspca_dev, 0x08);
513 if (gspca_dev->usb_buf[0] & 0x04) {
514 if (gspca_dev->usb_buf[0] & 0x08) {
515 dev_err(gspca_dev->v4l2_dev.dev,
516 "i2c error writing %02x %02x %02x %02x"
517 " %02x %02x %02x %02x\n",
518 buf[0], buf[1], buf[2], buf[3],
519 buf[4], buf[5], buf[6], buf[7]);
520 gspca_dev->usb_err = -EIO;
521 }
522 return;
523 }
524 }
525
526 dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n");
527 gspca_dev->usb_err = -EIO;
528}
529
530static void i2c_w_vector(struct gspca_dev *gspca_dev,
531 const __u8 buffer[][8], int len)
532{
533 for (;;) {
534 if (gspca_dev->usb_err < 0)
535 return;
536 i2c_w(gspca_dev, *buffer);
537 len -= 8;
538 if (len <= 0)
539 break;
540 buffer++;
541 }
542}
543
544static void setbrightness(struct gspca_dev *gspca_dev)
545{
546 struct sd *sd = (struct sd *) gspca_dev;
547
548 switch (sd->sensor) {
549 case SENSOR_OV6650:
550 case SENSOR_OV7630: {
551 __u8 i2cOV[] =
552 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
553
554
555 i2cOV[1] = sensor_data[sd->sensor].sensor_addr;
556 i2cOV[3] = sd->brightness->val;
557 i2c_w(gspca_dev, i2cOV);
558 break;
559 }
560 case SENSOR_PAS106:
561 case SENSOR_PAS202: {
562 __u8 i2cpbright[] =
563 {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
564 __u8 i2cpdoit[] =
565 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
566
567
568 if (sd->sensor == SENSOR_PAS106) {
569 i2cpbright[2] = 7;
570 i2cpdoit[2] = 0x13;
571 }
572
573 if (sd->brightness->val < 127) {
574
575 i2cpbright[3] = 0x01;
576
577 i2cpbright[4] = 127 - sd->brightness->val;
578 } else
579 i2cpbright[4] = sd->brightness->val - 127;
580
581 i2c_w(gspca_dev, i2cpbright);
582 i2c_w(gspca_dev, i2cpdoit);
583 break;
584 }
585 default:
586 break;
587 }
588}
589
590static void setgain(struct gspca_dev *gspca_dev)
591{
592 struct sd *sd = (struct sd *) gspca_dev;
593 u8 gain = gspca_dev->gain->val;
594
595 switch (sd->sensor) {
596 case SENSOR_HV7131D: {
597 __u8 i2c[] =
598 {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17};
599
600 i2c[3] = 0x3f - gain;
601 i2c[4] = 0x3f - gain;
602 i2c[5] = 0x3f - gain;
603
604 i2c_w(gspca_dev, i2c);
605 break;
606 }
607 case SENSOR_TAS5110C:
608 case SENSOR_TAS5130CXX: {
609 __u8 i2c[] =
610 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
611
612 i2c[4] = 255 - gain;
613 i2c_w(gspca_dev, i2c);
614 break;
615 }
616 case SENSOR_TAS5110D: {
617 __u8 i2c[] = {
618 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 };
619 gain = 255 - gain;
620
621 i2c[3] |= (gain & 0x80) >> 7;
622 i2c[3] |= (gain & 0x40) >> 5;
623 i2c[3] |= (gain & 0x20) >> 3;
624 i2c[3] |= (gain & 0x10) >> 1;
625 i2c[3] |= (gain & 0x08) << 1;
626 i2c[3] |= (gain & 0x04) << 3;
627 i2c[3] |= (gain & 0x02) << 5;
628 i2c[3] |= (gain & 0x01) << 7;
629 i2c_w(gspca_dev, i2c);
630 break;
631 }
632 case SENSOR_OV6650:
633 case SENSOR_OV7630: {
634 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
635
636
637
638
639
640 if (sd->sensor == SENSOR_OV7630 && gain >= 32)
641 gain += 16;
642
643 i2c[1] = sensor_data[sd->sensor].sensor_addr;
644 i2c[3] = gain;
645 i2c_w(gspca_dev, i2c);
646 break;
647 }
648 case SENSOR_PAS106:
649 case SENSOR_PAS202: {
650 __u8 i2cpgain[] =
651 {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
652 __u8 i2cpcolorgain[] =
653 {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
654 __u8 i2cpdoit[] =
655 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
656
657
658 if (sd->sensor == SENSOR_PAS106) {
659 i2cpgain[2] = 0x0e;
660 i2cpcolorgain[0] = 0xd0;
661 i2cpcolorgain[2] = 0x09;
662 i2cpdoit[2] = 0x13;
663 }
664
665 i2cpgain[3] = gain;
666 i2cpcolorgain[3] = gain >> 1;
667 i2cpcolorgain[4] = gain >> 1;
668 i2cpcolorgain[5] = gain >> 1;
669 i2cpcolorgain[6] = gain >> 1;
670
671 i2c_w(gspca_dev, i2cpgain);
672 i2c_w(gspca_dev, i2cpcolorgain);
673 i2c_w(gspca_dev, i2cpdoit);
674 break;
675 }
676 default:
677 if (sd->bridge == BRIDGE_103) {
678 u8 buf[3] = { gain, gain, gain };
679 reg_w(gspca_dev, 0x05, buf, 3);
680 } else {
681 u8 buf[2];
682 buf[0] = gain << 4 | gain;
683 buf[1] = gain;
684 reg_w(gspca_dev, 0x10, buf, 2);
685 }
686 }
687}
688
689static void setexposure(struct gspca_dev *gspca_dev)
690{
691 struct sd *sd = (struct sd *) gspca_dev;
692
693 switch (sd->sensor) {
694 case SENSOR_HV7131D: {
695
696
697 __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17};
698 u16 reg = gspca_dev->exposure->val;
699
700 i2c[3] = reg >> 8;
701 i2c[4] = reg & 0xff;
702 i2c_w(gspca_dev, i2c);
703 break;
704 }
705 case SENSOR_TAS5110C:
706 case SENSOR_TAS5110D: {
707
708
709
710 u8 reg = gspca_dev->exposure->val;
711
712 reg = (reg << 4) | 0x0b;
713 reg_w(gspca_dev, 0x19, ®, 1);
714 break;
715 }
716 case SENSOR_OV6650:
717 case SENSOR_OV7630: {
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
733 int reg10, reg11, reg10_max;
734
735
736
737
738
739
740
741 if (sd->sensor == SENSOR_OV6650) {
742 reg10_max = 0x4d;
743 i2c[4] = 0xc0;
744 } else
745 reg10_max = 0x41;
746
747 reg11 = (15 * gspca_dev->exposure->val + 999) / 1000;
748 if (reg11 < 1)
749 reg11 = 1;
750 else if (reg11 > 16)
751 reg11 = 16;
752
753
754
755
756 if (gspca_dev->width == 640 && reg11 < 4)
757 reg11 = 4;
758
759
760
761
762 reg10 = (gspca_dev->exposure->val * 15 * reg10_max)
763 / (1000 * reg11);
764
765
766
767
768
769 if (gspca_dev->autogain->val && reg10 < 10)
770 reg10 = 10;
771 else if (reg10 > reg10_max)
772 reg10 = reg10_max;
773
774
775 i2c[1] = sensor_data[sd->sensor].sensor_addr;
776 i2c[3] = reg10;
777 i2c[4] |= reg11 - 1;
778
779
780 if (sd->reg11 == reg11)
781 i2c[0] = 0xa0;
782
783 i2c_w(gspca_dev, i2c);
784 if (gspca_dev->usb_err == 0)
785 sd->reg11 = reg11;
786 break;
787 }
788 case SENSOR_PAS202: {
789 __u8 i2cpframerate[] =
790 {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
791 __u8 i2cpexpo[] =
792 {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
793 const __u8 i2cpdoit[] =
794 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
795 int framerate_ctrl;
796
797
798
799
800
801
802
803
804
805
806
807 if (gspca_dev->exposure->val < 200) {
808 i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255)
809 / 200;
810 framerate_ctrl = 500;
811 } else {
812
813
814
815 framerate_ctrl = (gspca_dev->exposure->val - 200)
816 * 1000 / 229 + 500;
817 }
818
819 i2cpframerate[3] = framerate_ctrl >> 6;
820 i2cpframerate[4] = framerate_ctrl & 0x3f;
821 i2c_w(gspca_dev, i2cpframerate);
822 i2c_w(gspca_dev, i2cpexpo);
823 i2c_w(gspca_dev, i2cpdoit);
824 break;
825 }
826 case SENSOR_PAS106: {
827 __u8 i2cpframerate[] =
828 {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
829 __u8 i2cpexpo[] =
830 {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
831 const __u8 i2cpdoit[] =
832 {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
833 int framerate_ctrl;
834
835
836
837 if (gspca_dev->exposure->val < 150) {
838 i2cpexpo[3] = 150 - gspca_dev->exposure->val;
839 framerate_ctrl = 300;
840 } else {
841
842
843
844 framerate_ctrl = (gspca_dev->exposure->val - 150)
845 * 1000 / 230 + 300;
846 }
847
848 i2cpframerate[3] = framerate_ctrl >> 4;
849 i2cpframerate[4] = framerate_ctrl & 0x0f;
850 i2c_w(gspca_dev, i2cpframerate);
851 i2c_w(gspca_dev, i2cpexpo);
852 i2c_w(gspca_dev, i2cpdoit);
853 break;
854 }
855 default:
856 break;
857 }
858}
859
860static void setfreq(struct gspca_dev *gspca_dev)
861{
862 struct sd *sd = (struct sd *) gspca_dev;
863
864 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) {
865
866
867
868
869 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
870 switch (sd->plfreq->val) {
871 default:
872
873
874 i2c[3] = 0;
875 break;
876 case 1:
877 i2c[3] = (sd->sensor == SENSOR_OV6650)
878 ? 0x4f : 0x8a;
879 break;
880 }
881 i2c[1] = sensor_data[sd->sensor].sensor_addr;
882 i2c_w(gspca_dev, i2c);
883 }
884}
885
886static void do_autogain(struct gspca_dev *gspca_dev)
887{
888 struct sd *sd = (struct sd *) gspca_dev;
889 int deadzone, desired_avg_lum, avg_lum;
890
891 avg_lum = atomic_read(&sd->avg_lum);
892 if (avg_lum == -1)
893 return;
894
895 if (sd->autogain_ignore_frames > 0) {
896 sd->autogain_ignore_frames--;
897 return;
898 }
899
900
901
902 if (sensor_data[sd->sensor].flags & F_SIF) {
903 deadzone = 500;
904
905 desired_avg_lum = 5000;
906 } else {
907 deadzone = 1500;
908 desired_avg_lum = 13000;
909 }
910
911 if (sd->brightness)
912 desired_avg_lum = sd->brightness->val * desired_avg_lum / 127;
913
914 if (gspca_dev->exposure->maximum < 500) {
915 if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
916 desired_avg_lum, deadzone))
917 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
918 } else {
919 int gain_knee = gspca_dev->gain->maximum * 9 / 10;
920 if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum,
921 deadzone, gain_knee, sd->exposure_knee))
922 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
923 }
924}
925
926
927static int sd_config(struct gspca_dev *gspca_dev,
928 const struct usb_device_id *id)
929{
930 struct sd *sd = (struct sd *) gspca_dev;
931 struct cam *cam;
932
933 reg_r(gspca_dev, 0x00);
934 if (gspca_dev->usb_buf[0] != 0x10)
935 return -ENODEV;
936
937
938 sd->sensor = id->driver_info >> 8;
939 sd->bridge = id->driver_info & 0xff;
940
941 cam = &gspca_dev->cam;
942 if (!(sensor_data[sd->sensor].flags & F_SIF)) {
943 cam->cam_mode = vga_mode;
944 cam->nmodes = ARRAY_SIZE(vga_mode);
945 } else {
946 cam->cam_mode = sif_mode;
947 cam->nmodes = ARRAY_SIZE(sif_mode);
948 }
949 cam->npkt = 36;
950
951 return 0;
952}
953
954
955static int sd_init(struct gspca_dev *gspca_dev)
956{
957 const __u8 stop = 0x09;
958
959 reg_w(gspca_dev, 0x01, &stop, 1);
960
961 return gspca_dev->usb_err;
962}
963
964static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
965{
966 struct gspca_dev *gspca_dev =
967 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
968 struct sd *sd = (struct sd *)gspca_dev;
969
970 gspca_dev->usb_err = 0;
971
972 if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) {
973
974
975
976
977 gspca_dev->gain->val = gspca_dev->gain->default_value;
978 gspca_dev->exposure->val = gspca_dev->exposure->default_value;
979 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
980 }
981
982 if (!gspca_dev->streaming)
983 return 0;
984
985 switch (ctrl->id) {
986 case V4L2_CID_BRIGHTNESS:
987 setbrightness(gspca_dev);
988 break;
989 case V4L2_CID_AUTOGAIN:
990 if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
991 setexposure(gspca_dev);
992 if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
993 setgain(gspca_dev);
994 break;
995 case V4L2_CID_POWER_LINE_FREQUENCY:
996 setfreq(gspca_dev);
997 break;
998 default:
999 return -EINVAL;
1000 }
1001 return gspca_dev->usb_err;
1002}
1003
1004static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1005 .s_ctrl = sd_s_ctrl,
1006};
1007
1008
1009static int sd_init_controls(struct gspca_dev *gspca_dev)
1010{
1011 struct sd *sd = (struct sd *) gspca_dev;
1012 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1013
1014 gspca_dev->vdev.ctrl_handler = hdl;
1015 v4l2_ctrl_handler_init(hdl, 5);
1016
1017 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 ||
1018 sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202)
1019 sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1020 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
1021
1022
1023 switch (sd->sensor) {
1024 case SENSOR_OV6650:
1025 case SENSOR_PAS106:
1026 case SENSOR_PAS202:
1027 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1028 V4L2_CID_GAIN, 0, 31, 1, 15);
1029 break;
1030 case SENSOR_OV7630:
1031 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1032 V4L2_CID_GAIN, 0, 47, 1, 31);
1033 break;
1034 case SENSOR_HV7131D:
1035 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1036 V4L2_CID_GAIN, 0, 63, 1, 31);
1037 break;
1038 case SENSOR_TAS5110C:
1039 case SENSOR_TAS5110D:
1040 case SENSOR_TAS5130CXX:
1041 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1042 V4L2_CID_GAIN, 0, 255, 1, 127);
1043 break;
1044 default:
1045 if (sd->bridge == BRIDGE_103) {
1046 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1047 V4L2_CID_GAIN, 0, 127, 1, 63);
1048 } else {
1049 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1050 V4L2_CID_GAIN, 0, 15, 1, 7);
1051 }
1052 }
1053
1054
1055 switch (sd->sensor) {
1056 case SENSOR_HV7131D:
1057 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1058 V4L2_CID_EXPOSURE, 0, 8191, 1, 482);
1059 sd->exposure_knee = 964;
1060 break;
1061 case SENSOR_OV6650:
1062 case SENSOR_OV7630:
1063 case SENSOR_PAS106:
1064 case SENSOR_PAS202:
1065 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1066 V4L2_CID_EXPOSURE, 0, 1023, 1, 66);
1067 sd->exposure_knee = 200;
1068 break;
1069 case SENSOR_TAS5110C:
1070 case SENSOR_TAS5110D:
1071 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1072 V4L2_CID_EXPOSURE, 2, 15, 1, 2);
1073 break;
1074 }
1075
1076 if (gspca_dev->exposure) {
1077 gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1078 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1079 }
1080
1081 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630)
1082 sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
1083 V4L2_CID_POWER_LINE_FREQUENCY,
1084 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
1085 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED);
1086
1087 if (hdl->error) {
1088 pr_err("Could not initialize controls\n");
1089 return hdl->error;
1090 }
1091
1092 if (gspca_dev->autogain)
1093 v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
1094
1095 return 0;
1096}
1097
1098
1099static int sd_start(struct gspca_dev *gspca_dev)
1100{
1101 struct sd *sd = (struct sd *) gspca_dev;
1102 struct cam *cam = &gspca_dev->cam;
1103 int i, mode;
1104 __u8 regs[0x31];
1105
1106 mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07;
1107
1108 memcpy(®s[0x01], sensor_data[sd->sensor].bridge_init, 0x19);
1109
1110 regs[0x18] |= mode << 4;
1111
1112
1113 if (sd->bridge == BRIDGE_103) {
1114 regs[0x05] = 0x20;
1115 regs[0x06] = 0x20;
1116 regs[0x07] = 0x20;
1117 } else {
1118 regs[0x10] = 0x00;
1119 regs[0x11] = 0x00;
1120 }
1121
1122
1123 if (sensor_data[sd->sensor].flags & F_SIF) {
1124 regs[0x1a] = 0x14;
1125 regs[0x1b] = 0x0a;
1126 regs[0x1c] = 0x02;
1127 regs[0x1d] = 0x02;
1128 regs[0x1e] = 0x09;
1129 regs[0x1f] = 0x07;
1130 } else {
1131 regs[0x1a] = 0x1d;
1132 regs[0x1b] = 0x10;
1133 regs[0x1c] = 0x05;
1134 regs[0x1d] = 0x03;
1135 regs[0x1e] = 0x0f;
1136 regs[0x1f] = 0x0c;
1137 }
1138
1139
1140 for (i = 0; i < 16; i++)
1141 regs[0x20 + i] = i * 16;
1142 regs[0x20 + i] = 255;
1143
1144
1145 switch (sd->sensor) {
1146 case SENSOR_TAS5130CXX:
1147
1148
1149
1150
1151 regs[0x19] = mode ? 0x23 : 0x43;
1152 break;
1153 case SENSOR_OV7630:
1154
1155
1156
1157
1158 if (sd->bridge == BRIDGE_103) {
1159 regs[0x01] = 0x44;
1160 regs[0x12] = 0x02;
1161 }
1162 break;
1163 case SENSOR_PAS202:
1164
1165
1166 if (sd->bridge == BRIDGE_103)
1167 regs[0x12] += 1;
1168 break;
1169 }
1170
1171 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW)
1172 regs[0x18] &= ~0x80;
1173
1174
1175 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) {
1176 regs[0x12] += 16;
1177 regs[0x13] += 24;
1178 regs[0x15] = 320 / 16;
1179 regs[0x16] = 240 / 16;
1180 }
1181
1182
1183 reg_w(gspca_dev, 0x01, ®s[0x01], 1);
1184
1185 reg_w(gspca_dev, 0x17, ®s[0x17], 1);
1186
1187 reg_w(gspca_dev, 0x01, ®s[0x01],
1188 (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f);
1189
1190
1191 i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init,
1192 sensor_data[sd->sensor].sensor_init_size);
1193
1194
1195 switch (sd->sensor) {
1196 case SENSOR_PAS202: {
1197 const __u8 i2cpclockdiv[] =
1198 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
1199
1200 if (mode)
1201 i2c_w(gspca_dev, i2cpclockdiv);
1202 break;
1203 }
1204 case SENSOR_OV7630:
1205
1206
1207 if (sd->bridge == BRIDGE_103) {
1208 const __u8 i2c[] = { 0xa0, 0x21, 0x13,
1209 0x80, 0x00, 0x00, 0x00, 0x10 };
1210 i2c_w(gspca_dev, i2c);
1211 }
1212 break;
1213 }
1214
1215 reg_w(gspca_dev, 0x15, ®s[0x15], 2);
1216
1217 reg_w(gspca_dev, 0x18, ®s[0x18], 1);
1218
1219 reg_w(gspca_dev, 0x12, ®s[0x12], 1);
1220
1221 reg_w(gspca_dev, 0x13, ®s[0x13], 1);
1222
1223
1224 reg_w(gspca_dev, 0x17, ®s[0x17], 1);
1225
1226 reg_w(gspca_dev, 0x19, ®s[0x19], 1);
1227
1228 reg_w(gspca_dev, 0x1c, ®s[0x1c], 4);
1229
1230 reg_w(gspca_dev, 0x01, ®s[0x01], 1);
1231
1232 reg_w(gspca_dev, 0x18, ®s[0x18], 2);
1233 msleep(20);
1234
1235 sd->reg11 = -1;
1236
1237 setgain(gspca_dev);
1238 setbrightness(gspca_dev);
1239 setexposure(gspca_dev);
1240 setfreq(gspca_dev);
1241
1242 sd->frames_to_drop = 0;
1243 sd->autogain_ignore_frames = 0;
1244 gspca_dev->exp_too_high_cnt = 0;
1245 gspca_dev->exp_too_low_cnt = 0;
1246 atomic_set(&sd->avg_lum, -1);
1247 return gspca_dev->usb_err;
1248}
1249
1250static void sd_stopN(struct gspca_dev *gspca_dev)
1251{
1252 sd_init(gspca_dev);
1253}
1254
1255static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1256{
1257 struct sd *sd = (struct sd *) gspca_dev;
1258 int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12;
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269 for (i = 0; i < len; i++) {
1270 switch (sd->header_read) {
1271 case 0:
1272 if (data[i] == 0xff)
1273 sd->header_read++;
1274 break;
1275 case 1:
1276 if (data[i] == 0xff)
1277 sd->header_read++;
1278 else
1279 sd->header_read = 0;
1280 break;
1281 case 2:
1282 if (data[i] == 0x00)
1283 sd->header_read++;
1284 else if (data[i] != 0xff)
1285 sd->header_read = 0;
1286 break;
1287 case 3:
1288 if (data[i] == 0xc4)
1289 sd->header_read++;
1290 else if (data[i] == 0xff)
1291 sd->header_read = 1;
1292 else
1293 sd->header_read = 0;
1294 break;
1295 case 4:
1296 if (data[i] == 0xc4)
1297 sd->header_read++;
1298 else if (data[i] == 0xff)
1299 sd->header_read = 1;
1300 else
1301 sd->header_read = 0;
1302 break;
1303 case 5:
1304 if (data[i] == 0x96)
1305 sd->header_read++;
1306 else if (data[i] == 0xff)
1307 sd->header_read = 1;
1308 else
1309 sd->header_read = 0;
1310 break;
1311 default:
1312 sd->header[sd->header_read - 6] = data[i];
1313 sd->header_read++;
1314 if (sd->header_read == header_size) {
1315 sd->header_read = 0;
1316 return data + i + 1;
1317 }
1318 }
1319 }
1320 return NULL;
1321}
1322
1323static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1324 u8 *data,
1325 int len)
1326{
1327 int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0;
1328 struct sd *sd = (struct sd *) gspca_dev;
1329 struct cam *cam = &gspca_dev->cam;
1330 u8 *sof;
1331
1332 sof = find_sof(gspca_dev, data, len);
1333 if (sof) {
1334 if (sd->bridge == BRIDGE_103) {
1335 fr_h_sz = 18;
1336 lum_offset = 3;
1337 } else {
1338 fr_h_sz = 12;
1339 lum_offset = 2;
1340 }
1341
1342 len_after_sof = len - (sof - data);
1343 len = (sof - data) - fr_h_sz;
1344 if (len < 0)
1345 len = 0;
1346 }
1347
1348 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1349
1350
1351 int used;
1352 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
1353
1354 used = gspca_dev->image_len;
1355 if (used + len > size)
1356 len = size - used;
1357 }
1358
1359 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1360
1361 if (sof) {
1362 int lum = sd->header[lum_offset] +
1363 (sd->header[lum_offset + 1] << 8);
1364
1365
1366
1367
1368
1369
1370
1371
1372 if (lum == 0 && sd->prev_avg_lum != 0) {
1373 lum = -1;
1374 sd->frames_to_drop = 2;
1375 sd->prev_avg_lum = 0;
1376 } else
1377 sd->prev_avg_lum = lum;
1378 atomic_set(&sd->avg_lum, lum);
1379
1380 if (sd->frames_to_drop)
1381 sd->frames_to_drop--;
1382 else
1383 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1384
1385 gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof);
1386 }
1387}
1388
1389#if IS_ENABLED(CONFIG_INPUT)
1390static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1391 u8 *data,
1392 int len)
1393{
1394 int ret = -EINVAL;
1395
1396 if (len == 1 && data[0] == 1) {
1397 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1398 input_sync(gspca_dev->input_dev);
1399 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1400 input_sync(gspca_dev->input_dev);
1401 ret = 0;
1402 }
1403
1404 return ret;
1405}
1406#endif
1407
1408
1409static const struct sd_desc sd_desc = {
1410 .name = MODULE_NAME,
1411 .config = sd_config,
1412 .init = sd_init,
1413 .init_controls = sd_init_controls,
1414 .start = sd_start,
1415 .stopN = sd_stopN,
1416 .pkt_scan = sd_pkt_scan,
1417 .dq_callback = do_autogain,
1418#if IS_ENABLED(CONFIG_INPUT)
1419 .int_pkt_scan = sd_int_pkt_scan,
1420#endif
1421};
1422
1423
1424#define SB(sensor, bridge) \
1425 .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge
1426
1427
1428static const struct usb_device_id device_table[] = {
1429 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)},
1430 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)},
1431 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)},
1432 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1433 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
1434 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
1435 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1436#if !IS_ENABLED(CONFIG_USB_SN9C102)
1437 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1438 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
1439#endif
1440 {USB_DEVICE(0x0c45, 0x6027), SB(OV7630, 101)},
1441 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1442 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
1443 {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)},
1444
1445 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
1446 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
1447 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
1448
1449
1450 {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)},
1451 {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)},
1452
1453 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
1454 {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)},
1455 {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)},
1456 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
1457 {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)},
1458 {}
1459};
1460MODULE_DEVICE_TABLE(usb, device_table);
1461
1462
1463static int sd_probe(struct usb_interface *intf,
1464 const struct usb_device_id *id)
1465{
1466 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1467 THIS_MODULE);
1468}
1469
1470static struct usb_driver sd_driver = {
1471 .name = MODULE_NAME,
1472 .id_table = device_table,
1473 .probe = sd_probe,
1474 .disconnect = gspca_disconnect,
1475#ifdef CONFIG_PM
1476 .suspend = gspca_suspend,
1477 .resume = gspca_resume,
1478 .reset_resume = gspca_resume,
1479#endif
1480};
1481
1482module_usb_driver(sd_driver);
1483