Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'topic/hda-mst' into for-next

+563 -73
+74
Documentation/sound/alsa/HD-Audio-DP-MST-audio.txt
··· 1 + To support DP MST audio, HD Audio hdmi codec driver introduces virtual pin 2 + and dynamic pcm assignment. 3 + 4 + Virtual pin is an extension of per_pin. The most difference of DP MST 5 + from legacy is that DP MST introduces device entry. Each pin can contain 6 + several device entries. Each device entry behaves as a pin. 7 + 8 + As each pin may contain several device entries and each codec may contain 9 + several pins, if we use one pcm per per_pin, there will be many PCMs. 10 + The new solution is to create a few PCMs and to dynamically bind pcm to 11 + per_pin. Driver uses spec->dyn_pcm_assign flag to indicate whether to use 12 + the new solution. 13 + 14 + PCM 15 + === 16 + To be added 17 + 18 + 19 + Jack 20 + ==== 21 + 22 + Presume: 23 + - MST must be dyn_pcm_assign, and it is acomp (for Intel scenario); 24 + - NON-MST may or may not be dyn_pcm_assign, it can be acomp or !acomp; 25 + 26 + So there are the following scenarios: 27 + a. MST (&& dyn_pcm_assign && acomp) 28 + b. NON-MST && dyn_pcm_assign && acomp 29 + c. NON-MST && !dyn_pcm_assign && !acomp 30 + 31 + Below discussion will ignore MST and NON-MST difference as it doesn't 32 + impact on jack handling too much. 33 + 34 + Driver uses struct hdmi_pcm pcm[] array in hdmi_spec and snd_jack is 35 + a member of hdmi_pcm. Each pin has one struct hdmi_pcm * pcm pointer. 36 + 37 + For !dyn_pcm_assign, per_pin->pcm will assigned to spec->pcm[n] statically. 38 + 39 + For dyn_pcm_assign, per_pin->pcm will assigned to spec->pcm[n] 40 + when monitor is hotplugged. 41 + 42 + 43 + Build Jack 44 + ---------- 45 + 46 + - dyn_pcm_assign 47 + Will not use hda_jack but use snd_jack in spec->pcm_rec[pcm_idx].jack directly. 48 + 49 + - !dyn_pcm_assign 50 + Use hda_jack and assign spec->pcm_rec[pcm_idx].jack = jack->jack statically. 51 + 52 + 53 + Unsolicited Event Enabling 54 + -------------------------- 55 + Enable unsolicited event if !acomp. 56 + 57 + 58 + Monitor Hotplug Event Handling 59 + ------------------------------ 60 + - acomp 61 + pin_eld_notify() -> check_presence_and_report() -> hdmi_present_sense() -> 62 + sync_eld_via_acomp(). 63 + Use directly snd_jack_report() on spec->pcm_rec[pcm_idx].jack for 64 + both dyn_pcm_assign and !dyn_pcm_assign 65 + 66 + - !acomp 67 + Hdmi_unsol_event() -> hdmi_intrinsic_event() -> check_presence_and_report() -> 68 + hdmi_present_sense() -> hdmi_prepsent_sense_via_verbs() 69 + Use directly snd_jack_report() on spec->pcm_rec[pcm_idx].jack for dyn_pcm_assign. 70 + Use hda_jack mechanism to handle jack events. 71 + 72 + 73 + Others to be added later 74 + ========================
+489 -73
sound/pci/hda/patch_hdmi.c
··· 75 75 76 76 struct hdmi_spec_per_pin { 77 77 hda_nid_t pin_nid; 78 + /* pin idx, different device entries on the same pin use the same idx */ 79 + int pin_nid_idx; 78 80 int num_mux_nids; 79 81 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; 80 82 int mux_idx; ··· 87 85 struct mutex lock; 88 86 struct delayed_work work; 89 87 struct snd_kcontrol *eld_ctl; 90 - struct snd_jack *acomp_jack; /* jack via audio component */ 88 + struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/ 89 + int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */ 91 90 int repoll_count; 92 91 bool setup; /* the stream has been set up by prepare callback */ 93 92 int channels; /* current number of channels */ ··· 133 130 int (*chmap_validate)(int ca, int channels, unsigned char *chmap); 134 131 }; 135 132 133 + struct hdmi_pcm { 134 + struct hda_pcm *pcm; 135 + struct snd_jack *jack; 136 + }; 137 + 136 138 struct hdmi_spec { 137 139 int num_cvts; 138 140 struct snd_array cvts; /* struct hdmi_spec_per_cvt */ ··· 145 137 146 138 int num_pins; 147 139 struct snd_array pins; /* struct hdmi_spec_per_pin */ 148 - struct hda_pcm *pcm_rec[16]; 140 + struct hdmi_pcm pcm_rec[16]; 141 + struct mutex pcm_lock; 142 + /* pcm_bitmap means which pcms have been assigned to pins*/ 143 + unsigned long pcm_bitmap; 144 + int pcm_used; /* counter of pcm_rec[] */ 145 + /* bitmap shows whether the pcm is opened in user space 146 + * bit 0 means the first playback PCM (PCM3); 147 + * bit 1 means the second playback PCM, and so on. 148 + */ 149 + unsigned long pcm_in_use; 149 150 unsigned int channels_max; /* max over all cvts */ 150 151 151 152 struct hdmi_eld temp_eld; 152 153 struct hdmi_ops ops; 153 154 154 155 bool dyn_pin_out; 155 - 156 + bool dyn_pcm_assign; 156 157 /* 157 158 * Non-generic VIA/NVIDIA specific 158 159 */ ··· 387 370 ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) 388 371 #define get_cvt(spec, idx) \ 389 372 ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) 390 - #define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx]) 373 + /* obtain hdmi_pcm object assigned to idx */ 374 + #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx]) 375 + /* obtain hda_pcm object assigned to idx */ 376 + #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm) 391 377 392 378 static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) 393 379 { ··· 405 385 return -EINVAL; 406 386 } 407 387 388 + static int hinfo_to_pcm_index(struct hda_codec *codec, 389 + struct hda_pcm_stream *hinfo) 390 + { 391 + struct hdmi_spec *spec = codec->spec; 392 + int pcm_idx; 393 + 394 + for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) 395 + if (get_pcm_rec(spec, pcm_idx)->stream == hinfo) 396 + return pcm_idx; 397 + 398 + codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo); 399 + return -EINVAL; 400 + } 401 + 408 402 static int hinfo_to_pin_index(struct hda_codec *codec, 409 403 struct hda_pcm_stream *hinfo) 410 404 { 411 405 struct hdmi_spec *spec = codec->spec; 406 + struct hdmi_spec_per_pin *per_pin; 412 407 int pin_idx; 413 408 414 - for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 415 - if (get_pcm_rec(spec, pin_idx)->stream == hinfo) 409 + for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 410 + per_pin = get_pin(spec, pin_idx); 411 + if (per_pin->pcm && 412 + per_pin->pcm->pcm->stream == hinfo) 416 413 return pin_idx; 414 + } 417 415 418 - codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo); 416 + codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo); 419 417 return -EINVAL; 418 + } 419 + 420 + static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec, 421 + int pcm_idx) 422 + { 423 + int i; 424 + struct hdmi_spec_per_pin *per_pin; 425 + 426 + for (i = 0; i < spec->num_pins; i++) { 427 + per_pin = get_pin(spec, i); 428 + if (per_pin->pcm_idx == pcm_idx) 429 + return per_pin; 430 + } 431 + return NULL; 420 432 } 421 433 422 434 static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid) ··· 1390 1338 return 0; 1391 1339 } 1392 1340 1341 + /* Try to find an available converter 1342 + * If pin_idx is less then zero, just try to find an available converter. 1343 + * Otherwise, try to find an available converter and get the cvt mux index 1344 + * of the pin. 1345 + */ 1393 1346 static int hdmi_choose_cvt(struct hda_codec *codec, 1394 1347 int pin_idx, int *cvt_id, int *mux_id) 1395 1348 { ··· 1403 1346 struct hdmi_spec_per_cvt *per_cvt = NULL; 1404 1347 int cvt_idx, mux_idx = 0; 1405 1348 1406 - per_pin = get_pin(spec, pin_idx); 1349 + /* pin_idx < 0 means no pin will be bound to the converter */ 1350 + if (pin_idx < 0) 1351 + per_pin = NULL; 1352 + else 1353 + per_pin = get_pin(spec, pin_idx); 1407 1354 1408 1355 /* Dynamically assign converter to stream */ 1409 1356 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { ··· 1416 1355 /* Must not already be assigned */ 1417 1356 if (per_cvt->assigned) 1418 1357 continue; 1358 + if (per_pin == NULL) 1359 + break; 1419 1360 /* Must be in pin's mux's list of converters */ 1420 1361 for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) 1421 1362 if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid) ··· 1430 1367 1431 1368 /* No free converters */ 1432 1369 if (cvt_idx == spec->num_cvts) 1433 - return -ENODEV; 1370 + return -EBUSY; 1434 1371 1435 - per_pin->mux_idx = mux_idx; 1372 + if (per_pin != NULL) 1373 + per_pin->mux_idx = mux_idx; 1436 1374 1437 1375 if (cvt_id) 1438 1376 *cvt_id = cvt_idx; ··· 1457 1393 snd_hda_codec_write_cache(codec, pin_nid, 0, 1458 1394 AC_VERB_SET_CONNECT_SEL, 1459 1395 mux_idx); 1396 + } 1397 + 1398 + /* get the mux index for the converter of the pins 1399 + * converter's mux index is the same for all pins on Intel platform 1400 + */ 1401 + static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec, 1402 + hda_nid_t cvt_nid) 1403 + { 1404 + int i; 1405 + 1406 + for (i = 0; i < spec->num_cvts; i++) 1407 + if (spec->cvt_nids[i] == cvt_nid) 1408 + return i; 1409 + return -EINVAL; 1460 1410 } 1461 1411 1462 1412 /* Intel HDMI workaround to fix audio routing issue: ··· 1524 1446 } 1525 1447 } 1526 1448 1449 + /* A wrapper of intel_not_share_asigned_cvt() */ 1450 + static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec, 1451 + hda_nid_t pin_nid, hda_nid_t cvt_nid) 1452 + { 1453 + int mux_idx; 1454 + struct hdmi_spec *spec = codec->spec; 1455 + 1456 + if (!is_haswell_plus(codec) && !is_valleyview_plus(codec)) 1457 + return; 1458 + 1459 + /* On Intel platform, the mapping of converter nid to 1460 + * mux index of the pins are always the same. 1461 + * The pin nid may be 0, this means all pins will not 1462 + * share the converter. 1463 + */ 1464 + mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid); 1465 + if (mux_idx >= 0) 1466 + intel_not_share_assigned_cvt(codec, pin_nid, mux_idx); 1467 + } 1468 + 1469 + /* called in hdmi_pcm_open when no pin is assigned to the PCM 1470 + * in dyn_pcm_assign mode. 1471 + */ 1472 + static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo, 1473 + struct hda_codec *codec, 1474 + struct snd_pcm_substream *substream) 1475 + { 1476 + struct hdmi_spec *spec = codec->spec; 1477 + struct snd_pcm_runtime *runtime = substream->runtime; 1478 + int cvt_idx, pcm_idx; 1479 + struct hdmi_spec_per_cvt *per_cvt = NULL; 1480 + int err; 1481 + 1482 + pcm_idx = hinfo_to_pcm_index(codec, hinfo); 1483 + if (pcm_idx < 0) 1484 + return -EINVAL; 1485 + 1486 + err = hdmi_choose_cvt(codec, -1, &cvt_idx, NULL); 1487 + if (err) 1488 + return err; 1489 + 1490 + per_cvt = get_cvt(spec, cvt_idx); 1491 + per_cvt->assigned = 1; 1492 + hinfo->nid = per_cvt->cvt_nid; 1493 + 1494 + intel_not_share_assigned_cvt_nid(codec, 0, per_cvt->cvt_nid); 1495 + 1496 + set_bit(pcm_idx, &spec->pcm_in_use); 1497 + /* todo: setup spdif ctls assign */ 1498 + 1499 + /* Initially set the converter's capabilities */ 1500 + hinfo->channels_min = per_cvt->channels_min; 1501 + hinfo->channels_max = per_cvt->channels_max; 1502 + hinfo->rates = per_cvt->rates; 1503 + hinfo->formats = per_cvt->formats; 1504 + hinfo->maxbps = per_cvt->maxbps; 1505 + 1506 + /* Store the updated parameters */ 1507 + runtime->hw.channels_min = hinfo->channels_min; 1508 + runtime->hw.channels_max = hinfo->channels_max; 1509 + runtime->hw.formats = hinfo->formats; 1510 + runtime->hw.rates = hinfo->rates; 1511 + 1512 + snd_pcm_hw_constraint_step(substream->runtime, 0, 1513 + SNDRV_PCM_HW_PARAM_CHANNELS, 2); 1514 + return 0; 1515 + } 1516 + 1527 1517 /* 1528 1518 * HDA PCM callbacks 1529 1519 */ ··· 1601 1455 { 1602 1456 struct hdmi_spec *spec = codec->spec; 1603 1457 struct snd_pcm_runtime *runtime = substream->runtime; 1604 - int pin_idx, cvt_idx, mux_idx = 0; 1458 + int pin_idx, cvt_idx, pcm_idx, mux_idx = 0; 1605 1459 struct hdmi_spec_per_pin *per_pin; 1606 1460 struct hdmi_eld *eld; 1607 1461 struct hdmi_spec_per_cvt *per_cvt = NULL; 1608 1462 int err; 1609 1463 1610 1464 /* Validate hinfo */ 1611 - pin_idx = hinfo_to_pin_index(codec, hinfo); 1612 - if (snd_BUG_ON(pin_idx < 0)) 1465 + pcm_idx = hinfo_to_pcm_index(codec, hinfo); 1466 + if (pcm_idx < 0) 1613 1467 return -EINVAL; 1614 - per_pin = get_pin(spec, pin_idx); 1615 - eld = &per_pin->sink_eld; 1468 + 1469 + mutex_lock(&spec->pcm_lock); 1470 + pin_idx = hinfo_to_pin_index(codec, hinfo); 1471 + if (!spec->dyn_pcm_assign) { 1472 + if (snd_BUG_ON(pin_idx < 0)) { 1473 + mutex_unlock(&spec->pcm_lock); 1474 + return -EINVAL; 1475 + } 1476 + } else { 1477 + /* no pin is assigned to the PCM 1478 + * PA need pcm open successfully when probe 1479 + */ 1480 + if (pin_idx < 0) { 1481 + err = hdmi_pcm_open_no_pin(hinfo, codec, substream); 1482 + mutex_unlock(&spec->pcm_lock); 1483 + return err; 1484 + } 1485 + } 1616 1486 1617 1487 err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx); 1618 - if (err < 0) 1488 + if (err < 0) { 1489 + mutex_unlock(&spec->pcm_lock); 1619 1490 return err; 1491 + } 1620 1492 1621 1493 per_cvt = get_cvt(spec, cvt_idx); 1622 1494 /* Claim converter */ 1623 1495 per_cvt->assigned = 1; 1496 + 1497 + set_bit(pcm_idx, &spec->pcm_in_use); 1498 + per_pin = get_pin(spec, pin_idx); 1624 1499 per_pin->cvt_nid = per_cvt->cvt_nid; 1625 1500 hinfo->nid = per_cvt->cvt_nid; 1626 1501 ··· 1653 1486 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) 1654 1487 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx); 1655 1488 1656 - snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid); 1489 + snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid); 1657 1490 1658 1491 /* Initially set the converter's capabilities */ 1659 1492 hinfo->channels_min = per_cvt->channels_min; ··· 1662 1495 hinfo->formats = per_cvt->formats; 1663 1496 hinfo->maxbps = per_cvt->maxbps; 1664 1497 1498 + eld = &per_pin->sink_eld; 1665 1499 /* Restrict capabilities by ELD if this isn't disabled */ 1666 1500 if (!static_hdmi_pcm && eld->eld_valid) { 1667 1501 snd_hdmi_eld_update_pcm_info(&eld->info, hinfo); ··· 1670 1502 !hinfo->rates || !hinfo->formats) { 1671 1503 per_cvt->assigned = 0; 1672 1504 hinfo->nid = 0; 1673 - snd_hda_spdif_ctls_unassign(codec, pin_idx); 1505 + snd_hda_spdif_ctls_unassign(codec, pcm_idx); 1506 + mutex_unlock(&spec->pcm_lock); 1674 1507 return -ENODEV; 1675 1508 } 1676 1509 } 1677 1510 1511 + mutex_unlock(&spec->pcm_lock); 1678 1512 /* Store the updated parameters */ 1679 1513 runtime->hw.channels_min = hinfo->channels_min; 1680 1514 runtime->hw.channels_max = hinfo->channels_max; ··· 1711 1541 return 0; 1712 1542 } 1713 1543 1544 + static int hdmi_find_pcm_slot(struct hdmi_spec *spec, 1545 + struct hdmi_spec_per_pin *per_pin) 1546 + { 1547 + int i; 1548 + 1549 + /* try the prefer PCM */ 1550 + if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap)) 1551 + return per_pin->pin_nid_idx; 1552 + 1553 + /* have a second try; check the "reserved area" over num_pins */ 1554 + for (i = spec->num_pins; i < spec->pcm_used; i++) { 1555 + if (!test_bit(i, &spec->pcm_bitmap)) 1556 + return i; 1557 + } 1558 + 1559 + /* the last try; check the empty slots in pins */ 1560 + for (i = 0; i < spec->num_pins; i++) { 1561 + if (!test_bit(i, &spec->pcm_bitmap)) 1562 + return i; 1563 + } 1564 + return -EBUSY; 1565 + } 1566 + 1567 + static void hdmi_attach_hda_pcm(struct hdmi_spec *spec, 1568 + struct hdmi_spec_per_pin *per_pin) 1569 + { 1570 + int idx; 1571 + 1572 + /* pcm already be attached to the pin */ 1573 + if (per_pin->pcm) 1574 + return; 1575 + idx = hdmi_find_pcm_slot(spec, per_pin); 1576 + if (idx == -ENODEV) 1577 + return; 1578 + per_pin->pcm_idx = idx; 1579 + per_pin->pcm = get_hdmi_pcm(spec, idx); 1580 + set_bit(idx, &spec->pcm_bitmap); 1581 + } 1582 + 1583 + static void hdmi_detach_hda_pcm(struct hdmi_spec *spec, 1584 + struct hdmi_spec_per_pin *per_pin) 1585 + { 1586 + int idx; 1587 + 1588 + /* pcm already be detached from the pin */ 1589 + if (!per_pin->pcm) 1590 + return; 1591 + idx = per_pin->pcm_idx; 1592 + per_pin->pcm_idx = -1; 1593 + per_pin->pcm = NULL; 1594 + if (idx >= 0 && idx < spec->pcm_used) 1595 + clear_bit(idx, &spec->pcm_bitmap); 1596 + } 1597 + 1598 + static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec, 1599 + struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid) 1600 + { 1601 + int mux_idx; 1602 + 1603 + for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) 1604 + if (per_pin->mux_nids[mux_idx] == cvt_nid) 1605 + break; 1606 + return mux_idx; 1607 + } 1608 + 1609 + static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid); 1610 + 1611 + static void hdmi_pcm_setup_pin(struct hdmi_spec *spec, 1612 + struct hdmi_spec_per_pin *per_pin) 1613 + { 1614 + struct hda_codec *codec = per_pin->codec; 1615 + struct hda_pcm *pcm; 1616 + struct hda_pcm_stream *hinfo; 1617 + struct snd_pcm_substream *substream; 1618 + int mux_idx; 1619 + bool non_pcm; 1620 + 1621 + if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used) 1622 + pcm = get_pcm_rec(spec, per_pin->pcm_idx); 1623 + else 1624 + return; 1625 + if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use)) 1626 + return; 1627 + 1628 + /* hdmi audio only uses playback and one substream */ 1629 + hinfo = pcm->stream; 1630 + substream = pcm->pcm->streams[0].substream; 1631 + 1632 + per_pin->cvt_nid = hinfo->nid; 1633 + 1634 + mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid); 1635 + if (mux_idx < per_pin->num_mux_nids) 1636 + snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1637 + AC_VERB_SET_CONNECT_SEL, 1638 + mux_idx); 1639 + snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid); 1640 + 1641 + non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid); 1642 + if (substream->runtime) 1643 + per_pin->channels = substream->runtime->channels; 1644 + per_pin->setup = true; 1645 + per_pin->mux_idx = mux_idx; 1646 + 1647 + hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); 1648 + } 1649 + 1650 + static void hdmi_pcm_reset_pin(struct hdmi_spec *spec, 1651 + struct hdmi_spec_per_pin *per_pin) 1652 + { 1653 + if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used) 1654 + snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx); 1655 + 1656 + per_pin->chmap_set = false; 1657 + memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); 1658 + 1659 + per_pin->setup = false; 1660 + per_pin->channels = 0; 1661 + } 1662 + 1714 1663 /* update per_pin ELD from the given new ELD; 1715 1664 * setup info frame and notification accordingly 1716 1665 */ ··· 1838 1549 struct hdmi_eld *eld) 1839 1550 { 1840 1551 struct hdmi_eld *pin_eld = &per_pin->sink_eld; 1552 + struct hdmi_spec *spec = codec->spec; 1841 1553 bool old_eld_valid = pin_eld->eld_valid; 1842 1554 bool eld_changed; 1555 + 1556 + if (spec->dyn_pcm_assign) { 1557 + if (eld->eld_valid) { 1558 + hdmi_attach_hda_pcm(spec, per_pin); 1559 + hdmi_pcm_setup_pin(spec, per_pin); 1560 + } else { 1561 + hdmi_pcm_reset_pin(spec, per_pin); 1562 + hdmi_detach_hda_pcm(spec, per_pin); 1563 + } 1564 + } 1843 1565 1844 1566 if (eld->eld_valid) 1845 1567 snd_hdmi_show_eld(codec, &eld->info); ··· 1962 1662 { 1963 1663 struct hdmi_spec *spec = codec->spec; 1964 1664 struct hdmi_eld *eld = &spec->temp_eld; 1665 + struct snd_jack *jack = NULL; 1965 1666 int size; 1966 1667 1967 1668 mutex_lock(&per_pin->lock); ··· 1986 1685 eld->eld_size = 0; 1987 1686 } 1988 1687 1688 + /* pcm_idx >=0 before update_eld() means it is in monitor 1689 + * disconnected event. Jack must be fetched before update_eld() 1690 + */ 1691 + if (per_pin->pcm_idx >= 0) 1692 + jack = spec->pcm_rec[per_pin->pcm_idx].jack; 1989 1693 update_eld(codec, per_pin, eld); 1990 - snd_jack_report(per_pin->acomp_jack, 1694 + if (jack == NULL && per_pin->pcm_idx >= 0) 1695 + jack = spec->pcm_rec[per_pin->pcm_idx].jack; 1696 + if (jack == NULL) 1697 + goto unlock; 1698 + snd_jack_report(jack, 1991 1699 eld->monitor_present ? SND_JACK_AVOUT : 0); 1992 1700 unlock: 1993 1701 mutex_unlock(&per_pin->lock); ··· 2005 1695 static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) 2006 1696 { 2007 1697 struct hda_codec *codec = per_pin->codec; 1698 + struct hdmi_spec *spec = codec->spec; 1699 + int ret; 2008 1700 1701 + mutex_lock(&spec->pcm_lock); 2009 1702 if (codec_has_acomp(codec)) { 2010 1703 sync_eld_via_acomp(codec, per_pin); 2011 - return false; /* don't call snd_hda_jack_report_sync() */ 1704 + ret = false; /* don't call snd_hda_jack_report_sync() */ 2012 1705 } else { 2013 - return hdmi_present_sense_via_verbs(per_pin, repoll); 1706 + ret = hdmi_present_sense_via_verbs(per_pin, repoll); 2014 1707 } 1708 + mutex_unlock(&spec->pcm_lock); 1709 + 1710 + return ret; 2015 1711 } 2016 1712 2017 1713 static void hdmi_repoll_eld(struct work_struct *work) ··· 2061 1745 2062 1746 per_pin->pin_nid = pin_nid; 2063 1747 per_pin->non_pcm = false; 1748 + if (spec->dyn_pcm_assign) 1749 + per_pin->pcm_idx = -1; 1750 + else { 1751 + per_pin->pcm = get_hdmi_pcm(spec, pin_idx); 1752 + per_pin->pcm_idx = pin_idx; 1753 + } 1754 + per_pin->pin_nid_idx = pin_idx; 2064 1755 2065 1756 err = hdmi_read_pin_conn(codec, pin_idx); 2066 1757 if (err < 0) ··· 2174 1851 { 2175 1852 hda_nid_t cvt_nid = hinfo->nid; 2176 1853 struct hdmi_spec *spec = codec->spec; 2177 - int pin_idx = hinfo_to_pin_index(codec, hinfo); 2178 - struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2179 - hda_nid_t pin_nid = per_pin->pin_nid; 1854 + int pin_idx; 1855 + struct hdmi_spec_per_pin *per_pin; 1856 + hda_nid_t pin_nid; 2180 1857 struct snd_pcm_runtime *runtime = substream->runtime; 2181 1858 bool non_pcm; 2182 1859 int pinctl; 1860 + int err; 2183 1861 1862 + mutex_lock(&spec->pcm_lock); 1863 + pin_idx = hinfo_to_pin_index(codec, hinfo); 1864 + if (spec->dyn_pcm_assign && pin_idx < 0) { 1865 + /* when dyn_pcm_assign and pcm is not bound to a pin 1866 + * skip pin setup and return 0 to make audio playback 1867 + * be ongoing 1868 + */ 1869 + intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid); 1870 + snd_hda_codec_setup_stream(codec, cvt_nid, 1871 + stream_tag, 0, format); 1872 + mutex_unlock(&spec->pcm_lock); 1873 + return 0; 1874 + } 1875 + 1876 + if (snd_BUG_ON(pin_idx < 0)) { 1877 + mutex_unlock(&spec->pcm_lock); 1878 + return -EINVAL; 1879 + } 1880 + per_pin = get_pin(spec, pin_idx); 1881 + pin_nid = per_pin->pin_nid; 2184 1882 if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { 2185 1883 /* Verify pin:cvt selections to avoid silent audio after S3. 2186 1884 * After S3, the audio driver restores pin:cvt selections ··· 2226 1882 2227 1883 hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); 2228 1884 mutex_unlock(&per_pin->lock); 2229 - 2230 1885 if (spec->dyn_pin_out) { 2231 1886 pinctl = snd_hda_codec_read(codec, pin_nid, 0, 2232 1887 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); ··· 2234 1891 pinctl | PIN_OUT); 2235 1892 } 2236 1893 2237 - return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); 1894 + err = spec->ops.setup_stream(codec, cvt_nid, pin_nid, 1895 + stream_tag, format); 1896 + mutex_unlock(&spec->pcm_lock); 1897 + return err; 2238 1898 } 2239 1899 2240 1900 static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, ··· 2253 1907 struct snd_pcm_substream *substream) 2254 1908 { 2255 1909 struct hdmi_spec *spec = codec->spec; 2256 - int cvt_idx, pin_idx; 1910 + int cvt_idx, pin_idx, pcm_idx; 2257 1911 struct hdmi_spec_per_cvt *per_cvt; 2258 1912 struct hdmi_spec_per_pin *per_pin; 2259 1913 int pinctl; 2260 1914 2261 1915 if (hinfo->nid) { 1916 + pcm_idx = hinfo_to_pcm_index(codec, hinfo); 1917 + if (snd_BUG_ON(pcm_idx < 0)) 1918 + return -EINVAL; 2262 1919 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); 2263 1920 if (snd_BUG_ON(cvt_idx < 0)) 2264 1921 return -EINVAL; ··· 2271 1922 per_cvt->assigned = 0; 2272 1923 hinfo->nid = 0; 2273 1924 1925 + mutex_lock(&spec->pcm_lock); 1926 + snd_hda_spdif_ctls_unassign(codec, pcm_idx); 1927 + clear_bit(pcm_idx, &spec->pcm_in_use); 2274 1928 pin_idx = hinfo_to_pin_index(codec, hinfo); 2275 - if (snd_BUG_ON(pin_idx < 0)) 1929 + if (spec->dyn_pcm_assign && pin_idx < 0) { 1930 + mutex_unlock(&spec->pcm_lock); 1931 + return 0; 1932 + } 1933 + 1934 + if (snd_BUG_ON(pin_idx < 0)) { 1935 + mutex_unlock(&spec->pcm_lock); 2276 1936 return -EINVAL; 1937 + } 2277 1938 per_pin = get_pin(spec, pin_idx); 2278 1939 2279 1940 if (spec->dyn_pin_out) { ··· 2294 1935 pinctl & ~PIN_OUT); 2295 1936 } 2296 1937 2297 - snd_hda_spdif_ctls_unassign(codec, pin_idx); 2298 - 2299 1938 mutex_lock(&per_pin->lock); 2300 1939 per_pin->chmap_set = false; 2301 1940 memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); ··· 2301 1944 per_pin->setup = false; 2302 1945 per_pin->channels = 0; 2303 1946 mutex_unlock(&per_pin->lock); 1947 + mutex_unlock(&spec->pcm_lock); 2304 1948 } 2305 1949 2306 1950 return 0; ··· 2413 2055 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); 2414 2056 struct hda_codec *codec = info->private_data; 2415 2057 struct hdmi_spec *spec = codec->spec; 2416 - int pin_idx = kcontrol->private_value; 2417 - struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2058 + int pcm_idx = kcontrol->private_value; 2059 + struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 2418 2060 int i; 2061 + 2062 + if (!per_pin) { 2063 + for (i = 0; i < spec->channels_max; i++) 2064 + ucontrol->value.integer.value[i] = 0; 2065 + return 0; 2066 + } 2419 2067 2420 2068 for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++) 2421 2069 ucontrol->value.integer.value[i] = per_pin->chmap[i]; ··· 2434 2070 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); 2435 2071 struct hda_codec *codec = info->private_data; 2436 2072 struct hdmi_spec *spec = codec->spec; 2437 - int pin_idx = kcontrol->private_value; 2438 - struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2073 + int pcm_idx = kcontrol->private_value; 2074 + struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx); 2439 2075 unsigned int ctl_idx; 2440 2076 struct snd_pcm_substream *substream; 2441 2077 unsigned char chmap[8]; 2442 2078 int i, err, ca, prepared = 0; 2079 + 2080 + /* No monitor is connected in dyn_pcm_assign. 2081 + * It's invalid to setup the chmap 2082 + */ 2083 + if (!per_pin) 2084 + return 0; 2443 2085 2444 2086 ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 2445 2087 substream = snd_pcm_chmap_substream(info, ctl_idx); ··· 2496 2126 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); 2497 2127 if (!info) 2498 2128 return -ENOMEM; 2499 - spec->pcm_rec[pin_idx] = info; 2129 + 2130 + spec->pcm_rec[pin_idx].pcm = info; 2131 + spec->pcm_used++; 2500 2132 info->pcm_type = HDA_PCM_TYPE_HDMI; 2501 2133 info->own_chmap = true; 2502 2134 ··· 2511 2139 return 0; 2512 2140 } 2513 2141 2514 - static void free_acomp_jack_priv(struct snd_jack *jack) 2142 + static void free_hdmi_jack_priv(struct snd_jack *jack) 2515 2143 { 2516 - struct hdmi_spec_per_pin *per_pin = jack->private_data; 2144 + struct hdmi_pcm *pcm = jack->private_data; 2517 2145 2518 - per_pin->acomp_jack = NULL; 2146 + pcm->jack = NULL; 2519 2147 } 2520 2148 2521 - static int add_acomp_jack_kctl(struct hda_codec *codec, 2522 - struct hdmi_spec_per_pin *per_pin, 2149 + static int add_hdmi_jack_kctl(struct hda_codec *codec, 2150 + struct hdmi_spec *spec, 2151 + int pcm_idx, 2523 2152 const char *name) 2524 2153 { 2525 2154 struct snd_jack *jack; ··· 2530 2157 true, false); 2531 2158 if (err < 0) 2532 2159 return err; 2533 - per_pin->acomp_jack = jack; 2534 - jack->private_data = per_pin; 2535 - jack->private_free = free_acomp_jack_priv; 2160 + 2161 + spec->pcm_rec[pcm_idx].jack = jack; 2162 + jack->private_data = &spec->pcm_rec[pcm_idx]; 2163 + jack->private_free = free_hdmi_jack_priv; 2536 2164 return 0; 2537 2165 } 2538 2166 2539 - static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx) 2167 + static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx) 2540 2168 { 2541 2169 char hdmi_str[32] = "HDMI/DP"; 2542 2170 struct hdmi_spec *spec = codec->spec; 2543 - struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2544 - int pcmdev = get_pcm_rec(spec, pin_idx)->device; 2171 + struct hdmi_spec_per_pin *per_pin; 2172 + struct hda_jack_tbl *jack; 2173 + int pcmdev = get_pcm_rec(spec, pcm_idx)->device; 2545 2174 bool phantom_jack; 2175 + int ret; 2546 2176 2547 2177 if (pcmdev > 0) 2548 2178 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); 2549 - if (codec_has_acomp(codec)) 2550 - return add_acomp_jack_kctl(codec, per_pin, hdmi_str); 2179 + 2180 + if (spec->dyn_pcm_assign) 2181 + return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str); 2182 + 2183 + /* for !dyn_pcm_assign, we still use hda_jack for compatibility */ 2184 + /* if !dyn_pcm_assign, it must be non-MST mode. 2185 + * This means pcms and pins are statically mapped. 2186 + * And pcm_idx is pin_idx. 2187 + */ 2188 + per_pin = get_pin(spec, pcm_idx); 2551 2189 phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid); 2552 2190 if (phantom_jack) 2553 2191 strncat(hdmi_str, " Phantom", 2554 2192 sizeof(hdmi_str) - strlen(hdmi_str) - 1); 2555 - 2556 - return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 2557 - phantom_jack); 2193 + ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 2194 + phantom_jack); 2195 + if (ret < 0) 2196 + return ret; 2197 + jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid); 2198 + if (jack == NULL) 2199 + return 0; 2200 + /* assign jack->jack to pcm_rec[].jack to 2201 + * align with dyn_pcm_assign mode 2202 + */ 2203 + spec->pcm_rec[pcm_idx].jack = jack->jack; 2204 + return 0; 2558 2205 } 2559 2206 2560 2207 static int generic_hdmi_build_controls(struct hda_codec *codec) 2561 2208 { 2562 2209 struct hdmi_spec *spec = codec->spec; 2563 2210 int err; 2564 - int pin_idx; 2211 + int pin_idx, pcm_idx; 2212 + 2213 + 2214 + for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 2215 + err = generic_hdmi_build_jack(codec, pcm_idx); 2216 + if (err < 0) 2217 + return err; 2218 + 2219 + /* create the spdif for each pcm 2220 + * pin will be bound when monitor is connected 2221 + */ 2222 + if (spec->dyn_pcm_assign) 2223 + err = snd_hda_create_dig_out_ctls(codec, 2224 + 0, spec->cvt_nids[0], 2225 + HDA_PCM_TYPE_HDMI); 2226 + else { 2227 + struct hdmi_spec_per_pin *per_pin = 2228 + get_pin(spec, pcm_idx); 2229 + err = snd_hda_create_dig_out_ctls(codec, 2230 + per_pin->pin_nid, 2231 + per_pin->mux_nids[0], 2232 + HDA_PCM_TYPE_HDMI); 2233 + } 2234 + if (err < 0) 2235 + return err; 2236 + snd_hda_spdif_ctls_unassign(codec, pcm_idx); 2237 + } 2565 2238 2566 2239 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2567 2240 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2568 2241 2569 - err = generic_hdmi_build_jack(codec, pin_idx); 2570 - if (err < 0) 2571 - return err; 2572 - 2573 - err = snd_hda_create_dig_out_ctls(codec, 2574 - per_pin->pin_nid, 2575 - per_pin->mux_nids[0], 2576 - HDA_PCM_TYPE_HDMI); 2577 - if (err < 0) 2578 - return err; 2579 - snd_hda_spdif_ctls_unassign(codec, pin_idx); 2580 - 2581 2242 /* add control for ELD Bytes */ 2582 2243 err = hdmi_create_eld_ctl(codec, pin_idx, 2583 - get_pcm_rec(spec, pin_idx)->device); 2244 + get_pcm_rec(spec, pin_idx)->device); 2584 2245 2585 2246 if (err < 0) 2586 2247 return err; ··· 2623 2216 } 2624 2217 2625 2218 /* add channel maps */ 2626 - for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2219 + for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 2627 2220 struct hda_pcm *pcm; 2628 2221 struct snd_pcm_chmap *chmap; 2629 2222 struct snd_kcontrol *kctl; 2630 2223 int i; 2631 2224 2632 - pcm = spec->pcm_rec[pin_idx]; 2225 + pcm = get_pcm_rec(spec, pcm_idx); 2633 2226 if (!pcm || !pcm->pcm) 2634 2227 break; 2635 2228 err = snd_pcm_add_chmap_ctls(pcm->pcm, 2636 2229 SNDRV_PCM_STREAM_PLAYBACK, 2637 - NULL, 0, pin_idx, &chmap); 2230 + NULL, 0, pcm_idx, &chmap); 2638 2231 if (err < 0) 2639 2232 return err; 2640 2233 /* override handlers */ ··· 2700 2293 static void generic_hdmi_free(struct hda_codec *codec) 2701 2294 { 2702 2295 struct hdmi_spec *spec = codec->spec; 2703 - int pin_idx; 2296 + int pin_idx, pcm_idx; 2704 2297 2705 2298 if (codec_has_acomp(codec)) 2706 2299 snd_hdac_i915_register_notifier(NULL); 2707 2300 2708 2301 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2709 2302 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2710 - 2711 2303 cancel_delayed_work_sync(&per_pin->work); 2712 2304 eld_proc_free(per_pin); 2713 - if (per_pin->acomp_jack) 2714 - snd_device_free(codec->card, per_pin->acomp_jack); 2305 + } 2306 + 2307 + for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) { 2308 + if (spec->pcm_rec[pcm_idx].jack == NULL) 2309 + continue; 2310 + if (spec->dyn_pcm_assign) 2311 + snd_device_free(codec->card, 2312 + spec->pcm_rec[pcm_idx].jack); 2313 + else 2314 + spec->pcm_rec[pcm_idx].jack = NULL; 2715 2315 } 2716 2316 2717 2317 if (spec->i915_bound) ··· 2867 2453 return -ENOMEM; 2868 2454 2869 2455 spec->ops = generic_standard_hdmi_ops; 2456 + mutex_init(&spec->pcm_lock); 2870 2457 codec->spec = spec; 2871 2458 hdmi_array_init(spec, 4); 2872 2459 ··· 2920 2505 2921 2506 init_channel_allocations(); 2922 2507 2508 + WARN_ON(spec->dyn_pcm_assign && !codec_has_acomp(codec)); 2923 2509 return 0; 2924 2510 } 2925 2511 ··· 2943 2527 info = snd_hda_codec_pcm_new(codec, "HDMI 0"); 2944 2528 if (!info) 2945 2529 return -ENOMEM; 2946 - spec->pcm_rec[0] = info; 2530 + spec->pcm_rec[0].pcm = info; 2947 2531 info->pcm_type = HDA_PCM_TYPE_HDMI; 2948 2532 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 2949 2533 *pstr = spec->pcm_playback;