Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | #include <drm/drmP.h> |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 26 | #include <drm/drm_crtc.h> |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 27 | #include "radeon.h" |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 28 | #include "atom.h" |
| 29 | #include "radeon_audio.h" |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 30 | |
| 31 | void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 32 | u8 enable_mask); |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 33 | void dce4_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 34 | u8 enable_mask); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 35 | void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 36 | u8 enable_mask); |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 37 | u32 dce6_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg); |
| 38 | void dce6_endpoint_wreg(struct radeon_device *rdev, |
| 39 | u32 offset, u32 reg, u32 v); |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 40 | void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder, |
| 41 | struct cea_sad *sads, int sad_count); |
| 42 | void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder, |
| 43 | struct cea_sad *sads, int sad_count); |
| 44 | void dce6_afmt_write_sad_regs(struct drm_encoder *encoder, |
| 45 | struct cea_sad *sads, int sad_count); |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 46 | void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 47 | u8 *sadb, int sad_count); |
| 48 | void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 49 | u8 *sadb, int sad_count); |
| 50 | void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 51 | u8 *sadb, int sad_count); |
| 52 | void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 53 | u8 *sadb, int sad_count); |
| 54 | void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 55 | u8 *sadb, int sad_count); |
| 56 | void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 57 | u8 *sadb, int sad_count); |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 58 | void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 59 | struct drm_connector *connector, struct drm_display_mode *mode); |
| 60 | void dce6_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 61 | struct drm_connector *connector, struct drm_display_mode *mode); |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 62 | struct r600_audio_pin* r600_audio_get_pin(struct radeon_device *rdev); |
| 63 | struct r600_audio_pin* dce6_audio_get_pin(struct radeon_device *rdev); |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 64 | void dce6_afmt_select_pin(struct drm_encoder *encoder); |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 65 | void r600_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 66 | struct radeon_crtc *crtc, unsigned int clock); |
| 67 | void dce3_2_audio_set_dto(struct radeon_device *rdev, |
| 68 | struct radeon_crtc *crtc, unsigned int clock); |
| 69 | void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 70 | struct radeon_crtc *crtc, unsigned int clock); |
| 71 | void dce4_dp_audio_set_dto(struct radeon_device *rdev, |
| 72 | struct radeon_crtc *crtc, unsigned int clock); |
| 73 | void dce6_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 74 | struct radeon_crtc *crtc, unsigned int clock); |
| 75 | void dce6_dp_audio_set_dto(struct radeon_device *rdev, |
| 76 | struct radeon_crtc *crtc, unsigned int clock); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 77 | |
| 78 | static const u32 pin_offsets[7] = |
| 79 | { |
| 80 | (0x5e00 - 0x5e00), |
| 81 | (0x5e18 - 0x5e00), |
| 82 | (0x5e30 - 0x5e00), |
| 83 | (0x5e48 - 0x5e00), |
| 84 | (0x5e60 - 0x5e00), |
| 85 | (0x5e78 - 0x5e00), |
| 86 | (0x5e90 - 0x5e00), |
| 87 | }; |
| 88 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 89 | static u32 radeon_audio_rreg(struct radeon_device *rdev, u32 offset, u32 reg) |
| 90 | { |
| 91 | return RREG32(reg); |
| 92 | } |
| 93 | |
| 94 | static void radeon_audio_wreg(struct radeon_device *rdev, u32 offset, |
| 95 | u32 reg, u32 v) |
| 96 | { |
| 97 | WREG32(reg, v); |
| 98 | } |
| 99 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 100 | static struct radeon_audio_basic_funcs r600_funcs = { |
| 101 | .endpoint_rreg = radeon_audio_rreg, |
| 102 | .endpoint_wreg = radeon_audio_wreg, |
| 103 | .enable = r600_audio_enable, |
| 104 | }; |
| 105 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 106 | static struct radeon_audio_basic_funcs dce32_funcs = { |
| 107 | .endpoint_rreg = radeon_audio_rreg, |
| 108 | .endpoint_wreg = radeon_audio_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 109 | .enable = r600_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static struct radeon_audio_basic_funcs dce4_funcs = { |
| 113 | .endpoint_rreg = radeon_audio_rreg, |
| 114 | .endpoint_wreg = radeon_audio_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 115 | .enable = dce4_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static struct radeon_audio_basic_funcs dce6_funcs = { |
| 119 | .endpoint_rreg = dce6_endpoint_rreg, |
| 120 | .endpoint_wreg = dce6_endpoint_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 121 | .enable = dce6_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 124 | static struct radeon_audio_funcs r600_hdmi_funcs = { |
| 125 | .get_pin = r600_audio_get_pin, |
| 126 | .set_dto = r600_hdmi_audio_set_dto, |
| 127 | }; |
| 128 | |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 129 | static struct radeon_audio_funcs dce32_hdmi_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 130 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 131 | .write_sad_regs = dce3_2_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 132 | .write_speaker_allocation = dce3_2_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 133 | .set_dto = dce3_2_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | static struct radeon_audio_funcs dce32_dp_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 137 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 138 | .write_sad_regs = dce3_2_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 139 | .write_speaker_allocation = dce3_2_afmt_dp_write_speaker_allocation, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 140 | .set_dto = dce3_2_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | static struct radeon_audio_funcs dce4_hdmi_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 144 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 145 | .write_sad_regs = evergreen_hdmi_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 146 | .write_speaker_allocation = dce4_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 147 | .write_latency_fields = dce4_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 148 | .set_dto = dce4_hdmi_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | static struct radeon_audio_funcs dce4_dp_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 152 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 153 | .write_sad_regs = evergreen_hdmi_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 154 | .write_speaker_allocation = dce4_afmt_dp_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 155 | .write_latency_fields = dce4_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 156 | .set_dto = dce4_dp_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static struct radeon_audio_funcs dce6_hdmi_funcs = { |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 160 | .select_pin = dce6_afmt_select_pin, |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 161 | .get_pin = dce6_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 162 | .write_sad_regs = dce6_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 163 | .write_speaker_allocation = dce6_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 164 | .write_latency_fields = dce6_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 165 | .set_dto = dce6_hdmi_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | static struct radeon_audio_funcs dce6_dp_funcs = { |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 169 | .select_pin = dce6_afmt_select_pin, |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 170 | .get_pin = dce6_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 171 | .write_sad_regs = dce6_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 172 | .write_speaker_allocation = dce6_afmt_dp_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 173 | .write_latency_fields = dce6_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 174 | .set_dto = dce6_dp_audio_set_dto, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 175 | }; |
| 176 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 177 | static void radeon_audio_interface_init(struct radeon_device *rdev) |
| 178 | { |
| 179 | if (ASIC_IS_DCE6(rdev)) { |
| 180 | rdev->audio.funcs = &dce6_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 181 | rdev->audio.hdmi_funcs = &dce6_hdmi_funcs; |
| 182 | rdev->audio.dp_funcs = &dce6_dp_funcs; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 183 | } else if (ASIC_IS_DCE4(rdev)) { |
| 184 | rdev->audio.funcs = &dce4_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 185 | rdev->audio.hdmi_funcs = &dce4_hdmi_funcs; |
| 186 | rdev->audio.dp_funcs = &dce4_dp_funcs; |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 187 | } else if (ASIC_IS_DCE32(rdev)) { |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 188 | rdev->audio.funcs = &dce32_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 189 | rdev->audio.hdmi_funcs = &dce32_hdmi_funcs; |
| 190 | rdev->audio.dp_funcs = &dce32_dp_funcs; |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 191 | } else { |
| 192 | rdev->audio.funcs = &r600_funcs; |
| 193 | rdev->audio.hdmi_funcs = &r600_hdmi_funcs; |
| 194 | rdev->audio.dp_funcs = 0; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 198 | static int radeon_audio_chipset_supported(struct radeon_device *rdev) |
| 199 | { |
| 200 | return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev); |
| 201 | } |
| 202 | |
| 203 | int radeon_audio_init(struct radeon_device *rdev) |
| 204 | { |
| 205 | int i; |
| 206 | |
| 207 | if (!radeon_audio || !radeon_audio_chipset_supported(rdev)) |
| 208 | return 0; |
| 209 | |
| 210 | rdev->audio.enabled = true; |
| 211 | |
| 212 | if (ASIC_IS_DCE83(rdev)) /* KB: 2 streams, 3 endpoints */ |
| 213 | rdev->audio.num_pins = 3; |
| 214 | else if (ASIC_IS_DCE81(rdev)) /* KV: 4 streams, 7 endpoints */ |
| 215 | rdev->audio.num_pins = 7; |
| 216 | else if (ASIC_IS_DCE8(rdev)) /* BN/HW: 6 streams, 7 endpoints */ |
| 217 | rdev->audio.num_pins = 7; |
| 218 | else if (ASIC_IS_DCE64(rdev)) /* OL: 2 streams, 2 endpoints */ |
| 219 | rdev->audio.num_pins = 2; |
| 220 | else if (ASIC_IS_DCE61(rdev)) /* TN: 4 streams, 6 endpoints */ |
| 221 | rdev->audio.num_pins = 6; |
| 222 | else if (ASIC_IS_DCE6(rdev)) /* SI: 6 streams, 6 endpoints */ |
| 223 | rdev->audio.num_pins = 6; |
| 224 | else |
| 225 | rdev->audio.num_pins = 1; |
| 226 | |
| 227 | for (i = 0; i < rdev->audio.num_pins; i++) { |
| 228 | rdev->audio.pin[i].channels = -1; |
| 229 | rdev->audio.pin[i].rate = -1; |
| 230 | rdev->audio.pin[i].bits_per_sample = -1; |
| 231 | rdev->audio.pin[i].status_bits = 0; |
| 232 | rdev->audio.pin[i].category_code = 0; |
| 233 | rdev->audio.pin[i].connected = false; |
| 234 | rdev->audio.pin[i].offset = pin_offsets[i]; |
| 235 | rdev->audio.pin[i].id = i; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | radeon_audio_interface_init(rdev); |
| 239 | |
| 240 | /* disable audio. it will be set up later */ |
| 241 | for (i = 0; i < rdev->audio.num_pins; i++) |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 242 | radeon_audio_enable(rdev, &rdev->audio.pin[i], false); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 246 | |
| 247 | void radeon_audio_detect(struct drm_connector *connector, |
| 248 | enum drm_connector_status status) |
| 249 | { |
| 250 | if (!connector || !connector->encoder) |
| 251 | return; |
| 252 | |
| 253 | if (status == connector_status_connected) { |
| 254 | int sink_type; |
| 255 | struct radeon_device *rdev = connector->encoder->dev->dev_private; |
| 256 | struct radeon_connector *radeon_connector; |
| 257 | struct radeon_encoder *radeon_encoder = |
| 258 | to_radeon_encoder(connector->encoder); |
| 259 | |
| 260 | if (!drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
| 261 | radeon_encoder->audio = 0; |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | radeon_connector = to_radeon_connector(connector); |
| 266 | sink_type = radeon_dp_getsinktype(radeon_connector); |
| 267 | |
| 268 | if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort && |
| 269 | sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) |
| 270 | radeon_encoder->audio = rdev->audio.dp_funcs; |
| 271 | else |
| 272 | radeon_encoder->audio = rdev->audio.hdmi_funcs; |
| 273 | /* TODO: set up the sads, etc. and set the audio enable_mask */ |
| 274 | } else { |
| 275 | /* TODO: reset the audio enable_mask */ |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | u32 radeon_audio_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg) |
| 280 | { |
| 281 | if (rdev->audio.funcs->endpoint_rreg) |
| 282 | return rdev->audio.funcs->endpoint_rreg(rdev, offset, reg); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | void radeon_audio_endpoint_wreg(struct radeon_device *rdev, u32 offset, |
| 288 | u32 reg, u32 v) |
| 289 | { |
| 290 | if (rdev->audio.funcs->endpoint_wreg) |
| 291 | rdev->audio.funcs->endpoint_wreg(rdev, offset, reg, v); |
| 292 | } |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 293 | |
| 294 | void radeon_audio_write_sad_regs(struct drm_encoder *encoder) |
| 295 | { |
| 296 | struct radeon_encoder *radeon_encoder; |
| 297 | struct drm_connector *connector; |
| 298 | struct radeon_connector *radeon_connector = NULL; |
| 299 | struct cea_sad *sads; |
| 300 | int sad_count; |
| 301 | |
| 302 | list_for_each_entry(connector, |
| 303 | &encoder->dev->mode_config.connector_list, head) { |
| 304 | if (connector->encoder == encoder) { |
| 305 | radeon_connector = to_radeon_connector(connector); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if (!radeon_connector) { |
| 311 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | sad_count = drm_edid_to_sad(radeon_connector_edid(connector), &sads); |
| 316 | if (sad_count <= 0) { |
| 317 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); |
| 318 | return; |
| 319 | } |
| 320 | BUG_ON(!sads); |
| 321 | |
| 322 | radeon_encoder = to_radeon_encoder(encoder); |
| 323 | |
| 324 | if (radeon_encoder->audio && radeon_encoder->audio->write_sad_regs) |
| 325 | radeon_encoder->audio->write_sad_regs(encoder, sads, sad_count); |
| 326 | |
| 327 | kfree(sads); |
| 328 | } |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 329 | |
| 330 | void radeon_audio_write_speaker_allocation(struct drm_encoder *encoder) |
| 331 | { |
| 332 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 333 | struct drm_connector *connector; |
| 334 | struct radeon_connector *radeon_connector = NULL; |
| 335 | u8 *sadb = NULL; |
| 336 | int sad_count; |
| 337 | |
| 338 | list_for_each_entry(connector, |
| 339 | &encoder->dev->mode_config.connector_list, head) { |
| 340 | if (connector->encoder == encoder) { |
| 341 | radeon_connector = to_radeon_connector(connector); |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if (!radeon_connector) { |
| 347 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | sad_count = drm_edid_to_speaker_allocation( |
| 352 | radeon_connector_edid(connector), &sadb); |
| 353 | if (sad_count < 0) { |
| 354 | DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", |
| 355 | sad_count); |
| 356 | sad_count = 0; |
| 357 | } |
| 358 | |
| 359 | if (radeon_encoder->audio && radeon_encoder->audio->write_speaker_allocation) |
| 360 | radeon_encoder->audio->write_speaker_allocation(encoder, sadb, sad_count); |
| 361 | |
| 362 | kfree(sadb); |
| 363 | } |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 364 | |
| 365 | void radeon_audio_write_latency_fields(struct drm_encoder *encoder, |
| 366 | struct drm_display_mode *mode) |
| 367 | { |
| 368 | struct radeon_encoder *radeon_encoder; |
| 369 | struct drm_connector *connector; |
| 370 | struct radeon_connector *radeon_connector = 0; |
| 371 | |
| 372 | list_for_each_entry(connector, |
| 373 | &encoder->dev->mode_config.connector_list, head) { |
| 374 | if (connector->encoder == encoder) { |
| 375 | radeon_connector = to_radeon_connector(connector); |
| 376 | break; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | if (!radeon_connector) { |
| 381 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | radeon_encoder = to_radeon_encoder(encoder); |
| 386 | |
| 387 | if (radeon_encoder->audio && radeon_encoder->audio->write_latency_fields) |
| 388 | radeon_encoder->audio->write_latency_fields(encoder, connector, mode); |
| 389 | } |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 390 | |
| 391 | struct r600_audio_pin* radeon_audio_get_pin(struct drm_encoder *encoder) |
| 392 | { |
| 393 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 394 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 395 | |
| 396 | if (radeon_encoder->audio && radeon_encoder->audio->get_pin) |
| 397 | return radeon_encoder->audio->get_pin(rdev); |
| 398 | |
| 399 | return NULL; |
| 400 | } |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 401 | |
| 402 | void radeon_audio_select_pin(struct drm_encoder *encoder) |
| 403 | { |
| 404 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 405 | |
| 406 | if (radeon_encoder->audio && radeon_encoder->audio->select_pin) |
| 407 | radeon_encoder->audio->select_pin(encoder); |
| 408 | } |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 409 | |
| 410 | void radeon_audio_enable(struct radeon_device *rdev, |
| 411 | struct r600_audio_pin *pin, u8 enable_mask) |
| 412 | { |
| 413 | if (rdev->audio.funcs->enable) |
| 414 | rdev->audio.funcs->enable(rdev, pin, enable_mask); |
| 415 | } |
Slava Grigorev | 7991d66 | 2014-12-03 17:07:01 -0500 | [diff] [blame] | 416 | |
| 417 | void radeon_audio_fini(struct radeon_device *rdev) |
| 418 | { |
| 419 | int i; |
| 420 | |
| 421 | if (!rdev->audio.enabled) |
| 422 | return; |
| 423 | |
| 424 | for (i = 0; i < rdev->audio.num_pins; i++) |
| 425 | radeon_audio_enable(rdev, &rdev->audio.pin[i], false); |
| 426 | |
| 427 | rdev->audio.enabled = false; |
| 428 | } |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame^] | 429 | |
| 430 | void radeon_audio_set_dto(struct drm_encoder *encoder, unsigned int clock) |
| 431 | { |
| 432 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 433 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 434 | struct radeon_crtc *crtc = to_radeon_crtc(encoder->crtc); |
| 435 | |
| 436 | if (radeon_encoder->audio && radeon_encoder->audio->set_dto) |
| 437 | radeon_encoder->audio->set_dto(rdev, crtc, clock); |
| 438 | } |