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"
33 #include "easycap_ioctl.h"
35 static int easycap_debug
;
36 static int easycap_bars
;
37 int easycap_gain
= 16;
38 module_param_named(debug
, easycap_debug
, int, S_IRUGO
| S_IWUSR
);
39 module_param_named(bars
, easycap_bars
, int, S_IRUGO
| S_IWUSR
);
40 module_param_named(gain
, easycap_gain
, int, S_IRUGO
| S_IWUSR
);
42 /*---------------------------------------------------------------------------*/
44 * dongle_this IS INDISPENSIBLY static BECAUSE FUNCTION easycap_usb_probe()
45 * IS CALLED SUCCESSIVELY FOR INTERFACES 0, 1, 2 AND THE POINTER peasycap
46 * ALLOCATED DURING THE PROBING OF INTERFACE 0 MUST BE REMEMBERED WHEN
47 * PROBING INTERFACES 1 AND 2.
49 * IOCTL LOCKING IS DONE AT MODULE LEVEL, NOT DEVICE LEVEL.
51 /*---------------------------------------------------------------------------*/
53 struct easycap_dongle easycap_dongle
[DONGLE_MANY
];
54 static int dongle_this
;
55 static int dongle_done
;
57 /*---------------------------------------------------------------------------*/
59 * PARAMETERS APPLICABLE TO ENTIRE DRIVER, I.E. BOTH VIDEO AND AUDIO
61 /*---------------------------------------------------------------------------*/
62 struct usb_device_id easycap_usb_device_id_table
[] = {
63 { USB_DEVICE(USB_EASYCAP_VENDOR_ID
, USB_EASYCAP_PRODUCT_ID
) },
66 MODULE_DEVICE_TABLE(usb
, easycap_usb_device_id_table
);
67 struct usb_driver easycap_usb_driver
= {
69 .id_table
= easycap_usb_device_id_table
,
70 .probe
= easycap_usb_probe
,
71 .disconnect
= easycap_usb_disconnect
,
73 /*---------------------------------------------------------------------------*/
75 * PARAMETERS USED WHEN REGISTERING THE VIDEO INTERFACE
77 * NOTE: SOME KERNELS IGNORE usb_class_driver.minor_base, AS MENTIONED BY
78 * CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGE 253.
79 * THIS IS THE CASE FOR OpenSUSE.
81 /*---------------------------------------------------------------------------*/
82 const struct file_operations easycap_fops
= {
85 .release
= easycap_release
,
86 #if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
87 .unlocked_ioctl
= easycap_ioctl_noinode
,
89 .ioctl
= easycap_ioctl
,
90 #endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
95 struct vm_operations_struct easycap_vm_ops
= {
96 .open
= easycap_vma_open
,
97 .close
= easycap_vma_close
,
98 .fault
= easycap_vma_fault
,
100 struct usb_class_driver easycap_class
= {
101 .name
= "usb/easycap%d",
102 .fops
= &easycap_fops
,
103 .minor_base
= USB_SKEL_MINOR_BASE
,
105 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
106 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
107 #if defined(EASYCAP_NEEDS_V4L2_FOPS)
108 const struct v4l2_file_operations v4l2_fops
= {
109 .owner
= THIS_MODULE
,
110 .open
= easycap_open_noinode
,
111 .release
= easycap_release_noinode
,
112 #if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
113 .unlocked_ioctl
= easycap_ioctl_noinode
,
115 .ioctl
= easycap_ioctl
,
116 #endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
117 .poll
= easycap_poll
,
118 .mmap
= easycap_mmap
,
120 #endif /*EASYCAP_NEEDS_V4L2_FOPS*/
121 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
122 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
123 /*--------------------------------------------------------------------------*/
125 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE
127 /*--------------------------------------------------------------------------*/
128 const struct file_operations easysnd_fops
= {
129 .owner
= THIS_MODULE
,
130 .open
= easysnd_open
,
131 .release
= easysnd_release
,
132 #if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
133 .unlocked_ioctl
= easysnd_ioctl_noinode
,
135 .ioctl
= easysnd_ioctl
,
136 #endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
137 .read
= easysnd_read
,
140 struct usb_class_driver easysnd_class
= {
141 .name
= "usb/easysnd%d",
142 .fops
= &easysnd_fops
,
143 .minor_base
= USB_SKEL_MINOR_BASE
,
145 /****************************************************************************/
146 /*---------------------------------------------------------------------------*/
148 * THIS ROUTINE DOES NOT DETECT DUPLICATE OCCURRENCES OF POINTER peasycap
150 /*---------------------------------------------------------------------------*/
152 isdongle(struct easycap
*peasycap
)
155 if (NULL
== peasycap
)
157 for (k
= 0; k
< DONGLE_MANY
; k
++) {
158 if (easycap_dongle
[k
].peasycap
== peasycap
) {
159 peasycap
->isdongle
= k
;
165 /*****************************************************************************/
166 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
167 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
169 easycap_open_noinode(struct file
*file
)
171 return easycap_open((struct inode
*)NULL
, file
);
173 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
174 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
176 easycap_open(struct inode
*inode
, struct file
*file
)
178 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
179 struct usb_interface
*pusb_interface
;
181 struct video_device
*pvideo_device
;
182 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
183 struct easycap
*peasycap
;
187 SAY("==========OPEN=========\n");
189 peasycap
= (struct easycap
*)NULL
;
190 /*---------------------------------------------------------------------------*/
191 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
192 if ((struct inode
*)NULL
== inode
) {
193 SAY("ERROR: inode is NULL.\n");
196 pusb_interface
= usb_find_interface(&easycap_usb_driver
, iminor(inode
));
197 if (!pusb_interface
) {
198 SAY("ERROR: pusb_interface is NULL.\n");
201 peasycap
= usb_get_intfdata(pusb_interface
);
202 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
204 pvideo_device
= video_devdata(file
);
205 if ((struct video_device
*)NULL
== pvideo_device
) {
206 SAY("ERROR: pvideo_device is NULL.\n");
209 peasycap
= (struct easycap
*)video_get_drvdata(pvideo_device
);
210 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
211 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
212 if (NULL
== peasycap
) {
213 SAY("ERROR: peasycap is NULL\n");
216 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
217 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
220 if (NULL
== peasycap
->pusb_device
) {
221 SAM("ERROR: peasycap->pusb_device is NULL\n");
224 JOM(16, "0x%08lX=peasycap->pusb_device\n", \
225 (long int)peasycap
->pusb_device
);
227 file
->private_data
= peasycap
;
228 rc
= wakeup_device(peasycap
->pusb_device
);
230 JOM(8, "wakeup_device() OK\n");
232 SAM("ERROR: wakeup_device() returned %i\n", rc
);
234 SAM("ERROR: wakeup_device() returned -ENODEV\n");
236 SAM("ERROR: wakeup_device() returned %i\n", rc
);
240 rc
= reset(peasycap
);
242 SAM("ERROR: reset() returned %i\n", rc
);
247 /*****************************************************************************/
248 /*---------------------------------------------------------------------------*/
250 * RESET THE HARDWARE TO ITS REFERENCE STATE.
252 * THIS ROUTINE MAY BE CALLED REPEATEDLY IF easycap_complete() DETECTS
253 * A BAD VIDEO FRAME SIZE.
255 /*---------------------------------------------------------------------------*/
257 reset(struct easycap
*peasycap
)
259 struct easycap_standard
const *peasycap_standard
;
260 int i
, rc
, input
, rate
;
263 if (NULL
== peasycap
) {
264 SAY("ERROR: peasycap is NULL\n");
267 input
= peasycap
->input
;
269 /*---------------------------------------------------------------------------*/
271 * IF THE SAA7113H HAS ALREADY ACQUIRED SYNC, USE ITS HARDWARE-DETECTED
272 * FIELD FREQUENCY TO DISTINGUISH NTSC FROM PAL. THIS IS ESSENTIAL FOR
273 * gstreamer AND OTHER USERSPACE PROGRAMS WHICH MAY NOT ATTEMPT TO INITIATE
274 * A SWITCH BETWEEN PAL AND NTSC.
276 * FUNCTION ready_saa() MAY REQUIRE A SUBSTANTIAL FRACTION OF A SECOND TO
277 * COMPLETE, SO SHOULD NOT BE INVOKED WITHOUT GOOD REASON.
279 /*---------------------------------------------------------------------------*/
281 if (true == peasycap
->ntsc
)
282 JOM(8, "true=peasycap->ntsc\n");
284 JOM(8, "false=peasycap->ntsc\n");
285 rate
= ready_saa(peasycap
->pusb_device
);
287 JOM(8, "not ready to capture after %i ms ...\n", PATIENCE
);
288 if (true == peasycap
->ntsc
) {
289 JOM(8, "... trying PAL ...\n"); ntsc
= false;
291 JOM(8, "... trying NTSC ...\n"); ntsc
= true;
293 rc
= setup_stk(peasycap
->pusb_device
, ntsc
);
295 JOM(4, "setup_stk() OK\n");
297 SAM("ERROR: setup_stk() returned %i\n", rc
);
300 rc
= setup_saa(peasycap
->pusb_device
, ntsc
);
302 JOM(4, "setup_saa() OK\n");
304 SAM("ERROR: setup_saa() returned %i\n", rc
);
307 rate
= ready_saa(peasycap
->pusb_device
);
309 JOM(8, "not ready to capture after %i ms ...\n", PATIENCE
);
310 JOM(8, "... saa register 0x1F has 0x%02X\n", \
311 read_saa(peasycap
->pusb_device
, 0x1F));
312 ntsc
= peasycap
->ntsc
;
314 JOM(8, "... success at second try: %i=rate\n", rate
);
315 ntsc
= (0 < (rate
/2)) ? true : false ;
319 JOM(8, "... success at first try: %i=rate\n", rate
);
320 ntsc
= (0 < rate
/2) ? true : false ;
323 JOM(8, "true=ntsc\n");
325 JOM(8, "false=ntsc\n");
326 /*---------------------------------------------------------------------------*/
328 rc
= setup_stk(peasycap
->pusb_device
, ntsc
);
330 JOM(4, "setup_stk() OK\n");
332 SAM("ERROR: setup_stk() returned %i\n", rc
);
335 rc
= setup_saa(peasycap
->pusb_device
, ntsc
);
337 JOM(4, "setup_saa() OK\n");
339 SAM("ERROR: setup_saa() returned %i\n", rc
);
343 for (i
= 0; i
< 180; i
++)
344 peasycap
->merit
[i
] = 0;
345 peasycap
->video_eof
= 0;
346 peasycap
->audio_eof
= 0;
347 do_gettimeofday(&peasycap
->timeval7
);
348 /*---------------------------------------------------------------------------*/
350 * RESTORE INPUT AND FORCE REFRESH OF STANDARD, FORMAT, ETC.
352 * WHILE THIS PROCEDURE IS IN PROGRESS, SOME IOCTL COMMANDS WILL RETURN -EBUSY.
354 /*---------------------------------------------------------------------------*/
355 peasycap
->input
= -8192;
356 peasycap
->standard_offset
= -8192;
358 peasycap_standard
= &easycap_standard
[0];
359 while (0xFFFF != peasycap_standard
->mask
) {
362 peasycap_standard
->v4l2_standard
.index
) {
363 peasycap
->inputset
[input
].standard_offset
= \
364 peasycap_standard
- \
365 &easycap_standard
[0];
370 peasycap_standard
->v4l2_standard
.index
) {
371 peasycap
->inputset
[input
].standard_offset
= \
373 &easycap_standard
[0];
379 if (0xFFFF == peasycap_standard
->mask
) {
380 SAM("ERROR: standard not found\n");
383 JOM(8, "%i=peasycap->inputset[%i].standard_offset\n", \
384 peasycap
->inputset
[input
].standard_offset
, input
);
386 peasycap
->format_offset
= -8192;
387 peasycap
->brightness
= -8192;
388 peasycap
->contrast
= -8192;
389 peasycap
->saturation
= -8192;
390 peasycap
->hue
= -8192;
392 rc
= newinput(peasycap
, input
);
395 JOM(4, "restored input, standard and format\n");
397 SAM("ERROR: newinput(.,%i) returned %i\n", rc
, input
);
400 if (true == peasycap
->ntsc
)
401 JOM(8, "true=peasycap->ntsc\n");
403 JOM(8, "false=peasycap->ntsc\n");
405 if (0 > peasycap
->input
) {
406 SAM("MISTAKE: %i=peasycap->input\n", peasycap
->input
);
409 if (0 > peasycap
->standard_offset
) {
410 SAM("MISTAKE: %i=peasycap->standard_offset\n", \
411 peasycap
->standard_offset
);
414 if (0 > peasycap
->format_offset
) {
415 SAM("MISTAKE: %i=peasycap->format_offset\n", \
416 peasycap
->format_offset
);
419 if (0 > peasycap
->brightness
) {
420 SAM("MISTAKE: %i=peasycap->brightness\n", peasycap
->brightness
);
423 if (0 > peasycap
->contrast
) {
424 SAM("MISTAKE: %i=peasycap->contrast\n", peasycap
->contrast
);
427 if (0 > peasycap
->saturation
) {
428 SAM("MISTAKE: %i=peasycap->saturation\n", peasycap
->saturation
);
431 if (0 > peasycap
->hue
) {
432 SAM("MISTAKE: %i=peasycap->hue\n", peasycap
->hue
);
437 /*****************************************************************************/
438 /*---------------------------------------------------------------------------*/
440 * IF THE REQUESTED INPUT IS THE SAME AS THE EXISTING INPUT, DO NOTHING.
442 * KILL URBS, CLEAR FIELD AND FRAME BUFFERS AND RESET THEIR
443 * _read AND _fill POINTERS.
444 * SELECT THE NEW INPUT.
445 * ADJUST THE STANDARD, FORMAT, BRIGHTNESS, CONTRAST, SATURATION AND HUE
446 * ON THE BASIS OF INFORMATION IN STRUCTURE easycap.inputset[input].
447 * RESUBMIT THE URBS IF STREAMING WAS ALREADY IN PROGRESS.
450 * THIS ROUTINE MAY BE CALLED FREQUENTLY BY ZONEMINDER VIA IOCTL,
451 * SO IT SHOULD WRITE ONLY SPARINGLY TO THE LOGFILE.
453 /*---------------------------------------------------------------------------*/
455 newinput(struct easycap
*peasycap
, int input
)
457 int rc
, k
, m
, mood
, off
;
458 int inputnow
, video_idlenow
, audio_idlenow
;
461 if (NULL
== peasycap
) {
462 SAY("ERROR: peasycap is NULL\n");
465 JOM(8, "%i=input sought\n", input
);
467 if (0 > input
&& INPUT_MANY
<= input
)
469 inputnow
= peasycap
->input
;
470 if (input
== inputnow
)
472 /*---------------------------------------------------------------------------*/
474 * IF STREAMING IS IN PROGRESS THE URBS ARE KILLED AT THIS
475 * STAGE AND WILL BE RESUBMITTED PRIOR TO EXIT FROM THE ROUTINE.
476 * IF NO STREAMING IS IN PROGRESS NO URBS WILL BE SUBMITTED BY THE
479 /*---------------------------------------------------------------------------*/
480 video_idlenow
= peasycap
->video_idle
;
481 audio_idlenow
= peasycap
->audio_idle
;
483 peasycap
->video_idle
= 1;
484 peasycap
->audio_idle
= 1;
485 if (peasycap
->video_isoc_streaming
) {
487 kill_video_urbs(peasycap
);
490 /*---------------------------------------------------------------------------*/
491 if (NULL
== peasycap
->pusb_device
) {
492 SAM("ERROR: peasycap->pusb_device is NULL\n");
495 rc
= usb_set_interface(peasycap
->pusb_device
,
496 peasycap
->video_interface
, \
497 peasycap
->video_altsetting_off
);
499 SAM("ERROR: usb_set_interface() returned %i\n", rc
);
502 rc
= stop_100(peasycap
->pusb_device
);
504 SAM("ERROR: stop_100() returned %i\n", rc
);
507 for (k
= 0; k
< FIELD_BUFFER_MANY
; k
++) {
508 for (m
= 0; m
< FIELD_BUFFER_SIZE
/PAGE_SIZE
; m
++)
509 memset(peasycap
->field_buffer
[k
][m
].pgo
, 0, PAGE_SIZE
);
511 for (k
= 0; k
< FRAME_BUFFER_MANY
; k
++) {
512 for (m
= 0; m
< FRAME_BUFFER_SIZE
/PAGE_SIZE
; m
++)
513 memset(peasycap
->frame_buffer
[k
][m
].pgo
, 0, PAGE_SIZE
);
515 peasycap
->field_page
= 0;
516 peasycap
->field_read
= 0;
517 peasycap
->field_fill
= 0;
519 peasycap
->frame_read
= 0;
520 peasycap
->frame_fill
= 0;
521 for (k
= 0; k
< peasycap
->input
; k
++) {
522 (peasycap
->frame_fill
)++;
523 if (peasycap
->frame_buffer_many
<= peasycap
->frame_fill
)
524 peasycap
->frame_fill
= 0;
526 peasycap
->input
= input
;
527 select_input(peasycap
->pusb_device
, peasycap
->input
, 9);
528 /*---------------------------------------------------------------------------*/
529 if (input
== peasycap
->inputset
[input
].input
) {
530 off
= peasycap
->inputset
[input
].standard_offset
;
531 if (off
!= peasycap
->standard_offset
) {
532 rc
= adjust_standard(peasycap
, \
533 easycap_standard
[off
].v4l2_standard
.id
);
535 SAM("ERROR: adjust_standard() returned %i\n", rc
);
538 JOM(8, "%i=peasycap->standard_offset\n", \
539 peasycap
->standard_offset
);
541 JOM(8, "%i=peasycap->standard_offset unchanged\n", \
542 peasycap
->standard_offset
);
544 off
= peasycap
->inputset
[input
].format_offset
;
545 if (off
!= peasycap
->format_offset
) {
546 rc
= adjust_format(peasycap
, \
547 easycap_format
[off
].v4l2_format
.fmt
.pix
.width
, \
548 easycap_format
[off
].v4l2_format
.fmt
.pix
.height
, \
549 easycap_format
[off
].v4l2_format
.fmt
.pix
.pixelformat
, \
550 easycap_format
[off
].v4l2_format
.fmt
.pix
.field
, false);
552 SAM("ERROR: adjust_format() returned %i\n", rc
);
555 JOM(8, "%i=peasycap->format_offset\n", peasycap
->format_offset
);
557 JOM(8, "%i=peasycap->format_offset unchanged\n", \
558 peasycap
->format_offset
);
560 mood
= peasycap
->inputset
[input
].brightness
;
561 if (mood
!= peasycap
->brightness
) {
562 rc
= adjust_brightness(peasycap
, mood
);
564 SAM("ERROR: adjust_brightness returned %i\n", rc
);
567 JOM(8, "%i=peasycap->brightness\n", peasycap
->brightness
);
569 mood
= peasycap
->inputset
[input
].contrast
;
570 if (mood
!= peasycap
->contrast
) {
571 rc
= adjust_contrast(peasycap
, mood
);
573 SAM("ERROR: adjust_contrast returned %i\n", rc
);
576 JOM(8, "%i=peasycap->contrast\n", peasycap
->contrast
);
578 mood
= peasycap
->inputset
[input
].saturation
;
579 if (mood
!= peasycap
->saturation
) {
580 rc
= adjust_saturation(peasycap
, mood
);
582 SAM("ERROR: adjust_saturation returned %i\n", rc
);
585 JOM(8, "%i=peasycap->saturation\n", peasycap
->saturation
);
587 mood
= peasycap
->inputset
[input
].hue
;
588 if (mood
!= peasycap
->hue
) {
589 rc
= adjust_hue(peasycap
, mood
);
591 SAM("ERROR: adjust_hue returned %i\n", rc
);
594 JOM(8, "%i=peasycap->hue\n", peasycap
->hue
);
597 SAM("MISTAKE: easycap.inputset[%i] unpopulated\n", input
);
600 /*---------------------------------------------------------------------------*/
601 if (NULL
== peasycap
->pusb_device
) {
602 SAM("ERROR: peasycap->pusb_device is NULL\n");
605 rc
= usb_set_interface(peasycap
->pusb_device
,
606 peasycap
->video_interface
, \
607 peasycap
->video_altsetting_on
);
609 SAM("ERROR: usb_set_interface() returned %i\n", rc
);
612 rc
= start_100(peasycap
->pusb_device
);
614 SAM("ERROR: start_100() returned %i\n", rc
);
617 if (true == resubmit
)
618 submit_video_urbs(peasycap
);
620 peasycap
->video_isoc_sequence
= VIDEO_ISOC_BUFFER_MANY
- 1;
621 peasycap
->video_idle
= video_idlenow
;
622 peasycap
->audio_idle
= audio_idlenow
;
623 peasycap
->video_junk
= 0;
627 /*****************************************************************************/
629 submit_video_urbs(struct easycap
*peasycap
)
631 struct data_urb
*pdata_urb
;
633 struct list_head
*plist_head
;
634 int j
, isbad
, nospc
, m
, rc
;
637 if (NULL
== peasycap
) {
638 SAY("ERROR: peasycap is NULL\n");
642 if (NULL
== peasycap
->purb_video_head
) {
643 SAY("ERROR: peasycap->urb_video_head uninitialized\n");
646 if (NULL
== peasycap
->pusb_device
) {
647 SAY("ERROR: peasycap->pusb_device is NULL\n");
650 if (!peasycap
->video_isoc_streaming
) {
651 JOM(4, "submission of all video urbs\n");
652 isbad
= 0; nospc
= 0; m
= 0;
653 list_for_each(plist_head
, (peasycap
->purb_video_head
)) {
654 pdata_urb
= list_entry(plist_head
, struct data_urb
, list_head
);
655 if (NULL
!= pdata_urb
) {
656 purb
= pdata_urb
->purb
;
658 isbuf
= pdata_urb
->isbuf
;
660 purb
->dev
= peasycap
->pusb_device
;
662 usb_rcvisocpipe(peasycap
->pusb_device
,\
663 peasycap
->video_endpointnumber
);
664 purb
->transfer_flags
= URB_ISO_ASAP
;
665 purb
->transfer_buffer
= \
666 peasycap
->video_isoc_buffer
[isbuf
].pgo
;
667 purb
->transfer_buffer_length
= \
668 peasycap
->video_isoc_buffer_size
;
669 purb
->complete
= easycap_complete
;
670 purb
->context
= peasycap
;
671 purb
->start_frame
= 0;
672 purb
->number_of_packets
= \
673 peasycap
->video_isoc_framesperdesc
;
675 for (j
= 0; j
< peasycap
->\
676 video_isoc_framesperdesc
; j
++) {
677 purb
->iso_frame_desc
[j
].\
680 video_isoc_maxframesize
;
681 purb
->iso_frame_desc
[j
].\
683 video_isoc_maxframesize
;
686 rc
= usb_submit_urb(purb
, GFP_KERNEL
);
689 SAM("ERROR: usb_submit_urb() failed " \
690 "for urb with rc:\n");
693 SAM("ERROR: -ENOMEM=" \
694 "usb_submit_urb()\n");
698 SAM("ERROR: -ENODEV=" \
699 "usb_submit_urb()\n");
703 SAM("ERROR: -ENXIO=" \
704 "usb_submit_urb()\n");
708 SAM("ERROR: -EINVAL=" \
709 "usb_submit_urb()\n");
713 SAM("ERROR: -EAGAIN=" \
714 "usb_submit_urb()\n");
718 SAM("ERROR: -EFBIG=" \
719 "usb_submit_urb()\n");
723 SAM("ERROR: -EPIPE=" \
724 "usb_submit_urb()\n");
728 SAM("ERROR: -EMSGSIZE=" \
729 "usb_submit_urb()\n");
738 "usb_submit_urb()\n",\
754 SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc
);
755 SAM("..... possibly inadequate USB bandwidth\n");
756 peasycap
->video_eof
= 1;
760 JOM(4, "attempting cleanup instead of submitting\n");
761 list_for_each(plist_head
, (peasycap
->purb_video_head
)) {
762 pdata_urb
= list_entry(plist_head
, struct data_urb
, \
764 if (NULL
!= pdata_urb
) {
765 purb
= pdata_urb
->purb
;
770 peasycap
->video_isoc_streaming
= 0;
772 peasycap
->video_isoc_streaming
= 1;
773 JOM(4, "submitted %i video urbs\n", m
);
776 JOM(4, "already streaming video urbs\n");
780 /*****************************************************************************/
782 kill_video_urbs(struct easycap
*peasycap
)
785 struct list_head
*plist_head
;
786 struct data_urb
*pdata_urb
;
788 if (NULL
== peasycap
) {
789 SAY("ERROR: peasycap is NULL\n");
792 if (peasycap
->video_isoc_streaming
) {
793 if ((struct list_head
*)NULL
!= peasycap
->purb_video_head
) {
794 peasycap
->video_isoc_streaming
= 0;
795 JOM(4, "killing video urbs\n");
797 list_for_each(plist_head
, (peasycap
->purb_video_head
)) {
798 pdata_urb
= list_entry(plist_head
, struct data_urb
, \
800 if (NULL
!= pdata_urb
) {
801 if (NULL
!= pdata_urb
->purb
) {
802 usb_kill_urb(pdata_urb
->purb
);
807 JOM(4, "%i video urbs killed\n", m
);
809 SAM("ERROR: peasycap->purb_video_head is NULL\n");
813 JOM(8, "%i=video_isoc_streaming, no video urbs killed\n", \
814 peasycap
->video_isoc_streaming
);
818 /****************************************************************************/
819 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
820 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
822 easycap_release_noinode(struct file
*file
)
824 return easycap_release((struct inode
*)NULL
, file
);
826 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
827 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
828 /*--------------------------------------------------------------------------*/
830 easycap_release(struct inode
*inode
, struct file
*file
)
832 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
833 struct easycap
*peasycap
;
837 peasycap
= file
->private_data
;
838 if (NULL
== peasycap
) {
839 SAY("ERROR: peasycap is NULL.\n");
840 SAY("ending unsuccessfully\n");
843 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
844 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
847 if (0 != kill_video_urbs(peasycap
)) {
848 SAM("ERROR: kill_video_urbs() failed\n");
851 JOM(4, "ending successfully\n");
852 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
855 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
856 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
860 /****************************************************************************/
861 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
862 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
864 videodev_release(struct video_device
*pvideo_device
)
866 struct easycap
*peasycap
;
870 peasycap
= video_get_drvdata(pvideo_device
);
871 if (NULL
== peasycap
) {
872 SAY("ERROR: peasycap is NULL\n");
873 SAY("ending unsuccessfully\n");
876 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
877 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
880 if (0 != kill_video_urbs(peasycap
)) {
881 SAM("ERROR: kill_video_urbs() failed\n");
884 JOM(4, "ending successfully\n");
887 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
888 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
889 /*****************************************************************************/
890 /*--------------------------------------------------------------------------*/
892 * THIS FUNCTION IS CALLED FROM WITHIN easycap_usb_disconnect() AND IS
893 * PROTECTED BY SEMAPHORES SET AND CLEARED BY easycap_usb_disconnect().
895 * BY THIS STAGE THE DEVICE HAS ALREADY BEEN PHYSICALLY UNPLUGGED, SO
896 * peasycap->pusb_device IS NO LONGER VALID.
898 /*---------------------------------------------------------------------------*/
900 easycap_delete(struct kref
*pkref
)
903 int allocation_video_urb
, allocation_video_page
, allocation_video_struct
;
904 int allocation_audio_urb
, allocation_audio_page
, allocation_audio_struct
;
905 int registered_video
, registered_audio
;
906 struct easycap
*peasycap
;
907 struct data_urb
*pdata_urb
;
908 struct list_head
*plist_head
, *plist_next
;
912 peasycap
= container_of(pkref
, struct easycap
, kref
);
913 if (NULL
== peasycap
) {
914 SAM("ERROR: peasycap is NULL: cannot perform deletions\n");
917 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
918 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
921 kd
= isdongle(peasycap
);
922 /*---------------------------------------------------------------------------*/
926 /*---------------------------------------------------------------------------*/
927 if ((struct list_head
*)NULL
!= peasycap
->purb_video_head
) {
928 JOM(4, "freeing video urbs\n");
930 list_for_each(plist_head
, (peasycap
->purb_video_head
)) {
931 pdata_urb
= list_entry(plist_head
, struct data_urb
, list_head
);
932 if (NULL
== pdata_urb
)
933 JOM(4, "ERROR: pdata_urb is NULL\n");
935 if ((struct urb
*)NULL
!= pdata_urb
->purb
) {
936 usb_free_urb(pdata_urb
->purb
);
937 pdata_urb
->purb
= (struct urb
*)NULL
;
938 peasycap
->allocation_video_urb
-= 1;
944 JOM(4, "%i video urbs freed\n", m
);
945 /*---------------------------------------------------------------------------*/
946 JOM(4, "freeing video data_urb structures.\n");
948 list_for_each_safe(plist_head
, plist_next
, peasycap
->purb_video_head
) {
949 pdata_urb
= list_entry(plist_head
, struct data_urb
, list_head
);
950 if ((struct data_urb
*)NULL
!= pdata_urb
) {
951 kfree(pdata_urb
); pdata_urb
= (struct data_urb
*)NULL
;
952 peasycap
->allocation_video_struct
-= \
953 sizeof(struct data_urb
);
957 JOM(4, "%i video data_urb structures freed\n", m
);
958 JOM(4, "setting peasycap->purb_video_head=NULL\n");
959 peasycap
->purb_video_head
= (struct list_head
*)NULL
;
961 /*---------------------------------------------------------------------------*/
962 JOM(4, "freeing video isoc buffers.\n");
964 for (k
= 0; k
< VIDEO_ISOC_BUFFER_MANY
; k
++) {
965 if ((void *)NULL
!= peasycap
->video_isoc_buffer
[k
].pgo
) {
966 free_pages((unsigned long)\
967 (peasycap
->video_isoc_buffer
[k
].pgo
), \
969 peasycap
->video_isoc_buffer
[k
].pgo
= (void *)NULL
;
970 peasycap
->allocation_video_page
-= \
971 ((unsigned int)(0x01 << VIDEO_ISOC_ORDER
));
975 JOM(4, "isoc video buffers freed: %i pages\n", m
* (0x01 << VIDEO_ISOC_ORDER
));
976 /*---------------------------------------------------------------------------*/
977 JOM(4, "freeing video field buffers.\n");
979 for (k
= 0; k
< FIELD_BUFFER_MANY
; k
++) {
980 for (m
= 0; m
< FIELD_BUFFER_SIZE
/PAGE_SIZE
; m
++) {
981 if ((void *)NULL
!= peasycap
->field_buffer
[k
][m
].pgo
) {
982 free_page((unsigned long)\
983 (peasycap
->field_buffer
[k
][m
].pgo
));
984 peasycap
->field_buffer
[k
][m
].pgo
= (void *)NULL
;
985 peasycap
->allocation_video_page
-= 1;
990 JOM(4, "video field buffers freed: %i pages\n", gone
);
991 /*---------------------------------------------------------------------------*/
992 JOM(4, "freeing video frame buffers.\n");
994 for (k
= 0; k
< FRAME_BUFFER_MANY
; k
++) {
995 for (m
= 0; m
< FRAME_BUFFER_SIZE
/PAGE_SIZE
; m
++) {
996 if ((void *)NULL
!= peasycap
->frame_buffer
[k
][m
].pgo
) {
997 free_page((unsigned long)\
998 (peasycap
->frame_buffer
[k
][m
].pgo
));
999 peasycap
->frame_buffer
[k
][m
].pgo
= (void *)NULL
;
1000 peasycap
->allocation_video_page
-= 1;
1005 JOM(4, "video frame buffers freed: %i pages\n", gone
);
1006 /*---------------------------------------------------------------------------*/
1010 /*---------------------------------------------------------------------------*/
1011 if ((struct list_head
*)NULL
!= peasycap
->purb_audio_head
) {
1012 JOM(4, "freeing audio urbs\n");
1014 list_for_each(plist_head
, (peasycap
->purb_audio_head
)) {
1015 pdata_urb
= list_entry(plist_head
, struct data_urb
, list_head
);
1016 if (NULL
== pdata_urb
)
1017 JOM(4, "ERROR: pdata_urb is NULL\n");
1019 if ((struct urb
*)NULL
!= pdata_urb
->purb
) {
1020 usb_free_urb(pdata_urb
->purb
);
1021 pdata_urb
->purb
= (struct urb
*)NULL
;
1022 peasycap
->allocation_audio_urb
-= 1;
1027 JOM(4, "%i audio urbs freed\n", m
);
1028 /*---------------------------------------------------------------------------*/
1029 JOM(4, "freeing audio data_urb structures.\n");
1031 list_for_each_safe(plist_head
, plist_next
, peasycap
->purb_audio_head
) {
1032 pdata_urb
= list_entry(plist_head
, struct data_urb
, list_head
);
1033 if ((struct data_urb
*)NULL
!= pdata_urb
) {
1034 kfree(pdata_urb
); pdata_urb
= (struct data_urb
*)NULL
;
1035 peasycap
->allocation_audio_struct
-= \
1036 sizeof(struct data_urb
);
1040 JOM(4, "%i audio data_urb structures freed\n", m
);
1041 JOM(4, "setting peasycap->purb_audio_head=NULL\n");
1042 peasycap
->purb_audio_head
= (struct list_head
*)NULL
;
1044 /*---------------------------------------------------------------------------*/
1045 JOM(4, "freeing audio isoc buffers.\n");
1047 for (k
= 0; k
< AUDIO_ISOC_BUFFER_MANY
; k
++) {
1048 if ((void *)NULL
!= peasycap
->audio_isoc_buffer
[k
].pgo
) {
1049 free_pages((unsigned long)\
1050 (peasycap
->audio_isoc_buffer
[k
].pgo
), \
1052 peasycap
->audio_isoc_buffer
[k
].pgo
= (void *)NULL
;
1053 peasycap
->allocation_audio_page
-= \
1054 ((unsigned int)(0x01 << AUDIO_ISOC_ORDER
));
1058 JOM(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \
1059 m
* (0x01 << AUDIO_ISOC_ORDER
));
1060 /*---------------------------------------------------------------------------*/
1061 JOM(4, "freeing audio buffers.\n");
1063 for (k
= 0; k
< peasycap
->audio_buffer_page_many
; k
++) {
1064 if ((void *)NULL
!= peasycap
->audio_buffer
[k
].pgo
) {
1065 free_page((unsigned long)(peasycap
->audio_buffer
[k
].pgo
));
1066 peasycap
->audio_buffer
[k
].pgo
= (void *)NULL
;
1067 peasycap
->allocation_audio_page
-= 1;
1071 JOM(4, "easysnd_delete(): audio buffers freed: %i pages\n", gone
);
1072 /*---------------------------------------------------------------------------*/
1073 JOM(4, "freeing easycap structure.\n");
1074 allocation_video_urb
= peasycap
->allocation_video_urb
;
1075 allocation_video_page
= peasycap
->allocation_video_page
;
1076 allocation_video_struct
= peasycap
->allocation_video_struct
;
1077 registered_video
= peasycap
->registered_video
;
1078 allocation_audio_urb
= peasycap
->allocation_audio_urb
;
1079 allocation_audio_page
= peasycap
->allocation_audio_page
;
1080 allocation_audio_struct
= peasycap
->allocation_audio_struct
;
1081 registered_audio
= peasycap
->registered_audio
;
1084 if (0 <= kd
&& DONGLE_MANY
> kd
) {
1085 easycap_dongle
[kd
].peasycap
= (struct easycap
*)NULL
;
1086 JOT(4, " null-->easycap_dongle[%i].peasycap\n", kd
);
1087 allocation_video_struct
-= sizeof(struct easycap
);
1089 SAY("ERROR: cannot purge easycap_dongle[].peasycap");
1091 /*---------------------------------------------------------------------------*/
1092 SAY("%8i= video urbs after all deletions\n", allocation_video_urb
);
1093 SAY("%8i= video pages after all deletions\n", allocation_video_page
);
1094 SAY("%8i= video structs after all deletions\n", allocation_video_struct
);
1095 SAY("%8i= video devices after all deletions\n", registered_video
);
1096 SAY("%8i= audio urbs after all deletions\n", allocation_audio_urb
);
1097 SAY("%8i= audio pages after all deletions\n", allocation_audio_page
);
1098 SAY("%8i= audio structs after all deletions\n", allocation_audio_struct
);
1099 SAY("%8i= audio devices after all deletions\n", registered_audio
);
1101 JOT(4, "ending.\n");
1104 /*****************************************************************************/
1105 unsigned int easycap_poll(struct file
*file
, poll_table
*wait
)
1107 struct easycap
*peasycap
;
1112 if (NULL
== ((poll_table
*)wait
))
1113 JOT(8, "WARNING: poll table pointer is NULL ... continuing\n");
1114 if ((struct file
*)NULL
== file
) {
1115 SAY("ERROR: file pointer is NULL\n");
1116 return -ERESTARTSYS
;
1118 peasycap
= file
->private_data
;
1119 if (NULL
== peasycap
) {
1120 SAY("ERROR: peasycap is NULL\n");
1123 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
1124 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
1127 if (NULL
== peasycap
->pusb_device
) {
1128 SAY("ERROR: peasycap->pusb_device is NULL\n");
1131 /*---------------------------------------------------------------------------*/
1132 kd
= isdongle(peasycap
);
1133 if (0 <= kd
&& DONGLE_MANY
> kd
) {
1134 if (mutex_lock_interruptible(&easycap_dongle
[kd
].mutex_video
)) {
1135 SAY("ERROR: cannot down easycap_dongle[%i].mutex_video\n", kd
);
1136 return -ERESTARTSYS
;
1138 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd
);
1139 /*-------------------------------------------------------------------*/
1141 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER
1142 * peasycap, IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
1143 * IF NECESSARY, BAIL OUT.
1145 /*-------------------------------------------------------------------*/
1146 if (kd
!= isdongle(peasycap
))
1147 return -ERESTARTSYS
;
1149 SAY("ERROR: file is NULL\n");
1150 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
1151 return -ERESTARTSYS
;
1153 peasycap
= file
->private_data
;
1154 if (NULL
== peasycap
) {
1155 SAY("ERROR: peasycap is NULL\n");
1156 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
1157 return -ERESTARTSYS
;
1159 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
1160 SAY("ERROR: bad peasycap: 0x%08lX\n", \
1161 (unsigned long int) peasycap
);
1162 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
1163 return -ERESTARTSYS
;
1165 if (NULL
== peasycap
->pusb_device
) {
1166 SAM("ERROR: peasycap->pusb_device is NULL\n");
1167 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
1168 return -ERESTARTSYS
;
1171 /*-------------------------------------------------------------------*/
1173 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap
1174 * BEFORE THE ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL
1175 * HAVE FAILED. BAIL OUT.
1177 /*-------------------------------------------------------------------*/
1178 return -ERESTARTSYS
;
1179 /*---------------------------------------------------------------------------*/
1180 rc
= easycap_dqbuf(peasycap
, 0);
1181 peasycap
->polled
= 1;
1182 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
1184 return POLLIN
| POLLRDNORM
;
1188 /*****************************************************************************/
1189 /*---------------------------------------------------------------------------*/
1191 * IF mode IS NONZERO THIS ROUTINE RETURNS -EAGAIN RATHER THAN BLOCKING.
1193 /*---------------------------------------------------------------------------*/
1195 easycap_dqbuf(struct easycap
*peasycap
, int mode
)
1197 int input
, ifield
, miss
, rc
;
1201 if (NULL
== peasycap
) {
1202 SAY("ERROR: peasycap is NULL\n");
1205 if (NULL
== peasycap
->pusb_device
) {
1206 SAY("ERROR: peasycap->pusb_device is NULL\n");
1210 JOM(8, "%i=ifield\n", ifield
);
1211 /*---------------------------------------------------------------------------*/
1213 * CHECK FOR LOST INPUT SIGNAL.
1215 * FOR THE FOUR-CVBS EasyCAP, THIS DOES NOT WORK AS EXPECTED.
1216 * IF INPUT 0 IS PRESENT AND SYNC ACQUIRED, UNPLUGGING INPUT 4 DOES NOT
1217 * RESULT IN SETTING BIT 0x40 ON REGISTER 0x1F, PRESUMABLY BECAUSE THERE
1218 * IS FLYWHEELING ON INPUT 0. THE UPSHOT IS:
1220 * INPUT 0 PLUGGED, INPUT 4 PLUGGED => SCREEN 0 OK, SCREEN 4 OK
1221 * INPUT 0 PLUGGED, INPUT 4 UNPLUGGED => SCREEN 0 OK, SCREEN 4 BLACK
1222 * INPUT 0 UNPLUGGED, INPUT 4 PLUGGED => SCREEN 0 BARS, SCREEN 4 OK
1223 * INPUT 0 UNPLUGGED, INPUT 4 UNPLUGGED => SCREEN 0 BARS, SCREEN 4 BARS
1225 /*---------------------------------------------------------------------------*/
1226 input
= peasycap
->input
;
1227 if (0 <= input
&& INPUT_MANY
> input
) {
1228 rc
= read_saa(peasycap
->pusb_device
, 0x1F);
1231 peasycap
->lost
[input
] += 1;
1233 peasycap
->lost
[input
] -= 2;
1235 if (0 > peasycap
->lost
[input
])
1236 peasycap
->lost
[input
] = 0;
1237 else if ((2 * VIDEO_LOST_TOLERATE
) < peasycap
->lost
[input
])
1238 peasycap
->lost
[input
] = (2 * VIDEO_LOST_TOLERATE
);
1241 /*---------------------------------------------------------------------------*/
1243 * WAIT FOR FIELD ifield (0 => TOP, 1 => BOTTOM)
1245 /*---------------------------------------------------------------------------*/
1247 while ((peasycap
->field_read
== peasycap
->field_fill
) || \
1248 (0 != (0xFF00 & peasycap
->field_buffer\
1249 [peasycap
->field_read
][0].kount
)) || \
1250 (ifield
!= (0x00FF & peasycap
->field_buffer\
1251 [peasycap
->field_read
][0].kount
))) {
1255 JOM(8, "first wait on wq_video, " \
1256 "%i=field_read %i=field_fill\n", \
1257 peasycap
->field_read
, peasycap
->field_fill
);
1259 if (0 != (wait_event_interruptible(peasycap
->wq_video
, \
1260 (peasycap
->video_idle
|| peasycap
->video_eof
|| \
1261 ((peasycap
->field_read
!= peasycap
->field_fill
) && \
1262 (0 == (0xFF00 & peasycap
->field_buffer\
1263 [peasycap
->field_read
][0].kount
)) && \
1264 (ifield
== (0x00FF & peasycap
->field_buffer\
1265 [peasycap
->field_read
][0].kount
))))))) {
1266 SAM("aborted by signal\n");
1269 if (peasycap
->video_idle
) {
1270 JOM(8, "%i=peasycap->video_idle ... returning -EAGAIN\n", \
1271 peasycap
->video_idle
);
1274 if (peasycap
->video_eof
) {
1275 JOM(8, "%i=peasycap->video_eof\n", peasycap
->video_eof
);
1276 #if defined(PERSEVERE)
1277 if (1 == peasycap
->status
) {
1278 JOM(8, "persevering ...\n");
1279 peasycap
->video_eof
= 0;
1280 peasycap
->audio_eof
= 0;
1281 if (0 != reset(peasycap
)) {
1282 JOM(8, " ... failed ... returning -EIO\n");
1283 peasycap
->video_eof
= 1;
1284 peasycap
->audio_eof
= 1;
1285 kill_video_urbs(peasycap
);
1288 peasycap
->status
= 0;
1289 JOM(8, " ... OK ... returning -EAGAIN\n");
1292 #endif /*PERSEVERE*/
1293 peasycap
->video_eof
= 1;
1294 peasycap
->audio_eof
= 1;
1295 kill_video_urbs(peasycap
);
1296 JOM(8, "returning -EIO\n");
1301 JOM(8, "first awakening on wq_video after %i waits\n", miss
);
1303 rc
= field2frame(peasycap
);
1305 SAM("ERROR: field2frame() returned %i\n", rc
);
1306 /*---------------------------------------------------------------------------*/
1308 * WAIT FOR THE OTHER FIELD
1310 /*---------------------------------------------------------------------------*/
1316 while ((peasycap
->field_read
== peasycap
->field_fill
) || \
1317 (0 != (0xFF00 & peasycap
->field_buffer\
1318 [peasycap
->field_read
][0].kount
)) || \
1319 (ifield
!= (0x00FF & peasycap
->field_buffer\
1320 [peasycap
->field_read
][0].kount
))) {
1324 JOM(8, "second wait on wq_video, " \
1325 "%i=field_read %i=field_fill\n", \
1326 peasycap
->field_read
, peasycap
->field_fill
);
1327 if (0 != (wait_event_interruptible(peasycap
->wq_video
, \
1328 (peasycap
->video_idle
|| peasycap
->video_eof
|| \
1329 ((peasycap
->field_read
!= peasycap
->field_fill
) && \
1330 (0 == (0xFF00 & peasycap
->field_buffer\
1331 [peasycap
->field_read
][0].kount
)) && \
1332 (ifield
== (0x00FF & peasycap
->field_buffer\
1333 [peasycap
->field_read
][0].\
1335 SAM("aborted by signal\n");
1338 if (peasycap
->video_idle
) {
1339 JOM(8, "%i=peasycap->video_idle ... returning -EAGAIN\n", \
1340 peasycap
->video_idle
);
1343 if (peasycap
->video_eof
) {
1344 JOM(8, "%i=peasycap->video_eof\n", peasycap
->video_eof
);
1345 #if defined(PERSEVERE)
1346 if (1 == peasycap
->status
) {
1347 JOM(8, "persevering ...\n");
1348 peasycap
->video_eof
= 0;
1349 peasycap
->audio_eof
= 0;
1350 if (0 != reset(peasycap
)) {
1351 JOM(8, " ... failed ... returning -EIO\n");
1352 peasycap
->video_eof
= 1;
1353 peasycap
->audio_eof
= 1;
1354 kill_video_urbs(peasycap
);
1357 peasycap
->status
= 0;
1358 JOM(8, " ... OK ... returning -EAGAIN\n");
1361 #endif /*PERSEVERE*/
1362 peasycap
->video_eof
= 1;
1363 peasycap
->audio_eof
= 1;
1364 kill_video_urbs(peasycap
);
1365 JOM(8, "returning -EIO\n");
1370 JOM(8, "second awakening on wq_video after %i waits\n", miss
);
1372 rc
= field2frame(peasycap
);
1374 SAM("ERROR: field2frame() returned %i\n", rc
);
1375 /*---------------------------------------------------------------------------*/
1379 /*---------------------------------------------------------------------------*/
1380 if (0 != peasycap
->skip
) {
1381 peasycap
->skipped
++;
1382 if (peasycap
->skip
!= peasycap
->skipped
)
1383 return peasycap
->skip
- peasycap
->skipped
;
1384 peasycap
->skipped
= 0;
1386 /*---------------------------------------------------------------------------*/
1387 peasycap
->frame_read
= peasycap
->frame_fill
;
1388 peasycap
->queued
[peasycap
->frame_read
] = 0;
1389 peasycap
->done
[peasycap
->frame_read
] = V4L2_BUF_FLAG_DONE
;
1391 (peasycap
->frame_fill
)++;
1392 if (peasycap
->frame_buffer_many
<= peasycap
->frame_fill
)
1393 peasycap
->frame_fill
= 0;
1395 if (0x01 & easycap_standard
[peasycap
->standard_offset
].mask
) {
1396 peasycap
->frame_buffer
[peasycap
->frame_read
][0].kount
= \
1399 peasycap
->frame_buffer
[peasycap
->frame_read
][0].kount
= \
1403 JOM(8, "setting: %i=peasycap->frame_read\n", peasycap
->frame_read
);
1404 JOM(8, "bumped to: %i=peasycap->frame_fill\n", peasycap
->frame_fill
);
1408 /*****************************************************************************/
1409 /*---------------------------------------------------------------------------*/
1411 * BY DEFINITION, odd IS true FOR THE FIELD OCCUPYING LINES 1,3,5,...,479
1412 * odd IS false FOR THE FIELD OCCUPYING LINES 0,2,4,...,478
1414 * WHEN BOOLEAN PARAMETER decimatepixel IS true, ONLY THE FIELD FOR WHICH
1415 * odd==false IS TRANSFERRED TO THE FRAME BUFFER.
1417 * THE BOOLEAN PARAMETER offerfields IS true ONLY WHEN THE USER PROGRAM
1418 * CHOOSES THE OPTION V4L2_FIELD_INTERLACED.
1420 /*---------------------------------------------------------------------------*/
1422 field2frame(struct easycap
*peasycap
)
1424 struct timeval timeval
;
1425 long long int above
, below
;
1427 struct signed_div_result sdr
;
1430 int kex
, kad
, mex
, mad
, rex
, rad
, rad2
;
1431 int c2
, c3
, w2
, w3
, cz
, wz
;
1432 int rc
, bytesperpixel
, multiplier
, much
, more
, over
, rump
, caches
, input
;
1434 bool odd
, isuy
, decimatepixel
, offerfields
, badinput
;
1436 if (NULL
== peasycap
) {
1437 SAY("ERROR: peasycap is NULL\n");
1442 input
= 0x07 & peasycap
->field_buffer
[peasycap
->field_read
][0].input
;
1444 JOM(8, "===== parity %i, input 0x%02X, field buffer %i --> " \
1445 "frame buffer %i\n", \
1446 peasycap
->field_buffer
[peasycap
->field_read
][0].kount
,\
1447 peasycap
->field_buffer
[peasycap
->field_read
][0].input
,\
1448 peasycap
->field_read
, peasycap
->frame_fill
);
1449 JOM(8, "===== %i=bytesperpixel\n", peasycap
->bytesperpixel
);
1450 if (true == peasycap
->offerfields
)
1451 JOM(8, "===== offerfields\n");
1453 /*---------------------------------------------------------------------------*/
1455 * REJECT OR CLEAN BAD FIELDS
1457 /*---------------------------------------------------------------------------*/
1458 if (peasycap
->field_read
== peasycap
->field_fill
) {
1459 SAM("ERROR: on entry, still filling field buffer %i\n", \
1460 peasycap
->field_read
);
1463 #if defined(EASYCAP_TESTCARD)
1464 easycap_testcard(peasycap
, peasycap
->field_read
);
1466 if (0 <= input
&& INPUT_MANY
> input
) {
1467 if (easycap_bars
&& VIDEO_LOST_TOLERATE
<= peasycap
->lost
[input
])
1468 easycap_testcard(peasycap
, peasycap
->field_read
);
1470 #endif /*EASYCAP_TESTCARD*/
1471 /*---------------------------------------------------------------------------*/
1473 offerfields
= peasycap
->offerfields
;
1474 bytesperpixel
= peasycap
->bytesperpixel
;
1475 decimatepixel
= peasycap
->decimatepixel
;
1477 if ((2 != bytesperpixel
) && \
1478 (3 != bytesperpixel
) && \
1479 (4 != bytesperpixel
)) {
1480 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel
);
1483 if (true == decimatepixel
)
1488 w2
= 2 * multiplier
* (peasycap
->width
);
1489 w3
= bytesperpixel
* \
1493 (peasycap
->height
) * \
1497 kex
= peasycap
->field_read
; mex
= 0;
1498 kad
= peasycap
->frame_fill
; mad
= 0;
1500 pex
= peasycap
->field_buffer
[kex
][0].pgo
; rex
= PAGE_SIZE
;
1501 pad
= peasycap
->frame_buffer
[kad
][0].pgo
; rad
= PAGE_SIZE
;
1502 if (peasycap
->field_buffer
[kex
][0].kount
)
1507 if ((true == odd
) && (false == decimatepixel
)) {
1508 JOM(8, " initial skipping %4i bytes p.%4i\n", \
1509 w3
/multiplier
, mad
);
1510 pad
+= (w3
/ multiplier
); rad
-= (w3
/ multiplier
);
1513 mask
= 0; rump
= 0; caches
= 0;
1517 /*-------------------------------------------------------------------*/
1519 ** PROCESS ONE LINE OF FRAME AT FULL RESOLUTION:
1520 ** READ w2 BYTES FROM FIELD BUFFER,
1521 ** WRITE w3 BYTES TO FRAME BUFFER
1523 /*-------------------------------------------------------------------*/
1524 if (false == decimatepixel
) {
1527 much
= over
; more
= 0; margin
= 0; mask
= 0x00;
1533 SAM("MISTAKE: much is odd\n");
1537 more
= (bytesperpixel
* \
1539 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1540 if (1 < bytesperpixel
) {
1541 if (rad
* 2 < much
* bytesperpixel
) {
1543 ** INJUDICIOUS ALTERATION OF THIS
1544 ** STATEMENT BLOCK WILL CAUSE
1545 ** BREAKAGE. BEWARE.
1547 rad2
= rad
+ bytesperpixel
- 1;
1549 rad2
)/bytesperpixel
)/2) * 2);
1550 rump
= ((bytesperpixel
* \
1558 if ((mex
+ 1) < FIELD_BUFFER_SIZE
/ \
1560 margin
= *((__u8
*)(peasycap
->\
1562 [kex
][mex
+ 1].pgo
));
1566 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1568 SAM("MISTAKE: %i=bytesperpixel\n", \
1572 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1575 if (true == badinput
) {
1576 JOM(8, "ERROR: 0x%02X=->field_buffer" \
1577 "[%i][%i].input, " \
1578 "0x%02X=(0x08|->input)\n", \
1579 peasycap
->field_buffer\
1580 [kex
][mex
].input
, kex
, mex
, \
1581 (0x08|peasycap
->input
));
1583 rc
= redaub(peasycap
, pad
, pex
, much
, more
, \
1584 mask
, margin
, isuy
);
1586 SAM("ERROR: redaub() failed\n");
1595 over
-= much
; cz
+= much
;
1596 pex
+= much
; rex
-= much
;
1599 pex
= peasycap
->field_buffer
[kex
][mex
].pgo
;
1601 if (peasycap
->field_buffer
[kex
][mex
].input
!= \
1602 (0x08|peasycap
->input
))
1609 pad
= peasycap
->frame_buffer
[kad
][mad
].pgo
;
1617 /*---------------------------------------------------------------------------*/
1619 * SKIP w3 BYTES IN TARGET FRAME BUFFER,
1620 * UNLESS IT IS THE LAST LINE OF AN ODD FRAME
1622 /*---------------------------------------------------------------------------*/
1623 if ((false == odd
) || (cz
!= wz
)) {
1628 pad
= peasycap
->frame_buffer\
1640 /*---------------------------------------------------------------------------*/
1642 * PROCESS ONE LINE OF FRAME AT REDUCED RESOLUTION:
1643 * ONLY IF false==odd,
1644 * READ w2 BYTES FROM FIELD BUFFER,
1645 * WRITE w3 / 2 BYTES TO FRAME BUFFER
1647 /*---------------------------------------------------------------------------*/
1648 } else if (false == odd
) {
1651 much
= over
; more
= 0; margin
= 0; mask
= 0x00;
1657 SAM("MISTAKE: much is odd\n");
1661 more
= (bytesperpixel
* \
1663 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1664 if (1 < bytesperpixel
) {
1665 if (rad
* 4 < much
* bytesperpixel
) {
1667 ** INJUDICIOUS ALTERATION OF THIS
1668 ** STATEMENT BLOCK WILL CAUSE
1669 ** BREAKAGE. BEWARE.
1671 rad2
= rad
+ bytesperpixel
- 1;
1672 much
= ((((2 * rad2
)/bytesperpixel
)/2)\
1674 rump
= ((bytesperpixel
* \
1682 if ((mex
+ 1) < FIELD_BUFFER_SIZE
/ \
1684 margin
= *((__u8
*)(peasycap
->\
1686 [kex
][mex
+ 1].pgo
));
1691 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1693 SAM("MISTAKE: %i=bytesperpixel\n", \
1697 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1701 if (true == badinput
) {
1702 JOM(8, "ERROR: 0x%02X=->field_buffer" \
1703 "[%i][%i].input, " \
1704 "0x%02X=(0x08|->input)\n", \
1705 peasycap
->field_buffer\
1706 [kex
][mex
].input
, kex
, mex
, \
1707 (0x08|peasycap
->input
));
1709 rc
= redaub(peasycap
, pad
, pex
, much
, more
, \
1710 mask
, margin
, isuy
);
1712 SAM("ERROR: redaub() failed\n");
1715 over
-= much
; cz
+= much
;
1716 pex
+= much
; rex
-= much
;
1719 pex
= peasycap
->field_buffer
[kex
][mex
].pgo
;
1721 if (peasycap
->field_buffer
[kex
][mex
].input
!= \
1722 (0x08|peasycap
->input
))
1729 pad
= peasycap
->frame_buffer
[kad
][mad
].pgo
;
1737 /*---------------------------------------------------------------------------*/
1740 * READ w2 BYTES FROM FIELD BUFFER AND DISCARD THEM
1742 /*---------------------------------------------------------------------------*/
1748 pex
= peasycap
->field_buffer
[kex
][mex
].pgo
;
1750 if (peasycap
->field_buffer
[kex
][mex
].input
!= \
1751 (0x08|peasycap
->input
)) {
1752 JOM(8, "ERROR: 0x%02X=->field_buffer"\
1753 "[%i][%i].input, " \
1754 "0x%02X=(0x08|->input)\n", \
1755 peasycap
->field_buffer\
1756 [kex
][mex
].input
, kex
, mex
, \
1757 (0x08|peasycap
->input
));
1771 /*---------------------------------------------------------------------------*/
1775 /*---------------------------------------------------------------------------*/
1776 c2
= (mex
+ 1)*PAGE_SIZE
- rex
;
1778 SAM("ERROR: discrepancy %i in bytes read\n", c2
- cz
);
1779 c3
= (mad
+ 1)*PAGE_SIZE
- rad
;
1781 if (false == decimatepixel
) {
1782 if (bytesperpixel
* \
1784 SAM("ERROR: discrepancy %i in bytes written\n", \
1785 c3
- (bytesperpixel
* \
1789 if (bytesperpixel
* \
1791 SAM("ERROR: discrepancy %i in bytes written\n", \
1792 (2*c3
)-(bytesperpixel
* \
1796 SAM("ERROR: discrepancy %i " \
1797 "in bytes written\n", c3
);
1801 SAM("WORRY: undischarged cache at end of line in frame buffer\n");
1803 JOM(8, "===== field2frame(): %i bytes --> %i bytes (incl skip)\n", c2
, c3
);
1804 JOM(8, "===== field2frame(): %i=mad %i=rad\n", mad
, rad
);
1807 JOM(8, "+++++ field2frame(): frame buffer %i is full\n", kad
);
1809 if (peasycap
->field_read
== peasycap
->field_fill
)
1810 SAM("WARNING: on exit, filling field buffer %i\n", \
1811 peasycap
->field_read
);
1812 /*---------------------------------------------------------------------------*/
1814 * CALCULATE VIDEO STREAMING RATE
1816 /*---------------------------------------------------------------------------*/
1817 do_gettimeofday(&timeval
);
1818 if (peasycap
->timeval6
.tv_sec
) {
1819 below
= ((long long int)(1000000)) * \
1820 ((long long int)(timeval
.tv_sec
- \
1821 peasycap
->timeval6
.tv_sec
)) + \
1822 (long long int)(timeval
.tv_usec
- peasycap
->timeval6
.tv_usec
);
1823 above
= (long long int)1000000;
1825 sdr
= signed_div(above
, below
);
1826 above
= sdr
.quotient
;
1827 remainder
= (__u32
)sdr
.remainder
;
1829 JOM(8, "video streaming at %3lli.%03i fields per second\n", above
, \
1832 peasycap
->timeval6
= timeval
;
1835 JOM(8, "%i=caches\n", caches
);
1838 /*****************************************************************************/
1839 struct signed_div_result
1840 signed_div(long long int above
, long long int below
)
1842 struct signed_div_result sdr
;
1844 if (((0 <= above
) && (0 <= below
)) || ((0 > above
) && (0 > below
))) {
1845 sdr
.remainder
= (unsigned long long int) do_div(above
, below
);
1846 sdr
.quotient
= (long long int) above
;
1852 sdr
.remainder
= (unsigned long long int) do_div(above
, below
);
1853 sdr
.quotient
= -((long long int) above
);
1857 /*****************************************************************************/
1858 /*---------------------------------------------------------------------------*/
1860 * DECIMATION AND COLOURSPACE CONVERSION.
1862 * THIS ROUTINE REQUIRES THAT ALL THE DATA TO BE READ RESIDES ON ONE PAGE
1863 * AND THAT ALL THE DATA TO BE WRITTEN RESIDES ON ONE (DIFFERENT) PAGE.
1864 * THE CALLING ROUTINE MUST ENSURE THAT THIS REQUIREMENT IS MET, AND MUST
1865 * ALSO ENSURE THAT much IS EVEN.
1867 * much BYTES ARE READ, AT LEAST (bytesperpixel * much)/2 BYTES ARE WRITTEN
1868 * IF THERE IS NO DECIMATION, HALF THIS AMOUNT IF THERE IS DECIMATION.
1870 * mask IS ZERO WHEN NO SPECIAL BEHAVIOUR REQUIRED. OTHERWISE IT IS SET THUS:
1871 * 0x03 & mask = number of bytes to be written to cache instead of to
1873 * 0x04 & mask => use argument margin to set the chrominance for last pixel
1874 * 0x08 & mask => do not set the chrominance for last pixel
1876 * YUV to RGB CONVERSION IS (OR SHOULD BE) ITU-R BT 601.
1878 * THERE IS A LOT OF CODE REPETITION IN THIS ROUTINE IN ORDER TO AVOID
1879 * INEFFICIENT SWITCHING INSIDE INNER LOOPS. REARRANGING THE LOGIC TO
1880 * REDUCE CODE LENGTH WILL GENERALLY IMPAIR RUNTIME PERFORMANCE. BEWARE.
1882 /*---------------------------------------------------------------------------*/
1884 redaub(struct easycap
*peasycap
, void *pad
, void *pex
, int much
, int more
, \
1885 __u8 mask
, __u8 margin
, bool isuy
)
1887 static __s32 ay
[256], bu
[256], rv
[256], gu
[256], gv
[256];
1889 __u8 r
, g
, b
, y
, u
, v
, c
, *p2
, *p3
, *pz
, *pr
;
1891 bool byteswaporder
, decimatepixel
, last
;
1896 SAM("MISTAKE: much is odd\n");
1899 bytesperpixel
= peasycap
->bytesperpixel
;
1900 byteswaporder
= peasycap
->byteswaporder
;
1901 decimatepixel
= peasycap
->decimatepixel
;
1903 /*---------------------------------------------------------------------------*/
1905 for (j
= 0; j
< 112; j
++) {
1906 s32
= (0xFF00 & (453 * j
)) >> 8;
1907 bu
[j
+ 128] = s32
; bu
[127 - j
] = -s32
;
1908 s32
= (0xFF00 & (359 * j
)) >> 8;
1909 rv
[j
+ 128] = s32
; rv
[127 - j
] = -s32
;
1910 s32
= (0xFF00 & (88 * j
)) >> 8;
1911 gu
[j
+ 128] = s32
; gu
[127 - j
] = -s32
;
1912 s32
= (0xFF00 & (183 * j
)) >> 8;
1913 gv
[j
+ 128] = s32
; gv
[127 - j
] = -s32
;
1915 for (j
= 0; j
< 16; j
++) {
1916 bu
[j
] = bu
[16]; rv
[j
] = rv
[16];
1917 gu
[j
] = gu
[16]; gv
[j
] = gv
[16];
1919 for (j
= 240; j
< 256; j
++) {
1920 bu
[j
] = bu
[239]; rv
[j
] = rv
[239];
1921 gu
[j
] = gu
[239]; gv
[j
] = gv
[239];
1923 for (j
= 16; j
< 236; j
++)
1925 for (j
= 0; j
< 16; j
++)
1927 for (j
= 236; j
< 256; j
++)
1929 JOM(8, "lookup tables are prepared\n");
1931 pcache
= peasycap
->pcache
;
1933 pcache
= &peasycap
->cache
[0];
1934 /*---------------------------------------------------------------------------*/
1936 * TRANSFER CONTENTS OF CACHE TO THE FRAME BUFFER
1938 /*---------------------------------------------------------------------------*/
1940 SAM("MISTAKE: pcache is NULL\n");
1944 if (pcache
!= &peasycap
->cache
[0])
1945 JOM(16, "cache has %i bytes\n", (int)(pcache
- &peasycap
->cache
[0]));
1946 p2
= &peasycap
->cache
[0];
1947 p3
= (__u8
*)pad
- (int)(pcache
- &peasycap
->cache
[0]);
1948 while (p2
< pcache
) {
1951 pcache
= &peasycap
->cache
[0];
1953 SAM("MISTAKE: pointer misalignment\n");
1956 /*---------------------------------------------------------------------------*/
1957 rump
= (int)(0x03 & mask
);
1959 p2
= (__u8
*)pex
; pz
= p2
+ much
; pr
= p3
+ more
; last
= false;
1968 JOM(16, "%4i=much %4i=more %i=rump\n", much
, more
, rump
);
1970 /*---------------------------------------------------------------------------*/
1971 switch (bytesperpixel
) {
1973 if (false == decimatepixel
) {
1974 memcpy(pad
, pex
, (size_t)much
);
1975 if (false == byteswaporder
)
1976 /*---------------------------------------------------*/
1980 /*---------------------------------------------------*/
1983 /*---------------------------------------------------*/
1987 /*---------------------------------------------------*/
1988 p3
= (__u8
*)pad
; pz
= p3
+ much
;
1998 if (false == byteswaporder
) {
1999 /*---------------------------------------------------*/
2003 /*---------------------------------------------------*/
2004 p2
= (__u8
*)pex
; p3
= (__u8
*)pad
; pz
= p2
+ much
;
2007 *(p3
+ 1) = *(p2
+ 1);
2008 *(p3
+ 2) = *(p2
+ 2);
2009 *(p3
+ 3) = *(p2
+ 3);
2014 /*---------------------------------------------------*/
2018 /*---------------------------------------------------*/
2019 p2
= (__u8
*)pex
; p3
= (__u8
*)pad
; pz
= p2
+ much
;
2023 *(p3
+ 2) = *(p2
+ 3);
2024 *(p3
+ 3) = *(p2
+ 2);
2034 if (false == decimatepixel
) {
2035 if (false == byteswaporder
) {
2036 /*---------------------------------------------------*/
2040 /*---------------------------------------------------*/
2042 if (pr
<= (p3
+ bytesperpixel
))
2047 if ((true == last
) && (0x0C & mask
)) {
2063 s32
= ay
[(int)y
] + rv
[(int)v
];
2064 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2066 s32
= ay
[(int)y
] - gu
[(int)u
] - gv
[(int)v
];
2067 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2069 s32
= ay
[(int)y
] + bu
[(int)u
];
2070 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2073 if ((true == last
) && rump
) {
2074 pcache
= &peasycap
->cache
[0];
2075 switch (bytesperpixel
- rump
) {
2089 SAM("MISTAKE: %i=rump\n", \
2090 bytesperpixel
- rump
);
2104 p3
+= bytesperpixel
;
2108 /*---------------------------------------------------*/
2112 /*---------------------------------------------------*/
2114 if (pr
<= (p3
+ bytesperpixel
))
2119 if ((true == last
) && (0x0C & mask
)) {
2136 s32
= ay
[(int)y
] + rv
[(int)v
];
2137 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2139 s32
= ay
[(int)y
] - gu
[(int)u
] - gv
[(int)v
];
2140 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2142 s32
= ay
[(int)y
] + bu
[(int)u
];
2143 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2146 if ((true == last
) && rump
) {
2147 pcache
= &peasycap
->cache
[0];
2148 switch (bytesperpixel
- rump
) {
2162 SAM("MISTAKE: %i=rump\n", \
2163 bytesperpixel
- rump
);
2177 p3
+= bytesperpixel
;
2182 if (false == byteswaporder
) {
2183 /*---------------------------------------------------*/
2187 /*---------------------------------------------------*/
2189 if (pr
<= (p3
+ bytesperpixel
))
2194 if ((true == last
) && (0x0C & mask
)) {
2211 s32
= ay
[(int)y
] + rv
[(int)v
];
2212 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2214 s32
= ay
[(int)y
] - gu
[(int)u
] - \
2216 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2218 s32
= ay
[(int)y
] + bu
[(int)u
];
2219 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2222 if ((true == last
) && rump
) {
2223 pcache
= &peasycap
->cache
[0];
2224 switch (bytesperpixel
- rump
) {
2240 bytesperpixel
- rump
);
2250 p3
+= bytesperpixel
;
2258 /*---------------------------------------------------*/
2262 /*---------------------------------------------------*/
2264 if (pr
<= (p3
+ bytesperpixel
))
2269 if ((true == last
) && (0x0C & mask
)) {
2287 s32
= ay
[(int)y
] + rv
[(int)v
];
2288 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2290 s32
= ay
[(int)y
] - gu
[(int)u
] - \
2292 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2294 s32
= ay
[(int)y
] + bu
[(int)u
];
2295 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2298 if ((true == last
) && rump
) {
2299 pcache
= &peasycap
->cache
[0];
2300 switch (bytesperpixel
- rump
) {
2316 bytesperpixel
- rump
);
2326 p3
+= bytesperpixel
;
2339 if (false == decimatepixel
) {
2340 if (false == byteswaporder
) {
2341 /*---------------------------------------------------*/
2345 /*---------------------------------------------------*/
2347 if (pr
<= (p3
+ bytesperpixel
))
2352 if ((true == last
) && (0x0C & mask
)) {
2368 s32
= ay
[(int)y
] + rv
[(int)v
];
2369 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2371 s32
= ay
[(int)y
] - gu
[(int)u
] - gv
[(int)v
];
2372 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2374 s32
= ay
[(int)y
] + bu
[(int)u
];
2375 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2378 if ((true == last
) && rump
) {
2379 pcache
= &peasycap
->cache
[0];
2380 switch (bytesperpixel
- rump
) {
2403 SAM("MISTAKE: %i=rump\n", \
2404 bytesperpixel
- rump
);
2419 p3
+= bytesperpixel
;
2423 /*---------------------------------------------------*/
2427 /*---------------------------------------------------*/
2429 if (pr
<= (p3
+ bytesperpixel
))
2434 if ((true == last
) && (0x0C & mask
)) {
2450 s32
= ay
[(int)y
] + rv
[(int)v
];
2451 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2453 s32
= ay
[(int)y
] - gu
[(int)u
] - gv
[(int)v
];
2454 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2456 s32
= ay
[(int)y
] + bu
[(int)u
];
2457 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2460 if ((true == last
) && rump
) {
2461 pcache
= &peasycap
->cache
[0];
2462 switch (bytesperpixel
- rump
) {
2485 SAM("MISTAKE: %i=rump\n", \
2486 bytesperpixel
- rump
);
2501 p3
+= bytesperpixel
;
2506 if (false == byteswaporder
) {
2507 /*---------------------------------------------------*/
2511 /*---------------------------------------------------*/
2513 if (pr
<= (p3
+ bytesperpixel
))
2518 if ((true == last
) && (0x0C & mask
)) {
2536 s32
= ay
[(int)y
] + rv
[(int)v
];
2537 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2539 s32
= ay
[(int)y
] - gu
[(int)u
] - \
2541 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2543 s32
= ay
[(int)y
] + bu
[(int)u
];
2544 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2547 if ((true == last
) && rump
) {
2548 pcache
= &peasycap
->cache
[0];
2549 switch (bytesperpixel
- rump
) {
2586 p3
+= bytesperpixel
;
2593 /*---------------------------------------------------*/
2597 /*---------------------------------------------------*/
2599 if (pr
<= (p3
+ bytesperpixel
))
2604 if ((true == last
) && (0x0C & mask
)) {
2621 s32
= ay
[(int)y
] + rv
[(int)v
];
2622 r
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2624 s32
= ay
[(int)y
] - gu
[(int)u
] - \
2626 g
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2628 s32
= ay
[(int)y
] + bu
[(int)u
];
2629 b
= (255 < s32
) ? 255 : ((0 > s32
) ? \
2632 if ((true == last
) && rump
) {
2633 pcache
= &peasycap
->cache
[0];
2634 switch (bytesperpixel
- rump
) {
2659 bytesperpixel
- rump
);
2670 p3
+= bytesperpixel
;
2681 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel
);
2687 /*****************************************************************************/
2688 /*---------------------------------------------------------------------------*/
2690 * SEE CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGES 430-434
2692 /*---------------------------------------------------------------------------*/
2693 int easycap_mmap(struct file
*file
, struct vm_area_struct
*pvma
)
2698 pvma
->vm_ops
= &easycap_vm_ops
;
2699 pvma
->vm_flags
|= VM_RESERVED
;
2701 pvma
->vm_private_data
= file
->private_data
;
2702 easycap_vma_open(pvma
);
2705 /*****************************************************************************/
2707 easycap_vma_open(struct vm_area_struct
*pvma
)
2709 struct easycap
*peasycap
;
2711 peasycap
= pvma
->vm_private_data
;
2712 if (NULL
== peasycap
) {
2713 SAY("ERROR: peasycap is NULL\n");
2716 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
2717 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
2720 peasycap
->vma_many
++;
2721 JOT(8, "%i=peasycap->vma_many\n", peasycap
->vma_many
);
2724 /*****************************************************************************/
2726 easycap_vma_close(struct vm_area_struct
*pvma
)
2728 struct easycap
*peasycap
;
2730 peasycap
= pvma
->vm_private_data
;
2731 if (NULL
== peasycap
) {
2732 SAY("ERROR: peasycap is NULL\n");
2735 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
2736 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
2739 peasycap
->vma_many
--;
2740 JOT(8, "%i=peasycap->vma_many\n", peasycap
->vma_many
);
2743 /*****************************************************************************/
2745 easycap_vma_fault(struct vm_area_struct
*pvma
, struct vm_fault
*pvmf
)
2750 struct easycap
*peasycap
;
2752 retcode
= VM_FAULT_NOPAGE
;
2753 pbuf
= (void *)NULL
;
2754 page
= (struct page
*)NULL
;
2757 SAY("pvma is NULL\n");
2761 SAY("pvmf is NULL\n");
2765 k
= (pvmf
->pgoff
) / (FRAME_BUFFER_SIZE
/PAGE_SIZE
);
2766 m
= (pvmf
->pgoff
) % (FRAME_BUFFER_SIZE
/PAGE_SIZE
);
2769 JOT(4, "%4i=k, %4i=m\n", k
, m
);
2771 JOT(16, "%4i=k, %4i=m\n", k
, m
);
2773 if ((0 > k
) || (FRAME_BUFFER_MANY
<= k
)) {
2774 SAY("ERROR: buffer index %i out of range\n", k
);
2777 if ((0 > m
) || (FRAME_BUFFER_SIZE
/PAGE_SIZE
<= m
)) {
2778 SAY("ERROR: page number %i out of range\n", m
);
2781 peasycap
= pvma
->vm_private_data
;
2782 if (NULL
== peasycap
) {
2783 SAY("ERROR: peasycap is NULL\n");
2786 /*---------------------------------------------------------------------------*/
2787 pbuf
= peasycap
->frame_buffer
[k
][m
].pgo
;
2789 SAM("ERROR: pbuf is NULL\n");
2792 page
= virt_to_page(pbuf
);
2794 SAM("ERROR: page is NULL\n");
2798 /*---------------------------------------------------------------------------*/
2801 SAM("ERROR: page is NULL after get_page(page)\n");
2804 retcode
= VM_FAULT_MINOR
;
2808 /*****************************************************************************/
2809 /*---------------------------------------------------------------------------*/
2811 * ON COMPLETION OF A VIDEO URB ITS DATA IS COPIED TO THE FIELD BUFFERS
2812 * PROVIDED peasycap->video_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
2813 * IT IS RESUBMITTED PROVIDED peasycap->video_isoc_streaming IS NOT ZERO.
2815 * THIS FUNCTION IS AN INTERRUPT SERVICE ROUTINE AND MUST NOT SLEEP.
2817 * INFORMATION ABOUT THE VALIDITY OF THE CONTENTS OF THE FIELD BUFFER ARE
2818 * STORED IN THE TWO-BYTE STATUS PARAMETER
2819 * peasycap->field_buffer[peasycap->field_fill][0].kount
2820 * NOTICE THAT THE INFORMATION IS STORED ONLY WITH PAGE 0 OF THE FIELD BUFFER.
2822 * THE LOWER BYTE CONTAINS THE FIELD PARITY BYTE FURNISHED BY THE SAA7113H
2825 * THE UPPER BYTE IS ZERO IF NO PROBLEMS, OTHERWISE:
2826 * 0 != (kount & 0x8000) => AT LEAST ONE URB COMPLETED WITH ERRORS
2827 * 0 != (kount & 0x4000) => BUFFER HAS TOO MUCH DATA
2828 * 0 != (kount & 0x2000) => BUFFER HAS NOT ENOUGH DATA
2829 * 0 != (kount & 0x1000) => BUFFER HAS DATA FROM DISPARATE INPUTS
2830 * 0 != (kount & 0x0400) => RESERVED
2831 * 0 != (kount & 0x0200) => FIELD BUFFER NOT YET CHECKED
2832 * 0 != (kount & 0x0100) => BUFFER HAS TWO EXTRA BYTES - WHY?
2834 /*---------------------------------------------------------------------------*/
2836 easycap_complete(struct urb
*purb
)
2838 struct easycap
*peasycap
;
2839 struct data_buffer
*pfield_buffer
;
2841 int i
, more
, much
, leap
, rc
, last
;
2842 int videofieldamount
;
2843 unsigned int override
, bad
;
2844 int framestatus
, framelength
, frameactual
, frameoffset
;
2848 SAY("ERROR: easycap_complete(): purb is NULL\n");
2851 peasycap
= purb
->context
;
2852 if (NULL
== peasycap
) {
2853 SAY("ERROR: easycap_complete(): peasycap is NULL\n");
2856 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
2857 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
2860 if (peasycap
->video_eof
)
2862 for (i
= 0; i
< VIDEO_ISOC_BUFFER_MANY
; i
++)
2863 if (purb
->transfer_buffer
== peasycap
->video_isoc_buffer
[i
].pgo
)
2865 JOM(16, "%2i=urb\n", i
);
2866 last
= peasycap
->video_isoc_sequence
;
2867 if ((((VIDEO_ISOC_BUFFER_MANY
- 1) == last
) && \
2869 (((VIDEO_ISOC_BUFFER_MANY
- 1) != last
) && \
2870 ((last
+ 1) != i
))) {
2871 JOM(16, "ERROR: out-of-order urbs %i,%i ... continuing\n", last
, i
);
2873 peasycap
->video_isoc_sequence
= i
;
2875 if (peasycap
->video_idle
) {
2876 JOM(16, "%i=video_idle %i=video_isoc_streaming\n", \
2877 peasycap
->video_idle
, peasycap
->video_isoc_streaming
);
2878 if (peasycap
->video_isoc_streaming
) {
2879 rc
= usb_submit_urb(purb
, GFP_ATOMIC
);
2919 SAM("0x%08X\n", rc
);
2923 if (-ENODEV
!= rc
) \
2924 SAM("ERROR: while %i=video_idle, " \
2925 "usb_submit_urb() " \
2926 "failed with rc:\n", \
2927 peasycap
->video_idle
);
2933 /*---------------------------------------------------------------------------*/
2934 if (FIELD_BUFFER_MANY
<= peasycap
->field_fill
) {
2935 SAM("ERROR: bad peasycap->field_fill\n");
2939 if ((-ESHUTDOWN
== purb
->status
) || (-ENOENT
== purb
->status
)) {
2940 JOM(8, "urb status -ESHUTDOWN or -ENOENT\n");
2944 (peasycap
->field_buffer
[peasycap
->field_fill
][0].kount
) |= 0x8000 ;
2945 SAM("ERROR: bad urb status:\n");
2946 switch (purb
->status
) {
2947 case -EINPROGRESS
: {
2948 SAM("-EINPROGRESS\n"); break;
2951 SAM("-ENOSR\n"); break;
2954 SAM("-EPIPE\n"); break;
2957 SAM("-EOVERFLOW\n"); break;
2960 SAM("-EPROTO\n"); break;
2963 SAM("-EILSEQ\n"); break;
2966 SAM("-ETIMEDOUT\n"); break;
2969 SAM("-EMSGSIZE\n"); break;
2972 SAM("-EOPNOTSUPP\n"); break;
2974 case -EPFNOSUPPORT
: {
2975 SAM("-EPFNOSUPPORT\n"); break;
2977 case -EAFNOSUPPORT
: {
2978 SAM("-EAFNOSUPPORT\n"); break;
2981 SAM("-EADDRINUSE\n"); break;
2983 case -EADDRNOTAVAIL
: {
2984 SAM("-EADDRNOTAVAIL\n"); break;
2987 SAM("-ENOBUFS\n"); break;
2990 SAM("-EISCONN\n"); break;
2993 SAM("-ENOTCONN\n"); break;
2996 SAM("-ESHUTDOWN\n"); break;
2999 SAM("-ENOENT\n"); break;
3002 SAM("-ECONNRESET\n"); break;
3005 SAM("ENOSPC\n"); break;
3008 SAM("unknown error code 0x%08X\n", purb
->status
); break;
3011 /*---------------------------------------------------------------------------*/
3013 for (i
= 0; i
< purb
->number_of_packets
; i
++) {
3014 if (0 != purb
->iso_frame_desc
[i
].status
) {
3015 (peasycap
->field_buffer\
3016 [peasycap
->field_fill
][0].kount
) |= 0x8000 ;
3017 switch (purb
->iso_frame_desc
[i
].status
) {
3019 strcpy(&errbuf
[0], "OK"); break;
3022 strcpy(&errbuf
[0], "-ENOENT"); break;
3024 case -EINPROGRESS
: {
3025 strcpy(&errbuf
[0], "-EINPROGRESS"); break;
3028 strcpy(&errbuf
[0], "-EPROTO"); break;
3031 strcpy(&errbuf
[0], "-EILSEQ"); break;
3034 strcpy(&errbuf
[0], "-ETIME"); break;
3037 strcpy(&errbuf
[0], "-ETIMEDOUT"); break;
3040 strcpy(&errbuf
[0], "-EPIPE"); break;
3043 strcpy(&errbuf
[0], "-ECOMM"); break;
3046 strcpy(&errbuf
[0], "-ENOSR"); break;
3049 strcpy(&errbuf
[0], "-EOVERFLOW"); break;
3052 strcpy(&errbuf
[0], "-EREMOTEIO"); break;
3055 strcpy(&errbuf
[0], "-ENODEV"); break;
3058 strcpy(&errbuf
[0], "-EXDEV"); break;
3061 strcpy(&errbuf
[0], "-EINVAL"); break;
3064 strcpy(&errbuf
[0], "-ECONNRESET"); break;
3067 SAM("ENOSPC\n"); break;
3070 strcpy(&errbuf
[0], "-ESHUTDOWN"); break;
3073 strcpy(&errbuf
[0], "unknown error"); break;
3077 framestatus
= purb
->iso_frame_desc
[i
].status
;
3078 framelength
= purb
->iso_frame_desc
[i
].length
;
3079 frameactual
= purb
->iso_frame_desc
[i
].actual_length
;
3080 frameoffset
= purb
->iso_frame_desc
[i
].offset
;
3082 JOM(16, "frame[%2i]:" \
3087 i
, framestatus
, frameactual
, framelength
, frameoffset
);
3088 if (!purb
->iso_frame_desc
[i
].status
) {
3089 more
= purb
->iso_frame_desc
[i
].actual_length
;
3090 pfield_buffer
= &peasycap
->field_buffer\
3091 [peasycap
->field_fill
][peasycap
->field_page
];
3092 videofieldamount
= (peasycap
->field_page
* \
3094 (int)(pfield_buffer
->pto
- pfield_buffer
->pgo
);
3096 peasycap
->video_mt
++;
3098 if (peasycap
->video_mt
) {
3099 JOM(8, "%4i empty video urb frames\n", \
3100 peasycap
->video_mt
);
3101 peasycap
->video_mt
= 0;
3103 if (FIELD_BUFFER_MANY
<= peasycap
->field_fill
) {
3104 SAM("ERROR: bad peasycap->field_fill\n");
3107 if (FIELD_BUFFER_SIZE
/PAGE_SIZE
<= \
3108 peasycap
->field_page
) {
3109 SAM("ERROR: bad peasycap->field_page\n");
3112 pfield_buffer
= &peasycap
->field_buffer\
3113 [peasycap
->field_fill
][peasycap
->field_page
];
3114 pu
= (__u8
*)(purb
->transfer_buffer
+ \
3115 purb
->iso_frame_desc
[i
].offset
);
3120 /*--------------------------------------------------------------------------*/
3122 * EIGHT-BYTE END-OF-VIDEOFIELD MARKER.
3123 * NOTE: A SUCCESSION OF URB FRAMES FOLLOWING THIS ARE EMPTY,
3124 * CORRESPONDING TO THE FIELD FLYBACK (VERTICAL BLANKING) PERIOD.
3126 * PROVIDED THE FIELD BUFFER CONTAINS GOOD DATA AS INDICATED BY A ZERO UPPER
3128 * peasycap->field_buffer[peasycap->field_fill][0].kount
3129 * THE CONTENTS OF THE FIELD BUFFER ARE OFFERED TO dqbuf(), field_read IS
3130 * UPDATED AND field_fill IS BUMPED. IF THE FIELD BUFFER CONTAINS BAD DATA
3131 * NOTHING IS OFFERED TO dqbuf().
3133 * THE DECISION ON WHETHER THE PARITY OF THE OFFERED FIELD BUFFER IS RIGHT
3134 * RESTS WITH dqbuf().
3136 /*---------------------------------------------------------------------------*/
3137 if ((8 == more
) || override
) {
3138 if (videofieldamount
> \
3139 peasycap
->videofieldamount
) {
3140 if (2 == videofieldamount
- \
3143 (peasycap
->field_buffer\
3144 [peasycap
->field_fill
]\
3145 [0].kount
) |= 0x0100;
3146 peasycap
->video_junk
+= (1 + \
3147 VIDEO_JUNK_TOLERATE
);
3149 (peasycap
->field_buffer\
3150 [peasycap
->field_fill
]\
3151 [0].kount
) |= 0x4000;
3152 } else if (videofieldamount
< \
3155 (peasycap
->field_buffer\
3156 [peasycap
->field_fill
]\
3157 [0].kount
) |= 0x2000;
3159 bad
= 0xFF00 & peasycap
->field_buffer\
3160 [peasycap
->field_fill
]\
3163 (peasycap
->video_junk
)--;
3164 if (-VIDEO_JUNK_TOLERATE
> \
3165 peasycap
->video_junk
) \
3166 peasycap
->video_junk
=\
3167 -VIDEO_JUNK_TOLERATE
;
3168 peasycap
->field_read
= \
3171 if (FIELD_BUFFER_MANY
<= \
3176 peasycap
->field_page
= 0;
3177 pfield_buffer
= &peasycap
->\
3183 pfield_buffer
->pto
= \
3185 JOM(8, "bumped to: %i="\
3189 peasycap
->field_fill
, \
3191 pfield_buffer
->kount
);
3192 JOM(8, "field buffer %i has "\
3193 "%i bytes fit to be "\
3195 peasycap
->field_read
, \
3197 JOM(8, "wakeup call to "\
3202 peasycap
->field_read
, \
3203 peasycap
->field_fill
, \
3204 0x00FF & peasycap
->\
3207 field_read
][0].kount
);
3208 wake_up_interruptible\
3212 (&peasycap
->timeval7
);
3214 peasycap
->video_junk
++;
3216 peasycap
->video_junk
+= \
3217 (1 + VIDEO_JUNK_TOLERATE
/2);
3218 JOM(8, "field buffer %i had %i " \
3219 "bytes, now discarded: "\
3221 peasycap
->field_fill
, \
3224 peasycap
->field_buffer\
3225 [peasycap
->field_fill
][0].\
3227 (peasycap
->field_fill
)++;
3229 if (FIELD_BUFFER_MANY
<= \
3230 peasycap
->field_fill
)
3231 peasycap
->field_fill
= 0;
3232 peasycap
->field_page
= 0;
3234 &peasycap
->field_buffer\
3235 [peasycap
->field_fill
]\
3236 [peasycap
->field_page
];
3237 pfield_buffer
->pto
= \
3240 JOM(8, "bumped to: %i=peasycap->" \
3241 "field_fill %i=parity\n", \
3242 peasycap
->field_fill
, \
3243 0x00FF & pfield_buffer
->kount
);
3246 JOM(8, "end-of-field: received " \
3247 "parity byte 0x%02X\n", \
3250 pfield_buffer
->kount
= 0x0000;
3252 pfield_buffer
->kount
= 0x0001;
3253 pfield_buffer
->input
= 0x08 | \
3254 (0x07 & peasycap
->input
);
3255 JOM(8, "end-of-field: 0x%02X=kount\n",\
3256 0xFF & pfield_buffer
->kount
);
3259 /*---------------------------------------------------------------------------*/
3261 * COPY more BYTES FROM ISOC BUFFER TO FIELD BUFFER
3263 /*---------------------------------------------------------------------------*/
3267 if (FIELD_BUFFER_MANY
<= peasycap
->field_fill
) {
3268 SAM("ERROR: bad peasycap->field_fill\n");
3271 if (FIELD_BUFFER_SIZE
/PAGE_SIZE
<= \
3272 peasycap
->field_page
) {
3273 SAM("ERROR: bad peasycap->field_page\n");
3276 pfield_buffer
= &peasycap
->field_buffer\
3277 [peasycap
->field_fill
][peasycap
->field_page
];
3279 pfield_buffer
= &peasycap
->field_buffer\
3280 [peasycap
->field_fill
]\
3281 [peasycap
->field_page
];
3282 if (PAGE_SIZE
< (pfield_buffer
->pto
- \
3283 pfield_buffer
->pgo
)) {
3284 SAM("ERROR: bad pfield_buffer->pto\n");
3287 if (PAGE_SIZE
== (pfield_buffer
->pto
- \
3288 pfield_buffer
->pgo
)) {
3289 (peasycap
->field_page
)++;
3290 if (FIELD_BUFFER_SIZE
/PAGE_SIZE
<= \
3291 peasycap
->field_page
) {
3292 JOM(16, "wrapping peasycap->" \
3294 peasycap
->field_page
= 0;
3296 pfield_buffer
= &peasycap
->\
3298 [peasycap
->field_fill
]\
3299 [peasycap
->field_page
];
3300 pfield_buffer
->pto
= \
3302 pfield_buffer
->input
= 0x08 | \
3303 (0x07 & peasycap
->input
);
3304 if ((peasycap
->field_buffer
[peasycap
->\
3307 pfield_buffer
->input
)
3308 (peasycap
->field_buffer\
3309 [peasycap
->field_fill
]\
3310 [0]).kount
|= 0x1000;
3313 much
= PAGE_SIZE
- (int)(pfield_buffer
->pto
- \
3314 pfield_buffer
->pgo
);
3318 memcpy(pfield_buffer
->pto
, pu
, much
);
3320 (pfield_buffer
->pto
) += much
;
3327 /*---------------------------------------------------------------------------*/
3329 * RESUBMIT THIS URB, UNLESS A SEVERE PERSISTENT ERROR CONDITION EXISTS.
3331 * IF THE WAIT QUEUES ARE NOT CLEARED IN RESPONSE TO AN ERROR CONDITION
3332 * THE USERSPACE PROGRAM, E.G. mplayer, MAY HANG ON EXIT. BEWARE.
3334 /*---------------------------------------------------------------------------*/
3335 if (VIDEO_ISOC_BUFFER_MANY
<= peasycap
->video_junk
) {
3336 SAM("easycap driver shutting down on condition green\n");
3337 peasycap
->status
= 1;
3338 peasycap
->video_eof
= 1;
3339 peasycap
->video_junk
= 0;
3340 wake_up_interruptible(&peasycap
->wq_video
);
3341 #if !defined(PERSEVERE)
3342 peasycap
->audio_eof
= 1;
3343 wake_up_interruptible(&peasycap
->wq_audio
);
3344 #endif /*PERSEVERE*/
3347 if (peasycap
->video_isoc_streaming
) {
3348 rc
= usb_submit_urb(purb
, GFP_ATOMIC
);
3352 SAM("ENOMEM\n"); break;
3355 SAM("ENODEV\n"); break;
3358 SAM("ENXIO\n"); break;
3361 SAM("EINVAL\n"); break;
3364 SAM("EAGAIN\n"); break;
3367 SAM("EFBIG\n"); break;
3370 SAM("EPIPE\n"); break;
3373 SAM("EMSGSIZE\n"); break;
3376 SAM("ENOSPC\n"); break;
3379 SAM("0x%08X\n", rc
); break;
3382 if (-ENODEV
!= rc
) \
3383 SAM("ERROR: while %i=video_idle, " \
3384 "usb_submit_urb() " \
3385 "failed with rc:\n", \
3386 peasycap
->video_idle
);
3391 /*****************************************************************************/
3392 /*---------------------------------------------------------------------------*/
3398 * THIS FUNCTION ASSUMES THAT, ON EACH AND EVERY OCCASION THAT THE EasyCAP
3399 * IS PHYSICALLY PLUGGED IN, INTERFACE 0 IS PROBED FIRST.
3400 * IF THIS IS NOT TRUE, THERE IS THE POSSIBILITY OF AN Oops.
3402 * THIS HAS NEVER BEEN A PROBLEM IN PRACTICE, BUT SOMETHING SEEMS WRONG HERE.
3404 /*---------------------------------------------------------------------------*/
3406 easycap_usb_probe(struct usb_interface
*pusb_interface
, \
3407 const struct usb_device_id
*id
)
3409 struct usb_device
*pusb_device
, *pusb_device1
;
3410 struct usb_host_interface
*pusb_host_interface
;
3411 struct usb_endpoint_descriptor
*pepd
;
3412 struct usb_interface_descriptor
*pusb_interface_descriptor
;
3413 struct usb_interface_assoc_descriptor
*pusb_interface_assoc_descriptor
;
3415 struct easycap
*peasycap
;
3416 struct data_urb
*pdata_urb
;
3417 size_t wMaxPacketSize
;
3418 int ISOCwMaxPacketSize
;
3419 int BULKwMaxPacketSize
;
3420 int INTwMaxPacketSize
;
3421 int CTRLwMaxPacketSize
;
3422 __u8 bEndpointAddress
;
3423 __u8 ISOCbEndpointAddress
;
3424 __u8 INTbEndpointAddress
;
3425 int isin
, i
, j
, k
, m
, rc
;
3426 __u8 bInterfaceNumber
;
3427 __u8 bInterfaceClass
;
3428 __u8 bInterfaceSubClass
;
3430 int okalt
[8], isokalt
;
3436 struct easycap_format
*peasycap_format
;
3442 for (k
= 0; k
< DONGLE_MANY
; k
++) {
3443 easycap_dongle
[k
].peasycap
= (struct easycap
*)NULL
;
3444 mutex_init(&easycap_dongle
[k
].mutex_video
);
3445 mutex_init(&easycap_dongle
[k
].mutex_audio
);
3449 peasycap
= (struct easycap
*)NULL
;
3451 if ((struct usb_interface
*)NULL
== pusb_interface
) {
3452 SAY("ERROR: pusb_interface is NULL\n");
3455 /*---------------------------------------------------------------------------*/
3457 * GET POINTER TO STRUCTURE usb_device
3459 /*---------------------------------------------------------------------------*/
3460 pusb_device1
= container_of(pusb_interface
->dev
.parent
, \
3461 struct usb_device
, dev
);
3462 if ((struct usb_device
*)NULL
== pusb_device1
) {
3463 SAY("ERROR: pusb_device1 is NULL\n");
3466 pusb_device
= usb_get_dev(pusb_device1
);
3467 if ((struct usb_device
*)NULL
== pusb_device
) {
3468 SAY("ERROR: pusb_device is NULL\n");
3471 if ((unsigned long int)pusb_device1
!= (unsigned long int)pusb_device
) {
3472 JOT(4, "ERROR: pusb_device1 != pusb_device\n");
3476 JOT(4, "bNumConfigurations=%i\n", pusb_device
->descriptor
.bNumConfigurations
);
3478 /*---------------------------------------------------------------------------*/
3479 pusb_host_interface
= pusb_interface
->cur_altsetting
;
3480 if (NULL
== pusb_host_interface
) {
3481 SAY("ERROR: pusb_host_interface is NULL\n");
3484 pusb_interface_descriptor
= &(pusb_host_interface
->desc
);
3485 if (NULL
== pusb_interface_descriptor
) {
3486 SAY("ERROR: pusb_interface_descriptor is NULL\n");
3489 /*---------------------------------------------------------------------------*/
3491 * GET PROPERTIES OF PROBED INTERFACE
3493 /*---------------------------------------------------------------------------*/
3494 bInterfaceNumber
= pusb_interface_descriptor
->bInterfaceNumber
;
3495 bInterfaceClass
= pusb_interface_descriptor
->bInterfaceClass
;
3496 bInterfaceSubClass
= pusb_interface_descriptor
->bInterfaceSubClass
;
3498 JOT(4, "intf[%i]: pusb_interface->num_altsetting=%i\n", \
3499 bInterfaceNumber
, pusb_interface
->num_altsetting
);
3500 JOT(4, "intf[%i]: pusb_interface->cur_altsetting - " \
3501 "pusb_interface->altsetting=%li\n", bInterfaceNumber
, \
3502 (long int)(pusb_interface
->cur_altsetting
- \
3503 pusb_interface
->altsetting
));
3504 switch (bInterfaceClass
) {
3505 case USB_CLASS_AUDIO
: {
3506 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_AUDIO\n", \
3507 bInterfaceNumber
, bInterfaceClass
); break;
3509 case USB_CLASS_VIDEO
: {
3510 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_VIDEO\n", \
3511 bInterfaceNumber
, bInterfaceClass
); break;
3513 case USB_CLASS_VENDOR_SPEC
: {
3514 JOT(4, "intf[%i]: bInterfaceClass=0x%02X=USB_CLASS_VENDOR_SPEC\n", \
3515 bInterfaceNumber
, bInterfaceClass
); break;
3520 switch (bInterfaceSubClass
) {
3522 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=AUDIOCONTROL\n", \
3523 bInterfaceNumber
, bInterfaceSubClass
); break;
3526 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=AUDIOSTREAMING\n", \
3527 bInterfaceNumber
, bInterfaceSubClass
); break;
3530 JOT(4, "intf[%i]: bInterfaceSubClass=0x%02X=MIDISTREAMING\n", \
3531 bInterfaceNumber
, bInterfaceSubClass
); break;
3536 /*---------------------------------------------------------------------------*/
3537 pusb_interface_assoc_descriptor
= pusb_interface
->intf_assoc
;
3538 if (NULL
!= pusb_interface_assoc_descriptor
) {
3539 JOT(4, "intf[%i]: bFirstInterface=0x%02X bInterfaceCount=0x%02X\n", \
3541 pusb_interface_assoc_descriptor
->bFirstInterface
, \
3542 pusb_interface_assoc_descriptor
->bInterfaceCount
);
3544 JOT(4, "intf[%i]: pusb_interface_assoc_descriptor is NULL\n", \
3547 /*---------------------------------------------------------------------------*/
3549 * A NEW struct easycap IS ALWAYS ALLOCATED WHEN INTERFACE 0 IS PROBED.
3550 * IT IS NOT POSSIBLE HERE TO FREE ANY EXISTING struct easycap. THIS
3551 * SHOULD HAVE BEEN DONE BY easycap_delete() WHEN THE EasyCAP WAS
3552 * PHYSICALLY UNPLUGGED.
3554 * THE POINTER peasycap TO THE struct easycap IS REMEMBERED WHEN
3555 * INTERFACES 1 AND 2 ARE PROBED.
3557 * IF TWO EasyCAPs ARE PLUGGED IN NEARLY SIMULTANEOUSLY THERE WILL
3558 * BE TROUBLE. BEWARE.
3560 /*---------------------------------------------------------------------------*/
3561 if (0 == bInterfaceNumber
) {
3562 peasycap
= kzalloc(sizeof(struct easycap
), GFP_KERNEL
);
3563 if (NULL
== peasycap
) {
3564 SAY("ERROR: Could not allocate peasycap\n");
3567 SAM("allocated 0x%08lX=peasycap\n", (unsigned long int) peasycap
);
3568 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3569 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
3570 SAM("where 0x%08lX=&peasycap->video_device\n", \
3571 (unsigned long int) &peasycap
->video_device
);
3572 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
3573 SAM("and 0x%08lX=&peasycap->v4l2_device\n", \
3574 (unsigned long int) &peasycap
->v4l2_device
);
3575 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
3576 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
3577 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3578 /*---------------------------------------------------------------------------*/
3580 * PERFORM URGENT INTIALIZATIONS ...
3582 /*---------------------------------------------------------------------------*/
3583 strcpy(&peasycap
->telltale
[0], TELLTALE
);
3584 kref_init(&peasycap
->kref
);
3585 JOM(8, "intf[%i]: after kref_init(..._video) " \
3586 "%i=peasycap->kref.refcount.counter\n", \
3587 bInterfaceNumber
, peasycap
->kref
.refcount
.counter
);
3589 init_waitqueue_head(&peasycap
->wq_video
);
3590 init_waitqueue_head(&peasycap
->wq_audio
);
3592 for (dongle_this
= 0; dongle_this
< DONGLE_MANY
; dongle_this
++) {
3593 if (NULL
== easycap_dongle
[dongle_this
].peasycap
) {
3594 if (0 == mutex_is_locked(&easycap_dongle\
3595 [dongle_this
].mutex_video
)) {
3596 if (0 == mutex_is_locked(&easycap_dongle\
3597 [dongle_this
].mutex_audio
)) {
3599 [dongle_this
].peasycap
= \
3601 JOM(8, "intf[%i]: peasycap-->easycap" \
3602 "_dongle[%i].peasycap\n", \
3603 bInterfaceNumber
, dongle_this
);
3609 if (DONGLE_MANY
<= dongle_this
) {
3610 SAM("ERROR: too many dongles\n");
3614 peasycap
->allocation_video_struct
= sizeof(struct easycap
);
3615 peasycap
->allocation_video_page
= 0;
3616 peasycap
->allocation_video_urb
= 0;
3617 peasycap
->allocation_audio_struct
= 0;
3618 peasycap
->allocation_audio_page
= 0;
3619 peasycap
->allocation_audio_urb
= 0;
3621 /*---------------------------------------------------------------------------*/
3623 * ... AND FURTHER INITIALIZE THE STRUCTURE
3625 /*---------------------------------------------------------------------------*/
3626 peasycap
->pusb_device
= pusb_device
;
3627 peasycap
->pusb_interface
= pusb_interface
;
3630 peasycap
->microphone
= false;
3632 peasycap
->video_interface
= -1;
3633 peasycap
->video_altsetting_on
= -1;
3634 peasycap
->video_altsetting_off
= -1;
3635 peasycap
->video_endpointnumber
= -1;
3636 peasycap
->video_isoc_maxframesize
= -1;
3637 peasycap
->video_isoc_buffer_size
= -1;
3639 peasycap
->audio_interface
= -1;
3640 peasycap
->audio_altsetting_on
= -1;
3641 peasycap
->audio_altsetting_off
= -1;
3642 peasycap
->audio_endpointnumber
= -1;
3643 peasycap
->audio_isoc_maxframesize
= -1;
3644 peasycap
->audio_isoc_buffer_size
= -1;
3646 peasycap
->frame_buffer_many
= FRAME_BUFFER_MANY
;
3648 for (k
= 0; k
< INPUT_MANY
; k
++)
3649 peasycap
->lost
[k
] = 0;
3651 peasycap
->skipped
= 0;
3652 peasycap
->offerfields
= 0;
3653 /*---------------------------------------------------------------------------*/
3655 * DYNAMICALLY FILL IN THE AVAILABLE FORMATS ...
3657 /*---------------------------------------------------------------------------*/
3658 rc
= fillin_formats();
3660 SAM("ERROR: fillin_formats() returned %i\n", rc
);
3663 JOM(4, "%i formats available\n", rc
);
3664 /*---------------------------------------------------------------------------*/
3666 * ... AND POPULATE easycap.inputset[]
3668 /*---------------------------------------------------------------------------*/
3669 for (k
= 0; k
< INPUT_MANY
; k
++) {
3670 peasycap
->inputset
[k
].input_ok
= 0;
3671 peasycap
->inputset
[k
].standard_offset_ok
= 0;
3672 peasycap
->inputset
[k
].format_offset_ok
= 0;
3673 peasycap
->inputset
[k
].brightness_ok
= 0;
3674 peasycap
->inputset
[k
].contrast_ok
= 0;
3675 peasycap
->inputset
[k
].saturation_ok
= 0;
3676 peasycap
->inputset
[k
].hue_ok
= 0;
3678 if (true == peasycap
->ntsc
) {
3682 while (0xFFFF != easycap_standard
[i
].mask
) {
3683 if (NTSC_M
== easycap_standard
[i
].\
3684 v4l2_standard
.index
) {
3686 for (k
= 0; k
< INPUT_MANY
; k
++) {
3687 peasycap
->inputset
[k
].\
3688 standard_offset
= i
;
3690 mask
= easycap_standard
[i
].mask
;
3698 while (0xFFFF != easycap_standard
[i
].mask
) {
3699 if (PAL_BGHIN
== easycap_standard
[i
].\
3700 v4l2_standard
.index
) {
3702 for (k
= 0; k
< INPUT_MANY
; k
++) {
3703 peasycap
->inputset
[k
].\
3704 standard_offset
= i
;
3706 mask
= easycap_standard
[i
].mask
;
3713 SAM("MISTAKE: easycap.inputset[].standard_offset " \
3714 "unpopulated, %i=m\n", m
);
3718 peasycap_format
= &easycap_format
[0];
3721 while (0 != peasycap_format
->v4l2_format
.fmt
.pix
.width
) {
3722 if (((peasycap_format
->mask
& 0x0F) == (mask
& 0x0F)) && \
3724 v4l2_format
.fmt
.pix
.field
== \
3725 V4L2_FIELD_NONE
) && \
3727 v4l2_format
.fmt
.pix
.pixelformat
== \
3728 V4L2_PIX_FMT_UYVY
) && \
3730 v4l2_format
.fmt
.pix
.width
== \
3733 v4l2_format
.fmt
.pix
.height
== 480)) {
3735 for (k
= 0; k
< INPUT_MANY
; k
++)
3736 peasycap
->inputset
[k
].format_offset
= i
;
3743 SAM("MISTAKE: easycap.inputset[].format_offset unpopulated\n");
3749 while (0xFFFFFFFF != easycap_control
[i
].id
) {
3750 value
= easycap_control
[i
].default_value
;
3751 if (V4L2_CID_BRIGHTNESS
== easycap_control
[i
].id
) {
3753 for (k
= 0; k
< INPUT_MANY
; k
++)
3754 peasycap
->inputset
[k
].brightness
= value
;
3755 } else if (V4L2_CID_CONTRAST
== easycap_control
[i
].id
) {
3757 for (k
= 0; k
< INPUT_MANY
; k
++)
3758 peasycap
->inputset
[k
].contrast
= value
;
3759 } else if (V4L2_CID_SATURATION
== easycap_control
[i
].id
) {
3761 for (k
= 0; k
< INPUT_MANY
; k
++)
3762 peasycap
->inputset
[k
].saturation
= value
;
3763 } else if (V4L2_CID_HUE
== easycap_control
[i
].id
) {
3765 for (k
= 0; k
< INPUT_MANY
; k
++)
3766 peasycap
->inputset
[k
].hue
= value
;
3771 SAM("MISTAKE: easycap.inputset[].brightness,... " \
3772 "underpopulated\n");
3775 for (k
= 0; k
< INPUT_MANY
; k
++)
3776 peasycap
->inputset
[k
].input
= k
;
3777 JOM(4, "populated easycap.inputset[]\n");
3778 JOM(4, "finished initialization\n");
3780 /*---------------------------------------------------------------------------*/
3782 * FOR INTERFACES 1 AND 2 THE POINTER peasycap IS OBTAINED BY ASSUMING
3783 * THAT dongle_this HAS NOT CHANGED SINCE INTERFACE 0 WAS PROBED. IF
3784 * THIS IS NOT THE CASE, FOR EXAMPLE WHEN TWO EASYCAPs ARE PLUGGED IN
3785 * SIMULTANEOUSLY, THERE WILL BE SERIOUS TROUBLE.
3787 /*---------------------------------------------------------------------------*/
3788 if ((0 > dongle_this
) || (DONGLE_MANY
<= dongle_this
)) {
3789 SAY("ERROR: bad dongle count\n");
3792 peasycap
= easycap_dongle
[dongle_this
].peasycap
;
3793 JOT(8, "intf[%i]: easycap_dongle[%i].peasycap-->peasycap\n", \
3794 bInterfaceNumber
, dongle_this
);
3796 if ((struct easycap
*)NULL
== peasycap
) {
3797 SAY("ERROR: peasycap is NULL when probing interface %i\n", \
3802 /*---------------------------------------------------------------------------*/
3803 if ((USB_CLASS_VIDEO
== bInterfaceClass
) || \
3804 (USB_CLASS_VENDOR_SPEC
== bInterfaceClass
)) {
3805 if (-1 == peasycap
->video_interface
) {
3806 peasycap
->video_interface
= bInterfaceNumber
;
3807 JOM(4, "setting peasycap->video_interface=%i\n", \
3808 peasycap
->video_interface
);
3810 if (peasycap
->video_interface
!= bInterfaceNumber
) {
3811 SAM("ERROR: attempting to reset " \
3812 "peasycap->video_interface\n");
3813 SAM("...... continuing with " \
3814 "%i=peasycap->video_interface\n", \
3815 peasycap
->video_interface
);
3818 } else if ((USB_CLASS_AUDIO
== bInterfaceClass
) && \
3819 (0x02 == bInterfaceSubClass
)) {
3820 if (-1 == peasycap
->audio_interface
) {
3821 peasycap
->audio_interface
= bInterfaceNumber
;
3822 JOM(4, "setting peasycap->audio_interface=%i\n", \
3823 peasycap
->audio_interface
);
3825 if (peasycap
->audio_interface
!= bInterfaceNumber
) {
3826 SAM("ERROR: attempting to reset " \
3827 "peasycap->audio_interface\n");
3828 SAM("...... continuing with " \
3829 "%i=peasycap->audio_interface\n", \
3830 peasycap
->audio_interface
);
3834 /*---------------------------------------------------------------------------*/
3836 * INVESTIGATE ALL ALTSETTINGS.
3837 * DONE IN DETAIL BECAUSE USB DEVICE 05e1:0408 HAS DISPARATE INCARNATIONS.
3839 /*---------------------------------------------------------------------------*/
3842 for (i
= 0; i
< pusb_interface
->num_altsetting
; i
++) {
3843 pusb_host_interface
= &(pusb_interface
->altsetting
[i
]);
3844 if ((struct usb_host_interface
*)NULL
== pusb_host_interface
) {
3845 SAM("ERROR: pusb_host_interface is NULL\n");
3848 pusb_interface_descriptor
= &(pusb_host_interface
->desc
);
3849 if ((struct usb_interface_descriptor
*)NULL
== \
3850 pusb_interface_descriptor
) {
3851 SAM("ERROR: pusb_interface_descriptor is NULL\n");
3855 JOM(4, "intf[%i]alt[%i]: desc.bDescriptorType=0x%02X\n", \
3856 bInterfaceNumber
, i
, pusb_interface_descriptor
->bDescriptorType
);
3857 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceNumber=0x%02X\n", \
3858 bInterfaceNumber
, i
, pusb_interface_descriptor
->bInterfaceNumber
);
3859 JOM(4, "intf[%i]alt[%i]: desc.bAlternateSetting=0x%02X\n", \
3860 bInterfaceNumber
, i
, pusb_interface_descriptor
->bAlternateSetting
);
3861 JOM(4, "intf[%i]alt[%i]: desc.bNumEndpoints=0x%02X\n", \
3862 bInterfaceNumber
, i
, pusb_interface_descriptor
->bNumEndpoints
);
3863 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceClass=0x%02X\n", \
3864 bInterfaceNumber
, i
, pusb_interface_descriptor
->bInterfaceClass
);
3865 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceSubClass=0x%02X\n", \
3866 bInterfaceNumber
, i
, pusb_interface_descriptor
->bInterfaceSubClass
);
3867 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceProtocol=0x%02X\n", \
3868 bInterfaceNumber
, i
, pusb_interface_descriptor
->bInterfaceProtocol
);
3869 JOM(4, "intf[%i]alt[%i]: desc.iInterface=0x%02X\n", \
3870 bInterfaceNumber
, i
, pusb_interface_descriptor
->iInterface
);
3872 ISOCwMaxPacketSize
= -1;
3873 BULKwMaxPacketSize
= -1;
3874 INTwMaxPacketSize
= -1;
3875 CTRLwMaxPacketSize
= -1;
3876 ISOCbEndpointAddress
= 0;
3877 INTbEndpointAddress
= 0;
3879 if (0 == pusb_interface_descriptor
->bNumEndpoints
)
3880 JOM(4, "intf[%i]alt[%i] has no endpoints\n", \
3881 bInterfaceNumber
, i
);
3882 /*---------------------------------------------------------------------------*/
3883 for (j
= 0; j
< pusb_interface_descriptor
->bNumEndpoints
; j
++) {
3884 pepd
= &(pusb_host_interface
->endpoint
[j
].desc
);
3885 if ((struct usb_endpoint_descriptor
*)NULL
== pepd
) {
3886 SAM("ERROR: pepd is NULL.\n");
3887 SAM("...... skipping\n");
3890 wMaxPacketSize
= le16_to_cpu(pepd
->wMaxPacketSize
);
3891 bEndpointAddress
= pepd
->bEndpointAddress
;
3893 JOM(4, "intf[%i]alt[%i]end[%i]: bEndpointAddress=0x%X\n", \
3894 bInterfaceNumber
, i
, j
, \
3895 pepd
->bEndpointAddress
);
3896 JOM(4, "intf[%i]alt[%i]end[%i]: bmAttributes=0x%X\n", \
3897 bInterfaceNumber
, i
, j
, \
3898 pepd
->bmAttributes
);
3899 JOM(4, "intf[%i]alt[%i]end[%i]: wMaxPacketSize=%i\n", \
3900 bInterfaceNumber
, i
, j
, \
3901 pepd
->wMaxPacketSize
);
3902 JOM(4, "intf[%i]alt[%i]end[%i]: bInterval=%i\n",
3903 bInterfaceNumber
, i
, j
, \
3906 if (pepd
->bEndpointAddress
& USB_DIR_IN
) {
3907 JOM(4, "intf[%i]alt[%i]end[%i] is an IN endpoint\n",\
3908 bInterfaceNumber
, i
, j
);
3911 JOM(4, "intf[%i]alt[%i]end[%i] is an OUT endpoint\n",\
3912 bInterfaceNumber
, i
, j
);
3913 SAM("ERROR: OUT endpoint unexpected\n");
3914 SAM("...... continuing\n");
3917 if ((pepd
->bmAttributes
& \
3918 USB_ENDPOINT_XFERTYPE_MASK
) == \
3919 USB_ENDPOINT_XFER_ISOC
) {
3920 JOM(4, "intf[%i]alt[%i]end[%i] is an ISOC endpoint\n",\
3921 bInterfaceNumber
, i
, j
);
3923 switch (bInterfaceClass
) {
3924 case USB_CLASS_VIDEO
:
3925 case USB_CLASS_VENDOR_SPEC
: {
3928 "peasycap is NULL\n");
3931 if (pepd
->wMaxPacketSize
) {
3940 bEndpointAddress
& \
3956 if (-1 == peasycap
->\
3957 video_altsetting_off
) {
3959 video_altsetting_off
=\
3961 JOM(4, "%i=video_" \
3965 video_altsetting_off
);
3967 SAM("ERROR: peasycap" \
3968 "->video_altsetting_" \
3969 "off already set\n");
3971 "continuing with " \
3972 "%i=peasycap->video_" \
3973 "altsetting_off\n", \
3975 video_altsetting_off
);
3980 case USB_CLASS_AUDIO
: {
3981 if (0x02 != bInterfaceSubClass
)
3985 "peasycap is NULL\n");
3988 if (pepd
->wMaxPacketSize
) {
3990 okalt
[isokalt
] = i
;
3997 bEndpointAddress
& \
4013 if (-1 == peasycap
->\
4014 audio_altsetting_off
) {
4016 audio_altsetting_off
=\
4018 JOM(4, "%i=audio_" \
4022 audio_altsetting_off
);
4024 SAM("ERROR: peasycap" \
4025 "->audio_altsetting_" \
4026 "off already set\n");
4028 "continuing with " \
4030 audio_altsetting_" \
4033 audio_altsetting_off
);
4042 } else if ((pepd
->bmAttributes
& \
4043 USB_ENDPOINT_XFERTYPE_MASK
) ==\
4044 USB_ENDPOINT_XFER_BULK
) {
4045 JOM(4, "intf[%i]alt[%i]end[%i] is a BULK endpoint\n",\
4046 bInterfaceNumber
, i
, j
);
4047 } else if ((pepd
->bmAttributes
& \
4048 USB_ENDPOINT_XFERTYPE_MASK
) ==\
4049 USB_ENDPOINT_XFER_INT
) {
4050 JOM(4, "intf[%i]alt[%i]end[%i] is an INT endpoint\n",\
4051 bInterfaceNumber
, i
, j
);
4053 JOM(4, "intf[%i]alt[%i]end[%i] is a CTRL endpoint\n",\
4054 bInterfaceNumber
, i
, j
);
4056 if (0 == pepd
->wMaxPacketSize
) {
4057 JOM(4, "intf[%i]alt[%i]end[%i] " \
4058 "has zero packet size\n", \
4059 bInterfaceNumber
, i
, j
);
4063 /*---------------------------------------------------------------------------*/
4065 * PERFORM INITIALIZATION OF THE PROBED INTERFACE
4067 /*---------------------------------------------------------------------------*/
4068 JOM(4, "initialization begins for interface %i\n", \
4069 pusb_interface_descriptor
->bInterfaceNumber
);
4070 switch (bInterfaceNumber
) {
4071 /*---------------------------------------------------------------------------*/
4073 * INTERFACE 0 IS THE VIDEO INTERFACE
4075 /*---------------------------------------------------------------------------*/
4078 SAM("MISTAKE: peasycap is NULL\n");
4082 SAM("ERROR: no viable video_altsetting_on\n");
4085 peasycap
->video_altsetting_on
= okalt
[isokalt
- 1];
4086 JOM(4, "%i=video_altsetting_on <====\n", \
4087 peasycap
->video_altsetting_on
);
4089 /*---------------------------------------------------------------------------*/
4091 * DECIDE THE VIDEO STREAMING PARAMETERS
4093 /*---------------------------------------------------------------------------*/
4094 peasycap
->video_endpointnumber
= okepn
[isokalt
- 1];
4095 JOM(4, "%i=video_endpointnumber\n", peasycap
->video_endpointnumber
);
4096 maxpacketsize
= okmps
[isokalt
- 1];
4097 if (USB_2_0_MAXPACKETSIZE
> maxpacketsize
) {
4098 peasycap
->video_isoc_maxframesize
= maxpacketsize
;
4100 peasycap
->video_isoc_maxframesize
= \
4101 USB_2_0_MAXPACKETSIZE
;
4103 JOM(4, "%i=video_isoc_maxframesize\n", \
4104 peasycap
->video_isoc_maxframesize
);
4105 if (0 >= peasycap
->video_isoc_maxframesize
) {
4106 SAM("ERROR: bad video_isoc_maxframesize\n");
4107 SAM(" possibly because port is USB 1.1\n");
4110 peasycap
->video_isoc_framesperdesc
= VIDEO_ISOC_FRAMESPERDESC
;
4111 JOM(4, "%i=video_isoc_framesperdesc\n", \
4112 peasycap
->video_isoc_framesperdesc
);
4113 if (0 >= peasycap
->video_isoc_framesperdesc
) {
4114 SAM("ERROR: bad video_isoc_framesperdesc\n");
4117 peasycap
->video_isoc_buffer_size
= \
4118 peasycap
->video_isoc_maxframesize
* \
4119 peasycap
->video_isoc_framesperdesc
;
4120 JOM(4, "%i=video_isoc_buffer_size\n", \
4121 peasycap
->video_isoc_buffer_size
);
4122 if ((PAGE_SIZE
<< VIDEO_ISOC_ORDER
) < \
4123 peasycap
->video_isoc_buffer_size
) {
4124 SAM("MISTAKE: peasycap->video_isoc_buffer_size too big\n");
4127 /*---------------------------------------------------------------------------*/
4128 if (-1 == peasycap
->video_interface
) {
4129 SAM("MISTAKE: video_interface is unset\n");
4132 if (-1 == peasycap
->video_altsetting_on
) {
4133 SAM("MISTAKE: video_altsetting_on is unset\n");
4136 if (-1 == peasycap
->video_altsetting_off
) {
4137 SAM("MISTAKE: video_interface_off is unset\n");
4140 if (-1 == peasycap
->video_endpointnumber
) {
4141 SAM("MISTAKE: video_endpointnumber is unset\n");
4144 if (-1 == peasycap
->video_isoc_maxframesize
) {
4145 SAM("MISTAKE: video_isoc_maxframesize is unset\n");
4148 if (-1 == peasycap
->video_isoc_buffer_size
) {
4149 SAM("MISTAKE: video_isoc_buffer_size is unset\n");
4152 /*---------------------------------------------------------------------------*/
4154 * ALLOCATE MEMORY FOR VIDEO BUFFERS. LISTS MUST BE INITIALIZED FIRST.
4156 /*---------------------------------------------------------------------------*/
4157 INIT_LIST_HEAD(&(peasycap
->urb_video_head
));
4158 peasycap
->purb_video_head
= &(peasycap
->urb_video_head
);
4159 /*---------------------------------------------------------------------------*/
4160 JOM(4, "allocating %i frame buffers of size %li\n", \
4161 FRAME_BUFFER_MANY
, (long int)FRAME_BUFFER_SIZE
);
4162 JOM(4, ".... each scattered over %li pages\n", \
4163 FRAME_BUFFER_SIZE
/PAGE_SIZE
);
4165 for (k
= 0; k
< FRAME_BUFFER_MANY
; k
++) {
4166 for (m
= 0; m
< FRAME_BUFFER_SIZE
/PAGE_SIZE
; m
++) {
4167 if ((void *)NULL
!= peasycap
->frame_buffer
[k
][m
].pgo
)
4168 SAM("attempting to reallocate frame " \
4171 pbuf
= (void *)__get_free_page(GFP_KERNEL
);
4172 if ((void *)NULL
== pbuf
) {
4173 SAM("ERROR: Could not allocate frame "\
4174 "buffer %i page %i\n", k
, m
);
4177 peasycap
->allocation_video_page
+= 1;
4178 peasycap
->frame_buffer
[k
][m
].pgo
= pbuf
;
4180 peasycap
->frame_buffer
[k
][m
].pto
= \
4181 peasycap
->frame_buffer
[k
][m
].pgo
;
4185 peasycap
->frame_fill
= 0;
4186 peasycap
->frame_read
= 0;
4187 JOM(4, "allocation of frame buffers done: %i pages\n", k
* \
4189 /*---------------------------------------------------------------------------*/
4190 JOM(4, "allocating %i field buffers of size %li\n", \
4191 FIELD_BUFFER_MANY
, (long int)FIELD_BUFFER_SIZE
);
4192 JOM(4, ".... each scattered over %li pages\n", \
4193 FIELD_BUFFER_SIZE
/PAGE_SIZE
);
4195 for (k
= 0; k
< FIELD_BUFFER_MANY
; k
++) {
4196 for (m
= 0; m
< FIELD_BUFFER_SIZE
/PAGE_SIZE
; m
++) {
4197 if ((void *)NULL
!= peasycap
->field_buffer
[k
][m
].pgo
) {
4198 SAM("ERROR: attempting to reallocate " \
4201 pbuf
= (void *) __get_free_page(GFP_KERNEL
);
4202 if ((void *)NULL
== pbuf
) {
4203 SAM("ERROR: Could not allocate field" \
4204 " buffer %i page %i\n", k
, m
);
4208 peasycap
->allocation_video_page
+= 1;
4209 peasycap
->field_buffer
[k
][m
].pgo
= pbuf
;
4211 peasycap
->field_buffer
[k
][m
].pto
= \
4212 peasycap
->field_buffer
[k
][m
].pgo
;
4214 peasycap
->field_buffer
[k
][0].kount
= 0x0200;
4216 peasycap
->field_fill
= 0;
4217 peasycap
->field_page
= 0;
4218 peasycap
->field_read
= 0;
4219 JOM(4, "allocation of field buffers done: %i pages\n", k
* \
4221 /*---------------------------------------------------------------------------*/
4222 JOM(4, "allocating %i isoc video buffers of size %i\n", \
4223 VIDEO_ISOC_BUFFER_MANY
, \
4224 peasycap
->video_isoc_buffer_size
);
4225 JOM(4, ".... each occupying contiguous memory pages\n");
4227 for (k
= 0; k
< VIDEO_ISOC_BUFFER_MANY
; k
++) {
4228 pbuf
= (void *)__get_free_pages(GFP_KERNEL
, VIDEO_ISOC_ORDER
);
4230 SAM("ERROR: Could not allocate isoc video buffer " \
4234 peasycap
->allocation_video_page
+= \
4235 ((unsigned int)(0x01 << VIDEO_ISOC_ORDER
));
4237 peasycap
->video_isoc_buffer
[k
].pgo
= pbuf
;
4238 peasycap
->video_isoc_buffer
[k
].pto
= pbuf
+ \
4239 peasycap
->video_isoc_buffer_size
;
4240 peasycap
->video_isoc_buffer
[k
].kount
= k
;
4242 JOM(4, "allocation of isoc video buffers done: %i pages\n", \
4243 k
* (0x01 << VIDEO_ISOC_ORDER
));
4244 /*---------------------------------------------------------------------------*/
4246 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
4248 /*---------------------------------------------------------------------------*/
4249 JOM(4, "allocating %i struct urb.\n", VIDEO_ISOC_BUFFER_MANY
);
4250 JOM(4, "using %i=peasycap->video_isoc_framesperdesc\n", \
4251 peasycap
->video_isoc_framesperdesc
);
4252 JOM(4, "using %i=peasycap->video_isoc_maxframesize\n", \
4253 peasycap
->video_isoc_maxframesize
);
4254 JOM(4, "using %i=peasycap->video_isoc_buffer_sizen", \
4255 peasycap
->video_isoc_buffer_size
);
4257 for (k
= 0; k
< VIDEO_ISOC_BUFFER_MANY
; k
++) {
4258 purb
= usb_alloc_urb(peasycap
->video_isoc_framesperdesc
, \
4261 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
4265 peasycap
->allocation_video_urb
+= 1;
4266 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
4267 pdata_urb
= kzalloc(sizeof(struct data_urb
), GFP_KERNEL
);
4268 if (NULL
== pdata_urb
) {
4269 SAM("ERROR: Could not allocate struct data_urb.\n");
4272 peasycap
->allocation_video_struct
+= \
4273 sizeof(struct data_urb
);
4275 pdata_urb
->purb
= purb
;
4276 pdata_urb
->isbuf
= k
;
4277 pdata_urb
->length
= 0;
4278 list_add_tail(&(pdata_urb
->list_head
), \
4279 peasycap
->purb_video_head
);
4280 /*---------------------------------------------------------------------------*/
4282 * ... AND INITIALIZE THEM
4284 /*---------------------------------------------------------------------------*/
4286 JOM(4, "initializing video urbs thus:\n");
4287 JOM(4, " purb->interval = 1;\n");
4288 JOM(4, " purb->dev = peasycap->pusb_device;\n");
4289 JOM(4, " purb->pipe = usb_rcvisocpipe" \
4290 "(peasycap->pusb_device,%i);\n", \
4291 peasycap
->video_endpointnumber
);
4292 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
4293 JOM(4, " purb->transfer_buffer = peasycap->" \
4294 "video_isoc_buffer[.].pgo;\n");
4295 JOM(4, " purb->transfer_buffer_length = %i;\n", \
4296 peasycap
->video_isoc_buffer_size
);
4297 JOM(4, " purb->complete = easycap_complete;\n");
4298 JOM(4, " purb->context = peasycap;\n");
4299 JOM(4, " purb->start_frame = 0;\n");
4300 JOM(4, " purb->number_of_packets = %i;\n", \
4301 peasycap
->video_isoc_framesperdesc
);
4302 JOM(4, " for (j = 0; j < %i; j++)\n", \
4303 peasycap
->video_isoc_framesperdesc
);
4305 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
4306 peasycap
->video_isoc_maxframesize
);
4307 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
4308 peasycap
->video_isoc_maxframesize
);
4313 purb
->dev
= peasycap
->pusb_device
;
4314 purb
->pipe
= usb_rcvisocpipe(peasycap
->pusb_device
, \
4315 peasycap
->video_endpointnumber
);
4316 purb
->transfer_flags
= URB_ISO_ASAP
;
4317 purb
->transfer_buffer
= peasycap
->video_isoc_buffer
[k
].pgo
;
4318 purb
->transfer_buffer_length
= \
4319 peasycap
->video_isoc_buffer_size
;
4320 purb
->complete
= easycap_complete
;
4321 purb
->context
= peasycap
;
4322 purb
->start_frame
= 0;
4323 purb
->number_of_packets
= peasycap
->video_isoc_framesperdesc
;
4324 for (j
= 0; j
< peasycap
->video_isoc_framesperdesc
; j
++) {
4325 purb
->iso_frame_desc
[j
].offset
= j
* \
4326 peasycap
->video_isoc_maxframesize
;
4327 purb
->iso_frame_desc
[j
].length
= \
4328 peasycap
->video_isoc_maxframesize
;
4331 JOM(4, "allocation of %i struct urb done.\n", k
);
4332 /*--------------------------------------------------------------------------*/
4334 * SAVE POINTER peasycap IN THIS INTERFACE.
4336 /*--------------------------------------------------------------------------*/
4337 usb_set_intfdata(pusb_interface
, peasycap
);
4338 /*---------------------------------------------------------------------------*/
4340 * IT IS ESSENTIAL TO INITIALIZE THE HARDWARE BEFORE, RATHER THAN AFTER,
4341 * THE DEVICE IS REGISTERED, BECAUSE SOME VERSIONS OF THE videodev MODULE
4342 * CALL easycap_open() IMMEDIATELY AFTER REGISTRATION, CAUSING A CLASH.
4345 /*---------------------------------------------------------------------------*/
4346 #if defined(PREFER_NTSC)
4347 peasycap
->ntsc
= true;
4348 JOM(8, "defaulting initially to NTSC\n");
4350 peasycap
->ntsc
= false;
4351 JOM(8, "defaulting initially to PAL\n");
4352 #endif /*PREFER_NTSC*/
4353 rc
= reset(peasycap
);
4355 SAM("ERROR: reset() returned %i\n", rc
);
4358 /*--------------------------------------------------------------------------*/
4360 * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY.
4362 /*--------------------------------------------------------------------------*/
4363 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4364 if (0 != (usb_register_dev(pusb_interface
, &easycap_class
))) {
4365 err("Not able to get a minor for this device");
4366 usb_set_intfdata(pusb_interface
, NULL
);
4369 (peasycap
->registered_video
)++;
4370 SAM("easycap attached to minor #%d\n", pusb_interface
->minor
);
4373 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4375 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4376 if (0 != (v4l2_device_register(&(pusb_interface
->dev
), \
4377 &(peasycap
->v4l2_device
)))) {
4378 SAM("v4l2_device_register() failed\n");
4381 JOM(4, "registered device instance: %s\n", \
4382 &(peasycap
->v4l2_device
.name
[0]));
4384 /*---------------------------------------------------------------------------*/
4389 * THIS IS BELIEVED TO BE HARMLESS, BUT MAY WELL BE UNNECESSARY OR WRONG:
4391 /*---------------------------------------------------------------------------*/
4392 peasycap
->video_device
.v4l2_dev
= (struct v4l2_device
*)NULL
;
4393 /*---------------------------------------------------------------------------*/
4395 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4397 strcpy(&peasycap
->video_device
.name
[0], "easycapdc60");
4398 #if defined(EASYCAP_NEEDS_V4L2_FOPS)
4399 peasycap
->video_device
.fops
= &v4l2_fops
;
4401 peasycap
->video_device
.fops
= &easycap_fops
;
4402 #endif /*EASYCAP_NEEDS_V4L2_FOPS*/
4403 peasycap
->video_device
.minor
= -1;
4404 peasycap
->video_device
.release
= (void *)(&videodev_release
);
4406 video_set_drvdata(&(peasycap
->video_device
), (void *)peasycap
);
4408 if (0 != (video_register_device(&(peasycap
->video_device
), \
4409 VFL_TYPE_GRABBER
, -1))) {
4410 err("Not able to register with videodev");
4411 videodev_release(&(peasycap
->video_device
));
4414 (peasycap
->registered_video
)++;
4415 SAM("registered with videodev: %i=minor\n", \
4416 peasycap
->video_device
.minor
);
4418 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4419 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4422 /*--------------------------------------------------------------------------*/
4424 * INTERFACE 1 IS THE AUDIO CONTROL INTERFACE
4425 * INTERFACE 2 IS THE AUDIO STREAMING INTERFACE
4427 /*--------------------------------------------------------------------------*/
4430 SAM("ERROR: peasycap is NULL\n");
4433 /*--------------------------------------------------------------------------*/
4435 * SAVE POINTER peasycap IN INTERFACE 1
4437 /*--------------------------------------------------------------------------*/
4438 usb_set_intfdata(pusb_interface
, peasycap
);
4439 JOM(4, "no initialization required for interface %i\n", \
4440 pusb_interface_descriptor
->bInterfaceNumber
);
4443 /*--------------------------------------------------------------------------*/
4446 SAM("MISTAKE: peasycap is NULL\n");
4450 SAM("ERROR: no viable audio_altsetting_on\n");
4453 peasycap
->audio_altsetting_on
= okalt
[isokalt
- 1];
4454 JOM(4, "%i=audio_altsetting_on <====\n", \
4455 peasycap
->audio_altsetting_on
);
4458 peasycap
->audio_endpointnumber
= okepn
[isokalt
- 1];
4459 JOM(4, "%i=audio_endpointnumber\n", peasycap
->audio_endpointnumber
);
4461 peasycap
->audio_isoc_maxframesize
= okmps
[isokalt
- 1];
4462 JOM(4, "%i=audio_isoc_maxframesize\n", \
4463 peasycap
->audio_isoc_maxframesize
);
4464 if (0 >= peasycap
->audio_isoc_maxframesize
) {
4465 SAM("ERROR: bad audio_isoc_maxframesize\n");
4468 if (9 == peasycap
->audio_isoc_maxframesize
) {
4469 peasycap
->ilk
|= 0x02;
4470 SAM("hardware is FOUR-CVBS\n");
4471 peasycap
->microphone
= true;
4472 peasycap
->audio_pages_per_fragment
= 4;
4473 } else if (256 == peasycap
->audio_isoc_maxframesize
) {
4474 peasycap
->ilk
&= ~0x02;
4475 SAM("hardware is CVBS+S-VIDEO\n");
4476 peasycap
->microphone
= false;
4477 peasycap
->audio_pages_per_fragment
= 4;
4479 SAM("hardware is unidentified:\n");
4480 SAM("%i=audio_isoc_maxframesize\n", \
4481 peasycap
->audio_isoc_maxframesize
);
4485 peasycap
->audio_bytes_per_fragment
= \
4486 peasycap
->audio_pages_per_fragment
* \
4488 peasycap
->audio_buffer_page_many
= (AUDIO_FRAGMENT_MANY
* \
4489 peasycap
->audio_pages_per_fragment
);
4491 JOM(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY
);
4492 JOM(4, "%6i=audio_pages_per_fragment\n", \
4493 peasycap
->audio_pages_per_fragment
);
4494 JOM(4, "%6i=audio_bytes_per_fragment\n", \
4495 peasycap
->audio_bytes_per_fragment
);
4496 JOM(4, "%6i=audio_buffer_page_many\n", \
4497 peasycap
->audio_buffer_page_many
);
4499 peasycap
->audio_isoc_framesperdesc
= 128;
4501 JOM(4, "%i=audio_isoc_framesperdesc\n", \
4502 peasycap
->audio_isoc_framesperdesc
);
4503 if (0 >= peasycap
->audio_isoc_framesperdesc
) {
4504 SAM("ERROR: bad audio_isoc_framesperdesc\n");
4508 peasycap
->audio_isoc_buffer_size
= \
4509 peasycap
->audio_isoc_maxframesize
* \
4510 peasycap
->audio_isoc_framesperdesc
;
4511 JOM(4, "%i=audio_isoc_buffer_size\n", \
4512 peasycap
->audio_isoc_buffer_size
);
4513 if (AUDIO_ISOC_BUFFER_SIZE
< peasycap
->audio_isoc_buffer_size
) {
4514 SAM("MISTAKE: audio_isoc_buffer_size bigger "
4515 "than %li=AUDIO_ISOC_BUFFER_SIZE\n", \
4516 AUDIO_ISOC_BUFFER_SIZE
);
4519 if (-1 == peasycap
->audio_interface
) {
4520 SAM("MISTAKE: audio_interface is unset\n");
4523 if (-1 == peasycap
->audio_altsetting_on
) {
4524 SAM("MISTAKE: audio_altsetting_on is unset\n");
4527 if (-1 == peasycap
->audio_altsetting_off
) {
4528 SAM("MISTAKE: audio_interface_off is unset\n");
4531 if (-1 == peasycap
->audio_endpointnumber
) {
4532 SAM("MISTAKE: audio_endpointnumber is unset\n");
4535 if (-1 == peasycap
->audio_isoc_maxframesize
) {
4536 SAM("MISTAKE: audio_isoc_maxframesize is unset\n");
4539 if (-1 == peasycap
->audio_isoc_buffer_size
) {
4540 SAM("MISTAKE: audio_isoc_buffer_size is unset\n");
4543 /*---------------------------------------------------------------------------*/
4545 * ALLOCATE MEMORY FOR AUDIO BUFFERS. LISTS MUST BE INITIALIZED FIRST.
4547 /*---------------------------------------------------------------------------*/
4548 INIT_LIST_HEAD(&(peasycap
->urb_audio_head
));
4549 peasycap
->purb_audio_head
= &(peasycap
->urb_audio_head
);
4551 JOM(4, "allocating an audio buffer\n");
4552 JOM(4, ".... scattered over %i pages\n", \
4553 peasycap
->audio_buffer_page_many
);
4555 for (k
= 0; k
< peasycap
->audio_buffer_page_many
; k
++) {
4556 if ((void *)NULL
!= peasycap
->audio_buffer
[k
].pgo
) {
4557 SAM("ERROR: attempting to reallocate audio buffers\n");
4559 pbuf
= (void *) __get_free_page(GFP_KERNEL
);
4560 if ((void *)NULL
== pbuf
) {
4561 SAM("ERROR: Could not allocate audio " \
4562 "buffer page %i\n", k
);
4565 peasycap
->allocation_audio_page
+= 1;
4567 peasycap
->audio_buffer
[k
].pgo
= pbuf
;
4569 peasycap
->audio_buffer
[k
].pto
= peasycap
->audio_buffer
[k
].pgo
;
4572 peasycap
->audio_fill
= 0;
4573 peasycap
->audio_read
= 0;
4574 JOM(4, "allocation of audio buffer done: %i pages\n", k
);
4575 /*---------------------------------------------------------------------------*/
4576 JOM(4, "allocating %i isoc audio buffers of size %i\n", \
4577 AUDIO_ISOC_BUFFER_MANY
, peasycap
->audio_isoc_buffer_size
);
4578 JOM(4, ".... each occupying contiguous memory pages\n");
4580 for (k
= 0; k
< AUDIO_ISOC_BUFFER_MANY
; k
++) {
4581 pbuf
= (void *)__get_free_pages(GFP_KERNEL
, AUDIO_ISOC_ORDER
);
4583 SAM("ERROR: Could not allocate isoc audio buffer " \
4587 peasycap
->allocation_audio_page
+= \
4588 ((unsigned int)(0x01 << AUDIO_ISOC_ORDER
));
4590 peasycap
->audio_isoc_buffer
[k
].pgo
= pbuf
;
4591 peasycap
->audio_isoc_buffer
[k
].pto
= pbuf
+ \
4592 peasycap
->audio_isoc_buffer_size
;
4593 peasycap
->audio_isoc_buffer
[k
].kount
= k
;
4595 JOM(4, "allocation of isoc audio buffers done.\n");
4596 /*---------------------------------------------------------------------------*/
4598 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
4600 /*---------------------------------------------------------------------------*/
4601 JOM(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY
);
4602 JOM(4, "using %i=peasycap->audio_isoc_framesperdesc\n", \
4603 peasycap
->audio_isoc_framesperdesc
);
4604 JOM(4, "using %i=peasycap->audio_isoc_maxframesize\n", \
4605 peasycap
->audio_isoc_maxframesize
);
4606 JOM(4, "using %i=peasycap->audio_isoc_buffer_size\n", \
4607 peasycap
->audio_isoc_buffer_size
);
4609 for (k
= 0; k
< AUDIO_ISOC_BUFFER_MANY
; k
++) {
4610 purb
= usb_alloc_urb(peasycap
->audio_isoc_framesperdesc
, \
4613 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
4617 peasycap
->allocation_audio_urb
+= 1 ;
4618 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
4619 pdata_urb
= kzalloc(sizeof(struct data_urb
), GFP_KERNEL
);
4620 if (NULL
== pdata_urb
) {
4621 SAM("ERROR: Could not allocate struct data_urb.\n");
4624 peasycap
->allocation_audio_struct
+= \
4625 sizeof(struct data_urb
);
4627 pdata_urb
->purb
= purb
;
4628 pdata_urb
->isbuf
= k
;
4629 pdata_urb
->length
= 0;
4630 list_add_tail(&(pdata_urb
->list_head
), \
4631 peasycap
->purb_audio_head
);
4632 /*---------------------------------------------------------------------------*/
4634 * ... AND INITIALIZE THEM
4636 /*---------------------------------------------------------------------------*/
4638 JOM(4, "initializing audio urbs thus:\n");
4639 JOM(4, " purb->interval = 1;\n");
4640 JOM(4, " purb->dev = peasycap->pusb_device;\n");
4641 JOM(4, " purb->pipe = usb_rcvisocpipe(peasycap->" \
4642 "pusb_device,%i);\n", \
4643 peasycap
->audio_endpointnumber
);
4644 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
4645 JOM(4, " purb->transfer_buffer = " \
4646 "peasycap->audio_isoc_buffer[.].pgo;\n");
4647 JOM(4, " purb->transfer_buffer_length = %i;\n", \
4648 peasycap
->audio_isoc_buffer_size
);
4649 JOM(4, " purb->complete = easysnd_complete;\n");
4650 JOM(4, " purb->context = peasycap;\n");
4651 JOM(4, " purb->start_frame = 0;\n");
4652 JOM(4, " purb->number_of_packets = %i;\n", \
4653 peasycap
->audio_isoc_framesperdesc
);
4654 JOM(4, " for (j = 0; j < %i; j++)\n", \
4655 peasycap
->audio_isoc_framesperdesc
);
4657 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
4658 peasycap
->audio_isoc_maxframesize
);
4659 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
4660 peasycap
->audio_isoc_maxframesize
);
4665 purb
->dev
= peasycap
->pusb_device
;
4666 purb
->pipe
= usb_rcvisocpipe(peasycap
->pusb_device
, \
4667 peasycap
->audio_endpointnumber
);
4668 purb
->transfer_flags
= URB_ISO_ASAP
;
4669 purb
->transfer_buffer
= peasycap
->audio_isoc_buffer
[k
].pgo
;
4670 purb
->transfer_buffer_length
= \
4671 peasycap
->audio_isoc_buffer_size
;
4672 purb
->complete
= easysnd_complete
;
4673 purb
->context
= peasycap
;
4674 purb
->start_frame
= 0;
4675 purb
->number_of_packets
= peasycap
->audio_isoc_framesperdesc
;
4676 for (j
= 0; j
< peasycap
->audio_isoc_framesperdesc
; j
++) {
4677 purb
->iso_frame_desc
[j
].offset
= j
* \
4678 peasycap
->audio_isoc_maxframesize
;
4679 purb
->iso_frame_desc
[j
].length
= \
4680 peasycap
->audio_isoc_maxframesize
;
4683 JOM(4, "allocation of %i struct urb done.\n", k
);
4684 /*---------------------------------------------------------------------------*/
4686 * SAVE POINTER peasycap IN THIS INTERFACE.
4688 /*---------------------------------------------------------------------------*/
4689 usb_set_intfdata(pusb_interface
, peasycap
);
4690 /*---------------------------------------------------------------------------*/
4692 * THE AUDIO DEVICE CAN BE REGISTERED NOW, AS IT IS READY.
4694 /*---------------------------------------------------------------------------*/
4695 rc
= usb_register_dev(pusb_interface
, &easysnd_class
);
4697 err("Not able to get a minor for this device.");
4698 usb_set_intfdata(pusb_interface
, NULL
);
4701 JOM(8, "kref_get() with %i=peasycap->kref.refcount.counter\n",\
4702 (int)peasycap
->kref
.refcount
.counter
);
4703 kref_get(&peasycap
->kref
);
4704 (peasycap
->registered_audio
)++;
4706 /*---------------------------------------------------------------------------*/
4708 * LET THE USER KNOW WHAT NODE THE AUDIO DEVICE IS ATTACHED TO.
4710 /*---------------------------------------------------------------------------*/
4711 SAM("easysnd attached to minor #%d\n", pusb_interface
->minor
);
4714 /*---------------------------------------------------------------------------*/
4716 * INTERFACES OTHER THAN 0, 1 AND 2 ARE UNEXPECTED
4718 /*---------------------------------------------------------------------------*/
4720 JOM(4, "ERROR: unexpected interface %i\n", bInterfaceNumber
);
4724 JOM(4, "ends successfully for interface %i\n", \
4725 pusb_interface_descriptor
->bInterfaceNumber
);
4728 /*****************************************************************************/
4729 /*---------------------------------------------------------------------------*/
4731 * WHEN THIS FUNCTION IS CALLED THE EasyCAP HAS ALREADY BEEN PHYSICALLY
4732 * UNPLUGGED. HENCE peasycap->pusb_device IS NO LONGER VALID.
4734 /*---------------------------------------------------------------------------*/
4736 easycap_usb_disconnect(struct usb_interface
*pusb_interface
)
4738 struct usb_host_interface
*pusb_host_interface
;
4739 struct usb_interface_descriptor
*pusb_interface_descriptor
;
4740 __u8 bInterfaceNumber
;
4741 struct easycap
*peasycap
;
4743 struct list_head
*plist_head
;
4744 struct data_urb
*pdata_urb
;
4746 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4747 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
4748 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4749 struct v4l2_device
*pv4l2_device
;
4750 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4751 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4752 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4756 if ((struct usb_interface
*)NULL
== pusb_interface
) {
4757 JOT(4, "ERROR: pusb_interface is NULL\n");
4760 pusb_host_interface
= pusb_interface
->cur_altsetting
;
4761 if ((struct usb_host_interface
*)NULL
== pusb_host_interface
) {
4762 JOT(4, "ERROR: pusb_host_interface is NULL\n");
4765 pusb_interface_descriptor
= &(pusb_host_interface
->desc
);
4766 if ((struct usb_interface_descriptor
*)NULL
== pusb_interface_descriptor
) {
4767 JOT(4, "ERROR: pusb_interface_descriptor is NULL\n");
4770 bInterfaceNumber
= pusb_interface_descriptor
->bInterfaceNumber
;
4771 minor
= pusb_interface
->minor
;
4772 JOT(4, "intf[%i]: minor=%i\n", bInterfaceNumber
, minor
);
4774 if (1 == bInterfaceNumber
)
4777 peasycap
= usb_get_intfdata(pusb_interface
);
4778 if (NULL
== peasycap
) {
4779 SAY("ERROR: peasycap is NULL\n");
4782 /*---------------------------------------------------------------------------*/
4783 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4785 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4787 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4788 /*---------------------------------------------------------------------------*/
4790 * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS
4791 * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(),
4792 * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE.
4793 * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED.
4795 /*---------------------------------------------------------------------------*/
4796 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
4797 pv4l2_device
= usb_get_intfdata(pusb_interface
);
4798 if ((struct v4l2_device
*)NULL
== pv4l2_device
) {
4799 SAY("ERROR: pv4l2_device is NULL\n");
4802 peasycap
= (struct easycap
*) \
4803 container_of(pv4l2_device
, struct easycap
, v4l2_device
);
4805 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4807 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4808 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4809 /*---------------------------------------------------------------------------*/
4810 if (memcmp(&peasycap
->telltale
[0], TELLTALE
, strlen(TELLTALE
))) {
4811 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap
);
4814 /*---------------------------------------------------------------------------*/
4816 * IF THE WAIT QUEUES ARE NOT CLEARED A DEADLOCK IS POSSIBLE. BEWARE.
4818 /*---------------------------------------------------------------------------*/
4819 peasycap
->video_eof
= 1;
4820 peasycap
->audio_eof
= 1;
4821 wake_up_interruptible(&(peasycap
->wq_video
));
4822 wake_up_interruptible(&(peasycap
->wq_audio
));
4823 /*---------------------------------------------------------------------------*/
4824 switch (bInterfaceNumber
) {
4826 if ((struct list_head
*)NULL
!= peasycap
->purb_video_head
) {
4827 JOM(4, "killing video urbs\n");
4829 list_for_each(plist_head
, (peasycap
->purb_video_head
))
4831 pdata_urb
= list_entry(plist_head
, \
4832 struct data_urb
, list_head
);
4833 if ((struct data_urb
*)NULL
!= pdata_urb
) {
4834 if ((struct urb
*)NULL
!= \
4836 usb_kill_urb(pdata_urb
->purb
);
4841 JOM(4, "%i video urbs killed\n", m
);
4845 /*---------------------------------------------------------------------------*/
4847 if ((struct list_head
*)NULL
!= peasycap
->purb_audio_head
) {
4848 JOM(4, "killing audio urbs\n");
4850 list_for_each(plist_head
, \
4851 (peasycap
->purb_audio_head
)) {
4852 pdata_urb
= list_entry(plist_head
, \
4853 struct data_urb
, list_head
);
4854 if ((struct data_urb
*)NULL
!= pdata_urb
) {
4855 if ((struct urb
*)NULL
!= \
4857 usb_kill_urb(pdata_urb
->purb
);
4862 JOM(4, "%i audio urbs killed\n", m
);
4866 /*---------------------------------------------------------------------------*/
4870 /*--------------------------------------------------------------------------*/
4874 * THIS PROCEDURE WILL BLOCK UNTIL easycap_poll(), VIDEO IOCTL AND AUDIO
4875 * IOCTL ARE ALL UNLOCKED. IF THIS IS NOT DONE AN Oops CAN OCCUR WHEN
4876 * AN EasyCAP IS UNPLUGGED WHILE THE URBS ARE RUNNING. BEWARE.
4878 /*--------------------------------------------------------------------------*/
4879 kd
= isdongle(peasycap
);
4880 switch (bInterfaceNumber
) {
4882 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4883 wake_up_interruptible(&peasycap
->wq_video
);
4884 JOM(4, "about to lock easycap_dongle[%i].mutex_video\n", kd
);
4885 if (mutex_lock_interruptible(&easycap_dongle
[kd
].\
4887 SAY("ERROR: cannot lock easycap_dongle[%i]." \
4888 "mutex_video\n", kd
);
4891 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd
);
4893 SAY("ERROR: %i=kd is bad: cannot lock dongle\n", kd
);
4894 /*---------------------------------------------------------------------------*/
4895 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4896 if ((struct easycap
*)NULL
== peasycap
) {
4897 SAM("ERROR: peasycap has become NULL\n");
4899 usb_deregister_dev(pusb_interface
, &easycap_class
);
4900 (peasycap
->registered_video
)--;
4901 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber
);
4902 SAM("easycap detached from minor #%d\n", minor
);
4904 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4906 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4907 if (!peasycap
->v4l2_device
.name
[0]) {
4908 SAM("ERROR: peasycap->v4l2_device.name is empty\n");
4909 if (0 <= kd
&& DONGLE_MANY
> kd
)
4910 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
4913 v4l2_device_disconnect(&peasycap
->v4l2_device
);
4914 JOM(4, "v4l2_device_disconnect() OK\n");
4915 v4l2_device_unregister(&peasycap
->v4l2_device
);
4916 JOM(4, "v4l2_device_unregister() OK\n");
4917 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4919 video_unregister_device(&peasycap
->video_device
);
4920 JOM(4, "intf[%i]: video_unregister_device() OK\n", bInterfaceNumber
);
4921 (peasycap
->registered_video
)--;
4922 JOM(4, "unregistered with videodev: %i=minor\n", minor
);
4923 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4924 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4926 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4927 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
4928 JOM(4, "unlocked easycap_dongle[%i].mutex_video\n", kd
);
4933 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4934 wake_up_interruptible(&peasycap
->wq_audio
);
4935 JOM(4, "about to lock easycap_dongle[%i].mutex_audio\n", kd
);
4936 if (mutex_lock_interruptible(&easycap_dongle
[kd
].\
4938 SAY("ERROR: cannot lock easycap_dongle[%i]." \
4939 "mutex_audio\n", kd
);
4942 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd
);
4944 SAY("ERROR: %i=kd is bad: cannot lock dongle\n", kd
);
4946 usb_deregister_dev(pusb_interface
, &easysnd_class
);
4947 (peasycap
->registered_audio
)--;
4949 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber
);
4950 SAM("easysnd detached from minor #%d\n", minor
);
4952 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4953 mutex_unlock(&easycap_dongle
[kd
].mutex_audio
);
4954 JOM(4, "unlocked easycap_dongle[%i].mutex_audio\n", kd
);
4961 /*---------------------------------------------------------------------------*/
4963 * CALL easycap_delete() IF NO REMAINING REFERENCES TO peasycap
4965 /*---------------------------------------------------------------------------*/
4966 if (!peasycap
->kref
.refcount
.counter
) {
4967 SAM("ERROR: peasycap->kref.refcount.counter is zero "
4968 "so cannot call kref_put()\n");
4969 SAM("ending unsuccessfully: may cause memory leak\n");
4972 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4973 JOM(4, "about to lock easycap_dongle[%i].mutex_video\n", kd
);
4974 if (mutex_lock_interruptible(&easycap_dongle
[kd
].mutex_video
)) {
4975 SAY("ERROR: cannot down easycap_dongle[%i].mutex_video\n", kd
);
4976 SAM("ending unsuccessfully: may cause memory leak\n");
4979 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd
);
4980 JOM(4, "about to lock easycap_dongle[%i].mutex_audio\n", kd
);
4981 if (mutex_lock_interruptible(&easycap_dongle
[kd
].mutex_audio
)) {
4982 SAY("ERROR: cannot down easycap_dongle[%i].mutex_audio\n", kd
);
4983 mutex_unlock(&(easycap_dongle
[kd
].mutex_video
));
4984 JOM(4, "unlocked easycap_dongle[%i].mutex_video\n", kd
);
4985 SAM("ending unsuccessfully: may cause memory leak\n");
4988 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd
);
4990 JOM(4, "intf[%i]: %i=peasycap->kref.refcount.counter\n", \
4991 bInterfaceNumber
, (int)peasycap
->kref
.refcount
.counter
);
4992 kref_put(&peasycap
->kref
, easycap_delete
);
4993 JOT(4, "intf[%i]: kref_put() done.\n", bInterfaceNumber
);
4994 if (0 <= kd
&& DONGLE_MANY
> kd
) {
4995 mutex_unlock(&(easycap_dongle
[kd
].mutex_audio
));
4996 JOT(4, "unlocked easycap_dongle[%i].mutex_audio\n", kd
);
4997 mutex_unlock(&easycap_dongle
[kd
].mutex_video
);
4998 JOT(4, "unlocked easycap_dongle[%i].mutex_video\n", kd
);
5000 /*---------------------------------------------------------------------------*/
5004 /*****************************************************************************/
5006 easycap_module_init(void)
5010 SAY("========easycap=======\n");
5011 JOT(4, "begins. %i=debug %i=bars %i=gain\n", easycap_debug
, easycap_bars
, \
5013 SAY("version: " EASYCAP_DRIVER_VERSION
"\n");
5014 /*---------------------------------------------------------------------------*/
5016 * REGISTER THIS DRIVER WITH THE USB SUBSYTEM.
5018 /*---------------------------------------------------------------------------*/
5019 JOT(4, "registering driver easycap\n");
5021 result
= usb_register(&easycap_usb_driver
);
5023 SAY("ERROR: usb_register returned %i\n", result
);
5028 /*****************************************************************************/
5030 easycap_module_exit(void)
5034 /*---------------------------------------------------------------------------*/
5036 * DEREGISTER THIS DRIVER WITH THE USB SUBSYTEM.
5038 /*---------------------------------------------------------------------------*/
5039 usb_deregister(&easycap_usb_driver
);
5043 /*****************************************************************************/
5045 module_init(easycap_module_init
);
5046 module_exit(easycap_module_exit
);
5048 MODULE_LICENSE("GPL");
5049 MODULE_AUTHOR("R.M. Thomas <rmthomas@sciolus.org>");
5050 MODULE_DESCRIPTION(EASYCAP_DRIVER_DESCRIPTION
);
5051 MODULE_VERSION(EASYCAP_DRIVER_VERSION
);
5052 #if defined(EASYCAP_DEBUG)
5053 MODULE_PARM_DESC(debug
, "Debug level: 0(default),1,2,...,9");
5054 #endif /*EASYCAP_DEBUG*/
5055 MODULE_PARM_DESC(bars
, \
5056 "Testcard bars on input signal failure: 0=>no, 1=>yes(default)");
5057 MODULE_PARM_DESC(gain
, "Audio gain: 0,...,16(default),...31");
5058 /*****************************************************************************/