From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073800; b=ZsAemf3hszKR0AfqkQn7f4cnw7K5YI6BsXcxTPvJGFGZE++9SOpNAlBxe7k3oaywYIdm aXbAO0Rs2CmH2WLMPY7w/6ODVWOvn1501oxsLPoIXug54H4HL61iXD0u4ys/HHaAo2U/C 8Qn4t6vCz3XwyGiOROGZF6+NH8bRxf/Mp5/87Lqren6hLEECb/P/cbba699pjpZ4eEOP/ 5YveOfKklphHOrB/vIWEX+VmiOq4t404y8JRHDhjTkaxERR21Q5p14KOfIANHnV80ydZO RD9XZg7XAqjffXlo8SG03YnsncSG52Cr1XTzIcXZKzkPfixMc30y7wRZO71Vpw/iFnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073800; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=6BUjM7PFD4zSOFXwpxgmxutlJh+zRMdOmosnlcufcqA=; b=FHlOPZBQI9BKRUXhHaVeRPIYzo7iw4d5oUE4DNu5Na5v0NCLssgfq48mNq5BiD9ledgc Gr2irseJpYMLgmR/6/ctdJwHjL9tZa+VDIkjMA0nayGzktC7KHjrnT2eKW8HSnHzgheB+ 3KVjbDDT7xB7fFzSuw3tBGK0XwsSZZ9x+lhQpDnAU00jJVCW9FlnxVatAmULezbkAQBfV YqJpLebGFmcZthznNQtpe+8GCpivvXiXlyajsyRbydhcpM3fzRQd9UXOgBjaIeZSd5Al7 YobEC85vygCObgFVUn19dJdQvPXPda4OjR/ARkP7EvqOXrEGOktuNoIqYWOrKEe/RJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=XHW4+nKk; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b="cgz/+et4"; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88DF8606A6A5 for ; Mon, 30 Nov 2026 21:23:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88DF8606A6A5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=XHW4+nKk; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=cgz/+et4 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKQESQ2032770 for ; Mon, 30 Nov 2026 21:23:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=6BUjM7PFD4z SOFXwpxgmxutlJh+zRMdOmosnlcufcqA=; b=XHW4+nKkGQh8GZTQYI7PGxUs/Jo m938RhbiP1Q//W1PtdpzDe081ebgcj0R/wyYEr1/Y7fBDm4JnGuYawIlpmXbwDeu znoa1UIxYUqVR7DWvsiNFoO7bGHJfBPxQ4hN0VUouy1GpiHic8itmIbXr3Rk3kU5 zZWWwbwO45YfaDsycqZMSRVivM2+cnHOGScoTNAlNTv7emxuyR1Gm2bWmDfkLX+d 8NIHZHN3XLJTs4vPK5f0iY+VIUGVrXjgS5nq4/VZhlW/hcfXZSR/e0/VsMGNebtk tVhGHgaYuLkCGD51e7sgbRSSimG+nSH/5qVHbwN1ZriOwYBpKHH5uZDEDLA== Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9enx0hh7-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:18 +0000 (GMT) Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-93909014c85so195065285a.0 for ; Mon, 30 Nov 2026 13:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073798; x=1796678598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6BUjM7PFD4zSOFXwpxgmxutlJh+zRMdOmosnlcufcqA=; b=cgz/+et46IJWgrODC5DQbIegRoe6CCAazQ6eayHSxuh1JL1Cz3bmuG6N45hzovopy7 VPXPYM9WWmxdVg9KnCwhlau9EK3tOC91yfC6eB+vweoFa3zBAt6wCu8PXhqz1YtZ5DIB 9oINlnWlhYhUWwJ0fuslAB0kie4eWnUo2IYzR5Ku0uhFJz/EaHiKYrLr+EOACUvVUbb4 oEERibMVJgtu+cxaxx70yQOisUTN/1GMV0o+fXlzirc+8WMNMiXaZUaiim7xO3mYqoJW cbtD0wdvSngMvXuY08vPlH4AqNXxQnzqtNrMeBUUT+GzQNTZfHrEXaKrifX7eLWXOgqk Q6kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073798; x=1796678598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6BUjM7PFD4zSOFXwpxgmxutlJh+zRMdOmosnlcufcqA=; b=nGL6xUzhXLlVwXN1X7sDZBd992+P7+bAFJdpsODzFfClFRpptROf0nyxM9tfgfA+to DpEgZH0xgWjCqYbLugO5zEmb6oHbheImrmwRlTCAzDInTqVhnQe7bFHQ6tm1yry+6mcx xTpXt6ZMjNr9PNrDtDwAehIGsdAZmzu1E3UP4exqvcuUG0kfJu7hxVtfiqimS9celZkI QCifcCp3WCtiBKq1y4/+Qej6c7TdZyeKXX45PM7oqCvXkKCvgfy1aUJOI+W967YJw31g r7odjZCs5QCPa4X0XOANwzxag6rjVs1ca7HZFcRKIk1jSbkrwEPeSYmybsQesqGqE+/m a5hg== X-Forwarded-Encrypted: i=1; AL+hErEsDcosIqffsI4zRBf+6eGJxOD1vvmWF+069EiEmbDC4USW/oiUeIPL+A84EU1zClCr8mT5DGT5K6ebiNY=@vger.kernel.org X-Gm-Message-State: APuU4Z8m8iKywFY2k9bNA8hj4+AlbSdyfKsadCJLnbQRu+qtAsdDZwzh g8FE3RpK2JGsSmniDGF7V/GHe8dNTbjt89EkRHIT1ksW6GLr8hvMtaSLaBkHVpUPbzaGKDW72e3 4EEFmMySplC3PmJSWV3CgGgp+W/OiSFMVEt+jiV2hDse1qt2VuDAAFY+6+pLVf6SzsuA= X-Gm-Gg: AZFdTZeVXylfPBs1CauWLAvqU/sFNnGxzSioEq2W3DrmwkSAn0nFAOpZ1b2D2H/iA6L NHF8t9XHOCPMcYRNs4mF+HLqNgqi3VEwEAsbFqRuVok2jsNd8A66qo0KKDPRQu5PReVm7xrwZsx 14WxMq1Fq23ShNFlyd2f81NXCiw0Yi7HCH+PouswPg0lsnldy0V3JpUTUuaioxOecko5zLy5qme bbdqZyol4BbLAfs8RWLHVN5I/PFeFCT0wv7XMGHu812rswZdR/dYDJlkQ/bvWMKAM3OwaA67bYE NzZPe4pbbs07D5yxcMjAW4kCV67ZNzPGld1ZJMAmbYICJAXrq4QM7Pb0ytqzOQK7cvUnWO3U81a zd9vvpx/Hr5njm2eUmH88/iy+WpQ5Tp/IHfI3TegjGgcZj1IRHU+pjoFlXu6Nw/Gw X-Received: by 2002:a05:620a:2b8a:b0:947:b201:faba with SMTP id af79cd13be357-949bab0eea6mr6215052085a.66.1796073797617; Mon, 30 Nov 2026 13:23:17 -0800 (PST) X-Received: by 2002:a05:620a:2b8a:b0:947:b201:faba with SMTP id af79cd13be357-949bab0eea6mr6215044885a.66.1796073796864; Mon, 30 Nov 2026 13:23:16 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:16 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Cc: Srinivas Kandagatla , Ravi Hothi , Jaroslav Kysela , Liam Girdwood , Takashi Iwai , Pierre-Louis Bossart , Kuninori Morimoto , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Date: Mon, 30 Nov 2026 21:22:38 +0000 Message-ID: <20261130212258.7376-5-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=Lv0HWXdc c=1 sm=1 tr=0 ts=6b0de946 cx=c_pps a=50t2pK5VMbmlHzFWWp8p/g==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=Npvw59_4gY62FyUIyv0A:9 a=IoWCM6iH3mJn3m4BftBB:22 X-Proofpoint-ORIG-GUID: pFuAMD6dKhzX3VG18CTinWZxbN6wqUyY X-Proofpoint-GUID: pFuAMD6dKhzX3VG18CTinWZxbN6wqUyY X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX0AHTHZS1t5Od v7RgawgOFtAfzzQhlT4YPDtzGJaptavCFN9l0wRs/3m99jBr59ztTCx/u4lxPYm1+WG2jwK+68Q 1Ki83t70kI/TGEZQvf8s0vTfFbP6BSY= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX4SM+KQTOo8uU trcDU93kzIjXyUY/YkQBPbqjg8StIUjpnagTye6bKh6pKTWgMj2tQLnqAxpqWi21jNWxEi8DC+3 TxY1D8EQK9Mngl+PBiOWcbkv05Xt1U8Foy+198zJg9rXMakurffJQRMNz8YjG4RDyY1fQe4MznP CpFzS3uJ8GGfuJldyUe7rGIBmOyeIfHQ+kdUmlOBn7blWPKbdjmjrGxYi8yqq+1VwqthTKo79pd V5H2ZtRGEXbjSBUOq4+uKfJ/3bxiNgv7cUC96MUDpE1OzjNgXsS/KflLHeHgLIDey7A6gc/dcfo jJZwbI78vNUSAWaOU6OmZQfjpQ1YABTx2PDNAXTCBBlTES9688rLY08AdKRS/EsPFgzOkLcPEDO 0zq193BA9STSOS5ycSufi6XYPaSaEldkTm8uNqlJ29bqNUXE/FKp+BoJ2q5UE0FUH0JlG0dvF8x 0mrg/jaW5VaYJ6kXvNQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_05,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300086 A SoundWire BE link with multi_direction_codecs carries codec DAIs of both directions, and each direction needs its own sdw_stream_runtime. Split startup, prepare, hw_free and shutdown into per-direction helpers and run them for both directions on such links. Stream runtime names are suffixed with "-Playback" / "-Capture" to keep debug output unambiguous. A small sdw_find_dir_stream() helper centralises the "find the stream for this direction" lookup that was previously open-coded in each callback. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/sdw.c | 232 +++++++++++++++++++++++++++++++++---------- 1 file changed, 178 insertions(+), 54 deletions(-) diff --git a/sound/soc/qcom/sdw.c b/sound/soc/qcom/sdw.c index 6576b47a4c8c..82f1c47a788c 100644 --- a/sound/soc/qcom/sdw.c +++ b/sound/soc/qcom/sdw.c @@ -5,9 +5,55 @@ #include #include #include +#include #include #include "sdw.h" +static struct sdw_stream_runtime * +qcom_snd_sdw_alloc_stream(const char *cpu_name, int dir) +{ + const char *suffix = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? + "Playback" : "Capture"; + struct sdw_stream_runtime *sr; + char *name; + + name = kasprintf(GFP_KERNEL, "%s-%s", cpu_name, suffix); + if (!name) + return NULL; + + sr = sdw_alloc_stream(name, SDW_STREAM_PCM); + if (!sr) { + kfree(name); + return NULL; + } + return sr; +} + +static void qcom_snd_sdw_release_stream(struct sdw_stream_runtime *sr) +{ + if (!sr) + return; + kfree(sr->name); + sdw_release_stream(sr); +} + +static struct sdw_stream_runtime * +sdw_find_dir_stream(struct snd_soc_pcm_runtime *rtd, int dir) +{ + struct snd_soc_dai *codec_dai; + struct sdw_stream_runtime *sr; + int i; + + for_each_rtd_codec_dais(rtd, i, codec_dai) { + if (!snd_soc_dai_stream_valid(codec_dai, dir)) + continue; + sr = snd_soc_dai_get_stream(codec_dai, dir); + if (!IS_ERR(sr) && sr) + return sr; + } + return NULL; +} + static bool qcom_snd_is_sdw_dai(int id) { switch (id) { @@ -49,43 +95,42 @@ static bool qcom_snd_is_sdw_dai(int id) return false; } -/** - * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card - * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup() - * - * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set - * Soundwire stream runtime to each codec DAI. - * - * The shutdown() callback should call sdw_release_stream() on the same - * sdw_stream_runtime. - * - * Return: 0 or errno +/* + * Allocate a stream runtime for one direction and set it on the codec DAIs + * of that direction. */ -int qcom_snd_sdw_startup(struct snd_pcm_substream *substream) +static int qcom_snd_sdw_setup_dir(struct snd_soc_pcm_runtime *rtd, int dir) { - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); - struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); - u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS]; + const char *cpu_name = snd_soc_rtd_to_cpu(rtd, 0)->name; struct sdw_stream_runtime *sruntime; struct snd_soc_dai *codec_dai; + u32 rx_ch[SDW_MAX_PORTS], tx_ch[SDW_MAX_PORTS]; u32 rx_ch_cnt = 0, tx_ch_cnt = 0; int ret, i, j; + bool used = false; - if (!qcom_snd_is_sdw_dai(cpu_dai->id)) + for_each_rtd_codec_dais(rtd, i, codec_dai) { + if (snd_soc_dai_stream_valid(codec_dai, dir)) { + used = true; + break; + } + } + if (!used) return 0; - sruntime = sdw_alloc_stream(cpu_dai->name, SDW_STREAM_PCM); + sruntime = qcom_snd_sdw_alloc_stream(cpu_name, dir); if (!sruntime) return -ENOMEM; for_each_rtd_codec_dais(rtd, i, codec_dai) { - ret = snd_soc_dai_set_stream(codec_dai, sruntime, - substream->stream); + if (!snd_soc_dai_stream_valid(codec_dai, dir)) + continue; + + ret = snd_soc_dai_set_stream(codec_dai, sruntime, dir); if (ret < 0 && ret != -ENOTSUPP) { dev_err(rtd->dev, "Failed to set sdw stream on %s\n", codec_dai->name); - goto err_set_stream; + goto err; } else if (ret == -ENOTSUPP) { - /* Ignore unsupported */ continue; } @@ -93,59 +138,106 @@ int qcom_snd_sdw_startup(struct snd_pcm_substream *substream) &rx_ch_cnt, rx_ch); if (ret != 0 && ret != -ENOTSUPP) { dev_err(rtd->dev, "Failed to get codec chan map %s\n", codec_dai->name); - goto err_set_stream; - } else if (ret == -ENOTSUPP) { - /* Ignore unsupported */ - continue; + goto err; } } - switch (cpu_dai->id) { + switch (snd_soc_rtd_to_cpu(rtd, 0)->id) { case RX_CODEC_DMA_RX_0: case TX_CODEC_DMA_TX_3: if (tx_ch_cnt || rx_ch_cnt) { for_each_rtd_codec_dais(rtd, j, codec_dai) { + if (!snd_soc_dai_stream_valid(codec_dai, dir)) + continue; ret = snd_soc_dai_set_channel_map(codec_dai, tx_ch_cnt, tx_ch, rx_ch_cnt, rx_ch); if (ret != 0 && ret != -ENOTSUPP) - goto err_set_stream; + goto err; } } } return 0; - -err_set_stream: - sdw_release_stream(sruntime); - +err: + qcom_snd_sdw_release_stream(sruntime); return ret; } -EXPORT_SYMBOL_GPL(qcom_snd_sdw_startup); -int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, - bool *stream_prepared) +/** + * qcom_snd_sdw_startup() - Helper to start Soundwire stream for SoC audio card + * @substream: The PCM substream from audio, as passed to snd_soc_ops->startup() + * + * Helper for the SoC audio card (snd_soc_ops->startup()) to allocate and set + * Soundwire stream runtime to each codec DAI. + * + * The shutdown() callback should call sdw_release_stream() on the same + * sdw_stream_runtime. + * + * Return: 0 or errno + */ +int qcom_snd_sdw_startup(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); - struct sdw_stream_runtime *sruntime; int ret; - if (!qcom_snd_is_sdw_dai(cpu_dai->id)) return 0; - sruntime = qcom_snd_sdw_get_stream(substream); - if (!sruntime) - return 0; + ret = qcom_snd_sdw_setup_dir(rtd, substream->stream); + if (ret) + return ret; - if (*stream_prepared) + /* Also set up the stream of the other direction on such links */ + if (rtd->dai_link->multi_direction_codecs) { + ret = qcom_snd_sdw_setup_dir(rtd, substream->stream ^ 1); + if (ret) { + qcom_snd_sdw_release_stream( + sdw_find_dir_stream(rtd, substream->stream)); + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_sdw_startup); + +/* Prepare+enable the SDW stream for one direction. */ +static int qcom_snd_sdw_prepare_dir(struct snd_soc_pcm_runtime *rtd, int dir) +{ + struct sdw_stream_runtime *sruntime; + int ret; + + sruntime = sdw_find_dir_stream(rtd, dir); + if (!sruntime) return 0; ret = sdw_prepare_stream(sruntime); if (ret) return ret; + ret = sdw_enable_stream(sruntime); + if (ret) { + sdw_deprepare_stream(sruntime); + return ret; + } + return 0; +} + +int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, + bool *stream_prepared) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + int ret; + + if (!qcom_snd_is_sdw_dai(cpu_dai->id)) + return 0; + + if (*stream_prepared) + return 0; + /** * NOTE: there is a strict hw requirement about the ordering of port * enables and actual WSA881x PA enable. PA enable should only happen @@ -153,15 +245,32 @@ int qcom_snd_sdw_prepare(struct snd_pcm_substream *substream, * accumulated resulting in Click/Pop Noise * PA enable/mute are handled as part of codec DAPM and digital mute. */ - - ret = sdw_enable_stream(sruntime); - if (ret) { - sdw_deprepare_stream(sruntime); + ret = qcom_snd_sdw_prepare_dir(rtd, substream->stream); + if (ret) return ret; + + if (rtd->dai_link->multi_direction_codecs) { + struct sdw_stream_runtime *sr_opp = + sdw_find_dir_stream(rtd, substream->stream ^ 1); + + /* Skip if no slave registered at hw_params (e.g. VI off) */ + if (sr_opp && sr_opp->state != SDW_STREAM_ALLOCATED) { + ret = qcom_snd_sdw_prepare_dir(rtd, + substream->stream ^ 1); + if (ret) { + struct sdw_stream_runtime *sr = + sdw_find_dir_stream(rtd, substream->stream); + if (sr) { + sdw_disable_stream(sr); + sdw_deprepare_stream(sr); + } + return ret; + } + } } - *stream_prepared = true; - return ret; + *stream_prepared = true; + return 0; } EXPORT_SYMBOL_GPL(qcom_snd_sdw_prepare); @@ -187,9 +296,13 @@ EXPORT_SYMBOL_GPL(qcom_snd_sdw_get_stream); void qcom_snd_sdw_shutdown(struct snd_pcm_substream *substream) { - struct sdw_stream_runtime *sruntime = qcom_snd_sdw_get_stream(substream); + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + + qcom_snd_sdw_release_stream(sdw_find_dir_stream(rtd, substream->stream)); - sdw_release_stream(sruntime); + if (rtd->dai_link->multi_direction_codecs) + qcom_snd_sdw_release_stream( + sdw_find_dir_stream(rtd, substream->stream ^ 1)); } EXPORT_SYMBOL_GPL(qcom_snd_sdw_shutdown); @@ -197,18 +310,29 @@ int qcom_snd_sdw_hw_free(struct snd_pcm_substream *substream, bool *stream_prepa { struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); - struct sdw_stream_runtime *sruntime; + struct sdw_stream_runtime *sr; if (!qcom_snd_is_sdw_dai(cpu_dai->id)) return 0; - sruntime = qcom_snd_sdw_get_stream(substream); - if (sruntime && *stream_prepared) { - sdw_disable_stream(sruntime); - sdw_deprepare_stream(sruntime); - *stream_prepared = false; + if (!*stream_prepared) + return 0; + + sr = sdw_find_dir_stream(rtd, substream->stream); + if (sr) { + sdw_disable_stream(sr); + sdw_deprepare_stream(sr); + } + + if (rtd->dai_link->multi_direction_codecs) { + sr = sdw_find_dir_stream(rtd, substream->stream ^ 1); + if (sr && sr->state != SDW_STREAM_ALLOCATED) { + sdw_disable_stream(sr); + sdw_deprepare_stream(sr); + } } + *stream_prepared = false; return 0; } EXPORT_SYMBOL_GPL(qcom_snd_sdw_hw_free); -- 2.53.0