xref: /linux-6.15/sound/soc/sof/sof-audio.h (revision 86069318)
1e149ca29SPierre-Louis Bossart /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2ee1e79b7SRanjani Sridharan /*
3ee1e79b7SRanjani Sridharan  * This file is provided under a dual BSD/GPLv2 license.  When using or
4ee1e79b7SRanjani Sridharan  * redistributing this file, you may do so under either license.
5ee1e79b7SRanjani Sridharan  *
6293ad281SPierre-Louis Bossart  * Copyright(c) 2019 Intel Corporation
7ee1e79b7SRanjani Sridharan  *
8ee1e79b7SRanjani Sridharan  * Author: Ranjani Sridharan <[email protected]>
9ee1e79b7SRanjani Sridharan  */
10ee1e79b7SRanjani Sridharan 
11ee1e79b7SRanjani Sridharan #ifndef __SOUND_SOC_SOF_AUDIO_H
12ee1e79b7SRanjani Sridharan #define __SOUND_SOC_SOF_AUDIO_H
13ee1e79b7SRanjani Sridharan 
149ef91cadSGuennadi Liakhovetski #include <linux/workqueue.h>
159ef91cadSGuennadi Liakhovetski 
16ee1e79b7SRanjani Sridharan #include <sound/soc.h>
17ee1e79b7SRanjani Sridharan #include <sound/control.h>
18ee1e79b7SRanjani Sridharan #include <sound/sof/stream.h> /* needs to be included before control.h */
19ee1e79b7SRanjani Sridharan #include <sound/sof/control.h>
20ee1e79b7SRanjani Sridharan #include <sound/sof/dai.h>
21ee1e79b7SRanjani Sridharan #include <sound/sof/topology.h>
22ee1e79b7SRanjani Sridharan #include "sof-priv.h"
23ee1e79b7SRanjani Sridharan 
24ee1e79b7SRanjani Sridharan #define SOF_AUDIO_PCM_DRV_NAME	"sof-audio-component"
25ee1e79b7SRanjani Sridharan 
266327c729SChao Song /*
276327c729SChao Song  * The ipc4 firmware only supports up to 8 sink or source pins
286327c729SChao Song  * per widget, because only 3 bits are used for queue(pin) ID
296327c729SChao Song  * in ipc4 protocol.
306327c729SChao Song  */
316327c729SChao Song #define SOF_WIDGET_MAX_NUM_PINS	8
326327c729SChao Song 
33bb79f2a6SRanjani Sridharan /* Widget pin type */
34bb79f2a6SRanjani Sridharan #define SOF_PIN_TYPE_INPUT	0
35bb79f2a6SRanjani Sridharan #define SOF_PIN_TYPE_OUTPUT	1
363b3acedbSChao Song 
37ee1e79b7SRanjani Sridharan /* max number of FE PCMs before BEs */
38ee1e79b7SRanjani Sridharan #define SOF_BE_PCM_BASE		16
39ee1e79b7SRanjani Sridharan 
40ee1e79b7SRanjani Sridharan #define DMA_CHAN_INVALID	0xFFFFFFFF
41ee1e79b7SRanjani Sridharan 
425fcdbb2dSRanjani Sridharan #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
435da0590aSRanjani Sridharan #define WIDGET_IS_AIF(id) ((id) == snd_soc_dapm_aif_in || (id) == snd_soc_dapm_aif_out)
445da0590aSRanjani Sridharan #define WIDGET_IS_AIF_OR_DAI(id) (WIDGET_IS_DAI(id) || WIDGET_IS_AIF(id))
4511f60563SBard Liao #define WIDGET_IS_COPIER(id) (WIDGET_IS_AIF_OR_DAI(id) || (id) == snd_soc_dapm_buffer)
465fcdbb2dSRanjani Sridharan 
476073c477SBrent Lu #define SOF_DAI_PARAM_INTEL_SSP_MCLK		0
486073c477SBrent Lu #define SOF_DAI_PARAM_INTEL_SSP_BCLK		1
491deba6e2SBrent Lu #define SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS	2
5085f7a8b6SRanjani Sridharan 
515da0590aSRanjani Sridharan enum sof_widget_op {
5266344c6dSRanjani Sridharan 	SOF_WIDGET_PREPARE,
535da0590aSRanjani Sridharan 	SOF_WIDGET_SETUP,
5466344c6dSRanjani Sridharan 	SOF_WIDGET_FREE,
5566344c6dSRanjani Sridharan 	SOF_WIDGET_UNPREPARE,
565da0590aSRanjani Sridharan };
575da0590aSRanjani Sridharan 
58b5cee8feSRanjani Sridharan /*
59b5cee8feSRanjani Sridharan  * Volume fractional word length define to 16 sets
60b5cee8feSRanjani Sridharan  * the volume linear gain value to use Qx.16 format
61b5cee8feSRanjani Sridharan  */
62b5cee8feSRanjani Sridharan #define VOLUME_FWL	16
63b5cee8feSRanjani Sridharan 
6448d2a1ceSRanjani Sridharan #define SOF_TLV_ITEMS 3
6548d2a1ceSRanjani Sridharan 
mixer_to_ipc(unsigned int value,u32 * volume_map,int size)667b3a5be5SRanjani Sridharan static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
677b3a5be5SRanjani Sridharan {
687b3a5be5SRanjani Sridharan 	if (value >= size)
697b3a5be5SRanjani Sridharan 		return volume_map[size - 1];
707b3a5be5SRanjani Sridharan 
717b3a5be5SRanjani Sridharan 	return volume_map[value];
727b3a5be5SRanjani Sridharan }
737b3a5be5SRanjani Sridharan 
ipc_to_mixer(u32 value,u32 * volume_map,int size)747b3a5be5SRanjani Sridharan static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
757b3a5be5SRanjani Sridharan {
767b3a5be5SRanjani Sridharan 	int i;
777b3a5be5SRanjani Sridharan 
787b3a5be5SRanjani Sridharan 	for (i = 0; i < size; i++) {
797b3a5be5SRanjani Sridharan 		if (volume_map[i] >= value)
807b3a5be5SRanjani Sridharan 			return i;
817b3a5be5SRanjani Sridharan 	}
827b3a5be5SRanjani Sridharan 
837b3a5be5SRanjani Sridharan 	return i - 1;
847b3a5be5SRanjani Sridharan }
857b3a5be5SRanjani Sridharan 
86226abb75SRanjani Sridharan struct snd_sof_widget;
87226abb75SRanjani Sridharan struct snd_sof_route;
88b5cee8feSRanjani Sridharan struct snd_sof_control;
8985f7a8b6SRanjani Sridharan struct snd_sof_dai;
907201a3d4SRanjani Sridharan struct snd_sof_pcm;
91226abb75SRanjani Sridharan 
92051744b1SRanjani Sridharan struct snd_sof_dai_config_data {
93051744b1SRanjani Sridharan 	int dai_index;
94051744b1SRanjani Sridharan 	int dai_data; /* contains DAI-specific information */
95a936456dSPierre-Louis Bossart 	int dai_node_id; /* contains DAI-specific information for Gateway configuration */
96051744b1SRanjani Sridharan };
97051744b1SRanjani Sridharan 
98226abb75SRanjani Sridharan /**
99967885eeSRanjani Sridharan  * struct sof_ipc_pcm_ops - IPC-specific PCM ops
100967885eeSRanjani Sridharan  * @hw_params: Function pointer for hw_params
101967885eeSRanjani Sridharan  * @hw_free: Function pointer for hw_free
102967885eeSRanjani Sridharan  * @trigger: Function pointer for trigger
103967885eeSRanjani Sridharan  * @dai_link_fixup: Function pointer for DAI link fixup
1047201a3d4SRanjani Sridharan  * @pcm_setup: Function pointer for IPC-specific PCM set up that can be used for allocating
1057201a3d4SRanjani Sridharan  *	       additional memory in the SOF PCM stream structure
1067201a3d4SRanjani Sridharan  * @pcm_free: Function pointer for PCM free that can be used for freeing any
1077201a3d4SRanjani Sridharan  *	       additional memory in the SOF PCM stream structure
10877165bd9SPeter Ujfalusi  * @pointer: Function pointer for pcm pointer
10977165bd9SPeter Ujfalusi  *	     Note: the @pointer callback may return -EOPNOTSUPP which should be
11077165bd9SPeter Ujfalusi  *		   handled in a same way as if the callback is not provided
11177165bd9SPeter Ujfalusi  * @delay: Function pointer for pcm delay reporting
1127d6f623cSRanjani Sridharan  * @reset_hw_params_during_stop: Flag indicating whether the hw_params should be reset during the
1137d6f623cSRanjani Sridharan  *				 STOP pcm trigger
11451ce3e6eSRanjani Sridharan  * @ipc_first_on_start: Send IPC before invoking platform trigger during
11551ce3e6eSRanjani Sridharan  *				START/PAUSE_RELEASE triggers
1166d0a21ddSRanjani Sridharan  * @platform_stop_during_hw_free: Invoke the platform trigger during hw_free. This is needed for
1176d0a21ddSRanjani Sridharan  *				  IPC4 where a pipeline is only paused during stop/pause/suspend
1186d0a21ddSRanjani Sridharan  *				  triggers. The FW keeps the host DMA running in this case and
1196d0a21ddSRanjani Sridharan  *				  therefore the host must do the same and should stop the DMA during
1206d0a21ddSRanjani Sridharan  *				  hw_free.
12190a23530SRanjani Sridharan  * @d0i3_supported_in_s0ix: Allow DSP D0I3 during S0iX
122967885eeSRanjani Sridharan  */
123967885eeSRanjani Sridharan struct sof_ipc_pcm_ops {
124967885eeSRanjani Sridharan 	int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
125967885eeSRanjani Sridharan 			 struct snd_pcm_hw_params *params,
126967885eeSRanjani Sridharan 			 struct snd_sof_platform_stream_params *platform_params);
127967885eeSRanjani Sridharan 	int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
128967885eeSRanjani Sridharan 	int (*trigger)(struct snd_soc_component *component,  struct snd_pcm_substream *substream,
129967885eeSRanjani Sridharan 		       int cmd);
130967885eeSRanjani Sridharan 	int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
1317201a3d4SRanjani Sridharan 	int (*pcm_setup)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
1327201a3d4SRanjani Sridharan 	void (*pcm_free)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
13377165bd9SPeter Ujfalusi 	int (*pointer)(struct snd_soc_component *component,
13477165bd9SPeter Ujfalusi 		       struct snd_pcm_substream *substream,
13577165bd9SPeter Ujfalusi 		       snd_pcm_uframes_t *pointer);
13627c2100bSRander Wang 	snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
13727c2100bSRander Wang 				   struct snd_pcm_substream *substream);
1387d6f623cSRanjani Sridharan 	bool reset_hw_params_during_stop;
13951ce3e6eSRanjani Sridharan 	bool ipc_first_on_start;
1406d0a21ddSRanjani Sridharan 	bool platform_stop_during_hw_free;
14190a23530SRanjani Sridharan 	bool d0i3_supported_in_s0ix;
142967885eeSRanjani Sridharan };
143967885eeSRanjani Sridharan 
144967885eeSRanjani Sridharan /**
14510f461d7SRanjani Sridharan  * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
146a0149a6bSRanjani Sridharan  */
14710f461d7SRanjani Sridharan struct sof_ipc_tplg_control_ops {
148a0149a6bSRanjani Sridharan 	bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
149a0149a6bSRanjani Sridharan 	int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
150a0149a6bSRanjani Sridharan 	bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
151a0149a6bSRanjani Sridharan 	int (*switch_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
152a0149a6bSRanjani Sridharan 	bool (*enum_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
153a0149a6bSRanjani Sridharan 	int (*enum_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
154a0149a6bSRanjani Sridharan 	int (*bytes_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
155a0149a6bSRanjani Sridharan 	int (*bytes_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
156a0149a6bSRanjani Sridharan 	int (*bytes_ext_get)(struct snd_sof_control *scontrol,
157a0149a6bSRanjani Sridharan 			     const unsigned int __user *binary_data, unsigned int size);
158a0149a6bSRanjani Sridharan 	int (*bytes_ext_volatile_get)(struct snd_sof_control *scontrol,
159a0149a6bSRanjani Sridharan 				      const unsigned int __user *binary_data, unsigned int size);
160a0149a6bSRanjani Sridharan 	int (*bytes_ext_put)(struct snd_sof_control *scontrol,
161a0149a6bSRanjani Sridharan 			     const unsigned int __user *binary_data, unsigned int size);
162a0149a6bSRanjani Sridharan 	/* update control data based on notification from the DSP */
163a0149a6bSRanjani Sridharan 	void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
164e394ffb8SPeter Ujfalusi 	/* Optional callback to setup kcontrols associated with an swidget */
165e394ffb8SPeter Ujfalusi 	int (*widget_kcontrol_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
16648d2a1ceSRanjani Sridharan 	/* mandatory callback to set up volume table for volume kcontrols */
16748d2a1ceSRanjani Sridharan 	int (*set_up_volume_table)(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS],
16848d2a1ceSRanjani Sridharan 				   int size);
169a0149a6bSRanjani Sridharan };
170a0149a6bSRanjani Sridharan 
171a0149a6bSRanjani Sridharan /**
172226abb75SRanjani Sridharan  * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
173226abb75SRanjani Sridharan  * @ipc_setup: Function pointer for setting up widget IPC params
174226abb75SRanjani Sridharan  * @ipc_free: Function pointer for freeing widget IPC params
175226abb75SRanjani Sridharan  * @token_list: List of token ID's that should be parsed for the widget
176226abb75SRanjani Sridharan  * @token_list_size: number of elements in token_list
177226abb75SRanjani Sridharan  * @bind_event: Function pointer for binding events to the widget
17866344c6dSRanjani Sridharan  * @ipc_prepare: Optional op for preparing a widget for set up
17966344c6dSRanjani Sridharan  * @ipc_unprepare: Optional op for unpreparing a widget
180226abb75SRanjani Sridharan  */
181226abb75SRanjani Sridharan struct sof_ipc_tplg_widget_ops {
182226abb75SRanjani Sridharan 	int (*ipc_setup)(struct snd_sof_widget *swidget);
183226abb75SRanjani Sridharan 	void (*ipc_free)(struct snd_sof_widget *swidget);
184226abb75SRanjani Sridharan 	enum sof_tokens *token_list;
185226abb75SRanjani Sridharan 	int token_list_size;
186226abb75SRanjani Sridharan 	int (*bind_event)(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
187226abb75SRanjani Sridharan 			  u16 event_type);
18866344c6dSRanjani Sridharan 	int (*ipc_prepare)(struct snd_sof_widget *swidget,
18966344c6dSRanjani Sridharan 			   struct snd_pcm_hw_params *fe_params,
19066344c6dSRanjani Sridharan 			   struct snd_sof_platform_stream_params *platform_params,
19166344c6dSRanjani Sridharan 			   struct snd_pcm_hw_params *source_params, int dir);
19266344c6dSRanjani Sridharan 	void (*ipc_unprepare)(struct snd_sof_widget *swidget);
193226abb75SRanjani Sridharan };
194226abb75SRanjani Sridharan 
195226abb75SRanjani Sridharan /**
196226abb75SRanjani Sridharan  * struct sof_ipc_tplg_ops - IPC-specific topology ops
197226abb75SRanjani Sridharan  * @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
198226abb75SRanjani Sridharan  *	    SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
199226abb75SRanjani Sridharan  *	    initialized to 0.
200a0149a6bSRanjani Sridharan  * @control: Pointer to the IPC-specific ops for topology kcontrol IO
201226abb75SRanjani Sridharan  * @route_setup: Function pointer for setting up pipeline connections
2027cbb1559SPeter Ujfalusi  * @route_free: Function pointer for freeing pipeline connections.
203226abb75SRanjani Sridharan  * @token_list: List of all tokens supported by the IPC version. The size of the token_list
204226abb75SRanjani Sridharan  *		array should be SOF_TOKEN_COUNT. The unused elements in the array will be
205226abb75SRanjani Sridharan  *		initialized to 0.
206b5cee8feSRanjani Sridharan  * @control_setup: Function pointer for setting up kcontrol IPC-specific data
207b5cee8feSRanjani Sridharan  * @control_free: Function pointer for freeing kcontrol IPC-specific data
20861ad28ffSRanjani Sridharan  * @pipeline_complete: Function pointer for pipeline complete IPC
209051744b1SRanjani Sridharan  * @widget_setup: Function pointer for setting up setup in the DSP
210051744b1SRanjani Sridharan  * @widget_free: Function pointer for freeing widget in the DSP
211051744b1SRanjani Sridharan  * @dai_config: Function pointer for sending DAI config IPC to the DSP
2126073c477SBrent Lu  * @dai_get_param: Function pointer for getting the DAI parameter
21331cd6e46SRanjani Sridharan  * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
21431cd6e46SRanjani Sridharan  * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
2157cbb1559SPeter Ujfalusi  * @parse_manifest: Function pointer for ipc4 specific parsing of topology manifest
216e380c907SRanjani Sridharan  * @link_setup: Function pointer for IPC-specific DAI link set up
2177cbb1559SPeter Ujfalusi  *
2187cbb1559SPeter Ujfalusi  * Note: function pointers (ops) are optional
219226abb75SRanjani Sridharan  */
220226abb75SRanjani Sridharan struct sof_ipc_tplg_ops {
221226abb75SRanjani Sridharan 	const struct sof_ipc_tplg_widget_ops *widget;
22210f461d7SRanjani Sridharan 	const struct sof_ipc_tplg_control_ops *control;
223226abb75SRanjani Sridharan 	int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
224d77d7795SRanjani Sridharan 	int (*route_free)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
225226abb75SRanjani Sridharan 	const struct sof_token_info *token_list;
226b5cee8feSRanjani Sridharan 	int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
227b5cee8feSRanjani Sridharan 	int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
22861ad28ffSRanjani Sridharan 	int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
229051744b1SRanjani Sridharan 	int (*widget_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
230051744b1SRanjani Sridharan 	int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
231051744b1SRanjani Sridharan 	int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
232051744b1SRanjani Sridharan 			  unsigned int flags, struct snd_sof_dai_config_data *data);
2336073c477SBrent Lu 	int (*dai_get_param)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int param_type);
23431cd6e46SRanjani Sridharan 	int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
23531cd6e46SRanjani Sridharan 	int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
236323aa1f0SRanjani Sridharan 	int (*parse_manifest)(struct snd_soc_component *scomp, int index,
237323aa1f0SRanjani Sridharan 			      struct snd_soc_tplg_manifest *man);
238e380c907SRanjani Sridharan 	int (*link_setup)(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link);
239226abb75SRanjani Sridharan };
240226abb75SRanjani Sridharan 
241c7b655adSRanjani Sridharan /** struct snd_sof_tuple - Tuple info
242c7b655adSRanjani Sridharan  * @token:	Token ID
243c7b655adSRanjani Sridharan  * @value:	union of a string or a u32 values
244c7b655adSRanjani Sridharan  */
245c7b655adSRanjani Sridharan struct snd_sof_tuple {
246c7b655adSRanjani Sridharan 	u32 token;
247c7b655adSRanjani Sridharan 	union {
248c7b655adSRanjani Sridharan 		u32 v;
249c7b655adSRanjani Sridharan 		const char *s;
250c7b655adSRanjani Sridharan 	} value;
251c7b655adSRanjani Sridharan };
252c7b655adSRanjani Sridharan 
253d87524bfSRanjani Sridharan /*
254d87524bfSRanjani Sridharan  * List of SOF token ID's. The order of ID's does not matter as token arrays are looked up based on
255d87524bfSRanjani Sridharan  * the ID.
256d87524bfSRanjani Sridharan  */
257d87524bfSRanjani Sridharan enum sof_tokens {
258d87524bfSRanjani Sridharan 	SOF_PCM_TOKENS,
259d87524bfSRanjani Sridharan 	SOF_PIPELINE_TOKENS,
260d87524bfSRanjani Sridharan 	SOF_SCHED_TOKENS,
261d87524bfSRanjani Sridharan 	SOF_ASRC_TOKENS,
262d87524bfSRanjani Sridharan 	SOF_SRC_TOKENS,
263d87524bfSRanjani Sridharan 	SOF_COMP_TOKENS,
264d87524bfSRanjani Sridharan 	SOF_BUFFER_TOKENS,
265d87524bfSRanjani Sridharan 	SOF_VOLUME_TOKENS,
266d87524bfSRanjani Sridharan 	SOF_PROCESS_TOKENS,
267d87524bfSRanjani Sridharan 	SOF_DAI_TOKENS,
268d87524bfSRanjani Sridharan 	SOF_DAI_LINK_TOKENS,
269d87524bfSRanjani Sridharan 	SOF_HDA_TOKENS,
270d87524bfSRanjani Sridharan 	SOF_SSP_TOKENS,
271d87524bfSRanjani Sridharan 	SOF_ALH_TOKENS,
272d87524bfSRanjani Sridharan 	SOF_DMIC_TOKENS,
273d87524bfSRanjani Sridharan 	SOF_DMIC_PDM_TOKENS,
274d87524bfSRanjani Sridharan 	SOF_ESAI_TOKENS,
275d87524bfSRanjani Sridharan 	SOF_SAI_TOKENS,
276d87524bfSRanjani Sridharan 	SOF_AFE_TOKENS,
277d87524bfSRanjani Sridharan 	SOF_CORE_TOKENS,
278d87524bfSRanjani Sridharan 	SOF_COMP_EXT_TOKENS,
2792cabd02bSRanjani Sridharan 	SOF_IN_AUDIO_FORMAT_TOKENS,
2802cabd02bSRanjani Sridharan 	SOF_OUT_AUDIO_FORMAT_TOKENS,
281594c1bb9SRanjani Sridharan 	SOF_COPIER_DEEP_BUFFER_TOKENS,
2822cabd02bSRanjani Sridharan 	SOF_COPIER_TOKENS,
2832cabd02bSRanjani Sridharan 	SOF_AUDIO_FMT_NUM_TOKENS,
2842cabd02bSRanjani Sridharan 	SOF_COPIER_FORMAT_TOKENS,
2854f838ab2SRanjani Sridharan 	SOF_GAIN_TOKENS,
286689614ceSAjit Kumar Pandey 	SOF_ACPDMIC_TOKENS,
28775af4199SV sujith kumar Reddy 	SOF_ACPI2S_TOKENS,
28889ef4208SDaniel Baluta 	SOF_MICFIL_TOKENS,
28914d89e55SVijendar Mukunda 	SOF_ACP_SDW_TOKENS,
290d87524bfSRanjani Sridharan 
291d87524bfSRanjani Sridharan 	/* this should be the last */
292d87524bfSRanjani Sridharan 	SOF_TOKEN_COUNT,
293d87524bfSRanjani Sridharan };
294d87524bfSRanjani Sridharan 
295d87524bfSRanjani Sridharan /**
296d87524bfSRanjani Sridharan  * struct sof_topology_token - SOF topology token definition
297d87524bfSRanjani Sridharan  * @token:		Token number
298d87524bfSRanjani Sridharan  * @type:		Token type
299d87524bfSRanjani Sridharan  * @get_token:		Function pointer to parse the token value and save it in a object
300d87524bfSRanjani Sridharan  * @offset:		Offset within an object to save the token value into
301d87524bfSRanjani Sridharan  */
302d87524bfSRanjani Sridharan struct sof_topology_token {
303d87524bfSRanjani Sridharan 	u32 token;
304d87524bfSRanjani Sridharan 	u32 type;
305d87524bfSRanjani Sridharan 	int (*get_token)(void *elem, void *object, u32 offset);
306d87524bfSRanjani Sridharan 	u32 offset;
307d87524bfSRanjani Sridharan };
308d87524bfSRanjani Sridharan 
309d87524bfSRanjani Sridharan struct sof_token_info {
310d87524bfSRanjani Sridharan 	const char *name;
311d87524bfSRanjani Sridharan 	const struct sof_topology_token *tokens;
312d87524bfSRanjani Sridharan 	int count;
313d87524bfSRanjani Sridharan };
314d87524bfSRanjani Sridharan 
315ba223b3aSRanjani Sridharan /**
316ba223b3aSRanjani Sridharan  * struct snd_sof_pcm_stream_pipeline_list - List of pipelines associated with a PCM stream
3179c04363dSRanjani Sridharan  * @pipelines: array of pipelines
3185821d7b4SPierre-Louis Bossart  * @count: number of pipeline widgets in the @pipe_widgets array
319ba223b3aSRanjani Sridharan  */
320ba223b3aSRanjani Sridharan struct snd_sof_pcm_stream_pipeline_list {
3219c04363dSRanjani Sridharan 	struct snd_sof_pipeline **pipelines;
3225821d7b4SPierre-Louis Bossart 	u32 count;
323ba223b3aSRanjani Sridharan };
324ba223b3aSRanjani Sridharan 
325ee1e79b7SRanjani Sridharan /* PCM stream, mapped to FW component  */
326ee1e79b7SRanjani Sridharan struct snd_sof_pcm_stream {
327ee1e79b7SRanjani Sridharan 	u32 comp_id;
328ee1e79b7SRanjani Sridharan 	struct snd_dma_buffer page_table;
329ee1e79b7SRanjani Sridharan 	struct sof_ipc_stream_posn posn;
330ee1e79b7SRanjani Sridharan 	struct snd_pcm_substream *substream;
331858f7a5cSDaniel Baluta 	struct snd_compr_stream *cstream;
332ee1e79b7SRanjani Sridharan 	struct work_struct period_elapsed_work;
3335fcdbb2dSRanjani Sridharan 	struct snd_soc_dapm_widget_list *list; /* list of connected DAPM widgets */
334ee1e79b7SRanjani Sridharan 	bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */
33570a667d7SPeter Ujfalusi 	bool pause_supported; /* PCM device supports PAUSE operation */
336fb9f8125SPeter Ujfalusi 	unsigned int dsp_max_burst_size_in_ms; /* The maximum size of the host DMA burst in ms */
337ee1e79b7SRanjani Sridharan 	/*
338ee1e79b7SRanjani Sridharan 	 * flag to indicate that the DSP pipelines should be kept
339ee1e79b7SRanjani Sridharan 	 * active or not while suspending the stream
340ee1e79b7SRanjani Sridharan 	 */
341ee1e79b7SRanjani Sridharan 	bool suspend_ignored;
342ba223b3aSRanjani Sridharan 	struct snd_sof_pcm_stream_pipeline_list pipeline_list;
34365a8ef49SRander Wang 
34465a8ef49SRander Wang 	/* used by IPC implementation and core does not touch it */
34565a8ef49SRander Wang 	void *private;
346ee1e79b7SRanjani Sridharan };
347ee1e79b7SRanjani Sridharan 
348ee1e79b7SRanjani Sridharan /* ALSA SOF PCM device */
349ee1e79b7SRanjani Sridharan struct snd_sof_pcm {
350ee1e79b7SRanjani Sridharan 	struct snd_soc_component *scomp;
351ee1e79b7SRanjani Sridharan 	struct snd_sof_pcm_stream stream[2];
352ee1e79b7SRanjani Sridharan 	struct list_head list;	/* list in sdev pcm list */
353ee1e79b7SRanjani Sridharan 	struct snd_pcm_hw_params params[2];
354ee1e79b7SRanjani Sridharan 	bool prepared[2]; /* PCM_PARAMS set successfully */
355dbc78bceSPierre-Louis Bossart 	bool pending_stop[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */
3565dde0cd2SGustavo A. R. Silva 
3575dde0cd2SGustavo A. R. Silva 	/* Must be last - ends in a flex-array member. */
3585dde0cd2SGustavo A. R. Silva 	struct snd_soc_tplg_pcm pcm;
359ee1e79b7SRanjani Sridharan };
360ee1e79b7SRanjani Sridharan 
361ee1e79b7SRanjani Sridharan struct snd_sof_led_control {
362ee1e79b7SRanjani Sridharan 	unsigned int use_led;
363ee1e79b7SRanjani Sridharan 	unsigned int direction;
36449c22696SKai-Heng Feng 	int led_value;
365ee1e79b7SRanjani Sridharan };
366ee1e79b7SRanjani Sridharan 
367ee1e79b7SRanjani Sridharan /* ALSA SOF Kcontrol device */
368ee1e79b7SRanjani Sridharan struct snd_sof_control {
369ee1e79b7SRanjani Sridharan 	struct snd_soc_component *scomp;
370b5cee8feSRanjani Sridharan 	const char *name;
371ee1e79b7SRanjani Sridharan 	int comp_id;
372ee1e79b7SRanjani Sridharan 	int min_volume_step; /* min volume step for volume_table */
373ee1e79b7SRanjani Sridharan 	int max_volume_step; /* max volume step for volume_table */
374ee1e79b7SRanjani Sridharan 	int num_channels;
375199a3754SRanjani Sridharan 	unsigned int access;
376b5cee8feSRanjani Sridharan 	int info_type;
377b5cee8feSRanjani Sridharan 	int index; /* pipeline ID */
378b5cee8feSRanjani Sridharan 	void *priv; /* private data copied from topology */
379b5cee8feSRanjani Sridharan 	size_t priv_size; /* size of private data */
380b5cee8feSRanjani Sridharan 	size_t max_size;
381b5cee8feSRanjani Sridharan 	void *ipc_control_data;
382299f6c75SPaul Olaru 	void *old_ipc_control_data;
383b5cee8feSRanjani Sridharan 	int max; /* applicable to volume controls */
384ee1e79b7SRanjani Sridharan 	u32 size;	/* cdata size */
385ee1e79b7SRanjani Sridharan 	u32 *volume_table; /* volume table computed from tlv data*/
386ee1e79b7SRanjani Sridharan 
387ee1e79b7SRanjani Sridharan 	struct list_head list;	/* list in sdev control list */
388ee1e79b7SRanjani Sridharan 
389ee1e79b7SRanjani Sridharan 	struct snd_sof_led_control led_ctl;
390756bbe42SPeter Ujfalusi 
391756bbe42SPeter Ujfalusi 	/* if true, the control's data needs to be updated from Firmware */
392756bbe42SPeter Ujfalusi 	bool comp_data_dirty;
393ee1e79b7SRanjani Sridharan };
394ee1e79b7SRanjani Sridharan 
3950af0f463SRanjani Sridharan /** struct snd_sof_dai_link - DAI link info
3960af0f463SRanjani Sridharan  * @tuples: array of parsed tuples
3970af0f463SRanjani Sridharan  * @num_tuples: number of tuples in the tuples array
3980af0f463SRanjani Sridharan  * @link: Pointer to snd_soc_dai_link
3990af0f463SRanjani Sridharan  * @hw_configs: Pointer to hw configs in topology
4000af0f463SRanjani Sridharan  * @num_hw_configs: Number of hw configs in topology
4010af0f463SRanjani Sridharan  * @default_hw_cfg_id: Default hw config ID
4020af0f463SRanjani Sridharan  * @type: DAI type
4030af0f463SRanjani Sridharan  * @list: item in snd_sof_dev dai_link list
4040af0f463SRanjani Sridharan  */
4050af0f463SRanjani Sridharan struct snd_sof_dai_link {
4060af0f463SRanjani Sridharan 	struct snd_sof_tuple *tuples;
4070af0f463SRanjani Sridharan 	int num_tuples;
4080af0f463SRanjani Sridharan 	struct snd_soc_dai_link *link;
4090af0f463SRanjani Sridharan 	struct snd_soc_tplg_hw_config *hw_configs;
4100af0f463SRanjani Sridharan 	int num_hw_configs;
4110af0f463SRanjani Sridharan 	int default_hw_cfg_id;
4120af0f463SRanjani Sridharan 	int type;
4130af0f463SRanjani Sridharan 	struct list_head list;
4140af0f463SRanjani Sridharan };
4152c28ecadSRanjani Sridharan 
416ee1e79b7SRanjani Sridharan /* ASoC SOF DAPM widget */
417ee1e79b7SRanjani Sridharan struct snd_sof_widget {
418ee1e79b7SRanjani Sridharan 	struct snd_soc_component *scomp;
419ee1e79b7SRanjani Sridharan 	int comp_id;
420ee1e79b7SRanjani Sridharan 	int pipeline_id;
421463a809bSRanjani Sridharan 	/*
42266344c6dSRanjani Sridharan 	 * the prepared flag is used to indicate that a widget has been prepared for getting set
42366344c6dSRanjani Sridharan 	 * up in the DSP.
42466344c6dSRanjani Sridharan 	 */
42566344c6dSRanjani Sridharan 	bool prepared;
426f94f3915SPeter Ujfalusi 
427f94f3915SPeter Ujfalusi 	struct mutex setup_mutex; /* to protect the swidget setup and free operations */
428f94f3915SPeter Ujfalusi 
429f94f3915SPeter Ujfalusi 	/*
430f94f3915SPeter Ujfalusi 	 * use_count is protected by the PCM mutex held by the core and the
431f94f3915SPeter Ujfalusi 	 * setup_mutex against non stream domain races (kcontrol access for
432f94f3915SPeter Ujfalusi 	 * example)
433f94f3915SPeter Ujfalusi 	 */
434f94f3915SPeter Ujfalusi 	int use_count;
435f94f3915SPeter Ujfalusi 
436d1c6c4a9SGuennadi Liakhovetski 	int core;
43736cbc9dfSRanjani Sridharan 	int id; /* id is the DAPM widget type */
43836cbc9dfSRanjani Sridharan 	/*
43936cbc9dfSRanjani Sridharan 	 * Instance ID is set dynamically when the widget gets set up in the FW. It should be
44036cbc9dfSRanjani Sridharan 	 * unique for each module type across all pipelines. This will not be used in SOF_IPC.
44136cbc9dfSRanjani Sridharan 	 */
44236cbc9dfSRanjani Sridharan 	int instance_id;
443ee1e79b7SRanjani Sridharan 
4442c28ecadSRanjani Sridharan 	/*
4452c28ecadSRanjani Sridharan 	 * Flag indicating if the widget should be set up dynamically when a PCM is opened.
4462c28ecadSRanjani Sridharan 	 * This flag is only set for the scheduler type widget in topology. During topology
4472c28ecadSRanjani Sridharan 	 * loading, this flag is propagated to all the widgets belonging to the same pipeline.
4482c28ecadSRanjani Sridharan 	 * When this flag is not set, a widget is set up at the time of topology loading
4492c28ecadSRanjani Sridharan 	 * and retained until the DSP enters D3. It will need to be set up again when resuming
4502c28ecadSRanjani Sridharan 	 * from D3.
4512c28ecadSRanjani Sridharan 	 */
4522c28ecadSRanjani Sridharan 	bool dynamic_pipeline_widget;
4532c28ecadSRanjani Sridharan 
454ee1e79b7SRanjani Sridharan 	struct snd_soc_dapm_widget *widget;
455ee1e79b7SRanjani Sridharan 	struct list_head list;	/* list in sdev widget list */
4569c04363dSRanjani Sridharan 	struct snd_sof_pipeline *spipe;
45736cbc9dfSRanjani Sridharan 	void *module_info;
458ee1e79b7SRanjani Sridharan 
4597a976552SRanjani Sridharan 	const guid_t uuid;
460f970a77fSKeyon Jie 
461c7b655adSRanjani Sridharan 	int num_tuples;
462c7b655adSRanjani Sridharan 	struct snd_sof_tuple *tuples;
463c7b655adSRanjani Sridharan 
4646327c729SChao Song 	/*
465bb79f2a6SRanjani Sridharan 	 * The allowed range for num_input/output_pins is [0, SOF_WIDGET_MAX_NUM_PINS].
466bb79f2a6SRanjani Sridharan 	 * Widgets may have zero input or output pins, for example the tone widget has
467bb79f2a6SRanjani Sridharan 	 * zero input pins.
4686327c729SChao Song 	 */
469bb79f2a6SRanjani Sridharan 	u32 num_input_pins;
470bb79f2a6SRanjani Sridharan 	u32 num_output_pins;
4716327c729SChao Song 
4723b3acedbSChao Song 	/*
473bb79f2a6SRanjani Sridharan 	 * The input/output pin binding array, it takes the form of
4743b3acedbSChao Song 	 * [widget_name_connected_to_pin0, widget_name_connected_to_pin1, ...],
4753b3acedbSChao Song 	 * with the index as the queue ID.
4763b3acedbSChao Song 	 *
4773b3acedbSChao Song 	 * The array is used for special pin binding. Note that even if there
478bb79f2a6SRanjani Sridharan 	 * is only one input/output pin requires special pin binding, pin binding
479bb79f2a6SRanjani Sridharan 	 * should be defined for all input/output pins in topology, for pin(s) that
4803b3acedbSChao Song 	 * are not used, give the value "NotConnected".
4813b3acedbSChao Song 	 *
4823b3acedbSChao Song 	 * If pin binding is not defined in topology, nothing to parse in the kernel,
483bb79f2a6SRanjani Sridharan 	 * input_pin_binding and output_pin_binding shall be NULL.
4843b3acedbSChao Song 	 */
485bb79f2a6SRanjani Sridharan 	char **input_pin_binding;
486bb79f2a6SRanjani Sridharan 	char **output_pin_binding;
4873b3acedbSChao Song 
488bb79f2a6SRanjani Sridharan 	struct ida output_queue_ida;
489bb79f2a6SRanjani Sridharan 	struct ida input_queue_ida;
490c84443dbSChao Song 
491ee1e79b7SRanjani Sridharan 	void *private;		/* core does not touch this */
492ee1e79b7SRanjani Sridharan };
493ee1e79b7SRanjani Sridharan 
4949c04363dSRanjani Sridharan /** struct snd_sof_pipeline - ASoC SOF pipeline
4959c04363dSRanjani Sridharan  * @pipe_widget: Pointer to the pipeline widget
4969c04363dSRanjani Sridharan  * @started_count: Count of number of PCM's that have started this pipeline
4979c04363dSRanjani Sridharan  * @paused_count: Count of number of PCM's that have started and have currently paused this
4989c04363dSRanjani Sridharan 		  pipeline
4999c04363dSRanjani Sridharan  * @complete: flag used to indicate that pipeline set up is complete.
5000376b995SRanjani Sridharan  * @core_mask: Mask containing target cores for all modules in the pipeline
5019c04363dSRanjani Sridharan  * @list: List item in sdev pipeline_list
5029c04363dSRanjani Sridharan  */
5039c04363dSRanjani Sridharan struct snd_sof_pipeline {
5049c04363dSRanjani Sridharan 	struct snd_sof_widget *pipe_widget;
5059c04363dSRanjani Sridharan 	int started_count;
5069c04363dSRanjani Sridharan 	int paused_count;
5079c04363dSRanjani Sridharan 	int complete;
5080376b995SRanjani Sridharan 	unsigned long core_mask;
5099c04363dSRanjani Sridharan 	struct list_head list;
5109c04363dSRanjani Sridharan };
5119c04363dSRanjani Sridharan 
512ee1e79b7SRanjani Sridharan /* ASoC SOF DAPM route */
513ee1e79b7SRanjani Sridharan struct snd_sof_route {
514ee1e79b7SRanjani Sridharan 	struct snd_soc_component *scomp;
515ee1e79b7SRanjani Sridharan 
516ee1e79b7SRanjani Sridharan 	struct snd_soc_dapm_route *route;
517ee1e79b7SRanjani Sridharan 	struct list_head list;	/* list in sdev route list */
5180a2dea1fSRanjani Sridharan 	struct snd_sof_widget *src_widget;
5190a2dea1fSRanjani Sridharan 	struct snd_sof_widget *sink_widget;
5200a2dea1fSRanjani Sridharan 	bool setup;
521ee1e79b7SRanjani Sridharan 
522c84443dbSChao Song 	int src_queue_id;
523c84443dbSChao Song 	int dst_queue_id;
524c84443dbSChao Song 
525ee1e79b7SRanjani Sridharan 	void *private;
526ee1e79b7SRanjani Sridharan };
527ee1e79b7SRanjani Sridharan 
528ee1e79b7SRanjani Sridharan /* ASoC DAI device */
529ee1e79b7SRanjani Sridharan struct snd_sof_dai {
530ee1e79b7SRanjani Sridharan 	struct snd_soc_component *scomp;
531ee1e79b7SRanjani Sridharan 	const char *name;
532f9618ff1SRanjani Sridharan 	u32 type;
533ee1e79b7SRanjani Sridharan 
534c1c03888SJaska Uimonen 	int number_configs;
535c1c03888SJaska Uimonen 	int current_config;
536ee1e79b7SRanjani Sridharan 	struct list_head list;	/* list in sdev dai list */
5372ae49c6fSRanjani Sridharan 	/* core should not touch this */
5382ae49c6fSRanjani Sridharan 	const void *platform_private;
539839e484fSRanjani Sridharan 	void *private;
540ee1e79b7SRanjani Sridharan };
541ee1e79b7SRanjani Sridharan 
542ee1e79b7SRanjani Sridharan /*
543ee1e79b7SRanjani Sridharan  * Kcontrols.
544ee1e79b7SRanjani Sridharan  */
545ee1e79b7SRanjani Sridharan 
546ee1e79b7SRanjani Sridharan int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
547ee1e79b7SRanjani Sridharan 		       struct snd_ctl_elem_value *ucontrol);
548ee1e79b7SRanjani Sridharan int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
549ee1e79b7SRanjani Sridharan 		       struct snd_ctl_elem_value *ucontrol);
550fca18e62SJaska Uimonen int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
551518a760cSPierre-Louis Bossart 			struct snd_ctl_elem_info *uinfo);
552ee1e79b7SRanjani Sridharan int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
553ee1e79b7SRanjani Sridharan 		       struct snd_ctl_elem_value *ucontrol);
554ee1e79b7SRanjani Sridharan int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
555ee1e79b7SRanjani Sridharan 		       struct snd_ctl_elem_value *ucontrol);
556ee1e79b7SRanjani Sridharan int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
557ee1e79b7SRanjani Sridharan 		     struct snd_ctl_elem_value *ucontrol);
558ee1e79b7SRanjani Sridharan int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
559ee1e79b7SRanjani Sridharan 		     struct snd_ctl_elem_value *ucontrol);
560ee1e79b7SRanjani Sridharan int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
561ee1e79b7SRanjani Sridharan 		      struct snd_ctl_elem_value *ucontrol);
562ee1e79b7SRanjani Sridharan int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
563ee1e79b7SRanjani Sridharan 		      struct snd_ctl_elem_value *ucontrol);
564ee1e79b7SRanjani Sridharan int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
565ee1e79b7SRanjani Sridharan 			  const unsigned int __user *binary_data,
566ee1e79b7SRanjani Sridharan 			  unsigned int size);
567ee1e79b7SRanjani Sridharan int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
568ee1e79b7SRanjani Sridharan 			  unsigned int __user *binary_data,
569ee1e79b7SRanjani Sridharan 			  unsigned int size);
570783560d0SDharageswari R int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
571783560d0SDharageswari R 				   unsigned int size);
572756bbe42SPeter Ujfalusi void snd_sof_control_notify(struct snd_sof_dev *sdev,
573756bbe42SPeter Ujfalusi 			    struct sof_ipc_ctrl_data *cdata);
574ee1e79b7SRanjani Sridharan 
575ee1e79b7SRanjani Sridharan /*
576ee1e79b7SRanjani Sridharan  * Topology.
577ee1e79b7SRanjani Sridharan  * There is no snd_sof_free_topology since topology components will
578ee1e79b7SRanjani Sridharan  * be freed by snd_soc_unregister_component,
579ee1e79b7SRanjani Sridharan  */
580ee1e79b7SRanjani Sridharan int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
581ee1e79b7SRanjani Sridharan 
582ee1e79b7SRanjani Sridharan /*
583ee1e79b7SRanjani Sridharan  * Stream IPC
584ee1e79b7SRanjani Sridharan  */
585ee1e79b7SRanjani Sridharan int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
586ee1e79b7SRanjani Sridharan 			    struct snd_sof_pcm *spcm, int direction,
587ee1e79b7SRanjani Sridharan 			    struct sof_ipc_stream_posn *posn);
588ee1e79b7SRanjani Sridharan 
589ee1e79b7SRanjani Sridharan struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
590ee1e79b7SRanjani Sridharan 					    const char *name);
591ee1e79b7SRanjani Sridharan struct snd_sof_widget *
592ee1e79b7SRanjani Sridharan snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
593ee1e79b7SRanjani Sridharan 			   const char *pcm_name, int dir);
594ee1e79b7SRanjani Sridharan struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
595ee1e79b7SRanjani Sridharan 				     const char *name);
596ee1e79b7SRanjani Sridharan 
597ee1e79b7SRanjani Sridharan static inline
snd_sof_find_spcm_dai(struct snd_soc_component * scomp,struct snd_soc_pcm_runtime * rtd)598ee1e79b7SRanjani Sridharan struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
599ee1e79b7SRanjani Sridharan 					  struct snd_soc_pcm_runtime *rtd)
600ee1e79b7SRanjani Sridharan {
601ee1e79b7SRanjani Sridharan 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
602d516e96bSPierre-Louis Bossart 	struct snd_sof_pcm *spcm;
603ee1e79b7SRanjani Sridharan 
604ee1e79b7SRanjani Sridharan 	list_for_each_entry(spcm, &sdev->pcm_list, list) {
605ee1e79b7SRanjani Sridharan 		if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
606ee1e79b7SRanjani Sridharan 			return spcm;
607ee1e79b7SRanjani Sridharan 	}
608ee1e79b7SRanjani Sridharan 
609ee1e79b7SRanjani Sridharan 	return NULL;
610ee1e79b7SRanjani Sridharan }
611ee1e79b7SRanjani Sridharan 
612ee1e79b7SRanjani Sridharan struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
613ee1e79b7SRanjani Sridharan 					   const char *name);
614ee1e79b7SRanjani Sridharan struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
615ee1e79b7SRanjani Sridharan 					   unsigned int comp_id,
616ee1e79b7SRanjani Sridharan 					   int *direction);
617ee1e79b7SRanjani Sridharan void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
618858f7a5cSDaniel Baluta void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
619858f7a5cSDaniel Baluta 
620*86069318SPeter Ujfalusi /*
621*86069318SPeter Ujfalusi  * snd_sof_pcm specific wrappers for dev_dbg() and dev_err() to provide
622*86069318SPeter Ujfalusi  * consistent and useful prints.
623*86069318SPeter Ujfalusi  */
624*86069318SPeter Ujfalusi #define spcm_dbg(__spcm, __dir, __fmt, ...)					\
625*86069318SPeter Ujfalusi 	dev_dbg((__spcm)->scomp->dev, "pcm%u (%s), dir %d: " __fmt,		\
626*86069318SPeter Ujfalusi 		(__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir,		\
627*86069318SPeter Ujfalusi 		##__VA_ARGS__)
628*86069318SPeter Ujfalusi 
629*86069318SPeter Ujfalusi #define spcm_err(__spcm, __dir, __fmt, ...)					\
630*86069318SPeter Ujfalusi 	dev_err((__spcm)->scomp->dev, "%s: pcm%u (%s), dir %d: " __fmt,		\
631*86069318SPeter Ujfalusi 		__func__, (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir,	\
632*86069318SPeter Ujfalusi 		##__VA_ARGS__)
633*86069318SPeter Ujfalusi 
634858f7a5cSDaniel Baluta #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
635858f7a5cSDaniel Baluta void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
636858f7a5cSDaniel Baluta void snd_sof_compr_init_elapsed_work(struct work_struct *work);
637858f7a5cSDaniel Baluta #else
snd_sof_compr_fragment_elapsed(struct snd_compr_stream * cstream)638858f7a5cSDaniel Baluta static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
snd_sof_compr_init_elapsed_work(struct work_struct * work)639858f7a5cSDaniel Baluta static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
640858f7a5cSDaniel Baluta #endif
641ee1e79b7SRanjani Sridharan 
642f805e7e0SRanjani Sridharan /* DAI link fixup */
643f805e7e0SRanjani Sridharan int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
644f805e7e0SRanjani Sridharan 
645ee1e79b7SRanjani Sridharan /* PM */
646700d1677SRanjani Sridharan bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
647de23a838SRanjani Sridharan bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
648ee1e79b7SRanjani Sridharan 
649285880a2SDaniel Baluta /* Machine driver enumeration */
650285880a2SDaniel Baluta int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
651285880a2SDaniel Baluta void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
652285880a2SDaniel Baluta 
6538b001416SRanjani Sridharan int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
6548b001416SRanjani Sridharan int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
6553816bbeaSRanjani Sridharan int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
6563816bbeaSRanjani Sridharan 		    struct snd_soc_dapm_widget *wsink);
6578b001416SRanjani Sridharan 
6585fcdbb2dSRanjani Sridharan /* PCM */
65966344c6dSRanjani Sridharan int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
66066344c6dSRanjani Sridharan 			  struct snd_pcm_hw_params *fe_params,
66166344c6dSRanjani Sridharan 			  struct snd_sof_platform_stream_params *platform_params,
66266344c6dSRanjani Sridharan 			  int dir);
6635fcdbb2dSRanjani Sridharan int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
66496da1740SRanjani Sridharan int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
66596da1740SRanjani Sridharan 			 struct snd_sof_pcm *spcm);
666169ec0a5SPeter Ujfalusi int sof_pcm_free_all_streams(struct snd_sof_dev *sdev);
667ea7e5ee6SRanjani Sridharan int get_token_u32(void *elem, void *object, u32 offset);
668ea7e5ee6SRanjani Sridharan int get_token_u16(void *elem, void *object, u32 offset);
669ea7e5ee6SRanjani Sridharan int get_token_comp_format(void *elem, void *object, u32 offset);
670ea7e5ee6SRanjani Sridharan int get_token_dai_type(void *elem, void *object, u32 offset);
671ea7e5ee6SRanjani Sridharan int get_token_uuid(void *elem, void *object, u32 offset);
6723b3acedbSChao Song int get_token_string(void *elem, void *object, u32 offset);
673d87524bfSRanjani Sridharan int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
674d87524bfSRanjani Sridharan 			  struct snd_sof_tuple *tuples, int num_tuples,
675d87524bfSRanjani Sridharan 			  size_t object_size, int token_instance_num);
67648d2a1ceSRanjani Sridharan u32 vol_compute_gain(u32 value, int *tlv);
677ee1e79b7SRanjani Sridharan #endif
678