14562236bSHarry Wentland /* 24562236bSHarry Wentland * Copyright 2016 Advanced Micro Devices, Inc. 34562236bSHarry Wentland * 44562236bSHarry Wentland * Permission is hereby granted, free of charge, to any person obtaining a 54562236bSHarry Wentland * copy of this software and associated documentation files (the "Software"), 64562236bSHarry Wentland * to deal in the Software without restriction, including without limitation 74562236bSHarry Wentland * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84562236bSHarry Wentland * and/or sell copies of the Software, and to permit persons to whom the 94562236bSHarry Wentland * Software is furnished to do so, subject to the following conditions: 104562236bSHarry Wentland * 114562236bSHarry Wentland * The above copyright notice and this permission notice shall be included in 124562236bSHarry Wentland * all copies or substantial portions of the Software. 134562236bSHarry Wentland * 144562236bSHarry Wentland * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 154562236bSHarry Wentland * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 164562236bSHarry Wentland * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 174562236bSHarry Wentland * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 184562236bSHarry Wentland * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 194562236bSHarry Wentland * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 204562236bSHarry Wentland * OTHER DEALINGS IN THE SOFTWARE. 214562236bSHarry Wentland * 224562236bSHarry Wentland * Authors: AMD 234562236bSHarry Wentland * 244562236bSHarry Wentland */ 254562236bSHarry Wentland 264562236bSHarry Wentland #ifndef MOD_FREESYNC_H_ 274562236bSHarry Wentland #define MOD_FREESYNC_H_ 284562236bSHarry Wentland 29c2791297SSivapiriyanKumarasamy #include "mod_shared.h" 304562236bSHarry Wentland 3198e6436dSAnthony Koo // Access structures 324562236bSHarry Wentland struct mod_freesync { 334562236bSHarry Wentland int dummy; 344562236bSHarry Wentland }; 354562236bSHarry Wentland 3698e6436dSAnthony Koo // TODO: References to this should be removed 374562236bSHarry Wentland struct mod_freesync_caps { 384562236bSHarry Wentland bool supported; 394562236bSHarry Wentland unsigned int min_refresh_in_micro_hz; 404562236bSHarry Wentland unsigned int max_refresh_in_micro_hz; 414562236bSHarry Wentland }; 424562236bSHarry Wentland 4398e6436dSAnthony Koo enum mod_vrr_state { 4498e6436dSAnthony Koo VRR_STATE_UNSUPPORTED = 0, 4598e6436dSAnthony Koo VRR_STATE_DISABLED, 4698e6436dSAnthony Koo VRR_STATE_INACTIVE, 4798e6436dSAnthony Koo VRR_STATE_ACTIVE_VARIABLE, 4898e6436dSAnthony Koo VRR_STATE_ACTIVE_FIXED 494562236bSHarry Wentland }; 504562236bSHarry Wentland 5198e6436dSAnthony Koo struct mod_freesync_config { 5298e6436dSAnthony Koo enum mod_vrr_state state; 5369ff8845SAnthony Koo bool vsif_supported; 5498e6436dSAnthony Koo bool ramping; 5598e6436dSAnthony Koo bool btr; 5698e6436dSAnthony Koo unsigned int min_refresh_in_uhz; 5798e6436dSAnthony Koo unsigned int max_refresh_in_uhz; 58d2bacc38SHaiyi Zhou unsigned int fixed_refresh_in_uhz; 59d2bacc38SHaiyi Zhou 6098e6436dSAnthony Koo }; 614562236bSHarry Wentland 6298e6436dSAnthony Koo struct mod_vrr_params_btr { 6398e6436dSAnthony Koo bool btr_enabled; 6498e6436dSAnthony Koo bool btr_active; 6598e6436dSAnthony Koo uint32_t mid_point_in_us; 6698e6436dSAnthony Koo uint32_t inserted_duration_in_us; 6798e6436dSAnthony Koo uint32_t frames_to_insert; 6898e6436dSAnthony Koo uint32_t frame_counter; 69ded6119eSAmanda Liu uint32_t margin_in_us; 7098e6436dSAnthony Koo }; 714562236bSHarry Wentland 7298e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh { 7398e6436dSAnthony Koo bool fixed_active; 7498e6436dSAnthony Koo bool ramping_active; 7598e6436dSAnthony Koo bool ramping_done; 7698e6436dSAnthony Koo uint32_t target_refresh_in_uhz; 7798e6436dSAnthony Koo uint32_t frame_counter; 7898e6436dSAnthony Koo }; 794562236bSHarry Wentland 803fe5739dSAngus Wang struct mod_vrr_params_flip_interval { 813fe5739dSAngus Wang bool flip_interval_workaround_active; 823fe5739dSAngus Wang bool program_flip_interval_workaround; 833fe5739dSAngus Wang bool do_flip_interval_workaround_cleanup; 843fe5739dSAngus Wang uint32_t flip_interval_detect_counter; 853fe5739dSAngus Wang uint32_t vsyncs_between_flip; 863fe5739dSAngus Wang uint32_t vsync_to_flip_in_us; 873fe5739dSAngus Wang uint32_t v_update_timestamp_in_us; 883fe5739dSAngus Wang }; 893fe5739dSAngus Wang 9098e6436dSAnthony Koo struct mod_vrr_params { 9198e6436dSAnthony Koo bool supported; 92ca35899cSBayan Zabihiyan bool send_info_frame; 9398e6436dSAnthony Koo enum mod_vrr_state state; 944562236bSHarry Wentland 9598e6436dSAnthony Koo uint32_t min_refresh_in_uhz; 9698e6436dSAnthony Koo uint32_t max_duration_in_us; 9798e6436dSAnthony Koo uint32_t max_refresh_in_uhz; 9898e6436dSAnthony Koo uint32_t min_duration_in_us; 99d2bacc38SHaiyi Zhou uint32_t fixed_refresh_in_uhz; 1004562236bSHarry Wentland 10198e6436dSAnthony Koo struct dc_crtc_timing_adjust adjust; 1024562236bSHarry Wentland 10398e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh fixed; 1041a87fbfeSAmy Zhang 10598e6436dSAnthony Koo struct mod_vrr_params_btr btr; 1063fe5739dSAngus Wang 1073fe5739dSAngus Wang struct mod_vrr_params_flip_interval flip_interval; 10898e6436dSAnthony Koo }; 10972ada5f7SEric Cook 11098e6436dSAnthony Koo struct mod_freesync *mod_freesync_create(struct dc *dc); 11198e6436dSAnthony Koo void mod_freesync_destroy(struct mod_freesync *mod_freesync); 11272ada5f7SEric Cook 11372ada5f7SEric Cook bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync, 11498e6436dSAnthony Koo const struct dc_stream_state *stream, 11572ada5f7SEric Cook unsigned int *vmin, 11672ada5f7SEric Cook unsigned int *vmax); 11772ada5f7SEric Cook 11872ada5f7SEric Cook bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync, 1190971c40eSHarry Wentland struct dc_stream_state *stream, 12072ada5f7SEric Cook unsigned int *nom_v_pos, 12172ada5f7SEric Cook unsigned int *v_pos); 12272ada5f7SEric Cook 123a3e1737eSAnthony Koo void mod_freesync_get_settings(struct mod_freesync *mod_freesync, 12498e6436dSAnthony Koo const struct mod_vrr_params *vrr, 125a3e1737eSAnthony Koo unsigned int *v_total_min, unsigned int *v_total_max, 126a3e1737eSAnthony Koo unsigned int *event_triggers, 127a3e1737eSAnthony Koo unsigned int *window_min, unsigned int *window_max, 128a3e1737eSAnthony Koo unsigned int *lfc_mid_point_in_us, 129a3e1737eSAnthony Koo unsigned int *inserted_frames, 130a3e1737eSAnthony Koo unsigned int *inserted_duration_in_us); 131a3e1737eSAnthony Koo 13298e6436dSAnthony Koo void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, 13398e6436dSAnthony Koo const struct dc_stream_state *stream, 13498e6436dSAnthony Koo const struct mod_vrr_params *vrr, 135c2791297SSivapiriyanKumarasamy enum vrr_packet_type packet_type, 136672e78caSNathan Chancellor enum color_transfer_func app_tf, 1374cda3243SMax.Tseng struct dc_info_packet *infopacket, 1384cda3243SMax.Tseng bool pack_sdp_v1_3); 13998e6436dSAnthony Koo 14098e6436dSAnthony Koo void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, 14198e6436dSAnthony Koo const struct dc_stream_state *stream, 14298e6436dSAnthony Koo struct mod_freesync_config *in_config, 14398e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 14498e6436dSAnthony Koo 14598e6436dSAnthony Koo void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync, 14698e6436dSAnthony Koo const struct dc_plane_state *plane, 14798e6436dSAnthony Koo const struct dc_stream_state *stream, 14898e6436dSAnthony Koo unsigned int curr_time_stamp_in_us, 14998e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 15098e6436dSAnthony Koo 15198e6436dSAnthony Koo void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, 15298e6436dSAnthony Koo const struct dc_stream_state *stream, 15398e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 15498e6436dSAnthony Koo 155ff6014d6SAnthony Koo unsigned long long mod_freesync_calc_nominal_field_rate( 156ff6014d6SAnthony Koo const struct dc_stream_state *stream); 157ff6014d6SAnthony Koo 15849c70eceSAlvin Lee unsigned long long mod_freesync_calc_field_rate_from_timing( 15949c70eceSAlvin Lee unsigned int vtotal, unsigned int htotal, unsigned int pix_clk); 16049c70eceSAlvin Lee 161ad339f69SJaehyun Chung bool mod_freesync_is_valid_range(uint32_t min_refresh_cap_in_uhz, 162e80e9446SAnthony Koo uint32_t max_refresh_cap_in_uhz, 163ad339f69SJaehyun Chung uint32_t nominal_field_rate_in_uhz); 164e80e9446SAnthony Koo 16549c70eceSAlvin Lee unsigned int mod_freesync_calc_v_total_from_refresh( 16649c70eceSAlvin Lee const struct dc_stream_state *stream, 16749c70eceSAlvin Lee unsigned int refresh_in_uhz); 168a9f54ce3SAhmad Othman 169c2fbe663SFelipe Clark // Returns true when FreeSync is supported and enabled (even if it is inactive) 170*ebfb1526SHarry VanZyllDeJong bool mod_freesync_get_freesync_enabled(struct mod_vrr_params *pVrr); 171c2fbe663SFelipe Clark 1724562236bSHarry Wentland #endif 173