ASoC: wm_adsp: Separate wm_adsp specifics in cs_dsp_client_ops
[linux-2.6-microblaze.git] / sound / soc / codecs / wm_adsp.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * wm_adsp.h  --  Wolfson ADSP support
4  *
5  * Copyright 2012 Wolfson Microelectronics plc
6  *
7  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8  */
9
10 #ifndef __WM_ADSP_H
11 #define __WM_ADSP_H
12
13 #include <sound/soc.h>
14 #include <sound/soc-dapm.h>
15 #include <sound/compress_driver.h>
16
17 #include "wmfw.h"
18
19 /* Return values for wm_adsp_compr_handle_irq */
20 #define WM_ADSP_COMPR_OK                 0
21 #define WM_ADSP_COMPR_VOICE_TRIGGER      1
22
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)
39
40 struct cs_dsp_region {
41         int type;
42         unsigned int base;
43 };
44
45 struct cs_dsp_alg_region {
46         struct list_head list;
47         unsigned int alg;
48         int type;
49         unsigned int base;
50 };
51
52 struct wm_adsp_compr;
53 struct wm_adsp_compr_buf;
54 struct cs_dsp_ops;
55 struct cs_dsp_client_ops;
56
57 struct cs_dsp_coeff_ctl {
58         const char *fw_name;
59         /* Subname is needed to match with firmware */
60         const char *subname;
61         unsigned int subname_len;
62         struct cs_dsp_alg_region alg_region;
63         struct cs_dsp *dsp;
64         unsigned int enabled:1;
65         struct list_head list;
66         void *cache;
67         unsigned int offset;
68         size_t len;
69         unsigned int set:1;
70         unsigned int flags;
71         unsigned int type;
72
73         void *priv;
74 };
75
76 struct cs_dsp {
77         const char *name;
78         int rev;
79         int num;
80         int type;
81         struct device *dev;
82         struct regmap *regmap;
83
84         const struct cs_dsp_ops *ops;
85         const struct cs_dsp_client_ops *client_ops;
86
87         unsigned int base;
88         unsigned int base_sysinfo;
89         unsigned int sysclk_reg;
90         unsigned int sysclk_mask;
91         unsigned int sysclk_shift;
92
93         struct list_head alg_regions;
94
95         const char *fw_name;
96         unsigned int fw_id;
97         unsigned int fw_id_version;
98         unsigned int fw_vendor_id;
99
100         const struct cs_dsp_region *mem;
101         int num_mems;
102
103         int fw_ver;
104
105         bool booted;
106         bool running;
107
108         struct list_head ctl_list;
109
110         struct mutex pwr_lock;
111
112         unsigned int lock_regions;
113
114 #ifdef CONFIG_DEBUG_FS
115         struct dentry *debugfs_root;
116         char *wmfw_file_name;
117         char *bin_file_name;
118 #endif
119 };
120
121 struct wm_adsp {
122         struct cs_dsp cs_dsp;
123         const char *part;
124         const char *fwf_name;
125         struct snd_soc_component *component;
126
127         unsigned int sys_config_size;
128
129         int fw;
130
131         struct work_struct boot_work;
132
133         bool preloaded;
134         bool fatal_error;
135
136         struct list_head compr_list;
137         struct list_head buffer_list;
138 };
139
140 struct cs_dsp_ops {
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,
144                                     unsigned int pos,
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);
149
150         void (*show_fw_status)(struct cs_dsp *dsp);
151         void (*stop_watchdog)(struct cs_dsp *dsp);
152
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);
156
157         int (*enable_core)(struct cs_dsp *dsp);
158         void (*disable_core)(struct cs_dsp *dsp);
159
160         int (*start_core)(struct cs_dsp *dsp);
161         void (*stop_core)(struct cs_dsp *dsp);
162 };
163
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)
167
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)
171
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 }
181
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)
185
186 extern const struct soc_enum wm_adsp_fw_enum[];
187
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);
194
195 int wm_adsp1_event(struct snd_soc_dapm_widget *w,
196                    struct snd_kcontrol *kcontrol, int event);
197
198 int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
199                         struct snd_kcontrol *kcontrol, int event);
200
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);
204
205 int wm_adsp_event(struct snd_soc_dapm_widget *w,
206                   struct snd_kcontrol *kcontrol, int event);
207
208 int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq);
209
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);
218
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);
241
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);
248 };
249
250 #endif