1 /*
2  * Copyright 2012-15 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  * Authors: AMD
23  *
24  */
25 
26 #ifndef __DAL_TIMING_GENERATOR_TYPES_H__
27 #define __DAL_TIMING_GENERATOR_TYPES_H__
28 
29 #include "hw_shared.h"
30 
31 struct dc_bios;
32 
33 /* Contains CRTC vertical/horizontal pixel counters */
34 struct crtc_position {
35 	int32_t vertical_count;
36 	int32_t horizontal_count;
37 	int32_t nominal_vcount;
38 };
39 
40 struct dcp_gsl_params {
41 	int gsl_group;
42 	int gsl_master;
43 };
44 
45 struct gsl_params {
46 	int gsl0_en;
47 	int gsl1_en;
48 	int gsl2_en;
49 	int gsl_master_en;
50 	int gsl_master_mode;
51 	int master_update_lock_gsl_en;
52 	int gsl_window_start_x;
53 	int gsl_window_end_x;
54 	int gsl_window_start_y;
55 	int gsl_window_end_y;
56 };
57 
58 /* define the structure of Dynamic Refresh Mode */
59 struct drr_params {
60 	uint32_t vertical_total_min;
61 	uint32_t vertical_total_max;
62 	uint32_t vertical_total_mid;
63 	uint32_t vertical_total_mid_frame_num;
64 	bool immediate_flip;
65 };
66 
67 #define LEFT_EYE_3D_PRIMARY_SURFACE 1
68 #define RIGHT_EYE_3D_PRIMARY_SURFACE 0
69 
70 enum crtc_state {
71 	CRTC_STATE_VBLANK = 0,
72 	CRTC_STATE_VACTIVE
73 };
74 
75 struct vupdate_keepout_params {
76 	int start_offset;
77 	int end_offset;
78 	int enable;
79 };
80 
81 struct crtc_stereo_flags {
82 	uint8_t PROGRAM_STEREO         : 1;
83 	uint8_t PROGRAM_POLARITY       : 1;
84 	uint8_t RIGHT_EYE_POLARITY     : 1;
85 	uint8_t FRAME_PACKED           : 1;
86 	uint8_t DISABLE_STEREO_DP_SYNC : 1;
87 };
88 
89 enum crc_selection {
90 	/* Order must match values expected by hardware */
91 	UNION_WINDOW_A_B = 0,
92 	UNION_WINDOW_A_NOT_B,
93 	UNION_WINDOW_NOT_A_B,
94 	UNION_WINDOW_NOT_A_NOT_B,
95 	INTERSECT_WINDOW_A_B,
96 	INTERSECT_WINDOW_A_NOT_B,
97 	INTERSECT_WINDOW_NOT_A_B,
98 	INTERSECT_WINDOW_NOT_A_NOT_B,
99 };
100 
101 enum otg_out_mux_dest {
102 	OUT_MUX_DIO = 0,
103 };
104 
105 enum h_timing_div_mode {
106 	H_TIMING_NO_DIV,
107 	H_TIMING_DIV_BY2,
108 	H_TIMING_RESERVED,
109 	H_TIMING_DIV_BY4,
110 };
111 
112 struct crc_params {
113 	/* Regions used to calculate CRC*/
114 	uint16_t windowa_x_start;
115 	uint16_t windowa_x_end;
116 	uint16_t windowa_y_start;
117 	uint16_t windowa_y_end;
118 
119 	uint16_t windowb_x_start;
120 	uint16_t windowb_x_end;
121 	uint16_t windowb_y_start;
122 	uint16_t windowb_y_end;
123 
124 	enum crc_selection selection;
125 
126 	uint8_t dsc_mode;
127 	uint8_t odm_mode;
128 
129 	bool continuous_mode;
130 	bool enable;
131 };
132 
133 struct timing_generator {
134 	const struct timing_generator_funcs *funcs;
135 	struct dc_bios *bp;
136 	struct dc_context *ctx;
137 	int inst;
138 };
139 
140 struct dc_crtc_timing;
141 
142 struct drr_params;
143 
144 
145 struct timing_generator_funcs {
146 	bool (*validate_timing)(struct timing_generator *tg,
147 							const struct dc_crtc_timing *timing);
148 	void (*program_timing)(struct timing_generator *tg,
149 							const struct dc_crtc_timing *timing,
150 							int vready_offset,
151 							int vstartup_start,
152 							int vupdate_offset,
153 							int vupdate_width,
154 							const enum signal_type signal,
155 							bool use_vbios
156 	);
157 	void (*setup_vertical_interrupt0)(
158 			struct timing_generator *optc,
159 			uint32_t start_line,
160 			uint32_t end_line);
161 	void (*setup_vertical_interrupt1)(
162 			struct timing_generator *optc,
163 			uint32_t start_line);
164 	void (*setup_vertical_interrupt2)(
165 			struct timing_generator *optc,
166 			uint32_t start_line);
167 
168 	bool (*enable_crtc)(struct timing_generator *tg);
169 	bool (*disable_crtc)(struct timing_generator *tg);
170 	bool (*is_counter_moving)(struct timing_generator *tg);
171 	void (*get_position)(struct timing_generator *tg,
172 				struct crtc_position *position);
173 
174 	uint32_t (*get_frame_count)(struct timing_generator *tg);
175 	void (*get_scanoutpos)(
176 		struct timing_generator *tg,
177 		uint32_t *v_blank_start,
178 		uint32_t *v_blank_end,
179 		uint32_t *h_position,
180 		uint32_t *v_position);
181 	bool (*get_otg_active_size)(struct timing_generator *optc,
182 			uint32_t *otg_active_width,
183 			uint32_t *otg_active_height);
184 	bool (*is_matching_timing)(struct timing_generator *tg,
185 			const struct dc_crtc_timing *otg_timing);
186 	void (*set_early_control)(struct timing_generator *tg,
187 							   uint32_t early_cntl);
188 	void (*wait_for_state)(struct timing_generator *tg,
189 							enum crtc_state state);
190 	void (*set_blank)(struct timing_generator *tg,
191 					bool enable_blanking);
192 	bool (*is_blanked)(struct timing_generator *tg);
193 	void (*set_overscan_blank_color) (struct timing_generator *tg, const struct tg_color *color);
194 	void (*set_blank_color)(struct timing_generator *tg, const struct tg_color *color);
195 	void (*set_colors)(struct timing_generator *tg,
196 						const struct tg_color *blank_color,
197 						const struct tg_color *overscan_color);
198 
199 	void (*disable_vga)(struct timing_generator *tg);
200 	bool (*did_triggered_reset_occur)(struct timing_generator *tg);
201 	void (*setup_global_swap_lock)(struct timing_generator *tg,
202 							const struct dcp_gsl_params *gsl_params);
203 	void (*unlock)(struct timing_generator *tg);
204 	void (*lock)(struct timing_generator *tg);
205 	void (*lock_doublebuffer_disable)(struct timing_generator *tg);
206 	void (*lock_doublebuffer_enable)(struct timing_generator *tg);
207 	void(*triplebuffer_unlock)(struct timing_generator *tg);
208 	void(*triplebuffer_lock)(struct timing_generator *tg);
209 	void (*enable_reset_trigger)(struct timing_generator *tg,
210 				     int source_tg_inst);
211 	void (*enable_crtc_reset)(struct timing_generator *tg,
212 				  int source_tg_inst,
213 				  struct crtc_trigger_info *crtc_tp);
214 	void (*disable_reset_trigger)(struct timing_generator *tg);
215 	void (*tear_down_global_swap_lock)(struct timing_generator *tg);
216 	void (*enable_advanced_request)(struct timing_generator *tg,
217 					bool enable, const struct dc_crtc_timing *timing);
218 	void (*set_drr)(struct timing_generator *tg, const struct drr_params *params);
219 	void (*set_static_screen_control)(struct timing_generator *tg,
220 						uint32_t event_triggers,
221 						uint32_t num_frames);
222 	void (*set_test_pattern)(
223 		struct timing_generator *tg,
224 		enum controller_dp_test_pattern test_pattern,
225 		enum dc_color_depth color_depth);
226 
227 	bool (*arm_vert_intr)(struct timing_generator *tg, uint8_t width);
228 
229 	void (*program_global_sync)(struct timing_generator *tg,
230 			int vready_offset,
231 			int vstartup_start,
232 			int vupdate_offset,
233 			int vupdate_width);
234 	void (*enable_optc_clock)(struct timing_generator *tg, bool enable);
235 	void (*program_stereo)(struct timing_generator *tg,
236 		const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags);
237 	bool (*is_stereo_left_eye)(struct timing_generator *tg);
238 
239 	void (*set_blank_data_double_buffer)(struct timing_generator *tg, bool enable);
240 
241 	void (*tg_init)(struct timing_generator *tg);
242 	bool (*is_tg_enabled)(struct timing_generator *tg);
243 	bool (*is_optc_underflow_occurred)(struct timing_generator *tg);
244 	void (*clear_optc_underflow)(struct timing_generator *tg);
245 
246 	void (*set_dwb_source)(struct timing_generator *optc,
247 		uint32_t dwb_pipe_inst);
248 
249 	void (*get_optc_source)(struct timing_generator *optc,
250 			uint32_t *num_of_input_segments,
251 			uint32_t *seg0_src_sel,
252 			uint32_t *seg1_src_sel);
253 
254 	/**
255 	 * Configure CRCs for the given timing generator. Return false if TG is
256 	 * not on.
257 	 */
258 	bool (*configure_crc)(struct timing_generator *tg,
259 			       const struct crc_params *params);
260 
261 	/**
262 	 * Get CRCs for the given timing generator. Return false if CRCs are
263 	 * not enabled (via configure_crc).
264 	 */
265 	bool (*get_crc)(struct timing_generator *tg,
266 			uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb);
267 
268 	void (*program_manual_trigger)(struct timing_generator *optc);
269 	void (*setup_manual_trigger)(struct timing_generator *optc);
270 	bool (*get_hw_timing)(struct timing_generator *optc,
271 			struct dc_crtc_timing *hw_crtc_timing);
272 
273 	void (*set_vtg_params)(struct timing_generator *optc,
274 			const struct dc_crtc_timing *dc_crtc_timing, bool program_fp2);
275 
276 	void (*set_dsc_config)(struct timing_generator *optc,
277 			       enum optc_dsc_mode dsc_mode,
278 			       uint32_t dsc_bytes_per_pixel,
279 			       uint32_t dsc_slice_width);
280 	void (*set_odm_bypass)(struct timing_generator *optc, const struct dc_crtc_timing *dc_crtc_timing);
281 	void (*set_odm_combine)(struct timing_generator *optc, int *opp_id, int opp_cnt,
282 			struct dc_crtc_timing *timing);
283 	void (*set_gsl)(struct timing_generator *optc, const struct gsl_params *params);
284 	void (*set_gsl_source_select)(struct timing_generator *optc,
285 			int group_idx,
286 			uint32_t gsl_ready_signal);
287 	void (*set_out_mux)(struct timing_generator *tg, enum otg_out_mux_dest dest);
288 	void (*set_vrr_m_const)(struct timing_generator *optc,
289 			double vtotal_avg);
290 	void (*set_drr_trigger_window)(struct timing_generator *optc,
291 			uint32_t window_start, uint32_t window_end);
292 	void (*set_vtotal_change_limit)(struct timing_generator *optc,
293 			uint32_t limit);
294 };
295 
296 #endif
297