From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: lgirdwood@gmail.com, yung-chuan.liao@linux.intel.com,
pierre-louis.bossart@linux.dev, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org, patches@opensource.cirrus.com
Subject: [PATCH v2 2/3] ASoC: SDCA: Factor out helper for creating mask of Cluster channels
Date: Fri, 6 Nov 2026 15:09:25 +0000 [thread overview]
Message-ID: <20261106150926.2587108-3-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20261106150926.2587108-1-ckeepax@opensource.cirrus.com>
Factor out the code that builds a mask of the allowed channels from the
Cluster information. This is slightly cleaner and prepares for
additional constraints to be added to sdca_asoc_set_constraints().
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
Changes since v1:
- Use BIT macro for the channel mask
- Some minor knock on changes from the new first patch in the series.
sound/soc/sdca/sdca_asoc.c | 64 +++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c
index b8bde56298706..be1b4c0075796 100644
--- a/sound/soc/sdca/sdca_asoc.c
+++ b/sound/soc/sdca/sdca_asoc.c
@@ -1476,6 +1476,37 @@ int sdca_asoc_free_constraints(struct snd_soc_dai *dai)
}
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)
+{
+ struct sdca_control_range *range;
+ struct sdca_control *control;
+ int i;
+
+ control = sdca_selector_find_control(dev, entity, SDCA_CTL_IT_CLUSTERINDEX);
+ if (!control)
+ return -EINVAL;
+
+ range = sdca_control_find_range(dev, entity, control, SDCA_CLUSTER_NCOLS, 0);
+ if (!range)
+ return -EINVAL;
+
+ *ch_mask = 0;
+
+ for (i = 0; i < range->rows; i++) {
+ int clusterid = sdca_range(range, SDCA_CLUSTER_CLUSTERID, i);
+ struct sdca_cluster *cluster;
+
+ cluster = sdca_id_find_cluster(dev, function, clusterid);
+ if (!cluster)
+ return -ENODEV;
+
+ *ch_mask |= BIT(cluster->num_channels - 1);
+ }
+
+ return 0;
+}
+
/**
* sdca_asoc_set_constraints - constrain channels available on a DAI
* @dev: Pointer to the device, used for error messages.
@@ -1499,42 +1530,25 @@ int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap,
};
struct sdca_asoc_constraints *constraints = snd_soc_dai_to_priv(dai);
struct sdca_entity *entity = &function->entities[dai->id];
- struct sdca_control_range *range;
- struct sdca_control *control;
- unsigned int channel_mask = 0;
- int i, ret;
+ unsigned int cluster_ch_mask;
+ int ret;
static_assert(ARRAY_SIZE(channel_list) == SDCA_MAX_CHANNEL_COUNT);
- static_assert(sizeof(channel_mask) * BITS_PER_BYTE >= SDCA_MAX_CHANNEL_COUNT);
+ static_assert(sizeof(cluster_ch_mask) * BITS_PER_BYTE >= SDCA_MAX_CHANNEL_COUNT);
if (entity->type != SDCA_ENTITY_TYPE_IT)
return 0;
- control = sdca_selector_find_control(dev, entity, SDCA_CTL_IT_CLUSTERINDEX);
- if (!control)
- return -EINVAL;
-
- range = sdca_control_find_range(dev, entity, control, SDCA_CLUSTER_NCOLS, 0);
- if (!range)
- return -EINVAL;
-
- for (i = 0; i < range->rows; i++) {
- int clusterid = sdca_range(range, SDCA_CLUSTER_CLUSTERID, i);
- struct sdca_cluster *cluster;
-
- cluster = sdca_id_find_cluster(dev, function, clusterid);
- if (!cluster)
- return -ENODEV;
-
- channel_mask |= (1 << (cluster->num_channels - 1));
- }
+ ret = get_cluster_mask(dev, function, entity, &cluster_ch_mask);
+ if (ret)
+ return ret;
dev_dbg(dev, "%s: set channel constraint mask: %#x\n",
- entity->label, channel_mask);
+ entity->label, cluster_ch_mask);
constraints->channels.count = ARRAY_SIZE(channel_list);
constraints->channels.list = channel_list;
- constraints->channels.mask = channel_mask;
+ constraints->channels.mask = cluster_ch_mask;
ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_CHANNELS,
--
2.47.3
next prev parent reply other threads:[~2026-11-06 15:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 15:09 [PATCH v2 0/3] Add SoundWire port constraints into SDCA stream Charles Keepax
2026-11-06 15:09 ` [PATCH v2 1/3] ASoC: SDCA: Move DAI constraint allocation Charles Keepax
2026-11-06 15:09 ` Charles Keepax [this message]
2026-11-06 15:09 ` [PATCH v2 3/3] ASoC: SDCA: Add port constraints into sdca_asoc_set_constraints() Charles Keepax
2026-11-06 16:35 ` Charles Keepax
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106150926.2587108-3-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®