diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index a8d6392f1e0735..98a76f07866a3a 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -151,77 +151,67 @@ static int hda_link_dma_params(struct hdac_ext_stream *stream, return 0; } -/* find the snd_sof_dai matching the BE CPU DAI name and update its config */ -static struct snd_sof_dai *hda_get_sof_dai(struct sof_intel_hda_stream *hda_stream, - const char *dai_name, int channel, int dir) +/* Update config for the DAI widget */ +static struct sof_ipc_dai_config *hda_dai_update_config(struct snd_soc_dapm_widget *w, + int channel) { - struct snd_sof_dev *sdev = hda_stream->sdev; + struct snd_sof_widget *swidget = w->dobj.private; struct sof_ipc_dai_config *config; struct snd_sof_dai *sof_dai; - bool found = false; - - /* find snd_sof_dai matching the BE CPU DAI name */ - list_for_each_entry(sof_dai, &sdev->dai_list, list) { - if (!sof_dai->cpu_dai_name) - continue; - if (!strcmp(dai_name, sof_dai->cpu_dai_name) && - dir == sof_dai->comp_dai.direction) { - found = true; - break; - } + if (!swidget) { + dev_err(swidget->scomp->dev, "error: No private data for widget %s\n", w->name); + return NULL; } - if (!found) { - dev_err(sdev->dev, "error: failed to find SOF DAI for: %s\n", dai_name); - return ERR_PTR(-ENOENT); - } + sof_dai = swidget->private; - config = sof_dai->dai_config; - if (!config) { - dev_err(sdev->dev, "error: no config for DAI %s\n", sof_dai->name); - return ERR_PTR(-ENOENT); + if (!sof_dai || !sof_dai->dai_config) { + dev_err(swidget->scomp->dev, "error: No config for DAI %s\n", w->name); + return NULL; } + config = &sof_dai->dai_config[sof_dai->current_config]; + /* update config with stream tag */ config->hda.link_dma_ch = channel; - return sof_dai; + return config; } static int hda_link_config_ipc(struct sof_intel_hda_stream *hda_stream, - const char *dai_name, int channel, int dir) + struct snd_soc_dapm_widget *w, int channel) { struct snd_sof_dev *sdev = hda_stream->sdev; struct sof_ipc_dai_config *config; - struct snd_sof_dai *sof_dai; struct sof_ipc_reply reply; - sof_dai = hda_get_sof_dai(hda_stream, dai_name, channel, dir); - if (IS_ERR(sof_dai)) - return PTR_ERR(sof_dai); - - config = sof_dai->dai_config; + config = hda_dai_update_config(w, channel); + if (!config) { + dev_err(sdev->dev, "error: no config for DAI %s\n", w->name); + return -ENOENT; + } /* send DAI_CONFIG IPC */ return sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, - &reply, sizeof(reply)); + &reply, sizeof(reply)); } static int hda_link_dai_widget_update(struct sof_intel_hda_stream *hda_stream, - const char *dai_name, int channel, int dir, - bool widget_setup) + struct snd_soc_dapm_widget *w, + int channel, bool widget_setup) { struct snd_sof_dev *sdev = hda_stream->sdev; - struct snd_sof_dai *sof_dai; + struct sof_ipc_dai_config *config; - sof_dai = hda_get_sof_dai(hda_stream, dai_name, channel, dir); - if (IS_ERR(sof_dai)) - return PTR_ERR(sof_dai); + config = hda_dai_update_config(w, channel); + if (!config) { + dev_err(sdev->dev, "error: no config for DAI %s\n", w->name); + return -ENOENT; + } /* set up/free DAI widget and send DAI_CONFIG IPC */ - return hda_ctrl_dai_widget_setup(sdev, sof_dai, sof_dai->dai_config, widget_setup, dir); - + return hda_ctrl_dai_widget_setup(w, widget_setup); } static int hda_link_hw_params(struct snd_pcm_substream *substream, @@ -235,6 +225,7 @@ static int hda_link_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); struct sof_intel_hda_stream *hda_stream; struct hda_pipe_params p_params = {0}; + struct snd_soc_dapm_widget *w; struct hdac_ext_link *link; int stream_tag; int ret; @@ -253,9 +244,13 @@ static int hda_link_hw_params(struct snd_pcm_substream *substream, hda_stream = hstream_to_sof_hda_stream(link_dev); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = dai->playback_widget; + else + w = dai->capture_widget; + /* set up the DAI widget and send the DAI_CONFIG with the new tag */ - ret = hda_link_dai_widget_update(hda_stream, dai->name, stream_tag - 1, - substream->stream, true); + ret = hda_link_dai_widget_update(hda_stream, w, stream_tag - 1, true); if (ret < 0) return ret; @@ -311,6 +306,7 @@ static int hda_link_pcm_trigger(struct snd_pcm_substream *substream, snd_soc_dai_get_dma_data(dai, substream); struct sof_intel_hda_stream *hda_stream; struct snd_soc_pcm_runtime *rtd; + struct snd_soc_dapm_widget *w; struct hdac_ext_link *link; struct hdac_stream *hstream; struct hdac_bus *bus; @@ -345,12 +341,16 @@ static int hda_link_pcm_trigger(struct snd_pcm_substream *substream, break; case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_STOP: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = dai->playback_widget; + else + w = dai->capture_widget; + /* * clear link DMA channel. It will be assigned when * hw_params is set up again after resume. */ - ret = hda_link_config_ipc(hda_stream, dai->name, - DMA_CHAN_INVALID, substream->stream); + ret = hda_link_config_ipc(hda_stream, w, DMA_CHAN_INVALID); if (ret < 0) return ret; @@ -381,6 +381,7 @@ static int hda_link_hw_free(struct snd_pcm_substream *substream, struct hdac_stream *hstream; struct snd_soc_pcm_runtime *rtd; struct hdac_ext_stream *link_dev; + struct snd_soc_dapm_widget *w; int ret; hstream = substream->runtime->private_data; @@ -396,9 +397,13 @@ static int hda_link_hw_free(struct snd_pcm_substream *substream, hda_stream = hstream_to_sof_hda_stream(link_dev); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = dai->playback_widget; + else + w = dai->capture_widget; + /* free the link DMA channel in the FW and the DAI widget */ - ret = hda_link_dai_widget_update(hda_stream, dai->name, DMA_CHAN_INVALID, - substream->stream, false); + ret = hda_link_dai_widget_update(hda_stream, w, DMA_CHAN_INVALID, false); if (ret < 0) return ret; @@ -443,41 +448,29 @@ static struct snd_soc_cdai_ops sof_probe_compr_ops = { #endif static int ssp_dai_config_update(struct snd_pcm_substream *substream, struct snd_soc_dai *dai, - bool widget_setup, int direction) + bool widget_setup) { - struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); - struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME); - struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); - struct sof_ipc_dai_config *config; - struct snd_sof_dai *sof_dai; - - list_for_each_entry(sof_dai, &sdev->dai_list, list) { - if (!sof_dai->cpu_dai_name || !sof_dai->dai_config) - continue; + struct snd_soc_dapm_widget *w; - if (!strcmp(dai->name, sof_dai->cpu_dai_name) && - direction == sof_dai->comp_dai.direction) { - config = &sof_dai->dai_config[sof_dai->current_config]; - - return hda_ctrl_dai_widget_setup(sdev, sof_dai, config, widget_setup, - direction); - } - } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = dai->playback_widget; + else + w = dai->capture_widget; - return 0; + return hda_ctrl_dai_widget_setup(w, widget_setup); } static int ssp_dai_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - return ssp_dai_config_update(substream, dai, true, substream->stream); + return ssp_dai_config_update(substream, dai, true); } static int ssp_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - return ssp_dai_config_update(substream, dai, false, substream->stream); + return ssp_dai_config_update(substream, dai, false); } static const struct snd_soc_dai_ops ssp_dai_ops = { diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index c69ff23d9c14fe..1d6053ad6e5750 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -45,55 +45,49 @@ * Helper function to set up a DAI widget in the DSP and then send the updated DAI config during * hw_params or send the updated DAI_CONFIG and then free the DAI widget during hw_free */ -int hda_ctrl_dai_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_dai *sof_dai, - struct sof_ipc_dai_config *config, bool setup, int dir) +int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, bool setup) { - struct snd_sof_widget *swidget; + struct snd_sof_widget *swidget = w->dobj.private; + struct snd_soc_component *component = swidget->scomp; + struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); + struct sof_ipc_dai_config *config; + struct snd_sof_dai *sof_dai; struct sof_ipc_reply reply; - bool found = false; int ret; - /* find snd_sof_widget of type DAI with matching sname as that of snd_sof_dai name */ - list_for_each_entry(swidget, &sdev->widget_list, list) { - if (dir == SNDRV_PCM_STREAM_PLAYBACK && swidget->id != snd_soc_dapm_dai_in) - continue; - - if (dir == SNDRV_PCM_STREAM_CAPTURE && swidget->id != snd_soc_dapm_dai_out) - continue; + sof_dai = swidget->private; - if (!strcmp(sof_dai->name, swidget->widget->sname)) { - found = true; - break; - } - } - - if (!found) { - dev_err(sdev->dev, "error: failed to find DAI widget for: %s\n", - sof_dai->cpu_dai_name); + if (!sof_dai || !sof_dai->dai_config) { + dev_err(sdev->dev, "No config for DAI %s\n", w->name); return -EINVAL; } + config = &sof_dai->dai_config[sof_dai->current_config]; + /* * For static pipelines, the DAI widget would already be set up and calling * sof_widget_setup()/free() simply returns without doing anything. * For dynamic pipelines, the DAI widget will be set up or freed here. */ if (setup) { - /* set up widget first */ ret = sof_widget_setup(sdev, swidget); + if (ret < 0) { + dev_err(sdev->dev, "error: setting up DAI widget %s\n", w->name); + return ret; + } - /* and then send DAI_CONFIG IPC */ + /* send DAI_CONFIG IPC */ return sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, &reply, sizeof(reply)); } - /* send DAI_CONFIG IPC first */ - ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, &reply, - sizeof(reply)); - if (ret < 0) + ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, + &reply, sizeof(reply)); + if (ret < 0) { + dev_err(sdev->dev, "error: updating DAI config for %s\n", w->name); return ret; + } - /* and then free the widget */ return sof_widget_free(sdev, swidget); } @@ -109,36 +103,33 @@ static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET; module_param(sdw_clock_stop_quirks, int, 0444); MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks"); -static int sdw_dai_config_ipc(struct snd_sof_dev *sdev, struct snd_soc_dai *d, - int link_id, int alh_stream_id, bool setup, int dir) +static int sdw_dai_config_ipc(struct snd_sof_dev *sdev, + struct snd_soc_dapm_widget *w, + int link_id, int alh_stream_id, int dai_id, bool setup) { + struct snd_sof_widget *swidget = w->dobj.private; struct sof_ipc_dai_config *config; struct snd_sof_dai *sof_dai; - bool found = false; - - /* find snd_sof_dai matching the BE CPU DAI name */ - list_for_each_entry(sof_dai, &sdev->dai_list, list) - if (sof_dai->cpu_dai_name && !strcmp(d->name, sof_dai->cpu_dai_name)) { - found = true; - break; - } - if (!found) { - dev_err(sdev->dev, "error: failed to find SOF DAI for: %s\n", d->name); + if (!swidget) { + dev_err(sdev->dev, "error: No private data for widget %s\n", w->name); return -EINVAL; } - config = sof_dai->dai_config; - if (!config) { - dev_err(sdev->dev, "error: no config for DAI %s\n", sof_dai->name); + sof_dai = swidget->private; + + if (!sof_dai || !sof_dai->dai_config) { + dev_err(sdev->dev, "error: No config for DAI %s\n", w->name); return -EINVAL; } + config = &sof_dai->dai_config[sof_dai->current_config]; + /* update config with link and stream ID */ - config->dai_index = (link_id << 8) | d->id; + config->dai_index = (link_id << 8) | dai_id; config->alh.stream_id = alh_stream_id; - return hda_ctrl_dai_widget_setup(sdev, sof_dai, config, setup, dir); + return hda_ctrl_dai_widget_setup(w, setup); } static int sdw_params_stream(struct device *dev, @@ -147,9 +138,15 @@ static int sdw_params_stream(struct device *dev, struct snd_pcm_substream *substream = params_data->substream; struct snd_sof_dev *sdev = dev_get_drvdata(dev); struct snd_soc_dai *d = params_data->dai; + struct snd_soc_dapm_widget *w; - return sdw_dai_config_ipc(sdev, d, params_data->link_id, params_data->alh_stream_id, - true, substream->stream); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = d->playback_widget; + else + w = d->capture_widget; + + return sdw_dai_config_ipc(sdev, w, params_data->link_id, params_data->alh_stream_id, + d->id, true); } static int sdw_free_stream(struct device *dev, @@ -158,9 +155,15 @@ static int sdw_free_stream(struct device *dev, struct snd_pcm_substream *substream = free_data->substream; struct snd_sof_dev *sdev = dev_get_drvdata(dev); struct snd_soc_dai *d = free_data->dai; + struct snd_soc_dapm_widget *w; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + w = d->playback_widget; + else + w = d->capture_widget; /* send invalid stream_id */ - return sdw_dai_config_ipc(sdev, d, free_data->link_id, 0xFFFF, false, substream->stream); + return sdw_dai_config_ipc(sdev, w, free_data->link_id, 0xFFFF, d->id, false); } static const struct sdw_intel_ops sdw_callback = { diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index 8db0fd97012ada..1715eeed3c0db8 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -770,7 +770,6 @@ int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) struct snd_sof_dai; struct sof_ipc_dai_config; -int hda_ctrl_dai_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_dai *sof_dai, - struct sof_ipc_dai_config *config, bool setup, int dir); +int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, bool setup); #endif diff --git a/sound/soc/sof/sof-audio.c b/sound/soc/sof/sof-audio.c index 2dc8f8bc375400..b64ead1f10531a 100644 --- a/sound/soc/sof/sof-audio.c +++ b/sound/soc/sof/sof-audio.c @@ -45,10 +45,11 @@ static int sof_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_control * static int sof_dai_config_setup(struct snd_sof_dev *sdev, struct snd_sof_dai *dai) { + struct sof_ipc_dai_config *config; struct sof_ipc_reply reply; - struct sof_ipc_dai_config *config = dai->dai_config; int ret; + config = &dai->dai_config[dai->current_config]; if (!config) { dev_err(sdev->dev, "error: no config for DAI %s\n", dai->name); return -EINVAL; diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 3daae8c4e34a93..5de65c1b69d0a5 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -130,7 +130,6 @@ struct snd_sof_route { struct snd_sof_dai { struct snd_soc_component *scomp; const char *name; - const char *cpu_dai_name; struct sof_ipc_comp_dai comp_dai; int number_configs; diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 51aed7a0e7d10f..744d6a5fd560a1 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -2753,9 +2753,6 @@ static int sof_set_dai_config_multi(struct snd_sof_dev *sdev, u32 size, if (!dai->dai_config) return -ENOMEM; - /* set cpu_dai_name */ - dai->cpu_dai_name = link->cpus->dai_name; - found = 1; } }