All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Yang, Libin" <libin.yang@intel.com>
Cc: "Lin, Mengdong" <mengdong.lin@intel.com>,
	"libin.yang@linux.intel.com" <libin.yang@linux.intel.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Re: [RFC PATCH v3 2/3] ALSA: hda - add DP mst audio support
Date: Fri, 21 Oct 2016 10:43:43 +0200	[thread overview]
Message-ID: <s5hfunqgkhs.wl-tiwai@suse.de> (raw)
In-Reply-To: <96A12704CE18D347B625EE2D4A099D194FA4A381@SHSMSX103.ccr.corp.intel.com>

On Fri, 21 Oct 2016 10:24:26 +0200,
Yang, Libin wrote:
> 
> Hi Takashi,
> 
> 
> > -----Original Message-----
> > From: Takashi Iwai [mailto:tiwai@suse.de]
> > Sent: Thursday, October 20, 2016 11:34 PM
> > To: libin.yang@linux.intel.com
> > Cc: alsa-devel@alsa-project.org; Yang, Libin <libin.yang@intel.com>; Lin,
> > Mengdong <mengdong.lin@intel.com>
> > Subject: Re: [alsa-devel] [RFC PATCH v3 2/3] ALSA: hda - add DP mst audio
> > support
> > 
> > On Thu, 13 Oct 2016 09:49:36 +0200,
> > libin.yang@linux.intel.com wrote:
> > >
> > > From: Libin Yang <libin.yang@linux.intel.com>
> > >
> > > This patch adds the DP mst audio support.
> > 
> > A bit more useful texts here please.  I know you'll give more explanations in
> > the document in the later patch, but still something better should be
> > mentioned here.
> 
> Yes, I will add more description here.
> 
> > 
> > >
> > > Signed-off-by: Libin Yang <libin.yang@linux.intel.com>
> > > ---
> > >  sound/pci/hda/hda_codec.c  |   4 +
> > >  sound/pci/hda/patch_hdmi.c | 243
> > > +++++++++++++++++++++++++++++++++++----------
> > >  2 files changed, 196 insertions(+), 51 deletions(-)
> > >
> > > diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
> > > index caa2c9d..8a6b0a2 100644
> > > --- a/sound/pci/hda/hda_codec.c
> > > +++ b/sound/pci/hda/hda_codec.c
> > > @@ -468,6 +468,10 @@ static int read_pin_defaults(struct hda_codec
> > *codec)
> > >  		pin->nid = nid;
> 
> ... 
> 
> > > +
> > >
> > >  		/* choose an unassigned converter. The conveters in the
> > >  		 * 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,
> > >  				break;
> > >  			}
> > >  		}
> > > +		snd_hda_set_dev_select(codec, nid, dev_id_saved);
> > 
> > I guess this revert won't be reached when you break or continue the loop
> > beforehand?
> 
> To make it easier to explain, please let me attach the full patched code here:
> 
> for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
> 		int dev_id_saved;
> 		int dev_num;
> 
> 		per_pin = get_pin(spec, pin_idx);
> 		/*
> 		 * pin not connected to monitor
> 		 * no need to operate on it
> 		 */
> 		if (!per_pin->pcm)
> 			continue;
> 
> 		if ((per_pin->pin_nid == pin_nid) &&
> 			(per_pin->dev_id == dev_id))
> 			continue;
> 
> 		/*
> 		 * if per_pin->dev_id >= dev_num,
> 		 * snd_hda_get_dev_select() will fail,
> 		 * and the following operation is unpredictable.
> 		 * So skip this situation.
> 		 */
> 		dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
> 		if (per_pin->dev_id >= dev_num)
> 			continue;
> 
> 		nid = per_pin->pin_nid;
> 
> 		/*
> 		 * Calling this function should not impact
> 		 * on the device entry selection
> 		 * So let's save the dev id for each pin,
> 		 * and restore it when return
> 		 */
> 		dev_id_saved = snd_hda_get_dev_select(codec, nid);
> tag 1		snd_hda_set_dev_select(codec, nid, per_pin->dev_id); 
> 		curr = snd_hda_codec_read(codec, nid, 0,
> 					  AC_VERB_GET_CONNECT_SEL, 0);
> 		if (curr != mux_idx) {
> tag 2			snd_hda_set_dev_select(codec, nid, dev_id_saved);
> 			continue;
> 		}
> 
> 
> 		/* choose an unassigned converter. The conveters in the
> 		 * connection list are in the same order as in the codec.
> 		 */
> 		for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
> 			per_cvt = get_cvt(spec, cvt_idx);
> 			if (!per_cvt->assigned) {
> 				codec_dbg(codec,
> 					  "choose cvt %d for pin nid %d\n",
> 					cvt_idx, nid);
> 				snd_hda_codec_write_cache(codec, nid, 0,
> 					    AC_VERB_SET_CONNECT_SEL,
> 					    cvt_idx);
> tag 3				break;
> 			}
> 		}
> 		snd_hda_set_dev_select(codec, nid, dev_id_saved);
> 	}
> 
> We need revert dev_id only after we change the dev_id setting before.
> This is done by: snd_hda_set_dev_select(codec, nid, per_pn->dev_id) (tag1)
> There is one "continue" and we have reverted dev_id before continue (tag 2)
> There is one "break" (tag 3). However, this is for another for loop.

OK, fair enough.


> > Also, this rewrite changes the loop completely, so we you should update the
> > comment appropriately.  It's no longer scanning the all pins (including
> > unused ones).  And I'm not 100% sure whether it's OK to change in that way;
> > the function was written to do that (touching the unused pin as well) on
> > purpose, IIRC.
> > 
> > Hm, or is it OK because we are listing always the three pins?
> > More explanation please, either in comments or in the changelog.
> > 
> 
> This function is a little complex now. Please let me explain it in detail.
> 
> As you know, we need this function because we need fix: same cvt is
> connecting to several pins. In this situation, playback on one pin will also
> impact on other pins. Let's assume cvt 1 are connecting to pin 1, 2, 3.
> When we playback on pin1, we need call this function to make sure
> pin 2, 3 is connected to other cvts.
> 
> In MST mode,  we are using dynamic pcm. If no pcm is attached to
> the pin, it means there is no monitor connected to the pin. So we
> don't need to set the cvt. Let's still assume the cvt 1 are connecting to 
> pin 1, 2, 3, 4, 5, 6, 7, 8, 9 (here pin is the virtual pin).
> 
> Let's assume playback on pin 1 (which is connected to cvt 1). 
> So we should make sure all others pins are not connected to cvt1.
> 
> 1) For other pins:
>     if (!per_pin->pcm)
>         continue;
> This means no monitors is connected to the pin. So we don't care
> the cvt connection because the pin doesn't output sound to monitor.
> (when the virtual pin is connected to monitor later, this function will
> be called in present_sense(), which will make sure the cvt connected
> to the virtual pin is different from the cvt connected to pin 1)
> 
> 2) For the following situation:
>     dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
>         if (per_pin->dev_id >= dev_num)
>             continue;
> The per_pin->dev_id is greater than dev_num. This means no such
> virtual pin. We should skip this situation.
> 
> 3) For the following situation:
>     if (curr != mux_idx) {
>         snd_hda_set_dev_select(codec, nid, dev_id_saved);
>         continue;
>     }
> It means the cvt connected to the virtual pin is already different to 
> the cvt connected to the pin 1. So we don't need to do anything. 
> 
> 4) Otherwise (the cvt is the same to pin 1), we need change the cvt.
> 
> I will add more description for this function in the next version patch.

One thing that is still unclear to me is how to deal with the
unconfigured pins.  I thought that the pins with port=non pincfg are
still ignored in hdmi_add_pin() even after your patch.  So they won't
be listed in the pins / nids arrays.

Now, your new code only loops over the enumerated pins, i.e. these
unconfigured pins are ignored.  What if these pins are connected to
the active converters?  I thought excluding such a connection is one
of the purposes of this function, judging from the function
description.


thanks,

Takashi

  reply	other threads:[~2016-10-21  8:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-13  7:49 [RFC PATCH v3 0/3] support DP MST audio libin.yang
2016-10-13  7:49 ` [RFC PATCH v3 1/3] ALSA: hda - add DP mst verb support libin.yang
2016-10-20 15:27   ` Takashi Iwai
2016-10-21  6:52     ` Yang, Libin
2016-10-13  7:49 ` [RFC PATCH v3 2/3] ALSA: hda - add DP mst audio support libin.yang
2016-10-20 15:34   ` Takashi Iwai
2016-10-21  8:24     ` Yang, Libin
2016-10-21  8:43       ` Takashi Iwai [this message]
2016-10-21  8:56         ` Yang, Libin
2016-10-21  9:05           ` Takashi Iwai
2016-10-21 12:25             ` Yang, Libin
2016-10-21 12:33               ` Takashi Iwai
2016-10-21 13:25                 ` Yang, Libin
2016-10-24  7:09                 ` Yang, Libin
2016-10-24  8:41                   ` Takashi Iwai
2016-10-24  8:52                     ` Yang, Libin
2016-10-13  7:49 ` [RFC PATCH v3 3/3] ALSA: Documentation about HDA DP MST pin init and connection libin.yang
2016-10-20  7:23 ` [RFC PATCH v3 0/3] support DP MST audio Yang, Libin
2016-10-20  8:46   ` Takashi Iwai

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=s5hfunqgkhs.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=libin.yang@intel.com \
    --cc=libin.yang@linux.intel.com \
    --cc=mengdong.lin@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.