blob: d69ef9f0f7a17219d2979114e8687a5db13f1f61
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 | |
29 | const struct vdec_common_if *get_h264_dec_comm_if(void); |
30 | const struct vdec_common_if *get_hevc_dec_comm_if(void); |
31 | const struct vdec_common_if *get_vp9_dec_comm_if(void); |
32 | |
33 | int vdec_if_init(struct aml_vcodec_ctx *ctx, unsigned int fourcc) |
34 | { |
35 | int ret = 0; |
36 | |
37 | switch (fourcc) { |
38 | case V4L2_PIX_FMT_H264: |
39 | ctx->dec_if = get_h264_dec_comm_if(); |
40 | break; |
41 | case V4L2_PIX_FMT_HEVC: |
42 | ctx->dec_if = get_hevc_dec_comm_if(); |
43 | break; |
44 | case V4L2_PIX_FMT_VP9: |
45 | ctx->dec_if = get_vp9_dec_comm_if(); |
46 | break; |
47 | default: |
48 | return -EINVAL; |
49 | } |
50 | |
51 | aml_vdec_lock(ctx); |
52 | //aml_vcodec_dec_clock_on(&ctx->dev->pm);//debug_tmp |
53 | ret = ctx->dec_if->init(ctx, &ctx->drv_handle); |
54 | //aml_vcodec_dec_clock_off(&ctx->dev->pm); |
55 | aml_vdec_unlock(ctx); |
56 | |
57 | return ret; |
58 | } |
59 | |
60 | int vdec_if_probe(struct aml_vcodec_ctx *ctx, |
61 | struct aml_vcodec_mem *bs, void *out) |
62 | { |
63 | int ret = 0; |
64 | |
65 | aml_vdec_lock(ctx); |
66 | ret = ctx->dec_if->probe(ctx->drv_handle, bs, out); |
67 | aml_vdec_unlock(ctx); |
68 | |
69 | return ret; |
70 | } |
71 | |
72 | int vdec_if_decode(struct aml_vcodec_ctx *ctx, struct aml_vcodec_mem *bs, |
73 | unsigned long int timestamp, bool *res_chg) |
74 | { |
75 | int ret = 0; |
76 | |
77 | if (bs) { |
78 | if ((bs->dma_addr & 63) != 0) { |
79 | aml_v4l2_err("bs dma_addr should 64 byte align"); |
80 | return -EINVAL; |
81 | } |
82 | } |
83 | |
84 | /*if (fb) { |
85 | if (((fb->base_y.dma_addr & 511) != 0) || |
86 | ((fb->base_c.dma_addr & 511) != 0)) { |
87 | aml_v4l2_err("frame buffer dma_addr should 512 byte align"); |
88 | return -EINVAL; |
89 | } |
90 | }*/ |
91 | |
92 | if (ctx->drv_handle == 0) |
93 | return -EIO; |
94 | |
95 | //aml_vdec_lock(ctx); |
96 | |
97 | aml_vcodec_set_curr_ctx(ctx->dev, ctx); |
98 | //aml_vcodec_dec_clock_on(&ctx->dev->pm);//debug_tmp |
99 | //enable_irq(ctx->dev->dec_irq); |
100 | ret = ctx->dec_if->decode(ctx->drv_handle, bs, timestamp, res_chg); |
101 | //disable_irq(ctx->dev->dec_irq); |
102 | //aml_vcodec_dec_clock_off(&ctx->dev->pm); |
103 | aml_vcodec_set_curr_ctx(ctx->dev, NULL); |
104 | |
105 | //aml_vdec_unlock(ctx); |
106 | |
107 | return ret; |
108 | } |
109 | |
110 | int vdec_if_get_param(struct aml_vcodec_ctx *ctx, |
111 | enum vdec_get_param_type type, void *out) |
112 | { |
113 | int ret = 0; |
114 | |
115 | if (ctx->drv_handle == 0) |
116 | return -EIO; |
117 | |
118 | //aml_vdec_lock(ctx); |
119 | ret = ctx->dec_if->get_param(ctx->drv_handle, type, out); |
120 | //aml_vdec_unlock(ctx); |
121 | |
122 | return ret; |
123 | } |
124 | |
125 | void vdec_if_deinit(struct aml_vcodec_ctx *ctx) |
126 | { |
127 | if (ctx->drv_handle == 0) |
128 | return; |
129 | |
130 | //aml_vdec_lock(ctx); |
131 | //aml_vcodec_dec_clock_on(&ctx->dev->pm); |
132 | ctx->dec_if->deinit(ctx->drv_handle); |
133 | //aml_vcodec_dec_clock_off(&ctx->dev->pm); |
134 | //aml_vdec_unlock(ctx); |
135 | |
136 | ctx->drv_handle = 0; |
137 | } |
138 |