Lines Matching refs:fe

61 static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
64 struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
71 "[%s - %s]\n", fe->dai_link->name,
75 dpcm_state_string(fe->dpcm[stream].state));
77 if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
78 (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
89 if (list_empty(&fe->dpcm[stream].be_clients)) {
95 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
96 for_each_dpcm_be(fe, stream, dpcm) {
116 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
124 struct snd_soc_pcm_runtime *fe = file->private_data;
129 if (fe->num_cpus > 1) {
130 dev_err(fe->dev,
140 if (snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream))
141 offset += dpcm_show_state(fe, stream,
183 name, dpcm->fe->debugfs_dpcm_root);
280 int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
285 for_each_dpcm_be(fe, dir, dpcm) {
299 snd_soc_dapm_stream_event(fe, dir, event);
1111 static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
1118 for_each_dpcm_be(fe, stream, dpcm) {
1119 if (dpcm->be == be && dpcm->fe == fe)
1128 dpcm->fe = fe;
1129 be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
1131 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1132 list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
1134 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1136 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
1137 stream ? "capture" : "playback", fe->dai_link->name,
1146 static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
1161 if (dpcm->fe == fe)
1164 dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
1166 dpcm->fe->dai_link->name,
1169 fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, stream);
1176 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
1181 for_each_dpcm_be_safe(fe, stream, dpcm, d) {
1182 dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
1189 dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
1190 stream ? "capture" : "playback", fe->dai_link->name,
1194 dpcm_be_reparent(fe, dpcm->be, stream);
1198 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1201 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1270 int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
1273 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
1276 if (fe->num_cpus > 1) {
1277 dev_err(fe->dev,
1286 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
1319 static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
1326 for_each_dpcm_be(fe, stream, dpcm) {
1330 dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
1332 dpcm->be->dai_link->name, fe->dai_link->name);
1338 dev_dbg(fe->dev, "ASoC: found %d old BE paths for pruning\n", prune);
1342 static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1345 struct snd_soc_card *card = fe->card;
1370 dev_err(fe->dev, "ASoC: no BE found for %s\n",
1376 if (!fe->dpcm[stream].runtime && !fe->fe_compr)
1380 err = dpcm_be_connect(fe, be, stream);
1382 dev_err(fe->dev, "ASoC: can't connect %s\n",
1393 dev_dbg(fe->dev, "ASoC: found %d new BE paths\n", new);
1401 int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
1405 return dpcm_add_paths(fe, stream, list);
1407 return dpcm_prune_paths(fe, stream, list);
1410 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
1415 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
1416 for_each_dpcm_be(fe, stream, dpcm)
1419 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
1422 static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
1428 for_each_dpcm_be(fe, stream, dpcm) {
1451 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
1457 for_each_dpcm_be(fe, stream, dpcm) {
1470 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1511 for_each_dpcm_be_rollback(fe, stream, dpcm) {
1516 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1555 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1560 if (!fe->dai_link->dpcm_merged_format)
1568 for_each_dpcm_be(fe, stream, dpcm) {
1592 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1596 if (!fe->dai_link->dpcm_merged_chan)
1604 for_each_dpcm_be(fe, stream, dpcm) {
1647 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1651 if (!fe->dai_link->dpcm_merged_rate)
1659 for_each_dpcm_be(fe, stream, dpcm) {
1716 static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1720 snd_soc_dpcm_get_substream(fe, stream);
1723 if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1725 fe->dpcm[stream].trigger_pending - 1);
1726 fe->dpcm[stream].trigger_pending = 0;
1728 fe->dpcm[stream].runtime_update = state;
1736 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1745 for_each_rtd_cpu_dais (fe, i, fe_cpu_dai) {
1755 for_each_dpcm_be(fe, stream, dpcm) {
1789 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
1793 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1795 ret = dpcm_be_dai_startup(fe, stream);
1797 dev_err(fe->dev,"ASoC: failed to start some BEs %d\n", ret);
1801 dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name);
1806 dev_err(fe->dev,"ASoC: failed to start FE %d\n", ret);
1810 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
1817 dev_err(fe->dev, "ASoC: failed to apply dpcm symmetry %d\n",
1822 dpcm_be_dai_startup_unwind(fe, stream);
1824 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1828 int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
1833 for_each_dpcm_be(fe, stream, dpcm) {
1840 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1870 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1873 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1876 dpcm_be_dai_shutdown(fe, stream);
1878 dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name);
1884 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1886 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1887 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1891 int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
1897 for_each_dpcm_be(fe, stream, dpcm) {
1904 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1908 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
1936 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1939 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1940 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1942 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
1947 dev_err(fe->dev,"ASoC: hw_free FE %s failed\n",
1948 fe->dai_link->name);
1952 err = dpcm_be_dai_hw_free(fe, stream);
1954 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1955 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1957 mutex_unlock(&fe->card->mutex);
1961 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
1966 for_each_dpcm_be(fe, stream, dpcm) {
1973 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
1977 memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
1990 if (!snd_soc_dpcm_can_be_params(fe, be, stream))
2014 for_each_dpcm_be_rollback(fe, stream, dpcm) {
2019 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2023 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2041 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2044 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2045 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2047 memcpy(&fe->dpcm[stream].hw_params, params,
2049 ret = dpcm_be_dai_hw_params(fe, stream);
2051 dev_err(fe->dev,"ASoC: hw_params BE failed %d\n", ret);
2055 dev_dbg(fe->dev, "ASoC: hw_params FE %s rate %d chan %x fmt %d\n",
2056 fe->dai_link->name, params_rate(params),
2062 dev_err(fe->dev,"ASoC: hw_params FE failed %d\n", ret);
2063 dpcm_be_dai_hw_free(fe, stream);
2065 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
2068 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2069 mutex_unlock(&fe->card->mutex);
2088 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
2094 for_each_dpcm_be(fe, stream, dpcm) {
2101 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2142 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2155 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2168 if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
2187 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2192 dev_dbg(fe->dev, "ASoC: pre trigger FE %s cmd %d\n",
2193 fe->dai_link->name, cmd);
2199 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2204 ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
2208 dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
2209 fe->dai_link->name, cmd);
2218 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2221 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2223 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
2265 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
2266 fe->dai_link->name, cmd);
2271 dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
2272 fe->dai_link->name);
2278 dev_err(fe->dev, "ASoC: trigger FE cmd: %d failed: %d\n",
2287 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
2291 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
2294 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
2299 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
2305 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2311 if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2312 fe->dpcm[stream].trigger_pending = cmd + 1;
2320 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
2325 for_each_dpcm_be(fe, stream, dpcm) {
2332 if (!snd_soc_dpcm_be_can_update(fe, be, stream))
2335 if (!snd_soc_dpcm_can_be_prepared(fe, be, stream))
2361 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
2364 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2366 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
2368 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2371 if (list_empty(&fe->dpcm[stream].be_clients)) {
2372 dev_err(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
2373 fe->dai_link->name);
2378 ret = dpcm_be_dai_prepare(fe, stream);
2385 dev_err(fe->dev,"ASoC: prepare FE %s failed\n",
2386 fe->dai_link->name);
2391 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
2392 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2395 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2396 mutex_unlock(&fe->card->mutex);
2401 static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
2404 snd_soc_dpcm_get_substream(fe, stream);
2405 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2408 dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
2409 stream ? "capture" : "playback", fe->dai_link->name);
2413 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
2414 fe->dai_link->name);
2418 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2420 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
2421 fe->dai_link->name);
2423 err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
2425 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", err);
2428 err = dpcm_be_dai_hw_free(fe, stream);
2430 dev_err(fe->dev,"ASoC: hw_free FE failed %d\n", err);
2432 err = dpcm_be_dai_shutdown(fe, stream);
2434 dev_err(fe->dev,"ASoC: shutdown FE failed %d\n", err);
2437 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2442 static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
2445 snd_soc_dpcm_get_substream(fe, stream);
2447 enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
2451 dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
2452 stream ? "capture" : "playback", fe->dai_link->name);
2455 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
2456 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
2460 ret = dpcm_be_dai_startup(fe, stream);
2465 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
2468 ret = dpcm_be_dai_hw_params(fe, stream);
2473 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
2477 ret = dpcm_be_dai_prepare(fe, stream);
2482 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_NOP);
2485 if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
2486 fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
2491 dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
2492 fe->dai_link->name);
2496 dev_err(fe->dev,"ASoC: bespoke trigger FE failed %d\n", ret);
2500 dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
2501 fe->dai_link->name);
2503 ret = dpcm_be_dai_trigger(fe, stream,
2506 dev_err(fe->dev,"ASoC: trigger FE failed %d\n", ret);
2514 dpcm_be_dai_hw_free(fe, stream);
2516 dpcm_be_dai_shutdown(fe, stream);
2519 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2520 for_each_dpcm_be(fe, stream, dpcm) {
2525 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2530 static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
2537 if (!fe->dai_link->dynamic)
2540 if (fe->num_cpus > 1) {
2541 dev_err(fe->dev,
2547 if (!snd_soc_dai_active(asoc_rtd_to_cpu(fe, 0)))
2551 dev_dbg(fe->dev, "ASoC: DPCM %s runtime update for FE %s\n",
2552 new ? "new" : "old", fe->dai_link->name);
2557 if (!snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream) ||
2558 !snd_soc_dai_stream_valid(asoc_rtd_to_codec(fe, 0), stream))
2562 if (!snd_soc_dai_stream_active(asoc_rtd_to_cpu(fe, 0), stream) ||
2563 !snd_soc_dai_stream_active(asoc_rtd_to_codec(fe, 0), stream))
2566 paths = dpcm_path_get(fe, stream, &list);
2568 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2569 fe->dai_link->name,
2576 count = dpcm_process_paths(fe, stream, &list, new);
2578 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2580 ret = dpcm_run_update_startup(fe, stream);
2582 ret = dpcm_run_update_shutdown(fe, stream);
2584 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
2585 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2587 dpcm_clear_pending_state(fe, stream);
2588 dpcm_be_disconnect(fe, stream);
2602 struct snd_soc_pcm_runtime *fe;
2607 for_each_card_rtds(card, fe) {
2608 ret = soc_dpcm_fe_runtime_update(fe, 0);
2614 for_each_card_rtds(card, fe) {
2615 ret = soc_dpcm_fe_runtime_update(fe, 1);
2628 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2633 for_each_dpcm_be(fe, stream, dpcm)
2636 dpcm_be_disconnect(fe, stream);
2638 fe->dpcm[stream].runtime = NULL;
2643 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2646 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2651 mutex_unlock(&fe->card->mutex);
2657 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(fe_substream);
2662 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
2663 fe->dpcm[stream].runtime = fe_substream->runtime;
2665 ret = dpcm_path_get(fe, stream, &list);
2669 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2670 fe->dai_link->name, stream ? "capture" : "playback");
2674 dpcm_process_paths(fe, stream, &list, 1);
2680 dpcm_clear_pending_state(fe, stream);
2683 mutex_unlock(&fe->card->mutex);
2884 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
2886 if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
2893 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
2896 if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
2897 ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
2912 static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
2924 spin_lock_irqsave(&fe->card->dpcm_lock, flags);
2927 if (dpcm->fe == fe)
2930 state = dpcm->fe->dpcm[stream].state;
2938 spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
2948 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
2957 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2965 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
2975 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
2983 int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe,
2992 return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));