Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Hauppauge HD PVR USB driver - video 4 linux 2 interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008      Janne Grunau (j@jannau.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <media/v4l2-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "hdpvr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	char request_type = 0x38, snd_request = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	mutex_lock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	dev->usbc_buf[0] = valbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	ret = usb_control_msg(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			      usb_sndctrlpipe(dev->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			      snd_request, 0x00 | request_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			      value, CTRL_DEFAULT_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			      dev->usbc_buf, 1, 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		 "config call request for value 0x%x returned %d\n", value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		 ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return ret < 0 ? ret : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	vidinf->valid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	mutex_lock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ret = usb_control_msg(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			      usb_rcvctrlpipe(dev->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			      0x81, 0x80 | 0x38,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			      0x1400, 0x0003,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			      dev->usbc_buf, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			      1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #ifdef HDPVR_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (hdpvr_debug & MSG_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			 "get video info returned: %d, %5ph\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			 dev->usbc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	vidinf->width	= dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	vidinf->height	= dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	vidinf->fps	= dev->usbc_buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	vidinf->valid   = vidinf->width && vidinf->height && vidinf->fps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) int get_input_lines_info(struct hdpvr_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int ret, lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	mutex_lock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	ret = usb_control_msg(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			      usb_rcvctrlpipe(dev->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			      0x81, 0x80 | 0x38,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			      0x1800, 0x0003,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			      dev->usbc_buf, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			      1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #ifdef HDPVR_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (hdpvr_debug & MSG_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			 "get input lines info returned: %d, %3ph\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			 dev->usbc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	(void)ret;	/* suppress compiler warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	lines = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int hdpvr_set_bitrate(struct hdpvr_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	mutex_lock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	memset(dev->usbc_buf, 0, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	dev->usbc_buf[0] = dev->options.bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	dev->usbc_buf[2] = dev->options.peak_bitrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = usb_control_msg(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			      usb_sndctrlpipe(dev->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			      0x01, 0x38, CTRL_BITRATE_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			      CTRL_DEFAULT_INDEX, dev->usbc_buf, 4, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		    enum v4l2_mpeg_audio_encoding codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (dev->flags & HDPVR_FLAG_AC3_CAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		mutex_lock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		memset(dev->usbc_buf, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		dev->usbc_buf[0] = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (codec == V4L2_MPEG_AUDIO_ENCODING_AAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			dev->usbc_buf[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		else if (codec == V4L2_MPEG_AUDIO_ENCODING_AC3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			dev->usbc_buf[1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			v4l2_err(&dev->v4l2_dev, "invalid audio codec %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				 codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ret = usb_control_msg(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				      usb_sndctrlpipe(dev->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				      0x01, 0x38, CTRL_AUDIO_INPUT_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				      CTRL_DEFAULT_INDEX, dev->usbc_buf, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				      1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		mutex_unlock(&dev->usbc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (ret == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		ret = hdpvr_config_call(dev, CTRL_AUDIO_INPUT_VALUE, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int hdpvr_set_options(struct hdpvr_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			 dev->options.video_input+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	hdpvr_set_audio(dev, dev->options.audio_input+1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		       dev->options.audio_codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	hdpvr_set_bitrate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			 dev->options.bitrate_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	hdpvr_config_call(dev, CTRL_CONTRAST,   dev->options.contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	hdpvr_config_call(dev, CTRL_HUE,        dev->options.hue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	hdpvr_config_call(dev, CTRL_SHARPNESS,  dev->options.sharpness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }