Lines Matching +full:venus +full:- +full:encoder

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()
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()
545 * encoder input to signal EOS. 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()
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()
739 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
740 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
742 * n = 0 - only the first I-frame is IDR frame in venc_set_properties()
743 * n = 1 - all I-frames will be IDR frames in venc_set_properties()
744 * n > 1 - every n-th I-frame will be IDR frame in venc_set_properties()
753 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC && in venc_set_properties()
754 ctr->profile.hevc == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10) { in venc_set_properties()
762 ctr->mastering.display_primaries_x[c]; in venc_set_properties()
764 ctr->mastering.display_primaries_y[c]; in venc_set_properties()
767 hdr10.mastering.white_point_x = ctr->mastering.white_point_x; in venc_set_properties()
768 hdr10.mastering.white_point_y = ctr->mastering.white_point_y; in venc_set_properties()
770 ctr->mastering.max_display_mastering_luminance; in venc_set_properties()
772 ctr->mastering.min_display_mastering_luminance; in venc_set_properties()
774 hdr10.cll.max_content_light = ctr->cll.max_content_light_level; in venc_set_properties()
776 ctr->cll.max_pic_average_light_level; in venc_set_properties()
783 if (ctr->num_b_frames) { in venc_set_properties()
793 intra_period.pframes = ctr->num_p_frames; in venc_set_properties()
794 intra_period.bframes = ctr->num_b_frames; in venc_set_properties()
800 if (!ctr->rc_enable) in venc_set_properties()
802 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) in venc_set_properties()
803 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : in venc_set_properties()
805 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) in venc_set_properties()
806 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : in venc_set_properties()
808 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) in venc_set_properties()
816 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { in venc_set_properties()
820 quality.frame_quality = ctr->const_quality; in venc_set_properties()
826 if (!ctr->bitrate) in venc_set_properties()
829 bitrate = ctr->bitrate; in venc_set_properties()
839 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
840 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
842 if (ctr->header_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) in venc_set_properties()
852 if (!ctr->bitrate_peak) in venc_set_properties()
855 bitrate = ctr->bitrate_peak; in venc_set_properties()
866 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
867 quant.qp_i = ctr->hevc_i_qp; in venc_set_properties()
868 quant.qp_p = ctr->hevc_p_qp; in venc_set_properties()
869 quant.qp_b = ctr->hevc_b_qp; in venc_set_properties()
871 quant.qp_i = ctr->h264_i_qp; in venc_set_properties()
872 quant.qp_p = ctr->h264_p_qp; in venc_set_properties()
873 quant.qp_b = ctr->h264_b_qp; in venc_set_properties()
880 if (inst->core->res->hfi_version == HFI_VERSION_4XX || in venc_set_properties()
881 inst->core->res->hfi_version == HFI_VERSION_6XX) { in venc_set_properties()
884 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
885 quant_range_v2.min_qp.qp_packed = ctr->hevc_min_qp; in venc_set_properties()
886 quant_range_v2.max_qp.qp_packed = ctr->hevc_max_qp; in venc_set_properties()
887 } else if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_VP8) { in venc_set_properties()
888 quant_range_v2.min_qp.qp_packed = ctr->vp8_min_qp; in venc_set_properties()
889 quant_range_v2.max_qp.qp_packed = ctr->vp8_max_qp; in venc_set_properties()
891 quant_range_v2.min_qp.qp_packed = ctr->h264_min_qp; in venc_set_properties()
892 quant_range_v2.max_qp.qp_packed = ctr->h264_max_qp; in venc_set_properties()
899 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
900 quant_range.min_qp = ctr->hevc_min_qp; in venc_set_properties()
901 quant_range.max_qp = ctr->hevc_max_qp; in venc_set_properties()
902 } else if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_VP8) { in venc_set_properties()
903 quant_range.min_qp = ctr->vp8_min_qp; in venc_set_properties()
904 quant_range.max_qp = ctr->vp8_max_qp; in venc_set_properties()
906 quant_range.min_qp = ctr->h264_min_qp; in venc_set_properties()
907 quant_range.max_qp = ctr->h264_max_qp; in venc_set_properties()
918 ltr_mode.ltr_count = ctr->ltr_count; in venc_set_properties()
925 switch (inst->hfi_codec) { in venc_set_properties()
927 profile = ctr->profile.h264; in venc_set_properties()
928 level = ctr->level.h264; in venc_set_properties()
931 profile = ctr->profile.mpeg4; in venc_set_properties()
932 level = ctr->level.mpeg4; in venc_set_properties()
935 profile = ctr->profile.vp8; in venc_set_properties()
939 profile = ctr->profile.vp9; in venc_set_properties()
940 level = ctr->level.vp9; in venc_set_properties()
943 profile = ctr->profile.hevc; in venc_set_properties()
944 level = ctr->level.hevc; in venc_set_properties()
957 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
958 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
963 if (ctr->aud_enable) in venc_set_properties()
969 if ((inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
970 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) && in venc_set_properties()
976 if (ctr->intra_refresh_period) { in venc_set_properties()
979 mbs = ALIGN(inst->width, 16) * ALIGN(inst->height, 16); in venc_set_properties()
981 if (mbs % ctr->intra_refresh_period) in venc_set_properties()
983 mbs /= ctr->intra_refresh_period; in venc_set_properties()
986 if (ctr->intra_refresh_type == in venc_set_properties()
1008 if (ret == -EALREADY) in venc_init_session()
1013 ret = venus_helper_set_stride(inst, inst->out_width, in venc_init_session()
1014 inst->out_height); in venc_init_session()
1018 ret = venus_helper_set_input_resolution(inst, inst->width, in venc_init_session()
1019 inst->height); in venc_init_session()
1023 ret = venus_helper_set_output_resolution(inst, inst->width, in venc_init_session()
1024 inst->height, in venc_init_session()
1029 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); in venc_init_session()
1062 struct venus_core *core = inst->core; in venc_queue_setup()
1067 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
1068 *num_planes != inst->fmt_out->num_planes) in venc_queue_setup()
1069 return -EINVAL; in venc_queue_setup()
1071 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
1072 *num_planes != inst->fmt_cap->num_planes) in venc_queue_setup()
1073 return -EINVAL; in venc_queue_setup()
1075 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
1076 sizes[0] < inst->input_buf_size) in venc_queue_setup()
1077 return -EINVAL; in venc_queue_setup()
1079 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
1080 sizes[0] < inst->output_buf_size) in venc_queue_setup()
1081 return -EINVAL; in venc_queue_setup()
1086 if (test_bit(0, &core->sys_error)) { in venc_queue_setup()
1087 if (inst->nonblock) in venc_queue_setup()
1088 return -EAGAIN; in venc_queue_setup()
1090 ret = wait_event_interruptible(core->sys_err_done, in venc_queue_setup()
1091 !test_bit(0, &core->sys_error)); in venc_queue_setup()
1100 mutex_lock(&inst->lock); in venc_queue_setup()
1102 mutex_unlock(&inst->lock); in venc_queue_setup()
1111 switch (q->type) { in venc_queue_setup()
1113 *num_planes = inst->fmt_out->num_planes; in venc_queue_setup()
1121 inst->num_input_bufs = *num_buffers; in venc_queue_setup()
1123 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in venc_queue_setup()
1124 inst->out_width, in venc_queue_setup()
1125 inst->out_height); in venc_queue_setup()
1126 inst->input_buf_size = sizes[0]; in venc_queue_setup()
1129 *num_planes = inst->fmt_cap->num_planes; in venc_queue_setup()
1131 inst->num_output_bufs = *num_buffers; in venc_queue_setup()
1132 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in venc_queue_setup()
1133 inst->width, in venc_queue_setup()
1134 inst->height); in venc_queue_setup()
1135 sizes[0] = max(sizes[0], inst->output_buf_size); in venc_queue_setup()
1136 inst->output_buf_size = sizes[0]; in venc_queue_setup()
1139 ret = -EINVAL; in venc_queue_setup()
1151 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_init()
1153 inst->buf_count++; in venc_buf_init()
1164 mutex_lock(&inst->lock); in venc_release_session()
1167 if (ret || inst->session_error) in venc_release_session()
1170 mutex_unlock(&inst->lock); in venc_release_session()
1173 INIT_LIST_HEAD(&inst->registeredbufs); in venc_release_session()
1181 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_cleanup()
1185 mutex_lock(&inst->lock); in venc_buf_cleanup()
1186 if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_buf_cleanup()
1187 if (!list_empty(&inst->registeredbufs)) in venc_buf_cleanup()
1188 list_del_init(&buf->reg_list); in venc_buf_cleanup()
1189 mutex_unlock(&inst->lock); in venc_buf_cleanup()
1191 inst->buf_count--; in venc_buf_cleanup()
1192 if (!inst->buf_count) in venc_buf_cleanup()
1198 enum hfi_version ver = inst->core->res->hfi_version; in venc_verify_conf()
1202 if (!inst->num_input_bufs || !inst->num_output_bufs) in venc_verify_conf()
1203 return -EINVAL; in venc_verify_conf()
1209 if (inst->num_output_bufs < bufreq.count_actual || in venc_verify_conf()
1210 inst->num_output_bufs < hfi_bufreq_get_count_min(&bufreq, ver)) in venc_verify_conf()
1211 return -EINVAL; in venc_verify_conf()
1217 if (inst->num_input_bufs < bufreq.count_actual || in venc_verify_conf()
1218 inst->num_input_bufs < hfi_bufreq_get_count_min(&bufreq, ver)) in venc_verify_conf()
1219 return -EINVAL; in venc_verify_conf()
1229 mutex_lock(&inst->lock); in venc_start_streaming()
1231 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1232 inst->streamon_out = 1; in venc_start_streaming()
1234 inst->streamon_cap = 1; in venc_start_streaming()
1236 if (!(inst->streamon_out & inst->streamon_cap)) { in venc_start_streaming()
1237 mutex_unlock(&inst->lock); in venc_start_streaming()
1243 inst->sequence_cap = 0; in venc_start_streaming()
1244 inst->sequence_out = 0; in venc_start_streaming()
1266 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in venc_start_streaming()
1267 inst->num_output_bufs, 0); in venc_start_streaming()
1275 inst->enc_state = VENUS_ENC_STATE_ENCODING; in venc_start_streaming()
1277 mutex_unlock(&inst->lock); in venc_start_streaming()
1284 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in venc_start_streaming()
1285 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1286 inst->streamon_out = 0; in venc_start_streaming()
1288 inst->streamon_cap = 0; in venc_start_streaming()
1289 mutex_unlock(&inst->lock); in venc_start_streaming()
1295 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_vb2_buf_queue()
1300 mutex_lock(&inst->lock); in venc_vb2_buf_queue()
1302 if (inst->enc_state == VENUS_ENC_STATE_STOPPED) { in venc_vb2_buf_queue()
1303 vbuf->sequence = inst->sequence_cap++; in venc_vb2_buf_queue()
1304 vbuf->field = V4L2_FIELD_NONE; in venc_vb2_buf_queue()
1307 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1312 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1344 vbuf->flags = flags; in venc_buf_done()
1347 vb = &vbuf->vb2_buf; in venc_buf_done()
1349 vb->planes[0].data_offset = data_offset; in venc_buf_done()
1350 vb->timestamp = timestamp_us * NSEC_PER_USEC; in venc_buf_done()
1351 vbuf->sequence = inst->sequence_cap++; in venc_buf_done()
1352 if ((vbuf->flags & V4L2_BUF_FLAG_LAST) && in venc_buf_done()
1353 inst->enc_state == VENUS_ENC_STATE_DRAIN) { in venc_buf_done()
1354 inst->enc_state = VENUS_ENC_STATE_STOPPED; in venc_buf_done()
1357 vbuf->sequence = inst->sequence_out++; in venc_buf_done()
1366 struct device *dev = inst->core->dev_enc; in venc_event_notify()
1371 inst->session_error = true; in venc_event_notify()
1373 dev_err(dev, "enc: event session error %x\n", inst->error); in venc_event_notify()
1393 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in m2m_queue_init()
1394 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1395 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1396 src_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1397 src_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1398 src_vq->drv_priv = inst; in m2m_queue_init()
1399 src_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1400 src_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1401 src_vq->min_queued_buffers = 1; in m2m_queue_init()
1402 src_vq->dev = inst->core->dev; in m2m_queue_init()
1403 src_vq->lock = &inst->ctx_q_lock; in m2m_queue_init()
1404 if (inst->core->res->hfi_version == HFI_VERSION_1XX) in m2m_queue_init()
1405 src_vq->bidirectional = 1; in m2m_queue_init()
1410 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in m2m_queue_init()
1411 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1412 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1413 dst_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1414 dst_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1415 dst_vq->drv_priv = inst; in m2m_queue_init()
1416 dst_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1417 dst_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1418 dst_vq->min_queued_buffers = 1; in m2m_queue_init()
1419 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1420 dst_vq->lock = &inst->ctx_q_lock; in m2m_queue_init()
1426 inst->fmt_cap = &venc_formats[VENUS_FMT_H264]; in venc_inst_init()
1427 inst->fmt_out = &venc_formats[VENUS_FMT_NV12]; in venc_inst_init()
1428 inst->width = 1280; in venc_inst_init()
1429 inst->height = ALIGN(720, 32); in venc_inst_init()
1430 inst->out_width = 1280; in venc_inst_init()
1431 inst->out_height = 720; in venc_inst_init()
1432 inst->fps = 15; in venc_inst_init()
1433 inst->timeperframe.numerator = 1; in venc_inst_init()
1434 inst->timeperframe.denominator = 15; in venc_inst_init()
1435 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in venc_inst_init()
1446 return -ENOMEM; in venc_open()
1448 INIT_LIST_HEAD(&inst->dpbbufs); in venc_open()
1449 INIT_LIST_HEAD(&inst->registeredbufs); in venc_open()
1450 INIT_LIST_HEAD(&inst->internalbufs); in venc_open()
1451 INIT_LIST_HEAD(&inst->list); in venc_open()
1452 mutex_init(&inst->lock); in venc_open()
1453 mutex_init(&inst->ctx_q_lock); in venc_open()
1455 inst->core = core; in venc_open()
1456 inst->session_type = VIDC_SESSION_TYPE_ENC; in venc_open()
1457 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in venc_open()
1458 inst->core_acquired = false; in venc_open()
1459 inst->nonblock = file->f_flags & O_NONBLOCK; in venc_open()
1461 if (inst->enc_state == VENUS_ENC_STATE_DEINIT) in venc_open()
1462 inst->enc_state = VENUS_ENC_STATE_INIT; in venc_open()
1480 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); in venc_open()
1481 if (IS_ERR(inst->m2m_dev)) { in venc_open()
1482 ret = PTR_ERR(inst->m2m_dev); in venc_open()
1486 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in venc_open()
1487 if (IS_ERR(inst->m2m_ctx)) { in venc_open()
1488 ret = PTR_ERR(inst->m2m_ctx); in venc_open()
1492 v4l2_fh_init(&inst->fh, core->vdev_enc); in venc_open()
1494 inst->fh.ctrl_handler = &inst->ctrl_handler; in venc_open()
1495 v4l2_fh_add(&inst->fh); in venc_open()
1496 inst->fh.m2m_ctx = inst->m2m_ctx; in venc_open()
1497 file->private_data = &inst->fh; in venc_open()
1502 v4l2_m2m_release(inst->m2m_dev); in venc_open()
1518 v4l2_m2m_ctx_release(inst->m2m_ctx); in venc_close()
1519 v4l2_m2m_release(inst->m2m_dev); in venc_close()
1522 mutex_destroy(&inst->lock); in venc_close()
1523 mutex_destroy(&inst->ctx_q_lock); in venc_close()
1524 v4l2_fh_del(&inst->fh); in venc_close()
1525 v4l2_fh_exit(&inst->fh); in venc_close()
1527 inst->enc_state = VENUS_ENC_STATE_DEINIT; in venc_close()
1546 struct device *dev = &pdev->dev; in venc_probe()
1551 if (!dev->parent) in venc_probe()
1552 return -EPROBE_DEFER; in venc_probe()
1554 core = dev_get_drvdata(dev->parent); in venc_probe()
1556 return -EPROBE_DEFER; in venc_probe()
1560 if (core->pm_ops->venc_get) { in venc_probe()
1561 ret = core->pm_ops->venc_get(dev); in venc_probe()
1568 return -ENOMEM; in venc_probe()
1570 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); in venc_probe()
1571 vdev->release = video_device_release; in venc_probe()
1572 vdev->fops = &venc_fops; in venc_probe()
1573 vdev->ioctl_ops = &venc_ioctl_ops; in venc_probe()
1574 vdev->vfl_dir = VFL_DIR_M2M; in venc_probe()
1575 vdev->v4l2_dev = &core->v4l2_dev; in venc_probe()
1576 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; in venc_probe()
1578 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in venc_probe()
1582 core->vdev_enc = vdev; in venc_probe()
1583 core->dev_enc = dev; in venc_probe()
1599 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); in venc_remove()
1601 video_unregister_device(core->vdev_enc); in venc_remove()
1602 pm_runtime_disable(core->dev_enc); in venc_remove()
1604 if (core->pm_ops->venc_put) in venc_remove()
1605 core->pm_ops->venc_put(core->dev_enc); in venc_remove()
1611 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_suspend()
1614 if (pm_ops->venc_power) in venc_runtime_suspend()
1615 ret = pm_ops->venc_power(dev, POWER_OFF); in venc_runtime_suspend()
1623 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_resume()
1626 if (pm_ops->venc_power) in venc_runtime_resume()
1627 ret = pm_ops->venc_power(dev, POWER_ON); in venc_runtime_resume()
1639 { .compatible = "venus-encoder" },
1648 .name = "qcom-venus-encoder",
1655 MODULE_ALIAS("platform:qcom-venus-encoder");
1656 MODULE_DESCRIPTION("Qualcomm Venus video encoder driver");