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