Lines Matching +full:adc +full:- +full:mux

1 // SPDX-License-Identifier: GPL-2.0
3 // mt6351.c -- mt6351 ALSA SoC audio codec driver
8 #include <linux/dma-mapping.h>
202 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2, in set_hp_gain_zero()
204 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2, in set_hp_gain_zero()
225 dev_warn(cmpnt->dev, "%s(), error rate %d, return 3", in get_cap_reg_val()
256 dev_warn(cmpnt->dev, "%s(), error rate %d, return 8", in get_play_reg_val()
266 struct snd_soc_component *cmpnt = dai->component; in mt6351_codec_dai_hw_params()
270 dev_dbg(priv->dev, "%s(), substream->stream %d, rate %d\n", in mt6351_codec_dai_hw_params()
271 __func__, substream->stream, rate); in mt6351_codec_dai_hw_params()
273 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in mt6351_codec_dai_hw_params()
274 priv->dl_rate = rate; in mt6351_codec_dai_hw_params()
275 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt6351_codec_dai_hw_params()
276 priv->ul_rate = rate; in mt6351_codec_dai_hw_params()
291 .name = "mt6351-snd-codec-aif1",
329 old_idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]; in hp_gain_ramp_set()
331 idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]; in hp_gain_ramp_set()
334 dev_dbg(priv->dev, "%s(), idx %d, old_idx %d\n", in hp_gain_ramp_set()
338 offset = idx - old_idx; in hp_gain_ramp_set()
340 offset = old_idx - idx; in hp_gain_ramp_set()
345 reg_idx = idx > old_idx ? reg_idx + 1 : reg_idx - 1; in hp_gain_ramp_set()
349 regmap_update_bits(cmpnt->regmap, in hp_gain_ramp_set()
355 offset--; in hp_gain_ramp_set()
363 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 8, 0x1 << 8); in hp_zcd_enable()
364 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 7, 0x0 << 7); in hp_zcd_enable()
367 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 6, 0x1 << 6); in hp_zcd_enable()
369 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x3 << 4, 0x0 << 4); in hp_zcd_enable()
370 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 1, 0x5 << 1); in hp_zcd_enable()
371 regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 0, 0x1 << 0); in hp_zcd_enable()
376 regmap_write(cmpnt->regmap, MT6351_ZCD_CON0, 0x0000); in hp_zcd_disable()
379 static const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0);
400 /* MUX */
402 /* LOL MUX */
421 /*HP MUX */
450 /* RCV MUX */
469 /* DAC In MUX */
488 /* AIF Out MUX */
499 /* ADC L MUX */
516 SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum);
518 /* ADC R MUX */
535 SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum);
537 /* PGA L MUX */
556 /* PGA R MUX */
579 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_reg_set_clr_event()
583 if (w->on_val) { in mt_reg_set_clr_event()
585 regmap_update_bits(cmpnt->regmap, in mt_reg_set_clr_event()
586 w->reg + REG_STRIDE, in mt_reg_set_clr_event()
587 0x1 << w->shift, in mt_reg_set_clr_event()
588 0x1 << w->shift); in mt_reg_set_clr_event()
591 regmap_update_bits(cmpnt->regmap, in mt_reg_set_clr_event()
592 w->reg + REG_STRIDE * 2, in mt_reg_set_clr_event()
593 0x1 << w->shift, in mt_reg_set_clr_event()
594 0x1 << w->shift); in mt_reg_set_clr_event()
598 if (w->off_val) { in mt_reg_set_clr_event()
600 regmap_update_bits(cmpnt->regmap, in mt_reg_set_clr_event()
601 w->reg + REG_STRIDE, in mt_reg_set_clr_event()
602 0x1 << w->shift, in mt_reg_set_clr_event()
603 0x1 << w->shift); in mt_reg_set_clr_event()
606 regmap_update_bits(cmpnt->regmap, in mt_reg_set_clr_event()
607 w->reg + REG_STRIDE * 2, in mt_reg_set_clr_event()
608 0x1 << w->shift, in mt_reg_set_clr_event()
609 0x1 << w->shift); in mt_reg_set_clr_event()
623 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_ncp_event()
627 regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG1, in mt_ncp_event()
630 regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG0, in mt_ncp_event()
647 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_sgen_event()
651 regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG0, in mt_sgen_event()
653 regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG1, in mt_sgen_event()
667 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_aif_in_event()
670 dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n", in mt_aif_in_event()
671 __func__, event, priv->dl_rate); in mt_aif_in_event()
676 regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, in mt_aif_in_event()
679 regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON0, in mt_aif_in_event()
682 regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, in mt_aif_in_event()
685 regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2, in mt_aif_in_event()
688 regmap_update_bits(cmpnt->regmap, MT6351_AFE_DL_SDM_CON1, in mt_aif_in_event()
691 regmap_write(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG0, in mt_aif_in_event()
692 (get_play_reg_val(cmpnt, priv->dl_rate) << 12) | in mt_aif_in_event()
694 regmap_write(cmpnt->regmap, MT6351_AFE_DL_SRC2_CON0_H, in mt_aif_in_event()
695 (get_play_reg_val(cmpnt, priv->dl_rate) << 12) | in mt_aif_in_event()
698 regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2, in mt_aif_in_event()
712 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_hp_event()
716 dev_dbg(priv->dev, "%s(), event 0x%x, hp_en_counter %d\n", in mt_hp_event()
717 __func__, event, priv->hp_en_counter); in mt_hp_event()
721 priv->hp_en_counter++; in mt_hp_event()
722 if (priv->hp_en_counter > 1) in mt_hp_event()
724 else if (priv->hp_en_counter <= 0) in mt_hp_event()
725 dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", in mt_hp_event()
727 priv->hp_en_counter); in mt_hp_event()
732 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6, in mt_hp_event()
736 regmap_read(cmpnt->regmap, MT6351_ZCD_CON2, &reg); in mt_hp_event()
737 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = reg & 0x1f; in mt_hp_event()
738 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = (reg >> 7) & 0x1f; in mt_hp_event()
740 /* Set HPR/HPL gain as minimum (~ -40dB) */ in mt_hp_event()
741 regmap_update_bits(cmpnt->regmap, in mt_hp_event()
743 /* Set HS gain as minimum (~ -40dB) */ in mt_hp_event()
744 regmap_update_bits(cmpnt->regmap, in mt_hp_event()
747 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON2, in mt_hp_event()
750 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, in mt_hp_event()
753 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, in mt_hp_event()
756 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, in mt_hp_event()
758 /* Enable pre-charge buffer */ in mt_hp_event()
759 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, in mt_hp_event()
768 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, in mt_hp_event()
770 /* Disable pre-charge buffer */ in mt_hp_event()
771 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1, in mt_hp_event()
774 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, in mt_hp_event()
779 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6, in mt_hp_event()
791 priv->hp_en_counter--; in mt_hp_event()
792 if (priv->hp_en_counter > 0) in mt_hp_event()
794 else if (priv->hp_en_counter < 0) in mt_hp_event()
795 dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", in mt_hp_event()
797 priv->hp_en_counter); in mt_hp_event()
802 /* Set HPR/HPL gain as -1dB, step by step */ in mt_hp_event()
808 if (priv->hp_en_counter > 0) in mt_hp_event()
810 else if (priv->hp_en_counter < 0) in mt_hp_event()
811 dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n", in mt_hp_event()
813 priv->hp_en_counter); in mt_hp_event()
816 regmap_update_bits(cmpnt->regmap, in mt_hp_event()
821 regmap_update_bits(cmpnt->regmap, in mt_hp_event()
840 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_aif_out_event()
843 dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n", in mt_aif_out_event()
844 __func__, event, priv->ul_rate); in mt_aif_out_event()
849 regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, in mt_aif_out_event()
852 regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, in mt_aif_out_event()
855 regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0, in mt_aif_out_event()
859 regmap_update_bits(cmpnt->regmap, MT6351_AFE_UL_SRC_CON0_H, in mt_aif_out_event()
861 get_cap_reg_val(cmpnt, priv->ul_rate) << 1); in mt_aif_out_event()
864 if (priv->ul_rate <= 48000) { in mt_aif_out_event()
866 regmap_update_bits(cmpnt->regmap, in mt_aif_out_event()
871 regmap_update_bits(cmpnt->regmap, in mt_aif_out_event()
879 if (priv->ul_rate <= 48000) { in mt_aif_out_event()
881 regmap_update_bits(cmpnt->regmap, in mt_aif_out_event()
886 regmap_update_bits(cmpnt->regmap, in mt_aif_out_event()
903 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_adc_clkgen_event()
907 /* Audio ADC clock gen. mode: 00_divided by 2 (Normal) */ in mt_adc_clkgen_event()
908 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3, in mt_adc_clkgen_event()
912 /* ADC CLK from: 00_13MHz from CLKSQ (Default) */ in mt_adc_clkgen_event()
913 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3, in mt_adc_clkgen_event()
926 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_left_event()
931 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, in mt_pga_left_event()
935 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, in mt_pga_left_event()
942 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0, in mt_pga_left_event()
956 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_right_event()
961 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, in mt_pga_right_event()
965 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, in mt_pga_right_event()
972 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1, in mt_pga_right_event()
986 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_0_event()
991 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_0_event()
994 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_0_event()
1000 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_0_event()
1014 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_1_event()
1019 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, in mt_mic_bias_1_event()
1022 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, in mt_mic_bias_1_event()
1028 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10, in mt_mic_bias_1_event()
1042 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_2_event()
1047 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_2_event()
1050 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_2_event()
1056 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9, in mt_mic_bias_2_event()
1136 SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM, 0, 0, &dac_in_mux_control),
1148 SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM, 0, 0, &lo_in_mux_control),
1159 SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0, &hpl_in_mux_control),
1160 SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0, &hpr_in_mux_control),
1176 SND_SOC_DAPM_MUX("RCV Mux", SND_SOC_NOPM, 0, 0, &rcv_in_mux_control),
1223 SND_SOC_DAPM_SUPPLY_S("ADC CLKGEN", SUPPLY_SUBSEQ_ENABLE,
1228 /* Uplinks MUX */
1229 SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM, 0, 0,
1232 SND_SOC_DAPM_MUX("ADC L Mux", SND_SOC_NOPM, 0, 0,
1234 SND_SOC_DAPM_MUX("ADC R Mux", SND_SOC_NOPM, 0, 0,
1237 SND_SOC_DAPM_ADC("ADC L", NULL,
1239 SND_SOC_DAPM_ADC("ADC R", NULL,
1242 SND_SOC_DAPM_MUX("PGA L Mux", SND_SOC_NOPM, 0, 0,
1244 SND_SOC_DAPM_MUX("PGA R Mux", SND_SOC_NOPM, 0, 0,
1285 {"AIF1TX", NULL, "AIF Out Mux"},
1301 {"AIF Out Mux", "Normal Path", "ADC L"},
1302 {"AIF Out Mux", "Normal Path", "ADC R"},
1304 {"ADC L", NULL, "ADC L Mux"},
1305 {"ADC L", NULL, "AUD_CK"},
1306 {"ADC L", NULL, "AUDIF_CK"},
1307 {"ADC L", NULL, "ADC CLKGEN"},
1308 {"ADC R", NULL, "ADC R Mux"},
1309 {"ADC R", NULL, "AUD_CK"},
1310 {"ADC R", NULL, "AUDIF_CK"},
1311 {"ADC R", NULL, "ADC CLKGEN"},
1313 {"ADC L Mux", "AIN0", "AIN0"},
1314 {"ADC L Mux", "Left Preamplifier", "PGA L"},
1316 {"ADC R Mux", "AIN0", "AIN0"},
1317 {"ADC R Mux", "Right Preamplifier", "PGA R"},
1319 {"PGA L", NULL, "PGA L Mux"},
1320 {"PGA R", NULL, "PGA R Mux"},
1322 {"PGA L Mux", "AIN0", "AIN0"},
1323 {"PGA L Mux", "AIN1", "AIN1"},
1324 {"PGA L Mux", "AIN2", "AIN2"},
1326 {"PGA R Mux", "AIN0", "AIN0"},
1327 {"PGA R Mux", "AIN3", "AIN3"},
1328 {"PGA R Mux", "AIN2", "AIN2"},
1361 {"DAC In Mux", "Normal Path", "AIF_RX"},
1363 {"DAC In Mux", "Sgen", "SGEN DL"},
1369 {"DACL", NULL, "DAC In Mux"},
1373 {"DACR", NULL, "DAC In Mux"},
1377 {"LOL Mux", "Playback", "DACL"},
1379 {"LOL Buffer", NULL, "LOL Mux"},
1386 {"HPL Mux", "Audio Playback", "DACL"},
1387 {"HPR Mux", "Audio Playback", "DACR"},
1389 {"HPL Mux", "LoudSPK Playback", "DACL"},
1390 {"HPR Mux", "LoudSPK Playback", "DACR"},
1392 {"HPL Power", NULL, "HPL Mux"},
1393 {"HPR Power", NULL, "HPR Mux"},
1399 {"RCV Mux", "Voice Playback", "DACL"},
1401 {"RCV Buffer", NULL, "RCV Mux"},
1411 regmap_update_bits(cmpnt->regmap, MT6351_TOP_CLKSQ, 0x0001, 0x0); in mt6351_codec_init_reg()
1413 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON9, in mt6351_codec_init_reg()
1416 regmap_update_bits(cmpnt->regmap, MT6351_TOP_CKPDN_CON0_SET, in mt6351_codec_init_reg()
1419 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0, in mt6351_codec_init_reg()
1422 regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON3, in mt6351_codec_init_reg()
1425 regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2, in mt6351_codec_init_reg()
1434 snd_soc_component_init_regmap(cmpnt, priv->regmap); in mt6351_codec_probe()
1455 priv = devm_kzalloc(&pdev->dev, in mt6351_codec_driver_probe()
1459 return -ENOMEM; in mt6351_codec_driver_probe()
1461 dev_set_drvdata(&pdev->dev, priv); in mt6351_codec_driver_probe()
1463 priv->dev = &pdev->dev; in mt6351_codec_driver_probe()
1465 priv->regmap = dev_get_regmap(pdev->dev.parent, NULL); in mt6351_codec_driver_probe()
1466 if (!priv->regmap) in mt6351_codec_driver_probe()
1467 return -ENODEV; in mt6351_codec_driver_probe()
1469 dev_dbg(priv->dev, "%s(), dev name %s\n", in mt6351_codec_driver_probe()
1470 __func__, dev_name(&pdev->dev)); in mt6351_codec_driver_probe()
1472 return devm_snd_soc_register_component(&pdev->dev, in mt6351_codec_driver_probe()
1479 {.compatible = "mediatek,mt6351-sound",},
1485 .name = "mt6351-sound",