Skip to content

Commit 1abc264

Browse files
ujfalusibroonie
authored andcommitted
ASoC: SOF: Intel: hda: Compensate LLP in case it is not reset
During pause/reset or stop/start the LLP counter is not reset, which will result broken delay reporting. Read the LLP value on STOP/PAUSE trigger and use it in LLP reading to normalize the LLP from the register. Cc: [email protected] # 6.8 Signed-off-by: Peter Ujfalusi <[email protected]> Reviewed-by: Kai Vehmanen <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f9eeb6b commit 1abc264

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

sound/soc/sof/intel/hda-dai-ops.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <sound/pcm_params.h>
99
#include <sound/hdaudio_ext.h>
10+
#include <sound/hda_register.h>
1011
#include <sound/hda-mlink.h>
1112
#include <sound/sof/ipc4/header.h>
1213
#include <uapi/sound/sof/header.h>
@@ -362,6 +363,16 @@ static int hda_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
362363
case SNDRV_PCM_TRIGGER_STOP:
363364
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
364365
snd_hdac_ext_stream_clear(hext_stream);
366+
367+
/*
368+
* Save the LLP registers in case the stream is
369+
* restarting due PAUSE_RELEASE, or START without a pcm
370+
* close/open since in this case the LLP register is not reset
371+
* to 0 and the delay calculation will return with invalid
372+
* results.
373+
*/
374+
hext_stream->pplcllpl = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPL);
375+
hext_stream->pplcllpu = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPU);
365376
break;
366377
default:
367378
dev_err(sdev->dev, "unknown trigger command %d\n", cmd);

sound/soc/sof/intel/hda-pcm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
282282

283283
/* binding pcm substream to hda stream */
284284
substream->runtime->private_data = &dsp_stream->hstream;
285+
286+
/*
287+
* Reset the llp cache values (they are used for LLP compensation in
288+
* case the counter is not reset)
289+
*/
290+
dsp_stream->pplcllpl = 0;
291+
dsp_stream->pplcllpu = 0;
292+
285293
return 0;
286294
}
287295

sound/soc/sof/intel/hda-stream.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,8 @@ snd_pcm_uframes_t hda_dsp_stream_get_position(struct hdac_stream *hstream,
10641064
return pos;
10651065
}
10661066

1067+
#define merge_u64(u32_u, u32_l) (((u64)(u32_u) << 32) | (u32_l))
1068+
10671069
/**
10681070
* hda_dsp_get_stream_llp - Retrieve the LLP (Linear Link Position) of the stream
10691071
* @sdev: SOF device
@@ -1093,7 +1095,12 @@ u64 hda_dsp_get_stream_llp(struct snd_sof_dev *sdev,
10931095
llp_l = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPL);
10941096
llp_u = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPU);
10951097

1096-
return ((u64)llp_u << 32) | llp_l;
1098+
/* Compensate the LLP counter with the saved offset */
1099+
if (hext_stream->pplcllpl || hext_stream->pplcllpu)
1100+
return merge_u64(llp_u, llp_l) -
1101+
merge_u64(hext_stream->pplcllpu, hext_stream->pplcllpl);
1102+
1103+
return merge_u64(llp_u, llp_l);
10971104
}
10981105

10991106
/**

0 commit comments

Comments
 (0)