1 /* Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved. */ 2 3 #ifndef MODULES_INC_MOD_POWER_H_ 4 #define MODULES_INC_MOD_POWER_H_ 5 6 #include "dm_services.h" 7 8 struct mod_power_init_params { 9 10 bool disable_fractional_pwm; 11 12 /* Use nits based brightness instead of brightness percentage 13 */ 14 bool use_nits_based_brightness; 15 unsigned int panel_min_millinits; 16 unsigned int panel_max_millinits; 17 18 unsigned int min_backlight_pwm; 19 unsigned int max_backlight_pwm; 20 21 unsigned int min_abm_backlight; 22 unsigned int num_backlight_levels; 23 bool backlight_ramping_override; 24 unsigned int backlight_ramping_reduction; 25 unsigned int backlight_ramping_start; 26 bool def_varibright_enable; 27 unsigned int def_varibright_level; 28 unsigned int varibright_level; 29 unsigned int abm_config_setting; 30 31 bool allow_psr_smu_optimizations; 32 33 bool allow_psr_multi_disp_optimizations; 34 35 bool use_custom_backlight_caps; 36 unsigned int custom_backlight_caps_config_no; 37 bool use_linear_backlight_curve; 38 }; 39 40 struct mod_power { 41 int dummy; 42 }; 43 44 /* VariBright settings structure */ 45 struct varibright_info { 46 unsigned int level; 47 bool enable; 48 bool activate; 49 }; 50 51 struct mod_power_psr_context { 52 /* ddc line */ 53 unsigned int channel; 54 /* Transmitter id */ 55 unsigned int transmitter_id; 56 /* Engine Id is used for Dig Be source select */ 57 unsigned int engine_id; 58 /* Controller Id used for Dig Fe source select */ 59 unsigned int controller_id; 60 /* Pcie or Uniphy */ 61 unsigned int phy_type; 62 /* Physical PHY Id used by SMU interpretation */ 63 unsigned int smu_phy_id; 64 /* Vertical total pixels from crtc timing. 65 * This is used for static screen detection. 66 * ie. If we want to detect half a frame, 67 * we use this to determine the hyst lines. 68 */ 69 unsigned int crtc_timing_vertical_total; 70 /* PSR supported from panel capabilities and 71 * current display configuration 72 */ 73 bool psr_supported_display_config; 74 /* Whether fast link training is supported by the panel */ 75 bool psr_exit_link_training_required; 76 /* If RFB setup time is greater than the total VBLANK time, 77 * it is not possible for the sink to capture the video frame 78 * in the same frame the SDP is sent. In this case, 79 * the frame capture indication bit should be set and an extra 80 * static frame should be transmitted to the sink. 81 */ 82 bool psr_frame_capture_indication_req; 83 /* Set the last possible line SDP may be transmitted without violating 84 * the RFB setup time or entering the active video frame. 85 */ 86 unsigned int sdp_transmit_line_num_deadline; 87 /* The VSync rate in Hz used to calculate the 88 * step size for smooth brightness feature 89 */ 90 unsigned int vsync_rate_hz; 91 unsigned int skip_psr_wait_for_pll_lock; 92 unsigned int number_of_controllers; 93 /* Unused, for future use. To indicate that first changed frame from 94 * state3 shouldn't result in psr_inactive, but rather to perform 95 * an automatic single frame rfb_update. 96 */ 97 bool rfb_update_auto_en; 98 /* Number of frame before entering static screen */ 99 unsigned int timehyst_frames; 100 /* Partial frames before entering static screen */ 101 unsigned int hyst_lines; 102 /* # of repeated AUX transaction attempts to make before 103 * indicating failure to the driver 104 */ 105 unsigned int aux_repeats; 106 /* Controls hw blocks to power down during PSR active state */ 107 unsigned int psr_level; 108 /* Controls additional delay after remote frame capture before 109 * continuing powerd own 110 */ 111 unsigned int frame_delay; 112 bool allow_smu_optimizations; 113 bool allow_multi_disp_optimizations; 114 unsigned int line_time_in_us; 115 /* Panel self refresh 2 selective update granularity required */ 116 bool su_granularity_required; 117 /* psr2 selective update y granularity capability */ 118 uint8_t su_y_granularity; 119 uint8_t rate_control_caps; 120 bool os_request_force_ffu; 121 }; 122 123 enum psr_event { 124 psr_event_invalid = 0x0, 125 psr_event_vsync = 0x1, 126 psr_event_full_screen = 0x2, 127 psr_event_defer_enable = 0x4, 128 psr_event_hw_programming = 0x8, 129 psr_event_test_harness_enable_psr = 0x10, 130 psr_event_test_harness_disable_psr = 0x20, 131 psr_event_mpo_video_selective_update = 0x40, 132 psr_event_edp_panel_off_disable_psr = 0x80, 133 psr_event_dynamic_display_switch = 0x100, 134 psr_event_big_screen_video = 0x200, 135 psr_event_dds_defer_stream_enable = 0x800, 136 psr_event_dynamic_link_rate_control = 0x1000, 137 psr_event_vrr_transition = 0x2000, 138 psr_event_pause = 0x4000, 139 psr_event_immediate_flip = 0x8000, 140 psr_event_os_request_disable = 0x10000, 141 psr_event_os_request_force_ffu = 0x20000, 142 psr_event_os_override_hold = 0x40000, 143 psr_event_crc_window_active = 0x80000, 144 }; 145 146 enum replay_event { 147 replay_event_invalid = 0x0, 148 replay_event_vsync = 0x1, 149 replay_event_full_screen = 0x2, 150 replay_event_mpo_video_selective_update = 0x4, 151 replay_event_big_screen_video = 0x8, 152 replay_event_hw_programming = 0x10, 153 replay_event_edp_panel_off_disable_psr = 0x20, 154 replay_event_general_ui = 0x40, 155 replay_event_vrr = 0x80, 156 replay_event_prepare_vtotal = 0x100, 157 replay_event_test_harness_enable_replay = 0x200, 158 replay_event_test_harness_disable_replay = 0x400, 159 replay_event_test_harness_ultra_sleep = 0x800, 160 replay_event_immediate_flip = 0x1000, 161 replay_event_vrr_transition = 0x2000, 162 replay_event_pause = 0x4000, 163 replay_event_disable_replay_while_DPMS = 0x8000, 164 replay_event_test_harness_mode = 0x10000, 165 replay_event_cursor_updating = 0x20000, 166 replay_event_sleep_resume = 0x40000, 167 replay_event_disable_in_AC = 0x80000, 168 replay_event_disable_replay_while_detect_display = 0x100000, 169 replay_event_disable_replay_while_switching_mux = 0x400000, 170 replay_event_infopacket = 0x800000, 171 replay_event_os_request_disable = 0x1000000, 172 replay_event_os_request_force_ffu = 0x2000000, 173 replay_event_os_override_hold = 0x4000000, 174 replay_event_crc_window_active = 0x8000000, 175 }; 176 177 enum replay_enable_option { 178 pr_enable_option_static_screen = 0x1, 179 pr_enable_option_mpo_video = 0x2, 180 pr_enable_option_full_screen_video = 0x4, 181 pr_enable_option_general_ui = 0x8, 182 pr_enable_option_full_screen = 0x10, 183 pr_enable_option_static_screen_coasting = 0x10000, 184 pr_enable_option_mpo_video_coasting = 0x20000, 185 pr_enable_option_full_screen_video_coasting = 0x40000, 186 pr_enable_option_full_screen_coasting = 0x100000, 187 }; 188 189 struct mod_power *mod_power_create(struct dc *dc, 190 struct mod_power_init_params *init_params, 191 unsigned int edp_num); 192 193 void mod_power_destroy(struct mod_power *mod_power); 194 195 bool mod_power_hw_init(struct mod_power *mod_power); 196 197 bool mod_power_add_stream(struct mod_power *mod_power, 198 struct dc_stream_state *stream, struct psr_caps *caps); 199 200 bool mod_power_remove_stream(struct mod_power *mod_power, 201 const struct dc_stream_state *stream); 202 203 bool mod_power_replace_stream(struct mod_power *mod_power, 204 const struct dc_stream_state *current_stream, 205 struct dc_stream_state *new_stream, 206 struct psr_caps *new_caps); 207 208 bool mod_power_set_backlight_nits(struct mod_power *mod_power, 209 struct dc_stream_state *streams, 210 unsigned int backlight_millinit, 211 unsigned int transition_time_millisec, 212 bool skip_aux, 213 bool is_hdr); 214 215 bool mod_power_set_backlight_percent(struct mod_power *mod_power, 216 struct dc_stream_state *stream, 217 unsigned int backlight_millipercent, 218 unsigned int transition_time_millisec, 219 bool is_hdr); 220 221 void mod_power_update_backlight(struct mod_power *mod_power, 222 struct dc_stream_state *stream, 223 unsigned int backlight_millipercent); 224 225 void mod_power_update_backlight_nits(struct mod_power *mod_power, 226 struct dc_stream_state *stream, 227 unsigned int backlight_millinit); 228 229 bool mod_power_get_backlight_pwm(struct mod_power *mod_power, 230 unsigned int *backlight_pwm, 231 unsigned int inst); 232 233 bool mod_power_get_backlight_nits(struct mod_power *mod_power, 234 unsigned int *backlight_millinit, 235 unsigned int inst); 236 237 bool mod_power_get_backlight_percent(struct mod_power *mod_power, 238 unsigned int *backlight_millipercent, 239 unsigned int inst); 240 241 bool mod_power_get_hw_target_backlight_pwm_nits( 242 struct mod_power *mod_power, 243 const struct dc_link *link, 244 unsigned int *backlight_millinit, 245 unsigned int inst); 246 247 bool mod_power_get_hw_target_backlight_pwm_percent( 248 struct mod_power *mod_power, 249 const struct dc_link *link, 250 unsigned int *backlight_millipercent, 251 unsigned int inst); 252 253 bool mod_power_get_hw_target_backlight_pwm( 254 struct mod_power *mod_power, 255 const struct dc_link *link, 256 unsigned int *backlight_u16_16); 257 258 bool mod_power_get_hw_backlight_pwm( 259 struct mod_power *mod_power, 260 const struct dc_link *link, 261 unsigned int *backlight); 262 263 bool mod_power_get_hw_backlight_pwm_nits( 264 struct mod_power *mod_power, 265 const struct dc_link *link, 266 unsigned int *backlight_millinit, 267 unsigned int inst); 268 269 bool mod_power_get_hw_backlight_aux_nits( 270 struct mod_power *mod_power, 271 struct dc_stream_state **streams, int num_streams, 272 unsigned int *backlight_millinit_avg, 273 unsigned int *backlight_millinit_peak); 274 275 bool mod_power_get_hw_backlight_pwm_percent( 276 struct mod_power *mod_power, 277 const struct dc_link *link, 278 unsigned int *backlight_millipercent, 279 unsigned int inst); 280 281 void mod_power_initialize_backlight_caps 282 (struct mod_power *mod_power); 283 284 bool mod_power_get_panel_backlight_boundaries 285 (struct mod_power *mod_power, 286 unsigned int *out_min_backlight, 287 unsigned int *out_max_backlight, 288 unsigned int *out_ac_backlight_percent, 289 unsigned int *out_dc_backlight_percent, 290 unsigned int inst); 291 292 bool mod_power_set_smooth_brightness(struct mod_power *mod_power, 293 bool enable_brightness, 294 unsigned int inst); 295 296 bool mod_power_notify_mode_change(struct mod_power *mod_power, 297 const struct dc_stream_state *stream, 298 bool is_hdr); 299 300 bool mod_power_get_varibright_level(struct mod_power *mod_power, 301 unsigned int *varibright_level); 302 303 bool mod_power_get_varibright_hw_level(struct mod_power *mod_power, 304 unsigned int *varibright_level); 305 306 bool mod_power_get_varibright_default_level(struct mod_power *mod_power, 307 unsigned int *varibright_level); 308 309 bool mod_power_get_varibright_enable(struct mod_power *mod_power, 310 bool *varibright_enable); 311 312 bool mod_power_varibright_activate(struct mod_power *mod_power, 313 bool activate, struct dc_stream_update *stream_update); 314 315 bool mod_power_varibright_feature_enable(struct mod_power *mod_power, 316 bool enable, struct dc_stream_update *stream_update); 317 318 319 bool mod_power_varibright_set_level(struct mod_power *mod_power, 320 unsigned int level, struct dc_stream_update *stream_update); 321 322 bool mod_power_varibright_set_hw_level(struct mod_power *mod_power, 323 unsigned int level, struct dc_stream_update *stream_update); 324 325 bool mod_power_is_abm_active(struct mod_power *mod_power, 326 const struct dc_link *link, 327 unsigned int inst); 328 329 330 bool mod_power_set_psr_event(struct mod_power *mod_power, 331 struct dc_stream_state *stream, bool set_event, 332 enum psr_event event, bool wait); 333 334 bool mod_power_get_psr_event(struct mod_power *mod_power, 335 struct dc_stream_state *stream, 336 unsigned int *active_psr_events); 337 338 bool mod_power_get_psr_state(struct mod_power *mod_power, 339 const struct dc_stream_state *stream, 340 enum dc_psr_state *state); 341 342 bool mod_power_get_psr_enabled_status(struct mod_power *mod_power, 343 const struct dc_stream_state *stream, 344 bool *psr_enabled); 345 346 bool mod_power_set_replay_event(struct mod_power *mod_power, 347 struct dc_stream_state *stream, bool set_event, 348 enum replay_event event, bool wait_for_disable); 349 350 bool mod_power_get_replay_event(struct mod_power *mod_power, 351 struct dc_stream_state *stream, 352 unsigned int *active_replay_events); 353 354 bool mod_power_get_replay_active_status(const struct dc_stream_state *stream, 355 bool *replay_active); 356 357 bool mod_power_replay_set_coasting_vtotal(struct mod_power *mod_power, 358 const struct dc_stream_state *stream, 359 uint32_t coasting_vtotal, uint16_t frame_skip_number); 360 361 void mod_power_replay_residency(const struct dc_stream_state *stream, 362 unsigned int *residency, const bool is_start, const bool is_alpm); 363 364 bool mod_power_replay_set_power_opt_and_coasting_vtotal(struct mod_power *mod_power, 365 const struct dc_stream_state *stream, unsigned int active_replay_events, uint32_t coasting_vtotal, 366 bool is_ultra_sleep_mode, uint16_t frame_skip_number); 367 368 void mod_power_replay_set_timing_sync_supported(struct mod_power *mod_power, 369 const struct dc_stream_state *stream); 370 371 void mod_power_replay_disabled_adaptive_sync_sdp(struct mod_power *mod_power, 372 const struct dc_stream_state *stream, bool force_disabled); 373 374 void mod_power_replay_disabled_desync_error_detection(struct mod_power *mod_power, 375 const struct dc_stream_state *stream, bool force_disabled); 376 void mod_power_set_low_rr_activate(struct mod_power *mod_power, 377 const struct dc_stream_state *stream, bool low_rr_supported); 378 379 void mod_power_set_video_conferencing_activate(struct mod_power *mod_power, 380 const struct dc_stream_state *stream, bool video_conferencing_activate); 381 382 void mod_power_set_live_capture_with_cvt_activate(struct mod_power *mod_power, 383 const struct dc_stream_state *stream, bool live_capture_with_cvt_activate); 384 385 void mod_power_set_replay_continuously_resync(struct mod_power *mod_power, 386 const struct dc_stream_state *stream, bool enable); 387 388 void mod_power_set_coasting_vtotal_without_frame_update(struct mod_power *mod_power, 389 const struct dc_stream_state *stream, uint32_t coasting_vtotal); 390 391 392 393 void mod_power_psr_residency(struct mod_power *mod_power, 394 const struct dc_stream_state *stream, 395 unsigned int *residency, 396 const uint8_t mode); 397 bool mod_power_psr_get_active_psr_events(struct mod_power *mod_power, 398 const struct dc_stream_state *stream, unsigned int *active_psr_events); 399 bool mod_power_psr_set_sink_vtotal_in_psr_active(struct mod_power *mod_power, 400 const struct dc_stream_state *stream, 401 uint16_t psr_vtotal_idle, 402 uint16_t psr_vtotal_su); 403 404 405 406 bool mod_power_backlight_percent_to_nits(struct mod_power *mod_power, 407 struct dc_stream_state *stream, 408 unsigned int backlight_millipercent, 409 unsigned int *backlight_millinit); 410 bool mod_power_backlight_nits_to_percent(struct mod_power *mod_power, 411 struct dc_stream_state *stream, 412 unsigned int backlight_millinit, 413 unsigned int *backlight_millipercent); 414 415 #endif /* MODULES_INC_MOD_POWER_H_ */ 416