2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
16 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
18 * OTHER DEALINGS IN THE SOFTWARE.
20 * Authors: Rafał Miłecki <zajec5@gmail.com>
21 * Alex Deucher <alexdeucher@gmail.com>
28 #include <linux/power_supply.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
32 #define RADEON_IDLE_LOOP_MS 100
33 #define RADEON_RECLOCK_DELAY_MS 200
34 #define RADEON_WAIT_VBLANK_TIMEOUT 200
36 static const char *radeon_pm_state_type_name
[5] = {
44 static void radeon_dynpm_idle_work_handler(struct work_struct
*work
);
45 static int radeon_debugfs_pm_init(struct radeon_device
*rdev
);
46 static bool radeon_pm_in_vbl(struct radeon_device
*rdev
);
47 static bool radeon_pm_debug_check_in_vbl(struct radeon_device
*rdev
, bool finish
);
48 static void radeon_pm_update_profile(struct radeon_device
*rdev
);
49 static void radeon_pm_set_clocks(struct radeon_device
*rdev
);
50 static void radeon_pm_compute_clocks_dpm(struct radeon_device
*rdev
);
52 int radeon_pm_get_type_index(struct radeon_device
*rdev
,
53 enum radeon_pm_state_type ps_type
,
57 int found_instance
= -1;
59 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
60 if (rdev
->pm
.power_state
[i
].type
== ps_type
) {
62 if (found_instance
== instance
)
66 /* return default if no match */
67 return rdev
->pm
.default_power_state_index
;
70 void radeon_pm_acpi_event_handler(struct radeon_device
*rdev
)
72 if ((rdev
->pm
.pm_method
== PM_METHOD_DPM
) && rdev
->pm
.dpm_enabled
) {
73 mutex_lock(&rdev
->pm
.mutex
);
74 if (power_supply_is_system_supplied() > 0)
75 rdev
->pm
.dpm
.ac_power
= true;
77 rdev
->pm
.dpm
.ac_power
= false;
78 if (rdev
->family
== CHIP_ARUBA
) {
79 if (rdev
->asic
->dpm
.enable_bapm
)
80 radeon_dpm_enable_bapm(rdev
, rdev
->pm
.dpm
.ac_power
);
82 mutex_unlock(&rdev
->pm
.mutex
);
83 /* allow new DPM state to be picked */
84 radeon_pm_compute_clocks_dpm(rdev
);
85 } else if (rdev
->pm
.pm_method
== PM_METHOD_PROFILE
) {
86 if (rdev
->pm
.profile
== PM_PROFILE_AUTO
) {
87 mutex_lock(&rdev
->pm
.mutex
);
88 radeon_pm_update_profile(rdev
);
89 radeon_pm_set_clocks(rdev
);
90 mutex_unlock(&rdev
->pm
.mutex
);
95 static void radeon_pm_update_profile(struct radeon_device
*rdev
)
97 switch (rdev
->pm
.profile
) {
98 case PM_PROFILE_DEFAULT
:
99 rdev
->pm
.profile_index
= PM_PROFILE_DEFAULT_IDX
;
101 case PM_PROFILE_AUTO
:
102 if (power_supply_is_system_supplied() > 0) {
103 if (rdev
->pm
.active_crtc_count
> 1)
104 rdev
->pm
.profile_index
= PM_PROFILE_HIGH_MH_IDX
;
106 rdev
->pm
.profile_index
= PM_PROFILE_HIGH_SH_IDX
;
108 if (rdev
->pm
.active_crtc_count
> 1)
109 rdev
->pm
.profile_index
= PM_PROFILE_MID_MH_IDX
;
111 rdev
->pm
.profile_index
= PM_PROFILE_MID_SH_IDX
;
115 if (rdev
->pm
.active_crtc_count
> 1)
116 rdev
->pm
.profile_index
= PM_PROFILE_LOW_MH_IDX
;
118 rdev
->pm
.profile_index
= PM_PROFILE_LOW_SH_IDX
;
121 if (rdev
->pm
.active_crtc_count
> 1)
122 rdev
->pm
.profile_index
= PM_PROFILE_MID_MH_IDX
;
124 rdev
->pm
.profile_index
= PM_PROFILE_MID_SH_IDX
;
126 case PM_PROFILE_HIGH
:
127 if (rdev
->pm
.active_crtc_count
> 1)
128 rdev
->pm
.profile_index
= PM_PROFILE_HIGH_MH_IDX
;
130 rdev
->pm
.profile_index
= PM_PROFILE_HIGH_SH_IDX
;
134 if (rdev
->pm
.active_crtc_count
== 0) {
135 rdev
->pm
.requested_power_state_index
=
136 rdev
->pm
.profiles
[rdev
->pm
.profile_index
].dpms_off_ps_idx
;
137 rdev
->pm
.requested_clock_mode_index
=
138 rdev
->pm
.profiles
[rdev
->pm
.profile_index
].dpms_off_cm_idx
;
140 rdev
->pm
.requested_power_state_index
=
141 rdev
->pm
.profiles
[rdev
->pm
.profile_index
].dpms_on_ps_idx
;
142 rdev
->pm
.requested_clock_mode_index
=
143 rdev
->pm
.profiles
[rdev
->pm
.profile_index
].dpms_on_cm_idx
;
147 static void radeon_unmap_vram_bos(struct radeon_device
*rdev
)
149 struct radeon_bo
*bo
, *n
;
151 if (list_empty(&rdev
->gem
.objects
))
154 list_for_each_entry_safe(bo
, n
, &rdev
->gem
.objects
, list
) {
155 if (bo
->tbo
.mem
.mem_type
== TTM_PL_VRAM
)
156 ttm_bo_unmap_virtual(&bo
->tbo
);
160 static void radeon_sync_with_vblank(struct radeon_device
*rdev
)
162 if (rdev
->pm
.active_crtcs
) {
163 rdev
->pm
.vblank_sync
= false;
165 rdev
->irq
.vblank_queue
, rdev
->pm
.vblank_sync
,
166 msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT
));
170 static void radeon_set_power_state(struct radeon_device
*rdev
)
173 bool misc_after
= false;
175 if ((rdev
->pm
.requested_clock_mode_index
== rdev
->pm
.current_clock_mode_index
) &&
176 (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
))
179 if (radeon_gui_idle(rdev
)) {
180 sclk
= rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
181 clock_info
[rdev
->pm
.requested_clock_mode_index
].sclk
;
182 if (sclk
> rdev
->pm
.default_sclk
)
183 sclk
= rdev
->pm
.default_sclk
;
185 /* starting with BTC, there is one state that is used for both
186 * MH and SH. Difference is that we always use the high clock index for
189 if ((rdev
->pm
.pm_method
== PM_METHOD_PROFILE
) &&
190 (rdev
->family
>= CHIP_BARTS
) &&
191 rdev
->pm
.active_crtc_count
&&
192 ((rdev
->pm
.profile_index
== PM_PROFILE_MID_MH_IDX
) ||
193 (rdev
->pm
.profile_index
== PM_PROFILE_LOW_MH_IDX
)))
194 mclk
= rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
195 clock_info
[rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
].mclk
;
197 mclk
= rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
198 clock_info
[rdev
->pm
.requested_clock_mode_index
].mclk
;
200 if (mclk
> rdev
->pm
.default_mclk
)
201 mclk
= rdev
->pm
.default_mclk
;
203 /* upvolt before raising clocks, downvolt after lowering clocks */
204 if (sclk
< rdev
->pm
.current_sclk
)
207 radeon_sync_with_vblank(rdev
);
209 if (rdev
->pm
.pm_method
== PM_METHOD_DYNPM
) {
210 if (!radeon_pm_in_vbl(rdev
))
214 radeon_pm_prepare(rdev
);
217 /* voltage, pcie lanes, etc.*/
218 radeon_pm_misc(rdev
);
220 /* set engine clock */
221 if (sclk
!= rdev
->pm
.current_sclk
) {
222 radeon_pm_debug_check_in_vbl(rdev
, false);
223 radeon_set_engine_clock(rdev
, sclk
);
224 radeon_pm_debug_check_in_vbl(rdev
, true);
225 rdev
->pm
.current_sclk
= sclk
;
226 DRM_DEBUG_DRIVER("Setting: e: %d\n", sclk
);
229 /* set memory clock */
230 if (rdev
->asic
->pm
.set_memory_clock
&& (mclk
!= rdev
->pm
.current_mclk
)) {
231 radeon_pm_debug_check_in_vbl(rdev
, false);
232 radeon_set_memory_clock(rdev
, mclk
);
233 radeon_pm_debug_check_in_vbl(rdev
, true);
234 rdev
->pm
.current_mclk
= mclk
;
235 DRM_DEBUG_DRIVER("Setting: m: %d\n", mclk
);
239 /* voltage, pcie lanes, etc.*/
240 radeon_pm_misc(rdev
);
242 radeon_pm_finish(rdev
);
244 rdev
->pm
.current_power_state_index
= rdev
->pm
.requested_power_state_index
;
245 rdev
->pm
.current_clock_mode_index
= rdev
->pm
.requested_clock_mode_index
;
247 DRM_DEBUG_DRIVER("pm: GUI not idle!!!\n");
250 static void radeon_pm_set_clocks(struct radeon_device
*rdev
)
252 struct drm_crtc
*crtc
;
255 /* no need to take locks, etc. if nothing's going to change */
256 if ((rdev
->pm
.requested_clock_mode_index
== rdev
->pm
.current_clock_mode_index
) &&
257 (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
))
260 down_write(&rdev
->pm
.mclk_lock
);
261 mutex_lock(&rdev
->ring_lock
);
263 /* wait for the rings to drain */
264 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++) {
265 struct radeon_ring
*ring
= &rdev
->ring
[i
];
269 r
= radeon_fence_wait_empty(rdev
, i
);
271 /* needs a GPU reset dont reset here */
272 mutex_unlock(&rdev
->ring_lock
);
273 up_write(&rdev
->pm
.mclk_lock
);
278 radeon_unmap_vram_bos(rdev
);
280 if (rdev
->irq
.installed
) {
282 drm_for_each_crtc(crtc
, rdev
->ddev
) {
283 if (rdev
->pm
.active_crtcs
& (1 << i
)) {
284 /* This can fail if a modeset is in progress */
285 if (drm_crtc_vblank_get(crtc
) == 0)
286 rdev
->pm
.req_vblank
|= (1 << i
);
288 DRM_DEBUG_DRIVER("crtc %d no vblank, can glitch\n",
295 radeon_set_power_state(rdev
);
297 if (rdev
->irq
.installed
) {
299 drm_for_each_crtc(crtc
, rdev
->ddev
) {
300 if (rdev
->pm
.req_vblank
& (1 << i
)) {
301 rdev
->pm
.req_vblank
&= ~(1 << i
);
302 drm_crtc_vblank_put(crtc
);
308 /* update display watermarks based on new power state */
309 radeon_update_bandwidth_info(rdev
);
310 if (rdev
->pm
.active_crtc_count
)
311 radeon_bandwidth_update(rdev
);
313 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_NONE
;
315 mutex_unlock(&rdev
->ring_lock
);
316 up_write(&rdev
->pm
.mclk_lock
);
319 static void radeon_pm_print_states(struct radeon_device
*rdev
)
322 struct radeon_power_state
*power_state
;
323 struct radeon_pm_clock_info
*clock_info
;
325 DRM_DEBUG_DRIVER("%d Power State(s)\n", rdev
->pm
.num_power_states
);
326 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
327 power_state
= &rdev
->pm
.power_state
[i
];
328 DRM_DEBUG_DRIVER("State %d: %s\n", i
,
329 radeon_pm_state_type_name
[power_state
->type
]);
330 if (i
== rdev
->pm
.default_power_state_index
)
331 DRM_DEBUG_DRIVER("\tDefault");
332 if ((rdev
->flags
& RADEON_IS_PCIE
) && !(rdev
->flags
& RADEON_IS_IGP
))
333 DRM_DEBUG_DRIVER("\t%d PCIE Lanes\n", power_state
->pcie_lanes
);
334 if (power_state
->flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
335 DRM_DEBUG_DRIVER("\tSingle display only\n");
336 DRM_DEBUG_DRIVER("\t%d Clock Mode(s)\n", power_state
->num_clock_modes
);
337 for (j
= 0; j
< power_state
->num_clock_modes
; j
++) {
338 clock_info
= &(power_state
->clock_info
[j
]);
339 if (rdev
->flags
& RADEON_IS_IGP
)
340 DRM_DEBUG_DRIVER("\t\t%d e: %d\n",
342 clock_info
->sclk
* 10);
344 DRM_DEBUG_DRIVER("\t\t%d e: %d\tm: %d\tv: %d\n",
346 clock_info
->sclk
* 10,
347 clock_info
->mclk
* 10,
348 clock_info
->voltage
.voltage
);
353 static ssize_t
radeon_get_pm_profile(struct device
*dev
,
354 struct device_attribute
*attr
,
357 struct drm_device
*ddev
= dev_get_drvdata(dev
);
358 struct radeon_device
*rdev
= ddev
->dev_private
;
359 int cp
= rdev
->pm
.profile
;
361 return snprintf(buf
, PAGE_SIZE
, "%s\n",
362 (cp
== PM_PROFILE_AUTO
) ? "auto" :
363 (cp
== PM_PROFILE_LOW
) ? "low" :
364 (cp
== PM_PROFILE_MID
) ? "mid" :
365 (cp
== PM_PROFILE_HIGH
) ? "high" : "default");
368 static ssize_t
radeon_set_pm_profile(struct device
*dev
,
369 struct device_attribute
*attr
,
373 struct drm_device
*ddev
= dev_get_drvdata(dev
);
374 struct radeon_device
*rdev
= ddev
->dev_private
;
376 /* Can't set profile when the card is off */
377 if ((rdev
->flags
& RADEON_IS_PX
) &&
378 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
))
381 mutex_lock(&rdev
->pm
.mutex
);
382 if (rdev
->pm
.pm_method
== PM_METHOD_PROFILE
) {
383 if (strncmp("default", buf
, strlen("default")) == 0)
384 rdev
->pm
.profile
= PM_PROFILE_DEFAULT
;
385 else if (strncmp("auto", buf
, strlen("auto")) == 0)
386 rdev
->pm
.profile
= PM_PROFILE_AUTO
;
387 else if (strncmp("low", buf
, strlen("low")) == 0)
388 rdev
->pm
.profile
= PM_PROFILE_LOW
;
389 else if (strncmp("mid", buf
, strlen("mid")) == 0)
390 rdev
->pm
.profile
= PM_PROFILE_MID
;
391 else if (strncmp("high", buf
, strlen("high")) == 0)
392 rdev
->pm
.profile
= PM_PROFILE_HIGH
;
397 radeon_pm_update_profile(rdev
);
398 radeon_pm_set_clocks(rdev
);
403 mutex_unlock(&rdev
->pm
.mutex
);
408 static ssize_t
radeon_get_pm_method(struct device
*dev
,
409 struct device_attribute
*attr
,
412 struct drm_device
*ddev
= dev_get_drvdata(dev
);
413 struct radeon_device
*rdev
= ddev
->dev_private
;
414 int pm
= rdev
->pm
.pm_method
;
416 return snprintf(buf
, PAGE_SIZE
, "%s\n",
417 (pm
== PM_METHOD_DYNPM
) ? "dynpm" :
418 (pm
== PM_METHOD_PROFILE
) ? "profile" : "dpm");
421 static ssize_t
radeon_set_pm_method(struct device
*dev
,
422 struct device_attribute
*attr
,
426 struct drm_device
*ddev
= dev_get_drvdata(dev
);
427 struct radeon_device
*rdev
= ddev
->dev_private
;
429 /* Can't set method when the card is off */
430 if ((rdev
->flags
& RADEON_IS_PX
) &&
431 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
)) {
436 /* we don't support the legacy modes with dpm */
437 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
) {
442 if (strncmp("dynpm", buf
, strlen("dynpm")) == 0) {
443 mutex_lock(&rdev
->pm
.mutex
);
444 rdev
->pm
.pm_method
= PM_METHOD_DYNPM
;
445 rdev
->pm
.dynpm_state
= DYNPM_STATE_PAUSED
;
446 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_DEFAULT
;
447 mutex_unlock(&rdev
->pm
.mutex
);
448 } else if (strncmp("profile", buf
, strlen("profile")) == 0) {
449 mutex_lock(&rdev
->pm
.mutex
);
451 rdev
->pm
.dynpm_state
= DYNPM_STATE_DISABLED
;
452 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_NONE
;
453 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
454 mutex_unlock(&rdev
->pm
.mutex
);
455 cancel_delayed_work_sync(&rdev
->pm
.dynpm_idle_work
);
460 radeon_pm_compute_clocks(rdev
);
465 static ssize_t
radeon_get_dpm_state(struct device
*dev
,
466 struct device_attribute
*attr
,
469 struct drm_device
*ddev
= dev_get_drvdata(dev
);
470 struct radeon_device
*rdev
= ddev
->dev_private
;
471 enum radeon_pm_state_type pm
= rdev
->pm
.dpm
.user_state
;
473 return snprintf(buf
, PAGE_SIZE
, "%s\n",
474 (pm
== POWER_STATE_TYPE_BATTERY
) ? "battery" :
475 (pm
== POWER_STATE_TYPE_BALANCED
) ? "balanced" : "performance");
478 static ssize_t
radeon_set_dpm_state(struct device
*dev
,
479 struct device_attribute
*attr
,
483 struct drm_device
*ddev
= dev_get_drvdata(dev
);
484 struct radeon_device
*rdev
= ddev
->dev_private
;
486 mutex_lock(&rdev
->pm
.mutex
);
487 if (strncmp("battery", buf
, strlen("battery")) == 0)
488 rdev
->pm
.dpm
.user_state
= POWER_STATE_TYPE_BATTERY
;
489 else if (strncmp("balanced", buf
, strlen("balanced")) == 0)
490 rdev
->pm
.dpm
.user_state
= POWER_STATE_TYPE_BALANCED
;
491 else if (strncmp("performance", buf
, strlen("performance")) == 0)
492 rdev
->pm
.dpm
.user_state
= POWER_STATE_TYPE_PERFORMANCE
;
494 mutex_unlock(&rdev
->pm
.mutex
);
498 mutex_unlock(&rdev
->pm
.mutex
);
500 /* Can't set dpm state when the card is off */
501 if (!(rdev
->flags
& RADEON_IS_PX
) ||
502 (ddev
->switch_power_state
== DRM_SWITCH_POWER_ON
))
503 radeon_pm_compute_clocks(rdev
);
509 static ssize_t
radeon_get_dpm_forced_performance_level(struct device
*dev
,
510 struct device_attribute
*attr
,
513 struct drm_device
*ddev
= dev_get_drvdata(dev
);
514 struct radeon_device
*rdev
= ddev
->dev_private
;
515 enum radeon_dpm_forced_level level
= rdev
->pm
.dpm
.forced_level
;
517 if ((rdev
->flags
& RADEON_IS_PX
) &&
518 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
))
519 return snprintf(buf
, PAGE_SIZE
, "off\n");
521 return snprintf(buf
, PAGE_SIZE
, "%s\n",
522 (level
== RADEON_DPM_FORCED_LEVEL_AUTO
) ? "auto" :
523 (level
== RADEON_DPM_FORCED_LEVEL_LOW
) ? "low" : "high");
526 static ssize_t
radeon_set_dpm_forced_performance_level(struct device
*dev
,
527 struct device_attribute
*attr
,
531 struct drm_device
*ddev
= dev_get_drvdata(dev
);
532 struct radeon_device
*rdev
= ddev
->dev_private
;
533 enum radeon_dpm_forced_level level
;
536 /* Can't force performance level when the card is off */
537 if ((rdev
->flags
& RADEON_IS_PX
) &&
538 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
))
541 mutex_lock(&rdev
->pm
.mutex
);
542 if (strncmp("low", buf
, strlen("low")) == 0) {
543 level
= RADEON_DPM_FORCED_LEVEL_LOW
;
544 } else if (strncmp("high", buf
, strlen("high")) == 0) {
545 level
= RADEON_DPM_FORCED_LEVEL_HIGH
;
546 } else if (strncmp("auto", buf
, strlen("auto")) == 0) {
547 level
= RADEON_DPM_FORCED_LEVEL_AUTO
;
552 if (rdev
->asic
->dpm
.force_performance_level
) {
553 if (rdev
->pm
.dpm
.thermal_active
) {
557 ret
= radeon_dpm_force_performance_level(rdev
, level
);
562 mutex_unlock(&rdev
->pm
.mutex
);
567 static ssize_t
radeon_hwmon_get_pwm1_enable(struct device
*dev
,
568 struct device_attribute
*attr
,
571 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
574 if (rdev
->asic
->dpm
.fan_ctrl_get_mode
)
575 pwm_mode
= rdev
->asic
->dpm
.fan_ctrl_get_mode(rdev
);
577 /* never 0 (full-speed), fuse or smc-controlled always */
578 return sprintf(buf
, "%i\n", pwm_mode
== FDO_PWM_MODE_STATIC
? 1 : 2);
581 static ssize_t
radeon_hwmon_set_pwm1_enable(struct device
*dev
,
582 struct device_attribute
*attr
,
586 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
590 if(!rdev
->asic
->dpm
.fan_ctrl_set_mode
)
593 err
= kstrtoint(buf
, 10, &value
);
598 case 1: /* manual, percent-based */
599 rdev
->asic
->dpm
.fan_ctrl_set_mode(rdev
, FDO_PWM_MODE_STATIC
);
601 default: /* disable */
602 rdev
->asic
->dpm
.fan_ctrl_set_mode(rdev
, 0);
609 static ssize_t
radeon_hwmon_get_pwm1_min(struct device
*dev
,
610 struct device_attribute
*attr
,
613 return sprintf(buf
, "%i\n", 0);
616 static ssize_t
radeon_hwmon_get_pwm1_max(struct device
*dev
,
617 struct device_attribute
*attr
,
620 return sprintf(buf
, "%i\n", 255);
623 static ssize_t
radeon_hwmon_set_pwm1(struct device
*dev
,
624 struct device_attribute
*attr
,
625 const char *buf
, size_t count
)
627 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
631 err
= kstrtou32(buf
, 10, &value
);
635 value
= (value
* 100) / 255;
637 err
= rdev
->asic
->dpm
.set_fan_speed_percent(rdev
, value
);
644 static ssize_t
radeon_hwmon_get_pwm1(struct device
*dev
,
645 struct device_attribute
*attr
,
648 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
652 err
= rdev
->asic
->dpm
.get_fan_speed_percent(rdev
, &speed
);
656 speed
= (speed
* 255) / 100;
658 return sprintf(buf
, "%i\n", speed
);
661 static DEVICE_ATTR(power_profile
, S_IRUGO
| S_IWUSR
, radeon_get_pm_profile
, radeon_set_pm_profile
);
662 static DEVICE_ATTR(power_method
, S_IRUGO
| S_IWUSR
, radeon_get_pm_method
, radeon_set_pm_method
);
663 static DEVICE_ATTR(power_dpm_state
, S_IRUGO
| S_IWUSR
, radeon_get_dpm_state
, radeon_set_dpm_state
);
664 static DEVICE_ATTR(power_dpm_force_performance_level
, S_IRUGO
| S_IWUSR
,
665 radeon_get_dpm_forced_performance_level
,
666 radeon_set_dpm_forced_performance_level
);
668 static ssize_t
radeon_hwmon_show_temp(struct device
*dev
,
669 struct device_attribute
*attr
,
672 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
673 struct drm_device
*ddev
= rdev
->ddev
;
676 /* Can't get temperature when the card is off */
677 if ((rdev
->flags
& RADEON_IS_PX
) &&
678 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
))
681 if (rdev
->asic
->pm
.get_temperature
)
682 temp
= radeon_get_temperature(rdev
);
686 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
);
689 static ssize_t
radeon_hwmon_show_temp_thresh(struct device
*dev
,
690 struct device_attribute
*attr
,
693 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
694 int hyst
= to_sensor_dev_attr(attr
)->index
;
698 temp
= rdev
->pm
.dpm
.thermal
.min_temp
;
700 temp
= rdev
->pm
.dpm
.thermal
.max_temp
;
702 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
);
705 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, radeon_hwmon_show_temp
, NULL
, 0);
706 static SENSOR_DEVICE_ATTR(temp1_crit
, S_IRUGO
, radeon_hwmon_show_temp_thresh
, NULL
, 0);
707 static SENSOR_DEVICE_ATTR(temp1_crit_hyst
, S_IRUGO
, radeon_hwmon_show_temp_thresh
, NULL
, 1);
708 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
| S_IWUSR
, radeon_hwmon_get_pwm1
, radeon_hwmon_set_pwm1
, 0);
709 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
| S_IWUSR
, radeon_hwmon_get_pwm1_enable
, radeon_hwmon_set_pwm1_enable
, 0);
710 static SENSOR_DEVICE_ATTR(pwm1_min
, S_IRUGO
, radeon_hwmon_get_pwm1_min
, NULL
, 0);
711 static SENSOR_DEVICE_ATTR(pwm1_max
, S_IRUGO
, radeon_hwmon_get_pwm1_max
, NULL
, 0);
714 static struct attribute
*hwmon_attributes
[] = {
715 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
716 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
717 &sensor_dev_attr_temp1_crit_hyst
.dev_attr
.attr
,
718 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
719 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
720 &sensor_dev_attr_pwm1_min
.dev_attr
.attr
,
721 &sensor_dev_attr_pwm1_max
.dev_attr
.attr
,
725 static umode_t
hwmon_attributes_visible(struct kobject
*kobj
,
726 struct attribute
*attr
, int index
)
728 struct device
*dev
= kobj_to_dev(kobj
);
729 struct radeon_device
*rdev
= dev_get_drvdata(dev
);
730 umode_t effective_mode
= attr
->mode
;
732 /* Skip attributes if DPM is not enabled */
733 if (rdev
->pm
.pm_method
!= PM_METHOD_DPM
&&
734 (attr
== &sensor_dev_attr_temp1_crit
.dev_attr
.attr
||
735 attr
== &sensor_dev_attr_temp1_crit_hyst
.dev_attr
.attr
||
736 attr
== &sensor_dev_attr_pwm1
.dev_attr
.attr
||
737 attr
== &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
||
738 attr
== &sensor_dev_attr_pwm1_max
.dev_attr
.attr
||
739 attr
== &sensor_dev_attr_pwm1_min
.dev_attr
.attr
))
742 /* Skip fan attributes if fan is not present */
743 if (rdev
->pm
.no_fan
&&
744 (attr
== &sensor_dev_attr_pwm1
.dev_attr
.attr
||
745 attr
== &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
||
746 attr
== &sensor_dev_attr_pwm1_max
.dev_attr
.attr
||
747 attr
== &sensor_dev_attr_pwm1_min
.dev_attr
.attr
))
750 /* mask fan attributes if we have no bindings for this asic to expose */
751 if ((!rdev
->asic
->dpm
.get_fan_speed_percent
&&
752 attr
== &sensor_dev_attr_pwm1
.dev_attr
.attr
) || /* can't query fan */
753 (!rdev
->asic
->dpm
.fan_ctrl_get_mode
&&
754 attr
== &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
)) /* can't query state */
755 effective_mode
&= ~S_IRUGO
;
757 if ((!rdev
->asic
->dpm
.set_fan_speed_percent
&&
758 attr
== &sensor_dev_attr_pwm1
.dev_attr
.attr
) || /* can't manage fan */
759 (!rdev
->asic
->dpm
.fan_ctrl_set_mode
&&
760 attr
== &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
)) /* can't manage state */
761 effective_mode
&= ~S_IWUSR
;
763 /* hide max/min values if we can't both query and manage the fan */
764 if ((!rdev
->asic
->dpm
.set_fan_speed_percent
&&
765 !rdev
->asic
->dpm
.get_fan_speed_percent
) &&
766 (attr
== &sensor_dev_attr_pwm1_max
.dev_attr
.attr
||
767 attr
== &sensor_dev_attr_pwm1_min
.dev_attr
.attr
))
770 return effective_mode
;
773 static const struct attribute_group hwmon_attrgroup
= {
774 .attrs
= hwmon_attributes
,
775 .is_visible
= hwmon_attributes_visible
,
778 static const struct attribute_group
*hwmon_groups
[] = {
783 static int radeon_hwmon_init(struct radeon_device
*rdev
)
787 switch (rdev
->pm
.int_thermal_type
) {
788 case THERMAL_TYPE_RV6XX
:
789 case THERMAL_TYPE_RV770
:
790 case THERMAL_TYPE_EVERGREEN
:
791 case THERMAL_TYPE_NI
:
792 case THERMAL_TYPE_SUMO
:
793 case THERMAL_TYPE_SI
:
794 case THERMAL_TYPE_CI
:
795 case THERMAL_TYPE_KV
:
796 if (rdev
->asic
->pm
.get_temperature
== NULL
)
798 rdev
->pm
.int_hwmon_dev
= hwmon_device_register_with_groups(rdev
->dev
,
801 if (IS_ERR(rdev
->pm
.int_hwmon_dev
)) {
802 err
= PTR_ERR(rdev
->pm
.int_hwmon_dev
);
804 "Unable to register hwmon device: %d\n", err
);
814 static void radeon_hwmon_fini(struct radeon_device
*rdev
)
816 if (rdev
->pm
.int_hwmon_dev
)
817 hwmon_device_unregister(rdev
->pm
.int_hwmon_dev
);
820 static void radeon_dpm_thermal_work_handler(struct work_struct
*work
)
822 struct radeon_device
*rdev
=
823 container_of(work
, struct radeon_device
,
824 pm
.dpm
.thermal
.work
);
825 /* switch to the thermal state */
826 enum radeon_pm_state_type dpm_state
= POWER_STATE_TYPE_INTERNAL_THERMAL
;
828 if (!rdev
->pm
.dpm_enabled
)
831 if (rdev
->asic
->pm
.get_temperature
) {
832 int temp
= radeon_get_temperature(rdev
);
834 if (temp
< rdev
->pm
.dpm
.thermal
.min_temp
)
835 /* switch back the user state */
836 dpm_state
= rdev
->pm
.dpm
.user_state
;
838 if (rdev
->pm
.dpm
.thermal
.high_to_low
)
839 /* switch back the user state */
840 dpm_state
= rdev
->pm
.dpm
.user_state
;
842 mutex_lock(&rdev
->pm
.mutex
);
843 if (dpm_state
== POWER_STATE_TYPE_INTERNAL_THERMAL
)
844 rdev
->pm
.dpm
.thermal_active
= true;
846 rdev
->pm
.dpm
.thermal_active
= false;
847 rdev
->pm
.dpm
.state
= dpm_state
;
848 mutex_unlock(&rdev
->pm
.mutex
);
850 radeon_pm_compute_clocks(rdev
);
853 static bool radeon_dpm_single_display(struct radeon_device
*rdev
)
855 bool single_display
= (rdev
->pm
.dpm
.new_active_crtc_count
< 2) ?
858 /* check if the vblank period is too short to adjust the mclk */
859 if (single_display
&& rdev
->asic
->dpm
.vblank_too_short
) {
860 if (radeon_dpm_vblank_too_short(rdev
))
861 single_display
= false;
864 /* 120hz tends to be problematic even if they are under the
867 if (single_display
&& (r600_dpm_get_vrefresh(rdev
) >= 120))
868 single_display
= false;
870 return single_display
;
873 static struct radeon_ps
*radeon_dpm_pick_power_state(struct radeon_device
*rdev
,
874 enum radeon_pm_state_type dpm_state
)
877 struct radeon_ps
*ps
;
879 bool single_display
= radeon_dpm_single_display(rdev
);
881 /* certain older asics have a separare 3D performance state,
882 * so try that first if the user selected performance
884 if (dpm_state
== POWER_STATE_TYPE_PERFORMANCE
)
885 dpm_state
= POWER_STATE_TYPE_INTERNAL_3DPERF
;
886 /* balanced states don't exist at the moment */
887 if (dpm_state
== POWER_STATE_TYPE_BALANCED
)
888 dpm_state
= rdev
->pm
.dpm
.ac_power
?
889 POWER_STATE_TYPE_PERFORMANCE
: POWER_STATE_TYPE_BATTERY
;
892 /* Pick the best power state based on current conditions */
893 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
894 ps
= &rdev
->pm
.dpm
.ps
[i
];
895 ui_class
= ps
->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK
;
898 case POWER_STATE_TYPE_BATTERY
:
899 if (ui_class
== ATOM_PPLIB_CLASSIFICATION_UI_BATTERY
) {
900 if (ps
->caps
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
) {
907 case POWER_STATE_TYPE_BALANCED
:
908 if (ui_class
== ATOM_PPLIB_CLASSIFICATION_UI_BALANCED
) {
909 if (ps
->caps
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
) {
916 case POWER_STATE_TYPE_PERFORMANCE
:
917 if (ui_class
== ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE
) {
918 if (ps
->caps
& ATOM_PPLIB_SINGLE_DISPLAY_ONLY
) {
925 /* internal states */
926 case POWER_STATE_TYPE_INTERNAL_UVD
:
927 if (rdev
->pm
.dpm
.uvd_ps
)
928 return rdev
->pm
.dpm
.uvd_ps
;
931 case POWER_STATE_TYPE_INTERNAL_UVD_SD
:
932 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE
)
935 case POWER_STATE_TYPE_INTERNAL_UVD_HD
:
936 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE
)
939 case POWER_STATE_TYPE_INTERNAL_UVD_HD2
:
940 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE
)
943 case POWER_STATE_TYPE_INTERNAL_UVD_MVC
:
944 if (ps
->class2
& ATOM_PPLIB_CLASSIFICATION2_MVC
)
947 case POWER_STATE_TYPE_INTERNAL_BOOT
:
948 return rdev
->pm
.dpm
.boot_ps
;
949 case POWER_STATE_TYPE_INTERNAL_THERMAL
:
950 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_THERMAL
)
953 case POWER_STATE_TYPE_INTERNAL_ACPI
:
954 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_ACPI
)
957 case POWER_STATE_TYPE_INTERNAL_ULV
:
958 if (ps
->class2
& ATOM_PPLIB_CLASSIFICATION2_ULV
)
961 case POWER_STATE_TYPE_INTERNAL_3DPERF
:
962 if (ps
->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE
)
969 /* use a fallback state if we didn't match */
971 case POWER_STATE_TYPE_INTERNAL_UVD_SD
:
972 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD_HD
;
974 case POWER_STATE_TYPE_INTERNAL_UVD_HD
:
975 case POWER_STATE_TYPE_INTERNAL_UVD_HD2
:
976 case POWER_STATE_TYPE_INTERNAL_UVD_MVC
:
977 if (rdev
->pm
.dpm
.uvd_ps
) {
978 return rdev
->pm
.dpm
.uvd_ps
;
980 dpm_state
= POWER_STATE_TYPE_PERFORMANCE
;
983 case POWER_STATE_TYPE_INTERNAL_THERMAL
:
984 dpm_state
= POWER_STATE_TYPE_INTERNAL_ACPI
;
986 case POWER_STATE_TYPE_INTERNAL_ACPI
:
987 dpm_state
= POWER_STATE_TYPE_BATTERY
;
989 case POWER_STATE_TYPE_BATTERY
:
990 case POWER_STATE_TYPE_BALANCED
:
991 case POWER_STATE_TYPE_INTERNAL_3DPERF
:
992 dpm_state
= POWER_STATE_TYPE_PERFORMANCE
;
1001 static void radeon_dpm_change_power_state_locked(struct radeon_device
*rdev
)
1004 struct radeon_ps
*ps
;
1005 enum radeon_pm_state_type dpm_state
;
1007 bool single_display
= radeon_dpm_single_display(rdev
);
1009 /* if dpm init failed */
1010 if (!rdev
->pm
.dpm_enabled
)
1013 if (rdev
->pm
.dpm
.user_state
!= rdev
->pm
.dpm
.state
) {
1014 /* add other state override checks here */
1015 if ((!rdev
->pm
.dpm
.thermal_active
) &&
1016 (!rdev
->pm
.dpm
.uvd_active
))
1017 rdev
->pm
.dpm
.state
= rdev
->pm
.dpm
.user_state
;
1019 dpm_state
= rdev
->pm
.dpm
.state
;
1021 ps
= radeon_dpm_pick_power_state(rdev
, dpm_state
);
1023 rdev
->pm
.dpm
.requested_ps
= ps
;
1027 /* no need to reprogram if nothing changed unless we are on BTC+ */
1028 if (rdev
->pm
.dpm
.current_ps
== rdev
->pm
.dpm
.requested_ps
) {
1029 /* vce just modifies an existing state so force a change */
1030 if (ps
->vce_active
!= rdev
->pm
.dpm
.vce_active
)
1032 /* user has made a display change (such as timing) */
1033 if (rdev
->pm
.dpm
.single_display
!= single_display
)
1035 if ((rdev
->family
< CHIP_BARTS
) || (rdev
->flags
& RADEON_IS_IGP
)) {
1036 /* for pre-BTC and APUs if the num crtcs changed but state is the same,
1037 * all we need to do is update the display configuration.
1039 if (rdev
->pm
.dpm
.new_active_crtcs
!= rdev
->pm
.dpm
.current_active_crtcs
) {
1040 /* update display watermarks based on new power state */
1041 radeon_bandwidth_update(rdev
);
1042 /* update displays */
1043 radeon_dpm_display_configuration_changed(rdev
);
1044 rdev
->pm
.dpm
.current_active_crtcs
= rdev
->pm
.dpm
.new_active_crtcs
;
1045 rdev
->pm
.dpm
.current_active_crtc_count
= rdev
->pm
.dpm
.new_active_crtc_count
;
1049 /* for BTC+ if the num crtcs hasn't changed and state is the same,
1050 * nothing to do, if the num crtcs is > 1 and state is the same,
1051 * update display configuration.
1053 if (rdev
->pm
.dpm
.new_active_crtcs
==
1054 rdev
->pm
.dpm
.current_active_crtcs
) {
1057 if ((rdev
->pm
.dpm
.current_active_crtc_count
> 1) &&
1058 (rdev
->pm
.dpm
.new_active_crtc_count
> 1)) {
1059 /* update display watermarks based on new power state */
1060 radeon_bandwidth_update(rdev
);
1061 /* update displays */
1062 radeon_dpm_display_configuration_changed(rdev
);
1063 rdev
->pm
.dpm
.current_active_crtcs
= rdev
->pm
.dpm
.new_active_crtcs
;
1064 rdev
->pm
.dpm
.current_active_crtc_count
= rdev
->pm
.dpm
.new_active_crtc_count
;
1072 if (radeon_dpm
== 1) {
1073 printk("switching from power state:\n");
1074 radeon_dpm_print_power_state(rdev
, rdev
->pm
.dpm
.current_ps
);
1075 printk("switching to power state:\n");
1076 radeon_dpm_print_power_state(rdev
, rdev
->pm
.dpm
.requested_ps
);
1079 down_write(&rdev
->pm
.mclk_lock
);
1080 mutex_lock(&rdev
->ring_lock
);
1082 /* update whether vce is active */
1083 ps
->vce_active
= rdev
->pm
.dpm
.vce_active
;
1085 ret
= radeon_dpm_pre_set_power_state(rdev
);
1089 /* update display watermarks based on new power state */
1090 radeon_bandwidth_update(rdev
);
1091 /* update displays */
1092 radeon_dpm_display_configuration_changed(rdev
);
1094 /* wait for the rings to drain */
1095 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++) {
1096 struct radeon_ring
*ring
= &rdev
->ring
[i
];
1098 radeon_fence_wait_empty(rdev
, i
);
1101 /* program the new power state */
1102 radeon_dpm_set_power_state(rdev
);
1104 /* update current power state */
1105 rdev
->pm
.dpm
.current_ps
= rdev
->pm
.dpm
.requested_ps
;
1107 radeon_dpm_post_set_power_state(rdev
);
1109 rdev
->pm
.dpm
.current_active_crtcs
= rdev
->pm
.dpm
.new_active_crtcs
;
1110 rdev
->pm
.dpm
.current_active_crtc_count
= rdev
->pm
.dpm
.new_active_crtc_count
;
1111 rdev
->pm
.dpm
.single_display
= single_display
;
1113 if (rdev
->asic
->dpm
.force_performance_level
) {
1114 if (rdev
->pm
.dpm
.thermal_active
) {
1115 enum radeon_dpm_forced_level level
= rdev
->pm
.dpm
.forced_level
;
1116 /* force low perf level for thermal */
1117 radeon_dpm_force_performance_level(rdev
, RADEON_DPM_FORCED_LEVEL_LOW
);
1118 /* save the user's level */
1119 rdev
->pm
.dpm
.forced_level
= level
;
1121 /* otherwise, user selected level */
1122 radeon_dpm_force_performance_level(rdev
, rdev
->pm
.dpm
.forced_level
);
1127 mutex_unlock(&rdev
->ring_lock
);
1128 up_write(&rdev
->pm
.mclk_lock
);
1131 void radeon_dpm_enable_uvd(struct radeon_device
*rdev
, bool enable
)
1133 enum radeon_pm_state_type dpm_state
;
1135 if (rdev
->asic
->dpm
.powergate_uvd
) {
1136 mutex_lock(&rdev
->pm
.mutex
);
1137 /* don't powergate anything if we
1138 have active but pause streams */
1139 enable
|= rdev
->pm
.dpm
.sd
> 0;
1140 enable
|= rdev
->pm
.dpm
.hd
> 0;
1141 /* enable/disable UVD */
1142 radeon_dpm_powergate_uvd(rdev
, !enable
);
1143 mutex_unlock(&rdev
->pm
.mutex
);
1146 mutex_lock(&rdev
->pm
.mutex
);
1147 rdev
->pm
.dpm
.uvd_active
= true;
1148 /* disable this for now */
1150 if ((rdev
->pm
.dpm
.sd
== 1) && (rdev
->pm
.dpm
.hd
== 0))
1151 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD_SD
;
1152 else if ((rdev
->pm
.dpm
.sd
== 2) && (rdev
->pm
.dpm
.hd
== 0))
1153 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD_HD
;
1154 else if ((rdev
->pm
.dpm
.sd
== 0) && (rdev
->pm
.dpm
.hd
== 1))
1155 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD_HD
;
1156 else if ((rdev
->pm
.dpm
.sd
== 0) && (rdev
->pm
.dpm
.hd
== 2))
1157 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD_HD2
;
1160 dpm_state
= POWER_STATE_TYPE_INTERNAL_UVD
;
1161 rdev
->pm
.dpm
.state
= dpm_state
;
1162 mutex_unlock(&rdev
->pm
.mutex
);
1164 mutex_lock(&rdev
->pm
.mutex
);
1165 rdev
->pm
.dpm
.uvd_active
= false;
1166 mutex_unlock(&rdev
->pm
.mutex
);
1169 radeon_pm_compute_clocks(rdev
);
1173 void radeon_dpm_enable_vce(struct radeon_device
*rdev
, bool enable
)
1176 mutex_lock(&rdev
->pm
.mutex
);
1177 rdev
->pm
.dpm
.vce_active
= true;
1178 /* XXX select vce level based on ring/task */
1179 rdev
->pm
.dpm
.vce_level
= RADEON_VCE_LEVEL_AC_ALL
;
1180 mutex_unlock(&rdev
->pm
.mutex
);
1182 mutex_lock(&rdev
->pm
.mutex
);
1183 rdev
->pm
.dpm
.vce_active
= false;
1184 mutex_unlock(&rdev
->pm
.mutex
);
1187 radeon_pm_compute_clocks(rdev
);
1190 static void radeon_pm_suspend_old(struct radeon_device
*rdev
)
1192 mutex_lock(&rdev
->pm
.mutex
);
1193 if (rdev
->pm
.pm_method
== PM_METHOD_DYNPM
) {
1194 if (rdev
->pm
.dynpm_state
== DYNPM_STATE_ACTIVE
)
1195 rdev
->pm
.dynpm_state
= DYNPM_STATE_SUSPENDED
;
1197 mutex_unlock(&rdev
->pm
.mutex
);
1199 cancel_delayed_work_sync(&rdev
->pm
.dynpm_idle_work
);
1202 static void radeon_pm_suspend_dpm(struct radeon_device
*rdev
)
1204 mutex_lock(&rdev
->pm
.mutex
);
1206 radeon_dpm_disable(rdev
);
1207 /* reset the power state */
1208 rdev
->pm
.dpm
.current_ps
= rdev
->pm
.dpm
.requested_ps
= rdev
->pm
.dpm
.boot_ps
;
1209 rdev
->pm
.dpm_enabled
= false;
1210 mutex_unlock(&rdev
->pm
.mutex
);
1213 void radeon_pm_suspend(struct radeon_device
*rdev
)
1215 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
1216 radeon_pm_suspend_dpm(rdev
);
1218 radeon_pm_suspend_old(rdev
);
1221 static void radeon_pm_resume_old(struct radeon_device
*rdev
)
1223 /* set up the default clocks if the MC ucode is loaded */
1224 if ((rdev
->family
>= CHIP_BARTS
) &&
1225 (rdev
->family
<= CHIP_CAYMAN
) &&
1227 if (rdev
->pm
.default_vddc
)
1228 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddc
,
1229 SET_VOLTAGE_TYPE_ASIC_VDDC
);
1230 if (rdev
->pm
.default_vddci
)
1231 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddci
,
1232 SET_VOLTAGE_TYPE_ASIC_VDDCI
);
1233 if (rdev
->pm
.default_sclk
)
1234 radeon_set_engine_clock(rdev
, rdev
->pm
.default_sclk
);
1235 if (rdev
->pm
.default_mclk
)
1236 radeon_set_memory_clock(rdev
, rdev
->pm
.default_mclk
);
1238 /* asic init will reset the default power state */
1239 mutex_lock(&rdev
->pm
.mutex
);
1240 rdev
->pm
.current_power_state_index
= rdev
->pm
.default_power_state_index
;
1241 rdev
->pm
.current_clock_mode_index
= 0;
1242 rdev
->pm
.current_sclk
= rdev
->pm
.default_sclk
;
1243 rdev
->pm
.current_mclk
= rdev
->pm
.default_mclk
;
1244 if (rdev
->pm
.power_state
) {
1245 rdev
->pm
.current_vddc
= rdev
->pm
.power_state
[rdev
->pm
.default_power_state_index
].clock_info
[0].voltage
.voltage
;
1246 rdev
->pm
.current_vddci
= rdev
->pm
.power_state
[rdev
->pm
.default_power_state_index
].clock_info
[0].voltage
.vddci
;
1248 if (rdev
->pm
.pm_method
== PM_METHOD_DYNPM
1249 && rdev
->pm
.dynpm_state
== DYNPM_STATE_SUSPENDED
) {
1250 rdev
->pm
.dynpm_state
= DYNPM_STATE_ACTIVE
;
1251 schedule_delayed_work(&rdev
->pm
.dynpm_idle_work
,
1252 msecs_to_jiffies(RADEON_IDLE_LOOP_MS
));
1254 mutex_unlock(&rdev
->pm
.mutex
);
1255 radeon_pm_compute_clocks(rdev
);
1258 static void radeon_pm_resume_dpm(struct radeon_device
*rdev
)
1262 /* asic init will reset to the boot state */
1263 mutex_lock(&rdev
->pm
.mutex
);
1264 rdev
->pm
.dpm
.current_ps
= rdev
->pm
.dpm
.requested_ps
= rdev
->pm
.dpm
.boot_ps
;
1265 radeon_dpm_setup_asic(rdev
);
1266 ret
= radeon_dpm_enable(rdev
);
1267 mutex_unlock(&rdev
->pm
.mutex
);
1269 goto dpm_resume_fail
;
1270 rdev
->pm
.dpm_enabled
= true;
1274 DRM_ERROR("radeon: dpm resume failed\n");
1275 if ((rdev
->family
>= CHIP_BARTS
) &&
1276 (rdev
->family
<= CHIP_CAYMAN
) &&
1278 if (rdev
->pm
.default_vddc
)
1279 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddc
,
1280 SET_VOLTAGE_TYPE_ASIC_VDDC
);
1281 if (rdev
->pm
.default_vddci
)
1282 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddci
,
1283 SET_VOLTAGE_TYPE_ASIC_VDDCI
);
1284 if (rdev
->pm
.default_sclk
)
1285 radeon_set_engine_clock(rdev
, rdev
->pm
.default_sclk
);
1286 if (rdev
->pm
.default_mclk
)
1287 radeon_set_memory_clock(rdev
, rdev
->pm
.default_mclk
);
1291 void radeon_pm_resume(struct radeon_device
*rdev
)
1293 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
1294 radeon_pm_resume_dpm(rdev
);
1296 radeon_pm_resume_old(rdev
);
1299 static int radeon_pm_init_old(struct radeon_device
*rdev
)
1303 rdev
->pm
.profile
= PM_PROFILE_DEFAULT
;
1304 rdev
->pm
.dynpm_state
= DYNPM_STATE_DISABLED
;
1305 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_NONE
;
1306 rdev
->pm
.dynpm_can_upclock
= true;
1307 rdev
->pm
.dynpm_can_downclock
= true;
1308 rdev
->pm
.default_sclk
= rdev
->clock
.default_sclk
;
1309 rdev
->pm
.default_mclk
= rdev
->clock
.default_mclk
;
1310 rdev
->pm
.current_sclk
= rdev
->clock
.default_sclk
;
1311 rdev
->pm
.current_mclk
= rdev
->clock
.default_mclk
;
1312 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_NONE
;
1315 if (rdev
->is_atom_bios
)
1316 radeon_atombios_get_power_modes(rdev
);
1318 radeon_combios_get_power_modes(rdev
);
1319 radeon_pm_print_states(rdev
);
1320 radeon_pm_init_profile(rdev
);
1321 /* set up the default clocks if the MC ucode is loaded */
1322 if ((rdev
->family
>= CHIP_BARTS
) &&
1323 (rdev
->family
<= CHIP_CAYMAN
) &&
1325 if (rdev
->pm
.default_vddc
)
1326 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddc
,
1327 SET_VOLTAGE_TYPE_ASIC_VDDC
);
1328 if (rdev
->pm
.default_vddci
)
1329 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddci
,
1330 SET_VOLTAGE_TYPE_ASIC_VDDCI
);
1331 if (rdev
->pm
.default_sclk
)
1332 radeon_set_engine_clock(rdev
, rdev
->pm
.default_sclk
);
1333 if (rdev
->pm
.default_mclk
)
1334 radeon_set_memory_clock(rdev
, rdev
->pm
.default_mclk
);
1338 /* set up the internal thermal sensor if applicable */
1339 ret
= radeon_hwmon_init(rdev
);
1343 INIT_DELAYED_WORK(&rdev
->pm
.dynpm_idle_work
, radeon_dynpm_idle_work_handler
);
1345 if (rdev
->pm
.num_power_states
> 1) {
1346 if (radeon_debugfs_pm_init(rdev
)) {
1347 DRM_ERROR("Failed to register debugfs file for PM!\n");
1350 DRM_INFO("radeon: power management initialized\n");
1356 static void radeon_dpm_print_power_states(struct radeon_device
*rdev
)
1360 for (i
= 0; i
< rdev
->pm
.dpm
.num_ps
; i
++) {
1361 printk("== power state %d ==\n", i
);
1362 radeon_dpm_print_power_state(rdev
, &rdev
->pm
.dpm
.ps
[i
]);
1366 static int radeon_pm_init_dpm(struct radeon_device
*rdev
)
1370 /* default to balanced state */
1371 rdev
->pm
.dpm
.state
= POWER_STATE_TYPE_BALANCED
;
1372 rdev
->pm
.dpm
.user_state
= POWER_STATE_TYPE_BALANCED
;
1373 rdev
->pm
.dpm
.forced_level
= RADEON_DPM_FORCED_LEVEL_AUTO
;
1374 rdev
->pm
.default_sclk
= rdev
->clock
.default_sclk
;
1375 rdev
->pm
.default_mclk
= rdev
->clock
.default_mclk
;
1376 rdev
->pm
.current_sclk
= rdev
->clock
.default_sclk
;
1377 rdev
->pm
.current_mclk
= rdev
->clock
.default_mclk
;
1378 rdev
->pm
.int_thermal_type
= THERMAL_TYPE_NONE
;
1380 if (rdev
->bios
&& rdev
->is_atom_bios
)
1381 radeon_atombios_get_power_modes(rdev
);
1385 /* set up the internal thermal sensor if applicable */
1386 ret
= radeon_hwmon_init(rdev
);
1390 INIT_WORK(&rdev
->pm
.dpm
.thermal
.work
, radeon_dpm_thermal_work_handler
);
1391 mutex_lock(&rdev
->pm
.mutex
);
1392 radeon_dpm_init(rdev
);
1393 rdev
->pm
.dpm
.current_ps
= rdev
->pm
.dpm
.requested_ps
= rdev
->pm
.dpm
.boot_ps
;
1394 if (radeon_dpm
== 1)
1395 radeon_dpm_print_power_states(rdev
);
1396 radeon_dpm_setup_asic(rdev
);
1397 ret
= radeon_dpm_enable(rdev
);
1398 mutex_unlock(&rdev
->pm
.mutex
);
1401 rdev
->pm
.dpm_enabled
= true;
1403 if (radeon_debugfs_pm_init(rdev
)) {
1404 DRM_ERROR("Failed to register debugfs file for dpm!\n");
1407 DRM_INFO("radeon: dpm initialized\n");
1412 rdev
->pm
.dpm_enabled
= false;
1413 if ((rdev
->family
>= CHIP_BARTS
) &&
1414 (rdev
->family
<= CHIP_CAYMAN
) &&
1416 if (rdev
->pm
.default_vddc
)
1417 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddc
,
1418 SET_VOLTAGE_TYPE_ASIC_VDDC
);
1419 if (rdev
->pm
.default_vddci
)
1420 radeon_atom_set_voltage(rdev
, rdev
->pm
.default_vddci
,
1421 SET_VOLTAGE_TYPE_ASIC_VDDCI
);
1422 if (rdev
->pm
.default_sclk
)
1423 radeon_set_engine_clock(rdev
, rdev
->pm
.default_sclk
);
1424 if (rdev
->pm
.default_mclk
)
1425 radeon_set_memory_clock(rdev
, rdev
->pm
.default_mclk
);
1427 DRM_ERROR("radeon: dpm initialization failed\n");
1431 struct radeon_dpm_quirk
{
1438 /* cards with dpm stability problems */
1439 static struct radeon_dpm_quirk radeon_dpm_quirk_list
[] = {
1440 /* TURKS - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1386534 */
1441 { PCI_VENDOR_ID_ATI
, 0x6759, 0x1682, 0x3195 },
1442 /* TURKS - https://bugzilla.kernel.org/show_bug.cgi?id=83731 */
1443 { PCI_VENDOR_ID_ATI
, 0x6840, 0x1179, 0xfb81 },
1447 int radeon_pm_init(struct radeon_device
*rdev
)
1449 struct radeon_dpm_quirk
*p
= radeon_dpm_quirk_list
;
1450 bool disable_dpm
= false;
1452 /* Apply dpm quirks */
1453 while (p
&& p
->chip_device
!= 0) {
1454 if (rdev
->pdev
->vendor
== p
->chip_vendor
&&
1455 rdev
->pdev
->device
== p
->chip_device
&&
1456 rdev
->pdev
->subsystem_vendor
== p
->subsys_vendor
&&
1457 rdev
->pdev
->subsystem_device
== p
->subsys_device
) {
1464 /* enable dpm on rv6xx+ */
1465 switch (rdev
->family
) {
1474 /* DPM requires the RLC, RV770+ dGPU requires SMC */
1476 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1477 else if ((rdev
->family
>= CHIP_RV770
) &&
1478 (!(rdev
->flags
& RADEON_IS_IGP
)) &&
1480 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1481 else if (radeon_dpm
== 1)
1482 rdev
->pm
.pm_method
= PM_METHOD_DPM
;
1484 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1512 /* DPM requires the RLC, RV770+ dGPU requires SMC */
1514 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1515 else if ((rdev
->family
>= CHIP_RV770
) &&
1516 (!(rdev
->flags
& RADEON_IS_IGP
)) &&
1518 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1519 else if (disable_dpm
&& (radeon_dpm
== -1))
1520 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1521 else if (radeon_dpm
== 0)
1522 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1524 rdev
->pm
.pm_method
= PM_METHOD_DPM
;
1527 /* default to profile method */
1528 rdev
->pm
.pm_method
= PM_METHOD_PROFILE
;
1532 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
1533 return radeon_pm_init_dpm(rdev
);
1535 return radeon_pm_init_old(rdev
);
1538 int radeon_pm_late_init(struct radeon_device
*rdev
)
1542 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
) {
1543 if (rdev
->pm
.dpm_enabled
) {
1544 if (!rdev
->pm
.sysfs_initialized
) {
1545 ret
= device_create_file(rdev
->dev
, &dev_attr_power_dpm_state
);
1547 DRM_ERROR("failed to create device file for dpm state\n");
1548 ret
= device_create_file(rdev
->dev
, &dev_attr_power_dpm_force_performance_level
);
1550 DRM_ERROR("failed to create device file for dpm state\n");
1551 /* XXX: these are noops for dpm but are here for backwards compat */
1552 ret
= device_create_file(rdev
->dev
, &dev_attr_power_profile
);
1554 DRM_ERROR("failed to create device file for power profile\n");
1555 ret
= device_create_file(rdev
->dev
, &dev_attr_power_method
);
1557 DRM_ERROR("failed to create device file for power method\n");
1558 rdev
->pm
.sysfs_initialized
= true;
1561 mutex_lock(&rdev
->pm
.mutex
);
1562 ret
= radeon_dpm_late_enable(rdev
);
1563 mutex_unlock(&rdev
->pm
.mutex
);
1565 rdev
->pm
.dpm_enabled
= false;
1566 DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n");
1568 /* set the dpm state for PX since there won't be
1569 * a modeset to call this.
1571 radeon_pm_compute_clocks(rdev
);
1575 if ((rdev
->pm
.num_power_states
> 1) &&
1576 (!rdev
->pm
.sysfs_initialized
)) {
1577 /* where's the best place to put these? */
1578 ret
= device_create_file(rdev
->dev
, &dev_attr_power_profile
);
1580 DRM_ERROR("failed to create device file for power profile\n");
1581 ret
= device_create_file(rdev
->dev
, &dev_attr_power_method
);
1583 DRM_ERROR("failed to create device file for power method\n");
1585 rdev
->pm
.sysfs_initialized
= true;
1591 static void radeon_pm_fini_old(struct radeon_device
*rdev
)
1593 if (rdev
->pm
.num_power_states
> 1) {
1594 mutex_lock(&rdev
->pm
.mutex
);
1595 if (rdev
->pm
.pm_method
== PM_METHOD_PROFILE
) {
1596 rdev
->pm
.profile
= PM_PROFILE_DEFAULT
;
1597 radeon_pm_update_profile(rdev
);
1598 radeon_pm_set_clocks(rdev
);
1599 } else if (rdev
->pm
.pm_method
== PM_METHOD_DYNPM
) {
1600 /* reset default clocks */
1601 rdev
->pm
.dynpm_state
= DYNPM_STATE_DISABLED
;
1602 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_DEFAULT
;
1603 radeon_pm_set_clocks(rdev
);
1605 mutex_unlock(&rdev
->pm
.mutex
);
1607 cancel_delayed_work_sync(&rdev
->pm
.dynpm_idle_work
);
1609 device_remove_file(rdev
->dev
, &dev_attr_power_profile
);
1610 device_remove_file(rdev
->dev
, &dev_attr_power_method
);
1613 radeon_hwmon_fini(rdev
);
1614 kfree(rdev
->pm
.power_state
);
1617 static void radeon_pm_fini_dpm(struct radeon_device
*rdev
)
1619 if (rdev
->pm
.num_power_states
> 1) {
1620 mutex_lock(&rdev
->pm
.mutex
);
1621 radeon_dpm_disable(rdev
);
1622 mutex_unlock(&rdev
->pm
.mutex
);
1624 device_remove_file(rdev
->dev
, &dev_attr_power_dpm_state
);
1625 device_remove_file(rdev
->dev
, &dev_attr_power_dpm_force_performance_level
);
1626 /* XXX backwards compat */
1627 device_remove_file(rdev
->dev
, &dev_attr_power_profile
);
1628 device_remove_file(rdev
->dev
, &dev_attr_power_method
);
1630 radeon_dpm_fini(rdev
);
1632 radeon_hwmon_fini(rdev
);
1633 kfree(rdev
->pm
.power_state
);
1636 void radeon_pm_fini(struct radeon_device
*rdev
)
1638 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
1639 radeon_pm_fini_dpm(rdev
);
1641 radeon_pm_fini_old(rdev
);
1644 static void radeon_pm_compute_clocks_old(struct radeon_device
*rdev
)
1646 struct drm_device
*ddev
= rdev
->ddev
;
1647 struct drm_crtc
*crtc
;
1648 struct radeon_crtc
*radeon_crtc
;
1650 if (rdev
->pm
.num_power_states
< 2)
1653 mutex_lock(&rdev
->pm
.mutex
);
1655 rdev
->pm
.active_crtcs
= 0;
1656 rdev
->pm
.active_crtc_count
= 0;
1657 if (rdev
->num_crtc
&& rdev
->mode_info
.mode_config_initialized
) {
1658 list_for_each_entry(crtc
,
1659 &ddev
->mode_config
.crtc_list
, head
) {
1660 radeon_crtc
= to_radeon_crtc(crtc
);
1661 if (radeon_crtc
->enabled
) {
1662 rdev
->pm
.active_crtcs
|= (1 << radeon_crtc
->crtc_id
);
1663 rdev
->pm
.active_crtc_count
++;
1668 if (rdev
->pm
.pm_method
== PM_METHOD_PROFILE
) {
1669 radeon_pm_update_profile(rdev
);
1670 radeon_pm_set_clocks(rdev
);
1671 } else if (rdev
->pm
.pm_method
== PM_METHOD_DYNPM
) {
1672 if (rdev
->pm
.dynpm_state
!= DYNPM_STATE_DISABLED
) {
1673 if (rdev
->pm
.active_crtc_count
> 1) {
1674 if (rdev
->pm
.dynpm_state
== DYNPM_STATE_ACTIVE
) {
1675 cancel_delayed_work(&rdev
->pm
.dynpm_idle_work
);
1677 rdev
->pm
.dynpm_state
= DYNPM_STATE_PAUSED
;
1678 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_DEFAULT
;
1679 radeon_pm_get_dynpm_state(rdev
);
1680 radeon_pm_set_clocks(rdev
);
1682 DRM_DEBUG_DRIVER("radeon: dynamic power management deactivated\n");
1684 } else if (rdev
->pm
.active_crtc_count
== 1) {
1685 /* TODO: Increase clocks if needed for current mode */
1687 if (rdev
->pm
.dynpm_state
== DYNPM_STATE_MINIMUM
) {
1688 rdev
->pm
.dynpm_state
= DYNPM_STATE_ACTIVE
;
1689 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_UPCLOCK
;
1690 radeon_pm_get_dynpm_state(rdev
);
1691 radeon_pm_set_clocks(rdev
);
1693 schedule_delayed_work(&rdev
->pm
.dynpm_idle_work
,
1694 msecs_to_jiffies(RADEON_IDLE_LOOP_MS
));
1695 } else if (rdev
->pm
.dynpm_state
== DYNPM_STATE_PAUSED
) {
1696 rdev
->pm
.dynpm_state
= DYNPM_STATE_ACTIVE
;
1697 schedule_delayed_work(&rdev
->pm
.dynpm_idle_work
,
1698 msecs_to_jiffies(RADEON_IDLE_LOOP_MS
));
1699 DRM_DEBUG_DRIVER("radeon: dynamic power management activated\n");
1701 } else { /* count == 0 */
1702 if (rdev
->pm
.dynpm_state
!= DYNPM_STATE_MINIMUM
) {
1703 cancel_delayed_work(&rdev
->pm
.dynpm_idle_work
);
1705 rdev
->pm
.dynpm_state
= DYNPM_STATE_MINIMUM
;
1706 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_MINIMUM
;
1707 radeon_pm_get_dynpm_state(rdev
);
1708 radeon_pm_set_clocks(rdev
);
1714 mutex_unlock(&rdev
->pm
.mutex
);
1717 static void radeon_pm_compute_clocks_dpm(struct radeon_device
*rdev
)
1719 struct drm_device
*ddev
= rdev
->ddev
;
1720 struct drm_crtc
*crtc
;
1721 struct radeon_crtc
*radeon_crtc
;
1723 if (!rdev
->pm
.dpm_enabled
)
1726 mutex_lock(&rdev
->pm
.mutex
);
1728 /* update active crtc counts */
1729 rdev
->pm
.dpm
.new_active_crtcs
= 0;
1730 rdev
->pm
.dpm
.new_active_crtc_count
= 0;
1731 if (rdev
->num_crtc
&& rdev
->mode_info
.mode_config_initialized
) {
1732 list_for_each_entry(crtc
,
1733 &ddev
->mode_config
.crtc_list
, head
) {
1734 radeon_crtc
= to_radeon_crtc(crtc
);
1735 if (crtc
->enabled
) {
1736 rdev
->pm
.dpm
.new_active_crtcs
|= (1 << radeon_crtc
->crtc_id
);
1737 rdev
->pm
.dpm
.new_active_crtc_count
++;
1742 /* update battery/ac status */
1743 if (power_supply_is_system_supplied() > 0)
1744 rdev
->pm
.dpm
.ac_power
= true;
1746 rdev
->pm
.dpm
.ac_power
= false;
1748 radeon_dpm_change_power_state_locked(rdev
);
1750 mutex_unlock(&rdev
->pm
.mutex
);
1754 void radeon_pm_compute_clocks(struct radeon_device
*rdev
)
1756 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
1757 radeon_pm_compute_clocks_dpm(rdev
);
1759 radeon_pm_compute_clocks_old(rdev
);
1762 static bool radeon_pm_in_vbl(struct radeon_device
*rdev
)
1764 int crtc
, vpos
, hpos
, vbl_status
;
1767 /* Iterate over all active crtc's. All crtc's must be in vblank,
1768 * otherwise return in_vbl == false.
1770 for (crtc
= 0; (crtc
< rdev
->num_crtc
) && in_vbl
; crtc
++) {
1771 if (rdev
->pm
.active_crtcs
& (1 << crtc
)) {
1772 vbl_status
= radeon_get_crtc_scanoutpos(rdev
->ddev
,
1774 USE_REAL_VBLANKSTART
,
1775 &vpos
, &hpos
, NULL
, NULL
,
1776 &rdev
->mode_info
.crtcs
[crtc
]->base
.hwmode
);
1777 if ((vbl_status
& DRM_SCANOUTPOS_VALID
) &&
1778 !(vbl_status
& DRM_SCANOUTPOS_IN_VBLANK
))
1786 static bool radeon_pm_debug_check_in_vbl(struct radeon_device
*rdev
, bool finish
)
1789 bool in_vbl
= radeon_pm_in_vbl(rdev
);
1791 if (in_vbl
== false)
1792 DRM_DEBUG_DRIVER("not in vbl for pm change %08x at %s\n", stat_crtc
,
1793 finish
? "exit" : "entry");
1797 static void radeon_dynpm_idle_work_handler(struct work_struct
*work
)
1799 struct radeon_device
*rdev
;
1801 rdev
= container_of(work
, struct radeon_device
,
1802 pm
.dynpm_idle_work
.work
);
1804 resched
= ttm_bo_lock_delayed_workqueue(&rdev
->mman
.bdev
);
1805 mutex_lock(&rdev
->pm
.mutex
);
1806 if (rdev
->pm
.dynpm_state
== DYNPM_STATE_ACTIVE
) {
1807 int not_processed
= 0;
1810 for (i
= 0; i
< RADEON_NUM_RINGS
; ++i
) {
1811 struct radeon_ring
*ring
= &rdev
->ring
[i
];
1814 not_processed
+= radeon_fence_count_emitted(rdev
, i
);
1815 if (not_processed
>= 3)
1820 if (not_processed
>= 3) { /* should upclock */
1821 if (rdev
->pm
.dynpm_planned_action
== DYNPM_ACTION_DOWNCLOCK
) {
1822 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_NONE
;
1823 } else if (rdev
->pm
.dynpm_planned_action
== DYNPM_ACTION_NONE
&&
1824 rdev
->pm
.dynpm_can_upclock
) {
1825 rdev
->pm
.dynpm_planned_action
=
1826 DYNPM_ACTION_UPCLOCK
;
1827 rdev
->pm
.dynpm_action_timeout
= jiffies
+
1828 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS
);
1830 } else if (not_processed
== 0) { /* should downclock */
1831 if (rdev
->pm
.dynpm_planned_action
== DYNPM_ACTION_UPCLOCK
) {
1832 rdev
->pm
.dynpm_planned_action
= DYNPM_ACTION_NONE
;
1833 } else if (rdev
->pm
.dynpm_planned_action
== DYNPM_ACTION_NONE
&&
1834 rdev
->pm
.dynpm_can_downclock
) {
1835 rdev
->pm
.dynpm_planned_action
=
1836 DYNPM_ACTION_DOWNCLOCK
;
1837 rdev
->pm
.dynpm_action_timeout
= jiffies
+
1838 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS
);
1842 /* Note, radeon_pm_set_clocks is called with static_switch set
1843 * to false since we want to wait for vbl to avoid flicker.
1845 if (rdev
->pm
.dynpm_planned_action
!= DYNPM_ACTION_NONE
&&
1846 jiffies
> rdev
->pm
.dynpm_action_timeout
) {
1847 radeon_pm_get_dynpm_state(rdev
);
1848 radeon_pm_set_clocks(rdev
);
1851 schedule_delayed_work(&rdev
->pm
.dynpm_idle_work
,
1852 msecs_to_jiffies(RADEON_IDLE_LOOP_MS
));
1854 mutex_unlock(&rdev
->pm
.mutex
);
1855 ttm_bo_unlock_delayed_workqueue(&rdev
->mman
.bdev
, resched
);
1861 #if defined(CONFIG_DEBUG_FS)
1863 static int radeon_debugfs_pm_info(struct seq_file
*m
, void *data
)
1865 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
1866 struct drm_device
*dev
= node
->minor
->dev
;
1867 struct radeon_device
*rdev
= dev
->dev_private
;
1868 struct drm_device
*ddev
= rdev
->ddev
;
1870 if ((rdev
->flags
& RADEON_IS_PX
) &&
1871 (ddev
->switch_power_state
!= DRM_SWITCH_POWER_ON
)) {
1872 seq_printf(m
, "PX asic powered off\n");
1873 } else if (rdev
->pm
.dpm_enabled
) {
1874 mutex_lock(&rdev
->pm
.mutex
);
1875 if (rdev
->asic
->dpm
.debugfs_print_current_performance_level
)
1876 radeon_dpm_debugfs_print_current_performance_level(rdev
, m
);
1878 seq_printf(m
, "Debugfs support not implemented for this asic\n");
1879 mutex_unlock(&rdev
->pm
.mutex
);
1881 seq_printf(m
, "default engine clock: %u0 kHz\n", rdev
->pm
.default_sclk
);
1882 /* radeon_get_engine_clock is not reliable on APUs so just print the current clock */
1883 if ((rdev
->family
>= CHIP_PALM
) && (rdev
->flags
& RADEON_IS_IGP
))
1884 seq_printf(m
, "current engine clock: %u0 kHz\n", rdev
->pm
.current_sclk
);
1886 seq_printf(m
, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev
));
1887 seq_printf(m
, "default memory clock: %u0 kHz\n", rdev
->pm
.default_mclk
);
1888 if (rdev
->asic
->pm
.get_memory_clock
)
1889 seq_printf(m
, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev
));
1890 if (rdev
->pm
.current_vddc
)
1891 seq_printf(m
, "voltage: %u mV\n", rdev
->pm
.current_vddc
);
1892 if (rdev
->asic
->pm
.get_pcie_lanes
)
1893 seq_printf(m
, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev
));
1899 static struct drm_info_list radeon_pm_info_list
[] = {
1900 {"radeon_pm_info", radeon_debugfs_pm_info
, 0, NULL
},
1904 static int radeon_debugfs_pm_init(struct radeon_device
*rdev
)
1906 #if defined(CONFIG_DEBUG_FS)
1907 return radeon_debugfs_add_files(rdev
, radeon_pm_info_list
, ARRAY_SIZE(radeon_pm_info_list
));