summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorLibin Yang <libin.yang@linux.intel.com>2017-01-12 03:04:53 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2017-01-12 04:06:47 -0500
commit9152085defb6426ce8f9989ca27e4450daefbd89 (patch)
tree91c90685a96ca5d47f1a02b41da2e44f2c07e52a /sound
parent13800f397ee3b4996f316b9caa8482cb90edef0d (diff)
ALSA: hda - add DP MST audio support
This patch adds the DP MST audio support on i915 platform and it will enable dyn_pcm_assign feature. DP MST supports several device entry on the same port and each device entry can map to one pcm stream. For example, on i915, there are 3 pins, and each pin has 3 device entries. This means there should be 3x3 pcms. However, there is only 3 pipe lines in i915. This means 3 pcms are actived at most at the same moment. We will create 5 pcms (pin number + dev entry num - 1) in this case. For the details, please refer commit a76056f2e57e ("ALSA: hda - hdmi dynamically bind PCM to pin when monitor hotplug") Each device entry is a virtual pin. It is described by pin_nid and dev_id in struct hdmi_spec_per_pin. Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Libin Yang <libin.yang@linux.intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1484208294-8637-3-git-send-email-libin.yang@intel.com
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/hda/hda_codec.c4
-rw-r--r--sound/pci/hda/patch_hdmi.c245
2 files changed, 197 insertions, 52 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 9dc847db1cc4..8fd745cb3f36 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -467,6 +467,10 @@ static int read_pin_defaults(struct hda_codec *codec)
467 pin->nid = nid; 467 pin->nid = nid;
468 pin->cfg = snd_hda_codec_read(codec, nid, 0, 468 pin->cfg = snd_hda_codec_read(codec, nid, 0,
469 AC_VERB_GET_CONFIG_DEFAULT, 0); 469 AC_VERB_GET_CONFIG_DEFAULT, 0);
470 /*
471 * all device entries are the same widget control so far
472 * fixme: if any codec is different, need fix here
473 */
470 pin->ctrl = snd_hda_codec_read(codec, nid, 0, 474 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
471 AC_VERB_GET_PIN_WIDGET_CONTROL, 475 AC_VERB_GET_PIN_WIDGET_CONTROL,
472 0); 476 0);
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index cf9bc042fe96..32105cee56ca 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -76,6 +76,7 @@ struct hdmi_spec_per_cvt {
76 76
77struct hdmi_spec_per_pin { 77struct hdmi_spec_per_pin {
78 hda_nid_t pin_nid; 78 hda_nid_t pin_nid;
79 int dev_id;
79 /* pin idx, different device entries on the same pin use the same idx */ 80 /* pin idx, different device entries on the same pin use the same idx */
80 int pin_nid_idx; 81 int pin_nid_idx;
81 int num_mux_nids; 82 int num_mux_nids;
@@ -130,7 +131,23 @@ struct hdmi_spec {
130 struct snd_array cvts; /* struct hdmi_spec_per_cvt */ 131 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
131 hda_nid_t cvt_nids[4]; /* only for haswell fix */ 132 hda_nid_t cvt_nids[4]; /* only for haswell fix */
132 133
134 /*
135 * num_pins is the number of virtual pins
136 * for example, there are 3 pins, and each pin
137 * has 4 device entries, then the num_pins is 12
138 */
133 int num_pins; 139 int num_pins;
140 /*
141 * num_nids is the number of real pins
142 * In the above example, num_nids is 3
143 */
144 int num_nids;
145 /*
146 * dev_num is the number of device entries
147 * on each pin.
148 * In the above example, dev_num is 4
149 */
150 int dev_num;
134 struct snd_array pins; /* struct hdmi_spec_per_pin */ 151 struct snd_array pins; /* struct hdmi_spec_per_pin */
135 struct hdmi_pcm pcm_rec[16]; 152 struct hdmi_pcm pcm_rec[16];
136 struct mutex pcm_lock; 153 struct mutex pcm_lock;
@@ -217,14 +234,26 @@ union audio_infoframe {
217/* obtain hda_pcm object assigned to idx */ 234/* obtain hda_pcm object assigned to idx */
218#define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm) 235#define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
219 236
220static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) 237static int pin_id_to_pin_index(struct hda_codec *codec,
238 hda_nid_t pin_nid, int dev_id)
221{ 239{
222 struct hdmi_spec *spec = codec->spec; 240 struct hdmi_spec *spec = codec->spec;
223 int pin_idx; 241 int pin_idx;
242 struct hdmi_spec_per_pin *per_pin;
243
244 /*
245 * (dev_id == -1) means it is NON-MST pin
246 * return the first virtual pin on this port
247 */
248 if (dev_id == -1)
249 dev_id = 0;
224 250
225 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 251 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
226 if (get_pin(spec, pin_idx)->pin_nid == pin_nid) 252 per_pin = get_pin(spec, pin_idx);
253 if ((per_pin->pin_nid == pin_nid) &&
254 (per_pin->dev_id == dev_id))
227 return pin_idx; 255 return pin_idx;
256 }
228 257
229 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid); 258 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
230 return -EINVAL; 259 return -EINVAL;
@@ -724,10 +753,11 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
724 753
725static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); 754static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
726 755
727static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid) 756static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
757 int dev_id)
728{ 758{
729 struct hdmi_spec *spec = codec->spec; 759 struct hdmi_spec *spec = codec->spec;
730 int pin_idx = pin_nid_to_pin_index(codec, nid); 760 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
731 761
732 if (pin_idx < 0) 762 if (pin_idx < 0)
733 return; 763 return;
@@ -738,7 +768,8 @@ static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)
738static void jack_callback(struct hda_codec *codec, 768static void jack_callback(struct hda_codec *codec,
739 struct hda_jack_callback *jack) 769 struct hda_jack_callback *jack)
740{ 770{
741 check_presence_and_report(codec, jack->nid); 771 /* hda_jack don't support DP MST */
772 check_presence_and_report(codec, jack->nid, 0);
742} 773}
743 774
744static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 775static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -747,6 +778,12 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
747 struct hda_jack_tbl *jack; 778 struct hda_jack_tbl *jack;
748 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; 779 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
749 780
781 /*
782 * assume DP MST uses dyn_pcm_assign and acomp and
783 * never comes here
784 * if DP MST supports unsol event, below code need
785 * consider dev_entry
786 */
750 jack = snd_hda_jack_tbl_get_from_tag(codec, tag); 787 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
751 if (!jack) 788 if (!jack)
752 return; 789 return;
@@ -757,7 +794,8 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
757 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA), 794 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
758 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); 795 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
759 796
760 check_presence_and_report(codec, jack->nid); 797 /* hda_jack don't support DP MST */
798 check_presence_and_report(codec, jack->nid, 0);
761} 799}
762 800
763static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 801static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -970,28 +1008,60 @@ static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
970 * by any other pins. 1008 * by any other pins.
971 */ 1009 */
972static void intel_not_share_assigned_cvt(struct hda_codec *codec, 1010static void intel_not_share_assigned_cvt(struct hda_codec *codec,
973 hda_nid_t pin_nid, int mux_idx) 1011 hda_nid_t pin_nid,
1012 int dev_id, int mux_idx)
974{ 1013{
975 struct hdmi_spec *spec = codec->spec; 1014 struct hdmi_spec *spec = codec->spec;
976 hda_nid_t nid; 1015 hda_nid_t nid;
977 int cvt_idx, curr; 1016 int cvt_idx, curr;
978 struct hdmi_spec_per_cvt *per_cvt; 1017 struct hdmi_spec_per_cvt *per_cvt;
1018 struct hdmi_spec_per_pin *per_pin;
1019 int pin_idx;
1020
1021 /* configure the pins connections */
1022 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1023 int dev_id_saved;
1024 int dev_num;
979 1025
980 /* configure all pins, including "no physical connection" ones */ 1026 per_pin = get_pin(spec, pin_idx);
981 for_each_hda_codec_node(nid, codec) { 1027 /*
982 unsigned int wid_caps = get_wcaps(codec, nid); 1028 * pin not connected to monitor
983 unsigned int wid_type = get_wcaps_type(wid_caps); 1029 * no need to operate on it
1030 */
1031 if (!per_pin->pcm)
1032 continue;
984 1033
985 if (wid_type != AC_WID_PIN) 1034 if ((per_pin->pin_nid == pin_nid) &&
1035 (per_pin->dev_id == dev_id))
986 continue; 1036 continue;
987 1037
988 if (nid == pin_nid) 1038 /*
1039 * if per_pin->dev_id >= dev_num,
1040 * snd_hda_get_dev_select() will fail,
1041 * and the following operation is unpredictable.
1042 * So skip this situation.
1043 */
1044 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1045 if (per_pin->dev_id >= dev_num)
989 continue; 1046 continue;
990 1047
1048 nid = per_pin->pin_nid;
1049
1050 /*
1051 * Calling this function should not impact
1052 * on the device entry selection
1053 * So let's save the dev id for each pin,
1054 * and restore it when return
1055 */
1056 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1057 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
991 curr = snd_hda_codec_read(codec, nid, 0, 1058 curr = snd_hda_codec_read(codec, nid, 0,
992 AC_VERB_GET_CONNECT_SEL, 0); 1059 AC_VERB_GET_CONNECT_SEL, 0);
993 if (curr != mux_idx) 1060 if (curr != mux_idx) {
1061 snd_hda_set_dev_select(codec, nid, dev_id_saved);
994 continue; 1062 continue;
1063 }
1064
995 1065
996 /* choose an unassigned converter. The conveters in the 1066 /* choose an unassigned converter. The conveters in the
997 * connection list are in the same order as in the codec. 1067 * connection list are in the same order as in the codec.
@@ -1008,12 +1078,13 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1008 break; 1078 break;
1009 } 1079 }
1010 } 1080 }
1081 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1011 } 1082 }
1012} 1083}
1013 1084
1014/* A wrapper of intel_not_share_asigned_cvt() */ 1085/* A wrapper of intel_not_share_asigned_cvt() */
1015static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec, 1086static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1016 hda_nid_t pin_nid, hda_nid_t cvt_nid) 1087 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1017{ 1088{
1018 int mux_idx; 1089 int mux_idx;
1019 struct hdmi_spec *spec = codec->spec; 1090 struct hdmi_spec *spec = codec->spec;
@@ -1025,7 +1096,7 @@ static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1025 */ 1096 */
1026 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid); 1097 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1027 if (mux_idx >= 0) 1098 if (mux_idx >= 0)
1028 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx); 1099 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1029} 1100}
1030 1101
1031/* skeleton caller of pin_cvt_fixup ops */ 1102/* skeleton caller of pin_cvt_fixup ops */
@@ -1140,6 +1211,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1140 per_pin->cvt_nid = per_cvt->cvt_nid; 1211 per_pin->cvt_nid = per_cvt->cvt_nid;
1141 hinfo->nid = per_cvt->cvt_nid; 1212 hinfo->nid = per_cvt->cvt_nid;
1142 1213
1214 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1143 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1215 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1144 AC_VERB_SET_CONNECT_SEL, 1216 AC_VERB_SET_CONNECT_SEL,
1145 per_pin->mux_idx); 1217 per_pin->mux_idx);
@@ -1198,6 +1270,7 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1198 return -EINVAL; 1270 return -EINVAL;
1199 } 1271 }
1200 1272
1273 /* all the device entries on the same pin have the same conn list */
1201 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid, 1274 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1202 per_pin->mux_nids, 1275 per_pin->mux_nids,
1203 HDA_MAX_CONNECTIONS); 1276 HDA_MAX_CONNECTIONS);
@@ -1215,13 +1288,13 @@ static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1215 return per_pin->pin_nid_idx; 1288 return per_pin->pin_nid_idx;
1216 1289
1217 /* have a second try; check the "reserved area" over num_pins */ 1290 /* have a second try; check the "reserved area" over num_pins */
1218 for (i = spec->num_pins; i < spec->pcm_used; i++) { 1291 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1219 if (!test_bit(i, &spec->pcm_bitmap)) 1292 if (!test_bit(i, &spec->pcm_bitmap))
1220 return i; 1293 return i;
1221 } 1294 }
1222 1295
1223 /* the last try; check the empty slots in pins */ 1296 /* the last try; check the empty slots in pins */
1224 for (i = 0; i < spec->num_pins; i++) { 1297 for (i = 0; i < spec->num_nids; i++) {
1225 if (!test_bit(i, &spec->pcm_bitmap)) 1298 if (!test_bit(i, &spec->pcm_bitmap))
1226 return i; 1299 return i;
1227 } 1300 }
@@ -1296,10 +1369,13 @@ static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
1296 per_pin->cvt_nid = hinfo->nid; 1369 per_pin->cvt_nid = hinfo->nid;
1297 1370
1298 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid); 1371 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1299 if (mux_idx < per_pin->num_mux_nids) 1372 if (mux_idx < per_pin->num_mux_nids) {
1373 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1374 per_pin->dev_id);
1300 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, 1375 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1301 AC_VERB_SET_CONNECT_SEL, 1376 AC_VERB_SET_CONNECT_SEL,
1302 mux_idx); 1377 mux_idx);
1378 }
1303 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid); 1379 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1304 1380
1305 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid); 1381 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
@@ -1467,6 +1543,11 @@ static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
1467 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign) 1543 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1468 jack = spec->pcm_rec[per_pin->pcm_idx].jack; 1544 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1469 else if (!spec->dyn_pcm_assign) { 1545 else if (!spec->dyn_pcm_assign) {
1546 /*
1547 * jack tbl doesn't support DP MST
1548 * DP MST will use dyn_pcm_assign,
1549 * so DP MST will never come here
1550 */
1470 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid); 1551 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1471 if (jack_tbl) 1552 if (jack_tbl)
1472 jack = jack_tbl->jack; 1553 jack = jack_tbl->jack;
@@ -1485,9 +1566,9 @@ static void sync_eld_via_acomp(struct hda_codec *codec,
1485 1566
1486 mutex_lock(&per_pin->lock); 1567 mutex_lock(&per_pin->lock);
1487 eld->monitor_present = false; 1568 eld->monitor_present = false;
1488 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, -1, 1569 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1489 &eld->monitor_present, eld->eld_buffer, 1570 per_pin->dev_id, &eld->monitor_present,
1490 ELD_MAX_SIZE); 1571 eld->eld_buffer, ELD_MAX_SIZE);
1491 if (size > 0) { 1572 if (size > 0) {
1492 size = min(size, ELD_MAX_SIZE); 1573 size = min(size, ELD_MAX_SIZE);
1493 if (snd_hdmi_parse_eld(codec, &eld->info, 1574 if (snd_hdmi_parse_eld(codec, &eld->info,
@@ -1565,38 +1646,81 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
1565 int pin_idx; 1646 int pin_idx;
1566 struct hdmi_spec_per_pin *per_pin; 1647 struct hdmi_spec_per_pin *per_pin;
1567 int err; 1648 int err;
1649 int dev_num, i;
1568 1650
1569 caps = snd_hda_query_pin_caps(codec, pin_nid); 1651 caps = snd_hda_query_pin_caps(codec, pin_nid);
1570 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) 1652 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1571 return 0; 1653 return 0;
1572 1654
1655 /*
1656 * For DP MST audio, Configuration Default is the same for
1657 * all device entries on the same pin
1658 */
1573 config = snd_hda_codec_get_pincfg(codec, pin_nid); 1659 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1574 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE) 1660 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1575 return 0; 1661 return 0;
1576 1662
1577 if (is_haswell_plus(codec)) 1663 /*
1578 intel_haswell_fixup_connect_list(codec, pin_nid); 1664 * To simplify the implementation, malloc all
1579 1665 * the virtual pins in the initialization statically
1580 pin_idx = spec->num_pins; 1666 */
1581 per_pin = snd_array_new(&spec->pins); 1667 if (is_haswell_plus(codec)) {
1582 if (!per_pin) 1668 /*
1583 return -ENOMEM; 1669 * On Intel platforms, device entries number is
1584 1670 * changed dynamically. If there is a DP MST
1585 per_pin->pin_nid = pin_nid; 1671 * hub connected, the device entries number is 3.
1586 per_pin->non_pcm = false; 1672 * Otherwise, it is 1.
1587 if (spec->dyn_pcm_assign) 1673 * Here we manually set dev_num to 3, so that
1588 per_pin->pcm_idx = -1; 1674 * we can initialize all the device entries when
1589 else { 1675 * bootup statically.
1590 per_pin->pcm = get_hdmi_pcm(spec, pin_idx); 1676 */
1591 per_pin->pcm_idx = pin_idx; 1677 dev_num = 3;
1678 spec->dev_num = 3;
1679 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1680 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1681 /*
1682 * spec->dev_num is the maxinum number of device entries
1683 * among all the pins
1684 */
1685 spec->dev_num = (spec->dev_num > dev_num) ?
1686 spec->dev_num : dev_num;
1687 } else {
1688 /*
1689 * If the platform doesn't support DP MST,
1690 * manually set dev_num to 1. This means
1691 * the pin has only one device entry.
1692 */
1693 dev_num = 1;
1694 spec->dev_num = 1;
1592 } 1695 }
1593 per_pin->pin_nid_idx = pin_idx;
1594 1696
1595 err = hdmi_read_pin_conn(codec, pin_idx); 1697 for (i = 0; i < dev_num; i++) {
1596 if (err < 0) 1698 pin_idx = spec->num_pins;
1597 return err; 1699 per_pin = snd_array_new(&spec->pins);
1598 1700
1599 spec->num_pins++; 1701 if (!per_pin)
1702 return -ENOMEM;
1703
1704 if (spec->dyn_pcm_assign) {
1705 per_pin->pcm = NULL;
1706 per_pin->pcm_idx = -1;
1707 } else {
1708 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1709 per_pin->pcm_idx = pin_idx;
1710 }
1711 per_pin->pin_nid = pin_nid;
1712 per_pin->pin_nid_idx = spec->num_nids;
1713 per_pin->dev_id = i;
1714 per_pin->non_pcm = false;
1715 snd_hda_set_dev_select(codec, pin_nid, i);
1716 if (is_haswell_plus(codec))
1717 intel_haswell_fixup_connect_list(codec, pin_nid);
1718 err = hdmi_read_pin_conn(codec, pin_idx);
1719 if (err < 0)
1720 return err;
1721 spec->num_pins++;
1722 }
1723 spec->num_nids++;
1600 1724
1601 return 0; 1725 return 0;
1602} 1726}
@@ -1744,7 +1868,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1744 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */ 1868 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1745 /* Todo: add DP1.2 MST audio support later */ 1869 /* Todo: add DP1.2 MST audio support later */
1746 if (codec_has_acomp(codec)) 1870 if (codec_has_acomp(codec))
1747 snd_hdac_sync_audio_rate(&codec->core, pin_nid, -1, 1871 snd_hdac_sync_audio_rate(&codec->core, pin_nid, per_pin->dev_id,
1748 runtime->rate); 1872 runtime->rate);
1749 1873
1750 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1874 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
@@ -1762,6 +1886,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1762 pinctl | PIN_OUT); 1886 pinctl | PIN_OUT);
1763 } 1887 }
1764 1888
1889 /* snd_hda_set_dev_select() has been called before */
1765 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid, 1890 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
1766 stream_tag, format); 1891 stream_tag, format);
1767 mutex_unlock(&spec->pcm_lock); 1892 mutex_unlock(&spec->pcm_lock);
@@ -1897,17 +2022,23 @@ static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
1897static int generic_hdmi_build_pcms(struct hda_codec *codec) 2022static int generic_hdmi_build_pcms(struct hda_codec *codec)
1898{ 2023{
1899 struct hdmi_spec *spec = codec->spec; 2024 struct hdmi_spec *spec = codec->spec;
1900 int pin_idx; 2025 int idx;
1901 2026
1902 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2027 /*
2028 * for non-mst mode, pcm number is the same as before
2029 * for DP MST mode, pcm number is (nid number + dev_num - 1)
2030 * dev_num is the device entry number in a pin
2031 *
2032 */
2033 for (idx = 0; idx < spec->num_nids + spec->dev_num - 1; idx++) {
1903 struct hda_pcm *info; 2034 struct hda_pcm *info;
1904 struct hda_pcm_stream *pstr; 2035 struct hda_pcm_stream *pstr;
1905 2036
1906 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); 2037 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
1907 if (!info) 2038 if (!info)
1908 return -ENOMEM; 2039 return -ENOMEM;
1909 2040
1910 spec->pcm_rec[pin_idx].pcm = info; 2041 spec->pcm_rec[idx].pcm = info;
1911 spec->pcm_used++; 2042 spec->pcm_used++;
1912 info->pcm_type = HDA_PCM_TYPE_HDMI; 2043 info->pcm_type = HDA_PCM_TYPE_HDMI;
1913 info->own_chmap = true; 2044 info->own_chmap = true;
@@ -1915,6 +2046,9 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
1915 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; 2046 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1916 pstr->substreams = 1; 2047 pstr->substreams = 1;
1917 pstr->ops = generic_ops; 2048 pstr->ops = generic_ops;
2049 /* pcm number is less than 16 */
2050 if (spec->pcm_used >= 16)
2051 break;
1918 /* other pstr fields are set in open */ 2052 /* other pstr fields are set in open */
1919 } 2053 }
1920 2054
@@ -2070,7 +2204,9 @@ static int generic_hdmi_init(struct hda_codec *codec)
2070 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 2204 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2071 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 2205 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2072 hda_nid_t pin_nid = per_pin->pin_nid; 2206 hda_nid_t pin_nid = per_pin->pin_nid;
2207 int dev_id = per_pin->dev_id;
2073 2208
2209 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2074 hdmi_init_pin(codec, pin_nid); 2210 hdmi_init_pin(codec, pin_nid);
2075 if (!codec_has_acomp(codec)) 2211 if (!codec_has_acomp(codec))
2076 snd_hda_jack_detect_enable_callback(codec, pin_nid, 2212 snd_hda_jack_detect_enable_callback(codec, pin_nid,
@@ -2178,6 +2314,7 @@ static int alloc_generic_hdmi(struct hda_codec *codec)
2178 return -ENOMEM; 2314 return -ENOMEM;
2179 2315
2180 spec->ops = generic_standard_hdmi_ops; 2316 spec->ops = generic_standard_hdmi_ops;
2317 spec->dev_num = 1; /* initialize to 1 */
2181 mutex_init(&spec->pcm_lock); 2318 mutex_init(&spec->pcm_lock);
2182 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap); 2319 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2183 2320
@@ -2295,6 +2432,7 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2295{ 2432{
2296 struct hda_codec *codec = audio_ptr; 2433 struct hda_codec *codec = audio_ptr;
2297 int pin_nid; 2434 int pin_nid;
2435 int dev_id = pipe;
2298 2436
2299 /* we assume only from port-B to port-D */ 2437 /* we assume only from port-B to port-D */
2300 if (port < 1 || port > 3) 2438 if (port < 1 || port > 3)
@@ -2321,7 +2459,7 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
2321 return; 2459 return;
2322 2460
2323 snd_hdac_i915_set_bclk(&codec->bus->core); 2461 snd_hdac_i915_set_bclk(&codec->bus->core);
2324 check_presence_and_report(codec, pin_nid); 2462 check_presence_and_report(codec, pin_nid, dev_id);
2325} 2463}
2326 2464
2327/* register i915 component pin_eld_notify callback */ 2465/* register i915 component pin_eld_notify callback */
@@ -2354,11 +2492,13 @@ static void i915_pin_cvt_fixup(struct hda_codec *codec,
2354 hda_nid_t cvt_nid) 2492 hda_nid_t cvt_nid)
2355{ 2493{
2356 if (per_pin) { 2494 if (per_pin) {
2495 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2496 per_pin->dev_id);
2357 intel_verify_pin_cvt_connect(codec, per_pin); 2497 intel_verify_pin_cvt_connect(codec, per_pin);
2358 intel_not_share_assigned_cvt(codec, per_pin->pin_nid, 2498 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2359 per_pin->mux_idx); 2499 per_pin->dev_id, per_pin->mux_idx);
2360 } else { 2500 } else {
2361 intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid); 2501 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2362 } 2502 }
2363} 2503}
2364 2504
@@ -2378,6 +2518,8 @@ static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2378 if (err < 0) 2518 if (err < 0)
2379 return err; 2519 return err;
2380 spec = codec->spec; 2520 spec = codec->spec;
2521 codec->dp_mst = true;
2522 spec->dyn_pcm_assign = true;
2381 2523
2382 intel_haswell_enable_all_pins(codec, true); 2524 intel_haswell_enable_all_pins(codec, true);
2383 intel_haswell_fixup_enable_dp12(codec); 2525 intel_haswell_fixup_enable_dp12(codec);
@@ -2389,7 +2531,6 @@ static int patch_i915_hsw_hdmi(struct hda_codec *codec)
2389 codec->core.link_power_control = 1; 2531 codec->core.link_power_control = 1;
2390 2532
2391 codec->patch_ops.set_power_state = haswell_set_power_state; 2533 codec->patch_ops.set_power_state = haswell_set_power_state;
2392 codec->dp_mst = true;
2393 codec->depop_delay = 0; 2534 codec->depop_delay = 0;
2394 codec->auto_runtime_pm = 1; 2535 codec->auto_runtime_pm = 1;
2395 2536