xref: /linux/sound/soc/codecs/arizona.h (revision e5e95a7639ed5f7dc3e404858ad7910de5fa2057)
1 /* SPDX-License-Identifier: GPL-2.0-only */
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>
8  */
9 
10 #ifndef _ASOC_ARIZONA_H
11 #define _ASOC_ARIZONA_H
12 
13 #include <linux/completion.h>
14 #include <linux/notifier.h>
15 #include <linux/mfd/arizona/core.h>
16 
17 #include <sound/soc.h>
18 
19 #include "wm_adsp.h"
20 
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
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 
34 #define ARIZONA_FLL_SRC_NONE      -1
35 #define ARIZONA_FLL_SRC_MCLK1      0
36 #define ARIZONA_FLL_SRC_MCLK2      1
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
46 
47 #define ARIZONA_MIXER_VOL_MASK             0x00FE
48 #define ARIZONA_MIXER_VOL_SHIFT                 1
49 #define ARIZONA_MIXER_VOL_WIDTH                 7
50 
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 
59 #define ARIZONA_MAX_DAI  10
60 #define ARIZONA_MAX_ADSP 4
61 
62 #define ARIZONA_DVFS_SR1_RQ	0x001
63 #define ARIZONA_DVFS_ADSP1_RQ	0x100
64 
65 /* Notifier events */
66 #define ARIZONA_NOTIFY_VOICE_TRIGGER   0x1
67 
68 struct wm_adsp;
69 
70 struct arizona_dai_priv {
71 	int clk;
72 
73 	struct snd_pcm_hw_constraint_list constraint;
74 };
75 
76 struct arizona_priv {
77 	struct wm_adsp adsp[ARIZONA_MAX_ADSP];
78 	struct arizona *arizona;
79 	int sysclk;
80 	int asyncclk;
81 	struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
82 
83 	int num_inputs;
84 	unsigned int in_pending;
85 
86 	unsigned int out_up_pending;
87 	unsigned int out_up_delay;
88 	unsigned int out_down_pending;
89 	unsigned int out_down_delay;
90 
91 	unsigned int dvfs_reqs;
92 	struct mutex dvfs_lock;
93 	bool dvfs_cached;
94 };
95 
96 struct arizona_voice_trigger_info {
97 	int core;
98 };
99 
100 #define ARIZONA_NUM_MIXER_INPUTS 104
101 
102 extern const unsigned int arizona_mixer_tlv[];
103 extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
104 extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
105 
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 
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) \
126 	SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
127 		name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
128 
129 #define ARIZONA_MUX_CTL_DECL(name) \
130 	const struct snd_kcontrol_new name##_mux =	\
131 		SOC_DAPM_ENUM("Route", name##_enum)
132 
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 
137 #define ARIZONA_MIXER_ENUMS(name, base_reg) \
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)
142 
143 #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
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)
150 
151 #define ARIZONA_MUX(name, ctrl) \
152 	SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
153 
154 #define ARIZONA_MUX_WIDGETS(name, name_str) \
155 	ARIZONA_MUX(name_str " Input", &name##_mux)
156 
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 
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 
174 #define ARIZONA_MUX_ROUTES(widget, name) \
175 	{ widget, NULL, name " Input" }, \
176 	ARIZONA_MIXER_INPUT_ROUTES(name " Input")
177 
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 
189 #define ARIZONA_DSP_ROUTES(name) \
190 	{ name, NULL, name " Preloader"}, \
191 	{ name " Preloader", NULL, "SYSCLK" }, \
192 	{ name " Preload", NULL, name " Preloader"}, \
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" }, \
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"), \
205 	ARIZONA_MIXER_ROUTES(name, name "L"), \
206 	ARIZONA_MIXER_ROUTES(name, name "R")
207 
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 
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 
222 #define ARIZONA_RATE_ENUM_SIZE 4
223 #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
224 
225 extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
226 extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
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];
229 
230 extern const struct soc_enum arizona_isrc_fsl[];
231 extern const struct soc_enum arizona_isrc_fsh[];
232 extern const struct soc_enum arizona_asrc_rate1;
233 
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 
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 
245 extern const struct soc_enum arizona_ng_hold;
246 extern const struct soc_enum arizona_in_hpf_cut_enum;
247 extern const struct soc_enum arizona_in_dmic_osr[];
248 
249 extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
250 
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 
255 extern const struct snd_kcontrol_new arizona_voice_trigger_switch[];
256 
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);
273 int arizona_set_sysclk(struct snd_soc_component *component, int clk_id, int source,
274 		       unsigned int freq, int dir);
275 
276 extern const struct snd_soc_dai_ops arizona_dai_ops;
277 extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
278 
279 #define ARIZONA_FLL_NAME_LEN 20
280 
281 struct arizona_fll {
282 	struct arizona *arizona;
283 	int id;
284 	unsigned int base;
285 	unsigned int vco_mult;
286 
287 	unsigned int fout;
288 	int sync_src;
289 	unsigned int sync_freq;
290 	int ref_src;
291 	unsigned int ref_freq;
292 
293 	char lock_name[ARIZONA_FLL_NAME_LEN];
294 	char clock_ok_name[ARIZONA_FLL_NAME_LEN];
295 };
296 
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);
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,
306 			   unsigned int Fref, unsigned int Fout);
307 int arizona_set_fll(struct arizona_fll *fll, int source,
308 		    unsigned int Fref, unsigned int Fout);
309 
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);
313 
314 int arizona_init_common(struct arizona *arizona);
315 int arizona_init_vol_limit(struct arizona *arizona);
316 
317 int arizona_init_spk_irqs(struct arizona *arizona);
318 int arizona_free_spk_irqs(struct arizona *arizona);
319 
320 int arizona_init_dai(struct arizona_priv *priv, int dai);
321 
322 int arizona_set_output_mode(struct snd_soc_component *component, int output,
323 			    bool diff);
324 
325 bool arizona_input_analog(struct snd_soc_component *component, int shift);
326 
327 const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
328 
329 static inline int arizona_register_notifier(struct snd_soc_component *component,
330 					    struct notifier_block *nb,
331 					    int (*notify)
332 					    (struct notifier_block *nb,
333 					    unsigned long action, void *data))
334 {
335 	struct arizona_priv *priv = snd_soc_component_get_drvdata(component);
336 	struct arizona *arizona = priv->arizona;
337 
338 	nb->notifier_call = notify;
339 
340 	return blocking_notifier_chain_register(&arizona->notifier, nb);
341 }
342 
343 static inline int arizona_unregister_notifier(struct snd_soc_component *component,
344 					      struct notifier_block *nb)
345 {
346 	struct arizona_priv *priv = snd_soc_component_get_drvdata(component);
347 	struct arizona *arizona = priv->arizona;
348 
349 	return blocking_notifier_chain_unregister(&arizona->notifier, nb);
350 }
351 
352 int arizona_of_get_audio_pdata(struct arizona *arizona);
353 
354 #endif
355