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 pixmp->width = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
196 pixmp->height = ALIGN(pixmp->height, 32); in venc_try_fmt_common()
198 pixmp->width = ALIGN(pixmp->width, 2); in venc_try_fmt_common()
199 pixmp->height = ALIGN(pixmp->height, 2); in venc_try_fmt_common()
201 if (pixmp->field == V4L2_FIELD_ANY) in venc_try_fmt_common()
202 pixmp->field = V4L2_FIELD_NONE; in venc_try_fmt_common()
203 pixmp->num_planes = fmt->num_planes; in venc_try_fmt_common()
204 pixmp->flags = 0; in venc_try_fmt_common()
206 sizeimage = venus_helper_get_framesz(pixmp->pixelformat, in venc_try_fmt_common()
207 pixmp->width, in venc_try_fmt_common()
208 pixmp->height); in venc_try_fmt_common()
209 pfmt[0].sizeimage = max(ALIGN(pfmt[0].sizeimage, SZ_4K), sizeimage); in venc_try_fmt_common()
211 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
212 pfmt[0].bytesperline = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
231 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_s_fmt()
238 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); in venc_s_fmt()
240 return -EINVAL; in venc_s_fmt()
243 return -EBUSY; in venc_s_fmt()
249 return -EINVAL; in venc_s_fmt()
251 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
252 pixfmt_out = pixmp->pixelformat; in venc_s_fmt()
253 pixfmt_cap = inst->fmt_cap->pixfmt; in venc_s_fmt()
254 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
255 pixfmt_cap = pixmp->pixelformat; in venc_s_fmt()
256 pixfmt_out = inst->fmt_out->pixfmt; in venc_s_fmt()
267 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
268 inst->out_width = format.fmt.pix_mp.width; in venc_s_fmt()
269 inst->out_height = format.fmt.pix_mp.height; in venc_s_fmt()
270 inst->colorspace = pixmp->colorspace; in venc_s_fmt()
271 inst->ycbcr_enc = pixmp->ycbcr_enc; in venc_s_fmt()
272 inst->quantization = pixmp->quantization; in venc_s_fmt()
273 inst->xfer_func = pixmp->xfer_func; in venc_s_fmt()
284 inst->width = format.fmt.pix_mp.width; in venc_s_fmt()
285 inst->height = format.fmt.pix_mp.height; in venc_s_fmt()
287 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_fmt()
288 inst->fmt_out = fmt; in venc_s_fmt()
289 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
290 inst->fmt_cap = fmt; in venc_s_fmt()
291 inst->output_buf_size = pixmp->plane_fmt[0].sizeimage; in venc_s_fmt()
299 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_g_fmt()
303 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_g_fmt()
304 fmt = inst->fmt_cap; in venc_g_fmt()
305 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_fmt()
306 fmt = inst->fmt_out; in venc_g_fmt()
308 return -EINVAL; in venc_g_fmt()
310 pixmp->pixelformat = fmt->pixfmt; in venc_g_fmt()
312 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_g_fmt()
313 pixmp->width = inst->width; in venc_g_fmt()
314 pixmp->height = inst->height; in venc_g_fmt()
315 pixmp->colorspace = inst->colorspace; in venc_g_fmt()
316 pixmp->ycbcr_enc = inst->ycbcr_enc; in venc_g_fmt()
317 pixmp->quantization = inst->quantization; in venc_g_fmt()
318 pixmp->xfer_func = inst->xfer_func; in venc_g_fmt()
319 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_g_fmt()
320 pixmp->width = inst->out_width; in venc_g_fmt()
321 pixmp->height = inst->out_height; in venc_g_fmt()
334 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_g_selection()
335 return -EINVAL; in venc_g_selection()
337 switch (s->target) { in venc_g_selection()
340 s->r.width = inst->out_width; in venc_g_selection()
341 s->r.height = inst->out_height; in venc_g_selection()
344 s->r.width = inst->width; in venc_g_selection()
345 s->r.height = inst->height; in venc_g_selection()
348 return -EINVAL; in venc_g_selection()
351 s->r.top = 0; in venc_g_selection()
352 s->r.left = 0; in venc_g_selection()
362 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_s_selection()
363 return -EINVAL; in venc_s_selection()
365 if (s->r.width > inst->out_width || in venc_s_selection()
366 s->r.height > inst->out_height) in venc_s_selection()
367 return -EINVAL; in venc_s_selection()
369 s->r.width = ALIGN(s->r.width, 2); in venc_s_selection()
370 s->r.height = ALIGN(s->r.height, 2); in venc_s_selection()
372 switch (s->target) { in venc_s_selection()
374 s->r.top = 0; in venc_s_selection()
375 s->r.left = 0; in venc_s_selection()
376 inst->width = s->r.width; in venc_s_selection()
377 inst->height = s->r.height; in venc_s_selection()
380 return -EINVAL; in venc_s_selection()
389 struct v4l2_outputparm *out = &a->parm.output; in venc_s_parm()
390 struct v4l2_fract *timeperframe = &out->timeperframe; in venc_s_parm()
393 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && in venc_s_parm()
394 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_parm()
395 return -EINVAL; in venc_s_parm()
397 memset(out->reserved, 0, sizeof(out->reserved)); in venc_s_parm()
399 if (!timeperframe->denominator) in venc_s_parm()
400 timeperframe->denominator = inst->timeperframe.denominator; in venc_s_parm()
401 if (!timeperframe->numerator) in venc_s_parm()
402 timeperframe->numerator = inst->timeperframe.numerator; in venc_s_parm()
404 out->capability = V4L2_CAP_TIMEPERFRAME; in venc_s_parm()
406 us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; in venc_s_parm()
407 do_div(us_per_frame, timeperframe->denominator); in venc_s_parm()
410 return -EINVAL; in venc_s_parm()
415 inst->timeperframe = *timeperframe; in venc_s_parm()
416 inst->fps = fps; in venc_s_parm()
425 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && in venc_g_parm()
426 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_parm()
427 return -EINVAL; in venc_g_parm()
429 a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; in venc_g_parm()
430 a->parm.output.timeperframe = inst->timeperframe; in venc_g_parm()
441 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in venc_enum_framesizes()
443 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
446 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
449 return -EINVAL; in venc_enum_framesizes()
452 if (fsize->index) in venc_enum_framesizes()
453 return -EINVAL; in venc_enum_framesizes()
455 fsize->stepwise.min_width = frame_width_min(inst); in venc_enum_framesizes()
456 fsize->stepwise.max_width = frame_width_max(inst); in venc_enum_framesizes()
457 fsize->stepwise.step_width = frame_width_step(inst); in venc_enum_framesizes()
458 fsize->stepwise.min_height = frame_height_min(inst); in venc_enum_framesizes()
459 fsize->stepwise.max_height = frame_height_max(inst); in venc_enum_framesizes()
460 fsize->stepwise.step_height = frame_height_step(inst); in venc_enum_framesizes()
472 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; in venc_enum_frameintervals()
474 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
477 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
480 return -EINVAL; in venc_enum_frameintervals()
483 if (fival->index) in venc_enum_frameintervals()
484 return -EINVAL; in venc_enum_frameintervals()
486 if (!fival->width || !fival->height) in venc_enum_frameintervals()
487 return -EINVAL; in venc_enum_frameintervals()
489 if (fival->width > frame_width_max(inst) || in venc_enum_frameintervals()
490 fival->width < frame_width_min(inst) || in venc_enum_frameintervals()
491 fival->height > frame_height_max(inst) || in venc_enum_frameintervals()
492 fival->height < frame_height_min(inst)) in venc_enum_frameintervals()
493 return -EINVAL; in venc_enum_frameintervals()
495 if (IS_V1(inst->core)) { in venc_enum_frameintervals()
500 fival->stepwise.min.numerator = 1; in venc_enum_frameintervals()
501 fival->stepwise.min.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
502 fival->stepwise.max.numerator = 1; in venc_enum_frameintervals()
503 fival->stepwise.max.denominator = frate_min(inst) / framerate_factor; in venc_enum_frameintervals()
504 fival->stepwise.step.numerator = 1; in venc_enum_frameintervals()
505 fival->stepwise.step.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
513 switch (sub->type) { in venc_subscribe_event()
519 return -EINVAL; in venc_subscribe_event()
555 struct venus_core *core = inst->core; in venc_pm_get()
556 struct device *dev = core->dev_enc; in venc_pm_get()
559 mutex_lock(&core->pm_lock); in venc_pm_get()
561 mutex_unlock(&core->pm_lock); in venc_pm_get()
568 struct venus_core *core = inst->core; in venc_pm_put()
569 struct device *dev = core->dev_enc; in venc_pm_put()
572 mutex_lock(&core->pm_lock); in venc_pm_put()
579 mutex_unlock(&core->pm_lock); in venc_pm_put()
586 struct venus_core *core = inst->core; in venc_pm_get_put()
587 struct device *dev = core->dev_enc; in venc_pm_get_put()
590 mutex_lock(&core->pm_lock); in venc_pm_get_put()
601 mutex_unlock(&core->pm_lock); in venc_pm_get_put()
608 pm_runtime_mark_last_busy(inst->core->dev_enc); in venc_pm_touch()
613 struct venc_controls *ctr = &inst->controls.enc; in venc_set_properties()
623 u32 ptype, rate_control, bitrate; in venc_set_properties() local
633 frate.framerate = inst->fps * (1 << 16); in venc_set_properties()
639 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { in venc_set_properties()
657 ctr->h264_entropy_mode); in venc_set_properties()
667 ctr->h264_loop_filter_mode); in venc_set_properties()
668 deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; in venc_set_properties()
669 deblock.slice_beta_offset = ctr->h264_loop_filter_beta; in venc_set_properties()
677 if (ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_HIGH || in venc_set_properties()
678 ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH) in venc_set_properties()
679 h264_transform.enable_type = ctr->h264_8x8_transform; in venc_set_properties()
687 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
688 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
690 * n = 0 - only the first I-frame is IDR frame in venc_set_properties()
691 * n = 1 - all I-frames will be IDR frames in venc_set_properties()
692 * n > 1 - every n-th I-frame will be IDR frame in venc_set_properties()
701 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC && in venc_set_properties()
702 ctr->profile.hevc == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10) { in venc_set_properties()
710 ctr->mastering.display_primaries_x[c]; in venc_set_properties()
712 ctr->mastering.display_primaries_y[c]; in venc_set_properties()
715 hdr10.mastering.white_point_x = ctr->mastering.white_point_x; in venc_set_properties()
716 hdr10.mastering.white_point_y = ctr->mastering.white_point_y; in venc_set_properties()
718 ctr->mastering.max_display_mastering_luminance; in venc_set_properties()
720 ctr->mastering.min_display_mastering_luminance; in venc_set_properties()
722 hdr10.cll.max_content_light = ctr->cll.max_content_light_level; in venc_set_properties()
724 ctr->cll.max_pic_average_light_level; in venc_set_properties()
731 if (ctr->num_b_frames) { in venc_set_properties()
741 intra_period.pframes = ctr->num_p_frames; in venc_set_properties()
742 intra_period.bframes = ctr->num_b_frames; in venc_set_properties()
748 if (!ctr->rc_enable) in venc_set_properties()
750 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) in venc_set_properties()
751 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : in venc_set_properties()
753 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) in venc_set_properties()
754 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : in venc_set_properties()
756 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) in venc_set_properties()
764 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { in venc_set_properties()
768 quality.frame_quality = ctr->const_quality; in venc_set_properties()
774 if (!ctr->bitrate) in venc_set_properties()
775 bitrate = 64000; in venc_set_properties()
777 bitrate = ctr->bitrate; in venc_set_properties()
780 brate.bitrate = bitrate; in venc_set_properties()
787 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
788 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
790 if (ctr->header_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) in venc_set_properties()
800 if (!ctr->bitrate_peak) in venc_set_properties()
801 bitrate *= 2; in venc_set_properties()
803 bitrate = ctr->bitrate_peak; in venc_set_properties()
806 brate.bitrate = bitrate; in venc_set_properties()
814 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
815 quant.qp_i = ctr->hevc_i_qp; in venc_set_properties()
816 quant.qp_p = ctr->hevc_p_qp; in venc_set_properties()
817 quant.qp_b = ctr->hevc_b_qp; in venc_set_properties()
819 quant.qp_i = ctr->h264_i_qp; in venc_set_properties()
820 quant.qp_p = ctr->h264_p_qp; in venc_set_properties()
821 quant.qp_b = ctr->h264_b_qp; in venc_set_properties()
829 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
830 quant_range.min_qp = ctr->hevc_min_qp; in venc_set_properties()
831 quant_range.max_qp = ctr->hevc_max_qp; in venc_set_properties()
833 quant_range.min_qp = ctr->h264_min_qp; in venc_set_properties()
834 quant_range.max_qp = ctr->h264_max_qp; in venc_set_properties()
842 ltr_mode.ltr_count = ctr->ltr_count; in venc_set_properties()
849 switch (inst->hfi_codec) { in venc_set_properties()
851 profile = ctr->profile.h264; in venc_set_properties()
852 level = ctr->level.h264; in venc_set_properties()
855 profile = ctr->profile.mpeg4; in venc_set_properties()
856 level = ctr->level.mpeg4; in venc_set_properties()
859 profile = ctr->profile.vp8; in venc_set_properties()
863 profile = ctr->profile.vp9; in venc_set_properties()
864 level = ctr->level.vp9; in venc_set_properties()
867 profile = ctr->profile.hevc; in venc_set_properties()
868 level = ctr->level.hevc; in venc_set_properties()
881 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
882 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { in venc_set_properties()
887 if (ctr->aud_enable) in venc_set_properties()
893 if ((inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || in venc_set_properties()
894 inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) && in venc_set_properties()
900 if (ctr->intra_refresh_period) { in venc_set_properties()
903 mbs = ALIGN(inst->width, 16) * ALIGN(inst->height, 16); in venc_set_properties()
905 if (mbs % ctr->intra_refresh_period) in venc_set_properties()
907 mbs /= ctr->intra_refresh_period; in venc_set_properties()
910 if (ctr->intra_refresh_type == in venc_set_properties()
932 if (ret == -EALREADY) in venc_init_session()
937 ret = venus_helper_set_stride(inst, inst->out_width, in venc_init_session()
938 inst->out_height); in venc_init_session()
942 ret = venus_helper_set_input_resolution(inst, inst->width, in venc_init_session()
943 inst->height); in venc_init_session()
947 ret = venus_helper_set_output_resolution(inst, inst->width, in venc_init_session()
948 inst->height, in venc_init_session()
953 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); in venc_init_session()
986 struct venus_core *core = inst->core; in venc_queue_setup()
991 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
992 *num_planes != inst->fmt_out->num_planes) in venc_queue_setup()
993 return -EINVAL; in venc_queue_setup()
995 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
996 *num_planes != inst->fmt_cap->num_planes) in venc_queue_setup()
997 return -EINVAL; in venc_queue_setup()
999 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
1000 sizes[0] < inst->input_buf_size) in venc_queue_setup()
1001 return -EINVAL; in venc_queue_setup()
1003 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
1004 sizes[0] < inst->output_buf_size) in venc_queue_setup()
1005 return -EINVAL; in venc_queue_setup()
1010 if (test_bit(0, &core->sys_error)) { in venc_queue_setup()
1011 if (inst->nonblock) in venc_queue_setup()
1012 return -EAGAIN; in venc_queue_setup()
1014 ret = wait_event_interruptible(core->sys_err_done, in venc_queue_setup()
1015 !test_bit(0, &core->sys_error)); in venc_queue_setup()
1024 mutex_lock(&inst->lock); in venc_queue_setup()
1026 mutex_unlock(&inst->lock); in venc_queue_setup()
1035 switch (q->type) { in venc_queue_setup()
1037 *num_planes = inst->fmt_out->num_planes; in venc_queue_setup()
1043 num = max(num, min); in venc_queue_setup()
1044 *num_buffers = max(*num_buffers, num); in venc_queue_setup()
1045 inst->num_input_bufs = *num_buffers; in venc_queue_setup()
1047 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in venc_queue_setup()
1048 inst->out_width, in venc_queue_setup()
1049 inst->out_height); in venc_queue_setup()
1050 inst->input_buf_size = sizes[0]; in venc_queue_setup()
1053 *num_planes = inst->fmt_cap->num_planes; in venc_queue_setup()
1054 *num_buffers = max(*num_buffers, min); in venc_queue_setup()
1055 inst->num_output_bufs = *num_buffers; in venc_queue_setup()
1056 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in venc_queue_setup()
1057 inst->width, in venc_queue_setup()
1058 inst->height); in venc_queue_setup()
1059 sizes[0] = max(sizes[0], inst->output_buf_size); in venc_queue_setup()
1060 inst->output_buf_size = sizes[0]; in venc_queue_setup()
1063 ret = -EINVAL; in venc_queue_setup()
1075 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_init()
1077 inst->buf_count++; in venc_buf_init()
1088 mutex_lock(&inst->lock); in venc_release_session()
1091 if (ret || inst->session_error) in venc_release_session()
1094 mutex_unlock(&inst->lock); in venc_release_session()
1097 INIT_LIST_HEAD(&inst->registeredbufs); in venc_release_session()
1105 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_buf_cleanup()
1109 mutex_lock(&inst->lock); in venc_buf_cleanup()
1110 if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_buf_cleanup()
1111 if (!list_empty(&inst->registeredbufs)) in venc_buf_cleanup()
1112 list_del_init(&buf->reg_list); in venc_buf_cleanup()
1113 mutex_unlock(&inst->lock); in venc_buf_cleanup()
1115 inst->buf_count--; in venc_buf_cleanup()
1116 if (!inst->buf_count) in venc_buf_cleanup()
1122 enum hfi_version ver = inst->core->res->hfi_version; in venc_verify_conf()
1126 if (!inst->num_input_bufs || !inst->num_output_bufs) in venc_verify_conf()
1127 return -EINVAL; in venc_verify_conf()
1133 if (inst->num_output_bufs < bufreq.count_actual || in venc_verify_conf()
1134 inst->num_output_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
1135 return -EINVAL; in venc_verify_conf()
1141 if (inst->num_input_bufs < bufreq.count_actual || in venc_verify_conf()
1142 inst->num_input_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
1143 return -EINVAL; in venc_verify_conf()
1153 mutex_lock(&inst->lock); in venc_start_streaming()
1155 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1156 inst->streamon_out = 1; in venc_start_streaming()
1158 inst->streamon_cap = 1; in venc_start_streaming()
1160 if (!(inst->streamon_out & inst->streamon_cap)) { in venc_start_streaming()
1161 mutex_unlock(&inst->lock); in venc_start_streaming()
1167 inst->sequence_cap = 0; in venc_start_streaming()
1168 inst->sequence_out = 0; in venc_start_streaming()
1190 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in venc_start_streaming()
1191 inst->num_output_bufs, 0); in venc_start_streaming()
1199 mutex_unlock(&inst->lock); in venc_start_streaming()
1206 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in venc_start_streaming()
1207 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
1208 inst->streamon_out = 0; in venc_start_streaming()
1210 inst->streamon_cap = 0; in venc_start_streaming()
1211 mutex_unlock(&inst->lock); in venc_start_streaming()
1217 struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); in venc_vb2_buf_queue()
1221 mutex_lock(&inst->lock); in venc_vb2_buf_queue()
1223 mutex_unlock(&inst->lock); in venc_vb2_buf_queue()
1255 vbuf->flags = flags; in venc_buf_done()
1258 vb = &vbuf->vb2_buf; in venc_buf_done()
1260 vb->planes[0].data_offset = data_offset; in venc_buf_done()
1261 vb->timestamp = timestamp_us * NSEC_PER_USEC; in venc_buf_done()
1262 vbuf->sequence = inst->sequence_cap++; in venc_buf_done()
1264 vbuf->sequence = inst->sequence_out++; in venc_buf_done()
1273 struct device *dev = inst->core->dev_enc; in venc_event_notify()
1278 inst->session_error = true; in venc_event_notify()
1280 dev_err(dev, "enc: event session error %x\n", inst->error); in venc_event_notify()
1300 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in m2m_queue_init()
1301 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1302 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1303 src_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1304 src_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1305 src_vq->drv_priv = inst; in m2m_queue_init()
1306 src_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1307 src_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1308 src_vq->min_buffers_needed = 1; in m2m_queue_init()
1309 src_vq->dev = inst->core->dev; in m2m_queue_init()
1310 if (inst->core->res->hfi_version == HFI_VERSION_1XX) in m2m_queue_init()
1311 src_vq->bidirectional = 1; in m2m_queue_init()
1316 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in m2m_queue_init()
1317 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1318 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1319 dst_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1320 dst_vq->mem_ops = &vb2_dma_contig_memops; in m2m_queue_init()
1321 dst_vq->drv_priv = inst; in m2m_queue_init()
1322 dst_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1323 dst_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1324 dst_vq->min_buffers_needed = 1; in m2m_queue_init()
1325 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1331 inst->fmt_cap = &venc_formats[3]; in venc_inst_init()
1332 inst->fmt_out = &venc_formats[0]; in venc_inst_init()
1333 inst->width = 1280; in venc_inst_init()
1334 inst->height = ALIGN(720, 32); in venc_inst_init()
1335 inst->out_width = 1280; in venc_inst_init()
1336 inst->out_height = 720; in venc_inst_init()
1337 inst->fps = 15; in venc_inst_init()
1338 inst->timeperframe.numerator = 1; in venc_inst_init()
1339 inst->timeperframe.denominator = 15; in venc_inst_init()
1340 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in venc_inst_init()
1351 return -ENOMEM; in venc_open()
1353 INIT_LIST_HEAD(&inst->dpbbufs); in venc_open()
1354 INIT_LIST_HEAD(&inst->registeredbufs); in venc_open()
1355 INIT_LIST_HEAD(&inst->internalbufs); in venc_open()
1356 INIT_LIST_HEAD(&inst->list); in venc_open()
1357 mutex_init(&inst->lock); in venc_open()
1359 inst->core = core; in venc_open()
1360 inst->session_type = VIDC_SESSION_TYPE_ENC; in venc_open()
1361 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in venc_open()
1362 inst->core_acquired = false; in venc_open()
1363 inst->nonblock = file->f_flags & O_NONBLOCK; in venc_open()
1381 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); in venc_open()
1382 if (IS_ERR(inst->m2m_dev)) { in venc_open()
1383 ret = PTR_ERR(inst->m2m_dev); in venc_open()
1387 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in venc_open()
1388 if (IS_ERR(inst->m2m_ctx)) { in venc_open()
1389 ret = PTR_ERR(inst->m2m_ctx); in venc_open()
1393 v4l2_fh_init(&inst->fh, core->vdev_enc); in venc_open()
1395 inst->fh.ctrl_handler = &inst->ctrl_handler; in venc_open()
1396 v4l2_fh_add(&inst->fh); in venc_open()
1397 inst->fh.m2m_ctx = inst->m2m_ctx; in venc_open()
1398 file->private_data = &inst->fh; in venc_open()
1403 v4l2_m2m_release(inst->m2m_dev); in venc_open()
1419 v4l2_m2m_ctx_release(inst->m2m_ctx); in venc_close()
1420 v4l2_m2m_release(inst->m2m_dev); in venc_close()
1423 mutex_destroy(&inst->lock); in venc_close()
1424 v4l2_fh_del(&inst->fh); in venc_close()
1425 v4l2_fh_exit(&inst->fh); in venc_close()
1444 struct device *dev = &pdev->dev; in venc_probe()
1449 if (!dev->parent) in venc_probe()
1450 return -EPROBE_DEFER; in venc_probe()
1452 core = dev_get_drvdata(dev->parent); in venc_probe()
1454 return -EPROBE_DEFER; in venc_probe()
1458 if (core->pm_ops->venc_get) { in venc_probe()
1459 ret = core->pm_ops->venc_get(dev); in venc_probe()
1466 return -ENOMEM; in venc_probe()
1468 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); in venc_probe()
1469 vdev->release = video_device_release; in venc_probe()
1470 vdev->fops = &venc_fops; in venc_probe()
1471 vdev->ioctl_ops = &venc_ioctl_ops; in venc_probe()
1472 vdev->vfl_dir = VFL_DIR_M2M; in venc_probe()
1473 vdev->v4l2_dev = &core->v4l2_dev; in venc_probe()
1474 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; in venc_probe()
1476 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in venc_probe()
1480 core->vdev_enc = vdev; in venc_probe()
1481 core->dev_enc = dev; in venc_probe()
1497 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); in venc_remove()
1499 video_unregister_device(core->vdev_enc); in venc_remove()
1500 pm_runtime_disable(core->dev_enc); in venc_remove()
1502 if (core->pm_ops->venc_put) in venc_remove()
1503 core->pm_ops->venc_put(core->dev_enc); in venc_remove()
1511 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_suspend()
1514 if (pm_ops->venc_power) in venc_runtime_suspend()
1515 ret = pm_ops->venc_power(dev, POWER_OFF); in venc_runtime_suspend()
1523 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_resume()
1526 if (pm_ops->venc_power) in venc_runtime_resume()
1527 ret = pm_ops->venc_power(dev, POWER_ON); in venc_runtime_resume()
1539 { .compatible = "venus-encoder" },
1548 .name = "qcom-venus-encoder",
1555 MODULE_ALIAS("platform:qcom-venus-encoder");