diff mbox

[3/4] ALSA: hda - hdmi jack created based on pcm

Message ID 1451524942-17288-4-git-send-email-libin.yang@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

libin.yang@linux.intel.com Dec. 31, 2015, 1:22 a.m. UTC
From: Libin Yang <libin.yang@linux.intel.com>

Jack is created based on pcm.

For dyn_pcm_assign:
 Driver will not use hda_jack. It will operate snd_jack directly.
 snd_jack pointer will be stored in spec->pcm.jack. When pcm is
 assigned to pin, jack will be assigned to pin automatically.
For !dyn_pcm_assign:
 Driver will continue using hda_jack for less impact on the old cases.
 Pcm is statically assigned to pin. So is jack. spec->pcm.jack will
 save the snd_jack pointer created in hda_jack.

Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
---
 sound/pci/hda/patch_hdmi.c | 96 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 67 insertions(+), 29 deletions(-)

Comments

Takashi Iwai Jan. 7, 2016, 2:13 p.m. UTC | #1
On Thu, 31 Dec 2015 02:22:21 +0100,
libin.yang@linux.intel.com wrote:
> 
> From: Libin Yang <libin.yang@linux.intel.com>
> 
> Jack is created based on pcm.
> 
> For dyn_pcm_assign:
>  Driver will not use hda_jack. It will operate snd_jack directly.

This is nothing new, it's already so for Intel codecs (via audio
component).

>  snd_jack pointer will be stored in spec->pcm.jack.

.... instead of the current spec->acomp_jack.


> When pcm is
>  assigned to pin, jack will be assigned to pin automatically.
> 
> For !dyn_pcm_assign:
>  Driver will continue using hda_jack for less impact on the old cases.
>  Pcm is statically assigned to pin. So is jack. spec->pcm.jack will
>  save the snd_jack pointer created in hda_jack.
> 
> Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
(snip)

> -static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
> +static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
>  {
>  	char hdmi_str[32] = "HDMI/DP";
>  	struct hdmi_spec *spec = codec->spec;
> -	struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> -	int pcmdev = get_pcm_rec(spec, pin_idx).pcm->device;
> +	struct hdmi_spec_per_pin *per_pin;
> +	struct hda_jack_tbl *jack;
> +	int pcmdev = get_pcm_rec(spec, pcm_idx).pcm->device;
>  	bool phantom_jack;
> +	int ret;
>  
>  	if (pcmdev > 0)
>  		sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
> -	if (codec_has_acomp(codec))
> -		return add_acomp_jack_kctl(codec, per_pin, hdmi_str);
> -	phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
> -	if (phantom_jack)
> -		strncat(hdmi_str, " Phantom",
> -			sizeof(hdmi_str) - strlen(hdmi_str) - 1);
>  
> -	return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
> -				     phantom_jack);
> +	/* for !dyn_pcm_assign, we still use hda_jack for compatibility */
> +	if (!spec->dyn_pcm_assign) {

Actually, the code changes become smaller with the following:

	if (spec->dyn_pcm_assign)
		return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);

Then the rest is almost same as the original code, and you'd need to
give a few more comments and assignment of pcm_rec[].jack in
addition.


> @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct hdmi_spec *spec)
>  static void generic_hdmi_free(struct hda_codec *codec)
>  {
>  	struct hdmi_spec *spec = codec->spec;
> -	int pin_idx;
> +	int pin_idx, pcm_idx;
>  
>  	if (codec_has_acomp(codec))
>  		snd_hdac_i915_register_notifier(NULL);
>  
>  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
>  		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> -
>  		cancel_delayed_work_sync(&per_pin->work);
>  		eld_proc_free(per_pin);
> -		if (per_pin->acomp_jack)
> -			snd_device_free(codec->card, per_pin->acomp_jack);
> +	}
> +
> +	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> +		if (spec->dyn_pcm_assign)
> +			snd_device_free(codec->card,
> +					spec->pcm_rec[pcm_idx].jack);
> +		else
> +			spec->pcm_rec[pcm_idx].jack = NULL;

Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.


Takashi
Yang, Libin Jan. 8, 2016, 3:15 a.m. UTC | #2
> -----Original Message-----
> From: Takashi Iwai [mailto:tiwai@suse.de]
> Sent: Thursday, January 07, 2016 10:14 PM
> To: libin.yang@linux.intel.com
> Cc: alsa-devel@alsa-project.org; Lin, Mengdong; Yang, Libin
> Subject: Re: [alsa-devel] [PATCH 3/4] ALSA: hda - hdmi jack created based
> on pcm
> 
> On Thu, 31 Dec 2015 02:22:21 +0100,
> libin.yang@linux.intel.com wrote:
> >
> > From: Libin Yang <libin.yang@linux.intel.com>
> >
> > Jack is created based on pcm.
> >
> > For dyn_pcm_assign:
> >  Driver will not use hda_jack. It will operate snd_jack directly.
> 
> This is nothing new, it's already so for Intel codecs (via audio
> component).

Yes. And I'm try to use this new method to all codecs as an option. :)

> 
> >  snd_jack pointer will be stored in spec->pcm.jack.
> 
> .... instead of the current spec->acomp_jack.
> 
> 
> > When pcm is
> >  assigned to pin, jack will be assigned to pin automatically.
> >
> > For !dyn_pcm_assign:
> >  Driver will continue using hda_jack for less impact on the old cases.
> >  Pcm is statically assigned to pin. So is jack. spec->pcm.jack will
> >  save the snd_jack pointer created in hda_jack.
> >
> > Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
> (snip)
> 
> > -static int generic_hdmi_build_jack(struct hda_codec *codec, int
> pin_idx)
> > +static int generic_hdmi_build_jack(struct hda_codec *codec, int
> pcm_idx)
> >  {
> >  	char hdmi_str[32] = "HDMI/DP";
> >  	struct hdmi_spec *spec = codec->spec;
> > -	struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> > -	int pcmdev = get_pcm_rec(spec, pin_idx).pcm->device;
> > +	struct hdmi_spec_per_pin *per_pin;
> > +	struct hda_jack_tbl *jack;
> > +	int pcmdev = get_pcm_rec(spec, pcm_idx).pcm->device;
> >  	bool phantom_jack;
> > +	int ret;
> >
> >  	if (pcmdev > 0)
> >  		sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d",
> pcmdev);
> > -	if (codec_has_acomp(codec))
> > -		return add_acomp_jack_kctl(codec, per_pin, hdmi_str);
> > -	phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
> > -	if (phantom_jack)
> > -		strncat(hdmi_str, " Phantom",
> > -			sizeof(hdmi_str) - strlen(hdmi_str) - 1);
> >
> > -	return snd_hda_jack_add_kctl(codec, per_pin->pin_nid,
> hdmi_str,
> > -				     phantom_jack);
> > +	/* for !dyn_pcm_assign, we still use hda_jack for compatibility */
> > +	if (!spec->dyn_pcm_assign) {
> 
> Actually, the code changes become smaller with the following:
> 
> 	if (spec->dyn_pcm_assign)
> 		return add_hdmi_jack_kctl(codec, spec, pcm_idx,
> hdmi_str);

OK, I will change it. Anyway, we need enable unsol_event here
if !acomp. 

> 
> Then the rest is almost same as the original code, and you'd need to
> give a few more comments and assignment of pcm_rec[].jack in
> addition.
> 
> 
> > @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct
> hdmi_spec *spec)
> >  static void generic_hdmi_free(struct hda_codec *codec)
> >  {
> >  	struct hdmi_spec *spec = codec->spec;
> > -	int pin_idx;
> > +	int pin_idx, pcm_idx;
> >
> >  	if (codec_has_acomp(codec))
> >  		snd_hdac_i915_register_notifier(NULL);
> >
> >  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> >  		struct hdmi_spec_per_pin *per_pin = get_pin(spec,
> pin_idx);
> > -
> >  		cancel_delayed_work_sync(&per_pin->work);
> >  		eld_proc_free(per_pin);
> > -		if (per_pin->acomp_jack)
> > -			snd_device_free(codec->card, per_pin-
> >acomp_jack);
> > +	}
> > +
> > +	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> > +		if (spec->dyn_pcm_assign)
> > +			snd_device_free(codec->card,
> > +					spec->pcm_rec[pcm_idx].jack);
> > +		else
> > +			spec->pcm_rec[pcm_idx].jack = NULL;
> 
> Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.
> 

Do you mean:
if (spec->pcm_rec[pcm_idx].jack)
    spec->pcm_rec[pcm_idx].jack = NULL;

Regards,
Libin
> 
> Takashi
Takashi Iwai Jan. 8, 2016, 7:43 a.m. UTC | #3
On Fri, 08 Jan 2016 04:15:03 +0100,
Yang, Libin wrote:
> > > @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct
> > hdmi_spec *spec)
> > >  static void generic_hdmi_free(struct hda_codec *codec)
> > >  {
> > >  	struct hdmi_spec *spec = codec->spec;
> > > -	int pin_idx;
> > > +	int pin_idx, pcm_idx;
> > >
> > >  	if (codec_has_acomp(codec))
> > >  		snd_hdac_i915_register_notifier(NULL);
> > >
> > >  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> > >  		struct hdmi_spec_per_pin *per_pin = get_pin(spec,
> > pin_idx);
> > > -
> > >  		cancel_delayed_work_sync(&per_pin->work);
> > >  		eld_proc_free(per_pin);
> > > -		if (per_pin->acomp_jack)
> > > -			snd_device_free(codec->card, per_pin-
> > >acomp_jack);
> > > +	}
> > > +
> > > +	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> > > +		if (spec->dyn_pcm_assign)
> > > +			snd_device_free(codec->card,
> > > +					spec->pcm_rec[pcm_idx].jack);
> > > +		else
> > > +			spec->pcm_rec[pcm_idx].jack = NULL;
> > 
> > Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.
> > 
> 
> Do you mean:
> if (spec->pcm_rec[pcm_idx].jack)
>     spec->pcm_rec[pcm_idx].jack = NULL;

Not only that.  Calling snd_device_free() with NULL isn't allowed.


Takashi
Yang, Libin Jan. 8, 2016, 7:52 a.m. UTC | #4
> -----Original Message-----
> From: Takashi Iwai [mailto:tiwai@suse.de]
> Sent: Friday, January 08, 2016 3:44 PM
> To: Yang, Libin
> Cc: libin.yang@linux.intel.com; alsa-devel@alsa-project.org; Lin,
> Mengdong
> Subject: Re: [alsa-devel] [PATCH 3/4] ALSA: hda - hdmi jack created based
> on pcm
> 
> On Fri, 08 Jan 2016 04:15:03 +0100,
> Yang, Libin wrote:
> > > > @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct
> > > hdmi_spec *spec)
> > > >  static void generic_hdmi_free(struct hda_codec *codec)
> > > >  {
> > > >  	struct hdmi_spec *spec = codec->spec;
> > > > -	int pin_idx;
> > > > +	int pin_idx, pcm_idx;
> > > >
> > > >  	if (codec_has_acomp(codec))
> > > >  		snd_hdac_i915_register_notifier(NULL);
> > > >
> > > >  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> > > >  		struct hdmi_spec_per_pin *per_pin = get_pin(spec,
> > > pin_idx);
> > > > -
> > > >  		cancel_delayed_work_sync(&per_pin->work);
> > > >  		eld_proc_free(per_pin);
> > > > -		if (per_pin->acomp_jack)
> > > > -			snd_device_free(codec->card, per_pin-
> > > >acomp_jack);
> > > > +	}
> > > > +
> > > > +	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> > > > +		if (spec->dyn_pcm_assign)
> > > > +			snd_device_free(codec->card,
> > > > +					spec->pcm_rec[pcm_idx].jack);
> > > > +		else
> > > > +			spec->pcm_rec[pcm_idx].jack = NULL;
> > >
> > > Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.
> > >
> >
> > Do you mean:
> > if (spec->pcm_rec[pcm_idx].jack)
> >     spec->pcm_rec[pcm_idx].jack = NULL;
> 
> Not only that.  Calling snd_device_free() with NULL isn't allowed.

I see. It will be:
+for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
+		if (spec->pcm_rec[pcm_idx].jack == NULL)
+			continue;
+		if (spec->dyn_pcm_assign)

BTW: It seems snd_device_free() will check the pointer.

Regards,
Libin

> Takashi
Takashi Iwai Jan. 8, 2016, 7:54 a.m. UTC | #5
On Fri, 08 Jan 2016 08:52:17 +0100,
Yang, Libin wrote:
> 
> 
> > -----Original Message-----
> > From: Takashi Iwai [mailto:tiwai@suse.de]
> > Sent: Friday, January 08, 2016 3:44 PM
> > To: Yang, Libin
> > Cc: libin.yang@linux.intel.com; alsa-devel@alsa-project.org; Lin,
> > Mengdong
> > Subject: Re: [alsa-devel] [PATCH 3/4] ALSA: hda - hdmi jack created based
> > on pcm
> > 
> > On Fri, 08 Jan 2016 04:15:03 +0100,
> > Yang, Libin wrote:
> > > > > @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct
> > > > hdmi_spec *spec)
> > > > >  static void generic_hdmi_free(struct hda_codec *codec)
> > > > >  {
> > > > >  	struct hdmi_spec *spec = codec->spec;
> > > > > -	int pin_idx;
> > > > > +	int pin_idx, pcm_idx;
> > > > >
> > > > >  	if (codec_has_acomp(codec))
> > > > >  		snd_hdac_i915_register_notifier(NULL);
> > > > >
> > > > >  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> > > > >  		struct hdmi_spec_per_pin *per_pin = get_pin(spec,
> > > > pin_idx);
> > > > > -
> > > > >  		cancel_delayed_work_sync(&per_pin->work);
> > > > >  		eld_proc_free(per_pin);
> > > > > -		if (per_pin->acomp_jack)
> > > > > -			snd_device_free(codec->card, per_pin-
> > > > >acomp_jack);
> > > > > +	}
> > > > > +
> > > > > +	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> > > > > +		if (spec->dyn_pcm_assign)
> > > > > +			snd_device_free(codec->card,
> > > > > +					spec->pcm_rec[pcm_idx].jack);
> > > > > +		else
> > > > > +			spec->pcm_rec[pcm_idx].jack = NULL;
> > > >
> > > > Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.
> > > >
> > >
> > > Do you mean:
> > > if (spec->pcm_rec[pcm_idx].jack)
> > >     spec->pcm_rec[pcm_idx].jack = NULL;
> > 
> > Not only that.  Calling snd_device_free() with NULL isn't allowed.
> 
> I see. It will be:
> +for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> +		if (spec->pcm_rec[pcm_idx].jack == NULL)
> +			continue;
> +		if (spec->dyn_pcm_assign)
> 
> BTW: It seems snd_device_free() will check the pointer.

Yes but with snd_BUG_ON(), i.e. with a warning.  It shouldn't be
called with NULL.


Takashi
Yang, Libin Jan. 8, 2016, 7:57 a.m. UTC | #6
> -----Original Message-----
> From: Takashi Iwai [mailto:tiwai@suse.de]
> Sent: Friday, January 08, 2016 3:55 PM
> To: Yang, Libin
> Cc: libin.yang@linux.intel.com; alsa-devel@alsa-project.org; Lin,
> Mengdong
> Subject: Re: [alsa-devel] [PATCH 3/4] ALSA: hda - hdmi jack created based
> on pcm
> 
> On Fri, 08 Jan 2016 08:52:17 +0100,
> Yang, Libin wrote:
> >
> >
> > > -----Original Message-----
> > > From: Takashi Iwai [mailto:tiwai@suse.de]
> > > Sent: Friday, January 08, 2016 3:44 PM
> > > To: Yang, Libin
> > > Cc: libin.yang@linux.intel.com; alsa-devel@alsa-project.org; Lin,
> > > Mengdong
> > > Subject: Re: [alsa-devel] [PATCH 3/4] ALSA: hda - hdmi jack created
> based
> > > on pcm
> > >
> > > On Fri, 08 Jan 2016 04:15:03 +0100,
> > > Yang, Libin wrote:
> > > > > > @@ -2626,18 +2659,23 @@ static void hdmi_array_free(struct
> > > > > hdmi_spec *spec)
> > > > > >  static void generic_hdmi_free(struct hda_codec *codec)
> > > > > >  {
> > > > > >  	struct hdmi_spec *spec = codec->spec;
> > > > > > -	int pin_idx;
> > > > > > +	int pin_idx, pcm_idx;
> > > > > >
> > > > > >  	if (codec_has_acomp(codec))
> > > > > >  		snd_hdac_i915_register_notifier(NULL);
> > > > > >
> > > > > >  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> > > > > >  		struct hdmi_spec_per_pin *per_pin =
> get_pin(spec,
> > > > > pin_idx);
> > > > > > -
> > > > > >  		cancel_delayed_work_sync(&per_pin->work);
> > > > > >  		eld_proc_free(per_pin);
> > > > > > -		if (per_pin->acomp_jack)
> > > > > > -			snd_device_free(codec->card, per_pin-
> > > > > >acomp_jack);
> > > > > > +	}
> > > > > > +
> > > > > > +	for (pcm_idx = 0; pcm_idx < spec->pcm_used;
> pcm_idx++) {
> > > > > > +		if (spec->dyn_pcm_assign)
> > > > > > +			snd_device_free(codec->card,
> > > > > > +					spec-
> >pcm_rec[pcm_idx].jack);
> > > > > > +		else
> > > > > > +			spec->pcm_rec[pcm_idx].jack = NULL;
> > > > >
> > > > > Check whether spec->pcm_rec[pcm_idx].jack is NULL beforehand.
> > > > >
> > > >
> > > > Do you mean:
> > > > if (spec->pcm_rec[pcm_idx].jack)
> > > >     spec->pcm_rec[pcm_idx].jack = NULL;
> > >
> > > Not only that.  Calling snd_device_free() with NULL isn't allowed.
> >
> > I see. It will be:
> > +for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
> > +		if (spec->pcm_rec[pcm_idx].jack == NULL)
> > +			continue;
> > +		if (spec->dyn_pcm_assign)
> >
> > BTW: It seems snd_device_free() will check the pointer.
> 
> Yes but with snd_BUG_ON(), i.e. with a warning.  It shouldn't be
> called with NULL.

Get it :-)

Regards,
Libin

> 
> 
> Takashi
diff mbox

Patch

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 5549ddf..356ae04 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -85,7 +85,6 @@  struct hdmi_spec_per_pin {
 	struct mutex lock;
 	struct delayed_work work;
 	struct snd_kcontrol *eld_ctl;
-	struct snd_jack *acomp_jack; /* jack via audio component */
 	struct hdmi_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;
@@ -1943,6 +1942,7 @@  static void sync_eld_via_acomp(struct hda_codec *codec,
 {
 	struct hdmi_spec *spec = codec->spec;
 	struct hdmi_eld *eld = &spec->temp_eld;
+	struct snd_jack *jack = NULL;
 	int size;
 
 	mutex_lock(&per_pin->lock);
@@ -1966,8 +1966,18 @@  static void sync_eld_via_acomp(struct hda_codec *codec,
 		eld->eld_size = 0;
 	}
 
+	/* pcm_idx >=0 before update_eld() means it is in monitor
+	 * disconnected event. Jack must be fetched before update_eld()
+	 * Get jack before update_eld()
+	 */
+	if (per_pin->pcm_idx >= 0)
+		jack = spec->pcm_rec[per_pin->pcm_idx].jack;
 	update_eld(codec, per_pin, eld);
-	snd_jack_report(per_pin->acomp_jack,
+	if (jack == NULL && per_pin->pcm_idx >= 0)
+		jack = spec->pcm_rec[per_pin->pcm_idx].jack;
+	if (jack == NULL)
+		goto unlock;
+	snd_jack_report(jack,
 			eld->monitor_present ? SND_JACK_AVOUT : 0);
  unlock:
 	mutex_unlock(&per_pin->lock);
@@ -2471,15 +2481,16 @@  static int generic_hdmi_build_pcms(struct hda_codec *codec)
 	return 0;
 }
 
-static void free_acomp_jack_priv(struct snd_jack *jack)
+static void free_hdmi_jack_priv(struct snd_jack *jack)
 {
-	struct hdmi_spec_per_pin *per_pin = jack->private_data;
+	struct hdmi_pcm *pcm = jack->private_data;
 
-	per_pin->acomp_jack = NULL;
+	pcm->jack = NULL;
 }
 
-static int add_acomp_jack_kctl(struct hda_codec *codec,
-			       struct hdmi_spec_per_pin *per_pin,
+static int add_hdmi_jack_kctl(struct hda_codec *codec,
+			       struct hdmi_spec *spec,
+			       int pcm_idx,
 			       const char *name)
 {
 	struct snd_jack *jack;
@@ -2489,45 +2500,67 @@  static int add_acomp_jack_kctl(struct hda_codec *codec,
 			   true, false);
 	if (err < 0)
 		return err;
-	per_pin->acomp_jack = jack;
-	jack->private_data = per_pin;
-	jack->private_free = free_acomp_jack_priv;
+
+	spec->pcm_rec[pcm_idx].jack = jack;
+	jack->private_data = &spec->pcm_rec[pcm_idx];
+	jack->private_free = free_hdmi_jack_priv;
 	return 0;
 }
 
-static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
+static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
 {
 	char hdmi_str[32] = "HDMI/DP";
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
-	int pcmdev = get_pcm_rec(spec, pin_idx).pcm->device;
+	struct hdmi_spec_per_pin *per_pin;
+	struct hda_jack_tbl *jack;
+	int pcmdev = get_pcm_rec(spec, pcm_idx).pcm->device;
 	bool phantom_jack;
+	int ret;
 
 	if (pcmdev > 0)
 		sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
-	if (codec_has_acomp(codec))
-		return add_acomp_jack_kctl(codec, per_pin, hdmi_str);
-	phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
-	if (phantom_jack)
-		strncat(hdmi_str, " Phantom",
-			sizeof(hdmi_str) - strlen(hdmi_str) - 1);
 
-	return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
-				     phantom_jack);
+	/* for !dyn_pcm_assign, we still use hda_jack for compatibility */
+	if (!spec->dyn_pcm_assign) {
+		/* if not dyn_pcm_assign, it must be non-MST mode.
+		 * This means pcms and pins are statically mapped.
+		 * And pcm_idx is pin_idx.
+		 */
+		per_pin = get_pin(spec, pcm_idx);
+		phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
+		if (phantom_jack)
+			strncat(hdmi_str, " Phantom",
+				sizeof(hdmi_str) - strlen(hdmi_str) - 1);
+		ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
+					    phantom_jack);
+		if (ret < 0)
+			return ret;
+		jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
+		if (jack == NULL)
+			return 0;
+		/* statically bind jack */
+		spec->pcm_rec[pcm_idx].jack = jack->jack;
+		return 0;
+	}
+
+	return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
 }
 
 static int generic_hdmi_build_controls(struct hda_codec *codec)
 {
 	struct hdmi_spec *spec = codec->spec;
 	int err;
-	int pin_idx;
+	int pin_idx, pcm_idx;
 
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
 
-		err = generic_hdmi_build_jack(codec, pin_idx);
+	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
+		err = generic_hdmi_build_jack(codec, pcm_idx);
 		if (err < 0)
 			return err;
+	}
+
+	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
+		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
 
 		err = snd_hda_create_dig_out_ctls(codec,
 						  per_pin->pin_nid,
@@ -2626,18 +2659,23 @@  static void hdmi_array_free(struct hdmi_spec *spec)
 static void generic_hdmi_free(struct hda_codec *codec)
 {
 	struct hdmi_spec *spec = codec->spec;
-	int pin_idx;
+	int pin_idx, pcm_idx;
 
 	if (codec_has_acomp(codec))
 		snd_hdac_i915_register_notifier(NULL);
 
 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
 		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
-
 		cancel_delayed_work_sync(&per_pin->work);
 		eld_proc_free(per_pin);
-		if (per_pin->acomp_jack)
-			snd_device_free(codec->card, per_pin->acomp_jack);
+	}
+
+	for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
+		if (spec->dyn_pcm_assign)
+			snd_device_free(codec->card,
+					spec->pcm_rec[pcm_idx].jack);
+		else
+			spec->pcm_rec[pcm_idx].jack = NULL;
 	}
 
 	if (spec->i915_bound)