This source file includes following definitions.
- reg_r
- reg_w
- i2c_w
- i2c_w_vector
- setbrightness
- setgain
- setexposure
- setfreq
- do_autogain
- sd_config
- sd_init
- sd_s_ctrl
- sd_init_controls
- sd_start
- sd_stopN
- find_sof
- sd_pkt_scan
- sd_int_pkt_scan
- sd_probe
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
42 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
43 MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
44 MODULE_LICENSE("GPL");
45
46
47 struct 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
80 typedef const __u8 sensor_init_t[8];
81
82 struct 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
119 static 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 };
141 static 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
174 static 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 };
180 static 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
188 static 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 };
194 static 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 };
201 static 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 };
207 static 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
239 static 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 };
246 static 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
268 static 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
299 static 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
341 static 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
365 static 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
381 static 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
388 static 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
395 static 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
404 static const __u8 tas5110d_sensor_init[][8] = {
405 {0xa0, 0x61, 0x9a, 0xca, 0x00, 0x00, 0x00, 0x17},
406 };
407
408 static 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 };
414 static 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
422 static 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
435 static 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
459
460 gspca_dev->usb_buf[0] = 0;
461 }
462 }
463
464 static void reg_w(struct gspca_dev *gspca_dev,
465 __u16 value,
466 const __u8 *buffer,
467 int len)
468 {
469 int res;
470
471 if (gspca_dev->usb_err < 0)
472 return;
473
474 memcpy(gspca_dev->usb_buf, buffer, len);
475 res = usb_control_msg(gspca_dev->dev,
476 usb_sndctrlpipe(gspca_dev->dev, 0),
477 0x08,
478 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
479 value,
480 0,
481 gspca_dev->usb_buf, len,
482 500);
483
484 if (res < 0) {
485 dev_err(gspca_dev->v4l2_dev.dev,
486 "Error writing register %02x: %d\n", value, res);
487 gspca_dev->usb_err = res;
488 }
489 }
490
491 static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
492 {
493 int retry = 60;
494
495 if (gspca_dev->usb_err < 0)
496 return;
497
498
499 reg_w(gspca_dev, 0x08, buf, 8);
500 while (retry--) {
501 if (gspca_dev->usb_err < 0)
502 return;
503 msleep(1);
504 reg_r(gspca_dev, 0x08);
505 if (gspca_dev->usb_buf[0] & 0x04) {
506 if (gspca_dev->usb_buf[0] & 0x08) {
507 dev_err(gspca_dev->v4l2_dev.dev,
508 "i2c error writing %8ph\n", buf);
509 gspca_dev->usb_err = -EIO;
510 }
511 return;
512 }
513 }
514
515 dev_err(gspca_dev->v4l2_dev.dev, "i2c write timeout\n");
516 gspca_dev->usb_err = -EIO;
517 }
518
519 static void i2c_w_vector(struct gspca_dev *gspca_dev,
520 const __u8 buffer[][8], int len)
521 {
522 for (;;) {
523 if (gspca_dev->usb_err < 0)
524 return;
525 i2c_w(gspca_dev, *buffer);
526 len -= 8;
527 if (len <= 0)
528 break;
529 buffer++;
530 }
531 }
532
533 static void setbrightness(struct gspca_dev *gspca_dev)
534 {
535 struct sd *sd = (struct sd *) gspca_dev;
536
537 switch (sd->sensor) {
538 case SENSOR_OV6650:
539 case SENSOR_OV7630: {
540 __u8 i2cOV[] =
541 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
542
543
544 i2cOV[1] = sensor_data[sd->sensor].sensor_addr;
545 i2cOV[3] = sd->brightness->val;
546 i2c_w(gspca_dev, i2cOV);
547 break;
548 }
549 case SENSOR_PAS106:
550 case SENSOR_PAS202: {
551 __u8 i2cpbright[] =
552 {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
553 __u8 i2cpdoit[] =
554 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
555
556
557 if (sd->sensor == SENSOR_PAS106) {
558 i2cpbright[2] = 7;
559 i2cpdoit[2] = 0x13;
560 }
561
562 if (sd->brightness->val < 127) {
563
564 i2cpbright[3] = 0x01;
565
566 i2cpbright[4] = 127 - sd->brightness->val;
567 } else
568 i2cpbright[4] = sd->brightness->val - 127;
569
570 i2c_w(gspca_dev, i2cpbright);
571 i2c_w(gspca_dev, i2cpdoit);
572 break;
573 }
574 default:
575 break;
576 }
577 }
578
579 static void setgain(struct gspca_dev *gspca_dev)
580 {
581 struct sd *sd = (struct sd *) gspca_dev;
582 u8 gain = gspca_dev->gain->val;
583
584 switch (sd->sensor) {
585 case SENSOR_HV7131D: {
586 __u8 i2c[] =
587 {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17};
588
589 i2c[3] = 0x3f - gain;
590 i2c[4] = 0x3f - gain;
591 i2c[5] = 0x3f - gain;
592
593 i2c_w(gspca_dev, i2c);
594 break;
595 }
596 case SENSOR_TAS5110C:
597 case SENSOR_TAS5130CXX: {
598 __u8 i2c[] =
599 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
600
601 i2c[4] = 255 - gain;
602 i2c_w(gspca_dev, i2c);
603 break;
604 }
605 case SENSOR_TAS5110D: {
606 __u8 i2c[] = {
607 0xb0, 0x61, 0x02, 0x00, 0x10, 0x00, 0x00, 0x17 };
608 gain = 255 - gain;
609
610 i2c[3] |= (gain & 0x80) >> 7;
611 i2c[3] |= (gain & 0x40) >> 5;
612 i2c[3] |= (gain & 0x20) >> 3;
613 i2c[3] |= (gain & 0x10) >> 1;
614 i2c[3] |= (gain & 0x08) << 1;
615 i2c[3] |= (gain & 0x04) << 3;
616 i2c[3] |= (gain & 0x02) << 5;
617 i2c[3] |= (gain & 0x01) << 7;
618 i2c_w(gspca_dev, i2c);
619 break;
620 }
621 case SENSOR_OV6650:
622 case SENSOR_OV7630: {
623 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
624
625
626
627
628
629 if (sd->sensor == SENSOR_OV7630 && gain >= 32)
630 gain += 16;
631
632 i2c[1] = sensor_data[sd->sensor].sensor_addr;
633 i2c[3] = gain;
634 i2c_w(gspca_dev, i2c);
635 break;
636 }
637 case SENSOR_PAS106:
638 case SENSOR_PAS202: {
639 __u8 i2cpgain[] =
640 {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
641 __u8 i2cpcolorgain[] =
642 {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
643 __u8 i2cpdoit[] =
644 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
645
646
647 if (sd->sensor == SENSOR_PAS106) {
648 i2cpgain[2] = 0x0e;
649 i2cpcolorgain[0] = 0xd0;
650 i2cpcolorgain[2] = 0x09;
651 i2cpdoit[2] = 0x13;
652 }
653
654 i2cpgain[3] = gain;
655 i2cpcolorgain[3] = gain >> 1;
656 i2cpcolorgain[4] = gain >> 1;
657 i2cpcolorgain[5] = gain >> 1;
658 i2cpcolorgain[6] = gain >> 1;
659
660 i2c_w(gspca_dev, i2cpgain);
661 i2c_w(gspca_dev, i2cpcolorgain);
662 i2c_w(gspca_dev, i2cpdoit);
663 break;
664 }
665 default:
666 if (sd->bridge == BRIDGE_103) {
667 u8 buf[3] = { gain, gain, gain };
668 reg_w(gspca_dev, 0x05, buf, 3);
669 } else {
670 u8 buf[2];
671 buf[0] = gain << 4 | gain;
672 buf[1] = gain;
673 reg_w(gspca_dev, 0x10, buf, 2);
674 }
675 }
676 }
677
678 static void setexposure(struct gspca_dev *gspca_dev)
679 {
680 struct sd *sd = (struct sd *) gspca_dev;
681
682 switch (sd->sensor) {
683 case SENSOR_HV7131D: {
684
685
686 __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17};
687 u16 reg = gspca_dev->exposure->val;
688
689 i2c[3] = reg >> 8;
690 i2c[4] = reg & 0xff;
691 i2c_w(gspca_dev, i2c);
692 break;
693 }
694 case SENSOR_TAS5110C:
695 case SENSOR_TAS5110D: {
696
697
698
699 u8 reg = gspca_dev->exposure->val;
700
701 reg = (reg << 4) | 0x0b;
702 reg_w(gspca_dev, 0x19, ®, 1);
703 break;
704 }
705 case SENSOR_OV6650:
706 case SENSOR_OV7630: {
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
722 int reg10, reg11, reg10_max;
723
724
725
726
727
728
729
730 if (sd->sensor == SENSOR_OV6650) {
731 reg10_max = 0x4d;
732 i2c[4] = 0xc0;
733 } else
734 reg10_max = 0x41;
735
736 reg11 = (15 * gspca_dev->exposure->val + 999) / 1000;
737 if (reg11 < 1)
738 reg11 = 1;
739 else if (reg11 > 16)
740 reg11 = 16;
741
742
743
744
745 if (gspca_dev->pixfmt.width == 640 && reg11 < 4)
746 reg11 = 4;
747
748
749
750
751 reg10 = (gspca_dev->exposure->val * 15 * reg10_max)
752 / (1000 * reg11);
753
754
755
756
757
758 if (gspca_dev->autogain->val && reg10 < 10)
759 reg10 = 10;
760 else if (reg10 > reg10_max)
761 reg10 = reg10_max;
762
763
764 i2c[1] = sensor_data[sd->sensor].sensor_addr;
765 i2c[3] = reg10;
766 i2c[4] |= reg11 - 1;
767
768
769 if (sd->reg11 == reg11)
770 i2c[0] = 0xa0;
771
772 i2c_w(gspca_dev, i2c);
773 if (gspca_dev->usb_err == 0)
774 sd->reg11 = reg11;
775 break;
776 }
777 case SENSOR_PAS202: {
778 __u8 i2cpframerate[] =
779 {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
780 __u8 i2cpexpo[] =
781 {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
782 const __u8 i2cpdoit[] =
783 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
784 int framerate_ctrl;
785
786
787
788
789
790
791
792
793
794
795
796 if (gspca_dev->exposure->val < 200) {
797 i2cpexpo[3] = 255 - (gspca_dev->exposure->val * 255)
798 / 200;
799 framerate_ctrl = 500;
800 } else {
801
802
803
804 framerate_ctrl = (gspca_dev->exposure->val - 200)
805 * 1000 / 229 + 500;
806 }
807
808 i2cpframerate[3] = framerate_ctrl >> 6;
809 i2cpframerate[4] = framerate_ctrl & 0x3f;
810 i2c_w(gspca_dev, i2cpframerate);
811 i2c_w(gspca_dev, i2cpexpo);
812 i2c_w(gspca_dev, i2cpdoit);
813 break;
814 }
815 case SENSOR_PAS106: {
816 __u8 i2cpframerate[] =
817 {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
818 __u8 i2cpexpo[] =
819 {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
820 const __u8 i2cpdoit[] =
821 {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
822 int framerate_ctrl;
823
824
825
826 if (gspca_dev->exposure->val < 150) {
827 i2cpexpo[3] = 150 - gspca_dev->exposure->val;
828 framerate_ctrl = 300;
829 } else {
830
831
832
833 framerate_ctrl = (gspca_dev->exposure->val - 150)
834 * 1000 / 230 + 300;
835 }
836
837 i2cpframerate[3] = framerate_ctrl >> 4;
838 i2cpframerate[4] = framerate_ctrl & 0x0f;
839 i2c_w(gspca_dev, i2cpframerate);
840 i2c_w(gspca_dev, i2cpexpo);
841 i2c_w(gspca_dev, i2cpdoit);
842 break;
843 }
844 default:
845 break;
846 }
847 }
848
849 static void setfreq(struct gspca_dev *gspca_dev)
850 {
851 struct sd *sd = (struct sd *) gspca_dev;
852
853 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630) {
854
855
856
857
858 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
859 switch (sd->plfreq->val) {
860 default:
861
862
863 i2c[3] = 0;
864 break;
865 case 1:
866 i2c[3] = (sd->sensor == SENSOR_OV6650)
867 ? 0x4f : 0x8a;
868 break;
869 }
870 i2c[1] = sensor_data[sd->sensor].sensor_addr;
871 i2c_w(gspca_dev, i2c);
872 }
873 }
874
875 static void do_autogain(struct gspca_dev *gspca_dev)
876 {
877 struct sd *sd = (struct sd *) gspca_dev;
878 int deadzone, desired_avg_lum, avg_lum;
879
880 avg_lum = atomic_read(&sd->avg_lum);
881 if (avg_lum == -1)
882 return;
883
884 if (sd->autogain_ignore_frames > 0) {
885 sd->autogain_ignore_frames--;
886 return;
887 }
888
889
890
891 if (sensor_data[sd->sensor].flags & F_SIF) {
892 deadzone = 500;
893
894 desired_avg_lum = 5000;
895 } else {
896 deadzone = 1500;
897 desired_avg_lum = 13000;
898 }
899
900 if (sd->brightness)
901 desired_avg_lum = sd->brightness->val * desired_avg_lum / 127;
902
903 if (gspca_dev->exposure->maximum < 500) {
904 if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
905 desired_avg_lum, deadzone))
906 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
907 } else {
908 int gain_knee = (s32)gspca_dev->gain->maximum * 9 / 10;
909 if (gspca_expo_autogain(gspca_dev, avg_lum, desired_avg_lum,
910 deadzone, gain_knee, sd->exposure_knee))
911 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
912 }
913 }
914
915
916 static int sd_config(struct gspca_dev *gspca_dev,
917 const struct usb_device_id *id)
918 {
919 struct sd *sd = (struct sd *) gspca_dev;
920 struct cam *cam;
921
922 reg_r(gspca_dev, 0x00);
923 if (gspca_dev->usb_buf[0] != 0x10)
924 return -ENODEV;
925
926
927 sd->sensor = id->driver_info >> 8;
928 sd->bridge = id->driver_info & 0xff;
929
930 cam = &gspca_dev->cam;
931 if (!(sensor_data[sd->sensor].flags & F_SIF)) {
932 cam->cam_mode = vga_mode;
933 cam->nmodes = ARRAY_SIZE(vga_mode);
934 } else {
935 cam->cam_mode = sif_mode;
936 cam->nmodes = ARRAY_SIZE(sif_mode);
937 }
938 cam->npkt = 36;
939
940 return 0;
941 }
942
943
944 static int sd_init(struct gspca_dev *gspca_dev)
945 {
946 const __u8 stop = 0x09;
947
948 reg_w(gspca_dev, 0x01, &stop, 1);
949
950 return gspca_dev->usb_err;
951 }
952
953 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
954 {
955 struct gspca_dev *gspca_dev =
956 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
957 struct sd *sd = (struct sd *)gspca_dev;
958
959 gspca_dev->usb_err = 0;
960
961 if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) {
962
963
964
965
966 gspca_dev->gain->val = gspca_dev->gain->default_value;
967 gspca_dev->exposure->val = gspca_dev->exposure->default_value;
968 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
969 }
970
971 if (!gspca_dev->streaming)
972 return 0;
973
974 switch (ctrl->id) {
975 case V4L2_CID_BRIGHTNESS:
976 setbrightness(gspca_dev);
977 break;
978 case V4L2_CID_AUTOGAIN:
979 if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
980 setexposure(gspca_dev);
981 if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
982 setgain(gspca_dev);
983 break;
984 case V4L2_CID_POWER_LINE_FREQUENCY:
985 setfreq(gspca_dev);
986 break;
987 default:
988 return -EINVAL;
989 }
990 return gspca_dev->usb_err;
991 }
992
993 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
994 .s_ctrl = sd_s_ctrl,
995 };
996
997
998 static int sd_init_controls(struct gspca_dev *gspca_dev)
999 {
1000 struct sd *sd = (struct sd *) gspca_dev;
1001 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1002
1003 gspca_dev->vdev.ctrl_handler = hdl;
1004 v4l2_ctrl_handler_init(hdl, 5);
1005
1006 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630 ||
1007 sd->sensor == SENSOR_PAS106 || sd->sensor == SENSOR_PAS202)
1008 sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1009 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
1010
1011
1012 switch (sd->sensor) {
1013 case SENSOR_OV6650:
1014 case SENSOR_PAS106:
1015 case SENSOR_PAS202:
1016 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1017 V4L2_CID_GAIN, 0, 31, 1, 15);
1018 break;
1019 case SENSOR_OV7630:
1020 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1021 V4L2_CID_GAIN, 0, 47, 1, 31);
1022 break;
1023 case SENSOR_HV7131D:
1024 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1025 V4L2_CID_GAIN, 0, 63, 1, 31);
1026 break;
1027 case SENSOR_TAS5110C:
1028 case SENSOR_TAS5110D:
1029 case SENSOR_TAS5130CXX:
1030 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1031 V4L2_CID_GAIN, 0, 255, 1, 127);
1032 break;
1033 default:
1034 if (sd->bridge == BRIDGE_103) {
1035 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1036 V4L2_CID_GAIN, 0, 127, 1, 63);
1037 } else {
1038 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1039 V4L2_CID_GAIN, 0, 15, 1, 7);
1040 }
1041 }
1042
1043
1044 switch (sd->sensor) {
1045 case SENSOR_HV7131D:
1046 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1047 V4L2_CID_EXPOSURE, 0, 8191, 1, 482);
1048 sd->exposure_knee = 964;
1049 break;
1050 case SENSOR_OV6650:
1051 case SENSOR_OV7630:
1052 case SENSOR_PAS106:
1053 case SENSOR_PAS202:
1054 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1055 V4L2_CID_EXPOSURE, 0, 1023, 1, 66);
1056 sd->exposure_knee = 200;
1057 break;
1058 case SENSOR_TAS5110C:
1059 case SENSOR_TAS5110D:
1060 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1061 V4L2_CID_EXPOSURE, 2, 15, 1, 2);
1062 break;
1063 }
1064
1065 if (gspca_dev->exposure) {
1066 gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1067 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1068 }
1069
1070 if (sd->sensor == SENSOR_OV6650 || sd->sensor == SENSOR_OV7630)
1071 sd->plfreq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
1072 V4L2_CID_POWER_LINE_FREQUENCY,
1073 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0,
1074 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED);
1075
1076 if (hdl->error) {
1077 pr_err("Could not initialize controls\n");
1078 return hdl->error;
1079 }
1080
1081 if (gspca_dev->autogain)
1082 v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
1083
1084 return 0;
1085 }
1086
1087
1088 static int sd_start(struct gspca_dev *gspca_dev)
1089 {
1090 struct sd *sd = (struct sd *) gspca_dev;
1091 struct cam *cam = &gspca_dev->cam;
1092 int i, mode;
1093 __u8 regs[0x31];
1094
1095 mode = cam->cam_mode[gspca_dev->curr_mode].priv & 0x07;
1096
1097 memcpy(®s[0x01], sensor_data[sd->sensor].bridge_init, 0x19);
1098
1099 regs[0x18] |= mode << 4;
1100
1101
1102 if (sd->bridge == BRIDGE_103) {
1103 regs[0x05] = 0x20;
1104 regs[0x06] = 0x20;
1105 regs[0x07] = 0x20;
1106 } else {
1107 regs[0x10] = 0x00;
1108 regs[0x11] = 0x00;
1109 }
1110
1111
1112 if (sensor_data[sd->sensor].flags & F_SIF) {
1113 regs[0x1a] = 0x14;
1114 regs[0x1b] = 0x0a;
1115 regs[0x1c] = 0x02;
1116 regs[0x1d] = 0x02;
1117 regs[0x1e] = 0x09;
1118 regs[0x1f] = 0x07;
1119 } else {
1120 regs[0x1a] = 0x1d;
1121 regs[0x1b] = 0x10;
1122 regs[0x1c] = 0x05;
1123 regs[0x1d] = 0x03;
1124 regs[0x1e] = 0x0f;
1125 regs[0x1f] = 0x0c;
1126 }
1127
1128
1129 for (i = 0; i < 16; i++)
1130 regs[0x20 + i] = i * 16;
1131 regs[0x20 + i] = 255;
1132
1133
1134 switch (sd->sensor) {
1135 case SENSOR_TAS5130CXX:
1136
1137
1138
1139
1140 regs[0x19] = mode ? 0x23 : 0x43;
1141 break;
1142 case SENSOR_OV7630:
1143
1144
1145
1146
1147 if (sd->bridge == BRIDGE_103) {
1148 regs[0x01] = 0x44;
1149 regs[0x12] = 0x02;
1150 }
1151 break;
1152 case SENSOR_PAS202:
1153
1154
1155 if (sd->bridge == BRIDGE_103)
1156 regs[0x12] += 1;
1157 break;
1158 }
1159
1160 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW)
1161 regs[0x18] &= ~0x80;
1162
1163
1164 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_REDUCED_SIF) {
1165 regs[0x12] += 16;
1166 regs[0x13] += 24;
1167 regs[0x15] = 320 / 16;
1168 regs[0x16] = 240 / 16;
1169 }
1170
1171
1172 reg_w(gspca_dev, 0x01, ®s[0x01], 1);
1173
1174 reg_w(gspca_dev, 0x17, ®s[0x17], 1);
1175
1176 reg_w(gspca_dev, 0x01, ®s[0x01],
1177 (sd->bridge == BRIDGE_103) ? 0x30 : 0x1f);
1178
1179
1180 i2c_w_vector(gspca_dev, sensor_data[sd->sensor].sensor_init,
1181 sensor_data[sd->sensor].sensor_init_size);
1182
1183
1184 switch (sd->sensor) {
1185 case SENSOR_PAS202: {
1186 const __u8 i2cpclockdiv[] =
1187 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
1188
1189 if (mode)
1190 i2c_w(gspca_dev, i2cpclockdiv);
1191 break;
1192 }
1193 case SENSOR_OV7630:
1194
1195
1196 if (sd->bridge == BRIDGE_103) {
1197 const __u8 i2c[] = { 0xa0, 0x21, 0x13,
1198 0x80, 0x00, 0x00, 0x00, 0x10 };
1199 i2c_w(gspca_dev, i2c);
1200 }
1201 break;
1202 }
1203
1204 reg_w(gspca_dev, 0x15, ®s[0x15], 2);
1205
1206 reg_w(gspca_dev, 0x18, ®s[0x18], 1);
1207
1208 reg_w(gspca_dev, 0x12, ®s[0x12], 1);
1209
1210 reg_w(gspca_dev, 0x13, ®s[0x13], 1);
1211
1212
1213 reg_w(gspca_dev, 0x17, ®s[0x17], 1);
1214
1215 reg_w(gspca_dev, 0x19, ®s[0x19], 1);
1216
1217 reg_w(gspca_dev, 0x1c, ®s[0x1c], 4);
1218
1219 reg_w(gspca_dev, 0x01, ®s[0x01], 1);
1220
1221 reg_w(gspca_dev, 0x18, ®s[0x18], 2);
1222 msleep(20);
1223
1224 sd->reg11 = -1;
1225
1226 setgain(gspca_dev);
1227 setbrightness(gspca_dev);
1228 setexposure(gspca_dev);
1229 setfreq(gspca_dev);
1230
1231 sd->frames_to_drop = 0;
1232 sd->autogain_ignore_frames = 0;
1233 gspca_dev->exp_too_high_cnt = 0;
1234 gspca_dev->exp_too_low_cnt = 0;
1235 atomic_set(&sd->avg_lum, -1);
1236 return gspca_dev->usb_err;
1237 }
1238
1239 static void sd_stopN(struct gspca_dev *gspca_dev)
1240 {
1241 sd_init(gspca_dev);
1242 }
1243
1244 static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1245 {
1246 struct sd *sd = (struct sd *) gspca_dev;
1247 int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12;
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258 for (i = 0; i < len; i++) {
1259 switch (sd->header_read) {
1260 case 0:
1261 if (data[i] == 0xff)
1262 sd->header_read++;
1263 break;
1264 case 1:
1265 if (data[i] == 0xff)
1266 sd->header_read++;
1267 else
1268 sd->header_read = 0;
1269 break;
1270 case 2:
1271 if (data[i] == 0x00)
1272 sd->header_read++;
1273 else if (data[i] != 0xff)
1274 sd->header_read = 0;
1275 break;
1276 case 3:
1277 if (data[i] == 0xc4)
1278 sd->header_read++;
1279 else if (data[i] == 0xff)
1280 sd->header_read = 1;
1281 else
1282 sd->header_read = 0;
1283 break;
1284 case 4:
1285 if (data[i] == 0xc4)
1286 sd->header_read++;
1287 else if (data[i] == 0xff)
1288 sd->header_read = 1;
1289 else
1290 sd->header_read = 0;
1291 break;
1292 case 5:
1293 if (data[i] == 0x96)
1294 sd->header_read++;
1295 else if (data[i] == 0xff)
1296 sd->header_read = 1;
1297 else
1298 sd->header_read = 0;
1299 break;
1300 default:
1301 sd->header[sd->header_read - 6] = data[i];
1302 sd->header_read++;
1303 if (sd->header_read == header_size) {
1304 sd->header_read = 0;
1305 return data + i + 1;
1306 }
1307 }
1308 }
1309 return NULL;
1310 }
1311
1312 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1313 u8 *data,
1314 int len)
1315 {
1316 int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0;
1317 struct sd *sd = (struct sd *) gspca_dev;
1318 struct cam *cam = &gspca_dev->cam;
1319 u8 *sof;
1320
1321 sof = find_sof(gspca_dev, data, len);
1322 if (sof) {
1323 if (sd->bridge == BRIDGE_103) {
1324 fr_h_sz = 18;
1325 lum_offset = 3;
1326 } else {
1327 fr_h_sz = 12;
1328 lum_offset = 2;
1329 }
1330
1331 len_after_sof = len - (sof - data);
1332 len = (sof - data) - fr_h_sz;
1333 if (len < 0)
1334 len = 0;
1335 }
1336
1337 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1338
1339
1340 int used;
1341 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
1342
1343 used = gspca_dev->image_len;
1344 if (used + len > size)
1345 len = size - used;
1346 }
1347
1348 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1349
1350 if (sof) {
1351 int lum = sd->header[lum_offset] +
1352 (sd->header[lum_offset + 1] << 8);
1353
1354
1355
1356
1357
1358
1359
1360
1361 if (lum == 0 && sd->prev_avg_lum != 0) {
1362 lum = -1;
1363 sd->frames_to_drop = 2;
1364 sd->prev_avg_lum = 0;
1365 } else
1366 sd->prev_avg_lum = lum;
1367 atomic_set(&sd->avg_lum, lum);
1368
1369 if (sd->frames_to_drop)
1370 sd->frames_to_drop--;
1371 else
1372 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1373
1374 gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof);
1375 }
1376 }
1377
1378 #if IS_ENABLED(CONFIG_INPUT)
1379 static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1380 u8 *data,
1381 int len)
1382 {
1383 int ret = -EINVAL;
1384
1385 if (len == 1 && data[0] == 1) {
1386 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1387 input_sync(gspca_dev->input_dev);
1388 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1389 input_sync(gspca_dev->input_dev);
1390 ret = 0;
1391 }
1392
1393 return ret;
1394 }
1395 #endif
1396
1397
1398 static const struct sd_desc sd_desc = {
1399 .name = MODULE_NAME,
1400 .config = sd_config,
1401 .init = sd_init,
1402 .init_controls = sd_init_controls,
1403 .start = sd_start,
1404 .stopN = sd_stopN,
1405 .pkt_scan = sd_pkt_scan,
1406 .dq_callback = do_autogain,
1407 #if IS_ENABLED(CONFIG_INPUT)
1408 .int_pkt_scan = sd_int_pkt_scan,
1409 #endif
1410 };
1411
1412
1413 #define SB(sensor, bridge) \
1414 .driver_info = (SENSOR_ ## sensor << 8) | BRIDGE_ ## bridge
1415
1416
1417 static const struct usb_device_id device_table[] = {
1418 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)},
1419 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)},
1420 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)},
1421 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1422 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
1423 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
1424 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1425 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1426 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
1427 {USB_DEVICE(0x0c45, 0x6027), SB(OV7630, 101)},
1428 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1429 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
1430 {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)},
1431
1432 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
1433 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
1434 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
1435
1436
1437 {USB_DEVICE(0x0c45, 0x6083), SB(HV7131D, 103)},
1438 {USB_DEVICE(0x0c45, 0x608c), SB(HV7131R, 103)},
1439
1440 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
1441 {USB_DEVICE(0x0c45, 0x60a8), SB(PAS106, 103)},
1442 {USB_DEVICE(0x0c45, 0x60aa), SB(TAS5130CXX, 103)},
1443 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
1444 {USB_DEVICE(0x0c45, 0x60b0), SB(OV7630, 103)},
1445 {}
1446 };
1447 MODULE_DEVICE_TABLE(usb, device_table);
1448
1449
1450 static int sd_probe(struct usb_interface *intf,
1451 const struct usb_device_id *id)
1452 {
1453 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1454 THIS_MODULE);
1455 }
1456
1457 static struct usb_driver sd_driver = {
1458 .name = MODULE_NAME,
1459 .id_table = device_table,
1460 .probe = sd_probe,
1461 .disconnect = gspca_disconnect,
1462 #ifdef CONFIG_PM
1463 .suspend = gspca_suspend,
1464 .resume = gspca_resume,
1465 .reset_resume = gspca_resume,
1466 #endif
1467 };
1468
1469 module_usb_driver(sd_driver);