Lines Matching +full:max +full:- +full:bitrate

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
12 #include <media/v4l2-mem2mem.h>
13 #include <media/videobuf2-dma-contig.h>
14 #include <media/v4l2-ioctl.h>
15 #include <media/v4l2-event.h>
16 #include <media/v4l2-ctrls.h>
30 * - the MPLANE formats allow only one plane to be used
31 * - the downstream driver use MPLANE formats too
32 * - future firmware versions could add support for >1 planes
142 strscpy(cap->driver, "qcom-venus", sizeof(cap->driver)); in venc_querycap()
143 strscpy(cap->card, "Qualcomm Venus video encoder", sizeof(cap->card)); in venc_querycap()
144 strscpy(cap->bus_info, "platform:qcom-venus", sizeof(cap->bus_info)); in venc_querycap()
154 fmt = find_format_by_index(inst, f->index, f->type); in venc_enum_fmt()
156 memset(f->reserved, 0, sizeof(f->reserved)); in venc_enum_fmt()
159 return -EINVAL; in venc_enum_fmt()
161 f->pixelformat = fmt->pixfmt; in venc_enum_fmt()
169 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_try_fmt_common()
170 struct v4l2_plane_pix_format *pfmt = pixmp->plane_fmt; in venc_try_fmt_common()
175 memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); in venc_try_fmt_common()
177 fmt = find_format(inst, pixmp->pixelformat, f->type); in venc_try_fmt_common()
179 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_try_fmt_common()
180 pixmp->pixelformat = V4L2_PIX_FMT_H264; in venc_try_fmt_common()
181 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
182 pixmp->pixelformat = V4L2_PIX_FMT_NV12; in venc_try_fmt_common()
185 fmt = find_format(inst, pixmp->pixelformat, f->type); in venc_try_fmt_common()
190 pixmp->width = clamp(pixmp->width, frame_width_min(inst), in venc_try_fmt_common()
192 pixmp->height = clamp(pixmp->height, frame_height_min(inst), in venc_try_fmt_common()
195 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_try_fmt_common()
196 pixmp->width = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
197 pixmp->height = ALIGN(pixmp->height, 32); in venc_try_fmt_common()
200 pixmp->width = ALIGN(pixmp->width, 2); in venc_try_fmt_common()
201 pixmp->height = ALIGN(pixmp->height, 2); in venc_try_fmt_common()
203 if (pixmp->field == V4L2_FIELD_ANY) in venc_try_fmt_common()
204 pixmp->field = V4L2_FIELD_NONE; in venc_try_fmt_common()
205 pixmp->num_planes = fmt->num_planes; in venc_try_fmt_common()
206 pixmp->flags = 0; in venc_try_fmt_common()
208 sizeimage = venus_helper_get_framesz(pixmp->pixelformat, in venc_try_fmt_common()
209 pixmp->width, in venc_try_fmt_common()
210 pixmp->height); in venc_try_fmt_common()
211 pfmt[0].sizeimage = max(ALIGN(pfmt[0].sizeimage, SZ_4K), sizeimage); in venc_try_fmt_common()
213 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
214 pfmt[0].bytesperline = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
233 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_s_fmt()
240 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); in venc_s_fmt()
242 return -EINVAL; in venc_s_fmt()
245 return -EBUSY; in venc_s_fmt()
251 return -EINVAL; in venc_s_fmt()
253 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
254 pixfmt_out = pixmp->pixelformat; in venc_s_fmt()
255 pixfmt_cap = inst->fmt_cap->pixfmt; in venc_s_fmt()
256 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
257 pixfmt_cap = pixmp->pixelformat; in venc_s_fmt()
258 pixfmt_out = inst->fmt_out->pixfmt; in venc_s_fmt()
269 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
270 inst->out_width = format.fmt.pix_mp.width; in venc_s_fmt()
271 inst->out_height = format.fmt.pix_mp.height; in venc_s_fmt()
272 inst->colorspace = pixmp->colorspace; in venc_s_fmt()
273 inst->ycbcr_enc = pixmp->ycbcr_enc; in venc_s_fmt()
274 inst->quantization = pixmp->quantization; in venc_s_fmt()
275 inst->xfer_func = pixmp->xfer_func; in venc_s_fmt()
286 inst->width = format.fmt.pix_mp.width; in venc_s_fmt()
287 inst->height = format.fmt.pix_mp.height; in venc_s_fmt()
289 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_fmt()
290 inst->fmt_out = fmt; in venc_s_fmt()
291 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
292 inst->fmt_cap = fmt; in venc_s_fmt()
293 inst->output_buf_size = pixmp->plane_fmt[0].sizeimage; in venc_s_fmt()
301 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_g_fmt()
305 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_g_fmt()
306 fmt = inst->fmt_cap; in venc_g_fmt()
307 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_fmt()
308 fmt = inst->fmt_out; in venc_g_fmt()
310 return -EINVAL; in venc_g_fmt()
312 pixmp->pixelformat = fmt->pixfmt; in venc_g_fmt()
314 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_g_fmt()
315 pixmp->width = inst->width; in venc_g_fmt()
316 pixmp->height = inst->height; in venc_g_fmt()
317 pixmp->colorspace = inst->colorspace; in venc_g_fmt()
318 pixmp->ycbcr_enc = inst->ycbcr_enc; in venc_g_fmt()
319 pixmp->quantization = inst->quantization; in venc_g_fmt()
320 pixmp->xfer_func = inst->xfer_func; in venc_g_fmt()
321 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_g_fmt()
322 pixmp->width = inst->out_width; in venc_g_fmt()
323 pixmp->height = inst->out_height; in venc_g_fmt()
336 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_g_selection()
337 return -EINVAL; in venc_g_selection()
339 switch (s->target) { in venc_g_selection()
342 s->r.width = inst->out_width; in venc_g_selection()
343 s->r.height = inst->out_height; in venc_g_selection()
346 s->r.width = inst->width; in venc_g_selection()
347 s->r.height = inst->height; in venc_g_selection()
350 return -EINVAL; in venc_g_selection()
353 s->r.top = 0; in venc_g_selection()
354 s->r.left = 0; in venc_g_selection()
364 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_s_selection()
365 return -EINVAL; in venc_s_selection()
367 if (s->r.width > inst->out_width || in venc_s_selection()
368 s->r.height > inst->out_height) in venc_s_selection()
369 return -EINVAL; in venc_s_selection()
371 s->r.width = ALIGN(s->r.width, 2); in venc_s_selection()
372 s->r.height = ALIGN(s->r.height, 2); in venc_s_selection()
374 switch (s->target) { in venc_s_selection()
376 s->r.top = 0; in venc_s_selection()
377 s->r.left = 0; in venc_s_selection()
378 inst->width = s->r.width; in venc_s_selection()
379 inst->height = s->r.height; in venc_s_selection()
382 return -EINVAL; in venc_s_selection()
391 struct v4l2_outputparm *out = &a->parm.output; in venc_s_parm()
392 struct v4l2_fract *timeperframe = &out->timeperframe; in venc_s_parm()
395 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_s_parm()
396 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_parm()
397 return -EINVAL; in venc_s_parm()
399 memset(out->reserved, 0, sizeof(out->reserved)); in venc_s_parm()
401 if (!timeperframe->denominator) in venc_s_parm()
402 timeperframe->denominator = inst->timeperframe.denominator; in venc_s_parm()
403 if (!timeperframe->numerator) in venc_s_parm()
404 timeperframe->numerator = inst->timeperframe.numerator; in venc_s_parm()
406 out->capability = V4L2_CAP_TIMEPERFRAME; in venc_s_parm()
408 us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; in venc_s_parm()
409 do_div(us_per_frame, timeperframe->denominator); in venc_s_parm()
412 return -EINVAL; in venc_s_parm()
417 inst->timeperframe = *timeperframe; in venc_s_parm()
418 inst->fps = fps; in venc_s_parm()
427 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_g_parm()
428 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_parm()
429 return -EINVAL; in venc_g_parm()
431 a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; in venc_g_parm()
432 a->parm.output.timeperframe = inst->timeperframe; in venc_g_parm()
443 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in venc_enum_framesizes()
445 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
448 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
451 return -EINVAL; in venc_enum_framesizes()
454 if (fsize->index) in venc_enum_framesizes()
455 return -EINVAL; in venc_enum_framesizes()
457 fsize->stepwise.min_width = frame_width_min(inst); in venc_enum_framesizes()
458 fsize->stepwise.max_width = frame_width_max(inst); in venc_enum_framesizes()
459 fsize->stepwise.step_width = frame_width_step(inst); in venc_enum_framesizes()
460 fsize->stepwise.min_height = frame_height_min(inst); in venc_enum_framesizes()
461 fsize->stepwise.max_height = frame_height_max(inst); in venc_enum_framesizes()
462 fsize->stepwise.step_height = frame_height_step(inst); in venc_enum_framesizes()
474 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; in venc_enum_frameintervals()
476 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
479 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
482 return -EINVAL; in venc_enum_frameintervals()
485 if (fival->index) in venc_enum_frameintervals()
486 return -EINVAL; in venc_enum_frameintervals()
488 if (!fival->width || !fival->height) in venc_enum_frameintervals()
489 return -EINVAL; in venc_enum_frameintervals()
491 if (fival->width > frame_width_max(inst) || in venc_enum_frameintervals()
492 fival->width < frame_width_min(inst) || in venc_enum_frameintervals()
493 fival->height > frame_height_max(inst) || in venc_enum_frameintervals()
494 fival->height < frame_height_min(inst)) in venc_enum_frameintervals()
495 return -EINVAL; in venc_enum_frameintervals()
497 if (IS_V1(inst->core)) { in venc_enum_frameintervals()
502 fival->stepwise.min.numerator = 1; in venc_enum_frameintervals()
503 fival->stepwise.min.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
504 fival->stepwise.max.numerator = 1; in venc_enum_frameintervals()
505 fival->stepwise.max.denominator = frate_min(inst) / framerate_factor; in venc_enum_frameintervals()
506 fival->stepwise.step.numerator = 1; in venc_enum_frameintervals()
507 fival->stepwise.step.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
543 struct venc_controls *ctr = &inst->controls.enc; in venc_set_properties()
553 u32 ptype, rate_control, bitrate; in venc_set_properties() local
563 frate.framerate = inst->fps * (1 << 16); in venc_set_properties()
569 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { in venc_set_properties()
587 ctr->h264_entropy_mode); in venc_set_properties()
597 ctr->h264_loop_filter_mode); in venc_set_properties()
598 deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; in venc_set_properties()
599 deblock.slice_beta_offset = ctr->h264_loop_filter_beta; in venc_set_properties()
607 if (ctr->profile.h264 == HFI_H264_PROFILE_HIGH || in venc_set_properties()
608 ctr->profile.h264 == HFI_H264_PROFILE_CONSTRAINED_HIGH) in venc_set_properties()
609 h264_transform.enable_type = ctr->h264_8x8_transform; in venc_set_properties()
617 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
618 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
620 * n = 0 - only the first I-frame is IDR frame in venc_set_properties()
621 * n = 1 - all I-frames will be IDR frames in venc_set_properties()
622 * n > 1 - every n-th I-frame will be IDR frame in venc_set_properties()
631 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
639 ctr->mastering.display_primaries_x[c]; in venc_set_properties()
641 ctr->mastering.display_primaries_y[c]; in venc_set_properties()
644 hdr10.mastering.white_point_x = ctr->mastering.white_point_x; in venc_set_properties()
645 hdr10.mastering.white_point_y = ctr->mastering.white_point_y; in venc_set_properties()
647 ctr->mastering.max_display_mastering_luminance; in venc_set_properties()
649 ctr->mastering.min_display_mastering_luminance; in venc_set_properties()
651 hdr10.cll.max_content_light = ctr->cll.max_content_light_level; in venc_set_properties()
653 ctr->cll.max_pic_average_light_level; in venc_set_properties()
660 if (ctr->num_b_frames) { in venc_set_properties()
670 intra_period.pframes = ctr->num_p_frames; in venc_set_properties()
671 intra_period.bframes = ctr->num_b_frames; in venc_set_properties()
677 if (!ctr->rc_enable) in venc_set_properties()
679 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) in venc_set_properties()
680 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : in venc_set_properties()
682 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) in venc_set_properties()
683 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : in venc_set_properties()
685 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) in venc_set_properties()
693 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { in venc_set_properties()
697 quality.frame_quality = ctr->const_quality; in venc_set_properties()
703 if (!ctr->bitrate) in venc_set_properties()
704 bitrate = 64000; in venc_set_properties()
706 bitrate = ctr->bitrate; in venc_set_properties()
709 brate.bitrate = bitrate; in venc_set_properties()
716 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
717 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
719 if (ctr->header_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) in venc_set_properties()
729 if (!ctr->bitrate_peak) in venc_set_properties()
730 bitrate *= 2; in venc_set_properties()
732 bitrate = ctr->bitrate_peak; in venc_set_properties()
735 brate.bitrate = bitrate; in venc_set_properties()
743 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
744 quant.qp_i = ctr->hevc_i_qp; in venc_set_properties()
745 quant.qp_p = ctr->hevc_p_qp; in venc_set_properties()
746 quant.qp_b = ctr->hevc_b_qp; in venc_set_properties()
748 quant.qp_i = ctr->h264_i_qp; in venc_set_properties()
749 quant.qp_p = ctr->h264_p_qp; in venc_set_properties()
750 quant.qp_b = ctr->h264_b_qp; in venc_set_properties()
758 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
759 quant_range.min_qp = ctr->hevc_min_qp; in venc_set_properties()
760 quant_range.max_qp = ctr->hevc_max_qp; in venc_set_properties()
762 quant_range.min_qp = ctr->h264_min_qp; in venc_set_properties()
763 quant_range.max_qp = ctr->h264_max_qp; in venc_set_properties()
771 ltr_mode.ltr_count = ctr->ltr_count; in venc_set_properties()
778 switch (inst->hfi_codec) { in venc_set_properties()
780 profile = ctr->profile.h264; in venc_set_properties()
781 level = ctr->level.h264; in venc_set_properties()
784 profile = ctr->profile.mpeg4; in venc_set_properties()
785 level = ctr->level.mpeg4; in venc_set_properties()
788 profile = ctr->profile.vp8; in venc_set_properties()
792 profile = ctr->profile.vp9; in venc_set_properties()
793 level = ctr->level.vp9; in venc_set_properties()
796 profile = ctr->profile.hevc; in venc_set_properties()
797 level = ctr->level.hevc; in venc_set_properties()
810 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
811 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
816 if (ctr->aud_enable) in venc_set_properties()
822 if ((inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
823 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) && in venc_set_properties()
829 if (ctr->intra_refresh_period) { in venc_set_properties()
832 mbs = ALIGN(inst->width, 16) * ALIGN(inst->height, 16); in venc_set_properties()
834 if (mbs % ctr->intra_refresh_period) in venc_set_properties()
836 mbs /= ctr->intra_refresh_period; in venc_set_properties()
857 if (ret == -EALREADY) in venc_init_session()
862 ret = venus_helper_set_stride(inst, inst->out_width, in venc_init_session()
863 inst->out_height); in venc_init_session()
867 ret = venus_helper_set_input_resolution(inst, inst->width, in venc_init_session()
868 inst->height); in venc_init_session()
872 ret = venus_helper_set_output_resolution(inst, inst->width, in venc_init_session()
873 inst->height, in venc_init_session()
878 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); in venc_init_session()
915 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
916 *num_planes != inst->fmt_out->num_planes) in venc_queue_setup()
917 return -EINVAL; in venc_queue_setup()
919 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
920 *num_planes != inst->fmt_cap->num_planes) in venc_queue_setup()
921 return -EINVAL; in venc_queue_setup()
923 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
924 sizes[0] < inst->input_buf_size) in venc_queue_setup()
925 return -EINVAL; in venc_queue_setup()
927 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
928 sizes[0] < inst->output_buf_size) in venc_queue_setup()
929 return -EINVAL; in venc_queue_setup()
934 mutex_lock(&inst->lock); in venc_queue_setup()
936 mutex_unlock(&inst->lock); in venc_queue_setup()
941 switch (q->type) { in venc_queue_setup()
943 *num_planes = inst->fmt_out->num_planes; in venc_queue_setup()
949 num = max(num, min); in venc_queue_setup()
950 *num_buffers = max(*num_buffers, num); in venc_queue_setup()
951 inst->num_input_bufs = *num_buffers; in venc_queue_setup()
953 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in venc_queue_setup()
954 inst->out_width, in venc_queue_setup()
955 inst->out_height); in venc_queue_setup()
956 inst->input_buf_size = sizes[0]; in venc_queue_setup()
959 *num_planes = inst->fmt_cap->num_planes; in venc_queue_setup()
960 *num_buffers = max(*num_buffers, min); in venc_queue_setup()
961 inst->num_output_bufs = *num_buffers; in venc_queue_setup()
962 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in venc_queue_setup()
963 inst->width, in venc_queue_setup()
964 inst->height); in venc_queue_setup()
965 sizes[0] = max(sizes[0], inst->output_buf_size); in venc_queue_setup()
966 inst->output_buf_size = sizes[0]; in venc_queue_setup()
969 ret = -EINVAL; in venc_queue_setup()
978 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_init()
980 inst->buf_count++; in venc_buf_init()
989 mutex_lock(&inst->lock); in venc_release_session()
992 if (ret || inst->session_error) in venc_release_session()
995 mutex_unlock(&inst->lock); in venc_release_session()
998 INIT_LIST_HEAD(&inst->registeredbufs); in venc_release_session()
1004 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_cleanup()
1008 mutex_lock(&inst->lock); in venc_buf_cleanup()
1009 if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_buf_cleanup()
1010 if (!list_empty(&inst->registeredbufs)) in venc_buf_cleanup()
1011 list_del_init(&buf->reg_list); in venc_buf_cleanup()
1012 mutex_unlock(&inst->lock); in venc_buf_cleanup()
1014 inst->buf_count--; in venc_buf_cleanup()
1015 if (!inst->buf_count) in venc_buf_cleanup()
1021 enum hfi_version ver = inst->core->res->hfi_version; in venc_verify_conf()
1025 if (!inst->num_input_bufs || !inst->num_output_bufs) in venc_verify_conf()
1026 return -EINVAL; in venc_verify_conf()
1032 if (inst->num_output_bufs < bufreq.count_actual || in venc_verify_conf()
1033 inst->num_output_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
1034 return -EINVAL; in venc_verify_conf()
1040 if (inst->num_input_bufs < bufreq.count_actual || in venc_verify_conf()
1041 inst->num_input_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
1042 return -EINVAL; in venc_verify_conf()
1052 mutex_lock(&inst->lock); in venc_start_streaming()
1054 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1055 inst->streamon_out = 1; in venc_start_streaming()
1057 inst->streamon_cap = 1; in venc_start_streaming()
1059 if (!(inst->streamon_out & inst->streamon_cap)) { in venc_start_streaming()
1060 mutex_unlock(&inst->lock); in venc_start_streaming()
1066 inst->sequence_cap = 0; in venc_start_streaming()
1067 inst->sequence_out = 0; in venc_start_streaming()
1081 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in venc_start_streaming()
1082 inst->num_output_bufs, 0); in venc_start_streaming()
1090 mutex_unlock(&inst->lock); in venc_start_streaming()
1095 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in venc_start_streaming()
1096 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1097 inst->streamon_out = 0; in venc_start_streaming()
1099 inst->streamon_cap = 0; in venc_start_streaming()
1100 mutex_unlock(&inst->lock); in venc_start_streaming()
1106 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_vb2_buf_queue()
1108 mutex_lock(&inst->lock); in venc_vb2_buf_queue()
1110 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1140 vbuf->flags = flags; in venc_buf_done()
1143 vb = &vbuf->vb2_buf; in venc_buf_done()
1145 vb->planes[0].data_offset = data_offset; in venc_buf_done()
1146 vb->timestamp = timestamp_us * NSEC_PER_USEC; in venc_buf_done()
1147 vbuf->sequence = inst->sequence_cap++; in venc_buf_done()
1149 vbuf->sequence = inst->sequence_out++; in venc_buf_done()
1158 struct device *dev = inst->core->dev_enc; in venc_event_notify()
1161 inst->session_error = true; in venc_event_notify()
1162 dev_err(dev, "enc: event session error %x\n", inst->error); in venc_event_notify()
1182 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in m2m_queue_init()
1183 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1184 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1185 src_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1186 src_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1187 src_vq->drv_priv = inst; in m2m_queue_init()
1188 src_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1189 src_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1190 src_vq->min_buffers_needed = 1; in m2m_queue_init()
1191 src_vq->dev = inst->core->dev; in m2m_queue_init()
1192 if (inst->core->res->hfi_version == HFI_VERSION_1XX) in m2m_queue_init()
1193 src_vq->bidirectional = 1; in m2m_queue_init()
1198 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in m2m_queue_init()
1199 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1200 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1201 dst_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1202 dst_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1203 dst_vq->drv_priv = inst; in m2m_queue_init()
1204 dst_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1205 dst_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1206 dst_vq->min_buffers_needed = 1; in m2m_queue_init()
1207 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1213 inst->fmt_cap = &venc_formats[3]; in venc_inst_init()
1214 inst->fmt_out = &venc_formats[0]; in venc_inst_init()
1215 inst->width = 1280; in venc_inst_init()
1216 inst->height = ALIGN(720, 32); in venc_inst_init()
1217 inst->out_width = 1280; in venc_inst_init()
1218 inst->out_height = 720; in venc_inst_init()
1219 inst->fps = 15; in venc_inst_init()
1220 inst->timeperframe.numerator = 1; in venc_inst_init()
1221 inst->timeperframe.denominator = 15; in venc_inst_init()
1222 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in venc_inst_init()
1233 return -ENOMEM; in venc_open()
1235 INIT_LIST_HEAD(&inst->dpbbufs); in venc_open()
1236 INIT_LIST_HEAD(&inst->registeredbufs); in venc_open()
1237 INIT_LIST_HEAD(&inst->internalbufs); in venc_open()
1238 INIT_LIST_HEAD(&inst->list); in venc_open()
1239 mutex_init(&inst->lock); in venc_open()
1241 inst->core = core; in venc_open()
1242 inst->session_type = VIDC_SESSION_TYPE_ENC; in venc_open()
1243 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in venc_open()
1244 inst->core_acquired = false; in venc_open()
1248 ret = pm_runtime_resume_and_get(core->dev_enc); in venc_open()
1266 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); in venc_open()
1267 if (IS_ERR(inst->m2m_dev)) { in venc_open()
1268 ret = PTR_ERR(inst->m2m_dev); in venc_open()
1272 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in venc_open()
1273 if (IS_ERR(inst->m2m_ctx)) { in venc_open()
1274 ret = PTR_ERR(inst->m2m_ctx); in venc_open()
1278 v4l2_fh_init(&inst->fh, core->vdev_enc); in venc_open()
1280 inst->fh.ctrl_handler = &inst->ctrl_handler; in venc_open()
1281 v4l2_fh_add(&inst->fh); in venc_open()
1282 inst->fh.m2m_ctx = inst->m2m_ctx; in venc_open()
1283 file->private_data = &inst->fh; in venc_open()
1288 v4l2_m2m_release(inst->m2m_dev); in venc_open()
1294 pm_runtime_put_sync(core->dev_enc); in venc_open()
1304 v4l2_m2m_ctx_release(inst->m2m_ctx); in venc_close()
1305 v4l2_m2m_release(inst->m2m_dev); in venc_close()
1308 mutex_destroy(&inst->lock); in venc_close()
1309 v4l2_fh_del(&inst->fh); in venc_close()
1310 v4l2_fh_exit(&inst->fh); in venc_close()
1312 pm_runtime_put_sync(inst->core->dev_enc); in venc_close()
1329 struct device *dev = &pdev->dev; in venc_probe()
1334 if (!dev->parent) in venc_probe()
1335 return -EPROBE_DEFER; in venc_probe()
1337 core = dev_get_drvdata(dev->parent); in venc_probe()
1339 return -EPROBE_DEFER; in venc_probe()
1343 if (core->pm_ops->venc_get) { in venc_probe()
1344 ret = core->pm_ops->venc_get(dev); in venc_probe()
1351 return -ENOMEM; in venc_probe()
1353 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); in venc_probe()
1354 vdev->release = video_device_release; in venc_probe()
1355 vdev->fops = &venc_fops; in venc_probe()
1356 vdev->ioctl_ops = &venc_ioctl_ops; in venc_probe()
1357 vdev->vfl_dir = VFL_DIR_M2M; in venc_probe()
1358 vdev->v4l2_dev = &core->v4l2_dev; in venc_probe()
1359 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; in venc_probe()
1361 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in venc_probe()
1365 core->vdev_enc = vdev; in venc_probe()
1366 core->dev_enc = dev; in venc_probe()
1380 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); in venc_remove()
1382 video_unregister_device(core->vdev_enc); in venc_remove()
1383 pm_runtime_disable(core->dev_enc); in venc_remove()
1385 if (core->pm_ops->venc_put) in venc_remove()
1386 core->pm_ops->venc_put(core->dev_enc); in venc_remove()
1394 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_suspend()
1397 if (pm_ops->venc_power) in venc_runtime_suspend()
1398 ret = pm_ops->venc_power(dev, POWER_OFF); in venc_runtime_suspend()
1406 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_resume()
1409 if (pm_ops->venc_power) in venc_runtime_resume()
1410 ret = pm_ops->venc_power(dev, POWER_ON); in venc_runtime_resume()
1422 { .compatible = "venus-encoder" },
1431 .name = "qcom-venus-encoder",
1438 MODULE_ALIAS("platform:qcom-venus-encoder");