]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame_incremental - sound/soc/codecs/arizona.h
Merge tag 'nfc-next-4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo...
[mirror_ubuntu-hirsute-kernel.git] / sound / soc / codecs / arizona.h
... / ...
CommitLineData
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
18#include <sound/soc.h>
19
20#include "wm_adsp.h"
21
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
26
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
34
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
47
48#define ARIZONA_MIXER_VOL_MASK 0x00FE
49#define ARIZONA_MIXER_VOL_SHIFT 1
50#define ARIZONA_MIXER_VOL_WIDTH 7
51
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
59
60#define ARIZONA_MAX_DAI 10
61#define ARIZONA_MAX_ADSP 4
62
63#define ARIZONA_DVFS_SR1_RQ 0x001
64#define ARIZONA_DVFS_ADSP1_RQ 0x100
65
66struct arizona;
67struct wm_adsp;
68
69struct arizona_dai_priv {
70 int clk;
71
72 struct snd_pcm_hw_constraint_list constraint;
73};
74
75struct arizona_priv {
76 struct wm_adsp adsp[ARIZONA_MAX_ADSP];
77 struct arizona *arizona;
78 int sysclk;
79 int asyncclk;
80 struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
81
82 int num_inputs;
83 unsigned int in_pending;
84
85 unsigned int out_up_pending;
86 unsigned int out_up_delay;
87 unsigned int out_down_pending;
88 unsigned int out_down_delay;
89
90 unsigned int spk_ena:2;
91 unsigned int spk_ena_pending:1;
92
93 unsigned int dvfs_reqs;
94 struct mutex dvfs_lock;
95 bool dvfs_cached;
96};
97
98#define ARIZONA_NUM_MIXER_INPUTS 104
99
100extern const unsigned int arizona_mixer_tlv[];
101extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
102extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
103
104#define ARIZONA_GAINMUX_CONTROLS(name, base) \
105 SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \
106 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
107 arizona_mixer_tlv)
108
109#define ARIZONA_MIXER_CONTROLS(name, base) \
110 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
111 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
112 arizona_mixer_tlv), \
113 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
114 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
115 arizona_mixer_tlv), \
116 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
117 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
118 arizona_mixer_tlv), \
119 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
120 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
121 arizona_mixer_tlv)
122
123#define ARIZONA_MUX_ENUM_DECL(name, reg) \
124 SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
125 name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
126
127#define ARIZONA_MUX_CTL_DECL(name) \
128 const struct snd_kcontrol_new name##_mux = \
129 SOC_DAPM_ENUM("Route", name##_enum)
130
131#define ARIZONA_MUX_ENUMS(name, base_reg) \
132 static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
133 static ARIZONA_MUX_CTL_DECL(name)
134
135#define ARIZONA_MIXER_ENUMS(name, base_reg) \
136 ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
137 ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
138 ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
139 ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
140
141#define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
142 ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
143 ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
144 ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
145 ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
146 ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
147 ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
148
149#define ARIZONA_MUX(name, ctrl) \
150 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
151
152#define ARIZONA_MUX_WIDGETS(name, name_str) \
153 ARIZONA_MUX(name_str " Input", &name##_mux)
154
155#define ARIZONA_MIXER_WIDGETS(name, name_str) \
156 ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
157 ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
158 ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
159 ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
160 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
161
162#define ARIZONA_DSP_WIDGETS(name, name_str) \
163 ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
164 ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
165 ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
166 ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
167 ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
168 ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
169 ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
170 ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
171
172#define ARIZONA_MUX_ROUTES(widget, name) \
173 { widget, NULL, name " Input" }, \
174 ARIZONA_MIXER_INPUT_ROUTES(name " Input")
175
176#define ARIZONA_MIXER_ROUTES(widget, name) \
177 { widget, NULL, name " Mixer" }, \
178 { name " Mixer", NULL, name " Input 1" }, \
179 { name " Mixer", NULL, name " Input 2" }, \
180 { name " Mixer", NULL, name " Input 3" }, \
181 { name " Mixer", NULL, name " Input 4" }, \
182 ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
183 ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
184 ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
185 ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
186
187#define ARIZONA_DSP_ROUTES(name) \
188 { name, NULL, name " Preloader"}, \
189 { name " Preloader", NULL, name " Aux 1" }, \
190 { name " Preloader", NULL, name " Aux 2" }, \
191 { name " Preloader", NULL, name " Aux 3" }, \
192 { name " Preloader", NULL, name " Aux 4" }, \
193 { name " Preloader", NULL, name " Aux 5" }, \
194 { name " Preloader", NULL, name " Aux 6" }, \
195 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
196 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
197 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
198 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
199 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
200 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
201 ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \
202 ARIZONA_MIXER_ROUTES(name " Preloader", name "R")
203
204#define ARIZONA_EQ_CONTROL(xname, xbase) \
205{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
206 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
207 .put = arizona_eq_coeff_put, .private_value = \
208 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
209 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
210
211#define ARIZONA_LHPF_CONTROL(xname, xbase) \
212{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
213 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
214 .put = arizona_lhpf_coeff_put, .private_value = \
215 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
216 .num_regs = 1 }) }
217
218#define ARIZONA_RATE_ENUM_SIZE 4
219#define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
220
221extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
222extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
223extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
224extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
225
226extern const struct soc_enum arizona_isrc_fsl[];
227extern const struct soc_enum arizona_isrc_fsh[];
228extern const struct soc_enum arizona_asrc_rate1;
229
230extern const struct soc_enum arizona_in_vi_ramp;
231extern const struct soc_enum arizona_in_vd_ramp;
232
233extern const struct soc_enum arizona_out_vi_ramp;
234extern const struct soc_enum arizona_out_vd_ramp;
235
236extern const struct soc_enum arizona_lhpf1_mode;
237extern const struct soc_enum arizona_lhpf2_mode;
238extern const struct soc_enum arizona_lhpf3_mode;
239extern const struct soc_enum arizona_lhpf4_mode;
240
241extern const struct soc_enum arizona_ng_hold;
242extern const struct soc_enum arizona_in_hpf_cut_enum;
243extern const struct soc_enum arizona_in_dmic_osr[];
244
245extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
246
247extern const struct soc_enum arizona_anc_input_src[];
248extern const struct soc_enum arizona_anc_ng_enum;
249extern const struct soc_enum arizona_output_anc_src[];
250
251extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
252 struct snd_kcontrol *kcontrol,
253 int event);
254extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
255 struct snd_kcontrol *kcontrol,
256 int event);
257extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
258 struct snd_kcontrol *kcontrol,
259 int event);
260extern int arizona_anc_ev(struct snd_soc_dapm_widget *w,
261 struct snd_kcontrol *kcontrol,
262 int event);
263
264extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol);
266extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_value *ucontrol);
268
269extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
270 int source, unsigned int freq, int dir);
271
272extern const struct snd_soc_dai_ops arizona_dai_ops;
273extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
274
275#define ARIZONA_FLL_NAME_LEN 20
276
277struct arizona_fll {
278 struct arizona *arizona;
279 int id;
280 unsigned int base;
281 unsigned int vco_mult;
282
283 unsigned int fout;
284 int sync_src;
285 unsigned int sync_freq;
286 int ref_src;
287 unsigned int ref_freq;
288
289 char lock_name[ARIZONA_FLL_NAME_LEN];
290 char clock_ok_name[ARIZONA_FLL_NAME_LEN];
291};
292
293extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
294extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
295extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
296 struct snd_kcontrol *kcontrol, int event);
297extern void arizona_init_dvfs(struct arizona_priv *priv);
298
299extern int arizona_init_fll(struct arizona *arizona, int id, int base,
300 int lock_irq, int ok_irq, struct arizona_fll *fll);
301extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
302 unsigned int Fref, unsigned int Fout);
303extern int arizona_set_fll(struct arizona_fll *fll, int source,
304 unsigned int Fref, unsigned int Fout);
305
306extern int arizona_init_spk(struct snd_soc_codec *codec);
307extern int arizona_init_gpio(struct snd_soc_codec *codec);
308extern int arizona_init_mono(struct snd_soc_codec *codec);
309
310extern int arizona_free_spk(struct snd_soc_codec *codec);
311
312extern int arizona_init_dai(struct arizona_priv *priv, int dai);
313
314int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
315 bool diff);
316
317extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);
318
319extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
320#endif