ASoC: SOF: Intel: hda: Compensate LLP in case it is not reset
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Thu, 21 Mar 2024 13:08:14 +0000 (15:08 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 25 Mar 2024 16:36:06 +0000 (16:36 +0000)
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: stable@vger.kernel.org # 6.8
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240321130814.4412-18-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/intel/hda-dai-ops.c
sound/soc/sof/intel/hda-pcm.c
sound/soc/sof/intel/hda-stream.c

index c50ca9e72d37385816ddb3cd6ef7456ed50a58e9..b073720b4cf432466e18bf8840dd87eb5efac98e 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <sound/pcm_params.h>
 #include <sound/hdaudio_ext.h>
+#include <sound/hda_register.h>
 #include <sound/hda-mlink.h>
 #include <sound/sof/ipc4/header.h>
 #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,
        case SNDRV_PCM_TRIGGER_STOP:
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
                snd_hdac_ext_stream_clear(hext_stream);
+
+               /*
+                * Save the LLP registers in case the stream is
+                * restarting due PAUSE_RELEASE, or START without a pcm
+                * close/open since in this case the LLP register is not reset
+                * to 0 and the delay calculation will return with invalid
+                * results.
+                */
+               hext_stream->pplcllpl = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPL);
+               hext_stream->pplcllpu = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPU);
                break;
        default:
                dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
index 69fefcd1abc5b481543bcc59a823b56cd27b2250..d7b446f3f973e3d532d8eaef241aac2f3a30a54d 100644 (file)
@@ -282,6 +282,14 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
 
        /* binding pcm substream to hda stream */
        substream->runtime->private_data = &dsp_stream->hstream;
+
+       /*
+        * Reset the llp cache values (they are used for LLP compensation in
+        * case the counter is not reset)
+        */
+       dsp_stream->pplcllpl = 0;
+       dsp_stream->pplcllpu = 0;
+
        return 0;
 }
 
index 8504a4f27b608ab0950349afd1090cb84bcbd7a2..0c189d3b19c1af6448d5d1264802ef493e5c7b14 100644 (file)
@@ -1064,6 +1064,8 @@ snd_pcm_uframes_t hda_dsp_stream_get_position(struct hdac_stream *hstream,
        return pos;
 }
 
+#define merge_u64(u32_u, u32_l) (((u64)(u32_u) << 32) | (u32_l))
+
 /**
  * hda_dsp_get_stream_llp - Retrieve the LLP (Linear Link Position) of the stream
  * @sdev: SOF device
@@ -1093,7 +1095,12 @@ u64 hda_dsp_get_stream_llp(struct snd_sof_dev *sdev,
        llp_l = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPL);
        llp_u = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPU);
 
-       return ((u64)llp_u << 32) | llp_l;
+       /* Compensate the LLP counter with the saved offset */
+       if (hext_stream->pplcllpl || hext_stream->pplcllpu)
+               return merge_u64(llp_u, llp_l) -
+                      merge_u64(hext_stream->pplcllpu, hext_stream->pplcllpl);
+
+       return merge_u64(llp_u, llp_l);
 }
 
 /**