xref: /linux/sound/soc/codecs/mt6359.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
18061734aSJiaxin Yu // SPDX-License-Identifier: GPL-2.0
28061734aSJiaxin Yu //
38061734aSJiaxin Yu // mt6359.c  --  mt6359 ALSA SoC audio codec driver
48061734aSJiaxin Yu //
58061734aSJiaxin Yu // Copyright (c) 2020 MediaTek Inc.
68061734aSJiaxin Yu // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
78061734aSJiaxin Yu 
88061734aSJiaxin Yu #include <linux/delay.h>
98061734aSJiaxin Yu #include <linux/kthread.h>
108061734aSJiaxin Yu #include <linux/mfd/mt6397/core.h>
118061734aSJiaxin Yu #include <linux/module.h>
12*340d79a1SRob Herring #include <linux/of.h>
138061734aSJiaxin Yu #include <linux/platform_device.h>
148061734aSJiaxin Yu #include <linux/regulator/consumer.h>
158061734aSJiaxin Yu #include <linux/sched.h>
168061734aSJiaxin Yu #include <sound/soc.h>
178061734aSJiaxin Yu #include <sound/tlv.h>
188061734aSJiaxin Yu 
198061734aSJiaxin Yu #include "mt6359.h"
208061734aSJiaxin Yu 
mt6359_set_gpio_smt(struct mt6359_priv * priv)2124f398e7STrevor Wu static void mt6359_set_gpio_smt(struct mt6359_priv *priv)
2224f398e7STrevor Wu {
2324f398e7STrevor Wu 	/* set gpio SMT mode */
2424f398e7STrevor Wu 	regmap_update_bits(priv->regmap, MT6359_SMT_CON1, 0x3ff0, 0x3ff0);
2524f398e7STrevor Wu }
2624f398e7STrevor Wu 
mt6359_set_gpio_driving(struct mt6359_priv * priv)2724f398e7STrevor Wu static void mt6359_set_gpio_driving(struct mt6359_priv *priv)
2824f398e7STrevor Wu {
2924f398e7STrevor Wu 	/* 8:4mA(default), a:8mA, c:12mA, e:16mA */
3024f398e7STrevor Wu 	regmap_update_bits(priv->regmap, MT6359_DRV_CON2, 0xffff, 0x8888);
3124f398e7STrevor Wu 	regmap_update_bits(priv->regmap, MT6359_DRV_CON3, 0xffff, 0x8888);
3224f398e7STrevor Wu 	regmap_update_bits(priv->regmap, MT6359_DRV_CON4, 0x00ff, 0x88);
3324f398e7STrevor Wu }
3424f398e7STrevor Wu 
mt6359_set_playback_gpio(struct mt6359_priv * priv)358061734aSJiaxin Yu static void mt6359_set_playback_gpio(struct mt6359_priv *priv)
368061734aSJiaxin Yu {
378061734aSJiaxin Yu 	/* set gpio mosi mode, clk / data mosi */
388061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE2_CLR, 0x0ffe);
398061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE2_SET, 0x0249);
408061734aSJiaxin Yu 
418061734aSJiaxin Yu 	/* sync mosi */
428061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x6);
438061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE3_SET, 0x1);
448061734aSJiaxin Yu }
458061734aSJiaxin Yu 
mt6359_reset_playback_gpio(struct mt6359_priv * priv)468061734aSJiaxin Yu static void mt6359_reset_playback_gpio(struct mt6359_priv *priv)
478061734aSJiaxin Yu {
488061734aSJiaxin Yu 	/* set pad_aud_*_mosi to GPIO mode and dir input
498061734aSJiaxin Yu 	 * reason:
508061734aSJiaxin Yu 	 * pad_aud_dat_mosi*, because the pin is used as boot strap
518061734aSJiaxin Yu 	 * don't clean clk/sync, for mtkaif protocol 2
528061734aSJiaxin Yu 	 */
538061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE2_CLR, 0x0ff8);
548061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_GPIO_DIR0, 0x7 << 9, 0x0);
558061734aSJiaxin Yu }
568061734aSJiaxin Yu 
mt6359_set_capture_gpio(struct mt6359_priv * priv)578061734aSJiaxin Yu static void mt6359_set_capture_gpio(struct mt6359_priv *priv)
588061734aSJiaxin Yu {
598061734aSJiaxin Yu 	/* set gpio miso mode */
608061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x0e00);
618061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE3_SET, 0x0200);
628061734aSJiaxin Yu 
638061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE4_CLR, 0x003f);
648061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE4_SET, 0x0009);
658061734aSJiaxin Yu }
668061734aSJiaxin Yu 
mt6359_reset_capture_gpio(struct mt6359_priv * priv)678061734aSJiaxin Yu static void mt6359_reset_capture_gpio(struct mt6359_priv *priv)
688061734aSJiaxin Yu {
698061734aSJiaxin Yu 	/* set pad_aud_*_miso to GPIO mode and dir input
708061734aSJiaxin Yu 	 * reason:
718061734aSJiaxin Yu 	 * pad_aud_clk_miso, because when playback only the miso_clk
728061734aSJiaxin Yu 	 * will also have 26m, so will have power leak
738061734aSJiaxin Yu 	 * pad_aud_dat_miso*, because the pin is used as boot strap
748061734aSJiaxin Yu 	 */
758061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE3_CLR, 0x0e00);
768061734aSJiaxin Yu 
778061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_GPIO_MODE4_CLR, 0x003f);
788061734aSJiaxin Yu 
798061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_GPIO_DIR0,
808061734aSJiaxin Yu 			   0x7 << 13, 0x0);
818061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_GPIO_DIR1,
828061734aSJiaxin Yu 			   0x3 << 0, 0x0);
838061734aSJiaxin Yu }
848061734aSJiaxin Yu 
85682c5a72SJiaxin Yu /* use only when doing mtkaif calibraiton at the boot time */
mt6359_set_dcxo(struct mt6359_priv * priv,bool enable)86682c5a72SJiaxin Yu static void mt6359_set_dcxo(struct mt6359_priv *priv, bool enable)
87682c5a72SJiaxin Yu {
88682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_DCXO_CW12,
89682c5a72SJiaxin Yu 			   0x1 << RG_XO_AUDIO_EN_M_SFT,
90682c5a72SJiaxin Yu 			   (enable ? 1 : 0) << RG_XO_AUDIO_EN_M_SFT);
91682c5a72SJiaxin Yu }
92682c5a72SJiaxin Yu 
93682c5a72SJiaxin Yu /* use only when doing mtkaif calibraiton at the boot time */
mt6359_set_clksq(struct mt6359_priv * priv,bool enable)94682c5a72SJiaxin Yu static void mt6359_set_clksq(struct mt6359_priv *priv, bool enable)
95682c5a72SJiaxin Yu {
96682c5a72SJiaxin Yu 	/* Enable/disable CLKSQ 26MHz */
97682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23,
98682c5a72SJiaxin Yu 			   RG_CLKSQ_EN_MASK_SFT,
99682c5a72SJiaxin Yu 			   (enable ? 1 : 0) << RG_CLKSQ_EN_SFT);
100682c5a72SJiaxin Yu }
101682c5a72SJiaxin Yu 
102682c5a72SJiaxin Yu /* use only when doing mtkaif calibraiton at the boot time */
mt6359_set_aud_global_bias(struct mt6359_priv * priv,bool enable)103682c5a72SJiaxin Yu static void mt6359_set_aud_global_bias(struct mt6359_priv *priv, bool enable)
104682c5a72SJiaxin Yu {
105682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON13,
106682c5a72SJiaxin Yu 			   RG_AUDGLB_PWRDN_VA32_MASK_SFT,
107682c5a72SJiaxin Yu 			   (enable ? 0 : 1) << RG_AUDGLB_PWRDN_VA32_SFT);
108682c5a72SJiaxin Yu }
109682c5a72SJiaxin Yu 
110682c5a72SJiaxin Yu /* use only when doing mtkaif calibraiton at the boot time */
mt6359_set_topck(struct mt6359_priv * priv,bool enable)111682c5a72SJiaxin Yu static void mt6359_set_topck(struct mt6359_priv *priv, bool enable)
112682c5a72SJiaxin Yu {
113682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUD_TOP_CKPDN_CON0,
114682c5a72SJiaxin Yu 			   0x0066, enable ? 0x0 : 0x66);
115682c5a72SJiaxin Yu }
116682c5a72SJiaxin Yu 
mt6359_set_decoder_clk(struct mt6359_priv * priv,bool enable)1178061734aSJiaxin Yu static void mt6359_set_decoder_clk(struct mt6359_priv *priv, bool enable)
1188061734aSJiaxin Yu {
1198061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON13,
1208061734aSJiaxin Yu 			   RG_RSTB_DECODER_VA32_MASK_SFT,
1218061734aSJiaxin Yu 			   (enable ? 1 : 0) << RG_RSTB_DECODER_VA32_SFT);
1228061734aSJiaxin Yu }
1238061734aSJiaxin Yu 
mt6359_mtkaif_tx_enable(struct mt6359_priv * priv)1248061734aSJiaxin Yu static void mt6359_mtkaif_tx_enable(struct mt6359_priv *priv)
1258061734aSJiaxin Yu {
1268061734aSJiaxin Yu 	switch (priv->mtkaif_protocol) {
1278061734aSJiaxin Yu 	case MT6359_MTKAIF_PROTOCOL_2_CLK_P2:
1288061734aSJiaxin Yu 		/* MTKAIF TX format setting */
1298061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1308061734aSJiaxin Yu 				   MT6359_AFE_ADDA_MTKAIF_CFG0,
1318061734aSJiaxin Yu 				   0xffff, 0x0210);
1328061734aSJiaxin Yu 		/* enable aud_pad TX fifos */
1338061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1348061734aSJiaxin Yu 				   MT6359_AFE_AUD_PAD_TOP,
1358061734aSJiaxin Yu 				   0xff00, 0x3800);
1368061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1378061734aSJiaxin Yu 				   MT6359_AFE_AUD_PAD_TOP,
1388061734aSJiaxin Yu 				   0xff00, 0x3900);
1398061734aSJiaxin Yu 		break;
1408061734aSJiaxin Yu 	case MT6359_MTKAIF_PROTOCOL_2:
1418061734aSJiaxin Yu 		/* MTKAIF TX format setting */
1428061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1438061734aSJiaxin Yu 				   MT6359_AFE_ADDA_MTKAIF_CFG0,
1448061734aSJiaxin Yu 				   0xffff, 0x0210);
1458061734aSJiaxin Yu 		/* enable aud_pad TX fifos */
1468061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1478061734aSJiaxin Yu 				   MT6359_AFE_AUD_PAD_TOP,
1488061734aSJiaxin Yu 				   0xff00, 0x3100);
1498061734aSJiaxin Yu 		break;
1508061734aSJiaxin Yu 	case MT6359_MTKAIF_PROTOCOL_1:
1518061734aSJiaxin Yu 	default:
1528061734aSJiaxin Yu 		/* MTKAIF TX format setting */
1538061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1548061734aSJiaxin Yu 				   MT6359_AFE_ADDA_MTKAIF_CFG0,
1558061734aSJiaxin Yu 				   0xffff, 0x0000);
1568061734aSJiaxin Yu 		/* enable aud_pad TX fifos */
1578061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
1588061734aSJiaxin Yu 				   MT6359_AFE_AUD_PAD_TOP,
1598061734aSJiaxin Yu 				   0xff00, 0x3100);
1608061734aSJiaxin Yu 		break;
1618061734aSJiaxin Yu 	}
1628061734aSJiaxin Yu }
1638061734aSJiaxin Yu 
mt6359_mtkaif_tx_disable(struct mt6359_priv * priv)1648061734aSJiaxin Yu static void mt6359_mtkaif_tx_disable(struct mt6359_priv *priv)
1658061734aSJiaxin Yu {
1668061734aSJiaxin Yu 	/* disable aud_pad TX fifos */
1678061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AFE_AUD_PAD_TOP,
1688061734aSJiaxin Yu 			   0xff00, 0x3000);
1698061734aSJiaxin Yu }
1708061734aSJiaxin Yu 
mt6359_set_mtkaif_protocol(struct snd_soc_component * cmpnt,int mtkaif_protocol)171682c5a72SJiaxin Yu void mt6359_set_mtkaif_protocol(struct snd_soc_component *cmpnt,
172682c5a72SJiaxin Yu 				int mtkaif_protocol)
173682c5a72SJiaxin Yu {
174682c5a72SJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
175682c5a72SJiaxin Yu 
176682c5a72SJiaxin Yu 	priv->mtkaif_protocol = mtkaif_protocol;
177682c5a72SJiaxin Yu }
178682c5a72SJiaxin Yu EXPORT_SYMBOL_GPL(mt6359_set_mtkaif_protocol);
179682c5a72SJiaxin Yu 
mt6359_mtkaif_calibration_enable(struct snd_soc_component * cmpnt)180682c5a72SJiaxin Yu void mt6359_mtkaif_calibration_enable(struct snd_soc_component *cmpnt)
181682c5a72SJiaxin Yu {
182682c5a72SJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
183682c5a72SJiaxin Yu 
184682c5a72SJiaxin Yu 	mt6359_set_playback_gpio(priv);
185682c5a72SJiaxin Yu 	mt6359_set_capture_gpio(priv);
186682c5a72SJiaxin Yu 	mt6359_mtkaif_tx_enable(priv);
187682c5a72SJiaxin Yu 
188682c5a72SJiaxin Yu 	mt6359_set_dcxo(priv, true);
189682c5a72SJiaxin Yu 	mt6359_set_aud_global_bias(priv, true);
190682c5a72SJiaxin Yu 	mt6359_set_clksq(priv, true);
191682c5a72SJiaxin Yu 	mt6359_set_topck(priv, true);
192682c5a72SJiaxin Yu 
193682c5a72SJiaxin Yu 	/* set dat_miso_loopback on */
194682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
195682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT,
196682c5a72SJiaxin Yu 			   1 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT);
197682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
198682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT,
199682c5a72SJiaxin Yu 			   1 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT);
200682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1,
201682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO3_LOOPBACK_MASK_SFT,
202682c5a72SJiaxin Yu 			   1 << RG_AUD_PAD_TOP_DAT_MISO3_LOOPBACK_SFT);
203682c5a72SJiaxin Yu }
204682c5a72SJiaxin Yu EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_enable);
205682c5a72SJiaxin Yu 
mt6359_mtkaif_calibration_disable(struct snd_soc_component * cmpnt)206682c5a72SJiaxin Yu void mt6359_mtkaif_calibration_disable(struct snd_soc_component *cmpnt)
207682c5a72SJiaxin Yu {
208682c5a72SJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
209682c5a72SJiaxin Yu 
210682c5a72SJiaxin Yu 	/* set dat_miso_loopback off */
211682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
212682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT,
213682c5a72SJiaxin Yu 			   0 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT);
214682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
215682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT,
216682c5a72SJiaxin Yu 			   0 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT);
217682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1,
218682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_DAT_MISO3_LOOPBACK_MASK_SFT,
219682c5a72SJiaxin Yu 			   0 << RG_AUD_PAD_TOP_DAT_MISO3_LOOPBACK_SFT);
220682c5a72SJiaxin Yu 
221682c5a72SJiaxin Yu 	mt6359_set_topck(priv, false);
222682c5a72SJiaxin Yu 	mt6359_set_clksq(priv, false);
223682c5a72SJiaxin Yu 	mt6359_set_aud_global_bias(priv, false);
224682c5a72SJiaxin Yu 	mt6359_set_dcxo(priv, false);
225682c5a72SJiaxin Yu 
226682c5a72SJiaxin Yu 	mt6359_mtkaif_tx_disable(priv);
227682c5a72SJiaxin Yu 	mt6359_reset_playback_gpio(priv);
228682c5a72SJiaxin Yu 	mt6359_reset_capture_gpio(priv);
229682c5a72SJiaxin Yu }
230682c5a72SJiaxin Yu EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_disable);
231682c5a72SJiaxin Yu 
mt6359_set_mtkaif_calibration_phase(struct snd_soc_component * cmpnt,int phase_1,int phase_2,int phase_3)232682c5a72SJiaxin Yu void mt6359_set_mtkaif_calibration_phase(struct snd_soc_component *cmpnt,
233682c5a72SJiaxin Yu 					 int phase_1, int phase_2, int phase_3)
234682c5a72SJiaxin Yu {
235682c5a72SJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
236682c5a72SJiaxin Yu 
237682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
238682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_PHASE_MODE_MASK_SFT,
239682c5a72SJiaxin Yu 			   phase_1 << RG_AUD_PAD_TOP_PHASE_MODE_SFT);
240682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG,
241682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_PHASE_MODE2_MASK_SFT,
242682c5a72SJiaxin Yu 			   phase_2 << RG_AUD_PAD_TOP_PHASE_MODE2_SFT);
243682c5a72SJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDIO_DIG_CFG1,
244682c5a72SJiaxin Yu 			   RG_AUD_PAD_TOP_PHASE_MODE3_MASK_SFT,
245682c5a72SJiaxin Yu 			   phase_3 << RG_AUD_PAD_TOP_PHASE_MODE3_SFT);
246682c5a72SJiaxin Yu }
247682c5a72SJiaxin Yu EXPORT_SYMBOL_GPL(mt6359_set_mtkaif_calibration_phase);
248682c5a72SJiaxin Yu 
zcd_disable(struct mt6359_priv * priv)2498061734aSJiaxin Yu static void zcd_disable(struct mt6359_priv *priv)
2508061734aSJiaxin Yu {
2518061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_ZCD_CON0, 0x0000);
2528061734aSJiaxin Yu }
2538061734aSJiaxin Yu 
hp_main_output_ramp(struct mt6359_priv * priv,bool up)2548061734aSJiaxin Yu static void hp_main_output_ramp(struct mt6359_priv *priv, bool up)
2558061734aSJiaxin Yu {
256d068ab4eSPierre-Louis Bossart 	int i, stage;
2578061734aSJiaxin Yu 	int target = 7;
2588061734aSJiaxin Yu 
2598061734aSJiaxin Yu 	/* Enable/Reduce HPL/R main output stage step by step */
2608061734aSJiaxin Yu 	for (i = 0; i <= target; i++) {
2618061734aSJiaxin Yu 		stage = up ? i : target - i;
2628061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1,
2638061734aSJiaxin Yu 				   RG_HPLOUTSTGCTRL_VAUDP32_MASK_SFT,
2648061734aSJiaxin Yu 				   stage << RG_HPLOUTSTGCTRL_VAUDP32_SFT);
2658061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1,
2668061734aSJiaxin Yu 				   RG_HPROUTSTGCTRL_VAUDP32_MASK_SFT,
2678061734aSJiaxin Yu 				   stage << RG_HPROUTSTGCTRL_VAUDP32_SFT);
2688061734aSJiaxin Yu 		usleep_range(600, 650);
2698061734aSJiaxin Yu 	}
2708061734aSJiaxin Yu }
2718061734aSJiaxin Yu 
hp_aux_feedback_loop_gain_ramp(struct mt6359_priv * priv,bool up)2728061734aSJiaxin Yu static void hp_aux_feedback_loop_gain_ramp(struct mt6359_priv *priv, bool up)
2738061734aSJiaxin Yu {
274d068ab4eSPierre-Louis Bossart 	int i, stage;
2758061734aSJiaxin Yu 	int target = 0xf;
2768061734aSJiaxin Yu 
2778061734aSJiaxin Yu 	/* Enable/Reduce HP aux feedback loop gain step by step */
2788061734aSJiaxin Yu 	for (i = 0; i <= target; i++) {
2798061734aSJiaxin Yu 		stage = up ? i : target - i;
2808061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON9,
2818061734aSJiaxin Yu 				   0xf << 12, stage << 12);
2828061734aSJiaxin Yu 		usleep_range(600, 650);
2838061734aSJiaxin Yu 	}
2848061734aSJiaxin Yu }
2858061734aSJiaxin Yu 
hp_in_pair_current(struct mt6359_priv * priv,bool increase)2868061734aSJiaxin Yu static void hp_in_pair_current(struct mt6359_priv *priv, bool increase)
2878061734aSJiaxin Yu {
288d51f6dfbSPierre-Louis Bossart 	int i, stage;
2898061734aSJiaxin Yu 	int target = 0x3;
2908061734aSJiaxin Yu 
2918061734aSJiaxin Yu 	/* Set input diff pair bias select (Hi-Fi mode) */
2928061734aSJiaxin Yu 	if (priv->hp_hifi_mode) {
2938061734aSJiaxin Yu 		/* Reduce HP aux feedback loop gain step by step */
2948061734aSJiaxin Yu 		for (i = 0; i <= target; i++) {
2958061734aSJiaxin Yu 			stage = increase ? i : target - i;
2968061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
2978061734aSJiaxin Yu 					   MT6359_AUDDEC_ANA_CON10,
2988061734aSJiaxin Yu 					   0x3 << 3, stage << 3);
2998061734aSJiaxin Yu 			usleep_range(100, 150);
3008061734aSJiaxin Yu 		}
3018061734aSJiaxin Yu 	}
3028061734aSJiaxin Yu }
3038061734aSJiaxin Yu 
hp_pull_down(struct mt6359_priv * priv,bool enable)3048061734aSJiaxin Yu static void hp_pull_down(struct mt6359_priv *priv, bool enable)
3058061734aSJiaxin Yu {
3068061734aSJiaxin Yu 	int i;
3078061734aSJiaxin Yu 
3088061734aSJiaxin Yu 	if (enable) {
3098061734aSJiaxin Yu 		for (i = 0x0; i <= 0x7; i++) {
3108061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2,
3118061734aSJiaxin Yu 					   RG_HPPSHORT2VCM_VAUDP32_MASK_SFT,
3128061734aSJiaxin Yu 					   i << RG_HPPSHORT2VCM_VAUDP32_SFT);
3138061734aSJiaxin Yu 			usleep_range(100, 150);
3148061734aSJiaxin Yu 		}
3158061734aSJiaxin Yu 	} else {
3168061734aSJiaxin Yu 		for (i = 0x7; i >= 0x0; i--) {
3178061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2,
3188061734aSJiaxin Yu 					   RG_HPPSHORT2VCM_VAUDP32_MASK_SFT,
3198061734aSJiaxin Yu 					   i << RG_HPPSHORT2VCM_VAUDP32_SFT);
3208061734aSJiaxin Yu 			usleep_range(100, 150);
3218061734aSJiaxin Yu 		}
3228061734aSJiaxin Yu 	}
3238061734aSJiaxin Yu }
3248061734aSJiaxin Yu 
is_valid_hp_pga_idx(int reg_idx)3258061734aSJiaxin Yu static bool is_valid_hp_pga_idx(int reg_idx)
3268061734aSJiaxin Yu {
3278061734aSJiaxin Yu 	return (reg_idx >= DL_GAIN_8DB && reg_idx <= DL_GAIN_N_22DB) ||
3288061734aSJiaxin Yu 	       reg_idx == DL_GAIN_N_40DB;
3298061734aSJiaxin Yu }
3308061734aSJiaxin Yu 
headset_volume_ramp(struct mt6359_priv * priv,int from,int to)3318061734aSJiaxin Yu static void headset_volume_ramp(struct mt6359_priv *priv,
3328061734aSJiaxin Yu 				int from, int to)
3338061734aSJiaxin Yu {
3348061734aSJiaxin Yu 	int offset = 0, count = 1, reg_idx;
3358061734aSJiaxin Yu 
3368061734aSJiaxin Yu 	if (!is_valid_hp_pga_idx(from) || !is_valid_hp_pga_idx(to)) {
3378061734aSJiaxin Yu 		dev_warn(priv->dev, "%s(), volume index is not valid, from %d, to %d\n",
3388061734aSJiaxin Yu 			 __func__, from, to);
3398061734aSJiaxin Yu 		return;
3408061734aSJiaxin Yu 	}
3418061734aSJiaxin Yu 
3428061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), from %d, to %d\n", __func__, from, to);
3438061734aSJiaxin Yu 
3448061734aSJiaxin Yu 	if (to > from)
3458061734aSJiaxin Yu 		offset = to - from;
3468061734aSJiaxin Yu 	else
3478061734aSJiaxin Yu 		offset = from - to;
3488061734aSJiaxin Yu 
3498061734aSJiaxin Yu 	while (offset > 0) {
3508061734aSJiaxin Yu 		if (to > from)
3518061734aSJiaxin Yu 			reg_idx = from + count;
3528061734aSJiaxin Yu 		else
3538061734aSJiaxin Yu 			reg_idx = from - count;
3548061734aSJiaxin Yu 
3558061734aSJiaxin Yu 		if (is_valid_hp_pga_idx(reg_idx)) {
3568061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
3578061734aSJiaxin Yu 					   MT6359_ZCD_CON2,
3588061734aSJiaxin Yu 					   DL_GAIN_REG_MASK,
3598061734aSJiaxin Yu 					   (reg_idx << 7) | reg_idx);
3608061734aSJiaxin Yu 			usleep_range(600, 650);
3618061734aSJiaxin Yu 		}
3628061734aSJiaxin Yu 		offset--;
3638061734aSJiaxin Yu 		count++;
3648061734aSJiaxin Yu 	}
3658061734aSJiaxin Yu }
3668061734aSJiaxin Yu 
mt6359_put_volsw(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3678061734aSJiaxin Yu static int mt6359_put_volsw(struct snd_kcontrol *kcontrol,
3688061734aSJiaxin Yu 			    struct snd_ctl_elem_value *ucontrol)
3698061734aSJiaxin Yu {
3708061734aSJiaxin Yu 	struct snd_soc_component *component =
3718061734aSJiaxin Yu 			snd_soc_kcontrol_component(kcontrol);
3728061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(component);
3738061734aSJiaxin Yu 	struct soc_mixer_control *mc =
3748061734aSJiaxin Yu 			(struct soc_mixer_control *)kcontrol->private_value;
3753a60fa4cSTrevor Wu 	unsigned int reg = 0;
3768061734aSJiaxin Yu 	int index = ucontrol->value.integer.value[0];
377acd4d219STrevor Wu 	int orig_gain[2], new_gain[2];
3788061734aSJiaxin Yu 	int ret;
3798061734aSJiaxin Yu 
380acd4d219STrevor Wu 	switch (mc->reg) {
381acd4d219STrevor Wu 	case MT6359_ZCD_CON2:
382acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL];
383acd4d219STrevor Wu 		orig_gain[1] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR];
384acd4d219STrevor Wu 		break;
385acd4d219STrevor Wu 	case MT6359_ZCD_CON1:
386acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL];
387acd4d219STrevor Wu 		orig_gain[1] = priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR];
388acd4d219STrevor Wu 		break;
389acd4d219STrevor Wu 	case MT6359_ZCD_CON3:
390acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL];
391acd4d219STrevor Wu 		break;
392acd4d219STrevor Wu 	case MT6359_AUDENC_ANA_CON0:
393acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1];
394acd4d219STrevor Wu 		break;
395acd4d219STrevor Wu 	case MT6359_AUDENC_ANA_CON1:
396acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2];
397acd4d219STrevor Wu 		break;
398acd4d219STrevor Wu 	case MT6359_AUDENC_ANA_CON2:
399acd4d219STrevor Wu 		orig_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3];
400acd4d219STrevor Wu 		break;
401acd4d219STrevor Wu 	default:
402acd4d219STrevor Wu 		return -EINVAL;
403acd4d219STrevor Wu 	}
404acd4d219STrevor Wu 
4058061734aSJiaxin Yu 	ret = snd_soc_put_volsw(kcontrol, ucontrol);
4068061734aSJiaxin Yu 	if (ret < 0)
4078061734aSJiaxin Yu 		return ret;
4088061734aSJiaxin Yu 
4098061734aSJiaxin Yu 	switch (mc->reg) {
4108061734aSJiaxin Yu 	case MT6359_ZCD_CON2:
4118061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_ZCD_CON2, &reg);
4128061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] =
4138061734aSJiaxin Yu 			(reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK;
4148061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] =
4158061734aSJiaxin Yu 			(reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK;
416acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL];
417acd4d219STrevor Wu 		new_gain[1] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR];
4188061734aSJiaxin Yu 		break;
4198061734aSJiaxin Yu 	case MT6359_ZCD_CON1:
4208061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_ZCD_CON1, &reg);
4218061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] =
4228061734aSJiaxin Yu 			(reg >> RG_AUDLOLGAIN_SFT) & RG_AUDLOLGAIN_MASK;
4238061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] =
4248061734aSJiaxin Yu 			(reg >> RG_AUDLORGAIN_SFT) & RG_AUDLORGAIN_MASK;
425acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL];
426acd4d219STrevor Wu 		new_gain[1] = priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR];
4278061734aSJiaxin Yu 		break;
4288061734aSJiaxin Yu 	case MT6359_ZCD_CON3:
4298061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_ZCD_CON3, &reg);
4308061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL] =
4318061734aSJiaxin Yu 			(reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK;
432acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL];
4338061734aSJiaxin Yu 		break;
4348061734aSJiaxin Yu 	case MT6359_AUDENC_ANA_CON0:
4358061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON0, &reg);
4368061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] =
4378061734aSJiaxin Yu 			(reg >> RG_AUDPREAMPLGAIN_SFT) & RG_AUDPREAMPLGAIN_MASK;
438acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1];
4398061734aSJiaxin Yu 		break;
4408061734aSJiaxin Yu 	case MT6359_AUDENC_ANA_CON1:
4418061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON1, &reg);
4428061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] =
4438061734aSJiaxin Yu 			(reg >> RG_AUDPREAMPRGAIN_SFT) & RG_AUDPREAMPRGAIN_MASK;
444acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2];
4458061734aSJiaxin Yu 		break;
4468061734aSJiaxin Yu 	case MT6359_AUDENC_ANA_CON2:
4478061734aSJiaxin Yu 		regmap_read(priv->regmap, MT6359_AUDENC_ANA_CON2, &reg);
4488061734aSJiaxin Yu 		priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3] =
4498061734aSJiaxin Yu 			(reg >> RG_AUDPREAMP3GAIN_SFT) & RG_AUDPREAMP3GAIN_MASK;
450acd4d219STrevor Wu 		new_gain[0] = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3];
4518061734aSJiaxin Yu 		break;
4528061734aSJiaxin Yu 	}
4538061734aSJiaxin Yu 
454acd4d219STrevor Wu 	ret = 0;
455acd4d219STrevor Wu 	if (orig_gain[0] != new_gain[0]) {
456acd4d219STrevor Wu 		ret = 1;
457acd4d219STrevor Wu 	} else if (snd_soc_volsw_is_stereo(mc)) {
458acd4d219STrevor Wu 		if (orig_gain[1] != new_gain[1])
459acd4d219STrevor Wu 			ret = 1;
460acd4d219STrevor Wu 	}
461acd4d219STrevor Wu 
4628061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), name %s, reg(0x%x) = 0x%x, set index = %x\n",
4638061734aSJiaxin Yu 		__func__, kcontrol->id.name, mc->reg, reg, index);
4648061734aSJiaxin Yu 
4658061734aSJiaxin Yu 	return ret;
4668061734aSJiaxin Yu }
4678061734aSJiaxin Yu 
mt6359_get_playback_volsw(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)468acd4d219STrevor Wu static int mt6359_get_playback_volsw(struct snd_kcontrol *kcontrol,
469acd4d219STrevor Wu 				     struct snd_ctl_elem_value *ucontrol)
470acd4d219STrevor Wu {
471acd4d219STrevor Wu 	struct snd_soc_component *component =
472acd4d219STrevor Wu 			snd_soc_kcontrol_component(kcontrol);
473acd4d219STrevor Wu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(component);
474acd4d219STrevor Wu 	struct soc_mixer_control *mc =
475acd4d219STrevor Wu 			(struct soc_mixer_control *)kcontrol->private_value;
476acd4d219STrevor Wu 
477acd4d219STrevor Wu 	switch (mc->reg) {
478acd4d219STrevor Wu 	case MT6359_ZCD_CON2:
479acd4d219STrevor Wu 		ucontrol->value.integer.value[0] =
480acd4d219STrevor Wu 			priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL];
481acd4d219STrevor Wu 		ucontrol->value.integer.value[1] =
482acd4d219STrevor Wu 			priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR];
483acd4d219STrevor Wu 		break;
484acd4d219STrevor Wu 	case MT6359_ZCD_CON1:
485acd4d219STrevor Wu 		ucontrol->value.integer.value[0] =
486acd4d219STrevor Wu 			priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL];
487acd4d219STrevor Wu 		ucontrol->value.integer.value[1] =
488acd4d219STrevor Wu 			priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR];
489acd4d219STrevor Wu 		break;
490acd4d219STrevor Wu 	case MT6359_ZCD_CON3:
491acd4d219STrevor Wu 		ucontrol->value.integer.value[0] =
492acd4d219STrevor Wu 			priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL];
493acd4d219STrevor Wu 		break;
494acd4d219STrevor Wu 	default:
495acd4d219STrevor Wu 		return -EINVAL;
496acd4d219STrevor Wu 	}
497acd4d219STrevor Wu 
498acd4d219STrevor Wu 	return 0;
499acd4d219STrevor Wu }
500acd4d219STrevor Wu 
5018061734aSJiaxin Yu /* MUX */
5028061734aSJiaxin Yu 
5038061734aSJiaxin Yu /* LOL MUX */
5048061734aSJiaxin Yu static const char * const lo_in_mux_map[] = {
5058061734aSJiaxin Yu 	"Open", "Playback_L_DAC", "Playback", "Test Mode"
5068061734aSJiaxin Yu };
5078061734aSJiaxin Yu 
5088061734aSJiaxin Yu static SOC_ENUM_SINGLE_DECL(lo_in_mux_map_enum, SND_SOC_NOPM, 0, lo_in_mux_map);
5098061734aSJiaxin Yu 
5108061734aSJiaxin Yu static const struct snd_kcontrol_new lo_in_mux_control =
5118061734aSJiaxin Yu 	SOC_DAPM_ENUM("LO Select", lo_in_mux_map_enum);
5128061734aSJiaxin Yu 
5138061734aSJiaxin Yu /*HP MUX */
5148061734aSJiaxin Yu static const char * const hp_in_mux_map[] = {
5158061734aSJiaxin Yu 	"Open",
5168061734aSJiaxin Yu 	"LoudSPK Playback",
5178061734aSJiaxin Yu 	"Audio Playback",
5188061734aSJiaxin Yu 	"Test Mode",
5198061734aSJiaxin Yu 	"HP Impedance",
5208061734aSJiaxin Yu };
5218061734aSJiaxin Yu 
5228061734aSJiaxin Yu static SOC_ENUM_SINGLE_DECL(hp_in_mux_map_enum,
5238061734aSJiaxin Yu 				  SND_SOC_NOPM,
5248061734aSJiaxin Yu 				  0,
5258061734aSJiaxin Yu 				  hp_in_mux_map);
5268061734aSJiaxin Yu 
5278061734aSJiaxin Yu static const struct snd_kcontrol_new hp_in_mux_control =
5288061734aSJiaxin Yu 	SOC_DAPM_ENUM("HP Select", hp_in_mux_map_enum);
5298061734aSJiaxin Yu 
5308061734aSJiaxin Yu /* RCV MUX */
5318061734aSJiaxin Yu static const char * const rcv_in_mux_map[] = {
5328061734aSJiaxin Yu 	"Open", "Mute", "Voice Playback", "Test Mode"
5338061734aSJiaxin Yu };
5348061734aSJiaxin Yu 
5358061734aSJiaxin Yu static SOC_ENUM_SINGLE_DECL(rcv_in_mux_map_enum,
5368061734aSJiaxin Yu 				  SND_SOC_NOPM,
5378061734aSJiaxin Yu 				  0,
5388061734aSJiaxin Yu 				  rcv_in_mux_map);
5398061734aSJiaxin Yu 
5408061734aSJiaxin Yu static const struct snd_kcontrol_new rcv_in_mux_control =
5418061734aSJiaxin Yu 	SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum);
5428061734aSJiaxin Yu 
5438061734aSJiaxin Yu /* DAC In MUX */
5448061734aSJiaxin Yu static const char * const dac_in_mux_map[] = {
5458061734aSJiaxin Yu 	"Normal Path", "Sgen"
5468061734aSJiaxin Yu };
5478061734aSJiaxin Yu 
5488061734aSJiaxin Yu static int dac_in_mux_map_value[] = {
5498061734aSJiaxin Yu 	0x0, 0x1,
5508061734aSJiaxin Yu };
5518061734aSJiaxin Yu 
5528061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum,
5538061734aSJiaxin Yu 				  MT6359_AFE_TOP_CON0,
5548061734aSJiaxin Yu 				  DL_SINE_ON_SFT,
5558061734aSJiaxin Yu 				  DL_SINE_ON_MASK,
5568061734aSJiaxin Yu 				  dac_in_mux_map,
5578061734aSJiaxin Yu 				  dac_in_mux_map_value);
5588061734aSJiaxin Yu 
5598061734aSJiaxin Yu static const struct snd_kcontrol_new dac_in_mux_control =
5608061734aSJiaxin Yu 	SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum);
5618061734aSJiaxin Yu 
5628061734aSJiaxin Yu /* AIF Out MUX */
5638061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum,
5648061734aSJiaxin Yu 				  MT6359_AFE_TOP_CON0,
5658061734aSJiaxin Yu 				  UL_SINE_ON_SFT,
5668061734aSJiaxin Yu 				  UL_SINE_ON_MASK,
5678061734aSJiaxin Yu 				  dac_in_mux_map,
5688061734aSJiaxin Yu 				  dac_in_mux_map_value);
5698061734aSJiaxin Yu 
5708061734aSJiaxin Yu static const struct snd_kcontrol_new aif_out_mux_control =
5718061734aSJiaxin Yu 	SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum);
5728061734aSJiaxin Yu 
5738061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(aif2_out_mux_map_enum,
5748061734aSJiaxin Yu 				  MT6359_AFE_TOP_CON0,
5758061734aSJiaxin Yu 				  ADDA6_UL_SINE_ON_SFT,
5768061734aSJiaxin Yu 				  ADDA6_UL_SINE_ON_MASK,
5778061734aSJiaxin Yu 				  dac_in_mux_map,
5788061734aSJiaxin Yu 				  dac_in_mux_map_value);
5798061734aSJiaxin Yu 
5808061734aSJiaxin Yu static const struct snd_kcontrol_new aif2_out_mux_control =
5818061734aSJiaxin Yu 	SOC_DAPM_ENUM("AIF Out Select", aif2_out_mux_map_enum);
5828061734aSJiaxin Yu 
5838061734aSJiaxin Yu static const char * const ul_src_mux_map[] = {
5848061734aSJiaxin Yu 	"AMIC",
5858061734aSJiaxin Yu 	"DMIC",
5868061734aSJiaxin Yu };
5878061734aSJiaxin Yu 
5888061734aSJiaxin Yu static int ul_src_mux_map_value[] = {
5898061734aSJiaxin Yu 	UL_SRC_MUX_AMIC,
5908061734aSJiaxin Yu 	UL_SRC_MUX_DMIC,
5918061734aSJiaxin Yu };
5928061734aSJiaxin Yu 
5938061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(ul_src_mux_map_enum,
5948061734aSJiaxin Yu 				  MT6359_AFE_UL_SRC_CON0_L,
5958061734aSJiaxin Yu 				  UL_SDM_3_LEVEL_CTL_SFT,
5968061734aSJiaxin Yu 				  UL_SDM_3_LEVEL_CTL_MASK,
5978061734aSJiaxin Yu 				  ul_src_mux_map,
5988061734aSJiaxin Yu 				  ul_src_mux_map_value);
5998061734aSJiaxin Yu 
6008061734aSJiaxin Yu static const struct snd_kcontrol_new ul_src_mux_control =
6018061734aSJiaxin Yu 	SOC_DAPM_ENUM("UL_SRC_MUX Select", ul_src_mux_map_enum);
6028061734aSJiaxin Yu 
6038061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(ul2_src_mux_map_enum,
6048061734aSJiaxin Yu 				  MT6359_AFE_ADDA6_UL_SRC_CON0_L,
6058061734aSJiaxin Yu 				  ADDA6_UL_SDM_3_LEVEL_CTL_SFT,
6068061734aSJiaxin Yu 				  ADDA6_UL_SDM_3_LEVEL_CTL_MASK,
6078061734aSJiaxin Yu 				  ul_src_mux_map,
6088061734aSJiaxin Yu 				  ul_src_mux_map_value);
6098061734aSJiaxin Yu 
6108061734aSJiaxin Yu static const struct snd_kcontrol_new ul2_src_mux_control =
6118061734aSJiaxin Yu 	SOC_DAPM_ENUM("UL_SRC_MUX Select", ul2_src_mux_map_enum);
6128061734aSJiaxin Yu 
6138061734aSJiaxin Yu static const char * const miso_mux_map[] = {
6148061734aSJiaxin Yu 	"UL1_CH1",
6158061734aSJiaxin Yu 	"UL1_CH2",
6168061734aSJiaxin Yu 	"UL2_CH1",
6178061734aSJiaxin Yu 	"UL2_CH2",
6188061734aSJiaxin Yu };
6198061734aSJiaxin Yu 
6208061734aSJiaxin Yu static int miso_mux_map_value[] = {
6218061734aSJiaxin Yu 	MISO_MUX_UL1_CH1,
6228061734aSJiaxin Yu 	MISO_MUX_UL1_CH2,
6238061734aSJiaxin Yu 	MISO_MUX_UL2_CH1,
6248061734aSJiaxin Yu 	MISO_MUX_UL2_CH2,
6258061734aSJiaxin Yu };
6268061734aSJiaxin Yu 
6278061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(miso0_mux_map_enum,
6288061734aSJiaxin Yu 				  MT6359_AFE_MTKAIF_MUX_CFG,
6298061734aSJiaxin Yu 				  RG_ADDA_CH1_SEL_SFT,
6308061734aSJiaxin Yu 				  RG_ADDA_CH1_SEL_MASK,
6318061734aSJiaxin Yu 				  miso_mux_map,
6328061734aSJiaxin Yu 				  miso_mux_map_value);
6338061734aSJiaxin Yu 
6348061734aSJiaxin Yu static const struct snd_kcontrol_new miso0_mux_control =
6358061734aSJiaxin Yu 	SOC_DAPM_ENUM("MISO_MUX Select", miso0_mux_map_enum);
6368061734aSJiaxin Yu 
6378061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(miso1_mux_map_enum,
6388061734aSJiaxin Yu 				  MT6359_AFE_MTKAIF_MUX_CFG,
6398061734aSJiaxin Yu 				  RG_ADDA_CH2_SEL_SFT,
6408061734aSJiaxin Yu 				  RG_ADDA_CH2_SEL_MASK,
6418061734aSJiaxin Yu 				  miso_mux_map,
6428061734aSJiaxin Yu 				  miso_mux_map_value);
6438061734aSJiaxin Yu 
6448061734aSJiaxin Yu static const struct snd_kcontrol_new miso1_mux_control =
6458061734aSJiaxin Yu 	SOC_DAPM_ENUM("MISO_MUX Select", miso1_mux_map_enum);
6468061734aSJiaxin Yu 
6478061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(miso2_mux_map_enum,
6488061734aSJiaxin Yu 				  MT6359_AFE_MTKAIF_MUX_CFG,
6498061734aSJiaxin Yu 				  RG_ADDA6_CH1_SEL_SFT,
6508061734aSJiaxin Yu 				  RG_ADDA6_CH1_SEL_MASK,
6518061734aSJiaxin Yu 				  miso_mux_map,
6528061734aSJiaxin Yu 				  miso_mux_map_value);
6538061734aSJiaxin Yu 
6548061734aSJiaxin Yu static const struct snd_kcontrol_new miso2_mux_control =
6558061734aSJiaxin Yu 	SOC_DAPM_ENUM("MISO_MUX Select", miso2_mux_map_enum);
6568061734aSJiaxin Yu 
6578061734aSJiaxin Yu static const char * const dmic_mux_map[] = {
6588061734aSJiaxin Yu 	"DMIC_DATA0",
6598061734aSJiaxin Yu 	"DMIC_DATA1_L",
6608061734aSJiaxin Yu 	"DMIC_DATA1_L_1",
6618061734aSJiaxin Yu 	"DMIC_DATA1_R",
6628061734aSJiaxin Yu };
6638061734aSJiaxin Yu 
6648061734aSJiaxin Yu static int dmic_mux_map_value[] = {
6658061734aSJiaxin Yu 	DMIC_MUX_DMIC_DATA0,
6668061734aSJiaxin Yu 	DMIC_MUX_DMIC_DATA1_L,
6678061734aSJiaxin Yu 	DMIC_MUX_DMIC_DATA1_L_1,
6688061734aSJiaxin Yu 	DMIC_MUX_DMIC_DATA1_R,
6698061734aSJiaxin Yu };
6708061734aSJiaxin Yu 
6718061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(dmic0_mux_map_enum,
6728061734aSJiaxin Yu 				  MT6359_AFE_MIC_ARRAY_CFG,
6738061734aSJiaxin Yu 				  RG_DMIC_ADC1_SOURCE_SEL_SFT,
6748061734aSJiaxin Yu 				  RG_DMIC_ADC1_SOURCE_SEL_MASK,
6758061734aSJiaxin Yu 				  dmic_mux_map,
6768061734aSJiaxin Yu 				  dmic_mux_map_value);
6778061734aSJiaxin Yu 
6788061734aSJiaxin Yu static const struct snd_kcontrol_new dmic0_mux_control =
6798061734aSJiaxin Yu 	SOC_DAPM_ENUM("DMIC_MUX Select", dmic0_mux_map_enum);
6808061734aSJiaxin Yu 
6818061734aSJiaxin Yu /* ul1 ch2 use RG_DMIC_ADC3_SOURCE_SEL */
6828061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(dmic1_mux_map_enum,
6838061734aSJiaxin Yu 				  MT6359_AFE_MIC_ARRAY_CFG,
6848061734aSJiaxin Yu 				  RG_DMIC_ADC3_SOURCE_SEL_SFT,
6858061734aSJiaxin Yu 				  RG_DMIC_ADC3_SOURCE_SEL_MASK,
6868061734aSJiaxin Yu 				  dmic_mux_map,
6878061734aSJiaxin Yu 				  dmic_mux_map_value);
6888061734aSJiaxin Yu 
6898061734aSJiaxin Yu static const struct snd_kcontrol_new dmic1_mux_control =
6908061734aSJiaxin Yu 	SOC_DAPM_ENUM("DMIC_MUX Select", dmic1_mux_map_enum);
6918061734aSJiaxin Yu 
6928061734aSJiaxin Yu /* ul2 ch1 use RG_DMIC_ADC2_SOURCE_SEL */
6938061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(dmic2_mux_map_enum,
6948061734aSJiaxin Yu 				  MT6359_AFE_MIC_ARRAY_CFG,
6958061734aSJiaxin Yu 				  RG_DMIC_ADC2_SOURCE_SEL_SFT,
6968061734aSJiaxin Yu 				  RG_DMIC_ADC2_SOURCE_SEL_MASK,
6978061734aSJiaxin Yu 				  dmic_mux_map,
6988061734aSJiaxin Yu 				  dmic_mux_map_value);
6998061734aSJiaxin Yu 
7008061734aSJiaxin Yu static const struct snd_kcontrol_new dmic2_mux_control =
7018061734aSJiaxin Yu 	SOC_DAPM_ENUM("DMIC_MUX Select", dmic2_mux_map_enum);
7028061734aSJiaxin Yu 
7038061734aSJiaxin Yu /* ADC L MUX */
7048061734aSJiaxin Yu static const char * const adc_left_mux_map[] = {
7058061734aSJiaxin Yu 	"Idle", "AIN0", "Left Preamplifier", "Idle_1"
7068061734aSJiaxin Yu };
7078061734aSJiaxin Yu 
7088061734aSJiaxin Yu static int adc_mux_map_value[] = {
7098061734aSJiaxin Yu 	ADC_MUX_IDLE,
7108061734aSJiaxin Yu 	ADC_MUX_AIN0,
7118061734aSJiaxin Yu 	ADC_MUX_PREAMPLIFIER,
7128061734aSJiaxin Yu 	ADC_MUX_IDLE1,
7138061734aSJiaxin Yu };
7148061734aSJiaxin Yu 
7158061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum,
7168061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON0,
7178061734aSJiaxin Yu 				  RG_AUDADCLINPUTSEL_SFT,
7188061734aSJiaxin Yu 				  RG_AUDADCLINPUTSEL_MASK,
7198061734aSJiaxin Yu 				  adc_left_mux_map,
7208061734aSJiaxin Yu 				  adc_mux_map_value);
7218061734aSJiaxin Yu 
7228061734aSJiaxin Yu static const struct snd_kcontrol_new adc_left_mux_control =
7238061734aSJiaxin Yu 	SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum);
7248061734aSJiaxin Yu 
7258061734aSJiaxin Yu /* ADC R MUX */
7268061734aSJiaxin Yu static const char * const adc_right_mux_map[] = {
7278061734aSJiaxin Yu 	"Idle", "AIN0", "Right Preamplifier", "Idle_1"
7288061734aSJiaxin Yu };
7298061734aSJiaxin Yu 
7308061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum,
7318061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON1,
7328061734aSJiaxin Yu 				  RG_AUDADCRINPUTSEL_SFT,
7338061734aSJiaxin Yu 				  RG_AUDADCRINPUTSEL_MASK,
7348061734aSJiaxin Yu 				  adc_right_mux_map,
7358061734aSJiaxin Yu 				  adc_mux_map_value);
7368061734aSJiaxin Yu 
7378061734aSJiaxin Yu static const struct snd_kcontrol_new adc_right_mux_control =
7388061734aSJiaxin Yu 	SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum);
7398061734aSJiaxin Yu 
7408061734aSJiaxin Yu /* ADC 3 MUX */
7418061734aSJiaxin Yu static const char * const adc_3_mux_map[] = {
7428061734aSJiaxin Yu 	"Idle", "AIN0", "Preamplifier", "Idle_1"
7438061734aSJiaxin Yu };
7448061734aSJiaxin Yu 
7458061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(adc_3_mux_map_enum,
7468061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON2,
7478061734aSJiaxin Yu 				  RG_AUDADC3INPUTSEL_SFT,
7488061734aSJiaxin Yu 				  RG_AUDADC3INPUTSEL_MASK,
7498061734aSJiaxin Yu 				  adc_3_mux_map,
7508061734aSJiaxin Yu 				  adc_mux_map_value);
7518061734aSJiaxin Yu 
7528061734aSJiaxin Yu static const struct snd_kcontrol_new adc_3_mux_control =
7538061734aSJiaxin Yu 	SOC_DAPM_ENUM("ADC 3 Select", adc_3_mux_map_enum);
7548061734aSJiaxin Yu 
7558061734aSJiaxin Yu static const char * const pga_l_mux_map[] = {
7568061734aSJiaxin Yu 	"None", "AIN0", "AIN1"
7578061734aSJiaxin Yu };
7588061734aSJiaxin Yu 
7598061734aSJiaxin Yu static int pga_l_mux_map_value[] = {
7608061734aSJiaxin Yu 	PGA_L_MUX_NONE,
7618061734aSJiaxin Yu 	PGA_L_MUX_AIN0,
7628061734aSJiaxin Yu 	PGA_L_MUX_AIN1
7638061734aSJiaxin Yu };
7648061734aSJiaxin Yu 
7658061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum,
7668061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON0,
7678061734aSJiaxin Yu 				  RG_AUDPREAMPLINPUTSEL_SFT,
7688061734aSJiaxin Yu 				  RG_AUDPREAMPLINPUTSEL_MASK,
7698061734aSJiaxin Yu 				  pga_l_mux_map,
7708061734aSJiaxin Yu 				  pga_l_mux_map_value);
7718061734aSJiaxin Yu 
7728061734aSJiaxin Yu static const struct snd_kcontrol_new pga_left_mux_control =
7738061734aSJiaxin Yu 	SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum);
7748061734aSJiaxin Yu 
7758061734aSJiaxin Yu static const char * const pga_r_mux_map[] = {
7768061734aSJiaxin Yu 	"None", "AIN2", "AIN3", "AIN0"
7778061734aSJiaxin Yu };
7788061734aSJiaxin Yu 
7798061734aSJiaxin Yu static int pga_r_mux_map_value[] = {
7808061734aSJiaxin Yu 	PGA_R_MUX_NONE,
7818061734aSJiaxin Yu 	PGA_R_MUX_AIN2,
7828061734aSJiaxin Yu 	PGA_R_MUX_AIN3,
7838061734aSJiaxin Yu 	PGA_R_MUX_AIN0
7848061734aSJiaxin Yu };
7858061734aSJiaxin Yu 
7868061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum,
7878061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON1,
7888061734aSJiaxin Yu 				  RG_AUDPREAMPRINPUTSEL_SFT,
7898061734aSJiaxin Yu 				  RG_AUDPREAMPRINPUTSEL_MASK,
7908061734aSJiaxin Yu 				  pga_r_mux_map,
7918061734aSJiaxin Yu 				  pga_r_mux_map_value);
7928061734aSJiaxin Yu 
7938061734aSJiaxin Yu static const struct snd_kcontrol_new pga_right_mux_control =
7948061734aSJiaxin Yu 	SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum);
7958061734aSJiaxin Yu 
7968061734aSJiaxin Yu static const char * const pga_3_mux_map[] = {
7978061734aSJiaxin Yu 	"None", "AIN3", "AIN2"
7988061734aSJiaxin Yu };
7998061734aSJiaxin Yu 
8008061734aSJiaxin Yu static int pga_3_mux_map_value[] = {
8018061734aSJiaxin Yu 	PGA_3_MUX_NONE,
8028061734aSJiaxin Yu 	PGA_3_MUX_AIN3,
8038061734aSJiaxin Yu 	PGA_3_MUX_AIN2
8048061734aSJiaxin Yu };
8058061734aSJiaxin Yu 
8068061734aSJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(pga_3_mux_map_enum,
8078061734aSJiaxin Yu 				  MT6359_AUDENC_ANA_CON2,
8088061734aSJiaxin Yu 				  RG_AUDPREAMP3INPUTSEL_SFT,
8098061734aSJiaxin Yu 				  RG_AUDPREAMP3INPUTSEL_MASK,
8108061734aSJiaxin Yu 				  pga_3_mux_map,
8118061734aSJiaxin Yu 				  pga_3_mux_map_value);
8128061734aSJiaxin Yu 
8138061734aSJiaxin Yu static const struct snd_kcontrol_new pga_3_mux_control =
8148061734aSJiaxin Yu 	SOC_DAPM_ENUM("PGA 3 Select", pga_3_mux_map_enum);
8158061734aSJiaxin Yu 
mt_sgen_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)8168061734aSJiaxin Yu static int mt_sgen_event(struct snd_soc_dapm_widget *w,
8178061734aSJiaxin Yu 			 struct snd_kcontrol *kcontrol,
8188061734aSJiaxin Yu 			 int event)
8198061734aSJiaxin Yu {
8208061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
8218061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
8228061734aSJiaxin Yu 
8238061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
8248061734aSJiaxin Yu 
8258061734aSJiaxin Yu 	switch (event) {
8268061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
8278061734aSJiaxin Yu 		/* sdm audio fifo clock power on */
8288061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0006);
8298061734aSJiaxin Yu 		/* scrambler clock on enable */
8308061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba1);
8318061734aSJiaxin Yu 		/* sdm power on */
8328061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0003);
8338061734aSJiaxin Yu 		/* sdm fifo enable */
8348061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x000b);
8358061734aSJiaxin Yu 
8368061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_SGEN_CFG0,
8378061734aSJiaxin Yu 				   0xff3f,
8388061734aSJiaxin Yu 				   0x0000);
8398061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_SGEN_CFG1,
8408061734aSJiaxin Yu 				   0xffff,
8418061734aSJiaxin Yu 				   0x0001);
8428061734aSJiaxin Yu 		break;
8438061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
8448061734aSJiaxin Yu 		/* DL scrambler disabling sequence */
8458061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON2, 0x0000);
8468061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba0);
8478061734aSJiaxin Yu 		break;
8488061734aSJiaxin Yu 	default:
8498061734aSJiaxin Yu 		break;
8508061734aSJiaxin Yu 	}
8518061734aSJiaxin Yu 
8528061734aSJiaxin Yu 	return 0;
8538061734aSJiaxin Yu }
8548061734aSJiaxin Yu 
mtk_hp_enable(struct mt6359_priv * priv)8558061734aSJiaxin Yu static void mtk_hp_enable(struct mt6359_priv *priv)
8568061734aSJiaxin Yu {
8578061734aSJiaxin Yu 	if (priv->hp_hifi_mode) {
8588061734aSJiaxin Yu 		/* Set HP DR bias current optimization, 010: 6uA */
8598061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11,
8608061734aSJiaxin Yu 				   DRBIAS_HP_MASK_SFT,
8618061734aSJiaxin Yu 				   DRBIAS_6UA << DRBIAS_HP_SFT);
8628061734aSJiaxin Yu 		/* Set HP & ZCD bias current optimization */
8638061734aSJiaxin Yu 		/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
8648061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
8658061734aSJiaxin Yu 				   IBIAS_ZCD_MASK_SFT,
8668061734aSJiaxin Yu 				   IBIAS_ZCD_4UA << IBIAS_ZCD_SFT);
8678061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
8688061734aSJiaxin Yu 				   IBIAS_HP_MASK_SFT,
8698061734aSJiaxin Yu 				   IBIAS_5UA << IBIAS_HP_SFT);
8708061734aSJiaxin Yu 	} else {
8718061734aSJiaxin Yu 		/* Set HP DR bias current optimization, 001: 5uA */
8728061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11,
8738061734aSJiaxin Yu 				   DRBIAS_HP_MASK_SFT,
8748061734aSJiaxin Yu 				   DRBIAS_5UA << DRBIAS_HP_SFT);
8758061734aSJiaxin Yu 		/* Set HP & ZCD bias current optimization */
8768061734aSJiaxin Yu 		/* 00: ZCD: 3uA, HP/HS/LO: 4uA */
8778061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
8788061734aSJiaxin Yu 				   IBIAS_ZCD_MASK_SFT,
8798061734aSJiaxin Yu 				   IBIAS_ZCD_3UA << IBIAS_ZCD_SFT);
8808061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
8818061734aSJiaxin Yu 				   IBIAS_HP_MASK_SFT,
8828061734aSJiaxin Yu 				   IBIAS_4UA << IBIAS_HP_SFT);
8838061734aSJiaxin Yu 	}
8848061734aSJiaxin Yu 
8858061734aSJiaxin Yu 	/* HP damp circuit enable */
8868061734aSJiaxin Yu 	/* Enable HPRN/HPLN output 4K to VCM */
8878061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x0087);
8888061734aSJiaxin Yu 
8898061734aSJiaxin Yu 	/* HP Feedback Cap select 2'b00: 15pF */
8908061734aSJiaxin Yu 	/* for >= 96KHz sampling rate: 2'b01: 10.5pF */
8918061734aSJiaxin Yu 	if (priv->dl_rate[MT6359_AIF_1] >= 96000)
8928061734aSJiaxin Yu 		regmap_update_bits(priv->regmap,
8938061734aSJiaxin Yu 				   MT6359_AUDDEC_ANA_CON4,
8948061734aSJiaxin Yu 				   RG_AUDHPHFCOMPBUFGAINSEL_VAUDP32_MASK_SFT,
8958061734aSJiaxin Yu 				   0x1 << RG_AUDHPHFCOMPBUFGAINSEL_VAUDP32_SFT);
8968061734aSJiaxin Yu 	else
8978061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON4, 0x0000);
8988061734aSJiaxin Yu 
8998061734aSJiaxin Yu 	/* Set HPP/N STB enhance circuits */
9008061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON2, 0xf133);
9018061734aSJiaxin Yu 
9028061734aSJiaxin Yu 	/* Enable HP aux output stage */
9038061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x000c);
9048061734aSJiaxin Yu 	/* Enable HP aux feedback loop */
9058061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x003c);
9068061734aSJiaxin Yu 	/* Enable HP aux CMFB loop */
9078061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0c00);
9088061734aSJiaxin Yu 	/* Enable HP driver bias circuits */
9098061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30c0);
9108061734aSJiaxin Yu 	/* Enable HP driver core circuits */
9118061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30f0);
9128061734aSJiaxin Yu 	/* Short HP main output to HP aux output stage */
9138061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x00fc);
9148061734aSJiaxin Yu 
9158061734aSJiaxin Yu 	/* Increase HP input pair current to HPM step by step */
9168061734aSJiaxin Yu 	hp_in_pair_current(priv, true);
9178061734aSJiaxin Yu 
9188061734aSJiaxin Yu 	/* Enable HP main CMFB loop */
9198061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0e00);
9208061734aSJiaxin Yu 	/* Disable HP aux CMFB loop */
9218061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0200);
9228061734aSJiaxin Yu 
9238061734aSJiaxin Yu 	/* Enable HP main output stage */
9248061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x00ff);
9258061734aSJiaxin Yu 	/* Enable HPR/L main output stage step by step */
9268061734aSJiaxin Yu 	hp_main_output_ramp(priv, true);
9278061734aSJiaxin Yu 
9288061734aSJiaxin Yu 	/* Reduce HP aux feedback loop gain */
9298061734aSJiaxin Yu 	hp_aux_feedback_loop_gain_ramp(priv, true);
9308061734aSJiaxin Yu 	/* Disable HP aux feedback loop */
9318061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77cf);
9328061734aSJiaxin Yu 
9338061734aSJiaxin Yu 	/* apply volume setting */
9348061734aSJiaxin Yu 	headset_volume_ramp(priv,
9358061734aSJiaxin Yu 			    DL_GAIN_N_22DB,
9368061734aSJiaxin Yu 			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]);
9378061734aSJiaxin Yu 
9388061734aSJiaxin Yu 	/* Disable HP aux output stage */
9398061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77c3);
9408061734aSJiaxin Yu 	/* Unshort HP main output to HP aux output stage */
9418061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x7703);
9428061734aSJiaxin Yu 	usleep_range(100, 120);
9438061734aSJiaxin Yu 
9448061734aSJiaxin Yu 	/* Enable AUD_CLK */
9458061734aSJiaxin Yu 	mt6359_set_decoder_clk(priv, true);
9468061734aSJiaxin Yu 
9478061734aSJiaxin Yu 	/* Enable Audio DAC  */
9488061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x30ff);
9498061734aSJiaxin Yu 	if (priv->hp_hifi_mode) {
9508061734aSJiaxin Yu 		/* Enable low-noise mode of DAC */
9518061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0xf201);
9528061734aSJiaxin Yu 	} else {
9538061734aSJiaxin Yu 		/* Disable low-noise mode of DAC */
9548061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0xf200);
9558061734aSJiaxin Yu 	}
9568061734aSJiaxin Yu 	usleep_range(100, 120);
9578061734aSJiaxin Yu 
9588061734aSJiaxin Yu 	/* Switch HPL MUX to audio DAC */
9598061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x32ff);
9608061734aSJiaxin Yu 	/* Switch HPR MUX to audio DAC */
9618061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x3aff);
9628061734aSJiaxin Yu 
9638061734aSJiaxin Yu 	/* Disable Pull-down HPL/R to AVSS28_AUD */
9648061734aSJiaxin Yu 	hp_pull_down(priv, false);
9658061734aSJiaxin Yu }
9668061734aSJiaxin Yu 
mtk_hp_disable(struct mt6359_priv * priv)9678061734aSJiaxin Yu static void mtk_hp_disable(struct mt6359_priv *priv)
9688061734aSJiaxin Yu {
9698061734aSJiaxin Yu 	/* Pull-down HPL/R to AVSS28_AUD */
9708061734aSJiaxin Yu 	hp_pull_down(priv, true);
9718061734aSJiaxin Yu 
9728061734aSJiaxin Yu 	/* HPR/HPL mux to open */
9738061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
9748061734aSJiaxin Yu 			   0x0f00, 0x0000);
9758061734aSJiaxin Yu 
9768061734aSJiaxin Yu 	/* Disable low-noise mode of DAC */
9778061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON9,
9788061734aSJiaxin Yu 			   0x0001, 0x0000);
9798061734aSJiaxin Yu 
9808061734aSJiaxin Yu 	/* Disable Audio DAC */
9818061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
9828061734aSJiaxin Yu 			   0x000f, 0x0000);
9838061734aSJiaxin Yu 
9848061734aSJiaxin Yu 	/* Disable AUD_CLK */
9858061734aSJiaxin Yu 	mt6359_set_decoder_clk(priv, false);
9868061734aSJiaxin Yu 
9878061734aSJiaxin Yu 	/* Short HP main output to HP aux output stage */
9888061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77c3);
9898061734aSJiaxin Yu 	/* Enable HP aux output stage */
9908061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77cf);
9918061734aSJiaxin Yu 
9928061734aSJiaxin Yu 	/* decrease HPL/R gain to normal gain step by step */
9938061734aSJiaxin Yu 	headset_volume_ramp(priv,
9948061734aSJiaxin Yu 			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL],
9958061734aSJiaxin Yu 			    DL_GAIN_N_22DB);
9968061734aSJiaxin Yu 
9978061734aSJiaxin Yu 	/* Enable HP aux feedback loop */
9988061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x77ff);
9998061734aSJiaxin Yu 
10008061734aSJiaxin Yu 	/* Reduce HP aux feedback loop gain */
10018061734aSJiaxin Yu 	hp_aux_feedback_loop_gain_ramp(priv, false);
10028061734aSJiaxin Yu 
10038061734aSJiaxin Yu 	/* decrease HPR/L main output stage step by step */
10048061734aSJiaxin Yu 	hp_main_output_ramp(priv, false);
10058061734aSJiaxin Yu 
10068061734aSJiaxin Yu 	/* Disable HP main output stage */
10078061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1, 0x3, 0x0);
10088061734aSJiaxin Yu 
10098061734aSJiaxin Yu 	/* Enable HP aux CMFB loop */
10108061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0e01);
10118061734aSJiaxin Yu 
10128061734aSJiaxin Yu 	/* Disable HP main CMFB loop */
10138061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0c01);
10148061734aSJiaxin Yu 
10158061734aSJiaxin Yu 	/* Decrease HP input pair current to 2'b00 step by step */
10168061734aSJiaxin Yu 	hp_in_pair_current(priv, false);
10178061734aSJiaxin Yu 
10188061734aSJiaxin Yu 	/* Unshort HP main output to HP aux output stage */
10198061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1,
10208061734aSJiaxin Yu 			   0x3 << 6, 0x0);
10218061734aSJiaxin Yu 
10228061734aSJiaxin Yu 	/* Disable HP driver core circuits */
10238061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
10248061734aSJiaxin Yu 			   0x3 << 4, 0x0);
10258061734aSJiaxin Yu 
10268061734aSJiaxin Yu 	/* Disable HP driver bias circuits */
10278061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
10288061734aSJiaxin Yu 			   0x3 << 6, 0x0);
10298061734aSJiaxin Yu 
10308061734aSJiaxin Yu 	/* Disable HP aux CMFB loop */
10318061734aSJiaxin Yu 	regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x201);
10328061734aSJiaxin Yu 
10338061734aSJiaxin Yu 	/* Disable HP aux feedback loop */
10348061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1,
10358061734aSJiaxin Yu 			   0x3 << 4, 0x0);
10368061734aSJiaxin Yu 
10378061734aSJiaxin Yu 	/* Disable HP aux output stage */
10388061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON1,
10398061734aSJiaxin Yu 			   0x3 << 2, 0x0);
10408061734aSJiaxin Yu }
10418061734aSJiaxin Yu 
mt_hp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)10428061734aSJiaxin Yu static int mt_hp_event(struct snd_soc_dapm_widget *w,
10438061734aSJiaxin Yu 		       struct snd_kcontrol *kcontrol,
10448061734aSJiaxin Yu 		       int event)
10458061734aSJiaxin Yu {
10468061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
10478061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
10488061734aSJiaxin Yu 	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
10498061734aSJiaxin Yu 	int device = DEVICE_HP;
10508061734aSJiaxin Yu 
10518061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
10528061734aSJiaxin Yu 		__func__, event, priv->dev_counter[device], mux);
10538061734aSJiaxin Yu 
10548061734aSJiaxin Yu 	switch (event) {
10558061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
10568061734aSJiaxin Yu 		priv->dev_counter[device]++;
10578061734aSJiaxin Yu 		if (mux == HP_MUX_HP)
10588061734aSJiaxin Yu 			mtk_hp_enable(priv);
10598061734aSJiaxin Yu 		break;
10608061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
10618061734aSJiaxin Yu 		priv->dev_counter[device]--;
10628061734aSJiaxin Yu 		if (mux == HP_MUX_HP)
10638061734aSJiaxin Yu 			mtk_hp_disable(priv);
10648061734aSJiaxin Yu 		break;
10658061734aSJiaxin Yu 	default:
10668061734aSJiaxin Yu 		break;
10678061734aSJiaxin Yu 	}
10688061734aSJiaxin Yu 
10698061734aSJiaxin Yu 	return 0;
10708061734aSJiaxin Yu }
10718061734aSJiaxin Yu 
mt_rcv_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)10728061734aSJiaxin Yu static int mt_rcv_event(struct snd_soc_dapm_widget *w,
10738061734aSJiaxin Yu 			struct snd_kcontrol *kcontrol,
10748061734aSJiaxin Yu 			int event)
10758061734aSJiaxin Yu {
10768061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
10778061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
10788061734aSJiaxin Yu 
10798061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, mux %u\n",
10808061734aSJiaxin Yu 		__func__, event, dapm_kcontrol_get_value(w->kcontrols[0]));
10818061734aSJiaxin Yu 
10828061734aSJiaxin Yu 	switch (event) {
10838061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
10848061734aSJiaxin Yu 		/* Disable handset short-circuit protection */
10858061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0010);
10868061734aSJiaxin Yu 
10878061734aSJiaxin Yu 		/* Set RCV DR bias current optimization, 010: 6uA */
10888061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11,
10898061734aSJiaxin Yu 				   DRBIAS_HS_MASK_SFT,
10908061734aSJiaxin Yu 				   DRBIAS_6UA << DRBIAS_HS_SFT);
10918061734aSJiaxin Yu 		/* Set RCV & ZCD bias current optimization */
10928061734aSJiaxin Yu 		/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
10938061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
10948061734aSJiaxin Yu 				   IBIAS_ZCD_MASK_SFT,
10958061734aSJiaxin Yu 				   IBIAS_ZCD_4UA << IBIAS_ZCD_SFT);
10968061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
10978061734aSJiaxin Yu 				   IBIAS_HS_MASK_SFT,
10988061734aSJiaxin Yu 				   IBIAS_5UA << IBIAS_HS_SFT);
10998061734aSJiaxin Yu 
11008061734aSJiaxin Yu 		/* Set HS STB enhance circuits */
11018061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0090);
11028061734aSJiaxin Yu 
11038061734aSJiaxin Yu 		/* Set HS output stage (3'b111 = 8x) */
11048061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x7000);
11058061734aSJiaxin Yu 
11068061734aSJiaxin Yu 		/* Enable HS driver bias circuits */
11078061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0092);
11088061734aSJiaxin Yu 		/* Enable HS driver core circuits */
11098061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x0093);
11108061734aSJiaxin Yu 
11118061734aSJiaxin Yu 		/* Set HS gain to normal gain step by step */
11128061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON3,
11138061734aSJiaxin Yu 			     priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL]);
11148061734aSJiaxin Yu 
11158061734aSJiaxin Yu 		/* Enable AUD_CLK */
11168061734aSJiaxin Yu 		mt6359_set_decoder_clk(priv, true);
11178061734aSJiaxin Yu 
11188061734aSJiaxin Yu 		/* Enable Audio DAC  */
11198061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x0009);
11208061734aSJiaxin Yu 		/* Enable low-noise mode of DAC */
11218061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0001);
11228061734aSJiaxin Yu 		/* Switch HS MUX to audio DAC */
11238061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON6, 0x009b);
11248061734aSJiaxin Yu 		break;
11258061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
11268061734aSJiaxin Yu 		/* HS mux to open */
11278061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6,
11288061734aSJiaxin Yu 				   RG_AUDHSMUXINPUTSEL_VAUDP32_MASK_SFT,
11298061734aSJiaxin Yu 				   RCV_MUX_OPEN);
11308061734aSJiaxin Yu 
11318061734aSJiaxin Yu 		/* Disable Audio DAC */
11328061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
11338061734aSJiaxin Yu 				   0x000f, 0x0000);
11348061734aSJiaxin Yu 
11358061734aSJiaxin Yu 		/* Disable AUD_CLK */
11368061734aSJiaxin Yu 		mt6359_set_decoder_clk(priv, false);
11378061734aSJiaxin Yu 
11388061734aSJiaxin Yu 		/* decrease HS gain to minimum gain step by step */
11398061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON3, DL_GAIN_N_40DB);
11408061734aSJiaxin Yu 
11418061734aSJiaxin Yu 		/* Disable HS driver core circuits */
11428061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6,
11438061734aSJiaxin Yu 				   RG_AUDHSPWRUP_VAUDP32_MASK_SFT, 0x0);
11448061734aSJiaxin Yu 
11458061734aSJiaxin Yu 		/* Disable HS driver bias circuits */
11468061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6,
11478061734aSJiaxin Yu 				   RG_AUDHSPWRUP_IBIAS_VAUDP32_MASK_SFT, 0x0);
11488061734aSJiaxin Yu 		break;
11498061734aSJiaxin Yu 	default:
11508061734aSJiaxin Yu 		break;
11518061734aSJiaxin Yu 	}
11528061734aSJiaxin Yu 
11538061734aSJiaxin Yu 	return 0;
11548061734aSJiaxin Yu }
11558061734aSJiaxin Yu 
mt_lo_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)11568061734aSJiaxin Yu static int mt_lo_event(struct snd_soc_dapm_widget *w,
11578061734aSJiaxin Yu 		       struct snd_kcontrol *kcontrol,
11588061734aSJiaxin Yu 		       int event)
11598061734aSJiaxin Yu {
11608061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
11618061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
1162104ce27bSTrevor Wu 	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
11638061734aSJiaxin Yu 
11648061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, mux %u\n",
1165104ce27bSTrevor Wu 		__func__, event, mux);
11668061734aSJiaxin Yu 
11678061734aSJiaxin Yu 	switch (event) {
11688061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
11698061734aSJiaxin Yu 		/* Disable handset short-circuit protection */
11708061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0010);
11718061734aSJiaxin Yu 
11728061734aSJiaxin Yu 		/* Set LO DR bias current optimization, 010: 6uA */
11738061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON11,
11748061734aSJiaxin Yu 				   DRBIAS_LO_MASK_SFT,
11758061734aSJiaxin Yu 				   DRBIAS_6UA << DRBIAS_LO_SFT);
11768061734aSJiaxin Yu 		/* Set LO & ZCD bias current optimization */
11778061734aSJiaxin Yu 		/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
11788061734aSJiaxin Yu 		if (priv->dev_counter[DEVICE_HP] == 0)
11798061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
11808061734aSJiaxin Yu 					   MT6359_AUDDEC_ANA_CON12,
11818061734aSJiaxin Yu 					   IBIAS_ZCD_MASK_SFT,
11828061734aSJiaxin Yu 					   IBIAS_ZCD_4UA << IBIAS_ZCD_SFT);
11838061734aSJiaxin Yu 
11848061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON12,
11858061734aSJiaxin Yu 				   IBIAS_LO_MASK_SFT,
11868061734aSJiaxin Yu 				   IBIAS_5UA << IBIAS_LO_SFT);
11878061734aSJiaxin Yu 
11888061734aSJiaxin Yu 		/* Set LO STB enhance circuits */
11898061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0110);
11908061734aSJiaxin Yu 
11918061734aSJiaxin Yu 		/* Enable LO driver bias circuits */
11928061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0112);
11938061734aSJiaxin Yu 		/* Enable LO driver core circuits */
11948061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0113);
11958061734aSJiaxin Yu 
11968061734aSJiaxin Yu 		/* Set LO gain to normal gain step by step */
11978061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON1,
11988061734aSJiaxin Yu 			     priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL]);
11998061734aSJiaxin Yu 
12008061734aSJiaxin Yu 		/* Enable AUD_CLK */
12018061734aSJiaxin Yu 		mt6359_set_decoder_clk(priv, true);
12028061734aSJiaxin Yu 
1203104ce27bSTrevor Wu 		/* Switch LOL MUX to audio DAC */
1204104ce27bSTrevor Wu 		if (mux == LO_MUX_L_DAC) {
1205104ce27bSTrevor Wu 			if (priv->dev_counter[DEVICE_HP] > 0) {
1206104ce27bSTrevor Wu 				dev_info(priv->dev, "%s(), can not enable DAC, hp count %d\n",
1207104ce27bSTrevor Wu 					 __func__, priv->dev_counter[DEVICE_HP]);
1208104ce27bSTrevor Wu 				break;
1209104ce27bSTrevor Wu 			}
1210104ce27bSTrevor Wu 			/* Enable DACL and switch HP MUX to open*/
1211104ce27bSTrevor Wu 			regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON0, 0x3009);
1212104ce27bSTrevor Wu 			/* Disable low-noise mode of DAC */
1213104ce27bSTrevor Wu 			regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0xf200);
1214104ce27bSTrevor Wu 			usleep_range(100, 120);
1215104ce27bSTrevor Wu 			/* Switch LOL MUX to DACL */
1216104ce27bSTrevor Wu 			regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x0117);
1217104ce27bSTrevor Wu 		} else if (mux == LO_MUX_3RD_DAC) {
12188061734aSJiaxin Yu 			/* Enable Audio DAC (3rd DAC) */
12198061734aSJiaxin Yu 			regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x3113);
12208061734aSJiaxin Yu 			/* Enable low-noise mode of DAC */
12218061734aSJiaxin Yu 			if (priv->dev_counter[DEVICE_HP] == 0)
1222104ce27bSTrevor Wu 				regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON9, 0x0001);
12238061734aSJiaxin Yu 			/* Switch LOL MUX to audio 3rd DAC */
12248061734aSJiaxin Yu 			regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON7, 0x311b);
1225104ce27bSTrevor Wu 		}
12268061734aSJiaxin Yu 		break;
12278061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
12288061734aSJiaxin Yu 		/* Switch LOL MUX to open */
12298061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7,
12308061734aSJiaxin Yu 				   RG_AUDLOLMUXINPUTSEL_VAUDP32_MASK_SFT,
12318061734aSJiaxin Yu 				   LO_MUX_OPEN);
12328061734aSJiaxin Yu 
12338061734aSJiaxin Yu 		/* Disable Audio DAC */
12348061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
12358061734aSJiaxin Yu 				   0x000f, 0x0000);
12368061734aSJiaxin Yu 
1237104ce27bSTrevor Wu 		if (mux == LO_MUX_L_DAC) {
1238104ce27bSTrevor Wu 			/* Disable HP driver core circuits */
1239104ce27bSTrevor Wu 			regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
1240104ce27bSTrevor Wu 					   0x3 << 4, 0x0);
1241104ce27bSTrevor Wu 			/* Disable HP driver bias circuits */
1242104ce27bSTrevor Wu 			regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
1243104ce27bSTrevor Wu 					   0x3 << 6, 0x0);
1244104ce27bSTrevor Wu 		}
1245104ce27bSTrevor Wu 
12468061734aSJiaxin Yu 		/* Disable AUD_CLK */
12478061734aSJiaxin Yu 		mt6359_set_decoder_clk(priv, false);
12488061734aSJiaxin Yu 
12498061734aSJiaxin Yu 		/* decrease LO gain to minimum gain step by step */
12508061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON1, DL_GAIN_N_40DB);
12518061734aSJiaxin Yu 
12528061734aSJiaxin Yu 		/* Disable LO driver core circuits */
12538061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7,
12548061734aSJiaxin Yu 				   RG_AUDLOLPWRUP_VAUDP32_MASK_SFT, 0x0);
12558061734aSJiaxin Yu 
12568061734aSJiaxin Yu 		/* Disable LO driver bias circuits */
12578061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7,
12588061734aSJiaxin Yu 				   RG_AUDLOLPWRUP_IBIAS_VAUDP32_MASK_SFT, 0x0);
12598061734aSJiaxin Yu 		break;
12608061734aSJiaxin Yu 	default:
12618061734aSJiaxin Yu 		break;
12628061734aSJiaxin Yu 	}
12638061734aSJiaxin Yu 
12648061734aSJiaxin Yu 	return 0;
12658061734aSJiaxin Yu }
12668061734aSJiaxin Yu 
mt_adc_clk_gen_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)12678061734aSJiaxin Yu static int mt_adc_clk_gen_event(struct snd_soc_dapm_widget *w,
12688061734aSJiaxin Yu 				struct snd_kcontrol *kcontrol,
12698061734aSJiaxin Yu 				int event)
12708061734aSJiaxin Yu {
12718061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
12728061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
12738061734aSJiaxin Yu 
12748061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x\n", __func__, event);
12758061734aSJiaxin Yu 
12768061734aSJiaxin Yu 	switch (event) {
12778061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
12788061734aSJiaxin Yu 		/* ADC CLK from CLKGEN (6.5MHz) */
12798061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12808061734aSJiaxin Yu 				   RG_AUDADCCLKRSTB_MASK_SFT,
12818061734aSJiaxin Yu 				   0x1 << RG_AUDADCCLKRSTB_SFT);
12828061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12838061734aSJiaxin Yu 				   RG_AUDADCCLKSOURCE_MASK_SFT, 0x0);
12848061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12858061734aSJiaxin Yu 				   RG_AUDADCCLKSEL_MASK_SFT, 0x0);
12868061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12878061734aSJiaxin Yu 				   RG_AUDADCCLKGENMODE_MASK_SFT,
12888061734aSJiaxin Yu 				   0x1 << RG_AUDADCCLKGENMODE_SFT);
12898061734aSJiaxin Yu 		break;
12908061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
12918061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12928061734aSJiaxin Yu 				   RG_AUDADCCLKSOURCE_MASK_SFT, 0x0);
12938061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12948061734aSJiaxin Yu 				   RG_AUDADCCLKSEL_MASK_SFT, 0x0);
12958061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12968061734aSJiaxin Yu 				   RG_AUDADCCLKGENMODE_MASK_SFT, 0x0);
12978061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON5,
12988061734aSJiaxin Yu 				   RG_AUDADCCLKRSTB_MASK_SFT, 0x0);
12998061734aSJiaxin Yu 		break;
13008061734aSJiaxin Yu 	default:
13018061734aSJiaxin Yu 		break;
13028061734aSJiaxin Yu 	}
13038061734aSJiaxin Yu 
13048061734aSJiaxin Yu 	return 0;
13058061734aSJiaxin Yu }
13068061734aSJiaxin Yu 
mt_dcc_clk_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)13078061734aSJiaxin Yu static int mt_dcc_clk_event(struct snd_soc_dapm_widget *w,
13088061734aSJiaxin Yu 			    struct snd_kcontrol *kcontrol,
13098061734aSJiaxin Yu 			    int event)
13108061734aSJiaxin Yu {
13118061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
13128061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
13138061734aSJiaxin Yu 
13148061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x\n", __func__, event);
13158061734aSJiaxin Yu 
13168061734aSJiaxin Yu 	switch (event) {
13178061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
13188061734aSJiaxin Yu 		/* DCC 50k CLK (from 26M) */
13198061734aSJiaxin Yu 		/* MT6359_AFE_DCCLK_CFG0, bit 3 for dm ck swap */
13208061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0,
13218061734aSJiaxin Yu 				   0xfff7, 0x2062);
13228061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0,
13238061734aSJiaxin Yu 				   0xfff7, 0x2060);
13248061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0,
13258061734aSJiaxin Yu 				   0xfff7, 0x2061);
13268061734aSJiaxin Yu 
13278061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFE_DCCLK_CFG1, 0x0100);
13288061734aSJiaxin Yu 		break;
13298061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
13308061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0,
13318061734aSJiaxin Yu 				   0xfff7, 0x2060);
13328061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_DCCLK_CFG0,
13338061734aSJiaxin Yu 				   0xfff7, 0x2062);
13348061734aSJiaxin Yu 		break;
13358061734aSJiaxin Yu 	default:
13368061734aSJiaxin Yu 		break;
13378061734aSJiaxin Yu 	}
13388061734aSJiaxin Yu 
13398061734aSJiaxin Yu 	return 0;
13408061734aSJiaxin Yu }
13418061734aSJiaxin Yu 
mt_mic_bias_0_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)13428061734aSJiaxin Yu static int mt_mic_bias_0_event(struct snd_soc_dapm_widget *w,
13438061734aSJiaxin Yu 			       struct snd_kcontrol *kcontrol,
13448061734aSJiaxin Yu 			       int event)
13458061734aSJiaxin Yu {
13468061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
13478061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
13488061734aSJiaxin Yu 	unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_0];
13498061734aSJiaxin Yu 
13508061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n",
13518061734aSJiaxin Yu 		__func__, event, mic_type);
13528061734aSJiaxin Yu 
13538061734aSJiaxin Yu 	switch (event) {
13548061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
13558061734aSJiaxin Yu 		switch (mic_type) {
13568061734aSJiaxin Yu 		case MIC_TYPE_MUX_DCC_ECM_DIFF:
13578061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
13588061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON15,
13598061734aSJiaxin Yu 					   0xff00, 0x7700);
13608061734aSJiaxin Yu 			break;
13618061734aSJiaxin Yu 		case MIC_TYPE_MUX_DCC_ECM_SINGLE:
13628061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
13638061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON15,
13648061734aSJiaxin Yu 					   0xff00, 0x1100);
13658061734aSJiaxin Yu 			break;
13668061734aSJiaxin Yu 		default:
13678061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
13688061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON15,
13698061734aSJiaxin Yu 					   0xff00, 0x0000);
13708061734aSJiaxin Yu 			break;
13718061734aSJiaxin Yu 		}
13728061734aSJiaxin Yu 
13738061734aSJiaxin Yu 		/* DMIC enable */
13748061734aSJiaxin Yu 		regmap_write(priv->regmap,
13758061734aSJiaxin Yu 			     MT6359_AUDENC_ANA_CON14, 0x0004);
13768061734aSJiaxin Yu 		/* MISBIAS0 = 1P9V */
13778061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON15,
13788061734aSJiaxin Yu 				   RG_AUDMICBIAS0VREF_MASK_SFT,
13798061734aSJiaxin Yu 				   MIC_BIAS_1P9 << RG_AUDMICBIAS0VREF_SFT);
13808061734aSJiaxin Yu 		/* normal power select */
13818061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON15,
13828061734aSJiaxin Yu 				   RG_AUDMICBIAS0LOWPEN_MASK_SFT,
13838061734aSJiaxin Yu 				   0 << RG_AUDMICBIAS0LOWPEN_SFT);
13848061734aSJiaxin Yu 		break;
13858061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
13868061734aSJiaxin Yu 		/* Disable MICBIAS0, MISBIAS0 = 1P7V */
13878061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDENC_ANA_CON15, 0x0000);
13888061734aSJiaxin Yu 		break;
13898061734aSJiaxin Yu 	default:
13908061734aSJiaxin Yu 		break;
13918061734aSJiaxin Yu 	}
13928061734aSJiaxin Yu 
13938061734aSJiaxin Yu 	return 0;
13948061734aSJiaxin Yu }
13958061734aSJiaxin Yu 
mt_mic_bias_1_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)13968061734aSJiaxin Yu static int mt_mic_bias_1_event(struct snd_soc_dapm_widget *w,
13978061734aSJiaxin Yu 			       struct snd_kcontrol *kcontrol,
13988061734aSJiaxin Yu 			       int event)
13998061734aSJiaxin Yu {
14008061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
14018061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
14028061734aSJiaxin Yu 	unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_1];
14038061734aSJiaxin Yu 
14048061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n",
14058061734aSJiaxin Yu 		__func__, event, mic_type);
14068061734aSJiaxin Yu 
14078061734aSJiaxin Yu 	switch (event) {
14088061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
14098061734aSJiaxin Yu 		/* MISBIAS1 = 2P6V */
14108061734aSJiaxin Yu 		if (mic_type == MIC_TYPE_MUX_DCC_ECM_SINGLE)
14118061734aSJiaxin Yu 			regmap_write(priv->regmap,
14128061734aSJiaxin Yu 				     MT6359_AUDENC_ANA_CON16, 0x0160);
14138061734aSJiaxin Yu 		else
14148061734aSJiaxin Yu 			regmap_write(priv->regmap,
14158061734aSJiaxin Yu 				     MT6359_AUDENC_ANA_CON16, 0x0060);
14168061734aSJiaxin Yu 
14178061734aSJiaxin Yu 		/* normal power select */
14188061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON16,
14198061734aSJiaxin Yu 				   RG_AUDMICBIAS1LOWPEN_MASK_SFT,
14208061734aSJiaxin Yu 				   0 << RG_AUDMICBIAS1LOWPEN_SFT);
14218061734aSJiaxin Yu 		break;
14228061734aSJiaxin Yu 	default:
14238061734aSJiaxin Yu 		break;
14248061734aSJiaxin Yu 	}
14258061734aSJiaxin Yu 
14268061734aSJiaxin Yu 	return 0;
14278061734aSJiaxin Yu }
14288061734aSJiaxin Yu 
mt_mic_bias_2_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)14298061734aSJiaxin Yu static int mt_mic_bias_2_event(struct snd_soc_dapm_widget *w,
14308061734aSJiaxin Yu 			       struct snd_kcontrol *kcontrol,
14318061734aSJiaxin Yu 			       int event)
14328061734aSJiaxin Yu {
14338061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
14348061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
14358061734aSJiaxin Yu 	unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE_2];
14368061734aSJiaxin Yu 
14378061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event 0x%x, mic_type %d\n",
14388061734aSJiaxin Yu 		__func__, event, mic_type);
14398061734aSJiaxin Yu 
14408061734aSJiaxin Yu 	switch (event) {
14418061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
14428061734aSJiaxin Yu 		switch (mic_type) {
14438061734aSJiaxin Yu 		case MIC_TYPE_MUX_DCC_ECM_DIFF:
14448061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
14458061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON17,
14468061734aSJiaxin Yu 					   0xff00, 0x7700);
14478061734aSJiaxin Yu 			break;
14488061734aSJiaxin Yu 		case MIC_TYPE_MUX_DCC_ECM_SINGLE:
14498061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
14508061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON17,
14518061734aSJiaxin Yu 					   0xff00, 0x1100);
14528061734aSJiaxin Yu 			break;
14538061734aSJiaxin Yu 		default:
14548061734aSJiaxin Yu 			regmap_update_bits(priv->regmap,
14558061734aSJiaxin Yu 					   MT6359_AUDENC_ANA_CON17,
14568061734aSJiaxin Yu 					   0xff00, 0x0000);
14578061734aSJiaxin Yu 			break;
14588061734aSJiaxin Yu 		}
14598061734aSJiaxin Yu 
14608061734aSJiaxin Yu 		/* MISBIAS2 = 1P9V */
14618061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON17,
14628061734aSJiaxin Yu 				   RG_AUDMICBIAS2VREF_MASK_SFT,
14638061734aSJiaxin Yu 				   MIC_BIAS_1P9 << RG_AUDMICBIAS2VREF_SFT);
14648061734aSJiaxin Yu 		/* normal power select */
14658061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON17,
14668061734aSJiaxin Yu 				   RG_AUDMICBIAS2LOWPEN_MASK_SFT,
14678061734aSJiaxin Yu 				   0 << RG_AUDMICBIAS2LOWPEN_SFT);
14688061734aSJiaxin Yu 		break;
14698061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
14708061734aSJiaxin Yu 		/* Disable MICBIAS2, MISBIAS0 = 1P7V */
14718061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDENC_ANA_CON17, 0x0000);
14728061734aSJiaxin Yu 		break;
14738061734aSJiaxin Yu 	default:
14748061734aSJiaxin Yu 		break;
14758061734aSJiaxin Yu 	}
14768061734aSJiaxin Yu 
14778061734aSJiaxin Yu 	return 0;
14788061734aSJiaxin Yu }
14798061734aSJiaxin Yu 
mt_mtkaif_tx_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)14808061734aSJiaxin Yu static int mt_mtkaif_tx_event(struct snd_soc_dapm_widget *w,
14818061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
14828061734aSJiaxin Yu 			      int event)
14838061734aSJiaxin Yu {
14848061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
14858061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
14868061734aSJiaxin Yu 
14878061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
14888061734aSJiaxin Yu 
14898061734aSJiaxin Yu 	switch (event) {
14908061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
14918061734aSJiaxin Yu 		mt6359_mtkaif_tx_enable(priv);
14928061734aSJiaxin Yu 		break;
14938061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
14948061734aSJiaxin Yu 		mt6359_mtkaif_tx_disable(priv);
14958061734aSJiaxin Yu 		break;
14968061734aSJiaxin Yu 	default:
14978061734aSJiaxin Yu 		break;
14988061734aSJiaxin Yu 	}
14998061734aSJiaxin Yu 
15008061734aSJiaxin Yu 	return 0;
15018061734aSJiaxin Yu }
15028061734aSJiaxin Yu 
mt_ul_src_dmic_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)15038061734aSJiaxin Yu static int mt_ul_src_dmic_event(struct snd_soc_dapm_widget *w,
15048061734aSJiaxin Yu 				struct snd_kcontrol *kcontrol,
15058061734aSJiaxin Yu 				int event)
15068061734aSJiaxin Yu {
15078061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15088061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15098061734aSJiaxin Yu 
15108061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
15118061734aSJiaxin Yu 
15128061734aSJiaxin Yu 	switch (event) {
15138061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
15148061734aSJiaxin Yu 		/* UL dmic setting */
15158061734aSJiaxin Yu 		if (priv->dmic_one_wire_mode)
15168061734aSJiaxin Yu 			regmap_write(priv->regmap, MT6359_AFE_UL_SRC_CON0_H,
15178061734aSJiaxin Yu 				     0x0400);
15188061734aSJiaxin Yu 		else
15198061734aSJiaxin Yu 			regmap_write(priv->regmap, MT6359_AFE_UL_SRC_CON0_H,
15208061734aSJiaxin Yu 				     0x0080);
15218061734aSJiaxin Yu 		/* default one wire, 3.25M */
15228061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_UL_SRC_CON0_L,
15238061734aSJiaxin Yu 				   0xfffc, 0x0000);
15248061734aSJiaxin Yu 		break;
15258061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
15268061734aSJiaxin Yu 		regmap_write(priv->regmap,
15278061734aSJiaxin Yu 			     MT6359_AFE_UL_SRC_CON0_H, 0x0000);
15288061734aSJiaxin Yu 		break;
15298061734aSJiaxin Yu 	default:
15308061734aSJiaxin Yu 		break;
15318061734aSJiaxin Yu 	}
15328061734aSJiaxin Yu 
15338061734aSJiaxin Yu 	return 0;
15348061734aSJiaxin Yu }
15358061734aSJiaxin Yu 
mt_ul_src_34_dmic_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)15368061734aSJiaxin Yu static int mt_ul_src_34_dmic_event(struct snd_soc_dapm_widget *w,
15378061734aSJiaxin Yu 				   struct snd_kcontrol *kcontrol,
15388061734aSJiaxin Yu 				   int event)
15398061734aSJiaxin Yu {
15408061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15418061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15428061734aSJiaxin Yu 
15438061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
15448061734aSJiaxin Yu 
15458061734aSJiaxin Yu 	switch (event) {
15468061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
15478061734aSJiaxin Yu 		/* default two wire, 3.25M */
15488061734aSJiaxin Yu 		regmap_write(priv->regmap,
15498061734aSJiaxin Yu 			     MT6359_AFE_ADDA6_L_SRC_CON0_H, 0x0080);
15508061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFE_ADDA6_UL_SRC_CON0_L,
15518061734aSJiaxin Yu 				   0xfffc, 0x0000);
15528061734aSJiaxin Yu 		break;
15538061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
15548061734aSJiaxin Yu 		regmap_write(priv->regmap,
15558061734aSJiaxin Yu 			     MT6359_AFE_ADDA6_L_SRC_CON0_H, 0x0000);
15568061734aSJiaxin Yu 		break;
15578061734aSJiaxin Yu 	default:
15588061734aSJiaxin Yu 		break;
15598061734aSJiaxin Yu 	}
15608061734aSJiaxin Yu 
15618061734aSJiaxin Yu 	return 0;
15628061734aSJiaxin Yu }
15638061734aSJiaxin Yu 
mt_adc_l_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)15648061734aSJiaxin Yu static int mt_adc_l_event(struct snd_soc_dapm_widget *w,
15658061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
15668061734aSJiaxin Yu 			  int event)
15678061734aSJiaxin Yu {
15688061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15698061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15708061734aSJiaxin Yu 
15718061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
15728061734aSJiaxin Yu 
15738061734aSJiaxin Yu 	switch (event) {
15748061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
15758061734aSJiaxin Yu 		usleep_range(100, 120);
15768061734aSJiaxin Yu 		/* Audio L preamplifier DCC precharge off */
15778061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0,
15788061734aSJiaxin Yu 				   RG_AUDPREAMPLDCPRECHARGE_MASK_SFT,
15798061734aSJiaxin Yu 				   0x0);
15808061734aSJiaxin Yu 		break;
15818061734aSJiaxin Yu 	default:
15828061734aSJiaxin Yu 		break;
15838061734aSJiaxin Yu 	}
15848061734aSJiaxin Yu 
15858061734aSJiaxin Yu 	return 0;
15868061734aSJiaxin Yu }
15878061734aSJiaxin Yu 
mt_adc_r_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)15888061734aSJiaxin Yu static int mt_adc_r_event(struct snd_soc_dapm_widget *w,
15898061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
15908061734aSJiaxin Yu 			  int event)
15918061734aSJiaxin Yu {
15928061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15938061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15948061734aSJiaxin Yu 
15958061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
15968061734aSJiaxin Yu 
15978061734aSJiaxin Yu 	switch (event) {
15988061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
15998061734aSJiaxin Yu 		usleep_range(100, 120);
16008061734aSJiaxin Yu 		/* Audio R preamplifier DCC precharge off */
16018061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1,
16028061734aSJiaxin Yu 				   RG_AUDPREAMPRDCPRECHARGE_MASK_SFT,
16038061734aSJiaxin Yu 				   0x0);
16048061734aSJiaxin Yu 		break;
16058061734aSJiaxin Yu 	default:
16068061734aSJiaxin Yu 		break;
16078061734aSJiaxin Yu 	}
16088061734aSJiaxin Yu 
16098061734aSJiaxin Yu 	return 0;
16108061734aSJiaxin Yu }
16118061734aSJiaxin Yu 
mt_adc_3_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)16128061734aSJiaxin Yu static int mt_adc_3_event(struct snd_soc_dapm_widget *w,
16138061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
16148061734aSJiaxin Yu 			  int event)
16158061734aSJiaxin Yu {
16168061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
16178061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
16188061734aSJiaxin Yu 
16198061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
16208061734aSJiaxin Yu 
16218061734aSJiaxin Yu 	switch (event) {
16228061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
16238061734aSJiaxin Yu 		usleep_range(100, 120);
16248061734aSJiaxin Yu 		/* Audio R preamplifier DCC precharge off */
16258061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2,
16268061734aSJiaxin Yu 				   RG_AUDPREAMP3DCPRECHARGE_MASK_SFT,
16278061734aSJiaxin Yu 				   0x0);
16288061734aSJiaxin Yu 		break;
16298061734aSJiaxin Yu 	default:
16308061734aSJiaxin Yu 		break;
16318061734aSJiaxin Yu 	}
16328061734aSJiaxin Yu 
16338061734aSJiaxin Yu 	return 0;
16348061734aSJiaxin Yu }
16358061734aSJiaxin Yu 
mt_pga_l_mux_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)16368061734aSJiaxin Yu static int mt_pga_l_mux_event(struct snd_soc_dapm_widget *w,
16378061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
16388061734aSJiaxin Yu 			      int event)
16398061734aSJiaxin Yu {
16408061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
16418061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
16428061734aSJiaxin Yu 	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
16438061734aSJiaxin Yu 
16448061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux);
16458061734aSJiaxin Yu 	priv->mux_select[MUX_PGA_L] = mux >> RG_AUDPREAMPLINPUTSEL_SFT;
16468061734aSJiaxin Yu 	return 0;
16478061734aSJiaxin Yu }
16488061734aSJiaxin Yu 
mt_pga_r_mux_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)16498061734aSJiaxin Yu static int mt_pga_r_mux_event(struct snd_soc_dapm_widget *w,
16508061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
16518061734aSJiaxin Yu 			      int event)
16528061734aSJiaxin Yu {
16538061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
16548061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
16558061734aSJiaxin Yu 	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
16568061734aSJiaxin Yu 
16578061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux);
16588061734aSJiaxin Yu 	priv->mux_select[MUX_PGA_R] = mux >> RG_AUDPREAMPRINPUTSEL_SFT;
16598061734aSJiaxin Yu 	return 0;
16608061734aSJiaxin Yu }
16618061734aSJiaxin Yu 
mt_pga_3_mux_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)16628061734aSJiaxin Yu static int mt_pga_3_mux_event(struct snd_soc_dapm_widget *w,
16638061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
16648061734aSJiaxin Yu 			      int event)
16658061734aSJiaxin Yu {
16668061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
16678061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
16688061734aSJiaxin Yu 	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
16698061734aSJiaxin Yu 
16708061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), mux %d\n", __func__, mux);
16718061734aSJiaxin Yu 	priv->mux_select[MUX_PGA_3] = mux >> RG_AUDPREAMP3INPUTSEL_SFT;
16728061734aSJiaxin Yu 	return 0;
16738061734aSJiaxin Yu }
16748061734aSJiaxin Yu 
mt_pga_l_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)16758061734aSJiaxin Yu static int mt_pga_l_event(struct snd_soc_dapm_widget *w,
16768061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
16778061734aSJiaxin Yu 			  int event)
16788061734aSJiaxin Yu {
16798061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
16808061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
16818061734aSJiaxin Yu 	int mic_gain_l = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1];
16828061734aSJiaxin Yu 	unsigned int mux_pga = priv->mux_select[MUX_PGA_L];
16838061734aSJiaxin Yu 	unsigned int mic_type;
16848061734aSJiaxin Yu 
16858061734aSJiaxin Yu 	switch (mux_pga) {
16868061734aSJiaxin Yu 	case PGA_L_MUX_AIN0:
16878061734aSJiaxin Yu 		mic_type = priv->mux_select[MUX_MIC_TYPE_0];
16888061734aSJiaxin Yu 		break;
16898061734aSJiaxin Yu 	case PGA_L_MUX_AIN1:
16908061734aSJiaxin Yu 		mic_type = priv->mux_select[MUX_MIC_TYPE_1];
16918061734aSJiaxin Yu 		break;
16928061734aSJiaxin Yu 	default:
16938061734aSJiaxin Yu 		dev_err(priv->dev, "%s(), invalid pga mux %d\n",
16948061734aSJiaxin Yu 			__func__, mux_pga);
16958061734aSJiaxin Yu 		return -EINVAL;
16968061734aSJiaxin Yu 	}
16978061734aSJiaxin Yu 
16988061734aSJiaxin Yu 	switch (event) {
16998061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
17008061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
17018061734aSJiaxin Yu 			/* Audio L preamplifier DCC precharge */
17028061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0,
17038061734aSJiaxin Yu 					   RG_AUDPREAMPLDCPRECHARGE_MASK_SFT,
17048061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMPLDCPRECHARGE_SFT);
17058061734aSJiaxin Yu 		}
17068061734aSJiaxin Yu 		break;
17078061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
17088061734aSJiaxin Yu 		/* set mic pga gain */
17098061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0,
17108061734aSJiaxin Yu 				   RG_AUDPREAMPLGAIN_MASK_SFT,
17118061734aSJiaxin Yu 				   mic_gain_l << RG_AUDPREAMPLGAIN_SFT);
17128061734aSJiaxin Yu 
17138061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
17148061734aSJiaxin Yu 			/* L preamplifier DCCEN */
17158061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0,
17168061734aSJiaxin Yu 					   RG_AUDPREAMPLDCCEN_MASK_SFT,
17178061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMPLDCCEN_SFT);
17188061734aSJiaxin Yu 		}
17198061734aSJiaxin Yu 		break;
17208061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
17218061734aSJiaxin Yu 		/* L preamplifier DCCEN */
17228061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON0,
17238061734aSJiaxin Yu 				   RG_AUDPREAMPLDCCEN_MASK_SFT,
17248061734aSJiaxin Yu 				   0x0 << RG_AUDPREAMPLDCCEN_SFT);
17258061734aSJiaxin Yu 		break;
17268061734aSJiaxin Yu 	default:
17278061734aSJiaxin Yu 		break;
17288061734aSJiaxin Yu 	}
17298061734aSJiaxin Yu 
17308061734aSJiaxin Yu 	return 0;
17318061734aSJiaxin Yu }
17328061734aSJiaxin Yu 
mt_pga_r_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)17338061734aSJiaxin Yu static int mt_pga_r_event(struct snd_soc_dapm_widget *w,
17348061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
17358061734aSJiaxin Yu 			  int event)
17368061734aSJiaxin Yu {
17378061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
17388061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
17398061734aSJiaxin Yu 	int mic_gain_r = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2];
17408061734aSJiaxin Yu 	unsigned int mux_pga = priv->mux_select[MUX_PGA_R];
17418061734aSJiaxin Yu 	unsigned int mic_type;
17428061734aSJiaxin Yu 
17438061734aSJiaxin Yu 	switch (mux_pga) {
17448061734aSJiaxin Yu 	case PGA_R_MUX_AIN0:
17458061734aSJiaxin Yu 		mic_type = priv->mux_select[MUX_MIC_TYPE_0];
17468061734aSJiaxin Yu 		break;
17478061734aSJiaxin Yu 	case PGA_R_MUX_AIN2:
17488061734aSJiaxin Yu 	case PGA_R_MUX_AIN3:
17498061734aSJiaxin Yu 		mic_type = priv->mux_select[MUX_MIC_TYPE_2];
17508061734aSJiaxin Yu 		break;
17518061734aSJiaxin Yu 	default:
17528061734aSJiaxin Yu 		dev_err(priv->dev, "%s(), invalid pga mux %d\n",
17538061734aSJiaxin Yu 			__func__, mux_pga);
17548061734aSJiaxin Yu 		return -EINVAL;
17558061734aSJiaxin Yu 	}
17568061734aSJiaxin Yu 
17578061734aSJiaxin Yu 	switch (event) {
17588061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
17598061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
17608061734aSJiaxin Yu 			/* Audio R preamplifier DCC precharge */
17618061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1,
17628061734aSJiaxin Yu 					   RG_AUDPREAMPRDCPRECHARGE_MASK_SFT,
17638061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMPRDCPRECHARGE_SFT);
17648061734aSJiaxin Yu 		}
17658061734aSJiaxin Yu 		break;
17668061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
17678061734aSJiaxin Yu 		/* set mic pga gain */
17688061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1,
17698061734aSJiaxin Yu 				   RG_AUDPREAMPRGAIN_MASK_SFT,
17708061734aSJiaxin Yu 				   mic_gain_r << RG_AUDPREAMPRGAIN_SFT);
17718061734aSJiaxin Yu 
17728061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
17738061734aSJiaxin Yu 			/* R preamplifier DCCEN */
17748061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1,
17758061734aSJiaxin Yu 					   RG_AUDPREAMPRDCCEN_MASK_SFT,
17768061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMPRDCCEN_SFT);
17778061734aSJiaxin Yu 		}
17788061734aSJiaxin Yu 		break;
17798061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
17808061734aSJiaxin Yu 		/* R preamplifier DCCEN */
17818061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON1,
17828061734aSJiaxin Yu 				   RG_AUDPREAMPRDCCEN_MASK_SFT,
17838061734aSJiaxin Yu 				   0x0 << RG_AUDPREAMPRDCCEN_SFT);
17848061734aSJiaxin Yu 		break;
17858061734aSJiaxin Yu 	default:
17868061734aSJiaxin Yu 		break;
17878061734aSJiaxin Yu 	}
17888061734aSJiaxin Yu 
17898061734aSJiaxin Yu 	return 0;
17908061734aSJiaxin Yu }
17918061734aSJiaxin Yu 
mt_pga_3_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)17928061734aSJiaxin Yu static int mt_pga_3_event(struct snd_soc_dapm_widget *w,
17938061734aSJiaxin Yu 			  struct snd_kcontrol *kcontrol,
17948061734aSJiaxin Yu 			  int event)
17958061734aSJiaxin Yu {
17968061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
17978061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
17988061734aSJiaxin Yu 	int mic_gain_3 = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3];
17998061734aSJiaxin Yu 	unsigned int mux_pga = priv->mux_select[MUX_PGA_3];
18008061734aSJiaxin Yu 	unsigned int mic_type;
18018061734aSJiaxin Yu 
18028061734aSJiaxin Yu 	switch (mux_pga) {
18038061734aSJiaxin Yu 	case PGA_3_MUX_AIN2:
18048061734aSJiaxin Yu 	case PGA_3_MUX_AIN3:
18058061734aSJiaxin Yu 		mic_type = priv->mux_select[MUX_MIC_TYPE_2];
18068061734aSJiaxin Yu 		break;
18078061734aSJiaxin Yu 	default:
18088061734aSJiaxin Yu 		dev_err(priv->dev, "%s(), invalid pga mux %d\n",
18098061734aSJiaxin Yu 			__func__, mux_pga);
18108061734aSJiaxin Yu 		return -EINVAL;
18118061734aSJiaxin Yu 	}
18128061734aSJiaxin Yu 
18138061734aSJiaxin Yu 	switch (event) {
18148061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
18158061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
18168061734aSJiaxin Yu 			/* Audio 3 preamplifier DCC precharge */
18178061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2,
18188061734aSJiaxin Yu 					   RG_AUDPREAMP3DCPRECHARGE_MASK_SFT,
18198061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMP3DCPRECHARGE_SFT);
18208061734aSJiaxin Yu 		}
18218061734aSJiaxin Yu 		break;
18228061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
18238061734aSJiaxin Yu 		/* set mic pga gain */
18248061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2,
18258061734aSJiaxin Yu 				   RG_AUDPREAMP3GAIN_MASK_SFT,
18268061734aSJiaxin Yu 				   mic_gain_3 << RG_AUDPREAMP3GAIN_SFT);
18278061734aSJiaxin Yu 
18288061734aSJiaxin Yu 		if (IS_DCC_BASE(mic_type)) {
18298061734aSJiaxin Yu 			/* 3 preamplifier DCCEN */
18308061734aSJiaxin Yu 			regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2,
18318061734aSJiaxin Yu 					   RG_AUDPREAMP3DCCEN_MASK_SFT,
18328061734aSJiaxin Yu 					   0x1 << RG_AUDPREAMP3DCCEN_SFT);
18338061734aSJiaxin Yu 		}
18348061734aSJiaxin Yu 		break;
18358061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
18368061734aSJiaxin Yu 		/* 3 preamplifier DCCEN */
18378061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON2,
18388061734aSJiaxin Yu 				   RG_AUDPREAMP3DCCEN_MASK_SFT,
18398061734aSJiaxin Yu 				   0x0 << RG_AUDPREAMP3DCCEN_SFT);
18408061734aSJiaxin Yu 		break;
18418061734aSJiaxin Yu 	default:
18428061734aSJiaxin Yu 		break;
18438061734aSJiaxin Yu 	}
18448061734aSJiaxin Yu 
18458061734aSJiaxin Yu 	return 0;
18468061734aSJiaxin Yu }
18478061734aSJiaxin Yu 
18488061734aSJiaxin Yu /* It is based on hw's control sequenece to add some delay when PMU/PMD */
mt_delay_250_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)18498061734aSJiaxin Yu static int mt_delay_250_event(struct snd_soc_dapm_widget *w,
18508061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
18518061734aSJiaxin Yu 			      int event)
18528061734aSJiaxin Yu {
18538061734aSJiaxin Yu 	switch (event) {
18548061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
18558061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
18568061734aSJiaxin Yu 		usleep_range(250, 270);
18578061734aSJiaxin Yu 		break;
18588061734aSJiaxin Yu 	default:
18598061734aSJiaxin Yu 		break;
18608061734aSJiaxin Yu 	}
18618061734aSJiaxin Yu 
18628061734aSJiaxin Yu 	return 0;
18638061734aSJiaxin Yu }
18648061734aSJiaxin Yu 
mt_delay_100_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)18658061734aSJiaxin Yu static int mt_delay_100_event(struct snd_soc_dapm_widget *w,
18668061734aSJiaxin Yu 			      struct snd_kcontrol *kcontrol,
18678061734aSJiaxin Yu 			      int event)
18688061734aSJiaxin Yu {
18698061734aSJiaxin Yu 	switch (event) {
18708061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMU:
18718061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMD:
18728061734aSJiaxin Yu 		usleep_range(100, 120);
18738061734aSJiaxin Yu 		break;
18748061734aSJiaxin Yu 	default:
18758061734aSJiaxin Yu 		break;
18768061734aSJiaxin Yu 	}
18778061734aSJiaxin Yu 
18788061734aSJiaxin Yu 	return 0;
18798061734aSJiaxin Yu }
18808061734aSJiaxin Yu 
mt_hp_pull_down_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)18818061734aSJiaxin Yu static int mt_hp_pull_down_event(struct snd_soc_dapm_widget *w,
18828061734aSJiaxin Yu 				 struct snd_kcontrol *kcontrol,
18838061734aSJiaxin Yu 				 int event)
18848061734aSJiaxin Yu {
18858061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
18868061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
18878061734aSJiaxin Yu 
18888061734aSJiaxin Yu 	switch (event) {
18898061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
18908061734aSJiaxin Yu 		hp_pull_down(priv, true);
18918061734aSJiaxin Yu 		break;
18928061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
18938061734aSJiaxin Yu 		hp_pull_down(priv, false);
18948061734aSJiaxin Yu 		break;
18958061734aSJiaxin Yu 	default:
18968061734aSJiaxin Yu 		break;
18978061734aSJiaxin Yu 	}
18988061734aSJiaxin Yu 
18998061734aSJiaxin Yu 	return 0;
19008061734aSJiaxin Yu }
19018061734aSJiaxin Yu 
mt_hp_mute_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)19028061734aSJiaxin Yu static int mt_hp_mute_event(struct snd_soc_dapm_widget *w,
19038061734aSJiaxin Yu 			    struct snd_kcontrol *kcontrol,
19048061734aSJiaxin Yu 			    int event)
19058061734aSJiaxin Yu {
19068061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19078061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19088061734aSJiaxin Yu 
19098061734aSJiaxin Yu 	switch (event) {
19108061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
19118061734aSJiaxin Yu 		/* Set HPR/HPL gain to -22dB */
19128061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON2, DL_GAIN_N_22DB_REG);
19138061734aSJiaxin Yu 		break;
19148061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
19158061734aSJiaxin Yu 		/* Set HPL/HPR gain to mute */
19168061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_ZCD_CON2, DL_GAIN_N_40DB_REG);
19178061734aSJiaxin Yu 		break;
19188061734aSJiaxin Yu 	default:
19198061734aSJiaxin Yu 		break;
19208061734aSJiaxin Yu 	}
19218061734aSJiaxin Yu 
19228061734aSJiaxin Yu 	return 0;
19238061734aSJiaxin Yu }
19248061734aSJiaxin Yu 
mt_hp_damp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)19258061734aSJiaxin Yu static int mt_hp_damp_event(struct snd_soc_dapm_widget *w,
19268061734aSJiaxin Yu 			    struct snd_kcontrol *kcontrol,
19278061734aSJiaxin Yu 			    int event)
19288061734aSJiaxin Yu {
19298061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19308061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19318061734aSJiaxin Yu 
19328061734aSJiaxin Yu 	switch (event) {
19338061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
19348061734aSJiaxin Yu 		/* Disable HP damping circuit & HPN 4K load */
19358061734aSJiaxin Yu 		/* reset CMFB PW level */
19368061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AUDDEC_ANA_CON10, 0x0000);
19378061734aSJiaxin Yu 		break;
19388061734aSJiaxin Yu 	default:
19398061734aSJiaxin Yu 		break;
19408061734aSJiaxin Yu 	}
19418061734aSJiaxin Yu 
19428061734aSJiaxin Yu 	return 0;
19438061734aSJiaxin Yu }
19448061734aSJiaxin Yu 
mt_esd_resist_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)19458061734aSJiaxin Yu static int mt_esd_resist_event(struct snd_soc_dapm_widget *w,
19468061734aSJiaxin Yu 			       struct snd_kcontrol *kcontrol,
19478061734aSJiaxin Yu 			       int event)
19488061734aSJiaxin Yu {
19498061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19508061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19518061734aSJiaxin Yu 
19528061734aSJiaxin Yu 	switch (event) {
19538061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
19548061734aSJiaxin Yu 		/* Reduce ESD resistance of AU_REFN */
19558061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2,
19568061734aSJiaxin Yu 				   RG_AUDREFN_DERES_EN_VAUDP32_MASK_SFT,
19578061734aSJiaxin Yu 				   0x1 << RG_AUDREFN_DERES_EN_VAUDP32_SFT);
19588061734aSJiaxin Yu 		usleep_range(250, 270);
19598061734aSJiaxin Yu 		break;
19608061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
19618061734aSJiaxin Yu 		/* Increase ESD resistance of AU_REFN */
19628061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON2,
19638061734aSJiaxin Yu 				   RG_AUDREFN_DERES_EN_VAUDP32_MASK_SFT, 0x0);
19648061734aSJiaxin Yu 		break;
19658061734aSJiaxin Yu 	default:
19668061734aSJiaxin Yu 		break;
19678061734aSJiaxin Yu 	}
19688061734aSJiaxin Yu 
19698061734aSJiaxin Yu 	return 0;
19708061734aSJiaxin Yu }
19718061734aSJiaxin Yu 
mt_sdm_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)19728061734aSJiaxin Yu static int mt_sdm_event(struct snd_soc_dapm_widget *w,
19738061734aSJiaxin Yu 			struct snd_kcontrol *kcontrol,
19748061734aSJiaxin Yu 			int event)
19758061734aSJiaxin Yu {
19768061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19778061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19788061734aSJiaxin Yu 
19798061734aSJiaxin Yu 	switch (event) {
19808061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
19818061734aSJiaxin Yu 		/* sdm audio fifo clock power on */
19828061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2,
19838061734aSJiaxin Yu 				   0xfffd, 0x0006);
19848061734aSJiaxin Yu 		/* scrambler clock on enable */
19858061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba1);
19868061734aSJiaxin Yu 		/* sdm power on */
19878061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2,
19888061734aSJiaxin Yu 				   0xfffd, 0x0003);
19898061734aSJiaxin Yu 		/* sdm fifo enable */
19908061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2,
19918061734aSJiaxin Yu 				   0xfffd, 0x000B);
19928061734aSJiaxin Yu 		break;
19938061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
19948061734aSJiaxin Yu 		/* DL scrambler disabling sequence */
19958061734aSJiaxin Yu 		regmap_update_bits(priv->regmap, MT6359_AFUNC_AUD_CON2,
19968061734aSJiaxin Yu 				   0xfffd, 0x0000);
19978061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON0, 0xcba0);
19988061734aSJiaxin Yu 		break;
19998061734aSJiaxin Yu 	default:
20008061734aSJiaxin Yu 		break;
20018061734aSJiaxin Yu 	}
20028061734aSJiaxin Yu 
20038061734aSJiaxin Yu 	return 0;
20048061734aSJiaxin Yu }
20058061734aSJiaxin Yu 
mt_sdm_3rd_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)20068061734aSJiaxin Yu static int mt_sdm_3rd_event(struct snd_soc_dapm_widget *w,
20078061734aSJiaxin Yu 			    struct snd_kcontrol *kcontrol,
20088061734aSJiaxin Yu 			    int event)
20098061734aSJiaxin Yu {
20108061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
20118061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
20128061734aSJiaxin Yu 
20138061734aSJiaxin Yu 	switch (event) {
20148061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
20158061734aSJiaxin Yu 		/* sdm audio fifo clock power on */
20168061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0006);
20178061734aSJiaxin Yu 		/* scrambler clock on enable */
20188061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON9, 0xcba1);
20198061734aSJiaxin Yu 		/* sdm power on */
20208061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0003);
20218061734aSJiaxin Yu 		/* sdm fifo enable */
20228061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x000b);
20238061734aSJiaxin Yu 		break;
20248061734aSJiaxin Yu 	case SND_SOC_DAPM_POST_PMD:
20258061734aSJiaxin Yu 		/* DL scrambler disabling sequence */
20268061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON11, 0x0000);
20278061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFUNC_AUD_CON9, 0xcba0);
20288061734aSJiaxin Yu 		break;
20298061734aSJiaxin Yu 	default:
20308061734aSJiaxin Yu 		break;
20318061734aSJiaxin Yu 	}
20328061734aSJiaxin Yu 
20338061734aSJiaxin Yu 	return 0;
20348061734aSJiaxin Yu }
20358061734aSJiaxin Yu 
mt_ncp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)20368061734aSJiaxin Yu static int mt_ncp_event(struct snd_soc_dapm_widget *w,
20378061734aSJiaxin Yu 			struct snd_kcontrol *kcontrol,
20388061734aSJiaxin Yu 			int event)
20398061734aSJiaxin Yu {
20408061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
20418061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
20428061734aSJiaxin Yu 
20438061734aSJiaxin Yu 	switch (event) {
20448061734aSJiaxin Yu 	case SND_SOC_DAPM_PRE_PMU:
20458061734aSJiaxin Yu 		regmap_write(priv->regmap, MT6359_AFE_NCP_CFG0, 0xc800);
20468061734aSJiaxin Yu 		break;
20478061734aSJiaxin Yu 	default:
20488061734aSJiaxin Yu 		break;
20498061734aSJiaxin Yu 	}
20508061734aSJiaxin Yu 
20518061734aSJiaxin Yu 	return 0;
20528061734aSJiaxin Yu }
20538061734aSJiaxin Yu 
20548061734aSJiaxin Yu /* DAPM Widgets */
20558061734aSJiaxin Yu static const struct snd_soc_dapm_widget mt6359_dapm_widgets[] = {
20568061734aSJiaxin Yu 	/* Global Supply*/
20578061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("CLK_BUF", SUPPLY_SEQ_CLK_BUF,
20588061734aSJiaxin Yu 			      MT6359_DCXO_CW12,
20598061734aSJiaxin Yu 			      RG_XO_AUDIO_EN_M_SFT, 0, NULL, 0),
20608061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDGLB", SUPPLY_SEQ_AUD_GLB,
20618061734aSJiaxin Yu 			      MT6359_AUDDEC_ANA_CON13,
20628061734aSJiaxin Yu 			      RG_AUDGLB_PWRDN_VA32_SFT, 1, NULL, 0),
20638061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("CLKSQ Audio", SUPPLY_SEQ_CLKSQ,
20648061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON23,
20658061734aSJiaxin Yu 			      RG_CLKSQ_EN_SFT, 0, NULL, SND_SOC_DAPM_PRE_PMU),
20668061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDNCP_CK", SUPPLY_SEQ_TOP_CK,
20678061734aSJiaxin Yu 			      MT6359_AUD_TOP_CKPDN_CON0,
20688061734aSJiaxin Yu 			      RG_AUDNCP_CK_PDN_SFT, 1, NULL, 0),
20698061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ZCD13M_CK", SUPPLY_SEQ_TOP_CK,
20708061734aSJiaxin Yu 			      MT6359_AUD_TOP_CKPDN_CON0,
20718061734aSJiaxin Yu 			      RG_ZCD13M_CK_PDN_SFT, 1, NULL, 0),
20728061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUD_CK", SUPPLY_SEQ_TOP_CK_LAST,
20738061734aSJiaxin Yu 			      MT6359_AUD_TOP_CKPDN_CON0,
20748061734aSJiaxin Yu 			      RG_AUD_CK_PDN_SFT, 1, mt_delay_250_event,
20758061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
20768061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIF_CK", SUPPLY_SEQ_TOP_CK,
20778061734aSJiaxin Yu 			      MT6359_AUD_TOP_CKPDN_CON0,
20788061734aSJiaxin Yu 			      RG_AUDIF_CK_PDN_SFT, 1, NULL, 0),
20799546c76cSJiaxin Yu 	SND_SOC_DAPM_REGULATOR_SUPPLY("vaud18", 0, 0),
20809546c76cSJiaxin Yu 
20818061734aSJiaxin Yu 	/* Digital Clock */
20828061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_AFE_CTL", SUPPLY_SEQ_AUD_TOP_LAST,
20838061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
20848061734aSJiaxin Yu 			      PDN_AFE_CTL_SFT, 1,
20858061734aSJiaxin Yu 			      mt_delay_250_event,
20868061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
20878061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_DAC_CTL", SUPPLY_SEQ_AUD_TOP,
20888061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
20898061734aSJiaxin Yu 			      PDN_DAC_CTL_SFT, 1, NULL, 0),
20908061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_ADC_CTL", SUPPLY_SEQ_AUD_TOP,
20918061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
20928061734aSJiaxin Yu 			      PDN_ADC_CTL_SFT, 1, NULL, 0),
20938061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_ADDA6_ADC_CTL", SUPPLY_SEQ_AUD_TOP,
20948061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
20958061734aSJiaxin Yu 			      PDN_ADDA6_ADC_CTL_SFT, 1, NULL, 0),
20968061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_I2S_DL", SUPPLY_SEQ_AUD_TOP,
20978061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
20988061734aSJiaxin Yu 			      PDN_I2S_DL_CTL_SFT, 1, NULL, 0),
20998061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PWR_CLK", SUPPLY_SEQ_AUD_TOP,
21008061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
21018061734aSJiaxin Yu 			      PWR_CLK_DIS_CTL_SFT, 1, NULL, 0),
21028061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_AFE_TESTMODEL", SUPPLY_SEQ_AUD_TOP,
21038061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
21048061734aSJiaxin Yu 			      PDN_AFE_TESTMODEL_CTL_SFT, 1, NULL, 0),
21058061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_RESERVED", SUPPLY_SEQ_AUD_TOP,
21068061734aSJiaxin Yu 			      MT6359_AUDIO_TOP_CON0,
21078061734aSJiaxin Yu 			      PDN_RESERVED_SFT, 1, NULL, 0),
21088061734aSJiaxin Yu 
21098061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("SDM", SUPPLY_SEQ_DL_SDM,
21108061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
21118061734aSJiaxin Yu 			      mt_sdm_event,
21128061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21138061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("SDM_3RD", SUPPLY_SEQ_DL_SDM,
21148061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
21158061734aSJiaxin Yu 			      mt_sdm_3rd_event,
21168061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21178061734aSJiaxin Yu 
21188061734aSJiaxin Yu 	/* ch123 share SDM FIFO CLK */
21198061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("SDM_FIFO_CLK", SUPPLY_SEQ_DL_SDM_FIFO_CLK,
21208061734aSJiaxin Yu 			      MT6359_AFUNC_AUD_CON2,
21218061734aSJiaxin Yu 			      CCI_AFIFO_CLK_PWDB_SFT, 0,
21228061734aSJiaxin Yu 			      NULL, 0),
21238061734aSJiaxin Yu 
21248061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("NCP", SUPPLY_SEQ_DL_NCP,
21258061734aSJiaxin Yu 			      MT6359_AFE_NCP_CFG0,
21268061734aSJiaxin Yu 			      RG_NCP_ON_SFT, 0,
21278061734aSJiaxin Yu 			      mt_ncp_event,
21288061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU),
21298061734aSJiaxin Yu 
21308061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM,
21318061734aSJiaxin Yu 			    0, 0, NULL, 0),
21328061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("DL Digital Clock CH_1_2", SND_SOC_NOPM,
21338061734aSJiaxin Yu 			    0, 0, NULL, 0),
21348061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("DL Digital Clock CH_3", SND_SOC_NOPM,
21358061734aSJiaxin Yu 			    0, 0, NULL, 0),
21368061734aSJiaxin Yu 
21378061734aSJiaxin Yu 	/* AFE ON */
21388061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AFE_ON", SUPPLY_SEQ_AFE,
21398061734aSJiaxin Yu 			      MT6359_AFE_UL_DL_CON0, AFE_ON_SFT, 0,
21408061734aSJiaxin Yu 			      NULL, 0),
21418061734aSJiaxin Yu 
21428061734aSJiaxin Yu 	/* AIF Rx*/
21438061734aSJiaxin Yu 	SND_SOC_DAPM_AIF_IN("AIF_RX", "AIF1 Playback", 0,
21448061734aSJiaxin Yu 			    SND_SOC_NOPM, 0, 0),
21458061734aSJiaxin Yu 
21468061734aSJiaxin Yu 	SND_SOC_DAPM_AIF_IN("AIF2_RX", "AIF2 Playback", 0,
21478061734aSJiaxin Yu 			    SND_SOC_NOPM, 0, 0),
21488061734aSJiaxin Yu 
21498061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("AFE_DL_SRC", SUPPLY_SEQ_DL_SRC,
21508061734aSJiaxin Yu 			      MT6359_AFE_DL_SRC2_CON0_L,
21518061734aSJiaxin Yu 			      DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0,
21528061734aSJiaxin Yu 			      NULL, 0),
21538061734aSJiaxin Yu 
21548061734aSJiaxin Yu 	/* DL Supply */
21558061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM,
21568061734aSJiaxin Yu 			    0, 0, NULL, 0),
21578061734aSJiaxin Yu 
21588061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ESD_RESIST", SUPPLY_SEQ_DL_ESD_RESIST,
21598061734aSJiaxin Yu 			      SND_SOC_NOPM,
21608061734aSJiaxin Yu 			      0, 0,
21618061734aSJiaxin Yu 			      mt_esd_resist_event,
21628061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21638061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("LDO", SUPPLY_SEQ_DL_LDO,
21648061734aSJiaxin Yu 			      MT6359_AUDDEC_ANA_CON14,
21658061734aSJiaxin Yu 			      RG_LCLDO_DEC_EN_VA32_SFT, 0,
21668061734aSJiaxin Yu 			      NULL, 0),
21678061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("LDO_REMOTE", SUPPLY_SEQ_DL_LDO_REMOTE_SENSE,
21688061734aSJiaxin Yu 			      MT6359_AUDDEC_ANA_CON14,
21698061734aSJiaxin Yu 			      RG_LCLDO_DEC_REMOTE_SENSE_VA18_SFT, 0,
21708061734aSJiaxin Yu 			      NULL, 0),
21718061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("NV_REGULATOR", SUPPLY_SEQ_DL_NV,
21728061734aSJiaxin Yu 			      MT6359_AUDDEC_ANA_CON14,
21738061734aSJiaxin Yu 			      RG_NVREG_EN_VAUDP32_SFT, 0,
21748061734aSJiaxin Yu 			      mt_delay_100_event, SND_SOC_DAPM_POST_PMU),
21758061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("IBIST", SUPPLY_SEQ_DL_IBIST,
21768061734aSJiaxin Yu 			      MT6359_AUDDEC_ANA_CON12,
21778061734aSJiaxin Yu 			      RG_AUDIBIASPWRDN_VAUDP32_SFT, 1,
21788061734aSJiaxin Yu 			      NULL, 0),
21798061734aSJiaxin Yu 
21808061734aSJiaxin Yu 	/* DAC */
21818061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM, 0, 0, &dac_in_mux_control),
21828061734aSJiaxin Yu 
21838061734aSJiaxin Yu 	SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
21848061734aSJiaxin Yu 
21858061734aSJiaxin Yu 	SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
21868061734aSJiaxin Yu 
21878061734aSJiaxin Yu 	SND_SOC_DAPM_DAC("DAC_3RD", NULL, SND_SOC_NOPM, 0, 0),
21888061734aSJiaxin Yu 
21898061734aSJiaxin Yu 	/* Headphone */
21908061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("HP Mux", SND_SOC_NOPM, 0, 0,
21918061734aSJiaxin Yu 			   &hp_in_mux_control,
21928061734aSJiaxin Yu 			   mt_hp_event,
21938061734aSJiaxin Yu 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
21948061734aSJiaxin Yu 
21958061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("HP_Supply", SND_SOC_NOPM,
21968061734aSJiaxin Yu 			    0, 0, NULL, 0),
21978061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("HP_PULL_DOWN", SUPPLY_SEQ_HP_PULL_DOWN,
21988061734aSJiaxin Yu 			      SND_SOC_NOPM,
21998061734aSJiaxin Yu 			      0, 0,
22008061734aSJiaxin Yu 			      mt_hp_pull_down_event,
22018061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22028061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("HP_MUTE", SUPPLY_SEQ_HP_MUTE,
22038061734aSJiaxin Yu 			      SND_SOC_NOPM,
22048061734aSJiaxin Yu 			      0, 0,
22058061734aSJiaxin Yu 			      mt_hp_mute_event,
22068061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22078061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("HP_DAMP", SUPPLY_SEQ_HP_DAMPING_OFF_RESET_CMFB,
22088061734aSJiaxin Yu 			      SND_SOC_NOPM,
22098061734aSJiaxin Yu 			      0, 0,
22108061734aSJiaxin Yu 			      mt_hp_damp_event,
22118061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMD),
22128061734aSJiaxin Yu 
22138061734aSJiaxin Yu 	/* Receiver */
22148061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("RCV Mux", SND_SOC_NOPM, 0, 0,
22158061734aSJiaxin Yu 			   &rcv_in_mux_control,
22168061734aSJiaxin Yu 			   mt_rcv_event,
22178061734aSJiaxin Yu 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
22188061734aSJiaxin Yu 
22198061734aSJiaxin Yu 	/* LOL */
22208061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("LOL Mux", SND_SOC_NOPM, 0, 0,
22218061734aSJiaxin Yu 			   &lo_in_mux_control,
22228061734aSJiaxin Yu 			   mt_lo_event,
22238061734aSJiaxin Yu 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
22248061734aSJiaxin Yu 
22258061734aSJiaxin Yu 	/* Outputs */
22268061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("Receiver"),
22278061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("Headphone L"),
22288061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("Headphone R"),
22298061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("Headphone L Ext Spk Amp"),
22308061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("Headphone R Ext Spk Amp"),
22318061734aSJiaxin Yu 	SND_SOC_DAPM_OUTPUT("LINEOUT L"),
22328061734aSJiaxin Yu 
22338061734aSJiaxin Yu 	/* SGEN */
22348061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6359_AFE_SGEN_CFG0,
22358061734aSJiaxin Yu 			    SGEN_DAC_EN_CTL_SFT, 0, NULL, 0),
22368061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6359_AFE_SGEN_CFG0,
22378061734aSJiaxin Yu 			    SGEN_MUTE_SW_CTL_SFT, 1,
22388061734aSJiaxin Yu 			    mt_sgen_event,
22398061734aSJiaxin Yu 			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22408061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6359_AFE_DL_SRC2_CON0_L,
22418061734aSJiaxin Yu 			    DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, NULL, 0),
22428061734aSJiaxin Yu 
22438061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("SGEN DL"),
22448061734aSJiaxin Yu 
22458061734aSJiaxin Yu 	/* Uplinks */
22468061734aSJiaxin Yu 	SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0,
22478061734aSJiaxin Yu 			     SND_SOC_NOPM, 0, 0),
22488061734aSJiaxin Yu 	SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0,
22498061734aSJiaxin Yu 			     SND_SOC_NOPM, 0, 0),
22508061734aSJiaxin Yu 
22518061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ADC_CLKGEN", SUPPLY_SEQ_ADC_CLKGEN,
22528061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
22538061734aSJiaxin Yu 			      mt_adc_clk_gen_event,
22548061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
22558061734aSJiaxin Yu 
22568061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("DCC_CLK", SUPPLY_SEQ_DCC_CLK,
22578061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
22588061734aSJiaxin Yu 			      mt_dcc_clk_event,
22598061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22608061734aSJiaxin Yu 
22618061734aSJiaxin Yu 	/* Uplinks MUX */
22628061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM, 0, 0,
22638061734aSJiaxin Yu 			 &aif_out_mux_control),
22648061734aSJiaxin Yu 
22658061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("AIF2 Out Mux", SND_SOC_NOPM, 0, 0,
22668061734aSJiaxin Yu 			 &aif2_out_mux_control),
22678061734aSJiaxin Yu 
22688061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY("AIFTX_Supply", SND_SOC_NOPM, 0, 0, NULL, 0),
22698061734aSJiaxin Yu 
22708061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("MTKAIF_TX", SUPPLY_SEQ_UL_MTKAIF,
22718061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
22728061734aSJiaxin Yu 			      mt_mtkaif_tx_event,
22738061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22748061734aSJiaxin Yu 
22758061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("UL_SRC", SUPPLY_SEQ_UL_SRC,
22768061734aSJiaxin Yu 			      MT6359_AFE_UL_SRC_CON0_L,
22778061734aSJiaxin Yu 			      UL_SRC_ON_TMP_CTL_SFT, 0,
22788061734aSJiaxin Yu 			      NULL, 0),
22798061734aSJiaxin Yu 
22808061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("UL_SRC_DMIC", SUPPLY_SEQ_UL_SRC_DMIC,
22818061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
22828061734aSJiaxin Yu 			      mt_ul_src_dmic_event,
22838061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22848061734aSJiaxin Yu 
22858061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("UL_SRC_34", SUPPLY_SEQ_UL_SRC,
22868061734aSJiaxin Yu 			      MT6359_AFE_ADDA6_UL_SRC_CON0_L,
22878061734aSJiaxin Yu 			      ADDA6_UL_SRC_ON_TMP_CTL_SFT, 0,
22888061734aSJiaxin Yu 			      NULL, 0),
22898061734aSJiaxin Yu 
22908061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("UL_SRC_34_DMIC", SUPPLY_SEQ_UL_SRC_DMIC,
22918061734aSJiaxin Yu 			      SND_SOC_NOPM, 0, 0,
22928061734aSJiaxin Yu 			      mt_ul_src_34_dmic_event,
22938061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
22948061734aSJiaxin Yu 
22958061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("MISO0_MUX", SND_SOC_NOPM, 0, 0, &miso0_mux_control),
22968061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("MISO1_MUX", SND_SOC_NOPM, 0, 0, &miso1_mux_control),
22978061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("MISO2_MUX", SND_SOC_NOPM, 0, 0, &miso2_mux_control),
22988061734aSJiaxin Yu 
22998061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("UL_SRC_MUX", SND_SOC_NOPM, 0, 0,
23008061734aSJiaxin Yu 			 &ul_src_mux_control),
23018061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("UL2_SRC_MUX", SND_SOC_NOPM, 0, 0,
23028061734aSJiaxin Yu 			 &ul2_src_mux_control),
23038061734aSJiaxin Yu 
23048061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("DMIC0_MUX", SND_SOC_NOPM, 0, 0, &dmic0_mux_control),
23058061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("DMIC1_MUX", SND_SOC_NOPM, 0, 0, &dmic1_mux_control),
23068061734aSJiaxin Yu 	SND_SOC_DAPM_MUX("DMIC2_MUX", SND_SOC_NOPM, 0, 0, &dmic2_mux_control),
23078061734aSJiaxin Yu 
23088061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("ADC_L_Mux", SND_SOC_NOPM, 0, 0,
23098061734aSJiaxin Yu 			   &adc_left_mux_control, NULL, 0),
23108061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("ADC_R_Mux", SND_SOC_NOPM, 0, 0,
23118061734aSJiaxin Yu 			   &adc_right_mux_control, NULL, 0),
23128061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("ADC_3_Mux", SND_SOC_NOPM, 0, 0,
23138061734aSJiaxin Yu 			   &adc_3_mux_control, NULL, 0),
23148061734aSJiaxin Yu 
23158061734aSJiaxin Yu 	SND_SOC_DAPM_ADC("ADC_L", NULL, SND_SOC_NOPM, 0, 0),
23168061734aSJiaxin Yu 	SND_SOC_DAPM_ADC("ADC_R", NULL, SND_SOC_NOPM, 0, 0),
23178061734aSJiaxin Yu 	SND_SOC_DAPM_ADC("ADC_3", NULL, SND_SOC_NOPM, 0, 0),
23188061734aSJiaxin Yu 
23198061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ADC_L_EN", SUPPLY_SEQ_UL_ADC,
23208061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON0,
23218061734aSJiaxin Yu 			      RG_AUDADCLPWRUP_SFT, 0,
23228061734aSJiaxin Yu 			      mt_adc_l_event,
23238061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU),
23248061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ADC_R_EN", SUPPLY_SEQ_UL_ADC,
23258061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON1,
23268061734aSJiaxin Yu 			      RG_AUDADCRPWRUP_SFT, 0,
23278061734aSJiaxin Yu 			      mt_adc_r_event,
23288061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU),
23298061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("ADC_3_EN", SUPPLY_SEQ_UL_ADC,
23308061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON2,
23318061734aSJiaxin Yu 			      RG_AUDADC3PWRUP_SFT, 0,
23328061734aSJiaxin Yu 			      mt_adc_3_event,
23338061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU),
23348061734aSJiaxin Yu 
23358061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("PGA_L_Mux", SND_SOC_NOPM, 0, 0,
23368061734aSJiaxin Yu 			   &pga_left_mux_control,
23378061734aSJiaxin Yu 			   mt_pga_l_mux_event,
23388061734aSJiaxin Yu 			   SND_SOC_DAPM_WILL_PMU),
23398061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("PGA_R_Mux", SND_SOC_NOPM, 0, 0,
23408061734aSJiaxin Yu 			   &pga_right_mux_control,
23418061734aSJiaxin Yu 			   mt_pga_r_mux_event,
23428061734aSJiaxin Yu 			   SND_SOC_DAPM_WILL_PMU),
23438061734aSJiaxin Yu 	SND_SOC_DAPM_MUX_E("PGA_3_Mux", SND_SOC_NOPM, 0, 0,
23448061734aSJiaxin Yu 			   &pga_3_mux_control,
23458061734aSJiaxin Yu 			   mt_pga_3_mux_event,
23468061734aSJiaxin Yu 			   SND_SOC_DAPM_WILL_PMU),
23478061734aSJiaxin Yu 
23488061734aSJiaxin Yu 	SND_SOC_DAPM_PGA("PGA_L", SND_SOC_NOPM, 0, 0, NULL, 0),
23498061734aSJiaxin Yu 	SND_SOC_DAPM_PGA("PGA_R", SND_SOC_NOPM, 0, 0, NULL, 0),
23508061734aSJiaxin Yu 	SND_SOC_DAPM_PGA("PGA_3", SND_SOC_NOPM, 0, 0, NULL, 0),
23518061734aSJiaxin Yu 
23528061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("PGA_L_EN", SUPPLY_SEQ_UL_PGA,
23538061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON0,
23548061734aSJiaxin Yu 			      RG_AUDPREAMPLON_SFT, 0,
23558061734aSJiaxin Yu 			      mt_pga_l_event,
23568061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU |
23578061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU |
23588061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMD),
23598061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("PGA_R_EN", SUPPLY_SEQ_UL_PGA,
23608061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON1,
23618061734aSJiaxin Yu 			      RG_AUDPREAMPRON_SFT, 0,
23628061734aSJiaxin Yu 			      mt_pga_r_event,
23638061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU |
23648061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU |
23658061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMD),
23668061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("PGA_3_EN", SUPPLY_SEQ_UL_PGA,
23678061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON2,
23688061734aSJiaxin Yu 			      RG_AUDPREAMP3ON_SFT, 0,
23698061734aSJiaxin Yu 			      mt_pga_3_event,
23708061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU |
23718061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMU |
23728061734aSJiaxin Yu 			      SND_SOC_DAPM_POST_PMD),
23738061734aSJiaxin Yu 
23748061734aSJiaxin Yu 	/* UL input */
23758061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN0"),
23768061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN1"),
23778061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN2"),
23788061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN3"),
23798061734aSJiaxin Yu 
23808061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN0_DMIC"),
23818061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN2_DMIC"),
23828061734aSJiaxin Yu 	SND_SOC_DAPM_INPUT("AIN3_DMIC"),
23838061734aSJiaxin Yu 
23848061734aSJiaxin Yu 	/* mic bias */
23858061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("MIC_BIAS_0", SUPPLY_SEQ_MIC_BIAS,
23868061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON15,
23878061734aSJiaxin Yu 			      RG_AUDPWDBMICBIAS0_SFT, 0,
23888061734aSJiaxin Yu 			      mt_mic_bias_0_event,
23898061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
23908061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("MIC_BIAS_1", SUPPLY_SEQ_MIC_BIAS,
23918061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON16,
23928061734aSJiaxin Yu 			      RG_AUDPWDBMICBIAS1_SFT, 0,
23938061734aSJiaxin Yu 			      mt_mic_bias_1_event,
23948061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU),
23958061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("MIC_BIAS_2", SUPPLY_SEQ_MIC_BIAS,
23968061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON17,
23978061734aSJiaxin Yu 			      RG_AUDPWDBMICBIAS2_SFT, 0,
23988061734aSJiaxin Yu 			      mt_mic_bias_2_event,
23998061734aSJiaxin Yu 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
24008061734aSJiaxin Yu 
24018061734aSJiaxin Yu 	/* dmic */
24028061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("DMIC_0", SUPPLY_SEQ_DMIC,
24038061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON13,
24048061734aSJiaxin Yu 			      RG_AUDDIGMICEN_SFT, 0,
24058061734aSJiaxin Yu 			      NULL, 0),
24068061734aSJiaxin Yu 	SND_SOC_DAPM_SUPPLY_S("DMIC_1", SUPPLY_SEQ_DMIC,
24078061734aSJiaxin Yu 			      MT6359_AUDENC_ANA_CON14,
24088061734aSJiaxin Yu 			      RG_AUDDIGMIC1EN_SFT, 0,
24098061734aSJiaxin Yu 			      NULL, 0),
24108061734aSJiaxin Yu };
24118061734aSJiaxin Yu 
mt_dcc_clk_connect(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)24128061734aSJiaxin Yu static int mt_dcc_clk_connect(struct snd_soc_dapm_widget *source,
24138061734aSJiaxin Yu 			      struct snd_soc_dapm_widget *sink)
24148061734aSJiaxin Yu {
24158061734aSJiaxin Yu 	struct snd_soc_dapm_widget *w = sink;
24168061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
24178061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
24188061734aSJiaxin Yu 
24198061734aSJiaxin Yu 	if (IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_0]) ||
24208061734aSJiaxin Yu 	    IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_1]) ||
24218061734aSJiaxin Yu 	    IS_DCC_BASE(priv->mux_select[MUX_MIC_TYPE_2]))
24228061734aSJiaxin Yu 		return 1;
24238061734aSJiaxin Yu 	else
24248061734aSJiaxin Yu 		return 0;
24258061734aSJiaxin Yu }
24268061734aSJiaxin Yu 
24278061734aSJiaxin Yu static const struct snd_soc_dapm_route mt6359_dapm_routes[] = {
24288061734aSJiaxin Yu 	/* Capture */
24298061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "CLK_BUF"},
24309546c76cSJiaxin Yu 	{"AIFTX_Supply", NULL, "vaud18"},
24318061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDGLB"},
24328061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "CLKSQ Audio"},
24338061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUD_CK"},
24348061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIF_CK"},
24358061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_AFE_CTL"},
24368061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_PWR_CLK"},
24378061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_PDN_RESERVED"},
24388061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_I2S_DL"},
24398061734aSJiaxin Yu 	/*
24408061734aSJiaxin Yu 	 * *_ADC_CTL should enable only if UL_SRC in use,
24418061734aSJiaxin Yu 	 * but dm ck may be needed even UL_SRC_x not in use
24428061734aSJiaxin Yu 	 */
24438061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_ADC_CTL"},
24448061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AUDIO_TOP_ADDA6_ADC_CTL"},
24458061734aSJiaxin Yu 	{"AIFTX_Supply", NULL, "AFE_ON"},
24468061734aSJiaxin Yu 
24478061734aSJiaxin Yu 	/* ul ch 12 */
24488061734aSJiaxin Yu 	{"AIF1TX", NULL, "AIF Out Mux"},
24498061734aSJiaxin Yu 	{"AIF1TX", NULL, "AIFTX_Supply"},
24508061734aSJiaxin Yu 	{"AIF1TX", NULL, "MTKAIF_TX"},
24518061734aSJiaxin Yu 
24528061734aSJiaxin Yu 	{"AIF2TX", NULL, "AIF2 Out Mux"},
24538061734aSJiaxin Yu 	{"AIF2TX", NULL, "AIFTX_Supply"},
24548061734aSJiaxin Yu 	{"AIF2TX", NULL, "MTKAIF_TX"},
24558061734aSJiaxin Yu 
24568061734aSJiaxin Yu 	{"AIF Out Mux", "Normal Path", "MISO0_MUX"},
24578061734aSJiaxin Yu 	{"AIF Out Mux", "Normal Path", "MISO1_MUX"},
24588061734aSJiaxin Yu 	{"AIF2 Out Mux", "Normal Path", "MISO2_MUX"},
24598061734aSJiaxin Yu 
24608061734aSJiaxin Yu 	{"MISO0_MUX", "UL1_CH1", "UL_SRC_MUX"},
24618061734aSJiaxin Yu 	{"MISO0_MUX", "UL1_CH2", "UL_SRC_MUX"},
24628061734aSJiaxin Yu 	{"MISO0_MUX", "UL2_CH1", "UL2_SRC_MUX"},
24638061734aSJiaxin Yu 	{"MISO0_MUX", "UL2_CH2", "UL2_SRC_MUX"},
24648061734aSJiaxin Yu 
24658061734aSJiaxin Yu 	{"MISO1_MUX", "UL1_CH1", "UL_SRC_MUX"},
24668061734aSJiaxin Yu 	{"MISO1_MUX", "UL1_CH2", "UL_SRC_MUX"},
24678061734aSJiaxin Yu 	{"MISO1_MUX", "UL2_CH1", "UL2_SRC_MUX"},
24688061734aSJiaxin Yu 	{"MISO1_MUX", "UL2_CH2", "UL2_SRC_MUX"},
24698061734aSJiaxin Yu 
24708061734aSJiaxin Yu 	{"MISO2_MUX", "UL1_CH1", "UL_SRC_MUX"},
24718061734aSJiaxin Yu 	{"MISO2_MUX", "UL1_CH2", "UL_SRC_MUX"},
24728061734aSJiaxin Yu 	{"MISO2_MUX", "UL2_CH1", "UL2_SRC_MUX"},
24738061734aSJiaxin Yu 	{"MISO2_MUX", "UL2_CH2", "UL2_SRC_MUX"},
24748061734aSJiaxin Yu 
24751a3eb4bbSTrevor Wu 	{"MISO0_MUX", NULL, "UL_SRC"},
24761a3eb4bbSTrevor Wu 	{"MISO1_MUX", NULL, "UL_SRC"},
24771a3eb4bbSTrevor Wu 	{"MISO2_MUX", NULL, "UL_SRC_34"},
24781a3eb4bbSTrevor Wu 
24798061734aSJiaxin Yu 	{"UL_SRC_MUX", "AMIC", "ADC_L"},
24808061734aSJiaxin Yu 	{"UL_SRC_MUX", "AMIC", "ADC_R"},
24818061734aSJiaxin Yu 	{"UL_SRC_MUX", "DMIC", "DMIC0_MUX"},
24828061734aSJiaxin Yu 	{"UL_SRC_MUX", "DMIC", "DMIC1_MUX"},
24838061734aSJiaxin Yu 	{"UL_SRC_MUX", NULL, "UL_SRC"},
24848061734aSJiaxin Yu 
24858061734aSJiaxin Yu 	{"UL2_SRC_MUX", "AMIC", "ADC_3"},
24868061734aSJiaxin Yu 	{"UL2_SRC_MUX", "DMIC", "DMIC2_MUX"},
24878061734aSJiaxin Yu 	{"UL2_SRC_MUX", NULL, "UL_SRC_34"},
24888061734aSJiaxin Yu 
24898061734aSJiaxin Yu 	{"DMIC0_MUX", "DMIC_DATA0", "AIN0_DMIC"},
24908061734aSJiaxin Yu 	{"DMIC0_MUX", "DMIC_DATA1_L", "AIN2_DMIC"},
24918061734aSJiaxin Yu 	{"DMIC0_MUX", "DMIC_DATA1_L_1", "AIN2_DMIC"},
24928061734aSJiaxin Yu 	{"DMIC0_MUX", "DMIC_DATA1_R", "AIN3_DMIC"},
24938061734aSJiaxin Yu 	{"DMIC1_MUX", "DMIC_DATA0", "AIN0_DMIC"},
24948061734aSJiaxin Yu 	{"DMIC1_MUX", "DMIC_DATA1_L", "AIN2_DMIC"},
24958061734aSJiaxin Yu 	{"DMIC1_MUX", "DMIC_DATA1_L_1", "AIN2_DMIC"},
24968061734aSJiaxin Yu 	{"DMIC1_MUX", "DMIC_DATA1_R", "AIN3_DMIC"},
24978061734aSJiaxin Yu 	{"DMIC2_MUX", "DMIC_DATA0", "AIN0_DMIC"},
24988061734aSJiaxin Yu 	{"DMIC2_MUX", "DMIC_DATA1_L", "AIN2_DMIC"},
24998061734aSJiaxin Yu 	{"DMIC2_MUX", "DMIC_DATA1_L_1", "AIN2_DMIC"},
25008061734aSJiaxin Yu 	{"DMIC2_MUX", "DMIC_DATA1_R", "AIN3_DMIC"},
25018061734aSJiaxin Yu 
25028061734aSJiaxin Yu 	{"DMIC0_MUX", NULL, "UL_SRC_DMIC"},
25038061734aSJiaxin Yu 	{"DMIC1_MUX", NULL, "UL_SRC_DMIC"},
25048061734aSJiaxin Yu 	{"DMIC2_MUX", NULL, "UL_SRC_34_DMIC"},
25058061734aSJiaxin Yu 
25068061734aSJiaxin Yu 	{"AIN0_DMIC", NULL, "DMIC_0"},
25078061734aSJiaxin Yu 	{"AIN2_DMIC", NULL, "DMIC_1"},
25088061734aSJiaxin Yu 	{"AIN3_DMIC", NULL, "DMIC_1"},
25098061734aSJiaxin Yu 	{"AIN0_DMIC", NULL, "MIC_BIAS_0"},
25108061734aSJiaxin Yu 	{"AIN2_DMIC", NULL, "MIC_BIAS_2"},
25118061734aSJiaxin Yu 	{"AIN3_DMIC", NULL, "MIC_BIAS_2"},
25128061734aSJiaxin Yu 
25138061734aSJiaxin Yu 	/* adc */
25148061734aSJiaxin Yu 	{"ADC_L", NULL, "ADC_L_Mux"},
25158061734aSJiaxin Yu 	{"ADC_L", NULL, "ADC_CLKGEN"},
25168061734aSJiaxin Yu 	{"ADC_L", NULL, "ADC_L_EN"},
25178061734aSJiaxin Yu 	{"ADC_R", NULL, "ADC_R_Mux"},
25188061734aSJiaxin Yu 	{"ADC_R", NULL, "ADC_CLKGEN"},
25198061734aSJiaxin Yu 	{"ADC_R", NULL, "ADC_R_EN"},
25208061734aSJiaxin Yu 	/*
25218061734aSJiaxin Yu 	 * amic fifo ch1/2 clk from ADC_L,
25228061734aSJiaxin Yu 	 * enable ADC_L even use ADC_R only
25238061734aSJiaxin Yu 	 */
25248061734aSJiaxin Yu 	{"ADC_R", NULL, "ADC_L_EN"},
25258061734aSJiaxin Yu 	{"ADC_3", NULL, "ADC_3_Mux"},
25268061734aSJiaxin Yu 	{"ADC_3", NULL, "ADC_CLKGEN"},
25278061734aSJiaxin Yu 	{"ADC_3", NULL, "ADC_3_EN"},
25288061734aSJiaxin Yu 
25298061734aSJiaxin Yu 	{"ADC_L_Mux", "Left Preamplifier", "PGA_L"},
25308061734aSJiaxin Yu 	{"ADC_R_Mux", "Right Preamplifier", "PGA_R"},
25318061734aSJiaxin Yu 	{"ADC_3_Mux", "Preamplifier", "PGA_3"},
25328061734aSJiaxin Yu 
25338061734aSJiaxin Yu 	{"PGA_L", NULL, "PGA_L_Mux"},
25348061734aSJiaxin Yu 	{"PGA_L", NULL, "PGA_L_EN"},
25358061734aSJiaxin Yu 	{"PGA_R", NULL, "PGA_R_Mux"},
25368061734aSJiaxin Yu 	{"PGA_R", NULL, "PGA_R_EN"},
25378061734aSJiaxin Yu 	{"PGA_3", NULL, "PGA_3_Mux"},
25388061734aSJiaxin Yu 	{"PGA_3", NULL, "PGA_3_EN"},
25398061734aSJiaxin Yu 
25408061734aSJiaxin Yu 	{"PGA_L", NULL, "DCC_CLK", mt_dcc_clk_connect},
25418061734aSJiaxin Yu 	{"PGA_R", NULL, "DCC_CLK", mt_dcc_clk_connect},
25428061734aSJiaxin Yu 	{"PGA_3", NULL, "DCC_CLK", mt_dcc_clk_connect},
25438061734aSJiaxin Yu 
25448061734aSJiaxin Yu 	{"PGA_L_Mux", "AIN0", "AIN0"},
25458061734aSJiaxin Yu 	{"PGA_L_Mux", "AIN1", "AIN1"},
25468061734aSJiaxin Yu 
25478061734aSJiaxin Yu 	{"PGA_R_Mux", "AIN0", "AIN0"},
25488061734aSJiaxin Yu 	{"PGA_R_Mux", "AIN2", "AIN2"},
25498061734aSJiaxin Yu 	{"PGA_R_Mux", "AIN3", "AIN3"},
25508061734aSJiaxin Yu 
25518061734aSJiaxin Yu 	{"PGA_3_Mux", "AIN2", "AIN2"},
25528061734aSJiaxin Yu 	{"PGA_3_Mux", "AIN3", "AIN3"},
25538061734aSJiaxin Yu 
25548061734aSJiaxin Yu 	{"AIN0", NULL, "MIC_BIAS_0"},
25558061734aSJiaxin Yu 	{"AIN1", NULL, "MIC_BIAS_1"},
25568061734aSJiaxin Yu 	{"AIN2", NULL, "MIC_BIAS_0"},
25578061734aSJiaxin Yu 	{"AIN2", NULL, "MIC_BIAS_2"},
25588061734aSJiaxin Yu 	{"AIN3", NULL, "MIC_BIAS_2"},
25598061734aSJiaxin Yu 
25608061734aSJiaxin Yu 	/* DL Supply */
25618061734aSJiaxin Yu 	{"DL Power Supply", NULL, "CLK_BUF"},
25629546c76cSJiaxin Yu 	{"DL Power Supply", NULL, "vaud18"},
25638061734aSJiaxin Yu 	{"DL Power Supply", NULL, "AUDGLB"},
25648061734aSJiaxin Yu 	{"DL Power Supply", NULL, "CLKSQ Audio"},
25658061734aSJiaxin Yu 	{"DL Power Supply", NULL, "AUDNCP_CK"},
25668061734aSJiaxin Yu 	{"DL Power Supply", NULL, "ZCD13M_CK"},
25678061734aSJiaxin Yu 	{"DL Power Supply", NULL, "AUD_CK"},
25688061734aSJiaxin Yu 	{"DL Power Supply", NULL, "AUDIF_CK"},
25698061734aSJiaxin Yu 	{"DL Power Supply", NULL, "ESD_RESIST"},
25708061734aSJiaxin Yu 	{"DL Power Supply", NULL, "LDO"},
25718061734aSJiaxin Yu 	{"DL Power Supply", NULL, "LDO_REMOTE"},
25728061734aSJiaxin Yu 	{"DL Power Supply", NULL, "NV_REGULATOR"},
25738061734aSJiaxin Yu 	{"DL Power Supply", NULL, "IBIST"},
25748061734aSJiaxin Yu 
25758061734aSJiaxin Yu 	/* DL Digital Supply */
25768061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AUDIO_TOP_AFE_CTL"},
25778061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AUDIO_TOP_DAC_CTL"},
25788061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AUDIO_TOP_PWR_CLK"},
25798061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AUDIO_TOP_PDN_RESERVED"},
25808061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "SDM_FIFO_CLK"},
25818061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "NCP"},
25828061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AFE_ON"},
25838061734aSJiaxin Yu 	{"DL Digital Clock", NULL, "AFE_DL_SRC"},
25848061734aSJiaxin Yu 
25858061734aSJiaxin Yu 	{"DL Digital Clock CH_1_2", NULL, "DL Digital Clock"},
25868061734aSJiaxin Yu 	{"DL Digital Clock CH_1_2", NULL, "SDM"},
25878061734aSJiaxin Yu 
25888061734aSJiaxin Yu 	{"DL Digital Clock CH_3", NULL, "DL Digital Clock"},
25898061734aSJiaxin Yu 	{"DL Digital Clock CH_3", NULL, "SDM_3RD"},
25908061734aSJiaxin Yu 
25918061734aSJiaxin Yu 	{"AIF_RX", NULL, "DL Digital Clock CH_1_2"},
25928061734aSJiaxin Yu 
25938061734aSJiaxin Yu 	{"AIF2_RX", NULL, "DL Digital Clock CH_3"},
25948061734aSJiaxin Yu 
25958061734aSJiaxin Yu 	/* DL Path */
25968061734aSJiaxin Yu 	{"DAC In Mux", "Normal Path", "AIF_RX"},
25978061734aSJiaxin Yu 	{"DAC In Mux", "Sgen", "SGEN DL"},
25988061734aSJiaxin Yu 	{"SGEN DL", NULL, "SGEN DL SRC"},
25998061734aSJiaxin Yu 	{"SGEN DL", NULL, "SGEN MUTE"},
26008061734aSJiaxin Yu 	{"SGEN DL", NULL, "SGEN DL Enable"},
26018061734aSJiaxin Yu 	{"SGEN DL", NULL, "DL Digital Clock CH_1_2"},
26028061734aSJiaxin Yu 	{"SGEN DL", NULL, "DL Digital Clock CH_3"},
26038061734aSJiaxin Yu 	{"SGEN DL", NULL, "AUDIO_TOP_PDN_AFE_TESTMODEL"},
26048061734aSJiaxin Yu 
26058061734aSJiaxin Yu 	{"DACL", NULL, "DAC In Mux"},
26068061734aSJiaxin Yu 	{"DACL", NULL, "DL Power Supply"},
26078061734aSJiaxin Yu 
26088061734aSJiaxin Yu 	{"DACR", NULL, "DAC In Mux"},
26098061734aSJiaxin Yu 	{"DACR", NULL, "DL Power Supply"},
26108061734aSJiaxin Yu 
26118061734aSJiaxin Yu 	/* DAC 3RD */
26128061734aSJiaxin Yu 	{"DAC In Mux", "Normal Path", "AIF2_RX"},
26138061734aSJiaxin Yu 	{"DAC_3RD", NULL, "DAC In Mux"},
26148061734aSJiaxin Yu 	{"DAC_3RD", NULL, "DL Power Supply"},
26158061734aSJiaxin Yu 
26168061734aSJiaxin Yu 	/* Lineout Path */
26178061734aSJiaxin Yu 	{"LOL Mux", "Playback", "DAC_3RD"},
2618104ce27bSTrevor Wu 	{"LOL Mux", "Playback_L_DAC", "DACL"},
26198061734aSJiaxin Yu 	{"LINEOUT L", NULL, "LOL Mux"},
26208061734aSJiaxin Yu 
26218061734aSJiaxin Yu 	/* Headphone Path */
26228061734aSJiaxin Yu 	{"HP_Supply", NULL, "HP_PULL_DOWN"},
26238061734aSJiaxin Yu 	{"HP_Supply", NULL, "HP_MUTE"},
26248061734aSJiaxin Yu 	{"HP_Supply", NULL, "HP_DAMP"},
26258061734aSJiaxin Yu 	{"HP Mux", NULL, "HP_Supply"},
26268061734aSJiaxin Yu 
26278061734aSJiaxin Yu 	{"HP Mux", "Audio Playback", "DACL"},
26288061734aSJiaxin Yu 	{"HP Mux", "Audio Playback", "DACR"},
26298061734aSJiaxin Yu 	{"HP Mux", "HP Impedance", "DACL"},
26308061734aSJiaxin Yu 	{"HP Mux", "HP Impedance", "DACR"},
26318061734aSJiaxin Yu 	{"HP Mux", "LoudSPK Playback", "DACL"},
26328061734aSJiaxin Yu 	{"HP Mux", "LoudSPK Playback", "DACR"},
26338061734aSJiaxin Yu 
26348061734aSJiaxin Yu 	{"Headphone L", NULL, "HP Mux"},
26358061734aSJiaxin Yu 	{"Headphone R", NULL, "HP Mux"},
26368061734aSJiaxin Yu 	{"Headphone L Ext Spk Amp", NULL, "HP Mux"},
26378061734aSJiaxin Yu 	{"Headphone R Ext Spk Amp", NULL, "HP Mux"},
26388061734aSJiaxin Yu 
26398061734aSJiaxin Yu 	/* Receiver Path */
26408061734aSJiaxin Yu 	{"RCV Mux", "Voice Playback", "DACL"},
26418061734aSJiaxin Yu 	{"Receiver", NULL, "RCV Mux"},
26428061734aSJiaxin Yu };
26438061734aSJiaxin Yu 
mt6359_codec_dai_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)26448061734aSJiaxin Yu static int mt6359_codec_dai_hw_params(struct snd_pcm_substream *substream,
26458061734aSJiaxin Yu 				      struct snd_pcm_hw_params *params,
26468061734aSJiaxin Yu 				      struct snd_soc_dai *dai)
26478061734aSJiaxin Yu {
26488061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = dai->component;
26498061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
26508061734aSJiaxin Yu 	unsigned int rate = params_rate(params);
26518061734aSJiaxin Yu 	int id = dai->id;
26528061734aSJiaxin Yu 
26538061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s(), id %d, substream->stream %d, rate %d, number %d\n",
26548061734aSJiaxin Yu 		__func__, id, substream->stream, rate, substream->number);
26558061734aSJiaxin Yu 
26568061734aSJiaxin Yu 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
26578061734aSJiaxin Yu 		priv->dl_rate[id] = rate;
26588061734aSJiaxin Yu 	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
26598061734aSJiaxin Yu 		priv->ul_rate[id] = rate;
26608061734aSJiaxin Yu 
26618061734aSJiaxin Yu 	return 0;
26628061734aSJiaxin Yu }
26638061734aSJiaxin Yu 
mt6359_codec_dai_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)26648061734aSJiaxin Yu static int mt6359_codec_dai_startup(struct snd_pcm_substream *substream,
26658061734aSJiaxin Yu 				    struct snd_soc_dai *dai)
26668061734aSJiaxin Yu {
26678061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = dai->component;
26688061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
26698061734aSJiaxin Yu 
26708061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s stream %d\n", __func__, substream->stream);
26718061734aSJiaxin Yu 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
26728061734aSJiaxin Yu 		mt6359_set_playback_gpio(priv);
26738061734aSJiaxin Yu 	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
26748061734aSJiaxin Yu 		mt6359_set_capture_gpio(priv);
26758061734aSJiaxin Yu 
26768061734aSJiaxin Yu 	return 0;
26778061734aSJiaxin Yu }
26788061734aSJiaxin Yu 
mt6359_codec_dai_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)26798061734aSJiaxin Yu static void mt6359_codec_dai_shutdown(struct snd_pcm_substream *substream,
26808061734aSJiaxin Yu 				      struct snd_soc_dai *dai)
26818061734aSJiaxin Yu {
26828061734aSJiaxin Yu 	struct snd_soc_component *cmpnt = dai->component;
26838061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
26848061734aSJiaxin Yu 
26858061734aSJiaxin Yu 	dev_dbg(priv->dev, "%s stream %d\n", __func__, substream->stream);
26868061734aSJiaxin Yu 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
26878061734aSJiaxin Yu 		mt6359_reset_playback_gpio(priv);
26888061734aSJiaxin Yu 	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
26898061734aSJiaxin Yu 		mt6359_reset_capture_gpio(priv);
26908061734aSJiaxin Yu }
26918061734aSJiaxin Yu 
26928061734aSJiaxin Yu static const struct snd_soc_dai_ops mt6359_codec_dai_ops = {
26938061734aSJiaxin Yu 	.hw_params = mt6359_codec_dai_hw_params,
26948061734aSJiaxin Yu 	.startup = mt6359_codec_dai_startup,
26958061734aSJiaxin Yu 	.shutdown = mt6359_codec_dai_shutdown,
26968061734aSJiaxin Yu };
26978061734aSJiaxin Yu 
2698d990af74SCharles Keepax #define MT6359_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE |\
2699d990af74SCharles Keepax 			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_U24_LE |\
2700d990af74SCharles Keepax 			SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE)
27018061734aSJiaxin Yu 
27028061734aSJiaxin Yu static struct snd_soc_dai_driver mt6359_dai_driver[] = {
27038061734aSJiaxin Yu 	{
27048061734aSJiaxin Yu 		.id = MT6359_AIF_1,
27058061734aSJiaxin Yu 		.name = "mt6359-snd-codec-aif1",
27068061734aSJiaxin Yu 		.playback = {
27078061734aSJiaxin Yu 			.stream_name = "AIF1 Playback",
27088061734aSJiaxin Yu 			.channels_min = 1,
27098061734aSJiaxin Yu 			.channels_max = 2,
27108061734aSJiaxin Yu 			.rates = SNDRV_PCM_RATE_8000_48000 |
27118061734aSJiaxin Yu 				 SNDRV_PCM_RATE_96000 |
27128061734aSJiaxin Yu 				 SNDRV_PCM_RATE_192000,
27138061734aSJiaxin Yu 			.formats = MT6359_FORMATS,
27148061734aSJiaxin Yu 		},
27158061734aSJiaxin Yu 		.capture = {
27168061734aSJiaxin Yu 			.stream_name = "AIF1 Capture",
27178061734aSJiaxin Yu 			.channels_min = 1,
27188061734aSJiaxin Yu 			.channels_max = 2,
27198061734aSJiaxin Yu 			.rates = SNDRV_PCM_RATE_8000 |
27208061734aSJiaxin Yu 				 SNDRV_PCM_RATE_16000 |
27218061734aSJiaxin Yu 				 SNDRV_PCM_RATE_32000 |
27228061734aSJiaxin Yu 				 SNDRV_PCM_RATE_48000 |
27238061734aSJiaxin Yu 				 SNDRV_PCM_RATE_96000 |
27248061734aSJiaxin Yu 				 SNDRV_PCM_RATE_192000,
27258061734aSJiaxin Yu 			.formats = MT6359_FORMATS,
27268061734aSJiaxin Yu 		},
27278061734aSJiaxin Yu 		.ops = &mt6359_codec_dai_ops,
27288061734aSJiaxin Yu 	},
27298061734aSJiaxin Yu 	{
27308061734aSJiaxin Yu 		.id = MT6359_AIF_2,
27318061734aSJiaxin Yu 		.name = "mt6359-snd-codec-aif2",
27328061734aSJiaxin Yu 		.playback = {
27338061734aSJiaxin Yu 			.stream_name = "AIF2 Playback",
27348061734aSJiaxin Yu 			.channels_min = 1,
27358061734aSJiaxin Yu 			.channels_max = 2,
27368061734aSJiaxin Yu 			.rates = SNDRV_PCM_RATE_8000_48000 |
27378061734aSJiaxin Yu 				 SNDRV_PCM_RATE_96000 |
27388061734aSJiaxin Yu 				 SNDRV_PCM_RATE_192000,
27398061734aSJiaxin Yu 			.formats = MT6359_FORMATS,
27408061734aSJiaxin Yu 		},
27418061734aSJiaxin Yu 		.capture = {
27428061734aSJiaxin Yu 			.stream_name = "AIF2 Capture",
27438061734aSJiaxin Yu 			.channels_min = 1,
27448061734aSJiaxin Yu 			.channels_max = 2,
27458061734aSJiaxin Yu 			.rates = SNDRV_PCM_RATE_8000 |
27468061734aSJiaxin Yu 				 SNDRV_PCM_RATE_16000 |
27478061734aSJiaxin Yu 				 SNDRV_PCM_RATE_32000 |
27488061734aSJiaxin Yu 				 SNDRV_PCM_RATE_48000,
27498061734aSJiaxin Yu 			.formats = MT6359_FORMATS,
27508061734aSJiaxin Yu 		},
27518061734aSJiaxin Yu 		.ops = &mt6359_codec_dai_ops,
27528061734aSJiaxin Yu 	},
27538061734aSJiaxin Yu };
27548061734aSJiaxin Yu 
mt6359_codec_init_reg(struct snd_soc_component * cmpnt)27558061734aSJiaxin Yu static int mt6359_codec_init_reg(struct snd_soc_component *cmpnt)
27568061734aSJiaxin Yu {
27578061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
27588061734aSJiaxin Yu 
27598061734aSJiaxin Yu 	/* enable clk buf */
27608061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_DCXO_CW12,
27618061734aSJiaxin Yu 			   0x1 << RG_XO_AUDIO_EN_M_SFT,
27628061734aSJiaxin Yu 			   0x1 << RG_XO_AUDIO_EN_M_SFT);
27638061734aSJiaxin Yu 
27648061734aSJiaxin Yu 	/* set those not controlled by dapm widget */
27658061734aSJiaxin Yu 
27668061734aSJiaxin Yu 	/* audio clk source from internal dcxo */
27678061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23,
27688061734aSJiaxin Yu 			   RG_CLKSQ_IN_SEL_TEST_MASK_SFT,
27698061734aSJiaxin Yu 			   0x0);
27708061734aSJiaxin Yu 
27718061734aSJiaxin Yu 	/* Disable HeadphoneL/HeadphoneR short circuit protection */
27728061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
27738061734aSJiaxin Yu 			   RG_AUDHPLSCDISABLE_VAUDP32_MASK_SFT,
27748061734aSJiaxin Yu 			   0x1 << RG_AUDHPLSCDISABLE_VAUDP32_SFT);
27758061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON0,
27768061734aSJiaxin Yu 			   RG_AUDHPRSCDISABLE_VAUDP32_MASK_SFT,
27778061734aSJiaxin Yu 			   0x1 << RG_AUDHPRSCDISABLE_VAUDP32_SFT);
27788061734aSJiaxin Yu 	/* Disable voice short circuit protection */
27798061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON6,
27808061734aSJiaxin Yu 			   RG_AUDHSSCDISABLE_VAUDP32_MASK_SFT,
27818061734aSJiaxin Yu 			   0x1 << RG_AUDHSSCDISABLE_VAUDP32_SFT);
27828061734aSJiaxin Yu 	/* disable LO buffer left short circuit protection */
27838061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_AUDDEC_ANA_CON7,
27848061734aSJiaxin Yu 			   RG_AUDLOLSCDISABLE_VAUDP32_MASK_SFT,
27858061734aSJiaxin Yu 			   0x1 << RG_AUDLOLSCDISABLE_VAUDP32_SFT);
27868061734aSJiaxin Yu 
27878061734aSJiaxin Yu 	/* set gpio */
278824f398e7STrevor Wu 	mt6359_set_gpio_smt(priv);
278924f398e7STrevor Wu 	mt6359_set_gpio_driving(priv);
27908061734aSJiaxin Yu 	mt6359_reset_playback_gpio(priv);
27918061734aSJiaxin Yu 	mt6359_reset_capture_gpio(priv);
27928061734aSJiaxin Yu 
27938061734aSJiaxin Yu 	/* hp hifi mode, default normal mode */
27948061734aSJiaxin Yu 	priv->hp_hifi_mode = 0;
27958061734aSJiaxin Yu 
27968061734aSJiaxin Yu 	/* Disable AUD_ZCD */
27978061734aSJiaxin Yu 	zcd_disable(priv);
27988061734aSJiaxin Yu 
27998061734aSJiaxin Yu 	/* disable clk buf */
28008061734aSJiaxin Yu 	regmap_update_bits(priv->regmap, MT6359_DCXO_CW12,
28018061734aSJiaxin Yu 			   0x1 << RG_XO_AUDIO_EN_M_SFT,
28028061734aSJiaxin Yu 			   0x0 << RG_XO_AUDIO_EN_M_SFT);
28038061734aSJiaxin Yu 
28048061734aSJiaxin Yu 	return 0;
28058061734aSJiaxin Yu }
28068061734aSJiaxin Yu 
mt6359_codec_probe(struct snd_soc_component * cmpnt)28078061734aSJiaxin Yu static int mt6359_codec_probe(struct snd_soc_component *cmpnt)
28088061734aSJiaxin Yu {
28098061734aSJiaxin Yu 	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
28108061734aSJiaxin Yu 
28118061734aSJiaxin Yu 	snd_soc_component_init_regmap(cmpnt, priv->regmap);
28128061734aSJiaxin Yu 
28138061734aSJiaxin Yu 	return mt6359_codec_init_reg(cmpnt);
28148061734aSJiaxin Yu }
28158061734aSJiaxin Yu 
mt6359_codec_remove(struct snd_soc_component * cmpnt)28168061734aSJiaxin Yu static void mt6359_codec_remove(struct snd_soc_component *cmpnt)
28178061734aSJiaxin Yu {
28186d66c5ccSTrevor Wu 	cmpnt->regmap = NULL;
28198061734aSJiaxin Yu }
28208061734aSJiaxin Yu 
28218061734aSJiaxin Yu static const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0);
28228061734aSJiaxin Yu static const DECLARE_TLV_DB_SCALE(capture_tlv, 0, 600, 0);
28238061734aSJiaxin Yu 
28248061734aSJiaxin Yu static const struct snd_kcontrol_new mt6359_snd_controls[] = {
28258061734aSJiaxin Yu 	/* dl pga gain */
28268061734aSJiaxin Yu 	SOC_DOUBLE_EXT_TLV("Headset Volume",
2827acd4d219STrevor Wu 			   MT6359_ZCD_CON2, 0, 7, 0x12, 0,
2828acd4d219STrevor Wu 			   mt6359_get_playback_volsw, mt6359_put_volsw,
2829acd4d219STrevor Wu 			   playback_tlv),
28308061734aSJiaxin Yu 	SOC_DOUBLE_EXT_TLV("Lineout Volume",
28318061734aSJiaxin Yu 			   MT6359_ZCD_CON1, 0, 7, 0x12, 0,
2832acd4d219STrevor Wu 			   mt6359_get_playback_volsw, mt6359_put_volsw,
2833acd4d219STrevor Wu 			   playback_tlv),
28348061734aSJiaxin Yu 	SOC_SINGLE_EXT_TLV("Handset Volume",
28358061734aSJiaxin Yu 			   MT6359_ZCD_CON3, 0, 0x12, 0,
2836acd4d219STrevor Wu 			   mt6359_get_playback_volsw, mt6359_put_volsw,
2837acd4d219STrevor Wu 			   playback_tlv),
28388061734aSJiaxin Yu 
28398061734aSJiaxin Yu 	/* ul pga gain */
28408061734aSJiaxin Yu 	SOC_SINGLE_EXT_TLV("PGA1 Volume",
28418061734aSJiaxin Yu 			   MT6359_AUDENC_ANA_CON0, RG_AUDPREAMPLGAIN_SFT, 4, 0,
28428061734aSJiaxin Yu 			   snd_soc_get_volsw, mt6359_put_volsw, capture_tlv),
28438061734aSJiaxin Yu 	SOC_SINGLE_EXT_TLV("PGA2 Volume",
28448061734aSJiaxin Yu 			   MT6359_AUDENC_ANA_CON1, RG_AUDPREAMPRGAIN_SFT, 4, 0,
28458061734aSJiaxin Yu 			   snd_soc_get_volsw, mt6359_put_volsw, capture_tlv),
28468061734aSJiaxin Yu 	SOC_SINGLE_EXT_TLV("PGA3 Volume",
28478061734aSJiaxin Yu 			   MT6359_AUDENC_ANA_CON2, RG_AUDPREAMP3GAIN_SFT, 4, 0,
28488061734aSJiaxin Yu 			   snd_soc_get_volsw, mt6359_put_volsw, capture_tlv),
28498061734aSJiaxin Yu };
28508061734aSJiaxin Yu 
28518061734aSJiaxin Yu static const struct snd_soc_component_driver mt6359_soc_component_driver = {
28528061734aSJiaxin Yu 	.name = CODEC_MT6359_NAME,
28538061734aSJiaxin Yu 	.probe = mt6359_codec_probe,
28548061734aSJiaxin Yu 	.remove = mt6359_codec_remove,
28558061734aSJiaxin Yu 	.controls = mt6359_snd_controls,
28568061734aSJiaxin Yu 	.num_controls = ARRAY_SIZE(mt6359_snd_controls),
28578061734aSJiaxin Yu 	.dapm_widgets = mt6359_dapm_widgets,
28588061734aSJiaxin Yu 	.num_dapm_widgets = ARRAY_SIZE(mt6359_dapm_widgets),
28598061734aSJiaxin Yu 	.dapm_routes = mt6359_dapm_routes,
28608061734aSJiaxin Yu 	.num_dapm_routes = ARRAY_SIZE(mt6359_dapm_routes),
2861d990af74SCharles Keepax 	.endianness = 1,
28628061734aSJiaxin Yu };
28638061734aSJiaxin Yu 
mt6359_parse_dt(struct mt6359_priv * priv)28648061734aSJiaxin Yu static int mt6359_parse_dt(struct mt6359_priv *priv)
28658061734aSJiaxin Yu {
28668061734aSJiaxin Yu 	int ret;
28678061734aSJiaxin Yu 	struct device *dev = priv->dev;
286868353028STzung-Bi Shih 	struct device_node *np;
28698061734aSJiaxin Yu 
287068353028STzung-Bi Shih 	np = of_get_child_by_name(dev->parent->of_node, "mt6359codec");
287168353028STzung-Bi Shih 	if (!np)
287268353028STzung-Bi Shih 		return -EINVAL;
287368353028STzung-Bi Shih 
287468353028STzung-Bi Shih 	ret = of_property_read_u32(np, "mediatek,dmic-mode",
28758061734aSJiaxin Yu 				   &priv->dmic_one_wire_mode);
28768061734aSJiaxin Yu 	if (ret) {
28771ecebae4STzung-Bi Shih 		dev_info(priv->dev,
28781ecebae4STzung-Bi Shih 			 "%s() failed to read dmic-mode, use default (0)\n",
28798061734aSJiaxin Yu 			 __func__);
28808061734aSJiaxin Yu 		priv->dmic_one_wire_mode = 0;
28818061734aSJiaxin Yu 	}
28828061734aSJiaxin Yu 
288368353028STzung-Bi Shih 	ret = of_property_read_u32(np, "mediatek,mic-type-0",
28848061734aSJiaxin Yu 				   &priv->mux_select[MUX_MIC_TYPE_0]);
28858061734aSJiaxin Yu 	if (ret) {
28861ecebae4STzung-Bi Shih 		dev_info(priv->dev,
28871ecebae4STzung-Bi Shih 			 "%s() failed to read mic-type-0, use default (%d)\n",
28881ecebae4STzung-Bi Shih 			 __func__, MIC_TYPE_MUX_IDLE);
28898061734aSJiaxin Yu 		priv->mux_select[MUX_MIC_TYPE_0] = MIC_TYPE_MUX_IDLE;
28908061734aSJiaxin Yu 	}
28918061734aSJiaxin Yu 
289268353028STzung-Bi Shih 	ret = of_property_read_u32(np, "mediatek,mic-type-1",
28938061734aSJiaxin Yu 				   &priv->mux_select[MUX_MIC_TYPE_1]);
28948061734aSJiaxin Yu 	if (ret) {
28951ecebae4STzung-Bi Shih 		dev_info(priv->dev,
28961ecebae4STzung-Bi Shih 			 "%s() failed to read mic-type-1, use default (%d)\n",
28971ecebae4STzung-Bi Shih 			 __func__, MIC_TYPE_MUX_IDLE);
28988061734aSJiaxin Yu 		priv->mux_select[MUX_MIC_TYPE_1] = MIC_TYPE_MUX_IDLE;
28998061734aSJiaxin Yu 	}
29008061734aSJiaxin Yu 
290168353028STzung-Bi Shih 	ret = of_property_read_u32(np, "mediatek,mic-type-2",
29028061734aSJiaxin Yu 				   &priv->mux_select[MUX_MIC_TYPE_2]);
2903a8d5df69SLiang He 	of_node_put(np);
29048061734aSJiaxin Yu 	if (ret) {
29051ecebae4STzung-Bi Shih 		dev_info(priv->dev,
29061ecebae4STzung-Bi Shih 			 "%s() failed to read mic-type-2, use default (%d)\n",
29071ecebae4STzung-Bi Shih 			 __func__, MIC_TYPE_MUX_IDLE);
29088061734aSJiaxin Yu 		priv->mux_select[MUX_MIC_TYPE_2] = MIC_TYPE_MUX_IDLE;
29098061734aSJiaxin Yu 	}
29108061734aSJiaxin Yu 
29118061734aSJiaxin Yu 	return 0;
29128061734aSJiaxin Yu }
29138061734aSJiaxin Yu 
mt6359_platform_driver_probe(struct platform_device * pdev)29148061734aSJiaxin Yu static int mt6359_platform_driver_probe(struct platform_device *pdev)
29158061734aSJiaxin Yu {
29168061734aSJiaxin Yu 	struct mt6359_priv *priv;
29178061734aSJiaxin Yu 	int ret;
29188061734aSJiaxin Yu 	struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
29198061734aSJiaxin Yu 
29208061734aSJiaxin Yu 	dev_dbg(&pdev->dev, "%s(), dev name %s\n",
29218061734aSJiaxin Yu 		__func__, dev_name(&pdev->dev));
29228061734aSJiaxin Yu 
29238061734aSJiaxin Yu 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
29248061734aSJiaxin Yu 	if (!priv)
29258061734aSJiaxin Yu 		return -ENOMEM;
29268061734aSJiaxin Yu 
29278061734aSJiaxin Yu 	priv->regmap = mt6397->regmap;
29288061734aSJiaxin Yu 	if (IS_ERR(priv->regmap))
29298061734aSJiaxin Yu 		return PTR_ERR(priv->regmap);
29308061734aSJiaxin Yu 
29318061734aSJiaxin Yu 	dev_set_drvdata(&pdev->dev, priv);
29328061734aSJiaxin Yu 	priv->dev = &pdev->dev;
29338061734aSJiaxin Yu 
29348061734aSJiaxin Yu 	ret = mt6359_parse_dt(priv);
29358061734aSJiaxin Yu 	if (ret) {
29368061734aSJiaxin Yu 		dev_warn(&pdev->dev, "%s() failed to parse dts\n", __func__);
29378061734aSJiaxin Yu 		return ret;
29388061734aSJiaxin Yu 	}
29398061734aSJiaxin Yu 
29408061734aSJiaxin Yu 	return devm_snd_soc_register_component(&pdev->dev,
29418061734aSJiaxin Yu 					       &mt6359_soc_component_driver,
29428061734aSJiaxin Yu 					       mt6359_dai_driver,
29438061734aSJiaxin Yu 					       ARRAY_SIZE(mt6359_dai_driver));
29448061734aSJiaxin Yu }
29458061734aSJiaxin Yu 
29468061734aSJiaxin Yu static struct platform_driver mt6359_platform_driver = {
29478061734aSJiaxin Yu 	.driver = {
29488061734aSJiaxin Yu 		.name = "mt6359-sound",
29498061734aSJiaxin Yu 	},
29508061734aSJiaxin Yu 	.probe = mt6359_platform_driver_probe,
29518061734aSJiaxin Yu };
29528061734aSJiaxin Yu 
29538061734aSJiaxin Yu module_platform_driver(mt6359_platform_driver)
29548061734aSJiaxin Yu 
29558061734aSJiaxin Yu /* Module information */
29568061734aSJiaxin Yu MODULE_DESCRIPTION("MT6359 ALSA SoC codec driver");
29578061734aSJiaxin Yu MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
29588061734aSJiaxin Yu MODULE_AUTHOR("Eason Yen <eason.yen@mediatek.com>");
29598061734aSJiaxin Yu MODULE_LICENSE("GPL v2");
2960