drm/radeon: switch audio handling to use callbacks
authorAlex Deucher <alexander.deucher@amd.com>
Thu, 18 Apr 2013 15:32:16 +0000 (11:32 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 23 Apr 2013 22:03:53 +0000 (18:03 -0400)
Register audio callbacks for asic where we support
audio.  Cleans up the code and makes it easier to
add support for newer asics.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/atombios_encoders.c
drivers/gpu/drm/radeon/evergreen_hdmi.c
drivers/gpu/drm/radeon/r600_hdmi.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_asic.c
drivers/gpu/drm/radeon/radeon_asic.h

index 4552d4aff3178ac7c6f90972c0711340837dfacf..44a7da66e0810ee489b46c4c1c500af639eeb848 100644 (file)
@@ -2150,13 +2150,10 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
        atombios_apply_encoder_quirks(encoder, adjusted_mode);
 
        if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
-               r600_hdmi_enable(encoder);
-               if (ASIC_IS_DCE6(rdev))
-                       ; /* TODO (use pointers instead of if-s?) */
-               else if (ASIC_IS_DCE4(rdev))
-                       evergreen_hdmi_setmode(encoder, adjusted_mode);
-               else
-                       r600_hdmi_setmode(encoder, adjusted_mode);
+               if (rdev->asic->display.hdmi_enable)
+                       radeon_hdmi_enable(rdev, encoder, true);
+               if (rdev->asic->display.hdmi_setmode)
+                       radeon_hdmi_setmode(rdev, encoder, adjusted_mode);
        }
 }
 
@@ -2413,8 +2410,10 @@ static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
 
 disable_done:
        if (radeon_encoder_is_digital(encoder)) {
-               if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
-                       r600_hdmi_disable(encoder);
+               if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
+                       if (rdev->asic->display.hdmi_enable)
+                               radeon_hdmi_enable(rdev, encoder, false);
+               }
                dig = radeon_encoder->enc_priv;
                dig->dig_encoder = -1;
        }
index 9fc22ee40f96f26b5037a1ade357a24abf14e3a5..e32fd2cbc3681e4929066ca3ffb51e7afc91e29a 100644 (file)
@@ -219,3 +219,20 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
        WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
        WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
 }
+
+void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
+{
+       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
+       struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
+
+       /* Silent, r600_hdmi_enable will raise WARN for us */
+       if (enable && dig->afmt->enabled)
+               return;
+       if (!enable && !dig->afmt->enabled)
+               return;
+
+       dig->afmt->enabled = enable;
+
+       DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
+                 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
+}
index 62721bfabe7704f5a857f4281d4310bd13a409e5..2e15888d8307218a2f65ef63a4326ca7a4151f92 100644 (file)
@@ -439,112 +439,73 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
 /*
  * enable the HDMI engine
  */
-void r600_hdmi_enable(struct drm_encoder *encoder)
+void r600_hdmi_enable(struct drm_encoder *encoder, bool enable)
 {
        struct drm_device *dev = encoder->dev;
        struct radeon_device *rdev = dev->dev_private;
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
-       uint32_t offset;
-       u32 hdmi;
-
-       if (ASIC_IS_DCE6(rdev))
-               return;
+       u32 hdmi = HDMI0_ERROR_ACK;
 
        /* Silent, r600_hdmi_enable will raise WARN for us */
-       if (dig->afmt->enabled)
+       if (enable && dig->afmt->enabled)
+               return;
+       if (!enable && !dig->afmt->enabled)
                return;
-       offset = dig->afmt->offset;
 
        /* Older chipsets require setting HDMI and routing manually */
-       if (ASIC_IS_DCE2(rdev) && !ASIC_IS_DCE3(rdev)) {
-               hdmi = HDMI0_ERROR_ACK | HDMI0_ENABLE;
+       if (!ASIC_IS_DCE3(rdev)) {
+               if (enable)
+                       hdmi |= HDMI0_ENABLE;
                switch (radeon_encoder->encoder_id) {
                case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
-                       WREG32_OR(AVIVO_TMDSA_CNTL, AVIVO_TMDSA_CNTL_HDMI_EN);
-                       hdmi |= HDMI0_STREAM(HDMI0_STREAM_TMDSA);
+                       if (enable) {
+                               WREG32_OR(AVIVO_TMDSA_CNTL, AVIVO_TMDSA_CNTL_HDMI_EN);
+                               hdmi |= HDMI0_STREAM(HDMI0_STREAM_TMDSA);
+                       } else {
+                               WREG32_AND(AVIVO_TMDSA_CNTL, ~AVIVO_TMDSA_CNTL_HDMI_EN);
+                       }
                        break;
                case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
-                       WREG32_OR(AVIVO_LVTMA_CNTL, AVIVO_LVTMA_CNTL_HDMI_EN);
-                       hdmi |= HDMI0_STREAM(HDMI0_STREAM_LVTMA);
+                       if (enable) {
+                               WREG32_OR(AVIVO_LVTMA_CNTL, AVIVO_LVTMA_CNTL_HDMI_EN);
+                               hdmi |= HDMI0_STREAM(HDMI0_STREAM_LVTMA);
+                       } else {
+                               WREG32_AND(AVIVO_LVTMA_CNTL, ~AVIVO_LVTMA_CNTL_HDMI_EN);
+                       }
                        break;
                case ENCODER_OBJECT_ID_INTERNAL_DDI:
-                       WREG32_OR(DDIA_CNTL, DDIA_HDMI_EN);
-                       hdmi |= HDMI0_STREAM(HDMI0_STREAM_DDIA);
+                       if (enable) {
+                               WREG32_OR(DDIA_CNTL, DDIA_HDMI_EN);
+                               hdmi |= HDMI0_STREAM(HDMI0_STREAM_DDIA);
+                       } else {
+                               WREG32_AND(DDIA_CNTL, ~DDIA_HDMI_EN);
+                       }
                        break;
                case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
-                       hdmi |= HDMI0_STREAM(HDMI0_STREAM_DVOA);
+                       if (enable)
+                               hdmi |= HDMI0_STREAM(HDMI0_STREAM_DVOA);
                        break;
                default:
                        dev_err(rdev->dev, "Invalid encoder for HDMI: 0x%X\n",
                                radeon_encoder->encoder_id);
                        break;
                }
-               WREG32(HDMI0_CONTROL + offset, hdmi);
+               WREG32(HDMI0_CONTROL + dig->afmt->offset, hdmi);
        }
 
        if (rdev->irq.installed) {
                /* if irq is available use it */
                /* XXX: shouldn't need this on any asics.  Double check DCE2/3 */
-               if (!ASIC_IS_DCE4(rdev))
+               if (enable)
                        radeon_irq_kms_enable_afmt(rdev, dig->afmt->id);
+               else
+                       radeon_irq_kms_disable_afmt(rdev, dig->afmt->id);
        }
 
-       dig->afmt->enabled = true;
+       dig->afmt->enabled = enable;
 
-       DRM_DEBUG("Enabling HDMI interface @ 0x%04X for encoder 0x%x\n",
-                 offset, radeon_encoder->encoder_id);
+       DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
+                 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
 }
 
-/*
- * disable the HDMI engine
- */
-void r600_hdmi_disable(struct drm_encoder *encoder)
-{
-       struct drm_device *dev = encoder->dev;
-       struct radeon_device *rdev = dev->dev_private;
-       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
-       struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
-       uint32_t offset;
-
-       if (ASIC_IS_DCE6(rdev))
-               return;
-
-       /* Called for ATOM_ENCODER_MODE_HDMI only */
-       if (!dig || !dig->afmt) {
-               return;
-       }
-       if (!dig->afmt->enabled)
-               return;
-       offset = dig->afmt->offset;
-
-       DRM_DEBUG("Disabling HDMI interface @ 0x%04X for encoder 0x%x\n",
-                 offset, radeon_encoder->encoder_id);
-
-       /* disable irq */
-       radeon_irq_kms_disable_afmt(rdev, dig->afmt->id);
-
-       /* Older chipsets not handled by AtomBIOS */
-       if (ASIC_IS_DCE2(rdev) && !ASIC_IS_DCE3(rdev)) {
-               switch (radeon_encoder->encoder_id) {
-               case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
-                       WREG32_AND(AVIVO_TMDSA_CNTL, ~AVIVO_TMDSA_CNTL_HDMI_EN);
-                       break;
-               case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
-                       WREG32_AND(AVIVO_LVTMA_CNTL, ~AVIVO_LVTMA_CNTL_HDMI_EN);
-                       break;
-               case ENCODER_OBJECT_ID_INTERNAL_DDI:
-                       WREG32_AND(DDIA_CNTL, ~DDIA_HDMI_EN);
-                       break;
-               case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
-                       break;
-               default:
-                       dev_err(rdev->dev, "Invalid encoder for HDMI: 0x%X\n",
-                               radeon_encoder->encoder_id);
-                       break;
-               }
-               WREG32(HDMI0_CONTROL + offset, HDMI0_ERROR_ACK);
-       }
-
-       dig->afmt->enabled = false;
-}
index 7935370f01afcfde4bc0d563305628fa1eb69498..856a67d5bd9b9987410f270dbd4b3b8e8db4b2c6 100644 (file)
@@ -1270,6 +1270,9 @@ struct radeon_asic {
                void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
                /* get backlight level */
                u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
+               /* audio callbacks */
+               void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
+               void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
        } display;
        /* copy functions for bo handling */
        struct {
@@ -1878,6 +1881,8 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
 #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_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
+#define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
 #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))
@@ -2013,9 +2018,6 @@ struct radeon_hdmi_acr {
 
 extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
 
-extern void r600_hdmi_enable(struct drm_encoder *encoder);
-extern void r600_hdmi_disable(struct drm_encoder *encoder);
-extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
 extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
                                     u32 tiling_pipe_num,
                                     u32 max_rb_num,
@@ -2026,8 +2028,6 @@ extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  * evergreen functions used by radeon_encoder.c
  */
 
-extern void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
-
 extern int ni_init_microcode(struct radeon_device *rdev);
 extern int ni_mc_load_microcode(struct radeon_device *rdev);
 
index 48d020057100dd8378e65a153230a52b1357c022..6417132c50cf5bf8df186225cc8233d182188197 100644 (file)
@@ -656,6 +656,8 @@ static struct radeon_asic rs600_asic = {
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &r600_hdmi_enable,
+               .hdmi_setmode = &r600_hdmi_setmode,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -732,6 +734,8 @@ static struct radeon_asic rs690_asic = {
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &r600_hdmi_enable,
+               .hdmi_setmode = &r600_hdmi_setmode,
        },
        .copy = {
                .blit = &r100_copy_blit,
@@ -970,6 +974,8 @@ static struct radeon_asic r600_asic = {
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &r600_hdmi_enable,
+               .hdmi_setmode = &r600_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1056,6 +1062,8 @@ static struct radeon_asic rs780_asic = {
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &r600_hdmi_enable,
+               .hdmi_setmode = &r600_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1151,6 +1159,8 @@ static struct radeon_asic rv770_asic = {
                .wait_for_vblank = &avivo_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &r600_hdmi_enable,
+               .hdmi_setmode = &r600_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1247,6 +1257,8 @@ static struct radeon_asic evergreen_asic = {
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &evergreen_hdmi_enable,
+               .hdmi_setmode = &evergreen_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1343,6 +1355,8 @@ static struct radeon_asic sumo_asic = {
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &evergreen_hdmi_enable,
+               .hdmi_setmode = &evergreen_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1439,6 +1453,8 @@ static struct radeon_asic btc_asic = {
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &evergreen_hdmi_enable,
+               .hdmi_setmode = &evergreen_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
@@ -1578,6 +1594,8 @@ static struct radeon_asic cayman_asic = {
                .wait_for_vblank = &dce4_wait_for_vblank,
                .set_backlight_level = &atombios_set_backlight_level,
                .get_backlight_level = &atombios_get_backlight_level,
+               .hdmi_enable = &evergreen_hdmi_enable,
+               .hdmi_setmode = &evergreen_hdmi_setmode,
        },
        .copy = {
                .blit = &r600_copy_blit,
index fa8b8bf61c2dc20cc3fac13abe5ef5e32cc8d6e2..2c87365d345fcf3a5128c9da26dd7b12df6ce757 100644 (file)
@@ -378,6 +378,8 @@ struct r600_audio r600_audio_status(struct radeon_device *rdev);
 void r600_audio_fini(struct radeon_device *rdev);
 int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
 void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
+void r600_hdmi_enable(struct drm_encoder *encoder, bool enable);
+void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
 /* r600 blit */
 int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages,
                           struct radeon_fence **fence, struct radeon_sa_bo **vb,
@@ -476,6 +478,8 @@ int evergreen_copy_dma(struct radeon_device *rdev,
                       uint64_t src_offset, uint64_t dst_offset,
                       unsigned num_gpu_pages,
                       struct radeon_fence **fence);
+void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable);
+void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
 
 /*
  * cayman