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