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 6 61 #define ARIZONA_MAX_ADSP 4 62 63 struct arizona; 64 struct wm_adsp; 65 66 struct arizona_dai_priv { 67 int clk; 68 }; 69 70 struct arizona_priv { 71 struct wm_adsp adsp[ARIZONA_MAX_ADSP]; 72 struct arizona *arizona; 73 int sysclk; 74 int asyncclk; 75 struct arizona_dai_priv dai[ARIZONA_MAX_DAI]; 76 77 int num_inputs; 78 unsigned int in_pending; 79 80 unsigned int out_up_pending; 81 unsigned int out_up_delay; 82 unsigned int out_down_pending; 83 unsigned int out_down_delay; 84 85 unsigned int spk_ena:2; 86 unsigned int spk_ena_pending:1; 87 }; 88 89 #define ARIZONA_NUM_MIXER_INPUTS 103 90 91 extern const unsigned int arizona_mixer_tlv[]; 92 extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS]; 93 extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS]; 94 95 #define ARIZONA_MIXER_CONTROLS(name, base) \ 96 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \ 97 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 98 arizona_mixer_tlv), \ 99 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \ 100 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 101 arizona_mixer_tlv), \ 102 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \ 103 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 104 arizona_mixer_tlv), \ 105 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \ 106 ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 107 arizona_mixer_tlv) 108 109 #define ARIZONA_MUX_ENUM_DECL(name, reg) \ 110 SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff, \ 111 arizona_mixer_texts, arizona_mixer_values) 112 113 #define ARIZONA_MUX_CTL_DECL(name) \ 114 const struct snd_kcontrol_new name##_mux = \ 115 SOC_DAPM_ENUM("Route", name##_enum) 116 117 #define ARIZONA_MUX_ENUMS(name, base_reg) \ 118 static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \ 119 static ARIZONA_MUX_CTL_DECL(name) 120 121 #define ARIZONA_MIXER_ENUMS(name, base_reg) \ 122 ARIZONA_MUX_ENUMS(name##_in1, base_reg); \ 123 ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \ 124 ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \ 125 ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6) 126 127 #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \ 128 ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \ 129 ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \ 130 ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \ 131 ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \ 132 ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \ 133 ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40) 134 135 #define ARIZONA_MUX(name, ctrl) \ 136 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl) 137 138 #define ARIZONA_MUX_WIDGETS(name, name_str) \ 139 ARIZONA_MUX(name_str " Input", &name##_mux) 140 141 #define ARIZONA_MIXER_WIDGETS(name, name_str) \ 142 ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \ 143 ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \ 144 ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \ 145 ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \ 146 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0) 147 148 #define ARIZONA_DSP_WIDGETS(name, name_str) \ 149 ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \ 150 ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \ 151 ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \ 152 ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \ 153 ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \ 154 ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \ 155 ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \ 156 ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux) 157 158 #define ARIZONA_MUX_ROUTES(widget, name) \ 159 { widget, NULL, name " Input" }, \ 160 ARIZONA_MIXER_INPUT_ROUTES(name " Input") 161 162 #define ARIZONA_MIXER_ROUTES(widget, name) \ 163 { widget, NULL, name " Mixer" }, \ 164 { name " Mixer", NULL, name " Input 1" }, \ 165 { name " Mixer", NULL, name " Input 2" }, \ 166 { name " Mixer", NULL, name " Input 3" }, \ 167 { name " Mixer", NULL, name " Input 4" }, \ 168 ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \ 169 ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \ 170 ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \ 171 ARIZONA_MIXER_INPUT_ROUTES(name " Input 4") 172 173 #define ARIZONA_DSP_ROUTES(name) \ 174 { name, NULL, name " Preloader"}, \ 175 { name " Preloader", NULL, name " Aux 1" }, \ 176 { name " Preloader", NULL, name " Aux 2" }, \ 177 { name " Preloader", NULL, name " Aux 3" }, \ 178 { name " Preloader", NULL, name " Aux 4" }, \ 179 { name " Preloader", NULL, name " Aux 5" }, \ 180 { name " Preloader", NULL, name " Aux 6" }, \ 181 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \ 182 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \ 183 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \ 184 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \ 185 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \ 186 ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \ 187 ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \ 188 ARIZONA_MIXER_ROUTES(name " Preloader", name "R") 189 190 #define ARIZONA_RATE_ENUM_SIZE 4 191 extern const char *arizona_rate_text[ARIZONA_RATE_ENUM_SIZE]; 192 extern const int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE]; 193 194 extern const struct soc_enum arizona_isrc_fsl[]; 195 extern const struct soc_enum arizona_isrc_fsh[]; 196 extern const struct soc_enum arizona_asrc_rate1; 197 198 extern const struct soc_enum arizona_in_vi_ramp; 199 extern const struct soc_enum arizona_in_vd_ramp; 200 201 extern const struct soc_enum arizona_out_vi_ramp; 202 extern const struct soc_enum arizona_out_vd_ramp; 203 204 extern const struct soc_enum arizona_lhpf1_mode; 205 extern const struct soc_enum arizona_lhpf2_mode; 206 extern const struct soc_enum arizona_lhpf3_mode; 207 extern const struct soc_enum arizona_lhpf4_mode; 208 209 extern const struct soc_enum arizona_ng_hold; 210 extern const struct soc_enum arizona_in_hpf_cut_enum; 211 extern const struct soc_enum arizona_in_dmic_osr[]; 212 213 extern int arizona_in_ev(struct snd_soc_dapm_widget *w, 214 struct snd_kcontrol *kcontrol, 215 int event); 216 extern int arizona_out_ev(struct snd_soc_dapm_widget *w, 217 struct snd_kcontrol *kcontrol, 218 int event); 219 extern int arizona_hp_ev(struct snd_soc_dapm_widget *w, 220 struct snd_kcontrol *kcontrol, 221 int event); 222 223 extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id, 224 int source, unsigned int freq, int dir); 225 226 extern const struct snd_soc_dai_ops arizona_dai_ops; 227 extern const struct snd_soc_dai_ops arizona_simple_dai_ops; 228 229 #define ARIZONA_FLL_NAME_LEN 20 230 231 struct arizona_fll { 232 struct arizona *arizona; 233 int id; 234 unsigned int base; 235 unsigned int vco_mult; 236 struct completion ok; 237 238 unsigned int fout; 239 int sync_src; 240 unsigned int sync_freq; 241 int ref_src; 242 unsigned int ref_freq; 243 244 char lock_name[ARIZONA_FLL_NAME_LEN]; 245 char clock_ok_name[ARIZONA_FLL_NAME_LEN]; 246 }; 247 248 extern int arizona_init_fll(struct arizona *arizona, int id, int base, 249 int lock_irq, int ok_irq, struct arizona_fll *fll); 250 extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source, 251 unsigned int Fref, unsigned int Fout); 252 extern int arizona_set_fll(struct arizona_fll *fll, int source, 253 unsigned int Fref, unsigned int Fout); 254 255 extern int arizona_init_spk(struct snd_soc_codec *codec); 256 extern int arizona_init_gpio(struct snd_soc_codec *codec); 257 extern int arizona_init_mono(struct snd_soc_codec *codec); 258 259 extern int arizona_init_dai(struct arizona_priv *priv, int dai); 260 261 int arizona_set_output_mode(struct snd_soc_codec *codec, int output, 262 bool diff); 263 264 #endif 265