Syntek USB Video Camera
stk11xx-dev-0408.c
Go to the documentation of this file.
1
35/*
36 * note currently only supporting 720x576, 704x576 and 640x480 PAL
37 * other resolutions should work but aren't
38 */
39
40#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/kernel.h>
43#include <linux/version.h>
44#include <linux/errno.h>
45#include <linux/slab.h>
46#include <linux/kref.h>
47
48#include <linux/usb.h>
49#include <media/v4l2-common.h>
50#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)
51#include <media/v4l2-ioctl.h>
52#endif
53
54#include "stk11xx.h"
55#include "stk11xx-dev.h"
56
57int dev_stk0408_check_device(struct usb_stk11xx *dev);
58int dev_stk0408_select_input(struct usb_stk11xx *dev, int input);
59int dev_stk0408_write0(struct usb_stk11xx *dev, int mask, int val);
60
75{
76 int i;
77 int value;
78
79 STK_INFO("Initialize USB2.0 Syntek Capture device\n");
80
81//what is all this writing to register 2 doing?
82 usb_stk11xx_write_registry(dev, 0x0002, 0x0000);
83 usb_stk11xx_write_registry(dev, 0x0000, 0x0000);
84 usb_stk11xx_write_registry(dev, 0x0002, 0x0000);
85 usb_stk11xx_write_registry(dev, 0x0003, 0x0000);
86 usb_stk11xx_write_registry(dev, 0x0002, 0x0007);
87
88 usb_stk11xx_read_registry(dev, 0x0002, &value);
89 usb_stk11xx_read_registry(dev, 0x0000, &value);
90
91 dev_stk0408_write0(dev, 7, 4);
92 dev_stk0408_write0(dev, 7, 4);
93 dev_stk0408_write0(dev, 7, 6);
94 dev_stk0408_write0(dev, 7, 7);
95 dev_stk0408_write0(dev, 7, 6);
96 dev_stk0408_write0(dev, 7, 4);
97 dev_stk0408_write0(dev, 7, 5);
98
99 for (i=0;i<7;i++)
100 {
101 dev_stk0408_write0(dev, 7, 4);
102 dev_stk0408_write0(dev, 7, 4);
103 dev_stk0408_write0(dev, 7, 5);
104 }
105
106/* start set */
107 usb_stk11xx_write_registry(dev, 0x0002, 0x0007);
108 usb_stk11xx_write_registry(dev, 0x0000, 0x0001);
109
112
113 usb_stk11xx_write_registry(dev, 0x0500, 0x0094);
114 msleep(10);
115
117
118 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
119 usb_stk11xx_write_registry(dev, 0x0000, 0x0000);
120 usb_stk11xx_write_registry(dev, 0x0203, 0x00a0);
121 usb_stk11xx_read_registry(dev, 0x0003, &value);
122 usb_stk11xx_write_registry(dev, 0x0003, 0x0000);
123
124 usb_stk11xx_read_registry(dev, 0x0002, &value); //78?
125 usb_stk11xx_write_registry(dev, 0x0002, 0x007f);
126
127 usb_stk11xx_read_registry(dev, 0x0002, &value); //7f?
128 usb_stk11xx_read_registry(dev, 0x0000, &value); //0?
129
130 dev_stk0408_write0(dev, 0x07f, 0x004);
131 dev_stk0408_write0(dev, 0x07f, 0x004);
132 dev_stk0408_write0(dev, 0x07f, 0x006);
133 dev_stk0408_write0(dev, 0x07f, 0x007);
134 dev_stk0408_write0(dev, 0x07f, 0x006);
135 dev_stk0408_write0(dev, 0x07f, 0x004);
136 dev_stk0408_write0(dev, 0x07f, 0x005);
137 dev_stk0408_write0(dev, 0x07f, 0x004);
138 dev_stk0408_write0(dev, 0x07f, 0x004);
139 dev_stk0408_write0(dev, 0x07f, 0x005);
140 dev_stk0408_write0(dev, 0x07f, 0x004);
141 dev_stk0408_write0(dev, 0x07f, 0x006);
142 dev_stk0408_write0(dev, 0x07f, 0x007);
143 dev_stk0408_write0(dev, 0x07f, 0x006);
144 dev_stk0408_write0(dev, 0x07f, 0x006);
145 dev_stk0408_write0(dev, 0x07f, 0x007);
146 dev_stk0408_write0(dev, 0x07f, 0x006);
147 dev_stk0408_write0(dev, 0x07f, 0x004);
148 dev_stk0408_write0(dev, 0x07f, 0x005);
149 dev_stk0408_write0(dev, 0x07f, 0x004);
150 dev_stk0408_write0(dev, 0x07f, 0x004);
151 dev_stk0408_write0(dev, 0x07f, 0x005);
152 dev_stk0408_write0(dev, 0x07f, 0x004);
153 dev_stk0408_write0(dev, 0x07f, 0x004);
154 dev_stk0408_write0(dev, 0x07f, 0x005);
155 dev_stk0408_write0(dev, 0x07f, 0x004);
156 dev_stk0408_write0(dev, 0x07f, 0x004);
157 dev_stk0408_write0(dev, 0x07f, 0x005);
158
159 usb_stk11xx_write_registry(dev, 0x0002, 0x007f);
160 usb_stk11xx_write_registry(dev, 0x0000, 0x0001);
161
162 dev_stk11xx_check_device(dev, 500);
163
165
166 // Device is initialized and is ready !!!
167 STK_INFO("Syntek USB2.0 Capture device is ready\n");
168
169 return 0;
170}
171
172int dev_stk0408_write0(struct usb_stk11xx *dev, int mask, int val)
173{
174 int value;
175
176 usb_stk11xx_write_registry(dev, 0x0002, mask);
177 usb_stk11xx_write_registry(dev, 0x0000, val);
178 usb_stk11xx_read_registry(dev, 0x0002, &value);
179 usb_stk11xx_read_registry(dev, 0x0000, &value);
180
181 return 0;
182}
183
184int dev_stk0408_write_208(struct usb_stk11xx *dev, int val)
185{
186 int value;
187 int retok;
188
189 usb_stk11xx_read_registry(dev, 0x02ff, &value);
190 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
191
192 usb_stk11xx_write_registry(dev, 0x0208, val);
193 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
194
195 retok = dev_stk0408_check_device(dev);
196
197 if (retok != 1) {
198 return -1;
199 }
200
201 usb_stk11xx_read_registry(dev, 0x0209, &value);
202 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
203
204 return 1;
205}
206
207int dev_stk0408_write_saa(struct usb_stk11xx *dev, int reg, int val)
208{
209 int value;
210 int retok;
211
212 usb_stk11xx_read_registry(dev, 0x02ff, &value);
213 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
214
215 usb_stk11xx_write_registry(dev, 0x0204, reg);
216 usb_stk11xx_write_registry(dev, 0x0205, val);
217 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
218
219 retok = dev_stk0408_check_device(dev);
220
221 if (retok != 1) {
222 return -1;
223 }
224
225 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
226
227 return 1;
228}
229
230int dev_stk0408_set_resolution(struct usb_stk11xx *dev)
231{
232/*
233 * These registers control the resolution of the capture buffer.
234 *
235 * xres = (X - xsub) / 2
236 * yres = (Y - ysub)
237 *
238 */
239 int x,y,xsub,ysub;
240
241 // RRK, need to return for NTSC ?
242 if (dev->vsettings.norm == 0)
243 return 0;
244
245 switch (stk11xx_image_sizes[dev->resolution].x)
246 {
247 case 720:
248 x = 0x5a0;
249 xsub = 0;
250 break;
251
252 case 704:
253 case 352:
254 case 176:
255 x = 0x584;
256 xsub = 4;
257 break;
258
259 case 640:
260 case 320:
261 case 160:
262 x = 0x508;
263 xsub = 0x08;
264 break;
265
266 default:
267 return -1;
268 }
269
270 switch (stk11xx_image_sizes[dev->resolution].y)
271 {
272 case 576:
273 case 288:
274 case 144:
275 y = 0x121;
276 ysub = 0x1;
277 break;
278
279 case 480:
280 y = 0x110;
281 ysub= 0x20;
282 break;
283
284 case 120:
285 case 240:
286 y = 0x103;
287 ysub = 0x13;
288 break;
289
290 default:
291 return -1;
292 }
293
294 usb_stk11xx_write_registry(dev, 0x0110, xsub ); // xsub
295 usb_stk11xx_write_registry(dev, 0x0111, 0 );
296 usb_stk11xx_write_registry(dev, 0x0112, ysub ); // ysub
297 usb_stk11xx_write_registry(dev, 0x0113, 0 );
298 usb_stk11xx_write_registry(dev, 0x0114, x ); // X
299 usb_stk11xx_write_registry(dev, 0x0115, 5 );
300 usb_stk11xx_write_registry(dev, 0x0116, y ); // Y
301 usb_stk11xx_write_registry(dev, 0x0117, 1 );
302
303 return 0;
304}
305
306
320{
321 int value;
322 int asize;
323 int i;
324
325
326 static const int ids[] = {
327 0x203,0x00d,0x00f,0x103,0x018,0x01b,0x01c,0x01a,0x019,
328 0x300,0x350,0x351,0x352,0x353,0x300,0x018,0x202,0x110,
329 0x111,0x112,0x113,0x114,0x115,0x116,0x117
330 };
331
332 const int values[] = {
333 0x04a,0x000,0x002,0x000,0x000,0x00e,0x046,0x014,0x000,
334 0x012,0x02d,0x001,0x000,0x000,0x080,0x010,0x00f,
335 (dev->vsettings.norm ? 0x008 : 0x038),
336 0x000,
337 (dev->vsettings.norm ? 0x013 : 0x003),
338 0x000,
339 (dev->vsettings.norm ? 0x008 : 0x038),
340 0x005,
341 (dev->vsettings.norm ? 0x003 : 0x0f3),
342 (dev->vsettings.norm ? 0x001 : 0x000)
343 };
344
345 if (step != 1)
346 {
347 usb_stk11xx_read_registry(dev, 0x0003, &value);
348 usb_stk11xx_read_registry(dev, 0x0001, &value);
349 usb_stk11xx_read_registry(dev, 0x0002, &value);
350 usb_stk11xx_read_registry(dev, 0x0000, &value);
351 usb_stk11xx_read_registry(dev, 0x0003, &value);
352 usb_stk11xx_read_registry(dev, 0x0001, &value);
353 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
354 usb_stk11xx_write_registry(dev, 0x0000, 0x0000);
355 usb_stk11xx_write_registry(dev, 0x0003, 0x0080);
356 usb_stk11xx_write_registry(dev, 0x0001, 0x0003);
357
358 usb_stk11xx_read_registry(dev, 0x0002, &value);
359 usb_stk11xx_read_registry(dev, 0x0000, &value);
360 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
361 usb_stk11xx_read_registry(dev, 0x0000, &value);
362 usb_stk11xx_read_registry(dev, 0x0002, &value);
363 usb_stk11xx_read_registry(dev, 0x0000, &value);
364 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
365 usb_stk11xx_write_registry(dev, 0x0000, 0x0030);
366 usb_stk11xx_read_registry(dev, 0x0002, &value);
367 usb_stk11xx_read_registry(dev, 0x0002, &value);
368 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
369 }
370
371 asize = ARRAY_SIZE(values);
372
373 for(i=0; i<asize; i++) {
374 usb_stk11xx_write_registry(dev, ids[i], values[i]);
375 }
376
377 if (step == 1)
378 {
379 usb_stk11xx_read_registry(dev, 0x0100, &value);
380 usb_stk11xx_write_registry(dev, 0x0100, 0x0000);
381 }
382 else
383 {
384 usb_stk11xx_read_registry(dev, 0x0100, &value);
385 usb_stk11xx_write_registry(dev, 0x0100, 0x0033);
386 }
387
388 if (step <=2 )
389 {
390 return 0;
391 }
392
393 if (step==3)
394 {
396 }
397
398 usb_stk11xx_read_registry(dev, 0x0100, &value);
399 usb_stk11xx_write_registry(dev, 0x0100, 0x0033);
400 usb_stk11xx_write_registry(dev, 0x0103, 0x0000);
401 usb_stk11xx_write_registry(dev, 0x0100, 0x0033);
402
403
404 switch (step)
405 {
406 case 3: /* all fine */
407 usb_stk11xx_write_registry(dev, 0x0104, 0x0000);
408 usb_stk11xx_write_registry(dev, 0x0105, 0x0000);
409 usb_stk11xx_write_registry(dev, 0x0106, 0x0000);
410
412
413 usb_stk11xx_write_registry(dev, 0x0500, 0x0094);
414 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
415 usb_stk11xx_write_registry(dev, 0x0506, 0x0001);
416 usb_stk11xx_write_registry(dev, 0x0507, 0x0000);
417
418 break;
419
420 case 5:
421/* if ((dev->resolution == STK11XX_320x240)||
422 (dev->resolution == STK11XX_352x288))
423 {
424 usb_stk11xx_write_registry(dev, 0x0104, 0x0000);
425 usb_stk11xx_write_registry(dev, 0x0105, 0x0000);
426 } */
427
428 usb_stk11xx_write_registry(dev, 0x0106, 0x0000);
429
430 dev_stk0408_write_saa(dev, 0x02, 0x80);
431 dev_stk0408_write_208(dev,0x09);
432 dev_stk0408_write_saa(dev, 0x09, 0x00);
433
434 break;
435 }
436
437 if (step == 3)
438 {
439 dev_stk0408_write_saa(dev, 0x02, 0x80);
440 dev_stk0408_write_208(dev,0x09);
441 dev_stk0408_write_saa(dev, 0x09, 0x00);
442
443 //test and set?
444 usb_stk11xx_write_registry(dev, 0x0504, 0x0012);
445 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
446 usb_stk11xx_write_registry(dev, 0x0504, 0x0012);
447 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
448 usb_stk11xx_write_registry(dev, 0x0503, 0x0080);
449 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
450
451 usb_stk11xx_write_registry(dev, 0x0504, 0x0010);
452 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
453 usb_stk11xx_write_registry(dev, 0x0504, 0x0010);
454 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
455 usb_stk11xx_write_registry(dev, 0x0503, 0x0000);
456 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
457
458 usb_stk11xx_write_registry(dev, 0x0504, 0x000e);
459 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
460 usb_stk11xx_write_registry(dev, 0x0504, 0x000e);
461 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
462 usb_stk11xx_write_registry(dev, 0x0503, 0x0000);
463 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
464
465 usb_stk11xx_write_registry(dev, 0x0504, 0x0016);
466 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
467 usb_stk11xx_write_registry(dev, 0x0504, 0x0016);
468 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
469 usb_stk11xx_write_registry(dev, 0x0503, 0x0000);
470 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
471
472 usb_stk11xx_write_registry(dev, 0x0504, 0x001a);
473 usb_stk11xx_write_registry(dev, 0x0502, 0x0004);
474 usb_stk11xx_write_registry(dev, 0x0503, 0x0004);
475 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
476
477 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
478 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
479 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
480 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
481 usb_stk11xx_write_registry(dev, 0x0503, 0x0080);
482 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
483
484 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
485 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
486 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
487 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
488 usb_stk11xx_write_registry(dev, 0x0503, 0x0080);
489 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
490
491 dev_stk0408_write_saa(dev, 0x02, 0x80);
492 dev_stk0408_write_208(dev,0x09);
493 dev_stk0408_write_saa(dev, 0x09, 0x00);
494
495 }
496
497 if ((step == 4 )|| (step == 6))
498 {
499 dev_stk0408_write_saa(dev, 0x02, 0x80);
500 dev_stk0408_write_208(dev,0x09);
501 dev_stk0408_write_saa(dev, 0x09, 0x00);
502 dev_stk0408_write_208(dev,0x0e);
503 dev_stk0408_write_saa(dev, 0x0e, 0x01);
504
505 dev_stk0408_set_resolution(dev);
506
507 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
509 }
510
511 if (step == 6)
512 {
513 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
514
515 dev_stk0408_write_208(dev,0x0e);
516 dev_stk0408_write_saa(dev, 0x0e, 0x01);
517
518 dev_stk0408_set_resolution( dev);
519
520 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
521
522 dev_stk0408_select_input(dev, dev->vsettings.input);
523
525
526 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
527 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
528 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
529 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
530 usb_stk11xx_write_registry(dev, 0x0503, 0x0080);
531 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
532
533 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
534 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
535 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
536 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
537 usb_stk11xx_write_registry(dev, 0x0503, 0x0080);
538 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
539
540 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
541 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
542 usb_stk11xx_write_registry(dev, 0x0504, 0x0002);
543 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
544 usb_stk11xx_write_registry(dev, 0x0503, 0x0000);
545 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
546
547 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
548 usb_stk11xx_write_registry(dev, 0x0500, 0x008b);
549 usb_stk11xx_write_registry(dev, 0x0504, 0x001c);
550 usb_stk11xx_write_registry(dev, 0x0502, 0x0000);
551 usb_stk11xx_write_registry(dev, 0x0503, 0x0000);
552 usb_stk11xx_write_registry(dev, 0x0500, 0x008c);
553
555
556 }
557
558 if (step==4)
559 {
561 }
562
563 return 0;
564}
565
566
567int dev_stk0408_select_input(struct usb_stk11xx *dev, int input)
568{
569 switch (input)
570 {
571 case 1:
572 usb_stk11xx_write_registry(dev, 0x0000, 0x0098);
573 break;
574 case 2:
575 usb_stk11xx_write_registry(dev, 0x0000, 0x0090);
576 break;
577 case 3:
578 usb_stk11xx_write_registry(dev, 0x0000, 0x0088);
579 break;
580 case 4:
581 usb_stk11xx_write_registry(dev, 0x0000, 0x0080);
582 break;
583 }
584 usb_stk11xx_write_registry(dev, 0x0002, 0x0093);
585
586 return 0;
587
588}
589
590
601{
602 int value;
603 int value0;
604
605 usb_stk11xx_read_registry(dev, 0x0104, &value);
606 usb_stk11xx_read_registry(dev, 0x0105, &value);
607 usb_stk11xx_read_registry(dev, 0x0106, &value);
608
609 usb_stk11xx_read_registry(dev, 0x0100, &value);
610
611 value = value & 0x7f;
612 usb_stk11xx_write_registry(dev, 0x0100, value);
613
614 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
615 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
616 usb_stk11xx_write_registry(dev, 0x0018, 0x0000);
617
618 usb_stk11xx_read_registry(dev, 0x0002, &value);
619 usb_stk11xx_read_registry(dev, 0x0000, &value0);
620 usb_stk11xx_write_registry(dev, 0x0002, value);
621 usb_stk11xx_read_registry(dev, 0x0000, &value0);
622
623 return 0;
624}
625
626
638{
640
644
646
647 return 0;
648}
649
650int dev_stk0408_check_device(struct usb_stk11xx *dev)
651{
652 int i;
653 int value;
654 const int retry=2;
655
656 for (i=0; i < retry; i++) {
657 usb_stk11xx_read_registry(dev, 0x201, &value);
658
659//writes to 204/204 return 4 on success
660//writes to 208 return 1 on success
661
662 if (value == 0x04 || value == 0x01)
663 return 1;
664
665 if (value != 0x00)
666 {
667 STK_ERROR("Check device return error (0x0201 = %02X) !\n", value);
668 return -1;
669 }
670// msleep(10);
671 }
672
673 return 0;
674}
675
676
688{
689 int i;
690 int retok;
691 int asize;
692
693// PAL registers
694 static const int registers[] = {
695 0x01,0x03,0x04,0x05,0x06,0x07,0x08,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,
696 0x13,0x15,0x16,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,
697 0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b };
698
699 const int values[] = {
700 0x08,0x33,0x00,0x00,0xe9,0x0d,
701 (dev->vsettings.norm ? 0x38 : 0x78),
702 0x80,0x47,0x40,0x00,0x01,0x2a,0x00,0x0c,0xe7,
703 0x00,0x00,0x00,0x02,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
704 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x55,0xff,0xff,0xff,0x40,0x54,
705 (dev->vsettings.norm ? 0x07 : 0x0a),
706 0x83 };
707
708 asize = ARRAY_SIZE(values);
709
710 for(i=0; i<asize; i++) {
711 retok = dev_stk0408_write_saa(dev, registers[i], values[i]);
712
713 if (retok != 1) {
714 STK_ERROR("Load default sensor settings fail !\n");
715 return -1;
716 }
717 }
718
719 return 0;
720}
721
722
737{
739
740 return 0;
741}
742
743
753{
754 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
755
756//brightness
757 dev_stk0408_write_saa(dev, 0x0a, dev->vsettings.brightness >> 8); //80
758//contrast
759 dev_stk0408_write_saa(dev, 0x0b, dev->vsettings.contrast >> 9); //40
760//hue
761 dev_stk0408_write_saa(dev, 0x0d, (dev->vsettings.colour - 32768) >> 8); //00
762//saturation
763 dev_stk0408_write_saa(dev, 0x0c, (dev->vsettings.hue) >> 9); //40
764
765 STK_DEBUG("Set colour : %d\n", dev->vsettings.colour);
766 STK_DEBUG("Set contrast : %d\n", dev->vsettings.contrast);
767 STK_DEBUG("Set hue : %d\n", dev->vsettings.hue);
768 STK_DEBUG("Set brightness : %d\n", dev->vsettings.brightness);
769
770 return 1;
771}
772
773
785{
786 //Unknown, setting FPS seems to have no effect
787 return 0;
788}
789
790
802{
803 int value;
804 int value_116, value_117;
805
806 usb_stk11xx_read_registry(dev, 0x0116, &value_116);
807 usb_stk11xx_read_registry(dev, 0x0117, &value_117);
808
809 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
810 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
811
812 usb_stk11xx_read_registry(dev, 0x0100, &value);
813 value |= 0x80;
814
815// msleep(0x1f4);
816 usb_stk11xx_write_registry(dev, 0x0100, value);
817// msleep(0x64);
818
819 usb_stk11xx_write_registry(dev, 0x0116, value_116);
820 usb_stk11xx_write_registry(dev, 0x0117, value_117);
821
822 return 0;
823}
824
825
836{
837
839
841
842 return 0;
843}
844
845
857{
858 int value;
859
860 usb_stk11xx_read_registry(dev, 0x0100, &value);
861 value &= 0x7f;
862 usb_stk11xx_write_registry(dev, 0x0100, value);
863 msleep(5);
864
865 return 0;
866}
867
868/*
869 * Needs some more work and optimisation!
870 */
871void stk11xx_copy_uvyv(uint8_t *src, uint8_t *rgb,
872 struct stk11xx_coord *image,
873 struct stk11xx_coord *view,
874 const int hflip, const int vflip,
875 const int hfactor, const int vfactor,
876 bool order, bool field)
877{
878 int width = image->x;
879 int height = image->y;
880 int x;
881 int y;
882
883 uint8_t *line1 = NULL;
884 uint8_t *line2 = NULL;
885
886 static uint8_t *prev=0;
887 if (!prev)
888 prev = rgb;
889
890// printk("copy image %d - %d %d,%d,%d\n", width, height, hfactor, vfactor, field);
891
892// vfactor=1 interlace rows
893// vfactor=2 full frame copy, duplicate rows
894// vfactor=4 half frame, copy rows
895
896 if (field == false) // odd frame
897 {
898 prev += width * 2;
899 }
900
901 for ( y=0; y < height/2; y++)
902 {
903 if (vfactor == 1)
904 {
905 if (field == false) // odd frame
906 {
907 line1 = rgb + (y*width*4);
908 line2 = rgb + (y*width*4) + width*2;
909 }
910 else
911 {
912 line1 = rgb + (y*width*4) + width*2;
913 line2 = rgb + (y*width*4);
914 }
915 }
916 else
917 {
918 line1 = rgb + (y*width*2);
919 }
920
921
922 if (order && hfactor == 1) //fast line copy with memcpy
923 {
924 memcpy(line1,src,width*2);
925 src += width*2;
926 }
927 else //slow line copy with hscaling or YUV reorder
928 {
929 for ( x = 0; x < width*2; x+=4)
930 {
931 if (order) //yuv order
932 {
933 line1[x] = src[0];
934 line1[x+1] = src[1];
935 line1[x+2] = src[2];
936 line1[x+3] = src[3];
937 }
938 else
939 {
940 line1[x] = src[1];
941 line1[x+1] = src[0];
942 line1[x+2] = src[3];
943 line1[x+3] = src[2];
944 }
945 src += (4 * hfactor);
946 }
947 }
948
949 if (vfactor == 1) //interlaced copy from previous frame
950 {
951 memcpy(line2,prev,width*2);
952 prev += width*4;
953 }
954 else if (vfactor == 2) //1 : 1
955 {
956 }
957 else if (vfactor == 4) // 2 : 1
958 {
959 src += (width*2)*2;
960 }
961 }
962
963 prev = rgb;
964}
965
966/*
967 * needs more work and optimisation!
968 *
969 * rgb is horribly slow but just written to check the image is working
970 * replace with a proper yuv to rgb conversion
971 */
972#define CLAMP(x) x < 0 ? 0 : x > 255 ? 255 : x
973
974void stk11xx_copy_rgb(uint8_t *src, uint8_t *rgb,
975 struct stk11xx_coord *image,
976 struct stk11xx_coord *view,
977 const int hflip, const int vflip,
978 const int hfactor, const int vfactor,
979 bool order, bool four, bool field)
980{
981
982 int width = image->x;
983 int height = image->y;
984 int x;
985 int y;
986 int step;
987
988 bool off = false;
989
990 uint8_t *line1 = NULL;
991 uint8_t *line2 = NULL;
992
993 static uint8_t *prev=0;
994 if (!prev)
995 prev = rgb;
996
997 step = four?4:3;
998
999 if (field==false)
1000 {
1001 prev += width * step;
1002 }
1003
1004 //uvyv
1005 for ( y=0; y < height/2; y++)
1006 {
1007 if (vfactor == 1)
1008 {
1009 if (field == false) // odd frame
1010 {//
1011 line1 = rgb + (y * width * step * 2);
1012 line2 = rgb + (y * width * step * 2) + width * step;
1013 }
1014 else
1015 {
1016 line1 = rgb + (y * width * step * 2) + width * step;
1017 line2 = rgb + (y * width * step * 2);
1018 }
1019 }
1020 else
1021 {
1022 line1 = rgb + (y * width * step);
1023 }
1024
1025 off=false;
1026 for ( x = 0; x < width*step; x+=step)
1027 {
1028/*
1029 C = Y - 16
1030 D = U - 128
1031 E = V - 128
1032
1033 R = clip(( 298 * C + 409 * E + 128) >> 8)
1034 G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
1035 B = clip(( 298 * C + 516 * D + 128) >> 8)
1036*/
1037 int c = src[off ? 3 : 1];
1038 int d = src[0] - 128;
1039 int e = src[2] - 128;
1040
1041 int R = ((298*c + 409 * e + 128) >>8);
1042 int G = ((298*c - 100 * d - 208 * e + 128)>>8);
1043 int B = ((298*c + 516 * d + 128)>>8);
1044
1045 R = CLAMP(R);
1046 G = CLAMP(G);
1047 B = CLAMP(B);
1048
1049 if (order)
1050 {
1051 line1[x] = B;
1052 line1[x+1] = G;
1053 line1[x+2] = R;
1054 }
1055 else
1056 {
1057 line1[x] = R;
1058 line1[x+1] = G;
1059 line1[x+2] = B;
1060 }
1061 if (four)
1062 line1[x+3] = 0;
1063
1064 if (off)
1065 {
1066 src += (4 * hfactor);
1067 off = false;
1068 }
1069 else
1070 {
1071 off = true;
1072 }
1073
1074 }
1075
1076
1077 if (vfactor == 1) //interlaced copy from previous frame
1078 {
1079 for ( x = 0; x < width * step; x++ )
1080 {
1081 line2[x] = (*prev++); //line1[x];
1082 }
1083 prev += width * step;
1084 }
1085 }
1086
1087 prev = rgb;
1088}
1089
1090
1091int dev_stk0408_decode(struct usb_stk11xx *dev)
1092{
1093 void *data;
1094 void *image;
1095
1096 int vfactor;
1097 int hfactor;
1098 bool odd;
1099
1100 struct stk11xx_frame_buf *framebuf;
1101
1102 if (dev == NULL)
1103 return -EFAULT;
1104
1105 framebuf = dev->read_frame;
1106
1107 if (framebuf == NULL)
1108 return -EFAULT;
1109
1110 image = dev->image_data;
1111 STK_DEBUG("fill image %d\n", dev->fill_image);
1112
1113 image += dev->images[dev->fill_image].offset;
1114
1115 data = framebuf->data;
1116 odd = framebuf->odd;
1117
1118 switch (dev->resolution) {
1119
1120/*
1121//Currently only 1:1 resolutions are working
1122 case STK11XX_160x120:
1123 case STK11XX_176x144:
1124 hfactor = 4;
1125 vfactor = 4;
1126 break;
1127
1128 case STK11XX_320x240:
1129 case STK11XX_352x240:
1130 case STK11XX_352x288:
1131 hfactor = 2;
1132 vfactor = 2;
1133 break;
1134*/
1135 case STK11XX_640x480:
1136/* case STK11XX_720x480:*/
1137 case STK11XX_720x576:
1138 hfactor = 1;
1139 vfactor = 1;
1140 break;
1141
1142 default:
1143 return -EFAULT;
1144 }
1145
1146 switch (dev->vsettings.palette) {
1147 case STK11XX_PALETTE_RGB24:
1148 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, false,false,odd);
1149 break;
1150 case STK11XX_PALETTE_RGB32:
1151 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, false,true,odd);
1152 break;
1153 case STK11XX_PALETTE_BGR24:
1154 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, true,false,odd);
1155 break;
1156 case STK11XX_PALETTE_BGR32:
1157 stk11xx_copy_rgb(data, image, &dev->image, &dev->view, dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, true,true,odd);
1158 break;
1159
1160 case STK11XX_PALETTE_UYVY:
1161 stk11xx_copy_uvyv(data, image, &dev->image, &dev->view,dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, true,odd);
1162 break;
1163 case STK11XX_PALETTE_YUYV:
1164 stk11xx_copy_uvyv(data, image, &dev->image, &dev->view,dev->vsettings.hflip, dev->vsettings.vflip, hfactor, vfactor, false,odd);
1165 break;
1166 }
1167
1168 return 0;
1169
1170}
1171
int dev_stk0408_configure_device(struct usb_stk11xx *dev, int step)
This function configures the device.
int dev_stk0408_reconf_camera(struct usb_stk11xx *dev)
Reconfigure the camera before the stream.
int dev_stk0408_start_stream(struct usb_stk11xx *dev)
This function sets the device to start the stream.
int dev_stk0408_set_camera_quality(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk0408_stop_stream(struct usb_stk11xx *dev)
This function sets the device to stop the stream.
int dev_stk0408_camera_settings(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk0408_init_camera(struct usb_stk11xx *dev)
This function initializes the device for the stream.
int dev_stk0408_initialize_device(struct usb_stk11xx *dev)
This function initializes the device.
int dev_stk0408_set_camera_fps(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk0408_camera_asleep(struct usb_stk11xx *dev)
Wake-up the camera.
int dev_stk0408_sensor_settings(struct usb_stk11xx *dev)
This function sets the default sensor settings.
int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
This function switchs off the camera.
int dev_stk11xx_camera_settings(struct usb_stk11xx *dev)
This function permits to modify the settings of the camera.
int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
This function switchs on the camera.
int dev_stk11xx_check_device(struct usb_stk11xx *dev, int nbr)
This function permits to check the device in reading the register 0x0201.
Driver for Syntek USB video camera.
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
Definition stk11xx-v4l.c:59
static int hflip
int usb_stk11xx_write_registry(struct usb_stk11xx *dev, __u16 index, __u16 value)
Write a 16-bits value to a 16-bits register.
static int vflip
int usb_stk11xx_read_registry(struct usb_stk11xx *dev, __u16 index, int *value)
Read a 16-bits value from a 16-bits register.
int usb_stk11xx_set_feature(struct usb_stk11xx *dev, int index)
Send the message SET_FEATURE and choose the interface.
Driver for Syntek USB video camera.
#define STK_ERROR(str, args...)
Definition stk11xx.h:156
#define STK_INFO(str, args...)
Definition stk11xx.h:155
#define STK_DEBUG(str, args...)
Definition stk11xx.h:158
unsigned long offset
Definition stk11xx.h:274
struct stk11xx_video vsettings
Definition stk11xx.h:336