17 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/version.h>
22 #include <linux/videodev2.h>
33 #define DEF_SRC_FMT_DEC V4L2_PIX_FMT_H264
34 #define DEF_DST_FMT_DEC V4L2_PIX_FMT_NV12MT_16X16
38 .name =
"4:2:0 2 Planes 16x16 Tiles",
45 .name =
"4:2:0 2 Planes 64x32 Tiles",
52 .name =
"4:2:0 2 Planes Y/CbCr",
59 .name =
"4:2:0 2 Planes Y/CrCb",
66 .name =
"H264 Encoded Stream",
73 .name =
"H264/MVC Encoded Stream",
80 .name =
"H263 Encoded Stream",
87 .name =
"MPEG1 Encoded Stream",
94 .name =
"MPEG2 Encoded Stream",
101 .name =
"MPEG4 Encoded Stream",
108 .name =
"XviD Encoded Stream",
115 .name =
"VC1 Encoded Stream",
122 .name =
"VC1 RCV Encoded Stream",
129 .name =
"VP8 Encoded Stream",
137 #define NUM_FORMATS ARRAY_SIZE(formats)
146 formats[i].
type == t)
156 .name =
"H264 Display Delay",
165 .name =
"H264 Display Delay Enable",
174 .name =
"Mpeg4 Loop Filter Enable",
183 .name =
"Slice Interface Enable",
192 .name =
"Minimum number of cap bufs",
201 #define NUM_CTRLS ARRAY_SIZE(controls)
236 .pre_seq_start =
NULL,
237 .post_seq_start =
NULL,
238 .pre_frame_start =
NULL,
239 .post_frame_start =
NULL,
243 static int vidioc_querycap(
struct file *
file,
void *
priv,
251 cap->
version = KERNEL_VERSION(1, 0, 0);
272 else if (!mplane && formats[i].
num_planes > 1)
291 static int vidioc_enum_fmt_vid_cap(
struct file *
file,
void *pirv,
294 return vidioc_enum_fmt(f,
false,
false);
297 static int vidioc_enum_fmt_vid_cap_mplane(
struct file *
file,
void *pirv,
300 return vidioc_enum_fmt(f,
true,
false);
303 static int vidioc_enum_fmt_vid_out(
struct file *
file,
void *prov,
306 return vidioc_enum_fmt(f,
false,
true);
309 static int vidioc_enum_fmt_vid_out_mplane(
struct file *
file,
void *prov,
312 return vidioc_enum_fmt(f,
true,
true);
363 mfc_err(
"Format could not be read\n");
364 mfc_debug(2,
"%s-- with error\n", __func__);
372 static int vidioc_try_fmt(
struct file *file,
void *priv,
struct v4l2_format *f)
381 mfc_err(
"Unsupported format for source.\n");
385 mfc_err(
"Not supported format.\n");
391 mfc_err(
"Unsupported format for destination.\n");
395 mfc_err(
"Not supported format.\n");
399 mfc_err(
"Not supported format.\n");
408 static int vidioc_s_fmt(
struct file *file,
void *priv,
struct v4l2_format *f)
417 ret = vidioc_try_fmt(file, priv, f);
429 mfc_err(
"Unsupported format for source.\n");
433 mfc_err(
"Not supported format.\n");
437 mfc_err(
"Not supported format.\n");
444 mfc_err(
"Wrong type error for S_FMT : %d", f->
type);
454 mfc_err(
"Wrong format selected, you should choose "
455 "format for decoding\n");
460 mfc_err(
"Not supported format.\n");
481 static int vidioc_reqbufs(
struct file *file,
void *priv,
489 mfc_err(
"Only V4L2_MEMORY_MAP is supported\n");
496 if (reqbufs->
count == 0) {
505 mfc_err(
"Bufs have already been requested\n");
512 mfc_err(
"vb2_reqbufs on output failed\n");
520 if (reqbufs->
count == 0) {
528 mfc_err(
"Bufs have already been requested\n");
536 mfc_err(
"vb2_reqbufs on capture failed\n");
540 mfc_err(
"Not enough buffers allocated\n");
550 mfc_err(
"Failed to allocate decoding buffers\n");
560 mfc_err(
"Not all buffers passed to buf_init\n");
569 if (s5p_mfc_ctx_ready(ctx))
579 static int vidioc_querybuf(
struct file *file,
void *priv,
587 mfc_err(
"Only mmaped buffers can be used\n");
597 for (i = 0; i < buf->
length; i++)
600 mfc_err(
"vidioc_querybuf called in an inappropriate state\n");
608 static int vidioc_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *buf)
613 mfc_err(
"Call on QBUF after unrecoverable error\n");
624 static int vidioc_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *buf)
629 mfc_err(
"Call on DQBUF after unrecoverable error\n");
640 static int vidioc_streamon(
struct file *file,
void *priv,
666 mfc_err(
"Error getting instance from hardware\n");
668 release_instance_buffer, ctx);
670 release_dec_desc_buffer, ctx);
684 static int vidioc_streamoff(
struct file *file,
void *priv,
715 mfc_err(
"Invalid control 0x%08x\n", ctrl->
id);
721 static int s5p_mfc_dec_g_v_ctrl(
struct v4l2_ctrl *ctrl)
754 .s_ctrl = s5p_mfc_dec_s_ctrl,
755 .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl,
759 static int vidioc_g_crop(
struct file *file,
void *priv,
783 mfc_debug(2,
"Cropping info [h264]: l=%d t=%d "
784 "w=%d h=%d (r=%d b=%d fw=%d fh=%d\n", left, top,
785 cr->
c.width, cr->
c.height, right, bottom,
792 mfc_debug(2,
"Cropping info: w=%d h=%d fw=%d "
793 "fh=%d\n", cr->
c.width, cr->
c.height, ctx->
buf_width,
806 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
807 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
808 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
809 .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt,
810 .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt,
811 .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt,
821 static int s5p_mfc_queue_setup(
struct vb2_queue *vq,
822 const struct v4l2_format *fmt,
unsigned int *buf_count,
823 unsigned int *plane_count,
unsigned int psize[],
846 if (*buf_count < ctx->dpb_count)
853 mfc_err(
"State seems invalid. State = %d, vq->type = %d\n",
857 mfc_debug(2,
"Buffer count=%d, plane count=%d\n",
858 *buf_count, *plane_count);
876 mfc_err(
"This video node is dedicated to decoding. Decoding not initalised\n");
882 static void s5p_mfc_unlock(
struct vb2_queue *
q)
898 static int s5p_mfc_buf_init(
struct vb2_buffer *vb)
907 for (i = 0; i <= ctx->
src_fmt->num_planes ; i++) {
908 if (IS_ERR_OR_NULL(ERR_PTR(
909 vb2_dma_contig_plane_dma_addr(vb, i)))) {
910 mfc_err(
"Plane mem not allocated\n");
914 if (vb2_plane_size(vb, 0) < ctx->
luma_size ||
916 mfc_err(
"Plane buffer (CAPTURE) is too small\n");
922 vb2_dma_contig_plane_dma_addr(vb, 0);
924 vb2_dma_contig_plane_dma_addr(vb, 1);
927 if (IS_ERR_OR_NULL(ERR_PTR(
928 vb2_dma_contig_plane_dma_addr(vb, 0)))) {
929 mfc_err(
"Plane memory not allocated\n");
933 mfc_err(
"Plane buffer (OUTPUT) is too small\n");
940 vb2_dma_contig_plane_dma_addr(vb, 0);
943 mfc_err(
"s5p_mfc_buf_init: unknown queue type\n");
949 static int s5p_mfc_start_streaming(
struct vb2_queue *
q,
unsigned int count)
959 if (s5p_mfc_ctx_ready(ctx))
965 static int s5p_mfc_stop_streaming(
struct vb2_queue *q)
997 spin_unlock_irqrestore(&dev->
irqlock, flags);
1002 static void s5p_mfc_buf_queue(
struct vb2_buffer *vb)
1007 unsigned long flags;
1016 spin_unlock_irqrestore(&dev->
irqlock, flags);
1025 spin_unlock_irqrestore(&dev->
irqlock, flags);
1027 mfc_err(
"Unsupported buffer type (%d)\n", vq->
type);
1029 if (s5p_mfc_ctx_ready(ctx))
1034 static struct vb2_ops s5p_mfc_dec_qops = {
1035 .queue_setup = s5p_mfc_queue_setup,
1036 .wait_prepare = s5p_mfc_unlock,
1037 .wait_finish = s5p_mfc_lock,
1038 .buf_init = s5p_mfc_buf_init,
1039 .start_streaming = s5p_mfc_start_streaming,
1040 .stop_streaming = s5p_mfc_stop_streaming,
1041 .buf_queue = s5p_mfc_buf_queue,
1046 return &decoder_codec_ops;
1051 return &s5p_mfc_dec_qops;
1056 return &s5p_mfc_dec_ioctl_ops;
1059 #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
1060 && V4L2_CTRL_DRIVER_PRIV(x))
1069 mfc_err(
"v4l2_ctrl_handler_init failed\n");
1076 cfg.
ops = &s5p_mfc_dec_ctrl_ops;
1077 cfg.
id = controls[
i].
id;
1091 &s5p_mfc_dec_ctrl_ops,
1097 mfc_err(
"Adding control (%d) failed\n", i);
1100 if (controls[i].is_volatile && ctx->
ctrls[i])
1122 mfc_debug(2,
"Default src_fmt is %x, dest_fmt is %x\n",