aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-03-19 08:30:50 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-04-14 18:57:10 -0400
commit99c77aa4281c41fab255a4eb25ccc36a8c2e113d (patch)
treeaf22a4c6b5bdeab7fb24f6d7f33181aa88cb96ef /drivers/media/usb
parenta7b74bd82a26379495e0e727d2c0fa9b0b97d917 (diff)
[media] hdpvr: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/usb')
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-video.c515
-rw-r--r--drivers/media/usb/hdpvr/hdpvr.h8
2 files changed, 145 insertions, 378 deletions
diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
index 2983bf0d5f0f..a89012720e5a 100644
--- a/drivers/media/usb/hdpvr/hdpvr-video.c
+++ b/drivers/media/usb/hdpvr/hdpvr-video.c
@@ -710,335 +710,69 @@ static int vidioc_g_audio(struct file *file, void *private_data,
710 return 0; 710 return 0;
711} 711}
712 712
713static const s32 supported_v4l2_ctrls[] = { 713static int hdpvr_try_ctrl(struct v4l2_ctrl *ctrl)
714 V4L2_CID_BRIGHTNESS,
715 V4L2_CID_CONTRAST,
716 V4L2_CID_SATURATION,
717 V4L2_CID_HUE,
718 V4L2_CID_SHARPNESS,
719 V4L2_CID_MPEG_AUDIO_ENCODING,
720 V4L2_CID_MPEG_VIDEO_ENCODING,
721 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
722 V4L2_CID_MPEG_VIDEO_BITRATE,
723 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
724};
725
726static int fill_queryctrl(struct hdpvr_options *opt, struct v4l2_queryctrl *qc,
727 int ac3, int fw_ver)
728{
729 int err;
730
731 if (fw_ver > 0x15) {
732 switch (qc->id) {
733 case V4L2_CID_BRIGHTNESS:
734 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
735 case V4L2_CID_CONTRAST:
736 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
737 case V4L2_CID_SATURATION:
738 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x40);
739 case V4L2_CID_HUE:
740 return v4l2_ctrl_query_fill(qc, 0x0, 0x1e, 1, 0xf);
741 case V4L2_CID_SHARPNESS:
742 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
743 }
744 } else {
745 switch (qc->id) {
746 case V4L2_CID_BRIGHTNESS:
747 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x86);
748 case V4L2_CID_CONTRAST:
749 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
750 case V4L2_CID_SATURATION:
751 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
752 case V4L2_CID_HUE:
753 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
754 case V4L2_CID_SHARPNESS:
755 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
756 }
757 }
758
759 switch (qc->id) {
760 case V4L2_CID_MPEG_AUDIO_ENCODING:
761 return v4l2_ctrl_query_fill(
762 qc, V4L2_MPEG_AUDIO_ENCODING_AAC,
763 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3
764 : V4L2_MPEG_AUDIO_ENCODING_AAC,
765 1, V4L2_MPEG_AUDIO_ENCODING_AAC);
766 case V4L2_CID_MPEG_VIDEO_ENCODING:
767 return v4l2_ctrl_query_fill(
768 qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC,
769 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
770 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
771
772/* case V4L2_CID_MPEG_VIDEO_? maybe keyframe interval: */
773/* return v4l2_ctrl_query_fill(qc, 0, 128, 128, 0); */
774 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
775 return v4l2_ctrl_query_fill(
776 qc, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
777 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
778 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
779
780 case V4L2_CID_MPEG_VIDEO_BITRATE:
781 return v4l2_ctrl_query_fill(qc, 1000000, 13500000, 100000,
782 6500000);
783 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
784 err = v4l2_ctrl_query_fill(qc, 1100000, 20200000, 100000,
785 9000000);
786 if (!err && opt->bitrate_mode == HDPVR_CONSTANT)
787 qc->flags |= V4L2_CTRL_FLAG_INACTIVE;
788 return err;
789 default:
790 return -EINVAL;
791 }
792}
793
794static int vidioc_queryctrl(struct file *file, void *private_data,
795 struct v4l2_queryctrl *qc)
796{ 714{
797 struct hdpvr_fh *fh = file->private_data; 715 struct hdpvr_device *dev =
798 struct hdpvr_device *dev = fh->dev; 716 container_of(ctrl->handler, struct hdpvr_device, hdl);
799 int i, next;
800 u32 id = qc->id;
801
802 memset(qc, 0, sizeof(*qc));
803
804 next = !!(id & V4L2_CTRL_FLAG_NEXT_CTRL);
805 qc->id = id & ~V4L2_CTRL_FLAG_NEXT_CTRL;
806
807 for (i = 0; i < ARRAY_SIZE(supported_v4l2_ctrls); i++) {
808 if (next) {
809 if (qc->id < supported_v4l2_ctrls[i])
810 qc->id = supported_v4l2_ctrls[i];
811 else
812 continue;
813 }
814
815 if (qc->id == supported_v4l2_ctrls[i])
816 return fill_queryctrl(&dev->options, qc,
817 dev->flags & HDPVR_FLAG_AC3_CAP,
818 dev->fw_ver);
819
820 if (qc->id < supported_v4l2_ctrls[i])
821 break;
822 }
823
824 return -EINVAL;
825}
826
827static int vidioc_g_ctrl(struct file *file, void *private_data,
828 struct v4l2_control *ctrl)
829{
830 struct hdpvr_fh *fh = file->private_data;
831 struct hdpvr_device *dev = fh->dev;
832 717
833 switch (ctrl->id) { 718 switch (ctrl->id) {
834 case V4L2_CID_BRIGHTNESS: 719 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
835 ctrl->value = dev->options.brightness; 720 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
836 break; 721 dev->video_bitrate->val >= dev->video_bitrate_peak->val)
837 case V4L2_CID_CONTRAST: 722 dev->video_bitrate_peak->val =
838 ctrl->value = dev->options.contrast; 723 dev->video_bitrate->val + 100000;
839 break;
840 case V4L2_CID_SATURATION:
841 ctrl->value = dev->options.saturation;
842 break;
843 case V4L2_CID_HUE:
844 ctrl->value = dev->options.hue;
845 break;
846 case V4L2_CID_SHARPNESS:
847 ctrl->value = dev->options.sharpness;
848 break; 724 break;
849 default:
850 return -EINVAL;
851 } 725 }
852 return 0; 726 return 0;
853} 727}
854 728
855static int vidioc_s_ctrl(struct file *file, void *private_data, 729static int hdpvr_s_ctrl(struct v4l2_ctrl *ctrl)
856 struct v4l2_control *ctrl)
857{ 730{
858 struct hdpvr_fh *fh = file->private_data; 731 struct hdpvr_device *dev =
859 struct hdpvr_device *dev = fh->dev; 732 container_of(ctrl->handler, struct hdpvr_device, hdl);
860 int retval; 733 struct hdpvr_options *opt = &dev->options;
734 int ret = -EINVAL;
861 735
862 switch (ctrl->id) { 736 switch (ctrl->id) {
863 case V4L2_CID_BRIGHTNESS: 737 case V4L2_CID_BRIGHTNESS:
864 retval = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->value); 738 ret = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->val);
865 if (!retval) 739 if (ret)
866 dev->options.brightness = ctrl->value; 740 break;
867 break; 741 dev->options.brightness = ctrl->val;
742 return 0;
868 case V4L2_CID_CONTRAST: 743 case V4L2_CID_CONTRAST:
869 retval = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->value); 744 ret = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->val);
870 if (!retval) 745 if (ret)
871 dev->options.contrast = ctrl->value; 746 break;
872 break; 747 dev->options.contrast = ctrl->val;
748 return 0;
873 case V4L2_CID_SATURATION: 749 case V4L2_CID_SATURATION:
874 retval = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->value); 750 ret = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->val);
875 if (!retval) 751 if (ret)
876 dev->options.saturation = ctrl->value; 752 break;
877 break; 753 dev->options.saturation = ctrl->val;
754 return 0;
878 case V4L2_CID_HUE: 755 case V4L2_CID_HUE:
879 retval = hdpvr_config_call(dev, CTRL_HUE, ctrl->value); 756 ret = hdpvr_config_call(dev, CTRL_HUE, ctrl->val);
880 if (!retval) 757 if (ret)
881 dev->options.hue = ctrl->value; 758 break;
882 break; 759 dev->options.hue = ctrl->val;
760 return 0;
883 case V4L2_CID_SHARPNESS: 761 case V4L2_CID_SHARPNESS:
884 retval = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->value); 762 ret = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->val);
885 if (!retval) 763 if (ret)
886 dev->options.sharpness = ctrl->value; 764 break;
887 break; 765 dev->options.sharpness = ctrl->val;
888 default: 766 return 0;
889 return -EINVAL;
890 }
891
892 return retval;
893}
894
895
896static int hdpvr_get_ctrl(struct hdpvr_options *opt,
897 struct v4l2_ext_control *ctrl)
898{
899 switch (ctrl->id) {
900 case V4L2_CID_MPEG_AUDIO_ENCODING:
901 ctrl->value = opt->audio_codec;
902 break;
903 case V4L2_CID_MPEG_VIDEO_ENCODING:
904 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC;
905 break;
906/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
907/* ctrl->value = (opt->gop_mode & 0x2) ? 0 : 128; */
908/* break; */
909 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
910 ctrl->value = opt->bitrate_mode == HDPVR_CONSTANT
911 ? V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
912 : V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
913 break;
914 case V4L2_CID_MPEG_VIDEO_BITRATE:
915 ctrl->value = opt->bitrate * 100000;
916 break;
917 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
918 ctrl->value = opt->peak_bitrate * 100000;
919 break;
920 case V4L2_CID_MPEG_STREAM_TYPE:
921 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
922 break;
923 default:
924 return -EINVAL;
925 }
926 return 0;
927}
928
929static int vidioc_g_ext_ctrls(struct file *file, void *priv,
930 struct v4l2_ext_controls *ctrls)
931{
932 struct hdpvr_fh *fh = file->private_data;
933 struct hdpvr_device *dev = fh->dev;
934 int i, err = 0;
935
936 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
937 for (i = 0; i < ctrls->count; i++) {
938 struct v4l2_ext_control *ctrl = ctrls->controls + i;
939
940 err = hdpvr_get_ctrl(&dev->options, ctrl);
941 if (err) {
942 ctrls->error_idx = i;
943 break;
944 }
945 }
946 return err;
947
948 }
949
950 return -EINVAL;
951}
952
953
954static int hdpvr_try_ctrl(struct v4l2_ext_control *ctrl, int ac3)
955{
956 int ret = -EINVAL;
957
958 switch (ctrl->id) {
959 case V4L2_CID_MPEG_AUDIO_ENCODING:
960 if (ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AAC ||
961 (ac3 && ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AC3))
962 ret = 0;
963 break;
964 case V4L2_CID_MPEG_VIDEO_ENCODING:
965 if (ctrl->value == V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC)
966 ret = 0;
967 break;
968/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
969/* if (ctrl->value == 0 || ctrl->value == 128) */
970/* ret = 0; */
971/* break; */
972 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
973 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
974 ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR)
975 ret = 0;
976 break;
977 case V4L2_CID_MPEG_VIDEO_BITRATE:
978 {
979 uint bitrate = ctrl->value / 100000;
980 if (bitrate >= 10 && bitrate <= 135)
981 ret = 0;
982 break;
983 }
984 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
985 {
986 uint peak_bitrate = ctrl->value / 100000;
987 if (peak_bitrate >= 10 && peak_bitrate <= 202)
988 ret = 0;
989 break;
990 }
991 case V4L2_CID_MPEG_STREAM_TYPE:
992 if (ctrl->value == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
993 ret = 0;
994 break;
995 default:
996 return -EINVAL;
997 }
998 return ret;
999}
1000
1001static int vidioc_try_ext_ctrls(struct file *file, void *priv,
1002 struct v4l2_ext_controls *ctrls)
1003{
1004 struct hdpvr_fh *fh = file->private_data;
1005 struct hdpvr_device *dev = fh->dev;
1006 int i, err = 0;
1007
1008 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1009 for (i = 0; i < ctrls->count; i++) {
1010 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1011
1012 err = hdpvr_try_ctrl(ctrl,
1013 dev->flags & HDPVR_FLAG_AC3_CAP);
1014 if (err) {
1015 ctrls->error_idx = i;
1016 break;
1017 }
1018 }
1019 return err;
1020 }
1021
1022 return -EINVAL;
1023}
1024
1025
1026static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1027 struct v4l2_ext_control *ctrl)
1028{
1029 struct hdpvr_options *opt = &dev->options;
1030 int ret = 0;
1031
1032 switch (ctrl->id) {
1033 case V4L2_CID_MPEG_AUDIO_ENCODING: 767 case V4L2_CID_MPEG_AUDIO_ENCODING:
1034 if (dev->flags & HDPVR_FLAG_AC3_CAP) { 768 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
1035 opt->audio_codec = ctrl->value; 769 opt->audio_codec = ctrl->val;
1036 ret = hdpvr_set_audio(dev, opt->audio_input, 770 return hdpvr_set_audio(dev, opt->audio_input,
1037 opt->audio_codec); 771 opt->audio_codec);
1038 } 772 }
1039 break; 773 return 0;
1040 case V4L2_CID_MPEG_VIDEO_ENCODING: 774 case V4L2_CID_MPEG_VIDEO_ENCODING:
1041 break; 775 return 0;
1042/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */ 776/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
1043/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */ 777/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */
1044/* opt->gop_mode |= 0x2; */ 778/* opt->gop_mode |= 0x2; */
@@ -1051,81 +785,37 @@ static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1051/* opt->gop_mode); */ 785/* opt->gop_mode); */
1052/* } */ 786/* } */
1053/* break; */ 787/* break; */
1054 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 788 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: {
1055 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR && 789 uint peak_bitrate = dev->video_bitrate_peak->val / 100000;
1056 opt->bitrate_mode != HDPVR_CONSTANT) { 790 uint bitrate = dev->video_bitrate->val / 100000;
1057 opt->bitrate_mode = HDPVR_CONSTANT; 791
1058 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, 792 if (ctrl->is_new) {
1059 opt->bitrate_mode); 793 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
1060 } 794 opt->bitrate_mode = HDPVR_CONSTANT;
1061 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && 795 else
1062 opt->bitrate_mode == HDPVR_CONSTANT) { 796 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1063 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1064 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, 797 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1065 opt->bitrate_mode); 798 opt->bitrate_mode);
799 v4l2_ctrl_activate(dev->video_bitrate_peak,
800 ctrl->val != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
1066 } 801 }
1067 break;
1068 case V4L2_CID_MPEG_VIDEO_BITRATE: {
1069 uint bitrate = ctrl->value / 100000;
1070
1071 opt->bitrate = bitrate;
1072 if (bitrate >= opt->peak_bitrate)
1073 opt->peak_bitrate = bitrate+1;
1074
1075 hdpvr_set_bitrate(dev);
1076 break;
1077 }
1078 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: {
1079 uint peak_bitrate = ctrl->value / 100000;
1080 802
1081 if (opt->bitrate_mode == HDPVR_CONSTANT) 803 if (dev->video_bitrate_peak->is_new ||
1082 break; 804 dev->video_bitrate->is_new) {
1083 805 opt->bitrate = bitrate;
1084 if (opt->bitrate < peak_bitrate) {
1085 opt->peak_bitrate = peak_bitrate; 806 opt->peak_bitrate = peak_bitrate;
1086 hdpvr_set_bitrate(dev); 807 hdpvr_set_bitrate(dev);
1087 } else 808 }
1088 ret = -EINVAL; 809 return 0;
1089 break;
1090 } 810 }
1091 case V4L2_CID_MPEG_STREAM_TYPE: 811 case V4L2_CID_MPEG_STREAM_TYPE:
1092 break; 812 return 0;
1093 default: 813 default:
1094 return -EINVAL; 814 break;
1095 } 815 }
1096 return ret; 816 return ret;
1097} 817}
1098 818
1099static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1100 struct v4l2_ext_controls *ctrls)
1101{
1102 struct hdpvr_fh *fh = file->private_data;
1103 struct hdpvr_device *dev = fh->dev;
1104 int i, err = 0;
1105
1106 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1107 for (i = 0; i < ctrls->count; i++) {
1108 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1109
1110 err = hdpvr_try_ctrl(ctrl,
1111 dev->flags & HDPVR_FLAG_AC3_CAP);
1112 if (err) {
1113 ctrls->error_idx = i;
1114 break;
1115 }
1116 err = hdpvr_set_ctrl(dev, ctrl);
1117 if (err) {
1118 ctrls->error_idx = i;
1119 break;
1120 }
1121 }
1122 return err;
1123
1124 }
1125
1126 return -EINVAL;
1127}
1128
1129static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data, 819static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data,
1130 struct v4l2_fmtdesc *f) 820 struct v4l2_fmtdesc *f)
1131{ 821{
@@ -1215,12 +905,6 @@ static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = {
1215 .vidioc_enumaudio = vidioc_enumaudio, 905 .vidioc_enumaudio = vidioc_enumaudio,
1216 .vidioc_g_audio = vidioc_g_audio, 906 .vidioc_g_audio = vidioc_g_audio,
1217 .vidioc_s_audio = vidioc_s_audio, 907 .vidioc_s_audio = vidioc_s_audio,
1218 .vidioc_queryctrl = vidioc_queryctrl,
1219 .vidioc_g_ctrl = vidioc_g_ctrl,
1220 .vidioc_s_ctrl = vidioc_s_ctrl,
1221 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
1222 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1223 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1224 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 908 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1225 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 909 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1226 .vidioc_encoder_cmd = vidioc_encoder_cmd, 910 .vidioc_encoder_cmd = vidioc_encoder_cmd,
@@ -1237,6 +921,7 @@ static void hdpvr_device_release(struct video_device *vdev)
1237 mutex_unlock(&dev->io_mutex); 921 mutex_unlock(&dev->io_mutex);
1238 922
1239 v4l2_device_unregister(&dev->v4l2_dev); 923 v4l2_device_unregister(&dev->v4l2_dev);
924 v4l2_ctrl_handler_free(&dev->hdl);
1240 925
1241 /* deregister I2C adapter */ 926 /* deregister I2C adapter */
1242#if IS_ENABLED(CONFIG_I2C) 927#if IS_ENABLED(CONFIG_I2C)
@@ -1264,13 +949,85 @@ static const struct video_device hdpvr_video_template = {
1264 V4L2_STD_PAL_60, 949 V4L2_STD_PAL_60,
1265}; 950};
1266 951
952static const struct v4l2_ctrl_ops hdpvr_ctrl_ops = {
953 .try_ctrl = hdpvr_try_ctrl,
954 .s_ctrl = hdpvr_s_ctrl,
955};
956
1267int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent, 957int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
1268 int devnum) 958 int devnum)
1269{ 959{
960 struct v4l2_ctrl_handler *hdl = &dev->hdl;
961 bool ac3 = dev->flags & HDPVR_FLAG_AC3_CAP;
962 int res;
963
964 v4l2_ctrl_handler_init(hdl, 11);
965 if (dev->fw_ver > 0x15) {
966 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
967 V4L2_CID_BRIGHTNESS, 0x0, 0xff, 1, 0x80);
968 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
969 V4L2_CID_CONTRAST, 0x0, 0xff, 1, 0x40);
970 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
971 V4L2_CID_SATURATION, 0x0, 0xff, 1, 0x40);
972 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
973 V4L2_CID_HUE, 0x0, 0x1e, 1, 0xf);
974 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
975 V4L2_CID_SHARPNESS, 0x0, 0xff, 1, 0x80);
976 } else {
977 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
978 V4L2_CID_BRIGHTNESS, 0x0, 0xff, 1, 0x86);
979 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
980 V4L2_CID_CONTRAST, 0x0, 0xff, 1, 0x80);
981 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
982 V4L2_CID_SATURATION, 0x0, 0xff, 1, 0x80);
983 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
984 V4L2_CID_HUE, 0x0, 0xff, 1, 0x80);
985 v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
986 V4L2_CID_SHARPNESS, 0x0, 0xff, 1, 0x80);
987 }
988
989 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
990 V4L2_CID_MPEG_STREAM_TYPE,
991 V4L2_MPEG_STREAM_TYPE_MPEG2_TS,
992 0x1, V4L2_MPEG_STREAM_TYPE_MPEG2_TS);
993 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
994 V4L2_CID_MPEG_AUDIO_ENCODING,
995 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 : V4L2_MPEG_AUDIO_ENCODING_AAC,
996 0x7, V4L2_MPEG_AUDIO_ENCODING_AAC);
997 v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
998 V4L2_CID_MPEG_VIDEO_ENCODING,
999 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 0x3,
1000 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
1001
1002 dev->video_mode = v4l2_ctrl_new_std_menu(hdl, &hdpvr_ctrl_ops,
1003 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
1004 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 0,
1005 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
1006
1007 dev->video_bitrate = v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1008 V4L2_CID_MPEG_VIDEO_BITRATE,
1009 1000000, 13500000, 100000, 6500000);
1010 dev->video_bitrate_peak = v4l2_ctrl_new_std(hdl, &hdpvr_ctrl_ops,
1011 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
1012 1100000, 20200000, 100000, 9000000);
1013 dev->v4l2_dev.ctrl_handler = hdl;
1014 if (hdl->error) {
1015 res = hdl->error;
1016 v4l2_err(&dev->v4l2_dev, "Could not register controls\n");
1017 goto error;
1018 }
1019 v4l2_ctrl_cluster(3, &dev->video_mode);
1020 res = v4l2_ctrl_handler_setup(hdl);
1021 if (res < 0) {
1022 v4l2_err(&dev->v4l2_dev, "Could not setup controls\n");
1023 goto error;
1024 }
1025
1270 /* setup and register video device */ 1026 /* setup and register video device */
1271 dev->video_dev = video_device_alloc(); 1027 dev->video_dev = video_device_alloc();
1272 if (!dev->video_dev) { 1028 if (!dev->video_dev) {
1273 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n"); 1029 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n");
1030 res = -ENOMEM;
1274 goto error; 1031 goto error;
1275 } 1032 }
1276 1033
@@ -1279,12 +1036,14 @@ int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
1279 dev->video_dev->parent = parent; 1036 dev->video_dev->parent = parent;
1280 video_set_drvdata(dev->video_dev, dev); 1037 video_set_drvdata(dev->video_dev, dev);
1281 1038
1282 if (video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum)) { 1039 res = video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum);
1040 if (res < 0) {
1283 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n"); 1041 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n");
1284 goto error; 1042 goto error;
1285 } 1043 }
1286 1044
1287 return 0; 1045 return 0;
1288error: 1046error:
1289 return -ENOMEM; 1047 v4l2_ctrl_handler_free(hdl);
1048 return res;
1290} 1049}
diff --git a/drivers/media/usb/hdpvr/hdpvr.h b/drivers/media/usb/hdpvr/hdpvr.h
index fea3c6926997..2a4deab70762 100644
--- a/drivers/media/usb/hdpvr/hdpvr.h
+++ b/drivers/media/usb/hdpvr/hdpvr.h
@@ -16,6 +16,7 @@
16#include <linux/videodev2.h> 16#include <linux/videodev2.h>
17 17
18#include <media/v4l2-device.h> 18#include <media/v4l2-device.h>
19#include <media/v4l2-ctrls.h>
19#include <media/ir-kbd-i2c.h> 20#include <media/ir-kbd-i2c.h>
20 21
21#define HDPVR_MAX 8 22#define HDPVR_MAX 8
@@ -65,10 +66,17 @@ struct hdpvr_options {
65struct hdpvr_device { 66struct hdpvr_device {
66 /* the v4l device for this device */ 67 /* the v4l device for this device */
67 struct video_device *video_dev; 68 struct video_device *video_dev;
69 /* the control handler for this device */
70 struct v4l2_ctrl_handler hdl;
68 /* the usb device for this device */ 71 /* the usb device for this device */
69 struct usb_device *udev; 72 struct usb_device *udev;
70 /* v4l2-device unused */ 73 /* v4l2-device unused */
71 struct v4l2_device v4l2_dev; 74 struct v4l2_device v4l2_dev;
75 struct { /* video mode/bitrate control cluster */
76 struct v4l2_ctrl *video_mode;
77 struct v4l2_ctrl *video_bitrate;
78 struct v4l2_ctrl *video_bitrate_peak;
79 };
72 80
73 /* the max packet size of the bulk endpoint */ 81 /* the max packet size of the bulk endpoint */
74 size_t bulk_in_size; 82 size_t bulk_in_size;