radeon/audio: consolidate write_speaker_allocation() functions
authorSlava Grigorev <slava.grigorev@amd.com>
Mon, 1 Dec 2014 23:02:57 +0000 (18:02 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 22 Jan 2015 15:42:05 +0000 (10:42 -0500)
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Slava Grigorev <slava.grigorev@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/dce3_1_afmt.c
drivers/gpu/drm/radeon/dce6_afmt.c
drivers/gpu/drm/radeon/evergreen_hdmi.c
drivers/gpu/drm/radeon/radeon_audio.c
drivers/gpu/drm/radeon/radeon_audio.h

index c74431e402e458ed77d98256644d95b60b2ee327..613e611b507b4013e93d56128140b1ee28628e8e 100644 (file)
 #include "radeon_audio.h"
 #include "r600d.h"
 
-static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
+void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
 {
        struct radeon_device *rdev = encoder->dev->dev_private;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
        u32 tmp;
-       u8 *sadb = NULL;
-       int sad_count;
-
-       list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
-               if (connector->encoder == encoder) {
-                       radeon_connector = to_radeon_connector(connector);
-                       break;
-               }
-       }
-
-       if (!radeon_connector) {
-               DRM_ERROR("Couldn't find encoder's connector\n");
-               return;
-       }
-
-       sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
-       if (sad_count < 0) {
-               DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
-               sad_count = 0;
-       }
 
        /* program the speaker allocation */
-       tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
+       tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
        tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
        /* set HDMI mode */
        tmp |= HDMI_CONNECTION;
@@ -63,9 +42,25 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
                tmp |= SPEAKER_ALLOCATION(sadb[0]);
        else
                tmp |= SPEAKER_ALLOCATION(5); /* stereo */
-       WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
+       WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
+}
 
-       kfree(sadb);
+void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
+{
+       struct radeon_device *rdev = encoder->dev->dev_private;
+       u32 tmp;
+
+       /* program the speaker allocation */
+       tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
+       tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK);
+       /* set DP mode */
+       tmp |= DP_CONNECTION;
+       if (sad_count)
+               tmp |= SPEAKER_ALLOCATION(sadb[0]);
+       else
+               tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+       WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
 }
 
 void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder,
@@ -167,7 +162,7 @@ void dce3_1_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *m
        }
 
        if (ASIC_IS_DCE32(rdev)) {
-               dce3_2_afmt_write_speaker_allocation(encoder);
+               radeon_audio_write_speaker_allocation(encoder);
                radeon_audio_write_sad_regs(encoder);
        }
 
index f263eaa9d190d99333f5b0f344ffd68453a1d863..a24c95a6e71e46e36970ca098eebf19c2df9df50 100644 (file)
@@ -144,40 +144,19 @@ void dce6_afmt_write_latency_fields(struct drm_encoder *encoder,
        WREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, tmp);
 }
 
-void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
+void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
 {
        struct radeon_device *rdev = encoder->dev->dev_private;
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
        u32 offset, tmp;
-       u8 *sadb = NULL;
-       int sad_count;
 
        if (!dig || !dig->afmt || !dig->afmt->pin)
                return;
 
        offset = dig->afmt->pin->offset;
 
-       list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
-               if (connector->encoder == encoder) {
-                       radeon_connector = to_radeon_connector(connector);
-                       break;
-               }
-       }
-
-       if (!radeon_connector) {
-               DRM_ERROR("Couldn't find encoder's connector\n");
-               return;
-       }
-
-       sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
-       if (sad_count < 0) {
-               DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
-               sad_count = 0;
-       }
-
        /* program the speaker allocation */
        tmp = RREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
        tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
@@ -188,8 +167,31 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
        else
                tmp |= SPEAKER_ALLOCATION(5); /* stereo */
        WREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
+}
 
-       kfree(sadb);
+void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
+{
+       struct radeon_device *rdev = encoder->dev->dev_private;
+       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
+       struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
+       u32 offset, tmp;
+
+       if (!dig || !dig->afmt || !dig->afmt->pin)
+               return;
+
+       offset = dig->afmt->pin->offset;
+
+       /* program the speaker allocation */
+       tmp = RREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
+       tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK);
+       /* set DP mode */
+       tmp |= DP_CONNECTION;
+       if (sad_count)
+               tmp |= SPEAKER_ALLOCATION(sadb[0]);
+       else
+               tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+       WREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
 }
 
 void dce6_afmt_write_sad_regs(struct drm_encoder *encoder,
index 2603f72234a178835815befc44118daabbe0e23b..58ff82b94f9710af8b0e4f11b521e2379b091e45 100644 (file)
@@ -33,7 +33,6 @@
 #include "evergreend.h"
 #include "atom.h"
 
-extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder);
 extern void dce6_afmt_select_pin(struct drm_encoder *encoder);
 extern void dce6_afmt_write_latency_fields(struct drm_encoder *encoder,
                                           struct drm_display_mode *mode);
@@ -127,35 +126,14 @@ static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
        WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp);
 }
 
-static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
+void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
 {
        struct radeon_device *rdev = encoder->dev->dev_private;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
        u32 tmp;
-       u8 *sadb = NULL;
-       int sad_count;
-
-       list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
-               if (connector->encoder == encoder) {
-                       radeon_connector = to_radeon_connector(connector);
-                       break;
-               }
-       }
-
-       if (!radeon_connector) {
-               DRM_ERROR("Couldn't find encoder's connector\n");
-               return;
-       }
-
-       sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
-       if (sad_count < 0) {
-               DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
-               sad_count = 0;
-       }
 
        /* program the speaker allocation */
-       tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
+       tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
        tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
        /* set HDMI mode */
        tmp |= HDMI_CONNECTION;
@@ -163,9 +141,25 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
                tmp |= SPEAKER_ALLOCATION(sadb[0]);
        else
                tmp |= SPEAKER_ALLOCATION(5); /* stereo */
-       WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
+       WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
+}
 
-       kfree(sadb);
+void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+       u8 *sadb, int sad_count)
+{
+       struct radeon_device *rdev = encoder->dev->dev_private;
+       u32 tmp;
+
+       /* program the speaker allocation */
+       tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
+       tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK);
+       /* set DP mode */
+       tmp |= DP_CONNECTION;
+       if (sad_count)
+               tmp |= SPEAKER_ALLOCATION(sadb[0]);
+       else
+               tmp |= SPEAKER_ALLOCATION(5); /* stereo */
+       WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
 }
 
 void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
@@ -417,11 +411,7 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
               AFMT_60958_CS_CHANNEL_NUMBER_6(7) |
               AFMT_60958_CS_CHANNEL_NUMBER_7(8));
 
-       if (ASIC_IS_DCE6(rdev)) {
-               dce6_afmt_write_speaker_allocation(encoder);
-       } else {
-               dce4_afmt_write_speaker_allocation(encoder);
-       }
+       radeon_audio_write_speaker_allocation(encoder);
 
        WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
               AFMT_AUDIO_CHANNEL_ENABLE(0xff));
index 0fc7a93a6fb2a7ed7ca71bd73dc0fbefd648bb30..22f12e8e1b1409f57e3b42bc3041a14703cace2a 100644 (file)
@@ -41,6 +41,18 @@ void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
                struct cea_sad *sads, int sad_count);
 void dce6_afmt_write_sad_regs(struct drm_encoder *encoder,
                struct cea_sad *sads, int sad_count);
+void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
+void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
+void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
+void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
+void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
+void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
 
 static const u32 pin_offsets[7] =
 {
@@ -81,26 +93,32 @@ static struct radeon_audio_basic_funcs dce6_funcs = {
 
 static struct radeon_audio_funcs dce32_hdmi_funcs = {
        .write_sad_regs = dce3_2_afmt_write_sad_regs,
+       .write_speaker_allocation = dce3_2_afmt_hdmi_write_speaker_allocation,
 };
 
 static struct radeon_audio_funcs dce32_dp_funcs = {
        .write_sad_regs = dce3_2_afmt_write_sad_regs,
+       .write_speaker_allocation = dce3_2_afmt_dp_write_speaker_allocation,
 };
 
 static struct radeon_audio_funcs dce4_hdmi_funcs = {
        .write_sad_regs = evergreen_hdmi_write_sad_regs,
+       .write_speaker_allocation = dce4_afmt_hdmi_write_speaker_allocation,
 };
 
 static struct radeon_audio_funcs dce4_dp_funcs = {
        .write_sad_regs = evergreen_hdmi_write_sad_regs,
+       .write_speaker_allocation = dce4_afmt_dp_write_speaker_allocation,
 };
 
 static struct radeon_audio_funcs dce6_hdmi_funcs = {
        .write_sad_regs = dce6_afmt_write_sad_regs,
+       .write_speaker_allocation = dce6_afmt_hdmi_write_speaker_allocation,
 };
 
 static struct radeon_audio_funcs dce6_dp_funcs = {
        .write_sad_regs = dce6_afmt_write_sad_regs,
+       .write_speaker_allocation = dce6_afmt_dp_write_speaker_allocation,
 };
 
 static void radeon_audio_interface_init(struct radeon_device *rdev)
@@ -254,3 +272,38 @@ void radeon_audio_write_sad_regs(struct drm_encoder *encoder)
 
        kfree(sads);
 }
+
+void radeon_audio_write_speaker_allocation(struct drm_encoder *encoder)
+{
+       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
+    struct drm_connector *connector;
+    struct radeon_connector *radeon_connector = NULL;
+    u8 *sadb = NULL;
+    int sad_count;
+
+    list_for_each_entry(connector,
+               &encoder->dev->mode_config.connector_list, head) {
+        if (connector->encoder == encoder) {
+            radeon_connector = to_radeon_connector(connector);
+            break;
+        }
+    }
+
+    if (!radeon_connector) {
+        DRM_ERROR("Couldn't find encoder's connector\n");
+        return;
+    }
+
+    sad_count = drm_edid_to_speaker_allocation(
+               radeon_connector_edid(connector), &sadb);
+    if (sad_count < 0) {
+        DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n",
+                       sad_count);
+        sad_count = 0;
+    }
+
+       if (radeon_encoder->audio && radeon_encoder->audio->write_speaker_allocation)
+               radeon_encoder->audio->write_speaker_allocation(encoder, sadb, sad_count);
+
+    kfree(sadb);
+}
index ea3594e3e03c2a988372932252c44ca4dd45ae07..cc0596f24d9adc30bd85d23677ddc9c381014e54 100644 (file)
@@ -43,6 +43,8 @@ struct radeon_audio_funcs
 {
        void (*write_sad_regs)(struct drm_encoder *encoder,
                struct cea_sad *sads, int sad_count);
+       void (*write_speaker_allocation)(struct drm_encoder *encoder,
+               u8 *sadb, int sad_count);
 };
 
 int radeon_audio_init(struct radeon_device *rdev);
@@ -53,5 +55,6 @@ u32 radeon_audio_endpoint_rreg(struct radeon_device *rdev,
 void radeon_audio_endpoint_wreg(struct radeon_device *rdev,
        u32 offset,     u32 reg, u32 v);
 void radeon_audio_write_sad_regs(struct drm_encoder *encoder);
+void radeon_audio_write_speaker_allocation(struct drm_encoder *encoder);
 
 #endif