Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | /* * Copyright 2020 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: AMD * */ #include "reg_helper.h" #include "fixed31_32.h" #include "resource.h" #include "basics/conversion.h" #include "dwb.h" #include "dcn30_dwb.h" #include "dcn30_cm_common.h" #include "dcn10/dcn10_cm_common.h" #define REG(reg)\ dwbc30->dwbc_regs->reg #define CTX \ dwbc30->base.ctx #undef FN #define FN(reg_name, field_name) \ dwbc30->dwbc_shift->field_name, dwbc30->dwbc_mask->field_name #define TO_DCN30_DWBC(dwbc_base) \ container_of(dwbc_base, struct dcn30_dwbc, base) static void dwb3_get_reg_field_ogam(struct dcn30_dwbc *dwbc30, struct dcn3_xfer_func_reg *reg) { reg->shifts.field_region_start_base = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_BASE_B; reg->masks.field_region_start_base = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_BASE_B; reg->shifts.field_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_OFFSET_B; reg->masks.field_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_OFFSET_B; reg->shifts.exp_region0_lut_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION0_LUT_OFFSET; reg->masks.exp_region0_lut_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION0_LUT_OFFSET; reg->shifts.exp_region0_num_segments = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION0_NUM_SEGMENTS; reg->masks.exp_region0_num_segments = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION0_NUM_SEGMENTS; reg->shifts.exp_region1_lut_offset = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION1_LUT_OFFSET; reg->masks.exp_region1_lut_offset = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION1_LUT_OFFSET; reg->shifts.exp_region1_num_segments = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION1_NUM_SEGMENTS; reg->masks.exp_region1_num_segments = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION1_NUM_SEGMENTS; reg->shifts.field_region_end = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_END_B; reg->masks.field_region_end = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_END_B; reg->shifts.field_region_end_slope = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_END_SLOPE_B; reg->masks.field_region_end_slope = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_END_SLOPE_B; reg->shifts.field_region_end_base = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_END_BASE_B; reg->masks.field_region_end_base = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_END_BASE_B; reg->shifts.field_region_linear_slope = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_SLOPE_B; reg->masks.field_region_linear_slope = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_SLOPE_B; reg->shifts.exp_region_start = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_B; reg->masks.exp_region_start = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_B; reg->shifts.exp_resion_start_segment = dwbc30->dwbc_shift->DWB_OGAM_RAMA_EXP_REGION_START_SEGMENT_B; reg->masks.exp_resion_start_segment = dwbc30->dwbc_mask->DWB_OGAM_RAMA_EXP_REGION_START_SEGMENT_B; } /*program dwb ogam RAM A*/ static void dwb3_program_ogam_luta_settings( struct dcn30_dwbc *dwbc30, const struct pwl_params *params) { struct dcn3_xfer_func_reg gam_regs; dwb3_get_reg_field_ogam(dwbc30, &gam_regs); gam_regs.start_cntl_b = REG(DWB_OGAM_RAMA_START_CNTL_B); gam_regs.start_cntl_g = REG(DWB_OGAM_RAMA_START_CNTL_G); gam_regs.start_cntl_r = REG(DWB_OGAM_RAMA_START_CNTL_R); gam_regs.start_base_cntl_b = REG(DWB_OGAM_RAMA_START_BASE_CNTL_B); gam_regs.start_base_cntl_g = REG(DWB_OGAM_RAMA_START_BASE_CNTL_G); gam_regs.start_base_cntl_r = REG(DWB_OGAM_RAMA_START_BASE_CNTL_R); gam_regs.start_slope_cntl_b = REG(DWB_OGAM_RAMA_START_SLOPE_CNTL_B); gam_regs.start_slope_cntl_g = REG(DWB_OGAM_RAMA_START_SLOPE_CNTL_G); gam_regs.start_slope_cntl_r = REG(DWB_OGAM_RAMA_START_SLOPE_CNTL_R); gam_regs.start_end_cntl1_b = REG(DWB_OGAM_RAMA_END_CNTL1_B); gam_regs.start_end_cntl2_b = REG(DWB_OGAM_RAMA_END_CNTL2_B); gam_regs.start_end_cntl1_g = REG(DWB_OGAM_RAMA_END_CNTL1_G); gam_regs.start_end_cntl2_g = REG(DWB_OGAM_RAMA_END_CNTL2_G); gam_regs.start_end_cntl1_r = REG(DWB_OGAM_RAMA_END_CNTL1_R); gam_regs.start_end_cntl2_r = REG(DWB_OGAM_RAMA_END_CNTL2_R); gam_regs.offset_b = REG(DWB_OGAM_RAMA_OFFSET_B); gam_regs.offset_g = REG(DWB_OGAM_RAMA_OFFSET_G); gam_regs.offset_r = REG(DWB_OGAM_RAMA_OFFSET_R); gam_regs.region_start = REG(DWB_OGAM_RAMA_REGION_0_1); gam_regs.region_end = REG(DWB_OGAM_RAMA_REGION_32_33); /*todo*/ cm_helper_program_gamcor_xfer_func(dwbc30->base.ctx, params, &gam_regs); } /*program dwb ogam RAM B*/ static void dwb3_program_ogam_lutb_settings( struct dcn30_dwbc *dwbc30, const struct pwl_params *params) { struct dcn3_xfer_func_reg gam_regs; dwb3_get_reg_field_ogam(dwbc30, &gam_regs); gam_regs.start_cntl_b = REG(DWB_OGAM_RAMB_START_CNTL_B); gam_regs.start_cntl_g = REG(DWB_OGAM_RAMB_START_CNTL_G); gam_regs.start_cntl_r = REG(DWB_OGAM_RAMB_START_CNTL_R); gam_regs.start_base_cntl_b = REG(DWB_OGAM_RAMB_START_BASE_CNTL_B); gam_regs.start_base_cntl_g = REG(DWB_OGAM_RAMB_START_BASE_CNTL_G); gam_regs.start_base_cntl_r = REG(DWB_OGAM_RAMB_START_BASE_CNTL_R); gam_regs.start_slope_cntl_b = REG(DWB_OGAM_RAMB_START_SLOPE_CNTL_B); gam_regs.start_slope_cntl_g = REG(DWB_OGAM_RAMB_START_SLOPE_CNTL_G); gam_regs.start_slope_cntl_r = REG(DWB_OGAM_RAMB_START_SLOPE_CNTL_R); gam_regs.start_end_cntl1_b = REG(DWB_OGAM_RAMB_END_CNTL1_B); gam_regs.start_end_cntl2_b = REG(DWB_OGAM_RAMB_END_CNTL2_B); gam_regs.start_end_cntl1_g = REG(DWB_OGAM_RAMB_END_CNTL1_G); gam_regs.start_end_cntl2_g = REG(DWB_OGAM_RAMB_END_CNTL2_G); gam_regs.start_end_cntl1_r = REG(DWB_OGAM_RAMB_END_CNTL1_R); gam_regs.start_end_cntl2_r = REG(DWB_OGAM_RAMB_END_CNTL2_R); gam_regs.offset_b = REG(DWB_OGAM_RAMB_OFFSET_B); gam_regs.offset_g = REG(DWB_OGAM_RAMB_OFFSET_G); gam_regs.offset_r = REG(DWB_OGAM_RAMB_OFFSET_R); gam_regs.region_start = REG(DWB_OGAM_RAMB_REGION_0_1); gam_regs.region_end = REG(DWB_OGAM_RAMB_REGION_32_33); cm_helper_program_gamcor_xfer_func(dwbc30->base.ctx, params, &gam_regs); } static enum dc_lut_mode dwb3_get_ogam_current( struct dcn30_dwbc *dwbc30) { enum dc_lut_mode mode; uint32_t state_mode; uint32_t ram_select; REG_GET_2(DWB_OGAM_CONTROL, DWB_OGAM_MODE_CURRENT, &state_mode, DWB_OGAM_SELECT_CURRENT, &ram_select); if (state_mode == 0) { mode = LUT_BYPASS; } else if (state_mode == 2) { if (ram_select == 0) mode = LUT_RAM_A; else if (ram_select == 1) mode = LUT_RAM_B; else mode = LUT_BYPASS; } else { // Reserved value mode = LUT_BYPASS; BREAK_TO_DEBUGGER(); return mode; } return mode; } static void dwb3_configure_ogam_lut( struct dcn30_dwbc *dwbc30, bool is_ram_a) { REG_UPDATE_2(DWB_OGAM_LUT_CONTROL, DWB_OGAM_LUT_WRITE_COLOR_MASK, 7, DWB_OGAM_LUT_HOST_SEL, (is_ram_a == true) ? 0 : 1); REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); } static void dwb3_program_ogam_pwl(struct dcn30_dwbc *dwbc30, const struct pwl_result_data *rgb, uint32_t num) { uint32_t i; uint32_t last_base_value_red = rgb[num-1].red_reg + rgb[num-1].delta_red_reg; uint32_t last_base_value_green = rgb[num-1].green_reg + rgb[num-1].delta_green_reg; uint32_t last_base_value_blue = rgb[num-1].blue_reg + rgb[num-1].delta_blue_reg; if (is_rgb_equal(rgb, num)) { for (i = 0 ; i < num; i++) REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].red_reg); REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_red); } else { REG_UPDATE(DWB_OGAM_LUT_CONTROL, DWB_OGAM_LUT_WRITE_COLOR_MASK, 4); for (i = 0 ; i < num; i++) REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].red_reg); REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_red); REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); REG_UPDATE(DWB_OGAM_LUT_CONTROL, DWB_OGAM_LUT_WRITE_COLOR_MASK, 2); for (i = 0 ; i < num; i++) REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].green_reg); REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_green); REG_SET(DWB_OGAM_LUT_INDEX, 0, DWB_OGAM_LUT_INDEX, 0); REG_UPDATE(DWB_OGAM_LUT_CONTROL, DWB_OGAM_LUT_WRITE_COLOR_MASK, 1); for (i = 0 ; i < num; i++) REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, rgb[i].blue_reg); REG_SET(DWB_OGAM_LUT_DATA, 0, DWB_OGAM_LUT_DATA, last_base_value_blue); } } static bool dwb3_program_ogam_lut( struct dcn30_dwbc *dwbc30, const struct pwl_params *params) { enum dc_lut_mode current_mode; enum dc_lut_mode next_mode; if (params == NULL) { REG_SET(DWB_OGAM_CONTROL, 0, DWB_OGAM_MODE, 0); return false; } REG_SET(DWB_OGAM_CONTROL, 0, DWB_OGAM_MODE, 2); current_mode = dwb3_get_ogam_current(dwbc30); if (current_mode == LUT_BYPASS || current_mode == LUT_RAM_A) next_mode = LUT_RAM_B; else next_mode = LUT_RAM_A; dwb3_configure_ogam_lut(dwbc30, next_mode == LUT_RAM_A ? true : false); if (next_mode == LUT_RAM_A) dwb3_program_ogam_luta_settings(dwbc30, params); else dwb3_program_ogam_lutb_settings(dwbc30, params); dwb3_program_ogam_pwl( dwbc30, params->rgb_resulted, params->hw_points_num); REG_UPDATE(DWB_OGAM_CONTROL, DWB_OGAM_SELECT, next_mode == LUT_RAM_A ? 0 : 1); return true; } bool dwb3_ogam_set_input_transfer_func( struct dwbc *dwbc, const struct dc_transfer_func *in_transfer_func_dwb_ogam) { struct dcn30_dwbc *dwbc30 = TO_DCN30_DWBC(dwbc); bool result = false; struct pwl_params *dwb_ogam_lut = NULL; if (in_transfer_func_dwb_ogam == NULL) return result; dwb_ogam_lut = kzalloc(sizeof(*dwb_ogam_lut), GFP_KERNEL); if (dwb_ogam_lut) { cm_helper_translate_curve_to_hw_format( in_transfer_func_dwb_ogam, dwb_ogam_lut, false); result = dwb3_program_ogam_lut( dwbc30, dwb_ogam_lut); kfree(dwb_ogam_lut); dwb_ogam_lut = NULL; } return result; } static void dwb3_program_gamut_remap( struct dwbc *dwbc, const uint16_t *regval, enum cm_gamut_coef_format coef_format, enum cm_gamut_remap_select select) { struct dcn30_dwbc *dwbc30 = TO_DCN30_DWBC(dwbc); struct color_matrices_reg gam_regs; if (regval == NULL || select == CM_GAMUT_REMAP_MODE_BYPASS) { REG_SET(DWB_GAMUT_REMAP_MODE, 0, DWB_GAMUT_REMAP_MODE, 0); return; } REG_UPDATE(DWB_GAMUT_REMAP_COEF_FORMAT, DWB_GAMUT_REMAP_COEF_FORMAT, coef_format); gam_regs.shifts.csc_c11 = dwbc30->dwbc_shift->DWB_GAMUT_REMAPA_C11; gam_regs.masks.csc_c11 = dwbc30->dwbc_mask->DWB_GAMUT_REMAPA_C11; gam_regs.shifts.csc_c12 = dwbc30->dwbc_shift->DWB_GAMUT_REMAPA_C12; gam_regs.masks.csc_c12 = dwbc30->dwbc_mask->DWB_GAMUT_REMAPA_C12; switch (select) { case CM_GAMUT_REMAP_MODE_RAMA_COEFF: gam_regs.csc_c11_c12 = REG(DWB_GAMUT_REMAPA_C11_C12); gam_regs.csc_c33_c34 = REG(DWB_GAMUT_REMAPA_C33_C34); cm_helper_program_color_matrices( dwbc30->base.ctx, regval, &gam_regs); break; case CM_GAMUT_REMAP_MODE_RAMB_COEFF: gam_regs.csc_c11_c12 = REG(DWB_GAMUT_REMAPB_C11_C12); gam_regs.csc_c33_c34 = REG(DWB_GAMUT_REMAPB_C33_C34); cm_helper_program_color_matrices( dwbc30->base.ctx, regval, &gam_regs); break; case CM_GAMUT_REMAP_MODE_RESERVED: /* should never happen, bug */ BREAK_TO_DEBUGGER(); return; default: break; } REG_SET(DWB_GAMUT_REMAP_MODE, 0, DWB_GAMUT_REMAP_MODE, select); } void dwb3_set_gamut_remap( struct dwbc *dwbc, const struct dc_dwb_params *params) { struct dcn30_dwbc *dwbc30 = TO_DCN30_DWBC(dwbc); struct cm_grph_csc_adjustment adjust = params->csc_params; int i = 0; if (adjust.gamut_adjust_type != CM_GAMUT_ADJUST_TYPE_SW) { /* Bypass if type is bypass or hw */ dwb3_program_gamut_remap(dwbc, NULL, adjust.gamut_coef_format, CM_GAMUT_REMAP_MODE_BYPASS); } else { struct fixed31_32 arr_matrix[12]; uint16_t arr_reg_val[12]; unsigned int current_mode; for (i = 0; i < 12; i++) arr_matrix[i] = adjust.temperature_matrix[i]; convert_float_matrix(arr_reg_val, arr_matrix, 12); REG_GET(DWB_GAMUT_REMAP_MODE, DWB_GAMUT_REMAP_MODE_CURRENT, ¤t_mode); if (current_mode == CM_GAMUT_REMAP_MODE_RAMA_COEFF) { dwb3_program_gamut_remap(dwbc, arr_reg_val, adjust.gamut_coef_format, CM_GAMUT_REMAP_MODE_RAMB_COEFF); } else { dwb3_program_gamut_remap(dwbc, arr_reg_val, adjust.gamut_coef_format, CM_GAMUT_REMAP_MODE_RAMA_COEFF); } } } void dwb3_program_hdr_mult( struct dwbc *dwbc, const struct dc_dwb_params *params) { struct dcn30_dwbc *dwbc30 = TO_DCN30_DWBC(dwbc); REG_UPDATE(DWB_HDR_MULT_COEF, DWB_HDR_MULT_COEF, params->hdr_mult); } |