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 */ 34 struct 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 */ 51 struct 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 60 struct snd_sof_led_control { 61 unsigned int use_led; 62 unsigned int direction; 63 int led_value; 64 }; 65 66 /* ALSA SOF Kcontrol device */ 67 struct 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 u32 *volume_table; /* volume table computed from tlv data*/ 78 79 struct list_head list; /* list in sdev control list */ 80 81 struct snd_sof_led_control led_ctl; 82 83 /* if true, the control's data needs to be updated from Firmware */ 84 bool comp_data_dirty; 85 }; 86 87 struct snd_sof_widget; 88 89 /* ASoC SOF DAPM widget */ 90 struct snd_sof_widget { 91 struct snd_soc_component *scomp; 92 int comp_id; 93 int pipeline_id; 94 int complete; 95 int use_count; /* use_count will be protected by the PCM mutex held by the core */ 96 int core; 97 int id; 98 99 /* 100 * Flag indicating if the widget should be set up dynamically when a PCM is opened. 101 * This flag is only set for the scheduler type widget in topology. During topology 102 * loading, this flag is propagated to all the widgets belonging to the same pipeline. 103 * When this flag is not set, a widget is set up at the time of topology loading 104 * and retained until the DSP enters D3. It will need to be set up again when resuming 105 * from D3. 106 */ 107 bool dynamic_pipeline_widget; 108 109 struct snd_soc_dapm_widget *widget; 110 struct list_head list; /* list in sdev widget list */ 111 struct snd_sof_widget *pipe_widget; 112 113 /* extended data for UUID components */ 114 struct sof_ipc_comp_ext comp_ext; 115 116 void *private; /* core does not touch this */ 117 }; 118 119 /* ASoC SOF DAPM route */ 120 struct snd_sof_route { 121 struct snd_soc_component *scomp; 122 123 struct snd_soc_dapm_route *route; 124 struct list_head list; /* list in sdev route list */ 125 struct snd_sof_widget *src_widget; 126 struct snd_sof_widget *sink_widget; 127 bool setup; 128 129 void *private; 130 }; 131 132 /* ASoC DAI device */ 133 struct snd_sof_dai { 134 struct snd_soc_component *scomp; 135 const char *name; 136 137 struct sof_ipc_comp_dai comp_dai; 138 int number_configs; 139 int current_config; 140 bool configured; /* DAI configured during BE hw_params */ 141 struct sof_ipc_dai_config *dai_config; 142 struct list_head list; /* list in sdev dai list */ 143 }; 144 145 /* 146 * Kcontrols. 147 */ 148 149 int snd_sof_volume_get(struct snd_kcontrol *kcontrol, 150 struct snd_ctl_elem_value *ucontrol); 151 int snd_sof_volume_put(struct snd_kcontrol *kcontrol, 152 struct snd_ctl_elem_value *ucontrol); 153 int snd_sof_volume_info(struct snd_kcontrol *kcontrol, 154 struct snd_ctl_elem_info *uinfo); 155 int snd_sof_switch_get(struct snd_kcontrol *kcontrol, 156 struct snd_ctl_elem_value *ucontrol); 157 int snd_sof_switch_put(struct snd_kcontrol *kcontrol, 158 struct snd_ctl_elem_value *ucontrol); 159 int snd_sof_enum_get(struct snd_kcontrol *kcontrol, 160 struct snd_ctl_elem_value *ucontrol); 161 int snd_sof_enum_put(struct snd_kcontrol *kcontrol, 162 struct snd_ctl_elem_value *ucontrol); 163 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol, 164 struct snd_ctl_elem_value *ucontrol); 165 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol, 166 struct snd_ctl_elem_value *ucontrol); 167 int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol, 168 const unsigned int __user *binary_data, 169 unsigned int size); 170 int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, 171 unsigned int __user *binary_data, 172 unsigned int size); 173 int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data, 174 unsigned int size); 175 void snd_sof_control_notify(struct snd_sof_dev *sdev, 176 struct sof_ipc_ctrl_data *cdata); 177 178 /* 179 * Topology. 180 * There is no snd_sof_free_topology since topology components will 181 * be freed by snd_soc_unregister_component, 182 */ 183 int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file); 184 int snd_sof_complete_pipeline(struct snd_sof_dev *sdev, 185 struct snd_sof_widget *swidget); 186 187 /* 188 * Stream IPC 189 */ 190 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp, 191 struct snd_sof_pcm *spcm, int direction, 192 struct sof_ipc_stream_posn *posn); 193 194 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp, 195 const char *name); 196 struct snd_sof_widget * 197 snd_sof_find_swidget_sname(struct snd_soc_component *scomp, 198 const char *pcm_name, int dir); 199 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp, 200 const char *name); 201 202 static inline 203 struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp, 204 struct snd_soc_pcm_runtime *rtd) 205 { 206 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); 207 208 struct snd_sof_pcm *spcm = NULL; 209 210 list_for_each_entry(spcm, &sdev->pcm_list, list) { 211 if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id) 212 return spcm; 213 } 214 215 return NULL; 216 } 217 218 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp, 219 const char *name); 220 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp, 221 unsigned int comp_id, 222 int *direction); 223 struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp, 224 unsigned int pcm_id); 225 const struct sof_ipc_pipe_new *snd_sof_pipeline_find(struct snd_sof_dev *sdev, 226 int pipeline_id); 227 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream); 228 void snd_sof_pcm_init_elapsed_work(struct work_struct *work); 229 230 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS) 231 void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream); 232 void snd_sof_compr_init_elapsed_work(struct work_struct *work); 233 #else 234 static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { } 235 static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { } 236 #endif 237 238 /* 239 * Mixer IPC 240 */ 241 int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, bool set); 242 243 /* DAI link fixup */ 244 int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params); 245 246 /* PM */ 247 int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify); 248 int sof_tear_down_pipelines(struct snd_sof_dev *sdev, bool verify); 249 int sof_set_hw_params_upon_resume(struct device *dev); 250 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev); 251 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev); 252 253 /* Machine driver enumeration */ 254 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata); 255 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata); 256 257 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget); 258 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget); 259 260 /* PCM */ 261 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir); 262 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir); 263 int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev, 264 struct snd_sof_pcm *spcm); 265 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream, 266 struct snd_sof_pcm *spcm, int dir, bool free_widget_list); 267 #endif 268