1 /* 2 * Copyright 2022 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 #include "link_hwss_hpo_dp.h" 26 #include "dm_helpers.h" 27 #include "core_types.h" 28 #include "dccg.h" 29 #include "clk_mgr.h" 30 31 static void set_hpo_dp_throttled_vcp_size(struct pipe_ctx *pipe_ctx, 32 struct fixed31_32 throttled_vcp_size) 33 { 34 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = 35 pipe_ctx->stream_res.hpo_dp_stream_enc; 36 struct hpo_dp_link_encoder *hpo_dp_link_encoder = 37 pipe_ctx->link_res.hpo_dp_link_enc; 38 39 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(hpo_dp_link_encoder, 40 hpo_dp_stream_encoder->inst, 41 throttled_vcp_size); 42 } 43 44 static void set_hpo_dp_hblank_min_symbol_width(struct pipe_ctx *pipe_ctx, 45 const struct dc_link_settings *link_settings, 46 struct fixed31_32 throttled_vcp_size) 47 { 48 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = 49 pipe_ctx->stream_res.hpo_dp_stream_enc; 50 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing; 51 struct fixed31_32 h_blank_in_ms, time_slot_in_ms, mtp_cnt_per_h_blank; 52 uint32_t link_bw_in_kbps = 53 hpo_dp_stream_encoder->ctx->dc->link_srv->dp_link_bandwidth_kbps( 54 pipe_ctx->stream->link, link_settings); 55 uint16_t hblank_min_symbol_width = 0; 56 57 if (link_bw_in_kbps > 0) { 58 h_blank_in_ms = dc_fixpt_div(dc_fixpt_from_int( 59 timing->h_total - timing->h_addressable), 60 dc_fixpt_from_fraction(timing->pix_clk_100hz, 10)); 61 time_slot_in_ms = dc_fixpt_from_fraction(32 * 4, link_bw_in_kbps); 62 mtp_cnt_per_h_blank = dc_fixpt_div(h_blank_in_ms, 63 dc_fixpt_mul_int(time_slot_in_ms, 64)); 64 hblank_min_symbol_width = dc_fixpt_floor( 65 dc_fixpt_mul(mtp_cnt_per_h_blank, throttled_vcp_size)); 66 } 67 68 hpo_dp_stream_encoder->funcs->set_hblank_min_symbol_width(hpo_dp_stream_encoder, 69 hblank_min_symbol_width); 70 } 71 72 static void setup_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx) 73 { 74 struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc; 75 struct hpo_dp_link_encoder *link_enc = pipe_ctx->link_res.hpo_dp_link_enc; 76 77 stream_enc->funcs->enable_stream(stream_enc); 78 stream_enc->funcs->map_stream_to_link(stream_enc, stream_enc->inst, link_enc->inst); 79 } 80 81 static void reset_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx) 82 { 83 struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc; 84 85 stream_enc->funcs->disable(stream_enc); 86 } 87 88 static void setup_hpo_dp_stream_attribute(struct pipe_ctx *pipe_ctx) 89 { 90 struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc; 91 struct dc_stream_state *stream = pipe_ctx->stream; 92 struct dc_link *link = stream->link; 93 94 stream_enc->funcs->set_stream_attribute( 95 stream_enc, 96 &stream->timing, 97 stream->output_color_space, 98 stream->use_vsc_sdp_for_colorimetry, 99 stream->timing.flags.DSC, 100 false); 101 link->dc->link_srv->dp_trace_source_sequence(link, 102 DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR); 103 } 104 105 static void enable_hpo_dp_link_output(struct dc_link *link, 106 const struct link_resource *link_res, 107 enum signal_type signal, 108 enum clock_source_id clock_source, 109 const struct dc_link_settings *link_settings) 110 { 111 link_res->hpo_dp_link_enc->funcs->enable_link_phy( 112 link_res->hpo_dp_link_enc, 113 link_settings, 114 link->link_enc->transmitter, 115 link->link_enc->hpd_source); 116 } 117 118 static void disable_hpo_dp_link_output(struct dc_link *link, 119 const struct link_resource *link_res, 120 enum signal_type signal) 121 { 122 link_res->hpo_dp_link_enc->funcs->link_disable(link_res->hpo_dp_link_enc); 123 link_res->hpo_dp_link_enc->funcs->disable_link_phy( 124 link_res->hpo_dp_link_enc, signal); 125 } 126 127 static void set_hpo_dp_link_test_pattern(struct dc_link *link, 128 const struct link_resource *link_res, 129 struct encoder_set_dp_phy_pattern_param *tp_params) 130 { 131 link_res->hpo_dp_link_enc->funcs->set_link_test_pattern( 132 link_res->hpo_dp_link_enc, tp_params); 133 link->dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN); 134 } 135 136 static void set_hpo_dp_lane_settings(struct dc_link *link, 137 const struct link_resource *link_res, 138 const struct dc_link_settings *link_settings, 139 const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX]) 140 { 141 link_res->hpo_dp_link_enc->funcs->set_ffe( 142 link_res->hpo_dp_link_enc, 143 link_settings, 144 lane_settings[0].FFE_PRESET.raw); 145 } 146 147 static void update_hpo_dp_stream_allocation_table(struct dc_link *link, 148 const struct link_resource *link_res, 149 const struct link_mst_stream_allocation_table *table) 150 { 151 link_res->hpo_dp_link_enc->funcs->update_stream_allocation_table( 152 link_res->hpo_dp_link_enc, 153 table); 154 } 155 156 static void setup_hpo_dp_audio_output(struct pipe_ctx *pipe_ctx, 157 struct audio_output *audio_output, uint32_t audio_inst) 158 { 159 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_setup( 160 pipe_ctx->stream_res.hpo_dp_stream_enc, 161 audio_inst, 162 &pipe_ctx->stream->audio_info); 163 } 164 165 static void enable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx) 166 { 167 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_enable( 168 pipe_ctx->stream_res.hpo_dp_stream_enc); 169 } 170 171 static void disable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx) 172 { 173 if (pipe_ctx->stream_res.audio) 174 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_disable( 175 pipe_ctx->stream_res.hpo_dp_stream_enc); 176 } 177 178 static const struct link_hwss hpo_dp_link_hwss = { 179 .setup_stream_encoder = setup_hpo_dp_stream_encoder, 180 .reset_stream_encoder = reset_hpo_dp_stream_encoder, 181 .setup_stream_attribute = setup_hpo_dp_stream_attribute, 182 .disable_link_output = disable_hpo_dp_link_output, 183 .setup_audio_output = setup_hpo_dp_audio_output, 184 .enable_audio_packet = enable_hpo_dp_audio_packet, 185 .disable_audio_packet = disable_hpo_dp_audio_packet, 186 .ext = { 187 .set_throttled_vcp_size = set_hpo_dp_throttled_vcp_size, 188 .set_hblank_min_symbol_width = set_hpo_dp_hblank_min_symbol_width, 189 .enable_dp_link_output = enable_hpo_dp_link_output, 190 .set_dp_link_test_pattern = set_hpo_dp_link_test_pattern, 191 .set_dp_lane_settings = set_hpo_dp_lane_settings, 192 .update_stream_allocation_table = update_hpo_dp_stream_allocation_table, 193 }, 194 }; 195 196 bool can_use_hpo_dp_link_hwss(const struct dc_link *link, 197 const struct link_resource *link_res) 198 { 199 return link_res->hpo_dp_link_enc != NULL; 200 } 201 202 const struct link_hwss *get_hpo_dp_link_hwss(void) 203 { 204 return &hpo_dp_link_hwss; 205 } 206 207