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