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