1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
24#define MODULE_NAME "spca505"
25
26#include "gspca.h"
27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
30MODULE_LICENSE("GPL");
31
32
33struct sd {
34 struct gspca_dev gspca_dev;
35
36 u8 subtype;
37#define IntelPCCameraPro 0
38#define Nxultra 1
39};
40
41static const struct v4l2_pix_format vga_mode[] = {
42 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
43 .bytesperline = 160,
44 .sizeimage = 160 * 120 * 3 / 2,
45 .colorspace = V4L2_COLORSPACE_SRGB,
46 .priv = 4},
47 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
48 .bytesperline = 176,
49 .sizeimage = 176 * 144 * 3 / 2,
50 .colorspace = V4L2_COLORSPACE_SRGB,
51 .priv = 3},
52 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
53 .bytesperline = 320,
54 .sizeimage = 320 * 240 * 3 / 2,
55 .colorspace = V4L2_COLORSPACE_SRGB,
56 .priv = 2},
57 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
58 .bytesperline = 352,
59 .sizeimage = 352 * 288 * 3 / 2,
60 .colorspace = V4L2_COLORSPACE_SRGB,
61 .priv = 1},
62 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
63 .bytesperline = 640,
64 .sizeimage = 640 * 480 * 3 / 2,
65 .colorspace = V4L2_COLORSPACE_SRGB,
66 .priv = 0},
67};
68
69#define SPCA50X_OFFSET_DATA 10
70
71#define SPCA50X_REG_USB 0x02
72
73#define SPCA50X_USB_CTRL 0x00
74#define SPCA50X_CUSB_ENABLE 0x01
75
76#define SPCA50X_REG_GLOBAL 0x03
77#define SPCA50X_GMISC0_IDSEL 0x01
78#define SPCA50X_GLOBAL_MISC0 0x00
79
80#define SPCA50X_GLOBAL_MISC1 0x01
81#define SPCA50X_GLOBAL_MISC3 0x03
82#define SPCA50X_GMISC3_SAA7113RST 0x20
83
84
85#define SPCA50X_REG_COMPRESS 0x04
86
87
88
89
90static const u8 spca505_init_data[][3] = {
91
92 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
93
94 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
95 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
96
97 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, SPCA50X_GLOBAL_MISC0},
98
99 {0x05, 0x01, 0x10},
100
101 {0x05, 0x0f, 0x11},
102
103
104 {0x06, 0x10, 0x08},
105 {0x06, 0x00, 0x09},
106 {0x06, 0x00, 0x0a},
107 {0x06, 0x00, 0x0b},
108 {0x06, 0x10, 0x0c},
109 {0x06, 0x00, 0x0d},
110 {0x06, 0x00, 0x0e},
111 {0x06, 0x00, 0x0f},
112 {0x06, 0x10, 0x10},
113 {0x06, 0x02, 0x11},
114 {0x06, 0x00, 0x12},
115 {0x06, 0x04, 0x13},
116 {0x06, 0x02, 0x14},
117 {0x06, 0x8a, 0x51},
118 {0x06, 0x40, 0x52},
119 {0x06, 0xb6, 0x53},
120 {0x06, 0x3d, 0x54},
121 {}
122};
123
124
125
126
127static const u8 spca505_open_data_ccd[][3] = {
128
129
130 {0x03, 0x04, 0x01},
131
132 {0x03, 0x00, 0x01},
133
134
135
136 {0x04, 0x10, 0x01},
137
138 {0x04, 0x00, 0x04},
139 {0x04, 0x00, 0x05},
140 {0x04, 0x20, 0x06},
141 {0x04, 0x20, 0x07},
142
143 {0x08, 0x0a, 0x00},
144
145
146 {0x05, 0x00, 0x10},
147 {0x05, 0x00, 0x11},
148 {0x05, 0x00, 0x00},
149
150 {0x05, 0x00, 0x01},
151
152 {0x05, 0x00, 0x02},
153
154 {0x05, 0x00, 0x03},
155
156 {0x05, 0x00, 0x04},
157
158 {0x05, 0x80, 0x05},
159
160 {0x05, 0xe0, 0x06},
161
162 {0x05, 0x20, 0x07},
163
164 {0x05, 0xa0, 0x08},
165
166 {0x05, 0x0, 0x12},
167
168 {0x05, 0x02, 0x0f},
169
170 {0x05, 0x10, 0x46},
171
172 {0x05, 0x8, 0x4a},
173
174
175 {0x03, 0x08, 0x03},
176
177 {0x03, 0x08, 0x01},
178 {0x03, 0x0c, 0x03},
179
180 {0x03, 0x21, 0x00},
181
182
183
184 {0x06, 0x10, 0x08},
185 {0x06, 0x00, 0x09},
186 {0x06, 0x00, 0x0a},
187 {0x06, 0x00, 0x0b},
188 {0x06, 0x10, 0x0c},
189 {0x06, 0x00, 0x0d},
190 {0x06, 0x00, 0x0e},
191 {0x06, 0x00, 0x0f},
192 {0x06, 0x10, 0x10},
193 {0x06, 0x02, 0x11},
194 {0x06, 0x00, 0x12},
195 {0x06, 0x04, 0x13},
196 {0x06, 0x02, 0x14},
197 {0x06, 0x8a, 0x51},
198 {0x06, 0x40, 0x52},
199 {0x06, 0xb6, 0x53},
200 {0x06, 0x3d, 0x54},
201
202
203 {0x06, 0x3f, 0x1},
204
205 {0x06, 0x10, 0x02},
206 {0x06, 0x64, 0x07},
207 {0x06, 0x10, 0x08},
208 {0x06, 0x00, 0x09},
209 {0x06, 0x00, 0x0a},
210 {0x06, 0x00, 0x0b},
211 {0x06, 0x10, 0x0c},
212 {0x06, 0x00, 0x0d},
213 {0x06, 0x00, 0x0e},
214 {0x06, 0x00, 0x0f},
215 {0x06, 0x10, 0x10},
216 {0x06, 0x02, 0x11},
217 {0x06, 0x00, 0x12},
218 {0x06, 0x04, 0x13},
219 {0x06, 0x02, 0x14},
220 {0x06, 0x8a, 0x51},
221 {0x06, 0x40, 0x52},
222 {0x06, 0xb6, 0x53},
223 {0x06, 0x3d, 0x54},
224 {0x06, 0x60, 0x57},
225 {0x06, 0x20, 0x58},
226 {0x06, 0x15, 0x59},
227 {0x06, 0x05, 0x5a},
228
229 {0x05, 0x01, 0xc0},
230 {0x05, 0x10, 0xcb},
231 {0x05, 0x80, 0xc1},
232
233 {0x05, 0x0, 0xc2},
234
235 {0x05, 0x00, 0xca},
236 {0x05, 0x80, 0xc1},
237
238 {0x05, 0x04, 0xc2},
239 {0x05, 0x00, 0xca},
240 {0x05, 0x0, 0xc1},
241
242 {0x05, 0x00, 0xc2},
243 {0x05, 0x00, 0xca},
244 {0x05, 0x40, 0xc1},
245
246 {0x05, 0x17, 0xc2},
247 {0x05, 0x00, 0xca},
248 {0x05, 0x80, 0xc1},
249
250 {0x05, 0x06, 0xc2},
251 {0x05, 0x00, 0xca},
252 {0x05, 0x80, 0xc1},
253
254 {0x05, 0x04, 0xc2},
255 {0x05, 0x00, 0xca},
256
257 {0x03, 0x4c, 0x3},
258 {0x03, 0x18, 0x1},
259
260 {0x06, 0x70, 0x51},
261 {0x06, 0xbe, 0x53},
262 {0x06, 0x71, 0x57},
263 {0x06, 0x20, 0x58},
264 {0x06, 0x05, 0x59},
265 {0x06, 0x15, 0x5a},
266
267 {0x04, 0x00, 0x08},
268
269 {0x04, 0x12, 0x09},
270 {0x04, 0x21, 0x0a},
271 {0x04, 0x10, 0x0b},
272 {0x04, 0x21, 0x0c},
273 {0x04, 0x05, 0x00},
274
275 {0x04, 0x00, 0x01},
276
277 {0x06, 0x3f, 0x01},
278
279 {0x04, 0x00, 0x04},
280 {0x04, 0x00, 0x05},
281 {0x04, 0x40, 0x06},
282 {0x04, 0x40, 0x07},
283
284 {0x06, 0x1c, 0x17},
285 {0x06, 0xe2, 0x19},
286 {0x06, 0x1c, 0x1b},
287 {0x06, 0xe2, 0x1d},
288 {0x06, 0xaa, 0x1f},
289 {0x06, 0x70, 0x20},
290
291 {0x05, 0x01, 0x10},
292 {0x05, 0x00, 0x11},
293 {0x05, 0x01, 0x00},
294 {0x05, 0x05, 0x01},
295 {0x05, 0x00, 0xc1},
296
297 {0x05, 0x00, 0xc2},
298 {0x05, 0x00, 0xca},
299
300 {0x06, 0x70, 0x51},
301 {0x06, 0xbe, 0x53},
302 {}
303};
304
305
306
307
308
309
310#define initial_brightness 0x7f
311
312
313
314
315static const u8 spca505b_init_data[][3] = {
316
317 {0x02, 0x00, 0x00},
318 {0x02, 0x00, 0x01},
319 {0x02, 0x00, 0x02},
320 {0x02, 0x00, 0x03},
321 {0x02, 0x00, 0x04},
322 {0x02, 0x00, 0x05},
323 {0x02, 0x00, 0x06},
324 {0x02, 0x00, 0x07},
325 {0x02, 0x00, 0x08},
326 {0x02, 0x00, 0x09},
327 {0x03, 0x00, 0x00},
328 {0x03, 0x00, 0x01},
329 {0x03, 0x00, 0x02},
330 {0x03, 0x00, 0x03},
331 {0x03, 0x00, 0x04},
332 {0x03, 0x00, 0x05},
333 {0x03, 0x00, 0x06},
334 {0x04, 0x00, 0x00},
335 {0x04, 0x00, 0x02},
336 {0x04, 0x00, 0x04},
337 {0x04, 0x00, 0x05},
338 {0x04, 0x00, 0x06},
339 {0x04, 0x00, 0x07},
340 {0x04, 0x00, 0x08},
341 {0x04, 0x00, 0x09},
342 {0x04, 0x00, 0x0a},
343 {0x04, 0x00, 0x0b},
344 {0x04, 0x00, 0x0c},
345 {0x07, 0x00, 0x00},
346 {0x07, 0x00, 0x03},
347 {0x08, 0x00, 0x00},
348 {0x08, 0x00, 0x01},
349 {0x08, 0x00, 0x02},
350 {0x06, 0x18, 0x08},
351 {0x06, 0xfc, 0x09},
352 {0x06, 0xfc, 0x0a},
353 {0x06, 0xfc, 0x0b},
354 {0x06, 0x18, 0x0c},
355 {0x06, 0xfc, 0x0d},
356 {0x06, 0xfc, 0x0e},
357 {0x06, 0xfc, 0x0f},
358 {0x06, 0x18, 0x10},
359 {0x06, 0xfe, 0x12},
360 {0x06, 0x00, 0x11},
361 {0x06, 0x00, 0x14},
362 {0x06, 0x00, 0x13},
363 {0x06, 0x28, 0x51},
364 {0x06, 0xff, 0x53},
365 {0x02, 0x00, 0x08},
366
367 {0x03, 0x00, 0x03},
368 {0x03, 0x10, 0x03},
369 {}
370};
371
372
373
374
375static const u8 spca505b_open_data_ccd[][3] = {
376
377
378 {0x03, 0x04, 0x01},
379 {0x03, 0x00, 0x01},
380 {0x03, 0x00, 0x00},
381 {0x03, 0x21, 0x00},
382 {0x03, 0x00, 0x04},
383 {0x03, 0x00, 0x03},
384 {0x03, 0x18, 0x03},
385 {0x03, 0x08, 0x01},
386 {0x03, 0x1c, 0x03},
387 {0x03, 0x5c, 0x03},
388 {0x03, 0x5c, 0x03},
389 {0x03, 0x18, 0x01},
390
391
392 {0x04, 0x10, 0x01},
393 {0x04, 0x00, 0x04},
394 {0x04, 0x00, 0x05},
395 {0x04, 0x20, 0x06},
396 {0x04, 0x20, 0x07},
397
398 {0x08, 0x0a, 0x00},
399
400 {0x05, 0x00, 0x10},
401 {0x05, 0x00, 0x11},
402 {0x05, 0x00, 0x12},
403 {0x05, 0x6f, 0x00},
404 {0x05, initial_brightness >> 6, 0x00},
405 {0x05, (initial_brightness << 2) & 0xff, 0x01},
406 {0x05, 0x00, 0x02},
407 {0x05, 0x01, 0x03},
408 {0x05, 0x00, 0x04},
409 {0x05, 0x03, 0x05},
410 {0x05, 0xe0, 0x06},
411 {0x05, 0x20, 0x07},
412 {0x05, 0xa0, 0x08},
413 {0x05, 0x00, 0x12},
414 {0x05, 0x02, 0x0f},
415 {0x05, 0x80, 0x14},
416 {0x05, 0x01, 0xb0},
417 {0x05, 0x01, 0xbf},
418 {0x03, 0x02, 0x06},
419 {0x05, 0x10, 0x46},
420 {0x05, 0x08, 0x4a},
421
422 {0x06, 0x00, 0x01},
423 {0x06, 0x10, 0x02},
424 {0x06, 0x64, 0x07},
425 {0x06, 0x18, 0x08},
426 {0x06, 0xfc, 0x09},
427 {0x06, 0xfc, 0x0a},
428 {0x06, 0xfc, 0x0b},
429 {0x04, 0x00, 0x01},
430 {0x06, 0x18, 0x0c},
431 {0x06, 0xfc, 0x0d},
432 {0x06, 0xfc, 0x0e},
433 {0x06, 0xfc, 0x0f},
434 {0x06, 0x11, 0x10},
435 {0x06, 0x00, 0x11},
436 {0x06, 0xfe, 0x12},
437 {0x06, 0x00, 0x13},
438 {0x06, 0x00, 0x14},
439 {0x06, 0x9d, 0x51},
440 {0x06, 0x40, 0x52},
441 {0x06, 0x7c, 0x53},
442 {0x06, 0x40, 0x54},
443 {0x06, 0x02, 0x57},
444 {0x06, 0x03, 0x58},
445 {0x06, 0x15, 0x59},
446 {0x06, 0x05, 0x5a},
447 {0x06, 0x03, 0x56},
448 {0x06, 0x02, 0x3f},
449 {0x06, 0x00, 0x40},
450 {0x06, 0x39, 0x41},
451 {0x06, 0x69, 0x42},
452 {0x06, 0x87, 0x43},
453 {0x06, 0x9e, 0x44},
454 {0x06, 0xb1, 0x45},
455 {0x06, 0xbf, 0x46},
456 {0x06, 0xcc, 0x47},
457 {0x06, 0xd5, 0x48},
458 {0x06, 0xdd, 0x49},
459 {0x06, 0xe3, 0x4a},
460 {0x06, 0xe8, 0x4b},
461 {0x06, 0xed, 0x4c},
462 {0x06, 0xf2, 0x4d},
463 {0x06, 0xf7, 0x4e},
464 {0x06, 0xfc, 0x4f},
465 {0x06, 0xff, 0x50},
466
467 {0x05, 0x01, 0xc0},
468 {0x05, 0x10, 0xcb},
469 {0x05, 0x40, 0xc1},
470 {0x05, 0x04, 0xc2},
471 {0x05, 0x00, 0xca},
472 {0x05, 0x40, 0xc1},
473 {0x05, 0x09, 0xc2},
474 {0x05, 0x00, 0xca},
475 {0x05, 0xc0, 0xc1},
476 {0x05, 0x09, 0xc2},
477 {0x05, 0x00, 0xca},
478 {0x05, 0x40, 0xc1},
479 {0x05, 0x59, 0xc2},
480 {0x05, 0x00, 0xca},
481 {0x04, 0x00, 0x01},
482 {0x05, 0x80, 0xc1},
483 {0x05, 0xec, 0xc2},
484 {0x05, 0x0, 0xca},
485
486 {0x06, 0x02, 0x57},
487 {0x06, 0x01, 0x58},
488 {0x06, 0x15, 0x59},
489 {0x06, 0x0a, 0x5a},
490 {0x06, 0x01, 0x57},
491 {0x06, 0x8a, 0x03},
492 {0x06, 0x0a, 0x6c},
493 {0x06, 0x30, 0x01},
494 {0x06, 0x20, 0x02},
495 {0x06, 0x00, 0x03},
496
497 {0x05, 0x8c, 0x25},
498
499 {0x06, 0x4d, 0x51},
500 {0x06, 0x84, 0x53},
501 {0x06, 0x00, 0x57},
502 {0x06, 0x18, 0x08},
503 {0x06, 0xfc, 0x09},
504 {0x06, 0xfc, 0x0a},
505 {0x06, 0xfc, 0x0b},
506 {0x06, 0x18, 0x0c},
507 {0x06, 0xfc, 0x0d},
508 {0x06, 0xfc, 0x0e},
509 {0x06, 0xfc, 0x0f},
510 {0x06, 0x18, 0x10},
511
512 {0x05, 0x01, 0x02},
513
514 {0x04, 0x00, 0x08},
515 {0x04, 0x12, 0x09},
516 {0x04, 0x21, 0x0a},
517 {0x04, 0x10, 0x0b},
518 {0x04, 0x21, 0x0c},
519 {0x04, 0x1d, 0x00},
520 {0x04, 0x41, 0x01},
521
522 {0x04, 0x00, 0x04},
523 {0x04, 0x00, 0x05},
524 {0x04, 0x10, 0x06},
525 {0x04, 0x10, 0x07},
526 {0x04, 0x40, 0x06},
527 {0x04, 0x40, 0x07},
528 {0x04, 0x00, 0x04},
529 {0x04, 0x00, 0x05},
530
531 {0x06, 0x1c, 0x17},
532 {0x06, 0xe2, 0x19},
533 {0x06, 0x1c, 0x1b},
534 {0x06, 0xe2, 0x1d},
535 {0x06, 0x5f, 0x1f},
536 {0x06, 0x32, 0x20},
537
538 {0x05, initial_brightness >> 6, 0x00},
539 {0x05, (initial_brightness << 2) & 0xff, 0x01},
540 {0x05, 0x06, 0xc1},
541 {0x05, 0x58, 0xc2},
542 {0x05, 0x00, 0xca},
543 {0x05, 0x00, 0x11},
544 {}
545};
546
547static int reg_write(struct gspca_dev *gspca_dev,
548 u16 req, u16 index, u16 value)
549{
550 int ret;
551 struct usb_device *dev = gspca_dev->dev;
552
553 ret = usb_control_msg(dev,
554 usb_sndctrlpipe(dev, 0),
555 req,
556 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
557 value, index, NULL, 0, 500);
558 PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
559 req, index, value, ret);
560 if (ret < 0)
561 pr_err("reg write: error %d\n", ret);
562 return ret;
563}
564
565
566static int reg_read(struct gspca_dev *gspca_dev,
567 u16 req,
568 u16 index)
569{
570 int ret;
571
572 ret = usb_control_msg(gspca_dev->dev,
573 usb_rcvctrlpipe(gspca_dev->dev, 0),
574 req,
575 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
576 0,
577 index,
578 gspca_dev->usb_buf, 2,
579 500);
580 if (ret < 0)
581 return ret;
582 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
583}
584
585static int write_vector(struct gspca_dev *gspca_dev,
586 const u8 data[][3])
587{
588 int ret, i = 0;
589
590 while (data[i][0] != 0) {
591 ret = reg_write(gspca_dev, data[i][0], data[i][2],
592 data[i][1]);
593 if (ret < 0)
594 return ret;
595 i++;
596 }
597 return 0;
598}
599
600
601static int sd_config(struct gspca_dev *gspca_dev,
602 const struct usb_device_id *id)
603{
604 struct sd *sd = (struct sd *) gspca_dev;
605 struct cam *cam;
606
607 cam = &gspca_dev->cam;
608 cam->cam_mode = vga_mode;
609 sd->subtype = id->driver_info;
610 if (sd->subtype != IntelPCCameraPro)
611 cam->nmodes = ARRAY_SIZE(vga_mode);
612 else
613 cam->nmodes = ARRAY_SIZE(vga_mode) - 1;
614
615 return 0;
616}
617
618
619static int sd_init(struct gspca_dev *gspca_dev)
620{
621 struct sd *sd = (struct sd *) gspca_dev;
622
623 if (write_vector(gspca_dev,
624 sd->subtype == Nxultra
625 ? spca505b_init_data
626 : spca505_init_data))
627 return -EIO;
628 return 0;
629}
630
631static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
632{
633 reg_write(gspca_dev, 0x05, 0x00, (255 - brightness) >> 6);
634 reg_write(gspca_dev, 0x05, 0x01, (255 - brightness) << 2);
635}
636
637static int sd_start(struct gspca_dev *gspca_dev)
638{
639 struct sd *sd = (struct sd *) gspca_dev;
640 int ret, mode;
641 static u8 mode_tb[][3] = {
642
643 {0x00, 0x10, 0x10},
644 {0x01, 0x1a, 0x1a},
645 {0x02, 0x1c, 0x1d},
646 {0x04, 0x34, 0x34},
647 {0x05, 0x40, 0x40}
648 };
649
650 if (sd->subtype == Nxultra)
651 write_vector(gspca_dev, spca505b_open_data_ccd);
652 else
653 write_vector(gspca_dev, spca505_open_data_ccd);
654 ret = reg_read(gspca_dev, 0x06, 0x16);
655
656 if (ret < 0) {
657 PERR("register read failed err: %d", ret);
658 return ret;
659 }
660 if (ret != 0x0101) {
661 pr_err("After vector read returns 0x%04x should be 0x0101\n",
662 ret);
663 }
664
665 ret = reg_write(gspca_dev, 0x06, 0x16, 0x0a);
666 if (ret < 0)
667 return ret;
668 reg_write(gspca_dev, 0x05, 0xc2, 0x12);
669
670
671
672
673 reg_write(gspca_dev, 0x02, 0x00, 0x00);
674
675 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
676 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]);
677 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]);
678 reg_write(gspca_dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]);
679
680 return reg_write(gspca_dev, SPCA50X_REG_USB,
681 SPCA50X_USB_CTRL,
682 SPCA50X_CUSB_ENABLE);
683}
684
685static void sd_stopN(struct gspca_dev *gspca_dev)
686{
687
688 reg_write(gspca_dev, 0x02, 0x00, 0x00);
689}
690
691
692static void sd_stop0(struct gspca_dev *gspca_dev)
693{
694 if (!gspca_dev->present)
695 return;
696
697
698 reg_write(gspca_dev, 0x03, 0x03, 0x20);
699 reg_write(gspca_dev, 0x03, 0x01, 0x00);
700 reg_write(gspca_dev, 0x03, 0x00, 0x01);
701 reg_write(gspca_dev, 0x05, 0x10, 0x01);
702 reg_write(gspca_dev, 0x05, 0x11, 0x0f);
703}
704
705static void sd_pkt_scan(struct gspca_dev *gspca_dev,
706 u8 *data,
707 int len)
708{
709 switch (data[0]) {
710 case 0:
711 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
712 data += SPCA50X_OFFSET_DATA;
713 len -= SPCA50X_OFFSET_DATA;
714 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
715 break;
716 case 0xff:
717 break;
718 default:
719 data += 1;
720 len -= 1;
721 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
722 break;
723 }
724}
725
726static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
727{
728 struct gspca_dev *gspca_dev =
729 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
730
731 gspca_dev->usb_err = 0;
732
733 if (!gspca_dev->streaming)
734 return 0;
735
736 switch (ctrl->id) {
737 case V4L2_CID_BRIGHTNESS:
738 setbrightness(gspca_dev, ctrl->val);
739 break;
740 }
741 return gspca_dev->usb_err;
742}
743
744static const struct v4l2_ctrl_ops sd_ctrl_ops = {
745 .s_ctrl = sd_s_ctrl,
746};
747
748static int sd_init_controls(struct gspca_dev *gspca_dev)
749{
750 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
751
752 gspca_dev->vdev.ctrl_handler = hdl;
753 v4l2_ctrl_handler_init(hdl, 5);
754 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
755 V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
756
757 if (hdl->error) {
758 pr_err("Could not initialize controls\n");
759 return hdl->error;
760 }
761 return 0;
762}
763
764
765static const struct sd_desc sd_desc = {
766 .name = MODULE_NAME,
767 .config = sd_config,
768 .init_controls = sd_init_controls,
769 .init = sd_init,
770 .start = sd_start,
771 .stopN = sd_stopN,
772 .stop0 = sd_stop0,
773 .pkt_scan = sd_pkt_scan,
774};
775
776
777static const struct usb_device_id device_table[] = {
778 {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
779 {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
780
781 {}
782};
783MODULE_DEVICE_TABLE(usb, device_table);
784
785
786static int sd_probe(struct usb_interface *intf,
787 const struct usb_device_id *id)
788{
789 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
790 THIS_MODULE);
791}
792
793static struct usb_driver sd_driver = {
794 .name = MODULE_NAME,
795 .id_table = device_table,
796 .probe = sd_probe,
797 .disconnect = gspca_disconnect,
798#ifdef CONFIG_PM
799 .suspend = gspca_suspend,
800 .resume = gspca_resume,
801 .reset_resume = gspca_resume,
802#endif
803};
804
805module_usb_driver(sd_driver);
806