Skip to contentSkip to conversation

ASoC: SOF: Intel: hda: Introduce HDA DAI abstraction

PATCH In review Peter Ujfalusi 2 participants 16 messages Mar 7, 2023 – Mar 9, 2023

Subsystems (3)
lore
Share & tools
lore

Peter Ujfalusi

author maintainer
#0 lore raw

cover ASoC: SOF: Intel: hda: Introduce HDA DAI abstraction

Hi,

This series introduces an abstraction of the HDA DAI handling.

The motivation is to simplify and make the code more flexible regarding to IPC versions, new features (ChainDMA (IPC4) and DSPless mode) and to pave the way for new platforms.

For the first look the series might feels a bit too intrusive but it introduces no functionality change (tested at each commit).

Regards,
Peter
---
Ranjani Sridharan (14):
ASoC: SOF: Intel: hda-dai: Remove BE DAI DRV ops for SSP DAI's
ASoC: SOF: Intel: hda-dai: Remove hda_link_dma_params()
ASoC: SOF: Intel: hda-dai: remove struct hda_pipe_params
ASoC: SOF: Intel: hda-dai: Modify the signature of
hda_link_dma_cleanup()
ASoC: SOF: Intel: hda-dai: Pass the CPU dai pointer
ASoC: SOF: Intel: hda-dai: Use the dai argument in
ipc4_hda_dai_trigger
ASoC: SOF: Intel: hda-dai: Introduce DAI widget ops
ASoC: SOF: Intel: hda-dai: Define and set the HDA DAI widget DMA ops
ASoC: SOF: Intel: hda-dai: Add setup_hext_stream/reset_hext_stream DMA
ops
ASoC: SOF: Intel: hda-dai: Use the topology IPC dai_config op
ASoC: SOF: Intel: hda-dai: Define DAI widget DMA trigger ops for IPC4
ASoC: SOF: Intel: hda: Unify DAI drv ops for IPC3 and IPC4
ASoC: SOF: Intel: hda: Remove hda_ctrl_dai_widget_setup/free()
ASoC: SOF: Intel: hda: remove redundant DAI config during hw_free

 sound/soc/sof/intel/Makefile      |   2 +-
 sound/soc/sof/intel/hda-dai-ops.c | 343 +++++++++++++++
 sound/soc/sof/intel/hda-dai.c     | 688 ++++++++----------------------
 sound/soc/sof/intel/hda.c         |  88 +---
 sound/soc/sof/intel/hda.h         |  41 +-
 sound/soc/sof/sof-audio.h         |   2 +
 6 files changed, 554 insertions(+), 610 deletions(-)
 create mode 100644 sound/soc/sof/intel/hda-dai-ops.c
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/14 ASoC: SOF: Intel: hda-dai: Remove BE DAI DRV ops for SSP DAI's

From: Ranjani Sridharan <[email protected]>

Now that the DAI_CONFIG IPC is sent after widget setup and before widget free, there is no need for the BE DAI DRV ops that do the same thing. So remove them.

---
 sound/soc/sof/intel/hda-dai.c | 113 ----------------------------------
 1 file changed, 113 deletions(-)
sound/soc/sof/intel/hda-dai.c +0 -113
index 8d9c38d562d3..c7f89c18d5c2 100644
@@ -605,115 +605,6 @@ static const struct snd_soc_dai_ops ipc4_hda_dai_ops = {
 
 #endif
 
-/* only one flag used so far to harden hw_params/hw_free/trigger/prepare */
-struct ssp_dai_dma_data {
-	bool setup;
-};
-
-static int ssp_dai_setup_or_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai,
-				 bool setup)
-{
-	struct snd_soc_dapm_widget *w;
-
-	w = snd_soc_dai_get_widget(dai, substream->stream);
-
-	if (setup)
-		return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE, NULL);
-
-	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, NULL);
-}
-
-static int ssp_dai_startup(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai)
-{
-	struct ssp_dai_dma_data *dma_data;
-
-	dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL);
-	if (!dma_data)
-		return -ENOMEM;
-
-	snd_soc_dai_set_dma_data(dai, substream, dma_data);
-
-	return 0;
-}
-
-static int ssp_dai_setup(struct snd_pcm_substream *substream,
-			 struct snd_soc_dai *dai,
-			 bool setup)
-{
-	struct ssp_dai_dma_data *dma_data;
-	int ret = 0;
-
-	dma_data = snd_soc_dai_get_dma_data(dai, substream);
-	if (!dma_data) {
-		dev_err(dai->dev, "%s: failed to get dma_data\n", __func__);
-		return -EIO;
-	}
-
-	if (dma_data->setup != setup) {
-		ret = ssp_dai_setup_or_free(substream, dai, setup);
-		if (!ret)
-			dma_data->setup = setup;
-	}
-	return ret;
-}
-
-static int ssp_dai_hw_params(struct snd_pcm_substream *substream,
-			     struct snd_pcm_hw_params *params,
-			     struct snd_soc_dai *dai)
-{
-	/* params are ignored for now */
-	return ssp_dai_setup(substream, dai, true);
-}
-
-static int ssp_dai_prepare(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai)
-{
-	/*
-	 * the SSP will only be reconfigured during resume operations and
-	 * not in case of xruns
-	 */
-	return ssp_dai_setup(substream, dai, true);
-}
-
-static int ipc3_ssp_dai_trigger(struct snd_pcm_substream *substream,
-				int cmd, struct snd_soc_dai *dai)
-{
-	if (cmd != SNDRV_PCM_TRIGGER_SUSPEND)
-		return 0;
-
-	return ssp_dai_setup(substream, dai, false);
-}
-
-static int ssp_dai_hw_free(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai)
-{
-	return ssp_dai_setup(substream, dai, false);
-}
-
-static void ssp_dai_shutdown(struct snd_pcm_substream *substream,
-			     struct snd_soc_dai *dai)
-{
-	struct ssp_dai_dma_data *dma_data;
-
-	dma_data = snd_soc_dai_get_dma_data(dai, substream);
-	if (!dma_data) {
-		dev_err(dai->dev, "%s: failed to get dma_data\n", __func__);
-		return;
-	}
-	snd_soc_dai_set_dma_data(dai, substream, NULL);
-	kfree(dma_data);
-}
-
-static const struct snd_soc_dai_ops ipc3_ssp_dai_ops = {
-	.startup = ssp_dai_startup,
-	.hw_params = ssp_dai_hw_params,
-	.prepare = ssp_dai_prepare,
-	.trigger = ipc3_ssp_dai_trigger,
-	.hw_free = ssp_dai_hw_free,
-	.shutdown = ssp_dai_shutdown,
-};
-
 void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops)
 {
 	int i;
@@ -721,10 +612,6 @@ void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops)
 	switch (sdev->pdata->ipc_type) {
 	case SOF_IPC:
 		for (i = 0; i < ops->num_drv; i++) {
-			if (strstr(ops->drv[i].name, "SSP")) {
-				ops->drv[i].ops = &ipc3_ssp_dai_ops;
-				continue;
-			}
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
 			if (strstr(ops->drv[i].name, "iDisp") ||
 			    strstr(ops->drv[i].name, "Analog") ||
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 2/14 ASoC: SOF: Intel: hda-dai: Remove hda_link_dma_params()

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

No code change. Just code move from hda_link_dma_params() to hda_link_dma_hw_params().

---
 sound/soc/sof/intel/hda-dai.c | 62 ++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 34 deletions(-)
sound/soc/sof/intel/hda-dai.c +28 -34
index c7f89c18d5c2..770c00ae29ac 100644
@@ -168,39 +168,6 @@ static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int hda_link_dma_params(struct hdac_ext_stream *hext_stream,
-			       struct hda_pipe_params *params)
-{
-	struct hdac_stream *hstream = &hext_stream->hstream;
-	unsigned char stream_tag = hstream->stream_tag;
-	struct hdac_bus *bus = hstream->bus;
-	struct hdac_ext_link *hlink;
-	unsigned int format_val;
-
-	snd_hdac_ext_stream_reset(hext_stream);
-
-	format_val = snd_hdac_calc_stream_format(params->s_freq, params->ch,
-						 params->format,
-						 params->link_bps, 0);
-
-	dev_dbg(bus->dev, "format_val=%d, rate=%d, ch=%d, format=%d\n",
-		format_val, params->s_freq, params->ch, params->format);
-
-	snd_hdac_ext_stream_setup(hext_stream, format_val);
-
-	if (hext_stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) {
-		list_for_each_entry(hlink, &bus->hlink_list, list) {
-			if (hlink->index == params->link_index)
-				snd_hdac_ext_bus_link_set_stream_id(hlink,
-								    stream_tag);
-		}
-	}
-
-	hext_stream->link_prepared = 1;
-
-	return 0;
-}
-
 static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 				  struct snd_pcm_hw_params *params)
 {
@@ -209,9 +176,12 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 	struct hda_pipe_params p_params = {0};
 	struct hdac_ext_stream *hext_stream;
+	struct hdac_stream *hstream;
 	struct hdac_ext_link *hlink;
 	struct snd_sof_dev *sdev;
 	struct hdac_bus *bus;
+	unsigned int format_val;
+	unsigned char stream_tag;
 
 	sdev = snd_soc_component_get_drvdata(cpu_dai->component);
 	bus = sof_to_bus(sdev);
@@ -229,6 +199,9 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 		snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)hext_stream);
 	}
 
+	hstream = &hext_stream->hstream;
+	stream_tag = hstream->stream_tag;
+
 	/* set the hdac_stream in the codec dai */
 	snd_soc_dai_set_stream(codec_dai, hdac_stream(hext_stream), substream->stream);
 
@@ -242,7 +215,28 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	else
 		p_params.link_bps = codec_dai->driver->capture.sig_bits;
 
-	return hda_link_dma_params(hext_stream, &p_params);
+	snd_hdac_ext_stream_reset(hext_stream);
+
+	format_val = snd_hdac_calc_stream_format(p_params.s_freq, p_params.ch,
+						 p_params.format,
+						 p_params.link_bps, 0);
+
+	dev_dbg(bus->dev, "format_val=%d, rate=%d, ch=%d, format=%d\n",
+		format_val, p_params.s_freq, p_params.ch, p_params.format);
+
+	snd_hdac_ext_stream_setup(hext_stream, format_val);
+
+	if (hext_stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) {
+		list_for_each_entry(hlink, &bus->hlink_list, list) {
+			if (hlink->index == p_params.link_index)
+				snd_hdac_ext_bus_link_set_stream_id(hlink,
+								    stream_tag);
+		}
+	}
+
+	hext_stream->link_prepared = 1;
+
+	return 0;
 }
 
 static int hda_link_dma_prepare(struct snd_pcm_substream *substream)
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 3/14 ASoC: SOF: Intel: hda-dai: remove struct hda_pipe_params

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Remove the struct definition and use the params argument directly. Also, use the hlink pointer to set the stream ID instead of looking it up again.

---
 sound/soc/sof/intel/hda-dai.c | 37 +++++++++--------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)
sound/soc/sof/intel/hda-dai.c +9 -28
index 770c00ae29ac..009299c6de40 100644
@@ -29,14 +29,6 @@ MODULE_PARM_DESC(sof_use_tplg_nhlt, "SOF topology nhlt override");
 
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
 
-struct hda_pipe_params {
-	u32 ch;
-	u32 s_freq;
-	snd_pcm_format_t format;
-	int link_index;
-	unsigned int link_bps;
-};
-
 /*
  * This function checks if the host dma channel corresponding
  * to the link DMA stream_tag argument is assigned to one
@@ -174,13 +166,13 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
-	struct hda_pipe_params p_params = {0};
 	struct hdac_ext_stream *hext_stream;
 	struct hdac_stream *hstream;
 	struct hdac_ext_link *hlink;
 	struct snd_sof_dev *sdev;
 	struct hdac_bus *bus;
 	unsigned int format_val;
+	unsigned int link_bps;
 	unsigned char stream_tag;
 
 	sdev = snd_soc_component_get_drvdata(cpu_dai->component);
@@ -202,38 +194,27 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	hstream = &hext_stream->hstream;
 	stream_tag = hstream->stream_tag;
 
+	if (hext_stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK)
+		snd_hdac_ext_bus_link_set_stream_id(hlink, stream_tag);
+
 	/* set the hdac_stream in the codec dai */
 	snd_soc_dai_set_stream(codec_dai, hdac_stream(hext_stream), substream->stream);
 
-	p_params.ch = params_channels(params);
-	p_params.s_freq = params_rate(params);
-	p_params.link_index = hlink->index;
-	p_params.format = params_format(params);
-
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		p_params.link_bps = codec_dai->driver->playback.sig_bits;
+		link_bps = codec_dai->driver->playback.sig_bits;
 	else
-		p_params.link_bps = codec_dai->driver->capture.sig_bits;
+		link_bps = codec_dai->driver->capture.sig_bits;
 
 	snd_hdac_ext_stream_reset(hext_stream);
 
-	format_val = snd_hdac_calc_stream_format(p_params.s_freq, p_params.ch,
-						 p_params.format,
-						 p_params.link_bps, 0);
+	format_val = snd_hdac_calc_stream_format(params_rate(params), params_channels(params),
+						 params_format(params), link_bps, 0);
 
 	dev_dbg(bus->dev, "format_val=%d, rate=%d, ch=%d, format=%d\n",
-		format_val, p_params.s_freq, p_params.ch, p_params.format);
+		format_val, params_rate(params), params_channels(params), params_format(params));
 
 	snd_hdac_ext_stream_setup(hext_stream, format_val);
 
-	if (hext_stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) {
-		list_for_each_entry(hlink, &bus->hlink_list, list) {
-			if (hlink->index == p_params.link_index)
-				snd_hdac_ext_bus_link_set_stream_id(hlink,
-								    stream_tag);
-		}
-	}
-
 	hext_stream->link_prepared = 1;
 
 	return 0;
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH 4/14 ASoC: SOF: Intel: hda-dai: Modify the signature of hda_link_dma_cleanup()

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Remove the trigger_suspend_stop argument from hda_link_dma_cleanup() and move the call to snd_hdac_ext_stream_clear() into snd_hdac_ext_stream_clear(). This is a preparatory step to unify the trigger ops for IPC3 and IPC4.

---
 sound/soc/sof/intel/hda-dai.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
sound/soc/sof/intel/hda-dai.c +6 -9
index 009299c6de40..d4b98bfe2adf 100644
@@ -129,8 +129,7 @@ hda_link_stream_assign(struct hdac_bus *bus,
 static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
 				struct hdac_ext_stream *hext_stream,
 				struct snd_soc_dai *cpu_dai,
-				struct snd_soc_dai *codec_dai,
-				bool trigger_suspend_stop)
+				struct snd_soc_dai *codec_dai)
 {
 	struct hdac_stream *hstream = &hext_stream->hstream;
 	struct hdac_bus *bus = hstream->bus;
@@ -142,9 +141,6 @@ static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
 	if (!hlink)
 		return -EINVAL;
 
-	if (trigger_suspend_stop)
-		snd_hdac_ext_stream_clear(hext_stream);
-
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		stream_tag = hdac_stream(hext_stream)->stream_tag;
 		snd_hdac_ext_bus_link_clear_stream_id(hlink, stream_tag);
@@ -246,7 +242,8 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
 		break;
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
-		ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai, true);
+		snd_hdac_ext_stream_clear(hext_stream);
+		ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
 		if (ret < 0)
 			return ret;
 
@@ -272,7 +269,7 @@ static int hda_link_dma_hw_free(struct snd_pcm_substream *substream)
 	if (!hext_stream)
 		return 0;
 
-	return hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai, false);
+	return hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
 }
 
 static int hda_dai_widget_update(struct snd_soc_dapm_widget *w,
@@ -483,7 +480,7 @@ static int ipc4_hda_dai_trigger(struct snd_pcm_substream *substream,
 
 		pipeline->state = SOF_IPC4_PIPE_RESET;
 
-		ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai, false);
+		ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
 		if (ret < 0) {
 			dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__);
 			return ret;
@@ -557,7 +554,7 @@ static int hda_dai_suspend(struct hdac_bus *bus)
 
 			ret = hda_link_dma_cleanup(hext_stream->link_substream,
 						   hext_stream,
-						   cpu_dai, codec_dai, false);
+						   cpu_dai, codec_dai);
 			if (ret < 0)
 				return ret;
 
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 5/14 ASoC: SOF: Intel: hda-dai: Pass the CPU dai pointer

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Pass the CPU DAI pointer from the ASoC core to hda_link_dma_hw_params() and ipc3_hda_dai_trigger(). This will avoid looking up the CPU DAI pointer multiple times.

---
 sound/soc/sof/intel/hda-dai.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
sound/soc/sof/intel/hda-dai.c +10 -12
index d4b98bfe2adf..e448c653cfe1 100644
@@ -157,10 +157,9 @@ static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
 }
 
 static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
-				  struct snd_pcm_hw_params *params)
+				  struct snd_pcm_hw_params *params, struct snd_soc_dai *cpu_dai)
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 	struct hdac_ext_stream *hext_stream;
 	struct hdac_stream *hstream;
@@ -216,18 +215,18 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int hda_link_dma_prepare(struct snd_pcm_substream *substream)
+static int hda_link_dma_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
 	int stream = substream->stream;
 
-	return hda_link_dma_hw_params(substream, &rtd->dpcm[stream].hw_params);
+	return hda_link_dma_hw_params(substream, &rtd->dpcm[stream].hw_params, cpu_dai);
 }
 
-static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
+static int hda_link_dma_trigger(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai,
+				int cmd)
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 	struct hdac_ext_stream *hext_stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
 	int ret;
@@ -258,10 +257,9 @@ static int hda_link_dma_trigger(struct snd_pcm_substream *substream, int cmd)
 	return 0;
 }
 
-static int hda_link_dma_hw_free(struct snd_pcm_substream *substream)
+static int hda_link_dma_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 	struct hdac_ext_stream *hext_stream;
 
@@ -317,7 +315,7 @@ static int hda_dai_hw_params(struct snd_pcm_substream *substream,
 	if (hext_stream && hext_stream->link_prepared)
 		return 0;
 
-	ret = hda_link_dma_hw_params(substream, params);
+	ret = hda_link_dma_hw_params(substream, params, dai);
 	if (ret < 0)
 		return ret;
 
@@ -357,7 +355,7 @@ static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_d
 
 	dev_dbg(sdev->dev, "prepare stream dir %d\n", substream->stream);
 
-	ret = hda_link_dma_prepare(substream);
+	ret = hda_link_dma_prepare(substream, dai);
 	if (ret < 0)
 		return ret;
 
@@ -384,7 +382,7 @@ static int ipc3_hda_dai_trigger(struct snd_pcm_substream *substream,
 	dev_dbg(dai->dev, "cmd=%d dai %s direction %d\n", cmd,
 		dai->name, substream->stream);
 
-	ret = hda_link_dma_trigger(substream, cmd);
+	ret = hda_link_dma_trigger(substream, dai, cmd);
 	if (ret < 0)
 		return ret;
 
@@ -512,7 +510,7 @@ static int hda_dai_hw_free(struct snd_pcm_substream *substream,
 {
 	int ret;
 
-	ret = hda_link_dma_hw_free(substream);
+	ret = hda_link_dma_hw_free(substream, dai);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH 6/14 ASoC: SOF: Intel: hda-dai: Use the dai argument in ipc4_hda_dai_trigger

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

No need to define a new variable and look it up again.

---
 sound/soc/sof/intel/hda-dai.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sof/intel/hda-dai.c +1 -3
index e448c653cfe1..49f25e55b15d 100644
@@ -426,14 +426,12 @@ static int ipc4_hda_dai_trigger(struct snd_pcm_substream *substream,
 	struct snd_sof_widget *swidget;
 	struct snd_soc_dapm_widget *w;
 	struct snd_soc_dai *codec_dai;
-	struct snd_soc_dai *cpu_dai;
 	int ret;
 
 	dev_dbg(dai->dev, "cmd=%d dai %s direction %d\n", cmd,
 		dai->name, substream->stream);
 
 	rtd = asoc_substream_to_rtd(substream);
-	cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	codec_dai = asoc_rtd_to_codec(rtd, 0);
 
 	w = snd_soc_dai_get_widget(dai, substream->stream);
@@ -478,7 +476,7 @@ static int ipc4_hda_dai_trigger(struct snd_pcm_substream *substream,
 
 		pipeline->state = SOF_IPC4_PIPE_RESET;
 
-		ret = hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
+		ret = hda_link_dma_cleanup(substream, hext_stream, dai, codec_dai);
 		if (ret < 0) {
 			dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__);
 			return ret;
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH 7/14 ASoC: SOF: Intel: hda-dai: Introduce DAI widget ops

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Introduce a new ops structure for HDA DAI widget DMA ops and add a new field to struct snd_sof_dai that will be used to set the ops pointer for DAI widgets.

---
 sound/soc/sof/intel/hda.h | 31 +++++++++++++++++++++++++++++++
 sound/soc/sof/sof-audio.h |  2 ++
 2 files changed, 33 insertions(+)
sound/soc/sof/intel/hda.h +31 -0
index 0679bebe4ad7..c6243827f8d0 100644
@@ -928,4 +928,35 @@ extern struct sdw_intel_ops sdw_callback;
 struct sof_ipc4_fw_library;
 int hda_dsp_ipc4_load_library(struct snd_sof_dev *sdev,
 			      struct sof_ipc4_fw_library *fw_lib, bool reload);
+
+/**
+ * struct hda_dai_widget_dma_ops - DAI DMA ops optional by default unless specified otherwise
+ * @get_hext_stream: Mandatory function pointer to get the saved pointer to struct hdac_ext_stream
+ * @assign_hext_stream: Function pointer to assign a hdac_ext_stream
+ * @release_hext_stream: Function pointer to release the hdac_ext_stream
+ * @setup_hext_stream: Function pointer for hdac_ext_stream setup
+ * @reset_hext_stream: Function pointer for hdac_ext_stream reset
+ * @pre_trigger: Function pointer for DAI DMA pre-trigger actions
+ * @trigger: Function pointer for DAI DMA trigger actions
+ * @post_trigger: Function pointer for DAI DMA post-trigger actions
+ */
+struct hda_dai_widget_dma_ops {
+	struct hdac_ext_stream *(*get_hext_stream)(struct snd_sof_dev *sdev,
+						   struct snd_soc_dai *cpu_dai,
+						   struct snd_pcm_substream *substream);
+	struct hdac_ext_stream *(*assign_hext_stream)(struct snd_sof_dev *sdev,
+						      struct snd_soc_dai *cpu_dai,
+						      struct snd_pcm_substream *substream);
+	void (*release_hext_stream)(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+				    struct snd_pcm_substream *substream);
+	void (*setup_hext_stream)(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream,
+				  unsigned int format_val);
+	void (*reset_hext_stream)(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_sream);
+	int (*pre_trigger)(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+			   struct snd_pcm_substream *substream, int cmd);
+	int (*trigger)(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+		       struct snd_pcm_substream *substream, int cmd);
+	int (*post_trigger)(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+			    struct snd_pcm_substream *substream, int cmd);
+};
 #endif
sound/soc/sof/sof-audio.h +2 -0
index e0579af9d281..239b82f37976 100644
@@ -502,6 +502,8 @@ struct snd_sof_dai {
 	int number_configs;
 	int current_config;
 	struct list_head list;	/* list in sdev dai list */
+	/* core should not touch this */
+	const void *platform_private;
 	void *private;
 };
 
Signature · 1 line
2.39.2
author maintainer
#8 lore raw

PATCH 8/14 ASoC: SOF: Intel: hda-dai: Define and set the HDA DAI widget DMA ops

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Define and set the get_hext_stream, assign_hext_stream and release_hext_stream DMA ops for HDA DAIs.

---
 sound/soc/sof/intel/Makefile      |   2 +-
 sound/soc/sof/intel/hda-dai-ops.c | 183 +++++++++++++++++++++++++++++
 sound/soc/sof/intel/hda-dai.c     | 188 +++++++++++-------------------
 sound/soc/sof/intel/hda.h         |   4 +
 4 files changed, 259 insertions(+), 118 deletions(-)
 create mode 100644 sound/soc/sof/intel/hda-dai-ops.c
sound/soc/sof/intel/Makefile +1 -1
index 8201cbdd654c..38ab86b6a9fe 100644
@@ -5,7 +5,7 @@ snd-sof-acpi-intel-bdw-objs := bdw.o
 
 snd-sof-intel-hda-common-objs := hda.o hda-loader.o hda-stream.o hda-trace.o \
 				 hda-dsp.o hda-ipc.o hda-ctrl.o hda-pcm.o \
-				 hda-dai.o hda-bus.o hda-mlink.o \
+				 hda-dai.o hda-dai-ops.o hda-bus.o hda-mlink.o \
 				 skl.o hda-loader-skl.o \
 				 apl.o cnl.o tgl.o icl.o mtl.o hda-common-ops.o
 
sound/soc/sof/intel/hda-dai-ops.c new file +183 -0

183 lines not on this page · raw message

sound/soc/sof/intel/hda-dai.c +71 -117

304 lines not on this page · raw message

sound/soc/sof/intel/hda.h +4 -0
index c6243827f8d0..e0469f86fa63 100644
@@ -959,4 +959,8 @@ struct hda_dai_widget_dma_ops {
 	int (*post_trigger)(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
 			    struct snd_pcm_substream *substream, int cmd);
 };
+
+const struct hda_dai_widget_dma_ops *
+hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+
 #endif
Signature · 1 line
2.39.2
author maintainer
#9 lore raw

PATCH 9/14 ASoC: SOF: Intel: hda-dai: Add setup_hext_stream/reset_hext_stream DMA ops

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Define and use the setup_hext_stream/reset_hext_stream DMA ops during link hw_params and cleanup.

---
 sound/soc/sof/intel/hda-dai-ops.c | 13 +++++++++++++
 sound/soc/sof/intel/hda-dai.c     |  6 ++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
sound/soc/sof/intel/hda-dai-ops.c +13 -0
index 9dfcafeab9e4..57db589906db 100644
@@ -144,10 +144,23 @@ static void hda_release_hext_stream(struct snd_sof_dev *sdev, struct snd_soc_dai
 	snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
 }
 
+static void hda_setup_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream,
+				  unsigned int format_val)
+{
+	snd_hdac_ext_stream_setup(hext_stream, format_val);
+}
+
+static void hda_reset_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream)
+{
+	snd_hdac_ext_stream_reset(hext_stream);
+}
+
 static const struct hda_dai_widget_dma_ops hda_dma_ops = {
 	.get_hext_stream = hda_get_hext_stream,
 	.assign_hext_stream = hda_assign_hext_stream,
 	.release_hext_stream = hda_release_hext_stream,
+	.setup_hext_stream = hda_setup_hext_stream,
+	.reset_hext_stream = hda_reset_hext_stream,
 };
 
 #endif
sound/soc/sof/intel/hda-dai.c +4 -2
index 963c40d8a10b..9616cdba79b6 100644
@@ -135,7 +135,8 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	else
 		link_bps = codec_dai->driver->capture.sig_bits;
 
-	snd_hdac_ext_stream_reset(hext_stream);
+	if (ops->reset_hext_stream)
+		ops->reset_hext_stream(sdev, hext_stream);
 
 	format_val = snd_hdac_calc_stream_format(params_rate(params), params_channels(params),
 						 params_format(params), link_bps, 0);
@@ -143,7 +144,8 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
 	dev_dbg(bus->dev, "format_val=%d, rate=%d, ch=%d, format=%d\n",
 		format_val, params_rate(params), params_channels(params), params_format(params));
 
-	snd_hdac_ext_stream_setup(hext_stream, format_val);
+	if (ops->setup_hext_stream)
+		ops->setup_hext_stream(sdev, hext_stream, format_val);
 
 	hext_stream->link_prepared = 1;
 
Signature · 1 line
2.39.2
author maintainer
#10 lore raw

PATCH 10/14 ASoC: SOF: Intel: hda-dai: Use the topology IPC dai_config op

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Use the topology IPC dai_config to update the dai_config for HDA DAI widgets.

---
 sound/soc/sof/intel/hda-dai.c | 86 +++++++++++++++++------------------
 1 file changed, 43 insertions(+), 43 deletions(-)
sound/soc/sof/intel/hda-dai.c +43 -43
index 9616cdba79b6..b726c0225110 100644
@@ -29,6 +29,27 @@ MODULE_PARM_DESC(sof_use_tplg_nhlt, "SOF topology nhlt override");
 
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
 
+static int hda_dai_config(struct snd_soc_dapm_widget *w, unsigned int flags,
+			  struct snd_sof_dai_config_data *data)
+{
+	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);
+	const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
+	int ret;
+
+	if (tplg_ops && tplg_ops->dai_config) {
+		ret = tplg_ops->dai_config(sdev, swidget, flags, data);
+		if (ret < 0) {
+			dev_err(sdev->dev, "DAI config with flags %x failed for widget %s\n",
+				flags, w->name);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static const struct hda_dai_widget_dma_ops *
 hda_dai_get_ops(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
 {
@@ -232,33 +253,16 @@ static int hda_dai_widget_update(struct snd_soc_dapm_widget *w,
 	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
 }
 
-static int hda_dai_hw_params_update(struct snd_pcm_substream *substream,
-				    struct snd_pcm_hw_params *params,
-				    struct snd_soc_dai *dai)
-{
-	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
-	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
-	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(dai->component);
-	struct hdac_ext_stream *hext_stream;
-	int stream_tag;
-
-	hext_stream = ops->get_hext_stream(sdev, dai, substream);
-	if (!hext_stream)
-		return -EINVAL;
-
-	stream_tag = hdac_stream(hext_stream)->stream_tag;
-
-	/* set up the DAI widget and send the DAI_CONFIG with the new tag */
-	return hda_dai_widget_update(w, stream_tag - 1, true);
-}
-
 static int hda_dai_hw_params(struct snd_pcm_substream *substream,
 			     struct snd_pcm_hw_params *params,
 			     struct snd_soc_dai *dai)
 {
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(dai->component);
 	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
 	struct hdac_ext_stream *hext_stream;
+	struct snd_sof_dai_config_data data = { 0 };
+	unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS;
 	int ret;
 
 	if (!ops) {
@@ -274,35 +278,22 @@ static int hda_dai_hw_params(struct snd_pcm_substream *substream,
 	if (ret < 0)
 		return ret;
 
-	return hda_dai_hw_params_update(substream, params, dai);
-}
-
-
-static int hda_dai_config_pause_push_ipc(struct snd_soc_dapm_widget *w)
-{
-	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);
-	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
-	int ret = 0;
+	hext_stream = ops->get_hext_stream(sdev, dai, substream);
 
-	if (tplg_ops->dai_config) {
-		ret = tplg_ops->dai_config(sdev, swidget, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
-		if (ret < 0)
-			dev_err(sdev->dev, "%s: DAI config failed for widget %s\n", __func__,
-				w->name);
-	}
+	flags |= SOF_DAI_CONFIG_FLAGS_2_STEP_STOP << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
+	data.dai_data = hdac_stream(hext_stream)->stream_tag - 1;
 
-	return ret;
+	return hda_dai_config(w, flags, &data);
 }
 
 static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
 {
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(dai->component);
 	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
-	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
 	struct hdac_ext_stream *hext_stream;
-	int stream = substream->stream;
+	struct snd_sof_dai_config_data data = { 0 };
+	unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS;
 	int ret;
 
 	hext_stream = ops->get_hext_stream(sdev, dai, substream);
@@ -315,7 +306,12 @@ static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_d
 	if (ret < 0)
 		return ret;
 
-	return hda_dai_hw_params_update(substream, &rtd->dpcm[stream].hw_params, dai);
+	hext_stream = ops->get_hext_stream(sdev, dai, substream);
+
+	flags |= SOF_DAI_CONFIG_FLAGS_2_STEP_STOP << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
+	data.dai_data = hdac_stream(hext_stream)->stream_tag - 1;
+
+	return hda_dai_config(w, flags, &data);
 }
 
 static int hda_dai_hw_free_ipc(int stream, /* direction */
@@ -356,7 +352,7 @@ static int ipc3_hda_dai_trigger(struct snd_pcm_substream *substream,
 
 		break;
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		ret = hda_dai_config_pause_push_ipc(w);
+		ret = hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
 		if (ret < 0)
 			return ret;
 		break;
@@ -462,13 +458,17 @@ static int ipc4_hda_dai_trigger(struct snd_pcm_substream *substream,
 static int hda_dai_hw_free(struct snd_pcm_substream *substream,
 			   struct snd_soc_dai *dai)
 {
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
+	struct snd_sof_dai_config_data data = { 0 };
 	int ret;
 
 	ret = hda_link_dma_hw_free(substream, dai);
 	if (ret < 0)
 		return ret;
 
-	return hda_dai_hw_free_ipc(substream->stream, dai);
+	data.dai_data = DMA_CHAN_INVALID;
+
+	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
 }
 
 static const struct snd_soc_dai_ops ipc3_hda_dai_ops = {
Signature · 1 line
2.39.2
author maintainer
#11 lore raw

PATCH 11/14 ASoC: SOF: Intel: hda-dai: Define DAI widget DMA trigger ops for IPC4

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Define and use the SOF widget's DMA pre_trigger/trigger/post_trigger ops in ipc4_hda_dai_trigger().

---
 sound/soc/sof/intel/hda-dai-ops.c | 128 +++++++++++++++++++++++++++++-
 sound/soc/sof/intel/hda-dai.c     |  62 ++++-----------
 2 files changed, 139 insertions(+), 51 deletions(-)
sound/soc/sof/intel/hda-dai-ops.c +125 -3
index 57db589906db..992c31772593 100644
@@ -155,7 +155,129 @@ static void hda_reset_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stre
 	snd_hdac_ext_stream_reset(hext_stream);
 }
 
-static const struct hda_dai_widget_dma_ops hda_dma_ops = {
+static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+				struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_sof_widget *pipe_widget;
+	struct sof_ipc4_pipeline *pipeline;
+	struct snd_sof_widget *swidget;
+	struct snd_soc_dapm_widget *w;
+	int ret;
+
+	w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
+	swidget = w->dobj.private;
+	pipe_widget = swidget->spipe->pipe_widget;
+	pipeline = pipe_widget->private;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		break;
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_STOP:
+		ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
+						  SOF_IPC4_PIPE_PAUSED);
+		if (ret < 0)
+			return ret;
+
+		pipeline->state = SOF_IPC4_PIPE_PAUSED;
+		break;
+	default:
+		dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int hda_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+		       struct snd_pcm_substream *substream, int cmd)
+{
+	struct hdac_ext_stream *hext_stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		snd_hdac_ext_stream_start(hext_stream);
+		break;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		snd_hdac_ext_stream_clear(hext_stream);
+		break;
+	default:
+		dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+				 struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_sof_widget *pipe_widget;
+	struct sof_ipc4_pipeline *pipeline;
+	struct snd_sof_widget *swidget;
+	struct snd_soc_dapm_widget *w;
+	int ret;
+
+	w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
+	swidget = w->dobj.private;
+	pipe_widget = swidget->spipe->pipe_widget;
+	pipeline = pipe_widget->private;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		if (pipeline->state != SOF_IPC4_PIPE_PAUSED) {
+			ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
+							  SOF_IPC4_PIPE_PAUSED);
+			if (ret < 0)
+				return ret;
+			pipeline->state = SOF_IPC4_PIPE_PAUSED;
+		}
+
+		ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
+						  SOF_IPC4_PIPE_RUNNING);
+		if (ret < 0)
+			return ret;
+		pipeline->state = SOF_IPC4_PIPE_RUNNING;
+		break;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_STOP:
+	{
+		ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
+						  SOF_IPC4_PIPE_RESET);
+		if (ret < 0)
+			return ret;
+
+		pipeline->state = SOF_IPC4_PIPE_RESET;
+		break;
+	}
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		break;
+	default:
+		dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct hda_dai_widget_dma_ops hda_ipc4_dma_ops = {
+	.get_hext_stream = hda_get_hext_stream,
+	.assign_hext_stream = hda_assign_hext_stream,
+	.release_hext_stream = hda_release_hext_stream,
+	.setup_hext_stream = hda_setup_hext_stream,
+	.reset_hext_stream = hda_reset_hext_stream,
+	.pre_trigger = hda_ipc4_pre_trigger,
+	.trigger = hda_trigger,
+	.post_trigger = hda_ipc4_post_trigger
+};
+
+static const struct hda_dai_widget_dma_ops hda_ipc3_dma_ops = {
 	.get_hext_stream = hda_get_hext_stream,
 	.assign_hext_stream = hda_assign_hext_stream,
 	.release_hext_stream = hda_release_hext_stream,
@@ -177,7 +299,7 @@ hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidg
 		struct sof_dai_private_data *private = sdai->private;
 
 		if (private->dai_config->type == SOF_DAI_INTEL_HDA)
-			return &hda_dma_ops;
+			return &hda_ipc3_dma_ops;
 		break;
 	}
 	case SOF_INTEL_IPC4:
@@ -185,7 +307,7 @@ hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidg
 		struct sof_ipc4_copier *ipc4_copier = sdai->private;
 
 		if (ipc4_copier->dai_type == SOF_DAI_INTEL_HDA)
-			return &hda_dma_ops;
+			return &hda_ipc4_dma_ops;
 		break;
 	}
 	default:
sound/soc/sof/intel/hda-dai.c +14 -48

92 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#12 lore raw

PATCH 12/14 ASoC: SOF: Intel: hda: Unify DAI drv ops for IPC3 and IPC4

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Define the post_trigger DMA op for IPC3 and unify the DAI driver ops for IPC3 and IPC4 for HDA DAI's.

Also, use the post_trigger op to stop the paused streams properly in the hda_dai_suspend() function. This fixes the suspend while paused case for IPC4 because previously we weren't resetting the pipeline when suspending the system with some paused streams.

---
 sound/soc/sof/intel/hda-dai-ops.c |  25 ++++
 sound/soc/sof/intel/hda-dai.c     | 183 ++++++------------------------
 sound/soc/sof/intel/hda.h         |   2 +
 3 files changed, 62 insertions(+), 148 deletions(-)
sound/soc/sof/intel/hda-dai-ops.c +25 -0
index 992c31772593..be109f33715f 100644
@@ -277,12 +277,37 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_dma_ops = {
 	.post_trigger = hda_ipc4_post_trigger
 };
 
+static int hda_ipc3_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
+				 struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_STOP:
+	{
+		struct snd_sof_dai_config_data data = { 0 };
+
+		data.dai_data = DMA_CHAN_INVALID;
+		return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
+	}
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 static const struct hda_dai_widget_dma_ops hda_ipc3_dma_ops = {
 	.get_hext_stream = hda_get_hext_stream,
 	.assign_hext_stream = hda_assign_hext_stream,
 	.release_hext_stream = hda_release_hext_stream,
 	.setup_hext_stream = hda_setup_hext_stream,
 	.reset_hext_stream = hda_reset_hext_stream,
+	.trigger = hda_trigger,
+	.post_trigger = hda_ipc3_post_trigger,
 };
 
 #endif
sound/soc/sof/intel/hda-dai.c +35 -148

258 lines not on this page · raw message

sound/soc/sof/intel/hda.h +2 -0
index e0469f86fa63..815f73d3acd2 100644
@@ -962,5 +962,7 @@ struct hda_dai_widget_dma_ops {
 
 const struct hda_dai_widget_dma_ops *
 hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
+int hda_dai_config(struct snd_soc_dapm_widget *w, unsigned int flags,
+		   struct snd_sof_dai_config_data *data);
 
 #endif
Signature · 1 line
2.39.2
author maintainer
#13 lore raw

PATCH 13/14 ASoC: SOF: Intel: hda: Remove hda_ctrl_dai_widget_setup/free()

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

Remove these functions and reuse hda_dai_config().

---
 sound/soc/sof/intel/hda.c | 78 +++------------------------------------
 sound/soc/sof/intel/hda.h |  4 --
 2 files changed, 6 insertions(+), 76 deletions(-)
sound/soc/sof/intel/hda.c +6 -72
index 81c697e20108..890993b2f14b 100644
@@ -44,70 +44,6 @@
 #define EXCEPT_MAX_HDR_SIZE	0x400
 #define HDA_EXT_ROM_STATUS_SIZE 8
 
-int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
-			      struct snd_sof_dai_config_data *data)
-{
-	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);
-	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
-	struct snd_sof_dai *sof_dai = swidget->private;
-	int ret;
-
-	if (!sof_dai) {
-		dev_err(sdev->dev, "%s: No DAI for DAI widget %s\n", __func__, w->name);
-		return -EINVAL;
-	}
-
-	if (tplg_ops->dai_config) {
-		unsigned int flags;
-
-		/* set HW_PARAMS flag along with quirks */
-		flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS |
-			quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
-
-		ret = tplg_ops->dai_config(sdev, swidget, flags, data);
-		if (ret < 0) {
-			dev_err(sdev->dev, "%s: DAI config failed for widget %s\n", __func__,
-				w->name);
-			return ret;
-		}
-	}
-
-	return 0;
-}
-
-int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
-			     struct snd_sof_dai_config_data *data)
-{
-	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);
-	const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
-	struct snd_sof_dai *sof_dai = swidget->private;
-
-	if (!sof_dai) {
-		dev_err(sdev->dev, "%s: No DAI for BE DAI widget %s\n", __func__, w->name);
-		return -EINVAL;
-	}
-
-	if (tplg_ops->dai_config) {
-		unsigned int flags;
-		int ret;
-
-		/* set HW_FREE flag along with any quirks */
-		flags = SOF_DAI_CONFIG_FLAGS_HW_FREE |
-			quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
-
-		ret = tplg_ops->dai_config(sdev, swidget, flags, data);
-		if (ret < 0)
-			dev_err(sdev->dev, "%s: DAI config failed for widget '%s'\n", __func__,
-				w->name);
-	}
-
-	return 0;
-}
-
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
 
 /*
@@ -124,30 +60,28 @@ static int sdw_params_stream(struct device *dev,
 			     struct sdw_intel_stream_params_data *params_data)
 {
 	struct snd_soc_dai *d = params_data->dai;
-	struct snd_sof_dai_config_data data;
-	struct snd_soc_dapm_widget *w;
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, params_data->stream);
+	struct snd_sof_dai_config_data data = { 0 };
 
-	w = snd_soc_dai_get_widget(d, params_data->stream);
 	data.dai_index = (params_data->link_id << 8) | d->id;
 	data.dai_data = params_data->alh_stream_id;
 
-	return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
+	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_PARAMS, &data);
 }
 
 static int sdw_free_stream(struct device *dev,
 			   struct sdw_intel_stream_free_data *free_data)
 {
 	struct snd_soc_dai *d = free_data->dai;
-	struct snd_sof_dai_config_data data;
-	struct snd_soc_dapm_widget *w;
+	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, free_data->stream);
+	struct snd_sof_dai_config_data data = { 0 };
 
-	w = snd_soc_dai_get_widget(d, free_data->stream);
 	data.dai_index = (free_data->link_id << 8) | d->id;
 
 	/* send invalid stream_id */
 	data.dai_data = 0xFFFF;
 
-	return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
+	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
 }
 
 struct sdw_intel_ops sdw_callback = {
sound/soc/sof/intel/hda.h +0 -4
index 815f73d3acd2..2a43bfc14583 100644
@@ -896,10 +896,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_soc_dapm_widget *w, unsigned int quirk_flags,
-			      struct snd_sof_dai_config_data *data);
-int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
-			     struct snd_sof_dai_config_data *data);
 
 #define SOF_HDA_POSITION_QUIRK_USE_SKYLAKE_LEGACY	(0) /* previous implementation */
 #define SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS	(1) /* recommended if VC0 only */
Signature · 1 line
2.39.2
author maintainer
#14 lore raw

PATCH 14/14 ASoC: SOF: Intel: hda: remove redundant DAI config during hw_free

In reply to Peter Ujfalusi

From: Ranjani Sridharan <[email protected]>

The DAI widget is freed during FE DAI hw_free and therefore the DAI config during BE DAI hw_free is redundant.

---
 sound/soc/sof/intel/hda-dai.c | 18 +-----------------
 sound/soc/sof/intel/hda.c     | 16 ----------------
 2 files changed, 1 insertion(+), 33 deletions(-)
sound/soc/sof/intel/hda-dai.c +1 -17
index 4ac6148940ae..9637f0f44b01 100644
@@ -181,7 +181,7 @@ static int hda_link_dma_prepare(struct snd_pcm_substream *substream, struct snd_
 	return hda_link_dma_hw_params(substream, &rtd->dpcm[stream].hw_params, cpu_dai);
 }
 
-static int hda_link_dma_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
+static int hda_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
 {
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(cpu_dai->component);
 	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
@@ -319,22 +319,6 @@ static int hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct
 	return 0;
 }
 
-static int hda_dai_hw_free(struct snd_pcm_substream *substream,
-			   struct snd_soc_dai *dai)
-{
-	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
-	struct snd_sof_dai_config_data data = { 0 };
-	int ret;
-
-	ret = hda_link_dma_hw_free(substream, dai);
-	if (ret < 0)
-		return ret;
-
-	data.dai_data = DMA_CHAN_INVALID;
-
-	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
-}
-
 static const struct snd_soc_dai_ops hda_dai_ops = {
 	.hw_params = hda_dai_hw_params,
 	.hw_free = hda_dai_hw_free,
sound/soc/sof/intel/hda.c +0 -16
index 890993b2f14b..65389c7278e2 100644
@@ -69,24 +69,8 @@ static int sdw_params_stream(struct device *dev,
 	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_PARAMS, &data);
 }
 
-static int sdw_free_stream(struct device *dev,
-			   struct sdw_intel_stream_free_data *free_data)
-{
-	struct snd_soc_dai *d = free_data->dai;
-	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, free_data->stream);
-	struct snd_sof_dai_config_data data = { 0 };
-
-	data.dai_index = (free_data->link_id << 8) | d->id;
-
-	/* send invalid stream_id */
-	data.dai_data = 0xFFFF;
-
-	return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
-}
-
 struct sdw_intel_ops sdw_callback = {
 	.params_stream = sdw_params_stream,
-	.free_stream = sdw_free_stream,
 };
 
 void hda_common_enable_sdw_irq(struct snd_sof_dev *sdev, bool enable)
Signature · 1 line
2.39.2
maintainer
#15 lore raw
In reply to Peter Ujfalusi
Quoted 10 lines · Peter Ujfalusi

This series introduces an abstraction of the HDA DAI handling.

The motivation is to simplify and make the code more flexible regarding to IPC versions, new features (ChainDMA (IPC4) and DSPless mode) and to pave the way for new platforms.

For the first look the series might feels a bit too intrusive but it introduces no functionality change (tested at each commit).

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[01/14] ASoC: SOF: Intel: hda-dai: Remove BE DAI DRV ops for SSP DAI's

        commit: 274f8a3b4eb855bb14e38f6f12421ed32a2e670b
[02/14] ASoC: SOF: Intel: hda-dai: Remove hda_link_dma_params()
        commit: a8310c0093f4ebeb3a317b4b70e864b91739fc50
[03/14] ASoC: SOF: Intel: hda-dai: remove struct hda_pipe_params
        commit: 2a6afac248b08a0bcec72a6a605f11319738f6db
[04/14] ASoC: SOF: Intel: hda-dai: Modify the signature of hda_link_dma_cleanup()
        commit: 2be2caf481c7200b29116cea83cf8dd45c9e097f
[05/14] ASoC: SOF: Intel: hda-dai: Pass the CPU dai pointer
        commit: b436ed8dd071cae10ac3f94c541a783a094971ff
[06/14] ASoC: SOF: Intel: hda-dai: Use the dai argument in ipc4_hda_dai_trigger
        commit: be7f4f8d0bee110505750d85e6e11c59f8ceb65f
[07/14] ASoC: SOF: Intel: hda-dai: Introduce DAI widget ops
        commit: 2ae49c6fe060baf432472aba48743e72b8345c52
[08/14] ASoC: SOF: Intel: hda-dai: Define and set the HDA DAI widget DMA ops
        commit: 80afde34e8f9c2459f7cd37ea2d5f71751fedd69
[09/14] ASoC: SOF: Intel: hda-dai: Add setup_hext_stream/reset_hext_stream DMA ops
        commit: e2d6569aba39f4b98da8e56999a19dc901188e5e
[10/14] ASoC: SOF: Intel: hda-dai: Use the topology IPC dai_config op
        commit: e6ffb0d5eda751371d030bb8ae324493b2d1abc2
[11/14] ASoC: SOF: Intel: hda-dai: Define DAI widget DMA trigger ops for IPC4
        commit: 4b2ee4cd7103607b303a079c0469c06694be87e9
[12/14] ASoC: SOF: Intel: hda: Unify DAI drv ops for IPC3 and IPC4
        commit: 2b009fa0823c1510700fd17a0780ddd06a460fb4
[13/14] ASoC: SOF: Intel: hda: Remove hda_ctrl_dai_widget_setup/free()
        commit: a492da0ce6450d6fdea49ec89006d7692c0c1382
[14/14] ASoC: SOF: Intel: hda: remove redundant DAI config during hw_free
        commit: 8c29e78b8ecbec208bdd6d8b385ada71c1e730cd

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark