• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute  it and/or modify it
5  * under  the terms of  the GNU General  Public License as published by the
6  * Free Software Foundation;  either version 2 of the  License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #include "vo.h"
20 #include "mkp_vo_dev.h"
21 #include "mkp_vo_video.h"
22 #include "mkp_vo_comm.h"
23 #include "mkp_vo_gfx.h"
24 #include "mkp_vo_init.h"
25 #include "mkp_vo_user.h"
26 #include "hi_math.h"
27 #include <common.h>
28 #include <command.h>
29 #include <version.h>
30 #include <asm/io.h>
31 #include <asm/arch/platform.h>
32 #include <config.h>
33 #include <cpu_func.h>
34 
35 #include "drv_vo.h"
36 #include "drv_vo_gfx.h"
37 
vo_dcache_range(hi_phys_addr_t start_addr,hi_u64 size)38 hi_void vo_dcache_range(hi_phys_addr_t start_addr, hi_u64 size)
39 {
40     if (dcache_status()) {
41         flush_dcache_range(start_addr, start_addr + size);
42     }
43 }
44 
set_vobg(unsigned int dev,unsigned int rgb)45 int set_vobg(unsigned int dev, unsigned int rgb)
46 {
47     vo_check_dev_id_return(dev);
48     vo_dev_set_bg_color(dev, rgb);
49     return HI_SUCCESS;
50 }
51 
vo_construct_pub_attr(unsigned int dev,unsigned int type,unsigned int sync,hi_vo_pub_attr * pub_attr)52 static hi_void vo_construct_pub_attr(unsigned int dev,
53     unsigned int type, unsigned int sync, hi_vo_pub_attr *pub_attr)
54 {
55     hi_vo_sync_info *sync_info = HI_NULL;
56 
57     pub_attr->bg_color = vo_dev_get_bg_color(dev);
58     pub_attr->intf_sync = sync;
59     pub_attr->intf_type = type;
60     if (vo_is_user_intf_sync(sync) == HI_TRUE) {
61         sync_info = vo_get_dev_user_sync_timing(dev);
62         if (sync_info != NULL) {
63             memcpy(&(pub_attr->sync_info), sync_info, sizeof(hi_vo_sync_info));
64         }
65     }
66 }
67 
vo_set_user_sync_clk(unsigned int dev,unsigned int sync)68 static hi_s32 vo_set_user_sync_clk(unsigned int dev, unsigned int sync)
69 {
70     hi_s32 ret;
71     hi_vo_user_sync_info *user_sync = HI_NULL;
72 
73     if (vo_is_user_intf_sync(sync) == HI_TRUE) {
74         /* set the user sync info: clk source, clk value */
75         user_sync = vo_get_dev_user_sync_info(dev);
76         if (user_sync == HI_NULL) {
77             return HI_FAILURE;
78         }
79         ret = vo_set_user_sync_info(dev, user_sync);
80         if (ret != HI_SUCCESS) {
81             return ret;
82         }
83     }
84     return HI_SUCCESS;
85 }
86 
start_vo(unsigned int dev,unsigned int type,unsigned int sync)87 int start_vo(unsigned int dev, unsigned int type, unsigned int sync)
88 {
89     hi_s32 ret;
90     hi_vo_pub_attr pub_attr = {0};
91 
92     vo_init();
93 
94     vo_construct_pub_attr(dev, type, sync, &pub_attr);
95 
96     ret = vo_set_pub_attr(dev, &pub_attr);
97     if (ret != HI_SUCCESS) {
98         return ret;
99     }
100 
101     ret = vo_set_user_sync_clk(dev, sync);
102     if (ret != HI_SUCCESS) {
103         return ret;
104     }
105 
106     ret = vo_enable(dev);
107     return ret;
108 }
109 
stop_vo(unsigned int dev)110 int stop_vo(unsigned int dev)
111 {
112     vo_check_dev_id_return(dev);
113     return vo_disable(dev);
114 }
115 
vo_construct_gfx_attr(unsigned long addr,unsigned int strd,hi_rect gfx_rect,unsigned int type,hi_vo_gfx_attr * gfx_attr)116 static hi_s32 vo_construct_gfx_attr(unsigned long addr, unsigned int strd,
117     hi_rect gfx_rect, unsigned int type, hi_vo_gfx_attr *gfx_attr)
118 {
119     hi_vo_gfx_attr gfx_attr_tmp = {0};
120 
121     gfx_attr_tmp.stride = strd;
122     gfx_attr_tmp.address = addr;
123     gfx_attr_tmp.type = type;
124     memcpy(&gfx_attr_tmp.display_rect, &gfx_rect, sizeof(hi_rect));
125 
126     return vo_drv_gfx_convert_gfx_attr(&gfx_attr_tmp, gfx_attr);
127 }
128 
start_gx(unsigned int layer,unsigned long addr,unsigned int strd,hi_rect gx_rect,unsigned int type)129 int start_gx(unsigned int layer, unsigned long addr, unsigned int strd, hi_rect gx_rect, unsigned int type)
130 {
131     hi_s32 ret;
132     hi_vo_gfx_attr gfx_attr = {0};
133 
134     ret = vo_construct_gfx_attr(addr, strd, gx_rect, type, &gfx_attr);
135     if (ret != HI_SUCCESS) {
136         vo_err_trace("convert gfx attr failed.\n");
137         return ret;
138     }
139 
140     ret = vo_set_gfx_attr(layer, &gfx_attr);
141     if (ret != HI_SUCCESS) {
142         printf("invalid parameter!\n");
143         return ret;
144     }
145     ret = vo_enable_gfx_layer(layer, &gfx_attr);
146 
147     return ret;
148 }
149 
stop_gx(unsigned int layer)150 int stop_gx(unsigned int layer)
151 {
152     hi_s32 ret;
153     ret = vo_disable_gfx_layer(layer);
154     if (ret != HI_SUCCESS) {
155         printf("invalid parameter!\n");
156         return ret;
157     }
158 
159     return HI_SUCCESS;
160 }
161 
vo_contruct_video_layer_attr(unsigned long addr,unsigned int strd,hi_rect layer_rect,hi_vo_video_layer_attr * video_attr)162 static hi_void vo_contruct_video_layer_attr(unsigned long addr, unsigned int strd,
163     hi_rect layer_rect, hi_vo_video_layer_attr *video_attr)
164 {
165     video_attr->stride = strd;
166     video_attr->address = addr;
167     memcpy(&video_attr->display_rect, &layer_rect, sizeof(hi_rect));
168 }
169 
start_videolayer(unsigned int layer,unsigned long addr,unsigned int strd,hi_rect layer_rect)170 int start_videolayer(unsigned int layer, unsigned long addr, unsigned int strd, hi_rect layer_rect)
171 {
172     hi_s32 ret;
173     hi_vo_video_layer_attr video_attr = {0};
174 
175     vo_contruct_video_layer_attr(addr, strd, layer_rect, &video_attr);
176     ret = vo_set_video_layer_attr(layer, &video_attr);
177     if (ret != HI_SUCCESS) {
178         printf("invalid parameter!\n");
179         return ret;
180     }
181 
182     vo_dcache_range(addr, strd * layer_rect.height * 3 / 2); /* 3 / 2 times */
183 
184     ret = vo_enable_video_layer(layer, &video_attr);
185 
186     return ret;
187 }
188 
stop_videolayer(unsigned int layer)189 int stop_videolayer(unsigned int layer)
190 {
191     hi_s32 ret;
192     ret = vo_disable_video_layer(layer);
193     if (ret != HI_SUCCESS) {
194         printf("invalid parameter!\n");
195         return ret;
196     }
197 
198     return 0;
199 }
200