* [PATCH v4 1/4] ALSA: pcm: Add snd_pcm_add_named_chmap_ctls() for custom control names
2026-11-24 10:57 [PATCH v4 0/4] ASoC: qcom: x1e80100: allow WSA channel map override Abel Vesa
@ 2026-11-24 10:57 ` Abel Vesa
2026-11-24 10:57 ` [PATCH v4 2/4] ALSA: pcm: Report writable chmap controls as variable Abel Vesa
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Abel Vesa @ 2026-11-24 10:57 UTC (permalink / raw)
To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai
Cc: Srinivas Kandagatla, linux-sound, linux-arm-msm, linux-kernel,
Abel Vesa
From: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Add snd_pcm_add_named_chmap_ctls() to allow drivers to register channel
map controls with names other than the default "Playback Channel Map"
and "Capture Channel Map".
This is useful for cards exposing several channel map controls, such as
Qualcomm machine drivers with both HDMI/DP and WSA speaker backends,
where a distinct name makes it clear to userspace which backend the
control belongs to.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
include/sound/pcm.h | 6 ++++++
sound/core/pcm_lib.c | 48 ++++++++++++++++++++++++++++++++++++++----------
2 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 04f58c2ec5c6..eff01f57b45f 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -1502,6 +1502,12 @@ extern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
#define SND_PCM_CHMAP_MASK_246 (SND_PCM_CHMAP_MASK_24 | (1U << 6))
#define SND_PCM_CHMAP_MASK_2468 (SND_PCM_CHMAP_MASK_246 | (1U << 8))
+int snd_pcm_add_named_chmap_ctls(struct snd_pcm *pcm, int stream,
+ const char *name,
+ const struct snd_pcm_chmap_elem *chmap,
+ int max_channels,
+ unsigned long private_value,
+ struct snd_pcm_chmap **info_ret);
int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
const struct snd_pcm_chmap_elem *chmap,
int max_channels,
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index e13286b51858..6806b1d258f2 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2585,9 +2585,11 @@ static void pcm_chmap_ctl_private_free(struct snd_kcontrol *kcontrol)
}
/**
- * snd_pcm_add_chmap_ctls - create channel-mapping control elements
+ * snd_pcm_add_named_chmap_ctls - create channel-mapping control elements
+ * with a custom name
* @pcm: the assigned PCM instance
* @stream: stream direction
+ * @name: the control element name
* @chmap: channel map elements (for query)
* @max_channels: the max number of channels for the stream
* @private_value: the value passed to each kcontrol's private_value field
@@ -2596,11 +2598,12 @@ static void pcm_chmap_ctl_private_free(struct snd_kcontrol *kcontrol)
* Create channel-mapping control elements assigned to the given PCM stream(s).
* Return: Zero if successful, or a negative error value.
*/
-int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
- const struct snd_pcm_chmap_elem *chmap,
- int max_channels,
- unsigned long private_value,
- struct snd_pcm_chmap **info_ret)
+int snd_pcm_add_named_chmap_ctls(struct snd_pcm *pcm, int stream,
+ const char *name,
+ const struct snd_pcm_chmap_elem *chmap,
+ int max_channels,
+ unsigned long private_value,
+ struct snd_pcm_chmap **info_ret)
{
struct snd_pcm_chmap *info;
struct snd_kcontrol_new knew = {
@@ -2624,10 +2627,7 @@ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
info->stream = stream;
info->chmap = chmap;
info->max_channels = max_channels;
- if (stream == SNDRV_PCM_STREAM_PLAYBACK)
- knew.name = "Playback Channel Map";
- else
- knew.name = "Capture Channel Map";
+ knew.name = name;
knew.device = pcm->device;
knew.count = pcm->streams[stream].substream_count;
knew.private_value = private_value;
@@ -2645,4 +2645,32 @@ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
*info_ret = info;
return 0;
}
+EXPORT_SYMBOL_GPL(snd_pcm_add_named_chmap_ctls);
+
+/**
+ * snd_pcm_add_chmap_ctls - create channel-mapping control elements
+ * @pcm: the assigned PCM instance
+ * @stream: stream direction
+ * @chmap: channel map elements (for query)
+ * @max_channels: the max number of channels for the stream
+ * @private_value: the value passed to each kcontrol's private_value field
+ * @info_ret: store struct snd_pcm_chmap instance if non-NULL
+ *
+ * Create channel-mapping control elements assigned to the given PCM stream(s),
+ * using the default "Playback Channel Map" / "Capture Channel Map" names.
+ * Return: Zero if successful, or a negative error value.
+ */
+int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
+ const struct snd_pcm_chmap_elem *chmap,
+ int max_channels,
+ unsigned long private_value,
+ struct snd_pcm_chmap **info_ret)
+{
+ const char *name = stream == SNDRV_PCM_STREAM_PLAYBACK ?
+ "Playback Channel Map" : "Capture Channel Map";
+
+ return snd_pcm_add_named_chmap_ctls(pcm, stream, name, chmap,
+ max_channels, private_value,
+ info_ret);
+}
EXPORT_SYMBOL_GPL(snd_pcm_add_chmap_ctls);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v4 2/4] ALSA: pcm: Report writable chmap controls as variable
2026-11-24 10:57 [PATCH v4 0/4] ASoC: qcom: x1e80100: allow WSA channel map override Abel Vesa
2026-11-24 10:57 ` [PATCH v4 1/4] ALSA: pcm: Add snd_pcm_add_named_chmap_ctls() for custom control names Abel Vesa
@ 2026-11-24 10:57 ` Abel Vesa
2026-11-24 10:57 ` [PATCH v4 3/4] ASoC: qcom: common: Add SNDRV channel map to Q6 slot helper Abel Vesa
2026-11-24 10:57 ` [PATCH v4 4/4] ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override Abel Vesa
3 siblings, 0 replies; 6+ messages in thread
From: Abel Vesa @ 2026-11-24 10:57 UTC (permalink / raw)
To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai
Cc: Srinivas Kandagatla, linux-sound, linux-arm-msm, linux-kernel,
Abel Vesa
The chmap control TLV always describes the maps as
SNDRV_CTL_TLVT_CHMAP_FIXED, which tells userspace the channel order
cannot be changed.
A chmap control that accepts writes exists precisely so userspace can
reorder the channels. Report such maps as SNDRV_CTL_TLVT_CHMAP_VAR,
so tools like alsa-lib expose the map as freely swappable.
Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
sound/core/pcm_lib.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 6806b1d258f2..219d506fdac2 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2539,11 +2539,15 @@ static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
{
struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
const struct snd_pcm_chmap_elem *map;
+ unsigned int tlv_type = SNDRV_CTL_TLVT_CHMAP_FIXED;
unsigned int __user *dst;
int c, count = 0;
if (!info->chmap)
return -EINVAL;
+ /* A writable control allows userspace to reorder the channels */
+ if (kcontrol->vd[0].access & SNDRV_CTL_ELEM_ACCESS_WRITE)
+ tlv_type = SNDRV_CTL_TLVT_CHMAP_VAR;
if (size < 8)
return -ENOMEM;
if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
@@ -2556,7 +2560,7 @@ static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
continue;
if (size < 8)
return -ENOMEM;
- if (put_user(SNDRV_CTL_TLVT_CHMAP_FIXED, dst) ||
+ if (put_user(tlv_type, dst) ||
put_user(chs_bytes, dst + 1))
return -EFAULT;
dst += 2;
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v4 3/4] ASoC: qcom: common: Add SNDRV channel map to Q6 slot helper
2026-11-24 10:57 [PATCH v4 0/4] ASoC: qcom: x1e80100: allow WSA channel map override Abel Vesa
2026-11-24 10:57 ` [PATCH v4 1/4] ALSA: pcm: Add snd_pcm_add_named_chmap_ctls() for custom control names Abel Vesa
2026-11-24 10:57 ` [PATCH v4 2/4] ALSA: pcm: Report writable chmap controls as variable Abel Vesa
@ 2026-11-24 10:57 ` Abel Vesa
2026-11-24 10:57 ` [PATCH v4 4/4] ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override Abel Vesa
3 siblings, 0 replies; 6+ messages in thread
From: Abel Vesa @ 2026-11-24 10:57 UTC (permalink / raw)
To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai
Cc: Srinivas Kandagatla, linux-sound, linux-arm-msm, linux-kernel,
Abel Vesa
Add a small helper that converts ALSA channel map positions to the Q6 PCM
channel identifiers used by Qualcomm machine drivers.
The mapping is useful beyond a single machine driver when exposing
writable channel-map controls.
Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
sound/soc/qcom/common.c | 30 ++++++++++++++++++++++++++++++
sound/soc/qcom/common.h | 1 +
2 files changed, 31 insertions(+)
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index af5cacddf67d..695350d2812b 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -6,7 +6,9 @@
#include <linux/module.h>
#include <sound/jack.h>
#include <linux/input-event-codes.h>
+#include <sound/pcm.h>
#include "common.h"
+#include "qdsp6/q6dsp-common.h"
#define NAME_SIZE 32
@@ -327,6 +329,34 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
}
EXPORT_SYMBOL_GPL(qcom_snd_parse_of);
+int qcom_snd_chmap_to_q6(unsigned int pos)
+{
+ switch (pos) {
+ case SNDRV_CHMAP_FL:
+ return PCM_CHANNEL_FL;
+ case SNDRV_CHMAP_FR:
+ return PCM_CHANNEL_FR;
+ case SNDRV_CHMAP_MONO:
+ case SNDRV_CHMAP_FC:
+ return PCM_CHANNEL_FC;
+ case SNDRV_CHMAP_LFE:
+ return PCM_CHANNEL_LFE;
+ case SNDRV_CHMAP_RL:
+ return PCM_CHANNEL_LB;
+ case SNDRV_CHMAP_RR:
+ return PCM_CHANNEL_RB;
+ case SNDRV_CHMAP_SL:
+ return PCM_CHANNEL_LS;
+ case SNDRV_CHMAP_SR:
+ return PCM_CHANNEL_RS;
+ case SNDRV_CHMAP_RC:
+ return PCM_CHANNEL_CS;
+ default:
+ return -EINVAL;
+ }
+}
+EXPORT_SYMBOL_GPL(qcom_snd_chmap_to_q6);
+
static struct snd_soc_jack_pin qcom_headset_jack_pins[] = {
/* Headset */
{
diff --git a/sound/soc/qcom/common.h b/sound/soc/qcom/common.h
index 37b185a4968f..2b1d30230d77 100644
--- a/sound/soc/qcom/common.h
+++ b/sound/soc/qcom/common.h
@@ -31,6 +31,7 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_jack *jack, bool *jack_setup);
int qcom_snd_dp_jack_setup(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_jack *dp_jack, int id);
+int qcom_snd_chmap_to_q6(unsigned int pos);
#endif
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v4 4/4] ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override
2026-11-24 10:57 [PATCH v4 0/4] ASoC: qcom: x1e80100: allow WSA channel map override Abel Vesa
` (2 preceding siblings ...)
2026-11-24 10:57 ` [PATCH v4 3/4] ASoC: qcom: common: Add SNDRV channel map to Q6 slot helper Abel Vesa
@ 2026-11-24 10:57 ` Abel Vesa
2026-11-24 11:19 ` sashiko-bot
3 siblings, 1 reply; 6+ messages in thread
From: Abel Vesa @ 2026-11-24 10:57 UTC (permalink / raw)
To: Srinivas Kandagatla, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai
Cc: Srinivas Kandagatla, linux-sound, linux-arm-msm, linux-kernel,
Abel Vesa
The WSA RX slot mapping is currently computed entirely from the channel
count in .prepare() and pushed unconditionally via
snd_soc_dai_set_channel_map(). Userspace has no way to express a
different channel map, so any map defined in UCM is ignored.
Add writable "WSA Playback Channel Map" and "WSA2 Playback Channel Map"
controls on the WSA RX backend PCMs, using the standard ALSA channel map
TLV. Store the userspace-selected SNDRV_CHMAP_* map per WSA backend and
translate it to Q6 PCM_CHANNEL_* slots at .prepare() time. Keep the
previous default mapping unless the selected map describes exactly the
prepared channel count, and reject maps with unset positions in the
middle, so a wider map is never truncated for a narrower stream.
Until userspace selects a map, report the default one for the last
prepared channel count, initially stereo. The map only takes effect at
.prepare() time, so refuse writes while the backend is prepared, and
snapshot the map under a lock so a concurrent write cannot tear it.
The controls are added from the card late_probe callback. The backend
PCMs are only created after all DAI links are initialized, and adding
controls from the stream startup callback would take controls_rwsem
under dapm_mutex, deadlocking against DAPM mixer writes.
Allow up to six WSA channels for Glymur.
Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
sound/soc/qcom/x1e80100.c | 246 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 222 insertions(+), 24 deletions(-)
diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
index c927672eaede..4fe86ec062c4 100644
--- a/sound/soc/qcom/x1e80100.c
+++ b/sound/soc/qcom/x1e80100.c
@@ -5,6 +5,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/soundwire/sdw.h>
+#include <linux/spinlock.h>
#include <sound/pcm.h>
#include <sound/jack.h>
#include <sound/soc.h>
@@ -15,14 +16,151 @@
#include "qdsp6/q6dsp-common.h"
#include "sdw.h"
+#define X1E80100_WSA_MAX_CHANNELS 6
+#define X1E80100_WSA_PORTS 2
+
struct x1e80100_snd_data {
bool stream_prepared[AFE_PORT_MAX];
struct snd_soc_card *card;
struct snd_soc_jack jack;
struct snd_soc_jack dp_jack[8];
bool jack_setup;
+ /* Protects the WSA channel map state below */
+ spinlock_t wsa_chmap_lock;
+ /* Userspace-selected SNDRV_CHMAP_* positions, 0 means unset */
+ unsigned int wsa_chmap[X1E80100_WSA_PORTS][X1E80100_WSA_MAX_CHANNELS];
+ /* Channel count of the last prepared stream */
+ unsigned int wsa_channels[X1E80100_WSA_PORTS];
+ bool wsa_prepared[X1E80100_WSA_PORTS];
};
+/* Default WSA RX channel maps, indexed by channel count */
+static const unsigned int
+x1e80100_wsa_default_chmap[X1E80100_WSA_MAX_CHANNELS + 1][X1E80100_WSA_MAX_CHANNELS] = {
+ [1] = { SNDRV_CHMAP_MONO },
+ [2] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR },
+ [3] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_FC },
+ [4] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_RL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RR },
+ [6] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL,
+ SNDRV_CHMAP_RR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE },
+};
+
+static int x1e80100_wsa_port_index(unsigned int dai_id)
+{
+ switch (dai_id) {
+ case WSA_CODEC_DMA_RX_0:
+ return 0;
+ case WSA_CODEC_DMA_RX_1:
+ return 1;
+ default:
+ return -EINVAL;
+ }
+}
+
+static struct x1e80100_snd_data *
+x1e80100_wsa_chmap_kcontrol_data(struct snd_kcontrol *kcontrol, int *idx)
+{
+ struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
+ struct snd_soc_pcm_runtime *rtd = info->pcm->private_data;
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+
+ *idx = x1e80100_wsa_port_index(cpu_dai->id);
+ if (*idx < 0)
+ return NULL;
+
+ return snd_soc_card_get_drvdata(rtd->card);
+}
+
+static int x1e80100_wsa_chmap_ctl_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct x1e80100_snd_data *data;
+ const unsigned int *map;
+ int i, idx;
+
+ data = x1e80100_wsa_chmap_kcontrol_data(kcontrol, &idx);
+ if (!data)
+ return -EINVAL;
+
+ guard(spinlock)(&data->wsa_chmap_lock);
+
+ /* Report the default map until userspace selects one */
+ map = data->wsa_chmap[idx];
+ if (!map[0])
+ map = x1e80100_wsa_default_chmap[data->wsa_channels[idx]];
+
+ for (i = 0; i < X1E80100_WSA_MAX_CHANNELS; i++)
+ ucontrol->value.integer.value[i] = map[i];
+
+ return 0;
+}
+
+static int x1e80100_wsa_chmap_ctl_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ unsigned int map[X1E80100_WSA_MAX_CHANNELS];
+ struct x1e80100_snd_data *data;
+ bool changed = false;
+ int i, idx;
+
+ data = x1e80100_wsa_chmap_kcontrol_data(kcontrol, &idx);
+ if (!data)
+ return -EINVAL;
+
+ for (i = 0; i < X1E80100_WSA_MAX_CHANNELS; i++) {
+ map[i] = ucontrol->value.integer.value[i];
+
+ if (map[i] && qcom_snd_chmap_to_q6(map[i]) < 0)
+ return -EINVAL;
+
+ /* Unset positions are allowed only as a suffix of the map */
+ if (map[i] && i && !map[i - 1])
+ return -EINVAL;
+ }
+
+ guard(spinlock)(&data->wsa_chmap_lock);
+
+ /* The map is applied on prepare; refuse updating prepared streams */
+ if (data->wsa_prepared[idx])
+ return -EBUSY;
+
+ for (i = 0; i < X1E80100_WSA_MAX_CHANNELS; i++) {
+ if (data->wsa_chmap[idx][i] != map[i]) {
+ data->wsa_chmap[idx][i] = map[i];
+ changed = true;
+ }
+ }
+
+ return changed ? 1 : 0;
+}
+
+static int x1e80100_add_wsa_chmap_ctls(struct snd_soc_pcm_runtime *rtd,
+ const char *name)
+{
+ struct snd_pcm_chmap *info;
+ unsigned int i;
+ int ret;
+
+ ret = snd_pcm_add_named_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK,
+ name, snd_pcm_std_chmaps,
+ X1E80100_WSA_MAX_CHANNELS, 0, &info);
+ if (ret)
+ return ret;
+
+ /*
+ * The core registers a query-only control. Make it writable so that
+ * userspace (UCM) can select the WSA channel map. The card is not yet
+ * registered at this point, so the control is not visible to
+ * userspace while being modified.
+ */
+ for (i = 0; i < info->kctl->count; i++)
+ info->kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
+ info->kctl->get = x1e80100_wsa_chmap_ctl_get;
+ info->kctl->put = x1e80100_wsa_chmap_ctl_put;
+
+ return 0;
+}
+
static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)
{
struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
@@ -109,29 +247,43 @@ static int x1e80100_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
return 0;
}
-static int x1e80100_snd_hw_map_channels(unsigned int *ch_map, int num)
+static int x1e80100_snd_build_wsa_slots(struct x1e80100_snd_data *data,
+ unsigned int dai_id,
+ unsigned int channels,
+ unsigned int *rx_slot)
{
- switch (num) {
- case 1:
- ch_map[0] = PCM_CHANNEL_FC;
- break;
- case 2:
- ch_map[0] = PCM_CHANNEL_FL;
- ch_map[1] = PCM_CHANNEL_FR;
- break;
- case 3:
- ch_map[0] = PCM_CHANNEL_FL;
- ch_map[1] = PCM_CHANNEL_FR;
- ch_map[2] = PCM_CHANNEL_FC;
- break;
- case 4:
- ch_map[0] = PCM_CHANNEL_FL;
- ch_map[1] = PCM_CHANNEL_LB;
- ch_map[2] = PCM_CHANNEL_FR;
- ch_map[3] = PCM_CHANNEL_RB;
- break;
- default:
+ unsigned int map[X1E80100_WSA_MAX_CHANNELS];
+ unsigned int i, set = 0;
+ int idx;
+
+ idx = x1e80100_wsa_port_index(dai_id);
+ if (idx < 0)
+ return idx;
+
+ if (channels > X1E80100_WSA_MAX_CHANNELS ||
+ !x1e80100_wsa_default_chmap[channels][0])
return -EINVAL;
+
+ scoped_guard(spinlock, &data->wsa_chmap_lock) {
+ memcpy(map, data->wsa_chmap[idx], sizeof(map));
+ data->wsa_channels[idx] = channels;
+ data->wsa_prepared[idx] = true;
+ }
+
+ for (i = 0; i < X1E80100_WSA_MAX_CHANNELS; i++)
+ if (map[i])
+ set++;
+
+ /* Use the map only when it describes exactly this channel count */
+ if (set != channels)
+ memcpy(map, x1e80100_wsa_default_chmap[channels], sizeof(map));
+
+ for (i = 0; i < channels; i++) {
+ int q6 = qcom_snd_chmap_to_q6(map[i]);
+
+ if (q6 < 0)
+ return q6;
+ rx_slot[i] = q6;
}
return 0;
@@ -143,13 +295,14 @@ static int x1e80100_snd_prepare(struct snd_pcm_substream *substream)
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
unsigned int channels = substream->runtime->channels;
- unsigned int rx_slot[4];
+ unsigned int rx_slot[X1E80100_WSA_MAX_CHANNELS];
int ret;
switch (cpu_dai->id) {
case WSA_CODEC_DMA_RX_0:
case WSA_CODEC_DMA_RX_1:
- ret = x1e80100_snd_hw_map_channels(rx_slot, channels);
+ ret = x1e80100_snd_build_wsa_slots(data, cpu_dai->id,
+ channels, rx_slot);
if (ret)
return ret;
@@ -170,6 +323,12 @@ static int x1e80100_snd_hw_free(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ int idx = x1e80100_wsa_port_index(cpu_dai->id);
+
+ if (idx >= 0) {
+ guard(spinlock)(&data->wsa_chmap_lock);
+ data->wsa_prepared[idx] = false;
+ }
return qcom_snd_sdw_hw_free(substream, &data->stream_prepared[cpu_dai->id]);
}
@@ -181,6 +340,40 @@ static const struct snd_soc_ops x1e80100_be_ops = {
.prepare = x1e80100_snd_prepare,
};
+/*
+ * The WSA channel map controls are added here rather than in the DAI link
+ * init or startup callbacks: the backend PCMs are created only after all
+ * links are initialized, and adding controls from startup would take
+ * controls_rwsem under dapm_mutex, deadlocking against DAPM mixer writes.
+ */
+static int x1e80100_late_probe(struct snd_soc_card *card)
+{
+ struct snd_soc_pcm_runtime *rtd;
+ int ret;
+
+ for_each_card_rtds(card, rtd) {
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ const char *name;
+
+ switch (cpu_dai->id) {
+ case WSA_CODEC_DMA_RX_0:
+ name = "WSA Playback Channel Map";
+ break;
+ case WSA_CODEC_DMA_RX_1:
+ name = "WSA2 Playback Channel Map";
+ break;
+ default:
+ continue;
+ }
+
+ ret = x1e80100_add_wsa_chmap_ctls(rtd, name);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static void x1e80100_add_be_ops(struct snd_soc_card *card)
{
struct snd_soc_dai_link *link;
@@ -201,7 +394,7 @@ static int x1e80100_platform_probe(struct platform_device *pdev)
struct snd_soc_card *card;
struct x1e80100_snd_data *data;
struct device *dev = &pdev->dev;
- int ret;
+ int i, ret;
card = devm_kzalloc_obj(dev, *card);
if (!card)
@@ -211,6 +404,10 @@ static int x1e80100_platform_probe(struct platform_device *pdev)
if (!data)
return -ENOMEM;
+ spin_lock_init(&data->wsa_chmap_lock);
+ for (i = 0; i < X1E80100_WSA_PORTS; i++)
+ data->wsa_channels[i] = 2;
+
card->owner = THIS_MODULE;
card->dev = dev;
dev_set_drvdata(dev, card);
@@ -221,6 +418,7 @@ static int x1e80100_platform_probe(struct platform_device *pdev)
return ret;
card->driver_name = of_device_get_match_data(dev);
+ card->late_probe = x1e80100_late_probe;
x1e80100_add_be_ops(card);
return devm_snd_soc_register_card(dev, card);
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 4/4] ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override
2026-11-24 10:57 ` [PATCH v4 4/4] ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override Abel Vesa
@ 2026-11-24 11:19 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-24 11:19 UTC (permalink / raw)
To: Abel Vesa; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: qcom: x1e80100: wsa_prepared left true on
x1e80100_snd_prepare() error
- [Medium] ASoC: qcom: x1e80100: 6-channel WSA playback fails in
AudioReach prepare
- [Low] ASoC: qcom: x1e80100: unvalidated 5-channel map in
x1e80100_wsa_chmap_ctl_put()
--
commit 4f20a2b7a20905953c2178f9804669a43500020c
Author: Abel Vesa <abel.vesa@oss.qualcomm.com>
ASoC: qcom: x1e80100: Allow userspace WSA RX chmap override
This commit adds writable ALSA channel map controls for the WSA RX
backends so userspace can override the default channel slot mapping, and
extends the maximum WSA channel count to six for Glymur.
> diff --git a/sound/soc/qcom/x1e80100.c b/sound/soc/qcom/x1e80100.c
> index c927672eaede7..4fe86ec062c40 100644
> --- a/sound/soc/qcom/x1e80100.c
> +++ b/sound/soc/qcom/x1e80100.c
> @@ -15,14 +16,151 @@
> #include "qdsp6/q6dsp-common.h"
> #include "sdw.h"
>
> +#define X1E80100_WSA_MAX_CHANNELS 6
> +#define X1E80100_WSA_PORTS 2
> +
> struct x1e80100_snd_data {
> bool stream_prepared[AFE_PORT_MAX];
> struct snd_soc_card *card;
> struct snd_soc_jack jack;
> struct snd_soc_jack dp_jack[8];
> bool jack_setup;
> + /* Protects the WSA channel map state below */
> + spinlock_t wsa_chmap_lock;
> + /* Userspace-selected SNDRV_CHMAP_* positions, 0 means unset */
> + unsigned int wsa_chmap[X1E80100_WSA_PORTS][X1E80100_WSA_MAX_CHANNELS];
> + /* Channel count of the last prepared stream */
> + unsigned int wsa_channels[X1E80100_WSA_PORTS];
> + bool wsa_prepared[X1E80100_WSA_PORTS];
> +};
> +
> +/* Default WSA RX channel maps, indexed by channel count */
> +static const unsigned int
> +x1e80100_wsa_default_chmap[X1E80100_WSA_MAX_CHANNELS + 1][X1E80100_WSA_MAX_CHANNELS] = {
> + [1] = { SNDRV_CHMAP_MONO },
> + [2] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR },
> + [3] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_FC },
> + [4] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_RL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RR },
> + [6] = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL,
> + SNDRV_CHMAP_RR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE },
> };
[Severity: Medium]
Can a 6-channel WSA playback stream succeed on AudioReach?
x1e80100_snd_build_wsa_slots() only uses a 6-channel map when
substream->runtime->channels is 6, and x1e80100_be_hw_params_fixup() leaves
the channel count unchanged for WSA_CODEC_DMA_RX_0 and WSA_CODEC_DMA_RX_1.
When a 6-channel stream is prepared, q6apm_dai_prepare() and
q6apm_lpass_dai_prepare() pass num_channels == 6 into
audioreach_shmem_set_media_format() and audioreach_pcm_set_media_format(),
both of which reject num_channels > 4 with -EINVAL (and
audioreach_set_default_channel_mapping() only populates 1, 2 and 4
channels):
sound/soc/qcom/qdsp6/audioreach.c:audioreach_pcm_set_media_format() {
...
if (num_channels > 4) {
dev_err(graph->dev, "Error: Invalid channels (%d)!\n", num_channels);
return -EINVAL;
}
...
}
[ ... ]
> +static int x1e80100_wsa_chmap_ctl_put(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + unsigned int map[X1E80100_WSA_MAX_CHANNELS];
> + struct x1e80100_snd_data *data;
> + bool changed = false;
> + int i, idx;
> +
> + data = x1e80100_wsa_chmap_kcontrol_data(kcontrol, &idx);
> + if (!data)
> + return -EINVAL;
> +
> + for (i = 0; i < X1E80100_WSA_MAX_CHANNELS; i++) {
> + map[i] = ucontrol->value.integer.value[i];
> +
> + if (map[i] && qcom_snd_chmap_to_q6(map[i]) < 0)
> + return -EINVAL;
> +
> + /* Unset positions are allowed only as a suffix of the map */
> + if (map[i] && i && !map[i - 1])
> + return -EINVAL;
> + }
[Severity: Low]
Should x1e80100_wsa_chmap_ctl_put() reject a 5-channel map?
Because x1e80100_wsa_default_chmap[5][0] is 0,
x1e80100_snd_build_wsa_slots() rejects 5-channel streams with -EINVAL and
falls back to the default map for any other channel count. However,
x1e80100_wsa_chmap_ctl_put() accepts and stores a 5-element map, causing
x1e80100_wsa_chmap_ctl_get() to report a map that can never be applied.
[ ... ]
> @@ -109,29 +247,43 @@ static int x1e80100_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
> return 0;
> }
>
> -static int x1e80100_snd_hw_map_channels(unsigned int *ch_map, int num)
> +static int x1e80100_snd_build_wsa_slots(struct x1e80100_snd_data *data,
> + unsigned int dai_id,
> + unsigned int channels,
> + unsigned int *rx_slot)
> {
> + unsigned int map[X1E80100_WSA_MAX_CHANNELS];
> + unsigned int i, set = 0;
> + int idx;
> +
> + idx = x1e80100_wsa_port_index(dai_id);
> + if (idx < 0)
> + return idx;
> +
> + if (channels > X1E80100_WSA_MAX_CHANNELS ||
> + !x1e80100_wsa_default_chmap[channels][0])
> return -EINVAL;
> +
> + scoped_guard(spinlock, &data->wsa_chmap_lock) {
> + memcpy(map, data->wsa_chmap[idx], sizeof(map));
> + data->wsa_channels[idx] = channels;
> + data->wsa_prepared[idx] = true;
> + }
[ ... ]
> @@ -143,13 +295,14 @@ static int x1e80100_snd_prepare(struct snd_pcm_substream *substream)
> struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
> struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
> unsigned int channels = substream->runtime->channels;
> - unsigned int rx_slot[4];
> + unsigned int rx_slot[X1E80100_WSA_MAX_CHANNELS];
> int ret;
>
> switch (cpu_dai->id) {
> case WSA_CODEC_DMA_RX_0:
> case WSA_CODEC_DMA_RX_1:
> - ret = x1e80100_snd_hw_map_channels(rx_slot, channels);
> + ret = x1e80100_snd_build_wsa_slots(data, cpu_dai->id,
> + channels, rx_slot);
> if (ret)
> return ret;
>
> ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
> channels, rx_slot);
> if (ret)
> return ret;
> break;
> default:
> break;
> }
>
> return qcom_snd_sdw_prepare(substream, &data->stream_prepared[cpu_dai->id]);
> }
[Severity: Medium]
Does x1e80100_snd_prepare() leave data->wsa_prepared[idx] set to true if
snd_soc_dai_set_channel_map() or qcom_snd_sdw_prepare() fails?
dpcm_fe_dai_prepare() does not call dpcm_be_dai_hw_free() when backend
prepare fails, so data->wsa_prepared[idx] stays true while the stream
remains in SNDRV_PCM_STATE_SETUP, and subsequent writes to the channel map
control via x1e80100_wsa_chmap_ctl_put() fail with -EBUSY until hw_free or
close.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-b4-sound-qcom-x1e80100-allow-ucm-channel-map-v4-0-1197ac8eacd2@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 6+ messages in thread