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 | |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 25 | #include <linux/gcd.h> |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 26 | #include <drm/drmP.h> |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 27 | #include <drm/drm_crtc.h> |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 28 | #include "radeon.h" |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 29 | #include "atom.h" |
| 30 | #include "radeon_audio.h" |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 31 | |
| 32 | void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 33 | u8 enable_mask); |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 34 | void dce4_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 35 | u8 enable_mask); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 36 | void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin, |
| 37 | u8 enable_mask); |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 38 | u32 dce6_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg); |
| 39 | void dce6_endpoint_wreg(struct radeon_device *rdev, |
| 40 | u32 offset, u32 reg, u32 v); |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 41 | void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder, |
| 42 | struct cea_sad *sads, int sad_count); |
| 43 | void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder, |
| 44 | struct cea_sad *sads, int sad_count); |
| 45 | void dce6_afmt_write_sad_regs(struct drm_encoder *encoder, |
| 46 | struct cea_sad *sads, int sad_count); |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 47 | void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 48 | u8 *sadb, int sad_count); |
| 49 | void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 50 | u8 *sadb, int sad_count); |
| 51 | void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 52 | u8 *sadb, int sad_count); |
| 53 | void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 54 | u8 *sadb, int sad_count); |
| 55 | void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 56 | u8 *sadb, int sad_count); |
| 57 | void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 58 | u8 *sadb, int sad_count); |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 59 | void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 60 | struct drm_connector *connector, struct drm_display_mode *mode); |
| 61 | void dce6_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 62 | struct drm_connector *connector, struct drm_display_mode *mode); |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 63 | struct r600_audio_pin* r600_audio_get_pin(struct radeon_device *rdev); |
| 64 | struct r600_audio_pin* dce6_audio_get_pin(struct radeon_device *rdev); |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 65 | void dce6_afmt_select_pin(struct drm_encoder *encoder); |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 66 | void r600_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 67 | struct radeon_crtc *crtc, unsigned int clock); |
| 68 | void dce3_2_audio_set_dto(struct radeon_device *rdev, |
| 69 | struct radeon_crtc *crtc, unsigned int clock); |
| 70 | void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 71 | struct radeon_crtc *crtc, unsigned int clock); |
| 72 | void dce4_dp_audio_set_dto(struct radeon_device *rdev, |
| 73 | struct radeon_crtc *crtc, unsigned int clock); |
| 74 | void dce6_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 75 | struct radeon_crtc *crtc, unsigned int clock); |
| 76 | void dce6_dp_audio_set_dto(struct radeon_device *rdev, |
| 77 | struct radeon_crtc *crtc, unsigned int clock); |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 78 | void r600_set_avi_packet(struct radeon_device *rdev, u32 offset, |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 79 | unsigned char *buffer, size_t size); |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 80 | void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset, |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 81 | unsigned char *buffer, size_t size); |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 82 | void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset, |
| 83 | const struct radeon_hdmi_acr *acr); |
| 84 | void dce3_2_hdmi_update_acr(struct drm_encoder *encoder, long offset, |
| 85 | const struct radeon_hdmi_acr *acr); |
| 86 | void evergreen_hdmi_update_acr(struct drm_encoder *encoder, long offset, |
| 87 | const struct radeon_hdmi_acr *acr); |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 88 | void r600_set_vbi_packet(struct drm_encoder *encoder, u32 offset); |
| 89 | void dce4_set_vbi_packet(struct drm_encoder *encoder, u32 offset); |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 90 | void dce4_hdmi_set_color_depth(struct drm_encoder *encoder, |
| 91 | u32 offset, int bpc); |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 92 | void r600_set_audio_packet(struct drm_encoder *encoder, u32 offset); |
| 93 | void dce3_2_set_audio_packet(struct drm_encoder *encoder, u32 offset); |
| 94 | void dce4_set_audio_packet(struct drm_encoder *encoder, u32 offset); |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 95 | void r600_set_mute(struct drm_encoder *encoder, u32 offset, bool mute); |
| 96 | void dce3_2_set_mute(struct drm_encoder *encoder, u32 offset, bool mute); |
| 97 | void dce4_set_mute(struct drm_encoder *encoder, u32 offset, bool mute); |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 98 | static void radeon_audio_hdmi_mode_set(struct drm_encoder *encoder, |
| 99 | struct drm_display_mode *mode); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 100 | static void radeon_audio_dp_mode_set(struct drm_encoder *encoder, |
| 101 | struct drm_display_mode *mode); |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 102 | void r600_hdmi_enable(struct drm_encoder *encoder, bool enable); |
| 103 | void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable); |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 104 | void evergreen_dp_enable(struct drm_encoder *encoder, bool enable); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 105 | |
| 106 | static const u32 pin_offsets[7] = |
| 107 | { |
| 108 | (0x5e00 - 0x5e00), |
| 109 | (0x5e18 - 0x5e00), |
| 110 | (0x5e30 - 0x5e00), |
| 111 | (0x5e48 - 0x5e00), |
| 112 | (0x5e60 - 0x5e00), |
| 113 | (0x5e78 - 0x5e00), |
| 114 | (0x5e90 - 0x5e00), |
| 115 | }; |
| 116 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 117 | static u32 radeon_audio_rreg(struct radeon_device *rdev, u32 offset, u32 reg) |
| 118 | { |
| 119 | return RREG32(reg); |
| 120 | } |
| 121 | |
| 122 | static void radeon_audio_wreg(struct radeon_device *rdev, u32 offset, |
| 123 | u32 reg, u32 v) |
| 124 | { |
| 125 | WREG32(reg, v); |
| 126 | } |
| 127 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 128 | static struct radeon_audio_basic_funcs r600_funcs = { |
| 129 | .endpoint_rreg = radeon_audio_rreg, |
| 130 | .endpoint_wreg = radeon_audio_wreg, |
| 131 | .enable = r600_audio_enable, |
| 132 | }; |
| 133 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 134 | static struct radeon_audio_basic_funcs dce32_funcs = { |
| 135 | .endpoint_rreg = radeon_audio_rreg, |
| 136 | .endpoint_wreg = radeon_audio_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 137 | .enable = r600_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static struct radeon_audio_basic_funcs dce4_funcs = { |
| 141 | .endpoint_rreg = radeon_audio_rreg, |
| 142 | .endpoint_wreg = radeon_audio_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 143 | .enable = dce4_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static struct radeon_audio_basic_funcs dce6_funcs = { |
| 147 | .endpoint_rreg = dce6_endpoint_rreg, |
| 148 | .endpoint_wreg = dce6_endpoint_wreg, |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 149 | .enable = dce6_audio_enable, |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 150 | }; |
| 151 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 152 | static struct radeon_audio_funcs r600_hdmi_funcs = { |
| 153 | .get_pin = r600_audio_get_pin, |
| 154 | .set_dto = r600_hdmi_audio_set_dto, |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 155 | .update_acr = r600_hdmi_update_acr, |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 156 | .set_vbi_packet = r600_set_vbi_packet, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 157 | .set_avi_packet = r600_set_avi_packet, |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 158 | .set_audio_packet = r600_set_audio_packet, |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 159 | .set_mute = r600_set_mute, |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 160 | .mode_set = radeon_audio_hdmi_mode_set, |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 161 | .dpms = r600_hdmi_enable, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 162 | }; |
| 163 | |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 164 | static struct radeon_audio_funcs dce32_hdmi_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 165 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 166 | .write_sad_regs = dce3_2_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 167 | .write_speaker_allocation = dce3_2_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 168 | .set_dto = dce3_2_audio_set_dto, |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 169 | .update_acr = dce3_2_hdmi_update_acr, |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 170 | .set_vbi_packet = r600_set_vbi_packet, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 171 | .set_avi_packet = r600_set_avi_packet, |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 172 | .set_audio_packet = dce3_2_set_audio_packet, |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 173 | .set_mute = dce3_2_set_mute, |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 174 | .mode_set = radeon_audio_hdmi_mode_set, |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 175 | .dpms = r600_hdmi_enable, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | static struct radeon_audio_funcs dce32_dp_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 179 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 180 | .write_sad_regs = dce3_2_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 181 | .write_speaker_allocation = dce3_2_afmt_dp_write_speaker_allocation, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 182 | .set_dto = dce3_2_audio_set_dto, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 183 | .set_avi_packet = r600_set_avi_packet, |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 184 | .set_audio_packet = dce3_2_set_audio_packet, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static struct radeon_audio_funcs dce4_hdmi_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 188 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 189 | .write_sad_regs = evergreen_hdmi_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 190 | .write_speaker_allocation = dce4_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 191 | .write_latency_fields = dce4_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 192 | .set_dto = dce4_hdmi_audio_set_dto, |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 193 | .update_acr = evergreen_hdmi_update_acr, |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 194 | .set_vbi_packet = dce4_set_vbi_packet, |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 195 | .set_color_depth = dce4_hdmi_set_color_depth, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 196 | .set_avi_packet = evergreen_set_avi_packet, |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 197 | .set_audio_packet = dce4_set_audio_packet, |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 198 | .set_mute = dce4_set_mute, |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 199 | .mode_set = radeon_audio_hdmi_mode_set, |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 200 | .dpms = evergreen_hdmi_enable, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | static struct radeon_audio_funcs dce4_dp_funcs = { |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 204 | .get_pin = r600_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 205 | .write_sad_regs = evergreen_hdmi_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 206 | .write_speaker_allocation = dce4_afmt_dp_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 207 | .write_latency_fields = dce4_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 208 | .set_dto = dce4_dp_audio_set_dto, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 209 | .set_avi_packet = evergreen_set_avi_packet, |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 210 | .set_audio_packet = dce4_set_audio_packet, |
| 211 | .mode_set = radeon_audio_dp_mode_set, |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 212 | .dpms = evergreen_dp_enable, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | static struct radeon_audio_funcs dce6_hdmi_funcs = { |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 216 | .select_pin = dce6_afmt_select_pin, |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 217 | .get_pin = dce6_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 218 | .write_sad_regs = dce6_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 219 | .write_speaker_allocation = dce6_afmt_hdmi_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 220 | .write_latency_fields = dce6_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 221 | .set_dto = dce6_hdmi_audio_set_dto, |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 222 | .update_acr = evergreen_hdmi_update_acr, |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 223 | .set_vbi_packet = dce4_set_vbi_packet, |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 224 | .set_color_depth = dce4_hdmi_set_color_depth, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 225 | .set_avi_packet = evergreen_set_avi_packet, |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 226 | .set_audio_packet = dce4_set_audio_packet, |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 227 | .set_mute = dce4_set_mute, |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 228 | .mode_set = radeon_audio_hdmi_mode_set, |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 229 | .dpms = evergreen_hdmi_enable, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | static struct radeon_audio_funcs dce6_dp_funcs = { |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 233 | .select_pin = dce6_afmt_select_pin, |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 234 | .get_pin = dce6_audio_get_pin, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 235 | .write_sad_regs = dce6_afmt_write_sad_regs, |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 236 | .write_speaker_allocation = dce6_afmt_dp_write_speaker_allocation, |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 237 | .write_latency_fields = dce6_afmt_write_latency_fields, |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 238 | .set_dto = dce6_dp_audio_set_dto, |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 239 | .set_avi_packet = evergreen_set_avi_packet, |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 240 | .set_audio_packet = dce4_set_audio_packet, |
| 241 | .mode_set = radeon_audio_dp_mode_set, |
Alex Deucher | 1242832 | 2015-03-31 11:38:48 -0400 | [diff] [blame] | 242 | .dpms = evergreen_dp_enable, |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 243 | }; |
| 244 | |
Alex Deucher | 0106219 | 2015-05-18 11:11:48 -0400 | [diff] [blame] | 245 | static void radeon_audio_enable(struct radeon_device *rdev, |
| 246 | struct r600_audio_pin *pin, u8 enable_mask) |
| 247 | { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 248 | struct drm_encoder *encoder; |
| 249 | struct radeon_encoder *radeon_encoder; |
| 250 | struct radeon_encoder_atom_dig *dig; |
| 251 | int pin_count = 0; |
| 252 | |
| 253 | if (!pin) |
| 254 | return; |
| 255 | |
| 256 | if (rdev->mode_info.mode_config_initialized) { |
| 257 | list_for_each_entry(encoder, &rdev->ddev->mode_config.encoder_list, head) { |
| 258 | if (radeon_encoder_is_digital(encoder)) { |
| 259 | radeon_encoder = to_radeon_encoder(encoder); |
| 260 | dig = radeon_encoder->enc_priv; |
| 261 | if (dig->pin == pin) |
| 262 | pin_count++; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if ((pin_count > 1) && (enable_mask == 0)) |
| 267 | return; |
| 268 | } |
| 269 | |
Alex Deucher | 0106219 | 2015-05-18 11:11:48 -0400 | [diff] [blame] | 270 | if (rdev->audio.funcs->enable) |
| 271 | rdev->audio.funcs->enable(rdev, pin, enable_mask); |
| 272 | } |
| 273 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 274 | static void radeon_audio_interface_init(struct radeon_device *rdev) |
| 275 | { |
| 276 | if (ASIC_IS_DCE6(rdev)) { |
| 277 | rdev->audio.funcs = &dce6_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 278 | rdev->audio.hdmi_funcs = &dce6_hdmi_funcs; |
| 279 | rdev->audio.dp_funcs = &dce6_dp_funcs; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 280 | } else if (ASIC_IS_DCE4(rdev)) { |
| 281 | rdev->audio.funcs = &dce4_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 282 | rdev->audio.hdmi_funcs = &dce4_hdmi_funcs; |
| 283 | rdev->audio.dp_funcs = &dce4_dp_funcs; |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 284 | } else if (ASIC_IS_DCE32(rdev)) { |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 285 | rdev->audio.funcs = &dce32_funcs; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 286 | rdev->audio.hdmi_funcs = &dce32_hdmi_funcs; |
| 287 | rdev->audio.dp_funcs = &dce32_dp_funcs; |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 288 | } else { |
| 289 | rdev->audio.funcs = &r600_funcs; |
| 290 | rdev->audio.hdmi_funcs = &r600_hdmi_funcs; |
| 291 | rdev->audio.dp_funcs = 0; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 295 | static int radeon_audio_chipset_supported(struct radeon_device *rdev) |
| 296 | { |
| 297 | return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev); |
| 298 | } |
| 299 | |
| 300 | int radeon_audio_init(struct radeon_device *rdev) |
| 301 | { |
| 302 | int i; |
| 303 | |
| 304 | if (!radeon_audio || !radeon_audio_chipset_supported(rdev)) |
| 305 | return 0; |
| 306 | |
| 307 | rdev->audio.enabled = true; |
| 308 | |
| 309 | if (ASIC_IS_DCE83(rdev)) /* KB: 2 streams, 3 endpoints */ |
| 310 | rdev->audio.num_pins = 3; |
| 311 | else if (ASIC_IS_DCE81(rdev)) /* KV: 4 streams, 7 endpoints */ |
| 312 | rdev->audio.num_pins = 7; |
| 313 | else if (ASIC_IS_DCE8(rdev)) /* BN/HW: 6 streams, 7 endpoints */ |
| 314 | rdev->audio.num_pins = 7; |
| 315 | else if (ASIC_IS_DCE64(rdev)) /* OL: 2 streams, 2 endpoints */ |
| 316 | rdev->audio.num_pins = 2; |
| 317 | else if (ASIC_IS_DCE61(rdev)) /* TN: 4 streams, 6 endpoints */ |
| 318 | rdev->audio.num_pins = 6; |
| 319 | else if (ASIC_IS_DCE6(rdev)) /* SI: 6 streams, 6 endpoints */ |
| 320 | rdev->audio.num_pins = 6; |
| 321 | else |
| 322 | rdev->audio.num_pins = 1; |
| 323 | |
| 324 | for (i = 0; i < rdev->audio.num_pins; i++) { |
| 325 | rdev->audio.pin[i].channels = -1; |
| 326 | rdev->audio.pin[i].rate = -1; |
| 327 | rdev->audio.pin[i].bits_per_sample = -1; |
| 328 | rdev->audio.pin[i].status_bits = 0; |
| 329 | rdev->audio.pin[i].category_code = 0; |
| 330 | rdev->audio.pin[i].connected = false; |
| 331 | rdev->audio.pin[i].offset = pin_offsets[i]; |
| 332 | rdev->audio.pin[i].id = i; |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | radeon_audio_interface_init(rdev); |
| 336 | |
| 337 | /* disable audio. it will be set up later */ |
| 338 | for (i = 0; i < rdev->audio.num_pins; i++) |
Alex Deucher | 0106219 | 2015-05-18 11:11:48 -0400 | [diff] [blame] | 339 | radeon_audio_enable(rdev, &rdev->audio.pin[i], 0); |
Slava Grigorev | bfc1f97 | 2014-12-22 17:26:51 -0500 | [diff] [blame] | 340 | |
| 341 | return 0; |
| 342 | } |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 343 | |
Slava Grigorev | 1a626b6 | 2014-12-01 13:49:39 -0500 | [diff] [blame] | 344 | u32 radeon_audio_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg) |
| 345 | { |
| 346 | if (rdev->audio.funcs->endpoint_rreg) |
| 347 | return rdev->audio.funcs->endpoint_rreg(rdev, offset, reg); |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | void radeon_audio_endpoint_wreg(struct radeon_device *rdev, u32 offset, |
| 353 | u32 reg, u32 v) |
| 354 | { |
| 355 | if (rdev->audio.funcs->endpoint_wreg) |
| 356 | rdev->audio.funcs->endpoint_wreg(rdev, offset, reg, v); |
| 357 | } |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 358 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 359 | static void radeon_audio_write_sad_regs(struct drm_encoder *encoder) |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 360 | { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 361 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
| 362 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 363 | struct cea_sad *sads; |
| 364 | int sad_count; |
| 365 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 366 | if (!connector) |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 367 | return; |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 368 | |
| 369 | sad_count = drm_edid_to_sad(radeon_connector_edid(connector), &sads); |
| 370 | if (sad_count <= 0) { |
| 371 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); |
| 372 | return; |
| 373 | } |
| 374 | BUG_ON(!sads); |
| 375 | |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 376 | if (radeon_encoder->audio && radeon_encoder->audio->write_sad_regs) |
| 377 | radeon_encoder->audio->write_sad_regs(encoder, sads, sad_count); |
| 378 | |
| 379 | kfree(sads); |
| 380 | } |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 381 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 382 | static void radeon_audio_write_speaker_allocation(struct drm_encoder *encoder) |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 383 | { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 384 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 385 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 386 | u8 *sadb = NULL; |
| 387 | int sad_count; |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 388 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 389 | if (!connector) |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 390 | return; |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 391 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 392 | sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), |
| 393 | &sadb); |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 394 | if (sad_count < 0) { |
| 395 | DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", |
| 396 | sad_count); |
| 397 | sad_count = 0; |
| 398 | } |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 399 | |
| 400 | if (radeon_encoder->audio && radeon_encoder->audio->write_speaker_allocation) |
| 401 | radeon_encoder->audio->write_speaker_allocation(encoder, sadb, sad_count); |
| 402 | |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 403 | kfree(sadb); |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 404 | } |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 405 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 406 | static void radeon_audio_write_latency_fields(struct drm_encoder *encoder, |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 407 | struct drm_display_mode *mode) |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 408 | { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 409 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
| 410 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 411 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 412 | if (!connector) |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 413 | return; |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 414 | |
| 415 | if (radeon_encoder->audio && radeon_encoder->audio->write_latency_fields) |
| 416 | radeon_encoder->audio->write_latency_fields(encoder, connector, mode); |
| 417 | } |
Slava Grigorev | 3cdde02 | 2014-12-02 15:22:43 -0500 | [diff] [blame] | 418 | |
| 419 | struct r600_audio_pin* radeon_audio_get_pin(struct drm_encoder *encoder) |
| 420 | { |
| 421 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 422 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 423 | |
| 424 | if (radeon_encoder->audio && radeon_encoder->audio->get_pin) |
| 425 | return radeon_encoder->audio->get_pin(rdev); |
| 426 | |
| 427 | return NULL; |
| 428 | } |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 429 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 430 | static void radeon_audio_select_pin(struct drm_encoder *encoder) |
Slava Grigorev | 88252d7 | 2014-12-02 17:27:29 -0500 | [diff] [blame] | 431 | { |
| 432 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 433 | |
| 434 | if (radeon_encoder->audio && radeon_encoder->audio->select_pin) |
| 435 | radeon_encoder->audio->select_pin(encoder); |
| 436 | } |
Slava Grigorev | 8bf5982 | 2014-12-03 15:29:53 -0500 | [diff] [blame] | 437 | |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 438 | void radeon_audio_detect(struct drm_connector *connector, |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 439 | struct drm_encoder *encoder, |
Alex Deucher | d3c34d2 | 2015-02-27 10:36:39 -0500 | [diff] [blame] | 440 | enum drm_connector_status status) |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 441 | { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 442 | struct drm_device *dev = connector->dev; |
| 443 | struct radeon_device *rdev = dev->dev_private; |
| 444 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 445 | struct radeon_encoder_atom_dig *dig; |
| 446 | |
Alex Deucher | d73a824 | 2015-05-04 14:35:01 -0400 | [diff] [blame] | 447 | if (!radeon_audio_chipset_supported(rdev)) |
| 448 | return; |
| 449 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 450 | if (!radeon_encoder_is_digital(encoder)) |
| 451 | return; |
| 452 | |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 453 | dig = radeon_encoder->enc_priv; |
| 454 | |
| 455 | if (status == connector_status_connected) { |
Alex Deucher | 479e9a9 | 2015-06-30 09:30:01 -0400 | [diff] [blame] | 456 | if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) { |
| 457 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 458 | |
Alex Deucher | 479e9a9 | 2015-06-30 09:30:01 -0400 | [diff] [blame] | 459 | if (radeon_dp_getsinktype(radeon_connector) == |
| 460 | CONNECTOR_OBJECT_ID_DISPLAYPORT) |
| 461 | radeon_encoder->audio = rdev->audio.dp_funcs; |
| 462 | else |
| 463 | radeon_encoder->audio = rdev->audio.hdmi_funcs; |
| 464 | } else { |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 465 | radeon_encoder->audio = rdev->audio.hdmi_funcs; |
Alex Deucher | 479e9a9 | 2015-06-30 09:30:01 -0400 | [diff] [blame] | 466 | } |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 467 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 468 | if (drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
| 469 | if (!dig->pin) |
| 470 | dig->pin = radeon_audio_get_pin(encoder); |
| 471 | radeon_audio_enable(rdev, dig->pin, 0xf); |
| 472 | } else { |
| 473 | radeon_audio_enable(rdev, dig->pin, 0); |
| 474 | dig->pin = NULL; |
| 475 | } |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 476 | } else { |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 477 | radeon_audio_enable(rdev, dig->pin, 0); |
| 478 | dig->pin = NULL; |
Slava Grigorev | ccd4be7 | 2014-12-11 13:11:29 -0500 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
Slava Grigorev | 7991d66 | 2014-12-03 17:07:01 -0500 | [diff] [blame] | 482 | void radeon_audio_fini(struct radeon_device *rdev) |
| 483 | { |
| 484 | int i; |
| 485 | |
| 486 | if (!rdev->audio.enabled) |
| 487 | return; |
| 488 | |
| 489 | for (i = 0; i < rdev->audio.num_pins; i++) |
Alex Deucher | 0106219 | 2015-05-18 11:11:48 -0400 | [diff] [blame] | 490 | radeon_audio_enable(rdev, &rdev->audio.pin[i], 0); |
Slava Grigorev | 7991d66 | 2014-12-03 17:07:01 -0500 | [diff] [blame] | 491 | |
| 492 | rdev->audio.enabled = false; |
| 493 | } |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 494 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 495 | static void radeon_audio_set_dto(struct drm_encoder *encoder, unsigned int clock) |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 496 | { |
| 497 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 498 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 499 | struct radeon_crtc *crtc = to_radeon_crtc(encoder->crtc); |
| 500 | |
| 501 | if (radeon_encoder->audio && radeon_encoder->audio->set_dto) |
| 502 | radeon_encoder->audio->set_dto(rdev, crtc, clock); |
| 503 | } |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 504 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 505 | static int radeon_audio_set_avi_packet(struct drm_encoder *encoder, |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 506 | struct drm_display_mode *mode) |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 507 | { |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 508 | struct radeon_device *rdev = encoder->dev->dev_private; |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 509 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 510 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 511 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 512 | u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; |
| 513 | struct hdmi_avi_infoframe frame; |
| 514 | int err; |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 515 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 516 | if (!connector) |
| 517 | return -EINVAL; |
Alex Deucher | a1dcc27 | 2015-02-23 17:14:47 -0500 | [diff] [blame] | 518 | |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 519 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
| 520 | if (err < 0) { |
| 521 | DRM_ERROR("failed to setup AVI infoframe: %d\n", err); |
| 522 | return err; |
| 523 | } |
| 524 | |
Alex Deucher | 86b7709 | 2015-08-27 09:52:22 -0400 | [diff] [blame] | 525 | if (radeon_encoder->output_csc != RADEON_OUTPUT_CSC_BYPASS) { |
| 526 | if (drm_rgb_quant_range_selectable(radeon_connector_edid(connector))) { |
| 527 | if (radeon_encoder->output_csc == RADEON_OUTPUT_CSC_TVRGB) |
| 528 | frame.quantization_range = HDMI_QUANTIZATION_RANGE_LIMITED; |
| 529 | else |
| 530 | frame.quantization_range = HDMI_QUANTIZATION_RANGE_FULL; |
| 531 | } else { |
| 532 | frame.quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT; |
| 533 | } |
Alex Deucher | a1dcc27 | 2015-02-23 17:14:47 -0500 | [diff] [blame] | 534 | } |
| 535 | |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 536 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 537 | if (err < 0) { |
| 538 | DRM_ERROR("failed to pack AVI infoframe: %d\n", err); |
| 539 | return err; |
| 540 | } |
| 541 | |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 542 | if (dig && dig->afmt && radeon_encoder->audio && |
| 543 | radeon_encoder->audio->set_avi_packet) |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 544 | radeon_encoder->audio->set_avi_packet(rdev, dig->afmt->offset, |
| 545 | buffer, sizeof(buffer)); |
| 546 | |
| 547 | return 0; |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 548 | } |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * calculate CTS and N values if they are not found in the table |
| 552 | */ |
| 553 | static void radeon_audio_calc_cts(unsigned int clock, int *CTS, int *N, int freq) |
| 554 | { |
| 555 | int n, cts; |
| 556 | unsigned long div, mul; |
| 557 | |
| 558 | /* Safe, but overly large values */ |
| 559 | n = 128 * freq; |
| 560 | cts = clock * 1000; |
| 561 | |
| 562 | /* Smallest valid fraction */ |
| 563 | div = gcd(n, cts); |
| 564 | |
| 565 | n /= div; |
| 566 | cts /= div; |
| 567 | |
| 568 | /* |
| 569 | * The optimal N is 128*freq/1000. Calculate the closest larger |
| 570 | * value that doesn't truncate any bits. |
| 571 | */ |
| 572 | mul = ((128*freq/1000) + (n-1))/n; |
| 573 | |
| 574 | n *= mul; |
| 575 | cts *= mul; |
| 576 | |
| 577 | /* Check that we are in spec (not always possible) */ |
| 578 | if (n < (128*freq/1500)) |
| 579 | printk(KERN_WARNING "Calculated ACR N value is too small. You may experience audio problems.\n"); |
| 580 | if (n > (128*freq/300)) |
| 581 | printk(KERN_WARNING "Calculated ACR N value is too large. You may experience audio problems.\n"); |
| 582 | |
| 583 | *N = n; |
| 584 | *CTS = cts; |
| 585 | |
| 586 | DRM_DEBUG("Calculated ACR timing N=%d CTS=%d for frequency %d\n", |
| 587 | *N, *CTS, freq); |
| 588 | } |
| 589 | |
| 590 | static const struct radeon_hdmi_acr* radeon_audio_acr(unsigned int clock) |
| 591 | { |
| 592 | static struct radeon_hdmi_acr res; |
| 593 | u8 i; |
| 594 | |
| 595 | static const struct radeon_hdmi_acr hdmi_predefined_acr[] = { |
| 596 | /* 32kHz 44.1kHz 48kHz */ |
| 597 | /* Clock N CTS N CTS N CTS */ |
| 598 | { 25175, 4096, 25175, 28224, 125875, 6144, 25175 }, /* 25,20/1.001 MHz */ |
| 599 | { 25200, 4096, 25200, 6272, 28000, 6144, 25200 }, /* 25.20 MHz */ |
| 600 | { 27000, 4096, 27000, 6272, 30000, 6144, 27000 }, /* 27.00 MHz */ |
| 601 | { 27027, 4096, 27027, 6272, 30030, 6144, 27027 }, /* 27.00*1.001 MHz */ |
| 602 | { 54000, 4096, 54000, 6272, 60000, 6144, 54000 }, /* 54.00 MHz */ |
| 603 | { 54054, 4096, 54054, 6272, 60060, 6144, 54054 }, /* 54.00*1.001 MHz */ |
| 604 | { 74176, 4096, 74176, 5733, 75335, 6144, 74176 }, /* 74.25/1.001 MHz */ |
| 605 | { 74250, 4096, 74250, 6272, 82500, 6144, 74250 }, /* 74.25 MHz */ |
| 606 | { 148352, 4096, 148352, 5733, 150670, 6144, 148352 }, /* 148.50/1.001 MHz */ |
| 607 | { 148500, 4096, 148500, 6272, 165000, 6144, 148500 }, /* 148.50 MHz */ |
| 608 | }; |
| 609 | |
| 610 | /* Precalculated values for common clocks */ |
| 611 | for (i = 0; i < ARRAY_SIZE(hdmi_predefined_acr); i++) |
| 612 | if (hdmi_predefined_acr[i].clock == clock) |
| 613 | return &hdmi_predefined_acr[i]; |
| 614 | |
| 615 | /* And odd clocks get manually calculated */ |
| 616 | radeon_audio_calc_cts(clock, &res.cts_32khz, &res.n_32khz, 32000); |
| 617 | radeon_audio_calc_cts(clock, &res.cts_44_1khz, &res.n_44_1khz, 44100); |
| 618 | radeon_audio_calc_cts(clock, &res.cts_48khz, &res.n_48khz, 48000); |
| 619 | |
| 620 | return &res; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * update the N and CTS parameters for a given pixel clock rate |
| 625 | */ |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 626 | static void radeon_audio_update_acr(struct drm_encoder *encoder, unsigned int clock) |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 627 | { |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 628 | const struct radeon_hdmi_acr *acr = radeon_audio_acr(clock); |
| 629 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 630 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 631 | |
| 632 | if (!dig || !dig->afmt) |
| 633 | return; |
| 634 | |
| 635 | if (radeon_encoder->audio && radeon_encoder->audio->update_acr) |
| 636 | radeon_encoder->audio->update_acr(encoder, dig->afmt->offset, acr); |
| 637 | } |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 638 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 639 | static void radeon_audio_set_vbi_packet(struct drm_encoder *encoder) |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 640 | { |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 641 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 642 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 643 | |
| 644 | if (!dig || !dig->afmt) |
| 645 | return; |
| 646 | |
| 647 | if (radeon_encoder->audio && radeon_encoder->audio->set_vbi_packet) |
| 648 | radeon_encoder->audio->set_vbi_packet(encoder, dig->afmt->offset); |
| 649 | } |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 650 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 651 | static void radeon_hdmi_set_color_depth(struct drm_encoder *encoder) |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 652 | { |
| 653 | int bpc = 8; |
| 654 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 655 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 656 | |
| 657 | if (!dig || !dig->afmt) |
| 658 | return; |
| 659 | |
| 660 | if (encoder->crtc) { |
| 661 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 662 | bpc = radeon_crtc->bpc; |
| 663 | } |
| 664 | |
| 665 | if (radeon_encoder->audio && radeon_encoder->audio->set_color_depth) |
| 666 | radeon_encoder->audio->set_color_depth(encoder, dig->afmt->offset, bpc); |
| 667 | } |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 668 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 669 | static void radeon_audio_set_audio_packet(struct drm_encoder *encoder) |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 670 | { |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 671 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 672 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 673 | |
| 674 | if (!dig || !dig->afmt) |
| 675 | return; |
| 676 | |
| 677 | if (radeon_encoder->audio && radeon_encoder->audio->set_audio_packet) |
| 678 | radeon_encoder->audio->set_audio_packet(encoder, dig->afmt->offset); |
| 679 | } |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 680 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 681 | static void radeon_audio_set_mute(struct drm_encoder *encoder, bool mute) |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 682 | { |
Alex Deucher | f4c6c08 | 2015-01-13 12:41:40 -0500 | [diff] [blame] | 683 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 684 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 685 | |
| 686 | if (!dig || !dig->afmt) |
| 687 | return; |
| 688 | |
| 689 | if (radeon_encoder->audio && radeon_encoder->audio->set_mute) |
| 690 | radeon_encoder->audio->set_mute(encoder, dig->afmt->offset, mute); |
| 691 | } |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 692 | |
| 693 | /* |
| 694 | * update the info frames with the data from the current display mode |
| 695 | */ |
| 696 | static void radeon_audio_hdmi_mode_set(struct drm_encoder *encoder, |
Alex Deucher | 3ed7cee | 2015-02-27 10:42:21 -0500 | [diff] [blame] | 697 | struct drm_display_mode *mode) |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 698 | { |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 699 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 700 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 701 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 702 | |
| 703 | if (!dig || !dig->afmt) |
| 704 | return; |
| 705 | |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 706 | if (!connector) |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 707 | return; |
| 708 | |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 709 | if (drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
| 710 | radeon_audio_set_mute(encoder, true); |
| 711 | |
| 712 | radeon_audio_write_speaker_allocation(encoder); |
| 713 | radeon_audio_write_sad_regs(encoder); |
| 714 | radeon_audio_write_latency_fields(encoder, mode); |
| 715 | radeon_audio_set_dto(encoder, mode->clock); |
| 716 | radeon_audio_set_vbi_packet(encoder); |
| 717 | radeon_hdmi_set_color_depth(encoder); |
| 718 | radeon_audio_update_acr(encoder, mode->clock); |
| 719 | radeon_audio_set_audio_packet(encoder); |
| 720 | radeon_audio_select_pin(encoder); |
| 721 | |
| 722 | if (radeon_audio_set_avi_packet(encoder, mode) < 0) |
| 723 | return; |
| 724 | |
| 725 | radeon_audio_set_mute(encoder, false); |
| 726 | } else { |
| 727 | radeon_hdmi_set_color_depth(encoder); |
| 728 | |
| 729 | if (radeon_audio_set_avi_packet(encoder, mode) < 0) |
| 730 | return; |
| 731 | } |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 732 | } |
| 733 | |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 734 | static void radeon_audio_dp_mode_set(struct drm_encoder *encoder, |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 735 | struct drm_display_mode *mode) |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 736 | { |
| 737 | struct drm_device *dev = encoder->dev; |
| 738 | struct radeon_device *rdev = dev->dev_private; |
| 739 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 740 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | aeefd07 | 2015-02-27 14:43:47 -0500 | [diff] [blame] | 741 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 742 | |
| 743 | if (!dig || !dig->afmt) |
| 744 | return; |
| 745 | |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 746 | if (!connector) |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 747 | return; |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 748 | |
| 749 | if (drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
| 750 | radeon_audio_write_speaker_allocation(encoder); |
| 751 | radeon_audio_write_sad_regs(encoder); |
| 752 | radeon_audio_write_latency_fields(encoder, mode); |
Slava Grigorev | c9a392e | 2016-01-26 16:45:10 -0500 | [diff] [blame] | 753 | radeon_audio_set_dto(encoder, rdev->clock.vco_freq * 10); |
Alex Deucher | 7726e72 | 2015-07-24 00:42:02 -0400 | [diff] [blame] | 754 | radeon_audio_set_audio_packet(encoder); |
| 755 | radeon_audio_select_pin(encoder); |
| 756 | |
| 757 | if (radeon_audio_set_avi_packet(encoder, mode) < 0) |
| 758 | return; |
| 759 | } |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 760 | } |
| 761 | |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 762 | void radeon_audio_mode_set(struct drm_encoder *encoder, |
Alex Deucher | d0ea397 | 2015-07-23 10:01:09 -0400 | [diff] [blame] | 763 | struct drm_display_mode *mode) |
Slava Grigorev | 6e72376 | 2014-12-10 10:43:51 -0500 | [diff] [blame] | 764 | { |
| 765 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 766 | |
| 767 | if (radeon_encoder->audio && radeon_encoder->audio->mode_set) |
| 768 | radeon_encoder->audio->mode_set(encoder, mode); |
| 769 | } |
Slava Grigorev | 6f94569 | 2014-12-10 14:52:43 -0500 | [diff] [blame] | 770 | |
| 771 | void radeon_audio_dpms(struct drm_encoder *encoder, int mode) |
| 772 | { |
| 773 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 774 | |
| 775 | if (radeon_encoder->audio && radeon_encoder->audio->dpms) |
| 776 | radeon_encoder->audio->dpms(encoder, mode == DRM_MODE_DPMS_ON); |
| 777 | } |
Slava Grigorev | a64c9da | 2016-01-26 16:56:25 -0500 | [diff] [blame] | 778 | |
| 779 | unsigned int radeon_audio_decode_dfs_div(unsigned int div) |
| 780 | { |
| 781 | if (div >= 8 && div < 64) |
| 782 | return (div - 8) * 25 + 200; |
| 783 | else if (div >= 64 && div < 96) |
| 784 | return (div - 64) * 50 + 1600; |
| 785 | else if (div >= 96 && div < 128) |
| 786 | return (div - 96) * 100 + 3200; |
| 787 | else |
| 788 | return 0; |
| 789 | } |