Syntek USB Video Camera
stk11xx-usb.c
Go to the documentation of this file.
1
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/kernel.h>
37#include <linux/version.h>
38#include <linux/errno.h>
39#include <linux/slab.h>
40#include <linux/kref.h>
41#include <linux/mm.h>
42
43#include <linux/usb.h>
44#include <media/v4l2-common.h>
45#include <media/v4l2-ioctl.h>
46
47#include "stk11xx.h"
48
49
54static int default_fps = -1;
55
60static int default_hflip = -1;
61
66static int default_vflip = -1;
67
72static int default_brightness = -1;
73
78static int default_whiteness = -1;
79
84static int default_contrast = -1;
85
90static int default_colour = -1;
91
96static int default_norm = -1;
97
98
118
119
134{
135 int i, j;
136 int ret = 0;
137 struct urb *urb;
138 struct usb_device *udev;
139
140 if (dev == NULL)
141 return -EFAULT;
142
143 if (dev->isoc_init_ok)
144 return 0;
145
146 udev = dev->udev;
147
148 STK_DEBUG("usb_stk11xx_isoc_init()\n");
149
150 // Allocate URB structure
151 for (i=0; i<MAX_ISO_BUFS; i++) {
152 urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
153
154 if (urb == NULL) {
155 STK_ERROR("Failed to allocate URB %d\n", i);
156 ret = -ENOMEM;
157 break;
158 }
159
160 dev->isobuf[i].urb = urb;
161 }
162
163 if (ret) {
164 while (i >= 0) {
165 if (dev->isobuf[i].urb != NULL)
166 usb_free_urb(dev->isobuf[i].urb);
167
168 dev->isobuf[i].urb = NULL;
169 i--;
170 }
171
172 return ret;
173 }
174
175 // Init URB structure
176 for (i=0; i<MAX_ISO_BUFS; i++) {
177 urb = dev->isobuf[i].urb;
178
179 urb->interval = 1;
180 urb->dev = udev;
181 urb->pipe = usb_rcvisocpipe(udev, dev->isoc_in_endpointAddr);
182 urb->transfer_flags = URB_ISO_ASAP;
183 urb->transfer_buffer = dev->isobuf[i].data;
184 urb->transfer_buffer_length = ISO_BUFFER_SIZE;
185 urb->complete = usb_stk11xx_isoc_handler;
186 urb->context = dev;
187 urb->start_frame = 0;
188 urb->number_of_packets = ISO_FRAMES_PER_DESC;
189
190 for (j=0; j<ISO_FRAMES_PER_DESC; j++) {
191 urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE;
192 urb->iso_frame_desc[j].length = ISO_MAX_FRAME_SIZE; //dev->isoc_in_size;
193 }
194 }
195
196 STK_DEBUG("dev->isoc_in_size = %X\n", dev->isoc_in_size);
197 STK_DEBUG("dev->isoc_in_endpointAddr = %X\n", dev->isoc_in_endpointAddr);
198
199 // Link
200 for (i=0; i<MAX_ISO_BUFS; i++) {
201 ret = usb_submit_urb(dev->isobuf[i].urb, GFP_KERNEL);
202
203 if (ret)
204 STK_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
205 else
206 STK_DEBUG("URB 0x%p submitted.\n", dev->isobuf[i].urb);
207
208 switch (ret) {
209 case -ENOMEM:
210 STK_ERROR("ENOMEM\n");
211 break;
212 case -ENODEV:
213 STK_ERROR("ENODEV\n");
214 break;
215 case -ENXIO:
216 STK_ERROR("ENXIO\n");
217 break;
218 case -EINVAL:
219 STK_ERROR("EINVAL\n");
220 break;
221 case -EAGAIN:
222 STK_ERROR("EAGAIN\n");
223 break;
224 case -EFBIG:
225 STK_ERROR("EFBIG\n");
226 break;
227 case -EPIPE:
228 STK_ERROR("EPIPE\n");
229 break;
230 case -EMSGSIZE:
231 STK_ERROR("EMSGSIZE\n");
232 break;
233 }
234 }
235
236 // All is done
237 dev->isoc_init_ok = 1;
238
239 return 0;
240}
241
242
252void usb_stk11xx_isoc_handler(struct urb *urb)
253{
254 int i;
255 int ret;
256 int skip;
257
258 int awake = 0;
259 int framestatus;
260 int framelen;
261
262 unsigned char *fill = NULL;
263 unsigned char *iso_buf = NULL;
264
265 struct usb_stk11xx *dev;
266 struct stk11xx_frame_buf *framebuf;
267
268 STK_STREAM("Isoc handler\n");
269
270 dev = (struct usb_stk11xx *) urb->context;
271
272 if (dev == NULL) {
273 STK_ERROR("isoc_handler called with NULL device !\n");
274 return;
275 }
276
277 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
278 STK_DEBUG("URB unlinked synchronuously !\n");
279 return;
280 }
281
282 if (urb->status != -EINPROGRESS && urb->status != 0) {
283 const char *errmsg;
284
285 errmsg = "Unknown";
286
287 switch(urb->status) {
288 case -ENOSR:
289 errmsg = "Buffer error (overrun)";
290 break;
291
292 case -EPIPE:
293 errmsg = "Stalled (device not responding)";
294 break;
295
296 case -EOVERFLOW:
297 errmsg = "Babble (bad cable?)";
298 break;
299
300 case -EPROTO:
301 errmsg = "Bit-stuff error (bad cable?)";
302 break;
303
304 case -EILSEQ:
305 errmsg = "CRC/Timeout (could be anything)";
306 break;
307
308 case -ETIMEDOUT:
309 errmsg = "NAK (device does not respond)";
310 break;
311 }
312
313 STK_ERROR("isoc_handler() called with status %d [%s].\n", urb->status, errmsg);
314
315 dev->visoc_errors++;
316
317 wake_up_interruptible(&dev->wait_frame);
318
319 urb->dev = dev->udev;
320 ret = usb_submit_urb(urb, GFP_ATOMIC);
321
322 if (ret != 0) {
323 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret);
324 }
325
326 return;
327 }
328
329 framebuf = dev->fill_frame;
330
331 if (framebuf == NULL) {
332 STK_ERROR("isoc_handler without valid fill frame !\n");
333
334 wake_up_interruptible(&dev->wait_frame);
335
336 urb->dev = dev->udev;
337 ret = usb_submit_urb(urb, GFP_ATOMIC);
338
339 if (ret != 0) {
340 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret);
341 }
342
343 return;
344 }
345 else {
346 fill = framebuf->data + framebuf->filled;
347 }
348
349 // Reset ISOC error counter
350 dev->visoc_errors = 0;
351
352 // Compact data
353 for (i=0; i<urb->number_of_packets; i++) {
354 framestatus = urb->iso_frame_desc[i].status;
355 framelen = urb->iso_frame_desc[i].actual_length;
356 iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
357
358 if (framestatus == 0) {
359 skip = 4;
360
361 if (framelen > 4) {
362 // we found something informational from there
363 // the isoc frames have to type of headers
364 // type1: 00 xx 00 00 or 20 xx 00 00
365 // type2: 80 xx 00 00 00 00 00 00 or a0 xx 00 00 00 00 00 00
366 // xx is a sequencer which has never been seen over 0x3f
367 //
368 // imho data written down looks like bayer, i see similarities after
369 // every 640 bytes
370 if (*iso_buf & 0x80) {
371 skip = 8;
372 }
373
374 // Determine if odd or even frame, and set a flag
375 if (framelen == 8) {
376 if (*iso_buf & 0x40)
377 framebuf->odd = true;
378 else
379 framebuf->odd = false;
380 }
381
382 // Our buffer is full !!!
383 if (framelen - skip + framebuf->filled > dev->frame_size) {
384 STK_ERROR("Frame buffer overflow %d %d %d!\n",
385 framelen, framelen-skip+framebuf->filled, dev->frame_size);
386 framebuf->errors++;
387 }
388 // All is OK
389 else {
390 memcpy(fill, iso_buf + skip, framelen - skip);
391 fill += framelen - skip;
392 }
393
394 // New size of our buffer
395 framebuf->filled += framelen - skip;
396 }
397
398 STK_STREAM("URB : Length = %d - Skip = %d - Buffer size = %d\n",
399 framelen, skip, framebuf->filled);
400
401 // Data is always follow by a frame with a length '4'
402 if (framelen == 4) {
403 if (framebuf->filled > 0) {
404 // Our buffer has enough data ?
405 if (framebuf->filled < dev->frame_size)
406 framebuf->errors++;
407
408 // If there are errors, we skip a frame...
409 if (framebuf->errors == 0) {
410 if (stk11xx_next_frame(dev))
411 dev->vframes_dumped++;
412 }
413 else
414 dev->vframes_error++;
415
416 awake = 1;
417 framebuf = dev->fill_frame;
418 framebuf->filled = 0;
419 framebuf->errors = 0;
420 fill = framebuf->data;
421 }
422 }
423 }
424 else {
425 STK_ERROR("Iso frame %d of USB has error %d\n", i, framestatus);
426 }
427 }
428
429 if (awake == 1)
430 wake_up_interruptible(&dev->wait_frame);
431
432 urb->dev = dev->udev;
433
434 ret = usb_submit_urb(urb, GFP_ATOMIC);
435
436 if (ret != 0) {
437 STK_ERROR("Error (%d) re-submitting urb in stk11xx_isoc_handler.\n", ret);
438 }
439}
440
441
450{
451 int i;
452
453 STK_DEBUG("Isoc cleanup\n");
454
455 if (dev == NULL)
456 return;
457
458 if (dev->isoc_init_ok == 0)
459 return;
460
461 // Unlinking ISOC buffers
462 for (i=0; i<MAX_ISO_BUFS; i++) {
463 struct urb *urb;
464
465 urb = dev->isobuf[i].urb;
466
467 if (urb != 0) {
468 if (dev->isoc_init_ok)
469 usb_kill_urb(urb);
470
471 usb_free_urb(urb);
472 dev->isobuf[i].urb = NULL;
473 }
474 }
475
476 // All is done
477 dev->isoc_init_ok = 0;
478}
479
480
481
492int usb_stk11xx_set_feature(struct usb_stk11xx *dev, int index)
493{
494 int result;
495 struct usb_device *udev = dev->udev;
496
497 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
498 USB_REQ_SET_FEATURE,
499 USB_TYPE_STANDARD | USB_DIR_OUT | USB_RECIP_DEVICE,
500 USB_DEVICE_REMOTE_WAKEUP,
501 index,
502 NULL,
503 0,
504 500);
505
506 if (result < 0)
507 STK_ERROR("SET FEATURE fail !\n");
508 else
509 STK_DEBUG("SET FEATURE\n");
510
511 return result;
512}
513
514
525{
526 int result;
527 struct usb_device *udev = dev->udev;
528
529 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
530 USB_REQ_SET_CONFIGURATION,
531 USB_TYPE_STANDARD | USB_DIR_OUT | USB_RECIP_DEVICE,
532 0,
533 udev->config[0].desc.bConfigurationValue,
534 NULL,
535 0,
536 500);
537
538 if (result < 0)
539 STK_ERROR("SET CONFIGURATION fail !\n");
540 else
541 STK_DEBUG("SET CONFIGURATION %d\n", udev->config[0].desc.bConfigurationValue);
542
543 return result;
544}
545
546
558int usb_stk11xx_write_registry(struct usb_stk11xx *dev, __u16 index, __u16 value)
559{
560 int result;
561 struct usb_device *udev = dev->udev;
562
563 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
564 0x01,
565 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
566 value,
567 index,
568 NULL,
569 0,
570 500);
571
572 if (result < 0)
573 STK_ERROR("Write registry fails %02X = %02X", index, value);
574
575 return result;
576}
577
578
590int usb_stk11xx_read_registry(struct usb_stk11xx *dev, __u16 index, int *value)
591{
592 int result;
593
594 struct usb_device *udev = dev->udev;
595
596 *value = 0;
597
598 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
599 0x00,
600 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
601 0x00,
602 index,
603 (__u8 *) value,
604 sizeof(__u8),
605 500);
606
607 if (result < 0)
608 STK_ERROR("Read registry fails %02X", index);
609
610 return result;
611}
612
613
625{
626 switch (dev->webcam_model) {
627 case SYNTEK_STK_0408:
628 dev->vsettings.fps = (default_fps == -1) ? 25 : default_fps;
629 dev->vsettings.vflip = (default_vflip == -1) ? 0 : default_vflip;
630 dev->vsettings.hflip = (default_hflip == -1) ? 0 : default_hflip;
631
635 dev->vsettings.colour = (default_colour == -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour;
636 dev->vsettings.norm = (default_norm == -1) ? 0 : default_norm;
637 dev->vsettings.input = 0;
638 break;
639
640 case SYNTEK_STK_M811:
641 case SYNTEK_STK_A311:
642 dev->vsettings.fps = (default_fps == -1) ? 25 : default_fps;
643 dev->vsettings.vflip = (default_vflip == -1) ? 1 : default_vflip;
644 dev->vsettings.hflip = (default_hflip == -1) ? 1 : default_hflip;
645
649 dev->vsettings.colour = (default_colour == -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour;
650 break;
651
652 case SYNTEK_STK_A821:
653 case SYNTEK_STK_AA11:
654 dev->vsettings.fps = (default_fps == -1) ? 25 : default_fps;
655 dev->vsettings.vflip = (default_vflip == -1) ? 0 : default_vflip;
656 dev->vsettings.hflip = (default_hflip == -1) ? 0 : default_hflip;
657
661 dev->vsettings.colour = (default_colour == -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour;
662 break;
663
664 case SYNTEK_STK_6A31:
665 case SYNTEK_STK_6A33:
666 case SYNTEK_STK_0500:
667 dev->vsettings.fps = (default_fps == -1) ? 25 : default_fps;
668 dev->vsettings.vflip = (default_vflip == -1) ? 0 : default_vflip;
669 dev->vsettings.hflip = (default_hflip == -1) ? 0 : default_hflip;
670
674 dev->vsettings.colour = (default_colour == -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour;
675 break;
676
677 case SYNTEK_STK_6A51:
678 case SYNTEK_STK_6D51:
679 case SYNTEK_STK_6A54:
680 dev->vsettings.fps = (default_fps == -1) ? 25 : default_fps;
681 dev->vsettings.vflip = (default_vflip == -1) ? 0 : default_vflip;
682 dev->vsettings.hflip = (default_hflip == -1) ? 0 : default_hflip;
683
687 dev->vsettings.colour = (default_colour == -1) ? STK11XX_PERCENT(50, 0xFFFF) : default_colour;
688 break;
689
690 default:
691 return -1;
692 }
693
694 dev->vsettings.default_brightness = dev->vsettings.brightness;
695 dev->vsettings.default_whiteness = dev->vsettings.whiteness;
696 dev->vsettings.default_contrast = dev->vsettings.contrast;
697 dev->vsettings.default_colour = dev->vsettings.colour;
698 dev->vsettings.default_hflip = dev->vsettings.hflip;
699 dev->vsettings.default_vflip = dev->vsettings.vflip;
700
701 return 0;
702}
703
704
716static int usb_stk11xx_probe(struct usb_interface *interface, const struct usb_device_id *id)
717{
718 int i;
719 int err;
720 size_t buffer_size;
721
722 int vendor_id;
723 int product_id;
724 int bNumInterfaces;
725 int webcam_model;
726 int webcam_type;
727
728 struct usb_stk11xx *dev = NULL;
729 struct usb_device *udev = interface_to_usbdev(interface);
730 struct usb_host_interface *iface_desc;
731 struct usb_endpoint_descriptor *endpoint;
732
733
734 // Get USB VendorID and ProductID
735 vendor_id = le16_to_cpu(udev->descriptor.idVendor);
736 product_id = le16_to_cpu(udev->descriptor.idProduct);
737
738 // Check if we can handle this device
739 STK_DEBUG("Probe function called with VendorID=%04X, ProductID=%04X and InterfaceNumber=%d\n",
740 vendor_id, product_id, interface->cur_altsetting->desc.bInterfaceNumber);
741
742 // The interface are probed one by one.
743 // We are interested in the video interface (always the interface '0')
744 // The interfaces '1' or '2' (if presents) are the audio control.
745 if (interface->cur_altsetting->desc.bInterfaceNumber > 0)
746 return -ENODEV;
747
748 // Detect device
749 if (vendor_id == USB_SYNTEK1_VENDOR_ID) {
750 switch (product_id) {
752 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
753 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0xA311.\n");
754 webcam_model = SYNTEK_STK_A311;
755 webcam_type = STK11XX_SXGA;
756 break;
757
759 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
760 STK_INFO("Syntek AVStream USB2.0 VGA WebCam - Product ID 0xA821.\n");
761 webcam_model = SYNTEK_STK_A821;
762 webcam_type = STK11XX_VGA;
763 break;
764
766 STK_INFO("Syntek AVStream USB2.0 VGA WebCam - Product ID 0xAA11.\n");
767 STK_INFO("Using code for Product ID AxA821\n");
768 webcam_model = SYNTEK_STK_AA11;
769 webcam_type = STK11XX_VGA;
770 break;
771
773 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
774 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A31.\n");
775 webcam_model = SYNTEK_STK_6A31;
776 webcam_type = STK11XX_VGA;
777 break;
778
780 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
781 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A33.\n");
782 webcam_model = SYNTEK_STK_6A33;
783 webcam_type = STK11XX_VGA;
784 break;
785
787 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
788 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A51.\n");
789 webcam_model = SYNTEK_STK_6A51;
790 webcam_type = STK11XX_VGA;
791 break;
792
794 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
795 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6A54.\n");
796 webcam_model = SYNTEK_STK_6A54;
797 webcam_type = STK11XX_VGA;
798 break;
799
801 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
802 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x6D51.\n");
803 webcam_model = SYNTEK_STK_6D51;
804 webcam_type = STK11XX_VGA;
805 break;
806
807 default:
808 STK_ERROR("usb_stk11xx_probe failed ! Camera product 0x%04X is not supported.\n",
809 le16_to_cpu(udev->descriptor.idProduct));
810 return -ENODEV;
811 }
812 }
813 else if (vendor_id == USB_SYNTEK2_VENDOR_ID) {
814 switch (product_id) {
816 STK_INFO("Syntek USB2.0 - STK-1160 based device found.\n");
817 STK_INFO("Syntek AVStream USB2.0 Video Capture - Product ID 0x0408.\n");
818 webcam_model = SYNTEK_STK_0408;
819 webcam_type = STK11XX_PAL;
820 break;
821
823 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
824 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x0500.\n");
825 webcam_model = SYNTEK_STK_0500;
826 webcam_type = STK11XX_VGA;
827 break;
828
830 STK_INFO("Syntek USB2.0 - STK-1135 based webcam found.\n");
831 STK_INFO("Syntek AVStream USB2.0 1.3M WebCam - Product ID 0x0501.\n");
832 webcam_model = SYNTEK_STK_M811;
833 webcam_type = STK11XX_SXGA;
834 break;
835
836 default:
837 STK_ERROR("usb_stk11xx_probe failed ! Camera product 0x%04X is not supported.\n",
838 le16_to_cpu(udev->descriptor.idProduct));
839 return -ENODEV;
840 }
841 }
842 else
843 return -ENODEV;
844
845 // Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device
846 dev = kzalloc(sizeof(struct usb_stk11xx), GFP_KERNEL);
847
848 if (dev == NULL) {
849 STK_ERROR("Out of memory !\n");
850 return -ENOMEM;
851 }
852
853 // Init mutexes, spinlock, etc.
854
855#ifndef init_MUTEX
856 sema_init(&dev->mutex,1);
857#else
858 init_MUTEX(&dev->mutex);
859#endif
860 mutex_init(&dev->modlock);
861 spin_lock_init(&dev->spinlock);
862 init_waitqueue_head(&dev->wait_frame);
863
864 // Save pointers
865 dev->webcam_model = webcam_model;
866 dev->webcam_type = webcam_type;
867 dev->udev = udev;
868 dev->interface = interface;
869
870 // Read the product release
871 dev->release = le16_to_cpu(udev->descriptor.bcdDevice);
872 STK_INFO("Release: %04x\n", dev->release);
873
874 // How many interfaces (1 or 3) ?
875 bNumInterfaces = udev->config->desc.bNumInterfaces;
876 STK_INFO("Number of interfaces : %d\n", bNumInterfaces);
877
878
879 // Constructor
880 // 2 : enough for webcam
881 // 3 : for easycap... it's usefull ?
882 dev->nbuffers = 2;
883// dev->nbuffers = 3;
884 dev->len_per_image = PAGE_ALIGN(STK11XX_FRAME_SIZE);
885
886
887 // Switch on the camera (to detect size of buffers)
889
890
891 // Set up the endpoint information
892 // use only the first int-in and isoc-in endpoints
893 // for the current alternate setting
894 iface_desc = interface->cur_altsetting;
895
896 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
897 endpoint = &iface_desc->endpoint[i].desc;
898
899 if (!dev->int_in_endpointAddr
900 && ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
901 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
902 // we found an interrupt in endpoint
903 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
904
905 dev->int_in_size = buffer_size;
906 dev->int_in_endpointAddr = (endpoint->bEndpointAddress & 0xf);
907 }
908
909 if (!dev->isoc_in_endpointAddr
910 && ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
911 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC)) {
912 // we found an isoc in endpoint
913 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
914
915 dev->isoc_in_size = buffer_size;
916 dev->isoc_in_endpointAddr = (endpoint->bEndpointAddress & 0xf);
917 }
918 }
919
920 if (!(dev->int_in_endpointAddr && dev->isoc_in_endpointAddr)) {
921 STK_ERROR("Could not find both int-in and isoc-in endpoints");
922
923 kfree(dev);
924
925 return -ENODEV;
926 }
927
928
929 // Switch off camera
931
932 // Initialize the video device
933 dev->vdev = video_device_alloc();
934
935 if (!dev->vdev) {
936 kfree(dev);
937 return -ENOMEM;
938 }
939
940 // Initialize the camera
942
943 // Register the video device
945
946 if (err) {
947 kfree(dev);
948 return err;
949 }
950
951 // Create the entries in the sys filesystem
953
954 // Save our data pointer in this interface device
955 usb_set_intfdata(interface, dev);
956
957 // Default settings video device
959
960 // Enable power management feature
961// usb_autopm_enable(dev->interface);
962
963 return 0;
964}
965
966
973static void usb_stk11xx_disconnect(struct usb_interface *interface)
974{
975 struct usb_stk11xx *dev = usb_get_intfdata(interface);
976
977 STK_INFO("Syntek USB2.0 Camera disconnected\n");
978
979 // We got unplugged; this is signalled by an EPIPE error code
980 if (dev->vopen) {
981 STK_INFO("Disconnected while webcam is in use !\n");
982 dev->error_status = EPIPE;
983 }
984
985 // Alert waiting processes
986 wake_up_interruptible(&dev->wait_frame);
987
988 // Wait until device is closed
989 while (dev->vopen)
990 schedule();
991
992 // Remove the entries in the sys filesystem
994
995 // Unregister the video device
997
998 usb_set_intfdata(interface, NULL);
999
1000 kfree(dev);
1001}
1002
1003/*
1004int usb_stk11xx_suspend(struct usb_interface *interface, pm_message_t message)
1005{
1006 struct usb_stk11xx *dev = usb_get_intfdata(interface);
1007
1008 STK_INFO("Syntek USB2.0 Camera Suspend\n");
1009
1010 // Stop the video stream
1011 dev_stk11xx_stop_stream(dev);
1012
1013 // ISOC and URB cleanup
1014 usb_stk11xx_isoc_cleanup(dev);
1015
1016 // Free memory
1017// stk11xx_free_buffers(dev);
1018
1019 // Switch off the camera
1020 dev_stk11xx_camera_off(dev);
1021
1022 return 0;
1023}
1024
1025
1026int usb_stk11xx_resume(struct usb_interface *interface)
1027{
1028 struct usb_stk11xx *dev = usb_get_intfdata(interface);
1029
1030 STK_INFO("Syntek USB2.0 Camera Resume\n");
1031
1032 // Initialize the camera
1033 dev_stk11xx_initialize_device(dev);
1034
1035 // Select the new video mode
1036 v4l_stk11xx_select_video_mode(dev, dev->view.x, dev->view.y);
1037
1038 // Clear the buffers
1039 stk11xx_clear_buffers(dev);
1040
1041 // Initialize the device
1042 dev_stk11xx_init_camera(dev);
1043 dev_stk11xx_camera_on(dev);
1044 dev_stk11xx_reconf_camera(dev);
1045
1046 // ISOC and URB init
1047 usb_stk11xx_isoc_init(dev);
1048
1049 // Start the video stream
1050 dev_stk11xx_start_stream(dev);
1051
1052 // Video settings
1053 dev_stk11xx_camera_settings(dev);
1054
1055 return 0;
1056}
1057*/
1058
1059
1065static struct usb_driver usb_stk11xx_driver = {
1066 .name = "usb_stk11xx_driver",
1067 .probe = usb_stk11xx_probe,
1068 .disconnect = usb_stk11xx_disconnect,
1069 .id_table = stk11xx_table,
1070// .suspend = usb_stk11xx_suspend,
1071// .resume = usb_stk11xx_resume,
1072};
1073
1074
1079static int fps;
1080
1085static int hflip = -1;
1086
1091static int vflip = -1;
1092
1097static int brightness = -1;
1098
1103static int whiteness = -1;
1104
1109static int contrast = -1;
1110
1115static int colour = -1;
1116
1121static int norm = -1;
1122
1123
1124module_param(fps, int, 0444);
1125module_param(hflip, int, 0444);
1126module_param(vflip, int, 0444);
1132module_param(norm, int, 0444);
1143static int __init usb_stk11xx_init(void)
1144{
1145 int result;
1146
1147 STK_INFO("%s driver %s startup\n", DRIVER_DESC, DRIVER_VERSION);
1148 STK_INFO("Copyright(c) 2006-%d %s\n", DRIVER_YEAR, DRIVER_AUTHOR);
1149 STK_INFO("%s\n", DRIVER_URL);
1150
1151 // Frame per second parameter
1152 if (fps) {
1153 if (fps < 9 || fps > 30) {
1154 STK_ERROR("Framerate out of bounds [10-30] !\n");
1155 return -EINVAL;
1156 }
1157
1158 default_fps = fps;
1159 }
1160
1161 // Horizontal flip value
1162 if ((hflip == 0) || (hflip == 1)) {
1163 STK_DEBUG("Set horizontal flip = %d\n", hflip);
1164
1166 }
1167
1168 // Vertical flip value
1169 if ((vflip == 0) || (vflip == 1)) {
1170 STK_DEBUG("Set vertical flip = %d\n", vflip);
1171
1173 }
1174
1175 // Brightness value
1176 if (brightness > -1) {
1177 STK_DEBUG("Set brightness = 0x%X\n", brightness);
1178
1179 default_brightness = 0xffff & brightness;
1180 }
1181
1182 // Whiteness value
1183 if (whiteness > -1) {
1184 STK_DEBUG("Set whiteness = 0x%X\n", whiteness);
1185
1186 default_whiteness = 0xffff & whiteness;
1187 }
1188
1189 // Contrast value
1190 if (contrast > -1) {
1191 STK_DEBUG("Set contrast = 0x%X\n", contrast);
1192
1193 default_contrast = 0xffff & contrast;
1194 }
1195
1196 // Colour value
1197 if (colour > -1) {
1198 STK_DEBUG("Set colour = 0x%X\n", colour);
1199
1200 default_colour = 0xffff & colour;
1201 }
1202
1203 // Norm value
1204 if (norm > -1) {
1205 default_norm = (norm > 0) ? 1 : 0;
1206
1207 STK_INFO("Set norm = %s\n", (default_norm > 0) ? "NTSC" : "PAL");
1208 }
1209
1210
1211 // Register the driver with the USB subsystem
1213
1214 if (result)
1215 STK_ERROR("usb_register failed ! Error number %d\n", result);
1216
1217 return result;
1218}
1219
1220
1226static void __exit usb_stk11xx_exit(void)
1227{
1228 STK_INFO("usb_stk11xx_exit: Syntek USB2.0 webcam driver shutdown\n");
1229
1230 // Deregister this driver with the USB subsystem
1232}
1233
1234
1239MODULE_PARM_DESC(fps, "Frames per second [5-30]");
1240MODULE_PARM_DESC(hflip, "Horizontal image flip");
1241MODULE_PARM_DESC(vflip, "Vertical image flip");
1242MODULE_PARM_DESC(brightness, "Brightness setting");
1243MODULE_PARM_DESC(whiteness, "Whiteness setting");
1244MODULE_PARM_DESC(colour, "Colour setting");
1245MODULE_PARM_DESC(contrast, "Contrast setting");
1246MODULE_PARM_DESC(norm, "Norm setting (0=NTSC, 1=PAL)");
int stk11xx_next_frame(struct usb_stk11xx *dev)
Prepare the next frame.
int dev_stk11xx_initialize_device(struct usb_stk11xx *dev)
This function permits to initialize the device.
Definition stk11xx-dev.c:63
int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
This function switchs off the camera.
int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
This function switchs on the camera.
int stk11xx_create_sysfs_files(struct video_device *vdev)
Create the 'sys' entries.
void stk11xx_remove_sysfs_files(struct video_device *vdev)
Remove the 'sys' entries.
module_init(usb_stk11xx_init)
Module initialize.
static int norm
static int usb_stk11xx_probe(struct usb_interface *interface, const struct usb_device_id *id)
Load the driver.
int usb_stk11xx_set_configuration(struct usb_stk11xx *dev)
Send the message SET_CONFIGURATION.
static struct usb_device_id stk11xx_table[]
static int hflip
static int default_brightness
Definition stk11xx-usb.c:72
static int usb_stk11xx_default_settings(struct usb_stk11xx *dev)
Set the default value about the video settings.
static int default_colour
Definition stk11xx-usb.c:90
static int __init usb_stk11xx_init(void)
Initialize the driver.
static int default_fps
Definition stk11xx-usb.c:54
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 default_vflip
Definition stk11xx-usb.c:66
static int whiteness
MODULE_AUTHOR(DRIVER_AUTHOR)
Driver is written by Nicolas VIVIEN.
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.
static int fps
int usb_stk11xx_set_feature(struct usb_stk11xx *dev, int index)
Send the message SET_FEATURE and choose the interface.
static void __exit usb_stk11xx_exit(void)
Close the driver.
static void usb_stk11xx_disconnect(struct usb_interface *interface)
This function is called when the device is disconnected or when the kernel module is unloaded.
static int default_contrast
Definition stk11xx-usb.c:84
void usb_stk11xx_isoc_cleanup(struct usb_stk11xx *dev)
Clean-up all the ISOC buffers.
MODULE_DESCRIPTION(DRIVER_DESC)
Define the description of the driver.
static int default_whiteness
Definition stk11xx-usb.c:78
static int default_norm
Definition stk11xx-usb.c:96
MODULE_SUPPORTED_DEVICE(DRIVER_SUPPORT)
List of supported device.
MODULE_INFO(url, DRIVER_URL)
Driver homepage URL.
static int colour
MODULE_VERSION(DRIVER_VERSION)
Define the version of the driver.
static int default_hflip
Definition stk11xx-usb.c:60
static struct usb_driver usb_stk11xx_driver
MODULE_PARM_DESC(fps, "Frames per second [5-30]")
Description of 'fps' parameter.
module_param(fps, int, 0444)
Module frame per second parameter.
module_exit(usb_stk11xx_exit)
Module exit.
MODULE_LICENSE("GPL")
Driver is under licence GPL.
void usb_stk11xx_isoc_handler(struct urb *urb)
ISOC handler.
int usb_stk11xx_isoc_init(struct usb_stk11xx *dev)
Initilize an isochronous pipe.
MODULE_DEVICE_TABLE(usb, stk11xx_table)
static int brightness
static int contrast
int v4l_stk11xx_register_video_device(struct usb_stk11xx *dev)
Register the video device.
int v4l_stk11xx_unregister_video_device(struct usb_stk11xx *dev)
Unregister the video device.
Driver for Syntek USB video camera.
#define USB_STK_0501_PRODUCT_ID
Definition stk11xx.h:61
#define USB_STK_6A33_PRODUCT_ID
Definition stk11xx.h:54
#define DRIVER_AUTHOR
Definition stk11xx.h:42
#define STK_ERROR(str, args...)
Definition stk11xx.h:156
#define USB_STK_6D51_PRODUCT_ID
Definition stk11xx.h:57
#define USB_STK_6A31_PRODUCT_ID
Definition stk11xx.h:53
#define DRIVER_SUPPORT
Definition stk11xx.h:120
@ STK11XX_SXGA
Definition stk11xx.h:210
@ STK11XX_VGA
Definition stk11xx.h:209
@ STK11XX_PAL
Definition stk11xx.h:211
#define STK_INFO(str, args...)
Definition stk11xx.h:155
#define STK11XX_PERCENT(x, y)
Definition stk11xx.h:386
#define DRIVER_URL
Definition stk11xx.h:44
#define STK_STREAM(str, args...)
Definition stk11xx.h:181
#define STK_DEBUG(str, args...)
Definition stk11xx.h:158
#define USB_SYNTEK2_VENDOR_ID
Definition stk11xx.h:48
#define USB_STK_6A51_PRODUCT_ID
Definition stk11xx.h:55
#define ISO_BUFFER_SIZE
Definition stk11xx.h:91
#define USB_STK_6A54_PRODUCT_ID
Definition stk11xx.h:56
#define ISO_MAX_FRAME_SIZE
Definition stk11xx.h:90
#define USB_STK_0500_PRODUCT_ID
Definition stk11xx.h:60
#define MAX_ISO_BUFS
Definition stk11xx.h:88
#define DRIVER_DESC
Definition stk11xx.h:41
#define USB_STK_A311_PRODUCT_ID
Definition stk11xx.h:50
#define USB_STK_0408_PRODUCT_ID
Definition stk11xx.h:59
#define STK11XX_FRAME_SIZE
Definition stk11xx.h:106
#define DRIVER_YEAR
Definition stk11xx.h:40
#define USB_STK_AA11_PRODUCT_ID
Definition stk11xx.h:52
#define DRIVER_VERSION
Definition stk11xx.h:38
#define ISO_FRAMES_PER_DESC
Definition stk11xx.h:89
#define USB_SYNTEK1_VENDOR_ID
Definition stk11xx.h:47
#define USB_STK_A821_PRODUCT_ID
Definition stk11xx.h:51
struct video_device * vdev
Definition stk11xx.h:319
struct stk11xx_video vsettings
Definition stk11xx.h:336
struct usb_interface * interface
Definition stk11xx.h:321
int vframes_error
Definition stk11xx.h:342
size_t int_in_size
Definition stk11xx.h:328
int visoc_errors
Definition stk11xx.h:341
spinlock_t spinlock
Definition stk11xx.h:348
int webcam_type
Definition stk11xx.h:325
struct semaphore mutex
Definition stk11xx.h:349
int release
Definition stk11xx.h:323
__u8 isoc_in_endpointAddr
Definition stk11xx.h:332
__u8 int_in_endpointAddr
Definition stk11xx.h:329
size_t isoc_in_size
Definition stk11xx.h:331
struct mutex modlock
Definition stk11xx.h:351
int webcam_model
Definition stk11xx.h:324
struct usb_device * udev
Definition stk11xx.h:320
wait_queue_head_t wait_frame
Definition stk11xx.h:350
int vframes_dumped
Definition stk11xx.h:343