Skip to content

Commit a76056f

Browse files
libinyangtiwai
authored andcommitted
ALSA: hda - hdmi dynamically bind PCM to pin when monitor hotplug
Dynamically bind/unbind the PCM to pin when HDMI/DP monitor hotplug. When monitor is connected, find a proper PCM for the monitor. When monitor is disconnected, unbind the PCM from the pin. The binding policy (use Intel platform as example) is: 1. Try to use the legacy pin-pcm mapping for the device entry 0 of the pin. 2. If step 1 fails, try to bind pin to the backup PCMs. For example, on Intel platform, if DP MST is enabled, 5 PCMs will be created. PCM 3, PCM 7, PCM 8 are supposed to be used by device entry 0 of pin 5, pin 6 and pin 7. PCM 9 and PCM 10 are the backup PCMs. 3. If step 2 fails, try to find any PCM to bind to the pin. Signed-off-by: Libin Yang <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 2bf3c85 commit a76056f

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

sound/pci/hda/patch_hdmi.c

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ struct hdmi_spec_per_cvt {
7575

7676
struct hdmi_spec_per_pin {
7777
hda_nid_t pin_nid;
78+
/* pin idx, different device entries on the same pin use the same idx */
79+
int pin_nid_idx;
7880
int num_mux_nids;
7981
hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
8082
int mux_idx;
@@ -87,6 +89,7 @@ struct hdmi_spec_per_pin {
8789
struct snd_kcontrol *eld_ctl;
8890
struct snd_jack *acomp_jack; /* jack via audio component */
8991
struct hda_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
92+
int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
9093
int repoll_count;
9194
bool setup; /* the stream has been set up by prepare callback */
9295
int channels; /* current number of channels */
@@ -140,6 +143,8 @@ struct hdmi_spec {
140143
struct snd_array pins; /* struct hdmi_spec_per_pin */
141144
struct hda_pcm *pcm_rec[16];
142145
struct mutex pcm_lock;
146+
/* pcm_bitmap means which pcms have been assigned to pins*/
147+
unsigned long pcm_bitmap;
143148
int pcm_used; /* counter of pcm_rec[] */
144149
unsigned int channels_max; /* max over all cvts */
145150

@@ -1673,6 +1678,60 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
16731678
return 0;
16741679
}
16751680

1681+
static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
1682+
struct hdmi_spec_per_pin *per_pin)
1683+
{
1684+
int i;
1685+
1686+
/* try the prefer PCM */
1687+
if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
1688+
return per_pin->pin_nid_idx;
1689+
1690+
/* have a second try; check the "reserved area" over num_pins */
1691+
for (i = spec->num_pins; i < spec->pcm_used; i++) {
1692+
if (!test_bit(i, &spec->pcm_bitmap))
1693+
return i;
1694+
}
1695+
1696+
/* the last try; check the empty slots in pins */
1697+
for (i = 0; i < spec->num_pins; i++) {
1698+
if (!test_bit(i, &spec->pcm_bitmap))
1699+
return i;
1700+
}
1701+
return -EBUSY;
1702+
}
1703+
1704+
static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
1705+
struct hdmi_spec_per_pin *per_pin)
1706+
{
1707+
int idx;
1708+
1709+
/* pcm already be attached to the pin */
1710+
if (per_pin->pcm)
1711+
return;
1712+
idx = hdmi_find_pcm_slot(spec, per_pin);
1713+
if (idx == -ENODEV)
1714+
return;
1715+
per_pin->pcm_idx = idx;
1716+
per_pin->pcm = spec->pcm_rec[idx];
1717+
set_bit(idx, &spec->pcm_bitmap);
1718+
}
1719+
1720+
static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
1721+
struct hdmi_spec_per_pin *per_pin)
1722+
{
1723+
int idx;
1724+
1725+
/* pcm already be detached from the pin */
1726+
if (!per_pin->pcm)
1727+
return;
1728+
idx = per_pin->pcm_idx;
1729+
per_pin->pcm_idx = -1;
1730+
per_pin->pcm = NULL;
1731+
if (idx >= 0 && idx < spec->pcm_used)
1732+
clear_bit(idx, &spec->pcm_bitmap);
1733+
}
1734+
16761735
/* update per_pin ELD from the given new ELD;
16771736
* setup info frame and notification accordingly
16781737
*/
@@ -1681,9 +1740,17 @@ static void update_eld(struct hda_codec *codec,
16811740
struct hdmi_eld *eld)
16821741
{
16831742
struct hdmi_eld *pin_eld = &per_pin->sink_eld;
1743+
struct hdmi_spec *spec = codec->spec;
16841744
bool old_eld_valid = pin_eld->eld_valid;
16851745
bool eld_changed;
16861746

1747+
if (spec->dyn_pcm_assign) {
1748+
if (eld->eld_valid)
1749+
hdmi_attach_hda_pcm(spec, per_pin);
1750+
else
1751+
hdmi_detach_hda_pcm(spec, per_pin);
1752+
}
1753+
16871754
if (eld->eld_valid)
16881755
snd_hdmi_show_eld(codec, &eld->info);
16891756

@@ -1827,13 +1894,19 @@ static void sync_eld_via_acomp(struct hda_codec *codec,
18271894
static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
18281895
{
18291896
struct hda_codec *codec = per_pin->codec;
1897+
struct hdmi_spec *spec = codec->spec;
1898+
int ret;
18301899

1900+
mutex_lock(&spec->pcm_lock);
18311901
if (codec_has_acomp(codec)) {
18321902
sync_eld_via_acomp(codec, per_pin);
1833-
return false; /* don't call snd_hda_jack_report_sync() */
1903+
ret = false; /* don't call snd_hda_jack_report_sync() */
18341904
} else {
1835-
return hdmi_present_sense_via_verbs(per_pin, repoll);
1905+
ret = hdmi_present_sense_via_verbs(per_pin, repoll);
18361906
}
1907+
mutex_unlock(&spec->pcm_lock);
1908+
1909+
return ret;
18371910
}
18381911

18391912
static void hdmi_repoll_eld(struct work_struct *work)
@@ -1877,6 +1950,11 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
18771950

18781951
per_pin->pin_nid = pin_nid;
18791952
per_pin->non_pcm = false;
1953+
if (spec->dyn_pcm_assign)
1954+
per_pin->pcm_idx = -1;
1955+
else
1956+
per_pin->pcm_idx = pin_idx;
1957+
per_pin->pin_nid_idx = pin_idx;
18801958

18811959
err = hdmi_read_pin_conn(codec, pin_idx);
18821960
if (err < 0)

0 commit comments

Comments
 (0)