1 /*
2 * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Description:
19 */
20 #include <linux/interrupt.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23
24 #include "vdec_drv_if.h"
25 #include "aml_vcodec_dec.h"
26 #include "vdec_drv_base.h"
27
28 const struct vdec_common_if *get_h264_dec_comm_if(void);
29 const struct vdec_common_if *get_hevc_dec_comm_if(void);
30 const struct vdec_common_if *get_vp9_dec_comm_if(void);
31 const struct vdec_common_if *get_mpeg12_dec_comm_if(void);
32 const struct vdec_common_if *get_mpeg4_dec_comm_if(void);
33 const struct vdec_common_if *get_mjpeg_dec_comm_if(void);
34
vdec_if_init(struct aml_vcodec_ctx * ctx,unsigned int fourcc)35 int vdec_if_init(struct aml_vcodec_ctx *ctx, unsigned int fourcc)
36 {
37 int ret = 0;
38
39 switch (fourcc) {
40 case V4L2_PIX_FMT_H264:
41 ctx->dec_if = get_h264_dec_comm_if();
42 break;
43 case V4L2_PIX_FMT_HEVC:
44 ctx->dec_if = get_hevc_dec_comm_if();
45 break;
46 case V4L2_PIX_FMT_VP9:
47 ctx->dec_if = get_vp9_dec_comm_if();
48 break;
49 case V4L2_PIX_FMT_MPEG:
50 case V4L2_PIX_FMT_MPEG1:
51 case V4L2_PIX_FMT_MPEG2:
52 ctx->dec_if = get_mpeg12_dec_comm_if();
53 break;
54 case V4L2_PIX_FMT_MPEG4:
55 ctx->dec_if = get_mpeg4_dec_comm_if();
56 break;
57 case V4L2_PIX_FMT_MJPEG:
58 ctx->dec_if = get_mjpeg_dec_comm_if();
59 break;
60 default:
61 return -EINVAL;
62 }
63
64 ret = ctx->dec_if->init(ctx, &ctx->drv_handle);
65
66 return ret;
67 }
68
vdec_if_probe(struct aml_vcodec_ctx * ctx,struct aml_vcodec_mem * bs,void * out)69 int vdec_if_probe(struct aml_vcodec_ctx *ctx,
70 struct aml_vcodec_mem *bs, void *out)
71 {
72 int ret = 0;
73
74 ret = ctx->dec_if->probe(ctx->drv_handle, bs, out);
75
76 return ret;
77 }
78
vdec_if_decode(struct aml_vcodec_ctx * ctx,struct aml_vcodec_mem * bs,u64 timestamp,bool * res_chg)79 int vdec_if_decode(struct aml_vcodec_ctx *ctx, struct aml_vcodec_mem *bs,
80 u64 timestamp, bool *res_chg)
81 {
82 int ret = 0;
83
84 if (bs) {
85 if ((bs->addr & 63) != 0) {
86 v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
87 "bs dma_addr should 64 byte align\n");
88 return -EINVAL;
89 }
90 }
91
92 if (ctx->drv_handle == 0)
93 return -EIO;
94
95 aml_vcodec_set_curr_ctx(ctx->dev, ctx);
96 ret = ctx->dec_if->decode(ctx->drv_handle, bs, timestamp, res_chg);
97 aml_vcodec_set_curr_ctx(ctx->dev, NULL);
98
99 return ret;
100 }
101
vdec_if_get_param(struct aml_vcodec_ctx * ctx,enum vdec_get_param_type type,void * out)102 int vdec_if_get_param(struct aml_vcodec_ctx *ctx,
103 enum vdec_get_param_type type, void *out)
104 {
105 int ret = 0;
106
107 if (ctx->drv_handle == 0)
108 return -EIO;
109
110 ret = ctx->dec_if->get_param(ctx->drv_handle, type, out);
111
112 return ret;
113 }
114
vdec_if_deinit(struct aml_vcodec_ctx * ctx)115 void vdec_if_deinit(struct aml_vcodec_ctx *ctx)
116 {
117 if (ctx->drv_handle == 0)
118 return;
119
120 ctx->dec_if->deinit(ctx->drv_handle);
121 ctx->drv_handle = 0;
122 }
123