radeon/audio: consolidate write_sad_regs() functions
authorAlex Deucher <alexander.deucher@amd.com>
Thu, 22 Jan 2015 15:41:55 +0000 (10:41 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 22 Jan 2015 15:41:55 +0000 (10:41 -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 bafdf92a5732dfa679f74e47ee582a699f9d635e..c74431e402e458ed77d98256644d95b60b2ee327 100644 (file)
@@ -24,6 +24,7 @@
 #include <drm/drmP.h>
 #include "radeon.h"
 #include "radeon_asic.h"
+#include "radeon_audio.h"
 #include "r600d.h"
 
 static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
@@ -67,14 +68,11 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
        kfree(sadb);
 }
 
-static void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder)
+void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder,
+       struct cea_sad *sads, int sad_count)
 {
+       int i;
        struct radeon_device *rdev = encoder->dev->dev_private;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
-       struct cea_sad *sads;
-       int i, sad_count;
-
        static const u16 eld_reg_to_type[][2] = {
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
@@ -90,25 +88,6 @@ static void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder)
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
        };
 
-       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_sad(radeon_connector->edid, &sads);
-       if (sad_count <= 0) {
-               DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
-               return;
-       }
-       BUG_ON(!sads);
-
        for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
                u32 value = 0;
                u8 stereo_freqs = 0;
@@ -135,10 +114,8 @@ static void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder)
 
                value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
 
-               WREG32(eld_reg_to_type[i][0], value);
+               WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value);
        }
-
-       kfree(sads);
 }
 
 /*
@@ -191,7 +168,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);
-               dce3_2_afmt_write_sad_regs(encoder);
+               radeon_audio_write_sad_regs(encoder);
        }
 
        WREG32(HDMI0_ACR_PACKET_CONTROL + offset,
index 821f53ce3f65323460e63007bf5f6d4b2ca8bea1..f263eaa9d190d99333f5b0f344ffd68453a1d863 100644 (file)
@@ -192,17 +192,14 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
        kfree(sadb);
 }
 
-void dce6_afmt_write_sad_regs(struct drm_encoder *encoder)
+void dce6_afmt_write_sad_regs(struct drm_encoder *encoder,
+       struct cea_sad *sads, int sad_count)
 {
-       struct radeon_device *rdev = encoder->dev->dev_private;
+       u32 offset;
+       int i;
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
-       u32 offset;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
-       struct cea_sad *sads;
-       int i, sad_count;
-
+       struct radeon_device *rdev = encoder->dev->dev_private;
        static const u16 eld_reg_to_type[][2] = {
                { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
                { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
@@ -223,25 +220,6 @@ void dce6_afmt_write_sad_regs(struct drm_encoder *encoder)
 
        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_sad(radeon_connector_edid(connector), &sads);
-       if (sad_count <= 0) {
-               DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
-               return;
-       }
-       BUG_ON(!sads);
-
        for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
                u32 value = 0;
                u8 stereo_freqs = 0;
@@ -270,8 +248,6 @@ void dce6_afmt_write_sad_regs(struct drm_encoder *encoder)
 
                WREG32_ENDPOINT(offset, eld_reg_to_type[i][0], value);
        }
-
-       kfree(sads);
 }
 
 void dce6_audio_enable(struct radeon_device *rdev,
index 53abd9b17a50b0490dd24b468461ccaab7b54e87..2603f72234a178835815befc44118daabbe0e23b 100644 (file)
 #include <drm/radeon_drm.h>
 #include "radeon.h"
 #include "radeon_asic.h"
+#include "radeon_audio.h"
 #include "evergreend.h"
 #include "atom.h"
 
 extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder);
-extern void dce6_afmt_write_sad_regs(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);
@@ -168,14 +168,11 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
        kfree(sadb);
 }
 
-static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
+void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
+       struct cea_sad *sads, int sad_count)
 {
+       int i;
        struct radeon_device *rdev = encoder->dev->dev_private;
-       struct drm_connector *connector;
-       struct radeon_connector *radeon_connector = NULL;
-       struct cea_sad *sads;
-       int i, sad_count;
-
        static const u16 eld_reg_to_type[][2] = {
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
@@ -191,25 +188,6 @@ static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
                { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
        };
 
-       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_sad(radeon_connector_edid(connector), &sads);
-       if (sad_count <= 0) {
-               DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
-               return;
-       }
-       BUG_ON(!sads);
-
        for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
                u32 value = 0;
                u8 stereo_freqs = 0;
@@ -236,10 +214,8 @@ static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
 
                value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
 
-               WREG32(eld_reg_to_type[i][0], value);
+               WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value);
        }
-
-       kfree(sads);
 }
 
 /*
@@ -454,13 +430,13 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
 
        if (ASIC_IS_DCE6(rdev)) {
                dce6_afmt_select_pin(encoder);
-               dce6_afmt_write_sad_regs(encoder);
                dce6_afmt_write_latency_fields(encoder, mode);
        } else {
-               evergreen_hdmi_write_sad_regs(encoder);
                dce4_afmt_write_latency_fields(encoder, mode);
        }
 
+       radeon_audio_write_sad_regs(encoder);
+
        err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
        if (err < 0) {
                DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
index 36174b6ca681cedd581eb8f114ca8e5ebf68ecdb..0fc7a93a6fb2a7ed7ca71bd73dc0fbefd648bb30 100644 (file)
@@ -35,6 +35,12 @@ void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
 u32 dce6_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg);
 void dce6_endpoint_wreg(struct radeon_device *rdev,
                u32 offset, u32 reg, u32 v);
+void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder,
+               struct cea_sad *sads, int sad_count);
+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);
 
 static const u32 pin_offsets[7] =
 {
@@ -73,14 +79,44 @@ static struct radeon_audio_basic_funcs dce6_funcs = {
        .endpoint_wreg = dce6_endpoint_wreg,
 };
 
+static struct radeon_audio_funcs dce32_hdmi_funcs = {
+       .write_sad_regs = dce3_2_afmt_write_sad_regs,
+};
+
+static struct radeon_audio_funcs dce32_dp_funcs = {
+       .write_sad_regs = dce3_2_afmt_write_sad_regs,
+};
+
+static struct radeon_audio_funcs dce4_hdmi_funcs = {
+       .write_sad_regs = evergreen_hdmi_write_sad_regs,
+};
+
+static struct radeon_audio_funcs dce4_dp_funcs = {
+       .write_sad_regs = evergreen_hdmi_write_sad_regs,
+};
+
+static struct radeon_audio_funcs dce6_hdmi_funcs = {
+       .write_sad_regs = dce6_afmt_write_sad_regs,
+};
+
+static struct radeon_audio_funcs dce6_dp_funcs = {
+       .write_sad_regs = dce6_afmt_write_sad_regs,
+};
+
 static void radeon_audio_interface_init(struct radeon_device *rdev)
 {
        if (ASIC_IS_DCE6(rdev)) {
                rdev->audio.funcs = &dce6_funcs;
+               rdev->audio.hdmi_funcs = &dce6_hdmi_funcs;
+               rdev->audio.dp_funcs = &dce6_dp_funcs;
        } else if (ASIC_IS_DCE4(rdev)) {
                rdev->audio.funcs = &dce4_funcs;
+               rdev->audio.hdmi_funcs = &dce4_hdmi_funcs;
+               rdev->audio.dp_funcs = &dce4_dp_funcs;
        } else {
                rdev->audio.funcs = &dce32_funcs;
+               rdev->audio.hdmi_funcs = &dce32_hdmi_funcs;
+               rdev->audio.dp_funcs = &dce32_dp_funcs;
        }
 }
 
@@ -182,3 +218,39 @@ void radeon_audio_endpoint_wreg(struct radeon_device *rdev, u32 offset,
        if (rdev->audio.funcs->endpoint_wreg)
                rdev->audio.funcs->endpoint_wreg(rdev, offset, reg, v);
 }
+
+void radeon_audio_write_sad_regs(struct drm_encoder *encoder)
+{
+       struct radeon_encoder *radeon_encoder;
+       struct drm_connector *connector;
+       struct radeon_connector *radeon_connector = NULL;
+       struct cea_sad *sads;
+       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_sad(radeon_connector_edid(connector), &sads);
+       if (sad_count <= 0) {
+               DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
+               return;
+       }
+       BUG_ON(!sads);
+
+       radeon_encoder = to_radeon_encoder(encoder);
+
+       if (radeon_encoder->audio && radeon_encoder->audio->write_sad_regs)
+               radeon_encoder->audio->write_sad_regs(encoder, sads, sad_count);
+
+       kfree(sads);
+}
index e4b0b6437df7c707d945dbbf16be83c0fd4843d2..ea3594e3e03c2a988372932252c44ca4dd45ae07 100644 (file)
@@ -41,7 +41,8 @@ struct radeon_audio_basic_funcs
 
 struct radeon_audio_funcs
 {
-       /* TODO: add mode depended audio interface */
+       void (*write_sad_regs)(struct drm_encoder *encoder,
+               struct cea_sad *sads, int sad_count);
 };
 
 int radeon_audio_init(struct radeon_device *rdev);
@@ -51,5 +52,6 @@ u32 radeon_audio_endpoint_rreg(struct radeon_device *rdev,
        u32 offset, u32 reg);
 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);
 
 #endif