From a6d43f53701f1287c963009a10c649d859121feb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
Date: Wed, 11 Nov 2009 21:46:39 +0100
Subject: [PATCH] PM hacks

---
 drivers/gpu/drm/radeon/radeon.h    |    1 +
 drivers/gpu/drm/radeon/radeon_pm.c |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 9f0bd98..51f0b6d 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -551,6 +551,7 @@ struct radeon_wb {
  * (type of memory, bus size, efficiency, ...)
  */
 struct radeon_pm {
+	struct timer_list idle_timer;
 	fixed20_12		max_bandwidth;
 	fixed20_12		igp_sideport_mclk;
 	fixed20_12		igp_system_mclk;
diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
index 46146c6..2829273 100644
--- a/drivers/gpu/drm/radeon/radeon_pm.c
+++ b/drivers/gpu/drm/radeon/radeon_pm.c
@@ -23,6 +23,7 @@
 #include "radeon.h"
 
 int radeon_debugfs_pm_init(struct radeon_device *rdev);
+void radeon_pm_reclock(unsigned long arg);
 
 int radeon_pm_init(struct radeon_device *rdev)
 {
@@ -30,9 +31,21 @@ int radeon_pm_init(struct radeon_device *rdev)
 		DRM_ERROR("Failed to register debugfs file for CP !\n");
 	}
 
+	setup_timer(&rdev->pm.idle_timer, radeon_pm_reclock, (unsigned long)rdev);
+
 	return 0;
 }
 
+void radeon_pm_reclock(unsigned long arg)
+{
+	struct radeon_device *rdev = (struct radeon_device *)arg;
+	radeon_ring_free_size(rdev);
+
+	mutex_lock(&rdev->cs_mutex);
+	radeon_set_engine_clock(rdev, 30000); /* 300'000 kHz */
+	mutex_unlock(&rdev->cs_mutex);
+}
+
 /*
  * Debugfs info
  */
@@ -47,6 +60,12 @@ static int radeon_debugfs_pm_info(struct seq_file *m, void *data)
 	seq_printf(m, "engine clock: %u0 Hz\n", radeon_get_engine_clock(rdev));
 	seq_printf(m, "memory clock: %u0 Hz\n", radeon_get_memory_clock(rdev));
 
+	/* This one works */
+	/*radeon_pm_reclock((unsigned long)rdev);*/
+
+	/* This causes lock up */
+	/*mod_timer(&rdev->pm.idle_timer, jiffies + msecs_to_jiffies(50));*/
+
 	return 0;
 }
 
-- 
1.6.4.2

