diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index d3ac63b53..9b2a42ebf 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -653,13 +653,18 @@ static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx) ctx->state = MFCINST_FINISHED; + /* Called from the interrupt handler, under dev->irqlock */ if (!list_empty(&ctx->dst_queue)) { mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list); list_del(&mb_entry->list); ctx->dst_queue_cnt--; vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0); + /* Tell the client that the drain is done */ + mb_entry->b->flags |= V4L2_BUF_FLAG_LAST; vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE); + } else { + ctx->last_pending = true; } clear_work_bit(ctx); @@ -1470,18 +1475,6 @@ static int s5p_mfc_probe(struct platform_device *pdev) v4l2_info(&dev->v4l2_dev, "decoder registered as /dev/video%d\n", dev->vfd_dec->num); - /* - * The v15 encoder's registers differ from v12's (0xF770/0xF774 clash - * with the decoder's) and nothing here programs them yet: no encoder - * node rather than one that hangs the firmware. - */ - if (IS_MFCV15(dev)) { - video_device_release(dev->vfd_enc); - dev->vfd_enc = NULL; - pr_debug("%s--\n", __func__); - return 0; - } - ret = video_register_device(dev->vfd_enc, VFL_TYPE_VIDEO, 0); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h index 8abf5104e..551a47100 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h @@ -573,6 +573,8 @@ struct s5p_mfc_codec_ops { * @dst_queue_cnt: number of buffers queued on the dest internal queue * @type: type of the instance - decoder or encoder * @state: state of the context + * @last_pending: the encoder drained with no capture buffer queued: the + * next one is returned empty with V4L2_BUF_FLAG_LAST * @inst_no: number of hw instance associated with the context * @img_width: width of the image that is decoded or encoded * @img_height: height of the image that is decoded or encoded @@ -662,6 +664,7 @@ struct s5p_mfc_ctx { enum s5p_mfc_inst_type type; enum s5p_mfc_inst_state state; + bool last_pending; int inst_no; /* Image parameters */ diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c index 3f8701e56..2c8bcf6f5 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c @@ -50,14 +50,14 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_NONE, .type = MFC_FMT_RAW, .num_planes = 2, - .versions = MFC_V5PLUS_BITS, + .versions = MFC_V5PLUS_BITS & ~MFC_V15_BIT, }, { .fourcc = V4L2_PIX_FMT_NV21M, .codec_mode = S5P_MFC_CODEC_NONE, .type = MFC_FMT_RAW, .num_planes = 2, - .versions = MFC_V6PLUS_BITS, + .versions = MFC_V6PLUS_BITS & ~MFC_V15_BIT, }, { .fourcc = V4L2_PIX_FMT_YUV420M, @@ -73,6 +73,13 @@ static const struct s5p_mfc_fmt formats[] = { .num_planes = 3, .versions = MFC_V12_BIT, }, + { + .fourcc = V4L2_PIX_FMT_NV12, + .codec_mode = S5P_MFC_CODEC_NONE, + .type = MFC_FMT_RAW, + .num_planes = 1, + .versions = MFC_V15_BIT, + }, { .fourcc = V4L2_PIX_FMT_H264, .codec_mode = S5P_MFC_CODEC_H264_ENC, @@ -85,14 +92,14 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_MPEG4_ENC, .type = MFC_FMT_ENC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = MFC_V5PLUS_BITS & ~MFC_V15_BIT, }, { .fourcc = V4L2_PIX_FMT_H263, .codec_mode = S5P_MFC_CODEC_H263_ENC, .type = MFC_FMT_ENC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = MFC_V5PLUS_BITS & ~MFC_V15_BIT, }, { .fourcc = V4L2_PIX_FMT_VP8, @@ -747,7 +754,7 @@ static struct mfc_control controls[] = { .minimum = 0, .maximum = 51, .step = 1, - .default_value = 0, + .default_value = 51, }, { .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE, @@ -1165,7 +1172,13 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx) struct s5p_mfc_enc_params *p = &ctx->enc_params; struct s5p_mfc_buf *dst_mb; - if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) { + /* + * VP8 on v15 has no header (no IVF), so the stream size reads 0 here: + * an empty buffer would look like the end of the stream. + */ + if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE && + (!IS_MFCV15(dev) || + s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev))) { if (!list_empty(&ctx->dst_queue)) { dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list); @@ -1198,6 +1211,30 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx) return 0; } +/* + * Bytes of a one-buffer NV12 source: both planes, then room for the rows + * the MFC reads past the chroma (its height rounded up to 16) and the + * 256 bytes it wants after a plane. + */ +static unsigned int enc_nv12_size(struct s5p_mfc_ctx *ctx) +{ + return ctx->luma_size + ctx->chroma_size + 8 * ctx->stride[1] + + MFC_CHROMA_PAD_BYTES_V12; +} + +/* + * Source plane addresses. NV12 in one buffer has its chroma right after + * the luma's bytesperline * height. + */ +static unsigned long enc_src_addr(struct s5p_mfc_ctx *ctx, + struct vb2_buffer *vb, unsigned int plane) +{ + if (ctx->src_fmt->num_planes == 1) + return vb2_dma_contig_plane_dma_addr(vb, 0) + + (plane ? ctx->luma_size : 0); + return vb2_dma_contig_plane_dma_addr(vb, plane); +} + static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx) { struct s5p_mfc_dev *dev = ctx->dev; @@ -1207,8 +1244,8 @@ static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx) unsigned int dst_size; src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); - src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0); - src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1); + src_y_addr = enc_src_addr(ctx, &src_mb->b->vb2_buf, 0); + src_c_addr = enc_src_addr(ctx, &src_mb->b->vb2_buf, 1); if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == V4L2_PIX_FMT_YVU420M) src_c_1_addr = @@ -1236,6 +1273,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) int slice_type; unsigned int strm_size; bool src_ready; + u64 timestamp = 0; slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev); strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev); @@ -1247,10 +1285,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) s5p_mfc_hw_call(dev->mfc_ops, get_enc_frame_buffer, ctx, &enc_y_addr, &enc_c_addr, &enc_c_1_addr); list_for_each_entry(mb_entry, &ctx->src_queue, list) { - mb_y_addr = vb2_dma_contig_plane_dma_addr( - &mb_entry->b->vb2_buf, 0); - mb_c_addr = vb2_dma_contig_plane_dma_addr( - &mb_entry->b->vb2_buf, 1); + mb_y_addr = enc_src_addr(ctx, &mb_entry->b->vb2_buf, 0); + mb_c_addr = enc_src_addr(ctx, &mb_entry->b->vb2_buf, 1); if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == @@ -1263,16 +1299,15 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) == mb_c_1_addr) { list_del(&mb_entry->list); ctx->src_queue_cnt--; + timestamp = mb_entry->b->vb2_buf.timestamp; vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE); break; } } list_for_each_entry(mb_entry, &ctx->ref_queue, list) { - mb_y_addr = vb2_dma_contig_plane_dma_addr( - &mb_entry->b->vb2_buf, 0); - mb_c_addr = vb2_dma_contig_plane_dma_addr( - &mb_entry->b->vb2_buf, 1); + mb_y_addr = enc_src_addr(ctx, &mb_entry->b->vb2_buf, 0); + mb_c_addr = enc_src_addr(ctx, &mb_entry->b->vb2_buf, 1); if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == V4L2_PIX_FMT_YVU420M) @@ -1284,6 +1319,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) == mb_c_1_addr) { list_del(&mb_entry->list); ctx->ref_queue_cnt--; + timestamp = mb_entry->b->vb2_buf.timestamp; vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE); break; @@ -1319,6 +1355,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx) mb_entry->b->flags |= V4L2_BUF_FLAG_BFRAME; break; } + /* The frame just encoded is the source buffer found above */ + mb_entry->b->vb2_buf.timestamp = timestamp; vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size); vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE); } @@ -1421,6 +1459,8 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_fmt_mp->plane_fmt[2].bytesperline = ctx->stride[2]; pix_fmt_mp->plane_fmt[2].sizeimage = ctx->chroma_size_1; } + if (ctx->src_fmt->num_planes == 1) + pix_fmt_mp->plane_fmt[0].sizeimage = enc_nv12_size(ctx); } else { mfc_err("invalid buf type\n"); return -EINVAL; @@ -1463,6 +1503,17 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) else v4l_bound_align_image(&pix_fmt_mp->width, 8, 1920, 1, &pix_fmt_mp ->height, 4, 1080, 1, 0); + pix_fmt_mp->field = V4L2_FIELD_NONE; + pix_fmt_mp->num_planes = fmt->num_planes; + /* Same layout as enc_calc_src_size() and enc_nv12_size() */ + if (fmt->num_planes == 1) { + unsigned int stride = ALIGN(pix_fmt_mp->width, 64); + + pix_fmt_mp->plane_fmt[0].bytesperline = stride; + pix_fmt_mp->plane_fmt[0].sizeimage = + stride * pix_fmt_mp->height * 3 / 2 + + 8 * stride + MFC_CHROMA_PAD_BYTES_V12; + } } else { mfc_err("invalid buf type\n"); return -EINVAL; @@ -1480,7 +1531,8 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) ret = vidioc_try_fmt(file, priv, f); if (ret) return ret; - if (ctx->vq_src.streaming || ctx->vq_dst.streaming) { + if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ? + ctx->vq_dst.streaming : ctx->vq_src.streaming) { v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__); ret = -EBUSY; goto out; @@ -1490,6 +1542,10 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) ctx->dst_fmt = find_format(f, MFC_FMT_ENC); ctx->state = MFCINST_INIT; ctx->codec_mode = ctx->dst_fmt->codec_mode; + /* A client may leave the bitstream buffer's size to us */ + if (!pix_fmt_mp->plane_fmt[0].sizeimage) + pix_fmt_mp->plane_fmt[0].sizeimage = + dev->variant->buf_size->cpb; ctx->enc_dst_buf_size = pix_fmt_mp->plane_fmt[0].sizeimage; pix_fmt_mp->plane_fmt[0].bytesperline = 0; ctx->dst_bufs_cnt = 0; @@ -1515,6 +1571,10 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_fmt_mp->plane_fmt[2].bytesperline = ctx->stride[2]; pix_fmt_mp->plane_fmt[2].sizeimage = ctx->chroma_size_1; } + if (ctx->src_fmt->num_planes == 1) { + pix_fmt_mp->num_planes = 1; + pix_fmt_mp->plane_fmt[0].sizeimage = enc_nv12_size(ctx); + } ctx->src_bufs_cnt = 0; ctx->output_state = QUEUE_FREE; @@ -2287,6 +2347,7 @@ static int vidioc_s_parm(struct file *file, void *priv, struct s5p_mfc_ctx *ctx = file_to_ctx(file); if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + a->parm.output.capability = V4L2_CAP_TIMEPERFRAME; ctx->enc_params.rc_framerate_num = a->parm.output.timeperframe.denominator; ctx->enc_params.rc_framerate_denom = @@ -2303,7 +2364,9 @@ static int vidioc_g_parm(struct file *file, void *priv, { struct s5p_mfc_ctx *ctx = file_to_ctx(file); - if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT || + a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + a->parm.output.capability = V4L2_CAP_TIMEPERFRAME; a->parm.output.timeperframe.denominator = ctx->enc_params.rc_framerate_num; a->parm.output.timeperframe.numerator = @@ -2450,6 +2513,8 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, psize[0] = ctx->luma_size; psize[1] = ctx->chroma_size; + if (ctx->src_fmt && ctx->src_fmt->num_planes == 1) + psize[0] = enc_nv12_size(ctx); if (ctx->src_fmt && (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == V4L2_PIX_FMT_YVU420M)) @@ -2496,10 +2561,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb) return ret; i = vb->index; ctx->src_bufs[i].b = vbuf; - ctx->src_bufs[i].cookie.raw.luma = - vb2_dma_contig_plane_dma_addr(vb, 0); - ctx->src_bufs[i].cookie.raw.chroma = - vb2_dma_contig_plane_dma_addr(vb, 1); + ctx->src_bufs[i].cookie.raw.luma = enc_src_addr(ctx, vb, 0); + ctx->src_bufs[i].cookie.raw.chroma = enc_src_addr(ctx, vb, 1); if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == V4L2_PIX_FMT_YVU420M) @@ -2537,7 +2600,9 @@ static int s5p_mfc_buf_prepare(struct vb2_buffer *vb) vb2_plane_size(vb, 0), ctx->luma_size); mfc_debug(2, "plane size: %ld, chroma size: %d\n", vb2_plane_size(vb, 1), ctx->chroma_size); - if (vb2_plane_size(vb, 0) < ctx->luma_size || + if (ctx->src_fmt->num_planes == 1 ? + vb2_plane_size(vb, 0) < enc_nv12_size(ctx) : + vb2_plane_size(vb, 0) < ctx->luma_size || vb2_plane_size(vb, 1) < ctx->chroma_size) { mfc_err("plane size is too small for output\n"); return -EINVAL; @@ -2600,6 +2665,7 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q) } ctx->state = MFCINST_FINISHED; spin_lock_irqsave(&dev->irqlock, flags); + ctx->last_pending = false; if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst); INIT_LIST_HEAD(&ctx->dst_queue); @@ -2632,6 +2698,15 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb) mfc_buf->flags &= ~MFC_BUF_FLAG_USED; /* Mark destination as available for use by MFC */ spin_lock_irqsave(&dev->irqlock, flags); + if (ctx->last_pending) { + /* The drain ended while no buffer was queued */ + ctx->last_pending = false; + spin_unlock_irqrestore(&dev->irqlock, flags); + vb2_set_plane_payload(vb, 0, 0); + to_vb2_v4l2_buffer(vb)->flags |= V4L2_BUF_FLAG_LAST; + vb2_buffer_done(vb, VB2_BUF_STATE_DONE); + return; + } list_add_tail(&mfc_buf->list, &ctx->dst_queue); ctx->dst_queue_cnt++; spin_unlock_irqrestore(&dev->irqlock, flags); @@ -2713,11 +2788,21 @@ int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx) if ((controls[i].type == V4L2_CTRL_TYPE_MENU) || (controls[i].type == V4L2_CTRL_TYPE_INTEGER_MENU)) { + s32 def = controls[i].default_value; + + /* + * On v15 the header comes with the first frame + * by default: GStreamer expects one capture + * buffer per frame and drops the extra one. + */ + if (controls[i].id == + V4L2_CID_MPEG_VIDEO_HEADER_MODE && + IS_MFCV15(ctx->dev)) + def = V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME; ctx->ctrls[i] = v4l2_ctrl_new_std_menu( &ctx->ctrl_handler, &s5p_mfc_enc_ctrl_ops, controls[i].id, - controls[i].maximum, 0, - controls[i].default_value); + controls[i].maximum, 0, def); } else { ctx->ctrls[i] = v4l2_ctrl_new_std( &ctx->ctrl_handler, @@ -2750,7 +2835,8 @@ void s5p_mfc_enc_ctrls_delete(struct s5p_mfc_ctx *ctx) void s5p_mfc_enc_init(struct s5p_mfc_ctx *ctx) { struct v4l2_format f; - f.fmt.pix_mp.pixelformat = DEF_SRC_FMT_ENC; + f.fmt.pix_mp.pixelformat = IS_MFCV15(ctx->dev) ? V4L2_PIX_FMT_NV12 : + DEF_SRC_FMT_ENC; ctx->src_fmt = find_format(&f, MFC_FMT_RAW); f.fmt.pix_mp.pixelformat = DEF_DST_FMT_ENC; ctx->dst_fmt = find_format(&f, MFC_FMT_ENC); diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c index 3f1e6e694..eaad16804 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c @@ -563,6 +563,18 @@ static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx) if (IS_MFCV12(ctx->dev)) { switch (ctx->src_fmt->fourcc) { + case V4L2_PIX_FMT_NV12: + /* + * One buffer, laid out as V4L2 NV12: a 64 byte aligned + * stride (as Google's NV12N) and the chroma right after + * bytesperline * height. + */ + ctx->stride[0] = ALIGN(ctx->img_width, 64); + ctx->stride[1] = ctx->stride[0]; + ctx->luma_size = ctx->stride[0] * ctx->img_height; + ctx->chroma_size = ctx->stride[1] * ctx->img_height / 2; + ctx->chroma_size_1 = 0; + return; case V4L2_PIX_FMT_NV12M: case V4L2_PIX_FMT_NV21M: ctx->stride[0] = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6); @@ -913,10 +925,17 @@ static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx) mfc_debug_enter(); - /* width */ - writel(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */ - /* height */ - writel(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */ + /* + * MFC v15 has no frame width and height registers: the encoder + * takes the cropped size, and 0xF770/0xF774 are the decoder's + * payload registers there (as in Google's exynos-mfc driver). + */ + if (!IS_MFCV15(dev)) { + /* width */ + writel(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */ + /* height */ + writel(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */ + } /* cropped width */ writel(ctx->img_width, mfc_regs->e_cropped_frame_width); @@ -964,7 +983,8 @@ static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx) writel(reg, mfc_regs->e_enc_options); /* memory structure cur. frame */ - if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) { + if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M || + ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12) { /* 0: Linear, 1: 2D tiled*/ reg = readl(mfc_regs->e_enc_options); reg &= ~(0x1 << 7); @@ -1191,8 +1211,9 @@ static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx) /* height */ if (p_h264->interlace) { - writel(ctx->img_height >> 1, - mfc_regs->e_frame_height); /* 32 align */ + if (!IS_MFCV15(dev)) + writel(ctx->img_height >> 1, + mfc_regs->e_frame_height); /* 32 align */ /* cropped height */ writel(ctx->img_height >> 1, mfc_regs->e_cropped_frame_height); @@ -1580,7 +1601,8 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx) writel(reg, mfc_regs->e_rc_frame_rate); } - /* frame QP */ + /* frame QP: reg may hold the frame rate now */ + reg = readl(mfc_regs->e_rc_config); reg &= ~(0x7F); reg |= p_vp8->rc_frame_qp & 0x7F; writel(reg, mfc_regs->e_rc_config); @@ -1628,6 +1650,12 @@ static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx) } reg |= (val & 0xF) << 3; reg |= (p_vp8->num_ref & 0x2); + /* + * MFC v15 wraps VP8 in IVF (file and frame headers) unless bit 12 is + * set; V4L2_PIX_FMT_VP8 is bare frames (Google's driver sets it too). + */ + if (IS_MFCV15(dev)) + reg |= BIT(12); writel(reg, mfc_regs->e_vp8_options); mfc_debug_leave(); @@ -1755,13 +1783,19 @@ static int s5p_mfc_set_enc_params_hevc(struct s5p_mfc_ctx *ctx) reg |= p_hevc->rc_frame_qp; writel(reg, mfc_regs->e_rc_config); - /* frame rate */ + /* + * frame rate: the one set with S_PARM, as for the other codecs, or + * else the HEVC frame rate control (1 fps by default) + */ if (p->rc_frame) { reg = 0; - reg &= ~(0xFFFF << 16); - reg |= ((p_hevc->rc_framerate) << 16); - reg &= ~(0xFFFF); - reg |= FRAME_DELTA_DEFAULT; + if (p->rc_framerate_num && p->rc_framerate_denom) { + reg |= ((p->rc_framerate_num & 0xFFFF) << 16); + reg |= p->rc_framerate_denom & 0xFFFF; + } else { + reg |= ((p_hevc->rc_framerate) << 16); + reg |= FRAME_DELTA_DEFAULT; + } writel(reg, mfc_regs->e_rc_frame_rate); } @@ -2138,7 +2172,11 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx) ctx->state = MFCINST_FINISHING; } else { src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0); - src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1); + /* One-buffer NV12: the chroma follows the luma */ + if (ctx->src_fmt->num_planes == 1) + src_c_addr = src_y_addr + ctx->luma_size; + else + src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1); if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->src_fmt->fourcc == V4L2_PIX_FMT_YVU420M) src_c_1_addr = vb2_dma_contig_plane_dma_addr