xref: /dflybsd-src/sys/dev/drm/amd/display/dc/dc_link.h (revision b843c749addef9340ee7d4e250b09fdd492602a1)
1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2012-14 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev  *
4*b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev  *
11*b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev  *
14*b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev  *
22*b843c749SSergey Zigachev  * Authors: AMD
23*b843c749SSergey Zigachev  *
24*b843c749SSergey Zigachev  */
25*b843c749SSergey Zigachev 
26*b843c749SSergey Zigachev #ifndef DC_LINK_H_
27*b843c749SSergey Zigachev #define DC_LINK_H_
28*b843c749SSergey Zigachev 
29*b843c749SSergey Zigachev #include "dc_types.h"
30*b843c749SSergey Zigachev #include "grph_object_defs.h"
31*b843c749SSergey Zigachev 
32*b843c749SSergey Zigachev struct dc_link_status {
33*b843c749SSergey Zigachev 	struct dpcd_caps *dpcd_caps;
34*b843c749SSergey Zigachev };
35*b843c749SSergey Zigachev 
36*b843c749SSergey Zigachev /* DP MST stream allocation (payload bandwidth number) */
37*b843c749SSergey Zigachev struct link_mst_stream_allocation {
38*b843c749SSergey Zigachev 	/* DIG front */
39*b843c749SSergey Zigachev 	const struct stream_encoder *stream_enc;
40*b843c749SSergey Zigachev 	/* associate DRM payload table with DC stream encoder */
41*b843c749SSergey Zigachev 	uint8_t vcp_id;
42*b843c749SSergey Zigachev 	/* number of slots required for the DP stream in transport packet */
43*b843c749SSergey Zigachev 	uint8_t slot_count;
44*b843c749SSergey Zigachev };
45*b843c749SSergey Zigachev 
46*b843c749SSergey Zigachev /* DP MST stream allocation table */
47*b843c749SSergey Zigachev struct link_mst_stream_allocation_table {
48*b843c749SSergey Zigachev 	/* number of DP video streams */
49*b843c749SSergey Zigachev 	int stream_count;
50*b843c749SSergey Zigachev 	/* array of stream allocations */
51*b843c749SSergey Zigachev 	struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
52*b843c749SSergey Zigachev };
53*b843c749SSergey Zigachev 
54*b843c749SSergey Zigachev struct time_stamp {
55*b843c749SSergey Zigachev 	uint64_t edp_poweroff;
56*b843c749SSergey Zigachev 	uint64_t edp_poweron;
57*b843c749SSergey Zigachev };
58*b843c749SSergey Zigachev 
59*b843c749SSergey Zigachev struct link_trace {
60*b843c749SSergey Zigachev 	struct time_stamp time_stamp;
61*b843c749SSergey Zigachev };
62*b843c749SSergey Zigachev /*
63*b843c749SSergey Zigachev  * A link contains one or more sinks and their connected status.
64*b843c749SSergey Zigachev  * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
65*b843c749SSergey Zigachev  */
66*b843c749SSergey Zigachev struct dc_link {
67*b843c749SSergey Zigachev 	struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
68*b843c749SSergey Zigachev 	unsigned int sink_count;
69*b843c749SSergey Zigachev 	struct dc_sink *local_sink;
70*b843c749SSergey Zigachev 	unsigned int link_index;
71*b843c749SSergey Zigachev 	enum dc_connection_type type;
72*b843c749SSergey Zigachev 	enum signal_type connector_signal;
73*b843c749SSergey Zigachev 	enum dc_irq_source irq_source_hpd;
74*b843c749SSergey Zigachev 	enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse  */
75*b843c749SSergey Zigachev 	bool is_hpd_filter_disabled;
76*b843c749SSergey Zigachev 	bool dp_ss_off;
77*b843c749SSergey Zigachev 
78*b843c749SSergey Zigachev 	/* caps is the same as reported_link_cap. link_traing use
79*b843c749SSergey Zigachev 	 * reported_link_cap. Will clean up.  TODO
80*b843c749SSergey Zigachev 	 */
81*b843c749SSergey Zigachev 	struct dc_link_settings reported_link_cap;
82*b843c749SSergey Zigachev 	struct dc_link_settings verified_link_cap;
83*b843c749SSergey Zigachev 	struct dc_link_settings cur_link_settings;
84*b843c749SSergey Zigachev 	struct dc_lane_settings cur_lane_setting;
85*b843c749SSergey Zigachev 	struct dc_link_settings preferred_link_setting;
86*b843c749SSergey Zigachev 
87*b843c749SSergey Zigachev 	uint8_t ddc_hw_inst;
88*b843c749SSergey Zigachev 
89*b843c749SSergey Zigachev 	uint8_t hpd_src;
90*b843c749SSergey Zigachev 
91*b843c749SSergey Zigachev 	uint8_t link_enc_hw_inst;
92*b843c749SSergey Zigachev 
93*b843c749SSergey Zigachev 	bool test_pattern_enabled;
94*b843c749SSergey Zigachev 	union compliance_test_state compliance_test_state;
95*b843c749SSergey Zigachev 
96*b843c749SSergey Zigachev 	void *priv;
97*b843c749SSergey Zigachev 
98*b843c749SSergey Zigachev 	struct ddc_service *ddc;
99*b843c749SSergey Zigachev 
100*b843c749SSergey Zigachev 	bool aux_mode;
101*b843c749SSergey Zigachev 
102*b843c749SSergey Zigachev 	/* Private to DC core */
103*b843c749SSergey Zigachev 
104*b843c749SSergey Zigachev 	const struct dc *dc;
105*b843c749SSergey Zigachev 
106*b843c749SSergey Zigachev 	struct dc_context *ctx;
107*b843c749SSergey Zigachev 
108*b843c749SSergey Zigachev 	struct link_encoder *link_enc;
109*b843c749SSergey Zigachev 	struct graphics_object_id link_id;
110*b843c749SSergey Zigachev 	union ddi_channel_mapping ddi_channel_mapping;
111*b843c749SSergey Zigachev 	struct connector_device_tag_info device_tag;
112*b843c749SSergey Zigachev 	struct dpcd_caps dpcd_caps;
113*b843c749SSergey Zigachev 	unsigned short chip_caps;
114*b843c749SSergey Zigachev 	unsigned int dpcd_sink_count;
115*b843c749SSergey Zigachev 	enum edp_revision edp_revision;
116*b843c749SSergey Zigachev 	bool psr_enabled;
117*b843c749SSergey Zigachev 
118*b843c749SSergey Zigachev 	/* MST record stream using this link */
119*b843c749SSergey Zigachev 	struct link_flags {
120*b843c749SSergey Zigachev 		bool dp_keep_receiver_powered;
121*b843c749SSergey Zigachev 	} wa_flags;
122*b843c749SSergey Zigachev 	struct link_mst_stream_allocation_table mst_stream_alloc_table;
123*b843c749SSergey Zigachev 
124*b843c749SSergey Zigachev 	struct dc_link_status link_status;
125*b843c749SSergey Zigachev 
126*b843c749SSergey Zigachev 	struct link_trace link_trace;
127*b843c749SSergey Zigachev };
128*b843c749SSergey Zigachev 
129*b843c749SSergey Zigachev const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);
130*b843c749SSergey Zigachev 
131*b843c749SSergey Zigachev /*
132*b843c749SSergey Zigachev  * Return an enumerated dc_link.  dc_link order is constant and determined at
133*b843c749SSergey Zigachev  * boot time.  They cannot be created or destroyed.
134*b843c749SSergey Zigachev  * Use dc_get_caps() to get number of links.
135*b843c749SSergey Zigachev  */
dc_get_link_at_index(struct dc * dc,uint32_t link_index)136*b843c749SSergey Zigachev static inline struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index)
137*b843c749SSergey Zigachev {
138*b843c749SSergey Zigachev 	return dc->links[link_index];
139*b843c749SSergey Zigachev }
140*b843c749SSergey Zigachev 
141*b843c749SSergey Zigachev /* Set backlight level of an embedded panel (eDP, LVDS). */
142*b843c749SSergey Zigachev bool dc_link_set_backlight_level(const struct dc_link *dc_link, uint32_t level,
143*b843c749SSergey Zigachev 		uint32_t frame_ramp, const struct dc_stream_state *stream);
144*b843c749SSergey Zigachev 
145*b843c749SSergey Zigachev int dc_link_get_backlight_level(const struct dc_link *dc_link);
146*b843c749SSergey Zigachev 
147*b843c749SSergey Zigachev bool dc_link_set_abm_disable(const struct dc_link *dc_link);
148*b843c749SSergey Zigachev 
149*b843c749SSergey Zigachev bool dc_link_set_psr_enable(const struct dc_link *dc_link, bool enable, bool wait);
150*b843c749SSergey Zigachev 
151*b843c749SSergey Zigachev bool dc_link_get_psr_state(const struct dc_link *dc_link, uint32_t *psr_state);
152*b843c749SSergey Zigachev 
153*b843c749SSergey Zigachev bool dc_link_setup_psr(struct dc_link *dc_link,
154*b843c749SSergey Zigachev 		const struct dc_stream_state *stream, struct psr_config *psr_config,
155*b843c749SSergey Zigachev 		struct psr_context *psr_context);
156*b843c749SSergey Zigachev 
157*b843c749SSergey Zigachev /* Request DC to detect if there is a Panel connected.
158*b843c749SSergey Zigachev  * boot - If this call is during initial boot.
159*b843c749SSergey Zigachev  * Return false for any type of detection failure or MST detection
160*b843c749SSergey Zigachev  * true otherwise. True meaning further action is required (status update
161*b843c749SSergey Zigachev  * and OS notification).
162*b843c749SSergey Zigachev  */
163*b843c749SSergey Zigachev enum dc_detect_reason {
164*b843c749SSergey Zigachev 	DETECT_REASON_BOOT,
165*b843c749SSergey Zigachev 	DETECT_REASON_HPD,
166*b843c749SSergey Zigachev 	DETECT_REASON_HPDRX,
167*b843c749SSergey Zigachev };
168*b843c749SSergey Zigachev 
169*b843c749SSergey Zigachev bool dc_link_detect(struct dc_link *dc_link, enum dc_detect_reason reason);
170*b843c749SSergey Zigachev 
171*b843c749SSergey Zigachev /* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
172*b843c749SSergey Zigachev  * Return:
173*b843c749SSergey Zigachev  * true - Downstream port status changed. DM should call DC to do the
174*b843c749SSergey Zigachev  * detection.
175*b843c749SSergey Zigachev  * false - no change in Downstream port status. No further action required
176*b843c749SSergey Zigachev  * from DM. */
177*b843c749SSergey Zigachev bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
178*b843c749SSergey Zigachev 		union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss);
179*b843c749SSergey Zigachev 
180*b843c749SSergey Zigachev struct dc_sink_init_data;
181*b843c749SSergey Zigachev 
182*b843c749SSergey Zigachev struct dc_sink *dc_link_add_remote_sink(
183*b843c749SSergey Zigachev 		struct dc_link *dc_link,
184*b843c749SSergey Zigachev 		const uint8_t *edid,
185*b843c749SSergey Zigachev 		int len,
186*b843c749SSergey Zigachev 		struct dc_sink_init_data *init_data);
187*b843c749SSergey Zigachev 
188*b843c749SSergey Zigachev void dc_link_remove_remote_sink(
189*b843c749SSergey Zigachev 	struct dc_link *link,
190*b843c749SSergey Zigachev 	struct dc_sink *sink);
191*b843c749SSergey Zigachev 
192*b843c749SSergey Zigachev /* Used by diagnostics for virtual link at the moment */
193*b843c749SSergey Zigachev 
194*b843c749SSergey Zigachev void dc_link_dp_set_drive_settings(
195*b843c749SSergey Zigachev 	struct dc_link *link,
196*b843c749SSergey Zigachev 	struct link_training_settings *lt_settings);
197*b843c749SSergey Zigachev 
198*b843c749SSergey Zigachev enum link_training_result dc_link_dp_perform_link_training(
199*b843c749SSergey Zigachev 	struct dc_link *link,
200*b843c749SSergey Zigachev 	const struct dc_link_settings *link_setting,
201*b843c749SSergey Zigachev 	bool skip_video_pattern);
202*b843c749SSergey Zigachev 
203*b843c749SSergey Zigachev void dc_link_dp_enable_hpd(const struct dc_link *link);
204*b843c749SSergey Zigachev 
205*b843c749SSergey Zigachev void dc_link_dp_disable_hpd(const struct dc_link *link);
206*b843c749SSergey Zigachev 
207*b843c749SSergey Zigachev bool dc_link_dp_set_test_pattern(
208*b843c749SSergey Zigachev 	struct dc_link *link,
209*b843c749SSergey Zigachev 	enum dp_test_pattern test_pattern,
210*b843c749SSergey Zigachev 	const struct link_training_settings *p_link_settings,
211*b843c749SSergey Zigachev 	const unsigned char *p_custom_pattern,
212*b843c749SSergey Zigachev 	unsigned int cust_pattern_size);
213*b843c749SSergey Zigachev 
214*b843c749SSergey Zigachev void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
215*b843c749SSergey Zigachev 
216*b843c749SSergey Zigachev bool dc_link_is_dp_sink_present(struct dc_link *link);
217*b843c749SSergey Zigachev 
218*b843c749SSergey Zigachev bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type);
219*b843c749SSergey Zigachev /*
220*b843c749SSergey Zigachev  * DPCD access interfaces
221*b843c749SSergey Zigachev  */
222*b843c749SSergey Zigachev 
223*b843c749SSergey Zigachev void dc_link_set_drive_settings(struct dc *dc,
224*b843c749SSergey Zigachev 				struct link_training_settings *lt_settings,
225*b843c749SSergey Zigachev 				const struct dc_link *link);
226*b843c749SSergey Zigachev void dc_link_perform_link_training(struct dc *dc,
227*b843c749SSergey Zigachev 				   struct dc_link_settings *link_setting,
228*b843c749SSergey Zigachev 				   bool skip_video_pattern);
229*b843c749SSergey Zigachev void dc_link_set_preferred_link_settings(struct dc *dc,
230*b843c749SSergey Zigachev 					 struct dc_link_settings *link_setting,
231*b843c749SSergey Zigachev 					 struct dc_link *link);
232*b843c749SSergey Zigachev void dc_link_enable_hpd(const struct dc_link *link);
233*b843c749SSergey Zigachev void dc_link_disable_hpd(const struct dc_link *link);
234*b843c749SSergey Zigachev void dc_link_set_test_pattern(struct dc_link *link,
235*b843c749SSergey Zigachev 			enum dp_test_pattern test_pattern,
236*b843c749SSergey Zigachev 			const struct link_training_settings *p_link_settings,
237*b843c749SSergey Zigachev 			const unsigned char *p_custom_pattern,
238*b843c749SSergey Zigachev 			unsigned int cust_pattern_size);
239*b843c749SSergey Zigachev 
240*b843c749SSergey Zigachev bool dc_submit_i2c(
241*b843c749SSergey Zigachev 		struct dc *dc,
242*b843c749SSergey Zigachev 		uint32_t link_index,
243*b843c749SSergey Zigachev 		struct i2c_command *cmd);
244*b843c749SSergey Zigachev 
245*b843c749SSergey Zigachev #endif /* DC_LINK_H_ */
246