2 * Copyright 2016 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
30 * Copyright 2016 Advanced Micro Devices, Inc.
32 * Permission is hereby granted, free of charge, to any person obtaining a
33 * copy of this software and associated documentation files (the "Software"),
34 * to deal in the Software without restriction, including without limitation
35 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
36 * and/or sell copies of the Software, and to permit persons to whom the
37 * Software is furnished to do so, subject to the following conditions:
39 * The above copyright notice and this permission notice shall be included in
40 * all copies or substantial portions of the Software.
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
46 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
47 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48 * OTHER DEALINGS IN THE SOFTWARE.
54 #ifndef MOD_FREESYNC_H_
55 #define MOD_FREESYNC_H_
57 #include "mod_shared.h"
64 // TODO: References to this should be removed
65 struct mod_freesync_caps {
67 unsigned int min_refresh_in_micro_hz;
68 unsigned int max_refresh_in_micro_hz;
72 VRR_STATE_UNSUPPORTED = 0,
75 VRR_STATE_ACTIVE_VARIABLE,
76 VRR_STATE_ACTIVE_FIXED
79 struct mod_freesync_config {
80 enum mod_vrr_state state;
84 unsigned int min_refresh_in_uhz;
85 unsigned int max_refresh_in_uhz;
86 unsigned int fixed_refresh_in_uhz;
90 struct mod_vrr_params_btr {
93 uint32_t mid_point_in_us;
94 uint32_t inserted_duration_in_us;
95 uint32_t frames_to_insert;
96 uint32_t frame_counter;
97 uint32_t margin_in_us;
100 struct mod_vrr_params_fixed_refresh {
104 uint32_t target_refresh_in_uhz;
105 uint32_t frame_counter;
108 struct mod_vrr_params_flip_interval {
109 bool flip_interval_workaround_active;
110 bool program_flip_interval_workaround;
111 bool do_flip_interval_workaround_cleanup;
112 uint32_t flip_interval_detect_counter;
113 uint32_t vsyncs_between_flip;
114 uint32_t vsync_to_flip_in_us;
115 uint32_t v_update_timestamp_in_us;
118 struct mod_vrr_params {
120 bool send_info_frame;
121 enum mod_vrr_state state;
123 uint32_t min_refresh_in_uhz;
124 uint32_t max_duration_in_us;
125 uint32_t max_refresh_in_uhz;
126 uint32_t min_duration_in_us;
127 uint32_t fixed_refresh_in_uhz;
129 struct dc_crtc_timing_adjust adjust;
131 struct mod_vrr_params_fixed_refresh fixed;
133 struct mod_vrr_params_btr btr;
135 struct mod_vrr_params_flip_interval flip_interval;
138 struct mod_freesync *mod_freesync_create(struct dc *dc);
139 void mod_freesync_destroy(struct mod_freesync *mod_freesync);
141 bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync,
142 const struct dc_stream_state *stream,
146 bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync,
147 struct dc_stream_state *stream,
148 unsigned int *nom_v_pos,
149 unsigned int *v_pos);
151 void mod_freesync_get_settings(struct mod_freesync *mod_freesync,
152 const struct mod_vrr_params *vrr,
153 unsigned int *v_total_min, unsigned int *v_total_max,
154 unsigned int *event_triggers,
155 unsigned int *window_min, unsigned int *window_max,
156 unsigned int *lfc_mid_point_in_us,
157 unsigned int *inserted_frames,
158 unsigned int *inserted_duration_in_us);
160 void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
161 const struct dc_stream_state *stream,
162 const struct mod_vrr_params *vrr,
163 enum vrr_packet_type packet_type,
164 enum color_transfer_func app_tf,
165 struct dc_info_packet *infopacket,
168 void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
169 const struct dc_stream_state *stream,
170 struct mod_freesync_config *in_config,
171 struct mod_vrr_params *in_out_vrr);
173 void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
174 const struct dc_plane_state *plane,
175 const struct dc_stream_state *stream,
176 unsigned int curr_time_stamp_in_us,
177 struct mod_vrr_params *in_out_vrr);
179 void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
180 const struct dc_stream_state *stream,
181 struct mod_vrr_params *in_out_vrr);
183 unsigned long long mod_freesync_calc_nominal_field_rate(
184 const struct dc_stream_state *stream);
186 unsigned long long mod_freesync_calc_field_rate_from_timing(
187 unsigned int vtotal, unsigned int htotal, unsigned int pix_clk);
189 bool mod_freesync_is_valid_range(uint32_t min_refresh_cap_in_uhz,
190 uint32_t max_refresh_cap_in_uhz,
191 uint32_t nominal_field_rate_in_uhz);
193 unsigned int mod_freesync_calc_v_total_from_refresh(
194 const struct dc_stream_state *stream,
195 unsigned int refresh_in_uhz);
197 // Returns true when FreeSync is supported and enabled (even if it is inactive)
198 bool mod_freesync_get_freesync_enabled(struct mod_vrr_params *pVrr);