blob: 8ebf96f8a24235b49e42f507c3842acd48b82176 [file] [log] [blame]
R.M. Thomas702422b2010-06-18 12:29:49 -07001/*****************************************************************************
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
Mike Thomas268dfed2010-11-07 20:11:36 +000036 * EASYCAP_NEEDS_UNLOCKED_IOCTL
R.M. Thomas702422b2010-06-18 12:29:49 -070037 *
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
R.M. Thomas702422b2010-06-18 12:29:49 -070046/*---------------------------------------------------------------------------*/
47/*
Mike Thomasf36bc372010-11-07 20:00:35 +000048 * THESE ARE NORMALLY DEFINED
49 */
50/*---------------------------------------------------------------------------*/
51#define PATIENCE 500
52#undef PREFER_NTSC
53#define PERSEVERE
54/*---------------------------------------------------------------------------*/
55/*
R.M. Thomas702422b2010-06-18 12:29:49 -070056 * THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED:
57 */
58/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -070059#undef EASYCAP_TESTCARD
60#undef EASYCAP_TESTTONE
R.M. Thomas702422b2010-06-18 12:29:49 -070061#undef NOREADBACK
62#undef AUDIOTIME
63/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -070064#include <linux/kernel.h>
65#include <linux/errno.h>
66#include <linux/init.h>
67#include <linux/slab.h>
Randy Dunlap72f9fc72010-11-22 12:12:37 -080068#include <linux/smp_lock.h>
R.M. Thomas702422b2010-06-18 12:29:49 -070069#include <linux/module.h>
70#include <linux/kref.h>
R.M. Thomas702422b2010-06-18 12:29:49 -070071#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)
R.M. Thomas702422b2010-06-18 12:29:49 -070085#include <media/v4l2-dev.h>
R.M. Thomas702422b2010-06-18 12:29:49 -070086#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/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
R.M. Thomas702422b2010-06-18 12:29:49 -070091#include <linux/videodev2.h>
R.M. Thomas702422b2010-06-18 12:29:49 -070092#include <linux/soundcard.h>
R.M. Thomas702422b2010-06-18 12:29:49 -070093#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)
R.M. Thomas702422b2010-06-18 12:29:49 -0700103/*---------------------------------------------------------------------------*/
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
Mike Thomasce36ced2010-11-07 19:56:40 +0000116#define EASYCAP_DRIVER_VERSION "0.8.41"
R.M. Thomas702422b2010-06-18 12:29:49 -0700117#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
118
119#define USB_SKEL_MINOR_BASE 192
Mike Thomase68703c2010-11-07 19:58:55 +0000120#define DONGLE_MANY 8
Mike Thomasf36bc372010-11-07 20:00:35 +0000121#define INPUT_MANY 6
R.M. Thomas702422b2010-06-18 12:29:49 -0700122/*---------------------------------------------------------------------------*/
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
Mike Thomasf36bc372010-11-07 20:00:35 +0000145#define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY
Mike Thomas849322a2010-11-07 20:03:50 +0000146#define VIDEO_LOST_TOLERATE 50
R.M. Thomas702422b2010-06-18 12:29:49 -0700147/*---------------------------------------------------------------------------*/
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/*
Mike Thomas3d423e92010-07-11 10:51:13 +0100172 * 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
Mike Thomas40b8d502010-11-07 20:02:15 +0000193#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
Mike Thomas3d423e92010-07-11 10:51:13 +0100204/*---------------------------------------------------------------------------*/
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,
Mike Thomas3d423e92010-07-11 10:51:13 +0100231INTERLACE_MANY
232};
233#define SETTINGS_MANY (STANDARD_MANY * \
234 RESOLUTION_MANY * \
235 2 * \
236 PIXELFORMAT_MANY * \
237 INTERLACE_MANY)
238/*---------------------------------------------------------------------------*/
239/*
R.M. Thomas702422b2010-06-18 12:29:49 -0700240 * STRUCTURE DEFINITIONS
241 */
242/*---------------------------------------------------------------------------*/
Mike Thomasae59dad2010-11-07 20:09:19 +0000243struct easycap_dongle {
244struct easycap *peasycap;
245struct mutex mutex_video;
246struct mutex mutex_audio;
247};
248/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -0700249struct data_buffer {
250struct list_head list_head;
251void *pgo;
252void *pto;
253__u16 kount;
Mike Thomasf36bc372010-11-07 20:00:35 +0000254__u16 input;
R.M. Thomas702422b2010-06-18 12:29:49 -0700255};
256/*---------------------------------------------------------------------------*/
257struct data_urb {
258struct list_head list_head;
259struct urb *purb;
260int isbuf;
261int length;
262};
263/*---------------------------------------------------------------------------*/
Mike Thomas3d423e92010-07-11 10:51:13 +0100264struct 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};
Mike Thomasf36bc372010-11-07 20:00:35 +0000273struct 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};
Mike Thomas3d423e92010-07-11 10:51:13 +0100289/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -0700290/*
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 {
Mike Thomas268dfed2010-11-07 20:11:36 +0000297#define TELLTALE "expectedstring"
298char telltale[16];
Mike Thomase68703c2010-11-07 19:58:55 +0000299int 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/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
Mike Thomasf36bc372010-11-07 20:00:35 +0000309int status;
Mike Thomas3d423e92010-07-11 10:51:13 +0100310unsigned 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
R.M. Thomas702422b2010-06-18 12:29:49 -0700319int ilk;
320bool microphone;
321
R.M. Thomas702422b2010-06-18 12:29:49 -0700322struct usb_device *pusb_device;
323struct usb_interface *pusb_interface;
324
325struct kref kref;
326
R.M. Thomas702422b2010-06-18 12:29:49 -0700327int 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;
Mike Thomasf36bc372010-11-07 20:00:35 +0000337struct inputset inputset[INPUT_MANY];
R.M. Thomas702422b2010-06-18 12:29:49 -0700338
Mike Thomasf36bc372010-11-07 20:00:35 +0000339bool ntsc;
R.M. Thomas702422b2010-06-18 12:29:49 -0700340int fps;
341int usec;
342int tolerate;
Mike Thomas40b8d502010-11-07 20:02:15 +0000343int skip;
344int skipped;
Mike Thomas849322a2010-11-07 20:03:50 +0000345int lost[INPUT_MANY];
R.M. Thomas702422b2010-06-18 12:29:49 -0700346int merit[180];
347
348struct timeval timeval0;
349struct timeval timeval1;
350struct timeval timeval2;
Mike Thomase68703c2010-11-07 19:58:55 +0000351struct timeval timeval3;
352struct timeval timeval6;
R.M. Thomas702422b2010-06-18 12:29:49 -0700353struct timeval timeval7;
Mike Thomase68703c2010-11-07 19:58:55 +0000354struct timeval timeval8;
R.M. Thomas702422b2010-06-18 12:29:49 -0700355long 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
R.M. Thomas702422b2010-06-18 12:29:49 -0700371struct 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
Mike Thomase68703c2010-11-07 19:58:55 +0000380__u8 cache[8];
381__u8 *pcache;
382int video_mt;
383int audio_mt;
384long long audio_bytes;
385__u32 isequence;
386
R.M. Thomas702422b2010-06-18 12:29:49 -0700387int 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;
R.M. Thomas702422b2010-06-18 12:29:49 -0700412int 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/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -0700484/*
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 *);
Mike Thomasae59dad2010-11-07 20:09:19 +0000491long easycap_ioctl_noinode(struct file *, unsigned int, \
492 unsigned long);
493int easycap_ioctl(struct inode *, struct file *, unsigned int, \
494 unsigned long);
R.M. Thomas702422b2010-06-18 12:29:49 -0700495/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
496#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
497int easycap_open_noinode(struct file *);
498int easycap_release_noinode(struct file *);
R.M. Thomas702422b2010-06-18 12:29:49 -0700499int 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);
R.M. Thomas702422b2010-06-18 12:29:49 -0700519void easycap_testcard(struct easycap *, int);
R.M. Thomas702422b2010-06-18 12:29:49 -0700520int fillin_formats(void);
Mike Thomasf36bc372010-11-07 20:00:35 +0000521int reset(struct easycap *);
522int newinput(struct easycap *, int);
R.M. Thomas702422b2010-06-18 12:29:49 -0700523int 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 *);
Mike Thomasae59dad2010-11-07 20:09:19 +0000540long easysnd_ioctl_noinode(struct file *, unsigned int, \
541 unsigned long);
542int easysnd_ioctl(struct inode *, struct file *, unsigned int, \
543 unsigned long);
R.M. Thomas702422b2010-06-18 12:29:49 -0700544unsigned 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
Mike Thomasf36bc372010-11-07 20:00:35 +0000563int setup_stk(struct usb_device *, bool);
564int setup_saa(struct usb_device *, bool);
R.M. Thomas702422b2010-06-18 12:29:49 -0700565int setup_vt(struct usb_device *);
Mike Thomasf36bc372010-11-07 20:00:35 +0000566int check_stk(struct usb_device *, bool);
567int check_saa(struct usb_device *, bool);
R.M. Thomas702422b2010-06-18 12:29:49 -0700568int 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);
R.M. Thomas702422b2010-06-18 12:29:49 -0700585int regset(struct usb_device *, __u16, __u16);
586int regget(struct usb_device *, __u16, void *);
Mike Thomase68703c2010-11-07 19:58:55 +0000587int isdongle(struct easycap *);
R.M. Thomas702422b2010-06-18 12:29:49 -0700588/*---------------------------------------------------------------------------*/
589struct signed_div_result {
590long long int quotient;
591unsigned long long int remainder;
592} signed_div(long long int, long long int);
593/*---------------------------------------------------------------------------*/
594/*
R.M. Thomas702422b2010-06-18 12:29:49 -0700595 * 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/*---------------------------------------------------------------------------*/
Mike Thomase68703c2010-11-07 19:58:55 +0000615/*
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/*---------------------------------------------------------------------------*/
R.M. Thomas702422b2010-06-18 12:29:49 -0700622#define SAY(format, args...) do { \
Mike Thomase68703c2010-11-07 19:58:55 +0000623 printk(KERN_DEBUG "easycap:: %s: " \
624 format, __func__, ##args); \
R.M. Thomas702422b2010-06-18 12:29:49 -0700625} while (0)
Mike Thomase68703c2010-11-07 19:58:55 +0000626#define SAM(format, args...) do { \
627 printk(KERN_DEBUG "easycap::%i%s: " \
628 format, peasycap->isdongle, __func__, ##args);\
629} while (0)
R.M. Thomas702422b2010-06-18 12:29:49 -0700630
631#if defined(EASYCAP_DEBUG)
632#define JOT(n, format, args...) do { \
Randy Dunlap62af33e2010-11-11 10:44:22 -0800633 if (n <= easycap_debug) { \
Mike Thomase68703c2010-11-07 19:58:55 +0000634 printk(KERN_DEBUG "easycap:: %s: " \
635 format, __func__, ##args);\
R.M. Thomas702422b2010-06-18 12:29:49 -0700636 } \
637} while (0)
Mike Thomase68703c2010-11-07 19:58:55 +0000638#define JOM(n, format, args...) do { \
Randy Dunlap62af33e2010-11-11 10:44:22 -0800639 if (n <= easycap_debug) { \
Mike Thomase68703c2010-11-07 19:58:55 +0000640 printk(KERN_DEBUG "easycap::%i%s: " \
641 format, peasycap->isdongle, __func__, ##args);\
642 } \
643} while (0)
644
R.M. Thomas702422b2010-06-18 12:29:49 -0700645#else
646#define JOT(n, format, args...) do {} while (0)
Mike Thomase68703c2010-11-07 19:58:55 +0000647#define JOM(n, format, args...) do {} while (0)
R.M. Thomas702422b2010-06-18 12:29:49 -0700648#endif /*EASYCAP_DEBUG*/
649
R.M. Thomas702422b2010-06-18 12:29:49 -0700650#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*/