xref: /rockchip-linux_mpp/mpp/hal/vpu/jpegd/hal_jpegd_api.c (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  * Copyright 2017 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define MODULE_TAG "hal_jpegd_api"
18 
19 #include <string.h>
20 
21 #include "mpp_env.h"
22 #include "mpp_debug.h"
23 #include "mpp_common.h"
24 #include "osal_2str.h"
25 
26 #include "mpp_hal.h"
27 #include "mpp_platform.h"
28 #include "hal_jpegd_base.h"
29 #include "hal_jpegd_vdpu2.h"
30 #include "hal_jpegd_vdpu1.h"
31 #include "hal_jpegd_rkv.h"
32 
hal_jpegd_reg_gen(void * hal,HalTaskInfo * task)33 static MPP_RET hal_jpegd_reg_gen(void *hal, HalTaskInfo *task)
34 {
35     JpegdHalCtx *self = (JpegdHalCtx *)hal;
36     return self->hal_api.reg_gen (hal, task);
37 }
38 
hal_jpegd_start(void * hal,HalTaskInfo * task)39 static MPP_RET hal_jpegd_start(void *hal, HalTaskInfo *task)
40 {
41     JpegdHalCtx *self = (JpegdHalCtx *)hal;
42     return self->hal_api.start (hal, task);
43 }
44 
hal_jpegd_wait(void * hal,HalTaskInfo * task)45 static MPP_RET hal_jpegd_wait(void *hal, HalTaskInfo *task)
46 {
47     JpegdHalCtx *self = (JpegdHalCtx *)hal;
48     return self->hal_api.wait (hal, task);
49 }
50 
hal_jpegd_control(void * hal,MpiCmd cmd_type,void * param)51 static MPP_RET hal_jpegd_control(void *hal, MpiCmd cmd_type, void *param)
52 {
53     JpegdHalCtx *self = (JpegdHalCtx *)hal;
54     return self->hal_api.control (hal, cmd_type, param);
55 }
56 
hal_jpegd_deinit(void * hal)57 static MPP_RET hal_jpegd_deinit(void *hal)
58 {
59     JpegdHalCtx *self = (JpegdHalCtx *)hal;
60     return self->hal_api.deinit (hal);
61 }
62 
hal_jpegd_init(void * hal,MppHalCfg * cfg)63 static MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg)
64 {
65     MPP_RET ret = MPP_ERR_UNKNOW;
66     JpegdHalCtx *self = (JpegdHalCtx *)hal;
67     MppHalApi *p_api = NULL;
68     MppClientType client_type = VPU_CLIENT_BUTT;
69     MppDecBaseCfg *base = &cfg->cfg->base;
70     RK_S32 hw_type = -1;
71     RK_U32 hw_flag = 0;
72 
73     if (NULL == self)
74         return MPP_ERR_VALUE;
75 
76     memset(self, 0, sizeof(JpegdHalCtx));
77 
78     p_api = &self->hal_api;
79 
80     hw_flag = mpp_get_vcodec_type();
81 
82     if (mpp_check_soc_cap(base->type, base->coding))
83         hw_type = base->hw_type;
84 
85     if (hw_type > 0) {
86         if (hw_flag & (1 << hw_type)) {
87             mpp_log("init with %s hw\n", strof_client_type(hw_type));
88             client_type = hw_type;
89         } else
90             mpp_err_f("invalid hw_type %d with vcodec_type %08x\n",
91                       hw_type, hw_flag);
92     }
93 
94     if (client_type == VPU_CLIENT_BUTT) {
95         if (hw_flag & HAVE_VDPU2)
96             client_type = VPU_CLIENT_VDPU2;
97         if (hw_flag & HAVE_VDPU1)
98             client_type = VPU_CLIENT_VDPU1;
99         if (hw_flag & HAVE_VDPU2_PP)
100             client_type = VPU_CLIENT_VDPU2_PP;
101         if (hw_flag & HAVE_VDPU1_PP)
102             client_type = VPU_CLIENT_VDPU1_PP;
103         if (hw_flag & HAVE_JPEG_DEC)
104             client_type = VPU_CLIENT_JPEG_DEC;
105     }
106 
107     mpp_env_get_u32("jpegd_mode", &client_type, client_type);
108 
109     switch (client_type) {
110     case VPU_CLIENT_VDPU2 :
111     case VPU_CLIENT_VDPU2_PP : {
112         p_api->init = hal_jpegd_vdpu2_init;
113         p_api->deinit = hal_jpegd_vdpu2_deinit;
114         p_api->reg_gen = hal_jpegd_vdpu2_gen_regs;
115         p_api->start = hal_jpegd_vdpu2_start;
116         p_api->wait = hal_jpegd_vdpu2_wait;
117         p_api->control = hal_jpegd_vdpu2_control;
118     } break;
119     case VPU_CLIENT_VDPU1 :
120     case VPU_CLIENT_VDPU1_PP : {
121         p_api->init = hal_jpegd_vdpu1_init;
122         p_api->deinit = hal_jpegd_vdpu1_deinit;
123         p_api->reg_gen = hal_jpegd_vdpu1_gen_regs;
124         p_api->start = hal_jpegd_vdpu1_start;
125         p_api->wait = hal_jpegd_vdpu1_wait;
126         p_api->control = hal_jpegd_vdpu1_control;
127     } break;
128     case VPU_CLIENT_JPEG_DEC : {
129         p_api->init = hal_jpegd_rkv_init;
130         p_api->deinit = hal_jpegd_rkv_deinit;
131         p_api->reg_gen = hal_jpegd_rkv_gen_regs;
132         p_api->start = hal_jpegd_rkv_start;
133         p_api->wait = hal_jpegd_rkv_wait;
134         p_api->control = hal_jpegd_rkv_control;
135     } break;
136     default : {
137         return MPP_ERR_INIT;
138     } break;
139     }
140 
141     ret = mpp_dev_init(&cfg->dev, client_type);
142     if (ret) {
143         mpp_err("mpp_dev_init failed ret: %d\n", ret);
144         goto __RETURN;
145     }
146 
147     cfg->hw_info = mpp_get_dec_hw_info_by_client_type(client_type);
148     self->hw_info = cfg->hw_info;
149     self->dev = cfg->dev;
150 
151     ret = p_api->init(hal, cfg);
152     if (ret) {
153         mpp_err("init device with client_type %d failed!\n", client_type);
154         mpp_dev_deinit(cfg->dev);
155     }
156 
157 __RETURN:
158     return ret;
159 }
160 
161 const MppHalApi hal_api_jpegd = {
162     .name = "jpegd",
163     .type = MPP_CTX_DEC,
164     .coding = MPP_VIDEO_CodingMJPEG,
165     .ctx_size = sizeof(JpegdHalCtx),
166     .flag = 0,
167     .init = hal_jpegd_init,
168     .deinit = hal_jpegd_deinit,
169     .reg_gen = hal_jpegd_reg_gen,
170     .start = hal_jpegd_start,
171     .wait = hal_jpegd_wait,
172     .reset = NULL,
173     .flush = NULL,
174     .control = hal_jpegd_control,
175 };
176