2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: Daniel Hsiao <daniel.hsiao@mediatek.com>
4 * Jungchang Tsao <jungchang.tsao@mediatek.com>
5 * Tiffany Lin <tiffany.lin@mediatek.com>
7 * This program is free software; you can redistribute it and/or
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/slab.h>
22 #include "venc_drv_base.h"
23 #include "venc_drv_if.h"
25 #include "mtk_vcodec_enc.h"
26 #include "mtk_vcodec_enc_pm.h"
29 const struct venc_common_if *get_h264_enc_comm_if(void);
30 const struct venc_common_if *get_vp8_enc_comm_if(void);
32 int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
37 case V4L2_PIX_FMT_VP8:
38 ctx->enc_if = get_vp8_enc_comm_if();
40 case V4L2_PIX_FMT_H264:
41 ctx->enc_if = get_h264_enc_comm_if();
48 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
49 ret = ctx->enc_if->init(ctx, (unsigned long *)&ctx->drv_handle);
50 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
56 int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
57 enum venc_set_param_type type, struct venc_enc_param *in)
62 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
63 ret = ctx->enc_if->set_param(ctx->drv_handle, type, in);
64 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
70 int venc_if_encode(struct mtk_vcodec_ctx *ctx,
71 enum venc_start_opt opt, struct venc_frm_buf *frm_buf,
72 struct mtk_vcodec_mem *bs_buf,
73 struct venc_done_result *result)
80 spin_lock_irqsave(&ctx->dev->irqlock, flags);
81 ctx->dev->curr_ctx = ctx;
82 spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
84 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
85 ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf,
87 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
89 spin_lock_irqsave(&ctx->dev->irqlock, flags);
90 ctx->dev->curr_ctx = NULL;
91 spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
97 int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
101 if (ctx->drv_handle == 0)
105 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
106 ret = ctx->enc_if->deinit(ctx->drv_handle);
107 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
108 mtk_venc_unlock(ctx);