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 enc_sdp_line_num {
75 	/* Adaptive Sync SDP */
76 	bool adaptive_sync_line_num_valid;
77 	uint32_t adaptive_sync_line_num;
78 };
79 
80 struct encoder_info_frame {
81 	/* auxiliary video information */
82 	struct dc_info_packet avi;
83 	struct dc_info_packet gamut;
84 	struct dc_info_packet vendor;
85 	struct dc_info_packet hfvsif;
86 	struct dc_info_packet vtem;
87 	/* source product description */
88 	struct dc_info_packet spd;
89 	/* video stream configuration */
90 	struct dc_info_packet vsc;
91 	/* HDR Static MetaData */
92 	struct dc_info_packet hdrsmd;
93 	/* Adaptive Sync SDP*/
94 	struct dc_info_packet adaptive_sync;
95 	struct enc_sdp_line_num sdp_line_num;
96 };
97 
98 struct encoder_unblank_param {
99 	struct dc_link_settings link_settings;
100 	struct dc_crtc_timing timing;
101 	int opp_cnt;
102 };
103 
104 struct encoder_set_dp_phy_pattern_param {
105 	enum dp_test_pattern dp_phy_pattern;
106 	const uint8_t *custom_pattern;
107 	uint32_t custom_pattern_size;
108 	enum dp_panel_mode dp_panel_mode;
109 };
110 
111 struct stream_encoder {
112 	const struct stream_encoder_funcs *funcs;
113 	struct dc_context *ctx;
114 	struct dc_bios *bp;
115 	enum engine_id id;
116 	uint32_t stream_enc_inst;
117 	struct vpg *vpg;
118 	struct afmt *afmt;
119 };
120 
121 struct enc_state {
122 	uint32_t dsc_mode;  // DISABLED  0; 1 or 2 indicate enabled state.
123 	uint32_t dsc_slice_width;
124 	uint32_t sec_gsp_pps_line_num;
125 	uint32_t vbid6_line_reference;
126 	uint32_t vbid6_line_num;
127 	uint32_t sec_gsp_pps_enable;
128 	uint32_t sec_stream_enable;
129 };
130 
131 struct stream_encoder_funcs {
132 	void (*dp_set_stream_attribute)(
133 		struct stream_encoder *enc,
134 		struct dc_crtc_timing *crtc_timing,
135 		enum dc_color_space output_color_space,
136 		bool use_vsc_sdp_for_colorimetry,
137 		uint32_t enable_sdp_splitting);
138 
139 	void (*hdmi_set_stream_attribute)(
140 		struct stream_encoder *enc,
141 		struct dc_crtc_timing *crtc_timing,
142 		int actual_pix_clk_khz,
143 		bool enable_audio);
144 
145 	void (*dvi_set_stream_attribute)(
146 		struct stream_encoder *enc,
147 		struct dc_crtc_timing *crtc_timing,
148 		bool is_dual_link);
149 
150 	void (*lvds_set_stream_attribute)(
151 		struct stream_encoder *enc,
152 		struct dc_crtc_timing *crtc_timing);
153 
154 	void (*set_throttled_vcp_size)(
155 		struct stream_encoder *enc,
156 		struct fixed31_32 avg_time_slots_per_mtp);
157 
158 	void (*update_hdmi_info_packets)(
159 		struct stream_encoder *enc,
160 		const struct encoder_info_frame *info_frame);
161 
162 	void (*stop_hdmi_info_packets)(
163 		struct stream_encoder *enc);
164 
165 	void (*update_dp_info_packets_sdp_line_num)(
166 		struct stream_encoder *enc,
167 		struct encoder_info_frame *info_frame);
168 
169 	void (*update_dp_info_packets)(
170 		struct stream_encoder *enc,
171 		const struct encoder_info_frame *info_frame);
172 
173 	void (*send_immediate_sdp_message)(
174 				struct stream_encoder *enc,
175 				const uint8_t *custom_sdp_message,
176 				unsigned int sdp_message_size);
177 
178 	void (*stop_dp_info_packets)(
179 		struct stream_encoder *enc);
180 
181 	void (*dp_blank)(
182 		struct dc_link *link,
183 		struct stream_encoder *enc);
184 
185 	void (*dp_unblank)(
186 		struct dc_link *link,
187 		struct stream_encoder *enc,
188 		const struct encoder_unblank_param *param);
189 
190 	void (*audio_mute_control)(
191 		struct stream_encoder *enc, bool mute);
192 
193 	void (*dp_audio_setup)(
194 		struct stream_encoder *enc,
195 		unsigned int az_inst,
196 		struct audio_info *info);
197 
198 	void (*dp_audio_enable) (
199 			struct stream_encoder *enc);
200 
201 	void (*dp_audio_disable) (
202 			struct stream_encoder *enc);
203 
204 	void (*hdmi_audio_setup)(
205 		struct stream_encoder *enc,
206 		unsigned int az_inst,
207 		struct audio_info *info,
208 		struct audio_crtc_info *audio_crtc_info);
209 
210 	void (*hdmi_audio_disable) (
211 			struct stream_encoder *enc);
212 
213 	void (*setup_stereo_sync) (
214 			struct stream_encoder *enc,
215 			int tg_inst,
216 			bool enable);
217 
218 	void (*set_avmute)(
219 		struct stream_encoder *enc, bool enable);
220 
221 	void (*dig_connect_to_otg)(
222 		struct stream_encoder *enc,
223 		int tg_inst);
224 
225 	void (*dig_stream_enable)(
226 		struct stream_encoder *enc,
227 		enum signal_type signal,
228 		bool enable);
229 
230 	void (*hdmi_reset_stream_attribute)(
231 		struct stream_encoder *enc);
232 
233 	unsigned int (*dig_source_otg)(
234 		struct stream_encoder *enc);
235 
236 	bool (*dp_get_pixel_format)(
237 		struct stream_encoder *enc,
238 		enum dc_pixel_encoding *encoding,
239 		enum dc_color_depth *depth);
240 
241 	void (*enc_read_state)(struct stream_encoder *enc, struct enc_state *s);
242 
243 	void (*dp_set_dsc_config)(
244 			struct stream_encoder *enc,
245 			enum optc_dsc_mode dsc_mode,
246 			uint32_t dsc_bytes_per_pixel,
247 			uint32_t dsc_slice_width);
248 
249 	void (*dp_set_dsc_pps_info_packet)(struct stream_encoder *enc,
250 				bool enable,
251 				uint8_t *dsc_packed_pps,
252 				bool immediate_update);
253 
254 	void (*set_dynamic_metadata)(struct stream_encoder *enc,
255 			bool enable,
256 			uint32_t hubp_requestor_id,
257 			enum dynamic_metadata_mode dmdata_mode);
258 
259 	/**
260 	 * @dp_set_odm_combine: Sets up DP stream encoder for ODM.
261 	 */
262 	void (*dp_set_odm_combine)(
263 		struct stream_encoder *enc,
264 		bool odm_combine);
265 
266 	uint32_t (*get_fifo_cal_average_level)(
267 		struct stream_encoder *enc);
268 
269 	void (*set_input_mode)(
270 		struct stream_encoder *enc, unsigned int pix_per_container);
271 	void (*enable_fifo)(struct stream_encoder *enc);
272 	void (*disable_fifo)(struct stream_encoder *enc);
273 	void (*map_stream_to_link)(struct stream_encoder *enc, uint32_t stream_enc_inst, uint32_t link_enc_inst);
274 };
275 
276 struct hpo_dp_stream_encoder_state {
277 	uint32_t stream_enc_enabled;
278 	uint32_t vid_stream_enabled;
279 	uint32_t otg_inst;
280 	uint32_t pixel_encoding;
281 	uint32_t component_depth;
282 	uint32_t compressed_format;
283 	uint32_t sdp_enabled;
284 	uint32_t mapped_to_link_enc;
285 };
286 
287 struct hpo_dp_stream_encoder {
288 	const struct hpo_dp_stream_encoder_funcs *funcs;
289 	struct dc_context *ctx;
290 	struct dc_bios *bp;
291 	uint32_t inst;
292 	enum engine_id id;
293 	struct vpg *vpg;
294 	struct apg *apg;
295 };
296 
297 struct hpo_dp_stream_encoder_funcs {
298 	void (*enable_stream)(
299 			struct hpo_dp_stream_encoder *enc);
300 
301 	void (*dp_unblank)(
302 			struct hpo_dp_stream_encoder *enc,
303 			uint32_t stream_source);
304 
305 	void (*dp_blank)(
306 			struct hpo_dp_stream_encoder *enc);
307 
308 	void (*disable)(
309 			struct hpo_dp_stream_encoder *enc);
310 
311 	void (*set_stream_attribute)(
312 		struct hpo_dp_stream_encoder *enc,
313 		struct dc_crtc_timing *crtc_timing,
314 		enum dc_color_space output_color_space,
315 		bool use_vsc_sdp_for_colorimetry,
316 		bool compressed_format,
317 		bool double_buffer_en);
318 
319 	void (*update_dp_info_packets_sdp_line_num)(
320 		struct hpo_dp_stream_encoder *enc,
321 		struct encoder_info_frame *info_frame);
322 
323 	void (*update_dp_info_packets)(
324 		struct hpo_dp_stream_encoder *enc,
325 		const struct encoder_info_frame *info_frame);
326 
327 	void (*stop_dp_info_packets)(
328 		struct hpo_dp_stream_encoder *enc);
329 
330 	void (*dp_set_dsc_pps_info_packet)(
331 			struct hpo_dp_stream_encoder *enc,
332 			bool enable,
333 			uint8_t *dsc_packed_pps,
334 			bool immediate_update);
335 
336 	void (*map_stream_to_link)(
337 			struct hpo_dp_stream_encoder *enc,
338 			uint32_t stream_enc_inst,
339 			uint32_t link_enc_inst);
340 
341 	void (*dp_audio_setup)(
342 			struct hpo_dp_stream_encoder *enc,
343 			unsigned int az_inst,
344 			struct audio_info *info);
345 
346 	void (*dp_audio_enable)(
347 			struct hpo_dp_stream_encoder *enc);
348 
349 	void (*dp_audio_disable)(
350 			struct hpo_dp_stream_encoder *enc);
351 
352 	void (*read_state)(
353 			struct hpo_dp_stream_encoder *enc,
354 			struct hpo_dp_stream_encoder_state *state);
355 
356 	void (*set_hblank_min_symbol_width)(
357 			struct hpo_dp_stream_encoder *enc,
358 			uint16_t width);
359 };
360 
361 #endif /* STREAM_ENCODER_H_ */
362