blob: 572f11bc90b43fa697178e9fff5c909de958c554 [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
Mark Brown0b09df62012-10-11 11:31:35 +090060#define ARIZONA_MAX_DAI 4
61#define ARIZONA_MAX_ADSP 4
Mark Brown5b2eec32012-07-04 17:32:05 +010062
Mark Brown07ed8732012-06-18 21:08:44 +010063struct arizona;
Mark Brown0b09df62012-10-11 11:31:35 +090064struct wm_adsp;
Mark Brown07ed8732012-06-18 21:08:44 +010065
Mark Brown5b2eec32012-07-04 17:32:05 +010066struct arizona_dai_priv {
67 int clk;
68};
69
Mark Brown07ed8732012-06-18 21:08:44 +010070struct arizona_priv {
Mark Brown0b09df62012-10-11 11:31:35 +090071 struct wm_adsp adsp[ARIZONA_MAX_ADSP];
Mark Brown07ed8732012-06-18 21:08:44 +010072 struct arizona *arizona;
73 int sysclk;
74 int asyncclk;
Mark Brown5b2eec32012-07-04 17:32:05 +010075 struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
Mark Brownddbce972013-02-15 17:27:22 +000076
77 int num_inputs;
78 unsigned int in_pending;
Mark Brown07ed8732012-06-18 21:08:44 +010079};
80
Mark Brown91660bd2012-12-05 20:35:24 +090081#define ARIZONA_NUM_MIXER_INPUTS 99
Mark Brown07ed8732012-06-18 21:08:44 +010082
83extern const unsigned int arizona_mixer_tlv[];
84extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
85extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
86
87#define ARIZONA_MIXER_CONTROLS(name, base) \
88 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
89 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
90 arizona_mixer_tlv), \
91 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
92 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
93 arizona_mixer_tlv), \
94 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
95 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
96 arizona_mixer_tlv), \
97 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
98 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
99 arizona_mixer_tlv)
100
101#define ARIZONA_MUX_ENUM_DECL(name, reg) \
102 SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff, \
103 arizona_mixer_texts, arizona_mixer_values)
104
105#define ARIZONA_MUX_CTL_DECL(name) \
106 const struct snd_kcontrol_new name##_mux = \
107 SOC_DAPM_VALUE_ENUM("Route", name##_enum)
108
Charles Keepax17bd09e2012-11-13 16:40:32 +0000109#define ARIZONA_MUX_ENUMS(name, base_reg) \
110 static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
111 static ARIZONA_MUX_CTL_DECL(name)
112
Mark Brown07ed8732012-06-18 21:08:44 +0100113#define ARIZONA_MIXER_ENUMS(name, base_reg) \
Charles Keepax17bd09e2012-11-13 16:40:32 +0000114 ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
115 ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
116 ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
117 ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
Mark Brown07ed8732012-06-18 21:08:44 +0100118
Mark Brown0b09df62012-10-11 11:31:35 +0900119#define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
Charles Keepax17bd09e2012-11-13 16:40:32 +0000120 ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
121 ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
122 ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
123 ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
124 ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
125 ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
Mark Brown0b09df62012-10-11 11:31:35 +0900126
Mark Brown07ed8732012-06-18 21:08:44 +0100127#define ARIZONA_MUX(name, ctrl) \
128 SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
129
Charles Keepax17bd09e2012-11-13 16:40:32 +0000130#define ARIZONA_MUX_WIDGETS(name, name_str) \
131 ARIZONA_MUX(name_str " Input", &name##_mux)
132
Mark Brown07ed8732012-06-18 21:08:44 +0100133#define ARIZONA_MIXER_WIDGETS(name, name_str) \
134 ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
135 ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
136 ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
137 ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
138 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
139
Mark Brown0b09df62012-10-11 11:31:35 +0900140#define ARIZONA_DSP_WIDGETS(name, name_str) \
141 ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
142 ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
143 ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
144 ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
145 ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
146 ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
147 ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
148 ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
149
Charles Keepax17bd09e2012-11-13 16:40:32 +0000150#define ARIZONA_MUX_ROUTES(name) \
151 ARIZONA_MIXER_INPUT_ROUTES(name " Input")
152
Mark Brown07ed8732012-06-18 21:08:44 +0100153#define ARIZONA_MIXER_ROUTES(widget, name) \
154 { widget, NULL, name " Mixer" }, \
155 { name " Mixer", NULL, name " Input 1" }, \
156 { name " Mixer", NULL, name " Input 2" }, \
157 { name " Mixer", NULL, name " Input 3" }, \
158 { name " Mixer", NULL, name " Input 4" }, \
159 ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
160 ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
161 ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
162 ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
163
Mark Brown0b09df62012-10-11 11:31:35 +0900164#define ARIZONA_DSP_ROUTES(name) \
165 { name, NULL, name " Aux 1" }, \
166 { name, NULL, name " Aux 2" }, \
167 { name, NULL, name " Aux 3" }, \
168 { name, NULL, name " Aux 4" }, \
169 { name, NULL, name " Aux 5" }, \
170 { name, NULL, name " Aux 6" }, \
171 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
172 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
173 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
174 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
175 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
176 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
177 ARIZONA_MIXER_ROUTES(name, name "L"), \
178 ARIZONA_MIXER_ROUTES(name, name "R")
179
Mark Browne853a002012-12-09 12:25:52 +0900180extern const struct soc_enum arizona_in_vi_ramp;
181extern const struct soc_enum arizona_in_vd_ramp;
182
183extern const struct soc_enum arizona_out_vi_ramp;
184extern const struct soc_enum arizona_out_vd_ramp;
185
Mark Brown07ed8732012-06-18 21:08:44 +0100186extern const struct soc_enum arizona_lhpf1_mode;
187extern const struct soc_enum arizona_lhpf2_mode;
188extern const struct soc_enum arizona_lhpf3_mode;
189extern const struct soc_enum arizona_lhpf4_mode;
190
Mark Brown845571c2012-12-18 13:47:57 +0000191extern const struct soc_enum arizona_ng_hold;
192
Mark Brown07ed8732012-06-18 21:08:44 +0100193extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
194 struct snd_kcontrol *kcontrol,
195 int event);
196extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
197 struct snd_kcontrol *kcontrol,
198 int event);
199
200extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
201 int source, unsigned int freq, int dir);
202
203extern const struct snd_soc_dai_ops arizona_dai_ops;
204
205#define ARIZONA_FLL_NAME_LEN 20
206
207struct arizona_fll {
208 struct arizona *arizona;
209 int id;
210 unsigned int base;
Mark Brown2b4d39f2012-07-10 17:03:46 +0100211 unsigned int vco_mult;
Mark Brown07ed8732012-06-18 21:08:44 +0100212 struct completion ok;
213
Charles Keepaxde1e6ee2013-02-20 17:28:39 +0000214 unsigned int fout;
Charles Keepax9e359c62013-02-20 17:28:35 +0000215 int sync_src;
216 unsigned int sync_freq;
Charles Keepax19b34bd2013-02-20 17:28:34 +0000217 int ref_src;
218 unsigned int ref_freq;
219
Mark Brown07ed8732012-06-18 21:08:44 +0100220 char lock_name[ARIZONA_FLL_NAME_LEN];
221 char clock_ok_name[ARIZONA_FLL_NAME_LEN];
222};
223
224extern int arizona_init_fll(struct arizona *arizona, int id, int base,
225 int lock_irq, int ok_irq, struct arizona_fll *fll);
Charles Keepaxee929a92013-02-20 17:28:40 +0000226extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
227 unsigned int Fref, unsigned int Fout);
Mark Brown07ed8732012-06-18 21:08:44 +0100228extern int arizona_set_fll(struct arizona_fll *fll, int source,
229 unsigned int Fref, unsigned int Fout);
230
Mark Brown5b2eec32012-07-04 17:32:05 +0100231extern int arizona_init_dai(struct arizona_priv *priv, int dai);
232
Mark Brownbc9ab6d2013-01-04 19:31:00 +0000233int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
234 bool diff);
235
Mark Brown07ed8732012-06-18 21:08:44 +0100236#endif