2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __AMDGPU_DPM_H__
24 #define __AMDGPU_DPM_H__
26 enum amdgpu_int_thermal_type {
28 THERMAL_TYPE_EXTERNAL,
29 THERMAL_TYPE_EXTERNAL_GPIO,
32 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
33 THERMAL_TYPE_EVERGREEN,
37 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
42 enum amdgpu_dpm_auto_throttle_src {
43 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
44 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
47 enum amdgpu_dpm_event_src {
48 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
49 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
50 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
51 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
52 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
56 u32 caps; /* vbios flags */
57 u32 class; /* vbios flags */
58 u32 class2; /* vbios flags */
66 enum amd_vce_level vce_level;
71 struct amdgpu_dpm_thermal {
72 /* thermal interrupt work */
73 struct work_struct work;
74 /* low temperature threshold */
76 /* high temperature threshold */
78 /* was last interrupt low to high or high to low */
80 /* interrupt source */
81 struct amdgpu_irq_src irq;
84 enum amdgpu_clk_action
90 struct amdgpu_blacklist_clocks
94 enum amdgpu_clk_action action;
97 struct amdgpu_clock_and_voltage_limits {
104 struct amdgpu_clock_array {
109 struct amdgpu_clock_voltage_dependency_entry {
114 struct amdgpu_clock_voltage_dependency_table {
116 struct amdgpu_clock_voltage_dependency_entry *entries;
119 union amdgpu_cac_leakage_entry {
131 struct amdgpu_cac_leakage_table {
133 union amdgpu_cac_leakage_entry *entries;
136 struct amdgpu_phase_shedding_limits_entry {
142 struct amdgpu_phase_shedding_limits_table {
144 struct amdgpu_phase_shedding_limits_entry *entries;
147 struct amdgpu_uvd_clock_voltage_dependency_entry {
153 struct amdgpu_uvd_clock_voltage_dependency_table {
155 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
158 struct amdgpu_vce_clock_voltage_dependency_entry {
164 struct amdgpu_vce_clock_voltage_dependency_table {
166 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
169 struct amdgpu_ppm_table {
173 u32 small_ac_platform_tdp;
175 u32 small_ac_platform_tdc;
182 struct amdgpu_cac_tdp_table {
184 u16 configurable_tdp;
186 u16 battery_power_limit;
187 u16 small_power_limit;
189 u16 high_cac_leakage;
190 u16 maximum_power_delivery_limit;
193 struct amdgpu_dpm_dynamic_state {
194 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
195 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
196 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
197 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
198 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
199 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
200 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
201 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
202 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
203 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
204 struct amdgpu_clock_array valid_sclk_values;
205 struct amdgpu_clock_array valid_mclk_values;
206 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
207 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
210 u16 vddc_vddci_delta;
211 u16 min_vddc_for_pcie_gen2;
212 struct amdgpu_cac_leakage_table cac_leakage_table;
213 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
214 struct amdgpu_ppm_table *ppm_table;
215 struct amdgpu_cac_tdp_table *cac_tdp_table;
218 struct amdgpu_dpm_fan {
229 u16 default_max_fan_pwm;
230 u16 default_fan_output_sensitivity;
231 u16 fan_output_sensitivity;
232 bool ucode_fan_control;
235 enum amdgpu_pcie_gen {
236 AMDGPU_PCIE_GEN1 = 0,
237 AMDGPU_PCIE_GEN2 = 1,
238 AMDGPU_PCIE_GEN3 = 2,
239 AMDGPU_PCIE_GEN_INVALID = 0xffff
242 enum amdgpu_dpm_forced_level {
243 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
244 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
245 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
246 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
249 struct amdgpu_dpm_funcs {
250 int (*get_temperature)(struct amdgpu_device *adev);
251 int (*pre_set_power_state)(struct amdgpu_device *adev);
252 int (*set_power_state)(struct amdgpu_device *adev);
253 void (*post_set_power_state)(struct amdgpu_device *adev);
254 void (*display_configuration_changed)(struct amdgpu_device *adev);
255 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
256 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
257 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
258 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
259 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
260 bool (*vblank_too_short)(struct amdgpu_device *adev);
261 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
262 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
263 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
264 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
265 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
266 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
267 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
268 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
269 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
270 int (*get_sclk_od)(struct amdgpu_device *adev);
271 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
272 int (*get_mclk_od)(struct amdgpu_device *adev);
273 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
274 int (*check_state_equal)(struct amdgpu_device *adev,
275 struct amdgpu_ps *cps,
276 struct amdgpu_ps *rps,
279 struct amd_vce_state* (*get_vce_clock_state)(struct amdgpu_device *adev, unsigned idx);
282 #define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
283 #define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
284 #define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
285 #define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
286 #define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
287 #define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
288 #define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
290 #define amdgpu_dpm_read_sensor(adev, idx, value) \
291 ((adev)->pp_enabled ? \
292 (adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value)) : \
295 #define amdgpu_dpm_get_temperature(adev) \
296 ((adev)->pp_enabled ? \
297 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
298 (adev)->pm.funcs->get_temperature((adev)))
300 #define amdgpu_dpm_set_fan_control_mode(adev, m) \
301 ((adev)->pp_enabled ? \
302 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
303 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
305 #define amdgpu_dpm_get_fan_control_mode(adev) \
306 ((adev)->pp_enabled ? \
307 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
308 (adev)->pm.funcs->get_fan_control_mode((adev)))
310 #define amdgpu_dpm_set_fan_speed_percent(adev, s) \
311 ((adev)->pp_enabled ? \
312 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
313 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
315 #define amdgpu_dpm_get_fan_speed_percent(adev, s) \
316 ((adev)->pp_enabled ? \
317 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
318 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
320 #define amdgpu_dpm_get_sclk(adev, l) \
321 ((adev)->pp_enabled ? \
322 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
323 (adev)->pm.funcs->get_sclk((adev), (l)))
325 #define amdgpu_dpm_get_mclk(adev, l) \
326 ((adev)->pp_enabled ? \
327 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
328 (adev)->pm.funcs->get_mclk((adev), (l)))
331 #define amdgpu_dpm_force_performance_level(adev, l) \
332 ((adev)->pp_enabled ? \
333 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
334 (adev)->pm.funcs->force_performance_level((adev), (l)))
336 #define amdgpu_dpm_powergate_uvd(adev, g) \
337 ((adev)->pp_enabled ? \
338 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
339 (adev)->pm.funcs->powergate_uvd((adev), (g)))
341 #define amdgpu_dpm_powergate_vce(adev, g) \
342 ((adev)->pp_enabled ? \
343 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
344 (adev)->pm.funcs->powergate_vce((adev), (g)))
346 #define amdgpu_dpm_get_current_power_state(adev) \
347 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
349 #define amdgpu_dpm_get_performance_level(adev) \
350 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
352 #define amdgpu_dpm_get_pp_num_states(adev, data) \
353 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
355 #define amdgpu_dpm_get_pp_table(adev, table) \
356 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
358 #define amdgpu_dpm_set_pp_table(adev, buf, size) \
359 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
361 #define amdgpu_dpm_print_clock_levels(adev, type, buf) \
362 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
364 #define amdgpu_dpm_force_clock_level(adev, type, level) \
365 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
367 #define amdgpu_dpm_get_sclk_od(adev) \
368 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
370 #define amdgpu_dpm_set_sclk_od(adev, value) \
371 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
373 #define amdgpu_dpm_get_mclk_od(adev) \
374 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
376 #define amdgpu_dpm_set_mclk_od(adev, value) \
377 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
379 #define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
380 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
382 #define amgdpu_dpm_check_state_equal(adev, cps, rps, equal) (adev)->pm.funcs->check_state_equal((adev), (cps),(rps),(equal))
384 #define amdgpu_dpm_get_vce_clock_state(adev, i) \
385 ((adev)->pp_enabled ? \
386 (adev)->powerplay.pp_funcs->get_vce_clock_state((adev)->powerplay.pp_handle, (i)) : \
387 (adev)->pm.funcs->get_vce_clock_state((adev), (i)))
390 struct amdgpu_ps *ps;
391 /* number of valid power states */
393 /* current power state that is active */
394 struct amdgpu_ps *current_ps;
395 /* requested power state */
396 struct amdgpu_ps *requested_ps;
397 /* boot up power state */
398 struct amdgpu_ps *boot_ps;
399 /* default uvd power state */
400 struct amdgpu_ps *uvd_ps;
401 /* vce requirements */
402 u32 num_of_vce_states;
403 struct amd_vce_state vce_states[AMD_MAX_VCE_LEVELS];
404 enum amd_vce_level vce_level;
405 enum amd_pm_state_type state;
406 enum amd_pm_state_type user_state;
408 u32 voltage_response_time;
409 u32 backbias_response_time;
411 u32 new_active_crtcs;
412 int new_active_crtc_count;
413 u32 current_active_crtcs;
414 int current_active_crtc_count;
415 struct amdgpu_dpm_dynamic_state dyn_state;
416 struct amdgpu_dpm_fan fan;
419 u32 near_tdp_limit_adjusted;
420 u32 sq_ramping_threshold;
427 /* special states active */
431 /* thermal handling */
432 struct amdgpu_dpm_thermal thermal;
434 enum amdgpu_dpm_forced_level forced_level;
443 struct amdgpu_i2c_chan *i2c_bus;
444 /* internal thermal controller on rv6xx+ */
445 enum amdgpu_int_thermal_type int_thermal_type;
446 struct device *int_hwmon_dev;
447 /* fan control parameters */
449 u8 fan_pulses_per_revolution;
454 bool sysfs_initialized;
455 struct amdgpu_dpm dpm;
456 const struct firmware *fw; /* SMC firmware */
458 const struct amdgpu_dpm_funcs *funcs;
459 uint32_t pcie_gen_mask;
460 uint32_t pcie_mlw_mask;
461 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
464 #define R600_SSTU_DFLT 0
465 #define R600_SST_DFLT 0x00C8
467 /* XXX are these ok? */
468 #define R600_TEMP_RANGE_MIN (90 * 1000)
469 #define R600_TEMP_RANGE_MAX (120 * 1000)
471 #define FDO_PWM_MODE_STATIC 1
472 #define FDO_PWM_MODE_STATIC_RPM 5
480 enum amdgpu_display_watermark {
481 AMDGPU_DISPLAY_WATERMARK_LOW = 0,
482 AMDGPU_DISPLAY_WATERMARK_HIGH = 1,
485 enum amdgpu_display_gap
487 AMDGPU_PM_DISPLAY_GAP_VBLANK_OR_WM = 0,
488 AMDGPU_PM_DISPLAY_GAP_VBLANK = 1,
489 AMDGPU_PM_DISPLAY_GAP_WATERMARK = 2,
490 AMDGPU_PM_DISPLAY_GAP_IGNORE = 3,
493 void amdgpu_dpm_print_class_info(u32 class, u32 class2);
494 void amdgpu_dpm_print_cap_info(u32 caps);
495 void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
496 struct amdgpu_ps *rps);
497 u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
498 u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
499 bool amdgpu_is_uvd_state(u32 class, u32 class2);
500 void amdgpu_calculate_u_and_p(u32 i, u32 r_c, u32 p_b,
502 int amdgpu_calculate_at(u32 t, u32 h, u32 fh, u32 fl, u32 *tl, u32 *th);
504 bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor);
506 int amdgpu_get_platform_caps(struct amdgpu_device *adev);
508 int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
509 void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
511 void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
513 enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
515 enum amdgpu_pcie_gen asic_gen,
516 enum amdgpu_pcie_gen default_gen);
518 u16 amdgpu_get_pcie_lane_support(struct amdgpu_device *adev,
521 u8 amdgpu_encode_pci_lane_width(u32 lanes);
523 struct amd_vce_state*
524 amdgpu_get_vce_clock_state(struct amdgpu_device *adev, unsigned idx);