From baa7d8e451f030c049f83f943b9995620d6d6bd3 Mon Sep 17 00:00:00 2001 From: Slava Grigorev Date: Mon, 8 Dec 2014 18:28:33 -0500 Subject: [PATCH] radeon/audio: set_avi_packet() function cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Christian König Signed-off-by: Slava Grigorev Signed-off-by: Alex Deucher --- drivers/gpu/drm/radeon/dce3_1_afmt.c | 22 ++----------- drivers/gpu/drm/radeon/evergreen_hdmi.c | 34 ++++++------------- drivers/gpu/drm/radeon/r600_hdmi.c | 31 ++++++------------ drivers/gpu/drm/radeon/radeon_audio.c | 43 ++++++++++++++++++------- drivers/gpu/drm/radeon/radeon_audio.h | 8 ++--- 5 files changed, 59 insertions(+), 79 deletions(-) diff --git a/drivers/gpu/drm/radeon/dce3_1_afmt.c b/drivers/gpu/drm/radeon/dce3_1_afmt.c index e96dd35fe59e..3ec9dea76ed1 100644 --- a/drivers/gpu/drm/radeon/dce3_1_afmt.c +++ b/drivers/gpu/drm/radeon/dce3_1_afmt.c @@ -208,10 +208,7 @@ void dce3_1_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *m 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; - u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; - struct hdmi_avi_infoframe frame; uint32_t offset; - ssize_t err; if (!dig || !dig->afmt) return; @@ -250,31 +247,18 @@ void dce3_1_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *m } /* TODO: HDMI0_AUDIO_INFO_UPDATE */ - WREG32(HDMI0_INFOFRAME_CONTROL0 + offset, - HDMI0_AVI_INFO_SEND | /* enable AVI info frames */ - HDMI0_AVI_INFO_CONT | /* send AVI info frames every frame/field */ + WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset, HDMI0_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ HDMI0_AUDIO_INFO_CONT); /* send audio info frames every frame/field */ - WREG32(HDMI0_INFOFRAME_CONTROL1 + offset, - HDMI0_AVI_INFO_LINE(2) | /* anything other than 0 */ + WREG32_OR(HDMI0_INFOFRAME_CONTROL1 + offset, HDMI0_AUDIO_INFO_LINE(2)); /* anything other than 0 */ WREG32(HDMI0_GC + offset, 0); /* unset HDMI0_GC_AVMUTE */ - err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); - if (err < 0) { - DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); + if (radeon_audio_set_avi_packet(encoder, mode) < 0) return; - } - - err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); - if (err < 0) { - DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); - return; - } - radeon_update_avi_infoframe(encoder, buffer, sizeof(buffer)); radeon_audio_update_acr(encoder, mode->clock); /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c index 454f656a79d0..6d22da986aa6 100644 --- a/drivers/gpu/drm/radeon/evergreen_hdmi.c +++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c @@ -205,7 +205,7 @@ void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder, /* * build a AVI Info Frame */ -void evergreen_update_avi_infoframe(struct radeon_device *rdev, u32 offset, +void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset, unsigned char *buffer, size_t size) { uint8_t *frame = buffer + 3; @@ -218,6 +218,14 @@ void evergreen_update_avi_infoframe(struct radeon_device *rdev, u32 offset, frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); WREG32(AFMT_AVI_INFO3 + offset, frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); + + WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, + HDMI_AVI_INFO_SEND | /* enable AVI info frames */ + HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ + + WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, + HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ + ~HDMI_AVI_INFO_LINE_MASK); } void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, @@ -346,10 +354,7 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode 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; - u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; - struct hdmi_avi_infoframe frame; uint32_t offset; - ssize_t err; if (!dig || !dig->afmt) return; @@ -415,27 +420,8 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode radeon_audio_write_sad_regs(encoder); radeon_audio_write_latency_fields(encoder, mode); - err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); - if (err < 0) { - DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); - return; - } - - err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); - if (err < 0) { - DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); + if (radeon_audio_set_avi_packet(encoder, mode) < 0) return; - } - - radeon_update_avi_infoframe(encoder, buffer, sizeof(buffer)); - - WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, - HDMI_AVI_INFO_SEND | /* enable AVI info frames */ - HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ - - WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, - HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ - ~HDMI_AVI_INFO_LINE_MASK); WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */ diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c index 5c5e723787ab..d6447da82c86 100644 --- a/drivers/gpu/drm/radeon/r600_hdmi.c +++ b/drivers/gpu/drm/radeon/r600_hdmi.c @@ -214,7 +214,7 @@ void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset, /* * build a HDMI Video Info Frame */ -void r600_update_avi_infoframe(struct radeon_device *rdev, u32 offset, +void r600_set_avi_packet(struct radeon_device *rdev, u32 offset, unsigned char *buffer, size_t size) { uint8_t *frame = buffer + 3; @@ -227,6 +227,13 @@ void r600_update_avi_infoframe(struct radeon_device *rdev, u32 offset, frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); WREG32(HDMI0_AVI_INFO3 + offset, frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); + + WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset, + HDMI0_AVI_INFO_SEND | /* enable AVI info frames */ + HDMI0_AVI_INFO_CONT); /* send AVI info frames every frame/field */ + + WREG32_OR(HDMI0_INFOFRAME_CONTROL1 + offset, + HDMI0_AVI_INFO_LINE(2)); /* anything other than 0 */ } /* @@ -349,10 +356,7 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod 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; - u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; - struct hdmi_avi_infoframe frame; uint32_t offset; - ssize_t err; if (!dig || !dig->afmt) return; @@ -381,33 +385,18 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod HDMI0_60958_CS_UPDATE)); WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset, - HDMI0_AVI_INFO_SEND | /* enable AVI info frames */ - HDMI0_AVI_INFO_CONT | /* send AVI info frames every frame/field */ HDMI0_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ HDMI0_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ WREG32_P(HDMI0_INFOFRAME_CONTROL1 + offset, - HDMI0_AVI_INFO_LINE(2) | /* anything other than 0 */ HDMI0_AUDIO_INFO_LINE(2), /* anything other than 0 */ - ~(HDMI0_AVI_INFO_LINE_MASK | - HDMI0_AUDIO_INFO_LINE_MASK)); + ~HDMI0_AUDIO_INFO_LINE_MASK); WREG32_AND(HDMI0_GC + offset, ~HDMI0_GC_AVMUTE); /* unset HDMI0_GC_AVMUTE */ - err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); - if (err < 0) { - DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); + if (radeon_audio_set_avi_packet(encoder, mode) < 0) return; - } - - err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); - if (err < 0) { - DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); - return; - } - - radeon_update_avi_infoframe(encoder, buffer, sizeof(buffer)); /* fglrx duplicates INFOFRAME_CONTROL0 & INFOFRAME_CONTROL1 ops here */ diff --git a/drivers/gpu/drm/radeon/radeon_audio.c b/drivers/gpu/drm/radeon/radeon_audio.c index ac9ebbfc48af..cafd2f8ec7c1 100644 --- a/drivers/gpu/drm/radeon/radeon_audio.c +++ b/drivers/gpu/drm/radeon/radeon_audio.c @@ -75,9 +75,9 @@ void dce6_hdmi_audio_set_dto(struct radeon_device *rdev, struct radeon_crtc *crtc, unsigned int clock); void dce6_dp_audio_set_dto(struct radeon_device *rdev, struct radeon_crtc *crtc, unsigned int clock); -void r600_update_avi_infoframe(struct radeon_device *rdev, u32 offset, +void r600_set_avi_packet(struct radeon_device *rdev, u32 offset, unsigned char *buffer, size_t size); -void evergreen_update_avi_infoframe(struct radeon_device *rdev, u32 offset, +void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset, unsigned char *buffer, size_t size); void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset, const struct radeon_hdmi_acr *acr); @@ -116,28 +116,24 @@ static struct radeon_audio_basic_funcs r600_funcs = { .endpoint_rreg = radeon_audio_rreg, .endpoint_wreg = radeon_audio_wreg, .enable = r600_audio_enable, - .update_avi_infoframe = r600_update_avi_infoframe, }; static struct radeon_audio_basic_funcs dce32_funcs = { .endpoint_rreg = radeon_audio_rreg, .endpoint_wreg = radeon_audio_wreg, .enable = r600_audio_enable, - .update_avi_infoframe = r600_update_avi_infoframe, }; static struct radeon_audio_basic_funcs dce4_funcs = { .endpoint_rreg = radeon_audio_rreg, .endpoint_wreg = radeon_audio_wreg, .enable = dce4_audio_enable, - .update_avi_infoframe = evergreen_update_avi_infoframe, }; static struct radeon_audio_basic_funcs dce6_funcs = { .endpoint_rreg = dce6_endpoint_rreg, .endpoint_wreg = dce6_endpoint_wreg, .enable = dce6_audio_enable, - .update_avi_infoframe = evergreen_update_avi_infoframe, }; static struct radeon_audio_funcs r600_hdmi_funcs = { @@ -145,6 +141,7 @@ static struct radeon_audio_funcs r600_hdmi_funcs = { .set_dto = r600_hdmi_audio_set_dto, .update_acr = r600_hdmi_update_acr, .set_vbi_packet = r600_set_vbi_packet, + .set_avi_packet = r600_set_avi_packet, }; static struct radeon_audio_funcs dce32_hdmi_funcs = { @@ -154,6 +151,7 @@ static struct radeon_audio_funcs dce32_hdmi_funcs = { .set_dto = dce3_2_audio_set_dto, .update_acr = dce3_2_hdmi_update_acr, .set_vbi_packet = r600_set_vbi_packet, + .set_avi_packet = r600_set_avi_packet, }; static struct radeon_audio_funcs dce32_dp_funcs = { @@ -161,6 +159,7 @@ 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, .set_dto = dce3_2_audio_set_dto, + .set_avi_packet = r600_set_avi_packet, }; static struct radeon_audio_funcs dce4_hdmi_funcs = { @@ -172,6 +171,7 @@ static struct radeon_audio_funcs dce4_hdmi_funcs = { .update_acr = evergreen_hdmi_update_acr, .set_vbi_packet = dce4_set_vbi_packet, .set_color_depth = dce4_hdmi_set_color_depth, + .set_avi_packet = evergreen_set_avi_packet, }; static struct radeon_audio_funcs dce4_dp_funcs = { @@ -180,6 +180,7 @@ static struct radeon_audio_funcs dce4_dp_funcs = { .write_speaker_allocation = dce4_afmt_dp_write_speaker_allocation, .write_latency_fields = dce4_afmt_write_latency_fields, .set_dto = dce4_dp_audio_set_dto, + .set_avi_packet = evergreen_set_avi_packet, }; static struct radeon_audio_funcs dce6_hdmi_funcs = { @@ -192,6 +193,7 @@ static struct radeon_audio_funcs dce6_hdmi_funcs = { .update_acr = evergreen_hdmi_update_acr, .set_vbi_packet = dce4_set_vbi_packet, .set_color_depth = dce4_hdmi_set_color_depth, + .set_avi_packet = evergreen_set_avi_packet, }; static struct radeon_audio_funcs dce6_dp_funcs = { @@ -201,6 +203,7 @@ static struct radeon_audio_funcs dce6_dp_funcs = { .write_speaker_allocation = dce6_afmt_dp_write_speaker_allocation, .write_latency_fields = dce6_afmt_write_latency_fields, .set_dto = dce6_dp_audio_set_dto, + .set_avi_packet = evergreen_set_avi_packet, }; static void radeon_audio_interface_init(struct radeon_device *rdev) @@ -466,16 +469,34 @@ void radeon_audio_set_dto(struct drm_encoder *encoder, unsigned int clock) radeon_encoder->audio->set_dto(rdev, crtc, clock); } -void radeon_update_avi_infoframe(struct drm_encoder *encoder, void *buffer, - size_t size) +int radeon_audio_set_avi_packet(struct drm_encoder *encoder, + struct drm_display_mode *mode) { 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; + u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; + struct hdmi_avi_infoframe frame; + int err; + + err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); + if (err < 0) { + DRM_ERROR("failed to setup AVI infoframe: %d\n", err); + return err; + } + + err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); + if (err < 0) { + DRM_ERROR("failed to pack AVI infoframe: %d\n", err); + return err; + } + + if (dig && dig->afmt && + radeon_encoder->audio && radeon_encoder->audio->set_avi_packet) + radeon_encoder->audio->set_avi_packet(rdev, dig->afmt->offset, + buffer, sizeof(buffer)); - if (dig && dig->afmt && rdev->audio.funcs->update_avi_infoframe) - rdev->audio.funcs->update_avi_infoframe(rdev, dig->afmt->offset, - buffer, size); + return 0; } /* diff --git a/drivers/gpu/drm/radeon/radeon_audio.h b/drivers/gpu/drm/radeon/radeon_audio.h index f179e5646e42..4880396b5afc 100644 --- a/drivers/gpu/drm/radeon/radeon_audio.h +++ b/drivers/gpu/drm/radeon/radeon_audio.h @@ -39,8 +39,6 @@ struct radeon_audio_basic_funcs u32 offset, u32 reg, u32 v); void (*enable)(struct radeon_device *rdev, struct r600_audio_pin *pin, u8 enable_mask); - void (*update_avi_infoframe)(struct radeon_device *rdev, u32 offset, - unsigned char *buffer, size_t size); }; struct radeon_audio_funcs @@ -59,6 +57,8 @@ struct radeon_audio_funcs const struct radeon_hdmi_acr *acr); void (*set_vbi_packet)(struct drm_encoder *encoder, u32 offset); void (*set_color_depth)(struct drm_encoder *encoder, u32 offset, int bpc); + void (*set_avi_packet)(struct radeon_device *rdev, u32 offset, + unsigned char *buffer, size_t size); }; int radeon_audio_init(struct radeon_device *rdev); @@ -78,8 +78,8 @@ void radeon_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, u8 enable_mask); void radeon_audio_fini(struct radeon_device *rdev); void radeon_audio_set_dto(struct drm_encoder *encoder, unsigned int clock); -void radeon_update_avi_infoframe(struct drm_encoder *encoder, void *buffer, - size_t size); +int radeon_audio_set_avi_packet(struct drm_encoder *encoder, + struct drm_display_mode *mode); void radeon_audio_update_acr(struct drm_encoder *encoder, unsigned int clock); void radeon_audio_set_vbi_packet(struct drm_encoder *encoder); void radeon_hdmi_set_color_depth(struct drm_encoder *encoder); -- 2.39.5