1 /* Copyright 2018 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a 4 * copy of this software and associated documentation files (the "Software"), 5 * to deal in the Software without restriction, including without limitation 6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 * and/or sell copies of the Software, and to permit persons to whom the 8 * Software is furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19 * OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * Authors: AMD 22 * 23 */ 24 25 #ifndef MODULES_POWER_POWER_HELPERS_H_ 26 #define MODULES_POWER_POWER_HELPERS_H_ 27 28 #include "dc/inc/hw/dmcu.h" 29 #include "dc/inc/hw/abm.h" 30 #include "dc/inc/core_types.h" 31 #include "mod_power.h" 32 33 struct resource_pool; 34 35 36 enum abm_defines { 37 abm_defines_max_level = 4, 38 abm_defines_max_config = 4, 39 }; 40 41 struct dmcu_iram_parameters { 42 unsigned int *backlight_lut_array; 43 unsigned int backlight_lut_array_size; 44 bool backlight_ramping_override; 45 unsigned int backlight_ramping_reduction; 46 unsigned int backlight_ramping_start; 47 unsigned int min_abm_backlight; 48 unsigned int set; 49 }; 50 struct backlight_state { 51 /* HW uses u16.16 format for backlight PWM */ 52 unsigned int backlight_pwm; 53 /* DM may call power module to set backlight 54 * targeting percent brightness 55 */ 56 unsigned int backlight_millipercent; 57 /* DM may call power module to set backlight based on an explicit 58 * nits value. 59 */ 60 unsigned int backlight_millinit; 61 unsigned int frame_ramp; 62 bool smooth_brightness_enabled; 63 bool isHDR; 64 }; 65 struct power_entity { 66 struct dc_stream_state *stream; 67 struct psr_caps *caps; 68 struct mod_power_psr_context *psr_context; 69 70 /*PSR cached properties*/ 71 bool psr_enabled; 72 unsigned int psr_events; 73 unsigned int psr_power_opt; 74 unsigned int replay_events; 75 }; 76 77 struct pwr_backlight_properties { 78 bool use_nits_based_brightness; 79 bool disable_fractional_pwm; 80 81 unsigned int min_abm_backlight; 82 unsigned int num_backlight_levels; 83 84 bool backlight_ramping_override; 85 unsigned int backlight_ramping_reduction; 86 unsigned int backlight_ramping_start; 87 88 /* Backlight cached properties */ 89 unsigned int ac_backlight_percent; 90 unsigned int dc_backlight_percent; 91 92 /* backlight LUT stored in HW u16.16 format*/ 93 unsigned int *backlight_lut; 94 unsigned int min_backlight_pwm; 95 unsigned int max_backlight_pwm; 96 unsigned int backlight_range; 97 98 /* Describes the panel's min and max luminance in millinits measured 99 * on full white screen, in min and max backlight settings. 100 */ 101 unsigned int min_brightness_millinits; 102 unsigned int max_brightness_millinits; 103 unsigned int nits_range; 104 105 /* Backlight control type of the associated link. Cached here so the 106 * brightness translation helpers can select the correct mapping 107 * (legacy vs. VESA AUX zero-anchored) without threading the type 108 * through every call. 109 */ 110 enum backlight_control_type backlight_control_type; 111 112 bool backlight_caps_valid; 113 bool use_custom_backlight_caps; 114 unsigned int custom_backlight_caps_config_no; 115 bool use_linear_backlight_curve; 116 }; 117 118 struct dmcu_varibright_cached_properties { 119 unsigned int varibright_config_setting; 120 unsigned int varibright_level; 121 unsigned int varibright_hw_level; 122 unsigned int def_varibright_level; 123 bool varibright_user_enable; 124 bool varibright_active; 125 }; 126 127 struct core_power { 128 struct mod_power mod_public; 129 struct dc *dc; 130 struct power_entity *map; 131 struct dmcu_varibright_cached_properties varibright_prop; 132 struct pwr_backlight_properties bl_prop[MAX_NUM_EDP]; 133 struct backlight_state bl_state[MAX_NUM_EDP]; 134 unsigned int edp_num; 135 136 bool psr_smu_optimizations_support; 137 bool multi_disp_optimizations_support; 138 139 unsigned int num_entities; 140 }; 141 142 union dmcu_abm_set_bl_params { 143 struct { 144 unsigned int gradual_change : 1; /* [0:0] */ 145 unsigned int reserved : 15; /* [15:1] */ 146 unsigned int frame_ramp : 16; /* [31:16] */ 147 } bits; 148 unsigned int u32All; 149 }; 150 bool dmcu_load_iram(struct dmcu *dmcu, 151 struct dmcu_iram_parameters params); 152 bool dmub_init_abm_config(struct resource_pool *res_pool, 153 struct dmcu_iram_parameters params, 154 unsigned int inst); 155 156 bool dmub_is_abm_supported(struct resource_pool *res_pool, 157 unsigned int inst); 158 bool dmub_set_abm_event(struct resource_pool *res_pool, 159 unsigned int full_screen, unsigned int trans_info, 160 unsigned int hdr_mode, unsigned int scaling_enable, 161 unsigned int scaling_strength_map, unsigned int inst); 162 bool dmub_set_abm_strength(struct resource_pool *res_pool, 163 unsigned int strength, 164 unsigned int inst); 165 166 void init_replay_config(struct dc_link *link, struct replay_config *pr_config); 167 void set_replay_coasting_vtotal(struct dc_link *link, 168 enum replay_coasting_vtotal_type type, 169 uint32_t vtotal); 170 void set_replay_defer_update_coasting_vtotal(struct dc_link *link, 171 enum replay_coasting_vtotal_type type, 172 uint32_t vtotal); 173 void set_replay_frame_skip_number(struct dc_link *link, 174 enum replay_coasting_vtotal_type type, 175 uint32_t coasting_vtotal_refresh_rate_Mhz, 176 uint32_t flicker_free_refresh_rate_Mhz, 177 bool is_defer); 178 void update_replay_coasting_vtotal_from_defer(struct dc_link *link, 179 enum replay_coasting_vtotal_type type); 180 void set_replay_low_rr_full_screen_video_src_vtotal(struct dc_link *link, uint16_t vtotal); 181 void calculate_replay_link_off_frame_count(struct dc_link *link, 182 uint16_t vtotal, uint16_t htotal); 183 184 bool is_psr_su_specific_panel(struct dc_link *link); 185 void mod_power_calc_psr_configs(struct psr_config *psr_config, 186 struct dc_link *link, 187 const struct dc_stream_state *stream); 188 bool mod_power_only_edp(const struct dc_state *context, 189 const struct dc_stream_state *stream); 190 bool psr_su_set_dsc_slice_height(struct dc *dc, struct dc_link *link, 191 struct dc_stream_state *stream, 192 struct psr_config *config); 193 194 bool fill_custom_backlight_caps(unsigned int config_no, 195 struct dm_acpi_atif_backlight_caps *caps); 196 void reset_replay_dsync_error_count(struct dc_link *link); 197 void change_replay_to_psr(struct dc_link *link); 198 void change_psr_to_replay(struct dc_link *link); 199 void initialize_backlight_caps(struct core_power *core_power, unsigned int inst); 200 void mod_power_set_backlight_control_type(struct core_power *core_power, 201 unsigned int inst, enum backlight_control_type backlight_control_type); 202 unsigned int backlight_millipercent_to_pwm( 203 struct core_power *core_power, unsigned int millipercent, unsigned int inst); 204 unsigned int backlight_millipercent_to_millinit( 205 struct core_power *core_power, unsigned int millipercent, unsigned int inst); 206 void fill_backlight_level_params(struct core_power *core_power, 207 struct set_backlight_level_params *backlight_level_params, 208 int panel_inst, uint8_t aux_inst, unsigned int backlight_pwm, 209 enum backlight_control_type backlight_control_type, 210 unsigned int backlight_millinit, unsigned int transition_time_millisec, 211 bool is_hdr); 212 bool mod_power_hw_init_backlight(struct mod_power *mod_power); 213 void mod_power_update_backlight_on_mode_change( 214 struct core_power *core_power, 215 struct dc_link *link, 216 unsigned int panel_inst, 217 uint8_t aux_inst, 218 bool is_hdr); 219 unsigned int map_index_from_stream(struct core_power *core_power, 220 const struct dc_stream_state *stream); 221 bool mod_power_psr_notify_mode_change(struct mod_power *mod_power, 222 const struct dc_stream_state *stream, 223 struct dc_link *link, 224 unsigned int stream_index); 225 void mod_power_replay_notify_mode_change(struct mod_power *mod_power, 226 struct dc *dc, 227 struct dc_link *link, 228 const struct dc_stream_state *stream, 229 unsigned int stream_index); 230 #endif /* MODULES_POWER_POWER_HELPERS_H_ */ 231