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