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=1796041059; b=PoGdkEKJqCSHMI7WiH7Rw5RfWGInHCEQh8G+TAB/wGG8mE8F7/My8YvfUJ33oSq5KrCp 4B0H4KHO/zdReKXa1Qw5/5LpJ7aCTOMYSQAZ4UoLNq09yUV8KVIZqZVrlWL9e6RWbtkV2 RUstdAnSxAg2d49fYAGY2GrZBfFsnUHnmhAd4R6VMquSOjOhrzegOUmFTmCBDyXPFIq2F AevEFFdzkj3/2TRYMBea/W9AMKWscjxJXyqZ0MvxzF97tSnkIymO2oD3tiy4qca6xLjq+ EM76tG/vfZjFe9b61s5i15l/b45iFAN5AG8Vxnn4GilSa0arV17BpmwR1f2dzShEflQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796041059; 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:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=m1huR+Ihl9NC5wj6auLF35Pdmt59isFDadwkYzW6/tk=; b=VHl/uYnZ+Eh+RBO5PY+xR0glaTguqRCgmv6brPYO0XqA5zutnf0jsXemOA815uwTyVeI eDR6YjmccBZRw2Oxe0bjk3sgkpqLnwpVGcq0V/T4ydyj9swlsOQk8o0bVZYKoNa1Q4iW4 mmIvlRMsKAekJlHDAeiK86YiwEZcNIxTDiz1rrwAoCo8EJSGRerSR6h/jwIpjdMpnNRut r1pvxMgjK5VdPPOR2GAu1P3T9MTJnLvR9m0pjK0h8mR9ZEASvedmmFOWXczgTjKDwp/iL TWMEr8awxsAdI0ZHhXBdL28u27M0L9ANViH8dN8ihe4sUYkfsPmmC6QWHA5eU7GcmVQ== 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=fdI81mND; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=IwH4XVwf; 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 A4974606A32A for ; Mon, 30 Nov 2026 12:17:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4974606A32A 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=fdI81mND; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=IwH4XVwf Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUC5Cjt2955507 for ; Mon, 30 Nov 2026 12:17:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=m1huR+Ihl9NC5wj6auLF35Pdmt59isFDadw kYzW6/tk=; b=fdI81mND7N9R34HOjvZSeczkEjE/9zY+1Zyx20KS227l8mKjm5L swuzPGYoJK/D/nWeWpf6SSflJbgOJJ4dvRxjH3tokA7ytgZ+CLoUwt5PJQKtjS+0 yI5NtmbGOReZEJ213mNZ16aPhgc5FjqCgx9eoVeqwBOl/0eXwIgyO9YVcGD5d+ad eWnpNXLwqhQNhLaintimdr15THZikV/koXGldyOprQplxediXGb34QRuYFG24wBQ 27a1rjjSPqGByxD3zPRpIm98nQZ1AXflMSsXoqIZSG34Ye8xHZMaqJM6ymWGHh7U FyRqKeFwdlovAEHbR3hge9+wTt5Mh9OW/OA== 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 4j98ud81hn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 12:17:37 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-93f37c94ceeso1770200585a.1 for ; Mon, 30 Nov 2026 04:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796041057; x=1796645857; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=m1huR+Ihl9NC5wj6auLF35Pdmt59isFDadwkYzW6/tk=; b=IwH4XVwfu1MkznOKsaDdzTrSDxsP4qqzYKtPMisKndmiTCm5zens/An/42OUGCssBd EwoBNOkaJawrAgFx8IpRmBI8CfuV0fGFYT5gVsIUiygnZ8BNQc6E2kExFco0DPBLm3N1 OOlDrStriJd7ebZS2SEjCJR2/hU3fN+h84j8xvTz2JvKdXEJ3zGDpa6qdBtJvSWCEbPd 8sh9g1GjDJAB9yPrWIUy4Ws4PYc+JEupzzoovbbKA6SKDXI5v4y9Nr7QmuM/Rg/CWh3Y QXRpI8xBWTYiTew8LnQIzTmRermy/PgOuPbQ8iKLAegGBEmry/fRtkOK5gChdF3rTzaO Plrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796041057; x=1796645857; h=content-transfer-encoding:mime-version: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=m1huR+Ihl9NC5wj6auLF35Pdmt59isFDadwkYzW6/tk=; b=jJQavnZkf/pxoeO6fXTUW/allMtSPZ+WWj97Bkj8imvq+H7kCI4xExeCDmgI1QPSF4 bMmCAY2hNqcme0CNdVT/MCyVfHQ/j1T0LG8ieo2S1g/+poJwj3rczFwVqh06UiatTEvw /p/TJmzTEacsz+pKLOux35ycLGXVpPw13iMEYEwJaa26Gq+xrK0jVSnCmI1XPNlVHvDj gBqqBndfCpnTNBO1fGR3j9hRUK9rzRfUE+sXRGUqLJHL0Jzg2/cZGaOJC9VlpVtQ4dG/ FRIDEcoCX+ohsmxSdTfMpTAimt4tyewmjpBgHGy93yeUX+1DrOPhBa914DDP6LtLU14s SWbg== X-Forwarded-Encrypted: i=1; AL+hErGNr6oDSzw777uj0QPxJ7+D18uZp7JhP2mA2i7uQZtp5aUm2fuXqoHYeNoGQYlR3bARxcEjUt3kxOiMZIk=@vger.kernel.org X-Gm-Message-State: APuU4Z9Y3g4gsunPQ9dwuYNqX0vdq1PwIWMNZ9QG6yUKAXpcvfVz4ZhZ As3K1py2dH9etZhYnr/TQnP1SnKkksWlM50Qz7X/L3ORNVc3P7e/T+uvmcQznM96Z6XuOWm3Z33 0Iys0uSZNHCuiuPKlSc4T+DM9E3t6jucEL8+2qDoG5N0f5hpElSD6MhGESQTTBCwQz40= X-Gm-Gg: AZFdTZcQ1ADUCFkYE9OFxK0c4Yw/s6BVBMl+IO3lVXRgcvnvXtC58wB+lYj372RzDAL MYi3F+C5NMNy/9YirwWAHez7NrKNX3tt5bRvD9uUbmjl7lCZHU4srxZFjiRzJTm/Cr6FPlFQgRt cjJlr26v/S32OgeGzUsCEbOpfkwL4oWnauP9Jdtp+kDfU6F7i94NkoPrFwETWvGSLp3O1dwhppP eopWsLIGNclI2g0Uj5w+4i9QFOAUAk3kCc9QqGt7xoMX7dw+DEQT3Cao5/VFsS2y0ctWid4Ut2W s4iI+HazeNRKkg0xsbZ3ddjZDjELNm+ejALbd8VWTRJxZyWI2zOhmeAFBUP3gHribi/04YmlL66 5u+HeIzqXyFyytZ/nJeYnFdzsujEfB2E/anw7WC/df0gPRXyu12EYjAJj/Qsze4qc X-Received: by 2002:a05:620a:372b:b0:949:70c5:c0ce with SMTP id af79cd13be357-949b35ac8e0mr6066968785a.19.1796041055571; Mon, 30 Nov 2026 04:17:35 -0800 (PST) X-Received: by 2002:a05:620a:372b:b0:949:70c5:c0ce with SMTP id af79cd13be357-949b35ac8e0mr6066958785a.19.1796041054812; Mon, 30 Nov 2026 04:17:34 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm765280795e9.0.2026.11.30.04.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 04:17:34 -0800 (PST) From: Srinivas Kandagatla To: Charles Keepax , Maciej Strozek , Bard Liao , Pierre-Louis Bossart , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Mark Brown Cc: linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH] ASoC: SDCA: push port+cluster caps into DAI driver properties Date: Mon, 30 Nov 2026 12:17:02 +0000 Message-ID: <20261130121702.321036-1-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 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: AW1haW4tMjYxMTMwMDA0NyBTYWx0ZWRfX5z3FSiaSo+Nl I56/Q5X9/RHI2bpGKHxOIzr3UTaTy4VFMyS3C59Uw/5FfiEhJEzV3oaAxYklky+ys43wz4R88ee Z1KE9hOqNVOE5psDabwhLidBhKiIX30= X-Authority-Analysis: v=2.4 cv=edqo7LEH c=1 sm=1 tr=0 ts=6b0d6961 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8 a=sVLhwBYB6D-3FAFupGQA:9 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA0NyBTYWx0ZWRfX9+UXDvxgkTwh LotxZb1v3mxE23LSjM548CUTkySF28Fku+AZkdyeCsbjlnKNxrocYYnA5eU0zEh+06+tf4nKcaG a4SME9myV4YjFFZsIHwT/+ETF06q1CU+iO13fzw3DwYt2CwTv6yJoMe2vZI0IC70etzJpHzGrna bOOXQGKLVTTSnAArzOXsD9e5GfVh4alFdomqiYYxgvAOTnP7Dh4RO8WU2EYfKgFrt0+i/rR/Bsr Dn1rPLNt4GhS7CiFgd6R0eOoAJ4q9PGy07fM3K6ZTbgKltOhfhPcBfUmbHZEHwUuDikyc+NWVeS CNldfncB98xUaEolKX6CBuF2+1tNfZljjGCcIZookN1SiSZcQz4JrZHb1MSkVdEjCOVDUpr7HKe biyrYJ/sqshAPIDuTixJplTtRzGMh+tSIpsT0syd7H3EU1pkVTkPc4rUdBJueH+pGdYPCzehl6C nGkTiqAQgu7sAI/7Lwg== X-Proofpoint-GUID: uiP3a-0DdeWxJHRbUG2xexlUSjoMYRvH X-Proofpoint-ORIG-GUID: uiP3a-0DdeWxJHRbUG2xexlUSjoMYRvH 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_03,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 spamscore=0 adultscore=0 suspectscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300047 sdca_asoc_set_constraints() installed channel and format masks via snd_pcm_hw_constraint_*() from .startup(). dpcm_be_dai_startup() aliases be_substream->runtime to fe_substream->runtime, so those rules leak onto the FE's hw_refine() and the FE wrongly inherits BE-only limits. On Qualcomm LPASS, the WCD9378 headset mic is single-channel on DP2 but exposed as stereo by the FE, and arecord -c 2 fails with "Slave PCM not usable". Resolve the port (and for ITs the cluster) channel bounds and port word-length at DAI registration, and fold them into the DAI driver's snd_soc_pcm_stream.channels_min/max and .formats. BE caps now flow to the FE through DPCM's own merge path (dpcm_runtime_setup_be_chan / _be_format, opt-in per dai_link via dpcm_merged_chan / dpcm_merged_format) and there is no DPCM awareness left in the codec class driver. Drop sdca_asoc_set_constraints() and the sdca_asoc_alloc/free_ constraints() helpers it needed, along with their exports. The only in-tree caller is the class-function driver and it no longer needs them. Channel count only expresses a contiguous range now, not a sparse mask, but every in-tree SDCA DP port and cluster mask is contiguous so there is no observable loss today. Fixes: 7b0d60dbb468 ("ASoC: SDCA: Add helper to add DAI constraints") Signed-off-by: Srinivas Kandagatla --- include/sound/sdca_asoc.h | 12 +- sound/soc/sdca/sdca_asoc.c | 248 +++++++++++---------------- sound/soc/sdca/sdca_class_function.c | 18 +- 3 files changed, 113 insertions(+), 165 deletions(-) diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h index 76f713e29426..ca6fda2ec389 100644 --- a/include/sound/sdca_asoc.h +++ b/include/sound/sdca_asoc.h @@ -90,17 +90,13 @@ int sdca_asoc_populate_rate_format(struct device *dev, struct sdca_entity *entity, struct snd_soc_pcm_stream *stream); -int sdca_asoc_alloc_constraints(struct snd_soc_dai *dai); -int sdca_asoc_free_constraints(struct snd_soc_dai *dai); -int sdca_asoc_set_constraints(struct device *dev, struct sdw_slave *sdw, - struct regmap *regmap, - struct sdca_function_data *function, - struct snd_pcm_substream *substream, - struct snd_soc_dai *dai); - int sdca_asoc_get_port(struct device *dev, struct regmap *regmap, struct sdca_function_data *function, struct snd_soc_dai *dai); +int sdca_asoc_narrow_dai_caps(struct device *dev, struct sdw_slave *sdw, + struct regmap *regmap, + struct sdca_function_data *function, + struct snd_soc_dai_driver *dais, int num_dais); int sdca_asoc_hw_params(struct device *dev, struct regmap *regmap, struct sdca_function_data *function, struct snd_pcm_substream *substream, diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c index 065108cd5249..3783187114db 100644 --- a/sound/soc/sdca/sdca_asoc.c +++ b/sound/soc/sdca/sdca_asoc.c @@ -1445,49 +1445,6 @@ int sdca_asoc_populate_component(struct device *dev, } EXPORT_SYMBOL_NS(sdca_asoc_populate_component, "SND_SOC_SDCA"); -struct sdca_asoc_constraints { - struct snd_pcm_hw_constraint_list channels; - u64 width; -}; - -/** - * sdca_asoc_alloc_constraints - allocate a constraint structure on the DAI - * @dai: Pointer to the ASoC DAI. - * - * Typically called from DAI probe(). - * - * Return: Returns zero on success, and a negative error code on failure. - */ -int sdca_asoc_alloc_constraints(struct snd_soc_dai *dai) -{ - struct sdca_asoc_constraints *constraints; - - constraints = kzalloc_obj(*constraints); - if (!constraints) - return -ENOMEM; - - snd_soc_dai_set_priv(dai, constraints); - - return 0; -} -EXPORT_SYMBOL_NS(sdca_asoc_alloc_constraints, "SND_SOC_SDCA"); - -/** - * sdca_asoc_free_constraints - free constraint allocations - * @dai: Pointer to the ASoC DAI. - * - * Typically called from DAI remove(). - * - * Return: Returns zero on success, and a negative error code on failure. - */ -int sdca_asoc_free_constraints(struct snd_soc_dai *dai) -{ - kfree(snd_soc_dai_to_priv(dai)); - - return 0; -} -EXPORT_SYMBOL_NS(sdca_asoc_free_constraints, "SND_SOC_SDCA"); - static int get_cluster_mask(struct device *dev, struct sdca_function_data *function, struct sdca_entity *entity, unsigned int *ch_mask) { @@ -1520,14 +1477,13 @@ static int get_cluster_mask(struct device *dev, struct sdca_function_data *funct } static int get_port_masks(struct sdw_slave *sdw, unsigned int port, - struct snd_pcm_substream *substream, - u64 *word_mask, unsigned int *ch_mask) + int stream, u64 *word_mask, unsigned int *ch_mask) { struct sdw_dpn_prop *prop; unsigned int nprop; int i, j; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { prop = sdw->prop.sink_dpn_prop; nprop = hweight32(sdw->prop.sink_ports); } else { @@ -1571,100 +1527,6 @@ static int get_port_masks(struct sdw_slave *sdw, unsigned int port, return -ENODEV; } -/** - * sdca_asoc_set_constraints - constrain channels available on a DAI - * @dev: Pointer to the device, used for error messages. - * @sdw: Pointer to the SoundWire peripheral device. - * @regmap: Pointer to the Function register map. - * @function: Pointer to the Function information. - * @substream: Pointer to the PCM substream. - * @dai: Pointer to the ASoC DAI. - * - * Typically called from startup(). - * - * Return: Returns zero on success, and a negative error code on failure. - */ -int sdca_asoc_set_constraints(struct device *dev, struct sdw_slave *sdw, - struct regmap *regmap, - struct sdca_function_data *function, - struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - static const unsigned int channel_list[] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - }; - struct sdca_asoc_constraints *constraints = snd_soc_dai_to_priv(dai); - struct sdca_entity *entity = &function->entities[dai->id]; - unsigned int port_ch_mask, cluster_ch_mask; - int port; - int ret; - - static_assert(ARRAY_SIZE(channel_list) == SDCA_MAX_CHANNEL_COUNT); - static_assert(sizeof(cluster_ch_mask) * BITS_PER_BYTE >= SDCA_MAX_CHANNEL_COUNT); - - /* FIXME: Currently only a single unshared port is supported */ - port = sdca_asoc_get_port(dev, regmap, function, dai); - if (port < 0) - return port; - - ret = get_port_masks(sdw, port, substream, &constraints->width, &port_ch_mask); - if (ret < 0) { - dev_err(dev, "%s: no properties for port %d\n", entity->label, port); - return ret; - } - - /* FIXME: OTs should inherit cluster information */ - if (entity->type == SDCA_ENTITY_TYPE_IT) { - ret = get_cluster_mask(dev, function, entity, &cluster_ch_mask); - if (ret) - return ret; - } else { - cluster_ch_mask = UINT_MAX; - } - - constraints->channels.count = ARRAY_SIZE(channel_list); - constraints->channels.list = channel_list; - constraints->channels.mask = cluster_ch_mask; - /* - * FIXME: dpcm_be_dai_startup() aliases be_substream->runtime to - * fe_substream->runtime, so a per-substream hw_constraint installed - * here lands on the FE's hw_refine(). The FE's channel count can - * differ from the SoundWire port (e.g. a DSP re-channelizes between - * the port and the FE PCM), so skip the port mask on DPCM BE links. - * The proper fix is in DPCM, not here. - */ - if (!snd_soc_substream_to_rtd(substream)->dai_link->no_pcm) - constraints->channels.mask &= port_ch_mask; - - if (!constraints->channels.mask || !constraints->width) { - dev_err(dev, "%s: no valid constraint masks channel: %#x,%#x width: %#llx\n", - entity->label, cluster_ch_mask, port_ch_mask, constraints->width); - return -EINVAL; - } - - ret = snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - &constraints->channels); - if (ret) { - dev_err(dev, "%s: failed to add channel constraint: %d\n", - entity->label, ret); - return ret; - } - - ret = snd_pcm_hw_constraint_mask64(substream->runtime, - SNDRV_PCM_HW_PARAM_FORMAT, - constraints->width); - if (ret) { - dev_err(dev, "%s: failed to add bit width constraint: %d\n", - entity->label, ret); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_NS(sdca_asoc_set_constraints, "SND_SOC_SDCA"); - /** * sdca_asoc_get_port - return SoundWire port for a DAI * @dev: Pointer to the device, used for error messages. @@ -1677,11 +1539,10 @@ EXPORT_SYMBOL_NS(sdca_asoc_set_constraints, "SND_SOC_SDCA"); * Return: Returns a positive port number on success, and a negative error * code on failure. */ -int sdca_asoc_get_port(struct device *dev, struct regmap *regmap, - struct sdca_function_data *function, - struct snd_soc_dai *dai) +static int sdca_asoc_get_entity_port(struct device *dev, struct regmap *regmap, + struct sdca_function_data *function, + struct sdca_entity *entity) { - struct sdca_entity *entity = &function->entities[dai->id]; struct sdca_control_range *range; unsigned int reg, val; int sel = -EINVAL; @@ -1737,8 +1598,107 @@ int sdca_asoc_get_port(struct device *dev, struct regmap *regmap, dev_err(dev, "%s: no dataport found\n", entity->label); return -ENODEV; } + +int sdca_asoc_get_port(struct device *dev, struct regmap *regmap, + struct sdca_function_data *function, + struct snd_soc_dai *dai) +{ + return sdca_asoc_get_entity_port(dev, regmap, function, + &function->entities[dai->id]); +} EXPORT_SYMBOL_NS(sdca_asoc_get_port, "SND_SOC_SDCA"); +/** + * sdca_asoc_narrow_dai_caps - narrow DAI channel and format caps to the port + * @dev: Pointer to the device, used for error messages. + * @sdw: Pointer to the SoundWire peripheral device. + * @regmap: Pointer to the Function register map. + * @function: Pointer to the Function information. + * @dais: DAI driver array populated by sdca_asoc_populate_dais(). + * @num_dais: Number of entries in @dais. + * + * Return: Zero on success, and a negative error code on failure. + */ +int sdca_asoc_narrow_dai_caps(struct device *dev, struct sdw_slave *sdw, + struct regmap *regmap, + struct sdca_function_data *function, + struct snd_soc_dai_driver *dais, int num_dais) +{ + int i; + + for (i = 0; i < num_dais; i++) { + struct snd_soc_dai_driver *drv = &dais[i]; + struct snd_soc_pcm_stream *stream; + struct sdca_entity *entity; + unsigned int port_ch_mask, cluster_ch_mask, combined; + int port, stream_dir, ret; + u64 word_mask; + + if (drv->id >= function->num_entities) { + dev_dbg(dev, "dai[%d]: id %d out of range (num_entities %d)\n", + i, drv->id, function->num_entities); + continue; + } + + entity = &function->entities[drv->id]; + + switch (entity->type) { + case SDCA_ENTITY_TYPE_IT: + stream = &drv->playback; + stream_dir = SNDRV_PCM_STREAM_PLAYBACK; + break; + case SDCA_ENTITY_TYPE_OT: + stream = &drv->capture; + stream_dir = SNDRV_PCM_STREAM_CAPTURE; + break; + default: + continue; + } + + if (!entity->iot.is_dataport) + continue; + + port = sdca_asoc_get_entity_port(dev, regmap, function, entity); + if (port < 0) { + dev_err(dev, "%s: cannot resolve port: %d\n", + entity->label, port); + return port; + } + + ret = get_port_masks(sdw, port, stream_dir, &word_mask, + &port_ch_mask); + if (ret < 0) { + dev_err(dev, "%s: no properties for port %d\n", + entity->label, port); + return ret; + } + + if (entity->type == SDCA_ENTITY_TYPE_IT) { + ret = get_cluster_mask(dev, function, entity, + &cluster_ch_mask); + if (ret) { + dev_err(dev, "%s: cannot resolve cluster mask: %d\n", + entity->label, ret); + return ret; + } + } else { + cluster_ch_mask = UINT_MAX; + } + + combined = port_ch_mask & cluster_ch_mask; + if (combined) { + stream->channels_min = __ffs(combined) + 1; + stream->channels_max = fls(combined); + } + + if (word_mask) + stream->formats &= word_mask; + } + + return 0; +} +EXPORT_SYMBOL_NS(sdca_asoc_narrow_dai_caps, "SND_SOC_SDCA"); + static int set_cluster(struct device *dev, struct regmap *regmap, struct sdca_function_data *function, struct sdca_entity *entity, unsigned int channels) diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c index 2483ecca7469..afee01a3645c 100644 --- a/sound/soc/sdca/sdca_class_function.c +++ b/sound/soc/sdca/sdca_class_function.c @@ -117,16 +117,6 @@ static const struct regmap_sdw_mbq_cfg class_function_mbq_config = { .timeout_us = 10000, }; -static int class_function_startup(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - struct class_function_drv *drv = snd_soc_component_get_drvdata(dai->component); - struct sdw_slave *sdw = dev_to_sdw_dev(drv->dev->parent); - - return sdca_asoc_set_constraints(drv->dev, sdw, drv->regmap, drv->function, - substream, dai); -} - static int class_function_sdw_add_peripheral(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -188,9 +178,6 @@ static int class_function_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stre } static const struct snd_soc_dai_ops class_function_sdw_ops = { - .probe = sdca_asoc_alloc_constraints, - .remove = sdca_asoc_free_constraints, - .startup = class_function_startup, .set_stream = class_function_sdw_set_stream, .hw_params = class_function_sdw_add_peripheral, .hw_free = class_function_sdw_remove_peripheral, @@ -441,6 +428,11 @@ static int class_function_probe(struct auxiliary_device *auxdev, if (ret) goto err_pm; + ret = sdca_asoc_narrow_dai_caps(dev, core->sdw, drv->regmap, + drv->function, dais, num_dais); + if (ret) + goto err_pm; + ret = devm_snd_soc_register_component(dev, cmp_drv, dais, num_dais); if (ret) { dev_err_probe(dev, ret, "failed to register component\n"); -- 2.53.0