1 /*
2  * Copyright 2017 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  */
23 /*
24  * stream_encoder.h
25  *
26  */
27 
28 #ifndef STREAM_ENCODER_H_
29 #define STREAM_ENCODER_H_
30 
31 #include "audio_types.h"
32 #include "hw_shared.h"
33 
34 struct dc_bios;
35 struct dc_context;
36 struct dc_crtc_timing;
37 
38 enum dp_pixel_encoding_type {
39 	DP_PIXEL_ENCODING_TYPE_RGB444		= 0x00000000,
40 	DP_PIXEL_ENCODING_TYPE_YCBCR422		= 0x00000001,
41 	DP_PIXEL_ENCODING_TYPE_YCBCR444		= 0x00000002,
42 	DP_PIXEL_ENCODING_TYPE_RGB_WIDE_GAMUT	= 0x00000003,
43 	DP_PIXEL_ENCODING_TYPE_Y_ONLY		= 0x00000004,
44 	DP_PIXEL_ENCODING_TYPE_YCBCR420		= 0x00000005
45 };
46 
47 enum dp_component_depth {
48 	DP_COMPONENT_PIXEL_DEPTH_6BPC		= 0x00000000,
49 	DP_COMPONENT_PIXEL_DEPTH_8BPC		= 0x00000001,
50 	DP_COMPONENT_PIXEL_DEPTH_10BPC		= 0x00000002,
51 	DP_COMPONENT_PIXEL_DEPTH_12BPC		= 0x00000003,
52 	DP_COMPONENT_PIXEL_DEPTH_16BPC		= 0x00000004
53 };
54 
55 struct audio_clock_info {
56 	/* pixel clock frequency*/
57 	uint32_t pixel_clock_in_10khz;
58 	/* N - 32KHz audio */
59 	uint32_t n_32khz;
60 	/* CTS - 32KHz audio*/
61 	uint32_t cts_32khz;
62 	uint32_t n_44khz;
63 	uint32_t cts_44khz;
64 	uint32_t n_48khz;
65 	uint32_t cts_48khz;
66 };
67 
68 enum dynamic_metadata_mode {
69 	dmdata_dp,
70 	dmdata_hdmi,
71 	dmdata_dolby_vision
72 };
73 
74 struct encoder_info_frame {
75 	/* auxiliary video information */
76 	struct dc_info_packet avi;
77 	struct dc_info_packet gamut;
78 	struct dc_info_packet vendor;
79 	struct dc_info_packet hfvsif;
80 	/* source product description */
81 	struct dc_info_packet spd;
82 	/* video stream configuration */
83 	struct dc_info_packet vsc;
84 	/* HDR Static MetaData */
85 	struct dc_info_packet hdrsmd;
86 };
87 
88 struct encoder_unblank_param {
89 	struct dc_link_settings link_settings;
90 	struct dc_crtc_timing timing;
91 	int opp_cnt;
92 };
93 
94 struct encoder_set_dp_phy_pattern_param {
95 	enum dp_test_pattern dp_phy_pattern;
96 	const uint8_t *custom_pattern;
97 	uint32_t custom_pattern_size;
98 	enum dp_panel_mode dp_panel_mode;
99 };
100 
101 struct stream_encoder {
102 	const struct stream_encoder_funcs *funcs;
103 	struct dc_context *ctx;
104 	struct dc_bios *bp;
105 	enum engine_id id;
106 	uint32_t stream_enc_inst;
107 	struct vpg *vpg;
108 	struct afmt *afmt;
109 };
110 
111 struct enc_state {
112 	uint32_t dsc_mode;  // DISABLED  0; 1 or 2 indicate enabled state.
113 	uint32_t dsc_slice_width;
114 	uint32_t sec_gsp_pps_line_num;
115 	uint32_t vbid6_line_reference;
116 	uint32_t vbid6_line_num;
117 	uint32_t sec_gsp_pps_enable;
118 	uint32_t sec_stream_enable;
119 };
120 
121 struct stream_encoder_funcs {
122 	void (*dp_set_stream_attribute)(
123 		struct stream_encoder *enc,
124 		struct dc_crtc_timing *crtc_timing,
125 		enum dc_color_space output_color_space,
126 		bool use_vsc_sdp_for_colorimetry,
127 		uint32_t enable_sdp_splitting);
128 
129 	void (*hdmi_set_stream_attribute)(
130 		struct stream_encoder *enc,
131 		struct dc_crtc_timing *crtc_timing,
132 		int actual_pix_clk_khz,
133 		bool enable_audio);
134 
135 	void (*dvi_set_stream_attribute)(
136 		struct stream_encoder *enc,
137 		struct dc_crtc_timing *crtc_timing,
138 		bool is_dual_link);
139 
140 	void (*lvds_set_stream_attribute)(
141 		struct stream_encoder *enc,
142 		struct dc_crtc_timing *crtc_timing);
143 
144 	void (*set_throttled_vcp_size)(
145 		struct stream_encoder *enc,
146 		struct fixed31_32 avg_time_slots_per_mtp);
147 
148 	void (*update_hdmi_info_packets)(
149 		struct stream_encoder *enc,
150 		const struct encoder_info_frame *info_frame);
151 
152 	void (*stop_hdmi_info_packets)(
153 		struct stream_encoder *enc);
154 
155 	void (*update_dp_info_packets)(
156 		struct stream_encoder *enc,
157 		const struct encoder_info_frame *info_frame);
158 
159 	void (*send_immediate_sdp_message)(
160 				struct stream_encoder *enc,
161 				const uint8_t *custom_sdp_message,
162 				unsigned int sdp_message_size);
163 
164 	void (*stop_dp_info_packets)(
165 		struct stream_encoder *enc);
166 
167 	void (*dp_blank)(
168 		struct dc_link *link,
169 		struct stream_encoder *enc);
170 
171 	void (*dp_unblank)(
172 		struct dc_link *link,
173 		struct stream_encoder *enc,
174 		const struct encoder_unblank_param *param);
175 
176 	void (*audio_mute_control)(
177 		struct stream_encoder *enc, bool mute);
178 
179 	void (*dp_audio_setup)(
180 		struct stream_encoder *enc,
181 		unsigned int az_inst,
182 		struct audio_info *info);
183 
184 	void (*dp_audio_enable) (
185 			struct stream_encoder *enc);
186 
187 	void (*dp_audio_disable) (
188 			struct stream_encoder *enc);
189 
190 	void (*hdmi_audio_setup)(
191 		struct stream_encoder *enc,
192 		unsigned int az_inst,
193 		struct audio_info *info,
194 		struct audio_crtc_info *audio_crtc_info);
195 
196 	void (*hdmi_audio_disable) (
197 			struct stream_encoder *enc);
198 
199 	void (*setup_stereo_sync) (
200 			struct stream_encoder *enc,
201 			int tg_inst,
202 			bool enable);
203 
204 	void (*set_avmute)(
205 		struct stream_encoder *enc, bool enable);
206 
207 	void (*dig_connect_to_otg)(
208 		struct stream_encoder *enc,
209 		int tg_inst);
210 
211 	void (*hdmi_reset_stream_attribute)(
212 		struct stream_encoder *enc);
213 
214 	unsigned int (*dig_source_otg)(
215 		struct stream_encoder *enc);
216 
217 	bool (*dp_get_pixel_format)(
218 		struct stream_encoder *enc,
219 		enum dc_pixel_encoding *encoding,
220 		enum dc_color_depth *depth);
221 
222 	void (*enc_read_state)(struct stream_encoder *enc, struct enc_state *s);
223 
224 	void (*dp_set_dsc_config)(
225 			struct stream_encoder *enc,
226 			enum optc_dsc_mode dsc_mode,
227 			uint32_t dsc_bytes_per_pixel,
228 			uint32_t dsc_slice_width);
229 
230 	void (*dp_set_dsc_pps_info_packet)(struct stream_encoder *enc,
231 				bool enable,
232 				uint8_t *dsc_packed_pps,
233 				bool immediate_update);
234 
235 	void (*set_dynamic_metadata)(struct stream_encoder *enc,
236 			bool enable,
237 			uint32_t hubp_requestor_id,
238 			enum dynamic_metadata_mode dmdata_mode);
239 
240 	void (*dp_set_odm_combine)(
241 		struct stream_encoder *enc,
242 		bool odm_combine);
243 
244 	uint32_t (*get_fifo_cal_average_level)(
245 		struct stream_encoder *enc);
246 };
247 
248 struct hpo_dp_stream_encoder_state {
249 	uint32_t stream_enc_enabled;
250 	uint32_t vid_stream_enabled;
251 	uint32_t otg_inst;
252 	uint32_t pixel_encoding;
253 	uint32_t component_depth;
254 	uint32_t compressed_format;
255 	uint32_t sdp_enabled;
256 	uint32_t mapped_to_link_enc;
257 };
258 
259 struct hpo_dp_stream_encoder {
260 	const struct hpo_dp_stream_encoder_funcs *funcs;
261 	struct dc_context *ctx;
262 	struct dc_bios *bp;
263 	uint32_t inst;
264 	enum engine_id id;
265 	struct vpg *vpg;
266 	struct apg *apg;
267 };
268 
269 struct hpo_dp_stream_encoder_funcs {
270 	void (*enable_stream)(
271 			struct hpo_dp_stream_encoder *enc);
272 
273 	void (*dp_unblank)(
274 			struct hpo_dp_stream_encoder *enc,
275 			uint32_t stream_source);
276 
277 	void (*dp_blank)(
278 			struct hpo_dp_stream_encoder *enc);
279 
280 	void (*disable)(
281 			struct hpo_dp_stream_encoder *enc);
282 
283 	void (*set_stream_attribute)(
284 		struct hpo_dp_stream_encoder *enc,
285 		struct dc_crtc_timing *crtc_timing,
286 		enum dc_color_space output_color_space,
287 		bool use_vsc_sdp_for_colorimetry,
288 		bool compressed_format,
289 		bool double_buffer_en);
290 
291 	void (*update_dp_info_packets)(
292 		struct hpo_dp_stream_encoder *enc,
293 		const struct encoder_info_frame *info_frame);
294 
295 	void (*stop_dp_info_packets)(
296 		struct hpo_dp_stream_encoder *enc);
297 
298 	void (*dp_set_dsc_pps_info_packet)(
299 			struct hpo_dp_stream_encoder *enc,
300 			bool enable,
301 			uint8_t *dsc_packed_pps,
302 			bool immediate_update);
303 
304 	void (*map_stream_to_link)(
305 			struct hpo_dp_stream_encoder *enc,
306 			uint32_t stream_enc_inst,
307 			uint32_t link_enc_inst);
308 
309 	void (*audio_mute_control)(
310 			struct hpo_dp_stream_encoder *enc, bool mute);
311 
312 	void (*dp_audio_setup)(
313 			struct hpo_dp_stream_encoder *enc,
314 			unsigned int az_inst,
315 			struct audio_info *info);
316 
317 	void (*dp_audio_enable)(
318 			struct hpo_dp_stream_encoder *enc);
319 
320 	void (*dp_audio_disable)(
321 			struct hpo_dp_stream_encoder *enc);
322 
323 	void (*read_state)(
324 			struct hpo_dp_stream_encoder *enc,
325 			struct hpo_dp_stream_encoder_state *state);
326 
327 	void (*set_hblank_min_symbol_width)(
328 			struct hpo_dp_stream_encoder *enc,
329 			uint16_t width);
330 };
331 
332 #endif /* STREAM_ENCODER_H_ */
333