0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/kernel.h>
0009 #include <linux/errno.h>
0010 #include <linux/init.h>
0011 #include <linux/slab.h>
0012 #include <linux/module.h>
0013 #include <linux/usb.h>
0014 #include <linux/mutex.h>
0015
0016 #include <linux/videodev2.h>
0017
0018 #include <media/v4l2-common.h>
0019
0020 #include "hdpvr.h"
0021
0022
0023 int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf)
0024 {
0025 int ret;
0026 char request_type = 0x38, snd_request = 0x01;
0027
0028 mutex_lock(&dev->usbc_mutex);
0029 dev->usbc_buf[0] = valbuf;
0030 ret = usb_control_msg(dev->udev,
0031 usb_sndctrlpipe(dev->udev, 0),
0032 snd_request, 0x00 | request_type,
0033 value, CTRL_DEFAULT_INDEX,
0034 dev->usbc_buf, 1, 10000);
0035
0036 mutex_unlock(&dev->usbc_mutex);
0037 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
0038 "config call request for value 0x%x returned %d\n", value,
0039 ret);
0040
0041 return ret < 0 ? ret : 0;
0042 }
0043
0044 int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf)
0045 {
0046 int ret;
0047
0048 vidinf->valid = false;
0049 mutex_lock(&dev->usbc_mutex);
0050 ret = usb_control_msg(dev->udev,
0051 usb_rcvctrlpipe(dev->udev, 0),
0052 0x81, 0x80 | 0x38,
0053 0x1400, 0x0003,
0054 dev->usbc_buf, 5,
0055 1000);
0056
0057 #ifdef HDPVR_DEBUG
0058 if (hdpvr_debug & MSG_INFO)
0059 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
0060 "get video info returned: %d, %5ph\n", ret,
0061 dev->usbc_buf);
0062 #endif
0063 mutex_unlock(&dev->usbc_mutex);
0064
0065 if (ret < 0)
0066 return ret;
0067
0068 vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
0069 vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
0070 vidinf->fps = dev->usbc_buf[4];
0071 vidinf->valid = vidinf->width && vidinf->height && vidinf->fps;
0072
0073 return 0;
0074 }
0075
0076 int get_input_lines_info(struct hdpvr_device *dev)
0077 {
0078 int ret, lines;
0079
0080 mutex_lock(&dev->usbc_mutex);
0081 ret = usb_control_msg(dev->udev,
0082 usb_rcvctrlpipe(dev->udev, 0),
0083 0x81, 0x80 | 0x38,
0084 0x1800, 0x0003,
0085 dev->usbc_buf, 3,
0086 1000);
0087
0088 #ifdef HDPVR_DEBUG
0089 if (hdpvr_debug & MSG_INFO)
0090 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
0091 "get input lines info returned: %d, %3ph\n", ret,
0092 dev->usbc_buf);
0093 #else
0094 (void)ret;
0095 #endif
0096 lines = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
0097 mutex_unlock(&dev->usbc_mutex);
0098 return lines;
0099 }
0100
0101
0102 int hdpvr_set_bitrate(struct hdpvr_device *dev)
0103 {
0104 int ret;
0105
0106 mutex_lock(&dev->usbc_mutex);
0107 memset(dev->usbc_buf, 0, 4);
0108 dev->usbc_buf[0] = dev->options.bitrate;
0109 dev->usbc_buf[2] = dev->options.peak_bitrate;
0110
0111 ret = usb_control_msg(dev->udev,
0112 usb_sndctrlpipe(dev->udev, 0),
0113 0x01, 0x38, CTRL_BITRATE_VALUE,
0114 CTRL_DEFAULT_INDEX, dev->usbc_buf, 4, 1000);
0115 mutex_unlock(&dev->usbc_mutex);
0116
0117 return ret;
0118 }
0119
0120 int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
0121 enum v4l2_mpeg_audio_encoding codec)
0122 {
0123 int ret = 0;
0124
0125 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
0126 mutex_lock(&dev->usbc_mutex);
0127 memset(dev->usbc_buf, 0, 2);
0128 dev->usbc_buf[0] = input;
0129 if (codec == V4L2_MPEG_AUDIO_ENCODING_AAC)
0130 dev->usbc_buf[1] = 0;
0131 else if (codec == V4L2_MPEG_AUDIO_ENCODING_AC3)
0132 dev->usbc_buf[1] = 1;
0133 else {
0134 mutex_unlock(&dev->usbc_mutex);
0135 v4l2_err(&dev->v4l2_dev, "invalid audio codec %d\n",
0136 codec);
0137 ret = -EINVAL;
0138 goto error;
0139 }
0140
0141 ret = usb_control_msg(dev->udev,
0142 usb_sndctrlpipe(dev->udev, 0),
0143 0x01, 0x38, CTRL_AUDIO_INPUT_VALUE,
0144 CTRL_DEFAULT_INDEX, dev->usbc_buf, 2,
0145 1000);
0146 mutex_unlock(&dev->usbc_mutex);
0147 if (ret == 2)
0148 ret = 0;
0149 } else
0150 ret = hdpvr_config_call(dev, CTRL_AUDIO_INPUT_VALUE, input);
0151 error:
0152 return ret;
0153 }
0154
0155 int hdpvr_set_options(struct hdpvr_device *dev)
0156 {
0157 hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std);
0158
0159 hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE,
0160 dev->options.video_input+1);
0161
0162 hdpvr_set_audio(dev, dev->options.audio_input+1,
0163 dev->options.audio_codec);
0164
0165 hdpvr_set_bitrate(dev);
0166 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
0167 dev->options.bitrate_mode);
0168 hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode);
0169
0170 hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness);
0171 hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast);
0172 hdpvr_config_call(dev, CTRL_HUE, dev->options.hue);
0173 hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation);
0174 hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness);
0175
0176 return 0;
0177 }