2 * Hauppauge 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 #include <media/v4l2-device.h>
20 #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)
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
33 #define HD_PVR_PRODUCT_ID4 0x4903
34 #define HD_PVR_PRODUCT_ID3 0x4982
38 #define NUM_BUFFERS 64
40 #define HDPVR_FIRMWARE_VERSION 0x08
41 #define HDPVR_FIRMWARE_VERSION_AC3 0x0d
42 #define HDPVR_FIRMWARE_VERSION_0X12 0x12
43 #define HDPVR_FIRMWARE_VERSION_0X15 0x15
45 /* #define HDPVR_DEBUG */
47 extern int hdpvr_debug;
52 struct hdpvr_options {
56 u8 bitrate; /* in 100kbps */
57 u8 peak_bitrate; /* in 100kbps */
60 enum v4l2_mpeg_audio_encoding audio_codec;
68 /* Structure to hold all of our device specific stuff */
70 /* the v4l device for this device */
71 struct video_device *video_dev;
72 /* the usb device for this device */
73 struct usb_device *udev;
74 /* v4l2-device unused */
75 struct v4l2_device v4l2_dev;
77 /* the max packet size of the bulk endpoint */
79 /* the address of the bulk in endpoint */
80 __u8 bulk_in_endpointAddr;
82 /* holds the current device status */
84 /* count the number of openers */
87 /* holds the cureent set options */
88 struct hdpvr_options options;
93 struct mutex io_mutex;
94 /* available buffers */
95 struct list_head free_buff_list;
96 /* in progress buffers */
97 struct list_head rec_buff_list;
98 /* waitqueue for buffers */
99 wait_queue_head_t wait_buffer;
100 /* waitqueue for data */
101 wait_queue_head_t wait_data;
103 struct workqueue_struct *workqueue;
105 struct work_struct worker;
108 struct i2c_adapter *i2c_adapter;
110 struct mutex i2c_mutex;
112 /* usb control transfer buffer and lock */
113 struct mutex usbc_mutex;
117 static inline struct hdpvr_device *to_hdpvr_dev(struct v4l2_device *v4l2_dev)
119 return container_of(v4l2_dev, struct hdpvr_device, v4l2_dev);
123 /* buffer one bulk urb of data */
124 struct hdpvr_buffer {
125 struct list_head buff_list;
129 struct hdpvr_device *dev;
138 struct hdpvr_video_info {
145 STATUS_UNINITIALIZED = 0,
148 STATUS_SHUTTING_DOWN,
155 HDPVR_FLAG_AC3_CAP = 1,
159 BUFSTAT_UNINITIALIZED = 0,
165 #define CTRL_START_STREAMING_VALUE 0x0700
166 #define CTRL_STOP_STREAMING_VALUE 0x0800
167 #define CTRL_BITRATE_VALUE 0x1000
168 #define CTRL_BITRATE_MODE_VALUE 0x1200
169 #define CTRL_GOP_MODE_VALUE 0x1300
170 #define CTRL_VIDEO_INPUT_VALUE 0x1500
171 #define CTRL_VIDEO_STD_TYPE 0x1700
172 #define CTRL_AUDIO_INPUT_VALUE 0x2500
173 #define CTRL_BRIGHTNESS 0x2900
174 #define CTRL_CONTRAST 0x2a00
175 #define CTRL_HUE 0x2b00
176 #define CTRL_SATURATION 0x2c00
177 #define CTRL_SHARPNESS 0x2d00
178 #define CTRL_LOW_PASS_FILTER_VALUE 0x3100
180 #define CTRL_DEFAULT_INDEX 0x0003
183 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
185 * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
186 * min: 1 mbit/s, max: 13.5 mbit/s
187 * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
188 * min: average + 100kbit/s,
192 /* :0 s 38 01 1200 0003 0001 1 = 02
194 * constant = 1, variable (peak) = 2, variable (average) = 3
197 /* :0 s 38 01 1300 0003 0001 1 = 03
199 * low bit 0/1: advanced/simple GOP
200 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
203 /* :0 s 38 01 1700 0003 0001 1 = 00
204 * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz
207 /* :0 s 38 01 3100 0003 0004 4 = 03030000
209 * 1st byte luma low pass filter strength,
210 * 2nd byte chroma low pass filter strength,
211 * 3rd byte MF enable chroma, min=0, max=1
216 /* :0 s 38 b9 0001 0000 0000 0 */
220 /* :0 s 38 d3 0000 0000 0001 1 = 00 */
221 /* ret = usb_control_msg(dev->udev, */
222 /* usb_sndctrlpipe(dev->udev, 0), */
228 /* info("control request returned %d", ret); */
232 /* :0 s b8 81 1400 0003 0005 5 <
233 * :0 0 5 = d0024002 19
234 * QUERY FRAME SIZE AND RATE
235 * 1st and 2nd byte (little endian): horizontal resolution
236 * 3rd and 4th byte (little endian): vertical resolution
237 * 5th byte: frame rate
240 /* :0 s b8 81 1800 0003 0003 3 <
242 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
245 enum hdpvr_video_std {
250 enum hdpvr_video_input {
257 enum hdpvr_audio_inputs {
264 enum hdpvr_bitrate_mode {
267 HDPVR_VARIABLE_AVERAGE,
270 enum hdpvr_gop_mode {
271 HDPVR_ADVANCED_IDR_GOP = 0,
272 HDPVR_SIMPLE_IDR_GOP,
273 HDPVR_ADVANCED_NOIDR_GOP,
274 HDPVR_SIMPLE_NOIDR_GOP,
277 void hdpvr_delete(struct hdpvr_device *dev);
279 /*========================================================================*/
280 /* hardware control functions */
281 int hdpvr_set_options(struct hdpvr_device *dev);
283 int hdpvr_set_bitrate(struct hdpvr_device *dev);
285 int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
286 enum v4l2_mpeg_audio_encoding codec);
288 int hdpvr_config_call(struct hdpvr_device *dev, uint value,
289 unsigned char valbuf);
291 struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev);
293 /* :0 s b8 81 1800 0003 0003 3 < */
294 /* :0 0 3 = 0301ff */
295 int get_input_lines_info(struct hdpvr_device *dev);
298 /*========================================================================*/
299 /* v4l2 registration */
300 int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
303 int hdpvr_cancel_queue(struct hdpvr_device *dev);
305 /*========================================================================*/
306 /* i2c adapter registration */
307 int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
309 /*========================================================================*/
310 /* buffer management */
311 int hdpvr_free_buffers(struct hdpvr_device *dev);
312 int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count);