1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Hauppauge HD PVR USB driver
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
10 #include <linux/mutex.h>
11 #include <linux/workqueue.h>
12 #include <linux/videodev2.h>
14 #include <media/v4l2-device.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/i2c/ir-kbd-i2c.h>
19 #define HDPVR_I2C_MAX_SIZE 128
21 /* Define these values to match your devices */
22 #define HD_PVR_VENDOR_ID 0x2040
23 #define HD_PVR_PRODUCT_ID 0x4900
24 #define HD_PVR_PRODUCT_ID1 0x4901
25 #define HD_PVR_PRODUCT_ID2 0x4902
26 #define HD_PVR_PRODUCT_ID4 0x4903
27 #define HD_PVR_PRODUCT_ID3 0x4982
31 #define NUM_BUFFERS 64
33 #define HDPVR_FIRMWARE_VERSION 0x08
34 #define HDPVR_FIRMWARE_VERSION_AC3 0x0d
35 #define HDPVR_FIRMWARE_VERSION_0X12 0x12
36 #define HDPVR_FIRMWARE_VERSION_0X15 0x15
37 #define HDPVR_FIRMWARE_VERSION_0X1E 0x1e
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 control handler for this device */
67 struct v4l2_ctrl_handler hdl
;
68 /* the usb device for this device */
69 struct usb_device
*udev
;
70 /* v4l2-device unused */
71 struct v4l2_device v4l2_dev
;
72 struct { /* video mode/bitrate control cluster */
73 struct v4l2_ctrl
*video_mode
;
74 struct v4l2_ctrl
*video_bitrate
;
75 struct v4l2_ctrl
*video_bitrate_peak
;
80 /* the max packet size of the bulk endpoint */
82 /* the address of the bulk in endpoint */
83 __u8 bulk_in_endpointAddr
;
85 /* holds the current device status */
88 /* holds the current set options */
89 struct hdpvr_options options
;
91 struct v4l2_dv_timings cur_dv_timings
;
96 struct mutex io_mutex
;
97 /* available buffers */
98 struct list_head free_buff_list
;
99 /* in progress buffers */
100 struct list_head rec_buff_list
;
101 /* waitqueue for buffers */
102 wait_queue_head_t wait_buffer
;
103 /* waitqueue for data */
104 wait_queue_head_t wait_data
;
106 struct work_struct worker
;
107 /* current stream owner */
108 struct v4l2_fh
*owner
;
111 struct i2c_adapter i2c_adapter
;
113 struct mutex i2c_mutex
;
114 /* I2C message buffer space */
115 char i2c_buf
[HDPVR_I2C_MAX_SIZE
];
117 /* For passing data to ir-kbd-i2c */
118 struct IR_i2c_init_data ir_i2c_init_data
;
120 /* usb control transfer buffer and lock */
121 struct mutex usbc_mutex
;
126 static inline struct hdpvr_device
*to_hdpvr_dev(struct v4l2_device
*v4l2_dev
)
128 return container_of(v4l2_dev
, struct hdpvr_device
, v4l2_dev
);
132 /* buffer one bulk urb of data */
133 struct hdpvr_buffer
{
134 struct list_head buff_list
;
138 struct hdpvr_device
*dev
;
147 struct hdpvr_video_info
{
155 STATUS_UNINITIALIZED
= 0,
158 STATUS_SHUTTING_DOWN
,
165 HDPVR_FLAG_AC3_CAP
= 1,
169 BUFSTAT_UNINITIALIZED
= 0,
175 #define CTRL_START_STREAMING_VALUE 0x0700
176 #define CTRL_STOP_STREAMING_VALUE 0x0800
177 #define CTRL_BITRATE_VALUE 0x1000
178 #define CTRL_BITRATE_MODE_VALUE 0x1200
179 #define CTRL_GOP_MODE_VALUE 0x1300
180 #define CTRL_VIDEO_INPUT_VALUE 0x1500
181 #define CTRL_VIDEO_STD_TYPE 0x1700
182 #define CTRL_AUDIO_INPUT_VALUE 0x2500
183 #define CTRL_BRIGHTNESS 0x2900
184 #define CTRL_CONTRAST 0x2a00
185 #define CTRL_HUE 0x2b00
186 #define CTRL_SATURATION 0x2c00
187 #define CTRL_SHARPNESS 0x2d00
188 #define CTRL_LOW_PASS_FILTER_VALUE 0x3100
190 #define CTRL_DEFAULT_INDEX 0x0003
193 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
195 * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
196 * min: 1 mbit/s, max: 13.5 mbit/s
197 * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
198 * min: average + 100kbit/s,
202 /* :0 s 38 01 1200 0003 0001 1 = 02
204 * constant = 1, variable (peak) = 2, variable (average) = 3
207 /* :0 s 38 01 1300 0003 0001 1 = 03
209 * low bit 0/1: advanced/simple GOP
210 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
213 /* :0 s 38 01 1700 0003 0001 1 = 00
214 * VIDEO STANDARD or FREQUENCY 0 = 60hz, 1 = 50hz
217 /* :0 s 38 01 3100 0003 0004 4 = 03030000
219 * 1st byte luma low pass filter strength,
220 * 2nd byte chroma low pass filter strength,
221 * 3rd byte MF enable chroma, min=0, max=1
226 /* :0 s 38 b9 0001 0000 0000 0 */
230 /* :0 s 38 d3 0000 0000 0001 1 = 00 */
231 /* ret = usb_control_msg(dev->udev, */
232 /* usb_sndctrlpipe(dev->udev, 0), */
238 /* info("control request returned %d", ret); */
242 /* :0 s b8 81 1400 0003 0005 5 <
243 * :0 0 5 = d0024002 19
244 * QUERY FRAME SIZE AND RATE
245 * 1st and 2nd byte (little endian): horizontal resolution
246 * 3rd and 4th byte (little endian): vertical resolution
247 * 5th byte: frame rate
250 /* :0 s b8 81 1800 0003 0003 3 <
252 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
255 enum hdpvr_video_std
{
260 enum hdpvr_video_input
{
267 enum hdpvr_audio_inputs
{
274 enum hdpvr_bitrate_mode
{
277 HDPVR_VARIABLE_AVERAGE
,
280 enum hdpvr_gop_mode
{
281 HDPVR_ADVANCED_IDR_GOP
= 0,
282 HDPVR_SIMPLE_IDR_GOP
,
283 HDPVR_ADVANCED_NOIDR_GOP
,
284 HDPVR_SIMPLE_NOIDR_GOP
,
287 void hdpvr_delete(struct hdpvr_device
*dev
);
289 /*========================================================================*/
290 /* hardware control functions */
291 int hdpvr_set_options(struct hdpvr_device
*dev
);
293 int hdpvr_set_bitrate(struct hdpvr_device
*dev
);
295 int hdpvr_set_audio(struct hdpvr_device
*dev
, u8 input
,
296 enum v4l2_mpeg_audio_encoding codec
);
298 int hdpvr_config_call(struct hdpvr_device
*dev
, uint value
,
299 unsigned char valbuf
);
301 int get_video_info(struct hdpvr_device
*dev
, struct hdpvr_video_info
*vid_info
);
303 /* :0 s b8 81 1800 0003 0003 3 < */
304 /* :0 0 3 = 0301ff */
305 int get_input_lines_info(struct hdpvr_device
*dev
);
308 /*========================================================================*/
309 /* v4l2 registration */
310 int hdpvr_register_videodev(struct hdpvr_device
*dev
, struct device
*parent
,
313 int hdpvr_cancel_queue(struct hdpvr_device
*dev
);
315 /*========================================================================*/
316 /* i2c adapter registration */
317 int hdpvr_register_i2c_adapter(struct hdpvr_device
*dev
);
319 struct i2c_client
*hdpvr_register_ir_i2c(struct hdpvr_device
*dev
);
321 /*========================================================================*/
322 /* buffer management */
323 int hdpvr_free_buffers(struct hdpvr_device
*dev
);
324 int hdpvr_alloc_buffers(struct hdpvr_device
*dev
, uint count
);