Skip to content

Commit 44a47e3

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 thats 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 previoius path 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 shouldnt be set up yet because the echo reference capture PCM hasnt 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 <[email protected]>
1 parent c987e7d commit 44a47e3

File tree

1 file changed

+129
-67
lines changed

1 file changed

+129
-67
lines changed

sound/soc/sof/sof-audio.c

Lines changed: 129 additions & 67 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,10 @@ 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);
300305
static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
301306
struct snd_soc_dapm_widget_list *list, int dir)
302307
{
303-
const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
304308
struct snd_soc_dapm_widget *widget;
305309
struct snd_sof_route *sroute;
306310
struct snd_soc_dapm_path *p;
@@ -315,14 +319,29 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
315319
*/
316320
if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
317321
for_each_dapm_widgets(list, i, widget) {
322+
struct snd_sof_widget *src_widget, *sink_widget;
323+
318324
if (!widget->dobj.private)
319325
continue;
320326

321327
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
322328
if (!widget_in_list(list, p->sink))
323329
continue;
330+
src_widget = widget->dobj.private;
324331

325332
if (p->sink->dobj.private) {
333+
sink_widget = p->sink->dobj.private;
334+
335+
/*
336+
* skip if source and sink are in different directions
337+
* (ex. playback and echo ref) if the direction is set in topology.
338+
* These will be set up later. It is enough to check if the direction_valid
339+
* is set for one of the widgets as all widgets will have the direction set
340+
* in topology if one is set.
341+
*/
342+
if (sink_widget->spipe->direction_valid &&
343+
!sof_widget_in_same_direction(sink_widget, src_widget->spipe->direction))
344+
continue;
326345
ret = sof_route_setup(sdev, widget, p->sink);
327346
if (ret < 0)
328347
return ret;
@@ -331,14 +350,31 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
331350
}
332351
} else {
333352
for_each_dapm_widgets(list, i, widget) {
353+
struct snd_sof_widget *src_widget, *sink_widget;
354+
334355
if (!widget->dobj.private)
335356
continue;
336357

337358
snd_soc_dapm_widget_for_each_source_path(widget, p) {
338359
if (!widget_in_list(list, p->source))
339360
continue;
340361

362+
sink_widget = widget->dobj.private;
363+
341364
if (p->source->dobj.private) {
365+
src_widget = p->source->dobj.private;
366+
367+
/*
368+
* skip if source and sink are in different directions
369+
* (ex. playback and echo ref) if the direction is set in topology.
370+
* These will be set up later. It is enough to check if the direction_valid
371+
* is set for one of the widgets as all widgets will have the direction set
372+
* in topology if one is set.
373+
*/
374+
if (sink_widget->spipe->direction_valid &&
375+
!sof_widget_in_same_direction(sink_widget, src_widget->spipe->direction))
376+
continue;
377+
342378
ret = sof_route_setup(sdev, p->source, widget);
343379
if (ret < 0)
344380
return ret;
@@ -355,7 +391,6 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
355391
*/
356392
list_for_each_entry(sroute, &sdev->route_list, list) {
357393
bool src_widget_in_dapm_list, sink_widget_in_dapm_list;
358-
struct snd_sof_widget *swidget;
359394

360395
if (sroute->setup)
361396
continue;
@@ -364,63 +399,68 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
364399
sink_widget_in_dapm_list = widget_in_list(list, sroute->sink_widget->widget);
365400

366401
/*
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.
402+
* no need to set up the route if both the source and sink widgets are not in the
403+
* DAPM list
370404
*/
371-
if (src_widget_in_dapm_list == sink_widget_in_dapm_list)
405+
if (!src_widget_in_dapm_list && !sink_widget_in_dapm_list)
372406
continue;
373407

374408
/*
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.
409+
* set up the route only if both the source and sink widgets are in the DAPM list
410+
* but are in different directions. The ones in the same direction would already have
411+
* been set up in the previous loop.
379412
*/
380-
if (src_widget_in_dapm_list)
381-
swidget = sroute->sink_widget;
382-
else
383-
swidget = sroute->src_widget;
413+
if (src_widget_in_dapm_list && sink_widget_in_dapm_list) {
414+
struct snd_sof_widget *src_widget, *sink_widget;
384415

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

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-
}
419+
/*
420+
* it is enough to check if the direction_valid is set for one of the widgets
421+
* as all widgets will have the direction set in topology if one is set.
422+
*/
423+
if (src_widget && sink_widget &&
424+
src_widget->spipe->direction_valid &&
425+
sof_widget_in_same_direction(sink_widget, src_widget->spipe->direction))
426+
continue;
399427
}
400428

429+
ret = sof_route_setup(sdev, sroute->src_widget->widget,
430+
sroute->sink_widget->widget);
431+
401432
if (ret < 0)
402433
return ret;
403434
}
404435

405436
return 0;
406437
}
407438

439+
static bool sof_widget_in_same_direction(struct snd_sof_widget *swidget, int dir)
440+
{
441+
if (swidget->spipe->direction == dir)
442+
return true;
443+
444+
return false;
445+
}
446+
408447
static void
409448
sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
410-
struct snd_soc_dapm_widget_list *list)
449+
struct snd_soc_dapm_widget_list *list, int dir)
411450
{
412451
const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
413452
struct snd_sof_widget *swidget = widget->dobj.private;
414453
const struct sof_ipc_tplg_widget_ops *widget_ops;
415454
struct snd_soc_dapm_path *p;
416455

417-
/* skip if the widget is in use or if it is already unprepared */
418-
if (!swidget || !swidget->prepared || swidget->use_count > 0 ||
419-
is_virtual_widget(sdev, widget, __func__))
456+
if (!swidget || is_virtual_widget(sdev, widget, __func__))
420457
goto sink_unprepare;
421458

422-
/* skip aggregated DAIs */
423-
if(is_aggregated_dai(swidget))
459+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
460+
return;
461+
462+
/* skip widgets in use, those already unprepared or aggregated DAIs */
463+
if (!swidget->prepared || swidget->use_count > 0 || is_aggregated_dai(swidget))
424464
goto sink_unprepare;
425465

426466
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
@@ -435,9 +475,10 @@ sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widg
435475
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
436476
if (!widget_in_list(list, p->sink))
437477
continue;
478+
438479
if (!p->walking && p->sink->dobj.private) {
439480
p->walking = true;
440-
sof_unprepare_widgets_in_path(sdev, p->sink, list);
481+
sof_unprepare_widgets_in_path(sdev, p->sink, list, dir);
441482
p->walking = false;
442483
}
443484
}
@@ -456,18 +497,21 @@ sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget
456497
struct snd_soc_dapm_path *p;
457498
int ret;
458499

459-
if (is_virtual_widget(sdev, widget, __func__))
500+
dev_dbg(sdev->dev, "%s: preparing widget %s id %d\n",
501+
__func__, widget->name, widget->id);
502+
503+
if (is_virtual_widget(sdev, widget, __func__) || !swidget)
460504
goto sink_prepare;
461505

462506
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
463507
if (!widget_ops)
464508
return 0;
465509

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

469-
/* skip aggregated DAIs */
470-
if(is_aggregated_dai(swidget))
513+
if (!widget_ops[widget->id].ipc_prepare || swidget->prepared ||
514+
is_aggregated_dai(swidget))
471515
goto sink_prepare;
472516

473517
/* prepare the source widget */
@@ -485,6 +529,7 @@ sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget
485529
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
486530
if (!widget_in_list(list, p->sink))
487531
continue;
532+
488533
if (!p->walking && p->sink->dobj.private) {
489534
p->walking = true;
490535
ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
@@ -514,23 +559,25 @@ static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dap
514559
int dir, struct snd_sof_pcm *spcm)
515560
{
516561
struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
517-
struct snd_sof_widget *swidget;
562+
struct snd_sof_widget *swidget = widget->dobj.private;
518563
struct snd_soc_dapm_path *p;
519564
int err;
520565
int ret = 0;
521566

522-
if (is_virtual_widget(sdev, widget, __func__))
567+
if (is_virtual_widget(sdev, widget, __func__) || !swidget)
523568
goto sink_free;
524569

525-
swidget = widget->dobj.private;
570+
/* skip aggregated DAIs */
571+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
572+
return 0;
526573

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-
}
574+
if(is_aggregated_dai(swidget))
575+
goto sink_free;
533576

577+
err = sof_widget_free(sdev, widget->dobj.private);
578+
if (err < 0)
579+
ret = err;
580+
sink_free:
534581
/* free all widgets in the sink paths even in case of error to keep use counts balanced */
535582
snd_soc_dapm_widget_for_each_sink_path(widget, p) {
536583
if (!p->walking) {
@@ -570,6 +617,10 @@ static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_d
570617
if (swidget) {
571618
int i;
572619

620+
/* skip aggregated DAIs */
621+
if (swidget->spipe->direction_valid && !sof_widget_in_same_direction(swidget, dir))
622+
return 0;
623+
573624
if(is_aggregated_dai(swidget))
574625
goto sink_setup;
575626

@@ -635,15 +686,14 @@ sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
635686
return 0;
636687

637688
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)
689+
/* starting widget for playback is of AIF or snd_soc_dapm_input type */
690+
if (dir == SNDRV_PCM_STREAM_PLAYBACK && (widget->id != snd_soc_dapm_aif_in &&
691+
widget->id != snd_soc_dapm_input))
643692
continue;
644693

645694
/* starting widget for capture is DAI type */
646-
if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
695+
if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out &&
696+
widget->id != snd_soc_dapm_output)
647697
continue;
648698

649699
switch (op) {
@@ -673,7 +723,7 @@ sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
673723
break;
674724
}
675725
case SOF_WIDGET_UNPREPARE:
676-
sof_unprepare_widgets_in_path(sdev, widget, list);
726+
sof_unprepare_widgets_in_path(sdev, widget, list, dir);
677727
break;
678728
default:
679729
dev_err(sdev->dev, "Invalid widget op %d\n", op);
@@ -920,29 +970,41 @@ struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
920970
return NULL;
921971
}
922972

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)
973+
static struct snd_sof_widget *snd_sof_find_swidget_sname_type(struct snd_soc_component *scomp,
974+
const char *sname,
975+
enum snd_soc_dapm_type type)
927976
{
928977
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
929978
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;
936979

937980
list_for_each_entry(swidget, &sdev->widget_list, list) {
938-
if (!strcmp(pcm_name, swidget->widget->sname) &&
939-
swidget->id == type)
981+
if (!strcmp(sname, swidget->widget->sname) && swidget->id == type)
940982
return swidget;
941983
}
942984

943985
return NULL;
944986
}
945987

988+
/* find widget by stream name and direction */
989+
struct snd_sof_widget *
990+
snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
991+
const char *pcm_name, int dir)
992+
{
993+
if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
994+
struct snd_sof_widget *swidget;
995+
996+
/* first look for an aif_in type widget */
997+
swidget = snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_aif_in);
998+
if (swidget)
999+
return swidget;
1000+
1001+
/* if not found, look for an input type widget */
1002+
return snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_input);
1003+
}
1004+
1005+
return snd_sof_find_swidget_sname_type(scomp, pcm_name, snd_soc_dapm_aif_out);
1006+
}
1007+
9461008
struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
9471009
const char *name)
9481010
{

0 commit comments

Comments
 (0)