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