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>
19 #include <media/v4l2-ctrls.h>
20 #include <media/ir-kbd-i2c.h>
23 #define HDPVR_I2C_MAX_SIZE 128
25 /* Define these values to match your devices */
26 #define HD_PVR_VENDOR_ID 0x2040
27 #define HD_PVR_PRODUCT_ID 0x4900
28 #define HD_PVR_PRODUCT_ID1 0x4901
29 #define HD_PVR_PRODUCT_ID2 0x4902
30 #define HD_PVR_PRODUCT_ID4 0x4903
31 #define HD_PVR_PRODUCT_ID3 0x4982
35 #define NUM_BUFFERS 64
37 #define HDPVR_FIRMWARE_VERSION 0x08
38 #define HDPVR_FIRMWARE_VERSION_AC3 0x0d
39 #define HDPVR_FIRMWARE_VERSION_0X12 0x12
40 #define HDPVR_FIRMWARE_VERSION_0X15 0x15
41 #define HDPVR_FIRMWARE_VERSION_0X1E 0x1e
43 /* #define HDPVR_DEBUG */
45 extern int hdpvr_debug
;
50 struct hdpvr_options
{
54 u8 bitrate
; /* in 100kbps */
55 u8 peak_bitrate
; /* in 100kbps */
58 enum v4l2_mpeg_audio_encoding audio_codec
;
66 /* Structure to hold all of our device specific stuff */
68 /* the v4l device for this device */
69 struct video_device
*video_dev
;
70 /* the control handler for this device */
71 struct v4l2_ctrl_handler hdl
;
72 /* the usb device for this device */
73 struct usb_device
*udev
;
74 /* v4l2-device unused */
75 struct v4l2_device v4l2_dev
;
76 struct { /* video mode/bitrate control cluster */
77 struct v4l2_ctrl
*video_mode
;
78 struct v4l2_ctrl
*video_bitrate
;
79 struct v4l2_ctrl
*video_bitrate_peak
;
84 /* the max packet size of the bulk endpoint */
86 /* the address of the bulk in endpoint */
87 __u8 bulk_in_endpointAddr
;
89 /* holds the current device status */
92 /* holds the current set options */
93 struct hdpvr_options options
;
95 struct v4l2_dv_timings cur_dv_timings
;
100 struct mutex io_mutex
;
101 /* available buffers */
102 struct list_head free_buff_list
;
103 /* in progress buffers */
104 struct list_head rec_buff_list
;
105 /* waitqueue for buffers */
106 wait_queue_head_t wait_buffer
;
107 /* waitqueue for data */
108 wait_queue_head_t wait_data
;
110 struct workqueue_struct
*workqueue
;
112 struct work_struct worker
;
113 /* current stream owner */
114 struct v4l2_fh
*owner
;
117 struct i2c_adapter i2c_adapter
;
119 struct mutex i2c_mutex
;
120 /* I2C message buffer space */
121 char i2c_buf
[HDPVR_I2C_MAX_SIZE
];
123 /* For passing data to ir-kbd-i2c */
124 struct IR_i2c_init_data ir_i2c_init_data
;
126 /* usb control transfer buffer and lock */
127 struct mutex usbc_mutex
;
132 static inline struct hdpvr_device
*to_hdpvr_dev(struct v4l2_device
*v4l2_dev
)
134 return container_of(v4l2_dev
, struct hdpvr_device
, v4l2_dev
);
138 /* buffer one bulk urb of data */
139 struct hdpvr_buffer
{
140 struct list_head buff_list
;
144 struct hdpvr_device
*dev
;
153 struct hdpvr_video_info
{
161 STATUS_UNINITIALIZED
= 0,
164 STATUS_SHUTTING_DOWN
,
171 HDPVR_FLAG_AC3_CAP
= 1,
175 BUFSTAT_UNINITIALIZED
= 0,
181 #define CTRL_START_STREAMING_VALUE 0x0700
182 #define CTRL_STOP_STREAMING_VALUE 0x0800
183 #define CTRL_BITRATE_VALUE 0x1000
184 #define CTRL_BITRATE_MODE_VALUE 0x1200
185 #define CTRL_GOP_MODE_VALUE 0x1300
186 #define CTRL_VIDEO_INPUT_VALUE 0x1500
187 #define CTRL_VIDEO_STD_TYPE 0x1700
188 #define CTRL_AUDIO_INPUT_VALUE 0x2500
189 #define CTRL_BRIGHTNESS 0x2900
190 #define CTRL_CONTRAST 0x2a00
191 #define CTRL_HUE 0x2b00
192 #define CTRL_SATURATION 0x2c00
193 #define CTRL_SHARPNESS 0x2d00
194 #define CTRL_LOW_PASS_FILTER_VALUE 0x3100
196 #define CTRL_DEFAULT_INDEX 0x0003
199 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
201 * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
202 * min: 1 mbit/s, max: 13.5 mbit/s
203 * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
204 * min: average + 100kbit/s,
208 /* :0 s 38 01 1200 0003 0001 1 = 02
210 * constant = 1, variable (peak) = 2, variable (average) = 3
213 /* :0 s 38 01 1300 0003 0001 1 = 03
215 * low bit 0/1: advanced/simple GOP
216 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
219 /* :0 s 38 01 1700 0003 0001 1 = 00
220 * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz
223 /* :0 s 38 01 3100 0003 0004 4 = 03030000
225 * 1st byte luma low pass filter strength,
226 * 2nd byte chroma low pass filter strength,
227 * 3rd byte MF enable chroma, min=0, max=1
232 /* :0 s 38 b9 0001 0000 0000 0 */
236 /* :0 s 38 d3 0000 0000 0001 1 = 00 */
237 /* ret = usb_control_msg(dev->udev, */
238 /* usb_sndctrlpipe(dev->udev, 0), */
244 /* info("control request returned %d", ret); */
248 /* :0 s b8 81 1400 0003 0005 5 <
249 * :0 0 5 = d0024002 19
250 * QUERY FRAME SIZE AND RATE
251 * 1st and 2nd byte (little endian): horizontal resolution
252 * 3rd and 4th byte (little endian): vertical resolution
253 * 5th byte: frame rate
256 /* :0 s b8 81 1800 0003 0003 3 <
258 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
261 enum hdpvr_video_std
{
266 enum hdpvr_video_input
{
273 enum hdpvr_audio_inputs
{
280 enum hdpvr_bitrate_mode
{
283 HDPVR_VARIABLE_AVERAGE
,
286 enum hdpvr_gop_mode
{
287 HDPVR_ADVANCED_IDR_GOP
= 0,
288 HDPVR_SIMPLE_IDR_GOP
,
289 HDPVR_ADVANCED_NOIDR_GOP
,
290 HDPVR_SIMPLE_NOIDR_GOP
,
293 void hdpvr_delete(struct hdpvr_device
*dev
);
295 /*========================================================================*/
296 /* hardware control functions */
297 int hdpvr_set_options(struct hdpvr_device
*dev
);
299 int hdpvr_set_bitrate(struct hdpvr_device
*dev
);
301 int hdpvr_set_audio(struct hdpvr_device
*dev
, u8 input
,
302 enum v4l2_mpeg_audio_encoding codec
);
304 int hdpvr_config_call(struct hdpvr_device
*dev
, uint value
,
305 unsigned char valbuf
);
307 int get_video_info(struct hdpvr_device
*dev
, struct hdpvr_video_info
*vid_info
);
309 /* :0 s b8 81 1800 0003 0003 3 < */
310 /* :0 0 3 = 0301ff */
311 int get_input_lines_info(struct hdpvr_device
*dev
);
314 /*========================================================================*/
315 /* v4l2 registration */
316 int hdpvr_register_videodev(struct hdpvr_device
*dev
, struct device
*parent
,
319 int hdpvr_cancel_queue(struct hdpvr_device
*dev
);
321 /*========================================================================*/
322 /* i2c adapter registration */
323 int hdpvr_register_i2c_adapter(struct hdpvr_device
*dev
);
325 struct i2c_client
*hdpvr_register_ir_rx_i2c(struct hdpvr_device
*dev
);
326 struct i2c_client
*hdpvr_register_ir_tx_i2c(struct hdpvr_device
*dev
);
328 /*========================================================================*/
329 /* buffer management */
330 int hdpvr_free_buffers(struct hdpvr_device
*dev
);
331 int hdpvr_alloc_buffers(struct hdpvr_device
*dev
, uint count
);