Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/* max number of FE PCMs before BEs */
27#define SOF_BE_PCM_BASE 16
28
29#define DMA_CHAN_INVALID 0xFFFFFFFF
30
31#define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
32
33/* PCM stream, mapped to FW component */
34struct snd_sof_pcm_stream {
35 u32 comp_id;
36 struct snd_dma_buffer page_table;
37 struct sof_ipc_stream_posn posn;
38 struct snd_pcm_substream *substream;
39 struct snd_compr_stream *cstream;
40 struct work_struct period_elapsed_work;
41 struct snd_soc_dapm_widget_list *list; /* list of connected DAPM widgets */
42 bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */
43 /*
44 * flag to indicate that the DSP pipelines should be kept
45 * active or not while suspending the stream
46 */
47 bool suspend_ignored;
48};
49
50/* ALSA SOF PCM device */
51struct snd_sof_pcm {
52 struct snd_soc_component *scomp;
53 struct snd_soc_tplg_pcm pcm;
54 struct snd_sof_pcm_stream stream[2];
55 struct list_head list; /* list in sdev pcm list */
56 struct snd_pcm_hw_params params[2];
57 bool prepared[2]; /* PCM_PARAMS set successfully */
58};
59
60struct snd_sof_led_control {
61 unsigned int use_led;
62 unsigned int direction;
63 int led_value;
64};
65
66/* ALSA SOF Kcontrol device */
67struct snd_sof_control {
68 struct snd_soc_component *scomp;
69 int comp_id;
70 int min_volume_step; /* min volume step for volume_table */
71 int max_volume_step; /* max volume step for volume_table */
72 int num_channels;
73 unsigned int access;
74 u32 readback_offset; /* offset to mmapped data if used */
75 struct sof_ipc_ctrl_data *control_data;
76 u32 size; /* cdata size */
77 enum sof_ipc_ctrl_cmd cmd;
78 u32 *volume_table; /* volume table computed from tlv data*/
79
80 struct list_head list; /* list in sdev control list */
81
82 struct snd_sof_led_control led_ctl;
83
84 /* if true, the control's data needs to be updated from Firmware */
85 bool comp_data_dirty;
86};
87
88struct snd_sof_widget;
89
90/* ASoC SOF DAPM widget */
91struct snd_sof_widget {
92 struct snd_soc_component *scomp;
93 int comp_id;
94 int pipeline_id;
95 int complete;
96 int use_count; /* use_count will be protected by the PCM mutex held by the core */
97 int core;
98 int id;
99
100 /*
101 * Flag indicating if the widget should be set up dynamically when a PCM is opened.
102 * This flag is only set for the scheduler type widget in topology. During topology
103 * loading, this flag is propagated to all the widgets belonging to the same pipeline.
104 * When this flag is not set, a widget is set up at the time of topology loading
105 * and retained until the DSP enters D3. It will need to be set up again when resuming
106 * from D3.
107 */
108 bool dynamic_pipeline_widget;
109
110 struct snd_soc_dapm_widget *widget;
111 struct list_head list; /* list in sdev widget list */
112 struct snd_sof_widget *pipe_widget;
113
114 /* extended data for UUID components */
115 struct sof_ipc_comp_ext comp_ext;
116
117 void *private; /* core does not touch this */
118};
119
120/* ASoC SOF DAPM route */
121struct snd_sof_route {
122 struct snd_soc_component *scomp;
123
124 struct snd_soc_dapm_route *route;
125 struct list_head list; /* list in sdev route list */
126 struct snd_sof_widget *src_widget;
127 struct snd_sof_widget *sink_widget;
128 bool setup;
129
130 void *private;
131};
132
133/* ASoC DAI device */
134struct snd_sof_dai {
135 struct snd_soc_component *scomp;
136 const char *name;
137
138 struct sof_ipc_comp_dai comp_dai;
139 int number_configs;
140 int current_config;
141 bool configured; /* DAI configured during BE hw_params */
142 struct sof_ipc_dai_config *dai_config;
143 struct list_head list; /* list in sdev dai list */
144};
145
146/*
147 * Kcontrols.
148 */
149
150int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
151 struct snd_ctl_elem_value *ucontrol);
152int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
153 struct snd_ctl_elem_value *ucontrol);
154int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_info *uinfo);
156int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
157 struct snd_ctl_elem_value *ucontrol);
158int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
159 struct snd_ctl_elem_value *ucontrol);
160int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
161 struct snd_ctl_elem_value *ucontrol);
162int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
163 struct snd_ctl_elem_value *ucontrol);
164int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
165 struct snd_ctl_elem_value *ucontrol);
166int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
167 struct snd_ctl_elem_value *ucontrol);
168int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
169 const unsigned int __user *binary_data,
170 unsigned int size);
171int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
172 unsigned int __user *binary_data,
173 unsigned int size);
174int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
175 unsigned int size);
176void snd_sof_control_notify(struct snd_sof_dev *sdev,
177 struct sof_ipc_ctrl_data *cdata);
178
179/*
180 * Topology.
181 * There is no snd_sof_free_topology since topology components will
182 * be freed by snd_soc_unregister_component,
183 */
184int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
185int snd_sof_complete_pipeline(struct snd_sof_dev *sdev,
186 struct snd_sof_widget *swidget);
187
188int sof_load_pipeline_ipc(struct snd_sof_dev *sdev,
189 struct sof_ipc_pipe_new *pipeline,
190 struct sof_ipc_comp_reply *r);
191int sof_pipeline_core_enable(struct snd_sof_dev *sdev,
192 const struct snd_sof_widget *swidget);
193
194/*
195 * Stream IPC
196 */
197int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
198 struct snd_sof_pcm *spcm, int direction,
199 struct sof_ipc_stream_posn *posn);
200
201struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
202 const char *name);
203struct snd_sof_widget *
204snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
205 const char *pcm_name, int dir);
206struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
207 const char *name);
208
209static inline
210struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
211 struct snd_soc_pcm_runtime *rtd)
212{
213 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
214
215 struct snd_sof_pcm *spcm = NULL;
216
217 list_for_each_entry(spcm, &sdev->pcm_list, list) {
218 if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
219 return spcm;
220 }
221
222 return NULL;
223}
224
225struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
226 const char *name);
227struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
228 unsigned int comp_id,
229 int *direction);
230struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,
231 unsigned int pcm_id);
232const struct sof_ipc_pipe_new *snd_sof_pipeline_find(struct snd_sof_dev *sdev,
233 int pipeline_id);
234void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
235void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
236
237#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
238void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
239void snd_sof_compr_init_elapsed_work(struct work_struct *work);
240#else
241static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
242static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
243#endif
244
245/*
246 * Mixer IPC
247 */
248int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,
249 u32 ipc_cmd,
250 enum sof_ipc_ctrl_type ctrl_type,
251 enum sof_ipc_ctrl_cmd ctrl_cmd,
252 bool send);
253
254/* DAI link fixup */
255int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
256
257/* PM */
258int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify);
259int sof_tear_down_pipelines(struct snd_sof_dev *sdev, bool verify);
260int sof_set_hw_params_upon_resume(struct device *dev);
261bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
262bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
263
264/* Machine driver enumeration */
265int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
266void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
267
268int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
269int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
270
271/* PCM */
272int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
273int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
274#endif