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