From 8729c167127febd098be8022df2bf441e2fd6295 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Thu, 12 Jan 2023 19:41:57 +0800 Subject: [PATCH 1/2] ASoC: Add the ability of split channels between cpu DAIs equally In theory, the captured data will be combined from each cpu DAI if the dai link has more than one cpu DAIs. Therefore, the channel number should divide by num_cpus for each cpu/codec DAI. This commit introduces a flag to support the feature. Signed-off-by: Bard Liao --- include/sound/soc.h | 5 +++++ sound/soc/soc-pcm.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/sound/soc.h b/include/sound/soc.h index 37bbfc8b45cb28..6f259e21c40ec1 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -646,6 +646,9 @@ struct snd_soc_dai_link_component { const char *dai_name; }; +/* Split channels between cpu DAIs equally */ +#define SND_SOC_DAI_LINK_EVEN_CHANNEL BIT(0) + struct snd_soc_dai_link { /* config - must be set by machine driver */ const char *name; /* Codec name */ @@ -691,6 +694,8 @@ struct snd_soc_dai_link { enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */ + unsigned int flags[SNDRV_PCM_STREAM_LAST + 1]; /* dai_link flags */ + /* codec/machine specific init - e.g. add machine controls */ int (*init)(struct snd_soc_pcm_runtime *rtd); diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index f6caa55ef322d5..52532f50459cf2 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2012,6 +2012,14 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream) dev_dbg(be->dev, "ASoC: hw_params BE %s\n", be->dai_link->name); + if (be->dai_link->flags[stream] & SND_SOC_DAI_LINK_EVEN_CHANNEL) { + struct snd_interval *channels; + + channels = hw_param_interval(&hw_params, SNDRV_PCM_HW_PARAM_CHANNELS); + channels->min /= be->dai_link->num_cpus; + channels->max = channels->min; + } + ret = __soc_pcm_hw_params(be, be_substream, &hw_params); if (ret < 0) goto unwind; From 172d780554e687289ed6db9a86d08e173ab5cd04 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Thu, 12 Jan 2023 20:08:21 +0800 Subject: [PATCH 2/2] ASoC: Intel: sof_sdw: add SND_SOC_DAI_LINK_EVEN_CHANNEL flag Add SND_SOC_DAI_LINK_EVEN_CHANNEL flag on capture stream to split captured channels equally. Signed-off-by: Bard Liao --- sound/soc/intel/boards/sof_sdw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index d24e6134cedb96..adbb328f1b425c 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -797,6 +797,7 @@ static void init_dai_link(struct device *dev, struct snd_soc_dai_link *dai_links dai_links->dpcm_capture = capture; dai_links->init = init; dai_links->ops = ops; + dai_links->flags[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DAI_LINK_EVEN_CHANNEL; } static bool is_unique_device(const struct snd_soc_acpi_link_adr *link,