1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * 4 * hdmi.c - routines for HDMI/DisplayPort codecs 5 * 6 * Copyright(c) 2008-2010 Intel Corporation 7 * Copyright (c) 2006 ATI Technologies Inc. 8 * Copyright (c) 2008 NVIDIA Corp. All rights reserved. 9 * Copyright (c) 2008 Wei Ni <wni@nvidia.com> 10 * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi> 11 * 12 * Authors: 13 * Wu Fengguang <wfg@linux.intel.com> 14 * 15 * Maintained by: 16 * Wu Fengguang <wfg@linux.intel.com> 17 */ 18 19 #include <linux/init.h> 20 #include <linux/delay.h> 21 #include <linux/pci.h> 22 #include <linux/slab.h> 23 #include <linux/module.h> 24 #include <linux/pm_runtime.h> 25 #include <sound/core.h> 26 #include <sound/jack.h> 27 #include <sound/asoundef.h> 28 #include <sound/tlv.h> 29 #include <sound/hdaudio.h> 30 #include <sound/hda_i915.h> 31 #include <sound/hda_chmap.h> 32 #include <sound/hda_codec.h> 33 #include "hda_local.h" 34 #include "hda_jack.h" 35 #include "hda_controller.h" 36 #include "hdmi_local.h" 37 38 static bool static_hdmi_pcm; 39 module_param(static_hdmi_pcm, bool, 0644); 40 MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); 41 42 static bool enable_acomp = true; 43 module_param(enable_acomp, bool, 0444); 44 MODULE_PARM_DESC(enable_acomp, "Enable audio component binding (default=yes)"); 45 46 static bool enable_all_pins; 47 module_param(enable_all_pins, bool, 0444); 48 MODULE_PARM_DESC(enable_all_pins, "Forcibly enable all pins"); 49 50 int snd_hda_hdmi_pin_id_to_pin_index(struct hda_codec *codec, 51 hda_nid_t pin_nid, int dev_id) 52 { 53 struct hdmi_spec *spec = codec->spec; 54 int pin_idx; 55 struct hdmi_spec_per_pin *per_pin; 56 57 /* 58 * (dev_id == -1) means it is NON-MST pin 59 * return the first virtual pin on this port 60 */ 61 if (dev_id == -1) 62 dev_id = 0; 63 64 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 65 per_pin = get_pin(spec, pin_idx); 66 if ((per_pin->pin_nid == pin_nid) && 67 (per_pin->dev_id == dev_id)) 68 return pin_idx; 69 } 70 71 codec_warn(codec, "HDMI: pin NID 0x%x not registered\n", pin_nid); 72 return -EINVAL; 73 } 74 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_pin_id_to_pin_index, "SND_HDA_CODEC_HDMI"); 75 76 static int hinfo_to_pcm_index(struct hda_codec *codec, 77 struct hda_pcm_stream *hinfo) 78 { 79 struct hdmi_spec *spec = codec->spec; 80 int pcm_idx; 81 82 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) 83 if (get_pcm_rec(spec, pcm_idx)->stream == hinfo) 84 return pcm_idx; 85 86 codec_warn(codec, "HDMI: hinfo %p not tied to a PCM\n", hinfo); 87 return -EINVAL; 88 } 89 90 static int hinfo_to_pin_index(struct hda_codec *codec, 91 struct hda_pcm_stream *hinfo) 92 { 93 struct hdmi_spec *spec = codec->spec; 94 struct hdmi_spec_per_pin *per_pin; 95 int pin_idx; 96 97 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 98 per_pin = get_pin(spec, pin_idx); 99 if (per_pin->pcm && 100 per_pin->pcm->pcm->stream == hinfo) 101 return pin_idx; 102 } 103 104 codec_dbg(codec, "HDMI: hinfo %p (pcm %d) not registered\n", hinfo, 105 hinfo_to_pcm_index(codec, hinfo)); 106 return -EINVAL; 107 } 108 109 static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec, 110 int pcm_idx) 111 { 112 int i; 113 struct hdmi_spec_per_pin *per_pin; 114 115 for (i = 0; i < spec->num_pins; i++) { 116 per_pin = get_pin(spec, i); 117 if (per_pin->pcm_idx == pcm_idx) 118 return per_pin; 119 } 120 return NULL; 121 } 122 123 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid) 124 { 125 struct hdmi_spec *spec = codec->spec; 126 int cvt_idx; 127 128 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) 129 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid) 130 return cvt_idx; 131 132 codec_warn(codec, "HDMI: cvt NID 0x%x not registered\n", cvt_nid); 133 return -EINVAL; 134 } 135 136 static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, 137 struct snd_ctl_elem_info *uinfo) 138 { 139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 140 struct hdmi_spec *spec = codec->spec; 141 struct hdmi_spec_per_pin *per_pin; 142 struct hdmi_eld *eld; 143 int pcm_idx; 144 145 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 146 147 pcm_idx = kcontrol->private_value; 148 mutex_lock(&spec->pcm_lock); 149 per_pin = pcm_idx_to_pin(spec, pcm_idx); 150 if (!per_pin) { 151 /* no pin is bound to the pcm */ 152 uinfo->count = 0; 153 goto unlock; 154 } 155 eld = &per_pin->sink_eld; 156 uinfo->count = eld->eld_valid ? eld->eld_size : 0; 157 158 unlock: 159 mutex_unlock(&spec->pcm_lock); 160 return 0; 161 } 162 163 static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, 164 struct snd_ctl_elem_value *ucontrol) 165 { 166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 167 struct hdmi_spec *spec = codec->spec; 168 struct hdmi_spec_per_pin *per_pin; 169 struct hdmi_eld *eld; 170 int pcm_idx; 171 int err = 0; 172 173 pcm_idx = kcontrol->private_value; 174 mutex_lock(&spec->pcm_lock); 175 per_pin = pcm_idx_to_pin(spec, pcm_idx); 176 if (!per_pin) { 177 /* no pin is bound to the pcm */ 178 memset(ucontrol->value.bytes.data, 0, 179 ARRAY_SIZE(ucontrol->value.bytes.data)); 180 goto unlock; 181 } 182 183 eld = &per_pin->sink_eld; 184 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) || 185 eld->eld_size > ELD_MAX_SIZE) { 186 snd_BUG(); 187 err = -EINVAL; 188 goto unlock; 189 } 190 191 memset(ucontrol->value.bytes.data, 0, 192 ARRAY_SIZE(ucontrol->value.bytes.data)); 193 if (eld->eld_valid) 194 memcpy(ucontrol->value.bytes.data, eld->eld_buffer, 195 eld->eld_size); 196 197 unlock: 198 mutex_unlock(&spec->pcm_lock); 199 return err; 200 } 201 202 static const struct snd_kcontrol_new eld_bytes_ctl = { 203 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE | 204 SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK, 205 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 206 .name = "ELD", 207 .info = hdmi_eld_ctl_info, 208 .get = hdmi_eld_ctl_get, 209 }; 210 211 static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx, 212 int device) 213 { 214 struct snd_kcontrol *kctl; 215 struct hdmi_spec *spec = codec->spec; 216 int err; 217 218 kctl = snd_ctl_new1(&eld_bytes_ctl, codec); 219 if (!kctl) 220 return -ENOMEM; 221 kctl->private_value = pcm_idx; 222 kctl->id.device = device; 223 224 /* no pin nid is associated with the kctl now 225 * tbd: associate pin nid to eld ctl later 226 */ 227 err = snd_hda_ctl_add(codec, 0, kctl); 228 if (err < 0) 229 return err; 230 231 get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl; 232 return 0; 233 } 234 235 #ifdef BE_PARANOID 236 static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 237 int *packet_index, int *byte_index) 238 { 239 int val; 240 241 val = snd_hda_codec_read(codec, pin_nid, 0, 242 AC_VERB_GET_HDMI_DIP_INDEX, 0); 243 244 *packet_index = val >> 5; 245 *byte_index = val & 0x1f; 246 } 247 #endif 248 249 static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 250 int packet_index, int byte_index) 251 { 252 int val; 253 254 val = (packet_index << 5) | (byte_index & 0x1f); 255 256 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); 257 } 258 259 static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, 260 unsigned char val) 261 { 262 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); 263 } 264 265 static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid) 266 { 267 struct hdmi_spec *spec = codec->spec; 268 int pin_out; 269 270 /* Unmute */ 271 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 272 snd_hda_codec_write(codec, pin_nid, 0, 273 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 274 275 if (spec->dyn_pin_out) 276 /* Disable pin out until stream is active */ 277 pin_out = 0; 278 else 279 /* Enable pin out: some machines with GM965 gets broken output 280 * when the pin is disabled or changed while using with HDMI 281 */ 282 pin_out = PIN_OUT; 283 284 snd_hda_codec_write(codec, pin_nid, 0, 285 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out); 286 } 287 288 /* 289 * ELD proc files 290 */ 291 292 #ifdef CONFIG_SND_PROC_FS 293 static void print_eld_info(struct snd_info_entry *entry, 294 struct snd_info_buffer *buffer) 295 { 296 struct hdmi_spec_per_pin *per_pin = entry->private_data; 297 298 mutex_lock(&per_pin->lock); 299 snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer, per_pin->pin_nid, 300 per_pin->dev_id, per_pin->cvt_nid); 301 mutex_unlock(&per_pin->lock); 302 } 303 304 static void write_eld_info(struct snd_info_entry *entry, 305 struct snd_info_buffer *buffer) 306 { 307 struct hdmi_spec_per_pin *per_pin = entry->private_data; 308 309 mutex_lock(&per_pin->lock); 310 snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer); 311 mutex_unlock(&per_pin->lock); 312 } 313 314 static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) 315 { 316 char name[32]; 317 struct hda_codec *codec = per_pin->codec; 318 struct snd_info_entry *entry; 319 int err; 320 321 snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); 322 err = snd_card_proc_new(codec->card, name, &entry); 323 if (err < 0) 324 return err; 325 326 snd_info_set_text_ops(entry, per_pin, print_eld_info); 327 entry->c.text.write = write_eld_info; 328 entry->mode |= 0200; 329 per_pin->proc_entry = entry; 330 331 return 0; 332 } 333 334 static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) 335 { 336 if (!per_pin->codec->bus->shutdown) { 337 snd_info_free_entry(per_pin->proc_entry); 338 per_pin->proc_entry = NULL; 339 } 340 } 341 #else 342 static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin, 343 int index) 344 { 345 return 0; 346 } 347 static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin) 348 { 349 } 350 #endif 351 352 /* 353 * Audio InfoFrame routines 354 */ 355 356 /* 357 * Enable Audio InfoFrame Transmission 358 */ 359 static void hdmi_start_infoframe_trans(struct hda_codec *codec, 360 hda_nid_t pin_nid) 361 { 362 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 363 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 364 AC_DIPXMIT_BEST); 365 } 366 367 /* 368 * Disable Audio InfoFrame Transmission 369 */ 370 static void hdmi_stop_infoframe_trans(struct hda_codec *codec, 371 hda_nid_t pin_nid) 372 { 373 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 374 snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, 375 AC_DIPXMIT_DISABLE); 376 } 377 378 static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) 379 { 380 #ifdef CONFIG_SND_DEBUG_VERBOSE 381 int i; 382 int size; 383 384 size = snd_hdmi_get_eld_size(codec, pin_nid); 385 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size); 386 387 for (i = 0; i < 8; i++) { 388 size = snd_hda_codec_read(codec, pin_nid, 0, 389 AC_VERB_GET_HDMI_DIP_SIZE, i); 390 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size); 391 } 392 #endif 393 } 394 395 static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) 396 { 397 #ifdef BE_PARANOID 398 int i, j; 399 int size; 400 int pi, bi; 401 for (i = 0; i < 8; i++) { 402 size = snd_hda_codec_read(codec, pin_nid, 0, 403 AC_VERB_GET_HDMI_DIP_SIZE, i); 404 if (size == 0) 405 continue; 406 407 hdmi_set_dip_index(codec, pin_nid, i, 0x0); 408 for (j = 1; j < 1000; j++) { 409 hdmi_write_dip_byte(codec, pin_nid, 0x0); 410 hdmi_get_dip_index(codec, pin_nid, &pi, &bi); 411 if (pi != i) 412 codec_dbg(codec, "dip index %d: %d != %d\n", 413 bi, pi, i); 414 if (bi == 0) /* byte index wrapped around */ 415 break; 416 } 417 codec_dbg(codec, 418 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", 419 i, size, j); 420 } 421 #endif 422 } 423 424 static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai) 425 { 426 u8 *bytes = (u8 *)hdmi_ai; 427 u8 sum = 0; 428 int i; 429 430 hdmi_ai->checksum = 0; 431 432 for (i = 0; i < sizeof(*hdmi_ai); i++) 433 sum += bytes[i]; 434 435 hdmi_ai->checksum = -sum; 436 } 437 438 static void hdmi_fill_audio_infoframe(struct hda_codec *codec, 439 hda_nid_t pin_nid, 440 u8 *dip, int size) 441 { 442 int i; 443 444 hdmi_debug_dip_size(codec, pin_nid); 445 hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ 446 447 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 448 for (i = 0; i < size; i++) 449 hdmi_write_dip_byte(codec, pin_nid, dip[i]); 450 } 451 452 static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, 453 u8 *dip, int size) 454 { 455 u8 val; 456 int i; 457 458 hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); 459 if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) 460 != AC_DIPXMIT_BEST) 461 return false; 462 463 for (i = 0; i < size; i++) { 464 val = snd_hda_codec_read(codec, pin_nid, 0, 465 AC_VERB_GET_HDMI_DIP_DATA, 0); 466 if (val != dip[i]) 467 return false; 468 } 469 470 return true; 471 } 472 473 static int hdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, 474 int dev_id, unsigned char *buf, int *eld_size) 475 { 476 snd_hda_set_dev_select(codec, nid, dev_id); 477 478 return snd_hdmi_get_eld(codec, nid, buf, eld_size); 479 } 480 481 static void hdmi_pin_setup_infoframe(struct hda_codec *codec, 482 hda_nid_t pin_nid, int dev_id, 483 int ca, int active_channels, 484 int conn_type) 485 { 486 struct hdmi_spec *spec = codec->spec; 487 union audio_infoframe ai; 488 489 memset(&ai, 0, sizeof(ai)); 490 if ((conn_type == 0) || /* HDMI */ 491 /* Nvidia DisplayPort: Nvidia HW expects same layout as HDMI */ 492 (conn_type == 1 && spec->nv_dp_workaround)) { 493 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; 494 495 if (conn_type == 0) { /* HDMI */ 496 hdmi_ai->type = 0x84; 497 hdmi_ai->ver = 0x01; 498 hdmi_ai->len = 0x0a; 499 } else {/* Nvidia DP */ 500 hdmi_ai->type = 0x84; 501 hdmi_ai->ver = 0x1b; 502 hdmi_ai->len = 0x11 << 2; 503 } 504 hdmi_ai->CC02_CT47 = active_channels - 1; 505 hdmi_ai->CA = ca; 506 hdmi_checksum_audio_infoframe(hdmi_ai); 507 } else if (conn_type == 1) { /* DisplayPort */ 508 struct dp_audio_infoframe *dp_ai = &ai.dp; 509 510 dp_ai->type = 0x84; 511 dp_ai->len = 0x1b; 512 dp_ai->ver = 0x11 << 2; 513 dp_ai->CC02_CT47 = active_channels - 1; 514 dp_ai->CA = ca; 515 } else { 516 codec_dbg(codec, "HDMI: unknown connection type at pin NID 0x%x\n", pin_nid); 517 return; 518 } 519 520 snd_hda_set_dev_select(codec, pin_nid, dev_id); 521 522 /* 523 * sizeof(ai) is used instead of sizeof(*hdmi_ai) or 524 * sizeof(*dp_ai) to avoid partial match/update problems when 525 * the user switches between HDMI/DP monitors. 526 */ 527 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, 528 sizeof(ai))) { 529 codec_dbg(codec, "%s: pin NID=0x%x channels=%d ca=0x%02x\n", 530 __func__, pin_nid, active_channels, ca); 531 hdmi_stop_infoframe_trans(codec, pin_nid); 532 hdmi_fill_audio_infoframe(codec, pin_nid, 533 ai.bytes, sizeof(ai)); 534 hdmi_start_infoframe_trans(codec, pin_nid); 535 } 536 } 537 538 void snd_hda_hdmi_setup_audio_infoframe(struct hda_codec *codec, 539 struct hdmi_spec_per_pin *per_pin, 540 bool non_pcm) 541 { 542 struct hdmi_spec *spec = codec->spec; 543 struct hdac_chmap *chmap = &spec->chmap; 544 hda_nid_t pin_nid = per_pin->pin_nid; 545 int dev_id = per_pin->dev_id; 546 int channels = per_pin->channels; 547 int active_channels; 548 struct hdmi_eld *eld; 549 int ca; 550 551 if (!channels) 552 return; 553 554 snd_hda_set_dev_select(codec, pin_nid, dev_id); 555 556 /* some HW (e.g. HSW+) needs reprogramming the amp at each time */ 557 if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) 558 snd_hda_codec_write(codec, pin_nid, 0, 559 AC_VERB_SET_AMP_GAIN_MUTE, 560 AMP_OUT_UNMUTE); 561 562 eld = &per_pin->sink_eld; 563 564 ca = snd_hdac_channel_allocation(&codec->core, 565 eld->info.spk_alloc, channels, 566 per_pin->chmap_set, non_pcm, per_pin->chmap); 567 568 active_channels = snd_hdac_get_active_channels(ca); 569 570 chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid, 571 active_channels); 572 573 /* 574 * always configure channel mapping, it may have been changed by the 575 * user in the meantime 576 */ 577 snd_hdac_setup_channel_mapping(&spec->chmap, 578 pin_nid, non_pcm, ca, channels, 579 per_pin->chmap, per_pin->chmap_set); 580 581 spec->ops.pin_setup_infoframe(codec, pin_nid, dev_id, 582 ca, active_channels, eld->info.conn_type); 583 584 per_pin->non_pcm = non_pcm; 585 } 586 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_setup_audio_infoframe, "SND_HDA_CODEC_HDMI"); 587 588 /* 589 * Unsolicited events 590 */ 591 592 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); 593 594 void snd_hda_hdmi_check_presence_and_report(struct hda_codec *codec, 595 hda_nid_t nid, int dev_id) 596 { 597 struct hdmi_spec *spec = codec->spec; 598 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id); 599 600 if (pin_idx < 0) 601 return; 602 mutex_lock(&spec->pcm_lock); 603 hdmi_present_sense(get_pin(spec, pin_idx), 1); 604 mutex_unlock(&spec->pcm_lock); 605 } 606 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_check_presence_and_report, 607 "SND_HDA_CODEC_HDMI"); 608 609 static void jack_callback(struct hda_codec *codec, 610 struct hda_jack_callback *jack) 611 { 612 /* stop polling when notification is enabled */ 613 if (codec_has_acomp(codec)) 614 return; 615 616 snd_hda_hdmi_check_presence_and_report(codec, jack->nid, jack->dev_id); 617 } 618 619 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res, 620 struct hda_jack_tbl *jack) 621 { 622 jack->jack_dirty = 1; 623 624 codec_dbg(codec, 625 "HDMI hot plug event: Codec=%d NID=0x%x Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", 626 codec->addr, jack->nid, jack->dev_id, !!(res & AC_UNSOL_RES_IA), 627 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); 628 629 snd_hda_hdmi_check_presence_and_report(codec, jack->nid, jack->dev_id); 630 } 631 632 static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 633 { 634 int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 635 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 636 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 637 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 638 639 codec_info(codec, 640 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 641 codec->addr, 642 tag, 643 subtag, 644 cp_state, 645 cp_ready); 646 647 /* TODO */ 648 if (cp_state) { 649 ; 650 } 651 if (cp_ready) { 652 ; 653 } 654 } 655 656 void snd_hda_hdmi_generic_unsol_event(struct hda_codec *codec, unsigned int res) 657 { 658 int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 659 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 660 struct hda_jack_tbl *jack; 661 662 if (codec_has_acomp(codec)) 663 return; 664 665 if (codec->dp_mst) { 666 int dev_entry = 667 (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; 668 669 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, dev_entry); 670 } else { 671 jack = snd_hda_jack_tbl_get_from_tag(codec, tag, 0); 672 } 673 674 if (!jack) { 675 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag); 676 return; 677 } 678 679 if (subtag == 0) 680 hdmi_intrinsic_event(codec, res, jack); 681 else 682 hdmi_non_intrinsic_event(codec, res); 683 } 684 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_unsol_event, "SND_HDA_CODEC_HDMI"); 685 686 /* 687 * Callbacks 688 */ 689 690 /* HBR should be Non-PCM, 8 channels */ 691 #define is_hbr_format(format) \ 692 ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) 693 694 static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, 695 int dev_id, bool hbr) 696 { 697 int pinctl, new_pinctl; 698 699 if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { 700 snd_hda_set_dev_select(codec, pin_nid, dev_id); 701 pinctl = snd_hda_codec_read(codec, pin_nid, 0, 702 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 703 704 if (pinctl < 0) 705 return hbr ? -EINVAL : 0; 706 707 new_pinctl = pinctl & ~AC_PINCTL_EPT; 708 if (hbr) 709 new_pinctl |= AC_PINCTL_EPT_HBR; 710 else 711 new_pinctl |= AC_PINCTL_EPT_NATIVE; 712 713 codec_dbg(codec, 714 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n", 715 pin_nid, 716 pinctl == new_pinctl ? "" : "new-", 717 new_pinctl); 718 719 if (pinctl != new_pinctl) 720 snd_hda_codec_write(codec, pin_nid, 0, 721 AC_VERB_SET_PIN_WIDGET_CONTROL, 722 new_pinctl); 723 } else if (hbr) 724 return -EINVAL; 725 726 return 0; 727 } 728 729 int snd_hda_hdmi_setup_stream(struct hda_codec *codec, 730 hda_nid_t cvt_nid, 731 hda_nid_t pin_nid, int dev_id, 732 u32 stream_tag, int format) 733 { 734 struct hdmi_spec *spec = codec->spec; 735 unsigned int param; 736 int err; 737 738 err = spec->ops.pin_hbr_setup(codec, pin_nid, dev_id, 739 is_hbr_format(format)); 740 741 if (err) { 742 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n"); 743 return err; 744 } 745 746 if (spec->intel_hsw_fixup) { 747 748 /* 749 * on recent platforms IEC Coding Type is required for HBR 750 * support, read current Digital Converter settings and set 751 * ICT bitfield if needed. 752 */ 753 param = snd_hda_codec_read(codec, cvt_nid, 0, 754 AC_VERB_GET_DIGI_CONVERT_1, 0); 755 756 param = (param >> 16) & ~(AC_DIG3_ICT); 757 758 /* on recent platforms ICT mode is required for HBR support */ 759 if (is_hbr_format(format)) 760 param |= 0x1; 761 762 snd_hda_codec_write(codec, cvt_nid, 0, 763 AC_VERB_SET_DIGI_CONVERT_3, param); 764 } 765 766 snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); 767 return 0; 768 } 769 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_setup_stream, "SND_HDA_CODEC_HDMI"); 770 771 /* Try to find an available converter 772 * If pin_idx is less then zero, just try to find an available converter. 773 * Otherwise, try to find an available converter and get the cvt mux index 774 * of the pin. 775 */ 776 static int hdmi_choose_cvt(struct hda_codec *codec, 777 int pin_idx, int *cvt_id, 778 bool silent) 779 { 780 struct hdmi_spec *spec = codec->spec; 781 struct hdmi_spec_per_pin *per_pin; 782 struct hdmi_spec_per_cvt *per_cvt = NULL; 783 int cvt_idx, mux_idx = 0; 784 785 /* pin_idx < 0 means no pin will be bound to the converter */ 786 if (pin_idx < 0) 787 per_pin = NULL; 788 else 789 per_pin = get_pin(spec, pin_idx); 790 791 if (per_pin && per_pin->silent_stream) { 792 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); 793 per_cvt = get_cvt(spec, cvt_idx); 794 if (per_cvt->assigned && !silent) 795 return -EBUSY; 796 if (cvt_id) 797 *cvt_id = cvt_idx; 798 return 0; 799 } 800 801 /* Dynamically assign converter to stream */ 802 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { 803 per_cvt = get_cvt(spec, cvt_idx); 804 805 /* Must not already be assigned */ 806 if (per_cvt->assigned || per_cvt->silent_stream) 807 continue; 808 if (per_pin == NULL) 809 break; 810 /* Must be in pin's mux's list of converters */ 811 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) 812 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid) 813 break; 814 /* Not in mux list */ 815 if (mux_idx == per_pin->num_mux_nids) 816 continue; 817 break; 818 } 819 820 /* No free converters */ 821 if (cvt_idx == spec->num_cvts) 822 return -EBUSY; 823 824 if (per_pin != NULL) 825 per_pin->mux_idx = mux_idx; 826 827 if (cvt_id) 828 *cvt_id = cvt_idx; 829 830 return 0; 831 } 832 833 /* skeleton caller of pin_cvt_fixup ops */ 834 static void pin_cvt_fixup(struct hda_codec *codec, 835 struct hdmi_spec_per_pin *per_pin, 836 hda_nid_t cvt_nid) 837 { 838 struct hdmi_spec *spec = codec->spec; 839 840 if (spec->ops.pin_cvt_fixup) 841 spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid); 842 } 843 844 /* called in hdmi_pcm_open when no pin is assigned to the PCM */ 845 static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo, 846 struct hda_codec *codec, 847 struct snd_pcm_substream *substream) 848 { 849 struct hdmi_spec *spec = codec->spec; 850 struct snd_pcm_runtime *runtime = substream->runtime; 851 int cvt_idx, pcm_idx; 852 struct hdmi_spec_per_cvt *per_cvt = NULL; 853 int err; 854 855 pcm_idx = hinfo_to_pcm_index(codec, hinfo); 856 if (pcm_idx < 0) 857 return -EINVAL; 858 859 err = hdmi_choose_cvt(codec, -1, &cvt_idx, false); 860 if (err) 861 return err; 862 863 per_cvt = get_cvt(spec, cvt_idx); 864 per_cvt->assigned = true; 865 hinfo->nid = per_cvt->cvt_nid; 866 867 pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid); 868 869 set_bit(pcm_idx, &spec->pcm_in_use); 870 /* todo: setup spdif ctls assign */ 871 872 /* Initially set the converter's capabilities */ 873 hinfo->channels_min = per_cvt->channels_min; 874 hinfo->channels_max = per_cvt->channels_max; 875 hinfo->rates = per_cvt->rates; 876 hinfo->formats = per_cvt->formats; 877 hinfo->maxbps = per_cvt->maxbps; 878 879 /* Store the updated parameters */ 880 runtime->hw.channels_min = hinfo->channels_min; 881 runtime->hw.channels_max = hinfo->channels_max; 882 runtime->hw.formats = hinfo->formats; 883 runtime->hw.rates = hinfo->rates; 884 885 snd_pcm_hw_constraint_step(substream->runtime, 0, 886 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 887 return 0; 888 } 889 890 /* 891 * HDA PCM callbacks 892 */ 893 static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, 894 struct hda_codec *codec, 895 struct snd_pcm_substream *substream) 896 { 897 struct hdmi_spec *spec = codec->spec; 898 struct snd_pcm_runtime *runtime = substream->runtime; 899 int pin_idx, cvt_idx, pcm_idx; 900 struct hdmi_spec_per_pin *per_pin; 901 struct hdmi_eld *eld; 902 struct hdmi_spec_per_cvt *per_cvt = NULL; 903 int err; 904 905 /* Validate hinfo */ 906 pcm_idx = hinfo_to_pcm_index(codec, hinfo); 907 if (pcm_idx < 0) 908 return -EINVAL; 909 910 mutex_lock(&spec->pcm_lock); 911 pin_idx = hinfo_to_pin_index(codec, hinfo); 912 /* no pin is assigned to the PCM 913 * PA need pcm open successfully when probe 914 */ 915 if (pin_idx < 0) { 916 err = hdmi_pcm_open_no_pin(hinfo, codec, substream); 917 goto unlock; 918 } 919 920 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, false); 921 if (err < 0) 922 goto unlock; 923 924 per_cvt = get_cvt(spec, cvt_idx); 925 /* Claim converter */ 926 per_cvt->assigned = true; 927 928 set_bit(pcm_idx, &spec->pcm_in_use); 929 per_pin = get_pin(spec, pin_idx); 930 per_pin->cvt_nid = per_cvt->cvt_nid; 931 hinfo->nid = per_cvt->cvt_nid; 932 933 /* flip stripe flag for the assigned stream if supported */ 934 if (get_wcaps(codec, per_cvt->cvt_nid) & AC_WCAP_STRIPE) 935 azx_stream(get_azx_dev(substream))->stripe = 1; 936 937 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); 938 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 939 AC_VERB_SET_CONNECT_SEL, 940 per_pin->mux_idx); 941 942 /* configure unused pins to choose other converters */ 943 pin_cvt_fixup(codec, per_pin, 0); 944 945 snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid); 946 947 /* Initially set the converter's capabilities */ 948 hinfo->channels_min = per_cvt->channels_min; 949 hinfo->channels_max = per_cvt->channels_max; 950 hinfo->rates = per_cvt->rates; 951 hinfo->formats = per_cvt->formats; 952 hinfo->maxbps = per_cvt->maxbps; 953 954 eld = &per_pin->sink_eld; 955 /* Restrict capabilities by ELD if this isn't disabled */ 956 if (!static_hdmi_pcm && eld->eld_valid) { 957 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo); 958 if (hinfo->channels_min > hinfo->channels_max || 959 !hinfo->rates || !hinfo->formats) { 960 per_cvt->assigned = false; 961 hinfo->nid = 0; 962 snd_hda_spdif_ctls_unassign(codec, pcm_idx); 963 err = -ENODEV; 964 goto unlock; 965 } 966 } 967 968 /* Store the updated parameters */ 969 runtime->hw.channels_min = hinfo->channels_min; 970 runtime->hw.channels_max = hinfo->channels_max; 971 runtime->hw.formats = hinfo->formats; 972 runtime->hw.rates = hinfo->rates; 973 974 snd_pcm_hw_constraint_step(substream->runtime, 0, 975 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 976 unlock: 977 mutex_unlock(&spec->pcm_lock); 978 return err; 979 } 980 981 /* 982 * HDA/HDMI auto parsing 983 */ 984 static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) 985 { 986 struct hdmi_spec *spec = codec->spec; 987 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 988 hda_nid_t pin_nid = per_pin->pin_nid; 989 int dev_id = per_pin->dev_id; 990 int conns; 991 992 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 993 codec_warn(codec, 994 "HDMI: pin NID 0x%x wcaps %#x does not support connection list\n", 995 pin_nid, get_wcaps(codec, pin_nid)); 996 return -EINVAL; 997 } 998 999 snd_hda_set_dev_select(codec, pin_nid, dev_id); 1000 1001 if (spec->intel_hsw_fixup) { 1002 conns = spec->num_cvts; 1003 memcpy(per_pin->mux_nids, spec->cvt_nids, 1004 sizeof(hda_nid_t) * conns); 1005 } else { 1006 conns = snd_hda_get_raw_connections(codec, pin_nid, 1007 per_pin->mux_nids, 1008 HDA_MAX_CONNECTIONS); 1009 } 1010 1011 /* all the device entries on the same pin have the same conn list */ 1012 per_pin->num_mux_nids = conns; 1013 1014 return 0; 1015 } 1016 1017 static int hdmi_find_pcm_slot(struct hdmi_spec *spec, 1018 struct hdmi_spec_per_pin *per_pin) 1019 { 1020 int i; 1021 1022 for (i = 0; i < spec->pcm_used; i++) { 1023 if (!test_bit(i, &spec->pcm_bitmap)) 1024 return i; 1025 } 1026 return -EBUSY; 1027 } 1028 1029 static void hdmi_attach_hda_pcm(struct hdmi_spec *spec, 1030 struct hdmi_spec_per_pin *per_pin) 1031 { 1032 int idx; 1033 1034 /* pcm already be attached to the pin */ 1035 if (per_pin->pcm) 1036 return; 1037 /* try the previously used slot at first */ 1038 idx = per_pin->prev_pcm_idx; 1039 if (idx >= 0) { 1040 if (!test_bit(idx, &spec->pcm_bitmap)) 1041 goto found; 1042 per_pin->prev_pcm_idx = -1; /* no longer valid, clear it */ 1043 } 1044 idx = hdmi_find_pcm_slot(spec, per_pin); 1045 if (idx == -EBUSY) 1046 return; 1047 found: 1048 per_pin->pcm_idx = idx; 1049 per_pin->pcm = get_hdmi_pcm(spec, idx); 1050 set_bit(idx, &spec->pcm_bitmap); 1051 } 1052 1053 static void hdmi_detach_hda_pcm(struct hdmi_spec *spec, 1054 struct hdmi_spec_per_pin *per_pin) 1055 { 1056 int idx; 1057 1058 /* pcm already be detached from the pin */ 1059 if (!per_pin->pcm) 1060 return; 1061 idx = per_pin->pcm_idx; 1062 per_pin->pcm_idx = -1; 1063 per_pin->prev_pcm_idx = idx; /* remember the previous index */ 1064 per_pin->pcm = NULL; 1065 if (idx >= 0 && idx < spec->pcm_used) 1066 clear_bit(idx, &spec->pcm_bitmap); 1067 } 1068 1069 static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec, 1070 struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid) 1071 { 1072 int mux_idx; 1073 1074 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) 1075 if (per_pin->mux_nids[mux_idx] == cvt_nid) 1076 break; 1077 return mux_idx; 1078 } 1079 1080 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid); 1081 1082 static void hdmi_pcm_setup_pin(struct hdmi_spec *spec, 1083 struct hdmi_spec_per_pin *per_pin) 1084 { 1085 struct hda_codec *codec = per_pin->codec; 1086 struct hda_pcm *pcm; 1087 struct hda_pcm_stream *hinfo; 1088 struct snd_pcm_substream *substream; 1089 int mux_idx; 1090 bool non_pcm; 1091 1092 if (per_pin->pcm_idx < 0 || per_pin->pcm_idx >= spec->pcm_used) 1093 return; 1094 pcm = get_pcm_rec(spec, per_pin->pcm_idx); 1095 if (!pcm->pcm) 1096 return; 1097 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use)) 1098 return; 1099 1100 /* hdmi audio only uses playback and one substream */ 1101 hinfo = pcm->stream; 1102 substream = pcm->pcm->streams[0].substream; 1103 1104 per_pin->cvt_nid = hinfo->nid; 1105 1106 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid); 1107 if (mux_idx < per_pin->num_mux_nids) { 1108 snd_hda_set_dev_select(codec, per_pin->pin_nid, 1109 per_pin->dev_id); 1110 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1111 AC_VERB_SET_CONNECT_SEL, 1112 mux_idx); 1113 } 1114 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid); 1115 1116 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid); 1117 if (substream->runtime) 1118 per_pin->channels = substream->runtime->channels; 1119 per_pin->setup = true; 1120 per_pin->mux_idx = mux_idx; 1121 1122 snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); 1123 } 1124 1125 static void hdmi_pcm_reset_pin(struct hdmi_spec *spec, 1126 struct hdmi_spec_per_pin *per_pin) 1127 { 1128 if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used) 1129 snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx); 1130 1131 per_pin->chmap_set = false; 1132 memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); 1133 1134 per_pin->setup = false; 1135 per_pin->channels = 0; 1136 } 1137 1138 static struct snd_jack *pin_idx_to_pcm_jack(struct hda_codec *codec, 1139 struct hdmi_spec_per_pin *per_pin) 1140 { 1141 struct hdmi_spec *spec = codec->spec; 1142 1143 if (per_pin->pcm_idx >= 0) 1144 return spec->pcm_rec[per_pin->pcm_idx].jack; 1145 else 1146 return NULL; 1147 } 1148 1149 /* update per_pin ELD from the given new ELD; 1150 * setup info frame and notification accordingly 1151 * also notify ELD kctl and report jack status changes 1152 */ 1153 static void update_eld(struct hda_codec *codec, 1154 struct hdmi_spec_per_pin *per_pin, 1155 struct hdmi_eld *eld, 1156 int repoll) 1157 { 1158 struct hdmi_eld *pin_eld = &per_pin->sink_eld; 1159 struct hdmi_spec *spec = codec->spec; 1160 struct snd_jack *pcm_jack; 1161 bool old_eld_valid = pin_eld->eld_valid; 1162 bool eld_changed; 1163 int pcm_idx; 1164 1165 if (eld->eld_valid) { 1166 if (eld->eld_size <= 0 || 1167 snd_parse_eld(hda_codec_dev(codec), &eld->info, 1168 eld->eld_buffer, eld->eld_size) < 0) { 1169 eld->eld_valid = false; 1170 if (repoll) { 1171 schedule_delayed_work(&per_pin->work, 1172 msecs_to_jiffies(300)); 1173 return; 1174 } 1175 } 1176 } 1177 1178 if (!eld->eld_valid || eld->eld_size <= 0 || eld->info.sad_count <= 0) { 1179 eld->eld_valid = false; 1180 eld->eld_size = 0; 1181 } 1182 1183 /* for monitor disconnection, save pcm_idx firstly */ 1184 pcm_idx = per_pin->pcm_idx; 1185 1186 /* 1187 * pcm_idx >=0 before update_eld() means it is in monitor 1188 * disconnected event. Jack must be fetched before update_eld(). 1189 */ 1190 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); 1191 1192 if (!spec->static_pcm_mapping) { 1193 if (eld->eld_valid) { 1194 hdmi_attach_hda_pcm(spec, per_pin); 1195 hdmi_pcm_setup_pin(spec, per_pin); 1196 } else { 1197 hdmi_pcm_reset_pin(spec, per_pin); 1198 hdmi_detach_hda_pcm(spec, per_pin); 1199 } 1200 } 1201 1202 /* if pcm_idx == -1, it means this is in monitor connection event 1203 * we can get the correct pcm_idx now. 1204 */ 1205 if (pcm_idx == -1) 1206 pcm_idx = per_pin->pcm_idx; 1207 if (!pcm_jack) 1208 pcm_jack = pin_idx_to_pcm_jack(codec, per_pin); 1209 1210 if (eld->eld_valid) 1211 snd_show_eld(hda_codec_dev(codec), &eld->info); 1212 1213 eld_changed = (pin_eld->eld_valid != eld->eld_valid); 1214 eld_changed |= (pin_eld->monitor_present != eld->monitor_present); 1215 if (!eld_changed && eld->eld_valid && pin_eld->eld_valid) 1216 if (pin_eld->eld_size != eld->eld_size || 1217 memcmp(pin_eld->eld_buffer, eld->eld_buffer, 1218 eld->eld_size) != 0) 1219 eld_changed = true; 1220 1221 if (eld_changed) { 1222 pin_eld->monitor_present = eld->monitor_present; 1223 pin_eld->eld_valid = eld->eld_valid; 1224 pin_eld->eld_size = eld->eld_size; 1225 if (eld->eld_valid) 1226 memcpy(pin_eld->eld_buffer, eld->eld_buffer, 1227 eld->eld_size); 1228 pin_eld->info = eld->info; 1229 } 1230 1231 /* 1232 * Re-setup pin and infoframe. This is needed e.g. when 1233 * - sink is first plugged-in 1234 * - transcoder can change during stream playback on Haswell 1235 * and this can make HW reset converter selection on a pin. 1236 */ 1237 if (eld->eld_valid && !old_eld_valid && per_pin->setup) { 1238 pin_cvt_fixup(codec, per_pin, 0); 1239 snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); 1240 } 1241 1242 if (eld_changed && pcm_idx >= 0) 1243 snd_ctl_notify(codec->card, 1244 SNDRV_CTL_EVENT_MASK_VALUE | 1245 SNDRV_CTL_EVENT_MASK_INFO, 1246 &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id); 1247 1248 if (eld_changed && pcm_jack) 1249 snd_jack_report(pcm_jack, 1250 (eld->monitor_present && eld->eld_valid) ? 1251 SND_JACK_AVOUT : 0); 1252 } 1253 1254 /* update ELD and jack state via HD-audio verbs */ 1255 static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, 1256 int repoll) 1257 { 1258 struct hda_codec *codec = per_pin->codec; 1259 struct hdmi_spec *spec = codec->spec; 1260 struct hdmi_eld *eld = &spec->temp_eld; 1261 struct device *dev = hda_codec_dev(codec); 1262 hda_nid_t pin_nid = per_pin->pin_nid; 1263 int dev_id = per_pin->dev_id; 1264 /* 1265 * Always execute a GetPinSense verb here, even when called from 1266 * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited 1267 * response's PD bit is not the real PD value, but indicates that 1268 * the real PD value changed. An older version of the HD-audio 1269 * specification worked this way. Hence, we just ignore the data in 1270 * the unsolicited response to avoid custom WARs. 1271 */ 1272 int present; 1273 int ret; 1274 1275 #ifdef CONFIG_PM 1276 if (dev->power.runtime_status == RPM_SUSPENDING) 1277 return; 1278 #endif 1279 1280 ret = snd_hda_power_up_pm(codec); 1281 if (ret < 0 && pm_runtime_suspended(dev)) 1282 goto out; 1283 1284 present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id); 1285 1286 mutex_lock(&per_pin->lock); 1287 eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); 1288 if (eld->monitor_present) 1289 eld->eld_valid = !!(present & AC_PINSENSE_ELDV); 1290 else 1291 eld->eld_valid = false; 1292 1293 codec_dbg(codec, 1294 "HDMI status: Codec=%d NID=0x%x Presence_Detect=%d ELD_Valid=%d\n", 1295 codec->addr, pin_nid, eld->monitor_present, eld->eld_valid); 1296 1297 if (eld->eld_valid) { 1298 if (spec->ops.pin_get_eld(codec, pin_nid, dev_id, 1299 eld->eld_buffer, &eld->eld_size) < 0) 1300 eld->eld_valid = false; 1301 } 1302 1303 update_eld(codec, per_pin, eld, repoll); 1304 mutex_unlock(&per_pin->lock); 1305 out: 1306 snd_hda_power_down_pm(codec); 1307 } 1308 1309 static void silent_stream_enable(struct hda_codec *codec, 1310 struct hdmi_spec_per_pin *per_pin) 1311 { 1312 struct hdmi_spec *spec = codec->spec; 1313 struct hdmi_spec_per_cvt *per_cvt; 1314 int cvt_idx, pin_idx, err; 1315 1316 /* 1317 * Power-up will call hdmi_present_sense, so the PM calls 1318 * have to be done without mutex held. 1319 */ 1320 1321 err = snd_hda_power_up_pm(codec); 1322 if (err < 0 && err != -EACCES) { 1323 codec_err(codec, 1324 "Failed to power up codec for silent stream enable ret=[%d]\n", err); 1325 snd_hda_power_down_pm(codec); 1326 return; 1327 } 1328 1329 mutex_lock(&per_pin->lock); 1330 1331 if (per_pin->setup) { 1332 codec_dbg(codec, "hdmi: PCM already open, no silent stream\n"); 1333 err = -EBUSY; 1334 goto unlock_out; 1335 } 1336 1337 pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id); 1338 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, true); 1339 if (err) { 1340 codec_err(codec, "hdmi: no free converter to enable silent mode\n"); 1341 goto unlock_out; 1342 } 1343 1344 per_cvt = get_cvt(spec, cvt_idx); 1345 per_cvt->silent_stream = true; 1346 per_pin->cvt_nid = per_cvt->cvt_nid; 1347 per_pin->silent_stream = true; 1348 1349 codec_dbg(codec, "hdmi: enabling silent stream pin-NID=0x%x cvt-NID=0x%x\n", 1350 per_pin->pin_nid, per_cvt->cvt_nid); 1351 1352 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); 1353 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1354 AC_VERB_SET_CONNECT_SEL, 1355 per_pin->mux_idx); 1356 1357 /* configure unused pins to choose other converters */ 1358 pin_cvt_fixup(codec, per_pin, 0); 1359 1360 spec->ops.silent_stream(codec, per_pin, true); 1361 1362 unlock_out: 1363 mutex_unlock(&per_pin->lock); 1364 1365 snd_hda_power_down_pm(codec); 1366 } 1367 1368 static void silent_stream_disable(struct hda_codec *codec, 1369 struct hdmi_spec_per_pin *per_pin) 1370 { 1371 struct hdmi_spec *spec = codec->spec; 1372 struct hdmi_spec_per_cvt *per_cvt; 1373 int cvt_idx, err; 1374 1375 err = snd_hda_power_up_pm(codec); 1376 if (err < 0 && err != -EACCES) { 1377 codec_err(codec, 1378 "Failed to power up codec for silent stream disable ret=[%d]\n", 1379 err); 1380 snd_hda_power_down_pm(codec); 1381 return; 1382 } 1383 1384 mutex_lock(&per_pin->lock); 1385 if (!per_pin->silent_stream) 1386 goto unlock_out; 1387 1388 codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n", 1389 per_pin->pin_nid, per_pin->cvt_nid); 1390 1391 cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); 1392 if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) { 1393 per_cvt = get_cvt(spec, cvt_idx); 1394 per_cvt->silent_stream = false; 1395 } 1396 1397 spec->ops.silent_stream(codec, per_pin, false); 1398 1399 per_pin->cvt_nid = 0; 1400 per_pin->silent_stream = false; 1401 1402 unlock_out: 1403 mutex_unlock(&per_pin->lock); 1404 1405 snd_hda_power_down_pm(codec); 1406 } 1407 1408 /* update ELD and jack state via audio component */ 1409 static void sync_eld_via_acomp(struct hda_codec *codec, 1410 struct hdmi_spec_per_pin *per_pin) 1411 { 1412 struct hdmi_spec *spec = codec->spec; 1413 struct hdmi_eld *eld = &spec->temp_eld; 1414 bool monitor_prev, monitor_next; 1415 1416 mutex_lock(&per_pin->lock); 1417 eld->monitor_present = false; 1418 monitor_prev = per_pin->sink_eld.monitor_present; 1419 eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, 1420 per_pin->dev_id, &eld->monitor_present, 1421 eld->eld_buffer, ELD_MAX_SIZE); 1422 eld->eld_valid = (eld->eld_size > 0); 1423 update_eld(codec, per_pin, eld, 0); 1424 monitor_next = per_pin->sink_eld.monitor_present; 1425 mutex_unlock(&per_pin->lock); 1426 1427 if (spec->silent_stream_type) { 1428 if (!monitor_prev && monitor_next) 1429 silent_stream_enable(codec, per_pin); 1430 else if (monitor_prev && !monitor_next) 1431 silent_stream_disable(codec, per_pin); 1432 } 1433 } 1434 1435 static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) 1436 { 1437 struct hda_codec *codec = per_pin->codec; 1438 1439 if (!codec_has_acomp(codec)) 1440 hdmi_present_sense_via_verbs(per_pin, repoll); 1441 else 1442 sync_eld_via_acomp(codec, per_pin); 1443 } 1444 1445 static void hdmi_repoll_eld(struct work_struct *work) 1446 { 1447 struct hdmi_spec_per_pin *per_pin = 1448 container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work); 1449 struct hda_codec *codec = per_pin->codec; 1450 struct hdmi_spec *spec = codec->spec; 1451 struct hda_jack_tbl *jack; 1452 1453 jack = snd_hda_jack_tbl_get_mst(codec, per_pin->pin_nid, 1454 per_pin->dev_id); 1455 if (jack) 1456 jack->jack_dirty = 1; 1457 1458 if (per_pin->repoll_count++ > 6) 1459 per_pin->repoll_count = 0; 1460 1461 mutex_lock(&spec->pcm_lock); 1462 hdmi_present_sense(per_pin, per_pin->repoll_count); 1463 mutex_unlock(&spec->pcm_lock); 1464 } 1465 1466 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) 1467 { 1468 struct hdmi_spec *spec = codec->spec; 1469 unsigned int caps, config; 1470 int pin_idx; 1471 struct hdmi_spec_per_pin *per_pin; 1472 int err; 1473 int dev_num, i; 1474 1475 caps = snd_hda_query_pin_caps(codec, pin_nid); 1476 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 1477 return 0; 1478 1479 /* 1480 * For DP MST audio, Configuration Default is the same for 1481 * all device entries on the same pin 1482 */ 1483 config = snd_hda_codec_get_pincfg(codec, pin_nid); 1484 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE && 1485 !spec->force_connect) 1486 return 0; 1487 1488 /* 1489 * To simplify the implementation, malloc all 1490 * the virtual pins in the initialization statically 1491 */ 1492 if (spec->intel_hsw_fixup) { 1493 /* 1494 * On Intel platforms, device entries count returned 1495 * by AC_PAR_DEVLIST_LEN is dynamic, and depends on 1496 * the type of receiver that is connected. Allocate pin 1497 * structures based on worst case. 1498 */ 1499 dev_num = spec->dev_num; 1500 } else if (codec->dp_mst) { 1501 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1; 1502 /* 1503 * spec->dev_num is the maxinum number of device entries 1504 * among all the pins 1505 */ 1506 spec->dev_num = (spec->dev_num > dev_num) ? 1507 spec->dev_num : dev_num; 1508 } else { 1509 /* 1510 * If the platform doesn't support DP MST, 1511 * manually set dev_num to 1. This means 1512 * the pin has only one device entry. 1513 */ 1514 dev_num = 1; 1515 spec->dev_num = 1; 1516 } 1517 1518 for (i = 0; i < dev_num; i++) { 1519 pin_idx = spec->num_pins; 1520 per_pin = snd_array_new(&spec->pins); 1521 1522 if (!per_pin) 1523 return -ENOMEM; 1524 1525 per_pin->pcm = NULL; 1526 per_pin->pcm_idx = -1; 1527 per_pin->prev_pcm_idx = -1; 1528 per_pin->pin_nid = pin_nid; 1529 per_pin->pin_nid_idx = spec->num_nids; 1530 per_pin->dev_id = i; 1531 per_pin->non_pcm = false; 1532 snd_hda_set_dev_select(codec, pin_nid, i); 1533 err = hdmi_read_pin_conn(codec, pin_idx); 1534 if (err < 0) 1535 return err; 1536 if (!is_jack_detectable(codec, pin_nid)) 1537 codec_warn(codec, "HDMI: pin NID 0x%x - jack not detectable\n", pin_nid); 1538 spec->num_pins++; 1539 } 1540 spec->num_nids++; 1541 1542 return 0; 1543 } 1544 1545 static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) 1546 { 1547 struct hdmi_spec *spec = codec->spec; 1548 struct hdmi_spec_per_cvt *per_cvt; 1549 unsigned int chans; 1550 int err; 1551 1552 chans = get_wcaps(codec, cvt_nid); 1553 chans = get_wcaps_channels(chans); 1554 1555 per_cvt = snd_array_new(&spec->cvts); 1556 if (!per_cvt) 1557 return -ENOMEM; 1558 1559 per_cvt->cvt_nid = cvt_nid; 1560 per_cvt->channels_min = 2; 1561 if (chans <= 16) { 1562 per_cvt->channels_max = chans; 1563 if (chans > spec->chmap.channels_max) 1564 spec->chmap.channels_max = chans; 1565 } 1566 1567 err = snd_hda_query_supported_pcm(codec, cvt_nid, 1568 &per_cvt->rates, 1569 &per_cvt->formats, 1570 NULL, 1571 &per_cvt->maxbps); 1572 if (err < 0) 1573 return err; 1574 1575 if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids)) 1576 spec->cvt_nids[spec->num_cvts] = cvt_nid; 1577 spec->num_cvts++; 1578 1579 return 0; 1580 } 1581 1582 static const struct snd_pci_quirk force_connect_list[] = { 1583 SND_PCI_QUIRK(0x103c, 0x83e2, "HP EliteDesk 800 G4", 1), 1584 SND_PCI_QUIRK(0x103c, 0x83ef, "HP MP9 G4 Retail System AMS", 1), 1585 SND_PCI_QUIRK(0x103c, 0x845a, "HP EliteDesk 800 G4 DM 65W", 1), 1586 SND_PCI_QUIRK(0x103c, 0x870f, "HP", 1), 1587 SND_PCI_QUIRK(0x103c, 0x871a, "HP", 1), 1588 SND_PCI_QUIRK(0x103c, 0x8711, "HP", 1), 1589 SND_PCI_QUIRK(0x103c, 0x8715, "HP", 1), 1590 SND_PCI_QUIRK(0x1043, 0x86ae, "ASUS", 1), /* Z170 PRO */ 1591 SND_PCI_QUIRK(0x1043, 0x86c7, "ASUS", 1), /* Z170M PLUS */ 1592 SND_PCI_QUIRK(0x1462, 0xec94, "MS-7C94", 1), 1593 SND_PCI_QUIRK(0x8086, 0x2060, "Intel NUC5CPYB", 1), 1594 SND_PCI_QUIRK(0x8086, 0x2081, "Intel NUC 10", 1), 1595 {} 1596 }; 1597 1598 int snd_hda_hdmi_parse_codec(struct hda_codec *codec) 1599 { 1600 struct hdmi_spec *spec = codec->spec; 1601 hda_nid_t start_nid; 1602 unsigned int caps; 1603 int i, nodes; 1604 const struct snd_pci_quirk *q; 1605 1606 nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid); 1607 if (!start_nid || nodes < 0) { 1608 codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); 1609 return -EINVAL; 1610 } 1611 1612 if (enable_all_pins) 1613 spec->force_connect = true; 1614 1615 q = snd_pci_quirk_lookup(codec->bus->pci, force_connect_list); 1616 1617 if (q && q->value) 1618 spec->force_connect = true; 1619 1620 /* 1621 * hdmi_add_pin() assumes total amount of converters to 1622 * be known, so first discover all converters 1623 */ 1624 for (i = 0; i < nodes; i++) { 1625 hda_nid_t nid = start_nid + i; 1626 1627 caps = get_wcaps(codec, nid); 1628 1629 if (!(caps & AC_WCAP_DIGITAL)) 1630 continue; 1631 1632 if (get_wcaps_type(caps) == AC_WID_AUD_OUT) 1633 hdmi_add_cvt(codec, nid); 1634 } 1635 1636 /* discover audio pins */ 1637 for (i = 0; i < nodes; i++) { 1638 hda_nid_t nid = start_nid + i; 1639 1640 caps = get_wcaps(codec, nid); 1641 1642 if (!(caps & AC_WCAP_DIGITAL)) 1643 continue; 1644 1645 if (get_wcaps_type(caps) == AC_WID_PIN) 1646 hdmi_add_pin(codec, nid); 1647 } 1648 1649 return 0; 1650 } 1651 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_parse_codec, "SND_HDA_CODEC_HDMI"); 1652 1653 /* 1654 */ 1655 static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) 1656 { 1657 struct hda_spdif_out *spdif; 1658 bool non_pcm; 1659 1660 mutex_lock(&codec->spdif_mutex); 1661 spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid); 1662 /* Add sanity check to pass klockwork check. 1663 * This should never happen. 1664 */ 1665 if (WARN_ON(spdif == NULL)) { 1666 mutex_unlock(&codec->spdif_mutex); 1667 return true; 1668 } 1669 non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO); 1670 mutex_unlock(&codec->spdif_mutex); 1671 return non_pcm; 1672 } 1673 1674 /* 1675 * HDMI callbacks 1676 */ 1677 1678 int snd_hda_hdmi_generic_pcm_prepare(struct hda_pcm_stream *hinfo, 1679 struct hda_codec *codec, 1680 unsigned int stream_tag, 1681 unsigned int format, 1682 struct snd_pcm_substream *substream) 1683 { 1684 hda_nid_t cvt_nid = hinfo->nid; 1685 struct hdmi_spec *spec = codec->spec; 1686 int pin_idx; 1687 struct hdmi_spec_per_pin *per_pin; 1688 struct snd_pcm_runtime *runtime = substream->runtime; 1689 bool non_pcm; 1690 int pinctl, stripe; 1691 int err = 0; 1692 1693 mutex_lock(&spec->pcm_lock); 1694 pin_idx = hinfo_to_pin_index(codec, hinfo); 1695 if (pin_idx < 0) { 1696 /* when pcm is not bound to a pin skip pin setup and return 0 1697 * to make audio playback be ongoing 1698 */ 1699 pin_cvt_fixup(codec, NULL, cvt_nid); 1700 snd_hda_codec_setup_stream(codec, cvt_nid, 1701 stream_tag, 0, format); 1702 goto unlock; 1703 } 1704 1705 per_pin = get_pin(spec, pin_idx); 1706 1707 /* Verify pin:cvt selections to avoid silent audio after S3. 1708 * After S3, the audio driver restores pin:cvt selections 1709 * but this can happen before gfx is ready and such selection 1710 * is overlooked by HW. Thus multiple pins can share a same 1711 * default convertor and mute control will affect each other, 1712 * which can cause a resumed audio playback become silent 1713 * after S3. 1714 */ 1715 pin_cvt_fixup(codec, per_pin, 0); 1716 1717 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */ 1718 /* Todo: add DP1.2 MST audio support later */ 1719 if (codec_has_acomp(codec)) 1720 snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid, 1721 per_pin->dev_id, runtime->rate); 1722 1723 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1724 mutex_lock(&per_pin->lock); 1725 per_pin->channels = substream->runtime->channels; 1726 per_pin->setup = true; 1727 1728 if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) { 1729 stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core, 1730 substream); 1731 snd_hda_codec_write(codec, cvt_nid, 0, 1732 AC_VERB_SET_STRIPE_CONTROL, 1733 stripe); 1734 } 1735 1736 snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); 1737 mutex_unlock(&per_pin->lock); 1738 if (spec->dyn_pin_out) { 1739 snd_hda_set_dev_select(codec, per_pin->pin_nid, 1740 per_pin->dev_id); 1741 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, 1742 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 1743 snd_hda_codec_write(codec, per_pin->pin_nid, 0, 1744 AC_VERB_SET_PIN_WIDGET_CONTROL, 1745 pinctl | PIN_OUT); 1746 } 1747 1748 /* snd_hda_set_dev_select() has been called before */ 1749 err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid, 1750 per_pin->dev_id, stream_tag, format); 1751 unlock: 1752 mutex_unlock(&spec->pcm_lock); 1753 return err; 1754 } 1755 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_pcm_prepare, "SND_HDA_CODEC_HDMI"); 1756 1757 int snd_hda_hdmi_generic_pcm_cleanup(struct hda_pcm_stream *hinfo, 1758 struct hda_codec *codec, 1759 struct snd_pcm_substream *substream) 1760 { 1761 snd_hda_codec_cleanup_stream(codec, hinfo->nid); 1762 return 0; 1763 } 1764 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_pcm_cleanup, "SND_HDA_CODEC_HDMI"); 1765 1766 static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, 1767 struct hda_codec *codec, 1768 struct snd_pcm_substream *substream) 1769 { 1770 struct hdmi_spec *spec = codec->spec; 1771 int cvt_idx, pin_idx, pcm_idx; 1772 struct hdmi_spec_per_cvt *per_cvt; 1773 struct hdmi_spec_per_pin *per_pin; 1774 int pinctl; 1775 int err = 0; 1776 1777 mutex_lock(&spec->pcm_lock); 1778 if (hinfo->nid) { 1779 pcm_idx = hinfo_to_pcm_index(codec, hinfo); 1780 if (snd_BUG_ON(pcm_idx < 0)) { 1781 err = -EINVAL; 1782 goto unlock; 1783 } 1784 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); 1785 if (snd_BUG_ON(cvt_idx < 0)) { 1786 err = -EINVAL; 1787 goto unlock; 1788 } 1789 per_cvt = get_cvt(spec, cvt_idx); 1790 per_cvt->assigned = false; 1791 hinfo->nid = 0; 1792 1793 azx_stream(get_azx_dev(substream))->stripe = 0; 1794 1795 snd_hda_spdif_ctls_unassign(codec, pcm_idx); 1796 clear_bit(pcm_idx, &spec->pcm_in_use); 1797 pin_idx = hinfo_to_pin_index(codec, hinfo); 1798 /* 1799 * In such a case, return 0 to match the behavior in 1800 * hdmi_pcm_open() 1801 */ 1802 if (pin_idx < 0) 1803 goto unlock; 1804 1805 per_pin = get_pin(spec, pin_idx); 1806 1807 if (spec->dyn_pin_out) { 1808 snd_hda_set_dev_select(codec, per_pin->pin_nid, 1809 per_pin->dev_id); 1810 pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, 1811 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 1812 snd_hda_codec_write(codec, per_pin->pin_nid, 0, 1813 AC_VERB_SET_PIN_WIDGET_CONTROL, 1814 pinctl & ~PIN_OUT); 1815 } 1816 1817 mutex_lock(&per_pin->lock); 1818 per_pin->chmap_set = false; 1819 memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); 1820 1821 per_pin->setup = false; 1822 per_pin->channels = 0; 1823 mutex_unlock(&per_pin->lock); 1824 } 1825 1826 unlock: 1827 mutex_unlock(&spec->pcm_lock); 1828 1829 return err; 1830 } 1831 1832 static const struct hda_pcm_ops generic_ops = { 1833 .open = hdmi_pcm_open, 1834 .close = hdmi_pcm_close, 1835 .prepare = snd_hda_hdmi_generic_pcm_prepare, 1836 .cleanup = snd_hda_hdmi_generic_pcm_cleanup, 1837 }; 1838 1839 static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx) 1840 { 1841 struct hda_codec *codec = hdac_to_hda_codec(hdac); 1842 struct hdmi_spec *spec = codec->spec; 1843 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 1844 1845 if (!per_pin) 1846 return 0; 1847 1848 return per_pin->sink_eld.info.spk_alloc; 1849 } 1850 1851 static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx, 1852 unsigned char *chmap) 1853 { 1854 struct hda_codec *codec = hdac_to_hda_codec(hdac); 1855 struct hdmi_spec *spec = codec->spec; 1856 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 1857 1858 /* chmap is already set to 0 in caller */ 1859 if (!per_pin) 1860 return; 1861 1862 memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap)); 1863 } 1864 1865 static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, 1866 unsigned char *chmap, int prepared) 1867 { 1868 struct hda_codec *codec = hdac_to_hda_codec(hdac); 1869 struct hdmi_spec *spec = codec->spec; 1870 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 1871 1872 if (!per_pin) 1873 return; 1874 mutex_lock(&per_pin->lock); 1875 per_pin->chmap_set = true; 1876 memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap)); 1877 if (prepared) 1878 snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); 1879 mutex_unlock(&per_pin->lock); 1880 } 1881 1882 static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) 1883 { 1884 struct hda_codec *codec = hdac_to_hda_codec(hdac); 1885 struct hdmi_spec *spec = codec->spec; 1886 struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 1887 1888 return per_pin ? true:false; 1889 } 1890 1891 int snd_hda_hdmi_generic_build_pcms(struct hda_codec *codec) 1892 { 1893 struct hdmi_spec *spec = codec->spec; 1894 int idx, pcm_num; 1895 1896 /* limit the PCM devices to the codec converters or available PINs */ 1897 pcm_num = min(spec->num_cvts, spec->num_pins); 1898 codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num); 1899 1900 for (idx = 0; idx < pcm_num; idx++) { 1901 struct hdmi_spec_per_cvt *per_cvt; 1902 struct hda_pcm *info; 1903 struct hda_pcm_stream *pstr; 1904 1905 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx); 1906 if (!info) 1907 return -ENOMEM; 1908 1909 spec->pcm_rec[idx].pcm = info; 1910 spec->pcm_used++; 1911 info->pcm_type = HDA_PCM_TYPE_HDMI; 1912 info->own_chmap = true; 1913 1914 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 1915 pstr->substreams = 1; 1916 pstr->ops = generic_ops; 1917 1918 per_cvt = get_cvt(spec, 0); 1919 pstr->channels_min = per_cvt->channels_min; 1920 pstr->channels_max = per_cvt->channels_max; 1921 1922 /* pcm number is less than pcm_rec array size */ 1923 if (spec->pcm_used >= ARRAY_SIZE(spec->pcm_rec)) 1924 break; 1925 /* other pstr fields are set in open */ 1926 } 1927 1928 return 0; 1929 } 1930 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_build_pcms, "SND_HDA_CODEC_HDMI"); 1931 1932 static void free_hdmi_jack_priv(struct snd_jack *jack) 1933 { 1934 struct hdmi_pcm *pcm = jack->private_data; 1935 1936 pcm->jack = NULL; 1937 } 1938 1939 static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx) 1940 { 1941 char hdmi_str[32] = "HDMI/DP"; 1942 struct hdmi_spec *spec = codec->spec; 1943 struct snd_jack *jack; 1944 int pcmdev = get_pcm_rec(spec, pcm_idx)->device; 1945 int err; 1946 1947 if (pcmdev > 0) 1948 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); 1949 1950 err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack, 1951 true, false); 1952 if (err < 0) 1953 return err; 1954 1955 spec->pcm_rec[pcm_idx].jack = jack; 1956 jack->private_data = &spec->pcm_rec[pcm_idx]; 1957 jack->private_free = free_hdmi_jack_priv; 1958 return 0; 1959 } 1960 1961 int snd_hda_hdmi_generic_build_controls(struct hda_codec *codec) 1962 { 1963 struct hdmi_spec *spec = codec->spec; 1964 int dev, err; 1965 int pin_idx, pcm_idx; 1966 1967 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 1968 if (!get_pcm_rec(spec, pcm_idx)->pcm) { 1969 /* no PCM: mark this for skipping permanently */ 1970 set_bit(pcm_idx, &spec->pcm_bitmap); 1971 continue; 1972 } 1973 1974 err = generic_hdmi_build_jack(codec, pcm_idx); 1975 if (err < 0) 1976 return err; 1977 1978 /* create the spdif for each pcm 1979 * pin will be bound when monitor is connected 1980 */ 1981 err = snd_hda_create_dig_out_ctls(codec, 1982 0, spec->cvt_nids[0], 1983 HDA_PCM_TYPE_HDMI); 1984 if (err < 0) 1985 return err; 1986 snd_hda_spdif_ctls_unassign(codec, pcm_idx); 1987 1988 dev = get_pcm_rec(spec, pcm_idx)->device; 1989 if (dev != SNDRV_PCM_INVALID_DEVICE) { 1990 /* add control for ELD Bytes */ 1991 err = hdmi_create_eld_ctl(codec, pcm_idx, dev); 1992 if (err < 0) 1993 return err; 1994 } 1995 } 1996 1997 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1998 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 1999 struct hdmi_eld *pin_eld = &per_pin->sink_eld; 2000 2001 if (spec->static_pcm_mapping) { 2002 hdmi_attach_hda_pcm(spec, per_pin); 2003 hdmi_pcm_setup_pin(spec, per_pin); 2004 } 2005 2006 pin_eld->eld_valid = false; 2007 hdmi_present_sense(per_pin, 0); 2008 } 2009 2010 /* add channel maps */ 2011 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 2012 struct hda_pcm *pcm; 2013 2014 pcm = get_pcm_rec(spec, pcm_idx); 2015 if (!pcm || !pcm->pcm) 2016 break; 2017 err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap); 2018 if (err < 0) 2019 return err; 2020 } 2021 2022 return 0; 2023 } 2024 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_build_controls, "SND_HDA_CODEC_HDMI"); 2025 2026 int snd_hda_hdmi_generic_init_per_pins(struct hda_codec *codec) 2027 { 2028 struct hdmi_spec *spec = codec->spec; 2029 int pin_idx; 2030 2031 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2032 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2033 2034 per_pin->codec = codec; 2035 mutex_init(&per_pin->lock); 2036 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); 2037 eld_proc_new(per_pin, pin_idx); 2038 } 2039 return 0; 2040 } 2041 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_init_per_pins, "SND_HDA_CODEC_HDMI"); 2042 2043 int snd_hda_hdmi_generic_init(struct hda_codec *codec) 2044 { 2045 struct hdmi_spec *spec = codec->spec; 2046 int pin_idx; 2047 2048 mutex_lock(&spec->bind_lock); 2049 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2050 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2051 hda_nid_t pin_nid = per_pin->pin_nid; 2052 int dev_id = per_pin->dev_id; 2053 2054 snd_hda_set_dev_select(codec, pin_nid, dev_id); 2055 hdmi_init_pin(codec, pin_nid); 2056 if (codec_has_acomp(codec)) 2057 continue; 2058 snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id, 2059 jack_callback); 2060 } 2061 mutex_unlock(&spec->bind_lock); 2062 return 0; 2063 } 2064 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_init, "SND_HDA_CODEC_HDMI"); 2065 2066 static void hdmi_array_init(struct hdmi_spec *spec, int nums) 2067 { 2068 snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); 2069 snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); 2070 } 2071 2072 static void hdmi_array_free(struct hdmi_spec *spec) 2073 { 2074 snd_array_free(&spec->pins); 2075 snd_array_free(&spec->cvts); 2076 } 2077 2078 void snd_hda_hdmi_generic_spec_free(struct hda_codec *codec) 2079 { 2080 struct hdmi_spec *spec = codec->spec; 2081 2082 if (spec) { 2083 hdmi_array_free(spec); 2084 kfree(spec); 2085 codec->spec = NULL; 2086 } 2087 codec->dp_mst = false; 2088 } 2089 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_spec_free, "SND_HDA_CODEC_HDMI"); 2090 2091 void snd_hda_hdmi_generic_remove(struct hda_codec *codec) 2092 { 2093 struct hdmi_spec *spec = codec->spec; 2094 int pin_idx, pcm_idx; 2095 2096 if (spec->acomp_registered) { 2097 snd_hdac_acomp_exit(&codec->bus->core); 2098 } else if (codec_has_acomp(codec)) { 2099 snd_hdac_acomp_register_notifier(&codec->bus->core, NULL); 2100 } 2101 codec->relaxed_resume = 0; 2102 2103 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2104 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2105 cancel_delayed_work_sync(&per_pin->work); 2106 eld_proc_free(per_pin); 2107 } 2108 2109 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 2110 if (spec->pcm_rec[pcm_idx].jack == NULL) 2111 continue; 2112 snd_device_free(codec->card, spec->pcm_rec[pcm_idx].jack); 2113 } 2114 2115 snd_hda_hdmi_generic_spec_free(codec); 2116 } 2117 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_remove, "SND_HDA_CODEC_HDMI"); 2118 2119 int snd_hda_hdmi_generic_suspend(struct hda_codec *codec) 2120 { 2121 struct hdmi_spec *spec = codec->spec; 2122 int pin_idx; 2123 2124 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2125 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2126 cancel_delayed_work_sync(&per_pin->work); 2127 } 2128 return 0; 2129 } 2130 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_suspend, "SND_HDA_CODEC_HDMI"); 2131 2132 int snd_hda_hdmi_generic_resume(struct hda_codec *codec) 2133 { 2134 struct hdmi_spec *spec = codec->spec; 2135 int pin_idx; 2136 2137 snd_hda_codec_init(codec); 2138 snd_hda_regmap_sync(codec); 2139 2140 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2141 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2142 hdmi_present_sense(per_pin, 1); 2143 } 2144 return 0; 2145 } 2146 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_resume, "SND_HDA_CODEC_HDMI"); 2147 2148 static const struct hdmi_ops generic_standard_hdmi_ops = { 2149 .pin_get_eld = hdmi_pin_get_eld, 2150 .pin_setup_infoframe = hdmi_pin_setup_infoframe, 2151 .pin_hbr_setup = hdmi_pin_hbr_setup, 2152 .setup_stream = snd_hda_hdmi_setup_stream, 2153 }; 2154 2155 /* allocate codec->spec and assign/initialize generic parser ops */ 2156 int snd_hda_hdmi_generic_alloc(struct hda_codec *codec) 2157 { 2158 struct hdmi_spec *spec; 2159 2160 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2161 if (!spec) 2162 return -ENOMEM; 2163 2164 spec->codec = codec; 2165 spec->ops = generic_standard_hdmi_ops; 2166 spec->dev_num = 1; /* initialize to 1 */ 2167 mutex_init(&spec->pcm_lock); 2168 mutex_init(&spec->bind_lock); 2169 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); 2170 2171 spec->chmap.ops.get_chmap = hdmi_get_chmap; 2172 spec->chmap.ops.set_chmap = hdmi_set_chmap; 2173 spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached; 2174 spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc; 2175 2176 codec->spec = spec; 2177 hdmi_array_init(spec, 4); 2178 2179 return 0; 2180 } 2181 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_alloc, "SND_HDA_CODEC_HDMI"); 2182 2183 /* generic HDMI parser */ 2184 int snd_hda_hdmi_generic_probe(struct hda_codec *codec) 2185 { 2186 int err; 2187 2188 err = snd_hda_hdmi_generic_alloc(codec); 2189 if (err < 0) 2190 return err; 2191 2192 err = snd_hda_hdmi_parse_codec(codec); 2193 if (err < 0) { 2194 snd_hda_hdmi_generic_spec_free(codec); 2195 return err; 2196 } 2197 2198 snd_hda_hdmi_generic_init_per_pins(codec); 2199 return 0; 2200 } 2201 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_probe, "SND_HDA_CODEC_HDMI"); 2202 2203 /* 2204 * generic audio component binding 2205 */ 2206 2207 /* turn on / off the unsol event jack detection dynamically */ 2208 static void reprogram_jack_detect(struct hda_codec *codec, hda_nid_t nid, 2209 int dev_id, bool use_acomp) 2210 { 2211 struct hda_jack_tbl *tbl; 2212 2213 tbl = snd_hda_jack_tbl_get_mst(codec, nid, dev_id); 2214 if (tbl) { 2215 /* clear unsol even if component notifier is used, or re-enable 2216 * if notifier is cleared 2217 */ 2218 unsigned int val = use_acomp ? 0 : (AC_USRSP_EN | tbl->tag); 2219 snd_hda_codec_write_cache(codec, nid, 0, 2220 AC_VERB_SET_UNSOLICITED_ENABLE, val); 2221 } 2222 } 2223 2224 /* set up / clear component notifier dynamically */ 2225 static void generic_acomp_notifier_set(struct drm_audio_component *acomp, 2226 bool use_acomp) 2227 { 2228 struct hdmi_spec *spec; 2229 int i; 2230 2231 spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops); 2232 mutex_lock(&spec->bind_lock); 2233 spec->use_acomp_notifier = use_acomp; 2234 spec->codec->relaxed_resume = use_acomp; 2235 spec->codec->bus->keep_power = 0; 2236 /* reprogram each jack detection logic depending on the notifier */ 2237 for (i = 0; i < spec->num_pins; i++) 2238 reprogram_jack_detect(spec->codec, 2239 get_pin(spec, i)->pin_nid, 2240 get_pin(spec, i)->dev_id, 2241 use_acomp); 2242 mutex_unlock(&spec->bind_lock); 2243 } 2244 2245 /* enable / disable the notifier via master bind / unbind */ 2246 int snd_hda_hdmi_acomp_master_bind(struct device *dev, 2247 struct drm_audio_component *acomp) 2248 { 2249 generic_acomp_notifier_set(acomp, true); 2250 return 0; 2251 } 2252 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_master_bind, "SND_HDA_CODEC_HDMI"); 2253 2254 void snd_hda_hdmi_acomp_master_unbind(struct device *dev, 2255 struct drm_audio_component *acomp) 2256 { 2257 generic_acomp_notifier_set(acomp, false); 2258 } 2259 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_master_unbind, "SND_HDA_CODEC_HDMI"); 2260 2261 /* check whether both HD-audio and DRM PCI devices belong to the same bus */ 2262 static int match_bound_vga(struct device *dev, int subtype, void *data) 2263 { 2264 struct hdac_bus *bus = data; 2265 struct pci_dev *pci, *master; 2266 2267 if (!dev_is_pci(dev) || !dev_is_pci(bus->dev)) 2268 return 0; 2269 master = to_pci_dev(bus->dev); 2270 pci = to_pci_dev(dev); 2271 return master->bus == pci->bus; 2272 } 2273 2274 /* audio component notifier for AMD/Nvidia HDMI codecs */ 2275 void snd_hda_hdmi_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) 2276 { 2277 struct hda_codec *codec = audio_ptr; 2278 struct hdmi_spec *spec = codec->spec; 2279 hda_nid_t pin_nid = spec->port2pin(codec, port); 2280 2281 if (!pin_nid) 2282 return; 2283 if (get_wcaps_type(get_wcaps(codec, pin_nid)) != AC_WID_PIN) 2284 return; 2285 /* skip notification during system suspend (but not in runtime PM); 2286 * the state will be updated at resume 2287 */ 2288 if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND) 2289 return; 2290 2291 snd_hda_hdmi_check_presence_and_report(codec, pin_nid, dev_id); 2292 } 2293 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_pin_eld_notify, "SND_HDA_CODEC_HDMI"); 2294 2295 /* set up the private drm_audio_ops from the template */ 2296 void snd_hda_hdmi_setup_drm_audio_ops(struct hda_codec *codec, 2297 const struct drm_audio_component_audio_ops *ops) 2298 { 2299 struct hdmi_spec *spec = codec->spec; 2300 2301 spec->drm_audio_ops.audio_ptr = codec; 2302 /* intel_audio_codec_enable() or intel_audio_codec_disable() 2303 * will call pin_eld_notify with using audio_ptr pointer 2304 * We need make sure audio_ptr is really setup 2305 */ 2306 wmb(); 2307 spec->drm_audio_ops.pin2port = ops->pin2port; 2308 spec->drm_audio_ops.pin_eld_notify = ops->pin_eld_notify; 2309 spec->drm_audio_ops.master_bind = ops->master_bind; 2310 spec->drm_audio_ops.master_unbind = ops->master_unbind; 2311 } 2312 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_setup_drm_audio_ops, "SND_HDA_CODEC_HDMI"); 2313 2314 /* initialize the generic HDMI audio component */ 2315 void snd_hda_hdmi_acomp_init(struct hda_codec *codec, 2316 const struct drm_audio_component_audio_ops *ops, 2317 int (*port2pin)(struct hda_codec *, int)) 2318 { 2319 struct hdmi_spec *spec = codec->spec; 2320 2321 if (!enable_acomp) { 2322 codec_info(codec, "audio component disabled by module option\n"); 2323 return; 2324 } 2325 2326 spec->port2pin = port2pin; 2327 snd_hda_hdmi_setup_drm_audio_ops(codec, ops); 2328 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops, 2329 match_bound_vga, 0)) { 2330 spec->acomp_registered = true; 2331 } 2332 } 2333 EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_init, "SND_HDA_CODEC_HDMI"); 2334 2335 /* 2336 */ 2337 2338 enum { 2339 MODEL_GENERIC, 2340 MODEL_GF, 2341 }; 2342 2343 static int generichdmi_probe(struct hda_codec *codec, 2344 const struct hda_device_id *id) 2345 { 2346 int err; 2347 2348 err = snd_hda_hdmi_generic_probe(codec); 2349 if (err < 0) 2350 return err; 2351 /* 2352 * Glenfly GPUs have two codecs, stream switches from one codec to 2353 * another, need to do actual clean-ups in codec_cleanup_stream 2354 */ 2355 if (id->driver_data == MODEL_GF) 2356 codec->no_sticky_stream = 1; 2357 2358 return 0; 2359 } 2360 2361 static const struct hda_codec_ops generichdmi_codec_ops = { 2362 .probe = generichdmi_probe, 2363 .remove = snd_hda_hdmi_generic_remove, 2364 .init = snd_hda_hdmi_generic_init, 2365 .build_pcms = snd_hda_hdmi_generic_build_pcms, 2366 .build_controls = snd_hda_hdmi_generic_build_controls, 2367 .unsol_event = snd_hda_hdmi_generic_unsol_event, 2368 .suspend = snd_hda_hdmi_generic_suspend, 2369 .resume = snd_hda_hdmi_generic_resume, 2370 }; 2371 2372 /* 2373 */ 2374 static const struct hda_device_id snd_hda_id_generichdmi[] = { 2375 HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI", MODEL_GENERIC), 2376 HDA_CODEC_ID_MODEL(0x10951390, "SiI1390 HDMI", MODEL_GENERIC), 2377 HDA_CODEC_ID_MODEL(0x10951392, "SiI1392 HDMI", MODEL_GENERIC), 2378 HDA_CODEC_ID_MODEL(0x11069f84, "VX11 HDMI/DP", MODEL_GENERIC), 2379 HDA_CODEC_ID_MODEL(0x11069f85, "VX11 HDMI/DP", MODEL_GENERIC), 2380 HDA_CODEC_ID_MODEL(0x17e80047, "Chrontel HDMI", MODEL_GENERIC), 2381 HDA_CODEC_ID_MODEL(0x1d179f86, "ZX-100S HDMI/DP", MODEL_GF), 2382 HDA_CODEC_ID_MODEL(0x1d179f87, "ZX-100S HDMI/DP", MODEL_GF), 2383 HDA_CODEC_ID_MODEL(0x1d179f88, "KX-5000 HDMI/DP", MODEL_GF), 2384 HDA_CODEC_ID_MODEL(0x1d179f89, "KX-5000 HDMI/DP", MODEL_GF), 2385 HDA_CODEC_ID_MODEL(0x1d179f8a, "KX-6000 HDMI/DP", MODEL_GF), 2386 HDA_CODEC_ID_MODEL(0x1d179f8b, "KX-6000 HDMI/DP", MODEL_GF), 2387 HDA_CODEC_ID_MODEL(0x1d179f8c, "KX-6000G HDMI/DP", MODEL_GF), 2388 HDA_CODEC_ID_MODEL(0x1d179f8d, "KX-6000G HDMI/DP", MODEL_GF), 2389 HDA_CODEC_ID_MODEL(0x1d179f8e, "KX-7000 HDMI/DP", MODEL_GF), 2390 HDA_CODEC_ID_MODEL(0x1d179f8f, "KX-7000 HDMI/DP", MODEL_GF), 2391 HDA_CODEC_ID_MODEL(0x1d179f90, "KX-7000 HDMI/DP", MODEL_GF), 2392 HDA_CODEC_ID_MODEL(0x67663d82, "Arise 82 HDMI/DP", MODEL_GF), 2393 HDA_CODEC_ID_MODEL(0x67663d83, "Arise 83 HDMI/DP", MODEL_GF), 2394 HDA_CODEC_ID_MODEL(0x67663d84, "Arise 84 HDMI/DP", MODEL_GF), 2395 HDA_CODEC_ID_MODEL(0x67663d85, "Arise 85 HDMI/DP", MODEL_GF), 2396 HDA_CODEC_ID_MODEL(0x67663d86, "Arise 86 HDMI/DP", MODEL_GF), 2397 HDA_CODEC_ID_MODEL(0x67663d87, "Arise 87 HDMI/DP", MODEL_GF), 2398 HDA_CODEC_ID_MODEL(0x80862801, "Bearlake HDMI", MODEL_GENERIC), 2399 HDA_CODEC_ID_MODEL(0x80862802, "Cantiga HDMI", MODEL_GENERIC), 2400 HDA_CODEC_ID_MODEL(0x80862803, "Eaglelake HDMI", MODEL_GENERIC), 2401 HDA_CODEC_ID_MODEL(0x80862880, "CedarTrail HDMI", MODEL_GENERIC), 2402 HDA_CODEC_ID_MODEL(0x808629fb, "Crestline HDMI", MODEL_GENERIC), 2403 /* special ID for generic HDMI */ 2404 HDA_CODEC_ID_MODEL(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", MODEL_GENERIC), 2405 {} /* terminator */ 2406 }; 2407 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_generichdmi); 2408 2409 MODULE_LICENSE("GPL"); 2410 MODULE_DESCRIPTION("Generic HDMI HD-audio codec"); 2411 2412 static struct hda_codec_driver generichdmi_driver = { 2413 .id = snd_hda_id_generichdmi, 2414 .ops = &generichdmi_codec_ops, 2415 }; 2416 2417 module_hda_codec_driver(generichdmi_driver); 2418