Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1801494ybh; Tue, 14 Jul 2020 07:42:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNLQOOngJCy38KvQrWPa+8auFhNxi5RyW4UPgcCjI66PXsehhBEzYZNht/11TgTjjAfpEq X-Received: by 2002:a17:906:a058:: with SMTP id bg24mr5027190ejb.370.1594737778222; Tue, 14 Jul 2020 07:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594737778; cv=none; d=google.com; s=arc-20160816; b=bGXzRzC5Lx1iEdQ+U26mKDutRrGKCC4CVfPl4UC+5DmoKKmuw+5GiTyuW/i5+8Lk7E 5SgCGDkEod8iGQYWQX1RvWyQ94JNaqj4sNBbb+D8JdnXVt+WK+pzGpAzobYO9WLDKM6H k1ALRTrGagWyStc3jOof59ePK8kUbn7H314EsqXn62uLsM+kX9MQzFxphzw+7U5nNUBG pNiOfpy5HjusYl02/t+AIBP4zC39w8Ah4DofKN3Ahw1nTmKSEFWVp2+1j+IzfZfWx5Rj KJpcay5G3oASqh0mkJarcQtH1mrQHM9r2rXsYjvAhu00sy2juJWyCzZZkny87nFOj6yI 4iEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FwM8dFgKgRU1jFPfWAybpFdzgL54XClOMnCEp6iPPZ4=; b=yRbySrQzf1rivVyVsU+nIcvB41VtiBvGg0hgD6Pl7DNmDUC4Pp6RDkHZ6nBh7zY8md noojoIN9d44AB/UwDb1C8GHygCGzMInqLDGGmS0rq1UqGT4+3UxlXSyo7Tbt6OHjoYGp zGDSndOzZtn23gevij3noyY5nC0HpCw7hU2S0r8sld0lI16vwJ5gvQ7rmCI1PD12+DGQ GRwjz5ji8+PDbwGGW3hGOdUz4d4Ylat49OttyoFAmDW+VdnKHV5+JUu6e7R5yvNnqOyB dlT0ERHkvvGd86aNt58eoAOsxsvEO5utoyFCsoyb62QKvOieprhrOXRBX31e/G6+LZq2 YwQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2Vh86KRb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si10742754ejb.103.2020.07.14.07.42.35; Tue, 14 Jul 2020 07:42:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2Vh86KRb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729417AbgGNOkj (ORCPT + 99 others); Tue, 14 Jul 2020 10:40:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:56462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729316AbgGNOkd (ORCPT ); Tue, 14 Jul 2020 10:40:33 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BA0C722227; Tue, 14 Jul 2020 14:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594737632; bh=gvBGplmD/bCXZ6jSiG5SiAMcTnGEktsb764GFQOsJM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Vh86KRbqbEn5xwyZEOrF99yAHf+CSrtjBZ56sddQnmmihbiDsFaEwtAuZSBOKUJR O5vFRNEdV8uwpnstVmW6yhDfGUATgbHAQzHnqPQz19KVO5/OvOhEnTa2l7ToqxgCjr QFVyMPR+jwSOYersKjWQfrYuCsLDHl0DB/2kA7U8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kai Vehmanen , Ranjani Sridharan , Pierre-Louis Bossart , Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.4 7/9] ALSA: hda/hdmi: fix failures at PCM open on Intel ICL and later Date: Tue, 14 Jul 2020 10:40:21 -0400 Message-Id: <20200714144024.4036118-7-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200714144024.4036118-1-sashal@kernel.org> References: <20200714144024.4036118-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai Vehmanen [ Upstream commit 56275036d8185f92eceac7479d48b858ee3dab84 ] When HDMI PCM devices are opened in a specific order, with at least one HDMI/DP receiver connected, ALSA PCM open fails to -EBUSY on the connected monitor, on recent Intel platforms (ICL/JSL and newer). While this is not a typical sequence, at least Pulseaudio does this every time when it is started, to discover the available PCMs. The rootcause is an invalid assumption in hdmi_add_pin(), where the total number of converters is assumed to be known at the time the function is called. On older Intel platforms this held true, but after ICL/JSL, the order how pins and converters are in the subnode list as returned by snd_hda_get_sub_nodes(), was changed. As a result, information for some converters was not stored to per_pin->mux_nids. And this means some pins cannot be connected to all converters, and application instead gets -EBUSY instead at open. The assumption that converters are always before pins in the subnode list, is not really a valid one. Fix the problem in hdmi_parse_codec() by introducing separate loops for discovering converters and pins. BugLink: https://github.com/thesofproject/linux/issues/1978 BugLink: https://github.com/thesofproject/linux/issues/2216 BugLink: https://github.com/thesofproject/linux/issues/2217 Reviewed-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Signed-off-by: Kai Vehmanen Link: https://lore.kernel.org/r/20200703153818.2808592-1-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/hda/patch_hdmi.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index b249b1b857464..6aa7403ad80ac 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -1735,33 +1735,43 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) static int hdmi_parse_codec(struct hda_codec *codec) { - hda_nid_t nid; + hda_nid_t start_nid; + unsigned int caps; int i, nodes; - nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid); - if (!nid || nodes < 0) { + nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &start_nid); + if (!start_nid || nodes < 0) { codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); return -EINVAL; } - for (i = 0; i < nodes; i++, nid++) { - unsigned int caps; - unsigned int type; + /* + * hdmi_add_pin() assumes total amount of converters to + * be known, so first discover all converters + */ + for (i = 0; i < nodes; i++) { + hda_nid_t nid = start_nid + i; caps = get_wcaps(codec, nid); - type = get_wcaps_type(caps); if (!(caps & AC_WCAP_DIGITAL)) continue; - switch (type) { - case AC_WID_AUD_OUT: + if (get_wcaps_type(caps) == AC_WID_AUD_OUT) hdmi_add_cvt(codec, nid); - break; - case AC_WID_PIN: + } + + /* discover audio pins */ + for (i = 0; i < nodes; i++) { + hda_nid_t nid = start_nid + i; + + caps = get_wcaps(codec, nid); + + if (!(caps & AC_WCAP_DIGITAL)) + continue; + + if (get_wcaps_type(caps) == AC_WID_PIN) hdmi_add_pin(codec, nid); - break; - } } return 0; -- 2.25.1