Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: SOF: sof-audio: add support for setting up loopback routes

During route setup, playback stream routes are setup by going through
sink path, capture stream routes are set up by going through source path.
This is not sufficient to handle loopback cases between pipelines
configured with different directions, e.g. a sidetone or an amplifier
feedback connected to a speaker protection module. So, add the logic to
handle such routes between widgets that aren't in the list of DAPM widgets
associated with the same PCM.

Link: https://github.com/thesofproject/linux/issues/4042

Suggested-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20230313101302.20950-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Chao Song and committed by
Mark Brown
8cd3cb17 4727d4d7

+60 -1
+60 -1
sound/soc/sof/sof-audio.c
··· 280 280 static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev, 281 281 struct snd_soc_dapm_widget_list *list, int dir) 282 282 { 283 + const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg); 283 284 struct snd_soc_dapm_widget *widget; 285 + struct snd_sof_route *sroute; 284 286 struct snd_soc_dapm_path *p; 285 - int ret; 287 + int ret = 0; 286 288 int i; 287 289 288 290 /* ··· 325 323 } 326 324 } 327 325 } 326 + } 327 + 328 + /* 329 + * The above loop handles connections between widgets that belong to the DAPM widget list. 330 + * This is not sufficient to handle loopback cases between pipelines configured with 331 + * different directions, e.g. a sidetone or an amplifier feedback connected to a speaker 332 + * protection module. 333 + */ 334 + list_for_each_entry(sroute, &sdev->route_list, list) { 335 + bool src_widget_in_dapm_list, sink_widget_in_dapm_list; 336 + struct snd_sof_widget *swidget; 337 + 338 + if (sroute->setup) 339 + continue; 340 + 341 + src_widget_in_dapm_list = widget_in_list(list, sroute->src_widget->widget); 342 + sink_widget_in_dapm_list = widget_in_list(list, sroute->sink_widget->widget); 343 + 344 + /* 345 + * if both source and sink are in the DAPM list, the route must already have been 346 + * set up above. And if neither are in the DAPM list, the route shouldn't be 347 + * handled now. 348 + */ 349 + if (src_widget_in_dapm_list == sink_widget_in_dapm_list) 350 + continue; 351 + 352 + /* 353 + * At this point either the source widget or the sink widget is in the DAPM list 354 + * with a route that might need to be set up. Check the use_count of the widget 355 + * that is not in the DAPM list to confirm if it is in use currently before setting 356 + * up the route. 357 + */ 358 + if (src_widget_in_dapm_list) 359 + swidget = sroute->sink_widget; 360 + else 361 + swidget = sroute->src_widget; 362 + 363 + mutex_lock(&swidget->setup_mutex); 364 + if (!swidget->use_count) { 365 + mutex_unlock(&swidget->setup_mutex); 366 + continue; 367 + } 368 + 369 + if (tplg_ops && tplg_ops->route_setup) { 370 + /* 371 + * this route will get freed when either the source widget or the sink 372 + * widget is freed during hw_free 373 + */ 374 + ret = tplg_ops->route_setup(sdev, sroute); 375 + if (!ret) 376 + sroute->setup = true; 377 + } 378 + 379 + mutex_unlock(&swidget->setup_mutex); 380 + 381 + if (ret < 0) 382 + return ret; 328 383 } 329 384 330 385 return 0;