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