1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright 2023 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: AMD
24  *
25  */
26 
27 /**
28  * DOC: overview
29  *
30  * Output Pipe Timing Combiner (OPTC) includes two major functional blocks:
31  * Output Data Mapper (ODM) and Output Timing Generator (OTG).
32  *
33  * - ODM: It is Output Data Mapping block. It can combine input data from
34  *   multiple OPP data pipes into one single data stream or split data from one
35  *   OPP data pipe into multiple data streams or just bypass OPP data to DIO.
36  * - OTG: It is Output Timing Generator. It generates display timing signals to
37  *   drive the display output.
38  */
39 
40 #ifndef __DC_OPTC_H__
41 #define __DC_OPTC_H__
42 
43 #include "timing_generator.h"
44 
45 struct optc {
46 	struct timing_generator base;
47 
48 	const struct dcn_optc_registers *tg_regs;
49 	const struct dcn_optc_shift *tg_shift;
50 	const struct dcn_optc_mask *tg_mask;
51 
52 	int opp_count;
53 
54 	uint32_t max_h_total;
55 	uint32_t max_v_total;
56 
57 	uint32_t min_h_blank;
58 
59 	uint32_t min_h_sync_width;
60 	uint32_t min_v_sync_width;
61 	uint32_t min_v_blank;
62 	uint32_t min_v_blank_interlace;
63 
64 	int vstartup_start;
65 	int vupdate_offset;
66 	int vupdate_width;
67 	int vready_offset;
68 	int pstate_keepout;
69 	struct dc_crtc_timing orginal_patched_timing;
70 	enum signal_type signal;
71 };
72 
73 void optc1_read_otg_state(struct timing_generator *optc, struct dcn_otg_state *s);
74 
75 bool optc1_get_hw_timing(struct timing_generator *tg, struct dc_crtc_timing *hw_crtc_timing);
76 
77 bool optc1_validate_timing(struct timing_generator *optc,
78 			   const struct dc_crtc_timing *timing);
79 
80 void optc1_program_timing(struct timing_generator *optc,
81 			  const struct dc_crtc_timing *dc_crtc_timing,
82 			  int vready_offset,
83 			  int vstartup_start,
84 			  int vupdate_offset,
85 			  int vupdate_width,
86 			  int pstate_keepout,
87 			  const enum signal_type signal,
88 			  bool use_vbios);
89 
90 void optc1_setup_vertical_interrupt0(struct timing_generator *optc,
91 				     uint32_t start_line,
92 				     uint32_t end_line);
93 
94 void optc1_setup_vertical_interrupt1(struct timing_generator *optc,
95 				     uint32_t start_line);
96 
97 void optc1_setup_vertical_interrupt2(struct timing_generator *optc,
98 				     uint32_t start_line);
99 
100 void optc1_program_global_sync(struct timing_generator *optc,
101 			       int vready_offset,
102 			       int vstartup_start,
103 			       int vupdate_offset,
104 			       int vupdate_width,
105 				   int pstate_keepout);
106 
107 bool optc1_disable_crtc(struct timing_generator *optc);
108 
109 bool optc1_is_counter_moving(struct timing_generator *optc);
110 
111 void optc1_get_position(struct timing_generator *optc,
112 			struct crtc_position *position);
113 
114 uint32_t optc1_get_vblank_counter(struct timing_generator *optc);
115 
116 void optc1_get_crtc_scanoutpos(struct timing_generator *optc,
117 			       uint32_t *v_blank_start,
118 			       uint32_t *v_blank_end,
119 			       uint32_t *h_position,
120 			       uint32_t *v_position);
121 
122 void optc1_set_early_control(struct timing_generator *optc,
123 			     uint32_t early_cntl);
124 
125 void optc1_wait_for_state(struct timing_generator *optc,
126 			  enum crtc_state state);
127 
128 void optc1_set_blank(struct timing_generator *optc,
129 		     bool enable_blanking);
130 
131 bool optc1_is_blanked(struct timing_generator *optc);
132 
133 void optc1_program_blank_color(struct timing_generator *optc,
134 			       const struct tg_color *black_color);
135 
136 bool optc1_did_triggered_reset_occur(struct timing_generator *optc);
137 
138 void optc1_enable_reset_trigger(struct timing_generator *optc, int source_tg_inst);
139 
140 void optc1_disable_reset_trigger(struct timing_generator *optc);
141 
142 void optc1_lock(struct timing_generator *optc);
143 
144 void optc1_unlock(struct timing_generator *optc);
145 
146 void optc1_enable_optc_clock(struct timing_generator *optc, bool enable);
147 
148 void optc1_set_drr(struct timing_generator *optc,
149 		   const struct drr_params *params);
150 
151 void optc1_set_vtotal_min_max(struct timing_generator *optc, int vtotal_min, int vtotal_max);
152 
153 void optc1_set_static_screen_control(struct timing_generator *optc,
154 				     uint32_t event_triggers,
155 				     uint32_t num_frames);
156 
157 void optc1_program_stereo(struct timing_generator *optc,
158 			  const struct dc_crtc_timing *timing,
159 			  struct crtc_stereo_flags *flags);
160 
161 bool optc1_is_stereo_left_eye(struct timing_generator *optc);
162 
163 void optc1_clear_optc_underflow(struct timing_generator *optc);
164 
165 void optc1_tg_init(struct timing_generator *optc);
166 
167 bool optc1_is_tg_enabled(struct timing_generator *optc);
168 
169 bool optc1_is_optc_underflow_occurred(struct timing_generator *optc);
170 
171 void optc1_set_blank_data_double_buffer(struct timing_generator *optc, bool enable);
172 
173 void optc1_set_timing_double_buffer(struct timing_generator *optc, bool enable);
174 
175 bool optc1_get_otg_active_size(struct timing_generator *optc,
176 			       uint32_t *otg_active_width,
177 			       uint32_t *otg_active_height);
178 
179 void optc1_enable_crtc_reset(struct timing_generator *optc,
180 			     int source_tg_inst,
181 			     struct crtc_trigger_info *crtc_tp);
182 
183 bool optc1_configure_crc(struct timing_generator *optc, const struct crc_params *params);
184 
185 bool optc1_get_crc(struct timing_generator *optc, uint8_t idx,
186 		   uint32_t *r_cr,
187 		   uint32_t *g_y,
188 		   uint32_t *b_cb);
189 
190 void optc1_set_vtg_params(struct timing_generator *optc,
191 			  const struct dc_crtc_timing *dc_crtc_timing,
192 			  bool program_fp2);
193 
194 bool optc1_is_two_pixels_per_container(const struct dc_crtc_timing *timing);
195 
196 #endif
197