This patch is aims to start a stronger discussion on allowing both CPU and Codec dais to set formats independently based on direction.
Currently it is very difficult to change stream formats because there is no way to specify it independently.
A previous discussion w.r.t. a codec's stream dependent format setting required a codec's dai to be split. See here : https://mailman.alsa-project.org/pipermail/alsa-devel/2020-March/164492.html
A previous discussion w.r.t. changing format based on the stream direction w.r.t. a CPU's dai showed the difficulty in setting fmt based on direection in thw hw_params function. See here : https://mailman.alsa-project.org/pipermail/alsa-devel/2020-March/165101.html
It seems that it may be necessary to allow the stream direction as an input argument to snd_soc_dai_set_fmt.
This patch is not complete, as there are many codecs and cpus which would require this change. However this patch is aimed as a discussion point.
One example of a sound card which requires independent stream formats is an isolated sound card, such as the Audio Injector Isolated sound card. The magnetic isolation chips on the sound card require stream fomats to be different because of digital latency variations on the I2S lines.
Signed-off-by: Matt Flax flatmax@flatmax.org --- include/sound/soc-dai.h | 4 ++-- sound/soc/soc-core.c | 5 +++-- sound/soc/soc-dai.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index eaaeb00e9e84..5071e006389b 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -123,7 +123,7 @@ int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
/* Digital Audio interface formatting */ -int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt); +int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt, int stream);
int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width); @@ -186,7 +186,7 @@ struct snd_soc_dai_ops { * DAI format configuration * Called by soc_card drivers, normally in their hw_params. */ - int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt); + int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt, int stream); int (*xlate_tdm_slot_mask)(unsigned int slots, unsigned int *tx_mask, unsigned int *rx_mask); int (*set_tdm_slot)(struct snd_soc_dai *dai, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 068d809c349a..27a6f01dc2d3 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1474,10 +1474,11 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *codec_dai; unsigned int i; - int ret; + int ret, stream;
for_each_rtd_codec_dai(rtd, i, codec_dai) { - ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); + int stream = 0; + ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt, stream); if (ret != 0 && ret != -ENOTSUPP) { dev_warn(codec_dai->dev, "ASoC: Failed to set DAI format: %d\n", ret); diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c index 51031e330179..1f8ee7875656 100644 --- a/sound/soc/soc-dai.c +++ b/sound/soc/soc-dai.c @@ -94,11 +94,11 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); * * Configures the DAI hardware format and clocking. */ -int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) +int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt, int stream) { if (dai->driver->ops->set_fmt == NULL) return -ENOTSUPP; - return dai->driver->ops->set_fmt(dai, fmt); + return dai->driver->ops->set_fmt(dai, fmt, stream); } EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);