drm/radeon/kms/pm: add asic specific callbacks for setting power state (v2)
authorAlex Deucher <alexdeucher@gmail.com>
Thu, 22 Apr 2010 17:38:05 +0000 (13:38 -0400)
committerDave Airlie <airlied@redhat.com>
Tue, 18 May 2010 08:20:57 +0000 (18:20 +1000)
(v2) Add evergreen vbl checks

Signed-off-by: Alex Deucher <alexdeucher@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/radeon/evergreen_reg.h
drivers/gpu/drm/radeon/r100.c
drivers/gpu/drm/radeon/r600.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_asic.c
drivers/gpu/drm/radeon/radeon_asic.h
drivers/gpu/drm/radeon/radeon_pm.c
drivers/gpu/drm/radeon/radeon_reg.h

index f7c7c964343317e38a073296c61f7df92e2cf4c4..9dba6d97d9b7b1b8310c55780eb4ac81742a6d4b 100644 (file)
 /* CRTC blocks at 0x6df0, 0x79f0, 0x105f0, 0x111f0, 0x11df0, 0x129f0 */
 #define EVERGREEN_CRTC_CONTROL                          0x6e70
 #       define EVERGREEN_CRTC_MASTER_EN                 (1 << 0)
+#define EVERGREEN_CRTC_STATUS                           0x6e8c
 #define EVERGREEN_CRTC_UPDATE_LOCK                      0x6ed4
 
 #define EVERGREEN_DC_GPIO_HPD_MASK                      0x64b0
index d35298684f301606cfac0f466172e4f32c9306d3..b076b96f8b6c23b6c5cd7d60a9b576a8f2794128 100644 (file)
@@ -67,6 +67,43 @@ MODULE_FIRMWARE(FIRMWARE_R520);
  * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280
  */
 
+void r100_set_power_state(struct radeon_device *rdev)
+{
+       /* if *_clock_mode are the same, *_power_state are as well */
+       if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode)
+               return;
+
+       DRM_INFO("Setting: e: %d m: %d p: %d\n",
+                rdev->pm.requested_clock_mode->sclk,
+                rdev->pm.requested_clock_mode->mclk,
+                rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
+
+       /* set pcie lanes */
+       /* TODO */
+
+       /* set voltage */
+       /* TODO */
+
+       /* set engine clock */
+       radeon_sync_with_vblank(rdev);
+       radeon_pm_debug_check_in_vbl(rdev, false);
+       radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk);
+       radeon_pm_debug_check_in_vbl(rdev, true);
+
+#if 0
+       /* set memory clock */
+       if (rdev->asic->set_memory_clock) {
+               radeon_sync_with_vblank(rdev);
+               radeon_pm_debug_check_in_vbl(rdev, false);
+               radeon_set_memory_clock(rdev, rdev->pm.requested_clock_mode->mclk);
+               radeon_pm_debug_check_in_vbl(rdev, true);
+       }
+#endif
+
+       rdev->pm.current_power_state = rdev->pm.requested_power_state;
+       rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode;
+}
+
 bool r100_gui_idle(struct radeon_device *rdev)
 {
        if (RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_ACTIVE)
index 094c29dd96e32eaa73d341d0490b6891edaf5f43..c2d1946535abd583017f7a0db73ab95a87cca470 100644 (file)
@@ -92,6 +92,43 @@ void r600_gpu_init(struct radeon_device *rdev);
 void r600_fini(struct radeon_device *rdev);
 void r600_irq_disable(struct radeon_device *rdev);
 
+void r600_set_power_state(struct radeon_device *rdev)
+{
+       /* if *_clock_mode are the same, *_power_state are as well */
+       if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode)
+               return;
+
+       DRM_INFO("Setting: e: %d m: %d p: %d\n",
+                rdev->pm.requested_clock_mode->sclk,
+                rdev->pm.requested_clock_mode->mclk,
+                rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
+
+       /* set pcie lanes */
+       /* TODO */
+
+       /* set voltage */
+       /* TODO */
+
+       /* set engine clock */
+       radeon_sync_with_vblank(rdev);
+       radeon_pm_debug_check_in_vbl(rdev, false);
+       radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk);
+       radeon_pm_debug_check_in_vbl(rdev, true);
+
+#if 0
+       /* set memory clock */
+       if (rdev->asic->set_memory_clock) {
+               radeon_sync_with_vblank(rdev);
+               radeon_pm_debug_check_in_vbl(rdev, false);
+               radeon_set_memory_clock(rdev, rdev->pm.requested_clock_mode->mclk);
+               radeon_pm_debug_check_in_vbl(rdev, true);
+       }
+#endif
+
+       rdev->pm.current_power_state = rdev->pm.requested_power_state;
+       rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode;
+}
+
 bool r600_gui_idle(struct radeon_device *rdev)
 {
        if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
index 433937109afc42f0a16d973a97ed129373c2ac83..11fe1d1444c232a596e4a40915007e4df892b564 100644 (file)
@@ -175,6 +175,8 @@ void radeon_pm_fini(struct radeon_device *rdev);
 void radeon_pm_compute_clocks(struct radeon_device *rdev);
 void radeon_combios_get_power_modes(struct radeon_device *rdev);
 void radeon_atombios_get_power_modes(struct radeon_device *rdev);
+bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish);
+void radeon_sync_with_vblank(struct radeon_device *rdev);
 
 /*
  * Fences.
@@ -808,6 +810,7 @@ struct radeon_asic {
         */
        void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
        bool (*gui_idle)(struct radeon_device *rdev);
+       void (*set_power_state)(struct radeon_device *rdev);
 };
 
 /*
@@ -1215,6 +1218,7 @@ static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
 #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
 #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
 #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
+#define radeon_set_power_state(rdev) (rdev)->asic->set_power_state((rdev))
 
 /* Common functions */
 /* AGP */
index 42708462fd4b2331e79b8a7d529218dc1df00a71..48893fbb658298841aa3125ba7f2a4a12de8e237 100644 (file)
@@ -166,6 +166,7 @@ static struct radeon_asic r100_asic = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r200_asic = {
@@ -205,6 +206,7 @@ static struct radeon_asic r200_asic = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r300_asic = {
@@ -245,6 +247,7 @@ static struct radeon_asic r300_asic = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r300_asic_pcie = {
@@ -284,6 +287,7 @@ static struct radeon_asic r300_asic_pcie = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r420_asic = {
@@ -324,6 +328,7 @@ static struct radeon_asic r420_asic = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic rs400_asic = {
@@ -364,6 +369,7 @@ static struct radeon_asic rs400_asic = {
        .hpd_set_polarity = &r100_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic rs600_asic = {
@@ -404,6 +410,7 @@ static struct radeon_asic rs600_asic = {
        .hpd_set_polarity = &rs600_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic rs690_asic = {
@@ -444,6 +451,7 @@ static struct radeon_asic rs690_asic = {
        .hpd_set_polarity = &rs600_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic rv515_asic = {
@@ -484,6 +492,7 @@ static struct radeon_asic rv515_asic = {
        .hpd_set_polarity = &rs600_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r520_asic = {
@@ -524,6 +533,7 @@ static struct radeon_asic r520_asic = {
        .hpd_set_polarity = &rs600_hpd_set_polarity,
        .ioctl_wait_idle = NULL,
        .gui_idle = &r100_gui_idle,
+       .set_power_state = &r100_set_power_state,
 };
 
 static struct radeon_asic r600_asic = {
@@ -563,6 +573,7 @@ static struct radeon_asic r600_asic = {
        .hpd_set_polarity = &r600_hpd_set_polarity,
        .ioctl_wait_idle = r600_ioctl_wait_idle,
        .gui_idle = &r600_gui_idle,
+       .set_power_state = &r600_set_power_state,
 };
 
 static struct radeon_asic rs780_asic = {
@@ -602,6 +613,7 @@ static struct radeon_asic rs780_asic = {
        .hpd_set_polarity = &r600_hpd_set_polarity,
        .ioctl_wait_idle = r600_ioctl_wait_idle,
        .gui_idle = &r600_gui_idle,
+       .set_power_state = &r600_set_power_state,
 };
 
 static struct radeon_asic rv770_asic = {
@@ -641,6 +653,7 @@ static struct radeon_asic rv770_asic = {
        .hpd_set_polarity = &r600_hpd_set_polarity,
        .ioctl_wait_idle = r600_ioctl_wait_idle,
        .gui_idle = &r600_gui_idle,
+       .set_power_state = &r600_set_power_state,
 };
 
 static struct radeon_asic evergreen_asic = {
@@ -678,6 +691,7 @@ static struct radeon_asic evergreen_asic = {
        .hpd_sense = &evergreen_hpd_sense,
        .hpd_set_polarity = &evergreen_hpd_set_polarity,
        .gui_idle = &r600_gui_idle,
+       .set_power_state = &r600_set_power_state,
 };
 
 int radeon_asic_init(struct radeon_device *rdev)
index c74bf9bd26c2bcba82e2568e119adaff5654f428..90d8e6dee52c4b985bd55bbd406760105c7c57a2 100644 (file)
@@ -127,6 +127,8 @@ void r100_enable_bm(struct radeon_device *rdev);
 void r100_set_common_regs(struct radeon_device *rdev);
 void r100_bm_disable(struct radeon_device *rdev);
 extern bool r100_gui_idle(struct radeon_device *rdev);
+extern void r100_set_power_state(struct radeon_device *rdev);
+
 /*
  * r200,rv250,rs300,rv280
  */
@@ -271,6 +273,7 @@ void r600_hpd_set_polarity(struct radeon_device *rdev,
                           enum radeon_hpd_id hpd);
 extern void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo);
 extern bool r600_gui_idle(struct radeon_device *rdev);
+extern void r600_set_power_state(struct radeon_device *rdev);
 
 /*
  * rv770,rv730,rv710,rv740
index ff3abd8c896692be7240972f066ca413c75709d9..129956d003a448b251208e7a35f1d1af2acdc584 100644 (file)
@@ -29,7 +29,6 @@
 #define RADEON_WAIT_VBLANK_TIMEOUT 200
 #define RADEON_WAIT_IDLE_TIMEOUT 200
 
-static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish);
 static void radeon_pm_set_clocks_locked(struct radeon_device *rdev);
 static void radeon_pm_set_clocks(struct radeon_device *rdev);
 static void radeon_pm_idle_work_handler(struct work_struct *work);
@@ -181,7 +180,7 @@ static void radeon_get_power_state(struct radeon_device *rdev,
                 rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
 }
 
-static inline void radeon_sync_with_vblank(struct radeon_device *rdev)
+void radeon_sync_with_vblank(struct radeon_device *rdev)
 {
        if (rdev->pm.active_crtcs) {
                rdev->pm.vblank_sync = false;
@@ -191,43 +190,6 @@ static inline void radeon_sync_with_vblank(struct radeon_device *rdev)
        }
 }
 
-static void radeon_set_power_state(struct radeon_device *rdev)
-{
-       /* if *_clock_mode are the same, *_power_state are as well */
-       if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode)
-               return;
-
-       DRM_INFO("Setting: e: %d m: %d p: %d\n",
-                rdev->pm.requested_clock_mode->sclk,
-                rdev->pm.requested_clock_mode->mclk,
-                rdev->pm.requested_power_state->non_clock_info.pcie_lanes);
-
-       /* set pcie lanes */
-       /* TODO */
-
-       /* set voltage */
-       /* TODO */
-
-       /* set engine clock */
-       radeon_sync_with_vblank(rdev);
-       radeon_pm_debug_check_in_vbl(rdev, false);
-       radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk);
-       radeon_pm_debug_check_in_vbl(rdev, true);
-
-#if 0
-       /* set memory clock */
-       if (rdev->asic->set_memory_clock) {
-               radeon_sync_with_vblank(rdev);
-               radeon_pm_debug_check_in_vbl(rdev, false);
-               radeon_set_memory_clock(rdev, rdev->pm.requested_clock_mode->mclk);
-               radeon_pm_debug_check_in_vbl(rdev, true);
-       }
-#endif
-
-       rdev->pm.current_power_state = rdev->pm.requested_power_state;
-       rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode;
-}
-
 int radeon_pm_init(struct radeon_device *rdev)
 {
        rdev->pm.state = PM_STATE_DISABLED;
@@ -330,26 +292,68 @@ void radeon_pm_compute_clocks(struct radeon_device *rdev)
        mutex_unlock(&rdev->pm.mutex);
 }
 
-static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish)
+bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish)
 {
-       u32 stat_crtc1 = 0, stat_crtc2 = 0;
+       u32 stat_crtc = 0;
        bool in_vbl = true;
 
-       if (ASIC_IS_AVIVO(rdev)) {
+       if (ASIC_IS_DCE4(rdev)) {
+               if (rdev->pm.active_crtcs & (1 << 0)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 1)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 2)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 3)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 4)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 5)) {
+                       stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+       } else if (ASIC_IS_AVIVO(rdev)) {
+               if (rdev->pm.active_crtcs & (1 << 0)) {
+                       stat_crtc = RREG32(D1CRTC_STATUS);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+               if (rdev->pm.active_crtcs & (1 << 1)) {
+                       stat_crtc = RREG32(D2CRTC_STATUS);
+                       if (!(stat_crtc & 1))
+                               in_vbl = false;
+               }
+       } else {
                if (rdev->pm.active_crtcs & (1 << 0)) {
-                       stat_crtc1 = RREG32(D1CRTC_STATUS);
-                       if (!(stat_crtc1 & 1))
+                       stat_crtc = RREG32(RADEON_CRTC_STATUS);
+                       if (!(stat_crtc & 1))
                                in_vbl = false;
                }
                if (rdev->pm.active_crtcs & (1 << 1)) {
-                       stat_crtc2 = RREG32(D2CRTC_STATUS);
-                       if (!(stat_crtc2 & 1))
+                       stat_crtc = RREG32(RADEON_CRTC2_STATUS);
+                       if (!(stat_crtc & 1))
                                in_vbl = false;
                }
        }
        if (in_vbl == false)
-               DRM_INFO("not in vbl for pm change %08x %08x at %s\n", stat_crtc1,
-                        stat_crtc2, finish ? "exit" : "entry");
+               DRM_INFO("not in vbl for pm change %08x at %s\n", stat_crtc,
+                        finish ? "exit" : "entry");
        return in_vbl;
 }
 static void radeon_pm_set_clocks_locked(struct radeon_device *rdev)
index 74d1cbfa23a1be18562d63a52a7e796eb41fe70f..c332f46340d5f632122fc82b0c49111b51f11b52 100644 (file)
 #       define RADEON_CRTC_CRNT_VLINE_MASK  (0x7ff << 16)
 #define RADEON_CRTC2_CRNT_FRAME             0x0314
 #define RADEON_CRTC2_GUI_TRIG_VLINE         0x0318
-#define RADEON_CRTC2_STATUS                 0x03fc
 #define RADEON_CRTC2_VLINE_CRNT_VLINE       0x0310
 #define RADEON_CRTC8_DATA                   0x03d5 /* VGA, 0x3b5 */
 #define RADEON_CRTC8_IDX                    0x03d4 /* VGA, 0x3b4 */