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=1796129293; b=g8pE1w8Kvjt2UkjFnGldM75m1mlXrFn8qvyITi1eJFVZrOFumOCuOgEt++QJbZJBoY/a U4El3V4cgCWCBbYg6M2P6wrIg47ZCHwDpoxm4Y9RPLH5Fb76M9//epCWvf62a2hlUhjG3 b6h5dGSDdWm3ah8I4EpQFV8f95EP1G/5HkUpG3vIAv2dplkwyAPCOLNTebr8wPv1ED8rl BZsXdGZ+MLqhTP+yZMdcryUlQJyRunIiC8qL+gOYzLCTAa3cDEXaQbalEm7fUk8KoENFe 84WpBh1m0qDXxVpiQupwkpuWEJOv18HeIL8bbq5AMD8Q0wHJg46wDb5hE/ozHDHgF/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129293; 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-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=9P/MZmIE+XQXiqCAlLK5VG001L6dpucd6oEjll+w3bA=; b=ZMLV8m14lU/bD3344B/vZIJQ/3UKmXwtbVm6nA+nHyfQic5Q/r5g84zSeQ4fJlvJ7Q0J Rrd93AlSvUbHhGcfaDJ18wQ3MtC8L43RhbqmD9CDBjkaIffEDByot7dB1kXLR1kQxCbTT X4IpxU9S1YaRtW59y/rWrqDGQYBtQH66+qIbIK6RijTeJ5zWkKx3ZAuCbnwkVqZHzbjkN NL0SNSijgjg4Ta2wl85VWuRYYkH+VtVVJxR9lbAHaCmXeorGNJj23AAiHGZxr5kGRPCTa PV3HtcaVroraI6M76I0szRg4wPbNHT4vrMP1YKWrv60cbMLi2zhXOFfFuJOeiIMvw1w== 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=QAISGqTz; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=bfT1hmwl; 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 7E51A606A69F for ; Tue, 1 Dec 2026 12:48:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E51A606A69F 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=QAISGqTz; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=bfT1hmwl 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 6B1AQ8MA3856899 for ; Tue, 1 Dec 2026 12:48:11 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=9P/MZmIE+XQ XiqCAlLK5VG001L6dpucd6oEjll+w3bA=; b=QAISGqTzFbJ0B2X+Q/QtqjpgXVH dpwZ4mjV6ULLKN7O44Tg2R1wSuk7+n7l/87WeBaQnsxY0eiao2qQj5tyf4L35RCX dc3Jcd1tsH9coIN8+znoegU3zu8FeyI0T1+BfBjdMLQpaccPgTwQSENi+p5BJkCm QEmeO8JwmAoAxs6GANbPfwgE8McJtboIUoBY3ITkJqeWKG2ABezjsUISzo0rYOdR 1+ucaLsibPgIUz28cJNXppWNAggW3DJc12LITvWdpEC8Tz7iy0b4EfF3LOglLL/T qkVY/WyQMidHrgVA3PHvGMIsoeErgXVjzsTIyqzTDUpAu6HC7kTOgegdt/Q== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9tng14g2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:10 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-949b0d322fbso1573791885a.3 for ; Tue, 01 Dec 2026 04:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129290; x=1796734090; 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=9P/MZmIE+XQXiqCAlLK5VG001L6dpucd6oEjll+w3bA=; b=bfT1hmwlV17BJChBITQ+XKTZJp5Spbnp4EFbYlTO645H3wjPwdfc8mklmx9u5lPBMw 0HF5tDBCLtiVh0dHIK24qN5Gdn3sVavpAZNyK3cesb/mHVuR0IMvcyKcyU6R+Bb2y9ud qF7XgUGaNzJqS3dqWeh2lotsBEUtHLfibLcURcvbLO9EKh2LndnaeG6gofCUEYY+wC9G BdOyAdWXbQNFW5rENs7ssX1qw9J3E0ZDfxphzTxM0gybS4Rjxipw3ELnddrVUk9bC5nh B78oKTp6QfsWhjWzLUUWoXCFq7lL/Hj3Re8tKmcXRdxQ/JJMGzYgEDyouo2XyEGnBGgf Izrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129290; x=1796734090; 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=9P/MZmIE+XQXiqCAlLK5VG001L6dpucd6oEjll+w3bA=; b=0VQ0dxSX4bNq8Zj7885ciNJuW/axFxm+vuHdLuWQPD+ARDKtQQXmURwCuReGHwCDyd IE/jcnPLQ8/DFxUgQXNggle1hy0aRZck1ng8tm3Ct8RDfJ8f8L6CNl1t+inJxhn2piWj d1Dy8jmm9rCkEm9MAaNVqZ/NGOwLgVxTpSHqxKWP6moDGvag8budYgwja3Q+hiCyOFHu 4X3+HiV34CSU4LW7Agp8N1rR8YlEB+LrhBKpnJ3Kh9QyCC4Sha2hUxHGzukxG9mn0kSJ hTwl4umNGj2ofMNdwn4tdPDnIqaZp62ULwj5xuYvZIrXqfRhUfYnudJko8x0mGjhXSvj 27Mg== X-Forwarded-Encrypted: i=1; AL+hErGE5YdRXZTC1NRdt2qCrhdTUTRZyjU8wB07cCF55goYAVXu1xYUJ5e6ezMeGaUoWbN2rthqeMgRx4QfpT4=@vger.kernel.org X-Gm-Message-State: APuU4Z/JPlgh8sUEmLRi/xt8qaBzboPpczJet0jK4q6MO7TxV2Wn4bh0 u0KiU0DC/vrFkK/YQbVNwPfewrmFoHhbqfytfzH+LGEuHe9TpznSn8sYHl2QKSXFmXzezjT4Qf2 LP2XQjWJLjzfUtG0m9j6EXVaFUYOlK1dj/7FO7DIS+rFbhbcMll/HpdQDG5s/o5uwQ6A= X-Gm-Gg: AZFdTZeLew5YORPckLBjx3t99WBU8+EXbDMcy4hzUT4dn9Zbhs1P3qYEtDG/FC4iH2U ZW8Tw3uCnyDHGD9Akdrf0SvOwDD0RrLp5axBJlC1B4RRV+A0Le0xe6rxRaRatpqb4Ozs4BV59dB u577eNgC0Au+hyCpvm3xvCOkQh1JEOt9KlupBRfiDe3eqTryxamDhfSfiHiw+ulxQU+z8jIqHCc XXhGk3HRRvm2kJoJGfmynZGBXsdhBV1rky0KKT1nD25hZXdwYPizep2mK27SYtcnC2pftjBJBnL nucK0HEx1trVapLi93sP3Ve3HIrTEDxjEdgy3R4OdxdnIR1asfJIHvq9maZsxvGO4jm1Msv213o wsqwoJDQswNgSUsFRgCuFRRv9hsmEcwA/92MoR9LRZ6A/7ASEsQX3Qr5B6c2NgZ0x X-Received: by 2002:a05:620a:890c:b0:949:6e5f:7395 with SMTP id af79cd13be357-949bab350f0mr6596847685a.79.1796129289306; Tue, 01 Dec 2026 04:48:09 -0800 (PST) X-Received: by 2002:a05:620a:890c:b0:949:6e5f:7395 with SMTP id af79cd13be357-949bab350f0mr6596841985a.79.1796129288698; Tue, 01 Dec 2026 04:48:08 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:07 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Pierre-Louis Bossart , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Randy Dunlap , Shuah Khan , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v4 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Date: Tue, 1 Dec 2026 12:47:31 +0000 Message-ID: <20261201124753.196748-3-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261201124753.196748-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-Proofpoint-ORIG-GUID: y4SzCpFUpTFbnqTz0pAszveZOMvdcCpm X-Proofpoint-GUID: y4SzCpFUpTFbnqTz0pAszveZOMvdcCpm X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX0l84LYGdODUx vZ5TTKcdgOkS+DcTMnsjDHVwyCOh26ZyI8w+GF/NUsGNWaP7FVj1j6kiESKPq7OzC9TM9CcIdwn mQeByLMKvcFd3YuKfoHfASPjrS6PA11YAvASuZfyxkj/tvRBnkluYbnz8HO7pMrdHHcaVsp9ecF 8HLrljxYUpIJ4j9PKd7gCJZpMMUw2IJ7pAeUrec9YfmVSYAEEXaxzt11cIDR0T30FQ/AHYWMVEt PHSmNrdDqsJa0hnar+oafhGfkNKB5n1SL0omSzGqLPYeSreNQ9AcUMg6sWHJG5rR35vE6evS97M VjQFyptqzhb5n8QWuzn86m/gXp7wcgFNQhreYpMnlysOIlJDDOwonMu4nf/4VkTfsFDNa80O2MV pBQFQEk+vAtz99v3i+qHrYYLK1+CHha8sOSEEWRdI4Z3xPA7iS4FON+p2HtLwl97cD0iNg6+kW1 xdgZ+Y2ajF2whqplPiQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX+OVFl088z+/F y6DMikTEwgiB0cs1BUlq1qdaU+HYSfg0lGtyk4/27C3doSqVMcQ4J3RMnQhFuKHH7r2riwtfStW 1dfpJ7INnfHYCFM72eS4+X4HOfAFY8U= X-Authority-Analysis: v=2.4 cv=O5ysLx9W c=1 sm=1 tr=0 ts=6b0ec20a cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=ydLYoo5a1XT2-liKb_8A:9 a=PEH46H7Ffwr30OY-TuGO:22 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-12-01_02,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010050 Speaker protection needs the amplifiers' V/I sense capture running whenever the speakers play. Putting the capture codec DAIs on the playback BE link ties the two together, but the core skips codec DAIs whose direction does not match the substream. Add a multi_direction_codecs link flag. When set, the core also calls .hw_params and .hw_free on codec DAIs of the other direction, with the substream direction switched to theirs for the call under pcm_mutex, and sends the matching stream events so their widgets power up and down. An optional multi_direction_params_fixup callback lets the machine driver set the parameters for those DAIs. Links without the flag are unchanged. There is no capture CPU DAI on such a link: the V/I feedback data never reaches userspace. The capture codec DAIs power up their SoundWire capture ports and feed the DSP through a codec-to-codec control link in the topology (the SP_VI module in the AudioReach case), so userspace just opens the playback FE. The per-direction SoundWire stream runtime needed to configure those capture ports is added by the following qcom sdw patch. Document the flag in Documentation/sound/soc/multi-direction-codecs.rst. Signed-off-by: Srinivas Kandagatla --- Documentation/sound/soc/index.rst | 1 + .../sound/soc/multi-direction-codecs.rst | 156 ++++++++++++++++++ include/sound/soc-dapm.h | 2 + include/sound/soc.h | 7 + sound/soc/soc-dapm.c | 32 ++++ sound/soc/soc-pcm.c | 136 ++++++++++++--- 6 files changed, 314 insertions(+), 20 deletions(-) create mode 100644 Documentation/sound/soc/multi-direction-codecs.rst diff --git a/Documentation/sound/soc/index.rst b/Documentation/sound/soc/index.rst index 22878d73f7a5..62d01a0a6e52 100644 --- a/Documentation/sound/soc/index.rst +++ b/Documentation/sound/soc/index.rst @@ -18,4 +18,5 @@ The documentation is split into the following sections:- jack dpcm codec-to-codec + multi-direction-codecs usb diff --git a/Documentation/sound/soc/multi-direction-codecs.rst b/Documentation/sound/soc/multi-direction-codecs.rst new file mode 100644 index 000000000000..8d3fa62bb1c6 --- /dev/null +++ b/Documentation/sound/soc/multi-direction-codecs.rst @@ -0,0 +1,156 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========================== +Multi-direction codec DAIs +=========================== + +Overview +======== + +An ASoC backend (BE) link that bundles **codec DAIs of both directions** +on a **single-direction CPU DAI** can set +``snd_soc_dai_link.multi_direction_codecs`` to tell the ASoC core to +call ``.hw_params`` / ``.hw_free`` on opposite-direction codec DAIs with +their own direction, instead of skipping them. + +Typical use case: a smart-amp speaker protection link where the CPU +side is a playback-only DMA (e.g. ``WSA_CODEC_DMA_RX_0`` on Qualcomm +AudioReach), but the codec side exposes both a playback SPKR DAI and a +companion capture V/I-sense DAI on the same SoundWire bus. Opening the +playback FE should bring up both the amplifier output chain *and* its +V/I feedback capture chain atomically, without userspace having to open +a secondary PCM. + +Without the flag, the second codec DAI's ``.hw_params`` is skipped +because its native direction does not match ``substream->stream``; +``snd_soc_dai_stream_valid()`` filters it out. With the flag set, the +ASoC core: + +1. Still iterates every codec DAI on the link. +2. For a codec DAI whose native direction is **opposite** the + substream's, calls its ``.hw_params`` / ``.hw_free`` with its own + direction (by briefly flipping the substream direction under + ``pcm_mutex``, encapsulated in ``soc_pcm_dai_hw_params_at_stream``). +3. Optionally calls ``.multi_direction_params_fixup`` so the machine + driver can rewrite rate/format/channels on a per-codec copy of the + params (an 8 kHz / S32_LE V/I-sense codec DAI will not accept a + 48 kHz / S16_LE playback stream's params verbatim). +4. Sends start and stop stream events for the opposite direction in + prepare and hw_free, so the stream widgets of those codec DAIs power + up and down with the link. + +Links that do not set the flag retain the pre-existing behaviour +exactly. + +When to use this +================ + +Prefer ``multi_direction_codecs`` when: + +* the two directions are physically **inseparable** on the codec side + (same chip, same wire); and +* a single open semantically covers both (speaker protection, playback + with feedback for echo-reference, haptic/boost feedback); and +* you do not want userspace to see or manage two PCMs. + +Prefer **DPCM FE/BE pairs** when: + +* the two directions can be exercised independently; or +* userspace legitimately needs to control each direction (classic + playback + microphone capture). + +Prefer a **DAPM supply widget** when: + +* only the DAPM power graph (clock, LDO, bias) needs linking, and +* no ``.hw_params`` plumbing is required on the secondary direction. + +Interaction with DAPM +===================== + +DAPM edges are directional and the flag does not change the graph. The +opposite-direction codec DAIs' stream widgets are powered by the extra +start and stop stream events the core sends for that direction in +prepare and hw_free. + +Only ``.hw_params`` and ``.hw_free`` are called on the opposite-direction +codec DAIs. Their ``.startup``, ``.prepare``, ``.trigger``, +``.shutdown`` and mute callbacks are not, so a codec DAI used this way +must not depend on them. + +Machine-driver example +====================== + +A machine driver that bundles V/I-sense capture codec DAIs onto a +speaker-playback BE link:: + + static int wsa_vi_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params, + int stream) + { + if (stream != SNDRV_PCM_STREAM_CAPTURE) + return 0; + /* VI capture chain runs at 8kHz / S32_LE / 4ch */ + hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = 8000; + hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = 8000; + hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min = 4; + hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max = 4; + snd_mask_none(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT)); + snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), + SNDRV_PCM_FORMAT_S32_LE); + return 0; + } + + SND_SOC_DAILINK_DEFS(wsa_sp, ...); + SND_SOC_DAILINK_REG(wsa_sp); + + static struct snd_soc_dai_link board_dai_links[] = { + { + .name = "WSA Playback", + .multi_direction_codecs = 1, + .multi_direction_params_fixup = wsa_vi_params_fixup, + SND_SOC_DAILINK_REG(wsa_sp), + /* + * codec DAIs include both the playback SPKR DAIs and + * their companion capture V/I-sense DAIs on the same + * SoundWire bus. + */ + }, + }; + +Ordering with other fixups +========================== + +``multi_direction_params_fixup`` runs per codec DAI inside +``__soc_pcm_hw_params()``, after link-level params have been settled +and after each codec has its own copy of ``params``:: + + snd_soc_link_hw_params() /* machine driver .hw_params */ + be_hw_params_fixup() /* DPCM only, applied by FE */ + for each codec DAI: + tmp_params = *params + if direction-flipped: + multi_direction_params_fixup(rtd, &tmp_params, codec_stream) + apply ch_map / TDM ch_mask narrowing + snd_soc_dai_hw_params(codec_dai, substream, &tmp_params) + +The fixup sees the stream's params after link / BE adjustments and +may rewrite rate, format or channels for the flipped-direction codec +DAI only. It does not affect the originating stream's params or +other codecs' ``tmp_params``. + +Notes +===== + +* ``multi_direction_params_fixup`` is called with the **flipped** + direction so the fixup logic can key off ``stream`` to decide + whether the params need rewriting. +* ``snd_soc_dai_symmetric_set_params()`` runs after the flipped + ``.hw_params``. The symmetric-params tracking is per-DAI, so each + codec DAI records the format it was called with in its own + direction; nothing cross-contaminates. +* The transient ``substream->stream`` flip is bounded to a single + codec DAI's ``.hw_params`` / ``.hw_free`` call and its DAPM update, + under ``pcm_mutex``. The codec DAI callbacks see the flipped value, + which is the purpose of the flip. ALSA core paths that do not take + ``pcm_mutex``, such as ``snd_pcm_info()``, can observe it during that + window. diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 33c4a3e9c1d4..90e527406a54 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -661,6 +661,8 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w); /* dapm events */ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int event); +void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd, + int stream, int event); void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream); void snd_soc_dapm_shutdown(struct snd_soc_card *card); diff --git a/include/sound/soc.h b/include/sound/soc.h index 5abebfa329b5..c15559bb4a84 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -736,6 +736,10 @@ struct snd_soc_dai_link { int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params); + /* Adjust params for codec DAIs of the other direction */ + int (*multi_direction_params_fixup)(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params, int stream); + /* machine stream operations */ const struct snd_soc_ops *ops; const struct snd_soc_compr_ops *compr_ops; @@ -770,6 +774,9 @@ struct snd_soc_dai_link { /* This DAI link can route to other DAI links at runtime (Frontend)*/ unsigned int dynamic:1; + /* Also run codec DAIs of the other direction on this BE link */ + unsigned int multi_direction_codecs:1; + /* DPCM used FE & BE merged format */ unsigned int dpcm_merged_format:1; /* DPCM used FE & BE merged channel */ diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 3ef13d2b1f5e..4bda3e5b930d 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -4670,6 +4670,18 @@ static void dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int e dapm_power_widgets(rtd->card, event, NULL); } +static void dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd, + int stream, int event) +{ + struct snd_soc_dai *codec_dai; + int i; + + for_each_rtd_codec_dais(rtd, i, codec_dai) + dapm_dai_stream_event(codec_dai, stream, event); + + dapm_power_widgets(rtd->card, event, NULL); +} + /** * snd_soc_dapm_stream_event - send a stream event to the dapm core * @rtd: PCM runtime data @@ -4691,6 +4703,26 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, snd_soc_dapm_mutex_unlock(card); } +/** + * snd_soc_dapm_codec_stream_event - stream event limited to codec-side DAIs + * @rtd: PCM runtime data + * @stream: stream direction + * @event: stream event + * + * Variant of snd_soc_dapm_stream_event() that only targets codec-side DAIs. + * Used by multi_direction_codecs links to power up/down the flipped- + * direction codec widgets without altering the CPU DAI's direction + * tracking. + */ +void snd_soc_dapm_codec_stream_event(struct snd_soc_pcm_runtime *rtd, + int stream, int event) +{ + snd_soc_dapm_mutex_lock(rtd->card); + dapm_codec_stream_event(rtd, stream, event); + snd_soc_dapm_mutex_unlock(rtd->card); +} +EXPORT_SYMBOL_GPL(snd_soc_dapm_codec_stream_event); + void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) { diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index dac353fec4bc..1160efe0b223 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -986,6 +986,13 @@ static int __soc_pcm_prepare(struct snd_soc_pcm_runtime *rtd, snd_soc_dapm_stream_event(rtd, substream->stream, SND_SOC_DAPM_STREAM_START); + /* + * Only flip codec-side widgets; CPU DAIs must keep their recorded + * direction so later state that reads it stays consistent. + */ + if (rtd->dai_link->multi_direction_codecs) + snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1, + SND_SOC_DAPM_STREAM_START); for_each_rtd_dais(rtd, i, dai) { if (!snd_soc_dai_mute_is_ctrled_at_trigger(dai)) @@ -1032,6 +1039,59 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, interval->max = channels; } +/* + * Call .hw_params on a codec DAI of the other direction, with the substream + * direction switched to the DAI's under pcm_mutex. + * + * Only ->stream is flipped. ->runtime is not; codec .hw_params callbacks + * on multi_direction_codecs links read from @params, per convention. + */ +static int soc_pcm_dai_hw_params_at_stream(struct snd_soc_dai *dai, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + int stream) +{ + int saved_stream = substream->stream; + int ret; + + if (stream == saved_stream) + return snd_soc_dai_hw_params(dai, substream, params); + + substream->stream = stream; + ret = snd_soc_dai_hw_params(dai, substream, params); + substream->stream = saved_stream; + return ret; +} + +/* hw_free counterpart to soc_pcm_dai_hw_params_at_stream(). */ +static void soc_pcm_dai_hw_free_at_stream(struct snd_soc_dai *dai, + struct snd_pcm_substream *substream, + int rollback, int stream) +{ + int saved_stream = substream->stream; + + if (stream == saved_stream) { + snd_soc_dai_hw_free(dai, substream, rollback); + return; + } + + substream->stream = stream; + snd_soc_dai_hw_free(dai, substream, rollback); + substream->stream = saved_stream; +} + +/* DAPM counterpart, so the DAI's own direction widget gets updated */ +static void soc_pcm_dapm_update_dai_at_stream(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai, int stream) +{ + int saved_stream = substream->stream; + + substream->stream = stream; + snd_soc_dapm_update_dai(substream, params, dai); + substream->stream = saved_stream; +} + static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_substream *substream, int rollback) { @@ -1053,6 +1113,10 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd, /* run the stream event */ snd_soc_dapm_stream_stop(rtd, substream->stream); + /* Flip only codec-side widgets; see __soc_pcm_prepare(). */ + if (rtd->dai_link->multi_direction_codecs) + snd_soc_dapm_codec_stream_event(rtd, substream->stream ^ 1, + SND_SOC_DAPM_STREAM_STOP); /* free any machine hw params */ snd_soc_link_hw_free(substream, rollback); @@ -1060,11 +1124,30 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd, /* free any component resources */ snd_soc_pcm_component_hw_free(substream, rollback); - /* now free hw params for the DAIs */ - for_each_rtd_dais(rtd, i, dai) + /* + * CPU DAIs go through the unflipped path only, mirroring + * __soc_pcm_hw_params(). Only codec DAIs can be direction-flipped + * on a multi_direction_codecs link. + */ + for_each_rtd_cpu_dais(rtd, i, dai) if (snd_soc_dai_stream_valid(dai, substream->stream)) snd_soc_dai_hw_free(dai, substream, rollback); + for_each_rtd_codec_dais(rtd, i, dai) { + int codec_stream = substream->stream; + + if (!snd_soc_dai_stream_valid(dai, codec_stream)) { + if (!rtd->dai_link->multi_direction_codecs) + continue; + codec_stream ^= 1; + if (!snd_soc_dai_stream_valid(dai, codec_stream)) + continue; + } + + soc_pcm_dai_hw_free_at_stream(dai, substream, rollback, + codec_stream); + } + return 0; } @@ -1114,30 +1197,41 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream, goto out; for_each_rtd_codec_dais(rtd, i, codec_dai) { - unsigned int ch_mask = snd_soc_dai_tdm_mask_get(codec_dai, substream->stream); + int codec_stream = substream->stream; + unsigned int ch_mask; struct snd_soc_dai_link_ch_map *ch_maps; int j; /* * Skip CODECs which don't support the current stream type, - * the idea being that if a CODEC is not used for the currently - * set up transfer direction, it should not need to be - * configured, especially since the configuration used might - * not even be supported by that CODEC. There may be cases - * however where a CODEC needs to be set up although it is - * actually not being used for the transfer, e.g. if a - * capture-only CODEC is acting as an LRCLK and/or BCLK master - * for the DAI link including a playback-only CODEC. - * If this becomes necessary, we will have to augment the - * machine driver setup with information on how to act, so - * we can do the right thing here. + * unless the link runs them in their own direction. */ - if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) - continue; + bool direction_flipped = false; + + if (!snd_soc_dai_stream_valid(codec_dai, codec_stream)) { + if (!rtd->dai_link->multi_direction_codecs) + continue; + codec_stream ^= 1; + if (!snd_soc_dai_stream_valid(codec_dai, codec_stream)) + continue; + direction_flipped = true; + } + + ch_mask = snd_soc_dai_tdm_mask_get(codec_dai, codec_stream); /* copy params for each codec */ tmp_params = *params; + /* The substream params describe the other direction */ + if (direction_flipped && rtd->dai_link->multi_direction_params_fixup) { + int fret = rtd->dai_link->multi_direction_params_fixup( + rtd, &tmp_params, codec_stream); + if (fret < 0) { + ret = fret; + goto out; + } + } + /* fixup params based on TDM or ch_map masks */ if (!ch_mask) { for_each_rtd_ch_maps(rtd, j, ch_maps) @@ -1148,13 +1242,15 @@ static int __soc_pcm_hw_params(struct snd_pcm_substream *substream, if (ch_mask) soc_pcm_codec_params_fixup(&tmp_params, ch_mask); - ret = snd_soc_dai_hw_params(codec_dai, substream, - &tmp_params); - if(ret < 0) + ret = soc_pcm_dai_hw_params_at_stream(codec_dai, substream, + &tmp_params, + codec_stream); + if (ret < 0) goto out; snd_soc_dai_symmetric_set_params(codec_dai, &tmp_params); - snd_soc_dapm_update_dai(substream, &tmp_params, codec_dai); + soc_pcm_dapm_update_dai_at_stream(substream, &tmp_params, + codec_dai, codec_stream); } for_each_rtd_cpu_dais(rtd, i, cpu_dai) { -- 2.53.0