Lines Matching +full:spk +full:- +full:shutdown
1 // SPDX-License-Identifier: GPL-2.0
3 // mt6359.c -- mt6359 ALSA SoC audio codec driver
24 regmap_write(priv->regmap, MT6359_GPIO_MODE2_CLR, 0x0ffe); in mt6359_set_playback_gpio()
25 regmap_write(priv->regmap, MT6359_GPIO_MODE2_SET, 0x0249); in mt6359_set_playback_gpio()
28 regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x6); in mt6359_set_playback_gpio()
29 regmap_write(priv->regmap, MT6359_GPIO_MODE3_SET, 0x1); in mt6359_set_playback_gpio()
39 regmap_write(priv->regmap, MT6359_GPIO_MODE2_CLR, 0x0ff8); in mt6359_reset_playback_gpio()
40 regmap_update_bits(priv->regmap, MT6359_GPIO_DIR0, 0x7 << 9, 0x0); in mt6359_reset_playback_gpio()
46 regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x0e00); in mt6359_set_capture_gpio()
47 regmap_write(priv->regmap, MT6359_GPIO_MODE3_SET, 0x0200); in mt6359_set_capture_gpio()
49 regmap_write(priv->regmap, MT6359_GPIO_MODE4_CLR, 0x003f); in mt6359_set_capture_gpio()
50 regmap_write(priv->regmap, MT6359_GPIO_MODE4_SET, 0x0009); in mt6359_set_capture_gpio()
61 regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x0e00); in mt6359_reset_capture_gpio()
63 regmap_write(priv->regmap, MT6359_GPIO_MODE4_CLR, 0x003f); in mt6359_reset_capture_gpio()
65 regmap_update_bits(priv->regmap, MT6359_GPIO_DIR0, in mt6359_reset_capture_gpio()
67 regmap_update_bits(priv->regmap, MT6359_GPIO_DIR1, in mt6359_reset_capture_gpio()
74 regmap_update_bits(priv->regmap, MT6359_DCXO_CW12, in mt6359_set_dcxo()
83 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23, in mt6359_set_clksq()
91 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON13, in mt6359_set_aud_global_bias()
99 regmap_update_bits(priv->regmap, MT6359_AUD_TOP_CKPDN_CON0, in mt6359_set_topck()
105 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON13, in mt6359_set_decoder_clk()
112 switch (priv->mtkaif_protocol) { in mt6359_mtkaif_tx_enable()
115 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
119 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
122 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
128 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
132 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
139 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
143 regmap_update_bits(priv->regmap, in mt6359_mtkaif_tx_enable()
153 regmap_update_bits(priv->regmap, MT6359_AFE_AUD_PAD_TOP, in mt6359_mtkaif_tx_disable()
162 priv->mtkaif_protocol = mtkaif_protocol; in mt6359_set_mtkaif_protocol()
180 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_mtkaif_calibration_enable()
183 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_mtkaif_calibration_enable()
186 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1, in mt6359_mtkaif_calibration_enable()
197 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_mtkaif_calibration_disable()
200 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_mtkaif_calibration_disable()
203 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1, in mt6359_mtkaif_calibration_disable()
223 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_set_mtkaif_calibration_phase()
226 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG, in mt6359_set_mtkaif_calibration_phase()
229 regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1, in mt6359_set_mtkaif_calibration_phase()
237 regmap_write(priv->regmap, MT6359_ZCD_CON0, 0x0000); in zcd_disable()
247 stage = up ? i : target - i; in hp_main_output_ramp()
248 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, in hp_main_output_ramp()
251 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, in hp_main_output_ramp()
265 stage = up ? i : target - i; in hp_aux_feedback_loop_gain_ramp()
266 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON9, in hp_aux_feedback_loop_gain_ramp()
277 /* Set input diff pair bias select (Hi-Fi mode) */ in hp_in_pair_current()
278 if (priv->hp_hifi_mode) { in hp_in_pair_current()
281 stage = increase ? i : target - i; in hp_in_pair_current()
282 regmap_update_bits(priv->regmap, in hp_in_pair_current()
296 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2, in hp_pull_down()
302 for (i = 0x7; i >= 0x0; i--) { in hp_pull_down()
303 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2, in hp_pull_down()
323 dev_warn(priv->dev, "%s(), volume index is not valid, from %d, to %d\n", in headset_volume_ramp()
328 dev_dbg(priv->dev, "%s(), from %d, to %d\n", __func__, from, to); in headset_volume_ramp()
331 offset = to - from; in headset_volume_ramp()
333 offset = from - to; in headset_volume_ramp()
339 reg_idx = from - count; in headset_volume_ramp()
342 regmap_update_bits(priv->regmap, in headset_volume_ramp()
348 offset--; in headset_volume_ramp()
360 (struct soc_mixer_control *)kcontrol->private_value; in mt6359_put_volsw()
362 int index = ucontrol->value.integer.value[0]; in mt6359_put_volsw()
369 switch (mc->reg) { in mt6359_put_volsw()
371 regmap_read(priv->regmap, MT6359_ZCD_CON2, ®); in mt6359_put_volsw()
372 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = in mt6359_put_volsw()
374 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = in mt6359_put_volsw()
378 regmap_read(priv->regmap, MT6359_ZCD_CON1, ®); in mt6359_put_volsw()
379 priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] = in mt6359_put_volsw()
381 priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] = in mt6359_put_volsw()
385 regmap_read(priv->regmap, MT6359_ZCD_CON3, ®); in mt6359_put_volsw()
386 priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL] = in mt6359_put_volsw()
390 regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON0, ®); in mt6359_put_volsw()
391 priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] = in mt6359_put_volsw()
395 regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON1, ®); in mt6359_put_volsw()
396 priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] = in mt6359_put_volsw()
400 regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON2, ®); in mt6359_put_volsw()
401 priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3] = in mt6359_put_volsw()
406 dev_dbg(priv->dev, "%s(), name %s, reg(0x%x) = 0x%x, set index = %x\n", in mt6359_put_volsw()
407 __func__, kcontrol->id.name, mc->reg, reg, index); in mt6359_put_volsw()
731 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_sgen_event()
734 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_sgen_event()
739 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0006); in mt_sgen_event()
741 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba1); in mt_sgen_event()
743 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0003); in mt_sgen_event()
745 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x000b); in mt_sgen_event()
747 regmap_update_bits(priv->regmap, MT6359_AFE_SGEN_CFG0, in mt_sgen_event()
750 regmap_update_bits(priv->regmap, MT6359_AFE_SGEN_CFG1, in mt_sgen_event()
756 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0000); in mt_sgen_event()
757 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba0); in mt_sgen_event()
768 if (priv->hp_hifi_mode) { in mtk_hp_enable()
770 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11, in mtk_hp_enable()
775 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mtk_hp_enable()
778 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mtk_hp_enable()
783 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11, in mtk_hp_enable()
788 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mtk_hp_enable()
791 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mtk_hp_enable()
798 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x0087); in mtk_hp_enable()
802 if (priv->dl_rate[MT6359_AIF_1] >= 96000) in mtk_hp_enable()
803 regmap_update_bits(priv->regmap, in mtk_hp_enable()
808 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON4, 0x0000); in mtk_hp_enable()
811 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON2, 0xf133); in mtk_hp_enable()
814 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x000c); in mtk_hp_enable()
816 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x003c); in mtk_hp_enable()
818 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0c00); in mtk_hp_enable()
820 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30c0); in mtk_hp_enable()
822 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30f0); in mtk_hp_enable()
824 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x00fc); in mtk_hp_enable()
830 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0e00); in mtk_hp_enable()
832 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0200); in mtk_hp_enable()
835 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x00ff); in mtk_hp_enable()
842 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77cf); in mtk_hp_enable()
847 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]); in mtk_hp_enable()
850 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77c3); in mtk_hp_enable()
852 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x7703); in mtk_hp_enable()
859 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30ff); in mtk_hp_enable()
860 if (priv->hp_hifi_mode) { in mtk_hp_enable()
861 /* Enable low-noise mode of DAC */ in mtk_hp_enable()
862 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0xf201); in mtk_hp_enable()
864 /* Disable low-noise mode of DAC */ in mtk_hp_enable()
865 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0xf200); in mtk_hp_enable()
870 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x32ff); in mtk_hp_enable()
872 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x3aff); in mtk_hp_enable()
874 /* Disable Pull-down HPL/R to AVSS28_AUD */ in mtk_hp_enable()
880 /* Pull-down HPL/R to AVSS28_AUD */ in mtk_hp_disable()
884 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mtk_hp_disable()
887 /* Disable low-noise mode of DAC */ in mtk_hp_disable()
888 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON9, in mtk_hp_disable()
892 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mtk_hp_disable()
899 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77c3); in mtk_hp_disable()
901 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77cf); in mtk_hp_disable()
905 priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL], in mtk_hp_disable()
909 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77ff); in mtk_hp_disable()
918 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x3, 0x0); in mtk_hp_disable()
921 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0e01); in mtk_hp_disable()
924 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0c01); in mtk_hp_disable()
930 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, in mtk_hp_disable()
934 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mtk_hp_disable()
938 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mtk_hp_disable()
942 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x201); in mtk_hp_disable()
945 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, in mtk_hp_disable()
949 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, in mtk_hp_disable()
957 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_hp_event()
959 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in mt_hp_event()
962 dev_dbg(priv->dev, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n", in mt_hp_event()
963 __func__, event, priv->dev_counter[device], mux); in mt_hp_event()
967 priv->dev_counter[device]++; in mt_hp_event()
972 priv->dev_counter[device]--; in mt_hp_event()
987 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_rcv_event()
990 dev_dbg(priv->dev, "%s(), event 0x%x, mux %u\n", in mt_rcv_event()
991 __func__, event, dapm_kcontrol_get_value(w->kcontrols[0])); in mt_rcv_event()
995 /* Disable handset short-circuit protection */ in mt_rcv_event()
996 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0010); in mt_rcv_event()
999 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11, in mt_rcv_event()
1004 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mt_rcv_event()
1007 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mt_rcv_event()
1012 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0090); in mt_rcv_event()
1015 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x7000); in mt_rcv_event()
1018 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0092); in mt_rcv_event()
1020 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0093); in mt_rcv_event()
1023 regmap_write(priv->regmap, MT6359_ZCD_CON3, in mt_rcv_event()
1024 priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL]); in mt_rcv_event()
1030 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x0009); in mt_rcv_event()
1031 /* Enable low-noise mode of DAC */ in mt_rcv_event()
1032 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0001); in mt_rcv_event()
1034 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x009b); in mt_rcv_event()
1038 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6, in mt_rcv_event()
1043 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mt_rcv_event()
1050 regmap_write(priv->regmap, MT6359_ZCD_CON3, DL_GAIN_N_40DB); in mt_rcv_event()
1053 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6, in mt_rcv_event()
1057 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6, in mt_rcv_event()
1071 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_lo_event()
1074 dev_dbg(priv->dev, "%s(), event 0x%x, mux %u\n", in mt_lo_event()
1075 __func__, event, dapm_kcontrol_get_value(w->kcontrols[0])); in mt_lo_event()
1079 /* Disable handset short-circuit protection */ in mt_lo_event()
1080 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0010); in mt_lo_event()
1083 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11, in mt_lo_event()
1088 if (priv->dev_counter[DEVICE_HP] == 0) in mt_lo_event()
1089 regmap_update_bits(priv->regmap, in mt_lo_event()
1094 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12, in mt_lo_event()
1099 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0110); in mt_lo_event()
1102 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0112); in mt_lo_event()
1104 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0113); in mt_lo_event()
1107 regmap_write(priv->regmap, MT6359_ZCD_CON1, in mt_lo_event()
1108 priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL]); in mt_lo_event()
1114 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x3113); in mt_lo_event()
1115 /* Enable low-noise mode of DAC */ in mt_lo_event()
1116 if (priv->dev_counter[DEVICE_HP] == 0) in mt_lo_event()
1117 regmap_write(priv->regmap, in mt_lo_event()
1120 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x311b); in mt_lo_event()
1124 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7, in mt_lo_event()
1129 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mt_lo_event()
1136 regmap_write(priv->regmap, MT6359_ZCD_CON1, DL_GAIN_N_40DB); in mt_lo_event()
1139 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7, in mt_lo_event()
1143 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7, in mt_lo_event()
1157 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_adc_clk_gen_event()
1160 dev_dbg(priv->dev, "%s(), event 0x%x\n", __func__, event); in mt_adc_clk_gen_event()
1165 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1168 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1170 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1172 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1177 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1179 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1181 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1183 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5, in mt_adc_clk_gen_event()
1197 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_dcc_clk_event()
1200 dev_dbg(priv->dev, "%s(), event 0x%x\n", __func__, event); in mt_dcc_clk_event()
1206 regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0, in mt_dcc_clk_event()
1208 regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0, in mt_dcc_clk_event()
1210 regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0, in mt_dcc_clk_event()
1213 regmap_write(priv->regmap, MT6359_AFE_DCCLK_CFG1, 0x0100); in mt_dcc_clk_event()
1216 regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0, in mt_dcc_clk_event()
1218 regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0, in mt_dcc_clk_event()
1232 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_0_event()
1234 unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_0]; in mt_mic_bias_0_event()
1236 dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n", in mt_mic_bias_0_event()
1243 regmap_update_bits(priv->regmap, in mt_mic_bias_0_event()
1248 regmap_update_bits(priv->regmap, in mt_mic_bias_0_event()
1253 regmap_update_bits(priv->regmap, in mt_mic_bias_0_event()
1260 regmap_write(priv->regmap, in mt_mic_bias_0_event()
1263 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON15, in mt_mic_bias_0_event()
1267 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON15, in mt_mic_bias_0_event()
1273 regmap_write(priv->regmap, MT6359_AUDENC_ANA_CON15, 0x0000); in mt_mic_bias_0_event()
1286 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_1_event()
1288 unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_1]; in mt_mic_bias_1_event()
1290 dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n", in mt_mic_bias_1_event()
1297 regmap_write(priv->regmap, in mt_mic_bias_1_event()
1300 regmap_write(priv->regmap, in mt_mic_bias_1_event()
1304 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON16, in mt_mic_bias_1_event()
1319 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mic_bias_2_event()
1321 unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_2]; in mt_mic_bias_2_event()
1323 dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n", in mt_mic_bias_2_event()
1330 regmap_update_bits(priv->regmap, in mt_mic_bias_2_event()
1335 regmap_update_bits(priv->regmap, in mt_mic_bias_2_event()
1340 regmap_update_bits(priv->regmap, in mt_mic_bias_2_event()
1347 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON17, in mt_mic_bias_2_event()
1351 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON17, in mt_mic_bias_2_event()
1357 regmap_write(priv->regmap, MT6359_AUDENC_ANA_CON17, 0x0000); in mt_mic_bias_2_event()
1370 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_mtkaif_tx_event()
1373 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_mtkaif_tx_event()
1393 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_ul_src_dmic_event()
1396 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_ul_src_dmic_event()
1401 if (priv->dmic_one_wire_mode) in mt_ul_src_dmic_event()
1402 regmap_write(priv->regmap, MT6359_AFE_UL_SRC_CON0_H, in mt_ul_src_dmic_event()
1405 regmap_write(priv->regmap, MT6359_AFE_UL_SRC_CON0_H, in mt_ul_src_dmic_event()
1408 regmap_update_bits(priv->regmap, MT6359_AFE_UL_SRC_CON0_L, in mt_ul_src_dmic_event()
1412 regmap_write(priv->regmap, in mt_ul_src_dmic_event()
1426 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_ul_src_34_dmic_event()
1429 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_ul_src_34_dmic_event()
1434 regmap_write(priv->regmap, in mt_ul_src_34_dmic_event()
1436 regmap_update_bits(priv->regmap, MT6359_AFE_ADDA6_UL_SRC_CON0_L, in mt_ul_src_34_dmic_event()
1440 regmap_write(priv->regmap, in mt_ul_src_34_dmic_event()
1454 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_adc_l_event()
1457 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_adc_l_event()
1463 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0, in mt_adc_l_event()
1478 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_adc_r_event()
1481 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_adc_r_event()
1487 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1, in mt_adc_r_event()
1502 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_adc_3_event()
1505 dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event); in mt_adc_3_event()
1511 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2, in mt_adc_3_event()
1526 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_l_mux_event()
1528 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in mt_pga_l_mux_event()
1530 dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux); in mt_pga_l_mux_event()
1531 priv->mux_select[MUX_PGA_L] = mux >> RG_AUDPREAMPLINPUTSEL_SFT; in mt_pga_l_mux_event()
1539 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_r_mux_event()
1541 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in mt_pga_r_mux_event()
1543 dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux); in mt_pga_r_mux_event()
1544 priv->mux_select[MUX_PGA_R] = mux >> RG_AUDPREAMPRINPUTSEL_SFT; in mt_pga_r_mux_event()
1552 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_3_mux_event()
1554 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in mt_pga_3_mux_event()
1556 dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux); in mt_pga_3_mux_event()
1557 priv->mux_select[MUX_PGA_3] = mux >> RG_AUDPREAMP3INPUTSEL_SFT; in mt_pga_3_mux_event()
1565 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_l_event()
1567 int mic_gain_l = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1]; in mt_pga_l_event()
1568 unsigned int mux_pga = priv->mux_select[MUX_PGA_L]; in mt_pga_l_event()
1573 mic_type = priv->mux_select[MUX_MIC_TYPE_0]; in mt_pga_l_event()
1576 mic_type = priv->mux_select[MUX_MIC_TYPE_1]; in mt_pga_l_event()
1579 dev_err(priv->dev, "%s(), invalid pga mux %d\n", in mt_pga_l_event()
1581 return -EINVAL; in mt_pga_l_event()
1588 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0, in mt_pga_l_event()
1595 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0, in mt_pga_l_event()
1601 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0, in mt_pga_l_event()
1608 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0, in mt_pga_l_event()
1623 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_r_event()
1625 int mic_gain_r = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2]; in mt_pga_r_event()
1626 unsigned int mux_pga = priv->mux_select[MUX_PGA_R]; in mt_pga_r_event()
1631 mic_type = priv->mux_select[MUX_MIC_TYPE_0]; in mt_pga_r_event()
1635 mic_type = priv->mux_select[MUX_MIC_TYPE_2]; in mt_pga_r_event()
1638 dev_err(priv->dev, "%s(), invalid pga mux %d\n", in mt_pga_r_event()
1640 return -EINVAL; in mt_pga_r_event()
1647 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1, in mt_pga_r_event()
1654 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1, in mt_pga_r_event()
1660 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1, in mt_pga_r_event()
1667 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1, in mt_pga_r_event()
1682 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_pga_3_event()
1684 int mic_gain_3 = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3]; in mt_pga_3_event()
1685 unsigned int mux_pga = priv->mux_select[MUX_PGA_3]; in mt_pga_3_event()
1691 mic_type = priv->mux_select[MUX_MIC_TYPE_2]; in mt_pga_3_event()
1694 dev_err(priv->dev, "%s(), invalid pga mux %d\n", in mt_pga_3_event()
1696 return -EINVAL; in mt_pga_3_event()
1703 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2, in mt_pga_3_event()
1710 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2, in mt_pga_3_event()
1716 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2, in mt_pga_3_event()
1723 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2, in mt_pga_3_event()
1771 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_hp_pull_down_event()
1792 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_hp_mute_event()
1797 /* Set HPR/HPL gain to -22dB */ in mt_hp_mute_event()
1798 regmap_write(priv->regmap, MT6359_ZCD_CON2, DL_GAIN_N_22DB_REG); in mt_hp_mute_event()
1802 regmap_write(priv->regmap, MT6359_ZCD_CON2, DL_GAIN_N_40DB_REG); in mt_hp_mute_event()
1815 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_hp_damp_event()
1822 regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x0000); in mt_hp_damp_event()
1835 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_esd_resist_event()
1841 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2, in mt_esd_resist_event()
1848 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2, in mt_esd_resist_event()
1862 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_sdm_event()
1868 regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2, in mt_sdm_event()
1871 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba1); in mt_sdm_event()
1873 regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2, in mt_sdm_event()
1876 regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2, in mt_sdm_event()
1881 regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2, in mt_sdm_event()
1883 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba0); in mt_sdm_event()
1896 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_sdm_3rd_event()
1902 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0006); in mt_sdm_3rd_event()
1904 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON9, 0xcba1); in mt_sdm_3rd_event()
1906 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0003); in mt_sdm_3rd_event()
1908 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x000b); in mt_sdm_3rd_event()
1912 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0000); in mt_sdm_3rd_event()
1913 regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON9, 0xcba0); in mt_sdm_3rd_event()
1926 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_ncp_event()
1931 regmap_write(priv->regmap, MT6359_AFE_NCP_CFG0, 0xc800); in mt_ncp_event()
2115 SND_SOC_DAPM_OUTPUT("Headphone L Ext Spk Amp"),
2116 SND_SOC_DAPM_OUTPUT("Headphone R Ext Spk Amp"),
2302 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mt_dcc_clk_connect()
2305 if (IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_0]) || in mt_dcc_clk_connect()
2306 IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_1]) || in mt_dcc_clk_connect()
2307 IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_2])) in mt_dcc_clk_connect()
2517 {"Headphone L Ext Spk Amp", NULL, "HP Mux"},
2518 {"Headphone R Ext Spk Amp", NULL, "HP Mux"},
2529 struct snd_soc_component *cmpnt = dai->component; in mt6359_codec_dai_hw_params()
2532 int id = dai->id; in mt6359_codec_dai_hw_params()
2534 dev_dbg(priv->dev, "%s(), id %d, substream->stream %d, rate %d, number %d\n", in mt6359_codec_dai_hw_params()
2535 __func__, id, substream->stream, rate, substream->number); in mt6359_codec_dai_hw_params()
2537 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in mt6359_codec_dai_hw_params()
2538 priv->dl_rate[id] = rate; in mt6359_codec_dai_hw_params()
2539 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt6359_codec_dai_hw_params()
2540 priv->ul_rate[id] = rate; in mt6359_codec_dai_hw_params()
2548 struct snd_soc_component *cmpnt = dai->component; in mt6359_codec_dai_startup()
2551 dev_dbg(priv->dev, "%s stream %d\n", __func__, substream->stream); in mt6359_codec_dai_startup()
2552 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in mt6359_codec_dai_startup()
2554 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt6359_codec_dai_startup()
2563 struct snd_soc_component *cmpnt = dai->component; in mt6359_codec_dai_shutdown()
2566 dev_dbg(priv->dev, "%s stream %d\n", __func__, substream->stream); in mt6359_codec_dai_shutdown()
2567 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in mt6359_codec_dai_shutdown()
2569 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt6359_codec_dai_shutdown()
2576 .shutdown = mt6359_codec_dai_shutdown,
2586 .name = "mt6359-snd-codec-aif1",
2612 .name = "mt6359-snd-codec-aif2",
2641 regmap_update_bits(priv->regmap, MT6359_DCXO_CW12, in mt6359_codec_init_reg()
2648 regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23, in mt6359_codec_init_reg()
2653 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mt6359_codec_init_reg()
2656 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0, in mt6359_codec_init_reg()
2660 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6, in mt6359_codec_init_reg()
2664 regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7, in mt6359_codec_init_reg()
2673 priv->hp_hifi_mode = 0; in mt6359_codec_init_reg()
2679 regmap_update_bits(priv->regmap, MT6359_DCXO_CW12, in mt6359_codec_init_reg()
2690 snd_soc_component_init_regmap(cmpnt, priv->regmap); in mt6359_codec_probe()
2697 cmpnt->regmap = NULL; in mt6359_codec_remove()
2700 static const DECLARE_TLV_DB_SCALE(hp_playback_tlv, -2200, 100, 0);
2701 static const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0);
2745 struct device *dev = priv->dev; in mt6359_parse_dt()
2748 np = of_get_child_by_name(dev->parent->of_node, "mt6359codec"); in mt6359_parse_dt()
2750 return -EINVAL; in mt6359_parse_dt()
2752 ret = of_property_read_u32(np, "mediatek,dmic-mode", in mt6359_parse_dt()
2753 &priv->dmic_one_wire_mode); in mt6359_parse_dt()
2755 dev_info(priv->dev, in mt6359_parse_dt()
2756 "%s() failed to read dmic-mode, use default (0)\n", in mt6359_parse_dt()
2758 priv->dmic_one_wire_mode = 0; in mt6359_parse_dt()
2761 ret = of_property_read_u32(np, "mediatek,mic-type-0", in mt6359_parse_dt()
2762 &priv->mux_select[MUX_MIC_TYPE_0]); in mt6359_parse_dt()
2764 dev_info(priv->dev, in mt6359_parse_dt()
2765 "%s() failed to read mic-type-0, use default (%d)\n", in mt6359_parse_dt()
2767 priv->mux_select[MUX_MIC_TYPE_0] = MIC_TYPE_MUX_IDLE; in mt6359_parse_dt()
2770 ret = of_property_read_u32(np, "mediatek,mic-type-1", in mt6359_parse_dt()
2771 &priv->mux_select[MUX_MIC_TYPE_1]); in mt6359_parse_dt()
2773 dev_info(priv->dev, in mt6359_parse_dt()
2774 "%s() failed to read mic-type-1, use default (%d)\n", in mt6359_parse_dt()
2776 priv->mux_select[MUX_MIC_TYPE_1] = MIC_TYPE_MUX_IDLE; in mt6359_parse_dt()
2779 ret = of_property_read_u32(np, "mediatek,mic-type-2", in mt6359_parse_dt()
2780 &priv->mux_select[MUX_MIC_TYPE_2]); in mt6359_parse_dt()
2783 dev_info(priv->dev, in mt6359_parse_dt()
2784 "%s() failed to read mic-type-2, use default (%d)\n", in mt6359_parse_dt()
2786 priv->mux_select[MUX_MIC_TYPE_2] = MIC_TYPE_MUX_IDLE; in mt6359_parse_dt()
2796 struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent); in mt6359_platform_driver_probe()
2798 dev_dbg(&pdev->dev, "%s(), dev name %s\n", in mt6359_platform_driver_probe()
2799 __func__, dev_name(&pdev->dev)); in mt6359_platform_driver_probe()
2801 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt6359_platform_driver_probe()
2803 return -ENOMEM; in mt6359_platform_driver_probe()
2805 priv->regmap = mt6397->regmap; in mt6359_platform_driver_probe()
2806 if (IS_ERR(priv->regmap)) in mt6359_platform_driver_probe()
2807 return PTR_ERR(priv->regmap); in mt6359_platform_driver_probe()
2809 dev_set_drvdata(&pdev->dev, priv); in mt6359_platform_driver_probe()
2810 priv->dev = &pdev->dev; in mt6359_platform_driver_probe()
2814 dev_warn(&pdev->dev, "%s() failed to parse dts\n", __func__); in mt6359_platform_driver_probe()
2818 return devm_snd_soc_register_component(&pdev->dev, in mt6359_platform_driver_probe()
2826 .name = "mt6359-sound",