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