Skip to content

Commit ce2faa9

Browse files
ujfalusibroonie
authored andcommitted
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: [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 4374f69 commit ce2faa9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

sound/soc/sof/ops.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,30 @@ static inline u64 snd_sof_pcm_get_stream_position(struct snd_sof_dev *sdev,
533533
return 0;
534534
}
535535

536+
static inline u64
537+
snd_sof_pcm_get_dai_frame_counter(struct snd_sof_dev *sdev,
538+
struct snd_soc_component *component,
539+
struct snd_pcm_substream *substream)
540+
{
541+
if (sof_ops(sdev) && sof_ops(sdev)->get_dai_frame_counter)
542+
return sof_ops(sdev)->get_dai_frame_counter(sdev, component,
543+
substream);
544+
545+
return 0;
546+
}
547+
548+
static inline u64
549+
snd_sof_pcm_get_host_byte_counter(struct snd_sof_dev *sdev,
550+
struct snd_soc_component *component,
551+
struct snd_pcm_substream *substream)
552+
{
553+
if (sof_ops(sdev) && sof_ops(sdev)->get_host_byte_counter)
554+
return sof_ops(sdev)->get_host_byte_counter(sdev, component,
555+
substream);
556+
557+
return 0;
558+
}
559+
536560
/* machine driver */
537561
static inline int
538562
snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)

sound/soc/sof/sof-priv.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,27 @@ struct snd_sof_dsp_ops {
270270
struct snd_soc_component *component,
271271
struct snd_pcm_substream *substream); /* optional */
272272

273+
/*
274+
* optional callback to retrieve the number of frames left/arrived from/to
275+
* the DSP on the DAI side (link/codec/DMIC/etc).
276+
*
277+
* The callback is used when the firmware does not provide this information
278+
* via the shared SRAM window and it can be retrieved by host.
279+
*/
280+
u64 (*get_dai_frame_counter)(struct snd_sof_dev *sdev,
281+
struct snd_soc_component *component,
282+
struct snd_pcm_substream *substream); /* optional */
283+
284+
/*
285+
* Optional callback to retrieve the number of bytes left/arrived from/to
286+
* the DSP on the host side (bytes between host ALSA buffer and DSP).
287+
*
288+
* The callback is needed for ALSA delay reporting.
289+
*/
290+
u64 (*get_host_byte_counter)(struct snd_sof_dev *sdev,
291+
struct snd_soc_component *component,
292+
struct snd_pcm_substream *substream); /* optional */
293+
273294
/* host read DSP stream data */
274295
int (*ipc_msg_data)(struct snd_sof_dev *sdev,
275296
struct snd_sof_pcm_stream *sps,

0 commit comments

Comments
 (0)