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-sg.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()
188 pixmp->width = clamp(pixmp->width, frame_width_min(inst), in venc_try_fmt_common()
190 pixmp->height = clamp(pixmp->height, frame_height_min(inst), in venc_try_fmt_common()
193 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
194 pixmp->height = ALIGN(pixmp->height, 32); in venc_try_fmt_common()
196 pixmp->width = ALIGN(pixmp->width, 2); in venc_try_fmt_common()
197 pixmp->height = ALIGN(pixmp->height, 2); in venc_try_fmt_common()
199 if (pixmp->field == V4L2_FIELD_ANY) in venc_try_fmt_common()
200 pixmp->field = V4L2_FIELD_NONE; in venc_try_fmt_common()
201 pixmp->num_planes = fmt->num_planes; in venc_try_fmt_common()
202 pixmp->flags = 0; in venc_try_fmt_common()
204 sizeimage = venus_helper_get_framesz(pixmp->pixelformat, in venc_try_fmt_common()
205 pixmp->width, in venc_try_fmt_common()
206 pixmp->height); in venc_try_fmt_common()
207 pfmt[0].sizeimage = max(ALIGN(pfmt[0].sizeimage, SZ_4K), sizeimage); in venc_try_fmt_common()
209 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_try_fmt_common()
210 pfmt[0].bytesperline = ALIGN(pixmp->width, 128); in venc_try_fmt_common()
229 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_s_fmt()
236 q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type); in venc_s_fmt()
238 return -EINVAL; in venc_s_fmt()
241 return -EBUSY; in venc_s_fmt()
247 return -EINVAL; in venc_s_fmt()
249 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
250 pixfmt_out = pixmp->pixelformat; in venc_s_fmt()
251 pixfmt_cap = inst->fmt_cap->pixfmt; in venc_s_fmt()
252 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
253 pixfmt_cap = pixmp->pixelformat; in venc_s_fmt()
254 pixfmt_out = inst->fmt_out->pixfmt; in venc_s_fmt()
265 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_s_fmt()
266 inst->out_width = format.fmt.pix_mp.width; in venc_s_fmt()
267 inst->out_height = format.fmt.pix_mp.height; in venc_s_fmt()
268 inst->colorspace = pixmp->colorspace; in venc_s_fmt()
269 inst->ycbcr_enc = pixmp->ycbcr_enc; in venc_s_fmt()
270 inst->quantization = pixmp->quantization; in venc_s_fmt()
271 inst->xfer_func = pixmp->xfer_func; in venc_s_fmt()
282 inst->width = format.fmt.pix_mp.width; in venc_s_fmt()
283 inst->height = format.fmt.pix_mp.height; in venc_s_fmt()
285 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_fmt()
286 inst->fmt_out = fmt; in venc_s_fmt()
287 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_s_fmt()
288 inst->fmt_cap = fmt; in venc_s_fmt()
289 inst->output_buf_size = pixmp->plane_fmt[0].sizeimage; in venc_s_fmt()
297 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_g_fmt()
301 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) in venc_g_fmt()
302 fmt = inst->fmt_cap; in venc_g_fmt()
303 else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_fmt()
304 fmt = inst->fmt_out; in venc_g_fmt()
306 return -EINVAL; in venc_g_fmt()
308 pixmp->pixelformat = fmt->pixfmt; in venc_g_fmt()
310 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { in venc_g_fmt()
311 pixmp->width = inst->width; in venc_g_fmt()
312 pixmp->height = inst->height; in venc_g_fmt()
313 pixmp->colorspace = inst->colorspace; in venc_g_fmt()
314 pixmp->ycbcr_enc = inst->ycbcr_enc; in venc_g_fmt()
315 pixmp->quantization = inst->quantization; in venc_g_fmt()
316 pixmp->xfer_func = inst->xfer_func; in venc_g_fmt()
317 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { in venc_g_fmt()
318 pixmp->width = inst->out_width; in venc_g_fmt()
319 pixmp->height = inst->out_height; in venc_g_fmt()
332 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_g_selection()
333 return -EINVAL; in venc_g_selection()
335 switch (s->target) { in venc_g_selection()
338 s->r.width = inst->width; in venc_g_selection()
339 s->r.height = inst->height; 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 return -EINVAL; in venc_g_selection()
349 s->r.top = 0; in venc_g_selection()
350 s->r.left = 0; in venc_g_selection()
360 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in venc_s_selection()
361 return -EINVAL; in venc_s_selection()
363 switch (s->target) { 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 s->r.top != 0 || s->r.left != 0) in venc_s_selection()
368 return -EINVAL; in venc_s_selection()
371 return -EINVAL; in venc_s_selection()
380 struct v4l2_outputparm *out = &a->parm.output; in venc_s_parm()
381 struct v4l2_fract *timeperframe = &out->timeperframe; in venc_s_parm()
384 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_s_parm()
385 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_parm()
386 return -EINVAL; in venc_s_parm()
388 memset(out->reserved, 0, sizeof(out->reserved)); in venc_s_parm()
390 if (!timeperframe->denominator) in venc_s_parm()
391 timeperframe->denominator = inst->timeperframe.denominator; in venc_s_parm()
392 if (!timeperframe->numerator) in venc_s_parm()
393 timeperframe->numerator = inst->timeperframe.numerator; in venc_s_parm()
395 out->capability = V4L2_CAP_TIMEPERFRAME; in venc_s_parm()
397 us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; in venc_s_parm()
398 do_div(us_per_frame, timeperframe->denominator); in venc_s_parm()
401 return -EINVAL; in venc_s_parm()
406 inst->timeperframe = *timeperframe; in venc_s_parm()
407 inst->fps = fps; in venc_s_parm()
416 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_g_parm()
417 a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_parm()
418 return -EINVAL; in venc_g_parm()
420 a->parm.output.capability |= V4L2_CAP_TIMEPERFRAME; in venc_g_parm()
421 a->parm.output.timeperframe = inst->timeperframe; in venc_g_parm()
432 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in venc_enum_framesizes()
434 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
437 fmt = find_format(inst, fsize->pixel_format, in venc_enum_framesizes()
440 return -EINVAL; in venc_enum_framesizes()
443 if (fsize->index) in venc_enum_framesizes()
444 return -EINVAL; in venc_enum_framesizes()
446 fsize->stepwise.min_width = frame_width_min(inst); in venc_enum_framesizes()
447 fsize->stepwise.max_width = frame_width_max(inst); in venc_enum_framesizes()
448 fsize->stepwise.step_width = frame_width_step(inst); in venc_enum_framesizes()
449 fsize->stepwise.min_height = frame_height_min(inst); in venc_enum_framesizes()
450 fsize->stepwise.max_height = frame_height_max(inst); in venc_enum_framesizes()
451 fsize->stepwise.step_height = frame_height_step(inst); in venc_enum_framesizes()
463 fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; in venc_enum_frameintervals()
465 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
468 fmt = find_format(inst, fival->pixel_format, in venc_enum_frameintervals()
471 return -EINVAL; in venc_enum_frameintervals()
474 if (fival->index) in venc_enum_frameintervals()
475 return -EINVAL; in venc_enum_frameintervals()
477 if (!fival->width || !fival->height) in venc_enum_frameintervals()
478 return -EINVAL; in venc_enum_frameintervals()
480 if (fival->width > frame_width_max(inst) || in venc_enum_frameintervals()
481 fival->width < frame_width_min(inst) || in venc_enum_frameintervals()
482 fival->height > frame_height_max(inst) || in venc_enum_frameintervals()
483 fival->height < frame_height_min(inst)) in venc_enum_frameintervals()
484 return -EINVAL; in venc_enum_frameintervals()
486 if (IS_V1(inst->core)) { in venc_enum_frameintervals()
491 fival->stepwise.min.numerator = 1; in venc_enum_frameintervals()
492 fival->stepwise.min.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
493 fival->stepwise.max.numerator = 1; in venc_enum_frameintervals()
494 fival->stepwise.max.denominator = frate_min(inst) / framerate_factor; in venc_enum_frameintervals()
495 fival->stepwise.step.numerator = 1; in venc_enum_frameintervals()
496 fival->stepwise.step.denominator = frate_max(inst) / framerate_factor; in venc_enum_frameintervals()
532 struct venc_controls *ctr = &inst->controls.enc; in venc_set_properties()
539 u32 ptype, rate_control, bitrate; in venc_set_properties() local
549 frate.framerate = inst->fps * (1 << 16); in venc_set_properties()
555 if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { in venc_set_properties()
572 ctr->h264_entropy_mode); in venc_set_properties()
582 ctr->h264_loop_filter_mode); in venc_set_properties()
583 deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; in venc_set_properties()
584 deblock.slice_beta_offset = ctr->h264_loop_filter_beta; in venc_set_properties()
592 * n = 0 - only the first I-frame is IDR frame in venc_set_properties()
593 * n = 1 - all I-frames will be IDR frames in venc_set_properties()
594 * n > 1 - every n-th I-frame will be IDR frame in venc_set_properties()
602 if (ctr->num_b_frames) { in venc_set_properties()
612 intra_period.pframes = ctr->num_p_frames; in venc_set_properties()
613 intra_period.bframes = ctr->num_b_frames; in venc_set_properties()
619 if (!ctr->rc_enable) in venc_set_properties()
621 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) in venc_set_properties()
622 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_VBR_VFR : in venc_set_properties()
624 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) in venc_set_properties()
625 rate_control = ctr->frame_skip_mode ? HFI_RATE_CONTROL_CBR_VFR : in venc_set_properties()
627 else if (ctr->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) in venc_set_properties()
635 if (rate_control == HFI_RATE_CONTROL_CQ && ctr->const_quality) { in venc_set_properties()
639 quality.frame_quality = ctr->const_quality; in venc_set_properties()
645 if (!ctr->bitrate) in venc_set_properties()
646 bitrate = 64000; in venc_set_properties()
648 bitrate = ctr->bitrate; in venc_set_properties()
651 brate.bitrate = bitrate; in venc_set_properties()
658 if (!ctr->bitrate_peak) in venc_set_properties()
659 bitrate *= 2; in venc_set_properties()
661 bitrate = ctr->bitrate_peak; in venc_set_properties()
664 brate.bitrate = bitrate; in venc_set_properties()
672 quant.qp_i = ctr->h264_i_qp; in venc_set_properties()
673 quant.qp_p = ctr->h264_p_qp; in venc_set_properties()
674 quant.qp_b = ctr->h264_b_qp; in venc_set_properties()
681 quant_range.min_qp = ctr->h264_min_qp; in venc_set_properties()
682 quant_range.max_qp = ctr->h264_max_qp; in venc_set_properties()
688 switch (inst->hfi_codec) { in venc_set_properties()
690 profile = ctr->profile.h264; in venc_set_properties()
691 level = ctr->level.h264; in venc_set_properties()
694 profile = ctr->profile.mpeg4; in venc_set_properties()
695 level = ctr->level.mpeg4; in venc_set_properties()
698 profile = ctr->profile.vp8; in venc_set_properties()
702 profile = ctr->profile.vp9; in venc_set_properties()
703 level = ctr->level.vp9; in venc_set_properties()
706 profile = ctr->profile.hevc; in venc_set_properties()
707 level = ctr->level.hevc; in venc_set_properties()
727 ret = hfi_session_init(inst, inst->fmt_cap->pixfmt); in venc_init_session()
731 ret = venus_helper_set_input_resolution(inst, inst->width, in venc_init_session()
732 inst->height); in venc_init_session()
736 ret = venus_helper_set_output_resolution(inst, inst->width, in venc_init_session()
737 inst->height, in venc_init_session()
742 ret = venus_helper_set_color_format(inst, inst->fmt_out->pixfmt); in venc_init_session()
787 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
788 *num_planes != inst->fmt_out->num_planes) in venc_queue_setup()
789 return -EINVAL; in venc_queue_setup()
791 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
792 *num_planes != inst->fmt_cap->num_planes) in venc_queue_setup()
793 return -EINVAL; in venc_queue_setup()
795 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && in venc_queue_setup()
796 sizes[0] < inst->input_buf_size) in venc_queue_setup()
797 return -EINVAL; in venc_queue_setup()
799 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && in venc_queue_setup()
800 sizes[0] < inst->output_buf_size) in venc_queue_setup()
801 return -EINVAL; in venc_queue_setup()
806 switch (q->type) { in venc_queue_setup()
808 *num_planes = inst->fmt_out->num_planes; in venc_queue_setup()
814 num = max(num, min); in venc_queue_setup()
815 *num_buffers = max(*num_buffers, num); in venc_queue_setup()
816 inst->num_input_bufs = *num_buffers; in venc_queue_setup()
818 sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt, in venc_queue_setup()
819 inst->width, in venc_queue_setup()
820 inst->height); in venc_queue_setup()
821 inst->input_buf_size = sizes[0]; in venc_queue_setup()
824 *num_planes = inst->fmt_cap->num_planes; in venc_queue_setup()
825 *num_buffers = max(*num_buffers, min); in venc_queue_setup()
826 inst->num_output_bufs = *num_buffers; in venc_queue_setup()
827 sizes[0] = venus_helper_get_framesz(inst->fmt_cap->pixfmt, in venc_queue_setup()
828 inst->width, in venc_queue_setup()
829 inst->height); in venc_queue_setup()
830 sizes[0] = max(sizes[0], inst->output_buf_size); in venc_queue_setup()
831 inst->output_buf_size = sizes[0]; in venc_queue_setup()
834 ret = -EINVAL; in venc_queue_setup()
843 enum hfi_version ver = inst->core->res->hfi_version; in venc_verify_conf()
847 if (!inst->num_input_bufs || !inst->num_output_bufs) in venc_verify_conf()
848 return -EINVAL; in venc_verify_conf()
854 if (inst->num_output_bufs < bufreq.count_actual || in venc_verify_conf()
855 inst->num_output_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
856 return -EINVAL; in venc_verify_conf()
862 if (inst->num_input_bufs < bufreq.count_actual || in venc_verify_conf()
863 inst->num_input_bufs < HFI_BUFREQ_COUNT_MIN(&bufreq, ver)) in venc_verify_conf()
864 return -EINVAL; in venc_verify_conf()
874 mutex_lock(&inst->lock); in venc_start_streaming()
876 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
877 inst->streamon_out = 1; in venc_start_streaming()
879 inst->streamon_cap = 1; in venc_start_streaming()
881 if (!(inst->streamon_out & inst->streamon_cap)) { in venc_start_streaming()
882 mutex_unlock(&inst->lock); in venc_start_streaming()
888 inst->sequence_cap = 0; in venc_start_streaming()
889 inst->sequence_out = 0; in venc_start_streaming()
907 ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, in venc_start_streaming()
908 inst->num_output_bufs, 0); in venc_start_streaming()
916 mutex_unlock(&inst->lock); in venc_start_streaming()
923 venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); in venc_start_streaming()
924 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_start_streaming()
925 inst->streamon_out = 0; in venc_start_streaming()
927 inst->streamon_cap = 0; in venc_start_streaming()
928 mutex_unlock(&inst->lock); in venc_start_streaming()
958 vbuf->flags = flags; in venc_buf_done()
961 vb = &vbuf->vb2_buf; in venc_buf_done()
963 vb->planes[0].data_offset = data_offset; in venc_buf_done()
964 vb->timestamp = timestamp_us * NSEC_PER_USEC; in venc_buf_done()
965 vbuf->sequence = inst->sequence_cap++; in venc_buf_done()
967 vbuf->sequence = inst->sequence_out++; in venc_buf_done()
976 struct device *dev = inst->core->dev_enc; in venc_event_notify()
979 inst->session_error = true; in venc_event_notify()
980 dev_err(dev, "enc: event session error %x\n", inst->error); in venc_event_notify()
1000 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; in m2m_queue_init()
1001 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1002 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1003 src_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1004 src_vq->mem_ops = &vb2_dma_sg_memops; in m2m_queue_init()
1005 src_vq->drv_priv = inst; in m2m_queue_init()
1006 src_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1007 src_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1008 src_vq->min_buffers_needed = 1; in m2m_queue_init()
1009 src_vq->dev = inst->core->dev; in m2m_queue_init()
1010 if (inst->core->res->hfi_version == HFI_VERSION_1XX) in m2m_queue_init()
1011 src_vq->bidirectional = 1; in m2m_queue_init()
1016 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in m2m_queue_init()
1017 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in m2m_queue_init()
1018 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; in m2m_queue_init()
1019 dst_vq->ops = &venc_vb2_ops; in m2m_queue_init()
1020 dst_vq->mem_ops = &vb2_dma_sg_memops; in m2m_queue_init()
1021 dst_vq->drv_priv = inst; in m2m_queue_init()
1022 dst_vq->buf_struct_size = sizeof(struct venus_buffer); in m2m_queue_init()
1023 dst_vq->allow_zero_bytesused = 1; in m2m_queue_init()
1024 dst_vq->min_buffers_needed = 1; in m2m_queue_init()
1025 dst_vq->dev = inst->core->dev; in m2m_queue_init()
1031 inst->fmt_cap = &venc_formats[2]; in venc_inst_init()
1032 inst->fmt_out = &venc_formats[0]; in venc_inst_init()
1033 inst->width = 1280; in venc_inst_init()
1034 inst->height = ALIGN(720, 32); in venc_inst_init()
1035 inst->out_width = 1280; in venc_inst_init()
1036 inst->out_height = 720; in venc_inst_init()
1037 inst->fps = 15; in venc_inst_init()
1038 inst->timeperframe.numerator = 1; in venc_inst_init()
1039 inst->timeperframe.denominator = 15; in venc_inst_init()
1040 inst->hfi_codec = HFI_VIDEO_CODEC_H264; in venc_inst_init()
1051 return -ENOMEM; in venc_open()
1053 INIT_LIST_HEAD(&inst->dpbbufs); in venc_open()
1054 INIT_LIST_HEAD(&inst->registeredbufs); in venc_open()
1055 INIT_LIST_HEAD(&inst->internalbufs); in venc_open()
1056 INIT_LIST_HEAD(&inst->list); in venc_open()
1057 mutex_init(&inst->lock); in venc_open()
1059 inst->core = core; in venc_open()
1060 inst->session_type = VIDC_SESSION_TYPE_ENC; in venc_open()
1061 inst->clk_data.core_id = VIDC_CORE_ID_DEFAULT; in venc_open()
1062 inst->core_acquired = false; in venc_open()
1066 ret = pm_runtime_get_sync(core->dev_enc); in venc_open()
1084 inst->m2m_dev = v4l2_m2m_init(&venc_m2m_ops); in venc_open()
1085 if (IS_ERR(inst->m2m_dev)) { in venc_open()
1086 ret = PTR_ERR(inst->m2m_dev); in venc_open()
1090 inst->m2m_ctx = v4l2_m2m_ctx_init(inst->m2m_dev, inst, m2m_queue_init); in venc_open()
1091 if (IS_ERR(inst->m2m_ctx)) { in venc_open()
1092 ret = PTR_ERR(inst->m2m_ctx); in venc_open()
1096 v4l2_fh_init(&inst->fh, core->vdev_enc); in venc_open()
1098 inst->fh.ctrl_handler = &inst->ctrl_handler; in venc_open()
1099 v4l2_fh_add(&inst->fh); in venc_open()
1100 inst->fh.m2m_ctx = inst->m2m_ctx; in venc_open()
1101 file->private_data = &inst->fh; in venc_open()
1106 v4l2_m2m_release(inst->m2m_dev); in venc_open()
1112 pm_runtime_put_sync(core->dev_enc); in venc_open()
1121 v4l2_m2m_ctx_release(inst->m2m_ctx); in venc_close()
1122 v4l2_m2m_release(inst->m2m_dev); in venc_close()
1125 mutex_destroy(&inst->lock); in venc_close()
1126 v4l2_fh_del(&inst->fh); in venc_close()
1127 v4l2_fh_exit(&inst->fh); in venc_close()
1129 pm_runtime_put_sync(inst->core->dev_enc); in venc_close()
1146 struct device *dev = &pdev->dev; in venc_probe()
1151 if (!dev->parent) in venc_probe()
1152 return -EPROBE_DEFER; in venc_probe()
1154 core = dev_get_drvdata(dev->parent); in venc_probe()
1156 return -EPROBE_DEFER; in venc_probe()
1160 if (core->pm_ops->venc_get) { in venc_probe()
1161 ret = core->pm_ops->venc_get(dev); in venc_probe()
1168 return -ENOMEM; in venc_probe()
1170 strscpy(vdev->name, "qcom-venus-encoder", sizeof(vdev->name)); in venc_probe()
1171 vdev->release = video_device_release; in venc_probe()
1172 vdev->fops = &venc_fops; in venc_probe()
1173 vdev->ioctl_ops = &venc_ioctl_ops; in venc_probe()
1174 vdev->vfl_dir = VFL_DIR_M2M; in venc_probe()
1175 vdev->v4l2_dev = &core->v4l2_dev; in venc_probe()
1176 vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; in venc_probe()
1178 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in venc_probe()
1182 core->vdev_enc = vdev; in venc_probe()
1183 core->dev_enc = dev; in venc_probe()
1197 struct venus_core *core = dev_get_drvdata(pdev->dev.parent); in venc_remove()
1199 video_unregister_device(core->vdev_enc); in venc_remove()
1200 pm_runtime_disable(core->dev_enc); in venc_remove()
1202 if (core->pm_ops->venc_put) in venc_remove()
1203 core->pm_ops->venc_put(core->dev_enc); in venc_remove()
1211 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_suspend()
1214 if (pm_ops->venc_power) in venc_runtime_suspend()
1215 ret = pm_ops->venc_power(dev, POWER_OFF); in venc_runtime_suspend()
1223 const struct venus_pm_ops *pm_ops = core->pm_ops; in venc_runtime_resume()
1226 if (pm_ops->venc_power) in venc_runtime_resume()
1227 ret = pm_ops->venc_power(dev, POWER_ON); in venc_runtime_resume()
1239 { .compatible = "venus-encoder" },
1248 .name = "qcom-venus-encoder",
1255 MODULE_ALIAS("platform:qcom-venus-encoder");