Repository navigation
ASoC: SOF: reset DMA state in prepare #1049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -423,25 +423,19 @@ int hda_dsp_suspend(struct snd_sof_dev *sdev) | |
|
|
||
| int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev) | ||
| { | ||
| struct hdac_bus *bus = sof_to_bus(sdev); | ||
| struct sof_intel_hda_stream *hda_stream; | ||
| struct hdac_ext_stream *stream; | ||
| struct hdac_stream *s; | ||
|
|
||
| #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) | ||
| struct hdac_bus *bus = sof_to_bus(sdev); | ||
| struct snd_soc_pcm_runtime *rtd; | ||
| struct hdac_ext_stream *stream; | ||
| struct hdac_ext_link *link; | ||
| struct hdac_stream *s; | ||
| const char *name; | ||
| int stream_tag; | ||
| #endif | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also refine the layout of variable declaration.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rander Ack, will do in next patch revision. |
||
|
|
||
| /* set internal flag for BE */ | ||
| list_for_each_entry(s, &bus->stream_list, list) { | ||
| stream = stream_to_hdac_ext_stream(s); | ||
| hda_stream = container_of(stream, struct sof_intel_hda_stream, | ||
| hda_stream); | ||
| hda_stream->hw_params_upon_resume = 1; | ||
| #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) | ||
|
|
||
| /* | ||
| * clear and release stream. This should already be taken care | ||
| * for running streams when the SUSPEND trigger is called. | ||
|
|
@@ -458,8 +452,9 @@ int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev) | |
| snd_hdac_ext_link_clear_stream_id(link, stream_tag); | ||
| snd_hdac_ext_stream_release(stream, | ||
| HDAC_EXT_STREAM_TYPE_LINK); | ||
| stream->link_prepared = 0; | ||
| } | ||
| #endif | ||
| } | ||
| #endif | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,11 +208,31 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream, | |
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| spcm->prepared[substream->stream] = true; | ||
|
|
||
| /* save pcm hw_params */ | ||
| memcpy(&spcm->params[substream->stream], params, sizeof(*params)); | ||
|
|
||
| /* clear hw_params_upon_resume flag */ | ||
| spcm->hw_params_upon_resume[substream->stream] = 0; | ||
| return ret; | ||
| } | ||
|
|
||
| static int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, | ||
| struct snd_sof_dev *sdev, | ||
| struct snd_sof_pcm *spcm) | ||
| { | ||
| struct sof_ipc_stream stream; | ||
| struct sof_ipc_reply reply; | ||
| int ret; | ||
|
|
||
| stream.hdr.size = sizeof(stream); | ||
| stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE; | ||
| stream.comp_id = spcm->stream[substream->stream].comp_id; | ||
|
|
||
| /* send IPC to the DSP */ | ||
| ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, | ||
| sizeof(stream), &reply, sizeof(reply)); | ||
| if (!ret) | ||
| spcm->prepared[substream->stream] = false; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
@@ -224,8 +244,6 @@ static int sof_pcm_hw_free(struct snd_pcm_substream *substream) | |
| snd_soc_rtdcom_lookup(rtd, DRV_NAME); | ||
| struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); | ||
| struct snd_sof_pcm *spcm; | ||
| struct sof_ipc_stream stream; | ||
| struct sof_ipc_reply reply; | ||
| int ret; | ||
|
|
||
| /* nothing to do for BE */ | ||
|
|
@@ -236,16 +254,13 @@ static int sof_pcm_hw_free(struct snd_pcm_substream *substream) | |
| if (!spcm) | ||
| return -EINVAL; | ||
|
|
||
| if (!spcm->prepared[substream->stream]) | ||
| return 0; | ||
|
|
||
| dev_dbg(sdev->dev, "pcm: free stream %d dir %d\n", spcm->pcm.pcm_id, | ||
| substream->stream); | ||
|
|
||
| stream.hdr.size = sizeof(stream); | ||
| stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE; | ||
| stream.comp_id = spcm->stream[substream->stream].comp_id; | ||
|
|
||
| /* send IPC to the DSP */ | ||
| ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, | ||
| sizeof(stream), &reply, sizeof(reply)); | ||
| ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm); | ||
|
|
||
| snd_pcm_lib_free_pages(substream); | ||
|
|
||
|
|
@@ -278,11 +293,7 @@ static int sof_pcm_prepare(struct snd_pcm_substream *substream) | |
| if (!spcm) | ||
| return -EINVAL; | ||
|
|
||
| /* | ||
| * check if hw_params needs to be set-up again. | ||
| * This is only needed when resuming from system sleep. | ||
| */ | ||
| if (!spcm->hw_params_upon_resume[substream->stream]) | ||
| if (spcm->prepared[substream->stream]) | ||
| return 0; | ||
|
|
||
| dev_dbg(sdev->dev, "pcm: prepare stream %d dir %d\n", spcm->pcm.pcm_id, | ||
|
|
@@ -311,6 +322,7 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |
| struct snd_sof_pcm *spcm; | ||
| struct sof_ipc_stream stream; | ||
| struct sof_ipc_reply reply; | ||
| bool reset_hw_params = false; | ||
| int ret; | ||
|
|
||
| /* nothing to do for BE */ | ||
|
|
@@ -351,6 +363,7 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |
| case SNDRV_PCM_TRIGGER_SUSPEND: | ||
| case SNDRV_PCM_TRIGGER_STOP: | ||
| stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP; | ||
| reset_hw_params = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add spcm->prepared[substream->stream] = false;
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang The prepared variable will be set to 'false' in this case. We set 'reset_hw_params' here to true, and at tne end of function, we will call sof_pcm_dsp_pcm_free() and this will set prepared[substream]=false. So should be fine, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I got it. I was confused by if(!ret) |
||
| break; | ||
| default: | ||
| dev_err(sdev->dev, "error: unhandled trigger cmd %d\n", cmd); | ||
|
|
@@ -363,21 +376,10 @@ static int sof_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |
| ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, | ||
| sizeof(stream), &reply, sizeof(reply)); | ||
|
|
||
| if (ret < 0 || cmd != SNDRV_PCM_TRIGGER_SUSPEND) | ||
| return ret; | ||
| if (!ret && reset_hw_params) | ||
| ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm); | ||
|
|
||
| /* | ||
| * The hw_free op is usually called when the pcm stream is closed. | ||
| * Since the stream is not closed during suspend, the DSP needs to be | ||
| * notified explicitly to free pcm to prevent errors upon resume. | ||
| */ | ||
| stream.hdr.size = sizeof(stream); | ||
| stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE; | ||
| stream.comp_id = spcm->stream[substream->stream].comp_id; | ||
|
|
||
| /* send IPC to the DSP */ | ||
| return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, | ||
| sizeof(stream), &reply, sizeof(reply)); | ||
| return ret; | ||
| } | ||
|
|
||
| static snd_pcm_uframes_t sof_pcm_pointer(struct snd_pcm_substream *substream) | ||
|
|
@@ -481,6 +483,7 @@ static int sof_pcm_open(struct snd_pcm_substream *substream) | |
| spcm->stream[substream->stream].posn.host_posn = 0; | ||
| spcm->stream[substream->stream].posn.dai_posn = 0; | ||
| spcm->stream[substream->stream].substream = substream; | ||
| spcm->prepared[substream->stream] = false; | ||
|
|
||
| ret = snd_sof_pcm_platform_open(sdev, substream); | ||
| if (ret < 0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better not call this function at all when CONFIG_SND_SOC_SOF_HDA isn't selected? The SOF CONFIG_* graph is too confusing...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh I completely agree, but I don't want to start refactoring the SOF_HDA approach in this patch too much. Now the #ifdefs are in hda-dsp.c code in sof/intel/ and not in the caller, and I'd prefer to keep it like this in the patch.
UPDATE: I have added cleaning the ifdef-chaos to this improvement item -> #990 @lyakh ok for you (for this patch)?