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