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 }; 178 179 enum replay_enable_option { 180 pr_enable_option_static_screen = 0x1, 181 pr_enable_option_mpo_video = 0x2, 182 pr_enable_option_full_screen_video = 0x4, 183 pr_enable_option_general_ui = 0x8, 184 pr_enable_option_full_screen = 0x10, 185 pr_enable_option_static_screen_coasting = 0x10000, 186 pr_enable_option_mpo_video_coasting = 0x20000, 187 pr_enable_option_full_screen_video_coasting = 0x40000, 188 pr_enable_option_full_screen_coasting = 0x100000, 189 }; 190 191 struct mod_power *mod_power_create(struct dc *dc, 192 struct mod_power_init_params *init_params, 193 unsigned int edp_num); 194 195 void mod_power_destroy(struct mod_power *mod_power); 196 197 bool mod_power_hw_init(struct mod_power *mod_power); 198 199 bool mod_power_add_stream(struct mod_power *mod_power, 200 struct dc_stream_state *stream, struct psr_caps *caps); 201 202 bool mod_power_remove_stream(struct mod_power *mod_power, 203 const struct dc_stream_state *stream); 204 205 bool mod_power_replace_stream(struct mod_power *mod_power, 206 const struct dc_stream_state *current_stream, 207 struct dc_stream_state *new_stream, 208 struct psr_caps *new_caps); 209 210 bool mod_power_set_backlight_nits(struct mod_power *mod_power, 211 struct dc_stream_state *streams, 212 unsigned int backlight_millinit, 213 unsigned int transition_time_millisec, 214 bool skip_aux, 215 bool is_hdr); 216 217 bool mod_power_set_backlight_percent(struct mod_power *mod_power, 218 struct dc_stream_state *stream, 219 unsigned int backlight_millipercent, 220 unsigned int transition_time_millisec, 221 bool is_hdr); 222 223 void mod_power_update_backlight(struct mod_power *mod_power, 224 struct dc_stream_state *stream, 225 unsigned int backlight_millipercent); 226 227 void mod_power_update_backlight_nits(struct mod_power *mod_power, 228 struct dc_stream_state *stream, 229 unsigned int backlight_millinit); 230 231 bool mod_power_get_backlight_pwm(struct mod_power *mod_power, 232 unsigned int *backlight_pwm, 233 unsigned int inst); 234 235 bool mod_power_get_backlight_nits(struct mod_power *mod_power, 236 unsigned int *backlight_millinit, 237 unsigned int inst); 238 239 bool mod_power_get_backlight_percent(struct mod_power *mod_power, 240 unsigned int *backlight_millipercent, 241 unsigned int inst); 242 243 bool mod_power_get_hw_target_backlight_pwm_nits( 244 struct mod_power *mod_power, 245 const struct dc_link *link, 246 unsigned int *backlight_millinit, 247 unsigned int inst); 248 249 bool mod_power_get_hw_target_backlight_pwm_percent( 250 struct mod_power *mod_power, 251 const struct dc_link *link, 252 unsigned int *backlight_millipercent, 253 unsigned int inst); 254 255 bool mod_power_get_hw_target_backlight_pwm( 256 struct mod_power *mod_power, 257 const struct dc_link *link, 258 unsigned int *backlight_u16_16); 259 260 bool mod_power_get_hw_backlight_pwm( 261 struct mod_power *mod_power, 262 const struct dc_link *link, 263 unsigned int *backlight); 264 265 bool mod_power_get_hw_backlight_pwm_nits( 266 struct mod_power *mod_power, 267 const struct dc_link *link, 268 unsigned int *backlight_millinit, 269 unsigned int inst); 270 271 bool mod_power_get_hw_backlight_aux_nits( 272 struct mod_power *mod_power, 273 struct dc_stream_state **streams, int num_streams, 274 unsigned int *backlight_millinit_avg, 275 unsigned int *backlight_millinit_peak); 276 277 bool mod_power_get_hw_backlight_pwm_percent( 278 struct mod_power *mod_power, 279 const struct dc_link *link, 280 unsigned int *backlight_millipercent, 281 unsigned int inst); 282 283 void mod_power_initialize_backlight_caps 284 (struct mod_power *mod_power); 285 286 bool mod_power_get_panel_backlight_boundaries 287 (struct mod_power *mod_power, 288 unsigned int *out_min_backlight, 289 unsigned int *out_max_backlight, 290 unsigned int *out_ac_backlight_percent, 291 unsigned int *out_dc_backlight_percent, 292 unsigned int inst); 293 294 bool mod_power_set_smooth_brightness(struct mod_power *mod_power, 295 bool enable_brightness, 296 unsigned int inst); 297 298 bool mod_power_notify_mode_change(struct mod_power *mod_power, 299 const struct dc_stream_state *stream, 300 bool is_hdr); 301 302 bool mod_power_get_varibright_level(struct mod_power *mod_power, 303 unsigned int *varibright_level); 304 305 bool mod_power_get_varibright_hw_level(struct mod_power *mod_power, 306 unsigned int *varibright_level); 307 308 bool mod_power_get_varibright_default_level(struct mod_power *mod_power, 309 unsigned int *varibright_level); 310 311 bool mod_power_get_varibright_enable(struct mod_power *mod_power, 312 bool *varibright_enable); 313 314 bool mod_power_varibright_activate(struct mod_power *mod_power, 315 bool activate, struct dc_stream_update *stream_update); 316 317 bool mod_power_varibright_feature_enable(struct mod_power *mod_power, 318 bool enable, struct dc_stream_update *stream_update); 319 320 321 bool mod_power_varibright_set_level(struct mod_power *mod_power, 322 unsigned int level, struct dc_stream_update *stream_update); 323 324 bool mod_power_varibright_set_hw_level(struct mod_power *mod_power, 325 unsigned int level, struct dc_stream_update *stream_update); 326 327 bool mod_power_is_abm_active(struct mod_power *mod_power, 328 const struct dc_link *link, 329 unsigned int inst); 330 331 332 bool mod_power_set_psr_event(struct mod_power *mod_power, 333 struct dc_stream_state *stream, bool set_event, 334 enum psr_event event, bool wait); 335 336 bool mod_power_get_psr_event(struct mod_power *mod_power, 337 struct dc_stream_state *stream, 338 unsigned int *active_psr_events); 339 340 bool mod_power_get_psr_state(struct mod_power *mod_power, 341 const struct dc_stream_state *stream, 342 enum dc_psr_state *state); 343 344 bool mod_power_get_psr_enabled_status(struct mod_power *mod_power, 345 const struct dc_stream_state *stream, 346 bool *psr_enabled); 347 348 bool mod_power_set_replay_event(struct mod_power *mod_power, 349 struct dc_stream_state *stream, bool set_event, 350 enum replay_event event, bool wait_for_disable); 351 352 bool mod_power_get_replay_event(struct mod_power *mod_power, 353 struct dc_stream_state *stream, 354 unsigned int *active_replay_events); 355 356 bool mod_power_get_replay_active_status(const struct dc_stream_state *stream, 357 bool *replay_active); 358 359 bool mod_power_replay_set_coasting_vtotal(struct mod_power *mod_power, 360 const struct dc_stream_state *stream, 361 uint32_t coasting_vtotal, uint16_t frame_skip_number); 362 363 void mod_power_replay_residency(const struct dc_stream_state *stream, 364 unsigned int *residency, const bool is_start, const bool is_alpm); 365 366 bool mod_power_replay_set_power_opt_and_coasting_vtotal(struct mod_power *mod_power, 367 const struct dc_stream_state *stream, unsigned int active_replay_events, uint32_t coasting_vtotal, 368 bool is_ultra_sleep_mode, uint16_t frame_skip_number); 369 370 void mod_power_replay_set_timing_sync_supported(struct mod_power *mod_power, 371 const struct dc_stream_state *stream); 372 373 void mod_power_replay_disabled_adaptive_sync_sdp(struct mod_power *mod_power, 374 const struct dc_stream_state *stream, bool force_disabled); 375 376 void mod_power_replay_disabled_desync_error_detection(struct mod_power *mod_power, 377 const struct dc_stream_state *stream, bool force_disabled); 378 void mod_power_set_low_rr_activate(struct mod_power *mod_power, 379 const struct dc_stream_state *stream, bool low_rr_supported); 380 381 void mod_power_set_video_conferencing_activate(struct mod_power *mod_power, 382 const struct dc_stream_state *stream, bool video_conferencing_activate); 383 384 void mod_power_set_live_capture_with_cvt_activate(struct mod_power *mod_power, 385 const struct dc_stream_state *stream, bool live_capture_with_cvt_activate); 386 387 void mod_power_set_replay_continuously_resync(struct mod_power *mod_power, 388 const struct dc_stream_state *stream, bool enable); 389 390 void mod_power_set_coasting_vtotal_without_frame_update(struct mod_power *mod_power, 391 const struct dc_stream_state *stream, uint32_t coasting_vtotal); 392 393 394 395 void mod_power_psr_residency(struct mod_power *mod_power, 396 const struct dc_stream_state *stream, 397 unsigned int *residency, 398 const uint8_t mode); 399 bool mod_power_psr_get_active_psr_events(struct mod_power *mod_power, 400 const struct dc_stream_state *stream, unsigned int *active_psr_events); 401 bool mod_power_psr_set_sink_vtotal_in_psr_active(struct mod_power *mod_power, 402 const struct dc_stream_state *stream, 403 uint16_t psr_vtotal_idle, 404 uint16_t psr_vtotal_su); 405 406 407 408 bool mod_power_backlight_percent_to_nits(struct mod_power *mod_power, 409 struct dc_stream_state *stream, 410 unsigned int backlight_millipercent, 411 unsigned int *backlight_millinit); 412 bool mod_power_backlight_nits_to_percent(struct mod_power *mod_power, 413 struct dc_stream_state *stream, 414 unsigned int backlight_millinit, 415 unsigned int *backlight_millipercent); 416 417 #endif /* MODULES_INC_MOD_POWER_H_ */ 418