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 "drv_vo_gfx_comm.h"
20 #include "drv_vo_gfx.h"
21 #include "mkp_vo_bmp.h"
22
23 #include "drv_vo.h"
24 #include "hal_vo.h"
25 #include "drv_vo_coef_org_comm.h"
26 #include "vo.h"
27 #include <common.h>
28
29 #if VO_DESC("UBOOT_VO")
30 #if VO_DESC("vo gfx csc")
31
vo_drv_set_gfx_layer_csc(hi_vo_layer gfx_layer,hi_vo_csc * csc,csc_coef_param * csc_param)32 hi_s32 vo_drv_set_gfx_layer_csc(hi_vo_layer gfx_layer, hi_vo_csc *csc, csc_coef_param *csc_param)
33 {
34 hi_s32 ret;
35 hal_disp_layer hal_layer;
36 csc_coef coef;
37
38 ret = vo_drv_get_hal_gfx_layer(gfx_layer, &hal_layer);
39 if (ret != HI_SUCCESS) {
40 vo_err_trace("gfx layer %d is illegal!\n", gfx_layer);
41 return HI_ERR_VO_INVALID_LAYER_ID;
42 }
43
44 vou_drv_calc_csc_matrix(csc, csc->csc_matrix, &coef);
45
46 coef.new_csc_scale2p = GFX_CSC_SCALE;
47 coef.new_csc_clip_min = GFX_CSC_CLIP_MIN;
48 coef.new_csc_clip_max = GFX_CSC_CLIP_MAX;
49
50 vo_drv_csc_trans_to_register(&coef);
51
52 vo_drv_clip_layer_csc_coef(&coef);
53
54 hal_layer_set_csc_coef(hal_layer, &coef);
55
56 return HI_SUCCESS;
57 }
58
59 #endif
60
61 #if VO_DESC("vo gfx open")
vo_drv_gfx_check_image_stride_and_xywh(hi_vo_gfx_attr * gfx_attr_out,osd_logo_t * scroll_image_logo)62 static hi_s32 vo_drv_gfx_check_image_stride_and_xywh(hi_vo_gfx_attr *gfx_attr_out, osd_logo_t *scroll_image_logo)
63 {
64 if ((gfx_attr_out->stride != scroll_image_logo->stride) ||
65 (gfx_attr_out->display_rect.width != scroll_image_logo->width) ||
66 (gfx_attr_out->display_rect.height != scroll_image_logo->height)) {
67 vo_err_trace("logo's stride=%d, w=%d, h=%d is not equal to gfx attr stride=%d, w=%d, h=%d\n",
68 scroll_image_logo->stride, scroll_image_logo->width, scroll_image_logo->height,
69 gfx_attr_out->stride, gfx_attr_out->display_rect.width, gfx_attr_out->display_rect.height);
70 return HI_ERR_VO_ILLEGAL_PARAM;
71 }
72 return HI_SUCCESS;
73 }
74
vo_drv_gfx_convert_gfx_attr(const hi_vo_gfx_attr * gfx_attr_in,hi_vo_gfx_attr * gfx_attr_out)75 hi_s32 vo_drv_gfx_convert_gfx_attr(const hi_vo_gfx_attr *gfx_attr_in, hi_vo_gfx_attr *gfx_attr_out)
76 {
77 hi_phys_addr_t addr;
78 osd_logo_t scroll_image_logo = {0};
79
80 if (gfx_attr_in->type == HI_VO_GFX_TYPE_ARGB1555) {
81 *gfx_attr_out = *gfx_attr_in;
82 } else if (gfx_attr_in->type == HI_VO_GFX_TYPE_BMP1555) {
83 addr = gfx_attr_in->address;
84 if (load_bmp(addr, &scroll_image_logo) != 0) {
85 return HI_FAILURE;
86 }
87 gfx_attr_out->address = scroll_image_logo.rgb_buffer;
88 gfx_attr_out->stride = gfx_attr_in->stride;
89 gfx_attr_out->display_rect = gfx_attr_in->display_rect;
90 (hi_void)vo_drv_gfx_check_image_stride_and_xywh(gfx_attr_out, &scroll_image_logo);
91 } else {
92 vo_err_trace("gfx unknown input type %d\n", gfx_attr_in->type);
93 return HI_FAILURE;
94 }
95
96 vo_dcache_range(gfx_attr_out->address, gfx_attr_out->stride * gfx_attr_out->display_rect.height);
97
98 return HI_SUCCESS;
99 }
100
vo_drv_gfx_open(hi_vo_layer gfx_id,const hi_vo_gfx_attr * gfx_attr)101 hi_void vo_drv_gfx_open(hi_vo_layer gfx_id, const hi_vo_gfx_attr *gfx_attr)
102 {
103 hi_s32 ret;
104 hal_disp_layer vo_layer;
105 hi_phys_addr_t addr;
106 hi_u32 strd;
107 hi_rect gx_rect;
108
109 ret = vo_drv_get_hal_gfx_layer(gfx_id, &vo_layer);
110 if (ret != HI_SUCCESS) {
111 vo_err_trace("get gfx id failed.\n");
112 return;
113 }
114 addr = gfx_attr->address;
115 strd = gfx_attr->stride;
116 gx_rect = gfx_attr->display_rect;
117
118 hal_gfx_set_pixel_alpha_range(vo_layer, 0xff);
119 hal_layer_set_layer_global_alpha(vo_layer, 0xff);
120 hal_gfx_set_gfx_pre_mult(vo_layer, HI_FALSE);
121
122 hal_gfx_set_gfx_addr(vo_layer, addr);
123 hal_gfx_set_gfx_stride(vo_layer, strd >> 4); /* stride div 16(2 ^ 4) */
124 hal_gfx_set_layer_in_rect(vo_layer, &gx_rect);
125
126 hal_gfx_set_layer_disp_rect(vo_layer, &gx_rect);
127 hal_gfx_set_layer_video_rect(vo_layer, &gx_rect);
128
129 hal_gfx_set_src_resolution(vo_layer, &gx_rect);
130
131 hal_gfx_set_layer_data_fmt(vo_layer, HAL_INPUTFMT_ARGB_1555);
132
133 hal_gfx_enable_layer(vo_layer, HI_TRUE);
134 hal_gfx_set_reg_up(vo_layer);
135 }
136
vo_drv_gfx_close(hi_vo_layer layer_id)137 hi_void vo_drv_gfx_close(hi_vo_layer layer_id)
138 {
139 hi_s32 ret;
140 hal_disp_layer hal_gfx_layer;
141
142 ret = vo_drv_get_hal_gfx_layer(layer_id, &hal_gfx_layer);
143 if (ret != HI_SUCCESS) {
144 return;
145 }
146
147 hal_gfx_set_reg_up(hal_gfx_layer);
148 hal_gfx_enable_layer(hal_gfx_layer, HI_FALSE);
149 hal_gfx_set_reg_up(hal_gfx_layer);
150 }
151 #endif
152 #endif /* #if VO_DESC("UBOOT_VO") */
153