perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / vdec_drv_if.c
blob5ffc468dd9105a68a56b6dcdf39bf2f145e46a5b
1 /*
2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: PC Chen <pc.chen@mediatek.com>
4 * Tiffany Lin <tiffany.lin@mediatek.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
20 #include "vdec_drv_if.h"
21 #include "mtk_vcodec_dec.h"
22 #include "vdec_drv_base.h"
23 #include "mtk_vcodec_dec_pm.h"
24 #include "mtk_vpu.h"
26 const struct vdec_common_if *get_h264_dec_comm_if(void);
27 const struct vdec_common_if *get_vp8_dec_comm_if(void);
28 const struct vdec_common_if *get_vp9_dec_comm_if(void);
30 int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
32 int ret = 0;
34 switch (fourcc) {
35 case V4L2_PIX_FMT_H264:
36 ctx->dec_if = get_h264_dec_comm_if();
37 break;
38 case V4L2_PIX_FMT_VP8:
39 ctx->dec_if = get_vp8_dec_comm_if();
40 break;
41 case V4L2_PIX_FMT_VP9:
42 ctx->dec_if = get_vp9_dec_comm_if();
43 break;
44 default:
45 return -EINVAL;
48 mtk_vdec_lock(ctx);
49 mtk_vcodec_dec_clock_on(&ctx->dev->pm);
50 ret = ctx->dec_if->init(ctx, &ctx->drv_handle);
51 mtk_vcodec_dec_clock_off(&ctx->dev->pm);
52 mtk_vdec_unlock(ctx);
54 return ret;
57 int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
58 struct vdec_fb *fb, bool *res_chg)
60 int ret = 0;
62 if (bs) {
63 if ((bs->dma_addr & 63) != 0) {
64 mtk_v4l2_err("bs dma_addr should 64 byte align");
65 return -EINVAL;
69 if (fb) {
70 if (((fb->base_y.dma_addr & 511) != 0) ||
71 ((fb->base_c.dma_addr & 511) != 0)) {
72 mtk_v4l2_err("frame buffer dma_addr should 512 byte align");
73 return -EINVAL;
77 if (ctx->drv_handle == 0)
78 return -EIO;
80 mtk_vdec_lock(ctx);
82 mtk_vcodec_set_curr_ctx(ctx->dev, ctx);
83 mtk_vcodec_dec_clock_on(&ctx->dev->pm);
84 enable_irq(ctx->dev->dec_irq);
85 ret = ctx->dec_if->decode(ctx->drv_handle, bs, fb, res_chg);
86 disable_irq(ctx->dev->dec_irq);
87 mtk_vcodec_dec_clock_off(&ctx->dev->pm);
88 mtk_vcodec_set_curr_ctx(ctx->dev, NULL);
90 mtk_vdec_unlock(ctx);
92 return ret;
95 int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
96 void *out)
98 int ret = 0;
100 if (ctx->drv_handle == 0)
101 return -EIO;
103 mtk_vdec_lock(ctx);
104 ret = ctx->dec_if->get_param(ctx->drv_handle, type, out);
105 mtk_vdec_unlock(ctx);
107 return ret;
110 void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
112 if (ctx->drv_handle == 0)
113 return;
115 mtk_vdec_lock(ctx);
116 mtk_vcodec_dec_clock_on(&ctx->dev->pm);
117 ctx->dec_if->deinit(ctx->drv_handle);
118 mtk_vcodec_dec_clock_off(&ctx->dev->pm);
119 mtk_vdec_unlock(ctx);
121 ctx->drv_handle = 0;