summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/display/modules/power/power_helpers.h
blob: 68679fa109460f9524390c87bc0333b53c79f176 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* Copyright 2018 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#ifndef MODULES_POWER_POWER_HELPERS_H_
#define MODULES_POWER_POWER_HELPERS_H_

#include "dc/inc/hw/dmcu.h"
#include "dc/inc/hw/abm.h"
#include "dc/inc/core_types.h"
#include "mod_power.h"

struct resource_pool;


enum abm_defines {
	abm_defines_max_level = 4,
	abm_defines_max_config = 4,
};

struct dmcu_iram_parameters {
	unsigned int *backlight_lut_array;
	unsigned int backlight_lut_array_size;
	bool backlight_ramping_override;
	unsigned int backlight_ramping_reduction;
	unsigned int backlight_ramping_start;
	unsigned int min_abm_backlight;
	unsigned int set;
};
struct backlight_state {
	/* HW uses u16.16 format for backlight PWM */
	unsigned int backlight_pwm;
	/* DM may call power module to set backlight
	 * targeting percent brightness
	 */
	unsigned int backlight_millipercent;
	/* DM may call power module to set backlight based on an explicit
	 * nits value.
	 */
	unsigned int backlight_millinit;
	unsigned int frame_ramp;
	bool smooth_brightness_enabled;
	bool isHDR;
};
struct power_entity {
	struct dc_stream_state *stream;
	struct psr_caps *caps;
	struct mod_power_psr_context *psr_context;

	/*PSR cached properties*/
	bool psr_enabled;
	unsigned int psr_events;
	unsigned int psr_power_opt;
	unsigned int replay_events;
};

struct pwr_backlight_properties {
	bool use_nits_based_brightness;
	bool disable_fractional_pwm;

	unsigned int min_abm_backlight;
	unsigned int num_backlight_levels;

	bool backlight_ramping_override;
	unsigned int backlight_ramping_reduction;
	unsigned int backlight_ramping_start;

	/* Backlight cached properties */
	unsigned int ac_backlight_percent;
	unsigned int dc_backlight_percent;

	/* backlight LUT stored in HW u16.16 format*/
	unsigned int *backlight_lut;
	unsigned int min_backlight_pwm;
	unsigned int max_backlight_pwm;
	unsigned int backlight_range;

	/* Describes the panel's min and max luminance in millinits measured
	 * on full white screen, in min and max backlight settings.
	 */
	unsigned int min_brightness_millinits;
	unsigned int max_brightness_millinits;
	unsigned int nits_range;

	/* Backlight control type of the associated link. Cached here so the
	 * brightness translation helpers can select the correct mapping
	 * (legacy vs. VESA AUX zero-anchored) without threading the type
	 * through every call.
	 */
	enum backlight_control_type backlight_control_type;

	bool backlight_caps_valid;
	bool use_custom_backlight_caps;
	unsigned int custom_backlight_caps_config_no;
	bool use_linear_backlight_curve;
};

struct dmcu_varibright_cached_properties {
	unsigned int varibright_config_setting;
	unsigned int varibright_level;
	unsigned int varibright_hw_level;
	unsigned int def_varibright_level;
	bool varibright_user_enable;
	bool varibright_active;
};

struct core_power {
	struct mod_power mod_public;
	struct dc *dc;
	struct power_entity *map;
	struct dmcu_varibright_cached_properties varibright_prop;
	struct pwr_backlight_properties bl_prop[MAX_NUM_EDP];
	struct backlight_state bl_state[MAX_NUM_EDP];
	unsigned int edp_num;

	bool psr_smu_optimizations_support;
	bool multi_disp_optimizations_support;

	unsigned int num_entities;
};

union dmcu_abm_set_bl_params {
	struct {
		unsigned int gradual_change : 1; /* [0:0] */
		unsigned int reserved : 15; /* [15:1] */
		unsigned int frame_ramp : 16; /* [31:16] */
	} bits;
	unsigned int u32All;
};
bool dmcu_load_iram(struct dmcu *dmcu,
		struct dmcu_iram_parameters params);
bool dmub_init_abm_config(struct resource_pool *res_pool,
		struct dmcu_iram_parameters params,
		unsigned int inst);

bool dmub_is_abm_supported(struct resource_pool *res_pool,
		unsigned int inst);
bool dmub_set_abm_event(struct resource_pool *res_pool,
		unsigned int full_screen, unsigned int trans_info,
		unsigned int hdr_mode, unsigned int scaling_enable,
		unsigned int scaling_strength_map, unsigned int inst);
bool dmub_set_abm_strength(struct resource_pool *res_pool,
		unsigned int strength,
		unsigned int inst);

void init_replay_config(struct dc_link *link, struct replay_config *pr_config);
void set_replay_coasting_vtotal(struct dc_link *link,
	enum replay_coasting_vtotal_type type,
	uint32_t vtotal);
void set_replay_defer_update_coasting_vtotal(struct dc_link *link,
	enum replay_coasting_vtotal_type type,
	uint32_t vtotal);
void set_replay_frame_skip_number(struct dc_link *link,
	enum replay_coasting_vtotal_type type,
	uint32_t coasting_vtotal_refresh_rate_Mhz,
	uint32_t flicker_free_refresh_rate_Mhz,
	bool is_defer);
void update_replay_coasting_vtotal_from_defer(struct dc_link *link,
	enum replay_coasting_vtotal_type type);
void set_replay_low_rr_full_screen_video_src_vtotal(struct dc_link *link, uint16_t vtotal);
void calculate_replay_link_off_frame_count(struct dc_link *link,
	uint16_t vtotal, uint16_t htotal);

bool is_psr_su_specific_panel(struct dc_link *link);
void mod_power_calc_psr_configs(struct psr_config *psr_config,
		struct dc_link *link,
		const struct dc_stream_state *stream);
bool mod_power_only_edp(const struct dc_state *context,
		const struct dc_stream_state *stream);
bool psr_su_set_dsc_slice_height(struct dc *dc, struct dc_link *link,
			      struct dc_stream_state *stream,
			      struct psr_config *config);

bool fill_custom_backlight_caps(unsigned int config_no,
		struct dm_acpi_atif_backlight_caps *caps);
void reset_replay_dsync_error_count(struct dc_link *link);
void change_replay_to_psr(struct dc_link *link);
void change_psr_to_replay(struct dc_link *link);
void initialize_backlight_caps(struct core_power *core_power, unsigned int inst);
void mod_power_set_backlight_control_type(struct core_power *core_power,
		unsigned int inst, enum backlight_control_type backlight_control_type);
unsigned int backlight_millipercent_to_pwm(
		struct core_power *core_power, unsigned int millipercent, unsigned int inst);
unsigned int backlight_millipercent_to_millinit(
		struct core_power *core_power, unsigned int millipercent, unsigned int inst);
void fill_backlight_level_params(struct core_power *core_power,
	struct set_backlight_level_params *backlight_level_params,
	int panel_inst, uint8_t aux_inst, unsigned int backlight_pwm,
	enum backlight_control_type backlight_control_type,
	unsigned int backlight_millinit, unsigned int transition_time_millisec,
	bool is_hdr);
bool mod_power_hw_init_backlight(struct mod_power *mod_power);
void mod_power_update_backlight_on_mode_change(
    struct core_power *core_power,
    struct dc_link *link,
    unsigned int panel_inst,
    uint8_t aux_inst,
    bool is_hdr);
unsigned int map_index_from_stream(struct core_power *core_power,
		const struct dc_stream_state *stream);
bool mod_power_psr_notify_mode_change(struct mod_power *mod_power,
	const struct dc_stream_state *stream,
	struct dc_link *link,
	unsigned int stream_index);
void mod_power_replay_notify_mode_change(struct mod_power *mod_power,
	struct dc *dc,
	struct dc_link *link,
	const struct dc_stream_state *stream,
	unsigned int stream_index);
#endif /* MODULES_POWER_POWER_HELPERS_H_ */