]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
07ed873e MB |
2 | /* |
3 | * arizona.h - Wolfson Arizona class device shared support | |
4 | * | |
5 | * Copyright 2012 Wolfson Microelectronics plc | |
6 | * | |
7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | |
07ed873e MB |
8 | */ |
9 | ||
10 | #ifndef _ASOC_ARIZONA_H | |
11 | #define _ASOC_ARIZONA_H | |
12 | ||
13 | #include <linux/completion.h> | |
d3d5c905 CK |
14 | #include <linux/notifier.h> |
15 | #include <linux/mfd/arizona/core.h> | |
07ed873e MB |
16 | |
17 | #include <sound/soc.h> | |
18 | ||
0b09df66 MB |
19 | #include "wm_adsp.h" |
20 | ||
cbd840da MB |
21 | #define ARIZONA_CLK_SYSCLK 1 |
22 | #define ARIZONA_CLK_ASYNCCLK 2 | |
23 | #define ARIZONA_CLK_OPCLK 3 | |
24 | #define ARIZONA_CLK_ASYNC_OPCLK 4 | |
07ed873e MB |
25 | |
26 | #define ARIZONA_CLK_SRC_MCLK1 0x0 | |
27 | #define ARIZONA_CLK_SRC_MCLK2 0x1 | |
28 | #define ARIZONA_CLK_SRC_FLL1 0x4 | |
29 | #define ARIZONA_CLK_SRC_FLL2 0x5 | |
30 | #define ARIZONA_CLK_SRC_AIF1BCLK 0x8 | |
31 | #define ARIZONA_CLK_SRC_AIF2BCLK 0x9 | |
32 | #define ARIZONA_CLK_SRC_AIF3BCLK 0xa | |
33 | ||
f3f1163d | 34 | #define ARIZONA_FLL_SRC_NONE -1 |
07ed873e MB |
35 | #define ARIZONA_FLL_SRC_MCLK1 0 |
36 | #define ARIZONA_FLL_SRC_MCLK2 1 | |
a8c02db0 MB |
37 | #define ARIZONA_FLL_SRC_SLIMCLK 3 |
38 | #define ARIZONA_FLL_SRC_FLL1 4 | |
39 | #define ARIZONA_FLL_SRC_FLL2 5 | |
40 | #define ARIZONA_FLL_SRC_AIF1BCLK 8 | |
41 | #define ARIZONA_FLL_SRC_AIF2BCLK 9 | |
42 | #define ARIZONA_FLL_SRC_AIF3BCLK 10 | |
43 | #define ARIZONA_FLL_SRC_AIF1LRCLK 12 | |
44 | #define ARIZONA_FLL_SRC_AIF2LRCLK 13 | |
45 | #define ARIZONA_FLL_SRC_AIF3LRCLK 14 | |
07ed873e MB |
46 | |
47 | #define ARIZONA_MIXER_VOL_MASK 0x00FE | |
48 | #define ARIZONA_MIXER_VOL_SHIFT 1 | |
49 | #define ARIZONA_MIXER_VOL_WIDTH 7 | |
50 | ||
3f341f74 MB |
51 | #define ARIZONA_CLK_6MHZ 0 |
52 | #define ARIZONA_CLK_12MHZ 1 | |
53 | #define ARIZONA_CLK_24MHZ 2 | |
54 | #define ARIZONA_CLK_49MHZ 3 | |
55 | #define ARIZONA_CLK_73MHZ 4 | |
56 | #define ARIZONA_CLK_98MHZ 5 | |
57 | #define ARIZONA_CLK_147MHZ 6 | |
58 | ||
31889507 | 59 | #define ARIZONA_MAX_DAI 10 |
0b09df66 | 60 | #define ARIZONA_MAX_ADSP 4 |
5b2eec3f | 61 | |
346d9683 RF |
62 | #define ARIZONA_DVFS_SR1_RQ 0x001 |
63 | #define ARIZONA_DVFS_ADSP1_RQ 0x100 | |
64 | ||
7baa7e24 CK |
65 | /* Notifier events */ |
66 | #define ARIZONA_NOTIFY_VOICE_TRIGGER 0x1 | |
67 | ||
0b09df66 | 68 | struct wm_adsp; |
07ed873e | 69 | |
5b2eec3f MB |
70 | struct arizona_dai_priv { |
71 | int clk; | |
d81221ff CK |
72 | |
73 | struct snd_pcm_hw_constraint_list constraint; | |
5b2eec3f MB |
74 | }; |
75 | ||
07ed873e | 76 | struct arizona_priv { |
0b09df66 | 77 | struct wm_adsp adsp[ARIZONA_MAX_ADSP]; |
07ed873e MB |
78 | struct arizona *arizona; |
79 | int sysclk; | |
80 | int asyncclk; | |
5b2eec3f | 81 | struct arizona_dai_priv dai[ARIZONA_MAX_DAI]; |
ddbce97c MB |
82 | |
83 | int num_inputs; | |
84 | unsigned int in_pending; | |
56447e13 | 85 | |
e1ae5fba CK |
86 | unsigned int out_up_pending; |
87 | unsigned int out_up_delay; | |
054e1b48 CK |
88 | unsigned int out_down_pending; |
89 | unsigned int out_down_delay; | |
90 | ||
346d9683 RF |
91 | unsigned int dvfs_reqs; |
92 | struct mutex dvfs_lock; | |
93 | bool dvfs_cached; | |
07ed873e MB |
94 | }; |
95 | ||
546ad3d0 CK |
96 | struct arizona_voice_trigger_info { |
97 | int core; | |
98 | }; | |
99 | ||
6ebbce0a | 100 | #define ARIZONA_NUM_MIXER_INPUTS 104 |
07ed873e MB |
101 | |
102 | extern const unsigned int arizona_mixer_tlv[]; | |
141bc6a6 CK |
103 | extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS]; |
104 | extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS]; | |
07ed873e | 105 | |
50e6168f RF |
106 | #define ARIZONA_GAINMUX_CONTROLS(name, base) \ |
107 | SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \ | |
108 | ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ | |
109 | arizona_mixer_tlv) | |
110 | ||
07ed873e MB |
111 | #define ARIZONA_MIXER_CONTROLS(name, base) \ |
112 | SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \ | |
113 | ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ | |
114 | arizona_mixer_tlv), \ | |
115 | SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \ | |
116 | ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ | |
117 | arizona_mixer_tlv), \ | |
118 | SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \ | |
119 | ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ | |
120 | arizona_mixer_tlv), \ | |
121 | SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \ | |
122 | ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ | |
123 | arizona_mixer_tlv) | |
124 | ||
125 | #define ARIZONA_MUX_ENUM_DECL(name, reg) \ | |
21a37e39 CK |
126 | SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \ |
127 | name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values) | |
07ed873e MB |
128 | |
129 | #define ARIZONA_MUX_CTL_DECL(name) \ | |
130 | const struct snd_kcontrol_new name##_mux = \ | |
355e3a08 | 131 | SOC_DAPM_ENUM("Route", name##_enum) |
07ed873e | 132 | |
17bd09e5 CK |
133 | #define ARIZONA_MUX_ENUMS(name, base_reg) \ |
134 | static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \ | |
135 | static ARIZONA_MUX_CTL_DECL(name) | |
136 | ||
07ed873e | 137 | #define ARIZONA_MIXER_ENUMS(name, base_reg) \ |
17bd09e5 CK |
138 | ARIZONA_MUX_ENUMS(name##_in1, base_reg); \ |
139 | ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \ | |
140 | ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \ | |
141 | ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6) | |
07ed873e | 142 | |
0b09df66 | 143 | #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \ |
17bd09e5 CK |
144 | ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \ |
145 | ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \ | |
146 | ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \ | |
147 | ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \ | |
148 | ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \ | |
149 | ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40) | |
0b09df66 | 150 | |
07ed873e | 151 | #define ARIZONA_MUX(name, ctrl) \ |
355e3a08 | 152 | SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl) |
07ed873e | 153 | |
17bd09e5 CK |
154 | #define ARIZONA_MUX_WIDGETS(name, name_str) \ |
155 | ARIZONA_MUX(name_str " Input", &name##_mux) | |
156 | ||
07ed873e MB |
157 | #define ARIZONA_MIXER_WIDGETS(name, name_str) \ |
158 | ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \ | |
159 | ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \ | |
160 | ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \ | |
161 | ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \ | |
162 | SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0) | |
163 | ||
0b09df66 MB |
164 | #define ARIZONA_DSP_WIDGETS(name, name_str) \ |
165 | ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \ | |
166 | ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \ | |
167 | ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \ | |
168 | ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \ | |
169 | ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \ | |
170 | ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \ | |
171 | ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \ | |
172 | ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux) | |
173 | ||
e7edb273 CK |
174 | #define ARIZONA_MUX_ROUTES(widget, name) \ |
175 | { widget, NULL, name " Input" }, \ | |
17bd09e5 CK |
176 | ARIZONA_MIXER_INPUT_ROUTES(name " Input") |
177 | ||
07ed873e MB |
178 | #define ARIZONA_MIXER_ROUTES(widget, name) \ |
179 | { widget, NULL, name " Mixer" }, \ | |
180 | { name " Mixer", NULL, name " Input 1" }, \ | |
181 | { name " Mixer", NULL, name " Input 2" }, \ | |
182 | { name " Mixer", NULL, name " Input 3" }, \ | |
183 | { name " Mixer", NULL, name " Input 4" }, \ | |
184 | ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \ | |
185 | ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \ | |
186 | ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \ | |
187 | ARIZONA_MIXER_INPUT_ROUTES(name " Input 4") | |
188 | ||
0b09df66 | 189 | #define ARIZONA_DSP_ROUTES(name) \ |
12db5edd | 190 | { name, NULL, name " Preloader"}, \ |
3577357a | 191 | { name " Preloader", NULL, "SYSCLK" }, \ |
af813a6f | 192 | { name " Preload", NULL, name " Preloader"}, \ |
5ca7e170 CK |
193 | { name, NULL, name " Aux 1" }, \ |
194 | { name, NULL, name " Aux 2" }, \ | |
195 | { name, NULL, name " Aux 3" }, \ | |
196 | { name, NULL, name " Aux 4" }, \ | |
197 | { name, NULL, name " Aux 5" }, \ | |
198 | { name, NULL, name " Aux 6" }, \ | |
0b09df66 MB |
199 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \ |
200 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \ | |
201 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \ | |
202 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \ | |
203 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \ | |
204 | ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \ | |
5ca7e170 CK |
205 | ARIZONA_MIXER_ROUTES(name, name "L"), \ |
206 | ARIZONA_MIXER_ROUTES(name, name "R") | |
0b09df66 | 207 | |
c05d9a8c CK |
208 | #define ARIZONA_EQ_CONTROL(xname, xbase) \ |
209 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | |
210 | .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ | |
211 | .put = arizona_eq_coeff_put, .private_value = \ | |
212 | ((unsigned long)&(struct soc_bytes) { .base = xbase, \ | |
213 | .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) } | |
214 | ||
5f8e671a CK |
215 | #define ARIZONA_LHPF_CONTROL(xname, xbase) \ |
216 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | |
217 | .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ | |
218 | .put = arizona_lhpf_coeff_put, .private_value = \ | |
219 | ((unsigned long)&(struct soc_bytes) { .base = xbase, \ | |
220 | .num_regs = 1 }) } | |
221 | ||
dc91428a | 222 | #define ARIZONA_RATE_ENUM_SIZE 4 |
6ebbce0a RF |
223 | #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14 |
224 | ||
141bc6a6 CK |
225 | extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE]; |
226 | extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE]; | |
6ebbce0a RF |
227 | extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE]; |
228 | extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE]; | |
dc91428a MB |
229 | |
230 | extern const struct soc_enum arizona_isrc_fsl[]; | |
fbedc8cb | 231 | extern const struct soc_enum arizona_isrc_fsh[]; |
56d37d85 | 232 | extern const struct soc_enum arizona_asrc_rate1; |
dc91428a | 233 | |
e853a00f MB |
234 | extern const struct soc_enum arizona_in_vi_ramp; |
235 | extern const struct soc_enum arizona_in_vd_ramp; | |
236 | ||
237 | extern const struct soc_enum arizona_out_vi_ramp; | |
238 | extern const struct soc_enum arizona_out_vd_ramp; | |
239 | ||
07ed873e MB |
240 | extern const struct soc_enum arizona_lhpf1_mode; |
241 | extern const struct soc_enum arizona_lhpf2_mode; | |
242 | extern const struct soc_enum arizona_lhpf3_mode; | |
243 | extern const struct soc_enum arizona_lhpf4_mode; | |
244 | ||
845571cc | 245 | extern const struct soc_enum arizona_ng_hold; |
254dc326 | 246 | extern const struct soc_enum arizona_in_hpf_cut_enum; |
c7f38435 | 247 | extern const struct soc_enum arizona_in_dmic_osr[]; |
845571cc | 248 | |
336d0442 RF |
249 | extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[]; |
250 | ||
d190106d CK |
251 | extern const struct soc_enum arizona_anc_input_src[]; |
252 | extern const struct soc_enum arizona_anc_ng_enum; | |
253 | extern const struct soc_enum arizona_output_anc_src[]; | |
254 | ||
97126ce8 CK |
255 | extern const struct snd_kcontrol_new arizona_voice_trigger_switch[]; |
256 | ||
73950715 CK |
257 | int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, |
258 | int event); | |
259 | int arizona_out_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, | |
260 | int event); | |
261 | int arizona_hp_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, | |
262 | int event); | |
263 | int arizona_anc_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, | |
264 | int event); | |
265 | ||
266 | int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol, | |
267 | struct snd_ctl_elem_value *ucontrol); | |
268 | int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol, | |
269 | struct snd_ctl_elem_value *ucontrol); | |
270 | ||
271 | int arizona_clk_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, | |
272 | int event); | |
0fe1daa6 | 273 | int arizona_set_sysclk(struct snd_soc_component *component, int clk_id, int source, |
73950715 | 274 | unsigned int freq, int dir); |
07ed873e MB |
275 | |
276 | extern const struct snd_soc_dai_ops arizona_dai_ops; | |
bd1dd885 | 277 | extern const struct snd_soc_dai_ops arizona_simple_dai_ops; |
07ed873e MB |
278 | |
279 | #define ARIZONA_FLL_NAME_LEN 20 | |
280 | ||
281 | struct arizona_fll { | |
282 | struct arizona *arizona; | |
283 | int id; | |
284 | unsigned int base; | |
2b4d39fc | 285 | unsigned int vco_mult; |
07ed873e | 286 | |
de1e6eed | 287 | unsigned int fout; |
9e359c64 CK |
288 | int sync_src; |
289 | unsigned int sync_freq; | |
19b34bdc CK |
290 | int ref_src; |
291 | unsigned int ref_freq; | |
292 | ||
07ed873e MB |
293 | char lock_name[ARIZONA_FLL_NAME_LEN]; |
294 | char clock_ok_name[ARIZONA_FLL_NAME_LEN]; | |
295 | }; | |
296 | ||
0fe1daa6 KM |
297 | int arizona_dvfs_up(struct snd_soc_component *component, unsigned int flags); |
298 | int arizona_dvfs_down(struct snd_soc_component *component, unsigned int flags); | |
73950715 CK |
299 | int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w, |
300 | struct snd_kcontrol *kcontrol, int event); | |
301 | void arizona_init_dvfs(struct arizona_priv *priv); | |
302 | ||
303 | int arizona_init_fll(struct arizona *arizona, int id, int base, | |
304 | int lock_irq, int ok_irq, struct arizona_fll *fll); | |
305 | int arizona_set_fll_refclk(struct arizona_fll *fll, int source, | |
07ed873e | 306 | unsigned int Fref, unsigned int Fout); |
73950715 CK |
307 | int arizona_set_fll(struct arizona_fll *fll, int source, |
308 | unsigned int Fref, unsigned int Fout); | |
07ed873e | 309 | |
0fe1daa6 KM |
310 | int arizona_init_spk(struct snd_soc_component *component); |
311 | int arizona_init_gpio(struct snd_soc_component *component); | |
312 | int arizona_init_mono(struct snd_soc_component *component); | |
9e3f9f36 CK |
313 | |
314 | int arizona_init_common(struct arizona *arizona); | |
85e7dd3f | 315 | int arizona_init_vol_limit(struct arizona *arizona); |
56447e13 | 316 | |
73950715 CK |
317 | int arizona_init_spk_irqs(struct arizona *arizona); |
318 | int arizona_free_spk_irqs(struct arizona *arizona); | |
54dca701 | 319 | |
73950715 | 320 | int arizona_init_dai(struct arizona_priv *priv, int dai); |
5b2eec3f | 321 | |
0fe1daa6 | 322 | int arizona_set_output_mode(struct snd_soc_component *component, int output, |
bc9ab6d3 MB |
323 | bool diff); |
324 | ||
0fe1daa6 | 325 | bool arizona_input_analog(struct snd_soc_component *component, int shift); |
002b083b | 326 | |
73950715 | 327 | const char *arizona_sample_rate_val_to_name(unsigned int rate_val); |
2230c49f | 328 | |
0fe1daa6 | 329 | static inline int arizona_register_notifier(struct snd_soc_component *component, |
d3d5c905 CK |
330 | struct notifier_block *nb, |
331 | int (*notify) | |
332 | (struct notifier_block *nb, | |
333 | unsigned long action, void *data)) | |
334 | { | |
0fe1daa6 | 335 | struct arizona_priv *priv = snd_soc_component_get_drvdata(component); |
d3d5c905 CK |
336 | struct arizona *arizona = priv->arizona; |
337 | ||
338 | nb->notifier_call = notify; | |
339 | ||
340 | return blocking_notifier_chain_register(&arizona->notifier, nb); | |
341 | } | |
342 | ||
0fe1daa6 | 343 | static inline int arizona_unregister_notifier(struct snd_soc_component *component, |
d3d5c905 CK |
344 | struct notifier_block *nb) |
345 | { | |
0fe1daa6 | 346 | struct arizona_priv *priv = snd_soc_component_get_drvdata(component); |
d3d5c905 CK |
347 | struct arizona *arizona = priv->arizona; |
348 | ||
349 | return blocking_notifier_chain_unregister(&arizona->notifier, nb); | |
350 | } | |
2230c49f | 351 | |
0a229b15 CK |
352 | int arizona_of_get_audio_pdata(struct arizona *arizona); |
353 | ||
07ed873e | 354 | #endif |