Skip to content

Commit 8544f08

Browse files
morimotobroonie
authored andcommitted
ASoC: soc-dai: update snd_soc_dai_delay() to snd_soc_pcm_dai_delay()
Current soc_pcm_pointer() is manually calculating both CPU-DAI's max delay (= A) and Codec-DAI's max delay (= B). static snd_pcm_uframes_t soc_pcm_pointer(...) { ... ^ for_each_rtd_cpu_dais(rtd, i, cpu_dai) (A) cpu_delay = max(cpu_delay, ...); v delay += cpu_delay; ^ for_each_rtd_codec_dais(rtd, i, codec_dai) (B) codec_delay = max(codec_delay, ...); v delay += codec_delay; runtime->delay = delay; ... } Current soc_pcm_pointer() and the total delay calculating is not readable / difficult to understand. This patch update snd_soc_dai_delay() to snd_soc_pcm_dai_delay(), and calcule both CPU/Codec delay in one function. Link: https://lore.kernel.org/r/87fszl4yrq.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/875yssy25z.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 335302d commit 8544f08

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

include/sound/soc-dai.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ int snd_soc_dai_startup(struct snd_soc_dai *dai,
208208
struct snd_pcm_substream *substream);
209209
void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
210210
struct snd_pcm_substream *substream, int rollback);
211-
snd_pcm_sframes_t snd_soc_dai_delay(struct snd_soc_dai *dai,
212-
struct snd_pcm_substream *substream);
213211
void snd_soc_dai_suspend(struct snd_soc_dai *dai);
214212
void snd_soc_dai_resume(struct snd_soc_dai *dai);
215213
int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
@@ -238,6 +236,8 @@ int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
238236
int rollback);
239237
int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
240238
int cmd);
239+
void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
240+
snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
241241

242242
int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
243243
struct snd_compr_stream *cstream);

sound/soc/soc-dai.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,6 @@ void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
453453
soc_dai_mark_pop(dai, substream, startup);
454454
}
455455

456-
snd_pcm_sframes_t snd_soc_dai_delay(struct snd_soc_dai *dai,
457-
struct snd_pcm_substream *substream)
458-
{
459-
int delay = 0;
460-
461-
if (dai->driver->ops &&
462-
dai->driver->ops->delay)
463-
delay = dai->driver->ops->delay(substream, dai);
464-
465-
return delay;
466-
}
467-
468456
int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
469457
struct snd_soc_pcm_runtime *rtd, int num)
470458
{
@@ -693,6 +681,34 @@ int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
693681
return 0;
694682
}
695683

684+
void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
685+
snd_pcm_sframes_t *cpu_delay,
686+
snd_pcm_sframes_t *codec_delay)
687+
{
688+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
689+
struct snd_soc_dai *dai;
690+
int i;
691+
692+
/*
693+
* We're looking for the delay through the full audio path so it needs to
694+
* be the maximum of the DAIs doing transmit and the maximum of the DAIs
695+
* doing receive (ie, all CPUs and all CODECs) rather than just the maximum
696+
* of all DAIs.
697+
*/
698+
699+
/* for CPU */
700+
for_each_rtd_cpu_dais(rtd, i, dai)
701+
if (dai->driver->ops &&
702+
dai->driver->ops->delay)
703+
*cpu_delay = max(*cpu_delay, dai->driver->ops->delay(substream, dai));
704+
705+
/* for Codec */
706+
for_each_rtd_codec_dais(rtd, i, dai)
707+
if (dai->driver->ops &&
708+
dai->driver->ops->delay)
709+
*codec_delay = max(*codec_delay, dai->driver->ops->delay(substream, dai));
710+
}
711+
696712
int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
697713
struct snd_compr_stream *cstream)
698714
{

sound/soc/soc-pcm.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,15 +1084,11 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
10841084
*/
10851085
static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
10861086
{
1087-
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1088-
struct snd_soc_dai *cpu_dai;
1089-
struct snd_soc_dai *codec_dai;
10901087
struct snd_pcm_runtime *runtime = substream->runtime;
10911088
snd_pcm_uframes_t offset = 0;
10921089
snd_pcm_sframes_t delay = 0;
10931090
snd_pcm_sframes_t codec_delay = 0;
10941091
snd_pcm_sframes_t cpu_delay = 0;
1095-
int i;
10961092

10971093
/* clearing the previous total delay */
10981094
runtime->delay = 0;
@@ -1102,19 +1098,9 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
11021098
/* base delay if assigned in pointer callback */
11031099
delay = runtime->delay;
11041100

1105-
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
1106-
cpu_delay = max(cpu_delay,
1107-
snd_soc_dai_delay(cpu_dai, substream));
1108-
}
1109-
delay += cpu_delay;
1110-
1111-
for_each_rtd_codec_dais(rtd, i, codec_dai) {
1112-
codec_delay = max(codec_delay,
1113-
snd_soc_dai_delay(codec_dai, substream));
1114-
}
1115-
delay += codec_delay;
1101+
snd_soc_pcm_dai_delay(substream, &cpu_delay, &codec_delay);
11161102

1117-
runtime->delay = delay;
1103+
runtime->delay = delay + cpu_delay + codec_delay;
11181104

11191105
return offset;
11201106
}

0 commit comments

Comments
 (0)