xref: /openbmc/linux/include/sound/soc-dpcm.h (revision 23607025303af6e84bc2cd4cabe89c21f6a22a3f)
101d7584cSLiam Girdwood /*
201d7584cSLiam Girdwood  * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
301d7584cSLiam Girdwood  *
401d7584cSLiam Girdwood  * Author:		Liam Girdwood <lrg@ti.com>
501d7584cSLiam Girdwood  *
601d7584cSLiam Girdwood  * This program is free software; you can redistribute it and/or modify
701d7584cSLiam Girdwood  * it under the terms of the GNU General Public License version 2 as
801d7584cSLiam Girdwood  * published by the Free Software Foundation.
901d7584cSLiam Girdwood  */
1001d7584cSLiam Girdwood 
1101d7584cSLiam Girdwood #ifndef __LINUX_SND_SOC_DPCM_H
1201d7584cSLiam Girdwood #define __LINUX_SND_SOC_DPCM_H
1301d7584cSLiam Girdwood 
14*23607025SLiam Girdwood #include <linux/slab.h>
1501d7584cSLiam Girdwood #include <linux/list.h>
1601d7584cSLiam Girdwood #include <sound/pcm.h>
1701d7584cSLiam Girdwood 
1801d7584cSLiam Girdwood struct snd_soc_pcm_runtime;
1901d7584cSLiam Girdwood 
2001d7584cSLiam Girdwood /*
2101d7584cSLiam Girdwood  * Types of runtime_update to perform. e.g. originated from FE PCM ops
2201d7584cSLiam Girdwood  * or audio route changes triggered by muxes/mixers.
2301d7584cSLiam Girdwood  */
2401d7584cSLiam Girdwood enum snd_soc_dpcm_update {
2501d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_NO	= 0,
2601d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_BE,
2701d7584cSLiam Girdwood 	SND_SOC_DPCM_UPDATE_FE,
2801d7584cSLiam Girdwood };
2901d7584cSLiam Girdwood 
3001d7584cSLiam Girdwood /*
3101d7584cSLiam Girdwood  * Dynamic PCM Frontend -> Backend link management states.
3201d7584cSLiam Girdwood  */
3301d7584cSLiam Girdwood enum snd_soc_dpcm_link_state {
3401d7584cSLiam Girdwood 	SND_SOC_DPCM_LINK_STATE_NEW	= 0,	/* newly created link */
3501d7584cSLiam Girdwood 	SND_SOC_DPCM_LINK_STATE_FREE,		/* link to be dismantled */
3601d7584cSLiam Girdwood };
3701d7584cSLiam Girdwood 
3801d7584cSLiam Girdwood /*
3901d7584cSLiam Girdwood  * Dynamic PCM Frontend -> Backend link PCM states.
4001d7584cSLiam Girdwood  */
4101d7584cSLiam Girdwood enum snd_soc_dpcm_state {
4201d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_NEW	= 0,
4301d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_OPEN,
4401d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_HW_PARAMS,
4501d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_PREPARE,
4601d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_START,
4701d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_STOP,
4801d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_PAUSED,
4901d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_SUSPEND,
5001d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_HW_FREE,
5101d7584cSLiam Girdwood 	SND_SOC_DPCM_STATE_CLOSE,
5201d7584cSLiam Girdwood };
5301d7584cSLiam Girdwood 
5401d7584cSLiam Girdwood /*
5501d7584cSLiam Girdwood  * Dynamic PCM trigger ordering. Triggering flexibility is required as some
5601d7584cSLiam Girdwood  * DSPs require triggering before/after their CPU platform and DAIs.
5701d7584cSLiam Girdwood  *
5801d7584cSLiam Girdwood  * i.e. some clients may want to manually order this call in their PCM
5901d7584cSLiam Girdwood  * trigger() whilst others will just use the regular core ordering.
6001d7584cSLiam Girdwood  */
6101d7584cSLiam Girdwood enum snd_soc_dpcm_trigger {
6201d7584cSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_PRE		= 0,
6301d7584cSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_POST,
6407bf84aaSLiam Girdwood 	SND_SOC_DPCM_TRIGGER_BESPOKE,
6501d7584cSLiam Girdwood };
6601d7584cSLiam Girdwood 
6701d7584cSLiam Girdwood /*
6801d7584cSLiam Girdwood  * Dynamic PCM link
6901d7584cSLiam Girdwood  * This links together a FE and BE DAI at runtime and stores the link
7001d7584cSLiam Girdwood  * state information and the hw_params configuration.
7101d7584cSLiam Girdwood  */
7201d7584cSLiam Girdwood struct snd_soc_dpcm {
7301d7584cSLiam Girdwood 	/* FE and BE DAIs*/
7401d7584cSLiam Girdwood 	struct snd_soc_pcm_runtime *be;
7501d7584cSLiam Girdwood 	struct snd_soc_pcm_runtime *fe;
7601d7584cSLiam Girdwood 
7701d7584cSLiam Girdwood 	/* link state */
7801d7584cSLiam Girdwood 	enum snd_soc_dpcm_link_state state;
7901d7584cSLiam Girdwood 
8001d7584cSLiam Girdwood 	/* list of BE and FE for this DPCM link */
8101d7584cSLiam Girdwood 	struct list_head list_be;
8201d7584cSLiam Girdwood 	struct list_head list_fe;
8301d7584cSLiam Girdwood 
8401d7584cSLiam Girdwood 	/* hw params for this link - may be different for each link */
8501d7584cSLiam Girdwood 	struct snd_pcm_hw_params hw_params;
86f86dcef8SLiam Girdwood #ifdef CONFIG_DEBUG_FS
87f86dcef8SLiam Girdwood 	struct dentry *debugfs_state;
88f86dcef8SLiam Girdwood #endif
8901d7584cSLiam Girdwood };
9001d7584cSLiam Girdwood 
9101d7584cSLiam Girdwood /*
9201d7584cSLiam Girdwood  * Dynamic PCM runtime data.
9301d7584cSLiam Girdwood  */
9401d7584cSLiam Girdwood struct snd_soc_dpcm_runtime {
9501d7584cSLiam Girdwood 	struct list_head be_clients;
9601d7584cSLiam Girdwood 	struct list_head fe_clients;
9701d7584cSLiam Girdwood 
9801d7584cSLiam Girdwood 	int users;
9901d7584cSLiam Girdwood 	struct snd_pcm_runtime *runtime;
10001d7584cSLiam Girdwood 	struct snd_pcm_hw_params hw_params;
10101d7584cSLiam Girdwood 
10201d7584cSLiam Girdwood 	/* state and update */
10301d7584cSLiam Girdwood 	enum snd_soc_dpcm_update runtime_update;
10401d7584cSLiam Girdwood 	enum snd_soc_dpcm_state state;
10501d7584cSLiam Girdwood };
10601d7584cSLiam Girdwood 
10701d7584cSLiam Girdwood /* can this BE stop and free */
10801d7584cSLiam Girdwood int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
10901d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
11001d7584cSLiam Girdwood 
11101d7584cSLiam Girdwood /* can this BE perform a hw_params() */
11201d7584cSLiam Girdwood int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
11301d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
11401d7584cSLiam Girdwood 
11501d7584cSLiam Girdwood /* is the current PCM operation for this FE ? */
11601d7584cSLiam Girdwood int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
11701d7584cSLiam Girdwood 
11801d7584cSLiam Girdwood /* is the current PCM operation for this BE ? */
11901d7584cSLiam Girdwood int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
12001d7584cSLiam Girdwood 		struct snd_soc_pcm_runtime *be, int stream);
12101d7584cSLiam Girdwood 
12201d7584cSLiam Girdwood /* get the substream for this BE */
12301d7584cSLiam Girdwood struct snd_pcm_substream *
12401d7584cSLiam Girdwood 	snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
12501d7584cSLiam Girdwood 
12601d7584cSLiam Girdwood /* get the BE runtime state */
12701d7584cSLiam Girdwood enum snd_soc_dpcm_state
12801d7584cSLiam Girdwood 	snd_soc_dpcm_be_get_state(struct snd_soc_pcm_runtime *be, int stream);
12901d7584cSLiam Girdwood 
13001d7584cSLiam Girdwood /* set the BE runtime state */
13101d7584cSLiam Girdwood void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,
13201d7584cSLiam Girdwood 	enum snd_soc_dpcm_state state);
13301d7584cSLiam Girdwood 
13401d7584cSLiam Girdwood /* internal use only */
13501d7584cSLiam Girdwood int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute);
136f86dcef8SLiam Girdwood int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
137c3f48ae6SLars-Peter Clausen int soc_dpcm_runtime_update(struct snd_soc_card *);
13801d7584cSLiam Girdwood 
139*23607025SLiam Girdwood int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
140*23607025SLiam Girdwood 	int stream, struct snd_soc_dapm_widget_list **list_);
141*23607025SLiam Girdwood int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
142*23607025SLiam Girdwood 	int stream, struct snd_soc_dapm_widget_list **list, int new);
143*23607025SLiam Girdwood int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream);
144*23607025SLiam Girdwood int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream);
145*23607025SLiam Girdwood void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream);
146*23607025SLiam Girdwood void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream);
147*23607025SLiam Girdwood int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
148*23607025SLiam Girdwood int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream);
149*23607025SLiam Girdwood int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
150*23607025SLiam Girdwood int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream);
151*23607025SLiam Girdwood int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
152*23607025SLiam Girdwood 	int event);
153*23607025SLiam Girdwood 
154*23607025SLiam Girdwood static inline void dpcm_path_put(struct snd_soc_dapm_widget_list **list)
155*23607025SLiam Girdwood {
156*23607025SLiam Girdwood 	kfree(*list);
157*23607025SLiam Girdwood }
158*23607025SLiam Girdwood 
159*23607025SLiam Girdwood 
16001d7584cSLiam Girdwood #endif
161