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 | 2aba631c0 | 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 | 2aba631c0 | 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 | 2aba631c0 | 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 | 2aba631c0 | 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 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 336 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 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 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 352 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 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 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 386 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 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 | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 391 | (pm == PM_METHOD_DYNPM) ? "dynpm" : |
| 392 | (pm == PM_METHOD_PROFILE) ? "profile" : "dpm"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 395 | static ssize_t radeon_set_pm_method(struct device *dev, |
| 396 | struct device_attribute *attr, |
| 397 | const char *buf, |
| 398 | size_t count) |
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 | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 402 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 403 | /* we don't support the legacy modes with dpm */ |
| 404 | if (rdev->pm.pm_method == PM_METHOD_DPM) { |
| 405 | count = -EINVAL; |
| 406 | goto fail; |
| 407 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 408 | |
| 409 | if (strncmp("dynpm", buf, strlen("dynpm")) == 0) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 410 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 411 | rdev->pm.pm_method = PM_METHOD_DYNPM; |
| 412 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 413 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 414 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 415 | } else if (strncmp("profile", buf, strlen("profile")) == 0) { |
| 416 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 417 | /* disable dynpm */ |
| 418 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 419 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 420 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 421 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 422 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 423 | } else { |
Thomas Renninger | 1783e4b | 2011-03-23 15:14:09 +0000 | [diff] [blame] | 424 | count = -EINVAL; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 425 | goto fail; |
| 426 | } |
| 427 | radeon_pm_compute_clocks(rdev); |
| 428 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 429 | return count; |
| 430 | } |
| 431 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 432 | static ssize_t radeon_get_dpm_state(struct device *dev, |
| 433 | struct device_attribute *attr, |
| 434 | char *buf) |
| 435 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 436 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 437 | struct radeon_device *rdev = ddev->dev_private; |
| 438 | enum radeon_pm_state_type pm = rdev->pm.dpm.user_state; |
| 439 | |
| 440 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 441 | (pm == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 442 | (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance"); |
| 443 | } |
| 444 | |
| 445 | static ssize_t radeon_set_dpm_state(struct device *dev, |
| 446 | struct device_attribute *attr, |
| 447 | const char *buf, |
| 448 | size_t count) |
| 449 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 450 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 451 | struct radeon_device *rdev = ddev->dev_private; |
| 452 | |
| 453 | mutex_lock(&rdev->pm.mutex); |
| 454 | if (strncmp("battery", buf, strlen("battery")) == 0) |
| 455 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BATTERY; |
| 456 | else if (strncmp("balanced", buf, strlen("balanced")) == 0) |
| 457 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; |
| 458 | else if (strncmp("performance", buf, strlen("performance")) == 0) |
| 459 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_PERFORMANCE; |
| 460 | else { |
| 461 | mutex_unlock(&rdev->pm.mutex); |
| 462 | count = -EINVAL; |
| 463 | goto fail; |
| 464 | } |
| 465 | mutex_unlock(&rdev->pm.mutex); |
| 466 | radeon_pm_compute_clocks(rdev); |
| 467 | fail: |
| 468 | return count; |
| 469 | } |
| 470 | |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 471 | static ssize_t radeon_get_dpm_forced_performance_level(struct device *dev, |
| 472 | struct device_attribute *attr, |
| 473 | char *buf) |
| 474 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 475 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 476 | struct radeon_device *rdev = ddev->dev_private; |
| 477 | enum radeon_dpm_forced_level level = rdev->pm.dpm.forced_level; |
| 478 | |
| 479 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 480 | (level == RADEON_DPM_FORCED_LEVEL_AUTO) ? "auto" : |
| 481 | (level == RADEON_DPM_FORCED_LEVEL_LOW) ? "low" : "high"); |
| 482 | } |
| 483 | |
| 484 | static ssize_t radeon_set_dpm_forced_performance_level(struct device *dev, |
| 485 | struct device_attribute *attr, |
| 486 | const char *buf, |
| 487 | size_t count) |
| 488 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 489 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 490 | struct radeon_device *rdev = ddev->dev_private; |
| 491 | enum radeon_dpm_forced_level level; |
| 492 | int ret = 0; |
| 493 | |
| 494 | mutex_lock(&rdev->pm.mutex); |
| 495 | if (strncmp("low", buf, strlen("low")) == 0) { |
| 496 | level = RADEON_DPM_FORCED_LEVEL_LOW; |
| 497 | } else if (strncmp("high", buf, strlen("high")) == 0) { |
| 498 | level = RADEON_DPM_FORCED_LEVEL_HIGH; |
| 499 | } else if (strncmp("auto", buf, strlen("auto")) == 0) { |
| 500 | level = RADEON_DPM_FORCED_LEVEL_AUTO; |
| 501 | } else { |
| 502 | mutex_unlock(&rdev->pm.mutex); |
| 503 | count = -EINVAL; |
| 504 | goto fail; |
| 505 | } |
| 506 | if (rdev->asic->dpm.force_performance_level) { |
| 507 | ret = radeon_dpm_force_performance_level(rdev, level); |
| 508 | if (ret) |
| 509 | count = -EINVAL; |
| 510 | } |
| 511 | mutex_unlock(&rdev->pm.mutex); |
| 512 | fail: |
| 513 | return count; |
| 514 | } |
| 515 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 516 | static DEVICE_ATTR(power_profile, S_IRUGO | S_IWUSR, radeon_get_pm_profile, radeon_set_pm_profile); |
| 517 | 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] | 518 | 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] | 519 | static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, |
| 520 | radeon_get_dpm_forced_performance_level, |
| 521 | radeon_set_dpm_forced_performance_level); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 522 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 523 | static ssize_t radeon_hwmon_show_temp(struct device *dev, |
| 524 | struct device_attribute *attr, |
| 525 | char *buf) |
| 526 | { |
Jean Delvare | 3e4e212 | 2013-09-10 10:30:44 +0200 | [diff] [blame] | 527 | struct drm_device *ddev = dev_get_drvdata(dev); |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 528 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | 20d391d | 2011-02-01 16:12:34 -0500 | [diff] [blame] | 529 | int temp; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 530 | |
Alex Deucher | 6bd1c38 | 2013-06-21 14:38:03 -0400 | [diff] [blame] | 531 | if (rdev->asic->pm.get_temperature) |
| 532 | temp = radeon_get_temperature(rdev); |
| 533 | else |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 534 | temp = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 535 | |
| 536 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 537 | } |
| 538 | |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame^] | 539 | static ssize_t radeon_hwmon_show_temp_thresh(struct device *dev, |
| 540 | struct device_attribute *attr, |
| 541 | char *buf) |
| 542 | { |
| 543 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 544 | struct radeon_device *rdev = ddev->dev_private; |
| 545 | int hyst = to_sensor_dev_attr(attr)->index; |
| 546 | int temp; |
| 547 | |
| 548 | if (hyst) |
| 549 | temp = rdev->pm.dpm.thermal.min_temp; |
| 550 | else |
| 551 | temp = rdev->pm.dpm.thermal.max_temp; |
| 552 | |
| 553 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 554 | } |
| 555 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 556 | static ssize_t radeon_hwmon_show_name(struct device *dev, |
| 557 | struct device_attribute *attr, |
| 558 | char *buf) |
| 559 | { |
| 560 | return sprintf(buf, "radeon\n"); |
| 561 | } |
| 562 | |
| 563 | 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^] | 564 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 0); |
| 565 | 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] | 566 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, radeon_hwmon_show_name, NULL, 0); |
| 567 | |
| 568 | static struct attribute *hwmon_attributes[] = { |
| 569 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame^] | 570 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 571 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 572 | &sensor_dev_attr_name.dev_attr.attr, |
| 573 | NULL |
| 574 | }; |
| 575 | |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame^] | 576 | static umode_t hwmon_attributes_visible(struct kobject *kobj, |
| 577 | struct attribute *attr, int index) |
| 578 | { |
| 579 | struct device *dev = container_of(kobj, struct device, kobj); |
| 580 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 581 | struct radeon_device *rdev = ddev->dev_private; |
| 582 | |
| 583 | /* Skip limit attributes if DPM is not enabled */ |
| 584 | if (rdev->pm.pm_method != PM_METHOD_DPM && |
| 585 | (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr || |
| 586 | attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr)) |
| 587 | return 0; |
| 588 | |
| 589 | return attr->mode; |
| 590 | } |
| 591 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 592 | static const struct attribute_group hwmon_attrgroup = { |
| 593 | .attrs = hwmon_attributes, |
Jean Delvare | 6ea4e84 | 2013-09-10 10:32:41 +0200 | [diff] [blame^] | 594 | .is_visible = hwmon_attributes_visible, |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 595 | }; |
| 596 | |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 597 | static int radeon_hwmon_init(struct radeon_device *rdev) |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 598 | { |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 599 | int err = 0; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 600 | |
| 601 | rdev->pm.int_hwmon_dev = NULL; |
| 602 | |
| 603 | switch (rdev->pm.int_thermal_type) { |
| 604 | case THERMAL_TYPE_RV6XX: |
| 605 | case THERMAL_TYPE_RV770: |
| 606 | case THERMAL_TYPE_EVERGREEN: |
Alex Deucher | 457558e | 2011-05-25 17:49:54 -0400 | [diff] [blame] | 607 | case THERMAL_TYPE_NI: |
Alex Deucher | e33df25 | 2010-11-22 17:56:32 -0500 | [diff] [blame] | 608 | case THERMAL_TYPE_SUMO: |
Alex Deucher | 1bd47d2 | 2012-03-20 17:18:10 -0400 | [diff] [blame] | 609 | case THERMAL_TYPE_SI: |
Alex Deucher | 286d9cc | 2013-06-21 15:50:47 -0400 | [diff] [blame] | 610 | case THERMAL_TYPE_CI: |
| 611 | case THERMAL_TYPE_KV: |
Alex Deucher | 6bd1c38 | 2013-06-21 14:38:03 -0400 | [diff] [blame] | 612 | if (rdev->asic->pm.get_temperature == NULL) |
Alex Deucher | 5d7486c | 2012-03-20 17:18:29 -0400 | [diff] [blame] | 613 | return err; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 614 | rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 615 | if (IS_ERR(rdev->pm.int_hwmon_dev)) { |
| 616 | err = PTR_ERR(rdev->pm.int_hwmon_dev); |
| 617 | dev_err(rdev->dev, |
| 618 | "Unable to register hwmon device: %d\n", err); |
| 619 | break; |
| 620 | } |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 621 | dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev); |
| 622 | err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj, |
| 623 | &hwmon_attrgroup); |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 624 | if (err) { |
| 625 | dev_err(rdev->dev, |
| 626 | "Unable to create hwmon sysfs file: %d\n", err); |
| 627 | hwmon_device_unregister(rdev->dev); |
| 628 | } |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 629 | break; |
| 630 | default: |
| 631 | break; |
| 632 | } |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 633 | |
| 634 | return err; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static void radeon_hwmon_fini(struct radeon_device *rdev) |
| 638 | { |
| 639 | if (rdev->pm.int_hwmon_dev) { |
| 640 | sysfs_remove_group(&rdev->pm.int_hwmon_dev->kobj, &hwmon_attrgroup); |
| 641 | hwmon_device_unregister(rdev->pm.int_hwmon_dev); |
| 642 | } |
| 643 | } |
| 644 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 645 | static void radeon_dpm_thermal_work_handler(struct work_struct *work) |
| 646 | { |
| 647 | struct radeon_device *rdev = |
| 648 | container_of(work, struct radeon_device, |
| 649 | pm.dpm.thermal.work); |
| 650 | /* switch to the thermal state */ |
| 651 | enum radeon_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL; |
| 652 | |
| 653 | if (!rdev->pm.dpm_enabled) |
| 654 | return; |
| 655 | |
| 656 | if (rdev->asic->pm.get_temperature) { |
| 657 | int temp = radeon_get_temperature(rdev); |
| 658 | |
| 659 | if (temp < rdev->pm.dpm.thermal.min_temp) |
| 660 | /* switch back the user state */ |
| 661 | dpm_state = rdev->pm.dpm.user_state; |
| 662 | } else { |
| 663 | if (rdev->pm.dpm.thermal.high_to_low) |
| 664 | /* switch back the user state */ |
| 665 | dpm_state = rdev->pm.dpm.user_state; |
| 666 | } |
Alex Deucher | 6032034 | 2013-07-24 14:59:48 -0400 | [diff] [blame] | 667 | mutex_lock(&rdev->pm.mutex); |
| 668 | if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL) |
| 669 | rdev->pm.dpm.thermal_active = true; |
| 670 | else |
| 671 | rdev->pm.dpm.thermal_active = false; |
| 672 | rdev->pm.dpm.state = dpm_state; |
| 673 | mutex_unlock(&rdev->pm.mutex); |
| 674 | |
| 675 | radeon_pm_compute_clocks(rdev); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static struct radeon_ps *radeon_dpm_pick_power_state(struct radeon_device *rdev, |
| 679 | enum radeon_pm_state_type dpm_state) |
| 680 | { |
| 681 | int i; |
| 682 | struct radeon_ps *ps; |
| 683 | u32 ui_class; |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 684 | bool single_display = (rdev->pm.dpm.new_active_crtc_count < 2) ? |
| 685 | true : false; |
| 686 | |
| 687 | /* check if the vblank period is too short to adjust the mclk */ |
| 688 | if (single_display && rdev->asic->dpm.vblank_too_short) { |
| 689 | if (radeon_dpm_vblank_too_short(rdev)) |
| 690 | single_display = false; |
| 691 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 692 | |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 693 | /* certain older asics have a separare 3D performance state, |
| 694 | * so try that first if the user selected performance |
| 695 | */ |
| 696 | if (dpm_state == POWER_STATE_TYPE_PERFORMANCE) |
| 697 | dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 698 | /* balanced states don't exist at the moment */ |
| 699 | if (dpm_state == POWER_STATE_TYPE_BALANCED) |
| 700 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 701 | |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 702 | restart_search: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 703 | /* Pick the best power state based on current conditions */ |
| 704 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 705 | ps = &rdev->pm.dpm.ps[i]; |
| 706 | ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK; |
| 707 | switch (dpm_state) { |
| 708 | /* user states */ |
| 709 | case POWER_STATE_TYPE_BATTERY: |
| 710 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) { |
| 711 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 712 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 713 | return ps; |
| 714 | } else |
| 715 | return ps; |
| 716 | } |
| 717 | break; |
| 718 | case POWER_STATE_TYPE_BALANCED: |
| 719 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) { |
| 720 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 721 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 722 | return ps; |
| 723 | } else |
| 724 | return ps; |
| 725 | } |
| 726 | break; |
| 727 | case POWER_STATE_TYPE_PERFORMANCE: |
| 728 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) { |
| 729 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
Alex Deucher | 4878306 | 2013-07-08 11:35:06 -0400 | [diff] [blame] | 730 | if (single_display) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 731 | return ps; |
| 732 | } else |
| 733 | return ps; |
| 734 | } |
| 735 | break; |
| 736 | /* internal states */ |
| 737 | case POWER_STATE_TYPE_INTERNAL_UVD: |
Alex Deucher | d4d3278 | 2013-06-11 17:55:39 -0400 | [diff] [blame] | 738 | if (rdev->pm.dpm.uvd_ps) |
| 739 | return rdev->pm.dpm.uvd_ps; |
| 740 | else |
| 741 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 742 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 743 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) |
| 744 | return ps; |
| 745 | break; |
| 746 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 747 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE) |
| 748 | return ps; |
| 749 | break; |
| 750 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 751 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE) |
| 752 | return ps; |
| 753 | break; |
| 754 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 755 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC) |
| 756 | return ps; |
| 757 | break; |
| 758 | case POWER_STATE_TYPE_INTERNAL_BOOT: |
| 759 | return rdev->pm.dpm.boot_ps; |
| 760 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 761 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL) |
| 762 | return ps; |
| 763 | break; |
| 764 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 765 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) |
| 766 | return ps; |
| 767 | break; |
| 768 | case POWER_STATE_TYPE_INTERNAL_ULV: |
| 769 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) |
| 770 | return ps; |
| 771 | break; |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 772 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 773 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE) |
| 774 | return ps; |
| 775 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | /* use a fallback state if we didn't match */ |
| 781 | switch (dpm_state) { |
| 782 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 783 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 784 | goto restart_search; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 785 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 786 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 787 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
Alex Deucher | d4d3278 | 2013-06-11 17:55:39 -0400 | [diff] [blame] | 788 | if (rdev->pm.dpm.uvd_ps) { |
| 789 | return rdev->pm.dpm.uvd_ps; |
| 790 | } else { |
| 791 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 792 | goto restart_search; |
| 793 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 794 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 795 | dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI; |
| 796 | goto restart_search; |
| 797 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 798 | dpm_state = POWER_STATE_TYPE_BATTERY; |
| 799 | goto restart_search; |
| 800 | case POWER_STATE_TYPE_BATTERY: |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 801 | case POWER_STATE_TYPE_BALANCED: |
| 802 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 803 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 804 | goto restart_search; |
| 805 | default: |
| 806 | break; |
| 807 | } |
| 808 | |
| 809 | return NULL; |
| 810 | } |
| 811 | |
| 812 | static void radeon_dpm_change_power_state_locked(struct radeon_device *rdev) |
| 813 | { |
| 814 | int i; |
| 815 | struct radeon_ps *ps; |
| 816 | enum radeon_pm_state_type dpm_state; |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 817 | int ret; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 818 | |
| 819 | /* if dpm init failed */ |
| 820 | if (!rdev->pm.dpm_enabled) |
| 821 | return; |
| 822 | |
| 823 | if (rdev->pm.dpm.user_state != rdev->pm.dpm.state) { |
| 824 | /* add other state override checks here */ |
Alex Deucher | 8a22755 | 2013-06-21 15:12:57 -0400 | [diff] [blame] | 825 | if ((!rdev->pm.dpm.thermal_active) && |
| 826 | (!rdev->pm.dpm.uvd_active)) |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 827 | rdev->pm.dpm.state = rdev->pm.dpm.user_state; |
| 828 | } |
| 829 | dpm_state = rdev->pm.dpm.state; |
| 830 | |
| 831 | ps = radeon_dpm_pick_power_state(rdev, dpm_state); |
| 832 | if (ps) |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 833 | rdev->pm.dpm.requested_ps = ps; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 834 | else |
| 835 | return; |
| 836 | |
Alex Deucher | d22b7e4 | 2012-11-29 19:27:56 -0500 | [diff] [blame] | 837 | /* no need to reprogram if nothing changed unless we are on BTC+ */ |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 838 | if (rdev->pm.dpm.current_ps == rdev->pm.dpm.requested_ps) { |
Alex Deucher | d22b7e4 | 2012-11-29 19:27:56 -0500 | [diff] [blame] | 839 | if ((rdev->family < CHIP_BARTS) || (rdev->flags & RADEON_IS_IGP)) { |
| 840 | /* for pre-BTC and APUs if the num crtcs changed but state is the same, |
| 841 | * all we need to do is update the display configuration. |
| 842 | */ |
| 843 | if (rdev->pm.dpm.new_active_crtcs != rdev->pm.dpm.current_active_crtcs) { |
| 844 | /* update display watermarks based on new power state */ |
| 845 | radeon_bandwidth_update(rdev); |
| 846 | /* update displays */ |
| 847 | radeon_dpm_display_configuration_changed(rdev); |
| 848 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 849 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 850 | } |
| 851 | return; |
| 852 | } else { |
| 853 | /* for BTC+ if the num crtcs hasn't changed and state is the same, |
| 854 | * nothing to do, if the num crtcs is > 1 and state is the same, |
| 855 | * update display configuration. |
| 856 | */ |
| 857 | if (rdev->pm.dpm.new_active_crtcs == |
| 858 | rdev->pm.dpm.current_active_crtcs) { |
| 859 | return; |
| 860 | } else { |
| 861 | if ((rdev->pm.dpm.current_active_crtc_count > 1) && |
| 862 | (rdev->pm.dpm.new_active_crtc_count > 1)) { |
| 863 | /* update display watermarks based on new power state */ |
| 864 | radeon_bandwidth_update(rdev); |
| 865 | /* update displays */ |
| 866 | radeon_dpm_display_configuration_changed(rdev); |
| 867 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 868 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 869 | return; |
| 870 | } |
| 871 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 872 | } |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | printk("switching from power state:\n"); |
| 876 | radeon_dpm_print_power_state(rdev, rdev->pm.dpm.current_ps); |
| 877 | printk("switching to power state:\n"); |
| 878 | radeon_dpm_print_power_state(rdev, rdev->pm.dpm.requested_ps); |
| 879 | |
| 880 | mutex_lock(&rdev->ddev->struct_mutex); |
| 881 | down_write(&rdev->pm.mclk_lock); |
| 882 | mutex_lock(&rdev->ring_lock); |
| 883 | |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 884 | ret = radeon_dpm_pre_set_power_state(rdev); |
| 885 | if (ret) |
| 886 | goto done; |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 887 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 888 | /* update display watermarks based on new power state */ |
| 889 | radeon_bandwidth_update(rdev); |
| 890 | /* update displays */ |
| 891 | radeon_dpm_display_configuration_changed(rdev); |
| 892 | |
| 893 | rdev->pm.dpm.current_active_crtcs = rdev->pm.dpm.new_active_crtcs; |
| 894 | rdev->pm.dpm.current_active_crtc_count = rdev->pm.dpm.new_active_crtc_count; |
| 895 | |
| 896 | /* wait for the rings to drain */ |
| 897 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
| 898 | struct radeon_ring *ring = &rdev->ring[i]; |
| 899 | if (ring->ready) |
| 900 | radeon_fence_wait_empty_locked(rdev, i); |
| 901 | } |
| 902 | |
| 903 | /* program the new power state */ |
| 904 | radeon_dpm_set_power_state(rdev); |
| 905 | |
| 906 | /* update current power state */ |
| 907 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps; |
| 908 | |
Alex Deucher | 89c9bc5 | 2013-01-16 14:40:26 -0500 | [diff] [blame] | 909 | radeon_dpm_post_set_power_state(rdev); |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 910 | |
Alex Deucher | 6032034 | 2013-07-24 14:59:48 -0400 | [diff] [blame] | 911 | /* force low perf level for thermal */ |
| 912 | if (rdev->pm.dpm.thermal_active && |
| 913 | rdev->asic->dpm.force_performance_level) { |
| 914 | radeon_dpm_force_performance_level(rdev, RADEON_DPM_FORCED_LEVEL_LOW); |
| 915 | } |
| 916 | |
Alex Deucher | 84dd192 | 2013-01-16 12:52:04 -0500 | [diff] [blame] | 917 | done: |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 918 | mutex_unlock(&rdev->ring_lock); |
| 919 | up_write(&rdev->pm.mclk_lock); |
| 920 | mutex_unlock(&rdev->ddev->struct_mutex); |
| 921 | } |
| 922 | |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 923 | void radeon_dpm_enable_uvd(struct radeon_device *rdev, bool enable) |
| 924 | { |
| 925 | enum radeon_pm_state_type dpm_state; |
| 926 | |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 927 | if (rdev->asic->dpm.powergate_uvd) { |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 928 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 929 | /* enable/disable UVD */ |
| 930 | radeon_dpm_powergate_uvd(rdev, !enable); |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 931 | mutex_unlock(&rdev->pm.mutex); |
| 932 | } else { |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 933 | if (enable) { |
| 934 | mutex_lock(&rdev->pm.mutex); |
| 935 | rdev->pm.dpm.uvd_active = true; |
| 936 | if ((rdev->pm.dpm.sd == 1) && (rdev->pm.dpm.hd == 0)) |
| 937 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_SD; |
| 938 | else if ((rdev->pm.dpm.sd == 2) && (rdev->pm.dpm.hd == 0)) |
| 939 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 940 | else if ((rdev->pm.dpm.sd == 0) && (rdev->pm.dpm.hd == 1)) |
| 941 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 942 | else if ((rdev->pm.dpm.sd == 0) && (rdev->pm.dpm.hd == 2)) |
| 943 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD2; |
| 944 | else |
| 945 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD; |
| 946 | rdev->pm.dpm.state = dpm_state; |
| 947 | mutex_unlock(&rdev->pm.mutex); |
| 948 | } else { |
| 949 | mutex_lock(&rdev->pm.mutex); |
| 950 | rdev->pm.dpm.uvd_active = false; |
| 951 | mutex_unlock(&rdev->pm.mutex); |
| 952 | } |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 953 | |
Alex Deucher | 9e9d976 | 2013-07-31 18:13:23 -0400 | [diff] [blame] | 954 | radeon_pm_compute_clocks(rdev); |
| 955 | } |
Alex Deucher | ce3537d | 2013-07-24 12:12:49 -0400 | [diff] [blame] | 956 | } |
| 957 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 958 | static void radeon_pm_suspend_old(struct radeon_device *rdev) |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 959 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 960 | mutex_lock(&rdev->pm.mutex); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 961 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 962 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) |
| 963 | rdev->pm.dynpm_state = DYNPM_STATE_SUSPENDED; |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 964 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 965 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 966 | |
| 967 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 968 | } |
| 969 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 970 | static void radeon_pm_suspend_dpm(struct radeon_device *rdev) |
| 971 | { |
| 972 | mutex_lock(&rdev->pm.mutex); |
| 973 | /* disable dpm */ |
| 974 | radeon_dpm_disable(rdev); |
| 975 | /* reset the power state */ |
| 976 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
| 977 | rdev->pm.dpm_enabled = false; |
| 978 | mutex_unlock(&rdev->pm.mutex); |
| 979 | } |
| 980 | |
| 981 | void radeon_pm_suspend(struct radeon_device *rdev) |
| 982 | { |
| 983 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 984 | radeon_pm_suspend_dpm(rdev); |
| 985 | else |
| 986 | radeon_pm_suspend_old(rdev); |
| 987 | } |
| 988 | |
| 989 | static void radeon_pm_resume_old(struct radeon_device *rdev) |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 990 | { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 991 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 992 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | c6cf777 | 2013-07-05 13:14:30 -0400 | [diff] [blame] | 993 | (rdev->family <= CHIP_HAINAN) && |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 994 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 995 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 996 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 997 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 998 | if (rdev->pm.default_vddci) |
| 999 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1000 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1001 | if (rdev->pm.default_sclk) |
| 1002 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1003 | if (rdev->pm.default_mclk) |
| 1004 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1005 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1006 | /* asic init will reset the default power state */ |
| 1007 | mutex_lock(&rdev->pm.mutex); |
| 1008 | rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; |
| 1009 | rdev->pm.current_clock_mode_index = 0; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 1010 | rdev->pm.current_sclk = rdev->pm.default_sclk; |
| 1011 | rdev->pm.current_mclk = rdev->pm.default_mclk; |
Alex Deucher | 4d60173 | 2010-06-07 18:15:18 -0400 | [diff] [blame] | 1012 | 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] | 1013 | 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] | 1014 | if (rdev->pm.pm_method == PM_METHOD_DYNPM |
| 1015 | && rdev->pm.dynpm_state == DYNPM_STATE_SUSPENDED) { |
| 1016 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1017 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1018 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1019 | } |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1020 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1021 | radeon_pm_compute_clocks(rdev); |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1024 | static void radeon_pm_resume_dpm(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1025 | { |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 1026 | int ret; |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 1027 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1028 | /* asic init will reset to the boot state */ |
| 1029 | mutex_lock(&rdev->pm.mutex); |
| 1030 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
| 1031 | radeon_dpm_setup_asic(rdev); |
| 1032 | ret = radeon_dpm_enable(rdev); |
| 1033 | mutex_unlock(&rdev->pm.mutex); |
| 1034 | if (ret) { |
| 1035 | DRM_ERROR("radeon: dpm resume failed\n"); |
| 1036 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | c6cf777 | 2013-07-05 13:14:30 -0400 | [diff] [blame] | 1037 | (rdev->family <= CHIP_HAINAN) && |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1038 | rdev->mc_fw) { |
| 1039 | if (rdev->pm.default_vddc) |
| 1040 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1041 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
| 1042 | if (rdev->pm.default_vddci) |
| 1043 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1044 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
| 1045 | if (rdev->pm.default_sclk) |
| 1046 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1047 | if (rdev->pm.default_mclk) |
| 1048 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1049 | } |
| 1050 | } else { |
| 1051 | rdev->pm.dpm_enabled = true; |
| 1052 | radeon_pm_compute_clocks(rdev); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | void radeon_pm_resume(struct radeon_device *rdev) |
| 1057 | { |
| 1058 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1059 | radeon_pm_resume_dpm(rdev); |
| 1060 | else |
| 1061 | radeon_pm_resume_old(rdev); |
| 1062 | } |
| 1063 | |
| 1064 | static int radeon_pm_init_old(struct radeon_device *rdev) |
| 1065 | { |
| 1066 | int ret; |
| 1067 | |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1068 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1069 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 1070 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1071 | rdev->pm.dynpm_can_upclock = true; |
| 1072 | rdev->pm.dynpm_can_downclock = true; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 1073 | rdev->pm.default_sclk = rdev->clock.default_sclk; |
| 1074 | rdev->pm.default_mclk = rdev->clock.default_mclk; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 1075 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 1076 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 1077 | rdev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1078 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1079 | if (rdev->bios) { |
| 1080 | if (rdev->is_atom_bios) |
| 1081 | radeon_atombios_get_power_modes(rdev); |
| 1082 | else |
| 1083 | radeon_combios_get_power_modes(rdev); |
Rafał Miłecki | f712d0c | 2010-06-07 18:29:44 -0400 | [diff] [blame] | 1084 | radeon_pm_print_states(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1085 | radeon_pm_init_profile(rdev); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1086 | /* set up the default clocks if the MC ucode is loaded */ |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1087 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | c6cf777 | 2013-07-05 13:14:30 -0400 | [diff] [blame] | 1088 | (rdev->family <= CHIP_HAINAN) && |
Alex Deucher | 2e3b3b1 | 2012-09-14 10:59:26 -0400 | [diff] [blame] | 1089 | rdev->mc_fw) { |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1090 | if (rdev->pm.default_vddc) |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 1091 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1092 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
Alex Deucher | 4639dd2 | 2011-07-25 18:50:08 -0400 | [diff] [blame] | 1093 | if (rdev->pm.default_vddci) |
| 1094 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1095 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
Alex Deucher | ed18a36 | 2011-01-06 21:19:32 -0500 | [diff] [blame] | 1096 | if (rdev->pm.default_sclk) |
| 1097 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1098 | if (rdev->pm.default_mclk) |
| 1099 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1100 | } |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 1103 | /* set up the internal thermal sensor if applicable */ |
Dan Carpenter | 0d18abe | 2010-08-09 21:59:42 +0200 | [diff] [blame] | 1104 | ret = radeon_hwmon_init(rdev); |
| 1105 | if (ret) |
| 1106 | return ret; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1107 | |
| 1108 | INIT_DELAYED_WORK(&rdev->pm.dynpm_idle_work, radeon_dynpm_idle_work_handler); |
| 1109 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1110 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1111 | /* where's the best place to put these? */ |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 1112 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 1113 | if (ret) |
| 1114 | DRM_ERROR("failed to create device file for power profile\n"); |
| 1115 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 1116 | if (ret) |
| 1117 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1118 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1119 | if (radeon_debugfs_pm_init(rdev)) { |
| 1120 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
| 1121 | } |
| 1122 | |
| 1123 | DRM_INFO("radeon: power management initialized\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1129 | static void radeon_dpm_print_power_states(struct radeon_device *rdev) |
| 1130 | { |
| 1131 | int i; |
| 1132 | |
| 1133 | for (i = 0; i < rdev->pm.dpm.num_ps; i++) { |
| 1134 | printk("== power state %d ==\n", i); |
| 1135 | radeon_dpm_print_power_state(rdev, &rdev->pm.dpm.ps[i]); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static int radeon_pm_init_dpm(struct radeon_device *rdev) |
| 1140 | { |
| 1141 | int ret; |
| 1142 | |
| 1143 | /* default to performance state */ |
Alex Deucher | edcaa5b | 2013-07-05 11:48:31 -0400 | [diff] [blame] | 1144 | rdev->pm.dpm.state = POWER_STATE_TYPE_BALANCED; |
| 1145 | rdev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1146 | rdev->pm.default_sclk = rdev->clock.default_sclk; |
| 1147 | rdev->pm.default_mclk = rdev->clock.default_mclk; |
| 1148 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 1149 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
| 1150 | rdev->pm.int_thermal_type = THERMAL_TYPE_NONE; |
| 1151 | |
| 1152 | if (rdev->bios && rdev->is_atom_bios) |
| 1153 | radeon_atombios_get_power_modes(rdev); |
| 1154 | else |
| 1155 | return -EINVAL; |
| 1156 | |
| 1157 | /* set up the internal thermal sensor if applicable */ |
| 1158 | ret = radeon_hwmon_init(rdev); |
| 1159 | if (ret) |
| 1160 | return ret; |
| 1161 | |
| 1162 | INIT_WORK(&rdev->pm.dpm.thermal.work, radeon_dpm_thermal_work_handler); |
| 1163 | mutex_lock(&rdev->pm.mutex); |
| 1164 | radeon_dpm_init(rdev); |
| 1165 | rdev->pm.dpm.current_ps = rdev->pm.dpm.requested_ps = rdev->pm.dpm.boot_ps; |
| 1166 | radeon_dpm_print_power_states(rdev); |
| 1167 | radeon_dpm_setup_asic(rdev); |
| 1168 | ret = radeon_dpm_enable(rdev); |
| 1169 | mutex_unlock(&rdev->pm.mutex); |
| 1170 | if (ret) { |
| 1171 | rdev->pm.dpm_enabled = false; |
| 1172 | if ((rdev->family >= CHIP_BARTS) && |
Alex Deucher | c6cf777 | 2013-07-05 13:14:30 -0400 | [diff] [blame] | 1173 | (rdev->family <= CHIP_HAINAN) && |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1174 | rdev->mc_fw) { |
| 1175 | if (rdev->pm.default_vddc) |
| 1176 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, |
| 1177 | SET_VOLTAGE_TYPE_ASIC_VDDC); |
| 1178 | if (rdev->pm.default_vddci) |
| 1179 | radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, |
| 1180 | SET_VOLTAGE_TYPE_ASIC_VDDCI); |
| 1181 | if (rdev->pm.default_sclk) |
| 1182 | radeon_set_engine_clock(rdev, rdev->pm.default_sclk); |
| 1183 | if (rdev->pm.default_mclk) |
| 1184 | radeon_set_memory_clock(rdev, rdev->pm.default_mclk); |
| 1185 | } |
| 1186 | DRM_ERROR("radeon: dpm initialization failed\n"); |
| 1187 | return ret; |
| 1188 | } |
| 1189 | rdev->pm.dpm_enabled = true; |
| 1190 | radeon_pm_compute_clocks(rdev); |
| 1191 | |
| 1192 | if (rdev->pm.num_power_states > 1) { |
| 1193 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_state); |
| 1194 | if (ret) |
| 1195 | DRM_ERROR("failed to create device file for dpm state\n"); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 1196 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); |
| 1197 | if (ret) |
| 1198 | DRM_ERROR("failed to create device file for dpm state\n"); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1199 | /* XXX: these are noops for dpm but are here for backwards compat */ |
| 1200 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 1201 | if (ret) |
| 1202 | DRM_ERROR("failed to create device file for power profile\n"); |
| 1203 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 1204 | if (ret) |
| 1205 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1206 | |
| 1207 | if (radeon_debugfs_pm_init(rdev)) { |
| 1208 | DRM_ERROR("Failed to register debugfs file for dpm!\n"); |
| 1209 | } |
| 1210 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1211 | DRM_INFO("radeon: dpm initialized\n"); |
| 1212 | } |
| 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | int radeon_pm_init(struct radeon_device *rdev) |
| 1218 | { |
| 1219 | /* enable dpm on rv6xx+ */ |
| 1220 | switch (rdev->family) { |
Alex Deucher | 4a6369e | 2013-04-12 14:04:10 -0400 | [diff] [blame] | 1221 | case CHIP_RV610: |
| 1222 | case CHIP_RV630: |
| 1223 | case CHIP_RV620: |
| 1224 | case CHIP_RV635: |
| 1225 | case CHIP_RV670: |
Alex Deucher | 9d67006 | 2013-04-12 13:59:22 -0400 | [diff] [blame] | 1226 | case CHIP_RS780: |
| 1227 | case CHIP_RS880: |
Alex Deucher | 66229b2 | 2013-06-26 00:11:19 -0400 | [diff] [blame] | 1228 | case CHIP_RV770: |
| 1229 | case CHIP_RV730: |
| 1230 | case CHIP_RV710: |
| 1231 | case CHIP_RV740: |
Alex Deucher | dc50ba7 | 2013-06-26 00:33:35 -0400 | [diff] [blame] | 1232 | case CHIP_CEDAR: |
| 1233 | case CHIP_REDWOOD: |
| 1234 | case CHIP_JUNIPER: |
| 1235 | case CHIP_CYPRESS: |
| 1236 | case CHIP_HEMLOCK: |
Alex Deucher | 80ea2c1 | 2013-04-12 14:56:21 -0400 | [diff] [blame] | 1237 | case CHIP_PALM: |
| 1238 | case CHIP_SUMO: |
| 1239 | case CHIP_SUMO2: |
Alex Deucher | 6596afd | 2013-06-26 00:15:24 -0400 | [diff] [blame] | 1240 | case CHIP_BARTS: |
| 1241 | case CHIP_TURKS: |
| 1242 | case CHIP_CAICOS: |
Alex Deucher | 69e0b57 | 2013-04-12 16:42:42 -0400 | [diff] [blame] | 1243 | case CHIP_CAYMAN: |
Alex Deucher | d70229f | 2013-04-12 16:40:41 -0400 | [diff] [blame] | 1244 | case CHIP_ARUBA: |
Alex Deucher | a9e6141 | 2013-06-25 17:56:16 -0400 | [diff] [blame] | 1245 | case CHIP_TAHITI: |
| 1246 | case CHIP_PITCAIRN: |
| 1247 | case CHIP_VERDE: |
| 1248 | case CHIP_OLAND: |
| 1249 | case CHIP_HAINAN: |
Alex Deucher | cc8dbbb | 2013-08-14 01:03:41 -0400 | [diff] [blame] | 1250 | case CHIP_BONAIRE: |
Alex Deucher | 41a524a | 2013-08-14 01:01:40 -0400 | [diff] [blame] | 1251 | case CHIP_KABINI: |
| 1252 | case CHIP_KAVERI: |
Alex Deucher | 8a53fa2 | 2013-08-07 16:09:08 -0400 | [diff] [blame] | 1253 | /* DPM requires the RLC, RV770+ dGPU requires SMC */ |
Alex Deucher | 761bfb9 | 2013-08-06 13:34:00 -0400 | [diff] [blame] | 1254 | if (!rdev->rlc_fw) |
| 1255 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 8a53fa2 | 2013-08-07 16:09:08 -0400 | [diff] [blame] | 1256 | else if ((rdev->family >= CHIP_RV770) && |
| 1257 | (!(rdev->flags & RADEON_IS_IGP)) && |
| 1258 | (!rdev->smc_fw)) |
| 1259 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | 761bfb9 | 2013-08-06 13:34:00 -0400 | [diff] [blame] | 1260 | else if (radeon_dpm == 1) |
Alex Deucher | 9d67006 | 2013-04-12 13:59:22 -0400 | [diff] [blame] | 1261 | rdev->pm.pm_method = PM_METHOD_DPM; |
| 1262 | else |
| 1263 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1264 | break; |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1265 | default: |
| 1266 | /* default to profile method */ |
| 1267 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 1268 | break; |
| 1269 | } |
| 1270 | |
| 1271 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1272 | return radeon_pm_init_dpm(rdev); |
| 1273 | else |
| 1274 | return radeon_pm_init_old(rdev); |
| 1275 | } |
| 1276 | |
| 1277 | static void radeon_pm_fini_old(struct radeon_device *rdev) |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1278 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1279 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1280 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1281 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 1282 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 1283 | radeon_pm_update_profile(rdev); |
| 1284 | radeon_pm_set_clocks(rdev); |
| 1285 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1286 | /* reset default clocks */ |
| 1287 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 1288 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 1289 | radeon_pm_set_clocks(rdev); |
| 1290 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1291 | mutex_unlock(&rdev->pm.mutex); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1292 | |
| 1293 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 1294 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1295 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 1296 | device_remove_file(rdev->dev, &dev_attr_power_method); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1297 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 1298 | |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 1299 | if (rdev->pm.power_state) |
| 1300 | kfree(rdev->pm.power_state); |
| 1301 | |
Alex Deucher | 21a8122 | 2010-07-02 12:58:16 -0400 | [diff] [blame] | 1302 | radeon_hwmon_fini(rdev); |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1303 | } |
| 1304 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1305 | static void radeon_pm_fini_dpm(struct radeon_device *rdev) |
| 1306 | { |
| 1307 | if (rdev->pm.num_power_states > 1) { |
| 1308 | mutex_lock(&rdev->pm.mutex); |
| 1309 | radeon_dpm_disable(rdev); |
| 1310 | mutex_unlock(&rdev->pm.mutex); |
| 1311 | |
| 1312 | device_remove_file(rdev->dev, &dev_attr_power_dpm_state); |
Alex Deucher | 70d01a5 | 2013-07-02 18:38:02 -0400 | [diff] [blame] | 1313 | device_remove_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1314 | /* XXX backwards compat */ |
| 1315 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 1316 | device_remove_file(rdev->dev, &dev_attr_power_method); |
| 1317 | } |
| 1318 | radeon_dpm_fini(rdev); |
| 1319 | |
| 1320 | if (rdev->pm.power_state) |
| 1321 | kfree(rdev->pm.power_state); |
| 1322 | |
| 1323 | radeon_hwmon_fini(rdev); |
| 1324 | } |
| 1325 | |
| 1326 | void radeon_pm_fini(struct radeon_device *rdev) |
| 1327 | { |
| 1328 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1329 | radeon_pm_fini_dpm(rdev); |
| 1330 | else |
| 1331 | radeon_pm_fini_old(rdev); |
| 1332 | } |
| 1333 | |
| 1334 | static void radeon_pm_compute_clocks_old(struct radeon_device *rdev) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1335 | { |
| 1336 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 1337 | struct drm_crtc *crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1338 | struct radeon_crtc *radeon_crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1339 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1340 | if (rdev->pm.num_power_states < 2) |
| 1341 | return; |
| 1342 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1343 | mutex_lock(&rdev->pm.mutex); |
| 1344 | |
| 1345 | rdev->pm.active_crtcs = 0; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 1346 | rdev->pm.active_crtc_count = 0; |
| 1347 | list_for_each_entry(crtc, |
| 1348 | &ddev->mode_config.crtc_list, head) { |
| 1349 | radeon_crtc = to_radeon_crtc(crtc); |
| 1350 | if (radeon_crtc->enabled) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1351 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 1352 | rdev->pm.active_crtc_count++; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1356 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 1357 | radeon_pm_update_profile(rdev); |
| 1358 | radeon_pm_set_clocks(rdev); |
| 1359 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
| 1360 | if (rdev->pm.dynpm_state != DYNPM_STATE_DISABLED) { |
| 1361 | if (rdev->pm.active_crtc_count > 1) { |
| 1362 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
| 1363 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 1364 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1365 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 1366 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 1367 | radeon_pm_get_dynpm_state(rdev); |
| 1368 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1369 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1370 | DRM_DEBUG_DRIVER("radeon: dynamic power management deactivated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1371 | } |
| 1372 | } else if (rdev->pm.active_crtc_count == 1) { |
| 1373 | /* TODO: Increase clocks if needed for current mode */ |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1374 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1375 | if (rdev->pm.dynpm_state == DYNPM_STATE_MINIMUM) { |
| 1376 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
| 1377 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_UPCLOCK; |
| 1378 | radeon_pm_get_dynpm_state(rdev); |
| 1379 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1380 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1381 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1382 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1383 | } else if (rdev->pm.dynpm_state == DYNPM_STATE_PAUSED) { |
| 1384 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1385 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1386 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1387 | DRM_DEBUG_DRIVER("radeon: dynamic power management activated\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1388 | } |
| 1389 | } else { /* count == 0 */ |
| 1390 | if (rdev->pm.dynpm_state != DYNPM_STATE_MINIMUM) { |
| 1391 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1392 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1393 | rdev->pm.dynpm_state = DYNPM_STATE_MINIMUM; |
| 1394 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_MINIMUM; |
| 1395 | radeon_pm_get_dynpm_state(rdev); |
| 1396 | radeon_pm_set_clocks(rdev); |
| 1397 | } |
| 1398 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1399 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1400 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 1401 | |
| 1402 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1403 | } |
| 1404 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1405 | static void radeon_pm_compute_clocks_dpm(struct radeon_device *rdev) |
| 1406 | { |
| 1407 | struct drm_device *ddev = rdev->ddev; |
| 1408 | struct drm_crtc *crtc; |
| 1409 | struct radeon_crtc *radeon_crtc; |
| 1410 | |
| 1411 | mutex_lock(&rdev->pm.mutex); |
| 1412 | |
Alex Deucher | 5ca302f | 2012-11-30 10:56:57 -0500 | [diff] [blame] | 1413 | /* update active crtc counts */ |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1414 | rdev->pm.dpm.new_active_crtcs = 0; |
| 1415 | rdev->pm.dpm.new_active_crtc_count = 0; |
| 1416 | list_for_each_entry(crtc, |
| 1417 | &ddev->mode_config.crtc_list, head) { |
| 1418 | radeon_crtc = to_radeon_crtc(crtc); |
| 1419 | if (crtc->enabled) { |
| 1420 | rdev->pm.dpm.new_active_crtcs |= (1 << radeon_crtc->crtc_id); |
| 1421 | rdev->pm.dpm.new_active_crtc_count++; |
| 1422 | } |
| 1423 | } |
| 1424 | |
Alex Deucher | 5ca302f | 2012-11-30 10:56:57 -0500 | [diff] [blame] | 1425 | /* update battery/ac status */ |
| 1426 | if (power_supply_is_system_supplied() > 0) |
| 1427 | rdev->pm.dpm.ac_power = true; |
| 1428 | else |
| 1429 | rdev->pm.dpm.ac_power = false; |
| 1430 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1431 | radeon_dpm_change_power_state_locked(rdev); |
| 1432 | |
| 1433 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | 8a22755 | 2013-06-21 15:12:57 -0400 | [diff] [blame] | 1434 | |
Alex Deucher | da321c8 | 2013-04-12 13:55:22 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 1438 | { |
| 1439 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
| 1440 | radeon_pm_compute_clocks_dpm(rdev); |
| 1441 | else |
| 1442 | radeon_pm_compute_clocks_old(rdev); |
| 1443 | } |
| 1444 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1445 | static bool radeon_pm_in_vbl(struct radeon_device *rdev) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1446 | { |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 1447 | int crtc, vpos, hpos, vbl_status; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1448 | bool in_vbl = true; |
| 1449 | |
Mario Kleiner | 75fa0b0 | 2010-10-05 19:57:37 -0400 | [diff] [blame] | 1450 | /* Iterate over all active crtc's. All crtc's must be in vblank, |
| 1451 | * otherwise return in_vbl == false. |
| 1452 | */ |
| 1453 | for (crtc = 0; (crtc < rdev->num_crtc) && in_vbl; crtc++) { |
| 1454 | if (rdev->pm.active_crtcs & (1 << crtc)) { |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1455 | vbl_status = radeon_get_crtc_scanoutpos(rdev->ddev, crtc, &vpos, &hpos); |
| 1456 | if ((vbl_status & DRM_SCANOUTPOS_VALID) && |
| 1457 | !(vbl_status & DRM_SCANOUTPOS_INVBL)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1458 | in_vbl = false; |
| 1459 | } |
| 1460 | } |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 1461 | |
| 1462 | return in_vbl; |
| 1463 | } |
| 1464 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1465 | 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] | 1466 | { |
| 1467 | u32 stat_crtc = 0; |
| 1468 | bool in_vbl = radeon_pm_in_vbl(rdev); |
| 1469 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1470 | if (in_vbl == false) |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1471 | 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] | 1472 | finish ? "exit" : "entry"); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 1473 | return in_vbl; |
| 1474 | } |
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 | static void radeon_dynpm_idle_work_handler(struct work_struct *work) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1477 | { |
| 1478 | struct radeon_device *rdev; |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1479 | int resched; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1480 | rdev = container_of(work, struct radeon_device, |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1481 | pm.dynpm_idle_work.work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1482 | |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1483 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1484 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1485 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1486 | int not_processed = 0; |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 1487 | int i; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1488 | |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 1489 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
Alex Deucher | 0ec0612 | 2012-06-14 15:54:57 -0400 | [diff] [blame] | 1490 | struct radeon_ring *ring = &rdev->ring[i]; |
| 1491 | |
| 1492 | if (ring->ready) { |
| 1493 | not_processed += radeon_fence_count_emitted(rdev, i); |
| 1494 | if (not_processed >= 3) |
| 1495 | break; |
| 1496 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1497 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1498 | |
| 1499 | if (not_processed >= 3) { /* should upclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1500 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_DOWNCLOCK) { |
| 1501 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1502 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 1503 | rdev->pm.dynpm_can_upclock) { |
| 1504 | rdev->pm.dynpm_planned_action = |
| 1505 | DYNPM_ACTION_UPCLOCK; |
| 1506 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1507 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 1508 | } |
| 1509 | } else if (not_processed == 0) { /* should downclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1510 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_UPCLOCK) { |
| 1511 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 1512 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 1513 | rdev->pm.dynpm_can_downclock) { |
| 1514 | rdev->pm.dynpm_planned_action = |
| 1515 | DYNPM_ACTION_DOWNCLOCK; |
| 1516 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1517 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 1518 | } |
| 1519 | } |
| 1520 | |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 1521 | /* Note, radeon_pm_set_clocks is called with static_switch set |
| 1522 | * to false since we want to wait for vbl to avoid flicker. |
| 1523 | */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 1524 | if (rdev->pm.dynpm_planned_action != DYNPM_ACTION_NONE && |
| 1525 | jiffies > rdev->pm.dynpm_action_timeout) { |
| 1526 | radeon_pm_get_dynpm_state(rdev); |
| 1527 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1528 | } |
Rafael J. Wysocki | 3f53eb6 | 2010-06-17 23:02:27 +0000 | [diff] [blame] | 1529 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 1530 | schedule_delayed_work(&rdev->pm.dynpm_idle_work, |
| 1531 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1532 | } |
| 1533 | mutex_unlock(&rdev->pm.mutex); |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 1534 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1535 | } |
| 1536 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1537 | /* |
| 1538 | * Debugfs info |
| 1539 | */ |
| 1540 | #if defined(CONFIG_DEBUG_FS) |
| 1541 | |
| 1542 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 1543 | { |
| 1544 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 1545 | struct drm_device *dev = node->minor->dev; |
| 1546 | struct radeon_device *rdev = dev->dev_private; |
| 1547 | |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1548 | if (rdev->pm.dpm_enabled) { |
| 1549 | mutex_lock(&rdev->pm.mutex); |
| 1550 | if (rdev->asic->dpm.debugfs_print_current_performance_level) |
| 1551 | radeon_dpm_debugfs_print_current_performance_level(rdev, m); |
| 1552 | else |
Alex Deucher | 7137592 | 2013-07-02 09:11:39 -0400 | [diff] [blame] | 1553 | seq_printf(m, "Debugfs support not implemented for this asic\n"); |
Alex Deucher | 1316b79 | 2013-06-28 09:28:39 -0400 | [diff] [blame] | 1554 | mutex_unlock(&rdev->pm.mutex); |
| 1555 | } else { |
| 1556 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->pm.default_sclk); |
| 1557 | /* radeon_get_engine_clock is not reliable on APUs so just print the current clock */ |
| 1558 | if ((rdev->family >= CHIP_PALM) && (rdev->flags & RADEON_IS_IGP)) |
| 1559 | seq_printf(m, "current engine clock: %u0 kHz\n", rdev->pm.current_sclk); |
| 1560 | else |
| 1561 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 1562 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->pm.default_mclk); |
| 1563 | if (rdev->asic->pm.get_memory_clock) |
| 1564 | seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
| 1565 | if (rdev->pm.current_vddc) |
| 1566 | seq_printf(m, "voltage: %u mV\n", rdev->pm.current_vddc); |
| 1567 | if (rdev->asic->pm.get_pcie_lanes) |
| 1568 | seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev)); |
| 1569 | } |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1570 | |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | static struct drm_info_list radeon_pm_info_list[] = { |
| 1575 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 1576 | }; |
| 1577 | #endif |
| 1578 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 1579 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1580 | { |
| 1581 | #if defined(CONFIG_DEBUG_FS) |
| 1582 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 1583 | #else |
| 1584 | return 0; |
| 1585 | #endif |
| 1586 | } |