blob: 17db74feb884da8c2e40d5a0fddd3770edaaff07 [file] [log] [blame]
Janne Grunau9aba42e2009-03-18 18:10:04 -03001/*
2 * Hauppage HD PVR USB driver
3 *
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
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#define HDPVR_MAJOR_VERSION 0
19#define HDPVR_MINOR_VERSION 2
20#define HDPVR_RELEASE 0
21#define HDPVR_VERSION \
22 KERNEL_VERSION(HDPVR_MAJOR_VERSION, HDPVR_MINOR_VERSION, HDPVR_RELEASE)
23
24#define HDPVR_MAX 8
25
26/* Define these values to match your devices */
27#define HD_PVR_VENDOR_ID 0x2040
28#define HD_PVR_PRODUCT_ID 0x4900
29#define HD_PVR_PRODUCT_ID1 0x4901
30#define HD_PVR_PRODUCT_ID2 0x4902
31
32#define UNSET (-1U)
33
34#define NUM_BUFFERS 64
35
36#define HDPVR_FIRMWARE_VERSION 0x8
37#define HDPVR_FIRMWARE_VERSION_AC3 0xd
38
39/* #define HDPVR_DEBUG */
40
41extern int hdpvr_debug;
42
43#define MSG_INFO 1
44#define MSG_BUFFER 2
45
46struct hdpvr_options {
47 u8 video_std;
48 u8 video_input;
49 u8 audio_input;
50 u8 bitrate; /* in 100kbps */
51 u8 peak_bitrate; /* in 100kbps */
52 u8 bitrate_mode;
53 u8 gop_mode;
54 enum v4l2_mpeg_audio_encoding audio_codec;
55 u8 brightness;
56 u8 contrast;
57 u8 hue;
58 u8 saturation;
59 u8 sharpness;
60};
61
62/* Structure to hold all of our device specific stuff */
63struct hdpvr_device {
64 /* the v4l device for this device */
65 struct video_device *video_dev;
66 /* the usb device for this device */
67 struct usb_device *udev;
68
69 /* the max packet size of the bulk endpoint */
70 size_t bulk_in_size;
71 /* the address of the bulk in endpoint */
72 __u8 bulk_in_endpointAddr;
73
74 /* holds the current device status */
75 __u8 status;
76 /* count the number of openers */
77 uint open_count;
78
79 /* holds the cureent set options */
80 struct hdpvr_options options;
81
82 uint flags;
83
84 /* synchronize I/O */
85 struct mutex io_mutex;
86 /* available buffers */
87 struct list_head free_buff_list;
88 /* in progress buffers */
89 struct list_head rec_buff_list;
90 /* waitqueue for buffers */
91 wait_queue_head_t wait_buffer;
92 /* waitqueue for data */
93 wait_queue_head_t wait_data;
94 /**/
95 struct workqueue_struct *workqueue;
96 /**/
97 struct work_struct worker;
98
99 /* I2C adapter */
100 struct i2c_adapter *i2c_adapter;
101 /* I2C lock */
102 struct mutex i2c_mutex;
103
104 /* usb control transfer buffer and lock */
105 struct mutex usbc_mutex;
106 u8 *usbc_buf;
107};
108
109
110/* buffer one bulk urb of data */
111struct hdpvr_buffer {
112 struct list_head buff_list;
113
114 struct urb *urb;
115
116 struct hdpvr_device *dev;
117
118 uint pos;
119
120 __u8 status;
121};
122
123/* */
124
125struct hdpvr_video_info {
126 u16 width;
127 u16 height;
128 u8 fps;
129};
130
131enum {
132 STATUS_UNINITIALIZED = 0,
133 STATUS_IDLE,
134 STATUS_STARTING,
135 STATUS_SHUTTING_DOWN,
136 STATUS_STREAMING,
137 STATUS_ERROR,
138 STATUS_DISCONNECTED,
139};
140
141enum {
142 HDPVR_FLAG_AC3_CAP = 1,
143};
144
145enum {
146 BUFSTAT_UNINITIALIZED = 0,
147 BUFSTAT_AVAILABLE,
148 BUFSTAT_INPROGRESS,
149 BUFSTAT_READY,
150};
151
152#define CTRL_START_STREAMING_VALUE 0x0700
153#define CTRL_STOP_STREAMING_VALUE 0x0800
154#define CTRL_BITRATE_VALUE 0x1000
155#define CTRL_BITRATE_MODE_VALUE 0x1200
156#define CTRL_GOP_MODE_VALUE 0x1300
157#define CTRL_VIDEO_INPUT_VALUE 0x1500
158#define CTRL_VIDEO_STD_TYPE 0x1700
159#define CTRL_AUDIO_INPUT_VALUE 0x2500
160#define CTRL_BRIGHTNESS 0x2900
161#define CTRL_CONTRAST 0x2a00
162#define CTRL_HUE 0x2b00
163#define CTRL_SATURATION 0x2c00
164#define CTRL_SHARPNESS 0x2d00
165#define CTRL_LOW_PASS_FILTER_VALUE 0x3100
166
167#define CTRL_DEFAULT_INDEX 0x0003
168
169
170 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
171 * BITRATE SETTING
172 * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
173 * min: 1 mbit/s, max: 13.5 mbit/s
174 * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
175 * min: average + 100kbit/s,
176 * max: 20.2 mbit/s
177 */
178
179 /* :0 s 38 01 1200 0003 0001 1 = 02
180 * BIT RATE MODE
181 * constant = 1, variable (peak) = 2, variable (average) = 3
182 */
183
184 /* :0 s 38 01 1300 0003 0001 1 = 03
185 * GOP MODE (2 bit)
186 * low bit 0/1: advanced/simple GOP
187 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
188 */
189
190 /* :0 s 38 01 1700 0003 0001 1 = 00
191 * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz
192 */
193
194 /* :0 s 38 01 3100 0003 0004 4 = 03030000
195 * FILTER CONTROL
196 * 1st byte luma low pass filter strength,
197 * 2nd byte chroma low pass filter strength,
198 * 3rd byte MF enable chroma, min=0, max=1
199 * 4th byte n
200 */
201
202
203 /* :0 s 38 b9 0001 0000 0000 0 */
204
205
206
207/* :0 s 38 d3 0000 0000 0001 1 = 00 */
208/* ret = usb_control_msg(dev->udev, */
209/* usb_sndctrlpipe(dev->udev, 0), */
210/* 0xd3, 0x38, */
211/* 0, 0, */
212/* "\0", 1, */
213/* 1000); */
214
215/* info("control request returned %d", ret); */
216/* msleep(5000); */
217
218
219 /* :0 s b8 81 1400 0003 0005 5 <
220 * :0 0 5 = d0024002 19
221 * QUERY FRAME SIZE AND RATE
222 * 1st and 2nd byte (little endian): horizontal resolution
223 * 3rd and 4th byte (little endian): vertical resolution
224 * 5th byte: frame rate
225 */
226
227 /* :0 s b8 81 1800 0003 0003 3 <
228 * :0 0 3 = 030104
229 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
230 */
231
232enum hdpvr_video_std {
233 HDPVR_60HZ = 0,
234 HDPVR_50HZ,
235};
236
237enum hdpvr_video_input {
238 HDPVR_COMPONENT = 0,
239 HDPVR_SVIDEO,
240 HDPVR_COMPOSITE,
241 HDPVR_VIDEO_INPUTS
242};
243
244enum hdpvr_audio_inputs {
245 HDPVR_RCA_BACK = 0,
246 HDPVR_RCA_FRONT,
247 HDPVR_SPDIF,
248 HDPVR_AUDIO_INPUTS
249};
250
251enum hdpvr_bitrate_mode {
252 HDPVR_CONSTANT = 1,
253 HDPVR_VARIABLE_PEAK,
254 HDPVR_VARIABLE_AVERAGE,
255};
256
257enum hdpvr_gop_mode {
258 HDPVR_ADVANCED_IDR_GOP = 0,
259 HDPVR_SIMPLE_IDR_GOP,
260 HDPVR_ADVANCED_NOIDR_GOP,
261 HDPVR_SIMPLE_NOIDR_GOP,
262};
263
264void hdpvr_delete(struct hdpvr_device *dev);
265
266/*========================================================================*/
267/* hardware control functions */
268int hdpvr_set_options(struct hdpvr_device *dev);
269
270int hdpvr_set_bitrate(struct hdpvr_device *dev);
271
272int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
273 enum v4l2_mpeg_audio_encoding codec);
274
275int hdpvr_config_call(struct hdpvr_device *dev, uint value,
276 unsigned char valbuf);
277
278struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev);
279
280/* :0 s b8 81 1800 0003 0003 3 < */
281/* :0 0 3 = 0301ff */
282int get_input_lines_info(struct hdpvr_device *dev);
283
284
285/*========================================================================*/
286/* v4l2 registration */
287int hdpvr_register_videodev(struct hdpvr_device *dev, int devnumber);
288
289int hdpvr_cancel_queue(struct hdpvr_device *dev);
290
291/*========================================================================*/
292/* i2c adapter registration */
293int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
294
295/*========================================================================*/
296/* buffer management */
297int hdpvr_free_buffers(struct hdpvr_device *dev);
298int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count);