1 /* 2 * Copyright 2023 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 /* FILE POLICY AND INTENDED USAGE: 27 * This file provides single entrance to link functionality declared in dc 28 * public headers. The file is intended to be used as a thin translation layer 29 * that directly calls link internal functions without adding new functional 30 * behavior. 31 * 32 * When exporting a new link related dc function, add function declaration in 33 * dc.h with detail interface documentation, then add function implementation 34 * in this file which calls link functions. 35 */ 36 #include "link.h" 37 #include "dce/dce_i2c.h" 38 struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index) 39 { 40 if (link_index >= MAX_LINKS) 41 return NULL; 42 43 return dc->links[link_index]; 44 } 45 46 void dc_get_edp_links(const struct dc *dc, 47 struct dc_link **edp_links, 48 int *edp_num) 49 { 50 int i; 51 52 *edp_num = 0; 53 for (i = 0; i < dc->link_count; i++) { 54 // report any eDP links, even unconnected DDI's 55 if (!dc->links[i]) 56 continue; 57 if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP) { 58 edp_links[*edp_num] = dc->links[i]; 59 if (++(*edp_num) == MAX_NUM_EDP) 60 return; 61 } 62 } 63 } 64 65 bool dc_get_edp_link_panel_inst(const struct dc *dc, 66 const struct dc_link *link, 67 unsigned int *inst_out) 68 { 69 struct dc_link *edp_links[MAX_NUM_EDP]; 70 int edp_num, i; 71 72 *inst_out = 0; 73 if (link->connector_signal != SIGNAL_TYPE_EDP) 74 return false; 75 dc_get_edp_links(dc, edp_links, &edp_num); 76 for (i = 0; i < edp_num; i++) { 77 if (link == edp_links[i]) 78 break; 79 (*inst_out)++; 80 } 81 return true; 82 } 83 84 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason) 85 { 86 return link->dc->link_srv->detect_link(link, reason); 87 } 88 89 bool dc_link_detect_connection_type(struct dc_link *link, 90 enum dc_connection_type *type) 91 { 92 return link->dc->link_srv->detect_connection_type(link, type); 93 } 94 95 const struct dc_link_status *dc_link_get_status(const struct dc_link *link) 96 { 97 return link->dc->link_srv->get_status(link); 98 } 99 100 /* return true if the connected receiver supports the hdcp version */ 101 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal) 102 { 103 return link->dc->link_srv->is_hdcp1x_supported(link, signal); 104 } 105 106 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal) 107 { 108 return link->dc->link_srv->is_hdcp2x_supported(link, signal); 109 } 110 111 void dc_link_clear_dprx_states(struct dc_link *link) 112 { 113 link->dc->link_srv->clear_dprx_states(link); 114 } 115 116 bool dc_link_reset_cur_dp_mst_topology(struct dc_link *link) 117 { 118 return link->dc->link_srv->reset_cur_dp_mst_topology(link); 119 } 120 121 uint32_t dc_link_bandwidth_kbps( 122 const struct dc_link *link, 123 const struct dc_link_settings *link_settings) 124 { 125 return link->dc->link_srv->dp_link_bandwidth_kbps(link, link_settings); 126 } 127 128 uint32_t dc_link_required_hblank_size_bytes( 129 const struct dc_link *link, 130 struct dp_audio_bandwidth_params *audio_params) 131 { 132 return link->dc->link_srv->dp_required_hblank_size_bytes(link, 133 audio_params); 134 } 135 136 void dc_get_cur_link_res_map(const struct dc *dc, uint32_t *map) 137 { 138 dc->link_srv->get_cur_res_map(dc, map); 139 } 140 141 void dc_restore_link_res_map(const struct dc *dc, uint32_t *map) 142 { 143 dc->link_srv->restore_res_map(dc, map); 144 } 145 146 bool dc_link_update_dsc_config(struct pipe_ctx *pipe_ctx) 147 { 148 struct dc_link *link = pipe_ctx->stream->link; 149 150 return link->dc->link_srv->update_dsc_config(pipe_ctx); 151 } 152 153 struct ddc_service * 154 dc_get_oem_i2c_device(struct dc *dc) 155 { 156 return dc->res_pool->oem_device; 157 } 158 159 bool dc_is_oem_i2c_device_present( 160 struct dc *dc, 161 size_t slave_address) 162 { 163 if (dc->res_pool->oem_device) 164 return dce_i2c_oem_device_present( 165 dc->res_pool, 166 dc->res_pool->oem_device, 167 slave_address); 168 169 return false; 170 } 171 172 bool dc_submit_i2c( 173 struct dc *dc, 174 uint32_t link_index, 175 struct i2c_command *cmd) 176 { 177 178 struct dc_link *link = dc->links[link_index]; 179 struct ddc_service *ddc = link->ddc; 180 181 return dce_i2c_submit_command( 182 dc->res_pool, 183 ddc->ddc_pin, 184 cmd); 185 } 186 187 bool dc_submit_i2c_oem( 188 struct dc *dc, 189 struct i2c_command *cmd) 190 { 191 struct ddc_service *ddc = dc->res_pool->oem_device; 192 193 if (ddc) 194 return dce_i2c_submit_command( 195 dc->res_pool, 196 ddc->ddc_pin, 197 cmd); 198 199 return false; 200 } 201 202 void dc_link_dp_handle_automated_test(struct dc_link *link) 203 { 204 link->dc->link_srv->dp_handle_automated_test(link); 205 } 206 207 bool dc_link_dp_set_test_pattern( 208 struct dc_link *link, 209 enum dp_test_pattern test_pattern, 210 enum dp_test_pattern_color_space test_pattern_color_space, 211 const struct link_training_settings *p_link_settings, 212 const unsigned char *p_custom_pattern, 213 unsigned int cust_pattern_size) 214 { 215 return link->dc->link_srv->dp_set_test_pattern(link, test_pattern, 216 test_pattern_color_space, p_link_settings, 217 p_custom_pattern, cust_pattern_size); 218 } 219 220 void dc_link_set_drive_settings(struct dc *dc, 221 struct link_training_settings *lt_settings, 222 struct dc_link *link) 223 { 224 struct link_resource link_res; 225 226 dc->link_srv->get_cur_link_res(link, &link_res); 227 dc->link_srv->dp_set_drive_settings(link, &link_res, lt_settings); 228 } 229 230 void dc_link_set_preferred_link_settings(struct dc *dc, 231 struct dc_link_settings *link_setting, 232 struct dc_link *link) 233 { 234 dc->link_srv->dp_set_preferred_link_settings(dc, link_setting, link); 235 } 236 237 void dc_link_set_preferred_training_settings(struct dc *dc, 238 struct dc_link_settings *link_setting, 239 struct dc_link_training_overrides *lt_overrides, 240 struct dc_link *link, 241 bool skip_immediate_retrain) 242 { 243 dc->link_srv->dp_set_preferred_training_settings(dc, link_setting, 244 lt_overrides, link, skip_immediate_retrain); 245 } 246 247 bool dc_dp_trace_is_initialized(struct dc_link *link) 248 { 249 return link->dc->link_srv->dp_trace_is_initialized(link); 250 } 251 252 void dc_dp_trace_set_is_logged_flag(struct dc_link *link, 253 bool in_detection, 254 bool is_logged) 255 { 256 link->dc->link_srv->dp_trace_set_is_logged_flag(link, in_detection, is_logged); 257 } 258 259 bool dc_dp_trace_is_logged(struct dc_link *link, bool in_detection) 260 { 261 return link->dc->link_srv->dp_trace_is_logged(link, in_detection); 262 } 263 264 unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link, 265 bool in_detection) 266 { 267 return link->dc->link_srv->dp_trace_get_lt_end_timestamp(link, in_detection); 268 } 269 270 const struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link, 271 bool in_detection) 272 { 273 return link->dc->link_srv->dp_trace_get_lt_counts(link, in_detection); 274 } 275 276 unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link) 277 { 278 return link->dc->link_srv->dp_trace_get_link_loss_count(link); 279 } 280 281 struct dc_sink *dc_link_add_remote_sink( 282 struct dc_link *link, 283 const uint8_t *edid, 284 int len, 285 struct dc_sink_init_data *init_data) 286 { 287 return link->dc->link_srv->add_remote_sink(link, edid, len, init_data); 288 } 289 290 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink) 291 { 292 link->dc->link_srv->remove_remote_sink(link, sink); 293 } 294 295 int dc_link_aux_transfer_raw(struct ddc_service *ddc, 296 struct aux_payload *payload, 297 enum aux_return_code_type *operation_result) 298 { 299 const struct dc *dc = ddc->link->dc; 300 301 return dc->link_srv->aux_transfer_raw( 302 ddc, payload, operation_result); 303 } 304 305 uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(const struct dc *dc, uint8_t bw) 306 { 307 return dc->link_srv->bw_kbps_from_raw_frl_link_rate_data(bw); 308 } 309 310 bool dc_link_decide_edp_link_settings(struct dc_link *link, 311 struct dc_link_settings *link_setting, uint32_t req_bw) 312 { 313 return link->dc->link_srv->edp_decide_link_settings(link, link_setting, req_bw); 314 } 315 316 317 bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, 318 struct dc_link_settings *max_link_enc_cap) 319 { 320 return link->dc->link_srv->dp_get_max_link_enc_cap(link, max_link_enc_cap); 321 } 322 323 enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format( 324 const struct dc_link *link) 325 { 326 return link->dc->link_srv->mst_decide_link_encoding_format(link); 327 } 328 329 const struct dc_link_settings *dc_link_get_link_cap(const struct dc_link *link) 330 { 331 return link->dc->link_srv->dp_get_verified_link_cap(link); 332 } 333 334 enum dc_link_encoding_format dc_link_get_highest_encoding_format(const struct dc_link *link) 335 { 336 if (dc_is_dp_signal(link->connector_signal)) { 337 if (link->dpcd_caps.dongle_type >= DISPLAY_DONGLE_DP_DVI_DONGLE && 338 link->dpcd_caps.dongle_type <= DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE) 339 return DC_LINK_ENCODING_HDMI_TMDS; 340 else if (link->dc->link_srv->dp_get_encoding_format(&link->verified_link_cap) == 341 DP_8b_10b_ENCODING) 342 return DC_LINK_ENCODING_DP_8b_10b; 343 else if (link->dc->link_srv->dp_get_encoding_format(&link->verified_link_cap) == 344 DP_128b_132b_ENCODING) 345 return DC_LINK_ENCODING_DP_128b_132b; 346 } else if (dc_is_hdmi_signal(link->connector_signal)) { 347 } 348 349 return DC_LINK_ENCODING_UNSPECIFIED; 350 } 351 352 bool dc_link_is_dp_sink_present(struct dc_link *link) 353 { 354 return link->dc->link_srv->dp_is_sink_present(link); 355 } 356 357 bool dc_link_is_fec_supported(const struct dc_link *link) 358 { 359 return link->dc->link_srv->dp_is_fec_supported(link); 360 } 361 362 void dc_link_overwrite_extended_receiver_cap( 363 struct dc_link *link) 364 { 365 link->dc->link_srv->dp_overwrite_extended_receiver_cap(link); 366 } 367 368 bool dc_link_should_enable_fec(const struct dc_link *link) 369 { 370 return link->dc->link_srv->dp_should_enable_fec(link); 371 } 372 373 void dc_link_dp_dpia_handle_usb4_bandwidth_allocation_for_link( 374 struct dc_link *link, int peak_bw) 375 { 376 link->dc->link_srv->dpia_handle_usb4_bandwidth_allocation_for_link(link, peak_bw); 377 } 378 379 bool dc_link_check_link_loss_status( 380 struct dc_link *link, 381 union hpd_irq_data *hpd_irq_dpcd_data) 382 { 383 return link->dc->link_srv->dp_parse_link_loss_status(link, hpd_irq_dpcd_data); 384 } 385 386 bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link) 387 { 388 return link->dc->link_srv->dp_should_allow_hpd_rx_irq(link); 389 } 390 391 void dc_link_dp_handle_link_loss(struct dc_link *link) 392 { 393 link->dc->link_srv->dp_handle_link_loss(link); 394 } 395 396 enum dc_status dc_link_dp_read_hpd_rx_irq_data( 397 struct dc_link *link, 398 union hpd_irq_data *irq_data) 399 { 400 return link->dc->link_srv->dp_read_hpd_rx_irq_data(link, irq_data); 401 } 402 403 bool dc_link_handle_hpd_rx_irq(struct dc_link *link, 404 union hpd_irq_data *out_hpd_irq_dpcd_data, bool *out_link_loss, 405 bool defer_handling, bool *has_left_work) 406 { 407 return link->dc->link_srv->dp_handle_hpd_rx_irq(link, out_hpd_irq_dpcd_data, 408 out_link_loss, defer_handling, has_left_work); 409 } 410 411 void dc_link_dp_receiver_power_ctrl(struct dc_link *link, bool on) 412 { 413 link->dc->link_srv->dpcd_write_rx_power_ctrl(link, on); 414 } 415 416 enum lttpr_mode dc_link_decide_lttpr_mode(struct dc_link *link, 417 struct dc_link_settings *link_setting) 418 { 419 return link->dc->link_srv->dp_decide_lttpr_mode(link, link_setting); 420 } 421 422 void dc_link_edp_panel_backlight_power_on(struct dc_link *link, bool wait_for_hpd) 423 { 424 link->dc->link_srv->edp_panel_backlight_power_on(link, wait_for_hpd); 425 } 426 427 int dc_link_get_backlight_level(const struct dc_link *link) 428 { 429 return link->dc->link_srv->edp_get_backlight_level(link); 430 } 431 432 bool dc_link_get_backlight_level_nits(struct dc_link *link, 433 uint32_t *backlight_millinits_avg, 434 uint32_t *backlight_millinits_peak) 435 { 436 return link->dc->link_srv->edp_get_backlight_level_nits(link, 437 backlight_millinits_avg, 438 backlight_millinits_peak); 439 } 440 441 bool dc_link_set_backlight_level(const struct dc_link *link, 442 struct set_backlight_level_params *backlight_level_params) 443 { 444 return link->dc->link_srv->edp_set_backlight_level(link, 445 backlight_level_params); 446 } 447 448 bool dc_link_set_backlight_level_nits(struct dc_link *link, 449 bool isHDR, 450 uint32_t backlight_millinits, 451 uint32_t transition_time_in_ms) 452 { 453 return link->dc->link_srv->edp_set_backlight_level_nits(link, isHDR, 454 backlight_millinits, transition_time_in_ms); 455 } 456 457 int dc_link_get_target_backlight_pwm(const struct dc_link *link) 458 { 459 return link->dc->link_srv->edp_get_target_backlight_pwm(link); 460 } 461 462 bool dc_link_get_psr_state(const struct dc_link *link, enum dc_psr_state *state) 463 { 464 return link->dc->link_srv->edp_get_psr_state(link, state); 465 } 466 467 bool dc_link_set_psr_allow_active(struct dc_link *link, const bool *allow_active, 468 bool wait, bool force_static, const unsigned int *power_opts) 469 { 470 return link->dc->link_srv->edp_set_psr_allow_active(link, allow_active, wait, 471 force_static, power_opts); 472 } 473 474 bool dc_link_setup_psr(struct dc_link *link, 475 const struct dc_stream_state *stream, struct psr_config *psr_config, 476 struct psr_context *psr_context) 477 { 478 return link->dc->link_srv->edp_setup_psr(link, stream, psr_config, psr_context); 479 } 480 481 bool dc_link_set_replay_allow_active(struct dc_link *link, const bool *allow_active, 482 bool wait, bool force_static, const unsigned int *power_opts) 483 { 484 return link->dc->link_srv->edp_set_replay_allow_active(link, allow_active, wait, 485 force_static, power_opts); 486 } 487 488 bool dc_link_get_replay_state(const struct dc_link *link, uint64_t *state) 489 { 490 return link->dc->link_srv->edp_get_replay_state(link, state); 491 } 492 493 bool dc_link_wait_for_t12(struct dc_link *link) 494 { 495 return link->dc->link_srv->edp_wait_for_t12(link); 496 } 497 498 bool dc_link_get_hpd_state(struct dc_link *link) 499 { 500 return link->dc->link_srv->get_hpd_state(link); 501 } 502 503 void dc_link_enable_hpd(const struct dc_link *link) 504 { 505 link->dc->link_srv->enable_hpd(link); 506 } 507 508 void dc_link_disable_hpd(const struct dc_link *link) 509 { 510 link->dc->link_srv->disable_hpd(link); 511 } 512 513 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable) 514 { 515 link->dc->link_srv->enable_hpd_filter(link, enable); 516 } 517 518 bool dc_link_dp_dpia_validate(struct dc *dc, const struct dc_stream_state *streams, const unsigned int count) 519 { 520 return dc->link_srv->validate_dpia_bandwidth(streams, count); 521 } 522