1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * wm_adsp.h -- Wolfson ADSP support
5 * Copyright 2012 Wolfson Microelectronics plc
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
13 #include <sound/soc.h>
14 #include <sound/soc-dapm.h>
15 #include <sound/compress_driver.h>
19 /* Return values for wm_adsp_compr_handle_irq */
20 #define WM_ADSP_COMPR_OK 0
21 #define WM_ADSP_COMPR_VOICE_TRIGGER 1
23 #define CS_ADSP2_REGION_0 BIT(0)
24 #define CS_ADSP2_REGION_1 BIT(1)
25 #define CS_ADSP2_REGION_2 BIT(2)
26 #define CS_ADSP2_REGION_3 BIT(3)
27 #define CS_ADSP2_REGION_4 BIT(4)
28 #define CS_ADSP2_REGION_5 BIT(5)
29 #define CS_ADSP2_REGION_6 BIT(6)
30 #define CS_ADSP2_REGION_7 BIT(7)
31 #define CS_ADSP2_REGION_8 BIT(8)
32 #define CS_ADSP2_REGION_9 BIT(9)
33 #define CS_ADSP2_REGION_1_9 (CS_ADSP2_REGION_1 | \
34 CS_ADSP2_REGION_2 | CS_ADSP2_REGION_3 | \
35 CS_ADSP2_REGION_4 | CS_ADSP2_REGION_5 | \
36 CS_ADSP2_REGION_6 | CS_ADSP2_REGION_7 | \
37 CS_ADSP2_REGION_8 | CS_ADSP2_REGION_9)
38 #define CS_ADSP2_REGION_ALL (CS_ADSP2_REGION_0 | CS_ADSP2_REGION_1_9)
40 struct cs_dsp_region {
45 struct cs_dsp_alg_region {
46 struct list_head list;
53 struct wm_adsp_compr_buf;
55 struct cs_dsp_client_ops;
57 struct cs_dsp_coeff_ctl {
59 /* Subname is needed to match with firmware */
61 unsigned int subname_len;
62 struct cs_dsp_alg_region alg_region;
64 unsigned int enabled:1;
65 struct list_head list;
82 struct regmap *regmap;
84 const struct cs_dsp_ops *ops;
85 const struct cs_dsp_client_ops *client_ops;
88 unsigned int base_sysinfo;
89 unsigned int sysclk_reg;
90 unsigned int sysclk_mask;
91 unsigned int sysclk_shift;
93 struct list_head alg_regions;
97 unsigned int fw_id_version;
98 unsigned int fw_vendor_id;
100 const struct cs_dsp_region *mem;
108 struct list_head ctl_list;
110 struct mutex pwr_lock;
112 unsigned int lock_regions;
114 #ifdef CONFIG_DEBUG_FS
115 struct dentry *debugfs_root;
116 char *wmfw_file_name;
122 struct cs_dsp cs_dsp;
124 const char *fwf_name;
125 struct snd_soc_component *component;
127 unsigned int sys_config_size;
131 struct work_struct boot_work;
136 struct list_head compr_list;
137 struct list_head buffer_list;
141 bool (*validate_version)(struct cs_dsp *dsp, unsigned int version);
142 unsigned int (*parse_sizes)(struct cs_dsp *dsp,
143 const char * const file,
145 const struct firmware *firmware);
146 int (*setup_algs)(struct cs_dsp *dsp);
147 unsigned int (*region_to_reg)(struct cs_dsp_region const *mem,
148 unsigned int offset);
150 void (*show_fw_status)(struct cs_dsp *dsp);
151 void (*stop_watchdog)(struct cs_dsp *dsp);
153 int (*enable_memory)(struct cs_dsp *dsp);
154 void (*disable_memory)(struct cs_dsp *dsp);
155 int (*lock_memory)(struct cs_dsp *dsp, unsigned int lock_regions);
157 int (*enable_core)(struct cs_dsp *dsp);
158 void (*disable_core)(struct cs_dsp *dsp);
160 int (*start_core)(struct cs_dsp *dsp);
161 void (*stop_core)(struct cs_dsp *dsp);
164 #define WM_ADSP1(wname, num) \
165 SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \
166 wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
168 #define WM_ADSP2_PRELOAD_SWITCH(wname, num) \
169 SOC_SINGLE_EXT(wname " Preload Switch", SND_SOC_NOPM, num, 1, 0, \
170 wm_adsp2_preloader_get, wm_adsp2_preloader_put)
172 #define WM_ADSP2(wname, num, event_fn) \
173 SND_SOC_DAPM_SPK(wname " Preload", NULL), \
174 { .id = snd_soc_dapm_supply, .name = wname " Preloader", \
175 .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \
176 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \
177 .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \
178 { .id = snd_soc_dapm_out_drv, .name = wname, \
179 .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \
180 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
182 #define WM_ADSP_FW_CONTROL(dspname, num) \
183 SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
184 wm_adsp_fw_get, wm_adsp_fw_put)
186 extern const struct soc_enum wm_adsp_fw_enum[];
188 int wm_adsp1_init(struct wm_adsp *dsp);
189 int wm_adsp2_init(struct wm_adsp *dsp);
190 void wm_adsp2_remove(struct wm_adsp *dsp);
191 int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component);
192 int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component);
193 int wm_halo_init(struct wm_adsp *dsp);
195 int wm_adsp1_event(struct snd_soc_dapm_widget *w,
196 struct snd_kcontrol *kcontrol, int event);
198 int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
199 struct snd_kcontrol *kcontrol, int event);
201 irqreturn_t wm_adsp2_bus_error(int irq, void *data);
202 irqreturn_t wm_halo_bus_error(int irq, void *data);
203 irqreturn_t wm_halo_wdt_expire(int irq, void *data);
205 int wm_adsp_event(struct snd_soc_dapm_widget *w,
206 struct snd_kcontrol *kcontrol, int event);
208 int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq);
210 int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol,
211 struct snd_ctl_elem_value *ucontrol);
212 int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol);
214 int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
215 struct snd_ctl_elem_value *ucontrol);
216 int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
217 struct snd_ctl_elem_value *ucontrol);
219 int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream);
220 int wm_adsp_compr_free(struct snd_soc_component *component,
221 struct snd_compr_stream *stream);
222 int wm_adsp_compr_set_params(struct snd_soc_component *component,
223 struct snd_compr_stream *stream,
224 struct snd_compr_params *params);
225 int wm_adsp_compr_get_caps(struct snd_soc_component *component,
226 struct snd_compr_stream *stream,
227 struct snd_compr_caps *caps);
228 int wm_adsp_compr_trigger(struct snd_soc_component *component,
229 struct snd_compr_stream *stream, int cmd);
230 int wm_adsp_compr_handle_irq(struct wm_adsp *dsp);
231 int wm_adsp_compr_pointer(struct snd_soc_component *component,
232 struct snd_compr_stream *stream,
233 struct snd_compr_tstamp *tstamp);
234 int wm_adsp_compr_copy(struct snd_soc_component *component,
235 struct snd_compr_stream *stream,
236 char __user *buf, size_t count);
237 int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
238 unsigned int alg, void *buf, size_t len);
239 int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
240 unsigned int alg, void *buf, size_t len);
242 struct cs_dsp_client_ops {
243 int (*control_add)(struct cs_dsp_coeff_ctl *ctl);
244 void (*control_remove)(struct cs_dsp_coeff_ctl *ctl);
245 int (*post_run)(struct cs_dsp *dsp);
246 void (*post_stop)(struct cs_dsp *dsp);
247 void (*watchdog_expired)(struct cs_dsp *dsp);