1 /* 2 * Copyright 2019 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 "dc_bios_types.h" 27 #include "dcn31_hpo_dp_stream_encoder.h" 28 #include "reg_helper.h" 29 #include "dc_link.h" 30 31 #define DC_LOGGER \ 32 enc3->base.ctx->logger 33 34 #define REG(reg)\ 35 (enc3->regs->reg) 36 37 #undef FN 38 #define FN(reg_name, field_name) \ 39 enc3->hpo_se_shift->field_name, enc3->hpo_se_mask->field_name 40 41 #define CTX \ 42 enc3->base.ctx 43 44 45 enum dp2_pixel_encoding { 46 DP_SYM32_ENC_PIXEL_ENCODING_RGB_YCBCR444, 47 DP_SYM32_ENC_PIXEL_ENCODING_YCBCR422, 48 DP_SYM32_ENC_PIXEL_ENCODING_YCBCR420, 49 DP_SYM32_ENC_PIXEL_ENCODING_Y_ONLY 50 }; 51 52 enum dp2_uncompressed_component_depth { 53 DP_SYM32_ENC_COMPONENT_DEPTH_6BPC, 54 DP_SYM32_ENC_COMPONENT_DEPTH_8BPC, 55 DP_SYM32_ENC_COMPONENT_DEPTH_10BPC, 56 DP_SYM32_ENC_COMPONENT_DEPTH_12BPC 57 }; 58 59 60 static void dcn31_hpo_dp_stream_enc_enable_stream( 61 struct hpo_dp_stream_encoder *enc) 62 { 63 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 64 65 /* Enable all clocks in the DP_STREAM_ENC */ 66 REG_UPDATE(DP_STREAM_ENC_CLOCK_CONTROL, 67 DP_STREAM_ENC_CLOCK_EN, 1); 68 69 /* Assert reset to the DP_SYM32_ENC logic */ 70 REG_UPDATE(DP_SYM32_ENC_CONTROL, 71 DP_SYM32_ENC_RESET, 1); 72 /* Wait for reset to complete (to assert) */ 73 REG_WAIT(DP_SYM32_ENC_CONTROL, 74 DP_SYM32_ENC_RESET_DONE, 1, 75 1, 10); 76 77 /* De-assert reset to the DP_SYM32_ENC logic */ 78 REG_UPDATE(DP_SYM32_ENC_CONTROL, 79 DP_SYM32_ENC_RESET, 0); 80 /* Wait for reset to de-assert */ 81 REG_WAIT(DP_SYM32_ENC_CONTROL, 82 DP_SYM32_ENC_RESET_DONE, 0, 83 1, 10); 84 85 /* Enable idle pattern generation */ 86 REG_UPDATE(DP_SYM32_ENC_CONTROL, 87 DP_SYM32_ENC_ENABLE, 1); 88 } 89 90 static void dcn31_hpo_dp_stream_enc_dp_unblank( 91 struct hpo_dp_stream_encoder *enc, 92 uint32_t stream_source) 93 { 94 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 95 96 /* Set the input mux for video stream source */ 97 REG_UPDATE(DP_STREAM_ENC_INPUT_MUX_CONTROL, 98 DP_STREAM_ENC_INPUT_MUX_PIXEL_STREAM_SOURCE_SEL, stream_source); 99 100 /* Enable video transmission in main framer */ 101 REG_UPDATE(DP_SYM32_ENC_VID_STREAM_CONTROL, 102 VID_STREAM_ENABLE, 1); 103 104 /* Reset and Enable Pixel to Symbol FIFO */ 105 REG_UPDATE(DP_SYM32_ENC_VID_FIFO_CONTROL, 106 PIXEL_TO_SYMBOL_FIFO_RESET, 1); 107 REG_WAIT(DP_SYM32_ENC_VID_FIFO_CONTROL, 108 PIXEL_TO_SYMBOL_FIFO_RESET_DONE, 1, 109 1, 10); 110 REG_UPDATE(DP_SYM32_ENC_VID_FIFO_CONTROL, 111 PIXEL_TO_SYMBOL_FIFO_RESET, 0); 112 REG_WAIT(DP_SYM32_ENC_VID_FIFO_CONTROL, /* Disable Clock Ramp Adjuster FIFO */ 113 PIXEL_TO_SYMBOL_FIFO_RESET_DONE, 0, 114 1, 10); 115 REG_UPDATE(DP_SYM32_ENC_VID_FIFO_CONTROL, 116 PIXEL_TO_SYMBOL_FIFO_ENABLE, 1); 117 118 /* Reset and Enable Clock Ramp Adjuster FIFO */ 119 REG_UPDATE(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 120 FIFO_RESET, 1); 121 REG_WAIT(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 122 FIFO_RESET_DONE, 1, 123 1, 10); 124 REG_UPDATE(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 125 FIFO_RESET, 0); 126 REG_WAIT(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 127 FIFO_RESET_DONE, 0, 128 1, 10); 129 130 /* For Debug -- Enable CRC */ 131 REG_UPDATE_2(DP_SYM32_ENC_VID_CRC_CONTROL, 132 CRC_ENABLE, 1, 133 CRC_CONT_MODE_ENABLE, 1); 134 135 REG_UPDATE(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 136 FIFO_ENABLE, 1); 137 } 138 139 static void dcn31_hpo_dp_stream_enc_dp_blank( 140 struct hpo_dp_stream_encoder *enc) 141 { 142 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 143 144 /* Disable video transmission */ 145 REG_UPDATE(DP_SYM32_ENC_VID_STREAM_CONTROL, 146 VID_STREAM_ENABLE, 0); 147 148 /* Wait for video stream transmission disabled 149 * Larger delay to wait until VBLANK - use max retry of 150 * 10us*5000=50ms. This covers 41.7ms of minimum 24 Hz mode + 151 * a little more because we may not trust delay accuracy. 152 */ 153 //REG_WAIT(DP_SYM32_ENC_VID_STREAM_CONTROL, 154 // VID_STREAM_STATUS, 0, 155 // 10, 5000); 156 157 /* Disable SDP tranmission */ 158 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 159 SDP_STREAM_ENABLE, 0); 160 161 /* Disable Pixel to Symbol FIFO */ 162 REG_UPDATE(DP_SYM32_ENC_VID_FIFO_CONTROL, 163 PIXEL_TO_SYMBOL_FIFO_ENABLE, 0); 164 165 /* Disable Clock Ramp Adjuster FIFO */ 166 REG_UPDATE(DP_STREAM_ENC_CLOCK_RAMP_ADJUSTER_FIFO_STATUS_CONTROL0, 167 FIFO_ENABLE, 0); 168 } 169 170 static void dcn31_hpo_dp_stream_enc_disable( 171 struct hpo_dp_stream_encoder *enc) 172 { 173 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 174 175 /* Disable DP_SYM32_ENC */ 176 REG_UPDATE(DP_SYM32_ENC_CONTROL, 177 DP_SYM32_ENC_ENABLE, 0); 178 179 /* Disable clocks in the DP_STREAM_ENC */ 180 REG_UPDATE(DP_STREAM_ENC_CLOCK_CONTROL, 181 DP_STREAM_ENC_CLOCK_EN, 0); 182 } 183 184 static void dcn31_hpo_dp_stream_enc_set_stream_attribute( 185 struct hpo_dp_stream_encoder *enc, 186 struct dc_crtc_timing *crtc_timing, 187 enum dc_color_space output_color_space, 188 bool use_vsc_sdp_for_colorimetry, 189 bool compressed_format, 190 bool double_buffer_en) 191 { 192 enum dp2_pixel_encoding pixel_encoding; 193 enum dp2_uncompressed_component_depth component_depth; 194 uint32_t h_active_start; 195 uint32_t v_active_start; 196 uint32_t h_blank; 197 uint32_t h_back_porch; 198 uint32_t h_width; 199 uint32_t v_height; 200 unsigned long long v_freq; 201 uint8_t misc0 = 0; 202 uint8_t misc1 = 0; 203 uint8_t hsp; 204 uint8_t vsp; 205 206 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 207 struct dc_crtc_timing hw_crtc_timing = *crtc_timing; 208 209 /* MISC0[0] = 0 video and link clocks are asynchronous 210 * MISC1[0] = 0 interlace not supported 211 * MISC1[2:1] = 0 stereo field is handled by hardware 212 * MISC1[5:3] = 0 Reserved 213 */ 214 215 /* Interlaced not supported */ 216 if (hw_crtc_timing.flags.INTERLACE) { 217 BREAK_TO_DEBUGGER(); 218 } 219 220 /* Double buffer enable for MSA and pixel format registers 221 * Only double buffer for changing stream attributes for active streams 222 * Do not double buffer when initially enabling a stream 223 */ 224 REG_UPDATE(DP_SYM32_ENC_VID_MSA_DOUBLE_BUFFER_CONTROL, 225 MSA_DOUBLE_BUFFER_ENABLE, double_buffer_en); 226 REG_UPDATE(DP_SYM32_ENC_VID_PIXEL_FORMAT_DOUBLE_BUFFER_CONTROL, 227 PIXEL_FORMAT_DOUBLE_BUFFER_ENABLE, double_buffer_en); 228 229 /* Pixel Encoding */ 230 switch (hw_crtc_timing.pixel_encoding) { 231 case PIXEL_ENCODING_YCBCR422: 232 pixel_encoding = DP_SYM32_ENC_PIXEL_ENCODING_YCBCR422; 233 misc0 = misc0 | 0x2; // MISC0[2:1] = 01 234 break; 235 case PIXEL_ENCODING_YCBCR444: 236 pixel_encoding = DP_SYM32_ENC_PIXEL_ENCODING_RGB_YCBCR444; 237 misc0 = misc0 | 0x4; // MISC0[2:1] = 10 238 239 if (hw_crtc_timing.flags.Y_ONLY) { 240 pixel_encoding = DP_SYM32_ENC_PIXEL_ENCODING_Y_ONLY; 241 if (hw_crtc_timing.display_color_depth != COLOR_DEPTH_666) { 242 /* HW testing only, no use case yet. 243 * Color depth of Y-only could be 244 * 8, 10, 12, 16 bits 245 */ 246 misc1 = misc1 | 0x80; // MISC1[7] = 1 247 } 248 } 249 break; 250 case PIXEL_ENCODING_YCBCR420: 251 pixel_encoding = DP_SYM32_ENC_PIXEL_ENCODING_YCBCR420; 252 misc1 = misc1 | 0x40; // MISC1[6] = 1 253 break; 254 case PIXEL_ENCODING_RGB: 255 default: 256 pixel_encoding = DP_SYM32_ENC_PIXEL_ENCODING_RGB_YCBCR444; 257 break; 258 } 259 260 /* For YCbCr420 and BT2020 Colorimetry Formats, VSC SDP shall be used. 261 * When MISC1, bit 6, is Set to 1, a Source device uses a VSC SDP to indicate the 262 * Pixel Encoding/Colorimetry Format and that a Sink device shall ignore MISC1, bit 7, 263 * and MISC0, bits 7:1 (MISC1, bit 7, and MISC0, bits 7:1, become "don't care"). 264 */ 265 if (use_vsc_sdp_for_colorimetry) 266 misc1 = misc1 | 0x40; 267 else 268 misc1 = misc1 & ~0x40; 269 270 /* Color depth */ 271 switch (hw_crtc_timing.display_color_depth) { 272 case COLOR_DEPTH_666: 273 component_depth = DP_SYM32_ENC_COMPONENT_DEPTH_6BPC; 274 // MISC0[7:5] = 000 275 break; 276 case COLOR_DEPTH_888: 277 component_depth = DP_SYM32_ENC_COMPONENT_DEPTH_8BPC; 278 misc0 = misc0 | 0x20; // MISC0[7:5] = 001 279 break; 280 case COLOR_DEPTH_101010: 281 component_depth = DP_SYM32_ENC_COMPONENT_DEPTH_10BPC; 282 misc0 = misc0 | 0x40; // MISC0[7:5] = 010 283 break; 284 case COLOR_DEPTH_121212: 285 component_depth = DP_SYM32_ENC_COMPONENT_DEPTH_12BPC; 286 misc0 = misc0 | 0x60; // MISC0[7:5] = 011 287 break; 288 default: 289 component_depth = DP_SYM32_ENC_COMPONENT_DEPTH_6BPC; 290 break; 291 } 292 293 REG_UPDATE_3(DP_SYM32_ENC_VID_PIXEL_FORMAT, 294 PIXEL_ENCODING_TYPE, compressed_format, 295 UNCOMPRESSED_PIXEL_ENCODING, pixel_encoding, 296 UNCOMPRESSED_COMPONENT_DEPTH, component_depth); 297 298 switch (output_color_space) { 299 case COLOR_SPACE_SRGB: 300 misc1 = misc1 & ~0x80; /* bit7 = 0*/ 301 break; 302 case COLOR_SPACE_SRGB_LIMITED: 303 misc0 = misc0 | 0x8; /* bit3=1 */ 304 misc1 = misc1 & ~0x80; /* bit7 = 0*/ 305 break; 306 case COLOR_SPACE_YCBCR601: 307 case COLOR_SPACE_YCBCR601_LIMITED: 308 misc0 = misc0 | 0x8; /* bit3=1, bit4=0 */ 309 misc1 = misc1 & ~0x80; /* bit7 = 0*/ 310 if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) 311 misc0 = misc0 | 0x2; /* bit2=0, bit1=1 */ 312 else if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR444) 313 misc0 = misc0 | 0x4; /* bit2=1, bit1=0 */ 314 break; 315 case COLOR_SPACE_YCBCR709: 316 case COLOR_SPACE_YCBCR709_LIMITED: 317 misc0 = misc0 | 0x18; /* bit3=1, bit4=1 */ 318 misc1 = misc1 & ~0x80; /* bit7 = 0*/ 319 if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422) 320 misc0 = misc0 | 0x2; /* bit2=0, bit1=1 */ 321 else if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR444) 322 misc0 = misc0 | 0x4; /* bit2=1, bit1=0 */ 323 break; 324 case COLOR_SPACE_2020_RGB_LIMITEDRANGE: 325 case COLOR_SPACE_2020_RGB_FULLRANGE: 326 case COLOR_SPACE_2020_YCBCR: 327 case COLOR_SPACE_XR_RGB: 328 case COLOR_SPACE_MSREF_SCRGB: 329 case COLOR_SPACE_ADOBERGB: 330 case COLOR_SPACE_DCIP3: 331 case COLOR_SPACE_XV_YCC_709: 332 case COLOR_SPACE_XV_YCC_601: 333 case COLOR_SPACE_DISPLAYNATIVE: 334 case COLOR_SPACE_DOLBYVISION: 335 case COLOR_SPACE_APPCTRL: 336 case COLOR_SPACE_CUSTOMPOINTS: 337 case COLOR_SPACE_UNKNOWN: 338 case COLOR_SPACE_YCBCR709_BLACK: 339 /* do nothing */ 340 break; 341 } 342 343 /* calculate from vesa timing parameters 344 * h_active_start related to leading edge of sync 345 */ 346 h_blank = hw_crtc_timing.h_total - hw_crtc_timing.h_border_left - 347 hw_crtc_timing.h_addressable - hw_crtc_timing.h_border_right; 348 349 h_back_porch = h_blank - hw_crtc_timing.h_front_porch - 350 hw_crtc_timing.h_sync_width; 351 352 /* start at beginning of left border */ 353 h_active_start = hw_crtc_timing.h_sync_width + h_back_porch; 354 355 v_active_start = hw_crtc_timing.v_total - hw_crtc_timing.v_border_top - 356 hw_crtc_timing.v_addressable - hw_crtc_timing.v_border_bottom - 357 hw_crtc_timing.v_front_porch; 358 359 h_width = hw_crtc_timing.h_border_left + hw_crtc_timing.h_addressable + hw_crtc_timing.h_border_right; 360 v_height = hw_crtc_timing.v_border_top + hw_crtc_timing.v_addressable + hw_crtc_timing.v_border_bottom; 361 hsp = hw_crtc_timing.flags.HSYNC_POSITIVE_POLARITY ? 0 : 0x80; 362 vsp = hw_crtc_timing.flags.VSYNC_POSITIVE_POLARITY ? 0 : 0x80; 363 v_freq = hw_crtc_timing.pix_clk_100hz * 100; 364 365 /* MSA Packet Mapping to 32-bit Link Symbols - DP2 spec, section 2.7.4.1 366 * 367 * Lane 0 Lane 1 Lane 2 Lane 3 368 * MSA[0] = { 0, 0, 0, VFREQ[47:40]} 369 * MSA[1] = { 0, 0, 0, VFREQ[39:32]} 370 * MSA[2] = { 0, 0, 0, VFREQ[31:24]} 371 * MSA[3] = { HTotal[15:8], HStart[15:8], HWidth[15:8], VFREQ[23:16]} 372 * MSA[4] = { HTotal[ 7:0], HStart[ 7:0], HWidth[ 7:0], VFREQ[15: 8]} 373 * MSA[5] = { VTotal[15:8], VStart[15:8], VHeight[15:8], VFREQ[ 7: 0]} 374 * MSA[6] = { VTotal[ 7:0], VStart[ 7:0], VHeight[ 7:0], MISC0[ 7: 0]} 375 * MSA[7] = { HSP|HSW[14:8], VSP|VSW[14:8], 0, MISC1[ 7: 0]} 376 * MSA[8] = { HSW[ 7:0], VSW[ 7:0], 0, 0} 377 */ 378 REG_SET_4(DP_SYM32_ENC_VID_MSA0, 0, 379 MSA_DATA_LANE_0, 0, 380 MSA_DATA_LANE_1, 0, 381 MSA_DATA_LANE_2, 0, 382 MSA_DATA_LANE_3, v_freq >> 40); 383 384 REG_SET_4(DP_SYM32_ENC_VID_MSA1, 0, 385 MSA_DATA_LANE_0, 0, 386 MSA_DATA_LANE_1, 0, 387 MSA_DATA_LANE_2, 0, 388 MSA_DATA_LANE_3, (v_freq >> 32) & 0xff); 389 390 REG_SET_4(DP_SYM32_ENC_VID_MSA2, 0, 391 MSA_DATA_LANE_0, 0, 392 MSA_DATA_LANE_1, 0, 393 MSA_DATA_LANE_2, 0, 394 MSA_DATA_LANE_3, (v_freq >> 24) & 0xff); 395 396 REG_SET_4(DP_SYM32_ENC_VID_MSA3, 0, 397 MSA_DATA_LANE_0, hw_crtc_timing.h_total >> 8, 398 MSA_DATA_LANE_1, h_active_start >> 8, 399 MSA_DATA_LANE_2, h_width >> 8, 400 MSA_DATA_LANE_3, (v_freq >> 16) & 0xff); 401 402 REG_SET_4(DP_SYM32_ENC_VID_MSA4, 0, 403 MSA_DATA_LANE_0, hw_crtc_timing.h_total & 0xff, 404 MSA_DATA_LANE_1, h_active_start & 0xff, 405 MSA_DATA_LANE_2, h_width & 0xff, 406 MSA_DATA_LANE_3, (v_freq >> 8) & 0xff); 407 408 REG_SET_4(DP_SYM32_ENC_VID_MSA5, 0, 409 MSA_DATA_LANE_0, hw_crtc_timing.v_total >> 8, 410 MSA_DATA_LANE_1, v_active_start >> 8, 411 MSA_DATA_LANE_2, v_height >> 8, 412 MSA_DATA_LANE_3, v_freq & 0xff); 413 414 REG_SET_4(DP_SYM32_ENC_VID_MSA6, 0, 415 MSA_DATA_LANE_0, hw_crtc_timing.v_total & 0xff, 416 MSA_DATA_LANE_1, v_active_start & 0xff, 417 MSA_DATA_LANE_2, v_height & 0xff, 418 MSA_DATA_LANE_3, misc0); 419 420 REG_SET_4(DP_SYM32_ENC_VID_MSA7, 0, 421 MSA_DATA_LANE_0, hsp | (hw_crtc_timing.h_sync_width >> 8), 422 MSA_DATA_LANE_1, vsp | (hw_crtc_timing.v_sync_width >> 8), 423 MSA_DATA_LANE_2, 0, 424 MSA_DATA_LANE_3, misc1); 425 426 REG_SET_4(DP_SYM32_ENC_VID_MSA8, 0, 427 MSA_DATA_LANE_0, hw_crtc_timing.h_sync_width & 0xff, 428 MSA_DATA_LANE_1, hw_crtc_timing.v_sync_width & 0xff, 429 MSA_DATA_LANE_2, 0, 430 MSA_DATA_LANE_3, 0); 431 } 432 433 static void dcn31_hpo_dp_stream_enc_update_dp_info_packets( 434 struct hpo_dp_stream_encoder *enc, 435 const struct encoder_info_frame *info_frame) 436 { 437 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 438 uint32_t dmdata_packet_enabled = 0; 439 bool sdp_stream_enable = false; 440 441 if (info_frame->vsc.valid) { 442 enc->vpg->funcs->update_generic_info_packet( 443 enc->vpg, 444 0, /* packetIndex */ 445 &info_frame->vsc, 446 true); 447 sdp_stream_enable = true; 448 } 449 if (info_frame->spd.valid) { 450 enc->vpg->funcs->update_generic_info_packet( 451 enc->vpg, 452 2, /* packetIndex */ 453 &info_frame->spd, 454 true); 455 sdp_stream_enable = true; 456 } 457 if (info_frame->hdrsmd.valid) { 458 enc->vpg->funcs->update_generic_info_packet( 459 enc->vpg, 460 3, /* packetIndex */ 461 &info_frame->hdrsmd, 462 true); 463 sdp_stream_enable = true; 464 } 465 /* enable/disable transmission of packet(s). 466 * If enabled, packet transmission begins on the next frame 467 */ 468 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL0, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, info_frame->vsc.valid); 469 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL2, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, info_frame->spd.valid); 470 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL3, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, info_frame->hdrsmd.valid); 471 472 /* check if dynamic metadata packet transmission is enabled */ 473 REG_GET(DP_SYM32_ENC_SDP_METADATA_PACKET_CONTROL, 474 METADATA_PACKET_ENABLE, &dmdata_packet_enabled); 475 476 /* Enable secondary data path */ 477 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 478 SDP_STREAM_ENABLE, 1); 479 } 480 481 static void dcn31_hpo_dp_stream_enc_stop_dp_info_packets( 482 struct hpo_dp_stream_encoder *enc) 483 { 484 /* stop generic packets on DP */ 485 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 486 uint32_t asp_enable = 0; 487 uint32_t atp_enable = 0; 488 uint32_t aip_enable = 0; 489 uint32_t acm_enable = 0; 490 491 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL0, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, 0); 492 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL2, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, 0); 493 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL3, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, 0); 494 495 /* Disable secondary data path if audio is also disabled */ 496 REG_GET_4(DP_SYM32_ENC_SDP_AUDIO_CONTROL0, 497 ASP_ENABLE, &asp_enable, 498 ATP_ENABLE, &atp_enable, 499 AIP_ENABLE, &aip_enable, 500 ACM_ENABLE, &acm_enable); 501 if (!(asp_enable || atp_enable || aip_enable || acm_enable)) 502 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 503 SDP_STREAM_ENABLE, 0); 504 } 505 506 static uint32_t hpo_dp_is_gsp_enabled( 507 struct hpo_dp_stream_encoder *enc) 508 { 509 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 510 uint32_t gsp0_enabled = 0; 511 uint32_t gsp2_enabled = 0; 512 uint32_t gsp3_enabled = 0; 513 uint32_t gsp11_enabled = 0; 514 515 REG_GET(DP_SYM32_ENC_SDP_GSP_CONTROL0, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, &gsp0_enabled); 516 REG_GET(DP_SYM32_ENC_SDP_GSP_CONTROL2, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, &gsp2_enabled); 517 REG_GET(DP_SYM32_ENC_SDP_GSP_CONTROL3, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, &gsp3_enabled); 518 REG_GET(DP_SYM32_ENC_SDP_GSP_CONTROL11, GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, &gsp11_enabled); 519 520 return (gsp0_enabled || gsp2_enabled || gsp3_enabled || gsp11_enabled); 521 } 522 523 static void dcn31_hpo_dp_stream_enc_set_dsc_pps_info_packet( 524 struct hpo_dp_stream_encoder *enc, 525 bool enable, 526 uint8_t *dsc_packed_pps, 527 bool immediate_update) 528 { 529 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 530 531 if (enable) { 532 struct dc_info_packet pps_sdp; 533 int i; 534 535 /* Configure for PPS packet size (128 bytes) */ 536 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL11, 537 GSP_PAYLOAD_SIZE, 3); 538 539 /* Load PPS into infoframe (SDP) registers */ 540 pps_sdp.valid = true; 541 pps_sdp.hb0 = 0; 542 pps_sdp.hb1 = DC_DP_INFOFRAME_TYPE_PPS; 543 pps_sdp.hb2 = 127; 544 pps_sdp.hb3 = 0; 545 546 for (i = 0; i < 4; i++) { 547 memcpy(pps_sdp.sb, &dsc_packed_pps[i * 32], 32); 548 enc3->base.vpg->funcs->update_generic_info_packet( 549 enc3->base.vpg, 550 11 + i, 551 &pps_sdp, 552 immediate_update); 553 } 554 555 /* SW should make sure VBID[6] update line number is bigger 556 * than PPS transmit line number 557 */ 558 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL11, 559 GSP_TRANSMISSION_LINE_NUMBER, 2); 560 561 REG_UPDATE_2(DP_SYM32_ENC_VID_VBID_CONTROL, 562 VBID_6_COMPRESSEDSTREAM_FLAG_SOF_REFERENCE, 0, 563 VBID_6_COMPRESSEDSTREAM_FLAG_LINE_NUMBER, 3); 564 565 /* Send PPS data at the line number specified above. */ 566 REG_UPDATE(DP_SYM32_ENC_SDP_GSP_CONTROL11, 567 GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, 1); 568 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 569 SDP_STREAM_ENABLE, 1); 570 } else { 571 /* Disable Generic Stream Packet 11 (GSP) transmission */ 572 REG_UPDATE_2(DP_SYM32_ENC_SDP_GSP_CONTROL11, 573 GSP_VIDEO_CONTINUOUS_TRANSMISSION_ENABLE, 0, 574 GSP_PAYLOAD_SIZE, 0); 575 } 576 } 577 578 static void dcn31_hpo_dp_stream_enc_map_stream_to_link( 579 struct hpo_dp_stream_encoder *enc, 580 uint32_t stream_enc_inst, 581 uint32_t link_enc_inst) 582 { 583 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 584 585 ASSERT(stream_enc_inst < 4 && link_enc_inst < 2); 586 587 switch (stream_enc_inst) { 588 case 0: 589 REG_UPDATE(DP_STREAM_MAPPER_CONTROL0, 590 DP_STREAM_LINK_TARGET, link_enc_inst); 591 break; 592 case 1: 593 REG_UPDATE(DP_STREAM_MAPPER_CONTROL1, 594 DP_STREAM_LINK_TARGET, link_enc_inst); 595 break; 596 case 2: 597 REG_UPDATE(DP_STREAM_MAPPER_CONTROL2, 598 DP_STREAM_LINK_TARGET, link_enc_inst); 599 break; 600 case 3: 601 REG_UPDATE(DP_STREAM_MAPPER_CONTROL3, 602 DP_STREAM_LINK_TARGET, link_enc_inst); 603 break; 604 } 605 } 606 607 static void dcn31_hpo_dp_stream_enc_mute_control( 608 struct hpo_dp_stream_encoder *enc, 609 bool mute) 610 { 611 ASSERT(enc->apg); 612 enc->apg->funcs->audio_mute_control(enc->apg, mute); 613 } 614 615 static void dcn31_hpo_dp_stream_enc_audio_setup( 616 struct hpo_dp_stream_encoder *enc, 617 unsigned int az_inst, 618 struct audio_info *info) 619 { 620 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 621 622 /* Set the input mux for video stream source */ 623 REG_UPDATE(DP_STREAM_ENC_AUDIO_CONTROL, 624 DP_STREAM_ENC_INPUT_MUX_AUDIO_STREAM_SOURCE_SEL, az_inst); 625 626 ASSERT(enc->apg); 627 enc->apg->funcs->se_audio_setup(enc->apg, az_inst, info); 628 } 629 630 static void dcn31_hpo_dp_stream_enc_audio_enable( 631 struct hpo_dp_stream_encoder *enc) 632 { 633 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 634 635 /* Enable Audio packets */ 636 REG_UPDATE(DP_SYM32_ENC_SDP_AUDIO_CONTROL0, ASP_ENABLE, 1); 637 638 /* Program the ATP and AIP next */ 639 REG_UPDATE_2(DP_SYM32_ENC_SDP_AUDIO_CONTROL0, 640 ATP_ENABLE, 1, 641 AIP_ENABLE, 1); 642 643 /* Enable secondary data path */ 644 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 645 SDP_STREAM_ENABLE, 1); 646 647 /* Enable APG block */ 648 enc->apg->funcs->enable_apg(enc->apg); 649 } 650 651 static void dcn31_hpo_dp_stream_enc_audio_disable( 652 struct hpo_dp_stream_encoder *enc) 653 { 654 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 655 656 /* Disable Audio packets */ 657 REG_UPDATE_4(DP_SYM32_ENC_SDP_AUDIO_CONTROL0, 658 ASP_ENABLE, 0, 659 ATP_ENABLE, 0, 660 AIP_ENABLE, 0, 661 ACM_ENABLE, 0); 662 663 /* Disable STP Stream Enable if other SDP GSP are also disabled */ 664 if (!(hpo_dp_is_gsp_enabled(enc))) 665 REG_UPDATE(DP_SYM32_ENC_SDP_CONTROL, 666 SDP_STREAM_ENABLE, 0); 667 668 /* Disable APG block */ 669 enc->apg->funcs->disable_apg(enc->apg); 670 } 671 672 static void dcn31_hpo_dp_stream_enc_read_state( 673 struct hpo_dp_stream_encoder *enc, 674 struct hpo_dp_stream_encoder_state *s) 675 { 676 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 677 678 REG_GET(DP_SYM32_ENC_CONTROL, 679 DP_SYM32_ENC_ENABLE, &s->stream_enc_enabled); 680 REG_GET(DP_SYM32_ENC_VID_STREAM_CONTROL, 681 VID_STREAM_ENABLE, &s->vid_stream_enabled); 682 REG_GET(DP_STREAM_ENC_INPUT_MUX_CONTROL, 683 DP_STREAM_ENC_INPUT_MUX_PIXEL_STREAM_SOURCE_SEL, &s->otg_inst); 684 685 REG_GET_3(DP_SYM32_ENC_VID_PIXEL_FORMAT, 686 PIXEL_ENCODING_TYPE, &s->compressed_format, 687 UNCOMPRESSED_PIXEL_ENCODING, &s->pixel_encoding, 688 UNCOMPRESSED_COMPONENT_DEPTH, &s->component_depth); 689 690 REG_GET(DP_SYM32_ENC_SDP_CONTROL, 691 SDP_STREAM_ENABLE, &s->sdp_enabled); 692 693 switch (enc->inst) { 694 case 0: 695 REG_GET(DP_STREAM_MAPPER_CONTROL0, 696 DP_STREAM_LINK_TARGET, &s->mapped_to_link_enc); 697 break; 698 case 1: 699 REG_GET(DP_STREAM_MAPPER_CONTROL1, 700 DP_STREAM_LINK_TARGET, &s->mapped_to_link_enc); 701 break; 702 case 2: 703 REG_GET(DP_STREAM_MAPPER_CONTROL2, 704 DP_STREAM_LINK_TARGET, &s->mapped_to_link_enc); 705 break; 706 case 3: 707 REG_GET(DP_STREAM_MAPPER_CONTROL3, 708 DP_STREAM_LINK_TARGET, &s->mapped_to_link_enc); 709 break; 710 } 711 } 712 713 static void dcn31_set_hblank_min_symbol_width( 714 struct hpo_dp_stream_encoder *enc, 715 uint16_t width) 716 { 717 struct dcn31_hpo_dp_stream_encoder *enc3 = DCN3_1_HPO_DP_STREAM_ENC_FROM_HPO_STREAM_ENC(enc); 718 719 REG_SET(DP_SYM32_ENC_HBLANK_CONTROL, 0, 720 HBLANK_MINIMUM_SYMBOL_WIDTH, width); 721 } 722 723 static const struct hpo_dp_stream_encoder_funcs dcn30_str_enc_funcs = { 724 .enable_stream = dcn31_hpo_dp_stream_enc_enable_stream, 725 .dp_unblank = dcn31_hpo_dp_stream_enc_dp_unblank, 726 .dp_blank = dcn31_hpo_dp_stream_enc_dp_blank, 727 .disable = dcn31_hpo_dp_stream_enc_disable, 728 .set_stream_attribute = dcn31_hpo_dp_stream_enc_set_stream_attribute, 729 .update_dp_info_packets = dcn31_hpo_dp_stream_enc_update_dp_info_packets, 730 .stop_dp_info_packets = dcn31_hpo_dp_stream_enc_stop_dp_info_packets, 731 .dp_set_dsc_pps_info_packet = dcn31_hpo_dp_stream_enc_set_dsc_pps_info_packet, 732 .map_stream_to_link = dcn31_hpo_dp_stream_enc_map_stream_to_link, 733 .audio_mute_control = dcn31_hpo_dp_stream_enc_mute_control, 734 .dp_audio_setup = dcn31_hpo_dp_stream_enc_audio_setup, 735 .dp_audio_enable = dcn31_hpo_dp_stream_enc_audio_enable, 736 .dp_audio_disable = dcn31_hpo_dp_stream_enc_audio_disable, 737 .read_state = dcn31_hpo_dp_stream_enc_read_state, 738 .set_hblank_min_symbol_width = dcn31_set_hblank_min_symbol_width, 739 }; 740 741 void dcn31_hpo_dp_stream_encoder_construct( 742 struct dcn31_hpo_dp_stream_encoder *enc3, 743 struct dc_context *ctx, 744 struct dc_bios *bp, 745 uint32_t inst, 746 enum engine_id eng_id, 747 struct vpg *vpg, 748 struct apg *apg, 749 const struct dcn31_hpo_dp_stream_encoder_registers *regs, 750 const struct dcn31_hpo_dp_stream_encoder_shift *hpo_se_shift, 751 const struct dcn31_hpo_dp_stream_encoder_mask *hpo_se_mask) 752 { 753 enc3->base.funcs = &dcn30_str_enc_funcs; 754 enc3->base.ctx = ctx; 755 enc3->base.inst = inst; 756 enc3->base.id = eng_id; 757 enc3->base.bp = bp; 758 enc3->base.vpg = vpg; 759 enc3->base.apg = apg; 760 enc3->regs = regs; 761 enc3->hpo_se_shift = hpo_se_shift; 762 enc3->hpo_se_mask = hpo_se_mask; 763 } 764