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"
34 enum aux_return_code_type;
36 enum dc_link_fec_state {
37 dc_link_fec_not_ready,
42 struct dc_link_status {
44 struct dpcd_caps *dpcd_caps;
48 bool cable_id_written;
51 /* DP MST stream allocation (payload bandwidth number) */
52 struct link_mst_stream_allocation {
54 const struct stream_encoder *stream_enc;
55 /* HPO DP Stream Encoder */
56 const struct hpo_dp_stream_encoder *hpo_dp_stream_enc;
57 /* associate DRM payload table with DC stream encoder */
59 /* number of slots required for the DP stream in transport packet */
63 /* DP MST stream allocation table */
64 struct link_mst_stream_allocation_table {
65 /* number of DP video streams */
67 /* array of stream allocations */
68 struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
71 struct edp_trace_power_timestamps {
76 struct dp_trace_lt_counts {
82 struct dp_trace_lt_counts counts;
83 struct dp_trace_timestamps {
84 unsigned long long start;
85 unsigned long long end;
87 enum link_training_result result;
92 struct dp_trace_lt detect_lt_trace;
93 struct dp_trace_lt commit_lt_trace;
94 unsigned int link_loss_count;
96 struct edp_trace_power_timestamps edp_trace_power_timestamps;
99 /* PSR feature flags */
100 struct psr_settings {
101 bool psr_feature_enabled; // PSR is supported by sink
102 bool psr_allow_active; // PSR is currently active
103 enum dc_psr_version psr_version; // Internal PSR version, determined based on DPCD
104 bool psr_vtotal_control_support; // Vtotal control is supported by sink
106 /* These parameters are calculated in Driver,
107 * based on display timing and Sink capabilities.
108 * If VBLANK region is too small and Sink takes a long time
109 * to set up RFB, it may take an extra frame to enter PSR state.
111 bool psr_frame_capture_indication_req;
112 unsigned int psr_sdp_transmit_line_num_deadline;
113 uint8_t force_ffu_mode;
114 unsigned int psr_power_opt;
117 /* To split out "global" and "per-panel" config settings.
118 * Add a struct dc_panel_config under dc_link
120 struct dc_panel_config {
121 /* extra panel power sequence parameters */
123 unsigned int extra_t3_ms;
124 unsigned int extra_t7_ms;
125 unsigned int extra_delay_backlight_off;
126 unsigned int extra_post_t7_ms;
127 unsigned int extra_pre_t11_ms;
128 unsigned int extra_t12_ms;
129 unsigned int extra_post_OUI_ms;
136 bool rc_allow_static_screen;
137 bool rc_allow_fullscreen_VPB;
141 unsigned int varibright_feature_enable;
142 unsigned int def_varibright_level;
143 unsigned int abm_config_setting;
147 bool disable_dsc_edp;
148 unsigned int force_dsc_edp_policy;
152 bool optimize_edp_link_rate; /* eDP ILR */
157 * USB4 DPIA BW ALLOCATION STRUCTS
159 struct dc_dpia_bw_alloc {
160 int sink_verified_bw; // The Verified BW that sink can allocated and use that has been verified already
161 int sink_allocated_bw; // The Actual Allocated BW that sink currently allocated
162 int sink_max_bw; // The Max BW that sink can require/support
163 int estimated_bw; // The estimated available BW for this DPIA
164 int bw_granularity; // BW Granularity
165 bool bw_alloc_enabled; // The BW Alloc Mode Support is turned ON for all 3: DP-Tx & Dpia & CM
166 bool response_ready; // Response ready from the CM side
170 * A link contains one or more sinks and their connected status.
171 * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
174 struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
175 unsigned int sink_count;
176 struct dc_sink *local_sink;
177 unsigned int link_index;
178 enum dc_connection_type type;
179 enum signal_type connector_signal;
180 enum dc_irq_source irq_source_hpd;
181 enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse */
182 bool is_hpd_filter_disabled;
188 * If there is no link and local sink, this variable should be set to
189 * false. Otherwise, it should be set to true; usually, the function
190 * core_link_enable_stream sets this field to true.
192 bool link_state_valid;
193 bool aux_access_disabled;
194 bool sync_lt_in_progress;
195 bool is_internal_display;
197 /* TODO: Rename. Flag an endpoint as having a programmable mapping to a
199 bool is_dig_mapping_flexible;
200 bool hpd_status; /* HPD status of link without physical HPD pin. */
201 bool is_hpd_pending; /* Indicates a new received hpd */
202 bool is_automated; /* Indicates automated testing */
204 bool edp_sink_present;
206 struct dp_trace dp_trace;
208 /* caps is the same as reported_link_cap. link_traing use
209 * reported_link_cap. Will clean up. TODO
211 struct dc_link_settings reported_link_cap;
212 struct dc_link_settings verified_link_cap;
213 struct dc_link_settings cur_link_settings;
214 struct dc_lane_settings cur_lane_setting[LANE_COUNT_DP_MAX];
215 struct dc_link_settings preferred_link_setting;
216 /* preferred_training_settings are override values that
217 * come from DM. DM is responsible for the memory
218 * management of the override pointers.
220 struct dc_link_training_overrides preferred_training_settings;
221 struct dp_audio_test_data audio_test_data;
227 uint8_t link_enc_hw_inst;
228 /* DIG link encoder ID. Used as index in link encoder resource pool.
229 * For links with fixed mapping to DIG, this is not changed after dc_link
232 enum engine_id eng_id;
234 bool test_pattern_enabled;
235 union compliance_test_state compliance_test_state;
239 struct ddc_service *ddc;
243 /* Private to DC core */
247 struct dc_context *ctx;
249 struct panel_cntl *panel_cntl;
250 struct link_encoder *link_enc;
251 struct graphics_object_id link_id;
252 /* Endpoint type distinguishes display endpoints which do not have entries
253 * in the BIOS connector table from those that do. Helps when tracking link
254 * encoder to display endpoint assignments.
256 enum display_endpoint_type ep_type;
257 union ddi_channel_mapping ddi_channel_mapping;
258 struct connector_device_tag_info device_tag;
259 struct dpcd_caps dpcd_caps;
260 uint32_t dongle_max_pix_clk;
261 unsigned short chip_caps;
262 unsigned int dpcd_sink_count;
263 #if defined(CONFIG_DRM_AMD_DC_HDCP)
264 struct hdcp_caps hdcp_caps;
266 enum edp_revision edp_revision;
267 union dpcd_sink_ext_caps dpcd_sink_ext_caps;
269 struct psr_settings psr_settings;
271 /* Drive settings read from integrated info table */
272 struct dc_lane_settings bios_forced_drive_settings;
274 /* Vendor specific LTTPR workaround variables */
275 uint8_t vendor_specific_lttpr_link_rate_wa;
276 bool apply_vendor_specific_lttpr_link_rate_wa;
278 /* MST record stream using this link */
280 bool dp_keep_receiver_powered;
282 bool dp_skip_reset_segment;
283 bool dp_skip_fs_144hz;
284 bool dp_mot_reset_segment;
285 /* Some USB4 docks do not handle turning off MST DSC once it has been enabled. */
286 bool dpia_mst_dsc_always_on;
287 /* Forced DPIA into TBT3 compatibility mode. */
288 bool dpia_forced_tbt3_mode;
289 bool dongle_mode_timing_override;
291 struct link_mst_stream_allocation_table mst_stream_alloc_table;
293 struct dc_link_status link_status;
294 struct dprx_states dprx_states;
296 struct gpio *hpd_gpio;
297 enum dc_link_fec_state fec_state;
298 bool link_powered_externally; // Used to bypass hardware sequencing delays when panel is powered down forcibly
300 struct dc_panel_config panel_config;
301 struct phy_state phy_state;
304 const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);
307 * dc_get_link_at_index() - Return an enumerated dc_link.
309 * dc_link order is constant and determined at
310 * boot time. They cannot be created or destroyed.
311 * Use dc_get_caps() to get number of links.
313 static inline struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index)
315 return dc->links[link_index];
318 static inline void get_edp_links(const struct dc *dc,
319 struct dc_link **edp_links,
325 for (i = 0; i < dc->link_count; i++) {
326 // report any eDP links, even unconnected DDI's
329 if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP) {
330 edp_links[*edp_num] = dc->links[i];
331 if (++(*edp_num) == MAX_NUM_EDP)
337 static inline bool dc_get_edp_link_panel_inst(const struct dc *dc,
338 const struct dc_link *link,
339 unsigned int *inst_out)
341 struct dc_link *edp_links[MAX_NUM_EDP];
345 if (link->connector_signal != SIGNAL_TYPE_EDP)
347 get_edp_links(dc, edp_links, &edp_num);
348 for (i = 0; i < edp_num; i++) {
349 if (link == edp_links[i])
356 /* Set backlight level of an embedded panel (eDP, LVDS).
357 * backlight_pwm_u16_16 is unsigned 32 bit with 16 bit integer
358 * and 16 bit fractional, where 1.0 is max backlight value.
360 bool dc_link_set_backlight_level(const struct dc_link *dc_link,
361 uint32_t backlight_pwm_u16_16,
362 uint32_t frame_ramp);
364 /* Set/get nits-based backlight level of an embedded panel (eDP, LVDS). */
365 bool dc_link_set_backlight_level_nits(struct dc_link *link,
367 uint32_t backlight_millinits,
368 uint32_t transition_time_in_ms);
370 bool dc_link_get_backlight_level_nits(struct dc_link *link,
371 uint32_t *backlight_millinits,
372 uint32_t *backlight_millinits_peak);
374 int dc_link_get_backlight_level(const struct dc_link *dc_link);
376 int dc_link_get_target_backlight_pwm(const struct dc_link *link);
378 bool dc_link_set_psr_allow_active(struct dc_link *dc_link, const bool *enable,
379 bool wait, bool force_static, const unsigned int *power_opts);
381 bool dc_link_get_psr_state(const struct dc_link *dc_link, enum dc_psr_state *state);
383 bool dc_link_setup_psr(struct dc_link *dc_link,
384 const struct dc_stream_state *stream, struct psr_config *psr_config,
385 struct psr_context *psr_context);
387 /* Request DC to detect if there is a Panel connected.
388 * boot - If this call is during initial boot.
389 * Return false for any type of detection failure or MST detection
390 * true otherwise. True meaning further action is required (status update
391 * and OS notification).
393 enum dc_detect_reason {
395 DETECT_REASON_RESUMEFROMS3S4,
398 DETECT_REASON_FALLBACK,
399 DETECT_REASON_RETRAIN,
403 bool dc_link_detect(struct dc_link *dc_link, enum dc_detect_reason reason);
404 bool dc_link_get_hpd_state(struct dc_link *dc_link);
406 /* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
408 * true - Downstream port status changed. DM should call DC to do the
410 * false - no change in Downstream port status. No further action required
412 bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
413 union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss,
414 bool defer_handling, bool *has_left_work);
417 * On eDP links this function call will stall until T12 has elapsed.
418 * If the panel is not in power off state, this function will return
421 bool dc_link_wait_for_t12(struct dc_link *link);
423 void dc_link_dp_handle_automated_test(struct dc_link *link);
424 void dc_link_dp_handle_link_loss(struct dc_link *link);
425 bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link);
426 bool dc_link_check_link_loss_status(struct dc_link *link,
427 union hpd_irq_data *hpd_irq_dpcd_data);
428 enum dc_status dc_link_dp_read_hpd_rx_irq_data(
429 struct dc_link *link,
430 union hpd_irq_data *irq_data);
431 struct dc_sink_init_data;
433 struct dc_sink *dc_link_add_remote_sink(
434 struct dc_link *dc_link,
437 struct dc_sink_init_data *init_data);
439 void dc_link_remove_remote_sink(
440 struct dc_link *link,
441 struct dc_sink *sink);
443 /* Used by diagnostics for virtual link at the moment */
445 bool dc_link_dp_set_test_pattern(
446 struct dc_link *link,
447 enum dp_test_pattern test_pattern,
448 enum dp_test_pattern_color_space test_pattern_color_space,
449 const struct link_training_settings *p_link_settings,
450 const unsigned char *p_custom_pattern,
451 unsigned int cust_pattern_size);
453 bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap);
456 *****************************************************************************
457 * Function: dc_link_enable_hpd_filter
460 * If enable is true, programs HPD filter on associated HPD line to default
461 * values dependent on link->connector_signal
463 * If enable is false, programs HPD filter on associated HPD line with no
464 * delays on connect or disconnect
466 * @param [in] link: pointer to the dc link
467 * @param [in] enable: boolean specifying whether to enable hbd
468 *****************************************************************************
470 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
472 bool dc_link_is_dp_sink_present(struct dc_link *link);
474 bool dc_link_detect_connection_type(struct dc_link *link, enum dc_connection_type *type);
476 * DPCD access interfaces
479 #ifdef CONFIG_DRM_AMD_DC_HDCP
480 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal);
481 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal);
483 void dc_link_set_drive_settings(struct dc *dc,
484 struct link_training_settings *lt_settings,
485 const struct dc_link *link);
486 void dc_link_set_preferred_link_settings(struct dc *dc,
487 struct dc_link_settings *link_setting,
488 struct dc_link *link);
489 void dc_link_set_preferred_training_settings(struct dc *dc,
490 struct dc_link_settings *link_setting,
491 struct dc_link_training_overrides *lt_overrides,
492 struct dc_link *link,
493 bool skip_immediate_retrain);
494 void dc_link_enable_hpd(const struct dc_link *link);
495 void dc_link_disable_hpd(const struct dc_link *link);
496 void dc_link_set_test_pattern(struct dc_link *link,
497 enum dp_test_pattern test_pattern,
498 enum dp_test_pattern_color_space test_pattern_color_space,
499 const struct link_training_settings *p_link_settings,
500 const unsigned char *p_custom_pattern,
501 unsigned int cust_pattern_size);
502 uint32_t dc_link_bandwidth_kbps(
503 const struct dc_link *link,
504 const struct dc_link_settings *link_setting);
506 const struct dc_link_settings *dc_link_get_link_cap(
507 const struct dc_link *link);
509 void dc_link_overwrite_extended_receiver_cap(
510 struct dc_link *link);
512 bool dc_is_oem_i2c_device_present(
520 struct i2c_command *cmd);
522 bool dc_submit_i2c_oem(
524 struct i2c_command *cmd);
526 uint32_t dc_bandwidth_in_kbps_from_timing(
527 const struct dc_crtc_timing *timing);
529 bool dc_link_is_fec_supported(const struct dc_link *link);
530 bool dc_link_should_enable_fec(const struct dc_link *link);
532 uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw);
533 enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(const struct dc_link *link);
535 void dc_link_get_cur_link_res(const struct dc_link *link,
536 struct link_resource *link_res);
537 /* take a snapshot of current link resource allocation state */
538 void dc_get_cur_link_res_map(const struct dc *dc, uint32_t *map);
539 /* restore link resource allocation state from a snapshot */
540 void dc_restore_link_res_map(const struct dc *dc, uint32_t *map);
541 void dc_link_clear_dprx_states(struct dc_link *link);
542 void dp_trace_reset(struct dc_link *link);
543 bool dc_dp_trace_is_initialized(struct dc_link *link);
544 unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
546 void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
549 bool dc_dp_trace_is_logged(struct dc_link *link,
551 struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
553 unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
555 /* Destruct the mst topology of the link and reset the allocated payload table */
556 bool dc_link_reset_cur_dp_mst_topology(struct dc_link *link);
558 /* Attempt to transfer the given aux payload. This function does not perform
559 * retries or handle error states. The reply is returned in the payload->reply
560 * and the result through operation_result. Returns the number of bytes
561 * transferred,or -1 on a failure.
563 int dc_link_aux_transfer_raw(struct ddc_service *ddc,
564 struct aux_payload *payload,
565 enum aux_return_code_type *operation_result);
567 enum lttpr_mode dc_link_decide_lttpr_mode(struct dc_link *link,
568 struct dc_link_settings *link_setting);
569 void dc_link_dp_receiver_power_ctrl(struct dc_link *link, bool on);
570 bool dc_link_decide_edp_link_settings(struct dc_link *link,
571 struct dc_link_settings *link_setting,
573 void dc_link_edp_panel_backlight_power_on(struct dc_link *link,
577 * USB4 DPIA BW ALLOCATION PUBLIC FUNCTIONS
580 * Send a request from DP-Tx requesting to allocate BW remotely after
581 * allocating it locally. This will get processed by CM and a CB function
584 * @link: pointer to the dc_link struct instance
585 * @req_bw: The requested bw in Kbyte to allocated
589 void dc_link_set_usb4_req_bw_req(struct dc_link *link, int req_bw);
592 * CB function for when the status of the Req above is complete. We will
593 * find out the result of allocating on CM and update structs accordingly
595 * @link: pointer to the dc_link struct instance
596 * @bw: Allocated or Estimated BW depending on the result
597 * @result: Response type
601 void dc_link_get_usb4_req_bw_resp(struct dc_link *link, uint8_t bw, uint8_t result);
603 /* TODO: this is not meant to be exposed to DM. Should switch to stream update
604 * interface i.e stream_update->dsc_config
606 bool dc_link_update_dsc_config(struct pipe_ctx *pipe_ctx);
607 #endif /* DC_LINK_H_ */