Lines Matching +full:ain0 +full:- +full:ain1
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);
501 "Idle", "AIN0", "Left Preamplifier", "Idle_1",
520 "Idle", "AIN0", "Right Preamplifier", "Idle_1",
539 "None", "AIN0", "AIN1", "AIN2",
558 "None", "AIN0", "AIN3", "AIN2",
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, ®); 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()
908 regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3, 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()
1277 SND_SOC_DAPM_INPUT("AIN0"),
1278 SND_SOC_DAPM_INPUT("AIN1"),
1313 {"ADC L Mux", "AIN0", "AIN0"},
1316 {"ADC R Mux", "AIN0", "AIN0"},
1322 {"PGA L Mux", "AIN0", "AIN0"},
1323 {"PGA L Mux", "AIN1", "AIN1"},
1326 {"PGA R Mux", "AIN0", "AIN0"},
1330 {"AIN0", NULL, "Mic Bias 0"},
1333 {"AIN1", NULL, "Mic Bias 1"},
1334 {"AIN1", NULL, "Mic Bias 1 DCC pull high"},
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",