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 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/usb.h>
39
40 #include <media/v4l2-device.h>
41 #include <media/v4l2-ctrls.h>
42 #include <media/videobuf2-v4l2.h>
43 #include <media/videobuf2-vmalloc.h>
44
45
46 #define USBTV_VIDEO_ENDP 0x81
47 #define USBTV_AUDIO_ENDP 0x83
48 #define USBTV_BASE 0xc000
49 #define USBTV_CONTROL_REG 11
50 #define USBTV_REQUEST_REG 12
51
52
53
54 #define USBTV_ISOC_TRANSFERS 16
55 #define USBTV_ISOC_PACKETS 8
56
57 #define USBTV_CHUNK_SIZE 256
58 #define USBTV_CHUNK 240
59
60 #define USBTV_AUDIO_URBSIZE 20480
61 #define USBTV_AUDIO_HDRSIZE 4
62 #define USBTV_AUDIO_BUFFER 65536
63
64
65 #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
66 == 0x88000000)
67 #define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
68 #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
69 #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
70
71 #define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL | V4L2_STD_SECAM)
72
73
74 struct usbtv_norm_params {
75 v4l2_std_id norm;
76 int cap_width, cap_height;
77 };
78
79
80 struct usbtv_buf {
81 struct vb2_v4l2_buffer vb;
82 struct list_head list;
83 };
84
85
86 struct usbtv {
87 struct device *dev;
88 struct usb_device *udev;
89
90
91 struct v4l2_device v4l2_dev;
92 struct v4l2_ctrl_handler ctrl;
93 struct video_device vdev;
94 struct vb2_queue vb2q;
95 struct mutex v4l2_lock;
96 struct mutex vb2q_lock;
97
98
99 spinlock_t buflock;
100 struct list_head bufs;
101
102
103
104 u32 frame_id;
105 int chunks_done;
106
107 enum {
108 USBTV_COMPOSITE_INPUT,
109 USBTV_SVIDEO_INPUT,
110 } input;
111 v4l2_std_id norm;
112 int width, height;
113 int n_chunks;
114 int iso_size;
115 int last_odd;
116 unsigned int sequence;
117 struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
118
119
120 struct snd_card *snd;
121 struct snd_pcm_substream *snd_substream;
122 atomic_t snd_stream;
123 struct work_struct snd_trigger;
124 struct urb *snd_bulk_urb;
125 size_t snd_buffer_pos;
126 size_t snd_period_pos;
127 };
128
129 int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size);
130
131 int usbtv_video_init(struct usbtv *usbtv);
132 void usbtv_video_free(struct usbtv *usbtv);
133
134 int usbtv_audio_init(struct usbtv *usbtv);
135 void usbtv_audio_free(struct usbtv *usbtv);
136 void usbtv_audio_suspend(struct usbtv *usbtv);
137 void usbtv_audio_resume(struct usbtv *usbtv);