blob: 850aa338ba293e2dca4b47f81fc93662e238bd50 [file] [log] [blame]
Mark Brown07ed8732012-06-18 21:08:44 +01001/*
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
Mark Brown0b09df62012-10-11 11:31:35 +090020#include "wm_adsp.h"
21
Mark Browncbd840d2012-08-08 17:52:44 +010022#define ARIZONA_CLK_SYSCLK 1
23#define ARIZONA_CLK_ASYNCCLK 2
24#define ARIZONA_CLK_OPCLK 3
25#define ARIZONA_CLK_ASYNC_OPCLK 4
Mark Brown07ed8732012-06-18 21:08:44 +010026
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
Charles Keepaxf3f11632013-02-20 17:28:41 +000035#define ARIZONA_FLL_SRC_NONE -1
Mark Brown07ed8732012-06-18 21:08:44 +010036#define ARIZONA_FLL_SRC_MCLK1 0
37#define ARIZONA_FLL_SRC_MCLK2 1
Mark Browna8c02db2012-12-18 14:05:01 +000038#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
Mark Brown07ed8732012-06-18 21:08:44 +010047
48#define ARIZONA_MIXER_VOL_MASK 0x00FE
49#define ARIZONA_MIXER_VOL_SHIFT 1
50#define ARIZONA_MIXER_VOL_WIDTH 7
51
Mark Brown3f341f72013-03-08 15:22:29 +080052#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
Charles Keepax31889502016-01-21 17:53:00 +000060#define ARIZONA_MAX_DAI 10
Mark Brown0b09df62012-10-11 11:31:35 +090061#define ARIZONA_MAX_ADSP 4
Mark Brown5b2eec32012-07-04 17:32:05 +010062
Richard Fitzgerald346d9682015-06-02 11:53:33 +010063#define ARIZONA_DVFS_SR1_RQ 0x001
64#define ARIZONA_DVFS_ADSP1_RQ 0x100
65
Charles Keepax7baa7e22016-05-13 16:45:19 +010066/* Notifier events */
67#define ARIZONA_NOTIFY_VOICE_TRIGGER 0x1
68
Mark Brown07ed8732012-06-18 21:08:44 +010069struct arizona;
Mark Brown0b09df62012-10-11 11:31:35 +090070struct wm_adsp;
Mark Brown07ed8732012-06-18 21:08:44 +010071
Mark Brown5b2eec32012-07-04 17:32:05 +010072struct arizona_dai_priv {
73 int clk;
Charles Keepaxd81221f2016-02-04 16:29:01 +000074
75 struct snd_pcm_hw_constraint_list constraint;
Mark Brown5b2eec32012-07-04 17:32:05 +010076};
77
Mark Brown07ed8732012-06-18 21:08:44 +010078struct arizona_priv {
Mark Brown0b09df62012-10-11 11:31:35 +090079 struct wm_adsp adsp[ARIZONA_MAX_ADSP];
Mark Brown07ed8732012-06-18 21:08:44 +010080 struct arizona *arizona;
81 int sysclk;
82 int asyncclk;
Mark Brown5b2eec32012-07-04 17:32:05 +010083 struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
Mark Brownddbce972013-02-15 17:27:22 +000084
85 int num_inputs;
86 unsigned int in_pending;
Mark Brown56447e12013-01-10 14:45:58 +000087
Charles Keepaxe1ae5fb2015-01-20 16:31:51 +000088 unsigned int out_up_pending;
89 unsigned int out_up_delay;
Charles Keepax054e1b42015-01-20 16:31:50 +000090 unsigned int out_down_pending;
91 unsigned int out_down_delay;
92
Richard Fitzgerald346d9682015-06-02 11:53:33 +010093 unsigned int dvfs_reqs;
94 struct mutex dvfs_lock;
95 bool dvfs_cached;
Mark Brown07ed8732012-06-18 21:08:44 +010096};
97
Charles Keepax546ad3d2016-05-31 12:44:17 +010098struct arizona_voice_trigger_info {
99 int core;
100};
101
Richard Fitzgerald6ebbce02015-09-28 14:01:09 +0100102#define ARIZONA_NUM_MIXER_INPUTS 104
Mark Brown07ed8732012-06-18 21:08:44 +0100103
104extern const unsigned int arizona_mixer_tlv[];
Charles Keepax141bc6a2015-12-03 18:15:06 +0000105extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
106extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
Mark Brown07ed8732012-06-18 21:08:44 +0100107
Richard Fitzgerald50e61682015-09-28 14:01:08 +0100108#define ARIZONA_GAINMUX_CONTROLS(name, base) \
109 SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \
110 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
111 arizona_mixer_tlv)
112
Mark Brown07ed8732012-06-18 21:08:44 +0100113#define ARIZONA_MIXER_CONTROLS(name, base) \
114 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
115 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
116 arizona_mixer_tlv), \
117 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
118 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
119 arizona_mixer_tlv), \
120 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
121 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
122 arizona_mixer_tlv), \
123 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
124 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
125 arizona_mixer_tlv)
126
127#define ARIZONA_MUX_ENUM_DECL(name, reg) \
Charles Keepax21a37e32015-05-01 12:37:27 +0100128 SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
129 name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
Mark Brown07ed8732012-06-18 21:08:44 +0100130
131#define ARIZONA_MUX_CTL_DECL(name) \
132 const struct snd_kcontrol_new name##_mux = \
Lars-Peter Clausen355e3a02014-04-14 21:30:58 +0200133 SOC_DAPM_ENUM("Route", name##_enum)
Mark Brown07ed8732012-06-18 21:08:44 +0100134
Charles Keepax17bd09e2012-11-13 16:40:32 +0000135#define ARIZONA_MUX_ENUMS(name, base_reg) \
136 static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
137 static ARIZONA_MUX_CTL_DECL(name)
138
Mark Brown07ed8732012-06-18 21:08:44 +0100139#define ARIZONA_MIXER_ENUMS(name, base_reg) \
Charles Keepax17bd09e2012-11-13 16:40:32 +0000140 ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
141 ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
142 ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
143 ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
Mark Brown07ed8732012-06-18 21:08:44 +0100144
Mark Brown0b09df62012-10-11 11:31:35 +0900145#define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
Charles Keepax17bd09e2012-11-13 16:40:32 +0000146 ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
147 ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
148 ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
149 ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
150 ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
151 ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
Mark Brown0b09df62012-10-11 11:31:35 +0900152
Mark Brown07ed8732012-06-18 21:08:44 +0100153#define ARIZONA_MUX(name, ctrl) \
Lars-Peter Clausen355e3a02014-04-14 21:30:58 +0200154 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
Mark Brown07ed8732012-06-18 21:08:44 +0100155
Charles Keepax17bd09e2012-11-13 16:40:32 +0000156#define ARIZONA_MUX_WIDGETS(name, name_str) \
157 ARIZONA_MUX(name_str " Input", &name##_mux)
158
Mark Brown07ed8732012-06-18 21:08:44 +0100159#define ARIZONA_MIXER_WIDGETS(name, name_str) \
160 ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
161 ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
162 ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
163 ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
164 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
165
Mark Brown0b09df62012-10-11 11:31:35 +0900166#define ARIZONA_DSP_WIDGETS(name, name_str) \
167 ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
168 ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
169 ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
170 ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
171 ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
172 ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
173 ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
174 ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
175
Charles Keepaxe7edb272013-08-12 11:33:32 +0100176#define ARIZONA_MUX_ROUTES(widget, name) \
177 { widget, NULL, name " Input" }, \
Charles Keepax17bd09e2012-11-13 16:40:32 +0000178 ARIZONA_MIXER_INPUT_ROUTES(name " Input")
179
Mark Brown07ed8732012-06-18 21:08:44 +0100180#define ARIZONA_MIXER_ROUTES(widget, name) \
181 { widget, NULL, name " Mixer" }, \
182 { name " Mixer", NULL, name " Input 1" }, \
183 { name " Mixer", NULL, name " Input 2" }, \
184 { name " Mixer", NULL, name " Input 3" }, \
185 { name " Mixer", NULL, name " Input 4" }, \
186 ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
187 ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
188 ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
189 ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
190
Mark Brown0b09df62012-10-11 11:31:35 +0900191#define ARIZONA_DSP_ROUTES(name) \
Charles Keepax12db5ed2014-01-08 17:42:19 +0000192 { name, NULL, name " Preloader"}, \
Charles Keepax35773572016-09-20 13:52:30 +0100193 { name " Preloader", NULL, "SYSCLK" }, \
Charles Keepax5ca7e172016-09-20 13:52:31 +0100194 { name, NULL, name " Aux 1" }, \
195 { name, NULL, name " Aux 2" }, \
196 { name, NULL, name " Aux 3" }, \
197 { name, NULL, name " Aux 4" }, \
198 { name, NULL, name " Aux 5" }, \
199 { name, NULL, name " Aux 6" }, \
Mark Brown0b09df62012-10-11 11:31:35 +0900200 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
201 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
202 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
203 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
204 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
205 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
Charles Keepax5ca7e172016-09-20 13:52:31 +0100206 ARIZONA_MIXER_ROUTES(name, name "L"), \
207 ARIZONA_MIXER_ROUTES(name, name "R")
Mark Brown0b09df62012-10-11 11:31:35 +0900208
Charles Keepaxc05d9a82015-06-25 09:35:11 +0100209#define ARIZONA_EQ_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_eq_coeff_put, .private_value = \
213 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
214 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
215
Charles Keepax5f8e6712015-06-25 09:35:12 +0100216#define ARIZONA_LHPF_CONTROL(xname, xbase) \
217{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
218 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
219 .put = arizona_lhpf_coeff_put, .private_value = \
220 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
221 .num_regs = 1 }) }
222
Mark Browndc914282013-02-18 19:09:23 +0000223#define ARIZONA_RATE_ENUM_SIZE 4
Richard Fitzgerald6ebbce02015-09-28 14:01:09 +0100224#define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
225
Charles Keepax141bc6a2015-12-03 18:15:06 +0000226extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
227extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
Richard Fitzgerald6ebbce02015-09-28 14:01:09 +0100228extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
229extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
Mark Browndc914282013-02-18 19:09:23 +0000230
231extern const struct soc_enum arizona_isrc_fsl[];
Charles Keepaxfbedc8c2013-12-19 09:30:12 +0000232extern const struct soc_enum arizona_isrc_fsh[];
Charles Keepax56d37d82013-12-19 09:30:13 +0000233extern const struct soc_enum arizona_asrc_rate1;
Mark Browndc914282013-02-18 19:09:23 +0000234
Mark Browne853a002012-12-09 12:25:52 +0900235extern const struct soc_enum arizona_in_vi_ramp;
236extern const struct soc_enum arizona_in_vd_ramp;
237
238extern const struct soc_enum arizona_out_vi_ramp;
239extern const struct soc_enum arizona_out_vd_ramp;
240
Mark Brown07ed8732012-06-18 21:08:44 +0100241extern const struct soc_enum arizona_lhpf1_mode;
242extern const struct soc_enum arizona_lhpf2_mode;
243extern const struct soc_enum arizona_lhpf3_mode;
244extern const struct soc_enum arizona_lhpf4_mode;
245
Mark Brown845571c2012-12-18 13:47:57 +0000246extern const struct soc_enum arizona_ng_hold;
Charles Keepax254dc322013-11-19 16:04:03 +0000247extern const struct soc_enum arizona_in_hpf_cut_enum;
Charles Keepaxc7f38432013-08-06 17:03:55 +0100248extern const struct soc_enum arizona_in_dmic_osr[];
Mark Brown845571c2012-12-18 13:47:57 +0000249
Richard Fitzgerald336d0442015-06-18 13:43:19 +0100250extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
251
Charles Keepaxd1901062015-11-19 16:11:10 +0000252extern const struct soc_enum arizona_anc_input_src[];
253extern const struct soc_enum arizona_anc_ng_enum;
254extern const struct soc_enum arizona_output_anc_src[];
255
Charles Keepax97126ce2016-05-13 16:45:16 +0100256extern const struct snd_kcontrol_new arizona_voice_trigger_switch[];
257
Mark Brown07ed8732012-06-18 21:08:44 +0100258extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
259 struct snd_kcontrol *kcontrol,
260 int event);
261extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
262 struct snd_kcontrol *kcontrol,
263 int event);
Mark Brownf607e312013-02-22 18:36:53 +0000264extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
265 struct snd_kcontrol *kcontrol,
266 int event);
Charles Keepaxd1901062015-11-19 16:11:10 +0000267extern int arizona_anc_ev(struct snd_soc_dapm_widget *w,
268 struct snd_kcontrol *kcontrol,
269 int event);
Mark Brown07ed8732012-06-18 21:08:44 +0100270
Charles Keepaxc05d9a82015-06-25 09:35:11 +0100271extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol);
Charles Keepax5f8e6712015-06-25 09:35:12 +0100273extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_value *ucontrol);
Charles Keepaxc05d9a82015-06-25 09:35:11 +0100275
Mark Brown07ed8732012-06-18 21:08:44 +0100276extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
277 int source, unsigned int freq, int dir);
278
279extern const struct snd_soc_dai_ops arizona_dai_ops;
Mark Brownbd1dd882013-05-17 13:29:03 +0100280extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
Mark Brown07ed8732012-06-18 21:08:44 +0100281
282#define ARIZONA_FLL_NAME_LEN 20
283
284struct arizona_fll {
285 struct arizona *arizona;
286 int id;
287 unsigned int base;
Mark Brown2b4d39f2012-07-10 17:03:46 +0100288 unsigned int vco_mult;
Mark Brown07ed8732012-06-18 21:08:44 +0100289
Charles Keepaxde1e6ee2013-02-20 17:28:39 +0000290 unsigned int fout;
Charles Keepax9e359c62013-02-20 17:28:35 +0000291 int sync_src;
292 unsigned int sync_freq;
Charles Keepax19b34bd2013-02-20 17:28:34 +0000293 int ref_src;
294 unsigned int ref_freq;
295
Mark Brown07ed8732012-06-18 21:08:44 +0100296 char lock_name[ARIZONA_FLL_NAME_LEN];
297 char clock_ok_name[ARIZONA_FLL_NAME_LEN];
298};
299
Richard Fitzgerald346d9682015-06-02 11:53:33 +0100300extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
301extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
302extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
303 struct snd_kcontrol *kcontrol, int event);
304extern void arizona_init_dvfs(struct arizona_priv *priv);
305
Mark Brown07ed8732012-06-18 21:08:44 +0100306extern int arizona_init_fll(struct arizona *arizona, int id, int base,
307 int lock_irq, int ok_irq, struct arizona_fll *fll);
Charles Keepaxee929a92013-02-20 17:28:40 +0000308extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
309 unsigned int Fref, unsigned int Fout);
Mark Brown07ed8732012-06-18 21:08:44 +0100310extern int arizona_set_fll(struct arizona_fll *fll, int source,
311 unsigned int Fref, unsigned int Fout);
312
Mark Brown56447e12013-01-10 14:45:58 +0000313extern int arizona_init_spk(struct snd_soc_codec *codec);
Charles Keepaxb63144e2013-07-04 08:56:28 +0100314extern int arizona_init_gpio(struct snd_soc_codec *codec);
Charles Keepaxb60f3632014-06-10 18:41:02 +0100315extern int arizona_init_mono(struct snd_soc_codec *codec);
Charles Keepax2230c492016-05-13 16:45:18 +0100316extern int arizona_init_notifiers(struct snd_soc_codec *codec);
Mark Brown56447e12013-01-10 14:45:58 +0000317
Charles Keepax54dca702016-04-15 13:11:56 +0100318extern int arizona_free_spk(struct snd_soc_codec *codec);
319
Mark Brown5b2eec32012-07-04 17:32:05 +0100320extern int arizona_init_dai(struct arizona_priv *priv, int dai);
321
Mark Brownbc9ab6d2013-01-04 19:31:00 +0000322int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
323 bool diff);
324
Charles Keepax002b0832015-09-16 13:59:41 +0100325extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);
326
Richard Fitzgerald6ebbce02015-09-28 14:01:09 +0100327extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
Charles Keepax2230c492016-05-13 16:45:18 +0100328
329extern int arizona_register_notifier(struct snd_soc_codec *codec,
330 struct notifier_block *nb,
331 int (*notify)(struct notifier_block *nb,
332 unsigned long action,
333 void *data));
334extern int arizona_unregister_notifier(struct snd_soc_codec *codec,
335 struct notifier_block *nb);
336
Mark Brown07ed8732012-06-18 21:08:44 +0100337#endif