Skip to content

ASoC: SOF: Intel: reset SPIB in hda_data_stream_cleanup#5718

Open
bardliao wants to merge 1 commit intothesofproject:topic/sof-devfrom
bardliao:reset-spib
Open

ASoC: SOF: Intel: reset SPIB in hda_data_stream_cleanup#5718
bardliao wants to merge 1 commit intothesofproject:topic/sof-devfrom
bardliao:reset-spib

Conversation

@bardliao
Copy link
Copy Markdown
Collaborator

@bardliao bardliao commented Apr 2, 2026

The register will indicate to the host DMA where the position is in the buffer currently processed by host SW. Reset it to 0 in hda_data_stream_cleanup. The register is ignored by the host DMA if SPIB is disabled. That's why the "enable" parameter needs to be HDA_DSP_SPIB_ENABLE.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Intel SOF HDA stream cleanup path to reset the SPIB (Software Position In Buffer) register to 0 during hda_data_stream_cleanup(), based on the requirement that the SPIB value is only honored by host DMA when SPIB is enabled.

Changes:

  • Add an SPIB “reset to 0” step in hda_data_stream_cleanup() using HDA_DSP_SPIB_ENABLE.
  • Keep the existing playback-specific SPIB disable call after cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1329 to 1336
/*
* Reset SPIB. The SPIB value will only take effect when SPIB is enabled,
* That's why we need to set the value with HDA_DSP_SPIB_ENABLE
*/
hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, 0);

if (hstream->direction == SNDRV_PCM_STREAM_PLAYBACK)
ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new SPIB reset call enables SPIB unconditionally, but SPIB is only disabled again for playback streams. For capture streams (notably the ICCMAX capture stream path, which doesn’t enable SPIB in hda_data_stream_prepare()), this will leave SPIB enabled after cleanup and changes the stream’s register state unexpectedly. Consider limiting the reset to the playback case (where SPIB is disabled right after), or preserving/restoring the previous SPIB enable state (or explicitly disabling again for capture) so cleanup doesn’t introduce a persistent SPIB enable side effect.

Copilot uses AI. Check for mistakes.
Comment on lines +1330 to +1331
* Reset SPIB. The SPIB value will only take effect when SPIB is enabled,
* That's why we need to set the value with HDA_DSP_SPIB_ENABLE
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comment grammar/casing — the sentence after the comma starts with "That's"; consider splitting into two sentences and avoiding the contraction (e.g., "That is why...") to match typical kernel comment style and improve readability.

Suggested change
* Reset SPIB. The SPIB value will only take effect when SPIB is enabled,
* That's why we need to set the value with HDA_DSP_SPIB_ENABLE
* Reset SPIB. The SPIB value will only take effect when SPIB is enabled.
* That is why we need to set the value with HDA_DSP_SPIB_ENABLE.

Copilot uses AI. Check for mistakes.
The register will indicate to the host DMA where the position is in the
buffer currently processed by host SW. Reset it to 0 in
hda_data_stream_cleanup. The register is ignored by the host DMA if SPIB
is disabled. That's why the "enable" parameter needs to be
HDA_DSP_SPIB_ENABLE.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1334 to +1342
ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, 0);
if (ret < 0) {
dev_err(sdev->dev, "%s: failed to reset SPIB: %d\n", __func__, ret);
}

ret1 = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
if (!ret)
ret = ret1;

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hda_data_stream_cleanup() now returns an error if the SPIB reset/disable fails, which changes behavior for capture streams (previously ret stayed 0 unless direction was PLAYBACK). Since SPIB appears optional and other call sites treat SPIB config as best-effort (e.g. hda_dsp_stream_hw_free() calls hda_dsp_stream_spib_config(...DISABLE...) and still returns 0 at hda-stream.c:770-774), consider not propagating SPIB failures from cleanup (e.g. only attempt when sdev->bar[HDA_DSP_SPIB_BAR] is present, and/or keep ret at 0 unless later cleanup steps fail).

Copilot uses AI. Check for mistakes.
Comment on lines +1327 to +1341
int ret1;
int ret;

if (hstream->direction == SNDRV_PCM_STREAM_PLAYBACK)
ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
else
/*
* Reset SPIB. The SPIB value will only take effect when SPIB is enabled,
* That is why we need to set the value with HDA_DSP_SPIB_ENABLE
*/
ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, 0);
if (ret < 0) {
dev_err(sdev->dev, "%s: failed to reset SPIB: %d\n", __func__, ret);
}

ret1 = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
if (!ret)
ret = ret1;
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret1 is non-descriptive in this context. Renaming it to reflect the operation (e.g. ret_disable) would make the error-handling logic easier to follow and reduce the chance of mistakes during future edits.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants