2 * Copyright 2012-14 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
31 #include "grph_object_defs.h"
35 enum dc_link_fec_state {
36 dc_link_fec_not_ready,
41 struct dc_link_status {
43 struct dpcd_caps *dpcd_caps;
47 bool cable_id_written;
50 /* DP MST stream allocation (payload bandwidth number) */
51 struct link_mst_stream_allocation {
53 const struct stream_encoder *stream_enc;
54 /* HPO DP Stream Encoder */
55 const struct hpo_dp_stream_encoder *hpo_dp_stream_enc;
56 /* associate DRM payload table with DC stream encoder */
58 /* number of slots required for the DP stream in transport packet */
62 /* DP MST stream allocation table */
63 struct link_mst_stream_allocation_table {
64 /* number of DP video streams */
66 /* array of stream allocations */
67 struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
70 struct edp_trace_power_timestamps {
75 struct dp_trace_lt_counts {
81 struct dp_trace_lt_counts counts;
82 struct dp_trace_timestamps {
83 unsigned long long start;
84 unsigned long long end;
86 enum link_training_result result;
91 struct dp_trace_lt detect_lt_trace;
92 struct dp_trace_lt commit_lt_trace;
93 unsigned int link_loss_count;
95 struct edp_trace_power_timestamps edp_trace_power_timestamps;
98 /* PSR feature flags */
100 bool psr_feature_enabled; // PSR is supported by sink
101 bool psr_allow_active; // PSR is currently active
102 enum dc_psr_version psr_version; // Internal PSR version, determined based on DPCD
103 bool psr_vtotal_control_support; // Vtotal control is supported by sink
105 /* These parameters are calculated in Driver,
106 * based on display timing and Sink capabilities.
107 * If VBLANK region is too small and Sink takes a long time
108 * to set up RFB, it may take an extra frame to enter PSR state.
110 bool psr_frame_capture_indication_req;
111 unsigned int psr_sdp_transmit_line_num_deadline;
112 uint8_t force_ffu_mode;
113 unsigned int psr_power_opt;
117 * A link contains one or more sinks and their connected status.
118 * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
121 struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
122 unsigned int sink_count;
123 struct dc_sink *local_sink;
124 unsigned int link_index;
125 enum dc_connection_type type;
126 enum signal_type connector_signal;
127 enum dc_irq_source irq_source_hpd;
128 enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse */
129 bool is_hpd_filter_disabled;
131 bool link_state_valid;
132 bool aux_access_disabled;
133 bool sync_lt_in_progress;
134 enum lttpr_mode lttpr_mode;
135 bool is_internal_display;
137 /* TODO: Rename. Flag an endpoint as having a programmable mapping to a
139 bool is_dig_mapping_flexible;
140 bool hpd_status; /* HPD status of link without physical HPD pin. */
141 bool is_hpd_pending; /* Indicates a new received hpd */
143 bool edp_sink_present;
145 struct dp_trace dp_trace;
147 /* caps is the same as reported_link_cap. link_traing use
148 * reported_link_cap. Will clean up. TODO
150 struct dc_link_settings reported_link_cap;
151 struct dc_link_settings verified_link_cap;
152 struct dc_link_settings cur_link_settings;
153 struct dc_lane_settings cur_lane_setting[LANE_COUNT_DP_MAX];
154 struct dc_link_settings preferred_link_setting;
155 /* preferred_training_settings are override values that
156 * come from DM. DM is responsible for the memory
157 * management of the override pointers.
159 struct dc_link_training_overrides preferred_training_settings;
160 struct dp_audio_test_data audio_test_data;
166 uint8_t link_enc_hw_inst;
167 /* DIG link encoder ID. Used as index in link encoder resource pool.
168 * For links with fixed mapping to DIG, this is not changed after dc_link
171 enum engine_id eng_id;
173 bool test_pattern_enabled;
174 union compliance_test_state compliance_test_state;
178 struct ddc_service *ddc;
182 /* Private to DC core */
186 struct dc_context *ctx;
188 struct panel_cntl *panel_cntl;
189 struct link_encoder *link_enc;
190 struct graphics_object_id link_id;
191 /* Endpoint type distinguishes display endpoints which do not have entries
192 * in the BIOS connector table from those that do. Helps when tracking link
193 * encoder to display endpoint assignments.
195 enum display_endpoint_type ep_type;
196 union ddi_channel_mapping ddi_channel_mapping;
197 struct connector_device_tag_info device_tag;
198 struct dpcd_caps dpcd_caps;
199 uint32_t dongle_max_pix_clk;
200 unsigned short chip_caps;
201 unsigned int dpcd_sink_count;
202 #if defined(CONFIG_DRM_AMD_DC_HDCP)
203 struct hdcp_caps hdcp_caps;
205 enum edp_revision edp_revision;
206 union dpcd_sink_ext_caps dpcd_sink_ext_caps;
208 struct psr_settings psr_settings;
210 /* Drive settings read from integrated info table */
211 struct dc_lane_settings bios_forced_drive_settings;
213 /* Vendor specific LTTPR workaround variables */
214 uint8_t vendor_specific_lttpr_link_rate_wa;
215 bool apply_vendor_specific_lttpr_link_rate_wa;
217 /* MST record stream using this link */
219 bool dp_keep_receiver_powered;
221 bool dp_skip_reset_segment;
222 bool dp_mot_reset_segment;
223 /* Some USB4 docks do not handle turning off MST DSC once it has been enabled. */
224 bool dpia_mst_dsc_always_on;
225 /* Forced DPIA into TBT3 compatibility mode. */
226 bool dpia_forced_tbt3_mode;
228 struct link_mst_stream_allocation_table mst_stream_alloc_table;
230 struct dc_link_status link_status;
231 struct dprx_states dprx_states;
233 struct gpio *hpd_gpio;
234 enum dc_link_fec_state fec_state;
237 const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);
240 * dc_get_link_at_index() - Return an enumerated dc_link.
242 * dc_link order is constant and determined at
243 * boot time. They cannot be created or destroyed.
244 * Use dc_get_caps() to get number of links.
246 static inline struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index)
248 return dc->links[link_index];
251 static inline void get_edp_links(const struct dc *dc,
252 struct dc_link **edp_links,
258 for (i = 0; i < dc->link_count; i++) {
259 // report any eDP links, even unconnected DDI's
262 if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP) {
263 edp_links[*edp_num] = dc->links[i];
264 if (++(*edp_num) == MAX_NUM_EDP)
270 static inline bool dc_get_edp_link_panel_inst(const struct dc *dc,
271 const struct dc_link *link,
272 unsigned int *inst_out)
274 struct dc_link *edp_links[MAX_NUM_EDP];
277 if (link->connector_signal != SIGNAL_TYPE_EDP)
279 get_edp_links(dc, edp_links, &edp_num);
280 if ((edp_num > 1) && (link->link_index > edp_links[0]->link_index))
287 /* Set backlight level of an embedded panel (eDP, LVDS).
288 * backlight_pwm_u16_16 is unsigned 32 bit with 16 bit integer
289 * and 16 bit fractional, where 1.0 is max backlight value.
291 bool dc_link_set_backlight_level(const struct dc_link *dc_link,
292 uint32_t backlight_pwm_u16_16,
293 uint32_t frame_ramp);
295 /* Set/get nits-based backlight level of an embedded panel (eDP, LVDS). */
296 bool dc_link_set_backlight_level_nits(struct dc_link *link,
298 uint32_t backlight_millinits,
299 uint32_t transition_time_in_ms);
301 bool dc_link_get_backlight_level_nits(struct dc_link *link,
302 uint32_t *backlight_millinits,
303 uint32_t *backlight_millinits_peak);
305 bool dc_link_backlight_enable_aux(struct dc_link *link, bool enable);
307 bool dc_link_read_default_bl_aux(struct dc_link *link, uint32_t *backlight_millinits);
308 bool dc_link_set_default_brightness_aux(struct dc_link *link);
310 int dc_link_get_backlight_level(const struct dc_link *dc_link);
312 int dc_link_get_target_backlight_pwm(const struct dc_link *link);
314 bool dc_link_set_psr_allow_active(struct dc_link *dc_link, const bool *enable,
315 bool wait, bool force_static, const unsigned int *power_opts);
317 bool dc_link_get_psr_state(const struct dc_link *dc_link, enum dc_psr_state *state);
319 bool dc_link_setup_psr(struct dc_link *dc_link,
320 const struct dc_stream_state *stream, struct psr_config *psr_config,
321 struct psr_context *psr_context);
323 bool dc_power_alpm_dpcd_enable(struct dc_link *link, bool enable);
325 void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency);
327 void dc_link_blank_all_dp_displays(struct dc *dc);
328 void dc_link_blank_all_edp_displays(struct dc *dc);
330 void dc_link_blank_dp_stream(struct dc_link *link, bool hw_init);
331 bool dc_link_set_sink_vtotal_in_psr_active(const struct dc_link *link,
332 uint16_t psr_vtotal_idle, uint16_t psr_vtotal_su);
334 /* Request DC to detect if there is a Panel connected.
335 * boot - If this call is during initial boot.
336 * Return false for any type of detection failure or MST detection
337 * true otherwise. True meaning further action is required (status update
338 * and OS notification).
340 enum dc_detect_reason {
342 DETECT_REASON_RESUMEFROMS3S4,
345 DETECT_REASON_FALLBACK,
346 DETECT_REASON_RETRAIN,
349 bool dc_link_detect(struct dc_link *dc_link, enum dc_detect_reason reason);
350 bool dc_link_get_hpd_state(struct dc_link *dc_link);
351 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx);
352 enum dc_status dc_link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
353 enum dc_status dc_link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
355 /* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
357 * true - Downstream port status changed. DM should call DC to do the
359 * false - no change in Downstream port status. No further action required
361 bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
362 union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss,
363 bool defer_handling, bool *has_left_work);
366 * On eDP links this function call will stall until T12 has elapsed.
367 * If the panel is not in power off state, this function will return
370 bool dc_link_wait_for_t12(struct dc_link *link);
372 void dc_link_dp_handle_automated_test(struct dc_link *link);
373 void dc_link_dp_handle_link_loss(struct dc_link *link);
374 bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link);
376 struct dc_sink_init_data;
378 struct dc_sink *dc_link_add_remote_sink(
379 struct dc_link *dc_link,
382 struct dc_sink_init_data *init_data);
384 void dc_link_remove_remote_sink(
385 struct dc_link *link,
386 struct dc_sink *sink);
388 /* Used by diagnostics for virtual link at the moment */
390 void dc_link_dp_set_drive_settings(
391 struct dc_link *link,
392 const struct link_resource *link_res,
393 struct link_training_settings *lt_settings);
395 bool dc_link_dp_perform_link_training_skip_aux(
396 struct dc_link *link,
397 const struct link_resource *link_res,
398 const struct dc_link_settings *link_setting);
400 enum link_training_result dc_link_dp_perform_link_training(
401 struct dc_link *link,
402 const struct link_resource *link_res,
403 const struct dc_link_settings *link_settings,
404 bool skip_video_pattern);
406 bool dc_link_dp_sync_lt_begin(struct dc_link *link);
408 enum link_training_result dc_link_dp_sync_lt_attempt(
409 struct dc_link *link,
410 const struct link_resource *link_res,
411 struct dc_link_settings *link_setting,
412 struct dc_link_training_overrides *lt_settings);
414 bool dc_link_dp_sync_lt_end(struct dc_link *link, bool link_down);
416 void dc_link_dp_enable_hpd(const struct dc_link *link);
418 void dc_link_dp_disable_hpd(const struct dc_link *link);
420 bool dc_link_dp_set_test_pattern(
421 struct dc_link *link,
422 enum dp_test_pattern test_pattern,
423 enum dp_test_pattern_color_space test_pattern_color_space,
424 const struct link_training_settings *p_link_settings,
425 const unsigned char *p_custom_pattern,
426 unsigned int cust_pattern_size);
428 bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap);
430 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
432 bool dc_link_is_dp_sink_present(struct dc_link *link);
434 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type);
436 * DPCD access interfaces
439 #ifdef CONFIG_DRM_AMD_DC_HDCP
440 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal);
441 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal);
443 void dc_link_set_drive_settings(struct dc *dc,
444 struct link_training_settings *lt_settings,
445 const struct dc_link *link);
446 void dc_link_set_preferred_link_settings(struct dc *dc,
447 struct dc_link_settings *link_setting,
448 struct dc_link *link);
449 void dc_link_set_preferred_training_settings(struct dc *dc,
450 struct dc_link_settings *link_setting,
451 struct dc_link_training_overrides *lt_overrides,
452 struct dc_link *link,
453 bool skip_immediate_retrain);
454 void dc_link_enable_hpd(const struct dc_link *link);
455 void dc_link_disable_hpd(const struct dc_link *link);
456 void dc_link_set_test_pattern(struct dc_link *link,
457 enum dp_test_pattern test_pattern,
458 enum dp_test_pattern_color_space test_pattern_color_space,
459 const struct link_training_settings *p_link_settings,
460 const unsigned char *p_custom_pattern,
461 unsigned int cust_pattern_size);
462 uint32_t dc_link_bandwidth_kbps(
463 const struct dc_link *link,
464 const struct dc_link_settings *link_setting);
466 const struct dc_link_settings *dc_link_get_link_cap(
467 const struct dc_link *link);
469 void dc_link_overwrite_extended_receiver_cap(
470 struct dc_link *link);
472 bool dc_is_oem_i2c_device_present(
480 struct i2c_command *cmd);
482 bool dc_submit_i2c_oem(
484 struct i2c_command *cmd);
486 uint32_t dc_bandwidth_in_kbps_from_timing(
487 const struct dc_crtc_timing *timing);
489 bool dc_link_is_fec_supported(const struct dc_link *link);
490 bool dc_link_should_enable_fec(const struct dc_link *link);
492 uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw);
493 enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(const struct dc_link *link);
495 void dc_link_get_cur_link_res(const struct dc_link *link,
496 struct link_resource *link_res);
497 /* take a snapshot of current link resource allocation state */
498 void dc_get_cur_link_res_map(const struct dc *dc, uint32_t *map);
499 /* restore link resource allocation state from a snapshot */
500 void dc_restore_link_res_map(const struct dc *dc, uint32_t *map);
501 void dc_link_clear_dprx_states(struct dc_link *link);
502 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
503 struct graphics_object_id link_id,
504 struct gpio_service *gpio_service);
505 void dp_trace_reset(struct dc_link *link);
506 bool dc_dp_trace_is_initialized(struct dc_link *link);
507 unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
509 void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
512 bool dc_dp_trace_is_logged(struct dc_link *link,
514 struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
516 unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
517 #endif /* DC_LINK_H_ */