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_dio.h"
26 #include "core_types.h"
27 #include "link_enc_cfg.h"
28
29 /**
30 * DOC: overview
31 *
32 * Display Input Output (DIO), is the display input and output unit in DCN. It
33 * includes output encoders to support different display output, like
34 * DisplayPort, HDMI, DVI interface, and others. It also includes the control
35 * and status channels for these interfaces.
36 */
37
38
set_dio_throttled_vcp_size(struct pipe_ctx * pipe_ctx,struct fixed31_32 throttled_vcp_size)39 void set_dio_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
40 struct fixed31_32 throttled_vcp_size)
41 {
42 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
43
44 stream_encoder->funcs->set_throttled_vcp_size(
45 stream_encoder,
46 throttled_vcp_size);
47 }
48
setup_dio_stream_encoder(struct pipe_ctx * pipe_ctx)49 void setup_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
50 {
51 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
52 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
53
54 if (!pipe_ctx->stream->ctx->dc->config.unify_link_enc_assignment)
55 link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
56 if (!link_enc) {
57 ASSERT(link_enc);
58 return;
59 }
60
61 link_enc->funcs->connect_dig_be_to_fe(link_enc,
62 pipe_ctx->stream_res.stream_enc->id, true);
63 if (dc_is_dp_signal(pipe_ctx->stream->signal))
64 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(pipe_ctx->stream->link,
65 DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_BE);
66 if (stream_enc->funcs->enable_stream)
67 stream_enc->funcs->enable_stream(stream_enc,
68 pipe_ctx->stream->signal, true);
69 if (stream_enc->funcs->map_stream_to_link)
70 stream_enc->funcs->map_stream_to_link(stream_enc,
71 stream_enc->stream_enc_inst, link_enc->transmitter - TRANSMITTER_UNIPHY_A);
72 if (stream_enc->funcs->set_input_mode)
73 stream_enc->funcs->set_input_mode(stream_enc,
74 pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle);
75 if (stream_enc->funcs->enable_fifo)
76 stream_enc->funcs->enable_fifo(stream_enc);
77 }
78
reset_dio_stream_encoder(struct pipe_ctx * pipe_ctx)79 void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
80 {
81 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
82 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
83
84 if (!pipe_ctx->stream->ctx->dc->config.unify_link_enc_assignment)
85 link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
86 if (!link_enc) {
87 ASSERT(link_enc);
88 return;
89 }
90
91 if (!stream_enc)
92 return;
93
94 if (stream_enc->funcs->disable_fifo)
95 stream_enc->funcs->disable_fifo(stream_enc);
96 if (stream_enc->funcs->set_input_mode)
97 stream_enc->funcs->set_input_mode(stream_enc, 0);
98 if (stream_enc->funcs->enable_stream)
99 stream_enc->funcs->enable_stream(stream_enc,
100 pipe_ctx->stream->signal, false);
101 link_enc->funcs->connect_dig_be_to_fe(
102 link_enc,
103 pipe_ctx->stream_res.stream_enc->id,
104 false);
105 if (dc_is_dp_signal(pipe_ctx->stream->signal))
106 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
107 pipe_ctx->stream->link,
108 DPCD_SOURCE_SEQ_AFTER_DISCONNECT_DIG_FE_BE);
109
110 }
111
setup_dio_stream_attribute(struct pipe_ctx * pipe_ctx)112 void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx)
113 {
114 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
115 struct dc_stream_state *stream = pipe_ctx->stream;
116 struct dc_link *link = stream->link;
117
118 if (!dc_is_virtual_signal(stream->signal))
119 stream_encoder->funcs->setup_stereo_sync(
120 stream_encoder,
121 pipe_ctx->stream_res.tg->inst,
122 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
123
124 if (dc_is_dp_signal(stream->signal))
125 stream_encoder->funcs->dp_set_stream_attribute(
126 stream_encoder,
127 &stream->timing,
128 stream->output_color_space,
129 stream->use_vsc_sdp_for_colorimetry,
130 link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
131 else if (dc_is_hdmi_tmds_signal(stream->signal))
132 stream_encoder->funcs->hdmi_set_stream_attribute(
133 stream_encoder,
134 &stream->timing,
135 stream->phy_pix_clk,
136 pipe_ctx->stream_res.audio != NULL);
137 else if (dc_is_dvi_signal(stream->signal))
138 stream_encoder->funcs->dvi_set_stream_attribute(
139 stream_encoder,
140 &stream->timing,
141 (stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
142 true : false);
143 else if (dc_is_lvds_signal(stream->signal))
144 stream_encoder->funcs->lvds_set_stream_attribute(
145 stream_encoder,
146 &stream->timing);
147
148 if (dc_is_dp_signal(stream->signal))
149 link->dc->link_srv->dp_trace_source_sequence(link,
150 DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
151 }
152
enable_dio_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)153 void enable_dio_dp_link_output(struct dc_link *link,
154 const struct link_resource *link_res,
155 enum signal_type signal,
156 enum clock_source_id clock_source,
157 const struct dc_link_settings *link_settings)
158 {
159 struct link_encoder *link_enc = link_res->dio_link_enc;
160
161 if (!link->dc->config.unify_link_enc_assignment)
162 link_enc = link_enc_cfg_get_link_enc(link);
163 if (!link_enc) {
164 ASSERT(link_enc);
165 return;
166 }
167
168 if (dc_is_dp_sst_signal(signal))
169 link_enc->funcs->enable_dp_output(
170 link_enc,
171 link_settings,
172 clock_source);
173 else
174 link_enc->funcs->enable_dp_mst_output(
175 link_enc,
176 link_settings,
177 clock_source);
178 link->dc->link_srv->dp_trace_source_sequence(link,
179 DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
180 }
181
disable_dio_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)182 void disable_dio_link_output(struct dc_link *link,
183 const struct link_resource *link_res,
184 enum signal_type signal)
185 {
186 struct link_encoder *link_enc = link_res->dio_link_enc;
187
188 if (!link->dc->config.unify_link_enc_assignment)
189 link_enc = link_enc_cfg_get_link_enc(link);
190 if (!link_enc) {
191 ASSERT(link_enc);
192 return;
193 }
194
195 link_enc->funcs->disable_output(link_enc, signal);
196 link->dc->link_srv->dp_trace_source_sequence(link,
197 DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
198 }
199
set_dio_dp_link_test_pattern(struct dc_link * link,const struct link_resource * link_res,struct encoder_set_dp_phy_pattern_param * tp_params)200 void set_dio_dp_link_test_pattern(struct dc_link *link,
201 const struct link_resource *link_res,
202 struct encoder_set_dp_phy_pattern_param *tp_params)
203 {
204 struct link_encoder *link_enc = link_res->dio_link_enc;
205
206 if (!link->dc->config.unify_link_enc_assignment)
207 link_enc = link_enc_cfg_get_link_enc(link);
208 if (!link_enc) {
209 ASSERT(link_enc);
210 return;
211 }
212
213 link_enc->funcs->dp_set_phy_pattern(link_enc, tp_params);
214 link->dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
215 }
216
set_dio_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])217 void set_dio_dp_lane_settings(struct dc_link *link,
218 const struct link_resource *link_res,
219 const struct dc_link_settings *link_settings,
220 const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
221 {
222 struct link_encoder *link_enc = link_res->dio_link_enc;
223
224 if (!link->dc->config.unify_link_enc_assignment)
225 link_enc = link_enc_cfg_get_link_enc(link);
226 if (!link_enc) {
227 ASSERT(link_enc);
228 return;
229 }
230
231 link_enc->funcs->dp_set_lane_settings(link_enc, link_settings, lane_settings);
232 }
233
update_dio_stream_allocation_table(struct dc_link * link,const struct link_resource * link_res,const struct link_mst_stream_allocation_table * table)234 void update_dio_stream_allocation_table(struct dc_link *link,
235 const struct link_resource *link_res,
236 const struct link_mst_stream_allocation_table *table)
237 {
238 struct link_encoder *link_enc = link_res->dio_link_enc;
239
240 if (!link->dc->config.unify_link_enc_assignment)
241 link_enc = link_enc_cfg_get_link_enc(link);
242 if (!link_enc) {
243 ASSERT(link_enc);
244 return;
245 }
246
247 link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
248 }
249
setup_dio_audio_output(struct pipe_ctx * pipe_ctx,struct audio_output * audio_output,uint32_t audio_inst)250 void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
251 struct audio_output *audio_output, uint32_t audio_inst)
252 {
253 if (dc_is_dp_signal(pipe_ctx->stream->signal))
254 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
255 pipe_ctx->stream_res.stream_enc,
256 audio_inst,
257 &pipe_ctx->stream->audio_info);
258 else
259 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
260 pipe_ctx->stream_res.stream_enc,
261 audio_inst,
262 &pipe_ctx->stream->audio_info,
263 &audio_output->crtc_info);
264 }
265
enable_dio_audio_packet(struct pipe_ctx * pipe_ctx)266 void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
267 {
268 if (dc_is_dp_signal(pipe_ctx->stream->signal))
269 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(
270 pipe_ctx->stream_res.stream_enc);
271
272 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
273 pipe_ctx->stream_res.stream_enc, false);
274
275 if (dc_is_dp_signal(pipe_ctx->stream->signal))
276 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
277 pipe_ctx->stream->link,
278 DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
279 }
280
disable_dio_audio_packet(struct pipe_ctx * pipe_ctx)281 void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
282 {
283 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
284 pipe_ctx->stream_res.stream_enc, true);
285
286 if (pipe_ctx->stream_res.audio) {
287 if (dc_is_dp_signal(pipe_ctx->stream->signal))
288 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
289 pipe_ctx->stream_res.stream_enc);
290 else
291 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
292 pipe_ctx->stream_res.stream_enc);
293 }
294
295 if (dc_is_dp_signal(pipe_ctx->stream->signal))
296 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
297 pipe_ctx->stream->link,
298 DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
299 }
300
301 static const struct link_hwss dio_link_hwss = {
302 .setup_stream_encoder = setup_dio_stream_encoder,
303 .reset_stream_encoder = reset_dio_stream_encoder,
304 .setup_stream_attribute = setup_dio_stream_attribute,
305 .disable_link_output = disable_dio_link_output,
306 .setup_audio_output = setup_dio_audio_output,
307 .enable_audio_packet = enable_dio_audio_packet,
308 .disable_audio_packet = disable_dio_audio_packet,
309 .ext = {
310 .set_throttled_vcp_size = set_dio_throttled_vcp_size,
311 .enable_dp_link_output = enable_dio_dp_link_output,
312 .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
313 .set_dp_lane_settings = set_dio_dp_lane_settings,
314 .update_stream_allocation_table = update_dio_stream_allocation_table,
315 },
316 };
317
318 /**
319 * can_use_dio_link_hwss - Check if the link_hwss is accessible
320 *
321 * @link: Reference a link struct containing one or more sinks and the
322 * connective status.
323 * @link_res: Mappable hardware resource used to enable a link.
324 *
325 * Returns:
326 * Return true if the link encoder is accessible from link.
327 */
can_use_dio_link_hwss(const struct dc_link * link,const struct link_resource * link_res)328 bool can_use_dio_link_hwss(const struct dc_link *link,
329 const struct link_resource *link_res)
330 {
331 if (!link->dc->config.unify_link_enc_assignment)
332 return link->link_enc != NULL;
333 else
334 return link_res->dio_link_enc != NULL;
335 }
336
337 /**
338 * get_dio_link_hwss - Return link_hwss reference
339 *
340 * This function behaves like a get function to return the link_hwss populated
341 * in the link_hwss_dio.c file.
342 *
343 * Returns:
344 * Return the reference to the filled struct of link_hwss.
345 */
get_dio_link_hwss(void)346 const struct link_hwss *get_dio_link_hwss(void)
347 {
348 return &dio_link_hwss;
349 }
350