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 = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
52 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
53
54 link_enc->funcs->connect_dig_be_to_fe(link_enc,
55 pipe_ctx->stream_res.stream_enc->id, true);
56 if (dc_is_dp_signal(pipe_ctx->stream->signal))
57 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(pipe_ctx->stream->link,
58 DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_BE);
59 if (stream_enc->funcs->enable_stream)
60 stream_enc->funcs->enable_stream(stream_enc,
61 pipe_ctx->stream->signal, true);
62 if (stream_enc->funcs->map_stream_to_link)
63 stream_enc->funcs->map_stream_to_link(stream_enc,
64 stream_enc->stream_enc_inst, link_enc->transmitter - TRANSMITTER_UNIPHY_A);
65 if (stream_enc->funcs->set_input_mode)
66 stream_enc->funcs->set_input_mode(stream_enc,
67 pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle);
68 if (stream_enc->funcs->enable_fifo)
69 stream_enc->funcs->enable_fifo(stream_enc);
70 }
71
reset_dio_stream_encoder(struct pipe_ctx * pipe_ctx)72 void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
73 {
74 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
75 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
76
77 if (!stream_enc)
78 return;
79
80 if (stream_enc->funcs->disable_fifo)
81 stream_enc->funcs->disable_fifo(stream_enc);
82 if (stream_enc->funcs->set_input_mode)
83 stream_enc->funcs->set_input_mode(stream_enc, 0);
84 if (stream_enc->funcs->enable_stream)
85 stream_enc->funcs->enable_stream(stream_enc,
86 pipe_ctx->stream->signal, false);
87 link_enc->funcs->connect_dig_be_to_fe(
88 link_enc,
89 pipe_ctx->stream_res.stream_enc->id,
90 false);
91 if (dc_is_dp_signal(pipe_ctx->stream->signal))
92 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
93 pipe_ctx->stream->link,
94 DPCD_SOURCE_SEQ_AFTER_DISCONNECT_DIG_FE_BE);
95
96 }
97
setup_dio_stream_attribute(struct pipe_ctx * pipe_ctx)98 void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx)
99 {
100 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
101 struct dc_stream_state *stream = pipe_ctx->stream;
102 struct dc_link *link = stream->link;
103
104 if (!dc_is_virtual_signal(stream->signal))
105 stream_encoder->funcs->setup_stereo_sync(
106 stream_encoder,
107 pipe_ctx->stream_res.tg->inst,
108 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
109
110 if (dc_is_dp_signal(stream->signal))
111 stream_encoder->funcs->dp_set_stream_attribute(
112 stream_encoder,
113 &stream->timing,
114 stream->output_color_space,
115 stream->use_vsc_sdp_for_colorimetry,
116 link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
117 else if (dc_is_hdmi_tmds_signal(stream->signal))
118 stream_encoder->funcs->hdmi_set_stream_attribute(
119 stream_encoder,
120 &stream->timing,
121 stream->phy_pix_clk,
122 pipe_ctx->stream_res.audio != NULL);
123 else if (dc_is_dvi_signal(stream->signal))
124 stream_encoder->funcs->dvi_set_stream_attribute(
125 stream_encoder,
126 &stream->timing,
127 (stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
128 true : false);
129 else if (dc_is_lvds_signal(stream->signal))
130 stream_encoder->funcs->lvds_set_stream_attribute(
131 stream_encoder,
132 &stream->timing);
133
134 if (dc_is_dp_signal(stream->signal))
135 link->dc->link_srv->dp_trace_source_sequence(link,
136 DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
137 }
138
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)139 void enable_dio_dp_link_output(struct dc_link *link,
140 const struct link_resource *link_res,
141 enum signal_type signal,
142 enum clock_source_id clock_source,
143 const struct dc_link_settings *link_settings)
144 {
145 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
146
147 if (dc_is_dp_sst_signal(signal))
148 link_enc->funcs->enable_dp_output(
149 link_enc,
150 link_settings,
151 clock_source);
152 else
153 link_enc->funcs->enable_dp_mst_output(
154 link_enc,
155 link_settings,
156 clock_source);
157 link->dc->link_srv->dp_trace_source_sequence(link,
158 DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
159 }
160
disable_dio_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)161 void disable_dio_link_output(struct dc_link *link,
162 const struct link_resource *link_res,
163 enum signal_type signal)
164 {
165 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
166
167 if (link_enc != NULL)
168 link_enc->funcs->disable_output(link_enc, signal);
169
170 link->dc->link_srv->dp_trace_source_sequence(link,
171 DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
172 }
173
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)174 void set_dio_dp_link_test_pattern(struct dc_link *link,
175 const struct link_resource *link_res,
176 struct encoder_set_dp_phy_pattern_param *tp_params)
177 {
178 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
179
180 link_enc->funcs->dp_set_phy_pattern(link_enc, tp_params);
181 link->dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
182 }
183
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])184 void set_dio_dp_lane_settings(struct dc_link *link,
185 const struct link_resource *link_res,
186 const struct dc_link_settings *link_settings,
187 const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
188 {
189 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
190
191 link_enc->funcs->dp_set_lane_settings(link_enc, link_settings, lane_settings);
192 }
193
update_dio_stream_allocation_table(struct dc_link * link,const struct link_resource * link_res,const struct link_mst_stream_allocation_table * table)194 void update_dio_stream_allocation_table(struct dc_link *link,
195 const struct link_resource *link_res,
196 const struct link_mst_stream_allocation_table *table)
197 {
198 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
199
200 ASSERT(link_enc);
201 link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
202 }
203
setup_dio_audio_output(struct pipe_ctx * pipe_ctx,struct audio_output * audio_output,uint32_t audio_inst)204 void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
205 struct audio_output *audio_output, uint32_t audio_inst)
206 {
207 if (dc_is_dp_signal(pipe_ctx->stream->signal))
208 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
209 pipe_ctx->stream_res.stream_enc,
210 audio_inst,
211 &pipe_ctx->stream->audio_info);
212 else
213 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
214 pipe_ctx->stream_res.stream_enc,
215 audio_inst,
216 &pipe_ctx->stream->audio_info,
217 &audio_output->crtc_info);
218 }
219
enable_dio_audio_packet(struct pipe_ctx * pipe_ctx)220 void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
221 {
222 if (dc_is_dp_signal(pipe_ctx->stream->signal))
223 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(
224 pipe_ctx->stream_res.stream_enc);
225
226 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
227 pipe_ctx->stream_res.stream_enc, false);
228
229 if (dc_is_dp_signal(pipe_ctx->stream->signal))
230 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
231 pipe_ctx->stream->link,
232 DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
233 }
234
disable_dio_audio_packet(struct pipe_ctx * pipe_ctx)235 void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
236 {
237 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
238 pipe_ctx->stream_res.stream_enc, true);
239
240 if (pipe_ctx->stream_res.audio) {
241 if (dc_is_dp_signal(pipe_ctx->stream->signal))
242 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
243 pipe_ctx->stream_res.stream_enc);
244 else
245 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
246 pipe_ctx->stream_res.stream_enc);
247 }
248
249 if (dc_is_dp_signal(pipe_ctx->stream->signal))
250 pipe_ctx->stream->ctx->dc->link_srv->dp_trace_source_sequence(
251 pipe_ctx->stream->link,
252 DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
253 }
254
255 static const struct link_hwss dio_link_hwss = {
256 .setup_stream_encoder = setup_dio_stream_encoder,
257 .reset_stream_encoder = reset_dio_stream_encoder,
258 .setup_stream_attribute = setup_dio_stream_attribute,
259 .disable_link_output = disable_dio_link_output,
260 .setup_audio_output = setup_dio_audio_output,
261 .enable_audio_packet = enable_dio_audio_packet,
262 .disable_audio_packet = disable_dio_audio_packet,
263 .ext = {
264 .set_throttled_vcp_size = set_dio_throttled_vcp_size,
265 .enable_dp_link_output = enable_dio_dp_link_output,
266 .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
267 .set_dp_lane_settings = set_dio_dp_lane_settings,
268 .update_stream_allocation_table = update_dio_stream_allocation_table,
269 },
270 };
271
272 /**
273 * can_use_dio_link_hwss - Check if the link_hwss is accessible
274 *
275 * @link: Reference a link struct containing one or more sinks and the
276 * connective status.
277 * @link_res: Mappable hardware resource used to enable a link.
278 *
279 * Returns:
280 * Return true if the link encoder is accessible from link.
281 */
can_use_dio_link_hwss(const struct dc_link * link,const struct link_resource * link_res)282 bool can_use_dio_link_hwss(const struct dc_link *link,
283 const struct link_resource *link_res)
284 {
285 return link->link_enc != NULL;
286 }
287
288 /**
289 * get_dio_link_hwss - Return link_hwss reference
290 *
291 * This function behaves like a get function to return the link_hwss populated
292 * in the link_hwss_dio.c file.
293 *
294 * Returns:
295 * Return the reference to the filled struct of link_hwss.
296 */
get_dio_link_hwss(void)297 const struct link_hwss *get_dio_link_hwss(void)
298 {
299 return &dio_link_hwss;
300 }
301