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 | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 70 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 71 | if (rdev->pm.profile == PM_PROFILE_AUTO) { |
| 72 | mutex_lock(&rdev->pm.mutex); |
| 73 | radeon_pm_update_profile(rdev); |
| 74 | radeon_pm_set_clocks(rdev); |
| 75 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 76 | } |
| 77 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 78 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 79 | |
| 80 | static void radeon_pm_update_profile(struct radeon_device *rdev) |
| 81 | { |
| 82 | switch (rdev->pm.profile) { |
| 83 | case PM_PROFILE_DEFAULT: |
| 84 | rdev->pm.profile_index = PM_PROFILE_DEFAULT_IDX; |
| 85 | break; |
| 86 | case PM_PROFILE_AUTO: |
| 87 | if (power_supply_is_system_supplied() > 0) { |
| 88 | if (rdev->pm.active_crtc_count > 1) |
| 89 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 90 | else |
| 91 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 92 | } else { |
| 93 | if (rdev->pm.active_crtc_count > 1) |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 94 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 95 | else |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 96 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 97 | } |
| 98 | break; |
| 99 | case PM_PROFILE_LOW: |
| 100 | if (rdev->pm.active_crtc_count > 1) |
| 101 | rdev->pm.profile_index = PM_PROFILE_LOW_MH_IDX; |
| 102 | else |
| 103 | rdev->pm.profile_index = PM_PROFILE_LOW_SH_IDX; |
| 104 | break; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 105 | case PM_PROFILE_MID: |
| 106 | if (rdev->pm.active_crtc_count > 1) |
| 107 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
| 108 | else |
| 109 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
| 110 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 111 | case PM_PROFILE_HIGH: |
| 112 | if (rdev->pm.active_crtc_count > 1) |
| 113 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 114 | else |
| 115 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | if (rdev->pm.active_crtc_count == 0) { |
| 120 | rdev->pm.requested_power_state_index = |
| 121 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_ps_idx; |
| 122 | rdev->pm.requested_clock_mode_index = |
| 123 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_cm_idx; |
| 124 | } else { |
| 125 | rdev->pm.requested_power_state_index = |
| 126 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_ps_idx; |
| 127 | rdev->pm.requested_clock_mode_index = |
| 128 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_cm_idx; |
| 129 | } |
| 130 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 131 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 132 | static void radeon_unmap_vram_bos(struct radeon_device *rdev) |
| 133 | { |
| 134 | struct radeon_bo *bo, *n; |
| 135 | |
| 136 | if (list_empty(&rdev->gem.objects)) |
| 137 | return; |
| 138 | |
| 139 | list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) { |
| 140 | if (bo->tbo.mem.mem_type == TTM_PL_VRAM) |
| 141 | ttm_bo_unmap_virtual(&bo->tbo); |
| 142 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 145 | static void radeon_sync_with_vblank(struct radeon_device *rdev) |
| 146 | { |
| 147 | if (rdev->pm.active_crtcs) { |
| 148 | rdev->pm.vblank_sync = false; |
| 149 | wait_event_timeout( |
| 150 | rdev->irq.vblank_queue, rdev->pm.vblank_sync, |
| 151 | msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT)); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | static void radeon_set_power_state(struct radeon_device *rdev) |
| 156 | { |
| 157 | u32 sclk, mclk; |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 158 | bool misc_after = false; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 159 | |
| 160 | if ((rdev->pm.requested_clock_mode_index == rdev->pm.current_clock_mode_index) && |
| 161 | (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index)) |
| 162 | return; |
| 163 | |
| 164 | if (radeon_gui_idle(rdev)) { |
| 165 | sclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 166 | clock_info[rdev->pm.requested_clock_mode_index].sclk; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 167 | if (sclk > rdev->pm.default_sclk) |
| 168 | sclk = rdev->pm.default_sclk; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 169 | |
Alex Deucher | 27810fb | 2012-10-01 19:25:11 -0400 | [diff] [blame] | 170 | /* starting with BTC, there is one state that is used for both |
| 171 | * 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] | 172 | * mclk and vddci. |
Alex Deucher | 27810fb | 2012-10-01 19:25:11 -0400 | [diff] [blame] | 173 | */ |
| 174 | if ((rdev->pm.pm_method == PM_METHOD_PROFILE) && |
| 175 | (rdev->family >= CHIP_BARTS) && |
| 176 | rdev->pm.active_crtc_count && |
| 177 | ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) || |
| 178 | (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX))) |
| 179 | mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 180 | clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].mclk; |
| 181 | else |
| 182 | mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 183 | clock_info[rdev->pm.requested_clock_mode_index].mclk; |
| 184 | |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 185 | if (mclk > rdev->pm.default_mclk) |
| 186 | mclk = rdev->pm.default_mclk; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 187 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 188 | /* upvolt before raising clocks, downvolt after lowering clocks */ |
| 189 | if (sclk < rdev->pm.current_sclk) |
| 190 | misc_after = true; |
| 191 | |
| 192 | radeon_sync_with_vblank(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 193 | |
| 194 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 195 | if (!radeon_pm_in_vbl(rdev)) |
| 196 | return; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 199 | radeon_pm_prepare(rdev); |
| 200 | |
| 201 | if (!misc_after) |
| 202 | /* voltage, pcie lanes, etc.*/ |
| 203 | radeon_pm_misc(rdev); |
| 204 | |
| 205 | /* set engine clock */ |
| 206 | if (sclk != rdev->pm.current_sclk) { |
| 207 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 208 | radeon_set_engine_clock(rdev, sclk); |
| 209 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 210 | rdev->pm.current_sclk = sclk; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 211 | DRM_DEBUG_DRIVER("Setting: e: %d\n", sclk); |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* set memory clock */ |
Alex Deucher | 798bcf7 | 2012-02-23 17:53:48 -0500 | [diff] [blame] | 215 | if (rdev->asic->pm.set_memory_clock && (mclk != rdev->pm.current_mclk)) { |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 216 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 217 | radeon_set_memory_clock(rdev, mclk); |
| 218 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 219 | rdev->pm.current_mclk = mclk; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 220 | DRM_DEBUG_DRIVER("Setting: m: %d\n", mclk); |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (misc_after) |
| 224 | /* voltage, pcie lanes, etc.*/ |
| 225 | radeon_pm_misc(rdev); |
| 226 | |
| 227 | radeon_pm_finish(rdev); |
| 228 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 229 | rdev->pm.current_power_state_index = rdev->pm.requested_power_state_index; |
| 230 | rdev->pm.current_clock_mode_index = rdev->pm.requested_clock_mode_index; |
| 231 | } else |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 232 | DRM_DEBUG_DRIVER("pm: GUI not idle!!!\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void radeon_pm_set_clocks(struct radeon_device *rdev) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 236 | { |
Jerome Glisse | 5f8f635 | 2012-12-17 11:04:32 -0500 | [diff] [blame] | 237 | int i, r; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 238 | |
Alex Deucher | 4e186b2 | 2010-08-13 10:53:35 -0400 | [diff] [blame] | 239 | /* no need to take locks, etc. if nothing's going to change */ |
| 240 | if ((rdev->pm.requested_clock_mode_index == rdev->pm.current_clock_mode_index) && |
| 241 | (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index)) |
| 242 | return; |
| 243 | |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 244 | mutex_lock(&rdev->ddev->struct_mutex); |
Christian König | db7fce3 | 2012-05-11 14:57:18 +0200 | [diff] [blame] | 245 | down_write(&rdev->pm.mclk_lock); |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 246 | mutex_lock(&rdev->ring_lock); |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 247 | |
Alex Deucher | 95f5a3a | 2012-08-10 13:12:08 -0400 | [diff] [blame] | 248 | /* wait for the rings to drain */ |
| 249 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
| 250 | struct radeon_ring *ring = &rdev->ring[i]; |
Jerome Glisse | 5f8f635 | 2012-12-17 11:04:32 -0500 | [diff] [blame] | 251 | if (!ring->ready) { |
| 252 | continue; |
| 253 | } |
| 254 | r = radeon_fence_wait_empty_locked(rdev, i); |
| 255 | if (r) { |
| 256 | /* needs a GPU reset dont reset here */ |
| 257 | mutex_unlock(&rdev->ring_lock); |
| 258 | up_write(&rdev->pm.mclk_lock); |
| 259 | mutex_unlock(&rdev->ddev->struct_mutex); |
| 260 | return; |
| 261 | } |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 262 | } |
Alex Deucher | 95f5a3a | 2012-08-10 13:12:08 -0400 | [diff] [blame] | 263 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 264 | radeon_unmap_vram_bos(rdev); |
| 265 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 266 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 267 | for (i = 0; i < rdev->num_crtc; i++) { |
| 268 | if (rdev->pm.active_crtcs & (1 << i)) { |
| 269 | rdev->pm.req_vblank |= (1 << i); |
| 270 | drm_vblank_get(rdev->ddev, i); |
| 271 | } |
| 272 | } |
| 273 | } |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 274 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 275 | radeon_set_power_state(rdev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 276 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 277 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 278 | for (i = 0; i < rdev->num_crtc; i++) { |
| 279 | if (rdev->pm.req_vblank & (1 << i)) { |
| 280 | rdev->pm.req_vblank &= ~(1 << i); |
| 281 | drm_vblank_put(rdev->ddev, i); |
| 282 | } |
| 283 | } |
| 284 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 285 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 286 | /* update display watermarks based on new power state */ |
| 287 | radeon_update_bandwidth_info(rdev); |
| 288 | if (rdev->pm.active_crtc_count) |
| 289 | radeon_bandwidth_update(rdev); |
| 290 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 291 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 292 | |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 293 | mutex_unlock(&rdev->ring_lock); |
Christian König | db7fce3 | 2012-05-11 14:57:18 +0200 | [diff] [blame] | 294 | up_write(&rdev->pm.mclk_lock); |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 295 | mutex_unlock(&rdev->ddev->struct_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 298 | static void radeon_pm_print_states(struct radeon_device *rdev) |
| 299 | { |
| 300 | int i, j; |
| 301 | struct radeon_power_state *power_state; |
| 302 | struct radeon_pm_clock_info *clock_info; |
| 303 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 304 | 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] | 305 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
| 306 | power_state = &rdev->pm.power_state[i]; |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 307 | DRM_DEBUG_DRIVER("State %d: %s\n", i, |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 308 | radeon_pm_state_type_name[power_state->type]); |
| 309 | if (i == rdev->pm.default_power_state_index) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 310 | DRM_DEBUG_DRIVER("\tDefault"); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 311 | if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP)) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 312 | 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] | 313 | if (power_state->flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 314 | DRM_DEBUG_DRIVER("\tSingle display only\n"); |
| 315 | 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] | 316 | for (j = 0; j < power_state->num_clock_modes; j++) { |
| 317 | clock_info = &(power_state->clock_info[j]); |
| 318 | if (rdev->flags & RADEON_IS_IGP) |
Alex Deucher | eb2c27a | 2012-10-01 18:28:09 -0400 | [diff] [blame] | 319 | DRM_DEBUG_DRIVER("\t\t%d e: %d\n", |
| 320 | j, |
| 321 | clock_info->sclk * 10); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 322 | else |
Alex Deucher | eb2c27a | 2012-10-01 18:28:09 -0400 | [diff] [blame] | 323 | DRM_DEBUG_DRIVER("\t\t%d e: %d\tm: %d\tv: %d\n", |
| 324 | j, |
| 325 | clock_info->sclk * 10, |
| 326 | clock_info->mclk * 10, |
| 327 | clock_info->voltage.voltage); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 332 | static ssize_t radeon_get_pm_profile(struct device *dev, |
| 333 | struct device_attribute *attr, |
| 334 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 335 | { |
| 336 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 337 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 338 | int cp = rdev->pm.profile; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 339 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 340 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 341 | (cp == PM_PROFILE_AUTO) ? "auto" : |
| 342 | (cp == PM_PROFILE_LOW) ? "low" : |
Daniel J Blueman | 12e27be | 2010-07-28 12:25:58 +0100 | [diff] [blame] | 343 | (cp == PM_PROFILE_MID) ? "mid" : |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 344 | (cp == PM_PROFILE_HIGH) ? "high" : "default"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 345 | } |
| 346 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 347 | static ssize_t radeon_set_pm_profile(struct device *dev, |
| 348 | struct device_attribute *attr, |
| 349 | const char *buf, |
| 350 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 351 | { |
| 352 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 353 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 354 | |
| 355 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 356 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 357 | if (strncmp("default", buf, strlen("default")) == 0) |
| 358 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 359 | else if (strncmp("auto", buf, strlen("auto")) == 0) |
| 360 | rdev->pm.profile = PM_PROFILE_AUTO; |
| 361 | else if (strncmp("low", buf, strlen("low")) == 0) |
| 362 | rdev->pm.profile = PM_PROFILE_LOW; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame] | 363 | else if (strncmp("mid", buf, strlen("mid")) == 0) |
| 364 | rdev->pm.profile = PM_PROFILE_MID; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 365 | else if (strncmp("high", buf, strlen("high")) == 0) |
| 366 | rdev->pm.profile = PM_PROFILE_HIGH; |
| 367 | else { |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 368 | count = -EINVAL; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 369 | goto fail; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 370 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 371 | radeon_pm_update_profile(rdev); |
| 372 | radeon_pm_set_clocks(rdev); |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 373 | } else |
| 374 | count = -EINVAL; |
| 375 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 376 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 377 | mutex_unlock(&rdev->pm.mutex); |
| 378 | |
| 379 | return count; |
| 380 | } |
| 381 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 382 | static ssize_t radeon_get_pm_method(struct device *dev, |
| 383 | struct device_attribute *attr, |
| 384 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 385 | { |
| 386 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 387 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 388 | int pm = rdev->pm.pm_method; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 389 | |
| 390 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 391 | (pm == PM_METHOD_DYNPM) ? "dynpm" : "profile"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 394 | static ssize_t radeon_set_pm_method(struct device *dev, |
| 395 | struct device_attribute *attr, |
| 396 | const char *buf, |
| 397 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 398 | { |
| 399 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 400 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 401 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 402 | |
| 403 | if (strncmp("dynpm", buf, strlen("dynpm")) == 0) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 404 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 405 | rdev->pm.pm_method = PM_METHOD_DYNPM; |
| 406 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 407 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 408 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 409 | } else if (strncmp("profile", buf, strlen("profile")) == 0) { |
| 410 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 411 | /* disable dynpm */ |
| 412 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 413 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 414 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 415 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 416 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 417 | } else { |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 418 | count = -EINVAL; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 419 | goto fail; |
| 420 | } |
| 421 | radeon_pm_compute_clocks(rdev); |
| 422 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 423 | return count; |
| 424 | } |
| 425 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 426 | static DEVICE_ATTR(power_profile, S_IRUGO | S_IWUSR, radeon_get_pm_profile, radeon_set_pm_profile); |
| 427 | static DEVICE_ATTR(power_method, S_IRUGO | S_IWUSR, radeon_get_pm_method, radeon_set_pm_method); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 428 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 429 | static ssize_t radeon_hwmon_show_temp(struct device *dev, |
| 430 | struct device_attribute *attr, |
| 431 | char *buf) |
| 432 | { |
| 433 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 434 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 435 | int temp; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 436 | |
| 437 | switch (rdev->pm.int_thermal_type) { |
| 438 | case THERMAL_TYPE_RV6XX: |
| 439 | temp = rv6xx_get_temp(rdev); |
| 440 | break; |
| 441 | case THERMAL_TYPE_RV770: |
| 442 | temp = rv770_get_temp(rdev); |
| 443 | break; |
| 444 | case THERMAL_TYPE_EVERGREEN: |
Alex Deucher | 4fddba1 | 2011-01-06 21:19:22 -0500 | [diff] [blame] | 445 | case THERMAL_TYPE_NI: |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 446 | temp = evergreen_get_temp(rdev); |
| 447 | break; |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 448 | case THERMAL_TYPE_SUMO: |
| 449 | temp = sumo_get_temp(rdev); |
| 450 | break; |
Alex Deucher | 1bd47d2 | 2012-03-20 17:18:10 -0400 | [diff] [blame] | 451 | case THERMAL_TYPE_SI: |
| 452 | temp = si_get_temp(rdev); |
| 453 | break; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 454 | default: |
| 455 | temp = 0; |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 460 | } |
| 461 | |
| 462 | static ssize_t radeon_hwmon_show_name(struct device *dev, |
| 463 | struct device_attribute *attr, |
| 464 | char *buf) |
| 465 | { |
| 466 | return sprintf(buf, "radeon\n"); |
| 467 | } |
| 468 | |
| 469 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, radeon_hwmon_show_temp, NULL, 0); |
| 470 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, radeon_hwmon_show_name, NULL, 0); |
| 471 | |
| 472 | static struct attribute *hwmon_attributes[] = { |
| 473 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 474 | &sensor_dev_attr_name.dev_attr.attr, |
| 475 | NULL |
| 476 | }; |
| 477 | |
| 478 | static const struct attribute_group hwmon_attrgroup = { |
| 479 | .attrs = hwmon_attributes, |
| 480 | }; |
| 481 | |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 482 | static int radeon_hwmon_init(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 483 | { |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 484 | int err = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 485 | |
| 486 | rdev->pm.int_hwmon_dev = NULL; |
| 487 | |
| 488 | switch (rdev->pm.int_thermal_type) { |
| 489 | case THERMAL_TYPE_RV6XX: |
| 490 | case THERMAL_TYPE_RV770: |
| 491 | case THERMAL_TYPE_EVERGREEN: |
Alex Deucher | 457558e | 2011-05-25 17:49:54 -0400 | [diff] [blame] | 492 | case THERMAL_TYPE_NI: |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 493 | case THERMAL_TYPE_SUMO: |
Alex Deucher | 1bd47d2 | 2012-03-20 17:18:10 -0400 | [diff] [blame] | 494 | case THERMAL_TYPE_SI: |
Alex Deucher | 5d7486c | 2012-03-20 17:18:29 -0400 | [diff] [blame] | 495 | /* No support for TN yet */ |
| 496 | if (rdev->family == CHIP_ARUBA) |
| 497 | return err; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 498 | rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 499 | if (IS_ERR(rdev->pm.int_hwmon_dev)) { |
| 500 | err = PTR_ERR(rdev->pm.int_hwmon_dev); |
| 501 | dev_err(rdev->dev, |
| 502 | "Unable to register hwmon device: %d\n", err); |
| 503 | break; |
| 504 | } |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 505 | dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev); |
| 506 | err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj, |
| 507 | &hwmon_attrgroup); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 508 | if (err) { |
| 509 | dev_err(rdev->dev, |
| 510 | "Unable to create hwmon sysfs file: %d\n", err); |
| 511 | hwmon_device_unregister(rdev->dev); |
| 512 | } |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 513 | break; |
| 514 | default: |
| 515 | break; |
| 516 | } |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 517 | |
| 518 | return err; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static void radeon_hwmon_fini(struct radeon_device *rdev) |
| 522 | { |
| 523 | if (rdev->pm.int_hwmon_dev) { |
| 524 | sysfs_remove_group(&rdev->pm.int_hwmon_dev->kobj, &hwmon_attrgroup); |
| 525 | hwmon_device_unregister(rdev->pm.int_hwmon_dev); |
| 526 | } |
| 527 | } |
| 528 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 529 | void radeon_pm_suspend(struct radeon_device *rdev) |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 530 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 531 | mutex_lock(&rdev->pm.mutex); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 532 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 533 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) |
| 534 | rdev->pm.dynpm_state = DYNPM_STATE_SUSPENDED; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 535 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 536 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 537 | |
| 538 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 539 | } |
| 540 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 541 | void radeon_pm_resume(struct radeon_device *rdev) |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 542 | { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 543 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 544 | if ((rdev->family >= CHIP_BARTS) && |
| 545 | (rdev->family <= CHIP_CAYMAN) && |
| 546 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 547 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 548 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 549 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 550 | if (rdev->pm.default_vddci) |
| 551 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 552 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 553 | if (rdev->pm.default_sclk) |
| 554 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 555 | if (rdev->pm.default_mclk) |
| 556 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 557 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 558 | /* asic init will reset the default power state */ |
| 559 | mutex_lock(&rdev->pm.mutex); |
| 560 | rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; |
| 561 | rdev->pm.current_clock_mode_index = 0; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 562 | rdev->pm.current_sclk = rdev->pm.default_sclk; |
| 563 | rdev->pm.current_mclk = rdev->pm.default_mclk; |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 564 | rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 565 | rdev->pm.current_vddci = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.vddci; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 566 | if (rdev->pm.pm_method == PM_METHOD_DYNPM |
| 567 | && rdev->pm.dynpm_state == DYNPM_STATE_SUSPENDED) { |
| 568 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 569 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 570 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 571 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 572 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 573 | radeon_pm_compute_clocks(rdev); |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 576 | int radeon_pm_init(struct radeon_device *rdev) |
| 577 | { |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 578 | int ret; |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 579 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 580 | /* default to profile method */ |
| 581 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 582 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 583 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 584 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 585 | rdev->pm.dynpm_can_upclock = true; |
| 586 | rdev->pm.dynpm_can_downclock = true; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 587 | rdev->pm.default_sclk = rdev->clock.default_sclk; |
| 588 | rdev->pm.default_mclk = rdev->clock.default_mclk; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 589 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 590 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 591 | rdev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 592 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 593 | if (rdev->bios) { |
| 594 | if (rdev->is_atom_bios) |
| 595 | radeon_atombios_get_power_modes(rdev); |
| 596 | else |
| 597 | radeon_combios_get_power_modes(rdev); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 598 | radeon_pm_print_states(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 599 | radeon_pm_init_profile(rdev); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 600 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 601 | if ((rdev->family >= CHIP_BARTS) && |
| 602 | (rdev->family <= CHIP_CAYMAN) && |
| 603 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 604 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 605 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 606 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4639dd2 | 2011-07-25 18:50:08 -0400 | [diff] [blame] | 607 | if (rdev->pm.default_vddci) |
| 608 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 609 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 610 | if (rdev->pm.default_sclk) |
| 611 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 612 | if (rdev->pm.default_mclk) |
| 613 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 614 | } |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 615 | } |
| 616 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 617 | /* set up the internal thermal sensor if applicable */ |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 618 | ret = radeon_hwmon_init(rdev); |
| 619 | if (ret) |
| 620 | return ret; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 621 | |
| 622 | INIT_DELAYED_WORK(&rdev->pm.dynpm_idle_work, radeon_dynpm_idle_work_handler); |
| 623 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 624 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 625 | /* where's the best place to put these? */ |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 626 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 627 | if (ret) |
| 628 | DRM_ERROR("failed to create device file for power profile\n"); |
| 629 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 630 | if (ret) |
| 631 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 632 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 633 | if (radeon_debugfs_pm_init(rdev)) { |
| 634 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
| 635 | } |
| 636 | |
| 637 | DRM_INFO("radeon: power management initialized\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 643 | void radeon_pm_fini(struct radeon_device *rdev) |
| 644 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 645 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 646 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 647 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 648 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 649 | radeon_pm_update_profile(rdev); |
| 650 | radeon_pm_set_clocks(rdev); |
| 651 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 652 | /* reset default clocks */ |
| 653 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 654 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 655 | radeon_pm_set_clocks(rdev); |
| 656 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 657 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 658 | |
| 659 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 660 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 661 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 662 | device_remove_file(rdev->dev, &dev_attr_power_method); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 663 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 664 | |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 665 | if (rdev->pm.power_state) |
| 666 | kfree(rdev->pm.power_state); |
| 667 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 668 | radeon_hwmon_fini(rdev); |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 669 | } |
| 670 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 671 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 672 | { |
| 673 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 674 | struct drm_crtc *crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 675 | struct radeon_crtc *radeon_crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 676 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 677 | if (rdev->pm.num_power_states < 2) |
| 678 | return; |
| 679 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 680 | mutex_lock(&rdev->pm.mutex); |
| 681 | |
| 682 | rdev->pm.active_crtcs = 0; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 683 | rdev->pm.active_crtc_count = 0; |
| 684 | list_for_each_entry(crtc, |
| 685 | &ddev->mode_config.crtc_list, head) { |
| 686 | radeon_crtc = to_radeon_crtc(crtc); |
| 687 | if (radeon_crtc->enabled) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 688 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 689 | rdev->pm.active_crtc_count++; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 693 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 694 | radeon_pm_update_profile(rdev); |
| 695 | radeon_pm_set_clocks(rdev); |
| 696 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
| 697 | if (rdev->pm.dynpm_state != DYNPM_STATE_DISABLED) { |
| 698 | if (rdev->pm.active_crtc_count > 1) { |
| 699 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
| 700 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 701 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 702 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 703 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 704 | radeon_pm_get_dynpm_state(rdev); |
| 705 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 706 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 707 | DRM_DEBUG_DRIVER("radeon: dynamic power management deactivated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 708 | } |
| 709 | } else if (rdev->pm.active_crtc_count == 1) { |
| 710 | /* TODO: Increase clocks if needed for current mode */ |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 711 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 712 | if (rdev->pm.dynpm_state == DYNPM_STATE_MINIMUM) { |
| 713 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
| 714 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_UPCLOCK; |
| 715 | radeon_pm_get_dynpm_state(rdev); |
| 716 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 717 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 718 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 719 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 720 | } else if (rdev->pm.dynpm_state == DYNPM_STATE_PAUSED) { |
| 721 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 722 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 723 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 724 | DRM_DEBUG_DRIVER("radeon: dynamic power management activated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 725 | } |
| 726 | } else { /* count == 0 */ |
| 727 | if (rdev->pm.dynpm_state != DYNPM_STATE_MINIMUM) { |
| 728 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 729 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 730 | rdev->pm.dynpm_state = DYNPM_STATE_MINIMUM; |
| 731 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_MINIMUM; |
| 732 | radeon_pm_get_dynpm_state(rdev); |
| 733 | radeon_pm_set_clocks(rdev); |
| 734 | } |
| 735 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 736 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 737 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 738 | |
| 739 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 742 | static bool radeon_pm_in_vbl(struct radeon_device *rdev) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 743 | { |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 744 | int crtc, vpos, hpos, vbl_status; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 745 | bool in_vbl = true; |
| 746 | |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 747 | /* Iterate over all active crtc's. All crtc's must be in vblank, |
| 748 | * otherwise return in_vbl == false. |
| 749 | */ |
| 750 | for (crtc = 0; (crtc < rdev->num_crtc) && in_vbl; crtc++) { |
| 751 | if (rdev->pm.active_crtcs & (1 << crtc)) { |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 752 | vbl_status = radeon_get_crtc_scanoutpos(rdev->ddev, crtc, &vpos, &hpos); |
| 753 | if ((vbl_status & DRM_SCANOUTPOS_VALID) && |
| 754 | !(vbl_status & DRM_SCANOUTPOS_INVBL)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 755 | in_vbl = false; |
| 756 | } |
| 757 | } |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 758 | |
| 759 | return in_vbl; |
| 760 | } |
| 761 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 762 | 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] | 763 | { |
| 764 | u32 stat_crtc = 0; |
| 765 | bool in_vbl = radeon_pm_in_vbl(rdev); |
| 766 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 767 | if (in_vbl == false) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 768 | 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] | 769 | finish ? "exit" : "entry"); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 770 | return in_vbl; |
| 771 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 772 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 773 | static void radeon_dynpm_idle_work_handler(struct work_struct *work) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 774 | { |
| 775 | struct radeon_device *rdev; |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 776 | int resched; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 777 | rdev = container_of(work, struct radeon_device, |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 778 | pm.dynpm_idle_work.work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 779 | |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 780 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 781 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 782 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 783 | int not_processed = 0; |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 784 | int i; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 785 | |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 786 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
Alex Deucher | 0ec0612 | 2012-06-14 15:54:57 -0400 | [diff] [blame] | 787 | struct radeon_ring *ring = &rdev->ring[i]; |
| 788 | |
| 789 | if (ring->ready) { |
| 790 | not_processed += radeon_fence_count_emitted(rdev, i); |
| 791 | if (not_processed >= 3) |
| 792 | break; |
| 793 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 794 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 795 | |
| 796 | if (not_processed >= 3) { /* should upclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 797 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_DOWNCLOCK) { |
| 798 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 799 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 800 | rdev->pm.dynpm_can_upclock) { |
| 801 | rdev->pm.dynpm_planned_action = |
| 802 | DYNPM_ACTION_UPCLOCK; |
| 803 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 804 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 805 | } |
| 806 | } else if (not_processed == 0) { /* should downclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 807 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_UPCLOCK) { |
| 808 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 809 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 810 | rdev->pm.dynpm_can_downclock) { |
| 811 | rdev->pm.dynpm_planned_action = |
| 812 | DYNPM_ACTION_DOWNCLOCK; |
| 813 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 814 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 815 | } |
| 816 | } |
| 817 | |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 818 | /* Note, radeon_pm_set_clocks is called with static_switch set |
| 819 | * to false since we want to wait for vbl to avoid flicker. |
| 820 | */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 821 | if (rdev->pm.dynpm_planned_action != DYNPM_ACTION_NONE && |
| 822 | jiffies > rdev->pm.dynpm_action_timeout) { |
| 823 | radeon_pm_get_dynpm_state(rdev); |
| 824 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 825 | } |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 826 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 827 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 828 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 829 | } |
| 830 | mutex_unlock(&rdev->pm.mutex); |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 831 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 834 | /* |
| 835 | * Debugfs info |
| 836 | */ |
| 837 | #if defined(CONFIG_DEBUG_FS) |
| 838 | |
| 839 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 840 | { |
| 841 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 842 | struct drm_device *dev = node->minor->dev; |
| 843 | struct radeon_device *rdev = dev->dev_private; |
| 844 | |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 845 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->pm.default_sclk); |
Alex Deucher | bf05d99 | 2013-03-18 17:12:50 -0400 | [diff] [blame] | 846 | /* radeon_get_engine_clock is not reliable on APUs so just print the current clock */ |
| 847 | if ((rdev->family >= CHIP_PALM) && (rdev->flags & RADEON_IS_IGP)) |
| 848 | seq_printf(m, "current engine clock: %u0 kHz\n", rdev->pm.current_sclk); |
| 849 | else |
| 850 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 851 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->pm.default_mclk); |
Alex Deucher | 798bcf7 | 2012-02-23 17:53:48 -0500 | [diff] [blame] | 852 | if (rdev->asic->pm.get_memory_clock) |
Rafał Miłecki | 6234077 | 2009-12-15 21:46:58 +0100 | [diff] [blame] | 853 | seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
Rafał Miłecki | 0fcbe94 | 2010-06-07 18:25:21 -0400 | [diff] [blame] | 854 | if (rdev->pm.current_vddc) |
| 855 | seq_printf(m, "voltage: %u mV\n", rdev->pm.current_vddc); |
Alex Deucher | 798bcf7 | 2012-02-23 17:53:48 -0500 | [diff] [blame] | 856 | if (rdev->asic->pm.get_pcie_lanes) |
Rafał Miłecki | aa5120d | 2010-02-18 20:24:28 +0000 | [diff] [blame] | 857 | seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev)); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | static struct drm_info_list radeon_pm_info_list[] = { |
| 863 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 864 | }; |
| 865 | #endif |
| 866 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 867 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 868 | { |
| 869 | #if defined(CONFIG_DEBUG_FS) |
| 870 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 871 | #else |
| 872 | return 0; |
| 873 | #endif |
| 874 | } |