1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#ifndef __EASYCAP_H__
39#define __EASYCAP_H__
40
41
42
43
44
45
46#define PATIENCE 500
47#define PERSEVERE
48
49
50
51
52
53#undef EASYCAP_TESTCARD
54
55#include <linux/kernel.h>
56#include <linux/errno.h>
57#include <linux/init.h>
58#include <linux/slab.h>
59#include <linux/module.h>
60#include <linux/kref.h>
61#include <linux/usb.h>
62#include <linux/uaccess.h>
63
64#include <linux/i2c.h>
65#include <linux/workqueue.h>
66#include <linux/poll.h>
67#include <linux/mm.h>
68#include <linux/fs.h>
69#include <linux/delay.h>
70#include <linux/types.h>
71
72#include <linux/vmalloc.h>
73#include <linux/sound.h>
74#include <sound/core.h>
75#include <sound/pcm.h>
76#include <sound/pcm_params.h>
77#include <sound/info.h>
78#include <sound/initval.h>
79#include <sound/control.h>
80#include <media/v4l2-dev.h>
81#include <media/v4l2-device.h>
82#include <linux/videodev2.h>
83#include <linux/soundcard.h>
84
85
86
87
88
89
90
91
92
93
94
95#define USB_EASYCAP_VENDOR_ID 0x05e1
96#define USB_EASYCAP_PRODUCT_ID 0x0408
97
98#define EASYCAP_DRIVER_VERSION "0.9.01"
99#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
100
101#define DONGLE_MANY 8
102#define INPUT_MANY 6
103
104
105
106
107
108#define SAA_0A_DEFAULT 0x7F
109#define SAA_0B_DEFAULT 0x3F
110#define SAA_0C_DEFAULT 0x2F
111#define SAA_0D_DEFAULT 0x00
112
113
114
115
116
117
118
119#define VIDEO_ISOC_BUFFER_MANY 16
120#define VIDEO_ISOC_ORDER 3
121#define VIDEO_ISOC_FRAMESPERDESC ((unsigned int) 1 << VIDEO_ISOC_ORDER)
122#define USB_2_0_MAXPACKETSIZE 3072
123#if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE)
124#error video_isoc_buffer[.] will not be big enough
125#endif
126#define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY
127#define VIDEO_LOST_TOLERATE 50
128
129
130
131
132
133#define FIELD_BUFFER_SIZE (203 * PAGE_SIZE)
134#define FRAME_BUFFER_SIZE (405 * PAGE_SIZE)
135#define FIELD_BUFFER_MANY 4
136#define FRAME_BUFFER_MANY 6
137
138
139
140
141
142#define AUDIO_ISOC_BUFFER_MANY 16
143#define AUDIO_ISOC_ORDER 1
144#define AUDIO_ISOC_FRAMESPERDESC 32
145#define AUDIO_ISOC_BUFFER_SIZE (PAGE_SIZE << AUDIO_ISOC_ORDER)
146
147
148
149
150
151#define AUDIO_FRAGMENT_MANY 32
152#define PAGES_PER_AUDIO_FRAGMENT 4
153
154
155
156
157
158
159
160
161
162
163
164
165
166#define PAL_BGHIN 0
167#define PAL_Nc 2
168#define SECAM 4
169#define NTSC_N 6
170#define NTSC_N_443 8
171#define NTSC_M 1
172#define NTSC_443 3
173#define NTSC_M_JP 5
174#define PAL_60 7
175#define PAL_M 9
176#define PAL_BGHIN_SLOW 10
177#define PAL_Nc_SLOW 12
178#define SECAM_SLOW 14
179#define NTSC_N_SLOW 16
180#define NTSC_N_443_SLOW 18
181#define NTSC_M_SLOW 11
182#define NTSC_443_SLOW 13
183#define NTSC_M_JP_SLOW 15
184#define PAL_60_SLOW 17
185#define PAL_M_SLOW 19
186#define STANDARD_MANY 20
187
188
189
190
191
192enum {
193 AT_720x576,
194 AT_704x576,
195 AT_640x480,
196 AT_720x480,
197 AT_360x288,
198 AT_320x240,
199 AT_360x240,
200 RESOLUTION_MANY
201};
202enum {
203 FMT_UYVY,
204 FMT_YUY2,
205 FMT_RGB24,
206 FMT_RGB32,
207 FMT_BGR24,
208 FMT_BGR32,
209 PIXELFORMAT_MANY
210};
211enum {
212 FIELD_NONE,
213 FIELD_INTERLACED,
214 INTERLACE_MANY
215};
216#define SETTINGS_MANY (STANDARD_MANY * \
217 RESOLUTION_MANY * \
218 2 * \
219 PIXELFORMAT_MANY * \
220 INTERLACE_MANY)
221
222
223
224
225
226struct easycap_dongle {
227 struct easycap *peasycap;
228 struct mutex mutex_video;
229 struct mutex mutex_audio;
230};
231
232struct data_buffer {
233 struct list_head list_head;
234 void *pgo;
235 void *pto;
236 u16 kount;
237 u16 input;
238};
239
240struct data_urb {
241 struct list_head list_head;
242 struct urb *purb;
243 int isbuf;
244 int length;
245};
246
247struct easycap_standard {
248 u16 mask;
249struct v4l2_standard v4l2_standard;
250};
251struct easycap_format {
252 u16 mask;
253 char name[128];
254struct v4l2_format v4l2_format;
255};
256struct inputset {
257 int input;
258 int input_ok;
259 int standard_offset;
260 int standard_offset_ok;
261 int format_offset;
262 int format_offset_ok;
263 int brightness;
264 int brightness_ok;
265 int contrast;
266 int contrast_ok;
267 int saturation;
268 int saturation_ok;
269 int hue;
270 int hue_ok;
271};
272
273
274
275
276
277
278
279struct easycap {
280 int isdongle;
281 int minor;
282
283 struct video_device video_device;
284 struct v4l2_device v4l2_device;
285
286 int status;
287 unsigned int audio_pages_per_fragment;
288 unsigned int audio_bytes_per_fragment;
289 unsigned int audio_buffer_page_many;
290
291#define UPSAMPLE
292#ifdef UPSAMPLE
293 s16 oldaudio;
294#endif
295
296 int ilk;
297 bool microphone;
298
299 struct usb_device *pusb_device;
300 struct usb_interface *pusb_interface;
301
302 struct kref kref;
303
304 int queued[FRAME_BUFFER_MANY];
305 int done[FRAME_BUFFER_MANY];
306
307 wait_queue_head_t wq_video;
308 wait_queue_head_t wq_audio;
309 wait_queue_head_t wq_trigger;
310
311 int input;
312 int polled;
313 int standard_offset;
314 int format_offset;
315 struct inputset inputset[INPUT_MANY];
316
317 bool ntsc;
318 int fps;
319 int usec;
320 int tolerate;
321 int skip;
322 int skipped;
323 int lost[INPUT_MANY];
324 int merit[180];
325
326 int video_interface;
327 int video_altsetting_on;
328 int video_altsetting_off;
329 int video_endpointnumber;
330 int video_isoc_maxframesize;
331 int video_isoc_buffer_size;
332 int video_isoc_framesperdesc;
333
334 int video_isoc_streaming;
335 int video_isoc_sequence;
336 int video_idle;
337 int video_eof;
338 int video_junk;
339
340 struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY];
341 struct data_buffer field_buffer[FIELD_BUFFER_MANY]
342 [(FIELD_BUFFER_SIZE/PAGE_SIZE)];
343 struct data_buffer frame_buffer[FRAME_BUFFER_MANY]
344 [(FRAME_BUFFER_SIZE/PAGE_SIZE)];
345
346 struct list_head urb_video_head;
347 struct list_head *purb_video_head;
348
349 u8 cache[8];
350 u8 *pcache;
351 int video_mt;
352 int audio_mt;
353 u32 isequence;
354
355 int vma_many;
356
357
358
359
360
361 int field_fill;
362
363 int field_page;
364
365 int field_read;
366
367 int frame_fill;
368
369
370 int frame_read;
371
372 int frame_lock;
373
374
375
376
377
378 u32 pixelformat;
379 int width;
380 int height;
381 int bytesperpixel;
382 bool byteswaporder;
383 bool decimatepixel;
384 bool offerfields;
385 int frame_buffer_used;
386 int frame_buffer_many;
387 int videofieldamount;
388
389 int brightness;
390 int contrast;
391 int saturation;
392 int hue;
393
394 int allocation_video_urb;
395 int allocation_video_page;
396 int allocation_video_struct;
397 int registered_video;
398
399
400
401
402
403 struct snd_pcm_hardware alsa_hardware;
404 struct snd_card *psnd_card;
405 struct snd_pcm *psnd_pcm;
406 struct snd_pcm_substream *psubstream;
407 int dma_fill;
408 int dma_next;
409 int dma_read;
410
411
412
413
414
415 int audio_interface;
416 int audio_altsetting_on;
417 int audio_altsetting_off;
418 int audio_endpointnumber;
419 int audio_isoc_maxframesize;
420 int audio_isoc_buffer_size;
421 int audio_isoc_framesperdesc;
422
423 int audio_isoc_streaming;
424 int audio_idle;
425 int audio_eof;
426 int volume;
427 int mute;
428 s8 gain;
429
430 struct data_buffer audio_isoc_buffer[AUDIO_ISOC_BUFFER_MANY];
431
432 struct list_head urb_audio_head;
433 struct list_head *purb_audio_head;
434
435
436
437
438
439 int audio_fill;
440
441 int audio_read;
442
443
444
445
446
447
448
449 int allocation_audio_urb;
450 int allocation_audio_page;
451 int allocation_audio_struct;
452 int registered_audio;
453
454 long long int audio_sample;
455 long long int audio_niveau;
456 long long int audio_square;
457
458 struct data_buffer audio_buffer[];
459};
460
461
462
463
464
465int easycap_newinput(struct easycap *, int);
466void easycap_testcard(struct easycap *, int);
467int easycap_isdongle(struct easycap *);
468
469long easycap_unlocked_ioctl(struct file *, unsigned int, unsigned long);
470
471int easycap_video_dqbuf(struct easycap *, int);
472int easycap_video_submit_urbs(struct easycap *);
473int easycap_video_kill_urbs(struct easycap *);
474int easycap_video_fillin_formats(void);
475
476int adjust_standard(struct easycap *, v4l2_std_id);
477int adjust_format(struct easycap *, u32, u32, u32, int, bool);
478int adjust_brightness(struct easycap *, int);
479int adjust_contrast(struct easycap *, int);
480int adjust_saturation(struct easycap *, int);
481int adjust_hue(struct easycap *, int);
482
483
484
485
486
487int easycap_alsa_probe(struct easycap *);
488int easycap_audio_kill_urbs(struct easycap *);
489void easycap_alsa_complete(struct urb *);
490
491
492
493
494
495int easycap_audio_gainset(struct usb_device *, s8);
496int easycap_audio_setup(struct easycap *);
497
498int easycap_wakeup_device(struct usb_device *);
499
500int setup_stk(struct usb_device *, bool);
501int setup_saa(struct usb_device *, bool);
502int ready_saa(struct usb_device *);
503int merit_saa(struct usb_device *);
504int check_vt(struct usb_device *);
505int select_input(struct usb_device *, int, int);
506int set_resolution(struct usb_device *, u16, u16, u16, u16);
507
508int read_saa(struct usb_device *, u16);
509int write_saa(struct usb_device *, u16, u16);
510int start_100(struct usb_device *);
511int stop_100(struct usb_device *);
512
513
514
515
516
517
518
519
520
521
522
523const char *strerror(int err);
524
525#define SAY(format, args...) do { \
526 printk(KERN_DEBUG "easycap:: %s: " \
527 format, __func__, ##args); \
528} while (0)
529#define SAM(format, args...) do { \
530 printk(KERN_DEBUG "easycap::%i%s: " \
531 format, peasycap->isdongle, __func__, ##args);\
532} while (0)
533
534#ifdef CONFIG_EASYCAP_DEBUG
535extern int easycap_debug;
536#define JOT(n, format, args...) do { \
537 if (n <= easycap_debug) { \
538 printk(KERN_DEBUG "easycap:: %s: " \
539 format, __func__, ##args);\
540 } \
541} while (0)
542#define JOM(n, format, args...) do { \
543 if (n <= easycap_debug) { \
544 printk(KERN_DEBUG "easycap::%i%s: " \
545 format, peasycap->isdongle, __func__, ##args);\
546 } \
547} while (0)
548
549#else
550#define JOT(n, format, args...) do {} while (0)
551#define JOM(n, format, args...) do {} while (0)
552#endif
553
554
555
556
557
558
559
560
561extern bool easycap_readback;
562extern const struct easycap_standard easycap_standard[];
563extern struct easycap_format easycap_format[];
564extern struct v4l2_queryctrl easycap_control[];
565extern struct easycap_dongle easycapdc60_dongle[];
566
567#endif
568