xref: /linux/sound/soc/sof/sof-audio.h (revision 906fd46a65383cd639e5eec72a047efc33045d86)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /*
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * Copyright(c) 2019 Intel Corporation
7  *
8  * Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
9  */
10 
11 #ifndef __SOUND_SOC_SOF_AUDIO_H
12 #define __SOUND_SOC_SOF_AUDIO_H
13 
14 #include <linux/workqueue.h>
15 
16 #include <sound/soc.h>
17 #include <sound/control.h>
18 #include <sound/sof/stream.h> /* needs to be included before control.h */
19 #include <sound/sof/control.h>
20 #include <sound/sof/dai.h>
21 #include <sound/sof/topology.h>
22 #include "sof-priv.h"
23 
24 #define SOF_AUDIO_PCM_DRV_NAME	"sof-audio-component"
25 
26 /*
27  * The ipc4 firmware only supports up to 8 sink or source pins
28  * per widget, because only 3 bits are used for queue(pin) ID
29  * in ipc4 protocol.
30  */
31 #define SOF_WIDGET_MAX_NUM_PINS	8
32 
33 /* Widget pin type */
34 #define SOF_PIN_TYPE_INPUT	0
35 #define SOF_PIN_TYPE_OUTPUT	1
36 
37 /* max number of FE PCMs before BEs */
38 #define SOF_BE_PCM_BASE		16
39 
40 #define DMA_CHAN_INVALID	0xFFFFFFFF
41 
42 #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
43 #define WIDGET_IS_AIF(id) ((id) == snd_soc_dapm_aif_in || (id) == snd_soc_dapm_aif_out)
44 #define WIDGET_IS_AIF_OR_DAI(id) (WIDGET_IS_DAI(id) || WIDGET_IS_AIF(id))
45 #define WIDGET_IS_COPIER(id) (WIDGET_IS_AIF_OR_DAI(id) || (id) == snd_soc_dapm_buffer)
46 
47 #define SOF_DAI_CLK_INTEL_SSP_MCLK	0
48 #define SOF_DAI_CLK_INTEL_SSP_BCLK	1
49 
50 enum sof_widget_op {
51 	SOF_WIDGET_PREPARE,
52 	SOF_WIDGET_SETUP,
53 	SOF_WIDGET_FREE,
54 	SOF_WIDGET_UNPREPARE,
55 };
56 
57 /*
58  * Volume fractional word length define to 16 sets
59  * the volume linear gain value to use Qx.16 format
60  */
61 #define VOLUME_FWL	16
62 
63 #define SOF_TLV_ITEMS 3
64 
65 static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
66 {
67 	if (value >= size)
68 		return volume_map[size - 1];
69 
70 	return volume_map[value];
71 }
72 
73 static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
74 {
75 	int i;
76 
77 	for (i = 0; i < size; i++) {
78 		if (volume_map[i] >= value)
79 			return i;
80 	}
81 
82 	return i - 1;
83 }
84 
85 struct snd_sof_widget;
86 struct snd_sof_route;
87 struct snd_sof_control;
88 struct snd_sof_dai;
89 struct snd_sof_pcm;
90 
91 struct snd_sof_dai_config_data {
92 	int dai_index;
93 	int dai_data; /* contains DAI-specific information */
94 	int dai_node_id; /* contains DAI-specific information for Gateway configuration */
95 };
96 
97 /**
98  * struct sof_ipc_pcm_ops - IPC-specific PCM ops
99  * @hw_params: Function pointer for hw_params
100  * @hw_free: Function pointer for hw_free
101  * @trigger: Function pointer for trigger
102  * @dai_link_fixup: Function pointer for DAI link fixup
103  * @pcm_setup: Function pointer for IPC-specific PCM set up that can be used for allocating
104  *	       additional memory in the SOF PCM stream structure
105  * @pcm_free: Function pointer for PCM free that can be used for freeing any
106  *	       additional memory in the SOF PCM stream structure
107  * @pointer: Function pointer for pcm pointer
108  *	     Note: the @pointer callback may return -EOPNOTSUPP which should be
109  *		   handled in a same way as if the callback is not provided
110  * @delay: Function pointer for pcm delay reporting
111  * @reset_hw_params_during_stop: Flag indicating whether the hw_params should be reset during the
112  *				 STOP pcm trigger
113  * @ipc_first_on_start: Send IPC before invoking platform trigger during
114  *				START/PAUSE_RELEASE triggers
115  * @platform_stop_during_hw_free: Invoke the platform trigger during hw_free. This is needed for
116  *				  IPC4 where a pipeline is only paused during stop/pause/suspend
117  *				  triggers. The FW keeps the host DMA running in this case and
118  *				  therefore the host must do the same and should stop the DMA during
119  *				  hw_free.
120  * @d0i3_supported_in_s0ix: Allow DSP D0I3 during S0iX
121  */
122 struct sof_ipc_pcm_ops {
123 	int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
124 			 struct snd_pcm_hw_params *params,
125 			 struct snd_sof_platform_stream_params *platform_params);
126 	int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
127 	int (*trigger)(struct snd_soc_component *component,  struct snd_pcm_substream *substream,
128 		       int cmd);
129 	int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
130 	int (*pcm_setup)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
131 	void (*pcm_free)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
132 	int (*pointer)(struct snd_soc_component *component,
133 		       struct snd_pcm_substream *substream,
134 		       snd_pcm_uframes_t *pointer);
135 	snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
136 				   struct snd_pcm_substream *substream);
137 	bool reset_hw_params_during_stop;
138 	bool ipc_first_on_start;
139 	bool platform_stop_during_hw_free;
140 	bool d0i3_supported_in_s0ix;
141 };
142 
143 /**
144  * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
145  */
146 struct sof_ipc_tplg_control_ops {
147 	bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
148 	int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
149 	bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
150 	int (*switch_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
151 	bool (*enum_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
152 	int (*enum_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
153 	int (*bytes_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
154 	int (*bytes_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
155 	int (*bytes_ext_get)(struct snd_sof_control *scontrol,
156 			     const unsigned int __user *binary_data, unsigned int size);
157 	int (*bytes_ext_volatile_get)(struct snd_sof_control *scontrol,
158 				      const unsigned int __user *binary_data, unsigned int size);
159 	int (*bytes_ext_put)(struct snd_sof_control *scontrol,
160 			     const unsigned int __user *binary_data, unsigned int size);
161 	/* update control data based on notification from the DSP */
162 	void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
163 	/* Optional callback to setup kcontrols associated with an swidget */
164 	int (*widget_kcontrol_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
165 	/* mandatory callback to set up volume table for volume kcontrols */
166 	int (*set_up_volume_table)(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS],
167 				   int size);
168 };
169 
170 /**
171  * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
172  * @ipc_setup: Function pointer for setting up widget IPC params
173  * @ipc_free: Function pointer for freeing widget IPC params
174  * @token_list: List of token ID's that should be parsed for the widget
175  * @token_list_size: number of elements in token_list
176  * @bind_event: Function pointer for binding events to the widget
177  * @ipc_prepare: Optional op for preparing a widget for set up
178  * @ipc_unprepare: Optional op for unpreparing a widget
179  */
180 struct sof_ipc_tplg_widget_ops {
181 	int (*ipc_setup)(struct snd_sof_widget *swidget);
182 	void (*ipc_free)(struct snd_sof_widget *swidget);
183 	enum sof_tokens *token_list;
184 	int token_list_size;
185 	int (*bind_event)(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
186 			  u16 event_type);
187 	int (*ipc_prepare)(struct snd_sof_widget *swidget,
188 			   struct snd_pcm_hw_params *fe_params,
189 			   struct snd_sof_platform_stream_params *platform_params,
190 			   struct snd_pcm_hw_params *source_params, int dir);
191 	void (*ipc_unprepare)(struct snd_sof_widget *swidget);
192 };
193 
194 /**
195  * struct sof_ipc_tplg_ops - IPC-specific topology ops
196  * @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
197  *	    SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
198  *	    initialized to 0.
199  * @control: Pointer to the IPC-specific ops for topology kcontrol IO
200  * @route_setup: Function pointer for setting up pipeline connections
201  * @route_free: Function pointer for freeing pipeline connections.
202  * @token_list: List of all tokens supported by the IPC version. The size of the token_list
203  *		array should be SOF_TOKEN_COUNT. The unused elements in the array will be
204  *		initialized to 0.
205  * @control_setup: Function pointer for setting up kcontrol IPC-specific data
206  * @control_free: Function pointer for freeing kcontrol IPC-specific data
207  * @pipeline_complete: Function pointer for pipeline complete IPC
208  * @widget_setup: Function pointer for setting up setup in the DSP
209  * @widget_free: Function pointer for freeing widget in the DSP
210  * @dai_config: Function pointer for sending DAI config IPC to the DSP
211  * @dai_get_clk: Function pointer for getting the DAI clock setting
212  * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
213  * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
214  * @parse_manifest: Function pointer for ipc4 specific parsing of topology manifest
215  * @link_setup: Function pointer for IPC-specific DAI link set up
216  *
217  * Note: function pointers (ops) are optional
218  */
219 struct sof_ipc_tplg_ops {
220 	const struct sof_ipc_tplg_widget_ops *widget;
221 	const struct sof_ipc_tplg_control_ops *control;
222 	int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
223 	int (*route_free)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
224 	const struct sof_token_info *token_list;
225 	int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
226 	int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
227 	int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
228 	int (*widget_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
229 	int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
230 	int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
231 			  unsigned int flags, struct snd_sof_dai_config_data *data);
232 	int (*dai_get_clk)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type);
233 	int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
234 	int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
235 	int (*parse_manifest)(struct snd_soc_component *scomp, int index,
236 			      struct snd_soc_tplg_manifest *man);
237 	int (*link_setup)(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link);
238 };
239 
240 /** struct snd_sof_tuple - Tuple info
241  * @token:	Token ID
242  * @value:	union of a string or a u32 values
243  */
244 struct snd_sof_tuple {
245 	u32 token;
246 	union {
247 		u32 v;
248 		const char *s;
249 	} value;
250 };
251 
252 /*
253  * List of SOF token ID's. The order of ID's does not matter as token arrays are looked up based on
254  * the ID.
255  */
256 enum sof_tokens {
257 	SOF_PCM_TOKENS,
258 	SOF_PIPELINE_TOKENS,
259 	SOF_SCHED_TOKENS,
260 	SOF_ASRC_TOKENS,
261 	SOF_SRC_TOKENS,
262 	SOF_COMP_TOKENS,
263 	SOF_BUFFER_TOKENS,
264 	SOF_VOLUME_TOKENS,
265 	SOF_PROCESS_TOKENS,
266 	SOF_DAI_TOKENS,
267 	SOF_DAI_LINK_TOKENS,
268 	SOF_HDA_TOKENS,
269 	SOF_SSP_TOKENS,
270 	SOF_ALH_TOKENS,
271 	SOF_DMIC_TOKENS,
272 	SOF_DMIC_PDM_TOKENS,
273 	SOF_ESAI_TOKENS,
274 	SOF_SAI_TOKENS,
275 	SOF_AFE_TOKENS,
276 	SOF_CORE_TOKENS,
277 	SOF_COMP_EXT_TOKENS,
278 	SOF_IN_AUDIO_FORMAT_TOKENS,
279 	SOF_OUT_AUDIO_FORMAT_TOKENS,
280 	SOF_COPIER_DEEP_BUFFER_TOKENS,
281 	SOF_COPIER_TOKENS,
282 	SOF_AUDIO_FMT_NUM_TOKENS,
283 	SOF_COPIER_FORMAT_TOKENS,
284 	SOF_GAIN_TOKENS,
285 	SOF_ACPDMIC_TOKENS,
286 	SOF_ACPI2S_TOKENS,
287 	SOF_MICFIL_TOKENS,
288 	SOF_ACP_SDW_TOKENS,
289 
290 	/* this should be the last */
291 	SOF_TOKEN_COUNT,
292 };
293 
294 /**
295  * struct sof_topology_token - SOF topology token definition
296  * @token:		Token number
297  * @type:		Token type
298  * @get_token:		Function pointer to parse the token value and save it in a object
299  * @offset:		Offset within an object to save the token value into
300  */
301 struct sof_topology_token {
302 	u32 token;
303 	u32 type;
304 	int (*get_token)(void *elem, void *object, u32 offset);
305 	u32 offset;
306 };
307 
308 struct sof_token_info {
309 	const char *name;
310 	const struct sof_topology_token *tokens;
311 	int count;
312 };
313 
314 /**
315  * struct snd_sof_pcm_stream_pipeline_list - List of pipelines associated with a PCM stream
316  * @count: number of pipeline widgets in the @pipe_widgets array
317  * @pipelines: array of pipelines
318  */
319 struct snd_sof_pcm_stream_pipeline_list {
320 	u32 count;
321 	struct snd_sof_pipeline **pipelines;
322 };
323 
324 /* PCM stream, mapped to FW component  */
325 struct snd_sof_pcm_stream {
326 	u32 comp_id;
327 	struct snd_dma_buffer page_table;
328 	struct sof_ipc_stream_posn posn;
329 	struct snd_pcm_substream *substream;
330 	struct snd_compr_stream *cstream;
331 	struct work_struct period_elapsed_work;
332 	struct snd_soc_dapm_widget_list *list; /* list of connected DAPM widgets */
333 	bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */
334 	unsigned int dsp_max_burst_size_in_ms; /* The maximum size of the host DMA burst in ms */
335 	/*
336 	 * flag to indicate that the DSP pipelines should be kept
337 	 * active or not while suspending the stream
338 	 */
339 	bool suspend_ignored;
340 	struct snd_sof_pcm_stream_pipeline_list pipeline_list;
341 
342 	/* used by IPC implementation and core does not touch it */
343 	void *private;
344 };
345 
346 /* ALSA SOF PCM device */
347 struct snd_sof_pcm {
348 	struct snd_soc_component *scomp;
349 	struct snd_soc_tplg_pcm pcm;
350 	struct snd_sof_pcm_stream stream[2];
351 	struct list_head list;	/* list in sdev pcm list */
352 	struct snd_pcm_hw_params params[2];
353 	bool prepared[2]; /* PCM_PARAMS set successfully */
354 	bool pending_stop[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */
355 };
356 
357 struct snd_sof_led_control {
358 	unsigned int use_led;
359 	unsigned int direction;
360 	int led_value;
361 };
362 
363 /* ALSA SOF Kcontrol device */
364 struct snd_sof_control {
365 	struct snd_soc_component *scomp;
366 	const char *name;
367 	int comp_id;
368 	int min_volume_step; /* min volume step for volume_table */
369 	int max_volume_step; /* max volume step for volume_table */
370 	int num_channels;
371 	unsigned int access;
372 	int info_type;
373 	int index; /* pipeline ID */
374 	void *priv; /* private data copied from topology */
375 	size_t priv_size; /* size of private data */
376 	size_t max_size;
377 	void *ipc_control_data;
378 	void *old_ipc_control_data;
379 	int max; /* applicable to volume controls */
380 	u32 size;	/* cdata size */
381 	u32 *volume_table; /* volume table computed from tlv data*/
382 
383 	struct list_head list;	/* list in sdev control list */
384 
385 	struct snd_sof_led_control led_ctl;
386 
387 	/* if true, the control's data needs to be updated from Firmware */
388 	bool comp_data_dirty;
389 };
390 
391 /** struct snd_sof_dai_link - DAI link info
392  * @tuples: array of parsed tuples
393  * @num_tuples: number of tuples in the tuples array
394  * @link: Pointer to snd_soc_dai_link
395  * @hw_configs: Pointer to hw configs in topology
396  * @num_hw_configs: Number of hw configs in topology
397  * @default_hw_cfg_id: Default hw config ID
398  * @type: DAI type
399  * @list: item in snd_sof_dev dai_link list
400  */
401 struct snd_sof_dai_link {
402 	struct snd_sof_tuple *tuples;
403 	int num_tuples;
404 	struct snd_soc_dai_link *link;
405 	struct snd_soc_tplg_hw_config *hw_configs;
406 	int num_hw_configs;
407 	int default_hw_cfg_id;
408 	int type;
409 	struct list_head list;
410 };
411 
412 /* ASoC SOF DAPM widget */
413 struct snd_sof_widget {
414 	struct snd_soc_component *scomp;
415 	int comp_id;
416 	int pipeline_id;
417 	/*
418 	 * the prepared flag is used to indicate that a widget has been prepared for getting set
419 	 * up in the DSP.
420 	 */
421 	bool prepared;
422 
423 	struct mutex setup_mutex; /* to protect the swidget setup and free operations */
424 
425 	/*
426 	 * use_count is protected by the PCM mutex held by the core and the
427 	 * setup_mutex against non stream domain races (kcontrol access for
428 	 * example)
429 	 */
430 	int use_count;
431 
432 	int core;
433 	int id; /* id is the DAPM widget type */
434 	/*
435 	 * Instance ID is set dynamically when the widget gets set up in the FW. It should be
436 	 * unique for each module type across all pipelines. This will not be used in SOF_IPC.
437 	 */
438 	int instance_id;
439 
440 	/*
441 	 * Flag indicating if the widget should be set up dynamically when a PCM is opened.
442 	 * This flag is only set for the scheduler type widget in topology. During topology
443 	 * loading, this flag is propagated to all the widgets belonging to the same pipeline.
444 	 * When this flag is not set, a widget is set up at the time of topology loading
445 	 * and retained until the DSP enters D3. It will need to be set up again when resuming
446 	 * from D3.
447 	 */
448 	bool dynamic_pipeline_widget;
449 
450 	struct snd_soc_dapm_widget *widget;
451 	struct list_head list;	/* list in sdev widget list */
452 	struct snd_sof_pipeline *spipe;
453 	void *module_info;
454 
455 	const guid_t uuid;
456 
457 	int num_tuples;
458 	struct snd_sof_tuple *tuples;
459 
460 	/*
461 	 * The allowed range for num_input/output_pins is [0, SOF_WIDGET_MAX_NUM_PINS].
462 	 * Widgets may have zero input or output pins, for example the tone widget has
463 	 * zero input pins.
464 	 */
465 	u32 num_input_pins;
466 	u32 num_output_pins;
467 
468 	/*
469 	 * The input/output pin binding array, it takes the form of
470 	 * [widget_name_connected_to_pin0, widget_name_connected_to_pin1, ...],
471 	 * with the index as the queue ID.
472 	 *
473 	 * The array is used for special pin binding. Note that even if there
474 	 * is only one input/output pin requires special pin binding, pin binding
475 	 * should be defined for all input/output pins in topology, for pin(s) that
476 	 * are not used, give the value "NotConnected".
477 	 *
478 	 * If pin binding is not defined in topology, nothing to parse in the kernel,
479 	 * input_pin_binding and output_pin_binding shall be NULL.
480 	 */
481 	char **input_pin_binding;
482 	char **output_pin_binding;
483 
484 	struct ida output_queue_ida;
485 	struct ida input_queue_ida;
486 
487 	void *private;		/* core does not touch this */
488 };
489 
490 /** struct snd_sof_pipeline - ASoC SOF pipeline
491  * @pipe_widget: Pointer to the pipeline widget
492  * @started_count: Count of number of PCM's that have started this pipeline
493  * @paused_count: Count of number of PCM's that have started and have currently paused this
494 		  pipeline
495  * @complete: flag used to indicate that pipeline set up is complete.
496  * @core_mask: Mask containing target cores for all modules in the pipeline
497  * @list: List item in sdev pipeline_list
498  */
499 struct snd_sof_pipeline {
500 	struct snd_sof_widget *pipe_widget;
501 	int started_count;
502 	int paused_count;
503 	int complete;
504 	unsigned long core_mask;
505 	struct list_head list;
506 };
507 
508 /* ASoC SOF DAPM route */
509 struct snd_sof_route {
510 	struct snd_soc_component *scomp;
511 
512 	struct snd_soc_dapm_route *route;
513 	struct list_head list;	/* list in sdev route list */
514 	struct snd_sof_widget *src_widget;
515 	struct snd_sof_widget *sink_widget;
516 	bool setup;
517 
518 	int src_queue_id;
519 	int dst_queue_id;
520 
521 	void *private;
522 };
523 
524 /* ASoC DAI device */
525 struct snd_sof_dai {
526 	struct snd_soc_component *scomp;
527 	const char *name;
528 	u32 type;
529 
530 	int number_configs;
531 	int current_config;
532 	struct list_head list;	/* list in sdev dai list */
533 	/* core should not touch this */
534 	const void *platform_private;
535 	void *private;
536 };
537 
538 /*
539  * Kcontrols.
540  */
541 
542 int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
543 		       struct snd_ctl_elem_value *ucontrol);
544 int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
545 		       struct snd_ctl_elem_value *ucontrol);
546 int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
547 			struct snd_ctl_elem_info *uinfo);
548 int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
549 		       struct snd_ctl_elem_value *ucontrol);
550 int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
551 		       struct snd_ctl_elem_value *ucontrol);
552 int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
553 		     struct snd_ctl_elem_value *ucontrol);
554 int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
555 		     struct snd_ctl_elem_value *ucontrol);
556 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
557 		      struct snd_ctl_elem_value *ucontrol);
558 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
559 		      struct snd_ctl_elem_value *ucontrol);
560 int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
561 			  const unsigned int __user *binary_data,
562 			  unsigned int size);
563 int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
564 			  unsigned int __user *binary_data,
565 			  unsigned int size);
566 int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
567 				   unsigned int size);
568 void snd_sof_control_notify(struct snd_sof_dev *sdev,
569 			    struct sof_ipc_ctrl_data *cdata);
570 
571 /*
572  * Topology.
573  * There is no snd_sof_free_topology since topology components will
574  * be freed by snd_soc_unregister_component,
575  */
576 int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
577 
578 /*
579  * Stream IPC
580  */
581 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
582 			    struct snd_sof_pcm *spcm, int direction,
583 			    struct sof_ipc_stream_posn *posn);
584 
585 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
586 					    const char *name);
587 struct snd_sof_widget *
588 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
589 			   const char *pcm_name, int dir);
590 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
591 				     const char *name);
592 
593 static inline
594 struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
595 					  struct snd_soc_pcm_runtime *rtd)
596 {
597 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
598 	struct snd_sof_pcm *spcm;
599 
600 	list_for_each_entry(spcm, &sdev->pcm_list, list) {
601 		if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
602 			return spcm;
603 	}
604 
605 	return NULL;
606 }
607 
608 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
609 					   const char *name);
610 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
611 					   unsigned int comp_id,
612 					   int *direction);
613 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
614 void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
615 
616 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
617 void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
618 void snd_sof_compr_init_elapsed_work(struct work_struct *work);
619 #else
620 static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
621 static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
622 #endif
623 
624 /* DAI link fixup */
625 int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
626 
627 /* PM */
628 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
629 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
630 
631 /* Machine driver enumeration */
632 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
633 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
634 
635 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
636 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
637 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
638 		    struct snd_soc_dapm_widget *wsink);
639 
640 /* PCM */
641 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
642 			  struct snd_pcm_hw_params *fe_params,
643 			  struct snd_sof_platform_stream_params *platform_params,
644 			  int dir);
645 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
646 int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
647 			 struct snd_sof_pcm *spcm);
648 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
649 			struct snd_sof_pcm *spcm, int dir, bool free_widget_list);
650 int get_token_u32(void *elem, void *object, u32 offset);
651 int get_token_u16(void *elem, void *object, u32 offset);
652 int get_token_comp_format(void *elem, void *object, u32 offset);
653 int get_token_dai_type(void *elem, void *object, u32 offset);
654 int get_token_uuid(void *elem, void *object, u32 offset);
655 int get_token_string(void *elem, void *object, u32 offset);
656 int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
657 			  struct snd_sof_tuple *tuples, int num_tuples,
658 			  size_t object_size, int token_instance_num);
659 u32 vol_compute_gain(u32 value, int *tlv);
660 #endif
661