1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arizona.h - Wolfson Arizona class device shared support
5 * Copyright 2012 Wolfson Microelectronics plc
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 #ifndef _ASOC_ARIZONA_H
11 #define _ASOC_ARIZONA_H
13 #include <linux/completion.h>
14 #include <linux/notifier.h>
15 #include <linux/mfd/arizona/core.h>
17 #include <sound/soc.h>
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
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
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
47 #define ARIZONA_MIXER_VOL_MASK 0x00FE
48 #define ARIZONA_MIXER_VOL_SHIFT 1
49 #define ARIZONA_MIXER_VOL_WIDTH 7
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
59 #define ARIZONA_MAX_DAI 10
60 #define ARIZONA_MAX_ADSP 4
62 #define ARIZONA_DVFS_SR1_RQ 0x001
63 #define ARIZONA_DVFS_ADSP1_RQ 0x100
66 #define ARIZONA_NOTIFY_VOICE_TRIGGER 0x1
70 struct arizona_dai_priv
{
73 struct snd_pcm_hw_constraint_list constraint
;
77 struct wm_adsp adsp
[ARIZONA_MAX_ADSP
];
78 struct arizona
*arizona
;
81 struct arizona_dai_priv dai
[ARIZONA_MAX_DAI
];
84 unsigned int in_pending
;
86 unsigned int out_up_pending
;
87 unsigned int out_up_delay
;
88 unsigned int out_down_pending
;
89 unsigned int out_down_delay
;
91 unsigned int dvfs_reqs
;
92 struct mutex dvfs_lock
;
96 struct arizona_voice_trigger_info
{
100 #define ARIZONA_NUM_MIXER_INPUTS 104
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
];
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, \
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, \
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)
129 #define ARIZONA_MUX_CTL_DECL(name) \
130 const struct snd_kcontrol_new name##_mux = \
131 SOC_DAPM_ENUM("Route", name##_enum)
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)
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)
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)
151 #define ARIZONA_MUX(name, ctrl) \
152 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
154 #define ARIZONA_MUX_WIDGETS(name, name_str) \
155 ARIZONA_MUX(name_str " Input", &name##_mux)
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)
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)
174 #define ARIZONA_MUX_ROUTES(widget, name) \
175 { widget, NULL, name " Input" }, \
176 ARIZONA_MIXER_INPUT_ROUTES(name " Input")
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")
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")
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 }) }
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, \
222 #define ARIZONA_RATE_ENUM_SIZE 4
223 #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
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
];
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
;
234 extern const struct soc_enum arizona_in_vi_ramp
;
235 extern const struct soc_enum arizona_in_vd_ramp
;
237 extern const struct soc_enum arizona_out_vi_ramp
;
238 extern const struct soc_enum arizona_out_vd_ramp
;
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
;
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
[];
249 extern const struct snd_kcontrol_new arizona_adsp2_rate_controls
[];
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
[];
255 extern const struct snd_kcontrol_new arizona_voice_trigger_switch
[];
257 int arizona_in_ev(struct snd_soc_dapm_widget
*w
, struct snd_kcontrol
*kcontrol
,
259 int arizona_out_ev(struct snd_soc_dapm_widget
*w
, struct snd_kcontrol
*kcontrol
,
261 int arizona_hp_ev(struct snd_soc_dapm_widget
*w
, struct snd_kcontrol
*kcontrol
,
263 int arizona_anc_ev(struct snd_soc_dapm_widget
*w
, struct snd_kcontrol
*kcontrol
,
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
);
271 int arizona_clk_ev(struct snd_soc_dapm_widget
*w
, struct snd_kcontrol
*kcontrol
,
273 int arizona_set_sysclk(struct snd_soc_component
*component
, int clk_id
, int source
,
274 unsigned int freq
, int dir
);
276 extern const struct snd_soc_dai_ops arizona_dai_ops
;
277 extern const struct snd_soc_dai_ops arizona_simple_dai_ops
;
279 #define ARIZONA_FLL_NAME_LEN 20
282 struct arizona
*arizona
;
285 unsigned int vco_mult
;
289 unsigned int sync_freq
;
291 unsigned int ref_freq
;
293 char lock_name
[ARIZONA_FLL_NAME_LEN
];
294 char clock_ok_name
[ARIZONA_FLL_NAME_LEN
];
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
);
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
);
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
);
314 int arizona_init_common(struct arizona
*arizona
);
315 int arizona_init_vol_limit(struct arizona
*arizona
);
317 int arizona_init_spk_irqs(struct arizona
*arizona
);
318 int arizona_free_spk_irqs(struct arizona
*arizona
);
320 int arizona_init_dai(struct arizona_priv
*priv
, int dai
);
322 int arizona_set_output_mode(struct snd_soc_component
*component
, int output
,
325 bool arizona_input_analog(struct snd_soc_component
*component
, int shift
);
327 const char *arizona_sample_rate_val_to_name(unsigned int rate_val
);
329 static inline int arizona_register_notifier(struct snd_soc_component
*component
,
330 struct notifier_block
*nb
,
332 (struct notifier_block
*nb
,
333 unsigned long action
, void *data
))
335 struct arizona_priv
*priv
= snd_soc_component_get_drvdata(component
);
336 struct arizona
*arizona
= priv
->arizona
;
338 nb
->notifier_call
= notify
;
340 return blocking_notifier_chain_register(&arizona
->notifier
, nb
);
343 static inline int arizona_unregister_notifier(struct snd_soc_component
*component
,
344 struct notifier_block
*nb
)
346 struct arizona_priv
*priv
= snd_soc_component_get_drvdata(component
);
347 struct arizona
*arizona
= priv
->arizona
;
349 return blocking_notifier_chain_unregister(&arizona
->notifier
, nb
);
352 int arizona_of_get_audio_pdata(struct arizona
*arizona
);