Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions drivers/soundwire/intel_ace2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ static int intel_params_stream(struct sdw_intel *sdw,
return -EIO;
}

static int intel_prepare_stream(struct sdw_intel *sdw,
struct snd_pcm_substream *substream,
struct snd_soc_dai *dai,
struct snd_pcm_hw_params *hw_params,
int link_id, int alh_stream_id)
{
struct sdw_intel_link_res *res = sdw->link_res;
struct sdw_intel_stream_params_data params_data;

params_data.substream = substream;
params_data.dai = dai;
params_data.hw_params = hw_params;
params_data.link_id = link_id;
params_data.alh_stream_id = alh_stream_id;

if (res->ops && res->ops->prepare_stream && res->dev)
return res->ops->prepare_stream(res->dev, &params_data);

return -EIO;
}

static int intel_free_stream(struct sdw_intel *sdw,
struct snd_pcm_substream *substream,
struct snd_soc_dai *dai,
Expand Down Expand Up @@ -422,8 +443,8 @@ static int intel_prepare(struct snd_pcm_substream *substream,
}

/* Inform DSP about PDI stream number */
return intel_params_stream(sdw, substream, dai, hw_params, sdw->instance,
dai_runtime->pdi->intel_alh_id);
return intel_prepare_stream(sdw, substream, dai, hw_params, sdw->instance,
dai_runtime->pdi->intel_alh_id);
}

static int
Expand Down
2 changes: 2 additions & 0 deletions include/linux/soundwire/sdw_intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ struct sdw_intel_stream_free_data {
struct sdw_intel_ops {
int (*params_stream)(struct device *dev,
struct sdw_intel_stream_params_data *params_data);
int (*prepare_stream)(struct device *dev,
struct sdw_intel_stream_params_data *params_data);
int (*free_stream)(struct device *dev,
struct sdw_intel_stream_free_data *free_data);
int (*trigger)(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai);
Expand Down
32 changes: 14 additions & 18 deletions sound/soc/sof/intel/hda-dai-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ static struct hdac_ext_stream *hda_ipc4_get_hext_stream(struct snd_sof_dev *sdev
struct snd_soc_dai *cpu_dai,
struct snd_pcm_substream *substream)
{
struct snd_sof_widget *pipe_widget;
struct sof_ipc4_pipeline *pipeline;
struct snd_sof_widget *swidget;
struct snd_soc_dapm_widget *w;

w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
swidget = w->dobj.private;
pipe_widget = swidget->spipe->pipe_widget;
pipeline = pipe_widget->private;

/* mark pipeline so that it can be skipped during FE trigger */
pipeline->skip_during_fe_trigger = true;

return snd_soc_dai_get_dma_data(cpu_dai, substream);
}

Expand Down Expand Up @@ -416,10 +403,11 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_STOP:
/*
* STOP/SUSPEND trigger is invoked only once when all users of this pipeline have
* been stopped. So, clear the started_count so that the pipeline can be reset
*/
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_RESET);
if (ret < 0)
goto out;
pipeline->state = SOF_IPC4_PIPE_RESET;
swidget->spipe->started_count = 0;
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Expand Down Expand Up @@ -623,28 +611,36 @@ hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidg
}
case SOF_IPC_TYPE_4:
{
struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
struct snd_sof_pipeline *spipe = swidget->spipe;
struct snd_sof_widget *pipe_widget = spipe->pipe_widget;
struct sof_ipc4_pipeline *pipeline = pipe_widget->private;

switch (sdai->type) {
case SOF_DAI_INTEL_HDA:
if (pipeline->use_chain_dma)
return &hda_ipc4_chain_dma_ops;

spipe->be_managed_pipeline = true;
return &hda_ipc4_dma_ops;
case SOF_DAI_INTEL_SSP:
if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
return NULL;

spipe->be_managed_pipeline = true;
return &ssp_ipc4_dma_ops;
case SOF_DAI_INTEL_DMIC:
if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
return NULL;

spipe->be_managed_pipeline = true;
return &dmic_ipc4_dma_ops;
case SOF_DAI_INTEL_ALH:
if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
return NULL;
if (pipeline->use_chain_dma)
return &sdw_ipc4_chain_dma_ops;

spipe->be_managed_pipeline = true;
return &sdw_ipc4_dma_ops;

default:
Expand Down
130 changes: 122 additions & 8 deletions sound/soc/sof/intel/hda-dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
static int __maybe_unused hda_dai_hw_free(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai)
{
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
struct hdac_ext_stream *hext_stream;
struct snd_sof_dev *sdev = dai_to_sdev(substream, cpu_dai);
struct snd_sof_widget *swidget = w->dobj.private;
int ret;

if (!ops) {
dev_err(cpu_dai->dev, "DAI widget ops not set\n");
Expand All @@ -222,9 +225,23 @@ static int __maybe_unused hda_dai_hw_free(struct snd_pcm_substream *substream,

hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream);
if (!hext_stream)
return 0;
goto free;

ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, true);
if (ret < 0)
return ret;

free:
if (sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, substream->stream);
if (ret < 0)
return ret;
}

return hda_link_dma_cleanup(substream, hext_stream, cpu_dai, true);
if (sof_is_widget_pipeline_be_managed(w))
snd_sof_unprepare_widgets_in_pipeline(w, swidget->spipe, substream->stream);

return 0;
}

static int __maybe_unused hda_dai_hw_params_data(struct snd_pcm_substream *substream,
Expand Down Expand Up @@ -316,14 +333,31 @@ static int __maybe_unused hda_dai_trigger(struct snd_pcm_substream *substream, i

switch (cmd) {
case SNDRV_PCM_TRIGGER_STOP:
ret = hda_link_dma_cleanup(substream, hext_stream, dai, false);
if (ret < 0) {
dev_err(sdev->dev, "%s: failed to clean up link DMA during stop\n",
__func__);
return ret;
}
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
ret = hda_link_dma_cleanup(substream, hext_stream, dai,
cmd == SNDRV_PCM_TRIGGER_STOP ? false : true);
{
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);

ret = hda_link_dma_cleanup(substream, hext_stream, dai, true);
if (ret < 0) {
dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__);
dev_err(sdev->dev, "%s: failed to clean up link DMA during suspend\n",
__func__);
return ret;
}

if (sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, substream->stream);
if (ret < 0)
return ret;
}
break;
}
default:
break;
}
Expand All @@ -336,9 +370,33 @@ static int __maybe_unused hda_dai_trigger(struct snd_pcm_substream *substream, i
static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
struct snd_sof_widget *swidget = w->dobj.private;
struct snd_sof_dev *sdev = widget_to_sdev(w);
int stream = substream->stream;
int ret;

if (!ops) {
dev_err(sdev->dev, "DAI widget ops not set\n");
return -EINVAL;
}

/* if this is a prepare without a hw_free or a suspend, free the BE pipeline */
if (swidget->spipe->complete && sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, stream);
if (ret < 0)
return ret;
}

ret = hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, dai);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any specific reason that we always call hw_params in .prepare?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because sometimes we dont have a hw_free like in the case of xruns and we'll need to do everything again.

Copy link
Member

Choose a reason for hiding this comment

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

prepare() should be fast. We should call this out in comments - we need to do X,Y out of cycle because Z

if (ret < 0)
return ret;

if (sof_is_widget_pipeline_be_managed(w))
return snd_sof_set_up_be_pipeline(w, stream);

return hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, dai);
return 0;
}

static const struct snd_soc_dai_ops hda_dai_ops = {
Expand Down Expand Up @@ -460,10 +518,27 @@ static int non_hda_dai_hw_params(struct snd_pcm_substream *substream,
static int non_hda_dai_prepare(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai)
{
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_sof_widget *swidget = w->dobj.private;
int stream = substream->stream;
int ret;

/* if this is a prepare without a hw_free or a suspend, free the BE pipeline */
if (swidget->spipe->complete && sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, stream);
if (ret < 0)
return ret;
}

ret = non_hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, cpu_dai);
if (ret < 0)
return ret;

if (sof_is_widget_pipeline_be_managed(w))
return snd_sof_set_up_be_pipeline(w, stream);

return non_hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, cpu_dai);
return 0;
}

static const struct snd_soc_dai_ops ssp_dai_ops = {
Expand Down Expand Up @@ -638,6 +713,38 @@ int sdw_hda_dai_trigger(struct snd_pcm_substream *substream, int cmd,
}
EXPORT_SYMBOL_NS(sdw_hda_dai_trigger, "SND_SOC_SOF_INTEL_HDA_COMMON");

int sdw_hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
struct snd_soc_dai *cpu_dai, int link_id, int intel_alh_id)
{
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
struct snd_sof_widget *swidget = w->dobj.private;
int stream = substream->stream;
int ret;

if (!ops) {
dev_err(cpu_dai->dev, "DAI widget ops not set\n");
return -EINVAL;
}

/* if this is a prepare without a hw_free or a suspend, free the BE pipeline */
if (swidget->spipe->complete && sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, stream);
if (ret < 0)
return ret;
}

ret = sdw_hda_dai_hw_params(substream, params, cpu_dai, link_id, intel_alh_id);
if (ret < 0)
return ret;

if (sof_is_widget_pipeline_be_managed(w))
return snd_sof_set_up_be_pipeline(w, stream);

return 0;
}
EXPORT_SYMBOL_NS(sdw_hda_dai_prepare, "SND_SOC_SOF_INTEL_HDA_COMMON");

static int hda_dai_suspend(struct hdac_bus *bus)
{
struct snd_soc_pcm_runtime *rtd;
Expand All @@ -663,10 +770,11 @@ static int hda_dai_suspend(struct hdac_bus *bus)
struct snd_soc_dai *cpu_dai;
struct snd_sof_dev *sdev;
struct snd_sof_dai *sdai;
int dir = s->direction;

rtd = snd_soc_substream_to_rtd(hext_stream->link_substream);
cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
w = snd_soc_dai_get_widget(cpu_dai, hdac_stream(hext_stream)->direction);
w = snd_soc_dai_get_widget(cpu_dai, dir);
swidget = w->dobj.private;
sdev = widget_to_sdev(w);
sdai = swidget->private;
Expand All @@ -689,6 +797,12 @@ static int hda_dai_suspend(struct hdac_bus *bus)
hext_stream, cpu_dai, true);
if (ret < 0)
return ret;

if (sof_is_widget_pipeline_be_managed(w)) {
ret = snd_sof_free_be_pipeline(w, dir);
if (ret < 0)
return ret;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions sound/soc/sof/intel/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ static int sdw_ace2x_params_stream(struct device *dev,
params_data->alh_stream_id);
}

static int sdw_ace2x_prepare_stream(struct device *dev,
struct sdw_intel_stream_params_data *params_data)
{
return sdw_hda_dai_prepare(params_data->substream, params_data->hw_params,
params_data->dai, params_data->link_id,
params_data->alh_stream_id);
}

static int sdw_ace2x_free_stream(struct device *dev,
struct sdw_intel_stream_free_data *free_data)
{
Expand All @@ -134,6 +142,7 @@ static int sdw_ace2x_trigger(struct snd_pcm_substream *substream, int cmd, struc

static struct sdw_intel_ops sdw_ace2x_callback = {
.params_stream = sdw_ace2x_params_stream,
.prepare_stream = sdw_ace2x_prepare_stream,
.free_stream = sdw_ace2x_free_stream,
.trigger = sdw_ace2x_trigger,
};
Expand Down
11 changes: 3 additions & 8 deletions sound/soc/sof/intel/hda.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,9 @@ int sdw_hda_dai_hw_free(struct snd_pcm_substream *substream,
int sdw_hda_dai_trigger(struct snd_pcm_substream *substream, int cmd,
struct snd_soc_dai *cpu_dai);

int sdw_hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
struct snd_soc_dai *cpu_dai, int link_id, int intel_alh_id);

/* common dai driver */
extern struct snd_soc_dai_driver skl_dai[];
int hda_dsp_dais_suspend(struct snd_sof_dev *sdev);
Expand Down Expand Up @@ -1039,12 +1042,4 @@ hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidg
int hda_dai_config(struct snd_soc_dapm_widget *w, unsigned int flags,
struct snd_sof_dai_config_data *data);

static inline struct snd_sof_dev *widget_to_sdev(struct snd_soc_dapm_widget *w)
{
struct snd_sof_widget *swidget = w->dobj.private;
struct snd_soc_component *component = swidget->scomp;

return snd_soc_component_get_drvdata(component);
}

#endif
Loading
Loading