mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: SDCA: push port+cluster caps into DAI driver properties
@ 2026-11-30 12:17 Srinivas Kandagatla
  2026-11-30 14:35 ` Mark Brown
  2026-11-30 15:21 ` Charles Keepax
  0 siblings, 2 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2026-11-30 12:17 UTC (permalink / raw)
  To: Charles Keepax, Maciej Strozek, Bard Liao, Pierre-Louis Bossart,
	Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown
  Cc: linux-sound, patches, linux-kernel, Srinivas Kandagatla

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 <srinivas.kandagatla@oss.qualcomm.com>
---
 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-30 21:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 12:17 [PATCH] ASoC: SDCA: push port+cluster caps into DAI driver properties Srinivas Kandagatla
2026-11-30 14:35 ` Mark Brown
2026-11-30 15:21 ` Charles Keepax
2026-11-30 15:32   ` Charles Keepax
2026-11-30 21:39     ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®