blob: 6458d52be4eeecbd48905c82cf89fef658c13172 [file] [log] [blame]
Rafał Miłecki74338742009-11-03 00:53:02 +01001/*
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 Deucher56278a82009-12-28 13:58:44 -050021 * Alex Deucher <alexdeucher@gmail.com>
Rafał Miłecki74338742009-11-03 00:53:02 +010022 */
23#include "drmP.h"
24#include "radeon.h"
Dave Airlief7352612010-02-18 15:58:36 +100025#include "avivod.h"
Rafał Miłecki74338742009-11-03 00:53:02 +010026
Rafał Miłeckic913e232009-12-22 23:02:16 +010027#define RADEON_IDLE_LOOP_MS 100
28#define RADEON_RECLOCK_DELAY_MS 200
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +010029#define RADEON_WAIT_VBLANK_TIMEOUT 200
Rafał Miłeckic913e232009-12-22 23:02:16 +010030
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +010031static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish);
Rafał Miłeckic913e232009-12-22 23:02:16 +010032static void radeon_pm_set_clocks_locked(struct radeon_device *rdev);
33static void radeon_pm_set_clocks(struct radeon_device *rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +010034static void radeon_pm_idle_work_handler(struct work_struct *work);
35static int radeon_debugfs_pm_init(struct radeon_device *rdev);
36
37static const char *pm_state_names[4] = {
38 "PM_STATE_DISABLED",
39 "PM_STATE_MINIMUM",
40 "PM_STATE_PAUSED",
41 "PM_STATE_ACTIVE"
42};
Rafał Miłecki74338742009-11-03 00:53:02 +010043
Alex Deucher0ec0e742009-12-23 13:21:58 -050044static const char *pm_state_types[5] = {
45 "Default",
46 "Powersave",
47 "Battery",
48 "Balanced",
49 "Performance",
50};
51
Alex Deucher56278a82009-12-28 13:58:44 -050052static void radeon_print_power_mode_info(struct radeon_device *rdev)
53{
54 int i, j;
55 bool is_default;
56
57 DRM_INFO("%d Power State(s)\n", rdev->pm.num_power_states);
58 for (i = 0; i < rdev->pm.num_power_states; i++) {
59 if (rdev->pm.default_power_state == &rdev->pm.power_state[i])
60 is_default = true;
61 else
62 is_default = false;
Alex Deucher0ec0e742009-12-23 13:21:58 -050063 DRM_INFO("State %d %s %s\n", i,
64 pm_state_types[rdev->pm.power_state[i].type],
65 is_default ? "(default)" : "");
Alex Deucher56278a82009-12-28 13:58:44 -050066 if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP))
67 DRM_INFO("\t%d PCIE Lanes\n", rdev->pm.power_state[i].non_clock_info.pcie_lanes);
68 DRM_INFO("\t%d Clock Mode(s)\n", rdev->pm.power_state[i].num_clock_modes);
69 for (j = 0; j < rdev->pm.power_state[i].num_clock_modes; j++) {
70 if (rdev->flags & RADEON_IS_IGP)
71 DRM_INFO("\t\t%d engine: %d\n",
72 j,
73 rdev->pm.power_state[i].clock_info[j].sclk * 10);
74 else
75 DRM_INFO("\t\t%d engine/memory: %d/%d\n",
76 j,
77 rdev->pm.power_state[i].clock_info[j].sclk * 10,
78 rdev->pm.power_state[i].clock_info[j].mclk * 10);
79 }
80 }
81}
82
Alex Deucher516d0e42009-12-23 14:28:05 -050083static struct radeon_power_state * radeon_pick_power_state(struct radeon_device *rdev,
84 enum radeon_pm_state_type type)
85{
Rafał Miłeckibc4624c2010-02-11 21:50:06 +000086 int i, j;
87 enum radeon_pm_state_type wanted_types[2];
88 int wanted_count;
Alex Deucher516d0e42009-12-23 14:28:05 -050089
90 switch (type) {
91 case POWER_STATE_TYPE_DEFAULT:
92 default:
93 return rdev->pm.default_power_state;
94 case POWER_STATE_TYPE_POWERSAVE:
Rafał Miłecki08ff2a72010-02-21 22:46:30 +000095 if (rdev->flags & RADEON_IS_MOBILITY) {
96 wanted_types[0] = POWER_STATE_TYPE_POWERSAVE;
97 wanted_types[1] = POWER_STATE_TYPE_BATTERY;
98 wanted_count = 2;
99 } else {
100 wanted_types[0] = POWER_STATE_TYPE_PERFORMANCE;
101 wanted_count = 1;
102 }
Alex Deucher516d0e42009-12-23 14:28:05 -0500103 break;
104 case POWER_STATE_TYPE_BATTERY:
Rafał Miłecki08ff2a72010-02-21 22:46:30 +0000105 if (rdev->flags & RADEON_IS_MOBILITY) {
106 wanted_types[0] = POWER_STATE_TYPE_BATTERY;
107 wanted_types[1] = POWER_STATE_TYPE_POWERSAVE;
108 wanted_count = 2;
109 } else {
110 wanted_types[0] = POWER_STATE_TYPE_PERFORMANCE;
111 wanted_count = 1;
112 }
Alex Deucher516d0e42009-12-23 14:28:05 -0500113 break;
114 case POWER_STATE_TYPE_BALANCED:
115 case POWER_STATE_TYPE_PERFORMANCE:
Rafał Miłeckibc4624c2010-02-11 21:50:06 +0000116 wanted_types[0] = type;
117 wanted_count = 1;
Alex Deucher516d0e42009-12-23 14:28:05 -0500118 break;
119 }
120
Rafał Miłeckibc4624c2010-02-11 21:50:06 +0000121 for (i = 0; i < wanted_count; i++) {
122 for (j = 0; j < rdev->pm.num_power_states; j++) {
123 if (rdev->pm.power_state[j].type == wanted_types[i])
124 return &rdev->pm.power_state[j];
125 }
126 }
Alex Deucher516d0e42009-12-23 14:28:05 -0500127
Rafał Miłeckibc4624c2010-02-11 21:50:06 +0000128 return rdev->pm.default_power_state;
Alex Deucher516d0e42009-12-23 14:28:05 -0500129}
130
131static struct radeon_pm_clock_info * radeon_pick_clock_mode(struct radeon_device *rdev,
132 struct radeon_power_state *power_state,
133 enum radeon_pm_clock_mode_type type)
134{
135 switch (type) {
136 case POWER_MODE_TYPE_DEFAULT:
137 default:
138 return power_state->default_clock_mode;
139 case POWER_MODE_TYPE_LOW:
140 return &power_state->clock_info[0];
141 case POWER_MODE_TYPE_MID:
142 if (power_state->num_clock_modes > 2)
143 return &power_state->clock_info[1];
144 else
145 return &power_state->clock_info[0];
146 break;
147 case POWER_MODE_TYPE_HIGH:
148 return &power_state->clock_info[power_state->num_clock_modes - 1];
149 }
150
151}
152
153static void radeon_get_power_state(struct radeon_device *rdev,
154 enum radeon_pm_action action)
155{
156 switch (action) {
Alex Deucher516d0e42009-12-23 14:28:05 -0500157 case PM_ACTION_MINIMUM:
158 rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_BATTERY);
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000159 rdev->pm.requested_clock_mode =
Alex Deucher516d0e42009-12-23 14:28:05 -0500160 radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_LOW);
161 break;
162 case PM_ACTION_DOWNCLOCK:
163 rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_POWERSAVE);
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000164 rdev->pm.requested_clock_mode =
Alex Deucher516d0e42009-12-23 14:28:05 -0500165 radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_MID);
166 break;
167 case PM_ACTION_UPCLOCK:
168 rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_DEFAULT);
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000169 rdev->pm.requested_clock_mode =
Alex Deucher516d0e42009-12-23 14:28:05 -0500170 radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_HIGH);
171 break;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000172 case PM_ACTION_NONE:
173 default:
174 DRM_ERROR("Requested mode for not defined action\n");
175 return;
Alex Deucher516d0e42009-12-23 14:28:05 -0500176 }
Alex Deucher530079a2009-12-23 14:39:36 -0500177 DRM_INFO("Requested: e: %d m: %d p: %d\n",
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000178 rdev->pm.requested_clock_mode->sclk,
179 rdev->pm.requested_clock_mode->mclk,
Alex Deucher530079a2009-12-23 14:39:36 -0500180 rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
Alex Deucher516d0e42009-12-23 14:28:05 -0500181}
182
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100183static inline void radeon_sync_with_vblank(struct radeon_device *rdev)
184{
185 if (rdev->pm.active_crtcs) {
186 rdev->pm.vblank_sync = false;
187 wait_event_timeout(
188 rdev->irq.vblank_queue, rdev->pm.vblank_sync,
189 msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
190 }
191}
192
Alex Deucher516d0e42009-12-23 14:28:05 -0500193static void radeon_set_power_state(struct radeon_device *rdev)
194{
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000195 /* if *_clock_mode are the same, *_power_state are as well */
196 if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode)
Alex Deucher516d0e42009-12-23 14:28:05 -0500197 return;
Alex Deucher530079a2009-12-23 14:39:36 -0500198
199 DRM_INFO("Setting: e: %d m: %d p: %d\n",
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000200 rdev->pm.requested_clock_mode->sclk,
201 rdev->pm.requested_clock_mode->mclk,
Alex Deucher530079a2009-12-23 14:39:36 -0500202 rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100203
Alex Deucher516d0e42009-12-23 14:28:05 -0500204 /* set pcie lanes */
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100205 /* TODO */
206
Alex Deucher516d0e42009-12-23 14:28:05 -0500207 /* set voltage */
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100208 /* TODO */
209
Alex Deucher516d0e42009-12-23 14:28:05 -0500210 /* set engine clock */
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100211 radeon_sync_with_vblank(rdev);
212 radeon_pm_debug_check_in_vbl(rdev, false);
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000213 radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk);
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100214 radeon_pm_debug_check_in_vbl(rdev, true);
215
216#if 0
Alex Deucher516d0e42009-12-23 14:28:05 -0500217 /* set memory clock */
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100218 if (rdev->asic->set_memory_clock) {
219 radeon_sync_with_vblank(rdev);
220 radeon_pm_debug_check_in_vbl(rdev, false);
221 radeon_set_memory_clock(rdev, rdev->pm.requested_clock_mode->mclk);
222 radeon_pm_debug_check_in_vbl(rdev, true);
223 }
224#endif
Alex Deucher516d0e42009-12-23 14:28:05 -0500225
226 rdev->pm.current_power_state = rdev->pm.requested_power_state;
Rafał Miłecki9038dfd2010-02-20 23:15:04 +0000227 rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode;
Alex Deucher516d0e42009-12-23 14:28:05 -0500228}
229
Rafał Miłecki74338742009-11-03 00:53:02 +0100230int radeon_pm_init(struct radeon_device *rdev)
231{
Rafał Miłeckic913e232009-12-22 23:02:16 +0100232 rdev->pm.state = PM_STATE_DISABLED;
233 rdev->pm.planned_action = PM_ACTION_NONE;
234 rdev->pm.downclocked = false;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100235
Alex Deucher56278a82009-12-28 13:58:44 -0500236 if (rdev->bios) {
237 if (rdev->is_atom_bios)
238 radeon_atombios_get_power_modes(rdev);
239 else
240 radeon_combios_get_power_modes(rdev);
241 radeon_print_power_mode_info(rdev);
242 }
243
Rafał Miłecki74338742009-11-03 00:53:02 +0100244 if (radeon_debugfs_pm_init(rdev)) {
Rafał Miłeckic142c3e2009-11-06 11:38:34 +0100245 DRM_ERROR("Failed to register debugfs file for PM!\n");
Rafał Miłecki74338742009-11-03 00:53:02 +0100246 }
247
Rafał Miłeckic913e232009-12-22 23:02:16 +0100248 INIT_DELAYED_WORK(&rdev->pm.idle_work, radeon_pm_idle_work_handler);
249
250 if (radeon_dynpm != -1 && radeon_dynpm) {
251 rdev->pm.state = PM_STATE_PAUSED;
252 DRM_INFO("radeon: dynamic power management enabled\n");
253 }
254
255 DRM_INFO("radeon: power management initialized\n");
256
Rafał Miłecki74338742009-11-03 00:53:02 +0100257 return 0;
258}
259
Alex Deucher29fb52c2010-03-11 10:01:17 -0500260void radeon_pm_fini(struct radeon_device *rdev)
261{
262 if (rdev->pm.i2c_bus)
263 radeon_i2c_destroy(rdev->pm.i2c_bus);
264}
265
Rafał Miłeckic913e232009-12-22 23:02:16 +0100266void radeon_pm_compute_clocks(struct radeon_device *rdev)
267{
268 struct drm_device *ddev = rdev->ddev;
269 struct drm_connector *connector;
270 struct radeon_crtc *radeon_crtc;
271 int count = 0;
272
273 if (rdev->pm.state == PM_STATE_DISABLED)
274 return;
275
276 mutex_lock(&rdev->pm.mutex);
277
278 rdev->pm.active_crtcs = 0;
279 list_for_each_entry(connector,
280 &ddev->mode_config.connector_list, head) {
281 if (connector->encoder &&
282 connector->dpms != DRM_MODE_DPMS_OFF) {
283 radeon_crtc = to_radeon_crtc(connector->encoder->crtc);
284 rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id);
285 ++count;
286 }
287 }
288
289 if (count > 1) {
290 if (rdev->pm.state == PM_STATE_ACTIVE) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100291 cancel_delayed_work(&rdev->pm.idle_work);
292
293 rdev->pm.state = PM_STATE_PAUSED;
294 rdev->pm.planned_action = PM_ACTION_UPCLOCK;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100295 if (rdev->pm.downclocked)
Rafał Miłeckic913e232009-12-22 23:02:16 +0100296 radeon_pm_set_clocks(rdev);
297
298 DRM_DEBUG("radeon: dynamic power management deactivated\n");
Rafał Miłeckic913e232009-12-22 23:02:16 +0100299 }
300 } else if (count == 1) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100301 /* TODO: Increase clocks if needed for current mode */
302
303 if (rdev->pm.state == PM_STATE_MINIMUM) {
304 rdev->pm.state = PM_STATE_ACTIVE;
305 rdev->pm.planned_action = PM_ACTION_UPCLOCK;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100306 radeon_pm_set_clocks(rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100307
308 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
309 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
310 }
311 else if (rdev->pm.state == PM_STATE_PAUSED) {
312 rdev->pm.state = PM_STATE_ACTIVE;
313 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
314 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
315 DRM_DEBUG("radeon: dynamic power management activated\n");
316 }
Rafał Miłeckic913e232009-12-22 23:02:16 +0100317 }
318 else { /* count == 0 */
319 if (rdev->pm.state != PM_STATE_MINIMUM) {
320 cancel_delayed_work(&rdev->pm.idle_work);
321
322 rdev->pm.state = PM_STATE_MINIMUM;
323 rdev->pm.planned_action = PM_ACTION_MINIMUM;
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100324 radeon_pm_set_clocks(rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100325 }
Rafał Miłeckic913e232009-12-22 23:02:16 +0100326 }
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100327
328 mutex_unlock(&rdev->pm.mutex);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100329}
330
Dave Airlief7352612010-02-18 15:58:36 +1000331static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish)
332{
333 u32 stat_crtc1 = 0, stat_crtc2 = 0;
334 bool in_vbl = true;
335
336 if (ASIC_IS_AVIVO(rdev)) {
337 if (rdev->pm.active_crtcs & (1 << 0)) {
338 stat_crtc1 = RREG32(D1CRTC_STATUS);
339 if (!(stat_crtc1 & 1))
340 in_vbl = false;
341 }
342 if (rdev->pm.active_crtcs & (1 << 1)) {
343 stat_crtc2 = RREG32(D2CRTC_STATUS);
344 if (!(stat_crtc2 & 1))
345 in_vbl = false;
346 }
347 }
348 if (in_vbl == false)
349 DRM_INFO("not in vbl for pm change %08x %08x at %s\n", stat_crtc1,
350 stat_crtc2, finish ? "exit" : "entry");
351 return in_vbl;
352}
Rafał Miłeckic913e232009-12-22 23:02:16 +0100353static void radeon_pm_set_clocks_locked(struct radeon_device *rdev)
354{
355 /*radeon_fence_wait_last(rdev);*/
356 switch (rdev->pm.planned_action) {
357 case PM_ACTION_UPCLOCK:
Rafał Miłeckic913e232009-12-22 23:02:16 +0100358 rdev->pm.downclocked = false;
359 break;
360 case PM_ACTION_DOWNCLOCK:
Rafał Miłeckic913e232009-12-22 23:02:16 +0100361 rdev->pm.downclocked = true;
362 break;
363 case PM_ACTION_MINIMUM:
Rafał Miłeckic913e232009-12-22 23:02:16 +0100364 break;
365 case PM_ACTION_NONE:
366 DRM_ERROR("%s: PM_ACTION_NONE\n", __func__);
367 break;
368 }
Dave Airlief7352612010-02-18 15:58:36 +1000369
Alex Deucher530079a2009-12-23 14:39:36 -0500370 radeon_set_power_state(rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100371 rdev->pm.planned_action = PM_ACTION_NONE;
372}
373
374static void radeon_pm_set_clocks(struct radeon_device *rdev)
375{
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100376 radeon_get_power_state(rdev, rdev->pm.planned_action);
377 mutex_lock(&rdev->cp.mutex);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100378
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100379 if (rdev->pm.active_crtcs & (1 << 0)) {
380 rdev->pm.req_vblank |= (1 << 0);
381 drm_vblank_get(rdev->ddev, 0);
382 }
383 if (rdev->pm.active_crtcs & (1 << 1)) {
384 rdev->pm.req_vblank |= (1 << 1);
385 drm_vblank_get(rdev->ddev, 1);
386 }
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100387 radeon_pm_set_clocks_locked(rdev);
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100388 if (rdev->pm.req_vblank & (1 << 0)) {
389 rdev->pm.req_vblank &= ~(1 << 0);
390 drm_vblank_put(rdev->ddev, 0);
391 }
392 if (rdev->pm.req_vblank & (1 << 1)) {
393 rdev->pm.req_vblank &= ~(1 << 1);
394 drm_vblank_put(rdev->ddev, 1);
395 }
396
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100397 mutex_unlock(&rdev->cp.mutex);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100398}
399
400static void radeon_pm_idle_work_handler(struct work_struct *work)
401{
402 struct radeon_device *rdev;
403 rdev = container_of(work, struct radeon_device,
404 pm.idle_work.work);
405
406 mutex_lock(&rdev->pm.mutex);
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100407 if (rdev->pm.state == PM_STATE_ACTIVE) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100408 unsigned long irq_flags;
409 int not_processed = 0;
410
411 read_lock_irqsave(&rdev->fence_drv.lock, irq_flags);
412 if (!list_empty(&rdev->fence_drv.emited)) {
413 struct list_head *ptr;
414 list_for_each(ptr, &rdev->fence_drv.emited) {
415 /* count up to 3, that's enought info */
416 if (++not_processed >= 3)
417 break;
418 }
419 }
420 read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
421
422 if (not_processed >= 3) { /* should upclock */
423 if (rdev->pm.planned_action == PM_ACTION_DOWNCLOCK) {
424 rdev->pm.planned_action = PM_ACTION_NONE;
425 } else if (rdev->pm.planned_action == PM_ACTION_NONE &&
426 rdev->pm.downclocked) {
427 rdev->pm.planned_action =
428 PM_ACTION_UPCLOCK;
429 rdev->pm.action_timeout = jiffies +
430 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS);
431 }
432 } else if (not_processed == 0) { /* should downclock */
433 if (rdev->pm.planned_action == PM_ACTION_UPCLOCK) {
434 rdev->pm.planned_action = PM_ACTION_NONE;
435 } else if (rdev->pm.planned_action == PM_ACTION_NONE &&
436 !rdev->pm.downclocked) {
437 rdev->pm.planned_action =
438 PM_ACTION_DOWNCLOCK;
439 rdev->pm.action_timeout = jiffies +
440 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS);
441 }
442 }
443
444 if (rdev->pm.planned_action != PM_ACTION_NONE &&
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100445 jiffies > rdev->pm.action_timeout) {
446 radeon_pm_set_clocks(rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100447 }
448 }
449 mutex_unlock(&rdev->pm.mutex);
450
451 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
452 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
453}
454
Rafał Miłecki74338742009-11-03 00:53:02 +0100455/*
456 * Debugfs info
457 */
458#if defined(CONFIG_DEBUG_FS)
459
460static int radeon_debugfs_pm_info(struct seq_file *m, void *data)
461{
462 struct drm_info_node *node = (struct drm_info_node *) m->private;
463 struct drm_device *dev = node->minor->dev;
464 struct radeon_device *rdev = dev->dev_private;
465
Rafał Miłeckic913e232009-12-22 23:02:16 +0100466 seq_printf(m, "state: %s\n", pm_state_names[rdev->pm.state]);
Rafał Miłecki62340772009-12-15 21:46:58 +0100467 seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk);
468 seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev));
469 seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk);
470 if (rdev->asic->get_memory_clock)
471 seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev));
Rafał Miłeckiaa5120d2010-02-18 20:24:28 +0000472 if (rdev->asic->get_pcie_lanes)
473 seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev));
Rafał Miłecki74338742009-11-03 00:53:02 +0100474
475 return 0;
476}
477
478static struct drm_info_list radeon_pm_info_list[] = {
479 {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL},
480};
481#endif
482
Rafał Miłeckic913e232009-12-22 23:02:16 +0100483static int radeon_debugfs_pm_init(struct radeon_device *rdev)
Rafał Miłecki74338742009-11-03 00:53:02 +0100484{
485#if defined(CONFIG_DEBUG_FS)
486 return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list));
487#else
488 return 0;
489#endif
490}