^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Liam Girdwood <lrg@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __LINUX_SND_SOC_DPCM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __LINUX_SND_SOC_DPCM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct snd_soc_pcm_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Types of runtime_update to perform. e.g. originated from FE PCM ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * or audio route changes triggered by muxes/mixers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) enum snd_soc_dpcm_update {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) SND_SOC_DPCM_UPDATE_NO = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) SND_SOC_DPCM_UPDATE_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) SND_SOC_DPCM_UPDATE_FE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Dynamic PCM Frontend -> Backend link management states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) enum snd_soc_dpcm_link_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) SND_SOC_DPCM_LINK_STATE_NEW = 0, /* newly created link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) SND_SOC_DPCM_LINK_STATE_FREE, /* link to be dismantled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Dynamic PCM Frontend -> Backend link PCM states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) enum snd_soc_dpcm_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) SND_SOC_DPCM_STATE_NEW = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) SND_SOC_DPCM_STATE_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) SND_SOC_DPCM_STATE_HW_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SND_SOC_DPCM_STATE_PREPARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) SND_SOC_DPCM_STATE_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) SND_SOC_DPCM_STATE_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) SND_SOC_DPCM_STATE_PAUSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) SND_SOC_DPCM_STATE_SUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) SND_SOC_DPCM_STATE_HW_FREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) SND_SOC_DPCM_STATE_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Dynamic PCM trigger ordering. Triggering flexibility is required as some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * DSPs require triggering before/after their CPU platform and DAIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * i.e. some clients may want to manually order this call in their PCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * trigger() whilst others will just use the regular core ordering.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) enum snd_soc_dpcm_trigger {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) SND_SOC_DPCM_TRIGGER_PRE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) SND_SOC_DPCM_TRIGGER_POST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) SND_SOC_DPCM_TRIGGER_BESPOKE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Dynamic PCM link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * This links together a FE and BE DAI at runtime and stores the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * state information and the hw_params configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct snd_soc_dpcm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* FE and BE DAIs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct snd_soc_pcm_runtime *be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct snd_soc_pcm_runtime *fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* link state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) enum snd_soc_dpcm_link_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* list of BE and FE for this DPCM link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct list_head list_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct list_head list_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* hw params for this link - may be different for each link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct snd_pcm_hw_params hw_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct dentry *debugfs_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Dynamic PCM runtime data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct snd_soc_dpcm_runtime {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct list_head be_clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct list_head fe_clients;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int users;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct snd_pcm_hw_params hw_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* state and update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) enum snd_soc_dpcm_update runtime_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) enum snd_soc_dpcm_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define for_each_dpcm_fe(be, stream, _dpcm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) list_for_each_entry(_dpcm, &(be)->dpcm[stream].fe_clients, list_fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define for_each_dpcm_be(fe, stream, _dpcm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) list_for_each_entry(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define for_each_dpcm_be_safe(fe, stream, _dpcm, __dpcm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) list_for_each_entry_safe(_dpcm, __dpcm, &(fe)->dpcm[stream].be_clients, list_be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define for_each_dpcm_be_rollback(fe, stream, _dpcm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) list_for_each_entry_continue_reverse(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* can this BE stop and free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct snd_soc_pcm_runtime *be, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* can this BE perform a hw_params() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct snd_soc_pcm_runtime *be, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* is the current PCM operation for this FE ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* is the current PCM operation for this BE ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct snd_soc_pcm_runtime *be, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* get the substream for this BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct snd_pcm_substream *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* update audio routing between PCMs and any DAI links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int snd_soc_dpcm_runtime_update(struct snd_soc_card *card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int stream, struct snd_soc_dapm_widget_list **list_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void dpcm_path_put(struct snd_soc_dapm_widget_list **list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int stream, struct snd_soc_dapm_widget_list **list, int new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #endif