1 // SPDX-License-Identifier: GPL-2.0-only
3 * Hauppauge HD PVR USB driver - video 4 linux 2 interface
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <linux/usb.h>
14 #include <linux/mutex.h>
16 #include <linux/videodev2.h>
18 #include <media/v4l2-common.h>
23 int hdpvr_config_call(struct hdpvr_device
*dev
, uint value
, u8 valbuf
)
26 char request_type
= 0x38, snd_request
= 0x01;
28 mutex_lock(&dev
->usbc_mutex
);
29 dev
->usbc_buf
[0] = valbuf
;
30 ret
= usb_control_msg(dev
->udev
,
31 usb_sndctrlpipe(dev
->udev
, 0),
32 snd_request
, 0x00 | request_type
,
33 value
, CTRL_DEFAULT_INDEX
,
34 dev
->usbc_buf
, 1, 10000);
36 mutex_unlock(&dev
->usbc_mutex
);
37 v4l2_dbg(MSG_INFO
, hdpvr_debug
, &dev
->v4l2_dev
,
38 "config call request for value 0x%x returned %d\n", value
,
41 return ret
< 0 ? ret
: 0;
44 int get_video_info(struct hdpvr_device
*dev
, struct hdpvr_video_info
*vidinf
)
48 vidinf
->valid
= false;
49 mutex_lock(&dev
->usbc_mutex
);
50 ret
= usb_control_msg(dev
->udev
,
51 usb_rcvctrlpipe(dev
->udev
, 0),
58 if (hdpvr_debug
& MSG_INFO
)
59 v4l2_dbg(MSG_INFO
, hdpvr_debug
, &dev
->v4l2_dev
,
60 "get video info returned: %d, %5ph\n", ret
,
63 mutex_unlock(&dev
->usbc_mutex
);
68 vidinf
->width
= dev
->usbc_buf
[1] << 8 | dev
->usbc_buf
[0];
69 vidinf
->height
= dev
->usbc_buf
[3] << 8 | dev
->usbc_buf
[2];
70 vidinf
->fps
= dev
->usbc_buf
[4];
71 vidinf
->valid
= vidinf
->width
&& vidinf
->height
&& vidinf
->fps
;
76 int get_input_lines_info(struct hdpvr_device
*dev
)
80 mutex_lock(&dev
->usbc_mutex
);
81 ret
= usb_control_msg(dev
->udev
,
82 usb_rcvctrlpipe(dev
->udev
, 0),
89 if (hdpvr_debug
& MSG_INFO
)
90 v4l2_dbg(MSG_INFO
, hdpvr_debug
, &dev
->v4l2_dev
,
91 "get input lines info returned: %d, %3ph\n", ret
,
94 (void)ret
; /* suppress compiler warning */
96 lines
= dev
->usbc_buf
[1] << 8 | dev
->usbc_buf
[0];
97 mutex_unlock(&dev
->usbc_mutex
);
102 int hdpvr_set_bitrate(struct hdpvr_device
*dev
)
106 mutex_lock(&dev
->usbc_mutex
);
107 memset(dev
->usbc_buf
, 0, 4);
108 dev
->usbc_buf
[0] = dev
->options
.bitrate
;
109 dev
->usbc_buf
[2] = dev
->options
.peak_bitrate
;
111 ret
= usb_control_msg(dev
->udev
,
112 usb_sndctrlpipe(dev
->udev
, 0),
113 0x01, 0x38, CTRL_BITRATE_VALUE
,
114 CTRL_DEFAULT_INDEX
, dev
->usbc_buf
, 4, 1000);
115 mutex_unlock(&dev
->usbc_mutex
);
120 int hdpvr_set_audio(struct hdpvr_device
*dev
, u8 input
,
121 enum v4l2_mpeg_audio_encoding codec
)
125 if (dev
->flags
& HDPVR_FLAG_AC3_CAP
) {
126 mutex_lock(&dev
->usbc_mutex
);
127 memset(dev
->usbc_buf
, 0, 2);
128 dev
->usbc_buf
[0] = input
;
129 if (codec
== V4L2_MPEG_AUDIO_ENCODING_AAC
)
130 dev
->usbc_buf
[1] = 0;
131 else if (codec
== V4L2_MPEG_AUDIO_ENCODING_AC3
)
132 dev
->usbc_buf
[1] = 1;
134 mutex_unlock(&dev
->usbc_mutex
);
135 v4l2_err(&dev
->v4l2_dev
, "invalid audio codec %d\n",
141 ret
= usb_control_msg(dev
->udev
,
142 usb_sndctrlpipe(dev
->udev
, 0),
143 0x01, 0x38, CTRL_AUDIO_INPUT_VALUE
,
144 CTRL_DEFAULT_INDEX
, dev
->usbc_buf
, 2,
146 mutex_unlock(&dev
->usbc_mutex
);
150 ret
= hdpvr_config_call(dev
, CTRL_AUDIO_INPUT_VALUE
, input
);
155 int hdpvr_set_options(struct hdpvr_device
*dev
)
157 hdpvr_config_call(dev
, CTRL_VIDEO_STD_TYPE
, dev
->options
.video_std
);
159 hdpvr_config_call(dev
, CTRL_VIDEO_INPUT_VALUE
,
160 dev
->options
.video_input
+1);
162 hdpvr_set_audio(dev
, dev
->options
.audio_input
+1,
163 dev
->options
.audio_codec
);
165 hdpvr_set_bitrate(dev
);
166 hdpvr_config_call(dev
, CTRL_BITRATE_MODE_VALUE
,
167 dev
->options
.bitrate_mode
);
168 hdpvr_config_call(dev
, CTRL_GOP_MODE_VALUE
, dev
->options
.gop_mode
);
170 hdpvr_config_call(dev
, CTRL_BRIGHTNESS
, dev
->options
.brightness
);
171 hdpvr_config_call(dev
, CTRL_CONTRAST
, dev
->options
.contrast
);
172 hdpvr_config_call(dev
, CTRL_HUE
, dev
->options
.hue
);
173 hdpvr_config_call(dev
, CTRL_SATURATION
, dev
->options
.saturation
);
174 hdpvr_config_call(dev
, CTRL_SHARPNESS
, dev
->options
.sharpness
);