1 /*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #include "dm_services.h"
27
28 #include "core_types.h"
29
30 #include "reg_helper.h"
31 #include "dcn401/dcn401_dpp.h"
32 #include "basics/conversion.h"
33 #include "dcn10/dcn10_cm_common.h"
34
35 #define NUM_PHASES 64
36 #define HORZ_MAX_TAPS 8
37 #define VERT_MAX_TAPS 8
38
39 #define BLACK_OFFSET_RGB_Y 0x0
40 #define BLACK_OFFSET_CBCR 0x8000
41
42 #define REG(reg)\
43 dpp->tf_regs->reg
44
45 #define CTX \
46 dpp->base.ctx
47
48 #undef FN
49 #define FN(reg_name, field_name) \
50 dpp->tf_shift->field_name, dpp->tf_mask->field_name
51
52 #define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
53
54
55 enum dcn401_coef_filter_type_sel {
56 SCL_COEF_LUMA_VERT_FILTER = 0,
57 SCL_COEF_LUMA_HORZ_FILTER = 1,
58 SCL_COEF_CHROMA_VERT_FILTER = 2,
59 SCL_COEF_CHROMA_HORZ_FILTER = 3,
60 SCL_COEF_SC_VERT_FILTER = 4,
61 SCL_COEF_SC_HORZ_FILTER = 5
62 };
63
64 enum dscl_autocal_mode {
65 AUTOCAL_MODE_OFF = 0,
66
67 /* Autocal calculate the scaling ratio and initial phase and the
68 * DSCL_MODE_SEL must be set to 1
69 */
70 AUTOCAL_MODE_AUTOSCALE = 1,
71 /* Autocal perform auto centering without replication and the
72 * DSCL_MODE_SEL must be set to 0
73 */
74 AUTOCAL_MODE_AUTOCENTER = 2,
75 /* Autocal perform auto centering and auto replication and the
76 * DSCL_MODE_SEL must be set to 0
77 */
78 AUTOCAL_MODE_AUTOREPLICATE = 3
79 };
80
81 enum dscl_mode_sel {
82 DSCL_MODE_SCALING_444_BYPASS = 0,
83 DSCL_MODE_SCALING_444_RGB_ENABLE = 1,
84 DSCL_MODE_SCALING_444_YCBCR_ENABLE = 2,
85 DSCL_MODE_SCALING_YCBCR_ENABLE = 3,
86 DSCL_MODE_LUMA_SCALING_BYPASS = 4,
87 DSCL_MODE_CHROMA_SCALING_BYPASS = 5,
88 DSCL_MODE_DSCL_BYPASS = 6
89 };
90
dpp401_set_cursor_attributes(struct dpp * dpp_base,struct dc_cursor_attributes * cursor_attributes)91 void dpp401_set_cursor_attributes(
92 struct dpp *dpp_base,
93 struct dc_cursor_attributes *cursor_attributes)
94 {
95 struct dcn401_dpp *dpp = TO_DCN401_DPP(dpp_base);
96 enum dc_cursor_color_format color_format = cursor_attributes->color_format;
97 int cur_rom_en = 0;
98
99 if (color_format == CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA ||
100 color_format == CURSOR_MODE_COLOR_UN_PRE_MULTIPLIED_ALPHA) {
101 if (cursor_attributes->attribute_flags.bits.ENABLE_CURSOR_DEGAMMA) {
102 cur_rom_en = 1;
103 }
104 }
105
106 REG_UPDATE_3(CURSOR0_CONTROL,
107 CUR0_MODE, color_format,
108 CUR0_EXPANSION_MODE, 0,
109 CUR0_ROM_EN, cur_rom_en);
110
111 if (color_format == CURSOR_MODE_MONO) {
112 /* todo: clarify what to program these to */
113 REG_UPDATE(CURSOR0_COLOR0,
114 CUR0_COLOR0, 0x00000000);
115 REG_UPDATE(CURSOR0_COLOR1,
116 CUR0_COLOR1, 0xFFFFFFFF);
117 }
118
119 dpp_base->att.cur0_ctl.bits.expansion_mode = 0;
120 dpp_base->att.cur0_ctl.bits.cur0_rom_en = cur_rom_en;
121 dpp_base->att.cur0_ctl.bits.mode = color_format;
122 }
123
dpp401_set_cursor_position(struct dpp * dpp_base,const struct dc_cursor_position * pos,const struct dc_cursor_mi_param * param,uint32_t width,uint32_t height)124 void dpp401_set_cursor_position(
125 struct dpp *dpp_base,
126 const struct dc_cursor_position *pos,
127 const struct dc_cursor_mi_param *param,
128 uint32_t width,
129 uint32_t height)
130 {
131 struct dcn401_dpp *dpp = TO_DCN401_DPP(dpp_base);
132 uint32_t cur_en = pos->enable ? 1 : 0;
133
134 if (dpp_base->pos.cur0_ctl.bits.cur0_enable != cur_en) {
135 REG_UPDATE(CURSOR0_CONTROL, CUR0_ENABLE, cur_en);
136
137 dpp_base->pos.cur0_ctl.bits.cur0_enable = cur_en;
138 }
139 }
140
dpp401_set_optional_cursor_attributes(struct dpp * dpp_base,struct dpp_cursor_attributes * attr)141 void dpp401_set_optional_cursor_attributes(
142 struct dpp *dpp_base,
143 struct dpp_cursor_attributes *attr)
144 {
145 struct dcn401_dpp *dpp = TO_DCN401_DPP(dpp_base);
146
147 if (attr) {
148 REG_UPDATE(CURSOR0_FP_SCALE_BIAS_G_Y, CUR0_FP_BIAS_G_Y, attr->bias);
149 REG_UPDATE(CURSOR0_FP_SCALE_BIAS_G_Y, CUR0_FP_SCALE_G_Y, attr->scale);
150 REG_UPDATE(CURSOR0_FP_SCALE_BIAS_RB_CRCB, CUR0_FP_BIAS_RB_CRCB, attr->bias);
151 REG_UPDATE(CURSOR0_FP_SCALE_BIAS_RB_CRCB, CUR0_FP_SCALE_RB_CRCB, attr->scale);
152 }
153 }
154
155 /* Program Cursor matrix block in DPP CM */
dpp401_program_cursor_csc(struct dpp * dpp_base,enum dc_color_space color_space,const struct dpp_input_csc_matrix * tbl_entry)156 static void dpp401_program_cursor_csc(
157 struct dpp *dpp_base,
158 enum dc_color_space color_space,
159 const struct dpp_input_csc_matrix *tbl_entry)
160 {
161 struct dcn401_dpp *dpp = TO_DCN401_DPP(dpp_base);
162 uint32_t mode_select = 0;
163 struct color_matrices_reg cur_matrix_regs;
164 unsigned int i;
165 const uint16_t *regval = NULL;
166 int arr_size = sizeof(dpp_input_csc_matrix) / sizeof(struct dpp_input_csc_matrix);
167
168 if (color_space < COLOR_SPACE_YCBCR601) {
169 REG_SET(CUR0_MATRIX_MODE, 0, CUR0_MATRIX_MODE, CUR_MATRIX_BYPASS);
170 return;
171 }
172
173 /* If adjustments not provided use hardcoded table for color space conversion */
174 if (tbl_entry == NULL) {
175
176 for (i = 0; i < arr_size; i++)
177 if (dpp_input_csc_matrix[i].color_space == color_space) {
178 regval = dpp_input_csc_matrix[i].regval;
179 break;
180 }
181
182 if (regval == NULL) {
183 BREAK_TO_DEBUGGER();
184 REG_SET(CUR0_MATRIX_MODE, 0, CUR0_MATRIX_MODE, CUR_MATRIX_BYPASS);
185 return;
186 }
187 } else {
188 regval = tbl_entry->regval;
189 }
190
191 REG_GET(CUR0_MATRIX_MODE, CUR0_MATRIX_MODE_CURRENT, &mode_select);
192
193 //If current set in use not set A, then use set A, otherwise use set B
194 if (mode_select != CUR_MATRIX_SET_A)
195 mode_select = CUR_MATRIX_SET_A;
196 else
197 mode_select = CUR_MATRIX_SET_B;
198
199 cur_matrix_regs.shifts.csc_c11 = dpp->tf_shift->CUR0_MATRIX_C11_A;
200 cur_matrix_regs.masks.csc_c11 = dpp->tf_mask->CUR0_MATRIX_C11_A;
201 cur_matrix_regs.shifts.csc_c12 = dpp->tf_shift->CUR0_MATRIX_C12_A;
202 cur_matrix_regs.masks.csc_c12 = dpp->tf_mask->CUR0_MATRIX_C12_A;
203
204 if (mode_select == CUR_MATRIX_SET_A) {
205 cur_matrix_regs.csc_c11_c12 = REG(CUR0_MATRIX_C11_C12_A);
206 cur_matrix_regs.csc_c33_c34 = REG(CUR0_MATRIX_C33_C34_A);
207 } else {
208 cur_matrix_regs.csc_c11_c12 = REG(CUR0_MATRIX_C11_C12_B);
209 cur_matrix_regs.csc_c33_c34 = REG(CUR0_MATRIX_C33_C34_B);
210 }
211
212 cm_helper_program_color_matrices(
213 dpp->base.ctx,
214 regval,
215 &cur_matrix_regs);
216
217 //select coefficient set to use
218 REG_SET(CUR0_MATRIX_MODE, 0, CUR0_MATRIX_MODE, mode_select);
219 }
220
221 /* Program Cursor matrix block in DPP CM */
dpp401_set_cursor_matrix(struct dpp * dpp_base,enum dc_color_space color_space,struct dc_csc_transform cursor_csc_color_matrix)222 void dpp401_set_cursor_matrix(
223 struct dpp *dpp_base,
224 enum dc_color_space color_space,
225 struct dc_csc_transform cursor_csc_color_matrix)
226 {
227 //Since we don't have cursor matrix information, force bypass mode by passing in unknown color space
228 dpp401_program_cursor_csc(dpp_base, COLOR_SPACE_UNKNOWN, NULL);
229 }
230