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