1 /******************************************************************************
5 * Video driver for EasyCAP USB2.0 Video Capture Device DC60 *
8 ******************************************************************************/
11 * Copyright (C) 2010 R.M. Thomas <rmthomas@sciolus.org>
14 * This is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * The software is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this software; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /*****************************************************************************/
32 #include "easycap_standard.h"
35 module_param(debug, int, S_IRUGO | S_IWUSR);
37 /*---------------------------------------------------------------------------*/
39 * dongle_this IS INDISPENSIBLY static BECAUSE FUNCTION easycap_usb_probe()
40 * IS CALLED SUCCESSIVELY FOR INTERFACES 0, 1, 2 AND THE POINTER peasycap
41 * ALLOCATED DURING THE PROBING OF INTERFACE 0 MUST BE REMEMBERED WHEN
42 * PROBING INTERFACES 1 AND 2.
44 /*---------------------------------------------------------------------------*/
46 struct easycap *peasycap_dongle[DONGLE_MANY];
47 static int dongle_this;
49 /*---------------------------------------------------------------------------*/
51 * PARAMETERS APPLICABLE TO ENTIRE DRIVER, I.E. BOTH VIDEO AND AUDIO
53 /*---------------------------------------------------------------------------*/
54 struct usb_device_id easycap_usb_device_id_table[] = {
55 { USB_DEVICE(USB_EASYCAP_VENDOR_ID, USB_EASYCAP_PRODUCT_ID) },
58 MODULE_DEVICE_TABLE(usb, easycap_usb_device_id_table);
59 struct usb_driver easycap_usb_driver = {
61 .id_table = easycap_usb_device_id_table,
62 .probe = easycap_usb_probe,
63 .disconnect = easycap_usb_disconnect,
65 /*---------------------------------------------------------------------------*/
67 * PARAMETERS USED WHEN REGISTERING THE VIDEO INTERFACE
69 * NOTE: SOME KERNELS IGNORE usb_class_driver.minor_base, AS MENTIONED BY
70 * CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGE 253.
71 * THIS IS THE CASE FOR OpenSUSE.
73 /*---------------------------------------------------------------------------*/
74 const struct file_operations easycap_fops = {
77 .release = easycap_release,
78 .unlocked_ioctl = easycap_ioctl,
83 struct vm_operations_struct easycap_vm_ops = {
84 .open = easycap_vma_open,
85 .close = easycap_vma_close,
86 .fault = easycap_vma_fault,
88 struct usb_class_driver easycap_class = {
89 .name = "usb/easycap%d",
90 .fops = &easycap_fops,
91 .minor_base = USB_SKEL_MINOR_BASE,
94 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
95 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
96 #if defined(EASYCAP_NEEDS_V4L2_FOPS)
97 const struct v4l2_file_operations v4l2_fops = {
99 .open = easycap_open_noinode,
100 .release = easycap_release_noinode,
101 .unlocked_ioctl = easycap_ioctl,
102 .poll = easycap_poll,
103 .mmap = easycap_mmap,
105 #endif /*EASYCAP_NEEDS_V4L2_FOPS*/
106 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
107 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
109 /*--------------------------------------------------------------------------*/
111 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE
113 /*--------------------------------------------------------------------------*/
114 const struct file_operations easysnd_fops = {
115 .owner = THIS_MODULE,
116 .open = easysnd_open,
117 .release = easysnd_release,
118 .unlocked_ioctl = easysnd_ioctl,
119 .read = easysnd_read,
122 struct usb_class_driver easysnd_class = {
123 .name = "usb/easysnd%d",
124 .fops = &easysnd_fops,
125 .minor_base = USB_SKEL_MINOR_BASE,
127 /****************************************************************************/
128 /*---------------------------------------------------------------------------*/
130 * THIS ROUTINE DOES NOT DETECT MULTIPLE OCCURRENCES OF POINTER peasycap
132 /*---------------------------------------------------------------------------*/
134 isdongle(struct easycap *peasycap)
137 if ((struct easycap *)NULL == peasycap)
139 for (k = 0; k < DONGLE_MANY; k++) {
140 if (peasycap_dongle[k] == peasycap) {
141 peasycap->isdongle = k;
147 /*****************************************************************************/
148 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
149 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
151 easycap_open_noinode(struct file *file)
153 return easycap_open((struct inode *)NULL, file);
155 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
156 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
158 easycap_open(struct inode *inode, struct file *file)
160 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
161 struct usb_interface *pusb_interface;
163 struct video_device *pvideo_device;
164 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
165 struct usb_device *p;
166 struct easycap *peasycap;
170 SAY("==========OPEN=========\n");
172 peasycap = (struct easycap *)NULL;
173 /*---------------------------------------------------------------------------*/
174 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
175 if ((struct inode *)NULL == inode) {
176 SAY("ERROR: inode is NULL.\n");
179 pusb_interface = usb_find_interface(&easycap_usb_driver, iminor(inode));
180 if (!pusb_interface) {
181 SAY("ERROR: pusb_interface is NULL.\n");
184 peasycap = usb_get_intfdata(pusb_interface);
185 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
187 pvideo_device = video_devdata(file);
188 if ((struct video_device *)NULL == pvideo_device) {
189 SAY("ERROR: pvideo_device is NULL.\n");
192 peasycap = (struct easycap *)video_get_drvdata(pvideo_device);
193 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
194 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
195 if ((struct easycap *)NULL == peasycap) {
196 SAY("ERROR: peasycap is NULL\n");
199 file->private_data = peasycap;
200 /*---------------------------------------------------------------------------*/
204 /*---------------------------------------------------------------------------*/
205 JOM(4, "starting initialization\n");
207 for (k = 0; k < FRAME_BUFFER_MANY; k++) {
208 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++)
209 memset(peasycap->frame_buffer[k][m].pgo, 0, PAGE_SIZE);
211 p = peasycap->pusb_device;
212 if ((struct usb_device *)NULL == p) {
213 SAM("ERROR: peasycap->pusb_device is NULL\n");
216 JOM(16, "0x%08lX=peasycap->pusb_device\n", \
217 (long int)peasycap->pusb_device);
219 rc = wakeup_device(peasycap->pusb_device);
221 JOM(8, "wakeup_device() OK\n");
223 SAM("ERROR: wakeup_device() returned %i\n", rc);
226 rc = setup_stk(p); peasycap->input = 0;
228 JOM(8, "setup_stk() OK\n");
230 SAM("ERROR: setup_stk() returned %i\n", rc);
235 JOM(8, "setup_saa() OK\n");
237 SAM("ERROR: setup_saa() returned %i\n", rc);
242 JOM(8, "check_saa() OK\n");
244 SAM("check_saa() returned %i\n", rc);
246 SAM("ERROR: check_saa() returned %i\n", rc);
249 peasycap->standard_offset = -1;
250 /*---------------------------------------------------------------------------*/
251 #if defined(PREFER_NTSC)
253 rc = adjust_standard(peasycap, V4L2_STD_NTSC_M);
255 JOM(8, "adjust_standard(.,NTSC_M) OK\n");
257 SAM("ERROR: adjust_standard(.,NTSC_M) returned %i\n", rc);
260 rc = adjust_format(peasycap, 640, 480, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, \
263 JOM(8, "adjust_format(.,640,480,UYVY) OK\n");
265 SAM("ERROR: adjust_format(.,640,480,UYVY) returned %i\n", rc);
271 rc = adjust_standard(peasycap, \
272 (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \
273 V4L2_STD_PAL_I | V4L2_STD_PAL_N));
275 JOM(8, "adjust_standard(.,PAL_BGHIN) OK\n");
277 SAM("ERROR: adjust_standard(.,PAL_BGHIN) returned %i\n", rc);
280 rc = adjust_format(peasycap, 640, 480, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, \
283 JOM(8, "adjust_format(.,640,480,uyvy,false) OK\n");
285 SAM("ERROR: adjust_format(.,640,480,uyvy,false) returned %i\n", rc);
289 #endif /* !PREFER_NTSC*/
290 /*---------------------------------------------------------------------------*/
291 rc = adjust_brightness(peasycap, -8192);
293 SAM("ERROR: adjust_brightness(default) returned %i\n", rc);
296 rc = adjust_contrast(peasycap, -8192);
298 SAM("ERROR: adjust_contrast(default) returned %i\n", rc);
301 rc = adjust_saturation(peasycap, -8192);
303 SAM("ERROR: adjust_saturation(default) returned %i\n", rc);
306 rc = adjust_hue(peasycap, -8192);
308 SAM("ERROR: adjust_hue(default) returned %i\n", rc);
311 /*---------------------------------------------------------------------------*/
312 rc = usb_set_interface(peasycap->pusb_device, peasycap->video_interface, \
313 peasycap->video_altsetting_on);
315 JOM(8, "usb_set_interface(.,%i,%i) OK\n", peasycap->video_interface, \
316 peasycap->video_altsetting_on);
318 SAM("ERROR: usb_set_interface() returned %i\n", rc);
323 JOM(8, "start_100() OK\n");
325 SAM("ERROR: start_100() returned %i\n", rc);
328 peasycap->video_isoc_sequence = VIDEO_ISOC_BUFFER_MANY - 1;
329 peasycap->video_idle = 0;
330 peasycap->video_junk = 0;
331 for (i = 0; i < 180; i++)
332 peasycap->merit[i] = 0;
333 peasycap->video_eof = 0;
334 peasycap->audio_eof = 0;
336 do_gettimeofday(&peasycap->timeval7);
338 JOM(4, "finished initialization\n");
341 /*****************************************************************************/
343 submit_video_urbs(struct easycap *peasycap)
345 struct data_urb *pdata_urb;
347 struct list_head *plist_head;
348 int j, isbad, nospc, m, rc;
351 if ((struct easycap *)NULL == peasycap) {
352 SAY("ERROR: peasycap is NULL\n");
356 if ((struct list_head *)NULL == peasycap->purb_video_head) {
357 SAY("ERROR: peasycap->urb_video_head uninitialized\n");
360 if ((struct usb_device *)NULL == peasycap->pusb_device) {
361 SAY("ERROR: peasycap->pusb_device is NULL\n");
364 if (!peasycap->video_isoc_streaming) {
365 JOM(4, "submission of all video urbs\n");
366 isbad = 0; nospc = 0; m = 0;
367 list_for_each(plist_head, (peasycap->purb_video_head)) {
368 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
369 if (NULL != pdata_urb) {
370 purb = pdata_urb->purb;
372 isbuf = pdata_urb->isbuf;
374 purb->dev = peasycap->pusb_device;
376 usb_rcvisocpipe(peasycap->pusb_device,\
377 peasycap->video_endpointnumber);
378 purb->transfer_flags = URB_ISO_ASAP;
379 purb->transfer_buffer = \
380 peasycap->video_isoc_buffer[isbuf].pgo;
381 purb->transfer_buffer_length = \
382 peasycap->video_isoc_buffer_size;
383 purb->complete = easycap_complete;
384 purb->context = peasycap;
385 purb->start_frame = 0;
386 purb->number_of_packets = \
387 peasycap->video_isoc_framesperdesc;
389 for (j = 0; j < peasycap->\
390 video_isoc_framesperdesc; j++) {
391 purb->iso_frame_desc[j].\
394 video_isoc_maxframesize;
395 purb->iso_frame_desc[j].\
397 video_isoc_maxframesize;
400 rc = usb_submit_urb(purb, GFP_KERNEL);
403 SAM("ERROR: usb_submit_urb() failed " \
404 "for urb with rc:\n");
407 SAM("ERROR: -ENOMEM=" \
408 "usb_submit_urb()\n");
412 SAM("ERROR: -ENODEV=" \
413 "usb_submit_urb()\n");
417 SAM("ERROR: -ENXIO=" \
418 "usb_submit_urb()\n");
422 SAM("ERROR: -EINVAL=" \
423 "usb_submit_urb()\n");
427 SAM("ERROR: -EAGAIN=" \
428 "usb_submit_urb()\n");
432 SAM("ERROR: -EFBIG=" \
433 "usb_submit_urb()\n");
437 SAM("ERROR: -EPIPE=" \
438 "usb_submit_urb()\n");
442 SAM("ERROR: -EMSGSIZE=" \
443 "usb_submit_urb()\n");
452 "usb_submit_urb()\n",\
468 SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
469 SAM("..... possibly inadequate USB bandwidth\n");
470 peasycap->video_eof = 1;
474 JOM(4, "attempting cleanup instead of submitting\n");
475 list_for_each(plist_head, (peasycap->purb_video_head)) {
476 pdata_urb = list_entry(plist_head, struct data_urb, \
478 if (NULL != pdata_urb) {
479 purb = pdata_urb->purb;
484 peasycap->video_isoc_streaming = 0;
486 peasycap->video_isoc_streaming = 1;
487 JOM(4, "submitted %i video urbs\n", m);
490 JOM(4, "already streaming video urbs\n");
494 /*****************************************************************************/
496 kill_video_urbs(struct easycap *peasycap)
499 struct list_head *plist_head;
500 struct data_urb *pdata_urb;
502 if ((struct easycap *)NULL == peasycap) {
503 SAY("ERROR: peasycap is NULL\n");
506 if (peasycap->video_isoc_streaming) {
507 if ((struct list_head *)NULL != peasycap->purb_video_head) {
508 peasycap->video_isoc_streaming = 0;
509 JOM(4, "killing video urbs\n");
511 list_for_each(plist_head, (peasycap->purb_video_head)) {
512 pdata_urb = list_entry(plist_head, struct data_urb, \
514 if ((struct data_urb *)NULL != pdata_urb) {
515 if ((struct urb *)NULL != pdata_urb->purb) {
516 usb_kill_urb(pdata_urb->purb);
521 JOM(4, "%i video urbs killed\n", m);
523 SAM("ERROR: peasycap->purb_video_head is NULL\n");
527 JOM(8, "%i=video_isoc_streaming, no video urbs killed\n", \
528 peasycap->video_isoc_streaming);
532 /****************************************************************************/
533 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
534 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
536 easycap_release_noinode(struct file *file)
538 return easycap_release((struct inode *)NULL, file);
540 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
541 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
542 /*--------------------------------------------------------------------------*/
544 easycap_release(struct inode *inode, struct file *file)
546 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
547 struct easycap *peasycap;
551 peasycap = file->private_data;
552 if (NULL == peasycap) {
553 SAY("ERROR: peasycap is NULL.\n");
554 SAY("ending unsuccessfully\n");
557 if (0 != kill_video_urbs(peasycap)) {
558 SAM("ERROR: kill_video_urbs() failed\n");
561 JOM(4, "ending successfully\n");
562 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
565 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
566 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
570 /****************************************************************************/
571 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
572 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
574 videodev_release(struct video_device *pvideo_device)
576 struct easycap *peasycap;
580 peasycap = video_get_drvdata(pvideo_device);
581 if (NULL == peasycap) {
582 SAY("ERROR: peasycap is NULL\n");
583 SAY("ending unsuccessfully\n");
586 if (0 != kill_video_urbs(peasycap)) {
587 SAM("ERROR: kill_video_urbs() failed\n");
590 JOM(4, "ending successfully\n");
593 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
594 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
595 /*****************************************************************************/
596 /*--------------------------------------------------------------------------*/
598 * THIS FUNCTION IS CALLED FROM WITHIN easycap_usb_disconnect().
599 * BY THIS STAGE THE DEVICE HAS ALREADY BEEN PHYSICALLY UNPLUGGED.
600 * peasycap->pusb_device IS NO LONGER VALID AND SHOULD HAVE BEEN SET TO NULL.
602 /*---------------------------------------------------------------------------*/
604 easycap_delete(struct kref *pkref)
607 int allocation_video_urb, allocation_video_page, allocation_video_struct;
608 int allocation_audio_urb, allocation_audio_page, allocation_audio_struct;
609 int registered_video, registered_audio;
610 struct easycap *peasycap;
611 struct data_urb *pdata_urb;
612 struct list_head *plist_head, *plist_next;
616 peasycap = container_of(pkref, struct easycap, kref);
617 if ((struct easycap *)NULL == peasycap) {
618 SAM("ERROR: peasycap is NULL: cannot perform deletions\n");
621 /*---------------------------------------------------------------------------*/
625 /*---------------------------------------------------------------------------*/
626 if ((struct list_head *)NULL != peasycap->purb_video_head) {
627 JOM(4, "freeing video urbs\n");
629 list_for_each(plist_head, (peasycap->purb_video_head)) {
630 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
631 if (NULL == pdata_urb)
632 JOM(4, "ERROR: pdata_urb is NULL\n");
634 if ((struct urb *)NULL != pdata_urb->purb) {
635 usb_free_urb(pdata_urb->purb);
636 pdata_urb->purb = (struct urb *)NULL;
637 peasycap->allocation_video_urb -= 1;
643 JOM(4, "%i video urbs freed\n", m);
644 /*---------------------------------------------------------------------------*/
645 JOM(4, "freeing video data_urb structures.\n");
647 list_for_each_safe(plist_head, plist_next, peasycap->purb_video_head) {
648 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
649 if ((struct data_urb *)NULL != pdata_urb) {
650 kfree(pdata_urb); pdata_urb = (struct data_urb *)NULL;
651 peasycap->allocation_video_struct -= \
652 sizeof(struct data_urb);
656 JOM(4, "%i video data_urb structures freed\n", m);
657 JOM(4, "setting peasycap->purb_video_head=NULL\n");
658 peasycap->purb_video_head = (struct list_head *)NULL;
660 JOM(4, "peasycap->purb_video_head is NULL\n");
662 /*---------------------------------------------------------------------------*/
663 JOM(4, "freeing video isoc buffers.\n");
665 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
666 if ((void *)NULL != peasycap->video_isoc_buffer[k].pgo) {
667 free_pages((unsigned long)\
668 (peasycap->video_isoc_buffer[k].pgo), \
670 peasycap->video_isoc_buffer[k].pgo = (void *)NULL;
671 peasycap->allocation_video_page -= \
672 ((unsigned int)(0x01 << VIDEO_ISOC_ORDER));
676 JOM(4, "isoc video buffers freed: %i pages\n", m * (0x01 << VIDEO_ISOC_ORDER));
677 /*---------------------------------------------------------------------------*/
678 JOM(4, "freeing video field buffers.\n");
680 for (k = 0; k < FIELD_BUFFER_MANY; k++) {
681 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) {
682 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) {
683 free_page((unsigned long)\
684 (peasycap->field_buffer[k][m].pgo));
685 peasycap->field_buffer[k][m].pgo = (void *)NULL;
686 peasycap->allocation_video_page -= 1;
691 JOM(4, "video field buffers freed: %i pages\n", lost);
692 /*---------------------------------------------------------------------------*/
693 JOM(4, "freeing video frame buffers.\n");
695 for (k = 0; k < FRAME_BUFFER_MANY; k++) {
696 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) {
697 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo) {
698 free_page((unsigned long)\
699 (peasycap->frame_buffer[k][m].pgo));
700 peasycap->frame_buffer[k][m].pgo = (void *)NULL;
701 peasycap->allocation_video_page -= 1;
706 JOM(4, "video frame buffers freed: %i pages\n", lost);
707 /*---------------------------------------------------------------------------*/
711 /*---------------------------------------------------------------------------*/
712 if ((struct list_head *)NULL != peasycap->purb_audio_head) {
713 JOM(4, "freeing audio urbs\n");
715 list_for_each(plist_head, (peasycap->purb_audio_head)) {
716 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
717 if (NULL == pdata_urb)
718 JOM(4, "ERROR: pdata_urb is NULL\n");
720 if ((struct urb *)NULL != pdata_urb->purb) {
721 usb_free_urb(pdata_urb->purb);
722 pdata_urb->purb = (struct urb *)NULL;
723 peasycap->allocation_audio_urb -= 1;
728 JOM(4, "%i audio urbs freed\n", m);
729 /*---------------------------------------------------------------------------*/
730 JOM(4, "freeing audio data_urb structures.\n");
732 list_for_each_safe(plist_head, plist_next, peasycap->purb_audio_head) {
733 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
734 if ((struct data_urb *)NULL != pdata_urb) {
735 kfree(pdata_urb); pdata_urb = (struct data_urb *)NULL;
736 peasycap->allocation_audio_struct -= \
737 sizeof(struct data_urb);
741 JOM(4, "%i audio data_urb structures freed\n", m);
742 JOM(4, "setting peasycap->purb_audio_head=NULL\n");
743 peasycap->purb_audio_head = (struct list_head *)NULL;
745 JOM(4, "peasycap->purb_audio_head is NULL\n");
747 /*---------------------------------------------------------------------------*/
748 JOM(4, "freeing audio isoc buffers.\n");
750 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
751 if ((void *)NULL != peasycap->audio_isoc_buffer[k].pgo) {
752 free_pages((unsigned long)\
753 (peasycap->audio_isoc_buffer[k].pgo), \
755 peasycap->audio_isoc_buffer[k].pgo = (void *)NULL;
756 peasycap->allocation_audio_page -= \
757 ((unsigned int)(0x01 << AUDIO_ISOC_ORDER));
761 JOM(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \
762 m * (0x01 << AUDIO_ISOC_ORDER));
763 /*---------------------------------------------------------------------------*/
764 JOM(4, "freeing audio buffers.\n");
766 for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
767 if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
768 free_page((unsigned long)(peasycap->audio_buffer[k].pgo));
769 peasycap->audio_buffer[k].pgo = (void *)NULL;
770 peasycap->allocation_audio_page -= 1;
774 JOM(4, "easysnd_delete(): audio buffers freed: %i pages\n", lost);
775 /*---------------------------------------------------------------------------*/
776 JOM(4, "freeing easycap structure.\n");
777 allocation_video_urb = peasycap->allocation_video_urb;
778 allocation_video_page = peasycap->allocation_video_page;
779 allocation_video_struct = peasycap->allocation_video_struct;
780 registered_video = peasycap->registered_video;
781 allocation_audio_urb = peasycap->allocation_audio_urb;
782 allocation_audio_page = peasycap->allocation_audio_page;
783 allocation_audio_struct = peasycap->allocation_audio_struct;
784 registered_audio = peasycap->registered_audio;
786 if ((struct easycap *)NULL != peasycap) {
787 kfree(peasycap); peasycap = (struct easycap *)NULL;
788 allocation_video_struct -= sizeof(struct easycap);
791 JOT(4, "%i easycap structure freed\n", m);
792 /*---------------------------------------------------------------------------*/
794 SAY("%8i= video urbs after all deletions\n", allocation_video_urb);
795 SAY("%8i= video pages after all deletions\n", allocation_video_page);
796 SAY("%8i= video structs after all deletions\n", allocation_video_struct);
797 SAY("%8i= video devices after all deletions\n", registered_video);
798 SAY("%8i= audio urbs after all deletions\n", allocation_audio_urb);
799 SAY("%8i= audio pages after all deletions\n", allocation_audio_page);
800 SAY("%8i= audio structs after all deletions\n", allocation_audio_struct);
801 SAY("%8i= audio devices after all deletions\n", registered_audio);
806 /*****************************************************************************/
807 unsigned int easycap_poll(struct file *file, poll_table *wait)
809 struct easycap *peasycap;
813 if (NULL == ((poll_table *)wait))
814 JOT(8, "WARNING: poll table pointer is NULL ... continuing\n");
815 if (NULL == ((struct file *)file)) {
816 SAY("ERROR: file pointer is NULL\n");
819 peasycap = file->private_data;
820 if (NULL == peasycap) {
821 SAY("ERROR: peasycap is NULL\n");
824 peasycap->polled = 1;
826 if (0 == easycap_dqbuf(peasycap, 0))
827 return POLLIN | POLLRDNORM;
832 /*****************************************************************************/
833 /*---------------------------------------------------------------------------*/
835 * IF mode IS NONZERO THIS ROUTINE RETURNS -EAGAIN RATHER THAN BLOCKING.
837 /*---------------------------------------------------------------------------*/
839 easycap_dqbuf(struct easycap *peasycap, int mode)
845 if (NULL == peasycap) {
846 SAY("ERROR: peasycap is NULL\n");
849 /*---------------------------------------------------------------------------*/
853 /*---------------------------------------------------------------------------*/
855 while ((peasycap->field_read == peasycap->field_fill) || \
856 (0 != (0xFF00 & peasycap->field_buffer\
857 [peasycap->field_read][0].kount)) || \
858 (0 != (0x00FF & peasycap->field_buffer\
859 [peasycap->field_read][0].kount))) {
863 JOM(8, "first wait on wq_video, " \
864 "%i=field_read %i=field_fill\n", \
865 peasycap->field_read, peasycap->field_fill);
868 if (0 != (wait_event_interruptible(peasycap->wq_video, \
869 (peasycap->video_idle || peasycap->video_eof || \
870 ((peasycap->field_read != peasycap->field_fill) && \
871 (0 == (0xFF00 & peasycap->field_buffer\
872 [peasycap->field_read][0].kount)) && \
873 (0 == (0x00FF & peasycap->field_buffer\
874 [peasycap->field_read][0].kount))))))){
875 SAM("aborted by signal\n");
878 if (peasycap->video_idle) {
879 JOM(8, "%i=peasycap->video_idle\n", peasycap->video_idle);
882 if (peasycap->video_eof) {
883 JOM(8, "%i=peasycap->video_eof\n", peasycap->video_eof);
884 kill_video_urbs(peasycap);
889 JOM(8, "first awakening on wq_video after %i waits\n", miss);
891 rc = field2frame(peasycap);
893 SAM("ERROR: field2frame() returned %i\n", rc);
895 if (true == peasycap->offerfields) {
896 peasycap->frame_read = peasycap->frame_fill;
897 (peasycap->frame_fill)++;
898 if (peasycap->frame_buffer_many <= peasycap->frame_fill)
899 peasycap->frame_fill = 0;
901 if (0x01 & easycap_standard[peasycap->standard_offset].mask) {
902 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
905 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
908 JOM(8, "setting: %i=peasycap->frame_read\n", peasycap->frame_read);
909 JOM(8, "bumped to: %i=peasycap->frame_fill\n", peasycap->frame_fill);
911 /*---------------------------------------------------------------------------*/
915 /*---------------------------------------------------------------------------*/
917 while ((peasycap->field_read == peasycap->field_fill) || \
918 (0 != (0xFF00 & peasycap->field_buffer\
919 [peasycap->field_read][0].kount)) || \
920 (0 == (0x00FF & peasycap->field_buffer\
921 [peasycap->field_read][0].kount))) {
925 JOM(8, "second wait on wq_video, " \
926 "%i=field_read %i=field_fill\n", \
927 peasycap->field_read, peasycap->field_fill);
929 if (0 != (wait_event_interruptible(peasycap->wq_video, \
930 (peasycap->video_idle || peasycap->video_eof || \
931 ((peasycap->field_read != peasycap->field_fill) && \
932 (0 == (0xFF00 & peasycap->field_buffer\
933 [peasycap->field_read][0].kount)) && \
934 (0 != (0x00FF & peasycap->field_buffer\
935 [peasycap->field_read][0].kount))))))){
936 SAM("aborted by signal\n");
939 if (peasycap->video_idle) {
940 JOM(8, "%i=peasycap->video_idle\n", peasycap->video_idle);
943 if (peasycap->video_eof) {
944 JOM(8, "%i=peasycap->video_eof\n", peasycap->video_eof);
945 kill_video_urbs(peasycap);
950 JOM(8, "second awakening on wq_video after %i waits\n", miss);
952 rc = field2frame(peasycap);
954 SAM("ERROR: field2frame() returned %i\n", rc);
956 peasycap->frame_read = peasycap->frame_fill;
957 peasycap->queued[peasycap->frame_read] = 0;
958 peasycap->done[peasycap->frame_read] = V4L2_BUF_FLAG_DONE;
960 (peasycap->frame_fill)++;
961 if (peasycap->frame_buffer_many <= peasycap->frame_fill)
962 peasycap->frame_fill = 0;
964 if (0x01 & easycap_standard[peasycap->standard_offset].mask) {
965 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
968 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
972 JOM(8, "setting: %i=peasycap->frame_read\n", peasycap->frame_read);
973 JOM(8, "bumped to: %i=peasycap->frame_fill\n", peasycap->frame_fill);
977 /*****************************************************************************/
978 /*---------------------------------------------------------------------------*/
980 * BY DEFINITION, odd IS true FOR THE FIELD OCCUPYING LINES 1,3,5,...,479
981 * odd IS false FOR THE FIELD OCCUPYING LINES 0,2,4,...,478
983 * WHEN BOOLEAN PARAMETER decimatepixel IS true, ONLY THE FIELD FOR WHICH
984 * odd==false IS TRANSFERRED TO THE FRAME BUFFER.
986 * THE BOOLEAN PARAMETER offerfields IS true ONLY WHEN THE USER PROGRAM
987 * CHOOSES THE OPTION V4L2_FIELD_ALTERNATE. NO USERSPACE PROGRAM TESTED
988 * TO DATE HAS DONE THIS. BUGS ARE LIKELY.
990 /*---------------------------------------------------------------------------*/
992 field2frame(struct easycap *peasycap)
994 struct timeval timeval;
995 long long int above, below;
997 struct signed_div_result sdr;
1000 int kex, kad, mex, mad, rex, rad, rad2;
1001 int c2, c3, w2, w3, cz, wz;
1002 int rc, bytesperpixel, multiplier, much, more, over, rump, caches;
1004 bool odd, isuy, decimatepixel, offerfields;
1006 if ((struct easycap *)NULL == peasycap) {
1007 SAY("ERROR: peasycap is NULL\n");
1011 JOM(8, "===== parity %i, field buffer %i --> frame buffer %i\n", \
1012 peasycap->field_buffer[peasycap->field_read][0].kount,\
1013 peasycap->field_read, peasycap->frame_fill);
1014 JOM(8, "===== %i=bytesperpixel\n", peasycap->bytesperpixel);
1015 if (true == peasycap->offerfields)
1016 JOM(8, "===== offerfields\n");
1018 /*---------------------------------------------------------------------------*/
1020 * REJECT OR CLEAN BAD FIELDS
1022 /*---------------------------------------------------------------------------*/
1023 if (peasycap->field_read == peasycap->field_fill) {
1024 SAM("ERROR: on entry, still filling field buffer %i\n", \
1025 peasycap->field_read);
1028 #if defined(EASYCAP_TESTCARD)
1029 easycap_testcard(peasycap, peasycap->field_read);
1031 if (0 != (0x0400 & peasycap->field_buffer[peasycap->field_read][0].kount))
1032 easycap_testcard(peasycap, peasycap->field_read);
1033 #endif /*EASYCAP_TESTCARD*/
1034 /*---------------------------------------------------------------------------*/
1036 offerfields = peasycap->offerfields;
1037 bytesperpixel = peasycap->bytesperpixel;
1038 decimatepixel = peasycap->decimatepixel;
1040 if ((2 != bytesperpixel) && \
1041 (3 != bytesperpixel) && \
1042 (4 != bytesperpixel)) {
1043 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel);
1046 if (true == decimatepixel)
1051 w2 = 2 * multiplier * (peasycap->width);
1052 w3 = bytesperpixel * \
1056 (peasycap->height) * \
1060 kex = peasycap->field_read; mex = 0;
1061 kad = peasycap->frame_fill; mad = 0;
1063 pex = peasycap->field_buffer[kex][0].pgo; rex = PAGE_SIZE;
1064 pad = peasycap->frame_buffer[kad][0].pgo; rad = PAGE_SIZE;
1065 if (peasycap->field_buffer[kex][0].kount)
1070 if ((true == odd) && (false == offerfields) &&(false == decimatepixel)) {
1071 JOM(8, " initial skipping %4i bytes p.%4i\n", \
1072 w3/multiplier, mad);
1073 pad += (w3 / multiplier); rad -= (w3 / multiplier);
1076 mask = 0; rump = 0; caches = 0;
1080 /*-------------------------------------------------------------------*/
1082 ** PROCESS ONE LINE OF FRAME AT FULL RESOLUTION:
1083 ** READ w2 BYTES FROM FIELD BUFFER,
1084 ** WRITE w3 BYTES TO FRAME BUFFER
1086 /*-------------------------------------------------------------------*/
1087 if (false == decimatepixel) {
1090 much = over; more = 0; margin = 0; mask = 0x00;
1096 SAM("MISTAKE: much is odd\n");
1100 more = (bytesperpixel * \
1102 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1103 if (1 < bytesperpixel) {
1108 ** INJUDICIOUS ALTERATION OF THIS
1109 ** BLOCK WILL CAUSE BREAKAGE.
1112 rad2 = rad + bytesperpixel - 1;
1114 rad2)/bytesperpixel)/2) * 2);
1115 rump = ((bytesperpixel * \
1123 if ((mex + 1) < FIELD_BUFFER_SIZE/ \
1125 margin = *((__u8 *)(peasycap->\
1127 [kex][mex + 1].pgo));
1131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1133 SAM("MISTAKE: %i=bytesperpixel\n", \
1137 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1141 rc = redaub(peasycap, pad, pex, much, more, \
1142 mask, margin, isuy);
1144 SAM("ERROR: redaub() failed\n");
1153 over -= much; cz += much;
1154 pex += much; rex -= much;
1157 pex = peasycap->field_buffer[kex][mex].pgo;
1164 pad = peasycap->frame_buffer[kad][mad].pgo;
1172 /*---------------------------------------------------------------------------*/
1174 * SKIP w3 BYTES IN TARGET FRAME BUFFER,
1175 * UNLESS IT IS THE LAST LINE OF AN ODD FRAME
1177 /*---------------------------------------------------------------------------*/
1178 if (((false == odd) || (cz != wz))&&(false == offerfields)) {
1183 pad = peasycap->frame_buffer\
1195 /*---------------------------------------------------------------------------*/
1197 * PROCESS ONE LINE OF FRAME AT REDUCED RESOLUTION:
1198 * ONLY IF false==odd,
1199 * READ w2 BYTES FROM FIELD BUFFER,
1200 * WRITE w3 / 2 BYTES TO FRAME BUFFER
1202 /*---------------------------------------------------------------------------*/
1203 } else if (false == odd) {
1206 much = over; more = 0; margin = 0; mask = 0x00;
1212 SAM("MISTAKE: much is odd\n");
1216 more = (bytesperpixel * \
1218 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1219 if (1 < bytesperpixel) {
1220 if ((rad * 4) < (much * \
1223 ** INJUDICIOUS ALTERATION OF THIS
1224 ** BLOCK WILL CAUSE BREAKAGE.
1227 rad2 = rad + bytesperpixel - 1;
1228 much = ((((2 * rad2)/bytesperpixel)/2)\
1230 rump = ((bytesperpixel * \
1238 if ((mex + 1) < FIELD_BUFFER_SIZE/ \
1240 margin = *((__u8 *)(peasycap->\
1242 [kex][mex + 1].pgo));
1247 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1249 SAM("MISTAKE: %i=bytesperpixel\n", \
1253 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1257 rc = redaub(peasycap, pad, pex, much, more, \
1258 mask, margin, isuy);
1260 SAM("ERROR: redaub() failed\n");
1263 over -= much; cz += much;
1264 pex += much; rex -= much;
1267 pex = peasycap->field_buffer[kex][mex].pgo;
1274 pad = peasycap->frame_buffer[kad][mad].pgo;
1282 /*---------------------------------------------------------------------------*/
1285 * READ w2 BYTES FROM FIELD BUFFER AND DISCARD THEM
1287 /*---------------------------------------------------------------------------*/
1293 pex = peasycap->field_buffer[kex][mex].pgo;
1306 /*---------------------------------------------------------------------------*/
1310 /*---------------------------------------------------------------------------*/
1311 c2 = (mex + 1)*PAGE_SIZE - rex;
1313 SAM("ERROR: discrepancy %i in bytes read\n", c2 - cz);
1314 c3 = (mad + 1)*PAGE_SIZE - rad;
1316 if (false == decimatepixel) {
1317 if (bytesperpixel * \
1319 SAM("ERROR: discrepancy %i in bytes written\n", \
1320 c3 - (bytesperpixel * \
1324 if (bytesperpixel * \
1326 SAM("ERROR: discrepancy %i in bytes written\n", \
1327 (2*c3)-(bytesperpixel * \
1331 SAM("ERROR: discrepancy %i " \
1332 "in bytes written\n", c3);
1336 SAM("WORRY: undischarged cache at end of line in frame buffer\n");
1338 JOM(8, "===== field2frame(): %i bytes --> %i bytes (incl skip)\n", c2, c3);
1339 JOM(8, "===== field2frame(): %i=mad %i=rad\n", mad, rad);
1342 JOM(8, "+++++ field2frame(): frame buffer %i is full\n", kad);
1344 if (peasycap->field_read == peasycap->field_fill)
1345 SAM("WARNING: on exit, filling field buffer %i\n", \
1346 peasycap->field_read);
1347 /*---------------------------------------------------------------------------*/
1349 * CALCULATE VIDEO STREAMING RATE
1351 /*---------------------------------------------------------------------------*/
1352 do_gettimeofday(&timeval);
1353 if (peasycap->timeval6.tv_sec) {
1354 below = ((long long int)(1000000)) * \
1355 ((long long int)(timeval.tv_sec - \
1356 peasycap->timeval6.tv_sec)) + \
1357 (long long int)(timeval.tv_usec - peasycap->timeval6.tv_usec);
1358 above = (long long int)1000000;
1360 sdr = signed_div(above, below);
1361 above = sdr.quotient;
1362 remainder = (__u32)sdr.remainder;
1364 JOM(8, "video streaming at %3lli.%03i fields per second\n", above, \
1367 peasycap->timeval6 = timeval;
1370 JOM(8, "%i=caches\n", caches);
1373 /*****************************************************************************/
1374 struct signed_div_result
1375 signed_div(long long int above, long long int below)
1377 struct signed_div_result sdr;
1379 if (((0 <= above) && (0 <= below)) || ((0 > above) && (0 > below))) {
1380 sdr.remainder = (unsigned long long int) do_div(above, below);
1381 sdr.quotient = (long long int) above;
1387 sdr.remainder = (unsigned long long int) do_div(above, below);
1388 sdr.quotient = -((long long int) above);
1392 /*****************************************************************************/
1393 /*---------------------------------------------------------------------------*/
1395 * DECIMATION AND COLOURSPACE CONVERSION.
1397 * THIS ROUTINE REQUIRES THAT ALL THE DATA TO BE READ RESIDES ON ONE PAGE
1398 * AND THAT ALL THE DATA TO BE WRITTEN RESIDES ON ONE (DIFFERENT) PAGE.
1399 * THE CALLING ROUTINE MUST ENSURE THAT THIS REQUIREMENT IS MET, AND MUST
1400 * ALSO ENSURE THAT much IS EVEN.
1402 * much BYTES ARE READ, AT LEAST (bytesperpixel * much)/2 BYTES ARE WRITTEN
1403 * IF THERE IS NO DECIMATION, HALF THIS AMOUNT IF THERE IS DECIMATION.
1405 * mask IS ZERO WHEN NO SPECIAL BEHAVIOUR REQUIRED. OTHERWISE IT IS SET THUS:
1406 * 0x03 & mask = number of bytes to be written to cache instead of to
1408 * 0x04 & mask => use argument margin to set the chrominance for last pixel
1409 * 0x08 & mask => do not set the chrominance for last pixel
1411 * YUV to RGB CONVERSION IS (OR SHOULD BE) ITU-R BT 601.
1413 * THERE IS A LOT OF CODE REPETITION IN THIS ROUTINE IN ORDER TO AVOID
1414 * INEFFICIENT SWITCHING INSIDE INNER LOOPS. REARRANGING THE LOGIC TO
1415 * REDUCE CODE LENGTH WILL GENERALLY IMPAIR RUNTIME PERFORMANCE. BEWARE.
1417 /*---------------------------------------------------------------------------*/
1419 redaub(struct easycap *peasycap, void *pad, void *pex, int much, int more, \
1420 __u8 mask, __u8 margin, bool isuy)
1422 static __s32 ay[256], bu[256], rv[256], gu[256], gv[256];
1424 __u8 r, g, b, y, u, v, c, *p2, *p3, *pz, *pr;
1426 bool byteswaporder, decimatepixel, last;
1431 SAM("MISTAKE: much is odd\n");
1434 bytesperpixel = peasycap->bytesperpixel;
1435 byteswaporder = peasycap->byteswaporder;
1436 decimatepixel = peasycap->decimatepixel;
1438 /*---------------------------------------------------------------------------*/
1440 for (j = 0; j < 112; j++) {
1441 s32 = (0xFF00 & (453 * j)) >> 8;
1442 bu[j + 128] = s32; bu[127 - j] = -s32;
1443 s32 = (0xFF00 & (359 * j)) >> 8;
1444 rv[j + 128] = s32; rv[127 - j] = -s32;
1445 s32 = (0xFF00 & (88 * j)) >> 8;
1446 gu[j + 128] = s32; gu[127 - j] = -s32;
1447 s32 = (0xFF00 & (183 * j)) >> 8;
1448 gv[j + 128] = s32; gv[127 - j] = -s32;
1450 for (j = 0; j < 16; j++) {
1451 bu[j] = bu[16]; rv[j] = rv[16];
1452 gu[j] = gu[16]; gv[j] = gv[16];
1454 for (j = 240; j < 256; j++) {
1455 bu[j] = bu[239]; rv[j] = rv[239];
1456 gu[j] = gu[239]; gv[j] = gv[239];
1458 for (j = 16; j < 236; j++)
1460 for (j = 0; j < 16; j++)
1462 for (j = 236; j < 256; j++)
1464 JOM(8, "lookup tables are prepared\n");
1466 pcache = peasycap->pcache;
1468 pcache = &peasycap->cache[0];
1469 /*---------------------------------------------------------------------------*/
1471 * TRANSFER CONTENTS OF CACHE TO THE FRAME BUFFER
1473 /*---------------------------------------------------------------------------*/
1475 SAM("MISTAKE: pcache is NULL\n");
1479 if (pcache != &peasycap->cache[0])
1480 JOM(16, "cache has %i bytes\n", (int)(pcache - &peasycap->cache[0]));
1481 p2 = &peasycap->cache[0];
1482 p3 = (__u8 *)pad - (int)(pcache - &peasycap->cache[0]);
1483 while (p2 < pcache) {
1486 pcache = &peasycap->cache[0];
1488 SAM("MISTAKE: pointer misalignment\n");
1491 /*---------------------------------------------------------------------------*/
1492 rump = (int)(0x03 & mask);
1494 p2 = (__u8 *)pex; pz = p2 + much; pr = p3 + more; last = false;
1503 JOM(16, "%4i=much %4i=more %i=rump\n", much, more, rump);
1505 /*---------------------------------------------------------------------------*/
1506 switch (bytesperpixel) {
1508 if (false == decimatepixel) {
1509 memcpy(pad, pex, (size_t)much);
1510 if (false == byteswaporder)
1511 /*---------------------------------------------------*/
1515 /*---------------------------------------------------*/
1518 /*---------------------------------------------------*/
1522 /*---------------------------------------------------*/
1523 p3 = (__u8 *)pad; pz = p3 + much;
1533 if (false == byteswaporder) {
1534 /*---------------------------------------------------*/
1538 /*---------------------------------------------------*/
1539 p2 = (__u8 *)pex; p3 = (__u8 *)pad; pz = p2 + much;
1542 *(p3 + 1) = *(p2 + 1);
1543 *(p3 + 2) = *(p2 + 2);
1544 *(p3 + 3) = *(p2 + 3);
1549 /*---------------------------------------------------*/
1553 /*---------------------------------------------------*/
1554 p2 = (__u8 *)pex; p3 = (__u8 *)pad; pz = p2 + much;
1558 *(p3 + 2) = *(p2 + 3);
1559 *(p3 + 3) = *(p2 + 2);
1569 if (false == decimatepixel) {
1570 if (false == byteswaporder) {
1571 /*---------------------------------------------------*/
1575 /*---------------------------------------------------*/
1577 if (pr <= (p3 + bytesperpixel))
1582 if ((true == last) && (0x0C & mask)) {
1598 s32 = ay[(int)y] + rv[(int)v];
1599 r = (255 < s32) ? 255 : ((0 > s32) ? \
1601 s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
1602 g = (255 < s32) ? 255 : ((0 > s32) ? \
1604 s32 = ay[(int)y] + bu[(int)u];
1605 b = (255 < s32) ? 255 : ((0 > s32) ? \
1608 if ((true == last) && rump) {
1609 pcache = &peasycap->cache[0];
1610 switch (bytesperpixel - rump) {
1624 SAM("MISTAKE: %i=rump\n", \
1625 bytesperpixel - rump);
1639 p3 += bytesperpixel;
1643 /*---------------------------------------------------*/
1647 /*---------------------------------------------------*/
1649 if (pr <= (p3 + bytesperpixel))
1654 if ((true == last) && (0x0C & mask)) {
1671 s32 = ay[(int)y] + rv[(int)v];
1672 r = (255 < s32) ? 255 : ((0 > s32) ? \
1674 s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
1675 g = (255 < s32) ? 255 : ((0 > s32) ? \
1677 s32 = ay[(int)y] + bu[(int)u];
1678 b = (255 < s32) ? 255 : ((0 > s32) ? \
1681 if ((true == last) && rump) {
1682 pcache = &peasycap->cache[0];
1683 switch (bytesperpixel - rump) {
1697 SAM("MISTAKE: %i=rump\n", \
1698 bytesperpixel - rump);
1712 p3 += bytesperpixel;
1717 if (false == byteswaporder) {
1718 /*---------------------------------------------------*/
1722 /*---------------------------------------------------*/
1724 if (pr <= (p3 + bytesperpixel))
1729 if ((true == last) && (0x0C & mask)) {
1746 s32 = ay[(int)y] + rv[(int)v];
1747 r = (255 < s32) ? 255 : ((0 > s32) ? \
1749 s32 = ay[(int)y] - gu[(int)u] - \
1751 g = (255 < s32) ? 255 : ((0 > s32) ? \
1753 s32 = ay[(int)y] + bu[(int)u];
1754 b = (255 < s32) ? 255 : ((0 > s32) ? \
1757 if ((true == last) && rump) {
1758 pcache = &peasycap->cache[0];
1759 switch (bytesperpixel - rump) {
1775 bytesperpixel - rump);
1785 p3 += bytesperpixel;
1793 /*---------------------------------------------------*/
1797 /*---------------------------------------------------*/
1799 if (pr <= (p3 + bytesperpixel))
1804 if ((true == last) && (0x0C & mask)) {
1822 s32 = ay[(int)y] + rv[(int)v];
1823 r = (255 < s32) ? 255 : ((0 > s32) ? \
1825 s32 = ay[(int)y] - gu[(int)u] - \
1827 g = (255 < s32) ? 255 : ((0 > s32) ? \
1829 s32 = ay[(int)y] + bu[(int)u];
1830 b = (255 < s32) ? 255 : ((0 > s32) ? \
1833 if ((true == last) && rump) {
1834 pcache = &peasycap->cache[0];
1835 switch (bytesperpixel - rump) {
1851 bytesperpixel - rump);
1861 p3 += bytesperpixel;
1874 if (false == decimatepixel) {
1875 if (false == byteswaporder) {
1876 /*---------------------------------------------------*/
1880 /*---------------------------------------------------*/
1882 if (pr <= (p3 + bytesperpixel))
1887 if ((true == last) && (0x0C & mask)) {
1903 s32 = ay[(int)y] + rv[(int)v];
1904 r = (255 < s32) ? 255 : ((0 > s32) ? \
1906 s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
1907 g = (255 < s32) ? 255 : ((0 > s32) ? \
1909 s32 = ay[(int)y] + bu[(int)u];
1910 b = (255 < s32) ? 255 : ((0 > s32) ? \
1913 if ((true == last) && rump) {
1914 pcache = &peasycap->cache[0];
1915 switch (bytesperpixel - rump) {
1938 SAM("MISTAKE: %i=rump\n", \
1939 bytesperpixel - rump);
1954 p3 += bytesperpixel;
1958 /*---------------------------------------------------*/
1962 /*---------------------------------------------------*/
1964 if (pr <= (p3 + bytesperpixel))
1969 if ((true == last) && (0x0C & mask)) {
1985 s32 = ay[(int)y] + rv[(int)v];
1986 r = (255 < s32) ? 255 : ((0 > s32) ? \
1988 s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
1989 g = (255 < s32) ? 255 : ((0 > s32) ? \
1991 s32 = ay[(int)y] + bu[(int)u];
1992 b = (255 < s32) ? 255 : ((0 > s32) ? \
1995 if ((true == last) && rump) {
1996 pcache = &peasycap->cache[0];
1997 switch (bytesperpixel - rump) {
2020 SAM("MISTAKE: %i=rump\n", \
2021 bytesperpixel - rump);
2036 p3 += bytesperpixel;
2041 if (false == byteswaporder) {
2042 /*---------------------------------------------------*/
2046 /*---------------------------------------------------*/
2048 if (pr <= (p3 + bytesperpixel))
2053 if ((true == last) && (0x0C & mask)) {
2071 s32 = ay[(int)y] + rv[(int)v];
2072 r = (255 < s32) ? 255 : ((0 > s32) ? \
2074 s32 = ay[(int)y] - gu[(int)u] - \
2076 g = (255 < s32) ? 255 : ((0 > s32) ? \
2078 s32 = ay[(int)y] + bu[(int)u];
2079 b = (255 < s32) ? 255 : ((0 > s32) ? \
2082 if ((true == last) && rump) {
2083 pcache = &peasycap->cache[0];
2084 switch (bytesperpixel - rump) {
2121 p3 += bytesperpixel;
2128 /*---------------------------------------------------*/
2132 /*---------------------------------------------------*/
2134 if (pr <= (p3 + bytesperpixel))
2139 if ((true == last) && (0x0C & mask)) {
2156 s32 = ay[(int)y] + rv[(int)v];
2157 r = (255 < s32) ? 255 : ((0 > s32) ? \
2159 s32 = ay[(int)y] - gu[(int)u] - \
2161 g = (255 < s32) ? 255 : ((0 > s32) ? \
2163 s32 = ay[(int)y] + bu[(int)u];
2164 b = (255 < s32) ? 255 : ((0 > s32) ? \
2167 if ((true == last) && rump) {
2168 pcache = &peasycap->cache[0];
2169 switch (bytesperpixel - rump) {
2194 bytesperpixel - rump);
2205 p3 += bytesperpixel;
2216 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel);
2222 /*****************************************************************************/
2223 /*---------------------------------------------------------------------------*/
2225 * SEE CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGES 430-434
2227 /*---------------------------------------------------------------------------*/
2228 int easycap_mmap(struct file *file, struct vm_area_struct *pvma)
2233 pvma->vm_ops = &easycap_vm_ops;
2234 pvma->vm_flags |= VM_RESERVED;
2236 pvma->vm_private_data = file->private_data;
2237 easycap_vma_open(pvma);
2240 /*****************************************************************************/
2242 easycap_vma_open(struct vm_area_struct *pvma)
2244 struct easycap *peasycap;
2246 peasycap = pvma->vm_private_data;
2247 if (NULL != peasycap)
2248 peasycap->vma_many++;
2250 JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many);
2254 /*****************************************************************************/
2256 easycap_vma_close(struct vm_area_struct *pvma)
2258 struct easycap *peasycap;
2260 peasycap = pvma->vm_private_data;
2261 if (NULL != peasycap) {
2262 peasycap->vma_many--;
2263 JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many);
2267 /*****************************************************************************/
2269 easycap_vma_fault(struct vm_area_struct *pvma, struct vm_fault *pvmf)
2274 struct easycap *peasycap;
2276 retcode = VM_FAULT_NOPAGE;
2277 pbuf = (void *)NULL;
2278 page = (struct page *)NULL;
2281 SAY("pvma is NULL\n");
2285 SAY("pvmf is NULL\n");
2289 k = (pvmf->pgoff) / (FRAME_BUFFER_SIZE/PAGE_SIZE);
2290 m = (pvmf->pgoff) % (FRAME_BUFFER_SIZE/PAGE_SIZE);
2293 JOT(4, "%4i=k, %4i=m\n", k, m);
2295 JOT(16, "%4i=k, %4i=m\n", k, m);
2297 if ((0 > k) || (FRAME_BUFFER_MANY <= k)) {
2298 SAY("ERROR: buffer index %i out of range\n", k);
2301 if ((0 > m) || (FRAME_BUFFER_SIZE/PAGE_SIZE <= m)) {
2302 SAY("ERROR: page number %i out of range\n", m);
2305 peasycap = pvma->vm_private_data;
2306 if (NULL == peasycap) {
2307 SAY("ERROR: peasycap is NULL\n");
2310 /*---------------------------------------------------------------------------*/
2311 pbuf = peasycap->frame_buffer[k][m].pgo;
2313 SAM("ERROR: pbuf is NULL\n");
2316 page = virt_to_page(pbuf);
2318 SAM("ERROR: page is NULL\n");
2322 /*---------------------------------------------------------------------------*/
2325 SAM("ERROR: page is NULL after get_page(page)\n");
2328 retcode = VM_FAULT_MINOR;
2332 /*****************************************************************************/
2333 /*---------------------------------------------------------------------------*/
2335 * ON COMPLETION OF A VIDEO URB ITS DATA IS COPIED TO THE FIELD BUFFERS
2336 * PROVIDED peasycap->video_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
2337 * IT IS RESUBMITTED PROVIDED peasycap->video_isoc_streaming IS NOT ZERO.
2339 * THIS FUNCTION IS AN INTERRUPT SERVICE ROUTINE AND MUST NOT SLEEP.
2341 * INFORMATION ABOUT THE VALIDITY OF THE CONTENTS OF THE FIELD BUFFER ARE
2342 * STORED IN THE TWO-BYTE STATUS PARAMETER
2343 * peasycap->field_buffer[peasycap->field_fill][0].kount
2344 * NOTICE THAT THE INFORMATION IS STORED ONLY WITH PAGE 0 OF THE FIELD BUFFER.
2346 * THE LOWER BYTE CONTAINS THE FIELD PARITY BYTE FURNISHED BY THE SAA7113H
2349 * THE UPPER BYTE IS ZERO IF NO PROBLEMS, OTHERWISE:
2350 * 0 != (kount & 0x8000) => AT LEAST ONE URB COMPLETED WITH ERRORS
2351 * 0 != (kount & 0x4000) => BUFFER HAS TOO MUCH DATA
2352 * 0 != (kount & 0x2000) => BUFFER HAS NOT ENOUGH DATA
2353 * 0 != (kount & 0x0400) => RESERVED
2354 * 0 != (kount & 0x0200) => FIELD BUFFER NOT YET CHECKED
2355 * 0 != (kount & 0x0100) => BUFFER HAS TWO EXTRA BYTES - WHY?
2357 /*---------------------------------------------------------------------------*/
2359 easycap_complete(struct urb *purb)
2361 struct easycap *peasycap;
2362 struct data_buffer *pfield_buffer;
2364 int i, more, much, leap, rc, last;
2365 int videofieldamount;
2366 unsigned int override;
2367 int framestatus, framelength, frameactual, frameoffset;
2371 SAY("ERROR: easycap_complete(): purb is NULL\n");
2374 peasycap = purb->context;
2375 if (NULL == peasycap) {
2376 SAY("ERROR: easycap_complete(): peasycap is NULL\n");
2380 if (peasycap->video_eof)
2383 for (i = 0; i < VIDEO_ISOC_BUFFER_MANY; i++)
2384 if (purb->transfer_buffer == peasycap->video_isoc_buffer[i].pgo)
2386 JOM(16, "%2i=urb\n", i);
2387 last = peasycap->video_isoc_sequence;
2388 if ((((VIDEO_ISOC_BUFFER_MANY - 1) == last) && \
2390 (((VIDEO_ISOC_BUFFER_MANY - 1) != last) && \
2391 ((last + 1) != i))) {
2392 SAM("ERROR: out-of-order urbs %i,%i ... continuing\n", last, i);
2394 peasycap->video_isoc_sequence = i;
2396 if (peasycap->video_idle) {
2397 JOM(16, "%i=video_idle %i=video_isoc_streaming\n", \
2398 peasycap->video_idle, peasycap->video_isoc_streaming);
2399 if (peasycap->video_isoc_streaming) {
2400 rc = usb_submit_urb(purb, GFP_ATOMIC);
2402 SAM("ERROR: while %i=video_idle, " \
2403 "usb_submit_urb() failed with rc:\n", \
2404 peasycap->video_idle);
2443 SAM("0x%08X\n", rc);
2452 /*---------------------------------------------------------------------------*/
2453 if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2454 SAM("ERROR: bad peasycap->field_fill\n");
2458 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
2459 JOM(8, "urb status -ESHUTDOWN or -ENOENT\n");
2463 (peasycap->field_buffer[peasycap->field_fill][0].kount) |= 0x8000 ;
2464 SAM("ERROR: bad urb status:\n");
2465 switch (purb->status) {
2466 case -EINPROGRESS: {
2467 SAM("-EINPROGRESS\n"); break;
2470 SAM("-ENOSR\n"); break;
2473 SAM("-EPIPE\n"); break;
2476 SAM("-EOVERFLOW\n"); break;
2479 SAM("-EPROTO\n"); break;
2482 SAM("-EILSEQ\n"); break;
2485 SAM("-ETIMEDOUT\n"); break;
2488 SAM("-EMSGSIZE\n"); break;
2491 SAM("-EOPNOTSUPP\n"); break;
2493 case -EPFNOSUPPORT: {
2494 SAM("-EPFNOSUPPORT\n"); break;
2496 case -EAFNOSUPPORT: {
2497 SAM("-EAFNOSUPPORT\n"); break;
2500 SAM("-EADDRINUSE\n"); break;
2502 case -EADDRNOTAVAIL: {
2503 SAM("-EADDRNOTAVAIL\n"); break;
2506 SAM("-ENOBUFS\n"); break;
2509 SAM("-EISCONN\n"); break;
2512 SAM("-ENOTCONN\n"); break;
2515 SAM("-ESHUTDOWN\n"); break;
2518 SAM("-ENOENT\n"); break;
2521 SAM("-ECONNRESET\n"); break;
2524 SAM("ENOSPC\n"); break;
2527 SAM("unknown error code 0x%08X\n", purb->status); break;
2530 /*---------------------------------------------------------------------------*/
2532 for (i = 0; i < purb->number_of_packets; i++) {
2533 if (0 != purb->iso_frame_desc[i].status) {
2534 (peasycap->field_buffer\
2535 [peasycap->field_fill][0].kount) |= 0x8000 ;
2536 switch (purb->iso_frame_desc[i].status) {
2538 strcpy(&errbuf[0], "OK"); break;
2541 strcpy(&errbuf[0], "-ENOENT"); break;
2543 case -EINPROGRESS: {
2544 strcpy(&errbuf[0], "-EINPROGRESS"); break;
2547 strcpy(&errbuf[0], "-EPROTO"); break;
2550 strcpy(&errbuf[0], "-EILSEQ"); break;
2553 strcpy(&errbuf[0], "-ETIME"); break;
2556 strcpy(&errbuf[0], "-ETIMEDOUT"); break;
2559 strcpy(&errbuf[0], "-EPIPE"); break;
2562 strcpy(&errbuf[0], "-ECOMM"); break;
2565 strcpy(&errbuf[0], "-ENOSR"); break;
2568 strcpy(&errbuf[0], "-EOVERFLOW"); break;
2571 strcpy(&errbuf[0], "-EREMOTEIO"); break;
2574 strcpy(&errbuf[0], "-ENODEV"); break;
2577 strcpy(&errbuf[0], "-EXDEV"); break;
2580 strcpy(&errbuf[0], "-EINVAL"); break;
2583 strcpy(&errbuf[0], "-ECONNRESET"); break;
2586 SAM("ENOSPC\n"); break;
2589 strcpy(&errbuf[0], "-ESHUTDOWN"); break;
2592 strcpy(&errbuf[0], "unknown error"); break;
2596 framestatus = purb->iso_frame_desc[i].status;
2597 framelength = purb->iso_frame_desc[i].length;
2598 frameactual = purb->iso_frame_desc[i].actual_length;
2599 frameoffset = purb->iso_frame_desc[i].offset;
2601 JOM(16, "frame[%2i]:" \
2606 i, framestatus, frameactual, framelength, frameoffset);
2607 if (!purb->iso_frame_desc[i].status) {
2608 more = purb->iso_frame_desc[i].actual_length;
2609 pfield_buffer = &peasycap->field_buffer\
2610 [peasycap->field_fill][peasycap->field_page];
2611 videofieldamount = (peasycap->field_page * \
2613 (int)(pfield_buffer->pto - pfield_buffer->pgo);
2615 peasycap->video_mt++;
2617 if (peasycap->video_mt) {
2618 JOM(8, "%4i empty video urb frames\n", \
2619 peasycap->video_mt);
2620 peasycap->video_mt = 0;
2622 if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2623 SAM("ERROR: bad peasycap->field_fill\n");
2626 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2627 peasycap->field_page) {
2628 SAM("ERROR: bad peasycap->field_page\n");
2631 pfield_buffer = &peasycap->field_buffer\
2632 [peasycap->field_fill][peasycap->field_page];
2633 pu = (__u8 *)(purb->transfer_buffer + \
2634 purb->iso_frame_desc[i].offset);
2639 /*--------------------------------------------------------------------------*/
2641 * EIGHT-BYTE END-OF-VIDEOFIELD MARKER.
2642 * NOTE: A SUCCESSION OF URB FRAMES FOLLOWING THIS ARE EMPTY,
2643 * CORRESPONDING TO THE FIELD FLYBACK (VERTICAL BLANKING) PERIOD.
2645 * PROVIDED THE FIELD BUFFER CONTAINS GOOD DATA AS INDICATED BY A ZERO UPPER
2647 * peasycap->field_buffer[peasycap->field_fill][0].kount
2648 * THE CONTENTS OF THE FIELD BUFFER ARE OFFERED TO dqbuf(), field_read IS
2649 * UPDATED AND field_fill IS BUMPED. IF THE FIELD BUFFER CONTAINS BAD DATA
2650 * NOTHING IS OFFERED TO dqbuf().
2652 * THE DECISION ON WHETHER THE PARITY OF THE OFFERED FIELD BUFFER IS RIGHT
2653 * RESTS WITH dqbuf().
2655 /*---------------------------------------------------------------------------*/
2656 if ((8 == more) || override) {
2657 if (videofieldamount > \
2658 peasycap->videofieldamount) {
2659 if (2 == videofieldamount - \
2662 (peasycap->field_buffer\
2663 [peasycap->field_fill]\
2664 [0].kount) |= 0x0100;
2666 (peasycap->field_buffer\
2667 [peasycap->field_fill]\
2668 [0].kount) |= 0x4000;
2669 } else if (videofieldamount < \
2672 (peasycap->field_buffer\
2673 [peasycap->field_fill]\
2674 [0].kount) |= 0x2000;
2676 if (!(0xFF00 & peasycap->field_buffer\
2677 [peasycap->field_fill]\
2679 (peasycap->video_junk)--;
2680 if (-16 > peasycap->video_junk)
2681 peasycap->video_junk = -16;
2682 peasycap->field_read = \
2686 if (FIELD_BUFFER_MANY <= \
2687 peasycap->field_fill)
2688 peasycap->field_fill = 0;
2689 peasycap->field_page = 0;
2690 pfield_buffer = &peasycap->\
2692 [peasycap->field_fill]\
2693 [peasycap->field_page];
2694 pfield_buffer->pto = \
2697 JOM(8, "bumped to: %i=peasycap->" \
2698 "field_fill %i=parity\n", \
2699 peasycap->field_fill, \
2700 0x00FF & pfield_buffer->kount);
2701 JOM(8, "field buffer %i has %i " \
2702 "bytes fit to be read\n", \
2703 peasycap->field_read, \
2705 JOM(8, "wakeup call to wq_video, " \
2706 "%i=field_read %i=field_fill "\
2708 peasycap->field_read, \
2709 peasycap->field_fill, \
2710 0x00FF & peasycap->\
2711 field_buffer[peasycap->\
2712 field_read][0].kount);
2713 wake_up_interruptible(&(peasycap->\
2715 do_gettimeofday(&peasycap->timeval7);
2717 peasycap->video_junk++;
2718 JOM(8, "field buffer %i had %i " \
2719 "bytes, now discarded\n", \
2720 peasycap->field_fill, \
2723 (peasycap->field_fill)++;
2725 if (FIELD_BUFFER_MANY <= \
2726 peasycap->field_fill)
2727 peasycap->field_fill = 0;
2728 peasycap->field_page = 0;
2730 &peasycap->field_buffer\
2731 [peasycap->field_fill]\
2732 [peasycap->field_page];
2733 pfield_buffer->pto = \
2736 JOM(8, "bumped to: %i=peasycap->" \
2737 "field_fill %i=parity\n", \
2738 peasycap->field_fill, \
2739 0x00FF & pfield_buffer->kount);
2742 JOM(8, "end-of-field: received " \
2743 "parity byte 0x%02X\n", \
2746 pfield_buffer->kount = 0x0000;
2748 pfield_buffer->kount = 0x0001;
2749 JOM(8, "end-of-field: 0x%02X=kount\n",\
2750 0xFF & pfield_buffer->kount);
2753 /*---------------------------------------------------------------------------*/
2755 * COPY more BYTES FROM ISOC BUFFER TO FIELD BUFFER
2757 /*---------------------------------------------------------------------------*/
2761 if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2762 SAM("ERROR: bad peasycap->field_fill\n");
2765 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2766 peasycap->field_page) {
2767 SAM("ERROR: bad peasycap->field_page\n");
2770 pfield_buffer = &peasycap->field_buffer\
2771 [peasycap->field_fill][peasycap->field_page];
2773 pfield_buffer = &peasycap->field_buffer\
2774 [peasycap->field_fill]\
2775 [peasycap->field_page];
2776 if (PAGE_SIZE < (pfield_buffer->pto - \
2777 pfield_buffer->pgo)) {
2778 SAM("ERROR: bad pfield_buffer->pto\n");
2781 if (PAGE_SIZE == (pfield_buffer->pto - \
2782 pfield_buffer->pgo)) {
2783 (peasycap->field_page)++;
2784 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2785 peasycap->field_page) {
2786 JOM(16, "wrapping peasycap->" \
2788 peasycap->field_page = 0;
2790 pfield_buffer = &peasycap->\
2792 [peasycap->field_fill]\
2793 [peasycap->field_page];
2794 pfield_buffer->pto = \
2798 much = PAGE_SIZE - (int)(pfield_buffer->pto - \
2799 pfield_buffer->pgo);
2803 memcpy(pfield_buffer->pto, pu, much);
2805 (pfield_buffer->pto) += much;
2812 /*---------------------------------------------------------------------------*/
2814 * RESUBMIT THIS URB, UNLESS A SEVERE PERSISTENT ERROR CONDITION EXISTS.
2816 * IF THE WAIT QUEUES ARE NOT CLEARED IN RESPONSE TO AN ERROR CONDITION
2817 * THE USERSPACE PROGRAM, E.G. mplayer, MAY HANG ON EXIT. BEWARE.
2819 /*---------------------------------------------------------------------------*/
2820 if (VIDEO_ISOC_BUFFER_MANY <= peasycap->video_junk) {
2821 SAM("easycap driver shutting down on condition green\n");
2822 peasycap->video_eof = 1;
2823 peasycap->audio_eof = 1;
2824 peasycap->video_junk = -VIDEO_ISOC_BUFFER_MANY;
2825 wake_up_interruptible(&(peasycap->wq_video));
2826 wake_up_interruptible(&(peasycap->wq_audio));
2829 if (peasycap->video_isoc_streaming) {
2830 rc = usb_submit_urb(purb, GFP_ATOMIC);
2832 SAM("ERROR: while %i=video_idle, usb_submit_urb() failed " \
2833 "with rc:\n", peasycap->video_idle);
2836 SAM("ENOMEM\n"); break;
2839 SAM("ENODEV\n"); break;
2842 SAM("ENXIO\n"); break;
2845 SAM("EINVAL\n"); break;
2848 SAM("EAGAIN\n"); break;
2851 SAM("EFBIG\n"); break;
2854 SAM("EPIPE\n"); break;
2857 SAM("EMSGSIZE\n"); break;
2860 SAM("ENOSPC\n"); break;
2863 SAM("0x%08X\n", rc); break;
2870 /*****************************************************************************/
2871 /*---------------------------------------------------------------------------*/
2877 * THIS FUNCTION ASSUMES THAT, ON EACH AND EVERY OCCASION THAT THE DEVICE IS
2878 * PHYSICALLY PLUGGED IN, INTERFACE 0 IS PROBED FIRST.
2879 * IF THIS IS NOT TRUE, THERE IS THE POSSIBILITY OF AN Oops.
2881 * THIS HAS NEVER BEEN A PROBLEM IN PRACTICE, BUT SOMETHING SEEMS WRONG HERE.
2883 /*---------------------------------------------------------------------------*/
2885 easycap_usb_probe(struct usb_interface *pusb_interface, \
2886 const struct usb_device_id *id)
2888 struct usb_device *pusb_device, *pusb_device1;
2889 struct usb_host_interface *pusb_host_interface;
2890 struct usb_endpoint_descriptor *pepd;
2891 struct usb_interface_descriptor *pusb_interface_descriptor;
2892 struct usb_interface_assoc_descriptor *pusb_interface_assoc_descriptor;
2894 struct easycap *peasycap;
2895 struct data_urb *pdata_urb;
2896 size_t wMaxPacketSize;
2897 int ISOCwMaxPacketSize;
2898 int BULKwMaxPacketSize;
2899 int INTwMaxPacketSize;
2900 int CTRLwMaxPacketSize;
2901 __u8 bEndpointAddress;
2902 __u8 ISOCbEndpointAddress;
2903 __u8 INTbEndpointAddress;
2904 int isin, i, j, k, m, rc;
2905 __u8 bInterfaceNumber;
2906 __u8 bInterfaceClass;
2907 __u8 bInterfaceSubClass;
2909 int okalt[8], isokalt;
2915 peasycap = (struct easycap *)NULL;
2917 if ((struct usb_interface *)NULL == pusb_interface) {
2918 SAY("ERROR: pusb_interface is NULL\n");
2921 /*---------------------------------------------------------------------------*/
2923 * GET POINTER TO STRUCTURE usb_device
2925 /*---------------------------------------------------------------------------*/
2926 pusb_device1 = container_of(pusb_interface->dev.parent, \
2927 struct usb_device, dev);
2928 if ((struct usb_device *)NULL == pusb_device1) {
2929 SAY("ERROR: pusb_device1 is NULL\n");
2932 pusb_device = usb_get_dev(pusb_device1);
2933 if ((struct usb_device *)NULL == pusb_device) {
2934 SAY("ERROR: pusb_device is NULL\n");
2937 if ((unsigned long int)pusb_device1 != (unsigned long int)pusb_device) {
2938 JOT(4, "ERROR: pusb_device1 != pusb_device\n");
2942 JOT(4, "bNumConfigurations=%i\n", pusb_device->descriptor.bNumConfigurations);
2944 /*---------------------------------------------------------------------------*/
2945 pusb_host_interface = pusb_interface->cur_altsetting;
2946 if (NULL == pusb_host_interface) {
2947 SAY("ERROR: pusb_host_interface is NULL\n");
2950 pusb_interface_descriptor = &(pusb_host_interface->desc);
2951 if (NULL == pusb_interface_descriptor) {
2952 SAY("ERROR: pusb_interface_descriptor is NULL\n");
2955 /*---------------------------------------------------------------------------*/
2957 * GET PROPERTIES OF PROBED INTERFACE
2959 /*---------------------------------------------------------------------------*/
2960 bInterfaceNumber = pusb_interface_descriptor->bInterfaceNumber;
2961 bInterfaceClass = pusb_interface_descriptor->bInterfaceClass;
2962 bInterfaceSubClass = pusb_interface_descriptor->bInterfaceSubClass;
2964 JOT(4, "intf[%i]: pusb_interface->num_altsetting=%i\n", \
2965 bInterfaceNumber, pusb_interface->num_altsetting);
2966 JOT(4, "intf[%i]: pusb_interface->cur_altsetting - " \
2967 "pusb_interface->altsetting=%li\n", bInterfaceNumber, \
2968 (long int)(pusb_interface->cur_altsetting - \
2969 pusb_interface->altsetting));
2970 switch (bInterfaceClass) {
2971 case USB_CLASS_AUDIO: {
2972 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_AUDIO\n", \
2973 bInterfaceNumber, bInterfaceClass); break;
2975 case USB_CLASS_VIDEO: {
2976 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_VIDEO\n", \
2977 bInterfaceNumber, bInterfaceClass); break;
2979 case USB_CLASS_VENDOR_SPEC: {
2980 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_VENDOR_SPEC\n", \
2981 bInterfaceNumber, bInterfaceClass); break;
2986 switch (bInterfaceSubClass) {
2988 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=AUDIOCONTROL\n", \
2989 bInterfaceNumber, bInterfaceSubClass); break;
2992 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=AUDIOSTREAMING\n", \
2993 bInterfaceNumber, bInterfaceSubClass); break;
2996 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=MIDISTREAMING\n", \
2997 bInterfaceNumber, bInterfaceSubClass); break;
3002 /*---------------------------------------------------------------------------*/
3003 pusb_interface_assoc_descriptor = pusb_interface->intf_assoc;
3004 if (NULL != pusb_interface_assoc_descriptor) {
3005 JOT(4, "intf[%i]: bFirstInterface=0x%02X bInterfaceCount=0x%02X\n", \
3007 pusb_interface_assoc_descriptor->bFirstInterface, \
3008 pusb_interface_assoc_descriptor->bInterfaceCount);
3010 JOT(4, "intf[%i]: pusb_interface_assoc_descriptor is NULL\n", \
3013 /*---------------------------------------------------------------------------*/
3015 * A NEW struct easycap IS ALWAYS ALLOCATED WHEN INTERFACE 0 IS PROBED.
3016 * IT IS NOT POSSIBLE HERE TO FREE ANY EXISTING struct easycap. THIS
3017 * SHOULD HAVE BEEN DONE BY easycap_delete() WHEN THE EasyCAP WAS
3018 * PHYSICALLY UNPLUGGED.
3020 * THE POINTER peasycap TO THE struct easycap IS REMEMBERED WHEN
3021 * INTERFACES 1 AND 2 ARE PROBED.
3023 * IF TWO EasyCAPs ARE PLUGGED IN NEARLY SIMULTANEOUSLY THERE WILL
3024 * BE TROUBLE. BEWARE.
3026 /*---------------------------------------------------------------------------*/
3027 if (0 == bInterfaceNumber) {
3028 peasycap = kzalloc(sizeof(struct easycap), GFP_KERNEL);
3029 if (NULL == peasycap) {
3030 SAY("ERROR: Could not allocate peasycap\n");
3033 SAM("allocated 0x%08lX=peasycap\n", (unsigned long int) peasycap);
3034 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3035 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
3036 SAM("where 0x%08lX=&peasycap->video_device\n", \
3037 (unsigned long int) &peasycap->video_device);
3038 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
3039 SAM("and 0x%08lX=&peasycap->v4l2_device\n", \
3040 (unsigned long int) &peasycap->v4l2_device);
3041 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
3042 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
3043 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3044 /*---------------------------------------------------------------------------*/
3046 * PERFORM URGENT INTIALIZATIONS ...
3048 /*---------------------------------------------------------------------------*/
3049 kref_init(&peasycap->kref);
3050 JOM(8, "intf[%i]: after kref_init(..._video) " \
3051 "%i=peasycap->kref.refcount.counter\n", \
3052 bInterfaceNumber, peasycap->kref.refcount.counter);
3054 init_waitqueue_head(&peasycap->wq_video);
3055 init_waitqueue_head(&peasycap->wq_audio);
3057 for (dongle_this = 0; dongle_this < DONGLE_MANY; dongle_this++) {
3058 if ((struct easycap *)NULL == peasycap_dongle[dongle_this]) {
3059 peasycap_dongle[dongle_this] = peasycap;
3060 JOM(8, "intf[%i]: peasycap-->easycap" \
3061 "_dongle[%i].peasycap\n", \
3062 bInterfaceNumber, dongle_this);
3066 if (DONGLE_MANY <= dongle_this) {
3067 SAM("ERROR: too many dongles\n");
3071 peasycap->allocation_video_struct = sizeof(struct easycap);
3072 peasycap->allocation_video_page = 0;
3073 peasycap->allocation_video_urb = 0;
3074 peasycap->allocation_audio_struct = 0;
3075 peasycap->allocation_audio_page = 0;
3076 peasycap->allocation_audio_urb = 0;
3078 /*---------------------------------------------------------------------------*/
3080 * ... AND FURTHER INITIALIZE THE STRUCTURE
3082 /*---------------------------------------------------------------------------*/
3083 peasycap->pusb_device = pusb_device;
3084 peasycap->pusb_interface = pusb_interface;
3087 peasycap->microphone = false;
3089 peasycap->video_interface = -1;
3090 peasycap->video_altsetting_on = -1;
3091 peasycap->video_altsetting_off = -1;
3092 peasycap->video_endpointnumber = -1;
3093 peasycap->video_isoc_maxframesize = -1;
3094 peasycap->video_isoc_buffer_size = -1;
3096 peasycap->audio_interface = -1;
3097 peasycap->audio_altsetting_on = -1;
3098 peasycap->audio_altsetting_off = -1;
3099 peasycap->audio_endpointnumber = -1;
3100 peasycap->audio_isoc_maxframesize = -1;
3101 peasycap->audio_isoc_buffer_size = -1;
3103 peasycap->frame_buffer_many = FRAME_BUFFER_MANY;
3105 peasycap->offerfields = 0;
3106 /*---------------------------------------------------------------------------*/
3108 * DYNAMICALLY FILL IN THE AVAILABLE FORMATS.
3110 /*---------------------------------------------------------------------------*/
3111 rc = fillin_formats();
3113 SAM("ERROR: fillin_formats() returned %i\n", rc);
3116 JOM(4, "%i formats available\n", rc);
3117 JOM(4, "finished initialization\n");
3119 /*---------------------------------------------------------------------------*/
3121 * FOR INTERFACES 1 AND 2 THE POINTER peasycap IS OBTAINED BY ASSUMING
3122 * THAT dongle_this HAS NOT CHANGED SINCE INTERFACE 0 WAS PROBED. IF
3123 * THIS IS NOT THE CASE, FOR EXAMPLE WHEN TWO EASYCAPs ARE PLUGGED IN
3124 * SIMULTANEOUSLY, THERE WILL BE VERY SERIOUS TROUBLE.
3126 /*---------------------------------------------------------------------------*/
3127 if ((0 > dongle_this) || (DONGLE_MANY <= dongle_this)) {
3128 SAY("ERROR: bad dongle count\n");
3131 peasycap = peasycap_dongle[dongle_this];
3132 JOT(8, "intf[%i]: peasycap_dongle[%i]-->peasycap\n", \
3133 bInterfaceNumber, dongle_this);
3135 if ((struct easycap *)NULL == peasycap) {
3136 SAY("ERROR: peasycap is NULL when probing interface %i\n", \
3141 /*---------------------------------------------------------------------------*/
3142 if ((USB_CLASS_VIDEO == bInterfaceClass) || \
3143 (USB_CLASS_VENDOR_SPEC == bInterfaceClass)) {
3144 if (-1 == peasycap->video_interface) {
3145 peasycap->video_interface = bInterfaceNumber;
3146 JOM(4, "setting peasycap->video_interface=%i\n", \
3147 peasycap->video_interface);
3149 if (peasycap->video_interface != bInterfaceNumber) {
3150 SAM("ERROR: attempting to reset " \
3151 "peasycap->video_interface\n");
3152 SAM("...... continuing with " \
3153 "%i=peasycap->video_interface\n", \
3154 peasycap->video_interface);
3157 } else if ((USB_CLASS_AUDIO == bInterfaceClass) && \
3158 (0x02 == bInterfaceSubClass)) {
3159 if (-1 == peasycap->audio_interface) {
3160 peasycap->audio_interface = bInterfaceNumber;
3161 JOM(4, "setting peasycap->audio_interface=%i\n", \
3162 peasycap->audio_interface);
3164 if (peasycap->audio_interface != bInterfaceNumber) {
3165 SAM("ERROR: attempting to reset " \
3166 "peasycap->audio_interface\n");
3167 SAM("...... continuing with " \
3168 "%i=peasycap->audio_interface\n", \
3169 peasycap->audio_interface);
3173 /*---------------------------------------------------------------------------*/
3175 * INVESTIGATE ALL ALTSETTINGS.
3176 * DONE IN DETAIL BECAUSE USB DEVICE 05e1:0408 HAS DISPARATE INCARNATIONS.
3178 /*---------------------------------------------------------------------------*/
3180 for (i = 0; i < pusb_interface->num_altsetting; i++) {
3181 pusb_host_interface = &(pusb_interface->altsetting[i]);
3182 if ((struct usb_host_interface *)NULL == pusb_host_interface) {
3183 SAM("ERROR: pusb_host_interface is NULL\n");
3186 pusb_interface_descriptor = &(pusb_host_interface->desc);
3187 if ((struct usb_interface_descriptor *)NULL == \
3188 pusb_interface_descriptor) {
3189 SAM("ERROR: pusb_interface_descriptor is NULL\n");
3193 JOM(4, "intf[%i]alt[%i]: desc.bDescriptorType=0x%02X\n", \
3194 bInterfaceNumber, i, pusb_interface_descriptor->bDescriptorType);
3195 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceNumber=0x%02X\n", \
3196 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceNumber);
3197 JOM(4, "intf[%i]alt[%i]: desc.bAlternateSetting=0x%02X\n", \
3198 bInterfaceNumber, i, pusb_interface_descriptor->bAlternateSetting);
3199 JOM(4, "intf[%i]alt[%i]: desc.bNumEndpoints=0x%02X\n", \
3200 bInterfaceNumber, i, pusb_interface_descriptor->bNumEndpoints);
3201 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceClass=0x%02X\n", \
3202 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceClass);
3203 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceSubClass=0x%02X\n", \
3204 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceSubClass);
3205 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceProtocol=0x%02X\n", \
3206 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceProtocol);
3207 JOM(4, "intf[%i]alt[%i]: desc.iInterface=0x%02X\n", \
3208 bInterfaceNumber, i, pusb_interface_descriptor->iInterface);
3210 ISOCwMaxPacketSize = -1;
3211 BULKwMaxPacketSize = -1;
3212 INTwMaxPacketSize = -1;
3213 CTRLwMaxPacketSize = -1;
3214 ISOCbEndpointAddress = 0;
3215 INTbEndpointAddress = 0;
3217 if (0 == pusb_interface_descriptor->bNumEndpoints)
3218 JOM(4, "intf[%i]alt[%i] has no endpoints\n", \
3219 bInterfaceNumber, i);
3220 /*---------------------------------------------------------------------------*/
3221 for (j = 0; j < pusb_interface_descriptor->bNumEndpoints; j++) {
3222 pepd = &(pusb_host_interface->endpoint[j].desc);
3223 if ((struct usb_endpoint_descriptor *)NULL == pepd) {
3224 SAM("ERROR: pepd is NULL.\n");
3225 SAM("...... skipping\n");
3228 wMaxPacketSize = le16_to_cpu(pepd->wMaxPacketSize);
3229 bEndpointAddress = pepd->bEndpointAddress;
3231 JOM(4, "intf[%i]alt[%i]end[%i]: bEndpointAddress=0x%X\n", \
3232 bInterfaceNumber, i, j, \
3233 pepd->bEndpointAddress);
3234 JOM(4, "intf[%i]alt[%i]end[%i]: bmAttributes=0x%X\n", \
3235 bInterfaceNumber, i, j, \
3236 pepd->bmAttributes);
3237 JOM(4, "intf[%i]alt[%i]end[%i]: wMaxPacketSize=%i\n", \
3238 bInterfaceNumber, i, j, \
3239 pepd->wMaxPacketSize);
3240 JOM(4, "intf[%i]alt[%i]end[%i]: bInterval=%i\n",
3241 bInterfaceNumber, i, j, \
3244 if (pepd->bEndpointAddress & USB_DIR_IN) {
3245 JOM(4, "intf[%i]alt[%i]end[%i] is an IN endpoint\n",\
3246 bInterfaceNumber, i, j);
3249 JOM(4, "intf[%i]alt[%i]end[%i] is an OUT endpoint\n",\
3250 bInterfaceNumber, i, j);
3251 SAM("ERROR: OUT endpoint unexpected\n");
3252 SAM("...... continuing\n");
3255 if ((pepd->bmAttributes & \
3256 USB_ENDPOINT_XFERTYPE_MASK) == \
3257 USB_ENDPOINT_XFER_ISOC) {
3258 JOM(4, "intf[%i]alt[%i]end[%i] is an ISOC endpoint\n",\
3259 bInterfaceNumber, i, j);
3261 switch (bInterfaceClass) {
3262 case USB_CLASS_VIDEO:
3263 case USB_CLASS_VENDOR_SPEC: {
3266 "peasycap is NULL\n");
3269 if (pepd->wMaxPacketSize) {
3278 bEndpointAddress & \
3294 if (-1 == peasycap->\
3295 video_altsetting_off) {
3297 video_altsetting_off =\
3299 JOM(4, "%i=video_" \
3303 video_altsetting_off);
3305 SAM("ERROR: peasycap" \
3306 "->video_altsetting_" \
3307 "off already set\n");
3309 "continuing with " \
3310 "%i=peasycap->video_" \
3311 "altsetting_off\n", \
3313 video_altsetting_off);
3318 case USB_CLASS_AUDIO: {
3319 if (0x02 != bInterfaceSubClass)
3323 "peasycap is NULL\n");
3326 if (pepd->wMaxPacketSize) {
3328 okalt[isokalt] = i ;
3335 bEndpointAddress & \
3351 if (-1 == peasycap->\
3352 audio_altsetting_off) {
3354 audio_altsetting_off =\
3356 JOM(4, "%i=audio_" \
3360 audio_altsetting_off);
3362 SAM("ERROR: peasycap" \
3363 "->audio_altsetting_" \
3364 "off already set\n");
3366 "continuing with " \
3368 audio_altsetting_" \
3371 audio_altsetting_off);
3380 } else if ((pepd->bmAttributes & \
3381 USB_ENDPOINT_XFERTYPE_MASK) ==\
3382 USB_ENDPOINT_XFER_BULK) {
3383 JOM(4, "intf[%i]alt[%i]end[%i] is a BULK endpoint\n",\
3384 bInterfaceNumber, i, j);
3385 } else if ((pepd->bmAttributes & \
3386 USB_ENDPOINT_XFERTYPE_MASK) ==\
3387 USB_ENDPOINT_XFER_INT) {
3388 JOM(4, "intf[%i]alt[%i]end[%i] is an INT endpoint\n",\
3389 bInterfaceNumber, i, j);
3391 JOM(4, "intf[%i]alt[%i]end[%i] is a CTRL endpoint\n",\
3392 bInterfaceNumber, i, j);
3394 if (0 == pepd->wMaxPacketSize) {
3395 JOM(4, "intf[%i]alt[%i]end[%i] " \
3396 "has zero packet size\n", \
3397 bInterfaceNumber, i, j);
3401 /*---------------------------------------------------------------------------*/
3403 * PERFORM INITIALIZATION OF THE PROBED INTERFACE
3405 /*---------------------------------------------------------------------------*/
3406 JOM(4, "initialization begins for interface %i\n", \
3407 pusb_interface_descriptor->bInterfaceNumber);
3408 switch (bInterfaceNumber) {
3409 /*---------------------------------------------------------------------------*/
3411 * INTERFACE 0 IS THE VIDEO INTERFACE
3413 /*---------------------------------------------------------------------------*/
3416 SAM("MISTAKE: peasycap is NULL\n");
3420 SAM("ERROR: no viable video_altsetting_on\n");
3423 peasycap->video_altsetting_on = okalt[isokalt - 1];
3424 JOM(4, "%i=video_altsetting_on <====\n", \
3425 peasycap->video_altsetting_on);
3427 /*---------------------------------------------------------------------------*/
3429 * DECIDE THE VIDEO STREAMING PARAMETERS
3431 /*---------------------------------------------------------------------------*/
3432 peasycap->video_endpointnumber = okepn[isokalt - 1];
3433 JOM(4, "%i=video_endpointnumber\n", peasycap->video_endpointnumber);
3434 maxpacketsize = okmps[isokalt - 1];
3435 if (USB_2_0_MAXPACKETSIZE > maxpacketsize) {
3436 peasycap->video_isoc_maxframesize = maxpacketsize;
3438 peasycap->video_isoc_maxframesize = \
3439 USB_2_0_MAXPACKETSIZE;
3441 JOM(4, "%i=video_isoc_maxframesize\n", \
3442 peasycap->video_isoc_maxframesize);
3443 if (0 >= peasycap->video_isoc_maxframesize) {
3444 SAM("ERROR: bad video_isoc_maxframesize\n");
3445 SAM(" possibly because port is USB 1.1\n");
3448 peasycap->video_isoc_framesperdesc = VIDEO_ISOC_FRAMESPERDESC;
3449 JOM(4, "%i=video_isoc_framesperdesc\n", \
3450 peasycap->video_isoc_framesperdesc);
3451 if (0 >= peasycap->video_isoc_framesperdesc) {
3452 SAM("ERROR: bad video_isoc_framesperdesc\n");
3455 peasycap->video_isoc_buffer_size = \
3456 peasycap->video_isoc_maxframesize * \
3457 peasycap->video_isoc_framesperdesc;
3458 JOM(4, "%i=video_isoc_buffer_size\n", \
3459 peasycap->video_isoc_buffer_size);
3460 if ((PAGE_SIZE << VIDEO_ISOC_ORDER) < \
3461 peasycap->video_isoc_buffer_size) {
3462 SAM("MISTAKE: peasycap->video_isoc_buffer_size too big\n");
3465 /*---------------------------------------------------------------------------*/
3466 if (-1 == peasycap->video_interface) {
3467 SAM("MISTAKE: video_interface is unset\n");
3470 if (-1 == peasycap->video_altsetting_on) {
3471 SAM("MISTAKE: video_altsetting_on is unset\n");
3474 if (-1 == peasycap->video_altsetting_off) {
3475 SAM("MISTAKE: video_interface_off is unset\n");
3478 if (-1 == peasycap->video_endpointnumber) {
3479 SAM("MISTAKE: video_endpointnumber is unset\n");
3482 if (-1 == peasycap->video_isoc_maxframesize) {
3483 SAM("MISTAKE: video_isoc_maxframesize is unset\n");
3486 if (-1 == peasycap->video_isoc_buffer_size) {
3487 SAM("MISTAKE: video_isoc_buffer_size is unset\n");
3490 /*---------------------------------------------------------------------------*/
3492 * ALLOCATE MEMORY FOR VIDEO BUFFERS. LISTS MUST BE INITIALIZED FIRST.
3494 /*---------------------------------------------------------------------------*/
3495 INIT_LIST_HEAD(&(peasycap->urb_video_head));
3496 peasycap->purb_video_head = &(peasycap->urb_video_head);
3497 /*---------------------------------------------------------------------------*/
3498 JOM(4, "allocating %i frame buffers of size %li\n", \
3499 FRAME_BUFFER_MANY, (long int)FRAME_BUFFER_SIZE);
3500 JOM(4, ".... each scattered over %li pages\n", \
3501 FRAME_BUFFER_SIZE/PAGE_SIZE);
3503 for (k = 0; k < FRAME_BUFFER_MANY; k++) {
3504 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) {
3505 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo)
3506 SAM("attempting to reallocate frame " \
3509 pbuf = (void *)__get_free_page(GFP_KERNEL);
3510 if ((void *)NULL == pbuf) {
3511 SAM("ERROR: Could not allocate frame "\
3512 "buffer %i page %i\n", k, m);
3515 peasycap->allocation_video_page += 1;
3516 peasycap->frame_buffer[k][m].pgo = pbuf;
3518 peasycap->frame_buffer[k][m].pto = \
3519 peasycap->frame_buffer[k][m].pgo;
3523 peasycap->frame_fill = 0;
3524 peasycap->frame_read = 0;
3525 JOM(4, "allocation of frame buffers done: %i pages\n", k * \
3527 /*---------------------------------------------------------------------------*/
3528 JOM(4, "allocating %i field buffers of size %li\n", \
3529 FIELD_BUFFER_MANY, (long int)FIELD_BUFFER_SIZE);
3530 JOM(4, ".... each scattered over %li pages\n", \
3531 FIELD_BUFFER_SIZE/PAGE_SIZE);
3533 for (k = 0; k < FIELD_BUFFER_MANY; k++) {
3534 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) {
3535 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) {
3536 SAM("ERROR: attempting to reallocate " \
3539 pbuf = (void *) __get_free_page(GFP_KERNEL);
3540 if ((void *)NULL == pbuf) {
3541 SAM("ERROR: Could not allocate field" \
3542 " buffer %i page %i\n", k, m);
3546 peasycap->allocation_video_page += 1;
3547 peasycap->field_buffer[k][m].pgo = pbuf;
3549 peasycap->field_buffer[k][m].pto = \
3550 peasycap->field_buffer[k][m].pgo;
3552 peasycap->field_buffer[k][0].kount = 0x0200;
3554 peasycap->field_fill = 0;
3555 peasycap->field_page = 0;
3556 peasycap->field_read = 0;
3557 JOM(4, "allocation of field buffers done: %i pages\n", k * \
3559 /*---------------------------------------------------------------------------*/
3560 JOM(4, "allocating %i isoc video buffers of size %i\n", \
3561 VIDEO_ISOC_BUFFER_MANY, \
3562 peasycap->video_isoc_buffer_size);
3563 JOM(4, ".... each occupying contiguous memory pages\n");
3565 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
3566 pbuf = (void *)__get_free_pages(GFP_KERNEL, VIDEO_ISOC_ORDER);
3568 SAM("ERROR: Could not allocate isoc video buffer " \
3572 peasycap->allocation_video_page += \
3573 ((unsigned int)(0x01 << VIDEO_ISOC_ORDER));
3575 peasycap->video_isoc_buffer[k].pgo = pbuf;
3576 peasycap->video_isoc_buffer[k].pto = pbuf + \
3577 peasycap->video_isoc_buffer_size;
3578 peasycap->video_isoc_buffer[k].kount = k;
3580 JOM(4, "allocation of isoc video buffers done: %i pages\n", \
3581 k * (0x01 << VIDEO_ISOC_ORDER));
3582 /*---------------------------------------------------------------------------*/
3584 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
3586 /*---------------------------------------------------------------------------*/
3587 JOM(4, "allocating %i struct urb.\n", VIDEO_ISOC_BUFFER_MANY);
3588 JOM(4, "using %i=peasycap->video_isoc_framesperdesc\n", \
3589 peasycap->video_isoc_framesperdesc);
3590 JOM(4, "using %i=peasycap->video_isoc_maxframesize\n", \
3591 peasycap->video_isoc_maxframesize);
3592 JOM(4, "using %i=peasycap->video_isoc_buffer_sizen", \
3593 peasycap->video_isoc_buffer_size);
3595 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
3596 purb = usb_alloc_urb(peasycap->video_isoc_framesperdesc, \
3599 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
3603 peasycap->allocation_video_urb += 1;
3604 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3605 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL);
3606 if (NULL == pdata_urb) {
3607 SAM("ERROR: Could not allocate struct data_urb.\n");
3610 peasycap->allocation_video_struct += \
3611 sizeof(struct data_urb);
3613 pdata_urb->purb = purb;
3614 pdata_urb->isbuf = k;
3615 pdata_urb->length = 0;
3616 list_add_tail(&(pdata_urb->list_head), \
3617 peasycap->purb_video_head);
3618 /*---------------------------------------------------------------------------*/
3620 * ... AND INITIALIZE THEM
3622 /*---------------------------------------------------------------------------*/
3624 JOM(4, "initializing video urbs thus:\n");
3625 JOM(4, " purb->interval = 1;\n");
3626 JOM(4, " purb->dev = peasycap->pusb_device;\n");
3627 JOM(4, " purb->pipe = usb_rcvisocpipe" \
3628 "(peasycap->pusb_device,%i);\n", \
3629 peasycap->video_endpointnumber);
3630 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
3631 JOM(4, " purb->transfer_buffer = peasycap->" \
3632 "video_isoc_buffer[.].pgo;\n");
3633 JOM(4, " purb->transfer_buffer_length = %i;\n", \
3634 peasycap->video_isoc_buffer_size);
3635 JOM(4, " purb->complete = easycap_complete;\n");
3636 JOM(4, " purb->context = peasycap;\n");
3637 JOM(4, " purb->start_frame = 0;\n");
3638 JOM(4, " purb->number_of_packets = %i;\n", \
3639 peasycap->video_isoc_framesperdesc);
3640 JOM(4, " for (j = 0; j < %i; j++)\n", \
3641 peasycap->video_isoc_framesperdesc);
3643 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
3644 peasycap->video_isoc_maxframesize);
3645 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
3646 peasycap->video_isoc_maxframesize);
3651 purb->dev = peasycap->pusb_device;
3652 purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, \
3653 peasycap->video_endpointnumber);
3654 purb->transfer_flags = URB_ISO_ASAP;
3655 purb->transfer_buffer = peasycap->video_isoc_buffer[k].pgo;
3656 purb->transfer_buffer_length = \
3657 peasycap->video_isoc_buffer_size;
3658 purb->complete = easycap_complete;
3659 purb->context = peasycap;
3660 purb->start_frame = 0;
3661 purb->number_of_packets = peasycap->video_isoc_framesperdesc;
3662 for (j = 0; j < peasycap->video_isoc_framesperdesc; j++) {
3663 purb->iso_frame_desc[j].offset = j * \
3664 peasycap->video_isoc_maxframesize;
3665 purb->iso_frame_desc[j].length = \
3666 peasycap->video_isoc_maxframesize;
3669 JOM(4, "allocation of %i struct urb done.\n", k);
3670 /*--------------------------------------------------------------------------*/
3672 * SAVE POINTER peasycap IN THIS INTERFACE.
3674 /*--------------------------------------------------------------------------*/
3675 usb_set_intfdata(pusb_interface, peasycap);
3676 /*--------------------------------------------------------------------------*/
3678 * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY.
3680 /*--------------------------------------------------------------------------*/
3681 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
3682 if (0 != (usb_register_dev(pusb_interface, &easycap_class))) {
3683 err("Not able to get a minor for this device");
3684 usb_set_intfdata(pusb_interface, NULL);
3687 (peasycap->registered_video)++;
3688 SAM("easycap attached to minor #%d\n", pusb_interface->minor);
3691 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3693 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
3694 if (0 != (v4l2_device_register(&(pusb_interface->dev), \
3695 &(peasycap->v4l2_device)))) {
3696 SAM("v4l2_device_register() failed\n");
3699 JOM(4, "registered device instance: %s\n", \
3700 &(peasycap->v4l2_device.name[0]));
3702 /*---------------------------------------------------------------------------*/
3704 * THIS IS BELIEVED TO BE HARMLESS, BUT MAY WELL BE UNNECESSARY OR WRONG:
3706 /*---------------------------------------------------------------------------*/
3707 peasycap->video_device.v4l2_dev = (struct v4l2_device *)NULL;
3708 /*---------------------------------------------------------------------------*/
3710 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
3712 strcpy(&peasycap->video_device.name[0], "easycapdc60");
3713 #if defined(EASYCAP_NEEDS_V4L2_FOPS)
3714 peasycap->video_device.fops = &v4l2_fops;
3716 peasycap->video_device.fops = &easycap_fops;
3717 #endif /*EASYCAP_NEEDS_V4L2_FOPS*/
3718 peasycap->video_device.minor = -1;
3719 peasycap->video_device.release = (void *)(&videodev_release);
3721 video_set_drvdata(&(peasycap->video_device), (void *)peasycap);
3723 if (0 != (video_register_device(&(peasycap->video_device), \
3724 VFL_TYPE_GRABBER, -1))) {
3725 err("Not able to register with videodev");
3726 videodev_release(&(peasycap->video_device));
3729 (peasycap->registered_video)++;
3730 SAM("registered with videodev: %i=minor\n", \
3731 peasycap->video_device.minor);
3733 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
3734 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3737 /*--------------------------------------------------------------------------*/
3739 * INTERFACE 1 IS THE AUDIO CONTROL INTERFACE
3740 * INTERFACE 2 IS THE AUDIO STREAMING INTERFACE
3742 /*--------------------------------------------------------------------------*/
3745 SAM("ERROR: peasycap is NULL\n");
3748 /*--------------------------------------------------------------------------*/
3750 * SAVE POINTER peasycap IN INTERFACE 1
3752 /*--------------------------------------------------------------------------*/
3753 usb_set_intfdata(pusb_interface, peasycap);
3754 JOM(4, "no initialization required for interface %i\n", \
3755 pusb_interface_descriptor->bInterfaceNumber);
3758 /*--------------------------------------------------------------------------*/
3761 SAM("MISTAKE: peasycap is NULL\n");
3765 SAM("ERROR: no viable audio_altsetting_on\n");
3768 peasycap->audio_altsetting_on = okalt[isokalt - 1];
3769 JOM(4, "%i=audio_altsetting_on <====\n", \
3770 peasycap->audio_altsetting_on);
3773 peasycap->audio_endpointnumber = okepn[isokalt - 1];
3774 JOM(4, "%i=audio_endpointnumber\n", peasycap->audio_endpointnumber);
3776 peasycap->audio_isoc_maxframesize = okmps[isokalt - 1];
3777 JOM(4, "%i=audio_isoc_maxframesize\n", \
3778 peasycap->audio_isoc_maxframesize);
3779 if (0 >= peasycap->audio_isoc_maxframesize) {
3780 SAM("ERROR: bad audio_isoc_maxframesize\n");
3783 if (9 == peasycap->audio_isoc_maxframesize) {
3784 peasycap->ilk |= 0x02;
3785 SAM("hardware is FOUR-CVBS\n");
3786 peasycap->microphone = true;
3787 peasycap->audio_pages_per_fragment = 4;
3788 } else if (256 == peasycap->audio_isoc_maxframesize) {
3789 peasycap->ilk &= ~0x02;
3790 SAM("hardware is CVBS+S-VIDEO\n");
3791 peasycap->microphone = false;
3792 peasycap->audio_pages_per_fragment = 4;
3794 SAM("hardware is unidentified:\n");
3795 SAM("%i=audio_isoc_maxframesize\n", \
3796 peasycap->audio_isoc_maxframesize);
3800 peasycap->audio_bytes_per_fragment = \
3801 peasycap->audio_pages_per_fragment * \
3803 peasycap->audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
3804 peasycap->audio_pages_per_fragment);
3806 JOM(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY);
3807 JOM(4, "%6i=audio_pages_per_fragment\n", \
3808 peasycap->audio_pages_per_fragment);
3809 JOM(4, "%6i=audio_bytes_per_fragment\n", \
3810 peasycap->audio_bytes_per_fragment);
3811 JOM(4, "%6i=audio_buffer_page_many\n", \
3812 peasycap->audio_buffer_page_many);
3814 peasycap->audio_isoc_framesperdesc = 128;
3816 JOM(4, "%i=audio_isoc_framesperdesc\n", \
3817 peasycap->audio_isoc_framesperdesc);
3818 if (0 >= peasycap->audio_isoc_framesperdesc) {
3819 SAM("ERROR: bad audio_isoc_framesperdesc\n");
3823 peasycap->audio_isoc_buffer_size = \
3824 peasycap->audio_isoc_maxframesize * \
3825 peasycap->audio_isoc_framesperdesc;
3826 JOM(4, "%i=audio_isoc_buffer_size\n", \
3827 peasycap->audio_isoc_buffer_size);
3828 if (AUDIO_ISOC_BUFFER_SIZE < peasycap->audio_isoc_buffer_size) {
3829 SAM("MISTAKE: audio_isoc_buffer_size bigger "
3830 "than %li=AUDIO_ISOC_BUFFER_SIZE\n", \
3831 AUDIO_ISOC_BUFFER_SIZE);
3834 if (-1 == peasycap->audio_interface) {
3835 SAM("MISTAKE: audio_interface is unset\n");
3838 if (-1 == peasycap->audio_altsetting_on) {
3839 SAM("MISTAKE: audio_altsetting_on is unset\n");
3842 if (-1 == peasycap->audio_altsetting_off) {
3843 SAM("MISTAKE: audio_interface_off is unset\n");
3846 if (-1 == peasycap->audio_endpointnumber) {
3847 SAM("MISTAKE: audio_endpointnumber is unset\n");
3850 if (-1 == peasycap->audio_isoc_maxframesize) {
3851 SAM("MISTAKE: audio_isoc_maxframesize is unset\n");
3854 if (-1 == peasycap->audio_isoc_buffer_size) {
3855 SAM("MISTAKE: audio_isoc_buffer_size is unset\n");
3858 /*---------------------------------------------------------------------------*/
3860 * ALLOCATE MEMORY FOR AUDIO BUFFERS. LISTS MUST BE INITIALIZED FIRST.
3862 /*---------------------------------------------------------------------------*/
3863 INIT_LIST_HEAD(&(peasycap->urb_audio_head));
3864 peasycap->purb_audio_head = &(peasycap->urb_audio_head);
3866 JOM(4, "allocating an audio buffer\n");
3867 JOM(4, ".... scattered over %i pages\n", \
3868 peasycap->audio_buffer_page_many);
3870 for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
3871 if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
3872 SAM("ERROR: attempting to reallocate audio buffers\n");
3874 pbuf = (void *) __get_free_page(GFP_KERNEL);
3875 if ((void *)NULL == pbuf) {
3876 SAM("ERROR: Could not allocate audio " \
3877 "buffer page %i\n", k);
3880 peasycap->allocation_audio_page += 1;
3882 peasycap->audio_buffer[k].pgo = pbuf;
3884 peasycap->audio_buffer[k].pto = peasycap->audio_buffer[k].pgo;
3887 peasycap->audio_fill = 0;
3888 peasycap->audio_read = 0;
3889 JOM(4, "allocation of audio buffer done: %i pages\n", k);
3890 /*---------------------------------------------------------------------------*/
3891 JOM(4, "allocating %i isoc audio buffers of size %i\n", \
3892 AUDIO_ISOC_BUFFER_MANY, peasycap->audio_isoc_buffer_size);
3893 JOM(4, ".... each occupying contiguous memory pages\n");
3895 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
3896 pbuf = (void *)__get_free_pages(GFP_KERNEL, AUDIO_ISOC_ORDER);
3898 SAM("ERROR: Could not allocate isoc audio buffer " \
3902 peasycap->allocation_audio_page += \
3903 ((unsigned int)(0x01 << AUDIO_ISOC_ORDER));
3905 peasycap->audio_isoc_buffer[k].pgo = pbuf;
3906 peasycap->audio_isoc_buffer[k].pto = pbuf + \
3907 peasycap->audio_isoc_buffer_size;
3908 peasycap->audio_isoc_buffer[k].kount = k;
3910 JOM(4, "allocation of isoc audio buffers done.\n");
3911 /*---------------------------------------------------------------------------*/
3913 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
3915 /*---------------------------------------------------------------------------*/
3916 JOM(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY);
3917 JOM(4, "using %i=peasycap->audio_isoc_framesperdesc\n", \
3918 peasycap->audio_isoc_framesperdesc);
3919 JOM(4, "using %i=peasycap->audio_isoc_maxframesize\n", \
3920 peasycap->audio_isoc_maxframesize);
3921 JOM(4, "using %i=peasycap->audio_isoc_buffer_size\n", \
3922 peasycap->audio_isoc_buffer_size);
3924 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
3925 purb = usb_alloc_urb(peasycap->audio_isoc_framesperdesc, \
3928 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
3932 peasycap->allocation_audio_urb += 1 ;
3933 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3934 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL);
3935 if (NULL == pdata_urb) {
3936 SAM("ERROR: Could not allocate struct data_urb.\n");
3939 peasycap->allocation_audio_struct += \
3940 sizeof(struct data_urb);
3942 pdata_urb->purb = purb;
3943 pdata_urb->isbuf = k;
3944 pdata_urb->length = 0;
3945 list_add_tail(&(pdata_urb->list_head), \
3946 peasycap->purb_audio_head);
3947 /*---------------------------------------------------------------------------*/
3949 * ... AND INITIALIZE THEM
3951 /*---------------------------------------------------------------------------*/
3953 JOM(4, "initializing audio urbs thus:\n");
3954 JOM(4, " purb->interval = 1;\n");
3955 JOM(4, " purb->dev = peasycap->pusb_device;\n");
3956 JOM(4, " purb->pipe = usb_rcvisocpipe(peasycap->" \
3957 "pusb_device,%i);\n", \
3958 peasycap->audio_endpointnumber);
3959 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
3960 JOM(4, " purb->transfer_buffer = " \
3961 "peasycap->audio_isoc_buffer[.].pgo;\n");
3962 JOM(4, " purb->transfer_buffer_length = %i;\n", \
3963 peasycap->audio_isoc_buffer_size);
3964 JOM(4, " purb->complete = easysnd_complete;\n");
3965 JOM(4, " purb->context = peasycap;\n");
3966 JOM(4, " purb->start_frame = 0;\n");
3967 JOM(4, " purb->number_of_packets = %i;\n", \
3968 peasycap->audio_isoc_framesperdesc);
3969 JOM(4, " for (j = 0; j < %i; j++)\n", \
3970 peasycap->audio_isoc_framesperdesc);
3972 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
3973 peasycap->audio_isoc_maxframesize);
3974 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
3975 peasycap->audio_isoc_maxframesize);
3980 purb->dev = peasycap->pusb_device;
3981 purb->pipe = usb_rcvisocpipe(peasycap->pusb_device, \
3982 peasycap->audio_endpointnumber);
3983 purb->transfer_flags = URB_ISO_ASAP;
3984 purb->transfer_buffer = peasycap->audio_isoc_buffer[k].pgo;
3985 purb->transfer_buffer_length = \
3986 peasycap->audio_isoc_buffer_size;
3987 purb->complete = easysnd_complete;
3988 purb->context = peasycap;
3989 purb->start_frame = 0;
3990 purb->number_of_packets = peasycap->audio_isoc_framesperdesc;
3991 for (j = 0; j < peasycap->audio_isoc_framesperdesc; j++) {
3992 purb->iso_frame_desc[j].offset = j * \
3993 peasycap->audio_isoc_maxframesize;
3994 purb->iso_frame_desc[j].length = \
3995 peasycap->audio_isoc_maxframesize;
3998 JOM(4, "allocation of %i struct urb done.\n", k);
3999 /*---------------------------------------------------------------------------*/
4001 * SAVE POINTER peasycap IN THIS INTERFACE.
4003 /*---------------------------------------------------------------------------*/
4004 usb_set_intfdata(pusb_interface, peasycap);
4005 /*---------------------------------------------------------------------------*/
4007 * THE AUDIO DEVICE CAN BE REGISTERED NOW, AS IT IS READY.
4009 /*---------------------------------------------------------------------------*/
4010 rc = usb_register_dev(pusb_interface, &easysnd_class);
4012 err("Not able to get a minor for this device.");
4013 usb_set_intfdata(pusb_interface, NULL);
4016 JOM(8, "kref_get() with %i=peasycap->kref.refcount.counter\n",\
4017 (int)peasycap->kref.refcount.counter);
4018 kref_get(&peasycap->kref);
4019 (peasycap->registered_audio)++;
4021 /*---------------------------------------------------------------------------*/
4023 * LET THE USER KNOW WHAT NODE THE AUDIO DEVICE IS ATTACHED TO.
4025 /*---------------------------------------------------------------------------*/
4026 SAM("easysnd attached to minor #%d\n", pusb_interface->minor);
4029 /*---------------------------------------------------------------------------*/
4031 * INTERFACES OTHER THAN 0, 1 AND 2 ARE UNEXPECTED
4033 /*---------------------------------------------------------------------------*/
4035 JOM(4, "ERROR: unexpected interface %i\n", bInterfaceNumber);
4039 JOM(4, "ends successfully for interface %i\n", \
4040 pusb_interface_descriptor->bInterfaceNumber);
4043 /*****************************************************************************/
4044 /*---------------------------------------------------------------------------*/
4046 * WHEN THIS FUNCTION IS CALLED THE DEVICE HAS ALREADY BEEN PHYSICALLY
4048 * HENCE peasycap->pusb_device IS NO LONGER VALID AND MUST BE SET TO NULL.
4050 /*---------------------------------------------------------------------------*/
4052 easycap_usb_disconnect(struct usb_interface *pusb_interface)
4054 struct usb_host_interface *pusb_host_interface;
4055 struct usb_interface_descriptor *pusb_interface_descriptor;
4056 __u8 bInterfaceNumber;
4057 struct easycap *peasycap;
4059 struct list_head *plist_head;
4060 struct data_urb *pdata_urb;
4065 if ((struct usb_interface *)NULL == pusb_interface) {
4066 JOT(4, "ERROR: pusb_interface is NULL\n");
4069 pusb_host_interface = pusb_interface->cur_altsetting;
4070 if ((struct usb_host_interface *)NULL == pusb_host_interface) {
4071 JOT(4, "ERROR: pusb_host_interface is NULL\n");
4074 pusb_interface_descriptor = &(pusb_host_interface->desc);
4075 if ((struct usb_interface_descriptor *)NULL == pusb_interface_descriptor) {
4076 JOT(4, "ERROR: pusb_interface_descriptor is NULL\n");
4079 bInterfaceNumber = pusb_interface_descriptor->bInterfaceNumber;
4080 minor = pusb_interface->minor;
4081 JOT(4, "intf[%i]: minor=%i\n", bInterfaceNumber, minor);
4083 if (1 == bInterfaceNumber)
4086 peasycap = usb_get_intfdata(pusb_interface);
4087 if (NULL == peasycap) {
4088 SAY("ERROR: peasycap is NULL\n");
4091 /*---------------------------------------------------------------------------*/
4093 * IF THE WAIT QUEUES ARE NOT CLEARED A DEADLOCK IS POSSIBLE. BEWARE.
4095 /*---------------------------------------------------------------------------*/
4096 peasycap->video_eof = 1;
4097 peasycap->audio_eof = 1;
4098 wake_up_interruptible(&peasycap->wq_video);
4099 wake_up_interruptible(&peasycap->wq_audio);
4100 /*---------------------------------------------------------------------------*/
4101 switch (bInterfaceNumber) {
4103 if ((struct list_head *)NULL != peasycap->purb_video_head) {
4104 JOM(4, "killing video urbs\n");
4106 list_for_each(plist_head, (peasycap->purb_video_head)) {
4107 pdata_urb = list_entry(plist_head, \
4108 struct data_urb, list_head);
4109 if ((struct data_urb *)NULL != pdata_urb) {
4110 if ((struct urb *)NULL != \
4112 usb_kill_urb(pdata_urb->purb);
4117 JOM(4, "%i video urbs killed\n", m);
4121 /*---------------------------------------------------------------------------*/
4123 if ((struct list_head *)NULL != peasycap->purb_audio_head) {
4124 JOM(4, "killing audio urbs\n");
4126 list_for_each(plist_head, (peasycap->purb_audio_head)) {
4127 pdata_urb = list_entry(plist_head, \
4128 struct data_urb, list_head);
4129 if ((struct data_urb *)NULL != pdata_urb) {
4130 if ((struct urb *)NULL != \
4132 usb_kill_urb(pdata_urb->purb);
4137 JOM(4, "%i audio urbs killed\n", m);
4141 /*---------------------------------------------------------------------------*/
4145 /*--------------------------------------------------------------------------*/
4149 /*--------------------------------------------------------------------------*/
4150 switch (bInterfaceNumber) {
4153 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4154 if ((struct easycap *)NULL == peasycap) {
4155 SAM("ERROR: peasycap has become NULL\n");
4158 usb_deregister_dev(pusb_interface, &easycap_class);
4159 (peasycap->registered_video)--;
4161 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber);
4163 SAM("easycap detached from minor #%d\n", minor);
4165 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4167 if ((struct easycap *)NULL == peasycap)
4168 SAM("ERROR: peasycap has become NULL\n");
4171 video_unregister_device(&peasycap->video_device);
4172 (peasycap->registered_video)--;
4174 JOM(4, "unregistered with videodev: %i=minor\n", \
4175 peasycap->video_device.minor);
4177 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4178 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4184 usb_deregister_dev(pusb_interface, &easysnd_class);
4185 if ((struct easycap *)NULL != peasycap)
4186 (peasycap->registered_audio)--;
4188 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber);
4191 SAM("easysnd detached from minor #%d\n", minor);
4197 /*---------------------------------------------------------------------------*/
4199 * CALL easycap_delete() IF NO REMAINING REFERENCES TO peasycap
4201 /*---------------------------------------------------------------------------*/
4202 if ((struct easycap *)NULL == peasycap) {
4203 SAM("ERROR: peasycap has become NULL\n");
4204 SAM("cannot call kref_put()\n");
4205 SAM("ending unsuccessfully: may cause memory leak\n");
4208 if (!peasycap->kref.refcount.counter) {
4209 SAM("ERROR: peasycap->kref.refcount.counter is zero " \
4210 "so cannot call kref_put()\n");
4211 SAM("ending unsuccessfully: may cause memory leak\n");
4214 JOM(4, "intf[%i]: kref_put() with %i=peasycap->kref.refcount.counter\n", \
4215 bInterfaceNumber, (int)peasycap->kref.refcount.counter);
4216 kref_put(&peasycap->kref, easycap_delete);
4217 JOM(4, "intf[%i]: kref_put() done.\n", bInterfaceNumber);
4218 /*---------------------------------------------------------------------------*/
4223 /*****************************************************************************/
4225 easycap_module_init(void)
4229 SAY("========easycap=======\n");
4230 JOT(4, "begins. %i=debug\n", debug);
4231 SAY("version: " EASYCAP_DRIVER_VERSION "\n");
4232 /*---------------------------------------------------------------------------*/
4234 * REGISTER THIS DRIVER WITH THE USB SUBSYTEM.
4236 /*---------------------------------------------------------------------------*/
4237 JOT(4, "registering driver easycap\n");
4239 result = usb_register(&easycap_usb_driver);
4241 SAY("ERROR: usb_register returned %i\n", result);
4246 /*****************************************************************************/
4248 easycap_module_exit(void)
4252 /*---------------------------------------------------------------------------*/
4254 * DEREGISTER THIS DRIVER WITH THE USB SUBSYTEM.
4256 /*---------------------------------------------------------------------------*/
4257 usb_deregister(&easycap_usb_driver);
4261 /*****************************************************************************/
4263 module_init(easycap_module_init);
4264 module_exit(easycap_module_exit);
4266 MODULE_LICENSE("GPL");
4267 MODULE_AUTHOR("R.M. Thomas <rmthomas@sciolus.org>");
4268 MODULE_DESCRIPTION(EASYCAP_DRIVER_DESCRIPTION);
4269 MODULE_VERSION(EASYCAP_DRIVER_VERSION);
4270 #if defined(EASYCAP_DEBUG)
4271 MODULE_PARM_DESC(debug, "debug: 0 (default), 1, 2,...");
4272 #endif /*EASYCAP_DEBUG*/
4273 /*****************************************************************************/