at v2.6.38 680 lines 24 kB view raw
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/*---------------------------------------------------------------------------*/ 209enum { 210AT_720x576, 211AT_704x576, 212AT_640x480, 213AT_720x480, 214AT_360x288, 215AT_320x240, 216AT_360x240, 217RESOLUTION_MANY 218}; 219enum { 220FMT_UYVY, 221FMT_YUY2, 222FMT_RGB24, 223FMT_RGB32, 224FMT_BGR24, 225FMT_BGR32, 226PIXELFORMAT_MANY 227}; 228enum { 229FIELD_NONE, 230FIELD_INTERLACED, 231INTERLACE_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/*---------------------------------------------------------------------------*/ 243struct easycap_dongle { 244struct easycap *peasycap; 245struct mutex mutex_video; 246struct mutex mutex_audio; 247}; 248/*---------------------------------------------------------------------------*/ 249struct data_buffer { 250struct list_head list_head; 251void *pgo; 252void *pto; 253__u16 kount; 254__u16 input; 255}; 256/*---------------------------------------------------------------------------*/ 257struct data_urb { 258struct list_head list_head; 259struct urb *purb; 260int isbuf; 261int length; 262}; 263/*---------------------------------------------------------------------------*/ 264struct easycap_standard { 265__u16 mask; 266struct v4l2_standard v4l2_standard; 267}; 268struct easycap_format { 269__u16 mask; 270char name[128]; 271struct v4l2_format v4l2_format; 272}; 273struct inputset { 274int input; 275int input_ok; 276int standard_offset; 277int standard_offset_ok; 278int format_offset; 279int format_offset_ok; 280int brightness; 281int brightness_ok; 282int contrast; 283int contrast_ok; 284int saturation; 285int saturation_ok; 286int hue; 287int 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/*---------------------------------------------------------------------------*/ 296struct easycap { 297#define TELLTALE "expectedstring" 298char telltale[16]; 299int isdongle; 300 301/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 302#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 303struct video_device video_device; 304#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H) 305struct v4l2_device v4l2_device; 306#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/ 307#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 308/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 309int status; 310unsigned int audio_pages_per_fragment; 311unsigned int audio_bytes_per_fragment; 312unsigned int audio_buffer_page_many; 313 314#define UPSAMPLE 315#if defined(UPSAMPLE) 316__s16 oldaudio; 317#endif /*UPSAMPLE*/ 318 319int ilk; 320bool microphone; 321 322struct usb_device *pusb_device; 323struct usb_interface *pusb_interface; 324 325struct kref kref; 326 327int queued[FRAME_BUFFER_MANY]; 328int done[FRAME_BUFFER_MANY]; 329 330wait_queue_head_t wq_video; 331wait_queue_head_t wq_audio; 332 333int input; 334int polled; 335int standard_offset; 336int format_offset; 337struct inputset inputset[INPUT_MANY]; 338 339bool ntsc; 340int fps; 341int usec; 342int tolerate; 343int skip; 344int skipped; 345int lost[INPUT_MANY]; 346int merit[180]; 347 348struct timeval timeval0; 349struct timeval timeval1; 350struct timeval timeval2; 351struct timeval timeval3; 352struct timeval timeval6; 353struct timeval timeval7; 354struct timeval timeval8; 355long long int dnbydt; 356 357int video_interface; 358int video_altsetting_on; 359int video_altsetting_off; 360int video_endpointnumber; 361int video_isoc_maxframesize; 362int video_isoc_buffer_size; 363int video_isoc_framesperdesc; 364 365int video_isoc_streaming; 366int video_isoc_sequence; 367int video_idle; 368int video_eof; 369int video_junk; 370 371struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY]; 372struct data_buffer \ 373 field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)]; 374struct data_buffer \ 375 frame_buffer[FRAME_BUFFER_MANY][(FRAME_BUFFER_SIZE/PAGE_SIZE)]; 376 377struct list_head urb_video_head; 378struct list_head *purb_video_head; 379 380__u8 cache[8]; 381__u8 *pcache; 382int video_mt; 383int audio_mt; 384long long audio_bytes; 385__u32 isequence; 386 387int vma_many; 388 389/*---------------------------------------------------------------------------*/ 390/* 391 * BUFFER INDICATORS 392 */ 393/*---------------------------------------------------------------------------*/ 394int field_fill; /* Field buffer being filled by easycap_complete(). */ 395 /* Bumped only by easycap_complete(). */ 396int field_page; /* Page of field buffer page being filled by */ 397 /* easycap_complete(). */ 398int field_read; /* Field buffer to be read by field2frame(). */ 399 /* Bumped only by easycap_complete(). */ 400int frame_fill; /* Frame buffer being filled by field2frame(). */ 401 /* Bumped only by easycap_dqbuf() when */ 402 /* field2frame() has created a complete frame. */ 403int frame_read; /* Frame buffer offered to user by DQBUF. */ 404 /* Set only by easycap_dqbuf() to trail frame_fill.*/ 405int frame_lock; /* Flag set to 1 by DQBUF and cleared by QBUF */ 406/*---------------------------------------------------------------------------*/ 407/* 408 * IMAGE PROPERTIES 409 */ 410/*---------------------------------------------------------------------------*/ 411__u32 pixelformat; 412int width; 413int height; 414int bytesperpixel; 415bool byteswaporder; 416bool decimatepixel; 417bool offerfields; 418int frame_buffer_used; 419int frame_buffer_many; 420int videofieldamount; 421 422int brightness; 423int contrast; 424int saturation; 425int hue; 426 427int allocation_video_urb; 428int allocation_video_page; 429int allocation_video_struct; 430int registered_video; 431/*---------------------------------------------------------------------------*/ 432/* 433 * SOUND PROPERTIES 434 */ 435/*---------------------------------------------------------------------------*/ 436int audio_interface; 437int audio_altsetting_on; 438int audio_altsetting_off; 439int audio_endpointnumber; 440int audio_isoc_maxframesize; 441int audio_isoc_buffer_size; 442int audio_isoc_framesperdesc; 443 444int audio_isoc_streaming; 445int audio_idle; 446int audio_eof; 447int volume; 448int mute; 449 450struct data_buffer audio_isoc_buffer[AUDIO_ISOC_BUFFER_MANY]; 451 452struct list_head urb_audio_head; 453struct list_head *purb_audio_head; 454/*---------------------------------------------------------------------------*/ 455/* 456 * BUFFER INDICATORS 457 */ 458/*---------------------------------------------------------------------------*/ 459int audio_fill; /* Audio buffer being filled by easysnd_complete(). */ 460 /* Bumped only by easysnd_complete(). */ 461int 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 470int audio_buffer_many; 471 472int allocation_audio_urb; 473int allocation_audio_page; 474int allocation_audio_struct; 475int registered_audio; 476 477long long int audio_sample; 478long long int audio_niveau; 479long long int audio_square; 480 481struct data_buffer audio_buffer[]; 482}; 483/*---------------------------------------------------------------------------*/ 484/* 485 * VIDEO FUNCTION PROTOTYPES 486 */ 487/*---------------------------------------------------------------------------*/ 488void easycap_complete(struct urb *); 489int easycap_open(struct inode *, struct file *); 490int easycap_release(struct inode *, struct file *); 491long easycap_ioctl_noinode(struct file *, unsigned int, \ 492 unsigned long); 493int easycap_ioctl(struct inode *, struct file *, unsigned int, \ 494 unsigned long); 495/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 496#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 497int easycap_open_noinode(struct file *); 498int easycap_release_noinode(struct file *); 499int videodev_release(struct video_device *); 500#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 501/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 502 503unsigned int easycap_poll(struct file *, poll_table *); 504int easycap_mmap(struct file *, struct vm_area_struct *); 505int easycap_usb_probe(struct usb_interface *, \ 506 const struct usb_device_id *); 507void easycap_usb_disconnect(struct usb_interface *); 508void easycap_delete(struct kref *); 509 510void easycap_vma_open(struct vm_area_struct *); 511void easycap_vma_close(struct vm_area_struct *); 512int easycap_vma_fault(struct vm_area_struct *, struct vm_fault *); 513int easycap_dqbuf(struct easycap *, int); 514int submit_video_urbs(struct easycap *); 515int kill_video_urbs(struct easycap *); 516int field2frame(struct easycap *); 517int redaub(struct easycap *, void *, void *, \ 518 int, int, __u8, __u8, bool); 519void easycap_testcard(struct easycap *, int); 520int fillin_formats(void); 521int reset(struct easycap *); 522int newinput(struct easycap *, int); 523int adjust_standard(struct easycap *, v4l2_std_id); 524int adjust_format(struct easycap *, __u32, __u32, __u32, \ 525 int, bool); 526int adjust_brightness(struct easycap *, int); 527int adjust_contrast(struct easycap *, int); 528int adjust_saturation(struct easycap *, int); 529int adjust_hue(struct easycap *, int); 530int adjust_volume(struct easycap *, int); 531/*---------------------------------------------------------------------------*/ 532/* 533 * AUDIO FUNCTION PROTOTYPES 534 */ 535/*---------------------------------------------------------------------------*/ 536void easysnd_complete(struct urb *); 537ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *); 538int easysnd_open(struct inode *, struct file *); 539int easysnd_release(struct inode *, struct file *); 540long easysnd_ioctl_noinode(struct file *, unsigned int, \ 541 unsigned long); 542int easysnd_ioctl(struct inode *, struct file *, unsigned int, \ 543 unsigned long); 544unsigned int easysnd_poll(struct file *, poll_table *); 545void easysnd_delete(struct kref *); 546int submit_audio_urbs(struct easycap *); 547int kill_audio_urbs(struct easycap *); 548void easysnd_testtone(struct easycap *, int); 549int audio_setup(struct easycap *); 550/*---------------------------------------------------------------------------*/ 551/* 552 * LOW-LEVEL FUNCTION PROTOTYPES 553 */ 554/*---------------------------------------------------------------------------*/ 555int audio_gainget(struct usb_device *); 556int audio_gainset(struct usb_device *, __s8); 557 558int set_interface(struct usb_device *, __u16); 559int wakeup_device(struct usb_device *); 560int confirm_resolution(struct usb_device *); 561int confirm_stream(struct usb_device *); 562 563int setup_stk(struct usb_device *, bool); 564int setup_saa(struct usb_device *, bool); 565int setup_vt(struct usb_device *); 566int check_stk(struct usb_device *, bool); 567int check_saa(struct usb_device *, bool); 568int ready_saa(struct usb_device *); 569int merit_saa(struct usb_device *); 570int check_vt(struct usb_device *); 571int select_input(struct usb_device *, int, int); 572int set_resolution(struct usb_device *, \ 573 __u16, __u16, __u16, __u16); 574 575int read_saa(struct usb_device *, __u16); 576int read_stk(struct usb_device *, __u32); 577int write_saa(struct usb_device *, __u16, __u16); 578int wait_i2c(struct usb_device *); 579int write_000(struct usb_device *, __u16, __u16); 580int start_100(struct usb_device *); 581int stop_100(struct usb_device *); 582int write_300(struct usb_device *); 583int read_vt(struct usb_device *, __u16); 584int write_vt(struct usb_device *, __u16, __u16); 585int regset(struct usb_device *, __u16, __u16); 586int regget(struct usb_device *, __u16, void *); 587int isdongle(struct easycap *); 588/*---------------------------------------------------------------------------*/ 589struct signed_div_result { 590long long int quotient; 591unsigned 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*/