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