Skip to content

Commit c4628f1

Browse files
committed
ASoC: SOF: Intel: hda-dai: add calc_stream_format 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 stream format setup which is currently completely related to the HDaudio codec setup - not something that will work for other types of DAIs. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent cb87fbe commit c4628f1

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ static void hda_codec_dai_set_stream(struct snd_sof_dev *sdev,
166166
snd_soc_dai_set_stream(codec_dai, hstream, substream->stream);
167167
}
168168

169+
static unsigned int hda_calc_stream_format(struct snd_sof_dev *sdev,
170+
struct snd_pcm_substream *substream,
171+
struct snd_pcm_hw_params *params)
172+
{
173+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
174+
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
175+
unsigned int link_bps;
176+
unsigned int format_val;
177+
178+
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
179+
link_bps = codec_dai->driver->playback.sig_bits;
180+
else
181+
link_bps = codec_dai->driver->capture.sig_bits;
182+
183+
format_val = snd_hdac_calc_stream_format(params_rate(params), params_channels(params),
184+
params_format(params), link_bps, 0);
185+
186+
dev_dbg(sdev->dev, "format_val=%#x, rate=%d, ch=%d, format=%d\n", format_val,
187+
params_rate(params), params_channels(params), params_format(params));
188+
189+
return format_val;
190+
}
191+
169192
static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
170193
struct snd_pcm_substream *substream, int cmd)
171194
{
@@ -287,6 +310,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_dma_ops = {
287310
.trigger = hda_trigger,
288311
.post_trigger = hda_ipc4_post_trigger,
289312
.codec_dai_set_stream = hda_codec_dai_set_stream,
313+
.calc_stream_format = hda_calc_stream_format,
290314
};
291315

292316
static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
@@ -297,6 +321,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
297321
.reset_hext_stream = hda_reset_hext_stream,
298322
.trigger = hda_trigger,
299323
.codec_dai_set_stream = hda_codec_dai_set_stream,
324+
.calc_stream_format = hda_calc_stream_format,
300325
};
301326

302327
static int hda_ipc3_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
@@ -331,6 +356,7 @@ static const struct hda_dai_widget_dma_ops hda_ipc3_dma_ops = {
331356
.trigger = hda_trigger,
332357
.post_trigger = hda_ipc3_post_trigger,
333358
.codec_dai_set_stream = hda_codec_dai_set_stream,
359+
.calc_stream_format = hda_calc_stream_format,
334360
};
335361

336362
static struct hdac_ext_stream *
@@ -358,6 +384,7 @@ static const struct hda_dai_widget_dma_ops hda_dspless_dma_ops = {
358384
.get_hext_stream = hda_dspless_get_hext_stream,
359385
.setup_hext_stream = hda_dspless_setup_hext_stream,
360386
.codec_dai_set_stream = hda_codec_dai_set_stream,
387+
.calc_stream_format = hda_calc_stream_format,
361388
};
362389

363390
#endif

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
154154
struct hdac_ext_link *hlink;
155155
struct snd_sof_dev *sdev;
156156
struct hdac_bus *bus;
157-
unsigned int format_val;
158-
unsigned int link_bps;
159157
int stream_tag;
160158

161159
sdev = dai_to_sdev(substream, cpu_dai);
@@ -185,22 +183,14 @@ static int hda_link_dma_hw_params(struct snd_pcm_substream *substream,
185183
if (ops->codec_dai_set_stream)
186184
ops->codec_dai_set_stream(sdev, substream, hstream);
187185

188-
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
189-
link_bps = codec_dai->driver->playback.sig_bits;
190-
else
191-
link_bps = codec_dai->driver->capture.sig_bits;
192-
193186
if (ops->reset_hext_stream)
194187
ops->reset_hext_stream(sdev, hext_stream);
195188

196-
format_val = snd_hdac_calc_stream_format(params_rate(params), params_channels(params),
197-
params_format(params), link_bps, 0);
198-
199-
dev_dbg(bus->dev, "format_val=%#x, rate=%d, ch=%d, format=%d\n", format_val,
200-
params_rate(params), params_channels(params), params_format(params));
189+
if (ops->calc_stream_format && ops->setup_hext_stream) {
190+
unsigned int format_val = ops->calc_stream_format(sdev, substream, params);
201191

202-
if (ops->setup_hext_stream)
203192
ops->setup_hext_stream(sdev, hext_stream, format_val);
193+
}
204194

205195
hext_stream->link_prepared = 1;
206196

sound/soc/sof/intel/hda.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,8 @@ int hda_dsp_ipc4_load_library(struct snd_sof_dev *sdev,
916916
* @trigger: Function pointer for DAI DMA trigger actions
917917
* @post_trigger: Function pointer for DAI DMA post-trigger actions
918918
* @codec_dai_set_stream: Function pointer to set codec-side stream information
919+
* @calc_stream_format: Function pointer to determine stream format from hw_params and
920+
* for HDaudio codec DAI from the .sig bits
919921
*/
920922
struct hda_dai_widget_dma_ops {
921923
struct hdac_ext_stream *(*get_hext_stream)(struct snd_sof_dev *sdev,
@@ -938,6 +940,9 @@ struct hda_dai_widget_dma_ops {
938940
void (*codec_dai_set_stream)(struct snd_sof_dev *sdev,
939941
struct snd_pcm_substream *substream,
940942
struct hdac_stream *hstream);
943+
unsigned int (*calc_stream_format)(struct snd_sof_dev *sdev,
944+
struct snd_pcm_substream *substream,
945+
struct snd_pcm_hw_params *params);
941946
};
942947

943948
const struct hda_dai_widget_dma_ops *

0 commit comments

Comments
 (0)