Skip to content

Commit 779773c

Browse files
committed
ASoC: SOF: sof-audio: Add support for hostless/dailess pipelines
This patch add supports for hostless/dailess pipelines in the SOF topology. An example of hostless pipeline is a pipeline that's completely internal to the DSP with the tone generator as the source. In order to support this with DPCM, we make use of a virtual widget of type snd_soc_dapm_input as the source widget with the pipeline as follows: virtual widget (snd_soc_dapm_input) -> tone generator (effect) -> gain -> DAI As far as the SOF driver is concerned, any widget of type snd_soc_dapm_input is not handled and is treated as a virtual widget but the previous patch allows traversing the list of widgets past this widget to set up the rest of the widgets in the pipeline. This patch also amends the logic for finding the source widget for this pipeline to include the type snd_soc_dapm_input in order to walk from the source to the sink DAI widget when the pipeline is started. An example of a DAI-less pipeline would be the echo reference capture in the speaker playback path. This pipeline is set up as follows: Host(Playback) -> mixin -> mixout -> gain -> module-copier -> DAI | V Host(Capture) <- Process module <- virtual DAI In the above example, the virtual DAI exploits the concept of an aggregated DAI (one with a non-zero DAI ID) in topology to enable this pipeline to work with DPCM. A virtual DAI is a DAI widget with a non-zero DAI ID and hence is skipped when traversing the list of DAPM widgets during widget prepare/set/up/free/unprepare. The process module in the above pipeline generates 0's that are captured by the echo reference PCM. When the playback path is active, the process module acts as a passthrough module to allow the playback samples to be passthrough to the capture host. In order for these pipelines to work properly, the logic for setting/preparing/freeing/unpreparing the widgets needs to be amended to make sure that only the widgets that are in the pipeline in the same direction as the PCM being started are set up. For example, when the playback PCM is started, the capture pipeline widgets also show up in the list of connected DAPM widgets but they shouldn't be set up yet because the echo reference capture PCM hasn't been started yet. Alternatively, when the echo reference capture PCM is started, the playback pipeline widgets should not be setup. Finally, the last step needed to put this all together is the set the routes for widgets connecting the playback and the capture pipelines when both are active. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 31efc9d commit 779773c

File tree

1 file changed

+120
-69
lines changed

1 file changed

+120
-69
lines changed

sound/soc/sof/sof-audio.c

Lines changed: 120 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsourc
269269
is_virtual_widget(sdev, sink_widget->widget, __func__))
270270
return 0;
271271

272+
/* skip route if source/sink widget is not set up */
273+
if (!src_widget->use_count || !sink_widget->use_count)
274+
return 0;
275+
272276
/* find route matching source and sink widgets */
273277
list_for_each_entry(sroute, &sdev->route_list, list)
274278
if (sroute->src_widget == src_widget && sroute->sink_widget == sink_widget) {
@@ -297,10 +301,37 @@ int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsourc
297301
return 0;
298302
}
299303

304+
static bool sof_widget_in_same_direction(struct snd_sof_widget *swidget, int dir)
305+
{
306+
if (swidget->spipe->direction == dir)
307+
return true;
308+
309+
return false;
310+
}
311+
312+
static int sof_set_up_same_dir_widget_routes(struct snd_sof_dev *sdev,
313+
struct snd_soc_dapm_widget *wsource,
314+
struct snd_soc_dapm_widget *wsink)
315+
{
316+
struct snd_sof_widget *src_widget = wsource->dobj.private;
317+
struct snd_sof_widget *sink_widget = wsink->dobj.private;
318+
319+
/*
320+
* skip setting up route if source and sink are in different directions (ex. playback and
321+
* echo ref) if the direction is set in topology. These will be set up later. It is enough
322+
* to check if the direction_valid is set for one of the widgets as all widgets will have
323+
* the direction set in topology if one is set.
324+
*/
325+
if (sink_widget->spipe->direction_valid &&
326+
!sof_widget_in_same_direction(sink_widget, src_widget->spipe->direction))
327+
return 0;
328+
329+
return sof_route_setup(sdev, wsource, wsink);
330+
}
331+
300332
static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
301333
struct snd_soc_dapm_widget_list *list, int dir)
302334
{
303-
const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
304335
struct snd_soc_dapm_widget *widget;
305336
struct snd_sof_route *sroute;
306337
struct snd_soc_dapm_path *p;
@@ -323,7 +354,7 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
323354
continue;
324355

325356
if (p->sink->dobj.private) {
326-
ret = sof_route_setup(sdev, widget, p->sink);
357+
ret = sof_set_up_same_dir_widget_routes(sdev, widget, p->sink);
327358
if (ret < 0)
328359
return ret;
329360
}
@@ -339,7 +370,7 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
339370
continue;
340371

341372
if (p->source->dobj.private) {
342-
ret = sof_route_setup(sdev, p->source, widget);
373+
ret = sof_set_up_same_dir_widget_routes(sdev, p->source, widget);
343374
if (ret < 0)
344375
return ret;
345376
}
@@ -355,7 +386,6 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
355386
*/
356387
list_for_each_entry(sroute, &sdev->route_list, list) {
357388
bool src_widget_in_dapm_list, sink_widget_in_dapm_list;
358-
struct snd_sof_widget *swidget;
359389

360390
if (sroute->setup)
361391
continue;
@@ -364,63 +394,64 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
364394
sink_widget_in_dapm_list = widget_in_list(list, sroute->sink_widget->widget);
365395

366396
/*
367-
* if both source and sink are in the DAPM list, the route must already have been
368-
* set up above. And if neither are in the DAPM list, the route shouldn't be
369-
* handled now.
397+
* no need to set up the route if both the source and sink widgets are not in the
398+
* DAPM list
370399
*/
371-
if (src_widget_in_dapm_list == sink_widget_in_dapm_list)
400+
if (!src_widget_in_dapm_list && !sink_widget_in_dapm_list)
372401
continue;
373402

374403
/*
375-
* At this point either the source widget or the sink widget is in the DAPM list
376-
* with a route that might need to be set up. Check the use_count of the widget
377-
* that is not in the DAPM list to confirm if it is in use currently before setting
378-
* up the route.
404+
* set up the route only if both the source and sink widgets are in the DAPM list
405+
* but are in different directions. The ones in the same direction would already
406+
* have been set up in the previous loop.
379407
*/
380-
if (src_widget_in_dapm_list)
381-
swidget = sroute->sink_widget;
382-
else
383-
swidget = sroute->src_widget;
408+
if (src_widget_in_dapm_list && sink_widget_in_dapm_list) {
409+
struct snd_sof_widget *src_widget, *sink_widget;
384410

385-
scoped_guard(mutex, &swidget->setup_mutex) {
386-
if (!swidget->use_count)
387-
continue;
411+
src_widget = sroute->src_widget->widget->dobj.private;
412+
sink_widget = sroute->sink_widget->widget->dobj.private;
388413

389-
if (tplg_ops && tplg_ops->route_setup) {
390-
/*
391-
* this route will get freed when either the
392-
* source widget or the sink widget is freed
393-
* during hw_free
394-
*/
395-
ret = tplg_ops->route_setup(sdev, sroute);
396-
if (!ret)
397-
sroute->setup = true;
398-
}
414+
/*
415+
* it is enough to check if the direction_valid is set for one of the
416+
* widgets as all widgets will have the direction set in topology if one
417+
* is set.
418+
*/
419+
if (src_widget && sink_widget &&
420+
src_widget->spipe->direction_valid &&
421+
sof_widget_in_same_direction(sink_widget, src_widget->spipe->direction))
422+
continue;
399423
}
400424

425+
ret = sof_route_setup(sdev, sroute->src_widget->widget,
426+
sroute->sink_widget->widget);
427+
401428
if (ret < 0)
402429
return ret;
403430
}
404431

405432
return 0;
406433
}
407434

435+
436+
408437
static void
409438
sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
410-
struct snd_soc_dapm_widget_list *list)
439+
struct snd_soc_dapm_widget_list *list, int dir)
411440
{
412441
const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
413442
struct snd_sof_widget *swidget = widget->dobj.private;
414443
const struct sof_ipc_tplg_widget_ops *widget_ops;
415444
struct snd_soc_dapm_path *p;
416445

417-
/* skip if the widget in use or already unprepared or virtual widgets */
418-
if (!swidget || !swidget->prepared || swidget->use_count > 0 ||
419-
is_virtual_widget(sdev, widget, __func__))
446+
/* skip virtual widgets */
447+
if (!swidget || is_virtual_widget(sdev, widget, __func__))
420448
goto sink_unprepare;
421449

422-
/* skip aggregated DAIs */
423-
if (is_aggregated_dai(swidget))
450+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
451+
return;
452+
453+
/* skip widgets in use, those already unprepared or aggregated DAIs */
454+
if (!swidget->prepared || swidget->use_count > 0 || is_aggregated_dai(swidget))
424455
goto sink_unprepare;
425456

426457
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
@@ -435,9 +466,10 @@ sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widg
435466
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
436467
if (!widget_in_list(list, p->sink))
437468
continue;
469+
438470
if (!p->walking && p->sink->dobj.private) {
439471
p->walking = true;
440-
sof_unprepare_widgets_in_path(sdev, p->sink, list);
472+
sof_unprepare_widgets_in_path(sdev, p->sink, list, dir);
441473
p->walking = false;
442474
}
443475
}
@@ -456,18 +488,19 @@ sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget
456488
struct snd_soc_dapm_path *p;
457489
int ret;
458490

459-
if (is_virtual_widget(sdev, widget, __func__))
491+
if (is_virtual_widget(sdev, widget, __func__) || !swidget)
460492
goto sink_prepare;
461493

462494
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
463495
if (!widget_ops)
464496
return 0;
465497

466-
if (!swidget || !widget_ops[widget->id].ipc_prepare || swidget->prepared)
467-
goto sink_prepare;
498+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
499+
return 0;
468500

469-
/* skip aggregated DAIs */
470-
if (is_aggregated_dai(swidget))
501+
/* skip widgets already prepared or aggregated DAI widgets*/
502+
if (!widget_ops[widget->id].ipc_prepare || swidget->prepared ||
503+
is_aggregated_dai(swidget))
471504
goto sink_prepare;
472505

473506
/* prepare the source widget */
@@ -485,6 +518,7 @@ sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget
485518
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
486519
if (!widget_in_list(list, p->sink))
487520
continue;
521+
488522
if (!p->walking && p->sink->dobj.private) {
489523
p->walking = true;
490524
ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
@@ -514,23 +548,25 @@ static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dap
514548
int dir, struct snd_sof_pcm *spcm)
515549
{
516550
struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
517-
struct snd_sof_widget *swidget;
551+
struct snd_sof_widget *swidget = widget->dobj.private;
518552
struct snd_soc_dapm_path *p;
519553
int err;
520554
int ret = 0;
521555

522-
if (is_virtual_widget(sdev, widget, __func__))
556+
if (is_virtual_widget(sdev, widget, __func__) || !swidget)
523557
goto sink_free;
524558

525-
swidget = widget->dobj.private;
559+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
560+
return 0;
526561

527-
/* no need to free aggregated DAI widgets */
528-
if (swidget && !is_aggregated_dai(swidget)) {
529-
err = sof_widget_free(sdev, swidget);
530-
if (err < 0)
531-
ret = err;
532-
}
562+
/* skip aggregated DAIs */
563+
if (is_aggregated_dai(swidget))
564+
goto sink_free;
533565

566+
err = sof_widget_free(sdev, widget->dobj.private);
567+
if (err < 0)
568+
ret = err;
569+
sink_free:
534570
/* free all widgets in the sink paths even in case of error to keep use counts balanced */
535571
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
536572
if (!p->walking) {
@@ -570,6 +606,10 @@ static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_d
570606
if (swidget) {
571607
int i;
572608

609+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
610+
return 0;
611+
612+
/* skip aggregated DAIs */
573613
if (is_aggregated_dai(swidget))
574614
goto sink_setup;
575615

@@ -635,15 +675,14 @@ sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
635675
return 0;
636676

637677
for_each_dapm_widgets(list, i, widget) {
638-
if (is_virtual_widget(sdev, widget, __func__))
639-
continue;
640-
641-
/* starting widget for playback is AIF type */
642-
if (dir == SNDRV_PCM_STREAM_PLAYBACK && widget->id != snd_soc_dapm_aif_in)
678+
/* starting widget for playback is of AIF or snd_soc_dapm_input type */
679+
if (dir == SNDRV_PCM_STREAM_PLAYBACK && (widget->id != snd_soc_dapm_aif_in &&
680+
widget->id != snd_soc_dapm_input))
643681
continue;
644682

645683
/* starting widget for capture is DAI type */
646-
if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
684+
if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out &&
685+
widget->id != snd_soc_dapm_output)
647686
continue;
648687

649688
switch (op) {
@@ -673,7 +712,7 @@ sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
673712
break;
674713
}
675714
case SOF_WIDGET_UNPREPARE:
676-
sof_unprepare_widgets_in_path(sdev, widget, list);
715+
sof_unprepare_widgets_in_path(sdev, widget, list, dir);
677716
break;
678717
default:
679718
dev_err(sdev->dev, "Invalid widget op %d\n", op);
@@ -920,29 +959,41 @@ struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
920959
return NULL;
921960
}
922961

923-
/* find widget by stream name and direction */
924-
struct snd_sof_widget *
925-
snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
926-
const char *pcm_name, int dir)
962+
static struct snd_sof_widget *snd_sof_find_swidget_sname_type(struct snd_soc_component *scomp,
963+
const char *sname,
964+
enum snd_soc_dapm_type type)
927965
{
928966
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
929967
struct snd_sof_widget *swidget;
930-
enum snd_soc_dapm_type type;
931-
932-
if (dir == SNDRV_PCM_STREAM_PLAYBACK)
933-
type = snd_soc_dapm_aif_in;
934-
else
935-
type = snd_soc_dapm_aif_out;
936968

937969
list_for_each_entry(swidget, &sdev->widget_list, list) {
938-
if (!strcmp(pcm_name, swidget->widget->sname) &&
939-
swidget->id == type)
970+
if (!strcmp(sname, swidget->widget->sname) && swidget->id == type)
940971
return swidget;
941972
}
942973

943974
return NULL;
944975
}
945976

977+
/* find widget by stream name and direction */
978+
struct snd_sof_widget *
979+
snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
980+
const char *pcm_name, int dir)
981+
{
982+
if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
983+
struct snd_sof_widget *swidget;
984+
985+
/* first look for an aif_in type widget */
986+
swidget = snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_aif_in);
987+
if (swidget)
988+
return swidget;
989+
990+
/* if not found, look for an input type widget */
991+
return snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_input);
992+
}
993+
994+
return snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_aif_out);
995+
}
996+
946997
struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
947998
const char *name)
948999
{

0 commit comments

Comments
 (0)