1 /*	$NetBSD: link_encoder.h,v 1.2 2021/12/18 23:45:05 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2017 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25 /*
26  * link_encoder.h
27  *
28  *  Created on: Oct 6, 2015
29  *      Author: yonsun
30  */
31 
32 #ifndef LINK_ENCODER_H_
33 #define LINK_ENCODER_H_
34 
35 #include "grph_object_defs.h"
36 #include "signal_types.h"
37 #include "dc_types.h"
38 
39 struct dc_context;
40 struct encoder_set_dp_phy_pattern_param;
41 struct link_mst_stream_allocation_table;
42 struct dc_link_settings;
43 struct link_training_settings;
44 struct pipe_ctx;
45 
46 struct encoder_init_data {
47 	enum channel_id channel;
48 	struct graphics_object_id connector;
49 	enum hpd_source_id hpd_source;
50 	/* TODO: in DAL2, here was pointer to EventManagerInterface */
51 	struct graphics_object_id encoder;
52 	struct dc_context *ctx;
53 	enum transmitter transmitter;
54 };
55 
56 struct encoder_feature_support {
57 	union {
58 		struct {
59 			uint32_t IS_HBR2_CAPABLE:1;
60 			uint32_t IS_HBR3_CAPABLE:1;
61 			uint32_t IS_TPS3_CAPABLE:1;
62 			uint32_t IS_TPS4_CAPABLE:1;
63 			uint32_t HDMI_6GB_EN:1;
64 			uint32_t DP_IS_USB_C:1;
65 		} bits;
66 		uint32_t raw;
67 	} flags;
68 
69 	enum dc_color_depth max_hdmi_deep_color;
70 	unsigned int max_hdmi_pixel_clock;
71 	bool hdmi_ycbcr420_supported;
72 	bool dp_ycbcr420_supported;
73 };
74 
75 union dpcd_psr_configuration {
76 	struct {
77 		unsigned char ENABLE                    : 1;
78 		unsigned char TRANSMITTER_ACTIVE_IN_PSR : 1;
79 		unsigned char CRC_VERIFICATION          : 1;
80 		unsigned char FRAME_CAPTURE_INDICATION  : 1;
81 		/* For eDP 1.4, PSR v2*/
82 		unsigned char LINE_CAPTURE_INDICATION   : 1;
83 		/* For eDP 1.4, PSR v2*/
84 		unsigned char IRQ_HPD_WITH_CRC_ERROR    : 1;
85 		unsigned char RESERVED                  : 2;
86 	} bits;
87 	unsigned char raw;
88 };
89 
90 union psr_error_status {
91 	struct {
92 		unsigned char LINK_CRC_ERROR        :1;
93 		unsigned char RFB_STORAGE_ERROR     :1;
94 		unsigned char RESERVED              :6;
95 	} bits;
96 	unsigned char raw;
97 };
98 
99 union psr_sink_psr_status {
100 	struct {
101 	unsigned char SINK_SELF_REFRESH_STATUS  :3;
102 	unsigned char RESERVED                  :5;
103 	} bits;
104 	unsigned char raw;
105 };
106 
107 struct link_encoder {
108 	const struct link_encoder_funcs *funcs;
109 	int32_t aux_channel_offset;
110 	struct dc_context *ctx;
111 	struct graphics_object_id id;
112 	struct graphics_object_id connector;
113 	uint32_t output_signals;
114 	enum engine_id preferred_engine;
115 	struct encoder_feature_support features;
116 	enum transmitter transmitter;
117 	enum hpd_source_id hpd_source;
118 	bool usbc_combo_phy;
119 };
120 
121 struct link_enc_state {
122 
123 		uint32_t dphy_fec_en;
124 		uint32_t dphy_fec_ready_shadow;
125 		uint32_t dphy_fec_active_status;
126 		uint32_t dp_link_training_complete;
127 
128 };
129 
130 struct link_encoder_funcs {
131 	void (*read_state)(
132 			struct link_encoder *enc, struct link_enc_state *s);
133 	bool (*validate_output_with_stream)(
134 		struct link_encoder *enc, const struct dc_stream_state *stream);
135 	void (*hw_init)(struct link_encoder *enc);
136 	void (*setup)(struct link_encoder *enc,
137 		enum signal_type signal);
138 	void (*enable_tmds_output)(struct link_encoder *enc,
139 		enum clock_source_id clock_source,
140 		enum dc_color_depth color_depth,
141 		enum signal_type signal,
142 		uint32_t pixel_clock);
143 	void (*enable_dp_output)(struct link_encoder *enc,
144 		const struct dc_link_settings *link_settings,
145 		enum clock_source_id clock_source);
146 	void (*enable_dp_mst_output)(struct link_encoder *enc,
147 		const struct dc_link_settings *link_settings,
148 		enum clock_source_id clock_source);
149 	void (*enable_lvds_output)(struct link_encoder *enc,
150 		enum clock_source_id clock_source,
151 		uint32_t pixel_clock);
152 	void (*disable_output)(struct link_encoder *link_enc,
153 		enum signal_type signal);
154 	void (*dp_set_lane_settings)(struct link_encoder *enc,
155 		const struct link_training_settings *link_settings);
156 	void (*dp_set_phy_pattern)(struct link_encoder *enc,
157 		const struct encoder_set_dp_phy_pattern_param *para);
158 	void (*update_mst_stream_allocation_table)(
159 		struct link_encoder *enc,
160 		const struct link_mst_stream_allocation_table *table);
161 	void (*psr_program_dp_dphy_fast_training)(struct link_encoder *enc,
162 			bool exit_link_training_required);
163 	void (*psr_program_secondary_packet)(struct link_encoder *enc,
164 				unsigned int sdp_transmit_line_num_deadline);
165 	void (*connect_dig_be_to_fe)(struct link_encoder *enc,
166 		enum engine_id engine,
167 		bool connect);
168 	void (*enable_hpd)(struct link_encoder *enc);
169 	void (*disable_hpd)(struct link_encoder *enc);
170 	bool (*is_dig_enabled)(struct link_encoder *enc);
171 	unsigned int (*get_dig_frontend)(struct link_encoder *enc);
172 	void (*destroy)(struct link_encoder **enc);
173 
174 	void (*fec_set_enable)(struct link_encoder *enc,
175 		bool enable);
176 
177 	void (*fec_set_ready)(struct link_encoder *enc,
178 		bool ready);
179 
180 	bool (*fec_is_active)(struct link_encoder *enc);
181 	bool (*is_in_alt_mode) (struct link_encoder *enc);
182 
183 	void (*get_max_link_cap)(struct link_encoder *enc,
184 		struct dc_link_settings *link_settings);
185 
186 	enum signal_type (*get_dig_mode)(
187 		struct link_encoder *enc);
188 };
189 
190 #endif /* LINK_ENCODER_H_ */
191