Commit 3299de95 authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Dave Airlie

drm/radeon/hdmi: compile audio status in 1 function

This optmizes calls, registers reads and assignments.
Signed-off-by: default avatarRafał Miłecki <zajec5@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent c284815d
...@@ -63,67 +63,56 @@ static int r600_audio_chipset_supported(struct radeon_device *rdev) ...@@ -63,67 +63,56 @@ static int r600_audio_chipset_supported(struct radeon_device *rdev)
|| rdev->family == CHIP_RS740; || rdev->family == CHIP_RS740;
} }
/* struct r600_audio r600_audio_status(struct radeon_device *rdev)
* current number of channels
*/
int r600_audio_channels(struct radeon_device *rdev)
{
return (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0x7) + 1;
}
/*
* current bits per sample
*/
int r600_audio_bits_per_sample(struct radeon_device *rdev)
{ {
uint32_t value = (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0xF0) >> 4; struct r600_audio status;
switch (value) { uint32_t value;
case 0x0: return 8;
case 0x1: return 16;
case 0x2: return 20;
case 0x3: return 24;
case 0x4: return 32;
}
dev_err(rdev->dev, "Unknown bits per sample 0x%x using 16 instead\n", value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL);
(int)value);
return 16; /* number of channels */
} status.channels = (value & 0x7) + 1;
/* /* bits per sample */
* current sampling rate in HZ switch ((value & 0xF0) >> 4) {
*/ case 0x0:
int r600_audio_rate(struct radeon_device *rdev) status.bits_per_sample = 8;
{ break;
uint32_t value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL); case 0x1:
uint32_t result; status.bits_per_sample = 16;
break;
case 0x2:
status.bits_per_sample = 20;
break;
case 0x3:
status.bits_per_sample = 24;
break;
case 0x4:
status.bits_per_sample = 32;
break;
default:
dev_err(rdev->dev, "Unknown bits per sample 0x%x, using 16\n",
(int)value);
status.bits_per_sample = 16;
}
/* current sampling rate in HZ */
if (value & 0x4000) if (value & 0x4000)
result = 44100; status.rate = 44100;
else else
result = 48000; status.rate = 48000;
status.rate *= ((value >> 11) & 0x7) + 1;
status.rate /= ((value >> 8) & 0x7) + 1;
result *= ((value >> 11) & 0x7) + 1; value = RREG32(R600_AUDIO_STATUS_BITS);
result /= ((value >> 8) & 0x7) + 1;
return result; /* iec 60958 status bits */
} status.status_bits = value & 0xff;
/* /* iec 60958 category code */
* iec 60958 status bits status.category_code = (value >> 8) & 0xff;
*/
uint8_t r600_audio_status_bits(struct radeon_device *rdev)
{
return RREG32(R600_AUDIO_STATUS_BITS) & 0xff;
}
/* return status;
* iec 60958 category code
*/
uint8_t r600_audio_category_code(struct radeon_device *rdev)
{
return (RREG32(R600_AUDIO_STATUS_BITS) >> 8) & 0xff;
} }
/* /*
...@@ -134,33 +123,23 @@ void r600_audio_update_hdmi(struct work_struct *work) ...@@ -134,33 +123,23 @@ void r600_audio_update_hdmi(struct work_struct *work)
struct radeon_device *rdev = container_of(work, struct radeon_device, struct radeon_device *rdev = container_of(work, struct radeon_device,
audio_work); audio_work);
struct drm_device *dev = rdev->ddev; struct drm_device *dev = rdev->ddev;
struct r600_audio audio_status = r600_audio_status(rdev);
int channels = r600_audio_channels(rdev);
int rate = r600_audio_rate(rdev);
int bps = r600_audio_bits_per_sample(rdev);
uint8_t status_bits = r600_audio_status_bits(rdev);
uint8_t category_code = r600_audio_category_code(rdev);
struct drm_encoder *encoder; struct drm_encoder *encoder;
int changes = 0; bool changed = false;
changes |= channels != rdev->audio.channels; if (rdev->audio_status.channels != audio_status.channels ||
changes |= rate != rdev->audio.rate; rdev->audio_status.rate != audio_status.rate ||
changes |= bps != rdev->audio.bits_per_sample; rdev->audio_status.bits_per_sample != audio_status.bits_per_sample ||
changes |= status_bits != rdev->audio.status_bits; rdev->audio_status.status_bits != audio_status.status_bits ||
changes |= category_code != rdev->audio.category_code; rdev->audio_status.category_code != audio_status.category_code) {
rdev->audio_status = audio_status;
if (changes) { changed = true;
rdev->audio.channels = channels;
rdev->audio.rate = rate;
rdev->audio.bits_per_sample = bps;
rdev->audio.status_bits = status_bits;
rdev->audio.category_code = category_code;
} }
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
if (!radeon_dig_encoder(encoder)) if (!radeon_dig_encoder(encoder))
continue; continue;
if (changes || r600_hdmi_buffer_status_changed(encoder)) if (changed || r600_hdmi_buffer_status_changed(encoder))
r600_hdmi_update_audio_settings(encoder); r600_hdmi_update_audio_settings(encoder);
} }
} }
...@@ -182,7 +161,7 @@ static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable) ...@@ -182,7 +161,7 @@ static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable)
WREG32_P(R600_AUDIO_ENABLE, WREG32_P(R600_AUDIO_ENABLE,
enable ? 0x81000000 : 0x0, ~0x81000000); enable ? 0x81000000 : 0x0, ~0x81000000);
} }
rdev->audio.enabled = enable; rdev->audio_enabled = enable;
} }
/* /*
...@@ -195,11 +174,11 @@ int r600_audio_init(struct radeon_device *rdev) ...@@ -195,11 +174,11 @@ int r600_audio_init(struct radeon_device *rdev)
r600_audio_engine_enable(rdev, true); r600_audio_engine_enable(rdev, true);
rdev->audio.channels = -1; rdev->audio_status.channels = -1;
rdev->audio.rate = -1; rdev->audio_status.rate = -1;
rdev->audio.bits_per_sample = -1; rdev->audio_status.bits_per_sample = -1;
rdev->audio.status_bits = 0; rdev->audio_status.status_bits = 0;
rdev->audio.category_code = 0; rdev->audio_status.category_code = 0;
return 0; return 0;
} }
...@@ -268,7 +247,7 @@ void r600_audio_set_clock(struct drm_encoder *encoder, int clock) ...@@ -268,7 +247,7 @@ void r600_audio_set_clock(struct drm_encoder *encoder, int clock)
*/ */
void r600_audio_fini(struct radeon_device *rdev) void r600_audio_fini(struct radeon_device *rdev)
{ {
if (!rdev->audio.enabled) if (!rdev->audio_enabled)
return; return;
r600_audio_engine_enable(rdev, false); r600_audio_engine_enable(rdev, false);
......
...@@ -398,14 +398,8 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder) ...@@ -398,14 +398,8 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
struct radeon_device *rdev = dev->dev_private; struct radeon_device *rdev = dev->dev_private;
struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
struct r600_audio audio = r600_audio_status(rdev);
uint32_t offset; uint32_t offset;
int channels = r600_audio_channels(rdev);
int rate = r600_audio_rate(rdev);
int bps = r600_audio_bits_per_sample(rdev);
uint8_t status_bits = r600_audio_status_bits(rdev);
uint8_t category_code = r600_audio_category_code(rdev);
uint32_t iec; uint32_t iec;
if (!dig->afmt || !dig->afmt->enabled) if (!dig->afmt || !dig->afmt->enabled)
...@@ -414,23 +408,23 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder) ...@@ -414,23 +408,23 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
DRM_DEBUG("%s with %d channels, %d Hz sampling rate, %d bits per sample,\n", DRM_DEBUG("%s with %d channels, %d Hz sampling rate, %d bits per sample,\n",
r600_hdmi_is_audio_buffer_filled(encoder) ? "playing" : "stopped", r600_hdmi_is_audio_buffer_filled(encoder) ? "playing" : "stopped",
channels, rate, bps); audio.channels, audio.rate, audio.bits_per_sample);
DRM_DEBUG("0x%02X IEC60958 status bits and 0x%02X category code\n", DRM_DEBUG("0x%02X IEC60958 status bits and 0x%02X category code\n",
(int)status_bits, (int)category_code); (int)audio.status_bits, (int)audio.category_code);
iec = 0; iec = 0;
if (status_bits & AUDIO_STATUS_PROFESSIONAL) if (audio.status_bits & AUDIO_STATUS_PROFESSIONAL)
iec |= 1 << 0; iec |= 1 << 0;
if (status_bits & AUDIO_STATUS_NONAUDIO) if (audio.status_bits & AUDIO_STATUS_NONAUDIO)
iec |= 1 << 1; iec |= 1 << 1;
if (status_bits & AUDIO_STATUS_COPYRIGHT) if (audio.status_bits & AUDIO_STATUS_COPYRIGHT)
iec |= 1 << 2; iec |= 1 << 2;
if (status_bits & AUDIO_STATUS_EMPHASIS) if (audio.status_bits & AUDIO_STATUS_EMPHASIS)
iec |= 1 << 3; iec |= 1 << 3;
iec |= HDMI0_60958_CS_CATEGORY_CODE(category_code); iec |= HDMI0_60958_CS_CATEGORY_CODE(audio.category_code);
switch (rate) { switch (audio.rate) {
case 32000: case 32000:
iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x3); iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x3);
break; break;
...@@ -457,7 +451,7 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder) ...@@ -457,7 +451,7 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
WREG32(HDMI0_60958_0 + offset, iec); WREG32(HDMI0_60958_0 + offset, iec);
iec = 0; iec = 0;
switch (bps) { switch (audio.bits_per_sample) {
case 16: case 16:
iec |= HDMI0_60958_CS_WORD_LENGTH(0x2); iec |= HDMI0_60958_CS_WORD_LENGTH(0x2);
break; break;
...@@ -468,11 +462,12 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder) ...@@ -468,11 +462,12 @@ void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
iec |= HDMI0_60958_CS_WORD_LENGTH(0xb); iec |= HDMI0_60958_CS_WORD_LENGTH(0xb);
break; break;
} }
if (status_bits & AUDIO_STATUS_V) if (audio.status_bits & AUDIO_STATUS_V)
iec |= 0x5 << 16; iec |= 0x5 << 16;
WREG32_P(HDMI0_60958_1 + offset, iec, ~0x5000f); WREG32_P(HDMI0_60958_1 + offset, iec, ~0x5000f);
r600_hdmi_audioinfoframe(encoder, channels - 1, 0, 0, 0, 0, 0, 0, 0); r600_hdmi_audioinfoframe(encoder, audio.channels - 1, 0, 0, 0, 0, 0, 0,
0);
r600_hdmi_audio_workaround(encoder); r600_hdmi_audio_workaround(encoder);
} }
......
...@@ -1094,7 +1094,6 @@ int radeon_pm_get_type_index(struct radeon_device *rdev, ...@@ -1094,7 +1094,6 @@ int radeon_pm_get_type_index(struct radeon_device *rdev,
int instance); int instance);
struct r600_audio { struct r600_audio {
bool enabled;
int channels; int channels;
int rate; int rate;
int bits_per_sample; int bits_per_sample;
...@@ -1535,7 +1534,8 @@ struct radeon_device { ...@@ -1535,7 +1534,8 @@ struct radeon_device {
int num_crtc; /* number of crtcs */ int num_crtc; /* number of crtcs */
struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */ struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
struct mutex vram_mutex; struct mutex vram_mutex;
struct r600_audio audio; /* audio stuff */ bool audio_enabled;
struct r600_audio audio_status; /* audio stuff */
struct notifier_block acpi_nb; struct notifier_block acpi_nb;
/* only one userspace can use Hyperz features or CMASK at a time */ /* only one userspace can use Hyperz features or CMASK at a time */
struct drm_file *hyperz_filp; struct drm_file *hyperz_filp;
......
...@@ -356,13 +356,8 @@ void r600_disable_interrupts(struct radeon_device *rdev); ...@@ -356,13 +356,8 @@ void r600_disable_interrupts(struct radeon_device *rdev);
void r600_rlc_stop(struct radeon_device *rdev); void r600_rlc_stop(struct radeon_device *rdev);
/* r600 audio */ /* r600 audio */
int r600_audio_init(struct radeon_device *rdev); int r600_audio_init(struct radeon_device *rdev);
int r600_audio_tmds_index(struct drm_encoder *encoder);
void r600_audio_set_clock(struct drm_encoder *encoder, int clock); void r600_audio_set_clock(struct drm_encoder *encoder, int clock);
int r600_audio_channels(struct radeon_device *rdev); struct r600_audio r600_audio_status(struct radeon_device *rdev);
int r600_audio_bits_per_sample(struct radeon_device *rdev);
int r600_audio_rate(struct radeon_device *rdev);
uint8_t r600_audio_status_bits(struct radeon_device *rdev);
uint8_t r600_audio_category_code(struct radeon_device *rdev);
void r600_audio_fini(struct radeon_device *rdev); void r600_audio_fini(struct radeon_device *rdev);
int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder); int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
void r600_hdmi_update_audio_settings(struct drm_encoder *encoder); void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment