blob: 48d49e651a30cf94212fe2b4482178e7870ed029 [file] [log] [blame]
Slava Grigorevbfc1f972014-12-22 17:26:51 -05001/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Slava Grigorev <slava.grigorev@amd.com>
23 */
24
Slava Grigorev64424d6e2014-12-06 20:19:16 -050025#include <linux/gcd.h>
Slava Grigorevbfc1f972014-12-22 17:26:51 -050026#include <drm/drmP.h>
Slava Grigorev1a626b62014-12-01 13:49:39 -050027#include <drm/drm_crtc.h>
Slava Grigorevbfc1f972014-12-22 17:26:51 -050028#include "radeon.h"
Slava Grigorev1a626b62014-12-01 13:49:39 -050029#include "atom.h"
30#include "radeon_audio.h"
Slava Grigorevbfc1f972014-12-22 17:26:51 -050031
32void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
33 u8 enable_mask);
Slava Grigorev8bf59822014-12-03 15:29:53 -050034void dce4_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
35 u8 enable_mask);
Slava Grigorevbfc1f972014-12-22 17:26:51 -050036void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
37 u8 enable_mask);
Slava Grigorev1a626b62014-12-01 13:49:39 -050038u32 dce6_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg);
39void dce6_endpoint_wreg(struct radeon_device *rdev,
40 u32 offset, u32 reg, u32 v);
Alex Deucher070a2e62015-01-22 10:41:55 -050041void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder,
42 struct cea_sad *sads, int sad_count);
43void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
44 struct cea_sad *sads, int sad_count);
45void dce6_afmt_write_sad_regs(struct drm_encoder *encoder,
46 struct cea_sad *sads, int sad_count);
Slava Grigorev00a9d4b2014-12-01 18:02:57 -050047void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
48 u8 *sadb, int sad_count);
49void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
50 u8 *sadb, int sad_count);
51void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
52 u8 *sadb, int sad_count);
53void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
54 u8 *sadb, int sad_count);
55void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
56 u8 *sadb, int sad_count);
57void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
58 u8 *sadb, int sad_count);
Slava Grigorev87654f82014-12-02 11:20:48 -050059void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
60 struct drm_connector *connector, struct drm_display_mode *mode);
61void dce6_afmt_write_latency_fields(struct drm_encoder *encoder,
62 struct drm_connector *connector, struct drm_display_mode *mode);
Slava Grigorev3cdde022014-12-02 15:22:43 -050063struct r600_audio_pin* r600_audio_get_pin(struct radeon_device *rdev);
64struct r600_audio_pin* dce6_audio_get_pin(struct radeon_device *rdev);
Slava Grigorev88252d72014-12-02 17:27:29 -050065void dce6_afmt_select_pin(struct drm_encoder *encoder);
Slava Grigoreva85d6822014-12-05 13:38:31 -050066void r600_hdmi_audio_set_dto(struct radeon_device *rdev,
67 struct radeon_crtc *crtc, unsigned int clock);
68void dce3_2_audio_set_dto(struct radeon_device *rdev,
69 struct radeon_crtc *crtc, unsigned int clock);
70void dce4_hdmi_audio_set_dto(struct radeon_device *rdev,
71 struct radeon_crtc *crtc, unsigned int clock);
72void dce4_dp_audio_set_dto(struct radeon_device *rdev,
73 struct radeon_crtc *crtc, unsigned int clock);
74void dce6_hdmi_audio_set_dto(struct radeon_device *rdev,
75 struct radeon_crtc *crtc, unsigned int clock);
76void dce6_dp_audio_set_dto(struct radeon_device *rdev,
77 struct radeon_crtc *crtc, unsigned int clock);
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -050078void r600_set_avi_packet(struct radeon_device *rdev, u32 offset,
Slava Grigorev96ea7af2014-12-05 17:59:56 -050079 unsigned char *buffer, size_t size);
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -050080void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset,
Slava Grigorev96ea7af2014-12-05 17:59:56 -050081 unsigned char *buffer, size_t size);
Slava Grigorev64424d6e2014-12-06 20:19:16 -050082void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset,
83 const struct radeon_hdmi_acr *acr);
84void dce3_2_hdmi_update_acr(struct drm_encoder *encoder, long offset,
85 const struct radeon_hdmi_acr *acr);
86void evergreen_hdmi_update_acr(struct drm_encoder *encoder, long offset,
87 const struct radeon_hdmi_acr *acr);
Alex Deucher930a9782015-01-20 19:20:52 -050088void r600_set_vbi_packet(struct drm_encoder *encoder, u32 offset);
89void dce4_set_vbi_packet(struct drm_encoder *encoder, u32 offset);
Slava Grigorevbe273e582014-12-08 16:25:37 -050090void dce4_hdmi_set_color_depth(struct drm_encoder *encoder,
91 u32 offset, int bpc);
Slava Grigorev1852c9a2014-12-09 16:44:18 -050092void r600_set_audio_packet(struct drm_encoder *encoder, u32 offset);
93void dce3_2_set_audio_packet(struct drm_encoder *encoder, u32 offset);
94void dce4_set_audio_packet(struct drm_encoder *encoder, u32 offset);
Slava Grigorev3be2e7d2014-12-09 17:17:35 -050095void r600_set_mute(struct drm_encoder *encoder, u32 offset, bool mute);
96void dce3_2_set_mute(struct drm_encoder *encoder, u32 offset, bool mute);
97void dce4_set_mute(struct drm_encoder *encoder, u32 offset, bool mute);
Slava Grigorev6e723762014-12-10 10:43:51 -050098static void radeon_audio_hdmi_mode_set(struct drm_encoder *encoder,
99 struct drm_display_mode *mode);
Slava Grigoreve55bca22014-12-12 17:01:42 -0500100static void radeon_audio_dp_mode_set(struct drm_encoder *encoder,
101 struct drm_display_mode *mode);
Slava Grigorev6f945692014-12-10 14:52:43 -0500102void r600_hdmi_enable(struct drm_encoder *encoder, bool enable);
103void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable);
Alex Deucheradd7d752015-02-27 10:04:11 -0500104void evergreen_dp_enable(struct drm_encoder *encoder, bool enable);
105void dce6_dp_enable(struct drm_encoder *encoder, bool enable);
Slava Grigorevbfc1f972014-12-22 17:26:51 -0500106
107static const u32 pin_offsets[7] =
108{
109 (0x5e00 - 0x5e00),
110 (0x5e18 - 0x5e00),
111 (0x5e30 - 0x5e00),
112 (0x5e48 - 0x5e00),
113 (0x5e60 - 0x5e00),
114 (0x5e78 - 0x5e00),
115 (0x5e90 - 0x5e00),
116};
117
Slava Grigorev1a626b62014-12-01 13:49:39 -0500118static u32 radeon_audio_rreg(struct radeon_device *rdev, u32 offset, u32 reg)
119{
120 return RREG32(reg);
121}
122
123static void radeon_audio_wreg(struct radeon_device *rdev, u32 offset,
124 u32 reg, u32 v)
125{
126 WREG32(reg, v);
127}
128
Slava Grigoreva85d6822014-12-05 13:38:31 -0500129static struct radeon_audio_basic_funcs r600_funcs = {
130 .endpoint_rreg = radeon_audio_rreg,
131 .endpoint_wreg = radeon_audio_wreg,
132 .enable = r600_audio_enable,
133};
134
Slava Grigorev1a626b62014-12-01 13:49:39 -0500135static struct radeon_audio_basic_funcs dce32_funcs = {
136 .endpoint_rreg = radeon_audio_rreg,
137 .endpoint_wreg = radeon_audio_wreg,
Slava Grigorev8bf59822014-12-03 15:29:53 -0500138 .enable = r600_audio_enable,
Slava Grigorev1a626b62014-12-01 13:49:39 -0500139};
140
141static struct radeon_audio_basic_funcs dce4_funcs = {
142 .endpoint_rreg = radeon_audio_rreg,
143 .endpoint_wreg = radeon_audio_wreg,
Slava Grigorev8bf59822014-12-03 15:29:53 -0500144 .enable = dce4_audio_enable,
Slava Grigorev1a626b62014-12-01 13:49:39 -0500145};
146
147static struct radeon_audio_basic_funcs dce6_funcs = {
148 .endpoint_rreg = dce6_endpoint_rreg,
149 .endpoint_wreg = dce6_endpoint_wreg,
Slava Grigorev8bf59822014-12-03 15:29:53 -0500150 .enable = dce6_audio_enable,
Slava Grigorev1a626b62014-12-01 13:49:39 -0500151};
152
Slava Grigoreva85d6822014-12-05 13:38:31 -0500153static struct radeon_audio_funcs r600_hdmi_funcs = {
154 .get_pin = r600_audio_get_pin,
155 .set_dto = r600_hdmi_audio_set_dto,
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500156 .update_acr = r600_hdmi_update_acr,
Alex Deucher930a9782015-01-20 19:20:52 -0500157 .set_vbi_packet = r600_set_vbi_packet,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500158 .set_avi_packet = r600_set_avi_packet,
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500159 .set_audio_packet = r600_set_audio_packet,
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500160 .set_mute = r600_set_mute,
Slava Grigorev6e723762014-12-10 10:43:51 -0500161 .mode_set = radeon_audio_hdmi_mode_set,
Slava Grigorev6f945692014-12-10 14:52:43 -0500162 .dpms = r600_hdmi_enable,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500163};
164
Alex Deucher070a2e62015-01-22 10:41:55 -0500165static struct radeon_audio_funcs dce32_hdmi_funcs = {
Slava Grigorev3cdde022014-12-02 15:22:43 -0500166 .get_pin = r600_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500167 .write_sad_regs = dce3_2_afmt_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500168 .write_speaker_allocation = dce3_2_afmt_hdmi_write_speaker_allocation,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500169 .set_dto = dce3_2_audio_set_dto,
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500170 .update_acr = dce3_2_hdmi_update_acr,
Alex Deucher930a9782015-01-20 19:20:52 -0500171 .set_vbi_packet = r600_set_vbi_packet,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500172 .set_avi_packet = r600_set_avi_packet,
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500173 .set_audio_packet = dce3_2_set_audio_packet,
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500174 .set_mute = dce3_2_set_mute,
Slava Grigorev6e723762014-12-10 10:43:51 -0500175 .mode_set = radeon_audio_hdmi_mode_set,
Slava Grigorev6f945692014-12-10 14:52:43 -0500176 .dpms = r600_hdmi_enable,
Alex Deucher070a2e62015-01-22 10:41:55 -0500177};
178
179static struct radeon_audio_funcs dce32_dp_funcs = {
Slava Grigorev3cdde022014-12-02 15:22:43 -0500180 .get_pin = r600_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500181 .write_sad_regs = dce3_2_afmt_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500182 .write_speaker_allocation = dce3_2_afmt_dp_write_speaker_allocation,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500183 .set_dto = dce3_2_audio_set_dto,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500184 .set_avi_packet = r600_set_avi_packet,
Slava Grigoreve55bca22014-12-12 17:01:42 -0500185 .set_audio_packet = dce3_2_set_audio_packet,
Alex Deucher070a2e62015-01-22 10:41:55 -0500186};
187
188static struct radeon_audio_funcs dce4_hdmi_funcs = {
Slava Grigorev3cdde022014-12-02 15:22:43 -0500189 .get_pin = r600_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500190 .write_sad_regs = evergreen_hdmi_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500191 .write_speaker_allocation = dce4_afmt_hdmi_write_speaker_allocation,
Slava Grigorev87654f82014-12-02 11:20:48 -0500192 .write_latency_fields = dce4_afmt_write_latency_fields,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500193 .set_dto = dce4_hdmi_audio_set_dto,
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500194 .update_acr = evergreen_hdmi_update_acr,
Alex Deucher930a9782015-01-20 19:20:52 -0500195 .set_vbi_packet = dce4_set_vbi_packet,
Slava Grigorevbe273e582014-12-08 16:25:37 -0500196 .set_color_depth = dce4_hdmi_set_color_depth,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500197 .set_avi_packet = evergreen_set_avi_packet,
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500198 .set_audio_packet = dce4_set_audio_packet,
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500199 .set_mute = dce4_set_mute,
Slava Grigorev6e723762014-12-10 10:43:51 -0500200 .mode_set = radeon_audio_hdmi_mode_set,
Slava Grigorev6f945692014-12-10 14:52:43 -0500201 .dpms = evergreen_hdmi_enable,
Alex Deucher070a2e62015-01-22 10:41:55 -0500202};
203
204static struct radeon_audio_funcs dce4_dp_funcs = {
Slava Grigorev3cdde022014-12-02 15:22:43 -0500205 .get_pin = r600_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500206 .write_sad_regs = evergreen_hdmi_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500207 .write_speaker_allocation = dce4_afmt_dp_write_speaker_allocation,
Slava Grigorev87654f82014-12-02 11:20:48 -0500208 .write_latency_fields = dce4_afmt_write_latency_fields,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500209 .set_dto = dce4_dp_audio_set_dto,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500210 .set_avi_packet = evergreen_set_avi_packet,
Slava Grigoreve55bca22014-12-12 17:01:42 -0500211 .set_audio_packet = dce4_set_audio_packet,
212 .mode_set = radeon_audio_dp_mode_set,
Alex Deucheradd7d752015-02-27 10:04:11 -0500213 .dpms = evergreen_dp_enable,
Alex Deucher070a2e62015-01-22 10:41:55 -0500214};
215
216static struct radeon_audio_funcs dce6_hdmi_funcs = {
Slava Grigorev88252d72014-12-02 17:27:29 -0500217 .select_pin = dce6_afmt_select_pin,
Slava Grigorev3cdde022014-12-02 15:22:43 -0500218 .get_pin = dce6_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500219 .write_sad_regs = dce6_afmt_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500220 .write_speaker_allocation = dce6_afmt_hdmi_write_speaker_allocation,
Slava Grigorev87654f82014-12-02 11:20:48 -0500221 .write_latency_fields = dce6_afmt_write_latency_fields,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500222 .set_dto = dce6_hdmi_audio_set_dto,
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500223 .update_acr = evergreen_hdmi_update_acr,
Alex Deucher930a9782015-01-20 19:20:52 -0500224 .set_vbi_packet = dce4_set_vbi_packet,
Slava Grigorevbe273e582014-12-08 16:25:37 -0500225 .set_color_depth = dce4_hdmi_set_color_depth,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500226 .set_avi_packet = evergreen_set_avi_packet,
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500227 .set_audio_packet = dce4_set_audio_packet,
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500228 .set_mute = dce4_set_mute,
Slava Grigorev6e723762014-12-10 10:43:51 -0500229 .mode_set = radeon_audio_hdmi_mode_set,
Slava Grigorev6f945692014-12-10 14:52:43 -0500230 .dpms = evergreen_hdmi_enable,
Alex Deucher070a2e62015-01-22 10:41:55 -0500231};
232
233static struct radeon_audio_funcs dce6_dp_funcs = {
Slava Grigorev88252d72014-12-02 17:27:29 -0500234 .select_pin = dce6_afmt_select_pin,
Slava Grigorev3cdde022014-12-02 15:22:43 -0500235 .get_pin = dce6_audio_get_pin,
Alex Deucher070a2e62015-01-22 10:41:55 -0500236 .write_sad_regs = dce6_afmt_write_sad_regs,
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500237 .write_speaker_allocation = dce6_afmt_dp_write_speaker_allocation,
Slava Grigorev87654f82014-12-02 11:20:48 -0500238 .write_latency_fields = dce6_afmt_write_latency_fields,
Slava Grigoreva85d6822014-12-05 13:38:31 -0500239 .set_dto = dce6_dp_audio_set_dto,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500240 .set_avi_packet = evergreen_set_avi_packet,
Slava Grigoreve55bca22014-12-12 17:01:42 -0500241 .set_audio_packet = dce4_set_audio_packet,
242 .mode_set = radeon_audio_dp_mode_set,
Alex Deucheradd7d752015-02-27 10:04:11 -0500243 .dpms = dce6_dp_enable,
Alex Deucher070a2e62015-01-22 10:41:55 -0500244};
245
Slava Grigorev1a626b62014-12-01 13:49:39 -0500246static void radeon_audio_interface_init(struct radeon_device *rdev)
247{
248 if (ASIC_IS_DCE6(rdev)) {
249 rdev->audio.funcs = &dce6_funcs;
Alex Deucher070a2e62015-01-22 10:41:55 -0500250 rdev->audio.hdmi_funcs = &dce6_hdmi_funcs;
251 rdev->audio.dp_funcs = &dce6_dp_funcs;
Slava Grigorev1a626b62014-12-01 13:49:39 -0500252 } else if (ASIC_IS_DCE4(rdev)) {
253 rdev->audio.funcs = &dce4_funcs;
Alex Deucher070a2e62015-01-22 10:41:55 -0500254 rdev->audio.hdmi_funcs = &dce4_hdmi_funcs;
255 rdev->audio.dp_funcs = &dce4_dp_funcs;
Slava Grigoreva85d6822014-12-05 13:38:31 -0500256 } else if (ASIC_IS_DCE32(rdev)) {
Slava Grigorev1a626b62014-12-01 13:49:39 -0500257 rdev->audio.funcs = &dce32_funcs;
Alex Deucher070a2e62015-01-22 10:41:55 -0500258 rdev->audio.hdmi_funcs = &dce32_hdmi_funcs;
259 rdev->audio.dp_funcs = &dce32_dp_funcs;
Slava Grigoreva85d6822014-12-05 13:38:31 -0500260 } else {
261 rdev->audio.funcs = &r600_funcs;
262 rdev->audio.hdmi_funcs = &r600_hdmi_funcs;
263 rdev->audio.dp_funcs = 0;
Slava Grigorev1a626b62014-12-01 13:49:39 -0500264 }
265}
266
Slava Grigorevbfc1f972014-12-22 17:26:51 -0500267static int radeon_audio_chipset_supported(struct radeon_device *rdev)
268{
269 return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev);
270}
271
272int radeon_audio_init(struct radeon_device *rdev)
273{
274 int i;
275
276 if (!radeon_audio || !radeon_audio_chipset_supported(rdev))
277 return 0;
278
279 rdev->audio.enabled = true;
280
281 if (ASIC_IS_DCE83(rdev)) /* KB: 2 streams, 3 endpoints */
282 rdev->audio.num_pins = 3;
283 else if (ASIC_IS_DCE81(rdev)) /* KV: 4 streams, 7 endpoints */
284 rdev->audio.num_pins = 7;
285 else if (ASIC_IS_DCE8(rdev)) /* BN/HW: 6 streams, 7 endpoints */
286 rdev->audio.num_pins = 7;
287 else if (ASIC_IS_DCE64(rdev)) /* OL: 2 streams, 2 endpoints */
288 rdev->audio.num_pins = 2;
289 else if (ASIC_IS_DCE61(rdev)) /* TN: 4 streams, 6 endpoints */
290 rdev->audio.num_pins = 6;
291 else if (ASIC_IS_DCE6(rdev)) /* SI: 6 streams, 6 endpoints */
292 rdev->audio.num_pins = 6;
293 else
294 rdev->audio.num_pins = 1;
295
296 for (i = 0; i < rdev->audio.num_pins; i++) {
297 rdev->audio.pin[i].channels = -1;
298 rdev->audio.pin[i].rate = -1;
299 rdev->audio.pin[i].bits_per_sample = -1;
300 rdev->audio.pin[i].status_bits = 0;
301 rdev->audio.pin[i].category_code = 0;
302 rdev->audio.pin[i].connected = false;
303 rdev->audio.pin[i].offset = pin_offsets[i];
304 rdev->audio.pin[i].id = i;
Slava Grigorev1a626b62014-12-01 13:49:39 -0500305 }
306
307 radeon_audio_interface_init(rdev);
308
309 /* disable audio. it will be set up later */
310 for (i = 0; i < rdev->audio.num_pins; i++)
Slava Grigorev8bf59822014-12-03 15:29:53 -0500311 radeon_audio_enable(rdev, &rdev->audio.pin[i], false);
Slava Grigorevbfc1f972014-12-22 17:26:51 -0500312
313 return 0;
314}
Slava Grigorev1a626b62014-12-01 13:49:39 -0500315
Slava Grigorev1a626b62014-12-01 13:49:39 -0500316u32 radeon_audio_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg)
317{
318 if (rdev->audio.funcs->endpoint_rreg)
319 return rdev->audio.funcs->endpoint_rreg(rdev, offset, reg);
320
321 return 0;
322}
323
324void radeon_audio_endpoint_wreg(struct radeon_device *rdev, u32 offset,
325 u32 reg, u32 v)
326{
327 if (rdev->audio.funcs->endpoint_wreg)
328 rdev->audio.funcs->endpoint_wreg(rdev, offset, reg, v);
329}
Alex Deucher070a2e62015-01-22 10:41:55 -0500330
Slava Grigorev6e723762014-12-10 10:43:51 -0500331static void radeon_audio_write_sad_regs(struct drm_encoder *encoder)
Alex Deucher070a2e62015-01-22 10:41:55 -0500332{
333 struct radeon_encoder *radeon_encoder;
334 struct drm_connector *connector;
335 struct radeon_connector *radeon_connector = NULL;
336 struct cea_sad *sads;
337 int sad_count;
338
339 list_for_each_entry(connector,
340 &encoder->dev->mode_config.connector_list, head) {
341 if (connector->encoder == encoder) {
342 radeon_connector = to_radeon_connector(connector);
343 break;
344 }
345 }
346
347 if (!radeon_connector) {
348 DRM_ERROR("Couldn't find encoder's connector\n");
349 return;
350 }
351
352 sad_count = drm_edid_to_sad(radeon_connector_edid(connector), &sads);
353 if (sad_count <= 0) {
354 DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
355 return;
356 }
357 BUG_ON(!sads);
358
359 radeon_encoder = to_radeon_encoder(encoder);
360
361 if (radeon_encoder->audio && radeon_encoder->audio->write_sad_regs)
362 radeon_encoder->audio->write_sad_regs(encoder, sads, sad_count);
363
364 kfree(sads);
365}
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500366
Slava Grigorev6e723762014-12-10 10:43:51 -0500367static void radeon_audio_write_speaker_allocation(struct drm_encoder *encoder)
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500368{
369 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherf4c6c082015-01-13 12:41:40 -0500370 struct drm_connector *connector;
371 struct radeon_connector *radeon_connector = NULL;
372 u8 *sadb = NULL;
373 int sad_count;
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500374
Alex Deucherf4c6c082015-01-13 12:41:40 -0500375 list_for_each_entry(connector,
376 &encoder->dev->mode_config.connector_list, head) {
377 if (connector->encoder == encoder) {
378 radeon_connector = to_radeon_connector(connector);
379 break;
380 }
381 }
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500382
Alex Deucherf4c6c082015-01-13 12:41:40 -0500383 if (!radeon_connector) {
384 DRM_ERROR("Couldn't find encoder's connector\n");
385 return;
386 }
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500387
Alex Deucherf4c6c082015-01-13 12:41:40 -0500388 sad_count = drm_edid_to_speaker_allocation(
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500389 radeon_connector_edid(connector), &sadb);
Alex Deucherf4c6c082015-01-13 12:41:40 -0500390 if (sad_count < 0) {
391 DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n",
392 sad_count);
393 sad_count = 0;
394 }
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500395
396 if (radeon_encoder->audio && radeon_encoder->audio->write_speaker_allocation)
397 radeon_encoder->audio->write_speaker_allocation(encoder, sadb, sad_count);
398
Alex Deucherf4c6c082015-01-13 12:41:40 -0500399 kfree(sadb);
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500400}
Slava Grigorev87654f82014-12-02 11:20:48 -0500401
Slava Grigorev6e723762014-12-10 10:43:51 -0500402static void radeon_audio_write_latency_fields(struct drm_encoder *encoder,
Slava Grigorev87654f82014-12-02 11:20:48 -0500403 struct drm_display_mode *mode)
404{
405 struct radeon_encoder *radeon_encoder;
406 struct drm_connector *connector;
407 struct radeon_connector *radeon_connector = 0;
408
409 list_for_each_entry(connector,
410 &encoder->dev->mode_config.connector_list, head) {
411 if (connector->encoder == encoder) {
412 radeon_connector = to_radeon_connector(connector);
413 break;
414 }
415 }
416
417 if (!radeon_connector) {
418 DRM_ERROR("Couldn't find encoder's connector\n");
419 return;
420 }
421
422 radeon_encoder = to_radeon_encoder(encoder);
423
424 if (radeon_encoder->audio && radeon_encoder->audio->write_latency_fields)
425 radeon_encoder->audio->write_latency_fields(encoder, connector, mode);
426}
Slava Grigorev3cdde022014-12-02 15:22:43 -0500427
428struct r600_audio_pin* radeon_audio_get_pin(struct drm_encoder *encoder)
429{
430 struct radeon_device *rdev = encoder->dev->dev_private;
431 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
432
433 if (radeon_encoder->audio && radeon_encoder->audio->get_pin)
434 return radeon_encoder->audio->get_pin(rdev);
435
436 return NULL;
437}
Slava Grigorev88252d72014-12-02 17:27:29 -0500438
Slava Grigorev6e723762014-12-10 10:43:51 -0500439static void radeon_audio_select_pin(struct drm_encoder *encoder)
Slava Grigorev88252d72014-12-02 17:27:29 -0500440{
441 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
442
443 if (radeon_encoder->audio && radeon_encoder->audio->select_pin)
444 radeon_encoder->audio->select_pin(encoder);
445}
Slava Grigorev8bf59822014-12-03 15:29:53 -0500446
447void radeon_audio_enable(struct radeon_device *rdev,
448 struct r600_audio_pin *pin, u8 enable_mask)
449{
450 if (rdev->audio.funcs->enable)
451 rdev->audio.funcs->enable(rdev, pin, enable_mask);
452}
Slava Grigorev7991d662014-12-03 17:07:01 -0500453
Slava Grigorevccd4be72014-12-11 13:11:29 -0500454void radeon_audio_detect(struct drm_connector *connector,
Alex Deucherd3c34d22015-02-27 10:36:39 -0500455 enum drm_connector_status status)
Slava Grigorevccd4be72014-12-11 13:11:29 -0500456{
457 struct radeon_device *rdev;
458 struct radeon_encoder *radeon_encoder;
459 struct radeon_encoder_atom_dig *dig;
460
461 if (!connector || !connector->encoder)
462 return;
463
464 rdev = connector->encoder->dev->dev_private;
465 radeon_encoder = to_radeon_encoder(connector->encoder);
466 dig = radeon_encoder->enc_priv;
467
468 if (status == connector_status_connected) {
469 struct radeon_connector *radeon_connector;
470 int sink_type;
471
472 if (!drm_detect_monitor_audio(radeon_connector_edid(connector))) {
Alex Deucher308de412015-01-14 17:20:10 -0500473 radeon_encoder->audio = NULL;
Slava Grigorevccd4be72014-12-11 13:11:29 -0500474 return;
475 }
476
477 radeon_connector = to_radeon_connector(connector);
478 sink_type = radeon_dp_getsinktype(radeon_connector);
479
480 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort &&
481 sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
482 radeon_encoder->audio = rdev->audio.dp_funcs;
483 else
484 radeon_encoder->audio = rdev->audio.hdmi_funcs;
485
Alex Deucherd3c34d22015-02-27 10:36:39 -0500486 dig->afmt->pin = radeon_audio_get_pin(connector->encoder);
Slava Grigorevccd4be72014-12-11 13:11:29 -0500487 radeon_audio_enable(rdev, dig->afmt->pin, 0xf);
488 } else {
489 radeon_audio_enable(rdev, dig->afmt->pin, 0);
Alex Deucherd3c34d22015-02-27 10:36:39 -0500490 dig->afmt->pin = NULL;
Slava Grigorevccd4be72014-12-11 13:11:29 -0500491 }
492}
493
Slava Grigorev7991d662014-12-03 17:07:01 -0500494void radeon_audio_fini(struct radeon_device *rdev)
495{
496 int i;
497
498 if (!rdev->audio.enabled)
499 return;
500
501 for (i = 0; i < rdev->audio.num_pins; i++)
502 radeon_audio_enable(rdev, &rdev->audio.pin[i], false);
503
504 rdev->audio.enabled = false;
505}
Slava Grigoreva85d6822014-12-05 13:38:31 -0500506
Slava Grigorev6e723762014-12-10 10:43:51 -0500507static void radeon_audio_set_dto(struct drm_encoder *encoder, unsigned int clock)
Slava Grigoreva85d6822014-12-05 13:38:31 -0500508{
509 struct radeon_device *rdev = encoder->dev->dev_private;
510 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
511 struct radeon_crtc *crtc = to_radeon_crtc(encoder->crtc);
512
513 if (radeon_encoder->audio && radeon_encoder->audio->set_dto)
514 radeon_encoder->audio->set_dto(rdev, crtc, clock);
515}
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500516
Slava Grigorev6e723762014-12-10 10:43:51 -0500517static int radeon_audio_set_avi_packet(struct drm_encoder *encoder,
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500518 struct drm_display_mode *mode)
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500519{
Alex Deucherf4c6c082015-01-13 12:41:40 -0500520 struct radeon_device *rdev = encoder->dev->dev_private;
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500521 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
522 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deuchera1dcc272015-02-23 17:14:47 -0500523 struct drm_connector *connector;
524 struct radeon_connector *radeon_connector = NULL;
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500525 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
526 struct hdmi_avi_infoframe frame;
527 int err;
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500528
Alex Deuchera1dcc272015-02-23 17:14:47 -0500529 list_for_each_entry(connector,
530 &encoder->dev->mode_config.connector_list, head) {
531 if (connector->encoder == encoder) {
532 radeon_connector = to_radeon_connector(connector);
533 break;
534 }
535 }
536
537 if (!radeon_connector) {
538 DRM_ERROR("Couldn't find encoder's connector\n");
539 return -ENOENT;
540 }
541
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500542 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
543 if (err < 0) {
544 DRM_ERROR("failed to setup AVI infoframe: %d\n", err);
545 return err;
546 }
547
Alex Deuchera1dcc272015-02-23 17:14:47 -0500548 if (drm_rgb_quant_range_selectable(radeon_connector_edid(connector))) {
549 if (radeon_encoder->output_csc == RADEON_OUTPUT_CSC_TVRGB)
550 frame.quantization_range = HDMI_QUANTIZATION_RANGE_LIMITED;
551 else
552 frame.quantization_range = HDMI_QUANTIZATION_RANGE_FULL;
553 } else {
554 frame.quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
555 }
556
Slava Grigorevbaa7d8e2014-12-08 18:28:33 -0500557 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
558 if (err < 0) {
559 DRM_ERROR("failed to pack AVI infoframe: %d\n", err);
560 return err;
561 }
562
563 if (dig && dig->afmt &&
564 radeon_encoder->audio && radeon_encoder->audio->set_avi_packet)
565 radeon_encoder->audio->set_avi_packet(rdev, dig->afmt->offset,
566 buffer, sizeof(buffer));
567
568 return 0;
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500569}
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500570
571/*
572 * calculate CTS and N values if they are not found in the table
573 */
574static void radeon_audio_calc_cts(unsigned int clock, int *CTS, int *N, int freq)
575{
576 int n, cts;
577 unsigned long div, mul;
578
579 /* Safe, but overly large values */
580 n = 128 * freq;
581 cts = clock * 1000;
582
583 /* Smallest valid fraction */
584 div = gcd(n, cts);
585
586 n /= div;
587 cts /= div;
588
589 /*
590 * The optimal N is 128*freq/1000. Calculate the closest larger
591 * value that doesn't truncate any bits.
592 */
593 mul = ((128*freq/1000) + (n-1))/n;
594
595 n *= mul;
596 cts *= mul;
597
598 /* Check that we are in spec (not always possible) */
599 if (n < (128*freq/1500))
600 printk(KERN_WARNING "Calculated ACR N value is too small. You may experience audio problems.\n");
601 if (n > (128*freq/300))
602 printk(KERN_WARNING "Calculated ACR N value is too large. You may experience audio problems.\n");
603
604 *N = n;
605 *CTS = cts;
606
607 DRM_DEBUG("Calculated ACR timing N=%d CTS=%d for frequency %d\n",
608 *N, *CTS, freq);
609}
610
611static const struct radeon_hdmi_acr* radeon_audio_acr(unsigned int clock)
612{
613 static struct radeon_hdmi_acr res;
614 u8 i;
615
616 static const struct radeon_hdmi_acr hdmi_predefined_acr[] = {
617 /* 32kHz 44.1kHz 48kHz */
618 /* Clock N CTS N CTS N CTS */
619 { 25175, 4096, 25175, 28224, 125875, 6144, 25175 }, /* 25,20/1.001 MHz */
620 { 25200, 4096, 25200, 6272, 28000, 6144, 25200 }, /* 25.20 MHz */
621 { 27000, 4096, 27000, 6272, 30000, 6144, 27000 }, /* 27.00 MHz */
622 { 27027, 4096, 27027, 6272, 30030, 6144, 27027 }, /* 27.00*1.001 MHz */
623 { 54000, 4096, 54000, 6272, 60000, 6144, 54000 }, /* 54.00 MHz */
624 { 54054, 4096, 54054, 6272, 60060, 6144, 54054 }, /* 54.00*1.001 MHz */
625 { 74176, 4096, 74176, 5733, 75335, 6144, 74176 }, /* 74.25/1.001 MHz */
626 { 74250, 4096, 74250, 6272, 82500, 6144, 74250 }, /* 74.25 MHz */
627 { 148352, 4096, 148352, 5733, 150670, 6144, 148352 }, /* 148.50/1.001 MHz */
628 { 148500, 4096, 148500, 6272, 165000, 6144, 148500 }, /* 148.50 MHz */
629 };
630
631 /* Precalculated values for common clocks */
632 for (i = 0; i < ARRAY_SIZE(hdmi_predefined_acr); i++)
633 if (hdmi_predefined_acr[i].clock == clock)
634 return &hdmi_predefined_acr[i];
635
636 /* And odd clocks get manually calculated */
637 radeon_audio_calc_cts(clock, &res.cts_32khz, &res.n_32khz, 32000);
638 radeon_audio_calc_cts(clock, &res.cts_44_1khz, &res.n_44_1khz, 44100);
639 radeon_audio_calc_cts(clock, &res.cts_48khz, &res.n_48khz, 48000);
640
641 return &res;
642}
643
644/*
645 * update the N and CTS parameters for a given pixel clock rate
646 */
Slava Grigorev6e723762014-12-10 10:43:51 -0500647static void radeon_audio_update_acr(struct drm_encoder *encoder, unsigned int clock)
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500648{
Alex Deucherf4c6c082015-01-13 12:41:40 -0500649 const struct radeon_hdmi_acr *acr = radeon_audio_acr(clock);
650 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
651 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Slava Grigorev64424d6e2014-12-06 20:19:16 -0500652
653 if (!dig || !dig->afmt)
654 return;
655
656 if (radeon_encoder->audio && radeon_encoder->audio->update_acr)
657 radeon_encoder->audio->update_acr(encoder, dig->afmt->offset, acr);
658}
Alex Deucher930a9782015-01-20 19:20:52 -0500659
Slava Grigorev6e723762014-12-10 10:43:51 -0500660static void radeon_audio_set_vbi_packet(struct drm_encoder *encoder)
Alex Deucher930a9782015-01-20 19:20:52 -0500661{
Alex Deucherf4c6c082015-01-13 12:41:40 -0500662 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
663 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher930a9782015-01-20 19:20:52 -0500664
665 if (!dig || !dig->afmt)
666 return;
667
668 if (radeon_encoder->audio && radeon_encoder->audio->set_vbi_packet)
669 radeon_encoder->audio->set_vbi_packet(encoder, dig->afmt->offset);
670}
Slava Grigorevbe273e582014-12-08 16:25:37 -0500671
Slava Grigorev6e723762014-12-10 10:43:51 -0500672static void radeon_hdmi_set_color_depth(struct drm_encoder *encoder)
Slava Grigorevbe273e582014-12-08 16:25:37 -0500673{
674 int bpc = 8;
675 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
676 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
677
678 if (!dig || !dig->afmt)
679 return;
680
681 if (encoder->crtc) {
682 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
683 bpc = radeon_crtc->bpc;
684 }
685
686 if (radeon_encoder->audio && radeon_encoder->audio->set_color_depth)
687 radeon_encoder->audio->set_color_depth(encoder, dig->afmt->offset, bpc);
688}
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500689
Slava Grigorev6e723762014-12-10 10:43:51 -0500690static void radeon_audio_set_audio_packet(struct drm_encoder *encoder)
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500691{
Alex Deucherf4c6c082015-01-13 12:41:40 -0500692 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
693 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Slava Grigorev1852c9a2014-12-09 16:44:18 -0500694
695 if (!dig || !dig->afmt)
696 return;
697
698 if (radeon_encoder->audio && radeon_encoder->audio->set_audio_packet)
699 radeon_encoder->audio->set_audio_packet(encoder, dig->afmt->offset);
700}
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500701
Slava Grigorev6e723762014-12-10 10:43:51 -0500702static void radeon_audio_set_mute(struct drm_encoder *encoder, bool mute)
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500703{
Alex Deucherf4c6c082015-01-13 12:41:40 -0500704 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
705 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Slava Grigorev3be2e7d2014-12-09 17:17:35 -0500706
707 if (!dig || !dig->afmt)
708 return;
709
710 if (radeon_encoder->audio && radeon_encoder->audio->set_mute)
711 radeon_encoder->audio->set_mute(encoder, dig->afmt->offset, mute);
712}
Slava Grigorev6e723762014-12-10 10:43:51 -0500713
714/*
715 * update the info frames with the data from the current display mode
716 */
717static void radeon_audio_hdmi_mode_set(struct drm_encoder *encoder,
Alex Deucher3ed7cee2015-02-27 10:42:21 -0500718 struct drm_display_mode *mode)
Slava Grigorev6e723762014-12-10 10:43:51 -0500719{
Slava Grigorev6e723762014-12-10 10:43:51 -0500720 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
721 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
722
723 if (!dig || !dig->afmt)
724 return;
725
Alex Deucher88af3392015-02-27 10:38:40 -0500726 radeon_audio_set_mute(encoder, true);
Slava Grigorev6e723762014-12-10 10:43:51 -0500727
Alex Deucherb20932d2015-02-27 10:51:40 -0500728 radeon_audio_write_speaker_allocation(encoder);
729 radeon_audio_write_sad_regs(encoder);
730 radeon_audio_write_latency_fields(encoder, mode);
Slava Grigorev6e723762014-12-10 10:43:51 -0500731 radeon_audio_set_dto(encoder, mode->clock);
732 radeon_audio_set_vbi_packet(encoder);
733 radeon_hdmi_set_color_depth(encoder);
Slava Grigorev6e723762014-12-10 10:43:51 -0500734 radeon_audio_update_acr(encoder, mode->clock);
Slava Grigorev6e723762014-12-10 10:43:51 -0500735 radeon_audio_set_audio_packet(encoder);
736 radeon_audio_select_pin(encoder);
Slava Grigorev6e723762014-12-10 10:43:51 -0500737
738 if (radeon_audio_set_avi_packet(encoder, mode) < 0)
739 return;
740
Alex Deucher88af3392015-02-27 10:38:40 -0500741 radeon_audio_set_mute(encoder, false);
Slava Grigorev6e723762014-12-10 10:43:51 -0500742}
743
Slava Grigoreve55bca22014-12-12 17:01:42 -0500744static void radeon_audio_dp_mode_set(struct drm_encoder *encoder,
745 struct drm_display_mode *mode)
746{
747 struct drm_device *dev = encoder->dev;
748 struct radeon_device *rdev = dev->dev_private;
749 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
750 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucheraeefd072015-02-27 14:43:47 -0500751 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
752 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
753 struct radeon_connector_atom_dig *dig_connector =
754 radeon_connector->con_priv;
Slava Grigoreve55bca22014-12-12 17:01:42 -0500755
756 if (!dig || !dig->afmt)
757 return;
758
Alex Deucherb20932d2015-02-27 10:51:40 -0500759 radeon_audio_write_speaker_allocation(encoder);
760 radeon_audio_write_sad_regs(encoder);
761 radeon_audio_write_latency_fields(encoder, mode);
Alex Deucheraeefd072015-02-27 14:43:47 -0500762 if (rdev->clock.dp_extclk || ASIC_IS_DCE5(rdev))
763 radeon_audio_set_dto(encoder, rdev->clock.default_dispclk * 10);
764 else
765 radeon_audio_set_dto(encoder, dig_connector->dp_clock);
Slava Grigoreve55bca22014-12-12 17:01:42 -0500766 radeon_audio_set_audio_packet(encoder);
767 radeon_audio_select_pin(encoder);
768
769 if (radeon_audio_set_avi_packet(encoder, mode) < 0)
770 return;
Slava Grigoreve55bca22014-12-12 17:01:42 -0500771}
772
Slava Grigorev6e723762014-12-10 10:43:51 -0500773void radeon_audio_mode_set(struct drm_encoder *encoder,
774 struct drm_display_mode *mode)
775{
776 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
777
778 if (radeon_encoder->audio && radeon_encoder->audio->mode_set)
779 radeon_encoder->audio->mode_set(encoder, mode);
780}
Slava Grigorev6f945692014-12-10 14:52:43 -0500781
782void radeon_audio_dpms(struct drm_encoder *encoder, int mode)
783{
784 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
785
786 if (radeon_encoder->audio && radeon_encoder->audio->dpms)
787 radeon_encoder->audio->dpms(encoder, mode == DRM_MODE_DPMS_ON);
788}