Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / venc_drv_if.c
blobce0bce81161599a243bbb278a4db70252907431c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Daniel Hsiao <daniel.hsiao@mediatek.com>
5 * Jungchang Tsao <jungchang.tsao@mediatek.com>
6 * Tiffany Lin <tiffany.lin@mediatek.com>
7 */
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
13 #include "venc_drv_base.h"
14 #include "venc_drv_if.h"
16 #include "mtk_vcodec_enc.h"
17 #include "mtk_vcodec_enc_pm.h"
19 int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
21 int ret = 0;
23 switch (fourcc) {
24 case V4L2_PIX_FMT_VP8:
25 ctx->enc_if = &venc_vp8_if;
26 break;
27 case V4L2_PIX_FMT_H264:
28 ctx->enc_if = &venc_h264_if;
29 break;
30 default:
31 return -EINVAL;
34 mtk_venc_lock(ctx);
35 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
36 ret = ctx->enc_if->init(ctx);
37 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
38 mtk_venc_unlock(ctx);
40 return ret;
43 int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
44 enum venc_set_param_type type, struct venc_enc_param *in)
46 int ret = 0;
48 mtk_venc_lock(ctx);
49 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
50 ret = ctx->enc_if->set_param(ctx->drv_handle, type, in);
51 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
52 mtk_venc_unlock(ctx);
54 return ret;
57 int venc_if_encode(struct mtk_vcodec_ctx *ctx,
58 enum venc_start_opt opt, struct venc_frm_buf *frm_buf,
59 struct mtk_vcodec_mem *bs_buf,
60 struct venc_done_result *result)
62 int ret = 0;
63 unsigned long flags;
65 mtk_venc_lock(ctx);
67 spin_lock_irqsave(&ctx->dev->irqlock, flags);
68 ctx->dev->curr_ctx = ctx;
69 spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
71 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
72 ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf,
73 bs_buf, result);
74 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
76 spin_lock_irqsave(&ctx->dev->irqlock, flags);
77 ctx->dev->curr_ctx = NULL;
78 spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
80 mtk_venc_unlock(ctx);
81 return ret;
84 int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
86 int ret = 0;
88 if (!ctx->drv_handle)
89 return 0;
91 mtk_venc_lock(ctx);
92 mtk_vcodec_enc_clock_on(&ctx->dev->pm);
93 ret = ctx->enc_if->deinit(ctx->drv_handle);
94 mtk_vcodec_enc_clock_off(&ctx->dev->pm);
95 mtk_venc_unlock(ctx);
97 ctx->drv_handle = NULL;
99 return ret;