1 /* SPDX-License-Identifier: (GPL-2.0 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 <sound/soc.h> 15 #include <sound/control.h> 16 #include <sound/sof/stream.h> /* needs to be included before control.h */ 17 #include <sound/sof/control.h> 18 #include <sound/sof/dai.h> 19 #include <sound/sof/topology.h> 20 #include "sof-priv.h" 21 22 #define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component" 23 24 /* max number of FE PCMs before BEs */ 25 #define SOF_BE_PCM_BASE 16 26 27 #define DMA_CHAN_INVALID 0xFFFFFFFF 28 29 /* PCM stream, mapped to FW component */ 30 struct snd_sof_pcm_stream { 31 u32 comp_id; 32 struct snd_dma_buffer page_table; 33 struct sof_ipc_stream_posn posn; 34 struct snd_pcm_substream *substream; 35 struct work_struct period_elapsed_work; 36 bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */ 37 /* 38 * flag to indicate that the DSP pipelines should be kept 39 * active or not while suspending the stream 40 */ 41 bool suspend_ignored; 42 }; 43 44 /* ALSA SOF PCM device */ 45 struct snd_sof_pcm { 46 struct snd_soc_component *scomp; 47 struct snd_soc_tplg_pcm pcm; 48 struct snd_sof_pcm_stream stream[2]; 49 struct list_head list; /* list in sdev pcm list */ 50 struct snd_pcm_hw_params params[2]; 51 bool prepared[2]; /* PCM_PARAMS set successfully */ 52 }; 53 54 struct snd_sof_led_control { 55 unsigned int use_led; 56 unsigned int direction; 57 unsigned int led_value; 58 }; 59 60 /* ALSA SOF Kcontrol device */ 61 struct snd_sof_control { 62 struct snd_soc_component *scomp; 63 int comp_id; 64 int min_volume_step; /* min volume step for volume_table */ 65 int max_volume_step; /* max volume step for volume_table */ 66 int num_channels; 67 u32 readback_offset; /* offset to mmapped data if used */ 68 struct sof_ipc_ctrl_data *control_data; 69 u32 size; /* cdata size */ 70 enum sof_ipc_ctrl_cmd cmd; 71 u32 *volume_table; /* volume table computed from tlv data*/ 72 73 struct list_head list; /* list in sdev control list */ 74 75 struct snd_sof_led_control led_ctl; 76 }; 77 78 /* ASoC SOF DAPM widget */ 79 struct snd_sof_widget { 80 struct snd_soc_component *scomp; 81 int comp_id; 82 int pipeline_id; 83 int complete; 84 int id; 85 86 struct snd_soc_dapm_widget *widget; 87 struct list_head list; /* list in sdev widget list */ 88 89 void *private; /* core does not touch this */ 90 }; 91 92 /* ASoC SOF DAPM route */ 93 struct snd_sof_route { 94 struct snd_soc_component *scomp; 95 96 struct snd_soc_dapm_route *route; 97 struct list_head list; /* list in sdev route list */ 98 99 void *private; 100 }; 101 102 /* ASoC DAI device */ 103 struct snd_sof_dai { 104 struct snd_soc_component *scomp; 105 const char *name; 106 const char *cpu_dai_name; 107 108 struct sof_ipc_comp_dai comp_dai; 109 struct sof_ipc_dai_config *dai_config; 110 struct list_head list; /* list in sdev dai list */ 111 }; 112 113 /* 114 * Kcontrols. 115 */ 116 117 int snd_sof_volume_get(struct snd_kcontrol *kcontrol, 118 struct snd_ctl_elem_value *ucontrol); 119 int snd_sof_volume_put(struct snd_kcontrol *kcontrol, 120 struct snd_ctl_elem_value *ucontrol); 121 int snd_sof_switch_get(struct snd_kcontrol *kcontrol, 122 struct snd_ctl_elem_value *ucontrol); 123 int snd_sof_switch_put(struct snd_kcontrol *kcontrol, 124 struct snd_ctl_elem_value *ucontrol); 125 int snd_sof_enum_get(struct snd_kcontrol *kcontrol, 126 struct snd_ctl_elem_value *ucontrol); 127 int snd_sof_enum_put(struct snd_kcontrol *kcontrol, 128 struct snd_ctl_elem_value *ucontrol); 129 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol, 130 struct snd_ctl_elem_value *ucontrol); 131 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol, 132 struct snd_ctl_elem_value *ucontrol); 133 int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol, 134 const unsigned int __user *binary_data, 135 unsigned int size); 136 int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, 137 unsigned int __user *binary_data, 138 unsigned int size); 139 140 /* 141 * Topology. 142 * There is no snd_sof_free_topology since topology components will 143 * be freed by snd_soc_unregister_component, 144 */ 145 int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file); 146 int snd_sof_complete_pipeline(struct device *dev, 147 struct snd_sof_widget *swidget); 148 149 int sof_load_pipeline_ipc(struct device *dev, 150 struct sof_ipc_pipe_new *pipeline, 151 struct sof_ipc_comp_reply *r); 152 153 /* 154 * Stream IPC 155 */ 156 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp, 157 struct snd_sof_pcm *spcm, int direction, 158 struct sof_ipc_stream_posn *posn); 159 160 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp, 161 const char *name); 162 struct snd_sof_widget * 163 snd_sof_find_swidget_sname(struct snd_soc_component *scomp, 164 const char *pcm_name, int dir); 165 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp, 166 const char *name); 167 168 static inline 169 struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp, 170 struct snd_soc_pcm_runtime *rtd) 171 { 172 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); 173 174 struct snd_sof_pcm *spcm = NULL; 175 176 list_for_each_entry(spcm, &sdev->pcm_list, list) { 177 if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id) 178 return spcm; 179 } 180 181 return NULL; 182 } 183 184 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp, 185 const char *name); 186 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp, 187 unsigned int comp_id, 188 int *direction); 189 struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp, 190 unsigned int pcm_id); 191 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream); 192 193 /* 194 * Mixer IPC 195 */ 196 int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, 197 u32 ipc_cmd, 198 enum sof_ipc_ctrl_type ctrl_type, 199 enum sof_ipc_ctrl_cmd ctrl_cmd, 200 bool send); 201 202 /* PM */ 203 int sof_restore_pipelines(struct device *dev); 204 int sof_set_hw_params_upon_resume(struct device *dev); 205 bool snd_sof_dsp_d0i3_on_suspend(struct snd_sof_dev *sdev); 206 207 /* Machine driver enumeration */ 208 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata); 209 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata); 210 211 #endif 212