drm/radeon: add get_backlight_level callback
authorAlex Deucher <alexander.deucher@amd.com>
Fri, 14 Sep 2012 13:59:26 +0000 (09:59 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 27 Sep 2012 14:22:41 +0000 (10:22 -0400)
Read back the backlight level from the hw.
Needed for proper backlight restoration on resume.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/atombios_encoders.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_legacy_encoders.c

index 266036b10fec81f90cc8708f0394878e1b919d8b..5ce13b8fbe6c6866455cc84175a90d3ebf907577 100644 (file)
@@ -72,6 +72,18 @@ radeon_atom_set_backlight_level_to_reg(struct radeon_device *rdev,
                WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
 }
 
+u8
+atombios_get_backlight_level(struct radeon_encoder *radeon_encoder)
+{
+       struct drm_device *dev = radeon_encoder->base.dev;
+       struct radeon_device *rdev = dev->dev_private;
+
+       if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
+               return 0;
+
+       return radeon_atom_get_backlight_level_from_reg(rdev);
+}
+
 void
 atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
 {
index 4d67f0f5a5a36191e33c5c6cf05e43efa813fee3..de86b8e259ce8de0618f19572c23bdc771afea51 100644 (file)
@@ -1174,6 +1174,8 @@ struct radeon_asic {
                void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
                /* set backlight level */
                void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
+               /* get backlight level */
+               u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
        } display;
        /* copy functions for bo handling */
        struct {
@@ -1767,6 +1769,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
 #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
 #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
+#define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
 #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
 #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
 #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
index 2f7adeab049b7bc7bade409db71ed457d47f5e66..6225e197770030451e32d44132620bc21af6397d 100644 (file)
@@ -199,6 +199,7 @@ static struct radeon_asic r100_asic = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &radeon_legacy_set_backlight_level,
+               .get_backlight_level = &radeon_legacy_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -274,6 +275,7 @@ static struct radeon_asic r200_asic = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &radeon_legacy_set_backlight_level,
+               .get_backlight_level = &radeon_legacy_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -349,6 +351,7 @@ static struct radeon_asic r300_asic = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &radeon_legacy_set_backlight_level,
+               .get_backlight_level = &radeon_legacy_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -424,6 +427,7 @@ static struct radeon_asic r300_asic_pcie = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &radeon_legacy_set_backlight_level,
+               .get_backlight_level = &radeon_legacy_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -499,6 +503,7 @@ static struct radeon_asic r420_asic = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -574,6 +579,7 @@ static struct radeon_asic rs400_asic = {
                .get_vblank_counter = &r100_get_vblank_counter,
                .wait_for_vblank = &r100_wait_for_vblank,
                .set_backlight_level = &radeon_legacy_set_backlight_level,
+               .get_backlight_level = &radeon_legacy_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -649,6 +655,7 @@ static struct radeon_asic rs600_asic = {
                .get_vblank_counter = &rs600_get_vblank_counter,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -724,6 +731,7 @@ static struct radeon_asic rs690_asic = {
                .bandwidth_update = &rs690_bandwidth_update,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -799,6 +807,7 @@ static struct radeon_asic rv515_asic = {
                .bandwidth_update = &rv515_bandwidth_update,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -874,6 +883,7 @@ static struct radeon_asic r520_asic = {
                .get_vblank_counter = &rs600_get_vblank_counter,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -948,6 +958,7 @@ static struct radeon_asic r600_asic = {
                .get_vblank_counter = &rs600_get_vblank_counter,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1022,6 +1033,7 @@ static struct radeon_asic rs780_asic = {
                .get_vblank_counter = &rs600_get_vblank_counter,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1096,6 +1108,7 @@ static struct radeon_asic rv770_asic = {
                .get_vblank_counter = &rs600_get_vblank_counter,
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1170,6 +1183,7 @@ static struct radeon_asic evergreen_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1244,6 +1258,7 @@ static struct radeon_asic sumo_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1318,6 +1333,7 @@ static struct radeon_asic btc_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1422,6 +1438,7 @@ static struct radeon_asic cayman_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1526,6 +1543,7 @@ static struct radeon_asic trinity_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1630,6 +1648,7 @@ static struct radeon_asic si_asic = {
                .get_vblank_counter = &evergreen_get_vblank_counter,
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
+               .get_backlight_level = &atombios_get_backlight_level,
        },
        .copy = {
                .blit = NULL,
index 29b3d0545f942ce613051ad9a491bd859d8a3048..8251b44550b74fe6936461cf4d3b9f38daa36ab5 100644 (file)
@@ -43,7 +43,9 @@ void radeon_atom_set_memory_clock(struct radeon_device *rdev, uint32_t mem_clock
 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
 
 void atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level);
+u8 atombios_get_backlight_level(struct radeon_encoder *radeon_encoder);
 void radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level);
+u8 radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder);
 
 
 /*
index ec00deaab9ca9ff2baf2128c4aada5129dcfc793..8ad9c5f1601486c8e8a6e6fd8336ecbeb6db6863 100644 (file)
@@ -290,6 +290,19 @@ static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd)
        return level;
 }
 
+u8
+radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder)
+{
+       struct drm_device *dev = radeon_encoder->base.dev;
+       struct radeon_device *rdev = dev->dev_private;
+       u8 backlight_level;
+
+       backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
+                          RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
+
+       return backlight_level;
+}
+
 void
 radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
 {