2 * arizona.h - Wolfson Arizona class device shared support
4 * Copyright 2012 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #ifndef _ASOC_ARIZONA_H
14 #define _ASOC_ARIZONA_H
16 #include <linux/completion.h>
18 #include <sound/soc.h>
22 #define ARIZONA_CLK_SYSCLK 1
23 #define ARIZONA_CLK_ASYNCCLK 2
24 #define ARIZONA_CLK_OPCLK 3
25 #define ARIZONA_CLK_ASYNC_OPCLK 4
27 #define ARIZONA_CLK_SRC_MCLK1 0x0
28 #define ARIZONA_CLK_SRC_MCLK2 0x1
29 #define ARIZONA_CLK_SRC_FLL1 0x4
30 #define ARIZONA_CLK_SRC_FLL2 0x5
31 #define ARIZONA_CLK_SRC_AIF1BCLK 0x8
32 #define ARIZONA_CLK_SRC_AIF2BCLK 0x9
33 #define ARIZONA_CLK_SRC_AIF3BCLK 0xa
35 #define ARIZONA_FLL_SRC_NONE -1
36 #define ARIZONA_FLL_SRC_MCLK1 0
37 #define ARIZONA_FLL_SRC_MCLK2 1
38 #define ARIZONA_FLL_SRC_SLIMCLK 3
39 #define ARIZONA_FLL_SRC_FLL1 4
40 #define ARIZONA_FLL_SRC_FLL2 5
41 #define ARIZONA_FLL_SRC_AIF1BCLK 8
42 #define ARIZONA_FLL_SRC_AIF2BCLK 9
43 #define ARIZONA_FLL_SRC_AIF3BCLK 10
44 #define ARIZONA_FLL_SRC_AIF1LRCLK 12
45 #define ARIZONA_FLL_SRC_AIF2LRCLK 13
46 #define ARIZONA_FLL_SRC_AIF3LRCLK 14
48 #define ARIZONA_MIXER_VOL_MASK 0x00FE
49 #define ARIZONA_MIXER_VOL_SHIFT 1
50 #define ARIZONA_MIXER_VOL_WIDTH 7
52 #define ARIZONA_CLK_6MHZ 0
53 #define ARIZONA_CLK_12MHZ 1
54 #define ARIZONA_CLK_24MHZ 2
55 #define ARIZONA_CLK_49MHZ 3
56 #define ARIZONA_CLK_73MHZ 4
57 #define ARIZONA_CLK_98MHZ 5
58 #define ARIZONA_CLK_147MHZ 6
60 #define ARIZONA_MAX_DAI 8
61 #define ARIZONA_MAX_ADSP 4
63 #define ARIZONA_DVFS_SR1_RQ 0x001
64 #define ARIZONA_DVFS_ADSP1_RQ 0x100
69 struct arizona_dai_priv {
74 struct wm_adsp adsp[ARIZONA_MAX_ADSP];
75 struct arizona *arizona;
78 struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
81 unsigned int in_pending;
83 unsigned int out_up_pending;
84 unsigned int out_up_delay;
85 unsigned int out_down_pending;
86 unsigned int out_down_delay;
88 unsigned int spk_ena:2;
89 unsigned int spk_ena_pending:1;
91 unsigned int dvfs_reqs;
92 struct mutex dvfs_lock;
96 #define ARIZONA_NUM_MIXER_INPUTS 104
98 extern const unsigned int arizona_mixer_tlv[];
99 extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
100 extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
102 #define ARIZONA_GAINMUX_CONTROLS(name, base) \
103 SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \
104 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
107 #define ARIZONA_MIXER_CONTROLS(name, base) \
108 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
109 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
110 arizona_mixer_tlv), \
111 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
112 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
113 arizona_mixer_tlv), \
114 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
115 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
116 arizona_mixer_tlv), \
117 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
118 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
121 #define ARIZONA_MUX_ENUM_DECL(name, reg) \
122 SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
123 name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
125 #define ARIZONA_MUX_CTL_DECL(name) \
126 const struct snd_kcontrol_new name##_mux = \
127 SOC_DAPM_ENUM("Route", name##_enum)
129 #define ARIZONA_MUX_ENUMS(name, base_reg) \
130 static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
131 static ARIZONA_MUX_CTL_DECL(name)
133 #define ARIZONA_MIXER_ENUMS(name, base_reg) \
134 ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
135 ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
136 ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
137 ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
139 #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
140 ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
141 ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
142 ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
143 ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
144 ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
145 ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
147 #define ARIZONA_MUX(name, ctrl) \
148 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
150 #define ARIZONA_MUX_WIDGETS(name, name_str) \
151 ARIZONA_MUX(name_str " Input", &name##_mux)
153 #define ARIZONA_MIXER_WIDGETS(name, name_str) \
154 ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
155 ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
156 ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
157 ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
158 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
160 #define ARIZONA_DSP_WIDGETS(name, name_str) \
161 ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
162 ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
163 ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
164 ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
165 ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
166 ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
167 ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
168 ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
170 #define ARIZONA_MUX_ROUTES(widget, name) \
171 { widget, NULL, name " Input" }, \
172 ARIZONA_MIXER_INPUT_ROUTES(name " Input")
174 #define ARIZONA_MIXER_ROUTES(widget, name) \
175 { widget, NULL, name " Mixer" }, \
176 { name " Mixer", NULL, name " Input 1" }, \
177 { name " Mixer", NULL, name " Input 2" }, \
178 { name " Mixer", NULL, name " Input 3" }, \
179 { name " Mixer", NULL, name " Input 4" }, \
180 ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
181 ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
182 ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
183 ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
185 #define ARIZONA_DSP_ROUTES(name) \
186 { name, NULL, name " Preloader"}, \
187 { name " Preloader", NULL, name " Aux 1" }, \
188 { name " Preloader", NULL, name " Aux 2" }, \
189 { name " Preloader", NULL, name " Aux 3" }, \
190 { name " Preloader", NULL, name " Aux 4" }, \
191 { name " Preloader", NULL, name " Aux 5" }, \
192 { name " Preloader", NULL, name " Aux 6" }, \
193 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
194 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
195 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
196 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
197 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
198 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
199 ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \
200 ARIZONA_MIXER_ROUTES(name " Preloader", name "R")
202 #define ARIZONA_EQ_CONTROL(xname, xbase) \
203 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
204 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
205 .put = arizona_eq_coeff_put, .private_value = \
206 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
207 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
209 #define ARIZONA_LHPF_CONTROL(xname, xbase) \
210 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
211 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
212 .put = arizona_lhpf_coeff_put, .private_value = \
213 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
216 #define ARIZONA_RATE_ENUM_SIZE 4
217 #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
219 extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
220 extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
221 extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
222 extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
224 extern const struct soc_enum arizona_isrc_fsl[];
225 extern const struct soc_enum arizona_isrc_fsh[];
226 extern const struct soc_enum arizona_asrc_rate1;
228 extern const struct soc_enum arizona_in_vi_ramp;
229 extern const struct soc_enum arizona_in_vd_ramp;
231 extern const struct soc_enum arizona_out_vi_ramp;
232 extern const struct soc_enum arizona_out_vd_ramp;
234 extern const struct soc_enum arizona_lhpf1_mode;
235 extern const struct soc_enum arizona_lhpf2_mode;
236 extern const struct soc_enum arizona_lhpf3_mode;
237 extern const struct soc_enum arizona_lhpf4_mode;
239 extern const struct soc_enum arizona_ng_hold;
240 extern const struct soc_enum arizona_in_hpf_cut_enum;
241 extern const struct soc_enum arizona_in_dmic_osr[];
243 extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
245 extern const struct soc_enum arizona_anc_input_src[];
246 extern const struct soc_enum arizona_anc_ng_enum;
247 extern const struct soc_enum arizona_output_anc_src[];
249 extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
250 struct snd_kcontrol *kcontrol,
252 extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
253 struct snd_kcontrol *kcontrol,
255 extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
256 struct snd_kcontrol *kcontrol,
258 extern int arizona_anc_ev(struct snd_soc_dapm_widget *w,
259 struct snd_kcontrol *kcontrol,
262 extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol);
264 extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol);
267 extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
268 int source, unsigned int freq, int dir);
270 extern const struct snd_soc_dai_ops arizona_dai_ops;
271 extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
273 #define ARIZONA_FLL_NAME_LEN 20
276 struct arizona *arizona;
279 unsigned int vco_mult;
283 unsigned int sync_freq;
285 unsigned int ref_freq;
287 char lock_name[ARIZONA_FLL_NAME_LEN];
288 char clock_ok_name[ARIZONA_FLL_NAME_LEN];
291 extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
292 extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
293 extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
294 struct snd_kcontrol *kcontrol, int event);
295 extern void arizona_init_dvfs(struct arizona_priv *priv);
297 extern int arizona_init_fll(struct arizona *arizona, int id, int base,
298 int lock_irq, int ok_irq, struct arizona_fll *fll);
299 extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
300 unsigned int Fref, unsigned int Fout);
301 extern int arizona_set_fll(struct arizona_fll *fll, int source,
302 unsigned int Fref, unsigned int Fout);
304 extern int arizona_init_spk(struct snd_soc_codec *codec);
305 extern int arizona_init_gpio(struct snd_soc_codec *codec);
306 extern int arizona_init_mono(struct snd_soc_codec *codec);
308 extern int arizona_init_dai(struct arizona_priv *priv, int dai);
310 int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
313 extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);
315 extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);