-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstk11xx-v4l.c
1922 lines (1506 loc) · 42.3 KB
/
stk11xx-v4l.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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file stk11xx-v4l.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/vmalloc.h>
#include <linux/mm.h>
#if defined(VIDIOCGCAP)
#include <linux/videodev.h>
#endif
#include <linux/usb.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include "stk11xx.h"
static struct v4l2_file_operations v4l_stk11xx_fops;
/**
* @var stk11xx_image_sizes
* List of all resolutions supported by the driver
*/
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES] = {
{ 80, 60 },
{ 128, 96 },
{ 160, 120 },
{ 213, 160 },
{ 320, 240 },
{ 640, 480 },
{ 720, 576 },
{ 800, 600 },
{ 1024, 768 },
{ 1280, 1024 }
};
/**
* @var stk11xx_controls
* List of all V4Lv2 controls supported by the driver
* default_value field will be overridden at runtime
*/
static struct v4l2_queryctrl stk11xx_controls[] = {
{
.id = V4L2_CID_BRIGHTNESS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Brightness",
.minimum = 0,
.maximum = 0xff00,
.step = 1,
.default_value = 0x7f00,
},
{
.id = V4L2_CID_WHITENESS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Whiteness",
.minimum = 0,
.maximum = 0xff00,
.step = 1,
.default_value = 0x7f00,
},
{
.id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Saturation",
.minimum = 0,
.maximum = 0xff00,
.step = 1,
.default_value = 0x7f00,
},
{
.id = V4L2_CID_CONTRAST,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Contrast",
.minimum = 0,
.maximum = 0xff00,
.step = 1,
.default_value = 0x7f00,
},
{
.id = V4L2_CID_HUE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Hue",
.minimum = 0,
.maximum = 0xff00,
.step = 1,
.default_value = 0x7f00,
},
{
.id = V4L2_CID_HFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "Flip Horizontally",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 0, // will be actually set later
},
{
.id = V4L2_CID_VFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "Flip Vertically",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 0, // will be actually set later
}
};
/**
* @param dev
* @param width Width of wished resolution
* @param height Height of wished resolution
*
* @returns 0 if all is OK
*
* @brief Select a video mode
*
* This function permits to check and select a video mode.
*/
int v4l_stk11xx_select_video_mode(struct usb_stk11xx *dev, int width, int height)
{
int i;
int find;
// Check width and height
// Notice : this test is usefull for the Kopete application !
// Driver can't build an image smaller than the minimal resolution !
if ((width < stk11xx_image_sizes[0].x)
|| (height < stk11xx_image_sizes[0].y)) {
width = stk11xx_image_sizes[0].x;
height = stk11xx_image_sizes[0].y;
}
// Driver can't build an image bigger than the maximal resolution !
switch (dev->webcam_type) {
case STK11XX_SXGA:
if ((width > stk11xx_image_sizes[STK11XX_1280x1024].x)
|| (height > stk11xx_image_sizes[STK11XX_1280x1024].y)) {
width = stk11xx_image_sizes[STK11XX_1280x1024].x;
height = stk11xx_image_sizes[STK11XX_1280x1024].y;
}
break;
case STK11XX_VGA:
if ((width > stk11xx_image_sizes[STK11XX_640x480].x)
|| (height > stk11xx_image_sizes[STK11XX_640x480].y)) {
width = stk11xx_image_sizes[STK11XX_640x480].x;
height = stk11xx_image_sizes[STK11XX_640x480].y;
}
break;
case STK11XX_PAL:
if (! (((width == 720) && (height==576))
|| ((width == 720) && (height==480))
|| ((width == 640) && (height==480)))) {
width = 640;
height = 480;
}
break;
default:
return -1;
}
// Seek the best resolution
switch (dev->webcam_type) {
case STK11XX_SXGA:
for (i=0, find=0; i<=STK11XX_1280x1024; i++) {
if (stk11xx_image_sizes[i].x <= width && stk11xx_image_sizes[i].y <= height)
find = i;
}
break;
case STK11XX_VGA:
for (i=0, find=0; i<=STK11XX_640x480; i++) {
if (stk11xx_image_sizes[i].x <= width && stk11xx_image_sizes[i].y <= height)
find = i;
}
break;
case STK11XX_PAL:
for (i=0, find=0; i<=STK11XX_720x576; i++) {
if (stk11xx_image_sizes[i].x <= width && stk11xx_image_sizes[i].y <= height)
find = i;
}
break;
default:
return -1;
}
// Save the new resolution
dev->resolution = find;
STK_DEBUG("Set mode %d [%dx%d]\n", dev->resolution,
stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y);
// Save the new size
dev->view.x = width;
dev->view.y = height;
// Calculate the frame size
if (dev->webcam_type == STK11XX_PAL) {
// Here, dev->resolution equals : 640x480 || 720x576
dev->image.x = stk11xx_image_sizes[dev->resolution].x;
dev->image.y = stk11xx_image_sizes[dev->resolution].y;
dev->frame_size = dev->image.x * dev->image.y;
}
else {
switch (dev->resolution) {
case STK11XX_80x60:
case STK11XX_128x96:
case STK11XX_160x120:
case STK11XX_213x160:
case STK11XX_320x240:
case STK11XX_640x480:
dev->image.x = stk11xx_image_sizes[STK11XX_640x480].x;
dev->image.y = stk11xx_image_sizes[STK11XX_640x480].y;
dev->frame_size = dev->image.x * dev->image.y;
break;
case STK11XX_720x576:
case STK11XX_800x600:
case STK11XX_1024x768:
case STK11XX_1280x1024:
dev->image.x = stk11xx_image_sizes[STK11XX_1280x1024].x;
dev->image.y = stk11xx_image_sizes[STK11XX_1280x1024].y;
dev->frame_size = dev->image.x * dev->image.y;
break;
}
}
// Calculate the image size
switch (dev->vsettings.palette) {
case STK11XX_PALETTE_RGB24:
case STK11XX_PALETTE_BGR24:
dev->view_size = 3 * dev->view.x * dev->view.y;
dev->image_size = 3 * dev->frame_size;
break;
case STK11XX_PALETTE_RGB32:
case STK11XX_PALETTE_BGR32:
dev->view_size = 3 * dev->view.x * dev->view.y;
dev->image_size = 4 * dev->frame_size;
break;
case STK11XX_PALETTE_UYVY:
case STK11XX_PALETTE_YUYV:
dev->view_size = 2 * dev->view.x * dev->view.y;
dev->image_size = 2 * dev->frame_size;
break;
}
return 0;
}
/**
* @param fp File pointer
*
* @returns 0 if all is OK
*
* @brief Open the video device
*
* This function permits to open a video device (/dev/videoX)
*/
static int v4l_stk11xx_open(struct file *fp)
{
int err;
struct usb_stk11xx *dev;
struct video_device *vdev;
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
if (dev == NULL) {
STK_ERROR("Device not initialized !!!\n");
BUG();
}
mutex_lock(&dev->modlock);
if (dev->vopen) {
STK_DEBUG("Device is busy, someone is using the device\n");
mutex_unlock(&dev->modlock);
return -EBUSY;
}
// Allocate memory
err = stk11xx_allocate_buffers(dev);
if (err < 0) {
STK_ERROR("Failed to allocate buffer memory !\n");
mutex_unlock(&dev->modlock);
return err;
}
// Reset buffers and parameters
stk11xx_reset_buffers(dev);
// Settings
dev->vsync = 0;
dev->v1st_cap = 5;
dev->error_status = 0;
dev->visoc_errors = 0;
dev->vframes_error = 0;
dev->vframes_dumped = 0;
dev->vsettings.hue = 0xffff;
dev->vsettings.whiteness = 0xffff;
dev->vsettings.depth = 24;
dev->vsettings.palette = STK11XX_PALETTE_BGR24;
// Select the resolution by default
v4l_stk11xx_select_video_mode(dev, 640, 480);
// Initialize the device
dev_stk11xx_init_camera(dev);
dev_stk11xx_camera_on(dev);
dev_stk11xx_reconf_camera(dev);
// Init Isoc and URB
err = usb_stk11xx_isoc_init(dev);
if (err) {
STK_ERROR("Failed to init ISOC stuff !\n");
usb_stk11xx_isoc_cleanup(dev);
stk11xx_free_buffers(dev);
mutex_unlock(&dev->modlock);
return err;
}
// Start the video stream
dev_stk11xx_start_stream(dev);
// Video settings
dev_stk11xx_camera_settings(dev);
// Register interface on power management
usb_autopm_get_interface(dev->interface);
dev->vopen++;
fp->private_data = vdev;
mutex_unlock(&dev->modlock);
return 0;
}
/**
* @param fp File pointer
*
* @returns 0 if all is OK
*
* @brief Release an opened file.
*
* This function permits to release an opened file with the 'open' method.
*/
static int v4l_stk11xx_release(struct file *fp)
{
struct usb_stk11xx *dev;
struct video_device *vdev;
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
if (dev->vopen == 0)
STK_ERROR("v4l_release called on closed device\n");
// Stop the video stream
dev_stk11xx_stop_stream(dev);
// ISOC and URB cleanup
usb_stk11xx_isoc_cleanup(dev);
// Free memory
stk11xx_free_buffers(dev);
// Switch off the camera
dev_stk11xx_camera_off(dev);
dev_stk11xx_camera_asleep(dev);
// Unregister interface on power management
usb_autopm_put_interface(dev->interface);
dev->vopen--;
return 0;
}
/**
* @param fp File pointer
*
* @retval buf Buffer in user space
* @retval count
* @retval f_pos
*
* @returns Count value
*
* @brief Read the video device
*
* This function is called by the application is reading the video device.
*/
static ssize_t v4l_stk11xx_read(struct file *fp, char __user *buf,
size_t count, loff_t *f_pos)
{
int noblock = fp->f_flags & O_NONBLOCK;
struct usb_stk11xx *dev;
struct video_device *vdev;
int bytes_to_read;
void *image_buffer_addr;
DECLARE_WAITQUEUE(wait, current);
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
STK_STREAM("Read vdev=0x%p, buf=0x%p, count=%zd\n", vdev, buf, count);
if (dev == NULL)
return -EFAULT;
if (vdev == NULL)
return -EFAULT;
mutex_lock(&dev->modlock);
if (dev->image_read_pos == 0) {
add_wait_queue(&dev->wait_frame, &wait);
while (dev->full_frames == NULL) {
if (dev->error_status) {
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
mutex_unlock(&dev->modlock);
return -dev->error_status ;
}
if (noblock) {
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
mutex_unlock(&dev->modlock);
return -EWOULDBLOCK;
}
if (signal_pending(current)) {
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
mutex_unlock(&dev->modlock);
return -ERESTARTSYS;
}
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
if (stk11xx_handle_frame(dev)) {
mutex_unlock(&dev->modlock);
return -EFAULT;
}
}
bytes_to_read = dev->view_size;
if (count + dev->image_read_pos > bytes_to_read)
count = bytes_to_read - dev->image_read_pos;
image_buffer_addr = dev->image_data;
image_buffer_addr += dev->images[dev->fill_image].offset;
image_buffer_addr += dev->image_read_pos;
if (copy_to_user(buf, image_buffer_addr, count)) {
mutex_unlock(&dev->modlock);
return -EFAULT;
}
dev->image_read_pos += count;
if (dev->image_read_pos >= bytes_to_read) {
dev->image_read_pos = 0;
stk11xx_next_image(dev);
}
mutex_unlock(&dev->modlock);
return count;
}
/**
* @param fp File pointer
* @param wait
*
* @returns 0 if all is OK
*
* @brief Polling function
*/
static unsigned int v4l_stk11xx_poll(struct file *fp, poll_table *wait)
{
struct usb_stk11xx *dev;
struct video_device *vdev;
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
STK_STREAM("Poll\n");
if (vdev == NULL)
return -EFAULT;
if (dev == NULL)
return -EFAULT;
poll_wait(fp, &dev->wait_frame, wait);
if (dev->error_status)
return POLLERR;
if (dev->full_frames != NULL)
return (POLLIN | POLLRDNORM);
return 0;
}
/**
* @param fp File pointer
* @param vma VMA structure
*
* @returns 0 if all is OK
*
* @brief Memory map
*
* This function permits to map a memory space.
*/
static int v4l_stk11xx_mmap(struct file *fp, struct vm_area_struct *vma)
{
unsigned int i;
unsigned long size;
unsigned long start;
unsigned long pos;
unsigned long page;
struct usb_stk11xx *dev;
struct video_device *vdev;
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
STK_STREAM("mmap\n");
start = vma->vm_start;
size = vma->vm_end - vma->vm_start;
// Find the buffer for this mapping...
for (i=0; i<dev->nbuffers; i++) {
pos = dev->images[i].offset;
if ((pos >> PAGE_SHIFT) == vma->vm_pgoff)
break;
}
// If no buffer found !
if (i == STK11XX_MAX_IMAGES) {
STK_ERROR("mmap no buffer found !\n");
return -EINVAL;
}
if (i == 0) {
unsigned long total_size;
total_size = dev->nbuffers * dev->len_per_image;
if (size != dev->len_per_image && size != total_size) {
STK_ERROR("Wrong size (%lu) needed to be len_per_image=%d or total_size=%lu\n",
size, dev->len_per_image, total_size);
return -EINVAL;
}
}
else if (size > dev->len_per_image)
return -EINVAL;
vma->vm_flags |= VM_IO;
pos = (unsigned long) dev->image_data;
while (size > 0) {
page = vmalloc_to_pfn((void *) pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
return -EAGAIN;
start += PAGE_SIZE;
pos += PAGE_SIZE;
if (size > PAGE_SIZE)
size -= PAGE_SIZE;
else
size = 0;
}
return 0;
}
/**
* @param fp File pointer
* @param cmd Command
* @param arg Arguments of the command
*
* @returns 0 if all is OK
*
* @brief Manage IOCTL
*
* This function permits to manage all the IOCTL from the application.
*/
static long v4l_stk11xx_do_ioctl(struct file *fp,
unsigned int cmd, void __user *arg)
{
struct usb_stk11xx *dev;
struct video_device *vdev;
DECLARE_WAITQUEUE(wait, current);
vdev = video_devdata(fp);
dev = video_get_drvdata(video_devdata(fp));
#if (CONFIG_STK11XX_DEBUG == 1)
v4l_printk_ioctl(cmd);
#endif
switch (cmd) {
#ifdef VIDIOCGCAP
// Video 4 Linux v1
case VIDIOCGCAP:
{
struct video_capability *cap = arg;
STK_DEBUG("VIDIOCGCAP\n");
memset(cap, 0, sizeof(*cap));
strlcpy(cap->name, "stk11xx", sizeof(cap->name));
cap->type = VID_TYPE_CAPTURE;
cap->channels = 1;
cap->audios = 0;
switch (dev->webcam_type) {
case STK11XX_SXGA:
cap->minwidth = stk11xx_image_sizes[STK11XX_80x60].x;
cap->minheight = stk11xx_image_sizes[STK11XX_80x60].y;
cap->maxwidth = stk11xx_image_sizes[STK11XX_1280x1024].x;
cap->maxheight = stk11xx_image_sizes[STK11XX_1280x1024].y;
break;
case STK11XX_PAL:
cap->minwidth = stk11xx_image_sizes[STK11XX_640x480].x;
cap->minheight = stk11xx_image_sizes[STK11XX_640x480].y;
cap->maxwidth = stk11xx_image_sizes[STK11XX_720x576].x;
cap->maxheight = stk11xx_image_sizes[STK11XX_720x576].y;
break;
case STK11XX_VGA:
cap->minwidth = stk11xx_image_sizes[STK11XX_80x60].x;
cap->minheight = stk11xx_image_sizes[STK11XX_80x60].y;
cap->maxwidth = stk11xx_image_sizes[STK11XX_640x480].x;
cap->maxheight = stk11xx_image_sizes[STK11XX_640x480].y;
break;
}
}
break;
case VIDIOCGCHAN:
{
struct video_channel *v = arg;
STK_DEBUG("VIDIOCGCHAN\n");
if (v->channel != 0)
return -EINVAL;
v->flags = 0;
v->tuners = 0;
v->type = VIDEO_TYPE_CAMERA;
strcpy(v->name, "Webcam");
}
break;
case VIDIOCSCHAN:
{
struct video_channel *v = arg;
STK_DEBUG("VIDIOCSCHAN\n");
if (v->channel != 0)
return -EINVAL;
}
break;
case VIDIOCGPICT:
{
struct video_picture *p = arg;
STK_DEBUG("VIDIOCGPICT\n");
p->brightness = dev->vsettings.brightness;
p->contrast = dev->vsettings.contrast;
p->whiteness = dev->vsettings.whiteness;
p->colour = dev->vsettings.colour;
p->depth = dev->vsettings.depth;
p->palette = dev->vsettings.palette;
p->hue = dev->vsettings.hue;
switch (dev->vsettings.palette) {
case STK11XX_PALETTE_BGR24:
p->palette = VIDEO_PALETTE_RGB24;
break;
case STK11XX_PALETTE_BGR32:
p->palette = VIDEO_PALETTE_RGB32;
break;
case STK11XX_PALETTE_UYVY:
p->palette = VIDEO_PALETTE_UYVY;
break;
case STK11XX_PALETTE_YUYV:
p->palette = VIDEO_PALETTE_YUYV;
break;
}
}
break;
case VIDIOCSPICT:
{
struct video_picture *p = arg;
STK_DEBUG("VIDIOCSPICT\n");
dev->vsettings.brightness = p->brightness;
dev->vsettings.contrast = p->contrast;
dev->vsettings.whiteness = p->whiteness;
dev->vsettings.colour = p->colour;
dev->vsettings.hue = p->hue;
if (p->palette && p->palette != dev->vsettings.palette) {
switch (p->palette) {
case VIDEO_PALETTE_RGB24:
dev->vsettings.depth = 24;
dev->vsettings.palette = STK11XX_PALETTE_BGR24;
break;
case VIDEO_PALETTE_RGB32:
dev->vsettings.depth = 32;
dev->vsettings.palette = STK11XX_PALETTE_BGR32;
break;
case VIDEO_PALETTE_UYVY:
dev->vsettings.depth = 16;
dev->vsettings.palette = STK11XX_PALETTE_UYVY;
break;
case VIDEO_PALETTE_YUYV:
dev->vsettings.depth = 16;
dev->vsettings.palette = STK11XX_PALETTE_YUYV;
break;
default:
return -EINVAL;
}
}
dev_stk11xx_camera_settings(dev);
STK_DEBUG("VIDIOCSPICT done\n");
}
break;
case VIDIOCGWIN:
{
struct video_window *vw = arg;
STK_DEBUG("VIDIOCGWIN\n");
vw->x = 0;
vw->y = 0;
vw->width = dev->view.x;
vw->height = dev->view.y;
vw->chromakey = 0;
}
break;
case VIDIOCSWIN:
{
struct video_window *vw = arg;
STK_DEBUG("VIDIOCSWIN\n");
STK_DEBUG("Set x=%d, y=%d\n", vw->x, vw->y);
STK_DEBUG("Set width=%d, height=%d\n", vw->width, vw->height);
STK_DEBUG("Flags = %X\n", vw->flags);
// Stop the video stream
dev_stk11xx_stop_stream(dev);
// ISOC and URB cleanup
usb_stk11xx_isoc_cleanup(dev);
// Switch off the camera
dev_stk11xx_camera_off(dev);
dev_stk11xx_camera_asleep(dev);
// Select the new video mode
if (v4l_stk11xx_select_video_mode(dev, vw->width, vw->height)) {
STK_ERROR("Select video mode failed !\n");
return -EAGAIN;
}
// Clear the buffers
stk11xx_clear_buffers(dev);
// Initialize the device
dev_stk11xx_init_camera(dev);
dev_stk11xx_camera_on(dev);
dev_stk11xx_reconf_camera(dev);
// ISOC and URB init
usb_stk11xx_isoc_init(dev);
// Re-start the stream
dev_stk11xx_start_stream(dev);
// Video settings
dev_stk11xx_camera_settings(dev);
}
break;
case VIDIOCGFBUF:
{
struct video_buffer *vb = arg;
STK_DEBUG("VIDIOCGFBUF\n");
memset(vb, 0, sizeof(*vb));
}
break;
case VIDIOCGMBUF:
{
int i;
struct video_mbuf *vm = arg;
STK_DEBUG("VIDIOCGMBUF\n");
memset(vm, 0, sizeof(*vm));
vm->size = dev->nbuffers * dev->len_per_image;
vm->frames = dev->nbuffers;
for (i=0; i<dev->nbuffers; i++)
vm->offsets[i] = i * dev->len_per_image;
}
break;
case VIDIOCMCAPTURE:
{
struct video_mmap *vm = arg;
STK_DEBUG("VIDIOCMCAPTURE format=%d\n", vm->format);
if (vm->frame < 0 || vm->frame >= dev->nbuffers)
return -EINVAL;
if (vm->format) {
switch (vm->format) {
case VIDEO_PALETTE_RGB32:
break;
case VIDEO_PALETTE_RGB24:
break;
case VIDEO_PALETTE_UYVY:
break;
case VIDEO_PALETTE_YUYV:
break;
default:
return -EINVAL;
}
}
if ((vm->width != dev->view.x) || (vm->height != dev->view.y))
return -EAGAIN;
if (dev->image_used[vm->frame])
return -EBUSY;
dev->image_used[vm->frame] = 1;
STK_DEBUG("VIDIOCMCAPTURE done\n");
}
break;
case VIDIOCSYNC:
{
int ret;
int *mbuf = arg;
STK_DEBUG("VIDIOCSYNC\n");
if (*mbuf < 0 || *mbuf >= dev->nbuffers)
return -EINVAL;
if (dev->image_used[*mbuf] == 0)
return -EINVAL;
add_wait_queue(&dev->wait_frame, &wait);
while (dev->full_frames == NULL) {
if (dev->error_status) {
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
return -dev->error_status;
}
if (signal_pending(current)) {
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
return -ERESTARTSYS;
}
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
remove_wait_queue(&dev->wait_frame, &wait);
set_current_state(TASK_RUNNING);
STK_DEBUG("VIDIOCSYNC: frame ready\n");
dev->fill_image = *mbuf;
ret = stk11xx_handle_frame(dev);