1 /* 2 * Copyright 2017 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 #include "dcn10_ipp.h" 28 #include "reg_helper.h" 29 30 #define REG(reg) \ 31 (ippn10->regs->reg) 32 33 #undef FN 34 #define FN(reg_name, field_name) \ 35 ippn10->ipp_shift->field_name, ippn10->ipp_mask->field_name 36 37 #define CTX \ 38 ippn10->base.ctx 39 40 41 struct dcn10_input_csc_matrix { 42 enum dc_color_space color_space; 43 uint32_t regval[12]; 44 }; 45 46 static const struct dcn10_input_csc_matrix dcn10_input_csc_matrix[] = { 47 {COLOR_SPACE_SRGB, 48 {0x2000, 0, 0, 0, 0, 0x2000, 0, 0, 0, 0, 0x2000, 0} }, 49 {COLOR_SPACE_SRGB_LIMITED, 50 {0x2000, 0, 0, 0, 0, 0x2000, 0, 0, 0, 0, 0x2000, 0} }, 51 {COLOR_SPACE_YCBCR601, 52 {0x2cdd, 0x2000, 0, 0xe991, 0xe926, 0x2000, 0xf4fd, 0x10ef, 53 0, 0x2000, 0x38b4, 0xe3a6} }, 54 {COLOR_SPACE_YCBCR601_LIMITED, 55 {0x3353, 0x2568, 0, 0xe400, 0xe5dc, 0x2568, 0xf367, 0x1108, 56 0, 0x2568, 0x40de, 0xdd3a} }, 57 {COLOR_SPACE_YCBCR709, 58 {0x3265, 0x2000, 0, 0xe6ce, 0xf105, 0x2000, 0xfa01, 0xa7d, 0, 59 0x2000, 0x3b61, 0xe24f} }, 60 61 {COLOR_SPACE_YCBCR709_LIMITED, 62 {0x39a6, 0x2568, 0, 0xe0d6, 0xeedd, 0x2568, 0xf925, 0x9a8, 0, 63 0x2568, 0x43ee, 0xdbb2} } 64 }; 65 66 enum dcn10_input_csc_select { 67 INPUT_CSC_SELECT_BYPASS = 0, 68 INPUT_CSC_SELECT_ICSC, 69 INPUT_CSC_SELECT_COMA 70 }; 71 72 static void dcn10_program_input_csc( 73 struct input_pixel_processor *ipp, 74 enum dc_color_space color_space, 75 enum dcn10_input_csc_select select) 76 { 77 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 78 int i; 79 int arr_size = sizeof(dcn10_input_csc_matrix)/sizeof(struct dcn10_input_csc_matrix); 80 const uint32_t *regval = NULL; 81 uint32_t selection = 1; 82 83 if (select == INPUT_CSC_SELECT_BYPASS) { 84 REG_SET(CM_ICSC_CONTROL, 0, CM_ICSC_MODE, 0); 85 return; 86 } 87 88 for (i = 0; i < arr_size; i++) 89 if (dcn10_input_csc_matrix[i].color_space == color_space) { 90 regval = dcn10_input_csc_matrix[i].regval; 91 break; 92 } 93 94 if (regval == NULL) { 95 BREAK_TO_DEBUGGER(); 96 return; 97 } 98 99 if (select == INPUT_CSC_SELECT_COMA) 100 selection = 2; 101 REG_SET(CM_ICSC_CONTROL, 0, 102 CM_ICSC_MODE, selection); 103 104 if (select == INPUT_CSC_SELECT_ICSC) { 105 /*R*/ 106 REG_SET_2(CM_ICSC_C11_C12, 0, 107 CM_ICSC_C11, regval[0], 108 CM_ICSC_C12, regval[1]); 109 regval += 2; 110 REG_SET_2(CM_ICSC_C13_C14, 0, 111 CM_ICSC_C13, regval[0], 112 CM_ICSC_C14, regval[1]); 113 /*G*/ 114 regval += 2; 115 REG_SET_2(CM_ICSC_C21_C22, 0, 116 CM_ICSC_C21, regval[0], 117 CM_ICSC_C22, regval[1]); 118 regval += 2; 119 REG_SET_2(CM_ICSC_C23_C24, 0, 120 CM_ICSC_C23, regval[0], 121 CM_ICSC_C24, regval[1]); 122 /*B*/ 123 regval += 2; 124 REG_SET_2(CM_ICSC_C31_C32, 0, 125 CM_ICSC_C31, regval[0], 126 CM_ICSC_C32, regval[1]); 127 regval += 2; 128 REG_SET_2(CM_ICSC_C33_C34, 0, 129 CM_ICSC_C33, regval[0], 130 CM_ICSC_C34, regval[1]); 131 } else { 132 /*R*/ 133 REG_SET_2(CM_COMA_C11_C12, 0, 134 CM_COMA_C11, regval[0], 135 CM_COMA_C12, regval[1]); 136 regval += 2; 137 REG_SET_2(CM_COMA_C13_C14, 0, 138 CM_COMA_C13, regval[0], 139 CM_COMA_C14, regval[1]); 140 /*G*/ 141 regval += 2; 142 REG_SET_2(CM_COMA_C21_C22, 0, 143 CM_COMA_C21, regval[0], 144 CM_COMA_C22, regval[1]); 145 regval += 2; 146 REG_SET_2(CM_COMA_C23_C24, 0, 147 CM_COMA_C23, regval[0], 148 CM_COMA_C24, regval[1]); 149 /*B*/ 150 regval += 2; 151 REG_SET_2(CM_COMA_C31_C32, 0, 152 CM_COMA_C31, regval[0], 153 CM_COMA_C32, regval[1]); 154 regval += 2; 155 REG_SET_2(CM_COMA_C33_C34, 0, 156 CM_COMA_C33, regval[0], 157 CM_COMA_C34, regval[1]); 158 } 159 } 160 161 /*program de gamma RAM B*/ 162 static void dcn10_ipp_program_degamma_lutb_settings( 163 struct input_pixel_processor *ipp, 164 const struct pwl_params *params) 165 { 166 const struct gamma_curve *curve; 167 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 168 169 REG_SET_2(CM_DGAM_RAMB_START_CNTL_B, 0, 170 CM_DGAM_RAMB_EXP_REGION_START_B, params->arr_points[0].custom_float_x, 171 CM_DGAM_RAMB_EXP_REGION_START_SEGMENT_B, 0); 172 173 REG_SET_2(CM_DGAM_RAMB_START_CNTL_G, 0, 174 CM_DGAM_RAMB_EXP_REGION_START_G, params->arr_points[0].custom_float_x, 175 CM_DGAM_RAMB_EXP_REGION_START_SEGMENT_G, 0); 176 177 REG_SET_2(CM_DGAM_RAMB_START_CNTL_R, 0, 178 CM_DGAM_RAMB_EXP_REGION_START_R, params->arr_points[0].custom_float_x, 179 CM_DGAM_RAMB_EXP_REGION_START_SEGMENT_R, 0); 180 181 REG_SET(CM_DGAM_RAMB_SLOPE_CNTL_B, 0, 182 CM_DGAM_RAMB_EXP_REGION_LINEAR_SLOPE_B, params->arr_points[0].custom_float_slope); 183 184 REG_SET(CM_DGAM_RAMB_SLOPE_CNTL_G, 0, 185 CM_DGAM_RAMB_EXP_REGION_LINEAR_SLOPE_G, params->arr_points[0].custom_float_slope); 186 187 REG_SET(CM_DGAM_RAMB_SLOPE_CNTL_R, 0, 188 CM_DGAM_RAMB_EXP_REGION_LINEAR_SLOPE_R, params->arr_points[0].custom_float_slope); 189 190 REG_SET(CM_DGAM_RAMB_END_CNTL1_B, 0, 191 CM_DGAM_RAMB_EXP_REGION_END_B, params->arr_points[1].custom_float_x); 192 193 REG_SET_2(CM_DGAM_RAMB_END_CNTL2_B, 0, 194 CM_DGAM_RAMB_EXP_REGION_END_SLOPE_B, params->arr_points[1].custom_float_y, 195 CM_DGAM_RAMB_EXP_REGION_END_BASE_B, params->arr_points[2].custom_float_slope); 196 197 REG_SET(CM_DGAM_RAMB_END_CNTL1_G, 0, 198 CM_DGAM_RAMB_EXP_REGION_END_G, params->arr_points[1].custom_float_x); 199 200 REG_SET_2(CM_DGAM_RAMB_END_CNTL2_G, 0, 201 CM_DGAM_RAMB_EXP_REGION_END_SLOPE_G, params->arr_points[1].custom_float_y, 202 CM_DGAM_RAMB_EXP_REGION_END_BASE_G, params->arr_points[2].custom_float_slope); 203 204 REG_SET(CM_DGAM_RAMB_END_CNTL1_R, 0, 205 CM_DGAM_RAMB_EXP_REGION_END_R, params->arr_points[1].custom_float_x); 206 207 REG_SET_2(CM_DGAM_RAMB_END_CNTL2_R, 0, 208 CM_DGAM_RAMB_EXP_REGION_END_SLOPE_R, params->arr_points[1].custom_float_y, 209 CM_DGAM_RAMB_EXP_REGION_END_BASE_R, params->arr_points[2].custom_float_slope); 210 211 curve = params->arr_curve_points; 212 REG_SET_4(CM_DGAM_RAMB_REGION_0_1, 0, 213 CM_DGAM_RAMB_EXP_REGION0_LUT_OFFSET, curve[0].offset, 214 CM_DGAM_RAMB_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num, 215 CM_DGAM_RAMB_EXP_REGION1_LUT_OFFSET, curve[1].offset, 216 CM_DGAM_RAMB_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num); 217 218 curve += 2; 219 REG_SET_4(CM_DGAM_RAMB_REGION_2_3, 0, 220 CM_DGAM_RAMB_EXP_REGION2_LUT_OFFSET, curve[0].offset, 221 CM_DGAM_RAMB_EXP_REGION2_NUM_SEGMENTS, curve[0].segments_num, 222 CM_DGAM_RAMB_EXP_REGION3_LUT_OFFSET, curve[1].offset, 223 CM_DGAM_RAMB_EXP_REGION3_NUM_SEGMENTS, curve[1].segments_num); 224 225 curve += 2; 226 REG_SET_4(CM_DGAM_RAMB_REGION_4_5, 0, 227 CM_DGAM_RAMB_EXP_REGION4_LUT_OFFSET, curve[0].offset, 228 CM_DGAM_RAMB_EXP_REGION4_NUM_SEGMENTS, curve[0].segments_num, 229 CM_DGAM_RAMB_EXP_REGION5_LUT_OFFSET, curve[1].offset, 230 CM_DGAM_RAMB_EXP_REGION5_NUM_SEGMENTS, curve[1].segments_num); 231 232 curve += 2; 233 REG_SET_4(CM_DGAM_RAMB_REGION_6_7, 0, 234 CM_DGAM_RAMB_EXP_REGION6_LUT_OFFSET, curve[0].offset, 235 CM_DGAM_RAMB_EXP_REGION6_NUM_SEGMENTS, curve[0].segments_num, 236 CM_DGAM_RAMB_EXP_REGION7_LUT_OFFSET, curve[1].offset, 237 CM_DGAM_RAMB_EXP_REGION7_NUM_SEGMENTS, curve[1].segments_num); 238 239 curve += 2; 240 REG_SET_4(CM_DGAM_RAMB_REGION_8_9, 0, 241 CM_DGAM_RAMB_EXP_REGION8_LUT_OFFSET, curve[0].offset, 242 CM_DGAM_RAMB_EXP_REGION8_NUM_SEGMENTS, curve[0].segments_num, 243 CM_DGAM_RAMB_EXP_REGION9_LUT_OFFSET, curve[1].offset, 244 CM_DGAM_RAMB_EXP_REGION9_NUM_SEGMENTS, curve[1].segments_num); 245 246 curve += 2; 247 REG_SET_4(CM_DGAM_RAMB_REGION_10_11, 0, 248 CM_DGAM_RAMB_EXP_REGION10_LUT_OFFSET, curve[0].offset, 249 CM_DGAM_RAMB_EXP_REGION10_NUM_SEGMENTS, curve[0].segments_num, 250 CM_DGAM_RAMB_EXP_REGION11_LUT_OFFSET, curve[1].offset, 251 CM_DGAM_RAMB_EXP_REGION11_NUM_SEGMENTS, curve[1].segments_num); 252 253 curve += 2; 254 REG_SET_4(CM_DGAM_RAMB_REGION_12_13, 0, 255 CM_DGAM_RAMB_EXP_REGION12_LUT_OFFSET, curve[0].offset, 256 CM_DGAM_RAMB_EXP_REGION12_NUM_SEGMENTS, curve[0].segments_num, 257 CM_DGAM_RAMB_EXP_REGION13_LUT_OFFSET, curve[1].offset, 258 CM_DGAM_RAMB_EXP_REGION13_NUM_SEGMENTS, curve[1].segments_num); 259 260 curve += 2; 261 REG_SET_4(CM_DGAM_RAMB_REGION_14_15, 0, 262 CM_DGAM_RAMB_EXP_REGION14_LUT_OFFSET, curve[0].offset, 263 CM_DGAM_RAMB_EXP_REGION14_NUM_SEGMENTS, curve[0].segments_num, 264 CM_DGAM_RAMB_EXP_REGION15_LUT_OFFSET, curve[1].offset, 265 CM_DGAM_RAMB_EXP_REGION15_NUM_SEGMENTS, curve[1].segments_num); 266 } 267 268 /*program de gamma RAM A*/ 269 static void dcn10_ipp_program_degamma_luta_settings( 270 struct input_pixel_processor *ipp, 271 const struct pwl_params *params) 272 { 273 const struct gamma_curve *curve; 274 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 275 276 REG_SET_2(CM_DGAM_RAMA_START_CNTL_B, 0, 277 CM_DGAM_RAMA_EXP_REGION_START_B, params->arr_points[0].custom_float_x, 278 CM_DGAM_RAMA_EXP_REGION_START_SEGMENT_B, 0); 279 280 REG_SET_2(CM_DGAM_RAMA_START_CNTL_G, 0, 281 CM_DGAM_RAMA_EXP_REGION_START_G, params->arr_points[0].custom_float_x, 282 CM_DGAM_RAMA_EXP_REGION_START_SEGMENT_G, 0); 283 284 REG_SET_2(CM_DGAM_RAMA_START_CNTL_R, 0, 285 CM_DGAM_RAMA_EXP_REGION_START_R, params->arr_points[0].custom_float_x, 286 CM_DGAM_RAMA_EXP_REGION_START_SEGMENT_R, 0); 287 288 REG_SET(CM_DGAM_RAMA_SLOPE_CNTL_B, 0, 289 CM_DGAM_RAMA_EXP_REGION_LINEAR_SLOPE_B, params->arr_points[0].custom_float_slope); 290 291 REG_SET(CM_DGAM_RAMA_SLOPE_CNTL_G, 0, 292 CM_DGAM_RAMA_EXP_REGION_LINEAR_SLOPE_G, params->arr_points[0].custom_float_slope); 293 294 REG_SET(CM_DGAM_RAMA_SLOPE_CNTL_R, 0, 295 CM_DGAM_RAMA_EXP_REGION_LINEAR_SLOPE_R, params->arr_points[0].custom_float_slope); 296 297 REG_SET(CM_DGAM_RAMA_END_CNTL1_B, 0, 298 CM_DGAM_RAMA_EXP_REGION_END_B, params->arr_points[1].custom_float_x); 299 300 REG_SET_2(CM_DGAM_RAMA_END_CNTL2_B, 0, 301 CM_DGAM_RAMA_EXP_REGION_END_SLOPE_B, params->arr_points[1].custom_float_y, 302 CM_DGAM_RAMA_EXP_REGION_END_BASE_B, params->arr_points[2].custom_float_slope); 303 304 REG_SET(CM_DGAM_RAMA_END_CNTL1_G, 0, 305 CM_DGAM_RAMA_EXP_REGION_END_G, params->arr_points[1].custom_float_x); 306 307 REG_SET_2(CM_DGAM_RAMA_END_CNTL2_G, 0, 308 CM_DGAM_RAMA_EXP_REGION_END_SLOPE_G, params->arr_points[1].custom_float_y, 309 CM_DGAM_RAMA_EXP_REGION_END_BASE_G, params->arr_points[2].custom_float_slope); 310 311 REG_SET(CM_DGAM_RAMA_END_CNTL1_R, 0, 312 CM_DGAM_RAMA_EXP_REGION_END_R, params->arr_points[1].custom_float_x); 313 314 REG_SET_2(CM_DGAM_RAMA_END_CNTL2_R, 0, 315 CM_DGAM_RAMA_EXP_REGION_END_SLOPE_R, params->arr_points[1].custom_float_y, 316 CM_DGAM_RAMA_EXP_REGION_END_BASE_R, params->arr_points[2].custom_float_slope); 317 318 curve = params->arr_curve_points; 319 REG_SET_4(CM_DGAM_RAMA_REGION_0_1, 0, 320 CM_DGAM_RAMA_EXP_REGION0_LUT_OFFSET, curve[0].offset, 321 CM_DGAM_RAMA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num, 322 CM_DGAM_RAMA_EXP_REGION1_LUT_OFFSET, curve[1].offset, 323 CM_DGAM_RAMA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num); 324 325 curve += 2; 326 REG_SET_4(CM_DGAM_RAMA_REGION_2_3, 0, 327 CM_DGAM_RAMA_EXP_REGION2_LUT_OFFSET, curve[0].offset, 328 CM_DGAM_RAMA_EXP_REGION2_NUM_SEGMENTS, curve[0].segments_num, 329 CM_DGAM_RAMA_EXP_REGION3_LUT_OFFSET, curve[1].offset, 330 CM_DGAM_RAMA_EXP_REGION3_NUM_SEGMENTS, curve[1].segments_num); 331 332 curve += 2; 333 REG_SET_4(CM_DGAM_RAMA_REGION_4_5, 0, 334 CM_DGAM_RAMA_EXP_REGION4_LUT_OFFSET, curve[0].offset, 335 CM_DGAM_RAMA_EXP_REGION4_NUM_SEGMENTS, curve[0].segments_num, 336 CM_DGAM_RAMA_EXP_REGION5_LUT_OFFSET, curve[1].offset, 337 CM_DGAM_RAMA_EXP_REGION5_NUM_SEGMENTS, curve[1].segments_num); 338 339 curve += 2; 340 REG_SET_4(CM_DGAM_RAMA_REGION_6_7, 0, 341 CM_DGAM_RAMA_EXP_REGION6_LUT_OFFSET, curve[0].offset, 342 CM_DGAM_RAMA_EXP_REGION6_NUM_SEGMENTS, curve[0].segments_num, 343 CM_DGAM_RAMA_EXP_REGION7_LUT_OFFSET, curve[1].offset, 344 CM_DGAM_RAMA_EXP_REGION7_NUM_SEGMENTS, curve[1].segments_num); 345 346 curve += 2; 347 REG_SET_4(CM_DGAM_RAMA_REGION_8_9, 0, 348 CM_DGAM_RAMA_EXP_REGION8_LUT_OFFSET, curve[0].offset, 349 CM_DGAM_RAMA_EXP_REGION8_NUM_SEGMENTS, curve[0].segments_num, 350 CM_DGAM_RAMA_EXP_REGION9_LUT_OFFSET, curve[1].offset, 351 CM_DGAM_RAMA_EXP_REGION9_NUM_SEGMENTS, curve[1].segments_num); 352 353 curve += 2; 354 REG_SET_4(CM_DGAM_RAMA_REGION_10_11, 0, 355 CM_DGAM_RAMA_EXP_REGION10_LUT_OFFSET, curve[0].offset, 356 CM_DGAM_RAMA_EXP_REGION10_NUM_SEGMENTS, curve[0].segments_num, 357 CM_DGAM_RAMA_EXP_REGION11_LUT_OFFSET, curve[1].offset, 358 CM_DGAM_RAMA_EXP_REGION11_NUM_SEGMENTS, curve[1].segments_num); 359 360 curve += 2; 361 REG_SET_4(CM_DGAM_RAMA_REGION_12_13, 0, 362 CM_DGAM_RAMA_EXP_REGION12_LUT_OFFSET, curve[0].offset, 363 CM_DGAM_RAMA_EXP_REGION12_NUM_SEGMENTS, curve[0].segments_num, 364 CM_DGAM_RAMA_EXP_REGION13_LUT_OFFSET, curve[1].offset, 365 CM_DGAM_RAMA_EXP_REGION13_NUM_SEGMENTS, curve[1].segments_num); 366 367 curve += 2; 368 REG_SET_4(CM_DGAM_RAMA_REGION_14_15, 0, 369 CM_DGAM_RAMA_EXP_REGION14_LUT_OFFSET, curve[0].offset, 370 CM_DGAM_RAMA_EXP_REGION14_NUM_SEGMENTS, curve[0].segments_num, 371 CM_DGAM_RAMA_EXP_REGION15_LUT_OFFSET, curve[1].offset, 372 CM_DGAM_RAMA_EXP_REGION15_NUM_SEGMENTS, curve[1].segments_num); 373 } 374 375 static void ipp_power_on_degamma_lut( 376 struct input_pixel_processor *ipp, 377 bool power_on) 378 { 379 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 380 381 REG_SET(CM_MEM_PWR_CTRL, 0, 382 SHARED_MEM_PWR_DIS, power_on == true ? 0:1); 383 384 } 385 386 static void ipp_program_degamma_lut( 387 struct input_pixel_processor *ipp, 388 const struct pwl_result_data *rgb, 389 uint32_t num, 390 bool is_ram_a) 391 { 392 uint32_t i; 393 394 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 395 REG_UPDATE(CM_IGAM_LUT_RW_CONTROL, CM_IGAM_LUT_HOST_EN, 0); 396 REG_UPDATE(CM_DGAM_LUT_WRITE_EN_MASK, 397 CM_DGAM_LUT_WRITE_EN_MASK, 7); 398 REG_UPDATE(CM_DGAM_LUT_WRITE_EN_MASK, CM_DGAM_LUT_WRITE_SEL, 399 is_ram_a == true ? 0:1); 400 401 REG_SET(CM_DGAM_LUT_INDEX, 0, CM_DGAM_LUT_INDEX, 0); 402 for (i = 0 ; i < num; i++) { 403 REG_SET(CM_DGAM_LUT_DATA, 0, CM_DGAM_LUT_DATA, rgb[i].red_reg); 404 REG_SET(CM_DGAM_LUT_DATA, 0, CM_DGAM_LUT_DATA, rgb[i].green_reg); 405 REG_SET(CM_DGAM_LUT_DATA, 0, CM_DGAM_LUT_DATA, rgb[i].blue_reg); 406 407 REG_SET(CM_DGAM_LUT_DATA, 0, 408 CM_DGAM_LUT_DATA, rgb[i].delta_red_reg); 409 REG_SET(CM_DGAM_LUT_DATA, 0, 410 CM_DGAM_LUT_DATA, rgb[i].delta_green_reg); 411 REG_SET(CM_DGAM_LUT_DATA, 0, 412 CM_DGAM_LUT_DATA, rgb[i].delta_blue_reg); 413 414 } 415 416 } 417 418 static void dcn10_ipp_enable_cm_block( 419 struct input_pixel_processor *ipp) 420 { 421 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 422 423 REG_UPDATE(DPP_CONTROL, DPP_CLOCK_ENABLE, 1); 424 REG_UPDATE(CM_CONTROL, CM_BYPASS_EN, 0); 425 } 426 427 428 static void dcn10_ipp_full_bypass(struct input_pixel_processor *ipp) 429 { 430 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 431 432 /* Input pixel format: ARGB8888 */ 433 REG_SET(CNVC_SURFACE_PIXEL_FORMAT, 0, 434 CNVC_SURFACE_PIXEL_FORMAT, 0x8); 435 436 /* Zero expansion */ 437 REG_SET_3(FORMAT_CONTROL, 0, 438 CNVC_BYPASS, 0, 439 ALPHA_EN, 0, 440 FORMAT_EXPANSION_MODE, 0); 441 442 /* COLOR_KEYER_CONTROL.COLOR_KEYER_EN = 0 this should be default */ 443 REG_SET(CM_CONTROL, 0, CM_BYPASS_EN, 1); 444 445 /* Setting degamma bypass for now */ 446 REG_SET(CM_DGAM_CONTROL, 0, CM_DGAM_LUT_MODE, 0); 447 REG_SET(CM_IGAM_CONTROL, 0, CM_IGAM_LUT_MODE, 0); 448 } 449 450 static void dcn10_ipp_set_degamma( 451 struct input_pixel_processor *ipp, 452 enum ipp_degamma_mode mode) 453 { 454 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 455 dcn10_ipp_enable_cm_block(ipp); 456 457 switch (mode) { 458 case IPP_DEGAMMA_MODE_BYPASS: 459 /* Setting de gamma bypass for now */ 460 REG_UPDATE(CM_DGAM_CONTROL, CM_DGAM_LUT_MODE, 0); 461 break; 462 case IPP_DEGAMMA_MODE_HW_sRGB: 463 REG_UPDATE(CM_DGAM_CONTROL, CM_DGAM_LUT_MODE, 1); 464 break; 465 case IPP_DEGAMMA_MODE_HW_xvYCC: 466 REG_UPDATE(CM_DGAM_CONTROL, CM_DGAM_LUT_MODE, 2); 467 break; 468 default: 469 BREAK_TO_DEBUGGER(); 470 break; 471 } 472 } 473 474 static bool dcn10_cursor_program_control( 475 struct dcn10_ipp *ippn10, 476 bool pixel_data_invert, 477 enum dc_cursor_color_format color_format) 478 { 479 REG_SET_2(CURSOR_SETTINS, 0, 480 /* no shift of the cursor HDL schedule */ 481 CURSOR0_DST_Y_OFFSET, 0, 482 /* used to shift the cursor chunk request deadline */ 483 CURSOR0_CHUNK_HDL_ADJUST, 3); 484 485 REG_UPDATE_2(CURSOR0_CONTROL, 486 CUR0_MODE, color_format, 487 CUR0_INVERT_MODE, 0); 488 489 if (color_format == CURSOR_MODE_MONO) { 490 /* todo: clarify what to program these to */ 491 REG_UPDATE(CURSOR0_COLOR0, 492 CUR0_COLOR0, 0x00000000); 493 REG_UPDATE(CURSOR0_COLOR1, 494 CUR0_COLOR1, 0xFFFFFFFF); 495 } 496 497 /* TODO: Fixed vs float */ 498 499 REG_UPDATE_3(FORMAT_CONTROL, 500 CNVC_BYPASS, 0, 501 ALPHA_EN, 1, 502 FORMAT_EXPANSION_MODE, 0); 503 504 REG_UPDATE(CURSOR0_CONTROL, 505 CUR0_EXPANSION_MODE, 0); 506 507 if (0 /*attributes->attribute_flags.bits.MIN_MAX_INVERT*/) { 508 REG_UPDATE(CURSOR0_CONTROL, 509 CUR0_MAX, 510 0 /* TODO */); 511 REG_UPDATE(CURSOR0_CONTROL, 512 CUR0_MIN, 513 0 /* TODO */); 514 } 515 516 return true; 517 } 518 519 enum cursor_pitch { 520 CURSOR_PITCH_64_PIXELS = 0, 521 CURSOR_PITCH_128_PIXELS, 522 CURSOR_PITCH_256_PIXELS 523 }; 524 525 enum cursor_lines_per_chunk { 526 CURSOR_LINE_PER_CHUNK_2 = 1, 527 CURSOR_LINE_PER_CHUNK_4, 528 CURSOR_LINE_PER_CHUNK_8, 529 CURSOR_LINE_PER_CHUNK_16 530 }; 531 532 static enum cursor_pitch dcn10_get_cursor_pitch( 533 unsigned int pitch) 534 { 535 enum cursor_pitch hw_pitch; 536 537 switch (pitch) { 538 case 64: 539 hw_pitch = CURSOR_PITCH_64_PIXELS; 540 break; 541 case 128: 542 hw_pitch = CURSOR_PITCH_128_PIXELS; 543 break; 544 case 256: 545 hw_pitch = CURSOR_PITCH_256_PIXELS; 546 break; 547 default: 548 DC_ERR("Invalid cursor pitch of %d. " 549 "Only 64/128/256 is supported on DCN.\n", pitch); 550 hw_pitch = CURSOR_PITCH_64_PIXELS; 551 break; 552 } 553 return hw_pitch; 554 } 555 556 static enum cursor_lines_per_chunk dcn10_get_lines_per_chunk( 557 unsigned int cur_width, 558 enum dc_cursor_color_format format) 559 { 560 enum cursor_lines_per_chunk line_per_chunk; 561 562 if (format == CURSOR_MODE_MONO) 563 /* impl B. expansion in CUR Buffer reader */ 564 line_per_chunk = CURSOR_LINE_PER_CHUNK_16; 565 else if (cur_width <= 32) 566 line_per_chunk = CURSOR_LINE_PER_CHUNK_16; 567 else if (cur_width <= 64) 568 line_per_chunk = CURSOR_LINE_PER_CHUNK_8; 569 else if (cur_width <= 128) 570 line_per_chunk = CURSOR_LINE_PER_CHUNK_4; 571 else 572 line_per_chunk = CURSOR_LINE_PER_CHUNK_2; 573 574 return line_per_chunk; 575 } 576 577 static void dcn10_cursor_set_attributes( 578 struct input_pixel_processor *ipp, 579 const struct dc_cursor_attributes *attr) 580 { 581 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 582 enum cursor_pitch hw_pitch = dcn10_get_cursor_pitch(attr->pitch); 583 enum cursor_lines_per_chunk lpc = dcn10_get_lines_per_chunk( 584 attr->width, attr->color_format); 585 586 ippn10->curs_attr = *attr; 587 588 REG_UPDATE(CURSOR_SURFACE_ADDRESS_HIGH, 589 CURSOR_SURFACE_ADDRESS_HIGH, attr->address.high_part); 590 REG_UPDATE(CURSOR_SURFACE_ADDRESS, 591 CURSOR_SURFACE_ADDRESS, attr->address.low_part); 592 593 REG_UPDATE_2(CURSOR_SIZE, 594 CURSOR_WIDTH, attr->width, 595 CURSOR_HEIGHT, attr->height); 596 597 REG_UPDATE_3(CURSOR_CONTROL, 598 CURSOR_MODE, attr->color_format, 599 CURSOR_PITCH, hw_pitch, 600 CURSOR_LINES_PER_CHUNK, lpc); 601 602 dcn10_cursor_program_control(ippn10, 603 attr->attribute_flags.bits.INVERT_PIXEL_DATA, 604 attr->color_format); 605 } 606 607 static void dcn10_cursor_set_position( 608 struct input_pixel_processor *ipp, 609 const struct dc_cursor_position *pos, 610 const struct dc_cursor_mi_param *param) 611 { 612 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 613 int src_x_offset = pos->x - pos->x_hotspot - param->viewport_x_start; 614 uint32_t cur_en = pos->enable ? 1 : 0; 615 uint32_t dst_x_offset = (src_x_offset >= 0) ? src_x_offset : 0; 616 617 dst_x_offset *= param->ref_clk_khz; 618 dst_x_offset /= param->pixel_clk_khz; 619 620 ASSERT(param->h_scale_ratio.value); 621 622 if (param->h_scale_ratio.value) 623 dst_x_offset = dal_fixed31_32_floor(dal_fixed31_32_div( 624 dal_fixed31_32_from_int(dst_x_offset), 625 param->h_scale_ratio)); 626 627 if (src_x_offset >= (int)param->viewport_width) 628 cur_en = 0; /* not visible beyond right edge*/ 629 630 if (src_x_offset + (int)ippn10->curs_attr.width < 0) 631 cur_en = 0; /* not visible beyond left edge*/ 632 633 if (cur_en && REG_READ(CURSOR_SURFACE_ADDRESS) == 0) 634 dcn10_cursor_set_attributes(ipp, &ippn10->curs_attr); 635 REG_UPDATE(CURSOR_CONTROL, 636 CURSOR_ENABLE, cur_en); 637 REG_UPDATE(CURSOR0_CONTROL, 638 CUR0_ENABLE, cur_en); 639 640 REG_SET_2(CURSOR_POSITION, 0, 641 CURSOR_X_POSITION, pos->x, 642 CURSOR_Y_POSITION, pos->y); 643 644 REG_SET_2(CURSOR_HOT_SPOT, 0, 645 CURSOR_HOT_SPOT_X, pos->x_hotspot, 646 CURSOR_HOT_SPOT_Y, pos->y_hotspot); 647 648 REG_SET(CURSOR_DST_OFFSET, 0, 649 CURSOR_DST_X_OFFSET, dst_x_offset); 650 /* TODO Handle surface pixel formats other than 4:4:4 */ 651 } 652 653 enum pixel_format_description { 654 PIXEL_FORMAT_FIXED = 0, 655 PIXEL_FORMAT_FIXED16, 656 PIXEL_FORMAT_FLOAT 657 658 }; 659 660 static void dcn10_setup_format_flags(enum surface_pixel_format input_format,\ 661 enum pixel_format_description *fmt) 662 { 663 664 if (input_format == SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F || 665 input_format == SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F) 666 *fmt = PIXEL_FORMAT_FLOAT; 667 else if (input_format == SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616) 668 *fmt = PIXEL_FORMAT_FIXED16; 669 else 670 *fmt = PIXEL_FORMAT_FIXED; 671 } 672 673 static void dcn10_ipp_set_degamma_format_float(struct input_pixel_processor *ipp, 674 bool is_float) 675 { 676 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 677 678 if (is_float) { 679 REG_UPDATE(CM_IGAM_CONTROL, CM_IGAM_INPUT_FORMAT, 3); 680 REG_UPDATE(CM_IGAM_CONTROL, CM_IGAM_LUT_MODE, 1); 681 } else { 682 REG_UPDATE(CM_IGAM_CONTROL, CM_IGAM_INPUT_FORMAT, 2); 683 REG_UPDATE(CM_IGAM_CONTROL, CM_IGAM_LUT_MODE, 0); 684 } 685 } 686 687 688 static void dcn10_ipp_cnv_setup ( 689 struct input_pixel_processor *ipp, 690 enum surface_pixel_format input_format, 691 enum expansion_mode mode, 692 enum ipp_output_format cnv_out_format) 693 { 694 uint32_t pixel_format; 695 uint32_t alpha_en; 696 enum pixel_format_description fmt ; 697 enum dc_color_space color_space; 698 enum dcn10_input_csc_select select; 699 bool is_float; 700 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 701 bool force_disable_cursor = false; 702 703 dcn10_setup_format_flags(input_format, &fmt); 704 alpha_en = 1; 705 pixel_format = 0; 706 color_space = COLOR_SPACE_SRGB; 707 select = INPUT_CSC_SELECT_BYPASS; 708 is_float = false; 709 710 switch (fmt) { 711 case PIXEL_FORMAT_FIXED: 712 case PIXEL_FORMAT_FIXED16: 713 /*when output is float then FORMAT_CONTROL__OUTPUT_FP=1*/ 714 REG_SET_3(FORMAT_CONTROL, 0, 715 CNVC_BYPASS, 0, 716 FORMAT_EXPANSION_MODE, mode, 717 OUTPUT_FP, 0); 718 break; 719 case PIXEL_FORMAT_FLOAT: 720 REG_SET_3(FORMAT_CONTROL, 0, 721 CNVC_BYPASS, 0, 722 FORMAT_EXPANSION_MODE, mode, 723 OUTPUT_FP, 1); 724 is_float = true; 725 break; 726 default: 727 728 break; 729 } 730 731 dcn10_ipp_set_degamma_format_float(ipp, is_float); 732 733 switch (input_format) { 734 case SURFACE_PIXEL_FORMAT_GRPH_ARGB1555: 735 pixel_format = 1; 736 break; 737 case SURFACE_PIXEL_FORMAT_GRPH_RGB565: 738 pixel_format = 3; 739 alpha_en = 0; 740 break; 741 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888: 742 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888: 743 pixel_format = 8; 744 break; 745 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010: 746 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010: 747 pixel_format = 10; 748 break; 749 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr: 750 force_disable_cursor = false; 751 pixel_format = 65; 752 color_space = COLOR_SPACE_YCBCR709; 753 select = INPUT_CSC_SELECT_ICSC; 754 break; 755 case SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb: 756 force_disable_cursor = true; 757 pixel_format = 64; 758 color_space = COLOR_SPACE_YCBCR709; 759 select = INPUT_CSC_SELECT_ICSC; 760 break; 761 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCbCr: 762 force_disable_cursor = true; 763 pixel_format = 67; 764 color_space = COLOR_SPACE_YCBCR709; 765 select = INPUT_CSC_SELECT_ICSC; 766 break; 767 case SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb: 768 force_disable_cursor = true; 769 pixel_format = 66; 770 color_space = COLOR_SPACE_YCBCR709; 771 select = INPUT_CSC_SELECT_ICSC; 772 break; 773 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616: 774 pixel_format = 22; 775 break; 776 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F: 777 pixel_format = 24; 778 break; 779 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F: 780 pixel_format = 25; 781 break; 782 default: 783 break; 784 } 785 REG_SET(CNVC_SURFACE_PIXEL_FORMAT, 0, 786 CNVC_SURFACE_PIXEL_FORMAT, pixel_format); 787 REG_UPDATE(FORMAT_CONTROL, ALPHA_EN, alpha_en); 788 789 dcn10_program_input_csc(ipp, color_space, select); 790 791 if (force_disable_cursor) { 792 REG_UPDATE(CURSOR_CONTROL, 793 CURSOR_ENABLE, 0); 794 REG_UPDATE(CURSOR0_CONTROL, 795 CUR0_ENABLE, 0); 796 } 797 } 798 799 800 static bool dcn10_degamma_ram_inuse(struct input_pixel_processor *ipp, 801 bool *ram_a_inuse) 802 { 803 bool ret = false; 804 uint32_t status_reg = 0; 805 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 806 807 status_reg = (REG_READ(CM_IGAM_LUT_RW_CONTROL) & 0x0F00) >>16; 808 if (status_reg == 9) { 809 *ram_a_inuse = true; 810 ret = true; 811 } else if (status_reg == 10) { 812 *ram_a_inuse = false; 813 ret = true; 814 } 815 return ret; 816 } 817 818 static void dcn10_degamma_ram_select(struct input_pixel_processor *ipp, 819 bool use_ram_a) 820 { 821 struct dcn10_ipp *ippn10 = TO_DCN10_IPP(ipp); 822 823 if (use_ram_a) 824 REG_UPDATE(CM_DGAM_CONTROL, CM_DGAM_LUT_MODE, 3); 825 else 826 REG_UPDATE(CM_DGAM_CONTROL, CM_DGAM_LUT_MODE, 4); 827 828 } 829 830 static void dcn10_ipp_set_degamma_pwl(struct input_pixel_processor *ipp, 831 const struct pwl_params *params) 832 { 833 bool is_ram_a = true; 834 835 ipp_power_on_degamma_lut(ipp, true); 836 dcn10_ipp_enable_cm_block(ipp); 837 dcn10_degamma_ram_inuse(ipp, &is_ram_a); 838 if (is_ram_a == true) 839 dcn10_ipp_program_degamma_lutb_settings(ipp, params); 840 else 841 dcn10_ipp_program_degamma_luta_settings(ipp, params); 842 843 ipp_program_degamma_lut(ipp, params->rgb_resulted, 844 params->hw_points_num, !is_ram_a); 845 dcn10_degamma_ram_select(ipp, !is_ram_a); 846 } 847 848 /*****************************************/ 849 /* Constructor, Destructor */ 850 /*****************************************/ 851 852 static void dcn10_ipp_destroy(struct input_pixel_processor **ipp) 853 { 854 dm_free(TO_DCN10_IPP(*ipp)); 855 *ipp = NULL; 856 } 857 858 static const struct ipp_funcs dcn10_ipp_funcs = { 859 .ipp_cursor_set_attributes = dcn10_cursor_set_attributes, 860 .ipp_cursor_set_position = dcn10_cursor_set_position, 861 .ipp_set_degamma = dcn10_ipp_set_degamma, 862 .ipp_full_bypass = dcn10_ipp_full_bypass, 863 .ipp_setup = dcn10_ipp_cnv_setup, 864 .ipp_program_degamma_pwl = dcn10_ipp_set_degamma_pwl, 865 .ipp_destroy = dcn10_ipp_destroy 866 }; 867 868 void dcn10_ipp_construct( 869 struct dcn10_ipp *ippn10, 870 struct dc_context *ctx, 871 int inst, 872 const struct dcn10_ipp_registers *regs, 873 const struct dcn10_ipp_shift *ipp_shift, 874 const struct dcn10_ipp_mask *ipp_mask) 875 { 876 ippn10->base.ctx = ctx; 877 ippn10->base.inst = inst; 878 ippn10->base.funcs = &dcn10_ipp_funcs; 879 880 ippn10->regs = regs; 881 ippn10->ipp_shift = ipp_shift; 882 ippn10->ipp_mask = ipp_mask; 883 } 884