xref: /openbmc/linux/sound/soc/codecs/arizona.h (revision 8730046c)
1 /*
2  * arizona.h - Wolfson Arizona class device shared support
3  *
4  * Copyright 2012 Wolfson Microelectronics plc
5  *
6  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 
13 #ifndef _ASOC_ARIZONA_H
14 #define _ASOC_ARIZONA_H
15 
16 #include <linux/completion.h>
17 #include <linux/notifier.h>
18 #include <linux/mfd/arizona/core.h>
19 
20 #include <sound/soc.h>
21 
22 #include "wm_adsp.h"
23 
24 #define ARIZONA_CLK_SYSCLK         1
25 #define ARIZONA_CLK_ASYNCCLK       2
26 #define ARIZONA_CLK_OPCLK          3
27 #define ARIZONA_CLK_ASYNC_OPCLK    4
28 
29 #define ARIZONA_CLK_SRC_MCLK1    0x0
30 #define ARIZONA_CLK_SRC_MCLK2    0x1
31 #define ARIZONA_CLK_SRC_FLL1     0x4
32 #define ARIZONA_CLK_SRC_FLL2     0x5
33 #define ARIZONA_CLK_SRC_AIF1BCLK 0x8
34 #define ARIZONA_CLK_SRC_AIF2BCLK 0x9
35 #define ARIZONA_CLK_SRC_AIF3BCLK 0xa
36 
37 #define ARIZONA_FLL_SRC_NONE      -1
38 #define ARIZONA_FLL_SRC_MCLK1      0
39 #define ARIZONA_FLL_SRC_MCLK2      1
40 #define ARIZONA_FLL_SRC_SLIMCLK    3
41 #define ARIZONA_FLL_SRC_FLL1       4
42 #define ARIZONA_FLL_SRC_FLL2       5
43 #define ARIZONA_FLL_SRC_AIF1BCLK   8
44 #define ARIZONA_FLL_SRC_AIF2BCLK   9
45 #define ARIZONA_FLL_SRC_AIF3BCLK  10
46 #define ARIZONA_FLL_SRC_AIF1LRCLK 12
47 #define ARIZONA_FLL_SRC_AIF2LRCLK 13
48 #define ARIZONA_FLL_SRC_AIF3LRCLK 14
49 
50 #define ARIZONA_MIXER_VOL_MASK             0x00FE
51 #define ARIZONA_MIXER_VOL_SHIFT                 1
52 #define ARIZONA_MIXER_VOL_WIDTH                 7
53 
54 #define ARIZONA_CLK_6MHZ   0
55 #define ARIZONA_CLK_12MHZ  1
56 #define ARIZONA_CLK_24MHZ  2
57 #define ARIZONA_CLK_49MHZ  3
58 #define ARIZONA_CLK_73MHZ  4
59 #define ARIZONA_CLK_98MHZ  5
60 #define ARIZONA_CLK_147MHZ 6
61 
62 #define ARIZONA_MAX_DAI  10
63 #define ARIZONA_MAX_ADSP 4
64 
65 #define ARIZONA_DVFS_SR1_RQ	0x001
66 #define ARIZONA_DVFS_ADSP1_RQ	0x100
67 
68 /* Notifier events */
69 #define ARIZONA_NOTIFY_VOICE_TRIGGER   0x1
70 
71 struct wm_adsp;
72 
73 struct arizona_dai_priv {
74 	int clk;
75 
76 	struct snd_pcm_hw_constraint_list constraint;
77 };
78 
79 struct arizona_priv {
80 	struct wm_adsp adsp[ARIZONA_MAX_ADSP];
81 	struct arizona *arizona;
82 	int sysclk;
83 	int asyncclk;
84 	struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
85 
86 	int num_inputs;
87 	unsigned int in_pending;
88 
89 	unsigned int out_up_pending;
90 	unsigned int out_up_delay;
91 	unsigned int out_down_pending;
92 	unsigned int out_down_delay;
93 
94 	unsigned int dvfs_reqs;
95 	struct mutex dvfs_lock;
96 	bool dvfs_cached;
97 };
98 
99 struct arizona_voice_trigger_info {
100 	int core;
101 };
102 
103 #define ARIZONA_NUM_MIXER_INPUTS 104
104 
105 extern const unsigned int arizona_mixer_tlv[];
106 extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
107 extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
108 
109 #define ARIZONA_GAINMUX_CONTROLS(name, base) \
110 	SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1,		\
111 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
112 			     arizona_mixer_tlv)
113 
114 #define ARIZONA_MIXER_CONTROLS(name, base) \
115 	SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1,		\
116 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
117 			     arizona_mixer_tlv),			\
118 	SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3,		\
119 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
120 			     arizona_mixer_tlv),			\
121 	SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5,		\
122 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
123 			     arizona_mixer_tlv),			\
124 	SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7,		\
125 			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
126 			     arizona_mixer_tlv)
127 
128 #define ARIZONA_MUX_ENUM_DECL(name, reg) \
129 	SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
130 		name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
131 
132 #define ARIZONA_MUX_CTL_DECL(name) \
133 	const struct snd_kcontrol_new name##_mux =	\
134 		SOC_DAPM_ENUM("Route", name##_enum)
135 
136 #define ARIZONA_MUX_ENUMS(name, base_reg) \
137 	static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg);      \
138 	static ARIZONA_MUX_CTL_DECL(name)
139 
140 #define ARIZONA_MIXER_ENUMS(name, base_reg) \
141 	ARIZONA_MUX_ENUMS(name##_in1, base_reg);     \
142 	ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
143 	ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
144 	ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
145 
146 #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
147 	ARIZONA_MUX_ENUMS(name##_aux1, base_reg);	\
148 	ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8);	\
149 	ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16);	\
150 	ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24);	\
151 	ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32);	\
152 	ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
153 
154 #define ARIZONA_MUX(name, ctrl) \
155 	SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
156 
157 #define ARIZONA_MUX_WIDGETS(name, name_str) \
158 	ARIZONA_MUX(name_str " Input", &name##_mux)
159 
160 #define ARIZONA_MIXER_WIDGETS(name, name_str)	\
161 	ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
162 	ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
163 	ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
164 	ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
165 	SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
166 
167 #define ARIZONA_DSP_WIDGETS(name, name_str) \
168 	ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
169 	ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
170 	ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
171 	ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
172 	ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
173 	ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
174 	ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
175 	ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
176 
177 #define ARIZONA_MUX_ROUTES(widget, name) \
178 	{ widget, NULL, name " Input" }, \
179 	ARIZONA_MIXER_INPUT_ROUTES(name " Input")
180 
181 #define ARIZONA_MIXER_ROUTES(widget, name) \
182 	{ widget, NULL, name " Mixer" },         \
183 	{ name " Mixer", NULL, name " Input 1" }, \
184 	{ name " Mixer", NULL, name " Input 2" }, \
185 	{ name " Mixer", NULL, name " Input 3" }, \
186 	{ name " Mixer", NULL, name " Input 4" }, \
187 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
188 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
189 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
190 	ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
191 
192 #define ARIZONA_DSP_ROUTES(name) \
193 	{ name, NULL, name " Preloader"}, \
194 	{ name " Preloader", NULL, "SYSCLK" }, \
195 	{ name, NULL, name " Aux 1" }, \
196 	{ name, NULL, name " Aux 2" }, \
197 	{ name, NULL, name " Aux 3" }, \
198 	{ name, NULL, name " Aux 4" }, \
199 	{ name, NULL, name " Aux 5" }, \
200 	{ name, NULL, name " Aux 6" }, \
201 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
202 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
203 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
204 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
205 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
206 	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
207 	ARIZONA_MIXER_ROUTES(name, name "L"), \
208 	ARIZONA_MIXER_ROUTES(name, name "R")
209 
210 #define ARIZONA_EQ_CONTROL(xname, xbase)                      \
211 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
212 	.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
213 	.put = arizona_eq_coeff_put, .private_value =         \
214 	((unsigned long)&(struct soc_bytes) { .base = xbase,  \
215 	 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
216 
217 #define ARIZONA_LHPF_CONTROL(xname, xbase)                    \
218 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
219 	.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
220 	.put = arizona_lhpf_coeff_put, .private_value =       \
221 	((unsigned long)&(struct soc_bytes) { .base = xbase,  \
222 	 .num_regs = 1 }) }
223 
224 #define ARIZONA_RATE_ENUM_SIZE 4
225 #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
226 
227 extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
228 extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
229 extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
230 extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
231 
232 extern const struct soc_enum arizona_isrc_fsl[];
233 extern const struct soc_enum arizona_isrc_fsh[];
234 extern const struct soc_enum arizona_asrc_rate1;
235 
236 extern const struct soc_enum arizona_in_vi_ramp;
237 extern const struct soc_enum arizona_in_vd_ramp;
238 
239 extern const struct soc_enum arizona_out_vi_ramp;
240 extern const struct soc_enum arizona_out_vd_ramp;
241 
242 extern const struct soc_enum arizona_lhpf1_mode;
243 extern const struct soc_enum arizona_lhpf2_mode;
244 extern const struct soc_enum arizona_lhpf3_mode;
245 extern const struct soc_enum arizona_lhpf4_mode;
246 
247 extern const struct soc_enum arizona_ng_hold;
248 extern const struct soc_enum arizona_in_hpf_cut_enum;
249 extern const struct soc_enum arizona_in_dmic_osr[];
250 
251 extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
252 
253 extern const struct soc_enum arizona_anc_input_src[];
254 extern const struct soc_enum arizona_anc_ng_enum;
255 extern const struct soc_enum arizona_output_anc_src[];
256 
257 extern const struct snd_kcontrol_new arizona_voice_trigger_switch[];
258 
259 int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
260 		  int event);
261 int arizona_out_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
262 		   int event);
263 int arizona_hp_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
264 		  int event);
265 int arizona_anc_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
266 		   int event);
267 
268 int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
269 			 struct snd_ctl_elem_value *ucontrol);
270 int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
271 			   struct snd_ctl_elem_value *ucontrol);
272 
273 int arizona_clk_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
274 		   int event);
275 int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id, int source,
276 		       unsigned int freq, int dir);
277 
278 extern const struct snd_soc_dai_ops arizona_dai_ops;
279 extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
280 
281 #define ARIZONA_FLL_NAME_LEN 20
282 
283 struct arizona_fll {
284 	struct arizona *arizona;
285 	int id;
286 	unsigned int base;
287 	unsigned int vco_mult;
288 
289 	unsigned int fout;
290 	int sync_src;
291 	unsigned int sync_freq;
292 	int ref_src;
293 	unsigned int ref_freq;
294 
295 	char lock_name[ARIZONA_FLL_NAME_LEN];
296 	char clock_ok_name[ARIZONA_FLL_NAME_LEN];
297 };
298 
299 int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
300 int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
301 int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
302 			   struct snd_kcontrol *kcontrol, int event);
303 void arizona_init_dvfs(struct arizona_priv *priv);
304 
305 int arizona_init_fll(struct arizona *arizona, int id, int base,
306 		     int lock_irq, int ok_irq, struct arizona_fll *fll);
307 int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
308 			   unsigned int Fref, unsigned int Fout);
309 int arizona_set_fll(struct arizona_fll *fll, int source,
310 		    unsigned int Fref, unsigned int Fout);
311 
312 int arizona_init_spk(struct snd_soc_codec *codec);
313 int arizona_init_gpio(struct snd_soc_codec *codec);
314 int arizona_init_mono(struct snd_soc_codec *codec);
315 int arizona_init_notifiers(struct snd_soc_codec *codec);
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_codec *codec, int output,
323 			    bool diff);
324 
325 bool arizona_input_analog(struct snd_soc_codec *codec, 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_codec *codec,
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_codec_get_drvdata(codec);
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_codec *codec,
344 					      struct notifier_block *nb)
345 {
346 	struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
347 	struct arizona *arizona = priv->arizona;
348 
349 	return blocking_notifier_chain_unregister(&arizona->notifier, nb);
350 }
351 
352 #endif
353