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