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