Commit ce2faa9a authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Mark Brown

ASoC: SOF: Introduce a new callback pair to be used for PCM delay reporting

For delay calculation we need two information:
Number of bytes transferred between the DSP and host memory (ALSA buffer)
Number of frames transferred between the DSP and external device
(link/codec/DMIC/etc).

The reason for the different units (bytes vs frames) on host and dai side
is that the format on the dai side is decided by the firmware and might
not be the same as on the host side, thus the expectation is that the
counter reflects the number of frames.
The kernel know the host side format and in there we have access to the
DMA position which is in bytes.

In a simplified way, the DSP caused delay is the difference between the
two counters.

The existing get_stream_position callback is defined to retrieve the frame
counter on the DAI side but it's name is too generic to be intuitive and
makes it hard to define a callback for the host side.

This patch introduces a new set of callbacks to replace the
get_stream_position and define the host side equivalent:
get_dai_frame_counter
get_host_byte_counter

Subsequent patches will remove the old callback.

Cc: stable@vger.kernel.org # 6.8
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240321130814.4412-7-peter.ujfalusi@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4374f698
...@@ -533,6 +533,30 @@ static inline u64 snd_sof_pcm_get_stream_position(struct snd_sof_dev *sdev, ...@@ -533,6 +533,30 @@ static inline u64 snd_sof_pcm_get_stream_position(struct snd_sof_dev *sdev,
return 0; return 0;
} }
static inline u64
snd_sof_pcm_get_dai_frame_counter(struct snd_sof_dev *sdev,
struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
if (sof_ops(sdev) && sof_ops(sdev)->get_dai_frame_counter)
return sof_ops(sdev)->get_dai_frame_counter(sdev, component,
substream);
return 0;
}
static inline u64
snd_sof_pcm_get_host_byte_counter(struct snd_sof_dev *sdev,
struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
if (sof_ops(sdev) && sof_ops(sdev)->get_host_byte_counter)
return sof_ops(sdev)->get_host_byte_counter(sdev, component,
substream);
return 0;
}
/* machine driver */ /* machine driver */
static inline int static inline int
snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata) snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
......
...@@ -270,6 +270,27 @@ struct snd_sof_dsp_ops { ...@@ -270,6 +270,27 @@ struct snd_sof_dsp_ops {
struct snd_soc_component *component, struct snd_soc_component *component,
struct snd_pcm_substream *substream); /* optional */ struct snd_pcm_substream *substream); /* optional */
/*
* optional callback to retrieve the number of frames left/arrived from/to
* the DSP on the DAI side (link/codec/DMIC/etc).
*
* The callback is used when the firmware does not provide this information
* via the shared SRAM window and it can be retrieved by host.
*/
u64 (*get_dai_frame_counter)(struct snd_sof_dev *sdev,
struct snd_soc_component *component,
struct snd_pcm_substream *substream); /* optional */
/*
* Optional callback to retrieve the number of bytes left/arrived from/to
* the DSP on the host side (bytes between host ALSA buffer and DSP).
*
* The callback is needed for ALSA delay reporting.
*/
u64 (*get_host_byte_counter)(struct snd_sof_dev *sdev,
struct snd_soc_component *component,
struct snd_pcm_substream *substream); /* optional */
/* host read DSP stream data */ /* host read DSP stream data */
int (*ipc_msg_data)(struct snd_sof_dev *sdev, int (*ipc_msg_data)(struct snd_sof_dev *sdev,
struct snd_sof_pcm_stream *sps, struct snd_sof_pcm_stream *sps,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment