projects/linux·blob master · refs

708 lines · 25.2 KiB

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