Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1 | /* |
| 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: |
| 8 | * |
| 9 | * The above copyright notice and this permission notice shall be included in |
| 10 | * all copies or substantial portions of the Software. |
| 11 | * |
| 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. |
| 19 | * |
| 20 | * Authors: Rafał Miłecki <zajec5@gmail.com> |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 21 | * Alex Deucher <alexdeucher@gmail.com> |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 22 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 23 | #include <drm/drmP.h> |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 24 | #include "radeon.h" |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 25 | #include "avivod.h" |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 26 | #include "atom.h" |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 27 | #include <linux/power_supply.h> |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 28 | #include <linux/hwmon.h> |
| 29 | #include <linux/hwmon-sysfs.h> |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 30 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 31 | #define RADEON_IDLE_LOOP_MS 100 |
| 32 | #define RADEON_RECLOCK_DELAY_MS 200 |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 33 | #define RADEON_WAIT_VBLANK_TIMEOUT 200 |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 34 | |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 35 | static const char *radeon_pm_state_type_name[5] = { |
Alex Deucher | eb2c27a | 2012-10-01 18:28:09 -0400 | [diff] [blame] | 36 | "", |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 37 | "Powersave", |
| 38 | "Battery", |
| 39 | "Balanced", |
| 40 | "Performance", |
| 41 | }; |
| 42 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 43 | static void radeon_dynpm_idle_work_handler(struct work_struct *work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 44 | static int radeon_debugfs_pm_init(struct radeon_device *rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 45 | static bool radeon_pm_in_vbl(struct radeon_device *rdev); |
| 46 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish); |
| 47 | static void radeon_pm_update_profile(struct radeon_device *rdev); |
| 48 | static void radeon_pm_set_clocks(struct radeon_device *rdev); |
| 49 | |
Alex Deucher | a4c9e2e | 2011-11-04 10:09:41 -0400 | [diff] [blame] | 50 | int radeon_pm_get_type_index(struct radeon_device *rdev, |
| 51 | enum radeon_pm_state_type ps_type, |
| 52 | int instance) |
| 53 | { |
| 54 | int i; |
| 55 | int found_instance = -1; |
| 56 | |
| 57 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
| 58 | if (rdev->pm.power_state[i].type == ps_type) { |
| 59 | found_instance++; |
| 60 | if (found_instance == instance) |
| 61 | return i; |
| 62 | } |
| 63 | } |
| 64 | /* return default if no match */ |
| 65 | return rdev->pm.default_power_state_index; |
| 66 | } |
| 67 | |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 68 | void radeon_pm_acpi_event_handler(struct radeon_device *rdev) |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 69 | { |
Alex Deucher | 1c71bda | 2013-09-09 19:11:52 -0400 | [diff] [blame] | 70 | if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) { |
| 71 | mutex_lock(&rdev->pm.mutex); |
| 72 | if (power_supply_is_system_supplied() > 0) |
| 73 | rdev->pm.dpm.ac_power = true; |
| 74 | else |
| 75 | rdev->pm.dpm.ac_power = false; |
Alex Deucher | 9668295 | 2014-06-18 14:23:46 -0400 | [diff] [blame] | 76 | if (rdev->family == CHIP_ARUBA) { |
| 77 | if (rdev->asic->dpm.enable_bapm) |
| 78 | radeon_dpm_enable_bapm(rdev, rdev->pm.dpm.ac_power); |
| 79 | } |
Alex Deucher | 1c71bda | 2013-09-09 19:11:52 -0400 | [diff] [blame] | 80 | mutex_unlock(&rdev->pm.mutex); |
| 81 | } else if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 82 | if (rdev->pm.profile == PM_PROFILE_AUTO) { |
| 83 | mutex_lock(&rdev->pm.mutex); |
| 84 | radeon_pm_update_profile(rdev); |
| 85 | radeon_pm_set_clocks(rdev); |
| 86 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 87 | } |
| 88 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 89 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 90 | |
| 91 | static void radeon_pm_update_profile(struct radeon_device *rdev) |
| 92 | { |
| 93 | switch (rdev->pm.profile) { |
| 94 | case PM_PROFILE_DEFAULT: |
| 95 | rdev->pm.profile_index = PM_PROFILE_DEFAULT_IDX; |
| 96 | break; |
| 97 | case PM_PROFILE_AUTO: |
| 98 | if (power_supply_is_system_supplied() > 0) { |
| 99 | if (rdev->pm.active_crtc_count > 1) |
| 100 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 101 | else |
| 102 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 103 | } else { |
| 104 | if (rdev->pm.active_crtc_count > 1) |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 105 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 106 | else |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 107 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 108 | } |
| 109 | break; |
| 110 | case PM_PROFILE_LOW: |
| 111 | if (rdev->pm.active_crtc_count > 1) |
| 112 | rdev->pm.profile_index = PM_PROFILE_LOW_MH_IDX; |
| 113 | else |
| 114 | rdev->pm.profile_index = PM_PROFILE_LOW_SH_IDX; |
| 115 | break; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 116 | case PM_PROFILE_MID: |
| 117 | if (rdev->pm.active_crtc_count > 1) |
| 118 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
| 119 | else |
| 120 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
| 121 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 122 | case PM_PROFILE_HIGH: |
| 123 | if (rdev->pm.active_crtc_count > 1) |
| 124 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 125 | else |
| 126 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | if (rdev->pm.active_crtc_count == 0) { |
| 131 | rdev->pm.requested_power_state_index = |
| 132 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_ps_idx; |
| 133 | rdev->pm.requested_clock_mode_index = |
| 134 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_cm_idx; |
| 135 | } else { |
| 136 | rdev->pm.requested_power_state_index = |
| 137 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_ps_idx; |
| 138 | rdev->pm.requested_clock_mode_index = |
| 139 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_cm_idx; |
| 140 | } |
| 141 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 142 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 143 | static void radeon_unmap_vram_bos(struct radeon_device *rdev) |
| 144 | { |
| 145 | struct radeon_bo *bo, *n; |
| 146 | |
| 147 | if (list_empty(&rdev->gem.objects)) |
| 148 | return; |
| 149 | |
| 150 | list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) { |
| 151 | if (bo->tbo.mem.mem_type == TTM_PL_VRAM) |
| 152 | ttm_bo_unmap_virtual(&bo->tbo); |
| 153 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 156 | static void radeon_sync_with_vblank(struct radeon_device *rdev) |
| 157 | { |
| 158 | if (rdev->pm.active_crtcs) { |
| 159 | rdev->pm.vblank_sync = false; |
| 160 | wait_event_timeout( |
| 161 | rdev->irq.vblank_queue, rdev->pm.vblank_sync, |
| 162 | msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT)); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void radeon_set_power_state(struct radeon_device *rdev) |
| 167 | { |
| 168 | u32 sclk, mclk; |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 169 | bool misc_after = false; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 170 | |
| 171 | if ((rdev->pm.requested_clock_mode_index == rdev->pm.current_clock_mode_index) && |
| 172 | (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index)) |
| 173 | return; |
| 174 | |
| 175 | if (radeon_gui_idle(rdev)) { |
| 176 | sclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 177 | clock_info[rdev->pm.requested_clock_mode_index].sclk; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 178 | if (sclk > rdev->pm.default_sclk) |
| 179 | sclk = rdev->pm.default_sclk; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 180 | |
Alex Deucher | 27810fb | 2012-10-01 19:25:11 -0400 | [diff] [blame] | 181 | /* starting with BTC, there is one state that is used for both |
| 182 | * MH and SH. Difference is that we always use the high clock index for |
Alex Deucher | 7ae764b | 2013-02-11 08:44:48 -0500 | [diff] [blame] | 183 | * mclk and vddci. |
Alex Deucher | 27810fb | 2012-10-01 19:25:11 -0400 | [diff] [blame] | 184 | */ |
| 185 | if ((rdev->pm.pm_method == PM_METHOD_PROFILE) && |
| 186 | (rdev->family >= CHIP_BARTS) && |
| 187 | rdev->pm.active_crtc_count && |
| 188 | ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) || |
| 189 | (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX))) |
| 190 | mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 191 | clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].mclk; |
| 192 | else |
| 193 | mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 194 | clock_info[rdev->pm.requested_clock_mode_index].mclk; |
| 195 | |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 196 | if (mclk > rdev->pm.default_mclk) |
| 197 | mclk = rdev->pm.default_mclk; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 198 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 199 | /* upvolt before raising clocks, downvolt after lowering clocks */ |
| 200 | if (sclk < rdev->pm.current_sclk) |
| 201 | misc_after = true; |
| 202 | |
| 203 | radeon_sync_with_vblank(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 204 | |
| 205 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 206 | if (!radeon_pm_in_vbl(rdev)) |
| 207 | return; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 210 | radeon_pm_prepare(rdev); |
| 211 | |
| 212 | if (!misc_after) |
| 213 | /* voltage, pcie lanes, etc.*/ |
| 214 | radeon_pm_misc(rdev); |
| 215 | |
| 216 | /* set engine clock */ |
| 217 | if (sclk != rdev->pm.current_sclk) { |
| 218 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 219 | radeon_set_engine_clock(rdev, sclk); |
| 220 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 221 | rdev->pm.current_sclk = sclk; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 222 | DRM_DEBUG_DRIVER("Setting: e: %d\n", sclk); |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* set memory clock */ |
Alex Deucher | 798bcf7 | 2012-02-23 17:53:48 -0500 | [diff] [blame] | 226 | if (rdev->asic->pm.set_memory_clock && (mclk != rdev->pm.current_mclk)) { |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 227 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 228 | radeon_set_memory_clock(rdev, mclk); |
| 229 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 230 | rdev->pm.current_mclk = mclk; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 231 | DRM_DEBUG_DRIVER("Setting: m: %d\n", mclk); |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (misc_after) |
| 235 | /* voltage, pcie lanes, etc.*/ |
| 236 | radeon_pm_misc(rdev); |
| 237 | |
| 238 | radeon_pm_finish(rdev); |
| 239 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 240 | rdev->pm.current_power_state_index = rdev->pm.requested_power_state_index; |
| 241 | rdev->pm.current_clock_mode_index = rdev->pm.requested_clock_mode_index; |
| 242 | } else |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 243 | DRM_DEBUG_DRIVER("pm: GUI not idle!!!\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static void radeon_pm_set_clocks(struct radeon_device *rdev) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 247 | { |
Jerome Glisse | 5f8f635 | 2012-12-17 11:04:32 -0500 | [diff] [blame] | 248 | int i, r; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 249 | |
Alex Deucher | 4e186b2 | 2010-08-13 10:53:35 -0400 | [diff] [blame] | 250 | /* no need to take locks, etc. if nothing's going to change */ |
| 251 | if ((rdev->pm.requested_clock_mode_index == rdev->pm.current_clock_mode_index) && |
| 252 | (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index)) |
| 253 | return; |
| 254 | |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 255 | mutex_lock(&rdev->ddev->struct_mutex); |
Christian König | db7fce3 | 2012-05-11 14:57:18 +0200 | [diff] [blame] | 256 | down_write(&rdev->pm.mclk_lock); |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 257 | mutex_lock(&rdev->ring_lock); |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 258 | |
Alex Deucher | 95f5a3a | 2012-08-10 13:12:08 -0400 | [diff] [blame] | 259 | /* wait for the rings to drain */ |
| 260 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
| 261 | struct radeon_ring *ring = &rdev->ring[i]; |
Jerome Glisse | 5f8f635 | 2012-12-17 11:04:32 -0500 | [diff] [blame] | 262 | if (!ring->ready) { |
| 263 | continue; |
| 264 | } |
Christian König | 3761552 | 2014-02-18 15:58:31 +0100 | [diff] [blame] | 265 | r = radeon_fence_wait_empty(rdev, i); |
Jerome Glisse | 5f8f635 | 2012-12-17 11:04:32 -0500 | [diff] [blame] | 266 | if (r) { |
| 267 | /* needs a GPU reset dont reset here */ |
| 268 | mutex_unlock(&rdev->ring_lock); |
| 269 | up_write(&rdev->pm.mclk_lock); |
| 270 | mutex_unlock(&rdev->ddev->struct_mutex); |
| 271 | return; |
| 272 | } |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 273 | } |
Alex Deucher | 95f5a3a | 2012-08-10 13:12:08 -0400 | [diff] [blame] | 274 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 275 | radeon_unmap_vram_bos(rdev); |
| 276 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 277 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 278 | for (i = 0; i < rdev->num_crtc; i++) { |
| 279 | if (rdev->pm.active_crtcs & (1 << i)) { |
| 280 | rdev->pm.req_vblank |= (1 << i); |
| 281 | drm_vblank_get(rdev->ddev, i); |
| 282 | } |
| 283 | } |
| 284 | } |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 285 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 286 | radeon_set_power_state(rdev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 287 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 288 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 289 | for (i = 0; i < rdev->num_crtc; i++) { |
| 290 | if (rdev->pm.req_vblank & (1 << i)) { |
| 291 | rdev->pm.req_vblank &= ~(1 << i); |
| 292 | drm_vblank_put(rdev->ddev, i); |
| 293 | } |
| 294 | } |
| 295 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 296 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 297 | /* update display watermarks based on new power state */ |
| 298 | radeon_update_bandwidth_info(rdev); |
| 299 | if (rdev->pm.active_crtc_count) |
| 300 | radeon_bandwidth_update(rdev); |
| 301 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 302 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 303 | |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 304 | mutex_unlock(&rdev->ring_lock); |
Christian König | db7fce3 | 2012-05-11 14:57:18 +0200 | [diff] [blame] | 305 | up_write(&rdev->pm.mclk_lock); |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 306 | mutex_unlock(&rdev->ddev->struct_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 307 | } |
| 308 | |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 309 | static void radeon_pm_print_states(struct radeon_device *rdev) |
| 310 | { |
| 311 | int i, j; |
| 312 | struct radeon_power_state *power_state; |
| 313 | struct radeon_pm_clock_info *clock_info; |
| 314 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 315 | DRM_DEBUG_DRIVER("%d Power State(s)\n", rdev->pm.num_power_states); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 316 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
| 317 | power_state = &rdev->pm.power_state[i]; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 318 | DRM_DEBUG_DRIVER("State %d: %s\n", i, |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 319 | radeon_pm_state_type_name[power_state->type]); |
| 320 | if (i == rdev->pm.default_power_state_index) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 321 | DRM_DEBUG_DRIVER("\tDefault"); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 322 | if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP)) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 323 | DRM_DEBUG_DRIVER("\t%d PCIE Lanes\n", power_state->pcie_lanes); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 324 | if (power_state->flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 325 | DRM_DEBUG_DRIVER("\tSingle display only\n"); |
| 326 | DRM_DEBUG_DRIVER("\t%d Clock Mode(s)\n", power_state->num_clock_modes); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 327 | for (j = 0; j < power_state->num_clock_modes; j++) { |
| 328 | clock_info = &(power_state->clock_info[j]); |
| 329 | if (rdev->flags & RADEON_IS_IGP) |
Alex Deucher | eb2c27a | 2012-10-01 18:28:09 -0400 | [diff] [blame] | 330 | DRM_DEBUG_DRIVER("\t\t%d e: %d\n", |
| 331 | j, |
| 332 | clock_info->sclk * 10); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 333 | else |
Alex Deucher | eb2c27a | 2012-10-01 18:28:09 -0400 | [diff] [blame] | 334 | DRM_DEBUG_DRIVER("\t\t%d e: %d\tm: %d\tv: %d\n", |
| 335 | j, |
| 336 | clock_info->sclk * 10, |
| 337 | clock_info->mclk * 10, |
| 338 | clock_info->voltage.voltage); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 343 | static ssize_t radeon_get_pm_profile(struct device *dev, |
| 344 | struct device_attribute *attr, |
| 345 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 346 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 347 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 348 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 349 | int cp = rdev->pm.profile; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 350 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 351 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 352 | (cp == PM_PROFILE_AUTO) ? "auto" : |
| 353 | (cp == PM_PROFILE_LOW) ? "low" : |
Daniel J Blueman | 12e27be | 2010-07-28 12:25:58 +0100 | [diff] [blame] | 354 | (cp == PM_PROFILE_MID) ? "mid" : |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 355 | (cp == PM_PROFILE_HIGH) ? "high" : "default"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 358 | static ssize_t radeon_set_pm_profile(struct device *dev, |
| 359 | struct device_attribute *attr, |
| 360 | const char *buf, |
| 361 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 362 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 363 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 364 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 365 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 366 | /* Can't set profile when the card is off */ |
| 367 | if ((rdev->flags & RADEON_IS_PX) && |
| 368 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 369 | return -EINVAL; |
| 370 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 371 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 372 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 373 | if (strncmp("default", buf, strlen("default")) == 0) |
| 374 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 375 | else if (strncmp("auto", buf, strlen("auto")) == 0) |
| 376 | rdev->pm.profile = PM_PROFILE_AUTO; |
| 377 | else if (strncmp("low", buf, strlen("low")) == 0) |
| 378 | rdev->pm.profile = PM_PROFILE_LOW; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 379 | else if (strncmp("mid", buf, strlen("mid")) == 0) |
| 380 | rdev->pm.profile = PM_PROFILE_MID; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 381 | else if (strncmp("high", buf, strlen("high")) == 0) |
| 382 | rdev->pm.profile = PM_PROFILE_HIGH; |
| 383 | else { |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 384 | count = -EINVAL; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 385 | goto fail; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 386 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 387 | radeon_pm_update_profile(rdev); |
| 388 | radeon_pm_set_clocks(rdev); |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 389 | } else |
| 390 | count = -EINVAL; |
| 391 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 392 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 393 | mutex_unlock(&rdev->pm.mutex); |
| 394 | |
| 395 | return count; |
| 396 | } |
| 397 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 398 | static ssize_t radeon_get_pm_method(struct device *dev, |
| 399 | struct device_attribute *attr, |
| 400 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 401 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 402 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 403 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 404 | int pm = rdev->pm.pm_method; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 405 | |
| 406 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 407 | (pm == PM_METHOD_DYNPM) ? "dynpm" : |
| 408 | (pm == PM_METHOD_PROFILE) ? "profile" : "dpm"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 411 | static ssize_t radeon_set_pm_method(struct device *dev, |
| 412 | struct device_attribute *attr, |
| 413 | const char *buf, |
| 414 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 415 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 416 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 417 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 418 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 419 | /* Can't set method when the card is off */ |
| 420 | if ((rdev->flags & RADEON_IS_PX) && |
| 421 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) { |
| 422 | count = -EINVAL; |
| 423 | goto fail; |
| 424 | } |
| 425 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 426 | /* we don't support the legacy modes with dpm */ |
| 427 | if (rdev->pm.pm_method == PM_METHOD_DPM) { |
| 428 | count = -EINVAL; |
| 429 | goto fail; |
| 430 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 431 | |
| 432 | if (strncmp("dynpm", buf, strlen("dynpm")) == 0) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 433 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 434 | rdev->pm.pm_method = PM_METHOD_DYNPM; |
| 435 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 436 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 437 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 438 | } else if (strncmp("profile", buf, strlen("profile")) == 0) { |
| 439 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 440 | /* disable dynpm */ |
| 441 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 442 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 443 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 444 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 445 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 446 | } else { |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 447 | count = -EINVAL; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 448 | goto fail; |
| 449 | } |
| 450 | radeon_pm_compute_clocks(rdev); |
| 451 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 452 | return count; |
| 453 | } |
| 454 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 455 | static ssize_t radeon_get_dpm_state(struct device *dev, |
| 456 | struct device_attribute *attr, |
| 457 | char *buf) |
| 458 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 459 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 460 | struct radeon_device *rdev = ddev->dev_private; |
| 461 | enum radeon_pm_state_type pm = rdev->pm.dpm.user_state; |
| 462 | |
| 463 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 464 | (pm == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 465 | (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance"); |
| 466 | } |
| 467 | |
| 468 | static ssize_t radeon_set_dpm_state(struct device *dev, |
| 469 | struct device_attribute *attr, |
| 470 | const char *buf, |
| 471 | size_t count) |
| 472 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 473 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 474 | struct radeon_device *rdev = ddev->dev_private; |
| 475 | |
| 476 | mutex_lock(&rdev->pm.mutex); |
| 477 | if (strncmp("battery", buf, strlen("battery")) == 0) |
| 478 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BATTERY; |
| 479 | else if (strncmp("balanced", buf, strlen("balanced")) == 0) |
| 480 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; |
| 481 | else if (strncmp("performance", buf, strlen("performance")) == 0) |
| 482 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_PERFORMANCE; |
| 483 | else { |
| 484 | mutex_unlock(&rdev->pm.mutex); |
| 485 | count = -EINVAL; |
| 486 | goto fail; |
| 487 | } |
| 488 | mutex_unlock(&rdev->pm.mutex); |
Pali Rohár | b07a657 | 2014-08-11 19:01:58 +0200 | [diff] [blame] | 489 | |
| 490 | /* Can't set dpm state when the card is off */ |
| 491 | if (!(rdev->flags & RADEON_IS_PX) || |
| 492 | (ddev->switch_power_state == DRM_SWITCH_POWER_ON)) |
| 493 | radeon_pm_compute_clocks(rdev); |
| 494 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 495 | fail: |
| 496 | return count; |
| 497 | } |
| 498 | |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 499 | static ssize_t radeon_get_dpm_forced_performance_level(struct device *dev, |
| 500 | struct device_attribute *attr, |
| 501 | char *buf) |
| 502 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 503 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 504 | struct radeon_device *rdev = ddev->dev_private; |
| 505 | enum radeon_dpm_forced_level level = rdev->pm.dpm.forced_level; |
| 506 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 507 | if ((rdev->flags & RADEON_IS_PX) && |
| 508 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 509 | return snprintf(buf, PAGE_SIZE, "off\n"); |
| 510 | |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 511 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 512 | (level == RADEON_DPM_FORCED_LEVEL_AUTO) ? "auto" : |
| 513 | (level == RADEON_DPM_FORCED_LEVEL_LOW) ? "low" : "high"); |
| 514 | } |
| 515 | |
| 516 | static ssize_t radeon_set_dpm_forced_performance_level(struct device *dev, |
| 517 | struct device_attribute *attr, |
| 518 | const char *buf, |
| 519 | size_t count) |
| 520 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 521 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 522 | struct radeon_device *rdev = ddev->dev_private; |
| 523 | enum radeon_dpm_forced_level level; |
| 524 | int ret = 0; |
| 525 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 526 | /* Can't force performance level when the card is off */ |
| 527 | if ((rdev->flags & RADEON_IS_PX) && |
| 528 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 529 | return -EINVAL; |
| 530 | |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 531 | mutex_lock(&rdev->pm.mutex); |
| 532 | if (strncmp("low", buf, strlen("low")) == 0) { |
| 533 | level = RADEON_DPM_FORCED_LEVEL_LOW; |
| 534 | } else if (strncmp("high", buf, strlen("high")) == 0) { |
| 535 | level = RADEON_DPM_FORCED_LEVEL_HIGH; |
| 536 | } else if (strncmp("auto", buf, strlen("auto")) == 0) { |
| 537 | level = RADEON_DPM_FORCED_LEVEL_AUTO; |
| 538 | } else { |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 539 | count = -EINVAL; |
| 540 | goto fail; |
| 541 | } |
| 542 | if (rdev->asic->dpm.force_performance_level) { |
Alex Deucher | 0a17af37 | 2013-10-23 17:22:29 -0400 | [diff] [blame] | 543 | if (rdev->pm.dpm.thermal_active) { |
| 544 | count = -EINVAL; |
| 545 | goto fail; |
| 546 | } |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 547 | ret = radeon_dpm_force_performance_level(rdev, level); |
| 548 | if (ret) |
| 549 | count = -EINVAL; |
| 550 | } |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 551 | fail: |
Alex Deucher | 0a17af37 | 2013-10-23 17:22:29 -0400 | [diff] [blame] | 552 | mutex_unlock(&rdev->pm.mutex); |
| 553 | |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 554 | return count; |
| 555 | } |
| 556 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 557 | static DEVICE_ATTR(power_profile, S_IRUGO | S_IWUSR, radeon_get_pm_profile, radeon_set_pm_profile); |
| 558 | static DEVICE_ATTR(power_method, S_IRUGO | S_IWUSR, radeon_get_pm_method, radeon_set_pm_method); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 559 | static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, radeon_get_dpm_state, radeon_set_dpm_state); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 560 | static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, |
| 561 | radeon_get_dpm_forced_performance_level, |
| 562 | radeon_set_dpm_forced_performance_level); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 563 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 564 | static ssize_t radeon_hwmon_show_temp(struct device *dev, |
| 565 | struct device_attribute *attr, |
| 566 | char *buf) |
| 567 | { |
Guenter Roeck | ec39f64 | 2013-11-22 21:52:00 -0800 | [diff] [blame] | 568 | struct radeon_device *rdev = dev_get_drvdata(dev); |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 569 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 570 | int temp; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 571 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 572 | /* Can't get temperature when the card is off */ |
| 573 | if ((rdev->flags & RADEON_IS_PX) && |
| 574 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 575 | return -EINVAL; |
| 576 | |
Alex Deucher | 6bd1c38 | 2013-06-21 14:38:03 -0400 | [diff] [blame] | 577 | if (rdev->asic->pm.get_temperature) |
| 578 | temp = radeon_get_temperature(rdev); |
| 579 | else |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 580 | temp = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 581 | |
| 582 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 583 | } |
| 584 | |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 585 | static ssize_t radeon_hwmon_show_temp_thresh(struct device *dev, |
| 586 | struct device_attribute *attr, |
| 587 | char *buf) |
| 588 | { |
Sergey Senozhatsky | e4158f1 | 2013-12-13 02:25:57 +0300 | [diff] [blame] | 589 | struct radeon_device *rdev = dev_get_drvdata(dev); |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 590 | int hyst = to_sensor_dev_attr(attr)->index; |
| 591 | int temp; |
| 592 | |
| 593 | if (hyst) |
| 594 | temp = rdev->pm.dpm.thermal.min_temp; |
| 595 | else |
| 596 | temp = rdev->pm.dpm.thermal.max_temp; |
| 597 | |
| 598 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 599 | } |
| 600 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 601 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, radeon_hwmon_show_temp, NULL, 0); |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 602 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 0); |
| 603 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 1); |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 604 | |
| 605 | static struct attribute *hwmon_attributes[] = { |
| 606 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 607 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 608 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 609 | NULL |
| 610 | }; |
| 611 | |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 612 | static umode_t hwmon_attributes_visible(struct kobject *kobj, |
| 613 | struct attribute *attr, int index) |
| 614 | { |
| 615 | struct device *dev = container_of(kobj, struct device, kobj); |
Sergey Senozhatsky | e4158f1 | 2013-12-13 02:25:57 +0300 | [diff] [blame] | 616 | struct radeon_device *rdev = dev_get_drvdata(dev); |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 617 | |
| 618 | /* Skip limit attributes if DPM is not enabled */ |
| 619 | if (rdev->pm.pm_method != PM_METHOD_DPM && |
| 620 | (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr || |
| 621 | attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr)) |
| 622 | return 0; |
| 623 | |
| 624 | return attr->mode; |
| 625 | } |
| 626 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 627 | static const struct attribute_group hwmon_attrgroup = { |
| 628 | .attrs = hwmon_attributes, |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame] | 629 | .is_visible = hwmon_attributes_visible, |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 630 | }; |
| 631 | |
Guenter Roeck | ec39f64 | 2013-11-22 21:52:00 -0800 | [diff] [blame] | 632 | static const struct attribute_group *hwmon_groups[] = { |
| 633 | &hwmon_attrgroup, |
| 634 | NULL |
| 635 | }; |
| 636 | |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 637 | static int radeon_hwmon_init(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 638 | { |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 639 | int err = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 640 | |
| 641 | switch (rdev->pm.int_thermal_type) { |
| 642 | case THERMAL_TYPE_RV6XX: |
| 643 | case THERMAL_TYPE_RV770: |
| 644 | case THERMAL_TYPE_EVERGREEN: |
Alex Deucher | 457558e | 2011-05-25 17:49:54 -0400 | [diff] [blame] | 645 | case THERMAL_TYPE_NI: |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 646 | case THERMAL_TYPE_SUMO: |
Alex Deucher | 1bd47d2 | 2012-03-20 17:18:10 -0400 | [diff] [blame] | 647 | case THERMAL_TYPE_SI: |
Alex Deucher | 286d9cc | 2013-06-21 15:50:47 -0400 | [diff] [blame] | 648 | case THERMAL_TYPE_CI: |
| 649 | case THERMAL_TYPE_KV: |
Alex Deucher | 6bd1c38 | 2013-06-21 14:38:03 -0400 | [diff] [blame] | 650 | if (rdev->asic->pm.get_temperature == NULL) |
Alex Deucher | 5d7486c | 2012-03-20 17:18:29 -0400 | [diff] [blame] | 651 | return err; |
Alex Deucher | cb3e4e7 | 2014-04-15 12:44:32 -0400 | [diff] [blame] | 652 | rdev->pm.int_hwmon_dev = hwmon_device_register_with_groups(rdev->dev, |
| 653 | "radeon", rdev, |
| 654 | hwmon_groups); |
| 655 | if (IS_ERR(rdev->pm.int_hwmon_dev)) { |
| 656 | err = PTR_ERR(rdev->pm.int_hwmon_dev); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 657 | dev_err(rdev->dev, |
| 658 | "Unable to register hwmon device: %d\n", err); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 659 | } |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 660 | break; |
| 661 | default: |
| 662 | break; |
| 663 | } |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 664 | |
| 665 | return err; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Alex Deucher | cb3e4e7 | 2014-04-15 12:44:32 -0400 | [diff] [blame] | 668 | static void radeon_hwmon_fini(struct radeon_device *rdev) |
| 669 | { |
| 670 | if (rdev->pm.int_hwmon_dev) |
| 671 | hwmon_device_unregister(rdev->pm.int_hwmon_dev); |
| 672 | } |
| 673 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 674 | static void radeon_dpm_thermal_work_handler(struct work_struct *work) |
| 675 | { |
| 676 | struct radeon_device *rdev = |
| 677 | container_of(work, struct radeon_device, |
| 678 | pm.dpm.thermal.work); |
| 679 | /* switch to the thermal state */ |
| 680 | enum radeon_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL; |
| 681 | |
| 682 | if (!rdev->pm.dpm_enabled) |
| 683 | return; |
| 684 | |
| 685 | if (rdev->asic->pm.get_temperature) { |
| 686 | int temp = radeon_get_temperature(rdev); |
| 687 | |
| 688 | if (temp < rdev->pm.dpm.thermal.min_temp) |
| 689 | /* switch back the user state */ |
| 690 | dpm_state = rdev->pm.dpm.user_state; |
| 691 | } else { |
| 692 | if (rdev->pm.dpm.thermal.high_to_low) |
| 693 | /* switch back the user state */ |
| 694 | dpm_state = rdev->pm.dpm.user_state; |
| 695 | } |
Alex Deucher | 6032034 | 2013-07-24 14:59:48 -0400 | [diff] [blame] | 696 | mutex_lock(&rdev->pm.mutex); |
| 697 | if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL) |
| 698 | rdev->pm.dpm.thermal_active = true; |
| 699 | else |
| 700 | rdev->pm.dpm.thermal_active = false; |
| 701 | rdev->pm.dpm.state = dpm_state; |
| 702 | mutex_unlock(&rdev->pm.mutex); |
| 703 | |
| 704 | radeon_pm_compute_clocks(rdev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static struct radeon_ps *radeon_dpm_pick_power_state(struct radeon_device *rdev, |
| 708 | enum radeon_pm_state_type dpm_state) |
| 709 | { |
| 710 | int i; |
| 711 | struct radeon_ps *ps; |
| 712 | u32 ui_class; |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 713 | bool single_display = (rdev->pm.dpm.new_active_crtc_count < 2) ? |
| 714 | true : false; |
| 715 | |
| 716 | /* check if the vblank period is too short to adjust the mclk */ |
| 717 | if (single_display && rdev->asic->dpm.vblank_too_short) { |
| 718 | if (radeon_dpm_vblank_too_short(rdev)) |
| 719 | single_display = false; |
| 720 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 721 | |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 722 | /* certain older asics have a separare 3D performance state, |
| 723 | * so try that first if the user selected performance |
| 724 | */ |
| 725 | if (dpm_state == POWER_STATE_TYPE_PERFORMANCE) |
| 726 | dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 727 | /* balanced states don't exist at the moment */ |
| 728 | if (dpm_state == POWER_STATE_TYPE_BALANCED) |
| 729 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 730 | |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 731 | restart_search: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 732 | /* Pick the best power state based on current conditions */ |
| 733 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 734 | ps = &rdev->pm.dpm.ps[i]; |
| 735 | ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK; |
| 736 | switch (dpm_state) { |
| 737 | /* user states */ |
| 738 | case POWER_STATE_TYPE_BATTERY: |
| 739 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) { |
| 740 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 741 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 742 | return ps; |
| 743 | } else |
| 744 | return ps; |
| 745 | } |
| 746 | break; |
| 747 | case POWER_STATE_TYPE_BALANCED: |
| 748 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) { |
| 749 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 750 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 751 | return ps; |
| 752 | } else |
| 753 | return ps; |
| 754 | } |
| 755 | break; |
| 756 | case POWER_STATE_TYPE_PERFORMANCE: |
| 757 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) { |
| 758 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 759 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 760 | return ps; |
| 761 | } else |
| 762 | return ps; |
| 763 | } |
| 764 | break; |
| 765 | /* internal states */ |
| 766 | case POWER_STATE_TYPE_INTERNAL_UVD: |
Alex Deucher | d4d3278 | 2013-06-11 17:55:39 -0400 | [diff] [blame] | 767 | if (rdev->pm.dpm.uvd_ps) |
| 768 | return rdev->pm.dpm.uvd_ps; |
| 769 | else |
| 770 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 771 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 772 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) |
| 773 | return ps; |
| 774 | break; |
| 775 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 776 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE) |
| 777 | return ps; |
| 778 | break; |
| 779 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 780 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE) |
| 781 | return ps; |
| 782 | break; |
| 783 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 784 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC) |
| 785 | return ps; |
| 786 | break; |
| 787 | case POWER_STATE_TYPE_INTERNAL_BOOT: |
| 788 | return rdev->pm.dpm.boot_ps; |
| 789 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 790 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL) |
| 791 | return ps; |
| 792 | break; |
| 793 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 794 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) |
| 795 | return ps; |
| 796 | break; |
| 797 | case POWER_STATE_TYPE_INTERNAL_ULV: |
| 798 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) |
| 799 | return ps; |
| 800 | break; |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 801 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 802 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE) |
| 803 | return ps; |
| 804 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 805 | default: |
| 806 | break; |
| 807 | } |
| 808 | } |
| 809 | /* use a fallback state if we didn't match */ |
| 810 | switch (dpm_state) { |
| 811 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 812 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 813 | goto restart_search; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 814 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 815 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 816 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
Alex Deucher | d4d3278 | 2013-06-11 17:55:39 -0400 | [diff] [blame] | 817 | if (rdev->pm.dpm.uvd_ps) { |
| 818 | return rdev->pm.dpm.uvd_ps; |
| 819 | } else { |
| 820 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 821 | goto restart_search; |
| 822 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 823 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 824 | dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI; |
| 825 | goto restart_search; |
| 826 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 827 | dpm_state = POWER_STATE_TYPE_BATTERY; |
| 828 | goto restart_search; |
| 829 | case POWER_STATE_TYPE_BATTERY: |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 830 | case POWER_STATE_TYPE_BALANCED: |
| 831 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 832 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 833 | goto restart_search; |
| 834 | default: |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | return NULL; |
| 839 | } |
| 840 | |
| 841 | static void radeon_dpm_change_power_state_locked(struct radeon_device *rdev) |
| 842 | { |
| 843 | int i; |
| 844 | struct radeon_ps *ps; |
| 845 | enum radeon_pm_state_type dpm_state; |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 846 | int ret; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 847 | |
| 848 | /* if dpm init failed */ |
| 849 | if (!rdev->pm.dpm_enabled) |
| 850 | return; |
| 851 | |
| 852 | if (rdev->pm.dpm.user_state != rdev->pm.dpm.state) { |
| 853 | /* add other state override checks here */ |
Alex Deucher | 8a22755 | 2013-06-21 15:12:57 -0400 | [diff] [blame] | 854 | if ((!rdev->pm.dpm.thermal_active) && |
| 855 | (!rdev->pm.dpm.uvd_active)) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 856 | rdev->pm.dpm.state = rdev->pm.dpm.user_state; |
| 857 | } |
| 858 | dpm_state = rdev->pm.dpm.state; |
| 859 | |
| 860 | ps = radeon_dpm_pick_power_state(rdev, dpm_state); |
| 861 | if (ps) |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 862 | rdev->pm.dpm.requested_ps = ps; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 863 | else |
| 864 | return; |
| 865 | |
Alex Deucher | d22b7e4 | 2012-11-29 19:27:56 -0500 | [diff] [blame] | 866 | /* no need to reprogram if nothing changed unless we are on BTC+ */ |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 867 | if (rdev->pm.dpm.current_ps == rdev->pm.dpm.requested_ps) { |
Alex Deucher | b62d628 | 2013-08-20 20:29:05 -0400 | [diff] [blame] | 868 | /* vce just modifies an existing state so force a change */ |
| 869 | if (ps->vce_active != rdev->pm.dpm.vce_active) |
| 870 | goto force; |
Alex Deucher | d22b7e4 | 2012-11-29 19:27:56 -0500 | [diff] [blame] | 871 | if ((rdev->family < CHIP_BARTS) || (rdev->flags & RADEON_IS_IGP)) { |
| 872 | /* for pre-BTC and APUs if the num crtcs changed but state is the same, |
| 873 | * all we need to do is update the display configuration. |
| 874 | */ |
| 875 | if (rdev->pm.dpm.new_active_crtcs != rdev->pm.dpm.current_active_crtcs) { |
| 876 | /* update display watermarks based on new power state */ |
| 877 | radeon_bandwidth_update(rdev); |
| 878 | /* update displays */ |
| 879 | radeon_dpm_display_configuration_changed(rdev); |
| 880 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 881 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 882 | } |
| 883 | return; |
| 884 | } else { |
| 885 | /* for BTC+ if the num crtcs hasn't changed and state is the same, |
| 886 | * nothing to do, if the num crtcs is > 1 and state is the same, |
| 887 | * update display configuration. |
| 888 | */ |
| 889 | if (rdev->pm.dpm.new_active_crtcs == |
| 890 | rdev->pm.dpm.current_active_crtcs) { |
| 891 | return; |
| 892 | } else { |
| 893 | if ((rdev->pm.dpm.current_active_crtc_count > 1) && |
| 894 | (rdev->pm.dpm.new_active_crtc_count > 1)) { |
| 895 | /* update display watermarks based on new power state */ |
| 896 | radeon_bandwidth_update(rdev); |
| 897 | /* update displays */ |
| 898 | radeon_dpm_display_configuration_changed(rdev); |
| 899 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 900 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 901 | return; |
| 902 | } |
| 903 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 904 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Alex Deucher | b62d628 | 2013-08-20 20:29:05 -0400 | [diff] [blame] | 907 | force: |
Alex Deucher | 033a37d | 2013-10-23 18:35:43 -0400 | [diff] [blame] | 908 | if (radeon_dpm == 1) { |
| 909 | printk("switching from power state:\n"); |
| 910 | radeon_dpm_print_power_state(rdev, rdev->pm.dpm.current_ps); |
| 911 | printk("switching to power state:\n"); |
| 912 | radeon_dpm_print_power_state(rdev, rdev->pm.dpm.requested_ps); |
| 913 | } |
Alex Deucher | b62d628 | 2013-08-20 20:29:05 -0400 | [diff] [blame] | 914 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 915 | mutex_lock(&rdev->ddev->struct_mutex); |
| 916 | down_write(&rdev->pm.mclk_lock); |
| 917 | mutex_lock(&rdev->ring_lock); |
| 918 | |
Alex Deucher | b62d628 | 2013-08-20 20:29:05 -0400 | [diff] [blame] | 919 | /* update whether vce is active */ |
| 920 | ps->vce_active = rdev->pm.dpm.vce_active; |
| 921 | |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 922 | ret = radeon_dpm_pre_set_power_state(rdev); |
| 923 | if (ret) |
| 924 | goto done; |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 925 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 926 | /* update display watermarks based on new power state */ |
| 927 | radeon_bandwidth_update(rdev); |
| 928 | /* update displays */ |
| 929 | radeon_dpm_display_configuration_changed(rdev); |
| 930 | |
| 931 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 932 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 933 | |
| 934 | /* wait for the rings to drain */ |
| 935 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
| 936 | struct radeon_ring *ring = &rdev->ring[i]; |
| 937 | if (ring->ready) |
Christian König | 3761552 | 2014-02-18 15:58:31 +0100 | [diff] [blame] | 938 | radeon_fence_wait_empty(rdev, i); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* program the new power state */ |
| 942 | radeon_dpm_set_power_state(rdev); |
| 943 | |
| 944 | /* update current power state */ |
| 945 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps; |
| 946 | |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 947 | radeon_dpm_post_set_power_state(rdev); |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 948 | |
Alex Deucher | 1cd8b21 | 2013-09-13 14:07:03 -0400 | [diff] [blame] | 949 | if (rdev->asic->dpm.force_performance_level) { |
Alex Deucher | 14ac88a | 2013-10-23 17:31:42 -0400 | [diff] [blame] | 950 | if (rdev->pm.dpm.thermal_active) { |
| 951 | enum radeon_dpm_forced_level level = rdev->pm.dpm.forced_level; |
Alex Deucher | 1cd8b21 | 2013-09-13 14:07:03 -0400 | [diff] [blame] | 952 | /* force low perf level for thermal */ |
| 953 | radeon_dpm_force_performance_level(rdev, RADEON_DPM_FORCED_LEVEL_LOW); |
Alex Deucher | 14ac88a | 2013-10-23 17:31:42 -0400 | [diff] [blame] | 954 | /* save the user's level */ |
| 955 | rdev->pm.dpm.forced_level = level; |
| 956 | } else { |
| 957 | /* otherwise, user selected level */ |
| 958 | radeon_dpm_force_performance_level(rdev, rdev->pm.dpm.forced_level); |
| 959 | } |
Alex Deucher | 6032034 | 2013-07-24 14:59:48 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 962 | done: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 963 | mutex_unlock(&rdev->ring_lock); |
| 964 | up_write(&rdev->pm.mclk_lock); |
| 965 | mutex_unlock(&rdev->ddev->struct_mutex); |
| 966 | } |
| 967 | |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 968 | void radeon_dpm_enable_uvd(struct radeon_device *rdev, bool enable) |
| 969 | { |
| 970 | enum radeon_pm_state_type dpm_state; |
| 971 | |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 972 | if (rdev->asic->dpm.powergate_uvd) { |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 973 | mutex_lock(&rdev->pm.mutex); |
Christian König | 8158eb9 | 2014-01-10 16:05:05 +0100 | [diff] [blame] | 974 | /* don't powergate anything if we |
| 975 | have active but pause streams */ |
| 976 | enable |= rdev->pm.dpm.sd > 0; |
| 977 | enable |= rdev->pm.dpm.hd > 0; |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 978 | /* enable/disable UVD */ |
| 979 | radeon_dpm_powergate_uvd(rdev, !enable); |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 980 | mutex_unlock(&rdev->pm.mutex); |
| 981 | } else { |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 982 | if (enable) { |
| 983 | mutex_lock(&rdev->pm.mutex); |
| 984 | rdev->pm.dpm.uvd_active = true; |
Alex Deucher | 0690a22 | 2014-06-07 11:31:25 -0400 | [diff] [blame] | 985 | /* disable this for now */ |
| 986 | #if 0 |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 987 | if ((rdev->pm.dpm.sd == 1) && (rdev->pm.dpm.hd == 0)) |
| 988 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_SD; |
| 989 | else if ((rdev->pm.dpm.sd == 2) && (rdev->pm.dpm.hd == 0)) |
| 990 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 991 | else if ((rdev->pm.dpm.sd == 0) && (rdev->pm.dpm.hd == 1)) |
| 992 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 993 | else if ((rdev->pm.dpm.sd == 0) && (rdev->pm.dpm.hd == 2)) |
| 994 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD2; |
| 995 | else |
Alex Deucher | 0690a22 | 2014-06-07 11:31:25 -0400 | [diff] [blame] | 996 | #endif |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 997 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD; |
| 998 | rdev->pm.dpm.state = dpm_state; |
| 999 | mutex_unlock(&rdev->pm.mutex); |
| 1000 | } else { |
| 1001 | mutex_lock(&rdev->pm.mutex); |
| 1002 | rdev->pm.dpm.uvd_active = false; |
| 1003 | mutex_unlock(&rdev->pm.mutex); |
| 1004 | } |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 1005 | |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 1006 | radeon_pm_compute_clocks(rdev); |
| 1007 | } |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
Alex Deucher | 03afe6f | 2013-08-23 11:56:26 -0400 | [diff] [blame] | 1010 | void radeon_dpm_enable_vce(struct radeon_device *rdev, bool enable) |
| 1011 | { |
| 1012 | if (enable) { |
| 1013 | mutex_lock(&rdev->pm.mutex); |
| 1014 | rdev->pm.dpm.vce_active = true; |
| 1015 | /* XXX select vce level based on ring/task */ |
| 1016 | rdev->pm.dpm.vce_level = RADEON_VCE_LEVEL_AC_ALL; |
| 1017 | mutex_unlock(&rdev->pm.mutex); |
| 1018 | } else { |
| 1019 | mutex_lock(&rdev->pm.mutex); |
| 1020 | rdev->pm.dpm.vce_active = false; |
| 1021 | mutex_unlock(&rdev->pm.mutex); |
| 1022 | } |
| 1023 | |
| 1024 | radeon_pm_compute_clocks(rdev); |
| 1025 | } |
| 1026 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1027 | static void radeon_pm_suspend_old(struct radeon_device *rdev) |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1028 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1029 | mutex_lock(&rdev->pm.mutex); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1030 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1031 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) |
| 1032 | rdev->pm.dynpm_state = DYNPM_STATE_SUSPENDED; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1033 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1034 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1035 | |
| 1036 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1039 | static void radeon_pm_suspend_dpm(struct radeon_device *rdev) |
| 1040 | { |
| 1041 | mutex_lock(&rdev->pm.mutex); |
| 1042 | /* disable dpm */ |
| 1043 | radeon_dpm_disable(rdev); |
| 1044 | /* reset the power state */ |
| 1045 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
| 1046 | rdev->pm.dpm_enabled = false; |
| 1047 | mutex_unlock(&rdev->pm.mutex); |
| 1048 | } |
| 1049 | |
| 1050 | void radeon_pm_suspend(struct radeon_device *rdev) |
| 1051 | { |
| 1052 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1053 | radeon_pm_suspend_dpm(rdev); |
| 1054 | else |
| 1055 | radeon_pm_suspend_old(rdev); |
| 1056 | } |
| 1057 | |
| 1058 | static void radeon_pm_resume_old(struct radeon_device *rdev) |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 1059 | { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1060 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1061 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | 3609918 | 2013-09-21 14:37:49 -0400 | [diff] [blame] | 1062 | (rdev->family <= CHIP_CAYMAN) && |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1063 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1064 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 1065 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1066 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 1067 | if (rdev->pm.default_vddci) |
| 1068 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1069 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1070 | if (rdev->pm.default_sclk) |
| 1071 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1072 | if (rdev->pm.default_mclk) |
| 1073 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1074 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1075 | /* asic init will reset the default power state */ |
| 1076 | mutex_lock(&rdev->pm.mutex); |
| 1077 | rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; |
| 1078 | rdev->pm.current_clock_mode_index = 0; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 1079 | rdev->pm.current_sclk = rdev->pm.default_sclk; |
| 1080 | rdev->pm.current_mclk = rdev->pm.default_mclk; |
Michel Dänzer | 3701695 | 2014-01-08 11:40:20 +0900 | [diff] [blame] | 1081 | if (rdev->pm.power_state) { |
| 1082 | rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage; |
| 1083 | rdev->pm.current_vddci = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.vddci; |
| 1084 | } |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1085 | if (rdev->pm.pm_method == PM_METHOD_DYNPM |
| 1086 | && rdev->pm.dynpm_state == DYNPM_STATE_SUSPENDED) { |
| 1087 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1088 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1089 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1090 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1091 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1092 | radeon_pm_compute_clocks(rdev); |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1095 | static void radeon_pm_resume_dpm(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1096 | { |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 1097 | int ret; |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 1098 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1099 | /* asic init will reset to the boot state */ |
| 1100 | mutex_lock(&rdev->pm.mutex); |
| 1101 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
| 1102 | radeon_dpm_setup_asic(rdev); |
| 1103 | ret = radeon_dpm_enable(rdev); |
| 1104 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | e14cd2b | 2013-12-19 16:17:47 -0500 | [diff] [blame] | 1105 | if (ret) |
| 1106 | goto dpm_resume_fail; |
Alex Deucher | e14cd2b | 2013-12-19 16:17:47 -0500 | [diff] [blame] | 1107 | rdev->pm.dpm_enabled = true; |
Alex Deucher | e14cd2b | 2013-12-19 16:17:47 -0500 | [diff] [blame] | 1108 | return; |
| 1109 | |
| 1110 | dpm_resume_fail: |
| 1111 | DRM_ERROR("radeon: dpm resume failed\n"); |
| 1112 | if ((rdev->family >= CHIP_BARTS) && |
| 1113 | (rdev->family <= CHIP_CAYMAN) && |
| 1114 | rdev->mc_fw) { |
| 1115 | if (rdev->pm.default_vddc) |
| 1116 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1117 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
| 1118 | if (rdev->pm.default_vddci) |
| 1119 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1120 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
| 1121 | if (rdev->pm.default_sclk) |
| 1122 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1123 | if (rdev->pm.default_mclk) |
| 1124 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | void radeon_pm_resume(struct radeon_device *rdev) |
| 1129 | { |
| 1130 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1131 | radeon_pm_resume_dpm(rdev); |
| 1132 | else |
| 1133 | radeon_pm_resume_old(rdev); |
| 1134 | } |
| 1135 | |
| 1136 | static int radeon_pm_init_old(struct radeon_device *rdev) |
| 1137 | { |
| 1138 | int ret; |
| 1139 | |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1140 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1141 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 1142 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1143 | rdev->pm.dynpm_can_upclock = true; |
| 1144 | rdev->pm.dynpm_can_downclock = true; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 1145 | rdev->pm.default_sclk = rdev->clock.default_sclk; |
| 1146 | rdev->pm.default_mclk = rdev->clock.default_mclk; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1147 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 1148 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 1149 | rdev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1150 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1151 | if (rdev->bios) { |
| 1152 | if (rdev->is_atom_bios) |
| 1153 | radeon_atombios_get_power_modes(rdev); |
| 1154 | else |
| 1155 | radeon_combios_get_power_modes(rdev); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 1156 | radeon_pm_print_states(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1157 | radeon_pm_init_profile(rdev); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1158 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1159 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | 3609918 | 2013-09-21 14:37:49 -0400 | [diff] [blame] | 1160 | (rdev->family <= CHIP_CAYMAN) && |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1161 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1162 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 1163 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1164 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4639dd2 | 2011-07-25 18:50:08 -0400 | [diff] [blame] | 1165 | if (rdev->pm.default_vddci) |
| 1166 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1167 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1168 | if (rdev->pm.default_sclk) |
| 1169 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1170 | if (rdev->pm.default_mclk) |
| 1171 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1172 | } |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1173 | } |
| 1174 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 1175 | /* set up the internal thermal sensor if applicable */ |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 1176 | ret = radeon_hwmon_init(rdev); |
| 1177 | if (ret) |
| 1178 | return ret; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1179 | |
| 1180 | INIT_DELAYED_WORK(&rdev->pm.dynpm_idle_work, radeon_dynpm_idle_work_handler); |
| 1181 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1182 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1183 | /* where's the best place to put these? */ |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 1184 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 1185 | if (ret) |
| 1186 | DRM_ERROR("failed to create device file for power profile\n"); |
| 1187 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 1188 | if (ret) |
| 1189 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1190 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1191 | if (radeon_debugfs_pm_init(rdev)) { |
| 1192 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
| 1193 | } |
| 1194 | |
| 1195 | DRM_INFO("radeon: power management initialized\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1201 | static void radeon_dpm_print_power_states(struct radeon_device *rdev) |
| 1202 | { |
| 1203 | int i; |
| 1204 | |
| 1205 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 1206 | printk("== power state %d ==\n", i); |
| 1207 | radeon_dpm_print_power_state(rdev, &rdev->pm.dpm.ps[i]); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static int radeon_pm_init_dpm(struct radeon_device *rdev) |
| 1212 | { |
| 1213 | int ret; |
| 1214 | |
Alex Deucher | 1cd8b21 | 2013-09-13 14:07:03 -0400 | [diff] [blame] | 1215 | /* default to balanced state */ |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 1216 | rdev->pm.dpm.state = POWER_STATE_TYPE_BALANCED; |
| 1217 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; |
Alex Deucher | 1cd8b21 | 2013-09-13 14:07:03 -0400 | [diff] [blame] | 1218 | rdev->pm.dpm.forced_level = RADEON_DPM_FORCED_LEVEL_AUTO; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1219 | rdev->pm.default_sclk = rdev->clock.default_sclk; |
| 1220 | rdev->pm.default_mclk = rdev->clock.default_mclk; |
| 1221 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 1222 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
| 1223 | rdev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
| 1224 | |
| 1225 | if (rdev->bios && rdev->is_atom_bios) |
| 1226 | radeon_atombios_get_power_modes(rdev); |
| 1227 | else |
| 1228 | return -EINVAL; |
| 1229 | |
| 1230 | /* set up the internal thermal sensor if applicable */ |
| 1231 | ret = radeon_hwmon_init(rdev); |
| 1232 | if (ret) |
| 1233 | return ret; |
| 1234 | |
| 1235 | INIT_WORK(&rdev->pm.dpm.thermal.work, radeon_dpm_thermal_work_handler); |
| 1236 | mutex_lock(&rdev->pm.mutex); |
| 1237 | radeon_dpm_init(rdev); |
| 1238 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
Alex Deucher | 033a37d | 2013-10-23 18:35:43 -0400 | [diff] [blame] | 1239 | if (radeon_dpm == 1) |
| 1240 | radeon_dpm_print_power_states(rdev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1241 | radeon_dpm_setup_asic(rdev); |
| 1242 | ret = radeon_dpm_enable(rdev); |
| 1243 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | e14cd2b | 2013-12-19 16:17:47 -0500 | [diff] [blame] | 1244 | if (ret) |
| 1245 | goto dpm_failed; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1246 | rdev->pm.dpm_enabled = true; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1247 | |
Alex Deucher | bb5abf9 | 2013-12-18 13:39:58 -0500 | [diff] [blame] | 1248 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_state); |
| 1249 | if (ret) |
| 1250 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 1251 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); |
| 1252 | if (ret) |
| 1253 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 1254 | /* XXX: these are noops for dpm but are here for backwards compat */ |
| 1255 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 1256 | if (ret) |
| 1257 | DRM_ERROR("failed to create device file for power profile\n"); |
| 1258 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 1259 | if (ret) |
| 1260 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1261 | |
Alex Deucher | bb5abf9 | 2013-12-18 13:39:58 -0500 | [diff] [blame] | 1262 | if (radeon_debugfs_pm_init(rdev)) { |
| 1263 | DRM_ERROR("Failed to register debugfs file for dpm!\n"); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
Alex Deucher | bb5abf9 | 2013-12-18 13:39:58 -0500 | [diff] [blame] | 1266 | DRM_INFO("radeon: dpm initialized\n"); |
| 1267 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1268 | return 0; |
Alex Deucher | e14cd2b | 2013-12-19 16:17:47 -0500 | [diff] [blame] | 1269 | |
| 1270 | dpm_failed: |
| 1271 | rdev->pm.dpm_enabled = false; |
| 1272 | if ((rdev->family >= CHIP_BARTS) && |
| 1273 | (rdev->family <= CHIP_CAYMAN) && |
| 1274 | rdev->mc_fw) { |
| 1275 | if (rdev->pm.default_vddc) |
| 1276 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1277 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
| 1278 | if (rdev->pm.default_vddci) |
| 1279 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1280 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
| 1281 | if (rdev->pm.default_sclk) |
| 1282 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1283 | if (rdev->pm.default_mclk) |
| 1284 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1285 | } |
| 1286 | DRM_ERROR("radeon: dpm initialization failed\n"); |
| 1287 | return ret; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Alex Deucher | 4369a69 | 2015-01-08 10:46:33 -0500 | [diff] [blame^] | 1290 | struct radeon_dpm_quirk { |
| 1291 | u32 chip_vendor; |
| 1292 | u32 chip_device; |
| 1293 | u32 subsys_vendor; |
| 1294 | u32 subsys_device; |
| 1295 | }; |
| 1296 | |
| 1297 | /* cards with dpm stability problems */ |
| 1298 | static struct radeon_dpm_quirk radeon_dpm_quirk_list[] = { |
| 1299 | /* TURKS - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1386534 */ |
| 1300 | { PCI_VENDOR_ID_ATI, 0x6759, 0x1682, 0x3195 }, |
| 1301 | /* TURKS - https://bugzilla.kernel.org/show_bug.cgi?id=83731 */ |
| 1302 | { PCI_VENDOR_ID_ATI, 0x6840, 0x1179, 0xfb81 }, |
| 1303 | { 0, 0, 0, 0 }, |
| 1304 | }; |
| 1305 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1306 | int radeon_pm_init(struct radeon_device *rdev) |
| 1307 | { |
Alex Deucher | 4369a69 | 2015-01-08 10:46:33 -0500 | [diff] [blame^] | 1308 | struct radeon_dpm_quirk *p = radeon_dpm_quirk_list; |
| 1309 | bool disable_dpm = false; |
| 1310 | |
| 1311 | /* Apply dpm quirks */ |
| 1312 | while (p && p->chip_device != 0) { |
| 1313 | if (rdev->pdev->vendor == p->chip_vendor && |
| 1314 | rdev->pdev->device == p->chip_device && |
| 1315 | rdev->pdev->subsystem_vendor == p->subsys_vendor && |
| 1316 | rdev->pdev->subsystem_device == p->subsys_device) { |
| 1317 | disable_dpm = true; |
| 1318 | break; |
| 1319 | } |
| 1320 | ++p; |
| 1321 | } |
| 1322 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1323 | /* enable dpm on rv6xx+ */ |
| 1324 | switch (rdev->family) { |
Alex Deucher | 4a6369e | 2013-04-12 14:04:10 -0400 | [diff] [blame] | 1325 | case CHIP_RV610: |
| 1326 | case CHIP_RV630: |
| 1327 | case CHIP_RV620: |
| 1328 | case CHIP_RV635: |
| 1329 | case CHIP_RV670: |
Alex Deucher | 9d67006 | 2013-04-12 13:59:22 -0400 | [diff] [blame] | 1330 | case CHIP_RS780: |
| 1331 | case CHIP_RS880: |
Alex Deucher | 76e6dce | 2014-04-18 09:08:11 -0400 | [diff] [blame] | 1332 | case CHIP_RV770: |
Alex Deucher | 8a53fa2 | 2013-08-07 16:09:08 -0400 | [diff] [blame] | 1333 | /* DPM requires the RLC, RV770+ dGPU requires SMC */ |
Alex Deucher | 761bfb9 | 2013-08-06 13:34:00 -0400 | [diff] [blame] | 1334 | if (!rdev->rlc_fw) |
| 1335 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 8a53fa2 | 2013-08-07 16:09:08 -0400 | [diff] [blame] | 1336 | else if ((rdev->family >= CHIP_RV770) && |
| 1337 | (!(rdev->flags & RADEON_IS_IGP)) && |
| 1338 | (!rdev->smc_fw)) |
| 1339 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 761bfb9 | 2013-08-06 13:34:00 -0400 | [diff] [blame] | 1340 | else if (radeon_dpm == 1) |
Alex Deucher | 9d67006 | 2013-04-12 13:59:22 -0400 | [diff] [blame] | 1341 | rdev->pm.pm_method = PM_METHOD_DPM; |
| 1342 | else |
| 1343 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1344 | break; |
Alex Deucher | ab70b1d | 2013-11-01 15:16:02 -0400 | [diff] [blame] | 1345 | case CHIP_RV730: |
| 1346 | case CHIP_RV710: |
| 1347 | case CHIP_RV740: |
Alex Deucher | 59f7a2f | 2013-11-01 15:11:34 -0400 | [diff] [blame] | 1348 | case CHIP_CEDAR: |
| 1349 | case CHIP_REDWOOD: |
| 1350 | case CHIP_JUNIPER: |
| 1351 | case CHIP_CYPRESS: |
| 1352 | case CHIP_HEMLOCK: |
Alex Deucher | 5a16f76 | 2013-10-23 17:11:06 -0400 | [diff] [blame] | 1353 | case CHIP_PALM: |
| 1354 | case CHIP_SUMO: |
| 1355 | case CHIP_SUMO2: |
Alex Deucher | c08abf1 | 2014-07-14 12:01:40 -0400 | [diff] [blame] | 1356 | case CHIP_BARTS: |
| 1357 | case CHIP_TURKS: |
| 1358 | case CHIP_CAICOS: |
Alex Deucher | 8f500af | 2014-07-07 17:13:37 -0400 | [diff] [blame] | 1359 | case CHIP_CAYMAN: |
Alex Deucher | 3a11898 | 2013-11-14 10:21:29 -0500 | [diff] [blame] | 1360 | case CHIP_ARUBA: |
Alex Deucher | 68bc778 | 2013-10-23 17:14:06 -0400 | [diff] [blame] | 1361 | case CHIP_TAHITI: |
| 1362 | case CHIP_PITCAIRN: |
| 1363 | case CHIP_VERDE: |
| 1364 | case CHIP_OLAND: |
| 1365 | case CHIP_HAINAN: |
Alex Deucher | 4f22dde | 2013-12-19 17:37:33 -0500 | [diff] [blame] | 1366 | case CHIP_BONAIRE: |
Alex Deucher | e308b1d | 2013-12-19 17:39:17 -0500 | [diff] [blame] | 1367 | case CHIP_KABINI: |
| 1368 | case CHIP_KAVERI: |
Alex Deucher | 4f22dde | 2013-12-19 17:37:33 -0500 | [diff] [blame] | 1369 | case CHIP_HAWAII: |
Samuel Li | 7d032a4 | 2014-04-30 18:40:51 -0400 | [diff] [blame] | 1370 | case CHIP_MULLINS: |
Alex Deucher | 5a16f76 | 2013-10-23 17:11:06 -0400 | [diff] [blame] | 1371 | /* DPM requires the RLC, RV770+ dGPU requires SMC */ |
| 1372 | if (!rdev->rlc_fw) |
| 1373 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1374 | else if ((rdev->family >= CHIP_RV770) && |
| 1375 | (!(rdev->flags & RADEON_IS_IGP)) && |
| 1376 | (!rdev->smc_fw)) |
| 1377 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 4369a69 | 2015-01-08 10:46:33 -0500 | [diff] [blame^] | 1378 | else if (disable_dpm && (radeon_dpm == -1)) |
| 1379 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 5a16f76 | 2013-10-23 17:11:06 -0400 | [diff] [blame] | 1380 | else if (radeon_dpm == 0) |
| 1381 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1382 | else |
| 1383 | rdev->pm.pm_method = PM_METHOD_DPM; |
| 1384 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1385 | default: |
| 1386 | /* default to profile method */ |
| 1387 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1388 | break; |
| 1389 | } |
| 1390 | |
| 1391 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1392 | return radeon_pm_init_dpm(rdev); |
| 1393 | else |
| 1394 | return radeon_pm_init_old(rdev); |
| 1395 | } |
| 1396 | |
Alex Deucher | 914a898 | 2013-12-19 11:37:22 -0500 | [diff] [blame] | 1397 | int radeon_pm_late_init(struct radeon_device *rdev) |
| 1398 | { |
| 1399 | int ret = 0; |
| 1400 | |
| 1401 | if (rdev->pm.pm_method == PM_METHOD_DPM) { |
| 1402 | mutex_lock(&rdev->pm.mutex); |
| 1403 | ret = radeon_dpm_late_enable(rdev); |
| 1404 | mutex_unlock(&rdev->pm.mutex); |
| 1405 | } |
| 1406 | return ret; |
| 1407 | } |
| 1408 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1409 | static void radeon_pm_fini_old(struct radeon_device *rdev) |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1410 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1411 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1412 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1413 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 1414 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 1415 | radeon_pm_update_profile(rdev); |
| 1416 | radeon_pm_set_clocks(rdev); |
| 1417 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1418 | /* reset default clocks */ |
| 1419 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 1420 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 1421 | radeon_pm_set_clocks(rdev); |
| 1422 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1423 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1424 | |
| 1425 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 1426 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1427 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 1428 | device_remove_file(rdev->dev, &dev_attr_power_method); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1429 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1430 | |
Alex Deucher | cb3e4e7 | 2014-04-15 12:44:32 -0400 | [diff] [blame] | 1431 | radeon_hwmon_fini(rdev); |
Fabian Frederick | 9c24487 | 2014-07-04 21:37:09 +0200 | [diff] [blame] | 1432 | kfree(rdev->pm.power_state); |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1435 | static void radeon_pm_fini_dpm(struct radeon_device *rdev) |
| 1436 | { |
| 1437 | if (rdev->pm.num_power_states > 1) { |
| 1438 | mutex_lock(&rdev->pm.mutex); |
| 1439 | radeon_dpm_disable(rdev); |
| 1440 | mutex_unlock(&rdev->pm.mutex); |
| 1441 | |
| 1442 | device_remove_file(rdev->dev, &dev_attr_power_dpm_state); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 1443 | device_remove_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1444 | /* XXX backwards compat */ |
| 1445 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 1446 | device_remove_file(rdev->dev, &dev_attr_power_method); |
| 1447 | } |
| 1448 | radeon_dpm_fini(rdev); |
| 1449 | |
Alex Deucher | cb3e4e7 | 2014-04-15 12:44:32 -0400 | [diff] [blame] | 1450 | radeon_hwmon_fini(rdev); |
Fabian Frederick | 9c24487 | 2014-07-04 21:37:09 +0200 | [diff] [blame] | 1451 | kfree(rdev->pm.power_state); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | void radeon_pm_fini(struct radeon_device *rdev) |
| 1455 | { |
| 1456 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1457 | radeon_pm_fini_dpm(rdev); |
| 1458 | else |
| 1459 | radeon_pm_fini_old(rdev); |
| 1460 | } |
| 1461 | |
| 1462 | static void radeon_pm_compute_clocks_old(struct radeon_device *rdev) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1463 | { |
| 1464 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 1465 | struct drm_crtc *crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1466 | struct radeon_crtc *radeon_crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1467 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1468 | if (rdev->pm.num_power_states < 2) |
| 1469 | return; |
| 1470 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1471 | mutex_lock(&rdev->pm.mutex); |
| 1472 | |
| 1473 | rdev->pm.active_crtcs = 0; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 1474 | rdev->pm.active_crtc_count = 0; |
Alex Deucher | 3ed9a33 | 2014-04-15 12:44:33 -0400 | [diff] [blame] | 1475 | if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) { |
| 1476 | list_for_each_entry(crtc, |
| 1477 | &ddev->mode_config.crtc_list, head) { |
| 1478 | radeon_crtc = to_radeon_crtc(crtc); |
| 1479 | if (radeon_crtc->enabled) { |
| 1480 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
| 1481 | rdev->pm.active_crtc_count++; |
| 1482 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1486 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 1487 | radeon_pm_update_profile(rdev); |
| 1488 | radeon_pm_set_clocks(rdev); |
| 1489 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
| 1490 | if (rdev->pm.dynpm_state != DYNPM_STATE_DISABLED) { |
| 1491 | if (rdev->pm.active_crtc_count > 1) { |
| 1492 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
| 1493 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 1494 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1495 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 1496 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 1497 | radeon_pm_get_dynpm_state(rdev); |
| 1498 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1499 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1500 | DRM_DEBUG_DRIVER("radeon: dynamic power management deactivated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1501 | } |
| 1502 | } else if (rdev->pm.active_crtc_count == 1) { |
| 1503 | /* TODO: Increase clocks if needed for current mode */ |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1504 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1505 | if (rdev->pm.dynpm_state == DYNPM_STATE_MINIMUM) { |
| 1506 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
| 1507 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_UPCLOCK; |
| 1508 | radeon_pm_get_dynpm_state(rdev); |
| 1509 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1510 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1511 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1512 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1513 | } else if (rdev->pm.dynpm_state == DYNPM_STATE_PAUSED) { |
| 1514 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1515 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1516 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1517 | DRM_DEBUG_DRIVER("radeon: dynamic power management activated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1518 | } |
| 1519 | } else { /* count == 0 */ |
| 1520 | if (rdev->pm.dynpm_state != DYNPM_STATE_MINIMUM) { |
| 1521 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1522 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1523 | rdev->pm.dynpm_state = DYNPM_STATE_MINIMUM; |
| 1524 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_MINIMUM; |
| 1525 | radeon_pm_get_dynpm_state(rdev); |
| 1526 | radeon_pm_set_clocks(rdev); |
| 1527 | } |
| 1528 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1529 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1530 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 1531 | |
| 1532 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1535 | static void radeon_pm_compute_clocks_dpm(struct radeon_device *rdev) |
| 1536 | { |
| 1537 | struct drm_device *ddev = rdev->ddev; |
| 1538 | struct drm_crtc *crtc; |
| 1539 | struct radeon_crtc *radeon_crtc; |
| 1540 | |
Alex Deucher | 6c7bcce | 2013-12-18 14:07:14 -0500 | [diff] [blame] | 1541 | if (!rdev->pm.dpm_enabled) |
| 1542 | return; |
| 1543 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1544 | mutex_lock(&rdev->pm.mutex); |
| 1545 | |
Alex Deucher | 5ca302f | 2012-11-30 10:56:57 -0500 | [diff] [blame] | 1546 | /* update active crtc counts */ |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1547 | rdev->pm.dpm.new_active_crtcs = 0; |
| 1548 | rdev->pm.dpm.new_active_crtc_count = 0; |
Alex Deucher | 3ed9a33 | 2014-04-15 12:44:33 -0400 | [diff] [blame] | 1549 | if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) { |
| 1550 | list_for_each_entry(crtc, |
| 1551 | &ddev->mode_config.crtc_list, head) { |
| 1552 | radeon_crtc = to_radeon_crtc(crtc); |
| 1553 | if (crtc->enabled) { |
| 1554 | rdev->pm.dpm.new_active_crtcs |= (1 << radeon_crtc->crtc_id); |
| 1555 | rdev->pm.dpm.new_active_crtc_count++; |
| 1556 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | |
Alex Deucher | 5ca302f | 2012-11-30 10:56:57 -0500 | [diff] [blame] | 1560 | /* update battery/ac status */ |
| 1561 | if (power_supply_is_system_supplied() > 0) |
| 1562 | rdev->pm.dpm.ac_power = true; |
| 1563 | else |
| 1564 | rdev->pm.dpm.ac_power = false; |
| 1565 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1566 | radeon_dpm_change_power_state_locked(rdev); |
| 1567 | |
| 1568 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | 8a22755 | 2013-06-21 15:12:57 -0400 | [diff] [blame] | 1569 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 1573 | { |
| 1574 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1575 | radeon_pm_compute_clocks_dpm(rdev); |
| 1576 | else |
| 1577 | radeon_pm_compute_clocks_old(rdev); |
| 1578 | } |
| 1579 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1580 | static bool radeon_pm_in_vbl(struct radeon_device *rdev) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1581 | { |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 1582 | int crtc, vpos, hpos, vbl_status; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1583 | bool in_vbl = true; |
| 1584 | |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 1585 | /* Iterate over all active crtc's. All crtc's must be in vblank, |
| 1586 | * otherwise return in_vbl == false. |
| 1587 | */ |
| 1588 | for (crtc = 0; (crtc < rdev->num_crtc) && in_vbl; crtc++) { |
| 1589 | if (rdev->pm.active_crtcs & (1 << crtc)) { |
Ville Syrjälä | abca9e4 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 1590 | vbl_status = radeon_get_crtc_scanoutpos(rdev->ddev, crtc, 0, &vpos, &hpos, NULL, NULL); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1591 | if ((vbl_status & DRM_SCANOUTPOS_VALID) && |
Daniel Vetter | 3d3cbd8 | 2014-09-10 17:36:11 +0200 | [diff] [blame] | 1592 | !(vbl_status & DRM_SCANOUTPOS_IN_VBLANK)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1593 | in_vbl = false; |
| 1594 | } |
| 1595 | } |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 1596 | |
| 1597 | return in_vbl; |
| 1598 | } |
| 1599 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1600 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish) |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 1601 | { |
| 1602 | u32 stat_crtc = 0; |
| 1603 | bool in_vbl = radeon_pm_in_vbl(rdev); |
| 1604 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1605 | if (in_vbl == false) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1606 | DRM_DEBUG_DRIVER("not in vbl for pm change %08x at %s\n", stat_crtc, |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 1607 | finish ? "exit" : "entry"); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1608 | return in_vbl; |
| 1609 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1610 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1611 | static void radeon_dynpm_idle_work_handler(struct work_struct *work) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1612 | { |
| 1613 | struct radeon_device *rdev; |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1614 | int resched; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1615 | rdev = container_of(work, struct radeon_device, |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1616 | pm.dynpm_idle_work.work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1617 | |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1618 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1619 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1620 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1621 | int not_processed = 0; |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 1622 | int i; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1623 | |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 1624 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
Alex Deucher | 0ec0612 | 2012-06-14 15:54:57 -0400 | [diff] [blame] | 1625 | struct radeon_ring *ring = &rdev->ring[i]; |
| 1626 | |
| 1627 | if (ring->ready) { |
| 1628 | not_processed += radeon_fence_count_emitted(rdev, i); |
| 1629 | if (not_processed >= 3) |
| 1630 | break; |
| 1631 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1632 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1633 | |
| 1634 | if (not_processed >= 3) { /* should upclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1635 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_DOWNCLOCK) { |
| 1636 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1637 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 1638 | rdev->pm.dynpm_can_upclock) { |
| 1639 | rdev->pm.dynpm_planned_action = |
| 1640 | DYNPM_ACTION_UPCLOCK; |
| 1641 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1642 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 1643 | } |
| 1644 | } else if (not_processed == 0) { /* should downclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1645 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_UPCLOCK) { |
| 1646 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1647 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 1648 | rdev->pm.dynpm_can_downclock) { |
| 1649 | rdev->pm.dynpm_planned_action = |
| 1650 | DYNPM_ACTION_DOWNCLOCK; |
| 1651 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1652 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 1653 | } |
| 1654 | } |
| 1655 | |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 1656 | /* Note, radeon_pm_set_clocks is called with static_switch set |
| 1657 | * to false since we want to wait for vbl to avoid flicker. |
| 1658 | */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1659 | if (rdev->pm.dynpm_planned_action != DYNPM_ACTION_NONE && |
| 1660 | jiffies > rdev->pm.dynpm_action_timeout) { |
| 1661 | radeon_pm_get_dynpm_state(rdev); |
| 1662 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1663 | } |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1664 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1665 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1666 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1667 | } |
| 1668 | mutex_unlock(&rdev->pm.mutex); |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1669 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1672 | /* |
| 1673 | * Debugfs info |
| 1674 | */ |
| 1675 | #if defined(CONFIG_DEBUG_FS) |
| 1676 | |
| 1677 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 1678 | { |
| 1679 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 1680 | struct drm_device *dev = node->minor->dev; |
| 1681 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 1682 | struct drm_device *ddev = rdev->ddev; |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1683 | |
Alex Deucher | 4f2f203 | 2014-05-19 19:21:29 -0400 | [diff] [blame] | 1684 | if ((rdev->flags & RADEON_IS_PX) && |
| 1685 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) { |
| 1686 | seq_printf(m, "PX asic powered off\n"); |
| 1687 | } else if (rdev->pm.dpm_enabled) { |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1688 | mutex_lock(&rdev->pm.mutex); |
| 1689 | if (rdev->asic->dpm.debugfs_print_current_performance_level) |
| 1690 | radeon_dpm_debugfs_print_current_performance_level(rdev, m); |
| 1691 | else |
Alex Deucher | 7137592 | 2013-07-02 09:11:39 -0400 | [diff] [blame] | 1692 | seq_printf(m, "Debugfs support not implemented for this asic\n"); |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1693 | mutex_unlock(&rdev->pm.mutex); |
| 1694 | } else { |
| 1695 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->pm.default_sclk); |
| 1696 | /* radeon_get_engine_clock is not reliable on APUs so just print the current clock */ |
| 1697 | if ((rdev->family >= CHIP_PALM) && (rdev->flags & RADEON_IS_IGP)) |
| 1698 | seq_printf(m, "current engine clock: %u0 kHz\n", rdev->pm.current_sclk); |
| 1699 | else |
| 1700 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 1701 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->pm.default_mclk); |
| 1702 | if (rdev->asic->pm.get_memory_clock) |
| 1703 | seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
| 1704 | if (rdev->pm.current_vddc) |
| 1705 | seq_printf(m, "voltage: %u mV\n", rdev->pm.current_vddc); |
| 1706 | if (rdev->asic->pm.get_pcie_lanes) |
| 1707 | seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev)); |
| 1708 | } |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
| 1713 | static struct drm_info_list radeon_pm_info_list[] = { |
| 1714 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 1715 | }; |
| 1716 | #endif |
| 1717 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1718 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1719 | { |
| 1720 | #if defined(CONFIG_DEBUG_FS) |
| 1721 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 1722 | #else |
| 1723 | return 0; |
| 1724 | #endif |
| 1725 | } |