arizona.h 10.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * arizona.h - Wolfson Arizona class device shared support
 *
 * Copyright 2012 Wolfson Microelectronics plc
 *
 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef _ASOC_ARIZONA_H
#define _ASOC_ARIZONA_H

#include <linux/completion.h>

#include <sound/soc.h>

20 21
#include "wm_adsp.h"

22 23 24 25
#define ARIZONA_CLK_SYSCLK         1
#define ARIZONA_CLK_ASYNCCLK       2
#define ARIZONA_CLK_OPCLK          3
#define ARIZONA_CLK_ASYNC_OPCLK    4
26 27 28 29 30 31 32 33 34

#define ARIZONA_CLK_SRC_MCLK1    0x0
#define ARIZONA_CLK_SRC_MCLK2    0x1
#define ARIZONA_CLK_SRC_FLL1     0x4
#define ARIZONA_CLK_SRC_FLL2     0x5
#define ARIZONA_CLK_SRC_AIF1BCLK 0x8
#define ARIZONA_CLK_SRC_AIF2BCLK 0x9
#define ARIZONA_CLK_SRC_AIF3BCLK 0xa

35
#define ARIZONA_FLL_SRC_NONE      -1
36 37
#define ARIZONA_FLL_SRC_MCLK1      0
#define ARIZONA_FLL_SRC_MCLK2      1
38 39 40 41 42 43 44 45 46
#define ARIZONA_FLL_SRC_SLIMCLK    3
#define ARIZONA_FLL_SRC_FLL1       4
#define ARIZONA_FLL_SRC_FLL2       5
#define ARIZONA_FLL_SRC_AIF1BCLK   8
#define ARIZONA_FLL_SRC_AIF2BCLK   9
#define ARIZONA_FLL_SRC_AIF3BCLK  10
#define ARIZONA_FLL_SRC_AIF1LRCLK 12
#define ARIZONA_FLL_SRC_AIF2LRCLK 13
#define ARIZONA_FLL_SRC_AIF3LRCLK 14
47 48 49 50 51

#define ARIZONA_MIXER_VOL_MASK             0x00FE
#define ARIZONA_MIXER_VOL_SHIFT                 1
#define ARIZONA_MIXER_VOL_WIDTH                 7

52 53 54 55 56 57 58 59
#define ARIZONA_CLK_6MHZ   0
#define ARIZONA_CLK_12MHZ  1
#define ARIZONA_CLK_24MHZ  2
#define ARIZONA_CLK_49MHZ  3
#define ARIZONA_CLK_73MHZ  4
#define ARIZONA_CLK_98MHZ  5
#define ARIZONA_CLK_147MHZ 6

60
#define ARIZONA_MAX_DAI  10
61
#define ARIZONA_MAX_ADSP 4
62

63 64 65
#define ARIZONA_DVFS_SR1_RQ	0x001
#define ARIZONA_DVFS_ADSP1_RQ	0x100

66
struct arizona;
67
struct wm_adsp;
68

69 70
struct arizona_dai_priv {
	int clk;
71 72

	struct snd_pcm_hw_constraint_list constraint;
73 74
};

75
struct arizona_priv {
76
	struct wm_adsp adsp[ARIZONA_MAX_ADSP];
77 78 79
	struct arizona *arizona;
	int sysclk;
	int asyncclk;
80
	struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
81 82 83

	int num_inputs;
	unsigned int in_pending;
84

85 86
	unsigned int out_up_pending;
	unsigned int out_up_delay;
87 88 89
	unsigned int out_down_pending;
	unsigned int out_down_delay;

90 91
	unsigned int spk_ena:2;
	unsigned int spk_ena_pending:1;
92 93 94 95

	unsigned int dvfs_reqs;
	struct mutex dvfs_lock;
	bool dvfs_cached;
96 97
};

98
#define ARIZONA_NUM_MIXER_INPUTS 104
99 100

extern const unsigned int arizona_mixer_tlv[];
101 102
extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
103

104 105 106 107 108
#define ARIZONA_GAINMUX_CONTROLS(name, base) \
	SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1,		\
			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
			     arizona_mixer_tlv)

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
#define ARIZONA_MIXER_CONTROLS(name, base) \
	SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1,		\
			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
			     arizona_mixer_tlv),			\
	SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3,		\
			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
			     arizona_mixer_tlv),			\
	SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5,		\
			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
			     arizona_mixer_tlv),			\
	SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7,		\
			     ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0,	\
			     arizona_mixer_tlv)

#define ARIZONA_MUX_ENUM_DECL(name, reg) \
124 125
	SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
		name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
126 127 128

#define ARIZONA_MUX_CTL_DECL(name) \
	const struct snd_kcontrol_new name##_mux =	\
129
		SOC_DAPM_ENUM("Route", name##_enum)
130

131 132 133 134
#define ARIZONA_MUX_ENUMS(name, base_reg) \
	static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg);      \
	static ARIZONA_MUX_CTL_DECL(name)

135
#define ARIZONA_MIXER_ENUMS(name, base_reg) \
136 137 138 139
	ARIZONA_MUX_ENUMS(name##_in1, base_reg);     \
	ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
	ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
	ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
140

141
#define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
142 143 144 145 146 147
	ARIZONA_MUX_ENUMS(name##_aux1, base_reg);	\
	ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8);	\
	ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16);	\
	ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24);	\
	ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32);	\
	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 153 154
#define ARIZONA_MUX_WIDGETS(name, name_str) \
	ARIZONA_MUX(name_str " Input", &name##_mux)

155 156 157 158 159 160 161
#define ARIZONA_MIXER_WIDGETS(name, name_str)	\
	ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
	ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
	ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
	ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
	SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)

162 163 164 165 166 167 168 169 170 171
#define ARIZONA_DSP_WIDGETS(name, name_str) \
	ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
	ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
	ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
	ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
	ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
	ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
	ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
	ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)

172 173
#define ARIZONA_MUX_ROUTES(widget, name) \
	{ widget, NULL, name " Input" }, \
174 175
	ARIZONA_MIXER_INPUT_ROUTES(name " Input")

176 177 178 179 180 181 182 183 184 185 186
#define ARIZONA_MIXER_ROUTES(widget, name) \
	{ widget, NULL, name " Mixer" },         \
	{ name " Mixer", NULL, name " Input 1" }, \
	{ name " Mixer", NULL, name " Input 2" }, \
	{ name " Mixer", NULL, name " Input 3" }, \
	{ name " Mixer", NULL, name " Input 4" }, \
	ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")

187
#define ARIZONA_DSP_ROUTES(name) \
188 189 190 191 192 193 194
	{ name, NULL, name " Preloader"}, \
	{ name " Preloader", NULL, name " Aux 1" }, \
	{ name " Preloader", NULL, name " Aux 2" }, \
	{ name " Preloader", NULL, name " Aux 3" }, \
	{ name " Preloader", NULL, name " Aux 4" }, \
	{ name " Preloader", NULL, name " Aux 5" }, \
	{ name " Preloader", NULL, name " Aux 6" }, \
195 196 197 198 199 200
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
	ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
201 202
	ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \
	ARIZONA_MIXER_ROUTES(name " Preloader", name "R")
203

204 205 206 207 208 209 210
#define ARIZONA_EQ_CONTROL(xname, xbase)                      \
{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
	.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
	.put = arizona_eq_coeff_put, .private_value =         \
	((unsigned long)&(struct soc_bytes) { .base = xbase,  \
	 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }

211 212 213 214 215 216 217
#define ARIZONA_LHPF_CONTROL(xname, xbase)                    \
{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
	.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
	.put = arizona_lhpf_coeff_put, .private_value =       \
	((unsigned long)&(struct soc_bytes) { .base = xbase,  \
	 .num_regs = 1 }) }

218
#define ARIZONA_RATE_ENUM_SIZE 4
219 220
#define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14

221 222
extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
223 224
extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
225 226

extern const struct soc_enum arizona_isrc_fsl[];
C
Charles Keepax 已提交
227
extern const struct soc_enum arizona_isrc_fsh[];
228
extern const struct soc_enum arizona_asrc_rate1;
229

230 231 232 233 234 235
extern const struct soc_enum arizona_in_vi_ramp;
extern const struct soc_enum arizona_in_vd_ramp;

extern const struct soc_enum arizona_out_vi_ramp;
extern const struct soc_enum arizona_out_vd_ramp;

236 237 238 239 240
extern const struct soc_enum arizona_lhpf1_mode;
extern const struct soc_enum arizona_lhpf2_mode;
extern const struct soc_enum arizona_lhpf3_mode;
extern const struct soc_enum arizona_lhpf4_mode;

241
extern const struct soc_enum arizona_ng_hold;
242
extern const struct soc_enum arizona_in_hpf_cut_enum;
243
extern const struct soc_enum arizona_in_dmic_osr[];
244

245 246
extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];

247 248 249 250
extern const struct soc_enum arizona_anc_input_src[];
extern const struct soc_enum arizona_anc_ng_enum;
extern const struct soc_enum arizona_output_anc_src[];

251 252 253 254 255 256
extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
			 struct snd_kcontrol *kcontrol,
			 int event);
extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
			  struct snd_kcontrol *kcontrol,
			  int event);
257 258 259
extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
			 struct snd_kcontrol *kcontrol,
			 int event);
260 261 262
extern int arizona_anc_ev(struct snd_soc_dapm_widget *w,
			  struct snd_kcontrol *kcontrol,
			  int event);
263

264 265
extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol);
266 267
extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
				  struct snd_ctl_elem_value *ucontrol);
268

269 270 271 272
extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
			      int source, unsigned int freq, int dir);

extern const struct snd_soc_dai_ops arizona_dai_ops;
273
extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
274 275 276 277 278 279 280

#define ARIZONA_FLL_NAME_LEN 20

struct arizona_fll {
	struct arizona *arizona;
	int id;
	unsigned int base;
281
	unsigned int vco_mult;
282

283
	unsigned int fout;
284 285
	int sync_src;
	unsigned int sync_freq;
286 287 288
	int ref_src;
	unsigned int ref_freq;

289 290 291 292
	char lock_name[ARIZONA_FLL_NAME_LEN];
	char clock_ok_name[ARIZONA_FLL_NAME_LEN];
};

293 294 295 296 297 298
extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
				  struct snd_kcontrol *kcontrol, int event);
extern void arizona_init_dvfs(struct arizona_priv *priv);

299 300
extern int arizona_init_fll(struct arizona *arizona, int id, int base,
			    int lock_irq, int ok_irq, struct arizona_fll *fll);
301 302
extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
				  unsigned int Fref, unsigned int Fout);
303 304 305
extern int arizona_set_fll(struct arizona_fll *fll, int source,
			   unsigned int Fref, unsigned int Fout);

306
extern int arizona_init_spk(struct snd_soc_codec *codec);
307
extern int arizona_init_gpio(struct snd_soc_codec *codec);
308
extern int arizona_init_mono(struct snd_soc_codec *codec);
309

310 311
extern int arizona_free_spk(struct snd_soc_codec *codec);

312 313
extern int arizona_init_dai(struct arizona_priv *priv, int dai);

314 315 316
int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
			    bool diff);

317 318
extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);

319
extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
320
#endif