summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/vdec_drv_if.c (plain)
blob: 4b70ed0200e0a212a4c869e92b9b3220bbfc9afe
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#include "aml_vcodec_dec_pm.h"
28
29const struct vdec_common_if *get_h264_dec_comm_if(void);
30const struct vdec_common_if *get_hevc_dec_comm_if(void);
31const struct vdec_common_if *get_vp9_dec_comm_if(void);
32const struct vdec_common_if *get_mpeg12_dec_comm_if(void);
33const struct vdec_common_if *get_mpeg4_dec_comm_if(void);
34const struct vdec_common_if *get_mjpeg_dec_comm_if(void);
35
36int vdec_if_init(struct aml_vcodec_ctx *ctx, unsigned int fourcc)
37{
38 int ret = 0;
39
40 switch (fourcc) {
41 case V4L2_PIX_FMT_H264:
42 ctx->dec_if = get_h264_dec_comm_if();
43 break;
44 case V4L2_PIX_FMT_HEVC:
45 ctx->dec_if = get_hevc_dec_comm_if();
46 break;
47 case V4L2_PIX_FMT_VP9:
48 ctx->dec_if = get_vp9_dec_comm_if();
49 break;
50 case V4L2_PIX_FMT_MPEG:
51 case V4L2_PIX_FMT_MPEG1:
52 case V4L2_PIX_FMT_MPEG2:
53 ctx->dec_if = get_mpeg12_dec_comm_if();
54 break;
55 case V4L2_PIX_FMT_MPEG4:
56 ctx->dec_if = get_mpeg4_dec_comm_if();
57 break;
58 case V4L2_PIX_FMT_MJPEG:
59 ctx->dec_if = get_mjpeg_dec_comm_if();
60 break;
61 default:
62 return -EINVAL;
63 }
64
65 ret = ctx->dec_if->init(ctx, &ctx->drv_handle);
66
67 return ret;
68}
69
70int vdec_if_probe(struct aml_vcodec_ctx *ctx,
71 struct aml_vcodec_mem *bs, void *out)
72{
73 int ret = 0;
74
75 ret = ctx->dec_if->probe(ctx->drv_handle, bs, out);
76
77 return ret;
78}
79
80int vdec_if_decode(struct aml_vcodec_ctx *ctx, struct aml_vcodec_mem *bs,
81 u64 timestamp, bool *res_chg)
82{
83 int ret = 0;
84
85 if (bs) {
86 if ((bs->dma_addr & 63) != 0) {
87 aml_v4l2_err("bs dma_addr should 64 byte align");
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
102int 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
115void 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