]> Pileus Git - ~andy/linux/blob - drivers/staging/easycap/easycap.h
staging: easycap: drop redunant backslashes from the code
[~andy/linux] / drivers / staging / easycap / easycap.h
1 /*****************************************************************************
2 *                                                                            *
3 *  easycap.h                                                                 *
4 *                                                                            *
5 *****************************************************************************/
6 /*
7  *
8  *  Copyright (C) 2010 R.M. Thomas  <rmthomas@sciolus.org>
9  *
10  *
11  *  This is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  The software is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this software; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25 */
26 /*****************************************************************************/
27 /*---------------------------------------------------------------------------*/
28 /*
29  *  THE FOLLOWING PARAMETERS ARE UNDEFINED:
30  *
31  *                EASYCAP_DEBUG
32  *                EASYCAP_IS_VIDEODEV_CLIENT
33  *                EASYCAP_NEEDS_USBVIDEO_H
34  *                EASYCAP_NEEDS_V4L2_DEVICE_H
35  *                EASYCAP_NEEDS_V4L2_FOPS
36  *                EASYCAP_NEEDS_UNLOCKED_IOCTL
37  *                EASYCAP_NEEDS_ALSA
38  *                EASYCAP_SILENT
39  *
40  *  IF REQUIRED THEY MUST BE EXTERNALLY DEFINED, FOR EXAMPLE AS COMPILER
41  *  OPTIONS.
42  */
43 /*---------------------------------------------------------------------------*/
44
45 #if (!defined(EASYCAP_H))
46 #define EASYCAP_H
47
48 /*---------------------------------------------------------------------------*/
49 /*
50  *  THESE ARE NORMALLY DEFINED
51  */
52 /*---------------------------------------------------------------------------*/
53 #define  PATIENCE  500
54 #undef   PREFER_NTSC
55 #define  PERSEVERE
56 /*---------------------------------------------------------------------------*/
57 /*
58  *  THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED:
59  */
60 /*---------------------------------------------------------------------------*/
61 #undef  EASYCAP_TESTCARD
62 #if (!defined(EASYCAP_NEEDS_ALSA))
63 #undef  EASYCAP_TESTTONE
64 #endif /*EASYCAP_NEEDS_ALSA*/
65 /*---------------------------------------------------------------------------*/
66 #include <linux/kernel.h>
67 #include <linux/errno.h>
68 #include <linux/init.h>
69 #include <linux/slab.h>
70 #include <linux/module.h>
71 #include <linux/kref.h>
72 #include <linux/usb.h>
73 #include <linux/uaccess.h>
74
75 #include <linux/i2c.h>
76 #include <linux/version.h>
77 #include <linux/workqueue.h>
78 #include <linux/poll.h>
79 #include <linux/mm.h>
80 #include <linux/fs.h>
81 #include <linux/delay.h>
82 #include <linux/types.h>
83
84 #if defined(EASYCAP_NEEDS_ALSA)
85 #include <linux/vmalloc.h>
86 #include <linux/sound.h>
87 #include <sound/core.h>
88 #include <sound/pcm.h>
89 #include <sound/pcm_params.h>
90 #include <sound/info.h>
91 #include <sound/initval.h>
92 #include <sound/control.h>
93 #endif /*EASYCAP_NEEDS_ALSA*/
94 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
95 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
96 #include <media/v4l2-dev.h>
97 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
98 #include <media/v4l2-device.h>
99 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
100 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
101 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
102 #include <linux/videodev2.h>
103 #include <linux/soundcard.h>
104 #if defined(EASYCAP_NEEDS_USBVIDEO_H)
105 #include <config/video/usbvideo.h>
106 #endif /*EASYCAP_NEEDS_USBVIDEO_H*/
107
108 #if (!defined(PAGE_SIZE))
109 #error "PAGE_SIZE not defined"
110 #endif
111
112 #define STRINGIZE_AGAIN(x) #x
113 #define STRINGIZE(x) STRINGIZE_AGAIN(x)
114 /*---------------------------------------------------------------------------*/
115 /*  VENDOR, PRODUCT:  Syntek Semiconductor Co., Ltd
116  *
117  *      EITHER        EasyCAP USB 2.0 Video Adapter with Audio, Model No. DC60
118  *               with input cabling:  AUDIO(L), AUDIO(R), CVBS, S-VIDEO.
119  *
120  *          OR        EasyCAP 4CHANNEL USB 2.0 DVR, Model No. EasyCAP002
121  *               with input cabling:  MICROPHONE, CVBS1, CVBS2, CVBS3, CVBS4.
122  */
123 /*---------------------------------------------------------------------------*/
124 #define USB_EASYCAP_VENDOR_ID   0x05e1
125 #define USB_EASYCAP_PRODUCT_ID  0x0408
126
127 #define EASYCAP_DRIVER_VERSION "0.9.01"
128 #define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
129
130 #define USB_SKEL_MINOR_BASE     192
131 #define DONGLE_MANY 8
132 #define INPUT_MANY 6
133 /*---------------------------------------------------------------------------*/
134 /*
135  *  DEFAULT LUMINANCE, CONTRAST, SATURATION AND HUE
136  */
137 /*---------------------------------------------------------------------------*/
138 #define SAA_0A_DEFAULT 0x7F
139 #define SAA_0B_DEFAULT 0x3F
140 #define SAA_0C_DEFAULT 0x2F
141 #define SAA_0D_DEFAULT 0x00
142 /*---------------------------------------------------------------------------*/
143 /*
144  *  VIDEO STREAMING PARAMETERS:
145  *  USB 2.0 PROVIDES FOR HIGH-BANDWIDTH ENDPOINTS WITH AN UPPER LIMIT
146  *  OF 3072 BYTES PER MICROFRAME for wMaxPacketSize.
147  */
148 /*---------------------------------------------------------------------------*/
149 #define VIDEO_ISOC_BUFFER_MANY 16
150 #define VIDEO_ISOC_ORDER 3
151 #define VIDEO_ISOC_FRAMESPERDESC ((unsigned int) 1 << VIDEO_ISOC_ORDER)
152 #define USB_2_0_MAXPACKETSIZE 3072
153 #if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE)
154 #error video_isoc_buffer[.] will not be big enough
155 #endif
156 #define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY
157 #define VIDEO_LOST_TOLERATE 50
158 /*---------------------------------------------------------------------------*/
159 /*
160  *  VIDEO BUFFERS
161  */
162 /*---------------------------------------------------------------------------*/
163 #define FIELD_BUFFER_SIZE (203 * PAGE_SIZE)
164 #define FRAME_BUFFER_SIZE (405 * PAGE_SIZE)
165 #define FIELD_BUFFER_MANY 4
166 #define FRAME_BUFFER_MANY 6
167 /*---------------------------------------------------------------------------*/
168 /*
169  *  AUDIO STREAMING PARAMETERS
170  */
171 /*---------------------------------------------------------------------------*/
172 #define AUDIO_ISOC_BUFFER_MANY 16
173 #define AUDIO_ISOC_ORDER 1
174 #define AUDIO_ISOC_FRAMESPERDESC 32
175 #define AUDIO_ISOC_BUFFER_SIZE (PAGE_SIZE << AUDIO_ISOC_ORDER)
176 /*---------------------------------------------------------------------------*/
177 /*
178  *  AUDIO BUFFERS
179  */
180 /*---------------------------------------------------------------------------*/
181 #define AUDIO_FRAGMENT_MANY 32
182 #define PAGES_PER_AUDIO_FRAGMENT 4
183 /*---------------------------------------------------------------------------*/
184 /*
185  *  IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
186  *                        ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
187  *  THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE.  NOT
188  *  ONLY MUST THE PARAMETER
189  *                             STANDARD_MANY
190  *  BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
191  *  NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE:  DUMMY STANDARDS
192  *  MAY NEED TO BE ADDED.   APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
193  *  ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE.  BEWARE.
194  */
195 /*---------------------------------------------------------------------------*/
196 #define  PAL_BGHIN      0
197 #define  PAL_Nc         2
198 #define  SECAM          4
199 #define  NTSC_N         6
200 #define  NTSC_N_443     8
201 #define  NTSC_M         1
202 #define  NTSC_443       3
203 #define  NTSC_M_JP      5
204 #define  PAL_60         7
205 #define  PAL_M          9
206 #define  PAL_BGHIN_SLOW    10
207 #define  PAL_Nc_SLOW       12
208 #define  SECAM_SLOW        14
209 #define  NTSC_N_SLOW       16
210 #define  NTSC_N_443_SLOW   18
211 #define  NTSC_M_SLOW       11
212 #define  NTSC_443_SLOW     13
213 #define  NTSC_M_JP_SLOW    15
214 #define  PAL_60_SLOW       17
215 #define  PAL_M_SLOW        19
216 #define  STANDARD_MANY 20
217 /*---------------------------------------------------------------------------*/
218 /*
219  *  ENUMS
220  */
221 /*---------------------------------------------------------------------------*/
222 enum {
223 AT_720x576,
224 AT_704x576,
225 AT_640x480,
226 AT_720x480,
227 AT_360x288,
228 AT_320x240,
229 AT_360x240,
230 RESOLUTION_MANY
231 };
232 enum {
233 FMT_UYVY,
234 FMT_YUY2,
235 FMT_RGB24,
236 FMT_RGB32,
237 FMT_BGR24,
238 FMT_BGR32,
239 PIXELFORMAT_MANY
240 };
241 enum {
242 FIELD_NONE,
243 FIELD_INTERLACED,
244 INTERLACE_MANY
245 };
246 #define SETTINGS_MANY   (STANDARD_MANY * \
247                         RESOLUTION_MANY * \
248                         2 * \
249                         PIXELFORMAT_MANY * \
250                         INTERLACE_MANY)
251 /*---------------------------------------------------------------------------*/
252 /*
253  *  STRUCTURE DEFINITIONS
254  */
255 /*---------------------------------------------------------------------------*/
256 struct easycap_dongle {
257 struct easycap *peasycap;
258 struct mutex mutex_video;
259 struct mutex mutex_audio;
260 };
261 /*---------------------------------------------------------------------------*/
262 struct data_buffer {
263 struct list_head list_head;
264 void *pgo;
265 void *pto;
266 __u16 kount;
267 __u16 input;
268 };
269 /*---------------------------------------------------------------------------*/
270 struct data_urb {
271 struct list_head list_head;
272 struct urb *purb;
273 int isbuf;
274 int length;
275 };
276 /*---------------------------------------------------------------------------*/
277 struct easycap_standard {
278 __u16 mask;
279 struct v4l2_standard v4l2_standard;
280 };
281 struct easycap_format {
282 __u16 mask;
283 char name[128];
284 struct v4l2_format v4l2_format;
285 };
286 struct inputset {
287 int input;
288 int input_ok;
289 int standard_offset;
290 int standard_offset_ok;
291 int format_offset;
292 int format_offset_ok;
293 int brightness;
294 int brightness_ok;
295 int contrast;
296 int contrast_ok;
297 int saturation;
298 int saturation_ok;
299 int hue;
300 int hue_ok;
301 };
302 /*---------------------------------------------------------------------------*/
303 /*
304  *   easycap.ilk == 0   =>  CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256
305  *   easycap.ilk == 2   =>  CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=9
306  *   easycap.ilk == 3   =>     FOUR-CVBS HARDWARE, AUDIO wMaxPacketSize=9
307  */
308 /*---------------------------------------------------------------------------*/
309 struct easycap {
310 #define TELLTALE "expectedstring"
311 char telltale[16];
312 int isdongle;
313 int minor;
314
315 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
316 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
317 struct video_device video_device;
318 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
319 struct v4l2_device v4l2_device;
320 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
321 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
322 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
323 int status;
324 unsigned int audio_pages_per_fragment;
325 unsigned int audio_bytes_per_fragment;
326 unsigned int audio_buffer_page_many;
327
328 #define UPSAMPLE
329 #if defined(UPSAMPLE)
330 __s16 oldaudio;
331 #endif /*UPSAMPLE*/
332
333 int ilk;
334 bool microphone;
335
336 struct usb_device *pusb_device;
337 struct usb_interface *pusb_interface;
338
339 struct kref kref;
340
341 int queued[FRAME_BUFFER_MANY];
342 int done[FRAME_BUFFER_MANY];
343
344 wait_queue_head_t wq_video;
345 wait_queue_head_t wq_audio;
346 wait_queue_head_t wq_trigger;
347
348 int input;
349 int polled;
350 int standard_offset;
351 int format_offset;
352 struct inputset inputset[INPUT_MANY];
353
354 bool ntsc;
355 int fps;
356 int usec;
357 int tolerate;
358 int skip;
359 int skipped;
360 int lost[INPUT_MANY];
361 int merit[180];
362
363 struct timeval timeval0;
364 struct timeval timeval1;
365 struct timeval timeval2;
366 struct timeval timeval3;
367 struct timeval timeval6;
368 struct timeval timeval7;
369 struct timeval timeval8;
370 long long int dnbydt;
371
372 int    video_interface;
373 int    video_altsetting_on;
374 int    video_altsetting_off;
375 int    video_endpointnumber;
376 int    video_isoc_maxframesize;
377 int    video_isoc_buffer_size;
378 int    video_isoc_framesperdesc;
379
380 int    video_isoc_streaming;
381 int    video_isoc_sequence;
382 int    video_idle;
383 int    video_eof;
384 int    video_junk;
385
386 struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY];
387 struct data_buffer
388              field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)];
389 struct data_buffer
390              frame_buffer[FRAME_BUFFER_MANY][(FRAME_BUFFER_SIZE/PAGE_SIZE)];
391
392 struct list_head urb_video_head;
393 struct list_head *purb_video_head;
394
395 __u8 cache[8];
396 __u8 *pcache;
397 int video_mt;
398 int audio_mt;
399 long long audio_bytes;
400 __u32 isequence;
401
402 int vma_many;
403
404 /*---------------------------------------------------------------------------*/
405 /*
406  *  BUFFER INDICATORS
407  */
408 /*---------------------------------------------------------------------------*/
409 int field_fill;         /* Field buffer being filled by easycap_complete().  */
410                         /*   Bumped only by easycap_complete().              */
411 int field_page;         /* Page of field buffer page being filled by         */
412                         /*   easycap_complete().                             */
413 int field_read;         /* Field buffer to be read by field2frame().         */
414                         /*   Bumped only by easycap_complete().              */
415 int frame_fill;         /* Frame buffer being filled by field2frame().       */
416                         /*   Bumped only by easycap_dqbuf() when             */
417                         /*   field2frame() has created a complete frame.     */
418 int frame_read;         /* Frame buffer offered to user by DQBUF.            */
419                         /*   Set only by easycap_dqbuf() to trail frame_fill.*/
420 int frame_lock;         /* Flag set to 1 by DQBUF and cleared by QBUF        */
421 /*---------------------------------------------------------------------------*/
422 /*
423  *  IMAGE PROPERTIES
424  */
425 /*---------------------------------------------------------------------------*/
426 __u32                   pixelformat;
427 int                     width;
428 int                     height;
429 int                     bytesperpixel;
430 bool                    byteswaporder;
431 bool                    decimatepixel;
432 bool                    offerfields;
433 int                     frame_buffer_used;
434 int                     frame_buffer_many;
435 int                     videofieldamount;
436
437 int                     brightness;
438 int                     contrast;
439 int                     saturation;
440 int                     hue;
441
442 int allocation_video_urb;
443 int allocation_video_page;
444 int allocation_video_struct;
445 int registered_video;
446 /*---------------------------------------------------------------------------*/
447 /*
448  *  ALSA
449  */
450 /*---------------------------------------------------------------------------*/
451 #if defined(EASYCAP_NEEDS_ALSA)
452 struct snd_pcm_hardware alsa_hardware;
453 struct snd_card *psnd_card;
454 struct snd_pcm *psnd_pcm;
455 struct snd_pcm_substream *psubstream;
456 int dma_fill;
457 int dma_next;
458 int dma_read;
459 #endif /*EASYCAP_NEEDS_ALSA*/
460 /*---------------------------------------------------------------------------*/
461 /*
462  *  SOUND PROPERTIES
463  */
464 /*---------------------------------------------------------------------------*/
465 int audio_interface;
466 int audio_altsetting_on;
467 int audio_altsetting_off;
468 int audio_endpointnumber;
469 int audio_isoc_maxframesize;
470 int audio_isoc_buffer_size;
471 int audio_isoc_framesperdesc;
472
473 int audio_isoc_streaming;
474 int audio_idle;
475 int audio_eof;
476 int volume;
477 int mute;
478 s8 gain;
479
480 struct data_buffer audio_isoc_buffer[AUDIO_ISOC_BUFFER_MANY];
481
482 struct list_head urb_audio_head;
483 struct list_head *purb_audio_head;
484 /*---------------------------------------------------------------------------*/
485 /*
486  *  BUFFER INDICATORS
487  */
488 /*---------------------------------------------------------------------------*/
489 int audio_fill;         /* Audio buffer being filled by easycap_complete().  */
490                         /*   Bumped only by easycap_complete().              */
491 int audio_read;         /* Audio buffer page being read by easycap_read().   */
492                         /*   Set by easycap_read() to trail audio_fill by    */
493                         /*   one fragment.                                   */
494 /*---------------------------------------------------------------------------*/
495 /*
496  *  SOUND PROPERTIES
497  */
498 /*---------------------------------------------------------------------------*/
499
500 int audio_buffer_many;
501
502 int allocation_audio_urb;
503 int allocation_audio_page;
504 int allocation_audio_struct;
505 int registered_audio;
506
507 long long int audio_sample;
508 long long int audio_niveau;
509 long long int audio_square;
510
511 struct data_buffer audio_buffer[];
512 };
513 /*---------------------------------------------------------------------------*/
514 /*
515  *  VIDEO FUNCTION PROTOTYPES
516  */
517 /*---------------------------------------------------------------------------*/
518 void             easycap_complete(struct urb *);
519 int              easycap_open(struct inode *, struct file *);
520 int              easycap_release(struct inode *, struct file *);
521 long             easycap_ioctl_noinode(struct file *, unsigned int,
522                                                                 unsigned long);
523 int              easycap_ioctl(struct inode *, struct file *, unsigned int,
524                                                                 unsigned long);
525 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
526 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
527 int              easycap_open_noinode(struct file *);
528 int              easycap_release_noinode(struct file *);
529 int              videodev_release(struct video_device *);
530 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
531 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
532
533 unsigned int     easycap_poll(struct file *, poll_table *);
534 int              easycap_mmap(struct file *, struct vm_area_struct *);
535 int              easycap_usb_probe(struct usb_interface *,
536                                                 const struct usb_device_id *);
537 void             easycap_usb_disconnect(struct usb_interface *);
538 void             easycap_delete(struct kref *);
539
540 void             easycap_vma_open(struct vm_area_struct *);
541 void             easycap_vma_close(struct vm_area_struct *);
542 int              easycap_vma_fault(struct vm_area_struct *, struct vm_fault *);
543 int              easycap_dqbuf(struct easycap *, int);
544 int              submit_video_urbs(struct easycap *);
545 int              kill_video_urbs(struct easycap *);
546 int              field2frame(struct easycap *);
547 int              redaub(struct easycap *, void *, void *,
548                                                 int, int, __u8, __u8, bool);
549 void             easycap_testcard(struct easycap *, int);
550 int              fillin_formats(void);
551 int              reset(struct easycap *);
552 int              newinput(struct easycap *, int);
553 int              adjust_standard(struct easycap *, v4l2_std_id);
554 int              adjust_format(struct easycap *, __u32, __u32, __u32,
555                                                                 int, bool);
556 int              adjust_brightness(struct easycap *, int);
557 int              adjust_contrast(struct easycap *, int);
558 int              adjust_saturation(struct easycap *, int);
559 int              adjust_hue(struct easycap *, int);
560 int              adjust_volume(struct easycap *, int);
561 /*---------------------------------------------------------------------------*/
562 /*
563  *  AUDIO FUNCTION PROTOTYPES
564  */
565 /*---------------------------------------------------------------------------*/
566 #if defined(EASYCAP_NEEDS_ALSA)
567 int             easycap_alsa_probe(struct easycap *);
568
569 void            easycap_alsa_complete(struct urb *);
570 int             easycap_alsa_open(struct snd_pcm_substream *);
571 int             easycap_alsa_close(struct snd_pcm_substream *);
572 int             easycap_alsa_hw_params(struct snd_pcm_substream *,
573                                                 struct snd_pcm_hw_params *);
574 int             easycap_alsa_vmalloc(struct snd_pcm_substream *, size_t);
575 int             easycap_alsa_hw_free(struct snd_pcm_substream *);
576 int             easycap_alsa_prepare(struct snd_pcm_substream *);
577 int             easycap_alsa_ack(struct snd_pcm_substream *);
578 int             easycap_alsa_trigger(struct snd_pcm_substream *, int);
579 snd_pcm_uframes_t easycap_alsa_pointer(struct snd_pcm_substream *);
580 struct page     *easycap_alsa_page(struct snd_pcm_substream *, unsigned long);
581
582 #else
583 void             easyoss_complete(struct urb *);
584 ssize_t          easyoss_read(struct file *, char __user *, size_t, loff_t *);
585 int              easyoss_open(struct inode *, struct file *);
586 int              easyoss_release(struct inode *, struct file *);
587 long             easyoss_ioctl_noinode(struct file *, unsigned int,
588                                                                 unsigned long);
589 int              easyoss_ioctl(struct inode *, struct file *, unsigned int,
590                                                                 unsigned long);
591 unsigned int     easyoss_poll(struct file *, poll_table *);
592 void             easyoss_delete(struct kref *);
593 #endif /*EASYCAP_NEEDS_ALSA*/
594 int              easycap_sound_setup(struct easycap *);
595 int              submit_audio_urbs(struct easycap *);
596 int              kill_audio_urbs(struct easycap *);
597 void             easyoss_testtone(struct easycap *, int);
598 int              audio_setup(struct easycap *);
599 /*---------------------------------------------------------------------------*/
600 /*
601  *  LOW-LEVEL FUNCTION PROTOTYPES
602  */
603 /*---------------------------------------------------------------------------*/
604 int              audio_gainget(struct usb_device *);
605 int              audio_gainset(struct usb_device *, __s8);
606
607 int              set_interface(struct usb_device *, __u16);
608 int              wakeup_device(struct usb_device *);
609 int              confirm_resolution(struct usb_device *);
610 int              confirm_stream(struct usb_device *);
611
612 int              setup_stk(struct usb_device *, bool);
613 int              setup_saa(struct usb_device *, bool);
614 int              setup_vt(struct usb_device *);
615 int              check_stk(struct usb_device *, bool);
616 int              check_saa(struct usb_device *, bool);
617 int              ready_saa(struct usb_device *);
618 int              merit_saa(struct usb_device *);
619 int              check_vt(struct usb_device *);
620 int              select_input(struct usb_device *, int, int);
621 int              set_resolution(struct usb_device *,
622                                                 __u16, __u16, __u16, __u16);
623
624 int              read_saa(struct usb_device *, __u16);
625 int              read_stk(struct usb_device *, __u32);
626 int              write_saa(struct usb_device *, __u16, __u16);
627 int              wait_i2c(struct usb_device *);
628 int              write_000(struct usb_device *, __u16, __u16);
629 int              start_100(struct usb_device *);
630 int              stop_100(struct usb_device *);
631 int              write_300(struct usb_device *);
632 int              read_vt(struct usb_device *, __u16);
633 int              write_vt(struct usb_device *, __u16, __u16);
634 int              regset(struct usb_device *, __u16, __u16);
635 int              regget(struct usb_device *, __u16, void *);
636 int             isdongle(struct easycap *);
637 /*---------------------------------------------------------------------------*/
638 struct signed_div_result {
639 long long int quotient;
640 unsigned long long int remainder;
641 } signed_div(long long int, long long int);
642
643
644 /*---------------------------------------------------------------------------*/
645 /*
646  *  MACROS
647  */
648 /*---------------------------------------------------------------------------*/
649 #define GET(X, Y, Z) do { \
650         int rc; \
651         *(Z) = (__u16)0; \
652         rc = regget(X, Y, Z); \
653         if (0 > rc) { \
654                 JOT(8, ":-(%i\n", __LINE__);  return(rc); \
655         } \
656 } while (0)
657
658 #define SET(X, Y, Z) do { \
659         int rc; \
660         rc = regset(X, Y, Z); \
661         if (0 > rc) { \
662                 JOT(8, ":-(%i\n", __LINE__);  return(rc); \
663         } \
664 } while (0)
665 /*---------------------------------------------------------------------------*/
666 /*
667  *  MACROS SAM(...) AND JOM(...) ALLOW DIAGNOSTIC OUTPUT TO BE TAGGED WITH
668  *  THE IDENTITY OF THE DONGLE TO WHICH IT APPLIES, BUT IF INVOKED WHEN THE
669  *  POINTER peasycap IS INVALID AN Oops IS LIKELY, AND ITS CAUSE MAY NOT BE
670  *  IMMEDIATELY OBVIOUS FROM A CASUAL READING OF THE SOURCE CODE.  BEWARE.
671 */
672 /*---------------------------------------------------------------------------*/
673 extern int easycap_debug;
674 #define SAY(format, args...) do { \
675         printk(KERN_DEBUG "easycap:: %s: " \
676                         format, __func__, ##args); \
677 } while (0)
678 #define SAM(format, args...) do { \
679         printk(KERN_DEBUG "easycap::%i%s: " \
680                         format, peasycap->isdongle, __func__, ##args);\
681 } while (0)
682
683 #if defined(EASYCAP_DEBUG)
684 #define JOT(n, format, args...) do { \
685         if (n <= easycap_debug) { \
686                 printk(KERN_DEBUG "easycap:: %s: " \
687                         format, __func__, ##args);\
688         } \
689 } while (0)
690 #define JOM(n, format, args...) do { \
691         if (n <= easycap_debug) { \
692                 printk(KERN_DEBUG "easycap::%i%s: " \
693                         format, peasycap->isdongle, __func__, ##args);\
694         } \
695 } while (0)
696
697 #else
698 #define JOT(n, format, args...) do {} while (0)
699 #define JOM(n, format, args...) do {} while (0)
700 #endif /*EASYCAP_DEBUG*/
701
702 #define MICROSECONDS(X, Y) \
703                         ((1000000*((long long int)(X.tv_sec - Y.tv_sec))) + \
704                                         (long long int)(X.tv_usec - Y.tv_usec))
705
706 /*---------------------------------------------------------------------------*/
707 /*
708  *  (unsigned char *)P           pointer to next byte pair
709  *       (long int *)X           pointer to accumulating count
710  *       (long int *)Y           pointer to accumulating sum
711  *  (long long int *)Z           pointer to accumulating sum of squares
712  */
713 /*---------------------------------------------------------------------------*/
714 #define SUMMER(P, X, Y, Z) do {                                 \
715         unsigned char *p;                                    \
716         unsigned int u0, u1, u2;                             \
717         long int s;                                          \
718         p = (unsigned char *)(P);                            \
719         u0 = (unsigned int) (*p);                            \
720         u1 = (unsigned int) (*(p + 1));                      \
721         u2 = (unsigned int) ((u1 << 8) | u0);                \
722         if (0x8000 & u2)                                     \
723                 s = -(long int)(0x7FFF & (~u2));             \
724         else                                                 \
725                 s =  (long int)(0x7FFF & u2);                \
726         *((X)) += (long int) 1;                              \
727         *((Y)) += (long int) s;                              \
728         *((Z)) += ((long long int)(s) * (long long int)(s)); \
729 } while (0)
730 /*---------------------------------------------------------------------------*/
731
732 #endif /*EASYCAP_H*/