From: libin.yang@linux.intel.com
To: alsa-devel@alsa-project.org, tiwai@suse.de
Cc: libin.yang@intel.com, Libin Yang <libin.yang@linux.intel.com>,
mengdong.lin@linux.intel.com
Subject: [RFC V2 PATCH 3/5] ALSA: hda - hdmi dynamically bind PCM to pin when monitor hotplug
Date: Mon, 23 Nov 2015 22:09:32 +0800 [thread overview]
Message-ID: <1448287774-146673-5-git-send-email-libin.yang@linux.intel.com> (raw)
In-Reply-To: <1448287774-146673-1-git-send-email-libin.yang@linux.intel.com>
From: Libin Yang <libin.yang@linux.intel.com>
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.
Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
---
sound/pci/hda/patch_hdmi.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index de22ac2..bcc2a90 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -72,6 +72,8 @@ struct hdmi_spec_per_cvt {
struct hdmi_spec_per_pin {
hda_nid_t pin_nid;
+ /* pin idx, different device entries on the same pin use the same idx */
+ int pin_nid_idx;
int num_mux_nids;
hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
int mux_idx;
@@ -83,6 +85,7 @@ struct hdmi_spec_per_pin {
struct delayed_work work;
struct snd_kcontrol *eld_ctl;
struct hda_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
+ int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
int repoll_count;
bool setup; /* the stream has been set up by prepare callback */
int channels; /* current number of channels */
@@ -136,6 +139,7 @@ struct hdmi_spec {
struct snd_array pins; /* struct hdmi_spec_per_pin */
struct hda_pcm *pcm_rec[16];
struct mutex pcm_lock;
+ unsigned long pcm_bitmap;
int pcm_used; /* counter of pcm_rec[] */
unsigned int channels_max; /* max over all cvts */
@@ -1663,6 +1667,70 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
return 0;
}
+static int get_preferred_pcm_slot(struct hdmi_spec *spec,
+ struct hdmi_spec_per_pin *per_pin)
+{
+ if ((spec->pcm_bitmap & (1 << per_pin->pin_nid_idx)) == 0)
+ return per_pin->pin_nid_idx;
+ return -1;
+}
+
+static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
+ struct hdmi_spec_per_pin *per_pin)
+{
+ int slot;
+ int i;
+
+ /* try the prefer PCM */
+ slot = get_preferred_pcm_slot(spec, per_pin);
+ if (slot != -1)
+ return slot;
+
+ /* have a second try */
+ for (i = spec->num_pins; i < spec->pcm_used; i++) {
+ if ((spec->pcm_bitmap & (1 << i)) == 0)
+ return i;
+ }
+
+ /* the last try */
+ for (i = 0; i < spec->pcm_used; i++) {
+ if ((spec->pcm_bitmap & (1 << i)) == 0)
+ return i;
+ }
+ return -ENODEV;
+}
+
+static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
+ struct hdmi_spec_per_pin *per_pin)
+{
+ int idx;
+
+ /* pcm already be attached to the pin */
+ if (per_pin->pcm)
+ return;
+ idx = hdmi_find_pcm_slot(spec, per_pin);
+ if (idx == -ENODEV)
+ return;
+ per_pin->pcm_idx = idx;
+ per_pin->pcm = spec->pcm_rec[idx];
+ set_bit(idx, &spec->pcm_bitmap);
+}
+
+static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
+ struct hdmi_spec_per_pin *per_pin)
+{
+ int idx;
+
+ /* pcm already be detached from the pin */
+ if (!per_pin->pcm)
+ return;
+ idx = per_pin->pcm_idx;
+ per_pin->pcm_idx = -1;
+ per_pin->pcm = NULL;
+ if (idx >= 0 && idx < spec->pcm_used)
+ clear_bit(idx, &spec->pcm_bitmap);
+}
+
static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
{
struct hda_jack_tbl *jack;
@@ -1687,6 +1755,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
snd_hda_power_up_pm(codec);
present = snd_hda_pin_sense(codec, pin_nid);
+ mutex_lock(&spec->pcm_lock);
mutex_lock(&per_pin->lock);
pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
if (pin_eld->monitor_present)
@@ -1720,6 +1789,13 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
}
}
+ if (spec->dyn_pcm_assign) {
+ if (eld->eld_valid)
+ hdmi_attach_hda_pcm(spec, per_pin);
+ else
+ hdmi_detach_hda_pcm(spec, per_pin);
+ }
+
if (pin_eld->eld_valid != eld->eld_valid)
eld_changed = true;
@@ -1770,6 +1846,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
jack->block_report = !ret;
mutex_unlock(&per_pin->lock);
+ mutex_unlock(&spec->pcm_lock);
snd_hda_power_down_pm(codec);
return ret;
}
@@ -1815,6 +1892,11 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
per_pin->pin_nid = pin_nid;
per_pin->non_pcm = false;
+ if (spec->dyn_pcm_assign)
+ per_pin->pcm_idx = -1;
+ else
+ per_pin->pcm_idx = pin_idx;
+ per_pin->pin_nid_idx = pin_idx;
err = hdmi_read_pin_conn(codec, pin_idx);
if (err < 0)
--
1.9.1
next prev parent reply other threads:[~2015-11-23 14:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-23 14:09 [RFC V2 PATCH 0/5] hdmi audio dynamically bind PCM to pin libin.yang
2015-11-23 14:09 ` libin.yang
2015-11-23 14:09 ` [RFC V2 PATCH 1/5] ALSA: hda - hdmi playback without monitor in dynamic pcm bind mode libin.yang
2015-11-23 16:01 ` Takashi Iwai
2015-11-25 6:50 ` Yang, Libin
2015-11-23 14:09 ` [RFC V2 PATCH 2/5] ALSA: hda - hdmi operate spdif based on pcm libin.yang
2015-11-23 14:09 ` libin.yang [this message]
2015-11-23 15:59 ` [RFC V2 PATCH 3/5] ALSA: hda - hdmi dynamically bind PCM to pin when monitor hotplug Takashi Iwai
2015-11-25 6:53 ` Yang, Libin
2015-11-23 14:09 ` [RFC V2 PATCH 4/5] ALSA: hda - add in_use flag in hda_pcm libin.yang
2015-11-23 15:50 ` Takashi Iwai
2015-11-25 6:50 ` Yang, Libin
2015-11-23 14:09 ` [RFC V2 PATCH 5/5] ALSA: hda - hdmi setup pin when monitor hotplug in pcm dynamic assignment mode libin.yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448287774-146673-5-git-send-email-libin.yang@linux.intel.com \
--to=libin.yang@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=libin.yang@intel.com \
--cc=mengdong.lin@linux.intel.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).