xref: /openbmc/linux/drivers/media/platform/qcom/venus/vdec_ctrls.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27472c1c6SStanimir Varbanov /*
37472c1c6SStanimir Varbanov  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
47472c1c6SStanimir Varbanov  * Copyright (C) 2017 Linaro Ltd.
57472c1c6SStanimir Varbanov  */
67472c1c6SStanimir Varbanov #include <linux/types.h>
77472c1c6SStanimir Varbanov #include <media/v4l2-ctrls.h>
87472c1c6SStanimir Varbanov 
97472c1c6SStanimir Varbanov #include "core.h"
10cef697d8SStanimir Varbanov #include "helpers.h"
117472c1c6SStanimir Varbanov #include "vdec.h"
127472c1c6SStanimir Varbanov 
vdec_op_s_ctrl(struct v4l2_ctrl * ctrl)137472c1c6SStanimir Varbanov static int vdec_op_s_ctrl(struct v4l2_ctrl *ctrl)
147472c1c6SStanimir Varbanov {
157472c1c6SStanimir Varbanov 	struct venus_inst *inst = ctrl_to_inst(ctrl);
167472c1c6SStanimir Varbanov 	struct vdec_controls *ctr = &inst->controls.dec;
177472c1c6SStanimir Varbanov 
187472c1c6SStanimir Varbanov 	switch (ctrl->id) {
197472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
207472c1c6SStanimir Varbanov 		ctr->post_loop_deb_mode = ctrl->val;
217472c1c6SStanimir Varbanov 		break;
227472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
237472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
245520b946SKeiichi Watanabe 	case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
253cd13671SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
267472c1c6SStanimir Varbanov 		ctr->profile = ctrl->val;
277472c1c6SStanimir Varbanov 		break;
287472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
297472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
303cd13671SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_VP9_LEVEL:
317472c1c6SStanimir Varbanov 		ctr->level = ctrl->val;
327472c1c6SStanimir Varbanov 		break;
338ec0b7b0SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY:
348ec0b7b0SStanimir Varbanov 		ctr->display_delay = ctrl->val;
358ec0b7b0SStanimir Varbanov 		break;
368ec0b7b0SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE:
378ec0b7b0SStanimir Varbanov 		ctr->display_delay_enable = ctrl->val;
388ec0b7b0SStanimir Varbanov 		break;
394ef6039fSStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR:
404ef6039fSStanimir Varbanov 		ctr->conceal_color = *ctrl->p_new.p_s64;
414ef6039fSStanimir Varbanov 		break;
427472c1c6SStanimir Varbanov 	default:
437472c1c6SStanimir Varbanov 		return -EINVAL;
447472c1c6SStanimir Varbanov 	}
457472c1c6SStanimir Varbanov 
467472c1c6SStanimir Varbanov 	return 0;
477472c1c6SStanimir Varbanov }
487472c1c6SStanimir Varbanov 
vdec_op_g_volatile_ctrl(struct v4l2_ctrl * ctrl)497472c1c6SStanimir Varbanov static int vdec_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
507472c1c6SStanimir Varbanov {
517472c1c6SStanimir Varbanov 	struct venus_inst *inst = ctrl_to_inst(ctrl);
527472c1c6SStanimir Varbanov 	struct vdec_controls *ctr = &inst->controls.dec;
53cef697d8SStanimir Varbanov 	struct hfi_buffer_requirements bufreq;
54cef697d8SStanimir Varbanov 	enum hfi_version ver = inst->core->res->hfi_version;
555a86626eSStanimir Varbanov 	u32 profile, level;
567472c1c6SStanimir Varbanov 	int ret;
577472c1c6SStanimir Varbanov 
587472c1c6SStanimir Varbanov 	switch (ctrl->id) {
597472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
607472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
615520b946SKeiichi Watanabe 	case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
623cd13671SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_VP9_PROFILE:
635a86626eSStanimir Varbanov 		ret = venus_helper_get_profile_level(inst, &profile, &level);
647472c1c6SStanimir Varbanov 		if (!ret)
655a86626eSStanimir Varbanov 			ctr->profile = profile;
667472c1c6SStanimir Varbanov 		ctrl->val = ctr->profile;
677472c1c6SStanimir Varbanov 		break;
687472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
697472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
703cd13671SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_VP9_LEVEL:
715a86626eSStanimir Varbanov 		ret = venus_helper_get_profile_level(inst, &profile, &level);
727472c1c6SStanimir Varbanov 		if (!ret)
735a86626eSStanimir Varbanov 			ctr->level = level;
747472c1c6SStanimir Varbanov 		ctrl->val = ctr->level;
757472c1c6SStanimir Varbanov 		break;
767472c1c6SStanimir Varbanov 	case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
777472c1c6SStanimir Varbanov 		ctrl->val = ctr->post_loop_deb_mode;
787472c1c6SStanimir Varbanov 		break;
79ebebc593SStanimir Varbanov 	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
80cef697d8SStanimir Varbanov 		ret = venus_helper_get_bufreq(inst, HFI_BUFFER_OUTPUT, &bufreq);
81cef697d8SStanimir Varbanov 		if (!ret)
82*bbfc89e6SKonrad Dybcio 			ctrl->val = hfi_bufreq_get_count_min(&bufreq, ver);
83ebebc593SStanimir Varbanov 		break;
847472c1c6SStanimir Varbanov 	default:
857472c1c6SStanimir Varbanov 		return -EINVAL;
86eb42ac1bSShobhit Kukreti 	}
877472c1c6SStanimir Varbanov 
887472c1c6SStanimir Varbanov 	return 0;
897472c1c6SStanimir Varbanov }
907472c1c6SStanimir Varbanov 
917472c1c6SStanimir Varbanov static const struct v4l2_ctrl_ops vdec_ctrl_ops = {
927472c1c6SStanimir Varbanov 	.s_ctrl = vdec_op_s_ctrl,
937472c1c6SStanimir Varbanov 	.g_volatile_ctrl = vdec_op_g_volatile_ctrl,
947472c1c6SStanimir Varbanov };
957472c1c6SStanimir Varbanov 
vdec_ctrl_init(struct venus_inst * inst)967472c1c6SStanimir Varbanov int vdec_ctrl_init(struct venus_inst *inst)
977472c1c6SStanimir Varbanov {
987472c1c6SStanimir Varbanov 	struct v4l2_ctrl *ctrl;
997472c1c6SStanimir Varbanov 	int ret;
1007472c1c6SStanimir Varbanov 
1014ef6039fSStanimir Varbanov 	ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 12);
1027472c1c6SStanimir Varbanov 	if (ret)
1037472c1c6SStanimir Varbanov 		return ret;
1047472c1c6SStanimir Varbanov 
1057472c1c6SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1067472c1c6SStanimir Varbanov 		V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE,
1077472c1c6SStanimir Varbanov 		V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY,
1087472c1c6SStanimir Varbanov 		~((1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE) |
1097472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE)),
1107472c1c6SStanimir Varbanov 		V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE);
1117472c1c6SStanimir Varbanov 	if (ctrl)
1127472c1c6SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1137472c1c6SStanimir Varbanov 
1147472c1c6SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1157472c1c6SStanimir Varbanov 				      V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL,
1167472c1c6SStanimir Varbanov 				      V4L2_MPEG_VIDEO_MPEG4_LEVEL_5,
1177472c1c6SStanimir Varbanov 				      0, V4L2_MPEG_VIDEO_MPEG4_LEVEL_0);
1187472c1c6SStanimir Varbanov 	if (ctrl)
1197472c1c6SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1207472c1c6SStanimir Varbanov 
1217472c1c6SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1227472c1c6SStanimir Varbanov 		V4L2_CID_MPEG_VIDEO_H264_PROFILE,
1237472c1c6SStanimir Varbanov 		V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH,
1247472c1c6SStanimir Varbanov 		~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
1257472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
1267472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
1277472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH) |
1287472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH) |
1297472c1c6SStanimir Varbanov 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH)),
1307472c1c6SStanimir Varbanov 		V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE);
1317472c1c6SStanimir Varbanov 	if (ctrl)
1327472c1c6SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1337472c1c6SStanimir Varbanov 
1347472c1c6SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1357472c1c6SStanimir Varbanov 				      V4L2_CID_MPEG_VIDEO_H264_LEVEL,
1367472c1c6SStanimir Varbanov 				      V4L2_MPEG_VIDEO_H264_LEVEL_5_1,
1377472c1c6SStanimir Varbanov 				      0, V4L2_MPEG_VIDEO_H264_LEVEL_1_0);
1387472c1c6SStanimir Varbanov 	if (ctrl)
1397472c1c6SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1407472c1c6SStanimir Varbanov 
1415520b946SKeiichi Watanabe 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1425520b946SKeiichi Watanabe 				      V4L2_CID_MPEG_VIDEO_VP8_PROFILE,
1435520b946SKeiichi Watanabe 				      V4L2_MPEG_VIDEO_VP8_PROFILE_3,
1445520b946SKeiichi Watanabe 				      0, V4L2_MPEG_VIDEO_VP8_PROFILE_0);
1457472c1c6SStanimir Varbanov 	if (ctrl)
1467472c1c6SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1477472c1c6SStanimir Varbanov 
1483cd13671SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1493cd13671SStanimir Varbanov 				      V4L2_CID_MPEG_VIDEO_VP9_PROFILE,
1503cd13671SStanimir Varbanov 				      V4L2_MPEG_VIDEO_VP9_PROFILE_3,
1513cd13671SStanimir Varbanov 				      0, V4L2_MPEG_VIDEO_VP9_PROFILE_0);
1523cd13671SStanimir Varbanov 	if (ctrl)
1533cd13671SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1543cd13671SStanimir Varbanov 
1553cd13671SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &vdec_ctrl_ops,
1563cd13671SStanimir Varbanov 				      V4L2_CID_MPEG_VIDEO_VP9_LEVEL,
1573cd13671SStanimir Varbanov 				      V4L2_MPEG_VIDEO_VP9_LEVEL_6_2,
1583cd13671SStanimir Varbanov 				      0, V4L2_MPEG_VIDEO_VP9_LEVEL_1_0);
1593cd13671SStanimir Varbanov 	if (ctrl)
1603cd13671SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
1613cd13671SStanimir Varbanov 
1627472c1c6SStanimir Varbanov 	v4l2_ctrl_new_std(&inst->ctrl_handler, &vdec_ctrl_ops,
1637472c1c6SStanimir Varbanov 		V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER, 0, 1, 1, 0);
1647472c1c6SStanimir Varbanov 
165ebebc593SStanimir Varbanov 	ctrl = v4l2_ctrl_new_std(&inst->ctrl_handler, &vdec_ctrl_ops,
166ebebc593SStanimir Varbanov 		V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 32, 1, 1);
167ebebc593SStanimir Varbanov 	if (ctrl)
168ebebc593SStanimir Varbanov 		ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
169ebebc593SStanimir Varbanov 
1708ec0b7b0SStanimir Varbanov 	v4l2_ctrl_new_std(&inst->ctrl_handler, &vdec_ctrl_ops,
1718ec0b7b0SStanimir Varbanov 			  V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY,
1728ec0b7b0SStanimir Varbanov 			  0, 16383, 1, 0);
1738ec0b7b0SStanimir Varbanov 
1748ec0b7b0SStanimir Varbanov 	v4l2_ctrl_new_std(&inst->ctrl_handler, &vdec_ctrl_ops,
1758ec0b7b0SStanimir Varbanov 			  V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE,
1768ec0b7b0SStanimir Varbanov 			  0, 1, 1, 0);
1778ec0b7b0SStanimir Varbanov 
1784ef6039fSStanimir Varbanov 	v4l2_ctrl_new_std(&inst->ctrl_handler, &vdec_ctrl_ops,
1794ef6039fSStanimir Varbanov 			  V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR, 0,
1804ef6039fSStanimir Varbanov 			  0xffffffffffffLL, 1, 0x8000800010LL);
1814ef6039fSStanimir Varbanov 
1827472c1c6SStanimir Varbanov 	ret = inst->ctrl_handler.error;
1837472c1c6SStanimir Varbanov 	if (ret) {
1847472c1c6SStanimir Varbanov 		v4l2_ctrl_handler_free(&inst->ctrl_handler);
1857472c1c6SStanimir Varbanov 		return ret;
1867472c1c6SStanimir Varbanov 	}
1877472c1c6SStanimir Varbanov 
1887472c1c6SStanimir Varbanov 	return 0;
1897472c1c6SStanimir Varbanov }
1907472c1c6SStanimir Varbanov 
vdec_ctrl_deinit(struct venus_inst * inst)1917472c1c6SStanimir Varbanov void vdec_ctrl_deinit(struct venus_inst *inst)
1927472c1c6SStanimir Varbanov {
1937472c1c6SStanimir Varbanov 	v4l2_ctrl_handler_free(&inst->ctrl_handler);
1947472c1c6SStanimir Varbanov }
195