diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2013-07-31 16:51:33 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2013-08-30 16:30:45 -0400 |
commit | b530602fd4625f763344e455902981b22f85f609 (patch) | |
tree | fb1c932b2bf74b76fbbdc198d527a698088500c2 /drivers/gpu/drm/radeon/dce6_afmt.c | |
parent | a4d39e68949f5b4f7b426be63782b421018f741a (diff) |
drm/radeon: add audio support for DCE6/8 GPUs (v12)
Similar to DCE4/5, but supports multiple audio pins
which can be assigned per afmt block.
v2: rework the driver to handle more than one audio
pin.
v3: try different dto reg
v4: properly program dto
v5 (ck): change dto programming order
v6: program speaker allocation block
v7: rebase
v8: rebase on Rafał's changes
v9: integrated Rafał's comments, update to latest
drm_edid_to_speaker_allocation API
v10: add missing line break in error message
v11: add back audio enabled messages
v12: fix copy paste typo in r600_audio_enable
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Rafał Miłecki <zajec5@gmail.com>
Diffstat (limited to 'drivers/gpu/drm/radeon/dce6_afmt.c')
-rw-r--r-- | drivers/gpu/drm/radeon/dce6_afmt.c | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c new file mode 100644 index 000000000000..0d9a6a21088c --- /dev/null +++ b/drivers/gpu/drm/radeon/dce6_afmt.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | * Copyright 2013 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 | */ | ||
23 | #include <linux/hdmi.h> | ||
24 | #include <drm/drmP.h> | ||
25 | #include "radeon.h" | ||
26 | #include "sid.h" | ||
27 | |||
28 | static u32 dce6_endpoint_rreg(struct radeon_device *rdev, | ||
29 | u32 block_offset, u32 reg) | ||
30 | { | ||
31 | u32 r; | ||
32 | |||
33 | WREG32(AZ_F0_CODEC_ENDPOINT_INDEX + block_offset, reg); | ||
34 | r = RREG32(AZ_F0_CODEC_ENDPOINT_DATA + block_offset); | ||
35 | return r; | ||
36 | } | ||
37 | |||
38 | static void dce6_endpoint_wreg(struct radeon_device *rdev, | ||
39 | u32 block_offset, u32 reg, u32 v) | ||
40 | { | ||
41 | if (ASIC_IS_DCE8(rdev)) | ||
42 | WREG32(AZ_F0_CODEC_ENDPOINT_INDEX + block_offset, reg); | ||
43 | else | ||
44 | WREG32(AZ_F0_CODEC_ENDPOINT_INDEX + block_offset, | ||
45 | AZ_ENDPOINT_REG_WRITE_EN | AZ_ENDPOINT_REG_INDEX(reg)); | ||
46 | WREG32(AZ_F0_CODEC_ENDPOINT_DATA + block_offset, v); | ||
47 | } | ||
48 | |||
49 | #define RREG32_ENDPOINT(block, reg) dce6_endpoint_rreg(rdev, (block), (reg)) | ||
50 | #define WREG32_ENDPOINT(block, reg, v) dce6_endpoint_wreg(rdev, (block), (reg), (v)) | ||
51 | |||
52 | |||
53 | static void dce6_afmt_get_connected_pins(struct radeon_device *rdev) | ||
54 | { | ||
55 | int i; | ||
56 | u32 offset, tmp; | ||
57 | |||
58 | for (i = 0; i < rdev->audio.num_pins; i++) { | ||
59 | offset = rdev->audio.pin[i].offset; | ||
60 | tmp = RREG32_ENDPOINT(offset, | ||
61 | AZ_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT); | ||
62 | if (((tmp & PORT_CONNECTIVITY_MASK) >> PORT_CONNECTIVITY_SHIFT) == 1) | ||
63 | rdev->audio.pin[i].connected = false; | ||
64 | else | ||
65 | rdev->audio.pin[i].connected = true; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev) | ||
70 | { | ||
71 | int i; | ||
72 | |||
73 | dce6_afmt_get_connected_pins(rdev); | ||
74 | |||
75 | for (i = 0; i < rdev->audio.num_pins; i++) { | ||
76 | if (rdev->audio.pin[i].connected) | ||
77 | return &rdev->audio.pin[i]; | ||
78 | } | ||
79 | DRM_ERROR("No connected audio pins found!\n"); | ||
80 | return NULL; | ||
81 | } | ||
82 | |||
83 | void dce6_afmt_select_pin(struct drm_encoder *encoder) | ||
84 | { | ||
85 | struct radeon_device *rdev = encoder->dev->dev_private; | ||
86 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); | ||
87 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; | ||
88 | u32 offset = dig->afmt->offset; | ||
89 | u32 id = dig->afmt->pin->id; | ||
90 | |||
91 | if (!dig->afmt->pin) | ||
92 | return; | ||
93 | |||
94 | WREG32(AFMT_AUDIO_SRC_CONTROL + offset, AFMT_AUDIO_SRC_SELECT(id)); | ||
95 | } | ||
96 | |||
97 | void dce6_afmt_write_sad_regs(struct drm_encoder *encoder) | ||
98 | { | ||
99 | struct radeon_device *rdev = encoder->dev->dev_private; | ||
100 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); | ||
101 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; | ||
102 | u32 offset, tmp; | ||
103 | struct drm_connector *connector; | ||
104 | struct radeon_connector *radeon_connector = NULL; | ||
105 | struct cea_sad *sads; | ||
106 | int i, sad_count, sadb_count; | ||
107 | u8 *sadb; | ||
108 | |||
109 | static const u16 eld_reg_to_type[][2] = { | ||
110 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, | ||
111 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, | ||
112 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, | ||
113 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, | ||
114 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, | ||
115 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, | ||
116 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, | ||
117 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, | ||
118 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, | ||
119 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, | ||
120 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, | ||
121 | { AZ_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, | ||
122 | }; | ||
123 | |||
124 | if (!dig->afmt->pin) | ||
125 | return; | ||
126 | |||
127 | offset = dig->afmt->pin->offset; | ||
128 | |||
129 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { | ||
130 | if (connector->encoder == encoder) | ||
131 | radeon_connector = to_radeon_connector(connector); | ||
132 | } | ||
133 | |||
134 | if (!radeon_connector) { | ||
135 | DRM_ERROR("Couldn't find encoder's connector\n"); | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | sad_count = drm_edid_to_sad(radeon_connector->edid, &sads); | ||
140 | if (sad_count < 0) { | ||
141 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); | ||
142 | return; | ||
143 | } | ||
144 | BUG_ON(!sads); | ||
145 | |||
146 | sadb_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb); | ||
147 | if (sadb_count < 0) { | ||
148 | DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sadb_count); | ||
149 | return; | ||
150 | } | ||
151 | |||
152 | /* program the speaker allocation */ | ||
153 | tmp = RREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER); | ||
154 | tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); | ||
155 | /* set HDMI mode */ | ||
156 | tmp |= HDMI_CONNECTION; | ||
157 | if (sadb_count) | ||
158 | tmp |= SPEAKER_ALLOCATION(sadb[0]); | ||
159 | else | ||
160 | tmp |= SPEAKER_ALLOCATION(5); /* stereo */ | ||
161 | WREG32_ENDPOINT(offset, AZ_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp); | ||
162 | |||
163 | for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { | ||
164 | u32 value = 0; | ||
165 | int j; | ||
166 | |||
167 | for (j = 0; j < sad_count; j++) { | ||
168 | struct cea_sad *sad = &sads[j]; | ||
169 | |||
170 | if (sad->format == eld_reg_to_type[i][1]) { | ||
171 | value = MAX_CHANNELS(sad->channels) | | ||
172 | DESCRIPTOR_BYTE_2(sad->byte2) | | ||
173 | SUPPORTED_FREQUENCIES(sad->freq); | ||
174 | if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) | ||
175 | value |= SUPPORTED_FREQUENCIES_STEREO(sad->freq); | ||
176 | break; | ||
177 | } | ||
178 | } | ||
179 | WREG32_ENDPOINT(offset, eld_reg_to_type[i][0], value); | ||
180 | } | ||
181 | |||
182 | kfree(sads); | ||
183 | kfree(sadb); | ||
184 | } | ||
185 | |||
186 | static int dce6_audio_chipset_supported(struct radeon_device *rdev) | ||
187 | { | ||
188 | return !ASIC_IS_NODCE(rdev); | ||
189 | } | ||
190 | |||
191 | static void dce6_audio_enable(struct radeon_device *rdev, | ||
192 | struct r600_audio_pin *pin, | ||
193 | bool enable) | ||
194 | { | ||
195 | WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL, | ||
196 | AUDIO_ENABLED); | ||
197 | DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id); | ||
198 | } | ||
199 | |||
200 | static const u32 pin_offsets[7] = | ||
201 | { | ||
202 | (0x5e00 - 0x5e00), | ||
203 | (0x5e18 - 0x5e00), | ||
204 | (0x5e30 - 0x5e00), | ||
205 | (0x5e48 - 0x5e00), | ||
206 | (0x5e60 - 0x5e00), | ||
207 | (0x5e78 - 0x5e00), | ||
208 | (0x5e90 - 0x5e00), | ||
209 | }; | ||
210 | |||
211 | int dce6_audio_init(struct radeon_device *rdev) | ||
212 | { | ||
213 | int i; | ||
214 | |||
215 | if (!radeon_audio || !dce6_audio_chipset_supported(rdev)) | ||
216 | return 0; | ||
217 | |||
218 | rdev->audio.enabled = true; | ||
219 | |||
220 | if (ASIC_IS_DCE8(rdev)) | ||
221 | rdev->audio.num_pins = 7; | ||
222 | else | ||
223 | rdev->audio.num_pins = 6; | ||
224 | |||
225 | for (i = 0; i < rdev->audio.num_pins; i++) { | ||
226 | rdev->audio.pin[i].channels = -1; | ||
227 | rdev->audio.pin[i].rate = -1; | ||
228 | rdev->audio.pin[i].bits_per_sample = -1; | ||
229 | rdev->audio.pin[i].status_bits = 0; | ||
230 | rdev->audio.pin[i].category_code = 0; | ||
231 | rdev->audio.pin[i].connected = false; | ||
232 | rdev->audio.pin[i].offset = pin_offsets[i]; | ||
233 | rdev->audio.pin[i].id = i; | ||
234 | dce6_audio_enable(rdev, &rdev->audio.pin[i], true); | ||
235 | } | ||
236 | |||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | void dce6_audio_fini(struct radeon_device *rdev) | ||
241 | { | ||
242 | int i; | ||
243 | |||
244 | if (!rdev->audio.enabled) | ||
245 | return; | ||
246 | |||
247 | for (i = 0; i < rdev->audio.num_pins; i++) | ||
248 | dce6_audio_enable(rdev, &rdev->audio.pin[i], false); | ||
249 | |||
250 | rdev->audio.enabled = false; | ||
251 | } | ||