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=1796078439; b=cJLTWa9O2+wz3wYlMDez21/ZGFsEWJesx6jSQgcsAmqfiDcpLZjau4VLPrr2LwfxiDbo /Vazns+4x25YL39rD8mcmlWPWJlGx60gs26nYaOzoUJcdE9u0OREGAtu4x+CRA2zK2ThJ C+PmiA42YurnPKoKwtnwDfltMA+EGwDVMQy15uTcdu2WPz+Xl1MaLzgZc7TW3bS+YYdxW MEwhBhwR6lyGSFd4c+2oVoCl2rpa9Gc5elDoknY9RhpFfQ+4qJCjWwp/PDOaxWeV5HDgc vSe+kodRCElSDPR4pSXGqGqacGNO27gDnsJoy7P+84wMnbMnGcPMqfqiqJ2xK/ouc1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796078439; 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=8G8smYH4Y7LoV2oBlziDvIdwLCw9WLSumuJ1Bp8fppI=; b=St2SWn/JX05v0g9CLaWsvMS3tu49sjkG3tIZr5fh59Xo0AF3LIkunERboLFDj88YELgn Gdcw6aOaYe9QSOkcDPGXYUgdRK9DgJ9OVOQStclMAH6fjnzDVoFJBp4VbSylF0FyW0sKt 4meHEFnE7TqoAwQnrtU5+Ulg36S7/6aypAYlMLW/geFm3j2maz1zvc26GAnP43Ocuff3I njIL+5oPYCX8bCIfBL9ZG/s61rMj9kHwETR/H5Zd5Ya3fKNvZRLi4D5vDSgyBi4wW69wY 2G8meJdOJrI9j7fJOhbXXBRtGllfUjnLuCDA70ylBK9o/SZvho0XhllF7cbSxO8R+lQ== 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=mgMg8bDm; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=LLbAJdzm; 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 D0424606A331 for ; Mon, 30 Nov 2026 22:40:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0424606A331 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=mgMg8bDm; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=LLbAJdzm Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKQIh42820310 for ; Mon, 30 Nov 2026 22:40:38 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=8G8smYH4Y7L oV2oBlziDvIdwLCw9WLSumuJ1Bp8fppI=; b=mgMg8bDmSvS9h/75+ry0r3hwfXG g77l1lRGD4LuSqVx6p4roR1Q29MDswrd/9eqdTgREvvdx0/5ZXgpT9ev9ZsN+t3I 5xFqfsfu0vA+ajVUltLfaDBGTkwRlcuev5BigGhWswIuTZ5Od8cdI4mTloOJQk04 OQa2LxI17hf1iE3+uLsfy369xlaUHPXSir+u9c3Dr+UeEaTviJG0BI6uzRRr5ioQ qlvcW7FlP85E7iteCV9KRyI9OhaH6YXOEpjmlg811lo9O2QniFURUHnFk0IuHxyh 1DG63cq9I/td4OC5UGfwdz0adqqurWZ+LbAYxblppkZuggh37lzPYZvt92w== 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 4j972dtxk3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 22:40:37 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-93cb7f9bb86so2078291185a.2 for ; Mon, 30 Nov 2026 14:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796078437; x=1796683237; 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=8G8smYH4Y7LoV2oBlziDvIdwLCw9WLSumuJ1Bp8fppI=; b=LLbAJdzmg6+kOCjY9D+nGSYfRrflWavHLwp92t9LBhhTXJ1KQGPbCmtvX4ePg93kNU Pt5KVtcO5RzvdFixK4dkBxOeaj4tUBBgj0Bhzi+440/ZDQlbM0mS/hTVcOfR9KIalGvZ rxxBc79g68OwY4Pn5jTXlk3NDUwPmBmlAv8GajfuhTBGa77jA8gLIX4bWgy0R4ZIiM7D Tq8jhDgdHIf16FElPZOxz4wI132pg2UydA7rwWH/jhNP024gCMN0eUrg69hK/izhNN1F 6vG9OaRoSnHpiPIxx1YP1FSQb3Jvb78IIHMskdrSr0UQQVcfAO1QSOLnMuKlqeTw/VvS kDgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796078437; x=1796683237; 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=8G8smYH4Y7LoV2oBlziDvIdwLCw9WLSumuJ1Bp8fppI=; b=HnDy84mvA0hvxMnzABISzmxpYY2w44pRLZgokVGZBQR/ss+Qb0evqhJCLv1H6ChXxI 1uLxssOgoeVvM+6YMK1VrTkG52ORnlFIY2IqXJ0zckKSAKDcuyiKSEfJW6BL1pLbyPzg ExsascYwq+BGmfNYA6LEZrmZK9YfxdbgxudwTG6b5Dum88ABvdPdt5h2q/IIjofiX0FK cKKEZKNrjPKSW0dd05AyeSv+GP3G1TVVZ2upfceNWNfJTIKZAoqXTzkTnrSJwWJxEgzE Yw+DusiUbb834EiOpwFORD+eeKDHC3TnA7cIGW45dutxHUMBypyONlJla0pfjgIxf3Zl s6mw== X-Forwarded-Encrypted: i=1; AL+hErElkZA16ljTPVQH/wJRvJb+aPnH3Tw5W0R42iUg+TXPcocDQew9UBVaJg+CxYQe7yEaVBj44/oxwBOWSZA=@vger.kernel.org X-Gm-Message-State: APuU4Z9KaxtBIKsjlajoOKUfDNQSCmKDEgBh3U4jFRI901WuxEVI1MaC jsuhyu8j9z9htigeva+BsbUlbE8fGHJEGpFVFIrNLqTVWy2Oy1am8rMSB+dJ3zy5Q3Ky13cqyTh PRdfa6t58ZzQrgX7gMqez28DGvmkg5XuE/0CxGavguqxzHxSsRtanOdhGB9QlbM0iQsw= X-Gm-Gg: AZFdTZffnTgCFhD/vPVXIedNluXktHiLALOS9boPyvJIrZRTvjJJmexqPLprhpp36Vi TDjH1wc9dxzuhMlwjJ/pn4WCYmgv4lk4GdHQ8RpnwY626PModd+LEtqP3FKIDREnWKSvIMoTZny YgYEs0CRR5uEmt/KILjvs8sQ+wnIAR/fimyiopwfwz5UI5WJRpgNudaB8FzlJu/dQ45RRdQwuEa I/vTqQn02KzVaQ5ml9wxXHaUKDsxFc86VkhjV0xpWtQcrrr+MfbfcTj9XInvMFyl3nYFM9we+nn bMeOnTa4m9khabTb4fnsu/gb82EQVQASDmyQEJUUlPxuIM+8DBbZr1K214ZCKDFTOno12nHs6T/ UIG2+xWvWwf4qoSlRbA+ah1Y9y99pnWPYFiMq2BtHuFqQ/T5V59rtLQ0j3vEAtOpd X-Received: by 2002:a05:620a:2a0f:b0:93f:2aa8:c550 with SMTP id af79cd13be357-949ba95df8cmr6336864785a.26.1796078431763; Mon, 30 Nov 2026 14:40:31 -0800 (PST) X-Received: by 2002:a05:620a:2a0f:b0:93f:2aa8:c550 with SMTP id af79cd13be357-949ba95df8cmr6336858685a.26.1796078431050; Mon, 30 Nov 2026 14:40:31 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab65cb42absm66697503f8f.1.2026.11.30.14.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:40:30 -0800 (PST) From: Srinivas Kandagatla To: Vinod Koul , Bard Liao Cc: Pierre-Louis Bossart , Sanyog Kale , Mark Brown , Jonathan Corbet , Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] soundwire: stream: add multi-direction stream lifecycle API Date: Mon, 30 Nov 2026 22:40:17 +0000 Message-ID: <20261130224018.20359-2-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130224018.20359-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261130224018.20359-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: BtwFj1EZD9Ossy9W7bJZqpwBZCpo8Dgk X-Proofpoint-GUID: BtwFj1EZD9Ossy9W7bJZqpwBZCpo8Dgk X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA5MSBTYWx0ZWRfXwCLiuj3/xU9J ctQcu6kMnB6hdRzB9lk74A2XlvpUhpKoLX95D0NKUAtbHnirCaNIUvBtXI2B74LrB2jcRFET8Rn 3DinuzNKjWJxP8PKDbU6G7CBd+Ec+GSIgf9jx18f+xP5IbA5BDppktQkaZIlBqtiBJCtPOM0vCG Mq3F5mWLaoAjUBvs5xrBq227wyEUL4wnjLQSIYClMfnsx7Ta80g4Nk8i6pTcVT4X5j1xnocEYje LMFBLF75JZlkVJ+XSFwVrPzKfIE1MmMjLKxL7vM2uNb5BQf+thVfogmHQFW3c/H6BYLZmlGcteF cNuSebYq5jXmE+95Wisw/Sm3haqlZeExAG7XsTDrFr9IJ7ZCSCyUdVxhNJX8LwW7Wtn8owV7EVN PvIxoMRnk1UNPgBc+nKY2tO5+EMjqH64Ola0BcjeT8T6ihCyt5S8imf9mrPR/HP6i70zzUGj3+e Mys5yS7U+/MbazXiwWw== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA5MSBTYWx0ZWRfXyme5eXWikjG0 T4DR4MEQ/TCEHTOAMWGXuhZudUJ9HD1zo9Ry9lztGh9C0OiGViaFowVHVWNS+SI7mcJzMynhwyS qccFvDq5W1ex//cxzLloT42wpog12fE= X-Authority-Analysis: v=2.4 cv=V5joQuni c=1 sm=1 tr=0 ts=6b0dfb65 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=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=b_-vVuZpxMNaxh346j0A:9 a=NFOGd7dJGGMPyQGDc5-O: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-11-30_05,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300091 Add sdw_multi_direction_stream, a lightweight group that aggregates one or more sdw_stream_runtimes that share a lifecycle on the bus. New entry points: sdw_multi_direction_stream_alloc / _release / _add sdw_prepare_multi_direction_stream sdw_enable_multi_direction_stream sdw_disable_multi_direction_stream sdw_deprepare_multi_direction_stream A multi-direction stream group with a single constituent behaves exactly like the direct sdw_prepare_stream() path, so callers can use this API unconditionally without having to branch on how many directions a dai_link uses. Groups with more than one constituent currently iterate the per-stream primitives with all-or-nothing rollback on prepare/enable errors. This already gives callers a uniform API and well-defined failure semantics but still triggers one bank switch per constituent stream. The follow-up step is to split _sdw_prepare_stream() and _sdw_enable_stream() into "params" and "commit" halves so the group can program every constituent stream's bus parameters first and then trigger a single do_bank_switch() across them. That is left out of this change to keep the diff reviewable and because it touches the SoundWire core state machine; it can land on top without changing the public API introduced here. Signed-off-by: Srinivas Kandagatla --- Documentation/driver-api/soundwire/stream.rst | 43 ++++ drivers/soundwire/stream.c | 184 ++++++++++++++++++ include/linux/soundwire/sdw.h | 37 ++++ 3 files changed, 264 insertions(+) diff --git a/Documentation/driver-api/soundwire/stream.rst b/Documentation/driver-api/soundwire/stream.rst index 58b05f2d0b0e..c8f593f2ee4f 100644 --- a/Documentation/driver-api/soundwire/stream.rst +++ b/Documentation/driver-api/soundwire/stream.rst @@ -518,6 +518,49 @@ typically called during a dailink .shutdown() callback, which clears the stream pointer for all DAIS connected to a stream and releases the memory allocated for the stream. +Multi-direction stream lifecycle +================================ + +Some dailinks run more than one sdw_stream_runtime that must come up +and go down together on the bus: for example a WSA playback link whose +V/I-sense capture ports have to track playback prepare/enable, or any +multi-direction codec-codec link where the FE opens a single substream +but the BE drives one runtime per direction. + +The SoundWire core exposes a lightweight group, sdw_multi_direction_stream, +that aggregates one or more sdw_stream_runtimes and lets the caller +drive the shared lifecycle through a single API: + +.. code-block:: c + + struct sdw_multi_direction_stream *sdw_multi_direction_stream_alloc(const char *name); + void sdw_multi_direction_stream_release(struct sdw_multi_direction_stream *md); + int sdw_multi_direction_stream_add(struct sdw_multi_direction_stream *md, + struct sdw_stream_runtime *stream); + + int sdw_prepare_multi_direction_stream(struct sdw_multi_direction_stream *md); + int sdw_enable_multi_direction_stream(struct sdw_multi_direction_stream *md); + int sdw_disable_multi_direction_stream(struct sdw_multi_direction_stream *md); + int sdw_deprepare_multi_direction_stream(struct sdw_multi_direction_stream *md); + +A group with a single constituent is handled by calling the matching +sdw_prepare_stream() / sdw_enable_stream() / ... directly, so callers +sdw_prepare_stream() / sdw_enable_stream() / ... directly, so callers +that may or may not need more than one direction can use this API +unconditionally without branching on the count. + +With more than one constituent the primitives iterate the per-stream +calls in insertion order, with all-or-nothing rollback on prepare and +enable errors: on failure at step N the API tears down streams 0..N-1 +in reverse order before returning the error, so the bus is left in the +same state it was in before the call. + +Current limitation: each constituent still triggers its own bank +switch, so a two-direction group costs two switches on prepare and two +on enable. The public API is final; a later change can split the +per-stream primitives into "params" and "commit" halves so the group +can program every constituent's bus parameters first and then issue a +single do_bank_switch(), without breaking callers. + Not Supported ============= diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index eccb279ea662..84d349c6663f 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -1884,6 +1884,208 @@ int sdw_deprepare_stream(struct sdw_stream_runtime *stream) } EXPORT_SYMBOL(sdw_deprepare_stream); +/* + * SoundWire multi-direction + * + * The multi-direction acts as a lifecycle coordinator across multiple constituent + * streams. Today the lifecycle primitives (prepare/enable/disable/ + * deprepare) are implemented by iterating sdw_*_stream() on each + * constituent stream; this already gives callers a single API surface + * and a well-defined atomic rollback on error, but still performs one + * bus parameter recompute + bank switch per stream. + * + * TODO: coalesce the per-stream bus programming + bank switch into one + * pass across all constituent streams. This requires splitting + * _sdw_prepare_stream() / _sdw_enable_stream() into "params" and + * "commit" halves so that params for every constituent stream can + * be programmed before a single do_bank_switch() is triggered. + * Left out of this RFC to keep the diff reviewable. + */ + +/** + * sdw_multi_direction_stream_init() - initialise a caller-owned handle + * @md: multi-direction handle to initialise + * @name: identifier used in diagnostics + * + * For callers that embed the handle in their own state (e.g. dai_link + * drvdata) to avoid allocation on PCM hot paths. The paired teardown + * is a no-op; callers must not invoke sdw_multi_direction_stream_release() + * on a handle that was set up with _init(). + */ +void sdw_multi_direction_stream_init(struct sdw_multi_direction_stream *md, + const char *name) +{ + memset(md, 0, sizeof(*md)); + md->name = name; +} +EXPORT_SYMBOL(sdw_multi_direction_stream_init); + +/** + * sdw_multi_direction_stream_alloc() - allocate a SoundWire multi-direction + * @name: identifier used in diagnostics + * + * Return: a new multi-direction handle, or NULL on failure. + */ +struct sdw_multi_direction_stream *sdw_multi_direction_stream_alloc(const char *name) +{ + struct sdw_multi_direction_stream *md; + + md = kzalloc(sizeof(*md), GFP_KERNEL); + if (!md) + return NULL; + md->name = name; + return md; +} +EXPORT_SYMBOL(sdw_multi_direction_stream_alloc); + +/** + * sdw_multi_direction_stream_release() - release a SoundWire multi-direction + * @md: multi-direction handle + * + * The constituent sdw_stream_runtimes are not freed; the caller still + * owns them and must release them with sdw_release_stream(). + */ +void sdw_multi_direction_stream_release(struct sdw_multi_direction_stream *md) +{ + if (!md) + return; + kfree(md); +} +EXPORT_SYMBOL(sdw_multi_direction_stream_release); + +/** + * sdw_multi_direction_stream_add() - add a stream to a multi-direction + * @md: multi-direction handle + * @stream: stream to add + * + * Return: 0 on success, -ENOSPC if the multi-direction is full. + */ +int sdw_multi_direction_stream_add(struct sdw_multi_direction_stream *md, + struct sdw_stream_runtime *stream) +{ + if (!md || !stream) + return -EINVAL; + if (md->num_streams >= SDW_MULTI_DIRECTION_STREAM_MAX) + return -ENOSPC; + md->streams[md->num_streams++] = stream; + return 0; +} +EXPORT_SYMBOL(sdw_multi_direction_stream_add); + +static int multi_direction_rollback_prepare(struct sdw_multi_direction_stream *md, int upto) +{ + int i; + + for (i = upto - 1; i >= 0; i--) + sdw_deprepare_stream(md->streams[i]); + return 0; +} + +static int multi_direction_rollback_enable(struct sdw_multi_direction_stream *md, int upto) +{ + int i; + + for (i = upto - 1; i >= 0; i--) + sdw_disable_stream(md->streams[i]); + return 0; +} + +/** + * sdw_prepare_multi_direction_stream() - prepare every constituent stream + * @md: multi-direction handle + * + * On error, any streams that were prepared successfully are rolled back + * (deprepared) so the caller always sees an all-or-nothing outcome. + */ +int sdw_prepare_multi_direction_stream(struct sdw_multi_direction_stream *md) +{ + int ret, i; + + if (!md || !md->num_streams) + return -EINVAL; + + for (i = 0; i < md->num_streams; i++) { + ret = sdw_prepare_stream(md->streams[i]); + if (ret) { + multi_direction_rollback_prepare(md, i); + return ret; + } + } + return 0; +} +EXPORT_SYMBOL(sdw_prepare_multi_direction_stream); + +/** + * sdw_enable_multi_direction_stream() - enable every constituent stream + * @md: multi-direction handle + * + * On error, any streams that were enabled successfully are rolled back + * (disabled) so the caller always sees an all-or-nothing outcome. + */ +int sdw_enable_multi_direction_stream(struct sdw_multi_direction_stream *md) +{ + int ret, i; + + if (!md || !md->num_streams) + return -EINVAL; + + for (i = 0; i < md->num_streams; i++) { + ret = sdw_enable_stream(md->streams[i]); + if (ret) { + multi_direction_rollback_enable(md, i); + return ret; + } + } + return 0; +} +EXPORT_SYMBOL(sdw_enable_multi_direction_stream); + +/** + * sdw_disable_multi_direction_stream() - disable every constituent stream + * @md: multi-direction handle + * + * Disables are best-effort; the first error is returned but all streams + * are walked so the bus ends up quiesced. + */ +int sdw_disable_multi_direction_stream(struct sdw_multi_direction_stream *md) +{ + int ret, first_err = 0, i; + + if (!md || !md->num_streams) + return -EINVAL; + + for (i = md->num_streams - 1; i >= 0; i--) { + ret = sdw_disable_stream(md->streams[i]); + if (ret && !first_err) + first_err = ret; + } + return first_err; +} +EXPORT_SYMBOL(sdw_disable_multi_direction_stream); + +/** + * sdw_deprepare_multi_direction_stream() - deprepare every constituent stream + * @md: multi-direction handle + * + * Deprepares are best-effort; the first error is returned but all + * streams are walked. + */ +int sdw_deprepare_multi_direction_stream(struct sdw_multi_direction_stream *md) +{ + int ret, first_err = 0, i; + + if (!md || !md->num_streams) + return -EINVAL; + + for (i = md->num_streams - 1; i >= 0; i--) { + ret = sdw_deprepare_stream(md->streams[i]); + if (ret && !first_err) + first_err = ret; + } + return first_err; +} +EXPORT_SYMBOL(sdw_deprepare_multi_direction_stream); + + * - A playback-only ASoC FE whose BE link carries both the audio stream + * (RX direction on the wire) and a companion V/I-sense capture + * stream (TX direction) that the DSP consumes; the two directions + * share the same clock and must be enabled atomically. + * - Companion-amp device-to-device (D2D) streams that mirror a host + * stream. + * - Any set of streams that need one bank switch rather than N. + * + * Each stream still lives in its own sdw_stream_runtime; the multi-direction is a + * lightweight container that coordinates the lifecycle. + */ +#define SDW_MULTI_DIRECTION_STREAM_MAX 4 + +struct sdw_multi_direction_stream { + const char *name; + struct sdw_stream_runtime *streams[SDW_MULTI_DIRECTION_STREAM_MAX]; + unsigned int num_streams; +}; + +struct sdw_multi_direction_stream *sdw_multi_direction_stream_alloc(const char *name); +void sdw_multi_direction_stream_release(struct sdw_multi_direction_stream *md); +int sdw_multi_direction_stream_add(struct sdw_multi_direction_stream *md, + struct sdw_stream_runtime *stream); + +int sdw_prepare_multi_direction_stream(struct sdw_multi_direction_stream *md); +int sdw_enable_multi_direction_stream(struct sdw_multi_direction_stream *md); +int sdw_disable_multi_direction_stream(struct sdw_multi_direction_stream *md); +int sdw_deprepare_multi_direction_stream(struct sdw_multi_direction_stream *md); + int sdw_stream_add_master(struct sdw_bus *bus, struct sdw_stream_config *stream_config, const struct sdw_port_config *port_config, base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8