Lines Matching +full:dmic +full:- +full:sample +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0
12 #include "mt8192-afe-clk.h"
13 #include "mt8192-afe-common.h"
14 #include "mt8192-afe-gpio.h"
15 #include "mt8192-interconnection.h"
70 unsigned int rate) in adda_dl_rate_transform() argument
72 switch (rate) { in adda_dl_rate_transform()
96 dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", in adda_dl_rate_transform()
97 __func__, rate); in adda_dl_rate_transform()
103 unsigned int rate) in adda_ul_rate_transform() argument
105 switch (rate) { in adda_ul_rate_transform()
119 dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", in adda_ul_rate_transform()
120 __func__, rate); in adda_ul_rate_transform()
273 return -EINVAL; in mtk_adda_ul_src_dmic()
276 /* dmic mode, 3.25M*/ in mtk_adda_ul_src_dmic()
277 regmap_update_bits(afe->regmap, reg, in mtk_adda_ul_src_dmic()
280 regmap_update_bits(afe->regmap, reg, in mtk_adda_ul_src_dmic()
284 /* turn on dmic, ch1, ch2 */ in mtk_adda_ul_src_dmic()
285 regmap_update_bits(afe->regmap, reg, in mtk_adda_ul_src_dmic()
288 regmap_update_bits(afe->regmap, reg, in mtk_adda_ul_src_dmic()
291 regmap_update_bits(afe->regmap, reg, in mtk_adda_ul_src_dmic()
301 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_ul_event()
303 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mtk_adda_ul_event()
304 int mtkaif_dmic = afe_priv->mtkaif_dmic; in mtk_adda_ul_event()
306 dev_info(afe->dev, "%s(), name %s, event 0x%x, mtkaif_dmic %d\n", in mtk_adda_ul_event()
307 __func__, w->name, event, mtkaif_dmic); in mtk_adda_ul_event()
311 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1); in mtk_adda_ul_event()
313 /* update setting to dmic */ in mtk_adda_ul_event()
315 /* mtkaif_rxif_data_mode = 1, dmic */ in mtk_adda_ul_event()
316 regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_RX_CFG0, in mtk_adda_ul_event()
319 /* dmic mode, 3.25M*/ in mtk_adda_ul_event()
320 regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_RX_CFG0, in mtk_adda_ul_event()
329 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1); in mtk_adda_ul_event()
342 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_ch34_ul_event()
344 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mtk_adda_ch34_ul_event()
345 int mtkaif_dmic = afe_priv->mtkaif_dmic_ch34; in mtk_adda_ch34_ul_event()
346 int mtkaif_adda6_only = afe_priv->mtkaif_adda6_only; in mtk_adda_ch34_ul_event()
348 dev_info(afe->dev, in mtk_adda_ch34_ul_event()
350 __func__, w->name, event, mtkaif_dmic, mtkaif_adda6_only); in mtk_adda_ch34_ul_event()
354 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, in mtk_adda_ch34_ul_event()
357 /* update setting to dmic */ in mtk_adda_ch34_ul_event()
359 /* mtkaif_rxif_data_mode = 1, dmic */ in mtk_adda_ch34_ul_event()
360 regmap_update_bits(afe->regmap, in mtk_adda_ch34_ul_event()
364 /* dmic mode, 3.25M*/ in mtk_adda_ch34_ul_event()
365 regmap_update_bits(afe->regmap, in mtk_adda_ch34_ul_event()
377 regmap_update_bits(afe->regmap, in mtk_adda_ch34_ul_event()
385 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, in mtk_adda_ch34_ul_event()
388 /* reset dmic */ in mtk_adda_ch34_ul_event()
389 afe_priv->mtkaif_dmic_ch34 = 0; in mtk_adda_ch34_ul_event()
392 regmap_update_bits(afe->regmap, in mtk_adda_ch34_ul_event()
408 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_pad_top_event()
410 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mtk_adda_pad_top_event()
414 if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2_CLK_P2) in mtk_adda_pad_top_event()
415 regmap_write(afe->regmap, AFE_AUD_PAD_TOP, 0x38); in mtk_adda_pad_top_event()
417 regmap_write(afe->regmap, AFE_AUD_PAD_TOP, 0x30); in mtk_adda_pad_top_event()
430 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_mtkaif_cfg_event()
432 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mtk_adda_mtkaif_cfg_event()
438 if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2_CLK_P2) { in mtk_adda_mtkaif_cfg_event()
440 regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
442 regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
445 if (strcmp(w->name, "ADDA_MTKAIF_CFG") == 0 && in mtk_adda_mtkaif_cfg_event()
446 (afe_priv->mtkaif_chosen_phase[0] < 0 || in mtk_adda_mtkaif_cfg_event()
447 afe_priv->mtkaif_chosen_phase[1] < 0)) { in mtk_adda_mtkaif_cfg_event()
448 dev_warn(afe->dev, in mtk_adda_mtkaif_cfg_event()
451 afe_priv->mtkaif_chosen_phase[0], in mtk_adda_mtkaif_cfg_event()
452 afe_priv->mtkaif_chosen_phase[1]); in mtk_adda_mtkaif_cfg_event()
454 } else if (strcmp(w->name, "ADDA6_MTKAIF_CFG") == 0 && in mtk_adda_mtkaif_cfg_event()
455 afe_priv->mtkaif_chosen_phase[2] < 0) { in mtk_adda_mtkaif_cfg_event()
456 dev_warn(afe->dev, in mtk_adda_mtkaif_cfg_event()
459 afe_priv->mtkaif_chosen_phase[2]); in mtk_adda_mtkaif_cfg_event()
464 regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
467 regmap_update_bits(afe->regmap, AFE_ADDA6_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
472 if (afe_priv->mtkaif_phase_cycle[0] >= in mtk_adda_mtkaif_cfg_event()
473 afe_priv->mtkaif_phase_cycle[1]) { in mtk_adda_mtkaif_cfg_event()
475 delay_cycle = afe_priv->mtkaif_phase_cycle[0] - in mtk_adda_mtkaif_cfg_event()
476 afe_priv->mtkaif_phase_cycle[1]; in mtk_adda_mtkaif_cfg_event()
479 delay_cycle = afe_priv->mtkaif_phase_cycle[1] - in mtk_adda_mtkaif_cfg_event()
480 afe_priv->mtkaif_phase_cycle[0]; in mtk_adda_mtkaif_cfg_event()
483 regmap_update_bits(afe->regmap, in mtk_adda_mtkaif_cfg_event()
489 regmap_update_bits(afe->regmap, in mtk_adda_mtkaif_cfg_event()
496 if (afe_priv->mtkaif_phase_cycle[2] >= in mtk_adda_mtkaif_cfg_event()
497 afe_priv->mtkaif_phase_cycle[1]) { in mtk_adda_mtkaif_cfg_event()
499 delay_cycle = afe_priv->mtkaif_phase_cycle[2] - in mtk_adda_mtkaif_cfg_event()
500 afe_priv->mtkaif_phase_cycle[1]; in mtk_adda_mtkaif_cfg_event()
503 delay_cycle = afe_priv->mtkaif_phase_cycle[1] - in mtk_adda_mtkaif_cfg_event()
504 afe_priv->mtkaif_phase_cycle[2]; in mtk_adda_mtkaif_cfg_event()
507 regmap_update_bits(afe->regmap, in mtk_adda_mtkaif_cfg_event()
512 regmap_update_bits(afe->regmap, in mtk_adda_mtkaif_cfg_event()
517 } else if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2) { in mtk_adda_mtkaif_cfg_event()
518 regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
520 regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0, in mtk_adda_mtkaif_cfg_event()
523 regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0, 0x0); in mtk_adda_mtkaif_cfg_event()
524 regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0, 0x0); in mtk_adda_mtkaif_cfg_event()
538 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_dl_event()
541 dev_info(afe->dev, "%s(), name %s, event 0x%x\n", in mtk_adda_dl_event()
542 __func__, w->name, event); in mtk_adda_dl_event()
546 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0); in mtk_adda_dl_event()
551 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0); in mtk_adda_dl_event()
564 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_ch34_dl_event()
567 dev_info(afe->dev, "%s(), name %s, event 0x%x\n", in mtk_adda_ch34_dl_event()
568 __func__, w->name, event); in mtk_adda_ch34_dl_event()
572 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, in mtk_adda_ch34_dl_event()
578 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, in mtk_adda_ch34_dl_event()
594 struct mt8192_afe_private *afe_priv = afe->platform_priv; in stf_positive_gain_get()
596 ucontrol->value.integer.value[0] = afe_priv->stf_positive_gain_db; in stf_positive_gain_get()
605 struct mt8192_afe_private *afe_priv = afe->platform_priv; in stf_positive_gain_set()
606 int gain_db = ucontrol->value.integer.value[0]; in stf_positive_gain_set()
608 afe_priv->stf_positive_gain_db = gain_db; in stf_positive_gain_set()
611 regmap_update_bits(afe->regmap, in stf_positive_gain_set()
616 dev_warn(afe->dev, "%s(), gain_db %d invalid\n", in stf_positive_gain_set()
627 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_adda_dmic_get()
629 ucontrol->value.integer.value[0] = afe_priv->mtkaif_dmic; in mt8192_adda_dmic_get()
638 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_adda_dmic_set()
641 dmic_on = ucontrol->value.integer.value[0]; in mt8192_adda_dmic_set()
643 dev_info(afe->dev, "%s(), kcontrol name %s, dmic_on %d\n", in mt8192_adda_dmic_set()
644 __func__, kcontrol->id.name, dmic_on); in mt8192_adda_dmic_set()
646 afe_priv->mtkaif_dmic = dmic_on; in mt8192_adda_dmic_set()
647 afe_priv->mtkaif_dmic_ch34 = dmic_on; in mt8192_adda_dmic_set()
656 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_adda6_only_get()
658 ucontrol->value.integer.value[0] = afe_priv->mtkaif_adda6_only; in mt8192_adda6_only_get()
667 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_adda6_only_set()
670 mtkaif_adda6_only = ucontrol->value.integer.value[0]; in mt8192_adda6_only_set()
672 dev_info(afe->dev, "%s(), kcontrol name %s, mtkaif_adda6_only %d\n", in mt8192_adda6_only_set()
673 __func__, kcontrol->id.name, mtkaif_adda6_only); in mt8192_adda6_only_set()
675 afe_priv->mtkaif_adda6_only = mtkaif_adda6_only; in mt8192_adda6_only_set()
728 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_stf_event()
736 regmap_read(afe->regmap, AFE_ADDA_UL_SRC_CON0, &ul_rate); in mtk_stf_event()
751 regmap_read(afe->regmap, AFE_SIDETONE_CON1, &reg_value); in mtk_stf_event()
753 dev_info(afe->dev, "%s(), name %s, event 0x%x, ul_rate 0x%x, AFE_SIDETONE_CON1 0x%x\n", in mtk_stf_event()
754 __func__, w->name, event, ul_rate, reg_value); in mtk_stf_event()
759 regmap_update_bits(afe->regmap, in mtk_stf_event()
763 regmap_update_bits(afe->regmap, in mtk_stf_event()
768 regmap_update_bits(afe->regmap, in mtk_stf_event()
773 regmap_update_bits(afe->regmap, in mtk_stf_event()
779 regmap_read(afe->regmap, AFE_SIDETONE_CON0, &reg_value); in mtk_stf_event()
785 regmap_update_bits(afe->regmap, in mtk_stf_event()
797 regmap_read(afe->regmap, in mtk_stf_event()
805 dev_warn(afe->dev, in mtk_stf_event()
813 /* need write -> read -> write to write next coeff */ in mtk_stf_event()
814 regmap_update_bits(afe->regmap, in mtk_stf_event()
822 regmap_update_bits(afe->regmap, in mtk_stf_event()
828 regmap_update_bits(afe->regmap, in mtk_stf_event()
832 regmap_update_bits(afe->regmap, in mtk_stf_event()
925 /* inter-connections */
1105 {"ADDA_UL_Mux", "AP_DMIC", "AP DMIC Capture"},
1108 {"ADDA_CH34_UL_Mux", "AP_DMIC", "AP DMIC CH34 Capture"},
1115 {"AP DMIC Capture", NULL, "ADDA Enable"},
1116 {"AP DMIC Capture", NULL, "ADDA Capture Enable"},
1117 {"AP DMIC Capture", NULL, "ADDA_FIFO"},
1118 {"AP DMIC Capture", NULL, "AP_DMIC_EN"},
1125 {"AP DMIC CH34 Capture", NULL, "ADDA Enable"},
1126 {"AP DMIC CH34 Capture", NULL, "ADDA CH34 Capture Enable"},
1127 {"AP DMIC CH34 Capture", NULL, "ADDA_CH34_FIFO"},
1128 {"AP DMIC CH34 Capture", NULL, "AP_DMIC_CH34_EN"},
1130 {"AP DMIC Capture", NULL, "AP_DMIC_INPUT"},
1131 {"AP DMIC CH34 Capture", NULL, "AP_DMIC_CH34_INPUT"},
1163 unsigned int rate = params_rate(params); in mtk_dai_adda_hw_params() local
1164 int id = dai->id; in mtk_dai_adda_hw_params()
1166 dev_info(afe->dev, "%s(), id %d, stream %d, rate %d\n", in mtk_dai_adda_hw_params()
1169 substream->stream, in mtk_dai_adda_hw_params()
1170 rate); in mtk_dai_adda_hw_params()
1172 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in mtk_dai_adda_hw_params()
1176 /* set sampling rate */ in mtk_dai_adda_hw_params()
1177 dl_src2_con0 = adda_dl_rate_transform(afe, rate) << in mtk_dai_adda_hw_params()
1187 /* set voice input data if input sample rate is 8k or 16k */ in mtk_dai_adda_hw_params()
1188 if (rate == 8000 || rate == 16000) in mtk_dai_adda_hw_params()
1191 /* SA suggest apply -0.3db to audio/speech path */ in mtk_dai_adda_hw_params()
1195 /* turn on down-link gain */ in mtk_dai_adda_hw_params()
1200 regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0); in mtk_dai_adda_hw_params()
1201 regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0); in mtk_dai_adda_hw_params()
1203 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1205 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1209 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1216 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1222 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1225 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1231 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1233 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1236 regmap_write(afe->regmap, AFE_ADDA_3RD_DAC_DL_SRC2_CON0, in mtk_dai_adda_hw_params()
1238 regmap_write(afe->regmap, AFE_ADDA_3RD_DAC_DL_SRC2_CON1, in mtk_dai_adda_hw_params()
1242 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1249 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1255 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1258 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1267 voice_mode = adda_ul_rate_transform(afe, rate); in mtk_dai_adda_hw_params()
1281 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1283 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1285 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1287 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1289 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1292 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1296 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1302 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1310 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1312 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1314 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1316 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1318 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1321 regmap_write(afe->regmap, in mtk_dai_adda_hw_params()
1325 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1331 regmap_update_bits(afe->regmap, in mtk_dai_adda_hw_params()
1340 /* ap dmic */ in mtk_dai_adda_hw_params()
1417 .stream_name = "AP DMIC Capture",
1429 .stream_name = "AP DMIC CH34 Capture",
1442 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_dai_adda_register()
1444 dev_info(afe->dev, "%s()\n", __func__); in mt8192_dai_adda_register()
1446 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8192_dai_adda_register()
1448 return -ENOMEM; in mt8192_dai_adda_register()
1450 list_add(&dai->list, &afe->sub_dais); in mt8192_dai_adda_register()
1452 dai->dai_drivers = mtk_dai_adda_driver; in mt8192_dai_adda_register()
1453 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver); in mt8192_dai_adda_register()
1455 dai->controls = mtk_adda_controls; in mt8192_dai_adda_register()
1456 dai->num_controls = ARRAY_SIZE(mtk_adda_controls); in mt8192_dai_adda_register()
1457 dai->dapm_widgets = mtk_dai_adda_widgets; in mt8192_dai_adda_register()
1458 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets); in mt8192_dai_adda_register()
1459 dai->dapm_routes = mtk_dai_adda_routes; in mt8192_dai_adda_register()
1460 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes); in mt8192_dai_adda_register()
1462 /* ap dmic priv share with adda */ in mt8192_dai_adda_register()
1463 afe_priv->dai_priv[MT8192_DAI_AP_DMIC] = in mt8192_dai_adda_register()
1464 afe_priv->dai_priv[MT8192_DAI_ADDA]; in mt8192_dai_adda_register()
1465 afe_priv->dai_priv[MT8192_DAI_AP_DMIC_CH34] = in mt8192_dai_adda_register()
1466 afe_priv->dai_priv[MT8192_DAI_ADDA_CH34]; in mt8192_dai_adda_register()