1 // SPDX-License-Identifier: GPL-2.0
3 * Hantro VPU codec driver
5 * Copyright (C) 2018 Collabora, Ltd.
6 * Copyright (C) 2018 Rockchip Electronics Co., Ltd.
7 * Alpha Lin <Alpha.Lin@rock-chips.com>
8 * Jeffy Chen <jeffy.chen@rock-chips.com>
10 * Copyright 2018 Google LLC.
11 * Tomasz Figa <tfiga@chromium.org>
13 * Based on s5p-mfc driver by Samsung Electronics Co., Ltd.
14 * Copyright (C) 2010-2011 Samsung Electronics Co., Ltd.
17 #include <linux/interrupt.h>
19 #include <linux/module.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/videodev2.h>
22 #include <linux/workqueue.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-event.h>
25 #include <media/v4l2-mem2mem.h>
26 #include <media/videobuf2-core.h>
27 #include <media/videobuf2-dma-sg.h>
30 #include "hantro_hw.h"
31 #include "hantro_v4l2.h"
33 static int hantro_set_fmt_out(struct hantro_ctx *ctx,
34 struct v4l2_pix_format_mplane *pix_mp);
35 static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
36 struct v4l2_pix_format_mplane *pix_mp);
38 static const struct hantro_fmt *
39 hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
41 const struct hantro_fmt *formats;
43 if (ctx->is_encoder) {
44 formats = ctx->dev->variant->enc_fmts;
45 *num_fmts = ctx->dev->variant->num_enc_fmts;
47 formats = ctx->dev->variant->dec_fmts;
48 *num_fmts = ctx->dev->variant->num_dec_fmts;
54 static const struct hantro_fmt *
55 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
56 unsigned int *num_fmts)
58 struct hantro_dev *vpu = ctx->dev;
60 if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
65 *num_fmts = ctx->dev->variant->num_postproc_fmts;
66 return ctx->dev->variant->postproc_fmts;
69 static const struct hantro_fmt *
70 hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)
72 const struct hantro_fmt *formats;
73 unsigned int i, num_fmts;
75 formats = hantro_get_formats(ctx, &num_fmts);
76 for (i = 0; i < num_fmts; i++)
77 if (formats[i].fourcc == fourcc)
80 formats = hantro_get_postproc_formats(ctx, &num_fmts);
81 for (i = 0; i < num_fmts; i++)
82 if (formats[i].fourcc == fourcc)
87 static const struct hantro_fmt *
88 hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream)
90 const struct hantro_fmt *formats;
91 unsigned int i, num_fmts;
93 formats = hantro_get_formats(ctx, &num_fmts);
94 for (i = 0; i < num_fmts; i++) {
95 if (bitstream == (formats[i].codec_mode !=
102 static int vidioc_querycap(struct file *file, void *priv,
103 struct v4l2_capability *cap)
105 struct hantro_dev *vpu = video_drvdata(file);
106 struct video_device *vdev = video_devdata(file);
108 strscpy(cap->driver, vpu->dev->driver->name, sizeof(cap->driver));
109 strscpy(cap->card, vdev->name, sizeof(cap->card));
110 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform: %s",
111 vpu->dev->driver->name);
115 static int vidioc_enum_framesizes(struct file *file, void *priv,
116 struct v4l2_frmsizeenum *fsize)
118 struct hantro_ctx *ctx = fh_to_ctx(priv);
119 const struct hantro_fmt *fmt;
121 if (fsize->index != 0) {
122 vpu_debug(0, "invalid frame size index (expected 0, got %d)\n",
127 fmt = hantro_find_format(ctx, fsize->pixel_format);
129 vpu_debug(0, "unsupported bitstream format (%08x)\n",
130 fsize->pixel_format);
134 /* This only makes sense for coded formats */
135 if (fmt->codec_mode == HANTRO_MODE_NONE)
138 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
139 fsize->stepwise = fmt->frmsize;
144 static int vidioc_enum_fmt(struct file *file, void *priv,
145 struct v4l2_fmtdesc *f, bool capture)
148 struct hantro_ctx *ctx = fh_to_ctx(priv);
149 const struct hantro_fmt *fmt, *formats;
150 unsigned int num_fmts, i, j = 0;
154 * When dealing with an encoder:
155 * - on the capture side we want to filter out all MODE_NONE formats.
156 * - on the output side we want to filter out all formats that are
158 * When dealing with a decoder:
159 * - on the capture side we want to filter out all formats that are
161 * - on the output side we want to filter out all MODE_NONE formats.
163 skip_mode_none = capture == ctx->is_encoder;
165 formats = hantro_get_formats(ctx, &num_fmts);
166 for (i = 0; i < num_fmts; i++) {
167 bool mode_none = formats[i].codec_mode == HANTRO_MODE_NONE;
169 if (skip_mode_none == mode_none)
173 f->pixelformat = fmt->fourcc;
180 * Enumerate post-processed formats. As per the specification,
181 * we enumerated these formats after natively decoded formats
182 * as a hint for applications on what's the preferred fomat.
186 formats = hantro_get_postproc_formats(ctx, &num_fmts);
187 for (i = 0; i < num_fmts; i++) {
190 f->pixelformat = fmt->fourcc;
199 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
200 struct v4l2_fmtdesc *f)
202 return vidioc_enum_fmt(file, priv, f, true);
205 static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
206 struct v4l2_fmtdesc *f)
208 return vidioc_enum_fmt(file, priv, f, false);
211 static int vidioc_g_fmt_out_mplane(struct file *file, void *priv,
212 struct v4l2_format *f)
214 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
215 struct hantro_ctx *ctx = fh_to_ctx(priv);
217 vpu_debug(4, "f->type = %d\n", f->type);
219 *pix_mp = ctx->src_fmt;
224 static int vidioc_g_fmt_cap_mplane(struct file *file, void *priv,
225 struct v4l2_format *f)
227 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
228 struct hantro_ctx *ctx = fh_to_ctx(priv);
230 vpu_debug(4, "f->type = %d\n", f->type);
232 *pix_mp = ctx->dst_fmt;
237 static int hantro_try_fmt(const struct hantro_ctx *ctx,
238 struct v4l2_pix_format_mplane *pix_mp,
239 enum v4l2_buf_type type)
241 const struct hantro_fmt *fmt, *vpu_fmt;
242 bool capture = V4L2_TYPE_IS_CAPTURE(type);
245 coded = capture == ctx->is_encoder;
247 vpu_debug(4, "trying format %c%c%c%c\n",
248 (pix_mp->pixelformat & 0x7f),
249 (pix_mp->pixelformat >> 8) & 0x7f,
250 (pix_mp->pixelformat >> 16) & 0x7f,
251 (pix_mp->pixelformat >> 24) & 0x7f);
253 fmt = hantro_find_format(ctx, pix_mp->pixelformat);
255 fmt = hantro_get_default_fmt(ctx, coded);
256 pix_mp->pixelformat = fmt->fourcc;
260 pix_mp->num_planes = 1;
262 } else if (ctx->is_encoder) {
263 vpu_fmt = ctx->vpu_dst_fmt;
265 vpu_fmt = ctx->vpu_src_fmt;
267 * Width/height on the CAPTURE end of a decoder are ignored and
268 * replaced by the OUTPUT ones.
270 pix_mp->width = ctx->src_fmt.width;
271 pix_mp->height = ctx->src_fmt.height;
274 pix_mp->field = V4L2_FIELD_NONE;
276 v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
280 /* Fill remaining fields */
281 v4l2_fill_pixfmt_mp(pix_mp, fmt->fourcc, pix_mp->width,
283 if (ctx->vpu_src_fmt->fourcc == V4L2_PIX_FMT_H264_SLICE &&
284 !hantro_needs_postproc(ctx, fmt))
285 pix_mp->plane_fmt[0].sizeimage +=
286 hantro_h264_mv_size(pix_mp->width,
288 } else if (!pix_mp->plane_fmt[0].sizeimage) {
290 * For coded formats the application can specify
291 * sizeimage. If the application passes a zero sizeimage,
292 * let's default to the maximum frame size.
294 pix_mp->plane_fmt[0].sizeimage = fmt->header_size +
295 pix_mp->width * pix_mp->height * fmt->max_depth;
301 static int vidioc_try_fmt_cap_mplane(struct file *file, void *priv,
302 struct v4l2_format *f)
304 return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
307 static int vidioc_try_fmt_out_mplane(struct file *file, void *priv,
308 struct v4l2_format *f)
310 return hantro_try_fmt(fh_to_ctx(priv), &f->fmt.pix_mp, f->type);
314 hantro_reset_fmt(struct v4l2_pix_format_mplane *fmt,
315 const struct hantro_fmt *vpu_fmt)
317 memset(fmt, 0, sizeof(*fmt));
319 fmt->pixelformat = vpu_fmt->fourcc;
320 fmt->field = V4L2_FIELD_NONE;
321 fmt->colorspace = V4L2_COLORSPACE_JPEG;
322 fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
323 fmt->quantization = V4L2_QUANTIZATION_DEFAULT;
324 fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT;
328 hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
330 const struct hantro_fmt *vpu_fmt;
331 struct v4l2_pix_format_mplane *fmt;
333 vpu_fmt = hantro_get_default_fmt(ctx, true);
335 if (ctx->is_encoder) {
336 ctx->vpu_dst_fmt = vpu_fmt;
339 ctx->vpu_src_fmt = vpu_fmt;
343 hantro_reset_fmt(fmt, vpu_fmt);
344 fmt->width = vpu_fmt->frmsize.min_width;
345 fmt->height = vpu_fmt->frmsize.min_height;
347 hantro_set_fmt_cap(ctx, fmt);
349 hantro_set_fmt_out(ctx, fmt);
353 hantro_reset_raw_fmt(struct hantro_ctx *ctx)
355 const struct hantro_fmt *raw_vpu_fmt;
356 struct v4l2_pix_format_mplane *raw_fmt, *encoded_fmt;
358 raw_vpu_fmt = hantro_get_default_fmt(ctx, false);
360 if (ctx->is_encoder) {
361 ctx->vpu_src_fmt = raw_vpu_fmt;
362 raw_fmt = &ctx->src_fmt;
363 encoded_fmt = &ctx->dst_fmt;
365 ctx->vpu_dst_fmt = raw_vpu_fmt;
366 raw_fmt = &ctx->dst_fmt;
367 encoded_fmt = &ctx->src_fmt;
370 hantro_reset_fmt(raw_fmt, raw_vpu_fmt);
371 raw_fmt->width = encoded_fmt->width;
372 raw_fmt->height = encoded_fmt->height;
374 hantro_set_fmt_out(ctx, raw_fmt);
376 hantro_set_fmt_cap(ctx, raw_fmt);
379 void hantro_reset_fmts(struct hantro_ctx *ctx)
381 hantro_reset_encoded_fmt(ctx);
382 hantro_reset_raw_fmt(ctx);
386 hantro_update_requires_request(struct hantro_ctx *ctx, u32 fourcc)
389 case V4L2_PIX_FMT_JPEG:
390 ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = false;
392 case V4L2_PIX_FMT_MPEG2_SLICE:
393 case V4L2_PIX_FMT_VP8_FRAME:
394 case V4L2_PIX_FMT_H264_SLICE:
395 case V4L2_PIX_FMT_HEVC_SLICE:
396 ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
403 static int hantro_set_fmt_out(struct hantro_ctx *ctx,
404 struct v4l2_pix_format_mplane *pix_mp)
406 struct vb2_queue *vq;
409 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
410 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
411 ret = hantro_try_fmt(ctx, pix_mp, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
415 if (!ctx->is_encoder) {
416 struct vb2_queue *peer_vq;
419 * In order to support dynamic resolution change,
420 * the decoder admits a resolution change, as long
421 * as the pixelformat remains. Can't be done if streaming.
423 if (vb2_is_streaming(vq) || (vb2_is_busy(vq) &&
424 pix_mp->pixelformat != ctx->src_fmt.pixelformat))
427 * Since format change on the OUTPUT queue will reset
428 * the CAPTURE queue, we can't allow doing so
429 * when the CAPTURE queue has buffers allocated.
431 peer_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
432 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
433 if (vb2_is_busy(peer_vq))
437 * The encoder doesn't admit a format change if
438 * there are OUTPUT buffers allocated.
444 ctx->vpu_src_fmt = hantro_find_format(ctx, pix_mp->pixelformat);
445 ctx->src_fmt = *pix_mp;
448 * Current raw format might have become invalid with newly
449 * selected codec, so reset it to default just to be safe and
450 * keep internal driver state sane. User is mandated to set
451 * the raw format again after we return, so we don't need
453 * Note that hantro_reset_raw_fmt() also propagates size
454 * changes to the raw format.
456 if (!ctx->is_encoder)
457 hantro_reset_raw_fmt(ctx);
459 /* Colorimetry information are always propagated. */
460 ctx->dst_fmt.colorspace = pix_mp->colorspace;
461 ctx->dst_fmt.ycbcr_enc = pix_mp->ycbcr_enc;
462 ctx->dst_fmt.xfer_func = pix_mp->xfer_func;
463 ctx->dst_fmt.quantization = pix_mp->quantization;
465 hantro_update_requires_request(ctx, pix_mp->pixelformat);
467 vpu_debug(0, "OUTPUT codec mode: %d\n", ctx->vpu_src_fmt->codec_mode);
468 vpu_debug(0, "fmt - w: %d, h: %d\n",
469 pix_mp->width, pix_mp->height);
473 static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
474 struct v4l2_pix_format_mplane *pix_mp)
476 struct vb2_queue *vq;
479 /* Change not allowed if queue is busy. */
480 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
481 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
485 if (ctx->is_encoder) {
486 struct vb2_queue *peer_vq;
489 * Since format change on the CAPTURE queue will reset
490 * the OUTPUT queue, we can't allow doing so
491 * when the OUTPUT queue has buffers allocated.
493 peer_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
494 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
495 if (vb2_is_busy(peer_vq) &&
496 (pix_mp->pixelformat != ctx->dst_fmt.pixelformat ||
497 pix_mp->height != ctx->dst_fmt.height ||
498 pix_mp->width != ctx->dst_fmt.width))
502 ret = hantro_try_fmt(ctx, pix_mp, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
506 ctx->vpu_dst_fmt = hantro_find_format(ctx, pix_mp->pixelformat);
507 ctx->dst_fmt = *pix_mp;
510 * Current raw format might have become invalid with newly
511 * selected codec, so reset it to default just to be safe and
512 * keep internal driver state sane. User is mandated to set
513 * the raw format again after we return, so we don't need
515 * Note that hantro_reset_raw_fmt() also propagates size
516 * changes to the raw format.
519 hantro_reset_raw_fmt(ctx);
521 /* Colorimetry information are always propagated. */
522 ctx->src_fmt.colorspace = pix_mp->colorspace;
523 ctx->src_fmt.ycbcr_enc = pix_mp->ycbcr_enc;
524 ctx->src_fmt.xfer_func = pix_mp->xfer_func;
525 ctx->src_fmt.quantization = pix_mp->quantization;
527 vpu_debug(0, "CAPTURE codec mode: %d\n", ctx->vpu_dst_fmt->codec_mode);
528 vpu_debug(0, "fmt - w: %d, h: %d\n",
529 pix_mp->width, pix_mp->height);
531 hantro_update_requires_request(ctx, pix_mp->pixelformat);
537 vidioc_s_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
539 return hantro_set_fmt_out(fh_to_ctx(priv), &f->fmt.pix_mp);
543 vidioc_s_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f)
545 return hantro_set_fmt_cap(fh_to_ctx(priv), &f->fmt.pix_mp);
548 const struct v4l2_ioctl_ops hantro_ioctl_ops = {
549 .vidioc_querycap = vidioc_querycap,
550 .vidioc_enum_framesizes = vidioc_enum_framesizes,
552 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt_cap_mplane,
553 .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt_out_mplane,
554 .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt_out_mplane,
555 .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt_cap_mplane,
556 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt_out_mplane,
557 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt_cap_mplane,
558 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
559 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
561 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
562 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
563 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
564 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
565 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
566 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
567 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
569 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
570 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
572 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
573 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
577 hantro_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
578 unsigned int *num_planes, unsigned int sizes[],
579 struct device *alloc_devs[])
581 struct hantro_ctx *ctx = vb2_get_drv_priv(vq);
582 struct v4l2_pix_format_mplane *pixfmt;
586 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
587 pixfmt = &ctx->dst_fmt;
589 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
590 pixfmt = &ctx->src_fmt;
593 vpu_err("invalid queue type: %d\n", vq->type);
598 if (*num_planes != pixfmt->num_planes)
600 for (i = 0; i < pixfmt->num_planes; ++i)
601 if (sizes[i] < pixfmt->plane_fmt[i].sizeimage)
606 *num_planes = pixfmt->num_planes;
607 for (i = 0; i < pixfmt->num_planes; ++i)
608 sizes[i] = pixfmt->plane_fmt[i].sizeimage;
613 hantro_buf_plane_check(struct vb2_buffer *vb,
614 struct v4l2_pix_format_mplane *pixfmt)
619 for (i = 0; i < pixfmt->num_planes; ++i) {
620 sz = pixfmt->plane_fmt[i].sizeimage;
621 vpu_debug(4, "plane %d size: %ld, sizeimage: %u\n",
622 i, vb2_plane_size(vb, i), sz);
623 if (vb2_plane_size(vb, i) < sz) {
624 vpu_err("plane %d is too small for output\n", i);
631 static int hantro_buf_prepare(struct vb2_buffer *vb)
633 struct vb2_queue *vq = vb->vb2_queue;
634 struct hantro_ctx *ctx = vb2_get_drv_priv(vq);
635 struct v4l2_pix_format_mplane *pix_fmt;
638 if (V4L2_TYPE_IS_OUTPUT(vq->type))
639 pix_fmt = &ctx->src_fmt;
641 pix_fmt = &ctx->dst_fmt;
642 ret = hantro_buf_plane_check(vb, pix_fmt);
646 * Buffer's bytesused must be written by driver for CAPTURE buffers.
647 * (for OUTPUT buffers, if userspace passes 0 bytesused, v4l2-core sets
648 * it to buffer length).
650 if (V4L2_TYPE_IS_CAPTURE(vq->type))
651 vb2_set_plane_payload(vb, 0, pix_fmt->plane_fmt[0].sizeimage);
656 static void hantro_buf_queue(struct vb2_buffer *vb)
658 struct hantro_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
659 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
661 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
664 static bool hantro_vq_is_coded(struct vb2_queue *q)
666 struct hantro_ctx *ctx = vb2_get_drv_priv(q);
668 return ctx->is_encoder != V4L2_TYPE_IS_OUTPUT(q->type);
671 static int hantro_start_streaming(struct vb2_queue *q, unsigned int count)
673 struct hantro_ctx *ctx = vb2_get_drv_priv(q);
676 if (V4L2_TYPE_IS_OUTPUT(q->type))
677 ctx->sequence_out = 0;
679 ctx->sequence_cap = 0;
681 if (hantro_vq_is_coded(q)) {
682 enum hantro_codec_mode codec_mode;
684 if (V4L2_TYPE_IS_OUTPUT(q->type))
685 codec_mode = ctx->vpu_src_fmt->codec_mode;
687 codec_mode = ctx->vpu_dst_fmt->codec_mode;
689 vpu_debug(4, "Codec mode = %d\n", codec_mode);
690 ctx->codec_ops = &ctx->dev->variant->codec_ops[codec_mode];
691 if (ctx->codec_ops->init) {
692 ret = ctx->codec_ops->init(ctx);
697 if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt)) {
698 ret = hantro_postproc_alloc(ctx);
706 if (ctx->codec_ops->exit)
707 ctx->codec_ops->exit(ctx);
712 hantro_return_bufs(struct vb2_queue *q,
713 struct vb2_v4l2_buffer *(*buf_remove)(struct v4l2_m2m_ctx *))
715 struct hantro_ctx *ctx = vb2_get_drv_priv(q);
718 struct vb2_v4l2_buffer *vbuf;
720 vbuf = buf_remove(ctx->fh.m2m_ctx);
723 v4l2_ctrl_request_complete(vbuf->vb2_buf.req_obj.req,
725 v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
729 static void hantro_stop_streaming(struct vb2_queue *q)
731 struct hantro_ctx *ctx = vb2_get_drv_priv(q);
733 if (hantro_vq_is_coded(q)) {
734 hantro_postproc_free(ctx);
735 if (ctx->codec_ops && ctx->codec_ops->exit)
736 ctx->codec_ops->exit(ctx);
740 * The mem2mem framework calls v4l2_m2m_cancel_job before
741 * .stop_streaming, so there isn't any job running and
742 * it is safe to return all the buffers.
744 if (V4L2_TYPE_IS_OUTPUT(q->type))
745 hantro_return_bufs(q, v4l2_m2m_src_buf_remove);
747 hantro_return_bufs(q, v4l2_m2m_dst_buf_remove);
750 static void hantro_buf_request_complete(struct vb2_buffer *vb)
752 struct hantro_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
754 v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->ctrl_handler);
757 static int hantro_buf_out_validate(struct vb2_buffer *vb)
759 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
761 vbuf->field = V4L2_FIELD_NONE;
765 const struct vb2_ops hantro_queue_ops = {
766 .queue_setup = hantro_queue_setup,
767 .buf_prepare = hantro_buf_prepare,
768 .buf_queue = hantro_buf_queue,
769 .buf_out_validate = hantro_buf_out_validate,
770 .buf_request_complete = hantro_buf_request_complete,
771 .start_streaming = hantro_start_streaming,
772 .stop_streaming = hantro_stop_streaming,
773 .wait_prepare = vb2_ops_wait_prepare,
774 .wait_finish = vb2_ops_wait_finish,