Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Generic routines and proc interface for ELD(EDID Like Data) information |
| 3 | * |
| 4 | * Copyright(c) 2008 Intel Corporation. |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 5 | * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi> |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 6 | * |
| 7 | * Authors: |
| 8 | * Wu Fengguang <wfg@linux.intel.com> |
| 9 | * |
| 10 | * This driver is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This driver is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include <asm/unaligned.h> |
Subhransu S. Prusty | 2f6e8a8 | 2016-03-04 19:59:51 +0530 | [diff] [blame] | 29 | #include <sound/hda_chmap.h> |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 30 | #include "hda_codec.h" |
| 31 | #include "hda_local.h" |
| 32 | |
| 33 | enum eld_versions { |
| 34 | ELD_VER_CEA_861D = 2, |
| 35 | ELD_VER_PARTIAL = 31, |
| 36 | }; |
| 37 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 38 | enum cea_edid_versions { |
| 39 | CEA_EDID_VER_NONE = 0, |
| 40 | CEA_EDID_VER_CEA861 = 1, |
| 41 | CEA_EDID_VER_CEA861A = 2, |
| 42 | CEA_EDID_VER_CEA861BCD = 3, |
| 43 | CEA_EDID_VER_RESERVED = 4, |
| 44 | }; |
| 45 | |
Takashi Iwai | d5cf00c | 2015-08-17 15:06:52 +0200 | [diff] [blame] | 46 | static const char * const eld_connection_type_names[4] = { |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 47 | "HDMI", |
Wu Fengguang | 9415e1c | 2008-11-22 09:40:56 +0800 | [diff] [blame] | 48 | "DisplayPort", |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 49 | "2-reserved", |
| 50 | "3-reserved" |
| 51 | }; |
| 52 | |
| 53 | enum cea_audio_coding_types { |
| 54 | AUDIO_CODING_TYPE_REF_STREAM_HEADER = 0, |
| 55 | AUDIO_CODING_TYPE_LPCM = 1, |
| 56 | AUDIO_CODING_TYPE_AC3 = 2, |
| 57 | AUDIO_CODING_TYPE_MPEG1 = 3, |
| 58 | AUDIO_CODING_TYPE_MP3 = 4, |
| 59 | AUDIO_CODING_TYPE_MPEG2 = 5, |
| 60 | AUDIO_CODING_TYPE_AACLC = 6, |
| 61 | AUDIO_CODING_TYPE_DTS = 7, |
| 62 | AUDIO_CODING_TYPE_ATRAC = 8, |
| 63 | AUDIO_CODING_TYPE_SACD = 9, |
| 64 | AUDIO_CODING_TYPE_EAC3 = 10, |
| 65 | AUDIO_CODING_TYPE_DTS_HD = 11, |
| 66 | AUDIO_CODING_TYPE_MLP = 12, |
| 67 | AUDIO_CODING_TYPE_DST = 13, |
| 68 | AUDIO_CODING_TYPE_WMAPRO = 14, |
| 69 | AUDIO_CODING_TYPE_REF_CXT = 15, |
| 70 | /* also include valid xtypes below */ |
| 71 | AUDIO_CODING_TYPE_HE_AAC = 15, |
| 72 | AUDIO_CODING_TYPE_HE_AAC2 = 16, |
| 73 | AUDIO_CODING_TYPE_MPEG_SURROUND = 17, |
| 74 | }; |
| 75 | |
| 76 | enum cea_audio_coding_xtypes { |
| 77 | AUDIO_CODING_XTYPE_HE_REF_CT = 0, |
| 78 | AUDIO_CODING_XTYPE_HE_AAC = 1, |
| 79 | AUDIO_CODING_XTYPE_HE_AAC2 = 2, |
| 80 | AUDIO_CODING_XTYPE_MPEG_SURROUND = 3, |
| 81 | AUDIO_CODING_XTYPE_FIRST_RESERVED = 4, |
| 82 | }; |
| 83 | |
Takashi Iwai | d5cf00c | 2015-08-17 15:06:52 +0200 | [diff] [blame] | 84 | static const char * const cea_audio_coding_type_names[] = { |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 85 | /* 0 */ "undefined", |
| 86 | /* 1 */ "LPCM", |
| 87 | /* 2 */ "AC-3", |
| 88 | /* 3 */ "MPEG1", |
| 89 | /* 4 */ "MP3", |
| 90 | /* 5 */ "MPEG2", |
| 91 | /* 6 */ "AAC-LC", |
| 92 | /* 7 */ "DTS", |
| 93 | /* 8 */ "ATRAC", |
Wu Fengguang | 06f69d1 | 2008-11-19 15:14:01 +0800 | [diff] [blame] | 94 | /* 9 */ "DSD (One Bit Audio)", |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 95 | /* 10 */ "E-AC-3/DD+ (Dolby Digital Plus)", |
| 96 | /* 11 */ "DTS-HD", |
| 97 | /* 12 */ "MLP (Dolby TrueHD)", |
| 98 | /* 13 */ "DST", |
| 99 | /* 14 */ "WMAPro", |
| 100 | /* 15 */ "HE-AAC", |
| 101 | /* 16 */ "HE-AACv2", |
| 102 | /* 17 */ "MPEG Surround", |
| 103 | }; |
| 104 | |
| 105 | /* |
| 106 | * The following two lists are shared between |
| 107 | * - HDMI audio InfoFrame (source to sink) |
Wu Fengguang | 4e19c58 | 2008-11-19 15:13:59 +0800 | [diff] [blame] | 108 | * - CEA E-EDID Extension (sink to source) |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 109 | */ |
| 110 | |
| 111 | /* |
| 112 | * SS1:SS0 index => sample size |
| 113 | */ |
| 114 | static int cea_sample_sizes[4] = { |
| 115 | 0, /* 0: Refer to Stream Header */ |
| 116 | AC_SUPPCM_BITS_16, /* 1: 16 bits */ |
| 117 | AC_SUPPCM_BITS_20, /* 2: 20 bits */ |
| 118 | AC_SUPPCM_BITS_24, /* 3: 24 bits */ |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * SF2:SF1:SF0 index => sampling frequency |
| 123 | */ |
| 124 | static int cea_sampling_frequencies[8] = { |
| 125 | 0, /* 0: Refer to Stream Header */ |
| 126 | SNDRV_PCM_RATE_32000, /* 1: 32000Hz */ |
| 127 | SNDRV_PCM_RATE_44100, /* 2: 44100Hz */ |
| 128 | SNDRV_PCM_RATE_48000, /* 3: 48000Hz */ |
| 129 | SNDRV_PCM_RATE_88200, /* 4: 88200Hz */ |
| 130 | SNDRV_PCM_RATE_96000, /* 5: 96000Hz */ |
| 131 | SNDRV_PCM_RATE_176400, /* 6: 176400Hz */ |
| 132 | SNDRV_PCM_RATE_192000, /* 7: 192000Hz */ |
| 133 | }; |
| 134 | |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 135 | static unsigned int hdmi_get_eld_data(struct hda_codec *codec, hda_nid_t nid, |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 136 | int byte_index) |
| 137 | { |
| 138 | unsigned int val; |
| 139 | |
| 140 | val = snd_hda_codec_read(codec, nid, 0, |
| 141 | AC_VERB_GET_HDMI_ELDD, byte_index); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 142 | #ifdef BE_PARANOID |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 143 | codec_info(codec, "HDMI: ELD data byte %d: 0x%x\n", byte_index, val); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 144 | #endif |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 145 | return val; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | #define GRAB_BITS(buf, byte, lowbit, bits) \ |
| 149 | ({ \ |
| 150 | BUILD_BUG_ON(lowbit > 7); \ |
| 151 | BUILD_BUG_ON(bits > 8); \ |
| 152 | BUILD_BUG_ON(bits <= 0); \ |
| 153 | \ |
| 154 | (buf[byte] >> (lowbit)) & ((1 << (bits)) - 1); \ |
| 155 | }) |
| 156 | |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 157 | static void hdmi_update_short_audio_desc(struct hda_codec *codec, |
| 158 | struct cea_sad *a, |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 159 | const unsigned char *buf) |
| 160 | { |
| 161 | int i; |
| 162 | int val; |
| 163 | |
| 164 | val = GRAB_BITS(buf, 1, 0, 7); |
| 165 | a->rates = 0; |
| 166 | for (i = 0; i < 7; i++) |
| 167 | if (val & (1 << i)) |
| 168 | a->rates |= cea_sampling_frequencies[i + 1]; |
| 169 | |
| 170 | a->channels = GRAB_BITS(buf, 0, 0, 3); |
| 171 | a->channels++; |
| 172 | |
Anssi Hannula | 0bbaee3 | 2010-12-07 21:19:23 +0200 | [diff] [blame] | 173 | a->sample_bits = 0; |
| 174 | a->max_bitrate = 0; |
| 175 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 176 | a->format = GRAB_BITS(buf, 0, 3, 4); |
| 177 | switch (a->format) { |
| 178 | case AUDIO_CODING_TYPE_REF_STREAM_HEADER: |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 179 | codec_info(codec, "HDMI: audio coding type 0 not expected\n"); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 180 | break; |
| 181 | |
| 182 | case AUDIO_CODING_TYPE_LPCM: |
| 183 | val = GRAB_BITS(buf, 2, 0, 3); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 184 | for (i = 0; i < 3; i++) |
| 185 | if (val & (1 << i)) |
| 186 | a->sample_bits |= cea_sample_sizes[i + 1]; |
| 187 | break; |
| 188 | |
| 189 | case AUDIO_CODING_TYPE_AC3: |
| 190 | case AUDIO_CODING_TYPE_MPEG1: |
| 191 | case AUDIO_CODING_TYPE_MP3: |
| 192 | case AUDIO_CODING_TYPE_MPEG2: |
| 193 | case AUDIO_CODING_TYPE_AACLC: |
| 194 | case AUDIO_CODING_TYPE_DTS: |
| 195 | case AUDIO_CODING_TYPE_ATRAC: |
| 196 | a->max_bitrate = GRAB_BITS(buf, 2, 0, 8); |
| 197 | a->max_bitrate *= 8000; |
| 198 | break; |
| 199 | |
| 200 | case AUDIO_CODING_TYPE_SACD: |
| 201 | break; |
| 202 | |
| 203 | case AUDIO_CODING_TYPE_EAC3: |
| 204 | break; |
| 205 | |
| 206 | case AUDIO_CODING_TYPE_DTS_HD: |
| 207 | break; |
| 208 | |
| 209 | case AUDIO_CODING_TYPE_MLP: |
| 210 | break; |
| 211 | |
| 212 | case AUDIO_CODING_TYPE_DST: |
| 213 | break; |
| 214 | |
| 215 | case AUDIO_CODING_TYPE_WMAPRO: |
| 216 | a->profile = GRAB_BITS(buf, 2, 0, 3); |
| 217 | break; |
| 218 | |
| 219 | case AUDIO_CODING_TYPE_REF_CXT: |
| 220 | a->format = GRAB_BITS(buf, 2, 3, 5); |
| 221 | if (a->format == AUDIO_CODING_XTYPE_HE_REF_CT || |
| 222 | a->format >= AUDIO_CODING_XTYPE_FIRST_RESERVED) { |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 223 | codec_info(codec, |
| 224 | "HDMI: audio coding xtype %d not expected\n", |
| 225 | a->format); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 226 | a->format = 0; |
| 227 | } else |
| 228 | a->format += AUDIO_CODING_TYPE_HE_AAC - |
| 229 | AUDIO_CODING_XTYPE_HE_AAC; |
| 230 | break; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Be careful, ELD buf could be totally rubbish! |
| 236 | */ |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 237 | int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e, |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 238 | const unsigned char *buf, int size) |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 239 | { |
| 240 | int mnl; |
| 241 | int i; |
| 242 | |
Takashi Iwai | 18014fd | 2015-11-13 12:51:49 +0100 | [diff] [blame] | 243 | memset(e, 0, sizeof(*e)); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 244 | e->eld_ver = GRAB_BITS(buf, 0, 3, 5); |
| 245 | if (e->eld_ver != ELD_VER_CEA_861D && |
| 246 | e->eld_ver != ELD_VER_PARTIAL) { |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 247 | codec_info(codec, "HDMI: Unknown ELD version %d\n", e->eld_ver); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 248 | goto out_fail; |
| 249 | } |
| 250 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 251 | e->baseline_len = GRAB_BITS(buf, 2, 0, 8); |
| 252 | mnl = GRAB_BITS(buf, 4, 0, 5); |
| 253 | e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3); |
| 254 | |
| 255 | e->support_hdcp = GRAB_BITS(buf, 5, 0, 1); |
| 256 | e->support_ai = GRAB_BITS(buf, 5, 1, 1); |
| 257 | e->conn_type = GRAB_BITS(buf, 5, 2, 2); |
| 258 | e->sad_count = GRAB_BITS(buf, 5, 4, 4); |
| 259 | |
| 260 | e->aud_synch_delay = GRAB_BITS(buf, 6, 0, 8) * 2; |
| 261 | e->spk_alloc = GRAB_BITS(buf, 7, 0, 7); |
| 262 | |
| 263 | e->port_id = get_unaligned_le64(buf + 8); |
| 264 | |
| 265 | /* not specified, but the spec's tendency is little endian */ |
| 266 | e->manufacture_id = get_unaligned_le16(buf + 16); |
| 267 | e->product_id = get_unaligned_le16(buf + 18); |
| 268 | |
| 269 | if (mnl > ELD_MAX_MNL) { |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 270 | codec_info(codec, "HDMI: MNL is reserved value %d\n", mnl); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 271 | goto out_fail; |
| 272 | } else if (ELD_FIXED_BYTES + mnl > size) { |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 273 | codec_info(codec, "HDMI: out of range MNL %d\n", mnl); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 274 | goto out_fail; |
| 275 | } else |
Wu Fengguang | f5b2d0e | 2011-06-29 14:26:07 +0800 | [diff] [blame] | 276 | strlcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 277 | |
| 278 | for (i = 0; i < e->sad_count; i++) { |
| 279 | if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) { |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 280 | codec_info(codec, "HDMI: out of range SAD %d\n", i); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 281 | goto out_fail; |
| 282 | } |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 283 | hdmi_update_short_audio_desc(codec, e->sad + i, |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 284 | buf + ELD_FIXED_BYTES + mnl + 3 * i); |
| 285 | } |
| 286 | |
Wu Fengguang | 2d1b439 | 2011-11-16 16:29:48 +0800 | [diff] [blame] | 287 | /* |
| 288 | * HDMI sink's ELD info cannot always be retrieved for now, e.g. |
| 289 | * in console or for audio devices. Assume the highest speakers |
| 290 | * configuration, to _not_ prohibit multi-channel audio playback. |
| 291 | */ |
| 292 | if (!e->spk_alloc) |
| 293 | e->spk_alloc = 0xffff; |
| 294 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 295 | return 0; |
| 296 | |
| 297 | out_fail: |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 298 | return -EINVAL; |
| 299 | } |
| 300 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 301 | int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid) |
| 302 | { |
| 303 | return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE, |
| 304 | AC_DIPSIZE_ELD_BUF); |
| 305 | } |
| 306 | |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 307 | int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid, |
| 308 | unsigned char *buf, int *eld_size) |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 309 | { |
| 310 | int i; |
Mengdong Lin | 2ef5692 | 2013-03-28 05:20:22 -0400 | [diff] [blame] | 311 | int ret = 0; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 312 | int size; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 313 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 314 | /* |
| 315 | * ELD size is initialized to zero in caller function. If no errors and |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 316 | * ELD is valid, actual eld_size is assigned. |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 317 | */ |
| 318 | |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 319 | size = snd_hdmi_get_eld_size(codec, nid); |
| 320 | if (size == 0) { |
| 321 | /* wfg: workaround for ASUS P5E-VM HDMI board */ |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 322 | codec_info(codec, "HDMI: ELD buf size is 0, force 128\n"); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 323 | size = 128; |
| 324 | } |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 325 | if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 326 | codec_info(codec, "HDMI: invalid ELD buf size %d\n", size); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 327 | return -ERANGE; |
| 328 | } |
| 329 | |
Pierre-Louis Bossart | 14bc52b | 2011-09-30 16:35:41 -0500 | [diff] [blame] | 330 | /* set ELD buffer */ |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 331 | for (i = 0; i < size; i++) { |
| 332 | unsigned int val = hdmi_get_eld_data(codec, nid, i); |
Wu Fengguang | a370fc6 | 2011-11-22 16:46:23 +0800 | [diff] [blame] | 333 | /* |
| 334 | * Graphics driver might be writing to ELD buffer right now. |
| 335 | * Just abort. The caller will repoll after a while. |
| 336 | */ |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 337 | if (!(val & AC_ELDD_ELD_VALID)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 338 | codec_info(codec, "HDMI: invalid ELD data byte %d\n", i); |
Wu Fengguang | a370fc6 | 2011-11-22 16:46:23 +0800 | [diff] [blame] | 339 | ret = -EINVAL; |
| 340 | goto error; |
| 341 | } |
| 342 | val &= AC_ELDD_ELD_DATA; |
| 343 | /* |
| 344 | * The first byte cannot be zero. This can happen on some DVI |
| 345 | * connections. Some Intel chips may also need some 250ms delay |
| 346 | * to return non-zero ELD data, even when the graphics driver |
| 347 | * correctly writes ELD content before setting ELD_valid bit. |
| 348 | */ |
| 349 | if (!val && !i) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 350 | codec_dbg(codec, "HDMI: 0 ELD data\n"); |
Wu Fengguang | a370fc6 | 2011-11-22 16:46:23 +0800 | [diff] [blame] | 351 | ret = -EINVAL; |
| 352 | goto error; |
| 353 | } |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 354 | buf[i] = val; |
| 355 | } |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 356 | |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 357 | *eld_size = size; |
Takashi Iwai | b6acf01 | 2011-08-20 09:14:45 +0200 | [diff] [blame] | 358 | error: |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 359 | return ret; |
| 360 | } |
| 361 | |
Takashi Iwai | a11e9b1 | 2014-10-29 15:06:01 +0100 | [diff] [blame] | 362 | /* |
Pierre-Louis Bossart | af65cbf | 2011-10-05 15:14:20 -0500 | [diff] [blame] | 363 | * SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with |
| 364 | * hdmi-specific routine. |
| 365 | */ |
| 366 | static void hdmi_print_pcm_rates(int pcm, char *buf, int buflen) |
| 367 | { |
| 368 | static unsigned int alsa_rates[] = { |
Anssi Hannula | 25dc16f | 2012-03-13 17:43:02 +0200 | [diff] [blame] | 369 | 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, |
| 370 | 88200, 96000, 176400, 192000, 384000 |
Pierre-Louis Bossart | af65cbf | 2011-10-05 15:14:20 -0500 | [diff] [blame] | 371 | }; |
| 372 | int i, j; |
| 373 | |
| 374 | for (i = 0, j = 0; i < ARRAY_SIZE(alsa_rates); i++) |
| 375 | if (pcm & (1 << i)) |
| 376 | j += snprintf(buf + j, buflen - j, " %d", |
| 377 | alsa_rates[i]); |
| 378 | |
| 379 | buf[j] = '\0'; /* necessary when j == 0 */ |
| 380 | } |
| 381 | |
Takashi Iwai | f71ff0d | 2011-10-06 08:16:29 +0200 | [diff] [blame] | 382 | #define SND_PRINT_RATES_ADVISED_BUFSIZE 80 |
| 383 | |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 384 | static void hdmi_show_short_audio_desc(struct hda_codec *codec, |
| 385 | struct cea_sad *a) |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 386 | { |
| 387 | char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 388 | char buf2[8 + SND_PRINT_BITS_ADVISED_BUFSIZE] = ", bits ="; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 389 | |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 390 | if (!a->format) |
| 391 | return; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 392 | |
Pierre-Louis Bossart | af65cbf | 2011-10-05 15:14:20 -0500 | [diff] [blame] | 393 | hdmi_print_pcm_rates(a->rates, buf, sizeof(buf)); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 394 | |
| 395 | if (a->format == AUDIO_CODING_TYPE_LPCM) |
David Henningsson | d757534 | 2011-01-25 19:44:26 +0100 | [diff] [blame] | 396 | snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8); |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 397 | else if (a->max_bitrate) |
| 398 | snprintf(buf2, sizeof(buf2), |
| 399 | ", max bitrate = %d", a->max_bitrate); |
| 400 | else |
| 401 | buf2[0] = '\0'; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 402 | |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 403 | codec_dbg(codec, |
| 404 | "HDMI: supports coding type %s: channels = %d, rates =%s%s\n", |
| 405 | cea_audio_coding_type_names[a->format], |
| 406 | a->channels, buf, buf2); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 407 | } |
| 408 | |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 409 | void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e) |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 410 | { |
| 411 | int i; |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 412 | |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 413 | codec_dbg(codec, "HDMI: detected monitor %s at connection type %s\n", |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 414 | e->monitor_name, |
| 415 | eld_connection_type_names[e->conn_type]); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 416 | |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 417 | if (e->spk_alloc) { |
| 418 | char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 419 | snd_hdac_print_channel_allocation(e->spk_alloc, buf, sizeof(buf)); |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 420 | codec_dbg(codec, "HDMI: available speakers:%s\n", buf); |
Wu Fengguang | ae8cb4c | 2008-11-19 15:14:03 +0800 | [diff] [blame] | 421 | } |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 422 | |
| 423 | for (i = 0; i < e->sad_count; i++) |
Takashi Iwai | 79514d4 | 2014-06-06 18:04:34 +0200 | [diff] [blame] | 424 | hdmi_show_short_audio_desc(codec, e->sad + i); |
Wu Fengguang | 7f4a9f4 | 2008-11-18 11:47:52 +0800 | [diff] [blame] | 425 | } |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 426 | |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 427 | #ifdef CONFIG_SND_PROC_FS |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 428 | |
| 429 | static void hdmi_print_sad_info(int i, struct cea_sad *a, |
| 430 | struct snd_info_buffer *buffer) |
| 431 | { |
Wu Fengguang | d39b435 | 2008-11-19 15:14:02 +0800 | [diff] [blame] | 432 | char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 433 | |
| 434 | snd_iprintf(buffer, "sad%d_coding_type\t[0x%x] %s\n", |
| 435 | i, a->format, cea_audio_coding_type_names[a->format]); |
| 436 | snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels); |
| 437 | |
Pierre-Louis Bossart | af65cbf | 2011-10-05 15:14:20 -0500 | [diff] [blame] | 438 | hdmi_print_pcm_rates(a->rates, buf, sizeof(buf)); |
Wu Fengguang | 06f69d1 | 2008-11-19 15:14:01 +0800 | [diff] [blame] | 439 | snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf); |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 440 | |
Wu Fengguang | d39b435 | 2008-11-19 15:14:02 +0800 | [diff] [blame] | 441 | if (a->format == AUDIO_CODING_TYPE_LPCM) { |
| 442 | snd_print_pcm_bits(a->sample_bits, buf, sizeof(buf)); |
| 443 | snd_iprintf(buffer, "sad%d_bits\t\t[0x%x]%s\n", |
| 444 | i, a->sample_bits, buf); |
| 445 | } |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 446 | |
| 447 | if (a->max_bitrate) |
| 448 | snd_iprintf(buffer, "sad%d_max_bitrate\t%d\n", |
| 449 | i, a->max_bitrate); |
| 450 | |
| 451 | if (a->profile) |
| 452 | snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile); |
| 453 | } |
| 454 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 455 | void snd_hdmi_print_eld_info(struct hdmi_eld *eld, |
| 456 | struct snd_info_buffer *buffer) |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 457 | { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 458 | struct parsed_hdmi_eld *e = &eld->info; |
Wu Fengguang | 903b21d | 2008-11-19 08:56:16 +0800 | [diff] [blame] | 459 | char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 460 | int i; |
Takashi Iwai | d5cf00c | 2015-08-17 15:06:52 +0200 | [diff] [blame] | 461 | static const char * const eld_version_names[32] = { |
Wu Fengguang | 4805286 | 2008-11-22 09:40:57 +0800 | [diff] [blame] | 462 | "reserved", |
| 463 | "reserved", |
| 464 | "CEA-861D or below", |
| 465 | [3 ... 30] = "reserved", |
| 466 | [31] = "partial" |
| 467 | }; |
Takashi Iwai | d5cf00c | 2015-08-17 15:06:52 +0200 | [diff] [blame] | 468 | static const char * const cea_edid_version_names[8] = { |
Wu Fengguang | 4805286 | 2008-11-22 09:40:57 +0800 | [diff] [blame] | 469 | "no CEA EDID Timing Extension block present", |
| 470 | "CEA-861", |
| 471 | "CEA-861-A", |
| 472 | "CEA-861-B, C or D", |
| 473 | [4 ... 7] = "reserved" |
| 474 | }; |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 475 | |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 476 | snd_iprintf(buffer, "monitor_present\t\t%d\n", eld->monitor_present); |
| 477 | snd_iprintf(buffer, "eld_valid\t\t%d\n", eld->eld_valid); |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 478 | if (!eld->eld_valid) |
Stephen Warren | 5d44f92 | 2011-05-24 17:11:17 -0600 | [diff] [blame] | 479 | return; |
Wu Fengguang | db74210 | 2008-11-21 12:34:05 +0800 | [diff] [blame] | 480 | snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 481 | snd_iprintf(buffer, "connection_type\t\t%s\n", |
| 482 | eld_connection_type_names[e->conn_type]); |
| 483 | snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver, |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 484 | eld_version_names[e->eld_ver]); |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 485 | snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver, |
| 486 | cea_edid_version_names[e->cea_edid_ver]); |
| 487 | snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id); |
| 488 | snd_iprintf(buffer, "product_id\t\t0x%x\n", e->product_id); |
| 489 | snd_iprintf(buffer, "port_id\t\t\t0x%llx\n", (long long)e->port_id); |
| 490 | snd_iprintf(buffer, "support_hdcp\t\t%d\n", e->support_hdcp); |
| 491 | snd_iprintf(buffer, "support_ai\t\t%d\n", e->support_ai); |
| 492 | snd_iprintf(buffer, "audio_sync_delay\t%d\n", e->aud_synch_delay); |
| 493 | |
Subhransu S. Prusty | bb63f72 | 2016-03-04 19:59:52 +0530 | [diff] [blame] | 494 | snd_hdac_print_channel_allocation(e->spk_alloc, buf, sizeof(buf)); |
Wu Fengguang | 06f69d1 | 2008-11-19 15:14:01 +0800 | [diff] [blame] | 495 | snd_iprintf(buffer, "speakers\t\t[0x%x]%s\n", e->spk_alloc, buf); |
Wu Fengguang | 5f1e71b | 2008-11-18 11:47:53 +0800 | [diff] [blame] | 496 | |
| 497 | snd_iprintf(buffer, "sad_count\t\t%d\n", e->sad_count); |
| 498 | |
| 499 | for (i = 0; i < e->sad_count; i++) |
| 500 | hdmi_print_sad_info(i, e->sad + i, buffer); |
| 501 | } |
| 502 | |
Takashi Iwai | a4e9a38 | 2013-10-17 18:21:12 +0200 | [diff] [blame] | 503 | void snd_hdmi_write_eld_info(struct hdmi_eld *eld, |
| 504 | struct snd_info_buffer *buffer) |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 505 | { |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 506 | struct parsed_hdmi_eld *e = &eld->info; |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 507 | char line[64]; |
| 508 | char name[64]; |
| 509 | char *sname; |
| 510 | long long val; |
Roel Kluin | 78735cf | 2009-07-29 14:35:20 +0200 | [diff] [blame] | 511 | unsigned int n; |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 512 | |
| 513 | while (!snd_info_get_line(buffer, line, sizeof(line))) { |
| 514 | if (sscanf(line, "%s %llx", name, &val) != 2) |
| 515 | continue; |
Wu Fengguang | acb0599 | 2008-11-22 09:40:54 +0800 | [diff] [blame] | 516 | /* |
| 517 | * We don't allow modification to these fields: |
| 518 | * monitor_name manufacture_id product_id |
| 519 | * eld_version edid_version |
| 520 | */ |
Wu Fengguang | 23ccc2b | 2009-11-18 12:38:01 +0800 | [diff] [blame] | 521 | if (!strcmp(name, "monitor_present")) |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 522 | eld->monitor_present = val; |
Wu Fengguang | 23ccc2b | 2009-11-18 12:38:01 +0800 | [diff] [blame] | 523 | else if (!strcmp(name, "eld_valid")) |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 524 | eld->eld_valid = val; |
Wu Fengguang | 23ccc2b | 2009-11-18 12:38:01 +0800 | [diff] [blame] | 525 | else if (!strcmp(name, "connection_type")) |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 526 | e->conn_type = val; |
| 527 | else if (!strcmp(name, "port_id")) |
| 528 | e->port_id = val; |
| 529 | else if (!strcmp(name, "support_hdcp")) |
| 530 | e->support_hdcp = val; |
| 531 | else if (!strcmp(name, "support_ai")) |
| 532 | e->support_ai = val; |
| 533 | else if (!strcmp(name, "audio_sync_delay")) |
| 534 | e->aud_synch_delay = val; |
| 535 | else if (!strcmp(name, "speakers")) |
| 536 | e->spk_alloc = val; |
| 537 | else if (!strcmp(name, "sad_count")) |
| 538 | e->sad_count = val; |
| 539 | else if (!strncmp(name, "sad", 3)) { |
| 540 | sname = name + 4; |
| 541 | n = name[3] - '0'; |
| 542 | if (name[4] >= '0' && name[4] <= '9') { |
| 543 | sname++; |
| 544 | n = 10 * n + name[4] - '0'; |
| 545 | } |
Roel Kluin | 78735cf | 2009-07-29 14:35:20 +0200 | [diff] [blame] | 546 | if (n >= ELD_MAX_SAD) |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 547 | continue; |
| 548 | if (!strcmp(sname, "_coding_type")) |
| 549 | e->sad[n].format = val; |
| 550 | else if (!strcmp(sname, "_channels")) |
| 551 | e->sad[n].channels = val; |
| 552 | else if (!strcmp(sname, "_rates")) |
| 553 | e->sad[n].rates = val; |
| 554 | else if (!strcmp(sname, "_bits")) |
| 555 | e->sad[n].sample_bits = val; |
| 556 | else if (!strcmp(sname, "_max_bitrate")) |
| 557 | e->sad[n].max_bitrate = val; |
Wu Fengguang | acb0599 | 2008-11-22 09:40:54 +0800 | [diff] [blame] | 558 | else if (!strcmp(sname, "_profile")) |
| 559 | e->sad[n].profile = val; |
Wu Fengguang | acdda79 | 2008-11-21 11:41:50 +0800 | [diff] [blame] | 560 | if (n >= e->sad_count) |
| 561 | e->sad_count = n + 1; |
| 562 | } |
| 563 | } |
| 564 | } |
Jie Yang | cd6a650 | 2015-05-27 19:45:45 +0800 | [diff] [blame] | 565 | #endif /* CONFIG_SND_PROC_FS */ |
Takashi Iwai | 274714f | 2010-08-19 08:11:53 +0200 | [diff] [blame] | 566 | |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 567 | /* update PCM info based on ELD */ |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 568 | void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e, |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 569 | struct hda_pcm_stream *hinfo) |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 570 | { |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 571 | u32 rates; |
| 572 | u64 formats; |
| 573 | unsigned int maxbps; |
| 574 | unsigned int channels_max; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 575 | int i; |
| 576 | |
Anssi Hannula | 3dc8642 | 2010-12-07 20:56:19 +0200 | [diff] [blame] | 577 | /* assume basic audio support (the basic audio flag is not in ELD; |
| 578 | * however, all audio capable sinks are required to support basic |
| 579 | * audio) */ |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 580 | rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | |
| 581 | SNDRV_PCM_RATE_48000; |
| 582 | formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 583 | maxbps = 16; |
| 584 | channels_max = 2; |
David Henningsson | 1613d6b | 2013-02-19 16:11:24 +0100 | [diff] [blame] | 585 | for (i = 0; i < e->sad_count; i++) { |
| 586 | struct cea_sad *a = &e->sad[i]; |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 587 | rates |= a->rates; |
| 588 | if (a->channels > channels_max) |
| 589 | channels_max = a->channels; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 590 | if (a->format == AUDIO_CODING_TYPE_LPCM) { |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 591 | if (a->sample_bits & AC_SUPPCM_BITS_20) { |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 592 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 593 | if (maxbps < 20) |
| 594 | maxbps = 20; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 595 | } |
| 596 | if (a->sample_bits & AC_SUPPCM_BITS_24) { |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 597 | formats |= SNDRV_PCM_FMTBIT_S32_LE; |
| 598 | if (maxbps < 24) |
| 599 | maxbps = 24; |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 604 | /* restrict the parameters by the values the codec provides */ |
Stephen Warren | 2def817 | 2011-06-01 11:14:20 -0600 | [diff] [blame] | 605 | hinfo->rates &= rates; |
| 606 | hinfo->formats &= formats; |
| 607 | hinfo->maxbps = min(hinfo->maxbps, maxbps); |
| 608 | hinfo->channels_max = min(hinfo->channels_max, channels_max); |
Takashi Iwai | bbbe339 | 2010-08-13 08:45:23 +0200 | [diff] [blame] | 609 | } |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 610 | |
| 611 | |
| 612 | /* ATI/AMD specific stuff (ELD emulation) */ |
| 613 | |
| 614 | #define ATI_VERB_SET_AUDIO_DESCRIPTOR 0x776 |
| 615 | #define ATI_VERB_SET_SINK_INFO_INDEX 0x780 |
| 616 | #define ATI_VERB_GET_SPEAKER_ALLOCATION 0xf70 |
| 617 | #define ATI_VERB_GET_AUDIO_DESCRIPTOR 0xf76 |
| 618 | #define ATI_VERB_GET_AUDIO_VIDEO_DELAY 0xf7b |
| 619 | #define ATI_VERB_GET_SINK_INFO_INDEX 0xf80 |
| 620 | #define ATI_VERB_GET_SINK_INFO_DATA 0xf81 |
| 621 | |
| 622 | #define ATI_SPKALLOC_SPKALLOC 0x007f |
| 623 | #define ATI_SPKALLOC_TYPE_HDMI 0x0100 |
| 624 | #define ATI_SPKALLOC_TYPE_DISPLAYPORT 0x0200 |
| 625 | |
| 626 | /* first three bytes are just standard SAD */ |
| 627 | #define ATI_AUDIODESC_CHANNELS 0x00000007 |
| 628 | #define ATI_AUDIODESC_RATES 0x0000ff00 |
| 629 | #define ATI_AUDIODESC_LPCM_STEREO_RATES 0xff000000 |
| 630 | |
| 631 | /* in standard HDMI VSDB format */ |
| 632 | #define ATI_DELAY_VIDEO_LATENCY 0x000000ff |
| 633 | #define ATI_DELAY_AUDIO_LATENCY 0x0000ff00 |
| 634 | |
| 635 | enum ati_sink_info_idx { |
| 636 | ATI_INFO_IDX_MANUFACTURER_ID = 0, |
| 637 | ATI_INFO_IDX_PRODUCT_ID = 1, |
| 638 | ATI_INFO_IDX_SINK_DESC_LEN = 2, |
| 639 | ATI_INFO_IDX_PORT_ID_LOW = 3, |
| 640 | ATI_INFO_IDX_PORT_ID_HIGH = 4, |
| 641 | ATI_INFO_IDX_SINK_DESC_FIRST = 5, |
| 642 | ATI_INFO_IDX_SINK_DESC_LAST = 22, /* max len 18 bytes */ |
| 643 | }; |
| 644 | |
| 645 | int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid, |
| 646 | unsigned char *buf, int *eld_size, bool rev3_or_later) |
| 647 | { |
| 648 | int spkalloc, ati_sad, aud_synch; |
| 649 | int sink_desc_len = 0; |
| 650 | int pos, i; |
| 651 | |
| 652 | /* ATI/AMD does not have ELD, emulate it */ |
| 653 | |
| 654 | spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0); |
| 655 | |
Anssi Hannula | 13122e6 | 2013-11-10 20:56:10 +0200 | [diff] [blame] | 656 | if (spkalloc <= 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 657 | codec_info(codec, "HDMI ATI/AMD: no speaker allocation for ELD\n"); |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 658 | return -EINVAL; |
| 659 | } |
| 660 | |
| 661 | memset(buf, 0, ELD_FIXED_BYTES + ELD_MAX_MNL + ELD_MAX_SAD * 3); |
| 662 | |
| 663 | /* version */ |
| 664 | buf[0] = ELD_VER_CEA_861D << 3; |
| 665 | |
| 666 | /* speaker allocation from EDID */ |
| 667 | buf[7] = spkalloc & ATI_SPKALLOC_SPKALLOC; |
| 668 | |
| 669 | /* is DisplayPort? */ |
| 670 | if (spkalloc & ATI_SPKALLOC_TYPE_DISPLAYPORT) |
| 671 | buf[5] |= 0x04; |
| 672 | |
| 673 | pos = ELD_FIXED_BYTES; |
| 674 | |
| 675 | if (rev3_or_later) { |
| 676 | int sink_info; |
| 677 | |
| 678 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_LOW); |
| 679 | sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 680 | put_unaligned_le32(sink_info, buf + 8); |
| 681 | |
| 682 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_HIGH); |
| 683 | sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 684 | put_unaligned_le32(sink_info, buf + 12); |
| 685 | |
| 686 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_MANUFACTURER_ID); |
| 687 | sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 688 | put_unaligned_le16(sink_info, buf + 16); |
| 689 | |
| 690 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PRODUCT_ID); |
| 691 | sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 692 | put_unaligned_le16(sink_info, buf + 18); |
| 693 | |
| 694 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_LEN); |
| 695 | sink_desc_len = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 696 | |
| 697 | if (sink_desc_len > ELD_MAX_MNL) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 698 | codec_info(codec, "HDMI ATI/AMD: Truncating HDMI sink description with length %d\n", |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 699 | sink_desc_len); |
| 700 | sink_desc_len = ELD_MAX_MNL; |
| 701 | } |
| 702 | |
| 703 | buf[4] |= sink_desc_len; |
| 704 | |
| 705 | for (i = 0; i < sink_desc_len; i++) { |
| 706 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_FIRST + i); |
| 707 | buf[pos++] = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | for (i = AUDIO_CODING_TYPE_LPCM; i <= AUDIO_CODING_TYPE_WMAPRO; i++) { |
| 712 | if (i == AUDIO_CODING_TYPE_SACD || i == AUDIO_CODING_TYPE_DST) |
| 713 | continue; /* not handled by ATI/AMD */ |
| 714 | |
| 715 | snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_AUDIO_DESCRIPTOR, i << 3); |
| 716 | ati_sad = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_DESCRIPTOR, 0); |
| 717 | |
Anssi Hannula | 13122e6 | 2013-11-10 20:56:10 +0200 | [diff] [blame] | 718 | if (ati_sad <= 0) |
| 719 | continue; |
| 720 | |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 721 | if (ati_sad & ATI_AUDIODESC_RATES) { |
| 722 | /* format is supported, copy SAD as-is */ |
| 723 | buf[pos++] = (ati_sad & 0x0000ff) >> 0; |
| 724 | buf[pos++] = (ati_sad & 0x00ff00) >> 8; |
| 725 | buf[pos++] = (ati_sad & 0xff0000) >> 16; |
| 726 | } |
| 727 | |
| 728 | if (i == AUDIO_CODING_TYPE_LPCM |
| 729 | && (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES) |
| 730 | && (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES) >> 16 != (ati_sad & ATI_AUDIODESC_RATES)) { |
| 731 | /* for PCM there is a separate stereo rate mask */ |
| 732 | buf[pos++] = ((ati_sad & 0x000000ff) & ~ATI_AUDIODESC_CHANNELS) | 0x1; |
| 733 | /* rates from the extra byte */ |
| 734 | buf[pos++] = (ati_sad & 0xff000000) >> 24; |
| 735 | buf[pos++] = (ati_sad & 0x00ff0000) >> 16; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if (pos == ELD_FIXED_BYTES + sink_desc_len) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 740 | codec_info(codec, "HDMI ATI/AMD: no audio descriptors for ELD\n"); |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 741 | return -EINVAL; |
| 742 | } |
| 743 | |
Anssi Hannula | a566682 | 2013-11-10 20:56:11 +0200 | [diff] [blame] | 744 | /* |
| 745 | * HDMI VSDB latency format: |
| 746 | * separately for both audio and video: |
| 747 | * 0 field not valid or unknown latency |
| 748 | * [1..251] msecs = (x-1)*2 (max 500ms with x = 251 = 0xfb) |
| 749 | * 255 audio/video not supported |
| 750 | * |
| 751 | * HDA latency format: |
| 752 | * single value indicating video latency relative to audio: |
| 753 | * 0 unknown or 0ms |
| 754 | * [1..250] msecs = x*2 (max 500ms with x = 250 = 0xfa) |
| 755 | * [251..255] reserved |
| 756 | */ |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 757 | aud_synch = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_VIDEO_DELAY, 0); |
| 758 | if ((aud_synch & ATI_DELAY_VIDEO_LATENCY) && (aud_synch & ATI_DELAY_AUDIO_LATENCY)) { |
Anssi Hannula | a566682 | 2013-11-10 20:56:11 +0200 | [diff] [blame] | 759 | int video_latency_hdmi = (aud_synch & ATI_DELAY_VIDEO_LATENCY); |
| 760 | int audio_latency_hdmi = (aud_synch & ATI_DELAY_AUDIO_LATENCY) >> 8; |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 761 | |
Anssi Hannula | a566682 | 2013-11-10 20:56:11 +0200 | [diff] [blame] | 762 | if (video_latency_hdmi <= 0xfb && audio_latency_hdmi <= 0xfb && |
| 763 | video_latency_hdmi > audio_latency_hdmi) |
| 764 | buf[6] = video_latency_hdmi - audio_latency_hdmi; |
| 765 | /* else unknown/invalid or 0ms or video ahead of audio, so use zero */ |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 766 | } |
| 767 | |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 768 | /* SAD count */ |
| 769 | buf[5] |= ((pos - ELD_FIXED_BYTES - sink_desc_len) / 3) << 4; |
| 770 | |
Anssi Hannula | 679605c | 2013-11-10 22:57:42 +0200 | [diff] [blame] | 771 | /* Baseline ELD block length is 4-byte aligned */ |
| 772 | pos = round_up(pos, 4); |
| 773 | |
| 774 | /* Baseline ELD length (4-byte header is not counted in) */ |
| 775 | buf[2] = (pos - 4) / 4; |
| 776 | |
Anssi Hannula | 89250f8 | 2013-10-24 21:10:36 +0300 | [diff] [blame] | 777 | *eld_size = pos; |
| 778 | |
| 779 | return 0; |
| 780 | } |