1/*	$NetBSD: stream_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 * stream_encoder.h
27 *
28 */
29
30#ifndef STREAM_ENCODER_H_
31#define STREAM_ENCODER_H_
32
33#include "audio_types.h"
34#include "hw_shared.h"
35
36struct dc_bios;
37struct dc_context;
38struct dc_crtc_timing;
39
40enum dp_pixel_encoding_type {
41	DP_PIXEL_ENCODING_TYPE_RGB444		= 0x00000000,
42	DP_PIXEL_ENCODING_TYPE_YCBCR422		= 0x00000001,
43	DP_PIXEL_ENCODING_TYPE_YCBCR444		= 0x00000002,
44	DP_PIXEL_ENCODING_TYPE_RGB_WIDE_GAMUT	= 0x00000003,
45	DP_PIXEL_ENCODING_TYPE_Y_ONLY		= 0x00000004,
46	DP_PIXEL_ENCODING_TYPE_YCBCR420		= 0x00000005
47};
48
49enum dp_component_depth {
50	DP_COMPONENT_PIXEL_DEPTH_6BPC		= 0x00000000,
51	DP_COMPONENT_PIXEL_DEPTH_8BPC		= 0x00000001,
52	DP_COMPONENT_PIXEL_DEPTH_10BPC		= 0x00000002,
53	DP_COMPONENT_PIXEL_DEPTH_12BPC		= 0x00000003,
54	DP_COMPONENT_PIXEL_DEPTH_16BPC		= 0x00000004
55};
56
57struct audio_clock_info {
58	/* pixel clock frequency*/
59	uint32_t pixel_clock_in_10khz;
60	/* N - 32KHz audio */
61	uint32_t n_32khz;
62	/* CTS - 32KHz audio*/
63	uint32_t cts_32khz;
64	uint32_t n_44khz;
65	uint32_t cts_44khz;
66	uint32_t n_48khz;
67	uint32_t cts_48khz;
68};
69
70enum dynamic_metadata_mode {
71	dmdata_dp,
72	dmdata_hdmi,
73	dmdata_dolby_vision
74};
75
76struct encoder_info_frame {
77	/* auxiliary video information */
78	struct dc_info_packet avi;
79	struct dc_info_packet gamut;
80	struct dc_info_packet vendor;
81	struct dc_info_packet hfvsif;
82	/* source product description */
83	struct dc_info_packet spd;
84	/* video stream configuration */
85	struct dc_info_packet vsc;
86	/* HDR Static MetaData */
87	struct dc_info_packet hdrsmd;
88};
89
90struct encoder_unblank_param {
91	struct dc_link_settings link_settings;
92	struct dc_crtc_timing timing;
93	int opp_cnt;
94};
95
96struct encoder_set_dp_phy_pattern_param {
97	enum dp_test_pattern dp_phy_pattern;
98	const uint8_t *custom_pattern;
99	uint32_t custom_pattern_size;
100	enum dp_panel_mode dp_panel_mode;
101};
102
103struct stream_encoder {
104	const struct stream_encoder_funcs *funcs;
105	struct dc_context *ctx;
106	struct dc_bios *bp;
107	enum engine_id id;
108};
109
110struct enc_state {
111	uint32_t dsc_mode;  // DISABLED  0; 1 or 2 indicate enabled state.
112	uint32_t dsc_slice_width;
113	uint32_t sec_gsp_pps_line_num;
114	uint32_t vbid6_line_reference;
115	uint32_t vbid6_line_num;
116	uint32_t sec_gsp_pps_enable;
117	uint32_t sec_stream_enable;
118};
119
120struct stream_encoder_funcs {
121	void (*dp_set_stream_attribute)(
122		struct stream_encoder *enc,
123		struct dc_crtc_timing *crtc_timing,
124		enum dc_color_space output_color_space,
125		bool use_vsc_sdp_for_colorimetry,
126		uint32_t enable_sdp_splitting);
127
128	void (*hdmi_set_stream_attribute)(
129		struct stream_encoder *enc,
130		struct dc_crtc_timing *crtc_timing,
131		int actual_pix_clk_khz,
132		bool enable_audio);
133
134	void (*dvi_set_stream_attribute)(
135		struct stream_encoder *enc,
136		struct dc_crtc_timing *crtc_timing,
137		bool is_dual_link);
138
139	void (*lvds_set_stream_attribute)(
140		struct stream_encoder *enc,
141		struct dc_crtc_timing *crtc_timing);
142
143	void (*set_mst_bandwidth)(
144		struct stream_encoder *enc,
145		struct fixed31_32 avg_time_slots_per_mtp);
146
147	void (*update_hdmi_info_packets)(
148		struct stream_encoder *enc,
149		const struct encoder_info_frame *info_frame);
150
151	void (*stop_hdmi_info_packets)(
152		struct stream_encoder *enc);
153
154	void (*update_dp_info_packets)(
155		struct stream_encoder *enc,
156		const struct encoder_info_frame *info_frame);
157
158	void (*send_immediate_sdp_message)(
159				struct stream_encoder *enc,
160				const uint8_t *custom_sdp_message,
161				unsigned int sdp_message_size);
162
163	void (*stop_dp_info_packets)(
164		struct stream_encoder *enc);
165
166	void (*dp_blank)(
167		struct stream_encoder *enc);
168
169	void (*dp_unblank)(
170		struct stream_encoder *enc,
171		const struct encoder_unblank_param *param);
172
173	void (*audio_mute_control)(
174		struct stream_encoder *enc, bool mute);
175
176	void (*dp_audio_setup)(
177		struct stream_encoder *enc,
178		unsigned int az_inst,
179		struct audio_info *info);
180
181	void (*dp_audio_enable) (
182			struct stream_encoder *enc);
183
184	void (*dp_audio_disable) (
185			struct stream_encoder *enc);
186
187	void (*hdmi_audio_setup)(
188		struct stream_encoder *enc,
189		unsigned int az_inst,
190		struct audio_info *info,
191		struct audio_crtc_info *audio_crtc_info);
192
193	void (*hdmi_audio_disable) (
194			struct stream_encoder *enc);
195
196	void (*setup_stereo_sync) (
197			struct stream_encoder *enc,
198			int tg_inst,
199			bool enable);
200
201	void (*set_avmute)(
202		struct stream_encoder *enc, bool enable);
203
204	void (*dig_connect_to_otg)(
205		struct stream_encoder *enc,
206		int tg_inst);
207
208	void (*hdmi_reset_stream_attribute)(
209		struct stream_encoder *enc);
210
211	unsigned int (*dig_source_otg)(
212		struct stream_encoder *enc);
213
214	bool (*dp_get_pixel_format)(
215		struct stream_encoder *enc,
216		enum dc_pixel_encoding *encoding,
217		enum dc_color_depth *depth);
218
219	void (*enc_read_state)(struct stream_encoder *enc, struct enc_state *s);
220
221	void (*dp_set_dsc_config)(
222			struct stream_encoder *enc,
223			enum optc_dsc_mode dsc_mode,
224			uint32_t dsc_bytes_per_pixel,
225			uint32_t dsc_slice_width);
226
227	void (*dp_set_dsc_pps_info_packet)(struct stream_encoder *enc,
228				bool enable,
229				uint8_t *dsc_packed_pps);
230
231	void (*set_dynamic_metadata)(struct stream_encoder *enc,
232			bool enable,
233			uint32_t hubp_requestor_id,
234			enum dynamic_metadata_mode dmdata_mode);
235
236	void (*dp_set_odm_combine)(
237		struct stream_encoder *enc,
238		bool odm_combine);
239};
240
241#endif /* STREAM_ENCODER_H_ */
242