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=1796073797; b=p941oL1ihoLO8d/NiMqWFaU2Y0KrUti1Tq2NQWvVV9xJanT2zW8GiqW9BYiG5PCh3DiO EYPA4Sw523NHFhbXShSId+6yUajYN1c9+3E/i1aPFovBcMbVzYcrCVhZur1B0LNSZWmYa /TXcxeuHlMEhA5YAr7Di5OLWFDJvocdEEF3dRL3DwaUPep9kHB94E6Tks10njCX0u6FjQ 7UqxiuXmI5YOZ/y2aXyyG6AnQiHKTOUDE5ddepcwwvuIsvp6cail2gkqsBggtbQFdMNTW NVy/QYi/xcwJAc+u2ePVQbeGt7vdA6WR9uYwAdHFnuUZ5+vFZ7/fSB1xJGwTtV1WtMQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073797; 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-Spam-Info:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=1TFsn/P+Dbq9Bfe76nvb6I+/uEd49ZFvH5REPcF5taM=; b=IfBFU1URqY5QKQsmSOaHCsvWaBcysRBHLILp158L1Cg9AYvhs9XbdUIWKyD0/KhnKLDo qFJuo9ebMKvYgWEryAsgLURielGM9zNa2omqPmwUTJdAn1mQuNmDCy84GFBYAYVuy/KtN 1jnynOFKfjA50lQIXF+uPZ1aBMkpJDWBrwJ+5D5IDuFaF9joc5Zp6GoAxNz/jdRzOZ083 +PSgBx/l9QI0Ton5V7dkAcn7hIQ/4D2SznaJWFxfYBHecdcKABAwCGLaIr6TBx0aWG/Y3 muNhlegPnJxs8zunsW25vI4fKvq1OZ6PkSxBnlgiP40vTCncpM9wXrvZa8P2sjYl2+A== 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=OcnQms0I; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Z0r8VI5z; 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 EA682606A68C for ; Mon, 30 Nov 2026 21:23:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EA682606A68C 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=OcnQms0I; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Z0r8VI5z Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKQNV73186545 for ; Mon, 30 Nov 2026 21:23:15 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=1TFsn/P+Dbq 9Bfe76nvb6I+/uEd49ZFvH5REPcF5taM=; b=OcnQms0IRunUcDRVQcSBSdNpoPT sVrMAPLqMqhyp4EzTTeColVDr8ESY1mdNDQEOGi/h2POvPyYMkyJYTE3ryFZ0vSE klshOqeCiU9oAG6i07JCPJSf5Mg5n2ZsjcbZUBe9/BxFR/GVVzALgW4t4WNFbAST 8V3ruIkPPnfBYYzTksQXEtGN5+lUj63tdl71SKXfLZ/xq1n/1NP7DYxi76hydt9O OqXzavFtHeYkYQmTUhbpl7hW3ukoBqGXBLnFm4y4oGPneHhUwlh16jIEdlM3qcWo kJT/CGcv8d2M+8BaluEyB96wq9d/X2x57E0dt8LmIsVPtOjew+qVsEb6AkQ== Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j94wfu9sk-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:15 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-9495a1f5e47so153146385a.1 for ; Mon, 30 Nov 2026 13:23:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073794; x=1796678594; 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=1TFsn/P+Dbq9Bfe76nvb6I+/uEd49ZFvH5REPcF5taM=; b=Z0r8VI5zfPdZT8OEHdzsFNB1ykeVPIWR6k347HXJP9++IpdTYXl1FwxZLqZB2c8bDx jG5JCQfGlKxvyeFG00tR2nMqab0qKMaTZIm0oPUDq1D0xh7m1rwtEuj8xihHCnmLbe45 JO3VcR/t7g9XbaYZcrU5i647L9pFc6wOp1eOU6Sh3GFHBchVS10YeWiIPGEMoALHW72f JYd4znxkcpC6bAxf4q4nvg35UPaYoIeKrpLxxQT6kWXMYIvuSmo0iJur2aZRouHuxBn2 QztPmPUBZ58Ge3UBP3rjUdE16C8RUn7L3HEN60X1qSz7jzwM9iUI2QykBQYev5/4j8yQ mCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073794; x=1796678594; 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=1TFsn/P+Dbq9Bfe76nvb6I+/uEd49ZFvH5REPcF5taM=; b=zk0OJKeJKe/L6b4NE03gMAsRqX6wOz4zIlwtfO7jd2PfyJopJ43kuuPPwVrhjfbLNf YOntuBxD3rGaYdtemMXJM4/gZPwkfEo/tJA748XyqmFfKKO6uXZ9msgbik/AwnSDnUwP gXreXrI04g08XUgNbPLcopvZi4xANSOWhQeyaMul5yASyXl6v1rS8EXqLZmyYoa6quDb ct+DAr9iGM8em6zgWKpJO0gBKg9WT+IElureh9ZfKKZgtIfwi8ogWK36UlWoSiNe5nED M0yOBkWnTzwEE6nQvlJMfUymVsgRB8VVwyDIAR0TJNbhl3jrBh3NCx7GHSK90MvGaB/F whww== X-Forwarded-Encrypted: i=1; AL+hErEFv2wN7pwAbng2yEiY2BqPxYmL/YgNlo3YWTq0z+M4FzpD7O3TrUxwT9N13RiqNzPPuJn3fQHqez3xmks=@vger.kernel.org X-Gm-Message-State: APuU4Z8SawQL6UiN9jGCLDpYCcFQb1alPHJmOJLiyXT7PS8ArdbQIpxZ ZJIl+WdEeKCioy+Oc917ZodQiJw9OsIoQd8dHh/zgrJizrmw07O967qnKRap8zW6Zu5j+mLP09o MP6hAnKfSMq+ai4tKfl/l/S4LwxsFar/5lsSviZwZyuVDs58p2ebB2C90X7hnM6V8HhQ= X-Gm-Gg: AZFdTZeDe+hHSk6k3xXsffCo4n+RRxkVqRih4DgtCYi98Zwa3EVXNNeKfMqQt6wFkvO I6TPzTzLZfPR4oNVYuC/vY1UcSeBKKzfHTyN8DHMC4PCMv4zV4ov4dxVCVmc4mIL3vX9h+oslTq XhYYrBbpB6N/INGJMMefv5NrtwoG3TbUIKHeGQHXEGkGpf6pnQTeQhnh7L/pA5hEhTiqifnyw/8 /IaO4IitkCsReb1qlychM8kOKpAKZPK8n/WXM4aJEWICZbs8b9oet+xGZoGCDu8aDBc6/2GSbzY DBNyolRpEf8NdrJjeQ31X5vF94JL54of+toieoSU9ZibEY7O9qM0uiDftF7Njur0RGFXFfUUFGw As27KYGvBF7O6uUc7OieRF6dcN+g9sfcxnYVRn+QSLDEj1YbQ9Ee/jh2b2OllwHkF X-Received: by 2002:a05:620a:1d0b:b0:93e:6c4f:bdf1 with SMTP id af79cd13be357-949ba96e85bmr5999166885a.17.1796073793675; Mon, 30 Nov 2026 13:23:13 -0800 (PST) X-Received: by 2002:a05:620a:1d0b:b0:93e:6c4f:bdf1 with SMTP id af79cd13be357-949ba96e85bmr5999160285a.17.1796073793053; Mon, 30 Nov 2026 13:23:13 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:12 -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 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Date: Mon, 30 Nov 2026 21:22:36 +0000 Message-ID: <20261130212258.7376-3-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-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX/xDlPuxGeHmx 6QHkYprH/VE5VmYqtHC8bi5O8j/+Whorwi/l67Z69FI7o5IVODLnyftauh52ZWrea9TpoI1LblD m1iUFDh5Ou1lx/V49UQQpRIyCH7wdKg= X-Authority-Analysis: v=2.4 cv=BZ1NQbt2 c=1 sm=1 tr=0 ts=6b0de943 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=ydLYoo5a1XT2-liKb_8A:9 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-ORIG-GUID: i4F77_LW6Kl9q3gr3fnSvwQUYp_EiuGN X-Proofpoint-GUID: i4F77_LW6Kl9q3gr3fnSvwQUYp_EiuGN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfXwmZZ3nwW6yb/ 2lIp8uh0OZwV7x512HzgcA4u33eWJvPTNLQWQTSmfHlqKLuHvLolqHA/ON8hJyckealMEThmnFR rKvkJKbCql4lYqqsphYltDV8EQv9gGoIXExHZQqpVAmNhc18tjgP9JpjnfbBoZ0Xu/6O46jePID ZbOfwNdbldc2GKMNTdx+UPpIoFXu60xbK7HwMUYpvFX8w7yo4XNbHneEp0AGJq67hYsCtRZ7aCd ARMXEnnOZVNOzyZ2LN6cffegkBoPIVWbyA7yg+pUbuTVG1kZKWAVwL34KQjKPe2mwKY4S2c4Wz1 +0f7EhlkEWJZm8S4+LZVj8GXaAqlIZs+uYKSnQGCg9A7r5lc+8Xovb1dZyXQrixbtcSKRZfrTBR OjYcbEJBBYjGaY3K7OuVsJZI71A3CFe6+5Kw2VCQjG61tH7a7cM2LuR52gcJhvn8qPduBU+Yu6M kaAPeQzBj1QupL6PY1w== 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 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 clxscore=1015 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300086 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..2af61598dd7b --- /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