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
147 strscpy(cap->driver, "qcom-venus", sizeof(cap->driver)); in venc_querycap()
148 strscpy(cap->card, "Qualcomm Venus video encoder", sizeof(cap->card)); in venc_querycap()
149 strscpy(cap->bus_info, "platform:qcom-venus", sizeof(cap->bus_info)); in venc_querycap()
159 fmt = find_format_by_index(inst, f->index, f->type); in venc_enum_fmt()
161 memset(f->reserved, 0, sizeof(f->reserved)); in venc_enum_fmt()
164 return -EINVAL; in venc_enum_fmt()
166 f->pixelformat = fmt->pixfmt; in venc_enum_fmt()
174 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_try_fmt_common()
175 struct v4l2_plane_pix_format *pfmt = pixmp->plane_fmt; in venc_try_fmt_common()
180 memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); in venc_try_fmt_common()
182 fmt = find_format(inst, pixmp->pixelformat, f->type); in venc_try_fmt_common()
184 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_try_fmt_common()
185 pixmp->pixelformat = V4L2_PIX_FMT_H264; in venc_try_fmt_common()
186 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
187 pixmp->pixelformat = V4L2_PIX_FMT_NV12; in venc_try_fmt_common()
190 fmt = find_format(inst, pixmp->pixelformat, f->type); in venc_try_fmt_common()
195 pixmp->width = clamp(pixmp->width, frame_width_min(inst), in venc_try_fmt_common()
197 pixmp->height = clamp(pixmp->height, frame_height_min(inst), in venc_try_fmt_common()
200 pixmp->width = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
201 pixmp->height = ALIGN(pixmp->height, 32); in venc_try_fmt_common()
203 pixmp->width = ALIGN(pixmp->width, 2); in venc_try_fmt_common()
204 pixmp->height = ALIGN(pixmp->height, 2); in venc_try_fmt_common()
206 if (pixmp->field == V4L2_FIELD_ANY) in venc_try_fmt_common()
207 pixmp->field = V4L2_FIELD_NONE; in venc_try_fmt_common()
208 pixmp->num_planes = fmt->num_planes; in venc_try_fmt_common()
209 pixmp->flags = 0; in venc_try_fmt_common()
211 sizeimage = venus_helper_get_framesz(pixmp->pixelformat, in venc_try_fmt_common()
212 pixmp->width, in venc_try_fmt_common()
213 pixmp->height); in venc_try_fmt_common()
214 pfmt[0].sizeimage = max(ALIGN(pfmt[0].sizeimage, SZ_4K), sizeimage); in venc_try_fmt_common()
216 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
217 pfmt[0].bytesperline = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
236 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_s_fmt()
243 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); in venc_s_fmt()
245 return -EINVAL; in venc_s_fmt()
248 return -EBUSY; in venc_s_fmt()
254 return -EINVAL; in venc_s_fmt()
256 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
257 pixfmt_out = pixmp->pixelformat; in venc_s_fmt()
258 pixfmt_cap = inst->fmt_cap->pixfmt; in venc_s_fmt()
259 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
260 pixfmt_cap = pixmp->pixelformat; in venc_s_fmt()
261 pixfmt_out = inst->fmt_out->pixfmt; in venc_s_fmt()
272 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
273 inst->out_width = format.fmt.pix_mp.width; in venc_s_fmt()
274 inst->out_height = format.fmt.pix_mp.height; in venc_s_fmt()
275 inst->colorspace = pixmp->colorspace; in venc_s_fmt()
276 inst->ycbcr_enc = pixmp->ycbcr_enc; in venc_s_fmt()
277 inst->quantization = pixmp->quantization; in venc_s_fmt()
278 inst->xfer_func = pixmp->xfer_func; in venc_s_fmt()
289 inst->width = format.fmt.pix_mp.width; in venc_s_fmt()
290 inst->height = format.fmt.pix_mp.height; in venc_s_fmt()
292 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_fmt()
293 inst->fmt_out = fmt; in venc_s_fmt()
294 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
295 inst->fmt_cap = fmt; in venc_s_fmt()
296 inst->output_buf_size = pixmp->plane_fmt[0].sizeimage; in venc_s_fmt()
304 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_g_fmt()
308 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_g_fmt()
309 fmt = inst->fmt_cap; in venc_g_fmt()
310 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_fmt()
311 fmt = inst->fmt_out; in venc_g_fmt()
313 return -EINVAL; in venc_g_fmt()
315 pixmp->pixelformat = fmt->pixfmt; in venc_g_fmt()
317 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_g_fmt()
318 pixmp->width = inst->width; in venc_g_fmt()
319 pixmp->height = inst->height; in venc_g_fmt()
320 pixmp->colorspace = inst->colorspace; in venc_g_fmt()
321 pixmp->ycbcr_enc = inst->ycbcr_enc; in venc_g_fmt()
322 pixmp->quantization = inst->quantization; in venc_g_fmt()
323 pixmp->xfer_func = inst->xfer_func; in venc_g_fmt()
324 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_g_fmt()
325 pixmp->width = inst->out_width; in venc_g_fmt()
326 pixmp->height = inst->out_height; in venc_g_fmt()
339 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_g_selection()
340 return -EINVAL; in venc_g_selection()
342 switch (s->target) { in venc_g_selection()
345 s->r.width = inst->out_width; in venc_g_selection()
346 s->r.height = inst->out_height; in venc_g_selection()
349 s->r.width = inst->width; in venc_g_selection()
350 s->r.height = inst->height; in venc_g_selection()
353 return -EINVAL; in venc_g_selection()
356 s->r.top = 0; in venc_g_selection()
357 s->r.left = 0; in venc_g_selection()
367 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_s_selection()
368 return -EINVAL; in venc_s_selection()
370 if (s->r.width > inst->out_width || in venc_s_selection()
371 s->r.height > inst->out_height) in venc_s_selection()
372 return -EINVAL; in venc_s_selection()
374 s->r.width = ALIGN(s->r.width, 2); in venc_s_selection()
375 s->r.height = ALIGN(s->r.height, 2); in venc_s_selection()
377 switch (s->target) { in venc_s_selection()
379 s->r.top = 0; in venc_s_selection()
380 s->r.left = 0; in venc_s_selection()
381 inst->width = s->r.width; in venc_s_selection()
382 inst->height = s->r.height; in venc_s_selection()
385 return -EINVAL; in venc_s_selection()
394 struct v4l2_outputparm *out = &a->parm.output; in venc_s_parm()
395 struct v4l2_fract *timeperframe = &out->timeperframe; in venc_s_parm()
398 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && in venc_s_parm()
399 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_parm()
400 return -EINVAL; in venc_s_parm()
402 memset(out->reserved, 0, sizeof(out->reserved)); in venc_s_parm()
404 if (!timeperframe->denominator) in venc_s_parm()
405 timeperframe->denominator = inst->timeperframe.denominator; in venc_s_parm()
406 if (!timeperframe->numerator) in venc_s_parm()
407 timeperframe->numerator = inst->timeperframe.numerator; in venc_s_parm()
409 out->capability = V4L2_CAP_TIMEPERFRAME; in venc_s_parm()
411 us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; in venc_s_parm()
412 do_div(us_per_frame, timeperframe->denominator); in venc_s_parm()
415 return -EINVAL; in venc_s_parm()
420 inst->timeperframe = *timeperframe; in venc_s_parm()
421 inst->fps = fps; in venc_s_parm()
430 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && in venc_g_parm()
431 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_parm()
432 return -EINVAL; in venc_g_parm()
434 a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; in venc_g_parm()
435 a->parm.output.timeperframe = inst->timeperframe; in venc_g_parm()
446 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in venc_enum_framesizes()
448 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
451 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
454 return -EINVAL; in venc_enum_framesizes()
457 if (fsize->index) in venc_enum_framesizes()
458 return -EINVAL; in venc_enum_framesizes()
460 fsize->stepwise.min_width = frame_width_min(inst); in venc_enum_framesizes()
461 fsize->stepwise.max_width = frame_width_max(inst); in venc_enum_framesizes()
462 fsize->stepwise.step_width = frame_width_step(inst); in venc_enum_framesizes()
463 fsize->stepwise.min_height = frame_height_min(inst); in venc_enum_framesizes()
464 fsize->stepwise.max_height = frame_height_max(inst); in venc_enum_framesizes()
465 fsize->stepwise.step_height = frame_height_step(inst); in venc_enum_framesizes()
477 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; in venc_enum_frameintervals()
479 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
482 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
485 return -EINVAL; in venc_enum_frameintervals()
488 if (fival->index) in venc_enum_frameintervals()
489 return -EINVAL; in venc_enum_frameintervals()
491 if (!fival->width || !fival->height) in venc_enum_frameintervals()
492 return -EINVAL; in venc_enum_frameintervals()
494 if (fival->width > frame_width_max(inst) || in venc_enum_frameintervals()
495 fival->width < frame_width_min(inst) || in venc_enum_frameintervals()
496 fival->height > frame_height_max(inst) || in venc_enum_frameintervals()
497 fival->height < frame_height_min(inst)) in venc_enum_frameintervals()
498 return -EINVAL; in venc_enum_frameintervals()
500 if (IS_V1(inst->core)) { in venc_enum_frameintervals()
505 fival->stepwise.min.numerator = 1; in venc_enum_frameintervals()
506 fival->stepwise.min.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
507 fival->stepwise.max.numerator = 1; in venc_enum_frameintervals()
508 fival->stepwise.max.denominator = frate_min(inst) / framerate_factor; in venc_enum_frameintervals()
509 fival->stepwise.step.numerator = 1; in venc_enum_frameintervals()
510 fival->stepwise.step.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
518 switch (sub->type) { in venc_subscribe_event()
524 return -EINVAL; in venc_subscribe_event()
539 mutex_lock(&inst->lock); in venc_encoder_cmd()
541 if (cmd->cmd == V4L2_ENC_CMD_STOP && in venc_encoder_cmd()
542 inst->enc_state == VENUS_ENC_STATE_ENCODING) { in venc_encoder_cmd()
547 if (!(inst->streamon_out && inst->streamon_cap)) in venc_encoder_cmd()
556 inst->enc_state = VENUS_ENC_STATE_DRAIN; in venc_encoder_cmd()
557 } else if (cmd->cmd == V4L2_ENC_CMD_START) { in venc_encoder_cmd()
558 if (inst->enc_state == VENUS_ENC_STATE_DRAIN) { in venc_encoder_cmd()
559 ret = -EBUSY; in venc_encoder_cmd()
562 if (inst->enc_state == VENUS_ENC_STATE_STOPPED) { in venc_encoder_cmd()
563 vb2_clear_last_buffer_dequeued(&inst->fh.m2m_ctx->cap_q_ctx.q); in venc_encoder_cmd()
564 inst->enc_state = VENUS_ENC_STATE_ENCODING; in venc_encoder_cmd()
569 mutex_unlock(&inst->lock); in venc_encoder_cmd()
606 struct venus_core *core = inst->core; in venc_pm_get()
607 struct device *dev = core->dev_enc; in venc_pm_get()
610 mutex_lock(&core->pm_lock); in venc_pm_get()
612 mutex_unlock(&core->pm_lock); in venc_pm_get()
619 struct venus_core *core = inst->core; in venc_pm_put()
620 struct device *dev = core->dev_enc; in venc_pm_put()
623 mutex_lock(&core->pm_lock); in venc_pm_put()
630 mutex_unlock(&core->pm_lock); in venc_pm_put()
637 struct venus_core *core = inst->core; in venc_pm_get_put()
638 struct device *dev = core->dev_enc; in venc_pm_get_put()
641 mutex_lock(&core->pm_lock); in venc_pm_get_put()
652 mutex_unlock(&core->pm_lock); in venc_pm_get_put()
659 pm_runtime_mark_last_busy(inst->core->dev_enc); in venc_pm_touch()
664 struct venc_controls *ctr = &inst->controls.enc; in venc_set_properties()
675 u32 ptype, rate_control, bitrate; in venc_set_properties() local
685 frate.framerate = inst->fps * (1 << 16); in venc_set_properties()
691 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { in venc_set_properties()
709 ctr->h264_entropy_mode); in venc_set_properties()
719 ctr->h264_loop_filter_mode); in venc_set_properties()
720 deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; in venc_set_properties()
721 deblock.slice_beta_offset = ctr->h264_loop_filter_beta; in venc_set_properties()
729 if (ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_HIGH || in venc_set_properties()
730 ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH) in venc_set_properties()
731 h264_transform.enable_type = ctr->h264_8x8_transform; in venc_set_properties()
737 if (ctr->layer_bitrate) { in venc_set_properties()
741 ret = hfi_session_set_property(inst, ptype, &ctr->h264_hier_layers); in venc_set_properties()
746 ret = hfi_session_set_property(inst, ptype, &ctr->layer_bitrate); in venc_set_properties()
750 for (i = 0; i < ctr->h264_hier_layers; ++i) { in venc_set_properties()
752 brate.bitrate = ctr->h264_hier_layer_bitrate[i]; in venc_set_properties()
762 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
763 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
765 * n = 0 - only the first I-frame is IDR frame in venc_set_properties()
766 * n = 1 - all I-frames will be IDR frames in venc_set_properties()
767 * n > 1 - every n-th I-frame will be IDR frame in venc_set_properties()
776 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC && in venc_set_properties()
777 ctr->profile.hevc == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10) { in venc_set_properties()
785 ctr->mastering.display_primaries_x[c]; in venc_set_properties()
787 ctr->mastering.display_primaries_y[c]; in venc_set_properties()
790 hdr10.mastering.white_point_x = ctr->mastering.white_point_x; in venc_set_properties()
791 hdr10.mastering.white_point_y = ctr->mastering.white_point_y; in venc_set_properties()
793 ctr->mastering.max_display_mastering_luminance; in venc_set_properties()
795 ctr->mastering.min_display_mastering_luminance; in venc_set_properties()
797 hdr10.cll.max_content_light = ctr->cll.max_content_light_level; in venc_set_properties()
799 ctr->cll.max_pic_average_light_level; in venc_set_properties()
806 if (ctr->num_b_frames) { in venc_set_properties()
816 intra_period.pframes = ctr->num_p_frames; in venc_set_properties()
817 intra_period.bframes = ctr->num_b_frames; in venc_set_properties()
823 if (!ctr->rc_enable) in venc_set_properties()
825 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) in venc_set_properties()
826 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : in venc_set_properties()
828 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) in venc_set_properties()
829 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : in venc_set_properties()
831 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) in venc_set_properties()
839 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { in venc_set_properties()
843 quality.frame_quality = ctr->const_quality; in venc_set_properties()
849 if (!ctr->layer_bitrate) { in venc_set_properties()
850 if (!ctr->bitrate) in venc_set_properties()
851 bitrate = 64000; in venc_set_properties()
853 bitrate = ctr->bitrate; in venc_set_properties()
856 brate.bitrate = bitrate; in venc_set_properties()
863 if (!ctr->bitrate_peak) in venc_set_properties()
864 bitrate *= 2; in venc_set_properties()
866 bitrate = ctr->bitrate_peak; in venc_set_properties()
869 brate.bitrate = bitrate; in venc_set_properties()
877 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
878 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
880 if (ctr->header_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) in venc_set_properties()
891 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
892 quant.qp_i = ctr->hevc_i_qp; in venc_set_properties()
893 quant.qp_p = ctr->hevc_p_qp; in venc_set_properties()
894 quant.qp_b = ctr->hevc_b_qp; in venc_set_properties()
896 quant.qp_i = ctr->h264_i_qp; in venc_set_properties()
897 quant.qp_p = ctr->h264_p_qp; in venc_set_properties()
898 quant.qp_b = ctr->h264_b_qp; in venc_set_properties()
905 if (inst->core->res->hfi_version == HFI_VERSION_4XX || in venc_set_properties()
906 inst->core->res->hfi_version == HFI_VERSION_6XX) { in venc_set_properties()
909 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
910 quant_range_v2.min_qp.qp_packed = ctr->hevc_min_qp; in venc_set_properties()
911 quant_range_v2.max_qp.qp_packed = ctr->hevc_max_qp; in venc_set_properties()
912 } else if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_VP8) { in venc_set_properties()
913 quant_range_v2.min_qp.qp_packed = ctr->vp8_min_qp; in venc_set_properties()
914 quant_range_v2.max_qp.qp_packed = ctr->vp8_max_qp; in venc_set_properties()
916 quant_range_v2.min_qp.qp_packed = ctr->h264_min_qp; in venc_set_properties()
917 quant_range_v2.max_qp.qp_packed = ctr->h264_max_qp; in venc_set_properties()
924 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
925 quant_range.min_qp = ctr->hevc_min_qp; in venc_set_properties()
926 quant_range.max_qp = ctr->hevc_max_qp; in venc_set_properties()
927 } else if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_VP8) { in venc_set_properties()
928 quant_range.min_qp = ctr->vp8_min_qp; in venc_set_properties()
929 quant_range.max_qp = ctr->vp8_max_qp; in venc_set_properties()
931 quant_range.min_qp = ctr->h264_min_qp; in venc_set_properties()
932 quant_range.max_qp = ctr->h264_max_qp; in venc_set_properties()
943 ltr_mode.ltr_count = ctr->ltr_count; in venc_set_properties()
950 switch (inst->hfi_codec) { in venc_set_properties()
952 profile = ctr->profile.h264; in venc_set_properties()
953 level = ctr->level.h264; in venc_set_properties()
956 profile = ctr->profile.mpeg4; in venc_set_properties()
957 level = ctr->level.mpeg4; in venc_set_properties()
960 profile = ctr->profile.vp8; in venc_set_properties()
964 profile = ctr->profile.vp9; in venc_set_properties()
965 level = ctr->level.vp9; in venc_set_properties()
968 profile = ctr->profile.hevc; in venc_set_properties()
969 level = ctr->level.hevc; in venc_set_properties()
982 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
983 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
988 if (ctr->aud_enable) in venc_set_properties()
994 if ((inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
995 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) && in venc_set_properties()
1001 if (ctr->intra_refresh_period) { in venc_set_properties()
1004 mbs = ALIGN(inst->width, 16) * ALIGN(inst->height, 16); in venc_set_properties()
1006 if (mbs % ctr->intra_refresh_period) in venc_set_properties()
1008 mbs /= ctr->intra_refresh_period; in venc_set_properties()
1011 if (ctr->intra_refresh_type == in venc_set_properties()
1033 if (ret == -EALREADY) in venc_init_session()
1038 ret = venus_helper_set_stride(inst, inst->out_width, in venc_init_session()
1039 inst->out_height); in venc_init_session()
1043 ret = venus_helper_set_input_resolution(inst, inst->width, in venc_init_session()
1044 inst->height); in venc_init_session()
1048 ret = venus_helper_set_output_resolution(inst, inst->width, in venc_init_session()
1049 inst->height, in venc_init_session()
1054 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); in venc_init_session()
1087 struct venus_core *core = inst->core; in venc_queue_setup()
1092 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
1093 *num_planes != inst->fmt_out->num_planes) in venc_queue_setup()
1094 return -EINVAL; in venc_queue_setup()
1096 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
1097 *num_planes != inst->fmt_cap->num_planes) in venc_queue_setup()
1098 return -EINVAL; in venc_queue_setup()
1100 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
1101 sizes[0] < inst->input_buf_size) in venc_queue_setup()
1102 return -EINVAL; in venc_queue_setup()
1104 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
1105 sizes[0] < inst->output_buf_size) in venc_queue_setup()
1106 return -EINVAL; in venc_queue_setup()
1111 if (test_bit(0, &core->sys_error)) { in venc_queue_setup()
1112 if (inst->nonblock) in venc_queue_setup()
1113 return -EAGAIN; in venc_queue_setup()
1115 ret = wait_event_interruptible(core->sys_err_done, in venc_queue_setup()
1116 !test_bit(0, &core->sys_error)); in venc_queue_setup()
1125 mutex_lock(&inst->lock); in venc_queue_setup()
1127 mutex_unlock(&inst->lock); in venc_queue_setup()
1136 switch (q->type) { in venc_queue_setup()
1138 *num_planes = inst->fmt_out->num_planes; in venc_queue_setup()
1144 num = max(num, min); in venc_queue_setup()
1145 *num_buffers = max(*num_buffers, num); in venc_queue_setup()
1146 inst->num_input_bufs = *num_buffers; in venc_queue_setup()
1148 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in venc_queue_setup()
1149 inst->out_width, in venc_queue_setup()
1150 inst->out_height); in venc_queue_setup()
1151 inst->input_buf_size = sizes[0]; in venc_queue_setup()
1154 *num_planes = inst->fmt_cap->num_planes; in venc_queue_setup()
1155 *num_buffers = max(*num_buffers, min); in venc_queue_setup()
1156 inst->num_output_bufs = *num_buffers; in venc_queue_setup()
1157 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in venc_queue_setup()
1158 inst->width, in venc_queue_setup()
1159 inst->height); in venc_queue_setup()
1160 sizes[0] = max(sizes[0], inst->output_buf_size); in venc_queue_setup()
1161 inst->output_buf_size = sizes[0]; in venc_queue_setup()
1164 ret = -EINVAL; in venc_queue_setup()
1176 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_init()
1178 inst->buf_count++; in venc_buf_init()
1189 mutex_lock(&inst->lock); in venc_release_session()
1192 if (ret || inst->session_error) in venc_release_session()
1195 mutex_unlock(&inst->lock); in venc_release_session()
1198 INIT_LIST_HEAD(&inst->registeredbufs); in venc_release_session()
1206 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_cleanup()
1210 mutex_lock(&inst->lock); in venc_buf_cleanup()
1211 if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_buf_cleanup()
1212 if (!list_empty(&inst->registeredbufs)) in venc_buf_cleanup()
1213 list_del_init(&buf->reg_list); in venc_buf_cleanup()
1214 mutex_unlock(&inst->lock); in venc_buf_cleanup()
1216 inst->buf_count--; in venc_buf_cleanup()
1217 if (!inst->buf_count) in venc_buf_cleanup()
1223 enum hfi_version ver = inst->core->res->hfi_version; in venc_verify_conf()
1227 if (!inst->num_input_bufs || !inst->num_output_bufs) in venc_verify_conf()
1228 return -EINVAL; in venc_verify_conf()
1234 if (inst->num_output_bufs < bufreq.count_actual || in venc_verify_conf()
1235 inst->num_output_bufs < hfi_bufreq_get_count_min(&bufreq, ver)) in venc_verify_conf()
1236 return -EINVAL; in venc_verify_conf()
1242 if (inst->num_input_bufs < bufreq.count_actual || in venc_verify_conf()
1243 inst->num_input_bufs < hfi_bufreq_get_count_min(&bufreq, ver)) in venc_verify_conf()
1244 return -EINVAL; in venc_verify_conf()
1254 mutex_lock(&inst->lock); in venc_start_streaming()
1256 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1257 inst->streamon_out = 1; in venc_start_streaming()
1259 inst->streamon_cap = 1; in venc_start_streaming()
1261 if (!(inst->streamon_out & inst->streamon_cap)) { in venc_start_streaming()
1262 mutex_unlock(&inst->lock); in venc_start_streaming()
1268 inst->sequence_cap = 0; in venc_start_streaming()
1269 inst->sequence_out = 0; in venc_start_streaming()
1291 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in venc_start_streaming()
1292 inst->num_output_bufs, 0); in venc_start_streaming()
1300 inst->enc_state = VENUS_ENC_STATE_ENCODING; in venc_start_streaming()
1302 mutex_unlock(&inst->lock); in venc_start_streaming()
1309 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in venc_start_streaming()
1310 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1311 inst->streamon_out = 0; in venc_start_streaming()
1313 inst->streamon_cap = 0; in venc_start_streaming()
1314 mutex_unlock(&inst->lock); in venc_start_streaming()
1320 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_vb2_buf_queue()
1325 mutex_lock(&inst->lock); in venc_vb2_buf_queue()
1327 if (inst->enc_state == VENUS_ENC_STATE_STOPPED) { in venc_vb2_buf_queue()
1328 vbuf->sequence = inst->sequence_cap++; in venc_vb2_buf_queue()
1329 vbuf->field = V4L2_FIELD_NONE; in venc_vb2_buf_queue()
1332 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1337 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1369 vbuf->flags = flags; in venc_buf_done()
1372 vb = &vbuf->vb2_buf; in venc_buf_done()
1374 vb->planes[0].data_offset = data_offset; in venc_buf_done()
1375 vb->timestamp = timestamp_us * NSEC_PER_USEC; in venc_buf_done()
1376 vbuf->sequence = inst->sequence_cap++; in venc_buf_done()
1377 if ((vbuf->flags & V4L2_BUF_FLAG_LAST) && in venc_buf_done()
1378 inst->enc_state == VENUS_ENC_STATE_DRAIN) { in venc_buf_done()
1379 inst->enc_state = VENUS_ENC_STATE_STOPPED; in venc_buf_done()
1382 vbuf->sequence = inst->sequence_out++; in venc_buf_done()
1391 struct device *dev = inst->core->dev_enc; in venc_event_notify()
1396 inst->session_error = true; in venc_event_notify()
1398 dev_err(dev, "enc: event session error %x\n", inst->error); in venc_event_notify()
1418 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in m2m_queue_init()
1419 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1420 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1421 src_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1422 src_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1423 src_vq->drv_priv = inst; in m2m_queue_init()
1424 src_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1425 src_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1426 src_vq->min_queued_buffers = 1; in m2m_queue_init()
1427 src_vq->dev = inst->core->dev; in m2m_queue_init()
1428 src_vq->lock = &inst->ctx_q_lock; in m2m_queue_init()
1429 if (inst->core->res->hfi_version == HFI_VERSION_1XX) in m2m_queue_init()
1430 src_vq->bidirectional = 1; in m2m_queue_init()
1435 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in m2m_queue_init()
1436 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1437 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1438 dst_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1439 dst_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1440 dst_vq->drv_priv = inst; in m2m_queue_init()
1441 dst_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1442 dst_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1443 dst_vq->min_queued_buffers = 1; in m2m_queue_init()
1444 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1445 dst_vq->lock = &inst->ctx_q_lock; in m2m_queue_init()
1451 inst->fmt_cap = &venc_formats[VENUS_FMT_H264]; in venc_inst_init()
1452 inst->fmt_out = &venc_formats[VENUS_FMT_NV12]; in venc_inst_init()
1453 inst->width = 1280; in venc_inst_init()
1454 inst->height = ALIGN(720, 32); in venc_inst_init()
1455 inst->out_width = 1280; in venc_inst_init()
1456 inst->out_height = 720; in venc_inst_init()
1457 inst->fps = 15; in venc_inst_init()
1458 inst->timeperframe.numerator = 1; in venc_inst_init()
1459 inst->timeperframe.denominator = 15; in venc_inst_init()
1460 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in venc_inst_init()
1471 return -ENOMEM; in venc_open()
1473 INIT_LIST_HEAD(&inst->dpbbufs); in venc_open()
1474 INIT_LIST_HEAD(&inst->registeredbufs); in venc_open()
1475 INIT_LIST_HEAD(&inst->internalbufs); in venc_open()
1476 INIT_LIST_HEAD(&inst->list); in venc_open()
1477 mutex_init(&inst->lock); in venc_open()
1478 mutex_init(&inst->ctx_q_lock); in venc_open()
1480 inst->core = core; in venc_open()
1481 inst->session_type = VIDC_SESSION_TYPE_ENC; in venc_open()
1482 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in venc_open()
1483 inst->core_acquired = false; in venc_open()
1484 inst->nonblock = file->f_flags & O_NONBLOCK; in venc_open()
1486 if (inst->enc_state == VENUS_ENC_STATE_DEINIT) in venc_open()
1487 inst->enc_state = VENUS_ENC_STATE_INIT; in venc_open()
1501 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); in venc_open()
1502 if (IS_ERR(inst->m2m_dev)) { in venc_open()
1503 ret = PTR_ERR(inst->m2m_dev); in venc_open()
1507 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in venc_open()
1508 if (IS_ERR(inst->m2m_ctx)) { in venc_open()
1509 ret = PTR_ERR(inst->m2m_ctx); in venc_open()
1517 v4l2_fh_init(&inst->fh, core->vdev_enc); in venc_open()
1519 inst->fh.ctrl_handler = &inst->ctrl_handler; in venc_open()
1520 v4l2_fh_add(&inst->fh); in venc_open()
1521 inst->fh.m2m_ctx = inst->m2m_ctx; in venc_open()
1522 file->private_data = &inst->fh; in venc_open()
1527 v4l2_m2m_ctx_release(inst->m2m_ctx); in venc_open()
1529 v4l2_m2m_release(inst->m2m_dev); in venc_open()
1531 v4l2_ctrl_handler_free(&inst->ctrl_handler); in venc_open()
1543 inst->enc_state = VENUS_ENC_STATE_DEINIT; in venc_close()
1561 struct device *dev = &pdev->dev; in venc_probe()
1566 if (!dev->parent) in venc_probe()
1567 return -EPROBE_DEFER; in venc_probe()
1569 core = dev_get_drvdata(dev->parent); in venc_probe()
1571 return -EPROBE_DEFER; in venc_probe()
1575 if (core->pm_ops->venc_get) { in venc_probe()
1576 ret = core->pm_ops->venc_get(dev); in venc_probe()
1583 return -ENOMEM; in venc_probe()
1585 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); in venc_probe()
1586 vdev->release = video_device_release; in venc_probe()
1587 vdev->fops = &venc_fops; in venc_probe()
1588 vdev->ioctl_ops = &venc_ioctl_ops; in venc_probe()
1589 vdev->vfl_dir = VFL_DIR_M2M; in venc_probe()
1590 vdev->v4l2_dev = &core->v4l2_dev; in venc_probe()
1591 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; in venc_probe()
1593 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in venc_probe()
1597 core->vdev_enc = vdev; in venc_probe()
1598 core->dev_enc = dev; in venc_probe()
1614 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); in venc_remove()
1616 video_unregister_device(core->vdev_enc); in venc_remove()
1617 pm_runtime_disable(core->dev_enc); in venc_remove()
1619 if (core->pm_ops->venc_put) in venc_remove()
1620 core->pm_ops->venc_put(core->dev_enc); in venc_remove()
1626 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_suspend()
1629 if (pm_ops->venc_power) in venc_runtime_suspend()
1630 ret = pm_ops->venc_power(dev, POWER_OFF); in venc_runtime_suspend()
1638 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_resume()
1641 if (pm_ops->venc_power) in venc_runtime_resume()
1642 ret = pm_ops->venc_power(dev, POWER_ON); in venc_runtime_resume()
1654 { .compatible = "venus-encoder" },
1663 .name = "qcom-venus-encoder",
1670 MODULE_ALIAS("platform:qcom-venus-encoder");