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
);
39 static const u32 pin_offsets
[7] =
50 static u32
radeon_audio_rreg(struct radeon_device
*rdev
, u32 offset
, u32 reg
)
55 static void radeon_audio_wreg(struct radeon_device
*rdev
, u32 offset
,
61 static struct radeon_audio_basic_funcs dce32_funcs
= {
62 .endpoint_rreg
= radeon_audio_rreg
,
63 .endpoint_wreg
= radeon_audio_wreg
,
66 static struct radeon_audio_basic_funcs dce4_funcs
= {
67 .endpoint_rreg
= radeon_audio_rreg
,
68 .endpoint_wreg
= radeon_audio_wreg
,
71 static struct radeon_audio_basic_funcs dce6_funcs
= {
72 .endpoint_rreg
= dce6_endpoint_rreg
,
73 .endpoint_wreg
= dce6_endpoint_wreg
,
76 static void radeon_audio_interface_init(struct radeon_device
*rdev
)
78 if (ASIC_IS_DCE6(rdev
)) {
79 rdev
->audio
.funcs
= &dce6_funcs
;
80 } else if (ASIC_IS_DCE4(rdev
)) {
81 rdev
->audio
.funcs
= &dce4_funcs
;
83 rdev
->audio
.funcs
= &dce32_funcs
;
87 static int radeon_audio_chipset_supported(struct radeon_device
*rdev
)
89 return ASIC_IS_DCE2(rdev
) && !ASIC_IS_NODCE(rdev
);
92 int radeon_audio_init(struct radeon_device
*rdev
)
96 if (!radeon_audio
|| !radeon_audio_chipset_supported(rdev
))
99 rdev
->audio
.enabled
= true;
101 if (ASIC_IS_DCE83(rdev
)) /* KB: 2 streams, 3 endpoints */
102 rdev
->audio
.num_pins
= 3;
103 else if (ASIC_IS_DCE81(rdev
)) /* KV: 4 streams, 7 endpoints */
104 rdev
->audio
.num_pins
= 7;
105 else if (ASIC_IS_DCE8(rdev
)) /* BN/HW: 6 streams, 7 endpoints */
106 rdev
->audio
.num_pins
= 7;
107 else if (ASIC_IS_DCE64(rdev
)) /* OL: 2 streams, 2 endpoints */
108 rdev
->audio
.num_pins
= 2;
109 else if (ASIC_IS_DCE61(rdev
)) /* TN: 4 streams, 6 endpoints */
110 rdev
->audio
.num_pins
= 6;
111 else if (ASIC_IS_DCE6(rdev
)) /* SI: 6 streams, 6 endpoints */
112 rdev
->audio
.num_pins
= 6;
114 rdev
->audio
.num_pins
= 1;
116 for (i
= 0; i
< rdev
->audio
.num_pins
; i
++) {
117 rdev
->audio
.pin
[i
].channels
= -1;
118 rdev
->audio
.pin
[i
].rate
= -1;
119 rdev
->audio
.pin
[i
].bits_per_sample
= -1;
120 rdev
->audio
.pin
[i
].status_bits
= 0;
121 rdev
->audio
.pin
[i
].category_code
= 0;
122 rdev
->audio
.pin
[i
].connected
= false;
123 rdev
->audio
.pin
[i
].offset
= pin_offsets
[i
];
124 rdev
->audio
.pin
[i
].id
= i
;
127 radeon_audio_interface_init(rdev
);
129 /* disable audio. it will be set up later */
130 for (i
= 0; i
< rdev
->audio
.num_pins
; i
++)
131 if (ASIC_IS_DCE6(rdev
))
132 dce6_audio_enable(rdev
, &rdev
->audio
.pin
[i
], false);
134 r600_audio_enable(rdev
, &rdev
->audio
.pin
[i
], false);
139 void radeon_audio_detect(struct drm_connector
*connector
,
140 enum drm_connector_status status
)
142 if (!connector
|| !connector
->encoder
)
145 if (status
== connector_status_connected
) {
147 struct radeon_device
*rdev
= connector
->encoder
->dev
->dev_private
;
148 struct radeon_connector
*radeon_connector
;
149 struct radeon_encoder
*radeon_encoder
=
150 to_radeon_encoder(connector
->encoder
);
152 if (!drm_detect_monitor_audio(radeon_connector_edid(connector
))) {
153 radeon_encoder
->audio
= 0;
157 radeon_connector
= to_radeon_connector(connector
);
158 sink_type
= radeon_dp_getsinktype(radeon_connector
);
160 if (connector
->connector_type
== DRM_MODE_CONNECTOR_DisplayPort
&&
161 sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
)
162 radeon_encoder
->audio
= rdev
->audio
.dp_funcs
;
164 radeon_encoder
->audio
= rdev
->audio
.hdmi_funcs
;
165 /* TODO: set up the sads, etc. and set the audio enable_mask */
167 /* TODO: reset the audio enable_mask */
171 u32
radeon_audio_endpoint_rreg(struct radeon_device
*rdev
, u32 offset
, u32 reg
)
173 if (rdev
->audio
.funcs
->endpoint_rreg
)
174 return rdev
->audio
.funcs
->endpoint_rreg(rdev
, offset
, reg
);
179 void radeon_audio_endpoint_wreg(struct radeon_device
*rdev
, u32 offset
,
182 if (rdev
->audio
.funcs
->endpoint_wreg
)
183 rdev
->audio
.funcs
->endpoint_wreg(rdev
, offset
, reg
, v
);