1
2
3
4
5
6
7
8
9
10
11
12#include <linux/usb.h>
13#include <linux/i2c.h>
14#include <linux/mutex.h>
15#include <linux/workqueue.h>
16#include <linux/videodev2.h>
17
18#include <media/v4l2-device.h>
19#include <media/v4l2-ctrls.h>
20#include <media/ir-kbd-i2c.h>
21
22#define HDPVR_MAX 8
23#define HDPVR_I2C_MAX_SIZE 128
24
25
26#define HD_PVR_VENDOR_ID 0x2040
27#define HD_PVR_PRODUCT_ID 0x4900
28#define HD_PVR_PRODUCT_ID1 0x4901
29#define HD_PVR_PRODUCT_ID2 0x4902
30#define HD_PVR_PRODUCT_ID4 0x4903
31#define HD_PVR_PRODUCT_ID3 0x4982
32
33#define UNSET (-1U)
34
35#define NUM_BUFFERS 64
36
37#define HDPVR_FIRMWARE_VERSION 0x08
38#define HDPVR_FIRMWARE_VERSION_AC3 0x0d
39#define HDPVR_FIRMWARE_VERSION_0X12 0x12
40#define HDPVR_FIRMWARE_VERSION_0X15 0x15
41#define HDPVR_FIRMWARE_VERSION_0X1E 0x1e
42
43
44
45extern int hdpvr_debug;
46
47#define MSG_INFO 1
48#define MSG_BUFFER 2
49
50struct hdpvr_options {
51 u8 video_std;
52 u8 video_input;
53 u8 audio_input;
54 u8 bitrate;
55 u8 peak_bitrate;
56 u8 bitrate_mode;
57 u8 gop_mode;
58 enum v4l2_mpeg_audio_encoding audio_codec;
59 u8 brightness;
60 u8 contrast;
61 u8 hue;
62 u8 saturation;
63 u8 sharpness;
64};
65
66
67struct hdpvr_device {
68
69 struct video_device *video_dev;
70
71 struct v4l2_ctrl_handler hdl;
72
73 struct usb_device *udev;
74
75 struct v4l2_device v4l2_dev;
76 struct {
77 struct v4l2_ctrl *video_mode;
78 struct v4l2_ctrl *video_bitrate;
79 struct v4l2_ctrl *video_bitrate_peak;
80 };
81
82 uint width, height;
83
84
85 size_t bulk_in_size;
86
87 __u8 bulk_in_endpointAddr;
88
89
90 __u8 status;
91
92
93 struct hdpvr_options options;
94 v4l2_std_id cur_std;
95 struct v4l2_dv_timings cur_dv_timings;
96
97 uint flags;
98
99
100 struct mutex io_mutex;
101
102 struct list_head free_buff_list;
103
104 struct list_head rec_buff_list;
105
106 wait_queue_head_t wait_buffer;
107
108 wait_queue_head_t wait_data;
109
110 struct workqueue_struct *workqueue;
111
112 struct work_struct worker;
113
114 struct v4l2_fh *owner;
115
116
117 struct i2c_adapter i2c_adapter;
118
119 struct mutex i2c_mutex;
120
121 char i2c_buf[HDPVR_I2C_MAX_SIZE];
122
123
124 struct IR_i2c_init_data ir_i2c_init_data;
125
126
127 struct mutex usbc_mutex;
128 u8 *usbc_buf;
129 u8 fw_ver;
130};
131
132static inline struct hdpvr_device *to_hdpvr_dev(struct v4l2_device *v4l2_dev)
133{
134 return container_of(v4l2_dev, struct hdpvr_device, v4l2_dev);
135}
136
137
138
139struct hdpvr_buffer {
140 struct list_head buff_list;
141
142 struct urb *urb;
143
144 struct hdpvr_device *dev;
145
146 uint pos;
147
148 __u8 status;
149};
150
151
152
153struct hdpvr_video_info {
154 u16 width;
155 u16 height;
156 u8 fps;
157 bool valid;
158};
159
160enum {
161 STATUS_UNINITIALIZED = 0,
162 STATUS_IDLE,
163 STATUS_STARTING,
164 STATUS_SHUTTING_DOWN,
165 STATUS_STREAMING,
166 STATUS_ERROR,
167 STATUS_DISCONNECTED,
168};
169
170enum {
171 HDPVR_FLAG_AC3_CAP = 1,
172};
173
174enum {
175 BUFSTAT_UNINITIALIZED = 0,
176 BUFSTAT_AVAILABLE,
177 BUFSTAT_INPROGRESS,
178 BUFSTAT_READY,
179};
180
181#define CTRL_START_STREAMING_VALUE 0x0700
182#define CTRL_STOP_STREAMING_VALUE 0x0800
183#define CTRL_BITRATE_VALUE 0x1000
184#define CTRL_BITRATE_MODE_VALUE 0x1200
185#define CTRL_GOP_MODE_VALUE 0x1300
186#define CTRL_VIDEO_INPUT_VALUE 0x1500
187#define CTRL_VIDEO_STD_TYPE 0x1700
188#define CTRL_AUDIO_INPUT_VALUE 0x2500
189#define CTRL_BRIGHTNESS 0x2900
190#define CTRL_CONTRAST 0x2a00
191#define CTRL_HUE 0x2b00
192#define CTRL_SATURATION 0x2c00
193#define CTRL_SHARPNESS 0x2d00
194#define CTRL_LOW_PASS_FILTER_VALUE 0x3100
195
196#define CTRL_DEFAULT_INDEX 0x0003
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261enum hdpvr_video_std {
262 HDPVR_60HZ = 0,
263 HDPVR_50HZ,
264};
265
266enum hdpvr_video_input {
267 HDPVR_COMPONENT = 0,
268 HDPVR_SVIDEO,
269 HDPVR_COMPOSITE,
270 HDPVR_VIDEO_INPUTS
271};
272
273enum hdpvr_audio_inputs {
274 HDPVR_RCA_BACK = 0,
275 HDPVR_RCA_FRONT,
276 HDPVR_SPDIF,
277 HDPVR_AUDIO_INPUTS
278};
279
280enum hdpvr_bitrate_mode {
281 HDPVR_CONSTANT = 1,
282 HDPVR_VARIABLE_PEAK,
283 HDPVR_VARIABLE_AVERAGE,
284};
285
286enum hdpvr_gop_mode {
287 HDPVR_ADVANCED_IDR_GOP = 0,
288 HDPVR_SIMPLE_IDR_GOP,
289 HDPVR_ADVANCED_NOIDR_GOP,
290 HDPVR_SIMPLE_NOIDR_GOP,
291};
292
293void hdpvr_delete(struct hdpvr_device *dev);
294
295
296
297int hdpvr_set_options(struct hdpvr_device *dev);
298
299int hdpvr_set_bitrate(struct hdpvr_device *dev);
300
301int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
302 enum v4l2_mpeg_audio_encoding codec);
303
304int hdpvr_config_call(struct hdpvr_device *dev, uint value,
305 unsigned char valbuf);
306
307int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vid_info);
308
309
310
311int get_input_lines_info(struct hdpvr_device *dev);
312
313
314
315
316int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
317 int devnumber);
318
319int hdpvr_cancel_queue(struct hdpvr_device *dev);
320
321
322
323int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
324
325struct i2c_client *hdpvr_register_ir_rx_i2c(struct hdpvr_device *dev);
326struct i2c_client *hdpvr_register_ir_tx_i2c(struct hdpvr_device *dev);
327
328
329
330int hdpvr_free_buffers(struct hdpvr_device *dev);
331int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count);
332