ALSA: hdmi - merge common code for intelhdmi and nvhdmi

Create patch_hdmi.c to hold common code from intelhdmi and nvhdmi.

For now the patch_hdmi.c file is simply included by patch_intelhdmi.c
and patch_nvhdmi.c, and does not represent a real codec.

There are no behavior changes to intelhdmi. However nvhdmi made several
changes when copying code out of intelhdmi, which are all reverted in
this patch. Wei Ni confirmed that the reverted code actually works fine.

Tested-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by Wu Fengguang and committed by Takashi Iwai 079d88cc 4193d13b

+882 -1613
+845
sound/pci/hda/patch_hdmi.c
··· 1 + /* 2 + * 3 + * patch_hdmi.c - routines for HDMI/DisplayPort codecs 4 + * 5 + * Copyright(c) 2008-2010 Intel Corporation. All rights reserved. 6 + * 7 + * Authors: 8 + * Wu Fengguang <wfg@linux.intel.com> 9 + * 10 + * Maintained by: 11 + * Wu Fengguang <wfg@linux.intel.com> 12 + * 13 + * This program is free software; you can redistribute it and/or modify it 14 + * under the terms of the GNU General Public License as published by the Free 15 + * Software Foundation; either version 2 of the License, or (at your option) 16 + * any later version. 17 + * 18 + * This program is distributed in the hope that it will be useful, but 19 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21 + * for more details. 22 + * 23 + * You should have received a copy of the GNU General Public License 24 + * along with this program; if not, write to the Free Software Foundation, 25 + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 + */ 27 + 28 + 29 + struct hdmi_spec { 30 + int num_cvts; 31 + int num_pins; 32 + hda_nid_t cvt[MAX_HDMI_CVTS+1]; /* audio sources */ 33 + hda_nid_t pin[MAX_HDMI_PINS+1]; /* audio sinks */ 34 + 35 + /* 36 + * source connection for each pin 37 + */ 38 + hda_nid_t pin_cvt[MAX_HDMI_PINS+1]; 39 + 40 + /* 41 + * HDMI sink attached to each pin 42 + */ 43 + struct hdmi_eld sink_eld[MAX_HDMI_PINS]; 44 + 45 + /* 46 + * export one pcm per pipe 47 + */ 48 + struct hda_pcm pcm_rec[MAX_HDMI_CVTS]; 49 + 50 + /* 51 + * nvhdmi specific 52 + */ 53 + struct hda_multi_out multiout; 54 + unsigned int codec_type; 55 + }; 56 + 57 + 58 + struct hdmi_audio_infoframe { 59 + u8 type; /* 0x84 */ 60 + u8 ver; /* 0x01 */ 61 + u8 len; /* 0x0a */ 62 + 63 + u8 checksum; /* PB0 */ 64 + u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ 65 + u8 SS01_SF24; 66 + u8 CXT04; 67 + u8 CA; 68 + u8 LFEPBL01_LSV36_DM_INH7; 69 + u8 reserved[5]; /* PB6 - PB10 */ 70 + }; 71 + 72 + /* 73 + * CEA speaker placement: 74 + * 75 + * FLH FCH FRH 76 + * FLW FL FLC FC FRC FR FRW 77 + * 78 + * LFE 79 + * TC 80 + * 81 + * RL RLC RC RRC RR 82 + * 83 + * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to 84 + * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC. 85 + */ 86 + enum cea_speaker_placement { 87 + FL = (1 << 0), /* Front Left */ 88 + FC = (1 << 1), /* Front Center */ 89 + FR = (1 << 2), /* Front Right */ 90 + FLC = (1 << 3), /* Front Left Center */ 91 + FRC = (1 << 4), /* Front Right Center */ 92 + RL = (1 << 5), /* Rear Left */ 93 + RC = (1 << 6), /* Rear Center */ 94 + RR = (1 << 7), /* Rear Right */ 95 + RLC = (1 << 8), /* Rear Left Center */ 96 + RRC = (1 << 9), /* Rear Right Center */ 97 + LFE = (1 << 10), /* Low Frequency Effect */ 98 + FLW = (1 << 11), /* Front Left Wide */ 99 + FRW = (1 << 12), /* Front Right Wide */ 100 + FLH = (1 << 13), /* Front Left High */ 101 + FCH = (1 << 14), /* Front Center High */ 102 + FRH = (1 << 15), /* Front Right High */ 103 + TC = (1 << 16), /* Top Center */ 104 + }; 105 + 106 + /* 107 + * ELD SA bits in the CEA Speaker Allocation data block 108 + */ 109 + static int eld_speaker_allocation_bits[] = { 110 + [0] = FL | FR, 111 + [1] = LFE, 112 + [2] = FC, 113 + [3] = RL | RR, 114 + [4] = RC, 115 + [5] = FLC | FRC, 116 + [6] = RLC | RRC, 117 + /* the following are not defined in ELD yet */ 118 + [7] = FLW | FRW, 119 + [8] = FLH | FRH, 120 + [9] = TC, 121 + [10] = FCH, 122 + }; 123 + 124 + struct cea_channel_speaker_allocation { 125 + int ca_index; 126 + int speakers[8]; 127 + 128 + /* derived values, just for convenience */ 129 + int channels; 130 + int spk_mask; 131 + }; 132 + 133 + /* 134 + * ALSA sequence is: 135 + * 136 + * surround40 surround41 surround50 surround51 surround71 137 + * ch0 front left = = = = 138 + * ch1 front right = = = = 139 + * ch2 rear left = = = = 140 + * ch3 rear right = = = = 141 + * ch4 LFE center center center 142 + * ch5 LFE LFE 143 + * ch6 side left 144 + * ch7 side right 145 + * 146 + * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR} 147 + */ 148 + static int hdmi_channel_mapping[0x32][8] = { 149 + /* stereo */ 150 + [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 151 + /* 2.1 */ 152 + [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 153 + /* Dolby Surround */ 154 + [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 }, 155 + /* surround40 */ 156 + [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 }, 157 + /* 4ch */ 158 + [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 }, 159 + /* surround41 */ 160 + [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 }, 161 + /* surround50 */ 162 + [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 }, 163 + /* surround51 */ 164 + [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 }, 165 + /* 7.1 */ 166 + [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 }, 167 + }; 168 + 169 + /* 170 + * This is an ordered list! 171 + * 172 + * The preceding ones have better chances to be selected by 173 + * hdmi_setup_channel_allocation(). 174 + */ 175 + static struct cea_channel_speaker_allocation channel_allocations[] = { 176 + /* channel: 7 6 5 4 3 2 1 0 */ 177 + { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, 178 + /* 2.1 */ 179 + { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, 180 + /* Dolby Surround */ 181 + { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, 182 + /* surround40 */ 183 + { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, 184 + /* surround41 */ 185 + { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, 186 + /* surround50 */ 187 + { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, 188 + /* surround51 */ 189 + { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, 190 + /* 6.1 */ 191 + { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, 192 + /* surround71 */ 193 + { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, 194 + 195 + { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, 196 + { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, 197 + { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, 198 + { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, 199 + { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, 200 + { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, 201 + { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, 202 + { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, 203 + { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, 204 + { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, 205 + { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, 206 + { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, 207 + { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, 208 + { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, 209 + { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, 210 + { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, 211 + { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, 212 + { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, 213 + { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, 214 + { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, 215 + { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, 216 + { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, 217 + { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, 218 + { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } }, 219 + { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } }, 220 + { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } }, 221 + { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } }, 222 + { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } }, 223 + { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } }, 224 + { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } }, 225 + { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } }, 226 + { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } }, 227 + { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } }, 228 + { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } }, 229 + { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } }, 230 + { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } }, 231 + { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } }, 232 + { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } }, 233 + { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } }, 234 + { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } }, 235 + { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, 236 + }; 237 + 238 + 239 + /* 240 + * HDMI routines 241 + */ 242 + 243 + static int hda_node_index(hda_nid_t *nids, hda_nid_t nid) 244 + { 245 + int i; 246 + 247 + for (i = 0; nids[i]; i++) 248 + if (nids[i] == nid) 249 + return i; 250 + 251 + snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid); 252 + return -EINVAL; 253 + } 254 + 255 + static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid, 256 + struct hdmi_eld *eld) 257 + { 258 + if (!snd_hdmi_get_eld(eld, codec, pin_nid)) 259 + snd_hdmi_show_eld(eld); 260 + } 261 + 262 + #ifdef BE_PARANOID 263 + static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 264 + int *packet_index, int *byte_index) 265 + { 266 + int val; 267 + 268 + val = snd_hda_codec_read(codec, pin_nid, 0, 269 + AC_VERB_GET_HDMI_DIP_INDEX, 0); 270 + 271 + *packet_index = val >> 5; 272 + *byte_index = val & 0x1f; 273 + } 274 + #endif 275 + 276 + static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 277 + int packet_index, int byte_index) 278 + { 279 + int val; 280 + 281 + val = (packet_index << 5) | (byte_index & 0x1f); 282 + 283 + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 284 + } 285 + 286 + static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, 287 + unsigned char val) 288 + { 289 + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 290 + } 291 + 292 + static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid) 293 + { 294 + /* Unmute */ 295 + if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 296 + snd_hda_codec_write(codec, pin_nid, 0, 297 + AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 298 + /* Enable pin out */ 299 + snd_hda_codec_write(codec, pin_nid, 0, 300 + AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 301 + } 302 + 303 + static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid) 304 + { 305 + return 1 + snd_hda_codec_read(codec, nid, 0, 306 + AC_VERB_GET_CVT_CHAN_COUNT, 0); 307 + } 308 + 309 + static void hdmi_set_channel_count(struct hda_codec *codec, 310 + hda_nid_t nid, int chs) 311 + { 312 + if (chs != hdmi_get_channel_count(codec, nid)) 313 + snd_hda_codec_write(codec, nid, 0, 314 + AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 315 + } 316 + 317 + 318 + /* 319 + * Channel mapping routines 320 + */ 321 + 322 + /* 323 + * Compute derived values in channel_allocations[]. 324 + */ 325 + static void init_channel_allocations(void) 326 + { 327 + int i, j; 328 + struct cea_channel_speaker_allocation *p; 329 + 330 + for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 331 + p = channel_allocations + i; 332 + p->channels = 0; 333 + p->spk_mask = 0; 334 + for (j = 0; j < ARRAY_SIZE(p->speakers); j++) 335 + if (p->speakers[j]) { 336 + p->channels++; 337 + p->spk_mask |= p->speakers[j]; 338 + } 339 + } 340 + } 341 + 342 + /* 343 + * The transformation takes two steps: 344 + * 345 + * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask 346 + * spk_mask => (channel_allocations[]) => ai->CA 347 + * 348 + * TODO: it could select the wrong CA from multiple candidates. 349 + */ 350 + static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid, 351 + struct hdmi_audio_infoframe *ai) 352 + { 353 + struct hdmi_spec *spec = codec->spec; 354 + struct hdmi_eld *eld; 355 + int i; 356 + int spk_mask = 0; 357 + int channels = 1 + (ai->CC02_CT47 & 0x7); 358 + char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; 359 + 360 + /* 361 + * CA defaults to 0 for basic stereo audio 362 + */ 363 + if (channels <= 2) 364 + return 0; 365 + 366 + i = hda_node_index(spec->pin_cvt, nid); 367 + if (i < 0) 368 + return 0; 369 + eld = &spec->sink_eld[i]; 370 + 371 + /* 372 + * HDMI sink's ELD info cannot always be retrieved for now, e.g. 373 + * in console or for audio devices. Assume the highest speakers 374 + * configuration, to _not_ prohibit multi-channel audio playback. 375 + */ 376 + if (!eld->spk_alloc) 377 + eld->spk_alloc = 0xffff; 378 + 379 + /* 380 + * expand ELD's speaker allocation mask 381 + * 382 + * ELD tells the speaker mask in a compact(paired) form, 383 + * expand ELD's notions to match the ones used by Audio InfoFrame. 384 + */ 385 + for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 386 + if (eld->spk_alloc & (1 << i)) 387 + spk_mask |= eld_speaker_allocation_bits[i]; 388 + } 389 + 390 + /* search for the first working match in the CA table */ 391 + for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 392 + if (channels == channel_allocations[i].channels && 393 + (spk_mask & channel_allocations[i].spk_mask) == 394 + channel_allocations[i].spk_mask) { 395 + ai->CA = channel_allocations[i].ca_index; 396 + break; 397 + } 398 + } 399 + 400 + snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf)); 401 + snd_printdd(KERN_INFO 402 + "HDMI: select CA 0x%x for %d-channel allocation: %s\n", 403 + ai->CA, channels, buf); 404 + 405 + return ai->CA; 406 + } 407 + 408 + static void hdmi_debug_channel_mapping(struct hda_codec *codec, 409 + hda_nid_t pin_nid) 410 + { 411 + #ifdef CONFIG_SND_DEBUG_VERBOSE 412 + int i; 413 + int slot; 414 + 415 + for (i = 0; i < 8; i++) { 416 + slot = snd_hda_codec_read(codec, pin_nid, 0, 417 + AC_VERB_GET_HDMI_CHAN_SLOT, i); 418 + printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 419 + slot >> 4, slot & 0xf); 420 + } 421 + #endif 422 + } 423 + 424 + 425 + static void hdmi_setup_channel_mapping(struct hda_codec *codec, 426 + hda_nid_t pin_nid, 427 + struct hdmi_audio_infoframe *ai) 428 + { 429 + int i; 430 + int ca = ai->CA; 431 + int err; 432 + 433 + if (hdmi_channel_mapping[ca][1] == 0) { 434 + for (i = 0; i < channel_allocations[ca].channels; i++) 435 + hdmi_channel_mapping[ca][i] = i | (i << 4); 436 + for (; i < 8; i++) 437 + hdmi_channel_mapping[ca][i] = 0xf | (i << 4); 438 + } 439 + 440 + for (i = 0; i < 8; i++) { 441 + err = snd_hda_codec_write(codec, pin_nid, 0, 442 + AC_VERB_SET_HDMI_CHAN_SLOT, 443 + hdmi_channel_mapping[ca][i]); 444 + if (err) { 445 + snd_printdd(KERN_INFO "HDMI: channel mapping failed\n"); 446 + break; 447 + } 448 + } 449 + 450 + hdmi_debug_channel_mapping(codec, pin_nid); 451 + } 452 + 453 + 454 + /* 455 + * Audio InfoFrame routines 456 + */ 457 + 458 + /* 459 + * Enable Audio InfoFrame Transmission 460 + */ 461 + static void hdmi_start_infoframe_trans(struct hda_codec *codec, 462 + hda_nid_t pin_nid) 463 + { 464 + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 465 + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 466 + AC_DIPXMIT_BEST); 467 + } 468 + 469 + /* 470 + * Disable Audio InfoFrame Transmission 471 + */ 472 + static void hdmi_stop_infoframe_trans(struct hda_codec *codec, 473 + hda_nid_t pin_nid) 474 + { 475 + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 476 + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 477 + AC_DIPXMIT_DISABLE); 478 + } 479 + 480 + static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) 481 + { 482 + #ifdef CONFIG_SND_DEBUG_VERBOSE 483 + int i; 484 + int size; 485 + 486 + size = snd_hdmi_get_eld_size(codec, pin_nid); 487 + printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); 488 + 489 + for (i = 0; i < 8; i++) { 490 + size = snd_hda_codec_read(codec, pin_nid, 0, 491 + AC_VERB_GET_HDMI_DIP_SIZE, i); 492 + printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); 493 + } 494 + #endif 495 + } 496 + 497 + static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) 498 + { 499 + #ifdef BE_PARANOID 500 + int i, j; 501 + int size; 502 + int pi, bi; 503 + for (i = 0; i < 8; i++) { 504 + size = snd_hda_codec_read(codec, pin_nid, 0, 505 + AC_VERB_GET_HDMI_DIP_SIZE, i); 506 + if (size == 0) 507 + continue; 508 + 509 + hdmi_set_dip_index(codec, pin_nid, i, 0x0); 510 + for (j = 1; j < 1000; j++) { 511 + hdmi_write_dip_byte(codec, pin_nid, 0x0); 512 + hdmi_get_dip_index(codec, pin_nid, &pi, &bi); 513 + if (pi != i) 514 + snd_printd(KERN_INFO "dip index %d: %d != %d\n", 515 + bi, pi, i); 516 + if (bi == 0) /* byte index wrapped around */ 517 + break; 518 + } 519 + snd_printd(KERN_INFO 520 + "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", 521 + i, size, j); 522 + } 523 + #endif 524 + } 525 + 526 + static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai) 527 + { 528 + u8 *bytes = (u8 *)ai; 529 + u8 sum = 0; 530 + int i; 531 + 532 + ai->checksum = 0; 533 + 534 + for (i = 0; i < sizeof(*ai); i++) 535 + sum += bytes[i]; 536 + 537 + ai->checksum = -sum; 538 + } 539 + 540 + static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 541 + hda_nid_t pin_nid, 542 + struct hdmi_audio_infoframe *ai) 543 + { 544 + u8 *bytes = (u8 *)ai; 545 + int i; 546 + 547 + hdmi_debug_dip_size(codec, pin_nid); 548 + hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ 549 + 550 + hdmi_checksum_audio_infoframe(ai); 551 + 552 + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 553 + for (i = 0; i < sizeof(*ai); i++) 554 + hdmi_write_dip_byte(codec, pin_nid, bytes[i]); 555 + } 556 + 557 + static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, 558 + struct hdmi_audio_infoframe *ai) 559 + { 560 + u8 *bytes = (u8 *)ai; 561 + u8 val; 562 + int i; 563 + 564 + if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) 565 + != AC_DIPXMIT_BEST) 566 + return false; 567 + 568 + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 569 + for (i = 0; i < sizeof(*ai); i++) { 570 + val = snd_hda_codec_read(codec, pin_nid, 0, 571 + AC_VERB_GET_HDMI_DIP_DATA, 0); 572 + if (val != bytes[i]) 573 + return false; 574 + } 575 + 576 + return true; 577 + } 578 + 579 + static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid, 580 + struct snd_pcm_substream *substream) 581 + { 582 + struct hdmi_spec *spec = codec->spec; 583 + hda_nid_t pin_nid; 584 + int i; 585 + struct hdmi_audio_infoframe ai = { 586 + .type = 0x84, 587 + .ver = 0x01, 588 + .len = 0x0a, 589 + .CC02_CT47 = substream->runtime->channels - 1, 590 + }; 591 + 592 + hdmi_setup_channel_allocation(codec, nid, &ai); 593 + 594 + for (i = 0; i < spec->num_pins; i++) { 595 + if (spec->pin_cvt[i] != nid) 596 + continue; 597 + if (!spec->sink_eld[i].monitor_present) 598 + continue; 599 + 600 + pin_nid = spec->pin[i]; 601 + if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) { 602 + hdmi_setup_channel_mapping(codec, pin_nid, &ai); 603 + hdmi_stop_infoframe_trans(codec, pin_nid); 604 + hdmi_fill_audio_infoframe(codec, pin_nid, &ai); 605 + hdmi_start_infoframe_trans(codec, pin_nid); 606 + } 607 + } 608 + } 609 + 610 + 611 + /* 612 + * Unsolicited events 613 + */ 614 + 615 + static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 616 + { 617 + struct hdmi_spec *spec = codec->spec; 618 + int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 619 + int pind = !!(res & AC_UNSOL_RES_PD); 620 + int eldv = !!(res & AC_UNSOL_RES_ELDV); 621 + int index; 622 + 623 + printk(KERN_INFO 624 + "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 625 + tag, pind, eldv); 626 + 627 + index = hda_node_index(spec->pin, tag); 628 + if (index < 0) 629 + return; 630 + 631 + spec->sink_eld[index].monitor_present = pind; 632 + spec->sink_eld[index].eld_valid = eldv; 633 + 634 + if (pind && eldv) { 635 + hdmi_get_show_eld(codec, spec->pin[index], 636 + &spec->sink_eld[index]); 637 + /* TODO: do real things about ELD */ 638 + } 639 + } 640 + 641 + static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 642 + { 643 + int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 644 + int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 645 + int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 646 + int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 647 + 648 + printk(KERN_INFO 649 + "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 650 + tag, 651 + subtag, 652 + cp_state, 653 + cp_ready); 654 + 655 + /* TODO */ 656 + if (cp_state) 657 + ; 658 + if (cp_ready) 659 + ; 660 + } 661 + 662 + 663 + static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res) 664 + { 665 + struct hdmi_spec *spec = codec->spec; 666 + int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 667 + int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 668 + 669 + if (hda_node_index(spec->pin, tag) < 0) { 670 + snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 671 + return; 672 + } 673 + 674 + if (subtag == 0) 675 + hdmi_intrinsic_event(codec, res); 676 + else 677 + hdmi_non_intrinsic_event(codec, res); 678 + } 679 + 680 + /* 681 + * Callbacks 682 + */ 683 + 684 + static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid, 685 + u32 stream_tag, int format) 686 + { 687 + int tag; 688 + int fmt; 689 + 690 + tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4; 691 + fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0); 692 + 693 + snd_printdd("hdmi_setup_stream: " 694 + "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n", 695 + nid, 696 + tag == stream_tag ? "" : "new-", 697 + stream_tag, 698 + fmt == format ? "" : "new-", 699 + format); 700 + 701 + if (tag != stream_tag) 702 + snd_hda_codec_write(codec, nid, 0, 703 + AC_VERB_SET_CHANNEL_STREAMID, 704 + stream_tag << 4); 705 + if (fmt != format) 706 + snd_hda_codec_write(codec, nid, 0, 707 + AC_VERB_SET_STREAM_FORMAT, format); 708 + } 709 + 710 + /* 711 + * HDA/HDMI auto parsing 712 + */ 713 + 714 + static int hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid) 715 + { 716 + struct hdmi_spec *spec = codec->spec; 717 + hda_nid_t conn_list[HDA_MAX_CONNECTIONS]; 718 + int conn_len, curr; 719 + int index; 720 + 721 + if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 722 + snd_printk(KERN_WARNING 723 + "HDMI: pin %d wcaps %#x " 724 + "does not support connection list\n", 725 + pin_nid, get_wcaps(codec, pin_nid)); 726 + return -EINVAL; 727 + } 728 + 729 + conn_len = snd_hda_get_connections(codec, pin_nid, conn_list, 730 + HDA_MAX_CONNECTIONS); 731 + if (conn_len > 1) 732 + curr = snd_hda_codec_read(codec, pin_nid, 0, 733 + AC_VERB_GET_CONNECT_SEL, 0); 734 + else 735 + curr = 0; 736 + 737 + index = hda_node_index(spec->pin, pin_nid); 738 + if (index < 0) 739 + return -EINVAL; 740 + 741 + spec->pin_cvt[index] = conn_list[curr]; 742 + 743 + return 0; 744 + } 745 + 746 + static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid, 747 + struct hdmi_eld *eld) 748 + { 749 + int present = snd_hda_pin_sense(codec, pin_nid); 750 + 751 + eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 752 + eld->eld_valid = !!(present & AC_PINSENSE_ELDV); 753 + 754 + if (present & AC_PINSENSE_ELDV) 755 + hdmi_get_show_eld(codec, pin_nid, eld); 756 + } 757 + 758 + static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) 759 + { 760 + struct hdmi_spec *spec = codec->spec; 761 + 762 + if (spec->num_pins >= MAX_HDMI_PINS) { 763 + snd_printk(KERN_WARNING 764 + "HDMI: no space for pin %d\n", pin_nid); 765 + return -EINVAL; 766 + } 767 + 768 + hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]); 769 + 770 + spec->pin[spec->num_pins] = pin_nid; 771 + spec->num_pins++; 772 + 773 + /* 774 + * It is assumed that converter nodes come first in the node list and 775 + * hence have been registered and usable now. 776 + */ 777 + return hdmi_read_pin_conn(codec, pin_nid); 778 + } 779 + 780 + static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid) 781 + { 782 + struct hdmi_spec *spec = codec->spec; 783 + 784 + if (spec->num_cvts >= MAX_HDMI_CVTS) { 785 + snd_printk(KERN_WARNING 786 + "HDMI: no space for converter %d\n", nid); 787 + return -EINVAL; 788 + } 789 + 790 + spec->cvt[spec->num_cvts] = nid; 791 + spec->num_cvts++; 792 + 793 + return 0; 794 + } 795 + 796 + static int hdmi_parse_codec(struct hda_codec *codec) 797 + { 798 + hda_nid_t nid; 799 + int i, nodes; 800 + 801 + nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 802 + if (!nid || nodes < 0) { 803 + snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n"); 804 + return -EINVAL; 805 + } 806 + 807 + for (i = 0; i < nodes; i++, nid++) { 808 + unsigned int caps; 809 + unsigned int type; 810 + 811 + caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); 812 + type = get_wcaps_type(caps); 813 + 814 + if (!(caps & AC_WCAP_DIGITAL)) 815 + continue; 816 + 817 + switch (type) { 818 + case AC_WID_AUD_OUT: 819 + if (hdmi_add_cvt(codec, nid) < 0) 820 + return -EINVAL; 821 + break; 822 + case AC_WID_PIN: 823 + caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 824 + if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 825 + continue; 826 + if (hdmi_add_pin(codec, nid) < 0) 827 + return -EINVAL; 828 + break; 829 + } 830 + } 831 + 832 + /* 833 + * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event 834 + * can be lost and presence sense verb will become inaccurate if the 835 + * HDA link is powered off at hot plug or hw initialization time. 836 + */ 837 + #ifdef CONFIG_SND_HDA_POWER_SAVE 838 + if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) & 839 + AC_PWRST_EPSS)) 840 + codec->bus->power_keep_link_on = 1; 841 + #endif 842 + 843 + return 0; 844 + } 845 +
+13 -808
sound/pci/hda/patch_intelhdmi.c
··· 40 40 * 41 41 * The HDA correspondence of pipes/ports are converter/pin nodes. 42 42 */ 43 - #define INTEL_HDMI_CVTS 2 44 - #define INTEL_HDMI_PINS 3 43 + #define MAX_HDMI_CVTS 2 44 + #define MAX_HDMI_PINS 3 45 45 46 - static char *intel_hdmi_pcm_names[INTEL_HDMI_CVTS] = { 46 + #include "patch_hdmi.c" 47 + 48 + static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = { 47 49 "INTEL HDMI 0", 48 50 "INTEL HDMI 1", 49 51 }; 50 52 51 - struct intel_hdmi_spec { 52 - int num_cvts; 53 - int num_pins; 54 - hda_nid_t cvt[INTEL_HDMI_CVTS+1]; /* audio sources */ 55 - hda_nid_t pin[INTEL_HDMI_PINS+1]; /* audio sinks */ 56 - 57 - /* 58 - * source connection for each pin 59 - */ 60 - hda_nid_t pin_cvt[INTEL_HDMI_PINS+1]; 61 - 62 - /* 63 - * HDMI sink attached to each pin 64 - */ 65 - struct hdmi_eld sink_eld[INTEL_HDMI_PINS]; 66 - 67 - /* 68 - * export one pcm per pipe 69 - */ 70 - struct hda_pcm pcm_rec[INTEL_HDMI_CVTS]; 71 - }; 72 - 73 - struct hdmi_audio_infoframe { 74 - u8 type; /* 0x84 */ 75 - u8 ver; /* 0x01 */ 76 - u8 len; /* 0x0a */ 77 - 78 - u8 checksum; /* PB0 */ 79 - u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ 80 - u8 SS01_SF24; 81 - u8 CXT04; 82 - u8 CA; 83 - u8 LFEPBL01_LSV36_DM_INH7; 84 - u8 reserved[5]; /* PB6 - PB10 */ 85 - }; 86 - 87 53 /* 88 - * CEA speaker placement: 89 - * 90 - * FLH FCH FRH 91 - * FLW FL FLC FC FRC FR FRW 92 - * 93 - * LFE 94 - * TC 95 - * 96 - * RL RLC RC RRC RR 97 - * 98 - * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to 99 - * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC. 54 + * HDMI callbacks 100 55 */ 101 - enum cea_speaker_placement { 102 - FL = (1 << 0), /* Front Left */ 103 - FC = (1 << 1), /* Front Center */ 104 - FR = (1 << 2), /* Front Right */ 105 - FLC = (1 << 3), /* Front Left Center */ 106 - FRC = (1 << 4), /* Front Right Center */ 107 - RL = (1 << 5), /* Rear Left */ 108 - RC = (1 << 6), /* Rear Center */ 109 - RR = (1 << 7), /* Rear Right */ 110 - RLC = (1 << 8), /* Rear Left Center */ 111 - RRC = (1 << 9), /* Rear Right Center */ 112 - LFE = (1 << 10), /* Low Frequency Effect */ 113 - FLW = (1 << 11), /* Front Left Wide */ 114 - FRW = (1 << 12), /* Front Right Wide */ 115 - FLH = (1 << 13), /* Front Left High */ 116 - FCH = (1 << 14), /* Front Center High */ 117 - FRH = (1 << 15), /* Front Right High */ 118 - TC = (1 << 16), /* Top Center */ 119 - }; 120 - 121 - /* 122 - * ELD SA bits in the CEA Speaker Allocation data block 123 - */ 124 - static int eld_speaker_allocation_bits[] = { 125 - [0] = FL | FR, 126 - [1] = LFE, 127 - [2] = FC, 128 - [3] = RL | RR, 129 - [4] = RC, 130 - [5] = FLC | FRC, 131 - [6] = RLC | RRC, 132 - /* the following are not defined in ELD yet */ 133 - [7] = FLW | FRW, 134 - [8] = FLH | FRH, 135 - [9] = TC, 136 - [10] = FCH, 137 - }; 138 - 139 - struct cea_channel_speaker_allocation { 140 - int ca_index; 141 - int speakers[8]; 142 - 143 - /* derived values, just for convenience */ 144 - int channels; 145 - int spk_mask; 146 - }; 147 - 148 - /* 149 - * ALSA sequence is: 150 - * 151 - * surround40 surround41 surround50 surround51 surround71 152 - * ch0 front left = = = = 153 - * ch1 front right = = = = 154 - * ch2 rear left = = = = 155 - * ch3 rear right = = = = 156 - * ch4 LFE center center center 157 - * ch5 LFE LFE 158 - * ch6 side left 159 - * ch7 side right 160 - * 161 - * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR} 162 - */ 163 - static int hdmi_channel_mapping[0x32][8] = { 164 - /* stereo */ 165 - [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 166 - /* 2.1 */ 167 - [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 168 - /* Dolby Surround */ 169 - [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 }, 170 - /* surround40 */ 171 - [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 }, 172 - /* 4ch */ 173 - [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 }, 174 - /* surround41 */ 175 - [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 }, 176 - /* surround50 */ 177 - [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 }, 178 - /* surround51 */ 179 - [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 }, 180 - /* 7.1 */ 181 - [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 }, 182 - }; 183 - 184 - /* 185 - * This is an ordered list! 186 - * 187 - * The preceding ones have better chances to be selected by 188 - * hdmi_setup_channel_allocation(). 189 - */ 190 - static struct cea_channel_speaker_allocation channel_allocations[] = { 191 - /* channel: 7 6 5 4 3 2 1 0 */ 192 - { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, 193 - /* 2.1 */ 194 - { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, 195 - /* Dolby Surround */ 196 - { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, 197 - /* surround40 */ 198 - { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, 199 - /* surround41 */ 200 - { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, 201 - /* surround50 */ 202 - { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, 203 - /* surround51 */ 204 - { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, 205 - /* 6.1 */ 206 - { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, 207 - /* surround71 */ 208 - { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, 209 - 210 - { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, 211 - { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, 212 - { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, 213 - { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, 214 - { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, 215 - { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, 216 - { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, 217 - { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, 218 - { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, 219 - { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, 220 - { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, 221 - { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, 222 - { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, 223 - { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, 224 - { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, 225 - { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, 226 - { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, 227 - { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, 228 - { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, 229 - { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, 230 - { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, 231 - { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, 232 - { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, 233 - { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } }, 234 - { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } }, 235 - { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } }, 236 - { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } }, 237 - { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } }, 238 - { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } }, 239 - { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } }, 240 - { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } }, 241 - { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } }, 242 - { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } }, 243 - { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } }, 244 - { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } }, 245 - { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } }, 246 - { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } }, 247 - { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } }, 248 - { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } }, 249 - { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } }, 250 - { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, 251 - }; 252 - 253 - /* 254 - * HDA/HDMI auto parsing 255 - */ 256 - 257 - static int hda_node_index(hda_nid_t *nids, hda_nid_t nid) 258 - { 259 - int i; 260 - 261 - for (i = 0; nids[i]; i++) 262 - if (nids[i] == nid) 263 - return i; 264 - 265 - snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid); 266 - return -EINVAL; 267 - } 268 - 269 - static int intel_hdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid) 270 - { 271 - struct intel_hdmi_spec *spec = codec->spec; 272 - hda_nid_t conn_list[HDA_MAX_CONNECTIONS]; 273 - int conn_len, curr; 274 - int index; 275 - 276 - if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 277 - snd_printk(KERN_WARNING 278 - "HDMI: pin %d wcaps %#x " 279 - "does not support connection list\n", 280 - pin_nid, get_wcaps(codec, pin_nid)); 281 - return -EINVAL; 282 - } 283 - 284 - conn_len = snd_hda_get_connections(codec, pin_nid, conn_list, 285 - HDA_MAX_CONNECTIONS); 286 - if (conn_len > 1) 287 - curr = snd_hda_codec_read(codec, pin_nid, 0, 288 - AC_VERB_GET_CONNECT_SEL, 0); 289 - else 290 - curr = 0; 291 - 292 - index = hda_node_index(spec->pin, pin_nid); 293 - if (index < 0) 294 - return -EINVAL; 295 - 296 - spec->pin_cvt[index] = conn_list[curr]; 297 - 298 - return 0; 299 - } 300 - 301 - static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid, 302 - struct hdmi_eld *eld) 303 - { 304 - if (!snd_hdmi_get_eld(eld, codec, pin_nid)) 305 - snd_hdmi_show_eld(eld); 306 - } 307 - 308 - static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid, 309 - struct hdmi_eld *eld) 310 - { 311 - int present = snd_hda_pin_sense(codec, pin_nid); 312 - 313 - eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 314 - eld->eld_valid = !!(present & AC_PINSENSE_ELDV); 315 - 316 - if (present & AC_PINSENSE_ELDV) 317 - hdmi_get_show_eld(codec, pin_nid, eld); 318 - } 319 - 320 - static int intel_hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) 321 - { 322 - struct intel_hdmi_spec *spec = codec->spec; 323 - 324 - if (spec->num_pins >= INTEL_HDMI_PINS) { 325 - snd_printk(KERN_WARNING 326 - "HDMI: no space for pin %d \n", pin_nid); 327 - return -EINVAL; 328 - } 329 - 330 - hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]); 331 - 332 - spec->pin[spec->num_pins] = pin_nid; 333 - spec->num_pins++; 334 - 335 - /* 336 - * It is assumed that converter nodes come first in the node list and 337 - * hence have been registered and usable now. 338 - */ 339 - return intel_hdmi_read_pin_conn(codec, pin_nid); 340 - } 341 - 342 - static int intel_hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid) 343 - { 344 - struct intel_hdmi_spec *spec = codec->spec; 345 - 346 - if (spec->num_cvts >= INTEL_HDMI_CVTS) { 347 - snd_printk(KERN_WARNING 348 - "HDMI: no space for converter %d \n", nid); 349 - return -EINVAL; 350 - } 351 - 352 - spec->cvt[spec->num_cvts] = nid; 353 - spec->num_cvts++; 354 - 355 - return 0; 356 - } 357 - 358 - static int intel_hdmi_parse_codec(struct hda_codec *codec) 359 - { 360 - hda_nid_t nid; 361 - int i, nodes; 362 - 363 - nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 364 - if (!nid || nodes < 0) { 365 - snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n"); 366 - return -EINVAL; 367 - } 368 - 369 - for (i = 0; i < nodes; i++, nid++) { 370 - unsigned int caps; 371 - unsigned int type; 372 - 373 - caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); 374 - type = get_wcaps_type(caps); 375 - 376 - if (!(caps & AC_WCAP_DIGITAL)) 377 - continue; 378 - 379 - switch (type) { 380 - case AC_WID_AUD_OUT: 381 - if (intel_hdmi_add_cvt(codec, nid) < 0) 382 - return -EINVAL; 383 - break; 384 - case AC_WID_PIN: 385 - caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 386 - if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 387 - continue; 388 - if (intel_hdmi_add_pin(codec, nid) < 0) 389 - return -EINVAL; 390 - break; 391 - } 392 - } 393 - 394 - /* 395 - * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event 396 - * can be lost and presence sense verb will become inaccurate if the 397 - * HDA link is powered off at hot plug or hw initialization time. 398 - */ 399 - #ifdef CONFIG_SND_HDA_POWER_SAVE 400 - if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) & 401 - AC_PWRST_EPSS)) 402 - codec->bus->power_keep_link_on = 1; 403 - #endif 404 - 405 - return 0; 406 - } 407 - 408 - /* 409 - * HDMI routines 410 - */ 411 - 412 - #ifdef BE_PARANOID 413 - static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 414 - int *packet_index, int *byte_index) 415 - { 416 - int val; 417 - 418 - val = snd_hda_codec_read(codec, pin_nid, 0, 419 - AC_VERB_GET_HDMI_DIP_INDEX, 0); 420 - 421 - *packet_index = val >> 5; 422 - *byte_index = val & 0x1f; 423 - } 424 - #endif 425 - 426 - static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 427 - int packet_index, int byte_index) 428 - { 429 - int val; 430 - 431 - val = (packet_index << 5) | (byte_index & 0x1f); 432 - 433 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 434 - } 435 - 436 - static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, 437 - unsigned char val) 438 - { 439 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 440 - } 441 - 442 - static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid) 443 - { 444 - /* Unmute */ 445 - if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 446 - snd_hda_codec_write(codec, pin_nid, 0, 447 - AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 448 - /* Enable pin out */ 449 - snd_hda_codec_write(codec, pin_nid, 0, 450 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 451 - } 452 - 453 - /* 454 - * Enable Audio InfoFrame Transmission 455 - */ 456 - static void hdmi_start_infoframe_trans(struct hda_codec *codec, 457 - hda_nid_t pin_nid) 458 - { 459 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 460 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 461 - AC_DIPXMIT_BEST); 462 - } 463 - 464 - /* 465 - * Disable Audio InfoFrame Transmission 466 - */ 467 - static void hdmi_stop_infoframe_trans(struct hda_codec *codec, 468 - hda_nid_t pin_nid) 469 - { 470 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 471 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 472 - AC_DIPXMIT_DISABLE); 473 - } 474 - 475 - static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid) 476 - { 477 - return 1 + snd_hda_codec_read(codec, nid, 0, 478 - AC_VERB_GET_CVT_CHAN_COUNT, 0); 479 - } 480 - 481 - static void hdmi_set_channel_count(struct hda_codec *codec, 482 - hda_nid_t nid, int chs) 483 - { 484 - if (chs != hdmi_get_channel_count(codec, nid)) 485 - snd_hda_codec_write(codec, nid, 0, 486 - AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 487 - } 488 - 489 - static void hdmi_debug_channel_mapping(struct hda_codec *codec, 490 - hda_nid_t pin_nid) 491 - { 492 - #ifdef CONFIG_SND_DEBUG_VERBOSE 493 - int i; 494 - int slot; 495 - 496 - for (i = 0; i < 8; i++) { 497 - slot = snd_hda_codec_read(codec, pin_nid, 0, 498 - AC_VERB_GET_HDMI_CHAN_SLOT, i); 499 - printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 500 - slot >> 4, slot & 0xf); 501 - } 502 - #endif 503 - } 504 - 505 - 506 - /* 507 - * Audio InfoFrame routines 508 - */ 509 - 510 - static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) 511 - { 512 - #ifdef CONFIG_SND_DEBUG_VERBOSE 513 - int i; 514 - int size; 515 - 516 - size = snd_hdmi_get_eld_size(codec, pin_nid); 517 - printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); 518 - 519 - for (i = 0; i < 8; i++) { 520 - size = snd_hda_codec_read(codec, pin_nid, 0, 521 - AC_VERB_GET_HDMI_DIP_SIZE, i); 522 - printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); 523 - } 524 - #endif 525 - } 526 - 527 - static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) 528 - { 529 - #ifdef BE_PARANOID 530 - int i, j; 531 - int size; 532 - int pi, bi; 533 - for (i = 0; i < 8; i++) { 534 - size = snd_hda_codec_read(codec, pin_nid, 0, 535 - AC_VERB_GET_HDMI_DIP_SIZE, i); 536 - if (size == 0) 537 - continue; 538 - 539 - hdmi_set_dip_index(codec, pin_nid, i, 0x0); 540 - for (j = 1; j < 1000; j++) { 541 - hdmi_write_dip_byte(codec, pin_nid, 0x0); 542 - hdmi_get_dip_index(codec, pin_nid, &pi, &bi); 543 - if (pi != i) 544 - snd_printd(KERN_INFO "dip index %d: %d != %d\n", 545 - bi, pi, i); 546 - if (bi == 0) /* byte index wrapped around */ 547 - break; 548 - } 549 - snd_printd(KERN_INFO 550 - "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", 551 - i, size, j); 552 - } 553 - #endif 554 - } 555 - 556 - static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai) 557 - { 558 - u8 *bytes = (u8 *)ai; 559 - u8 sum = 0; 560 - int i; 561 - 562 - ai->checksum = 0; 563 - 564 - for (i = 0; i < sizeof(*ai); i++) 565 - sum += bytes[i]; 566 - 567 - ai->checksum = - sum; 568 - } 569 - 570 - static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 571 - hda_nid_t pin_nid, 572 - struct hdmi_audio_infoframe *ai) 573 - { 574 - u8 *bytes = (u8 *)ai; 575 - int i; 576 - 577 - hdmi_debug_dip_size(codec, pin_nid); 578 - hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ 579 - 580 - hdmi_checksum_audio_infoframe(ai); 581 - 582 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 583 - for (i = 0; i < sizeof(*ai); i++) 584 - hdmi_write_dip_byte(codec, pin_nid, bytes[i]); 585 - } 586 - 587 - /* 588 - * Compute derived values in channel_allocations[]. 589 - */ 590 - static void init_channel_allocations(void) 591 - { 592 - int i, j; 593 - struct cea_channel_speaker_allocation *p; 594 - 595 - for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 596 - p = channel_allocations + i; 597 - p->channels = 0; 598 - p->spk_mask = 0; 599 - for (j = 0; j < ARRAY_SIZE(p->speakers); j++) 600 - if (p->speakers[j]) { 601 - p->channels++; 602 - p->spk_mask |= p->speakers[j]; 603 - } 604 - } 605 - } 606 - 607 - /* 608 - * The transformation takes two steps: 609 - * 610 - * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask 611 - * spk_mask => (channel_allocations[]) => ai->CA 612 - * 613 - * TODO: it could select the wrong CA from multiple candidates. 614 - */ 615 - static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid, 616 - struct hdmi_audio_infoframe *ai) 617 - { 618 - struct intel_hdmi_spec *spec = codec->spec; 619 - struct hdmi_eld *eld; 620 - int i; 621 - int spk_mask = 0; 622 - int channels = 1 + (ai->CC02_CT47 & 0x7); 623 - char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; 624 - 625 - /* 626 - * CA defaults to 0 for basic stereo audio 627 - */ 628 - if (channels <= 2) 629 - return 0; 630 - 631 - i = hda_node_index(spec->pin_cvt, nid); 632 - if (i < 0) 633 - return 0; 634 - eld = &spec->sink_eld[i]; 635 - 636 - /* 637 - * HDMI sink's ELD info cannot always be retrieved for now, e.g. 638 - * in console or for audio devices. Assume the highest speakers 639 - * configuration, to _not_ prohibit multi-channel audio playback. 640 - */ 641 - if (!eld->spk_alloc) 642 - eld->spk_alloc = 0xffff; 643 - 644 - /* 645 - * expand ELD's speaker allocation mask 646 - * 647 - * ELD tells the speaker mask in a compact(paired) form, 648 - * expand ELD's notions to match the ones used by Audio InfoFrame. 649 - */ 650 - for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 651 - if (eld->spk_alloc & (1 << i)) 652 - spk_mask |= eld_speaker_allocation_bits[i]; 653 - } 654 - 655 - /* search for the first working match in the CA table */ 656 - for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 657 - if (channels == channel_allocations[i].channels && 658 - (spk_mask & channel_allocations[i].spk_mask) == 659 - channel_allocations[i].spk_mask) { 660 - ai->CA = channel_allocations[i].ca_index; 661 - break; 662 - } 663 - } 664 - 665 - snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf)); 666 - snd_printdd(KERN_INFO 667 - "HDMI: select CA 0x%x for %d-channel allocation: %s\n", 668 - ai->CA, channels, buf); 669 - 670 - return ai->CA; 671 - } 672 - 673 - static void hdmi_setup_channel_mapping(struct hda_codec *codec, 674 - hda_nid_t pin_nid, 675 - struct hdmi_audio_infoframe *ai) 676 - { 677 - int i; 678 - int ca = ai->CA; 679 - int err; 680 - 681 - if (hdmi_channel_mapping[ca][1] == 0) { 682 - for (i = 0; i < channel_allocations[ca].channels; i++) 683 - hdmi_channel_mapping[ca][i] = i | (i << 4); 684 - for (; i < 8; i++) 685 - hdmi_channel_mapping[ca][i] = 0xf | (i << 4); 686 - } 687 - 688 - for (i = 0; i < 8; i++) { 689 - err = snd_hda_codec_write(codec, pin_nid, 0, 690 - AC_VERB_SET_HDMI_CHAN_SLOT, 691 - hdmi_channel_mapping[ca][i]); 692 - if (err) { 693 - snd_printdd(KERN_INFO "HDMI: channel mapping failed\n"); 694 - break; 695 - } 696 - } 697 - 698 - hdmi_debug_channel_mapping(codec, pin_nid); 699 - } 700 - 701 - static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, 702 - struct hdmi_audio_infoframe *ai) 703 - { 704 - u8 *bytes = (u8 *)ai; 705 - u8 val; 706 - int i; 707 - 708 - if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) 709 - != AC_DIPXMIT_BEST) 710 - return false; 711 - 712 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 713 - for (i = 0; i < sizeof(*ai); i++) { 714 - val = snd_hda_codec_read(codec, pin_nid, 0, 715 - AC_VERB_GET_HDMI_DIP_DATA, 0); 716 - if (val != bytes[i]) 717 - return false; 718 - } 719 - 720 - return true; 721 - } 722 - 723 - static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid, 724 - struct snd_pcm_substream *substream) 725 - { 726 - struct intel_hdmi_spec *spec = codec->spec; 727 - hda_nid_t pin_nid; 728 - int i; 729 - struct hdmi_audio_infoframe ai = { 730 - .type = 0x84, 731 - .ver = 0x01, 732 - .len = 0x0a, 733 - .CC02_CT47 = substream->runtime->channels - 1, 734 - }; 735 - 736 - hdmi_setup_channel_allocation(codec, nid, &ai); 737 - 738 - for (i = 0; i < spec->num_pins; i++) { 739 - if (spec->pin_cvt[i] != nid) 740 - continue; 741 - if (!spec->sink_eld[i].monitor_present) 742 - continue; 743 - 744 - pin_nid = spec->pin[i]; 745 - if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) { 746 - hdmi_setup_channel_mapping(codec, pin_nid, &ai); 747 - hdmi_stop_infoframe_trans(codec, pin_nid); 748 - hdmi_fill_audio_infoframe(codec, pin_nid, &ai); 749 - hdmi_start_infoframe_trans(codec, pin_nid); 750 - } 751 - } 752 - } 753 - 754 - 755 - /* 756 - * Unsolicited events 757 - */ 758 - 759 - static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 760 - { 761 - struct intel_hdmi_spec *spec = codec->spec; 762 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 763 - int pind = !!(res & AC_UNSOL_RES_PD); 764 - int eldv = !!(res & AC_UNSOL_RES_ELDV); 765 - int index; 766 - 767 - printk(KERN_INFO 768 - "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 769 - tag, pind, eldv); 770 - 771 - index = hda_node_index(spec->pin, tag); 772 - if (index < 0) 773 - return; 774 - 775 - spec->sink_eld[index].monitor_present = pind; 776 - spec->sink_eld[index].eld_valid = eldv; 777 - 778 - if (pind && eldv) { 779 - hdmi_get_show_eld(codec, spec->pin[index], &spec->sink_eld[index]); 780 - /* TODO: do real things about ELD */ 781 - } 782 - } 783 - 784 - static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 785 - { 786 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 787 - int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 788 - int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 789 - int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 790 - 791 - printk(KERN_INFO 792 - "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 793 - tag, 794 - subtag, 795 - cp_state, 796 - cp_ready); 797 - 798 - /* TODO */ 799 - if (cp_state) 800 - ; 801 - if (cp_ready) 802 - ; 803 - } 804 - 805 - 806 - static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res) 807 - { 808 - struct intel_hdmi_spec *spec = codec->spec; 809 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 810 - int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 811 - 812 - if (hda_node_index(spec->pin, tag) < 0) { 813 - snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 814 - return; 815 - } 816 - 817 - if (subtag == 0) 818 - hdmi_intrinsic_event(codec, res); 819 - else 820 - hdmi_non_intrinsic_event(codec, res); 821 - } 822 - 823 - /* 824 - * Callbacks 825 - */ 826 - 827 - static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid, 828 - u32 stream_tag, int format) 829 - { 830 - int tag; 831 - int fmt; 832 - 833 - tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4; 834 - fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0); 835 - 836 - snd_printdd("hdmi_setup_stream: " 837 - "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n", 838 - nid, 839 - tag == stream_tag ? "" : "new-", 840 - stream_tag, 841 - fmt == format ? "" : "new-", 842 - format); 843 - 844 - if (tag != stream_tag) 845 - snd_hda_codec_write(codec, nid, 0, 846 - AC_VERB_SET_CHANNEL_STREAMID, stream_tag << 4); 847 - if (fmt != format) 848 - snd_hda_codec_write(codec, nid, 0, 849 - AC_VERB_SET_STREAM_FORMAT, format); 850 - } 851 56 852 57 static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 853 58 struct hda_codec *codec, ··· 87 882 88 883 static int intel_hdmi_build_pcms(struct hda_codec *codec) 89 884 { 90 - struct intel_hdmi_spec *spec = codec->spec; 885 + struct hdmi_spec *spec = codec->spec; 91 886 struct hda_pcm *info = spec->pcm_rec; 92 887 int i; 93 888 ··· 113 908 114 909 static int intel_hdmi_build_controls(struct hda_codec *codec) 115 910 { 116 - struct intel_hdmi_spec *spec = codec->spec; 911 + struct hdmi_spec *spec = codec->spec; 117 912 int err; 118 913 int i; 119 914 ··· 128 923 129 924 static int intel_hdmi_init(struct hda_codec *codec) 130 925 { 131 - struct intel_hdmi_spec *spec = codec->spec; 926 + struct hdmi_spec *spec = codec->spec; 132 927 int i; 133 928 134 929 for (i = 0; spec->pin[i]; i++) { ··· 142 937 143 938 static void intel_hdmi_free(struct hda_codec *codec) 144 939 { 145 - struct intel_hdmi_spec *spec = codec->spec; 940 + struct hdmi_spec *spec = codec->spec; 146 941 int i; 147 942 148 943 for (i = 0; i < spec->num_pins; i++) ··· 156 951 .free = intel_hdmi_free, 157 952 .build_pcms = intel_hdmi_build_pcms, 158 953 .build_controls = intel_hdmi_build_controls, 159 - .unsol_event = intel_hdmi_unsol_event, 954 + .unsol_event = hdmi_unsol_event, 160 955 }; 161 956 162 957 static int patch_intel_hdmi(struct hda_codec *codec) 163 958 { 164 - struct intel_hdmi_spec *spec; 959 + struct hdmi_spec *spec; 165 960 int i; 166 961 167 962 spec = kzalloc(sizeof(*spec), GFP_KERNEL); ··· 169 964 return -ENOMEM; 170 965 171 966 codec->spec = spec; 172 - if (intel_hdmi_parse_codec(codec) < 0) { 967 + if (hdmi_parse_codec(codec) < 0) { 173 968 codec->spec = NULL; 174 969 kfree(spec); 175 970 return -EINVAL;
+24 -805
sound/pci/hda/patch_nvhdmi.c
··· 29 29 #include "hda_codec.h" 30 30 #include "hda_local.h" 31 31 32 + #define MAX_HDMI_CVTS 1 33 + #define MAX_HDMI_PINS 1 34 + 35 + #include "patch_hdmi.c" 36 + 37 + static char *nvhdmi_pcm_names[MAX_HDMI_CVTS] = { 38 + "NVIDIA HDMI", 39 + }; 40 + 32 41 /* define below to restrict the supported rates and formats */ 33 42 /* #define LIMITED_RATE_FMT_SUPPORT */ 34 43 ··· 92 83 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) 93 84 #endif 94 85 95 - #define NVIDIA_89_HDMI_CVTS 1 96 - #define NVIDIA_89_HDMI_PINS 1 97 - 98 - static char *nvhdmi_pcm_names[NVIDIA_89_HDMI_CVTS] = { 99 - "NVIDIA HDMI", 100 - }; 101 - 102 - struct nvhdmi_spec { 103 - int num_cvts; 104 - int num_pins; 105 - hda_nid_t cvt[NVIDIA_89_HDMI_CVTS+1]; /* audio sources */ 106 - hda_nid_t pin[NVIDIA_89_HDMI_PINS+1]; /* audio sinks */ 107 - hda_nid_t pin_cvt[NVIDIA_89_HDMI_PINS+1]; 108 - struct hda_pcm pcm_rec[NVIDIA_89_HDMI_CVTS]; 109 - struct hdmi_eld sink_eld[NVIDIA_89_HDMI_PINS]; 110 - struct hda_multi_out multiout; 111 - unsigned int codec_type; 112 - }; 113 - 114 - struct hdmi_audio_infoframe { 115 - u8 type; /* 0x84 */ 116 - u8 ver; /* 0x01 */ 117 - u8 len; /* 0x0a */ 118 - 119 - u8 checksum; /* PB0 */ 120 - u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ 121 - u8 SS01_SF24; 122 - u8 CXT04; 123 - u8 CA; 124 - u8 LFEPBL01_LSV36_DM_INH7; 125 - }; 126 - 127 - /* 128 - * CEA speaker placement: 129 - * 130 - * FLH FCH FRH 131 - * FLW FL FLC FC FRC FR FRW 132 - * 133 - * LFE 134 - * TC 135 - * 136 - * RL RLC RC RRC RR 137 - * 138 - * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to 139 - * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC. 140 - */ 141 - enum cea_speaker_placement { 142 - FL = (1 << 0), /* Front Left */ 143 - FC = (1 << 1), /* Front Center */ 144 - FR = (1 << 2), /* Front Right */ 145 - FLC = (1 << 3), /* Front Left Center */ 146 - FRC = (1 << 4), /* Front Right Center */ 147 - RL = (1 << 5), /* Rear Left */ 148 - RC = (1 << 6), /* Rear Center */ 149 - RR = (1 << 7), /* Rear Right */ 150 - RLC = (1 << 8), /* Rear Left Center */ 151 - RRC = (1 << 9), /* Rear Right Center */ 152 - LFE = (1 << 10), /* Low Frequency Effect */ 153 - FLW = (1 << 11), /* Front Left Wide */ 154 - FRW = (1 << 12), /* Front Right Wide */ 155 - FLH = (1 << 13), /* Front Left High */ 156 - FCH = (1 << 14), /* Front Center High */ 157 - FRH = (1 << 15), /* Front Right High */ 158 - TC = (1 << 16), /* Top Center */ 159 - }; 160 - 161 - /* 162 - * ELD SA bits in the CEA Speaker Allocation data block 163 - */ 164 - static int eld_speaker_allocation_bits[] = { 165 - [0] = FL | FR, 166 - [1] = LFE, 167 - [2] = FC, 168 - [3] = RL | RR, 169 - [4] = RC, 170 - [5] = FLC | FRC, 171 - [6] = RLC | RRC, 172 - /* the following are not defined in ELD yet */ 173 - [7] = FLW | FRW, 174 - [8] = FLH | FRH, 175 - [9] = TC, 176 - [10] = FCH, 177 - }; 178 - 179 - struct cea_channel_speaker_allocation { 180 - int ca_index; 181 - int speakers[8]; 182 - 183 - /* derived values, just for convenience */ 184 - int channels; 185 - int spk_mask; 186 - }; 187 - 188 - /* 189 - * ALSA sequence is: 190 - * 191 - * surround40 surround41 surround50 surround51 surround71 192 - * ch0 front left = = = = 193 - * ch1 front right = = = = 194 - * ch2 rear left = = = = 195 - * ch3 rear right = = = = 196 - * ch4 LFE center center center 197 - * ch5 LFE LFE 198 - * ch6 side left 199 - * ch7 side right 200 - * 201 - * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR} 202 - */ 203 - static int hdmi_channel_mapping[0x32][8] = { 204 - /* stereo */ 205 - [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 206 - /* 2.1 */ 207 - [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, 208 - /* Dolby Surround */ 209 - [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 }, 210 - /* surround40 */ 211 - [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 }, 212 - /* 4ch */ 213 - [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 }, 214 - /* surround41 */ 215 - [0x09] = { 0x00, 0x11, 0x24, 0x34, 0x43, 0xf2, 0xf6, 0xf7 }, 216 - /* surround50 */ 217 - [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 }, 218 - /* surround51 */ 219 - [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 }, 220 - /* 7.1 */ 221 - [0x13] = { 0x00, 0x11, 0x32, 0x23, 0x64, 0x75, 0x46, 0x57 }, 222 - }; 223 - 224 - /* 225 - * This is an ordered list! 226 - * 227 - * The preceding ones have better chances to be selected by 228 - * hdmi_setup_channel_allocation(). 229 - */ 230 - static struct cea_channel_speaker_allocation channel_allocations[] = { 231 - /* channel: 7 6 5 4 3 2 1 0 */ 232 - { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, 233 - /* 2.1 */ 234 - { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, 235 - /* Dolby Surround */ 236 - { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, 237 - /* surround40 */ 238 - { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, 239 - /* surround41 */ 240 - { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, 241 - /* surround50 */ 242 - { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, 243 - /* surround51 */ 244 - { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, 245 - /* 6.1 */ 246 - { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, 247 - /* surround71 */ 248 - { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, 249 - 250 - { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, 251 - { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, 252 - { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, 253 - { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, 254 - { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, 255 - { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, 256 - { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, 257 - { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, 258 - { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, 259 - { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, 260 - { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, 261 - { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, 262 - { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, 263 - { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, 264 - { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, 265 - { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, 266 - { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, 267 - { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, 268 - { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, 269 - { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, 270 - { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, 271 - { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, 272 - { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, 273 - { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } }, 274 - { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } }, 275 - { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } }, 276 - { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } }, 277 - { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } }, 278 - { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } }, 279 - { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } }, 280 - { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } }, 281 - { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } }, 282 - { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } }, 283 - { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } }, 284 - { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } }, 285 - { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } }, 286 - { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } }, 287 - { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } }, 288 - { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } }, 289 - { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } }, 290 - { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, 291 - }; 292 - 293 - /* 294 - * HDA/HDMI auto parsing 295 - */ 296 - 297 - static int hda_node_index(hda_nid_t *nids, hda_nid_t nid) 298 - { 299 - int i; 300 - 301 - for (i = 0; nids[i]; i++) 302 - if (nids[i] == nid) 303 - return i; 304 - 305 - snd_printk(KERN_WARNING "HDMI: nid %d not registered\n", nid); 306 - return -EINVAL; 307 - } 308 - 309 - static int nvhdmi_read_pin_conn(struct hda_codec *codec, hda_nid_t pin_nid) 310 - { 311 - struct nvhdmi_spec *spec = codec->spec; 312 - hda_nid_t conn_list[HDA_MAX_CONNECTIONS]; 313 - int conn_len, curr; 314 - int index; 315 - 316 - if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 317 - snd_printk(KERN_WARNING 318 - "HDMI: pin %d wcaps %#x " 319 - "does not support connection list\n", 320 - pin_nid, get_wcaps(codec, pin_nid)); 321 - return -EINVAL; 322 - } 323 - 324 - conn_len = snd_hda_get_connections(codec, pin_nid, conn_list, 325 - HDA_MAX_CONNECTIONS); 326 - if (conn_len > 1) 327 - curr = snd_hda_codec_read(codec, pin_nid, 0, 328 - AC_VERB_GET_CONNECT_SEL, 0); 329 - else 330 - curr = 0; 331 - 332 - index = hda_node_index(spec->pin, pin_nid); 333 - if (index < 0) 334 - return -EINVAL; 335 - 336 - spec->pin_cvt[index] = conn_list[curr]; 337 - 338 - return 0; 339 - } 340 - 341 - static void hdmi_get_show_eld(struct hda_codec *codec, hda_nid_t pin_nid, 342 - struct hdmi_eld *eld) 343 - { 344 - if (!snd_hdmi_get_eld(eld, codec, pin_nid)) 345 - snd_hdmi_show_eld(eld); 346 - } 347 - 348 - static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid, 349 - struct hdmi_eld *eld) 350 - { 351 - int present = snd_hda_pin_sense(codec, pin_nid); 352 - 353 - eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 354 - eld->eld_valid = !!(present & AC_PINSENSE_ELDV); 355 - 356 - if (present & AC_PINSENSE_ELDV) 357 - hdmi_get_show_eld(codec, pin_nid, eld); 358 - } 359 - 360 - static int nvhdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) 361 - { 362 - struct nvhdmi_spec *spec = codec->spec; 363 - 364 - if (spec->num_pins >= NVIDIA_89_HDMI_PINS) { 365 - snd_printk(KERN_WARNING 366 - "HDMI: no space for pin %d \n", pin_nid); 367 - return -EINVAL; 368 - } 369 - 370 - hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]); 371 - 372 - spec->pin[spec->num_pins] = pin_nid; 373 - spec->num_pins++; 374 - 375 - /* 376 - * It is assumed that converter nodes come first in the node list and 377 - * hence have been registered and usable now. 378 - */ 379 - return nvhdmi_read_pin_conn(codec, pin_nid); 380 - } 381 - 382 - static int nvhdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid) 383 - { 384 - struct nvhdmi_spec *spec = codec->spec; 385 - 386 - if (spec->num_cvts >= NVIDIA_89_HDMI_CVTS) { 387 - snd_printk(KERN_WARNING 388 - "HDMI: no space for converter %d \n", nid); 389 - return -EINVAL; 390 - } 391 - 392 - spec->cvt[spec->num_cvts] = nid; 393 - spec->num_cvts++; 394 - 395 - return 0; 396 - } 397 - 398 - 399 - static int nvhdmi_parse_codec(struct hda_codec *codec) 400 - { 401 - hda_nid_t nid; 402 - int i, nodes; 403 - 404 - nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 405 - if (!nid || nodes < 0) { 406 - snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n"); 407 - return -EINVAL; 408 - } 409 - 410 - for (i = 0; i < nodes; i++, nid++) { 411 - unsigned int caps; 412 - unsigned int type; 413 - 414 - caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP); 415 - type = get_wcaps_type(caps); 416 - 417 - if (!(caps & AC_WCAP_DIGITAL)) 418 - continue; 419 - 420 - switch (type) { 421 - case AC_WID_AUD_OUT: 422 - if (nvhdmi_add_cvt(codec, nid) < 0) 423 - return -EINVAL; 424 - break; 425 - case AC_WID_PIN: 426 - caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 427 - if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 428 - continue; 429 - if (nvhdmi_add_pin(codec, nid) < 0) 430 - return -EINVAL; 431 - break; 432 - } 433 - } 434 - 435 - /* 436 - * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event 437 - * can be lost and presence sense verb will become inaccurate if the 438 - * HDA link is powered off at hot plug or hw initialization time. 439 - */ 440 - #ifdef CONFIG_SND_HDA_POWER_SAVE 441 - if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) & 442 - AC_PWRST_EPSS)) 443 - codec->bus->power_keep_link_on = 1; 444 - #endif 445 - 446 - return 0; 447 - } 448 - 449 - /* 450 - * HDMI routines 451 - */ 452 - 453 - #ifdef BE_PARANOID 454 - static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 455 - int *packet_index, int *byte_index) 456 - { 457 - int val; 458 - 459 - val = snd_hda_codec_read(codec, pin_nid, 0, 460 - AC_VERB_GET_HDMI_DIP_INDEX, 0); 461 - 462 - *packet_index = val >> 5; 463 - *byte_index = val & 0x1f; 464 - } 465 - #endif 466 - 467 - static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 468 - int packet_index, int byte_index) 469 - { 470 - int val; 471 - 472 - val = (packet_index << 5) | (byte_index & 0x1f); 473 - 474 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 475 - } 476 - 477 - static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, 478 - unsigned char val) 479 - { 480 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 481 - } 482 - 483 - static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid) 484 - { 485 - /* Unmute */ 486 - if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 487 - snd_hda_codec_write(codec, pin_nid, 0, 488 - AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 489 - /* Enable pin out */ 490 - snd_hda_codec_write(codec, pin_nid, 0, 491 - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 492 - } 493 - 494 - /* 495 - * Enable Audio InfoFrame Transmission 496 - */ 497 - static void hdmi_start_infoframe_trans(struct hda_codec *codec, 498 - hda_nid_t pin_nid) 499 - { 500 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 501 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 502 - AC_DIPXMIT_BEST); 503 - } 504 - 505 - /* 506 - * Disable Audio InfoFrame Transmission 507 - */ 508 - static void hdmi_stop_infoframe_trans(struct hda_codec *codec, 509 - hda_nid_t pin_nid) 510 - { 511 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 512 - snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 513 - AC_DIPXMIT_DISABLE); 514 - } 515 - 516 - static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid) 517 - { 518 - return 1 + snd_hda_codec_read(codec, nid, 0, 519 - AC_VERB_GET_CVT_CHAN_COUNT, 0); 520 - } 521 - 522 - static void hdmi_set_channel_count(struct hda_codec *codec, 523 - hda_nid_t nid, int chs) 524 - { 525 - if (chs != hdmi_get_channel_count(codec, nid)) 526 - snd_hda_codec_write(codec, nid, 0, 527 - AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); 528 - } 529 - 530 - static void hdmi_debug_channel_mapping(struct hda_codec *codec, 531 - hda_nid_t pin_nid) 532 - { 533 - #ifdef CONFIG_SND_DEBUG_VERBOSE 534 - int i; 535 - int slot; 536 - 537 - for (i = 0; i < 8; i++) { 538 - slot = snd_hda_codec_read(codec, pin_nid, 0, 539 - AC_VERB_GET_HDMI_CHAN_SLOT, i); 540 - printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 541 - slot >> 4, slot & 0xf); 542 - } 543 - #endif 544 - } 545 - 546 - 547 - /* 548 - * Audio InfoFrame routines 549 - */ 550 - 551 - static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) 552 - { 553 - #ifdef CONFIG_SND_DEBUG_VERBOSE 554 - int i; 555 - int size; 556 - 557 - size = snd_hdmi_get_eld_size(codec, pin_nid); 558 - printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); 559 - 560 - for (i = 0; i < 8; i++) { 561 - size = snd_hda_codec_read(codec, pin_nid, 0, 562 - AC_VERB_GET_HDMI_DIP_SIZE, i); 563 - printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); 564 - } 565 - #endif 566 - } 567 - 568 - static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) 569 - { 570 - #ifdef BE_PARANOID 571 - int i, j; 572 - int size; 573 - int pi, bi; 574 - for (i = 0; i < 8; i++) { 575 - size = snd_hda_codec_read(codec, pin_nid, 0, 576 - AC_VERB_GET_HDMI_DIP_SIZE, i); 577 - if (size == 0) 578 - continue; 579 - 580 - hdmi_set_dip_index(codec, pin_nid, i, 0x0); 581 - for (j = 1; j < 1000; j++) { 582 - hdmi_write_dip_byte(codec, pin_nid, 0x0); 583 - hdmi_get_dip_index(codec, pin_nid, &pi, &bi); 584 - if (pi != i) 585 - snd_printd(KERN_INFO "dip index %d: %d != %d\n", 586 - bi, pi, i); 587 - if (bi == 0) /* byte index wrapped around */ 588 - break; 589 - } 590 - snd_printd(KERN_INFO 591 - "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", 592 - i, size, j); 593 - } 594 - #endif 595 - } 596 - 597 - static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai) 598 - { 599 - ai->checksum = 0; 600 - } 601 - 602 - static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 603 - hda_nid_t pin_nid, 604 - struct hdmi_audio_infoframe *ai) 605 - { 606 - u8 *bytes = (u8 *)ai; 607 - int i; 608 - 609 - hdmi_debug_dip_size(codec, pin_nid); 610 - hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ 611 - 612 - hdmi_checksum_audio_infoframe(ai); 613 - 614 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 615 - for (i = 0; i < sizeof(*ai); i++) 616 - hdmi_write_dip_byte(codec, pin_nid, bytes[i]); 617 - } 618 - 619 - /* 620 - * Compute derived values in channel_allocations[]. 621 - */ 622 - static void init_channel_allocations(void) 623 - { 624 - int i, j; 625 - struct cea_channel_speaker_allocation *p; 626 - 627 - for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 628 - p = channel_allocations + i; 629 - p->channels = 0; 630 - p->spk_mask = 0; 631 - for (j = 0; j < ARRAY_SIZE(p->speakers); j++) 632 - if (p->speakers[j]) { 633 - p->channels++; 634 - p->spk_mask |= p->speakers[j]; 635 - } 636 - } 637 - } 638 - 639 - /* 640 - * The transformation takes two steps: 641 - * 642 - * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask 643 - * spk_mask => (channel_allocations[]) => ai->CA 644 - * 645 - * TODO: it could select the wrong CA from multiple candidates. 646 - */ 647 - static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid, 648 - struct hdmi_audio_infoframe *ai) 649 - { 650 - struct nvhdmi_spec *spec = codec->spec; 651 - struct hdmi_eld *eld; 652 - int i; 653 - int spk_mask = 0; 654 - int channels = 1 + (ai->CC02_CT47 & 0x7); 655 - char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; 656 - 657 - /* 658 - * CA defaults to 0 for basic stereo audio 659 - */ 660 - if (channels <= 2) 661 - return 0; 662 - 663 - i = hda_node_index(spec->pin_cvt, nid); 664 - if (i < 0) 665 - return 0; 666 - eld = &spec->sink_eld[i]; 667 - 668 - /* 669 - * HDMI sink's ELD info cannot always be retrieved for now, e.g. 670 - * in console or for audio devices. Assume the highest speakers 671 - * configuration, to _not_ prohibit multi-channel audio playback. 672 - */ 673 - if (!eld->spk_alloc) 674 - eld->spk_alloc = 0xffff; 675 - 676 - /* 677 - * expand ELD's speaker allocation mask 678 - * 679 - * ELD tells the speaker mask in a compact(paired) form, 680 - * expand ELD's notions to match the ones used by Audio InfoFrame. 681 - */ 682 - for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { 683 - if (eld->spk_alloc & (1 << i)) 684 - spk_mask |= eld_speaker_allocation_bits[i]; 685 - } 686 - 687 - /* search for the first working match in the CA table */ 688 - for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { 689 - if (channels == channel_allocations[i].channels && 690 - (spk_mask & channel_allocations[i].spk_mask) == 691 - channel_allocations[i].spk_mask) { 692 - ai->CA = channel_allocations[i].ca_index; 693 - break; 694 - } 695 - } 696 - 697 - snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf)); 698 - snd_printdd(KERN_INFO 699 - "HDMI: select CA 0x%x for %d-channel allocation: %s\n", 700 - ai->CA, channels, buf); 701 - 702 - return ai->CA; 703 - } 704 - 705 - static void hdmi_setup_channel_mapping(struct hda_codec *codec, 706 - hda_nid_t pin_nid, 707 - struct hdmi_audio_infoframe *ai) 708 - { 709 - int i; 710 - int ca = ai->CA; 711 - int err; 712 - 713 - if (hdmi_channel_mapping[ca][1] == 0) { 714 - for (i = 0; i < channel_allocations[ca].channels; i++) 715 - hdmi_channel_mapping[ca][i] = i | (i << 4); 716 - for (; i < 8; i++) 717 - hdmi_channel_mapping[ca][i] = 0xf | (i << 4); 718 - } 719 - 720 - for (i = 0; i < 8; i++) { 721 - err = snd_hda_codec_write(codec, pin_nid, 0, 722 - AC_VERB_SET_HDMI_CHAN_SLOT, 723 - hdmi_channel_mapping[ca][i]); 724 - if (err) { 725 - snd_printdd(KERN_INFO "HDMI: channel mapping failed\n"); 726 - break; 727 - } 728 - } 729 - 730 - hdmi_debug_channel_mapping(codec, pin_nid); 731 - } 732 - 733 - static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, 734 - struct hdmi_audio_infoframe *ai) 735 - { 736 - u8 *bytes = (u8 *)ai; 737 - u8 val; 738 - int i; 739 - 740 - if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) 741 - != AC_DIPXMIT_BEST) 742 - return false; 743 - 744 - hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 745 - for (i = 0; i < sizeof(*ai); i++) { 746 - val = snd_hda_codec_read(codec, pin_nid, 0, 747 - AC_VERB_GET_HDMI_DIP_DATA, 0); 748 - if (val != bytes[i]) 749 - return false; 750 - } 751 - 752 - return true; 753 - } 754 - 755 - static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid, 756 - struct snd_pcm_substream *substream) 757 - { 758 - struct nvhdmi_spec *spec = codec->spec; 759 - hda_nid_t pin_nid; 760 - int i; 761 - struct hdmi_audio_infoframe ai = { 762 - .type = 0x84, 763 - .ver = 0x01, 764 - .len = 0x0a, 765 - .CC02_CT47 = substream->runtime->channels - 1, 766 - }; 767 - 768 - hdmi_setup_channel_allocation(codec, nid, &ai); 769 - 770 - for (i = 0; i < spec->num_pins; i++) { 771 - if (spec->pin_cvt[i] != nid) 772 - continue; 773 - if (!spec->sink_eld[i].monitor_present) 774 - continue; 775 - 776 - pin_nid = spec->pin[i]; 777 - if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) { 778 - hdmi_setup_channel_mapping(codec, pin_nid, &ai); 779 - hdmi_stop_infoframe_trans(codec, pin_nid); 780 - hdmi_fill_audio_infoframe(codec, pin_nid, &ai); 781 - hdmi_start_infoframe_trans(codec, pin_nid); 782 - } 783 - } 784 - } 785 - 786 - /* 787 - * Unsolicited events 788 - */ 789 - 790 - static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 791 - { 792 - struct nvhdmi_spec *spec = codec->spec; 793 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 794 - int pind = !!(res & AC_UNSOL_RES_PD); 795 - int eldv = !!(res & AC_UNSOL_RES_ELDV); 796 - int index; 797 - 798 - printk(KERN_INFO 799 - "HDMI hot plug event: Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 800 - tag, pind, eldv); 801 - 802 - index = hda_node_index(spec->pin, tag); 803 - if (index < 0) 804 - return; 805 - 806 - spec->sink_eld[index].monitor_present = pind; 807 - spec->sink_eld[index].eld_valid = eldv; 808 - 809 - if (eldv) { 810 - spec->sink_eld[index].monitor_present = 1; 811 - hdmi_get_show_eld(codec, spec->pin[index], 812 - &spec->sink_eld[index]); 813 - /* TODO: do real things about ELD */ 814 - } 815 - } 816 - 817 - static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 818 - { 819 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 820 - int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 821 - int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 822 - int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 823 - 824 - printk(KERN_INFO 825 - "HDMI CP event: PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 826 - tag, 827 - subtag, 828 - cp_state, 829 - cp_ready); 830 - 831 - /* TODO */ 832 - if (cp_state) 833 - ; 834 - if (cp_ready) 835 - ; 836 - } 837 - 838 - static void nvhdmi_unsol_event(struct hda_codec *codec, unsigned int res) 839 - { 840 - struct nvhdmi_spec *spec = codec->spec; 841 - int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 842 - int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 843 - 844 - if (hda_node_index(spec->pin, tag) < 0) { 845 - snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 846 - return; 847 - } 848 - 849 - if (subtag == 0) 850 - hdmi_intrinsic_event(codec, res); 851 - else 852 - hdmi_non_intrinsic_event(codec, res); 853 - } 854 - 855 - /* 856 - * Callbacks 857 - */ 858 - 859 - static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid, 860 - u32 stream_tag, int format) 861 - { 862 - int tag; 863 - int fmt; 864 - 865 - tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4; 866 - fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0); 867 - 868 - snd_printdd("hdmi_setup_stream: " 869 - "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n", 870 - nid, 871 - tag == stream_tag ? "" : "new-", 872 - stream_tag, 873 - fmt == format ? "" : "new-", 874 - format); 875 - 876 - if (tag != stream_tag) 877 - snd_hda_codec_write(codec, nid, 0, 878 - AC_VERB_SET_CHANNEL_STREAMID, 879 - stream_tag << 4); 880 - if (fmt != format) 881 - snd_hda_codec_write(codec, nid, 0, 882 - AC_VERB_SET_STREAM_FORMAT, format); 883 - } 884 - 885 86 /* 886 87 * Controls 887 88 */ 888 89 static int nvhdmi_build_controls(struct hda_codec *codec) 889 90 { 890 - struct nvhdmi_spec *spec = codec->spec; 91 + struct hdmi_spec *spec = codec->spec; 891 92 int err; 892 93 int i; 893 94 ··· 121 902 122 903 static int nvhdmi_init(struct hda_codec *codec) 123 904 { 124 - struct nvhdmi_spec *spec = codec->spec; 905 + struct hdmi_spec *spec = codec->spec; 125 906 int i; 126 907 if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89) 127 908 || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X)) { ··· 139 920 140 921 static void nvhdmi_free(struct hda_codec *codec) 141 922 { 142 - struct nvhdmi_spec *spec = codec->spec; 923 + struct hdmi_spec *spec = codec->spec; 143 924 int i; 144 925 145 926 if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89) ··· 158 939 struct hda_codec *codec, 159 940 struct snd_pcm_substream *substream) 160 941 { 161 - struct nvhdmi_spec *spec = codec->spec; 942 + struct hdmi_spec *spec = codec->spec; 162 943 return snd_hda_multi_out_dig_open(codec, &spec->multiout); 163 944 } 164 945 ··· 166 947 struct hda_codec *codec, 167 948 struct snd_pcm_substream *substream) 168 949 { 169 - struct nvhdmi_spec *spec = codec->spec; 950 + struct hdmi_spec *spec = codec->spec; 170 951 int i; 171 952 172 953 snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, ··· 187 968 struct hda_codec *codec, 188 969 struct snd_pcm_substream *substream) 189 970 { 190 - struct nvhdmi_spec *spec = codec->spec; 971 + struct hdmi_spec *spec = codec->spec; 191 972 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 192 973 } 193 974 ··· 340 1121 unsigned int format, 341 1122 struct snd_pcm_substream *substream) 342 1123 { 343 - struct nvhdmi_spec *spec = codec->spec; 1124 + struct hdmi_spec *spec = codec->spec; 344 1125 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, 345 1126 format, substream); 346 1127 } ··· 389 1170 390 1171 static int nvhdmi_build_pcms_8ch_89(struct hda_codec *codec) 391 1172 { 392 - struct nvhdmi_spec *spec = codec->spec; 1173 + struct hdmi_spec *spec = codec->spec; 393 1174 struct hda_pcm *info = spec->pcm_rec; 394 1175 int i; 395 1176 ··· 415 1196 416 1197 static int nvhdmi_build_pcms_8ch_7x(struct hda_codec *codec) 417 1198 { 418 - struct nvhdmi_spec *spec = codec->spec; 1199 + struct hdmi_spec *spec = codec->spec; 419 1200 struct hda_pcm *info = spec->pcm_rec; 420 1201 421 1202 codec->num_pcms = 1; ··· 431 1212 432 1213 static int nvhdmi_build_pcms_2ch(struct hda_codec *codec) 433 1214 { 434 - struct nvhdmi_spec *spec = codec->spec; 1215 + struct hdmi_spec *spec = codec->spec; 435 1216 struct hda_pcm *info = spec->pcm_rec; 436 1217 437 1218 codec->num_pcms = 1; ··· 450 1231 .build_pcms = nvhdmi_build_pcms_8ch_89, 451 1232 .init = nvhdmi_init, 452 1233 .free = nvhdmi_free, 453 - .unsol_event = nvhdmi_unsol_event, 1234 + .unsol_event = hdmi_unsol_event, 454 1235 }; 455 1236 456 1237 static struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = { ··· 469 1250 470 1251 static int patch_nvhdmi_8ch_89(struct hda_codec *codec) 471 1252 { 472 - struct nvhdmi_spec *spec; 1253 + struct hdmi_spec *spec; 473 1254 int i; 474 1255 475 1256 spec = kzalloc(sizeof(*spec), GFP_KERNEL); ··· 479 1260 codec->spec = spec; 480 1261 spec->codec_type = HDA_CODEC_NVIDIA_MCP89; 481 1262 482 - if (nvhdmi_parse_codec(codec) < 0) { 1263 + if (hdmi_parse_codec(codec) < 0) { 483 1264 codec->spec = NULL; 484 1265 kfree(spec); 485 1266 return -EINVAL; ··· 496 1277 497 1278 static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) 498 1279 { 499 - struct nvhdmi_spec *spec; 1280 + struct hdmi_spec *spec; 500 1281 501 1282 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 502 1283 if (spec == NULL) ··· 516 1297 517 1298 static int patch_nvhdmi_2ch(struct hda_codec *codec) 518 1299 { 519 - struct nvhdmi_spec *spec; 1300 + struct hdmi_spec *spec; 520 1301 521 1302 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 522 1303 if (spec == NULL)