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