2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Slava Grigorev <slava.grigorev@amd.com>
26 #include <drm/drm_crtc.h>
29 #include "radeon_audio.h"
31 void r600_audio_enable(struct radeon_device
*rdev
, struct r600_audio_pin
*pin
,
33 void dce6_audio_enable(struct radeon_device
*rdev
, struct r600_audio_pin
*pin
,
35 u32
dce6_endpoint_rreg(struct radeon_device
*rdev
, u32 offset
, u32 reg
);
36 void dce6_endpoint_wreg(struct radeon_device
*rdev
,
37 u32 offset
, u32 reg
, u32 v
);
38 void dce3_2_afmt_write_sad_regs(struct drm_encoder
*encoder
,
39 struct cea_sad
*sads
, int sad_count
);
40 void evergreen_hdmi_write_sad_regs(struct drm_encoder
*encoder
,
41 struct cea_sad
*sads
, int sad_count
);
42 void dce6_afmt_write_sad_regs(struct drm_encoder
*encoder
,
43 struct cea_sad
*sads
, int sad_count
);
44 void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder
*encoder
,
45 u8
*sadb
, int sad_count
);
46 void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder
*encoder
,
47 u8
*sadb
, int sad_count
);
48 void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder
*encoder
,
49 u8
*sadb
, int sad_count
);
50 void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder
*encoder
,
51 u8
*sadb
, int sad_count
);
52 void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder
*encoder
,
53 u8
*sadb
, int sad_count
);
54 void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder
*encoder
,
55 u8
*sadb
, int sad_count
);
57 static const u32 pin_offsets
[7] =
68 static u32
radeon_audio_rreg(struct radeon_device
*rdev
, u32 offset
, u32 reg
)
73 static void radeon_audio_wreg(struct radeon_device
*rdev
, u32 offset
,
79 static struct radeon_audio_basic_funcs dce32_funcs
= {
80 .endpoint_rreg
= radeon_audio_rreg
,
81 .endpoint_wreg
= radeon_audio_wreg
,
84 static struct radeon_audio_basic_funcs dce4_funcs
= {
85 .endpoint_rreg
= radeon_audio_rreg
,
86 .endpoint_wreg
= radeon_audio_wreg
,
89 static struct radeon_audio_basic_funcs dce6_funcs
= {
90 .endpoint_rreg
= dce6_endpoint_rreg
,
91 .endpoint_wreg
= dce6_endpoint_wreg
,
94 static struct radeon_audio_funcs dce32_hdmi_funcs
= {
95 .write_sad_regs
= dce3_2_afmt_write_sad_regs
,
96 .write_speaker_allocation
= dce3_2_afmt_hdmi_write_speaker_allocation
,
99 static struct radeon_audio_funcs dce32_dp_funcs
= {
100 .write_sad_regs
= dce3_2_afmt_write_sad_regs
,
101 .write_speaker_allocation
= dce3_2_afmt_dp_write_speaker_allocation
,
104 static struct radeon_audio_funcs dce4_hdmi_funcs
= {
105 .write_sad_regs
= evergreen_hdmi_write_sad_regs
,
106 .write_speaker_allocation
= dce4_afmt_hdmi_write_speaker_allocation
,
109 static struct radeon_audio_funcs dce4_dp_funcs
= {
110 .write_sad_regs
= evergreen_hdmi_write_sad_regs
,
111 .write_speaker_allocation
= dce4_afmt_dp_write_speaker_allocation
,
114 static struct radeon_audio_funcs dce6_hdmi_funcs
= {
115 .write_sad_regs
= dce6_afmt_write_sad_regs
,
116 .write_speaker_allocation
= dce6_afmt_hdmi_write_speaker_allocation
,
119 static struct radeon_audio_funcs dce6_dp_funcs
= {
120 .write_sad_regs
= dce6_afmt_write_sad_regs
,
121 .write_speaker_allocation
= dce6_afmt_dp_write_speaker_allocation
,
124 static void radeon_audio_interface_init(struct radeon_device
*rdev
)
126 if (ASIC_IS_DCE6(rdev
)) {
127 rdev
->audio
.funcs
= &dce6_funcs
;
128 rdev
->audio
.hdmi_funcs
= &dce6_hdmi_funcs
;
129 rdev
->audio
.dp_funcs
= &dce6_dp_funcs
;
130 } else if (ASIC_IS_DCE4(rdev
)) {
131 rdev
->audio
.funcs
= &dce4_funcs
;
132 rdev
->audio
.hdmi_funcs
= &dce4_hdmi_funcs
;
133 rdev
->audio
.dp_funcs
= &dce4_dp_funcs
;
135 rdev
->audio
.funcs
= &dce32_funcs
;
136 rdev
->audio
.hdmi_funcs
= &dce32_hdmi_funcs
;
137 rdev
->audio
.dp_funcs
= &dce32_dp_funcs
;
141 static int radeon_audio_chipset_supported(struct radeon_device
*rdev
)
143 return ASIC_IS_DCE2(rdev
) && !ASIC_IS_NODCE(rdev
);
146 int radeon_audio_init(struct radeon_device
*rdev
)
150 if (!radeon_audio
|| !radeon_audio_chipset_supported(rdev
))
153 rdev
->audio
.enabled
= true;
155 if (ASIC_IS_DCE83(rdev
)) /* KB: 2 streams, 3 endpoints */
156 rdev
->audio
.num_pins
= 3;
157 else if (ASIC_IS_DCE81(rdev
)) /* KV: 4 streams, 7 endpoints */
158 rdev
->audio
.num_pins
= 7;
159 else if (ASIC_IS_DCE8(rdev
)) /* BN/HW: 6 streams, 7 endpoints */
160 rdev
->audio
.num_pins
= 7;
161 else if (ASIC_IS_DCE64(rdev
)) /* OL: 2 streams, 2 endpoints */
162 rdev
->audio
.num_pins
= 2;
163 else if (ASIC_IS_DCE61(rdev
)) /* TN: 4 streams, 6 endpoints */
164 rdev
->audio
.num_pins
= 6;
165 else if (ASIC_IS_DCE6(rdev
)) /* SI: 6 streams, 6 endpoints */
166 rdev
->audio
.num_pins
= 6;
168 rdev
->audio
.num_pins
= 1;
170 for (i
= 0; i
< rdev
->audio
.num_pins
; i
++) {
171 rdev
->audio
.pin
[i
].channels
= -1;
172 rdev
->audio
.pin
[i
].rate
= -1;
173 rdev
->audio
.pin
[i
].bits_per_sample
= -1;
174 rdev
->audio
.pin
[i
].status_bits
= 0;
175 rdev
->audio
.pin
[i
].category_code
= 0;
176 rdev
->audio
.pin
[i
].connected
= false;
177 rdev
->audio
.pin
[i
].offset
= pin_offsets
[i
];
178 rdev
->audio
.pin
[i
].id
= i
;
181 radeon_audio_interface_init(rdev
);
183 /* disable audio. it will be set up later */
184 for (i
= 0; i
< rdev
->audio
.num_pins
; i
++)
185 if (ASIC_IS_DCE6(rdev
))
186 dce6_audio_enable(rdev
, &rdev
->audio
.pin
[i
], false);
188 r600_audio_enable(rdev
, &rdev
->audio
.pin
[i
], false);
193 void radeon_audio_detect(struct drm_connector
*connector
,
194 enum drm_connector_status status
)
196 if (!connector
|| !connector
->encoder
)
199 if (status
== connector_status_connected
) {
201 struct radeon_device
*rdev
= connector
->encoder
->dev
->dev_private
;
202 struct radeon_connector
*radeon_connector
;
203 struct radeon_encoder
*radeon_encoder
=
204 to_radeon_encoder(connector
->encoder
);
206 if (!drm_detect_monitor_audio(radeon_connector_edid(connector
))) {
207 radeon_encoder
->audio
= 0;
211 radeon_connector
= to_radeon_connector(connector
);
212 sink_type
= radeon_dp_getsinktype(radeon_connector
);
214 if (connector
->connector_type
== DRM_MODE_CONNECTOR_DisplayPort
&&
215 sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
)
216 radeon_encoder
->audio
= rdev
->audio
.dp_funcs
;
218 radeon_encoder
->audio
= rdev
->audio
.hdmi_funcs
;
219 /* TODO: set up the sads, etc. and set the audio enable_mask */
221 /* TODO: reset the audio enable_mask */
225 u32
radeon_audio_endpoint_rreg(struct radeon_device
*rdev
, u32 offset
, u32 reg
)
227 if (rdev
->audio
.funcs
->endpoint_rreg
)
228 return rdev
->audio
.funcs
->endpoint_rreg(rdev
, offset
, reg
);
233 void radeon_audio_endpoint_wreg(struct radeon_device
*rdev
, u32 offset
,
236 if (rdev
->audio
.funcs
->endpoint_wreg
)
237 rdev
->audio
.funcs
->endpoint_wreg(rdev
, offset
, reg
, v
);
240 void radeon_audio_write_sad_regs(struct drm_encoder
*encoder
)
242 struct radeon_encoder
*radeon_encoder
;
243 struct drm_connector
*connector
;
244 struct radeon_connector
*radeon_connector
= NULL
;
245 struct cea_sad
*sads
;
248 list_for_each_entry(connector
,
249 &encoder
->dev
->mode_config
.connector_list
, head
) {
250 if (connector
->encoder
== encoder
) {
251 radeon_connector
= to_radeon_connector(connector
);
256 if (!radeon_connector
) {
257 DRM_ERROR("Couldn't find encoder's connector\n");
261 sad_count
= drm_edid_to_sad(radeon_connector_edid(connector
), &sads
);
262 if (sad_count
<= 0) {
263 DRM_ERROR("Couldn't read SADs: %d\n", sad_count
);
268 radeon_encoder
= to_radeon_encoder(encoder
);
270 if (radeon_encoder
->audio
&& radeon_encoder
->audio
->write_sad_regs
)
271 radeon_encoder
->audio
->write_sad_regs(encoder
, sads
, sad_count
);
276 void radeon_audio_write_speaker_allocation(struct drm_encoder
*encoder
)
278 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
279 struct drm_connector
*connector
;
280 struct radeon_connector
*radeon_connector
= NULL
;
284 list_for_each_entry(connector
,
285 &encoder
->dev
->mode_config
.connector_list
, head
) {
286 if (connector
->encoder
== encoder
) {
287 radeon_connector
= to_radeon_connector(connector
);
292 if (!radeon_connector
) {
293 DRM_ERROR("Couldn't find encoder's connector\n");
297 sad_count
= drm_edid_to_speaker_allocation(
298 radeon_connector_edid(connector
), &sadb
);
300 DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n",
305 if (radeon_encoder
->audio
&& radeon_encoder
->audio
->write_speaker_allocation
)
306 radeon_encoder
->audio
->write_speaker_allocation(encoder
, sadb
, sad_count
);