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