xref: /openbmc/linux/include/sound/soc-dpcm.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1b53c34b4SKuninori Morimoto /* SPDX-License-Identifier: GPL-2.0
2b53c34b4SKuninori Morimoto  *
301d7584cSLiam Girdwood  * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
401d7584cSLiam Girdwood  *
501d7584cSLiam Girdwood  * Author:		Liam Girdwood <lrg@ti.com>
601d7584cSLiam Girdwood  */
701d7584cSLiam Girdwood 
801d7584cSLiam Girdwood #ifndef __LINUX_SND_SOC_DPCM_H
901d7584cSLiam Girdwood #define __LINUX_SND_SOC_DPCM_H
1001d7584cSLiam Girdwood 
1123607025SLiam Girdwood #include <linux/slab.h>
1201d7584cSLiam Girdwood #include <linux/list.h>
1301d7584cSLiam Girdwood #include <sound/pcm.h>
1401d7584cSLiam Girdwood 
1501d7584cSLiam Girdwood struct snd_soc_pcm_runtime;
1601d7584cSLiam Girdwood 
1701d7584cSLiam Girdwood /*
1801d7584cSLiam Girdwood  * Types of runtime_update to perform. e.g. originated from FE PCM ops
1901d7584cSLiam Girdwood  * or audio route changes triggered by muxes/mixers.
2001d7584cSLiam Girdwood  */
2101d7584cSLiam Girdwood enum snd_soc_dpcm_update {
2201d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_NO	= 0,
2301d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_BE,
2401d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_FE,
2501d7584cSLiam Girdwood };
2601d7584cSLiam Girdwood 
2701d7584cSLiam Girdwood /*
2801d7584cSLiam Girdwood  * Dynamic PCM Frontend -> Backend link management states.
2901d7584cSLiam Girdwood  */
3001d7584cSLiam Girdwood enum snd_soc_dpcm_link_state {
3101d7584cSLiam Girdwood 	SND_SOC_DPCM_LINK_STATE_NEW	= 0,	/* newly created link */
3201d7584cSLiam Girdwood 	SND_SOC_DPCM_LINK_STATE_FREE,		/* link to be dismantled */
3301d7584cSLiam Girdwood };
3401d7584cSLiam Girdwood 
3501d7584cSLiam Girdwood /*
3601d7584cSLiam Girdwood  * Dynamic PCM Frontend -> Backend link PCM states.
3701d7584cSLiam Girdwood  */
3801d7584cSLiam Girdwood enum snd_soc_dpcm_state {
3901d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_NEW	= 0,
4001d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_OPEN,
4101d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_HW_PARAMS,
4201d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_PREPARE,
4301d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_START,
4401d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_STOP,
4501d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_PAUSED,
4601d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_SUSPEND,
4701d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_HW_FREE,
4801d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_CLOSE,
4901d7584cSLiam Girdwood };
5001d7584cSLiam Girdwood 
5101d7584cSLiam Girdwood /*
5201d7584cSLiam Girdwood  * Dynamic PCM trigger ordering. Triggering flexibility is required as some
5301d7584cSLiam Girdwood  * DSPs require triggering before/after their CPU platform and DAIs.
5401d7584cSLiam Girdwood  *
5501d7584cSLiam Girdwood  * i.e. some clients may want to manually order this call in their PCM
5601d7584cSLiam Girdwood  * trigger() whilst others will just use the regular core ordering.
5701d7584cSLiam Girdwood  */
5801d7584cSLiam Girdwood enum snd_soc_dpcm_trigger {
5901d7584cSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_PRE		= 0,
6001d7584cSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_POST,
6107bf84aaSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_BESPOKE,
6201d7584cSLiam Girdwood };
6301d7584cSLiam Girdwood 
6401d7584cSLiam Girdwood /*
6501d7584cSLiam Girdwood  * Dynamic PCM link
6601d7584cSLiam Girdwood  * This links together a FE and BE DAI at runtime and stores the link
6701d7584cSLiam Girdwood  * state information and the hw_params configuration.
6801d7584cSLiam Girdwood  */
6901d7584cSLiam Girdwood struct snd_soc_dpcm {
7001d7584cSLiam Girdwood 	/* FE and BE DAIs*/
7101d7584cSLiam Girdwood 	struct snd_soc_pcm_runtime *be;
7201d7584cSLiam Girdwood 	struct snd_soc_pcm_runtime *fe;
7301d7584cSLiam Girdwood 
7401d7584cSLiam Girdwood 	/* link state */
7501d7584cSLiam Girdwood 	enum snd_soc_dpcm_link_state state;
7601d7584cSLiam Girdwood 
7701d7584cSLiam Girdwood 	/* list of BE and FE for this DPCM link */
7801d7584cSLiam Girdwood 	struct list_head list_be;
7901d7584cSLiam Girdwood 	struct list_head list_fe;
8001d7584cSLiam Girdwood 
81f86dcef8SLiam Girdwood #ifdef CONFIG_DEBUG_FS
82f86dcef8SLiam Girdwood 	struct dentry *debugfs_state;
83f86dcef8SLiam Girdwood #endif
8401d7584cSLiam Girdwood };
8501d7584cSLiam Girdwood 
8601d7584cSLiam Girdwood /*
8701d7584cSLiam Girdwood  * Dynamic PCM runtime data.
8801d7584cSLiam Girdwood  */
8901d7584cSLiam Girdwood struct snd_soc_dpcm_runtime {
9001d7584cSLiam Girdwood 	struct list_head be_clients;
9101d7584cSLiam Girdwood 	struct list_head fe_clients;
9201d7584cSLiam Girdwood 
9301d7584cSLiam Girdwood 	int users;
9401d7584cSLiam Girdwood 	struct snd_pcm_hw_params hw_params;
9501d7584cSLiam Girdwood 
9601d7584cSLiam Girdwood 	/* state and update */
9701d7584cSLiam Girdwood 	enum snd_soc_dpcm_update runtime_update;
9801d7584cSLiam Girdwood 	enum snd_soc_dpcm_state state;
99ea9d0d77STakashi Iwai 
100ea9d0d77STakashi Iwai 	int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */
101848aedfdSPierre-Louis Bossart 
102848aedfdSPierre-Louis Bossart 	int be_start; /* refcount protected by BE stream pcm lock */
1039995c1d0SPierre-Louis Bossart 	int be_pause; /* refcount protected by BE stream pcm lock */
1049995c1d0SPierre-Louis Bossart 	bool fe_pause; /* used to track STOP after PAUSE */
10501d7584cSLiam Girdwood };
10601d7584cSLiam Girdwood 
1074baabbf9SKuninori Morimoto #define for_each_dpcm_fe(be, stream, _dpcm)				\
1084baabbf9SKuninori Morimoto 	list_for_each_entry(_dpcm, &(be)->dpcm[stream].fe_clients, list_fe)
109d2e24d64SKuninori Morimoto 
1104baabbf9SKuninori Morimoto #define for_each_dpcm_be(fe, stream, _dpcm)				\
1114baabbf9SKuninori Morimoto 	list_for_each_entry(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
1124baabbf9SKuninori Morimoto #define for_each_dpcm_be_safe(fe, stream, _dpcm, __dpcm)			\
1134baabbf9SKuninori Morimoto 	list_for_each_entry_safe(_dpcm, __dpcm, &(fe)->dpcm[stream].be_clients, list_be)
1144baabbf9SKuninori Morimoto #define for_each_dpcm_be_rollback(fe, stream, _dpcm)			\
1154baabbf9SKuninori Morimoto 	list_for_each_entry_continue_reverse(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
1168d6258a4SKuninori Morimoto 
11701d7584cSLiam Girdwood /* can this BE stop and free */
11801d7584cSLiam Girdwood int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
11901d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
12001d7584cSLiam Girdwood 
12101d7584cSLiam Girdwood /* can this BE perform a hw_params() */
12201d7584cSLiam Girdwood int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
12301d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
12401d7584cSLiam Girdwood 
125*e123036bSRanjani Sridharan /* can this BE perform prepare */
126*e123036bSRanjani Sridharan int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe,
127*e123036bSRanjani Sridharan 				 struct snd_soc_pcm_runtime *be, int stream);
128*e123036bSRanjani Sridharan 
12901d7584cSLiam Girdwood /* is the current PCM operation for this FE ? */
13001d7584cSLiam Girdwood int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
13101d7584cSLiam Girdwood 
13201d7584cSLiam Girdwood /* is the current PCM operation for this BE ? */
13301d7584cSLiam Girdwood int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
13401d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
13501d7584cSLiam Girdwood 
13601d7584cSLiam Girdwood /* get the substream for this BE */
13701d7584cSLiam Girdwood struct snd_pcm_substream *
13801d7584cSLiam Girdwood 	snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
13901d7584cSLiam Girdwood 
140f17a1478SGuennadi Liakhovetski /* update audio routing between PCMs and any DAI links */
141f17a1478SGuennadi Liakhovetski int snd_soc_dpcm_runtime_update(struct snd_soc_card *card);
14201d7584cSLiam Girdwood 
143ee5b3f11SKuninori Morimoto #ifdef CONFIG_DEBUG_FS
144ee5b3f11SKuninori Morimoto void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
145ee5b3f11SKuninori Morimoto #else
soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime * rtd)146ee5b3f11SKuninori Morimoto static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
147ee5b3f11SKuninori Morimoto {
148ee5b3f11SKuninori Morimoto }
149ee5b3f11SKuninori Morimoto #endif
150ee5b3f11SKuninori Morimoto 
15123607025SLiam Girdwood int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
15223607025SLiam Girdwood 	int stream, struct snd_soc_dapm_widget_list **list_);
15352645e33SKuninori Morimoto void dpcm_path_put(struct snd_soc_dapm_widget_list **list);
15423607025SLiam Girdwood int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
15523607025SLiam Girdwood 	int stream, struct snd_soc_dapm_widget_list **list, int new);
15623607025SLiam Girdwood int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream);
157531590bbSKuninori Morimoto void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
158531590bbSKuninori Morimoto 		      int do_hw_free, struct snd_soc_dpcm *last);
15923607025SLiam Girdwood void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream);
16023607025SLiam Girdwood void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream);
161f52366e6SKuninori Morimoto void dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
16223607025SLiam Girdwood int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream);
16323607025SLiam Girdwood int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
16423607025SLiam Girdwood int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream);
16523607025SLiam Girdwood int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
16623607025SLiam Girdwood 	int event);
167d1a7af09SRanjani Sridharan bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, enum snd_soc_dapm_direction dir);
1685edcf2a3SRanjani Sridharan int widget_in_list(struct snd_soc_dapm_widget_list *list,
1695edcf2a3SRanjani Sridharan 		   struct snd_soc_dapm_widget *widget);
17023607025SLiam Girdwood 
171531590bbSKuninori Morimoto #define dpcm_be_dai_startup_rollback(fe, stream, last)	\
172531590bbSKuninori Morimoto 						dpcm_be_dai_stop(fe, stream, 0, last)
173531590bbSKuninori Morimoto #define dpcm_be_dai_startup_unwind(fe, stream)	dpcm_be_dai_stop(fe, stream, 0, NULL)
174531590bbSKuninori Morimoto #define dpcm_be_dai_shutdown(fe, stream)	dpcm_be_dai_stop(fe, stream, 1, NULL)
175531590bbSKuninori Morimoto 
17601d7584cSLiam Girdwood #endif
177