xref: /linux/drivers/gpu/drm/amd/display/modules/power/power_helpers.h (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
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 	bool backlight_caps_valid;
106 	bool use_custom_backlight_caps;
107 	unsigned int custom_backlight_caps_config_no;
108 	bool use_linear_backlight_curve;
109 };
110 
111 struct dmcu_varibright_cached_properties {
112 	unsigned int varibright_config_setting;
113 	unsigned int varibright_level;
114 	unsigned int varibright_hw_level;
115 	unsigned int def_varibright_level;
116 	bool varibright_user_enable;
117 	bool varibright_active;
118 };
119 
120 struct core_power {
121 	struct mod_power mod_public;
122 	struct dc *dc;
123 	struct power_entity *map;
124 	struct dmcu_varibright_cached_properties varibright_prop;
125 	struct pwr_backlight_properties bl_prop[MAX_NUM_EDP];
126 	struct backlight_state bl_state[MAX_NUM_EDP];
127 	unsigned int edp_num;
128 
129 	bool psr_smu_optimizations_support;
130 	bool multi_disp_optimizations_support;
131 
132 	unsigned int num_entities;
133 };
134 
135 union dmcu_abm_set_bl_params {
136 	struct {
137 		unsigned int gradual_change : 1; /* [0:0] */
138 		unsigned int reserved : 15; /* [15:1] */
139 		unsigned int frame_ramp : 16; /* [31:16] */
140 	} bits;
141 	unsigned int u32All;
142 };
143 bool dmcu_load_iram(struct dmcu *dmcu,
144 		struct dmcu_iram_parameters params);
145 bool dmub_init_abm_config(struct resource_pool *res_pool,
146 		struct dmcu_iram_parameters params,
147 		unsigned int inst);
148 
149 void init_replay_config(struct dc_link *link, struct replay_config *pr_config);
150 void set_replay_coasting_vtotal(struct dc_link *link,
151 	enum replay_coasting_vtotal_type type,
152 	uint32_t vtotal);
153 void set_replay_defer_update_coasting_vtotal(struct dc_link *link,
154 	enum replay_coasting_vtotal_type type,
155 	uint32_t vtotal);
156 void set_replay_frame_skip_number(struct dc_link *link,
157 	enum replay_coasting_vtotal_type type,
158 	uint32_t coasting_vtotal_refresh_rate_Mhz,
159 	uint32_t flicker_free_refresh_rate_Mhz,
160 	bool is_defer);
161 void update_replay_coasting_vtotal_from_defer(struct dc_link *link,
162 	enum replay_coasting_vtotal_type type);
163 void set_replay_low_rr_full_screen_video_src_vtotal(struct dc_link *link, uint16_t vtotal);
164 void calculate_replay_link_off_frame_count(struct dc_link *link,
165 	uint16_t vtotal, uint16_t htotal);
166 
167 bool is_psr_su_specific_panel(struct dc_link *link);
168 void mod_power_calc_psr_configs(struct psr_config *psr_config,
169 		struct dc_link *link,
170 		const struct dc_stream_state *stream);
171 bool mod_power_only_edp(const struct dc_state *context,
172 		const struct dc_stream_state *stream);
173 bool psr_su_set_dsc_slice_height(struct dc *dc, struct dc_link *link,
174 			      struct dc_stream_state *stream,
175 			      struct psr_config *config);
176 
177 bool fill_custom_backlight_caps(unsigned int config_no,
178 		struct dm_acpi_atif_backlight_caps *caps);
179 void reset_replay_dsync_error_count(struct dc_link *link);
180 void change_replay_to_psr(struct dc_link *link);
181 void change_psr_to_replay(struct dc_link *link);
182 void initialize_backlight_caps(struct core_power *core_power, unsigned int inst);
183 unsigned int backlight_millipercent_to_pwm(
184 		struct core_power *core_power, unsigned int millipercent, unsigned int inst);
185 unsigned int backlight_millipercent_to_millinit(
186 		struct core_power *core_power, unsigned int millipercent, unsigned int inst);
187 void fill_backlight_level_params(struct core_power *core_power,
188 	struct set_backlight_level_params *backlight_level_params,
189 	int panel_inst, uint8_t aux_inst, unsigned int backlight_pwm,
190 	enum backlight_control_type backlight_control_type,
191 	unsigned int backlight_millinit, unsigned int transition_time_millisec,
192 	bool is_hdr);
193 bool mod_power_hw_init_backlight(struct mod_power *mod_power);
194 void mod_power_update_backlight_on_mode_change(
195     struct core_power *core_power,
196     struct dc_link *link,
197     unsigned int panel_inst,
198     uint8_t aux_inst,
199     bool is_hdr);
200 unsigned int map_index_from_stream(struct core_power *core_power,
201 		const struct dc_stream_state *stream);
202 bool mod_power_psr_notify_mode_change(struct mod_power *mod_power,
203 	const struct dc_stream_state *stream,
204 	struct dc_link *link,
205 	unsigned int stream_index);
206 void mod_power_replay_notify_mode_change(struct mod_power *mod_power,
207 	struct dc *dc,
208 	struct dc_link *link,
209 	const struct dc_stream_state *stream,
210 	unsigned int stream_index);
211 #endif /* MODULES_POWER_POWER_HELPERS_H_ */
212