From patchwork Tue Sep 20 13:46:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeeja KP X-Patchwork-Id: 9342253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C609607EE for ; Tue, 20 Sep 2016 18:20:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 219E9299B9 for ; Tue, 20 Sep 2016 18:20:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13CFF29A8F; Tue, 20 Sep 2016 18:20:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 403BC299B9 for ; Tue, 20 Sep 2016 18:20:07 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E46CE266DE5; Tue, 20 Sep 2016 20:20:05 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 89927266D9C; Tue, 20 Sep 2016 20:17:41 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 7F89C266D1B; Tue, 20 Sep 2016 15:38:16 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by alsa0.perex.cz (Postfix) with ESMTP id ED5922666AA for ; Tue, 20 Sep 2016 15:38:11 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 20 Sep 2016 06:38:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,368,1470726000"; d="scan'208";a="763719740" Received: from kpjeeja-desk.iind.intel.com ([10.223.96.110]) by FMSMGA003.fm.intel.com with ESMTP; 20 Sep 2016 06:38:10 -0700 From: jeeja.kp@intel.com To: alsa-devel@alsa-project.org Date: Tue, 20 Sep 2016 19:16:14 +0530 Message-Id: <1474379180-7132-11-git-send-email-jeeja.kp@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1474379180-7132-1-git-send-email-jeeja.kp@intel.com> References: <1474379180-7132-1-git-send-email-jeeja.kp@intel.com> Cc: tiwai@suse.de, patches.audio@intel.com, broonie@kernel.org, liam.r.girdwood@intel.com, Jeeja KP Subject: [alsa-devel] [RFC 10/16] ASoc: hdac_hdmi: Configure pin verbs for MST X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeeja KP To enable stream on to specific port which is MST capable pin, before configuring the pin widget verb, Port need to be selected. When Port is selected, all the Pin widget verb controlling the sink device operation will be directed to selected port. So add port selection before configuring the pin widget verb. Since the port select can change between pcm, need to protect the selection of port and the configuration of pin widget verb. So moved the port lock to pcm lock. Signed-off-by: Jeeja KP --- sound/soc/codecs/hdac_hdmi.c | 80 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index d99eb9c..618af31 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c @@ -93,7 +93,6 @@ struct hdac_hdmi_port { int num_mux_nids; hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; struct hdac_hdmi_eld eld; - struct mutex lock; bool chmap_set; unsigned char chmap[8]; /* ALSA API channel-map */ int channels; /* current number of channels */ @@ -101,6 +100,7 @@ struct hdac_hdmi_port { struct hdac_hdmi_pcm { struct list_head head; + struct mutex lock; int pcm_id; struct hdac_hdmi_port *port; struct hdac_hdmi_cvt *cvt; @@ -125,6 +125,20 @@ struct hdac_hdmi_priv { struct hdac_chmap chmap; }; +static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm_from_cvt( + struct hdac_hdmi_priv *hdmi, + struct hdac_hdmi_cvt *cvt) +{ + struct hdac_hdmi_pcm *pcm = NULL; + + list_for_each_entry(pcm, &hdmi->pcm_list, head) { + if (pcm->cvt == cvt) + break; + } + + return pcm; +} + /* MST supported verbs */ /* * Get the no devices that can be connected to a port on the Pin widget. @@ -323,6 +337,9 @@ static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *hdac, break; } + if (hdac_hdmi_port_select_set(hdac, port) < 0) + return -EIO; + ca = snd_hdac_channel_allocation(&hdac->hdac, port->eld.info.spk_alloc, port->channels, port->chmap_set, true, port->chmap); @@ -416,6 +433,7 @@ static int hdac_hdmi_playback_prepare(struct snd_pcm_substream *substream, struct hdac_hdmi_priv *hdmi = hdac->private_data; struct hdac_hdmi_dai_port_map *dai_map; struct hdac_hdmi_port *port; + struct hdac_hdmi_pcm *pcm; struct hdac_ext_dma_params *dd; int ret; @@ -427,16 +445,21 @@ static int hdac_hdmi_playback_prepare(struct snd_pcm_substream *substream, dd->stream_tag, dd->format); hdac_hdmi_enable_cvt(hdac, dai_map); + pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt); + + if (!pcm) + return -EIO; + + mutex_lock(&pcm->lock); ret = hdac_hdmi_enable_pin(hdac, dai_map); if (ret < 0) return ret; - mutex_lock(&port->lock); port->channels = substream->runtime->channels; ret = hdac_hdmi_setup_audio_infoframe(hdac, dai_map->cvt->nid, port->pin->nid, port); - mutex_unlock(&port->lock); + mutex_unlock(&pcm->lock); if (ret < 0) return ret; @@ -520,6 +543,10 @@ static int hdac_hdmi_enable_pin(struct hdac_ext_device *hdac, int mux_idx; struct hdac_hdmi_port *port = dai_map->port; + /* set the device if pin is mst_capable */ + if (hdac_hdmi_port_select_set(hdac, port) < 0) + return -EIO; + for (mux_idx = 0; mux_idx < port->num_mux_nids; mux_idx++) { if (port->mux_nids[mux_idx] == dai_map->cvt->nid) { snd_hdac_codec_write(&hdac->hdac, port->pin->nid, 0, @@ -547,6 +574,11 @@ static int hdac_hdmi_query_port_connlist(struct hdac_ext_device *hdac, struct hdac_hdmi_pin *pin, struct hdac_hdmi_port *port) { + + /* set the device if pin is mst_capable */ + if (hdac_hdmi_port_select_set(hdac, port) < 0) + return -EIO; + if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) { dev_warn(&hdac->hdac.dev, "HDMI: pin %d wcaps %#x does not support connection list\n", @@ -593,7 +625,10 @@ static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt( } if (port) { + mutex_lock(&pcm->lock); ret = hdac_hdmi_query_port_connlist(edev, port->pin, port); + mutex_unlock(&pcm->lock); + if (ret < 0) return NULL; @@ -681,25 +716,32 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream, struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); struct hdac_hdmi_priv *hdmi = hdac->private_data; struct hdac_hdmi_dai_port_map *dai_map; + struct hdac_hdmi_port *port; + struct hdac_hdmi_pcm *pcm; dai_map = &hdmi->dai_map[dai->id]; - if (dai_map->port) { + pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt); + + if (dai_map->port && pcm) { + port = dai_map->port; snd_hdac_codec_write(&hdac->hdac, dai_map->cvt->nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); snd_hdac_codec_write(&hdac->hdac, dai_map->cvt->nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); - hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D3); - - snd_hdac_codec_write(&hdac->hdac, dai_map->port->pin->nid, 0, - AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); + mutex_lock(&pcm->lock); + /* set the device if pin is mst_capable */ + if (!hdac_hdmi_port_select_set(hdac, port)) { + hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D3); - mutex_lock(&dai_map->port->lock); + snd_hdac_codec_write(&hdac->hdac, dai_map->port->pin->nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); + } dai_map->port->chmap_set = false; memset(dai_map->port->chmap, 0, sizeof(dai_map->port->chmap)); dai_map->port->channels = 0; - mutex_unlock(&dai_map->port->lock); + mutex_unlock(&pcm->lock); dai_map->port = NULL; } @@ -1209,7 +1251,6 @@ static int hdac_hdmi_add_ports(struct hdac_hdmi_priv *hdmi, for (i=0; i < max_ports; i++) { ports[i].id = i + 1; ports[i].pin = pin; - mutex_init(&ports[i].lock); } pin->ports = ports; pin->num_ports = max_ports; @@ -1510,6 +1551,7 @@ int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device) return -ENOMEM; pcm->pcm_id = device; pcm->cvt = hdmi->dai_map[dai->id].cvt; + mutex_init(&pcm->lock); snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device); if (snd_pcm) { @@ -1676,13 +1718,15 @@ static void hdac_hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, struct hdac_hdmi_port *port = pcm->port; struct hdac_hdmi_pin *pin = port->pin; - mutex_lock(&port->lock); - port->chmap_set = true; - memcpy(port->chmap, chmap, ARRAY_SIZE(port->chmap)); - if (prepared) - hdac_hdmi_setup_audio_infoframe(edev, pcm->cvt->nid, - pin->nid, port); - mutex_unlock(&port->lock); + if (pcm) { + mutex_lock(&pcm->lock); + port->chmap_set = true; + memcpy(port->chmap, chmap, ARRAY_SIZE(port->chmap)); + if (prepared) + hdac_hdmi_setup_audio_infoframe(edev, pcm->cvt->nid, + pin->nid, port); + mutex_unlock(&pcm->lock); + } } static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)