xref: /openbmc/linux/drivers/gpu/drm/amd/display/dc/inc/link.h (revision 36516001)
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 
26 #ifndef __DC_LINK_H__
27 #define __DC_LINK_H__
28 
29 /* FILE POLICY AND INTENDED USAGE:
30  *
31  * This header declares link functions exposed to dc. All functions must have
32  * "link_" as prefix. For example link_run_my_function. This header is strictly
33  * private in dc and should never be included in other header files. dc
34  * components should include this header in their .c files in order to access
35  * functions in link folder. This file should never include any header files in
36  * link folder. If there is a need to expose a function declared in one of
37  * header files in side link folder, you need to move the function declaration
38  * into this file and prefix it with "link_".
39  */
40 #include "core_types.h"
41 
42 struct link_init_data {
43 	const struct dc *dc;
44 	struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */
45 	uint32_t connector_index; /* this will be mapped to the HPD pins */
46 	uint32_t link_index; /* this is mapped to DAL display_index
47 				TODO: remove it when DC is complete. */
48 	bool is_dpia_link;
49 };
50 
51 struct link_service {
52 	void (*dp_handle_automated_test)(struct dc_link *link);
53 	bool (*dp_set_test_pattern)(
54 			struct dc_link *link,
55 			enum dp_test_pattern test_pattern,
56 			enum dp_test_pattern_color_space test_pattern_color_space,
57 			const struct link_training_settings *p_link_settings,
58 			const unsigned char *p_custom_pattern,
59 			unsigned int cust_pattern_size);
60 	void (*dp_set_preferred_link_settings)(struct dc *dc,
61 			struct dc_link_settings *link_setting,
62 			struct dc_link *link);
63 	void (*dp_set_preferred_training_settings)(struct dc *dc,
64 			struct dc_link_settings *link_setting,
65 			struct dc_link_training_overrides *lt_overrides,
66 			struct dc_link *link,
67 			bool skip_immediate_retrain);
68 	bool (*dp_trace_is_initialized)(struct dc_link *link);
69 	void (*dp_trace_set_is_logged_flag)(struct dc_link *link,
70 			bool in_detection,
71 			bool is_logged);
72 	bool (*dp_trace_is_logged)(struct dc_link *link, bool in_detection);
73 	unsigned long long (*dp_trace_get_lt_end_timestamp)(
74 			struct dc_link *link, bool in_detection);
75 	const struct dp_trace_lt_counts *(*dp_trace_get_lt_counts)(
76 			struct dc_link *link, bool in_detection);
77 	unsigned int (*dp_trace_get_link_loss_count)(struct dc_link *link);
78 };
79 
80 struct dc_link *link_create(const struct link_init_data *init_params);
81 void link_destroy(struct dc_link **link);
82 const struct link_service *link_get_link_service(void);
83 
84 // TODO - convert any function declarations below to function pointers
85 struct gpio *link_get_hpd_gpio(struct dc_bios *dcb,
86 		struct graphics_object_id link_id,
87 		struct gpio_service *gpio_service);
88 
89 struct ddc_service_init_data {
90 	struct graphics_object_id id;
91 	struct dc_context *ctx;
92 	struct dc_link *link;
93 	bool is_dpia_link;
94 };
95 
96 struct ddc_service *link_create_ddc_service(
97 		struct ddc_service_init_data *ddc_init_data);
98 
99 void link_destroy_ddc_service(struct ddc_service **ddc);
100 
101 bool link_is_in_aux_transaction_mode(struct ddc_service *ddc);
102 
103 bool link_query_ddc_data(
104 		struct ddc_service *ddc,
105 		uint32_t address,
106 		uint8_t *write_buf,
107 		uint32_t write_size,
108 		uint8_t *read_buf,
109 		uint32_t read_size);
110 
111 
112 /* Attempt to submit an aux payload, retrying on timeouts, defers, and busy
113  * states as outlined in the DP spec.  Returns true if the request was
114  * successful.
115  *
116  * NOTE: The function requires explicit mutex on DM side in order to prevent
117  * potential race condition. DC components should call the dpcd read/write
118  * function in dm_helpers in order to access dpcd safely
119  */
120 bool link_aux_transfer_with_retries_no_mutex(struct ddc_service *ddc,
121 		struct aux_payload *payload);
122 
123 uint32_t link_get_aux_defer_delay(struct ddc_service *ddc);
124 
125 bool link_is_dp_128b_132b_signal(struct pipe_ctx *pipe_ctx);
126 
127 enum dp_link_encoding link_dp_get_encoding_format(
128 		const struct dc_link_settings *link_settings);
129 
130 bool link_decide_link_settings(
131 	struct dc_stream_state *stream,
132 	struct dc_link_settings *link_setting);
133 
134 void link_dp_trace_set_edp_power_timestamp(struct dc_link *link,
135 		bool power_up);
136 uint64_t link_dp_trace_get_edp_poweron_timestamp(struct dc_link *link);
137 uint64_t link_dp_trace_get_edp_poweroff_timestamp(struct dc_link *link);
138 
139 bool link_is_edp_ilr_optimization_required(struct dc_link *link,
140 		struct dc_crtc_timing *crtc_timing);
141 
142 bool link_backlight_enable_aux(struct dc_link *link, bool enable);
143 void link_edp_add_delay_for_T9(struct dc_link *link);
144 bool link_edp_receiver_ready_T9(struct dc_link *link);
145 bool link_edp_receiver_ready_T7(struct dc_link *link);
146 bool link_power_alpm_dpcd_enable(struct dc_link *link, bool enable);
147 bool link_set_sink_vtotal_in_psr_active(const struct dc_link *link,
148 		uint16_t psr_vtotal_idle, uint16_t psr_vtotal_su);
149 void link_get_psr_residency(const struct dc_link *link, uint32_t *residency);
150 enum dc_status link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
151 enum dc_status link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
152 void link_blank_all_dp_displays(struct dc *dc);
153 void link_blank_all_edp_displays(struct dc *dc);
154 void link_blank_dp_stream(struct dc_link *link, bool hw_init);
155 void link_resume(struct dc_link *link);
156 void link_set_dpms_on(
157 		struct dc_state *state,
158 		struct pipe_ctx *pipe_ctx);
159 void link_set_dpms_off(struct pipe_ctx *pipe_ctx);
160 void link_dp_source_sequence_trace(struct dc_link *link, uint8_t dp_test_mode);
161 void link_set_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable);
162 bool link_set_dsc_enable(struct pipe_ctx *pipe_ctx, bool enable);
163 bool link_update_dsc_config(struct pipe_ctx *pipe_ctx);
164 enum dc_status link_validate_mode_timing(
165 		const struct dc_stream_state *stream,
166 		struct dc_link *link,
167 		const struct dc_crtc_timing *timing);
168 bool link_detect(struct dc_link *link, enum dc_detect_reason reason);
169 bool link_detect_connection_type(struct dc_link *link,
170 		enum dc_connection_type *type);
171 const struct dc_link_status *link_get_status(const struct dc_link *link);
172 /* return true if the connected receiver supports the hdcp version */
173 bool link_is_hdcp14(struct dc_link *link, enum signal_type signal);
174 bool link_is_hdcp22(struct dc_link *link, enum signal_type signal);
175 void link_clear_dprx_states(struct dc_link *link);
176 bool link_reset_cur_dp_mst_topology(struct dc_link *link);
177 uint32_t dp_link_bandwidth_kbps(
178 	const struct dc_link *link,
179 	const struct dc_link_settings *link_settings);
180 uint32_t link_timing_bandwidth_kbps(const struct dc_crtc_timing *timing);
181 void link_get_cur_res_map(const struct dc *dc, uint32_t *map);
182 void link_restore_res_map(const struct dc *dc, uint32_t *map);
183 void link_get_cur_link_res(const struct dc_link *link,
184 		struct link_resource *link_res);
185 void dp_set_drive_settings(
186 	struct dc_link *link,
187 	const struct link_resource *link_res,
188 	struct link_training_settings *lt_settings);
189 #endif /* __DC_LINK_HPD_H__ */
190