From patchwork Fri Mar 22 06:24:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang, Libin" X-Patchwork-Id: 10865051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA581922 for ; Fri, 22 Mar 2019 07:00:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96B6B2A2F4 for ; Fri, 22 Mar 2019 07:00:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86DAA2A2FD; Fri, 22 Mar 2019 07:00:58 +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=-2.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RDNS_NONE autolearn=no version=3.3.1 Received: from alsa0.perex.cz (unknown [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6FD3F2A2F4 for ; Fri, 22 Mar 2019 07:00:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A606E15D7; Fri, 22 Mar 2019 07:41:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A606E15D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1553236939; bh=BiIz8WXpRQlQZcrZx4sduAR2B0TK9fQQ8TJ5ombeVE0=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=a9s6/OCc6/f9LS5AemwHyt7XAuT3aVlnUu6wUMT3RHhF23rHvJ3mQs1rkqiyM8xRA Xa59eHHEUFo+VxwGEc1KGxNnC9fuTdlBPpIP1j7I/cWLzgyXa+1SwtDwY0dtmomdxP +y2Pa/llYye0lbMi06LLY9ZyGZxk1biiLSC4+KPA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 270EDF89674; Fri, 22 Mar 2019 07:41:29 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 807AFF89678; Fri, 22 Mar 2019 07:41:27 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8775EF8076F for ; Fri, 22 Mar 2019 07:41:21 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8775EF8076F X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Mar 2019 23:41:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,255,1549958400"; d="scan'208";a="127622400" Received: from younglee-svr.sh.intel.com ([10.239.159.31]) by orsmga008.jf.intel.com with ESMTP; 21 Mar 2019 23:41:18 -0700 From: libin.yang@intel.com To: alsa-devel@alsa-project.org, broonie@kernel.org Date: Fri, 22 Mar 2019 14:24:56 +0800 Message-Id: <1553235896-8185-1-git-send-email-libin.yang@intel.com> X-Mailer: git-send-email 2.7.4 Cc: libin.yang@intel.com Subject: [alsa-devel] [PATCH V2] ASoC: fix hdmi codec driver contest in S3 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Libin Yang In S3, there is a contest between dapm event and getting display power. When resume, the sequence is: hdac_hdmi_runtime_resume() => snd_hdac_display_power() hdac_hdmi_xxx_widget_event() The hdac_hdmi_xxx_widget_event() are based on the power being on. Otherwise, the operation on the codec register will fail. However, in snd_hdac_display_power(), it may sleep because of the mutex_lock() in display driver. In this case, hdac_hdmi_xxx_widget_event() will be called before the power is on. Let's not operate the registers and wait for the power in hdac_hdmi_xxx_widget_event() Signed-off-by: Libin Yang --- sound/soc/codecs/hdac_hdmi.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index 5eeb0fe..3c5c122 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c @@ -144,6 +144,7 @@ struct hdac_hdmi_priv { int num_pin; int num_cvt; int num_ports; + int display_power; /* 0: power off; 1 power on */ struct mutex pin_mutex; struct hdac_chmap chmap; struct hdac_hdmi_drv_data *drv_data; @@ -742,12 +743,27 @@ static void hdac_hdmi_set_amp(struct hdac_device *hdev, AC_VERB_SET_AMP_GAIN_MUTE, val); } +static int wait_for_display_power(struct hdac_hdmi_priv *hdmi) +{ + int i = 0; + + /* sleep for totally 80ms ~ 200ms should be enough */ + while (i < 40) { + if (!hdmi->display_power) + usleep_range(2000, 5000); + else + return 0; + i++; + } + return -EAGAIN; +} static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kc, int event) { struct hdac_hdmi_port *port = w->priv; struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev); + struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev); struct hdac_hdmi_pcm *pcm; dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n", @@ -757,6 +773,11 @@ static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w, if (!pcm) return -EIO; + if (wait_for_display_power(hdmi)) { + dev_err(&hdev->dev, "%s: hdmi power is not ready\n", __func__); + return -EAGAIN; + } + /* set the device if pin is mst_capable */ if (hdac_hdmi_port_select_set(hdev, port) < 0) return -EIO; @@ -803,6 +824,11 @@ static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w, if (!pcm) return -EIO; + if (wait_for_display_power(hdmi)) { + dev_err(&hdev->dev, "%s: hdmi power is not ready\n", __func__); + return -EAGAIN; + } + switch (event) { case SND_SOC_DAPM_PRE_PMU: hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0); @@ -840,6 +866,7 @@ static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w, { struct hdac_hdmi_port *port = w->priv; struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev); + struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev); int mux_idx; dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n", @@ -850,6 +877,11 @@ static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w, mux_idx = dapm_kcontrol_get_value(kc); + if (wait_for_display_power(hdmi)) { + dev_err(&hdev->dev, "%s: hdmi power is not ready\n", __func__); + return -EAGAIN; + } + /* set the device if pin is mst_capable */ if (hdac_hdmi_port_select_set(hdev, port) < 0) return -EIO; @@ -2068,6 +2100,7 @@ static int hdac_hdmi_runtime_suspend(struct device *dev) { struct hdac_device *hdev = dev_to_hdac_dev(dev); struct hdac_bus *bus = hdev->bus; + struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev); struct hdac_ext_link *hlink = NULL; dev_dbg(dev, "Enter: %s\n", __func__); @@ -2095,6 +2128,7 @@ static int hdac_hdmi_runtime_suspend(struct device *dev) snd_hdac_ext_bus_link_put(bus, hlink); snd_hdac_display_power(bus, hdev->addr, false); + hdmi->display_power = 0; return 0; } @@ -2102,6 +2136,7 @@ static int hdac_hdmi_runtime_suspend(struct device *dev) static int hdac_hdmi_runtime_resume(struct device *dev) { struct hdac_device *hdev = dev_to_hdac_dev(dev); + struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev); struct hdac_bus *bus = hdev->bus; struct hdac_ext_link *hlink = NULL; @@ -2128,6 +2163,7 @@ static int hdac_hdmi_runtime_resume(struct device *dev) snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0); + hdmi->display_power = 1; return 0; } #else