1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Cirrus Logic Madera class codecs common support 4 * 5 * Copyright (C) 2015-2018 Cirrus Logic, Inc. and 6 * Cirrus Logic International Semiconductor Ltd. 7 */ 8 9 #ifndef ASOC_MADERA_H 10 #define ASOC_MADERA_H 11 12 #include <linux/completion.h> 13 #include <sound/soc.h> 14 #include <sound/madera-pdata.h> 15 16 #include "wm_adsp.h" 17 18 #define MADERA_FLL1_REFCLK 1 19 #define MADERA_FLL2_REFCLK 2 20 #define MADERA_FLL3_REFCLK 3 21 #define MADERA_FLLAO_REFCLK 4 22 #define MADERA_FLL1_SYNCCLK 5 23 #define MADERA_FLL2_SYNCCLK 6 24 #define MADERA_FLL3_SYNCCLK 7 25 #define MADERA_FLLAO_SYNCCLK 8 26 27 #define MADERA_FLL_SRC_NONE -1 28 #define MADERA_FLL_SRC_MCLK1 0 29 #define MADERA_FLL_SRC_MCLK2 1 30 #define MADERA_FLL_SRC_SLIMCLK 3 31 #define MADERA_FLL_SRC_FLL1 4 32 #define MADERA_FLL_SRC_FLL2 5 33 #define MADERA_FLL_SRC_AIF1BCLK 8 34 #define MADERA_FLL_SRC_AIF2BCLK 9 35 #define MADERA_FLL_SRC_AIF3BCLK 10 36 #define MADERA_FLL_SRC_AIF4BCLK 11 37 #define MADERA_FLL_SRC_AIF1LRCLK 12 38 #define MADERA_FLL_SRC_AIF2LRCLK 13 39 #define MADERA_FLL_SRC_AIF3LRCLK 14 40 #define MADERA_FLL_SRC_AIF4LRCLK 15 41 42 #define MADERA_CLK_SYSCLK_1 1 43 #define MADERA_CLK_ASYNCCLK_1 2 44 #define MADERA_CLK_OPCLK 3 45 #define MADERA_CLK_ASYNC_OPCLK 4 46 #define MADERA_CLK_SYSCLK_2 5 47 #define MADERA_CLK_SYSCLK_3 6 48 #define MADERA_CLK_ASYNCCLK_2 7 49 #define MADERA_CLK_DSPCLK 8 50 51 #define MADERA_CLK_SRC_MCLK1 0x0 52 #define MADERA_CLK_SRC_MCLK2 0x1 53 #define MADERA_CLK_SRC_FLL1 0x4 54 #define MADERA_CLK_SRC_FLL2 0x5 55 #define MADERA_CLK_SRC_FLL3 0x6 56 #define MADERA_CLK_SRC_FLLAO_HI 0x7 57 #define MADERA_CLK_SRC_FLL1_DIV6 0x7 58 #define MADERA_CLK_SRC_AIF1BCLK 0x8 59 #define MADERA_CLK_SRC_AIF2BCLK 0x9 60 #define MADERA_CLK_SRC_AIF3BCLK 0xA 61 #define MADERA_CLK_SRC_AIF4BCLK 0xB 62 #define MADERA_CLK_SRC_FLLAO 0xF 63 64 #define MADERA_MIXER_VOL_MASK 0x00FE 65 #define MADERA_MIXER_VOL_SHIFT 1 66 #define MADERA_MIXER_VOL_WIDTH 7 67 68 #define MADERA_DOM_GRP_FX 0 69 #define MADERA_DOM_GRP_ASRC1 1 70 #define MADERA_DOM_GRP_ASRC2 2 71 #define MADERA_DOM_GRP_ISRC1 3 72 #define MADERA_DOM_GRP_ISRC2 4 73 #define MADERA_DOM_GRP_ISRC3 5 74 #define MADERA_DOM_GRP_ISRC4 6 75 #define MADERA_DOM_GRP_OUT 7 76 #define MADERA_DOM_GRP_SPD 8 77 #define MADERA_DOM_GRP_DSP1 9 78 #define MADERA_DOM_GRP_DSP2 10 79 #define MADERA_DOM_GRP_DSP3 11 80 #define MADERA_DOM_GRP_DSP4 12 81 #define MADERA_DOM_GRP_DSP5 13 82 #define MADERA_DOM_GRP_DSP6 14 83 #define MADERA_DOM_GRP_DSP7 15 84 #define MADERA_DOM_GRP_AIF1 16 85 #define MADERA_DOM_GRP_AIF2 17 86 #define MADERA_DOM_GRP_AIF3 18 87 #define MADERA_DOM_GRP_AIF4 19 88 #define MADERA_DOM_GRP_SLIMBUS 20 89 #define MADERA_DOM_GRP_PWM 21 90 #define MADERA_DOM_GRP_DFC 22 91 #define MADERA_N_DOM_GRPS 23 92 93 #define MADERA_MAX_DAI 11 94 #define MADERA_MAX_ADSP 7 95 96 #define MADERA_NUM_MIXER_INPUTS 148 97 98 struct madera; 99 struct wm_adsp; 100 101 struct madera_voice_trigger_info { 102 /** Which core triggered, 1-based (1 = DSP1, ...) */ 103 int core_num; 104 }; 105 106 struct madera_dai_priv { 107 int clk; 108 struct snd_pcm_hw_constraint_list constraint; 109 }; 110 111 struct madera_priv { 112 struct wm_adsp adsp[MADERA_MAX_ADSP]; 113 struct madera *madera; 114 struct device *dev; 115 int sysclk; 116 int asyncclk; 117 int dspclk; 118 struct madera_dai_priv dai[MADERA_MAX_DAI]; 119 120 int num_inputs; 121 122 unsigned int in_pending; 123 124 unsigned int out_up_pending; 125 unsigned int out_up_delay; 126 unsigned int out_down_pending; 127 unsigned int out_down_delay; 128 129 unsigned int adsp_rate_cache[MADERA_MAX_ADSP]; 130 131 struct mutex rate_lock; 132 133 int tdm_width[MADERA_MAX_AIF]; 134 int tdm_slots[MADERA_MAX_AIF]; 135 136 int domain_group_ref[MADERA_N_DOM_GRPS]; 137 }; 138 139 struct madera_fll_cfg { 140 int n; 141 unsigned int theta; 142 unsigned int lambda; 143 int refdiv; 144 int fratio; 145 int gain; 146 int alt_gain; 147 }; 148 149 struct madera_fll { 150 struct madera *madera; 151 int id; 152 unsigned int base; 153 154 unsigned int fout; 155 156 int sync_src; 157 unsigned int sync_freq; 158 159 int ref_src; 160 unsigned int ref_freq; 161 struct madera_fll_cfg ref_cfg; 162 }; 163 164 struct madera_enum { 165 struct soc_enum mixer_enum; 166 int val; 167 }; 168 169 extern const unsigned int madera_ana_tlv[]; 170 extern const unsigned int madera_eq_tlv[]; 171 extern const unsigned int madera_digital_tlv[]; 172 extern const unsigned int madera_noise_tlv[]; 173 extern const unsigned int madera_ng_tlv[]; 174 175 extern const unsigned int madera_mixer_tlv[]; 176 extern const char * const madera_mixer_texts[MADERA_NUM_MIXER_INPUTS]; 177 extern const unsigned int madera_mixer_values[MADERA_NUM_MIXER_INPUTS]; 178 179 #define MADERA_GAINMUX_CONTROLS(name, base) \ 180 SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \ 181 MADERA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 182 madera_mixer_tlv) 183 184 #define MADERA_MIXER_CONTROLS(name, base) \ 185 SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \ 186 MADERA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 187 madera_mixer_tlv), \ 188 SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \ 189 MADERA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 190 madera_mixer_tlv), \ 191 SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \ 192 MADERA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 193 madera_mixer_tlv), \ 194 SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \ 195 MADERA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \ 196 madera_mixer_tlv) 197 198 #define MADERA_MUX_ENUM_DECL(name, reg) \ 199 SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \ 200 name, reg, 0, 0xff, madera_mixer_texts, madera_mixer_values) 201 202 #define MADERA_MUX_CTL_DECL(name) \ 203 const struct snd_kcontrol_new name##_mux = \ 204 SOC_DAPM_ENUM("Route", name##_enum) 205 206 #define MADERA_MUX_ENUMS(name, base_reg) \ 207 static MADERA_MUX_ENUM_DECL(name##_enum, base_reg); \ 208 static MADERA_MUX_CTL_DECL(name) 209 210 #define MADERA_MIXER_ENUMS(name, base_reg) \ 211 MADERA_MUX_ENUMS(name##_in1, base_reg); \ 212 MADERA_MUX_ENUMS(name##_in2, base_reg + 2); \ 213 MADERA_MUX_ENUMS(name##_in3, base_reg + 4); \ 214 MADERA_MUX_ENUMS(name##_in4, base_reg + 6) 215 216 #define MADERA_DSP_AUX_ENUMS(name, base_reg) \ 217 MADERA_MUX_ENUMS(name##_aux1, base_reg); \ 218 MADERA_MUX_ENUMS(name##_aux2, base_reg + 8); \ 219 MADERA_MUX_ENUMS(name##_aux3, base_reg + 16); \ 220 MADERA_MUX_ENUMS(name##_aux4, base_reg + 24); \ 221 MADERA_MUX_ENUMS(name##_aux5, base_reg + 32); \ 222 MADERA_MUX_ENUMS(name##_aux6, base_reg + 40) 223 224 #define MADERA_MUX(name, ctrl) \ 225 SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl) 226 227 #define MADERA_MUX_WIDGETS(name, name_str) \ 228 MADERA_MUX(name_str " Input 1", &name##_mux) 229 230 #define MADERA_MIXER_WIDGETS(name, name_str) \ 231 MADERA_MUX(name_str " Input 1", &name##_in1_mux), \ 232 MADERA_MUX(name_str " Input 2", &name##_in2_mux), \ 233 MADERA_MUX(name_str " Input 3", &name##_in3_mux), \ 234 MADERA_MUX(name_str " Input 4", &name##_in4_mux), \ 235 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0) 236 237 #define MADERA_DSP_WIDGETS(name, name_str) \ 238 MADERA_MIXER_WIDGETS(name##L, name_str "L"), \ 239 MADERA_MIXER_WIDGETS(name##R, name_str "R"), \ 240 MADERA_MUX(name_str " Aux 1", &name##_aux1_mux), \ 241 MADERA_MUX(name_str " Aux 2", &name##_aux2_mux), \ 242 MADERA_MUX(name_str " Aux 3", &name##_aux3_mux), \ 243 MADERA_MUX(name_str " Aux 4", &name##_aux4_mux), \ 244 MADERA_MUX(name_str " Aux 5", &name##_aux5_mux), \ 245 MADERA_MUX(name_str " Aux 6", &name##_aux6_mux) 246 247 #define MADERA_MUX_ROUTES(widget, name) \ 248 { widget, NULL, name " Input 1" }, \ 249 MADERA_MIXER_INPUT_ROUTES(name " Input 1") 250 251 #define MADERA_MIXER_ROUTES(widget, name) \ 252 { widget, NULL, name " Mixer" }, \ 253 { name " Mixer", NULL, name " Input 1" }, \ 254 { name " Mixer", NULL, name " Input 2" }, \ 255 { name " Mixer", NULL, name " Input 3" }, \ 256 { name " Mixer", NULL, name " Input 4" }, \ 257 MADERA_MIXER_INPUT_ROUTES(name " Input 1"), \ 258 MADERA_MIXER_INPUT_ROUTES(name " Input 2"), \ 259 MADERA_MIXER_INPUT_ROUTES(name " Input 3"), \ 260 MADERA_MIXER_INPUT_ROUTES(name " Input 4") 261 262 #define MADERA_DSP_ROUTES(name) \ 263 { name, NULL, name " Preloader"}, \ 264 { name " Preload", NULL, name " Preloader"}, \ 265 { name, NULL, "SYSCLK"}, \ 266 { name, NULL, "DSPCLK"}, \ 267 { name, NULL, name " Aux 1" }, \ 268 { name, NULL, name " Aux 2" }, \ 269 { name, NULL, name " Aux 3" }, \ 270 { name, NULL, name " Aux 4" }, \ 271 { name, NULL, name " Aux 5" }, \ 272 { name, NULL, name " Aux 6" }, \ 273 MADERA_MIXER_INPUT_ROUTES(name " Aux 1"), \ 274 MADERA_MIXER_INPUT_ROUTES(name " Aux 2"), \ 275 MADERA_MIXER_INPUT_ROUTES(name " Aux 3"), \ 276 MADERA_MIXER_INPUT_ROUTES(name " Aux 4"), \ 277 MADERA_MIXER_INPUT_ROUTES(name " Aux 5"), \ 278 MADERA_MIXER_INPUT_ROUTES(name " Aux 6"), \ 279 MADERA_MIXER_ROUTES(name, name "L"), \ 280 MADERA_MIXER_ROUTES(name, name "R") 281 282 #define MADERA_RATE_ENUM(xname, xenum) \ 283 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ 284 .info = snd_soc_info_enum_double, \ 285 .get = snd_soc_get_enum_double, .put = madera_rate_put, \ 286 .private_value = (unsigned long)&xenum } 287 288 #define MADERA_EQ_CONTROL(xname, xbase) \ 289 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 290 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ 291 .put = madera_eq_coeff_put, .private_value = \ 292 ((unsigned long)&(struct soc_bytes) { .base = xbase, \ 293 .num_regs = 20, .mask = ~MADERA_EQ1_B1_MODE }) } 294 295 #define MADERA_LHPF_CONTROL(xname, xbase) \ 296 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 297 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ 298 .put = madera_lhpf_coeff_put, .private_value = \ 299 ((unsigned long)&(struct soc_bytes) { .base = xbase, \ 300 .num_regs = 1 }) } 301 302 #define MADERA_RATES SNDRV_PCM_RATE_KNOT 303 304 #define MADERA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 305 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 306 307 #define MADERA_OSR_ENUM_SIZE 5 308 #define MADERA_SYNC_RATE_ENUM_SIZE 3 309 #define MADERA_ASYNC_RATE_ENUM_SIZE 2 310 #define MADERA_RATE_ENUM_SIZE \ 311 (MADERA_SYNC_RATE_ENUM_SIZE + MADERA_ASYNC_RATE_ENUM_SIZE) 312 #define MADERA_SAMPLE_RATE_ENUM_SIZE 16 313 #define MADERA_DFC_TYPE_ENUM_SIZE 5 314 #define MADERA_DFC_WIDTH_ENUM_SIZE 5 315 316 extern const struct snd_soc_dai_ops madera_dai_ops; 317 extern const struct snd_soc_dai_ops madera_simple_dai_ops; 318 319 extern const struct snd_kcontrol_new madera_inmux[]; 320 extern const struct snd_kcontrol_new madera_inmode[]; 321 322 extern const char * const madera_rate_text[MADERA_RATE_ENUM_SIZE]; 323 extern const unsigned int madera_rate_val[MADERA_RATE_ENUM_SIZE]; 324 325 extern const struct soc_enum madera_sample_rate[]; 326 extern const struct soc_enum madera_isrc_fsl[]; 327 extern const struct soc_enum madera_isrc_fsh[]; 328 extern const struct soc_enum madera_asrc1_rate[]; 329 extern const struct soc_enum madera_asrc2_rate[]; 330 extern const struct soc_enum madera_dfc_width[]; 331 extern const struct soc_enum madera_dfc_type[]; 332 333 extern const struct soc_enum madera_in_vi_ramp; 334 extern const struct soc_enum madera_in_vd_ramp; 335 336 extern const struct soc_enum madera_out_vi_ramp; 337 extern const struct soc_enum madera_out_vd_ramp; 338 339 extern const struct soc_enum madera_lhpf1_mode; 340 extern const struct soc_enum madera_lhpf2_mode; 341 extern const struct soc_enum madera_lhpf3_mode; 342 extern const struct soc_enum madera_lhpf4_mode; 343 344 extern const struct soc_enum madera_ng_hold; 345 extern const struct soc_enum madera_in_hpf_cut_enum; 346 extern const struct soc_enum madera_in_dmic_osr[]; 347 348 extern const struct soc_enum madera_output_anc_src[]; 349 extern const struct soc_enum madera_anc_input_src[]; 350 extern const struct soc_enum madera_anc_ng_enum; 351 352 extern const struct snd_kcontrol_new madera_dsp_trigger_output_mux[]; 353 extern const struct snd_kcontrol_new madera_drc_activity_output_mux[]; 354 355 extern const struct snd_kcontrol_new madera_adsp_rate_controls[]; 356 357 int madera_dfc_put(struct snd_kcontrol *kcontrol, 358 struct snd_ctl_elem_value *ucontrol); 359 360 int madera_lp_mode_put(struct snd_kcontrol *kcontrol, 361 struct snd_ctl_elem_value *ucontrol); 362 363 int madera_out1_demux_put(struct snd_kcontrol *kcontrol, 364 struct snd_ctl_elem_value *ucontrol); 365 int madera_out1_demux_get(struct snd_kcontrol *kcontrol, 366 struct snd_ctl_elem_value *ucontrol); 367 368 int madera_rate_put(struct snd_kcontrol *kcontrol, 369 struct snd_ctl_elem_value *ucontrol); 370 371 int madera_eq_coeff_put(struct snd_kcontrol *kcontrol, 372 struct snd_ctl_elem_value *ucontrol); 373 int madera_lhpf_coeff_put(struct snd_kcontrol *kcontrol, 374 struct snd_ctl_elem_value *ucontrol); 375 376 int madera_sysclk_ev(struct snd_soc_dapm_widget *w, 377 struct snd_kcontrol *kcontrol, int event); 378 int madera_spk_ev(struct snd_soc_dapm_widget *w, 379 struct snd_kcontrol *kcontrol, int event); 380 int madera_in_ev(struct snd_soc_dapm_widget *w, 381 struct snd_kcontrol *kcontrol, int event); 382 int madera_out_ev(struct snd_soc_dapm_widget *w, 383 struct snd_kcontrol *kcontrol, int event); 384 int madera_hp_ev(struct snd_soc_dapm_widget *w, 385 struct snd_kcontrol *kcontrol, int event); 386 int madera_anc_ev(struct snd_soc_dapm_widget *w, 387 struct snd_kcontrol *kcontrol, int event); 388 int madera_domain_clk_ev(struct snd_soc_dapm_widget *w, 389 struct snd_kcontrol *kcontrol, 390 int event); 391 392 int madera_set_adsp_clk(struct madera_priv *priv, int dsp_num, 393 unsigned int freq); 394 395 int madera_set_sysclk(struct snd_soc_component *component, int clk_id, 396 int source, unsigned int freq, int dir); 397 398 int madera_init_fll(struct madera *madera, int id, int base, 399 struct madera_fll *fll); 400 int madera_set_fll_refclk(struct madera_fll *fll, int source, 401 unsigned int fref, unsigned int fout); 402 int madera_set_fll_syncclk(struct madera_fll *fll, int source, 403 unsigned int fref, unsigned int fout); 404 int madera_set_fll_ao_refclk(struct madera_fll *fll, int source, 405 unsigned int fin, unsigned int fout); 406 407 int madera_core_init(struct madera_priv *priv); 408 int madera_core_free(struct madera_priv *priv); 409 int madera_init_overheat(struct madera_priv *priv); 410 int madera_free_overheat(struct madera_priv *priv); 411 int madera_init_inputs(struct snd_soc_component *component); 412 int madera_init_outputs(struct snd_soc_component *component, int n_mono_routes); 413 int madera_init_bus_error_irq(struct madera_priv *priv, int dsp_num, 414 irq_handler_t handler); 415 void madera_free_bus_error_irq(struct madera_priv *priv, int dsp_num); 416 417 int madera_init_dai(struct madera_priv *priv, int dai); 418 419 int madera_set_output_mode(struct snd_soc_component *component, int output, 420 bool differential); 421 422 /* Following functions are for use by machine drivers */ 423 static inline int madera_register_notifier(struct snd_soc_component *component, 424 struct notifier_block *nb) 425 { 426 struct madera_priv *priv = snd_soc_component_get_drvdata(component); 427 struct madera *madera = priv->madera; 428 429 return blocking_notifier_chain_register(&madera->notifier, nb); 430 } 431 432 static inline int 433 madera_unregister_notifier(struct snd_soc_component *component, 434 struct notifier_block *nb) 435 { 436 struct madera_priv *priv = snd_soc_component_get_drvdata(component); 437 struct madera *madera = priv->madera; 438 439 return blocking_notifier_chain_unregister(&madera->notifier, nb); 440 } 441 442 #endif 443