Skip to content

Commit f02bb90

Browse files
committed
ASoC: SOF: Intel: hda-dai: add get_hlink callback
The existing code for HDAudio DAIs cannot be extended to other types of DAIs, specific programming sequences need to be abstracted away. This patch hides the mechanism to determine the multi-link structure related to the DAI and program the LOSIDV register. An added benefit is that we can remove all references to the codec DAI from what should be a CPU dai configuration only. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent c4628f1 commit f02bb90

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

sound/soc/sof/intel/hda-dai-ops.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ static unsigned int hda_calc_stream_format(struct snd_sof_dev *sdev,
189189
return format_val;
190190
}
191191

192+
static struct hdac_ext_link *hda_get_hlink(struct snd_sof_dev *sdev,
193+
struct snd_pcm_substream *substream)
194+
{
195+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
196+
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
197+
struct hdac_bus *bus = sof_to_bus(sdev);
198+
199+
return snd_hdac_ext_bus_get_hlink_by_name(bus, codec_dai->component->name);
200+
}
201+
192202
static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
193203
struct snd_pcm_substream *substream, int cmd)
194204
{
@@ -311,6 +321,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_dma_ops = {
311321
.post_trigger = hda_ipc4_post_trigger,
312322
.codec_dai_set_stream = hda_codec_dai_set_stream,
313323
.calc_stream_format = hda_calc_stream_format,
324+
.get_hlink = hda_get_hlink,
314325
};
315326

316327
static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
@@ -322,6 +333,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
322333
.trigger = hda_trigger,
323334
.codec_dai_set_stream = hda_codec_dai_set_stream,
324335
.calc_stream_format = hda_calc_stream_format,
336+
.get_hlink = hda_get_hlink,
325337
};
326338

327339
static int hda_ipc3_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
@@ -357,6 +369,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc3_dma_ops = {
357369
.post_trigger = hda_ipc3_post_trigger,
358370
.codec_dai_set_stream = hda_codec_dai_set_stream,
359371
.calc_stream_format = hda_calc_stream_format,
372+
.get_hlink = hda_get_hlink,
360373
};
361374

362375
static struct hdac_ext_stream *
@@ -385,6 +398,7 @@ static const struct hda_dai_widget_dma_ops hda_dspless_dma_ops = {
385398
.setup_hext_stream = hda_dspless_setup_hext_stream,
386399
.codec_dai_set_stream = hda_codec_dai_set_stream,
387400
.calc_stream_format = hda_calc_stream_format,
401+
.get_hlink = hda_get_hlink,
388402
};
389403

390404
#endif

sound/soc/sof/intel/hda-dai.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,17 @@ hda_dai_get_ops(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai
109109

110110
static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
111111
struct hdac_ext_stream *hext_stream,
112-
struct snd_soc_dai *cpu_dai,
113-
struct snd_soc_dai *codec_dai)
112+
struct snd_soc_dai *cpu_dai)
114113
{
115114
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
116-
struct hdac_stream *hstream = &hext_stream->hstream;
117-
struct hdac_bus *bus = hstream->bus;
118115
struct sof_intel_hda_stream *hda_stream;
119116
struct hdac_ext_link *hlink;
120117
struct snd_sof_dev *sdev;
121118
int stream_tag;
122119

123120
sdev = dai_to_sdev(substream, cpu_dai);
124121

125-
hlink = snd_hdac_ext_bus_get_hlink_by_name(bus, codec_dai->component->name);
122+
hlink = ops->get_hlink(sdev, substream);
126123
if (!hlink)
127124
return -EINVAL;
128125

@@ -147,19 +144,15 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
147144
struct snd_pcm_hw_params *params, struct snd_soc_dai *cpu_dai)
148145
{
149146
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
150-
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
151-
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
152147
struct hdac_ext_stream *hext_stream;
153148
struct hdac_stream *hstream;
154149
struct hdac_ext_link *hlink;
155150
struct snd_sof_dev *sdev;
156-
struct hdac_bus *bus;
157151
int stream_tag;
158152

159153
sdev = dai_to_sdev(substream, cpu_dai);
160-
bus = sof_to_bus(sdev);
161154

162-
hlink = snd_hdac_ext_bus_get_hlink_by_name(bus, codec_dai->component->name);
155+
hlink = ops->get_hlink(sdev, substream);
163156
if (!hlink)
164157
return -EINVAL;
165158

@@ -200,8 +193,6 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
200193
static int hda_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
201194
{
202195
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
203-
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
204-
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
205196
struct hdac_ext_stream *hext_stream;
206197
struct snd_sof_dev *sdev = dai_to_sdev(substream, cpu_dai);
207198

@@ -214,7 +205,7 @@ static int hda_dai_hw_free(struct snd_pcm_substream *substream, struct snd_soc_d
214205
if (!hext_stream)
215206
return 0;
216207

217-
return hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
208+
return hda_link_dma_cleanup(substream, hext_stream, cpu_dai);
218209
}
219210

220211
static int hda_dai_hw_params(struct snd_pcm_substream *substream,
@@ -266,8 +257,6 @@ static int hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct
266257
{
267258
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
268259
struct hdac_ext_stream *hext_stream;
269-
struct snd_soc_pcm_runtime *rtd;
270-
struct snd_soc_dai *codec_dai;
271260
struct snd_sof_dev *sdev;
272261
int ret;
273262

@@ -280,9 +269,6 @@ static int hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct
280269
if (!hext_stream)
281270
return -EINVAL;
282271

283-
rtd = asoc_substream_to_rtd(substream);
284-
codec_dai = asoc_rtd_to_codec(rtd, 0);
285-
286272
if (ops->pre_trigger) {
287273
ret = ops->pre_trigger(sdev, dai, substream, cmd);
288274
if (ret < 0)
@@ -304,7 +290,7 @@ static int hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct
304290
switch (cmd) {
305291
case SNDRV_PCM_TRIGGER_SUSPEND:
306292
case SNDRV_PCM_TRIGGER_STOP:
307-
ret = hda_link_dma_cleanup(substream, hext_stream, dai, codec_dai);
293+
ret = hda_link_dma_cleanup(substream, hext_stream, dai);
308294
if (ret < 0) {
309295
dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__);
310296
return ret;
@@ -346,14 +332,12 @@ static int hda_dai_suspend(struct hdac_bus *bus)
346332
const struct hda_dai_widget_dma_ops *ops;
347333
struct snd_sof_widget *swidget;
348334
struct snd_soc_dapm_widget *w;
349-
struct snd_soc_dai *codec_dai;
350335
struct snd_soc_dai *cpu_dai;
351336
struct snd_sof_dev *sdev;
352337
struct snd_sof_dai *sdai;
353338

354339
rtd = asoc_substream_to_rtd(hext_stream->link_substream);
355340
cpu_dai = asoc_rtd_to_cpu(rtd, 0);
356-
codec_dai = asoc_rtd_to_codec(rtd, 0);
357341
w = snd_soc_dai_get_widget(cpu_dai, hdac_stream(hext_stream)->direction);
358342
swidget = w->dobj.private;
359343
sdev = widget_to_sdev(w);
@@ -362,7 +346,7 @@ static int hda_dai_suspend(struct hdac_bus *bus)
362346

363347
ret = hda_link_dma_cleanup(hext_stream->link_substream,
364348
hext_stream,
365-
cpu_dai, codec_dai);
349+
cpu_dai);
366350
if (ret < 0)
367351
return ret;
368352

sound/soc/sof/intel/hda.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ int hda_dsp_ipc4_load_library(struct snd_sof_dev *sdev,
918918
* @codec_dai_set_stream: Function pointer to set codec-side stream information
919919
* @calc_stream_format: Function pointer to determine stream format from hw_params and
920920
* for HDaudio codec DAI from the .sig bits
921+
* @get_hlink: Mandatory function pointer to retrieve hlink, mainly to program LOSIDV
922+
* for legacy HDaudio links or program HDaudio Extended Link registers.
921923
*/
922924
struct hda_dai_widget_dma_ops {
923925
struct hdac_ext_stream *(*get_hext_stream)(struct snd_sof_dev *sdev,
@@ -943,6 +945,8 @@ struct hda_dai_widget_dma_ops {
943945
unsigned int (*calc_stream_format)(struct snd_sof_dev *sdev,
944946
struct snd_pcm_substream *substream,
945947
struct snd_pcm_hw_params *params);
948+
struct hdac_ext_link * (*get_hlink)(struct snd_sof_dev *sdev,
949+
struct snd_pcm_substream *substream);
946950
};
947951

948952
const struct hda_dai_widget_dma_ops *

0 commit comments

Comments
 (0)