2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Christian König.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Christian König
26 * $FreeBSD: head/sys/dev/drm2/radeon/r600_audio.c 254885 2013-08-25 19:37:15Z dumbbell $
31 #include "radeon_reg.h"
32 #include "radeon_asic.h"
36 * check if enc_priv stores radeon_encoder_atom_dig
38 static bool radeon_dig_encoder(struct drm_encoder *encoder)
40 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
41 switch (radeon_encoder->encoder_id) {
42 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
43 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
44 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
45 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
46 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
47 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
48 case ENCODER_OBJECT_ID_INTERNAL_DDI:
49 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
50 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
51 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
52 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
59 * check if the chipset is supported
61 static int r600_audio_chipset_supported(struct radeon_device *rdev)
63 return ASIC_IS_DCE2(rdev) && !ASIC_IS_DCE6(rdev);
66 struct r600_audio r600_audio_status(struct radeon_device *rdev)
68 struct r600_audio status;
71 value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL);
73 /* number of channels */
74 status.channels = (value & 0x7) + 1;
77 switch ((value & 0xF0) >> 4) {
79 status.bits_per_sample = 8;
82 status.bits_per_sample = 16;
85 status.bits_per_sample = 20;
88 status.bits_per_sample = 24;
91 status.bits_per_sample = 32;
94 dev_err(rdev->dev, "Unknown bits per sample 0x%x, using 16\n",
96 status.bits_per_sample = 16;
99 /* current sampling rate in HZ */
104 status.rate *= ((value >> 11) & 0x7) + 1;
105 status.rate /= ((value >> 8) & 0x7) + 1;
107 value = RREG32(R600_AUDIO_STATUS_BITS);
109 /* iec 60958 status bits */
110 status.status_bits = value & 0xff;
112 /* iec 60958 category code */
113 status.category_code = (value >> 8) & 0xff;
119 * update all hdmi interfaces with current audio parameters
121 void r600_audio_update_hdmi(void *arg, int pending)
123 struct radeon_device *rdev = arg;
124 struct drm_device *dev = rdev->ddev;
125 struct r600_audio audio_status = r600_audio_status(rdev);
126 struct drm_encoder *encoder;
127 bool changed = false;
129 if (rdev->audio_status.channels != audio_status.channels ||
130 rdev->audio_status.rate != audio_status.rate ||
131 rdev->audio_status.bits_per_sample != audio_status.bits_per_sample ||
132 rdev->audio_status.status_bits != audio_status.status_bits ||
133 rdev->audio_status.category_code != audio_status.category_code) {
134 rdev->audio_status = audio_status;
138 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
139 if (!radeon_dig_encoder(encoder))
141 if (changed || r600_hdmi_buffer_status_changed(encoder))
142 r600_hdmi_update_audio_settings(encoder);
147 * turn on/off audio engine
149 static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable)
152 DRM_INFO("%s audio support\n", enable ? "Enabling" : "Disabling");
153 if (ASIC_IS_DCE4(rdev)) {
155 value |= 0x81000000; /* Required to enable audio */
156 value |= 0x0e1000f0; /* fglrx sets that too */
158 WREG32(EVERGREEN_AUDIO_ENABLE, value);
160 WREG32_P(R600_AUDIO_ENABLE,
161 enable ? 0x81000000 : 0x0, ~0x81000000);
163 rdev->audio_enabled = enable;
167 * initialize the audio vars
169 int r600_audio_init(struct radeon_device *rdev)
171 if (!radeon_audio || !r600_audio_chipset_supported(rdev))
174 r600_audio_engine_enable(rdev, true);
176 rdev->audio_status.channels = -1;
177 rdev->audio_status.rate = -1;
178 rdev->audio_status.bits_per_sample = -1;
179 rdev->audio_status.status_bits = 0;
180 rdev->audio_status.category_code = 0;
186 * release the audio timer
187 * TODO: How to do this correctly on SMP systems?
189 void r600_audio_fini(struct radeon_device *rdev)
191 if (!rdev->audio_enabled)
194 r600_audio_engine_enable(rdev, false);