2 * Hauppage HD PVR USB driver
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
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.
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>
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)
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
34 #define NUM_BUFFERS 64
36 #define HDPVR_FIRMWARE_VERSION 0x8
37 #define HDPVR_FIRMWARE_VERSION_AC3 0xd
39 /* #define HDPVR_DEBUG */
41 extern int hdpvr_debug
;
46 struct hdpvr_options
{
50 u8 bitrate
; /* in 100kbps */
51 u8 peak_bitrate
; /* in 100kbps */
54 enum v4l2_mpeg_audio_encoding audio_codec
;
62 /* Structure to hold all of our device specific stuff */
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
;
69 /* the max packet size of the bulk endpoint */
71 /* the address of the bulk in endpoint */
72 __u8 bulk_in_endpointAddr
;
74 /* holds the current device status */
76 /* count the number of openers */
79 /* holds the cureent set options */
80 struct hdpvr_options options
;
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
;
95 struct workqueue_struct
*workqueue
;
97 struct work_struct worker
;
100 struct i2c_adapter
*i2c_adapter
;
102 struct mutex i2c_mutex
;
104 /* usb control transfer buffer and lock */
105 struct mutex usbc_mutex
;
110 /* buffer one bulk urb of data */
111 struct hdpvr_buffer
{
112 struct list_head buff_list
;
116 struct hdpvr_device
*dev
;
125 struct hdpvr_video_info
{
132 STATUS_UNINITIALIZED
= 0,
135 STATUS_SHUTTING_DOWN
,
142 HDPVR_FLAG_AC3_CAP
= 1,
146 BUFSTAT_UNINITIALIZED
= 0,
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
167 #define CTRL_DEFAULT_INDEX 0x0003
170 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
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,
179 /* :0 s 38 01 1200 0003 0001 1 = 02
181 * constant = 1, variable (peak) = 2, variable (average) = 3
184 /* :0 s 38 01 1300 0003 0001 1 = 03
186 * low bit 0/1: advanced/simple GOP
187 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
190 /* :0 s 38 01 1700 0003 0001 1 = 00
191 * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz
194 /* :0 s 38 01 3100 0003 0004 4 = 03030000
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
203 /* :0 s 38 b9 0001 0000 0000 0 */
207 /* :0 s 38 d3 0000 0000 0001 1 = 00 */
208 /* ret = usb_control_msg(dev->udev, */
209 /* usb_sndctrlpipe(dev->udev, 0), */
215 /* info("control request returned %d", ret); */
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
227 /* :0 s b8 81 1800 0003 0003 3 <
229 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
232 enum hdpvr_video_std
{
237 enum hdpvr_video_input
{
244 enum hdpvr_audio_inputs
{
251 enum hdpvr_bitrate_mode
{
254 HDPVR_VARIABLE_AVERAGE
,
257 enum hdpvr_gop_mode
{
258 HDPVR_ADVANCED_IDR_GOP
= 0,
259 HDPVR_SIMPLE_IDR_GOP
,
260 HDPVR_ADVANCED_NOIDR_GOP
,
261 HDPVR_SIMPLE_NOIDR_GOP
,
264 void hdpvr_delete(struct hdpvr_device
*dev
);
266 /*========================================================================*/
267 /* hardware control functions */
268 int hdpvr_set_options(struct hdpvr_device
*dev
);
270 int hdpvr_set_bitrate(struct hdpvr_device
*dev
);
272 int hdpvr_set_audio(struct hdpvr_device
*dev
, u8 input
,
273 enum v4l2_mpeg_audio_encoding codec
);
275 int hdpvr_config_call(struct hdpvr_device
*dev
, uint value
,
276 unsigned char valbuf
);
278 struct hdpvr_video_info
*get_video_info(struct hdpvr_device
*dev
);
280 /* :0 s b8 81 1800 0003 0003 3 < */
281 /* :0 0 3 = 0301ff */
282 int get_input_lines_info(struct hdpvr_device
*dev
);
285 /*========================================================================*/
286 /* v4l2 registration */
287 int hdpvr_register_videodev(struct hdpvr_device
*dev
, int devnumber
);
289 int hdpvr_cancel_queue(struct hdpvr_device
*dev
);
291 /*========================================================================*/
292 /* i2c adapter registration */
293 int hdpvr_register_i2c_adapter(struct hdpvr_device
*dev
);
295 /*========================================================================*/
296 /* buffer management */
297 int hdpvr_free_buffers(struct hdpvr_device
*dev
);
298 int hdpvr_alloc_buffers(struct hdpvr_device
*dev
, uint count
);