1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2016 MediaTek Inc. 4 * Author: Daniel Hsiao <[email protected]> 5 * Jungchang Tsao <[email protected]> 6 * Tiffany Lin <[email protected]> 7 */ 8 9 #include <linux/interrupt.h> 10 #include <linux/kernel.h> 11 #include <linux/slab.h> 12 13 #include "venc_drv_base.h" 14 #include "venc_drv_if.h" 15 16 #include "mtk_vcodec_enc.h" 17 #include "mtk_vcodec_enc_pm.h" 18 19 int venc_if_init(struct mtk_vcodec_enc_ctx *ctx, unsigned int fourcc) 20 { 21 int ret = 0; 22 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; 32 } 33 34 mtk_venc_lock(ctx); 35 ret = ctx->enc_if->init(ctx); 36 mtk_venc_unlock(ctx); 37 38 return ret; 39 } 40 41 int venc_if_set_param(struct mtk_vcodec_enc_ctx *ctx, 42 enum venc_set_param_type type, struct venc_enc_param *in) 43 { 44 int ret = 0; 45 46 mtk_venc_lock(ctx); 47 ret = ctx->enc_if->set_param(ctx->drv_handle, type, in); 48 mtk_venc_unlock(ctx); 49 50 return ret; 51 } 52 53 int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx, 54 enum venc_start_opt opt, struct venc_frm_buf *frm_buf, 55 struct mtk_vcodec_mem *bs_buf, 56 struct venc_done_result *result) 57 { 58 int ret = 0; 59 unsigned long flags; 60 61 mtk_venc_lock(ctx); 62 63 spin_lock_irqsave(&ctx->dev->irqlock, flags); 64 ctx->dev->curr_ctx = ctx; 65 spin_unlock_irqrestore(&ctx->dev->irqlock, flags); 66 67 mtk_vcodec_enc_pw_on(&ctx->dev->pm); 68 mtk_vcodec_enc_clock_on(&ctx->dev->pm); 69 ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf, 70 bs_buf, result); 71 mtk_vcodec_enc_clock_off(&ctx->dev->pm); 72 mtk_vcodec_enc_pw_off(&ctx->dev->pm); 73 74 spin_lock_irqsave(&ctx->dev->irqlock, flags); 75 ctx->dev->curr_ctx = NULL; 76 spin_unlock_irqrestore(&ctx->dev->irqlock, flags); 77 78 mtk_venc_unlock(ctx); 79 return ret; 80 } 81 82 int venc_if_deinit(struct mtk_vcodec_enc_ctx *ctx) 83 { 84 int ret = 0; 85 86 if (!ctx->drv_handle) 87 return 0; 88 89 mtk_venc_lock(ctx); 90 ret = ctx->enc_if->deinit(ctx->drv_handle); 91 mtk_venc_unlock(ctx); 92 93 ctx->drv_handle = NULL; 94 95 return ret; 96 } 97