forked from hbars/stk11xx-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stk11xx-dev.c
756 lines (618 loc) · 14.3 KB
/
stk11xx-dev.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/**
* @file stk11xx-dev.c
* @author Nicolas VIVIEN
* @date 2006-10-23
* @version v2.2.x
*
* @brief Driver for Syntek USB video camera
*
* @note Copyright (C) Nicolas VIVIEN
*
* @par Licences
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @par SubVersion
* $Date$
* $Revision$
* $Author$
* $HeadURL$
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/kref.h>
#include <linux/usb.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include "stk11xx.h"
#include "stk11xx-dev.h"
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function permits to initialize the device.
*
* This function must be called at first. It's the start of the
* initialization process. After this process, the device is
* completly initalized and it's ready.
*
* This function is written from the USB log.
*/
int dev_stk11xx_initialize_device(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_initialize_device(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_initialize_device(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_initialize_device(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_initialize_device(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_initialize_device(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_initialize_device(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_initialize_device(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_initialize_device(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_initialize_device(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function initializes the device for the stream.
*
* It's the start. This function has to be called at first, before
* enabling the video stream.
*/
int dev_stk11xx_init_camera(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_init_camera(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_init_camera(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_init_camera(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_init_camera(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_init_camera(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_init_camera(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_init_camera(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_init_camera(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_init_camera(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
* @param nbr Number of tries
*
* @returns 0 if all is OK
*
* @brief This function permits to check the device in reading the register 0x0201.
*
* When we configure the stk11xx, this function is used to check the device status.
* - If the read value is 0x00, then the device isn't ready.
* - If the read value is 0x04, then the device is ready.
* - If the read value is other, then the device is misconfigured.
*/
int dev_stk11xx_check_device(struct usb_stk11xx *dev, int nbr)
{
int i;
int value;
for (i=0; i<nbr; i++) {
usb_stk11xx_read_registry(dev, 0x201, &value);
if (value == 0x00) {
}
else if ((value == 0x11) || (value == 0x14)) {
}
else if ((value == 0x30) || (value == 0x31)) {
}
else if ((value == 0x51)) {
}
else if ((value == 0x70) || (value == 0x71)) {
}
else if ((value == 0x91)) {
}
else if (value == 0x01) {
return 1;
}
else if ((value == 0x04) || (value == 0x05))
return 1;
else if (value == 0x15)
return 1;
else {
STK_ERROR("Check device return error (0x0201 = %02X) !\n", value);
return -1;
}
}
return 0;
}
/**
* @param dev Device structure
*
* @returns Value of register 0x0001
*
* @brief A espece of software watchdog.
*
* This function reads periodically the value of register 0x0001.
*
* We don't know the purpose. I assume that it seems to a software watchdog.
*/
int dev_stk11xx_watchdog_camera(struct usb_stk11xx *dev)
{
int value;
usb_stk11xx_read_registry(dev, 0x0001, &value);
if (value != 0x03) {
STK_DEBUG("Error : Register 0x0001 = %02X\n", value);
}
return value;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function switchs on the camera.
*
* In fact, we choose the alternate interface '5'.
*/
int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
{
int ret = -1;
struct usb_device *udev = dev->udev;
ret = usb_set_interface(udev, 0, 5);
if (ret < 0)
STK_ERROR("usb_set_interface failed !\n");
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function switchs off the camera.
*
* In fact, we choose the alternate interface '0'.
*/
int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
{
int ret = -1;
struct usb_device *udev = dev->udev;
ret = usb_set_interface(udev, 0, 0);
if (ret < 0)
STK_ERROR("usb_set_interface failed !\n");
return 0;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief Wake-up the camera.
*
* This function permits to wake-up the device.
*/
int dev_stk11xx_camera_asleep(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_camera_asleep(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_camera_asleep(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_camera_asleep(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_camera_asleep(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_camera_asleep(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_camera_asleep(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_camera_asleep(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_camera_asleep(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_camera_asleep(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function permits to modify the settings of the camera.
*
* This functions permits to modify the settings :
* - brightness
* - contrast
* - white balance
* - ...
*/
int dev_stk11xx_camera_settings(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_camera_settings(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_camera_settings(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_camera_settings(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_camera_settings(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_camera_settings(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_camera_settings(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_camera_settings(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_camera_settings(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_camera_settings(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function permits to modify the quality video of the camera.
*
* This functions permits to modify the settings :
* - brightness
* - contrast
* - white balance
* - ...
*/
int dev_stk11xx_set_camera_quality(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_set_camera_quality(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_set_camera_quality(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_set_camera_quality(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_set_camera_quality(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_set_camera_quality(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_set_camera_quality(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_set_camera_quality(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_set_camera_quality(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_set_camera_quality(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function permits to modify the fps of the camera.
*
* This functions permits to modify the frame rate per second of the camera.
* So the number of images per second.
*/
int dev_stk11xx_set_camera_fps(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_set_camera_fps(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_set_camera_fps(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_set_camera_fps(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_set_camera_fps(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_set_camera_fps(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_set_camera_fps(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_set_camera_fps(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_set_camera_fps(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_set_camera_fps(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function sets the device to start the stream.
*
* After the initialization of the device and the initialization of the video stream,
* this function permits to enable the stream.
*/
int dev_stk11xx_start_stream(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_start_stream(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_start_stream(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_start_stream(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_start_stream(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_start_stream(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_start_stream(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_start_stream(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_start_stream(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_start_stream(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief Reconfigure the camera before the stream.
*
* Before enabling the video stream, you have to reconfigure the device.
*/
int dev_stk11xx_reconf_camera(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_reconf_camera(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_reconf_camera(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_reconf_camera(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_reconf_camera(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_reconf_camera(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_reconf_camera(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_reconf_camera(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_reconf_camera(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_reconf_camera(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief This function sets the device to stop the stream.
*
* You use the function start_stream to enable the video stream. So you
* have to use the function stop_strem to disable the video stream.
*/
int dev_stk11xx_stop_stream(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
ret = dev_stk0408_stop_stream(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
ret = dev_stka311_stop_stream(dev);
break;
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
ret = dev_stka821_stop_stream(dev);
break;
case SYNTEK_STK_6A31:
ret = dev_stk6a31_stop_stream(dev);
break;
case SYNTEK_STK_6A33:
ret = dev_stk6a33_stop_stream(dev);
break;
case SYNTEK_STK_6A51:
ret = dev_stk6a51_stop_stream(dev);
break;
case SYNTEK_STK_6A54:
ret = dev_stk6a54_stop_stream(dev);
break;
case SYNTEK_STK_6D51:
ret = dev_stk6d51_stop_stream(dev);
break;
case SYNTEK_STK_0500:
ret = dev_stk0500_stop_stream(dev);
break;
default:
ret = -1;
}
return ret;
}
/**
* @param dev Device structure
*
* @returns 0 if all is OK
*
* @brief Decompress/convert a frame from the video stream
*
* @param dev Device structure
*/
int dev_stk11xx_decompress(struct usb_stk11xx *dev)
{
int ret;
switch (dev->webcam_model) {
case SYNTEK_STK_0408:
// Use a particular decompressor based uvyv
ret = dev_stk0408_decode(dev);
break;
case SYNTEK_STK_M811:
case SYNTEK_STK_A311:
case SYNTEK_STK_A821:
case SYNTEK_STK_AA11:
case SYNTEK_STK_6A31:
case SYNTEK_STK_6A33:
case SYNTEK_STK_6A51:
case SYNTEK_STK_6A54:
case SYNTEK_STK_6D51:
// Use a generec decompressor based bayer stream
ret = stk11xx_decompress(dev);
break;
default:
ret = -1;
}
return ret;
}