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